AGX Dynamics  2.37.3.2
MarchingCubes.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGX_MARCHINGCUBES_H
18 #define AGX_MARCHINGCUBES_H
19 
20 #if AGX_USE_OPENGL()
21 
22 #include <agx/config/AGX_USE_OPENGL.h>
23 #include <agx/agx_vector_types.h>
24 #include <agx/Referenced.h>
25 #include <agx/Vec3.h>
26 #include <agx/HashTable.h>
27 
28 namespace agx
29 {
31  {
32  public:
33  MarchingCubes(Real resolution, Real searchRadius, Real surfaceThreshold = -1);
34 
35  void clearParticles();
36  void addParticles(Vec3Vector& particlePositions);
37  const Vec3Vector& calculateSurface();
38  void drawCells();
39  void drawSurfaceVertices();
40 
41  protected:
42  virtual ~MarchingCubes();
43 
44  private:
45  class SamplingCell;
46  struct McVertex;
47  struct McCell;
48 
50  inline Vec3i calculateCellId(const Vec3& pos);
51 
52  private:
53  SamplingCellHash m_cellHash;
54  // Real m_searchRadius; // Not used yet.
55  Real m_cellSize;
56  Real m_invCellSize;
57  Real m_surfaceThreshold;
58  int m_sampleDimensions;
59  Vec3Vector m_surfaceVertices;
60  };
61 
62  struct AGXPHYSICS_EXPORT MarchingCubes::McVertex
63  {
64  McVertex() {}
65  McVertex(const Vec3& pos) : value(0), position(pos) {}
68  };
69 
70  struct AGXPHYSICS_EXPORT MarchingCubes::McCell
71  {
72  McCell() : type(-1) {}
73 
74  int type;
75  McVertex *vertices[8];
76 
77  void calculateType(Real surfaceThreshold);
78  void addSurfaceVertices(Vec3Vector& resultBuffer, Real invThreshold);
79  Vec3 interpolateEdgeVertex(int edge, Real invThreshold);
80  };
81 
82 
83  class AGXPHYSICS_EXPORT MarchingCubes::SamplingCell
84  {
85  public:
86 
87  SamplingCell(const Vec3i& id, Real size, int sampleDimensions, SamplingCellHash& cellHash);
88  ~SamplingCell();
89  inline const Vec3Vector& getParticles();
90  inline void clearParticles();
91  inline void addParticle(const Vec3& particlePosition);
92  inline const Vec3i& getId() const;
93 
94  void addNeighborConnections(SamplingCellHash& cellHash);
95  void removeNeighborConnections();
96  void calculateSurface(Real surfaceThreshold, Vec3Vector& vertexBuffer);
97 
98  inline McVertex *operator() (unsigned int x, unsigned int y, unsigned int z);
99 
100  SamplingCell **getNeighbors();
101 
102  void draw(Real surfaceThreshold);
103  private:
104  friend class MarchingCubes;
105  void updateSamplePoints(Real surfaceThreshold);
106 
107  Vec3i m_id;
108  Real m_size;
109  Vec3 m_offset;
110  SamplingCell *m_neighbors[26];
111  Vec3Vector m_particles;
112  Vector<McVertex> m_msVertices;
113  Vector<McCell> m_msCells;
114  unsigned int m_emptyCounter;
115  Vec3 m_innerBoundsMin;
116  Vec3 m_innerBoundsMax;
117  unsigned int m_sampleDimensions;
118  };
119 
120 
121 
123 }
124 
125 #endif
126 
127 #endif /* _AGX_MARCHINGCUBES_H_ */
#define m_size
Definition: Vector.h:429
Vec2i calculateCellId(Real x, Real y, Real invCellSize)
Definition: Vec2.h:72
#define AGXPHYSICS_EXPORT
Base class providing referencing counted objects.
Definition: Referenced.h:119
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
McVertex(const Vec3 &pos)
Definition: MarchingCubes.h:65
double Real
Definition: Real.h:42
Inheritance with partial specialization due to bug with ref_ptr containers.
ref_ptr< MarchingCubes > MarchingCubesRef