Skip to content

Commit

Permalink
Improved pick image drawing. Re #6212.
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Apr 2, 2013
1 parent e7f6a06 commit 97a6631
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
GLActorCollection::GLActorCollection()
:GLActor(),
m_minBound(DBL_MAX,DBL_MAX,DBL_MAX),
m_maxBound(-DBL_MAX,-DBL_MAX,-DBL_MAX),
m_displayListId(0),
m_useDisplayList(false)
m_maxBound(-DBL_MAX,-DBL_MAX,-DBL_MAX)
{
m_displayListId[0] = 0;
m_displayListId[1] = 0;
m_useDisplayList[0] = false;
m_useDisplayList[1] = false;
}

GLActorCollection::~GLActorCollection()
Expand All @@ -26,10 +28,13 @@ GLActorCollection::~GLActorCollection()
delete (*i);
}
mActorsList.clear();
if(m_displayListId != 0)
{
glDeleteLists(m_displayListId,1);
}
for(size_t i = 0; i < 2; ++i)
{
if (m_displayListId[i] != 0)
{
glDeleteLists(m_displayListId[i],1);
}
}

}

Expand All @@ -38,37 +43,31 @@ GLActorCollection::~GLActorCollection()
*/
void GLActorCollection::draw(bool picking)const
{
if (!isVisible()) return;
OpenGLError::check("GLActorCollection::draw(0)");
if (picking)
{
drawGL(picking);
}
else
{
if (m_useDisplayList)
if (!isVisible()) return;
OpenGLError::check("GLActorCollection::draw(0)");
size_t i = picking? 1 : 0;
if (m_useDisplayList[i])
{
glCallList(m_displayListId);
glCallList(m_displayListId[i]);
}
else if (m_displayListId == 0)
else if (m_displayListId[i] == 0)
{
m_displayListId = glGenLists(1);
m_displayListId[i] = glGenLists(1);
// child actors can also create display lists, so delay
// until all the children have finished making theirs
drawGL(picking);
}
else
{
m_useDisplayList = true;
glNewList(m_displayListId,GL_COMPILE); //Construct display list for object representation
m_useDisplayList[i] = true;
glNewList(m_displayListId[i],GL_COMPILE); //Construct display list for object representation
drawGL(picking);
glEndList();
if(glGetError()==GL_OUT_OF_MEMORY) //Throw an exception
throw Mantid::Kernel::Exception::OpenGLError("OpenGL: Out of video memory");
glCallList(m_displayListId);
glCallList(m_displayListId[i]);
}
}
OpenGLError::check("GLActorCollection::draw()");
OpenGLError::check("GLActorCollection::draw()");
}

void GLActorCollection::drawGL(bool picking )const
Expand Down Expand Up @@ -168,11 +167,14 @@ void GLActorCollection::getBoundingBox(Mantid::Kernel::V3D& minBound,Mantid::Ker

void GLActorCollection::invalidateDisplayList()const
{
if(m_displayListId != 0)
for(size_t i = 0; i < 2; ++i)
{
glDeleteLists(m_displayListId,1);
m_displayListId = 0;
m_useDisplayList = false;
if (m_displayListId[i] != 0)
{
glDeleteLists(m_displayListId[i],1);
m_displayListId[i] = 0;
m_useDisplayList[i] = false;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class GLActorCollection: public GLActor
mutable std::vector<GLActor*> mActorsList; ///< Vector of GLActors for fast access.
Mantid::Kernel::V3D m_minBound;
Mantid::Kernel::V3D m_maxBound;
mutable GLuint m_displayListId;
mutable bool m_useDisplayList;
mutable GLuint m_displayListId[2];
mutable bool m_useDisplayList[2];
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void InputController3DMove::mouseMoveEvent(QMouseEvent *event)
void InputController3DMove::mouseReleaseEvent(QMouseEvent *)
{
m_isButtonPressed = false;
emit finish();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class InputController3DMove: public InputController
void rotate(int x, int y);
/// Translate
void translate(int x, int y);
/// Finish movement
void finish();

private:
bool m_isButtonPressed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Projection3D::Projection3D(const InstrumentActor* rootActor,int winWidth,int win
connect(moveController,SIGNAL(initZoom(int,int)),this,SLOT(initZoom(int,int)));
connect(moveController,SIGNAL(zoom(int,int)),this,SLOT(zoom(int,int)));
connect(moveController,SIGNAL(wheelZoom(int,int,int)),this,SLOT(wheelZoom(int,int,int)));
connect(moveController,SIGNAL(finish()),this,SLOT(finishMove()));
}

Projection3D::~Projection3D()
Expand Down Expand Up @@ -439,6 +440,14 @@ void Projection3D::rotate(int x, int y)
updateView();
}

/**
* Call upon finishing all moves to update the pick image.
*/
void Projection3D::finishMove()
{
updateView(true);
}

/**
* Get bounds of this projection surface. Used with 2D overlays.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ protected slots:
void wheelZoom(int x, int y, int d);
void initRotation(int x, int y);
void rotate(int x, int y);
void finishMove();

protected:
virtual void init() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ ProjectionSurface::ProjectionSurface(const InstrumentActor* rootActor,const Mant

ProjectionSurface::~ProjectionSurface()
{
//std::cerr<<"ProjectionSurface deleted\n";
if (m_viewImage)
{
delete m_viewImage;
Expand Down Expand Up @@ -120,6 +119,7 @@ void ProjectionSurface::clear()
m_pickImage = NULL;
}
m_viewChanged = true;
m_redrawPicking = true;
m_viewRect = RectF();
m_selectRect = QRect();
}
Expand Down Expand Up @@ -317,7 +317,11 @@ void ProjectionSurface::leaveEvent(QEvent *e)
void ProjectionSurface::updateView(bool picking)
{
m_viewChanged = true;
m_redrawPicking = picking;
if (picking)
{
// don't change to false if it's already true
m_redrawPicking = true;
}
}

void ProjectionSurface::updateDetectors()
Expand Down

0 comments on commit 97a6631

Please sign in to comment.