Commit 7cc2a674 authored by Christopher Tenter's avatar Christopher Tenter

add function to generate a random bspline curve

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@20552 383ad7c9-94d9-4d36-a494-682f7c89f535
parent dc32fe93
......@@ -3,7 +3,7 @@ include (plugin)
SET( CURRENT_PLUGIN_DEPS "")
if (EXISTS ${CMAKE_SOURCE_DIR}/ObjectTypes/BSplineCurve)
add_definitions (-DENABLE_SKELETON_SUPPORT)
add_definitions (-DENABLE_BSPLINECURVE_SUPPORT)
endif()
if (EXISTS ${CMAKE_SOURCE_DIR}/ObjectTypes/BSplineSurface)
......
......@@ -51,6 +51,10 @@
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <ACG/Geometry/Algorithms.hh>
#ifdef ENABLE_BSPLINECURVE_SUPPORT
#include <ObjectTypes/BSplineCurve/BSplineCurve.hh>
#endif
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
#include <ObjectTypes/BSplineSurface/BSplineSurface.hh>
#endif
......@@ -121,6 +125,13 @@ void PrimitivesGeneratorPlugin::initializePlugin()
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_BSPLINECURVE_SUPPORT
emit setSlotDescription("addRandomBSplineCurve(Vector,int)",
tr("Generates a random B-spline curve (ObjectId is returned)"),
QString("Position,Count").split(","),
QString("Center position,Number of control points").split(","));
#endif
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
emit setSlotDescription("addRandomBSplineSurface(Vector,int)",
tr("Generates a random B-spline surface (ObjectId is returned)"),
......@@ -187,6 +198,11 @@ void PrimitivesGeneratorPlugin::pluginsInitialized() {
action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"primitive_tetrahedron.png"));
whatsThisGen.setWhatsThis(action,tr("Create a Tetrahedron."),"Tetrahedron");
#ifdef ENABLE_BSPLINECURVE_SUPPORT
action = primitivesMenu_->addAction("Random B-spline curve",this,SLOT(addRandomBSplineCurve()));
whatsThisGen.setWhatsThis(action,tr("Create a random B-spline curve."),"B-spline curve");
#endif
#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"));
......@@ -1038,6 +1054,40 @@ int PrimitivesGeneratorPlugin::addDodecahedron(const Vector& _position,const dou
return -1;
}
#ifdef ENABLE_BSPLINECURVE_SUPPORT
int PrimitivesGeneratorPlugin::addRandomBSplineCurve(const Vector& _position, int nDiv)
{
int id = -1;
emit addEmptyObject(DATA_BSPLINE_CURVE, id);
if (id == -1) {
return -1;
}
BSplineCurveObject *object = NULL;
if (!PluginFunctions::getObject(id, object)) {
return -1;
}
BSplineCurve *curve = object->splineCurve();
curve->autocompute_knotvector(true);
for (int i = 0; i < nDiv; ++i) {
double x = _position[0] + i - nDiv / 2.0;
double r = (2.0 * std::rand()) / RAND_MAX - 1.0;
BSplineCurve::Point cp(x, _position[1] + r, _position[2]);
curve->add_control_point(cp);
}
emit updatedObject(id, UPDATE_ALL);
emit createBackup(id, "Original Object");
PluginFunctions::viewAll();
return id;
}
#endif
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
int PrimitivesGeneratorPlugin::addRandomBSplineSurface(const Vector& _position, int nDiv)
{
......
......@@ -145,6 +145,10 @@ public slots:
int addDodecahedron(const Vector& _position = Vector(0.0,0.0,0.0),
const double _length = 2.0);
#ifdef ENABLE_BSPLINECURVE_SUPPORT
int addRandomBSplineCurve(const Vector& _position = Vector(0, 0, 0), int nDiv = 5);
#endif
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
int addRandomBSplineSurface(const Vector& _position = Vector(0, 0, 0), int nDiv = 5);
#endif
......
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