PeriDyno 1.0.0
Loading...
Searching...
No Matches
CopyToPoint.cu
Go to the documentation of this file.
1#include "CopyToPoint.h"
2#include "Topology/PointSet.h"
3#include "GLSurfaceVisualModule.h"
4#include "GLWireframeVisualModule.h"
5#include "GLPointVisualModule.h"
6
7
8
9namespace dyno
10{
11 template<typename TDataType>
12 CopyToPoint<TDataType>::CopyToPoint()
13 : ParametricModel<TDataType>()
14 {
15 this->stateTriangleSet()->setDataPtr(std::make_shared<TriangleSet<TDataType>>());
16
17 glModule = std::make_shared<GLSurfaceVisualModule>();
18 glModule->setColor(Color(0.8f, 0.52f, 0.25f));
19 glModule->setVisible(true);
20 this->stateTriangleSet()->connect(glModule->inTriangleSet());
21 this->graphicsPipeline()->pushModule(glModule);
22
23 auto glModule2 = std::make_shared<GLPointVisualModule>();
24 glModule2->setColor(Color(1.0f, 0.1f, 0.1f));
25 glModule2->setVisible(false);
26 glModule2->varPointSize()->setValue(0.01);
27 this->stateTriangleSet()->connect(glModule2->inPointSet());
28 this->graphicsPipeline()->pushModule(glModule2);
29
30 auto glModule3 = std::make_shared<GLWireframeVisualModule>();
31 glModule3->setColor(Color(0.0f, 0.0f, 0.0f));
32 glModule3->setVisible(false);
33 this->stateTriangleSet()->connect(glModule3->inEdgeSet());
34 this->graphicsPipeline()->pushModule(glModule3);
35
36
37
38 }
39
40 template<typename TDataType>
41 void CopyToPoint<TDataType>::resetStates()
42 {
43 auto triangleSet = this->stateTriangleSet()->getDataPtr();
44
45
46 auto VertexIn = this->inTriangleSetIn()->getData().getPoints();
47 auto TriangleIn = this->inTriangleSetIn()->getData().getTriangles();
48 auto target = this->inTargetPointSet()->getData().getPoints();
49
50
51 std::vector<Coord> vertices;
52 std::vector<TopologyModule::Triangle> triangle;
53
54 CArray<TopologyModule::Triangle> c_triangle;
55 CArray<Coord> c_point;
56 CArray<Coord> c_target;
57 c_point.assign(VertexIn);
58 c_triangle.assign(TriangleIn);
59 c_target.assign(target);
60
61 int lengthV = VertexIn.size();
62 int lengthT = TriangleIn.size();
63 unsigned CopyNumber = c_target.size();
64
65 Coord Location;
66 //for (int i = 0; i < lengthV; i++)
67 //{
68 // Location = { c_point[i][0], c_point[i][1], c_point[i][2] };
69 // vertices.push_back( Location );
70 //}
71 //for (int i = 0; i < lengthT; i++)
72 //{
73 // triangle.push_back(TopologyModule::Triangle(c_triangle[i][0], c_triangle[i][1], c_triangle[i][2]));
74 //}
75
76
77 //Copy polygons
78 //vertices
79 if (!this->inTargetPointSet()->isEmpty())
80 {
81
82 for(int i = 0;i < CopyNumber; i++)
83 {
84 //Quat<Real> q = Quat<Real>(M_PI * rot[0] / 180 * (i + 1), Coord(1, 0, 0))
85 // * Quat<Real>(M_PI * rot[1] / 180 * (i + 1), Coord(0, 1, 0))
86 // * Quat<Real>(M_PI * rot[2] / 180 * (i + 1), Coord(0, 0, 1));
87 //q.normalize();
88
89 //auto RV = [&](const Coord& v)->Coord {
90 // return q.rotate(v );//center + q.rotate(v - center)
91 //};
92
93 //Vec3f RealScale = scale;
94 //if (this->varScaleMode()->getData() == 0)
95 //{
96 // for (int k = 0; k < i; k++)
97 // {
98 // RealScale *= scale;
99 // }
100 //}
101 //if (this->varScaleMode()->getData() == 1)
102 //{
103 // RealScale = scale * 1 / (i + 1);
104 //}
105
106 for (int j = 0; j < lengthV; j++)
107 {
108 Location = { c_point[j][0], c_point[j][1], c_point[j][2] };
109
110 //Location = RV(Location * RealScale) + center * (i+1);//添加变换RV(Location * RealScale + RV(center * (i + 1)))
111 Location = Location + c_target[i];
112 vertices.push_back(Location);
113 }
114 }
115
116 //face
117 for (int i = 0; i < CopyNumber; i++)
118 {
119 for (int j = 0; j < lengthT; j++)
120 {
121 ;
122 triangle.push_back(TopologyModule::Triangle(c_triangle[j][0] + i * lengthV, c_triangle[j][1] + i * lengthV, c_triangle[j][2] + i * lengthV));
123
124 }
125
126 }
127
128 }
129
130 //transform
131
132 auto centert = this->varLocation()->getData();
133 auto rott = this->varRotation()->getData();
134 auto scalet= this->varScale()->getData();
135
136 Quat<Real> qt = this->computeQuaternion();
137
138 qt.normalize();
139
140 auto RVt = [&](const Coord& v)->Coord {
141 return centert + qt.rotate(v - centert);
142 };
143
144 int numptt = vertices.size();
145
146 for (int i = 0; i < numptt; i++)
147 {
148 vertices[i] = RVt(vertices[i] * scalet + RVt(centert));
149 }
150
151 triangleSet->setPoints(vertices);
152 triangleSet->setTriangles(triangle);
153
154
155 triangleSet->update();
156
157
158
159 vertices.clear();
160 triangle.clear();
161
162
163 }
164
165
166 template<typename TDataType>
167 void CopyToPoint<TDataType>::disableRender() {
168 glModule->setVisible(false);
169 };
170
171
172
173
174 DEFINE_CLASS(CopyToPoint);
175}