]> Creatis software - clitk.git/blob - vv/vvSlicer.cxx
removed headers
[clitk.git] / vv / vvSlicer.cxx
1 #include "vvSlicer.h"
2
3 #include "vvImage.h"
4 #include "vvSlicerManagerCommand.h"
5 #include "vvGlyphSource.h"
6 #include "vvGlyph2D.h"
7 #include "vvImageMapToWLColors.h"
8
9 #include <vtkTextProperty.h>
10 #include <vtkTextActor.h>
11 #include <vtkTextSource.h>
12 #include <vtkActor2D.h>
13 #include <vtkCursor2D.h>
14 #include <vtkPolyDataMapper2D.h>
15 #include <vtkProperty2D.h>
16 #include <vtkCornerAnnotation.h>
17 #include <vtkImageMapToWindowLevelColors.h>
18 #include <vtkImageData.h>
19 #include <vtkImageActor.h>
20 #include <vtkToolkits.h>
21 #include <vtkObjectFactory.h>
22 #include <vtkPointData.h>
23 #include <vtkDataArray.h>
24 #include <vtkFloatArray.h>
25 #include <vtkClipPolyData.h>
26 #include <vtkGlyph3D.h>
27 #include <vtkMath.h>
28 #include <vtkCursor3D.h>
29 #include <vtkProperty.h>
30 #include <vtkLight.h>
31 #include <vtkLightCollection.h>
32 #include <vtkScalarBarActor.h>
33 #include <vtkLookupTable.h>
34
35 #include <vtkRenderer.h>
36 #include <vtkRendererCollection.h>
37 #include <vtkRenderWindow.h>
38 #include <vtkRenderWindowInteractor.h>
39 #include <vtkCamera.h>
40 #include <vtkCallbackCommand.h>
41 #include <vtkCommand.h>
42 #include <vtkPolyDataMapper.h>
43 #include <vtkBox.h>
44
45 #include <vtkExtractVOI.h>
46 #include <vtkSphereSource.h>
47 #include <vtkCutter.h>
48 #include <vtkAssignAttribute.h>
49 #include <vtkImageAccumulate.h>
50
51 vtkCxxRevisionMacro(vvSlicer, "DummyRevision");
52 vtkStandardNewMacro(vvSlicer);
53
54 //------------------------------------------------------------------------------
55 vvSlicer::vvSlicer()
56 {
57   mImage = NULL;
58   mCurrentTSlice = 0;
59   mUseReducedExtent = false;
60
61   mCurrent[0] = -VTK_DOUBLE_MAX;
62   mCurrent[1] = -VTK_DOUBLE_MAX;
63   mCurrent[2] = -VTK_DOUBLE_MAX;
64
65   mCursor[0] = -VTK_DOUBLE_MAX;
66   mCursor[1] = -VTK_DOUBLE_MAX;
67   mCursor[2] = -VTK_DOUBLE_MAX;
68   mCursor[3] = -VTK_DOUBLE_MAX;
69
70   mSubSampling = 5;
71   mScale = 1;
72   mVFLog = 0;
73
74   std::string text = "F1 = sagital; F2 = coronal; F3 = axial\n";
75   text += "F5 = horizontal flip; F6 = vertical flip\n\n";
76   text += "0,1,2,3,4,5 : preset windowing\n";
77   text += "6,7,8,9 : preset colormap\n";
78   text += "z : local windowing\n";
79   text += "r : reset view\n";
80   text += "l : reload image\n";
81   text += "f : fly to mouse position\n";
82   text += "g : go to cross hair position\n\n";
83   text += "Up,down : change slice\n";
84   text += "Left,right : change tenporal slice\n\n";
85   text += "Scrollbar (or w/x) : zoom in/out\n";
86   text += "left button : synchronize all views\n";
87   text += "middle button : grab image\n";
88   text += "right button : change windowing\n";
89
90   crossCursor = vtkCursor2D::New();
91   crossCursor->AllOff();
92   crossCursor->AxesOn();
93   crossCursor->SetTranslationMode(1);
94   crossCursor->SetRadius(2);
95
96   pdm = vtkPolyDataMapper2D::New();
97   pdm->SetInput(crossCursor->GetOutput());
98
99   pdmA = vtkActor2D::New();
100   pdmA->SetMapper(pdm);
101   pdmA->GetProperty()->SetColor(255,10,212);
102   pdmA->SetVisibility(0);
103   pdmA->SetPickable(0);
104
105   ca = vtkCornerAnnotation::New();
106   ca->GetTextProperty()->SetColor(255,10,212);
107   ca->SetVisibility(1);
108   mFileName = "";
109
110   mVF = NULL;
111   mOverlay = NULL;
112   mFusion = NULL;
113   mLandmarks = NULL;
114
115   legend = vtkSmartPointer<vtkScalarBarActor>::New();
116   //legend->SetTitle("test!");
117   legend->SetPosition(0.82,0.18);
118   legend->SetWidth(0.1);
119   legend->SetVisibility(0);
120   legend->SetLabelFormat("%.1f");
121   this->GetRenderer()->AddActor(legend);
122
123   this->WindowLevel->Delete();
124   this->WindowLevel = vvImageMapToWLColors::New();
125   this->InstallPipeline();
126 }
127 //------------------------------------------------------------------------------
128
129
130 //------------------------------------------------------------------------------
131 vtkImageMapToWindowLevelColors* vvSlicer::GetOverlayMapper() {
132   return mOverlayMapper.GetPointer();
133 }
134 //------------------------------------------------------------------------------
135
136
137 //------------------------------------------------------------------------------
138 vtkImageActor* vvSlicer::GetOverlayActor() {
139   return mOverlayActor.GetPointer();
140 }
141 //------------------------------------------------------------------------------
142
143
144 //------------------------------------------------------------------------------
145 vtkImageMapToWindowLevelColors* vvSlicer::GetFusionMapper() {
146   return mFusionMapper.GetPointer();
147 }
148 //------------------------------------------------------------------------------
149
150     
151 //------------------------------------------------------------------------------
152 vtkImageActor* vvSlicer::GetFusionActor() {
153   return mFusionActor.GetPointer();
154 }
155 //------------------------------------------------------------------------------
156
157
158 //------------------------------------------------------------------------------
159 vtkActor* vvSlicer::GetVFActor() {
160   return mVFActor.GetPointer();
161 }
162 //------------------------------------------------------------------------------
163
164
165 //------------------------------------------------------------------------------
166 vtkCornerAnnotation* vvSlicer::GetAnnotation() {
167   return ca.GetPointer();
168 }
169 //------------------------------------------------------------------------------
170
171
172 //------------------------------------------------------------------------------
173 void vvSlicer::EnableReducedExtent(bool b) {
174   mUseReducedExtent = b;
175 }
176 //------------------------------------------------------------------------------
177
178
179 //------------------------------------------------------------------------------
180 void vvSlicer::SetReducedExtent(int * ext) {
181   mReducedExtent = ext;
182 }
183 //------------------------------------------------------------------------------
184
185
186 //------------------------------------------------------------------------------
187 void vvSlicer::AddContour(vvMesh::Pointer contour,bool propagate)
188 {
189
190   mSurfaceCutActors.push_back(new vvMeshActor());
191   if (propagate)
192     mSurfaceCutActors.back()->Init(contour,mCurrentTSlice,mVF);
193   else
194     mSurfaceCutActors.back()->Init(contour,mCurrentTSlice);
195   mSurfaceCutActors.back()->SetSlicingOrientation(SliceOrientation);
196   this->GetRenderer()->AddActor(mSurfaceCutActors.back()->GetActor());
197
198   SetContourSlice();
199 }
200 //------------------------------------------------------------------------------
201
202
203 //------------------------------------------------------------------------------
204 void vvSlicer::ToggleContourSuperposition()
205 {
206   for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
207        i!=mSurfaceCutActors.end();i++)
208     (*i)->ToggleSuperposition();
209 }
210 //------------------------------------------------------------------------------
211
212
213 //------------------------------------------------------------------------------
214 void vvSlicer::SetCursorColor(int r,int g, int b)
215 {
216   pdmA->GetProperty()->SetColor(r,g,b);
217 }
218 //------------------------------------------------------------------------------
219
220
221 //------------------------------------------------------------------------------
222 void vvSlicer::SetCursorVisibility(bool s)
223 {
224   pdmA->SetVisibility(s);
225 }
226 //------------------------------------------------------------------------------
227
228
229 //------------------------------------------------------------------------------
230 bool vvSlicer::GetCursorVisibility()
231 {
232   return pdmA->GetVisibility();
233 }
234 //------------------------------------------------------------------------------
235
236
237 //------------------------------------------------------------------------------
238 vvSlicer::~vvSlicer()
239 {
240   for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
241        i!=mSurfaceCutActors.end();i++)
242     delete (*i);
243 }
244 //------------------------------------------------------------------------------
245
246
247 //------------------------------------------------------------------------------
248 void vvSlicer::SetCurrentPosition(double x, double y, double z, int t)
249 {
250   mCurrent[0] = x;
251   mCurrent[1] = y;
252   mCurrent[2] = z;
253   mCurrentTSlice = t;
254 }
255 //------------------------------------------------------------------------------
256
257
258 //------------------------------------------------------------------------------
259 void vvSlicer::SetImage(vvImage::Pointer image)
260 {
261   if (image->GetVTKImages().size())
262     {
263       mImage = image;
264       this->Superclass::SetInput(image->GetVTKImages()[0]);
265       this->UpdateDisplayExtent();
266       mCurrentTSlice = 0;
267       ca->SetText(0,mFileName.c_str());
268     }
269 }
270 //------------------------------------------------------------------------------
271
272
273 //------------------------------------------------------------------------------
274 void vvSlicer::SetOverlay(vvImage::Pointer overlay)
275 {
276   if (overlay->GetVTKImages().size())
277     {
278       mOverlay = overlay;
279
280       if (!mOverlayMapper)
281         mOverlayMapper = vtkImageMapToWindowLevelColors::New();
282       mOverlayMapper->SetInput(overlay->GetVTKImages()[0]);
283
284       if (!mOverlayActor)
285         {
286           mOverlayActor = vtkImageActor::New();
287           mOverlayActor->SetInput(mOverlayMapper->GetOutput());
288           mOverlayActor->SetPickable(0);
289           mOverlayActor->SetVisibility(false);
290           mOverlayActor->SetOpacity(0.5);
291           this->UpdateDisplayExtent();
292         }
293
294       //stupid but necessary : the Overlay need to be rendered before fusion
295       if (mFusionActor)
296         {
297           this->GetRenderer()->RemoveActor(mFusionActor);
298           this->GetRenderer()->AddActor(mOverlayActor);
299           this->GetRenderer()->AddActor(mFusionActor);
300         }
301       else
302         this->GetRenderer()->AddActor(mOverlayActor);
303
304       //Synchronize slice
305       SetTSlice(mCurrentTSlice);
306     }
307 }
308 //------------------------------------------------------------------------------
309
310
311 //------------------------------------------------------------------------------
312 void vvSlicer::SetFusion(vvImage::Pointer fusion)
313 {
314   if (fusion->GetVTKImages().size())
315     {
316       mFusion = fusion;
317
318       if (!mFusionMapper)
319         mFusionMapper = vtkImageMapToWindowLevelColors::New();
320       mFusionMapper->SetInput(fusion->GetVTKImages()[0]);
321
322       if (!mFusionActor)
323         {
324           mFusionActor = vtkImageActor::New();
325           mFusionActor->SetInput(mFusionMapper->GetOutput());
326           mFusionActor->SetPickable(0);
327           mFusionActor->SetVisibility(false);
328           mFusionActor->SetOpacity(0.7);
329           this->UpdateDisplayExtent();
330           this->GetRenderer()->AddActor(mFusionActor);
331         }
332
333       //Synchronize slice
334       SetTSlice(mCurrentTSlice);
335     }
336 }
337 //------------------------------------------------------------------------------
338
339
340 //------------------------------------------------------------------------------
341 void vvSlicer::SetActorVisibility(const std::string& actor_type, int overlay_index ,bool vis)
342 {
343   if (actor_type == "vector")
344     {
345       this->mVFActor->SetVisibility(vis);
346     }
347   if (actor_type == "overlay")
348     {
349       this->mOverlayActor->SetVisibility(vis);
350     }
351   if (actor_type == "fusion")
352     {
353       this->mFusionActor->SetVisibility(vis);
354     }
355   if (actor_type == "contour")
356     this->mSurfaceCutActors[overlay_index]->GetActor()->SetVisibility(vis);
357   UpdateDisplayExtent();
358 }
359 //------------------------------------------------------------------------------
360
361
362 //------------------------------------------------------------------------------
363 void vvSlicer::SetVF(vvImage::Pointer vf)
364 {
365   if (vf->GetVTKImages().size())
366     {
367       mVF = vf;
368
369       if (!mAAFilter)
370         {
371           mAAFilter=vtkAssignAttribute::New();
372           mVOIFilter = vtkExtractVOI::New();
373           mVOIFilter->SetSampleRate(mSubSampling,mSubSampling,mSubSampling);
374         }
375       mVOIFilter->SetInput(vf->GetVTKImages()[0]);
376       mAAFilter->SetInput(mVOIFilter->GetOutput());
377       ///This tells VTK to use the scalar (pixel) data of the image to draw the little arrows
378       mAAFilter->Assign(vtkDataSetAttributes::SCALARS, vtkDataSetAttributes::VECTORS, vtkAssignAttribute::POINT_DATA);
379
380       if (!mArrow)
381         mArrow = vvGlyphSource::New();
382       mArrow->SetGlyphTypeToSpecificArrow();
383       mArrow->SetScale(mScale);
384       mArrow->FilledOff();
385
386       // Glyph the gradient vector (with arrows)
387       if (!mGlyphFilter)
388         mGlyphFilter = vvGlyph2D::New();
389       mGlyphFilter->SetInput(mAAFilter->GetOutput());
390       mGlyphFilter->SetSource(mArrow->GetOutput());
391       mGlyphFilter->ScalingOn();
392       mGlyphFilter->SetScaleModeToScaleByVector();
393       mGlyphFilter->OrientOn();
394       mGlyphFilter->SetVectorModeToUseVector();
395       mGlyphFilter->SetColorModeToColorByVector();
396
397       if (!mVFMapper)
398         mVFMapper = vtkPolyDataMapper::New();
399       //mVFMapper->SetInputConnection(mGlyphFilter->GetOutputPort());
400       mVFMapper->SetInput(mGlyphFilter->GetOutput());
401       mVFMapper->ImmediateModeRenderingOn();
402
403       if (!mVFActor)
404         mVFActor = vtkActor::New();
405       mVFActor->SetMapper(mVFMapper);
406       mVFActor->SetPickable(0);
407       this->UpdateDisplayExtent();
408       this->GetRenderer()->AddActor(mVFActor);
409
410       //Synchronize slice
411       SetTSlice(mCurrentTSlice);
412     }
413 }
414 //------------------------------------------------------------------------------
415
416
417 //------------------------------------------------------------------------------
418 void vvSlicer::SetLandmarks(vvLandmarks* landmarks)
419 {
420   mLandmarks = landmarks;
421   if (landmarks)
422     {
423
424       if (!mCross)
425         mCross = vtkCursor3D::New();
426       mCross->SetFocalPoint(0.0,0.0,0.0);
427       mCross->SetModelBounds(-10,10,-10,10,-10,10);
428       mCross->AllOff();
429       mCross->AxesOn();
430
431       if (!mLandGlyph)
432         mLandGlyph = vtkGlyph3D::New();
433       mLandGlyph->SetSource(mCross->GetOutput());
434       mLandGlyph->SetInput(landmarks->GetOutput());
435       //mLandGlyph->SetIndexModeToScalar();
436       mLandGlyph->SetRange(0,1);
437       mLandGlyph->ScalingOff();
438
439       mLandGlyph->SetColorModeToColorByScalar();
440
441       if (!mClipBox)
442         mClipBox = vtkBox::New();
443       if (!mLandClipper)
444         mLandClipper = vtkClipPolyData::New();
445       mLandClipper->InsideOutOn();
446       mLandClipper->SetInput(mLandGlyph->GetOutput());
447       mLandClipper->SetClipFunction(mClipBox);
448
449       if (!mLandMapper)
450         mLandMapper = vtkPolyDataMapper::New();
451       mLandMapper->SetInputConnection(mLandClipper->GetOutputPort());
452       //mLandMapper->ScalarVisibilityOff();
453
454       if (!mLandActor)
455         mLandActor = vtkActor::New();
456       mLandActor->SetMapper(mLandMapper);
457       mLandActor->GetProperty()->SetColor(255,10,212);
458       mLandActor->SetPickable(0);
459       mLandActor->SetVisibility(true);
460       this->UpdateDisplayExtent();
461       this->GetRenderer()->AddActor(mLandActor);
462     }
463 }
464 //------------------------------------------------------------------------------
465
466 //------------------------------------------------------------------------------
467 //FIXME: this function leaks memory, we should fix it someday :)
468 void vvSlicer::RemoveActor(const std::string& actor_type, int overlay_index)
469 {
470   if (actor_type == "vector")
471     {
472       Renderer->RemoveActor(mVFActor);
473       mGlyphFilter=NULL;
474       mVF = NULL;
475       mArrow = NULL;
476       mAAFilter=NULL;
477       mVOIFilter = NULL;
478       mVFMapper = NULL;
479       mVFActor = NULL;
480     }
481   if (actor_type == "overlay")
482     {
483       Renderer->RemoveActor(mOverlayActor);
484       mOverlay = NULL;
485       mOverlayActor = NULL;
486       mOverlayMapper = NULL;
487     }
488   if (actor_type == "fusion")
489     {
490       Renderer->RemoveActor(mFusionActor);
491       mFusion = NULL;
492       mFusionActor = NULL;
493       mFusionMapper = NULL;
494     }
495   if (actor_type == "contour")
496     {
497       Renderer->RemoveActor(this->mSurfaceCutActors[overlay_index]->GetActor());
498       mSurfaceCutActors.erase(mSurfaceCutActors.begin()+overlay_index);
499     }
500 }
501 //------------------------------------------------------------------------------
502
503
504 //------------------------------------------------------------------------------
505 void vvSlicer::SetVFSubSampling(int sub)
506 {
507   if (mVOIFilter)
508     {
509       mVOIFilter->SetSampleRate(mSubSampling,mSubSampling,mSubSampling);
510       mSubSampling = sub;
511     }
512   UpdateDisplayExtent();
513   Render();
514 }
515 //------------------------------------------------------------------------------
516
517
518 //------------------------------------------------------------------------------
519 void vvSlicer::SetVFScale(int scale)
520 {
521   mScale = scale;
522   if (mArrow)
523     mArrow->SetScale(mScale);
524   UpdateDisplayExtent();
525   Render();
526 }
527 //------------------------------------------------------------------------------
528
529
530 //------------------------------------------------------------------------------
531 void vvSlicer::SetVFLog(int log)
532 {
533   mVFLog = log;
534   if (mGlyphFilter)
535     {
536       mGlyphFilter->SetUseLog(mVFLog);
537       mGlyphFilter->Modified();
538     }
539   UpdateDisplayExtent();
540   Render();
541 }
542 //------------------------------------------------------------------------------
543
544
545 //------------------------------------------------------------------------------
546 void vvSlicer::SetTSlice(int t)
547 {
548   if (t < 0)
549     t = 0;
550   else if ((unsigned int)t >= mImage->GetVTKImages().size())
551     t = mImage->GetVTKImages().size() -1;
552   mCurrentTSlice = t;
553   this->SetInput(mImage->GetVTKImages()[t]);
554   if (mVF && mVFActor->GetVisibility())
555     {
556       if (mVF->GetVTKImages().size() > (unsigned int)mCurrentTSlice)
557         mVOIFilter->SetInput(mVF->GetVTKImages()[mCurrentTSlice]);
558     }
559   if (mOverlay && mOverlayActor->GetVisibility())
560     {
561       if (mOverlay->GetVTKImages().size() > (unsigned int)mCurrentTSlice)
562         mOverlayMapper->SetInput(mOverlay->GetVTKImages()[mCurrentTSlice]);
563     }
564   if (mFusion && mFusionActor->GetVisibility())
565     {
566       if (mFusion->GetVTKImages().size() > (unsigned int)mCurrentTSlice)
567         mFusionMapper->SetInput(mFusion->GetVTKImages()[mCurrentTSlice]);
568     }
569   if (mSurfaceCutActors.size() > 0)
570     for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
571          i!=mSurfaceCutActors.end();i++)
572       (*i)->SetTimeSlice(mCurrentTSlice);
573   UpdateDisplayExtent();
574 }
575 //------------------------------------------------------------------------------
576
577
578 //------------------------------------------------------------------------------
579 int vvSlicer::GetTSlice()
580 {
581   return mCurrentTSlice;
582 }
583 //------------------------------------------------------------------------------
584
585
586 //------------------------------------------------------------------------------
587 void vvSlicer::SetSliceOrientation(int orientation)
588 {
589   //if 2D image, force to watch in Axial View
590   int extent[6];
591   this->GetInput()->GetWholeExtent(extent);
592   if (extent[5]-extent[4] <= 2)
593     orientation=2;
594
595   if (orientation < vtkImageViewer2::SLICE_ORIENTATION_YZ ||
596       orientation > vtkImageViewer2::SLICE_ORIENTATION_XY)
597     {
598       vtkErrorMacro("Error - invalid slice orientation " << orientation);
599       return;
600     }
601
602   this->SliceOrientation = orientation;
603     
604   // Update the viewer
605   int *range = this->GetSliceRange();
606   if (range)
607     this->Slice = static_cast<int>((range[0] + range[1]) * 0.5);
608
609   this->UpdateOrientation();
610   this->UpdateDisplayExtent();
611
612   if (this->Renderer && this->GetInput())
613     {
614       double scale = this->Renderer->GetActiveCamera()->GetParallelScale();
615       this->Renderer->ResetCamera();
616       this->Renderer->GetActiveCamera()->SetParallelScale(scale);
617     }
618
619   SetContourSlice();
620 }
621
622 //----------------------------------------------------------------------------
623 void vvSlicer::UpdateDisplayExtent()
624 {
625   vtkImageData *input = this->GetInput();
626   if (!input || !this->ImageActor)
627     {
628       return;
629     }
630   input->UpdateInformation();
631   int *w_ext;// = input->GetWholeExtent();
632
633   if (mUseReducedExtent) {
634     w_ext = mReducedExtent;
635   }
636   else w_ext = input->GetWholeExtent();
637
638   switch (this->SliceOrientation)
639     {
640     case vtkImageViewer2::SLICE_ORIENTATION_XY:
641       this->ImageActor->SetDisplayExtent(
642                                          w_ext[0], w_ext[1], w_ext[2], w_ext[3], this->Slice, this->Slice);
643       if (mVF && mVFActor->GetVisibility())
644         {
645           int vfExtent[6];
646           ComputeVFDisplayedExtent(w_ext[0], w_ext[1], w_ext[2], w_ext[3], this->Slice, this->Slice,vfExtent);
647           mVOIFilter->SetVOI(vfExtent);
648           mGlyphFilter->SetOrientation(1,1,0);
649           mVFMapper->Update();
650           // put the vector field between the image and the camera
651           if (Renderer->GetActiveCamera()->GetPosition()[2] > this->Slice)
652             mVFActor->SetPosition(0,0,ImageActor->GetBounds()[5]+2);
653           else
654             mVFActor->SetPosition(0,0,ImageActor->GetBounds()[4]-2);
655         }
656       if (mOverlay && mOverlayActor->GetVisibility())
657         {
658           int overExtent[6];
659           ComputeOverlayDisplayedExtent(w_ext[0], w_ext[1], w_ext[2], w_ext[3], this->Slice, this->Slice,overExtent);
660           mOverlayActor->SetDisplayExtent(overExtent);
661           if (Renderer->GetActiveCamera()->GetPosition()[2] > this->Slice)
662             mOverlayActor->SetPosition(0,0,1);
663           else
664             mOverlayActor->SetPosition(0,0,-1);
665         }
666       if (mFusion && mFusionActor->GetVisibility())
667         {
668           int fusExtent[6];
669           ComputeFusionDisplayedExtent(w_ext[0], w_ext[1], w_ext[2], w_ext[3], this->Slice, this->Slice,fusExtent);
670           mFusionActor->SetDisplayExtent(fusExtent);
671           if (Renderer->GetActiveCamera()->GetPosition()[2] > this->Slice)
672             mFusionActor->SetPosition(0,0,1.5);
673           else
674             mFusionActor->SetPosition(0,0,-1.5);
675         }
676       if (mLandActor)
677         {
678           if (mClipBox)
679             {
680               double bounds [6];
681               bounds[0] = ImageActor->GetBounds()[0];
682               bounds[1] = ImageActor->GetBounds()[1];
683               bounds[2] = ImageActor->GetBounds()[2];
684               bounds[3] = ImageActor->GetBounds()[3];
685               bounds[4] = ImageActor->GetBounds()[4]-(0.9/this->GetInput()->GetSpacing()[2]);
686               bounds[5] = ImageActor->GetBounds()[5]+(0.9/this->GetInput()->GetSpacing()[2]);
687               mClipBox->SetBounds(bounds);
688               UpdateLandmarks();
689             }
690           if (Renderer->GetActiveCamera()->GetPosition()[2] > this->Slice)
691             mLandActor->SetPosition(0,0,1.5);
692           else
693             mLandActor->SetPosition(0,0,-1.5);
694         }
695       break;
696
697     case vtkImageViewer2::SLICE_ORIENTATION_XZ:
698       this->ImageActor->SetDisplayExtent(
699                                          w_ext[0], w_ext[1], this->Slice, this->Slice, w_ext[4], w_ext[5]);
700       if (mVF && mVFActor->GetVisibility())
701         {
702           int vfExtent[6];
703           ComputeVFDisplayedExtent(w_ext[0], w_ext[1], this->Slice, this->Slice, w_ext[4], w_ext[5],vfExtent);
704           mVOIFilter->SetVOI(vfExtent);
705           mGlyphFilter->SetOrientation(1,0,1);
706           mVFMapper->Update();
707           // put the vector field between the image aSpacingnd the camera
708           if (Renderer->GetActiveCamera()->GetPosition()[1] > this->Slice)
709             mVFActor->SetPosition(0,ImageActor->GetBounds()[3]+2,0);
710           else
711             mVFActor->SetPosition(0,ImageActor->GetBounds()[2]-2,0);
712         }
713       if (mOverlay && mOverlayActor->GetVisibility())
714         {
715           int overExtent[6];
716           ComputeOverlayDisplayedExtent(w_ext[0], w_ext[1], this->Slice, this->Slice, w_ext[4], w_ext[5],overExtent);
717           mOverlayActor->SetDisplayExtent(overExtent);
718           if (Renderer->GetActiveCamera()->GetPosition()[1] > this->Slice)
719             mOverlayActor->SetPosition(0,1,0);
720           else
721             mOverlayActor->SetPosition(0,-1,0);
722         }
723       if (mFusion && mFusionActor->GetVisibility())
724         {
725           int fusExtent[6];
726           ComputeFusionDisplayedExtent(w_ext[0], w_ext[1], this->Slice, this->Slice, w_ext[4], w_ext[5],fusExtent);
727           mFusionActor->SetDisplayExtent(fusExtent);
728           if (Renderer->GetActiveCamera()->GetPosition()[1] > this->Slice)
729             mFusionActor->SetPosition(0,1.5,0);
730           else
731             mFusionActor->SetPosition(0,-1.5,0);
732         }
733       if (mLandActor)
734         {
735           if (mClipBox)
736             {
737               double bounds [6];
738               bounds[0] = ImageActor->GetBounds()[0];
739               bounds[1] = ImageActor->GetBounds()[1];
740               bounds[2] = ImageActor->GetBounds()[2]-(0.5/this->GetInput()->GetSpacing()[1]);
741               bounds[3] = ImageActor->GetBounds()[3]+(0.5/this->GetInput()->GetSpacing()[1]);
742               bounds[4] = ImageActor->GetBounds()[4];
743               bounds[5] = ImageActor->GetBounds()[5];
744               mClipBox->SetBounds(bounds);
745               UpdateLandmarks();
746             }
747           if (Renderer->GetActiveCamera()->GetPosition()[1] > this->Slice)
748             mLandActor->SetPosition(0,1.5,0);
749           else
750             mLandActor->SetPosition(0,-1.5,0);
751         }
752       break;
753
754     case vtkImageViewer2::SLICE_ORIENTATION_YZ:
755       this->ImageActor->SetDisplayExtent(
756                                          this->Slice, this->Slice, w_ext[2], w_ext[3], w_ext[4], w_ext[5]);
757       if (mVF && mVFActor->GetVisibility())
758         {
759           int vfExtent[6];
760           ComputeVFDisplayedExtent(this->Slice, this->Slice, w_ext[2], w_ext[3], w_ext[4], w_ext[5],vfExtent);
761           mVOIFilter->SetVOI(vfExtent);
762           mGlyphFilter->SetOrientation(0,1,1);
763           mVFMapper->Update();
764           // put the vector field between the image and the camera
765           if (Renderer->GetActiveCamera()->GetPosition()[0] > this->Slice)
766             mVFActor->SetPosition(ImageActor->GetBounds()[1]+2,0,0);
767           else
768             mVFActor->SetPosition(ImageActor->GetBounds()[0]-2,0,0);
769         }
770       if (mOverlay && mOverlayActor->GetVisibility())
771         {
772           int overExtent[6];
773           ComputeOverlayDisplayedExtent(this->Slice, this->Slice, w_ext[2], w_ext[3], w_ext[4], w_ext[5],overExtent);
774           mOverlayActor->SetDisplayExtent(overExtent);
775           if (Renderer->GetActiveCamera()->GetPosition()[0] > this->Slice)
776             mOverlayActor->SetPosition(1,0,0);
777           else
778             mOverlayActor->SetPosition(-1,0,0);
779         }
780       if (mFusion && mFusionActor->GetVisibility())
781         {
782           int fusExtent[6];
783           ComputeFusionDisplayedExtent(this->Slice, this->Slice, w_ext[2], w_ext[3], w_ext[4], w_ext[5],fusExtent);
784           mFusionActor->SetDisplayExtent(fusExtent);
785           if (Renderer->GetActiveCamera()->GetPosition()[0] > this->Slice)
786             mFusionActor->SetPosition(1.5,0,0);
787           else
788             mFusionActor->SetPosition(-1.5,0,0);
789         }
790       if (mLandActor)
791         {
792           if (mClipBox)
793             {
794               double bounds [6];
795               bounds[0] = ImageActor->GetBounds()[0]-(0.5/this->GetInput()->GetSpacing()[0]);
796               bounds[1] = ImageActor->GetBounds()[1]+(0.5/this->GetInput()->GetSpacing()[0]);
797               bounds[2] = ImageActor->GetBounds()[2];
798               bounds[3] = ImageActor->GetBounds()[3];
799               bounds[4] = ImageActor->GetBounds()[4];
800               bounds[5] = ImageActor->GetBounds()[5];
801               mClipBox->SetBounds(bounds);
802               UpdateLandmarks();
803             }
804           if (Renderer->GetActiveCamera()->GetPosition()[0] > this->Slice)
805             mLandActor->SetPosition(1.5,0,0);
806           else
807             mLandActor->SetPosition(-1.5,0,0);
808         }
809       break;
810     }
811
812   // Figure out the correct clipping range
813
814   if (this->Renderer)
815     {
816       if (this->InteractorStyle &&
817           this->InteractorStyle->GetAutoAdjustCameraClippingRange())
818         {
819           this->Renderer->ResetCameraClippingRange();
820         }
821       else
822         {
823           vtkCamera *cam = this->Renderer->GetActiveCamera();
824           if (cam)
825             {
826               double bounds[6];
827               this->ImageActor->GetBounds(bounds);
828               double spos = (double)bounds[this->SliceOrientation * 2];
829               double cpos = (double)cam->GetPosition()[this->SliceOrientation];
830               double range = fabs(spos - cpos);
831               double *spacing = input->GetSpacing();
832               double avg_spacing =
833                 ((double)spacing[0] + (double)spacing[1] + (double)spacing[2]) / 3.0;
834               cam->SetClippingRange(
835                                     range - avg_spacing * 3.0, range + avg_spacing * 3.0);
836             }
837         }
838     }
839 }
840 //----------------------------------------------------------------------------
841
842
843 //----------------------------------------------------------------------------
844 void vvSlicer::ComputeVFDisplayedExtent(int x1,int x2,int y1,int y2,int z1,int z2,int vfExtent[6])
845 {
846   vtkImageData* image=this->GetInput();
847   vfExtent[0] = (( image->GetOrigin()[0] + x1*image->GetSpacing()[0] ) - mVF->GetOrigin()[0]) /
848     mVF->GetSpacing()[0];
849   vfExtent[1] = (( image->GetOrigin()[0] + x2*image->GetSpacing()[0] ) - mVF->GetOrigin()[0]) /
850     mVF->GetSpacing()[0];
851   vfExtent[2] = (( image->GetOrigin()[1] + y1*image->GetSpacing()[1] ) - mVF->GetOrigin()[1]) /
852     mVF->GetSpacing()[1];
853   vfExtent[3] = (( image->GetOrigin()[1] + y2*image->GetSpacing()[1] ) - mVF->GetOrigin()[1]) /
854     mVF->GetSpacing()[1];
855   vfExtent[4] = (( image->GetOrigin()[2] + z1*image->GetSpacing()[2] ) - mVF->GetOrigin()[2]) /
856     mVF->GetSpacing()[2];
857   vfExtent[5] = (( image->GetOrigin()[2] + z2*image->GetSpacing()[2] ) - mVF->GetOrigin()[2]) /
858     mVF->GetSpacing()[2];
859
860   ClipDisplayedExtent(vfExtent,mVOIFilter->GetInput()->GetWholeExtent());
861 }
862 //----------------------------------------------------------------------------
863
864
865 //----------------------------------------------------------------------------
866 void vvSlicer::ComputeOverlayDisplayedExtent(int x1,int x2,int y1,int y2,int z1,int z2,int overExtent[6])
867 {
868   vtkImageData* image=this->GetInput();
869   overExtent[0] = (( image->GetOrigin()[0] + x1*image->GetSpacing()[0] ) - mOverlay->GetOrigin()[0]) /
870     mOverlay->GetSpacing()[0];
871   overExtent[1] = (( image->GetOrigin()[0] + x2*image->GetSpacing()[0] ) - mOverlay->GetOrigin()[0]) /
872     mOverlay->GetSpacing()[0];
873   overExtent[2] = (( image->GetOrigin()[1] + y1*image->GetSpacing()[1] ) - mOverlay->GetOrigin()[1]) /
874     mOverlay->GetSpacing()[1];
875   overExtent[3] = (( image->GetOrigin()[1] + y2*image->GetSpacing()[1] ) - mOverlay->GetOrigin()[1]) /
876     mOverlay->GetSpacing()[1];
877   overExtent[4] = (( image->GetOrigin()[2] + z1*image->GetSpacing()[2] ) - mOverlay->GetOrigin()[2]) /
878     mOverlay->GetSpacing()[2];
879   overExtent[5] = (( image->GetOrigin()[2] + z2*image->GetSpacing()[2] ) - mOverlay->GetOrigin()[2]) /
880     mOverlay->GetSpacing()[2];
881   ClipDisplayedExtent(overExtent, mOverlayMapper->GetInput()->GetWholeExtent());
882 }
883 //----------------------------------------------------------------------------
884
885
886 //----------------------------------------------------------------------------
887 void vvSlicer::ComputeFusionDisplayedExtent(int x1,int x2,int y1,int y2,int z1,int z2,int fusExtent[6])
888 {
889   vtkImageData* image=this->GetInput();
890   fusExtent[0] = (( image->GetOrigin()[0] + x1*image->GetSpacing()[0] ) - mFusion->GetOrigin()[0]) /
891     mFusion->GetSpacing()[0];
892   fusExtent[1] = (( image->GetOrigin()[0] + x2*image->GetSpacing()[0] ) - mFusion->GetOrigin()[0]) /
893     mFusion->GetSpacing()[0];
894   fusExtent[2] = (( image->GetOrigin()[1] + y1*image->GetSpacing()[1] ) - mFusion->GetOrigin()[1]) /
895     mFusion->GetSpacing()[1];
896   fusExtent[3] = (( image->GetOrigin()[1] + y2*image->GetSpacing()[1] ) - mFusion->GetOrigin()[1]) /
897     mFusion->GetSpacing()[1];
898   fusExtent[4] = (( image->GetOrigin()[2] + z1*image->GetSpacing()[2] ) - mFusion->GetOrigin()[2]) /
899     mFusion->GetSpacing()[2];
900   fusExtent[5] = (( image->GetOrigin()[2] + z2*image->GetSpacing()[2] ) - mFusion->GetOrigin()[2]) /
901     mFusion->GetSpacing()[2];
902   ClipDisplayedExtent(fusExtent, mFusionMapper->GetInput()->GetWholeExtent());
903 }
904 //----------------------------------------------------------------------------
905
906
907 //----------------------------------------------------------------------------
908 void vvSlicer::ClipDisplayedExtent(int extent[6], int refExtent[6])
909 {
910   bool out = false;
911   int maxBound = 6;
912
913   //2D overlay on 3D image specific case
914   if (refExtent[4] == refExtent[5])
915     {
916       maxBound = 4;
917       extent[4] = refExtent[4];
918       extent[5] = refExtent[5];
919     }
920
921   for (int i = 0; i < maxBound; i = i+2)
922     {
923       //if we are totally outside the image
924       if ( extent[i] > refExtent[i+1] || extent[i+1] < refExtent[i] )
925         {
926           out = true;
927           break;
928         }
929       //crop to the limit of the image
930       extent[i] = (extent[i] > refExtent[i]) ? extent[i] : refExtent[i];
931       extent[i] = (extent[i] < refExtent[i+1]) ? extent[i] : refExtent[i+1];
932       extent[i+1] = (extent[i+1] > refExtent[i]) ? extent[i+1] : refExtent[i];
933       extent[i+1] = (extent[i+1] < refExtent[i+1]) ? extent[i+1] : refExtent[i+1];
934     }
935   if (out)
936     for (int i = 0; i < maxBound; i = i+2)
937       {
938         extent[i] = refExtent[i];
939         extent[i+1] = refExtent[i];
940       }
941 }
942 //----------------------------------------------------------------------------
943
944
945 //----------------------------------------------------------------------------
946 void vvSlicer::UpdateOrientation()
947 {
948   // Set the camera position
949   vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
950   if (cam)
951     {
952       switch (this->SliceOrientation)
953         {
954         case vtkImageViewer2::SLICE_ORIENTATION_XY:
955           cam->SetFocalPoint(0,0,0);
956           cam->SetPosition(0,0,-1); // -1 if medical ?
957           cam->SetViewUp(0,-1,0);
958           break;
959
960         case vtkImageViewer2::SLICE_ORIENTATION_XZ:
961           cam->SetFocalPoint(0,0,0);
962           cam->SetPosition(0,-1,0); // 1 if medical ?
963           cam->SetViewUp(0,0,1);
964           break;
965
966         case vtkImageViewer2::SLICE_ORIENTATION_YZ:
967           cam->SetFocalPoint(0,0,0);
968           cam->SetPosition(-1,0,0); // -1 if medical ?
969           cam->SetViewUp(0,0,1);
970           break;
971         }
972     }
973 }
974 //----------------------------------------------------------------------------
975
976
977 //----------------------------------------------------------------------------
978 void vvSlicer::SetOpacity(double s)
979 {
980   this->GetImageActor()->SetOpacity(s);
981 }
982 //----------------------------------------------------------------------------
983
984
985 //----------------------------------------------------------------------------
986 void vvSlicer::SetRenderWindow(int orientation, vtkRenderWindow * rw)
987 {
988   this->Superclass::SetRenderWindow(rw);
989   this->SetupInteractor(rw->GetInteractor());
990   ca->SetImageActor(this->GetImageActor());
991   ca->SetWindowLevel(this->GetWindowLevel());
992   ca->SetText(2, "<slice>");
993   ca->SetText(3, "<window>\n<level>");
994
995   double bounds[6];
996   double max = 65000;
997
998   bounds[0] = -max;
999   bounds[1] = max;
1000   bounds[2] = -max;
1001   bounds[3] = max;
1002   bounds[4] = -max;
1003   bounds[5] = max;
1004
1005   crossCursor->SetModelBounds(bounds);
1006   this->GetRenderer()->AddActor(pdmA);
1007   this->GetRenderer()->AddActor(ca);
1008   this->GetRenderer()->ResetCamera();
1009
1010   //this is just a mapping between the labeling of the orientations presented to the user and
1011   //the one used by vtk
1012   SetSliceOrientation(2-(orientation%3));
1013   ResetCamera();
1014 }
1015 //----------------------------------------------------------------------------
1016
1017
1018 //----------------------------------------------------------------------------
1019 void vvSlicer::ResetCamera()
1020 {
1021   if (this->GetInput())
1022     {
1023       double* input_bounds=this->GetInput()->GetBounds();
1024       double bmax=input_bounds[1]-input_bounds[0];
1025       if (bmax < input_bounds[3]-input_bounds[2]) bmax=input_bounds[3]-input_bounds[2];
1026       if (bmax < input_bounds[5]-input_bounds[4]) bmax=input_bounds[5]-input_bounds[4];
1027       this->GetRenderer()->ResetCamera();
1028       this->GetRenderer()->GetActiveCamera()->SetParallelScale(bmax/2);
1029     }
1030 }
1031 //----------------------------------------------------------------------------
1032
1033
1034 //----------------------------------------------------------------------------
1035 void vvSlicer::SetDisplayMode(bool i)
1036 {
1037   this->GetImageActor()->SetVisibility(i);
1038   this->GetAnnotation()->SetVisibility(i);
1039   this->GetRenderer()->SetDraw(i);
1040   if (mLandActor)
1041     mLandActor->SetVisibility(i);
1042   pdmA->SetVisibility(i);
1043   if (i)
1044     UpdateDisplayExtent();
1045 }
1046 //----------------------------------------------------------------------------
1047
1048
1049 //----------------------------------------------------------------------------
1050 void vvSlicer::FlipHorizontalView()
1051 {
1052   vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
1053   if (cam)
1054     {
1055       double *position = cam->GetPosition();
1056       switch (this->SliceOrientation)
1057         {
1058         case vtkImageViewer2::SLICE_ORIENTATION_XY:
1059           cam->SetPosition(position[0],position[1],-position[2]);
1060           break;
1061
1062         case vtkImageViewer2::SLICE_ORIENTATION_XZ:
1063           cam->SetPosition(position[0],-position[1],position[2]);
1064           break;
1065
1066         case vtkImageViewer2::SLICE_ORIENTATION_YZ:
1067           cam->SetPosition(-position[0],position[1],position[2]);
1068           break;
1069         }
1070       this->Renderer->ResetCameraClippingRange();
1071       this->UpdateDisplayExtent();
1072     }
1073 }
1074 //----------------------------------------------------------------------------
1075
1076
1077 //----------------------------------------------------------------------------
1078 void vvSlicer::FlipVerticalView()
1079 {
1080   vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
1081   if (cam)
1082     {
1083       FlipHorizontalView();
1084       double *viewup = cam->GetViewUp();
1085       cam->SetViewUp(-viewup[0],-viewup[1],-viewup[2]);
1086       this->UpdateDisplayExtent();
1087     }
1088 }
1089 //----------------------------------------------------------------------------
1090
1091
1092 //----------------------------------------------------------------------------
1093 void vvSlicer::SetColorWindow(double window)
1094 {
1095   vtkLookupTable* LUT = static_cast<vtkLookupTable*>(this->GetWindowLevel()->GetLookupTable());
1096   if ( LUT )
1097     {
1098       double level = this->GetWindowLevel()->GetLevel();
1099       LUT->SetTableRange(level-fabs(window)/4,level+fabs(window)/4);
1100       LUT->Build();
1101     }
1102   this->vtkImageViewer2::SetColorWindow(window);
1103 }
1104 //----------------------------------------------------------------------------
1105
1106
1107 //----------------------------------------------------------------------------
1108 void vvSlicer::SetColorLevel(double level)
1109 {
1110   vtkLookupTable* LUT = static_cast<vtkLookupTable*>(this->GetWindowLevel()->GetLookupTable());
1111   if ( LUT )
1112     {
1113       double window = this->GetWindowLevel()->GetWindow();
1114       LUT->SetTableRange(level-fabs(window)/4,level+fabs(window)/4);
1115       LUT->Build();
1116     }
1117   this->vtkImageViewer2::SetColorLevel(level);
1118 }
1119 //----------------------------------------------------------------------------
1120
1121 //----------------------------------------------------------------------------
1122 // Returns the min an the max value in a 41x41 region around the mouse pointer
1123 void vvSlicer::GetExtremasAroundMousePointer(double & min, double & max)
1124 {
1125     //Get mouse pointer position in view coordinates
1126     double fLocalExtents[6];
1127     for(int i=0; i<3; i++)
1128     {
1129         fLocalExtents[i*2  ] = mCurrent[i];
1130         fLocalExtents[i*2+1] = mCurrent[i];
1131     }
1132     this->Renderer->WorldToView(fLocalExtents[0], fLocalExtents[2], fLocalExtents[4]);
1133     this->Renderer->WorldToView(fLocalExtents[1], fLocalExtents[3], fLocalExtents[5]);
1134     for(int i=0; i<3; i++)
1135     {
1136         if (i!=SliceOrientation) //SR: assumes that SliceOrientation is valid in ViewCoordinates (???)
1137         {
1138             fLocalExtents[i*2  ] -= 0.2;
1139             fLocalExtents[i*2+1] += 0.2;
1140         }
1141     }
1142     this->Renderer->ViewToWorld(fLocalExtents[0], fLocalExtents[2], fLocalExtents[4]);
1143     this->Renderer->ViewToWorld(fLocalExtents[1], fLocalExtents[3], fLocalExtents[5]);
1144
1145     //Convert to image pixel coordinates (rounded)
1146     int iLocalExtents[6];
1147     for(int i=0; i<3; i++)
1148     {
1149         fLocalExtents[i*2  ] = (fLocalExtents[i*2  ] - this->GetInput()->GetOrigin()[i])/this->GetInput()->GetSpacing()[i];
1150         fLocalExtents[i*2+1] = (fLocalExtents[i*2+1] - this->GetInput()->GetOrigin()[i])/this->GetInput()->GetSpacing()[i];
1151     
1152         iLocalExtents[i*2  ] = lrint(fLocalExtents[i*2  ]);
1153         iLocalExtents[i*2+1] = lrint(fLocalExtents[i*2+1]);
1154
1155         if(iLocalExtents[i*2  ]>iLocalExtents[i*2+1])
1156             std::swap(iLocalExtents[i*2], iLocalExtents[i*2+1]);
1157     }
1158     
1159     vtkSmartPointer<vtkExtractVOI> voiFilter = vtkExtractVOI::New();
1160     voiFilter->SetInput(this->GetInput());
1161     voiFilter->SetVOI(iLocalExtents);
1162
1163     vtkSmartPointer<vtkImageAccumulate> accFilter = vtkImageAccumulate::New();
1164     accFilter->SetInput(voiFilter->GetOutput());
1165     accFilter->Update();
1166    
1167     min = *(accFilter->GetMin());
1168     max = *(accFilter->GetMax());
1169 }
1170 //----------------------------------------------------------------------------
1171
1172 //----------------------------------------------------------------------------
1173 void vvSlicer::Render()
1174 {
1175   if (this->GetWindowLevel()->GetLookupTable() && !this->mOverlay && !this->mFusion)
1176     {
1177       legend->SetLookupTable(this->GetWindowLevel()->GetLookupTable());
1178       legend->SetVisibility(1);
1179     }
1180   else legend->SetVisibility(0);
1181
1182   if (ca->GetVisibility())
1183     {
1184       std::string worldPos = "";
1185       std::stringstream world1;
1186       std::stringstream world2;
1187       std::stringstream world3;
1188       world1 << (int)mCurrent[0];
1189       world2 << (int)mCurrent[1];
1190       world3 << (int)mCurrent[2];
1191       double X = (mCurrent[0] - this->GetInput()->GetOrigin()[0])/this->GetInput()->GetSpacing()[0];
1192       double Y = (mCurrent[1] - this->GetInput()->GetOrigin()[1])/this->GetInput()->GetSpacing()[1];
1193       double Z = (mCurrent[2] - this->GetInput()->GetOrigin()[2])/this->GetInput()->GetSpacing()[2];
1194
1195       if (pdmA->GetVisibility())
1196         {
1197           double x = mCursor[0];
1198           double y = mCursor[1];
1199           double z = mCursor[2];
1200           double xCursor = (x - this->GetInput()->GetOrigin()[0])/this->GetInput()->GetSpacing()[0];
1201           double yCursor = (y - this->GetInput()->GetOrigin()[1])/this->GetInput()->GetSpacing()[1];
1202           double zCursor = (z - this->GetInput()->GetOrigin()[2])/this->GetInput()->GetSpacing()[2];
1203
1204           if (xCursor >= this->GetImageActor()->GetDisplayExtent()[0] &&
1205               xCursor < this->GetImageActor()->GetDisplayExtent()[1]+1 &&
1206               yCursor >= this->GetImageActor()->GetDisplayExtent()[2] &&
1207               yCursor < this->GetImageActor()->GetDisplayExtent()[3]+1 &&
1208               zCursor >= this->GetImageActor()->GetDisplayExtent()[4] &&
1209               zCursor < this->GetImageActor()->GetDisplayExtent()[5]+1 )
1210             {
1211               vtkRenderer * renderer = this->Renderer;
1212
1213               renderer->WorldToView(x,y,z);
1214               renderer->ViewToNormalizedViewport(x,y,z);
1215               renderer->NormalizedViewportToViewport(x,y);
1216               renderer->ViewportToNormalizedDisplay(x,y);
1217               renderer->NormalizedDisplayToDisplay(x,y);
1218               crossCursor->SetFocalPoint(x,y,z);
1219             }
1220           else
1221             crossCursor->SetFocalPoint(-1,-1,z);
1222         }
1223
1224       if (X >= this->GetInput()->GetWholeExtent()[0] &&
1225           X <= this->GetInput()->GetWholeExtent()[1] &&
1226           Y >= this->GetInput()->GetWholeExtent()[2] &&
1227           Y <= this->GetInput()->GetWholeExtent()[3] &&
1228           Z >= this->GetInput()->GetWholeExtent()[4] &&
1229           Z <= this->GetInput()->GetWholeExtent()[5])
1230         {
1231           std::stringstream pixel1;
1232           std::stringstream pixel2;
1233           std::stringstream pixel3;
1234           std::stringstream temps;
1235           pixel1 << (int)X;
1236           pixel2 << (int)Y;
1237           pixel3 << (int)Z;
1238           temps << mCurrentTSlice;
1239           double value = this->GetInput()->GetScalarComponentAsDouble(
1240                                                                       (int)X,
1241                                                                       (int)Y,
1242                                                                       (int)Z,0);
1243
1244           std::stringstream val;
1245           val << value;
1246           worldPos += "data value : " + val.str();
1247           worldPos += "\n mm : " + world1.str() + " " + world2.str() + " " + 
1248             world3.str() + " " + temps.str();
1249           worldPos += "\n pixel : " + pixel1.str() + " " + pixel2.str() + " " + 
1250             pixel3.str() + " " + temps.str();
1251         }
1252       ca->SetText(1,worldPos.c_str());
1253     }
1254   if (mOverlay && mOverlayActor->GetVisibility())
1255     {
1256       mOverlayMapper->SetWindow(this->GetColorWindow());
1257       mOverlayMapper->SetLevel(this->GetColorLevel());
1258       mOverlayMapper->Update();
1259     }
1260   if (mLandMapper)
1261     UpdateLandmarks();
1262   //this->Superclass::Render();
1263   this->GetRenderWindow()->Render();
1264 }
1265 //----------------------------------------------------------------------------
1266
1267
1268 //----------------------------------------------------------------------------
1269 void vvSlicer::UpdateCursorPosition()
1270 {
1271   if (this->GetImageActor()->GetVisibility())
1272     {
1273       pdmA->SetVisibility(true);
1274       mCursor[0] = mCurrent[0];
1275       mCursor[1] = mCurrent[1];
1276       mCursor[2] = mCurrent[2];
1277       mCursor[3] = mCurrentTSlice;
1278     }
1279 }
1280 //----------------------------------------------------------------------------
1281
1282
1283 //----------------------------------------------------------------------------
1284 void vvSlicer::UpdateLandmarks()
1285 {
1286   vtkPolyData *pd = static_cast<vtkPolyData*>(mLandClipper->GetInput());
1287   if (pd->GetPoints())
1288     {
1289       mLandGlyph->SetRange(0,1);
1290       mLandGlyph->Modified();
1291       mLandGlyph->Update();
1292
1293       mClipBox->Modified();
1294       mLandClipper->Update();
1295       mLandMapper->Update();
1296     }
1297
1298 }
1299 //----------------------------------------------------------------------------
1300
1301
1302 //----------------------------------------------------------------------------
1303 void vvSlicer::SetSlice(int slice)
1304 {
1305   int *range = this->GetSliceRange();
1306   if (range)
1307     {
1308       if (slice < range[0])
1309         {
1310           slice = range[0];
1311         }
1312       else if (slice > range[1])
1313         {
1314           slice = range[1];
1315         }
1316     }
1317
1318   if (this->Slice == slice)
1319     {
1320       return;
1321     }
1322
1323   this->Slice = slice;
1324   SetContourSlice();
1325   this->Modified();
1326   this->UpdateDisplayExtent();
1327   this->Render();
1328 }
1329 //----------------------------------------------------------------------------
1330
1331
1332 //----------------------------------------------------------------------------
1333 void vvSlicer::SetContourSlice()
1334 {
1335   if (mSurfaceCutActors.size() > 0)
1336     for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
1337          i!=mSurfaceCutActors.end();i++)
1338       (*i)->SetCutSlice((this->Slice)*this->GetImage()->GetSpacing()[this->SliceOrientation]+
1339                         this->GetImage()->GetOrigin()[this->SliceOrientation]);
1340 }
1341 //----------------------------------------------------------------------------
1342
1343
1344 //----------------------------------------------------------------------------
1345 void vvSlicer::ForceUpdateDisplayExtent()
1346 {
1347   this->UpdateDisplayExtent();
1348 }
1349 //----------------------------------------------------------------------------
1350
1351
1352 //----------------------------------------------------------------------------
1353 int* vvSlicer::GetDisplayExtent()
1354 {
1355   return this->GetImageActor()->GetDisplayExtent();
1356 }
1357 //----------------------------------------------------------------------------
1358
1359
1360 //----------------------------------------------------------------------------
1361 void vvSlicer::PrintSelf(ostream& os, vtkIndent indent)
1362 {
1363   this->Superclass::PrintSelf(os, indent);
1364 }
1365 //----------------------------------------------------------------------------