From c227d3b470baf79bdd7539608baa47ad97c2cbd3 Mon Sep 17 00:00:00 2001 From: Xiangyu Hu Date: Wed, 17 Jul 2024 07:09:18 +0000 Subject: [PATCH] replace TriangleMeshShapeSTL with new formulation --- .../structural_simulation_class.cpp | 4 +- .../geometries/triangle_mesh_shape.cpp | 58 ++----------------- .../geometries/triangle_mesh_shape.h | 28 ++------- .../beam_pulling_pressure_load.cpp | 2 +- .../excitation-contraction.cpp | 2 +- .../excitation_contraction.h | 2 +- .../nonlinear_wave_fsi.cpp | 2 +- .../nonlinear_wave_fsi.h | 4 +- .../particle_relaxation.cpp | 2 +- ...rticle_relaxation_single_resolution_3D.cpp | 6 +- .../pkj_lv_electrocontraction.h | 2 +- .../test_3d_self_contact/3d_self_contact.cpp | 2 +- .../test_3d_shell_particle_relaxation.cpp | 2 +- .../bernoulli_beam_struct_sim.cpp | 2 +- 14 files changed, 25 insertions(+), 93 deletions(-) diff --git a/modules/structural_simulation/structural_simulation_class.cpp b/modules/structural_simulation/structural_simulation_class.cpp index e0a0dab83f..16c991b8bf 100755 --- a/modules/structural_simulation/structural_simulation_class.cpp +++ b/modules/structural_simulation/structural_simulation_class.cpp @@ -303,9 +303,9 @@ void StructuralSimulation::createBodyMeshList() { std::string relative_input_path_copy = relative_input_path_; #ifdef __EMSCRIPTEN__ - body_mesh_list_.push_back(makeShared(reinterpret_cast(imported_stl_list_[i].ptr), translation_list_[i], scale_stl_, imported_stl_list_[i].name)); + body_mesh_list_.push_back(makeShared(reinterpret_cast(imported_stl_list_[i].ptr), translation_list_[i], scale_stl_, imported_stl_list_[i].name)); #else - body_mesh_list_.push_back(makeShared(relative_input_path_copy.append(imported_stl_list_[i]), translation_list_[i], scale_stl_, imported_stl_list_[i])); + body_mesh_list_.push_back(makeShared(relative_input_path_copy.append(imported_stl_list_[i]), translation_list_[i], scale_stl_, imported_stl_list_[i])); #endif } } diff --git a/src/for_3D_build/geometries/triangle_mesh_shape.cpp b/src/for_3D_build/geometries/triangle_mesh_shape.cpp index bf84f65056..51c9329b19 100644 --- a/src/for_3D_build/geometries/triangle_mesh_shape.cpp +++ b/src/for_3D_build/geometries/triangle_mesh_shape.cpp @@ -97,55 +97,6 @@ BoundingBox TriangleMeshShape::findBounds() return BoundingBox(lower_bound, upper_bound); } //=================================================================================================// -TriangleMeshShapeSTL::TriangleMeshShapeSTL(const std::string &filepathname, Vecd translation, Real scale_factor, - const std::string &shape_name) - : TriangleMeshShape(shape_name) -{ - if (!fs::exists(filepathname)) - { - std::cout << "\n Error: the input file:" << filepathname << " is not exists" << std::endl; - std::cout << __FILE__ << ':' << __LINE__ << std::endl; - throw; - } - SimTK::PolygonalMesh polymesh; - polymesh.loadStlFile(filepathname); - polymesh.scaleMesh(scale_factor); - triangle_mesh_ = generateTriangleMesh(polymesh.transformMesh(SimTKVec3(translation[0], translation[1], translation[2]))); -} -//=================================================================================================// -TriangleMeshShapeSTL::TriangleMeshShapeSTL(const std::string &filepathname, Mat3d rotation, - Vec3d translation, Real scale_factor, const std::string &shape_name) - : TriangleMeshShape(shape_name) -{ - if (!fs::exists(filepathname)) - { - std::cout << "\n Error: the input file:" << filepathname << " is not exists" << std::endl; - std::cout << __FILE__ << ':' << __LINE__ << std::endl; - throw; - } - SimTK::PolygonalMesh polymesh; - polymesh.loadStlFile(filepathname); - - polymesh.scaleMesh(scale_factor); - SimTK::Transform_ transform(SimTK::Rotation_(SimTKMat33((double)rotation(0, 0), (double)rotation(0, 1), (double)rotation(0, 2), - (double)rotation(1, 0), (double)rotation(1, 1), (double)rotation(1, 2), - (double)rotation(2, 0), (double)rotation(2, 1), (double)rotation(2, 2))), - SimTKVec3((double)translation[0], (double)translation[1], (double)translation[2])); - triangle_mesh_ = generateTriangleMesh(polymesh.transformMesh(transform)); -} -//=================================================================================================// -#ifdef __EMSCRIPTEN__ -TriangleMeshShapeSTL::TriangleMeshShapeSTL(const uint8_t *buffer, Vecd translation, Real scale_factor, - const std::string &shape_name) - : TriangleMeshShape(shape_name) -{ - SimTK::PolygonalMesh polymesh; - polymesh.loadStlBuffer(buffer); - polymesh.scaleMesh(scale_factor); - triangle_mesh_ = generateTriangleMesh(polymesh.transformMesh(SimTKVec3(translation[0], translation[1], translation[2]))); -} -#endif -//=================================================================================================// TriangleMeshShapeBrick::TriangleMeshShapeBrick(Vecd halfsize, int resolution, Vecd translation, const std::string &shape_name) : TriangleMeshShape(shape_name) @@ -176,9 +127,8 @@ TriangleMeshShapeCylinder::TriangleMeshShapeCylinder(SimTK::UnitVec3 axis, Real triangle_mesh_ = generateTriangleMesh(polymesh.transformMesh(SimTKVec3(translation[0], translation[1], translation[2]))); } //=================================================================================================// -TriangleMeshShapeGeneric:: - TriangleMeshShapeGeneric(const std::string &filepathname, Vec3d translation, Real scale_factor, - const std::string &shape_name) +TriangleMeshShapeSTL::TriangleMeshShapeSTL(const std::string &filepathname, Vec3d translation, + Real scale_factor, const std::string &shape_name) : TriangleMeshShape(shape_name) { if (!fs::exists(filepathname)) @@ -213,14 +163,14 @@ TriangleMeshShapeGeneric:: triangle_mesh_distance_.construct(vertices, faces); } //=================================================================================================// -bool TriangleMeshShapeGeneric::checkContain(const Vec3d &probe_point, bool BOUNDARY_INCLUDED) +bool TriangleMeshShapeSTL::checkContain(const Vec3d &probe_point, bool BOUNDARY_INCLUDED) { Real distance = triangle_mesh_distance_.signed_distance(probe_point).distance; return distance < 0.0 ? true : false; } //=================================================================================================// -Vecd TriangleMeshShapeGeneric::findClosestPoint(const Vecd &probe_point) +Vecd TriangleMeshShapeSTL::findClosestPoint(const Vecd &probe_point) { auto closest_pnt = triangle_mesh_distance_.signed_distance(probe_point).nearest_point; return Vecd(closest_pnt[0], closest_pnt[1], closest_pnt[2]); diff --git a/src/for_3D_build/geometries/triangle_mesh_shape.h b/src/for_3D_build/geometries/triangle_mesh_shape.h index 75d195998e..e7f265ed97 100644 --- a/src/for_3D_build/geometries/triangle_mesh_shape.h +++ b/src/for_3D_build/geometries/triangle_mesh_shape.h @@ -74,24 +74,6 @@ class TriangleMeshShape : public Shape virtual BoundingBox findBounds() override; }; -/** - * @class TriangleMeshShapeSTL - * @brief Input triangle mesh with stl file. - */ -class TriangleMeshShapeSTL : public TriangleMeshShape -{ - public: - explicit TriangleMeshShapeSTL(const std::string &file_path_name, Vec3d translation, Real scale_factor, - const std::string &shape_name = "TriangleMeshShapeSTL"); - /** Overloaded to include rotation. */ - explicit TriangleMeshShapeSTL(const std::string &file_path_name, Mat3d rotation, Vec3d translation, - Real scale_factor, const std::string &shape_name = "TriangleMeshShapeSTL"); -#ifdef __EMSCRIPTEN__ - TriangleMeshShapeSTL(const uint8_t *buffer, Vec3d translation, Real scale_factor, const std::string &shape_name = "TriangleMeshShapeSTL"); -#endif - virtual ~TriangleMeshShapeSTL(){}; -}; - /** * @class TriangleMeshShapeBrick * @brief Generate a brick triangle mesh using SIMBODy default shape. @@ -139,15 +121,15 @@ class TriangleMeshShapeCylinder : public TriangleMeshShape }; /** - * @class TriangleMeshShapeGeneric + * @class TriangleMeshShapeSTL * @brief Input triangle mesh with stl file. */ -class TriangleMeshShapeGeneric : public TriangleMeshShape +class TriangleMeshShapeSTL : public TriangleMeshShape { public: - explicit TriangleMeshShapeGeneric(const std::string &file_path_name, Vec3d translation, Real scale_factor, - const std::string &shape_name = "TriangleMeshShapeSTL"); - virtual ~TriangleMeshShapeGeneric(){}; + explicit TriangleMeshShapeSTL(const std::string &file_path_name, Vec3d translation, Real scale_factor, + const std::string &shape_name = "TriangleMeshShapeSTL"); + virtual ~TriangleMeshShapeSTL(){}; /** Here, we use the open source method TriangleMeshDistance library. * https://github.com/InteractiveComputerGraphics/TriangleMeshDistance/tree/main */ diff --git a/tests/3d_examples/test_3d_beam_pulling_pressure_load/beam_pulling_pressure_load.cpp b/tests/3d_examples/test_3d_beam_pulling_pressure_load/beam_pulling_pressure_load.cpp index db14f90c44..5aff9a7f5b 100644 --- a/tests/3d_examples/test_3d_beam_pulling_pressure_load/beam_pulling_pressure_load.cpp +++ b/tests/3d_examples/test_3d_beam_pulling_pressure_load/beam_pulling_pressure_load.cpp @@ -36,7 +36,7 @@ class Beam : public ComplexShape { std::string fname_ = "./input/beam.stl"; Vecd translation(0.0, 0.0, 0.0); - add(fname_, translation, 0.001); + add(fname_, translation, 0.001); } }; diff --git a/tests/3d_examples/test_3d_heart_electromechanics/excitation-contraction.cpp b/tests/3d_examples/test_3d_heart_electromechanics/excitation-contraction.cpp index 42c6fc5538..026071b11f 100644 --- a/tests/3d_examples/test_3d_heart_electromechanics/excitation-contraction.cpp +++ b/tests/3d_examples/test_3d_heart_electromechanics/excitation-contraction.cpp @@ -61,7 +61,7 @@ class Heart : public ComplexShape explicit Heart(const std::string &shape_name) : ComplexShape(shape_name) { Vecd translation(-53.5 * length_scale, -70.0 * length_scale, -32.5 * length_scale); - add(full_path_to_stl_file, translation, length_scale); + add(full_path_to_stl_file, translation, length_scale); } }; using FiberDirectionDiffusionRelaxation = diff --git a/tests/3d_examples/test_3d_heart_volume_change/excitation_contraction.h b/tests/3d_examples/test_3d_heart_volume_change/excitation_contraction.h index 6a53053557..8522974a88 100644 --- a/tests/3d_examples/test_3d_heart_volume_change/excitation_contraction.h +++ b/tests/3d_examples/test_3d_heart_volume_change/excitation_contraction.h @@ -63,7 +63,7 @@ class Heart : public ComplexShape public: explicit Heart(const std::string &shape_name) : ComplexShape(shape_name) { - add(full_path_to_myocardium, translation, length_scale); + add(full_path_to_myocardium, translation, length_scale); } }; /** Set diffusion relaxation method. */ diff --git a/tests/3d_examples/test_3d_nonlinear_wave_fsi/nonlinear_wave_fsi.cpp b/tests/3d_examples/test_3d_nonlinear_wave_fsi/nonlinear_wave_fsi.cpp index 8b8374c95c..1badea3f1f 100644 --- a/tests/3d_examples/test_3d_nonlinear_wave_fsi/nonlinear_wave_fsi.cpp +++ b/tests/3d_examples/test_3d_nonlinear_wave_fsi/nonlinear_wave_fsi.cpp @@ -187,7 +187,7 @@ int main(int ac, char *av[]) /** mass properties of the fixed spot. */ SimTK::Body::Rigid fixed_spot_info(SimTK::MassProperties(1, SimTK::Vec3(0), SimTK::UnitInertia(1))); /** mass properties of the structure. */ - StructureSystemForSimbody structure_multibody(structure, makeShared(stl_structure_path, translation_str, StructureScale)); + StructureSystemForSimbody structure_multibody(structure, makeShared(stl_structure_path, translation_str, StructureScale)); SimTK::Body::Rigid structure_info(*structure_multibody.body_part_mass_properties_); /** Free mobilizer */ SimTK::MobilizedBody::Free tethered_struct(matter.Ground(), SimTK::Transform(SimTK::Vec3(translation_str[0], translation_str[1], translation_str[2])), structure_info, SimTK::Transform(SimTK::Vec3(0.0, 0.0, 0.0))); diff --git a/tests/3d_examples/test_3d_nonlinear_wave_fsi/nonlinear_wave_fsi.h b/tests/3d_examples/test_3d_nonlinear_wave_fsi/nonlinear_wave_fsi.h index fc370f1b62..09b45b13b2 100644 --- a/tests/3d_examples/test_3d_nonlinear_wave_fsi/nonlinear_wave_fsi.h +++ b/tests/3d_examples/test_3d_nonlinear_wave_fsi/nonlinear_wave_fsi.h @@ -268,7 +268,7 @@ class FloatingStructure : public ComplexShape public: explicit FloatingStructure(const std::string &shape_name) : ComplexShape(shape_name) { - add(stl_structure_path, translation_str, StructureScale); + add(stl_structure_path, translation_str, StructureScale); } }; @@ -299,7 +299,7 @@ class WaterBlock : public ComplexShape Vecd water_pos(0.5 * DW, 0.5 * (DL - EXS), 0.5 * WH); Transform translation_water(water_pos); add>(Transform(translation_water), halfsize_water); - subtract(stl_structure_path, translation_str, StructureScale); + subtract(stl_structure_path, translation_str, StructureScale); } }; diff --git a/tests/3d_examples/test_3d_particle_relaxation/particle_relaxation.cpp b/tests/3d_examples/test_3d_particle_relaxation/particle_relaxation.cpp index 7396b6fd70..3a63cae19f 100644 --- a/tests/3d_examples/test_3d_particle_relaxation/particle_relaxation.cpp +++ b/tests/3d_examples/test_3d_particle_relaxation/particle_relaxation.cpp @@ -30,7 +30,7 @@ class SolidBodyFromMesh : public ComplexShape explicit SolidBodyFromMesh(const std::string &shape_name) : ComplexShape(shape_name) { Vecd translation(0.0, 0.0, 0.0); - add(full_path_to_file, translation, 1.0); + add(full_path_to_file, translation, 1.0); } }; //----------------------------------------------------------------------------------------------------------- diff --git a/tests/3d_examples/test_3d_particle_relaxation_single_resolution/particle_relaxation_single_resolution_3D.cpp b/tests/3d_examples/test_3d_particle_relaxation_single_resolution/particle_relaxation_single_resolution_3D.cpp index bd11e4661f..4b3e812d1f 100644 --- a/tests/3d_examples/test_3d_particle_relaxation_single_resolution/particle_relaxation_single_resolution_3D.cpp +++ b/tests/3d_examples/test_3d_particle_relaxation_single_resolution/particle_relaxation_single_resolution_3D.cpp @@ -47,8 +47,8 @@ class SolidBodyFromMesh : public ComplexShape public: explicit SolidBodyFromMesh(const std::string &shape_name) : ComplexShape(shape_name) { - add>(4.0 * dp_0, full_path_to_file, translation, scaling); - subtract(full_path_to_file, translation, scaling); + add>(4.0 * dp_0, full_path_to_file, translation, scaling); + subtract(full_path_to_file, translation, scaling); } }; //---------------------------------------------------------------------- @@ -77,7 +77,7 @@ class SolidBodyFromMesh : public ComplexShape // public: // explicit SolidBodyFromMesh(const std::string &shape_name) : ComplexShape(shape_name) // { -// add(full_path_to_file, translation, scaling); +// add(full_path_to_file, translation, scaling); // } //}; //----------------------------------------------------------------------------------------------------------- diff --git a/tests/3d_examples/test_3d_pkj_lv_electrocontraction/pkj_lv_electrocontraction.h b/tests/3d_examples/test_3d_pkj_lv_electrocontraction/pkj_lv_electrocontraction.h index b0e563a553..83cd7d4fcf 100644 --- a/tests/3d_examples/test_3d_pkj_lv_electrocontraction/pkj_lv_electrocontraction.h +++ b/tests/3d_examples/test_3d_pkj_lv_electrocontraction/pkj_lv_electrocontraction.h @@ -93,7 +93,7 @@ class Heart : public ComplexShape explicit Heart(const std::string &shape_name) : ComplexShape(shape_name) { Vecd translation(0.0, 0.0, 0.0); - add(full_path_to_lv, translation, length_scale); + add(full_path_to_lv, translation, length_scale); } }; /** Set diffusion relaxation. */ diff --git a/tests/3d_examples/test_3d_self_contact/3d_self_contact.cpp b/tests/3d_examples/test_3d_self_contact/3d_self_contact.cpp index 4e0b91ee74..edb8bbe07c 100644 --- a/tests/3d_examples/test_3d_self_contact/3d_self_contact.cpp +++ b/tests/3d_examples/test_3d_self_contact/3d_self_contact.cpp @@ -35,7 +35,7 @@ class Coil : public ComplexShape public: explicit Coil(const std::string &shape_name) : ComplexShape(shape_name) { - add(full_path_to_file, Vecd::Zero(), 1.0); + add(full_path_to_file, Vecd::Zero(), 1.0); } }; class StationaryPlate : public ComplexShape diff --git a/tests/3d_examples/test_3d_shell_particle_relaxation/test_3d_shell_particle_relaxation.cpp b/tests/3d_examples/test_3d_shell_particle_relaxation/test_3d_shell_particle_relaxation.cpp index 84713bd76f..e096c174f9 100644 --- a/tests/3d_examples/test_3d_shell_particle_relaxation/test_3d_shell_particle_relaxation.cpp +++ b/tests/3d_examples/test_3d_shell_particle_relaxation/test_3d_shell_particle_relaxation.cpp @@ -32,7 +32,7 @@ class ImportedShellModel : public ComplexShape public: explicit ImportedShellModel(const std::string &shape_name) : ComplexShape(shape_name) { - add(full_path_to_geometry, Vecd::Zero(), 1.0); + add(full_path_to_geometry, Vecd::Zero(), 1.0); } }; //-------------------------------------------------------------------------- diff --git a/tests/modules/bernoulli_beam_struct_sim/bernoulli_beam_struct_sim.cpp b/tests/modules/bernoulli_beam_struct_sim/bernoulli_beam_struct_sim.cpp index 5991563cec..19e0ef6d99 100755 --- a/tests/modules/bernoulli_beam_struct_sim/bernoulli_beam_struct_sim.cpp +++ b/tests/modules/bernoulli_beam_struct_sim/bernoulli_beam_struct_sim.cpp @@ -20,7 +20,7 @@ TEST(BernoulliBeam20x, Pressure) SharedPtr material = makeShared(rho_0, Youngs_modulus, poisson); std::vector> material_model_list = {material}; - SharedPtr specimen = makeShared("./input/bernoulli_beam_20x.stl", Vec3d::Zero(), scale_stl, "bernoulli_beam_20x"); + SharedPtr specimen = makeShared("./input/bernoulli_beam_20x.stl", Vec3d::Zero(), scale_stl, "bernoulli_beam_20x"); BoundingBox fixation = specimen->getBounds(); fixation.second_[0] = fixation.first_[0] + 0.01;