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>
51 //----------------------------------------------------------------------------
52 //----------------------------------------------------------------------------
53 //----------------------------------------------------------------------------
54 class vtkWindowLevelImagePlaneWidgetCallback : public vtkCommand
57 static vtkWindowLevelImagePlaneWidgetCallback *New()
59 return new vtkWindowLevelImagePlaneWidgetCallback;
62 void Execute( vtkObject *caller, unsigned long ev, void *callData )
64 bool needRefresh=false;
66 vtkImagePlaneWidget* ipw =dynamic_cast< vtkImagePlaneWidget* >( caller );
67 if ( ev == vtkCommand::WindowLevelEvent)
70 ipw->GetWindowLevel(info);
71 _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetColorWindow(info[0]);
72 _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetColorLevel(info[1]);
76 if ( ev == vtkCommand::InteractionEvent)
79 if (ipw->GetCursorDataStatus())
82 ipw->GetCursorData(xyzv);
83 _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetX(xyzv[0]);
84 _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetY(xyzv[1]);
85 _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetZ(xyzv[2]);
89 vtkImageData *image = _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
93 image->GetSpacing(spc);
97 slicePosition = ipw->GetSlicePosition();
98 ipw->GetNormal(normal);
101 if ((normal[0]==1)&&(normal[1]==0)&&(normal[2]==0))
103 _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetX( slicePosition/spc[0] );
106 if ((normal[0]==0)&&(normal[1]==1)&&(normal[2]==0))
108 _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetY( slicePosition/spc[1] );
111 if ((normal[0]==0)&&(normal[1]==0)&&(normal[2]==1))
113 _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetZ( slicePosition/spc[2] );
115 }// ipw->GetCursorDataStatus
120 vtkInteractorStyleBaseView *isbv = (vtkInteractorStyleBaseView*)_wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetInteractorStyleBaseView();
121 isbv->SetParent_refresh_waiting();
122 isbv->EvaluateToRefresh();
127 vtkWindowLevelImagePlaneWidgetCallback(){}
128 wxVtkMPR3DView *_wxvtkmpr3Dview;
133 //-------------------------------------------------------------------
134 //-------------------------------------------------------------------
135 //-------------------------------------------------------------------
139 wxVtkMPR3DView::wxVtkMPR3DView( wxVtk3DBaseView *wxvtk3Dbaseview )
141 _wxvtk3Dbaseview = wxvtk3Dbaseview;
142 _vtkmpr3Ddataviewer = NULL;
143 _wxvtkmpr3DviewCntrlPanel = NULL;
144 //_myCallback = NULL;
149 _contourMapper = NULL;
151 _planeWidgetX = NULL;
152 _planeWidgetY = NULL;
153 _planeWidgetZ = NULL;
159 //-------------------------------------------------------------------
160 wxVtkMPR3DView::~wxVtkMPR3DView()
162 VisiblePointWidget( false );
163 VisiblePlaneWidget( false );
165 if(_pointWidget!=NULL){
166 _pointWidget->Delete();
168 if(_planeWidget!=NULL){
169 _planeWidget->Delete();
175 _contourMapper->Delete();
176 _contourPlaneActor->Delete();
181 //-------------------------------------------------------------------
182 void wxVtkMPR3DView::RemoveActor(vtkActor* actor)
184 _wxvtk3Dbaseview->GetRenderer()->RemoveActor(actor);
187 //-------------------------------------------------------------------
188 void wxVtkMPR3DView::ResetCamera(int* ext, double* origin,double* spc)
191 _wxvtk3Dbaseview->GetRenderer()->ResetCamera ();
192 _wxvtk3Dbaseview->GetCamera()->Dolly(2.0);
194 //EED 21 mars 2012 FLIP probleme ..PLOP..
195 _wxvtk3Dbaseview->GetCamera()->Roll(180);
196 _wxvtk3Dbaseview->GetCamera()->Yaw(180+30);
197 _wxvtk3Dbaseview->GetCamera()->Pitch(-22);
201 /*double x = (spc[0])*(origin[0]+(((double)ext[1]-(double)ext[0])/2.0));
202 double y = (spc[1])*(origin[1]+(double)ext[3]);
203 double z = (spc[2])*(origin[2]+(((double)ext[5]-(double)ext[4])/2.0));*/
204 /*double x0=(spc[0])*((double)ext[0]+origin[0]);
205 double x1=(spc[0])*((double)ext[1]+origin[0]);
206 double y0=(spc[1])*((double)ext[2]+origin[1]);
207 double y1=(spc[1])*((double)ext[3]+origin[1]);
208 double z0=(spc[2])*((double)ext[4]+origin[2]);
209 double z1=(spc[2])*((double)ext[5]+origin[2]);*/
211 double x0=(spc[0])*((double)ext[0]);
212 double x1=(spc[0])*((double)ext[1]);
213 double y0=(spc[1])*((double)ext[2]);
214 double y1=(spc[1])*((double)ext[3]);
215 double z0=(spc[2])*((double)ext[4]);
216 double z1=(spc[2])*((double)ext[5]);
218 _wxvtk3Dbaseview->GetRenderer()->ResetCamera(x0,x1,y0,y1,z0,z1);
219 //_wxvtk3Dbaseview->GetCamera()->SetPosition(x,y,z);
220 _wxvtk3Dbaseview->GetCamera()->Dolly(1.5);
226 //-------------------------------------------------------------------
227 void wxVtkMPR3DView::Configure()
229 vtkImageData *imageData = GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
231 _wxvtk3Dbaseview->Configure();
232 _wxvtkmpr3DviewCntrlPanel->UpdateControlPanel();
235 // _wxvtk3Dbaseview->GetRenderer()->Clear();
237 // Actors are added to the renderer.
238 vtkActor* _outlineActor = _vtkmpr3Ddataviewer->GetOutlineActor();
239 _wxvtk3Dbaseview->GetRenderer()->AddActor( _outlineActor );
240 // _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkmpr3Ddataviewer->GetImageActor(0) ); // _saggital
241 // _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkmpr3Ddataviewer->GetImageActor(1) ); // _axial
242 // _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkmpr3Ddataviewer->GetImageActor(2) ); // _coronal
245 // An initial camera view is created. The Dolly() method moves
246 // the camera towards the FocalPoint, thereby enlarging the image.
247 _wxvtk3Dbaseview->GetRenderer()->SetActiveCamera(_wxvtk3Dbaseview->GetCamera());
251 // Set a background color for the renderer and set the size of the
252 // render window (expressed in pixels).
253 _wxvtk3Dbaseview->GetRenderer()->SetBackground( 0.36 , 0.36 , 0.36 );
254 //EED 23oct2010 _wxvtk3Dbaseview->GetRenWin()->SetSize(400, 400);
256 // Note that when camera movement occurs (as it does in the Dolly()
257 // method), the clipping planes often need adjusting. Clipping planes
258 // consist of two planes: near and far along the view direction. The
259 // near plane clips out objects in front of the plane; the far plane
260 // clips out objects behind the plane. This way only what is drawn
261 // between the planes is actually rendered.
262 _wxvtk3Dbaseview->GetRenderer()->ResetCameraClippingRange();
266 //if(_myCallback!=NULL){
267 //_myCallback->Delete();
270 vtkmyPWCallback_3DPointWidget *_myCallback = vtkmyPWCallback_3DPointWidget::New();
271 _myCallback->SetWxVtkMPR3DView(this);
275 if(_pointWidget==NULL){
276 _pointWidget = vtkPointWidget::New();
278 _pointWidget->SetInput( imageData );
279 _myCallback->SetVtkPointWidget(_pointWidget);
280 _pointWidget->SetInteractor( GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor() );
281 _pointWidget->AllOff();
282 _pointWidget->PlaceWidget();
284 _pointWidget->AddObserver(vtkCommand::InteractionEvent,_myCallback);
286 if(_planeWidget==NULL)
288 _planeWidget = vtkPlaneWidget::New();
290 _planeWidget->SetInput( imageData );
292 _myCallback->SetVtkPlaneWidget(_planeWidget);
294 _planeWidget->NormalToXAxisOn();
295 _planeWidget->SetResolution(50);
296 _planeWidget->SetRepresentationToOutline();
300 imageData->GetDimensions(dim);
305 _planeWidget->PlaceWidget( px-dd , px+dd , py-dd , py+dd , pz-dd , pz+dd );
308 _vtkplane = vtkPolyData::New();
310 _probe = vtkProbeFilter::New();
311 _probe->SetInput(_vtkplane);
313 _contourMapper = vtkPolyDataMapper::New();
315 _contourMapper->SetInput( _probe->GetPolyDataOutput() );
317 _contourPlaneActor = vtkActor::New();
318 _contourPlaneActor->SetMapper(_contourMapper);
320 _contourPlaneActor->VisibilityOff();
322 _planeWidget->SetInteractor( GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor() );
323 _planeWidget->AddObserver(vtkCommand::InteractionEvent,_myCallback);
326 _wxvtk3Dbaseview->GetRenderer()->AddActor( _contourPlaneActor );
330 _planeWidget->GetPolyData(_vtkplane);
331 _probe->SetSource( imageData );
332 _contourMapper->SetScalarRange( imageData->GetScalarRange() );
334 ConfigureFreePlanes();
337 // _pointWidget->SetPosition( x,y,z );
340 // MACOS probleme vtk-window out of wx-window
341 // _pointWidget->On();
347 //-------------------------------------------------------------------
348 void wxVtkMPR3DView::ConfigureFreePlanes()
351 // The shared picker enables us to use 3 planes at one time
352 // and gets the picking order right
353 vtkCellPicker* picker = vtkCellPicker::New();
354 picker->SetTolerance(0.005);
356 // The 3 image plane widgets
357 _planeWidgetX = GetPlaneWidget('x', 1, 0, 0, picker);
358 _planeWidgetY = GetPlaneWidget('y', 1, 1, 0, picker);
359 _planeWidgetZ = GetPlaneWidget('z', 0, 0, 1, picker);
361 _planeWidgetY->SetLookupTable(_planeWidgetX->GetLookupTable());
362 _planeWidgetZ->SetLookupTable(_planeWidgetX->GetLookupTable());
364 picker->UnRegister(NULL);
366 // ColorWindow ColorLevel Callback
367 vtkWindowLevelImagePlaneWidgetCallback *wlipwc = vtkWindowLevelImagePlaneWidgetCallback::New();
368 wlipwc->_wxvtkmpr3Dview = this;
369 _planeWidgetX->AddObserver(vtkCommand::WindowLevelEvent, wlipwc );
370 _planeWidgetY->AddObserver(vtkCommand::WindowLevelEvent, wlipwc );
371 _planeWidgetZ->AddObserver(vtkCommand::WindowLevelEvent, wlipwc );
374 _planeWidgetX->AddObserver(vtkCommand::InteractionEvent, wlipwc );
375 _planeWidgetY->AddObserver(vtkCommand::InteractionEvent, wlipwc );
376 _planeWidgetZ->AddObserver(vtkCommand::InteractionEvent, wlipwc );
379 //-------------------------------------------------------------------
380 vtkImagePlaneWidget* wxVtkMPR3DView::GetPlaneWidget(unsigned char activationkey, double r, double g, double b, vtkCellPicker* picker)
382 vtkProperty* prop1 = 0;
383 vtkImagePlaneWidget* planeWidget = 0;
384 planeWidget = vtkImagePlaneWidget::New();
385 planeWidget->SetInteractor( GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor() );
386 planeWidget->EnabledOff();
387 vtkImageData *image = GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
388 int xMin = 0, xMax = 0, yMin = 0, yMax = 0, zMin = 0, zMax = 0;
389 double xSpacing = 0, ySpacing = 0, zSpacing = 0;
392 planeWidget->SetInput( image );
393 image->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax);
394 image->GetSpacing(xSpacing, ySpacing, zSpacing);
397 if (activationkey=='x')
399 planeWidget->SetPlaneOrientationToXAxes();
400 planeWidget->SetSlicePosition((xMax+xMin)/2.*xSpacing);
403 if (activationkey=='y')
405 planeWidget->SetPlaneOrientationToYAxes();
406 planeWidget->SetSlicePosition((yMax+yMin)/2.*ySpacing);
409 if (activationkey=='z')
411 planeWidget->SetPlaneOrientationToZAxes();
412 planeWidget->SetSlicePosition((zMax+zMin)/2.*zSpacing);
415 planeWidget->DisplayTextOn();
416 planeWidget->SetPicker(picker);
417 planeWidget->SetKeyPressActivationValue(activationkey);
418 prop1 = planeWidget->GetPlaneProperty();
419 prop1->SetColor(r, g, b);
423 //-------------------------------------------------------------------
424 void wxVtkMPR3DView::SetFreePlanesOrtho()
426 _planeWidgetX->SetPlaneOrientationToXAxes();
427 _planeWidgetY->SetPlaneOrientationToYAxes();
428 _planeWidgetZ->SetPlaneOrientationToZAxes();
429 vtkInteractorStyleBaseView *isbv = (vtkInteractorStyleBaseView*)GetWxvtk3Dbaseview()->GetInteractorStyleBaseView();
430 isbv->SetParent_refresh_waiting();
431 isbv->EvaluateToRefresh();
434 //-------------------------------------------------------------------
435 void wxVtkMPR3DView::FreePlaneVisible(int plane, bool ok)
439 if ((plane==1) && (ok==true)) _planeWidgetX->EnabledOn();
440 if ((plane==2) && (ok==true)) _planeWidgetY->EnabledOn();
441 if ((plane==3) && (ok==true)) _planeWidgetZ->EnabledOn();
442 if ((plane==1) && (ok==false)) _planeWidgetX->EnabledOff();
443 if ((plane==2) && (ok==false)) _planeWidgetY->EnabledOff();
444 if ((plane==3) && (ok==false)) _planeWidgetZ->EnabledOff();
448 //-------------------------------------------------------------------
449 void wxVtkMPR3DView::FreePlaneInteraction(bool ok)
455 _planeWidgetX->InteractionOn();
456 _planeWidgetY->InteractionOn();
457 _planeWidgetZ->InteractionOn();
459 _planeWidgetX->InteractionOff();
460 _planeWidgetY->InteractionOff();
461 _planeWidgetZ->InteractionOff();
463 } // if _planeWidgetX
468 //-------------------------------------------------------------------
469 void wxVtkMPR3DView::setColorTransferFunction(vtkColorTransferFunction* colortable)
471 GetVtkMPR3DDataViewer ()->setColorTransferFunction(colortable);
474 //-------------------------------------------------------------------
475 void wxVtkMPR3DView::Refresh() // virtual
477 _vtkmpr3Ddataviewer -> Refresh();
478 if (_wxvtkmpr3DviewCntrlPanel!=NULL)
480 _wxvtkmpr3DviewCntrlPanel->Refresh();
485 //-------------------------------------------------------------------
486 void wxVtkMPR3DView::RefreshView() // virtual
489 vtkImageData *image = GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
492 image->GetSpacing(spc);
498 //this->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData()->GetSpacing(spc);
500 //double nx=1,ny=0,nz=0; // JPRx
502 double x=GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetX();
503 double y=GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetY();
504 double z=GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetZ();
506 SetColorWindow( _vtkmpr3Ddataviewer->GetVtkMPRBaseData()->GetColorWindow() );
507 SetColorLevel( _vtkmpr3Ddataviewer->GetVtkMPRBaseData()->GetColorLevel() );
512 _planeWidgetX->GetNormal(normal);
513 if ((normal[0]==1)&&(normal[1]==0)&&(normal[2]==0))
515 _planeWidgetX->SetSlicePosition( x*spc[0] );
518 _planeWidgetY->GetNormal(normal);
519 if ((normal[0]==0)&&(normal[1]==1)&&(normal[2]==0))
521 _planeWidgetY->SetSlicePosition( y*spc[1] );
524 _planeWidgetZ->GetNormal(normal);
525 if ((normal[0]==0)&&(normal[1]==0)&&(normal[2]==1))
527 _planeWidgetZ->SetSlicePosition( z*spc[2] );
535 _pointWidget->SetPosition( x,y,z );
538 vtkTransform *transform = GetVtkMPR3DDataViewer ()->GetVtkMPRBaseData()->GetTransformOrientation();
539 in[0]=1; in[1]=0; in[2]=0;
540 transform->TransformPoint(in,normal);
541 _planeWidget->SetNormal( normal[0],normal[1],normal[2] );
542 _planeWidget->SetCenter( x,y,z );
543 _planeWidget->UpdatePlacement();
544 _planeWidget->GetPolyData(_vtkplane);
548 //-------------------------------------------------------------------
549 wxPanel* wxVtkMPR3DView::CreateControlPanel(wxWindow *parent, bool align)
551 _wxvtkmpr3DviewCntrlPanel = new wxVtkMPR3DViewCntrlPanel(parent,this, align);
552 return _wxvtkmpr3DviewCntrlPanel;
554 //-------------------------------------------------------------------
555 vtkMPR3DDataViewer* wxVtkMPR3DView::GetVtkMPR3DDataViewer()
557 return _vtkmpr3Ddataviewer;
559 //-------------------------------------------------------------------
560 wxVtk3DBaseView* wxVtkMPR3DView::GetWxvtk3Dbaseview() throw (char*)
562 if(_wxvtk3Dbaseview==NULL){
563 throw "wxVtk3DBaseView* wxVtkMPR3DView::GetWxvtk3Dbaseview() _wxvtk3Dbaseview=NULL";
565 return _wxvtk3Dbaseview;
567 //-------------------------------------------------------------------
569 //-------------------------------------------------------------------
570 void wxVtkMPR3DView::VisibleImageActor(int idPosition, bool visible){
571 /*if(visible == false)
572 printf("CPR: wxVtkMPR3DView::VisibleImageActor-> visibleActor == false \n");
575 printf("CPR: wxVtkMPR3DView::VisibleImageActor-> visibleActor == true\n");
576 printf("CPR: wxVtkMPR3DView::VisibleImageActor-> idPosition == %d\n", idPosition);
579 if (visible!=_vtkmpr3Ddataviewer->GetVisiblePosition(idPosition)){
581 _wxvtk3Dbaseview->GetRenderer()->RemoveActor( _vtkmpr3Ddataviewer->GetImageActor(idPosition) );
583 _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkmpr3Ddataviewer->GetImageActor(idPosition) );
585 _vtkmpr3Ddataviewer->SetVisiblePosition(idPosition,visible);
590 //-------------------------------------------------------------------
591 void wxVtkMPR3DView::VisiblePointWidget( bool visible )
603 //-------------------------------------------------------------------
604 void wxVtkMPR3DView::VisiblePlaneWidget( bool visible )
610 _contourPlaneActor->VisibilityOn();
614 _contourPlaneActor->VisibilityOff();
619 //CPR: Method added 30 Nov 2009
620 void wxVtkMPR3DView::showOutlineActor(bool value)
622 vtkActor* _outlineActor = _vtkmpr3Ddataviewer->GetOutlineActor();
625 _wxvtk3Dbaseview->GetRenderer()->AddActor( _outlineActor );
629 _wxvtk3Dbaseview->GetRenderer()->RemoveActor( _outlineActor );
633 //-------------------------------------------------------------------
634 void wxVtkMPR3DView::SetVtkMPR3DDataViewer(vtkMPR3DDataViewer *vtkmpr3Ddataviewer)
636 _vtkmpr3Ddataviewer = vtkmpr3Ddataviewer;
639 //-------------------------------------------------------------------
640 void wxVtkMPR3DView::InitOrientationPointWidget()
642 this->_planeWidget->SetNormal(1,0,0);
645 //-------------------------------------------------------------------
646 void wxVtkMPR3DView::SetColorWindow(double colorWindow)
648 double colorLevel = _planeWidgetX->GetLevel();
649 _planeWidgetX->SetWindowLevel(colorWindow,colorLevel);
652 //-------------------------------------------------------------------
653 void wxVtkMPR3DView::SetColorLevel(double colorLevel)
655 double colorWindow = _planeWidgetX->GetWindow();
656 _planeWidgetX->SetWindowLevel(colorWindow,colorLevel);
659 //-------------------------------------------------------------------
660 // EED 25 Janvier 2007 testLoic
661 void wxVtkMPR3DView::TestLoic1()
665 double dimIma = sizeIma*2;
667 vtkImageData *vtkimagedata = this->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
670 vtkimagedata->GetSpacing(spc);
672 vtkimagedata->Update();
676 this->_planeWidget->GetOrigin(p);
677 this->_planeWidget->GetNormal(n);
681 vtkPlaneSource* pSource = vtkPlaneSource::New( );
682 pSource->SetResolution( sizeIma - 1, sizeIma - 1 );
683 pSource->SetOrigin( p[ 0 ], p[ 1 ], p[ 2 ] );
684 pSource->SetPoint1( p[ 0 ] + dimIma - 1.0, p[ 1 ], p[ 2 ] );
685 pSource->SetPoint2( p[ 0 ], p[ 1 ]+ dimIma - 1.0 , p[ 2 ] );
687 pSource->SetCenter( p[ 0 ], p[ 1 ], p[ 2 ] );
688 pSource->SetNormal( n[ 0 ], n[ 1 ], n[ 2 ] );
691 vtkProbeFilter* slices = vtkProbeFilter::New();
692 slices->SetInput( ( vtkDataSet* )pSource->GetOutput( ) );
693 slices->SetSource( vtkimagedata );
697 vtkStructuredPoints *stPoints = vtkStructuredPoints::New();
698 stPoints -> GetPointData( )->SetScalars( slices->GetOutput()->GetPointData()->GetScalars() );
699 stPoints -> SetDimensions( sizeIma, sizeIma, 1 );
700 stPoints -> SetScalarType( vtkimagedata->GetScalarType() );
701 stPoints -> SetScalarTypeToShort();
702 stPoints -> Update();
704 vtkImageChangeInformation *change = vtkImageChangeInformation ::New();
705 change -> SetInput( stPoints );
706 change -> Update(); //important
709 vtkimagedata->GetScalarRange(_range);
710 vtkWindowLevelLookupTable *_bwlookup = vtkWindowLevelLookupTable::New( );
711 _bwlookup->SetHueRange( 0 , 1 );
712 _bwlookup->SetNumberOfColors( (int)(_range[1] - _range[0] + 1) );
713 _bwlookup->SetTableRange( _range[0] , _range[1] );
714 _bwlookup->SetSaturationRange( 0 , 0 );
715 _bwlookup->SetValueRange( 0 , 1 );
716 _bwlookup->SetAlphaRange( 1 , 1 );
719 vtkLookupTable * _collookup = vtkLookupTable::New( );
720 _collookup->SetNumberOfColors( 256 );
721 _collookup->SetTableRange( 0 , 255 );
722 _collookup->Build( );
723 _collookup->SetTableValue( 0 , 1 , 0 , 0 , 1 );
724 _collookup->SetTableValue(128 , 0 , 0 , 1 , 1 );
725 _collookup->SetTableValue(255 , 0 , 1 , 0 , 1 );
728 vtkMetaImageWriter *writer = vtkMetaImageWriter::New( );
729 writer->SetInput( stPoints );
730 writer->SetFileName( "C:/Users/Images/temp_EED/image.mhd" );
731 writer->SetFileDimensionality( 2 );
736 vtkDataSetMapper *_3DSliceMapper = vtkDataSetMapper::New( );
737 _3DSliceMapper->SetInput(change->GetOutput( ) );
738 _3DSliceMapper->SetLookupTable( _bwlookup );
739 _3DSliceMapper->SetScalarRange( _range );
740 _3DSliceMapper->ImmediateModeRenderingOn( );
742 vtkActor *_3DSliceActor = vtkActor::New( );
743 _3DSliceActor->SetMapper( _3DSliceMapper );
745 // The usual rendering stuff.
746 vtkCamera *camera = vtkCamera::New();
747 camera->SetPosition(1,1,1);
748 camera->SetFocalPoint(0,0,0);
750 vtkRenderer *renderer = vtkRenderer::New();
751 vtkRenderWindow *renWin = vtkRenderWindow::New();
752 renWin->AddRenderer(renderer);
754 vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
755 iren->SetRenderWindow(renWin);
757 renderer->AddActor( _3DSliceActor );
758 renderer->SetActiveCamera(camera);
759 renderer->ResetCamera();
760 renderer->SetBackground(1,1,1);
762 renWin->SetSize(300,300);
764 // interact with data
774 //-------------------------------------------------------------------
775 // EED 25 Janvier 2007 testLoic
776 void wxVtkMPR3DView::TestLoic2()
779 vtkVectorNorm *vecMagnitude = vtkVectorNorm::New();
780 vecMagnitude->SetInput(VtkMainGrid);
781 vecMagnitude->NormalizeOff();
782 vecMagnitude->Update();
785 vtkPlane *slicePlane = vtkPlane::New();
786 this->_planeWidget->GetPlane( slicePlane );
789 vtkCutter* sliceCutter = vtkCutter::New();
790 vtkImageData *vtkimagedata = this->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
791 sliceCutter->SetInput( vtkimagedata );
792 sliceCutter->SetCutFunction( slicePlane );
795 // vtkLookupTable *lut = BuildHueWeightBaseMap();
798 vtkPolyDataMapper *slice = vtkPolyDataMapper::New();
799 slice->SetInput( sliceCutter->GetOutput() );
803 vtkimagedata->GetScalarRange(range);
804 // vecMagnitude->GetOutput()->GetScalarRange( range );
805 // range[1] *= 0.7; // reduce the upper range by 30%
806 // slice->SetScalarRange( range );
807 // slice->SetLookupTable( lut );
809 // vtkActor *sliceActor = vtkActor::New();
810 // sliceActor->SetMapper( slice );
812 vtkPolyDataMapper *contourMapper = vtkPolyDataMapper::New();
813 contourMapper->SetInput( sliceCutter->GetOutput() );
814 contourMapper->SetScalarRange( range );
815 // contourMapper->SetLookupTable( lut );
818 vtkActor *contourActor = vtkActor::New();
819 contourActor->SetMapper( contourMapper );
823 // The usual rendering stuff.
824 vtkCamera *camera = vtkCamera::New();
825 camera->SetPosition(1,1,1);
826 camera->SetFocalPoint(0,0,0);
828 vtkRenderer *renderer = vtkRenderer::New();
829 vtkRenderWindow *renWin = vtkRenderWindow::New();
830 renWin->AddRenderer(renderer);
832 vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
833 iren->SetRenderWindow(renWin);
835 renderer->AddActor( contourActor );
836 // renderer->AddActor(cubeActor);
837 renderer->SetActiveCamera(camera);
838 renderer->ResetCamera();
839 renderer->SetBackground(1,1,1);
841 renWin->SetSize(300,300);
843 // interact with data