From d653db1bd5d3650822d8c8f6febd9e1ab59cd701 Mon Sep 17 00:00:00 2001
From: Juan Prieto <Juan.Prieto@creatis.insa-lyon.fr>
Date: Wed, 4 Aug 2010 18:45:27 +0000
Subject: [PATCH] changes in viewers, now is possible to initialize them with
 out an image but the render and the interactors are created, the old
 constructor is deprecated

---
 .../wxWindows/widgets/vtkBaseData.cxx         |  17 +-
 .../wxWindows/widgets/vtkMPR3DDataViewer.cxx  |  33 ++-
 .../wxWindows/widgets/wxMPRBaseData.cxx       |  29 ++-
 .../widgets/wxMaracas_N_ViewersWidget.cxx     |  62 ++++-
 .../widgets/wxMaracas_N_ViewersWidget.h       |  31 ++-
 .../wxWindows/widgets/wxVtk2DBaseView.cxx     |  50 +++-
 .../wxWindows/widgets/wxVtkMPR2DView.cxx      | 246 ++++++++++--------
 .../wxWindows/widgets/wxVtkMPR3DView.cxx      |  56 +++-
 8 files changed, 359 insertions(+), 165 deletions(-)

diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkBaseData.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkBaseData.cxx
index 5fe3f8b..bcec976 100644
--- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkBaseData.cxx
+++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkBaseData.cxx
@@ -6,7 +6,7 @@ vtkBaseData::vtkBaseData()
 
 	_z            = 0;
 	_t            = 0;
-	_marImageData = NULL;
+	_marImageData = 0;
 }
 
 //-------------------------------------------------------------------
@@ -24,7 +24,12 @@ void vtkBaseData::SetMarImageData(marImageData *marimagedata)
 //-------------------------------------------------------------------
 vtkImageData* vtkBaseData::GetImageData()
 {
-	return _marImageData->GetImageDataT(_t);
+	if(_marImageData){
+		return _marImageData->GetImageDataT(_t);
+	}else{
+		return 0;
+	}
+	
 }
 //-------------------------------------------------------------------
 marImageData* vtkBaseData::GetMarImageData()
@@ -47,6 +52,9 @@ void vtkBaseData::SetZ(double z){
 //	maxZ=dim[2];
 
 	int ext[6];
+	double *origin;
+	
+	
 	vtkImageData* img = _marImageData->GetImageData();
 	if(img!=NULL){
 		/*img->GetWholeExtent(ext);
@@ -63,13 +71,14 @@ void vtkBaseData::SetZ(double z){
 
 		_z=z;*/
 		img->GetExtent(ext);
+		origin = img->GetOrigin();
 		if (z > ext[5])
 		{
-			z = ext[5];
+			z = ext[5] + origin[2];
 		}
 		if (z < ext[4])
 		{
-			z = ext[4];
+			z = ext[4] + origin[2];
 		}
 
 		_z=z;
diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkMPR3DDataViewer.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkMPR3DDataViewer.cxx
index 8c369ff..07c0ec1 100644
--- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkMPR3DDataViewer.cxx
+++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkMPR3DDataViewer.cxx
@@ -140,8 +140,17 @@ void vtkMPR3DDataViewer::Configure()
 
 
 	double range[2];
-	_vtkmprbasedata->GetImageData()->GetScalarRange(range);
-	double max = range[1];
+	double max;
+	
+	if(_vtkmprbasedata->GetImageData()){
+		_vtkmprbasedata->GetImageData()->GetScalarRange(range);
+		max = range[1];
+	}else{
+		max = 1;
+	}
+	
+	
+	
 
 	_ctFunVectorPoint.clear();
 	_ctFunVectorPoint.push_back(max*0/4);
@@ -205,7 +214,9 @@ void vtkMPR3DDataViewer::Configure()
 	}
 	_saggitalColors->RemoveAllInputs();
 	
-    _saggitalColors->SetInput( _vtkmprbasedata->GetImageData() );
+	if(_vtkmprbasedata->GetImageData()){
+		_saggitalColors->SetInput( _vtkmprbasedata->GetImageData() );
+	}
 //    _saggitalColors->SetLookupTable(_bwLut);
 	
     _saggitalColors->SetLookupTable(_ctfun);
@@ -228,7 +239,9 @@ void vtkMPR3DDataViewer::Configure()
 	}
 
 	_axialColors->RemoveAllInputs();
-    _axialColors->SetInput( _vtkmprbasedata->GetImageData() );
+	if(_vtkmprbasedata->GetImageData()){
+		_axialColors->SetInput( _vtkmprbasedata->GetImageData() );
+	}
 //    _axialColors->SetLookupTable(_hueLut);
     _axialColors->SetLookupTable(_ctfun);
 
