1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
26 #include "wxVtkMPR3DView.h"
28 #include "vtkDataSetMapper.h"
29 #include "vtkPlaneSource.h"
30 #include "vtkProbeFilter.h"
31 #include "vtkStructuredPoints.h"
32 #include "vtkMetaImageWriter.h"
33 #include "vtkImageChangeInformation.h"
34 #include "vtkPointData.h"
35 #include "vtkWindowLevelLookupTable.h"
37 #include "vtkCutter.h"
38 #include "vtkTransform.h"
39 #include "vtkmyPWCallback_3DPointWidget.h"
40 #include "vtkProperty.h"
41 #include "vtkCellPicker.h"
42 #include "vtkInteractorStyleBaseView.h"
43 #include <vtkImageReslice.h>
47 //----------------------------------------------------------------------------
48 //----------------------------------------------------------------------------
49 //----------------------------------------------------------------------------
50 class vtkWindowLevelImagePlaneWidgetCallback : public vtkCommand
53 static vtkWindowLevelImagePlaneWidgetCallback *New()
55 return new vtkWindowLevelImagePlaneWidgetCallback;
58 void Execute( vtkObject *caller, unsigned long ev, void *callData )
60 bool needRefresh=false;
62 vtkImagePlaneWidget* ipw =dynamic_cast< vtkImagePlaneWidget* >( caller );
63 if ( ev == vtkCommand::WindowLevelEvent)
66 ipw->GetWindowLevel(info);
67 _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetColorWindow(info[0]);
68 _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetColorLevel(info[1]);
72 if ( ev == vtkCommand::InteractionEvent)
75 if (ipw->GetCursorDataStatus())
78 ipw->GetCursorData(xyzv);
79 _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetX(xyzv[0]);
80 _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetY(xyzv[1]);
81 _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetZ(xyzv[2]);
85 vtkImageData *image = _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
89 image->GetSpacing(spc);
93 slicePosition = ipw->GetSlicePosition();
94 ipw->GetNormal(normal);
97 if ((normal[0]==1)&&(normal[1]==0)&&(normal[2]==0))
99 _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetX( slicePosition/spc[0] );
102 if ((normal[0]==0)&&(normal[1]==1)&&(normal[2]==0))
104 _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetY( slicePosition/spc[1] );
107 if ((normal[0]==0)&&(normal[1]==0)&&(normal[2]==1))
109 _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetZ( slicePosition/spc[2] );
111 }// ipw->GetCursorDataStatus
116 vtkInteractorStyleBaseView *isbv = (vtkInteractorStyleBaseView*)_wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetInteractorStyleBaseView();
117 isbv->SetParent_refresh_waiting();
118 isbv->EvaluateToRefresh();
123 vtkWindowLevelImagePlaneWidgetCallback(){}
124 wxVtkMPR3DView *_wxvtkmpr3Dview;
129 //-------------------------------------------------------------------
130 //-------------------------------------------------------------------
131 //-------------------------------------------------------------------
135 wxVtkMPR3DView::wxVtkMPR3DView( wxVtk3DBaseView *wxvtk3Dbaseview )
137 _wxvtk3Dbaseview = wxvtk3Dbaseview;
138 _vtkmpr3Ddataviewer = NULL;
139 _wxvtkmpr3DviewCntrlPanel = NULL;
140 //_myCallback = NULL;
145 _contourMapper = NULL;
147 _planeWidgetX = NULL;
148 _planeWidgetY = NULL;
149 _planeWidgetZ = NULL;
155 //-------------------------------------------------------------------
156 wxVtkMPR3DView::~wxVtkMPR3DView()
158 VisiblePointWidget( false );
159 VisiblePlaneWidget( false );
161 if(_pointWidget!=NULL){
162 _pointWidget->Delete();
164 if(_planeWidget!=NULL){
165 _planeWidget->Delete();
171 _contourMapper->Delete();
172 _contourPlaneActor->Delete();
177 //-------------------------------------------------------------------
178 void wxVtkMPR3DView::RemoveActor(vtkActor* actor)
180 _wxvtk3Dbaseview->GetRenderer()->RemoveActor(actor);
183 //-------------------------------------------------------------------
184 void wxVtkMPR3DView::ResetCamera(int* ext, double* origin,double* spc)
189 //EED 21 mars 2012 FLIP probleme ..PLOP..
190 //EED 13 may 2013 FLIP probleme ..PLOP..
191 _wxvtk3Dbaseview->GetCamera()->Roll(180);
192 _wxvtk3Dbaseview->GetCamera()->Yaw(180+30);
193 _wxvtk3Dbaseview->GetCamera()->Pitch(-22);
195 _wxvtk3Dbaseview->GetRenderer()->ResetCamera ();
196 _wxvtk3Dbaseview->GetCamera()->Dolly(2.0);
200 /*double x = (spc[0])*(origin[0]+(((double)ext[1]-(double)ext[0])/2.0));
201 double y = (spc[1])*(origin[1]+(double)ext[3]);
202 double z = (spc[2])*(origin[2]+(((double)ext[5]-(double)ext[4])/2.0));*/
203 /*double x0=(spc[0])*((double)ext[0]+origin[0]);
204 double x1=(spc[0])*((double)ext[1]+origin[0]);
205 double y0=(spc[1])*((double)ext[2]+origin[1]);
206 double y1=(spc[1])*((double)ext[3]+origin[1]);
207 double z0=(spc[2])*((double)ext[4]+origin[2]);
208 double z1=(spc[2])*((double)ext[5]+origin[2]);*/
210 double x0=(spc[0])*((double)ext[0]);
211 double x1=(spc[0])*((double)ext[1]);
212 double y0=(spc[1])*((double)ext[2]);
213 double y1=(spc[1])*((double)ext[3]);
214 double z0=(spc[2])*((double)ext[4]);
215 double z1=(spc[2])*((double)ext[5]);
217 _wxvtk3Dbaseview->GetRenderer()->ResetCamera(x0,x1,y0,y1,z0,z1);
218 //_wxvtk3Dbaseview->GetCamera()->SetPosition(x,y,z);
219 _wxvtk3Dbaseview->GetCamera()->Dolly(1.5);
223 //-------------------------------------------------------------------
224 void wxVtkMPR3DView::Configure()
226 vtkImageData *imageData = GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
228 _wxvtk3Dbaseview->Configure();
229 _wxvtkmpr3DviewCntrlPanel->UpdateControlPanel();
232 // _wxvtk3Dbaseview->GetRenderer()->Clear();
234 // Actors are added to the renderer.
235 vtkActor* _outlineActor = _vtkmpr3Ddataviewer->GetOutlineActor();
236 _wxvtk3Dbaseview->GetRenderer()->AddActor( _outlineActor );
237 // _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkmpr3Ddataviewer->GetImageActor(0) ); // _saggital
238 // _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkmpr3Ddataviewer->GetImageActor(1) ); // _axial
239 // _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkmpr3Ddataviewer->GetImageActor(2) ); // _coronal
244 //if(_myCallback!=NULL){
245 //_myCallback->Delete();
248 vtkmyPWCallback_3DPointWidget *_myCallback = vtkmyPWCallback_3DPointWidget::New();
249 _myCallback->SetWxVtkMPR3DView(this);
253 if(_pointWidget==NULL){
254 _pointWidget = vtkPointWidget::New();
256 _pointWidget->SetInput( imageData );
257 _myCallback->SetVtkPointWidget(_pointWidget);
258 _pointWidget->SetInteractor( GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor() );
259 _pointWidget->AllOff();
260 _pointWidget->PlaceWidget();
262 _pointWidget->AddObserver(vtkCommand::InteractionEvent,_myCallback);
264 if(_planeWidget==NULL)
266 _planeWidget = vtkPlaneWidget::New();
268 _planeWidget->SetInput( imageData );
270 _myCallback->SetVtkPlaneWidget(_planeWidget);
272 _planeWidget->NormalToXAxisOn();
273 _planeWidget->SetResolution(50);
274 _planeWidget->SetRepresentationToOutline();
278 imageData->GetDimensions(dim);
283 _planeWidget->PlaceWidget( px-dd , px+dd , py-dd , py+dd , pz-dd , pz+dd );
286 _vtkplane = vtkPolyData::New();
288 _probe = vtkProbeFilter::New();
289 _probe->SetInput(_vtkplane);
291 _contourMapper = vtkPolyDataMapper::New();
293 _contourMapper->SetInput( _probe->GetPolyDataOutput() );
295 _contourPlaneActor = vtkActor::New();
296 _contourPlaneActor->SetMapper(_contourMapper);
298 _contourPlaneActor->VisibilityOff();
300 _planeWidget->SetInteractor( GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor() );
301 _planeWidget->AddObserver(vtkCommand::InteractionEvent,_myCallback);
304 _wxvtk3Dbaseview->GetRenderer()->AddActor( _contourPlaneActor );
308 _planeWidget->GetPolyData(_vtkplane);
309 _probe->SetSource( imageData );
310 _contourMapper->SetScalarRange( imageData->GetScalarRange() );
312 ConfigureFreePlanes();
315 // _pointWidget->SetPosition( x,y,z );
318 // MACOS probleme vtk-window out of wx-window
319 // _pointWidget->On();
324 // An initial camera view is created. The Dolly() method moves
325 // the camera towards the FocalPoint, thereby enlarging the image.
326 _wxvtk3Dbaseview->GetRenderer()->SetActiveCamera(_wxvtk3Dbaseview->GetCamera());
328 // Note that when camera movement occurs (as it does in the Dolly()
329 // method), the clipping planes often need adjusting. Clipping planes
330 // consist of two planes: near and far along the view direction. The
331 // near plane clips out objects in front of the plane; the far plane
332 // clips out objects behind the plane. This way only what is drawn
333 // between the planes is actually rendered.
334 _wxvtk3Dbaseview->GetRenderer()->ResetCameraClippingRange();
339 // Set a background color for the renderer and set the size of the
340 // render window (expressed in pixels).
341 _wxvtk3Dbaseview->GetRenderer()->SetBackground( 0.36 , 0.36 , 0.36 );
342 //EED 23oct2010 _wxvtk3Dbaseview->GetRenWin()->SetSize(400, 400);
346 //-------------------------------------------------------------------
347 void wxVtkMPR3DView::ConfigureFreePlanes()
350 // The shared picker enables us to use 3 planes at one time
351 // and gets the picking order right
352 vtkCellPicker* picker = vtkCellPicker::New();
353 picker->SetTolerance(0.005);
355 // The 3 image plane widgets
356 _planeWidgetX = GetPlaneWidget('x', 1, 0, 0, picker);
357 _planeWidgetY = GetPlaneWidget('y', 1, 1, 0, picker);
358 _planeWidgetZ = GetPlaneWidget('z', 0, 0, 1, picker);
360 _planeWidgetY->SetLookupTable(_planeWidgetX->GetLookupTable());
361 _planeWidgetZ->SetLookupTable(_planeWidgetX->GetLookupTable());
363 picker->UnRegister(NULL);
365 // ColorWindow ColorLevel Callback
366 vtkWindowLevelImagePlaneWidgetCallback *wlipwc = vtkWindowLevelImagePlaneWidgetCallback::New();
367 wlipwc->_wxvtkmpr3Dview = this;
368 _planeWidgetX->AddObserver(vtkCommand::WindowLevelEvent, wlipwc );
369 _planeWidgetY->AddObserver(vtkCommand::WindowLevelEvent, wlipwc );
370 _planeWidgetZ->AddObserver(vtkCommand::WindowLevelEvent, wlipwc );
373 _planeWidgetX->AddObserver(vtkCommand::InteractionEvent, wlipwc );
374 _planeWidgetY->AddObserver(vtkCommand::InteractionEvent, wlipwc );
375 _planeWidgetZ->AddObserver(vtkCommand::InteractionEvent, wlipwc );
378 //-------------------------------------------------------------------
379 vtkImagePlaneWidget* wxVtkMPR3DView::GetPlaneWidget(unsigned char activationkey, double r, double g, double b, vtkCellPicker* picker)
381 vtkProperty* prop1 = 0;
382 vtkImagePlaneWidget* planeWidget = 0;
383 planeWidget = vtkImagePlaneWidget::New();
384 planeWidget->SetInteractor( GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor() );
385 planeWidget->EnabledOff();
386 vtkImageData *image = GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
387 int xMin = 0, xMax = 0, yMin = 0, yMax = 0, zMin = 0, zMax = 0;
388 double xSpacing = 0, ySpacing = 0, zSpacing = 0;
391 planeWidget->SetInput( image );
392 image->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax);
393 image->GetSpacing(xSpacing, ySpacing, zSpacing);
396 if (activationkey=='x')
398 planeWidget->SetPlaneOrientationToXAxes();
399 planeWidget->SetSlicePosition((xMax+xMin)/2.*xSpacing);
402 if (activationkey=='y')
404 planeWidget->SetPlaneOrientationToYAxes();
405 planeWidget->SetSlicePosition((yMax+yMin)/2.*ySpacing);
408 if (activationkey=='z')
410 planeWidget->SetPlaneOrientationToZAxes();
411 planeWidget->SetSlicePosition((zMax+zMin)/2.*zSpacing);
414 planeWidget->DisplayTextOn();
415 planeWidget->SetPicker(picker);
416 planeWidget->SetKeyPressActivationValue(activationkey);
417 prop1 = planeWidget->GetPlaneProperty();
418 prop1->SetColor(r, g, b);
422 //-------------------------------------------------------------------
423 void wxVtkMPR3DView::SetFreePlanesOrtho()
425 _planeWidgetX->SetPlaneOrientationToXAxes();
426 _planeWidgetY->SetPlaneOrientationToYAxes();
427 _planeWidgetZ->SetPlaneOrientationToZAxes();
428 vtkInteractorStyleBaseView *isbv = (vtkInteractorStyleBaseView*)GetWxvtk3Dbaseview()->GetInteractorStyleBaseView();
429 isbv->SetParent_refresh_waiting();
430 isbv->EvaluateToRefresh();
433 //-------------------------------------------------------------------
434 void wxVtkMPR3DView::FreePlaneVisible(int plane, bool ok)
438 if ((plane==1) && (ok==true)) _planeWidgetX->EnabledOn();
439 if ((plane==2) && (ok==true)) _planeWidgetY->EnabledOn();
440 if ((plane==3) && (ok==true)) _planeWidgetZ->EnabledOn();
441 if ((plane==1) && (ok==false)) _planeWidgetX->EnabledOff();
442 if ((plane==2) && (ok==false)) _planeWidgetY->EnabledOff();
443 if ((plane==3) && (ok==false)) _planeWidgetZ->EnabledOff();
447 //-------------------------------------------------------------------
448 void wxVtkMPR3DView::FreePlaneInteraction(bool ok)
454 _planeWidgetX->InteractionOn();
455 _planeWidgetY->InteractionOn();
456 _planeWidgetZ->InteractionOn();
458 _planeWidgetX->InteractionOff();
459 _planeWidgetY->InteractionOff();
460 _planeWidgetZ->InteractionOff();
462 } // if _planeWidgetX
467 //-------------------------------------------------------------------
468 void wxVtkMPR3DView::setColorTransferFunction(vtkColorTransferFunction* colortable)
470 GetVtkMPR3DDataViewer ()->setColorTransferFunction(colortable);
473 //-------------------------------------------------------------------
474 void wxVtkMPR3DView::Refresh() // virtual
476 _vtkmpr3Ddataviewer -> Refresh();
477 if (_wxvtkmpr3DviewCntrlPanel!=NULL)
479 _wxvtkmpr3DviewCntrlPanel->Refresh();
484 //-------------------------------------------------------------------
485 void wxVtkMPR3DView::RefreshView() // virtual
488 vtkImageData *image = GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
491 image->GetSpacing(spc);
497 //this->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData()->GetSpacing(spc);
499 //double nx=1,ny=0,nz=0; // JPRx
501 double x=GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetX();
502 double y=GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetY();
503 double z=GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetZ();
505 SetColorWindow( _vtkmpr3Ddataviewer->GetVtkMPRBaseData()->GetColorWindow() );
506 SetColorLevel( _vtkmpr3Ddataviewer->GetVtkMPRBaseData()->GetColorLevel() );
511 _planeWidgetX->GetNormal(normal);
512 if ((normal[0]==1)&&(normal[1]==0)&&(normal[2]==0))
514 _planeWidgetX->SetSlicePosition( x*spc[0] );
517 _planeWidgetY->GetNormal(normal);
518 if ((normal[0]==0)&&(normal[1]==1)&&(normal[2]==0))
520 _planeWidgetY->SetSlicePosition( y*spc[1] );
523 _planeWidgetZ->GetNormal(normal);
524 if ((normal[0]==0)&&(normal[1]==0)&&(normal[2]==1))
526 _planeWidgetZ->SetSlicePosition( z*spc[2] );
534 _pointWidget->SetPosition( x,y,z );
537 vtkTransform *transform = GetVtkMPR3DDataViewer ()->GetVtkMPRBaseData()->GetTransformOrientation();
538 in[0]=1; in[1]=0; in[2]=0;
539 transform->TransformPoint(in,normal);
540 _planeWidget->SetNormal( normal[0],normal[1],normal[2] );
541 _planeWidget->SetCenter( x,y,z );
542 _planeWidget->UpdatePlacement();
543 _planeWidget->GetPolyData(_vtkplane);
547 //-------------------------------------------------------------------
548 wxPanel* wxVtkMPR3DView::CreateControlPanel(wxWindow *parent, bool align)
550 _wxvtkmpr3DviewCntrlPanel = new wxVtkMPR3DViewCntrlPanel(parent,this, align);
551 return _wxvtkmpr3DviewCntrlPanel;
553 //-------------------------------------------------------------------
554 vtkMPR3DDataViewer* wxVtkMPR3DView::GetVtkMPR3DDataViewer()
556 return _vtkmpr3Ddataviewer;
558 //-------------------------------------------------------------------
559 wxVtk3DBaseView* wxVtkMPR3DView::GetWxvtk3Dbaseview() throw (char*)
561 if(_wxvtk3Dbaseview==NULL){
562 throw "wxVtk3DBaseView* wxVtkMPR3DView::GetWxvtk3Dbaseview() _wxvtk3Dbaseview=NULL";
564 return _wxvtk3Dbaseview;
566 //-------------------------------------------------------------------
568 //-------------------------------------------------------------------
569 void wxVtkMPR3DView::VisibleImageActor(int idPosition, bool visible){
570 /*if(visible == false)
571 printf("CPR: wxVtkMPR3DView::VisibleImageActor-> visibleActor == false \n");
574 printf("CPR: wxVtkMPR3DView::VisibleImageActor-> visibleActor == true\n");
575 printf("CPR: wxVtkMPR3DView::VisibleImageActor-> idPosition == %d\n", idPosition);
578 if (visible!=_vtkmpr3Ddataviewer->GetVisiblePosition(idPosition)){
580 _wxvtk3Dbaseview->GetRenderer()->RemoveActor( _vtkmpr3Ddataviewer->GetImageActor(idPosition) );
582 _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkmpr3Ddataviewer->GetImageActor(idPosition) );
584 _vtkmpr3Ddataviewer->SetVisiblePosition(idPosition,visible);
589 //-------------------------------------------------------------------
590 void wxVtkMPR3DView::VisiblePointWidget( bool visible )
602 //-------------------------------------------------------------------
603 void wxVtkMPR3DView::VisiblePlaneWidget( bool visible )
609 _contourPlaneActor->VisibilityOn();
613 _contourPlaneActor->VisibilityOff();
618 //CPR: Method added 30 Nov 2009
619 void wxVtkMPR3DView::showOutlineActor(bool value)
621 vtkActor* _outlineActor = _vtkmpr3Ddataviewer->GetOutlineActor();
624 _wxvtk3Dbaseview->GetRenderer()->AddActor( _outlineActor );
628 _wxvtk3Dbaseview->GetRenderer()->RemoveActor( _outlineActor );
632 //-------------------------------------------------------------------
633 void wxVtkMPR3DView::SetVtkMPR3DDataViewer(vtkMPR3DDataViewer *vtkmpr3Ddataviewer)
635 _vtkmpr3Ddataviewer = vtkmpr3Ddataviewer;
638 //-------------------------------------------------------------------
639 void wxVtkMPR3DView::InitOrientationPointWidget()
641 this->_planeWidget->SetNormal(1,0,0);
644 //-------------------------------------------------------------------
645 void wxVtkMPR3DView::SetColorWindow(double colorWindow)
647 double colorLevel = _planeWidgetX->GetLevel();
648 _planeWidgetX->SetWindowLevel(colorWindow,colorLevel);
651 //-------------------------------------------------------------------
652 void wxVtkMPR3DView::SetColorLevel(double colorLevel)
654 double colorWindow = _planeWidgetX->GetWindow();
655 _planeWidgetX->SetWindowLevel(colorWindow,colorLevel);
658 //-------------------------------------------------------------------
659 // EED 25 Janvier 2007 testLoic
660 void wxVtkMPR3DView::TestLoic1()
664 double dimIma = sizeIma*2;
666 vtkImageData *vtkimagedata = this->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
669 vtkimagedata->GetSpacing(spc);
671 vtkimagedata->Update();
675 this->_planeWidget->GetOrigin(p);
676 this->_planeWidget->GetNormal(n);
680 vtkPlaneSource* pSource = vtkPlaneSource::New( );
681 pSource->SetResolution( sizeIma - 1, sizeIma - 1 );
682 pSource->SetOrigin( p[ 0 ], p[ 1 ], p[ 2 ] );
683 pSource->SetPoint1( p[ 0 ] + dimIma - 1.0, p[ 1 ], p[ 2 ] );
684 pSource->SetPoint2( p[ 0 ], p[ 1 ]+ dimIma - 1.0 , p[ 2 ] );
686 pSource->SetCenter( p[ 0 ], p[ 1 ], p[ 2 ] );
687 pSource->SetNormal( n[ 0 ], n[ 1 ], n[ 2 ] );
690 vtkProbeFilter* slices = vtkProbeFilter::New();
691 slices->SetInput( ( vtkDataSet* )pSource->GetOutput( ) );
692 slices->SetSource( vtkimagedata );
696 vtkStructuredPoints *stPoints = vtkStructuredPoints::New();
697 stPoints -> GetPointData( )->SetScalars( slices->GetOutput()->GetPointData()->GetScalars() );
698 stPoints -> SetDimensions( sizeIma, sizeIma, 1 );
699 stPoints -> SetScalarType( vtkimagedata->GetScalarType() );
700 stPoints -> SetScalarTypeToShort();
701 stPoints -> Update();
703 vtkImageChangeInformation *change = vtkImageChangeInformation ::New();
704 change -> SetInput( stPoints );
705 change -> Update(); //important
708 vtkimagedata->GetScalarRange(_range);
709 vtkWindowLevelLookupTable *_bwlookup = vtkWindowLevelLookupTable::New( );
710 _bwlookup->SetHueRange( 0 , 1 );
711 _bwlookup->SetNumberOfColors( (int)(_range[1] - _range[0] + 1) );
712 _bwlookup->SetTableRange( _range[0] , _range[1] );
713 _bwlookup->SetSaturationRange( 0 , 0 );
714 _bwlookup->SetValueRange( 0 , 1 );
715 _bwlookup->SetAlphaRange( 1 , 1 );
718 vtkLookupTable * _collookup = vtkLookupTable::New( );
719 _collookup->SetNumberOfColors( 256 );
720 _collookup->SetTableRange( 0 , 255 );
721 _collookup->Build( );
722 _collookup->SetTableValue( 0 , 1 , 0 , 0 , 1 );
723 _collookup->SetTableValue(128 , 0 , 0 , 1 , 1 );
724 _collookup->SetTableValue(255 , 0 , 1 , 0 , 1 );
727 vtkMetaImageWriter *writer = vtkMetaImageWriter::New( );
728 writer->SetInput( stPoints );
729 writer->SetFileName( "C:/Users/Images/temp_EED/image.mhd" );
730 writer->SetFileDimensionality( 2 );
735 vtkDataSetMapper *_3DSliceMapper = vtkDataSetMapper::New( );
736 _3DSliceMapper->SetInput(change->GetOutput( ) );
737 _3DSliceMapper->SetLookupTable( _bwlookup );
738 _3DSliceMapper->SetScalarRange( _range );
739 _3DSliceMapper->ImmediateModeRenderingOn( );
741 vtkActor *_3DSliceActor = vtkActor::New( );
742 _3DSliceActor->SetMapper( _3DSliceMapper );
744 // The usual rendering stuff.
745 vtkCamera *camera = vtkCamera::New();
746 camera->SetPosition(1,1,1);
747 camera->SetFocalPoint(0,0,0);
749 vtkRenderer *renderer = vtkRenderer::New();
750 vtkRenderWindow *renWin = vtkRenderWindow::New();
751 renWin->AddRenderer(renderer);
753 vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
754 iren->SetRenderWindow(renWin);
756 renderer->AddActor( _3DSliceActor );
757 renderer->SetActiveCamera(camera);
758 renderer->ResetCamera();
759 renderer->SetBackground(1,1,1);
761 renWin->SetSize(300,300);
763 // interact with data
773 //-------------------------------------------------------------------
774 // EED 25 Janvier 2007 testLoic
775 void wxVtkMPR3DView::TestLoic2()
778 vtkVectorNorm *vecMagnitude = vtkVectorNorm::New();
779 vecMagnitude->SetInput(VtkMainGrid);
780 vecMagnitude->NormalizeOff();
781 vecMagnitude->Update();
784 vtkPlane *slicePlane = vtkPlane::New();
785 this->_planeWidget->GetPlane( slicePlane );
788 vtkCutter* sliceCutter = vtkCutter::New();
789 vtkImageData *vtkimagedata = this->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
790 sliceCutter->SetInput( vtkimagedata );
791 sliceCutter->SetCutFunction( slicePlane );
794 // vtkLookupTable *lut = BuildHueWeightBaseMap();
797 vtkPolyDataMapper *slice = vtkPolyDataMapper::New();
798 slice->SetInput( sliceCutter->GetOutput() );
802 vtkimagedata->GetScalarRange(range);
803 // vecMagnitude->GetOutput()->GetScalarRange( range );
804 // range[1] *= 0.7; // reduce the upper range by 30%
805 // slice->SetScalarRange( range );
806 // slice->SetLookupTable( lut );
808 // vtkActor *sliceActor = vtkActor::New();
809 // sliceActor->SetMapper( slice );
811 vtkPolyDataMapper *contourMapper = vtkPolyDataMapper::New();
812 contourMapper->SetInput( sliceCutter->GetOutput() );
813 contourMapper->SetScalarRange( range );
814 // contourMapper->SetLookupTable( lut );
817 vtkActor *contourActor = vtkActor::New();
818 contourActor->SetMapper( contourMapper );
822 // The usual rendering stuff.
823 vtkCamera *camera = vtkCamera::New();
824 camera->SetPosition(1,1,1);
825 camera->SetFocalPoint(0,0,0);
827 vtkRenderer *renderer = vtkRenderer::New();
828 vtkRenderWindow *renWin = vtkRenderWindow::New();
829 renWin->AddRenderer(renderer);
831 vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
832 iren->SetRenderWindow(renWin);
834 renderer->AddActor( contourActor );
835 // renderer->AddActor(cubeActor);
836 renderer->SetActiveCamera(camera);
837 renderer->ResetCamera();
838 renderer->SetBackground(1,1,1);
840 renWin->SetSize(300,300);
842 // interact with data