18 this->varRadius()->setRange(0.001f, 100.0f);
24 this->varLatitude()->setRange(2, 10000);
25 this->varLongitude()->setRange(3, 10000);
26 this->varIcosahedronStep()->setRange(0,6);
31 this->varLocation()->attach(callback);
32 this->varScale()->attach(callback);
33 this->varRotation()->attach(callback);
34 this->varRadius()->attach(callback);
35 this->varLatitude()->attach(callback);
36 this->varLongitude()->attach(callback);
37 this->varType()->attach(callback);
39 auto tsRender = std::make_shared<GLSurfaceVisualModule>();
40 this->stateTriangleSet()->connect(tsRender->inTriangleSet());
43 auto exES = std::make_shared<ExtractEdgeSetFromPolygonSet<TDataType>>();
44 this->statePolygonSet()->connect(exES->inPolygonSet());
47 auto esRender = std::make_shared<GLWireframeVisualModule>();
48 esRender->varBaseColor()->setValue(
Color(0, 0, 0));
49 exES->outEdgeSet()->connect(esRender->inEdgeSet());
52 this->stateTriangleSet()->promoteOuput();
53 this->statePolygonSet()->promoteOuput();
104 auto center = this->varLocation()->getValue();
105 auto rot = this->varRotation()->getValue();
106 auto scale = this->varScale()->getValue();
108 auto radius = this->varRadius()->getValue();
110 auto latitude = this->varLatitude()->getValue();
111 auto longitude = this->varLongitude()->getValue();
113 auto type = this->varType()->getValue();
115 auto polySet = this->statePolygonSet()->getDataPtr();
117 std::vector<Coord> vertices;
121 Real deltaPhi = 2 *
M_PI / longitude;
124 vertices.push_back(
Coord(0, radius, 0));
127 for (
uint i = 0; i < latitude - 1; i++)
132 for (
uint j = 0; j < longitude; j++)
136 Real y = radius * std::cos(theta);
137 Real x = (std::sin(theta) * radius) * std::sin(phi);
138 Real z = (std::sin(theta) * radius) * std::cos(phi);
140 vertices.push_back(
Coord(x, y, z));
144 vertices.push_back(
Coord(0, -radius, 0));
147 uint numOfPolygon = latitude * longitude;
152 for (
uint j = 0; j < longitude; j++)
158 for (
uint i = 0; i < latitude - 2; i++)
160 for (
uint j = 0; j < longitude; j++)
167 for (
uint j = 0; j < longitude; j++)
174 polygonIndices.resize(counter);
178 for (
uint j = 0; j < longitude; j++)
180 auto& index = polygonIndices[incre];
182 index.insert(offset + j);
183 index.insert(offset + (j + 1) % longitude);
188 for (
uint i = 0; i < latitude - 2; i++)
190 for (
uint j = 0; j < longitude; j++)
192 auto& index = polygonIndices[incre];
193 index.insert(offset + j);
194 index.insert(offset + j + longitude);
195 index.insert(offset + (j + 1) % longitude + longitude);
196 index.insert(offset + (j + 1) % longitude);
203 for (
uint j = 0; j < longitude; j++)
205 auto& index = polygonIndices[incre];
206 index.insert(offset + j);
207 index.insert(vertices.size() - 1);
208 index.insert(offset + (j + 1) % longitude);
217 return center + q.
rotate(v - center);
220 int numpt = vertices.size();
222 for (
int i = 0; i < numpt; i++) {
223 vertices[i] = RV(vertices[i] * scale + RV(center));
226 polySet->setPoints(vertices);
227 polySet->setPolygons(polygonIndices);
230 polygonIndices.clear();
232 auto& ts = this->stateTriangleSet()->getData();
233 polySet->turnIntoTriangleSet(ts);
241 std::vector<Vec3f> vts;
242 std::vector<TopologyModule::Triangle> trs;
245 float fixScale = this->varIcosahedronStep()->getValue() >= 2 ? 1.08 : 1;
248 auto center = this->varLocation()->getData();
249 auto scale = this->varScale()->getData();
252 return center + q.
rotate(v - center);
255 for (
int i = 0; i < vts.size(); i++) {
256 vts[i] = RV(vts[i] * scale * fixScale + RV(center));
259 if (this->varIcosahedronStep()->getValue() >= 2)
261 for (
int i = 0; i < (int)this->varIcosahedronStep()->getValue() - 1; i++)
268 this->stateTriangleSet()->getDataPtr()->setPoints(vts);
269 this->stateTriangleSet()->getDataPtr()->setTriangles(trs);
270 this->stateTriangleSet()->getDataPtr()->update();
272 this->statePolygonSet()->getDataPtr()->triangleSetToPolygonSet(this->stateTriangleSet()->getData());
308 auto radius = this->varRadius()->getValue() * 2;
310 if (this->varIcosahedronStep()->getValue() == 0)
312 float phi = (1.0 + std::sqrt(5.0)) / 2.0;
315 Vec3f(-1, phi, 0),
Vec3f(1, phi, 0),
Vec3f(-1, -phi, 0),
Vec3f(1, -phi, 0),
316 Vec3f(0, -1, phi),
Vec3f(0, 1, phi),
Vec3f(0, -1, -phi),
Vec3f(0, 1, -phi),
317 Vec3f(phi, 0, -1),
Vec3f(phi, 0, 1),
Vec3f(-phi, 0, -1),
Vec3f(-phi, 0, 1)
321 TopologyModule::Triangle(0, 11, 5),
TopologyModule::Triangle(0, 5, 1),
TopologyModule::Triangle(0, 1, 7),
TopologyModule::Triangle(0, 7, 10),
TopologyModule::Triangle(0, 10, 11),
322 TopologyModule::Triangle(1, 5, 9),
TopologyModule::Triangle(5, 11, 4),
TopologyModule::Triangle(11, 10, 2),
TopologyModule::Triangle(10, 7, 6),
TopologyModule::Triangle(7, 1, 8),
323 TopologyModule::Triangle(3, 9, 4),
TopologyModule::Triangle(3, 4, 2),
TopologyModule::Triangle(3, 2, 6),
TopologyModule::Triangle(3, 6, 8),
TopologyModule::Triangle(3, 8, 9),
324 TopologyModule::Triangle(4, 9, 5),
TopologyModule::Triangle(2, 4, 11),
TopologyModule::Triangle(6, 2, 10),
TopologyModule::Triangle(8, 6, 7),
TopologyModule::Triangle(9, 8, 1)
327 for (
auto& v : vertices) {
328 v = v /
M_PI * radius;
335 Vec3f(0,0, -0.5) * radius,
336 Vec3f(0, 0.262865603, -0.425325394) * radius,
337 Vec3f(0.249999985, 0.0812300518, -0.425325394) * radius,
338 Vec3f(0, 0.44721368, -0.223606572) * radius,
339 Vec3f(0.249999985, 0.344095677, -0.262865305) * radius,
340 Vec3f(0.425325423, 0.138196841, -0.223606601) * radius,
341 Vec3f(0.154508501, -0.212662712, -0.425325423) * radius,
342 Vec3f(0.404508621, -0.131432697, -0.262865394) * radius,
343 Vec3f(0.262865603, -0.361803472, -0.223606631) * radius,
344 Vec3f(-0.154508501, -0.212662712, -0.425325423) * radius,
345 Vec3f(0, -0.425325513, -0.262865365) * radius,
346 Vec3f(-0.262865603, -0.361803472, -0.223606631) * radius,
347 Vec3f(-0.249999985, 0.0812300518, -0.425325394) * radius,
348 Vec3f(-0.404508621, -0.131432697, -0.262865394) * radius,
349 Vec3f(-0.425325423, 0.138196841, -0.223606601) * radius,
350 Vec3f(-0.249999985, 0.344095677, -0.262865305) * radius,
351 Vec3f(-0.154508486, 0.4755283, 0) * radius,
352 Vec3f(-0.404508412, 0.293892711, 0) * radius,
353 Vec3f(-0.262865603, 0.361803472, 0.223606631) * radius,
354 Vec3f(-0.5, 0, 0) * radius,
355 Vec3f(-0.404508412, -0.293892711, 0) * radius,
356 Vec3f(-0.425325423, -0.138196841, 0.223606601) * radius,
357 Vec3f(-0.154508486, -0.4755283, 0) * radius,
358 Vec3f(0.154508486, -0.4755283, 0) * radius,
359 Vec3f(0, -0.44721368, 0.223606572) * radius,
360 Vec3f(0.404508412, -0.293892711, 0) * radius,
361 Vec3f(0.5, 0 ,0) * radius,
362 Vec3f(0.425325423, -0.138196841, 0.223606601) * radius,
363 Vec3f(0.404508412, 0.293892711, 0) * radius,
364 Vec3f(0.154508486, 0.4755283, 0) * radius,
365 Vec3f(0.262865603, 0.361803472 ,0.223606631) * radius,
366 Vec3f(0, 0.425325513, 0.262865365) * radius,
367 Vec3f(-0.404508621, 0.131432697, 0.262865394) * radius,
368 Vec3f(-0.249999985, -0.344095677, 0.262865305) * radius,
369 Vec3f(0.249999985, -0.344095677, 0.262865305) * radius,
370 Vec3f(0.404508621, 0.131432697, 0.262865394) * radius,
371 Vec3f(0, 0, 0.5) * radius,
372 Vec3f(0.154508501, 0.212662712 ,0.425325423) * radius,
373 Vec3f(-0.154508501, 0.212662712, 0.425325423) * radius,
374 Vec3f(0.249999985, -0.0812300518, 0.425325394) * radius,
375 Vec3f(0, -0.262865603, 0.425325394) * radius,
376 Vec3f(-0.249999985, -0.0812300518, 0.425325394) * radius
462 for (
size_t i = 0; i < triangles.size(); i++)