1#include "CopyToPoint.h"
2#include "Topology/PointSet.h"
3#include "GLSurfaceVisualModule.h"
4#include "GLWireframeVisualModule.h"
5#include "GLPointVisualModule.h"
11 template<typename TDataType>
12 CopyToPoint<TDataType>::CopyToPoint()
13 : ParametricModel<TDataType>()
15 this->stateTriangleSet()->setDataPtr(std::make_shared<TriangleSet<TDataType>>());
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);
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);
40 template<typename TDataType>
41 void CopyToPoint<TDataType>::resetStates()
43 auto triangleSet = this->stateTriangleSet()->getDataPtr();
46 auto VertexIn = this->inTriangleSetIn()->getData().getPoints();
47 auto TriangleIn = this->inTriangleSetIn()->getData().getTriangles();
48 auto target = this->inTargetPointSet()->getData().getPoints();
51 std::vector<Coord> vertices;
52 std::vector<TopologyModule::Triangle> triangle;
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);
61 int lengthV = VertexIn.size();
62 int lengthT = TriangleIn.size();
63 unsigned CopyNumber = c_target.size();
66 //for (int i = 0; i < lengthV; i++)
68 // Location = { c_point[i][0], c_point[i][1], c_point[i][2] };
69 // vertices.push_back( Location );
71 //for (int i = 0; i < lengthT; i++)
73 // triangle.push_back(TopologyModule::Triangle(c_triangle[i][0], c_triangle[i][1], c_triangle[i][2]));
79 if (!this->inTargetPointSet()->isEmpty())
82 for(int i = 0;i < CopyNumber; i++)
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));
89 //auto RV = [&](const Coord& v)->Coord {
90 // return q.rotate(v );//center + q.rotate(v - center)
93 //Vec3f RealScale = scale;
94 //if (this->varScaleMode()->getData() == 0)
96 // for (int k = 0; k < i; k++)
98 // RealScale *= scale;
101 //if (this->varScaleMode()->getData() == 1)
103 // RealScale = scale * 1 / (i + 1);
106 for (int j = 0; j < lengthV; j++)
108 Location = { c_point[j][0], c_point[j][1], c_point[j][2] };
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);
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 * lengthV, c_triangle[j][1] + i * lengthV, c_triangle[j][2] + i * lengthV));
132 auto centert = this->varLocation()->getData();
133 auto rott = this->varRotation()->getData();
134 auto scalet= this->varScale()->getData();
136 Quat<Real> qt = this->computeQuaternion();
140 auto RVt = [&](const Coord& v)->Coord {
141 return centert + qt.rotate(v - centert);
144 int numptt = vertices.size();
146 for (int i = 0; i < numptt; i++)
148 vertices[i] = RVt(vertices[i] * scalet + RVt(centert));
151 triangleSet->setPoints(vertices);
152 triangleSet->setTriangles(triangle);
155 triangleSet->update();
166 template<typename TDataType>
167 void CopyToPoint<TDataType>::disableRender() {
168 glModule->setVisible(false);
174 DEFINE_CLASS(CopyToPoint);