PeriDyno 1.2.1
Loading...
Searching...
No Matches
PointFromCurve.cpp
Go to the documentation of this file.
1#include "PointFromCurve.h"
2
6
7
8
9namespace dyno
10{
11 template<typename TDataType>
13 : ParametricModel<TDataType>()
14 {
15
16 this->varScale()->setRange(0.001f, 10.0f);
17
18 this->statePointSet()->setDataPtr(std::make_shared<PointSet<TDataType>>());
19 this->stateEdgeSet()->setDataPtr(std::make_shared<EdgeSet<TDataType>>());
20
21 this->statePointSet()->promoteOuput();
22
23 auto pointGlModule = std::make_shared<GLPointVisualModule>();
24 this->statePointSet()->connect(pointGlModule->inPointSet());
25 this->graphicsPipeline()->pushModule(pointGlModule);
26 pointGlModule->varPointSize()->setValue(0.01);
27
28 auto wireframe = std::make_shared<GLWireframeVisualModule>();
29 this->stateEdgeSet()->connect(wireframe->inEdgeSet());
30 this->graphicsPipeline()->pushModule(wireframe);
31 wireframe->setColor(Color(1, 1, 0));
32 wireframe->varLineWidth()->setValue(0.1);
33 wireframe->varRenderMode()->setCurrentKey(1);
34
35 this->statePointSet()->promoteOuput();
36 auto curve = this->varCurve()->getValue();
37 this->varCurve()->setValue(curve);
38
39 auto callback = std::make_shared<FCallBackFunc>(std::bind(&PointFromCurve<TDataType>::varChanged, this));
40
41 this->varLocation()->attach(callback);
42 this->varScale()->attach(callback);
43 this->varRotation()->attach(callback);
44
45 this->varUniformScale()->attach(callback);
46 this->varCurve()->attach(callback);
47
48
49 }
50
51 template<typename TDataType>
56
57 template<typename TDataType>
59 {
60 auto center = this->varLocation()->getData();
61 auto rot = this->varRotation()->getData();
62 auto scale = this->varScale()->getData();
63 auto uniformScale = this->varUniformScale()->getData();
64 auto pointSet = this->statePointSet()->getDataPtr();
65 auto curve = this->varCurve()->getValue();
66 auto floatCoord = curve.getPoints();
67 int length = floatCoord.size();
68 std::vector<Coord> vertices;
69
70
71 Coord Location;
72 if (length != 0)
73 {
74 for (size_t i = 0; i < length; i++)
75 {
76 Location = Coord(floatCoord[i].x, floatCoord[i].y, 0);
77
78 vertices.push_back(Location);
79 }
80 }
81
82 if (curve.getClose() && curve.getResample() == true && vertices.size()>=3)
83 {
84
85 vertices.erase(vertices.end() - 1);
86
87 }
88
89 //Transform Coord
90
91 Quat<Real> q2 = this->computeQuaternion();
92
93 q2.normalize();
94
95 auto RVt = [&](const Coord& v)->Coord {
96 return center + q2.rotate(v - center);
97 };
98
99 int numpt = vertices.size();
100
101 for (int i = 0; i < numpt; i++)
102 {
103
104 vertices[i] = RVt(vertices[i] * scale * uniformScale + RVt(center));
105 }
106
107 int s = vertices.size();
108
109 pointSet->setPoints(vertices);
110
111 // create EdgeSet
112 {
113 std::vector<TopologyModule::Edge> edges;
114
115 auto edgeSet = this->stateEdgeSet()->getDataPtr();
116
117 int ptnum = vertices.size();
118
119 if (ptnum >= 2)
120 {
121 for (int i = 0; i < ptnum - 1; i++)
122 {
123 edges.push_back(TopologyModule::Edge(i, i + 1));
124 }
125 }
126
127 if (curve.getClose() == true && vertices.size()>=3)
128 {
129 edges.push_back(TopologyModule::Edge(vertices.size()-1,0));
130 }
131
132 edgeSet->setPoints(vertices);
133 edgeSet->setEdges(edges);
134
135
136 vertices.clear();
137 edges.clear();
138
139 }
140
141 }
142
144}
#define DEFINE_CLASS(name)
Definition Object.h:140
std::shared_ptr< GraphicsPipeline > graphicsPipeline()
Definition Node.cpp:311
Quat< Real > computeQuaternion()
void resetStates() override
TDataType::Coord Coord
A PointSet stores the coordinates for a set of independent points.
Definition PointSet.h:8
DYN_FUNC Quat< Real > & normalize()
Definition Quat.inl:183
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
VectorND< PointType, 2 > Edge
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25