2#include "Topology/PointSet.h"
3#include "GLSurfaceVisualModule.h"
4#include "GLWireframeVisualModule.h"
5#include "GLPointVisualModule.h"
11 template<typename TDataType>
12 CopyModel<TDataType>::CopyModel()
13 : ParametricModel<TDataType>()
15 this->stateTriangleSet()->setDataPtr(std::make_shared<TriangleSet<TDataType>>());
17 auto 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);
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);
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);
37 template<typename TDataType>
38 void CopyModel<TDataType>::resetStates()
40 auto center = this->varCopyTransform()->getData();
41 auto rot = this->varCopyRotation()->getData();
42 auto scale = this->varCopyScale()->getData();
44 auto triangleSet = this->stateTriangleSet()->getDataPtr();
46 auto VertexIn = this->inTriangleSetIn()->getData().getPoints();
47 auto TriangleIn = this->inTriangleSetIn()->getData().getTriangles();
49 std::vector<Coord> vertices;
50 std::vector<TopologyModule::Triangle> triangle;
52 CArray<TopologyModule::Triangle> c_triangle;
53 CArray<Coord> c_point;
54 c_point.assign(VertexIn);
55 c_triangle.assign(TriangleIn);
57 int lengthV = VertexIn.size();
58 int lengthT = TriangleIn.size();
59 unsigned CopyNumber = this->varTotalNumber()->getData() - 1 ;
63 for (int i = 0; i < lengthV; i++)
65 Location = { c_point[i][0], c_point[i][1], c_point[i][2] };
66 vertices.push_back( Location );
68 for (int i = 0; i < lengthT; i++)
70 triangle.push_back(TopologyModule::Triangle(c_triangle[i][0], c_triangle[i][1], c_triangle[i][2]));
76 if (this->varTotalNumber()->getValue() > 1)
79 for(int i = 0;i < CopyNumber; i++)
82 auto rot = this->varCopyRotation()->getValue() * (i + 1);
85 Quat<Real>(Real(M_PI) * rot[2] / 180, Coord(0, 0, 1))
86 * Quat<Real>(Real(M_PI) * rot[1] / 180, Coord(0, 1, 0))
87 * Quat<Real>(Real(M_PI) * rot[0] / 180, Coord(1, 0, 0));
90 auto RV = [&](const Coord& v)->Coord {
94 Vec3f RealScale = scale;
95 if (this->varScaleMode()->getData() == 0)
97 for (int k = 0; k < i; k++)
102 if (this->varScaleMode()->getData() == 1)
104 RealScale = scale * 1 / (i + 1);
107 for (int j = 0; j < lengthV; j++)
109 Location = { c_point[j][0], c_point[j][1], c_point[j][2] };
111 Location = RV(Location * RealScale) + center * (i+1);
112 vertices.push_back(Location);
117 for (int i = 0; i < CopyNumber; i++)
119 for (int j = 0; j < lengthT; j++)
122 triangle.push_back(TopologyModule::Triangle(c_triangle[j][0] + (i + 1) * lengthV, c_triangle[j][1] + (i + 1) * lengthV, c_triangle[j][2] + (i + 1) * lengthV));
131 auto centert = this->varLocation()->getData();
132 auto rott = this->varRotation()->getData();
133 auto scalet= this->varScale()->getData();
135 Quat<Real> qt = this->computeQuaternion();
139 auto RVt = [&](const Coord& v)->Coord {
140 return centert + qt.rotate(v - centert);
143 int numptt = vertices.size();
145 for (int i = 0; i < numptt; i++)
147 vertices[i] = RVt(vertices[i] * scalet + RVt(centert));
150 triangleSet->setPoints(vertices);
151 triangleSet->setTriangles(triangle);
154 triangleSet->update();
160 DEFINE_CLASS(CopyModel);