PeriDyno 1.0.0
Loading...
Searching...
No Matches
ShapeSampler.cpp
Go to the documentation of this file.
1#include "ShapeSampler.h"
2
5
6namespace dyno
7{
8 template<typename TDataType>
10 : Sampler<TDataType>()
11 {
12 this->varSamplingDistance()->setRange(0.001, 1.0);
13 }
14
15 template<typename TDataType>
17 {
18 auto shape = this->getShape();
19
20 if (shape == nullptr) return;
21
22 auto shapeType = shape->getShapeType();
23 if (shapeType == BasicShapeType::CUBE)
24 {
25 auto model = dynamic_cast<CubeModel<TDataType>*>(shape);
26
27 if (model == nullptr) return;
28
29 auto box = model->outCube()->getValue();
30 Coord u = box.u;
31 Coord v = box.v;
32 Coord w = box.w;
33
34 Coord ext = box.extent;
35 Coord center = box.center;
36
37 Real s = std::max(Real(0.001), this->varSamplingDistance()->getData());
38
39 int nx = ext[0] / s;
40 int ny = ext[1] / s;
41 int nz = ext[2] / s;
42
43 std::vector<Coord> points;
44 for (int i = -nx; i <= nx; i++)
45 {
46 for (int j = -ny; j <= ny; j++)
47 {
48 for (int k = -nz; k <= nz; k++)
49 {
50 Coord p = center + (i * s) * u + (j * s) * v + (k * s) * w;
51 points.push_back(p);
52 }
53 }
54 }
55
56 auto ptSet = this->statePointSet()->getDataPtr();
57
58 ptSet->setPoints(points);
59
60 points.clear();
61 }
62 else if (shapeType == BasicShapeType::SPHERE)
63 {
64 auto model = dynamic_cast<SphereModel<TDataType>*>(shape);
65
66 if (model == nullptr) return;
67
68 auto sphere = model->outSphere()->getValue();
69 Real r = sphere.radius;
70 Coord center = sphere.center;
71 Real distance = this->varSamplingDistance()->getValue();
72
73 std::vector<Coord> points;
74 for (Real x = center[0] - r; x < center[0] + r; x += distance) {
75 for (Real y = center[1] - r; y < center[1] + r; y += distance) {
76 for (Real z = center[2] - r; z < center[2] + r; z += distance)
77 {
78 Real h = (Coord(x, y, z) - center).norm();
79 if (h < r)
80 {
81 points.push_back(Coord(x, y, z));
82 }
83 }
84 }
85 }
86
87 auto ptSet = this->statePointSet()->getDataPtr();
88 ptSet->setPoints(points);
89 points.clear();
90 }
91
92 }
93
95}
#define DEFINE_CLASS(name)
Definition Object.h:140
double Real
Definition Typedef.inl:23
TDataType::Coord Coord
void resetStates() override
TDataType::Real Real
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
@ SPHERE
Definition BasicShape.h:26
@ CUBE
Definition BasicShape.h:25