+/*# ---------------------------------------------------------------------
+#
+# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
+# pour la Sant�)
+# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
+# Previous Authors : Laurent Guigues, Jean-Pierre Roux
+# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
+#
+# This software is governed by the CeCILL-B license under French law and
+# abiding by the rules of distribution of free software. You can use,
+# modify and/ or redistribute the software under the terms of the CeCILL-B
+# license as circulated by CEA, CNRS and INRIA at the following URL
+# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+# or in the file LICENSE.txt.
+#
+# As a counterpart to the access to the source code and rights to copy,
+# modify and redistribute granted by the license, users are provided only
+# with a limited warranty and the software's author, the holder of the
+# economic rights, and the successive licensors have only limited
+# liability.
+#
+# The fact that you are presently reading this means that you have had
+# knowledge of the CeCILL-B license and that you accept its terms.
+# ------------------------------------------------------------------------ */
+
#include "wxVtkMPR3DView.h"
#include "vtkDataSetMapper.h"
#include "vtkProbeFilter.h"
#include "vtkStructuredPoints.h"
#include "vtkMetaImageWriter.h"
-#include "vtkDataSetMapper.h"
#include "vtkImageChangeInformation.h"
#include "vtkPointData.h"
#include "vtkWindowLevelLookupTable.h"
#include "vtkmyPWCallback_3DPointWidget.h"
#include "vtkProperty.h"
#include "vtkCellPicker.h"
+#include "vtkInteractorStyleBaseView.h"
+#include <vtkImageReslice.h>
+
+
+
+//----------------------------------------------------------------------------
+//----------------------------------------------------------------------------
+//----------------------------------------------------------------------------
+class vtkWindowLevelImagePlaneWidgetCallback : public vtkCommand
+{
+ public:
+ static vtkWindowLevelImagePlaneWidgetCallback *New()
+ {
+ return new vtkWindowLevelImagePlaneWidgetCallback;
+ }
+
+ void Execute( vtkObject *caller, unsigned long ev, void *callData )
+ {
+ bool needRefresh=false;
+ double slicePosition;
+ vtkImagePlaneWidget* ipw =dynamic_cast< vtkImagePlaneWidget* >( caller );
+ if ( ev == vtkCommand::WindowLevelEvent)
+ {
+ double info[2];
+ ipw->GetWindowLevel(info);
+ _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetColorWindow(info[0]);
+ _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetColorLevel(info[1]);
+ needRefresh=true;
+ } // if ev
+
+ if ( ev == vtkCommand::InteractionEvent)
+ {
+ needRefresh=true;
+ if (ipw->GetCursorDataStatus())
+ {
+ double xyzv[4];
+ ipw->GetCursorData(xyzv);
+ _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetX(xyzv[0]);
+ _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetY(xyzv[1]);
+ _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetZ(xyzv[2]);
+ } else {
+
+
+ vtkImageData *image = _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
+ double spc[3];
+ if(image)
+ {
+ image->GetSpacing(spc);
+ }
+
+ double normal[3];
+ slicePosition = ipw->GetSlicePosition();
+ ipw->GetNormal(normal);
+
+ // FreePlaneX
+ if ((normal[0]==1)&&(normal[1]==0)&&(normal[2]==0))
+ {
+ _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetX( slicePosition/spc[0] );
+ }
+ // FreePlaneY
+ if ((normal[0]==0)&&(normal[1]==1)&&(normal[2]==0))
+ {
+ _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetY( slicePosition/spc[1] );
+ }
+ // FreePlaneZ
+ if ((normal[0]==0)&&(normal[1]==0)&&(normal[2]==1))
+ {
+ _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetZ( slicePosition/spc[2] );
+ }
+ }// ipw->GetCursorDataStatus
+ }// ev
+
+ if (needRefresh)
+ {
+ vtkInteractorStyleBaseView *isbv = (vtkInteractorStyleBaseView*)_wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetInteractorStyleBaseView();
+ isbv->SetParent_refresh_waiting();
+ isbv->EvaluateToRefresh();
+ }
+
+ } // Execute
+
+ vtkWindowLevelImagePlaneWidgetCallback(){}
+ wxVtkMPR3DView *_wxvtkmpr3Dview;
+};
+
+
+
+//-------------------------------------------------------------------
+//-------------------------------------------------------------------
+//-------------------------------------------------------------------
-#ifdef _DEBUG
-#define new DEBUG_NEW
-#endif
wxVtkMPR3DView::wxVtkMPR3DView( wxVtk3DBaseView *wxvtk3Dbaseview )
{
_probe = NULL;
_contourMapper = NULL;
- _planeWidgetX = 0;
- _planeWidgetY = 0;
- _planeWidgetZ = 0;
+ _planeWidgetX = NULL;
+ _planeWidgetY = NULL;
+ _planeWidgetZ = NULL;
//EED Fev 3 2010
//Free Planes
}
//-------------------------------------------------------------------
void wxVtkMPR3DView::ResetCamera(int* ext, double* origin,double* spc)
{
- if(ext == NULL){
+ if(ext == NULL)
+ {
+
+//EED 21 mars 2012 FLIP probleme ..PLOP..
+//EED 13 may 2013 FLIP probleme ..PLOP..
+ _wxvtk3Dbaseview->GetCamera()->Roll(180);
+ _wxvtk3Dbaseview->GetCamera()->Yaw(180+30);
+ _wxvtk3Dbaseview->GetCamera()->Pitch(-22);
+
_wxvtk3Dbaseview->GetRenderer()->ResetCamera ();
- _wxvtk3Dbaseview->GetCamera()->Dolly(1.5);
+ _wxvtk3Dbaseview->GetCamera()->Dolly(2.0);
+
}else{
+
/*double x = (spc[0])*(origin[0]+(((double)ext[1]-(double)ext[0])/2.0));
double y = (spc[1])*(origin[1]+(double)ext[3]);
double z = (spc[2])*(origin[2]+(((double)ext[5]-(double)ext[4])/2.0));*/
double y1=(spc[1])*((double)ext[3]+origin[1]);
double z0=(spc[2])*((double)ext[4]+origin[2]);
double z1=(spc[2])*((double)ext[5]+origin[2]);*/
+
double x0=(spc[0])*((double)ext[0]);
double x1=(spc[0])*((double)ext[1]);
double y0=(spc[1])*((double)ext[2]);
_wxvtk3Dbaseview->GetRenderer()->ResetCamera(x0,x1,y0,y1,z0,z1);
//_wxvtk3Dbaseview->GetCamera()->SetPosition(x,y,z);
- _wxvtk3Dbaseview->GetCamera()->Dolly(1.5);
- }
+ _wxvtk3Dbaseview->GetCamera()->Dolly(1.5);
+ }
}
//-------------------------------------------------------------------
// _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkmpr3Ddataviewer->GetImageActor(2) ); // _coronal
- // An initial camera view is created. The Dolly() method moves
- // the camera towards the FocalPoint, thereby enlarging the image.
- _wxvtk3Dbaseview->GetRenderer()->SetActiveCamera(_wxvtk3Dbaseview->GetCamera());
- this->ResetCamera();
-
-
- // Set a background color for the renderer and set the size of the
- // render window (expressed in pixels).
- _wxvtk3Dbaseview->GetRenderer()->SetBackground( 0.36 , 0.36 , 0.36 );
-//EED 23oct2010 _wxvtk3Dbaseview->GetRenWin()->SetSize(400, 400);
-
- // Note that when camera movement occurs (as it does in the Dolly()
- // method), the clipping planes often need adjusting. Clipping planes
- // consist of two planes: near and far along the view direction. The
- // near plane clips out objects in front of the plane; the far plane
- // clips out objects behind the plane. This way only what is drawn
- // between the planes is actually rendered.
- _wxvtk3Dbaseview->GetRenderer()->ResetCameraClippingRange();
-
-
+
// vtkPointWidget
//if(_myCallback!=NULL){
//_myCallback->Delete();
_probe->SetSource( imageData );
_contourMapper->SetScalarRange( imageData->GetScalarRange() );
-
- ConfigureFreePlanes();
+ ConfigureFreePlanes();
}
// _pointWidget->SetPosition( x,y,z );
// PlaneWidget
+
+// An initial camera view is created. The Dolly() method moves
+ // the camera towards the FocalPoint, thereby enlarging the image.
+ _wxvtk3Dbaseview->GetRenderer()->SetActiveCamera(_wxvtk3Dbaseview->GetCamera());
+
+ // Note that when camera movement occurs (as it does in the Dolly()
+ // method), the clipping planes often need adjusting. Clipping planes
+ // consist of two planes: near and far along the view direction. The
+ // near plane clips out objects in front of the plane; the far plane
+ // clips out objects behind the plane. This way only what is drawn
+ // between the planes is actually rendered.
+ _wxvtk3Dbaseview->GetRenderer()->ResetCameraClippingRange();
+
+ this->ResetCamera();
+
+
+ // Set a background color for the renderer and set the size of the
+ // render window (expressed in pixels).
+ _wxvtk3Dbaseview->GetRenderer()->SetBackground( 0.36 , 0.36 , 0.36 );
+//EED 23oct2010 _wxvtk3Dbaseview->GetRenWin()->SetSize(400, 400);
+
}
//-------------------------------------------------------------------
picker->UnRegister(NULL);
+ // ColorWindow ColorLevel Callback
+ vtkWindowLevelImagePlaneWidgetCallback *wlipwc = vtkWindowLevelImagePlaneWidgetCallback::New();
+ wlipwc->_wxvtkmpr3Dview = this;
+ _planeWidgetX->AddObserver(vtkCommand::WindowLevelEvent, wlipwc );
+ _planeWidgetY->AddObserver(vtkCommand::WindowLevelEvent, wlipwc );
+ _planeWidgetZ->AddObserver(vtkCommand::WindowLevelEvent, wlipwc );
+
+ // Cursor Callback
+ _planeWidgetX->AddObserver(vtkCommand::InteractionEvent, wlipwc );
+ _planeWidgetY->AddObserver(vtkCommand::InteractionEvent, wlipwc );
+ _planeWidgetZ->AddObserver(vtkCommand::InteractionEvent, wlipwc );
}
//-------------------------------------------------------------------
vtkImagePlaneWidget* wxVtkMPR3DView::GetPlaneWidget(unsigned char activationkey, double r, double g, double b, vtkCellPicker* picker)
{
- vtkProperty* prop1 = 0;
- vtkImagePlaneWidget* planeWidget = 0;
- planeWidget = vtkImagePlaneWidget::New();
+ vtkProperty* prop1 = 0;
+ vtkImagePlaneWidget* planeWidget = 0;
+ planeWidget = vtkImagePlaneWidget::New();
planeWidget->SetInteractor( GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor() );
planeWidget->EnabledOff();
- vtkImageData *image = GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
+ vtkImageData *image = GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
int xMin = 0, xMax = 0, yMin = 0, yMax = 0, zMin = 0, zMax = 0;
double xSpacing = 0, ySpacing = 0, zSpacing = 0;
- if(image){
+ if(image)
+ {
planeWidget->SetInput( image );
image->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax);
image->GetSpacing(xSpacing, ySpacing, zSpacing);
return planeWidget;
}
+//-------------------------------------------------------------------
+void wxVtkMPR3DView::SetFreePlanesOrtho()
+{
+ _planeWidgetX->SetPlaneOrientationToXAxes();
+ _planeWidgetY->SetPlaneOrientationToYAxes();
+ _planeWidgetZ->SetPlaneOrientationToZAxes();
+ vtkInteractorStyleBaseView *isbv = (vtkInteractorStyleBaseView*)GetWxvtk3Dbaseview()->GetInteractorStyleBaseView();
+ isbv->SetParent_refresh_waiting();
+ isbv->EvaluateToRefresh();
+}
+
//-------------------------------------------------------------------
void wxVtkMPR3DView::FreePlaneVisible(int plane, bool ok)
{
- if(_planeWidgetX){
+ if(_planeWidgetX)
+ {
if ((plane==1) && (ok==true)) _planeWidgetX->EnabledOn();
if ((plane==2) && (ok==true)) _planeWidgetY->EnabledOn();
if ((plane==3) && (ok==true)) _planeWidgetZ->EnabledOn();
//-------------------------------------------------------------------
void wxVtkMPR3DView::FreePlaneInteraction(bool ok)
{
- if(_planeWidgetX){
+ if(_planeWidgetX)
+ {
if (ok==true)
{
_planeWidgetX->InteractionOn();
_planeWidgetY->InteractionOff();
_planeWidgetZ->InteractionOff();
}
- }
+ } // if _planeWidgetX
}
+
//-------------------------------------------------------------------
void wxVtkMPR3DView::setColorTransferFunction(vtkColorTransferFunction* colortable)
{
//double nx=1,ny=0,nz=0; // JPRx
Refresh();
- double x=GetVtkMPR3DDataViewer ()->GetVtkMPRBaseData()->GetX();
- double y=GetVtkMPR3DDataViewer ()->GetVtkMPRBaseData()->GetY();
- double z=GetVtkMPR3DDataViewer ()->GetVtkMPRBaseData()->GetZ();
+ double x=GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetX();
+ double y=GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetY();
+ double z=GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetZ();
+ SetColorWindow( _vtkmpr3Ddataviewer->GetVtkMPRBaseData()->GetColorWindow() );
+ SetColorLevel( _vtkmpr3Ddataviewer->GetVtkMPRBaseData()->GetColorLevel() );
+
+
+ double normal[3];
+ // FreePlaneX
+ _planeWidgetX->GetNormal(normal);
+ if ((normal[0]==1)&&(normal[1]==0)&&(normal[2]==0))
+ {
+ _planeWidgetX->SetSlicePosition( x*spc[0] );
+ }
+ // FreePlaneY
+ _planeWidgetY->GetNormal(normal);
+ if ((normal[0]==0)&&(normal[1]==1)&&(normal[2]==0))
+ {
+ _planeWidgetY->SetSlicePosition( y*spc[1] );
+ }
+ // FreePlaneZ
+ _planeWidgetZ->GetNormal(normal);
+ if ((normal[0]==0)&&(normal[1]==0)&&(normal[2]==1))
+ {
+ _planeWidgetZ->SetSlicePosition( z*spc[2] );
+ }
+
x=x*spc[0];
y=y*spc[1];
z=z*spc[2];
if(_pointWidget){
_pointWidget->SetPosition( x,y,z );
-
-
double in[3];
double normal[3];
vtkTransform *transform = GetVtkMPR3DDataViewer ()->GetVtkMPRBaseData()->GetTransformOrientation();
in[0]=1; in[1]=0; in[2]=0;
transform->TransformPoint(in,normal);
_planeWidget->SetNormal( normal[0],normal[1],normal[2] );
-
-
_planeWidget->SetCenter( x,y,z );
_planeWidget->UpdatePlacement();
_planeWidget->GetPolyData(_vtkplane);
}
}
+
//-------------------------------------------------------------------
wxPanel* wxVtkMPR3DView::CreateControlPanel(wxWindow *parent, bool align)
{
this->_planeWidget->SetNormal(1,0,0);
}
+//-------------------------------------------------------------------
+void wxVtkMPR3DView::SetColorWindow(double colorWindow)
+{
+ double colorLevel = _planeWidgetX->GetLevel();
+ _planeWidgetX->SetWindowLevel(colorWindow,colorLevel);
+}
-
+//-------------------------------------------------------------------
+void wxVtkMPR3DView::SetColorLevel(double colorLevel)
+{
+ double colorWindow = _planeWidgetX->GetWindow();
+ _planeWidgetX->SetWindowLevel(colorWindow,colorLevel);
+}
//-------------------------------------------------------------------
// EED 25 Janvier 2007 testLoic
// interact with data
renWin->Render();
iren->Start();
+}
-}