Commit abd2fab5 authored by Jan Möbius's avatar Jan Möbius
Browse files

Generator for cuboid tetrahedral meshes (Thanks to Vladimir Chalupecky for the code)

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@17252 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 26435164
include (plugin) include (plugin)
if (EXISTS ${CMAKE_SOURCE_DIR}/ObjectTypes/BSplineCurve)
add_definitions (-DENABLE_SKELETON_SUPPORT)
endif()
if (EXISTS ${CMAKE_SOURCE_DIR}/ObjectTypes/PolyhedralMesh)
add_definitions (-DENABLE_OPENVOLUMEMESH_SUPPORT)
add_definitions (-DENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT)
endif()
if (EXISTS ${CMAKE_SOURCE_DIR}/ObjectTypes/HexahedralMesh)
add_definitions (-DENABLE_OPENVOLUMEMESH_SUPPORT)
add_definitions (-DENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT)
endif()
openflipper_plugin ( INSTALLDATA Icons ) openflipper_plugin ( INSTALLDATA Icons )
/*===========================================================================*\ /*===========================================================================*\
* * * *
* OpenFlipper * * OpenFlipper *
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen * * Copyright (C) 2001-2013 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org * * www.openflipper.org *
* * * *
*--------------------------------------------------------------------------- * *--------------------------------------------------------------------------- *
...@@ -40,10 +40,11 @@ ...@@ -40,10 +40,11 @@
* * * *
\*===========================================================================*/ \*===========================================================================*/
#include "PrimitivesGenerator.hh" #include "PrimitivesGenerator.hh"
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
#include "TetrahedralCuboidGenerator.hh"
#endif
#include <OpenFlipper/BasePlugin/PluginFunctions.hh> #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <ACG/Geometry/Algorithms.hh> #include <ACG/Geometry/Algorithms.hh>
...@@ -100,7 +101,7 @@ void PrimitivesGeneratorPlugin::initializePlugin() ...@@ -100,7 +101,7 @@ void PrimitivesGeneratorPlugin::initializePlugin()
QString("Center position,Radius").split(",")); QString("Center position,Radius").split(","));
emit setSlotDescription("addTriangulatedCube(Vector, double)", emit setSlotDescription("addTriangulatedCube(Vector, double)",
tr("Generates a cube (ObjectId is returned)"), tr("Generates a triangular mesh of cube (ObjectId is returned)"),
QString("Position,Length").split(","), QString("Position,Length").split(","),
QString("Center position,Length of each edge").split(",")); QString("Center position,Length of each edge").split(","));
...@@ -108,6 +109,19 @@ void PrimitivesGeneratorPlugin::initializePlugin() ...@@ -108,6 +109,19 @@ void PrimitivesGeneratorPlugin::initializePlugin()
tr("Generates a triangulated cylinder (ObjectId is returned)") , tr("Generates a triangulated cylinder (ObjectId is returned)") ,
QString("Position,Axis,Radius,Height,Top,Bottom").split(","), QString("Position,Axis,Radius,Height,Top,Bottom").split(","),
QString("Bottom center vertex position,Center axis,radius,height,add top vertex,add bottom vertex").split(",")); QString("Bottom center vertex position,Center axis,radius,height,add top vertex,add bottom vertex").split(","));
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
emit setSlotDescription("addTetrahedralCube(Vector,double)",
tr("Generates a tetrahedral mesh of a cube (ObjectId is returned)"),
QString("Position,Length").split(","),
QString("Center position,Length of each edge").split(","));
emit setSlotDescription("addTetrahedralCuboid(Vector,Vector,uint,uint,uint)",
tr("Generates a tetrahedral mesh of a cuboid (ObjectId is returned)"),
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
} }
void PrimitivesGeneratorPlugin::pluginsInitialized() { void PrimitivesGeneratorPlugin::pluginsInitialized() {
...@@ -150,8 +164,17 @@ void PrimitivesGeneratorPlugin::pluginsInitialized() { ...@@ -150,8 +164,17 @@ void PrimitivesGeneratorPlugin::pluginsInitialized() {
action = primitivesMenu_->addAction("Tetrahedron",this,SLOT(addTetrahedron())); action = primitivesMenu_->addAction("Tetrahedron",this,SLOT(addTetrahedron()));
action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"primitive_tetrahedron.png")); action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"primitive_tetrahedron.png"));
whatsThisGen.setWhatsThis(action,tr("Create a Tetrahedron."),"Tetrahedron"); whatsThisGen.setWhatsThis(action,tr("Create a Tetrahedron."),"Tetrahedron");
}
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
action = primitivesMenu_->addAction("Cube (Tetrahedral Mesh)" ,this,SLOT(addTetrahedralCube()));
action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"primitive_cube.png"));
whatsThisGen.setWhatsThis(action,tr("Create a Tetrahedral Cube."), "Cube");
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
}
} }
...@@ -183,6 +206,23 @@ int PrimitivesGeneratorPlugin::addPolyMesh() { ...@@ -183,6 +206,23 @@ int PrimitivesGeneratorPlugin::addPolyMesh() {
return objectId; return objectId;
} }
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
int PrimitivesGeneratorPlugin::addPolyhedralMesh() {
int objectId = -1;
emit addEmptyObject( DATA_POLYHEDRAL_MESH, objectId );
PolyhedralMeshObject* object;
if (!PluginFunctions::getObject(objectId, object) ) {
emit log(LOGERR, "Unable to create new PolyhedralMesh object");
return -1;
}
return objectId;
}
#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();
...@@ -219,6 +259,8 @@ int PrimitivesGeneratorPlugin::addTetrahedron(const Vector& _position, const dou ...@@ -219,6 +259,8 @@ int PrimitivesGeneratorPlugin::addTetrahedron(const Vector& _position, const dou
emit updatedObject(newObject,UPDATE_ALL); emit updatedObject(newObject,UPDATE_ALL);
PluginFunctions::viewAll();
return newObject; return newObject;
} }
...@@ -276,12 +318,59 @@ int PrimitivesGeneratorPlugin::addTriangulatedCube(const Vector& _position,const ...@@ -276,12 +318,59 @@ int PrimitivesGeneratorPlugin::addTriangulatedCube(const Vector& _position,const
emit updatedObject(newObject,UPDATE_ALL); emit updatedObject(newObject,UPDATE_ALL);
PluginFunctions::viewAll();
return newObject; return newObject;
} }
return -1; return -1;
} }
//========================================================================
// Tetrahedral cube
//========================================================================
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
int PrimitivesGeneratorPlugin::addTetrahedralCube(const Vector& _position, const double _length)
{
return addTetrahedralCuboid(_position, Vector(_length, _length, _length), 1, 1, 1);
}
#endif
//========================================================================
// Tetrahedral Cuboid
//========================================================================
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
int PrimitivesGeneratorPlugin::addTetrahedralCuboid(const Vector& _position,
const Vector& _length, const unsigned int n_x, const unsigned int n_y, const unsigned int n_z)
{
int object_id = addPolyhedralMesh();
PolyhedralMeshObject* object;
if (!PluginFunctions::getObject(object_id, object)) {
return -1;
}
object->setName("Cuboid " + QString::number(object_id));
TetrahedralCuboidGenerator gen;
gen.generate(*(object->mesh()), _position, _length, n_x, n_y, n_z);
emit updatedObject(object_id, UPDATE_ALL);
object->setObjectDrawMode(ACG::SceneGraph::DrawModes::getDrawMode("Cells (flat shaded)"));
PluginFunctions::viewAll();
return object_id;
}
#endif
//======================================================================== //========================================================================
// Cylinder // Cylinder
//======================================================================== //========================================================================
...@@ -425,6 +514,8 @@ int PrimitivesGeneratorPlugin::addTriangulatedCylinder(const Vector& _position,c ...@@ -425,6 +514,8 @@ int PrimitivesGeneratorPlugin::addTriangulatedCylinder(const Vector& _position,c
emit updatedObject(newObject,UPDATE_ALL); emit updatedObject(newObject,UPDATE_ALL);
PluginFunctions::viewAll();
return object->id(); return object->id();
} }
...@@ -561,6 +652,8 @@ int PrimitivesGeneratorPlugin::addSphere(const Vector& _position, const double _ ...@@ -561,6 +652,8 @@ int PrimitivesGeneratorPlugin::addSphere(const Vector& _position, const double _
emit updatedObject(newObject,UPDATE_ALL); emit updatedObject(newObject,UPDATE_ALL);
PluginFunctions::viewAll();
return object->id(); return object->id();
} }
...@@ -612,6 +705,8 @@ int PrimitivesGeneratorPlugin::addPyramid(const Vector& _position,const double _ ...@@ -612,6 +705,8 @@ int PrimitivesGeneratorPlugin::addPyramid(const Vector& _position,const double _
emit updatedObject(newObject,UPDATE_ALL); emit updatedObject(newObject,UPDATE_ALL);
PluginFunctions::viewAll();
return newObject; return newObject;
} }
...@@ -715,6 +810,8 @@ int PrimitivesGeneratorPlugin::addIcosahedron(const Vector& _position,const doub ...@@ -715,6 +810,8 @@ int PrimitivesGeneratorPlugin::addIcosahedron(const Vector& _position,const doub
emit updatedObject(newObject,UPDATE_ALL); emit updatedObject(newObject,UPDATE_ALL);
PluginFunctions::viewAll();
return newObject; return newObject;
} }
...@@ -767,6 +864,8 @@ int PrimitivesGeneratorPlugin::addOctahedron(const Vector& _position,const doubl ...@@ -767,6 +864,8 @@ int PrimitivesGeneratorPlugin::addOctahedron(const Vector& _position,const doubl
emit updatedObject(newObject,UPDATE_ALL); emit updatedObject(newObject,UPDATE_ALL);
PluginFunctions::viewAll();
return newObject; return newObject;
} }
...@@ -839,6 +938,8 @@ int PrimitivesGeneratorPlugin::addDodecahedron(const Vector& _position,const dou ...@@ -839,6 +938,8 @@ int PrimitivesGeneratorPlugin::addDodecahedron(const Vector& _position,const dou
emit updatedObject(newObject,UPDATE_ALL); emit updatedObject(newObject,UPDATE_ALL);
PluginFunctions::viewAll();
return newObject; return newObject;
} }
......
/*===========================================================================*\ /*===========================================================================*\
* * * *
* OpenFlipper * * OpenFlipper *
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen * * Copyright (C) 2001-2013 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org * * www.openflipper.org *
* * * *
*--------------------------------------------------------------------------- * *--------------------------------------------------------------------------- *
...@@ -52,6 +52,11 @@ ...@@ -52,6 +52,11 @@
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh> #include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
#include <ObjectTypes/PolyMesh/PolyMesh.hh> #include <ObjectTypes/PolyMesh/PolyMesh.hh>
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
#include <ObjectTypes/PolyhedralMesh/PolyhedralMesh.hh>
#endif
class PrimitivesGeneratorPlugin: public QObject, BaseInterface, LoggingInterface, MenuInterface, LoadSaveInterface { class PrimitivesGeneratorPlugin: public QObject, BaseInterface, LoggingInterface, MenuInterface, LoadSaveInterface {
Q_OBJECT Q_OBJECT
Q_INTERFACES(BaseInterface) Q_INTERFACES(BaseInterface)
...@@ -130,10 +135,25 @@ public slots: ...@@ -130,10 +135,25 @@ public slots:
int addDodecahedron(const Vector& _position = Vector(0.0,0.0,0.0), int addDodecahedron(const Vector& _position = Vector(0.0,0.0,0.0),
const double _length = 2.0); const double _length = 2.0);
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
int addTetrahedralCube(const Vector& _position = Vector(0.0,0.0,0.0),
const double _length = 2.0);
int addTetrahedralCuboid(const Vector& _position = Vector(0.0,0.0,0.0),
const Vector& _length = Vector(4.0,6.0,12.0),
const unsigned int n_x = 5,
const unsigned int n_y = 5,
const unsigned int n_z = 10);
#endif
private: private:
int addTriMesh(); int addTriMesh();
int addPolyMesh(); int addPolyMesh();
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_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 , int _vh5 ); inline void add_face( int _vh1 , int _vh2, int _vh3, int _vh4 , int _vh5 );
......
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2013 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*--------------------------------------------------------------------------- *
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $LastChangedBy$ *
* $Date$ *
* *
\*===========================================================================*/
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
#include "TetrahedralCuboidGenerator.hh"
void TetrahedralCuboidGenerator::add_vertices(Vector const& position, Vector const& length)
{
vertices_.clear();
vertices_.reserve((size_[0] + 1) * (size_[1] + 1) * (size_[2] + 1));
Vector h(length[0] / size_[0], length[1] / size_[1], length[2] / size_[2]);
Vector origin = position - 0.5 * length;
for (std::size_t k = 0; k < size_[2] + 1; ++k)
for (std::size_t j = 0; j < size_[1] + 1; ++j)
for (std::size_t i = 0; i < size_[0] + 1; ++i)
vertices_.push_back(mesh_->add_vertex(Vector(h[0]*i, h[1]*j, h[2]*k) + origin));
}
void TetrahedralCuboidGenerator::get_cube_vertices(std::size_t i, std::size_t j, std::size_t k,
std::vector<OpenVolumeMesh::VertexHandle>& v)
{
v[0] = vertices_[k * (size_[0] + 1) * (size_[1] + 1) + j * (size_[0] + 1) + i];
v[1] = vertices_[k * (size_[0] + 1) * (size_[1] + 1) + j * (size_[0] + 1) + i + 1];
v[2] = vertices_[k * (size_[0] + 1) * (size_[1] + 1) + (j + 1) * (size_[0] + 1) + i];
v[3] = vertices_[k * (size_[0] + 1) * (size_[1] + 1) + (j + 1) * (size_[0] + 1) + i + 1];
v[4] = vertices_[(k + 1) * (size_[0] + 1) * (size_[1] + 1) + j * (size_[0] + 1) + i];
v[5] = vertices_[(k + 1) * (size_[0] + 1) * (size_[1] + 1) + j * (size_[0] + 1) + i + 1];
v[6] = vertices_[(k + 1) * (size_[0] + 1) * (size_[1] + 1) + (j + 1) * (size_[0] + 1) + i];
v[7] = vertices_[(k + 1) * (size_[0] + 1) * (size_[1] + 1) + (j + 1) * (size_[0] + 1) + i + 1];
}
void TetrahedralCuboidGenerator::add_faces()
{
std::vector<OpenVolumeMesh::VertexHandle> v(8);
for (std::size_t i = 0; i < size_[0]; ++i)
for (std::size_t j = 0; j < size_[1]; ++j)
for (std::size_t k = 0; k < size_[2]; ++k)
{
get_cube_vertices(i, j, k, v);
if ((i + j + k) % 2 == 0)
add_cube_type_1_faces(i, j, k, v);
else
add_cube_type_2_faces(i, j, k, v);
}
}
void TetrahedralCuboidGenerator::add_cube_type_1_faces(std::size_t i, std::size_t j, std::size_t k,
std::vector<OpenVolumeMesh::VertexHandle>& v)
{
std::vector<OpenVolumeMesh::VertexHandle> fv(3);
// left side
fv[0] = v[0]; fv[1] = v[2]; fv[2] = v[6];
faces_.insert(std::make_pair(SortedFace(fv), mesh_->add_face(fv)));
fv[0] = v[0]; fv[1] = v[6]; fv[2] = v[4];
faces_.insert(std::make_pair(SortedFace(fv), mesh_->add_face(fv)));
// front side
fv[0] = v[0]; fv[1] = v[4]; fv[2] = v[5];
faces_.insert(std::make_pair(SortedFace(fv), mesh_->add_face(fv)));
fv[0] = v[0]; fv[1] = v[5]; fv[2] = v[1];
faces_.insert(std::make_pair(SortedFace(fv), mesh_->add_face(fv)));
// bottom side
fv[0] = v[0]; fv[1] = v[1]; fv[2] = v[3];
faces_.insert(std::make_pair(SortedFace(fv), mesh_->add_face(fv)));
fv[0] = v[0]; fv[1] = v[3]; fv[2] = v[2];
faces_.insert(std::make_pair(SortedFace(fv), mesh_->add_face(fv)));
// inner faces
fv[0] = v[0]; fv[1] = v[5]; fv[2] = v[6];
faces_.insert(std::make_pair(SortedFace(fv), mesh_->add_face(fv)));
fv[0] = v[0]; fv[1] = v[3]; fv[2] = v[5];
faces_.insert(std::make_pair(SortedFace(fv), mesh_->add_face(fv)));
fv[0] = v[0]; fv[1] = v[6]; fv[2] = v[3];
faces_.insert(std::make_pair(SortedFace(fv), mesh_->add_face(fv)));
fv[0] = v[3]; fv[1] = v[6]; fv[2] = v[5];
faces_.insert(std::make_pair(SortedFace(fv), mesh_->add_face(fv)));
// right face
if (i == size_[0] - 1) {
fv[0] = v[3]; fv[1] = v[5]; fv[2] = v[1];
faces_.insert(std::make_pair(SortedFace(fv), mesh_->add_face(fv)));
fv[0] = v[3]; fv[1] = v[7]; fv[2] = v[5];
faces_.insert(std::make_pair(SortedFace(fv), mesh_->add_face(fv)));
}
// back face
if (j == size_[1] - 1) {
fv[0] = v[3]; fv[1] = v[6]; fv[2] = v[7];
faces_.insert(std::make_pair(SortedFace(fv), mesh_->add_face(fv)));
fv[0] = v[3]; fv[1] = v[2]; fv[2] = v[6];
faces_.insert(std::make_pair(SortedFace(fv), mesh_->add_face(fv)));
}
// top face
if (k == size_[2] - 1) {
fv[0] = v[5]; fv[1] = v[6]; fv[2] = v[4];
faces_.insert(std::make_pair(SortedFace(fv), mesh_->add_face(fv)));
fv[0] = v[5]; fv[1] = v[7]; fv[2] = v[6];
faces_.insert(std::make_pair(SortedFace(fv), mesh_->add_face(fv)));
}
}
void TetrahedralCuboidGenerator::add_cube_type_2_faces(std::size_t i, std::size_t j, std::size_t k,
std::vector<OpenVolumeMesh::VertexHandle>& v)
{
std::vector<OpenVolumeMesh::VertexHandle> fv(3);
// left side
fv[0] = v[0]; fv[1] = v[2]; fv[2] = v[4];
faces_.insert(std::make_pair(SortedFace(fv), mesh_->add_face(fv)));
fv[0] = v[2]; fv[1] = v[6]; fv[2] = v[4];
faces_.insert(std::make_pair(SortedFace(fv), mesh_->add_face(fv)));
// front side
fv[0] = v[0]; fv[1] = v[4]; fv[2] = v[1];
faces_.insert(std::make_pair(SortedFace(fv), mesh_->add_face(fv)));
fv[0] = v[4]; fv[1] = v[5]; fv[2] = v[1];
faces_.insert(std::make_pair(SortedFace(fv), mesh_->add_face(fv)));
// bottom side
fv[0] = v[0]; fv[1] = v[1]; fv[2] = v[2];
faces_.insert(std::make_pair(SortedFace(fv), mesh_->add_face(fv)));
fv[0] = v[1]; fv[1] = v[3]; fv[2] = v[2];
faces_.insert(std::make_pair(SortedFace(fv), mesh_->add_face(fv)));
// inner faces
fv[0] = v[1]; fv[1] = v[7]; fv[2] = v[4];
faces_.insert(std::make_pair(SortedFace(fv), mesh_->add_face(fv)));
fv[0] = v[1]; fv[1] = v[2]; fv[2] = v[7];
faces_.insert(std::make_pair(SortedFace(fv), mesh_->add_face(fv)));
fv[0] = v[2]; fv[1] = v[4]; fv[2] = v[7];
faces_.insert(std::make_pair(SortedFace(fv), mesh_->add_face(fv)));
fv[0] = v[1]; fv[1] = v[4]; fv[2] = v[2];
faces_.insert(std::make_pair(SortedFace(fv), mesh_->add_face(fv)));
// right face
if (i == size_[0] - 1) {
fv[0] = v[1]; fv[1] = v[7]; fv[2] = v[5];
faces_.insert(std::make_pair(SortedFace(fv), mesh_->add_face(fv)));
fv[0] = v[1]; fv[1] = v[3]; fv[2] = v[7];
faces_.insert(std::make_pair(SortedFace(fv), mesh_->add_face(fv)));
}
// back face
if (j == size_[1] - 1) {
fv[0] = v[2]; fv[1] = v[7]; fv[2] = v[3];
faces_.insert(std::make_pair(SortedFace(fv), mesh_->add_face(fv)));
fv[0] = v[2]; fv[1] = v[6]; fv[2] = v[7];
faces_.insert(std::make_pair(SortedFace(fv), mesh_->add_face(fv)));
}
// top face
if (k == size_[2] - 1) {
fv[0] = v[4]; fv[1] = v[7]; fv[2] = v[6];
faces_.insert(std::make_pair(SortedFace(fv), mesh_->add_face(fv)));
fv[0] = v[4]; fv[1] = v[5]; fv[2] = v[7];
faces_.insert(std::make_pair(SortedFace(fv), mesh_->add_face(fv)));
}
}
void TetrahedralCuboidGenerator::add_cells()
{
std::vector<OpenVolumeMesh::VertexHandle> v(8);
for (std::size_t i = 0; i < size_[0]; ++i)
for (std::size_t j = 0; j < size_[1]; ++j)
for (std::size_t k = 0; k < size_[2]; ++k)
{
get_cube_vertices(i, j, k, v);
if ((i + j + k) % 2 == 0)
add_cube_type_1_cells(i, j, k, v);
else
add_cube_type_2_cells(i, j, k, v);
}
}
void TetrahedralCuboidGenerator::add_cube_type_1_cells(std::size_t i, std::size_t j, std::size_t k,
std::vector<OpenVolumeMesh::VertexHandle>& v)
{
std::vector<OpenVolumeMesh::FaceHandle> f(4);
std::vector<OpenVolumeMesh::HalfFaceHandle> hf(4);
// inner cell
f[0] = faces_[SortedFace(v[0], v[5], v[6])];
f[1] = faces_[SortedFace(v[0], v[3], v[5])];