PeriDyno 1.0.0
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 curve.setUseSquard(true);
38 this->varCurve()->setValue(curve);
39
40 auto callback = std::make_shared<FCallBackFunc>(std::bind(&PointFromCurve<TDataType>::varChanged, this));
41
42 this->varLocation()->attach(callback);
43 this->varScale()->attach(callback);
44 this->varRotation()->attach(callback);
45
46 this->varUniformScale()->attach(callback);
47 this->varCurve()->attach(callback);
48
49
50 }
51
52 template<typename TDataType>
57
58 template<typename TDataType>
60 {
61 auto center = this->varLocation()->getData();
62 auto rot = this->varRotation()->getData();
63 auto scale = this->varScale()->getData();
64 auto uniformScale = this->varUniformScale()->getData();
65 auto pointSet = this->statePointSet()->getDataPtr();
66 auto curve = this->varCurve()->getValue();
67 auto floatCoord = curve.getPoints();
68 int length = floatCoord.size();
69 std::vector<Coord> vertices;
70
71
72 Coord Location;
73 if (length != 0)
74 {
75 for (size_t i = 0; i < length; i++)
76 {
77 Location = Coord(floatCoord[i].x, floatCoord[i].y, 0);
78
79 vertices.push_back(Location);
80 }
81 }
82
83 if (curve.curveClose && curve.resample == true && vertices.size()>=3)
84 {
85
86 vertices.erase(vertices.end() - 1);
87
88 }
89
90 //Transform Coord
91
92 Quat<Real> q2 = this->computeQuaternion();
93
94 q2.normalize();
95
96 auto RVt = [&](const Coord& v)->Coord {
97 return center + q2.rotate(v - center);
98 };
99
100 int numpt = vertices.size();
101
102 for (int i = 0; i < numpt; i++)
103 {
104
105 vertices[i] = RVt(vertices[i] * scale * uniformScale + RVt(center));
106 }
107
108 int s = vertices.size();
109
110 pointSet->setPoints(vertices);
111
112
113
114
115
116 // create EdgeSet
117 {
118 std::vector<TopologyModule::Edge> edges;
119
120
121 auto edgeSet = this->stateEdgeSet()->getDataPtr();
122
123 int ptnum = vertices.size();
124
125
126 //printf("vertices.size %d \n", ptnum);
127 if (ptnum >= 2)
128 {
129 for (int i = 0; i < ptnum - 1; i++)
130 {
131 edges.push_back(TopologyModule::Edge(i, i + 1));
132 //printf(" %d -- %d \n", i, i + 1);
133 }
134 }
135 //printf(" set \n");
136
137 if (curve.curveClose == true && vertices.size()>=3)
138 {
139 edges.push_back(TopologyModule::Edge(vertices.size()-1,0));
140 }
141
142
143
144 edgeSet->setPoints(vertices);
145 edgeSet->setEdges(edges);
146
147
148 vertices.clear();
149 edges.clear();
150 //printf(" clear \n");
151
152
153 }
154
155 }
156
158}
#define DEFINE_CLASS(name)
Definition Object.h:140
std::shared_ptr< GraphicsPipeline > graphicsPipeline()
Definition Node.cpp:320
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