PeriDyno 1.0.0
Loading...
Searching...
No Matches
SparseMarchingCubes.cpp
Go to the documentation of this file.
2
4
6
7#include "VolumeHelper.h"
8
9namespace dyno
10{
11 template<typename TDataType>
13 : Node()
14 {
15 auto module = std::make_shared<GLSurfaceVisualModule>();
16 this->stateTriangleSet()->connect(module->inTriangleSet());
17 this->graphicsPipeline()->pushModule(module);
18 }
19
20 template<typename TDataType>
24
25 template<typename TDataType>
27 {
28 auto sv = this->getSparseVolume();
29
30 if (sv->stateSDFTopology()->isEmpty())
31 {
32 printf("SparseMarchingCubes: The import is empty! \n");
33 return;
34 }
35
36 Real isoValue = this->varIsoValue()->getData();
37
38 //auto sv = this->getSparseVolume();
39
40
41 auto octree = sv->stateSDFTopology()->getDataPtr();
42
43 DArray<Coord> ceilVertices;
44
45 octree->getCellVertices0(ceilVertices);
46
47 DArray<Real> sdfs;
48 DArray<Coord> normals;
49
50 octree->getSignDistanceMLS(ceilVertices, sdfs, normals, false);
51 //sv->getSignDistanceKernel(ceilVertices, sdfs);
52
53 //DArray3D<Real> distances(nx + 1, ny + 1, nz + 1);
54 DArray<uint> voxelVertNum(ceilVertices.size() / 8);
55
57 voxelVertNum,
58 ceilVertices,
59 sdfs,
60 isoValue);
61
62 Reduction<uint> reduce;
63 uint totalVNum = reduce.accumulate(voxelVertNum.begin(), voxelVertNum.size());
64
65 Scan<uint> scan;
66 scan.exclusive(voxelVertNum.begin(), voxelVertNum.size());
67
68 DArray<Coord> triangleVertices(totalVNum);
69
70 DArray<TopologyModule::Triangle> triangles(totalVNum / 3);
71
73 triangleVertices,
74 triangles,
75 voxelVertNum,
76 ceilVertices,
77 sdfs,
78 isoValue);
79
80 if (this->stateTriangleSet()->isEmpty()) {
81 this->stateTriangleSet()->setDataPtr(std::make_shared<TriangleSet<TDataType>>());
82 }
83
84 auto triSet = this->stateTriangleSet()->getDataPtr();
85 triSet->setPoints(triangleVertices);
86 triSet->setTriangles(triangles);
87
88 sdfs.clear();
89 normals.clear();
90 voxelVertNum.clear();
91 ceilVertices.clear();
92 triangleVertices.clear();
93 triangles.clear();
94 }
95
96 template<typename TDataType>
101
102 template<typename TDataType>
104 {
105 return this->getSparseVolume() != nullptr;
106 }
107
109}
#define DEFINE_CLASS(name)
Definition Object.h:140
static void countVerticeNumberForOctree(DArray< uint > &num, DArray< Coord > &vertices, DArray< Real > &sdfs, Real isoValue)
static void constructTrianglesForOctree(DArray< Coord > &triangleVertices, DArray< TopologyModule::Triangle > &triangles, DArray< uint > &num, DArray< Coord > &cellVertices, DArray< Real > &sdfs, Real isoValue)
std::shared_ptr< GraphicsPipeline > graphicsPipeline()
Definition Node.cpp:320
void reset()
Definition Node.cpp:183
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
unsigned int uint
Definition VkProgram.h:14