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"
26 #include "vvImageMapToWLColors.h"
27 #include "vvBlendImageActor.h"
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>
43 //----------------------------------------------------------------------------
44 vvSlicerManager::vvSlicerManager(int numberOfSlicers)
53 mType = UNDEFINEDIMAGETYPE;
66 for ( int i = 0; i < numberOfSlicers; i++)
67 mSlicers.push_back(vtkSmartPointer<vvSlicer>::New());
69 mPreviousSlice.resize(numberOfSlicers);
70 mPreviousTSlice.resize(numberOfSlicers);
72 //----------------------------------------------------------------------------
75 //----------------------------------------------------------------------------
76 vvSlicerManager::~vvSlicerManager()
81 //----------------------------------------------------------------------------
84 //------------------------------------------------------------------------------
85 void vvSlicerManager::SetFilename(std::string filename, int number)
88 mFileName = vtksys::SystemTools::GetFilenameName(mFileName);
89 mBaseFileName = vtksys::SystemTools::GetFilenameName(vtksys::SystemTools::GetFilenameWithoutLastExtension(mFileName));
90 mBaseFileNameNumber = number;
92 mFileName = mBaseFileName;
94 mFileName.append("_"+clitk::toString(number));
96 mFileName.append(vtksys::SystemTools::GetFilenameLastExtension(filename));
98 for(unsigned int i=0; i<mSlicers.size(); i++) {
99 mSlicers[i]->SetFileName(mFileName);//vtksys::SystemTools::GetFilenameWithoutLastExtension(filename));
103 //------------------------------------------------------------------------------
106 //----------------------------------------------------------------------------
107 void vvSlicerManager::AddContour(vvMesh::Pointer contour,bool propagate)
109 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
110 mSlicers[i]->AddContour(contour,propagate);
113 //----------------------------------------------------------------------------
116 //----------------------------------------------------------------------------
117 void vvSlicerManager::ToggleContourSuperposition()
119 for ( unsigned int i = 0; i < mSlicers.size(); i++)
120 mSlicers[i]->ToggleContourSuperposition();
122 //----------------------------------------------------------------------------
125 //----------------------------------------------------------------------------
126 bool vvSlicerManager::SetImage(std::string filename, LoadedImageType type, int n, unsigned int slice)
129 if (mReader.IsNull())
130 mReader = vvImageReader::New();
131 std::vector<std::string> filenames;
132 filenames.push_back(filename);
133 mReader->SetInputFilenames(filenames);
134 mReader->SetSlice(slice); // Only used for SLICED type
135 mReader->Update(type);
137 SetFilename(filename, n);
138 // mFileName = vtksys::SystemTools::GetFilenameName(mFileName);
139 //mBaseFileName = vtksys::SystemTools::GetFilenameName(vtksys::SystemTools::GetFilenameWithoutLastExtension(mFileName));
140 //mBaseFileNameNumber = n;
142 if (mReader->GetLastError().size() == 0) {
143 mImage=mReader->GetOutput();
144 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
145 mSlicers[i]->SetFileName(vtksys::SystemTools::GetFilenameWithoutLastExtension(filename));
146 mSlicers[i]->SetImage(mReader->GetOutput());
149 mLastError = mReader->GetLastError();
153 // mFileName.append("_"+clitk::toString(n));
157 //----------------------------------------------------------------------------
160 //----------------------------------------------------------------------------
161 void vvSlicerManager::SetImage(vvImage::Pointer image)
164 for (unsigned int i = 0; i < mSlicers.size(); i++) {
165 mSlicers[i]->SetImage(image);
168 //----------------------------------------------------------------------------
171 //----------------------------------------------------------------------------
172 bool vvSlicerManager::SetImages(std::vector<std::string> filenames,LoadedImageType type, int n)
175 std::string fileWithoutExtension = vtksys::SystemTools::GetFilenameWithoutExtension(filenames[0]);
177 fileWithoutExtension += "_dicom";
178 else if (type == MERGED)
179 fileWithoutExtension += "_merged";
180 else if (type == MERGEDWITHTIME)
181 fileWithoutExtension += "_merged_wt";
183 mFileName = vtksys::SystemTools::GetFilenameName(mFileName);
184 mFileName = fileWithoutExtension + vtksys::SystemTools::GetFilenameExtension(filenames[0]);
185 if (mReader.IsNull())
186 mReader = vvImageReader::New();
187 mReader->SetInputFilenames(filenames);
188 mReader->Update(type);
190 mBaseFileName = vtksys::SystemTools::GetFilenameName(vtksys::SystemTools::GetFilenameWithoutLastExtension(mFileName));
191 mBaseFileNameNumber = n;
193 if (mReader->GetLastError().size() == 0) {
194 mImage=mReader->GetOutput();
195 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
196 mSlicers[i]->SetFileName(fileWithoutExtension);
197 mSlicers[i]->SetImage(mReader->GetOutput());
200 mLastError = mReader->GetLastError();
204 mFileName.append("_"+clitk::toString(n));
208 //----------------------------------------------------------------------------
211 //----------------------------------------------------------------------------
212 bool vvSlicerManager::SetOverlay(std::string filename,int dim, std::string component)
214 mOverlayName = filename;
215 mOverlayComponent = component;
216 if (dim > mImage->GetNumberOfDimensions()) {
217 mLastError = " Overlay dimension cannot be greater then reference image!";
220 if (mOverlayReader.IsNull())
221 mOverlayReader = vvImageReader::New();
222 std::vector<std::string> filenames;
223 filenames.push_back(filename);
224 mOverlayReader->SetInputFilenames(filenames);
225 mOverlayReader->Update(mImage->GetNumberOfDimensions(),component.c_str(),mType);
226 if (mOverlayReader->GetLastError().size() == 0) {
227 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
228 mSlicers[i]->SetOverlay(mOverlayReader->GetOutput());
231 mLastError = mOverlayReader->GetLastError();
236 //----------------------------------------------------------------------------
239 //----------------------------------------------------------------------------
240 bool vvSlicerManager::SetFusion(std::string filename,int dim, std::string component)
242 mFusionName = filename;
243 mFusionComponent = component;
244 if (dim > mImage->GetNumberOfDimensions()) {
245 mLastError = " Overlay dimension cannot be greater then reference image!";
248 if (mFusionReader.IsNull())
249 mFusionReader = vvImageReader::New();
250 std::vector<std::string> filenames;
251 filenames.push_back(filename);
252 mFusionReader->SetInputFilenames(filenames);
253 mFusionReader->Update(mImage->GetNumberOfDimensions(),component.c_str(),mType);
254 if (mFusionReader->GetLastError().size() == 0) {
255 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
256 mSlicers[i]->SetFusion(mFusionReader->GetOutput());
259 mLastError = mFusionReader->GetLastError();
262 double *fusRange = mFusionReader->GetOutput()->GetVTKImages()[0]->GetScalarRange();
263 mFusionLevel = (fusRange[0]+fusRange[1])/2;
264 mFusionWindow = fusRange[1]-fusRange[0];
267 //----------------------------------------------------------------------------
270 //----------------------------------------------------------------------------
271 bool vvSlicerManager::SetVF(std::string filename)
273 if (mVectorReader.IsNull())
274 mVectorReader = vvImageReader::New();
275 mVectorReader->SetInputFilename(filename);
276 mVectorReader->Update(VECTORFIELD);
277 if (mVectorReader->GetLastError().size() != 0) {
278 mLastError = mVectorReader->GetLastError();
281 return SetVF(mVectorReader->GetOutput(),filename);
283 //----------------------------------------------------------------------------
286 //----------------------------------------------------------------------------
287 bool vvSlicerManager::SetVF(vvImage::Pointer vf,std::string filename)
289 if (vf->GetNumberOfDimensions() > mImage->GetNumberOfDimensions()) {
290 mLastError = "Sorry, vector field dimension cannot be greater then reference image.";
293 if (vf->GetNumberOfDimensions() == 4) {
294 if (vf->GetSpacing()[3] != mImage->GetSpacing()[3]) {
295 mLastError = "Sorry, vector field time spacing cannot be different from time spacing of the reference image.";
298 if (vf->GetOrigin()[3] != mImage->GetOrigin()[3]) {
299 mLastError = "Sorry, vector field time origin cannot be different from time origin of the reference image.";
305 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
306 mSlicers[i]->SetVF(vf);
310 //----------------------------------------------------------------------------
313 //----------------------------------------------------------------------------
314 vvSlicer* vvSlicerManager::GetSlicer(int i)
318 //----------------------------------------------------------------------------
321 //----------------------------------------------------------------------------
322 void vvSlicerManager::UpdateSlicer(int num, bool state)
324 if (mSlicers[num]->GetImage())
325 mSlicers[num]->SetDisplayMode(state);
327 //----------------------------------------------------------------------------
330 //----------------------------------------------------------------------------
331 void vvSlicerManager::SetSlicerWindow(int i, vtkRenderWindow* RW)
333 mSlicers[i]->SetRenderWindow(i,RW);
335 //----------------------------------------------------------------------------
338 //----------------------------------------------------------------------------
339 void vvSlicerManager::SetInteractorStyleNavigator(int i, vtkInteractorStyle* style)
341 vvSlicerManagerCommand *smc = vvSlicerManagerCommand::New();
343 smc->SetSlicerNumber(i);
344 mSlicers[i]->GetRenderWindow()->GetInteractor()->SetInteractorStyle(style);
346 mSlicers[i]->GetRenderWindow()->GetInteractor()->
347 GetInteractorStyle()->AddObserver(vtkCommand::KeyPressEvent, smc);
348 mSlicers[i]->GetRenderWindow()->GetInteractor()->
349 GetInteractorStyle()->AddObserver(vtkCommand::WindowLevelEvent, smc);
350 mSlicers[i]->GetRenderWindow()->GetInteractor()->
351 GetInteractorStyle()->AddObserver(vtkCommand::EndWindowLevelEvent, smc);
352 mSlicers[i]->GetRenderWindow()->GetInteractor()->
353 GetInteractorStyle()->AddObserver(vtkCommand::StartWindowLevelEvent, smc);
354 mSlicers[i]->GetRenderWindow()->GetInteractor()->
355 GetInteractorStyle()->AddObserver(vtkCommand::PickEvent, smc);
356 mSlicers[i]->GetRenderWindow()->GetInteractor()->
357 GetInteractorStyle()->AddObserver(vtkCommand::StartPickEvent, smc);
358 mSlicers[i]->GetRenderWindow()->GetInteractor()->
359 GetInteractorStyle()->AddObserver(vtkCommand::LeaveEvent, smc);
360 mSlicers[i]->GetRenderWindow()->GetInteractor()->
361 GetInteractorStyle()->AddObserver(vtkCommand::UserEvent, smc);
362 mSlicers[i]->GetRenderWindow()->GetInteractor()->
363 GetInteractorStyle()->AddObserver(vtkCommand::MouseWheelForwardEvent, smc);
364 mSlicers[i]->GetRenderWindow()->GetInteractor()->
365 GetInteractorStyle()->AddObserver(vtkCommand::MouseWheelBackwardEvent, smc);
366 // mSlicers[i]->GetRenderWindow()->GetInteractor()->
367 // GetInteractorStyle()->AddObserver(vtkCommand::LeftButtonReleaseEvent, smc);
368 mSlicers[i]->GetRenderWindow()->GetInteractor()->
369 GetInteractorStyle()->AddObserver(vtkCommand::EndPickEvent, smc);
370 mSlicers[i]->GetRenderWindow()->GetInteractor()->
371 GetInteractorStyle()->AddObserver(vtkCommand::EndInteractionEvent, smc);
374 //----------------------------------------------------------------------------
377 //----------------------------------------------------------------------------
378 void vvSlicerManager::LeftButtonReleaseEvent(int slicer)
380 emit LeftButtonReleaseSignal(slicer);
382 //----------------------------------------------------------------------------
385 //----------------------------------------------------------------------------
386 void vvSlicerManager::SetTSlice(int slice)
390 else if (slice > mSlicers[0]->GetTMax())
391 slice = mSlicers[0]->GetTMax();
393 mLandmarks->SetTime(slice);
394 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
395 if (slice != mSlicers[i]->GetTSlice()) {
396 mSlicers[i]->SetTSlice(slice);
397 if (mSlicers[i]->GetImageActor()->GetVisibility())
402 //----------------------------------------------------------------------------
405 //----------------------------------------------------------------------------
406 void vvSlicerManager::SetNextTSlice(int originating_slicer)
408 int t = mSlicers[0]->GetTSlice();
410 if (t > mSlicers[0]->GetTMax())
412 emit UpdateTSlice(originating_slicer,t);
414 //----------------------------------------------------------------------------
417 //----------------------------------------------------------------------------
418 void vvSlicerManager::SetPreviousTSlice(int originating_slicer)
420 int t = mSlicers[0]->GetTSlice();
423 t = mSlicers[0]->GetTMax();
424 emit UpdateTSlice(originating_slicer,t);
426 //----------------------------------------------------------------------------
429 //----------------------------------------------------------------------------
430 void vvSlicerManager::ToggleInterpolation()
432 bool interpolate=!(mSlicers[0]->GetImageActor()->GetInterpolate());
433 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
434 mSlicers[i]->GetImageActor()->SetInterpolate(interpolate);
435 if (mSlicers[i]->GetOverlayActor())
436 mSlicers[i]->GetOverlayActor()->SetInterpolate(interpolate);
437 if (mSlicers[i]->GetFusionActor())
438 mSlicers[i]->GetFusionActor()->SetInterpolate(interpolate);
441 //----------------------------------------------------------------------------
444 //----------------------------------------------------------------------------
445 void vvSlicerManager::SetTSliceInSlicer(int tslice, int slicer)
449 else if (tslice > mSlicers[slicer]->GetTMax())
450 tslice = mSlicers[slicer]->GetTMax();
452 mLandmarks->SetTime(tslice);
454 if (mSlicers[slicer]->GetTSlice() == tslice) return;
456 mSlicers[slicer]->SetTSlice(tslice);
457 if (mSlicers[slicer]->GetImageActor()->GetVisibility())
458 UpdateTSlice(slicer);
460 //----------------------------------------------------------------------------
463 //----------------------------------------------------------------------------
464 void vvSlicerManager::SetColorWindow(double s)
466 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
467 mSlicers[i]->SetColorWindow(s);
470 //----------------------------------------------------------------------------
473 //----------------------------------------------------------------------------
474 void vvSlicerManager::SetColorLevel(double s)
476 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
477 mSlicers[i]->SetColorLevel(s);
480 //----------------------------------------------------------------------------
482 //----------------------------------------------------------------------------
483 void vvSlicerManager::SetCursorAndCornerAnnotationVisibility(int s)
485 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
486 mSlicers[i]->SetCursorVisibility(s);
487 mSlicers[i]->SetCornerAnnotationVisibility(s);
490 //----------------------------------------------------------------------------
492 //----------------------------------------------------------------------------
493 void vvSlicerManager::SetOpacity(int i, double factor)
495 mSlicers[i]->SetOpacity(1/factor);
497 //----------------------------------------------------------------------------
500 //----------------------------------------------------------------------------
501 void vvSlicerManager::UpdateViews(int current,int slicer)
503 double x = (mSlicers[slicer]->GetCurrentPosition()[0] - mSlicers[slicer]->GetInput()->GetOrigin()[0])
504 /mSlicers[slicer]->GetInput()->GetSpacing()[0];
505 double y = (mSlicers[slicer]->GetCurrentPosition()[1] - mSlicers[slicer]->GetInput()->GetOrigin()[1])
506 /mSlicers[slicer]->GetInput()->GetSpacing()[1];
507 double z = (mSlicers[slicer]->GetCurrentPosition()[2] - mSlicers[slicer]->GetInput()->GetOrigin()[2])
508 /mSlicers[slicer]->GetInput()->GetSpacing()[2];
510 if (x >= mSlicers[slicer]->GetInput()->GetWholeExtent()[0] &&
511 x <= mSlicers[slicer]->GetInput()->GetWholeExtent()[1] &&
512 y >= mSlicers[slicer]->GetInput()->GetWholeExtent()[2] &&
513 y <= mSlicers[slicer]->GetInput()->GetWholeExtent()[3] &&
514 z >= mSlicers[slicer]->GetInput()->GetWholeExtent()[4] &&
515 z <= mSlicers[slicer]->GetInput()->GetWholeExtent()[5]) {
516 mSlicers[slicer]->UpdateCursorPosition();
517 mSlicers[slicer]->SetCursorColor(10,212,255);
519 switch (mSlicers[slicer]->GetSliceOrientation()) {
520 case vtkImageViewer2::SLICE_ORIENTATION_XY:
521 if (mSlicers[slicer]->GetSlice() != (int)floor(z))
522 mSlicers[slicer]->SetSlice((int)floor(z));
525 case vtkImageViewer2::SLICE_ORIENTATION_XZ:
526 if (mSlicers[slicer]->GetSlice() != (int)floor(y))
527 mSlicers[slicer]->SetSlice((int)floor(y));
530 case vtkImageViewer2::SLICE_ORIENTATION_YZ:
531 if (mSlicers[slicer]->GetSlice() != (int)floor(x))
532 mSlicers[slicer]->SetSlice((int)floor(x));
535 mSlicers[slicer]->Render();
537 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
538 if (i != (unsigned int)slicer && mSlicers[i]->GetImageActor()->GetVisibility()
539 && mSlicers[i]->GetRenderWindow()->GetSize()[0] > 2
540 && mSlicers[i]->GetRenderWindow()->GetSize()[1] > 2) {
541 mSlicers[i]->SetCurrentPosition(mSlicers[slicer]->GetCurrentPosition()[0],
542 mSlicers[slicer]->GetCurrentPosition()[1],
543 mSlicers[slicer]->GetCurrentPosition()[2],
544 mSlicers[slicer]->GetTSlice());
545 mSlicers[i]->UpdateCursorPosition();
546 if (current) { //do not display corner annotation if image is the one picked
547 mSlicers[i]->SetCurrentPosition(-VTK_DOUBLE_MAX,-VTK_DOUBLE_MAX,
548 -VTK_DOUBLE_MAX, mSlicers[slicer]->GetTSlice());
549 mSlicers[i]->SetCursorColor(255,10,212);
551 mSlicers[i]->SetCursorColor(150,10,282);
553 switch (mSlicers[i]->GetSliceOrientation()) {
554 case vtkImageViewer2::SLICE_ORIENTATION_XY:
555 if (mSlicers[i]->GetSlice() != (int)floor(z))
556 mSlicers[i]->SetSlice((int)floor(z));
559 case vtkImageViewer2::SLICE_ORIENTATION_XZ:
560 if (mSlicers[i]->GetSlice() != (int)floor(y))
561 mSlicers[i]->SetSlice((int)floor(y));
564 case vtkImageViewer2::SLICE_ORIENTATION_YZ:
565 if (mSlicers[i]->GetSlice() != (int)floor(x))
566 mSlicers[i]->SetSlice((int)floor(x));
570 mSlicers[i]->Render();
578 //----------------------------------------------------------------------------
581 //----------------------------------------------------------------------------
582 void vvSlicerManager::UpdateLinked(int slicer)
584 double x = (mSlicers[slicer]->GetCurrentPosition()[0] - mSlicers[slicer]->GetInput()->GetOrigin()[0])
585 /mSlicers[slicer]->GetInput()->GetSpacing()[0];
586 double y = (mSlicers[slicer]->GetCurrentPosition()[1] - mSlicers[slicer]->GetInput()->GetOrigin()[1])
587 /mSlicers[slicer]->GetInput()->GetSpacing()[1];
588 double z = (mSlicers[slicer]->GetCurrentPosition()[2] - mSlicers[slicer]->GetInput()->GetOrigin()[2])
589 /mSlicers[slicer]->GetInput()->GetSpacing()[2];
591 if (x >= mSlicers[slicer]->GetInput()->GetWholeExtent()[0] &&
592 x <= mSlicers[slicer]->GetInput()->GetWholeExtent()[1] &&
593 y >= mSlicers[slicer]->GetInput()->GetWholeExtent()[2] &&
594 y <= mSlicers[slicer]->GetInput()->GetWholeExtent()[3] &&
595 z >= mSlicers[slicer]->GetInput()->GetWholeExtent()[4] &&
596 z <= mSlicers[slicer]->GetInput()->GetWholeExtent()[5]) {
597 for (std::list<std::string>::const_iterator i = mLinkedId.begin(); i != mLinkedId.end(); i++) {
598 emit UpdateLinkManager(*i, slicer,mSlicers[slicer]->GetCurrentPosition()[0],
599 mSlicers[slicer]->GetCurrentPosition()[1],
600 mSlicers[slicer]->GetCurrentPosition()[2],mSlicers[slicer]->GetTSlice());
604 //----------------------------------------------------------------------------
606 //----------------------------------------------------------------------------
607 void vvSlicerManager::UpdateLinkedNavigation(vvSlicer *refSlicer, bool bPropagate)
609 vtkCamera *refCam = refSlicer->GetRenderer()->GetActiveCamera();
610 double refPosition[3], refFocal[3];
611 refCam->GetPosition(refPosition);
612 refCam->GetFocalPoint(refFocal);
614 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
615 vtkCamera *camera = mSlicers[i]->GetRenderer()->GetActiveCamera();
616 camera->SetParallelScale(refCam->GetParallelScale());
618 double position[3], focal[3];
619 camera->GetPosition(position);
620 camera->GetFocalPoint(focal);
622 if(refSlicer->GetSliceOrientation()==mSlicers[i]->GetSliceOrientation()) {
623 for(int i=0; i<3; i++) {
624 position[i] = refPosition[i];
625 focal[i] = refFocal[i];
629 if(refSlicer->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_XY) {
630 if(mSlicers[i]->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_XZ) {
631 position[0] = refPosition[0];
632 focal[0] = refFocal[0];
634 if(mSlicers[i]->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_YZ) {
635 position[1] = refPosition[1];
636 focal[1] = refFocal[1];
640 if(refSlicer->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_XZ) {
641 if(mSlicers[i]->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_YZ) {
642 position[2] = refPosition[2];
643 focal[2] = refFocal[2];
645 if(mSlicers[i]->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_XY) {
646 position[0] = refPosition[0];
647 focal[0] = refFocal[0];
651 if(refSlicer->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_YZ) {
652 if(mSlicers[i]->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_XY) {
653 position[1] = refPosition[1];
654 focal[1] = refFocal[1];
656 if(mSlicers[i]->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_XZ) {
657 position[2] = refPosition[2];
658 focal[2] = refFocal[2];
662 camera->SetFocalPoint(focal);
663 camera->SetPosition(position);
666 mSlicers[i]->ForceUpdateDisplayExtent();
671 for (std::list<std::string>::const_iterator i = mLinkedId.begin(); i != mLinkedId.end(); i++)
672 emit UpdateLinkedNavigation(*i, this, refSlicer);
674 //----------------------------------------------------------------------------
676 //----------------------------------------------------------------------------
677 double vvSlicerManager::GetColorWindow()
680 return mSlicers[0]->GetColorWindow();
683 //----------------------------------------------------------------------------
686 //----------------------------------------------------------------------------
687 double vvSlicerManager::GetColorLevel()
690 return mSlicers[0]->GetColorLevel();
693 //----------------------------------------------------------------------------
696 //----------------------------------------------------------------------------
697 void vvSlicerManager::Render()
699 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
700 mSlicers[i]->Render();
703 //----------------------------------------------------------------------------
706 //----------------------------------------------------------------------------
707 void vvSlicerManager::GenerateDefaultLookupTable()
710 SetColorMap(mColorMap);
712 //----------------------------------------------------------------------------
715 //----------------------------------------------------------------------------
716 void vvSlicerManager::Reload()
718 mReader->Update(mType);
719 mImage=mReader->GetOutput();
720 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
721 mSlicers[i]->SetImage(mImage);
724 //----------------------------------------------------------------------------
727 //----------------------------------------------------------------------------
728 void vvSlicerManager::ReloadFusion()
730 mFusionReader->Update();
731 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
732 mSlicers[i]->SetFusion(mFusionReader->GetOutput());
733 mSlicers[i]->Render();
736 //----------------------------------------------------------------------------
739 //----------------------------------------------------------------------------
740 void vvSlicerManager::ReloadOverlay()
742 mOverlayReader->Update();
743 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
744 mSlicers[i]->SetOverlay(mOverlayReader->GetOutput());
745 mSlicers[i]->Render();
748 //----------------------------------------------------------------------------
751 //----------------------------------------------------------------------------
752 void vvSlicerManager::ReloadVF()
754 mVectorReader->Update(VECTORFIELD); //deletes the old images through the VF::Init() function
755 mVF=mVectorReader->GetOutput();
756 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
757 mSlicers[i]->SetVF(mVF);
758 mSlicers[i]->Render();
761 //----------------------------------------------------------------------------
764 //----------------------------------------------------------------------------
765 void vvSlicerManager::RemoveActor(const std::string& actor_type, int overlay_index)
767 if (actor_type =="overlay")
768 mOverlayReader = NULL;
770 if (actor_type =="fusion")
771 mFusionReader = NULL;
773 for (unsigned int i = 0; i < mSlicers.size(); i++)
774 mSlicers[i]->RemoveActor(actor_type,overlay_index);
776 if (actor_type=="vector") {
781 //----------------------------------------------------------------------------
784 //----------------------------------------------------------------------------
785 void vvSlicerManager::RemoveActors()
787 ///This method leaks a few objects. See RemoveActor for what a
788 ///correct implementation would look like
789 //DS -> probably due to the reader (now released in the
790 //RemoveActor() function. (I hope)
791 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
792 mSlicers[i]->SetDisplayMode(0);
793 mSlicers[i]->GetRenderer()->RemoveActor(mSlicers[i]->GetImageActor());
796 //----------------------------------------------------------------------------
799 //----------------------------------------------------------------------------
800 void vvSlicerManager::UpdateInfoOnCursorPosition(int slicer)
802 // int view = mSlicers[slicer]->GetSliceOrientation();
803 // int slice = mSlicers[slicer]->GetSlice();
804 double x = mSlicers[slicer]->GetCursorPosition()[0];
805 double y = mSlicers[slicer]->GetCursorPosition()[1];
806 double z = mSlicers[slicer]->GetCursorPosition()[2];
807 double X = (x - mSlicers[slicer]->GetInput()->GetOrigin()[0])/
808 mSlicers[slicer]->GetInput()->GetSpacing()[0];
809 double Y = (y - mSlicers[slicer]->GetInput()->GetOrigin()[1])/
810 mSlicers[slicer]->GetInput()->GetSpacing()[1];
811 double Z = (z - mSlicers[slicer]->GetInput()->GetOrigin()[2])/
812 mSlicers[slicer]->GetInput()->GetSpacing()[2];
813 double value = -VTK_DOUBLE_MAX;
815 double xVec=0, yVec=0, zVec=0, valueVec=0;
818 double valueOver=0, valueFus=0;
819 if (X >= mSlicers[slicer]->GetInput()->GetWholeExtent()[0] &&
820 X <= mSlicers[slicer]->GetInput()->GetWholeExtent()[1] &&
821 Y >= mSlicers[slicer]->GetInput()->GetWholeExtent()[2] &&
822 Y <= mSlicers[slicer]->GetInput()->GetWholeExtent()[3] &&
823 Z >= mSlicers[slicer]->GetInput()->GetWholeExtent()[4] &&
824 Z <= mSlicers[slicer]->GetInput()->GetWholeExtent()[5]) {
825 value = this->GetScalarComponentAsDouble(mSlicers[slicer]->GetInput(), X, Y, Z);
827 if (mSlicers[slicer]->GetVFActor() && mSlicers[slicer]->GetVFActor()->GetVisibility()) {
829 unsigned int currentTime = mSlicers[slicer]->GetTSlice();
830 vtkImageData *vf = NULL;
832 if (mSlicers[slicer]->GetVF()->GetVTKImages().size() > currentTime)
833 vf = mSlicers[slicer]->GetVF()->GetVTKImages()[currentTime];
835 vf = mSlicers[slicer]->GetVF()->GetVTKImages()[0];
838 double Xvf = (x - vf->GetOrigin()[0])/ vf->GetSpacing()[0];
839 double Yvf = (y - vf->GetOrigin()[1])/ vf->GetSpacing()[1];
840 double Zvf = (z - vf->GetOrigin()[2])/ vf->GetSpacing()[2];
841 xVec = this->GetScalarComponentAsDouble( vf, Xvf, Yvf, Zvf, 0);
842 yVec = this->GetScalarComponentAsDouble( vf, Xvf, Yvf, Zvf, 1);
843 zVec = this->GetScalarComponentAsDouble( vf, Xvf, Yvf, Zvf, 2);
844 valueVec = sqrt(xVec*xVec + yVec*yVec + zVec*zVec);
847 if (mSlicers[slicer]->GetOverlayActor() && mSlicers[slicer]->GetOverlayActor()->GetVisibility()) {
849 double Xover = (x - mSlicers[slicer]->GetOverlay()->GetOrigin()[0])
850 /mSlicers[slicer]->GetOverlay()->GetSpacing()[0];
851 double Yover = (y - mSlicers[slicer]->GetOverlay()->GetOrigin()[1])
852 /mSlicers[slicer]->GetOverlay()->GetSpacing()[1];
853 double Zover = (z - mSlicers[slicer]->GetOverlay()->GetOrigin()[2])
854 /mSlicers[slicer]->GetOverlay()->GetSpacing()[2];
855 if (Xover >= mSlicers[slicer]->GetOverlayMapper()->GetInput()->GetWholeExtent()[0] &&
856 Xover <= mSlicers[slicer]->GetOverlayMapper()->GetInput()->GetWholeExtent()[1] &&
857 Yover >= mSlicers[slicer]->GetOverlayMapper()->GetInput()->GetWholeExtent()[2] &&
858 Yover <= mSlicers[slicer]->GetOverlayMapper()->GetInput()->GetWholeExtent()[3] &&
859 Zover >= mSlicers[slicer]->GetOverlayMapper()->GetInput()->GetWholeExtent()[4] &&
860 Zover <= mSlicers[slicer]->GetOverlayMapper()->GetInput()->GetWholeExtent()[5]) {
861 valueOver = this->GetScalarComponentAsDouble(static_cast<vtkImageData*>(mSlicers[slicer]->GetOverlayMapper()->GetInput()), Xover, Yover, Zover);
864 if (mSlicers[slicer]->GetFusionActor() && mSlicers[slicer]->GetFusionActor()->GetVisibility()) {
866 double Xfus = (x - mSlicers[slicer]->GetFusion()->GetOrigin()[0])
867 /mSlicers[slicer]->GetFusion()->GetSpacing()[0];
868 double Yfus = (y - mSlicers[slicer]->GetFusion()->GetOrigin()[1])
869 /mSlicers[slicer]->GetFusion()->GetSpacing()[1];
870 double Zfus = (z - mSlicers[slicer]->GetFusion()->GetOrigin()[2])
871 /mSlicers[slicer]->GetFusion()->GetSpacing()[2];
872 if (Xfus >= mSlicers[slicer]->GetFusionMapper()->GetInput()->GetWholeExtent()[0] &&
873 Xfus <= mSlicers[slicer]->GetFusionMapper()->GetInput()->GetWholeExtent()[1] &&
874 Yfus >= mSlicers[slicer]->GetFusionMapper()->GetInput()->GetWholeExtent()[2] &&
875 Yfus <= mSlicers[slicer]->GetFusionMapper()->GetInput()->GetWholeExtent()[3] &&
876 Zfus >= mSlicers[slicer]->GetFusionMapper()->GetInput()->GetWholeExtent()[4] &&
877 Zfus <= mSlicers[slicer]->GetFusionMapper()->GetInput()->GetWholeExtent()[5]) {
878 valueFus = this->GetScalarComponentAsDouble(static_cast<vtkImageData*>(mSlicers[slicer]->GetFusionMapper()->GetInput()), Xfus, Yfus, Zfus);
881 emit UpdatePosition(mSlicers[slicer]->GetCursorVisibility(),
883 emit UpdateVector(displayVec,xVec, yVec, zVec, valueVec);
884 emit UpdateOverlay(displayOver,valueOver,value);
885 emit UpdateFusion(displayFus,valueFus);
886 for (unsigned int i = 0; i < mSlicers.size(); i++) {
887 if (mSlicers[i]->GetImageActor()->GetVisibility() == 1)
888 emit UpdateWindows(i,mSlicers[i]->GetSliceOrientation(),mSlicers[i]->GetSlice());
890 emit UpdateWindows(i,-1,-1);
894 //----------------------------------------------------------------------------
897 //----------------------------------------------------------------------------
898 void vvSlicerManager::Activated()
900 emit currentImageChanged(mId);
902 //----------------------------------------------------------------------------
905 //----------------------------------------------------------------------------
906 void vvSlicerManager::Picked()
908 emit currentPickedImageChanged(mId);
910 //----------------------------------------------------------------------------
912 //----------------------------------------------------------------------------
913 void vvSlicerManager::UpdateWindowLevel()
915 emit WindowLevelChanged(mSlicers[0]->GetColorWindow(),mSlicers[0]->GetColorLevel(),mPreset,mColorMap);
917 //----------------------------------------------------------------------------
920 //----------------------------------------------------------------------------
921 void vvSlicerManager::UpdateSlice(int slicer)
923 if (mPreviousSlice[slicer] == mSlicers[slicer]->GetSlice()) {
924 //DD("============= NOTHING");
927 emit UpdateSlice(slicer, mSlicers[slicer]->GetSlice());
928 mSlicers[slicer]->Render(); // DS <-- I add this, this could/must be the only Render ...
929 mPreviousSlice[slicer] = mSlicers[slicer]->GetSlice();
931 //----------------------------------------------------------------------------
934 //----------------------------------------------------------------------------
935 void vvSlicerManager::UpdateTSlice(int slicer)
937 if (mPreviousSlice[slicer] == mSlicers[slicer]->GetSlice()) {
938 if (mPreviousTSlice[slicer] == mSlicers[slicer]->GetTSlice()) {
939 // DD("************** NOTHING ***********");
943 mPreviousSlice[slicer] = mSlicers[slicer]->GetSlice();
944 mPreviousTSlice[slicer] = mSlicers[slicer]->GetTSlice();
945 emit UpdateTSlice(slicer,mSlicers[slicer]->GetTSlice());
947 //----------------------------------------------------------------------------
950 //----------------------------------------------------------------------------
951 void vvSlicerManager::UpdateSliceRange(int slicer)
953 emit UpdateSliceRange(slicer,
954 mSlicers[slicer]->GetSliceRange()[0], mSlicers[slicer]->GetSliceRange()[1],
955 0,mSlicers[slicer]->GetTMax());
957 //----------------------------------------------------------------------------
960 //----------------------------------------------------------------------------
961 void vvSlicerManager::SetPreset(int preset)
963 //vtkLookupTable* LUT = static_cast<vtkLookupTable*>(mSlicers[0]->GetWindowLevel()->GetLookupTable());
964 double window = mSlicers[0]->GetColorWindow();
965 double level = mSlicers[0]->GetColorLevel();
967 std::string component_type=mImage->GetScalarTypeAsITKString();
971 mImage->GetScalarRange(range);
972 window = range[1] - range[0];
973 level = (range[1] + range[0])* 0.5;
1003 this->SetColorWindow(window);
1004 this->SetColorLevel(level);
1011 //----------------------------------------------------------------------------
1014 //----------------------------------------------------------------------------
1015 void vvSlicerManager::SetLocalColorWindowing(const int slicer)
1018 this->mSlicers[slicer]->GetExtremasAroundMousePointer(min, max);
1019 this->SetColorWindow(max-min);
1020 this->SetColorLevel(0.5*(min+max));
1021 this->UpdateWindowLevel();
1024 //----------------------------------------------------------------------------
1027 //----------------------------------------------------------------------------
1028 void vvSlicerManager::SetColorMap()
1030 SetColorMap(mColorMap);
1032 //----------------------------------------------------------------------------
1035 //----------------------------------------------------------------------------
1036 void vvSlicerManager::SetColorMap(int colormap)
1039 range[0] = mSlicers[0]->GetInput()->GetScalarRange()[0];
1040 range[1] = mSlicers[0]->GetInput()->GetScalarRange()[1];
1042 double window = mSlicers[0]->GetWindowLevel()->GetWindow();
1043 double level = mSlicers[0]->GetWindowLevel()->GetLevel();
1045 vtkLookupTable* LUT = static_cast<vtkLookupTable*>(mSlicers[0]->GetWindowLevel()->GetLookupTable());
1054 LUT = vtkLookupTable::New();
1055 LUT->SetValueRange(0,1);
1056 LUT->SetSaturationRange(1,1);
1057 LUT->SetHueRange(0,0.18);
1061 LUT = vtkLookupTable::New();
1062 LUT->SetValueRange(0,1);
1063 LUT->SetSaturationRange(1,1);
1064 LUT->SetHueRange(0.4,0.80);
1068 LUT = vtkLookupTable::New();
1069 LUT->SetValueRange(0,1);
1070 LUT->SetSaturationRange(1,1);
1071 LUT->SetHueRange(0,1);
1075 LUT = vtkLookupTable::New();
1076 LUT->SetValueRange(0.,1);
1077 LUT->SetSaturationRange(1,1);
1078 LUT->SetHueRange(1,0.1);
1079 //LUT->SetRampToLinear();
1083 LUT->SetTableRange(level-fabs(window)/4,level+fabs(window)/4);
1086 vtkLookupTable* fusLUT = NULL;
1087 if (mSlicers[0]->GetFusion()) {
1088 fusLUT = vtkLookupTable::New();
1089 double fusRange [2];
1090 fusRange[0] = mFusionLevel - mFusionWindow/2;
1091 fusRange[1] = mFusionLevel + mFusionWindow/2;
1092 fusLUT->SetTableRange(fusRange[0],fusRange[1]);
1093 fusLUT->SetValueRange(1,1);
1094 fusLUT->SetSaturationRange(1,1);
1095 if (mFusionColorMap == 1)
1096 fusLUT->SetHueRange(0,0.18);
1097 else if (mFusionColorMap == 2)
1098 fusLUT->SetHueRange(0.4,0.80);
1099 else if (mFusionColorMap == 3)
1100 fusLUT->SetHueRange(0,1);
1102 if (mFusionColorMap == 0)
1105 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
1106 if (mSlicers[i]->GetOverlay() && mSlicers[i]->GetOverlayActor()->GetVisibility()) {
1107 vtkLookupTable* supLUT = vtkLookupTable::New();
1108 supLUT->SetTableRange(range[0],range[1]);
1109 supLUT->SetValueRange(1,1);
1110 supLUT->SetSaturationRange(1,1);
1111 supLUT->SetHueRange(double(mOverlayColor)/360,double(mOverlayColor)/360);
1113 vtkLookupTable* invLUT = vtkLookupTable::New();
1114 invLUT->SetTableRange(range[0],range[1]);
1115 invLUT->SetValueRange(1,1);
1116 invLUT->SetSaturationRange(1,1);
1117 invLUT->SetHueRange(double((mOverlayColor+180)%360)/360,double((mOverlayColor+180)%360)/360);
1119 dynamic_cast<vvImageMapToWLColors*>(mSlicers[i]->GetWindowLevel())
1120 ->SetWindowLevelMode(true);
1121 mSlicers[i]->GetWindowLevel()->SetLookupTable(supLUT);
1122 mSlicers[i]->GetOverlayMapper()->SetLookupTable(invLUT);
1125 } else if (mSlicers[i]->GetOverlay()) {
1126 //dynamic_cast<vvImageMapToWLColors*>(mSlicers[i]->GetWindowLevel())
1127 //->SetWindowLevelMode(false);
1128 mSlicers[i]->GetWindowLevel()->SetLookupTable(LUT);
1130 mSlicers[i]->GetWindowLevel()->SetLookupTable(LUT);
1132 if (mSlicers[i]->GetFusion() && mSlicers[i]->GetFusionActor()->GetVisibility()) {
1133 mSlicers[i]->GetFusionActor()->SetOpacity(double(mFusionOpacity)/100);
1134 mSlicers[i]->GetFusionMapper()->SetLookupTable(fusLUT);
1135 mSlicers[i]->GetFusionMapper()->SetWindow(mFusionWindow);
1136 mSlicers[i]->GetFusionMapper()->SetLevel(mFusionLevel);
1142 mColorMap = colormap;
1144 //----------------------------------------------------------------------------
1147 //----------------------------------------------------------------------------
1148 vvLandmarks* vvSlicerManager::GetLandmarks()
1150 if (mLandmarks == NULL) {
1151 mLandmarks = new vvLandmarks(mSlicers[0]->GetTMax()+1);
1152 for (unsigned int i = 0; i < mSlicers.size(); i++)
1153 mSlicers[i]->SetLandmarks(mLandmarks);
1157 //----------------------------------------------------------------------------
1160 //----------------------------------------------------------------------------
1161 void vvSlicerManager::AddLandmark(float x,float y,float z,float t)
1163 double x_index = (x - mSlicers[0]->GetInput()->GetOrigin()[0])/mSlicers[0]->GetInput()->GetSpacing()[0];
1164 double y_index = (y - mSlicers[0]->GetInput()->GetOrigin()[1])/mSlicers[0]->GetInput()->GetSpacing()[1];
1165 double z_index = (z - mSlicers[0]->GetInput()->GetOrigin()[2])/mSlicers[0]->GetInput()->GetSpacing()[2];
1166 if (x_index >= mSlicers[0]->GetInput()->GetWholeExtent()[0] &&
1167 x_index <= mSlicers[0]->GetInput()->GetWholeExtent()[1] &&
1168 y_index >= mSlicers[0]->GetInput()->GetWholeExtent()[2] &&
1169 y_index <= mSlicers[0]->GetInput()->GetWholeExtent()[3] &&
1170 z_index >= mSlicers[0]->GetInput()->GetWholeExtent()[4] &&
1171 z_index <= mSlicers[0]->GetInput()->GetWholeExtent()[5]) {
1172 double value = this->GetScalarComponentAsDouble(mSlicers[0]->GetInput(), x_index, y_index, z_index);
1173 this->GetLandmarks()->AddLandmark(x,y,z,t,value);
1174 emit LandmarkAdded();
1177 //----------------------------------------------------------------------------
1179 //----------------------------------------------------------------------------
1180 void vvSlicerManager::PrevImage(int slicer)
1182 emit ChangeImageWithIndexOffset(this, slicer, -1);
1184 //----------------------------------------------------------------------------
1186 //----------------------------------------------------------------------------
1187 void vvSlicerManager::NextImage(int slicer)
1189 emit ChangeImageWithIndexOffset(this, slicer, 1);
1191 //----------------------------------------------------------------------------
1193 //----------------------------------------------------------------------------
1194 void vvSlicerManager::VerticalSliderHasChanged(int slicer, int slice)
1196 emit AVerticalSliderHasChanged(slicer, slice);
1199 //----------------------------------------------------------------------------
1201 //----------------------------------------------------------------------------
1202 double vvSlicerManager::GetScalarComponentAsDouble(vtkImageData *image, double X, double Y, double Z, int component)
1205 return mSlicers[0]->GetScalarComponentAsDouble(image, X, Y, Z, ix, iy, iz, component);
1207 //----------------------------------------------------------------------------