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