Commit 095b2c46 authored by Jan Möbius's avatar Jan Möbius

Move Plugin ask if common bounding box should be used when moving objects

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@6764 383ad7c9-94d9-4d36-a494-682f7c89f535
parent ed17b644
......@@ -300,6 +300,7 @@ void MovePlugin::slotKeyEvent (QKeyEvent* _event)
#include <qt4/QtGui/QDialog>
#include <qt4/QtGui/qmessagebox.h>
#include "../ACG/Math/VectorT.hh"
//------------------------------------------------------------------------------
void MovePlugin::slotKeyReleaseEvent (QKeyEvent* _event)
......@@ -1085,23 +1086,26 @@ void MovePlugin::slotMoveToOrigin() {
useCommonCOG = ( button == QMessageBox::Yes );
double count = 0.0;
// Compute cog for all objects
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
if ( o_it->dataType( DATA_TRIANGLE_MESH )) {
TriMesh& mesh = *PluginFunctions::triMesh(*o_it);
cog += MeshInfo::cog(mesh);
++count;
}
if ( useCommonCOG ) {
// Compute cog for all objects
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
if ( o_it->dataType( DATA_TRIANGLE_MESH )) {
TriMesh& mesh = *PluginFunctions::triMesh(*o_it);
cog += MeshInfo::cog(mesh);
++count;
}
if ( o_it->dataType( DATA_POLY_MESH )) {
PolyMesh& mesh = *PluginFunctions::polyMesh(*o_it);
cog += MeshInfo::cog(mesh);
++count;
if ( o_it->dataType( DATA_POLY_MESH )) {
PolyMesh& mesh = *PluginFunctions::polyMesh(*o_it);
cog += MeshInfo::cog(mesh);
++count;
}
}
cog = cog / count;
}
cog = cog / count;
}
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
......@@ -1149,13 +1153,56 @@ void MovePlugin::slotMoveToOrigin() {
*/
void MovePlugin::slotUnifyBoundingBoxDiagonal()
{
bool useCommonBB = false;
ACG::Vec3d bb_min = ACG::Vec3d(FLT_MAX,FLT_MAX,FLT_MAX);
ACG::Vec3d bb_max = ACG::Vec3d(FLT_MIN,FLT_MIN,FLT_MIN);
if ( PluginFunctions::targetCount() > 1 ) {
QMessageBox::StandardButton button = QMessageBox::question( 0, tr("Use common BB?"), tr("Should the targets be scaled depending on their common Bounding Box?"),QMessageBox::Yes|QMessageBox::No);
useCommonBB = ( button == QMessageBox::Yes );
double count = 0.0;
if ( useCommonBB ) {
// Compute cog for all objects
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
ACG::Vec3d bb_min_tmp(0.0,0.0,0.0);
ACG::Vec3d bb_max_tmp(0.0,0.0,0.0);
if ( o_it->dataType( DATA_TRIANGLE_MESH )) {
TriMesh& mesh = *PluginFunctions::triMesh(*o_it);
getBB(mesh,bb_min_tmp,bb_max_tmp);
bb_min.minimize(bb_min_tmp);
bb_max.maximize(bb_max_tmp);
}
if ( o_it->dataType( DATA_POLY_MESH )) {
PolyMesh& mesh = *PluginFunctions::polyMesh(*o_it);
getBB(mesh,bb_min_tmp,bb_max_tmp);
bb_min.minimize(bb_min_tmp);
bb_max.maximize(bb_max_tmp);
}
}
}
}
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
if ( useCommonBB ) {
if ( o_it->dataType( DATA_TRIANGLE_MESH ) )
unifyBBDiag(*PluginFunctions::triMesh(*o_it),bb_min,bb_max);
else if ( o_it->dataType( DATA_POLY_MESH ) )
unifyBBDiag(*PluginFunctions::polyMesh(*o_it),bb_min,bb_max);
} else {
if ( o_it->dataType( DATA_TRIANGLE_MESH ) )
unifyBBDiag(*PluginFunctions::triMesh(*o_it));
else if ( o_it->dataType( DATA_POLY_MESH ) )
unifyBBDiag(*PluginFunctions::polyMesh(*o_it));
unifyBBDiag(*PluginFunctions::polyMesh(*o_it));
}
emit updatedObject( o_it->id() );
emit updatedObject( o_it->id() );
}
......@@ -1398,6 +1445,57 @@ void MovePlugin::unifyBBDiag(MeshT& _mesh )
}
/** \brief Get the bounding box of a mesh
*
* @param _mesh the mesh
* @param _bb_min Lower left corner of bounding box
* @param _bb_max Upper right corner of bounding box
*/
template< typename MeshT >
void MovePlugin::getBB( MeshT& _mesh, ACG::Vec3d& _bb_min, ACG::Vec3d& _bb_max )
{
typename MeshT::VertexIter v_it = _mesh.vertices_begin();
typename MeshT::VertexIter v_end = _mesh.vertices_end();
// no vertices?
if( v_it == v_end) return;
_bb_min = _mesh.point(v_it);
_bb_max = _mesh.point(v_it);
for(; v_it!=v_end; ++v_it)
{
_bb_min.minimize( _mesh.point(v_it));
_bb_max.maximize( _mesh.point(v_it));
}
}
/** \brief Scales object such that bounding box diagonal has unit length
*
* @param _mesh the mesh
* @param _bb_min Lower left corner of bounding box
* @param _bb_max Upper right corner of bounding box
*/
template< typename MeshT >
void MovePlugin::unifyBBDiag( MeshT& _mesh, ACG::Vec3d& _bb_min, ACG::Vec3d& _bb_max )
{
typename MeshT::VertexIter v_it = _mesh.vertices_begin();
typename MeshT::VertexIter v_end = _mesh.vertices_end();
typename MeshT::Point bb_center = 0.5 * (_bb_min + _bb_max) ;
typename MeshT::Scalar scale = 1.0/(_bb_max-_bb_min).norm();
for( v_it ; v_it!=v_end; ++v_it)
_mesh.point(v_it) = (_mesh.point(v_it) - bb_center) * scale + bb_center;
_mesh.update_normals();
}
//------------------------------------------------------------------------------
......
......@@ -295,6 +295,14 @@ class MovePlugin : public QObject, BaseInterface, MouseInterface, KeyInterface,
/// scale mesh to have a boundingboxdiagonal of one
template< typename MeshT >
void unifyBBDiag(MeshT& _mesh );
/// get bounding box diagonal of a mesh
template< typename MeshT >
void getBB( MeshT& _mesh, ACG::Vec3d& _bb_min, ACG::Vec3d& _bb_max );
/// Scales object such that bounding box diagonal has unit length
template< typename MeshT >
void unifyBBDiag( MeshT& _mesh, ACG::Vec3d& _bb_min, ACG::Vec3d& _bb_max );
/// Size for the manipulators
double manip_size_;
......
......@@ -118,126 +118,136 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../MovePlugin.cc" line="355"/>
<location filename="../MovePlugin.cc" line="356"/>
<source>moveObject called for unsupported Object Type</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../MovePlugin.cc" line="555"/>
<location filename="../MovePlugin.cc" line="580"/>
<location filename="../MovePlugin.cc" line="556"/>
<location filename="../MovePlugin.cc" line="581"/>
<source>Picking failed</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../MovePlugin.cc" line="641"/>
<location filename="../MovePlugin.cc" line="724"/>
<location filename="../MovePlugin.cc" line="731"/>
<location filename="../MovePlugin.cc" line="801"/>
<location filename="../MovePlugin.cc" line="943"/>
<location filename="../MovePlugin.cc" line="642"/>
<location filename="../MovePlugin.cc" line="725"/>
<location filename="../MovePlugin.cc" line="732"/>
<location filename="../MovePlugin.cc" line="802"/>
<location filename="../MovePlugin.cc" line="944"/>
<source>Wrong Format for X Coordinate</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../MovePlugin.cc" line="643"/>
<location filename="../MovePlugin.cc" line="726"/>
<location filename="../MovePlugin.cc" line="733"/>
<location filename="../MovePlugin.cc" line="803"/>
<location filename="../MovePlugin.cc" line="945"/>
<location filename="../MovePlugin.cc" line="644"/>
<location filename="../MovePlugin.cc" line="727"/>
<location filename="../MovePlugin.cc" line="734"/>
<location filename="../MovePlugin.cc" line="804"/>
<location filename="../MovePlugin.cc" line="946"/>
<source>Wrong Format for Y Coordinate</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../MovePlugin.cc" line="645"/>
<location filename="../MovePlugin.cc" line="728"/>
<location filename="../MovePlugin.cc" line="735"/>
<location filename="../MovePlugin.cc" line="805"/>
<location filename="../MovePlugin.cc" line="947"/>
<location filename="../MovePlugin.cc" line="646"/>
<location filename="../MovePlugin.cc" line="729"/>
<location filename="../MovePlugin.cc" line="736"/>
<location filename="../MovePlugin.cc" line="806"/>
<location filename="../MovePlugin.cc" line="948"/>
<source>Wrong Format for Z Coordinate</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../MovePlugin.cc" line="674"/>
<location filename="../MovePlugin.cc" line="699"/>
<location filename="../MovePlugin.cc" line="675"/>
<location filename="../MovePlugin.cc" line="700"/>
<source>X Direction</source>
<translation type="unfinished">X Richtung</translation>
</message>
<message>
<location filename="../MovePlugin.cc" line="675"/>
<location filename="../MovePlugin.cc" line="700"/>
<location filename="../MovePlugin.cc" line="676"/>
<location filename="../MovePlugin.cc" line="701"/>
<source>Y Direction</source>
<translation type="unfinished">Y Richtung</translation>
</message>
<message>
<location filename="../MovePlugin.cc" line="676"/>
<location filename="../MovePlugin.cc" line="701"/>
<location filename="../MovePlugin.cc" line="677"/>
<location filename="../MovePlugin.cc" line="702"/>
<source>Z Direction</source>
<translation type="unfinished">Z Richtung</translation>
</message>
<message>
<location filename="../MovePlugin.cc" line="760"/>
<location filename="../MovePlugin.cc" line="761"/>
<source>The axes of the new direction have to be orthogonal</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../MovePlugin.cc" line="872"/>
<location filename="../MovePlugin.cc" line="873"/>
<source>TODO Project for multiple targets</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../MovePlugin.cc" line="875"/>
<location filename="../MovePlugin.cc" line="876"/>
<source>TODO Project for one target</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../MovePlugin.cc" line="950"/>
<location filename="../MovePlugin.cc" line="951"/>
<source>Wrong Format for Angle</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../MovePlugin.cc" line="1016"/>
<location filename="../MovePlugin.cc" line="1017"/>
<source>Wrong Format for factor 1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../MovePlugin.cc" line="1018"/>
<location filename="../MovePlugin.cc" line="1019"/>
<source>Wrong Format for factor 2</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../MovePlugin.cc" line="1020"/>
<location filename="../MovePlugin.cc" line="1021"/>
<source>Wrong Format for factor 3</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../MovePlugin.cc" line="1082"/>
<location filename="../MovePlugin.cc" line="1083"/>
<source>Use common COG?</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../MovePlugin.cc" line="1082"/>
<source>Should the targets be moved depending on their common cog or on their own?</source>
<location filename="../MovePlugin.cc" line="1083"/>
<source>Should the targets be moved depending on their common cog?</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../MovePlugin.cc" line="1161"/>
<source>Use common BB?</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../MovePlugin.cc" line="1161"/>
<source>Should the targets be scaled depending on their common Bounding Box?</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../MovePlugin.cc" line="1423"/>
<location filename="../MovePlugin.cc" line="1458"/>
<location filename="../MovePlugin.cc" line="1521"/>
<location filename="../MovePlugin.cc" line="1556"/>
<source>Enable Vertex Selection</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../MovePlugin.cc" line="1430"/>
<location filename="../MovePlugin.cc" line="1460"/>
<location filename="../MovePlugin.cc" line="1528"/>
<location filename="../MovePlugin.cc" line="1558"/>
<source>Enable Edge Selection</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../MovePlugin.cc" line="1433"/>
<location filename="../MovePlugin.cc" line="1462"/>
<location filename="../MovePlugin.cc" line="1531"/>
<location filename="../MovePlugin.cc" line="1560"/>
<source>Enable Face Selection</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../MovePlugin.cc" line="1445"/>
<location filename="../MovePlugin.cc" line="1543"/>
<source>Unable to connect to Selection-Plugin. MoveSelection will work on vertices only.</source>
<translation type="unfinished"></translation>
</message>
......
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