@@ -246,7 +259,9 @@ void vtkMPR3DDataViewer::Configure()
 		_coronalColors = vtkImageMapToColors::New();
 	}
 	_coronalColors->RemoveAllInputs();
-    _coronalColors->SetInput( _vtkmprbasedata->GetImageData() );
+	if(_vtkmprbasedata->GetImageData()){
+		_coronalColors->SetInput( _vtkmprbasedata->GetImageData() );
+	}
 //    _coronalColors->SetLookupTable(_satLut);
     _coronalColors->SetLookupTable(_ctfun);
 
@@ -263,7 +278,9 @@ void vtkMPR3DDataViewer::Configure()
 		_outlineData = vtkOutlineFilter::New();
 	}
 	_outlineData->RemoveAllInputs();
-    _outlineData->SetInput((vtkDataSet *) _vtkmprbasedata->GetImageData() );
+	if(_vtkmprbasedata->GetImageData()){
+		_outlineData->SetInput((vtkDataSet *) _vtkmprbasedata->GetImageData() );
+	}
 
 	if(_mapOutline==NULL){
 		_mapOutline = vtkPolyDataMapper::New();
@@ -280,8 +297,8 @@ void vtkMPR3DDataViewer::Configure()
 	
     
 
-	int ext[6];
-	_vtkmprbasedata->GetImageData()->GetExtent(ext);
+	//int ext[6];
+	//_vtkmprbasedata->GetImageData()->GetExtent(ext);
 
 	
 
diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMPRBaseData.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMPRBaseData.cxx
index 9ec1502..e1b7c37 100644
--- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMPRBaseData.cxx
+++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMPRBaseData.cxx
@@ -27,6 +27,12 @@ vtkMPRBaseData::vtkMPRBaseData()
   _x=0;
   _y=0;
   _z=0;
+  _x1 = 0;
+  _x2 = 0;
+  _y1 = 0;
+  _y2 = 0;
+  _z1 = 0;
+  _z2 = 0;
   _transformOrientation = NULL;
   _marImageData = NULL;
 }
@@ -43,11 +49,12 @@ void vtkMPRBaseData::Configure()
 	if(img !=NULL){
 		img->GetExtent (_x1,_x2,_y1,_y2,_z1,_z2);
 	//std::cout<<"vtkMPRBaseData::Configure() _x1= "<<_x1<<" _x2= "<<_x2<<" _y1= "<<_y1<<" _y2= "<<_y2<<" _z1= "<<_z1<<" _z2= "<<_z2<<std::endl;
-		if(_transformOrientation==NULL){
-			_transformOrientation=vtkTransform::New();
-		}
-		_transformOrientation->Identity();
+		
+	}
+	if(_transformOrientation==NULL){
+		_transformOrientation=vtkTransform::New();
 	}
+	_transformOrientation->Identity();
 }
 //-------------------------------------------------------------------
 void vtkMPRBaseData::GetDimensionExtention(int *x1,int *x2,int *y1,int *y2,int *z1,int *z2)
@@ -95,7 +102,7 @@ void vtkMPRBaseData::SetX(double x)
 {
 	//int dim[3];
 	int ext[6];
-
+	double* origin;
 	vtkImageData* img = _marImageData->GetImageData();
 	if(img!=NULL){
 		/*img->GetDimensions(dim);
@@ -109,14 +116,16 @@ void vtkMPRBaseData::SetX(double x)
 		}
 		_x=x;*/
 		img->GetExtent(ext);
+		origin = img->GetOrigin();
 		if (x < ext[0])
 		{
-			x=ext[0];
+			x=ext[0] + origin[0];
 		}
 		if (x > ext[1])
 		{
-			x=ext[1];
+			x=ext[1] + origin[0];
 		}
+		
 		_x=x;
 	}
 }
@@ -128,6 +137,7 @@ void vtkMPRBaseData::SetY(double y)
 {
 	//int dim[3];
 	int ext[6];
+	double* origin;
 	vtkImageData* img = _marImageData->GetImageData();
 	if(img!=NULL){
 		/*img->GetDimensions(dim);
@@ -141,13 +151,14 @@ void vtkMPRBaseData::SetY(double y)
 		}
 		_y=y;*/
 		img->GetExtent(ext);
+		origin = img->GetOrigin();
 		if (y<ext[2])
 		{
-			y=ext[2];
+			y=ext[2] + origin[1];
 		}
 		if (y > ext[3])
 		{
-			y=ext[3];
+			y=ext[3] + origin[1];
 		}
 		_y=y;
 	}
diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracas_N_ViewersWidget.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracas_N_ViewersWidget.cxx
index 4e6cd19..c097c93 100644
--- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracas_N_ViewersWidget.cxx
+++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracas_N_ViewersWidget.cxx
@@ -3,8 +3,8 @@
   Program:   wxMaracas
   Module:    $RCSfile: wxMaracas_N_ViewersWidget.cxx,v $
   Language:  C++
-  Date:      $Date: 2010/05/03 13:46:48 $
-  Version:   $Revision: 1.17 $
+  Date:      $Date: 2010/08/04 18:45:27 $
+  Version:   $Revision: 1.18 $
 
   Copyright: (c) 2002, 2003
   License:
@@ -63,6 +63,51 @@
 		}
 
 		
