Commit 8fcf3094 authored by Jan Möbius's avatar Jan Möbius

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 95c57857
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 *
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
* Copyright (C) 2001-2013 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*--------------------------------------------------------------------------- *
......@@ -40,10 +40,11 @@
* *
\*===========================================================================*/
#include "PrimitivesGenerator.hh"
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
#include "TetrahedralCuboidGenerator.hh"
#endif
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <ACG/Geometry/Algorithms.hh>
......@@ -100,7 +101,7 @@ void PrimitivesGeneratorPlugin::initializePlugin()
QString("Center position,Radius").split(","));
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("Center position,Length of each edge").split(","));
......@@ -108,6 +109,19 @@ void PrimitivesGeneratorPlugin::initializePlugin()
tr("Generates a triangulated cylinder (ObjectId is returned)") ,
QString("Position,Axis,Radius,Height,Top,Bottom").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() {
......@@ -150,8 +164,17 @@ void PrimitivesGeneratorPlugin::pluginsInitialized() {
action = primitivesMenu_->addAction("Tetrahedron",this,SLOT(addTetrahedron()));
action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"primitive_tetrahedron.png"));
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() {
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 newObject = addTriMesh();
......@@ -219,6 +259,8 @@ int PrimitivesGeneratorPlugin::addTetrahedron(const Vector& _position, const dou
emit updatedObject(newObject,UPDATE_ALL);
PluginFunctions::viewAll();
return newObject;
}
......@@ -276,12 +318,59 @@ int PrimitivesGeneratorPlugin::addTriangulatedCube(const Vector& _position,const
emit updatedObject(newObject,UPDATE_ALL);
PluginFunctions::viewAll();
return newObject;
}
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
//========================================================================
......@@ -425,6 +514,8 @@ int PrimitivesGeneratorPlugin::addTriangulatedCylinder(const Vector& _position,c
emit updatedObject(newObject,UPDATE_ALL);
PluginFunctions::viewAll();
return object->id();
}
......@@ -561,6 +652,8 @@ int PrimitivesGeneratorPlugin::addSphere(const Vector& _position, const double _
emit updatedObject(newObject,UPDATE_ALL);
PluginFunctions::viewAll();
return object->id();
}
......@@ -612,6 +705,8 @@ int PrimitivesGeneratorPlugin::addPyramid(const Vector& _position,const double _
emit updatedObject(newObject,UPDATE_ALL);
PluginFunctions::viewAll();
return newObject;
}
......@@ -715,6 +810,8 @@ int PrimitivesGeneratorPlugin::addIcosahedron(const Vector& _position,const doub
emit updatedObject(newObject,UPDATE_ALL);
PluginFunctions::viewAll();
return newObject;
}
......@@ -767,6 +864,8 @@ int PrimitivesGeneratorPlugin::addOctahedron(const Vector& _position,const doubl
emit updatedObject(newObject,UPDATE_ALL);
PluginFunctions::viewAll();
return newObject;
}
......@@ -839,6 +938,8 @@ int PrimitivesGeneratorPlugin::addDodecahedron(const Vector& _position,const dou
emit updatedObject(newObject,UPDATE_ALL);
PluginFunctions::viewAll();
return newObject;
}
......
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
* Copyright (C) 2001-2013 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*--------------------------------------------------------------------------- *
......@@ -52,6 +52,11 @@
#include <ObjectTypes/TriangleMesh/TriangleMesh.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 {
Q_OBJECT
Q_INTERFACES(BaseInterface)
......@@ -130,10 +135,25 @@ public slots:
int addDodecahedron(const Vector& _position = Vector(0.0,0.0,0.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:
int addTriMesh();
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, int _vh4 , int _vh5 );
......
This diff is collapsed.
/*===========================================================================*\
* *
* 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$ *
* *
\*===========================================================================*/
#pragma once
#include <ObjectTypes/PolyhedralMesh/PolyhedralMesh.hh>
struct SortedFace
{
explicit SortedFace(std::vector<OpenVolumeMesh::VertexHandle> const& face)
: v(face)
{
std::sort(v.begin(), v.end());
}
SortedFace(OpenVolumeMesh::VertexHandle v1,
OpenVolumeMesh::VertexHandle v2,
OpenVolumeMesh::VertexHandle v3)
: v(3)
{
v[0] = v1;
v[1] = v2;
v[2] = v3;
std::sort(v.begin(), v.end());
}
std::vector<OpenVolumeMesh::VertexHandle> v;
};
inline bool operator<(SortedFace const& f1, SortedFace const& f2)
{
return std::lexicographical_compare(f1.v.begin(), f1.v.end(),
f2.v.begin(), f2.v.end());
}
class TetrahedralCuboidGenerator
{
public:
void generate(PolyhedralMesh& mesh, Vector const& position, Vector const& length,
unsigned const n_x, unsigned const n_y, unsigned const n_z);
private:
void add_vertices(Vector const& position, Vector const& length);
void get_cube_vertices(std::size_t i, std::size_t j, std::size_t k,
std::vector<OpenVolumeMesh::VertexHandle>& v);
void add_faces();
void add_cube_type_1_faces(std::size_t i, std::size_t j, std::size_t k,
std::vector<OpenVolumeMesh::VertexHandle>& v);
void add_cube_type_2_faces(std::size_t i, std::size_t j, std::size_t k,
std::vector<OpenVolumeMesh::VertexHandle>& v);
void add_cells();
void add_cube_type_1_cells(std::size_t i, std::size_t j, std::size_t k,
std::vector<OpenVolumeMesh::VertexHandle>& v);
void add_cube_type_2_cells(std::size_t i, std::size_t j, std::size_t k,
std::vector<OpenVolumeMesh::VertexHandle>& v);
PolyhedralMesh* mesh_;
std::size_t size_[3];
std::vector<OpenVolumeMesh::VertexHandle> vertices_;
std::map<SortedFace, OpenVolumeMesh::FaceHandle> faces_;
};
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