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

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( QString _message );
void log( Logtype _type, QString _message );
void log( QString _message );
private slots:
......@@ -110,7 +110,7 @@ public:
~FilePTSPlugin() { }
//-- Base Interface --
QString name() { return QString( "FilePTS" ); }
QString name() { return QString( "FilePTS" ); }
QString description( ) { return QString( tr("Load/Save SplatCloud format files") ); }
// -- File Interface --
......@@ -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_;
......
......@@ -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
return false;
if( _splatCloud == 0 )
return false; // error
unsigned int numDeleted = _splatCloud->eraseSplatsByIndex( SplatCloudSelection::getVertexSelection( _splatCloud ) );
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_ )
{
_splatCloud->initSelections();
_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 ) + "])" );
}
if( (_primitiveType & vertexType_) == 0 )
return; // done
if( _splatCloud == 0 )
return; // error
if( /*(_index < 0) ||*/ (_index >= _splatCloud->numSplats()) )
return; // error
if( !_splatCloud->hasSelections() )
{
if( !_splatCloud->requestSelections() )
return; // error
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,11 +134,52 @@ 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_ )
{
_splatCloud->initSelections();
_splatCloud->setSphereSelections( _splatCloud->points()[ _index ], _radius * _radius, !_deselection );
}
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() )
{
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,27 +197,55 @@ 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_ )
{
_splatCloud->initSelections();
unsigned int i, num = _splatCloud->numPoints();
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] ) );
if( _region->contains( QPoint( (int) proj[0], _state.context_height() - (int) proj[1] ) ) )
{
_splatCloud->selections()[ i ] = !_deselection;
rv = true;
}
}
}
return rv;
if( (_primitiveType & vertexType_) == 0 )
return false; // done
if( _splatCloud == 0 )
return false; // error
if( !_splatCloud->hasPositions() )
return false; // error
bool modify = true;
if( !_splatCloud->hasSelections() )
{
if( _deselection )
{
modify = false;
}
else
{
if( !_splatCloud->requestSelections() )
return false; // error
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::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] ) ) )
{
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_ )
{
_splatCloud->initSelections();
_splatCloud->colorizeSelected( SplatCloud::Color( _r, _g, _b ) ); // alpha-component will be dropped
}
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 )
{
if( _splatCloud->selections( i ) )
_splatCloud->colors( i ) = color;
}
}
......@@ -68,34 +68,60 @@ 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();
unsigned int i;
for( i=0; i<_vertices.size(); ++i )
{
const int &v = _vertices[i];
if( (v >= 0) && (v < n_vertices) )
_splatCloud->selections()[ v ] = true;
}
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 )
{
int v = _vertices[ i ];
if( (v >= 0) && (v < n_vertices) )
_splatCloud->selections( v ) = true;
}
}
//----------------------------------------------------------------
void unselectVertices( SplatCloud *_splatCloud, std::vector<int> &_vertices )
void unselectVertices( SplatCloud *_splatCloud, const std::vector<int> &_vertices )
{
int n_vertices = (int) _splatCloud->numPoints();
unsigned int i;
for( i=0; i<_vertices.size(); ++i )
{
const int &v = _vertices[i];
if( (v >= 0) && (v < n_vertices) )
_splatCloud->selections()[ v ] = false;
}
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 )
{
int v = _vertices[ i ];
if( (v >= 0) && (v < n_vertices) )
_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;
}
}
//----------------------------------------------------------------
static unsigned int countSelected( const SplatCloud *_splatCloud )
{
unsigned int count = 0;
unsigned int i, num = _splatCloud->numSplats();
for( i=0; i<num; ++i )
{
if( _splatCloud->selections( i ) )
++count;
}
return count;
}
//----------------------------------------------------------------
std::vector<int> getVertexSelection( SplatCloud *_splatCloud )
std::vector<int> getVertexSelection( const SplatCloud *_splatCloud )
{
std::vector<int> selection;
std::vector<int> vertices;
if( _splatCloud == 0 )
return vertices; // error
if( !_splatCloud->hasSelections() )
return vertices; // done
unsigned int i, num = _splatCloud->numPoints();
for( i=0; i<num; ++i )
{
if( _splatCloud->selections()[ i ] )
selection.push_back( i );
}
unsigned int numSelected = countSelected( _splatCloud );
return selection;
vertices.reserve( numSelected );
unsigned int i, num = _splatCloud->numSplats();
for( i=0; i<num; ++i )
{
if( _splatCloud->selections( i ) )
vertices.push_back( i );
}
return vertices;
}
//----------------------------------------------------------------
std::vector<int> getVertexSelection( SplatCloud *_splatCloud, bool &_invert)
std::vector<int> getVertexSelection( const SplatCloud *_splatCloud, bool &_inverted )
{
unsigned int numSelected = 0;
_inverted = false;
std::vector<int> vertices;
if( _splatCloud == 0 )
return vertices; // error
if( !_splatCloud->hasSelections() )
return vertices; // done
unsigned int numSelected = countSelected( _splatCloud );
unsigned int numUnselected = _splatCloud->numSplats() - numSelected;
unsigned int i, num = _splatCloud->numPoints();
for( i=0; i<num; ++i )
{
if( _splatCloud->selections()[ i ] )
++numSelected;
}
if( numSelected <= numUnselected )
{
vertices.reserve( numSelected );
_invert = (numSelected > _splatCloud->numPoints() / 2);
unsigned int i, num = _splatCloud->numSplats();
for( i=0; i<num; ++i )
{
if( _splatCloud->selections( i ) )
vertices.push_back( i );
}
}
else
{
_inverted = true;
std::vector<int> selection;
vertices.reserve( numUnselected );
for( i=0; i<num; ++i )
{
if( _splatCloud->selections()[ i ] ^ _invert )
selection.push_back( i );
}
unsigned int i, num = _splatCloud->numSplats();
for( i=0; i<num; ++i )
{
if( !_splatCloud->selections( i ) )
vertices.push_back( i );
}
}
return selection;
return vertices;
}
......
......@@ -79,29 +79,13 @@ namespace SplatCloudSelection {
* @{ */
//===========================================================================
/// Select given vertices of a SplatCloud
void selectVertices(SplatCloud *_splatCloud, std::vector<int> &_vertices);
/// Unselect given vertices of a SplatCloud
void unselectVertices(SplatCloud *_splatCloud, std::vector<int> &_vertices);
/// Select all vertices of a SplatCloud
void selectAllVertices(SplatCloud *_splatCloud);
/// Set all vertices to unselected
void clearVertexSelection(SplatCloud *_splatCloud);
/// Invert vertex selection
void invertVertexSelection(SplatCloud *_splatCloud);
/// Get the current vertex selection
std::vector<int> getVertexSelection(SplatCloud *_splatCloud);
/** Get the current vertex selection
*
* @param _invert if true : vector has been inverted to save memory )
*/
std::vector<int> getVertexSelection(SplatCloud *_splatCloud, bool &_invert);
void selectVertices ( SplatCloud *_splatCloud, const std::vector<int> &_vertices ); /// Select given vertices.
void unselectVertices ( SplatCloud *_splatCloud, const std::vector<int> &_vertices ); /// Unselect given vertices.
void selectAllVertices ( SplatCloud *_splatCloud ); /// Select all vertices.
void clearVertexSelection ( SplatCloud *_splatCloud ); /// Unselect all vertices.
void invertVertexSelection( SplatCloud *_splatCloud ); /// Invert vertex selection.
std::vector<int> getVertexSelection ( const SplatCloud *_splatCloud ); /// Get current vertex selection.
std::vector<int> getVertexSelection ( const SplatCloud *_splatCloud, bool &_inverted ); /// Get current vertex selection. If _inverted is true, vector is inverted to save memory.
/** @} */
......
include (plugin)
openflipper_plugin ()
openflipper_plugin (INSTALLDATA Icons)
......@@ -62,6 +62,7 @@
#include <QObject>
#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
#include <OpenFlipper/BasePlugin/ToolboxInterface.hh>
#include <OpenFlipper/BasePlugin/ContextMenuInterface.hh>
#include <OpenFlipper/BasePlugin/ViewModeInterface.hh>
......@@ -73,113 +74,120 @@
//== CLASS DEFINITION ============================================
class SplatCloudRenderingControlPlugin : public QObject, BaseInterface, ToolboxInterface, ContextMenuInterface, ViewModeInterface, LoggingInterface
class SplatCloudRenderingControlPlugin : public QObject, BaseInterface, LoadSaveInterface, ToolboxInterface, ContextMenuInterface, ViewModeInterface, LoggingInterface
{
Q_OBJECT
Q_INTERFACES( BaseInterface )
Q_INTERFACES( ToolboxInterface )
Q_INTERFACES( ContextMenuInterface )
Q_INTERFACES( ViewModeInterface )
Q_INTERFACES( LoggingInterface )
Q_OBJECT
Q_INTERFACES( BaseInterface )
Q_INTERFACES( LoadSaveInterface )
Q_INTERFACES( ToolboxInterface )
Q_INTERFACES( ContextMenuInterface )
Q_INTERFACES( ViewModeInterface )
Q_INTERFACES( LoggingInterface )
signals:
//-- Base Interface --
void updatedObject( int _identifier, const UpdateType& _type);
//-- Base Interface --
void updatedObject( int _objectId, const UpdateType &_type );
//-- Toolbox Interface --
void addToolbox( QString _name, QWidget *_widget, QIcon *_icon );
//-- Toolbox Interface --
void addToolbox( QString _name, QWidget *_widget, QIcon *_icon );
//-- ContextMenu Interface--
void addContextMenuItem( QAction *_action, DataType _objectType, ContextMenuType _type );
//-- ContextMenu Interface--
void addContextMenuItem( QAction *_action, DataType _objectType, ContextMenuType _type );
//-- ViewMode Interface--
void defineViewModeToolboxes ( QString _mode, QStringList _usedWidgets );
void defineViewModeToolbars ( QString _mode, QStringList _usedToolbars );
void defineViewModeContextMenus( QString _mode, QStringList _usedContextMenus );
void defineViewModeIcon ( QString _mode, QString _iconName );
//-- ViewMode Interface--
void defineViewModeToolboxes ( QString _mode, QStringList _usedWidgets );
void defineViewModeToolbars ( QString _mode, QStringList _usedToolbars );
void defineViewModeContextMenus( QString _mode, QStringList _usedContextMenus );
void defineViewModeIcon ( QString _mode, QString _iconName );
//-- Logging Interface --
void log( Logtype _type, QString _message );
void log( QString _message );
//-- Logging Interface --
void log( QString _message );
void log( Logtype _type, QString _message );
public:
SplatCloudRenderingControlPlugin();
SplatCloudRenderingControlPlugin();
//-- Base Interface --
QString name() { return QString( "SplatCloud Rendering Control Plugin" ); }
QString description() { return QString( "Control over rendering of SplatClouds" ); }
//-- Base Interface --
QString name() { return QString( "SplatCloud Rendering Control Plugin" ); }
QString description() { return QString( "Control over rendering of SplatClouds" ); }
private:
// toolbox options
QDoubleSpinBox *toolboxPointsizeScale_;
QDoubleSpinBox *toolboxDefaultNormalX_;
QDoubleSpinBox *toolboxDefaultNormalY_;
QDoubleSpinBox *toolboxDefaultNormalZ_;
QDoubleSpinBox *toolboxDefaultPointsize_;
QSpinBox *toolboxDefaultColorR_;
QSpinBox *toolboxDefaultColorG_;
QSpinBox *toolboxDefaultColorB_;
// context menu options
QAction *contextScaleAction_;