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