45 #include "PrimitivesGenerator.hh" 46 #include <OpenFlipper/BasePlugin/WhatsThisGenerator.hh> 48 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 49 #include "TetrahedralCuboidGenerator.hh" 52 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 56 #ifdef ENABLE_BSPLINECURVE_SUPPORT 60 #ifdef ENABLE_BSPLINESURFACE_SUPPORT 64 PrimitivesGeneratorPlugin::PrimitivesGeneratorPlugin() :
74 PrimitivesGeneratorPlugin::~PrimitivesGeneratorPlugin()
77 if ( OpenFlipper::Options::gui()) {
78 delete primitivesMenu_;
85 emit setSlotDescription(
"addCube(Vector,double)",
86 tr(
"Generates a poly mesh of cube (ObjectId is returned)"),
87 QString(
"Position,Length").split(
","),
88 QString(
"Center position,Length of each edge").split(
","));
90 emit setSlotDescription(
"addTetrahedron(Vector,double)",
91 tr(
"Generates a tetrahedron (ObjectId is returned)"),
92 QString(
"Position,Length").split(
","),
93 QString(
"Center position,Length of each edge").split(
","));
95 emit setSlotDescription(
"addIcosahedron(Vector,double)",
96 tr(
"Generates an icosahedron (ObjectId is returned)"),
97 QString(
"Position,Length").split(
","),
98 QString(
"Center position,Length of each edge").split(
","));
100 emit setSlotDescription(
"addPyramid(Vector,double)",
101 tr(
"Generates a pyramid (ObjectId is returned)"),
102 QString(
"Position,Length").split(
","),
103 QString(
"Center position,Length of each edge").split(
","));
105 emit setSlotDescription(
"addOctahedron(Vector,double)",
106 tr(
"Generates an octahedron (ObjectId is returned)"),
107 QString(
"Position,Length").split(
","),
108 QString(
"Center position,Length of each edge").split(
","));
110 emit setSlotDescription(
"addDodecahedron(Vector,double)",
111 tr(
"Generates a dodecahedron (ObjectId is returned)"),
112 QString(
"Position,Length").split(
","),
113 QString(
"Center position,Length of each edge").split(
","));
115 emit setSlotDescription(
"addSphere(Vector,double)",
116 tr(
"Generates a triangulated sphere with all vertical lines connected to the poles (ObjectId is returned)"),
117 QString(
"Position, Radius").split(
","),
118 QString(
"Center position,Radius").split(
","));
120 emit setSlotDescription(
"addSubdivisionSphere(Vector,double)",
121 tr(
"Generates a triangulated sphere by subdivision without poles. (ObjectId is returned)"),
122 QString(
"Position, Radius").split(
","),
123 QString(
"Center position,Radius").split(
","));
125 emit setSlotDescription(
"addTriangulatedCube(Vector,double)",
126 tr(
"Generates a triangular mesh of cube (ObjectId is returned)"),
127 QString(
"Position,Length").split(
","),
128 QString(
"Center position,Length of each edge").split(
","));
130 emit setSlotDescription(
"addTriangulatedCylinder(Vector,Vector,double,double)",
131 tr(
"Generates a triangulated cylinder (ObjectId is returned)") ,
132 QString(
"Position,Axis,Radius,Height,Top,Bottom").split(
","),
133 QString(
"Bottom center vertex position,Center axis,radius,height,add top vertex,add bottom vertex").split(
","));
135 #ifdef ENABLE_BSPLINECURVE_SUPPORT 136 emit setSlotDescription(
"addRandomBSplineCurve(Vector,int)",
137 tr(
"Generates a random B-spline curve (ObjectId is returned)"),
138 QString(
"Position,Count").split(
","),
139 QString(
"Center position,Number of control points").split(
","));
142 #ifdef ENABLE_BSPLINESURFACE_SUPPORT 143 emit setSlotDescription(
"addRandomBSplineSurface(Vector,int)",
144 tr(
"Generates a random B-spline surface (ObjectId is returned)"),
145 QString(
"Position,Count").split(
","),
146 QString(
"Center position,Number of control points").split(
","));
149 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 150 emit setSlotDescription(
"addTetrahedralCube(Vector,double)",
151 tr(
"Generates a tetrahedral mesh of a cube (ObjectId is returned)"),
152 QString(
"Position,Length").split(
","),
153 QString(
"Center position,Length of each edge").split(
","));
155 emit setSlotDescription(
"addTetrahedralCuboid(Vector,Vector,uint,uint,uint)",
156 tr(
"Generates a tetrahedral mesh of a cuboid (ObjectId is returned)"),
157 QString(
"Position,Lengths,Count,Count,Count").split(
","),
158 QString(
"Center position,Length of each side,Number of units in x-axis,Number of units in y-axis,Number of units in z-axis").split(
","));
160 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 161 emit setSlotDescription(
"addHexahedralCube(Vector,double)",
162 tr(
"Generates a hexahedral mesh of a cube (ObjectId is returned)"),
163 QString(
"Position,Length").split(
","),
164 QString(
"Center position,Length of each edge").split(
","));
169 void PrimitivesGeneratorPlugin::pluginsInitialized() {
171 if ( OpenFlipper::Options::gui()) {
173 emit getMenubarMenu(tr(
"&Primitives"), primitivesMenu_,
true );
178 action = primitivesMenu_->addAction(
"Cube (Poly Mesh)" ,
this,SLOT(addCube()));
179 action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"primitive_cube.png"));
180 whatsThisGen.
setWhatsThis(action,tr(
"Create a Cube."),
"Cube");
182 action = primitivesMenu_->addAction(
"Cube (Triangle Mesh)" ,
this,SLOT(addTriangulatedCube()));
183 action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"primitive_cube.png"));
184 whatsThisGen.
setWhatsThis(action,tr(
"Create a Cube."),
"Cube");
186 action = primitivesMenu_->addAction(
"Dodecahedron" ,
this,SLOT(addDodecahedron()));
187 action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"primitive_dodecahedron.png"));
188 whatsThisGen.
setWhatsThis(action,tr(
"Create a Dodecahedron."),
"Dodecahedron");
190 action = primitivesMenu_->addAction(
"Icosahedron" ,
this,SLOT(addIcosahedron()));
191 action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"primitive_icosahedron.png"));
192 whatsThisGen.
setWhatsThis(action,tr(
"Create a Icosahedron.",
"Icosahedron"));
194 action = primitivesMenu_->addAction(
"Octahedron" ,
this,SLOT(addOctahedron()));
195 action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"primitive_octahedron.png"));
196 whatsThisGen.
setWhatsThis(action,tr(
"Create an Octahedron."),
"Octahedron");
198 action = primitivesMenu_->addAction(
"Pyramid" ,
this,SLOT(addPyramid()));
199 action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"primitive_pyramid.png"));
200 whatsThisGen.
setWhatsThis(action,tr(
"Create a Pyramid."),
"Pyramid");
202 action = primitivesMenu_->addAction(
"Cylinder (Triangle Mesh)" ,
this,SLOT(addTriangulatedCylinder()));
203 action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"primitive_cylinder.png"));
205 action = primitivesMenu_->addAction(
"Sphere (Poles,Triangle Mesh)",
this,SLOT(addSphere()));
206 action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"primitive_sphere.png"));
207 whatsThisGen.
setWhatsThis(action,tr(
"Create a Sphere. All vertical lines connect to poles) "),
"Sphere");
209 action = primitivesMenu_->addAction(
"Sphere (Subdivision,Triangle Mesh)",
this,SLOT(addSubdivisionSphere()));
210 action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"primitive_sphere.png"));
211 whatsThisGen.
setWhatsThis(action,tr(
"Create a Sphere. No poles due to Subdivision) "),
"Sphere");
213 action = primitivesMenu_->addAction(
"Tetrahedron",
this,SLOT(addTetrahedron()));
214 action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"primitive_tetrahedron.png"));
215 whatsThisGen.
setWhatsThis(action,tr(
"Create a Tetrahedron."),
"Tetrahedron");
217 #ifdef ENABLE_BSPLINECURVE_SUPPORT 218 action = primitivesMenu_->addAction(
"Random B-spline curve",
this,SLOT(addRandomBSplineCurve()));
219 action->setIcon(QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() +
"bspline_curve.png"));
220 whatsThisGen.
setWhatsThis(action, tr(
"Create a random B-spline curve."),
"B-spline curve");
223 #ifdef ENABLE_BSPLINESURFACE_SUPPORT 224 action = primitivesMenu_->addAction(
"Random B-spline surface",
this,SLOT(addRandomBSplineSurface()));
225 action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"bspline_surface.png"));
226 whatsThisGen.
setWhatsThis(action,tr(
"Create a random B-spline surface."),
"B-spline surface");
229 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 230 action = primitivesMenu_->addAction(
"Cube (Tetrahedral Mesh)" ,
this,SLOT(addTetrahedralCube()));
231 action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"primitive_cube.png"));
232 whatsThisGen.
setWhatsThis(action,tr(
"Create a Tetrahedral Cube."),
"Cube");
234 action = primitivesMenu_->addAction(
"Cuboid (Tetrahedral Mesh)" ,
this,SLOT(addTetrahedralCuboid()));
235 action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"primitive_cube.png"));
236 whatsThisGen.
setWhatsThis(action,tr(
"Create a Tetrahedral Cuboid."),
"Cuboid");
239 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 240 action = primitivesMenu_->addAction(
"Cube (Hexahedral Mesh)" ,
this,SLOT(addHexahedralCube()));
241 action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"primitive_cube.png"));
242 whatsThisGen.
setWhatsThis(action,tr(
"Create a Hexahedral Cube."),
"Cube");
249 int PrimitivesGeneratorPlugin::addTriMesh() {
256 emit log(
LOGERR,
"Unable to create new Object");
263 int PrimitivesGeneratorPlugin::addPolyMesh() {
270 emit log(
LOGERR,
"Unable to create new Object");
278 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 279 int PrimitivesGeneratorPlugin::addPolyhedralMesh() {
286 emit log(
LOGERR,
"Unable to create new PolyhedralMesh object");
295 int PrimitivesGeneratorPlugin::addTetrahedron(
const Vector& _position,
const double _length) {
297 int newObject = addTriMesh();
301 emit log(
LOGERR,
"Unable to create new Object");
305 object->setName(
"Tetrahedron " + QString::number(newObject) );
307 triMesh_ =
object->mesh();
314 const double halfSize = 0.5*_length;
316 vhandles_[0] = triMesh_->add_vertex(
TriMesh::Point(-halfSize, -halfSize, halfSize)+_position);
317 vhandles_[1] = triMesh_->add_vertex(
TriMesh::Point( halfSize, halfSize, halfSize)+_position);
318 vhandles_[2] = triMesh_->add_vertex(
TriMesh::Point(-halfSize, halfSize, -halfSize)+_position);
319 vhandles_[3] = triMesh_->add_vertex(
TriMesh::Point( halfSize, -halfSize, -halfSize)+_position);
327 triMesh_->update_normals();
330 emit createBackup(newObject,
"Original Object");
340 int PrimitivesGeneratorPlugin::addTriangulatedCube(
const Vector& _position,
const double _length) {
341 int newObject = addTriMesh();
345 emit log(
LOGERR,
"Unable to create new Object");
349 object->setName(
"Cube " + QString::number(newObject) );
351 triMesh_ =
object->mesh();
358 const double halfSize = 0.5*_length;
360 vhandles_[0] = triMesh_->add_vertex(
TriMesh::Point( halfSize, -halfSize, halfSize)+_position);
361 vhandles_[1] = triMesh_->add_vertex(
TriMesh::Point( halfSize, halfSize, halfSize)+_position);
362 vhandles_[2] = triMesh_->add_vertex(
TriMesh::Point(-halfSize, halfSize, halfSize)+_position);
363 vhandles_[3] = triMesh_->add_vertex(
TriMesh::Point(-halfSize, -halfSize, halfSize)+_position);
364 vhandles_[4] = triMesh_->add_vertex(
TriMesh::Point( halfSize, -halfSize,-halfSize)+_position);
365 vhandles_[5] = triMesh_->add_vertex(
TriMesh::Point( halfSize, halfSize,-halfSize)+_position);
366 vhandles_[6] = triMesh_->add_vertex(
TriMesh::Point(-halfSize, halfSize,-halfSize)+_position);
367 vhandles_[7] = triMesh_->add_vertex(
TriMesh::Point(-halfSize, -halfSize,-halfSize)+_position);
385 triMesh_->update_normals();
388 emit createBackup(newObject,
"Original Object");
398 int PrimitivesGeneratorPlugin::addCube(
const Vector& _position,
const double _length) {
399 int newObject = addPolyMesh();
403 emit log(
LOGERR,
"Unable to create new Object");
407 object->setName(
"Cube " + QString::number(newObject) );
409 polyMesh_ =
object->mesh();
415 const double halfSize = 0.5*_length;
423 vhandles_[0] = polyMesh_->add_vertex(
PolyMesh::Point( halfSize, -halfSize, halfSize)+_position);
424 vhandles_[1] = polyMesh_->add_vertex(
PolyMesh::Point( halfSize, halfSize, halfSize)+_position);
425 vhandles_[2] = polyMesh_->add_vertex(
PolyMesh::Point(-halfSize, halfSize, halfSize)+_position);
426 vhandles_[3] = polyMesh_->add_vertex(
PolyMesh::Point(-halfSize, -halfSize, halfSize)+_position);
427 vhandles_[4] = polyMesh_->add_vertex(
PolyMesh::Point( halfSize, -halfSize,-halfSize)+_position);
428 vhandles_[5] = polyMesh_->add_vertex(
PolyMesh::Point( halfSize, halfSize,-halfSize)+_position);
429 vhandles_[6] = polyMesh_->add_vertex(
PolyMesh::Point(-halfSize, halfSize,-halfSize)+_position);
430 vhandles_[7] = polyMesh_->add_vertex(
PolyMesh::Point(-halfSize, -halfSize,-halfSize)+_position);
440 polyMesh_->update_normals();
443 emit createBackup(newObject,
"Original Object");
457 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 459 int PrimitivesGeneratorPlugin::addTetrahedralCube(
const Vector& _position,
const double _length)
461 return addTetrahedralCuboid(_position,
Vector(_length, _length, _length), 1, 1, 1);
470 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 472 int PrimitivesGeneratorPlugin::addTetrahedralCuboid(
const Vector& _position,
473 const Vector& _length,
const unsigned int n_x,
const unsigned int n_y,
const unsigned int n_z)
476 int object_id = addPolyhedralMesh();
483 object->
setName(
"Cuboid " + QString::number(object_id));
488 emit createBackup(object_id,
"Original Object");
502 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 504 int PrimitivesGeneratorPlugin::addHexahedralCube(
const Vector& _position,
const double _length)
511 emit log(
LOGERR,
"Unable to create new HexahedralMesh object");
514 object->setName(
"HexCube " + QString::number(object_id) );
516 auto mesh =
object->mesh();
518 std::vector<OVM::VertexHandle> vertices(8);
520 const double halfSize = 0.5*_length;
521 vertices[0] = mesh->
add_vertex(
Vector(-halfSize, -halfSize, halfSize)+_position);
522 vertices[1] = mesh->
add_vertex(
Vector( halfSize, -halfSize, halfSize)+_position);
523 vertices[2] = mesh->
add_vertex(
Vector( halfSize, halfSize, halfSize)+_position);
524 vertices[3] = mesh->
add_vertex(
Vector(-halfSize, halfSize, halfSize)+_position);
525 vertices[4] = mesh->
add_vertex(
Vector(-halfSize, -halfSize,-halfSize)+_position);
526 vertices[5] = mesh->
add_vertex(
Vector(-halfSize, halfSize,-halfSize)+_position);
527 vertices[6] = mesh->
add_vertex(
Vector( halfSize, halfSize,-halfSize)+_position);
528 vertices[7] = mesh->
add_vertex(
Vector( halfSize, -halfSize,-halfSize)+_position);
530 mesh->add_cell(vertices);
533 emit createBackup(object_id,
"Original Object");
549 ACG::Vec3d PrimitivesGeneratorPlugin::positionOnCylinder(
const int _sliceNumber,
550 const int _stackNumber,
553 const double _radius,
554 const double _height)
559 const ACG::Vec3d left = (cross( _axis, right)).normalized();
561 double beta = ((2.0 * M_PI) /
double(slices_)) *
double(_sliceNumber);
563 if ( _sliceNumber == 0 && _stackNumber == 0) {
566 position[2] = _height;
567 }
else if ( _sliceNumber == slices_ && _stackNumber == stacks_ ) {
572 position[0] = sin(beta) * _radius;
573 position[1] = cos(beta) * _radius;
574 position[2] = _height * double(stacks_ - _stackNumber -1 ) / double(stacks_-2);
577 position = _position + position[0] * right + position[1] * left + position[2] * _axis ;
582 int PrimitivesGeneratorPlugin::addTriangulatedCylinder(
const Vector& _position,
const Vector& _axis,
const double _radius,
const double _height,
const bool _top,
const bool _bottom ) {
585 int newObject = addTriMesh();
589 emit log(
LOGERR,
"Unable to create new Object");
593 object->setName(
"Cylinder " + QString::number(newObject) );
595 triMesh_ =
object->mesh();
601 TriMesh::VertexHandle vh;
602 TriMesh::VertexHandle top = triMesh_->add_vertex(positionOnCylinder(0, 0,_position,_axis,_radius,_height));
605 for (
int st = 1; st < stacks_; ++st) {
606 for (
int sl = 0; sl < slices_; ++sl) {
607 vh = triMesh_->add_vertex(positionOnCylinder(sl, st,_position,_axis,_radius,_height));
612 TriMesh::VertexHandle bottom = triMesh_->add_vertex(positionOnCylinder(slices_, stacks_,_position,_axis,_radius,_height));
615 std::vector<TriMesh::VertexHandle> vhandles;
619 for (
int sl = 1; sl < slices_ + 1; ++sl) {
623 vhandles.push_back(triMesh_->vertex_handle(sl));
624 vhandles.push_back(triMesh_->vertex_handle(0));
625 vhandles.push_back(triMesh_->vertex_handle(1 * 1 + (sl % slices_)));
627 triMesh_->add_face(vhandles);
630 triMesh_->delete_vertex(top);
633 for (
int st = 0; st < stacks_ - 2; ++st) {
636 for (
int sl = 0; sl < slices_; ++sl) {
639 unsigned int startTop = 1 + slices_ * st;
640 unsigned int startBottom = 1 + slices_ * (st + 1);
644 vhandles.push_back(triMesh_->vertex_handle(startTop + sl));
645 vhandles.push_back(triMesh_->vertex_handle(startTop + ((sl + 1) % slices_)));
646 vhandles.push_back(triMesh_->vertex_handle(startBottom + sl));
648 triMesh_->add_face(vhandles);
652 vhandles.push_back(triMesh_->vertex_handle(startBottom + sl));
653 vhandles.push_back(triMesh_->vertex_handle(startTop + ((sl + 1) % slices_)));
654 vhandles.push_back(triMesh_->vertex_handle(startBottom + ((sl + 1) % slices_)));
656 triMesh_->add_face(vhandles);
661 const int startTop = 1 + (stacks_ - 2) * slices_;
662 const int bottomVertex = 1 + (stacks_ - 1) * slices_;
666 for (
int sl = 0; sl < slices_; ++sl) {
670 vhandles.push_back(triMesh_->vertex_handle(bottomVertex));
671 vhandles.push_back(triMesh_->vertex_handle(startTop + sl));
672 vhandles.push_back(triMesh_->vertex_handle(startTop + ((sl + 1) % slices_)));
674 triMesh_->add_face(vhandles);
677 triMesh_->delete_vertex(bottom);
681 triMesh_->garbage_collection();
683 triMesh_->update_normals();
686 emit createBackup(newObject,
"Original Object");
701 ACG::Vec3d PrimitivesGeneratorPlugin::positionOnSphere(
int _sliceNumber,
int _stackNumber,
double _radius,
const Vector& _position)
705 double alpha = (M_PI / double(stacks_)) *
double(_stackNumber);
706 double beta = ((2.0 * M_PI) /
double(slices_)) *
double(_sliceNumber);
708 double ringRadius = sin(alpha);
709 position[0] = sin(beta) * ringRadius * _radius;
710 position[1] = cos(beta) * ringRadius * _radius;
711 position[2] = cos(alpha)* _radius;
713 return _position+position;
718 ACG::Vec2f PrimitivesGeneratorPlugin::texCoordOnSphere(
int _sliceNumber,
int _stackNumber)
722 double alpha = (M_PI / double(stacks_)) *
double(_stackNumber);
723 texCoord[0] = double(_sliceNumber) / double(slices_);
724 texCoord[1] = 0.5 * (cos(alpha) + 1.0);
732 int PrimitivesGeneratorPlugin::addSphere(
const Vector& _position,
const double _radius)
734 int newObject = addTriMesh();
738 emit log(
LOGERR,
"Unable to create new Object");
742 object->setName(
"Sphere " + QString::number(newObject) );
744 triMesh_ =
object->mesh();
748 triMesh_->request_vertex_texcoords2D();
750 TriMesh::VertexHandle vh;
752 vh = triMesh_->add_vertex(positionOnSphere(0, 0, _radius,_position));
753 triMesh_->set_texcoord2D(vh, texCoordOnSphere(0, 0));
755 for (
int st = 1; st < stacks_; ++st) {
756 for (
int sl = 0; sl < slices_; ++sl) {
757 vh = triMesh_->add_vertex(positionOnSphere(sl, st, _radius,_position));
758 triMesh_->set_texcoord2D(vh, texCoordOnSphere(sl, st));
762 vh = triMesh_->add_vertex(positionOnSphere(slices_, stacks_, _radius,_position));
763 triMesh_->set_texcoord2D(vh, texCoordOnSphere(slices_, stacks_));
765 std::vector<TriMesh::VertexHandle> vhandles;
768 for (
int sl = 1; sl < slices_ + 1; ++sl) {
772 vhandles.push_back(triMesh_->vertex_handle(sl));
773 vhandles.push_back(triMesh_->vertex_handle(0));
774 vhandles.push_back(triMesh_->vertex_handle(1 * 1 + (sl % slices_)));
776 triMesh_->add_face(vhandles);
779 for (
int st = 0; st < stacks_ - 2; ++st) {
782 for (
int sl = 0; sl < slices_; ++sl) {
785 unsigned int startTop = 1 + slices_ * st;
786 unsigned int startBottom = 1 + slices_ * (st + 1);
790 vhandles.push_back(triMesh_->vertex_handle(startTop + sl));
791 vhandles.push_back(triMesh_->vertex_handle(startTop + ((sl + 1) % slices_)));
792 vhandles.push_back(triMesh_->vertex_handle(startBottom + sl));
794 triMesh_->add_face(vhandles);
798 vhandles.push_back(triMesh_->vertex_handle(startBottom + sl));
799 vhandles.push_back(triMesh_->vertex_handle(startTop + ((sl + 1) % slices_)));
800 vhandles.push_back(triMesh_->vertex_handle(startBottom + ((sl + 1) % slices_)));
802 triMesh_->add_face(vhandles);
807 const int startTop = 1 + (stacks_ - 2) * slices_;
808 const int bottomVertex = 1 + (stacks_ - 1) * slices_;
811 for (
int sl = 0; sl < slices_; ++sl) {
815 vhandles.push_back(triMesh_->vertex_handle(bottomVertex));
816 vhandles.push_back(triMesh_->vertex_handle(startTop + sl));
817 vhandles.push_back(triMesh_->vertex_handle(startTop + ((sl + 1) % slices_)));
819 triMesh_->add_face(vhandles);
822 triMesh_->update_normals();
825 emit createBackup(newObject,
"Original Object");
837 int PrimitivesGeneratorPlugin::addSubdivisionSphere(
const Vector& _position,
const double _radius)
841 int newObject = addTriMesh();
845 emit log(
LOGERR,
"Unable to create new Object");
848 object->setName(
"Sphere " + QString::number(newObject) );
850 triMesh_ =
object->mesh();
851 constructOctahedron(_position, _radius);
854 const size_t subdivisionSteps = 4;
856 for (
size_t i = 0 ; i < subdivisionSteps; ++i) {
859 RPC::callFunction(
"subdivider",
"subdivide", newObject, QString(
"loop"), 1,
false);
862 for (TriMesh::VertexIter v_it = triMesh_->vertices_begin(); v_it != triMesh_->vertices_end(); ++v_it) {
866 triMesh_->set_point(*v_it, p);
871 triMesh_->update_normals();
874 emit createBackup(newObject,
"Original Object");
890 int PrimitivesGeneratorPlugin::addPyramid(
const Vector& _position,
const double _length) {
891 int newObject = addTriMesh();
895 emit log(
LOGERR,
"Unable to create new Object");
899 object->setName(
"Pyramid " + QString::number(newObject) );
901 triMesh_ =
object->mesh();
908 const double halfLength = 0.5*_length;
910 vhandles_[0] = triMesh_->add_vertex(
TriMesh::Point( halfLength, -halfLength, 0.0)+_position);
911 vhandles_[1] = triMesh_->add_vertex(
TriMesh::Point( halfLength, halfLength, 0.0)+_position);
912 vhandles_[2] = triMesh_->add_vertex(
TriMesh::Point(-halfLength, halfLength, 0.0)+_position);
913 vhandles_[3] = triMesh_->add_vertex(
TriMesh::Point(-halfLength, -halfLength, 0.0)+_position);
915 vhandles_[4] = triMesh_->add_vertex(
TriMesh::Point(0.0, 0.0, sqrt(2.0)*halfLength));
926 triMesh_->update_normals();
929 emit createBackup(newObject,
"Original Object");
939 void PrimitivesGeneratorPlugin::add_face(
int _vh1 ,
int _vh2,
int _vh3) {
941 static_cast<TriMesh::VertexHandle>(_vh1),
942 static_cast<TriMesh::VertexHandle>(_vh2),
943 static_cast<TriMesh::VertexHandle>(_vh3)
947 void PrimitivesGeneratorPlugin::add_face(
int _vh1,
int _vh2,
int _vh3,
int _vh4)
950 static_cast<PolyMesh::VertexHandle>(_vh1),
951 static_cast<PolyMesh::VertexHandle>(_vh2),
952 static_cast<PolyMesh::VertexHandle>(_vh3),
953 static_cast<PolyMesh::VertexHandle>(_vh4)
957 void PrimitivesGeneratorPlugin::add_face(
int _vh1 ,
int _vh2,
int _vh3,
int _vh4 ,
int _vh5 ) {
958 std::vector<PolyMesh::VertexHandle> vhandles;
960 vhandles.push_back(vphandles_[_vh1]);
961 vhandles.push_back(vphandles_[_vh2]);
962 vhandles.push_back(vphandles_[_vh3]);
963 vhandles.push_back(vphandles_[_vh4]);
964 vhandles.push_back(vphandles_[_vh5]);
966 polyMesh_->add_face(vhandles);
969 int PrimitivesGeneratorPlugin::addIcosahedron(
const Vector& _position,
const double _length) {
970 int newObject = addTriMesh();
974 emit log(
LOGERR,
"Unable to create new Object");
978 object->setName(
"Icosahedron " + QString::number(newObject) );
980 triMesh_ =
object->mesh();
985 vhandles_.resize(12);
987 const double phi = 0.5 * (1.0 + sqrt(5.0));
989 const double norm = 1.0;
990 const double halfLength = 0.5*_length;
992 vhandles_[0 ] = triMesh_->add_vertex(norm *
TriMesh::Point( 0.0 , -halfLength , -phi )+_position);
993 vhandles_[1 ] = triMesh_->add_vertex(norm *
TriMesh::Point( 0.0 , halfLength , -phi )+_position);
994 vhandles_[2 ] = triMesh_->add_vertex(norm *
TriMesh::Point( 0.0 , halfLength , phi )+_position);
995 vhandles_[3 ] = triMesh_->add_vertex(norm *
TriMesh::Point( 0.0 , -halfLength , phi )+_position);
997 vhandles_[4 ] = triMesh_->add_vertex(norm *
TriMesh::Point( -halfLength , -phi , 0.0 )+_position);
998 vhandles_[5 ] = triMesh_->add_vertex(norm *
TriMesh::Point( halfLength , -phi , 0.0 )+_position);
999 vhandles_[6 ] = triMesh_->add_vertex(norm *
TriMesh::Point( halfLength , phi , 0.0 )+_position);
1000 vhandles_[7 ] = triMesh_->add_vertex(norm *
TriMesh::Point( -halfLength , phi , 0.0 )+_position);
1002 vhandles_[8 ] = triMesh_->add_vertex(norm *
TriMesh::Point( -phi , 0.0 , -halfLength )+_position);
1003 vhandles_[9 ] = triMesh_->add_vertex(norm *
TriMesh::Point( -phi , 0.0 , halfLength )+_position);
1004 vhandles_[10] = triMesh_->add_vertex(norm *
TriMesh::Point( phi , 0.0 , halfLength )+_position);
1005 vhandles_[11] = triMesh_->add_vertex(norm *
TriMesh::Point( phi , 0.0 , -halfLength )+_position);
1039 triMesh_->update_normals();
1042 emit createBackup(newObject,
"Original Object");
1052 void PrimitivesGeneratorPlugin::constructOctahedron(
const Vector& _position,
const double _length)
1057 vhandles_.resize(6);
1059 const double sqrtLength = sqrt(_length);
1061 vhandles_[0 ] = triMesh_->add_vertex(
TriMesh::Point(-sqrtLength, 0.0, 0.0)+_position);
1062 vhandles_[1 ] = triMesh_->add_vertex(
TriMesh::Point( 0.0, -sqrtLength, 0.0)+_position);
1063 vhandles_[2 ] = triMesh_->add_vertex(
TriMesh::Point( sqrtLength, 0.0, 0.0)+_position);
1064 vhandles_[3 ] = triMesh_->add_vertex(
TriMesh::Point( 0.0, sqrtLength, 0.0)+_position);
1066 vhandles_[4 ] = triMesh_->add_vertex(
TriMesh::Point( 0.0, 0.0, sqrtLength)+_position);
1067 vhandles_[5 ] = triMesh_->add_vertex(
TriMesh::Point( 0.0, 0.0, -sqrtLength)+_position);
1083 triMesh_->update_normals();
1086 int PrimitivesGeneratorPlugin::addOctahedron(
const Vector& _position,
const double _length) {
1087 int newObject = addTriMesh();
1091 emit log(
LOGERR,
"Unable to create new Object");
1095 object->setName(
"Octahedron " + QString::number(newObject) );
1097 triMesh_ =
object->mesh();
1099 constructOctahedron(_position, _length);
1102 emit createBackup(newObject,
"Original Object");
1112 int PrimitivesGeneratorPlugin::addDodecahedron(
const Vector& _position,
const double _length) {
1113 int newObject = addPolyMesh();
1117 emit log(
LOGERR,
"Unable to create new Object");
1121 object->setName(
"Dodecahedron " + QString::number(newObject) );
1123 polyMesh_ =
object->mesh();
1128 vphandles_.resize(20);
1130 const double phi = (1.0 + sqrt(5.0)) / 2.0;
1131 const double halfLength = 0.5*_length;
1134 vphandles_[0 ] = polyMesh_->add_vertex(
TriMesh::Point( halfLength , halfLength , halfLength )+_position);
1135 vphandles_[1 ] = polyMesh_->add_vertex(
TriMesh::Point( halfLength , halfLength ,-halfLength )+_position);
1136 vphandles_[2 ] = polyMesh_->add_vertex(
TriMesh::Point( halfLength , -halfLength , halfLength )+_position);
1137 vphandles_[3 ] = polyMesh_->add_vertex(
TriMesh::Point( halfLength , -halfLength ,-halfLength )+_position);
1138 vphandles_[4 ] = polyMesh_->add_vertex(
TriMesh::Point( -halfLength , halfLength , halfLength )+_position);
1139 vphandles_[5 ] = polyMesh_->add_vertex(
TriMesh::Point( -halfLength , halfLength ,-halfLength )+_position);
1140 vphandles_[6 ] = polyMesh_->add_vertex(
TriMesh::Point( -halfLength , -halfLength , halfLength )+_position);
1141 vphandles_[7 ] = polyMesh_->add_vertex(
TriMesh::Point( -halfLength , -halfLength ,-halfLength )+_position);
1143 vphandles_[8 ] = polyMesh_->add_vertex(
TriMesh::Point( 0.0 , halfLength / phi , phi )+_position);
1144 vphandles_[9 ] = polyMesh_->add_vertex(
TriMesh::Point( 0.0 , halfLength / phi , -phi )+_position);
1145 vphandles_[10] = polyMesh_->add_vertex(
TriMesh::Point( 0.0 , -halfLength / phi , phi )+_position);
1146 vphandles_[11] = polyMesh_->add_vertex(
TriMesh::Point( 0.0 , -halfLength / phi , -phi )+_position);
1148 vphandles_[12] = polyMesh_->add_vertex(
TriMesh::Point( halfLength / phi , phi, 0.0)+_position);
1149 vphandles_[13] = polyMesh_->add_vertex(
TriMesh::Point( halfLength / phi , -phi, 0.0)+_position);
1150 vphandles_[14] = polyMesh_->add_vertex(
TriMesh::Point( -halfLength / phi , phi, 0.0)+_position);
1151 vphandles_[15] = polyMesh_->add_vertex(
TriMesh::Point( -halfLength / phi , -phi, 0.0)+_position);
1153 vphandles_[16] = polyMesh_->add_vertex(
TriMesh::Point( phi , 0.0 , halfLength / phi)+_position);
1154 vphandles_[17] = polyMesh_->add_vertex(
TriMesh::Point( phi , 0.0 ,-halfLength / phi)+_position);
1155 vphandles_[18] = polyMesh_->add_vertex(
TriMesh::Point( -phi , 0.0 , halfLength / phi)+_position);
1156 vphandles_[19] = polyMesh_->add_vertex(
TriMesh::Point( -phi , 0.0 ,-halfLength / phi)+_position);
1159 add_face(14, 5,19,18, 4);
1160 add_face( 5, 9,11, 7,19);
1161 add_face( 6,15,13, 2,10);
1162 add_face(12, 0,16,17, 1);
1164 add_face( 0, 8,10, 2,16);
1165 add_face(16, 2,13, 3,17);
1166 add_face( 3,13,15, 7,11);
1167 add_face( 7,15, 6,18,19);
1169 add_face( 4,18, 6,10, 8);
1170 add_face( 4, 8, 0,12,14);
1171 add_face(14,12, 1, 9, 5);
1172 add_face( 9, 1,17, 3,11);
1174 polyMesh_->update_normals();
1177 emit createBackup(newObject,
"Original Object");
1187 #ifdef ENABLE_BSPLINECURVE_SUPPORT 1188 int PrimitivesGeneratorPlugin::addRandomBSplineCurve(
const Vector& _position,
int nDiv)
1203 curve->autocompute_knotvector(
true);
1204 for (
int i = 0; i < nDiv; ++i) {
1205 double x = _position[0] + i - nDiv / 2.0;
1207 double r = (2.0 * std::rand()) / RAND_MAX - 1.0;
1208 BSplineCurve::Point cp(x, _position[1] + r, _position[2]);
1213 emit createBackup(
id,
"Original Object");
1221 #ifdef ENABLE_BSPLINESURFACE_SUPPORT 1222 int PrimitivesGeneratorPlugin::addRandomBSplineSurface(
const Vector& _position,
int nDiv)
1236 typedef BSplineSurface::Point Point;
1237 std::vector<Point> cp(nDiv);
1239 for (
int i = 0; i < nDiv; ++i) {
1240 double x = _position[0] + i - nDiv / 2.0;
1241 for (
int j = 0; j < nDiv; ++j) {
1242 double y = _position[1] + j - nDiv / 2.0;
1243 cp[j] = Point(x, y, _position[2] + (2.0 * std::rand()) / RAND_MAX - 1);
1250 emit createBackup(
id,
"Original Object");
void add_vector_m(const std::vector< Point > &_control_polygon)
Adds a control point n-vector.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
void initializePlugin()
BaseInterface.
void createKnots()
Creates interpolating knotvectors 0...0, 1, 2, ..., n...n.
Kernel::Point Point
Coordinate type.
VertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
const DrawMode & getDrawMode(const std::string &_name)
Get a custom DrawMode.
auto normalize() -> decltype(*this/=std::declval< VectorT< S, DIM >>().norm())
QScriptValue callFunction(QString _plugin, QString _functionName, std::vector< QScriptValue > _parameters)
Call a function provided by a plugin getting multiple parameters.
void add_control_point(const Point &_cp)
add a control point
void setName(QString _name)
Set the name of the Object.
VectorT< Scalar, 3 > perpendicular(const VectorT< Scalar, 3 > &v)
find a vector that's perpendicular to _v
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
Type for a MeshObject containing a triangle mesh.
#define DATA_BSPLINE_SURFACE
#define DATA_HEXAHEDRAL_MESH
void viewAll(int _viewer)
View the whole scene.
a class which provides an link generator for WhatsThisMessages linking to the user doc If you have an...
#define DATA_POLYHEDRAL_MESH
ACG::Vec3d Vector
Standard Type for 3d Vector used for scripting.
#define DATA_TRIANGLE_MESH
MeshT * mesh()
return a pointer to the mesh
#define DATA_BSPLINE_CURVE
Type for a Meshobject containing a poly mesh.
void setWhatsThis(QAction *_action, const QString &_msg, const QString &_ref="", const QString &_site="index.html") const
sets a whatsThis Message plus link to the doc for the given QAction