SPHinXsys  alpha version
triangle_mesh_shape.h
Go to the documentation of this file.
1 /* -------------------------------------------------------------------------*
2 * SPHinXsys *
3 * --------------------------------------------------------------------------*
4 * SPHinXsys (pronunciation: s'finksis) is an acronym from Smoothed Particle *
5 * Hydrodynamics for industrial compleX systems. It provides C++ APIs for *
6 * physical accurate simulation and aims to model coupled industrial dynamic *
7 * systems including fluid, solid, multi-body dynamics and beyond with SPH *
8 * (smoothed particle hydrodynamics), a meshless computational method using *
9 * particle discretization. *
10 * *
11 * SPHinXsys is partially funded by German Research Foundation *
12 * (Deutsche Forschungsgemeinschaft) DFG HU1527/6-1, HU1527/10-1 *
13 * and HU1527/12-1. *
14 * *
15 * Portions copyright (c) 2017-2020 Technical University of Munich and *
16 * the authors' affiliations. *
17 * *
18 * Licensed under the Apache License, Version 2.0 (the "License"); you may *
19 * not use this file except in compliance with the License. You may obtain a *
20 * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
21 * *
22 * --------------------------------------------------------------------------*/
31 #ifndef TRIANGULAR_MESH_SHAPE_H
32 #define TRIANGULAR_MESH_SHAPE_H
33 
34 #define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
35 
36 #include "base_geometry.h"
37 #include "simbody_middle.h"
38 
39 #include <iostream>
40 #include <string>
41 #include <fstream>
42 
44 #ifdef __APPLE__
45 #include <boost/filesystem.hpp>
46 namespace fs = boost::filesystem;
47 #else
48 #include <experimental/filesystem>
49 namespace fs = std::experimental::filesystem;
50 #endif
51 
52 namespace SPH
53 {
54  class TriangleMeshShape : public Shape
55  {
56  private:
58 
59  public:
60  explicit TriangleMeshShape(const std::string &shape_name, const SimTK::PolygonalMesh* mesh = nullptr)
61  : Shape(shape_name), triangle_mesh_(nullptr){
62  if(mesh)
63  triangle_mesh_ = generateTriangleMesh(*mesh);
64 
65  };
66 
67  virtual bool checkContain(const Vec3d &pnt, bool BOUNDARY_INCLUDED = true) override;
68  virtual Vec3d findClosestPoint(const Vec3d &input_pnt) override;
69 
70  SimTK::ContactGeometry::TriangleMesh *getTriangleMesh() { return triangle_mesh_; };
71 
72  protected:
73  SimTK::ContactGeometry::TriangleMesh *triangle_mesh_;
74 
75  //generate triangle mesh from polymesh
76  SimTK::ContactGeometry::TriangleMesh *generateTriangleMesh(const SimTK::PolygonalMesh &poly_mesh);
77  virtual BoundingBox findBounds() override;
78  };
79 
81  {
82  public:
83  //constructor for load STL file from out side
84  explicit TriangleMeshShapeSTL(const std::string &file_path_name, Vec3d translation, Real scale_factor,
85  const std::string &shape_name = "TriangleMeshShapeSTL");
86  // constructor overloaded to include rotation
87  explicit TriangleMeshShapeSTL(const std::string &file_path_name, Mat3d rotation, Vec3d translation,
88  Real scale_factor, const std::string &shape_name = "TriangleMeshShapeSTL");
89  #ifdef __EMSCRIPTEN__
90  //constructor for load stl file from buffer
91  TriangleMeshShapeSTL(const uint8_t* buffer, Vec3d translation, Real scale_factor, const std::string &shape_name = "TriangleMeshShapeSTL");
92  #endif
93  virtual ~TriangleMeshShapeSTL(){};
94  };
95 
97  {
98  public:
100  {
101  public:
102  ShapeParameters() : halfsize_(0), resolution_(0), translation_(0) {};
103  Vec3d halfsize_;
104  int resolution_;
105  Vec3d translation_;
106  };
107  explicit TriangleMeshShapeBrick(Vec3d halfsize, int resolution, Vec3d translation,
108  const std::string &shape_name = "TriangleMeshShapeBrick");
109  explicit TriangleMeshShapeBrick(const TriangleMeshShapeBrick::ShapeParameters &shape_parameters,
110  const std::string &shape_name = "TriangleMeshShapeBrick");
111  virtual ~TriangleMeshShapeBrick(){};
112  };
113 
115  {
116  public:
117  //constructor for sphere shape
118  explicit TriangleMeshShapeSphere(Real radius, int resolution, Vec3d translation,
119  const std::string &shape_name = "TriangleMeshShapeSphere");
120  virtual ~TriangleMeshShapeSphere(){};
121  };
122 
124  {
125  public:
126  //constructor for cylinder shape
127  explicit TriangleMeshShapeCylinder(SimTK::UnitVec3 axis, Real radius, Real halflength, int resolution, Vec3d translation,
128  const std::string &shape_name = "TriangleMeshShapeCylinder");
129  virtual ~TriangleMeshShapeCylinder(){};
130  };
131 }
132 
133 #endif //TRIANGULAR_MESH_SHAPE_H
Definition: triangle_mesh_shape.h:96
Base class for all volumetric geometries Note that checkContain and findClosest point are basic funct...
Definition: base_geometry.h:64
Definition: triangle_mesh_shape.h:80
Definition: triangle_mesh_shape.h:123
Definition: triangle_mesh_shape.h:99
Definition: triangle_mesh_shape.h:54
virtual bool checkContain(const Vec3d &pnt, bool BOUNDARY_INCLUDED=true) override
Definition: triangle_mesh_shape.cpp:22
Shape is the base class for all geometries.
Definition: triangle_mesh_shape.h:114
Definition: solid_body_supplementary.cpp:9
file to include Simbody headers and suppress their warnings