PeriDyno 1.2.1
Loading...
Searching...
No Matches
VolumeToTriangleSet.cpp
Go to the documentation of this file.
2
4
5namespace dyno
6{
7 template<typename TDataType>
13
14 template<typename TDataType>
19
20 template<typename TDataType>
22 {
23 Real iso = this->varIsoValue()->getValue();
24
25 auto levelset = this->inVolume()->constDataPtr();
26
27 auto& sdf = levelset->getSDF();
28
29 Coord lowerBound = sdf.lowerBound();
30 Coord upperBound = sdf.upperBound();
31
32 Real h = sdf.getGridSpacing();
33
34 if (h < EPSILON)
35 return false;
36
37 int nx = (upperBound[0] - lowerBound[0]) / h;
38 int ny = (upperBound[1] - lowerBound[1]) / h;
39 int nz = (upperBound[2] - lowerBound[2]) / h;
40
41 DArray3D<Real> distances(nx + 1, ny + 1, nz + 1);
42 DArray<int> voxelVertNum(nx * ny * nz);
43
45 distances,
46 lowerBound,
47 h,
48 sdf);
49
51 voxelVertNum,
52 distances,
53 iso,
54 h);
55
56 Reduction<int> reduce;
57 int totalVNum = reduce.accumulate(voxelVertNum.begin(), voxelVertNum.size());
58
59 Scan<int> scan;
60 scan.exclusive(voxelVertNum.begin(), voxelVertNum.size());
61
62 DArray<Coord> vertices(totalVNum);
63
64 DArray<TopologyModule::Triangle> triangles(totalVNum / 3);
65
67 vertices,
68 triangles,
69 voxelVertNum,
70 distances,
71 lowerBound,
72 iso,
73 h);
74
75 if (this->outTriangleSet()->isEmpty()) {
76 this->outTriangleSet()->allocate();
77 }
78
79 auto triSet = this->outTriangleSet()->getDataPtr();
80 triSet->setPoints(vertices);
81 triSet->setTriangles(triangles);
82 triSet->update();
83
84 distances.clear();
85 voxelVertNum.clear();
86 vertices.clear();
87 triangles.clear();
88
89 return true;
90 }
91
93}
#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)
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
constexpr Real EPSILON
Definition Typedef.inl:42
Array3D< T, DeviceType::GPU > DArray3D
Definition Array3D.inl:90