Commit be5e2854 authored by Frédéric Larue's avatar Frédéric Larue

Each Displayable can now provide to the viewer its own geometric transformation.

Used for display, picking, bounding box positioning.
parent 8a297cce
......@@ -21,6 +21,27 @@
void GLViewer::DisplayableInfo::Initialize( DisplayableInterface *displayable,
DisplayableList::iterator &priorityPos,
UIParamSet &params )
{
this->displayable = displayable;
this->posInPriorityList = priorityPos;
this->selectionMgr = displayable->selectionManager();
displayable->initialize( params );
displayable->transformation( this->userTransform );
this->packingTransform.setToIdentity();
this->fullTransform = this->userTransform * this->packingTransform;
displayable->boundingBox( this->boundingBox );
}
const char* GLViewer::s_PickingVPG =
"#version 330\n"
......@@ -303,13 +324,6 @@ bool GLViewer::addDisplayable( GenericUIData *m )
{
makeCurrent();
std::list<DisplayableInfo*> &priorityList = m_DisplayablesByPriority[ factory->second->displayPriority() ];
dispInfo = &m_Displayables[ m ];
dispInfo->displayable = displayable;
dispInfo->posInPriorityList = priorityList.insert( priorityList.end(), dispInfo );
dispInfo->packingXform.setToIdentity();
if( !m->GetDisplayOptions() )
{
UIParamSet *params = new UIParamSet( m->GetBaseName() + " display options:", NULL );
......@@ -322,6 +336,7 @@ bool GLViewer::addDisplayable( GenericUIData *m )
m->SetDisplayOptions( params );
}
connect( m->GetDisplayOptions(), SIGNAL(parameterUpdated(UIParam*)), this, SLOT(update()) );
connect( m->GetDisplayOptions(), SIGNAL(parameterUpdated(UIParam*)), displayable, SLOT(updateParameter(UIParam*)) );
......@@ -339,8 +354,14 @@ bool GLViewer::addDisplayable( GenericUIData *m )
connect( displayable, SIGNAL(displayNeedUpdate()), this, SLOT(update()) );
}
displayable->initialize( *m->GetDisplayOptions() );
dispInfo->selectionMgr = displayable->selectionManager();
DisplayableList &priorityList = m_DisplayablesByPriority[ factory->second->displayPriority() ];
dispInfo = &m_Displayables[ m ];
dispInfo->Initialize(
displayable,
priorityList.insert( priorityList.end(), dispInfo ),
*m->GetDisplayOptions()
);
if( !m->GetDisplayOptions()->empty() )
{
......@@ -368,12 +389,12 @@ bool GLViewer::addDisplayable( GenericUIData *m )
}
void GLViewer::setTransform( GenericUIData *m, const QMatrix4x4 &xf )
{
DisplayableMap::iterator d = m_Displayables.find( m );
if( d != m_Displayables.end() )
d->second.packingXform = xf;
}
//void GLViewer::setTransform( GenericUIData *m, const QMatrix4x4 &xf )
//{
// DisplayableMap::iterator d = m_Displayables.find( m );
// if( d != m_Displayables.end() )
// d->second.packingTransform = xf;
//}
void GLViewer::updateDisplayable( GenericUIData *m )
......@@ -422,11 +443,7 @@ void GLViewer::frameItem( GenericUIData* item )
{
DisplayableMap::iterator dispInfo = m_Displayables.find( item );
if( dispInfo != m_Displayables.end() )
{
Box3f box;
dispInfo->second.displayable->boundingBox( box );
frameBox( box, &dispInfo->second.packingXform );
}
frameBox( dispInfo->second.boundingBox, &dispInfo->second.GetTransform() );
}
......@@ -438,19 +455,14 @@ void GLViewer::frameItems( std::list<GenericUIData*> &items )
{
DisplayableMap::iterator dispInfo = m_Displayables.find( *m );
if( dispInfo != m_Displayables.end() )
{
Box3f objectBox;
dispInfo->second.displayable->boundingBox( objectBox );
if( !objectBox.IsNull() )
if( !dispInfo->second.boundingBox.IsNull() )
{
Box3f::CornerSet objectBoxCorners;
objectBox.Corners( objectBoxCorners );
dispInfo->second.boundingBox.Corners( objectBoxCorners );
for( auto c=objectBoxCorners.begin(); c!=objectBoxCorners.end(); ++c )
box.Add( dispInfo->second.packingXform.map(*c) );
box.Add( dispInfo->second.GetTransform().map(*c) );
}
}
}
frameBox( box );
......@@ -474,7 +486,7 @@ void GLViewer::frameAll()
objectBox.Corners( objectBoxCorners );
for( auto c=objectBoxCorners.begin(); c!=objectBoxCorners.end(); ++c )
box.Add( dispInfo->second.packingXform.map(*c) );
box.Add( dispInfo->second.GetTransform().map(*c) );
}
}
......@@ -537,11 +549,13 @@ void GLViewer::repackDisplayables()
float scalingFactor = rowHeight / boxes[i].Dimensions().y();
float rescaledWidth = boxes[i].Dimensions().x() * scalingFactor;
(*d)->packingXform.setToIdentity();
(*d)->packingXform(0,0) = scalingFactor;
(*d)->packingXform(1,1) = scalingFactor;
(*d)->packingXform(0,3) = x - boxes[i].Min().x()*scalingFactor + 0.5f*(columnWidth[c]-rescaledWidth);
(*d)->packingXform(1,3) = y - boxes[i].Min().y()*scalingFactor;
QMatrix4x4 packTr;
packTr.setToIdentity();
packTr(0,0) = scalingFactor;
packTr(1,1) = scalingFactor;
packTr(0,3) = x - boxes[i].Min().x()*scalingFactor + 0.5f*(columnWidth[c]-rescaledWidth);
packTr(1,3) = y - boxes[i].Min().y()*scalingFactor;
(*d)->SetPackingTransform( packTr );
x += columnWidth[c] + gridSpacing;
......@@ -779,7 +793,7 @@ QMatrix4x4 GLViewer::modelMatrix( const DisplayableInterface *d ) const
{
auto dispInfo = m_Displayables.find(d->getSource());
if( dispInfo != m_Displayables.end() )
return dispInfo->second.packingXform;
return dispInfo->second.GetTransform();
else
return QMatrix4x4();
}
......@@ -916,7 +930,7 @@ void GLViewer::paintGL()
for( DisplayableList::iterator dinfo=dlist->second.begin(); dinfo!=dlist->second.end(); ++dinfo )
{
glPushMatrix();
glMultMatrixf( (*dinfo)->packingXform.data() );
glMultMatrixf( (*dinfo)->GetTransform().data() );
glPushAttrib( GL_ALL_ATTRIB_BITS );
(*dinfo)->displayable->onDisplay( *(*dinfo)->displayable->getSource()->GetDisplayOptions() );
displayLabel( (*dinfo)->displayable );
......@@ -1119,7 +1133,7 @@ void GLViewer::updateSelection( SelectionTool &tool )
if( d->second.selectionMgr && d->second.selectionMgr->selectableEntity() == tool.entityToSelect() )
{
glPushMatrix();
glMultMatrixf( d->second.packingXform.data() );
glMultMatrixf( d->second.GetTransform().data() );
d->second.selectionMgr->onUpdatingSelection( &tool );
glPopMatrix();
}
......@@ -1206,7 +1220,7 @@ void GLViewer::updateSelectionZBuffer()
for( PriorityMap::iterator dlist=m_DisplayablesByPriority.begin(); dlist!=m_DisplayablesByPriority.end(); ++dlist )
for( DisplayableList::iterator dinfo=dlist->second.begin(); dinfo!=dlist->second.end(); ++dinfo )
{
m_ZBufferShader.SetUniform( "fullTransformMatrix", (projectionMatrix() * viewMatrix() * (*dinfo)->packingXform).data() );
m_ZBufferShader.SetUniform( "fullTransformMatrix", (projectionMatrix() * viewMatrix() * (*dinfo)->GetTransform()).data() );
glPushAttrib( GL_ALL_ATTRIB_BITS );
(*dinfo)->displayable->onPicking( *(*dinfo)->displayable->getSource()->GetDisplayOptions(), m_ZBufferShader, "vertexPosition" );
glPopAttrib();
......@@ -2017,7 +2031,7 @@ bool GLViewer::getPickedPoint( const float x,
for( DisplayableMap::iterator d=m_Displayables.begin(); d!=m_Displayables.end(); ++d )
if( d->second.displayable->isPickable( *d->first->GetDisplayOptions() ) )
{
m_PickingShader.SetUniform( "viewMatrix", (viewMatrix() * d->second.packingXform).data() );
m_PickingShader.SetUniform( "viewMatrix", (viewMatrix() * d->second.GetTransform()).data() );
m_PickingShader.SetUniform( "projectionMatrix", projMat.data() );
orderedManageables.push_back( d->second.displayable->getSource() );
......@@ -2085,7 +2099,7 @@ bool GLViewer::getPickedPoint( const float x,
{
picked.srcObject = orderedManageables[ pickedObjIdBuffer[nearestId]-1 ];
picked.position = pickedPointBuffer[nearestId].position;
picked.global = m_Displayables[picked.srcObject].packingXform.map( picked.position );
picked.global = m_Displayables[picked.srcObject].GetTransform().map( picked.position );
}
......
......@@ -38,19 +38,33 @@ public:
};
protected:
struct DisplayableInfo
{
DisplayableInterface *displayable;
SelectionManager *selectionMgr;
std::list<DisplayableInfo*>::iterator posInPriorityList;
QMatrix4x4 packingXform;
};
class DisplayableInfo;
typedef std::map<QString,DisplayableFactoryInterface*> FactoryMap;
typedef std::list<DisplayableInfo*> DisplayableList;
typedef std::map<int,DisplayableList> PriorityMap;
typedef std::map<const GenericUIData*,DisplayableInfo> DisplayableMap;
class DisplayableInfo
{
QMatrix4x4 userTransform;
QMatrix4x4 packingTransform;
QMatrix4x4 fullTransform;
public:
void Initialize( DisplayableInterface *displayable,
DisplayableList::iterator &priorityPos,
UIParamSet &params );
inline void SetPackingTransform( const QMatrix4x4& tr ) { packingTransform = tr; fullTransform = userTransform * tr; }
inline const QMatrix4x4& GetTransform() const { return fullTransform; }
DisplayableInterface *displayable;
SelectionManager *selectionMgr;
DisplayableList::iterator posInPriorityList;
Box3f boundingBox;
};
enum SelectionToolName
{
SELECTION_TOOL_DISK = 0,
......
......@@ -99,8 +99,10 @@ public:
*/
virtual void release( UIParamSet &params ) {}
/** Recover the bounding box of the displayed item in global space. */
/** Recover the bounding box of the displayed item in locam frame. */
virtual void boundingBox( Box3f &box ) const = 0;
/** Recover the transformation matrix of the displayed item from local to global frame. */
virtual void transformation( QMatrix4x4 &tr ) const { tr.setToIdentity(); }
/** Recover the label to be displayed. */
virtual QString label() const { return QString(); }
/** Recover parameters describing the display options of the current item. */
......
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