AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
MarchingCubes.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx 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>
24#include <agx/Referenced.h>
25#include <agx/Vec3.h>
26#include <agx/HashTable.h>
27
28namespace agx
29{
31 {
32 public:
33 MarchingCubes(Real resolution, Real searchRadius, Real surfaceThreshold = -1);
34
36 void addParticles(Vec3Vector& particlePositions);
38 void drawCells();
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 {
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);
89 inline const Vec3Vector& getParticles();
90 inline void clearParticles();
91 inline void addParticle(const Vec3& particlePosition);
92 inline const Vec3i& getId() const;
93
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 AGXPHYSICS_EXPORT
#define m_size
Definition agx/Vector.h:429
Inheritance with partial specialization due to bug with ref_ptr containers.
MarchingCubes(Real resolution, Real searchRadius, Real surfaceThreshold=-1)
void draw(Real surfaceThreshold)
const Vec3i & getId() const
const Vec3Vector & getParticles()
void calculateSurface(Real surfaceThreshold, Vec3Vector &vertexBuffer)
void drawSurfaceVertices()
virtual ~MarchingCubes()
Vec3 interpolateEdgeVertex(int edge, Real invThreshold)
void addSurfaceVertices(Vec3Vector &resultBuffer, Real invThreshold)
void calculateType(Real surfaceThreshold)
void addParticle(const Vec3 &particlePosition)
SamplingCell(const Vec3i &id, Real size, int sampleDimensions, SamplingCellHash &cellHash)
void addParticles(Vec3Vector &particlePositions)
SamplingCell ** getNeighbors()
void removeNeighborConnections()
void addNeighborConnections(SamplingCellHash &cellHash)
McVertex(const Vec3 &pos)
const Vec3Vector & calculateSurface()
Base class providing referencing counted objects.
Definition Referenced.h:120
Templated vector class.
Definition agx/Vector.h:53
Smart pointer for handling referenced counted objects.
Definition ref_ptr.h:30
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
ref_ptr< MarchingCubes > MarchingCubesRef
double Real
Definition Real.h:42
Vec2i calculateCellId(Real x, Real y, Real invCellSize)
Definition Vec2.h:72