Commit 14c5e091 authored by Jan Möbius's avatar Jan Möbius

Use a hash map to cash the target objects to avoid linear time lookup for the targets

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@15138 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 5afe85e1
......@@ -69,6 +69,14 @@
//== IMPLEMENTATION ==========================================================
InfoMeshObjectPlugin::InfoMeshObjectPlugin() :
info_(0),
infoBar_(0)
{
}
void InfoMeshObjectPlugin::initializePlugin() {
if ( OpenFlipper::Options::gui()) {
......@@ -789,76 +797,113 @@ bool InfoMeshObjectPlugin::getEdgeLengths(int _id, double &min, double &max, dou
return false;
}
////------------------------------------------------------------------------------
void InfoMeshObjectPlugin::addedEmptyObject(int _id) {
BaseObject* object;
PluginFunctions::getObject(_id,object);
if( object ) {
if ( (object->dataType() == DATA_TRIANGLE_MESH || object->dataType() == DATA_POLY_MESH) &&
object->target()
)
targetMeshes_.insert(_id);
} else {
std::cerr << "MeshObject Info Plugin: Unable to get Object after adding!" << std::endl;
}
}
//------------------------------------------------------------------------------
void InfoMeshObjectPlugin::objectDeleted(int _id) {
BaseObject* object;
PluginFunctions::getObject(_id,object);
if( object ) {
if ( object->dataType() == DATA_TRIANGLE_MESH || object->dataType() == DATA_POLY_MESH) {
QSet<int>::iterator iter = targetMeshes_.find(_id);
if ( iter != targetMeshes_.end() ) {
targetMeshes_.erase(iter);
}
}
} else {
std::cerr << "MeshObject Info Plugin: Unable to get Object after adding!" << std::endl;
}
}
//------------------------------------------------------------------------------
void InfoMeshObjectPlugin::slotObjectUpdated( int /*_identifier*/ , const UpdateType& _type){
void InfoMeshObjectPlugin::slotObjectUpdated( int _identifier , const UpdateType& _type){
if ( !infoBar_ ) {
return;
}
if ( (PluginFunctions::objectCount() == 1) || (PluginFunctions::targetCount() == 1) ){
if ( targetMeshes_.count() == 1) {
BaseObjectData* object;
PluginFunctions::getObject((*targetMeshes_.begin()),object);
if( object ) {
if (object->dataType(DATA_TRIANGLE_MESH)){
// This block is only interesting for topology changes
if ( ! _type.contains(UPDATE_TOPOLOGY) ) {
return;
}
TriMesh* mesh = PluginFunctions::triMesh(object);
bool found = false;
PluginFunctions::IteratorRestriction restriction;
if ( PluginFunctions::targetCount() == 1 )
restriction = PluginFunctions::TARGET_OBJECTS;
else
restriction = PluginFunctions::ALL_OBJECTS;
for ( PluginFunctions::ObjectIterator o_it(restriction,DataType( DATA_TRIANGLE_MESH | DATA_POLY_MESH )) ;
o_it != PluginFunctions::objectsEnd(); ++o_it) {
if (o_it->dataType(DATA_TRIANGLE_MESH)){
TriMesh* mesh = PluginFunctions::triMesh(*o_it);
infoBar_->vertices->setText( QLocale::system().toString( mesh->n_vertices() ) );
infoBar_->edges->setText( QLocale::system().toString( mesh->n_edges() ) );
infoBar_->faces->setText( QLocale::system().toString( mesh->n_faces() ) );
infoBar_->showCounts();
return;
}
if (o_it->dataType(DATA_POLY_MESH)){
PolyMesh* mesh = PluginFunctions::polyMesh(*o_it);
if (object->dataType(DATA_POLY_MESH)){
PolyMesh* mesh = PluginFunctions::polyMesh(object);
infoBar_->vertices->setText( QLocale::system().toString( mesh->n_vertices() ) );
infoBar_->edges->setText( QLocale::system().toString( mesh->n_edges() ) );
infoBar_->faces->setText( QLocale::system().toString( mesh->n_faces() ) );
infoBar_->showCounts();
return;
}
found = true;
}
if (found)
infoBar_->showCounts();
else
infoBar_->hideCounts();
} else {
if ( PluginFunctions::targetCount() > 0 )
// Display only count information
if ( PluginFunctions::targetCount() > 0 ) {
infoBar_->showTargetCount( PluginFunctions::targetCount() );
else
} else
infoBar_->hideCounts();
}
}
//------------------------------------------------------------------------------
void InfoMeshObjectPlugin::slotObjectSelectionChanged( int _identifier ){
BaseObject* object;
PluginFunctions::getObject(_identifier,object);
if( object ) {
if ( object->dataType() == DATA_TRIANGLE_MESH || object->dataType() == DATA_POLY_MESH) {
if ( ! object->target() ) {
QSet<int>::iterator iter = targetMeshes_.find(_identifier);
if ( iter != targetMeshes_.end() )
targetMeshes_.erase(iter);
} else
targetMeshes_.insert(_identifier);
}
} else {
std::cerr << "MeshObject Info Plugin: Unable to get Object after adding!" << std::endl;
}
slotObjectUpdated( _identifier , UPDATE_ALL );
}
//------------------------------------------------------------------------------
void InfoMeshObjectPlugin::slotAllCleared(){
targetMeshes_.clear();
if ( infoBar_ )
infoBar_->hideCounts();
}
......
......@@ -59,6 +59,7 @@
#include <OpenFlipper/BasePlugin/StatusbarInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
#include <OpenFlipper/common/Types.hh>
#include <ObjectTypes/PolyMesh/PolyMesh.hh>
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
......@@ -73,13 +74,14 @@
Plugin to visualize information about objects in the scene
*/
class InfoMeshObjectPlugin : public QObject, BaseInterface, InformationInterface, LoggingInterface, StatusbarInterface
class InfoMeshObjectPlugin : public QObject, BaseInterface, InformationInterface, LoggingInterface, StatusbarInterface, LoadSaveInterface
{
Q_OBJECT
Q_INTERFACES(BaseInterface)
Q_INTERFACES(InformationInterface)
Q_INTERFACES(LoggingInterface)
Q_INTERFACES(StatusbarInterface)
Q_INTERFACES(LoadSaveInterface)
signals:
......@@ -95,6 +97,7 @@ class InfoMeshObjectPlugin : public QObject, BaseInterface, InformationInterface
void addWidgetToStatusbar(QWidget* _widget);
private slots :
// BaseInterface
void initializePlugin();
void pluginsInitialized();
......@@ -102,6 +105,11 @@ class InfoMeshObjectPlugin : public QObject, BaseInterface, InformationInterface
void slotObjectSelectionChanged( int _identifier );
void slotAllCleared();
//LoadSaveInterface
void addedEmptyObject(int _id);
void objectDeleted(int _id);
void noguiSupported( ) {} ;
// InformationInterface
......@@ -110,23 +118,25 @@ class InfoMeshObjectPlugin : public QObject, BaseInterface, InformationInterface
public :
// default constructor
InfoMeshObjectPlugin(): info_(0),infoBar_(0) {};
// default constructor
InfoMeshObjectPlugin();
// default destructor
~InfoMeshObjectPlugin() {};
// default destructor
~InfoMeshObjectPlugin() {};
/// Name of the Plugin
QString name(){ return (QString("InfoMeshObject")); };
/// Name of the Plugin
QString name(){ return (QString("InfoMeshObject")); };
/// Description of the Plugin
QString description() { return (QString(tr("Provides Information on Mesh Objects"))); };
/// Description of the Plugin
QString description() { return (QString(tr("Provides Information on Mesh Objects"))); };
private :
InfoDialog* info_;
InfoBar* infoBar_;
QSet<int> targetMeshes_;
template< class MeshT >
void printMeshInfo( MeshT* _mesh, int _id, unsigned int _face, ACG::Vec3d& _hitPoint );
......
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