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)
153 mReader = new vvImageReader;
154 std::vector<std::string> filenames;
155 filenames.push_back(filename);
156 mReader->SetInputFilenames(filenames);
157 mReader->Update(type);
159 SetFilename(filename, n);
160 // mFileName = vtksys::SystemTools::GetFilenameName(mFileName);
161 //mBaseFileName = vtksys::SystemTools::GetFilenameName(vtksys::SystemTools::GetFilenameWithoutLastExtension(mFileName));
162 // DD(mBaseFileName);
163 //mBaseFileNameNumber = n;
165 if (mReader->GetLastError().size() == 0) {
166 mImage=mReader->GetOutput();
167 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
168 mSlicers[i]->SetFileName(vtksys::SystemTools::GetFilenameWithoutLastExtension(filename));
169 mSlicers[i]->SetImage(mReader->GetOutput());
170 // DD(mSlicers[i]->GetFileName());
173 mLastError = mReader->GetLastError();
178 // mFileName.append("_"+clitk::toString(n));
182 //----------------------------------------------------------------------------
185 //----------------------------------------------------------------------------
186 void vvSlicerManager::SetImage(vvImage::Pointer image)
189 for (unsigned int i = 0; i < mSlicers.size(); i++) {
190 mSlicers[i]->SetImage(image);
193 //----------------------------------------------------------------------------
196 //----------------------------------------------------------------------------
197 bool vvSlicerManager::SetImages(std::vector<std::string> filenames,LoadedImageType type, int n)
200 std::string fileWithoutExtension = vtksys::SystemTools::GetFilenameWithoutExtension(filenames[0]);
202 fileWithoutExtension += "_dicom";
203 else if (type == MERGED)
204 fileWithoutExtension += "_merged";
205 else if (type == MERGEDWITHTIME)
206 fileWithoutExtension += "_merged_wt";
208 mFileName = vtksys::SystemTools::GetFilenameName(mFileName);
209 mFileName = fileWithoutExtension + vtksys::SystemTools::GetFilenameExtension(filenames[0]);
211 mReader = new vvImageReader;
212 mReader->SetInputFilenames(filenames);
213 mReader->Update(type);
215 mBaseFileName = vtksys::SystemTools::GetFilenameName(vtksys::SystemTools::GetFilenameWithoutLastExtension(mFileName));
216 // DD(mBaseFileName);
217 mBaseFileNameNumber = n;
219 if (mReader->GetLastError().size() == 0) {
220 mImage=mReader->GetOutput();
221 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
222 mSlicers[i]->SetFileName(fileWithoutExtension);
223 mSlicers[i]->SetImage(mReader->GetOutput());
226 mLastError = mReader->GetLastError();
231 mFileName.append("_"+clitk::toString(n));
236 //----------------------------------------------------------------------------
239 //----------------------------------------------------------------------------
240 bool vvSlicerManager::SetOverlay(std::string filename,int dim, std::string component)
242 mOverlayName = filename;
243 mOverlayComponent = component;
244 if (dim > mImage->GetNumberOfDimensions()) {
245 mLastError = " Overlay dimension cannot be greater then reference image!";
248 if (mOverlayReader == NULL)
249 mOverlayReader = new vvImageReader;
250 std::vector<std::string> filenames;
251 filenames.push_back(filename);
252 mOverlayReader->SetInputFilenames(filenames);
253 mOverlayReader->Update(mImage->GetNumberOfDimensions(),component.c_str(),mType);
254 if (mOverlayReader->GetLastError().size() == 0) {
255 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
256 mSlicers[i]->SetOverlay(mOverlayReader->GetOutput());
259 mLastError = mOverlayReader->GetLastError();
264 //----------------------------------------------------------------------------
267 //----------------------------------------------------------------------------
268 bool vvSlicerManager::SetFusion(std::string filename,int dim, std::string component)
270 mFusionName = filename;
271 mFusionComponent = component;
272 if (dim > mImage->GetNumberOfDimensions()) {
273 mLastError = " Overlay dimension cannot be greater then reference image!";
276 if (mFusionReader == NULL)
277 mFusionReader = new vvImageReader;
278 std::vector<std::string> filenames;
279 filenames.push_back(filename);
280 mFusionReader->SetInputFilenames(filenames);
281 mFusionReader->Update(mImage->GetNumberOfDimensions(),component.c_str(),mType);
282 if (mFusionReader->GetLastError().size() == 0) {
283 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
284 mSlicers[i]->SetFusion(mFusionReader->GetOutput());
287 mLastError = mFusionReader->GetLastError();
290 double *fusRange = mFusionReader->GetOutput()->GetVTKImages()[0]->GetScalarRange();
291 mFusionLevel = (fusRange[0]+fusRange[1])/2;
292 mFusionWindow = fusRange[1]-fusRange[0];
295 //----------------------------------------------------------------------------
298 //----------------------------------------------------------------------------
299 bool vvSlicerManager::SetVF(std::string filename)
301 if (mVectorReader == NULL)
302 mVectorReader = new vvImageReader;
303 mVectorReader->SetInputFilename(filename);
304 mVectorReader->Update(VECTORFIELD);
305 if (mVectorReader->GetLastError().size() != 0) {
306 mLastError = mVectorReader->GetLastError();
309 return SetVF(mVectorReader->GetOutput(),filename);
311 //----------------------------------------------------------------------------
314 //----------------------------------------------------------------------------
315 bool vvSlicerManager::SetVF(vvImage::Pointer vf,std::string filename)
317 if (vf->GetNumberOfDimensions() > mImage->GetNumberOfDimensions()) {
318 mLastError = "Sorry, vector field dimension cannot be greater then reference image.";
321 if (vf->GetNumberOfDimensions() == 4) {
322 // DD(vf->GetSpacing()[3]);
323 // DD(mImage->GetSpacing()[3]);
324 // DD(vf->GetOrigin()[3]);
325 // DD(mImage->GetOrigin()[3]);
326 if (vf->GetSpacing()[3] != mImage->GetSpacing()[3]) {
327 mLastError = "Sorry, vector field time spacing cannot be different from time spacing of the reference image.";
330 if (vf->GetOrigin()[3] != mImage->GetOrigin()[3]) {
331 mLastError = "Sorry, vector field time origin cannot be different from time origin of the reference image.";
337 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
338 mSlicers[i]->SetVF(vf);
342 //----------------------------------------------------------------------------
345 //----------------------------------------------------------------------------
346 void vvSlicerManager::SetExtractedImage(std::string filename,vvImage::Pointer image, int slice)
348 mFileName = filename;
349 mImage = vvImage::New();
350 if (image->GetNumberOfDimensions() == 4) {
351 mImage->AddImage(image->GetVTKImages()[slice]);
352 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
353 mSlicers[i]->SetFileName(vtksys::SystemTools::GetFilenameWithoutLastExtension(filename));
354 mSlicers[i]->SetImage(mImage);
357 vtkImageClip* clipper = vtkImageClip::New();
359 image->GetVTKImages()[0]->GetWholeExtent(extent);
360 clipper->SetInput(image->GetVTKImages()[0]);
361 clipper->SetOutputWholeExtent(extent[0],extent[1],extent[2],extent[3],slice,slice);
363 mImage->AddImage(clipper->GetOutput());
364 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
365 mSlicers[i]->SetFileName(vtksys::SystemTools::GetFilenameWithoutLastExtension(filename));
366 mSlicers[i]->SetImage(mImage);
371 //----------------------------------------------------------------------------
374 //----------------------------------------------------------------------------
375 vvSlicer* vvSlicerManager::GetSlicer(int i)
379 //----------------------------------------------------------------------------
382 //----------------------------------------------------------------------------
383 void vvSlicerManager::UpdateSlicer(int num, bool state)
385 if (mSlicers[num]->GetImage())
386 mSlicers[num]->SetDisplayMode(state);
388 //----------------------------------------------------------------------------
391 //----------------------------------------------------------------------------
392 void vvSlicerManager::SetSlicerWindow(int i, vtkRenderWindow* RW)
394 mSlicers[i]->SetRenderWindow(i,RW);
396 //----------------------------------------------------------------------------
399 //----------------------------------------------------------------------------
400 void vvSlicerManager::SetInteractorStyleNavigator(int i, vtkInteractorStyle* style)
402 vvSlicerManagerCommand *smc = vvSlicerManagerCommand::New();
404 smc->SetSlicerNumber(i);
405 mSlicers[i]->GetRenderWindow()->GetInteractor()->SetInteractorStyle(style);
407 mSlicers[i]->GetRenderWindow()->GetInteractor()->
408 GetInteractorStyle()->AddObserver(vtkCommand::KeyPressEvent, smc);
409 mSlicers[i]->GetRenderWindow()->GetInteractor()->
410 GetInteractorStyle()->AddObserver(vtkCommand::WindowLevelEvent, smc);
411 mSlicers[i]->GetRenderWindow()->GetInteractor()->
412 GetInteractorStyle()->AddObserver(vtkCommand::EndWindowLevelEvent, smc);
413 mSlicers[i]->GetRenderWindow()->GetInteractor()->
414 GetInteractorStyle()->AddObserver(vtkCommand::StartWindowLevelEvent, smc);
415 mSlicers[i]->GetRenderWindow()->GetInteractor()->
416 GetInteractorStyle()->AddObserver(vtkCommand::PickEvent, smc);
417 mSlicers[i]->GetRenderWindow()->GetInteractor()->
418 GetInteractorStyle()->AddObserver(vtkCommand::StartPickEvent, smc);
419 mSlicers[i]->GetRenderWindow()->GetInteractor()->
420 GetInteractorStyle()->AddObserver(vtkCommand::LeaveEvent, smc);
421 mSlicers[i]->GetRenderWindow()->GetInteractor()->
422 GetInteractorStyle()->AddObserver(vtkCommand::UserEvent, smc);
423 mSlicers[i]->GetRenderWindow()->GetInteractor()->
424 GetInteractorStyle()->AddObserver(vtkCommand::MouseWheelForwardEvent, smc);
425 mSlicers[i]->GetRenderWindow()->GetInteractor()->
426 GetInteractorStyle()->AddObserver(vtkCommand::MouseWheelBackwardEvent, smc);
427 // mSlicers[i]->GetRenderWindow()->GetInteractor()->
428 // GetInteractorStyle()->AddObserver(vtkCommand::LeftButtonReleaseEvent, smc);
429 mSlicers[i]->GetRenderWindow()->GetInteractor()->
430 GetInteractorStyle()->AddObserver(vtkCommand::EndPickEvent, smc);
431 mSlicers[i]->GetRenderWindow()->GetInteractor()->
432 GetInteractorStyle()->AddObserver(vtkCommand::EndInteractionEvent, smc);
435 //----------------------------------------------------------------------------
438 //----------------------------------------------------------------------------
439 void vvSlicerManager::LeftButtonReleaseEvent(int slicer)
441 emit LeftButtonReleaseSignal(slicer);
443 //----------------------------------------------------------------------------
446 //----------------------------------------------------------------------------
447 void vvSlicerManager::SetTSlice(int slice)
451 else if (slice > mSlicers[0]->GetTMax())
452 slice = mSlicers[0]->GetTMax();
454 mLandmarks->SetTime(slice);
455 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
456 if (slice != mSlicers[i]->GetTSlice()) {
457 mSlicers[i]->SetTSlice(slice);
458 if (mSlicers[i]->GetImageActor()->GetVisibility())
463 //----------------------------------------------------------------------------
466 //----------------------------------------------------------------------------
467 void vvSlicerManager::SetNextTSlice(int originating_slicer)
469 int t = mSlicers[0]->GetTSlice();
471 if (t > mSlicers[0]->GetTMax())
473 // DD("SetNextTSlice");
474 // DD(originating_slicer);
476 emit UpdateTSlice(originating_slicer,t);
478 //----------------------------------------------------------------------------
481 //----------------------------------------------------------------------------
482 void vvSlicerManager::SetPreviousTSlice(int originating_slicer)
484 int t = mSlicers[0]->GetTSlice();
487 t = mSlicers[0]->GetTMax();
488 emit UpdateTSlice(originating_slicer,t);
490 //----------------------------------------------------------------------------
493 //----------------------------------------------------------------------------
494 void vvSlicerManager::ToggleInterpolation()
496 bool interpolate=!(mSlicers[0]->GetImageActor()->GetInterpolate());
497 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
498 mSlicers[i]->GetImageActor()->SetInterpolate(interpolate);
501 //----------------------------------------------------------------------------
504 //----------------------------------------------------------------------------
505 void vvSlicerManager::SetTSliceInSlicer(int tslice, int slicer)
509 else if (tslice > mSlicers[slicer]->GetTMax())
510 tslice = mSlicers[slicer]->GetTMax();
512 mLandmarks->SetTime(tslice);
514 if (mSlicers[slicer]->GetTSlice() == tslice) return;
516 mSlicers[slicer]->SetTSlice(tslice);
517 if (mSlicers[slicer]->GetImageActor()->GetVisibility())
518 UpdateTSlice(slicer);
520 //----------------------------------------------------------------------------
523 //----------------------------------------------------------------------------
524 void vvSlicerManager::SetColorWindow(double s)
526 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
527 mSlicers[i]->SetColorWindow(s);
530 //----------------------------------------------------------------------------
533 //----------------------------------------------------------------------------
534 void vvSlicerManager::SetColorLevel(double s)
536 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
537 mSlicers[i]->SetColorLevel(s);
540 //----------------------------------------------------------------------------
542 //----------------------------------------------------------------------------
543 void vvSlicerManager::SetCursorVisibility(int s)
545 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
546 mSlicers[i]->SetCursorVisibility(s);
549 //----------------------------------------------------------------------------
552 //----------------------------------------------------------------------------
553 void vvSlicerManager::SetOpacity(int i, double factor)
555 mSlicers[i]->SetOpacity(1/factor);
557 //----------------------------------------------------------------------------
560 //----------------------------------------------------------------------------
561 void vvSlicerManager::UpdateViews(int current,int slicer)
563 // DD("UpdateViews");
567 double x = (mSlicers[slicer]->GetCurrentPosition()[0] - mSlicers[slicer]->GetInput()->GetOrigin()[0])
568 /mSlicers[slicer]->GetInput()->GetSpacing()[0];
569 double y = (mSlicers[slicer]->GetCurrentPosition()[1] - mSlicers[slicer]->GetInput()->GetOrigin()[1])
570 /mSlicers[slicer]->GetInput()->GetSpacing()[1];
571 double z = (mSlicers[slicer]->GetCurrentPosition()[2] - mSlicers[slicer]->GetInput()->GetOrigin()[2])
572 /mSlicers[slicer]->GetInput()->GetSpacing()[2];
574 if (x >= mSlicers[slicer]->GetInput()->GetWholeExtent()[0] &&
575 x <= mSlicers[slicer]->GetInput()->GetWholeExtent()[1] &&
576 y >= mSlicers[slicer]->GetInput()->GetWholeExtent()[2] &&
577 y <= mSlicers[slicer]->GetInput()->GetWholeExtent()[3] &&
578 z >= mSlicers[slicer]->GetInput()->GetWholeExtent()[4] &&
579 z <= mSlicers[slicer]->GetInput()->GetWholeExtent()[5]) {
580 mSlicers[slicer]->UpdateCursorPosition();
581 mSlicers[slicer]->SetCursorColor(10,212,255);
583 switch (mSlicers[slicer]->GetSliceOrientation()) {
584 case vtkImageViewer2::SLICE_ORIENTATION_XY:
585 if (mSlicers[slicer]->GetSlice() == (int)floor(z))
586 mSlicers[slicer]->Render();
588 mSlicers[slicer]->SetSlice((int)floor(z));
591 case vtkImageViewer2::SLICE_ORIENTATION_XZ:
592 if (mSlicers[slicer]->GetSlice() == (int)floor(y))
593 mSlicers[slicer]->Render();
595 mSlicers[slicer]->SetSlice((int)floor(y));
598 case vtkImageViewer2::SLICE_ORIENTATION_YZ:
599 if (mSlicers[slicer]->GetSlice() == (int)floor(x))
600 mSlicers[slicer]->Render();
602 mSlicers[slicer]->SetSlice((int)floor(x));
606 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
607 if (i != (unsigned int)slicer && mSlicers[i]->GetImageActor()->GetVisibility()
608 && mSlicers[i]->GetRenderWindow()->GetSize()[0] > 2
609 && mSlicers[i]->GetRenderWindow()->GetSize()[1] > 2) {
610 mSlicers[i]->SetCurrentPosition(mSlicers[slicer]->GetCurrentPosition()[0],
611 mSlicers[slicer]->GetCurrentPosition()[1],
612 mSlicers[slicer]->GetCurrentPosition()[2],
613 mSlicers[slicer]->GetTSlice());
614 mSlicers[i]->UpdateCursorPosition();
615 if (current) { //do not display corner annotation if image is the one picked
616 mSlicers[i]->SetCurrentPosition(-VTK_DOUBLE_MAX,-VTK_DOUBLE_MAX,
617 -VTK_DOUBLE_MAX, mSlicers[slicer]->GetTSlice());
618 mSlicers[i]->SetCursorColor(255,10,212);
620 mSlicers[i]->SetCursorColor(150,10,282);
622 switch (mSlicers[i]->GetSliceOrientation()) {
623 case vtkImageViewer2::SLICE_ORIENTATION_XY:
624 if (mSlicers[i]->GetSlice() == (int)floor(z))
625 mSlicers[i]->Render();
627 mSlicers[i]->SetSlice((int)floor(z));
630 case vtkImageViewer2::SLICE_ORIENTATION_XZ:
631 if (mSlicers[i]->GetSlice() == (int)floor(y))
632 mSlicers[i]->Render();
634 mSlicers[i]->SetSlice((int)floor(y));
637 case vtkImageViewer2::SLICE_ORIENTATION_YZ:
638 if (mSlicers[i]->GetSlice() == (int)floor(x))
639 mSlicers[i]->Render();
641 mSlicers[i]->SetSlice((int)floor(x));
644 // DD("UpdateViews::");
652 //----------------------------------------------------------------------------
655 //----------------------------------------------------------------------------
656 void vvSlicerManager::UpdateLinked(int slicer)
658 double x = (mSlicers[slicer]->GetCurrentPosition()[0] - mSlicers[slicer]->GetInput()->GetOrigin()[0])
659 /mSlicers[slicer]->GetInput()->GetSpacing()[0];
660 double y = (mSlicers[slicer]->GetCurrentPosition()[1] - mSlicers[slicer]->GetInput()->GetOrigin()[1])
661 /mSlicers[slicer]->GetInput()->GetSpacing()[1];
662 double z = (mSlicers[slicer]->GetCurrentPosition()[2] - mSlicers[slicer]->GetInput()->GetOrigin()[2])
663 /mSlicers[slicer]->GetInput()->GetSpacing()[2];
665 if (x >= mSlicers[slicer]->GetInput()->GetWholeExtent()[0] &&
666 x <= mSlicers[slicer]->GetInput()->GetWholeExtent()[1] &&
667 y >= mSlicers[slicer]->GetInput()->GetWholeExtent()[2] &&
668 y <= mSlicers[slicer]->GetInput()->GetWholeExtent()[3] &&
669 z >= mSlicers[slicer]->GetInput()->GetWholeExtent()[4] &&
670 z <= mSlicers[slicer]->GetInput()->GetWholeExtent()[5]) {
671 for (std::list<std::string>::const_iterator i = mLinkedId.begin(); i != mLinkedId.end(); i++) {
672 emit UpdateLinkManager(*i, slicer,mSlicers[slicer]->GetCurrentPosition()[0],
673 mSlicers[slicer]->GetCurrentPosition()[1],
674 mSlicers[slicer]->GetCurrentPosition()[2],mSlicers[slicer]->GetTSlice());
678 //----------------------------------------------------------------------------
680 //----------------------------------------------------------------------------
681 void vvSlicerManager::UpdateLinkedNavigation(vvSlicer *slicer, bool bPropagate)
683 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
684 vtkCamera *camera = mSlicers[i] ->GetRenderer()->GetActiveCamera();
685 vtkCamera *refCam = slicer->GetRenderer()->GetActiveCamera();
686 camera->SetParallelScale(refCam->GetParallelScale());
688 double position[3], focal[3];
689 camera->GetPosition(position);
690 camera->GetFocalPoint(focal);
692 double refPosition[3], refFocal[3];
693 refCam->GetPosition(refPosition);
694 refCam->GetFocalPoint(refFocal);
696 if(slicer->GetSliceOrientation()==mSlicers[i]->GetSliceOrientation()) {
697 for(int i=0; i<3; i++) {
698 position[i] = refPosition[i];
699 focal[i] = refFocal[i];
703 if(slicer->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_XY) {
704 if(mSlicers[i]->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_XZ) {
705 position[0] = refPosition[0];
706 focal[0] = refFocal[0];
708 if(mSlicers[i]->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_YZ) {
709 position[1] = refPosition[1];
710 focal[1] = refFocal[1];
714 if(slicer->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_XZ) {
715 if(mSlicers[i]->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_YZ) {
716 position[2] = refPosition[2];
717 focal[2] = refFocal[2];
719 if(mSlicers[i]->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_XY) {
720 position[0] = refPosition[0];
721 focal[0] = refFocal[0];
725 if(slicer->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_YZ) {
726 if(mSlicers[i]->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_XY) {
727 position[1] = refPosition[1];
728 focal[1] = refFocal[1];
730 if(mSlicers[i]->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_XZ) {
731 position[2] = refPosition[2];
732 focal[2] = refFocal[2];
736 camera->SetFocalPoint(focal);
737 camera->SetPosition(position);
740 for (std::list<std::string>::const_iterator i = mLinkedId.begin(); i != mLinkedId.end(); i++)
741 emit UpdateLinkedNavigation(*i, this);
745 //----------------------------------------------------------------------------
747 //----------------------------------------------------------------------------
748 double vvSlicerManager::GetColorWindow()
751 return mSlicers[0]->GetColorWindow();
754 //----------------------------------------------------------------------------
757 //----------------------------------------------------------------------------
758 double vvSlicerManager::GetColorLevel()
761 return mSlicers[0]->GetColorLevel();
764 //----------------------------------------------------------------------------
767 //----------------------------------------------------------------------------
768 void vvSlicerManager::Render()
770 // DD("vvSlicerManager::Render");
771 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
773 mSlicers[i]->Render();
776 //----------------------------------------------------------------------------
779 //----------------------------------------------------------------------------
780 void vvSlicerManager::GenerateDefaultLookupTable()
783 SetColorMap(mColorMap);
785 //----------------------------------------------------------------------------
788 //----------------------------------------------------------------------------
789 void vvSlicerManager::Reload()
791 mReader->Update(mType);
792 mImage=mReader->GetOutput();
793 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
794 mSlicers[i]->SetImage(mImage);
797 //----------------------------------------------------------------------------
800 //----------------------------------------------------------------------------
801 void vvSlicerManager::ReloadFusion()
803 mFusionReader->Update();
804 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
805 mSlicers[i]->SetFusion(mFusionReader->GetOutput());
806 mSlicers[i]->Render();
809 //----------------------------------------------------------------------------
812 //----------------------------------------------------------------------------
813 void vvSlicerManager::ReloadOverlay()
815 mOverlayReader->Update();
816 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
817 mSlicers[i]->SetOverlay(mOverlayReader->GetOutput());
818 mSlicers[i]->Render();
821 //----------------------------------------------------------------------------
824 //----------------------------------------------------------------------------
825 void vvSlicerManager::ReloadVF()
827 mVectorReader->Update(VECTORFIELD); //deletes the old images through the VF::Init() function
828 mVF=mVectorReader->GetOutput();
829 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
830 mSlicers[i]->SetVF(mVF);
831 mSlicers[i]->Render();
834 //----------------------------------------------------------------------------
837 //----------------------------------------------------------------------------
838 void vvSlicerManager::RemoveActor(const std::string& actor_type, int overlay_index)
840 for (unsigned int i = 0; i < mSlicers.size(); i++) {
841 mSlicers[i]->RemoveActor(actor_type,overlay_index);
843 if (actor_type=="vector") {
846 delete mVectorReader;
851 //----------------------------------------------------------------------------
854 //----------------------------------------------------------------------------
855 void vvSlicerManager::RemoveActors()
857 ///This method leaks a few objects. See RemoveActor for what a correct implementation would look like
858 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
859 mSlicers[i]->SetDisplayMode(0);
860 mSlicers[i]->GetRenderer()->RemoveActor(mSlicers[i]->GetImageActor());
863 //----------------------------------------------------------------------------
866 //----------------------------------------------------------------------------
867 void vvSlicerManager::UpdateInfoOnCursorPosition(int slicer)
869 // int view = mSlicers[slicer]->GetSliceOrientation();
870 // int slice = mSlicers[slicer]->GetSlice();
871 double x = mSlicers[slicer]->GetCursorPosition()[0];
872 double y = mSlicers[slicer]->GetCursorPosition()[1];
873 double z = mSlicers[slicer]->GetCursorPosition()[2];
874 double X = (x - mSlicers[slicer]->GetInput()->GetOrigin()[0])/
875 mSlicers[slicer]->GetInput()->GetSpacing()[0];
876 double Y = (y - mSlicers[slicer]->GetInput()->GetOrigin()[1])/
877 mSlicers[slicer]->GetInput()->GetSpacing()[1];
878 double Z = (z - mSlicers[slicer]->GetInput()->GetOrigin()[2])/
879 mSlicers[slicer]->GetInput()->GetSpacing()[2];
880 double value = -VTK_DOUBLE_MAX;
882 double xVec=0, yVec=0, zVec=0, valueVec=0;
885 double valueOver=0, valueFus=0;
886 if (X >= mSlicers[slicer]->GetInput()->GetWholeExtent()[0] &&
887 X <= mSlicers[slicer]->GetInput()->GetWholeExtent()[1] &&
888 Y >= mSlicers[slicer]->GetInput()->GetWholeExtent()[2] &&
889 Y <= mSlicers[slicer]->GetInput()->GetWholeExtent()[3] &&
890 Z >= mSlicers[slicer]->GetInput()->GetWholeExtent()[4] &&
891 Z <= mSlicers[slicer]->GetInput()->GetWholeExtent()[5]) {
892 value = mSlicers[slicer]->GetInput()->GetScalarComponentAsDouble(
896 if (mSlicers[slicer]->GetVFActor() && mSlicers[slicer]->GetVFActor()->GetVisibility()) {
898 unsigned int currentTime = mSlicers[slicer]->GetTSlice();
899 vtkImageData *vf = NULL;
901 if (mSlicers[slicer]->GetVF()->GetVTKImages().size() > currentTime)
902 vf = mSlicers[slicer]->GetVF()->GetVTKImages()[currentTime];
904 vf = mSlicers[slicer]->GetVF()->GetVTKImages()[0];
907 double Xvf = (x - vf->GetOrigin()[0])/ vf->GetSpacing()[0];
908 double Yvf = (y - vf->GetOrigin()[1])/ vf->GetSpacing()[1];
909 double Zvf = (z - vf->GetOrigin()[2])/ vf->GetSpacing()[2];
910 xVec = vf->GetScalarComponentAsDouble( (int)floor(Xvf), (int)floor(Yvf), (int)floor(Zvf),0);
911 yVec = vf->GetScalarComponentAsDouble( (int)floor(Xvf), (int)floor(Yvf), (int)floor(Zvf),1);
912 zVec = vf->GetScalarComponentAsDouble( (int)floor(Xvf), (int)floor(Yvf), (int)floor(Zvf),2);
913 valueVec = sqrt(xVec*xVec + yVec*yVec + zVec*zVec);
916 if (mSlicers[slicer]->GetOverlayActor() && mSlicers[slicer]->GetOverlayActor()->GetVisibility()) {
918 double Xover = (x - mSlicers[slicer]->GetOverlay()->GetOrigin()[0])
919 /mSlicers[slicer]->GetOverlay()->GetSpacing()[0];
920 double Yover = (y - mSlicers[slicer]->GetOverlay()->GetOrigin()[1])
921 /mSlicers[slicer]->GetOverlay()->GetSpacing()[1];
922 double Zover = (z - mSlicers[slicer]->GetOverlay()->GetOrigin()[2])
923 /mSlicers[slicer]->GetOverlay()->GetSpacing()[2];
924 if (Xover >= mSlicers[slicer]->GetOverlayMapper()->GetInput()->GetWholeExtent()[0] &&
925 Xover <= mSlicers[slicer]->GetOverlayMapper()->GetInput()->GetWholeExtent()[1] &&
926 Yover >= mSlicers[slicer]->GetOverlayMapper()->GetInput()->GetWholeExtent()[2] &&
927 Yover <= mSlicers[slicer]->GetOverlayMapper()->GetInput()->GetWholeExtent()[3] &&
928 Zover >= mSlicers[slicer]->GetOverlayMapper()->GetInput()->GetWholeExtent()[4] &&
929 Zover <= mSlicers[slicer]->GetOverlayMapper()->GetInput()->GetWholeExtent()[5]) {
930 valueOver = static_cast<vtkImageData*>(mSlicers[slicer]->GetOverlayMapper()->GetInput())->
931 GetScalarComponentAsDouble(
934 (int)floor(Zover),0);
937 if (mSlicers[slicer]->GetFusionActor() && mSlicers[slicer]->GetFusionActor()->GetVisibility()) {
939 double Xfus = (x - mSlicers[slicer]->GetFusion()->GetOrigin()[0])
940 /mSlicers[slicer]->GetFusion()->GetSpacing()[0];
941 double Yfus = (y - mSlicers[slicer]->GetFusion()->GetOrigin()[1])
942 /mSlicers[slicer]->GetFusion()->GetSpacing()[1];
943 double Zfus = (z - mSlicers[slicer]->GetFusion()->GetOrigin()[2])
944 /mSlicers[slicer]->GetFusion()->GetSpacing()[2];
945 if (Xfus >= mSlicers[slicer]->GetFusionMapper()->GetInput()->GetWholeExtent()[0] &&
946 Xfus <= mSlicers[slicer]->GetFusionMapper()->GetInput()->GetWholeExtent()[1] &&
947 Yfus >= mSlicers[slicer]->GetFusionMapper()->GetInput()->GetWholeExtent()[2] &&
948 Yfus <= mSlicers[slicer]->GetFusionMapper()->GetInput()->GetWholeExtent()[3] &&
949 Zfus >= mSlicers[slicer]->GetFusionMapper()->GetInput()->GetWholeExtent()[4] &&
950 Zfus <= mSlicers[slicer]->GetFusionMapper()->GetInput()->GetWholeExtent()[5]) {
951 valueFus = static_cast<vtkImageData*>(mSlicers[slicer]->GetFusionMapper()->GetInput())->
952 GetScalarComponentAsDouble(
958 emit UpdatePosition(mSlicers[slicer]->GetCursorVisibility(),
960 emit UpdateVector(displayVec,xVec, yVec, zVec, valueVec);
961 emit UpdateOverlay(displayOver,valueOver,value);
962 emit UpdateFusion(displayFus,valueFus);
963 for (unsigned int i = 0; i < mSlicers.size(); i++) {
964 if (mSlicers[i]->GetImageActor()->GetVisibility() == 1)
965 emit UpdateWindows(i,mSlicers[i]->GetSliceOrientation(),mSlicers[i]->GetSlice());
967 emit UpdateWindows(i,-1,-1);
971 //----------------------------------------------------------------------------
974 //----------------------------------------------------------------------------
975 void vvSlicerManager::Activated()
977 emit currentImageChanged(mId);
979 //----------------------------------------------------------------------------
982 //----------------------------------------------------------------------------
983 void vvSlicerManager::UpdateWindowLevel()
985 emit WindowLevelChanged(mSlicers[0]->GetColorWindow(),mSlicers[0]->GetColorLevel(),mPreset,mColorMap);
987 //----------------------------------------------------------------------------
990 //----------------------------------------------------------------------------
991 void vvSlicerManager::UpdateSlice(int slicer)
993 // DD("vvSlicerManager::UpdateSlice emit UpdateSlice");
995 // DD(mSlicers[slicer]->GetSlice());
996 if (mPreviousSlice[slicer] == mSlicers[slicer]->GetSlice()) {
997 //DD("============= NOTHING");
1000 emit UpdateSlice(slicer, mSlicers[slicer]->GetSlice());
1001 mSlicers[slicer]->Render(); // DS <-- I add this, this could/must be the only Render ...
1002 mPreviousSlice[slicer] = mSlicers[slicer]->GetSlice();
1004 //----------------------------------------------------------------------------
1007 //----------------------------------------------------------------------------
1008 void vvSlicerManager::UpdateTSlice(int slicer)
1010 // DD("vvSlicerManager::UpdateTSlice emit UpdateTSlice");
1012 // DD(mSlicers[slicer]->GetTSlice());
1013 // DD(mSlicers[slicer]->GetSlice());
1014 if (mPreviousSlice[slicer] == mSlicers[slicer]->GetSlice()) {
1015 if (mPreviousTSlice[slicer] == mSlicers[slicer]->GetTSlice()) {
1016 // DD("************** NOTHING ***********");
1020 mPreviousSlice[slicer] = mSlicers[slicer]->GetSlice();
1021 mPreviousTSlice[slicer] = mSlicers[slicer]->GetTSlice();
1022 emit UpdateTSlice(slicer,mSlicers[slicer]->GetTSlice());
1024 //----------------------------------------------------------------------------
1027 //----------------------------------------------------------------------------
1028 void vvSlicerManager::UpdateSliceRange(int slicer)
1030 emit UpdateSliceRange(slicer,
1031 mSlicers[slicer]->GetSliceRange()[0], mSlicers[slicer]->GetSliceRange()[1],
1032 0,mSlicers[slicer]->GetTMax());
1034 //----------------------------------------------------------------------------
1037 //----------------------------------------------------------------------------
1038 void vvSlicerManager::SetPreset(int preset)
1040 //vtkLookupTable* LUT = static_cast<vtkLookupTable*>(mSlicers[0]->GetWindowLevel()->GetLookupTable());
1041 double window = mSlicers[0]->GetColorWindow();
1042 double level = mSlicers[0]->GetColorLevel();
1044 std::string component_type=mImage->GetScalarTypeAsITKString();
1047 if (component_type == "unsigned_char") {
1050 } else if (component_type == "short") {
1055 mImage->GetScalarRange(range);
1056 window = range[1] - range[0];
1057 level = (range[1] + range[0])* 0.5;
1088 this->SetColorWindow(window);
1089 this->SetColorLevel(level);
1096 //----------------------------------------------------------------------------
1099 //----------------------------------------------------------------------------
1100 void vvSlicerManager::SetLocalColorWindowing(const int slicer)
1103 this->mSlicers[slicer]->GetExtremasAroundMousePointer(min, max);
1104 this->SetColorWindow(max-min);
1105 this->SetColorLevel(0.5*(min+max));
1106 this->UpdateWindowLevel();
1109 //----------------------------------------------------------------------------
1112 //----------------------------------------------------------------------------
1113 void vvSlicerManager::SetColorMap()
1115 SetColorMap(mColorMap);
1117 //----------------------------------------------------------------------------
1120 //----------------------------------------------------------------------------
1121 void vvSlicerManager::SetColorMap(int colormap)
1124 range[0] = mSlicers[0]->GetInput()->GetScalarRange()[0];
1125 range[1] = mSlicers[0]->GetInput()->GetScalarRange()[1];
1127 double window = mSlicers[0]->GetWindowLevel()->GetWindow();
1128 double level = mSlicers[0]->GetWindowLevel()->GetLevel();
1130 vtkLookupTable* LUT = static_cast<vtkLookupTable*>(mSlicers[0]->GetWindowLevel()->GetLookupTable());
1139 LUT = vtkLookupTable::New();
1140 LUT->SetValueRange(0,1);
1141 LUT->SetSaturationRange(1,1);
1142 LUT->SetHueRange(0,0.18);
1146 LUT = vtkLookupTable::New();
1147 LUT->SetValueRange(0,1);
1148 LUT->SetSaturationRange(1,1);
1149 LUT->SetHueRange(0.4,0.80);
1153 LUT = vtkLookupTable::New();
1154 LUT->SetValueRange(0,1);
1155 LUT->SetSaturationRange(1,1);
1156 LUT->SetHueRange(0,1);
1160 LUT = vtkLookupTable::New();
1161 LUT->SetValueRange(0.,1);
1162 LUT->SetSaturationRange(1,1);
1163 LUT->SetHueRange(1,0.1);
1164 //LUT->SetRampToLinear();
1168 LUT->SetTableRange(level-fabs(window)/4,level+fabs(window)/4);
1171 vtkLookupTable* fusLUT = NULL;
1172 if (mSlicers[0]->GetFusion()) {
1173 fusLUT = vtkLookupTable::New();
1174 double fusRange [2];
1175 fusRange[0] = mFusionLevel - mFusionWindow/2;
1176 fusRange[1] = mFusionLevel + mFusionWindow/2;
1177 fusLUT->SetTableRange(fusRange[0],fusRange[1]);
1178 fusLUT->SetValueRange(1,1);
1179 fusLUT->SetSaturationRange(1,1);
1180 if (mFusionColorMap == 1)
1181 fusLUT->SetHueRange(0,0.18);
1182 else if (mFusionColorMap == 2)
1183 fusLUT->SetHueRange(0.4,0.80);
1184 else if (mFusionColorMap == 3)
1185 fusLUT->SetHueRange(0,1);
1187 if (mFusionColorMap == 0)
1190 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
1191 if (mSlicers[i]->GetOverlay() && mSlicers[i]->GetOverlayActor()->GetVisibility()) {
1192 vtkLookupTable* supLUT = vtkLookupTable::New();
1193 supLUT->SetTableRange(range[0],range[1]);
1194 supLUT->SetValueRange(1,1);
1195 supLUT->SetSaturationRange(1,1);
1196 supLUT->SetHueRange(double(mOverlayColor)/360,double(mOverlayColor)/360);
1198 vtkLookupTable* invLUT = vtkLookupTable::New();
1199 invLUT->SetTableRange(range[0],range[1]);
1200 invLUT->SetValueRange(1,1);
1201 invLUT->SetSaturationRange(1,1);
1202 invLUT->SetHueRange(double((mOverlayColor+180)%360)/360,double((mOverlayColor+180)%360)/360);
1204 dynamic_cast<vvImageMapToWLColors*>(mSlicers[i]->GetWindowLevel())
1205 ->SetWindowLevelMode(true);
1206 mSlicers[i]->GetWindowLevel()->SetLookupTable(supLUT);
1207 mSlicers[i]->GetOverlayMapper()->SetLookupTable(invLUT);
1210 } else if (mSlicers[i]->GetOverlay()) {
1211 //dynamic_cast<vvImageMapToWLColors*>(mSlicers[i]->GetWindowLevel())
1212 //->SetWindowLevelMode(false);
1213 mSlicers[i]->GetWindowLevel()->SetLookupTable(LUT);
1215 mSlicers[i]->GetWindowLevel()->SetLookupTable(LUT);
1217 if (mSlicers[i]->GetFusion() && mSlicers[i]->GetFusionActor()->GetVisibility()) {
1218 mSlicers[i]->GetFusionActor()->SetOpacity(double(mFusionOpacity)/100);
1219 mSlicers[i]->GetFusionMapper()->SetLookupTable(fusLUT);
1225 mColorMap = colormap;
1227 //----------------------------------------------------------------------------
1230 //----------------------------------------------------------------------------
1231 vvLandmarks* vvSlicerManager::GetLandmarks()
1233 if (mLandmarks == NULL) {
1234 mLandmarks = new vvLandmarks(mSlicers[0]->GetTMax()+1);
1235 for (unsigned int i = 0; i < mSlicers.size(); i++)
1236 mSlicers[i]->SetLandmarks(mLandmarks);
1240 //----------------------------------------------------------------------------
1243 //----------------------------------------------------------------------------
1244 void vvSlicerManager::AddLandmark(float x,float y,float z,float t)
1246 double x_index = (x - mSlicers[0]->GetInput()->GetOrigin()[0])/mSlicers[0]->GetInput()->GetSpacing()[0];
1247 double y_index = (y - mSlicers[0]->GetInput()->GetOrigin()[1])/mSlicers[0]->GetInput()->GetSpacing()[1];
1248 double z_index = (z - mSlicers[0]->GetInput()->GetOrigin()[2])/mSlicers[0]->GetInput()->GetSpacing()[2];
1249 if (x_index >= mSlicers[0]->GetInput()->GetWholeExtent()[0] &&
1250 x_index <= mSlicers[0]->GetInput()->GetWholeExtent()[1] &&
1251 y_index >= mSlicers[0]->GetInput()->GetWholeExtent()[2] &&
1252 y_index <= mSlicers[0]->GetInput()->GetWholeExtent()[3] &&
1253 z_index >= mSlicers[0]->GetInput()->GetWholeExtent()[4] &&
1254 z_index <= mSlicers[0]->GetInput()->GetWholeExtent()[5]) {
1255 double value = mSlicers[0]->GetInput()->GetScalarComponentAsDouble(
1259 this->GetLandmarks()->AddLandmark(x,y,z,t,value);
1260 emit LandmarkAdded();
1263 //----------------------------------------------------------------------------
1265 //----------------------------------------------------------------------------
1266 void vvSlicerManager::PrevImage(int slicer)
1268 emit ChangeImageWithIndexOffset(this, slicer, -1);
1270 //----------------------------------------------------------------------------
1273 //----------------------------------------------------------------------------
1274 void vvSlicerManager::NextImage(int slicer)
1276 emit ChangeImageWithIndexOffset(this, slicer, 1);
1278 //----------------------------------------------------------------------------
1281 //----------------------------------------------------------------------------
1282 void vvSlicerManager::VerticalSliderHasChanged(int slicer, int slice)
1284 emit AVerticalSliderHasChanged(slicer, slice);
1287 //----------------------------------------------------------------------------