Skip to content
Snippets Groups Projects
Commit 7680828c authored by Julien Michel's avatar Julien Michel
Browse files

ENH: (Visu Refactoring) Adding a base class for Gl widgets objects

parent d0c736e8
No related branches found
No related tags found
No related merge requests found
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __otbGlWidget_cxx
#define __otbGlWidget_cxx
#include "otbGlWidget.h"
namespace otb
{
GlWidget
::GlWidget() : Fl_Gl_Window(0,0,0,0), m_Identifier("Default"), m_UseGlAcceleration(false)
{
#ifdef OTB_GL_USE_ACCEL
m_UseGlAcceleration = true;
#endif
}
GlWidget::~GlWidget()
{}
void GlWidget::PrintSelf(std::ostream& os, itk::Indent indent) const
{
// Call the superclass implementation
Superclass::PrintSelf(os,indent);
// Display information about the widget
os<<indent<<"Widget "<<m_Identifier<<": "<<std::endl;
#ifndef OTB_GL_USE_ACCEL
os<<indent<<indent<<"OpenGl acceleration is not allowed."<<std::endl;
#else
if(m_UseGlAcceleration)
{
os<<indent<<indent<<"OpenGl acceleration is allowed and enabled."<<std::endl;
}
else
{
os<<indent<<indent<<"OpenGl acceleration is allowed but disabled."<<std::endl;
}
#endif
}
void GlWidget::draw()
{
// Check if Gl acceleration mode is correct
#ifndef OTB_GL_USE_ACCEL
if(m_UseGlAcceleration)
{
itkWarningMacro(<<"Gl acceleration enabled but not allowed. Consider rebuilding with OTB_USE_GL_ACCEL to ON. For now, disabling Gl acceleration.");
m_UseGlAcceleration=false;
}
#endif
}
void GlWidget::resize(int x, int y, int w, int h)
{
// Distinguish between resize, move and not changed events
// (The system window manager may generate multiple resizing events,
// so we'd rather avoid event flooding here)
bool reportMove = false;
bool reportResize = false;
if(this->x() != x || this->y() != y)
{
reportMove = true;
}
if(this->w() != w || this->h() != h)
{
reportResize = true;
}
// First call the superclass implementation
Fl_Gl_Window::resize(x,y,w,h);
// If There is a controller
if(m_Controller.IsNotNull())
{
if(reportMove)
{
m_Controller->HandleWidgetMove(m_Identifier,x,y);
}
if(reportResize)
{
m_Controller->HandleWidgetResize(m_Identifier,w,h);
}
}
}
int GlWidget::handle(int event)
{
// If there is a controller
if(m_Controller.IsNotNull())
{
return m_Controller->HandleWidgetEvent(m_Identifier,event);
}
else
{
return 0;
}
}
}
#endif
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __otbGlWidget_h
#define __otbGlWidget_h
// FLTK includes
#include <FL/gl.h>
#include "FL/Fl_Gl_Window.H"
// This include is needed to get the OTB_GL_USE_ACCEL definition
#include "otbConfigure.h"
#include "otbImageWidgetController.h"
namespace otb
{
/** \class GlWidget
* \brief Base class for widgets using OpenGl
*
* The SetUseGlAcceleration() allows you to disable Gl
* acceleration. If OTB_USE_GL_ACCEL is OFF, enabling Gl acceleration
* will generate an exception.
* Using Gl acceleration allows you to have a better rendering when
* zooming.
*
* \sa ImageWidget
*/
class GlWidget
: public Fl_Gl_Window, public itk::Object
{
public:
/** Standard class typedefs */
typedef GlWidget Self;
typedef itk::Object Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory */
itkNewMacro(Self);
/** Runtime information */
itkTypeMacro(GlWidget,Object);
/** Controller typedef */
typedef otb::ImageWidgetController ControllerType;
typedef ControllerType::Pointer ControllerPointerType;
/** Set/Get the Controller */
itkSetObjectMacro(Controller,ControllerType);
itkGetObjectMacro(Controller,ControllerType);
/** Handle resizing event. This method is used by FLTK routines and
* should not be called on its own.
*/
virtual void resize(int x, int y, int w, int h);
/** Enable/disable Gl acceleration */
itkSetMacro(UseGlAcceleration,bool);
itkGetMacro(UseGlAcceleration,bool);
itkBooleanMacro(UseGlAcceleration);
/** Set/Get the identifier */
itkSetStringMacro(Identifier);
itkGetStringMacro(Identifier);
protected:
/** Constructor */
GlWidget();
/** Destructor */
~GlWidget();
/** Printself method */
virtual void PrintSelf(std::ostream& os, itk::Indent indent) const;
/** Actually render the buffer to the screen. This method is
* used by FLTK routines and should not be called on its own.
*/
virtual void draw(void);
/** Handle the event from the users. This method is used by FLTK
* routines and should not be called on its own.
*/
virtual int handle(int event);
private:
GlWidget(const Self&); // purposely not implemented
void operator=(const Self&); // purposely not implemented
/** Widget identifier */
std::string m_Identifier;
/** Controller */
ControllerPointerType m_Controller;
/** Flag for GlAcceleration */
bool m_UseGlAcceleration;
}; // end class
} // end namespace otb
#endif
......@@ -18,19 +18,13 @@
#ifndef __otbImageWidget_h
#define __otbImageWidget_h
// FLTK includes
#include <FL/gl.h>
#include "FL/Fl_Gl_Window.H"
#include "otbGlWidget.h"
// This is included for the default template
#include "otbImage.h"
#include "itkRGBPixel.h"
#include "itkFixedArray.h"
// This include is needed to get the OTB_GL_USE_ACCEL definition
#include "otbConfigure.h"
#include "otbImageWidgetController.h"
namespace otb
{
......@@ -39,23 +33,18 @@ namespace otb
* Rendered data can be loaded using the ReadBuffer() method.
* The SetIsotropicZoom() method allows to tune the zooming (zooming
* is centered).
* The SetUseGlAcceleration() allows you to disable Gl
* acceleration. If OTB_USE_GL_ACCEL is OFF, enabling Gl acceleration
* will generate an exception.
* Using Gl acceleration allows you to have a better rendering when
* zooming.
*
*
* It is also able to display a rectangle on the displayed image.
*/
template <class TInputImage=otb::Image<itk::RGBPixel<unsigned char>,2 > >
class ImageWidget
: public Fl_Gl_Window, public itk::Object
: public GlWidget
{
public:
/** Standard class typedefs */
typedef ImageWidget Self;
typedef itk::Object Superclass;
typedef GlWidget Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
......@@ -63,7 +52,7 @@ public:
itkNewMacro(Self);
/** Runtime information */
itkTypeMacro(ImageWidget,Object);
itkTypeMacro(ImageWidget,GlWidget);
/** Input image typedef */
typedef TInputImage InputImageType;
/** Image region typedef */
......@@ -71,9 +60,6 @@ public:
/** Region size & index typedef */
typedef typename RegionType::SizeType SizeType;
typedef typename RegionType::IndexType IndexType;
/** Controller typedef */
typedef otb::ImageWidgetController ControllerType;
typedef typename ControllerType::Pointer ControllerPointerType;
/** Color typedef (used to draw the rectangle, 4th channel is alpha) */
typedef itk::FixedArray<float,4> ColorType;
......@@ -88,25 +74,11 @@ public:
*/
virtual void ReadBuffer(const InputImageType * image, const RegionType & region);
/** Set/Get the Controller */
itkSetObjectMacro(Controller,ControllerType);
itkGetObjectMacro(Controller,ControllerType);
/** Handle resizing event. This method is used by FLTK routines and
* should not be called on its own.
*/
virtual void resize(int x, int y, int w, int h);
/** Set/Get the Isotropic zoom */
itkSetMacro(IsotropicZoom,double);
itkGetMacro(IsotropicZoom,double);
/** Enable/disable Gl acceleration */
itkSetMacro(UseGlAcceleration,bool);
itkGetMacro(UseGlAcceleration,bool);
itkBooleanMacro(UseGlAcceleration);
/** Enable/disable rectangle drawing */
/** Enable/disable rectangle drawing */
itkSetMacro(DisplayRectangle,bool);
itkGetMacro(DisplayRectangle,bool);
itkBooleanMacro(DisplayRectangle);
......@@ -115,10 +87,6 @@ public:
itkSetMacro(Rectangle,RegionType);
itkGetConstReferenceMacro(Rectangle,RegionType);
/** Set/Get the identifier */
itkSetStringMacro(Identifier);
itkGetStringMacro(Identifier);
/** Set/Get the color of the rectangle */
itkSetMacro(RectangleColor,ColorType);
itkGetConstReferenceMacro(RectangleColor,ColorType);
......@@ -148,15 +116,12 @@ protected:
~ImageWidget();
/** Printself method */
void PrintSelf(std::ostream& os, itk::Indent indent) const;
/** Actually render the buffer to the screen. This method is
* used by FLTK routines and should not be called on its own.
*/
virtual void draw(void);
/** Handle the event from the users. This method is used by FLTK
* routines and should not be called on its own.
*/
virtual int handle(int event);
/** Compute the linear buffer index according to the 2D region and
* its 2D index.This method is used when OTB_GL_USE_ACCEL is ON.
* \param index 2D index
......@@ -191,15 +156,6 @@ private:
/** OpenGl buffered region */
RegionType m_OpenGlBufferedRegion;
/** Widget identifier */
std::string m_Identifier;
/** Controller */
ControllerPointerType m_Controller;
/** Flag for GlAcceleration */
bool m_UseGlAcceleration;
/** Rectangle region */
RegionType m_Rectangle;
bool m_DisplayRectangle;
......
......@@ -25,15 +25,10 @@ namespace otb
{
template <class TInputImage>
ImageWidget<TInputImage>
::ImageWidget() : Fl_Gl_Window(0,0,0,0), m_IsotropicZoom(1.0), m_OpenGlBuffer(NULL), m_OpenGlBufferedRegion(),
m_Identifier("Default"), m_UseGlAcceleration(false), m_Rectangle(),m_DisplayRectangle(false),
m_RectangleColor(), m_ImageExtentWidth(0), m_ImageExtentHeight(0), m_ImageExtentX(), m_ImageExtentY(),
m_SubsamplingRate(1)
::ImageWidget() : m_IsotropicZoom(1.0), m_OpenGlBuffer(NULL), m_OpenGlBufferedRegion(),
m_Rectangle(),m_DisplayRectangle(false),m_RectangleColor(), m_ImageExtentWidth(0),
m_ImageExtentHeight(0), m_ImageExtentX(), m_ImageExtentY(), m_SubsamplingRate(1)
{
#ifdef OTB_GL_USE_ACCEL
m_UseGlAcceleration = true;
#endif
// Default color for rectangle
m_RectangleColor.Fill(0.);
m_RectangleColor[0]=1.0;
......@@ -59,20 +54,7 @@ ImageWidget<TInputImage>
{
// Call the superclass implementation
Superclass::PrintSelf(os,indent);
// Display information about the widget
os<<indent<<"Widget "<<m_Identifier<<": "<<std::endl;
#ifndef OTB_GL_USE_ACCEL
os<<indent<<indent<<"OpenGl acceleration is not allowed."<<std::endl;
#else
if(m_UseGlAcceleration)
{
os<<indent<<indent<<"OpenGl acceleration is allowed and enabled."<<std::endl;
}
else
{
os<<indent<<indent<<"OpenGl acceleration is allowed but disabled."<<std::endl;
}
#endif
if(m_OpenGlBuffer == NULL)
{
os<<indent<<indent<<"OpenGl buffer is not allocated."<<std::endl;
......@@ -97,14 +79,6 @@ ImageWidget<TInputImage>
{
itkExceptionMacro(<<"Region to read is oustside of the buffered region.");
}
// Check if Gl acceleration mode is correct
#ifndef OTB_GL_USE_ACCEL
if(m_UseGlAcceleration)
{
itkExceptionMacro(<<"Gl acceleration enabled but not allowed. Consider rebuilding with OTB_USE_GL_ACCEL to ON.");
}
#endif
// Delete previous buffer if needed
if(m_OpenGlBuffer != NULL)
{
......@@ -124,7 +98,7 @@ ImageWidget<TInputImage>
{
// Fill the buffer
unsigned int index = 0;
if(!m_UseGlAcceleration)
if(!this->GetUseGlAcceleration())
{
// compute the linear index (buffer is flipped around X axis
// when gl acceleration is disabled
......@@ -151,14 +125,8 @@ void
ImageWidget<TInputImage>
::draw()
{
// Check if Gl acceleration mode is correct
#ifndef OTB_GL_USE_ACCEL
if(m_UseGlAcceleration)
{
itkWarningMacro(<<"Gl acceleration enabled but not allowed. Consider rebuilding with OTB_USE_GL_ACCEL to ON. For now, disabling Gl acceleration.");
m_UseGlAcceleration=false;
}
#endif
// perform checks from superclass
Superclass::draw();
// Set up Gl environement
if (!this->valid())
......@@ -189,7 +157,7 @@ ImageWidget<TInputImage>
m_ImageExtentX = (static_cast<double>(this->w())-m_ImageExtentWidth)/2;
m_ImageExtentY = (static_cast<double>(this->h())-m_ImageExtentHeight)/2;
if(!m_UseGlAcceleration)
if(!this->GetUseGlAcceleration())
{
// Set the pixel Zoom
glRasterPos2f(m_ImageExtentX,m_ImageExtentY);
......@@ -252,58 +220,6 @@ ImageWidget<TInputImage>
}
}
template <class TInputImage>
void
ImageWidget<TInputImage>
::resize(int x, int y, int w, int h)
{
// Distinguish between resize, move and not changed events
// (The system window manager may generate multiple resizing events,
// so we'd rather avoid event flooding here)
bool reportMove = false;
bool reportResize = false;
if(this->x() != x || this->y() != y)
{
reportMove = true;
}
if(this->w() != w || this->h() != h)
{
reportResize = true;
}
// First call the superclass implementation
Fl_Gl_Window::resize(x,y,w,h);
// If There is a controller
if(m_Controller.IsNotNull())
{
if(reportMove)
{
m_Controller->HandleWidgetMove(m_Identifier,x,y);
}
if(reportResize)
{
m_Controller->HandleWidgetResize(m_Identifier,w,h);
}
}
}
template <class TInputImage>
int
ImageWidget<TInputImage>
::handle(int event)
{
// If there is a controller
if(m_Controller.IsNotNull())
{
return m_Controller->HandleWidgetEvent(m_Identifier,event);
}
else
{
return 0;
}
}
template <class TInputImage>
typename ImageWidget<TInputImage>
::IndexType
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment