Commit 62072674 authored by Jan Möbius's avatar Jan Möbius
Browse files

Tobias: Update for splatcloud with the new property system

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@14928 383ad7c9-94d9-4d36-a494-682f7c89f535
parent c5e70df0
This diff is collapsed.
......@@ -87,16 +87,16 @@ class FilePTSPlugin : public QObject, BaseInterface, FileInterface, LoadSaveInte
signals:
// -- File Interface --
void openedFile( int _id );
void openedFile( int _objectId );
// -- LoadSave Interface --
void addEmptyObject( DataType _type, int &_id );
void deleteObject( int _id );
void updatedObject( int _id, const UpdateType &_type );
void addEmptyObject( DataType _type, int &_objectId );
void deleteObject( int _objectId );
void updatedObject( int _objectId, const UpdateType &_type );
//-- Logging Interface --
void log( Logtype _type, QString _message );
void log( QString _message );
void log( Logtype _type, QString _message );
private slots:
......@@ -129,7 +129,7 @@ public slots:
// -- File Interface --
int loadObject( QString _filename );
bool saveObject( int _id, QString _filename );
bool saveObject( int _objectId, QString _filename );
private:
......@@ -152,7 +152,6 @@ private:
QCheckBox *loadColors_;
QComboBox *loadColorRange_;
QCheckBox *loadIndices_;
QCheckBox *loadNormalizeSize_;
// options in the saving menu
QCheckBox *saveBinaryFile_;
......
......@@ -406,7 +406,7 @@ void SplatCloudObjectSelectionPlugin::slotVolumeLassoSelection( QMouseEvent *_ev
//----------------------------------------------------------------
void SplatCloudObjectSelectionPlugin::loadSelection( int _objId, const QString &_filename )
void SplatCloudObjectSelectionPlugin::loadSelection( int _objectId, const QString &_filename )
{
// Load ini file
INIFile file;
......@@ -418,19 +418,19 @@ void SplatCloudObjectSelectionPlugin::loadSelection( int _objId, const QString &
}
// Load selection from file
loadIniFile( file, _objId );
loadIniFile( file, _objectId );
}
//----------------------------------------------------------------
void SplatCloudObjectSelectionPlugin::loadIniFile( INIFile &_ini, int _id )
void SplatCloudObjectSelectionPlugin::loadIniFile( INIFile &_ini, int _objectId )
{
BaseObjectData *object = 0;
if(!PluginFunctions::getObject( _id,object ) )
if( !PluginFunctions::getObject( _objectId, object ) )
{
emit log( LOGERR, tr("Cannot find object for id ") + QString::number( _id ) + tr(" in saveFile") );
emit log( LOGERR, tr("Cannot find object for id ") + QString::number( _objectId ) + tr(" in saveFile") );
return;
}
......@@ -480,12 +480,12 @@ void SplatCloudObjectSelectionPlugin::loadIniFile( INIFile &_ini, int _id )
//----------------------------------------------------------------
void SplatCloudObjectSelectionPlugin::saveIniFile( INIFile &_ini, int _id )
void SplatCloudObjectSelectionPlugin::saveIniFile( INIFile &_ini, int _objectId )
{
BaseObjectData *object = 0;
if( !PluginFunctions::getObject( _id, object ) )
if( !PluginFunctions::getObject( _objectId, object ) )
{
emit log( LOGERR, tr("Cannot find object for id ") + QString::number( _id ) + tr(" in saveFile") );
emit log( LOGERR, tr("Cannot find object for id ") + QString::number( _objectId ) + tr(" in saveFile") );
return;
}
......@@ -495,7 +495,7 @@ void SplatCloudObjectSelectionPlugin::saveIniFile( INIFile &_ini, int _id )
QString sectionName = object->name();
if( !_ini.section_exists( sectionName ) )
{
emit log( LOGERR, tr("Cannot find object section id ") + QString::number( _id ) + tr(" in saveFile") );
emit log( LOGERR, tr("Cannot find object section id ") + QString::number( _objectId ) + tr(" in saveFile") );
return;
}
......
......@@ -97,16 +97,16 @@ signals:
//-- Base Interface --
void updateView();
void updatedObject( int _identifier, const UpdateType& _type );
void nodeVisibilityChanged( int _identifier );
void updatedObject( int _objectId, const UpdateType& _type );
void nodeVisibilityChanged( int _objectId );
void setSlotDescription( QString _slotName, QString _slotDescription, QStringList _parameters, QStringList _descriptions );
//-- Backup Interface --
void createBackup( int _objectId, QString _name, UpdateType _type = UPDATE_ALL );
//-- Logging Interface --
void log( Logtype _type, QString _message );
void log( QString _message );
void log( Logtype _type, QString _message );
//-- Selection Interface --
void addSelectionEnvironment( QString _modeName, QString _description, QIcon _icon, QString &_handleName );
......@@ -134,13 +134,13 @@ signals:
public slots:
//-- Selection Interface --
void loadSelection( int _objId, const QString &_filename );
void loadSelection( int _objectId, const QString &_filename );
private slots:
//-- INI Interface --
void loadIniFile( INIFile &_ini, int _id );
void saveIniFile( INIFile &_ini, int _id );
void loadIniFile( INIFile &_ini, int _objectId );
void saveIniFile( INIFile &_ini, int _objectId );
//-- Base Interface --
void initializePlugin();
......@@ -163,8 +163,7 @@ private slots:
public:
//-- Base Interface --
QString name() { return QString( tr("SplatCloud Object Selection") ); }
QString name() { return QString( tr("SplatCloud Object Selection" ) ); }
QString description() { return QString( tr("Allows to select parts of SplatCloud Objects") ); }
//===========================================================================
......
......@@ -68,13 +68,15 @@
*/
bool SplatCloudObjectSelectionPlugin::splatCloudDeleteSelection( SplatCloud *_splatCloud, PrimitiveType _primitiveType )
{
if( _primitiveType & vertexType_ )
{
_splatCloud->initSelections();
return _splatCloud->deleteSelected();
}
if( (_primitiveType & vertexType_) == 0 )
return false; // done
if( _splatCloud == 0 )
return false; // error
unsigned int numDeleted = _splatCloud->eraseSplatsByIndex( SplatCloudSelection::getVertexSelection( _splatCloud ) );
return false;
return (numDeleted != 0);
}
......@@ -90,16 +92,31 @@ bool SplatCloudObjectSelectionPlugin::splatCloudDeleteSelection( SplatCloud *_sp
*/
void SplatCloudObjectSelectionPlugin::splatCloudToggleSelection( SplatCloud *_splatCloud, uint _index, ACG::Vec3d &_hit_point, PrimitiveType _primitiveType )
{
if( _primitiveType & vertexType_ )
if( (_primitiveType & vertexType_) == 0 )
return; // done
if( _splatCloud == 0 )
return; // error
if( /*(_index < 0) ||*/ (_index >= _splatCloud->numSplats()) )
return; // error
if( !_splatCloud->hasSelections() )
{
_splatCloud->initSelections();
_splatCloud->selections()[ _index ] = !_splatCloud->selections()[ _index ];
if( !_splatCloud->requestSelections() )
return; // error
if( _splatCloud->selections()[ _index ] )
unsigned int i, num = _splatCloud->numSplats();
for( i=0; i<num; ++i )
_splatCloud->selections( i ) = false;
}
_splatCloud->selections( _index ) = !_splatCloud->selections( _index );
if( _splatCloud->selections( _index ) )
emit scriptInfo( "selectVertices(ObjectId , [" + QString::number( _index ) + "])" );
else
emit scriptInfo( "unselectVertices(ObjectId , [" + QString::number( _index ) + "])" );
}
}
......@@ -117,10 +134,51 @@ void SplatCloudObjectSelectionPlugin::splatCloudToggleSelection( SplatCloud *_sp
*/
void SplatCloudObjectSelectionPlugin::splatCloudSphereSelection( SplatCloud *_splatCloud, uint _index, ACG::Vec3d &_hit_point, double _radius, PrimitiveType _primitiveType, bool _deselection )
{
if( _primitiveType & vertexType_ )
if( (_primitiveType & vertexType_) == 0 )
return; // done
if( _splatCloud == 0 )
return; // error
if( /*(_index < 0) ||*/ (_index >= _splatCloud->numSplats()) )
return; // error
if( !_splatCloud->hasPositions() )
return; // error
if( !_splatCloud->hasSelections() )
{
_splatCloud->initSelections();
_splatCloud->setSphereSelections( _splatCloud->points()[ _index ], _radius * _radius, !_deselection );
if( _deselection )
return; // done
if( !_splatCloud->requestSelections() )
return; // error
unsigned int i, num = _splatCloud->numSplats();
for( i=0; i<num; ++i )
_splatCloud->selections( i ) = false;
}
if( _radius < 0.0 )
return; // done
double sqrRadius = _radius * _radius;
SplatCloud::Selection selection = !_deselection;
unsigned int i, num = _splatCloud->numSplats();
for( i=0; i<num; ++i )
{
const SplatCloud::Position &pos = _splatCloud->positions( i );
double dx = pos[0] - _hit_point[0];
double dy = pos[1] - _hit_point[1];
double dz = pos[2] - _hit_point[2];
double sqrDist = dx*dx + dy*dy + dz*dz;
if( sqrDist <= sqrRadius )
_splatCloud->selections( i ) = selection;
}
}
......@@ -139,25 +197,53 @@ void SplatCloudObjectSelectionPlugin::splatCloudSphereSelection( SplatCloud *_sp
*/
bool SplatCloudObjectSelectionPlugin::splatCloudVolumeSelection( SplatCloud *_splatCloud, ACG::GLState &_state, QRegion *_region, PrimitiveType _primitiveType, bool _deselection )
{
bool rv = false;
if( (_primitiveType & vertexType_) == 0 )
return false; // done
if( _primitiveType & vertexType_ )
if( _splatCloud == 0 )
return false; // error
if( !_splatCloud->hasPositions() )
return false; // error
bool modify = true;
if( !_splatCloud->hasSelections() )
{
if( _deselection )
{
_splatCloud->initSelections();
modify = false;
}
else
{
if( !_splatCloud->requestSelections() )
return false; // error
unsigned int i, num = _splatCloud->numPoints();
unsigned int i, num = _splatCloud->numSplats();
for( i=0; i<num; ++i )
_splatCloud->selections( i ) = false;
}
}
bool rv = false;
SplatCloud::Selection selection = !_deselection;
unsigned int i, num = _splatCloud->numSplats();
for( i=0; i<num; ++i )
{
const SplatCloud::Point &p = _splatCloud->points()[ i ];
ACG::Vec3d proj = _state.project( ACG::Vec3d( p[0], p[1], p[2] ) );
const SplatCloud::Position &pos = _splatCloud->positions( i );
ACG::Vec3d proj = _state.project( ACG::Vec3d( pos[0], pos[1], pos[2] ) );
if( _region->contains( QPoint( (int) proj[0], _state.context_height() - (int) proj[1] ) ) )
{
_splatCloud->selections()[ i ] = !_deselection;
if( modify )
_splatCloud->selections( i ) = selection;
rv = true;
}
}
}
return rv;
}
......@@ -177,9 +263,37 @@ bool SplatCloudObjectSelectionPlugin::splatCloudVolumeSelection( SplatCloud *_sp
*/
void SplatCloudObjectSelectionPlugin::splatCloudColorizeSelection( SplatCloud *_splatCloud, PrimitiveType _primitiveTypes, int _r, int _g, int _b, int _a )
{
if( _primitiveTypes & vertexType_ )
if( (_primitiveTypes & vertexType_) == 0 )
return; // done
if( _splatCloud == 0 )
return; // error
if( !_splatCloud->hasColors() )
{
if( !_splatCloud->requestColors() )
return; // error
SplatCloud::Color black( 0, 0, 0 );
unsigned int i, num = _splatCloud->numSplats();
for( i=0; i<num; ++i )
_splatCloud->colors( i ) = black;
}
if( !_splatCloud->hasSelections() )
return; // done
unsigned char r = (_r < 0) ? 0 : (_r > 255) ? 255 : (unsigned char) _r;
unsigned char g = (_g < 0) ? 0 : (_g > 255) ? 255 : (unsigned char) _g;
unsigned char b = (_b < 0) ? 0 : (_b > 255) ? 255 : (unsigned char) _b;
SplatCloud::Color color( r, g, b ); // drop alpha
unsigned int i, num = _splatCloud->numSplats();
for( i=0; i<num; ++i )
{
_splatCloud->initSelections();
_splatCloud->colorizeSelected( SplatCloud::Color( _r, _g, _b ) ); // alpha-component will be dropped
if( _splatCloud->selections( i ) )
_splatCloud->colors( i ) = color;
}
}
......@@ -68,16 +68,33 @@ namespace SplatCloudSelection {
//== Vertex Selection =====================================
//=========================================================
void selectVertices( SplatCloud *_splatCloud, std::vector<int> &_vertices )
void selectVertices( SplatCloud *_splatCloud, const std::vector<int> &_vertices )
{
int n_vertices = (int) _splatCloud->numPoints();
if( _splatCloud == 0 )
return; // error
if( _vertices.empty() )
return; // done
if( !_splatCloud->hasSelections() )
{
if( !_splatCloud->requestSelections() )
return; // error
unsigned int i, num = _splatCloud->numSplats();
for( i=0; i<num; ++i )
_splatCloud->selections( i ) = false;
}
int n_vertices = (int) _splatCloud->numSplats();
unsigned int i;
for( i=0; i<_vertices.size(); ++i )
{
const int &v = _vertices[i];
int v = _vertices[ i ];
if( (v >= 0) && (v < n_vertices) )
_splatCloud->selections()[ v ] = true;
_splatCloud->selections( v ) = true;
}
}
......@@ -85,16 +102,25 @@ void selectVertices( SplatCloud *_splatCloud, std::vector<int> &_vertices )
//----------------------------------------------------------------
void unselectVertices( SplatCloud *_splatCloud, std::vector<int> &_vertices )
void unselectVertices( SplatCloud *_splatCloud, const std::vector<int> &_vertices )
{
int n_vertices = (int) _splatCloud->numPoints();
if( _splatCloud == 0 )
return; // error
if( _vertices.empty() )
return; // done
if( !_splatCloud->hasSelections() )
return; // done
int n_vertices = (int) _splatCloud->numSplats();
unsigned int i;
for( i=0; i<_vertices.size(); ++i )
{
const int &v = _vertices[i];
int v = _vertices[ i ];
if( (v >= 0) && (v < n_vertices) )
_splatCloud->selections()[ v ] = false;
_splatCloud->selections( v ) = false;
}
}
......@@ -104,7 +130,15 @@ void unselectVertices( SplatCloud *_splatCloud, std::vector<int> &_vertices )
void selectAllVertices( SplatCloud *_splatCloud )
{
_splatCloud->setSelections( true );
if( _splatCloud == 0 )
return; // error
if( !_splatCloud->requestSelections() )
return; // error
unsigned int i, num = _splatCloud->numSplats();
for( i=0; i<num; ++i )
_splatCloud->selections( i ) = true;
}
......@@ -113,7 +147,15 @@ void selectAllVertices( SplatCloud *_splatCloud )
void clearVertexSelection( SplatCloud *_splatCloud )
{
_splatCloud->setSelections( false );
if( _splatCloud == 0 )
return; // error
if( !_splatCloud->hasSelections() )
return; // done
unsigned int i, num = _splatCloud->numSplats();
for( i=0; i<num; ++i )
_splatCloud->selections( i ) = false;
}
......@@ -122,53 +164,117 @@ void clearVertexSelection( SplatCloud *_splatCloud )
void invertVertexSelection( SplatCloud *_splatCloud )
{
_splatCloud->invertSelections();
if( _splatCloud == 0 )
return; // error
if( _splatCloud->hasSelections() )
{
unsigned int i, num = _splatCloud->numSplats();
for( i=0; i<num; ++i )
_splatCloud->selections( i ) = !_splatCloud->selections( i );
}
else
{
if( !_splatCloud->requestSelections() )
return; // error
unsigned int i, num = _splatCloud->numSplats();
for( i=0; i<num; ++i )
_splatCloud->selections( i ) = true;
}
}
//----------------------------------------------------------------
std::vector<int> getVertexSelection( SplatCloud *_splatCloud )
static unsigned int countSelected( const SplatCloud *_splatCloud )
{
std::vector<int> selection;
unsigned int count = 0;
unsigned int i, num = _splatCloud->numPoints();
unsigned int i, num = _splatCloud->numSplats();
for( i=0; i<num; ++i )
{
if( _splatCloud->selections()[ i ] )
selection.push_back( i );
if( _splatCloud->selections( i ) )
++count;
}
return selection;
return count;
}
//----------------------------------------------------------------
std::vector<int> getVertexSelection( SplatCloud *_splatCloud, bool &_invert)
std::vector<int> getVertexSelection( const SplatCloud *_splatCloud )
{
unsigned int numSelected = 0;
std::vector<int> vertices;
unsigned int i, num = _splatCloud->numPoints();
if( _splatCloud == 0 )
return vertices; // error
if( !_splatCloud->hasSelections() )
return vertices; // done
unsigned int numSelected = countSelected( _splatCloud );
vertices.reserve( numSelected );
unsigned int i, num = _splatCloud->numSplats();
for( i=0; i<num; ++i )
{
if( _splatCloud->selections()[ i ] )
++numSelected;
if( _splatCloud->selections( i ) )
vertices.push_back( i );
}
_invert = (numSelected > _splatCloud->numPoints() / 2);
return vertices;
}
//----------------------------------------------------------------
std::vector<int> getVertexSelection( const SplatCloud *_splatCloud, bool &_inverted )
{
_inverted = false;
std::vector<int> vertices;
std::vector<int> selection;
if( _splatCloud == 0 )
return vertices; // error
if( !_splatCloud->hasSelections() )
return vertices; // done
unsigned int numSelected = countSelected( _splatCloud );
unsigned int numUnselected = _splatCloud->numSplats() - numSelected;
if( numSelected <= numUnselected )
{
vertices.reserve( numSelected );
unsigned int i, num = _splatCloud->numSplats();
for( i=0; i<num; ++i )
{
if( _splatCloud->selections( i ) )
vertices.push_back( i );
}
}
else
{
_inverted = true;
vertices.reserve( numUnselected );