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 #include <qfileinfo.h>
45 //----------------------------------------------------------------------------
46 vvSlicerManager::vvSlicerManager(int numberOfSlicers)
55 mType = vvImageReader::UNDEFINEDIMAGETYPE;
61 mFusionThresOpacity = 1;
65 mFusionShowLegend = true;
70 for ( int i = 0; i < numberOfSlicers; i++)
71 mSlicers.push_back(vtkSmartPointer<vvSlicer>::New());
73 mPreviousSlice.resize(numberOfSlicers);
74 mPreviousTSlice.resize(numberOfSlicers);
75 mSlicingPreset = WORLD_SLICING;
77 //----------------------------------------------------------------------------
80 //----------------------------------------------------------------------------
81 vvSlicerManager::~vvSlicerManager()
86 //----------------------------------------------------------------------------
89 //------------------------------------------------------------------------------
90 void vvSlicerManager::SetFilename(std::string filename, int number)
93 mFileName = vtksys::SystemTools::GetFilenameName(mFileName);
94 mBaseFileName = vtksys::SystemTools::GetFilenameName(vtksys::SystemTools::GetFilenameWithoutLastExtension(mFileName));
95 mBaseFileNameNumber = number;
97 mFileName = mBaseFileName;
99 mFileName.append("_"+clitk::toString(number));
101 mFileName.append(vtksys::SystemTools::GetFilenameLastExtension(filename));
103 for(unsigned int i=0; i<mSlicers.size(); i++) {
104 mSlicers[i]->SetFileName(mFileName);//vtksys::SystemTools::GetFilenameWithoutLastExtension(filename));
108 //------------------------------------------------------------------------------
111 //----------------------------------------------------------------------------
112 void vvSlicerManager::AddContour(vvMesh::Pointer contour,bool propagate)
114 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
115 mSlicers[i]->AddContour(contour,propagate);
118 //----------------------------------------------------------------------------
121 //----------------------------------------------------------------------------
122 void vvSlicerManager::ToggleContourSuperposition()
124 for ( unsigned int i = 0; i < mSlicers.size(); i++)
125 mSlicers[i]->ToggleContourSuperposition();
127 //----------------------------------------------------------------------------
129 //----------------------------------------------------------------------------
130 std::string vvSlicerManager::GetListOfAbsoluteFilePathInOneString(const std::string &actorType)
132 vvImageReader *reader = NULL;
134 if(actorType=="image")
136 else if(actorType=="overlay")
137 reader = mOverlayReader;
138 else if(actorType=="fusion")
139 reader = mFusionReader;
140 else if(actorType=="vector")
141 reader = mVectorReader;
147 for(unsigned int i=0; i<reader->GetInputFilenames().size(); i++){
148 QFileInfo fileinfo(reader->GetInputFilenames()[i].c_str()); //Do not show the path
151 list += fileinfo.absoluteFilePath().toStdString();
155 //----------------------------------------------------------------------------
158 //----------------------------------------------------------------------------
159 bool vvSlicerManager::SetImage(std::string filename, vvImageReader::LoadedImageType type, int n, unsigned int slice)
162 if (mReader.IsNull())
163 mReader = vvImageReader::New();
164 std::vector<std::string> filenames;
165 filenames.push_back(filename);
166 mReader->SetInputFilenames(filenames);
167 mReader->SetSlice(slice); // Only used for SLICED type
168 mReader->Update(type);
170 SetFilename(filename, n);
171 // mFileName = vtksys::SystemTools::GetFilenameName(mFileName);
172 //mBaseFileName = vtksys::SystemTools::GetFilenameName(vtksys::SystemTools::GetFilenameWithoutLastExtension(mFileName));
173 //mBaseFileNameNumber = n;
175 if (mReader->GetLastError().size() == 0) {
176 mImage=mReader->GetOutput();
177 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
178 mSlicers[i]->SetFileName(vtksys::SystemTools::GetFilenameWithoutLastExtension(filename));
179 mSlicers[i]->SetImage(mReader->GetOutput());
182 mLastError = mReader->GetLastError();
186 // mFileName.append("_"+clitk::toString(n));
190 //----------------------------------------------------------------------------
193 //----------------------------------------------------------------------------
194 void vvSlicerManager::SetImage(vvImage::Pointer image)
197 for (unsigned int i = 0; i < mSlicers.size(); i++) {
198 mSlicers[i]->SetImage(image);
201 //----------------------------------------------------------------------------
204 //----------------------------------------------------------------------------
205 bool vvSlicerManager::SetImages(std::vector<std::string> filenames, vvImageReader::LoadedImageType type, int n)
208 std::string fileWithoutExtension = vtksys::SystemTools::GetFilenameWithoutExtension(filenames[0]);
209 if (type == vvImageReader::DICOM)
210 fileWithoutExtension += "_dicom";
211 else if (type == vvImageReader::MERGED)
212 fileWithoutExtension += "_merged";
213 else if (type == vvImageReader::MERGEDWITHTIME)
214 fileWithoutExtension += "_merged_wt";
216 mFileName = vtksys::SystemTools::GetFilenameName(mFileName);
217 mFileName = fileWithoutExtension + vtksys::SystemTools::GetFilenameExtension(filenames[0]);
218 if (mReader.IsNull())
219 mReader = vvImageReader::New();
220 mReader->SetInputFilenames(filenames);
221 mReader->Update(type);
223 mBaseFileName = vtksys::SystemTools::GetFilenameName(vtksys::SystemTools::GetFilenameWithoutLastExtension(mFileName));
224 mBaseFileNameNumber = n;
226 if (mReader->GetLastError().size() == 0) {
227 mImage=mReader->GetOutput();
228 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
229 mSlicers[i]->SetFileName(fileWithoutExtension);
230 mSlicers[i]->SetImage(mReader->GetOutput());
233 mLastError = mReader->GetLastError();
237 mFileName.append("_"+clitk::toString(n));
241 //----------------------------------------------------------------------------
244 //----------------------------------------------------------------------------
245 bool vvSlicerManager::SetOverlay(std::string filename,int dim, std::string component)
247 mOverlayName = filename;
248 mOverlayComponent = component;
249 if (dim > mImage->GetNumberOfDimensions()) {
250 mLastError = " Overlay dimension cannot be greater then reference image!";
253 if (mOverlayReader.IsNull())
254 mOverlayReader = vvImageReader::New();
255 std::vector<std::string> filenames;
256 filenames.push_back(filename);
257 mOverlayReader->SetInputFilenames(filenames);
258 mOverlayReader->Update(mImage->GetNumberOfDimensions(),component.c_str(),mType);
259 if (mOverlayReader->GetLastError().size() == 0) {
260 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
261 mSlicers[i]->SetOverlay(mOverlayReader->GetOutput());
264 mLastError = mOverlayReader->GetLastError();
269 //----------------------------------------------------------------------------
272 //----------------------------------------------------------------------------
273 bool vvSlicerManager::SetFusion(std::string filename,int dim, std::string component)
275 mFusionName = filename;
276 mFusionComponent = component;
277 if (dim > mImage->GetNumberOfDimensions()) {
278 mLastError = " Overlay dimension cannot be greater then reference image!";
281 if (mFusionReader.IsNull())
282 mFusionReader = vvImageReader::New();
283 std::vector<std::string> filenames;
284 filenames.push_back(filename);
285 mFusionReader->SetInputFilenames(filenames);
286 mFusionReader->Update(mImage->GetNumberOfDimensions(),component.c_str(),mType);
287 if (mFusionReader->GetLastError().size() == 0) {
288 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
289 mSlicers[i]->SetFusion(mFusionReader->GetOutput());
292 mLastError = mFusionReader->GetLastError();
295 double *fusRange = mFusionReader->GetOutput()->GetVTKImages()[0]->GetScalarRange();
296 mFusionLevel = (fusRange[0]+fusRange[1])/2;
297 mFusionWindow = fusRange[1]-fusRange[0];
301 //----------------------------------------------------------------------------
304 //----------------------------------------------------------------------------
305 bool vvSlicerManager::SetVF(std::string filename)
307 if (mVectorReader.IsNull())
308 mVectorReader = vvImageReader::New();
309 mVectorReader->SetInputFilename(filename);
311 if (mType == vvImageReader::IMAGEWITHTIME)
312 mVectorReader->Update(vvImageReader::VECTORFIELDWITHTIME);
314 mVectorReader->Update(vvImageReader::VECTORFIELD);
315 if (mVectorReader->GetLastError().size() != 0) {
316 mLastError = mVectorReader->GetLastError();
319 return SetVF(mVectorReader->GetOutput(),filename);
321 //----------------------------------------------------------------------------
324 //----------------------------------------------------------------------------
325 bool vvSlicerManager::SetVF(vvImage::Pointer vf,std::string filename)
327 if (vf->GetNumberOfDimensions() > mImage->GetNumberOfDimensions()) {
328 mLastError = "Sorry, vector field dimension cannot be greater then reference image.";
331 if (vf->GetNumberOfDimensions() == 4) {
332 if (vf->GetSpacing()[3] != mImage->GetSpacing()[3]) {
333 mLastError = "Sorry, vector field time spacing cannot be different from time spacing of the reference image.";
336 if (vf->GetOrigin()[3] != mImage->GetOrigin()[3]) {
337 mLastError = "Sorry, vector field time origin cannot be different from time origin of the reference image.";
343 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
344 mSlicers[i]->SetVF(vf);
348 //----------------------------------------------------------------------------
351 //----------------------------------------------------------------------------
352 vvSlicer* vvSlicerManager::GetSlicer(int i)
356 //----------------------------------------------------------------------------
359 //----------------------------------------------------------------------------
360 void vvSlicerManager::UpdateSlicer(int num, bool state)
362 if (mSlicers[num]->GetImage())
363 mSlicers[num]->SetDisplayMode(state);
365 //----------------------------------------------------------------------------
368 //----------------------------------------------------------------------------
369 void vvSlicerManager::SetSlicerWindow(int i, vtkRenderWindow* RW)
371 mSlicers[i]->SetRenderWindow(i,RW);
373 //----------------------------------------------------------------------------
376 //----------------------------------------------------------------------------
377 void vvSlicerManager::SetInteractorStyleNavigator(int i, vtkInteractorStyle* style)
379 vvSlicerManagerCommand *smc = vvSlicerManagerCommand::New();
381 smc->SetSlicerNumber(i);
382 mSlicers[i]->GetRenderWindow()->GetInteractor()->SetInteractorStyle(style);
384 mSlicers[i]->GetRenderWindow()->GetInteractor()->
385 GetInteractorStyle()->AddObserver(vtkCommand::KeyPressEvent, smc);
386 mSlicers[i]->GetRenderWindow()->GetInteractor()->
387 GetInteractorStyle()->AddObserver(vtkCommand::WindowLevelEvent, smc);
388 mSlicers[i]->GetRenderWindow()->GetInteractor()->
389 GetInteractorStyle()->AddObserver(vtkCommand::EndWindowLevelEvent, smc);
390 mSlicers[i]->GetRenderWindow()->GetInteractor()->
391 GetInteractorStyle()->AddObserver(vtkCommand::StartWindowLevelEvent, smc);
392 mSlicers[i]->GetRenderWindow()->GetInteractor()->
393 GetInteractorStyle()->AddObserver(vtkCommand::PickEvent, smc);
394 mSlicers[i]->GetRenderWindow()->GetInteractor()->
395 GetInteractorStyle()->AddObserver(vtkCommand::StartPickEvent, smc);
396 mSlicers[i]->GetRenderWindow()->GetInteractor()->
397 GetInteractorStyle()->AddObserver(vtkCommand::LeaveEvent, smc);
398 mSlicers[i]->GetRenderWindow()->GetInteractor()->
399 GetInteractorStyle()->AddObserver(vtkCommand::UserEvent, smc);
400 mSlicers[i]->GetRenderWindow()->GetInteractor()->
401 GetInteractorStyle()->AddObserver(vtkCommand::MouseWheelForwardEvent, smc);
402 mSlicers[i]->GetRenderWindow()->GetInteractor()->
403 GetInteractorStyle()->AddObserver(vtkCommand::MouseWheelBackwardEvent, smc);
404 // mSlicers[i]->GetRenderWindow()->GetInteractor()->
405 // GetInteractorStyle()->AddObserver(vtkCommand::LeftButtonReleaseEvent, smc);
406 mSlicers[i]->GetRenderWindow()->GetInteractor()->
407 GetInteractorStyle()->AddObserver(vtkCommand::EndPickEvent, smc);
408 mSlicers[i]->GetRenderWindow()->GetInteractor()->
409 GetInteractorStyle()->AddObserver(vtkCommand::EndInteractionEvent, smc);
412 //----------------------------------------------------------------------------
415 //----------------------------------------------------------------------------
416 void vvSlicerManager::LeftButtonReleaseEvent(int slicer)
418 emit LeftButtonReleaseSignal(slicer);
420 //----------------------------------------------------------------------------
422 //----------------------------------------------------------------------------
423 void vvSlicerManager::SetSliceOrientation(int slicer, int orientation)
425 mSlicers[slicer]->SetSliceOrientation(orientation);
426 emit UpdateOrientation(slicer, orientation);
428 //----------------------------------------------------------------------------
430 //----------------------------------------------------------------------------
431 int vvSlicerManager::GetTSlice()
433 return mSlicers[0]->GetTSlice();
435 //----------------------------------------------------------------------------
437 //----------------------------------------------------------------------------
438 void vvSlicerManager::SetTSlice(int slice)
442 else if (slice > mSlicers[0]->GetTMax())
443 slice = mSlicers[0]->GetTMax();
445 mLandmarks->SetTime(slice);
446 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
447 if (slice != mSlicers[i]->GetTSlice()) {
448 mSlicers[i]->SetTSlice(slice);
453 //----------------------------------------------------------------------------
456 //----------------------------------------------------------------------------
457 void vvSlicerManager::SetNextTSlice(int originating_slicer)
459 int t = mSlicers[0]->GetTSlice();
461 if (t > mSlicers[0]->GetTMax())
463 //std::cout << "vvSlicerManager::SetNextTSlice" << std::endl;
464 emit UpdateTSlice(originating_slicer,t);
466 //----------------------------------------------------------------------------
469 //----------------------------------------------------------------------------
470 void vvSlicerManager::SetPreviousTSlice(int originating_slicer)
472 int t = mSlicers[0]->GetTSlice();
475 t = mSlicers[0]->GetTMax();
476 //std::cout << "vvSlicerManager::SetPreviousTSlice" << std::endl;
477 emit UpdateTSlice(originating_slicer,t);
479 //----------------------------------------------------------------------------
482 //----------------------------------------------------------------------------
483 void vvSlicerManager::ToggleInterpolation()
485 bool interpolate=!(mSlicers[0]->GetImageActor()->GetInterpolate());
486 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
487 mSlicers[i]->GetImageActor()->SetInterpolate(interpolate);
488 if (mSlicers[i]->GetOverlayActor())
489 mSlicers[i]->GetOverlayActor()->SetInterpolate(interpolate);
490 if (mSlicers[i]->GetFusionActor())
491 mSlicers[i]->GetFusionActor()->SetInterpolate(interpolate);
494 //----------------------------------------------------------------------------
497 //----------------------------------------------------------------------------
498 void vvSlicerManager::SetTSliceInSlicer(int tslice, int slicer)
502 else if (tslice > mSlicers[slicer]->GetTMax())
503 tslice = mSlicers[slicer]->GetTMax();
505 mLandmarks->SetTime(tslice);
507 if (mSlicers[slicer]->GetTSlice() == tslice) return;
509 if(mSlicingPreset==VOXELS_SLICING) {
510 vtkMatrix4x4 *imageTransformInverse = vtkMatrix4x4::New();
511 mImage->GetTransform()[tslice]->GetInverse(imageTransformInverse);
512 this->GetSlicer(slicer)->GetSlicingTransform()->SetMatrix(imageTransformInverse);
513 imageTransformInverse->Delete();
516 mSlicers[slicer]->SetTSlice(tslice);
517 UpdateTSlice(slicer);
519 //----------------------------------------------------------------------------
522 //----------------------------------------------------------------------------
523 void vvSlicerManager::SetColorWindow(double s)
525 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
526 mSlicers[i]->SetColorWindow(s);
529 //----------------------------------------------------------------------------
531 //----------------------------------------------------------------------------
532 void vvSlicerManager::SetColorLevel(double s)
534 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
535 mSlicers[i]->SetColorLevel(s);
538 //----------------------------------------------------------------------------
540 //----------------------------------------------------------------------------
541 void vvSlicerManager::SetOverlayColorWindow(double s)
543 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
544 mSlicers[i]->SetOverlayColorWindow(s);
547 //----------------------------------------------------------------------------
549 //----------------------------------------------------------------------------
550 void vvSlicerManager::SetOverlayColorLevel(double s)
552 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
553 mSlicers[i]->SetOverlayColorLevel(s);
556 //----------------------------------------------------------------------------
558 //----------------------------------------------------------------------------
559 void vvSlicerManager::SetLinkOverlayWindowLevel(bool b)
561 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
562 mSlicers[i]->SetLinkOverlayWindowLevel(b);
565 //----------------------------------------------------------------------------
567 //----------------------------------------------------------------------------
568 void vvSlicerManager::SetCursorAndCornerAnnotationVisibility(int s)
570 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
571 mSlicers[i]->SetCursorVisibility(s);
572 mSlicers[i]->SetCornerAnnotationVisibility(s);
575 //----------------------------------------------------------------------------
577 //----------------------------------------------------------------------------
578 void vvSlicerManager::SetOpacity(int i, double factor)
580 mSlicers[i]->SetOpacity(1/factor);
582 //----------------------------------------------------------------------------
585 //----------------------------------------------------------------------------
586 void vvSlicerManager::UpdateViews(int current,int slicer)
589 p[0] = mSlicers[slicer]->GetCurrentPosition()[0];
590 p[1] = mSlicers[slicer]->GetCurrentPosition()[1];
591 p[2] = mSlicers[slicer]->GetCurrentPosition()[2];
592 mSlicers[slicer]->GetSlicingTransform()->GetInverse()->TransformPoint(p, pt);
594 double x = (pt[0] - mSlicers[slicer]->GetInput()->GetOrigin()[0])
595 /mSlicers[slicer]->GetInput()->GetSpacing()[0];
596 double y = (pt[1] - mSlicers[slicer]->GetInput()->GetOrigin()[1])
597 /mSlicers[slicer]->GetInput()->GetSpacing()[1];
598 double z = (pt[2] - mSlicers[slicer]->GetInput()->GetOrigin()[2])
599 /mSlicers[slicer]->GetInput()->GetSpacing()[2];
601 if (x >= mSlicers[slicer]->GetInput()->GetWholeExtent()[0]-0.5 &&
602 x <= mSlicers[slicer]->GetInput()->GetWholeExtent()[1]+0.5 &&
603 y >= mSlicers[slicer]->GetInput()->GetWholeExtent()[2]-0.5 &&
604 y <= mSlicers[slicer]->GetInput()->GetWholeExtent()[3]+0.5 &&
605 z >= mSlicers[slicer]->GetInput()->GetWholeExtent()[4]-0.5 &&
606 z <= mSlicers[slicer]->GetInput()->GetWholeExtent()[5]+0.5) {
607 mSlicers[slicer]->UpdateCursorPosition();
608 mSlicers[slicer]->SetCursorColor(10,212,255);
610 switch (mSlicers[slicer]->GetSliceOrientation()) {
611 case vtkImageViewer2::SLICE_ORIENTATION_XY:
612 if (mSlicers[slicer]->GetSlice() != (int)lrint(z))
613 mSlicers[slicer]->SetSlice((int)lrint(z));
616 case vtkImageViewer2::SLICE_ORIENTATION_XZ:
617 if (mSlicers[slicer]->GetSlice() != (int)lrint(y))
618 mSlicers[slicer]->SetSlice((int)lrint(y));
621 case vtkImageViewer2::SLICE_ORIENTATION_YZ:
622 if (mSlicers[slicer]->GetSlice() != (int)lrint(x))
623 mSlicers[slicer]->SetSlice((int)lrint(x));
626 mSlicers[slicer]->Render();
628 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
629 if (i != (unsigned int)slicer
630 && mSlicers[i]->GetRenderer()->GetDraw()
631 && mSlicers[i]->GetRenderWindow()->GetSize()[0] > 2
632 && mSlicers[i]->GetRenderWindow()->GetSize()[1] > 2) {
633 mSlicers[i]->SetCurrentPosition(p[0], p[1], p[2], mSlicers[slicer]->GetTSlice());
634 mSlicers[i]->UpdateCursorPosition();
635 if (current) { //do not display corner annotation if image is the one picked
636 mSlicers[i]->SetCurrentPosition(-VTK_DOUBLE_MAX,-VTK_DOUBLE_MAX,
637 -VTK_DOUBLE_MAX, mSlicers[slicer]->GetTSlice());
638 mSlicers[i]->SetCursorColor(255,10,212);
640 mSlicers[i]->SetCursorColor(150,10,282);
642 switch (mSlicers[i]->GetSliceOrientation()) {
643 case vtkImageViewer2::SLICE_ORIENTATION_XY:
644 if (mSlicers[i]->GetSlice() != (int)floor(z))
645 mSlicers[i]->SetSlice((int)floor(z));
648 case vtkImageViewer2::SLICE_ORIENTATION_XZ:
649 if (mSlicers[i]->GetSlice() != (int)floor(y))
650 mSlicers[i]->SetSlice((int)floor(y));
653 case vtkImageViewer2::SLICE_ORIENTATION_YZ:
654 if (mSlicers[i]->GetSlice() != (int)floor(x))
655 mSlicers[i]->SetSlice((int)floor(x));
659 mSlicers[i]->Render();
667 //----------------------------------------------------------------------------
670 //----------------------------------------------------------------------------
671 void vvSlicerManager::UpdateLinked(int slicer)
674 p[0] = mSlicers[slicer]->GetCurrentPosition()[0];
675 p[1] = mSlicers[slicer]->GetCurrentPosition()[1];
676 p[2] = mSlicers[slicer]->GetCurrentPosition()[2];
677 mSlicers[slicer]->GetSlicingTransform()->GetInverse()->TransformPoint(p, pt);
678 double x = (pt[0] - mSlicers[slicer]->GetInput()->GetOrigin()[0]) / mSlicers[slicer]->GetInput()->GetSpacing()[0];
679 double y = (pt[1] - mSlicers[slicer]->GetInput()->GetOrigin()[1]) / mSlicers[slicer]->GetInput()->GetSpacing()[1];
680 double z = (pt[2] - mSlicers[slicer]->GetInput()->GetOrigin()[2]) / mSlicers[slicer]->GetInput()->GetSpacing()[2];
682 if (x >= mSlicers[slicer]->GetInput()->GetWholeExtent()[0]-0.5 &&
683 x <= mSlicers[slicer]->GetInput()->GetWholeExtent()[1]+0.5 &&
684 y >= mSlicers[slicer]->GetInput()->GetWholeExtent()[2]-0.5 &&
685 y <= mSlicers[slicer]->GetInput()->GetWholeExtent()[3]+0.5 &&
686 z >= mSlicers[slicer]->GetInput()->GetWholeExtent()[4]-0.5 &&
687 z <= mSlicers[slicer]->GetInput()->GetWholeExtent()[5]+0.5) {
688 for (std::list<std::string>::const_iterator i = mLinkedId.begin(); i != mLinkedId.end(); i++) {
689 emit UpdateLinkManager(*i, slicer,mSlicers[slicer]->GetCurrentPosition()[0],
690 mSlicers[slicer]->GetCurrentPosition()[1],
691 mSlicers[slicer]->GetCurrentPosition()[2],mSlicers[slicer]->GetTSlice());
695 //----------------------------------------------------------------------------
697 //----------------------------------------------------------------------------
698 void vvSlicerManager::UpdateLinkedNavigation(vvSlicer *refSlicer, bool bPropagate)
700 vtkCamera *refCam = refSlicer->GetRenderer()->GetActiveCamera();
701 double refPosition[3], refFocal[3];
702 refCam->GetPosition(refPosition);
703 refCam->GetFocalPoint(refFocal);
705 refSlicer->GetSlicingTransform()->TransformPoint(refPosition);
706 refSlicer->GetSlicingTransform()->TransformPoint(refFocal);
707 mSlicers[0]->GetSlicingTransform()->GetInverse()->TransformPoint(refPosition);
708 mSlicers[0]->GetSlicingTransform()->GetInverse()->TransformPoint(refFocal);
710 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
711 vtkCamera *camera = mSlicers[i]->GetRenderer()->GetActiveCamera();
712 camera->SetParallelScale(refCam->GetParallelScale());
714 double position[3], focal[3];
715 camera->GetPosition(position);
716 camera->GetFocalPoint(focal);
718 if(refSlicer->GetSliceOrientation()==mSlicers[i]->GetSliceOrientation()) {
719 for(int i=0; i<3; i++) {
720 position[i] = refPosition[i];
721 focal[i] = refFocal[i];
725 if(refSlicer->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_XY) {
726 if(mSlicers[i]->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_XZ) {
727 position[0] = refPosition[0];
728 focal[0] = refFocal[0];
730 if(mSlicers[i]->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_YZ) {
731 position[1] = refPosition[1];
732 focal[1] = refFocal[1];
736 if(refSlicer->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_XZ) {
737 if(mSlicers[i]->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_YZ) {
738 position[2] = refPosition[2];
739 focal[2] = refFocal[2];
741 if(mSlicers[i]->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_XY) {
742 position[0] = refPosition[0];
743 focal[0] = refFocal[0];
747 if(refSlicer->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_YZ) {
748 if(mSlicers[i]->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_XY) {
749 position[1] = refPosition[1];
750 focal[1] = refFocal[1];
752 if(mSlicers[i]->GetSliceOrientation()==vtkImageViewer2::SLICE_ORIENTATION_XZ) {
753 position[2] = refPosition[2];
754 focal[2] = refFocal[2];
757 DD(camera->GetFocalPoint()[0] << ' ' << camera->GetFocalPoint()[1] << ' ' << camera->GetFocalPoint()[2])
758 camera->SetFocalPoint(focal);
759 DD(camera->GetFocalPoint()[0] << ' ' << camera->GetFocalPoint()[1] << ' ' << camera->GetFocalPoint()[2])
760 DD(camera->GetPosition()[0] << ' ' << camera->GetPosition()[1] << ' ' << camera->GetPosition()[2])
761 camera->SetPosition(position);
762 DD(camera->GetPosition()[0] << ' ' << camera->GetPosition()[1] << ' ' << camera->GetPosition()[2])
765 mSlicers[i]->ForceUpdateDisplayExtent();
770 for (std::list<std::string>::const_iterator i = mLinkedId.begin(); i != mLinkedId.end(); i++)
771 emit UpdateLinkedNavigation(*i, this, refSlicer);
773 //----------------------------------------------------------------------------
775 //----------------------------------------------------------------------------
776 double vvSlicerManager::GetColorWindow()
779 return mSlicers[0]->GetColorWindow();
782 //----------------------------------------------------------------------------
785 //----------------------------------------------------------------------------
786 double vvSlicerManager::GetColorLevel()
789 return mSlicers[0]->GetColorLevel();
792 //----------------------------------------------------------------------------
794 //----------------------------------------------------------------------------
795 double vvSlicerManager::GetOverlayColorWindow() const
798 return mSlicers[0]->GetOverlayColorWindow();
801 //----------------------------------------------------------------------------
803 //----------------------------------------------------------------------------
804 double vvSlicerManager::GetOverlayColorLevel() const
807 return mSlicers[0]->GetOverlayColorLevel();
810 //----------------------------------------------------------------------------
812 //----------------------------------------------------------------------------
813 bool vvSlicerManager::GetLinkOverlayWindowLevel() const
816 return mSlicers[0]->GetLinkOverlayWindowLevel();
819 //----------------------------------------------------------------------------
821 //------------------------------------------------------------------------------
822 void vvSlicerManager::ResetTransformationToIdentity(const std::string actorType)
824 if(actorType == "image")
825 for(unsigned int i=0; i<this->GetImage()->GetTransform().size(); i++)
826 this->GetImage()->GetTransform()[i]->Identity();
827 else if(actorType == "overlay")
828 for(unsigned int i=0; i<this->GetImage()->GetTransform().size(); i++)
829 this->GetSlicer(0)->GetOverlay()->GetTransform()[i]->Identity();
830 else if(actorType == "fusion")
831 for(unsigned int i=0; i<this->GetImage()->GetTransform().size(); i++)
832 this->GetSlicer(0)->GetFusion()->GetTransform()[i]->Identity();
833 else if(actorType == "vf")
834 for(unsigned int i=0; i<this->GetImage()->GetTransform().size(); i++)
835 this->GetVF()->GetTransform()[i]->Identity();
839 for(int i=0; i< this->GetNumberOfSlicers(); i++){
840 this->GetSlicer(i)->ForceUpdateDisplayExtent();
841 this->GetSlicer(i)->ResetCamera();
842 this->GetSlicer(i)->Render();
845 //------------------------------------------------------------------------------
847 //----------------------------------------------------------------------------
848 void vvSlicerManager::Render()
850 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
851 mSlicers[i]->Render();
854 //----------------------------------------------------------------------------
857 //----------------------------------------------------------------------------
858 void vvSlicerManager::GenerateDefaultLookupTable()
861 SetColorMap(mColorMap);
863 //----------------------------------------------------------------------------
866 //----------------------------------------------------------------------------
867 void vvSlicerManager::Reload()
869 mReader->Update(mType);
870 mImage=mReader->GetOutput();
871 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
872 mSlicers[i]->SetImage(mImage);
875 //----------------------------------------------------------------------------
878 //----------------------------------------------------------------------------
879 void vvSlicerManager::ReloadFusion()
881 mFusionReader->Update(mImage->GetNumberOfDimensions(),mFusionComponent.c_str(),mType);
883 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
884 mSlicers[i]->SetFusion(mFusionReader->GetOutput());
885 mSlicers[i]->Render();
888 //----------------------------------------------------------------------------
891 //----------------------------------------------------------------------------
892 void vvSlicerManager::ReloadOverlay()
894 mOverlayReader->Update(mImage->GetNumberOfDimensions(),mOverlayComponent.c_str(),mType);
895 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
896 mSlicers[i]->SetOverlay(mOverlayReader->GetOutput());
897 mSlicers[i]->Render();
900 //----------------------------------------------------------------------------
903 //----------------------------------------------------------------------------
904 void vvSlicerManager::ReloadVF()
906 mVectorReader->Update(vvImageReader::VECTORFIELD); //deletes the old images through the VF::Init() function
907 mVF=mVectorReader->GetOutput();
908 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
909 mSlicers[i]->SetVF(mVF);
910 mSlicers[i]->Render();
913 //----------------------------------------------------------------------------
916 //----------------------------------------------------------------------------
917 void vvSlicerManager::RemoveActor(const std::string& actor_type, int overlay_index)
919 if (actor_type =="overlay")
920 mOverlayReader = NULL;
922 if (actor_type =="fusion")
923 mFusionReader = NULL;
925 for (unsigned int i = 0; i < mSlicers.size(); i++)
926 mSlicers[i]->RemoveActor(actor_type,overlay_index);
928 if (actor_type=="vector") {
933 //----------------------------------------------------------------------------
936 //----------------------------------------------------------------------------
937 void vvSlicerManager::RemoveActors()
939 ///This method leaks a few objects. See RemoveActor for what a
940 ///correct implementation would look like
941 //DS -> probably due to the reader (now released in the
942 //RemoveActor() function. (I hope)
943 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
944 mSlicers[i]->SetDisplayMode(0);
945 mSlicers[i]->GetRenderer()->RemoveActor(mSlicers[i]->GetImageActor());
948 //----------------------------------------------------------------------------
951 //----------------------------------------------------------------------------
952 void vvSlicerManager::UpdateInfoOnCursorPosition(int slicer)
954 // int view = mSlicers[slicer]->GetSliceOrientation();
955 // int slice = mSlicers[slicer]->GetSlice();
956 double x = mSlicers[slicer]->GetCursorPosition()[0];
957 double y = mSlicers[slicer]->GetCursorPosition()[1];
958 double z = mSlicers[slicer]->GetCursorPosition()[2];
959 double X = (x - mSlicers[slicer]->GetInput()->GetOrigin()[0])/
960 mSlicers[slicer]->GetInput()->GetSpacing()[0];
961 double Y = (y - mSlicers[slicer]->GetInput()->GetOrigin()[1])/
962 mSlicers[slicer]->GetInput()->GetSpacing()[1];
963 double Z = (z - mSlicers[slicer]->GetInput()->GetOrigin()[2])/
964 mSlicers[slicer]->GetInput()->GetSpacing()[2];
965 double value = -VTK_DOUBLE_MAX;
967 double xVec=0, yVec=0, zVec=0, valueVec=0;
970 double valueOver=0, valueFus=0;
971 if (X >= mSlicers[slicer]->GetInput()->GetWholeExtent()[0] &&
972 X <= mSlicers[slicer]->GetInput()->GetWholeExtent()[1] &&
973 Y >= mSlicers[slicer]->GetInput()->GetWholeExtent()[2] &&
974 Y <= mSlicers[slicer]->GetInput()->GetWholeExtent()[3] &&
975 Z >= mSlicers[slicer]->GetInput()->GetWholeExtent()[4] &&
976 Z <= mSlicers[slicer]->GetInput()->GetWholeExtent()[5]) {
977 value = this->GetScalarComponentAsDouble(mSlicers[slicer]->GetInput(), X, Y, Z);
979 if (mSlicers[slicer]->GetVFActor() ) {
981 unsigned int currentTime = mSlicers[slicer]->GetTSlice();
982 vtkImageData *vf = NULL;
984 if (mSlicers[slicer]->GetVF()->GetVTKImages().size() > currentTime)
985 vf = mSlicers[slicer]->GetVF()->GetVTKImages()[currentTime];
987 vf = mSlicers[slicer]->GetVF()->GetVTKImages()[0];
990 double Xvf = (x - vf->GetOrigin()[0])/ vf->GetSpacing()[0];
991 double Yvf = (y - vf->GetOrigin()[1])/ vf->GetSpacing()[1];
992 double Zvf = (z - vf->GetOrigin()[2])/ vf->GetSpacing()[2];
993 xVec = this->GetScalarComponentAsDouble( vf, Xvf, Yvf, Zvf, 0);
994 yVec = this->GetScalarComponentAsDouble( vf, Xvf, Yvf, Zvf, 1);
995 zVec = this->GetScalarComponentAsDouble( vf, Xvf, Yvf, Zvf, 2);
996 valueVec = sqrt(xVec*xVec + yVec*yVec + zVec*zVec);
999 if (mSlicers[slicer]->GetOverlayActor() ) {
1001 vtkImageData *overlay = dynamic_cast<vtkImageData*>(mSlicers[slicer]->GetOverlayMapper()->GetInput());
1002 double Xover = (x - overlay->GetOrigin()[0]) / overlay->GetSpacing()[0];
1003 double Yover = (y - overlay->GetOrigin()[1]) / overlay->GetSpacing()[1];
1004 double Zover = (z - overlay->GetOrigin()[2]) / overlay->GetSpacing()[2];
1005 valueOver = this->GetScalarComponentAsDouble(overlay, Xover, Yover, Zover);
1007 if (mSlicers[slicer]->GetFusionActor() ) {
1009 vtkImageData *fusion = dynamic_cast<vtkImageData*>(mSlicers[slicer]->GetFusionMapper()->GetInput());
1010 double Xover = (x - fusion->GetOrigin()[0]) / fusion->GetSpacing()[0];
1011 double Yover = (y - fusion->GetOrigin()[1]) / fusion->GetSpacing()[1];
1012 double Zover = (z - fusion->GetOrigin()[2]) / fusion->GetSpacing()[2];
1013 valueFus = this->GetScalarComponentAsDouble(fusion, Xover, Yover, Zover);
1015 emit UpdatePosition(mSlicers[slicer]->GetCursorVisibility(),
1017 emit UpdateVector(displayVec,xVec, yVec, zVec, valueVec);
1018 emit UpdateOverlay(displayOver,valueOver,value);
1019 emit UpdateFusion(displayFus,valueFus);
1022 //----------------------------------------------------------------------------
1025 //----------------------------------------------------------------------------
1026 void vvSlicerManager::Activated()
1028 emit currentImageChanged(mId);
1030 //----------------------------------------------------------------------------
1033 //----------------------------------------------------------------------------
1034 void vvSlicerManager::Picked()
1036 emit currentPickedImageChanged(mId);
1038 //----------------------------------------------------------------------------
1041 //----------------------------------------------------------------------------
1042 void vvSlicerManager::UpdateWindowLevel()
1044 emit WindowLevelChanged();
1046 //----------------------------------------------------------------------------
1049 //----------------------------------------------------------------------------
1050 void vvSlicerManager::UpdateSlice(int slicer)
1052 if (mPreviousSlice[slicer] == mSlicers[slicer]->GetSlice()) {
1053 //DD("============= NOTHING");
1056 //std::cout << "vvSlicerManager::UpdateSlice " << slicer << " " << mSlicers[slicer]->GetSlice() << std::endl;
1057 emit UpdateSlice(slicer, mSlicers[slicer]->GetSlice());
1058 mSlicers[slicer]->Render(); // DS <-- I add this, this could/must be the only Render ...
1059 mPreviousSlice[slicer] = mSlicers[slicer]->GetSlice();
1061 //----------------------------------------------------------------------------
1064 //----------------------------------------------------------------------------
1065 void vvSlicerManager::UpdateTSlice(int slicer)
1067 int slice = mSlicers[slicer]->GetSlice();
1068 int tslice = mSlicers[slicer]->GetTSlice();
1069 if (mPreviousSlice[slicer] == slice) {
1070 if (mPreviousTSlice[slicer] == tslice) {
1071 // DD("************** NOTHING ***********");
1075 mPreviousSlice[slicer] = slice;
1076 mPreviousTSlice[slicer] = tslice;
1077 //std::cout << "vvSlicerManager::UpdateTSlice " << slicer << " " << tslice << std::endl;
1078 emit UpdateTSlice(slicer, tslice);
1080 //----------------------------------------------------------------------------
1083 //----------------------------------------------------------------------------
1084 void vvSlicerManager::UpdateSliceRange(int slicer)
1086 emit UpdateSliceRange(slicer,
1087 mSlicers[slicer]->GetSliceRange()[0], mSlicers[slicer]->GetSliceRange()[1],
1088 0,mSlicers[slicer]->GetTMax());
1090 //----------------------------------------------------------------------------
1092 //----------------------------------------------------------------------------
1093 void vvSlicerManager::SetSlicingPreset(SlicingPresetType preset)
1095 if(mSlicingPreset==preset)
1098 vtkMatrix4x4 *imageTransformInverse = vtkMatrix4x4::New();
1099 mImage->GetTransform()[this->GetTSlice()]->GetInverse(imageTransformInverse);
1101 for(int i=0; i< this->GetNumberOfSlicers(); i++){
1102 vvSlicer *s = this->GetSlicer(i);
1106 s->GetSlicingTransform()->Identity();
1108 case VOXELS_SLICING:
1109 s->GetSlicingTransform()->SetMatrix(imageTransformInverse);
1112 imageTransformInverse->Delete();
1115 s->ForceUpdateDisplayExtent();
1116 s->SetSlice((s->GetInput()->GetWholeExtent()[s->GetSliceOrientation()*2+1]
1117 +s->GetInput()->GetWholeExtent()[s->GetSliceOrientation()*2])/2.0);
1122 imageTransformInverse->Delete();
1123 mSlicingPreset = preset;
1126 //----------------------------------------------------------------------------
1128 //----------------------------------------------------------------------------
1129 void vvSlicerManager::SetPreset(int preset)
1131 //vtkLookupTable* LUT = static_cast<vtkLookupTable*>(mSlicers[0]->GetWindowLevel()->GetLookupTable());
1132 double window = mSlicers[0]->GetColorWindow();
1133 double level = mSlicers[0]->GetColorLevel();
1135 std::string component_type=mImage->GetScalarTypeAsITKString();
1139 mImage->GetScalarRange(range);
1140 window = range[1] - range[0];
1141 level = (range[1] + range[0])* 0.5;
1171 this->SetColorWindow(window);
1172 this->SetColorLevel(level);
1179 //----------------------------------------------------------------------------
1182 //----------------------------------------------------------------------------
1183 void vvSlicerManager::SetLocalColorWindowing(const int slicer, const bool bCtrlKey)
1186 int t = this->GetTSlice();
1187 if(bCtrlKey && this->mSlicers[slicer]->GetFusion()) {
1188 this->mSlicers[slicer]->GetExtremasAroundMousePointer(min, max,
1189 this->mSlicers[slicer]->GetFusion()->GetVTKImages()[t],
1190 this->mSlicers[slicer]->GetFusion()->GetTransform()[t]);
1191 this->SetFusionWindow(max-min);
1192 this->SetFusionLevel(0.5*(min+max));
1193 this->SetColorMap(mColorMap);
1195 else if(bCtrlKey && this->mSlicers[slicer]->GetOverlay()) {
1196 this->mSlicers[slicer]->GetExtremasAroundMousePointer(min, max,
1197 this->mSlicers[slicer]->GetOverlay()->GetVTKImages()[t],
1198 this->mSlicers[slicer]->GetOverlay()->GetTransform()[t]);
1199 if(this->mSlicers[slicer]->GetLinkOverlayWindowLevel()){
1200 this->SetColorWindow(max-min);
1201 this->SetColorLevel(0.5*(min+max));
1203 this->SetOverlayColorWindow(max-min);
1204 this->SetOverlayColorLevel(0.5*(min+max));
1208 this->mSlicers[slicer]->GetExtremasAroundMousePointer(min, max,
1209 this->mSlicers[slicer]->GetImage()->GetVTKImages()[t],
1210 this->mSlicers[slicer]->GetConcatenatedTransform());
1211 this->SetColorWindow(max-min);
1212 this->SetColorLevel(0.5*(min+max));
1216 this->UpdateWindowLevel();
1218 //----------------------------------------------------------------------------
1221 //----------------------------------------------------------------------------
1222 void vvSlicerManager::SetColorMap(int colormap)
1225 range[0] = mSlicers[0]->GetInput()->GetScalarRange()[0];
1226 range[1] = mSlicers[0]->GetInput()->GetScalarRange()[1];
1228 double window = mSlicers[0]->GetWindowLevel()->GetWindow();
1229 double level = mSlicers[0]->GetWindowLevel()->GetLevel();
1231 vtkLookupTable* LUT = static_cast<vtkLookupTable*>(mSlicers[0]->GetWindowLevel()->GetLookupTable());
1240 LUT = vtkLookupTable::New();
1241 LUT->SetValueRange(0,1);
1242 LUT->SetSaturationRange(1,1);
1243 LUT->SetHueRange(0,0.18);
1247 LUT = vtkLookupTable::New();
1248 LUT->SetValueRange(0,1);
1249 LUT->SetSaturationRange(1,1);
1250 LUT->SetHueRange(0.4,0.80);
1254 LUT = vtkLookupTable::New();
1255 LUT->SetValueRange(0.5,1);
1256 LUT->SetSaturationRange(1,1);
1257 LUT->SetHueRange(0.666,0);
1261 LUT = vtkLookupTable::New();
1262 LUT->SetValueRange(1,1);
1263 LUT->SetSaturationRange(1,1);
1264 LUT->SetHueRange(0,1);
1265 LUT->SetAlphaRange(1, 1);
1269 LUT = vtkLookupTable::New();
1270 LUT->SetValueRange(1,1);
1271 LUT->SetSaturationRange(1,1);
1272 LUT->SetHueRange(1,0.1);
1273 //LUT->SetRampToLinear();
1277 LUT->SetTableRange(level-fabs(window)/2,level+fabs(window)/2);
1280 vtkWindowLevelLookupTable* fusLUT = NULL;
1281 if (mSlicers[0]->GetFusion()) { // && mFusionColorMap >= 0) {
1282 fusLUT = vtkWindowLevelLookupTable::New();
1283 double fusRange [2];
1284 fusRange[0] = mFusionLevel - mFusionWindow/2;
1285 fusRange[1] = mFusionLevel + mFusionWindow/2;
1286 double* frange = mFusionReader->GetOutput()->GetVTKImages()[0]->GetScalarRange();
1287 fusLUT->SetTableRange(frange);
1288 fusLUT->SetValueRange(1,1);
1289 fusLUT->SetSaturationRange(1,1);
1290 fusLUT->SetAlphaRange(1, 1);
1291 fusLUT->SetWindow(mFusionWindow);
1292 fusLUT->SetLevel(mFusionLevel);
1293 if (mFusionColorMap == 1)
1294 fusLUT->SetHueRange(0,0.18);
1295 else if (mFusionColorMap == 2)
1296 fusLUT->SetHueRange(0.4,0.80);
1297 else if (mFusionColorMap == 3)
1299 fusLUT->SetHueRange(0.666, 0);
1300 fusLUT->SetValueRange(0.5, 1);
1302 else if (mFusionColorMap == 4)
1303 fusLUT->SetHueRange(0,1);
1304 else if (mFusionColorMap <= 0)
1306 fusLUT->SetValueRange(0,1);
1307 fusLUT->SetSaturationRange(0,0);
1310 fusLUT->ForceBuild();
1313 // set color table transparency
1314 //double alpha_range=(double)mFusionThresOpacity/10;
1315 double range_end = fusRange[0] + (double)mFusionThresOpacity*(fusRange[1] - fusRange[0])/100;
1316 double curr_value = fusRange[0];
1317 int nvalues = fusLUT->GetNumberOfTableValues();
1318 for (double i = 0; curr_value < range_end; i++) {
1319 fusLUT->GetTableValue(i, v);
1321 //if (curr_value >= -alpha_range && curr_value <= alpha_range) v[3] = pow(fabs(curr_value/alpha_range),2);
1323 fusLUT->SetTableValue(i, v);
1324 curr_value += (fusRange[1] - fusRange[0])/nvalues;
1327 for ( unsigned int i = 0; i < mSlicers.size(); i++) {
1329 if (mSlicers[i]->GetOverlay()) {
1330 vtkLookupTable* supLUT = vtkLookupTable::New();
1331 supLUT->SetTableRange(range[0],range[1]);
1332 supLUT->SetValueRange(1,1);
1333 supLUT->SetSaturationRange(1,1);
1334 supLUT->SetHueRange(double(mOverlayColor)/360,double(mOverlayColor)/360);
1336 vtkLookupTable* invLUT = vtkLookupTable::New();
1337 invLUT->SetTableRange(range[0],range[1]);
1338 invLUT->SetValueRange(1,1);
1339 invLUT->SetSaturationRange(1,1);
1340 invLUT->SetHueRange(double((mOverlayColor+180)%360)/360,double((mOverlayColor+180)%360)/360);
1342 dynamic_cast<vvImageMapToWLColors*>(mSlicers[i]->GetWindowLevel())
1343 ->SetWindowLevelMode(true);
1344 mSlicers[i]->GetWindowLevel()->SetLookupTable(supLUT);
1345 mSlicers[i]->GetOverlayMapper()->SetLookupTable(invLUT);
1348 } else if (mSlicers[i]->GetOverlay()) {
1349 //dynamic_cast<vvImageMapToWLColors*>(mSlicers[i]->GetWindowLevel())
1350 //->SetWindowLevelMode(false);
1351 mSlicers[i]->GetWindowLevel()->SetLookupTable(LUT);
1353 mSlicers[i]->GetWindowLevel()->SetLookupTable(LUT);
1356 if (mSlicers[i]->GetFusion()) {
1357 mSlicers[i]->ShowFusionLegend(mFusionShowLegend);
1358 mSlicers[i]->GetFusionMapper()->SetLookupTable(fusLUT);
1359 mSlicers[i]->GetFusionActor()->SetOpacity(double(mFusionOpacity)/100);
1365 mColorMap = colormap;
1367 //----------------------------------------------------------------------------
1370 //----------------------------------------------------------------------------
1371 vvLandmarks* vvSlicerManager::GetLandmarks()
1373 if (mLandmarks == NULL) {
1374 mLandmarks = new vvLandmarks(mSlicers[0]->GetTMax()+1);
1375 for (unsigned int i = 0; i < mSlicers.size(); i++)
1376 mSlicers[i]->SetLandmarks(mLandmarks);
1380 //----------------------------------------------------------------------------
1383 //----------------------------------------------------------------------------
1384 void vvSlicerManager::AddLandmark(float x,float y,float z,float t)
1386 double x_index = (x - mSlicers[0]->GetInput()->GetOrigin()[0])/mSlicers[0]->GetInput()->GetSpacing()[0];
1387 double y_index = (y - mSlicers[0]->GetInput()->GetOrigin()[1])/mSlicers[0]->GetInput()->GetSpacing()[1];
1388 double z_index = (z - mSlicers[0]->GetInput()->GetOrigin()[2])/mSlicers[0]->GetInput()->GetSpacing()[2];
1389 if (x_index >= mSlicers[0]->GetInput()->GetWholeExtent()[0]-0.5 &&
1390 x_index <= mSlicers[0]->GetInput()->GetWholeExtent()[1]+0.5 &&
1391 y_index >= mSlicers[0]->GetInput()->GetWholeExtent()[2]-0.5 &&
1392 y_index <= mSlicers[0]->GetInput()->GetWholeExtent()[3]+0.5 &&
1393 z_index >= mSlicers[0]->GetInput()->GetWholeExtent()[4]-0.5 &&
1394 z_index <= mSlicers[0]->GetInput()->GetWholeExtent()[5]+0.5) {
1395 double value = this->GetScalarComponentAsDouble(mSlicers[0]->GetInput(), x_index, y_index, z_index);
1396 this->GetLandmarks()->AddLandmark(x,y,z,t,value);
1397 emit LandmarkAdded();
1400 //----------------------------------------------------------------------------
1402 //----------------------------------------------------------------------------
1403 void vvSlicerManager::PrevImage(int slicer)
1405 emit ChangeImageWithIndexOffset(this, slicer, -1);
1407 //----------------------------------------------------------------------------
1409 //----------------------------------------------------------------------------
1410 void vvSlicerManager::NextImage(int slicer)
1412 emit ChangeImageWithIndexOffset(this, slicer, 1);
1414 //----------------------------------------------------------------------------
1416 //----------------------------------------------------------------------------
1417 void vvSlicerManager::VerticalSliderHasChanged(int slicer, int slice)
1419 emit AVerticalSliderHasChanged(slicer, slice);
1422 //----------------------------------------------------------------------------
1424 //----------------------------------------------------------------------------
1425 double vvSlicerManager::GetScalarComponentAsDouble(vtkImageData *image, double X, double Y, double Z, int component)
1428 return mSlicers[0]->GetScalarComponentAsDouble(image, X, Y, Z, ix, iy, iz, component);
1430 //----------------------------------------------------------------------------