From d8edef346f2d6c64f6ed3bea7225aeb3a8b3970c Mon Sep 17 00:00:00 2001
From: Eduardo Davila <Eduardo.Davila@creatis.insa-lyon.fr>
Date: Wed, 21 Jul 2010 15:56:46 +0000
Subject: [PATCH] *** empty log message ***

---
 .../ColorLayerImageView.cxx                   |  35 ++++++
 .../ThresholdImageView/ColorLayerImageView.h  |   8 +-
 .../ColorLayerImageViewPanel.cxx              |  62 +++++++++-
 .../ColorLayerImageViewPanel.h                |   5 +-
 .../ThresholdImageView/LayerImageBase.cxx     | 107 +++++++++++-------
 .../ThresholdImageView/LayerImageBase.h       |   4 +-
 6 files changed, 169 insertions(+), 52 deletions(-)

diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageView.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageView.cxx
index 93d63ad..01c53b7 100644
--- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageView.cxx
+++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageView.cxx
@@ -17,6 +17,8 @@
   //=========================================================================
 	ColorLayerImageView::ColorLayerImageView( )
   {
+	  _z2			=	0;
+	  _fix_dinamic	=	true;
   }
 
   //=========================================================================
@@ -26,6 +28,33 @@
   //=========================================================================
 
 
+//----------------------------------------------------------------------------
+void ColorLayerImageView::SetSliceFixDinamic(bool fix_dinamic)
+{
+	_fix_dinamic = fix_dinamic;
+}
+
+//----------------------------------------------------------------------------
+void ColorLayerImageView::SetZ2(int z2)  
+{
+	_z2 = z2;
+}
+
+//----------------------------------------------------------------------------
+int ColorLayerImageView::GetZ() // virtual 
+{
+	int result=0;
+	if (_fix_dinamic==false)
+	{
+		result = _z2;
+	} else 	{
+		result = LayerImageBase::GetZ();
+	}  
+
+	return result;
+}
+
+
 //----------------------------------------------------------------------------
 void ColorLayerImageView::ConfigLookupTable()  // virtual
 {
@@ -66,6 +95,12 @@ void ColorLayerImageView::ConfigLookupTable()  // virtual
 		if ((ii>=delta0) && (ii<=delta1)) // iBlue
 		{
 			thresholdTable->SetTableValue( i , 0 , 0 , iBlue/delta , 1);	
+			if (ii==0)
+			{
+				thresholdTable->SetTableValue( i , 0 , 0 , iBlue/delta , 0);	
+			} else {
+				thresholdTable->SetTableValue( i , 0 , 0 , iBlue/delta , 1);	
+			}
 			iBlue++;
 		}
 		if ((ii>=delta1) && (ii<=delta2)) // iYellow
diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageView.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageView.h
index 6229bf1..e1f4a53 100644
--- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageView.h
+++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageView.h
@@ -22,11 +22,17 @@ class  ColorLayerImageView : public LayerImageBase
   public: 
 	  ColorLayerImageView( );
 	  ~ColorLayerImageView();
-	  
+	  void SetSliceFixDinamic(bool fix_dinamic);
+	  void SetZ2(int z2);
+	  virtual int GetZ();
+
   private:
 
+	  int _z2;
+	  bool _fix_dinamic;
 	  virtual void ConfigLookupTable();
 
+
   protected:
  };
 
diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageViewPanel.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageViewPanel.cxx
index 01244c3..6ea524f 100644
--- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageViewPanel.cxx
+++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageViewPanel.cxx
@@ -7,7 +7,7 @@
 
 
 #include "ColorLayerImageViewPanel.h"
