Commit 21c20550 authored by Jan Möbius's avatar Jan Möbius

Added Sphere generator based on subdivision (Thanks to Vladimir Chalupecky for the original patch).

closes #2041



git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@18461 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 7b437b8b
......@@ -70,37 +70,42 @@ PrimitivesGeneratorPlugin::~PrimitivesGeneratorPlugin()
void PrimitivesGeneratorPlugin::initializePlugin()
{
emit setSlotDescription("addTetrahedron(Vector, double)",
emit setSlotDescription("addTetrahedron(Vector,double)",
tr("Generates a tetrahedron (ObjectId is returned)"),
QString("Position,Length").split(","),
QString("Center position,Length of each edge").split(","));
emit setSlotDescription("addIcosahedron(Vector, double)",
emit setSlotDescription("addIcosahedron(Vector,double)",
tr("Generates an icosahedron (ObjectId is returned)"),
QString("Position,Length").split(","),
QString("Center position,Length of each edge").split(","));
emit setSlotDescription("addPyramid(Vector, double)",
emit setSlotDescription("addPyramid(Vector,double)",
tr("Generates a pyramid (ObjectId is returned)"),
QString("Position,Length").split(","),
QString("Center position,Length of each edge").split(","));
emit setSlotDescription("addOctahedron(Vector, double)",
emit setSlotDescription("addOctahedron(Vector,double)",
tr("Generates an octahedron (ObjectId is returned)"),
QString("Position,Length").split(","),
QString("Center position,Length of each edge").split(","));
emit setSlotDescription("addDodecahedron(Vector, double)",
emit setSlotDescription("addDodecahedron(Vector,double)",
tr("Generates a dodecahedron (ObjectId is returned)"),
QString("Position,Length").split(","),
QString("Center position,Length of each edge").split(","));
emit setSlotDescription("addSphere(Vector, double)",
tr("Generates a sphere (ObjectId is returned)"),
emit setSlotDescription("addSphere(Vector,double)",
tr("Generates a triangulated sphere with all vertical lines connected to the poles (ObjectId is returned)"),
QString("Position, Radius").split(","),
QString("Center position,Radius").split(","));
emit setSlotDescription("addTriangulatedCube(Vector, double)",
emit setSlotDescription("addSubdivisionSphere(Vector,double)",
tr("Generates a triangulated sphere by subdivision without poles. (ObjectId is returned)"),
QString("Position, Radius").split(","),
QString("Center position,Radius").split(","));
emit setSlotDescription("addTriangulatedCube(Vector,double)",
tr("Generates a triangular mesh of cube (ObjectId is returned)"),
QString("Position,Length").split(","),
QString("Center position,Length of each edge").split(","));
......@@ -157,9 +162,13 @@ void PrimitivesGeneratorPlugin::pluginsInitialized() {
action = primitivesMenu_->addAction("Cylinder (Triangle Mesh)" ,this,SLOT(addTriangulatedCylinder()));
action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"primitive_cylinder.png"));
action = primitivesMenu_->addAction("Sphere",this,SLOT(addSphere()));
action = primitivesMenu_->addAction("Sphere (Poles,Triangle Mesh)",this,SLOT(addSphere()));
action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"primitive_sphere.png"));
whatsThisGen.setWhatsThis(action,tr("Create a Sphere. All vertical lines connect to poles) "),"Sphere");
action = primitivesMenu_->addAction("Sphere (Subdivision,Triangle Mesh)",this,SLOT(addSubdivisionSphere()));
action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"primitive_sphere.png"));
whatsThisGen.setWhatsThis(action,tr("Create a Sphere. "),"Sphere");
whatsThisGen.setWhatsThis(action,tr("Create a Sphere. No poles due to Subdivision) "),"Sphere");
action = primitivesMenu_->addAction("Tetrahedron",this,SLOT(addTetrahedron()));
action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"primitive_tetrahedron.png"));
......@@ -657,6 +666,54 @@ int PrimitivesGeneratorPlugin::addSphere(const Vector& _position, const double _
}
}
//------------------------------------------------------------------------
int PrimitivesGeneratorPlugin::addSubdivisionSphere(const Vector& _position, const double _radius)
{
// Create the underlying octahedron
int newObject = addOctahedron(_position,_radius);
TriMeshObject* object;
if (!PluginFunctions::getObject(newObject, object)) {
emit log(LOGERR, "Unable to create new Object");
return -1;
} else {
object->setName( "Sphere " + QString::number(newObject) );
triMesh_ = object->mesh();
// Number of subdivision iterations for the sphere
const size_t subdivisionSteps = 4;
for (size_t i = 0 ; i < subdivisionSteps; ++i) {
// Call the subdivision algorithm
RPC::callFunction("subdivider", "subdivide", newObject, QString("loop"), 1, false);
// Reposition vertices onto sphere
for (TriMesh::VertexIter v_it = triMesh_->vertices_begin(); v_it != triMesh_->vertices_end(); ++v_it) {
TriMesh::Point p = triMesh_->point(*v_it);
p -= _position;
p = _radius * p.normalize() + _position;
triMesh_->set_point(*v_it, p);
}
}
// Make sure that the normals are fine
triMesh_->update_normals();
emit updatedObject(newObject, UPDATE_ALL);
PluginFunctions::viewAll();
return newObject;
}
}
......
......@@ -47,6 +47,7 @@
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/MenuInterface.hh>
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
#include <OpenFlipper/BasePlugin/RPCInterface.hh>
#include <OpenFlipper/common/Types.hh>
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
......@@ -57,12 +58,13 @@
#endif
class PrimitivesGeneratorPlugin: public QObject, BaseInterface, LoggingInterface, MenuInterface, LoadSaveInterface {
class PrimitivesGeneratorPlugin: public QObject, BaseInterface, LoggingInterface, MenuInterface, LoadSaveInterface, RPCInterface {
Q_OBJECT
Q_INTERFACES(BaseInterface)
Q_INTERFACES(LoggingInterface)
Q_INTERFACES(MenuInterface)
Q_INTERFACES(LoadSaveInterface)
Q_INTERFACES(RPCInterface)
#if QT_VERSION >= 0x050000
Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-PrimitiveGenerator")
......@@ -117,6 +119,9 @@ public slots:
int addSphere(const Vector& _position = Vector(0.0,0.0,0.0),
const double _radius = 1.0);
int addSubdivisionSphere(const Vector& _position = Vector(0.0,0.0,0.0),
const double _radius = 1.0);
int addTetrahedron(const Vector& _position = Vector(0.0,0.0,0.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