PeriDyno 1.2.1
Loading...
Searching...
No Matches
MarchingCubes.cpp
Go to the documentation of this file.
1#include "MarchingCubes.h"
2
4
6
7namespace dyno
8{
9 template<typename TDataType>
11 : Node()
12 {
13 this->varGridSpacing()->setRange(0.001, 1.0);
14
15 auto renderer = std::make_shared<GLSurfaceVisualModule>();
16 this->stateTriangleSet()->connect(renderer->inTriangleSet());
17 this->graphicsPipeline()->pushModule(renderer);
18 }
19
20 template<typename TDataType>
24
25
26 template<typename TDataType>
28 {
29
30 auto sdfTopo = this->inLevelSet()->getDataPtr();
31 auto isoValue = this->varIsoValue()->getData();
32
33 auto& sdf = sdfTopo->getSDF();
34
35 Coord lowerBound = sdf.lowerBound();
36 Coord upperBound = sdf.upperBound();
37
38 Real h = this->varGridSpacing()->getData();
39
40 int nx = (upperBound[0] - lowerBound[0]) / h;
41 int ny = (upperBound[1] - lowerBound[1]) / h;
42 int nz = (upperBound[2] - lowerBound[2]) / h;
43
44 DArray3D<Real> distances(nx + 1, ny + 1, nz + 1);
45 DArray<int> voxelVertNum(nx * ny * nz);
46
48 distances,
49 lowerBound,
50 h,
51 sdf);
52
54 voxelVertNum,
55 distances,
56 isoValue,
57 h);
58
59 Reduction<int> reduce;
60 int totalVNum = reduce.accumulate(voxelVertNum.begin(), voxelVertNum.size());
61
62 Scan<int> scan;
63 scan.exclusive(voxelVertNum.begin(), voxelVertNum.size());
64
65 DArray<Coord> vertices(totalVNum);
66
67 DArray<TopologyModule::Triangle> triangles(totalVNum / 3);
68
70 vertices,
71 triangles,
72 voxelVertNum,
73 distances,
74 lowerBound,
75 isoValue,
76 h);
77
78 if (this->stateTriangleSet()->isEmpty()) {
79 this->stateTriangleSet()->setDataPtr(std::make_shared<TriangleSet<TDataType>>());
80 }
81
82 auto triSet = this->stateTriangleSet()->getDataPtr();
83 triSet->setPoints(vertices);
84 triSet->setTriangles(triangles);
85 triSet->update();
86
87 distances.clear();
88 voxelVertNum.clear();
89 vertices.clear();
90 triangles.clear();
91 }
92
93
94 template<typename TDataType>
99
100
101 template<typename TDataType>
106
108}
#define DEFINE_CLASS(name)
Definition Object.h:140
static void countVerticeNumber(DArray< int > &num, DArray3D< Real > &distances, Real isoValue, Real h)
static void reconstructSDF(DArray3D< Real > &distances, Coord origin, Real h, DistanceField3D< TDataType > &sdf)
static void constructTriangles(DArray< Coord > &vertices, DArray< TopologyModule::Triangle > &triangles, DArray< int > &vertNum, DArray3D< Real > &distances, Coord origin, Real isoValue, Real h)
void resetStates() override
void updateStates() override
TDataType::Real Real
TDataType::Coord Coord
std::shared_ptr< GraphicsPipeline > graphicsPipeline()
Definition Node.cpp:311
T accumulate(const T *val, const uint num)
void exclusive(T *output, const T *input, size_t length, bool bcao=true)
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
Array< T, DeviceType::GPU > DArray
Definition Array.inl:89
Array3D< T, DeviceType::GPU > DArray3D
Definition Array3D.inl:90