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

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
#define BSPLINESELECTION_C
#define BSPLINECURVESELECTION_C
//== INCLUDES =================================================================
#include "bSplineCurveSelectionT.hh"
#include "../Knotvector/knotvectorSelectionT.hh"
//== NAMESPACES ===============================================================
......@@ -12,78 +13,85 @@ namespace BSplineCurveSelection {
//== DEFINITIONS ==============================================================
//=========================================================
//== Vertex Selection =======================================
//== Vertex Selection (selects control points) ============
//=========================================================
template< typename BSplineT >
template< typename BSplineCurveT >
inline
void selectVertices(BSplineT* _bSpline, std::vector< int >& _vertices) {
const int max = _bSpline->n_control_points();
if(_bSpline->vertex_selections_available())
void
selectVertices(BSplineCurveT* _bSplineCurve, std::vector< int >& _vertices)
{
const int max = _bSplineCurve->n_control_points();
if(_bSplineCurve->controlpoint_selections_available())
for ( unsigned int i = 0 ; i < _vertices.size(); ++i )
if ( (_vertices[i] > 0) && ( _vertices[i] < max ) )
_bSpline->vertex_selection(_vertices[i]) = true;
_bSplineCurve->controlpoint_selection(_vertices[i]) = true;
}
//-----------------------------------------------------------------------------
template< typename BSplineT >
template< typename BSplineCurveT >
inline
void unselectVertices(BSplineT* _bSpline, std::vector< int >& _vertices) {
const int max = _bSpline->n_control_points();
if(_bSpline->vertex_selections_available())
void
unselectVertices(BSplineCurveT* _bSplineCurve, std::vector< int >& _vertices)
{
const int max = _bSplineCurve->n_control_points();
if (_bSplineCurve->controlpoint_selections_available())
for ( unsigned int i = 0 ; i < _vertices.size(); ++i )
if ( (_vertices[i] > 0) && ( _vertices[i] < max ) )
_bSpline->vertex_selection(_vertices[i]) = false;
_bSplineCurve->controlpoint_selection(_vertices[i]) = false;
}
//-----------------------------------------------------------------------------
template< typename BSplineT >
template< typename BSplineCurveT >
inline
void selectAllVertices(BSplineT* _bSpline)
void
selectAllVertices(BSplineCurveT* _bSplineCurve)
{
if(_bSpline->vertex_selections_available())
for(unsigned int i=0; i< _bSpline->n_control_points(); ++i)
_bSpline->vertex_selection(i) = true;
if (_bSplineCurve->controlpoint_selections_available())
for (unsigned int i = 0; i< _bSplineCurve->n_control_points(); ++i)
_bSplineCurve->controlpoint_selection(i) = true;
}
//-----------------------------------------------------------------------------
template< typename BSplineT >
template< typename BSplineCurveT >
inline
void clearVertexSelection(BSplineT* _bSpline)
void
clearVertexSelection(BSplineCurveT* _bSplineCurve)
{
if(_bSpline->vertex_selections_available())
for(unsigned int i=0; i< _bSpline->n_control_points(); ++i)
_bSpline->vertex_selection(i) = false;
if (_bSplineCurve->controlpoint_selections_available())
for(unsigned int i = 0; i < _bSplineCurve->n_control_points(); ++i)
_bSplineCurve->controlpoint_selection(i) = false;
}
//-----------------------------------------------------------------------------
template< typename BSplineT >
template< typename BSplineCurveT >
inline
void invertVertexSelection(BSplineT* _bSpline)
void
invertVertexSelection(BSplineCurveT* _bSplineCurve)
{
if(_bSpline->vertex_selections_available())
for(unsigned int i=0; i< _bSpline->n_control_points(); ++i)
_bSpline->vertex_selection(i) = !_bSpline->vertex_selection(i);
if (_bSplineCurve->controlpoint_selections_available())
for (unsigned int i = 0; i < _bSplineCurve->n_control_points(); ++i)
_bSplineCurve->controlpoint_selection(i) = !_bSplineCurve->controlpoint_selection(i);
}
//-----------------------------------------------------------------------------
template< typename BSplineT >
template< typename BSplineCurveT >
inline
std::vector< int > getVertexSelection(BSplineT* _bSpline) {
std::vector< int >
getVertexSelection(BSplineCurveT* _bSplineCurve)
{
std::vector< int > selection;
if( ! _bSpline->vertex_selections_available() )
if ( !_bSplineCurve->controlpoint_selections_available() )
return selection;
for(unsigned int i=0; i< _bSpline->n_control_points(); ++i)
if (_bSpline->vertex_selection(i) )
for (unsigned int i = 0; i < _bSplineCurve->n_control_points(); ++i)
if (_bSplineCurve->controlpoint_selection(i) )
selection.push_back(i);
return selection;
......@@ -91,87 +99,155 @@ std::vector< int > getVertexSelection(BSplineT* _bSpline) {
//=========================================================
//== EdgeSelection =======================================
//== Knot Selection =======================================
//=========================================================
template< typename BSplineCurveT >
inline
void
selectKnots(BSplineCurveT* _bSplineCurve, std::vector< int >& _knots)
{
KnotvectorSelection::selectKnots(_bSplineCurve->get_knotvector_ref(), _knots);
}
//-----------------------------------------------------------------------------
template< typename BSplineCurveT >
inline
void
unselectKnots(BSplineCurveT* _bSplineCurve, std::vector< int >& _knots)
{
KnotvectorSelection::unselectKnots(_bSplineCurve->get_knotvector_ref(), _knots);
}
//-----------------------------------------------------------------------------
template< typename BSplineCurveT >
inline
void
selectAllKnots(BSplineCurveT* _bSplineCurve)
{
KnotvectorSelection::selectAllKnots(_bSplineCurve->get_knotvector_ref());
}
//-----------------------------------------------------------------------------
template< typename BSplineCurveT >
inline
void
clearKnotSelection(BSplineCurveT* _bSplineCurve)
{
KnotvectorSelection::clearKnotSelection(_bSplineCurve->get_knotvector_ref());
}
//-----------------------------------------------------------------------------
template< typename BSplineCurveT >
inline
void
invertKnotSelection(BSplineCurveT* _bSplineCurve)
{
KnotvectorSelection::invertKnotSelection(_bSplineCurve->get_knotvector_ref());
}
//-----------------------------------------------------------------------------
template< typename BSplineCurveT >
inline
std::vector< int >
getKnotSelection(BSplineCurveT* _bSplineCurve)
{
std::vector< int > selection;
selection = KnotvectorSelection::getKnotSelection(_bSplineCurve->get_knotvector_ref());
return selection;
}
//=========================================================
//== Edge Selection =======================================
//=========================================================
template< typename BSplineT >
template< typename BSplineCurveT >
inline
void selectEdges(BSplineT* _bSpline, std::vector< int >& _edges) {
const int max = _bSpline->n_control_points();
if(_bSpline->edge_selections_available())
void
selectEdges(BSplineCurveT* _bSplineCurve, std::vector< int >& _edges)
{
const int max = _bSplineCurve->n_control_points();
if (_bSplineCurve->edge_selections_available())
for ( unsigned int i = 0 ; i < _edges.size(); ++i )
if ( (_edges[i] > 0) && ( _edges[i] < max ) )
_bSpline->edge_selection(_edges[i]) = true;
_bSplineCurve->edge_selection(_edges[i]) = true;
}
//-----------------------------------------------------------------------------
template< typename BSplineT >
template< typename BSplineCurveT >
inline
void unselectEdges(BSplineT* _bSpline, std::vector< int >& _edges) {
const int max = _bSpline->n_control_points();
if(_bSpline->edge_selections_available())
void
unselectEdges(BSplineCurveT* _bSplineCurve, std::vector< int >& _edges)
{
const int max = _bSplineCurve->n_control_points();
if (_bSplineCurve->edge_selections_available())
for ( unsigned int i = 0 ; i < _edges.size(); ++i )
if ( (_edges[i] > 0) && ( _edges[i] < max ) )
_bSpline->edge_selection(_edges[i]) = false;
_bSplineCurve->edge_selection(_edges[i]) = false;
}
//-----------------------------------------------------------------------------
template< typename BSplineT >
template< typename BSplineCurveT >
inline
void selectAllEdges(BSplineT* _bSpline)
void
selectAllEdges(BSplineCurveT* _bSplineCurve)
{
if(_bSpline->edge_selections_available())
for(unsigned int i=0; i< _bSpline->n_control_points(); ++i)
_bSpline->edge_selection(i) = true;
if (_bSplineCurve->edge_selections_available())
for (unsigned int i = 0; i < _bSplineCurve->n_control_points(); ++i)
_bSplineCurve->edge_selection(i) = true;
}
//-----------------------------------------------------------------------------
template< typename BSplineT >
template< typename BSplineCurveT >
inline
void clearEdgeSelection(BSplineT* _bSpline)
void
clearEdgeSelection(BSplineCurveT* _bSplineCurve)
{
if(_bSpline->edge_selections_available())
for(unsigned int i=0; i< _bSpline->n_control_points(); ++i)
_bSpline->edge_selection(i) = false;
if (_bSplineCurve->edge_selections_available())
for (unsigned int i = 0; i < _bSplineCurve->n_control_points(); ++i)
_bSplineCurve->edge_selection(i) = false;
}
//-----------------------------------------------------------------------------
template< typename BSplineT >
template< typename BSplineCurveT >
inline
void invertEdgeSelection(BSplineT* _bSpline)
void
invertEdgeSelection(BSplineCurveT* _bSplineCurve)
{
if(_bSpline->edge_selections_available())
for(unsigned int i=0; i< _bSpline->n_control_points(); ++i)
_bSpline->edge_selection(i) = !_bSpline->edge_selection(i);
if (_bSplineCurve->edge_selections_available())
for (unsigned int i = 0; i < _bSplineCurve->n_control_points(); ++i)
_bSplineCurve->edge_selection(i) = !_bSplineCurve->edge_selection(i);
}
//-----------------------------------------------------------------------------
template< typename BSplineT >
template< typename BSplineCurveT >
inline
std::vector< int > getEdgeSelection(BSplineT* _bSpline) {
std::vector< int >
getEdgeSelection(BSplineCurveT* _bSplineCurve)
{
std::vector< int > selection;
if( ! _bSpline->edge_selections_available() )
if (!_bSplineCurve->edge_selections_available())
return selection;
for(unsigned int i=0; i< _bSpline->n_control_points(); ++i)
if (_bSpline->edge_selection(i) )
for (unsigned int i= 0 ; i < _bSplineCurve->n_control_points(); ++i)
if (_bSplineCurve->edge_selection(i) )
selection.push_back(i);
return selection;
}
}
//------------------------------------------------------------------------------
}
//=============================================================================
//
// 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);