Commit 706df58e authored by Matthias Möller's avatar Matthias Möller

add bspline surface support

thanks to Vladimir Chalupecky for the provided code

refs #2252

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@19436 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 21c20550
...@@ -6,6 +6,10 @@ if (EXISTS ${CMAKE_SOURCE_DIR}/ObjectTypes/BSplineCurve) ...@@ -6,6 +6,10 @@ if (EXISTS ${CMAKE_SOURCE_DIR}/ObjectTypes/BSplineCurve)
add_definitions (-DENABLE_SKELETON_SUPPORT) add_definitions (-DENABLE_SKELETON_SUPPORT)
endif() endif()
if (EXISTS ${CMAKE_SOURCE_DIR}/ObjectTypes/BSplineSurface)
add_definitions (-DENABLE_BSPLINESURFACE_SUPPORT)
endif ()
if (EXISTS ${CMAKE_SOURCE_DIR}/ObjectTypes/PolyhedralMesh) if (EXISTS ${CMAKE_SOURCE_DIR}/ObjectTypes/PolyhedralMesh)
add_definitions (-DENABLE_OPENVOLUMEMESH_SUPPORT) add_definitions (-DENABLE_OPENVOLUMEMESH_SUPPORT)
add_definitions (-DENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT) add_definitions (-DENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT)
......
...@@ -40,6 +40,8 @@ ...@@ -40,6 +40,8 @@
* * * *
\*===========================================================================*/ \*===========================================================================*/
#include <cstdlib>
#include "PrimitivesGenerator.hh" #include "PrimitivesGenerator.hh"
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
...@@ -49,6 +51,10 @@ ...@@ -49,6 +51,10 @@
#include <OpenFlipper/BasePlugin/PluginFunctions.hh> #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <ACG/Geometry/Algorithms.hh> #include <ACG/Geometry/Algorithms.hh>
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
#include <ObjectTypes/BSplineSurface/BSplineSurface.hh>
#endif
PrimitivesGeneratorPlugin::PrimitivesGeneratorPlugin() : PrimitivesGeneratorPlugin::PrimitivesGeneratorPlugin() :
triMesh_(0), triMesh_(0),
polyMesh_(0), polyMesh_(0),
...@@ -115,6 +121,13 @@ void PrimitivesGeneratorPlugin::initializePlugin() ...@@ -115,6 +121,13 @@ void PrimitivesGeneratorPlugin::initializePlugin()
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_BSPLINESURFACE_SUPPORT
emit setSlotDescription("addRandomBSplineSurface(Vector,int)",
tr("Generates a random B-spline surface (ObjectId is returned)"),
QString("Position,Count").split(","),
QString("Center position,Number of control points").split(","));
#endif
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
emit setSlotDescription("addTetrahedralCube(Vector,double)", emit setSlotDescription("addTetrahedralCube(Vector,double)",
tr("Generates a tetrahedral mesh of a cube (ObjectId is returned)"), tr("Generates a tetrahedral mesh of a cube (ObjectId is returned)"),
...@@ -174,6 +187,12 @@ void PrimitivesGeneratorPlugin::pluginsInitialized() { ...@@ -174,6 +187,12 @@ void PrimitivesGeneratorPlugin::pluginsInitialized() {
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_BSPLINESURFACE_SUPPORT
action = primitivesMenu_->addAction("Random B-spline surface",this,SLOT(addRandomBSplineSurface()));
// action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"bspline_surface.png"));
whatsThisGen.setWhatsThis(action,tr("Create a random B-spline surface."),"B-spline surface");
#endif
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
action = primitivesMenu_->addAction("Cube (Tetrahedral Mesh)" ,this,SLOT(addTetrahedralCube())); action = primitivesMenu_->addAction("Cube (Tetrahedral Mesh)" ,this,SLOT(addTetrahedralCube()));
action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"primitive_cube.png")); action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"primitive_cube.png"));
...@@ -1002,6 +1021,40 @@ int PrimitivesGeneratorPlugin::addDodecahedron(const Vector& _position,const dou ...@@ -1002,6 +1021,40 @@ int PrimitivesGeneratorPlugin::addDodecahedron(const Vector& _position,const dou
return -1; return -1;
} }
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
int PrimitivesGeneratorPlugin::addRandomBSplineSurface(const Vector& _position, int nDiv)
{
int id = -1;
emit addEmptyObject(DATA_BSPLINE_SURFACE, id);
if (id == -1) {
return -1;
}
BSplineSurfaceObject *object = NULL;
if (!PluginFunctions::getObject(id, object)) {
return -1;
}
BSplineSurface *surf = object->splineSurface();
typedef BSplineSurface::Point Point;
std::vector<Point> cp(nDiv);
for (int i = 0; i < nDiv; ++i) {
double x = _position[0] + i - nDiv / 2.0;
for (int j = 0; j < nDiv; ++j) {
double y = _position[1] + j - nDiv / 2.0;
cp[j] = Point(x, y, _position[2] + (2.0 * std::rand()) / RAND_MAX - 1);
}
surf->add_vector_m(cp);
}
surf->createKnots();
emit updatedObject(id, UPDATE_ALL);
PluginFunctions::viewAll();
return id;
}
#endif
#if QT_VERSION < 0x050000 #if QT_VERSION < 0x050000
Q_EXPORT_PLUGIN2( primitivesgeneratorplugin , PrimitivesGeneratorPlugin ); Q_EXPORT_PLUGIN2( primitivesgeneratorplugin , PrimitivesGeneratorPlugin );
......
...@@ -140,6 +140,10 @@ public slots: ...@@ -140,6 +140,10 @@ 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_BSPLINESURFACE_SUPPORT
int addRandomBSplineSurface(const Vector& _position = Vector(0, 0, 0), int nDiv = 5);
#endif
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
int addTetrahedralCube(const Vector& _position = Vector(0.0,0.0,0.0), int addTetrahedralCube(const Vector& _position = Vector(0.0,0.0,0.0),
const double _length = 2.0); const double _length = 2.0);
......
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