Commit 4e22ca2d authored by Cyrille Valladeau's avatar Cyrille Valladeau
Browse files

Modification de la visu : affichage de rectangle.

parent 53bf3081
......@@ -142,7 +142,8 @@ class ITK_EXPORT ImageViewer
itkGetMacro(UseScroll,bool);
itkGetConstReferenceMacro(MinComponentValue,VectorPixelType);
itkGetConstReferenceMacro(MaxComponentValue,VectorPixelType);
itkGetConstReferenceMacro(ZoomWidget,ZoomWidgetPointerType);
/** Set the input image (VectorImage version) */
virtual void SetImage(ImageType * img);
......
......@@ -574,6 +574,7 @@ typedef itk::ImageRegionConstIterator< ImageType > InputIteratorType;
{
m_ZoomWindow->copy_label(oss.str().c_str());
}
m_ZoomWidget->SetFormListOverlay(m_FullWidget->GetFormList());
m_ZoomWindow->redraw();
m_ZoomWidget->redraw();
}
......@@ -670,11 +671,12 @@ ImageViewer<TPixel>
IndexType newIndex;
newIndex[0]=clickedIndex[0]-region.GetSize()[0]/2;
newIndex[1]=clickedIndex[1]-region.GetSize()[1]/2;
region.SetIndex(newIndex);
RegionType newRegion = ComputeConstrainedRegion(region,m_InputImage->GetLargestPossibleRegion());
m_FullWidget->SetUpperLeftCorner(newRegion.GetIndex());
this->UpdateScrollWidget();
typename ViewerListType::Iterator linkedIt = m_LinkedViewerList->Begin();
......@@ -699,7 +701,7 @@ template <class TPixel>
void
ImageViewer<TPixel>
::ChangeZoomViewedRegion(IndexType clickedIndex)
{
{
m_Updating = true;
RegionType region = m_ZoomWidget->GetViewedRegion();
IndexType newIndex;
......@@ -709,6 +711,7 @@ template <class TPixel>
region.SetIndex(newIndex);
RegionType newRegion = ComputeConstrainedRegion(region,m_FullWidget->GetViewedRegion());
m_ZoomWidget->SetZoomUpperLeftCorner(newRegion.GetIndex());
m_ZoomWidget->redraw();
this->UpdateFullWidget();
......
......@@ -19,7 +19,10 @@ PURPOSE. See the above copyright notices for more information.
#define _otbImageViewerFullWidget_h
#include "otbFullResolutionImageWidget.h"
#include "otbImageWidgetBoxForm.h"
#include "otbImageWidgetRectangleForm.h"
#include "otbImageWidgetPointForm.h"
#include "otbPolygon.h"
namespace otb
{
......@@ -39,24 +42,29 @@ class ITK_EXPORT ImageViewerFullWidget
public:
/** Standard class typedefs */
typedef ImageViewerFullWidget Self;
typedef FullResolutionImageWidget<TPixel> Superclass;
typedef FullResolutionImageWidget<TPixel> Superclass;
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(ImageViewerFullWidget, FullResolutionImageWidget);
typedef TPixel PixelType;
typedef typename Superclass::IndexType IndexType;
typedef typename Superclass::SizeType SizeType;
typedef typename Superclass::SizeType SizeType;
typedef typename Superclass::ImageType ImageType;
typedef ImageViewer<PixelType> ParentType;
typedef ParentType* ParentPointerType;
typedef ImageViewer<PixelType> ParentType;
typedef ParentType* ParentPointerType;
typedef ImageWidgetBoxForm BoxType;
typedef ImageWidgetRectangleForm RectangleType;
typedef RectangleType::ColorType ColorType;
typedef ImageWidgetPointForm PointType;
itkSetMacro(Parent,ParentPointerType);
itkGetMacro(Parent,ParentPointerType);
/** Handle method */
......@@ -71,9 +79,20 @@ class ITK_EXPORT ImageViewerFullWidget
IndexType clickedIndex;
clickedIndex[0]=x;
clickedIndex[1]=y;
clickedIndex=this->WindowToImageCoordinates(clickedIndex);
m_Parent->ChangeZoomViewedRegion(clickedIndex);
return 1;
if (!m_ShortCutRectangle)
{
clickedIndex=this->WindowToImageCoordinates(clickedIndex);
m_Parent->ChangeZoomViewedRegion(clickedIndex);
}
if (!m_Drag)
{
m_LastIndex=this->WindowToImageCoordinates(clickedIndex);
if (m_ShortCutRectangle)
{
m_Drag = false;
}
}
return 1;
}
case FL_ENTER:
{
......@@ -88,6 +107,8 @@ class ITK_EXPORT ImageViewerFullWidget
}
case FL_MOVE:
{
if (!m_ShortCutRectangle)
{
m_MouseIn=true;
if(m_MouseMoveCount%m_ValueUpdateFrequency==0)
{
......@@ -103,8 +124,115 @@ class ITK_EXPORT ImageViewerFullWidget
}
}
m_MouseMoveCount++;
}
return 1;
}
case FL_DRAG:
{
if (m_ShortCutRectangle)
{
int x = Fl::event_x();
int y = Fl::event_y();
IndexType index;
index[0]=x;
index[1]=y;
IndexType clickedIndex=this->WindowToImageCoordinates(index);
//otbMsgDebugMacro(<<"Mouse dragged: "<<clickedIndex);
typename BoxType::Pointer box = BoxType::New();
box->SetColor(m_ClassColor);
IndexType boxIndex;
SizeType boxSize;
// compute the size of the select box
if(clickedIndex[0]>m_LastIndex[0])
{
boxIndex[0]=m_LastIndex[0];
boxSize[0]=clickedIndex[0]-m_LastIndex[0];
}
else
{
boxIndex[0]=clickedIndex[0];
boxSize[0]=m_LastIndex[0]-clickedIndex[0];
}
if(clickedIndex[1]>m_LastIndex[1])
{
boxIndex[1]=m_LastIndex[1];
boxSize[1]=clickedIndex[1]-m_LastIndex[1];
}
else
{
boxIndex[1]=clickedIndex[1];
boxSize[1]=m_LastIndex[1]-clickedIndex[1];
}
box->SetIndex(boxIndex);
box->SetSize(boxSize);
if(m_Drag)
{
this->GetFormList()->PopBack();
}
this->GetFormList()->PushBack(box);
m_Parent->Update();
m_Drag=true;
}
return 1;
}
case FL_RELEASE:
{
if (m_ShortCutRectangle)
{
int x = Fl::event_x();
int y = Fl::event_y();
IndexType clickedIndex;
clickedIndex[0]=x;
clickedIndex[1]=y;
clickedIndex=this->WindowToImageCoordinates(clickedIndex);
if(m_Drag)
{
typename RectangleType::Pointer rectangle = RectangleType::New();
IndexType boxIndex;
SizeType boxSize;
// compute the size of the select box
if(clickedIndex[0]>m_LastIndex[0])
{
boxIndex[0]=m_LastIndex[0];
boxSize[0]=clickedIndex[0]-m_LastIndex[0];
}
else
{
boxIndex[0]=clickedIndex[0];
boxSize[0]=m_LastIndex[0]-clickedIndex[0];
}
if(clickedIndex[1]>m_LastIndex[1])
{
boxIndex[1]=m_LastIndex[1];
boxSize[1]=clickedIndex[1]-m_LastIndex[1];
}
else
{
boxIndex[1]=clickedIndex[1];
boxSize[1]=m_LastIndex[1]-clickedIndex[1];
}
rectangle->SetIndex(boxIndex);
rectangle->SetSize(boxSize);
rectangle->SetColor(m_ClassColor);
this->GetFormList()->PopBack();
//otbMsgDebugMacro(<<"FL_RELEASE: PushBack");
this->GetFormList()->PushBack(rectangle);
}
else
{
typename PointType::Pointer point = PointType::New();
point->SetColor(m_ClassColor);
point->SetIndex(clickedIndex);
//otbMsgDebugMacro(<<"FL_RELEASE: PushBack");
this->GetFormList()->PushBack(point);
}
m_Parent->Update();
m_Drag=false;
}
return 1;
}
case FL_FOCUS:
{
return 1;
......@@ -115,35 +243,64 @@ class ITK_EXPORT ImageViewerFullWidget
}
case FL_KEYDOWN:
{
IndexType newIndex = this->GetViewedRegion().GetIndex();
SizeType newSize = this->GetViewedRegion().GetSize();
newIndex[0]=newIndex[0]+newSize[0]/2;
newIndex[1] = newIndex[1] + newSize[1]/2;
//IndexType newIndex = this->GetViewedRegion().GetIndex();
IndexType newIndex;
newIndex[0] = m_Parent->GetZoomWidget()->GetViewedRegion().GetIndex()[0];
newIndex[1] = m_Parent->GetZoomWidget()->GetViewedRegion().GetIndex()[1];
SizeType newSize = m_Parent->GetZoomWidget()->GetViewedRegion().GetSize();
//newIndex[0] = newIndex[0] + newSize[0]/2;
//newIndex[1] = newIndex[1] + newSize[1]/2;
switch(Fl::event_key())
{
case FL_Down:
{
newIndex[1] = newIndex[1]+newSize[1]/8;
if (!m_ShortCutRectangle)
{
newIndex[1] = newIndex[1]+static_cast<long int>(newSize[1]/2)+ newSize[1]/2;
newIndex[0] += newSize[0]/2;
}
break;
}
case FL_Up:
{
newIndex[1] = newIndex[1]-newSize[1]/8;
if (!m_ShortCutRectangle)
{
newIndex[1] = newIndex[1]-static_cast<long int>(newSize[1]/2)+ newSize[1]/2;
newIndex[0] += newSize[0]/2;
}
break;
}
case FL_Left:
{
newIndex[0] = newIndex[0]-newSize[0]/8;
if (!m_ShortCutRectangle)
{
newIndex[0] = newIndex[0]-static_cast<long int>(newSize[0]/2)+ newSize[0]/2;
newIndex[1] += newSize[1]/2;
}
break;
}
case FL_Right:
{
newIndex[0] = newIndex[0]+newSize[0]/8;
if (!m_ShortCutRectangle)
{
newIndex[0] = newIndex[0]+static_cast<long int>(newSize[0]/2)+ newSize[0]/2;
newIndex[1] += newSize[1]/2;
}
break;
}
}
m_Parent->ChangeFullViewedRegion(newIndex);
m_Parent->ChangeZoomViewedRegion(newIndex);
// RECTANGE SELECTION //////////////////////////////////////////////////
case FL_Control_L:
{
m_ShortCutRectangle = !m_ShortCutRectangle;
break;
}
}
if (!m_ShortCutRectangle)
{
m_Parent->ChangeFullViewedRegion(newIndex);
m_Parent->ChangeZoomViewedRegion(newIndex);
}
return 1;
}
case FL_HIDE:
......@@ -151,16 +308,20 @@ class ITK_EXPORT ImageViewerFullWidget
m_Parent->Hide();
return 0;
}
}
return 0;
}
}
return 0;
}
virtual void resize(int x,int y, int w, int h)
{
Superclass::resize(x,y,w,h);
{
Superclass::resize(x,y,w,h);
if(m_Parent->GetBuilt())
m_Parent->UpdateScrollWidget();
}
itkSetMacro(ClassColor,ColorType);
itkGetMacro(ClassColor,ColorType);
protected:
/**
......@@ -172,6 +333,13 @@ class ITK_EXPORT ImageViewerFullWidget
m_MousePos.Fill(0);
m_MouseMoveCount = 0;
m_ValueUpdateFrequency = 5;
m_ClassColor[0]=0.;
m_ClassColor[1]=1.;
m_ClassColor[2]=0.;
m_ClassColor[3]=0.5;
m_LastIndex.Fill(0);
m_ShortCutRectangle = false;
m_Drag = false;
};
/**
* Destructor.
......@@ -187,7 +355,10 @@ class ITK_EXPORT ImageViewerFullWidget
bool m_MouseIn;
unsigned int m_MouseMoveCount;
unsigned int m_ValueUpdateFrequency;
ColorType m_ClassColor;
IndexType m_LastIndex;
bool m_ShortCutRectangle;
bool m_Drag;
};
} // end namespace otb
......
......@@ -43,7 +43,8 @@ int otbImageViewer( int argc, char * argv[] )
// build the app
viewer->Show();
Fl::check();
//Fl::check();
Fl::run();
}
catch( itk::ExceptionObject & err )
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment