Choreonoid  1.8
MeshGenerator.h
Go to the documentation of this file.
1 
6 #ifndef CNOID_UTIL_MESH_GENERATOR_H
7 #define CNOID_UTIL_MESH_GENERATOR_H
8 
9 #include "EigenTypes.h"
10 #include "SceneDrawables.h"
11 #include "exportdecl.h"
12 
13 namespace cnoid {
14 
15 class MeshFilter;
16 
17 class CNOID_EXPORT MeshGenerator
18 {
19 public:
20  MeshGenerator();
21  MeshGenerator(const MeshGenerator& org);
22  ~MeshGenerator();
23 
24  void setDivisionNumber(int n);
25  int divisionNumber() const { return divisionNumber_; }
26  static int defaultDivisionNumber();
27 
28  // Deprecated. Use SgMesh::setExtraDivisionNumber and SgMesh::setExtraDivisionMode
31  extraDivisionNumber_ = n;
32  extraDivisionMode_ = mode;
33  }
34  int extraDivisionNumber() const { return extraDivisionNumber_; }
35  int extraDivisionMode() const { return extraDivisionMode_; }
36 
37  void setNormalGenerationEnabled(bool on);
38  [[deprecated("Use setNormalGenerationEnabled")]]
39  void enableNormalGeneration(bool on);
40  bool isNormalGenerationEnabled() const;
41 
42  void setBoundingBoxUpdateEnabled(bool on);
43  bool isBoundingBoxUpdateEnabled() const;
44 
45  enum MeshOption {
46  NoOption = 0,
47  TextureCoordinate = 1
48  };
49 
50  bool updateMeshWithPrimitiveInformation(SgMesh* mesh, int options = NoOption);
51 
52  SgMesh* generateBox(const Vector3& size, int options = NoOption);
53  SgMesh* generateSphere(double radius, int options = NoOption);
54  SgMesh* generateCylinder(double radius, double height, int options = NoOption);
55  SgMesh* generateCone(double radius, double height, int options = NoOption);
56  SgMesh* generateCapsule(double radius, double height);
57  SgMesh* generateDisc(double radius, double innerRadius);
58  SgMesh* generateArrow(double cylinderRadius, double cylinderHeight, double coneRadius, double coneHeight);
59  SgMesh* generateTorus(double radius, double crossSectionRadius);
60  SgMesh* generateTorus(double radius, double crossSectionRadius, double beginAngle, double endAngle);
61 
62  typedef std::vector<Vector2, Eigen::aligned_allocator<Vector2>> Vector2Array;
63  typedef std::vector<Vector3, Eigen::aligned_allocator<Vector3>> Vector3Array;
64  typedef std::vector<AngleAxis, Eigen::aligned_allocator<AngleAxis>> AngleAxisArray;
65 
66  struct Extrusion
67  {
72  double creaseAngle;
73  bool beginCap;
74  bool endCap;
76  creaseAngle = 0.0;
77  beginCap = true;
78  endCap = true;
79  }
80  };
81 
82  SgMesh* generateExtrusion(const Extrusion& extrusion, int meshOptions = NoOption);
83  SgLineSet* generateExtrusionLineSet(const Extrusion& extrusion, SgMesh* mesh);
84 
86  {
89  double xSpacing;
90  double zSpacing;
91  std::vector<double> height;
92  bool ccw;
93  double creaseAngle;
95  xDimension = 0;
96  zDimension = 0;
97  xSpacing = 1.0;
98  zSpacing = 1.0;
99  ccw = true;
100  creaseAngle = 0.0;
101  }
102  };
103 
104  SgMesh* generateElevationGrid(const ElevationGrid& elevationGrid, int meshOptions = NoOption);
105 
106  void generateTextureCoordinateForIndexedFaceSet(SgMeshBase* mesh);
107 
108 private:
109  int divisionNumber_;
110  int extraDivisionNumber_;
111  int extraDivisionMode_;
112  bool isNormalGenerationEnabled_;
113  bool isBoundingBoxUpdateEnabled_;
114  MeshFilter* meshFilter;
115 
116  MeshFilter* getOrCreateMeshFilter();
117  void generateNormals(SgMesh* mesh, double creaseAngle);
118  bool generateBox(SgMesh* mesh, int options);
119  bool generateBoxWithExtraTriangles(SgMesh* mesh);
120  void generateTextureCoordinateForBox(SgMesh* mesh);
121  void generateBoxPlaneMesh(
122  const Vector3& size, SgMesh* mesh, SgVertexArray* vertices, int axis1, int axis2, int axis3, int* divisions);
123  bool generateSphere(SgMesh* mesh, int options);
124  bool generateCylinder(SgMesh* mesh, int options);
125  bool generateCone(SgMesh* mesh, int options);
126  bool generateCapsule(SgMesh* mesh);
127  void generateTextureCoordinateForSphere(SgMesh* mesh);
128  void generateTextureCoordinateForCylinder(SgMesh* mesh);
129  void generateTextureCoordinateForCone(SgMesh* mesh);
130  void generateTextureCoordinateForExtrusion(
131  SgMesh* mesh, const Vector2Array& crossSections, const Vector3Array& spinePoints,
132  int numTriOfbeginCap, int numTriOfendCap, int indexOfendCap);
133  void generateTextureCoordinateForElevationGrid(SgMesh* mesh, const ElevationGrid& grid);
134 };
135 
136 }
137 
138 #endif
cnoid::MeshGenerator::Vector2Array
std::vector< Vector2, Eigen::aligned_allocator< Vector2 > > Vector2Array
Definition: MeshGenerator.h:62
cnoid::MeshGenerator::extraDivisionNumber
int extraDivisionNumber() const
Definition: MeshGenerator.h:34
cnoid::MeshGenerator::Extrusion::orientation
AngleAxisArray orientation
Definition: MeshGenerator.h:70
cnoid::Vector3
Eigen::Vector3d Vector3
Definition: EigenTypes.h:57
cnoid::MeshGenerator::ElevationGrid::height
std::vector< double > height
Definition: MeshGenerator.h:91
cnoid::SgMesh
Definition: SceneDrawables.h:337
cnoid::MeshGenerator::MeshOption
MeshOption
Definition: MeshGenerator.h:45
SceneDrawables.h
cnoid::MeshGenerator::ElevationGrid
Definition: MeshGenerator.h:85
cnoid::SgLineSet
Definition: SceneDrawables.h:660
cnoid::SgVectorArray< Vector3f >
cnoid::MeshFilter
Definition: MeshFilter.h:17
cnoid::MeshGenerator
Definition: MeshGenerator.h:17
cnoid::MeshGenerator::extraDivisionMode
int extraDivisionMode() const
Definition: MeshGenerator.h:35
cnoid::MeshGenerator::ElevationGrid::zDimension
int zDimension
Definition: MeshGenerator.h:88
cnoid::SgMesh::ExtraDivisionPreferred
@ ExtraDivisionPreferred
Definition: SceneDrawables.h:476
cnoid::MeshGenerator::divisionNumber
int divisionNumber() const
Definition: MeshGenerator.h:25
cnoid::MeshGenerator::Extrusion::endCap
bool endCap
Definition: MeshGenerator.h:74
cnoid::MeshGenerator::Extrusion::creaseAngle
double creaseAngle
Definition: MeshGenerator.h:72
cnoid::MeshGenerator::ElevationGrid::creaseAngle
double creaseAngle
Definition: MeshGenerator.h:93
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::MeshGenerator::Extrusion::crossSection
Vector2Array crossSection
Definition: MeshGenerator.h:68
cnoid::MeshGenerator::ElevationGrid::xDimension
int xDimension
Definition: MeshGenerator.h:87
cnoid::MeshGenerator::Extrusion::beginCap
bool beginCap
Definition: MeshGenerator.h:73
cnoid::MeshGenerator::Extrusion::Extrusion
Extrusion()
Definition: MeshGenerator.h:75
cnoid::MeshGenerator::Extrusion::spine
Vector3Array spine
Definition: MeshGenerator.h:69
cnoid::MeshGenerator::ElevationGrid::zSpacing
double zSpacing
Definition: MeshGenerator.h:90
cnoid::MeshGenerator::setExtraDivisionNumber
void setExtraDivisionNumber(int n, int mode=SgMesh::ExtraDivisionPreferred)
Definition: MeshGenerator.h:30
EigenTypes.h
cnoid::SgMeshBase
Definition: SceneDrawables.h:256
cnoid::MeshGenerator::Extrusion
Definition: MeshGenerator.h:66
cnoid::MeshGenerator::ElevationGrid::ccw
bool ccw
Definition: MeshGenerator.h:92
cnoid::MeshGenerator::Extrusion::scale
Vector2Array scale
Definition: MeshGenerator.h:71
cnoid::MeshGenerator::ElevationGrid::xSpacing
double xSpacing
Definition: MeshGenerator.h:89
cnoid::MeshGenerator::AngleAxisArray
std::vector< AngleAxis, Eigen::aligned_allocator< AngleAxis > > AngleAxisArray
Definition: MeshGenerator.h:64
cnoid::MeshGenerator::ElevationGrid::ElevationGrid
ElevationGrid()
Definition: MeshGenerator.h:94
cnoid::MeshGenerator::Vector3Array
std::vector< Vector3, Eigen::aligned_allocator< Vector3 > > Vector3Array
Definition: MeshGenerator.h:63