Commit 6e2ec0b9 authored by Janis Born's avatar Janis Born

add a "Cube (Poly Mesh)" option to Plugin-PrimitivesGenerator

parent f619bfe2
......@@ -84,6 +84,11 @@ PrimitivesGeneratorPlugin::~PrimitivesGeneratorPlugin()
void PrimitivesGeneratorPlugin::initializePlugin()
{
emit setSlotDescription("addCube(Vector,double)",
tr("Generates a poly mesh of cube (ObjectId is returned)"),
QString("Position,Length").split(","),
QString("Center position,Length of each edge").split(","));
emit setSlotDescription("addTetrahedron(Vector,double)",
tr("Generates a tetrahedron (ObjectId is returned)"),
QString("Position,Length").split(","),
......@@ -163,12 +168,15 @@ void PrimitivesGeneratorPlugin::pluginsInitialized() {
emit getMenubarMenu(tr("&Primitives"), primitivesMenu_, true );
WhatsThisGenerator whatsThisGen("PrimitivesGenerator");
QAction* action;
action = primitivesMenu_->addAction("Cube (Triangle Mesh)" ,this,SLOT(addTriangulatedCube()));
action = primitivesMenu_->addAction("Cube (Poly Mesh)" ,this,SLOT(addCube()));
action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"primitive_cube.png"));
whatsThisGen.setWhatsThis(action,tr("Create a Cube."),"Cube");
WhatsThisGenerator whatsThisGen("PrimitivesGenerator");
action = primitivesMenu_->addAction("Cube (Triangle Mesh)" ,this,SLOT(addTriangulatedCube()));
action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"primitive_cube.png"));
whatsThisGen.setWhatsThis(action,tr("Create a Cube."),"Cube");
action = primitivesMenu_->addAction("Dodecahedron" ,this,SLOT(addDodecahedron()));
......@@ -319,8 +327,6 @@ int PrimitivesGeneratorPlugin::addTetrahedron(const Vector& _position, const dou
}
int PrimitivesGeneratorPlugin::addTriangulatedCube(const Vector& _position,const double _length) {
int newObject = addTriMesh();
TriMeshObject* object;
......@@ -378,6 +384,61 @@ int PrimitivesGeneratorPlugin::addTriangulatedCube(const Vector& _position,const
return -1;
}
int PrimitivesGeneratorPlugin::addCube(const Vector& _position,const double _length) {
int newObject = addPolyMesh();
PolyMeshObject* object;
if ( !PluginFunctions::getObject(newObject,object) ) {
emit log(LOGERR,"Unable to create new Object");
return -1;
} else {
object->setName( "Cube " + QString::number(newObject) );
polyMesh_ = object->mesh();
polyMesh_->clear();
// Add 8 vertices
vhandles_.resize(8);
const double halfSize = 0.5*_length;
// 6------5
// /| /|
// 2------1 |
// | | | |
// | 7----|-4
// |/ |/
// 3------0
vhandles_[0] = polyMesh_->add_vertex(PolyMesh::Point( halfSize, -halfSize, halfSize)+_position);
vhandles_[1] = polyMesh_->add_vertex(PolyMesh::Point( halfSize, halfSize, halfSize)+_position);
vhandles_[2] = polyMesh_->add_vertex(PolyMesh::Point(-halfSize, halfSize, halfSize)+_position);
vhandles_[3] = polyMesh_->add_vertex(PolyMesh::Point(-halfSize, -halfSize, halfSize)+_position);
vhandles_[4] = polyMesh_->add_vertex(PolyMesh::Point( halfSize, -halfSize,-halfSize)+_position);
vhandles_[5] = polyMesh_->add_vertex(PolyMesh::Point( halfSize, halfSize,-halfSize)+_position);
vhandles_[6] = polyMesh_->add_vertex(PolyMesh::Point(-halfSize, halfSize,-halfSize)+_position);
vhandles_[7] = polyMesh_->add_vertex(PolyMesh::Point(-halfSize, -halfSize,-halfSize)+_position);
// Add faces
add_face(0,1,2,3);
add_face(0,4,5,1);
add_face(4,7,6,5);
add_face(7,3,2,6);
add_face(1,5,6,2);
add_face(0,3,7,4);
polyMesh_->update_normals();
emit updatedObject(newObject,UPDATE_ALL);
emit createBackup(newObject, "Original Object");
PluginFunctions::viewAll();
return newObject;
}
return -1;
}
//========================================================================
// Tetrahedral cube
//========================================================================
......@@ -818,15 +879,22 @@ int PrimitivesGeneratorPlugin::addPyramid(const Vector& _position,const double _
return -1;
}
void PrimitivesGeneratorPlugin::add_face( int _vh1 , int _vh2, int _vh3 ) {
std::vector<TriMesh::VertexHandle> vhandles;
vhandles.push_back(vhandles_[_vh1]);
vhandles.push_back(vhandles_[_vh2]);
vhandles.push_back(vhandles_[_vh3]);
triMesh_->add_face(vhandles);
void PrimitivesGeneratorPlugin::add_face(int _vh1 , int _vh2, int _vh3) {
triMesh_->add_face(
static_cast<TriMesh::VertexHandle>(_vh1),
static_cast<TriMesh::VertexHandle>(_vh2),
static_cast<TriMesh::VertexHandle>(_vh3)
);
}
void PrimitivesGeneratorPlugin::add_face(int _vh1, int _vh2, int _vh3, int _vh4)
{
polyMesh_->add_face(
static_cast<PolyMesh::VertexHandle>(_vh1),
static_cast<PolyMesh::VertexHandle>(_vh2),
static_cast<PolyMesh::VertexHandle>(_vh3),
static_cast<PolyMesh::VertexHandle>(_vh4)
);
}
void PrimitivesGeneratorPlugin::add_face( int _vh1 , int _vh2, int _vh3, int _vh4 , int _vh5 ) {
......
......@@ -140,6 +140,9 @@ public slots:
int addPyramid(const Vector& _position = Vector(0.0,0.0,0.0),
const double _length = 2.0);
int addCube(const Vector& _position = Vector(0.0,0.0,0.0),
const double _length = 2.0);
int addTriangulatedCube(const Vector& _position = Vector(0.0,0.0,0.0),
const double _length = 2.0);
......@@ -180,8 +183,9 @@ private:
#ifdef ENABLE_POLYHEDRALMESH_SUPPORT
int addPolyhedralMesh();
#endif
inline void add_face(int _vh1 , int _vh2, int _vh3);
inline void add_face( int _vh1 , int _vh2, int _vh3 );
inline void add_face(int _vh1 , int _vh2, int _vh3 , int _vh4);
inline void add_face( int _vh1 , int _vh2, int _vh3, int _vh4 , int _vh5 );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment