1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
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
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.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
19 #include "vvSlicerManager.h"
22 #include "vvSlicerManagerCommand.h"
23 #include "vvInteractorStyleNavigator.h"
24 #include "vvLandmarks.h"
25 #include "vvImageReader.h"
26 #include "vvImageReader.h"
28 #include "vvImageMapToWLColors.h"
29 #include "vvBlendImageActor.h"
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>
45 //----------------------------------------------------------------------------
46 vvSlicerManager::vvSlicerManager(int numberOfSlicers)
55 mType = UNDEFINEDIMAGETYPE;
69 mOverlayReader = NULL;
74 for ( int i = 0; i < numberOfSlicers; i++) {
75 vvSlicer *slicer = vvSlicer::New();
76 mSlicers.push_back(slicer);
78 mPreviousSlice.resize(numberOfSlicers);
79 mPreviousTSlice.resize(numberOfSlicers);
81 //----------------------------------------------------------------------------
84 //----------------------------------------------------------------------------
85 vvSlicerManager::~vvSlicerManager()
87 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
88 if (mSlicers[i] != NULL)
89 mSlicers[i]->Delete();
98 delete mOverlayReader;
101 delete mFusionReader;
106 //----------------------------------------------------------------------------
109 //------------------------------------------------------------------------------
110 void vvSlicerManager::SetFilename(std::string filename, int number)
112 mFileName = filename;
113 mFileName = vtksys::SystemTools::GetFilenameName(mFileName);
114 mBaseFileName = vtksys::SystemTools::GetFilenameName(vtksys::SystemTools::GetFilenameWithoutLastExtension(mFileName));
115 // DD(mBaseFileName);
116 mBaseFileNameNumber = number;
118 for(unsigned int i=0; i<mSlicers.size(); i++) {
119 mSlicers[i]->SetFileName(vtksys::SystemTools::GetFilenameWithoutLastExtension(filename));
123 mFileName.append("_"+clitk::toString(number));
126 //------------------------------------------------------------------------------
129 //----------------------------------------------------------------------------
130 void vvSlicerManager::AddContour(vvMesh::Pointer contour,bool propagate)
132 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
133 mSlicers[i]->AddContour(contour,propagate);
136 //----------------------------------------------------------------------------
139 //----------------------------------------------------------------------------
140 void vvSlicerManager::ToggleContourSuperposition()
142 for ( unsigned int i = 0; i < mSlicers.size(); i++)
143 mSlicers[i]->ToggleContourSuperposition();
145 //----------------------------------------------------------------------------
148 //----------------------------------------------------------------------------
149 bool vvSlicerManager::SetImage(std::string filename, LoadedImageType type, int n, unsigned int slice)
153 mReader = new vvImageReader;
154 std::vector<std::string> filenames;
155 filenames.push_back(filename);
156 mReader->SetInputFilenames(filenames);
157 mReader->SetSlice(slice); // Only used for SLICED type
158 mReader->Update(type);
160 SetFilename(filename, n);
161 // mFileName = vtksys::SystemTools::GetFilenameName(mFileName);
162 //mBaseFileName = vtksys::SystemTools::GetFilenameName(vtksys::SystemTools::GetFilenameWithoutLastExtension(mFileName));
163 // DD(mBaseFileName);
164 //mBaseFileNameNumber = n;
166 if (mReader->GetLastError().size() == 0) {
167 mImage=mReader->GetOutput();
168 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
169 mSlicers[i]->SetFileName(vtksys::SystemTools::GetFilenameWithoutLastExtension(filename));
170 mSlicers[i]->SetImage(mReader->GetOutput());
171 // DD(mSlicers[i]->GetFileName());
174 mLastError = mReader->GetLastError();
179 // mFileName.append("_"+clitk::toString(n));
183 //----------------------------------------------------------------------------
186 //----------------------------------------------------------------------------
187 void vvSlicerManager::SetImage(vvImage::Pointer image)
190 for (unsigned int i = 0; i < mSlicers.size(); i++) {
191 mSlicers[i]->SetImage(image);
194 //----------------------------------------------------------------------------
197 //----------------------------------------------------------------------------
198 bool vvSlicerManager::SetImages(std::vector<std::string> filenames,LoadedImageType type, int n)
201 std::string fileWithoutExtension = vtksys::SystemTools::GetFilenameWithoutExtension(filenames[0]);
203 fileWithoutExtension += "_dicom";
204 else if (type == MERGED)
205 fileWithoutExtension += "_merged";
206 else if (type == MERGEDWITHTIME)
207 fileWithoutExtension += "_merged_wt";
209 mFileName = vtksys::SystemTools::GetFilenameName(mFileName);
210 mFileName = fileWithoutExtension + vtksys::SystemTools::GetFilenameExtension(filenames[0]);
212 mReader = new vvImageReader;
213 mReader->SetInputFilenames(filenames);
214 mReader->Update(type);
216 mBaseFileName = vtksys::SystemTools::GetFilenameName(vtksys::SystemTools::GetFilenameWithoutLastExtension(mFileName));
217 // DD(mBaseFileName);
218 mBaseFileNameNumber = n;
220 if (mReader->GetLastError().size() == 0) {
221 mImage=mReader->GetOutput();
222 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
223 mSlicers[i]->SetFileName(fileWithoutExtension);
224 mSlicers[i]->SetImage(mReader->GetOutput());
227 mLastError = mReader->GetLastError();
232 mFileName.append("_"+clitk::toString(n));
237 //----------------------------------------------------------------------------
240 //----------------------------------------------------------------------------
241 bool vvSlicerManager::SetOverlay(std::string filename,int dim, std::string component)
243 mOverlayName = filename;
244 mOverlayComponent = component;
245 if (dim > mImage->GetNumberOfDimensions()) {
246 mLastError = " Overlay dimension cannot be greater then reference image!";
249 if (mOverlayReader == NULL)
250 mOverlayReader = new vvImageReader;
251 std::vector<std::string> filenames;
252 filenames.push_back(filename);
253 mOverlayReader->SetInputFilenames(filenames);
254 mOverlayReader->Update(mImage->GetNumberOfDimensions(),component.c_str(),mType);
255 if (mOverlayReader->GetLastError().size() == 0) {
256 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
257 mSlicers[i]->SetOverlay(mOverlayReader->GetOutput());
260 mLastError = mOverlayReader->GetLastError();
265 //----------------------------------------------------------------------------
268 //----------------------------------------------------------------------------
269 bool vvSlicerManager::SetFusion(std::string filename,int dim, std::string component)
271 mFusionName = filename;
272 mFusionComponent = component;
273 if (dim > mImage->GetNumberOfDimensions()) {
274 mLastError = " Overlay dimension cannot be greater then reference image!";
277 if (mFusionReader == NULL)
278 mFusionReader = new vvImageReader;
279 std::vector<std::string> filenames;
280 filenames.push_back(filename);
281 mFusionReader->SetInputFilenames(filenames);
282 mFusionReader->Update(mImage->GetNumberOfDimensions(),component.c_str(),mType);
283 if (mFusionReader->GetLastError().size() == 0) {
284 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
285 mSlicers[i]->SetFusion(mFusionReader->GetOutput());
288 mLastError = mFusionReader->GetLastError();
291 double *fusRange = mFusionReader->GetOutput()->GetVTKImages()[0]->GetScalarRange();
292 mFusionLevel = (fusRange[0]+fusRange[1])/2;
293 mFusionWindow = fusRange[1]-fusRange[0];
296 //----------------------------------------------------------------------------
299 //----------------------------------------------------------------------------
300 bool vvSlicerManager::SetVF(std::string filename)
302 if (mVectorReader == NULL)
303 mVectorReader = new vvImageReader;
304 mVectorReader->SetInputFilename(filename);
305 mVectorReader->Update(VECTORFIELD);
306 if (mVectorReader->GetLastError().size() != 0) {
307 mLastError = mVectorReader->GetLastError();
310 return SetVF(mVectorReader->GetOutput(),filename);
312 //----------------------------------------------------------------------------
315 //----------------------------------------------------------------------------
316 bool vvSlicerManager::SetVF(vvImage::Pointer vf,std::string filename)
318 if (vf->GetNumberOfDimensions() > mImage->GetNumberOfDimensions()) {
319 mLastError = "Sorry, vector field dimension cannot be greater then reference image.";
322 if (vf->GetNumberOfDimensions() == 4) {
323 // DD(vf->GetSpacing()[3]);
324 // DD(mImage->GetSpacing()[3]);
325 // DD(vf->GetOrigin()[3]);
326 // DD(mImage->GetOrigin()[3]);
327 if (vf->GetSpacing()[3] != mImage->GetSpacing()[3]) {
328 mLastError = "Sorry, vector field time spacing cannot be different from time spacing of the reference image.";
331 if (vf->GetOrigin()[3] != mImage->GetOrigin()[3]) {
332 mLastError = "Sorry, vector field time origin cannot be different from time origin of the reference image.";
338 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
339 mSlicers[i]->SetVF(vf);
343 //----------------------------------------------------------------------------
346 //----------------------------------------------------------------------------
347 vvSlicer* vvSlicerManager::GetSlicer(int i)
351 //----------------------------------------------------------------------------
354 //----------------------------------------------------------------------------
355 void vvSlicerManager::UpdateSlicer(int num, bool state)
357 if (mSlicers[num]->GetImage())
358 mSlicers[num]->SetDisplayMode(state);
360 //----------------------------------------------------------------------------
363 //----------------------------------------------------------------------------
364 void vvSlicerManager::SetSlicerWindow(int i, vtkRenderWindow* RW)
366 mSlicers[i]->SetRenderWindow(i,RW);
368 //----------------------------------------------------------------------------
371 //----------------------------------------------------------------------------
372 void vvSlicerManager::SetInteractorStyleNavigator(int i, vtkInteractorStyle* style)
374 vvSlicerManagerCommand *smc = vvSlicerManagerCommand::New();
376 smc->SetSlicerNumber(i);
377 mSlicers[i]->GetRenderWindow()->GetInteractor()->SetInteractorStyle(style);
379 mSlicers[i]->GetRenderWindow()->GetInteractor()->
380 GetInteractorStyle()->AddObserver(vtkCommand::KeyPressEvent, smc);
381 mSlicers[i]->GetRenderWindow()->GetInteractor()->
382 GetInteractorStyle()->AddObserver(vtkCommand::WindowLevelEvent, smc);
383 mSlicers[i]->GetRenderWindow()->GetInteractor()->
384 GetInteractorStyle()->AddObserver(vtkCommand::EndWindowLevelEvent, smc);
385 mSlicers[i]->GetRenderWindow()->GetInteractor()->
386 GetInteractorStyle()->AddObserver(vtkCommand::StartWindowLevelEvent, smc);
387 mSlicers[i]->GetRenderWindow()->GetInteractor()->
388 GetInteractorStyle()->AddObserver(vtkCommand::PickEvent, smc);
389 mSlicers[i]->GetRenderWindow()->GetInteractor()->
390 GetInteractorStyle()->AddObserver(vtkCommand::StartPickEvent, smc);
391 mSlicers[i]->GetRenderWindow()->GetInteractor()->
392 GetInteractorStyle()->AddObserver(vtkCommand::LeaveEvent, smc);
393 mSlicers[i]->GetRenderWindow()->GetInteractor()->
394 GetInteractorStyle()->AddObserver(vtkCommand::UserEvent, smc);
395 mSlicers[i]->GetRenderWindow()->GetInteractor()->
396 GetInteractorStyle()->AddObserver(vtkCommand::MouseWheelForwardEvent, smc);
397 mSlicers[i]->GetRenderWindow()->GetInteractor()->
398 GetInteractorStyle()->AddObserver(vtkCommand::MouseWheelBackwardEvent, smc);
399 // mSlicers[i]->GetRenderWindow()->GetInteractor()->
400 // GetInteractorStyle()->AddObserver(vtkCommand::LeftButtonReleaseEvent, smc);
401 mSlicers[i]->GetRenderWindow()->GetInteractor()->
402 GetInteractorStyle()->AddObserver(vtkCommand::EndPickEvent, smc);
403 mSlicers[i]->GetRenderWindow()->GetInteractor()->
404 GetInteractorStyle()->AddObserver(vtkCommand::EndInteractionEvent, smc);
407 //----------------------------------------------------------------------------
410 //----------------------------------------------------------------------------
411 void vvSlicerManager::LeftButtonReleaseEvent(int slicer)
413 emit LeftButtonReleaseSignal(slicer);
415 //----------------------------------------------------------------------------
418 //----------------------------------------------------------------------------
419 void vvSlicerManager::SetTSlice(int slice)
423 else if (slice > mSlicers[0]->GetTMax())
424 slice = mSlicers[0]->GetTMax();
426 mLandmarks->SetTime(slice);
427 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
428 if (slice != mSlicers[i]->GetTSlice()) {
429 mSlicers[i]->SetTSlice(slice);
430 if (mSlicers[i]->GetImageActor()->GetVisibility())
435 //----------------------------------------------------------------------------
438 //----------------------------------------------------------------------------
439 void vvSlicerManager::SetNextTSlice(int originating_slicer)
441 int t = mSlicers[0]->GetTSlice();
443 if (t > mSlicers[0]->GetTMax())
445 // DD("SetNextTSlice");
446 // DD(originating_slicer);
448 emit UpdateTSlice(originating_slicer,t);
450 //----------------------------------------------------------------------------
453 //----------------------------------------------------------------------------
454 void vvSlicerManager::SetPreviousTSlice(int originating_slicer)
456 int t = mSlicers[0]->GetTSlice();
459 t = mSlicers[0]->GetTMax();
460 emit UpdateTSlice(originating_slicer,t);
462 //----------------------------------------------------------------------------
465 //----------------------------------------------------------------------------
466 void vvSlicerManager::ToggleInterpolation()
468 bool interpolate=!(mSlicers[0]->GetImageActor()->GetInterpolate());
469 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
470 mSlicers[i]->GetImageActor()->SetInterpolate(interpolate);
473 //----------------------------------------------------------------------------
476 //----------------------------------------------------------------------------
477 void vvSlicerManager::SetTSliceInSlicer(int tslice, int slicer)
481 else if (tslice > mSlicers[slicer]->GetTMax())
482 tslice = mSlicers[slicer]->GetTMax();
484 mLandmarks->SetTime(tslice);
486 if (mSlicers[slicer]->GetTSlice() == tslice) return;
488 mSlicers[slicer]->SetTSlice(tslice);
489 if (mSlicers[slicer]->GetImageActor()->GetVisibility())
490 UpdateTSlice(slicer);
492 //----------------------------------------------------------------------------
495 //----------------------------------------------------------------------------
496 void vvSlicerManager::SetColorWindow(double s)
498 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
499 mSlicers[i]->SetColorWindow(s);
502 //----------------------------------------------------------------------------
505 //----------------------------------------------------------------------------
506 void vvSlicerManager::SetColorLevel(double s)
508 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
509 mSlicers[i]->SetColorLevel(s);
512 //----------------------------------------------------------------------------
514 //----------------------------------------------------------------------------
515 void vvSlicerManager::SetCursorVisibility(int s)
517 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
518 mSlicers[i]->SetCursorVisibility(s);
521 //----------------------------------------------------------------------------
524 //----------------------------------------------------------------------------
525 void vvSlicerManager::SetOpacity(int i, double factor)
527 mSlicers[i]->SetOpacity(1/factor);
529 //----------------------------------------------------------------------------
532 //----------------------------------------------------------------------------
533 void vvSlicerManager::UpdateViews(int current,int slicer)
535 // DD("UpdateViews");
539 double x = (mSlicers[slicer]->GetCurrentPosition()[0] - mSlicers[slicer]->GetInput()->GetOrigin()[0])
540 /mSlicers[slicer]->GetInput()->GetSpacing()[0];
541 double y = (mSlicers[slicer]->GetCurrentPosition()[1] - mSlicers[slicer]->GetInput()->GetOrigin()[1])
542 /mSlicers[slicer]->GetInput()->GetSpacing()[1];
543 double z = (mSlicers[slicer]->GetCurrentPosition()[2] - mSlicers[slicer]->GetInput()->GetOrigin()[2])
544 /mSlicers[slicer]->GetInput()->GetSpacing()[2];
546 if (x >= mSlicers[slicer]->GetInput()->GetWholeExtent()[0] &&
547 x <= mSlicers[slicer]->GetInput()->GetWholeExtent()[1] &&
548 y >= mSlicers[slicer]->GetInput()->GetWholeExtent()[2] &&
549 y <= mSlicers[slicer]->GetInput()->GetWholeExtent()[3] &&
550 z >= mSlicers[slicer]->GetInput()->GetWholeExtent()[4] &&
551 z <= mSlicers[slicer]->GetInput()->GetWholeExtent()[5]) {
552 mSlicers[slicer]->UpdateCursorPosition();
553 mSlicers[slicer]->SetCursorColor(10,212,255);
555 switch (mSlicers[slicer]->GetSliceOrientation()) {
556 case vtkImageViewer2::SLICE_ORIENTATION_XY:
557 if (mSlicers[slicer]->GetSlice() == (int)floor(z))
558 mSlicers[slicer]->Render();
560 mSlicers[slicer]->SetSlice((int)floor(z));
563 case vtkImageViewer2::SLICE_ORIENTATION_XZ:
564 if (mSlicers[slicer]->GetSlice() == (int)floor(y))
565 mSlicers[slicer]->Render();
567 mSlicers[slicer]->SetSlice((int)floor(y));
570 case vtkImageViewer2::SLICE_ORIENTATION_YZ:
571 if (mSlicers[slicer]->GetSlice() == (int)floor(x))
572 mSlicers[slicer]->Render();
574 mSlicers[slicer]->SetSlice((int)floor(x));
578 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
579 if (i != (unsigned int)slicer && mSlicers[i]->GetImageActor()->GetVisibility()
580 && mSlicers[i]->GetRenderWindow()->GetSize()[0] > 2
581 && mSlicers[i]->GetRenderWindow()->GetSize()[1] > 2) {
582 mSlicers[i]->SetCurrentPosition(mSlicers[slicer]->GetCurrentPosition()[0],
583 mSlicers[slicer]->GetCurrentPosition()[1],
584 mSlicers[slicer]->GetCurrentPosition()[2],
585 mSlicers[slicer]->GetTSlice());
586 mSlicers[i]->UpdateCursorPosition();
587 if (current) { //do not display corner annotation if image is the one picked
588 mSlicers[i]->SetCurrentPosition(-VTK_DOUBLE_MAX,-VTK_DOUBLE_MAX,
589 -VTK_DOUBLE_MAX, mSlicers[slicer]->GetTSlice());
590 mSlicers[i]->SetCursorColor(255,10,212);
592 mSlicers[i]->SetCursorColor(150,10,282);
594 switch (mSlicers[i]->GetSliceOrientation()) {
595 case vtkImageViewer2::SLICE_ORIENTATION_XY:
596 if (mSlicers[i]->GetSlice() == (int)floor(z))
597 mSlicers[i]->Render();
599 mSlicers[i]->SetSlice((int)floor(z));
602 case vtkImageViewer2::SLICE_ORIENTATION_XZ:
603 if (mSlicers[i]->GetSlice() == (int)floor(y))
604 mSlicers[i]->Render();
606 mSlicers[i]->SetSlice((int)floor(y));
609 case vtkImageViewer2::SLICE_ORIENTATION_YZ:
610 if (mSlicers[i]->GetSlice() == (int)floor(x))
611 mSlicers[i]->Render();
613 mSlicers[i]->SetSlice((int)floor(x));
616 // DD("UpdateViews::");
624 //----------------------------------------------------------------------------
627 //----------------------------------------------------------------------------
628 void vvSlicerManager::UpdateLinked(int slicer)
630 double x = (mSlicers[slicer]->GetCurrentPosition()[0] - mSlicers[slicer]->GetInput()->GetOrigin()[0])
631 /mSlicers[slicer]->GetInput()->GetSpacing()[0];
632 double y = (mSlicers[slicer]->GetCurrentPosition()[1] - mSlicers[slicer]->GetInput()->GetOrigin()[1])
633 /mSlicers[slicer]->GetInput()->GetSpacing()[1];
634 double z = (mSlicers[slicer]->GetCurrentPosition()[2] - mSlicers[slicer]->GetInput()->GetOrigin()[2])
635 /mSlicers[slicer]->GetInput()->GetSpacing()[2];
637 if (x >= mSlicers[slicer]->GetInput()->GetWholeExtent()[0] &&
638 x <= mSlicers[slicer]->GetInput()->GetWholeExtent()[1] &&
639 y >= mSlicers[slicer]->GetInput()->GetWholeExtent()[2] &&
640 y <= mSlicers[slicer]->GetInput()->GetWholeExtent()[3] &&
641 z >= mSlicers[slicer]->GetInput()->GetWholeExtent()[4] &&
642 z <= mSlicers[slicer]->GetInput()->GetWholeExtent()[5]) {
643 for (std::list<std::string>::const_iterator i = mLinkedId.begin(); i != mLinkedId.end(); i++) {
644 emit UpdateLinkManager(*i, slicer,mSlicers[slicer]->GetCurrentPosition()[0],
645 mSlicers[slicer]->GetCurrentPosition()[1],
646 mSlicers[slicer]->GetCurrentPosition()[2],mSlicers[slicer]->GetTSlice());
650 //----------------------------------------------------------------------------
652 //----------------------------------------------------------------------------
653 void vvSlicerManager::UpdateLinkedNavigation(vvSlicer *slicer, bool bPropagate)
655 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
656 vtkCamera *camera = mSlicers[i] ->GetRenderer()->GetActiveCamera();
657 vtkCamera *refCam = slicer->GetRenderer()->GetActiveCamera();
658 camera->SetParallelScale(refCam->GetParallelScale());
660 double position[3], focal[3];
661 camera->GetPosition(position);
662 camera->GetFocalPoint(focal);
664 double refPosition[3], refFocal[3];
665 refCam->GetPosition(refPosition);
666 refCam->GetFocalPoint(refFocal);
668 if(slicer->GetSliceOrientation()==mSlicers[i]->GetSliceOrientation()) {
669 for(int i=0; i<3; i++) {
670 position[i] = refPosition[i];
671 focal[i] = refFocal[i];
675 if(slicer->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_XY) {
676 if(mSlicers[i]->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_XZ) {
677 position[0] = refPosition[0];
678 focal[0] = refFocal[0];
680 if(mSlicers[i]->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_YZ) {
681 position[1] = refPosition[1];
682 focal[1] = refFocal[1];
686 if(slicer->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_XZ) {
687 if(mSlicers[i]->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_YZ) {
688 position[2] = refPosition[2];
689 focal[2] = refFocal[2];
691 if(mSlicers[i]->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_XY) {
692 position[0] = refPosition[0];
693 focal[0] = refFocal[0];
697 if(slicer->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_YZ) {
698 if(mSlicers[i]->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_XY) {
699 position[1] = refPosition[1];
700 focal[1] = refFocal[1];
702 if(mSlicers[i]->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_XZ) {
703 position[2] = refPosition[2];
704 focal[2] = refFocal[2];
708 camera->SetFocalPoint(focal);
709 camera->SetPosition(position);
712 for (std::list<std::string>::const_iterator i = mLinkedId.begin(); i != mLinkedId.end(); i++)
713 emit UpdateLinkedNavigation(*i, this);
717 //----------------------------------------------------------------------------
719 //----------------------------------------------------------------------------
720 double vvSlicerManager::GetColorWindow()
723 return mSlicers[0]->GetColorWindow();
726 //----------------------------------------------------------------------------
729 //----------------------------------------------------------------------------
730 double vvSlicerManager::GetColorLevel()
733 return mSlicers[0]->GetColorLevel();
736 //----------------------------------------------------------------------------
739 //----------------------------------------------------------------------------
740 void vvSlicerManager::Render()
742 // DD("vvSlicerManager::Render");
743 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
745 mSlicers[i]->Render();
748 //----------------------------------------------------------------------------
751 //----------------------------------------------------------------------------
752 void vvSlicerManager::GenerateDefaultLookupTable()
755 SetColorMap(mColorMap);
757 //----------------------------------------------------------------------------
760 //----------------------------------------------------------------------------
761 void vvSlicerManager::Reload()
763 mReader->Update(mType);
764 mImage=mReader->GetOutput();
765 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
766 mSlicers[i]->SetImage(mImage);
769 //----------------------------------------------------------------------------
772 //----------------------------------------------------------------------------
773 void vvSlicerManager::ReloadFusion()
775 mFusionReader->Update();
776 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
777 mSlicers[i]->SetFusion(mFusionReader->GetOutput());
778 mSlicers[i]->Render();
781 //----------------------------------------------------------------------------
784 //----------------------------------------------------------------------------
785 void vvSlicerManager::ReloadOverlay()
787 mOverlayReader->Update();
788 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
789 mSlicers[i]->SetOverlay(mOverlayReader->GetOutput());
790 mSlicers[i]->Render();
793 //----------------------------------------------------------------------------
796 //----------------------------------------------------------------------------
797 void vvSlicerManager::ReloadVF()
799 mVectorReader->Update(VECTORFIELD); //deletes the old images through the VF::Init() function
800 mVF=mVectorReader->GetOutput();
801 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
802 mSlicers[i]->SetVF(mVF);
803 mSlicers[i]->Render();
806 //----------------------------------------------------------------------------
809 //----------------------------------------------------------------------------
810 void vvSlicerManager::RemoveActor(const std::string& actor_type, int overlay_index)
812 for (unsigned int i = 0; i < mSlicers.size(); i++) {
813 mSlicers[i]->RemoveActor(actor_type,overlay_index);
815 if (actor_type=="vector") {
818 delete mVectorReader;
823 //----------------------------------------------------------------------------
826 //----------------------------------------------------------------------------
827 void vvSlicerManager::RemoveActors()
829 ///This method leaks a few objects. See RemoveActor for what a correct implementation would look like
830 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
831 mSlicers[i]->SetDisplayMode(0);
832 mSlicers[i]->GetRenderer()->RemoveActor(mSlicers[i]->GetImageActor());
835 //----------------------------------------------------------------------------
838 //----------------------------------------------------------------------------
839 void vvSlicerManager::UpdateInfoOnCursorPosition(int slicer)
841 // int view = mSlicers[slicer]->GetSliceOrientation();
842 // int slice = mSlicers[slicer]->GetSlice();
843 double x = mSlicers[slicer]->GetCursorPosition()[0];
844 double y = mSlicers[slicer]->GetCursorPosition()[1];
845 double z = mSlicers[slicer]->GetCursorPosition()[2];
846 double X = (x - mSlicers[slicer]->GetInput()->GetOrigin()[0])/
847 mSlicers[slicer]->GetInput()->GetSpacing()[0];
848 double Y = (y - mSlicers[slicer]->GetInput()->GetOrigin()[1])/
849 mSlicers[slicer]->GetInput()->GetSpacing()[1];
850 double Z = (z - mSlicers[slicer]->GetInput()->GetOrigin()[2])/
851 mSlicers[slicer]->GetInput()->GetSpacing()[2];
852 double value = -VTK_DOUBLE_MAX;
854 double xVec=0, yVec=0, zVec=0, valueVec=0;
857 double valueOver=0, valueFus=0;
858 if (X >= mSlicers[slicer]->GetInput()->GetWholeExtent()[0] &&
859 X <= mSlicers[slicer]->GetInput()->GetWholeExtent()[1] &&
860 Y >= mSlicers[slicer]->GetInput()->GetWholeExtent()[2] &&
861 Y <= mSlicers[slicer]->GetInput()->GetWholeExtent()[3] &&
862 Z >= mSlicers[slicer]->GetInput()->GetWholeExtent()[4] &&
863 Z <= mSlicers[slicer]->GetInput()->GetWholeExtent()[5]) {
864 value = mSlicers[slicer]->GetInput()->GetScalarComponentAsDouble(
868 if (mSlicers[slicer]->GetVFActor() && mSlicers[slicer]->GetVFActor()->GetVisibility()) {
870 unsigned int currentTime = mSlicers[slicer]->GetTSlice();
871 vtkImageData *vf = NULL;
873 if (mSlicers[slicer]->GetVF()->GetVTKImages().size() > currentTime)
874 vf = mSlicers[slicer]->GetVF()->GetVTKImages()[currentTime];
876 vf = mSlicers[slicer]->GetVF()->GetVTKImages()[0];
879 double Xvf = (x - vf->GetOrigin()[0])/ vf->GetSpacing()[0];
880 double Yvf = (y - vf->GetOrigin()[1])/ vf->GetSpacing()[1];
881 double Zvf = (z - vf->GetOrigin()[2])/ vf->GetSpacing()[2];
882 xVec = vf->GetScalarComponentAsDouble( (int)floor(Xvf), (int)floor(Yvf), (int)floor(Zvf),0);
883 yVec = vf->GetScalarComponentAsDouble( (int)floor(Xvf), (int)floor(Yvf), (int)floor(Zvf),1);
884 zVec = vf->GetScalarComponentAsDouble( (int)floor(Xvf), (int)floor(Yvf), (int)floor(Zvf),2);
885 valueVec = sqrt(xVec*xVec + yVec*yVec + zVec*zVec);
888 if (mSlicers[slicer]->GetOverlayActor() && mSlicers[slicer]->GetOverlayActor()->GetVisibility()) {
890 double Xover = (x - mSlicers[slicer]->GetOverlay()->GetOrigin()[0])
891 /mSlicers[slicer]->GetOverlay()->GetSpacing()[0];
892 double Yover = (y - mSlicers[slicer]->GetOverlay()->GetOrigin()[1])
893 /mSlicers[slicer]->GetOverlay()->GetSpacing()[1];
894 double Zover = (z - mSlicers[slicer]->GetOverlay()->GetOrigin()[2])
895 /mSlicers[slicer]->GetOverlay()->GetSpacing()[2];
896 if (Xover >= mSlicers[slicer]->GetOverlayMapper()->GetInput()->GetWholeExtent()[0] &&
897 Xover <= mSlicers[slicer]->GetOverlayMapper()->GetInput()->GetWholeExtent()[1] &&
898 Yover >= mSlicers[slicer]->GetOverlayMapper()->GetInput()->GetWholeExtent()[2] &&
899 Yover <= mSlicers[slicer]->GetOverlayMapper()->GetInput()->GetWholeExtent()[3] &&
900 Zover >= mSlicers[slicer]->GetOverlayMapper()->GetInput()->GetWholeExtent()[4] &&
901 Zover <= mSlicers[slicer]->GetOverlayMapper()->GetInput()->GetWholeExtent()[5]) {
902 valueOver = static_cast<vtkImageData*>(mSlicers[slicer]->GetOverlayMapper()->GetInput())->
903 GetScalarComponentAsDouble(
906 (int)floor(Zover),0);
909 if (mSlicers[slicer]->GetFusionActor() && mSlicers[slicer]->GetFusionActor()->GetVisibility()) {
911 double Xfus = (x - mSlicers[slicer]->GetFusion()->GetOrigin()[0])
912 /mSlicers[slicer]->GetFusion()->GetSpacing()[0];
913 double Yfus = (y - mSlicers[slicer]->GetFusion()->GetOrigin()[1])
914 /mSlicers[slicer]->GetFusion()->GetSpacing()[1];
915 double Zfus = (z - mSlicers[slicer]->GetFusion()->GetOrigin()[2])
916 /mSlicers[slicer]->GetFusion()->GetSpacing()[2];
917 if (Xfus >= mSlicers[slicer]->GetFusionMapper()->GetInput()->GetWholeExtent()[0] &&
918 Xfus <= mSlicers[slicer]->GetFusionMapper()->GetInput()->GetWholeExtent()[1] &&
919 Yfus >= mSlicers[slicer]->GetFusionMapper()->GetInput()->GetWholeExtent()[2] &&
920 Yfus <= mSlicers[slicer]->GetFusionMapper()->GetInput()->GetWholeExtent()[3] &&
921 Zfus >= mSlicers[slicer]->GetFusionMapper()->GetInput()->GetWholeExtent()[4] &&
922 Zfus <= mSlicers[slicer]->GetFusionMapper()->GetInput()->GetWholeExtent()[5]) {
923 valueFus = static_cast<vtkImageData*>(mSlicers[slicer]->GetFusionMapper()->GetInput())->
924 GetScalarComponentAsDouble(
930 emit UpdatePosition(mSlicers[slicer]->GetCursorVisibility(),
932 emit UpdateVector(displayVec,xVec, yVec, zVec, valueVec);
933 emit UpdateOverlay(displayOver,valueOver,value);
934 emit UpdateFusion(displayFus,valueFus);
935 for (unsigned int i = 0; i < mSlicers.size(); i++) {
936 if (mSlicers[i]->GetImageActor()->GetVisibility() == 1)
937 emit UpdateWindows(i,mSlicers[i]->GetSliceOrientation(),mSlicers[i]->GetSlice());
939 emit UpdateWindows(i,-1,-1);
943 //----------------------------------------------------------------------------
946 //----------------------------------------------------------------------------
947 void vvSlicerManager::Activated()
949 emit currentImageChanged(mId);
951 //----------------------------------------------------------------------------
954 //----------------------------------------------------------------------------
955 void vvSlicerManager::UpdateWindowLevel()
957 emit WindowLevelChanged(mSlicers[0]->GetColorWindow(),mSlicers[0]->GetColorLevel(),mPreset,mColorMap);
959 //----------------------------------------------------------------------------
962 //----------------------------------------------------------------------------
963 void vvSlicerManager::UpdateSlice(int slicer)
965 // DD("vvSlicerManager::UpdateSlice emit UpdateSlice");
967 // DD(mSlicers[slicer]->GetSlice());
968 if (mPreviousSlice[slicer] == mSlicers[slicer]->GetSlice()) {
969 //DD("============= NOTHING");
972 emit UpdateSlice(slicer, mSlicers[slicer]->GetSlice());
973 mSlicers[slicer]->Render(); // DS <-- I add this, this could/must be the only Render ...
974 mPreviousSlice[slicer] = mSlicers[slicer]->GetSlice();
976 //----------------------------------------------------------------------------
979 //----------------------------------------------------------------------------
980 void vvSlicerManager::UpdateTSlice(int slicer)
982 // DD("vvSlicerManager::UpdateTSlice emit UpdateTSlice");
984 // DD(mSlicers[slicer]->GetTSlice());
985 // DD(mSlicers[slicer]->GetSlice());
986 if (mPreviousSlice[slicer] == mSlicers[slicer]->GetSlice()) {
987 if (mPreviousTSlice[slicer] == mSlicers[slicer]->GetTSlice()) {
988 // DD("************** NOTHING ***********");
992 mPreviousSlice[slicer] = mSlicers[slicer]->GetSlice();
993 mPreviousTSlice[slicer] = mSlicers[slicer]->GetTSlice();
994 emit UpdateTSlice(slicer,mSlicers[slicer]->GetTSlice());
996 //----------------------------------------------------------------------------
999 //----------------------------------------------------------------------------
1000 void vvSlicerManager::UpdateSliceRange(int slicer)
1002 emit UpdateSliceRange(slicer,
1003 mSlicers[slicer]->GetSliceRange()[0], mSlicers[slicer]->GetSliceRange()[1],
1004 0,mSlicers[slicer]->GetTMax());
1006 //----------------------------------------------------------------------------
1009 //----------------------------------------------------------------------------
1010 void vvSlicerManager::SetPreset(int preset)
1012 //vtkLookupTable* LUT = static_cast<vtkLookupTable*>(mSlicers[0]->GetWindowLevel()->GetLookupTable());
1013 double window = mSlicers[0]->GetColorWindow();
1014 double level = mSlicers[0]->GetColorLevel();
1016 std::string component_type=mImage->GetScalarTypeAsITKString();
1019 if (component_type == "unsigned_char") {
1022 } else if (component_type == "short") {
1027 mImage->GetScalarRange(range);
1028 window = range[1] - range[0];
1029 level = (range[1] + range[0])* 0.5;
1060 this->SetColorWindow(window);
1061 this->SetColorLevel(level);
1068 //----------------------------------------------------------------------------
1071 //----------------------------------------------------------------------------
1072 void vvSlicerManager::SetLocalColorWindowing(const int slicer)
1075 this->mSlicers[slicer]->GetExtremasAroundMousePointer(min, max);
1076 this->SetColorWindow(max-min);
1077 this->SetColorLevel(0.5*(min+max));
1078 this->UpdateWindowLevel();
1081 //----------------------------------------------------------------------------
1084 //----------------------------------------------------------------------------
1085 void vvSlicerManager::SetColorMap()
1087 SetColorMap(mColorMap);
1089 //----------------------------------------------------------------------------
1092 //----------------------------------------------------------------------------
1093 void vvSlicerManager::SetColorMap(int colormap)
1096 range[0] = mSlicers[0]->GetInput()->GetScalarRange()[0];
1097 range[1] = mSlicers[0]->GetInput()->GetScalarRange()[1];
1099 double window = mSlicers[0]->GetWindowLevel()->GetWindow();
1100 double level = mSlicers[0]->GetWindowLevel()->GetLevel();
1102 vtkLookupTable* LUT = static_cast<vtkLookupTable*>(mSlicers[0]->GetWindowLevel()->GetLookupTable());
1111 LUT = vtkLookupTable::New();
1112 LUT->SetValueRange(0,1);
1113 LUT->SetSaturationRange(1,1);
1114 LUT->SetHueRange(0,0.18);
1118 LUT = vtkLookupTable::New();
1119 LUT->SetValueRange(0,1);
1120 LUT->SetSaturationRange(1,1);
1121 LUT->SetHueRange(0.4,0.80);
1125 LUT = vtkLookupTable::New();
1126 LUT->SetValueRange(0,1);
1127 LUT->SetSaturationRange(1,1);
1128 LUT->SetHueRange(0,1);
1132 LUT = vtkLookupTable::New();
1133 LUT->SetValueRange(0.,1);
1134 LUT->SetSaturationRange(1,1);
1135 LUT->SetHueRange(1,0.1);
1136 //LUT->SetRampToLinear();
1140 LUT->SetTableRange(level-fabs(window)/4,level+fabs(window)/4);
1143 vtkLookupTable* fusLUT = NULL;
1144 if (mSlicers[0]->GetFusion()) {
1145 fusLUT = vtkLookupTable::New();
1146 double fusRange [2];
1147 fusRange[0] = mFusionLevel - mFusionWindow/2;
1148 fusRange[1] = mFusionLevel + mFusionWindow/2;
1149 fusLUT->SetTableRange(fusRange[0],fusRange[1]);
1150 fusLUT->SetValueRange(1,1);
1151 fusLUT->SetSaturationRange(1,1);
1152 if (mFusionColorMap == 1)
1153 fusLUT->SetHueRange(0,0.18);
1154 else if (mFusionColorMap == 2)
1155 fusLUT->SetHueRange(0.4,0.80);
1156 else if (mFusionColorMap == 3)
1157 fusLUT->SetHueRange(0,1);
1159 if (mFusionColorMap == 0)
1162 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
1163 if (mSlicers[i]->GetOverlay() && mSlicers[i]->GetOverlayActor()->GetVisibility()) {
1164 vtkLookupTable* supLUT = vtkLookupTable::New();
1165 supLUT->SetTableRange(range[0],range[1]);
1166 supLUT->SetValueRange(1,1);
1167 supLUT->SetSaturationRange(1,1);
1168 supLUT->SetHueRange(double(mOverlayColor)/360,double(mOverlayColor)/360);
1170 vtkLookupTable* invLUT = vtkLookupTable::New();
1171 invLUT->SetTableRange(range[0],range[1]);
1172 invLUT->SetValueRange(1,1);
1173 invLUT->SetSaturationRange(1,1);
1174 invLUT->SetHueRange(double((mOverlayColor+180)%360)/360,double((mOverlayColor+180)%360)/360);
1176 dynamic_cast<vvImageMapToWLColors*>(mSlicers[i]->GetWindowLevel())
1177 ->SetWindowLevelMode(true);
1178 mSlicers[i]->GetWindowLevel()->SetLookupTable(supLUT);
1179 mSlicers[i]->GetOverlayMapper()->SetLookupTable(invLUT);
1182 } else if (mSlicers[i]->GetOverlay()) {
1183 //dynamic_cast<vvImageMapToWLColors*>(mSlicers[i]->GetWindowLevel())
1184 //->SetWindowLevelMode(false);
1185 mSlicers[i]->GetWindowLevel()->SetLookupTable(LUT);
1187 mSlicers[i]->GetWindowLevel()->SetLookupTable(LUT);
1189 if (mSlicers[i]->GetFusion() && mSlicers[i]->GetFusionActor()->GetVisibility()) {
1190 mSlicers[i]->GetFusionActor()->SetOpacity(double(mFusionOpacity)/100);
1191 mSlicers[i]->GetFusionMapper()->SetLookupTable(fusLUT);
1192 mSlicers[i]->GetFusionMapper()->SetWindow(mFusionWindow);
1193 mSlicers[i]->GetFusionMapper()->SetLevel(mFusionLevel);
1199 mColorMap = colormap;
1201 //----------------------------------------------------------------------------
1204 //----------------------------------------------------------------------------
1205 vvLandmarks* vvSlicerManager::GetLandmarks()
1207 if (mLandmarks == NULL) {
1208 mLandmarks = new vvLandmarks(mSlicers[0]->GetTMax()+1);
1209 for (unsigned int i = 0; i < mSlicers.size(); i++)
1210 mSlicers[i]->SetLandmarks(mLandmarks);
1214 //----------------------------------------------------------------------------
1217 //----------------------------------------------------------------------------
1218 void vvSlicerManager::AddLandmark(float x,float y,float z,float t)
1220 double x_index = (x - mSlicers[0]->GetInput()->GetOrigin()[0])/mSlicers[0]->GetInput()->GetSpacing()[0];
1221 double y_index = (y - mSlicers[0]->GetInput()->GetOrigin()[1])/mSlicers[0]->GetInput()->GetSpacing()[1];
1222 double z_index = (z - mSlicers[0]->GetInput()->GetOrigin()[2])/mSlicers[0]->GetInput()->GetSpacing()[2];
1223 if (x_index >= mSlicers[0]->GetInput()->GetWholeExtent()[0] &&
1224 x_index <= mSlicers[0]->GetInput()->GetWholeExtent()[1] &&
1225 y_index >= mSlicers[0]->GetInput()->GetWholeExtent()[2] &&
1226 y_index <= mSlicers[0]->GetInput()->GetWholeExtent()[3] &&
1227 z_index >= mSlicers[0]->GetInput()->GetWholeExtent()[4] &&
1228 z_index <= mSlicers[0]->GetInput()->GetWholeExtent()[5]) {
1229 double value = mSlicers[0]->GetInput()->GetScalarComponentAsDouble(
1233 this->GetLandmarks()->AddLandmark(x,y,z,t,value);
1234 emit LandmarkAdded();
1237 //----------------------------------------------------------------------------
1239 //----------------------------------------------------------------------------
1240 void vvSlicerManager::PrevImage(int slicer)
1242 emit ChangeImageWithIndexOffset(this, slicer, -1);
1244 //----------------------------------------------------------------------------
1247 //----------------------------------------------------------------------------
1248 void vvSlicerManager::NextImage(int slicer)
1250 emit ChangeImageWithIndexOffset(this, slicer, 1);
1252 //----------------------------------------------------------------------------
1255 //----------------------------------------------------------------------------
1256 void vvSlicerManager::VerticalSliderHasChanged(int slicer, int slice)
1258 emit AVerticalSliderHasChanged(slicer, slice);
1261 //----------------------------------------------------------------------------