]> Creatis software - clitk.git/blob - vv/vvSlicerManager.cxx
Romulo:
[clitk.git] / vv / vvSlicerManager.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
19 #include "vvSlicerManager.h"
20 #include "vvSlicer.h"
21 #include "vvImage.h"
22 #include "vvSlicerManagerCommand.h"
23 #include "vvInteractorStyleNavigator.h"
24 #include "vvLandmarks.h"
25 #include "vvMesh.h"
26 #include "vvImageMapToWLColors.h"
27 #include "vvBlendImageActor.h"
28
29 #include <vtkImageActor.h>
30 #include <vtkImageData.h>
31 #include <vtkRenderWindow.h>
32 #include <vtkRendererCollection.h>
33 #include <vtkRenderWindowInteractor.h>
34 #include <vtkImageMapToWindowLevelColors.h>
35 #include <vtkWindowLevelLookupTable.h>
36 #include <vtkColorTransferFunction.h>
37 #include <vtkImageClip.h>
38 #include <vtkLODActor.h>
39 #include <vtkPointData.h>
40 #include <vtksys/SystemTools.hxx>
41 #include <vtkCamera.h>
42
43 //----------------------------------------------------------------------------
44 vvSlicerManager::vvSlicerManager(int numberOfSlicers)
45 {
46   mFileName = "";
47   mId = "";
48   mVFName = "";
49   mOverlayName = "";
50   mFusionName = "";
51   mVFId = "";
52   mLastError = "";
53   mType = UNDEFINEDIMAGETYPE;
54   mColorMap = 0;
55   mPreset = 0;
56   mOverlayColor = 130;
57
58   mFusionOpacity = 70;
59   mFusionColorMap = 3;
60   mFusionWindow = 1000;
61   mFusionLevel = 1000;
62
63   mLandmarks = NULL;
64   mLinkedId.resize(0);
65
66   for ( int i = 0; i < numberOfSlicers; i++)
67     mSlicers.push_back(vtkSmartPointer<vvSlicer>::New());
68
69   mPreviousSlice.resize(numberOfSlicers);
70   mPreviousTSlice.resize(numberOfSlicers);
71 }
72 //----------------------------------------------------------------------------
73
74
75 //----------------------------------------------------------------------------
76 vvSlicerManager::~vvSlicerManager()
77 {
78   if (mLandmarks)
79     delete mLandmarks;
80 }
81 //----------------------------------------------------------------------------
82
83
84 //------------------------------------------------------------------------------
85 void vvSlicerManager::SetFilename(std::string filename, int number)
86 {
87   mFileName = filename;
88   mFileName = vtksys::SystemTools::GetFilenameName(mFileName);
89   mBaseFileName = vtksys::SystemTools::GetFilenameName(vtksys::SystemTools::GetFilenameWithoutLastExtension(mFileName));
90   mBaseFileNameNumber = number;
91
92   mFileName = mBaseFileName;
93   if (number != 0) {
94     mFileName.append("_"+clitk::toString(number));
95   }
96   mFileName.append(vtksys::SystemTools::GetFilenameLastExtension(filename));
97
98   for(unsigned int i=0; i<mSlicers.size(); i++) {
99     mSlicers[i]->SetFileName(mFileName);//vtksys::SystemTools::GetFilenameWithoutLastExtension(filename));
100   }
101   
102 }
103 //------------------------------------------------------------------------------
104
105
106 //----------------------------------------------------------------------------
107 void vvSlicerManager::AddContour(vvMesh::Pointer contour,bool propagate)
108 {
109   for ( unsigned int i = 0; i < mSlicers.size(); i++) {
110     mSlicers[i]->AddContour(contour,propagate);
111   }
112 }
113 //----------------------------------------------------------------------------
114
115
116 //----------------------------------------------------------------------------
117 void vvSlicerManager::ToggleContourSuperposition()
118 {
119   for ( unsigned int i = 0; i < mSlicers.size(); i++)
120     mSlicers[i]->ToggleContourSuperposition();
121 }
122 //----------------------------------------------------------------------------
123
124
125 //----------------------------------------------------------------------------
126 bool vvSlicerManager::SetImage(std::string filename, LoadedImageType type, int n, unsigned int slice)
127 {
128   mType = type;
129   if (mReader.IsNull())
130     mReader = vvImageReader::New();
131   std::vector<std::string> filenames;
132   filenames.push_back(filename);
133   mReader->SetInputFilenames(filenames);
134   mReader->SetSlice(slice); // Only used for SLICED type
135   mReader->Update(type);
136
137   SetFilename(filename, n);
138   //  mFileName = vtksys::SystemTools::GetFilenameName(mFileName);
139   //mBaseFileName = vtksys::SystemTools::GetFilenameName(vtksys::SystemTools::GetFilenameWithoutLastExtension(mFileName));
140   //mBaseFileNameNumber = n;
141
142   if (mReader->GetLastError().size() == 0) {
143     mImage=mReader->GetOutput();
144     for ( unsigned int i = 0; i < mSlicers.size(); i++) {
145       mSlicers[i]->SetFileName(vtksys::SystemTools::GetFilenameWithoutLastExtension(filename));
146       mSlicers[i]->SetImage(mReader->GetOutput());
147     }
148   } else {
149     mLastError = mReader->GetLastError();
150     return false;
151   }
152   // if (n!=0) {
153   //   mFileName.append("_"+clitk::toString(n));
154   // }
155   return true;
156 }
157 //----------------------------------------------------------------------------
158
159
160 //----------------------------------------------------------------------------
161 void vvSlicerManager::SetImage(vvImage::Pointer image)
162 {
163   mImage=image;
164   for (unsigned int i = 0; i < mSlicers.size(); i++) {
165     mSlicers[i]->SetImage(image);
166   }
167 }
168 //----------------------------------------------------------------------------
169
170
171 //----------------------------------------------------------------------------
172 bool vvSlicerManager::SetImages(std::vector<std::string> filenames,LoadedImageType type, int n)
173 {
174   mType = type;
175   std::string fileWithoutExtension = vtksys::SystemTools::GetFilenameWithoutExtension(filenames[0]);
176   if (type == DICOM)
177     fileWithoutExtension += "_dicom";
178   else if (type == MERGED)
179     fileWithoutExtension += "_merged";
180   else if (type == MERGEDWITHTIME)
181     fileWithoutExtension += "_merged_wt";
182
183   mFileName = vtksys::SystemTools::GetFilenameName(mFileName);
184   mFileName = fileWithoutExtension + vtksys::SystemTools::GetFilenameExtension(filenames[0]);
185   if (mReader.IsNull())
186     mReader = vvImageReader::New();
187   mReader->SetInputFilenames(filenames);
188   mReader->Update(type);
189
190   mBaseFileName = vtksys::SystemTools::GetFilenameName(vtksys::SystemTools::GetFilenameWithoutLastExtension(mFileName));
191   mBaseFileNameNumber = n;
192
193   if (mReader->GetLastError().size() == 0) {
194     mImage=mReader->GetOutput();
195     for ( unsigned int i = 0; i < mSlicers.size(); i++) {
196       mSlicers[i]->SetFileName(fileWithoutExtension);
197       mSlicers[i]->SetImage(mReader->GetOutput());
198     }
199   } else {
200     mLastError = mReader->GetLastError();
201     return false;
202   }
203   if (n!=0) {
204     mFileName.append("_"+clitk::toString(n));
205   }
206   return true;
207 }
208 //----------------------------------------------------------------------------
209
210
211 //----------------------------------------------------------------------------
212 bool vvSlicerManager::SetOverlay(std::string filename,int dim, std::string component)
213 {
214   mOverlayName = filename;
215   mOverlayComponent = component;
216   if (dim > mImage->GetNumberOfDimensions()) {
217     mLastError = " Overlay dimension cannot be greater then reference image!";
218     return false;
219   }
220   if (mOverlayReader.IsNull())
221     mOverlayReader = vvImageReader::New();
222   std::vector<std::string> filenames;
223   filenames.push_back(filename);
224   mOverlayReader->SetInputFilenames(filenames);
225   mOverlayReader->Update(mImage->GetNumberOfDimensions(),component.c_str(),mType);
226   if (mOverlayReader->GetLastError().size() == 0) {
227     for ( unsigned int i = 0; i < mSlicers.size(); i++) {
228       mSlicers[i]->SetOverlay(mOverlayReader->GetOutput());
229     }
230   } else {
231     mLastError = mOverlayReader->GetLastError();
232     return false;
233   }
234   return true;
235 }
236 //----------------------------------------------------------------------------
237
238
239 //----------------------------------------------------------------------------
240 bool vvSlicerManager::SetFusion(std::string filename,int dim, std::string component)
241 {
242   mFusionName = filename;
243   mFusionComponent = component;
244   if (dim > mImage->GetNumberOfDimensions()) {
245     mLastError = " Overlay dimension cannot be greater then reference image!";
246     return false;
247   }
248   if (mFusionReader.IsNull())
249     mFusionReader = vvImageReader::New();
250   std::vector<std::string> filenames;
251   filenames.push_back(filename);
252   mFusionReader->SetInputFilenames(filenames);
253   mFusionReader->Update(mImage->GetNumberOfDimensions(),component.c_str(),mType);
254   if (mFusionReader->GetLastError().size() == 0) {
255     for ( unsigned int i = 0; i < mSlicers.size(); i++) {
256       mSlicers[i]->SetFusion(mFusionReader->GetOutput());
257     }
258   } else {
259     mLastError = mFusionReader->GetLastError();
260     return false;
261   }
262   double *fusRange = mFusionReader->GetOutput()->GetVTKImages()[0]->GetScalarRange();
263   mFusionLevel = (fusRange[0]+fusRange[1])/2;
264   mFusionWindow = fusRange[1]-fusRange[0];
265   return true;
266 }
267 //----------------------------------------------------------------------------
268
269
270 //----------------------------------------------------------------------------
271 bool vvSlicerManager::SetVF(std::string filename)
272 {
273   if (mVectorReader.IsNull())
274     mVectorReader = vvImageReader::New();
275   mVectorReader->SetInputFilename(filename);
276   mVectorReader->Update(VECTORFIELD);
277   if (mVectorReader->GetLastError().size() != 0) {
278     mLastError = mVectorReader->GetLastError();
279     return false;
280   } else
281     return SetVF(mVectorReader->GetOutput(),filename);
282 }
283 //----------------------------------------------------------------------------
284
285
286 //----------------------------------------------------------------------------
287 bool vvSlicerManager::SetVF(vvImage::Pointer vf,std::string filename)
288 {
289   if (vf->GetNumberOfDimensions() > mImage->GetNumberOfDimensions()) {
290     mLastError = "Sorry, vector field dimension cannot be greater then reference image.";
291     return false;
292   }
293   if (vf->GetNumberOfDimensions() == 4) {
294     if (vf->GetSpacing()[3] != mImage->GetSpacing()[3]) {
295       mLastError = "Sorry, vector field time spacing cannot be different from time spacing of the reference image.";
296       return false;
297     }
298     if (vf->GetOrigin()[3] != mImage->GetOrigin()[3]) {
299       mLastError = "Sorry, vector field time origin cannot be different from time origin of the reference image.";
300       return false;
301     }
302   }
303   mVF=vf;
304   mVFName = filename;
305   for ( unsigned int i = 0; i < mSlicers.size(); i++) {
306     mSlicers[i]->SetVF(vf);
307   }
308   return true;
309 }
310 //----------------------------------------------------------------------------
311
312
313 //----------------------------------------------------------------------------
314 vvSlicer* vvSlicerManager::GetSlicer(int i)
315 {
316   return mSlicers[i];
317 }
318 //----------------------------------------------------------------------------
319
320
321 //----------------------------------------------------------------------------
322 void vvSlicerManager::UpdateSlicer(int num, bool state)
323 {
324   if (mSlicers[num]->GetImage())
325     mSlicers[num]->SetDisplayMode(state);
326 }
327 //----------------------------------------------------------------------------
328
329
330 //----------------------------------------------------------------------------
331 void vvSlicerManager::SetSlicerWindow(int i, vtkRenderWindow* RW)
332 {
333   mSlicers[i]->SetRenderWindow(i,RW);
334 }
335 //----------------------------------------------------------------------------
336
337
338 //----------------------------------------------------------------------------
339 void vvSlicerManager::SetInteractorStyleNavigator(int i, vtkInteractorStyle* style)
340 {
341   vvSlicerManagerCommand *smc = vvSlicerManagerCommand::New();
342   smc->SM = this;
343   smc->SetSlicerNumber(i);
344   mSlicers[i]->GetRenderWindow()->GetInteractor()->SetInteractorStyle(style);
345
346   mSlicers[i]->GetRenderWindow()->GetInteractor()->
347     GetInteractorStyle()->AddObserver(vtkCommand::KeyPressEvent, smc);
348   mSlicers[i]->GetRenderWindow()->GetInteractor()->
349     GetInteractorStyle()->AddObserver(vtkCommand::WindowLevelEvent, smc);
350   mSlicers[i]->GetRenderWindow()->GetInteractor()->
351     GetInteractorStyle()->AddObserver(vtkCommand::EndWindowLevelEvent, smc);
352   mSlicers[i]->GetRenderWindow()->GetInteractor()->
353     GetInteractorStyle()->AddObserver(vtkCommand::StartWindowLevelEvent, smc);
354   mSlicers[i]->GetRenderWindow()->GetInteractor()->
355     GetInteractorStyle()->AddObserver(vtkCommand::PickEvent, smc);
356   mSlicers[i]->GetRenderWindow()->GetInteractor()->
357     GetInteractorStyle()->AddObserver(vtkCommand::StartPickEvent, smc);
358   mSlicers[i]->GetRenderWindow()->GetInteractor()->
359     GetInteractorStyle()->AddObserver(vtkCommand::LeaveEvent, smc);
360   mSlicers[i]->GetRenderWindow()->GetInteractor()->
361     GetInteractorStyle()->AddObserver(vtkCommand::UserEvent, smc);
362   mSlicers[i]->GetRenderWindow()->GetInteractor()->
363     GetInteractorStyle()->AddObserver(vtkCommand::MouseWheelForwardEvent, smc);
364   mSlicers[i]->GetRenderWindow()->GetInteractor()->
365     GetInteractorStyle()->AddObserver(vtkCommand::MouseWheelBackwardEvent, smc);
366   // mSlicers[i]->GetRenderWindow()->GetInteractor()->
367   //   GetInteractorStyle()->AddObserver(vtkCommand::LeftButtonReleaseEvent, smc);
368   mSlicers[i]->GetRenderWindow()->GetInteractor()->
369     GetInteractorStyle()->AddObserver(vtkCommand::EndPickEvent, smc);
370   mSlicers[i]->GetRenderWindow()->GetInteractor()->
371     GetInteractorStyle()->AddObserver(vtkCommand::EndInteractionEvent, smc);
372   smc->Delete();
373 }
374 //----------------------------------------------------------------------------
375
376
377 //----------------------------------------------------------------------------
378 void vvSlicerManager::LeftButtonReleaseEvent(int slicer)
379 {
380   emit LeftButtonReleaseSignal(slicer);
381 }
382 //----------------------------------------------------------------------------
383
384
385 //----------------------------------------------------------------------------
386 void vvSlicerManager::SetTSlice(int slice)
387 {
388   if (slice < 0)
389     slice = 0;
390   else if (slice > mSlicers[0]->GetTMax())
391     slice = mSlicers[0]->GetTMax();
392   if (mLandmarks)
393     mLandmarks->SetTime(slice);
394   for ( unsigned int i = 0; i < mSlicers.size(); i++) {
395     if (slice != mSlicers[i]->GetTSlice()) {
396       mSlicers[i]->SetTSlice(slice);
397       if (mSlicers[i]->GetImageActor()->GetVisibility())
398         UpdateTSlice(i);
399     }
400   }
401 }
402 //----------------------------------------------------------------------------
403
404
405 //----------------------------------------------------------------------------
406 void vvSlicerManager::SetNextTSlice(int originating_slicer)
407 {
408   int t = mSlicers[0]->GetTSlice();
409   t++;
410   if (t > mSlicers[0]->GetTMax())
411     t = 0;
412   emit UpdateTSlice(originating_slicer,t);
413 }
414 //----------------------------------------------------------------------------
415
416
417 //----------------------------------------------------------------------------
418 void vvSlicerManager::SetPreviousTSlice(int originating_slicer)
419 {
420   int t = mSlicers[0]->GetTSlice();
421   t--;
422   if (t < 0)
423     t = mSlicers[0]->GetTMax();
424   emit UpdateTSlice(originating_slicer,t);
425 }
426 //----------------------------------------------------------------------------
427
428
429 //----------------------------------------------------------------------------
430 void vvSlicerManager::ToggleInterpolation()
431 {
432   bool interpolate=!(mSlicers[0]->GetImageActor()->GetInterpolate());
433   for ( unsigned int i = 0; i < mSlicers.size(); i++) {
434     mSlicers[i]->GetImageActor()->SetInterpolate(interpolate);
435     if (mSlicers[i]->GetOverlayActor())
436       mSlicers[i]->GetOverlayActor()->SetInterpolate(interpolate);
437     if (mSlicers[i]->GetFusionActor())
438       mSlicers[i]->GetFusionActor()->SetInterpolate(interpolate);
439   }
440 }
441 //----------------------------------------------------------------------------
442
443
444 //----------------------------------------------------------------------------
445 void vvSlicerManager::SetTSliceInSlicer(int tslice, int slicer)
446 {
447   if (tslice < 0)
448     tslice = 0;
449   else if (tslice > mSlicers[slicer]->GetTMax())
450     tslice = mSlicers[slicer]->GetTMax();
451   if (mLandmarks)
452     mLandmarks->SetTime(tslice);
453
454   if (mSlicers[slicer]->GetTSlice() == tslice) return;
455
456   mSlicers[slicer]->SetTSlice(tslice);
457   if (mSlicers[slicer]->GetImageActor()->GetVisibility())
458     UpdateTSlice(slicer);
459 }
460 //----------------------------------------------------------------------------
461
462
463 //----------------------------------------------------------------------------
464 void vvSlicerManager::SetColorWindow(double s)
465 {
466   for ( unsigned int i = 0; i < mSlicers.size(); i++) {
467     mSlicers[i]->SetColorWindow(s);
468   }
469 }
470 //----------------------------------------------------------------------------
471
472
473 //----------------------------------------------------------------------------
474 void vvSlicerManager::SetColorLevel(double s)
475 {
476   for ( unsigned int i = 0; i < mSlicers.size(); i++) {
477     mSlicers[i]->SetColorLevel(s);
478   }
479 }
480 //----------------------------------------------------------------------------
481
482 //----------------------------------------------------------------------------
483 void vvSlicerManager::SetCursorAndCornerAnnotationVisibility(int s)
484 {
485   for ( unsigned int i = 0; i < mSlicers.size(); i++) {
486     mSlicers[i]->SetCursorVisibility(s);
487     mSlicers[i]->SetCornerAnnotationVisibility(s);
488   }
489 }
490 //----------------------------------------------------------------------------
491
492 //----------------------------------------------------------------------------
493 void vvSlicerManager::SetOpacity(int i, double factor)
494 {
495   mSlicers[i]->SetOpacity(1/factor);
496 }
497 //----------------------------------------------------------------------------
498
499
500 //----------------------------------------------------------------------------
501 void vvSlicerManager::UpdateViews(int current,int slicer)
502 {
503   double x = (mSlicers[slicer]->GetCurrentPosition()[0] - mSlicers[slicer]->GetInput()->GetOrigin()[0])
504     /mSlicers[slicer]->GetInput()->GetSpacing()[0];
505   double y = (mSlicers[slicer]->GetCurrentPosition()[1] - mSlicers[slicer]->GetInput()->GetOrigin()[1])
506     /mSlicers[slicer]->GetInput()->GetSpacing()[1];
507   double z = (mSlicers[slicer]->GetCurrentPosition()[2] - mSlicers[slicer]->GetInput()->GetOrigin()[2])
508     /mSlicers[slicer]->GetInput()->GetSpacing()[2];
509
510   if (x >= mSlicers[slicer]->GetInput()->GetWholeExtent()[0] &&
511       x <= mSlicers[slicer]->GetInput()->GetWholeExtent()[1] &&
512       y >= mSlicers[slicer]->GetInput()->GetWholeExtent()[2] &&
513       y <= mSlicers[slicer]->GetInput()->GetWholeExtent()[3] &&
514       z >= mSlicers[slicer]->GetInput()->GetWholeExtent()[4] &&
515       z <= mSlicers[slicer]->GetInput()->GetWholeExtent()[5]) {
516     mSlicers[slicer]->UpdateCursorPosition();
517     mSlicers[slicer]->SetCursorColor(10,212,255);
518
519     switch (mSlicers[slicer]->GetSliceOrientation()) {
520     case vtkImageViewer2::SLICE_ORIENTATION_XY:
521       if (mSlicers[slicer]->GetSlice() != (int)floor(z))
522         mSlicers[slicer]->SetSlice((int)floor(z));
523       break;
524
525     case vtkImageViewer2::SLICE_ORIENTATION_XZ:
526       if (mSlicers[slicer]->GetSlice() != (int)floor(y))
527         mSlicers[slicer]->SetSlice((int)floor(y));
528       break;
529
530     case vtkImageViewer2::SLICE_ORIENTATION_YZ:
531       if (mSlicers[slicer]->GetSlice() != (int)floor(x))
532         mSlicers[slicer]->SetSlice((int)floor(x));
533       break;
534     }
535     mSlicers[slicer]->Render();
536
537     for ( unsigned int i = 0; i < mSlicers.size(); i++) {
538       if (i != (unsigned int)slicer && mSlicers[i]->GetImageActor()->GetVisibility()
539           && mSlicers[i]->GetRenderWindow()->GetSize()[0] > 2
540           && mSlicers[i]->GetRenderWindow()->GetSize()[1] > 2) {
541         mSlicers[i]->SetCurrentPosition(mSlicers[slicer]->GetCurrentPosition()[0],
542                                         mSlicers[slicer]->GetCurrentPosition()[1],
543                                         mSlicers[slicer]->GetCurrentPosition()[2],
544                                         mSlicers[slicer]->GetTSlice());
545         mSlicers[i]->UpdateCursorPosition();
546         if (current) { //do not display corner annotation if image is the one picked
547           mSlicers[i]->SetCurrentPosition(-VTK_DOUBLE_MAX,-VTK_DOUBLE_MAX,
548                                           -VTK_DOUBLE_MAX, mSlicers[slicer]->GetTSlice());
549           mSlicers[i]->SetCursorColor(255,10,212);
550         } else {
551           mSlicers[i]->SetCursorColor(150,10,282);
552         }
553         switch (mSlicers[i]->GetSliceOrientation()) {
554         case vtkImageViewer2::SLICE_ORIENTATION_XY:
555           if (mSlicers[i]->GetSlice() != (int)floor(z))
556             mSlicers[i]->SetSlice((int)floor(z));
557           break;
558
559         case vtkImageViewer2::SLICE_ORIENTATION_XZ:
560           if (mSlicers[i]->GetSlice() != (int)floor(y))
561             mSlicers[i]->SetSlice((int)floor(y));
562           break;
563
564         case vtkImageViewer2::SLICE_ORIENTATION_YZ:
565           if (mSlicers[i]->GetSlice() != (int)floor(x))
566             mSlicers[i]->SetSlice((int)floor(x));
567           break;
568         }
569         
570         mSlicers[i]->Render();
571         
572         UpdateSlice(i);
573         UpdateTSlice(i);
574       }
575     }
576   }
577 }
578 //----------------------------------------------------------------------------
579
580
581 //----------------------------------------------------------------------------
582 void vvSlicerManager::UpdateLinked(int slicer)
583 {
584   double x = (mSlicers[slicer]->GetCurrentPosition()[0] - mSlicers[slicer]->GetInput()->GetOrigin()[0])
585     /mSlicers[slicer]->GetInput()->GetSpacing()[0];
586   double y = (mSlicers[slicer]->GetCurrentPosition()[1] - mSlicers[slicer]->GetInput()->GetOrigin()[1])
587     /mSlicers[slicer]->GetInput()->GetSpacing()[1];
588   double z = (mSlicers[slicer]->GetCurrentPosition()[2] - mSlicers[slicer]->GetInput()->GetOrigin()[2])
589     /mSlicers[slicer]->GetInput()->GetSpacing()[2];
590
591   if (x >= mSlicers[slicer]->GetInput()->GetWholeExtent()[0] &&
592       x <= mSlicers[slicer]->GetInput()->GetWholeExtent()[1] &&
593       y >= mSlicers[slicer]->GetInput()->GetWholeExtent()[2] &&
594       y <= mSlicers[slicer]->GetInput()->GetWholeExtent()[3] &&
595       z >= mSlicers[slicer]->GetInput()->GetWholeExtent()[4] &&
596       z <= mSlicers[slicer]->GetInput()->GetWholeExtent()[5]) {
597     for (std::list<std::string>::const_iterator i = mLinkedId.begin(); i != mLinkedId.end(); i++) {
598       emit UpdateLinkManager(*i, slicer,mSlicers[slicer]->GetCurrentPosition()[0],
599                              mSlicers[slicer]->GetCurrentPosition()[1],
600                              mSlicers[slicer]->GetCurrentPosition()[2],mSlicers[slicer]->GetTSlice());
601     }
602   }
603 }
604 //----------------------------------------------------------------------------
605
606 //----------------------------------------------------------------------------
607 void vvSlicerManager::UpdateLinkedNavigation(vvSlicer *refSlicer, bool bPropagate)
608 {
609   vtkCamera *refCam = refSlicer->GetRenderer()->GetActiveCamera();
610   double refPosition[3], refFocal[3];
611   refCam->GetPosition(refPosition);
612   refCam->GetFocalPoint(refFocal);
613   
614   for ( unsigned int i = 0; i < mSlicers.size(); i++) {
615     vtkCamera *camera = mSlicers[i]->GetRenderer()->GetActiveCamera();
616     camera->SetParallelScale(refCam->GetParallelScale());
617
618     double position[3], focal[3];
619     camera->GetPosition(position);
620     camera->GetFocalPoint(focal);
621
622     if(refSlicer->GetSliceOrientation()==mSlicers[i]->GetSliceOrientation()) {
623       for(int i=0; i<3; i++) {
624         position[i] = refPosition[i];
625         focal[i]    = refFocal[i];
626       }
627     }
628
629     if(refSlicer->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_XY) {
630       if(mSlicers[i]->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_XZ) {
631         position[0] = refPosition[0];
632         focal[0]    = refFocal[0];
633       }
634       if(mSlicers[i]->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_YZ) {
635         position[1] = refPosition[1];
636         focal[1]    = refFocal[1];
637       }
638     }
639
640     if(refSlicer->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_XZ) {
641       if(mSlicers[i]->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_YZ) {
642         position[2] = refPosition[2];
643         focal[2]    = refFocal[2];
644       }
645       if(mSlicers[i]->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_XY) {
646         position[0] = refPosition[0];
647         focal[0]    = refFocal[0];
648       }
649     }
650
651     if(refSlicer->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_YZ) {
652       if(mSlicers[i]->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_XY) {
653         position[1] = refPosition[1];
654         focal[1]    = refFocal[1];
655       }
656       if(mSlicers[i]->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_XZ) {
657         position[2] = refPosition[2];
658         focal[2]    = refFocal[2];
659       }
660     }
661
662     camera->SetFocalPoint(focal);
663     camera->SetPosition(position);
664   
665     //Fix for bug #243
666     mSlicers[i]->ForceUpdateDisplayExtent();
667   }
668   
669   Render();
670   if(bPropagate)
671     for (std::list<std::string>::const_iterator i = mLinkedId.begin(); i != mLinkedId.end(); i++)
672       emit UpdateLinkedNavigation(*i, this, refSlicer);
673 }
674 //----------------------------------------------------------------------------
675
676 //----------------------------------------------------------------------------
677 double vvSlicerManager::GetColorWindow()
678 {
679   if (mSlicers.size())
680     return mSlicers[0]->GetColorWindow();
681   return -1;
682 }
683 //----------------------------------------------------------------------------
684
685
686 //----------------------------------------------------------------------------
687 double vvSlicerManager::GetColorLevel()
688 {
689   if (mSlicers.size())
690     return mSlicers[0]->GetColorLevel();
691   return -1;
692 }
693 //----------------------------------------------------------------------------
694
695
696 //----------------------------------------------------------------------------
697 void vvSlicerManager::Render()
698 {
699   for ( unsigned int i = 0; i < mSlicers.size(); i++) {
700     mSlicers[i]->Render();
701   }
702 }
703 //----------------------------------------------------------------------------
704
705
706 //----------------------------------------------------------------------------
707 void vvSlicerManager::GenerateDefaultLookupTable()
708 {
709   SetPreset(mPreset);
710   SetColorMap(mColorMap);
711 }
712 //----------------------------------------------------------------------------
713
714
715 //----------------------------------------------------------------------------
716 void vvSlicerManager::Reload()
717 {
718   mReader->Update(mType);
719   mImage=mReader->GetOutput();
720   for ( unsigned int i = 0; i < mSlicers.size(); i++) {
721     mSlicers[i]->SetImage(mImage);
722   }
723 }
724 //----------------------------------------------------------------------------
725
726
727 //----------------------------------------------------------------------------
728 void vvSlicerManager::ReloadFusion()
729 {
730   mFusionReader->Update();
731   for ( unsigned int i = 0; i < mSlicers.size(); i++) {
732     mSlicers[i]->SetFusion(mFusionReader->GetOutput());
733     mSlicers[i]->Render();
734   }
735 }
736 //----------------------------------------------------------------------------
737
738
739 //----------------------------------------------------------------------------
740 void vvSlicerManager::ReloadOverlay()
741 {
742   mOverlayReader->Update();
743   for ( unsigned int i = 0; i < mSlicers.size(); i++) {
744     mSlicers[i]->SetOverlay(mOverlayReader->GetOutput());
745     mSlicers[i]->Render();
746   }
747 }
748 //----------------------------------------------------------------------------
749
750
751 //----------------------------------------------------------------------------
752 void vvSlicerManager::ReloadVF()
753 {
754   mVectorReader->Update(VECTORFIELD); //deletes the old images through the VF::Init() function
755   mVF=mVectorReader->GetOutput();
756   for ( unsigned int i = 0; i < mSlicers.size(); i++) {
757     mSlicers[i]->SetVF(mVF);
758     mSlicers[i]->Render();
759   }
760 }
761 //----------------------------------------------------------------------------
762
763
764 //----------------------------------------------------------------------------
765 void vvSlicerManager::RemoveActor(const std::string& actor_type, int overlay_index)
766 {
767   if (actor_type =="overlay")
768     mOverlayReader = NULL;
769
770   if (actor_type =="fusion")
771     mFusionReader = NULL;
772
773   for (unsigned int i = 0; i < mSlicers.size(); i++)
774     mSlicers[i]->RemoveActor(actor_type,overlay_index);
775
776   if (actor_type=="vector") {
777     mVF=NULL;
778     mVectorReader=NULL;
779   }
780 }
781 //----------------------------------------------------------------------------
782
783
784 //----------------------------------------------------------------------------
785 void vvSlicerManager::RemoveActors()
786 {
787   ///This method leaks a few objects. See RemoveActor for what a
788   ///correct implementation would look like
789   //DS -> probably due to the reader (now released in the
790   //RemoveActor() function. (I hope)
791   for ( unsigned int i = 0; i < mSlicers.size(); i++) {
792     mSlicers[i]->SetDisplayMode(0);
793     mSlicers[i]->GetRenderer()->RemoveActor(mSlicers[i]->GetImageActor());
794   }
795 }
796 //----------------------------------------------------------------------------
797
798
799 //----------------------------------------------------------------------------
800 void vvSlicerManager::UpdateInfoOnCursorPosition(int slicer)
801 {
802   //  int view = mSlicers[slicer]->GetSliceOrientation();
803   //  int slice = mSlicers[slicer]->GetSlice();
804   double x = mSlicers[slicer]->GetCursorPosition()[0];
805   double y = mSlicers[slicer]->GetCursorPosition()[1];
806   double z = mSlicers[slicer]->GetCursorPosition()[2];
807   double X = (x - mSlicers[slicer]->GetInput()->GetOrigin()[0])/
808     mSlicers[slicer]->GetInput()->GetSpacing()[0];
809   double Y = (y - mSlicers[slicer]->GetInput()->GetOrigin()[1])/
810     mSlicers[slicer]->GetInput()->GetSpacing()[1];
811   double Z = (z - mSlicers[slicer]->GetInput()->GetOrigin()[2])/
812     mSlicers[slicer]->GetInput()->GetSpacing()[2];
813   double value = -VTK_DOUBLE_MAX;
814   int displayVec = 0;
815   double xVec=0, yVec=0, zVec=0, valueVec=0;
816   int displayOver = 0;
817   int displayFus = 0;
818   double valueOver=0, valueFus=0;
819   if (X >= mSlicers[slicer]->GetInput()->GetWholeExtent()[0] &&
820       X <= mSlicers[slicer]->GetInput()->GetWholeExtent()[1] &&
821       Y >= mSlicers[slicer]->GetInput()->GetWholeExtent()[2] &&
822       Y <= mSlicers[slicer]->GetInput()->GetWholeExtent()[3] &&
823       Z >= mSlicers[slicer]->GetInput()->GetWholeExtent()[4] &&
824       Z <= mSlicers[slicer]->GetInput()->GetWholeExtent()[5]) {
825     value = this->GetScalarComponentAsDouble(mSlicers[slicer]->GetInput(), X, Y, Z);
826
827     if (mSlicers[slicer]->GetVFActor() && mSlicers[slicer]->GetVFActor()->GetVisibility()) {
828       displayVec = 1;
829       unsigned int currentTime = mSlicers[slicer]->GetTSlice();
830       vtkImageData *vf = NULL;
831
832       if (mSlicers[slicer]->GetVF()->GetVTKImages().size() > currentTime)
833         vf = mSlicers[slicer]->GetVF()->GetVTKImages()[currentTime];
834       else
835         vf = mSlicers[slicer]->GetVF()->GetVTKImages()[0];
836
837       if (vf) {
838         double Xvf = (x - vf->GetOrigin()[0])/ vf->GetSpacing()[0];
839         double Yvf = (y - vf->GetOrigin()[1])/ vf->GetSpacing()[1];
840         double Zvf = (z - vf->GetOrigin()[2])/ vf->GetSpacing()[2];
841         xVec = this->GetScalarComponentAsDouble( vf, Xvf, Yvf, Zvf, 0);
842         yVec = this->GetScalarComponentAsDouble( vf, Xvf, Yvf, Zvf, 1);
843         zVec = this->GetScalarComponentAsDouble( vf, Xvf, Yvf, Zvf, 2);
844         valueVec = sqrt(xVec*xVec + yVec*yVec + zVec*zVec);
845       }
846     }
847     if (mSlicers[slicer]->GetOverlayActor() && mSlicers[slicer]->GetOverlayActor()->GetVisibility()) {
848       displayOver = 1;
849       double Xover = (x - mSlicers[slicer]->GetOverlay()->GetOrigin()[0])
850         /mSlicers[slicer]->GetOverlay()->GetSpacing()[0];
851       double Yover = (y - mSlicers[slicer]->GetOverlay()->GetOrigin()[1])
852         /mSlicers[slicer]->GetOverlay()->GetSpacing()[1];
853       double Zover = (z - mSlicers[slicer]->GetOverlay()->GetOrigin()[2])
854         /mSlicers[slicer]->GetOverlay()->GetSpacing()[2];
855       if (Xover >= mSlicers[slicer]->GetOverlayMapper()->GetInput()->GetWholeExtent()[0] &&
856           Xover <= mSlicers[slicer]->GetOverlayMapper()->GetInput()->GetWholeExtent()[1] &&
857           Yover >= mSlicers[slicer]->GetOverlayMapper()->GetInput()->GetWholeExtent()[2] &&
858           Yover <= mSlicers[slicer]->GetOverlayMapper()->GetInput()->GetWholeExtent()[3] &&
859           Zover >= mSlicers[slicer]->GetOverlayMapper()->GetInput()->GetWholeExtent()[4] &&
860           Zover <= mSlicers[slicer]->GetOverlayMapper()->GetInput()->GetWholeExtent()[5]) {
861         valueOver = this->GetScalarComponentAsDouble(static_cast<vtkImageData*>(mSlicers[slicer]->GetOverlayMapper()->GetInput()), Xover, Yover, Zover);
862       }
863     }
864     if (mSlicers[slicer]->GetFusionActor() && mSlicers[slicer]->GetFusionActor()->GetVisibility()) {
865       displayFus = 1;
866       double Xfus = (x - mSlicers[slicer]->GetFusion()->GetOrigin()[0])
867         /mSlicers[slicer]->GetFusion()->GetSpacing()[0];
868       double Yfus = (y - mSlicers[slicer]->GetFusion()->GetOrigin()[1])
869         /mSlicers[slicer]->GetFusion()->GetSpacing()[1];
870       double Zfus = (z - mSlicers[slicer]->GetFusion()->GetOrigin()[2])
871         /mSlicers[slicer]->GetFusion()->GetSpacing()[2];
872       if (Xfus >= mSlicers[slicer]->GetFusionMapper()->GetInput()->GetWholeExtent()[0] &&
873           Xfus <= mSlicers[slicer]->GetFusionMapper()->GetInput()->GetWholeExtent()[1] &&
874           Yfus >= mSlicers[slicer]->GetFusionMapper()->GetInput()->GetWholeExtent()[2] &&
875           Yfus <= mSlicers[slicer]->GetFusionMapper()->GetInput()->GetWholeExtent()[3] &&
876           Zfus >= mSlicers[slicer]->GetFusionMapper()->GetInput()->GetWholeExtent()[4] &&
877           Zfus <= mSlicers[slicer]->GetFusionMapper()->GetInput()->GetWholeExtent()[5]) {
878         valueFus = this->GetScalarComponentAsDouble(static_cast<vtkImageData*>(mSlicers[slicer]->GetFusionMapper()->GetInput()), Xfus, Yfus, Zfus);
879       }
880     }
881     emit UpdatePosition(mSlicers[slicer]->GetCursorVisibility(),
882                         x,y,z,X,Y,Z,value);
883     emit UpdateVector(displayVec,xVec, yVec, zVec, valueVec);
884     emit UpdateOverlay(displayOver,valueOver,value);
885     emit UpdateFusion(displayFus,valueFus);
886     for (unsigned int i = 0; i < mSlicers.size(); i++) {
887       if (mSlicers[i]->GetImageActor()->GetVisibility() == 1)
888         emit UpdateWindows(i,mSlicers[i]->GetSliceOrientation(),mSlicers[i]->GetSlice());
889       else
890         emit UpdateWindows(i,-1,-1);
891     }
892   }
893 }
894 //----------------------------------------------------------------------------
895
896
897 //----------------------------------------------------------------------------
898 void vvSlicerManager::Activated()
899 {
900   emit currentImageChanged(mId);
901 }
902 //----------------------------------------------------------------------------
903
904
905 //----------------------------------------------------------------------------
906 void vvSlicerManager::Picked()
907 {
908   emit currentPickedImageChanged(mId);
909 }
910 //----------------------------------------------------------------------------
911
912 //----------------------------------------------------------------------------
913 void vvSlicerManager::UpdateWindowLevel()
914 {
915   emit WindowLevelChanged(mSlicers[0]->GetColorWindow(),mSlicers[0]->GetColorLevel(),mPreset,mColorMap);
916 }
917 //----------------------------------------------------------------------------
918
919
920 //----------------------------------------------------------------------------
921 void vvSlicerManager::UpdateSlice(int slicer)
922 {
923   if (mPreviousSlice[slicer] == mSlicers[slicer]->GetSlice()) {
924     //DD("============= NOTHING");
925     return;
926   }
927   emit UpdateSlice(slicer, mSlicers[slicer]->GetSlice());
928   mSlicers[slicer]->Render(); // DS <-- I add this, this could/must be the only Render ...
929   mPreviousSlice[slicer] = mSlicers[slicer]->GetSlice();
930 }
931 //----------------------------------------------------------------------------
932
933
934 //----------------------------------------------------------------------------
935 void vvSlicerManager::UpdateTSlice(int slicer)
936 {
937   if (mPreviousSlice[slicer] == mSlicers[slicer]->GetSlice()) {
938     if (mPreviousTSlice[slicer] == mSlicers[slicer]->GetTSlice()) {
939       //      DD("************** NOTHING ***********");
940       return;
941     }
942   }
943   mPreviousSlice[slicer] = mSlicers[slicer]->GetSlice();
944   mPreviousTSlice[slicer] = mSlicers[slicer]->GetTSlice();
945   emit UpdateTSlice(slicer,mSlicers[slicer]->GetTSlice());
946 }
947 //----------------------------------------------------------------------------
948
949
950 //----------------------------------------------------------------------------
951 void vvSlicerManager::UpdateSliceRange(int slicer)
952 {
953   emit UpdateSliceRange(slicer,
954                         mSlicers[slicer]->GetSliceRange()[0], mSlicers[slicer]->GetSliceRange()[1],
955                         0,mSlicers[slicer]->GetTMax());
956 }
957 //----------------------------------------------------------------------------
958
959
960 //----------------------------------------------------------------------------
961 void vvSlicerManager::SetPreset(int preset)
962 {
963   //vtkLookupTable* LUT = static_cast<vtkLookupTable*>(mSlicers[0]->GetWindowLevel()->GetLookupTable());
964   double window = mSlicers[0]->GetColorWindow();
965   double level = mSlicers[0]->GetColorLevel();
966
967   std::string component_type=mImage->GetScalarTypeAsITKString();
968   switch (preset) {
969   case 0:
970     double range[2];
971     mImage->GetScalarRange(range);
972     window = range[1] - range[0];
973     level = (range[1] + range[0])* 0.5;
974     break;
975   case 1:
976     window = 2000;
977     level = 0;
978     break;
979   case 2:
980     window = 400;
981     level = 20;
982     break;
983   case 3:
984     window = 1500;
985     level = -500;
986     break;
987   case 4:
988     window = 1000;
989     level = 500;
990     break;
991   case 5:
992     window = 1;
993     level = 0.5;
994     break;
995   case 6:
996     break;
997   case 7:
998     window=1.;
999     level=0.;
1000     break;
1001   }
1002   mPreset = preset;
1003   this->SetColorWindow(window);
1004   this->SetColorLevel(level);
1005
1006   //if (LUT)
1007   //{
1008   //    SetColorMap(-1);
1009   //}
1010 }
1011 //----------------------------------------------------------------------------
1012
1013
1014 //----------------------------------------------------------------------------
1015 void vvSlicerManager::SetLocalColorWindowing(const int slicer)
1016 {
1017   double min, max;
1018   this->mSlicers[slicer]->GetExtremasAroundMousePointer(min, max);
1019   this->SetColorWindow(max-min);
1020   this->SetColorLevel(0.5*(min+max));
1021   this->UpdateWindowLevel();
1022   this->Render();
1023 }
1024 //----------------------------------------------------------------------------
1025
1026
1027 //----------------------------------------------------------------------------
1028 void vvSlicerManager::SetColorMap()
1029 {
1030   SetColorMap(mColorMap);
1031 }
1032 //----------------------------------------------------------------------------
1033
1034
1035 //----------------------------------------------------------------------------
1036 void vvSlicerManager::SetColorMap(int colormap)
1037 {
1038   double range[2];
1039   range[0] = mSlicers[0]->GetInput()->GetScalarRange()[0];
1040   range[1] = mSlicers[0]->GetInput()->GetScalarRange()[1];
1041
1042   double window = mSlicers[0]->GetWindowLevel()->GetWindow();
1043   double level = mSlicers[0]->GetWindowLevel()->GetLevel();
1044
1045   vtkLookupTable* LUT = static_cast<vtkLookupTable*>(mSlicers[0]->GetWindowLevel()->GetLookupTable());
1046   switch (colormap) {
1047   case -1:
1048     break;
1049   case 0:
1050     LUT = NULL;
1051     break;
1052   case 1:
1053     if (LUT == NULL)
1054       LUT = vtkLookupTable::New();
1055     LUT->SetValueRange(0,1);
1056     LUT->SetSaturationRange(1,1);
1057     LUT->SetHueRange(0,0.18);
1058     break;
1059   case 2:
1060     if (LUT == NULL)
1061       LUT = vtkLookupTable::New();
1062     LUT->SetValueRange(0,1);
1063     LUT->SetSaturationRange(1,1);
1064     LUT->SetHueRange(0.4,0.80);
1065     break;
1066   case 3:
1067     if (LUT == NULL)
1068       LUT = vtkLookupTable::New();
1069     LUT->SetValueRange(0,1);
1070     LUT->SetSaturationRange(1,1);
1071     LUT->SetHueRange(0,1);
1072     break;
1073   case 5:
1074     if (LUT == NULL)
1075       LUT = vtkLookupTable::New();
1076     LUT->SetValueRange(0.,1);
1077     LUT->SetSaturationRange(1,1);
1078     LUT->SetHueRange(1,0.1);
1079     //LUT->SetRampToLinear();
1080     break;
1081   }
1082   if (LUT) {
1083     LUT->SetTableRange(level-fabs(window)/4,level+fabs(window)/4);
1084     LUT->Build();
1085   }
1086   vtkLookupTable* fusLUT = NULL;
1087   if (mSlicers[0]->GetFusion()) {
1088     fusLUT = vtkLookupTable::New();
1089     double fusRange [2];
1090     fusRange[0] = mFusionLevel - mFusionWindow/2;
1091     fusRange[1] = mFusionLevel + mFusionWindow/2;
1092     fusLUT->SetTableRange(fusRange[0],fusRange[1]);
1093     fusLUT->SetValueRange(1,1);
1094     fusLUT->SetSaturationRange(1,1);
1095     if (mFusionColorMap == 1)
1096       fusLUT->SetHueRange(0,0.18);
1097     else if (mFusionColorMap == 2)
1098       fusLUT->SetHueRange(0.4,0.80);
1099     else if (mFusionColorMap == 3)
1100       fusLUT->SetHueRange(0,1);
1101     fusLUT->Build();
1102     if (mFusionColorMap == 0)
1103       fusLUT = NULL;
1104   }
1105   for ( unsigned int i = 0; i < mSlicers.size(); i++) {
1106     if (mSlicers[i]->GetOverlay() && mSlicers[i]->GetOverlayActor()->GetVisibility()) {
1107       vtkLookupTable* supLUT = vtkLookupTable::New();
1108       supLUT->SetTableRange(range[0],range[1]);
1109       supLUT->SetValueRange(1,1);
1110       supLUT->SetSaturationRange(1,1);
1111       supLUT->SetHueRange(double(mOverlayColor)/360,double(mOverlayColor)/360);
1112       supLUT->Build();
1113       vtkLookupTable* invLUT = vtkLookupTable::New();
1114       invLUT->SetTableRange(range[0],range[1]);
1115       invLUT->SetValueRange(1,1);
1116       invLUT->SetSaturationRange(1,1);
1117       invLUT->SetHueRange(double((mOverlayColor+180)%360)/360,double((mOverlayColor+180)%360)/360);
1118       invLUT->Build();
1119       dynamic_cast<vvImageMapToWLColors*>(mSlicers[i]->GetWindowLevel())
1120         ->SetWindowLevelMode(true);
1121       mSlicers[i]->GetWindowLevel()->SetLookupTable(supLUT);
1122       mSlicers[i]->GetOverlayMapper()->SetLookupTable(invLUT);
1123       invLUT->Delete();
1124       supLUT->Delete();
1125     } else if (mSlicers[i]->GetOverlay()) {
1126       //dynamic_cast<vvImageMapToWLColors*>(mSlicers[i]->GetWindowLevel())
1127       //->SetWindowLevelMode(false);
1128       mSlicers[i]->GetWindowLevel()->SetLookupTable(LUT);
1129     } else {
1130       mSlicers[i]->GetWindowLevel()->SetLookupTable(LUT);
1131     }
1132     if (mSlicers[i]->GetFusion() && mSlicers[i]->GetFusionActor()->GetVisibility()) {
1133       mSlicers[i]->GetFusionActor()->SetOpacity(double(mFusionOpacity)/100);
1134       mSlicers[i]->GetFusionMapper()->SetLookupTable(fusLUT);
1135       mSlicers[i]->GetFusionMapper()->SetWindow(mFusionWindow);
1136       mSlicers[i]->GetFusionMapper()->SetLevel(mFusionLevel);
1137     }
1138   }
1139   if (fusLUT)
1140     fusLUT->Delete();
1141   if (colormap >= 0)
1142     mColorMap = colormap;
1143 }
1144 //----------------------------------------------------------------------------
1145
1146
1147 //----------------------------------------------------------------------------
1148 vvLandmarks* vvSlicerManager::GetLandmarks()
1149 {
1150   if (mLandmarks == NULL) {
1151     mLandmarks = new vvLandmarks(mSlicers[0]->GetTMax()+1);
1152     for (unsigned int i = 0; i < mSlicers.size(); i++)
1153       mSlicers[i]->SetLandmarks(mLandmarks);
1154   }
1155   return mLandmarks;
1156 }
1157 //----------------------------------------------------------------------------
1158
1159
1160 //----------------------------------------------------------------------------
1161 void vvSlicerManager::AddLandmark(float x,float y,float z,float t)
1162 {
1163   double x_index = (x - mSlicers[0]->GetInput()->GetOrigin()[0])/mSlicers[0]->GetInput()->GetSpacing()[0];
1164   double y_index = (y - mSlicers[0]->GetInput()->GetOrigin()[1])/mSlicers[0]->GetInput()->GetSpacing()[1];
1165   double z_index = (z - mSlicers[0]->GetInput()->GetOrigin()[2])/mSlicers[0]->GetInput()->GetSpacing()[2];
1166   if (x_index >= mSlicers[0]->GetInput()->GetWholeExtent()[0] &&
1167       x_index <= mSlicers[0]->GetInput()->GetWholeExtent()[1] &&
1168       y_index >= mSlicers[0]->GetInput()->GetWholeExtent()[2] &&
1169       y_index <= mSlicers[0]->GetInput()->GetWholeExtent()[3] &&
1170       z_index >= mSlicers[0]->GetInput()->GetWholeExtent()[4] &&
1171       z_index <= mSlicers[0]->GetInput()->GetWholeExtent()[5]) {
1172     double value = this->GetScalarComponentAsDouble(mSlicers[0]->GetInput(), x_index, y_index, z_index);
1173     this->GetLandmarks()->AddLandmark(x,y,z,t,value);
1174     emit LandmarkAdded();
1175   }
1176 }
1177 //----------------------------------------------------------------------------
1178
1179 //----------------------------------------------------------------------------
1180 void vvSlicerManager::PrevImage(int slicer)
1181 {
1182   emit ChangeImageWithIndexOffset(this, slicer, -1);
1183 }
1184 //----------------------------------------------------------------------------
1185
1186 //----------------------------------------------------------------------------
1187 void vvSlicerManager::NextImage(int slicer)
1188 {
1189   emit ChangeImageWithIndexOffset(this, slicer,  1);
1190 }
1191 //----------------------------------------------------------------------------
1192
1193 //----------------------------------------------------------------------------
1194 void vvSlicerManager::VerticalSliderHasChanged(int slicer, int slice)
1195 {
1196   emit AVerticalSliderHasChanged(slicer, slice);
1197 }
1198
1199 //----------------------------------------------------------------------------
1200
1201 //----------------------------------------------------------------------------
1202 double vvSlicerManager::GetScalarComponentAsDouble(vtkImageData *image, double X, double Y, double Z, int component)
1203 {
1204   int ix, iy, iz;
1205   return mSlicers[0]->GetScalarComponentAsDouble(image, X, Y, Z, ix, iy, iz, component);
1206 }
1207 //----------------------------------------------------------------------------