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");
246 action = primitivesMenu_->addAction(
"Plane (Triangle Mesh)" ,
this,SLOT(addTriangulatedPlaneFlat()));
247 action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"primitive_plane_flat.png"));
248 whatsThisGen.
setWhatsThis(action,tr(
"Create a flat simple plane."),
"Plane");
250 action = primitivesMenu_->addAction(
"Plane, bumpy (Triangle Mesh)" ,
this,SLOT(addTriangulatedPlaneBumpy()));
251 action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"primitive_plane_bumpy.png"));
252 whatsThisGen.
setWhatsThis(action,tr(
"Create a bumpy plane."),
"Plane");
254 action = primitivesMenu_->addAction(
"Perpendicular planes Non-Manifold (Triangle Mesh)" ,
this,SLOT(addTriangulatedPlanesNonManifold()));
255 action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"primitive_plane_non-manifold.png"));
256 whatsThisGen.
setWhatsThis(action,tr(
"Create a non manifold plane configuration."),
"Plane");
262 int PrimitivesGeneratorPlugin::addTriMesh() {
269 emit log(
LOGERR,
"Unable to create new Object");
276 int PrimitivesGeneratorPlugin::addPolyMesh() {
283 emit log(
LOGERR,
"Unable to create new Object");
291 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 292 int PrimitivesGeneratorPlugin::addPolyhedralMesh() {
299 emit log(
LOGERR,
"Unable to create new PolyhedralMesh object");
308 int PrimitivesGeneratorPlugin::addTetrahedron(
const Vector& _position,
const double _length) {
310 int newObject = addTriMesh();
314 emit log(
LOGERR,
"Unable to create new Object");
318 object->setName(
"Tetrahedron " + QString::number(newObject) );
320 triMesh_ =
object->mesh();
327 const double halfSize = 0.5*_length;
329 vhandles_[0] = triMesh_->add_vertex(
TriMesh::Point(-halfSize, -halfSize, halfSize)+_position);
330 vhandles_[1] = triMesh_->add_vertex(
TriMesh::Point( halfSize, halfSize, halfSize)+_position);
331 vhandles_[2] = triMesh_->add_vertex(
TriMesh::Point(-halfSize, halfSize, -halfSize)+_position);
332 vhandles_[3] = triMesh_->add_vertex(
TriMesh::Point( halfSize, -halfSize, -halfSize)+_position);
340 triMesh_->update_normals();
343 emit createBackup(newObject,
"Original Object");
354 int PrimitivesGeneratorPlugin::addTriangulatedPlaneFlat(
const Vector& _position ,
355 const double _sizeX ,
const double _sizeY ,
356 const int _segmentsX ,
const int _segmentsY )
358 int newObject = addTriMesh();
362 emit log(
LOGERR,
"Unable to create new Object");
366 object->setName(
"Cube " + QString::number(newObject) );
368 triMesh_ =
object->mesh();
371 vhandles_.resize( (_segmentsX+1) * (_segmentsY+1) );
373 for (
auto i = 0 ; i < (_segmentsX + 1) ; ++i) {
374 for (
auto j = 0 ; j < (_segmentsY + 1) ; ++j) {
375 vhandles_[ i * (_segmentsY + 1) + j ] = triMesh_->add_vertex(
TriMesh::Point( _sizeX / _segmentsX * i , _sizeY / _segmentsY * j ,0)+_position);
379 for (
auto i = 0 ; i < _segmentsX ; ++i) {
380 for (
auto j = 0 ; j < _segmentsY ; ++j) {
381 add_face(i * (_segmentsY+1) + j, (i + 1) * (_segmentsY+1) + j, i * (_segmentsY+1) + j + 1);
382 add_face(i * (_segmentsY+1) + j + 1, (i + 1) * (_segmentsY+1) + j, (i + 1) * (_segmentsY+1) + j + 1);
387 triMesh_->update_normals();
390 emit createBackup(newObject,
"Original Object");
400 int PrimitivesGeneratorPlugin::addTriangulatedPlaneBumpy(
const Vector& _position ,
401 const double _sizeX ,
const double _sizeY ,
402 const int _segmentsX ,
const int _segmentsY )
404 int newObject = addTriMesh();
408 emit log(
LOGERR,
"Unable to create new Object");
412 object->setName(
"Cube " + QString::number(newObject) );
414 triMesh_ =
object->mesh();
417 vhandles_.resize( (_segmentsX+1) * (_segmentsY+1) );
419 for (
auto i = 0 ; i < (_segmentsX + 1) ; ++i) {
420 for (
auto j = 0 ; j < (_segmentsY + 1) ; ++j) {
423 const double x = _sizeX / _segmentsX * i - _sizeX / 2.0;
424 const double y = _sizeY / _segmentsY * j - _sizeY / 2.0;
425 const double z = sin( x * x) * cos( y * y) ;
426 vhandles_[ i * (_segmentsY + 1) + j ] = triMesh_->add_vertex(
TriMesh::Point( x , y , z ) +_position);
430 for (
auto i = 0 ; i < _segmentsX ; ++i) {
431 for (
auto j = 0 ; j < _segmentsY ; ++j) {
432 add_face(i * (_segmentsY+1) + j, (i + 1) * (_segmentsY+1) + j, i * (_segmentsY+1) + j + 1);
433 add_face(i * (_segmentsY+1) + j + 1, (i + 1) * (_segmentsY+1) + j, (i + 1) * (_segmentsY+1) + j + 1);
438 triMesh_->update_normals();
441 emit createBackup(newObject,
"Original Object");
452 int PrimitivesGeneratorPlugin::addTriangulatedPlanesNonManifold(
const Vector& _position ,
453 const double _sizeX ,
const double _sizeY ,
const double _sizeZ ,
454 const int _segmentsX ,
const int _segmentsY ,
const int _segmentsZ )
456 int newObject = addTriMesh();
460 emit log(
LOGERR,
"Unable to create new Object");
464 object->setName(
"Cube " + QString::number(newObject) );
466 triMesh_ =
object->mesh();
469 vhandles_.resize( (_segmentsX+1) * (_segmentsY+1) );
472 for (
auto i = 0 ; i < (_segmentsX + 1) ; ++i) {
473 for (
auto j = 0 ; j < (_segmentsY + 1) ; ++j) {
474 vhandles_[ i * (_segmentsY + 1) + j ] = triMesh_->add_vertex(
TriMesh::Point( _sizeX / _segmentsX * i , _sizeY / _segmentsY * j ,0)+_position);
478 for (
auto i = 0 ; i < _segmentsX ; ++i) {
479 for (
auto j = 0 ; j < _segmentsY ; ++j) {
480 add_face(i * (_segmentsY+1) + j, (i + 1) * (_segmentsY+1) + j, i * (_segmentsY+1) + j + 1);
481 add_face(i * (_segmentsY+1) + j + 1, (i + 1) * (_segmentsY+1) + j, (i + 1) * (_segmentsY+1) + j + 1);
486 vhandles_.resize( (_segmentsX+1) * (_segmentsY+1) );
490 for (
auto j = 0 ; j < (_segmentsY + 1) ; ++j) {
491 for (
auto k = 0 ; k < (_segmentsZ + 1) ; ++k) {
492 vhandles_[ j * (_segmentsY + 1) + k ] = triMesh_->add_vertex(
TriMesh::Point(_sizeX / 2, _sizeY / _segmentsY * j , _sizeZ / _segmentsZ * k )+_position);
496 const int offset = (_segmentsX+1) * (_segmentsY+1);
498 for (
auto i = 0 ; i < _segmentsY ; ++i) {
499 for (
auto j = 0 ; j < _segmentsZ ; ++j) {
500 add_face(offset + i * (_segmentsZ+1) + j, offset + (i + 1) * (_segmentsZ+1) + j, offset + i * (_segmentsZ+1) + j + 1);
501 add_face(offset + i * (_segmentsZ+1) + j + 1, offset + (i + 1) * (_segmentsZ+1) + j, offset + (i + 1) * (_segmentsZ+1) + j + 1);
505 triMesh_->update_normals();
508 emit createBackup(newObject,
"Original Object");
519 int PrimitivesGeneratorPlugin::addTriangulatedCube(
const Vector& _position,
const double _length) {
520 int newObject = addTriMesh();
524 emit log(
LOGERR,
"Unable to create new Object");
528 object->setName(
"Cube " + QString::number(newObject) );
530 triMesh_ =
object->mesh();
537 const double halfSize = 0.5*_length;
539 vhandles_[0] = triMesh_->add_vertex(
TriMesh::Point( halfSize, -halfSize, halfSize)+_position);
540 vhandles_[1] = triMesh_->add_vertex(
TriMesh::Point( halfSize, halfSize, halfSize)+_position);
541 vhandles_[2] = triMesh_->add_vertex(
TriMesh::Point(-halfSize, halfSize, halfSize)+_position);
542 vhandles_[3] = triMesh_->add_vertex(
TriMesh::Point(-halfSize, -halfSize, halfSize)+_position);
543 vhandles_[4] = triMesh_->add_vertex(
TriMesh::Point( halfSize, -halfSize,-halfSize)+_position);
544 vhandles_[5] = triMesh_->add_vertex(
TriMesh::Point( halfSize, halfSize,-halfSize)+_position);
545 vhandles_[6] = triMesh_->add_vertex(
TriMesh::Point(-halfSize, halfSize,-halfSize)+_position);
546 vhandles_[7] = triMesh_->add_vertex(
TriMesh::Point(-halfSize, -halfSize,-halfSize)+_position);
564 triMesh_->update_normals();
567 emit createBackup(newObject,
"Original Object");
577 int PrimitivesGeneratorPlugin::addCube(
const Vector& _position,
const double _length) {
578 int newObject = addPolyMesh();
582 emit log(
LOGERR,
"Unable to create new Object");
586 object->setName(
"Cube " + QString::number(newObject) );
588 polyMesh_ =
object->mesh();
594 const double halfSize = 0.5*_length;
602 vhandles_[0] = polyMesh_->add_vertex(
PolyMesh::Point( halfSize, -halfSize, halfSize)+_position);
603 vhandles_[1] = polyMesh_->add_vertex(
PolyMesh::Point( halfSize, halfSize, halfSize)+_position);
604 vhandles_[2] = polyMesh_->add_vertex(
PolyMesh::Point(-halfSize, halfSize, halfSize)+_position);
605 vhandles_[3] = polyMesh_->add_vertex(
PolyMesh::Point(-halfSize, -halfSize, halfSize)+_position);
606 vhandles_[4] = polyMesh_->add_vertex(
PolyMesh::Point( halfSize, -halfSize,-halfSize)+_position);
607 vhandles_[5] = polyMesh_->add_vertex(
PolyMesh::Point( halfSize, halfSize,-halfSize)+_position);
608 vhandles_[6] = polyMesh_->add_vertex(
PolyMesh::Point(-halfSize, halfSize,-halfSize)+_position);
609 vhandles_[7] = polyMesh_->add_vertex(
PolyMesh::Point(-halfSize, -halfSize,-halfSize)+_position);
619 polyMesh_->update_normals();
622 emit createBackup(newObject,
"Original Object");
636 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 638 int PrimitivesGeneratorPlugin::addTetrahedralCube(
const Vector& _position,
const double _length)
640 return addTetrahedralCuboid(_position,
Vector(_length, _length, _length), 1, 1, 1);
649 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 651 int PrimitivesGeneratorPlugin::addTetrahedralCuboid(
const Vector& _position,
652 const Vector& _length,
const unsigned int n_x,
const unsigned int n_y,
const unsigned int n_z)
655 int object_id = addPolyhedralMesh();
662 object->
setName(
"Cuboid " + QString::number(object_id));
667 emit createBackup(object_id,
"Original Object");
681 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 683 int PrimitivesGeneratorPlugin::addHexahedralCube(
const Vector& _position,
const double _length)
690 emit log(
LOGERR,
"Unable to create new HexahedralMesh object");
693 object->setName(
"HexCube " + QString::number(object_id) );
695 auto mesh =
object->mesh();
697 std::vector<OVM::VertexHandle> vertices(8);
699 const double halfSize = 0.5*_length;
700 vertices[0] = mesh->
add_vertex(
Vector(-halfSize, -halfSize, halfSize)+_position);
701 vertices[1] = mesh->
add_vertex(
Vector( halfSize, -halfSize, halfSize)+_position);
702 vertices[2] = mesh->
add_vertex(
Vector( halfSize, halfSize, halfSize)+_position);
703 vertices[3] = mesh->
add_vertex(
Vector(-halfSize, halfSize, halfSize)+_position);
704 vertices[4] = mesh->
add_vertex(
Vector(-halfSize, -halfSize,-halfSize)+_position);
705 vertices[5] = mesh->
add_vertex(
Vector(-halfSize, halfSize,-halfSize)+_position);
706 vertices[6] = mesh->
add_vertex(
Vector( halfSize, halfSize,-halfSize)+_position);
707 vertices[7] = mesh->
add_vertex(
Vector( halfSize, -halfSize,-halfSize)+_position);
709 mesh->add_cell(vertices);
712 emit createBackup(object_id,
"Original Object");
728 ACG::Vec3d PrimitivesGeneratorPlugin::positionOnCylinder(
const int _sliceNumber,
729 const int _stackNumber,
732 const double _radius,
733 const double _height)
738 const ACG::Vec3d left = (cross( _axis, right)).normalized();
740 double beta = ((2.0 * M_PI) /
double(slices_)) *
double(_sliceNumber);
742 if ( _sliceNumber == 0 && _stackNumber == 0) {
745 position[2] = _height;
746 }
else if ( _sliceNumber == slices_ && _stackNumber == stacks_ ) {
751 position[0] = sin(beta) * _radius;
752 position[1] = cos(beta) * _radius;
753 position[2] = _height * double(stacks_ - _stackNumber -1 ) / double(stacks_-2);
756 position = _position + position[0] * right + position[1] * left + position[2] * _axis ;
761 int PrimitivesGeneratorPlugin::addTriangulatedCylinder(
const Vector& _position,
const Vector& _axis,
const double _radius,
const double _height,
const bool _top,
const bool _bottom ) {
764 int newObject = addTriMesh();
768 emit log(
LOGERR,
"Unable to create new Object");
772 object->setName(
"Cylinder " + QString::number(newObject) );
774 triMesh_ =
object->mesh();
780 TriMesh::VertexHandle vh;
781 TriMesh::VertexHandle top = triMesh_->add_vertex(positionOnCylinder(0, 0,_position,_axis,_radius,_height));
784 for (
int st = 1; st < stacks_; ++st) {
785 for (
int sl = 0; sl < slices_; ++sl) {
786 vh = triMesh_->add_vertex(positionOnCylinder(sl, st,_position,_axis,_radius,_height));
791 TriMesh::VertexHandle bottom = triMesh_->add_vertex(positionOnCylinder(slices_, stacks_,_position,_axis,_radius,_height));
794 std::vector<TriMesh::VertexHandle> vhandles;
798 for (
int sl = 1; sl < slices_ + 1; ++sl) {
802 vhandles.push_back(triMesh_->vertex_handle(sl));
803 vhandles.push_back(triMesh_->vertex_handle(0));
804 vhandles.push_back(triMesh_->vertex_handle(1 * 1 + (sl % slices_)));
806 triMesh_->add_face(vhandles);
809 triMesh_->delete_vertex(top);
812 for (
int st = 0; st < stacks_ - 2; ++st) {
815 for (
int sl = 0; sl < slices_; ++sl) {
818 unsigned int startTop = 1 + slices_ * st;
819 unsigned int startBottom = 1 + slices_ * (st + 1);
823 vhandles.push_back(triMesh_->vertex_handle(startTop + sl));
824 vhandles.push_back(triMesh_->vertex_handle(startTop + ((sl + 1) % slices_)));
825 vhandles.push_back(triMesh_->vertex_handle(startBottom + sl));
827 triMesh_->add_face(vhandles);
831 vhandles.push_back(triMesh_->vertex_handle(startBottom + sl));
832 vhandles.push_back(triMesh_->vertex_handle(startTop + ((sl + 1) % slices_)));
833 vhandles.push_back(triMesh_->vertex_handle(startBottom + ((sl + 1) % slices_)));
835 triMesh_->add_face(vhandles);
840 const int startTop = 1 + (stacks_ - 2) * slices_;
841 const int bottomVertex = 1 + (stacks_ - 1) * slices_;
845 for (
int sl = 0; sl < slices_; ++sl) {
849 vhandles.push_back(triMesh_->vertex_handle(bottomVertex));
850 vhandles.push_back(triMesh_->vertex_handle(startTop + sl));
851 vhandles.push_back(triMesh_->vertex_handle(startTop + ((sl + 1) % slices_)));
853 triMesh_->add_face(vhandles);
856 triMesh_->delete_vertex(bottom);
860 triMesh_->garbage_collection();
862 triMesh_->update_normals();
865 emit createBackup(newObject,
"Original Object");
880 ACG::Vec3d PrimitivesGeneratorPlugin::positionOnSphere(
int _sliceNumber,
int _stackNumber,
double _radius,
const Vector& _position)
884 double alpha = (M_PI / double(stacks_)) *
double(_stackNumber);
885 double beta = ((2.0 * M_PI) /
double(slices_)) *
double(_sliceNumber);
887 double ringRadius = sin(alpha);
888 position[0] = sin(beta) * ringRadius * _radius;
889 position[1] = cos(beta) * ringRadius * _radius;
890 position[2] = cos(alpha)* _radius;
892 return _position+position;
897 ACG::Vec2f PrimitivesGeneratorPlugin::texCoordOnSphere(
int _sliceNumber,
int _stackNumber)
901 double alpha = (M_PI / double(stacks_)) *
double(_stackNumber);
902 texCoord[0] = double(_sliceNumber) / double(slices_);
903 texCoord[1] = 0.5 * (cos(alpha) + 1.0);
911 int PrimitivesGeneratorPlugin::addSphere(
const Vector& _position,
const double _radius)
913 int newObject = addTriMesh();
917 emit log(
LOGERR,
"Unable to create new Object");
921 object->setName(
"Sphere " + QString::number(newObject) );
923 triMesh_ =
object->mesh();
927 triMesh_->request_vertex_texcoords2D();
929 TriMesh::VertexHandle vh;
931 vh = triMesh_->add_vertex(positionOnSphere(0, 0, _radius,_position));
932 triMesh_->set_texcoord2D(vh, texCoordOnSphere(0, 0));
934 for (
int st = 1; st < stacks_; ++st) {
935 for (
int sl = 0; sl < slices_; ++sl) {
936 vh = triMesh_->add_vertex(positionOnSphere(sl, st, _radius,_position));
937 triMesh_->set_texcoord2D(vh, texCoordOnSphere(sl, st));
941 vh = triMesh_->add_vertex(positionOnSphere(slices_, stacks_, _radius,_position));
942 triMesh_->set_texcoord2D(vh, texCoordOnSphere(slices_, stacks_));
944 std::vector<TriMesh::VertexHandle> vhandles;
947 for (
int sl = 1; sl < slices_ + 1; ++sl) {
951 vhandles.push_back(triMesh_->vertex_handle(sl));
952 vhandles.push_back(triMesh_->vertex_handle(0));
953 vhandles.push_back(triMesh_->vertex_handle(1 * 1 + (sl % slices_)));
955 triMesh_->add_face(vhandles);
958 for (
int st = 0; st < stacks_ - 2; ++st) {
961 for (
int sl = 0; sl < slices_; ++sl) {
964 unsigned int startTop = 1 + slices_ * st;
965 unsigned int startBottom = 1 + slices_ * (st + 1);
969 vhandles.push_back(triMesh_->vertex_handle(startTop + sl));
970 vhandles.push_back(triMesh_->vertex_handle(startTop + ((sl + 1) % slices_)));
971 vhandles.push_back(triMesh_->vertex_handle(startBottom + sl));
973 triMesh_->add_face(vhandles);
977 vhandles.push_back(triMesh_->vertex_handle(startBottom + sl));
978 vhandles.push_back(triMesh_->vertex_handle(startTop + ((sl + 1) % slices_)));
979 vhandles.push_back(triMesh_->vertex_handle(startBottom + ((sl + 1) % slices_)));
981 triMesh_->add_face(vhandles);
986 const int startTop = 1 + (stacks_ - 2) * slices_;
987 const int bottomVertex = 1 + (stacks_ - 1) * slices_;
990 for (
int sl = 0; sl < slices_; ++sl) {
994 vhandles.push_back(triMesh_->vertex_handle(bottomVertex));
995 vhandles.push_back(triMesh_->vertex_handle(startTop + sl));
996 vhandles.push_back(triMesh_->vertex_handle(startTop + ((sl + 1) % slices_)));
998 triMesh_->add_face(vhandles);
1001 triMesh_->update_normals();
1004 emit createBackup(newObject,
"Original Object");
1008 return object->id();
1016 int PrimitivesGeneratorPlugin::addSubdivisionSphere(
const Vector& _position,
const double _radius)
1020 int newObject = addTriMesh();
1024 emit log(
LOGERR,
"Unable to create new Object");
1027 object->setName(
"Sphere " + QString::number(newObject) );
1029 triMesh_ =
object->mesh();
1030 constructOctahedron(_position, _radius);
1033 const size_t subdivisionSteps = 4;
1035 for (
size_t i = 0 ; i < subdivisionSteps; ++i) {
1038 RPC::callFunction(
"subdivider",
"subdivide", newObject, QString(
"loop"), 1,
false);
1041 for (TriMesh::VertexIter v_it = triMesh_->vertices_begin(); v_it != triMesh_->vertices_end(); ++v_it) {
1044 p = _radius * p.
normalize() + _position;
1045 triMesh_->set_point(*v_it, p);
1050 triMesh_->update_normals();
1053 emit createBackup(newObject,
"Original Object");
1069 int PrimitivesGeneratorPlugin::addPyramid(
const Vector& _position,
const double _length) {
1070 int newObject = addTriMesh();
1074 emit log(
LOGERR,
"Unable to create new Object");
1078 object->setName(
"Pyramid " + QString::number(newObject) );
1080 triMesh_ =
object->mesh();
1085 vhandles_.resize(5);
1087 const double halfLength = 0.5*_length;
1089 vhandles_[0] = triMesh_->add_vertex(
TriMesh::Point( halfLength, -halfLength, 0.0)+_position);
1090 vhandles_[1] = triMesh_->add_vertex(
TriMesh::Point( halfLength, halfLength, 0.0)+_position);
1091 vhandles_[2] = triMesh_->add_vertex(
TriMesh::Point(-halfLength, halfLength, 0.0)+_position);
1092 vhandles_[3] = triMesh_->add_vertex(
TriMesh::Point(-halfLength, -halfLength, 0.0)+_position);
1094 vhandles_[4] = triMesh_->add_vertex(
TriMesh::Point(0.0, 0.0, sqrt(2.0)*halfLength));
1105 triMesh_->update_normals();
1108 emit createBackup(newObject,
"Original Object");
1118 void PrimitivesGeneratorPlugin::add_face(
int _vh1 ,
int _vh2,
int _vh3) {
1120 static_cast<TriMesh::VertexHandle>(_vh1),
1121 static_cast<TriMesh::VertexHandle>(_vh2),
1122 static_cast<TriMesh::VertexHandle>(_vh3)
1126 void PrimitivesGeneratorPlugin::add_face(
int _vh1,
int _vh2,
int _vh3,
int _vh4)
1128 polyMesh_->add_face(
1129 static_cast<PolyMesh::VertexHandle>(_vh1),
1130 static_cast<PolyMesh::VertexHandle>(_vh2),
1131 static_cast<PolyMesh::VertexHandle>(_vh3),
1132 static_cast<PolyMesh::VertexHandle>(_vh4)
1136 void PrimitivesGeneratorPlugin::add_face(
int _vh1 ,
int _vh2,
int _vh3,
int _vh4 ,
int _vh5 ) {
1137 std::vector<PolyMesh::VertexHandle> vhandles;
1139 vhandles.push_back(vphandles_[_vh1]);
1140 vhandles.push_back(vphandles_[_vh2]);
1141 vhandles.push_back(vphandles_[_vh3]);
1142 vhandles.push_back(vphandles_[_vh4]);
1143 vhandles.push_back(vphandles_[_vh5]);
1145 polyMesh_->add_face(vhandles);
1148 int PrimitivesGeneratorPlugin::addIcosahedron(
const Vector& _position,
const double _length) {
1149 int newObject = addTriMesh();
1153 emit log(
LOGERR,
"Unable to create new Object");
1157 object->setName(
"Icosahedron " + QString::number(newObject) );
1159 triMesh_ =
object->mesh();
1164 vhandles_.resize(12);
1166 const double phi = 0.5 * (1.0 + sqrt(5.0));
1168 const double norm = 1.0;
1169 const double halfLength = 0.5*_length;
1171 vhandles_[0 ] = triMesh_->add_vertex(norm *
TriMesh::Point( 0.0 , -halfLength , -phi )+_position);
1172 vhandles_[1 ] = triMesh_->add_vertex(norm *
TriMesh::Point( 0.0 , halfLength , -phi )+_position);
1173 vhandles_[2 ] = triMesh_->add_vertex(norm *
TriMesh::Point( 0.0 , halfLength , phi )+_position);
1174 vhandles_[3 ] = triMesh_->add_vertex(norm *
TriMesh::Point( 0.0 , -halfLength , phi )+_position);
1176 vhandles_[4 ] = triMesh_->add_vertex(norm *
TriMesh::Point( -halfLength , -phi , 0.0 )+_position);
1177 vhandles_[5 ] = triMesh_->add_vertex(norm *
TriMesh::Point( halfLength , -phi , 0.0 )+_position);
1178 vhandles_[6 ] = triMesh_->add_vertex(norm *
TriMesh::Point( halfLength , phi , 0.0 )+_position);
1179 vhandles_[7 ] = triMesh_->add_vertex(norm *
TriMesh::Point( -halfLength , phi , 0.0 )+_position);
1181 vhandles_[8 ] = triMesh_->add_vertex(norm *
TriMesh::Point( -phi , 0.0 , -halfLength )+_position);
1182 vhandles_[9 ] = triMesh_->add_vertex(norm *
TriMesh::Point( -phi , 0.0 , halfLength )+_position);
1183 vhandles_[10] = triMesh_->add_vertex(norm *
TriMesh::Point( phi , 0.0 , halfLength )+_position);
1184 vhandles_[11] = triMesh_->add_vertex(norm *
TriMesh::Point( phi , 0.0 , -halfLength )+_position);
1218 triMesh_->update_normals();
1221 emit createBackup(newObject,
"Original Object");
1231 void PrimitivesGeneratorPlugin::constructOctahedron(
const Vector& _position,
const double _length)
1236 vhandles_.resize(6);
1238 const double sqrtLength = sqrt(_length);
1240 vhandles_[0 ] = triMesh_->add_vertex(
TriMesh::Point(-sqrtLength, 0.0, 0.0)+_position);
1241 vhandles_[1 ] = triMesh_->add_vertex(
TriMesh::Point( 0.0, -sqrtLength, 0.0)+_position);
1242 vhandles_[2 ] = triMesh_->add_vertex(
TriMesh::Point( sqrtLength, 0.0, 0.0)+_position);
1243 vhandles_[3 ] = triMesh_->add_vertex(
TriMesh::Point( 0.0, sqrtLength, 0.0)+_position);
1245 vhandles_[4 ] = triMesh_->add_vertex(
TriMesh::Point( 0.0, 0.0, sqrtLength)+_position);
1246 vhandles_[5 ] = triMesh_->add_vertex(
TriMesh::Point( 0.0, 0.0, -sqrtLength)+_position);
1262 triMesh_->update_normals();
1265 int PrimitivesGeneratorPlugin::addOctahedron(
const Vector& _position,
const double _length) {
1266 int newObject = addTriMesh();
1270 emit log(
LOGERR,
"Unable to create new Object");
1274 object->setName(
"Octahedron " + QString::number(newObject) );
1276 triMesh_ =
object->mesh();
1278 constructOctahedron(_position, _length);
1281 emit createBackup(newObject,
"Original Object");
1291 int PrimitivesGeneratorPlugin::addDodecahedron(
const Vector& _position,
const double _length) {
1292 int newObject = addPolyMesh();
1296 emit log(
LOGERR,
"Unable to create new Object");
1300 object->setName(
"Dodecahedron " + QString::number(newObject) );
1302 polyMesh_ =
object->mesh();
1307 vphandles_.resize(20);
1309 const double phi = (1.0 + sqrt(5.0)) / 2.0;
1310 const double halfLength = 0.5*_length;
1313 vphandles_[0 ] = polyMesh_->add_vertex(
TriMesh::Point( halfLength , halfLength , halfLength )+_position);
1314 vphandles_[1 ] = polyMesh_->add_vertex(
TriMesh::Point( halfLength , halfLength ,-halfLength )+_position);
1315 vphandles_[2 ] = polyMesh_->add_vertex(
TriMesh::Point( halfLength , -halfLength , halfLength )+_position);
1316 vphandles_[3 ] = polyMesh_->add_vertex(
TriMesh::Point( halfLength , -halfLength ,-halfLength )+_position);
1317 vphandles_[4 ] = polyMesh_->add_vertex(
TriMesh::Point( -halfLength , halfLength , halfLength )+_position);
1318 vphandles_[5 ] = polyMesh_->add_vertex(
TriMesh::Point( -halfLength , halfLength ,-halfLength )+_position);
1319 vphandles_[6 ] = polyMesh_->add_vertex(
TriMesh::Point( -halfLength , -halfLength , halfLength )+_position);
1320 vphandles_[7 ] = polyMesh_->add_vertex(
TriMesh::Point( -halfLength , -halfLength ,-halfLength )+_position);
1322 vphandles_[8 ] = polyMesh_->add_vertex(
TriMesh::Point( 0.0 , halfLength / phi , phi )+_position);
1323 vphandles_[9 ] = polyMesh_->add_vertex(
TriMesh::Point( 0.0 , halfLength / phi , -phi )+_position);
1324 vphandles_[10] = polyMesh_->add_vertex(
TriMesh::Point( 0.0 , -halfLength / phi , phi )+_position);
1325 vphandles_[11] = polyMesh_->add_vertex(
TriMesh::Point( 0.0 , -halfLength / phi , -phi )+_position);
1327 vphandles_[12] = polyMesh_->add_vertex(
TriMesh::Point( halfLength / phi , phi, 0.0)+_position);
1328 vphandles_[13] = polyMesh_->add_vertex(
TriMesh::Point( halfLength / phi , -phi, 0.0)+_position);
1329 vphandles_[14] = polyMesh_->add_vertex(
TriMesh::Point( -halfLength / phi , phi, 0.0)+_position);
1330 vphandles_[15] = polyMesh_->add_vertex(
TriMesh::Point( -halfLength / phi , -phi, 0.0)+_position);
1332 vphandles_[16] = polyMesh_->add_vertex(
TriMesh::Point( phi , 0.0 , halfLength / phi)+_position);
1333 vphandles_[17] = polyMesh_->add_vertex(
TriMesh::Point( phi , 0.0 ,-halfLength / phi)+_position);
1334 vphandles_[18] = polyMesh_->add_vertex(
TriMesh::Point( -phi , 0.0 , halfLength / phi)+_position);
1335 vphandles_[19] = polyMesh_->add_vertex(
TriMesh::Point( -phi , 0.0 ,-halfLength / phi)+_position);
1338 add_face(14, 5,19,18, 4);
1339 add_face( 5, 9,11, 7,19);
1340 add_face( 6,15,13, 2,10);
1341 add_face(12, 0,16,17, 1);
1343 add_face( 0, 8,10, 2,16);
1344 add_face(16, 2,13, 3,17);
1345 add_face( 3,13,15, 7,11);
1346 add_face( 7,15, 6,18,19);
1348 add_face( 4,18, 6,10, 8);
1349 add_face( 4, 8, 0,12,14);
1350 add_face(14,12, 1, 9, 5);
1351 add_face( 9, 1,17, 3,11);
1353 polyMesh_->update_normals();
1356 emit createBackup(newObject,
"Original Object");
1366 #ifdef ENABLE_BSPLINECURVE_SUPPORT 1367 int PrimitivesGeneratorPlugin::addRandomBSplineCurve(
const Vector& _position,
int nDiv)
1382 curve->autocompute_knotvector(
true);
1383 for (
int i = 0; i < nDiv; ++i) {
1384 double x = _position[0] + i - nDiv / 2.0;
1386 double r = (2.0 * std::rand()) / RAND_MAX - 1.0;
1387 BSplineCurve::Point cp(x, _position[1] + r, _position[2]);
1392 emit createBackup(
id,
"Original Object");
1400 #ifdef ENABLE_BSPLINESURFACE_SUPPORT 1401 int PrimitivesGeneratorPlugin::addRandomBSplineSurface(
const Vector& _position,
int nDiv)
1415 typedef BSplineSurface::Point Point;
1416 std::vector<Point> cp(nDiv);
1418 for (
int i = 0; i < nDiv; ++i) {
1419 double x = _position[0] + i - nDiv / 2.0;
1420 for (
int j = 0; j < nDiv; ++j) {
1421 double y = _position[1] + j - nDiv / 2.0;
1422 cp[j] = Point(x, y, _position[2] + (2.0 * std::rand()) / RAND_MAX - 1);
1429 emit createBackup(
id,
"Original Object");
a class which provides an link generator for WhatsThisMessages linking to the user doc If you have an...
void initializePlugin()
BaseInterface.
#define DATA_POLYHEDRAL_MESH
#define DATA_TRIANGLE_MESH
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
Type for a Meshobject containing a poly mesh.
void add_control_point(const Point &_cp)
add a control point
QScriptValue callFunction(QString _plugin, QString _functionName, std::vector< QScriptValue > _parameters)
Call a function provided by a plugin getting multiple parameters.
Kernel::Point Point
Coordinate type.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
#define DATA_HEXAHEDRAL_MESH
void createKnots()
Creates interpolating knotvectors 0...0, 1, 2, ..., n...n.
void add_vector_m(const std::vector< Point > &_control_polygon)
Adds a control point n-vector.
ACG::Vec3d Vector
Standard Type for 3d Vector used for scripting.
#define DATA_BSPLINE_SURFACE
const DrawMode & getDrawMode(const std::string &_name)
Get a custom DrawMode.
#define DATA_BSPLINE_CURVE
Type for a MeshObject containing a triangle mesh.
SmartVertexHandle add_vertex(const Point &_p)
MeshT * mesh()
return a pointer to the 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
auto normalize() -> decltype(*this/=std::declval< VectorT< S, DIM >>().norm())
VectorT< Scalar, 3 > perpendicular(const VectorT< Scalar, 3 > &v)
find a vector that's perpendicular to _v
void viewAll(int _viewer)
View the whole scene.
void setName(QString _name)
Set the name of the Object.