From 6d3efcbafd17d3c2f00b28042f0889680e14a158 Mon Sep 17 00:00:00 2001 From: Martin Heistermann Date: Sat, 13 Jan 2018 02:48:31 +0100 Subject: [PATCH] New feature: create hexahedral cube --- PrimitivesGenerator.cc | 65 +++++++++++++++++++++++++++++++++++++++++- PrimitivesGenerator.hh | 7 +++++ 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/PrimitivesGenerator.cc b/PrimitivesGenerator.cc index 55193a4..dad4548 100644 --- a/PrimitivesGenerator.cc +++ b/PrimitivesGenerator.cc @@ -55,6 +55,10 @@ #include "TetrahedralCuboidGenerator.hh" #endif +#ifdef ENABLE_HEXAHEDRALMESH_SUPPORT +#include +#endif + #ifdef ENABLE_BSPLINECURVE_SUPPORT #include #endif @@ -159,6 +163,12 @@ void PrimitivesGeneratorPlugin::initializePlugin() 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(",")); #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() { action = primitivesMenu_->addAction("Cuboid (Tetrahedral Mesh)" ,this,SLOT(addTetrahedralCuboid())); action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"primitive_cube.png")); 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 } } @@ -276,11 +293,11 @@ int PrimitivesGeneratorPlugin::addPolyhedralMesh() { return -1; } - return objectId; } #endif + int PrimitivesGeneratorPlugin::addTetrahedron(const Vector& _position, const double _length) { int newObject = addTriMesh(); @@ -484,6 +501,52 @@ int PrimitivesGeneratorPlugin::addTetrahedralCuboid(const Vector& _position, #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 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 //======================================================================== diff --git a/PrimitivesGenerator.hh b/PrimitivesGenerator.hh index e0d55ff..c2879d9 100644 --- a/PrimitivesGenerator.hh +++ b/PrimitivesGenerator.hh @@ -173,6 +173,10 @@ public slots: const unsigned int n_y = 5, const unsigned int n_z = 10); #endif +#ifdef ENABLE_HEXAHEDRALMESH_SUPPORT + int addHexahedralCube(const Vector& _position = Vector(0.0,0.0,0.0), + const double _length = 2.0); +#endif private: int addTriMesh(); @@ -182,6 +186,9 @@ private: #ifdef ENABLE_POLYHEDRALMESH_SUPPORT int addPolyhedralMesh(); +#endif +#ifdef ENABLE_HEXAHEDRALMESH_SUPPORT + int addHexahedralMesh(); #endif inline void add_face(int _vh1 , int _vh2, int _vh3); -- 2.22.0