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