Commit 356c667f authored by Ellen Dekkers's avatar Ellen Dekkers

Plugin-Selection: Vertex (control point) selection for bspline curves and...

Plugin-Selection: Vertex (control point) selection for bspline curves and surfaces. work in progress on knot selection

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@9583 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 7fcf52d3
//=============================================================================
//
// SelectionFunctions BSplineCurve
//
// Author: Ellen Dekkers <dekkers@cs.rwth-aachen.de>
//
// $Date$
//
//=============================================================================
#include <Plugin-Selection/SelectionPlugin.hh>
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
......@@ -8,17 +18,20 @@
//-----------------------------------------------------------------------------
void SelectionPlugin::toggleBSplineCurveSelection(QMouseEvent* _event)
void
SelectionPlugin::
toggleBSplineCurveSelection(QMouseEvent* _event)
{
if ( _event->type() != QEvent::MouseButtonPress )
return;
if (selectionType_ & VERTEX){
if (selectionType_ & VERTEX)
{
unsigned int node_idx, target_idx;
ACG::Vec3d hit_point;
if (PluginFunctions::scenegraphPick(ACG::SceneGraph::PICK_VERTEX, _event->pos(),node_idx, target_idx, &hit_point)) {
if (PluginFunctions::scenegraphPick(ACG::SceneGraph::PICK_VERTEX, _event->pos(),node_idx, target_idx, &hit_point))
{
BaseObjectData* object;
if ( PluginFunctions::getPickedObject(node_idx, object) )
......@@ -26,18 +39,51 @@ void SelectionPlugin::toggleBSplineCurveSelection(QMouseEvent* _event)
BSplineCurveObject* bsco = PluginFunctions::bsplineCurveObject( object );
// toggle selection
if( bsco->splineCurve()->vertex_selections_available() )
if( bsco->splineCurve()->controlpoint_selections_available() )
{
if( target_idx < bsco->splineCurve()->n_control_points())
if( bsco->splineCurve()->vertex_selection( target_idx) == 0)
bsco->splineCurve()->vertex_selection( target_idx ) = 1;
else
bsco->splineCurve()->vertex_selection( target_idx ) = 0;
{
if( bsco->splineCurve()->controlpoint_selection( target_idx) == 0)
bsco->splineCurve()->controlpoint_selection( target_idx ) = 1;
else
bsco->splineCurve()->controlpoint_selection( target_idx ) = 0;
}
}
emit updateView();
}
}
}
else if (selectionType_ & KNOT)
{
unsigned int node_idx, target_idx;
ACG::Vec3d hit_point;
if (PluginFunctions::scenegraphPick(ACG::SceneGraph::PICK_SPLINE, _event->pos(),node_idx, target_idx, &hit_point))
{
BaseObjectData* object;
if ( PluginFunctions::getPickedObject(node_idx, object) )
{
BSplineCurveObject* bsco = PluginFunctions::bsplineCurveObject( object );
// toggle selection
if( bsco->splineCurve()->get_knotvector_ref()->selections_available() )
{
if( target_idx < bsco->splineCurve()->get_knotvector_ref()->size())
if( bsco->splineCurve()->get_knotvector_ref()->selection( target_idx) == 0)
bsco->splineCurve()->get_knotvector_ref()->selection( target_idx ) = 1;
else
bsco->splineCurve()->get_knotvector_ref()->selection( target_idx ) = 0;
}
emit updateView();
}
}
}
}
#endif
//=============================================================================
//
// BSplineCurve Selection
//
// Author: Ellen Dekkers <dekkers@cs.rwth-aachen.de>
//
// $Date$
//
//=============================================================================
#ifndef BSPLINESELECTION_HH
#define BSPLINESELECTION_HH
#ifndef BSPLINECURVESELECTION_HH
#define BSPLINECURVESELECTION_HH
/*! \file bSplineCurveSelection.hh
\brief Functions for selection on a BSpline
/*! \file bSplineCurveSelectionT.hh
\brief Functions for selection on a BSpline curve
*/
......@@ -23,29 +32,29 @@ namespace BSplineCurveSelection {
* @{ */
//===========================================================================
template< typename BSplineT >
template< typename BSplineCurveT >
inline
void selectVertices(BSplineT* _bSpline, std::vector< int >& _vertices);
void selectVertices(BSplineCurveT* _bSplineCurve, std::vector< int >& _vertices);
template< typename BSplineT >
template< typename BSplineCurveT >
inline
void unselectVertices(BSplineT* _bSpline, std::vector< int >& _vertices);
void unselectVertices(BSplineCurveT* _bSplineCurve, std::vector< int >& _vertices);
template< typename BSplineT >
template< typename BSplineCurveT >
inline
void selectAllVertices(BSplineT* _bSpline);
void selectAllVertices(BSplineCurveT* _bSplineCurve);
template< typename BSplineT >
template< typename BSplineCurveT >
inline
void clearVertexSelection(BSplineT* _bSpline);
void clearVertexSelection(BSplineCurveT* _bSplineCurve);
template< typename BSplineT >
template< typename BSplineCurveT >
inline
void invertVertexSelection(BSplineT* _bSpline);
void invertVertexSelection(BSplineCurveT* _bSplineCurve);
template< typename BSplineT >
template< typename BSplineCurveT >
inline
std::vector< int > getVertexSelection(BSplineT* _bSpline);
std::vector< int > getVertexSelection(BSplineCurveT* _bSplineCurve);
/** @} */
......@@ -54,30 +63,61 @@ std::vector< int > getVertexSelection(BSplineT* _bSpline);
* @{ */
//===========================================================================
template< typename BSplineT >
template< typename BSplineCurveT >
inline
void selectEdges(BSplineT* _bSpline, std::vector< int >& _edges);
void selectEdges(BSplineCurveT* _bSplineCurve, std::vector< int >& _edges);
template< typename BSplineT >
template< typename BSplineCurveT >
inline
void unselectEdges(BSplineT* _bSpline, std::vector< int >& _edges);
void unselectEdges(BSplineCurveT* _bSplineCurve, std::vector< int >& _edges);
template< typename BSplineT >
template< typename BSplineCurveT >
inline
void selectAllEdges(BSplineT* _bSpline);
void selectAllEdges(BSplineCurveT* _bSplineCurve);
template< typename BSplineT >
template< typename BSplineCurveT >
inline
void clearEdgeSelection(BSplineT* _bSpline);
void clearEdgeSelection(BSplineCurveT* _bSplineCurve);
template< typename BSplineT >
template< typename BSplineCurveT >
inline
void invertEdgeSelection(BSplineT* _bSpline);
void invertEdgeSelection(BSplineCurveT* _bSplineCurve);
template< typename BSplineCurveT >
inline
std::vector< int > getEdgeSelection(BSplineCurveT* _bSplineCurve);
/** @} */
//===========================================================================
/** @name Knot Selection
* @{ */
//===========================================================================
template< typename BSplineCurveT >
inline
void selectKnots(BSplineCurveT* _bSplineCurve, std::vector< int >& _knots);
template< typename BSplineCurveT >
inline
void unselectKnots(BSplineCurveT* _bSplineCurve, std::vector< int >& _knots);
template< typename BSplineCurveT >
inline
void selectAllKnots(BSplineCurveT* _bSplineCurve);
template< typename BSplineCurveT >
inline
void clearKnotSelection(BSplineCurveT* _bSplineCurve);
template< typename BSplineCurveT >
inline
void invertKnotSelection(BSplineCurveT* _bSplineCurve);
template< typename BSplineT >
template< typename BSplineCurveT >
inline
std::vector< int > getEdgeSelection(BSplineT* _bSpline);
std::vector< int > getKnotSelection(BSplineCurveT* _bSplineCurve);
/** @} */
......@@ -85,11 +125,11 @@ std::vector< int > getEdgeSelection(BSplineT* _bSpline);
} // BSplineCurveSelection Namespace
//=============================================================================
#if defined(INCLUDE_TEMPLATES) && !defined(BSPLINESELECTION_C)
#define BSPLINESELECTION_TEMPLATES
#if defined(INCLUDE_TEMPLATES) && !defined(BSPLINECURVESELECTION_C)
#define BSPLINECURVESELECTION_TEMPLATES
#include "bSplineCurveSelectionT.cc"
#endif
//=============================================================================
#endif // BSPLINESELECTION_HH defined
#endif // BSPLINECURVESELECTION_HH defined
//=============================================================================
//=============================================================================
//
// SelectionFunctions BSplineSurface
//
// Author: Ellen Dekkers <dekkers@cs.rwth-aachen.de>
//
// $Date$
//
//=============================================================================
#include <Plugin-Selection/SelectionPlugin.hh>
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
//-----------------------------------------------------------------------------
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
//-----------------------------------------------------------------------------
void
SelectionPlugin::
toggleBSplineSurfaceSelection(QMouseEvent* _event)
{
if ( _event->type() != QEvent::MouseButtonPress )
return;
if (selectionType_ & VERTEX)
{
unsigned int node_idx, target_idx;
ACG::Vec3d hit_point;
if (PluginFunctions::scenegraphPick(ACG::SceneGraph::PICK_VERTEX, _event->pos(),node_idx, target_idx, &hit_point))
{
BaseObjectData* object;
if ( PluginFunctions::getPickedObject(node_idx, object) )
{
BSplineSurfaceObject* bsso = PluginFunctions::bsplineSurfaceObject( object );
// toggle selection
if( bsso->splineSurface()->controlpoint_selections_available() )
{
unsigned int max = bsso->splineSurface()->n_control_points_m() * bsso->splineSurface()->n_control_points_n();
if( target_idx < max)
{
int idx_m = target_idx / bsso->splineSurface()->n_control_points_n();
int idx_n = target_idx % bsso->splineSurface()->n_control_points_n();
// TODO try global idx access
if( bsso->splineSurface()->controlpoint_selection(idx_m, idx_n) == 0)
bsso->splineSurface()->controlpoint_selection(idx_m, idx_n) = true;
else
bsso->splineSurface()->controlpoint_selection(idx_m, idx_n) = 0;
}
}
emit updateView();
}
}
}
}
//-----------------------------------------------------------------------------
#endif
//=============================================================================
//
// BSplineSurface Selection - IMPLEMENTATION
//
// Author: Ellen Dekkers <dekkers@cs.rwth-aachen.de>
//
// $Date$
//
//=============================================================================
#define BSPLINESURFACESELECTION_C
//== INCLUDES =================================================================
#include "bSplineSurfaceSelectionT.hh"
//== NAMESPACES ===============================================================
namespace BSplineSurfaceSelection {
//== DEFINITIONS ==============================================================
//=========================================================
//== Vertex Selection =======================================
//=========================================================
template< typename BSplineSurfaceT >
inline
void
selectVertices(BSplineSurfaceT* _bSplineSurface, std::vector< int >& _vertices)
{
const int max = _bSplineSurface->n_control_points_m() * _bSplineSurface->n_control_points_n();
if (_bSplineSurface->controlpoint_selections_available())
{
for ( unsigned int i = 0 ; i < _vertices.size(); ++i )
{
if ( (_vertices[i] > 0) && ( _vertices[i] < max ) )
{
int idx_m = _vertices[i] / _bSplineSurface->n_control_points_n();
int idx_n = _vertices[i] % _bSplineSurface->n_control_points_n();
_bSplineSurface->controlpoint_selection(idx_m, idx_n) = true;
// TODO try global idx selection
// _bSplineSurface->vertex_selection(_vertices[i]) = true;
}
}
}
}
//-----------------------------------------------------------------------------
template< typename BSplineSurfaceT >
inline
void
unselectVertices(BSplineSurfaceT* _bSplineSurface, std::vector< int >& _vertices)
{
const int max = _bSplineSurface->n_control_points_m() * _bSplineSurface->n_control_points_n();
if (_bSplineSurface->controlpoint_selections_available())
{
for ( unsigned int i = 0 ; i < _vertices.size(); ++i )
{
if ( (_vertices[i] > 0) && ( _vertices[i] < max ) )
{
int idx_m = _vertices[i] / _bSplineSurface->n_control_points_n();
int idx_n = _vertices[i] % _bSplineSurface->n_control_points_n();
_bSplineSurface->controlpoint_selection(idx_m, idx_n) = false;
// TODO try global idx selection
// _bSplineSurface->vertex_selection(_vertices[i]) = true;
}
}
}
}
//-----------------------------------------------------------------------------
template< typename BSplineSurfaceT >
inline
void
selectAllVertices(BSplineSurfaceT* _bSplineSurface)
{
if (_bSplineSurface->controlpoint_selections_available())
for (unsigned int i = 0; i < _bSplineSurface->n_control_points_m(); ++i)
for(unsigned int j = 0; j < _bSplineSurface->n_control_points_n(); ++j)
_bSplineSurface->controlpoint_selection(i,j) = true;
}
//-----------------------------------------------------------------------------
template< typename BSplineSurfaceT >
inline
void
clearVertexSelection(BSplineSurfaceT* _bSplineSurface)
{
if(_bSplineSurface->controlpoint_selections_available())
for(unsigned int i = 0; i < _bSplineSurface->n_control_points_m(); ++i)
for(unsigned int j = 0; j < _bSplineSurface->n_control_points_n(); ++j)
_bSplineSurface->controlpoint_selection(i,j) = false;
}
//-----------------------------------------------------------------------------
template< typename BSplineSurfaceT >
inline
void
invertVertexSelection(BSplineSurfaceT* _bSplineSurface)
{
if(_bSplineSurface->controlpoint_selections_available())
for(unsigned int i = 0; i < _bSplineSurface->n_control_points_m(); ++i)
for(unsigned int j = 0; j < _bSplineSurface->n_control_points_n(); ++j)
_bSplineSurface->controlpoint_selection(i,j) = !_bSplineSurface->controlpoint_selection(i,j);
}
//-----------------------------------------------------------------------------
template< typename BSplineSurfaceT >
inline
std::vector< int >
getVertexSelection(BSplineSurfaceT* _bSplineSurface)
{
std::vector< int > selection;
if( ! _bSplineSurface->controlpoint_selections_available() )
return selection;
for (unsigned int i = 0; i < _bSplineSurface->n_control_points_m(); ++i)
{
for (unsigned int j = 0; j < _bSplineSurface->n_control_points_n(); ++j)
{
int idx = i * _bSplineSurface->n_control_points_n() + j;
if (_bSplineSurface->controlpoint_selection(i,j) )
selection.push_back(idx);
}
}
return selection;
}
//=========================================================
//== Knot Selection =======================================
//=========================================================
//=========================================================
//== Edge Selection =======================================
//=========================================================
template< typename BSplineSurfaceT >
inline
void
selectEdges(BSplineSurfaceT* _bSplineSurface, std::vector< int >& _edges)
{
const int max = _bSplineSurface->n_control_points_m() * _bSplineSurface->n_control_points_n();
// if(_bSplineSurface->edge_selections_available())
// for ( unsigned int i = 0 ; i < _edges.size(); ++i )
// if ( (_edges[i] > 0) && ( _edges[i] < max ) )
// _bSplineSurface->edge_selection(_edges[i]) = true;
}
//-----------------------------------------------------------------------------
template< typename BSplineSurfaceT >
inline
void
unselectEdges(BSplineSurfaceT* _bSplineSurface, std::vector< int >& _edges)
{
const int max = _bSplineSurface->n_control_points_m() * _bSplineSurface->n_control_points_n();
// if(_bSplineSurface->edge_selections_available())
// for ( unsigned int i = 0 ; i < _edges.size(); ++i )
// if ( (_edges[i] > 0) && ( _edges[i] < max ) )
// _bSplineSurface->edge_selection(_edges[i]) = false;
}
//-----------------------------------------------------------------------------
template< typename BSplineSurfaceT >
inline
void
selectAllEdges(BSplineSurfaceT* _bSplineSurface)
{
// if(_bSplineSurface->edge_selections_available())
// for(unsigned int i = 0; i < _bSplineSurface->n_control_points_m(); ++i)
// for(unsigned int j = 0; j < _bSplineSurface->n_control_points_n(); ++j)
// _bSplineSurface->edge_selection(i,j) = true;
}
//-----------------------------------------------------------------------------
template< typename BSplineSurfaceT >
inline
void
clearEdgeSelection(BSplineSurfaceT* _bSplineSurface)
{
// if(_bSplineSurface->edge_selections_available())
// for(unsigned int i = 0; i < _bSplineSurface->n_control_points_m(); ++i)
// for(unsigned int j = 0; j < _bSplineSurface->n_control_points_n(); ++j)
// _bSplineSurface->edge_selection(i,j) = false;
}
//-----------------------------------------------------------------------------
template< typename BSplineSurfaceT >
inline
void
invertEdgeSelection(BSplineSurfaceT* _bSplineSurface)
{
// if(_bSplineSurface->edge_selections_available())
// for(unsigned int i = 0; i < _bSplineSurface->n_control_points_m(); ++i)
// for(unsigned int j = 0; j < _bSplineSurface->n_control_points_n(); ++j)
// _bSplineSurface->edge_selection(i,j) = !_bSplineSurface->edge_selection(i,j);
}
//-----------------------------------------------------------------------------
template< typename BSplineSurfaceT >
inline
std::vector< int > getEdgeSelection(BSplineSurfaceT* _bSplineSurface)
{
std::vector< int > selection;
if( ! _bSplineSurface->edge_selections_available() )
return selection;
// for(unsigned int i = 0; i < _bSplineSurface->n_control_points_m(); ++i)
// for(unsigned int j = 0; j < _bSplineSurface->n_control_points_n(); ++j)
// if (_bSplineSurface->edge_selection(i,j) )
// selection.push_back(i);
return selection;
}
//------------------------------------------------------------------------------
}
//=============================================================================
//
// BSplineSurface Selection
//
// Author: Ellen Dekkers <dekkers@cs.rwth-aachen.de>
//
// $Date$
//
//=============================================================================
#ifndef BSPLINESURFACESELECTION_HH
#define BSPLINESURFACESELECTION_HH
/*! \file bSplineSurfaceSelection.hh
\brief Functions for selection on a BSpline Surface
*/
//== INCLUDES =================================================================
#include <vector>
//== NAMESPACES ===============================================================
namespace BSplineSurfaceSelection {
//== DEFINITIONS ==============================================================
//===========================================================================
/** @name Vertex Selection
* @{ */
//===========================================================================
template< typename BSplineSurfaceT >
inline
void selectVertices(BSplineSurfaceT* _bSplineSurface, std::vector< int >& _vertices);
template< typename BSplineSurfaceT >
inline
void unselectVertices(BSplineSurfaceT* _bSplineSurface, std::vector< int >& _vertices);
template< typename BSplineSurfaceT >
inline
void selectAllVertices(BSplineSurfaceT* _bSplineSurface);
template< typename BSplineSurfaceT >
inline
void clearVertexSelection(BSplineSurfaceT* _bSplineSurface);
template< typename BSplineSurfaceT >
inline
void invertVertexSelection(BSplineSurfaceT* _bSplineSurface);