Skip to content
Snippets Groups Projects
Commit 01ceb9ad authored by Thomas Feuvrier's avatar Thomas Feuvrier
Browse files

Visu : classes implémentant le viewer otb::ImageViewer

parent a31b7515
No related branches found
No related tags found
No related merge requests found
# OTB-FA-00015-CS
#FILE(GLOB OTBVisu_SRCS "*.cxx" )
SET ( OTBVisu_SRCS
toto.cxx
......@@ -6,7 +8,8 @@ SET ( OTBVisu_SRCS
#FILE(GLOB OTBVisu_GUI_SRCS "*.fl" )
SET ( OTBVisu_GUI_SRCS
otbVectorImageViewerGUI.fl
# otbVectorImageViewerGUI.fl
otbImageViewerGUI.fl
)
......@@ -26,7 +29,7 @@ FLTK_WRAP_UI(OTBVisu ${OTBVisu_GUI_SRCS} )
ADD_LIBRARY(OTBVisu ${OTBVisu_SRCS} ${OTBVisu_FLTK_UI_SRCS})
ADD_LIBRARY(OTBVisu ${OTBVisu_SRCS} )
INSTALL_FILES(/include/otb/Visu "(\\.h|\\.txx)$")
INSTALL_TARGETS(/lib OTBVisu)
INSTALL_TARGETS(/lib/otb OTBVisu)
TARGET_LINK_LIBRARIES(OTBVisu ${FLTK_LIBRARIES} ${OPENGL_glu_LIBRARY}
${OPENGL_LIBRARIES})
......
/*=========================================================================
Programme : OTB (ORFEO ToolBox)
Auteurs : CS - T.Feuvrier
Language : C++
Date : 4 avril 2005
Version :
Role : Classe permettant de grer l'affichage d'une image dans un fenetre
$Id$
=========================================================================*/
#ifndef otbGLVectorImageView_h
#define otbGLVectorImageView_h
......@@ -5,6 +16,7 @@
#include <FL/Fl.H>
#include <FL/fl_draw.H>
#include <FL/Fl_Gl_Window.H>
#include <FL/Fl_Double_Window.H>
#include "itkColorTable.h"
#include "itkVectorImage.h"
......@@ -49,10 +61,13 @@ public:
typedef typename Superclass::ColorTableType ColorTableType;
typedef typename Superclass::ColorTablePointer ColorTablePointer;
virtual void CalculeDataMinMax(double & pMin, double & pMax);
typedef enum { PRINCIPAL_IMAGE_VIEW, ZOOM_IMAGE_VIEW, SCROLL_IMAGE_VIEW } IdentWindowViewType;
itkSetMacro(CenterPointImage,IndexType);
itkGetConstReferenceMacro(CenterPointImage,IndexType);
itkSetMacro(DrawViewRectangle,RegionType);
itkGetConstReferenceMacro(DrawViewRectangle,RegionType);
virtual void SetWinImData(void);
protected:
/*! FLTK required constructor - must use imData() to complete
......@@ -60,37 +75,36 @@ protected:
GLVectorImageView();
/*! Standard destructor */
virtual ~GLVectorImageView(void);
IdentWindowViewType m_IdentWindowView;
IndexType m_CenterPointImage;
public:
virtual IndexType GetCenterRegion( const RegionType & zone );
static RegionType ShrinkRegion( const RegionType & zone, const float shrinkfactor );
virtual RegionType GetViewRegion( const IndexType & centerPointImage );
virtual RegionType GetViewRegion( const RegionType & region, const IndexType & centerPointImage );
virtual RegionType TranslateImageRegionToWindowRegion( const RegionType & imageRegion, const RegionType & sousimageRegion, const int windowWidth, const int windowHeight);
/** Update the view region, with the new zoom and new Window sizes */
virtual void MajViewRegion(void);
virtual void PrintInfos(void);
virtual void BuildWithImageRegion();
virtual void BuildWithWindowRegion(const int zoom);
virtual IndexType WindowCoord2ImageCoord( const IndexType & index )const;
virtual SizeType WindowSize2ImageSize( const SizeType & size )const;
virtual RegionType WindowZone2ImageRegion( const RegionType & zone )const;
virtual void Init(int x, int y, int w, int h, const char *l);
/*! Specify the 3D image to view slice by slice */
// virtual void SetInputImage(ImageType * newImData);
virtual void TreatInputImage(void);
virtual void FinaliseInitialisation(void);
// virtual ImageType * GetInput(void) ;
// virtual const ImagePointer & GetInputImage(void) const;
/*! Specify the 3D image to view as an overlay */
void SetInputOverlay(OverlayType * newOverlayData);
/*! Return a pointer to the overlay data */
const OverlayPointer & GetInputOverlay(void) const;
/*! Turn on/off the viewing of the overlay */
void ViewOverlayData(bool newViewOverlayData);
/*! Status of the overlay - viewed /not viewed */
bool ViewOverlayData(void);
/*! Specify the opacity of the overlay */
void OverlayOpacity(float newOverlayOpacity);
/*! Get the opacity of the overlay */
float OverlayOpacity(void);
/*! Called when overlay is toggled or opacity is changed */
void ViewOverlayCallBack(void (* newOverlayCallBack)(void));
ColorTablePointer GetColorTable(void);
void SetColorTable(ColorTablePointer newColorTable);
......@@ -102,16 +116,22 @@ public:
/*! Status of clicked points display - on/off */
bool ViewClickedPoints();
virtual void clickSelect(float x, float y, float z);
virtual void clickSelect(float x, float y/*, float z*/);
virtual void size(int w, int h);
virtual void resize(int x, int y, int w, int h);
virtual void update();
virtual void draw();
virtual int handle(int event);
// virtual int handle(int event);
virtual void SetDoubleWindow( Fl_Double_Window * pflDoubleWindow)
{
m_flDoubleWindow = pflDoubleWindow;
}
protected :
bool m_ViewRectangle;
RegionType m_DrawViewRectangle;
Fl_Double_Window * m_flDoubleWindow;
};
} //namespace
......
This diff is collapsed.
/*=========================================================================
Programme : OTB (ORFEO ToolBox)
Auteurs : CS - T.Feuvrier
Language : C++
Date : 4 avril 2005
Version :
Role : Classe de base, contenant quelques algorithmes, utilises pour visualiser une image
$Id$
=========================================================================*/
#ifndef otbGLVectorImageViewBase_h
#define otbGLVectorImageViewBase_h
......@@ -10,12 +21,17 @@
#include "itkColorTable.h"
#include "itkImage.h"
#include "itkMacro.h"
#include "otbVectorImageView.h"
//#include "otbImageViewer.h"
namespace otb
{
template <class TPixel, class OverlayPixelType> class ImageViewer;
/**
* GLVectorImageViewBase : Derived from abstract class ImageView and Fl_Gl_Window
* See ImageView.h for details...
......@@ -40,6 +56,10 @@ public:
typedef itk::Image<OverlayPixelType,3> OverlayType;
typedef typename OverlayType::Pointer OverlayPointer;
typedef ImageViewer<TPixel,OverlayPixelType> ImageViewerType;
typedef ImageViewerType * ImageViewerPointer;
typedef typename Superclass::ImageType ImageType;
typedef typename Superclass::ImagePointer ImagePointer;
typedef typename Superclass::ImageConstPointer ImageConstPointer;
......@@ -57,6 +77,15 @@ public:
typedef enum { GRAY_LEVEL = 1, RGB_LEVEL = 3 } ModeViewType;
virtual void ClearSelectChannels(void);
//Mthode d'accs sur le Viewer
itkSetMacro(Viewer,ImageViewerPointer);
itkGetConstMacro(Viewer,ImageViewerPointer);
itkSetMacro(NbDim,int);
itkSetMacro(ModeView,ModeViewType);
itkSetMacro(GrayLevelChannel,int);
itkSetMacro(RedChannel,int);
itkSetMacro(GreenChannel,int);
......@@ -69,9 +98,25 @@ public:
SetBlueChannel(pBlueChannel);
}
virtual void ClearSelectChannels(void);
// itkSetMacro(ChannelsWorks, ChannelsType);
virtual void SetChannelsWorks(const ChannelsType & pChannelsWorks)
{
m_ChannelsWorks = pChannelsWorks;
}
virtual void DrawRectangle(const RegionType & zone);
protected:
//Mthode Get en criture sur le Viewer
itkGetMacro(Viewer,ImageViewerPointer);
virtual void CalculeDataMinMax(const RegionType & region, double & pMin, double & pMax);
virtual void SetWinImData(const RegionType & zone);
bool cValidOverlayData;
float cOverlayOpacity;
......@@ -91,7 +136,6 @@ protected:
/*! Standard destructor */
virtual ~GLVectorImageViewBase(void);
virtual void GenerateChannelsInformations(void);
/** Liste des canaux qui seront rellement traits [1...] */
ChannelsType m_ChannelsWorks;
......@@ -116,6 +160,10 @@ public:
cOverlayColorIndex = c;
}
private:
// Pointeur sur le Viewer
ImageViewerPointer m_Viewer;
};
......
......@@ -2,6 +2,8 @@
#define otbGLVectorImageViewBase_txx
#include "itkExceptionObject.h"
#include "itkImageRegionConstIterator.h"
#include "otbGLVectorImageViewBase.h"
#include <math.h>
......@@ -34,87 +36,175 @@ GLVectorImageViewBase<TPixel, OverlayPixelType>::
}
template <class TPixel, class OverlayPixelType>
void
GLVectorImageViewBase<TPixel, OverlayPixelType>::
GenerateChannelsInformations(void)
ClearSelectChannels(void)
{
m_RedChannel = -1;
m_GreenChannel = -1;
m_BlueChannel = -1;
m_GrayLevelChannel = -1;
m_ChannelsWorks.clear();
}
template <class TPixel, class OverlayPixelType>
void
GLVectorImageViewBase<TPixel, OverlayPixelType>::
CalculeDataMinMax(const RegionType & region, double & pMin, double & pMax)
{
typedef itk::ImageRegionConstIterator<ImageType> InputIterator;
InputIterator inIt(this->GetInput(), region);
m_ChannelsWorks.clear();
//Controle que l'utilisateur a bien selectionne de canaux coherent
if( m_GrayLevelChannel != -1 )
// Parcours des canaux a traiter
unsigned int channelIn(0);
unsigned int channelOut(0);
unsigned int nbChannels(0);
PixelType pixelInput;
pixelInput = inIt.Get();
channelOut = 0;
//Initialisation du Max/Min
for ( nbChannels = 0 ; nbChannels < this->m_ChannelsWorks.size() ; nbChannels++)
{
if( (m_RedChannel != -1 ) || (m_GreenChannel != -1 ) || (m_BlueChannel != -1 ) )
{
itkExceptionMacro(<< "Vous avez selectionne un canal pour le niveau de gris, mais aussi un (ou des) canaux en RGB" );
}
m_ModeView = GRAY_LEVEL;
channelIn = this->m_ChannelsWorks[nbChannels] - 1;
pMax = static_cast<double>(pixelInput[channelIn]);
pMin = pMax;
}
else
++inIt;
while( !inIt.IsAtEnd() )
{
m_ModeView = RGB_LEVEL;
if( (m_RedChannel == -1 ) && (m_GreenChannel == -1 ) && (m_BlueChannel == -1 ) )
{
//itkExceptionMacro(<< "Aucun canal n'a ete selectionne" );
// On les choisi automatiquement,si c'est possible
int nbCanauxInputImage = this->GetInput()->GetNumberOfComponentsPerPixel();
std::cout << "Nb canaux de l'image : "<<nbCanauxInputImage<<std::endl;
switch ( nbCanauxInputImage )
pixelInput = inIt.Get();
channelOut = 0;
for ( nbChannels = 0 ; nbChannels < this->m_ChannelsWorks.size() ; nbChannels++)
{
channelIn = this->m_ChannelsWorks[nbChannels] - 1;
if ( pixelInput[channelIn] > pMax )
{
case 1 :
m_GrayLevelChannel = 1;
m_ModeView = GRAY_LEVEL;
break;
default :
case 3 :
m_BlueChannel = 3;
m_ModeView = RGB_LEVEL;
case 2 :
m_GreenChannel = 2;
m_RedChannel = 1;
m_ModeView = RGB_LEVEL;
break;
pMax = static_cast<double>(pixelInput[channelIn]);
}
}
}
// On selectionne dans "m_ChannelsWorks" que les canaux valide, a lire dans l'image d'entree
switch( m_ModeView )
{
case GRAY_LEVEL : m_ChannelsWorks.push_back( m_GrayLevelChannel );
break;
case RGB_LEVEL : if ( m_RedChannel != -1 ) m_ChannelsWorks.push_back( m_RedChannel );
if ( m_GreenChannel != -1 ) m_ChannelsWorks.push_back( m_GreenChannel );
if ( m_BlueChannel != -1 ) m_ChannelsWorks.push_back( m_BlueChannel );
break;
else if ( pixelInput[channelIn] < pMin )
{
pMin = static_cast<double>(pixelInput[channelIn]);
}
channelOut++;
}
++inIt;
}
//Controle que les canaux selection existe bien dans l'image d'entree
for ( int nbChannels = 0 ; nbChannels < m_ChannelsWorks.size() ; nbChannels++)
}
template <class TPixel, class OverlayPixelType>
void
GLVectorImageViewBase<TPixel, OverlayPixelType>::
SetWinImData(const RegionType & zone)
{
IndexType ind;
int l, m;
float tf;
//std::cout << " Region Image - Requested : Star("<<this->GetInput()->GetRequestedRegion().GetIndex()[0]<<","<<this->GetInput()->GetRequestedRegion().GetIndex()[1]<<") Size("<<this->GetInput()->GetRequestedRegion().GetSize()[0]<<","<<this->GetInput()->GetRequestedRegion().GetSize()[1]<<") "<<std::endl;
//std::cout << " - Buffer display : Star("<<zone.GetIndex()[0]<<","<<zone.GetIndex()[1]<<") Size("<<zone.GetSize()[0]<<","<<zone.GetSize()[1]<<") "<<std::endl;
//std::cout << " Centre ("<<this->cWinCenter[0]<<","<<this->cWinCenter[1]<<")"<<std::endl;
// ind[ this->cWinOrder[ 2 ] ] = this->cWinCenter[ this->cWinOrder[ 2 ] ];
int lWinMinX = zone.GetIndex()[0];
int lWinMinY = zone.GetIndex()[1];
int lWinMaxX = lWinMinX + zone.GetSize()[0] - 1;
int lWinMaxY = lWinMinY + zone.GetSize()[1] - 1;
// int startK = this->cWinMinY;
int startK = zone.GetIndex()[1];
if(startK<0)
startK = 0;
// int startJ = this->cWinMinX;
int startJ = zone.GetIndex()[0];
if(startJ<0)
startJ = 0;
float lCoef = (float)(255./(this->cIWMax-this->cIWMin));
ImagePointer lInpuPtr = this->GetInput();
PixelType pixelInput;
// PixelType pixelOutput;
itk::VariableLengthVector<float> pixelOutput;
int nbChannels(0);
int channelIn(0);
for(int k=startK; k <= lWinMaxY; k++)
// for(int k=lWinMaxY ; k >= startK; k--)
{
// ind[this->cWinOrder[1]] = k;
ind[1] = k;
if(k-lWinMinY >= (int)this->cWinDataSizeY)
continue;
for(int j=startJ; j <= lWinMaxX; j++)
{
// ind[this->cWinOrder[0]] = j;
ind[0] = j;
if(j-lWinMinX >= (int)this->cWinDataSizeX)
continue;
switch( this->cImageMode )
{
if ( (m_ChannelsWorks[nbChannels] <= 0) || (m_ChannelsWorks[nbChannels] > this->GetInput()->GetNumberOfComponentsPerPixel()) )
default:
case IMG_VAL:
pixelInput = lInpuPtr->GetPixel(ind);
pixelOutput.Reserve( lInpuPtr->GetVectorLength() );
// Traitement sur les canaux selectionnes.
for ( nbChannels = 0 ; nbChannels < this->m_ChannelsWorks.size() ; nbChannels++)
{
itkExceptionMacro(<< "L'image d'entree possede "<<this->GetInput()->GetNumberOfComponentsPerPixel()<< "\n Vous devez selectionner des canaux dans [1..."<<this->GetInput()->GetNumberOfComponentsPerPixel()<<"]." );
channelIn = this->m_ChannelsWorks[nbChannels] - 1;
pixelOutput[channelIn] = static_cast<float>(pixelInput[channelIn]);
pixelOutput[channelIn] = (float)( (pixelOutput[channelIn]-this->cIWMin) * lCoef);
}
break;
}
m_NbDim = (int)m_ModeView;
// On s'assure que les valeurs sont dans [0,255]
for ( nbChannels = 0 ; nbChannels < this->m_ChannelsWorks.size() ; nbChannels++)
{
channelIn = this->m_ChannelsWorks[nbChannels] - 1;
if ( pixelOutput[channelIn] > 255. ) pixelOutput[channelIn] = 255.;
else if ( pixelOutput[channelIn] < 0. ) pixelOutput[channelIn] = 0.;
}
// l = ((j-lWinMinX) + (k-lWinMinY)*this->cWinDataSizeX)*this->m_NbDim;
l = (j-lWinMinX)*this->m_NbDim + (k-lWinMinY)*this->cWinDataSizeX*this->m_NbDim;
// this->cWinImData[l] = (unsigned char)tf;
if( this->m_ModeView == GRAY_LEVEL )
{
this->cWinImData[l] = (unsigned char)pixelOutput[this->m_GrayLevelChannel - 1];
}
else
{
if ( this->m_RedChannel != -1 ) this->cWinImData[l+0] = (unsigned char)pixelOutput[this->m_RedChannel - 1];
else this->cWinImData[l+0] = (unsigned char)(0);
if ( this->m_GreenChannel != -1 ) this->cWinImData[l+1] = (unsigned char)pixelOutput[this->m_GreenChannel - 1];
else this->cWinImData[l+1] = (unsigned char)(0);
if ( this->m_BlueChannel != -1 ) this->cWinImData[l+2] = (unsigned char)pixelOutput[this->m_BlueChannel - 1];
else this->cWinImData[l+2] = (unsigned char)(0);
}
}
}
}
template <class TPixel, class OverlayPixelType>
void
void
GLVectorImageViewBase<TPixel, OverlayPixelType>::
ClearSelectChannels(void)
{
m_RedChannel = -1;
m_GreenChannel = -1;
m_BlueChannel = -1;
m_GrayLevelChannel = -1;
m_ChannelsWorks.clear();
DrawRectangle(const RegionType & zone)
{
}
}; //namespace
......
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