Skip to content

Commit d152df7

Browse files
authored
2349 - Improve mesh domain memory usage (#2353)
Fix #2349 by switching to LibIGL style storage of polydata and associated functions. It also generates gradient normals on demand, so if they are not needed, they are not computed, saving further memory and computation time.
1 parent cea8246 commit d152df7

File tree

23 files changed

+797
-612
lines changed

23 files changed

+797
-612
lines changed

ExternalLibs/robin_hood/robin_hood.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,7 @@ static Counts& counts() {
192192
# define ROBIN_HOOD_PRIVATE_DEFINITION_HAS_NATIVE_WCHART() 1
193193
#endif
194194

195-
// workaround missing "is_trivially_copyable" in g++ < 5.0
196-
// See https://stackoverflow.com/a/31798726/48181
197-
#if defined(__GNUC__) && __GNUC__ < 5
198-
# define ROBIN_HOOD_IS_TRIVIALLY_COPYABLE(...) __has_trivial_copy(__VA_ARGS__)
199-
#else
200-
# define ROBIN_HOOD_IS_TRIVIALLY_COPYABLE(...) std::is_trivially_copyable<__VA_ARGS__>::value
201-
#endif
195+
#define ROBIN_HOOD_IS_TRIVIALLY_COPYABLE(...) std::is_trivially_copyable<__VA_ARGS__>::value
202196

203197
// helpers for C++ versions, see https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html
204198
#define ROBIN_HOOD_PRIVATE_DEFINITION_CXX() __cplusplus

Libs/Analyze/Analyze.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static void write_good_bad_angles(json& json_object, ProjectHandle project, Anal
7575
std::vector<json> good_bad_angles;
7676

7777
for (int d = 0; d < project->get_number_of_domains_per_subject(); d++) {
78-
std::vector<std::shared_ptr<MeshWrapper>> meshes;
78+
std::vector<std::shared_ptr<Surface>> meshes;
7979
for (auto& shape : analyze.get_shapes()) {
8080
meshes.push_back(shape->get_groomed_mesh_wrappers()[d]);
8181
}

Libs/Analyze/Shape.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <vtkKdTreePointLocator.h>
1717
#include <vtkPointData.h>
1818

19-
#include "Libs/Optimize/Domain/MeshWrapper.h"
19+
#include "Libs/Optimize/Domain/Surface.h"
2020

2121
using ReaderType = itk::ImageFileReader<ImageType>;
2222

@@ -931,14 +931,14 @@ bool Shape::has_planes() {
931931
}
932932

933933
//---------------------------------------------------------------------------
934-
std::vector<std::shared_ptr<MeshWrapper>> Shape::get_groomed_mesh_wrappers() {
934+
std::vector<std::shared_ptr<Surface>> Shape::get_groomed_mesh_wrappers() {
935935
if (!groomed_mesh_wrappers_.empty()) {
936936
return groomed_mesh_wrappers_;
937937
}
938938

939939
auto group = get_groomed_meshes(true /* wait */);
940940
for (auto& mesh : group.meshes()) {
941-
auto wrapper = std::make_shared<MeshWrapper>(mesh->get_poly_data());
941+
auto wrapper = std::make_shared<Surface>(mesh->get_poly_data());
942942
groomed_mesh_wrappers_.push_back(wrapper);
943943
}
944944
return groomed_mesh_wrappers_;

Libs/Analyze/Shape.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace shapeworks {
2222
class Shape;
2323
using ShapeHandle = std::shared_ptr<Shape>;
2424
using ShapeList = std::vector<ShapeHandle>;
25-
class MeshWrapper;
25+
class Surface;
2626

2727
//! Representation of a single shape/patient/subject.
2828
class Shape {
@@ -187,7 +187,7 @@ class Shape {
187187

188188
bool has_planes();
189189

190-
std::vector<std::shared_ptr<MeshWrapper>> get_groomed_mesh_wrappers();
190+
std::vector<std::shared_ptr<Surface>> get_groomed_mesh_wrappers();
191191

192192
void recompute_original_surface();
193193

@@ -208,7 +208,7 @@ class Shape {
208208
MeshGroup original_meshes_;
209209
MeshGroup groomed_meshes_;
210210
MeshGroup reconstructed_meshes_;
211-
std::vector<std::shared_ptr<MeshWrapper>> groomed_mesh_wrappers_;
211+
std::vector<std::shared_ptr<Surface>> groomed_mesh_wrappers_;
212212

213213
std::string override_feature_;
214214

Libs/Mesh/Mesh.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060

6161
#include "FEFixMesh.h"
6262
#include "Image.h"
63-
#include "Libs/Optimize/Domain/MeshWrapper.h"
63+
#include "Libs/Optimize/Domain/Surface.h"
6464
#include "Logging.h"
6565
#include "MeshComputeThickness.h"
6666
#include "MeshUtils.h"
@@ -785,8 +785,8 @@ double Mesh::geodesicDistance(int source, int target) const {
785785
throw std::invalid_argument("requested point ids outside range of points available in mesh");
786786
}
787787

788-
MeshWrapper wrap(this->poly_data_, true);
789-
return wrap.ComputeDistance(getPoint(source), -1, getPoint(target), -1);
788+
Surface surface(this->poly_data_, true);
789+
return surface.compute_distance(getPoint(source), -1, getPoint(target), -1);
790790
}
791791

792792
Field Mesh::geodesicDistance(const Point3 landmark) const {
@@ -795,10 +795,10 @@ Field Mesh::geodesicDistance(const Point3 landmark) const {
795795
distance->SetNumberOfTuples(numPoints());
796796
distance->SetName("GeodesicDistanceToLandmark");
797797

798-
MeshWrapper wrap(this->poly_data_, true);
798+
Surface surface(this->poly_data_, true);
799799

800800
for (int i = 0; i < numPoints(); i++) {
801-
distance->SetValue(i, wrap.ComputeDistance(landmark, -1, getPoint(i), -1));
801+
distance->SetValue(i, surface.compute_distance(landmark, -1, getPoint(i), -1));
802802
}
803803

804804
return distance;
@@ -1767,7 +1767,7 @@ Eigen::Vector3d Mesh::getFFCGradient(Eigen::Vector3d query) const {
17671767
return grad;
17681768
}
17691769

1770-
// WARNING: Copied directly from Meshwrapper. TODO: When refactoring, take this into account.
1770+
// WARNING: Copied directly from Surface. TODO: When refactoring, take this into account.
17711771
vtkSmartPointer<vtkPoints> Mesh::getIGLMesh(Eigen::MatrixXd& V, Eigen::MatrixXi& F) const {
17721772
const int n_verts = this->poly_data_->GetNumberOfPoints();
17731773
const int n_faces = this->poly_data_->GetNumberOfCells();

Libs/Mesh/Mesh.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ class Mesh {
277277

278278
//! Formats mesh into an IGL format
279279
vtkSmartPointer<vtkPoints> getIGLMesh(Eigen::MatrixXd& V, Eigen::MatrixXi& F)
280-
const; // Copied directly from MeshWrapper. this->poly_data_ becomes this->mesh. // WARNING: Copied directly
281-
// from Meshwrapper. TODO: When refactoring, take this into account.
280+
const; // Copied directly from Surface. this->poly_data_ becomes this->mesh. // WARNING: Copied directly
281+
// from Surface. TODO: When refactoring, take this into account.
282282

283283
//! Clips the mesh according to a field value
284284
vtkSmartPointer<vtkPolyData> clipByField(const std::string& name, double value);
@@ -293,7 +293,7 @@ class Mesh {
293293

294294
/// Computes baricentric coordinates given a query point and a face number
295295
Eigen::Vector3d computeBarycentricCoordinates(const Eigen::Vector3d& pt, int face)
296-
const; // // WARNING: Copied directly from Meshwrapper. TODO: When refactoring, take this into account.
296+
const; // // WARNING: Copied directly from Surface. TODO: When refactoring, take this into account.
297297

298298
//! Interpolates scalar values at points (e.g. correspondence points) to the mesh, assign/create a field with the
299299
//! given name

0 commit comments

Comments
 (0)