Skip to content

Commit

Permalink
ENH: Add Support for loading mesh files
Browse files Browse the repository at this point in the history
  • Loading branch information
NicerNewerCar committed Jun 1, 2023
1 parent 152fc3b commit 486a8d1
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 15 deletions.
8 changes: 7 additions & 1 deletion libautoscoper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ set(libautoscoper_SOURCES
src/VolumeTransform.cpp
)

if(Autoscoper_COLLISION_DETECTION) # Add collision detection sources
if(Autoscoper_COLLISION_DETECTION) # Add collision detection sources/headers
list(APPEND libautoscoper_SOURCES
src/Mesh.cpp
)
list(APPEND libautoscoper_HEADERS
src/Mesh.hpp
)
endif()

if(Autoscoper_RENDERING_BACKEND STREQUAL "CUDA")
Expand Down
24 changes: 24 additions & 0 deletions libautoscoper/src/Mesh.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "Mesh.hpp"
#include <vtkSTLReader.h>
#include <vtkSTLWriter.h>

Mesh::Mesh(const std::string& filename) {
vtkSTLReader* reader = vtkSTLReader::New();
reader->SetFileName(filename.c_str());
reader->Update();
this->polyData = reader->GetOutput();
reader->Delete();
}

Mesh::Mesh(const Mesh& other) {
this->polyData = vtkPolyData::New();
this->polyData->DeepCopy(other.polyData);
}

void Mesh::Write(const std::string& filename) const {
vtkSTLWriter* writer = vtkSTLWriter::New();
writer->SetFileName(filename.c_str());
writer->SetInputData(this->polyData);
writer->Write();
writer->Delete();
}
17 changes: 17 additions & 0 deletions libautoscoper/src/Mesh.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once
#include <string>
#include <vtkPolyData.h>

class Mesh {
public:
Mesh(const std::string& filename);
Mesh(const Mesh&);

vtkPolyData* GetPolyData() const { return this->polyData; }

void Write(const std::string& filename) const;

private:

vtkPolyData* polyData;
};
27 changes: 27 additions & 0 deletions libautoscoper/src/Trial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ namespace xromm
std::vector<std::string> volumeFlips;
std::vector<std::string> renderResolution;
std::vector<std::string> optimizationOffsets;
std::vector<std::string> meshFiles;

std::string line, key, value;
while (getline(file, line)) {
Expand Down Expand Up @@ -114,6 +115,10 @@ namespace xromm
getline(lineStream, value);
optimizationOffsets.push_back(value);
}
else if (key.compare("MeshFile") == 0) {
getline(lineStream, value);
meshFiles.push_back(value);
}
}

// Close the file.
Expand All @@ -132,6 +137,9 @@ namespace xromm
if (volumeFiles.size() != voxelSizes.size()) {
throw std::runtime_error("You must sepcify a voxels size for each volume.");
}
if (meshFiles.size() != 0 && volumeFiles.size() != meshFiles.size()) {
throw std::runtime_error("You must sepcify a mesh file for each volume or none at all.");
}

cameras.clear();
for (unsigned int i = 0; i < mayaCams.size(); ++i) {
Expand Down Expand Up @@ -179,6 +187,25 @@ namespace xromm
}
}

// load in mesh files if they exist
if (meshFiles.size() > 0) {
#ifdef Autoscoper_COLLISION_DETECTION
meshes.clear();
for (unsigned int i = 0; i < meshFiles.size(); ++i) {
try {
Mesh mesh(meshFiles[i]);
meshes.push_back(mesh);
}
catch (std::exception& e) {
std::cerr << e.what() << std::endl;
}
}
#else
std::cerr << "WARNING: Autoscoper was not compiled with collision detection support. No mesh files will be loaded." << std::endl;
#endif // Autoscoper_COLLISION_DETECTION
}


int maxVideoFrames = 0;
videos.clear();
for (unsigned int i = 0; i < camRootDirs.size(); ++i) {
Expand Down
37 changes: 23 additions & 14 deletions libautoscoper/src/Trial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
#include "Volume.hpp"
#include "VolumeTransform.hpp"

#ifdef Autoscoper_COLLISION_DETECTION
#include "Mesh.hpp"
#endif // Autoscoper_COLLISION_DETECTION


namespace xromm
{
// The trial class contains all of the state information for an autoscoper run.
Expand All @@ -63,28 +68,32 @@ class Trial
{
public:

// Loads a trial file
// Loads a trial file

Trial(const std::string& filename = "");
Trial(const std::string& filename = "");

void save(const std::string& filename);
void save(const std::string& filename);

std::vector<Camera> cameras;
std::vector<Video> videos;
std::vector<Volume> volumes;
std::vector<Camera> cameras;
std::vector<Video> videos;
std::vector<Volume> volumes;
std::vector<VolumeTransform> volumestransform;
#ifdef Autoscoper_COLLISION_DETECTION
std::vector<Mesh> meshes;
#endif // Autoscoper_COLLISION_DETECTION


// State information
int frame;
int num_frames;
// State information
int frame;
int num_frames;
int current_volume;
int num_volumes;

//Controls for the optimization process
int guess;
double offsets[6];
int render_width;
int render_height;
//Controls for the optimization process
int guess;
double offsets[6];
int render_width;
int render_height;

KeyCurve * getXCurve(int volumeID);
KeyCurve * getYCurve(int volumeID);
Expand Down

0 comments on commit 486a8d1

Please sign in to comment.