31 this->varRadius()->setRange(0.001f, 100.0f);
39 this->varLatitude()->setRange(2, 10000);
40 this->varLongitude()->setRange(3, 10000);
41 this->varHeight()->setRange(0, 100);
42 this->varHeightSegment()->setRange(1, 10000);
47 this->varLocation()->attach(callback);
48 this->varScale()->attach(callback);
49 this->varRotation()->attach(callback);
50 this->varRadius()->attach(callback);
51 this->varLatitude()->attach(callback);
52 this->varLongitude()->attach(callback);
54 auto tsRender = std::make_shared<GLSurfaceVisualModule>();
55 tsRender->setVisible(
true);
56 this->stateTriangleSet()->connect(tsRender->inTriangleSet());
59 auto exES = std::make_shared<ExtractEdgeSetFromPolygonSet<TDataType>>();
60 this->statePolygonSet()->connect(exES->inPolygonSet());
63 auto clRender = std::make_shared<GLWireframeVisualModule>();
64 clRender->varBaseColor()->setValue(
Color(46.f / 255.f , 107.f / 255.f, 202.f / 255.f));
65 clRender->varLineWidth()->setValue(1.f);
66 clRender->varRenderMode()->setCurrentKey(GLWireframeVisualModule::CYLINDER);
68 this->stateCenterLine()->connect(clRender->inEdgeSet());
71 auto esRender = std::make_shared<GLWireframeVisualModule>();
72 esRender->varBaseColor()->setValue(
Color(0, 0, 0));
73 exES->outEdgeSet()->connect(esRender->inEdgeSet());
76 this->stateTriangleSet()->promoteOuput();
77 this->statePolygonSet()->promoteOuput();
130 auto center = this->varLocation()->getValue();
131 auto rot = this->varRotation()->getValue();
132 auto scale = this->varScale()->getValue();
134 auto radius = this->varRadius()->getValue();
135 auto latitude = this->varLatitude()->getValue();
136 auto longitude = this->varLongitude()->getValue();
137 Real halfHeight = this->varHeight()->getValue() / 2;
138 auto row = this->varHeightSegment()->getValue();
145 this->outCapsule()->setValue(capsulePrim);
147 auto polySet = this->statePolygonSet()->getDataPtr();
149 std::vector<Coord> vertices;
150 std::map<Index2D, uint> index_ID;
151 std::map<Index2D, Coord> index_Coord;
155 Real deltaPhi = 2 *
M_PI / longitude;
160 vertices.push_back(
Coord(0, radius + halfHeight, 0));
162 for (
uint i = 0; i < (latitude) / 2; i++)
166 Real tempheight = i <= (latitude) / 2 ? halfHeight : - halfHeight;
169 for (
uint j = 0; j < longitude; j++)
173 Real y = radius * std::cos(theta) + tempheight;
174 Real x = (std::sin(theta) * radius) * std::sin(phi);
175 Real z = (std::sin(theta) * radius) * std::cos(phi);
177 vertices.push_back(
Coord(x, y, z));
179 if (i == latitude / 2 - 1)
182 index_ID[RC] = vertices.size() - 1;
184 index_Coord[RC] =
Coord(x, y, z);
190 uint halfVtNum = vertices.size();
191 for (
size_t i = 0; i < halfVtNum; i++)
193 vertices.push_back(
Coord(vertices[i][0], - vertices[i][1], vertices[i][2]));
196 for (
auto list : index_ID)
199 auto s = list.second;
201 index_ID[RC] = s + halfVtNum;
206 for (
int i = 0; i <= row ; i++)
208 Real tempy = halfHeight * 2 / row * i - halfHeight;
212 if (i != 0 && i != row )
214 Real phi = deltaPhi * longitude;
216 for (
int j = 0; j < longitude; j++) {
220 v =
Coord(v[0], tempy,v[2]);
222 vertices.push_back(v);
224 index_ID[RC] = vertices.size() - 1;
231 uint numOfPolygon = 0;
234 numOfPolygon = latitude * longitude + row * longitude - longitude;
236 numOfPolygon = latitude * longitude + row * longitude;
245 for (
uint j = 0; j < longitude; j++)
251 for (
uint i = 0; i < std::floor((latitude - 2)/2); i++)
253 for (
uint j = 0; j < longitude; j++)
260 for (
uint j = 0; j < longitude; j++)
266 for (
uint i = 0; i < std::floor((latitude - 2) / 2); i++)
268 for (
uint j = 0; j < longitude; j++)
276 for (
uint i = 0; i < row; i++)
278 for (
uint j = 0; j < longitude; j++)
288 polygonIndices.resize(counter);
294 for (
uint j = 0; j < longitude; j++)
296 auto& index = polygonIndices[incre];
298 index.insert(offset + j);
299 index.insert(offset + (j + 1) % longitude);
304 for (
uint i = 0; i < (latitude - 2)/2; i++)
306 for (
uint j = 0; j < longitude; j++)
308 auto& index = polygonIndices[incre];
309 index.insert(offset + j);
310 index.insert(offset + j + longitude);
311 index.insert(offset + (j + 1) % longitude + longitude);
312 index.insert(offset + (j + 1) % longitude);
319 for (
size_t i = 0; i < incre; i++)
321 auto& source = polygonIndices[i];
322 auto& index = polygonIndices[i + incre];
324 for (
size_t j = 0; j < source.size(); j++)
326 uint N = source.size() - 1;
327 index.insert(source[
N - j] + halfVtNum);
335 for (
size_t i = 0; i < row ; i++)
337 for (
size_t j = 0; j < longitude; j++)
339 auto& index = polygonIndices[incre];
340 index.insert(index_ID.find(
Index2D(i, (j + 1) % longitude))->second);
341 index.insert(index_ID.find(
Index2D(i + 1, (j + 1) % longitude))->second);
342 index.insert(index_ID.find(
Index2D(i + 1, j))->second);
343 index.insert(index_ID.find(
Index2D(i, j))->second);
354 return center + q.
rotate(v - center);
357 int numpt = vertices.size();
359 for (
int i = 0; i < numpt; i++) {
360 vertices[i] = RV(vertices[i] * scale + RV(center));
363 polySet->setPoints(vertices);
364 polySet->setPolygons(polygonIndices);
367 polygonIndices.clear();
371 auto& ts = this->stateTriangleSet()->getData();
372 polySet->turnIntoTriangleSet(ts);
375 std::vector<TopologyModule::Edge> edges;
377 vertices.push_back(center + q.
rotate(
Coord(0, + halfHeight, 0)));
378 vertices.push_back(center + q.
rotate(
Coord(0, - halfHeight, 0)));
381 auto edgeSet = this->stateCenterLine()->getDataPtr();
382 edgeSet->setPoints(vertices);
383 edgeSet->setEdges(edges);