version 3.3

VRS::ScenePicker Class Reference

This class provides functionality for picking scene objects. More...

#include <vrs/sg/scenepicker.h>

Inheritance diagram for VRS::ScenePicker:

VRS::InteractionTechnique VRS::SharedObj VRS::Visitable

List of all members.

Public Types

typedef Callback3< SO
< Iterator< PickResult >
>, unsigned int, unsigned int > 
SelectionCallback
typedef CallbackR1< unsigned
int, SO< Shape > > 
IdCreationCallback

Public Member Functions

 ScenePicker (SO< SceneThing > scene, SO< IdCreationCallback > idCreationCallback, SO< SelectionCallback > pickingCallback, SO< GLCanvas > canvas, unsigned int textureUnit, unsigned int numberOfIdsToReserve=10000, bool renderPositionBuffer=true, SO< Iterator< ScenePicker::MouseButtonFunctionID > > buttonFunctionsToRegister=0)
void setupFBO (SO< GLCanvas > canvas)
virtual void onActivation ()
 Called each time a InteractionTechnique is activated, i.e.
virtual void onDeactivation ()
 Called each time a InteractionTechnique is deactivated, i.e.
virtual void onDragStart (int x, int y, SO< ButtonEvent >, MouseButtonFunctionID id)
virtual void onDragMotion (int x, int y, SO< MotionEvent >, MouseButtonFunctionID id, int startX, int startY)
virtual void onDragEnd (int x, int y, SO< ButtonEvent >, MouseButtonFunctionID id, int startX, int startY)
virtual void onEvent (SO< Event > e)
 For each incoming event the base class checks the event type and passes the event to the corresponding virtual method.
void updatePickingBuffers ()
 This method updates the lookup image(s) for picking.
bool preservingViewDirectionRequired ()
 Rendered Id buffers are view dependent.
bool getRangeSelectionEnabled () const
void setRangeSelectionEnabled (bool val)
 Enables or Disables selection of multiple Objects by dragging a rectangle over the view plane.
void registerSelectionCallback (const SO< SelectionCallback > newSelectionCallback)
 Register a callback which is called in case of picking If the "callOnNoHit" flag is set the method is also called when no (registered) geometry was hit.
void unregisterSelectionCallback (const SO< SelectionCallback > exisitingSelectioncallback)
void clearSelectionCallbacks ()
void assignIdValues (SO< SceneThing > scene, SO< IdCreationCallback > idCreationCallback, unsigned int numberOfIdValues, unsigned int startId=0)
 Creates a mapping from ids returned by the given callback to PolygonSets contained in the given scene.
void setSceneForRender (SO< SceneThing > scene)
 Sets the scene containing the visible content.
const Vector addPolygonSet (unsigned int id, SO< PolygonSet > pset, bool updateLookupTexture=false)
 Makes the polygon set identifiable by assigning the id.
void incrementTextureCoordinate ()
SO< Iterator< Vector > > addPolygonSets (SO< Iterator< unsigned int > > ids, SO< Iterator< SO< PolygonSet > > > psets, bool updateLookupTexture=false)
 Makes the polygon set identifiable by assigning an id per polygonset.
SO< Iterator< Vector > > addPolygonSets (SO< Iterator< unsigned int > > ids, SO< Iterator< SO< Iterator< SO< PolygonSet > > > > > psets, bool updateLookupTexture=false)
 Assign ids to groups of polygonsets.
void addSceneThing (SO< SceneThing > scene, unsigned int id, bool updateLookupTexture=false)
 Assigns the given id to every PolygonSet in the given scene.
const SO< GLImagegetPixelPositions () const
const SO< GLImagegetIdBufferImage ()
const bool getCameraSpaceCoordinateForPixel (unsigned int x, unsigned int y, Vector &coordinate) const
 Reads the position in camera space coordinates associated with the pixel displayed To obtain world space coordinates the camera for the specific object / pixel must be known.
const unsigned int getIdForPixel (unsigned int x, unsigned int y) const
 Reads the object id of the object displayed at the given pixel position.
bool getCallOnNoHit () const
void setCallOnNoHit (bool val)
bool ScenePicker::hasUnassignedIds (unsigned int numberOfRequiredIds)
unsigned int getTextureUnit ()
 VRS_TYPEINFO (ScenePicker, InteractionTechnique)

Static Public Member Functions

static VRS::UINT32 getIdForColor (const Color &c)
static Color getColorForId (VRS::UINT32 id)
static unsigned int ScenePicker::getPixelForCoordinate (float coordinate, unsigned int size)
 Calculates the pixel corresponding to the given coordinate in one dimension.
static float getCoordinateForPixel (unsigned pixel, unsigned int size)

Static Public Attributes

static const MouseButtonFunctionID pickFunction

Classes

class  GLImage
struct  PickResult


Detailed Description

This class provides functionality for picking scene objects.