+	}
+	/**
+	*	@pre A wxWindow* object must be provided as a parent for the viewer and the type of layout for the viewer
+	*	@post The layout of the viewer is initialized, if no image is provided at first, a default image is 
+	*		used
+	*	@param wxWindow* parent of the window
+	*	@param std::vector<int>* vector of the type for the viewer 
+	*	@param vtkImageData* imagedata of the viewer
+	*/
+	wxMaracas_N_ViewersWidget::wxMaracas_N_ViewersWidget(wxWindow *parent, std::vector<int> *nTypeView, vtkImageData* imagedata)
+	: wxPanel( parent, -1){
+		wxwindow1		= NULL;
+		wxwindow2		= NULL;
+		wxwindow3		= NULL;
+		wxwindow4		= NULL;
+		_currentwxw		= NULL;
+		mvtkmprbasedata = NULL;
+		
+		wxSizer *sizer	= new wxBoxSizer(wxVERTICAL);
+		this->SetSizer(sizer);
+		this->SetAutoLayout(true);
+		
+		this->SetType(nTypeView);
+		
+		/*if(imagedata==NULL){
+			double spc[3];
+			spc[0] = 1;
+			spc[1] = 1;
+			spc[2] = 1;
+			int extent[6];
+			extent[0] = 0;
+			extent[1] = 1;
+			extent[2] = 0;
+			extent[3] = 1;
+			extent[4] = 0;
+			extent[5] = 1;
+			
+			imagedata = vtkImageData::New();
+			imagedata->SetSpacing(spc);
+			imagedata->SetExtent(extent);
+			imagedata->SetScalarTypeToUnsignedShort();
+			imagedata->AllocateScalars();
+		}*/
+		
+		this->UpdateLayout(imagedata);
 	}
 	//-------------------------------------------------------------------------
 	  
@@ -229,13 +274,13 @@
 		}
 		
 		//panel->SetDimension()
-		sizer->Add( wxwindow , 1, wxEXPAND);
+		sizer->Add( wxwindow , 1, wxGROW);
 		sizer->Layout();
-		_currentwxw = wxwindow;		
-		_currentwxw->Show(true);
+		//_currentwxw = wxwindow;		
+		//_currentwxw->Show(true);
 		
-		this->Layout();
-		this->Refresh();
+		//this->Layout();
+		//this->Refresh();
  }
 
 
@@ -253,6 +298,9 @@
 	 if (wxwindow2!=NULL) { wxwindow2->SetImage(image); } 
 	 if (wxwindow3!=NULL) { wxwindow3->SetImage(image); }
 	 if (wxwindow4!=NULL) { wxwindow4->SetImage(image); }
+	 
+	 ConfigureVTK();
+	 
  }
 
 //-----------------------------------------------------------------------------------
diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracas_N_ViewersWidget.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracas_N_ViewersWidget.h
index f938a38..19bd3c2 100644
--- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracas_N_ViewersWidget.h
+++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracas_N_ViewersWidget.h
@@ -3,8 +3,8 @@
   Program:   wxMaracas
   Module:    $RCSfile: wxMaracas_N_ViewersWidget.h,v $
   Language:  C++
-  Date:      $Date: 2010/05/03 13:46:48 $
-  Version:   $Revision: 1.10 $
+  Date:      $Date: 2010/08/04 18:45:27 $
+  Version:   $Revision: 1.11 $
 
   Copyright: (c) 2002, 2003
   License:
@@ -53,8 +53,33 @@ class creaMaracasVisu_EXPORT wxMaracas_N_ViewersWidget : public wxPanel
 	// Constructors & Destructors
 	//------------------------------------------------------------------------------------------------------------
 