-
+#include "OpenImageDialog.h"
 
 
 /**
@@ -24,7 +24,13 @@ ColorLayerImageViewPanel::ColorLayerImageViewPanel(wxWindow* parent, int min, in
 	_thresholdGo = true;
 	_cb_ShowHide = new wxCheckBox(this, wxID_ANY, _T("Show/Hide layer") );
 	_cb_ShowHide->SetValue(_thresholdGo);
-	
+
+	_cb_SliceFixDinamic = new wxCheckBox(this, wxID_ANY, _T("Slice Fix/Dinamic") );
+	_cb_SliceFixDinamic->SetValue(true);
+
+	_sl_SliceImage = new wxSlider(this, wxID_ANY, 0, 1000, 1000, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
+	_sl_SliceImage->Enable(false);
+
 	_interpolationCheckBox = new wxCheckBox(this, -1, _T("Image interpolation") );
 	_interpolationCheckBox->SetValue(true);	
 	_opacity = new wxSlider(this, wxID_ANY, 6, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
@@ -42,7 +48,14 @@ ColorLayerImageViewPanel::ColorLayerImageViewPanel(wxWindow* parent, int min, in
 	Connect( _cb_ShowHide->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &ColorLayerImageViewPanel::onThresholdShow ); 
 	Connect( _interpolationCheckBox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &ColorLayerImageViewPanel::onThresholdInterpolation );
 	Connect( _opacity->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction) &ColorLayerImageViewPanel::onChangeOpacity );
-	
+	Connect( _cb_SliceFixDinamic->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceFixDinamic );
+	Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_THUMBTRACK	, (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
+	Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_LINEUP		, (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
+	Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_LINEDOWN		, (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
+	Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_PAGEUP		, (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
+	Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_PAGEDOWN		, (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
+
+
 	wxFlexGridSizer * sizer		= new wxFlexGridSizer(1);
 	if (type==1)
 	{
@@ -56,7 +69,12 @@ ColorLayerImageViewPanel::ColorLayerImageViewPanel(wxWindow* parent, int min, in
 	sizer -> Add( _cb_ShowHide, 1, wxGROW );
 	sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
 	sizer -> Add( _interpolationCheckBox, 1, wxGROW );
-	
+
+	sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
+	sizer -> Add( new wxStaticText(this,-1,_T("Slice "))  , 1, wxGROW );
+	sizer -> Add( _sl_SliceImage, 1, wxGROW );
+	sizer -> Add( _cb_SliceFixDinamic, 1, wxGROW );
+
 	this->SetSizer( sizer );
 	this->SetAutoLayout( true );
 	this->Layout();
@@ -77,7 +95,19 @@ void ColorLayerImageViewPanel::SetColorLayerImageView(ColorLayerImageView* color
 //----------------------------------------------------------------------------
 void ColorLayerImageViewPanel::onReadImage(wxCommandEvent& event)
 {
-	printf("EED UPS.... ");
+// EED ???
+//      creaImageIO::WxSimpleDlg w(0,_T("Select your image"),"creaContours_Descriptor.dscp","creatisContours DB"); 
+//      w.ShowModal(); 
+
+	creaMaracasVisuKernel::OpenImageDialog diag = creaMaracasVisuKernel::OpenImageDialog();
+	_colorLayerImageView->SetImage( diag.getImageData() );
+
+	int ext[6];
+	diag.getImageData()->GetWholeExtent(ext);
+	_sl_SliceImage->SetRange( 0 , ext[5]-ext[4] );
+
+	_colorLayerImageView->onThreshold();
+	_colorLayerImageView->GetwxVtkBaseView()->Refresh();
 }
 
 
@@ -125,6 +155,28 @@ void ColorLayerImageViewPanel::onThresholdInterpolation(wxCommandEvent& event)
 
 }
 
+//----------------------------------------------------------------------------
+void ColorLayerImageViewPanel::onSliceFixDinamic(wxCommandEvent& event)
+{
+	bool fixdin = _cb_SliceFixDinamic->GetValue();
+	_colorLayerImageView->SetSliceFixDinamic( fixdin );
+	if (fixdin==false)
+	{
+		_colorLayerImageView->SetZ2( _sl_SliceImage->GetValue() );
+	}
+	_sl_SliceImage->Enable(!fixdin);
+	_colorLayerImageView->onThreshold();
+	_colorLayerImageView->GetwxVtkBaseView()->Refresh();
+}
+
+//----------------------------------------------------------------------------
+void ColorLayerImageViewPanel::onSliceImage(wxScrollEvent& event)
+{
+	_colorLayerImageView->SetZ2( _sl_SliceImage->GetValue() );
+	_colorLayerImageView->onThreshold();
+	_colorLayerImageView->GetwxVtkBaseView()->Refresh();
+}
+
 //----------------------------------------------------------------------------
 void ColorLayerImageViewPanel::onChangeOpacity(wxScrollEvent& event)
 {
diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageViewPanel.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageViewPanel.h
index bbb52c4..3927cc9 100644
--- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageViewPanel.h
+++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageViewPanel.h
@@ -37,12 +37,15 @@
 			wxSlider			*_opacity;
 			wxCheckBox			*_interpolationCheckBox;	
 			wxCheckBox			*_cb_ShowHide;
-			
+			wxCheckBox			*_cb_SliceFixDinamic;
+			wxSlider			*_sl_SliceImage;
 			void onReadImage(wxCommandEvent& event);
 			void onThresholdChange(wxCommandEvent& event);			
 			void onThresholdShow(wxCommandEvent& event);
 			void onThresholdInterpolation(wxCommandEvent& event);
 			void onChangeOpacity(wxScrollEvent& event);
+			void onSliceFixDinamic(wxCommandEvent& event);
+			void onSliceImage(wxScrollEvent& event);
 		};
 
 #endif
diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.cxx
index a4946f0..c079604 100644
--- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.cxx
+++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.cxx
@@ -30,7 +30,7 @@ void LayerImageBase::SetZ(int z)
 }
 
 //----------------------------------------------------------------------------
-int LayerImageBase::GetZ()
+int LayerImageBase::GetZ()  // virtual
 {
 	return _Z;
 }
@@ -75,54 +75,73 @@ vtkLookupTable* LayerImageBase::GetThresholdTable()
 	return _thresholdTable;
 }
 
+//----------------------------------------------------------------------------
+int LayerImageBase::CleanZ(int z)
+{ 
+	int ext[6];
+	_image->GetWholeExtent(ext);
+
+	if (z<0)
+	{
+		z=0;
+	}
+
+	if ( z > (ext[5]-ext[4]) )
+	{
+		z=ext[5]-ext[4];
+	}
 
+	return z;
+}
 
 //----------------------------------------------------------------------------
 void LayerImageBase::onThreshold()
 {
-	int	z = GetZ();
-	
-	if (!GetActorPresent())
-	{				
-		if (_thresholdTable==NULL)
-		{
-			//Lookup Table
-			_thresholdTable = vtkLookupTable::New();
-		} // _thresholdTable
-		
-		if (_thresholdMapper==NULL)
-		{
-			_thresholdMapper = vtkImageMapToColors::New( );
-		}
-		
-		if (_thresholdActor==NULL)
-		{
-			_thresholdActor = vtkImageActor::New( );
-			_thresholdActor->SetOpacity( 0.6 );
-			_thresholdActor->InterpolateOn(  );
-			_thresholdActor->SetPosition( 0,0, 900-1 );
-		} // _thresholdActor
-		
-		
-		_baseView->GetRenderer()->AddActor( _thresholdActor );
-		_actorPresent = true;		
-	}  // !GetActorPresent()
-
-	ConfigLookupTable();  // virtual method
-	_imageReslicer->SetInput( GetImage() );
-	_imageReslicer->SetInformationInput( GetImage() );			
-	_imageReslicer->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
-	_imageReslicer->SetOutputDimensionality(2);
-	_imageReslicer->SetInterpolationModeToLinear();
-	_imageReslicer->SetResliceAxesOrigin(0,0,z);
-
-	vtkImageData *img = _imageReslicer->GetOutput();
-	img->Update();
-	img->UpdateInformation();
-
-	_thresholdMapper->SetInput( img );
-	_thresholdMapper->SetLookupTable( _thresholdTable );
-	_thresholdActor->SetInput( _thresholdMapper->GetOutput() );
+
+	if (_image!=NULL)
+	{
+		int z=CleanZ( GetZ() );
+
+		if (!GetActorPresent())
+		{				
+			if (_thresholdTable==NULL)
+			{
+				//Lookup Table
+				_thresholdTable = vtkLookupTable::New();
+			} // _thresholdTable
+			
+			if (_thresholdMapper==NULL)
+			{
+				_thresholdMapper = vtkImageMapToColors::New( );
+			}
+			
+			if (_thresholdActor==NULL)
+			{
+				_thresholdActor = vtkImageActor::New( );
+				_thresholdActor->SetOpacity( 0.6 );
+				_thresholdActor->InterpolateOn(  );
+				_thresholdActor->SetPosition( 0,0, 900-1 );
+			} // _thresholdActor			
+			_baseView->GetRenderer()->AddActor( _thresholdActor );
+			_actorPresent = true;		
+		}  // !GetActorPresent()
+
+		ConfigLookupTable();  // virtual method
+		_imageReslicer->SetInput( GetImage() );
+		_imageReslicer->SetInformationInput( GetImage() );			
+		_imageReslicer->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
+		_imageReslicer->SetOutputDimensionality(2);
+		_imageReslicer->SetInterpolationModeToLinear();
+		_imageReslicer->SetResliceAxesOrigin(0,0,z);
+
+		vtkImageData *img = _imageReslicer->GetOutput();
+		img->Update();
+		img->UpdateInformation();
+
+		_thresholdMapper->SetInput( img );
+		_thresholdMapper->SetLookupTable( _thresholdTable );
+		_thresholdActor->SetInput( _thresholdMapper->GetOutput() );
+		} // _image
 }
 
 
diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.h
index 0af0e62..a96a2b3 100644
--- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.h
+++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.h
@@ -48,10 +48,12 @@ class LayerImageBase
 		wxVtkBaseView		*_baseView;
 
 		virtual void ConfigLookupTable() = 0;
-		int GetZ();
 		bool GetActorPresent();
+		int CleanZ(int z);
+
 
   protected:
+		virtual int GetZ();
 		vtkLookupTable* GetThresholdTable();
 		vtkImageData* GetImage();
  };
-- 
2.49.0