Once initialized with a scene an id is assigned to each polygonset using an ID texture and an additional texture coordinate channel. Afterwards the identification color image has to be updated when the scene view changes or the canvas is resized. After registering a scene the polygonsets can be merged or transformed as long as the texture coordinates stay the same.


Member Typedef Documentation

typedef Callback3<SO<Iterator<PickResult> >,unsigned int, unsigned int> VRS::ScenePicker::SelectionCallback


Constructor & Destructor Documentation

VRS::ScenePicker::ScenePicker ( SO< SceneThing scene,
SO< IdCreationCallback idCreationCallback,
SO< SelectionCallback pickingCallback,
SO< GLCanvas canvas,
unsigned int  textureUnit,
unsigned int  numberOfIdsToReserve = 10000,
bool  renderPositionBuffer = true,
SO< Iterator< ScenePicker::MouseButtonFunctionID > >  buttonFunctionsToRegister = 0 
)

Parameters:
 SO<SceneThing> scene
 SO<IdCreationCallback> idCreationCallback Function or method receiving a SO<Shape> and returning an id in the range of [1,MAXUINT]
 SO<SelectionCallback> pickingCallback
 SO<GLCanvas> canvas
 unsigned int textureUnit
 unsigned int numberOfIdsToReserve Maxium number of Ids that should be given. Defines the pixel size of the id image.
 bool renderPositionBuffer
 buttonFunctionsToRegister Additional ids to register (each id can be connected with one mouse button / modifier combination). The Sceen


Member Function Documentation

void VRS::ScenePicker::setupFBO ( SO< GLCanvas canvas  ) 

virtual void VRS::ScenePicker::onActivation (  )  [virtual]

Called each time a InteractionTechnique is activated, i.e.

selected as active Interaction of a InteractionMode. It can be implemented by derivatives to initialize internal parameters.

Reimplemented from VRS::InteractionTechnique.

virtual void VRS::ScenePicker::onDeactivation (  )  [virtual]

Called each time a InteractionTechnique is deactivated, i.e.

deselected as active Interaction of a InteractionMode. It can be implemented by derivatives to reset internal parameters.

Reimplemented from VRS::InteractionTechnique.

virtual void VRS::ScenePicker::onDragStart ( int  x,
int  y,
SO< ButtonEvent ,
MouseButtonFunctionID  id 
) [virtual]

virtual void VRS::ScenePicker::onDragMotion ( int  x,
int  y,
SO< MotionEvent ,
MouseButtonFunctionID  id,
int  startX,
int  startY 
) [virtual]

virtual void VRS::ScenePicker::onDragEnd ( int  x,
int  y,
SO< ButtonEvent ,
MouseButtonFunctionID  id,
int  startX,
int  startY 
) [virtual]

virtual void VRS::ScenePicker::onEvent ( SO< Event e  )  [virtual]

For each incoming event the base class checks the event type and passes the event to the corresponding virtual method.

In addition each event() method is called for each event.

Reimplemented from VRS::InteractionTechnique.

void VRS::ScenePicker::updatePickingBuffers (  ) 

This method updates the lookup image(s) for picking.

bool VRS::ScenePicker::preservingViewDirectionRequired (  )  [inline]

Rendered Id buffers are view dependent.

Force the view direction to be preserved. Does always return 'false'

bool VRS::ScenePicker::getRangeSelectionEnabled (  )  const [inline]

void VRS::ScenePicker::setRangeSelectionEnabled ( bool  val  )  [inline]

Enables or Disables selection of multiple Objects by dragging a rectangle over the view plane.

void VRS::ScenePicker::registerSelectionCallback ( const SO< SelectionCallback newSelectionCallback  ) 

Register a callback which is called in case of picking If the "callOnNoHit" flag is set the method is also called when no (registered) geometry was hit.

The id for this case is 0; The position included in the result is in Camera coordinates. Apply the inverse Orientation Matrix to get World Coordinates

Parameters:
 const SO<SelectionCallback> newSelectionCallback Function or Method callback taking the id of the object and the position of the pixel which has been hit.

void VRS::ScenePicker::unregisterSelectionCallback ( const SO< SelectionCallback exisitingSelectioncallback  ) 

void VRS::ScenePicker::clearSelectionCallbacks (  ) 

void VRS::ScenePicker::assignIdValues ( SO< SceneThing scene,
SO< IdCreationCallback idCreationCallback,
unsigned int  numberOfIdValues,
unsigned int  startId = 0 
)

Creates a mapping from ids returned by the given callback to PolygonSets contained in the given scene.

Parameters:
 SO<SceneThing> scene Scene containing the objects to be destinguished
 SO<CallbackR1<unsigned int,SO<PolygonSet> > > idCreationCallback CallbackFunction or method that returns an identifier for the given Polygonset. The id returned must be included in the interval [1,MAXUINT-1). Otherwise an exeption will be thrown.
numberOfIdValues Number of distinct element ids that should be reserved. Influences the size of the id texture generated.

