Skip to content
Snippets Groups Projects
Commit eebbcd08 authored by Jan Möbius's avatar Jan Möbius
Browse files

Merge branch 'planes' into 'master'

Planes

See merge request !2
parents 4aa7d2a3 41a798e4
No related branches found
No related tags found
1 merge request!2Planes
Icons/primitive_plane_bumpy.png

42.3 KiB

Icons/primitive_plane_flat.png

11.9 KiB

Icons/primitive_plane_non-manifold.png

13.3 KiB

......@@ -242,6 +242,19 @@ void PrimitivesGeneratorPlugin::pluginsInitialized() {
whatsThisGen.setWhatsThis(action,tr("Create a Hexahedral Cube."), "Cube");
#endif
action = primitivesMenu_->addAction("Plane (Triangle Mesh)" ,this,SLOT(addTriangulatedPlaneFlat()));
action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"primitive_plane_flat.png"));
whatsThisGen.setWhatsThis(action,tr("Create a flat simple plane."),"Plane");
action = primitivesMenu_->addAction("Plane, bumpy (Triangle Mesh)" ,this,SLOT(addTriangulatedPlaneBumpy()));
action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"primitive_plane_bumpy.png"));
whatsThisGen.setWhatsThis(action,tr("Create a bumpy plane."),"Plane");
action = primitivesMenu_->addAction("Perpendicular planes Non-Manifold (Triangle Mesh)" ,this,SLOT(addTriangulatedPlanesNonManifold()));
action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"primitive_plane_non-manifold.png"));
whatsThisGen.setWhatsThis(action,tr("Create a non manifold plane configuration."),"Plane");
}
}
......@@ -337,6 +350,172 @@ int PrimitivesGeneratorPlugin::addTetrahedron(const Vector& _position, const dou
return -1;
}
int PrimitivesGeneratorPlugin::addTriangulatedPlaneFlat(const Vector& _position ,
const double _sizeX , const double _sizeY ,
const int _segmentsX , const int _segmentsY )
{
int newObject = addTriMesh();
TriMeshObject* object;
if ( !PluginFunctions::getObject(newObject,object) ) {
emit log(LOGERR,"Unable to create new Object");
return -1;
} else {
object->setName( "Cube " + QString::number(newObject) );
triMesh_ = object->mesh();
triMesh_->clear();
vhandles_.resize( (_segmentsX+1) * (_segmentsY+1) );
for (auto i = 0 ; i < (_segmentsX + 1) ; ++i) {
for (auto j = 0 ; j < (_segmentsY + 1) ; ++j) {
vhandles_[ i * (_segmentsY + 1) + j ] = triMesh_->add_vertex(TriMesh::Point( _sizeX / _segmentsX * i , _sizeY / _segmentsY * j ,0)+_position);
}
}
for (auto i = 0 ; i < _segmentsX ; ++i) {
for (auto j = 0 ; j < _segmentsY ; ++j) {
add_face(i * (_segmentsY+1) + j, (i + 1) * (_segmentsY+1) + j, i * (_segmentsY+1) + j + 1);
add_face(i * (_segmentsY+1) + j + 1, (i + 1) * (_segmentsY+1) + j, (i + 1) * (_segmentsY+1) + j + 1);
}
}
triMesh_->update_normals();
emit updatedObject(newObject,UPDATE_ALL);
emit createBackup(newObject, "Original Object");
PluginFunctions::viewAll();
return newObject;
}
return -1;
}
int PrimitivesGeneratorPlugin::addTriangulatedPlaneBumpy(const Vector& _position ,
const double _sizeX , const double _sizeY ,
const int _segmentsX , const int _segmentsY )
{
int newObject = addTriMesh();
TriMeshObject* object;
if ( !PluginFunctions::getObject(newObject,object) ) {
emit log(LOGERR,"Unable to create new Object");
return -1;
} else {
object->setName( "Cube " + QString::number(newObject) );
triMesh_ = object->mesh();
triMesh_->clear();
vhandles_.resize( (_segmentsX+1) * (_segmentsY+1) );
for (auto i = 0 ; i < (_segmentsX + 1) ; ++i) {
for (auto j = 0 ; j < (_segmentsY + 1) ; ++j) {
const double x = _sizeX / _segmentsX * i - _sizeX / 2.0;
const double y = _sizeY / _segmentsY * j - _sizeY / 2.0;
const double z = sin( x * x) * cos( y * y) ;
vhandles_[ i * (_segmentsY + 1) + j ] = triMesh_->add_vertex(TriMesh::Point( x , y , z ) +_position);
}
}
for (auto i = 0 ; i < _segmentsX ; ++i) {
for (auto j = 0 ; j < _segmentsY ; ++j) {
add_face(i * (_segmentsY+1) + j, (i + 1) * (_segmentsY+1) + j, i * (_segmentsY+1) + j + 1);
add_face(i * (_segmentsY+1) + j + 1, (i + 1) * (_segmentsY+1) + j, (i + 1) * (_segmentsY+1) + j + 1);
}
}
triMesh_->update_normals();
emit updatedObject(newObject,UPDATE_ALL);
emit createBackup(newObject, "Original Object");
PluginFunctions::viewAll();
return newObject;
}
return -1;
}
int PrimitivesGeneratorPlugin::addTriangulatedPlanesNonManifold(const Vector& _position ,
const double _sizeX , const double _sizeY , const double _sizeZ ,
const int _segmentsX , const int _segmentsY , const int _segmentsZ )
{
int newObject = addTriMesh();
TriMeshObject* object;
if ( !PluginFunctions::getObject(newObject,object) ) {
emit log(LOGERR,"Unable to create new Object");
return -1;
} else {
object->setName( "Cube " + QString::number(newObject) );
triMesh_ = object->mesh();
triMesh_->clear();
vhandles_.resize( (_segmentsX+1) * (_segmentsY+1) );
// Adding the flat manifold component
for (auto i = 0 ; i < (_segmentsX + 1) ; ++i) {
for (auto j = 0 ; j < (_segmentsY + 1) ; ++j) {
vhandles_[ i * (_segmentsY + 1) + j ] = triMesh_->add_vertex(TriMesh::Point( _sizeX / _segmentsX * i , _sizeY / _segmentsY * j ,0)+_position);
}
}
for (auto i = 0 ; i < _segmentsX ; ++i) {
for (auto j = 0 ; j < _segmentsY ; ++j) {
add_face(i * (_segmentsY+1) + j, (i + 1) * (_segmentsY+1) + j, i * (_segmentsY+1) + j + 1);
add_face(i * (_segmentsY+1) + j + 1, (i + 1) * (_segmentsY+1) + j, (i + 1) * (_segmentsY+1) + j + 1);
}
}
vhandles_.clear();
vhandles_.resize( (_segmentsX+1) * (_segmentsY+1) );
// Adding the perpendicular component
for (auto j = 0 ; j < (_segmentsY + 1) ; ++j) {
for (auto k = 0 ; k < (_segmentsZ + 1) ; ++k) {
vhandles_[ j * (_segmentsY + 1) + k ] = triMesh_->add_vertex(TriMesh::Point(_sizeX / 2, _sizeY / _segmentsY * j , _sizeZ / _segmentsZ * k )+_position);
}
}
const int offset = (_segmentsX+1) * (_segmentsY+1);
for (auto i = 0 ; i < _segmentsY ; ++i) {
for (auto j = 0 ; j < _segmentsZ ; ++j) {
add_face(offset + i * (_segmentsZ+1) + j, offset + (i + 1) * (_segmentsZ+1) + j, offset + i * (_segmentsZ+1) + j + 1);
add_face(offset + i * (_segmentsZ+1) + j + 1, offset + (i + 1) * (_segmentsZ+1) + j, offset + (i + 1) * (_segmentsZ+1) + j + 1);
}
}
triMesh_->update_normals();
emit updatedObject(newObject,UPDATE_ALL);
emit createBackup(newObject, "Original Object");
PluginFunctions::viewAll();
return newObject;
}
return -1;
}
int PrimitivesGeneratorPlugin::addTriangulatedCube(const Vector& _position,const double _length) {
int newObject = addTriMesh();
......
......@@ -136,6 +136,18 @@ public slots:
int addCube(const Vector& _position = Vector(0.0,0.0,0.0),
const double _length = 2.0);
int addTriangulatedPlaneFlat(const Vector& _position = Vector(0.0,0.0,0.0),
const double _sizeX = 2.0, const double _sizeY = 2.0,
const int _segmentsX = 10, const int _segmentsY = 10 );
int addTriangulatedPlaneBumpy(const Vector& _position = Vector(0.0,0.0,0.0),
const double _sizeX = 10.0, const double _sizeY = 10.0,
const int _segmentsX = 200, const int _segmentsY = 200 );
int addTriangulatedPlanesNonManifold(const Vector& _position = Vector(0.0,0.0,0.0),
const double _sizeX = 2.0, const double _sizeY = 2.0, const double _sizeZ = 1.0,
const int _segmentsX = 50, const int _segmentsY = 50 , const int _segmentsZ = 50);
int addTriangulatedCube(const Vector& _position = Vector(0.0,0.0,0.0),
const double _length = 2.0);
......
......@@ -120,6 +120,33 @@ PYBIND11_EMBEDDED_MODULE(PrimitivesGenerator, m) {
py::arg(QCoreApplication::translate("PythonDocPrimitivesGenerator","Center position").toLatin1().data()) = Vector(0.0,0.0,0.0),
py::arg(QCoreApplication::translate("PythonDocPrimitivesGenerator","Length of each edge").toLatin1().data()) = 2.0);
generator.def("addTriangulatedPlaneFlat", &PrimitivesGeneratorPlugin::addTriangulatedPlaneFlat,
QCoreApplication::translate("PythonDocPrimitivesGenerator","Generates a flat triangular planar mesh in the z plane (ObjectId is returned)").toLatin1().data(),
py::arg(QCoreApplication::translate("PythonDocPrimitivesGenerator","Corner position").toLatin1().data()) = Vector(0.0,0.0,0.0),
py::arg(QCoreApplication::translate("PythonDocPrimitivesGenerator","Size in X direction").toLatin1().data()) = 2.0,
py::arg(QCoreApplication::translate("PythonDocPrimitivesGenerator","Size in Y direction").toLatin1().data()) = 2.0,
py::arg(QCoreApplication::translate("PythonDocPrimitivesGenerator","Number of linesegments in x direction").toLatin1().data()) = 10,
py::arg(QCoreApplication::translate("PythonDocPrimitivesGenerator","Number of linesegments in y direction").toLatin1().data()) = 10);
generator.def("addTriangulatedPlaneBumpy", &PrimitivesGeneratorPlugin::addTriangulatedPlaneBumpy,
QCoreApplication::translate("PythonDocPrimitivesGenerator","Generates a bumpy triangular planar mesh in the z plane (ObjectId is returned)").toLatin1().data(),
py::arg(QCoreApplication::translate("PythonDocPrimitivesGenerator","Corner position").toLatin1().data()) = Vector(0.0,0.0,0.0),
py::arg(QCoreApplication::translate("PythonDocPrimitivesGenerator","Size in X direction").toLatin1().data()) = 10.0,
py::arg(QCoreApplication::translate("PythonDocPrimitivesGenerator","Size in Y direction").toLatin1().data()) = 10.0,
py::arg(QCoreApplication::translate("PythonDocPrimitivesGenerator","Number of linesegments in x direction").toLatin1().data()) = 200,
py::arg(QCoreApplication::translate("PythonDocPrimitivesGenerator","Number of linesegments in y direction").toLatin1().data()) = 200);
generator.def("addTriangulatedPlanesNonManifold", &PrimitivesGeneratorPlugin::addTriangulatedPlanesNonManifold,
QCoreApplication::translate("PythonDocPrimitivesGenerator","Generates two perpendicular planes in a non manifold config (ObjectId is returned)").toLatin1().data(),
py::arg(QCoreApplication::translate("PythonDocPrimitivesGenerator","Corner position").toLatin1().data()) = Vector(0.0,0.0,0.0),
py::arg(QCoreApplication::translate("PythonDocPrimitivesGenerator","Size in X direction").toLatin1().data()) = 2.0,
py::arg(QCoreApplication::translate("PythonDocPrimitivesGenerator","Size in Y direction").toLatin1().data()) = 2.0,
py::arg(QCoreApplication::translate("PythonDocPrimitivesGenerator","Size in Z direction").toLatin1().data()) = 1.0,
py::arg(QCoreApplication::translate("PythonDocPrimitivesGenerator","Number of linesegments in x direction").toLatin1().data()) = 50,
py::arg(QCoreApplication::translate("PythonDocPrimitivesGenerator","Number of linesegments in y direction").toLatin1().data()) = 50,
py::arg(QCoreApplication::translate("PythonDocPrimitivesGenerator","Number of linesegments in y direction").toLatin1().data()) = 50);
generator.def("addIcosahedron", &PrimitivesGeneratorPlugin::addIcosahedron,
QCoreApplication::translate("PythonDocPrimitivesGenerator","Generates an Icosahedron (ObjectId is returned)").toLatin1().data(),
py::arg(QCoreApplication::translate("PythonDocPrimitivesGenerator","Center position").toLatin1().data()) = Vector(0.0,0.0,0.0),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment