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://www.centreleonberard.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 <QMessageBox>
24 #include "vvSlicerManagerCommand.h"
25 #include "vvGlyphSource.h"
26 #include "vvGlyph2D.h"
28 #include <vtkVersion.h>
29 #include <vtkExtentTranslator.h>
30 #include <vtkAlgorithm.h>
31 #include <vtkExecutive.h>
32 #include <vtkStreamingDemandDrivenPipeline.h>
33 #include <vtkInformation.h>
34 #include <vtkTextProperty.h>
35 #include <vtkTextActor.h>
36 #include <vtkTextSource.h>
37 #include <vtkActor2D.h>
38 #include <vtkCursor2D.h>
39 #include <vtkPolyDataMapper2D.h>
40 #include <vtkProperty2D.h>
41 #include <vtkCornerAnnotation.h>
42 #include <vtkImageMapToWindowLevelColors.h>
43 #include <vtkImageData.h>
44 #include <vtkImageActor.h>
45 #include <vvBlendImageActor.h>
46 #include <vtkToolkits.h>
47 #include <vtkObjectFactory.h>
48 #include <vtkPointData.h>
49 #include <vtkDataArray.h>
50 #include <vtkFloatArray.h>
51 #include <vtkClipPolyData.h>
52 #include <vtkActor2DCollection.h>
53 #include <vtkGlyph3D.h>
55 #include <vtkCursor3D.h>
56 #include <vtkProperty.h>
58 #include <vtkLightCollection.h>
59 #include <vtkScalarBarActor.h>
60 #include <vtkImageProperty.h>
61 #include <vtkLookupTable.h>
63 #include <vtkRenderer.h>
64 #include <vtkRendererCollection.h>
65 #include <vtkRenderWindow.h>
66 #include <vtkRenderWindowInteractor.h>
67 #include <vtkCamera.h>
68 #include <vtkCallbackCommand.h>
69 #include <vtkCommand.h>
70 #include <vtkPolyDataMapper.h>
73 #include <vtkExtractVOI.h>
74 #include <vtkSphereSource.h>
75 #include <vtkCutter.h>
76 #include <vtkAssignAttribute.h>
77 #include <vtkImageAccumulate.h>
78 #include <vtkImageReslice.h>
79 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
80 # include <vtkOpenGLImageSliceMapper.h>
81 # include <vtkImageMapper3D.h>
82 # include <vtkImageSliceMapper.h>
85 vtkStandardNewMacro(vvSlicer);
86 static void copyExtent(int* in, int* to){
87 for(int i=0; i<6; ++i)
92 //------------------------------------------------------------------------------
95 mFusionSequenceCode = -1;
96 this->UnInstallPipeline();
98 mReducedExtent = new int[6];
99 mRegisterExtent = NULL;
101 mCurrentFusionTSlice = 0;
102 mCurrentOverlayTSlice = 0;
103 mUseReducedExtent = false;
105 mCurrent[0] = -VTK_DOUBLE_MAX;
106 mCurrent[1] = -VTK_DOUBLE_MAX;
107 mCurrent[2] = -VTK_DOUBLE_MAX;
109 mCursor[0] = 0;//-VTK_DOUBLE_MAX;
110 mCursor[1] = 0;//-VTK_DOUBLE_MAX;
111 mCursor[2] = 0;//-VTK_DOUBLE_MAX;
112 mCursor[3] = 0;//-VTK_DOUBLE_MAX;
122 crossCursor = vtkSmartPointer<vtkCursor2D>::New();
123 crossCursor->AllOff();
124 crossCursor->AxesOn();
125 crossCursor->SetTranslationMode(1);
126 crossCursor->SetRadius(2);
128 pdm = vtkSmartPointer<vtkPolyDataMapper2D>::New();
129 #if VTK_MAJOR_VERSION <= 5
130 pdm->SetInput(crossCursor->GetOutput());
132 pdm->SetInputConnection(crossCursor->GetOutputPort(0));
135 pdmA = vtkSmartPointer<vtkActor2D>::New();
136 pdmA->SetMapper(pdm);
137 pdmA->GetProperty()->SetColor(255,10,212);
138 pdmA->SetVisibility(0);
139 pdmA->SetPickable(0);
141 ca = vtkSmartPointer<vtkCornerAnnotation>::New();
142 ca->GetTextProperty()->SetColor(255,10,212);
143 ca->SetVisibility(1);
151 legend = vtkSmartPointer<vtkScalarBarActor>::New();
152 //legend->SetTitle("test!");
153 legend->SetPosition(0.82,0.08);
154 //legend->SetWidth(0.1);
155 legend->SetVisibility(0);
156 legend->SetLabelFormat("%.1e");
157 this->GetRenderer()->AddActor(legend);
158 showFusionLegend = false;
160 this->InstallPipeline();
162 mLinkOverlayWindowLevel = true;
163 mImageVisibility = true;
165 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
166 this->GetImageActor()->GetMapper()->BorderOn();
169 mSlicingTransform = vtkSmartPointer<vtkTransform>::New();
170 mConcatenatedTransform = vtkSmartPointer<vtkTransform>::New();
171 mConcatenatedFusionTransform = vtkSmartPointer<vtkTransform>::New();
172 mConcatenatedOverlayTransform = vtkSmartPointer<vtkTransform>::New();
173 mConcatenatedVFTransform = vtkSmartPointer<vtkTransform>::New();
174 mFirstSetSliceOrientation = true;
176 //------------------------------------------------------------------------------
179 //------------------------------------------------------------------------------
180 vtkImageMapToWindowLevelColors* vvSlicer::GetOverlayMapper()
182 return mOverlayMapper.GetPointer();
184 //------------------------------------------------------------------------------
187 //------------------------------------------------------------------------------
188 vvBlendImageActor* vvSlicer::GetOverlayActor()
190 return mOverlayActor.GetPointer();
192 //------------------------------------------------------------------------------
195 //------------------------------------------------------------------------------
196 vtkImageMapToColors* vvSlicer::GetFusionMapper()
198 return mFusionMapper.GetPointer();
200 //------------------------------------------------------------------------------
203 //------------------------------------------------------------------------------
204 vtkImageActor* vvSlicer::GetFusionActor()
206 return mFusionActor.GetPointer();
208 //------------------------------------------------------------------------------
211 //------------------------------------------------------------------------------
212 vtkActor* vvSlicer::GetVFActor()
214 return mVFActor.GetPointer();
216 //------------------------------------------------------------------------------
219 //------------------------------------------------------------------------------
220 vtkCornerAnnotation* vvSlicer::GetAnnotation()
222 return ca.GetPointer();
224 //------------------------------------------------------------------------------
227 //------------------------------------------------------------------------------
228 void vvSlicer::EnableReducedExtent(bool b)
230 mUseReducedExtent = b;
232 //------------------------------------------------------------------------------
235 //------------------------------------------------------------------------------
236 void vvSlicer::SetReducedExtent(int * ext)
238 copyExtent(ext, mReducedExtent);
240 //------------------------------------------------------------------------------
243 //------------------------------------------------------------------------------
244 void vvSlicer::AddContour(vvMesh::Pointer contour,bool propagate)
247 mSurfaceCutActors.push_back(new vvMeshActor());
249 mSurfaceCutActors.back()->Init(contour,mCurrentTSlice,mVF);
251 mSurfaceCutActors.back()->Init(contour,mCurrentTSlice);
252 mSurfaceCutActors.back()->SetSlicingOrientation(SliceOrientation);
253 this->GetRenderer()->AddActor(mSurfaceCutActors.back()->GetActor());
257 //------------------------------------------------------------------------------
260 //------------------------------------------------------------------------------
261 void vvSlicer::ToggleContourSuperposition()
263 for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
264 i!=mSurfaceCutActors.end(); i++)
265 (*i)->ToggleSuperposition();
267 //------------------------------------------------------------------------------
270 //------------------------------------------------------------------------------
271 void vvSlicer::SetCursorColor(int r,int g, int b)
273 pdmA->GetProperty()->SetColor(r,g,b);
275 //------------------------------------------------------------------------------
278 //------------------------------------------------------------------------------
279 void vvSlicer::SetCursorVisibility(bool s)
281 pdmA->SetVisibility(s);
283 //------------------------------------------------------------------------------
286 //------------------------------------------------------------------------------
287 bool vvSlicer::GetCursorVisibility()
289 return pdmA->GetVisibility();
291 //------------------------------------------------------------------------------
294 //------------------------------------------------------------------------------
295 void vvSlicer::SetCornerAnnotationVisibility(bool s)
297 ca->SetVisibility(s);
299 //------------------------------------------------------------------------------
302 //------------------------------------------------------------------------------
303 bool vvSlicer::GetCornerAnnotationVisibility()
305 return ca->GetVisibility();
307 //------------------------------------------------------------------------------
310 //------------------------------------------------------------------------------
311 vvSlicer::~vvSlicer()
313 for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
314 i!=mSurfaceCutActors.end(); i++)
316 delete [] mReducedExtent;
318 //------------------------------------------------------------------------------
320 //------------------------------------------------------------------------------
321 double* vvSlicer::GetCurrentPosition()
323 return mCurrentBeforeSlicingTransform;
325 //------------------------------------------------------------------------------
327 //------------------------------------------------------------------------------
328 void vvSlicer::SetInterpolationImageReslice(int interpolation)
330 mImageReslice->SetInterpolationMode(interpolation);
332 //------------------------------------------------------------------------------
334 //------------------------------------------------------------------------------
335 void vvSlicer::SetCurrentPosition(double x, double y, double z, int t)
337 mCurrentBeforeSlicingTransform[0]=x;
338 mCurrentBeforeSlicingTransform[1]=y;
339 mCurrentBeforeSlicingTransform[2]=z;
340 mSlicingTransform->GetInverse()->TransformPoint(mCurrentBeforeSlicingTransform,mCurrent);
341 if (t>=0) SetTSlice(t);
343 //------------------------------------------------------------------------------
346 //------------------------------------------------------------------------------
347 void vvSlicer::SetImage(vvImage::Pointer image)
349 if (image->GetVTKImages().size()) {
352 if (!mImageReslice) {
353 mImageReslice = vtkSmartPointer<vtkImageReslice>::New();
354 mImageReslice->SetInterpolationModeToLinear();
355 mImageReslice->AutoCropOutputOn();
356 mImageReslice->SetBackgroundColor(-1000,-1000,-1000,1);
359 mConcatenatedTransform->Identity();
360 mConcatenatedTransform->Concatenate(mImage->GetTransform()[0]);
361 mConcatenatedTransform->Concatenate(mSlicingTransform);
362 mImageReslice->SetResliceTransform(mConcatenatedTransform);
363 //mImageReslice->SetResliceAxes(mConcatenatedTransform->GetMatrix());
364 #if VTK_MAJOR_VERSION <= 5
365 mImageReslice->SetInput(0, mImage->GetFirstVTKImageData());
367 mImageReslice->SetInputData(0, mImage->GetFirstVTKImageData());
369 mImageReslice->UpdateInformation();
371 #if VTK_MAJOR_VERSION <= 5
372 this->Superclass::SetInput(mImageReslice->GetOutput());
374 this->Superclass::SetInputConnection(mImageReslice->GetOutputPort());
378 #if VTK_MAJOR_VERSION <= 5
379 this->GetInput()->GetWholeExtent(extent);
381 int* ext = mImageReslice->GetInputInformation()->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT());
382 copyExtent(ext, extent);
385 // Prevent crash when reload -> change slice if outside extent
386 if (Slice < extent[SliceOrientation*2] || Slice>=extent[SliceOrientation*2+1]) {
387 Slice = (extent[SliceOrientation*2+1]+extent[SliceOrientation*2])/2.0;
390 // Make sure that the required part image has been computed
391 extent[SliceOrientation*2] = Slice;
392 extent[SliceOrientation*2+1] = Slice;
393 #if VTK_MAJOR_VERSION <= 5
394 mImageReslice->GetOutput()->SetUpdateExtent(extent);
395 mImageReslice->GetOutput()->Update();
396 #elif VTK_MAJOR_VERSION >= 7 && VTK_MINOR_VERSION >= 1
397 mImageReslice->UpdateExtent(extent);
398 mImageReslice->Update();
400 mImageReslice->SetUpdateExtent(extent);
401 mImageReslice->Update();
404 this->UpdateDisplayExtent();
407 ca->SetText(0,mFileName.c_str());
410 //------------------------------------------------------------------------------
413 //------------------------------------------------------------------------------
414 void vvSlicer::SetOverlay(vvImage::Pointer overlay)
416 if (overlay->GetVTKImages().size()) {
418 mOverlayVisibility = true;
420 if (!mOverlayReslice) {
421 mOverlayReslice = vtkSmartPointer<vtkImageReslice>::New();
422 mOverlayReslice->SetInterpolationModeToLinear();
423 mOverlayReslice->AutoCropOutputOn();
424 mOverlayReslice->SetBackgroundColor(-1000,-1000,-1000,1);
427 mConcatenatedOverlayTransform->Identity();
428 mConcatenatedOverlayTransform->Concatenate(mOverlay->GetTransform()[0]);
429 mConcatenatedOverlayTransform->Concatenate(mSlicingTransform);
430 mOverlayReslice->SetResliceTransform(mConcatenatedOverlayTransform);
431 #if VTK_MAJOR_VERSION <= 5
432 mOverlayReslice->SetInput(0, mOverlay->GetFirstVTKImageData());
433 mImageReslice->UpdateInformation();
435 mOverlayReslice->SetInputData(0, mOverlay->GetFirstVTKImageData());
437 mOverlayReslice->Update();
440 mOverlayMapper = vtkSmartPointer<vtkImageMapToWindowLevelColors>::New();
441 #if VTK_MAJOR_VERSION <= 5
442 mOverlayMapper->SetInput(mOverlayReslice->GetOutput());
444 mOverlayMapper->SetInputConnection(mOverlayReslice->GetOutputPort(0));
447 if (!mOverlayActor) {
448 mOverlayActor = vtkSmartPointer<vvBlendImageActor>::New();
449 #if VTK_MAJOR_VERSION <= 5
450 mOverlayActor->SetInput(mOverlayMapper->GetOutput());
452 mOverlayActor->GetMapper()->SetInputConnection(mOverlayMapper->GetOutputPort());
454 mOverlayActor->SetPickable(0);
455 mOverlayActor->SetVisibility(true);
456 mOverlayActor->SetOpacity(0.5);
457 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
458 mOverlayActor->GetMapper()->BorderOn();
462 //stupid but necessary : the Overlay need to be rendered before fusion
464 this->GetRenderer()->RemoveActor(mFusionActor);
465 this->GetRenderer()->AddActor(mOverlayActor);
466 this->GetRenderer()->AddActor(mFusionActor);
468 this->GetRenderer()->AddActor(mOverlayActor);
470 //Synchronize orientation and slice
471 AdjustResliceToSliceOrientation(mOverlayReslice);
472 this->UpdateDisplayExtent();
473 this->SetTSlice(mCurrentTSlice);
476 //------------------------------------------------------------------------------
479 //------------------------------------------------------------------------------
480 void vvSlicer::SetFusion(vvImage::Pointer fusion, int fusionSequenceCode)
482 mFusionSequenceCode = fusionSequenceCode;
483 if (fusion->GetVTKImages().size()) {
485 mFusionVisibility = true;
487 if (!mFusionReslice) {
488 mFusionReslice = vtkSmartPointer<vtkImageReslice>::New();
489 mFusionReslice->SetInterpolationModeToLinear();
490 mFusionReslice->AutoCropOutputOn();
491 mFusionReslice->SetBackgroundColor(-1000,-1000,-1000,1);
494 mConcatenatedFusionTransform->Identity();
495 mConcatenatedFusionTransform->Concatenate(mFusion->GetTransform()[0]);
496 mConcatenatedFusionTransform->Concatenate(mSlicingTransform);
497 mFusionReslice->SetResliceTransform(mConcatenatedFusionTransform);
498 #if VTK_MAJOR_VERSION <= 5
499 mFusionReslice->SetInput(0, mFusion->GetFirstVTKImageData());
500 mFusionReslice->UpdateInformation();
502 mFusionReslice->SetInputData(0, mFusion->GetFirstVTKImageData());
504 mFusionReslice->Update();
507 mFusionMapper = vtkSmartPointer<vtkImageMapToColors>::New();
509 vtkSmartPointer<vtkLookupTable> lut = vtkLookupTable::New();
511 lut->SetValueRange(0, 1);
512 lut->SetSaturationRange(0, 0);
514 mFusionMapper->SetLookupTable(lut);
515 #if VTK_MAJOR_VERSION <= 5
516 mFusionMapper->SetInput(mFusionReslice->GetOutput());
518 mFusionMapper->SetInputConnection(mFusionReslice->GetOutputPort(0));
522 mFusionActor = vtkSmartPointer<vtkImageActor>::New();
523 #if VTK_MAJOR_VERSION <= 5
524 mFusionActor->SetInput(mFusionMapper->GetOutput());
526 mFusionActor->GetMapper()->SetInputConnection(mFusionMapper->GetOutputPort());
528 mFusionActor->SetPickable(0);
529 mFusionActor->SetVisibility(true);
530 mFusionActor->SetOpacity(0.7);
531 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
532 mFusionActor->GetMapper()->BorderOn();
535 this->GetRenderer()->AddActor(mFusionActor);
538 //Synchronize orientation and slice
539 AdjustResliceToSliceOrientation(mFusionReslice);
540 this->UpdateDisplayExtent();
541 this->SetTSlice(mCurrentTSlice);
544 //------------------------------------------------------------------------------
547 //------------------------------------------------------------------------------
548 bool vvSlicer::GetActorVisibility(const std::string& actor_type, int overlay_index)
551 if (actor_type == "image")
552 vis = mImageVisibility;
553 else if (actor_type == "vector")
555 else if (actor_type == "overlay")
556 vis = mOverlayVisibility;
557 else if ( (actor_type == "fusion") || (actor_type == "fusionSequence") )
558 vis = mFusionVisibility;
559 else if (actor_type == "contour")
560 vis = this->mSurfaceCutActors[overlay_index]->GetActor()->GetVisibility();
563 //------------------------------------------------------------------------------
565 //------------------------------------------------------------------------------
566 void vvSlicer::SetActorVisibility(const std::string& actor_type, int overlay_index ,bool vis)
568 if (actor_type == "image")
569 mImageVisibility = vis;
570 else if (actor_type == "vector")
572 else if (actor_type == "overlay")
573 mOverlayVisibility = vis;
574 else if ( (actor_type == "fusion") || (actor_type == "fusionSequence") )
575 mFusionVisibility = vis;
576 else if (actor_type == "contour")
577 this->mSurfaceCutActors[overlay_index]->GetActor()->SetVisibility(vis);
578 UpdateDisplayExtent();
580 //------------------------------------------------------------------------------
582 //------------------------------------------------------------------------------
583 void vvSlicer::SetVF(vvImage::Pointer vf)
585 if (vf->GetVTKImages().size()) {
587 mVFVisibility = true;
590 mVFReslice = vtkSmartPointer<vtkImageReslice>::New();
591 mVFReslice->SetInterpolationModeToLinear();
592 mVFReslice->AutoCropOutputOn();
593 mVFReslice->SetBackgroundColor(-1000,-1000,-1000,1);
594 mAAFilter= vtkSmartPointer<vtkAssignAttribute>::New();
595 mVOIFilter = vtkSmartPointer<vtkExtractVOI>::New();
596 mVOIFilter->SetSampleRate(mSubSampling,mSubSampling,mSubSampling);
599 mConcatenatedVFTransform->Identity();
600 mConcatenatedVFTransform->Concatenate(mVF->GetTransform()[0]);
601 mConcatenatedVFTransform->Concatenate(mSlicingTransform);
602 mVFReslice->SetResliceTransform(mConcatenatedVFTransform);
603 #if VTK_MAJOR_VERSION <= 5
604 mVFReslice->SetInput(0, mVF->GetFirstVTKImageData());
606 mVFReslice->SetInputData(0, mVF->GetFirstVTKImageData());
608 mVFReslice->Update();
610 #if VTK_MAJOR_VERSION <= 5
611 mVOIFilter->SetInput(mVFReslice->GetOutput());
612 mAAFilter->SetInput(mVOIFilter->GetOutput());
614 mVOIFilter->SetInputConnection(mVFReslice->GetOutputPort());
615 mAAFilter->SetInputConnection(mVOIFilter->GetOutputPort());
617 ///This tells VTK to use the scalar (pixel) data of the image to draw the little arrows
618 mAAFilter->Assign(vtkDataSetAttributes::SCALARS, vtkDataSetAttributes::VECTORS, vtkAssignAttribute::POINT_DATA);
621 mArrow = vtkSmartPointer<vvGlyphSource>::New();
622 mArrow->SetGlyphTypeToSpecificArrow();
623 mArrow->SetScale(mScale);
626 // Glyph the gradient vector (with arrows)
628 mGlyphFilter = vtkSmartPointer<vvGlyph2D>::New();
629 #if VTK_MAJOR_VERSION <= 5
630 mGlyphFilter->SetInput(mAAFilter->GetOutput());
631 mGlyphFilter->SetSource(mArrow->GetOutput());
633 mGlyphFilter->SetInputConnection(mAAFilter->GetOutputPort());
634 mGlyphFilter->SetSourceConnection(mArrow->GetOutputPort());
636 mGlyphFilter->ScalingOn();
637 mGlyphFilter->SetScaleModeToScaleByVector();
638 mGlyphFilter->OrientOn();
639 mGlyphFilter->SetVectorModeToUseVector();
640 mGlyphFilter->SetColorModeToColorByVector();
643 mVFColorLUT = vtkSmartPointer<vtkLookupTable>::New();
645 double mVFColorHSV[3];
646 vtkMath::RGBToHSV(mVFColor, mVFColorHSV);
647 mVFColorLUT->SetHueRange(mVFColorHSV[0], mVFColorHSV[0]);
648 mVFColorLUT->SetSaturationRange(mVFColorHSV[1],mVFColorHSV[1]);
649 mVFColorLUT->SetValueRange(mVFColorHSV[2], mVFColorHSV[2]);
652 mVFMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
653 #if VTK_MAJOR_VERSION <= 5
654 mVFMapper->SetInput(mGlyphFilter->GetOutput());
656 mVFMapper->SetInputConnection(mGlyphFilter->GetOutputPort());
658 mVFMapper->ImmediateModeRenderingOn();
659 mVFMapper->SetLookupTable(mVFColorLUT);
662 mVFActor = vtkSmartPointer<vtkActor>::New();
663 mVFActor->SetMapper(mVFMapper);
664 mVFActor->SetPickable(0);
665 mVFActor->GetProperty()->SetLineWidth(mVFWidth);
666 this->UpdateDisplayExtent();
667 this->GetRenderer()->AddActor(mVFActor);
670 SetTSlice(mCurrentTSlice);
673 //------------------------------------------------------------------------------
676 //------------------------------------------------------------------------------
677 void vvSlicer::SetLandmarks(vvLandmarks* landmarks)
679 mLandmarks = landmarks;
683 mCross = vtkSmartPointer<vtkCursor3D>::New();
685 mClipBox = vtkSmartPointer<vtkBox>::New();
687 mLandClipper = vtkSmartPointer<vvClipPolyData>::New();
689 mLandGlyph = vtkSmartPointer<vtkGlyph3D>::New();
691 mLandMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
693 mLandActor = vtkSmartPointer<vtkActor>::New();
695 mCross->SetFocalPoint(0.0,0.0,0.0);
696 mCross->SetModelBounds(-10,10,-10,10,-10,10);
700 mLandClipper->SetClipFunction(mClipBox);
701 mLandClipper->InsideOutOn();
702 #if VTK_MAJOR_VERSION <= 5
703 mLandmarkTransform = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
704 mLandmarkTransform->SetInput(mLandmarks->GetOutput());
705 mConcatenatedTransform->Identity();
706 mConcatenatedTransform->Concatenate(mImage->GetTransform()[0]);
707 mConcatenatedTransform->Concatenate(mSlicingTransform);
708 mLandmarkTransform->SetTransform(mConcatenatedTransform->GetInverse());
709 mLandClipper->SetInput(mLandmarkTransform->GetOutput());
711 mLandGlyph->SetSource(mCross->GetOutput());
712 mLandGlyph->SetInput(mLandClipper->GetOutput());
714 mLandmarkTransform = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
715 mLandmarkTransform->SetInputData(mLandmarks->GetOutput());
716 mConcatenatedTransform->Identity();
717 mConcatenatedTransform->Concatenate(mImage->GetTransform()[0]);
718 mConcatenatedTransform->Concatenate(mSlicingTransform);
719 mLandmarkTransform->SetTransform(mConcatenatedTransform->GetInverse());
720 mLandClipper->SetInputConnection(mLandmarkTransform->GetOutputPort());
722 mLandGlyph->SetSourceConnection(mCross->GetOutputPort());
723 mLandGlyph->SetInputConnection(mLandClipper->GetOutputPort());
725 //mLandGlyph->SetIndexModeToScalar();
726 //mLandGlyph->SetRange(0,1);
727 //mLandGlyph->ScalingOff();
729 //mLandGlyph->SetColorModeToColorByScalar();
731 mLandGlyph->SetScaleModeToDataScalingOff();
732 mLandGlyph->SetIndexModeToOff();
734 mLandMapper->SetInputConnection(mLandGlyph->GetOutputPort());
735 //mLandMapper->ScalarVisibilityOff();
737 mLandActor->SetMapper(mLandMapper);
738 mLandActor->GetProperty()->SetOpacity(0.995); //in order to get VTK to turn on the alpha-blending in OpenGL
739 mLandActor->GetProperty()->SetColor(255,10,212);
740 mLandActor->SetPickable(0);
741 mLandActor->SetVisibility(true);
742 this->UpdateDisplayExtent();
745 //------------------------------------------------------------------------------
747 //------------------------------------------------------------------------------
748 //FIXME: this function leaks memory, we should fix it someday :)
749 void vvSlicer::RemoveActor(const std::string& actor_type, int overlay_index)
751 if (actor_type == "vector") {
752 Renderer->RemoveActor(mVFActor);
761 if (actor_type == "overlay") {
762 Renderer->RemoveActor(mOverlayActor);
764 mOverlayActor = NULL;
765 mOverlayMapper = NULL;
767 if ( (actor_type == "fusion") || (actor_type == "fusionSequence") ) {
768 Renderer->RemoveActor(mFusionActor);
771 mFusionMapper = NULL;
773 if (actor_type == "contour") {
774 Renderer->RemoveActor(this->mSurfaceCutActors[overlay_index]->GetActor());
775 mSurfaceCutActors.erase(mSurfaceCutActors.begin()+overlay_index);
778 //------------------------------------------------------------------------------
781 //------------------------------------------------------------------------------
782 void vvSlicer::SetVFSubSampling(int sub)
785 mVOIFilter->SetSampleRate(mSubSampling,mSubSampling,mSubSampling);
788 UpdateDisplayExtent();
791 //------------------------------------------------------------------------------
794 //------------------------------------------------------------------------------
795 void vvSlicer::SetVFScale(int scale)
799 mArrow->SetScale(mScale);
800 UpdateDisplayExtent();
803 //------------------------------------------------------------------------------
805 //------------------------------------------------------------------------------
806 void vvSlicer::SetVFWidth(int width)
810 mVFActor->GetProperty()->SetLineWidth(mVFWidth);
811 UpdateDisplayExtent();
814 //------------------------------------------------------------------------------
817 //------------------------------------------------------------------------------
818 void vvSlicer::SetVFLog(int log)
822 mGlyphFilter->SetUseLog(mVFLog);
823 mGlyphFilter->Modified();
825 UpdateDisplayExtent();
828 //------------------------------------------------------------------------------
831 //------------------------------------------------------------------------------
832 void vvSlicer::SetTSlice(int t, bool updateLinkedImages)
834 if (!updateLinkedImages) {
836 #if VTK_MAJOR_VERSION <= 5
837 mImageReslice->SetInput( mImage->GetVTKImages()[mCurrentTSlice] );
839 mImageReslice->SetInputData( mImage->GetVTKImages()[mCurrentTSlice] );
842 mConcatenatedTransform->Identity();
843 mConcatenatedTransform->Concatenate(mImage->GetTransform()[mCurrentTSlice]);
844 mConcatenatedTransform->Concatenate(mSlicingTransform);
845 UpdateDisplayExtent();
850 else if ((unsigned int)t >= mImage->GetVTKImages().size())
851 mCurrentTSlice = mImage->GetVTKImages().size() -1;
856 mConcatenatedTransform->Identity();
857 mConcatenatedTransform->Concatenate(mImage->GetTransform()[mCurrentTSlice]);
858 mConcatenatedTransform->Concatenate(mSlicingTransform);
861 #if VTK_MAJOR_VERSION <= 5
862 mImageReslice->SetInput( mImage->GetVTKImages()[mCurrentTSlice] );
864 mImageReslice->SetInputData( mImage->GetVTKImages()[mCurrentTSlice] );
866 if (mVF && mVFActor->GetVisibility()) {
867 if (mVF->GetVTKImages().size() > (unsigned int)mCurrentTSlice)
868 #if VTK_MAJOR_VERSION <= 5
869 mVFReslice->SetInput(mVF->GetVTKImages()[mCurrentTSlice]);
871 mVFReslice->SetInputData(mVF->GetVTKImages()[mCurrentTSlice]);
873 // Update overlay transform
874 mConcatenatedVFTransform->Identity();
875 mConcatenatedVFTransform->Concatenate(mVF->GetTransform()[mCurrentTSlice]);
876 mConcatenatedVFTransform->Concatenate(mSlicingTransform);
879 if (mOverlay && mOverlayActor->GetVisibility()) {
880 if (mOverlay->GetVTKImages().size() > (unsigned int)t) {
881 mCurrentOverlayTSlice = t;
882 #if VTK_MAJOR_VERSION <= 5
883 mOverlayReslice->SetInput( mOverlay->GetVTKImages()[mCurrentOverlayTSlice] );
885 mOverlayReslice->SetInputData( mOverlay->GetVTKImages()[mCurrentOverlayTSlice] );
887 // Update overlay transform
888 mConcatenatedOverlayTransform->Identity();
889 mConcatenatedOverlayTransform->Concatenate(mOverlay->GetTransform()[mCurrentOverlayTSlice]);
890 mConcatenatedOverlayTransform->Concatenate(mSlicingTransform);
893 //update the fusion ; except in case this is a fusionSequence, in which case both 'times' should be independent.
894 if (mFusion && mFusionActor->GetVisibility() && (mFusionSequenceCode<0)) {
895 if (mFusion->GetVTKImages().size() > (unsigned int)t) {
896 mCurrentFusionTSlice = t;
897 #if VTK_MAJOR_VERSION <= 5
898 mFusionReslice->SetInput( mFusion->GetVTKImages()[mCurrentFusionTSlice]);
900 mFusionReslice->SetInputData( mFusion->GetVTKImages()[mCurrentFusionTSlice]);
903 // Update fusion transform
904 mConcatenatedFusionTransform->Identity();
905 mConcatenatedFusionTransform->Concatenate(mFusion->GetTransform()[mCurrentFusionTSlice]);
906 mConcatenatedFusionTransform->Concatenate(mSlicingTransform);
909 if (mSurfaceCutActors.size() > 0)
910 for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
911 i!=mSurfaceCutActors.end(); i++)
912 (*i)->SetTimeSlice(mCurrentTSlice);
913 UpdateDisplayExtent();
915 //------------------------------------------------------------------------------
918 //------------------------------------------------------------------------------
919 void vvSlicer::SetFusionSequenceTSlice(int t)
921 if (mFusion && mFusionActor->GetVisibility() && (mFusionSequenceCode>=0)) {
922 if (mFusion->GetVTKImages().size() > (unsigned int)t) {
923 mCurrentFusionTSlice = t;
924 #if VTK_MAJOR_VERSION <= 5
925 mFusionReslice->SetInput( mFusion->GetVTKImages()[mCurrentFusionTSlice] );
927 mFusionReslice->SetInputData( mFusion->GetVTKImages()[mCurrentFusionTSlice] );
929 // Update fusion transform
930 mConcatenatedFusionTransform->Identity();
931 mConcatenatedFusionTransform->Concatenate(mFusion->GetTransform()[mCurrentFusionTSlice]); //not really useful...
932 mConcatenatedFusionTransform->Concatenate(mSlicingTransform);
936 UpdateDisplayExtent();
938 //------------------------------------------------------------------------------
941 //------------------------------------------------------------------------------
942 int vvSlicer::GetTSlice()
944 return mCurrentTSlice;
946 //------------------------------------------------------------------------------
948 //------------------------------------------------------------------------------
949 int vvSlicer::GetMaxCurrentTSlice()
951 int t = mCurrentTSlice;
952 if(mOverlay && mOverlayActor->GetVisibility())
953 t = std::max(t, mCurrentOverlayTSlice);
954 if(mFusion&& (mFusionSequenceCode<0) && mFusionActor->GetVisibility()) //ignore fusionSequence data: for these, the times are not to be related (this way)
955 t = std::max(t, mCurrentFusionTSlice);
958 //------------------------------------------------------------------------------
960 //------------------------------------------------------------------------------
961 int vvSlicer::GetFusionTSlice()
963 return mCurrentFusionTSlice;
965 //------------------------------------------------------------------------------
967 //------------------------------------------------------------------------------
968 int vvSlicer::GetOverlayTSlice()
970 return mCurrentOverlayTSlice;
972 //------------------------------------------------------------------------------
974 //------------------------------------------------------------------------------
975 void vvSlicer::SetSliceOrientation(int orientation)
977 //if 2D image, force to watch in Axial View
979 #if VTK_MAJOR_VERSION <= 5
980 this->GetInput()->GetWholeExtent(extent);
982 int* ext = mImageReslice->GetInputInformation()->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT());
983 copyExtent(ext, extent);
986 if (extent[5]-extent[4] <= 2)
987 orientation = vtkImageViewer2::SLICE_ORIENTATION_XY;
989 if (orientation < vtkImageViewer2::SLICE_ORIENTATION_YZ ||
990 orientation > vtkImageViewer2::SLICE_ORIENTATION_XY) {
991 vtkErrorMacro("Error - invalid slice orientation " << orientation);
995 this->SliceOrientation = orientation;
998 AdjustResliceToSliceOrientation(mFusionReslice);
1001 AdjustResliceToSliceOrientation(mOverlayReslice);
1004 AdjustResliceToSliceOrientation(mVFReslice);
1006 // Update the viewer
1008 // Go to current cursor position
1009 // double* cursorPos = GetCursorPosition();
1010 // DDV(cursorPos, 3);
1011 // SetCurrentPosition(cursorPos[0],cursorPos[1],cursorPos[2],cursorPos[3]);
1013 if (mFirstSetSliceOrientation) {
1014 int *range = this->GetSliceRange();
1016 this->Slice = static_cast<int>((range[0] + range[1]) * 0.5);
1017 #if VTK_MAJOR_VERSION <= 5
1018 mFirstSetSliceOrientation = false;
1021 else if (this->Renderer && this->GetInput()) {
1022 double s = mCursor[orientation];
1023 double sCursor = (s - this->GetInput()->GetOrigin()[orientation])/this->GetInput()->GetSpacing()[orientation];
1024 this->Slice = static_cast<int>(sCursor);
1027 this->UpdateOrientation();
1029 this->UpdateDisplayExtent();
1031 if (mFirstSetSliceOrientation) {
1032 mFirstSetSliceOrientation = false;
1035 if (this->Renderer && this->GetInput()) {
1036 double scale = this->Renderer->GetActiveCamera()->GetParallelScale();
1037 this->Renderer->ResetCamera();
1038 this->Renderer->GetActiveCamera()->SetParallelScale(scale);
1043 //----------------------------------------------------------------------------
1045 //------------------------------------------------------------------------------
1046 // This function ensures that we sample the slices of a vtkImageReslice filter
1047 // in the direction of the slicer (SliceOrientation) similarly as mImageReslice.
1048 // In other words, we change the grid of the reslice in the same way as the grid
1049 // of the displayed image in the slicing direction.
1050 void vvSlicer::AdjustResliceToSliceOrientation(vtkImageReslice *reslice)
1052 // Reset autocrop and update output information
1053 reslice->SetOutputOriginToDefault();
1054 reslice->SetOutputSpacingToDefault();
1055 #if VTK_MAJOR_VERSION <= 5
1056 reslice->GetOutput()->UpdateInformation();
1058 reslice->UpdateInformation();
1061 // Ge new origin / spacing
1064 reslice->GetOutput()->GetOrigin(origin);
1065 reslice->GetOutput()->GetSpacing(spacing);
1067 // Use similar spacing as the image in the direction SliceOrientation
1068 spacing[this->SliceOrientation] = mImageReslice->GetOutput()->GetSpacing()[this->SliceOrientation];
1070 // Modify origin to be on the image grid in the direction SliceOrientation in 3 steps
1071 // Step 1: from world coordinates to image coordinates
1072 origin[this->SliceOrientation] -= mImageReslice->GetOutput()->GetOrigin()[this->SliceOrientation];
1073 origin[this->SliceOrientation] /= mImageReslice->GetOutput()->GetSpacing()[this->SliceOrientation];
1075 // Step 2: round to nearest grid positionInc. This has been validated as the only
1076 // way to have something consistent with the thickness of a 2D slice visible on the
1077 // other slices. The thickness is accounted for so if the 2D slice is to thin and
1078 // between two slices, one will never be able to see this 2D slice (bug #1883).
1079 origin[this->SliceOrientation] = itk::Math::Round<double>(origin[this->SliceOrientation]);
1081 // Step 3: back to world coordinates
1082 origin[this->SliceOrientation] *= mImageReslice->GetOutput()->GetSpacing()[this->SliceOrientation];
1083 origin[this->SliceOrientation] += mImageReslice->GetOutput()->GetOrigin()[this->SliceOrientation];
1085 // Set new spacing and origin
1086 reslice->SetOutputOrigin(origin);
1087 reslice->SetOutputSpacing(spacing);
1088 reslice->UpdateInformation();
1089 #if VTK_MAJOR_VERSION <= 5
1090 reslice->GetOutput()->UpdateInformation();
1093 //------------------------------------------------------------------------------
1095 //----------------------------------------------------------------------------
1096 int * vvSlicer::GetExtent()
1099 if (mUseReducedExtent) {
1100 w_ext = mReducedExtent;
1103 #if VTK_MAJOR_VERSION <= 5
1104 w_ext = GetInput()->GetWholeExtent();
1106 w_ext = mImageReslice->GetInputInformation()->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT());
1111 //----------------------------------------------------------------------------
1114 //----------------------------------------------------------------------------
1115 int vvSlicer::GetOrientation()
1117 return this->SliceOrientation;
1119 //----------------------------------------------------------------------------
1122 //----------------------------------------------------------------------------
1123 void vvSlicer::UpdateDisplayExtent()
1125 emit UpdateDisplayExtentBegin(mSlicerNumber);
1126 vtkImageData *input = this->GetInput();
1127 if (!input || !this->ImageActor) {
1131 #if VTK_MAJOR_VERSION <= 5
1132 input->UpdateInformation();
1134 mRegisterExtent = mImageReslice->GetOutputInformation(0)->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT());
1136 this->SetSlice( this->GetSlice() ); //SR: make sure the update let the slice in extents
1138 // Local copy of extent
1140 #if VTK_MAJOR_VERSION <= 5
1141 int* ext = GetExtent();
1143 int* ext = mImageReslice->GetOutputInformation(0)->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT());
1145 copyExtent(ext, w_ext);
1146 if (mUseReducedExtent) {
1147 copyExtent(mReducedExtent, w_ext);
1151 w_ext[ this->SliceOrientation*2 ] = this->Slice;
1152 w_ext[ this->SliceOrientation*2+1 ] = this->Slice;
1155 this->ImageActor->SetVisibility(mImageVisibility);
1156 this->ImageActor->SetDisplayExtent(w_ext);
1158 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
1159 // Fix for bug #1882
1160 dynamic_cast<vtkImageSliceMapper *>(this->ImageActor->GetMapper())->SetOrientation(this->GetOrientation());
1163 // Overlay image actor
1164 if (mOverlay && mOverlayVisibility) {
1165 AdjustResliceToSliceOrientation(mOverlayReslice);
1167 #if VTK_MAJOR_VERSION <= 5
1168 this->ConvertImageToImageDisplayExtent(input, w_ext, mOverlayReslice->GetOutput(), overExtent);
1169 bool out = ClipDisplayedExtent(overExtent, mOverlayMapper->GetInput()->GetWholeExtent());
1171 this->ConvertImageToImageDisplayExtent(mImageReslice->GetOutputInformation(0), w_ext, mOverlayReslice->GetOutput(), overExtent);
1172 bool out = ClipDisplayedExtent(overExtent, mOverlayMapper->GetInputInformation()->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT()));
1174 mOverlayActor->SetVisibility(!out);
1175 mOverlayActor->SetDisplayExtent( overExtent );
1176 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
1177 // Fix for bug #1882
1178 dynamic_cast<vtkImageSliceMapper *>(mOverlayActor->GetMapper())->SetOrientation(this->GetOrientation());
1182 mOverlayActor->SetVisibility(false);
1184 // Fusion image actor
1185 if (mFusion && mFusionVisibility) {
1186 AdjustResliceToSliceOrientation(mFusionReslice);
1188 #if VTK_MAJOR_VERSION <= 5
1189 this->ConvertImageToImageDisplayExtent(input, w_ext, mFusionReslice->GetOutput(), fusExtent);
1190 bool out = ClipDisplayedExtent(fusExtent, mFusionMapper->GetInput()->GetWholeExtent());
1192 this->ConvertImageToImageDisplayExtent(mImageReslice->GetOutputInformation(0), w_ext, mFusionReslice->GetOutput(), fusExtent);
1193 bool out = ClipDisplayedExtent(fusExtent, mFusionMapper->GetInputInformation()->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT()));
1195 mFusionActor->SetVisibility(!out);
1196 mFusionActor->SetDisplayExtent( fusExtent );
1197 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
1198 // Fix for bug #1882
1199 dynamic_cast<vtkImageSliceMapper *>(mFusionActor->GetMapper())->SetOrientation(this->GetOrientation());
1203 mFusionActor->SetVisibility(false);
1204 // Vector field actor
1205 double* camera = Renderer->GetActiveCamera()->GetPosition();
1206 double* image_bounds = ImageActor->GetBounds();
1207 double position[3] = {0, 0, 0};
1208 position[this->SliceOrientation] = image_bounds[this->SliceOrientation*2];
1210 //print_vector<double, 6>("camera", camera);
1211 //print_vector<double, 6>("image_bounds", image_bounds);
1212 //print_vector<double, 3>("position", position);
1214 // find where to place the VF actor. to deal with
1215 // z-buffer issues, the VF is placed right in front of the image,
1216 // subject to a small offset. the position actually depends on the
1217 // the location of the camera relative to the image.
1219 if (camera[this->SliceOrientation] < image_bounds[this->SliceOrientation*2])
1222 if (mVF && mVFVisibility) {
1223 AdjustResliceToSliceOrientation(mVFReslice);
1225 #if VTK_MAJOR_VERSION <= 5
1226 mVF->GetVTKImages()[0]->UpdateInformation();
1227 this->ConvertImageToImageDisplayExtent(input, w_ext, mVFReslice->GetOutput(), vfExtent);
1228 bool out = ClipDisplayedExtent(vfExtent, mVOIFilter->GetInput()->GetWholeExtent());
1230 mVOIFilter->Update();
1231 this->ConvertImageToImageDisplayExtent(mImageReslice->GetOutputInformation(0), w_ext, mVFReslice->GetOutput(), vfExtent);
1232 bool out = ClipDisplayedExtent(vfExtent, mVOIFilter->GetInputInformation()->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT()));
1234 mVFActor->SetVisibility(!out);
1235 mVOIFilter->SetVOI(vfExtent);
1236 int orientation[3] = {1,1,1};
1237 orientation[this->SliceOrientation] = 0;
1238 mGlyphFilter->SetOrientation(orientation[0], orientation[1], orientation[2]);
1239 position[this->SliceOrientation] += offset;
1240 mVFActor->SetPosition(position);
1241 mVFActor->GetProperty()->SetOpacity(0.995); //in order to get VTK to turn on the alpha-blending in OpenGL
1242 mVFMapper->Update();
1246 mVFActor->SetVisibility(false);
1250 for(unsigned int i=0; i<6; i++)
1251 boundsT[i] = ImageActor->GetBounds()[i];
1252 boundsT[ this->SliceOrientation*2 ] = ImageActor->GetBounds()[ this->SliceOrientation*2 ]-fabs(this->GetInput()->GetSpacing()[this->SliceOrientation]);
1253 boundsT[ this->SliceOrientation*2+1 ] = ImageActor->GetBounds()[ this->SliceOrientation*2+1 ]+fabs(this->GetInput()->GetSpacing()[this->SliceOrientation]);
1262 position[this->SliceOrientation] = offset;
1263 mLandActor->SetPosition(position);
1266 // Figure out the correct clipping range
1267 if (this->Renderer) {
1268 if (this->InteractorStyle &&
1269 this->InteractorStyle->GetAutoAdjustCameraClippingRange()) {
1270 this->Renderer->ResetCameraClippingRange();
1272 vtkCamera *cam = this->Renderer->GetActiveCamera();
1275 this->ImageActor->GetBounds(bounds);
1276 double spos = (double)bounds[this->SliceOrientation * 2];
1277 double cpos = (double)cam->GetPosition()[this->SliceOrientation];
1278 double range = fabs(spos - cpos);
1279 double *spacing = input->GetSpacing();
1280 double sumSpacing = spacing[0] + spacing[1] + spacing[2];
1281 cam->SetClippingRange(range - sumSpacing, range + sumSpacing);
1291 emit UpdateDisplayExtentEnd(mSlicerNumber);
1293 //----------------------------------------------------------------------------
1295 //----------------------------------------------------------------------------
1296 void vvSlicer::ConvertImageToImageDisplayExtent(vtkInformation *sourceImage, const int sourceExtent[6],
1297 vtkImageData *targetImage, int targetExtent[6])
1300 double *origin, *spacing;
1301 origin = sourceImage->Get(vtkDataObject::ORIGIN());
1302 spacing = sourceImage->Get(vtkDataObject::SPACING());
1303 for(unsigned int i=0; i<6; i++) {
1304 // From source voxel coordinates to world coordinates
1305 dExtents[i] = origin[i/2] + spacing[i/2] * sourceExtent[i];
1307 // From world coordinates to floating point target voxel coordinates
1308 dExtents[i] = (dExtents[i]- targetImage->GetOrigin()[i/2]) / targetImage->GetSpacing()[i/2];
1310 // Round to current slice or larger extent
1311 if(i/2==this->GetOrientation())
1312 targetExtent[i] = itk::Math::Round<double>(dExtents[i]);
1314 targetExtent[i] = itk::Math::Ceil<double>(dExtents[i]);
1316 targetExtent[i] = itk::Math::Floor<double>(dExtents[i]);
1319 //----------------------------------------------------------------------------
1321 //----------------------------------------------------------------------------
1322 void vvSlicer::ConvertImageToImageDisplayExtent(vtkImageData *sourceImage, const int sourceExtent[6],
1323 vtkImageData *targetImage, int targetExtent[6])
1326 for(unsigned int i=0; i<6; i++) {
1327 // From source voxel coordinates to world coordinates
1328 dExtents[i] = sourceImage->GetOrigin()[i/2] + sourceImage->GetSpacing()[i/2] * sourceExtent[i];
1330 // From world coordinates to floating point target voxel coordinates
1331 dExtents[i] = (dExtents[i]- targetImage->GetOrigin()[i/2]) / targetImage->GetSpacing()[i/2];
1333 // Round to current slice or larger extent
1334 if(i/2==this->GetOrientation())
1335 targetExtent[i] = itk::Math::Round<double>(dExtents[i]);
1337 targetExtent[i] = itk::Math::Ceil<double>(dExtents[i]);
1339 targetExtent[i] = itk::Math::Floor<double>(dExtents[i]);
1342 //----------------------------------------------------------------------------
1344 //----------------------------------------------------------------------------
1345 bool vvSlicer::ClipDisplayedExtent(int extent[6], int refExtent[6])
1350 for (int i = 0; i < maxBound; i = i+2) {
1351 //if we are totally outside the image
1352 if ( extent[i] > refExtent[i+1] || extent[i+1] < refExtent[i] ) {
1356 //crop to the limit of the image
1357 extent[i] = std::max(extent[i], refExtent[i]);
1358 extent[i] = std::min(extent[i], refExtent[i+1]);;
1359 extent[i+1] = std::max(extent[i+1], refExtent[i]);
1360 extent[i+1] = std::min(extent[i+1], refExtent[i+1]);;
1363 for (int i = 0; i < maxBound; i = i+2) {
1364 extent[i] = refExtent[i];
1365 extent[i+1] = refExtent[i];
1369 //----------------------------------------------------------------------------
1372 //----------------------------------------------------------------------------
1373 void vvSlicer::UpdateOrientation()
1375 // Set the camera position
1376 vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
1378 switch (this->SliceOrientation) {
1379 case vtkImageViewer2::SLICE_ORIENTATION_XY:
1380 cam->SetFocalPoint(0,0,0);
1381 cam->SetPosition(0,0,-1); // -1 if medical ?
1382 cam->SetViewUp(0,-1,0);
1385 case vtkImageViewer2::SLICE_ORIENTATION_XZ:
1386 cam->SetFocalPoint(0,0,0);
1387 cam->SetPosition(0,-1,0); // 1 if medical ?
1388 cam->SetViewUp(0,0,1);
1391 case vtkImageViewer2::SLICE_ORIENTATION_YZ:
1392 cam->SetFocalPoint(0,0,0);
1393 cam->SetPosition(-1,0,0); // -1 if medical ?
1394 cam->SetViewUp(0,0,1);
1399 //----------------------------------------------------------------------------
1402 //----------------------------------------------------------------------------
1403 void vvSlicer::SetOpacity(double s)
1405 this->GetImageActor()->SetOpacity(s);
1407 //----------------------------------------------------------------------------
1410 //----------------------------------------------------------------------------
1411 void vvSlicer::SetRenderWindow(int orientation, vtkRenderWindow * rw)
1413 this->Superclass::SetRenderWindow(rw);
1414 this->SetupInteractor(rw->GetInteractor());
1415 ca->SetImageActor(this->GetImageActor());
1416 ca->SetWindowLevel(this->GetWindowLevel());
1417 ca->SetText(3, "<window>\n<level>");
1428 crossCursor->SetModelBounds(bounds);
1430 this->GetRenderer()->AddActor(pdmA);
1431 this->GetRenderer()->AddActor(ca);
1432 this->GetRenderer()->ResetCamera();
1434 //this is just a mapping between the labeling of the orientations presented to the user and
1435 //the one used by vtk
1436 SetSliceOrientation(2-(orientation%3));
1439 //----------------------------------------------------------------------------
1442 //----------------------------------------------------------------------------
1443 void vvSlicer::ResetCamera()
1445 this->GetRenderer()->ResetCamera();
1447 //----------------------------------------------------------------------------
1450 //----------------------------------------------------------------------------
1451 void vvSlicer::SetDisplayMode(bool i)
1453 this->GetRenderer()->SetDraw(i);
1454 if (i) UpdateDisplayExtent();
1456 //----------------------------------------------------------------------------
1459 //----------------------------------------------------------------------------
1460 void vvSlicer::FlipHorizontalView()
1462 vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
1464 double *position = cam->GetPosition();
1465 double factor[3] = {1, 1, 1};
1466 factor[this->SliceOrientation] = -1;
1467 cam->SetPosition(factor[0]*position[0],factor[1]*position[1],factor[2]*position[2]);
1469 /* switch (this->SliceOrientation) {
1470 case vtkImageViewer2::SLICE_ORIENTATION_XY:
1471 cam->SetPosition(position[0],position[1],-position[2]);
1474 case vtkImageViewer2::SLICE_ORIENTATION_XZ:
1475 cam->SetPosition(position[0],-position[1],position[2]);
1478 case vtkImageViewer2::SLICE_ORIENTATION_YZ:
1479 cam->SetPosition(-position[0],position[1],position[2]);
1483 this->Renderer->ResetCameraClippingRange();
1484 this->UpdateDisplayExtent();
1487 //----------------------------------------------------------------------------
1490 //----------------------------------------------------------------------------
1491 void vvSlicer::FlipVerticalView()
1493 vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
1495 FlipHorizontalView();
1496 double *viewup = cam->GetViewUp();
1497 cam->SetViewUp(-viewup[0],-viewup[1],-viewup[2]);
1498 this->UpdateDisplayExtent();
1501 //----------------------------------------------------------------------------
1504 //----------------------------------------------------------------------------
1505 void vvSlicer::SetColorWindow(double window)
1507 vtkLookupTable* LUT = static_cast<vtkLookupTable*>(this->GetWindowLevel()->GetLookupTable());
1509 double level = this->GetWindowLevel()->GetLevel();
1510 LUT->SetTableRange(level-fabs(window)/2,level+fabs(window)/2);
1513 this->vtkImageViewer2::SetColorWindow(window);
1515 //----------------------------------------------------------------------------
1517 //----------------------------------------------------------------------------
1518 void vvSlicer::SetColorLevel(double level)
1520 vtkLookupTable* LUT = static_cast<vtkLookupTable*>(this->GetWindowLevel()->GetLookupTable());
1522 double window = this->GetWindowLevel()->GetWindow();
1523 LUT->SetTableRange(level-fabs(window)/2,level+fabs(window)/2);
1526 this->vtkImageViewer2::SetColorLevel(level);
1528 //----------------------------------------------------------------------------
1530 //----------------------------------------------------------------------------
1531 double vvSlicer::GetOverlayColorWindow()
1534 return mOverlayMapper->GetWindow();
1538 //----------------------------------------------------------------------------
1540 //----------------------------------------------------------------------------
1541 double vvSlicer::GetOverlayColorLevel()
1544 return mOverlayMapper->GetLevel();
1548 //----------------------------------------------------------------------------
1550 //----------------------------------------------------------------------------
1551 void vvSlicer::SetOverlayColorWindow(double window)
1554 mOverlayMapper->SetWindow(window);
1556 //----------------------------------------------------------------------------
1558 //----------------------------------------------------------------------------
1559 void vvSlicer::SetOverlayColorLevel(double level)
1562 mOverlayMapper->SetLevel(level);
1564 //----------------------------------------------------------------------------
1566 //----------------------------------------------------------------------------
1567 // Returns the min an the max value in a 20%x20% region around the mouse pointer
1568 void vvSlicer::GetExtremasAroundMousePointer(double & min, double & max, vtkImageData *image, vtkTransform *transform)
1570 //Get mouse pointer position in view coordinates
1573 for(int i=0; i<3; i++) {
1574 corner1[i] = mCurrent[i];
1575 corner2[i] = mCurrent[i];
1578 this->Renderer->WorldToView(corner1[0], corner1[1], corner1[2]);
1579 this->Renderer->WorldToView(corner2[0], corner2[1], corner2[2]);
1581 // In view coordinates, x is the slicer width and y is the slicer height are the in-plane axis
1583 this->Renderer->GetTiledSize(&w, &h);
1584 corner1[0] -= 0.2*h/(double)w;
1585 corner2[0] += 0.2*h/(double)w;
1588 this->Renderer->ViewToWorld(corner1[0], corner1[1], corner1[2]);
1589 this->Renderer->ViewToWorld(corner2[0], corner2[1], corner2[2]);
1591 //Convert to image pixel coordinates (rounded)
1592 transform->TransformPoint(corner1, corner1);
1593 transform->TransformPoint(corner2, corner2);
1594 int iLocalExtents[6];
1595 for(int i=0; i<3; i++) {
1596 corner1[i] = (corner1[i] - image->GetOrigin()[i])/image->GetSpacing()[i];
1597 corner2[i] = (corner2[i] - image->GetOrigin()[i])/image->GetSpacing()[i];
1599 iLocalExtents[i*2 ] = lrint(corner1[i]);
1600 iLocalExtents[i*2+1] = lrint(corner2[i]);
1602 if(iLocalExtents[i*2 ]>iLocalExtents[i*2+1])
1603 std::swap(iLocalExtents[i*2], iLocalExtents[i*2+1]);
1605 #if VTK_MAJOR_VERSION > 5
1606 for(int j=0;j<2; j++) {
1607 if(iLocalExtents[i*2+j]< mImageReslice->GetInputInformation()->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT())[2*i])
1608 iLocalExtents[i*2+j] = mImageReslice->GetInputInformation()->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT())[2*i];
1610 if(iLocalExtents[i*2+j]> mImageReslice->GetInputInformation()->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT())[2*i+1])
1611 iLocalExtents[i*2+j] = mImageReslice->GetInputInformation()->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT())[2*i+1];
1616 vtkSmartPointer<vtkExtractVOI> voiFilter = vtkSmartPointer<vtkExtractVOI>::New();
1617 #if VTK_MAJOR_VERSION <= 5
1618 voiFilter->SetInput(image);
1620 voiFilter->SetInputData(image);
1622 voiFilter->SetVOI(iLocalExtents);
1623 voiFilter->Update();
1624 if (!voiFilter->GetOutput()->GetNumberOfPoints()) {
1630 vtkSmartPointer<vtkImageAccumulate> accFilter = vtkSmartPointer<vtkImageAccumulate>::New();
1631 #if VTK_MAJOR_VERSION <= 5
1632 accFilter->SetInput(voiFilter->GetOutput());
1634 accFilter->SetInputConnection(voiFilter->GetOutputPort(0));
1636 accFilter->Update();
1638 min = *(accFilter->GetMin());
1639 max = *(accFilter->GetMax());
1641 //----------------------------------------------------------------------------
1643 //----------------------------------------------------------------------------
1644 double vvSlicer::GetScalarComponentAsDouble(vtkImageData *image, double X, double Y, double Z, int &ix, int &iy, int &iz, int component)
1649 #if VTK_MAJOR_VERSION <= 5
1650 if (ix < image->GetWholeExtent()[0] ||
1651 ix > image->GetWholeExtent()[1] ||
1652 iy < image->GetWholeExtent()[2] ||
1653 iy > image->GetWholeExtent()[3] ||
1654 iz < image->GetWholeExtent()[4] ||
1655 iz > image->GetWholeExtent()[5] )
1656 return std::numeric_limits<double>::quiet_NaN();
1657 image->SetUpdateExtent(ix, ix, iy, iy, iz, iz);
1660 if (ix < image->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[0] ||
1661 ix > image->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[1] ||
1662 iy < image->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[2] ||
1663 iy > image->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[3] ||
1664 iz < image->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[4] ||
1665 iz > image->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[5] )
1666 return std::numeric_limits<double>::quiet_NaN();
1667 //image->SetUpdateExtent(ix, ix, iy, iy, iz, iz);
1670 return image->GetScalarComponentAsDouble(ix, iy, iz, component);
1672 //----------------------------------------------------------------------------
1674 //----------------------------------------------------------------------------
1675 void vvSlicer::Render()
1677 if (this->mFusion && mFusionActor->GetVisibility() && showFusionLegend) {
1678 legend->SetLookupTable(this->GetFusionMapper()->GetLookupTable());
1679 legend->UseOpacityOn();
1680 legend->SetVisibility(1);
1682 else if (this->GetWindowLevel()->GetLookupTable() && !this->mOverlay) {
1683 legend->SetLookupTable(this->GetWindowLevel()->GetLookupTable());
1684 legend->UseOpacityOff();
1685 legend->SetVisibility(1);
1686 } else legend->SetVisibility(0);
1688 if (ca->GetVisibility()) {
1689 std::stringstream worldPos(" ");
1691 mConcatenatedTransform->TransformPoint(mCurrent, pt);
1692 double X = (pt[0] - mImage->GetVTKImages()[mCurrentTSlice]->GetOrigin()[0])/mImage->GetVTKImages()[mCurrentTSlice]->GetSpacing()[0];
1693 double Y = (pt[1] - mImage->GetVTKImages()[mCurrentTSlice]->GetOrigin()[1])/mImage->GetVTKImages()[mCurrentTSlice]->GetSpacing()[1];
1694 double Z = (pt[2] - mImage->GetVTKImages()[mCurrentTSlice]->GetOrigin()[2])/mImage->GetVTKImages()[mCurrentTSlice]->GetSpacing()[2];
1695 #if VTK_MAJOR_VERSION <= 5
1696 if (X >= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[0]-0.5 &&
1697 X <= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[1]+0.5 &&
1698 Y >= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[2]-0.5 &&
1699 Y <= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[3]+0.5 &&
1700 Z >= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[4]-0.5 &&
1701 Z <= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[5]+0.5) {
1703 if (X >= mImage->GetVTKImages()[mCurrentTSlice]->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[0]-0.5 &&
1704 X <= mImage->GetVTKImages()[mCurrentTSlice]->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[1]+0.5 &&
1705 Y >= mImage->GetVTKImages()[mCurrentTSlice]->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[2]-0.5 &&
1706 Y <= mImage->GetVTKImages()[mCurrentTSlice]->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[3]+0.5 &&
1707 Z >= mImage->GetVTKImages()[mCurrentTSlice]->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[4]-0.5 &&
1708 Z <= mImage->GetVTKImages()[mCurrentTSlice]->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[5]+0.5) {
1711 double value = this->GetScalarComponentAsDouble(mImage->GetVTKImages()[mCurrentTSlice], X, Y, Z, ix, iy, iz);
1712 if(ImageActor->GetVisibility())
1713 worldPos << "data value : " << value << std::endl;
1714 worldPos << "mm : " << lrint(mCurrent[0]) << ' '
1715 << lrint(mCurrent[1]) << ' '
1716 << lrint(mCurrent[2]) << ' '
1719 worldPos << "pixel : " << ix << ' '
1726 ca->SetText(1,worldPos.str().c_str());
1728 std::stringstream slicePos;
1729 slicePos << "Slice: " << this->GetSlice();
1730 ca->SetText(2, slicePos.str().c_str());
1733 if (pdmA->GetVisibility()) {
1734 double x = mCursor[0];
1735 double y = mCursor[1];
1736 double z = mCursor[2];
1737 double xCursor = (x - this->GetInput()->GetOrigin()[0])/this->GetInput()->GetSpacing()[0];
1738 double yCursor = (y - this->GetInput()->GetOrigin()[1])/this->GetInput()->GetSpacing()[1];
1739 double zCursor = (z - this->GetInput()->GetOrigin()[2])/this->GetInput()->GetSpacing()[2];
1740 #if VTK_MAJOR_VERSION <= 5
1741 if (xCursor >= this->GetImageActor()->GetDisplayExtent()[0]-0.5 &&
1742 xCursor < this->GetImageActor()->GetDisplayExtent()[1]+0.5 &&
1743 yCursor >= this->GetImageActor()->GetDisplayExtent()[2]-0.5 &&
1744 yCursor < this->GetImageActor()->GetDisplayExtent()[3]+0.5 &&
1745 zCursor >= this->GetImageActor()->GetDisplayExtent()[4]-0.5 &&
1746 zCursor < this->GetImageActor()->GetDisplayExtent()[5]+0.5 ) {
1747 vtkRenderer * renderer = this->Renderer;
1749 renderer->WorldToView(x,y,z);
1750 renderer->ViewToNormalizedViewport(x,y,z);
1751 renderer->NormalizedViewportToViewport(x,y);
1752 renderer->ViewportToNormalizedDisplay(x,y);
1753 renderer->NormalizedDisplayToDisplay(x,y);
1754 crossCursor->SetFocalPoint(x,y,z);
1756 crossCursor->SetFocalPoint(-1,-1,z);
1757 crossCursor->Update();
1760 vtkSmartPointer<vtkOpenGLImageSliceMapper> mapperOpenGL= vtkSmartPointer<vtkOpenGLImageSliceMapper>::New();
1762 mapperOpenGL = dynamic_cast<vtkOpenGLImageSliceMapper*>(GetImageActor()->GetMapper());
1763 } catch (const std::bad_cast& e) {
1764 std::cerr << e.what() << std::endl;
1765 std::cerr << "Conversion error" << std::endl;
1769 if (xCursor >= mapperOpenGL->GetCroppingRegion()[0]-0.5 &&
1770 xCursor < mapperOpenGL->GetCroppingRegion()[1]+0.5 &&
1771 yCursor >= mapperOpenGL->GetCroppingRegion()[2]-0.5 &&
1772 yCursor < mapperOpenGL->GetCroppingRegion()[3]+0.5 &&
1773 zCursor >= mapperOpenGL->GetCroppingRegion()[4]-0.5 &&
1774 zCursor < mapperOpenGL->GetCroppingRegion()[5]+0.5 ) {
1775 vtkRenderer * renderer = this->Renderer;
1777 renderer->WorldToView(x,y,z);
1778 renderer->ViewToNormalizedViewport(x,y,z);
1779 renderer->NormalizedViewportToViewport(x,y);
1780 renderer->ViewportToNormalizedDisplay(x,y);
1781 renderer->NormalizedDisplayToDisplay(x,y);
1782 crossCursor->SetFocalPoint(x,y,z);
1784 crossCursor->SetFocalPoint(-1,-1,z);
1785 crossCursor->Update();
1789 if (mOverlay && mOverlayActor->GetVisibility()) {
1790 if(mLinkOverlayWindowLevel) {
1791 mOverlayMapper->SetWindow(this->GetColorWindow());
1792 mOverlayMapper->SetLevel(this->GetColorLevel());
1794 #if VTK_MAJOR_VERSION <= 5
1795 mOverlayMapper->GetOutput()->SetUpdateExtent(mOverlayActor->GetDisplayExtent());
1796 #elif VTK_MAJOR_VERSION >= 7 && VTK_MINOR_VERSION >= 1
1797 mOverlayMapper->UpdateExtent(mOverlayActor->GetDisplayExtent());
1799 mOverlayMapper->SetUpdateExtent(mOverlayActor->GetDisplayExtent());
1801 mOverlayMapper->Update();
1803 if (mFusion && mFusionActor->GetVisibility()) {
1804 #if VTK_MAJOR_VERSION <= 5
1805 mFusionMapper->GetOutput()->SetUpdateExtent(mFusionActor->GetDisplayExtent());
1806 #elif VTK_MAJOR_VERSION >= 7 && VTK_MINOR_VERSION >= 1
1807 mFusionMapper->UpdateExtent(mFusionActor->GetDisplayExtent());
1809 mFusionMapper->SetUpdateExtent(mFusionActor->GetDisplayExtent());
1811 mFusionMapper->Update();
1818 this->GetRenderWindow()->Render();
1820 //----------------------------------------------------------------------------
1823 //----------------------------------------------------------------------------
1824 void vvSlicer::UpdateCursorPosition()
1826 pdmA->SetVisibility(true);
1827 mCursor[0] = mCurrent[0];
1828 mCursor[1] = mCurrent[1];
1829 mCursor[2] = mCurrent[2];
1830 mCursor[3] = mCurrentTSlice;
1832 //----------------------------------------------------------------------------
1835 //----------------------------------------------------------------------------
1836 void vvSlicer::RemoveLandmarks()
1838 vtkPolyData *pd = static_cast<vtkPolyData*>(mLandmarks->GetOutput());
1839 if (pd->GetPoints()) {
1841 //First remove all captions:
1842 for(unsigned int i=0;i<mLandLabelActors.size();i++) {
1843 this->Renderer->RemoveActor2D(mLandLabelActors[i]);
1844 //allActors2D->Remove (mLandLabelActors[i]);
1846 mLandLabelActors.clear();
1849 //----------------------------------------------------------------------------
1852 //----------------------------------------------------------------------------
1853 void vvSlicer::DisplayLandmarks()
1857 for(unsigned int i=0; i<6; i++)
1858 bounds[i] = ImageActor->GetBounds()[i];
1859 bounds[ this->SliceOrientation*2 ] = ImageActor->GetBounds()[ this->SliceOrientation*2 ]-fabs(this->GetInput()->GetSpacing()[this->SliceOrientation]);
1860 bounds[ this->SliceOrientation*2+1 ] = ImageActor->GetBounds()[ this->SliceOrientation*2+1 ]+fabs(this->GetInput()->GetSpacing()[this->SliceOrientation]);
1861 mClipBox->SetBounds(bounds);
1864 vtkPolyData *pd = static_cast<vtkPolyData*>(mLandmarks->GetOutput());
1865 if (pd->GetPoints()) {
1866 this->GetRenderer()->AddActor(mLandActor);
1867 //mLandGlyph->SetRange(0,1);
1868 //mLandGlyph->Modified();
1869 //mLandGlyph->Update();
1870 mClipBox->Modified();
1871 mLandClipper->Update();
1872 mLandMapper->Update();
1873 //Next add the captions to the displayed points
1874 for (vtkIdType id=0; id<mLandClipper->GetOutput()->GetNumberOfPoints(); id++) {
1875 double *position = mLandClipper->GetOutput()->GetPoint(id);
1876 vtkStdString label = static_cast<vtkStringArray*>(mLandClipper->GetOutput()->GetPointData()->GetAbstractArray("labels"))->GetValue(id);
1877 vtkSmartPointer<vtkCaptionActor2D> label_actor = vtkSmartPointer<vtkCaptionActor2D>::New();
1878 label_actor->SetCaption(label);
1879 label_actor->SetAttachmentPoint(position);
1880 label_actor->GetCaptionTextProperty()->SetColor(1,0,0);
1881 label_actor->GetCaptionTextProperty()->SetOrientation(33.333333);
1882 label_actor->GetCaptionTextProperty()->SetFontFamilyToTimes();
1883 label_actor->GetCaptionTextProperty()->SetBold(0);
1884 label_actor->GetCaptionTextProperty()->SetFontSize(6);
1885 label_actor->BorderOff();
1886 label_actor->LeaderOff();
1887 label_actor->ThreeDimensionalLeaderOff();
1888 mLandLabelActors.push_back(label_actor);
1889 this->Renderer->AddActor2D(mLandLabelActors[id]);
1894 //----------------------------------------------------------------------------
1897 //----------------------------------------------------------------------------
1898 void vvSlicer::SetSlice(int slice)
1900 int *range = this->GetSliceRange();
1902 if (slice < range[0]) {
1904 } else if (slice > range[1]) {
1909 if (this->Slice == slice) {
1913 this->Slice = slice;
1916 this->UpdateDisplayExtent();
1918 // Seems to work without this line
1921 //----------------------------------------------------------------------------
1923 //----------------------------------------------------------------------------
1924 int vvSlicer::GetTMax()
1926 int tmax = (int)mImage->GetVTKImages().size() - 1;
1928 tmax = std::max(tmax, (int)mOverlay->GetVTKImages().size()-1);
1931 //----------------------------------------------------------------------------
1933 //----------------------------------------------------------------------------
1934 void vvSlicer::SetContourSlice()
1936 if (mSurfaceCutActors.size() > 0)
1937 for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
1938 i!=mSurfaceCutActors.end(); i++) {
1940 (*i)->SetSlicingOrientation(this->SliceOrientation);
1941 (*i)->SetCutSlice((this->Slice)*this->GetImage()->GetSpacing()[this->SliceOrientation]+
1942 this->GetImage()->GetOrigin()[this->SliceOrientation]);
1945 //----------------------------------------------------------------------------
1948 //----------------------------------------------------------------------------
1949 void vvSlicer::ForceUpdateDisplayExtent()
1951 this->UpdateDisplayExtent();
1953 //----------------------------------------------------------------------------
1956 //----------------------------------------------------------------------------
1957 int* vvSlicer::GetDisplayExtent()
1959 return this->GetImageActor()->GetDisplayExtent();
1961 //----------------------------------------------------------------------------
1964 //----------------------------------------------------------------------------
1965 void vvSlicer::PrintSelf(ostream& os, vtkIndent indent)
1967 this->Superclass::PrintSelf(os, indent);
1969 //----------------------------------------------------------------------------
1972 //----------------------------------------------------------------------------
1973 void vvSlicer::SetVFColor(double r, double g, double b)
1975 double mVFColorHSV[3];
1980 vtkMath::RGBToHSV(mVFColor, mVFColorHSV);
1981 mVFColorLUT->SetHueRange(mVFColorHSV[0], mVFColorHSV[0]);
1982 mVFColorLUT->SetSaturationRange(mVFColorHSV[1],mVFColorHSV[1]);
1983 mVFColorLUT->SetValueRange(mVFColorHSV[2], mVFColorHSV[2]);
1987 //----------------------------------------------------------------------------
1990 //----------------------------------------------------------------------------
1991 void vvSlicer::SetRegisterExtent(int ext[6])
1993 copyExtent(ext, mRegisterExtent);
1995 //----------------------------------------------------------------------------
1998 //----------------------------------------------------------------------------
1999 void vvSlicer::GetRegisterExtent(int ext[6])
2001 copyExtent(mRegisterExtent, ext);
2003 //----------------------------------------------------------------------------