Skip to content

Commit

Permalink
using new TriangleMeshDistance for triangle mesh shape
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiangyu-Hu committed Jul 16, 2024
1 parent 88e526f commit 9f12566
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 18 deletions.
4 changes: 2 additions & 2 deletions modules/structural_simulation/structural_simulation_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,9 @@ void StructuralSimulation::createBodyMeshList()
{
std::string relative_input_path_copy = relative_input_path_;
#ifdef __EMSCRIPTEN__
body_mesh_list_.push_back(makeShared<TriangleMeshShapeSTL>(reinterpret_cast<const uint8_t *>(imported_stl_list_[i].ptr), translation_list_[i], scale_stl_, imported_stl_list_[i].name));
body_mesh_list_.push_back(makeShared<TriangleMeshShapeGeneric>(reinterpret_cast<const uint8_t *>(imported_stl_list_[i].ptr), translation_list_[i], scale_stl_, imported_stl_list_[i].name));
#else
body_mesh_list_.push_back(makeShared<TriangleMeshShapeSTL>(relative_input_path_copy.append(imported_stl_list_[i]), translation_list_[i], scale_stl_, imported_stl_list_[i]));
body_mesh_list_.push_back(makeShared<TriangleMeshShapeGeneric>(relative_input_path_copy.append(imported_stl_list_[i]), translation_list_[i], scale_stl_, imported_stl_list_[i]));
#endif
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/for_3D_build/geometries/TriangleMeshDistance.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ inline tmd::Result tmd::TriangleMeshDistance::signed_distance(const std::array<d
Result result = this->unsigned_distance(p);

const std::array<int, 3> &triangle = this->triangles[result.triangle_id];
Vec3d pseudonormal;
Vec3d pseudonormal(0.0, 0.0, 0.0);
switch (result.nearest_entity)
{
case tmd::NearestEntity::V0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Beam : public ComplexShape
{
std::string fname_ = "./input/beam.stl";
Vecd translation(0.0, 0.0, 0.0);
add<TriangleMeshShapeSTL>(fname_, translation, 0.001);
add<TriangleMeshShapeGeneric>(fname_, translation, 0.001);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Heart : public ComplexShape
public:
explicit Heart(const std::string &shape_name) : ComplexShape(shape_name)
{
add<TriangleMeshShapeSTL>(full_path_to_myocardium, translation, length_scale);
add<TriangleMeshShapeGeneric>(full_path_to_myocardium, translation, length_scale);
}
};
/** Set diffusion relaxation method. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TriangleMeshShapeSTL>(stl_structure_path, translation_str, StructureScale));
StructureSystemForSimbody structure_multibody(structure, makeShared<TriangleMeshShapeGeneric>(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)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class FloatingStructure : public ComplexShape
public:
explicit FloatingStructure(const std::string &shape_name) : ComplexShape(shape_name)
{
add<TriangleMeshShapeSTL>(stl_structure_path, translation_str, StructureScale);
add<TriangleMeshShapeGeneric>(stl_structure_path, translation_str, StructureScale);
}
};

Expand Down Expand Up @@ -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<TransformShape<GeometricShapeBox>>(Transform(translation_water), halfsize_water);
subtract<TriangleMeshShapeSTL>(stl_structure_path, translation_str, StructureScale);
subtract<TriangleMeshShapeGeneric>(stl_structure_path, translation_str, StructureScale);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TriangleMeshShapeSTL>(full_path_to_file, translation, 1.0);
add<TriangleMeshShapeGeneric>(full_path_to_file, translation, 1.0);
}
};
//-----------------------------------------------------------------------------------------------------------
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ using namespace SPH;
Vec3d domain_upper_bound(2.3, 4.5, 0.3);
Vecd translation(0.0, 0.0, 0.0);
Real scaling = 1.0; */

//----------------------------------------------------------------------
// Setting for the second geometry.
// To use this, please commenting the setting for the first geometry.
Expand All @@ -40,18 +41,45 @@ Real scaling = 2.5;
//----------------------------------------------------------------------
BoundingBox system_domain_bounds(domain_lower_bound, domain_upper_bound);
Real dp_0 = (domain_upper_bound[0] - domain_lower_bound[0]) / 100.0;
//----------------------------------------------------------------------
// define the imported model.
//----------------------------------------------------------------------
//--------------------------------------------------------------------
class SolidBodyFromMesh : public ComplexShape
{
public:
explicit SolidBodyFromMesh(const std::string &shape_name) : ComplexShape(shape_name)
{
add<ExtrudeShape<TriangleMeshShapeSTL>>(4.0 * dp_0, full_path_to_file, translation, scaling);
subtract<TriangleMeshShapeSTL>(full_path_to_file, translation, scaling);
add<ExtrudeShape<TriangleMeshShapeGeneric>>(4.0 * dp_0, full_path_to_file, translation, scaling);
subtract<TriangleMeshShapeGeneric>(full_path_to_file, translation, scaling);
}
};
//----------------------------------------------------------------------
// Setting for the second geometry.
// To use this, please commenting the setting for the first geometry.
//----------------------------------------------------------------------
//std::string full_path_to_file = "./input/fluid.stl";
//----------------------------------------------------------------------
// Basic geometry parameters and numerical setup.
//----------------------------------------------------------------------
//Vec3d domain_lower_bound(-0.036, -0.046, -0.011);
//Vec3d domain_upper_bound(0.036, 0.093, 0.072);
//Vecd translation(0.0, 0.0, 0.0);
//Real scaling = 1.0;

//----------------------------------------------------------------------
// Below are common parts for the two test geometries.
//----------------------------------------------------------------------
//BoundingBox system_domain_bounds(domain_lower_bound, domain_upper_bound);
//Real dp_0 = (domain_upper_bound[0] - domain_lower_bound[0]) / 100.0;
//----------------------------------------------------------------------
// define the imported model.
//----------------------------------------------------------------------
//class SolidBodyFromMesh : public ComplexShape
//{
// public:
// explicit SolidBodyFromMesh(const std::string &shape_name) : ComplexShape(shape_name)
// {
// add<TriangleMeshShapeGeneric>(full_path_to_file, translation, scaling);
// }
//};
//-----------------------------------------------------------------------------------------------------------
// Main program starts here.
//-----------------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TriangleMeshShapeSTL>(full_path_to_lv, translation, length_scale);
add<TriangleMeshShapeGeneric>(full_path_to_lv, translation, length_scale);
}
};
/** Set diffusion relaxation. */
Expand Down
2 changes: 1 addition & 1 deletion tests/3d_examples/test_3d_self_contact/3d_self_contact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Coil : public ComplexShape
public:
explicit Coil(const std::string &shape_name) : ComplexShape(shape_name)
{
add<TriangleMeshShapeSTL>(full_path_to_file, Vecd::Zero(), 1.0);
add<TriangleMeshShapeGeneric>(full_path_to_file, Vecd::Zero(), 1.0);
}
};
class StationaryPlate : public ComplexShape
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ImportedShellModel : public ComplexShape
public:
explicit ImportedShellModel(const std::string &shape_name) : ComplexShape(shape_name)
{
add<TriangleMeshShapeSTL>(full_path_to_geometry, Vecd::Zero(), 1.0);
add<TriangleMeshShapeGeneric>(full_path_to_geometry, Vecd::Zero(), 1.0);
}
};
//--------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ TEST(BernoulliBeam20x, Pressure)
SharedPtr<SaintVenantKirchhoffSolid> material = makeShared<SaintVenantKirchhoffSolid>(rho_0, Youngs_modulus, poisson);
std::vector<SharedPtr<SaintVenantKirchhoffSolid>> material_model_list = {material};

SharedPtr<TriangleMeshShapeSTL> specimen = makeShared<TriangleMeshShapeSTL>("./input/bernoulli_beam_20x.stl", Vec3d::Zero(), scale_stl, "bernoulli_beam_20x");
SharedPtr<TriangleMeshShapeGeneric> specimen = makeShared<TriangleMeshShapeGeneric>("./input/bernoulli_beam_20x.stl", Vec3d::Zero(), scale_stl, "bernoulli_beam_20x");
BoundingBox fixation = specimen->getBounds();
fixation.second_[0] = fixation.first_[0] + 0.01;

Expand Down

0 comments on commit 9f12566

Please sign in to comment.