+	/**
+	*	@pre A wxWindow* object must be provided as a parent for the viewer
+	*	@post The layout of the viewer is initialize, if there is no image or type set, 
+			only the panel of the viwer is created with no vtk objects
+	*	@param wxWindow* parent of the window
+	*	@param vtkImageData* imagedata of the viewer
+	*	@param std::vector<int>* vector of the type for the viewer
+	*	@deprecated This method will be eliminated in future versions, 
+	*	@deprecated the viewers will start with a default image if it is not specified, 
+	*	@deprecated this is in order to create the layout of the viewer, 
+	*	@deprecated the vtkInteractors* and the object vtkRenderer* use second constructor 
+	*/
 	wxMaracas_N_ViewersWidget(wxWindow *parent, vtkImageData* imagedata = NULL, std::vector<int> *nTypeView = NULL);
-    ~wxMaracas_N_ViewersWidget();
+	/**
+	*	@pre A wxWindow* object must be provided as a parent for the viewer and the type of layout for the viewer
+	*	@post The layout of the viewer is initialized, if no image is provided at first, a default image is 
+	*		used
+	*	@param wxWindow* parent of the window
+	*	@param std::vector<int>* vector of the type for the viewer 
+	*	@param vtkImageData* imagedata of the viewer
+	*/
+	wxMaracas_N_ViewersWidget(wxWindow *parent, std::vector<int> *nTypeView, vtkImageData* imagedata = NULL);
+	/**
+	*	@pre none
+	*	@post the viewer window is deleted, all of the interactors and the renderer are deleted
+	*/
+	~wxMaracas_N_ViewersWidget();
 
 	
 	//------------------------------------------------------------------------------------------------------------
diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtk2DBaseView.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtk2DBaseView.cxx
index b587d76..eba5e3e 100644
--- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtk2DBaseView.cxx
+++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtk2DBaseView.cxx
@@ -33,7 +33,16 @@ void wxVtk2DBaseView::TransformCoordinate_spacing_ViewToModel(double &X,double &
 //EEDx5
 	double spc[3];
 //	GetVtkBaseData()->GetImageData()->GetSpacing(spc);
-	this->_imageViewer2XYZ->GetVtkImageViewer2()->GetInput()->GetSpacing(spc);
+//JCP 04/08/10	W/O Image this->_imageViewer2XYZ->GetVtkImageViewer2()->GetInput()->GetSpacing(spc);
+	vtkImageData* image = this->_imageViewer2XYZ->GetVtkImageViewer2()->GetInput();
+	if(image){
+		image->GetSpacing(spc);
+	}else{
+		spc[0] = 1;
+		spc[1] = 1;
+		spc[2] = 1;
+	}
+	
 
 	X = X / spc[0];
 	Y = Y / spc[1];
@@ -47,8 +56,16 @@ void wxVtk2DBaseView::TransformCoordinate_spacing_ModelToView(double &X,double &
 //EEDx5
 	double spc[3];
 //	GetVtkBaseData()->GetImageData()->GetSpacing(spc);
-	this->_imageViewer2XYZ->GetVtkImageViewer2()->GetInput()->GetSpacing(spc);
-
+//JCP 04/08/10	W/O Image this->_imageViewer2XYZ->GetVtkImageViewer2()->GetInput()->GetSpacing(spc);
+	vtkImageData* image = this->_imageViewer2XYZ->GetVtkImageViewer2()->GetInput();
+	if(image){
+		image->GetSpacing(spc);
+	}else{
+		spc[0] = 1;
+		spc[1] = 1;
+		spc[2] = 1;
+	}
+//
 	X=X*spc[0];
 	Y=Y*spc[1];
 	Z=Z*spc[2];
@@ -58,19 +75,22 @@ void wxVtk2DBaseView::TransformCoordinate_spacing_ModelToView(double &X,double &
 //-------------------------------------------------------------------
 void wxVtk2DBaseView::ResetView()
 {
-	double spx,spy,spz;
-	int x1,x2,y1,y2,z1,z2;
+	double spx = 0,spy = 0,spz = 0;
+	int x1 = 1,x2 = 1,y1 = 1,y2 = 1,z1 = 1,z2 = 1;
 	wxVtkBaseView::Configure();
 	
 	wxVTKRenderWindowInteractor *iren = GetWxVTKRenderWindowInteractor();
 	vtkImageData *imageData	= GetVtkBaseData()->GetImageData();
-	imageData->UpdateInformation();
-	imageData->SetUpdateExtent( imageData->GetWholeExtent());
-	imageData->Update();
+	if(imageData){
+		imageData->UpdateInformation();
+		imageData->SetUpdateExtent( imageData->GetWholeExtent());
+		imageData->Update();
+		_imageViewer2XYZ->GetVtkImageViewer2()->SetInput(imageData );
+		imageData->GetSpacing (spx,spy,spz);
+		imageData->GetExtent (x1,x2,y1,y2,z1,z2);
+	}
 
-	_imageViewer2XYZ->GetVtkImageViewer2()->SetInput(imageData );
-	imageData->GetSpacing (spx,spy,spz);
-	imageData->GetExtent (x1,x2,y1,y2,z1,z2);
+	
 	_imageViewer2XYZ -> SetExtentDimension(x1,x2,y1,y2,z1,z2);
  	_imageViewer2XYZ -> GetVtkImageViewer2()->SetupInteractor ( iren );
 
@@ -276,7 +296,13 @@ vtkRenderWindow* wxVtk2DBaseView::GetRenWin()		// virtual
 void wxVtk2DBaseView::GetSpacing(double spc[3])  // virtual
 {
    vtkImageData *imageData	= GetVtkBaseData()->GetImageData();
-   imageData->GetSpacing(spc);
+   if(imageData){
+	imageData->GetSpacing(spc);
+   }else{
+	 spc[0] = 0; 
+	 spc[1] = 0;
+	 spc[2] = 0;
+   }
 }
 
 void wxVtk2DBaseView::setColorTransferFunction(vtkColorTransferFunction* colortable){
diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtkMPR2DView.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtkMPR2DView.cxx
index 7632ba2..b527964 100644
--- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtkMPR2DView.cxx
+++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtkMPR2DView.cxx
@@ -57,7 +57,15 @@ void wxVtkMPR2DView::Configure(){
 	double spc[3];
 	vtkImageData* img =  GetVtkmprbasedata()->GetImageData();
 	if(img!=NULL){
+		double* origin = img->GetOrigin();
+		img->GetExtent(x1,x2,y1,y2,z1,z2);
 		img->GetSpacing(spc);
+		x1 += origin[0];
+		x2 += origin[0];
+		y1 += origin[1];
+		y2 += origin[1];
+		z1 += origin[2];
+		z2 += origin[2];
 		x1 = (int)(x1*spc[0]);
 		y1 = (int)(y1*spc[1]);
 		z1 = (int)(z1*spc[2]);
@@ -67,114 +75,124 @@ void wxVtkMPR2DView::Configure(){
 		z2 = (int)(z2*spc[2]);
 
 		_visibleAxis = true;
-
+	}
+	
 	// Axe A
-		if(_lineAActor==NULL){
-			_ptsA = vtkPoints::New();
-			_ptsA->SetNumberOfPoints(2);
-			_ptsA->SetPoint(0, -1000	, -1000	, -1000 );
-			_ptsA->SetPoint(1,  1000	,  1000	,  1000	);
-			vtkCellArray *linesA;
-			linesA = vtkCellArray::New();
-			linesA->InsertNextCell(2);
-			linesA->InsertCellPoint(0);
-			linesA->InsertCellPoint(1);
-			_pdA = vtkPolyData::New();
-			_pdA->SetPoints( _ptsA );
-			_pdA->SetLines( linesA );
-			linesA->Delete();  //do not delete lines ??
-			_lineAActor						=	vtkActor::New();
-			_lineAMapper					=	vtkPolyDataMapper::New();
-
-			_lineAMapper->SetInput(_pdA);
-			_lineAMapper->ImmediateModeRenderingOn();
-			_lineAActor->SetMapper(_lineAMapper);
-	//		_lineAActor->GetProperty()->BackfaceCullingOn();
-			_lineAActor->GetProperty()->SetDiffuseColor(1,0,0);
-			_lineAActor->GetProperty()->SetLineWidth(2);
-			_imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineAActor );
-		}
+	if(_lineAActor==NULL){
+		_lineAActor = vtkActor::New();
+		_lineAActor->GetProperty()->SetDiffuseColor(1,0,0);
+		_lineAActor->GetProperty()->SetLineWidth(2);
+		
+		_ptsA = vtkPoints::New();
+		_ptsA->SetNumberOfPoints(2);
+		_ptsA->SetPoint(0, -1000	, -1000	, -1000 );
+		_ptsA->SetPoint(1,  1000	,  1000	,  1000	);
+		
+		_pdA = vtkPolyData::New();
+		
+		_lineAMapper = vtkPolyDataMapper::New();
+		
+		_lineAMapper->SetInput(_pdA);
+		_lineAMapper->ImmediateModeRenderingOn();
+		_lineAActor->SetMapper(_lineAMapper);
+		
+		_imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineAActor );
+	}	
+	
+	vtkCellArray *linesA = vtkCellArray::New();
+	linesA->InsertNextCell(2);
+	linesA->InsertCellPoint(0);
+	linesA->InsertCellPoint(1);
+	_pdA->SetPoints( _ptsA );
+	_pdA->SetLines( linesA );
+	linesA->Delete();  //do not delete lines ??
+//		_lineAActor->GetProperty()->BackfaceCullingOn();
+	
+	
+
 
+	
 
+// Axe B
+	if(_lineBActor==NULL){
+		_lineBActor						=	vtkActor::New();
+		_lineBActor->GetProperty()->SetDiffuseColor(1,0,0);
+		_lineBActor->GetProperty()->SetLineWidth(2);
+		_lineBMapper					=	vtkPolyDataMapper::New();		
+		_lineBActor->SetMapper(_lineBMapper);
+		
+		_ptsB = vtkPoints::New();
+		_ptsB->SetNumberOfPoints(2);
+		_ptsB->SetPoint(0, -1000	, -1000	, -1000 );
+		_ptsB->SetPoint(1,  1000	,  1000	,  1000	);
 		
+//		_lineBActor->GetProperty()->BackfaceCullingOn();
+		
+		_imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineBActor );
+	}
+	
+	vtkCellArray *linesB;
+	linesB = vtkCellArray::New();
+	linesB->InsertNextCell(2);
+	linesB->InsertCellPoint(0);
+	linesB->InsertCellPoint(1);
+	_pdB = vtkPolyData::New();
+	_pdB->SetPoints( _ptsB );
+	_pdB->SetLines( linesB );
+	linesB->Delete();  //do not delete lines ??
+	
+	
+	_lineBMapper->SetInput(_pdB);
+	_lineBMapper->ImmediateModeRenderingOn();
 
-	// Axe B
-		if(_lineBActor==NULL){
-			_ptsB = vtkPoints::New();
-			_ptsB->SetNumberOfPoints(2);
-			_ptsB->SetPoint(0, -1000	, -1000	, -1000 );
-			_ptsB->SetPoint(1,  1000	,  1000	,  1000	);
-			vtkCellArray *linesB;
-			linesB = vtkCellArray::New();
-			linesB->InsertNextCell(2);
-			linesB->InsertCellPoint(0);
-			linesB->InsertCellPoint(1);
-			_pdB = vtkPolyData::New();
-			_pdB->SetPoints( _ptsB );
-			_pdB->SetLines( linesB );
-			linesB->Delete();  //do not delete lines ??
-			_lineBActor						=	vtkActor::New();
-			_lineBMapper					=	vtkPolyDataMapper::New();
-			_lineBMapper->SetInput(_pdB);
-			_lineBMapper->ImmediateModeRenderingOn();
-			_lineBActor->SetMapper(_lineBMapper);
-	//		_lineBActor->GetProperty()->BackfaceCullingOn();
-			_lineBActor->GetProperty()->SetDiffuseColor(1,0,0);
-			_lineBActor->GetProperty()->SetLineWidth(2);
-			_imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineBActor );
-		}
 
+	vtkCamera *camera =_imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->GetActiveCamera();
 	
-		vtkCamera *camera =_imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->GetActiveCamera();
-		
 //EED 17Avril2009
 /*		
-		if (_direction==0) {
-			camera->SetViewUp		(   0	,    -1		,     0		);
-			camera->SetPosition		( -10000,(y1+y2)/2	, (z1+z2)/2	); 
-			camera->SetFocalPoint	(   0	, (y1+y2)/2	, (z1+z2)/2	);
-			camera->SetParallelScale( (z2-z1)/3.0 );
-		}
+	if (_direction==0) {
+		camera->SetViewUp		(   0	,    -1		,     0		);
+		camera->SetPosition		( -10000,(y1+y2)/2	, (z1+z2)/2	); 
+		camera->SetFocalPoint	(   0	, (y1+y2)/2	, (z1+z2)/2	);
+		camera->SetParallelScale( (z2-z1)/3.0 );
+	}
 
-		if (_direction==1) { 
-			camera->SetViewUp		(	0		,	0	,	-1		);
-			camera->SetPosition		((x1+x2)/2	, 10000	, (z1+z2)/2	); 
-			camera->SetFocalPoint	((x1+x2)/2	,   0	, (z1+z2)/2	);
-			camera->SetParallelScale( (x2-x1)/3.0 );
-		}
+	if (_direction==1) { 
+		camera->SetViewUp		(	0		,	0	,	-1		);
+		camera->SetPosition		((x1+x2)/2	, 10000	, (z1+z2)/2	); 
+		camera->SetFocalPoint	((x1+x2)/2	,   0	, (z1+z2)/2	);
+		camera->SetParallelScale( (x2-x1)/3.0 );
+	}
 
-		if (_direction==2) { 
-			camera->SetViewUp		(	0		,	-1		,	0	);
-			camera->SetPosition		((x1+x2)/2	, (y1+y2)/2	, -10000); 
-			camera->SetFocalPoint	((x1+x2)/2	, (y1+y2)/2	,	0	); 
-			camera->SetParallelScale( (x2-x1)/3.0 );
-		}
- */
+	if (_direction==2) { 
+		camera->SetViewUp		(	0		,	-1		,	0	);
+		camera->SetPosition		((x1+x2)/2	, (y1+y2)/2	, -10000); 
+		camera->SetFocalPoint	((x1+x2)/2	, (y1+y2)/2	,	0	); 
+		camera->SetParallelScale( (x2-x1)/3.0 );
+	}
+*/
 
-		if (_direction==0) {	// YZ
-			camera->SetViewUp		(   0	,     1		,     0		);
-			camera->SetPosition		(  10000,(y1+y2)/2	, (z1+z2)/2	); 
-			camera->SetFocalPoint	(   0	, (y1+y2)/2	, (z1+z2)/2	);
-			camera->SetParallelScale( (z2-z1)/3.0 );
-		}
-		
-		if (_direction==1) {	// XZ
-			camera->SetViewUp		(	0		,	0	,	-1		);
-			camera->SetPosition		((x1+x2)/2	, 10000	, (z1+z2)/2	); 
-			camera->SetFocalPoint	((x1+x2)/2	,   0	, (z1+z2)/2	);
-			camera->SetParallelScale( (x2-x1)/3.0 );
-		}
-		
-		if (_direction==2) {	// XY
-			camera->SetViewUp		(	0		,	1		,	0	);
-			camera->SetPosition		((x1+x2)/2	, (y1+y2)/2	,  10000); 
-			camera->SetFocalPoint	((x1+x2)/2	, (y1+y2)/2	,	0	); 
-			camera->SetParallelScale( (x2-x1)/3.0 );
-		}
-		
-		
-		
+	if (_direction==0) {	// YZ
+		camera->SetViewUp		(   0	,     1		,     0		);
+		camera->SetPosition		(  10000,(y1+y2)/2	, (z1+z2)/2	); 
+		camera->SetFocalPoint	(   0	, (y1+y2)/2	, (z1+z2)/2	);
+		camera->SetParallelScale( (z2-z1)/3.0 );
+	}
+	
+	if (_direction==1) {	// XZ
+		camera->SetViewUp		(	0		,	0	,	-1		);
+		camera->SetPosition		((x1+x2)/2	, 10000	, (z1+z2)/2	); 
+		camera->SetFocalPoint	((x1+x2)/2	,   0	, (z1+z2)/2	);
+		camera->SetParallelScale( (x2-x1)/3.0 );
+	}
+	
+	if (_direction==2) {	// XY
+		camera->SetViewUp		(	0		,	1		,	0	);
+		camera->SetPosition		((x1+x2)/2	, (y1+y2)/2	,  10000); 
+		camera->SetFocalPoint	((x1+x2)/2	, (y1+y2)/2	,	0	); 
+		camera->SetParallelScale( (x2-x1)/3.0 );
 	}
+	
 
 //	_imageViewer2XYZ->GetVtkImageViewer2()->SetColorWindow (160);
 //	_imageViewer2XYZ->GetVtkImageViewer2()->SetColorLevel (800);
@@ -211,24 +229,36 @@ void wxVtkMPR2DView::Refresh()
 
 
 
-	int x1,x2,y1,y2,z1,z2;
-	GetVtkmprbasedata()->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
-	double spc[3];
+	int x1 = 0,x2 = 0,y1 = 0,y2 = 0,z1 = 0,z2 = 0, x = 0, y = 0, z = 0;
+	double *spc = 0;
+	double *origin = 0;
+	
+	
+	//GetVtkmprbasedata()->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
+	
 	
 	vtkImageData* img = GetVtkmprbasedata()->GetImageData();
 	if(img!=NULL){
-		img->GetSpacing(spc);
-		x1 =  (int)(x1*spc[0]);
-		y1 =  (int)(y1*spc[1]);
-		z1 =  (int)(z1*spc[2]);
+		origin = img->GetOrigin();
+		img->GetExtent(x1,x2,y1,y2,z1,z2);
+		spc = img->GetSpacing();
+		x1 += origin[0];
+		x2 += origin[0];
+		y1 += origin[1];
+		y2 += origin[1];
+		z1 += origin[2];
+		z2 += origin[2];
+		x1 = (int)(x1*spc[0]);
+		y1 = (int)(y1*spc[1]);
+		z1 = (int)(z1*spc[2]);
 
-		x2 =  (int)(x2*spc[0]);
-		y2 =  (int)(y2*spc[1]);
-		z2 =  (int)(z2*spc[2]);
+		x2 = (int)(x2*spc[0]);
+		y2 = (int)(y2*spc[1]);
+		z2 = (int)(z2*spc[2]);
 
-		int x = (int)(GetVtkmprbasedata()->GetX());
-		int y = (int)(GetVtkmprbasedata()->GetY());
-		int z = (int)(GetVtkmprbasedata()->GetZ());
+		x = (int)(GetVtkmprbasedata()->GetX());
+		y = (int)(GetVtkmprbasedata()->GetY());
+		z = (int)(GetVtkmprbasedata()->GetZ());
 
 		x =  (int)(x*spc[0]);
 		y =  (int)(y*spc[1]);
diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtkMPR3DView.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtkMPR3DView.cxx
index e740c60..e406380 100644
--- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtkMPR3DView.cxx
+++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtkMPR3DView.cxx
@@ -93,6 +93,9 @@ void wxVtkMPR3DView::ResetCamera(int* ext, double* origin,double* spc)
 
 //-------------------------------------------------------------------
 void wxVtkMPR3DView::Configure(){
+	
+	
+	vtkImageData *imageData = GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
 
 	_wxvtk3Dbaseview->Configure();
 	_wxvtkmpr3DviewCntrlPanel->UpdateControlPanel();
@@ -142,7 +145,10 @@ void wxVtkMPR3DView::Configure(){
 	_pointWidget = vtkPointWidget::New();
 	_myCallback->SetVtkPointWidget(_pointWidget);
 	_pointWidget->SetInteractor( GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor() ); 
-	_pointWidget->SetInput( GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData() );
+	
+	if(imageData){
+		_pointWidget->SetInput( imageData );
+	}
 	
 	_pointWidget->AllOff();
 	
@@ -163,12 +169,20 @@ void wxVtkMPR3DView::Configure(){
 	}
 	_planeWidget = vtkPlaneWidget::New();
 	_myCallback->SetVtkPlaneWidget(_planeWidget);
-	_planeWidget->SetInput( GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData() );
+	if(imageData){
+		_planeWidget->SetInput( imageData );
+	}
 	_planeWidget->NormalToXAxisOn();
 	_planeWidget->SetResolution(50);
 	_planeWidget->SetRepresentationToOutline();
 	int dim[3];
-	GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData()->GetDimensions(dim);
+	if(imageData){
+		imageData->GetDimensions(dim);
+	}else{
+		dim[0] = 0;
+		dim[1] = 0;
+		dim[2] = 0;
+	}
 	int px=(dim[0]/2);
 	int py=(dim[1]/2);
 	int pz=(dim[2]/2);
@@ -197,13 +211,13 @@ void wxVtkMPR3DView::Configure(){
 		_planeWidget->Off();
 		_wxvtk3Dbaseview->GetRenderer()->AddActor( _contourPlaneActor );	
 
-	}else{
-		
 	}
+
 	_planeWidget->GetPolyData(_vtkplane);
-	vtkImageData *imageData = GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();	
-	_probe->SetSource( imageData );
-	_contourMapper->SetScalarRange( imageData->GetScalarRange() );
+	if(imageData){
+		_probe->SetSource( imageData );
+		_contourMapper->SetScalarRange( imageData->GetScalarRange() );
+	}
 	
 	ConfigureFreePlanes();
 }
@@ -238,13 +252,18 @@ vtkImagePlaneWidget* wxVtkMPR3DView::GetPlaneWidget(unsigned char activationkey,
 	planeWidget->EnabledOff();
 	planeWidget->SetInteractor( GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor() );
 	vtkImageData *image = GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
-	planeWidget->SetInput( image );
+	int xMin = 0, xMax = 0, yMin = 0, yMax = 0, zMin = 0, zMax = 0;
+	double xSpacing = 0, ySpacing = 0, zSpacing = 0;
+	if(image){
+		planeWidget->SetInput( image );
+		image->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax);	
+		image->GetSpacing(xSpacing, ySpacing, zSpacing);
+	}
 
 	
-	int xMin, xMax, yMin, yMax, zMin, zMax;
-	image->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax);	
-	double xSpacing, ySpacing, zSpacing;
-	image->GetSpacing(xSpacing, ySpacing, zSpacing);	
+	
+	
+		
 	
 	if (activationkey=='x')
 	{
@@ -321,7 +340,16 @@ void wxVtkMPR3DView::Refresh()   // virtual
 void wxVtkMPR3DView::RefreshView()   // virtual
 {
 	double spc[3];
-	this->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData()->GetSpacing(spc);
+	vtkImageData *image = GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
+	
+	if(image){
+		image->GetSpacing(spc);
+	}else{
+		spc[0] = 0;
+		spc[1] = 0;
+		spc[2] = 0;
+	}
+	//this->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData()->GetSpacing(spc);
 
 	//double nx=1,ny=0,nz=0; // JPRx
 	Refresh();
-- 
2.49.0