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

Suppression de l'application de Classif (...AS) dans /Visu.

Elle sera repérise à partir du code de l'application ICD et sera dans OTB-Applications.
parent ace83dd6
No related branches found
No related tags found
No related merge requests found
......@@ -9,7 +9,6 @@ SET ( OTBVisu_SRCS
SET ( OTBVisu_GUI_SRCS
# otbVectorImageViewerGUI.fl
otbImageViewerGUI.fl
otbImageViewerASGUI.fl
)
......
/*=========================================================================
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 otbGLVectorImageViewBaseAS_h
#define otbGLVectorImageViewBaseAS_h
#include <FL/gl.h>
#include <FL/Fl.H>
#include <FL/fl_draw.H>
#include <FL/Fl_Gl_Window.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_File_Chooser.H>
#include <vector>
#include <string>
#include "itkColorTable.h"
#include "otbImage.h"
#include "itkMacro.h"
#include "otbVectorImageView.h"
namespace otb
{
const int NUM_ClickModeTypes = 3;
typedef enum {CM_NOP, CM_SELECT, CM_BOX} ClickModeType;
typedef enum { COLOR_BLUE , COLOR_RED } ColorType;
typedef enum {IMG_VAL, IMG_INV, IMG_LOG, IMG_DX, IMG_DY, IMG_DZ,
IMG_BLEND, IMG_MIP} ImageModeType;
typedef enum {IW_MIN, IW_MAX, IW_FLIP} IWModeType;
const char ClickModeTypeName[3][7] =
{{'N', 'O', 'P', '\0', ' ', ' ', ' '},
{'S', 'e', 'l', 'e', 'c', 't', '\0'},
{'B', 'o', 'x', '\0', ' ', ' ', ' '}};
/*! Structure clickPoint to store the x,y,z and intensity value of a
* point in the image
*/
class ClickPoint
{
public:
ClickPoint()
: x(0),y(0),z(0),value(0),color(COLOR_BLUE), w(0), h(0), isForBox(false){}
ClickPoint( const ClickPoint & p )
{ x = p.x; y = p.y; z = p.z;value = p.value;color = p.color;
w = p.w; h = p.h; isForBox=p.isForBox; }
ClickPoint(float _x,float _y,float _z,double v,ColorType _color)
: x(_x),y(_y),z(_z),value(v),color(_color),w(0),h(0),isForBox(false){}
ClickPoint(float _x,float _y,float _z,double v,ColorType _color,
float _w,float _h) :
x(_x),y(_y),z(_z),value(v),color(_color),w(_w),h(_h),isForBox(true){}
public:
float x, y, z, w, h;
double value;
ColorType color;
bool isForBox;
};
template <class TPixel> class ImageViewerAS;
/** \class GLVectorImageViewBase
* \brief Base class for image view
* Contain all algorithms and functionnalities for display an image in a window.
*/
template <class TPixel, class TPixelOverlay>
class ITK_EXPORT GLVectorImageViewClick : public VectorImageView<TPixel>,
public Fl_Gl_Window
{
public:
typedef GLVectorImageViewClick Self;
typedef VectorImageView<TPixel> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
typedef otb::Image<TPixelOverlay,2> OverlayType;
typedef typename OverlayType::Pointer OverlayPointer;
typedef itk::ColorTable<float> ColorTableType;
typedef typename ColorTableType::Pointer ColorTablePointer;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Run-time type information (and related methods). */
itkTypeMacro(GLVectorImageViewClick,VectorImageView);
typedef ImageViewerAS<TPixel> ImageViewerType;
typedef ImageViewerType * ImageViewerPointer;
typedef typename Superclass::ImageType ImageType;
typedef typename Superclass::ImagePointer ImagePointer;
typedef typename Superclass::ImageConstPointer ImageConstPointer;
typedef typename Superclass::RegionType RegionType;
typedef typename Superclass::SizeType SizeType;
typedef typename Superclass::IndexType IndexType;
typedef typename Superclass::PixelType PixelType;
/** Typedef Liste des canaux */
typedef typename std::vector<int> ChannelsType;
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);
itkSetMacro(BlueChannel,int);
virtual void SetRGBChannels(int pRedChannel,int pGreenChannel, int pBlueChannel)
{
SetRedChannel(pRedChannel);
SetGreenChannel(pGreenChannel);
SetBlueChannel(pBlueChannel);
}
// itkSetMacro(ChannelsWorks, ChannelsType);
virtual void SetChannelsWorks(const ChannelsType & pChannelsWorks)
{
m_ChannelsWorks = pChannelsWorks;
}
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);
virtual void FinalizeInitialisation(void);
virtual void size(int w, int h);
virtual void resize(int x, int y, int w, int h);
/** Click Mode */
/* list of points clicked and maximum no. of points to be stored*/
std::list< ClickPoint > cClickedPoints;
unsigned int maxClickPoints;
ClickModeType cClickMode;
float cClickSelect[3];
float cClickSelectV;
void (* cClickSelectCallBack)(float x,float y,float z,
float v);
void * cClickSelectArg;
void (* cClickSelectArgCallBack)(float x, float y, float z,
float v, void *clickSelectArg);
float cBoxMin[3];
float cBoxMax[3];
void (* cClickBoxCallBack)(float minX, float minY, float minZ,
float maxX, float maxY, float maxZ);
void * cClickBoxArg;
void (* cClickBoxArgCallBack)(float minX, float minY, float minZ,
float maxX, float maxY, float maxZ,
void * clickBoxArg);
/*! Turn on/off the display of clicked points */
void ViewClickedPoints( bool newViewClickedPoints );
/*! Status of clicked points display - on/off */
bool ViewClickedPoints();
/*! Specify the clickMode - a user click in a window will cause
* various events */
void clickMode(ClickModeType newClickMode);
ClickModeType clickMode(void);
virtual void clickSelect(float x, float y, float z, ColorType color);
virtual void clickSelectBox(float x, float y, float z, ColorType color,
int width, int height);
float clickSelectX(void);
float clickSelectY(void);
float clickSelectZ(void);
void clickSelectCallBack(
void (*newClickSelectCallBack)(float, float,
float, float));
void clickSelectCallBack(
void (*newClickSelectArgCallBack)(float, float,
float, float,
void *),
void * newClickSelectArg);
/*! Returns the last ith clicked point - ie. to get the last point
* i = 0, to get the 2nd last point i = 1, and so on
*/
bool getClickedPoint(unsigned int i, ClickPoint & point);
int numClickedPointsStored(){ return cClickedPoints.size();}
void maxClickedPointsStored(unsigned int i);
unsigned int maxClickedPointsStored();
void clearClickedPointsStored(){cClickedPoints.clear();}
void deleteLastClickedPointsStored(){cClickedPoints.pop_front();}
void saveClickedPointsStored() {
/*const char * filename = fl_file_chooser("Please select a file name","*.*","");
std::ofstream fpoints( filename );
std::list< ClickPoint >::const_iterator point = cClickedPoints.begin();
while( point != cClickedPoints.end() )
{
fpoints << point->x << " " << point->y << " " << point->z << std::endl;
++point;
}
fpoints.close();*/
};
void boxMin(float minX, float minY, float minZ);
virtual void boxMax(float maxX, float maxY, float maxZ);
void clickBoxCallBack(
void (*newClickBoxCallBack)(float, float, float,
float, float, float));
void clickBoxCallBack(
void (*newClickBoxArgCallBack)(float, float, float,
float, float, float,
void *),
void * newClickBoxArg);
/** End Click Mode */
virtual void update();
virtual void draw();
// virtual int handle(int event);
virtual void SetDoubleWindow( Fl_Double_Window * pflDoubleWindow)
{
m_flDoubleWindow = pflDoubleWindow;
}
itkSetMacro(CenterPointImage,IndexType);
itkGetConstReferenceMacro(CenterPointImage,IndexType);
itkSetMacro(DrawViewRectangle,RegionType);
itkGetConstReferenceMacro(DrawViewRectangle,RegionType);
itkSetMacro(Label,std::string);
itkGetConstMacro(Label,std::string);
// itkSetMacro(Label,std::string);
// itkGetConstReferenceMacro(Label,std::string);
// itkSetStringMacro(Label);
// itkGetStringMacro(Label);
// Overlay
bool cOverlay;
/*! Activate overlays on image */
void ActivateOverlayFirst(bool b);
void ActivateOverlaySecond(bool b);
bool cViewOverlayData;
/*! Specify the 3D image to view as an overlay */
void SetInputOverlay( OverlayPointer newOverlayDataClassFirst,
OverlayPointer newOverlayDataClassSecond);
/*! Return a pointer to the overlay data */
const OverlayPointer & GetInputOverlay(void) const;
/*! Return a pointer to the overlay data for the Red Class*/
const OverlayPointer & GetInputOverlayClassFirst(void) const;
/*! Return a pointer to the overlay data for the Blue Class*/
const OverlayPointer & GetInputOverlayClassSecond(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);
/*! Display Overlay in Color 'c'. You must ensure that the color-table specified
* contains color 'c'. For example with the default useDiscrete() color table,
* SetOverlayColorIndex( 0 ) will display the overlay in red.
* SetOverlayColorIndex( 1 ) purple etc.... */
void SetOverlayColorIndex( unsigned int c)
{
cOverlayColorIndex = c;
}
/** Box Selection */
bool cSelectRectangle;
int coord[4];
int cOffSetX;
int cOffSetY;
float cScale;
// virtual void SetInput( const ImageType *image);
protected:
//Mthodes utilises pour l'overlay de l'image
bool cValidOverlayData;
//Booleens permettant l'affichage des overlays de la classification
bool cViewOverlayClassFirst;
bool cViewOverlayClassSecond;
float cOverlayOpacity;
// Overlay utilis pour afficher le rsultat de la classification
// OverlayPointer cOverlayData;
// Overlay utilis pour afficher le rsultat de la classe #C1
OverlayPointer cOverlayDataClassFirst;
// Overlay utilis pour afficher le rsultat de la classe #C2
OverlayPointer cOverlayDataClassSecond;
void (* cViewOverlayCallBack)(void);
ImageModeType cImageMode;
//unsigned char * cWinOverlayData;
unsigned char * cWinOverlayDataFirst;
unsigned char * cWinOverlayDataSecond;
unsigned int cOverlayColorIndex;
ColorTablePointer cColorTable;
//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);
/*! FLTK required constructor - must use imData() to complete
definition */
GLVectorImageViewClick();
/*! Standard destructor */
virtual ~GLVectorImageViewClick(void);
/** Liste des canaux qui seront rellement traits [1...] */
ChannelsType m_ChannelsWorks;
/** Nombre de dimensions de l'image : = 1 si GRAY_LEVEL, sinon 3 si RGB_LEVEL */
int m_NbDim;
int m_RedChannel;
int m_GreenChannel;
int m_BlueChannel;
int m_GrayLevelChannel;
bool m_ViewRectangle;
RegionType m_DrawViewRectangle;
Fl_Double_Window * m_flDoubleWindow;
IndexType m_CenterPointImage;
ModeViewType m_ModeView;
private:
// Pointeur sur le Viewer
ImageViewerPointer m_Viewer;
std::string m_Label;
};
} //namespace
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbGLVectorImageViewClick.txx"
#endif
#endif
This diff is collapsed.
/*=========================================================================
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 __otbImageViewerAS_h
#define __otbImageViewerAS_h
#include <string>
#include "itkShrinkImageFilter.h"
#include "otbPrincipalImageViewAS.h"
#include "otbImageViewerASGUI.h"
#include "otbMultiChannelExtractROI.h"
#include "otbGLVectorImageViewClick.h"
namespace otb
{
/** \class ImageViewerAS
* \brief Base class for viewing an image, by Rom's way
*
* This viewer show the image with one window display.
* The purpose is to select points in this image, display them
* and finally save them in a file
*
* Use FLTK gui.
*
*/
template <class TPixel>
class ITK_EXPORT ImageViewerAS : public itk::ProcessObject,
public otbImageViewerASGUI
{
public:
/**
* Standard "Self" typedef.
*/
typedef ImageViewerAS Self;
typedef itk::ProcessObject Superclass;
/**
* Smart pointer typedef support.
*/
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Run-time type information (and related methods). */
itkTypeMacro(ImageViewerAS,itk::ProcessObject);
typedef TPixel InputPixelType;
typedef TPixel InputOverlayType;
typedef otb::MultiChannelExtractROI< InputPixelType,
InputPixelType > ExtractROIFilterType;
typedef typename ExtractROIFilterType::Pointer ExtractROIFilterPointer;
typedef PrincipalImageViewAS<InputPixelType,InputOverlayType> PrincipalImageViewType;
typedef typename PrincipalImageViewType::Pointer PrincipalImageViewPointer;
typedef GLVectorImageViewClick<InputPixelType,InputOverlayType> ImageViewBaseType;
typedef typename ExtractROIFilterType::InputImageType ImageType;
// typedef typename PrincipalImageViewType::ImageType ImageType;
typedef typename ImageType::Pointer ImagePointer;
typedef typename ImageType::ConstPointer ImageConstPointer;
typedef typename ImageType::RegionType RegionType;
typedef typename ImageType::SizeType SizeType;
typedef typename ImageType::IndexType IndexType;
typedef typename ImageType::PixelType PixelType;
ImageViewerAS();
virtual ~ImageViewerAS();
/** Set the left input image */
virtual void SetLeftImage(itk::ImageBase<2> * img);
/** Set the right input image */
virtual void SetRightImage(itk::ImageBase<2> * img);
/** Show the viewer (Update) */
virtual void Show(void);
/** Hide all Image View Windows */
virtual void Hide(void);
/** Update */
virtual void Update(void);
/** Gestion des vnements associs aux bouttons */
void EraseLastClickedPoint();
void EraseAllClickedPoints();
void LearnAlgorithm();
void ClassificationAlgorithm();
void DisplayFirstClass();
void DisplaySecondClass();
void LoadLeftImage();
void LoadRightImage();
/** Build the HMI */
virtual void BuildHMI(void);
virtual void CreatePrincipalImageViewBeforeClassif( Fl_Group * g , Fl_Gl_Window * w );
virtual void CreatePrincipalImageViewAfterClassif( Fl_Group * g , Fl_Gl_Window * w );
// virtual void SetLabel( const char * );
virtual void ClickSelectCallBack(
void (*newClickSelectArgCallBack)(float, float,
/*float,*/ float,
void *),
void * newClickSelectArg);
virtual void PrincipalAction(const IndexType & index);
//virtual void ExtractImagePrincipal(const RegionType & zone);
virtual void GenerateLeftChannelsInformations(void);
virtual void GenerateRightChannelsInformations(void);
typedef typename ImageViewBaseType::ModeViewType ModeViewType;
typedef typename ImageViewBaseType::ChannelsType ChannelsType;
itkSetMacro(LeftGrayLevelChannel,int);
itkSetMacro(LeftRedChannel,int);
itkSetMacro(LeftGreenChannel,int);
itkSetMacro(LeftBlueChannel,int);
itkSetMacro(RightGrayLevelChannel,int);
itkSetMacro(RightRedChannel,int);
itkSetMacro(RightGreenChannel,int);
itkSetMacro(RightBlueChannel,int);
itkSetStringMacro(Label);
itkGetStringMacro(Label);
virtual void SetLeftRGBChannels(int pRedChannel,int pGreenChannel, int pBlueChannel)
{
SetLeftRedChannel(pRedChannel);
SetLeftGreenChannel(pGreenChannel);
SetLeftBlueChannel(pBlueChannel);
}
virtual void SetRightRGBChannels(int pRedChannel,int pGreenChannel, int pBlueChannel)
{
SetRightRedChannel(pRedChannel);
SetRightGreenChannel(pGreenChannel);
SetRightBlueChannel(pBlueChannel);
}
virtual void ClearSelectChannels(void);
/** Synchronize clicked points on images before and after classif */
void SynchronizeClickedPoints(float x,float y,float z,ColorType c);
/** Synchronize clicked points Box on images before and after classif */
void SynchronizeClickedPointsBox(float x,float y,float z,ColorType c,
int width, int height);
private:
virtual void SetChannelsInformationsToImagesView(void);
/** Label of the windows */
std::string m_Label;
static const std::string m_SuffixPrincipalTitle;
/** Informations for left image */
int m_LeftNbDim;
int m_LeftRedChannel;
int m_LeftGreenChannel;
int m_LeftBlueChannel;
int m_LeftGrayLevelChannel;
ModeViewType m_LeftModeView;
ChannelsType m_LeftChannelsWorks;
/** Informations for right image */
int m_RightNbDim;
int m_RightRedChannel;
int m_RightGreenChannel;
int m_RightBlueChannel;
int m_RightGrayLevelChannel;
ModeViewType m_RightModeView;
ChannelsType m_RightChannelsWorks;
// PrincipalImageViewPointer m_PrincipalView;
PrincipalImageViewPointer m_PrincipalViewBeforeClassif;
PrincipalImageViewPointer m_PrincipalViewAfterClassif;
typedef unsigned long WinSizeType;
/** Default size for the principal image */
WinSizeType m_InitPrincipalWinSizeMax;
/** Extract image filter use to calculte the Principal image view */
//ExtractROIFilterPointer m_ExtractROIFilter;
ImageType * m_InputLeftImage;
ImageType * m_InputRightImage;
ImageType * m_PrincipalLeftImage;
ImageType * m_PrincipalRightImage;
};
} // end namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbImageViewerAS.txx"
#endif
#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 _otbImageViewerAS_txx
#define _otbImageViewerAS_txx
#include "otbImageViewerAS.h"
#include <iostream>
#include "otbMacro.h"
namespace otb
{
template <class TPixel>
const std::string ImageViewerAS<TPixel>::m_SuffixPrincipalTitle = " - Principal Window";
template <class TPixel>
ImageViewerAS<TPixel>
::ImageViewerAS()
{
m_Label = "Image";
this->ClearSelectChannels();
m_PrincipalLeftImage = NULL;
m_PrincipalRightImage = NULL;
m_InitPrincipalWinSizeMax = 300;
//m_ExtractROIFilter = ExtractROIFilterType::New();
CreateGUI();
}
template <class TPixel>
ImageViewerAS<TPixel>
::~ImageViewerAS()
{
}
template <class TPixel>
void
ImageViewerAS<TPixel>
::PrincipalAction(const IndexType & index)
{
//Si une action est faite sur la fenetre principale (ex : agrandir al fenetre, dans le cas ou il la fenetre scroll existe)
m_PrincipalViewBeforeClassif->update();
m_PrincipalViewAfterClassif->update();
}
template <class TPixel>
void
ImageViewerAS<TPixel>
::BuildHMI(void)
{
m_InputLeftImage->Update();
m_InputRightImage->Update();
m_PrincipalLeftImage = m_InputLeftImage;
m_PrincipalRightImage = m_InputRightImage;
this->ClearSelectChannels();
this->GenerateLeftChannelsInformations();
this->GenerateRightChannelsInformations();
this->SetChannelsInformationsToImagesView();
this->Superclass::Update();
static bool firstTime = true;
// Fenetre d'affichage AVANT classif
//----------------------------------------
/*
otbMsgDevMacro( << "Taille input image : " << m_InputLeftImage->GetLargestPossibleRegion().GetSize()[0]
<< " " << m_InputLeftImage->GetLargestPossibleRegion().GetSize()[1] ) ;
otbMsgDevMacro( << "Taille principal image : " << m_PrincipalViewBeforeClassif->sizeX()
<< " " << m_PrincipalViewBeforeClassif->sizeY() );
*/
/*m_ShrinkImageFilter->SetShrinkFactors(0);
m_ShrinkImageFilter->SetInput( m_InputImage );
m_ShrinkImageFilter->Update();
m_PrincipalImage = m_ShrinkImageFilter->GetOutput();*/
m_PrincipalViewBeforeClassif->SetClickable(true);
m_PrincipalViewBeforeClassif->SetInput( m_PrincipalLeftImage );
m_PrincipalViewBeforeClassif->SetDoubleWindow( iviewWindowPrincipal );
m_PrincipalViewBeforeClassif->SetViewer( this );
m_PrincipalViewBeforeClassif->SetLabel( m_Label + m_SuffixPrincipalTitle );
m_PrincipalViewBeforeClassif->Show();
// Fenetre d'affichage APRES classif
//----------------------------------------
m_PrincipalViewAfterClassif->SetClickable(false);
m_PrincipalViewAfterClassif->SetInput( m_PrincipalRightImage );
m_PrincipalViewAfterClassif->SetDoubleWindow( iviewWindowPrincipal );
m_PrincipalViewAfterClassif->SetViewer( this );
m_PrincipalViewAfterClassif->SetLabel( m_Label + m_SuffixPrincipalTitle );
m_PrincipalViewAfterClassif->Show();
if( firstTime == true)
{
firstTime = false;
Fl::check();
m_PrincipalViewBeforeClassif->redraw();
m_PrincipalViewAfterClassif->redraw();
Fl::check();
}
SetLabel("Application classification supervise");
}
template <class TPixel>
void
ImageViewerAS<TPixel>
::SetLeftImage(itk::ImageBase<2> * img)
{
m_InputLeftImage = dynamic_cast<ImageType *>( img );
this->Modified();
}
template <class TPixel>
void
ImageViewerAS<TPixel>
::SetRightImage(itk::ImageBase<2> * img)
{
m_InputRightImage = dynamic_cast<ImageType *>( img );
this->Modified();
}
template <class TPixel>
void
ImageViewerAS<TPixel>
::Show(void)
{
this->Update();
}
template <class TPixel>
void
ImageViewerAS<TPixel>
::Hide(void)
{
iviewWindowPrincipal->hide();
}
template <class TPixel>
void
ImageViewerAS<TPixel>
::Update(void)
{
this->BuildHMI();
}
template <class TPixel>
void
ImageViewerAS<TPixel>
::CreatePrincipalImageViewBeforeClassif( Fl_Group * group, Fl_Gl_Window * original )
{
int x = original->x();
int y = original->y();
int w = original->w();
int h = original->h();
const char * label = original->label();
this->m_PrincipalViewBeforeClassif = PrincipalImageViewType::New();
this->m_PrincipalViewBeforeClassif->Init(x,y,w,h,label);
this->m_PrincipalViewBeforeClassif->box( FL_EMBOSSED_BOX );
group->remove( original );
delete original;
}
template <class TPixel>
void
ImageViewerAS<TPixel>
::CreatePrincipalImageViewAfterClassif( Fl_Group * group, Fl_Gl_Window * original )
{
int x = original->x();
int y = original->y();
int w = original->w();
int h = original->h();
const char * label = original->label();
this->m_PrincipalViewAfterClassif = PrincipalImageViewType::New();
this->m_PrincipalViewAfterClassif->Init(x,y,w,h,label);
this->m_PrincipalViewAfterClassif->box( FL_EMBOSSED_BOX );
group->remove( original );
delete original;
}
template <class TPixel>
void
ImageViewerAS<TPixel>
::ClickSelectCallBack( void (*newClickSelectArgCallBack)(float, float,
float,
void *),
void * newClickSelectArg)
{
//THOMAS
/*
m_PrincipalViewBeforeClassif->clickSelectCallBack( newClickSelectArgCallBack,
newClickSelectArg );
m_ScrollView->clickSelectCallBack( newClickSelectArgCallBack,
newClickSelectArg );
m_ZoomView->clickSelectCallBack( newClickSelectArgCallBack,
newClickSelectArg );
*/
}
template <class TPixel>
void
ImageViewerAS<TPixel>
::GenerateLeftChannelsInformations(void)
{
m_LeftChannelsWorks.clear();
//Controle que l'utilisateur a bien selectionne de canaux coherent
if( m_LeftGrayLevelChannel != -1 )
{
if( (m_LeftRedChannel != -1 ) || (m_LeftGreenChannel != -1 ) || (m_LeftBlueChannel != -1 ) )
{
itkExceptionMacro(<< "Vous avez selectionne un canal pour le niveau de gris, mais aussi un (ou des) canaux en RGB" );
}
m_LeftModeView = ImageViewBaseType::GRAY_LEVEL;
}
else
{
m_LeftModeView = ImageViewBaseType::RGB_LEVEL;
if( (m_LeftRedChannel == -1 ) && (m_LeftGreenChannel == -1 ) && (m_LeftBlueChannel == -1 ) )
{
//itkExceptionMacro(<< "Aucun canal n'a ete selectionne" );
// On les choisi automatiquement,si c'est possible
int nbCanauxInputImage = m_PrincipalLeftImage->GetNumberOfComponentsPerPixel();
switch ( nbCanauxInputImage )
{
case 1 :
m_LeftGrayLevelChannel = 1;
m_LeftModeView = ImageViewBaseType::GRAY_LEVEL;
break;
default :
case 3 :
m_LeftBlueChannel = 3;
m_LeftModeView = ImageViewBaseType::RGB_LEVEL;
case 2 :
m_LeftGreenChannel = 2;
m_LeftRedChannel = 1;
m_LeftModeView = ImageViewBaseType::RGB_LEVEL;
break;
}
}
}
// On selectionne dans "m_ChannelsWorks" que les canaux valide, a lire dans l'image d'entree
switch( m_LeftModeView )
{
case ImageViewBaseType::GRAY_LEVEL : m_LeftChannelsWorks.push_back( m_LeftGrayLevelChannel );
break;
case ImageViewBaseType::RGB_LEVEL :
if ( m_LeftRedChannel != -1 ) m_LeftChannelsWorks.push_back( m_LeftRedChannel );
if ( m_LeftGreenChannel != -1 ) m_LeftChannelsWorks.push_back( m_LeftGreenChannel );
if ( m_LeftBlueChannel != -1 ) m_LeftChannelsWorks.push_back( m_LeftBlueChannel );
break;
}
//Controle que les canaux selection existe bien dans l'image d'entree
for ( int nbChannels = 0 ; nbChannels < m_LeftChannelsWorks.size() ; nbChannels++)
{
if ( (m_LeftChannelsWorks[nbChannels] <= 0) ||
(m_LeftChannelsWorks[nbChannels] > m_PrincipalLeftImage->GetNumberOfComponentsPerPixel()) )
{
itkExceptionMacro(<< "L'image d'entree possede"
<<m_PrincipalLeftImage->GetNumberOfComponentsPerPixel()
<< "\n Vous devez selectionner des canaux dans [1..."<<m_PrincipalLeftImage->GetNumberOfComponentsPerPixel()<<"]." );
}
}
m_LeftNbDim = (int)m_LeftModeView;
}
template <class TPixel>
void
ImageViewerAS<TPixel>
::GenerateRightChannelsInformations(void)
{
m_RightChannelsWorks.clear();
//Controle que l'utilisateur a bien selectionne de canaux coherent
if( m_RightGrayLevelChannel != -1 )
{
if( (m_RightRedChannel != -1 ) || (m_RightGreenChannel != -1 ) || (m_RightBlueChannel != -1 ) )
{
itkExceptionMacro(<< "Vous avez selectionne un canal pour le niveau de gris, mais aussi un (ou des) canaux en RGB" );
}
m_RightModeView = ImageViewBaseType::GRAY_LEVEL;
}
else
{
m_RightModeView = ImageViewBaseType::RGB_LEVEL;
if( (m_RightRedChannel == -1 ) && (m_RightGreenChannel == -1 ) && (m_RightBlueChannel == -1 ) )
{
//itkExceptionMacro(<< "Aucun canal n'a ete selectionne" );
// On les choisi automatiquement,si c'est possible
int nbCanauxInputImage = m_PrincipalRightImage->GetNumberOfComponentsPerPixel();
switch ( nbCanauxInputImage )
{
case 1 :
m_RightGrayLevelChannel = 1;
m_RightModeView = ImageViewBaseType::GRAY_LEVEL;
break;
default :
case 3 :
m_RightBlueChannel = 3;
m_RightModeView = ImageViewBaseType::RGB_LEVEL;
case 2 :
m_RightGreenChannel = 2;
m_RightRedChannel = 1;
m_RightModeView = ImageViewBaseType::RGB_LEVEL;
break;
}
}
}
// On selectionne dans "m_ChannelsWorks" que les canaux valide, a lire dans l'image d'entree
switch( m_RightModeView )
{
case ImageViewBaseType::GRAY_LEVEL : m_RightChannelsWorks.push_back( m_RightGrayLevelChannel );
break;
case ImageViewBaseType::RGB_LEVEL :
if ( m_RightRedChannel != -1 ) m_RightChannelsWorks.push_back( m_RightRedChannel );
if ( m_RightGreenChannel != -1 ) m_RightChannelsWorks.push_back( m_RightGreenChannel );
if ( m_RightBlueChannel != -1 ) m_RightChannelsWorks.push_back( m_RightBlueChannel );
break;
}
//Controle que les canaux selection existe bien dans l'image d'entree
for ( int nbChannels = 0 ; nbChannels < m_RightChannelsWorks.size() ; nbChannels++)
{
if ( (m_RightChannelsWorks[nbChannels] <= 0) ||
(m_RightChannelsWorks[nbChannels] > m_PrincipalRightImage->GetNumberOfComponentsPerPixel()) )
{
itkExceptionMacro(<< "L'image d'entree possede"
<<m_PrincipalRightImage->GetNumberOfComponentsPerPixel()
<< "\n Vous devez selectionner des canaux dans [1..."<<m_PrincipalLeftImage->GetNumberOfComponentsPerPixel()<<"]." );
}
}
m_RightNbDim = (int)m_RightModeView;
}
template <class TPixel>
void
ImageViewerAS<TPixel>::
SetChannelsInformationsToImagesView(void)
{
m_PrincipalViewBeforeClassif->SetChannelsWorks(m_LeftChannelsWorks);
m_PrincipalViewBeforeClassif->SetModeView(m_LeftModeView);
m_PrincipalViewBeforeClassif->SetNbDim(m_LeftNbDim);
m_PrincipalViewBeforeClassif->SetGrayLevelChannel(m_LeftGrayLevelChannel);
m_PrincipalViewBeforeClassif->SetRGBChannels(m_LeftRedChannel,m_LeftGreenChannel,m_LeftBlueChannel);
m_PrincipalViewAfterClassif->SetChannelsWorks(m_RightChannelsWorks);
m_PrincipalViewAfterClassif->SetModeView(m_RightModeView);
m_PrincipalViewAfterClassif->SetNbDim(m_RightNbDim);
m_PrincipalViewAfterClassif->SetGrayLevelChannel(m_RightGrayLevelChannel);
m_PrincipalViewAfterClassif->SetRGBChannels(m_RightRedChannel,m_RightGreenChannel,m_RightBlueChannel);
}
template <class TPixel>
void
ImageViewerAS<TPixel>::
ClearSelectChannels(void)
{
m_LeftRedChannel = -1;
m_LeftGreenChannel = -1;
m_LeftBlueChannel = -1;
m_LeftGrayLevelChannel = -1;
m_LeftChannelsWorks.clear();
m_RightRedChannel = -1;
m_RightGreenChannel = -1;
m_RightBlueChannel = -1;
m_RightGrayLevelChannel = -1;
m_RightChannelsWorks.clear();
}
// Gestion des vnements boutons
template <class TPixel>
void
ImageViewerAS<TPixel>::EraseLastClickedPoint()
{
m_PrincipalViewBeforeClassif->UndoPt();
m_PrincipalViewAfterClassif->UndoPt();
}
template <class TPixel>
void
ImageViewerAS<TPixel>::EraseAllClickedPoints()
{
m_PrincipalViewBeforeClassif->ResetPts();
m_PrincipalViewAfterClassif->ResetPts();
}
template <class TPixel>
void
ImageViewerAS<TPixel>::LearnAlgorithm()
{
m_PrincipalViewBeforeClassif->LearnStep();
}
template <class TPixel>
void
ImageViewerAS<TPixel>::ClassificationAlgorithm()
{
m_PrincipalViewBeforeClassif->ClassificationStep();
m_PrincipalViewAfterClassif->SetInputOverlay(m_PrincipalViewBeforeClassif->GetInputOverlayClassFirst(),
m_PrincipalViewBeforeClassif->GetInputOverlayClassSecond());
}
template <class TPixel>
void
ImageViewerAS<TPixel>::DisplayFirstClass()
{
m_PrincipalViewAfterClassif->ActivateOverlayFirst(true);
m_PrincipalViewAfterClassif->ActivateOverlaySecond(false);
this->Update();
}
template <class TPixel>
void
ImageViewerAS<TPixel>::DisplaySecondClass()
{
m_PrincipalViewAfterClassif->ActivateOverlayFirst(false);
m_PrincipalViewAfterClassif->ActivateOverlaySecond(true);
this->Update();
}
template <class TPixel>
void
ImageViewerAS<TPixel>::LoadLeftImage()
{
const char* filename = fl_file_chooser("Pick an image file", "*.*",
".");
if(filename == NULL || strlen(filename)<1)
{
return ;
}
typedef otb::ImageViewerAS<unsigned char> ViewerType;
typedef ViewerType::ImageType ImageType;
typedef otb::ImageFileReader< ImageType > VolumeReaderType;
VolumeReaderType::Pointer lReader = VolumeReaderType::New();
lReader->SetFileName(filename);
lReader->Update();
SetLabel( "Label" );
SetLeftImage( lReader->GetOutput() );
this->Update();
}
template <class TPixel>
void
ImageViewerAS<TPixel>::LoadRightImage()
{
const char* filename = fl_file_chooser("Pick an image file", "*.*",
".");
if(filename == NULL || strlen(filename)<1)
{
return ;
}
typedef otb::ImageViewerAS<unsigned char> ViewerType;
typedef ViewerType::ImageType ImageType;
typedef otb::ImageFileReader< ImageType > VolumeReaderType;
VolumeReaderType::Pointer lReader = VolumeReaderType::New();
lReader->SetFileName(filename);
lReader->Update();
SetLabel( "Label" );
SetRightImage( lReader->GetOutput() );
this->Update();
}
template <class TPixel>
void
ImageViewerAS<TPixel>::SynchronizeClickedPoints(float x,float y,float z,
ColorType color)
{
m_PrincipalViewAfterClassif->ViewClickedPoints(true);
m_PrincipalViewAfterClassif->clickSelect(x,y,z,color);
}
template <class TPixel>
void
ImageViewerAS<TPixel>::SynchronizeClickedPointsBox(float x,float y,float z,
ColorType color, int width, int height)
{
m_PrincipalViewAfterClassif->ViewClickedPoints(true);
m_PrincipalViewAfterClassif->clickSelectBox(x,y,z,color,width,height);
}
} // end namespace otb
#endif
# data file for the Fltk User Interface Designer (fluid)
version 1.0107
header_name {.h}
code_name {.cxx}
class otbImageViewerASGUI {open
} {
Function {otbImageViewerASGUI()} {} {}
Function {~otbImageViewerASGUI()} {return_type virtual
} {}
Function {CreateGUI()} {open
} {
Fl_Window iviewWindowPrincipal {
label {Principal Window} open
xywh {469 33 710 575} type Double box PLASTIC_DOWN_BOX color 196 labelsize 12 align 33 visible
} {
Fl_Group glWindowGroupPrincipal {open
xywh {-5 -5 715 580} color 40
} {
Fl_Button bUndo {
label Undo
callback {EraseLastClickedPoint();}
xywh {70 420 64 25} box SHADOW_BOX color 55 labelfont 1 labelcolor 176
}
Fl_Button bLearn {
label Learn
callback {LearnAlgorithm();}
xywh {215 420 64 25} box SHADOW_BOX color 55 labelfont 1 labelcolor 176
}
Fl_Button bClassif {
label Classif
callback {ClassificationAlgorithm();} selected
xywh {215 450 64 25} box SHADOW_BOX color 55 labelfont 1 labelcolor 176
}
Fl_Button bReset {
label Reset
callback {EraseAllClickedPoints();}
xywh {70 450 65 25} box SHADOW_BOX color 55 labelfont 1 labelcolor 176
}
Fl_Button bC2 {
label C2
callback {DisplaySecondClass();}
xywh {560 430 64 25} box SHADOW_BOX color 55 labelfont 1 labelcolor 176
}
Fl_Button bC1 {
label C1
callback {DisplayFirstClass();}
xywh {440 430 64 25} box SHADOW_BOX color 55 labelfont 1 labelcolor 176
}
Fl_Menu_Bar {} {open
xywh {0 0 710 25} color 7 labelfont 1 labelcolor 136
} {
Submenu {} {
label File open
xywh {30 30 100 20} labelfont 1 labelcolor 176
} {
MenuItem {} {
label {Load Left File}
callback {LoadLeftImage();}
xywh {20 20 30 20}
}
MenuItem {} {
label {Load Right File}
callback {LoadRightImage();}
xywh {5 5 30 20}
}
MenuItem {} {
label Exit
callback {exit(-1);}
xywh {20 20 30 20}
}
}
}
Fl_Box {} {
label Avant
xywh {10 35 340 375} box EMBOSSED_BOX
code0 {\#include <otbPrincipalImageViewAS.h>}
code1 {CreatePrincipalImageViewBeforeClassif( glWindowGroupPrincipal, o );}
class Fl_Gl_Window
}
Fl_Box {} {
label {Aprs}
xywh {360 35 340 375} box EMBOSSED_BOX
code0 {\#include <otbPrincipalImageViewAS.h>}
code1 {CreatePrincipalImageViewAfterClassif( glWindowGroupPrincipal, o );}
class Fl_Gl_Window
}
Fl_Text_Display {} {
label Commentaires
xywh {15 505 685 50} labelfont 1 labelcolor 176
}
}
}
}
Function {CreatePrincipalImageViewBeforeClassif( Fl_Group *,Fl_Gl_Window * w )} {return_type {virtual void}
} {}
Function {CreatePrincipalImageViewAfterClassif( Fl_Group *,Fl_Gl_Window * w )} {return_type {virtual void}
} {}
Function {SetImage( itk::ImageBase<3> * img )} {return_type {virtual void}
} {}
Function {Show(void)} {return_type {virtual void}
} {}
Function {Hide(void)} {return_type {virtual void}
} {}
Function {Update(void)} {return_type {virtual void}
} {}
Function {Synchronize(void)} {return_type {virtual void}
} {}
Function {EraseLastClickedPoint()} {return_type {virtual void}
} {}
Function {EraseAllClickedPoints()} {return_type {virtual void}
} {}
Function {LearnAlgorithm()} {return_type {virtual void}
} {}
Function {ClassificationAlgorithm()} {return_type {virtual void}
} {}
Function {DisplaySecondClass()} {return_type {virtual void}
} {}
Function {DisplayFirstClass()} {return_type {virtual void}
} {}
Function {LoadLeftImage()} {return_type {virtual void}
} {}
Function {LoadRightImage()} {open return_type {virtual void}
} {}
}
/*=========================================================================
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 otbPrincipalImageViewAS_h
#define otbPrincipalImageViewAS_h
#include <FL/gl.h>
#include <FL/Fl.H>
#include <FL/fl_draw.H>
#include <FL/Fl_Gl_Window.H>
#include "otbGLVectorImageViewClick.h"
#include "otbSVMPointSetModelEstimator.h"
#include "itkPointSet.h"
namespace otb
{
/**
* \class PrincipalImageViewAS
* \brief Class for viewing an image in entier resolution
*
* See GLVectorImageViewClick.h for details...
**/
template <class TPixel, class TPixelOverlay>
class ITK_EXPORT PrincipalImageViewAS : public
GLVectorImageViewClick<TPixel, TPixelOverlay>
{
public:
float _x,_y,_z;
typedef PrincipalImageViewAS Self;
typedef GLVectorImageViewClick<TPixel, TPixelOverlay> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/* typdef for the image*/
typedef typename Superclass::ImageType ImageType;
typedef typename Superclass::ImagePointer ImagePointer;
typedef typename Superclass::ImageConstPointer ImageConstPointer;
typedef typename Superclass::RegionType RegionType;
typedef typename Superclass::SizeType SizeType;
typedef typename Superclass::IndexType IndexType;
typedef typename Superclass::PixelType PixelType;
/* typedef for learning and classification */
typedef float InputPixelType;
typedef std::vector<InputPixelType> InputVectorType;
typedef int LabelPixelType;
typedef itk::PointSet< InputVectorType, 2> MeasurePointSetType;
typedef itk::PointSet< LabelPixelType, 2> LabelPointSetType;
typedef otb::SVMPointSetModelEstimator< MeasurePointSetType,
LabelPointSetType > EstimatorType;
/*! Method for creation through the object factory. */
itkNewMacro(Self);
/*! Run-time type information (and related methods). */
itkTypeMacro(PrincipalImageViewAS,GLVectorImageViewClick);
virtual int handle(int event);
/*! Show the image (display the window) */
virtual void Show(void);
/*! Erase the last clicked point */
virtual void UndoPt();
/*! Erase all clicked points */
virtual void ResetPts();
/*! Learn Step */
void LearnStep();
/*! Classification Step */
void ClassificationStep();
/*! If b is false, it is not possible to click on the image */
void SetClickable(bool b);
/*! Selected point correct */
bool cMem;
/*! Box color */
ColorType cRectColor;
/*! To know if click or box */
int nbDrag;
/*! Image clickable */
bool cClickable;
/*! Estimator after learning */
EstimatorType::Pointer cEstimator;
protected:
/*! Standard constructor */
PrincipalImageViewAS();
/*! Standard destructor */
virtual ~PrincipalImageViewAS(void);
};
} //namespace
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbPrincipalImageViewAS.txx"
#endif
#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 otbPrincipalImageViewAS_txx
#define otbPrincipalImageViewAS_txx
#include "otbPrincipalImageViewAS.h"
#include "itkPointSet.h"
#include "otbSVMPointSetModelEstimator.h"
#include "itkListSample.h"
//#include "otbVectorImageToASImageAdaptor.h"
#include "otbVectorImage.h"
#include "otbImage.h"
#include "itkImageToListAdaptor.h"
#include "itkScalarToArrayCastImageFilter.h"
#include "itkVectorCastImageFilter.h"
//#include "itkPointSetToListAdaptor.h"
#include "otbSVMClassifier.h"
#include "itkVectorToRGBImageAdaptor.h"
#include "itkVectorCastImageFilter.h"
#include "itkCastImageFilter.h"
namespace otb
{
template <class TPixel, class TPixelOverlay>
PrincipalImageViewAS<TPixel, TPixelOverlay>::
PrincipalImageViewAS() : GLVectorImageViewClick<TPixel, TPixelOverlay>()
{
}
template <class TPixel, class TPixelOverlay>
PrincipalImageViewAS<TPixel, TPixelOverlay>::
~PrincipalImageViewAS()
{
}
template <class TPixel, class TPixelOverlay>
int
PrincipalImageViewAS<TPixel, TPixelOverlay>::handle(int event)
{
int key, x=0, y=0 ,z=0;
ColorType colorTmp;
std::list<ClickPoint>::iterator it;
switch(event)
{
case FL_PUSH:
nbDrag = 0;
x = Fl::event_x()-this->cOffSetX;
y = Fl::event_y()-this->cOffSetY;
// Click on the picture ?
if ((x<0)||(x>this->GetViewImageRegion().GetSize()[0]*this->cScale)
||(y<0)||(y>this->GetViewImageRegion().GetSize()[1]*this->cScale))
cMem = false ;
else
cMem = true;
//std::cout << "Coord : " << x << " " << y << std::endl;
// Clicked points display
this->ViewClickedPoints(true);
// Test to know if mouse click is on image
if (cMem&&cClickable)
{
if (Fl::event_button()==FL_LEFT_MOUSE)
{
colorTmp = COLOR_BLUE;
//std::cout << "Click gauche !!" << std::endl;
}
else if (Fl::event_button()==FL_RIGHT_MOUSE)
{
colorTmp = COLOR_RED;
//std::cout << "Click droit !!" << std::endl;
}
this->clickSelect(x,y,z,colorTmp);
// Synchronize two displays in HMI
this->GetViewer()->SynchronizeClickedPoints(x,y,z,colorTmp);
/*for (it=this->cClickedPoints.begin();it!=this->cClickedPoints.end();it++)
std::cout << "Point : " << (*it).x << " " << (*it).y << std::endl ;
this->cClickedPoints.pop_back();*/
this->coord[0] = x;
this->coord[1] = y;
cRectColor=colorTmp;
}
case FL_DRAG:
{
nbDrag++;
if (cMem&&cClickable)
{
x = Fl::event_x()-this->cOffSetX;
y = Fl::event_y()-this->cOffSetY;
// Drag on the picture ?
if ((x>0)&&(x<this->GetViewImageRegion().GetSize()[0]*this->cScale)
&&(y>0)&&(y<this->GetViewImageRegion().GetSize()[1]*this->cScale))
{
this->cSelectRectangle = true ; // Display ON for box selection
this->coord[2] = Fl::event_x()-this->cOffSetX;
this->coord[3] = Fl::event_y()-this->cOffSetY;
this->redraw();
}
}
}
case FL_FOCUS :
this->update();
//THOMAS
// this->GetViewer()->PrincipalResize();
return 1;
break;
case FL_HIDE :
this->GetViewer()->Hide();
return 0;
break;
case FL_RELEASE:
this->cSelectRectangle = false ; // Display OFF for box selection
if (cMem&&cClickable)
{
// Release on the picture ?
if ((x>0)&&(x<this->GetViewImageRegion().GetSize()[0]*this->cScale)
&&(y>0)&&(y<this->GetViewImageRegion().GetSize()[1]*this->cScale))
{
this->coord[2] = Fl::event_x()-this->cOffSetX;
this->coord[3] = Fl::event_y()-this->cOffSetY;
}
this->ViewClickedPoints(true);
// If box selection
if (nbDrag>1)
{
int xTmp = this->coord[0];
int yTmp = this->coord[1];
if (this->coord[0]>this->coord[2])
{
xTmp = this->coord[2];
}
if (this->coord[1]>this->coord[3])
{
yTmp = this->coord[3];
}
this->clickSelectBox(xTmp,yTmp,z,cRectColor,
static_cast<int>(fabs(static_cast<float>(this->coord[2]-this->coord[0]))),
static_cast<int>(fabs(static_cast<float>(this->coord[1]-this->coord[3]))));
// Synchronize two displays in HMI
this->GetViewer()->SynchronizeClickedPointsBox(xTmp,yTmp,z,cRectColor,
static_cast<int>(fabs(static_cast<float>(this->coord[2]-this->coord[0]))),
static_cast<int>(fabs(static_cast<float>(this->coord[1]-this->coord[3]))));
}
}
return 0;
break;
case FL_KEYBOARD:
case FL_SHORTCUT:
key = Fl::event_text()[0];
switch(key)
{
case 'u':
case 'U':
this->update();
return 1;
break;
default:
break;
}
default:
break;
}
return 0;
}
template <class TPixel, class TPixelOverlay>
void PrincipalImageViewAS<TPixel, TPixelOverlay>::Show(void)
{
this->BuildWithImageRegion();
this->m_flDoubleWindow->show();
this->m_flDoubleWindow->label( this->GetLabel().c_str() );
this->show();
this->update();
}
template <class TPixel, class TPixelOverlay>
void
PrincipalImageViewAS<TPixel, TPixelOverlay>::UndoPt()
{
if (this->cClickedPoints.size()!=0)
this->cClickedPoints.pop_front();
this->update();
}
template <class TPixel, class TPixelOverlay>
void
PrincipalImageViewAS<TPixel, TPixelOverlay>::ResetPts()
{
this->cClickedPoints.clear();
this->update();
}
template <class TPixel, class TPixelOverlay>
void
PrincipalImageViewAS<TPixel, TPixelOverlay>::LearnStep()
{
// Declaration for input image values
ImagePointer lInpuPtr = this->GetInput();
IndexType ind;
// Scale calcul for correspondance between real image and displayed image
double zoomBase = (double)this->cW / (this->cDimSize[0]);
if(zoomBase > (double)this->cH / (this->cDimSize[1]))
{
zoomBase = (double)this->cH / (this->cDimSize[1]);
}
zoomBase = 1/zoomBase ;
std::list<ClickPoint>::iterator it;
// Conversion from ClickedPoint structure to PointSet structure
MeasurePointSetType::Pointer mPSet = MeasurePointSetType::New();
LabelPointSetType::Pointer lPSet = LabelPointSetType::New();
typedef MeasurePointSetType::PointType MeasurePointType;
typedef LabelPointSetType::PointType LabelPointType;
typedef MeasurePointSetType::PointsContainer MeasurePointsContainer;
typedef LabelPointSetType::PointsContainer LabelPointsContainer;
MeasurePointsContainer::Pointer mCont = MeasurePointsContainer::New();
LabelPointsContainer::Pointer lCont = LabelPointsContainer::New();
int pointId=0, indiceIm = 0;
MeasurePointType mP;
LabelPointType lP;
LabelPixelType label;
PixelType pixelInput;
int noChannels(0);
int nbChannels(0);
int channelIn(0);
InputVectorType measure(this->m_ChannelsWorks.size() );
it=this->cClickedPoints.begin();
while(it!=this->cClickedPoints.end() )
{
// ClickPoint is a point
if (!(it->isForBox))
{
// index position for the measured point
mP[0]=it->x;
mP[1]=it->y;
mP[0]=(int)((it->x)*zoomBase);
mP[1]=(int)((it->y)*zoomBase);
// index position for the label point
lP[0]=it->x;
lP[1]=it->y;
lP[0]=(int)((it->x)*zoomBase);
lP[1]=(int)((it->y)*zoomBase);
// Recuperation of real values in input image, not display values
ind[0]=(int)((it->x)*zoomBase);
ind[1]=(int)((it->y)*zoomBase);
/*
std::cout <<" points : "<< ind[0] << " , " << ind[1] << std::endl;
*/
// Traitement sur les canaux selectionnes.
pixelInput = lInpuPtr->GetPixel(ind);
for ( nbChannels = 0 ; nbChannels < this->m_ChannelsWorks.size() ; nbChannels++)
{
channelIn = this->m_ChannelsWorks[nbChannels] - 1;
measure[nbChannels] = static_cast<InputPixelType>(pixelInput[channelIn]);
}
if (it->color == COLOR_BLUE)
label= -1;
else if (it->color == COLOR_RED)
label = 1;
else
itkExceptionMacro(<< "Unknown color");
mCont->InsertElement( pointId , mP );
mPSet->SetPointData( pointId, measure );
lCont->InsertElement( pointId , lP );
lPSet->SetPointData( pointId, label );
pointId++;
}
// ClickPoint is a box
else
{
int startX = (int)((it->x)*zoomBase);
int endX = (int)((it->x+it->w)*zoomBase);
int startY = (int)((it->y)*zoomBase);
int endY = (int)((it->y+it->h)*zoomBase);
int temp;
if(startX > endX )
{
temp = endX;
endX = startX;
startX = temp;
}
if(startY > endY )
{
temp = endY;
endY = startY;
startY = temp;
}
for (int i=startX; i<=endX; i++)
{
for (int j=startY; j<=endY; j++)
{
// index position for the measured point
mP[0]=i;
mP[1]=j;
// index position for the label point
lP[0]=i;
lP[1]=j;
// Recuperation of real values in input image, not display values
ind[0]=i;
ind[1]=j;
/*
std::cout <<" box : "<< ind[0] << " , " << ind[1] << std::endl;
*/
// Traitement sur les canaux selectionnes.
pixelInput = lInpuPtr->GetPixel(ind);
for ( nbChannels = 0 ; nbChannels < this->m_ChannelsWorks.size() ; nbChannels++)
{
channelIn = this->m_ChannelsWorks[nbChannels] - 1;
measure[nbChannels] = static_cast<InputPixelType>(pixelInput[channelIn]);
}
if (it->color == COLOR_BLUE)
label = -1;
else if (it->color == COLOR_RED)
label = 1;
else
itkExceptionMacro(<< "Unknown color");
mCont->InsertElement( pointId , mP );
mPSet->SetPointData( pointId, measure );
lCont->InsertElement( pointId , lP );
lPSet->SetPointData( pointId, label );
pointId++;
}
}
}
++it;
}
mPSet->SetPoints( mCont );
std::cout << "1" << std::endl;
lPSet->SetPoints( lCont );
std::cout << "2" << std::endl;
EstimatorType::Pointer learningEstimator = EstimatorType::New();
std::cout << "3" << std::endl;
learningEstimator->SetInputPointSet( mPSet );
std::cout << "4" << std::endl;
learningEstimator->SetTrainingPointSet( lPSet );
std::cout << "5" << std::endl;
learningEstimator->SetNumberOfClasses( 2 );
std::cout << "6" << std::endl;
std::cout << "pointId : " << pointId << std::endl;
learningEstimator->Update();
std::cout << "7" << std::endl;
cEstimator = learningEstimator;
std::cout << "End learning model" << std::endl;
}
template <class TPixel, class TPixelOverlay>
void
PrincipalImageViewAS<TPixel, TPixelOverlay>::ClassificationStep()
{
// Image conversion from reader to classification
typedef otb::VectorImage<TPixel,2> ReaderImageType;
typedef itk::FixedArray< float, 3 > MeasurementVectorType;
typedef otb::Image< MeasurementVectorType, 2 > InputClassifImageType;
typename ReaderImageType::Pointer inputImage;
inputImage = this->GetInput();
typedef itk::VectorCastImageFilter<ReaderImageType,InputClassifImageType> CasterType;
typename CasterType::Pointer caster = CasterType::New();
caster->SetInput(inputImage);
caster->Update();
// Image definition for classification
typedef itk::Statistics::ImageToListAdaptor< InputClassifImageType > SampleType;
SampleType::Pointer sample = SampleType::New();
sample->SetImage( caster->GetOutput() );
std::cout << "Sample set to Adaptor" << std::endl;
// preparing classifier and decision rule object
typedef otb::SVMModel< SampleType::MeasurementVectorType::ValueType, LabelPixelType > ModelType;
ModelType::Pointer model = cEstimator->GetModel();
int numberOfClasses = model->GetNumberOfClasses();
typedef otb::SVMClassifier< SampleType, LabelPixelType > ClassifierType ;
ClassifierType::Pointer classifier = ClassifierType::New() ;
classifier->SetNumberOfClasses(numberOfClasses) ;
classifier->SetModel( model );
classifier->SetSample(sample.GetPointer()) ;
classifier->Update() ;
// Build the class map
std::cout << "Generating classify map" << std::endl;
ClassifierType::OutputType* membershipSample =
classifier->GetOutput() ;
ClassifierType::OutputType::ConstIterator m_iter =
membershipSample->Begin() ;
ClassifierType::OutputType::ConstIterator m_last =
membershipSample->End() ;
const unsigned int Dimension = 2;
typedef ClassifierType::ClassLabelType OutputPixelType;
typedef otb::Image< TPixelOverlay, Dimension > OutputImageType;
typename OutputImageType::Pointer outputImage = OutputImageType::New();
typename OutputImageType::Pointer ImageClassFirst = OutputImageType::New();
typename OutputImageType::Pointer ImageClassSecond = OutputImageType::New();
typedef itk::Index<Dimension> myIndexType;
typedef itk::Size<Dimension> mySizeType;
typedef itk::ImageRegion<Dimension> myRegionType;
mySizeType size;
size[0] = inputImage->GetRequestedRegion().GetSize()[0];
size[1] = inputImage->GetRequestedRegion().GetSize()[1];
myIndexType start;
start[0] = 0;
start[1] = 0;
myRegionType region;
region.SetIndex( start );
region.SetSize( size );
outputImage->SetRegions( region );
outputImage->Allocate();
ImageClassFirst->SetRegions( region );
ImageClassFirst->Allocate();
ImageClassSecond->SetRegions( region );
ImageClassSecond->Allocate();
std::cout << "Image iterator" << std::endl;
typedef itk::ImageRegionIterator< OutputImageType> OutputIteratorType;
OutputIteratorType outIt( outputImage, outputImage->GetBufferedRegion() );
OutputIteratorType classSecondIt( ImageClassSecond, outputImage->GetBufferedRegion() );
OutputIteratorType classFirstIt( ImageClassFirst,outputImage->GetBufferedRegion() );
outIt.GoToBegin();
classSecondIt.GoToBegin();
classFirstIt.GoToBegin();
TPixelOverlay MaxValue = static_cast<TPixelOverlay>(255);
TPixelOverlay MinValue = static_cast<TPixelOverlay>(0);
while (m_iter != m_last && !outIt.IsAtEnd())
{
ClassifierType::ClassLabelType label = m_iter.GetClassLabel();
if( label == -1 )
{
classFirstIt.Set(MaxValue);
classSecondIt.Set(MinValue);
}
if( label == 1 )
{
classFirstIt.Set(MinValue);
classSecondIt.Set(MaxValue);
}
outIt.Set(m_iter.GetClassLabel());
++m_iter ;
++outIt;
++classSecondIt;
++classFirstIt;
}
// cOverlayData ....
this->SetInputOverlay(ImageClassFirst, ImageClassSecond );
//ViewOverlayData(true);
std::cout << "End Classif" << std::endl;
}
template <class TPixel, class TPixelOverlay>
void
PrincipalImageViewAS<TPixel, TPixelOverlay>::SetClickable(bool b)
{
cClickable = b ;
}
}; //namespace
#endif
......@@ -53,8 +53,6 @@ TARGET_LINK_LIBRARIES(otbImageViewerWithitkVectorImage OTBVisu OTBIO OTBCommon g
ADD_EXECUTABLE(otbImageViewerWithitkImage otbImageViewerWithitkImage.cxx)
TARGET_LINK_LIBRARIES(otbImageViewerWithitkImage OTBVisu OTBIO OTBCommon gdal ITKIO ITKCommon)
ADD_EXECUTABLE(otbImageViewerAS otbImageViewerAS.cxx)
TARGET_LINK_LIBRARIES(otbImageViewerAS OTBVisu OTBIO OTBCommon otbsvm gdal ITKIO ITKCommon)
ENDIF( NOT OTB_DISABLE_CXX_TESTING )
......
/*=========================================================================
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.
=========================================================================*/
#include <stdlib.h>
#include <iostream>
#include "itkExceptionObject.h"
#include "otbImageFileReader.h"
#include "otbImageViewerAS.h"
int main( int argc, char * argv[] )
{
try
{
int lRunFLTK(1);
if( argc < 2 || argc > 3 )
{
std::cout <<" Usage : InputImage"<<std::endl;
}
//Parametre utilise pour le lancement du test de facon automatique, sans intervention de l'utilisateur
if( argc == 3 )
{
lRunFLTK = atoi(argv[2]);
}
const char * inputFilename = argv[1];
typedef otb::ImageViewerAS<unsigned char> ViewerType;
ViewerType::Pointer lViewer = ViewerType::New();
typedef ViewerType::ImageType ImageType;
typedef otb::ImageFileReader< ImageType > VolumeReaderType;
VolumeReaderType::Pointer lReader = VolumeReaderType::New();
lReader->SetFileName(inputFilename);
lReader->Update();
lViewer->SetLabel( "Label" );
lViewer->SetLeftImage( lReader->GetOutput() );
lViewer->SetRightImage( lReader->GetOutput() );
// lViewer->SetGrayLevelChannel(1);
// lViewer->SetRGBChannels(1,2,3);
// lViewer->SetRedChannel(3);
// lViewer->SetGreenChannel(2);
// lViewer->SetBlueChannel(1);
// lViewer->Update();
lViewer->Show();
if( lRunFLTK == 1 )
{
Fl::run();
}
}
catch( itk::ExceptionObject & err )
{
std::cout << "Exception itk::ExceptionObject levee !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch( ... )
{
std::cout << "Exception levee inconnue !" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
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