PeriDyno 1.0.0
Loading...
Searching...
No Matches
BasicShapeToVolume.cu
Go to the documentation of this file.
1#include "BasicShapeToVolume.h"
2
3//Basic shapes
4#include "BasicShapes/CubeModel.h"
5#include "BasicShapes/SphereModel.h"
6
7namespace dyno
8{
9 IMPLEMENT_TCLASS(BasicShapeToVolume, TDataType)
10
11 template<typename TDataType>
12 BasicShapeToVolume<TDataType>::BasicShapeToVolume()
13 : Volume<TDataType>()
14 {
15 this->varGridSpacing()->setRange(0.001f, 1.0f);
16 }
17
18 template<typename TDataType>
19 BasicShapeToVolume<TDataType>::~BasicShapeToVolume()
20 {
21
22 }
23
24 template<typename TDataType>
25 void BasicShapeToVolume<TDataType>::resetStates()
26 {
27 if (this->stateLevelSet()->isEmpty()){
28 this->stateLevelSet()->allocate();
29 }
30 convert();
31 }
32
33 template<typename TDataType>
34 bool BasicShapeToVolume<TDataType>::validateInputs()
35 {
36 return this->getShape() != nullptr;
37 }
38
39 template<typename TDataType>
40 void BasicShapeToVolume<TDataType>::convert()
41 {
42 auto levelset = this->stateLevelSet()->getDataPtr();
43
44 auto shape = this->getShape();
45
46 bool inverted = this->varInerted()->getValue();
47
48 Real h = this->varGridSpacing()->getValue();
49
50 BasicShapeType type = shape->getShapeType();
51
52 if (type == BasicShapeType::CUBE)
53 {
54 auto cubeModel = dynamic_cast<CubeModel<TDataType>*>(shape);
55
56 if (cubeModel != nullptr)
57 {
58 auto obb = cubeModel->outCube()->getValue();
59
60 auto aabb = obb.aabb();
61
62 auto& sdf = levelset->getSDF();
63
64 auto lo = aabb.v0;
65 auto hi = aabb.v1;
66
67 int nx = floor((hi[0] - lo[0]) / h);
68 int ny = floor((hi[1] - lo[1]) / h);
69 int nz = floor((hi[2] - lo[2]) / h);
70
71 uint padding = 5;
72
73 sdf.setSpace(lo - padding * h, hi + padding * h, h);
74 sdf.loadBox(aabb.v0, aabb.v1, inverted);
75 }
76 }
77 else if (type == BasicShapeType::SPHERE)
78 {
79 auto sphereModel = dynamic_cast<SphereModel<TDataType>*>(shape);
80
81 if (sphereModel != nullptr)
82 {
83 auto sphere = sphereModel->outSphere()->getValue();
84
85 auto aabb = sphere.aabb();
86
87 auto& sdf = levelset->getSDF();
88
89 auto lo = aabb.v0;
90 auto hi = aabb.v1;
91
92 int nx = floor((hi[0] - lo[0]) / h);
93 int ny = floor((hi[1] - lo[1]) / h);
94 int nz = floor((hi[2] - lo[2]) / h);
95
96 uint padding = 5;
97
98 sdf.setSpace(lo - padding * h, hi + padding * h, h);
99 sdf.loadSphere(sphere.center, sphere.radius, inverted);
100 }
101 }
102 else
103 {
104 std::cout << "Basic shape is not supported yet " << std::endl;
105 }
106 }
107
108 DEFINE_CLASS(BasicShapeToVolume);
109}