1#include "BasicShapeToVolume.h"
4#include "BasicShapes/CubeModel.h"
5#include "BasicShapes/SphereModel.h"
9 IMPLEMENT_TCLASS(BasicShapeToVolume, TDataType)
11 template<typename TDataType>
12 BasicShapeToVolume<TDataType>::BasicShapeToVolume()
15 this->varGridSpacing()->setRange(0.001f, 1.0f);
18 template<typename TDataType>
19 BasicShapeToVolume<TDataType>::~BasicShapeToVolume()
24 template<typename TDataType>
25 void BasicShapeToVolume<TDataType>::resetStates()
27 if (this->stateLevelSet()->isEmpty()){
28 this->stateLevelSet()->allocate();
33 template<typename TDataType>
34 bool BasicShapeToVolume<TDataType>::validateInputs()
36 return this->getShape() != nullptr;
39 template<typename TDataType>
40 void BasicShapeToVolume<TDataType>::convert()
42 auto levelset = this->stateLevelSet()->getDataPtr();
44 auto shape = this->getShape();
46 bool inverted = this->varInerted()->getValue();
48 Real h = this->varGridSpacing()->getValue();
50 BasicShapeType type = shape->getShapeType();
52 if (type == BasicShapeType::CUBE)
54 auto cubeModel = dynamic_cast<CubeModel<TDataType>*>(shape);
56 if (cubeModel != nullptr)
58 auto obb = cubeModel->outCube()->getValue();
60 auto aabb = obb.aabb();
62 auto& sdf = levelset->getSDF();
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);
73 sdf.setSpace(lo - padding * h, hi + padding * h, h);
74 sdf.loadBox(aabb.v0, aabb.v1, inverted);
77 else if (type == BasicShapeType::SPHERE)
79 auto sphereModel = dynamic_cast<SphereModel<TDataType>*>(shape);
81 if (sphereModel != nullptr)
83 auto sphere = sphereModel->outSphere()->getValue();
85 auto aabb = sphere.aabb();
87 auto& sdf = levelset->getSDF();
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);
98 sdf.setSpace(lo - padding * h, hi + padding * h, h);
99 sdf.loadSphere(sphere.center, sphere.radius, inverted);
104 std::cout << "Basic shape is not supported yet " << std::endl;
108 DEFINE_CLASS(BasicShapeToVolume);