52 #include "PrimitivesGenerator.hh"
54 #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
55 #include "TetrahedralCuboidGenerator.hh"
58 #ifdef ENABLE_BSPLINECURVE_SUPPORT
62 #ifdef ENABLE_BSPLINESURFACE_SUPPORT
66 PrimitivesGeneratorPlugin::PrimitivesGeneratorPlugin() :
76 PrimitivesGeneratorPlugin::~PrimitivesGeneratorPlugin()
79 if ( OpenFlipper::Options::gui()) {
80 delete primitivesMenu_;
87 emit setSlotDescription(
"addTetrahedron(Vector,double)",
88 tr(
"Generates a tetrahedron (ObjectId is returned)"),
89 QString(
"Position,Length").split(
","),
90 QString(
"Center position,Length of each edge").split(
","));
92 emit setSlotDescription(
"addIcosahedron(Vector,double)",
93 tr(
"Generates an icosahedron (ObjectId is returned)"),
94 QString(
"Position,Length").split(
","),
95 QString(
"Center position,Length of each edge").split(
","));
97 emit setSlotDescription(
"addPyramid(Vector,double)",
98 tr(
"Generates a pyramid (ObjectId is returned)"),
99 QString(
"Position,Length").split(
","),
100 QString(
"Center position,Length of each edge").split(
","));
102 emit setSlotDescription(
"addOctahedron(Vector,double)",
103 tr(
"Generates an octahedron (ObjectId is returned)"),
104 QString(
"Position,Length").split(
","),
105 QString(
"Center position,Length of each edge").split(
","));
107 emit setSlotDescription(
"addDodecahedron(Vector,double)",
108 tr(
"Generates a dodecahedron (ObjectId is returned)"),
109 QString(
"Position,Length").split(
","),
110 QString(
"Center position,Length of each edge").split(
","));
112 emit setSlotDescription(
"addSphere(Vector,double)",
113 tr(
"Generates a triangulated sphere with all vertical lines connected to the poles (ObjectId is returned)"),
114 QString(
"Position, Radius").split(
","),
115 QString(
"Center position,Radius").split(
","));
117 emit setSlotDescription(
"addSubdivisionSphere(Vector,double)",
118 tr(
"Generates a triangulated sphere by subdivision without poles. (ObjectId is returned)"),
119 QString(
"Position, Radius").split(
","),
120 QString(
"Center position,Radius").split(
","));
122 emit setSlotDescription(
"addTriangulatedCube(Vector,double)",
123 tr(
"Generates a triangular mesh of cube (ObjectId is returned)"),
124 QString(
"Position,Length").split(
","),
125 QString(
"Center position,Length of each edge").split(
","));
127 emit setSlotDescription(
"addTriangulatedCylinder(Vector,Vector,double,double)",
128 tr(
"Generates a triangulated cylinder (ObjectId is returned)") ,
129 QString(
"Position,Axis,Radius,Height,Top,Bottom").split(
","),
130 QString(
"Bottom center vertex position,Center axis,radius,height,add top vertex,add bottom vertex").split(
","));
132 #ifdef ENABLE_BSPLINECURVE_SUPPORT
133 emit setSlotDescription(
"addRandomBSplineCurve(Vector,int)",
134 tr(
"Generates a random B-spline curve (ObjectId is returned)"),
135 QString(
"Position,Count").split(
","),
136 QString(
"Center position,Number of control points").split(
","));
139 #ifdef ENABLE_BSPLINESURFACE_SUPPORT
140 emit setSlotDescription(
"addRandomBSplineSurface(Vector,int)",
141 tr(
"Generates a random B-spline surface (ObjectId is returned)"),
142 QString(
"Position,Count").split(
","),
143 QString(
"Center position,Number of control points").split(
","));
146 #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
147 emit setSlotDescription(
"addTetrahedralCube(Vector,double)",
148 tr(
"Generates a tetrahedral mesh of a cube (ObjectId is returned)"),
149 QString(
"Position,Length").split(
","),
150 QString(
"Center position,Length of each edge").split(
","));
152 emit setSlotDescription(
"addTetrahedralCuboid(Vector,Vector,uint,uint,uint)",
153 tr(
"Generates a tetrahedral mesh of a cuboid (ObjectId is returned)"),
154 QString(
"Position,Lengths,Count,Count,Count").split(
","),
155 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 void PrimitivesGeneratorPlugin::pluginsInitialized() {
162 if ( OpenFlipper::Options::gui()) {
164 emit getMenubarMenu(tr(
"&Primitives"), primitivesMenu_,
true );
168 action = primitivesMenu_->addAction(
"Cube (Triangle Mesh)" ,
this,SLOT(addTriangulatedCube()));
169 action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"primitive_cube.png"));
172 whatsThisGen.setWhatsThis(action,tr(
"Create a Cube."),
"Cube");
174 action = primitivesMenu_->addAction(
"Dodecahedron" ,
this,SLOT(addDodecahedron()));
175 action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"primitive_dodecahedron.png"));
176 whatsThisGen.setWhatsThis(action,tr(
"Create a Dodecahedron."),
"Dodecahedron");
178 action = primitivesMenu_->addAction(
"Icosahedron" ,
this,SLOT(addIcosahedron()));
179 action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"primitive_icosahedron.png"));
180 whatsThisGen.setWhatsThis(action,tr(
"Create a Icosahedron.",
"Icosahedron"));
182 action = primitivesMenu_->addAction(
"Octahedron" ,
this,SLOT(addOctahedron()));
183 action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"primitive_octahedron.png"));
184 whatsThisGen.setWhatsThis(action,tr(
"Create an Octahedron."),
"Octahedron");
186 action = primitivesMenu_->addAction(
"Pyramid" ,
this,SLOT(addPyramid()));
187 action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"primitive_pyramid.png"));
188 whatsThisGen.setWhatsThis(action,tr(
"Create a Pyramid."),
"Pyramid");
190 action = primitivesMenu_->addAction(
"Cylinder (Triangle Mesh)" ,
this,SLOT(addTriangulatedCylinder()));
191 action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"primitive_cylinder.png"));
193 action = primitivesMenu_->addAction(
"Sphere (Poles,Triangle Mesh)",
this,SLOT(addSphere()));
194 action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"primitive_sphere.png"));
195 whatsThisGen.setWhatsThis(action,tr(
"Create a Sphere. All vertical lines connect to poles) "),
"Sphere");
197 action = primitivesMenu_->addAction(
"Sphere (Subdivision,Triangle Mesh)",
this,SLOT(addSubdivisionSphere()));
198 action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"primitive_sphere.png"));
199 whatsThisGen.setWhatsThis(action,tr(
"Create a Sphere. No poles due to Subdivision) "),
"Sphere");
201 action = primitivesMenu_->addAction(
"Tetrahedron",
this,SLOT(addTetrahedron()));
202 action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"primitive_tetrahedron.png"));
203 whatsThisGen.setWhatsThis(action,tr(
"Create a Tetrahedron."),
"Tetrahedron");
205 #ifdef ENABLE_BSPLINECURVE_SUPPORT
206 action = primitivesMenu_->addAction(
"Random B-spline curve",
this,SLOT(addRandomBSplineCurve()));
207 action->setIcon(QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() +
"bspline_curve.png"));
208 whatsThisGen.setWhatsThis(action, tr(
"Create a random B-spline curve."),
"B-spline curve");
211 #ifdef ENABLE_BSPLINESURFACE_SUPPORT
212 action = primitivesMenu_->addAction(
"Random B-spline surface",
this,SLOT(addRandomBSplineSurface()));
213 action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"bspline_surface.png"));
214 whatsThisGen.setWhatsThis(action,tr(
"Create a random B-spline surface."),
"B-spline surface");
217 #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
218 action = primitivesMenu_->addAction(
"Cube (Tetrahedral Mesh)" ,
this,SLOT(addTetrahedralCube()));
219 action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"primitive_cube.png"));
220 whatsThisGen.setWhatsThis(action,tr(
"Create a Tetrahedral Cube."),
"Cube");
222 action = primitivesMenu_->addAction(
"Cuboid (Tetrahedral Mesh)" ,
this,SLOT(addTetrahedralCuboid()));
223 action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"primitive_cube.png"));
224 whatsThisGen.setWhatsThis(action,tr(
"Create a Tetrahedral Cuboid."),
"Cuboid");
230 int PrimitivesGeneratorPlugin::addTriMesh() {
237 emit log(
LOGERR,
"Unable to create new Object");
244 int PrimitivesGeneratorPlugin::addPolyMesh() {
251 emit log(
LOGERR,
"Unable to create new Object");
259 #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
260 int PrimitivesGeneratorPlugin::addPolyhedralMesh() {
267 emit log(
LOGERR,
"Unable to create new PolyhedralMesh object");
276 int PrimitivesGeneratorPlugin::addTetrahedron(
const Vector& _position,
const double _length) {
278 int newObject = addTriMesh();
282 emit log(
LOGERR,
"Unable to create new Object");
286 object->setName(
"Tetrahedron " + QString::number(newObject) );
288 triMesh_ =
object->mesh();
295 const double halfSize = 0.5*_length;
297 vhandles_[0] = triMesh_->add_vertex(TriMesh::Point(-halfSize, -halfSize, halfSize)+_position);
298 vhandles_[1] = triMesh_->add_vertex(TriMesh::Point( halfSize, halfSize, halfSize)+_position);
299 vhandles_[2] = triMesh_->add_vertex(TriMesh::Point(-halfSize, halfSize, -halfSize)+_position);
300 vhandles_[3] = triMesh_->add_vertex(TriMesh::Point( halfSize, -halfSize, -halfSize)+_position);
308 triMesh_->update_normals();
311 emit createBackup(newObject,
"Original Object");
321 int PrimitivesGeneratorPlugin::addTriangulatedCube(
const Vector& _position,
const double _length) {
324 int newObject = addTriMesh();
328 emit log(
LOGERR,
"Unable to create new Object");
332 object->setName(
"Cube " + QString::number(newObject) );
334 triMesh_ =
object->mesh();
341 const double halfSize = 0.5*_length;
343 vhandles_[0] = triMesh_->add_vertex(TriMesh::Point( halfSize, -halfSize, halfSize)+_position);
344 vhandles_[1] = triMesh_->add_vertex(TriMesh::Point( halfSize, halfSize, halfSize)+_position);
345 vhandles_[2] = triMesh_->add_vertex(TriMesh::Point(-halfSize, halfSize, halfSize)+_position);
346 vhandles_[3] = triMesh_->add_vertex(TriMesh::Point(-halfSize, -halfSize, halfSize)+_position);
347 vhandles_[4] = triMesh_->add_vertex(TriMesh::Point( halfSize, -halfSize,-halfSize)+_position);
348 vhandles_[5] = triMesh_->add_vertex(TriMesh::Point( halfSize, halfSize,-halfSize)+_position);
349 vhandles_[6] = triMesh_->add_vertex(TriMesh::Point(-halfSize, halfSize,-halfSize)+_position);
350 vhandles_[7] = triMesh_->add_vertex(TriMesh::Point(-halfSize, -halfSize,-halfSize)+_position);
368 triMesh_->update_normals();
371 emit createBackup(newObject,
"Original Object");
385 #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
387 int PrimitivesGeneratorPlugin::addTetrahedralCube(
const Vector& _position,
const double _length)
389 return addTetrahedralCuboid(_position,
Vector(_length, _length, _length), 1, 1, 1);
398 #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
400 int PrimitivesGeneratorPlugin::addTetrahedralCuboid(
const Vector& _position,
401 const Vector& _length,
const unsigned int n_x,
const unsigned int n_y,
const unsigned int n_z)
404 int object_id = addPolyhedralMesh();
411 object->
setName(
"Cuboid " + QString::number(object_id));
416 emit createBackup(object_id,
"Original Object");
431 ACG::Vec3d PrimitivesGeneratorPlugin::positionOnCylinder(
const int _sliceNumber,
432 const int _stackNumber,
435 const double _radius,
436 const double _height)
443 double beta = ((2.0 * M_PI) /
double(slices_)) *
double(_sliceNumber);
445 if ( _sliceNumber == 0 && _stackNumber == 0) {
448 position[2] = _height;
449 }
else if ( _sliceNumber == slices_ && _stackNumber == stacks_ ) {
454 position[0] = sin(beta) * _radius;
455 position[1] = cos(beta) * _radius;
456 position[2] = _height * double(stacks_ - _stackNumber -1 ) / double(stacks_-2);
459 position = _position + position[0] * right + position[1] * left + position[2] * _axis ;
464 int PrimitivesGeneratorPlugin::addTriangulatedCylinder(
const Vector& _position,
const Vector& _axis,
const double _radius,
const double _height,
const bool _top,
const bool _bottom ) {
467 int newObject = addTriMesh();
471 emit log(
LOGERR,
"Unable to create new Object");
475 object->setName(
"Cylinder " + QString::number(newObject) );
477 triMesh_ =
object->mesh();
483 TriMesh::VertexHandle vh;
484 TriMesh::VertexHandle top = triMesh_->add_vertex(positionOnCylinder(0, 0,_position,_axis,_radius,_height));
487 for (
int st = 1; st < stacks_; ++st) {
488 for (
int sl = 0; sl < slices_; ++sl) {
489 vh = triMesh_->add_vertex(positionOnCylinder(sl, st,_position,_axis,_radius,_height));
494 TriMesh::VertexHandle bottom = triMesh_->add_vertex(positionOnCylinder(slices_, stacks_,_position,_axis,_radius,_height));
497 std::vector<TriMesh::VertexHandle> vhandles;
501 for (
int sl = 1; sl < slices_ + 1; ++sl) {
505 vhandles.push_back(triMesh_->vertex_handle(sl));
506 vhandles.push_back(triMesh_->vertex_handle(0));
507 vhandles.push_back(triMesh_->vertex_handle(1 * 1 + (sl % slices_)));
509 triMesh_->add_face(vhandles);
512 triMesh_->delete_vertex(top);
515 for (
int st = 0; st < stacks_ - 2; ++st) {
518 for (
int sl = 0; sl < slices_; ++sl) {
521 unsigned int startTop = 1 + slices_ * st;
522 unsigned int startBottom = 1 + slices_ * (st + 1);
526 vhandles.push_back(triMesh_->vertex_handle(startTop + sl));
527 vhandles.push_back(triMesh_->vertex_handle(startTop + ((sl + 1) % slices_)));
528 vhandles.push_back(triMesh_->vertex_handle(startBottom + sl));
530 triMesh_->add_face(vhandles);
534 vhandles.push_back(triMesh_->vertex_handle(startBottom + sl));
535 vhandles.push_back(triMesh_->vertex_handle(startTop + ((sl + 1) % slices_)));
536 vhandles.push_back(triMesh_->vertex_handle(startBottom + ((sl + 1) % slices_)));
538 triMesh_->add_face(vhandles);
543 const int startTop = 1 + (stacks_ - 2) * slices_;
544 const int bottomVertex = 1 + (stacks_ - 1) * slices_;
548 for (
int sl = 0; sl < slices_; ++sl) {
552 vhandles.push_back(triMesh_->vertex_handle(bottomVertex));
553 vhandles.push_back(triMesh_->vertex_handle(startTop + sl));
554 vhandles.push_back(triMesh_->vertex_handle(startTop + ((sl + 1) % slices_)));
556 triMesh_->add_face(vhandles);
559 triMesh_->delete_vertex(bottom);
563 triMesh_->garbage_collection();
565 triMesh_->update_normals();
568 emit createBackup(newObject,
"Original Object");
583 ACG::Vec3d PrimitivesGeneratorPlugin::positionOnSphere(
int _sliceNumber,
int _stackNumber,
double _radius,
const Vector& _position)
587 double alpha = (M_PI / double(stacks_)) *
double(_stackNumber);
588 double beta = ((2.0 * M_PI) /
double(slices_)) *
double(_sliceNumber);
590 double ringRadius = sin(alpha);
591 position[0] = sin(beta) * ringRadius * _radius;
592 position[1] = cos(beta) * ringRadius * _radius;
593 position[2] = cos(alpha)* _radius;
595 return _position+position;
600 ACG::Vec2f PrimitivesGeneratorPlugin::texCoordOnSphere(
int _sliceNumber,
int _stackNumber)
604 double alpha = (M_PI / double(stacks_)) *
double(_stackNumber);
605 texCoord[0] = double(_sliceNumber) / double(slices_);
606 texCoord[1] = 0.5 * (cos(alpha) + 1.0);
614 int PrimitivesGeneratorPlugin::addSphere(
const Vector& _position,
const double _radius)
616 int newObject = addTriMesh();
620 emit log(
LOGERR,
"Unable to create new Object");
624 object->setName(
"Sphere " + QString::number(newObject) );
626 triMesh_ =
object->mesh();
630 triMesh_->request_vertex_texcoords2D();
632 TriMesh::VertexHandle vh;
634 vh = triMesh_->add_vertex(positionOnSphere(0, 0, _radius,_position));
635 triMesh_->set_texcoord2D(vh, texCoordOnSphere(0, 0));
637 for (
int st = 1; st < stacks_; ++st) {
638 for (
int sl = 0; sl < slices_; ++sl) {
639 vh = triMesh_->add_vertex(positionOnSphere(sl, st, _radius,_position));
640 triMesh_->set_texcoord2D(vh, texCoordOnSphere(sl, st));
644 vh = triMesh_->add_vertex(positionOnSphere(slices_, stacks_, _radius,_position));
645 triMesh_->set_texcoord2D(vh, texCoordOnSphere(slices_, stacks_));
647 std::vector<TriMesh::VertexHandle> vhandles;
650 for (
int sl = 1; sl < slices_ + 1; ++sl) {
654 vhandles.push_back(triMesh_->vertex_handle(sl));
655 vhandles.push_back(triMesh_->vertex_handle(0));
656 vhandles.push_back(triMesh_->vertex_handle(1 * 1 + (sl % slices_)));
658 triMesh_->add_face(vhandles);
661 for (
int st = 0; st < stacks_ - 2; ++st) {
664 for (
int sl = 0; sl < slices_; ++sl) {
667 unsigned int startTop = 1 + slices_ * st;
668 unsigned int startBottom = 1 + slices_ * (st + 1);
672 vhandles.push_back(triMesh_->vertex_handle(startTop + sl));
673 vhandles.push_back(triMesh_->vertex_handle(startTop + ((sl + 1) % slices_)));
674 vhandles.push_back(triMesh_->vertex_handle(startBottom + sl));
676 triMesh_->add_face(vhandles);
680 vhandles.push_back(triMesh_->vertex_handle(startBottom + sl));
681 vhandles.push_back(triMesh_->vertex_handle(startTop + ((sl + 1) % slices_)));
682 vhandles.push_back(triMesh_->vertex_handle(startBottom + ((sl + 1) % slices_)));
684 triMesh_->add_face(vhandles);
689 const int startTop = 1 + (stacks_ - 2) * slices_;
690 const int bottomVertex = 1 + (stacks_ - 1) * slices_;
693 for (
int sl = 0; sl < slices_; ++sl) {
697 vhandles.push_back(triMesh_->vertex_handle(bottomVertex));
698 vhandles.push_back(triMesh_->vertex_handle(startTop + sl));
699 vhandles.push_back(triMesh_->vertex_handle(startTop + ((sl + 1) % slices_)));
701 triMesh_->add_face(vhandles);
704 triMesh_->update_normals();
707 emit createBackup(newObject,
"Original Object");
719 int PrimitivesGeneratorPlugin::addSubdivisionSphere(
const Vector& _position,
const double _radius)
723 int newObject = addTriMesh();
727 emit log(
LOGERR,
"Unable to create new Object");
730 object->setName(
"Sphere " + QString::number(newObject) );
732 triMesh_ =
object->mesh();
733 constructOctahedron(_position, _radius);
736 const size_t subdivisionSteps = 4;
738 for (
size_t i = 0 ; i < subdivisionSteps; ++i) {
741 RPC::callFunction(
"subdivider",
"subdivide", newObject, QString(
"loop"), 1,
false);
744 for (TriMesh::VertexIter v_it = triMesh_->vertices_begin(); v_it != triMesh_->vertices_end(); ++v_it) {
745 TriMesh::Point p = triMesh_->point(*v_it);
747 p = _radius * p.normalize() + _position;
748 triMesh_->set_point(*v_it, p);
753 triMesh_->update_normals();
756 emit createBackup(newObject,
"Original Object");
772 int PrimitivesGeneratorPlugin::addPyramid(
const Vector& _position,
const double _length) {
773 int newObject = addTriMesh();
777 emit log(
LOGERR,
"Unable to create new Object");
781 object->setName(
"Pyramid " + QString::number(newObject) );
783 triMesh_ =
object->mesh();
790 const double halfLength = 0.5*_length;
792 vhandles_[0] = triMesh_->add_vertex(TriMesh::Point( halfLength, -halfLength, 0.0)+_position);
793 vhandles_[1] = triMesh_->add_vertex(TriMesh::Point( halfLength, halfLength, 0.0)+_position);
794 vhandles_[2] = triMesh_->add_vertex(TriMesh::Point(-halfLength, halfLength, 0.0)+_position);
795 vhandles_[3] = triMesh_->add_vertex(TriMesh::Point(-halfLength, -halfLength, 0.0)+_position);
797 vhandles_[4] = triMesh_->add_vertex(TriMesh::Point(0.0, 0.0, sqrt(2.0)*halfLength));
808 triMesh_->update_normals();
811 emit createBackup(newObject,
"Original Object");
821 void PrimitivesGeneratorPlugin::add_face(
int _vh1 ,
int _vh2,
int _vh3 ) {
822 std::vector<TriMesh::VertexHandle> vhandles;
824 vhandles.push_back(vhandles_[_vh1]);
825 vhandles.push_back(vhandles_[_vh2]);
826 vhandles.push_back(vhandles_[_vh3]);
828 triMesh_->add_face(vhandles);
832 void PrimitivesGeneratorPlugin::add_face(
int _vh1 ,
int _vh2,
int _vh3,
int _vh4 ,
int _vh5 ) {
833 std::vector<PolyMesh::VertexHandle> vhandles;
835 vhandles.push_back(vphandles_[_vh1]);
836 vhandles.push_back(vphandles_[_vh2]);
837 vhandles.push_back(vphandles_[_vh3]);
838 vhandles.push_back(vphandles_[_vh4]);
839 vhandles.push_back(vphandles_[_vh5]);
841 polyMesh_->add_face(vhandles);
844 int PrimitivesGeneratorPlugin::addIcosahedron(
const Vector& _position,
const double _length) {
845 int newObject = addTriMesh();
849 emit log(
LOGERR,
"Unable to create new Object");
853 object->setName(
"Icosahedron " + QString::number(newObject) );
855 triMesh_ =
object->mesh();
860 vhandles_.resize(12);
862 const double phi = 0.5 * (1.0 + sqrt(5.0));
864 const double norm = 1.0;
865 const double halfLength = 0.5*_length;
867 vhandles_[0 ] = triMesh_->add_vertex(norm * TriMesh::Point( 0.0 , -halfLength , -phi )+_position);
868 vhandles_[1 ] = triMesh_->add_vertex(norm * TriMesh::Point( 0.0 , halfLength , -phi )+_position);
869 vhandles_[2 ] = triMesh_->add_vertex(norm * TriMesh::Point( 0.0 , halfLength , phi )+_position);
870 vhandles_[3 ] = triMesh_->add_vertex(norm * TriMesh::Point( 0.0 , -halfLength , phi )+_position);
872 vhandles_[4 ] = triMesh_->add_vertex(norm * TriMesh::Point( -halfLength , -phi , 0.0 )+_position);
873 vhandles_[5 ] = triMesh_->add_vertex(norm * TriMesh::Point( halfLength , -phi , 0.0 )+_position);
874 vhandles_[6 ] = triMesh_->add_vertex(norm * TriMesh::Point( halfLength , phi , 0.0 )+_position);
875 vhandles_[7 ] = triMesh_->add_vertex(norm * TriMesh::Point( -halfLength , phi , 0.0 )+_position);
877 vhandles_[8 ] = triMesh_->add_vertex(norm * TriMesh::Point( -phi , 0.0 , -halfLength )+_position);
878 vhandles_[9 ] = triMesh_->add_vertex(norm * TriMesh::Point( -phi , 0.0 , halfLength )+_position);
879 vhandles_[10] = triMesh_->add_vertex(norm * TriMesh::Point( phi , 0.0 , halfLength )+_position);
880 vhandles_[11] = triMesh_->add_vertex(norm * TriMesh::Point( phi , 0.0 , -halfLength )+_position);
914 triMesh_->update_normals();
917 emit createBackup(newObject,
"Original Object");
927 void PrimitivesGeneratorPlugin::constructOctahedron(
const Vector& _position,
const double _length)
934 const double sqrtLength = sqrt(_length);
936 vhandles_[0 ] = triMesh_->add_vertex(TriMesh::Point(-sqrtLength, 0.0, 0.0)+_position);
937 vhandles_[1 ] = triMesh_->add_vertex(TriMesh::Point( 0.0, -sqrtLength, 0.0)+_position);
938 vhandles_[2 ] = triMesh_->add_vertex(TriMesh::Point( sqrtLength, 0.0, 0.0)+_position);
939 vhandles_[3 ] = triMesh_->add_vertex(TriMesh::Point( 0.0, sqrtLength, 0.0)+_position);
941 vhandles_[4 ] = triMesh_->add_vertex(TriMesh::Point( 0.0, 0.0, sqrtLength)+_position);
942 vhandles_[5 ] = triMesh_->add_vertex(TriMesh::Point( 0.0, 0.0, -sqrtLength)+_position);
958 triMesh_->update_normals();
961 int PrimitivesGeneratorPlugin::addOctahedron(
const Vector& _position,
const double _length) {
962 int newObject = addTriMesh();
966 emit log(
LOGERR,
"Unable to create new Object");
970 object->setName(
"Octahedron " + QString::number(newObject) );
972 triMesh_ =
object->mesh();
974 constructOctahedron(_position, _length);
977 emit createBackup(newObject,
"Original Object");
987 int PrimitivesGeneratorPlugin::addDodecahedron(
const Vector& _position,
const double _length) {
988 int newObject = addPolyMesh();
992 emit log(
LOGERR,
"Unable to create new Object");
996 object->setName(
"Dodecahedron " + QString::number(newObject) );
998 polyMesh_ =
object->mesh();
1003 vphandles_.resize(20);
1005 const double phi = (1.0 + sqrt(5.0)) / 2.0;
1006 const double halfLength = 0.5*_length;
1009 vphandles_[0 ] = polyMesh_->add_vertex(TriMesh::Point( halfLength , halfLength , halfLength )+_position);
1010 vphandles_[1 ] = polyMesh_->add_vertex(TriMesh::Point( halfLength , halfLength ,-halfLength )+_position);
1011 vphandles_[2 ] = polyMesh_->add_vertex(TriMesh::Point( halfLength , -halfLength , halfLength )+_position);
1012 vphandles_[3 ] = polyMesh_->add_vertex(TriMesh::Point( halfLength , -halfLength ,-halfLength )+_position);
1013 vphandles_[4 ] = polyMesh_->add_vertex(TriMesh::Point( -halfLength , halfLength , halfLength )+_position);
1014 vphandles_[5 ] = polyMesh_->add_vertex(TriMesh::Point( -halfLength , halfLength ,-halfLength )+_position);
1015 vphandles_[6 ] = polyMesh_->add_vertex(TriMesh::Point( -halfLength , -halfLength , halfLength )+_position);
1016 vphandles_[7 ] = polyMesh_->add_vertex(TriMesh::Point( -halfLength , -halfLength ,-halfLength )+_position);
1018 vphandles_[8 ] = polyMesh_->add_vertex(TriMesh::Point( 0.0 , halfLength / phi , phi )+_position);
1019 vphandles_[9 ] = polyMesh_->add_vertex(TriMesh::Point( 0.0 , halfLength / phi , -phi )+_position);
1020 vphandles_[10] = polyMesh_->add_vertex(TriMesh::Point( 0.0 , -halfLength / phi , phi )+_position);
1021 vphandles_[11] = polyMesh_->add_vertex(TriMesh::Point( 0.0 , -halfLength / phi , -phi )+_position);
1023 vphandles_[12] = polyMesh_->add_vertex(TriMesh::Point( halfLength / phi , phi, 0.0)+_position);
1024 vphandles_[13] = polyMesh_->add_vertex(TriMesh::Point( halfLength / phi , -phi, 0.0)+_position);
1025 vphandles_[14] = polyMesh_->add_vertex(TriMesh::Point( -halfLength / phi , phi, 0.0)+_position);
1026 vphandles_[15] = polyMesh_->add_vertex(TriMesh::Point( -halfLength / phi , -phi, 0.0)+_position);
1028 vphandles_[16] = polyMesh_->add_vertex(TriMesh::Point( phi , 0.0 , halfLength / phi)+_position);
1029 vphandles_[17] = polyMesh_->add_vertex(TriMesh::Point( phi , 0.0 ,-halfLength / phi)+_position);
1030 vphandles_[18] = polyMesh_->add_vertex(TriMesh::Point( -phi , 0.0 , halfLength / phi)+_position);
1031 vphandles_[19] = polyMesh_->add_vertex(TriMesh::Point( -phi , 0.0 ,-halfLength / phi)+_position);
1034 add_face(14, 5,19,18, 4);
1035 add_face( 5, 9,11, 7,19);
1036 add_face( 6,15,13, 2,10);
1037 add_face(12, 0,16,17, 1);
1039 add_face( 0, 8,10, 2,16);
1040 add_face(16, 2,13, 3,17);
1041 add_face( 3,13,15, 7,11);
1042 add_face( 7,15, 6,18,19);
1044 add_face( 4,18, 6,10, 8);
1045 add_face( 4, 8, 0,12,14);
1046 add_face(14,12, 1, 9, 5);
1047 add_face( 9, 1,17, 3,11);
1049 polyMesh_->update_normals();
1052 emit createBackup(newObject,
"Original Object");
1062 #ifdef ENABLE_BSPLINECURVE_SUPPORT
1063 int PrimitivesGeneratorPlugin::addRandomBSplineCurve(
const Vector& _position,
int nDiv)
1078 curve->autocompute_knotvector(
true);
1079 for (
int i = 0; i < nDiv; ++i) {
1080 double x = _position[0] + i - nDiv / 2.0;
1082 double r = (2.0 * std::rand()) / RAND_MAX - 1.0;
1083 BSplineCurve::Point cp(x, _position[1] + r, _position[2]);
1088 emit createBackup(
id,
"Original Object");
1096 #ifdef ENABLE_BSPLINESURFACE_SUPPORT
1097 int PrimitivesGeneratorPlugin::addRandomBSplineSurface(
const Vector& _position,
int nDiv)
1111 typedef BSplineSurface::Point Point;
1112 std::vector<Point> cp(nDiv);
1114 for (
int i = 0; i < nDiv; ++i) {
1115 double x = _position[0] + i - nDiv / 2.0;
1116 for (
int j = 0; j < nDiv; ++j) {
1117 double y = _position[1] + j - nDiv / 2.0;
1118 cp[j] = Point(x, y, _position[2] + (2.0 * std::rand()) / RAND_MAX - 1);
1125 emit createBackup(
id,
"Original Object");
1133 #if QT_VERSION < 0x050000
VectorT< Scalar, 3 > perpendicular(const VectorT< Scalar, 3 > &v)
find a vector that's perpendicular to _v
void add_control_point(const Point &_cp)
add a control point
MeshT * mesh()
return a pointer to the mesh
Type for a Meshobject containing a poly mesh.
void add_vector_m(const std::vector< Point > &_control_polygon)
Adds a control point n-vector.
Type for a MeshObject containing a triangle mesh.
#define DATA_POLYHEDRAL_MESH
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
bool getObject(int _identifier, BSplineCurveObject *&_object)
#define DATA_BSPLINE_CURVE
void setName(QString _name)
Set the name of the Object.
const DrawMode & getDrawMode(const std::string &_name)
Get a custom DrawMode.
osg::Vec3f cross(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.
void createKnots()
Creates interpolating knotvectors 0...0, 1, 2, ..., n...n.
ACG::Vec3d Vector
Standard Type for 3d Vector used for scripting.
QScriptValue callFunction(QString _plugin, QString _functionName, std::vector< QScriptValue > _parameters)
Call a function provided by a plugin getting multiple parameters.
#define DATA_BSPLINE_SURFACE
a class which provides an link generator for WhatsThisMessages linking to the user doc If you have an...
void initializePlugin()
BaseInterface.
#define DATA_TRIANGLE_MESH
void viewAll(int _viewer)
View the whole scene.