void VRS::ScenePicker::setSceneForRender ( SO< SceneThing scene  ) 

Sets the scene containing the visible content.

A camera must be contained in the scene. The scene can be an optimized version of the id-assigned scene which has been processed by assignIdValues as long as the generated texture coordinates are still available at the right place.

Parameters:
 SO<SceneThing> scene Scene containing all PolygonSets which shall be pickable. It must contain a scene camera and therefore be displayed equally on the canvas

const Vector VRS::ScenePicker::addPolygonSet ( unsigned int  id,
SO< PolygonSet pset,
bool  updateLookupTexture = false 
)

Makes the polygon set identifiable by assigning the id.

The id is only assigned if there are enough ids left in the id image. Otherwise an exception is thrown.

Parameters:
 unsigned int id
 SO<PolygonSet> pset
 bool updateLookupTexture Call updateTextures after entry creation
Returns:
: Texture coordinates set at the given position

void VRS::ScenePicker::incrementTextureCoordinate (  ) 

SO<Iterator<Vector> > VRS::ScenePicker::addPolygonSets ( SO< Iterator< unsigned int > >  ids,
SO< Iterator< SO< PolygonSet > > >  psets,
bool  updateLookupTexture = false 
)

Makes the polygon set identifiable by assigning an id per polygonset.

The iterators of ids and polygonsets must have an equal length

Returns:
: SO<Iterator<const Vector> > Texture coordinates assigned to each polygonset
Parameters:
 SO<Iterator<unsigned int> > ids ids to assing to corresponding polygonset
 SO<Iterator<SO<PolygonSet> > > psets Polygonsets
 bool updateLookupTexture

SO<Iterator<Vector> > VRS::ScenePicker::addPolygonSets ( SO< Iterator< unsigned int > >  ids,
SO< Iterator< SO< Iterator< SO< PolygonSet > > > > >  psets,
bool  updateLookupTexture = false 
)

Assign ids to groups of polygonsets.

Returns:
: SO<Iterator<const Vector> > Texture coordinates assigned to each polygonset group
Parameters:
 SO<Iterator<unsigned int> > ids
 SO<Iterator<SO<Iterator<SO<PolygonSet> > > > > psets
 bool updateLookupTexture

void VRS::ScenePicker::addSceneThing ( SO< SceneThing scene,
unsigned int  id,
bool  updateLookupTexture = false 
)

Assigns the given id to every PolygonSet in the given scene.

Parameters:
 SO<SceneThing> scene
 unsigned int id
 bool updateLookupTexture

const SO<GLImage> VRS::ScenePicker::getPixelPositions (  )  const [inline]

const SO<GLImage> VRS::ScenePicker::getIdBufferImage (  ) 

const bool VRS::ScenePicker::getCameraSpaceCoordinateForPixel ( unsigned int  x,
unsigned int  y,
Vector coordinate 
) const

Reads the position in camera space coordinates associated with the pixel displayed To obtain world space coordinates the camera for the specific object / pixel must be known.

Returns:
: const bool The value for the coordinate vector could be set
Parameters:
 unsigned int x X position in screen coordinates
 unsigned int y Y Position in screen coordinates
 Vector & coordinate in/out parameter holding the position value after successful read

const unsigned int VRS::ScenePicker::getIdForPixel ( unsigned int  x,
unsigned int  y 
) const

Reads the object id of the object displayed at the given pixel position.

Returns:
: const unsigned int Object id -> '0' if no known object is displayed at the position
Parameters:
 unsigned int x
 unsigned int y

bool VRS::ScenePicker::getCallOnNoHit (  )  const [inline]

void VRS::ScenePicker::setCallOnNoHit ( bool  val  )  [inline]

static VRS::UINT32 VRS::ScenePicker::getIdForColor ( const Color c  )  [static]

static Color VRS::ScenePicker::getColorForId ( VRS::UINT32  id  )  [static]

static unsigned int VRS::ScenePicker::ScenePicker::getPixelForCoordinate ( float  coordinate,
unsigned int  size 
) [static]

Calculates the pixel corresponding to the given coordinate in one dimension.

Parameters:
 float coordinate Texture coordinate in [0,1]
 unsigned int size number of pixel in the required dimension

static float VRS::ScenePicker::getCoordinateForPixel ( unsigned  pixel,
unsigned int  size 
) [static]

bool VRS::ScenePicker::ScenePicker::hasUnassignedIds ( unsigned int  numberOfRequiredIds  ) 

unsigned int VRS::ScenePicker::getTextureUnit (  )  [inline]

VRS::ScenePicker::VRS_TYPEINFO ( ScenePicker  ,
InteractionTechnique   
)


Member Data Documentation


The documentation for this class was generated from the following file:

Generated on Tue May 22 06:00:30 2012 by Doxygen 1.5.6
© 2001-2010 Hasso-Plattner-Institut | Impressum | Contact