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

ENH: (Visu Refactoring) Implemented the ReadBuffer() method

parent 822ae0f1
No related branches found
No related tags found
No related merge requests found
......@@ -57,8 +57,9 @@ public:
typedef TInputImage InputImageType;
/** Image region typedef */
typedef typename InputImageType::RegionType RegionType;
/** Region size typedef */
/** Region size & index typedef */
typedef typename RegionType::SizeType SizeType;
typedef typename RegionType::IndexType IndexType;
/** Controller typedef */
//typedef otb::ImageViewerController ControllerType;
......@@ -75,6 +76,11 @@ public:
/** 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);
protected:
/** Constructor */
......@@ -87,15 +93,33 @@ protected:
* used by FLTK routines and should not be called on its own.
*/
virtual void draw(void);
/** 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);
/** 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
* \param region 2D region
*/
static inline unsigned int ComputeBufferIndex(const IndexType& index, const RegionType & region)
{
return (index[1]-region.GetIndex()[1])*3*region.GetSize()[0]+3*(index[0]-region.GetIndex()[0]);
}
/** Compute the linear buffer index according to the 2D region and
* its 2D index.This method is used when OTB_GL_USE_ACCEL is OFF.
* The resulting buffer will be flipped over the X axis.
* \param index 2D index
* \param region 2D region
*/
static inline unsigned int ComputeXAxisFlippedBufferIndex(const IndexType& iteratorIndex,const RegionType & region)
{
return (region.GetSize()[1]-1+region.GetIndex()[1]-index[1])*3*region.GetSize()[0]+3*(index[0]-region.GetIndex()[0]);
}
private:
ImageWidget(const Self&); // purposely not implemented
void operator=(const Self&); // purposely not implemented
......
......@@ -19,6 +19,7 @@ PURPOSE. See the above copyright notices for more information.
#define __otbImageWidget_txx
#include "otbImageWidget.h"
#include "itkImageRegionConstIteratorWithIndex.h"
namespace otb
{
......@@ -37,9 +38,11 @@ template <class TInputImage>
ImageWidget<TInputImage>
::~ImageWidget()
{
// Delete OpenGl buffer if needed
if(m_OpenGlBuffer!=NULL)
{
delete [] m_OpenGlBuffer;
m_OpenGlBuffer = NULL;
}
}
......@@ -75,7 +78,43 @@ void
ImageWidget<TInputImage>
::ReadBuffer(InputImageType * image, RegionType & region)
{
// Before doing anything, check if region is inside the buffered
// region of image
if(!image->GetBufferedRegion().IsInside(region))
{
itkExceptionMacro(<<"Region to read is oustside of the buffered region.");
}
// Delete previous buffer if needed
if(m_OpenGlBuffer != NULL)
{
delete [] m_OpenGlBuffer;
m_OpenGlBuffer = NULL;
}
// Allocate new memory
m_OpenGlBuffer = new unsigned char[3*region.GetNumberOfPixels()];
// Declare the iterator
itk::ImageRegionConstIteratorWithIndex<InputImageType> it(image,region);
// Go to begin
it.GoToBegin();
while(!it.IsAtEnd())
{
// Fill compute the linear index
#ifdef OTB_GL_USE_ACCEL
unsigned int index = ComputeBufferIndex(it.GetIndex(),region);
#else
unsigned int index = ComputeXAxisFlippedBufferIndex(it.GetIndex(),region);
#endif
// Fill the buffer
m_OpenGlBuffer[index] =it.Get()[0];
m_OpenGlBuffer[index+1]=it.Get()[1];
m_OpenGlBuffer[index+2]=it.Get()[2];
++it;
}
// Last, updating buffer size
m_OpenGlBufferSize = region.GetSize();
}
template <class TInputImage>
......
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