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

Correction bug d'allocation mémoire dans le ImageFileReader.

Nouveau viewer utilisant les briques de vase de la visualisation.
parent e98678ae
Branches
Tags
No related merge requests found
......@@ -165,15 +165,27 @@ ImageFileReader<TOutputImage>
ImageRegionType region = output->GetBufferedRegion();
//THOMAS : PB : le GetImageSizeInBytes s'appuie sur m_Dimension lue, donc dimensions physique,de
// l'image (pas celle bufferisd ans la cas du streaming )
char * loadBuffer =
new char[this->m_ImageIO->GetImageSizeInBytes()];
// JULIEN: fix for the problem mentionned : the componentsize is computed here since ad hoc methods in
// itkImageIOBase are protected.
unsigned int componentSize = this->m_ImageIO->GetImageSizeInBytes();
for(unsigned int i=0;i<this->m_ImageIO->GetNumberOfDimensions();++i)
{
componentSize = componentSize/this->m_ImageIO->GetDimensions(i);
}
unsigned int nbBytes = componentSize*region.GetNumberOfPixels();
otbMsgDevMacro(<<"NbBytes "<<nbBytes);
this->m_ImageIO->Read(loadBuffer);
otbMsgDevMacro(<< "Buffer conversion required from: "
<< this->m_ImageIO->GetComponentTypeInfo().name()
<< " to: "
<< typeid(ITK_TYPENAME ConvertPixelTraits::ComponentType).name() << " ImageSizeInBytes()"<<this->m_ImageIO->GetImageSizeInBytes()<<" region.GetNumberOfPixels()"<<region.GetNumberOfPixels());
<< typeid(ITK_TYPENAME ConvertPixelTraits::ComponentType).name() << " NbBytes"<<nbBytes<<" region.GetNumberOfPixels()"<<region.GetNumberOfPixels());
char * loadBuffer = new char[nbBytes];
this->m_ImageIO->Read(loadBuffer);
this->DoConvertBuffer(loadBuffer, region.GetNumberOfPixels());
......
......@@ -63,11 +63,11 @@ class FullResolutionImageWidget
virtual void resize(int x, int y, int w, int h);
/**
* Set upper right corner position in image.
* \param index the upper right corner index.
* Set upper left corner position in image.
* \param index the upper left corner index.
*/
void SetUpperRightCorner(IndexType index);
itkGetMacro(UpperRightCorner,IndexType);
void SetUpperLeftCorner(IndexType index);
itkGetMacro(UpperLeftCorner,IndexType);
protected:
/** Constructor. */
......@@ -79,7 +79,7 @@ class FullResolutionImageWidget
FullResolutionImageWidget(const Self&);// purposely not implemented
void operator=(const Self&);// purposely not implemented
IndexType m_UpperRightCorner;
IndexType m_UpperLeftCorner;
};
} // end namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
......
......@@ -33,9 +33,9 @@ FullResolutionImageWidget<TPixel>
{
SizeType size;
size.Fill(256);
m_UpperRightCorner.Fill(0);
m_UpperLeftCorner.Fill(0);
RegionType region;
region.SetIndex(m_UpperRightCorner);
region.SetIndex(m_UpperLeftCorner);
region.SetSize(size);
this->SetViewedRegion(region);
}
......@@ -61,7 +61,7 @@ FullResolutionImageWidget<TPixel>
}
else
{
this->GetInput()->Update();
// this->GetInput()->Update();
if(this->GetImageOverlayVisible())
{
this->GetInputOverlay()->Update();
......@@ -85,12 +85,12 @@ FullResolutionImageWidget<TPixel>
size[1]=h;
RegionType region;
region.SetSize(size);
region.SetIndex(m_UpperRightCorner);
region.SetIndex(m_UpperLeftCorner);
region.Crop(this->GetInput()->GetLargestPossibleRegion());
this->SetViewedRegion(region);
this->redraw();
this->Fl_Gl_Window::resize(region.GetIndex()[0],
region.GetIndex()[1],
this->Fl_Gl_Window::resize(x,
y,
region.GetSize()[0],
region.GetSize()[1]);
......@@ -163,9 +163,9 @@ FullResolutionImageWidget<TPixel>
template <class TPixel>
void
FullResolutionImageWidget<TPixel>
::SetUpperRightCorner(IndexType index)
::SetUpperLeftCorner(IndexType index)
{
m_UpperRightCorner=index;
m_UpperLeftCorner=index;
RegionType region = this->GetViewedRegion();
region.SetIndex(index);
region.Crop(this->GetInput()->GetLargestPossibleRegion());
......
......@@ -51,6 +51,7 @@ class ImageWidgetBase
/** Template related typedef */
typedef TPixel PixelType;
typedef otb::VectorImage<PixelType,2> ImageType;
typedef typename ImageType::PixelType VectorPixelType;
typedef typename ImageType::Pointer ImagePointerType;
typedef typename ImageType::SizeType SizeType;
typedef typename ImageType::IndexType IndexType;
......@@ -90,12 +91,19 @@ class ImageWidgetBase
itkSetMacro(BlackTransparency,bool);
itkGetMacro(BlackTransparency,bool);
itkGetMacro(ViewModelIsRGB,bool);
itkSetMacro(MaxComponentValues,VectorPixelType);
itkGetMacro(MaxComponentValues,VectorPixelType);
itkSetMacro(MinComponentValues,VectorPixelType);
itkGetMacro(MinComponentValues,VectorPixelType);
itkGetMacro(ViewModelIsRGB,bool);
itkGetMacro(ImageOverlayOpacity,unsigned char);
itkGetObjectMacro(FormList,FormListType);
itkGetMacro(OpenGlIsotropicZoom,double);
/** Set the input image.
* \param image The image to view.
......@@ -158,12 +166,14 @@ class ImageWidgetBase
/** Rebuild opengl image overlay buffer */
virtual void RebuildOpenGlImageOverlayBuffer(void);
/** Normalization function */
unsigned char Normalize(PixelType value, unsigned int channelIndex);
// PURE VIRTUAL METHODS
// User is not supposed to be allowed to move the zoom in the generic implementation
itkSetMacro(OpenGlIsotropicZoom,double);
itkGetMacro(OpenGlIsotropicZoom,double);
/** Unlarge OpenGlBuffer */
virtual void UpdateOpenGlBufferedRegion(void){};
......@@ -217,7 +227,10 @@ class ImageWidgetBase
RegionType m_ImageOverlayBufferedRegion;
/** OpenGl image overlay buffer */
unsigned char * m_OpenGlImageOverlayBuffer;
/** Max value for normalization */
VectorPixelType m_MaxComponentValues;
/** Min value for normalization */
VectorPixelType m_MinComponentValues;
};
} // end namespace otb
......
......@@ -56,6 +56,8 @@ ImageWidgetBase<TPixel>
m_ImageOverlay = NULL;
m_OpenGlImageOverlayBuffer = NULL;
m_ImageOverlayOpacity = 128;
m_MinComponentValues.Fill(0);
m_MaxComponentValues.Fill(256);
}
/**
* Destructor.
......@@ -249,13 +251,36 @@ ImageWidgetBase<TPixel>
}
else
{
//otbMsgDebugMacro(<<"Show");
// m_Image->SetRequestedRegion(m_BufferedRegion);
// m_Image->Update();
//otbMsgDebugMacro(<<"Zoomable widget Show");
this->show();
//otbMsgDebugMacro(<<"Before redraw.");
this->redraw();
//otbMsgDebugMacro(<<"After redraw.");
}
}
template <class TPixel>
unsigned char
ImageWidgetBase<TPixel>
::Normalize(PixelType value, unsigned int channelIndex)
{
if(value>m_MaxComponentValues[channelIndex])
{
return 255;
}
else if(value<m_MinComponentValues[channelIndex])
{
return 0;
}
else
{
return static_cast<unsigned char>(256*static_cast<double>(value-m_MinComponentValues[channelIndex])
/static_cast<double>(m_MaxComponentValues[channelIndex]-m_MinComponentValues[channelIndex]));
}
}
/**
* Draw the widget
*/
......@@ -268,8 +293,9 @@ ImageWidgetBase<TPixel>
if(this->UpdateOpenGlBufferedRegionRequested())
{
UpdateOpenGlBufferedRegion();
// m_Image->SetRequestedRegion(m_BufferedRegion);
// m_Image->Update();
m_Image->SetRequestedRegion(m_BufferedRegion);
m_Image->PropagateRequestedRegion();
m_Image->UpdateOutputData();
RebuildOpenGlBuffer();
}
if(m_ImageOverlayVisible && this->UpdateOpenGlImageOverlayBufferedRegionRequested())
......@@ -360,20 +386,20 @@ ImageWidgetBase<TPixel>
unsigned int index = 0;
for(it.GoToBegin();!it.IsAtEnd();++it)
{
m_OpenGlBuffer[index] = static_cast<unsigned int>(it.Get()[m_RedChannelIndex]);
m_OpenGlBuffer[index] = Normalize(it.Get()[m_RedChannelIndex],m_RedChannelIndex);
if(m_ViewModelIsRGB)
{
m_OpenGlBuffer[index+1] = static_cast<unsigned int>(it.Get()[m_GreenChannelIndex]);
m_OpenGlBuffer[index+2] = static_cast<unsigned int>(it.Get()[m_BlueChannelIndex]);
m_OpenGlBuffer[index+3] = 256;
m_OpenGlBuffer[index+1] = Normalize(it.Get()[m_GreenChannelIndex],m_GreenChannelIndex);
m_OpenGlBuffer[index+2] = Normalize(it.Get()[m_BlueChannelIndex],m_BlueChannelIndex);
m_OpenGlBuffer[index+3] = 255;
index+=4;
}
else
{
m_OpenGlBuffer[index+1] = static_cast<unsigned int>(it.Get()[m_RedChannelIndex]);
m_OpenGlBuffer[index+2] = static_cast<unsigned int>(it.Get()[m_RedChannelIndex]);
m_OpenGlBuffer[index+3] = 256;
index+=4;
m_OpenGlBuffer[index+1] = Normalize(it.Get()[m_RedChannelIndex],m_RedChannelIndex);
m_OpenGlBuffer[index+2] = Normalize(it.Get()[m_RedChannelIndex],m_RedChannelIndex);
m_OpenGlBuffer[index+3] = 255;
index+=4;
}
}
}
......@@ -413,9 +439,9 @@ ImageWidgetBase<TPixel>
}
else
{
m_OpenGlImageOverlayBuffer[index] = static_cast<unsigned int>(it.Get()[0]);
m_OpenGlImageOverlayBuffer[index+1] = static_cast<unsigned int>( it.Get()[1]);
m_OpenGlImageOverlayBuffer[index+2] = static_cast<unsigned int>(it.Get()[2]);
m_OpenGlImageOverlayBuffer[index] = static_cast<unsigned char>(it.Get()[0]);
m_OpenGlImageOverlayBuffer[index+1] = static_cast<unsigned char>( it.Get()[1]);
m_OpenGlImageOverlayBuffer[index+2] = static_cast<unsigned char>(it.Get()[2]);
m_OpenGlImageOverlayBuffer[index+3] = m_ImageOverlayOpacity;
}
index+=4;
......@@ -425,9 +451,9 @@ ImageWidgetBase<TPixel>
{
for(it.GoToBegin();!it.IsAtEnd();++it)
{
m_OpenGlImageOverlayBuffer[index] = static_cast<unsigned int>(it.Get()[0]);
m_OpenGlImageOverlayBuffer[index+1] =static_cast<unsigned int>(it.Get()[1]);
m_OpenGlImageOverlayBuffer[index+2] =static_cast<unsigned int>(it.Get()[2]);
m_OpenGlImageOverlayBuffer[index] = static_cast<unsigned char>(it.Get()[0]);
m_OpenGlImageOverlayBuffer[index+1] =static_cast<unsigned char>(it.Get()[1]);
m_OpenGlImageOverlayBuffer[index+2] =static_cast<unsigned char>(it.Get()[2]);
m_OpenGlImageOverlayBuffer[index+3] =m_ImageOverlayOpacity;
index+=4;
}
......
......@@ -74,7 +74,6 @@ class ZoomableImageWidget
void SetZoomUpperLeftCorner(IndexType index);
itkGetMacro(ZoomUpperLeftCorner,IndexType);
protected:
/** Constructor. */
ZoomableImageWidget();
......
......@@ -63,7 +63,7 @@ ZoomableImageWidget<TPixel>
}
else
{
this->GetInput()->Update();
// this->GetInput()->Update();
if(this->GetImageOverlayVisible())
{
this->GetInputOverlay()->Update();
......@@ -169,14 +169,12 @@ ZoomableImageWidget<TPixel>
RegionType region = this->GetViewedRegion();
IndexType newIndex;
SizeType newSize;
RegionType newRegion;
newSize[0] = static_cast<unsigned int>((double)this->w()/zoomFactor);
newSize[1] = static_cast<unsigned int>((double)this->h()/zoomFactor);
otbMsgDebugMacro(<<"SetZoomFactor: newSize ->"<<newSize);
otbMsgDebugMacro(<<"SetZoomFactor: newIndex ->"<<newIndex);
// otbMsgDebugMacro(<<"SetZoomFactor: newSize ->"<<newSize);
newRegion.SetIndex(m_ZoomUpperLeftCorner);
newRegion.SetSize(newSize);
this->SetViewedRegion(newRegion);
......@@ -195,9 +193,9 @@ ZoomableImageWidget<TPixel>
RegionType newRegion;
size = this->GetViewedRegion().GetSize();
otbMsgDebugMacro(<<"SetZoomCenter: Size ->"<<size);
// otbMsgDebugMacro(<<"SetZoomCenter: Size ->"<<size);
otbMsgDebugMacro(<<"SetZoomCenter: newIndex ->"<<index);
// otbMsgDebugMacro(<<"SetZoomCenter: newIndex ->"<<index);
newRegion.SetIndex(index);
newRegion.SetSize(size);
this->SetViewedRegion(newRegion);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment