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