PeriDyno 1.0.0
Loading...
Searching...
No Matches
VolumeClipper.cpp
Go to the documentation of this file.
1#include "VolumeClipper.h"
2
4
5#include "ColorMapping.h"
7
8namespace dyno
9{
10 template<typename TDataType>
12 : Node()
13 {
14 this->stateTriangleSet()->setDataPtr(std::make_shared<TriangleSet<TDataType>>());
15
16 auto colorMapper = std::make_shared<ColorMapping<DataType3f>>();
17 colorMapper->varMin()->setValue(-0.5);
18 colorMapper->varMax()->setValue(0.5);
19 this->stateField()->connect(colorMapper->inScalar());
20 this->graphicsPipeline()->pushModule(colorMapper);
21 //
22 //
23 auto surfaceVisualizer = std::make_shared<GLSurfaceVisualModule>();
24 surfaceVisualizer->varColorMode()->getDataPtr()->setCurrentKey(1);
25 colorMapper->outColor()->connect(surfaceVisualizer->inColor());
26 this->stateTriangleSet()->connect(surfaceVisualizer->inTriangleSet());
27 this->graphicsPipeline()->pushModule(surfaceVisualizer);
28 }
29
30 template<typename TDataType>
34
35 template<typename TDataType>
37 {
38 auto center = this->varTranslation()->getValue();
39 auto eulerAngles = this->varRotation()->getValue();
40
41 eulerAngles /= 180.0f;
42 eulerAngles *= M_PI;
43
44 auto levelSet = this->inLevelSet()->getDataPtr()->getSDF();
45
46 Coord lo = levelSet.lowerBound();
47 Coord hi = levelSet.upperBound();
48
49 Quat<Real> q = Quat<Real>::fromEulerAngles(eulerAngles[0], eulerAngles[1], eulerAngles[2]);
50
51 int nx = levelSet.nx() - 1;
52 int ny = levelSet.ny() - 1;
53 int nz = levelSet.nz() - 1;
54
55 DArray<int> voxelVertNum(nx * ny * nz);
56
57 Coord shifted_center = center + 0.5 * (lo + hi);
58
59 MarchingCubesHelper<TDataType>::countVerticeNumberForClipper(voxelVertNum, levelSet, TPlane3D<Real>(shifted_center, q.rotate(Coord(0, 1, 0))));
60
61 Reduction<int> reduce;
62 int totalVNum = reduce.accumulate(voxelVertNum.begin(), voxelVertNum.size());
63
64 Scan<int> scan;
65 scan.exclusive(voxelVertNum.begin(), voxelVertNum.size());
66
67 this->stateField()->resize(totalVNum);
68
69 DArray<Coord> vertices(totalVNum);
70
71 DArray<TopologyModule::Triangle> triangles(totalVNum / 3);
72
74 this->stateField()->getData(),
75 vertices,
76 triangles,
77 voxelVertNum,
78 levelSet,
79 TPlane3D<Real>(shifted_center, q.rotate(Coord(0, 1, 0))));
80
81 auto triSet = this->stateTriangleSet()->getDataPtr();
82 triSet->setPoints(vertices);
83 triSet->setTriangles(triangles);
84 triSet->update();
85
86 voxelVertNum.clear();
87 vertices.clear();
88 triangles.clear();
89 }
90
92}
#define DEFINE_CLASS(name)
Definition Object.h:140
#define M_PI
Definition Typedef.inl:36
static void constructTrianglesForClipper(DArray< Real > &field, DArray< Coord > &vertices, DArray< TopologyModule::Triangle > &triangles, DArray< int > &vertNum, DistanceField3D< TDataType > &sdf, TPlane3D< Real > plane)
static void countVerticeNumberForClipper(DArray< int > &num, DistanceField3D< TDataType > &sdf, TPlane3D< Real > plane)
std::shared_ptr< GraphicsPipeline > graphicsPipeline()
Definition Node.cpp:320
static DYN_FUNC Quat< Real > fromEulerAngles(const Real &yaw, const Real &pitch, const Real &roll)
Definition Quat.h:105
DYN_FUNC Vector< Real, 3 > rotate(const Vector< Real, 3 > &v) const
Rotate a vector by the quaternion, guarantee the quaternion is normalized before rotating the vector.
Definition Quat.inl:259
T accumulate(const T *val, const uint num)
void exclusive(T *output, const T *input, size_t length, bool bcao=true)
2D geometric primitives in three-dimensional space
TDataType::Coord Coord
void resetStates() override
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
Array< T, DeviceType::GPU > DArray
Definition Array.inl:89