Commit 6d3efcba authored by Martin Heistermann's avatar Martin Heistermann

New feature: create hexahedral cube

parent 6e2ec0b9
...@@ -55,6 +55,10 @@ ...@@ -55,6 +55,10 @@
#include "TetrahedralCuboidGenerator.hh" #include "TetrahedralCuboidGenerator.hh"
#endif #endif
#ifdef ENABLE_HEXAHEDRALMESH_SUPPORT
#include <ObjectTypes/HexahedralMesh/HexahedralMesh.hh>
#endif
#ifdef ENABLE_BSPLINECURVE_SUPPORT #ifdef ENABLE_BSPLINECURVE_SUPPORT
#include <ObjectTypes/BSplineCurve/BSplineCurve.hh> #include <ObjectTypes/BSplineCurve/BSplineCurve.hh>
#endif #endif
...@@ -159,6 +163,12 @@ void PrimitivesGeneratorPlugin::initializePlugin() ...@@ -159,6 +163,12 @@ void PrimitivesGeneratorPlugin::initializePlugin()
QString("Position,Lengths,Count,Count,Count").split(","), QString("Position,Lengths,Count,Count,Count").split(","),
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(",")); 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(","));
#endif #endif
#ifdef ENABLE_HEXAHEDRALMESH_SUPPORT
emit setSlotDescription("addHexahedralCube(Vector,double)",
tr("Generates a hexahedral mesh of a cube (ObjectId is returned)"),
QString("Position,Length").split(","),
QString("Center position,Length of each edge").split(","));
#endif
} }
...@@ -230,6 +240,13 @@ void PrimitivesGeneratorPlugin::pluginsInitialized() { ...@@ -230,6 +240,13 @@ void PrimitivesGeneratorPlugin::pluginsInitialized() {
action = primitivesMenu_->addAction("Cuboid (Tetrahedral Mesh)" ,this,SLOT(addTetrahedralCuboid())); action = primitivesMenu_->addAction("Cuboid (Tetrahedral Mesh)" ,this,SLOT(addTetrahedralCuboid()));
action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"primitive_cube.png")); action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"primitive_cube.png"));
whatsThisGen.setWhatsThis(action,tr("Create a Tetrahedral Cuboid."), "Cuboid"); whatsThisGen.setWhatsThis(action,tr("Create a Tetrahedral Cuboid."), "Cuboid");
#endif
#ifdef ENABLE_HEXAHEDRALMESH_SUPPORT
action = primitivesMenu_->addAction("Cube (Hexahedral Mesh)" ,this,SLOT(addHexahedralCube()));
action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"primitive_cube.png"));
whatsThisGen.setWhatsThis(action,tr("Create a Hexahedral Cube."), "Cube");
#endif #endif
} }
} }
...@@ -276,11 +293,11 @@ int PrimitivesGeneratorPlugin::addPolyhedralMesh() { ...@@ -276,11 +293,11 @@ int PrimitivesGeneratorPlugin::addPolyhedralMesh() {
return -1; return -1;
} }
return objectId; return objectId;
} }
#endif #endif
int PrimitivesGeneratorPlugin::addTetrahedron(const Vector& _position, const double _length) { int PrimitivesGeneratorPlugin::addTetrahedron(const Vector& _position, const double _length) {
int newObject = addTriMesh(); int newObject = addTriMesh();
...@@ -484,6 +501,52 @@ int PrimitivesGeneratorPlugin::addTetrahedralCuboid(const Vector& _position, ...@@ -484,6 +501,52 @@ int PrimitivesGeneratorPlugin::addTetrahedralCuboid(const Vector& _position,
#endif #endif
//========================================================================
// Hexahedral Cube & Cuboid
//========================================================================
#ifdef ENABLE_HEXAHEDRALMESH_SUPPORT
int PrimitivesGeneratorPlugin::addHexahedralCube(const Vector& _position, const double _length)
{
int object_id;
emit addEmptyObject( DATA_HEXAHEDRAL_MESH, object_id);
HexahedralMeshObject* object;
if (!PluginFunctions::getObject(object_id, object) ) {
emit log(LOGERR, "Unable to create new HexahedralMesh object");
return -1;
}
object->setName( "HexCube " + QString::number(object_id) );
auto mesh = object->mesh();
namespace OVM = OpenVolumeMesh;
std::vector<OVM::VertexHandle> vertices(8);
const double halfSize = 0.5*_length;
vertices[0] = mesh->add_vertex(Vector(-halfSize, -halfSize, halfSize)+_position);
vertices[1] = mesh->add_vertex(Vector( halfSize, -halfSize, halfSize)+_position);
vertices[2] = mesh->add_vertex(Vector( halfSize, halfSize, halfSize)+_position);
vertices[3] = mesh->add_vertex(Vector(-halfSize, halfSize, halfSize)+_position);
vertices[4] = mesh->add_vertex(Vector(-halfSize, -halfSize,-halfSize)+_position);
vertices[5] = mesh->add_vertex(Vector(-halfSize, halfSize,-halfSize)+_position);
vertices[6] = mesh->add_vertex(Vector( halfSize, halfSize,-halfSize)+_position);
vertices[7] = mesh->add_vertex(Vector( halfSize, -halfSize,-halfSize)+_position);
mesh->add_cell(vertices);
emit updatedObject(object_id, UPDATE_ALL);
emit createBackup(object_id, "Original Object");
object->setObjectDrawMode(ACG::SceneGraph::DrawModes::getDrawMode("Cells (flat shaded)"));
PluginFunctions::viewAll();
return object_id;
}
#endif
//======================================================================== //========================================================================
// Cylinder // Cylinder
//======================================================================== //========================================================================
......
...@@ -173,6 +173,10 @@ public slots: ...@@ -173,6 +173,10 @@ public slots:
const unsigned int n_y = 5, const unsigned int n_y = 5,
const unsigned int n_z = 10); const unsigned int n_z = 10);
#endif #endif
#ifdef ENABLE_HEXAHEDRALMESH_SUPPORT
int addHexahedralCube(const Vector& _position = Vector(0.0,0.0,0.0),
const double _length = 2.0);
#endif
private: private:
int addTriMesh(); int addTriMesh();
...@@ -182,6 +186,9 @@ private: ...@@ -182,6 +186,9 @@ private:
#ifdef ENABLE_POLYHEDRALMESH_SUPPORT #ifdef ENABLE_POLYHEDRALMESH_SUPPORT
int addPolyhedralMesh(); int addPolyhedralMesh();
#endif
#ifdef ENABLE_HEXAHEDRALMESH_SUPPORT
int addHexahedralMesh();
#endif #endif
inline void add_face(int _vh1 , int _vh2, int _vh3); inline void add_face(int _vh1 , int _vh2, int _vh3);
......
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