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