Commit 6e7879c9 authored by Jan Möbius's avatar Jan Möbius

Dennis:

Added-color-based-region-picking-to-examiner-plugin.patch

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5270 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 443825b7
......@@ -332,6 +332,26 @@ bool scenegraphPick( const unsigned int _examiner, ACG::SceneGraph::PickTarget _
return examiner_widgets_[_examiner]->pick( _pickTarget,_mousePos,_nodeIdx,_targetIdx,_hitPointPtr );
}
bool scenegraphRegionPick( ACG::SceneGraph::PickTarget _pickTarget,
const QRegion& _region,
QList<QPair<unsigned int, unsigned int> >& _list)
{
return examiner_widgets_[activeExaminer_]->pick_region( _pickTarget, _region, _list);
}
bool scenegraphRegionPick( const unsigned int _examiner,
ACG::SceneGraph::PickTarget _pickTarget,
const QRegion& _region,
QList<QPair<unsigned int, unsigned int> >& _list)
{
if ( _examiner >= examiner_widgets_.size() ) {
std::cerr << "Wrong examiner id" << std::endl;
return false;
}
return examiner_widgets_[_examiner]->pick_region( _pickTarget, _region, _list);
}
//Warning : Dont use template function as external static pointer for examiner widget is not resolved correctly!!
void traverse( ACG::SceneGraph::MouseEventAction &_action ) {
......
......@@ -47,6 +47,8 @@
#ifndef PLUGINFUNCTIONS_HH
#define PLUGINFUNCTIONS_HH
#include <QPair>
#include <OpenFlipper/common/Types.hh>
#include <ACG/Scenegraph/SceneGraph.hh>
......@@ -217,6 +219,25 @@ bool scenegraphPick( ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mou
DLLEXPORT
bool scenegraphPick( const unsigned int _examiner ,ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, unsigned int &_nodeIdx, unsigned int &_targetIdx, ACG::Vec3d *_hitPointPtr );
/** Execute picking operation on scenegraph
* This picking function will pick in the last active examiner context which is automatically
* Set by mouseevents from the core
*/
DLLEXPORT
bool scenegraphRegionPick( ACG::SceneGraph::PickTarget _pickTarget,
const QRegion& _region,
QList<QPair<unsigned int, unsigned int> >& _list);
/** Execute picking operation on scenegraph
* This picking function will pick in the specified examiner context
*/
DLLEXPORT
bool scenegraphRegionPick( const unsigned int _examiner,
ACG::SceneGraph::PickTarget _pickTarget,
const QRegion& _region,
QList<QPair<unsigned int, unsigned int> >& _list);
/** Execute Scenegraph traversal with action and use the last active examiner
* If you are reacting on a mouseEvent you should use this function as it will
* automatically set the right view
......
......@@ -81,6 +81,10 @@ void Core::applyOptions(){
target = ACG::SceneGraph::PICK_EDGE;
} else if ( OpenFlipper::Options::pickingRenderMode() == "PICK_FACE") {
target = ACG::SceneGraph::PICK_FACE;
} else if ( OpenFlipper::Options::pickingRenderMode() == "PICK_FRONT_VERTEX") {
target = ACG::SceneGraph::PICK_FRONT_VERTEX;
} else if ( OpenFlipper::Options::pickingRenderMode() == "PICK_FRONT_EDGE") {
target = ACG::SceneGraph::PICK_FRONT_EDGE;
} else {
target = ACG::SceneGraph::PICK_ANYTHING;
}
......
......@@ -193,7 +193,7 @@ glViewer::glViewer( QtGLGraphicsScene* _scene,
slotPropertiesUpdated();
setAcceptDrops(true);
setHome();
}
......@@ -391,6 +391,7 @@ void glViewer::viewingDirection( const ACG::Vec3d& _dir, const ACG::Vec3d& _up )
void glViewer::updateActionMode(Viewer::ActionMode)
{
std::cerr << "UpdateActionMode" << properties_.actionMode() << std::endl;
trackMouse(false);
......@@ -414,7 +415,7 @@ void glViewer::updateActionMode(Viewer::ActionMode)
{
setCursor(Qt::ArrowCursor);
if (pick_mode_idx_ != -1) {
trackMouse(pick_modes_[pick_mode_idx_].tracking);
trackMouse(pick_modes_[pick_mode_idx_].tracking);
setCursor(pick_modes_[pick_mode_idx_].cursor);
}
......
......@@ -701,6 +701,21 @@ private:
unsigned int& _targetIdx,
ACG::Vec3d* _hitPointPtr=0 );
/** Apply pick action. <br>
* Picks all objects in the given Region. Information about the picked primitives is stored in the
* provided list. Resulting values are defined only if \c true
* has been returned!
* <br>
*
* @param _pickTarget Select what should be picked: Faces/Vertices/...
* @param _region Area for picking
* @param _list List of found scenegraph objects (node/target pairs)
* @return Successfull?
*/
bool pick_region( ACG::SceneGraph::PickTarget _pickTarget,
const QRegion& _region,
QList<QPair<unsigned int, unsigned int> >& _list);
/** get the coordinates of the picked point by z-buffer re-projection
* @param _mousePos The position to pick
* @param _hitPoint The point returned by the reprojection
......
......@@ -275,6 +275,90 @@ bool glViewer::pickGL( ACG::SceneGraph::PickTarget _pickTarget,
//-----------------------------------------------------------------------------
bool glViewer::pick_region( ACG::SceneGraph::PickTarget _pickTarget,
const QRegion& _region,
QList<QPair<unsigned int, unsigned int> >& _list)
{
GLint w = glWidth(),
h = glHeight(),
l = scenePos().x(),
b = scene()->height () - scenePos().y() - h;
GLubyte* buffer;
QRect rect = _region.boundingRect();
const ACG::GLMatrixd& modelview = properties_.glState().modelview();
const ACG::GLMatrixd& projection = properties_.glState().projection();
// prepare GL state
makeCurrent();
glViewport (l, b, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMultMatrixd(projection.get_raw_data());
glMatrixMode(GL_MODELVIEW);
glLoadMatrixd(modelview.get_raw_data());
glDisable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
properties_.glState().pick_init (true);
// do the picking
ACG::SceneGraph::PickAction action(_pickTarget);
ACG::SceneGraph::traverse(sceneGraphRoot_, action, properties_.glState());
// restore GL state
glMatrixMode( GL_PROJECTION );
glLoadMatrixd(projection.get_raw_data());
glMatrixMode( GL_MODELVIEW );
glLoadMatrixd(modelview.get_raw_data());
glEnable(GL_LIGHTING);
if (properties_.glState().pick_error ())
return false;
buffer = new GLubyte[3 * rect.width() * rect.height()];
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glReadPixels (rect.x(), scene()->height () - rect.bottom() , rect.width(),
rect.height(), GL_RGB, GL_UNSIGNED_BYTE, buffer);
QSet<QPair<unsigned int, unsigned int> > found;
for (int y = 0; y < rect.height (); y++)
for (int x = 0; x < rect.width (); x++)
{
if (_region.contains (QPoint (rect.x() + x, rect.y() + y)))
{
int bPos = (((rect.height () - (y + 1)) * rect.width ()) + x) * 3;
if (buffer[bPos + 2] != 0 || buffer[bPos + 1] != 0 || buffer[bPos] != 0)
{
ACG::Vec3uc rgb;
rgb[0] = buffer[bPos];
rgb[1] = buffer[bPos + 1];
rgb[2] = buffer[bPos + 2];
std::vector<unsigned int> rv = properties_.glState().pick_color_to_stack (rgb);
if (rv.size () < 2)
continue;
found << QPair<unsigned int, unsigned int>(rv[1], rv[0]);
}
}
}
delete buffer;
_list = found.toList();
return true;
}
//-----------------------------------------------------------------------------
bool
glViewer::
fast_pick( const QPoint& _mousePos,
......
......@@ -22,7 +22,7 @@
<string/>
</property>
<property name="currentIndex" >
<number>0</number>
<number>6</number>
</property>
<property name="usesScrollButtons" >
<bool>true</bool>
......@@ -719,6 +719,16 @@ p, li { white-space: pre-wrap; }
<string>PICK_FACE</string>
</property>
</item>
<item>
<property name="text" >
<string>PICK_FRONT_VERTEX</string>
</property>
</item>
<item>
<property name="text" >
<string>PICK_FRONT_EDGE</string>
</property>
</item>
</widget>
</item>
</layout>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment