3#include "GLSurfaceVisualModule.h"
4#include "GLWireframeVisualModule.h"
10 template<typename TDataType>
11 PointClip<TDataType>::PointClip()
13 this->stateClipPlane()->setDataPtr(std::make_shared<TriangleSet<TDataType>>());
14 this->statePointSet()->setDataPtr(std::make_shared<PointSet<TDataType>>());
15 auto plane = this->stateClipPlane()->getDataPtr();
16 auto size = this->varPlaneSize()->getData();
18 std::vector<TopologyModule::Triangle> triangles;
20 planeVertices.push_back(Coord(0, size, size));
21 planeVertices.push_back(Coord(0, size, -size));
22 planeVertices.push_back(Coord(0, -size, -size));
23 planeVertices.push_back(Coord(0, -size, size));
25 triangles.push_back(TopologyModule::Triangle(0,1,2));
26 triangles.push_back(TopologyModule::Triangle(2,3,0));
28 plane->setPoints(planeVertices);
29 plane->setTriangles(triangles);
31 surface = std::make_shared<GLSurfaceVisualModule>();
32 glpoint = std::make_shared<GLPointVisualModule>();
34 surface->setAlpha(0.4);
35 surface->setColor(Color(0,0,0));
36 this->stateClipPlane()->connect(surface->inTriangleSet());
38 glpoint->setColor(this->varPointColor()->getData());
39 glpoint->varPointSize()->setValue(this->varPointSize()->getData());
40 this->statePointSet()->connect(glpoint->inPointSet());
42 this->graphicsPipeline()->pushModule(surface);
43 this->graphicsPipeline()->pushModule(glpoint);
44 this->statePointSet()->promoteOuput();
49 template<typename TDataType>
50 void PointClip<TDataType>::resetStates()
55 glpoint->setColor(this->varPointColor()->getData());
59 template<typename TDataType>
60 void PointClip<TDataType>::updateStates()
67 template<typename TDataType>
68 void PointClip<TDataType>::clip()
70 auto plane = this->stateClipPlane()->getDataPtr();
72 auto pointSet = this->inPointSet()->getDataPtr();
73 auto pointSetState = this->statePointSet()->getDataPtr();
75 CArray<Coord> planePoint;
76 planePoint.assign(plane->getPoints());
77 Vec3f planeV1 = planePoint[0] - planePoint[1];
78 Vec3f planeV2 = planePoint[1] - planePoint[2];
81 Normal = planeV1.cross(planeV2);
85 CArray<Coord> c_point;
86 std::vector<Coord> vertices;
87 c_point.assign(pointSet->getPoints());
89 for (size_t i = 0; i < c_point.size(); i++)
91 if (this->varReverse()->getData()) { planeV3 = c_point[i]-planePoint[0];}
92 else { planeV3 = planePoint[0] - c_point[i]; }
93 if (planeV3.dot(Normal) >= 0)
95 vertices.push_back(c_point[i]);
98 pointSetState->getPoints().clear();
99 pointSetState->setPoints(vertices);
100 pointSetState->update();
107 template<typename TDataType>
108 void PointClip<TDataType>::transformPlane()
110 auto plane = this->stateClipPlane()->getDataPtr();
112 auto scale = this->varScale()->getData();
113 auto rot = this->varRotation()->getData();
114 auto center = this->varLocation()->getData();
116 std::vector<Coord> vertices;
118 for (size_t i = 0; i < planeVertices.size(); i++)
120 vertices.push_back(planeVertices[i]);
124 Quat<Real> q = this->computeQuaternion();
128 auto RV = [&](const Coord& v)->Coord {
129 return center + q.rotate(v - center);
132 int numpt = vertices.size();
134 for (int i = 0; i < numpt; i++)
136 vertices[i] = RV(vertices[i] * scale + RV(center));
138 plane->getPoints().clear();
139 plane->setPoints(vertices);
144 template<typename TDataType>
145 void PointClip<TDataType>::showPlane()
147 surface->setVisible(this->varShowPlane()->getData());
149 DEFINE_CLASS(PointClip);