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