Commit c5ecef9b authored by Martin Schultz's avatar Martin Schultz

* added more boundingbox operations to move plugin by refactoring button callbacks

TODO: change icons of the new buttons and remove redundant functionality from align meshes plugin
parent 68c19c30
Pipeline #367 passed with stage
...@@ -347,6 +347,14 @@ void MovePlugin::initializePlugin() ...@@ -347,6 +347,14 @@ void MovePlugin::initializePlugin()
tool_->unifyBoundingBoxDiagonal->setWhatsThis(QString(tr("Rescale objects such that its bounding box diagonal has length one.")) tool_->unifyBoundingBoxDiagonal->setWhatsThis(QString(tr("Rescale objects such that its bounding box diagonal has length one."))
+whatsThis.generateLink("unifyBB")); +whatsThis.generateLink("unifyBB"));
connect(tool_->unifyBoundingBoxLongest,SIGNAL(clicked() ),this,SLOT(slotUnifyBoundingBoxLongestAxis()));
tool_->unifyBoundingBoxLongest->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "unifyBB.png") );
tool_->unifyBoundingBoxLongest->setIconSize(QSize(48,48));
connect(tool_->unifyBoundingBoxAll,SIGNAL(clicked() ),this,SLOT(slotUnifyBoundingBoxAllAxis()));
tool_->unifyBoundingBoxAll->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "unifyBB.png") );
tool_->unifyBoundingBoxAll->setIconSize(QSize(48,48));
lastActiveManipulator_ = -1; lastActiveManipulator_ = -1;
toolIcon_ = new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"move-toolBox.png"); toolIcon_ = new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"move-toolBox.png");
...@@ -1845,6 +1853,21 @@ void MovePlugin::slotMoveToOrigin() { ...@@ -1845,6 +1853,21 @@ void MovePlugin::slotMoveToOrigin() {
* *
*/ */
void MovePlugin::slotUnifyBoundingBoxDiagonal() void MovePlugin::slotUnifyBoundingBoxDiagonal()
{
unifyBoundingBox(MovePlugin::DIAGONAL);
}
void MovePlugin::slotUnifyBoundingBoxLongestAxis()
{
unifyBoundingBox((MovePlugin::LONGEST_AXIS));
}
void MovePlugin::slotUnifyBoundingBoxAllAxis()
{
unifyBoundingBox(MovePlugin::ALL_AXIS);
}
void MovePlugin::unifyBoundingBox(Unificationtype u)
{ {
bool useCommonBB = false; bool useCommonBB = false;
ACG::Vec3d bb_min = ACG::Vec3d(FLT_MAX,FLT_MAX,FLT_MAX); ACG::Vec3d bb_min = ACG::Vec3d(FLT_MAX,FLT_MAX,FLT_MAX);
...@@ -1912,37 +1935,37 @@ void MovePlugin::slotUnifyBoundingBoxDiagonal() ...@@ -1912,37 +1935,37 @@ void MovePlugin::slotUnifyBoundingBoxDiagonal()
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) { for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
if ( useCommonBB ) { if ( useCommonBB ) {
if ( o_it->dataType( DATA_TRIANGLE_MESH ) ) if ( o_it->dataType( DATA_TRIANGLE_MESH ) )
unifyBBDiag(*PluginFunctions::triMesh(*o_it),bb_min,bb_max); unifyBB(*PluginFunctions::triMesh(*o_it),bb_min,bb_max, u);
else if ( o_it->dataType( DATA_POLY_MESH ) ) else if ( o_it->dataType( DATA_POLY_MESH ) )
unifyBBDiag(*PluginFunctions::polyMesh(*o_it),bb_min,bb_max); unifyBB(*PluginFunctions::polyMesh(*o_it),bb_min,bb_max, u);
#ifdef ENABLE_TSPLINEMESH_SUPPORT #ifdef ENABLE_TSPLINEMESH_SUPPORT
else if ( o_it->dataType( DATA_TSPLINE_MESH ) ) else if ( o_it->dataType( DATA_TSPLINE_MESH ) )
unifyBBDiag(*PluginFunctions::tsplineMesh(*o_it),bb_min,bb_max); unifyBB(*PluginFunctions::tsplineMesh(*o_it),bb_min,bb_max, u);
#endif #endif
#ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT #ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
else if ( o_it->dataType( DATA_HEXAHEDRAL_MESH ) ) else if ( o_it->dataType( DATA_HEXAHEDRAL_MESH ) )
unifyBBDiagVolumeMesh(*PluginFunctions::hexahedralMesh(*o_it),(PluginFunctions::hexahedralMeshObject(*o_it)->normals()),bb_min,bb_max); unifyBBVolumeMesh(*PluginFunctions::hexahedralMesh(*o_it),(PluginFunctions::hexahedralMeshObject(*o_it)->normals()),bb_min,bb_max, u);
#endif #endif
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
else if ( o_it->dataType( DATA_POLYHEDRAL_MESH ) ) else if ( o_it->dataType( DATA_POLYHEDRAL_MESH ) )
unifyBBDiagVolumeMesh(*PluginFunctions::polyhedralMesh(*o_it),(PluginFunctions::polyhedralMeshObject(*o_it)->normals()),bb_min,bb_max); unifyBBVolumeMesh(*PluginFunctions::polyhedralMesh(*o_it),(PluginFunctions::polyhedralMeshObject(*o_it)->normals()),bb_min,bb_max, u);
#endif #endif
} else { } else {
if ( o_it->dataType( DATA_TRIANGLE_MESH ) ) if ( o_it->dataType( DATA_TRIANGLE_MESH ) )
unifyBBDiag(*PluginFunctions::triMesh(*o_it)); unifyBB(*PluginFunctions::triMesh(*o_it), u);
else if ( o_it->dataType( DATA_POLY_MESH ) ) else if ( o_it->dataType( DATA_POLY_MESH ) )
unifyBBDiag(*PluginFunctions::polyMesh(*o_it)); unifyBB(*PluginFunctions::polyMesh(*o_it), u);
#ifdef ENABLE_TSPLINEMESH_SUPPORT #ifdef ENABLE_TSPLINEMESH_SUPPORT
else if ( o_it->dataType( DATA_TSPLINE_MESH ) ) else if ( o_it->dataType( DATA_TSPLINE_MESH ) )
unifyBBDiag(*PluginFunctions::tsplineMesh(*o_it)); unifyBB(*PluginFunctions::tsplineMesh(*o_it), u);
#endif #endif
#ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT #ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
else if ( o_it->dataType( DATA_HEXAHEDRAL_MESH ) ) else if ( o_it->dataType( DATA_HEXAHEDRAL_MESH ) )
unifyBBDiagVolumeMesh(*PluginFunctions::hexahedralMesh(*o_it),(PluginFunctions::hexahedralMeshObject(*o_it)->normals())); unifyBBVolumeMesh(*PluginFunctions::hexahedralMesh(*o_it),(PluginFunctions::hexahedralMeshObject(*o_it)->normals()), u);
#endif #endif
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
else if ( o_it->dataType( DATA_POLYHEDRAL_MESH ) ) else if ( o_it->dataType( DATA_POLYHEDRAL_MESH ) )
unifyBBDiagVolumeMesh(*PluginFunctions::polyhedralMesh(*o_it),(PluginFunctions::polyhedralMeshObject(*o_it)->normals())); unifyBBVolumeMesh(*PluginFunctions::polyhedralMesh(*o_it),(PluginFunctions::polyhedralMeshObject(*o_it)->normals()), u);
#endif #endif
} }
...@@ -2288,7 +2311,7 @@ void MovePlugin::getBBVolumeMesh( VolumeMeshT& _mesh, ACG::Vec3d& _bb_min, ACG:: ...@@ -2288,7 +2311,7 @@ void MovePlugin::getBBVolumeMesh( VolumeMeshT& _mesh, ACG::Vec3d& _bb_min, ACG::
* @param _normalAttrib the normal attribute * @param _normalAttrib the normal attribute
*/ */
template< typename VolumeMeshT > template< typename VolumeMeshT >
void MovePlugin::unifyBBDiagVolumeMesh(VolumeMeshT& _mesh, OpenVolumeMesh::NormalAttrib<VolumeMeshT>& _normalAttrib) void MovePlugin::unifyBBVolumeMesh(VolumeMeshT& _mesh, OpenVolumeMesh::NormalAttrib<VolumeMeshT>& _normalAttrib, Unificationtype u)
{ {
// no vertices? // no vertices?
if( _mesh.n_vertices() == 0) return; if( _mesh.n_vertices() == 0) return;
...@@ -2296,24 +2319,42 @@ void MovePlugin::unifyBBDiagVolumeMesh(VolumeMeshT& _mesh, OpenVolumeMesh::Norma ...@@ -2296,24 +2319,42 @@ void MovePlugin::unifyBBDiagVolumeMesh(VolumeMeshT& _mesh, OpenVolumeMesh::Norma
ACG::Vec3d bb_min, bb_max; ACG::Vec3d bb_min, bb_max;
getBBVolumeMesh( _mesh, bb_min, bb_max ); getBBVolumeMesh( _mesh, bb_min, bb_max );
unifyBBDiagVolumeMesh( _mesh, _normalAttrib, bb_min, bb_max ); unifyBBVolumeMesh( _mesh, _normalAttrib, bb_min, bb_max, u );
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/** \brief Scales object such that bounding box diagonal has unit length /** \brief Scales object such that bounding box to have unit length as specified by parameter u
* *
* @param _mesh the mesh * @param _mesh the mesh
* @param _normalAttrib the normal attribute * @param _normalAttrib the normal attribute
* @param _bb_min Lower left corner of bounding box * @param _bb_min Lower left corner of bounding box
* @param _bb_max Upper right corner of bounding box * @param _bb_max Upper right corner of bounding box
* @param u the unification type (Diagonal, longest axis, all axis)
*/ */
template< typename VolumeMeshT > template< typename VolumeMeshT >
void MovePlugin::unifyBBDiagVolumeMesh( VolumeMeshT& _mesh, OpenVolumeMesh::NormalAttrib<VolumeMeshT>& _normalAttrib, ACG::Vec3d& _bb_min, ACG::Vec3d& _bb_max ) void MovePlugin::unifyBBVolumeMesh( VolumeMeshT& _mesh, OpenVolumeMesh::NormalAttrib<VolumeMeshT>& _normalAttrib, ACG::Vec3d& _bb_min, ACG::Vec3d& _bb_max, Unificationtype u)
{ {
ACG::Vec3d bb_center = 0.5 * (_bb_min + _bb_max) ; ACG::Vec3d bb_center = 0.5 * (_bb_min + _bb_max) ;
ACG::Vec3d bb_diagonal = _bb_max-_bb_min;
double bb_longestAxis = bb_diagonal.max();
ACG::Vec3d scale;
switch(u)
{
case MovePlugin::DIAGONAL :
scale = ACG::Vec3d(1.0/(_bb_max-_bb_min).norm());
break;
case MovePlugin::LONGEST_AXIS :
scale = ACG::Vec3d(1.0/(bb_longestAxis));
break;
case MovePlugin::ALL_AXIS :
scale = ACG::Vec3d(ACG::Vec3d(1.0)/bb_diagonal);
break;
default:
scale = ACG::Vec3d(1.0/(_bb_max-_bb_min).norm());
}
double scale = 1.0/(_bb_max-_bb_min).norm();
for( OpenVolumeMesh::VertexIter v_it = _mesh.vertices_begin(); v_it!=_mesh.vertices_end(); ++v_it) for( OpenVolumeMesh::VertexIter v_it = _mesh.vertices_begin(); v_it!=_mesh.vertices_end(); ++v_it)
_mesh.set_vertex(*v_it, (_mesh.vertex(*v_it) - bb_center) * scale + bb_center); _mesh.set_vertex(*v_it, (_mesh.vertex(*v_it) - bb_center) * scale + bb_center);
...@@ -2325,12 +2366,13 @@ void MovePlugin::unifyBBDiagVolumeMesh( VolumeMeshT& _mesh, OpenVolumeMesh::Norm ...@@ -2325,12 +2366,13 @@ void MovePlugin::unifyBBDiagVolumeMesh( VolumeMeshT& _mesh, OpenVolumeMesh::Norm
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/** \brief scale mesh to have a boundingboxdiagonal of one /** \brief scale mesh to have a boundingbox axis('s) or diagonal of one
* *
* @param _mesh the mesh * @param _mesh the mesh
* @param u the unification type (Diagonal, longest axis, all axis)
*/ */
template< typename MeshT > template< typename MeshT >
void MovePlugin::unifyBBDiag(MeshT& _mesh ) void MovePlugin::unifyBB(MeshT& _mesh , Unificationtype u)
{ {
typename MeshT::VertexIter v_it = _mesh.vertices_begin(); typename MeshT::VertexIter v_it = _mesh.vertices_begin();
typename MeshT::VertexIter v_end = _mesh.vertices_end(); typename MeshT::VertexIter v_end = _mesh.vertices_end();
...@@ -2348,8 +2390,24 @@ void MovePlugin::unifyBBDiag(MeshT& _mesh ) ...@@ -2348,8 +2390,24 @@ void MovePlugin::unifyBBDiag(MeshT& _mesh )
} }
typename MeshT::Point bb_center = 0.5 * (bb_min + bb_max) ; typename MeshT::Point bb_center = 0.5 * (bb_min + bb_max) ;
ACG::Vec3d bb_diagonal = bb_max-bb_min;
typename MeshT::Scalar bb_longestAxis = bb_diagonal.max();
typename MeshT::Scalar scale = 1.0/(bb_max-bb_min).norm(); ACG::Vec3d scale;
switch(u)
{
case MovePlugin::DIAGONAL :
scale = ACG::Vec3d(1.0/(bb_max-bb_min).norm());
break;
case MovePlugin::LONGEST_AXIS :
scale = ACG::Vec3d(1.0 / bb_longestAxis);
break;
case MovePlugin::ALL_AXIS :
scale = ACG::Vec3d(ACG::Vec3d(1.0)/bb_diagonal);
break;
default:
scale = ACG::Vec3d(1.0/(bb_max-bb_min).norm());
}
for( v_it = _mesh.vertices_begin(); v_it!=v_end; ++v_it) for( v_it = _mesh.vertices_begin(); v_it!=v_end; ++v_it)
{ {
...@@ -2388,19 +2446,35 @@ void MovePlugin::getBB( MeshT& _mesh, ACG::Vec3d& _bb_min, ACG::Vec3d& _bb_max ...@@ -2388,19 +2446,35 @@ void MovePlugin::getBB( MeshT& _mesh, ACG::Vec3d& _bb_min, ACG::Vec3d& _bb_max
} }
/** \brief Scales object such that bounding box diagonal has unit length /** \brief Scales object such that bounding box axis('s) or diagonal have unit length
* *
* @param _mesh the mesh * @param _mesh the mesh
* @param _bb_min Lower left corner of bounding box * @param _bb_min Lower left corner of bounding box
* @param _bb_max Upper right corner of bounding box * @param _bb_max Upper right corner of bounding box
* @param u the unification type (Diagonal, longest axis, all axis)
*/ */
template< typename MeshT > template< typename MeshT >
void MovePlugin::unifyBBDiag( MeshT& _mesh, ACG::Vec3d& _bb_min, ACG::Vec3d& _bb_max ) void MovePlugin::unifyBB(MeshT& _mesh, ACG::Vec3d& _bb_min, ACG::Vec3d& _bb_max , Unificationtype u)
{ {
typename MeshT::Point bb_center = 0.5 * (_bb_min + _bb_max) ; typename MeshT::Point bb_center = 0.5 * (_bb_min + _bb_max) ;
ACG::Vec3d bb_diagonal = _bb_max-_bb_min;
typename MeshT::Scalar scale = 1.0/(_bb_max-_bb_min).norm(); typename MeshT::Scalar bb_longestAxis = bb_diagonal.max();
ACG::Vec3d scale;
switch(u)
{
case MovePlugin::DIAGONAL :
scale = ACG::Vec3d(1.0/(_bb_max-_bb_min).norm());
break;
case MovePlugin::LONGEST_AXIS :
scale = ACG::Vec3d(1.0 / bb_longestAxis);
break;
case MovePlugin::ALL_AXIS :
scale = ACG::Vec3d(ACG::Vec3d(1.0)/bb_diagonal);
break;
default:
scale = ACG::Vec3d(1.0/(_bb_max-_bb_min).norm());
}
typename MeshT::VertexIter v_it; typename MeshT::VertexIter v_it;
......
...@@ -202,6 +202,13 @@ public: ...@@ -202,6 +202,13 @@ public:
int axisA_; int axisA_;
int axisB_; int axisB_;
enum Unificationtype
{
DIAGONAL,
LONGEST_AXIS,
ALL_AXIS
};
private slots: private slots:
/// Position of manipulator in tab changed /// Position of manipulator in tab changed
...@@ -237,6 +244,12 @@ public: ...@@ -237,6 +244,12 @@ public:
/// Scale Boundingbox Diagonal to unit size /// Scale Boundingbox Diagonal to unit size
void slotUnifyBoundingBoxDiagonal(); void slotUnifyBoundingBoxDiagonal();
/// Scale Boundingbox longest axis to unit size (keeps aspect ratio)
void slotUnifyBoundingBoxLongestAxis();
/// Scale all Boundingbox axis to unit size
void slotUnifyBoundingBoxAllAxis();
void slotEnableSelectionMode(); void slotEnableSelectionMode();
void slotEnableObjectMode(); void slotEnableObjectMode();
...@@ -338,6 +351,8 @@ public: ...@@ -338,6 +351,8 @@ public:
private: private:
void unifyBoundingBox(Unificationtype u);
///Transform a mesh with the given transformation matrix ///Transform a mesh with the given transformation matrix
template< typename MeshT > template< typename MeshT >
void transformMesh(ACG::Matrix4x4d _mat , MeshT& _mesh ); void transformMesh(ACG::Matrix4x4d _mat , MeshT& _mesh );
...@@ -368,11 +383,11 @@ public: ...@@ -368,11 +383,11 @@ public:
/// scale volume mesh to have a boundingboxdiagonal of one /// scale volume mesh to have a boundingboxdiagonal of one
template< typename VolumeMeshT > template< typename VolumeMeshT >
void unifyBBDiagVolumeMesh(VolumeMeshT& _mesh, OpenVolumeMesh::NormalAttrib<VolumeMeshT>& _normalAttrib); void unifyBBVolumeMesh(VolumeMeshT& _mesh, OpenVolumeMesh::NormalAttrib<VolumeMeshT>& _normalAttrib, Unificationtype u = MovePlugin::DIAGONAL);
/// Scales volume mesh such that bounding box diagonal has unit length /// Scales volume mesh such that bounding box diagonal has unit length
template< typename VolumeMeshT > template< typename VolumeMeshT >
void unifyBBDiagVolumeMesh( VolumeMeshT& _mesh, OpenVolumeMesh::NormalAttrib<VolumeMeshT>& _normalAttrib, ACG::Vec3d& _bb_min, ACG::Vec3d& _bb_max ); void unifyBBVolumeMesh( VolumeMeshT& _mesh, OpenVolumeMesh::NormalAttrib<VolumeMeshT>& _normalAttrib, ACG::Vec3d& _bb_min, ACG::Vec3d& _bb_max, Unificationtype u = MovePlugin::DIAGONAL );
#endif #endif
/** Get the Matrix of the last active Manipulator ( Identity if not found or hidden Manipulator ) /** Get the Matrix of the last active Manipulator ( Identity if not found or hidden Manipulator )
...@@ -390,7 +405,7 @@ public: ...@@ -390,7 +405,7 @@ public:
/// scale mesh to have a boundingboxdiagonal of one /// scale mesh to have a boundingboxdiagonal of one
template< typename MeshT > template< typename MeshT >
void unifyBBDiag(MeshT& _mesh ); void unifyBB(MeshT& _mesh , Unificationtype u = MovePlugin::DIAGONAL);
/// get bounding box diagonal of a mesh /// get bounding box diagonal of a mesh
template< typename MeshT > template< typename MeshT >
...@@ -398,7 +413,7 @@ public: ...@@ -398,7 +413,7 @@ public:
/// Scales object such that bounding box diagonal has unit length /// Scales object such that bounding box diagonal has unit length
template< typename MeshT > template< typename MeshT >
void unifyBBDiag( MeshT& _mesh, ACG::Vec3d& _bb_min, ACG::Vec3d& _bb_max ); void unifyBB( MeshT& _mesh, ACG::Vec3d& _bb_min, ACG::Vec3d& _bb_max, Unificationtype u = MovePlugin::DIAGONAL );
/// Size for the manipulators /// Size for the manipulators
double manip_size_; double manip_size_;
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>1</number>
</property> </property>
<widget class="QWidget" name="tab"> <widget class="QWidget" name="tab">
<attribute name="title"> <attribute name="title">
...@@ -89,6 +89,32 @@ p, li { white-space: pre-wrap; } ...@@ -89,6 +89,32 @@ p, li { white-space: pre-wrap; }
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="unifyBoundingBoxLongest">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Normalize Bounding box longest axis of objects&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="whatsThis">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Normalize Bounding box longest axis of objects&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Unify Boundingbox Longest Axis</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="unifyBoundingBoxAll">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Normalize Bounding box all axis of objects&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="whatsThis">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Normalize Bounding box all axis of objects&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Unify Boundingbox All Axis</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</widget> </widget>
......
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