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->SetResliceAxes(mConcatenatedTransform->GetMatrix());
363 #if VTK_MAJOR_VERSION <= 5
364 mImageReslice->SetInput(0, mImage->GetFirstVTKImageData());
366 mImageReslice->SetInputData(0, mImage->GetFirstVTKImageData());
368 mImageReslice->UpdateInformation();
370 #if VTK_MAJOR_VERSION <= 5
371 this->Superclass::SetInput(mImageReslice->GetOutput());
373 this->Superclass::SetInputConnection(mImageReslice->GetOutputPort());
377 #if VTK_MAJOR_VERSION <= 5
378 this->GetInput()->GetWholeExtent(extent);
380 mImageReslice->GetOutput()->GetExtent(extent);
383 // Prevent crash when reload -> change slice if outside extent
384 if (Slice < extent[SliceOrientation*2] || Slice>=extent[SliceOrientation*2+1]) {
385 Slice = (extent[SliceOrientation*2+1]+extent[SliceOrientation*2])/2.0;
388 // Make sure that the required part image has been computed
389 extent[SliceOrientation*2] = Slice;
390 extent[SliceOrientation*2+1] = Slice;
391 #if VTK_MAJOR_VERSION <= 5
392 mImageReslice->GetOutput()->SetUpdateExtent(extent);
393 mImageReslice->GetOutput()->Update();
394 #elif VTK_MAJOR_VERSION >= 8 || (VTK_MAJOR_VERSION == 7 && VTK_MINOR_VERSION >= 1)
395 mImageReslice->UpdateExtent(extent);
396 mImageReslice->Update();
398 mImageReslice->SetUpdateExtent(extent);
399 mImageReslice->Update();
402 this->UpdateDisplayExtent();
405 ca->SetText(0,mFileName.c_str());
408 //------------------------------------------------------------------------------
411 //------------------------------------------------------------------------------
412 void vvSlicer::SetOverlay(vvImage::Pointer overlay)
414 if (overlay->GetVTKImages().size()) {
416 mOverlayVisibility = true;
418 if (!mOverlayReslice) {
419 mOverlayReslice = vtkSmartPointer<vtkImageReslice>::New();
420 mOverlayReslice->SetInterpolationModeToLinear();
421 mOverlayReslice->AutoCropOutputOn();
422 mOverlayReslice->SetBackgroundColor(-1000,-1000,-1000,1);
425 mConcatenatedOverlayTransform->Identity();
426 mConcatenatedOverlayTransform->Concatenate(mOverlay->GetTransform()[0]);
427 mConcatenatedOverlayTransform->Concatenate(mSlicingTransform);
428 mOverlayReslice->SetResliceAxes(mConcatenatedOverlayTransform->GetMatrix());
429 #if VTK_MAJOR_VERSION <= 5
430 mOverlayReslice->SetInput(0, mOverlay->GetFirstVTKImageData());
431 mImageReslice->UpdateInformation();
433 mOverlayReslice->SetInputData(0, mOverlay->GetFirstVTKImageData());
435 mOverlayReslice->Update();
438 mOverlayMapper = vtkSmartPointer<vtkImageMapToWindowLevelColors>::New();
439 #if VTK_MAJOR_VERSION <= 5
440 mOverlayMapper->SetInput(mOverlayReslice->GetOutput());
442 mOverlayMapper->SetInputConnection(mOverlayReslice->GetOutputPort(0));
445 if (!mOverlayActor) {
446 mOverlayActor = vtkSmartPointer<vvBlendImageActor>::New();
447 #if VTK_MAJOR_VERSION <= 5
448 mOverlayActor->SetInput(mOverlayMapper->GetOutput());
450 mOverlayActor->GetMapper()->SetInputConnection(mOverlayMapper->GetOutputPort());
452 mOverlayActor->SetPickable(0);
453 mOverlayActor->SetVisibility(true);
454 mOverlayActor->SetOpacity(0.5);
455 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
456 mOverlayActor->GetMapper()->BorderOn();
460 //stupid but necessary : the Overlay need to be rendered before fusion
462 this->GetRenderer()->RemoveActor(mFusionActor);
463 this->GetRenderer()->AddActor(mOverlayActor);
464 this->GetRenderer()->AddActor(mFusionActor);
466 this->GetRenderer()->AddActor(mOverlayActor);
468 //Synchronize orientation and slice
469 AdjustResliceToSliceOrientation(mOverlayReslice);
470 this->UpdateDisplayExtent();
471 this->SetTSlice(mCurrentTSlice);
474 //------------------------------------------------------------------------------
477 //------------------------------------------------------------------------------
478 void vvSlicer::SetFusion(vvImage::Pointer fusion, int fusionSequenceCode)
480 mFusionSequenceCode = fusionSequenceCode;
481 if (fusion->GetVTKImages().size()) {
483 mFusionVisibility = true;
485 if (!mFusionReslice) {
486 mFusionReslice = vtkSmartPointer<vtkImageReslice>::New();
487 mFusionReslice->SetInterpolationModeToLinear();
488 mFusionReslice->AutoCropOutputOn();
489 mFusionReslice->SetBackgroundColor(-1000,-1000,-1000,1);
492 mConcatenatedFusionTransform->Identity();
493 mConcatenatedFusionTransform->Concatenate(mFusion->GetTransform()[0]);
494 mConcatenatedFusionTransform->Concatenate(mSlicingTransform);
495 mFusionReslice->SetResliceAxes(mConcatenatedFusionTransform->GetMatrix());
496 #if VTK_MAJOR_VERSION <= 5
497 mFusionReslice->SetInput(0, mFusion->GetFirstVTKImageData());
498 mFusionReslice->UpdateInformation();
500 mFusionReslice->SetInputData(0, mFusion->GetFirstVTKImageData());
502 mFusionReslice->Update();
505 mFusionMapper = vtkSmartPointer<vtkImageMapToColors>::New();
507 vtkSmartPointer<vtkLookupTable> lut = vtkLookupTable::New();
509 lut->SetValueRange(0, 1);
510 lut->SetSaturationRange(0, 0);
512 mFusionMapper->SetLookupTable(lut);
513 #if VTK_MAJOR_VERSION <= 5
514 mFusionMapper->SetInput(mFusionReslice->GetOutput());
516 mFusionMapper->SetInputConnection(mFusionReslice->GetOutputPort(0));
520 mFusionActor = vtkSmartPointer<vtkImageActor>::New();
521 #if VTK_MAJOR_VERSION <= 5
522 mFusionActor->SetInput(mFusionMapper->GetOutput());
524 mFusionActor->GetMapper()->SetInputConnection(mFusionMapper->GetOutputPort());
526 mFusionActor->SetPickable(0);
527 mFusionActor->SetVisibility(true);
528 mFusionActor->SetOpacity(0.7);
529 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
530 mFusionActor->GetMapper()->BorderOn();
533 this->GetRenderer()->AddActor(mFusionActor);
536 //Synchronize orientation and slice
537 AdjustResliceToSliceOrientation(mFusionReslice);
538 this->UpdateDisplayExtent();
539 this->SetTSlice(mCurrentTSlice);
542 //------------------------------------------------------------------------------
545 //------------------------------------------------------------------------------
546 bool vvSlicer::GetActorVisibility(const std::string& actor_type, int overlay_index)
549 if (actor_type == "image")
550 vis = mImageVisibility;
551 else if (actor_type == "vector")
553 else if (actor_type == "overlay")
554 vis = mOverlayVisibility;
555 else if ( (actor_type == "fusion") || (actor_type == "fusionSequence") )
556 vis = mFusionVisibility;
557 else if (actor_type == "contour")
558 vis = this->mSurfaceCutActors[overlay_index]->GetActor()->GetVisibility();
561 //------------------------------------------------------------------------------
563 //------------------------------------------------------------------------------
564 void vvSlicer::SetActorVisibility(const std::string& actor_type, int overlay_index ,bool vis)
566 if (actor_type == "image")
567 mImageVisibility = vis;
568 else if (actor_type == "vector")
570 else if (actor_type == "overlay")
571 mOverlayVisibility = vis;
572 else if ( (actor_type == "fusion") || (actor_type == "fusionSequence") )
573 mFusionVisibility = vis;
574 else if (actor_type == "contour")
575 this->mSurfaceCutActors[overlay_index]->GetActor()->SetVisibility(vis);
576 UpdateDisplayExtent();
578 //------------------------------------------------------------------------------
580 //------------------------------------------------------------------------------
581 void vvSlicer::SetVF(vvImage::Pointer vf)
583 if (vf->GetVTKImages().size()) {
585 mVFVisibility = true;
588 mVFReslice = vtkSmartPointer<vtkImageReslice>::New();
589 mVFReslice->SetInterpolationModeToLinear();
590 mVFReslice->AutoCropOutputOn();
591 mVFReslice->SetBackgroundColor(-1000,-1000,-1000,1);
592 mAAFilter= vtkSmartPointer<vtkAssignAttribute>::New();
593 mVOIFilter = vtkSmartPointer<vtkExtractVOI>::New();
594 mVOIFilter->SetSampleRate(mSubSampling,mSubSampling,mSubSampling);
597 mConcatenatedVFTransform->Identity();
598 mConcatenatedVFTransform->Concatenate(mVF->GetTransform()[0]);
599 mConcatenatedVFTransform->Concatenate(mSlicingTransform);
600 mVFReslice->SetResliceAxes(mConcatenatedVFTransform->GetMatrix());
601 #if VTK_MAJOR_VERSION <= 5
602 mVFReslice->SetInput(0, mVF->GetFirstVTKImageData());
604 mVFReslice->SetInputData(0, mVF->GetFirstVTKImageData());
606 mVFReslice->Update();
608 #if VTK_MAJOR_VERSION <= 5
609 mVOIFilter->SetInput(mVFReslice->GetOutput());
610 mAAFilter->SetInput(mVOIFilter->GetOutput());
612 mVOIFilter->SetInputConnection(mVFReslice->GetOutputPort());
613 mAAFilter->SetInputConnection(mVOIFilter->GetOutputPort());
615 ///This tells VTK to use the scalar (pixel) data of the image to draw the little arrows
616 mAAFilter->Assign(vtkDataSetAttributes::SCALARS, vtkDataSetAttributes::VECTORS, vtkAssignAttribute::POINT_DATA);
619 mArrow = vtkSmartPointer<vvGlyphSource>::New();
620 mArrow->SetGlyphTypeToSpecificArrow();
621 mArrow->SetScale(mScale);
624 // Glyph the gradient vector (with arrows)
626 mGlyphFilter = vtkSmartPointer<vvGlyph2D>::New();
627 #if VTK_MAJOR_VERSION <= 5
628 mGlyphFilter->SetInput(mAAFilter->GetOutput());
629 mGlyphFilter->SetSource(mArrow->GetOutput());
631 mGlyphFilter->SetInputConnection(mAAFilter->GetOutputPort());
632 mGlyphFilter->SetSourceConnection(mArrow->GetOutputPort());
634 mGlyphFilter->ScalingOn();
635 mGlyphFilter->SetScaleModeToScaleByVector();
636 mGlyphFilter->OrientOn();
637 mGlyphFilter->SetVectorModeToUseVector();
638 mGlyphFilter->SetColorModeToColorByVector();
641 mVFColorLUT = vtkSmartPointer<vtkLookupTable>::New();
643 double mVFColorHSV[3];
644 vtkMath::RGBToHSV(mVFColor, mVFColorHSV);
645 mVFColorLUT->SetHueRange(mVFColorHSV[0], mVFColorHSV[0]);
646 mVFColorLUT->SetSaturationRange(mVFColorHSV[1],mVFColorHSV[1]);
647 mVFColorLUT->SetValueRange(mVFColorHSV[2], mVFColorHSV[2]);
650 mVFMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
651 #if VTK_MAJOR_VERSION <= 5
652 mVFMapper->SetInput(mGlyphFilter->GetOutput());
654 mVFMapper->SetInputConnection(mGlyphFilter->GetOutputPort());
656 mVFMapper->ImmediateModeRenderingOn();
657 mVFMapper->SetLookupTable(mVFColorLUT);
660 mVFActor = vtkSmartPointer<vtkActor>::New();
661 mVFActor->SetMapper(mVFMapper);
662 mVFActor->SetPickable(0);
663 mVFActor->GetProperty()->SetLineWidth(mVFWidth);
664 this->UpdateDisplayExtent();
665 this->GetRenderer()->AddActor(mVFActor);
668 SetTSlice(mCurrentTSlice);
671 //------------------------------------------------------------------------------
674 //------------------------------------------------------------------------------
675 void vvSlicer::SetLandmarks(vvLandmarks* landmarks)
677 mLandmarks = landmarks;
681 mCross = vtkSmartPointer<vtkCursor3D>::New();
683 mClipBox = vtkSmartPointer<vtkBox>::New();
685 mLandClipper = vtkSmartPointer<vvClipPolyData>::New();
687 mLandGlyph = vtkSmartPointer<vtkGlyph3D>::New();
689 mLandMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
691 mLandActor = vtkSmartPointer<vtkActor>::New();
693 mCross->SetFocalPoint(0.0,0.0,0.0);
694 mCross->SetModelBounds(-10,10,-10,10,-10,10);
698 mLandClipper->SetClipFunction(mClipBox);
699 mLandClipper->InsideOutOn();
700 #if VTK_MAJOR_VERSION <= 5
701 mLandmarkTransform = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
702 mLandmarkTransform->SetInput(mLandmarks->GetOutput());
703 mConcatenatedTransform->Identity();
704 mConcatenatedTransform->Concatenate(mImage->GetTransform()[0]);
705 mConcatenatedTransform->Concatenate(mSlicingTransform);
706 mLandmarkTransform->SetTransform(mConcatenatedTransform->GetInverse());
707 mLandClipper->SetInput(mLandmarkTransform->GetOutput());
709 mLandGlyph->SetSource(mCross->GetOutput());
710 mLandGlyph->SetInput(mLandClipper->GetOutput());
712 mLandmarkTransform = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
713 mLandmarkTransform->SetInputData(mLandmarks->GetOutput());
714 mConcatenatedTransform->Identity();
715 mConcatenatedTransform->Concatenate(mImage->GetTransform()[0]);
716 mConcatenatedTransform->Concatenate(mSlicingTransform);
717 mLandmarkTransform->SetTransform(mConcatenatedTransform->GetInverse());
718 mLandClipper->SetInputConnection(mLandmarkTransform->GetOutputPort());
720 mLandGlyph->SetSourceConnection(mCross->GetOutputPort());
721 mLandGlyph->SetInputConnection(mLandClipper->GetOutputPort());
723 //mLandGlyph->SetIndexModeToScalar();
724 //mLandGlyph->SetRange(0,1);
725 //mLandGlyph->ScalingOff();
727 //mLandGlyph->SetColorModeToColorByScalar();
729 mLandGlyph->SetScaleModeToDataScalingOff();
730 mLandGlyph->SetIndexModeToOff();
732 mLandMapper->SetInputConnection(mLandGlyph->GetOutputPort());
733 //mLandMapper->ScalarVisibilityOff();
735 mLandActor->SetMapper(mLandMapper);
736 mLandActor->GetProperty()->SetOpacity(0.995); //in order to get VTK to turn on the alpha-blending in OpenGL
737 mLandActor->GetProperty()->SetColor(255,10,212);
738 mLandActor->SetPickable(0);
739 mLandActor->SetVisibility(true);
740 this->UpdateDisplayExtent();
743 //------------------------------------------------------------------------------
745 //------------------------------------------------------------------------------
746 //FIXME: this function leaks memory, we should fix it someday :)
747 void vvSlicer::RemoveActor(const std::string& actor_type, int overlay_index)
749 if (actor_type == "vector") {
750 Renderer->RemoveActor(mVFActor);
759 if (actor_type == "overlay") {
760 Renderer->RemoveActor(mOverlayActor);
762 mOverlayActor = NULL;
763 mOverlayMapper = NULL;
765 if ( (actor_type == "fusion") || (actor_type == "fusionSequence") ) {
766 Renderer->RemoveActor(mFusionActor);
769 mFusionMapper = NULL;
771 if (actor_type == "contour") {
772 Renderer->RemoveActor(this->mSurfaceCutActors[overlay_index]->GetActor());
773 mSurfaceCutActors.erase(mSurfaceCutActors.begin()+overlay_index);
776 //------------------------------------------------------------------------------
779 //------------------------------------------------------------------------------
780 void vvSlicer::SetVFSubSampling(int sub)
783 mVOIFilter->SetSampleRate(mSubSampling,mSubSampling,mSubSampling);
786 UpdateDisplayExtent();
789 //------------------------------------------------------------------------------
792 //------------------------------------------------------------------------------
793 void vvSlicer::SetVFScale(int scale)
797 mArrow->SetScale(mScale);
798 UpdateDisplayExtent();
801 //------------------------------------------------------------------------------
803 //------------------------------------------------------------------------------
804 void vvSlicer::SetVFWidth(int width)
808 mVFActor->GetProperty()->SetLineWidth(mVFWidth);
809 UpdateDisplayExtent();
812 //------------------------------------------------------------------------------
815 //------------------------------------------------------------------------------
816 void vvSlicer::SetVFLog(int log)
820 mGlyphFilter->SetUseLog(mVFLog);
821 mGlyphFilter->Modified();
823 UpdateDisplayExtent();
826 //------------------------------------------------------------------------------
829 //------------------------------------------------------------------------------
830 void vvSlicer::SetTSlice(int t, bool updateLinkedImages)
832 if (!updateLinkedImages) {
834 #if VTK_MAJOR_VERSION <= 5
835 mImageReslice->SetInput( mImage->GetVTKImages()[mCurrentTSlice] );
837 mImageReslice->SetInputData( mImage->GetVTKImages()[mCurrentTSlice] );
840 mConcatenatedTransform->Identity();
841 mConcatenatedTransform->Concatenate(mImage->GetTransform()[mCurrentTSlice]);
842 mConcatenatedTransform->Concatenate(mSlicingTransform);
843 UpdateDisplayExtent();
848 else if ((unsigned int)t >= mImage->GetVTKImages().size())
849 mCurrentTSlice = mImage->GetVTKImages().size() -1;
854 mConcatenatedTransform->Identity();
855 mConcatenatedTransform->Concatenate(mImage->GetTransform()[mCurrentTSlice]);
856 mConcatenatedTransform->Concatenate(mSlicingTransform);
859 #if VTK_MAJOR_VERSION <= 5
860 mImageReslice->SetInput( mImage->GetVTKImages()[mCurrentTSlice] );
862 mImageReslice->SetInputData( mImage->GetVTKImages()[mCurrentTSlice] );
864 if (mVF && mVFActor->GetVisibility()) {
865 if (mVF->GetVTKImages().size() > (unsigned int)mCurrentTSlice)
866 #if VTK_MAJOR_VERSION <= 5
867 mVFReslice->SetInput(mVF->GetVTKImages()[mCurrentTSlice]);
869 mVFReslice->SetInputData(mVF->GetVTKImages()[mCurrentTSlice]);
871 // Update overlay transform
872 mConcatenatedVFTransform->Identity();
873 mConcatenatedVFTransform->Concatenate(mVF->GetTransform()[mCurrentTSlice]);
874 mConcatenatedVFTransform->Concatenate(mSlicingTransform);
877 if (mOverlay && mOverlayActor->GetVisibility()) {
878 if (mOverlay->GetVTKImages().size() > (unsigned int)t) {
879 mCurrentOverlayTSlice = t;
880 #if VTK_MAJOR_VERSION <= 5
881 mOverlayReslice->SetInput( mOverlay->GetVTKImages()[mCurrentOverlayTSlice] );
883 mOverlayReslice->SetInputData( mOverlay->GetVTKImages()[mCurrentOverlayTSlice] );
885 // Update overlay transform
886 mConcatenatedOverlayTransform->Identity();
887 mConcatenatedOverlayTransform->Concatenate(mOverlay->GetTransform()[mCurrentOverlayTSlice]);
888 mConcatenatedOverlayTransform->Concatenate(mSlicingTransform);
891 //update the fusion ; except in case this is a fusionSequence, in which case both 'times' should be independent.
892 if (mFusion && mFusionActor->GetVisibility() && (mFusionSequenceCode<0)) {
893 if (mFusion->GetVTKImages().size() > (unsigned int)t) {
894 mCurrentFusionTSlice = t;
895 #if VTK_MAJOR_VERSION <= 5
896 mFusionReslice->SetInput( mFusion->GetVTKImages()[mCurrentFusionTSlice]);
898 mFusionReslice->SetInputData( mFusion->GetVTKImages()[mCurrentFusionTSlice]);
901 // Update fusion transform
902 mConcatenatedFusionTransform->Identity();
903 mConcatenatedFusionTransform->Concatenate(mFusion->GetTransform()[mCurrentFusionTSlice]);
904 mConcatenatedFusionTransform->Concatenate(mSlicingTransform);
907 if (mSurfaceCutActors.size() > 0)
908 for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
909 i!=mSurfaceCutActors.end(); i++)
910 (*i)->SetTimeSlice(mCurrentTSlice);
911 UpdateDisplayExtent();
913 //------------------------------------------------------------------------------
916 //------------------------------------------------------------------------------
917 void vvSlicer::SetFusionSequenceTSlice(int t)
919 if (mFusion && mFusionActor->GetVisibility() && (mFusionSequenceCode>=0)) {
920 if (mFusion->GetVTKImages().size() > (unsigned int)t) {
921 mCurrentFusionTSlice = t;
922 #if VTK_MAJOR_VERSION <= 5
923 mFusionReslice->SetInput( mFusion->GetVTKImages()[mCurrentFusionTSlice] );
925 mFusionReslice->SetInputData( mFusion->GetVTKImages()[mCurrentFusionTSlice] );
927 // Update fusion transform
928 mConcatenatedFusionTransform->Identity();
929 mConcatenatedFusionTransform->Concatenate(mFusion->GetTransform()[mCurrentFusionTSlice]); //not really useful...
930 mConcatenatedFusionTransform->Concatenate(mSlicingTransform);
934 UpdateDisplayExtent();
936 //------------------------------------------------------------------------------
939 //------------------------------------------------------------------------------
940 int vvSlicer::GetTSlice()
942 return mCurrentTSlice;
944 //------------------------------------------------------------------------------
946 //------------------------------------------------------------------------------
947 int vvSlicer::GetMaxCurrentTSlice()
949 int t = mCurrentTSlice;
950 if(mOverlay && mOverlayActor->GetVisibility())
951 t = std::max(t, mCurrentOverlayTSlice);
952 if(mFusion&& (mFusionSequenceCode<0) && mFusionActor->GetVisibility()) //ignore fusionSequence data: for these, the times are not to be related (this way)
953 t = std::max(t, mCurrentFusionTSlice);
956 //------------------------------------------------------------------------------
958 //------------------------------------------------------------------------------
959 int vvSlicer::GetFusionTSlice()
961 return mCurrentFusionTSlice;
963 //------------------------------------------------------------------------------
965 //------------------------------------------------------------------------------
966 int vvSlicer::GetOverlayTSlice()
968 return mCurrentOverlayTSlice;
970 //------------------------------------------------------------------------------
972 //------------------------------------------------------------------------------
973 void vvSlicer::SetSliceOrientation(int orientation)
975 //if 2D image, force to watch in Axial View
977 #if VTK_MAJOR_VERSION <= 5
978 this->GetInput()->GetWholeExtent(extent);
980 int* ext = mImageReslice->GetInputInformation()->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT());
981 copyExtent(ext, extent);
984 if (extent[5]-extent[4] <= 2)
985 orientation = vtkImageViewer2::SLICE_ORIENTATION_XY;
987 if (orientation < vtkImageViewer2::SLICE_ORIENTATION_YZ ||
988 orientation > vtkImageViewer2::SLICE_ORIENTATION_XY) {
989 vtkErrorMacro("Error - invalid slice orientation " << orientation);
993 this->SliceOrientation = orientation;
996 AdjustResliceToSliceOrientation(mFusionReslice);
999 AdjustResliceToSliceOrientation(mOverlayReslice);
1002 AdjustResliceToSliceOrientation(mVFReslice);
1004 // Update the viewer
1006 // Go to current cursor position
1007 // double* cursorPos = GetCursorPosition();
1008 // DDV(cursorPos, 3);
1009 // SetCurrentPosition(cursorPos[0],cursorPos[1],cursorPos[2],cursorPos[3]);
1011 if (mFirstSetSliceOrientation) {
1012 int *range = this->GetSliceRange();
1014 this->Slice = static_cast<int>((range[0] + range[1]) * 0.5);
1015 #if VTK_MAJOR_VERSION <= 5
1016 mFirstSetSliceOrientation = false;
1019 else if (this->Renderer && this->GetInput()) {
1020 double s = mCursor[orientation];
1021 double sCursor = (s - this->GetInput()->GetOrigin()[orientation])/this->GetInput()->GetSpacing()[orientation];
1022 this->Slice = static_cast<int>(sCursor);
1025 this->UpdateOrientation();
1027 this->UpdateDisplayExtent();
1029 if (mFirstSetSliceOrientation) {
1030 mFirstSetSliceOrientation = false;
1033 if (this->Renderer && this->GetInput()) {
1034 double scale = this->Renderer->GetActiveCamera()->GetParallelScale();
1035 this->Renderer->ResetCamera();
1036 this->Renderer->GetActiveCamera()->SetParallelScale(scale);
1041 //----------------------------------------------------------------------------
1043 //------------------------------------------------------------------------------
1044 // This function ensures that we sample the slices of a vtkImageReslice filter
1045 // in the direction of the slicer (SliceOrientation) similarly as mImageReslice.
1046 // In other words, we change the grid of the reslice in the same way as the grid
1047 // of the displayed image in the slicing direction.
1048 void vvSlicer::AdjustResliceToSliceOrientation(vtkImageReslice *reslice)
1050 // Reset autocrop and update output information
1051 reslice->SetOutputOriginToDefault();
1052 reslice->SetOutputSpacingToDefault();
1053 #if VTK_MAJOR_VERSION <= 5
1054 reslice->GetOutput()->UpdateInformation();
1056 reslice->UpdateInformation();
1059 // Ge new origin / spacing
1062 reslice->GetOutput()->GetOrigin(origin);
1063 reslice->GetOutput()->GetSpacing(spacing);
1065 // Use similar spacing as the image in the direction SliceOrientation
1066 spacing[this->SliceOrientation] = mImageReslice->GetOutput()->GetSpacing()[this->SliceOrientation];
1068 // Modify origin to be on the image grid in the direction SliceOrientation in 3 steps
1069 // Step 1: from world coordinates to image coordinates
1070 origin[this->SliceOrientation] -= mImageReslice->GetOutput()->GetOrigin()[this->SliceOrientation];
1071 origin[this->SliceOrientation] /= mImageReslice->GetOutput()->GetSpacing()[this->SliceOrientation];
1073 // Step 2: round to nearest grid positionInc. This has been validated as the only
1074 // way to have something consistent with the thickness of a 2D slice visible on the
1075 // other slices. The thickness is accounted for so if the 2D slice is to thin and
1076 // between two slices, one will never be able to see this 2D slice (bug #1883).
1077 origin[this->SliceOrientation] = itk::Math::Round<double>(origin[this->SliceOrientation]);
1079 // Step 3: back to world coordinates
1080 origin[this->SliceOrientation] *= mImageReslice->GetOutput()->GetSpacing()[this->SliceOrientation];
1081 origin[this->SliceOrientation] += mImageReslice->GetOutput()->GetOrigin()[this->SliceOrientation];
1083 // Set new spacing and origin
1084 reslice->SetOutputOrigin(origin);
1085 reslice->SetOutputSpacing(spacing);
1086 reslice->UpdateInformation();
1087 #if VTK_MAJOR_VERSION <= 5
1088 reslice->GetOutput()->UpdateInformation();
1091 //------------------------------------------------------------------------------
1093 //----------------------------------------------------------------------------
1094 int * vvSlicer::GetExtent()
1097 if (mUseReducedExtent) {
1098 w_ext = mReducedExtent;
1101 #if VTK_MAJOR_VERSION <= 5
1102 w_ext = GetInput()->GetWholeExtent();
1104 w_ext = mImageReslice->GetInputInformation()->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT());
1109 //----------------------------------------------------------------------------
1112 //----------------------------------------------------------------------------
1113 int vvSlicer::GetOrientation()
1115 return this->SliceOrientation;
1117 //----------------------------------------------------------------------------
1120 //----------------------------------------------------------------------------
1121 void vvSlicer::UpdateDisplayExtent()
1123 emit UpdateDisplayExtentBegin(mSlicerNumber);
1124 vtkImageData *input = this->GetInput();
1125 if (!input || !this->ImageActor) {
1129 #if VTK_MAJOR_VERSION <= 5
1130 input->UpdateInformation();
1132 mRegisterExtent = mImageReslice->GetOutputInformation(0)->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT());
1134 this->SetSlice( this->GetSlice() ); //SR: make sure the update let the slice in extents
1136 // Local copy of extent
1138 #if VTK_MAJOR_VERSION <= 5
1139 int* ext = GetExtent();
1141 int* ext = mImageReslice->GetOutputInformation(0)->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT());
1143 copyExtent(ext, w_ext);
1144 if (mUseReducedExtent) {
1145 copyExtent(mReducedExtent, w_ext);
1149 w_ext[ this->SliceOrientation*2 ] = this->Slice;
1150 w_ext[ this->SliceOrientation*2+1 ] = this->Slice;
1153 this->ImageActor->SetVisibility(mImageVisibility);
1154 this->ImageActor->SetDisplayExtent(w_ext);
1156 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
1157 // Fix for bug #1882
1158 dynamic_cast<vtkImageSliceMapper *>(this->ImageActor->GetMapper())->SetOrientation(this->GetOrientation());
1161 // Overlay image actor
1162 if (mOverlay && mOverlayVisibility) {
1163 AdjustResliceToSliceOrientation(mOverlayReslice);
1165 #if VTK_MAJOR_VERSION <= 5
1166 this->ConvertImageToImageDisplayExtent(input, w_ext, mOverlayReslice->GetOutput(), overExtent);
1167 bool out = ClipDisplayedExtent(overExtent, mOverlayMapper->GetInput()->GetWholeExtent());
1169 this->ConvertImageToImageDisplayExtent(mImageReslice->GetOutputInformation(0), w_ext, mOverlayReslice->GetOutput(), overExtent);
1170 bool out = ClipDisplayedExtent(overExtent, mOverlayMapper->GetInputInformation()->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT()));
1172 mOverlayActor->SetVisibility(!out);
1173 mOverlayActor->SetDisplayExtent( overExtent );
1174 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
1175 // Fix for bug #1882
1176 dynamic_cast<vtkImageSliceMapper *>(mOverlayActor->GetMapper())->SetOrientation(this->GetOrientation());
1180 mOverlayActor->SetVisibility(false);
1182 // Fusion image actor
1183 if (mFusion && mFusionVisibility) {
1184 AdjustResliceToSliceOrientation(mFusionReslice);
1186 #if VTK_MAJOR_VERSION <= 5
1187 this->ConvertImageToImageDisplayExtent(input, w_ext, mFusionReslice->GetOutput(), fusExtent);
1188 bool out = ClipDisplayedExtent(fusExtent, mFusionMapper->GetInput()->GetWholeExtent());
1190 this->ConvertImageToImageDisplayExtent(mImageReslice->GetOutputInformation(0), w_ext, mFusionReslice->GetOutput(), fusExtent);
1191 bool out = ClipDisplayedExtent(fusExtent, mFusionMapper->GetInputInformation()->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT()));
1193 mFusionActor->SetVisibility(!out);
1194 mFusionActor->SetDisplayExtent( fusExtent );
1195 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
1196 // Fix for bug #1882
1197 dynamic_cast<vtkImageSliceMapper *>(mFusionActor->GetMapper())->SetOrientation(this->GetOrientation());
1201 mFusionActor->SetVisibility(false);
1202 // Vector field actor
1203 double* camera = Renderer->GetActiveCamera()->GetPosition();
1204 double* image_bounds = ImageActor->GetBounds();
1205 double position[3] = {0, 0, 0};
1206 position[this->SliceOrientation] = image_bounds[this->SliceOrientation*2];
1208 //print_vector<double, 6>("camera", camera);
1209 //print_vector<double, 6>("image_bounds", image_bounds);
1210 //print_vector<double, 3>("position", position);
1212 // find where to place the VF actor. to deal with
1213 // z-buffer issues, the VF is placed right in front of the image,
1214 // subject to a small offset. the position actually depends on the
1215 // the location of the camera relative to the image.
1217 if (camera[this->SliceOrientation] < image_bounds[this->SliceOrientation*2])
1220 if (mVF && mVFVisibility) {
1221 AdjustResliceToSliceOrientation(mVFReslice);
1223 #if VTK_MAJOR_VERSION <= 5
1224 mVF->GetVTKImages()[0]->UpdateInformation();
1225 this->ConvertImageToImageDisplayExtent(input, w_ext, mVFReslice->GetOutput(), vfExtent);
1226 bool out = ClipDisplayedExtent(vfExtent, mVOIFilter->GetInput()->GetWholeExtent());
1228 mVOIFilter->Update();
1229 this->ConvertImageToImageDisplayExtent(mImageReslice->GetOutputInformation(0), w_ext, mVFReslice->GetOutput(), vfExtent);
1230 bool out = ClipDisplayedExtent(vfExtent, mVOIFilter->GetInputInformation()->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT()));
1232 mVFActor->SetVisibility(!out);
1233 mVOIFilter->SetVOI(vfExtent);
1234 int orientation[3] = {1,1,1};
1235 orientation[this->SliceOrientation] = 0;
1236 mGlyphFilter->SetOrientation(orientation[0], orientation[1], orientation[2]);
1237 position[this->SliceOrientation] += offset;
1238 mVFActor->SetPosition(position);
1239 mVFActor->GetProperty()->SetOpacity(0.995); //in order to get VTK to turn on the alpha-blending in OpenGL
1240 mVFMapper->Update();
1244 mVFActor->SetVisibility(false);
1248 for(unsigned int i=0; i<6; i++)
1249 boundsT[i] = ImageActor->GetBounds()[i];
1250 boundsT[ this->SliceOrientation*2 ] = ImageActor->GetBounds()[ this->SliceOrientation*2 ]-fabs(this->GetInput()->GetSpacing()[this->SliceOrientation]);
1251 boundsT[ this->SliceOrientation*2+1 ] = ImageActor->GetBounds()[ this->SliceOrientation*2+1 ]+fabs(this->GetInput()->GetSpacing()[this->SliceOrientation]);
1260 position[this->SliceOrientation] = offset;
1261 mLandActor->SetPosition(position);
1264 // Figure out the correct clipping range
1265 if (this->Renderer) {
1266 if (this->InteractorStyle &&
1267 this->InteractorStyle->GetAutoAdjustCameraClippingRange()) {
1268 this->Renderer->ResetCameraClippingRange();
1270 vtkCamera *cam = this->Renderer->GetActiveCamera();
1273 this->ImageActor->GetBounds(bounds);
1274 double spos = (double)bounds[this->SliceOrientation * 2];
1275 double cpos = (double)cam->GetPosition()[this->SliceOrientation];
1276 double range = fabs(spos - cpos);
1277 double *spacing = input->GetSpacing();
1278 double sumSpacing = spacing[0] + spacing[1] + spacing[2];
1279 cam->SetClippingRange(range - sumSpacing, range + sumSpacing);
1289 emit UpdateDisplayExtentEnd(mSlicerNumber);
1291 //----------------------------------------------------------------------------
1293 //----------------------------------------------------------------------------
1294 void vvSlicer::ConvertImageToImageDisplayExtent(vtkInformation *sourceImage, const int sourceExtent[6],
1295 vtkImageData *targetImage, int targetExtent[6])
1298 double *origin, *spacing;
1299 origin = sourceImage->Get(vtkDataObject::ORIGIN());
1300 spacing = sourceImage->Get(vtkDataObject::SPACING());
1301 for(unsigned int i=0; i<6; i++) {
1302 // From source voxel coordinates to world coordinates
1303 dExtents[i] = origin[i/2] + spacing[i/2] * sourceExtent[i];
1305 // From world coordinates to floating point target voxel coordinates
1306 dExtents[i] = (dExtents[i]- targetImage->GetOrigin()[i/2]) / targetImage->GetSpacing()[i/2];
1308 // Round to current slice or larger extent
1309 if(i/2==this->GetOrientation())
1310 targetExtent[i] = itk::Math::Round<double>(dExtents[i]);
1312 targetExtent[i] = itk::Math::Ceil<double>(dExtents[i]);
1314 targetExtent[i] = itk::Math::Floor<double>(dExtents[i]);
1317 //----------------------------------------------------------------------------
1319 //----------------------------------------------------------------------------
1320 void vvSlicer::ConvertImageToImageDisplayExtent(vtkImageData *sourceImage, const int sourceExtent[6],
1321 vtkImageData *targetImage, int targetExtent[6])
1324 for(unsigned int i=0; i<6; i++) {
1325 // From source voxel coordinates to world coordinates
1326 dExtents[i] = sourceImage->GetOrigin()[i/2] + sourceImage->GetSpacing()[i/2] * sourceExtent[i];
1328 // From world coordinates to floating point target voxel coordinates
1329 dExtents[i] = (dExtents[i]- targetImage->GetOrigin()[i/2]) / targetImage->GetSpacing()[i/2];
1331 // Round to current slice or larger extent
1332 if(i/2==this->GetOrientation())
1333 targetExtent[i] = itk::Math::Round<double>(dExtents[i]);
1335 targetExtent[i] = itk::Math::Ceil<double>(dExtents[i]);
1337 targetExtent[i] = itk::Math::Floor<double>(dExtents[i]);
1340 //----------------------------------------------------------------------------
1342 //----------------------------------------------------------------------------
1343 bool vvSlicer::ClipDisplayedExtent(int extent[6], int refExtent[6])
1348 for (int i = 0; i < maxBound; i = i+2) {
1349 //if we are totally outside the image
1350 if ( extent[i] > refExtent[i+1] || extent[i+1] < refExtent[i] ) {
1354 //crop to the limit of the image
1355 extent[i] = std::max(extent[i], refExtent[i]);
1356 extent[i] = std::min(extent[i], refExtent[i+1]);;
1357 extent[i+1] = std::max(extent[i+1], refExtent[i]);
1358 extent[i+1] = std::min(extent[i+1], refExtent[i+1]);;
1361 for (int i = 0; i < maxBound; i = i+2) {
1362 extent[i] = refExtent[i];
1363 extent[i+1] = refExtent[i];
1367 //----------------------------------------------------------------------------
1370 //----------------------------------------------------------------------------
1371 void vvSlicer::UpdateOrientation()
1373 // Set the camera position
1374 vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
1376 switch (this->SliceOrientation) {
1377 case vtkImageViewer2::SLICE_ORIENTATION_XY:
1378 cam->SetFocalPoint(0,0,0);
1379 cam->SetPosition(0,0,-1); // -1 if medical ?
1380 cam->SetViewUp(0,-1,0);
1383 case vtkImageViewer2::SLICE_ORIENTATION_XZ:
1384 cam->SetFocalPoint(0,0,0);
1385 cam->SetPosition(0,-1,0); // 1 if medical ?
1386 cam->SetViewUp(0,0,1);
1389 case vtkImageViewer2::SLICE_ORIENTATION_YZ:
1390 cam->SetFocalPoint(0,0,0);
1391 cam->SetPosition(-1,0,0); // -1 if medical ?
1392 cam->SetViewUp(0,0,1);
1397 //----------------------------------------------------------------------------
1400 //----------------------------------------------------------------------------
1401 void vvSlicer::SetOpacity(double s)
1403 this->GetImageActor()->SetOpacity(s);
1405 //----------------------------------------------------------------------------
1408 //----------------------------------------------------------------------------
1409 void vvSlicer::SetRenderWindow(int orientation, vtkRenderWindow * rw)
1411 this->Superclass::SetRenderWindow(rw);
1412 this->SetupInteractor(rw->GetInteractor());
1413 ca->SetImageActor(this->GetImageActor());
1414 ca->SetWindowLevel(this->GetWindowLevel());
1415 ca->SetText(3, "<window>\n<level>");
1426 crossCursor->SetModelBounds(bounds);
1428 this->GetRenderer()->AddActor(pdmA);
1429 this->GetRenderer()->AddActor(ca);
1430 this->GetRenderer()->ResetCamera();
1432 //this is just a mapping between the labeling of the orientations presented to the user and
1433 //the one used by vtk
1434 SetSliceOrientation(2-(orientation%3));
1437 //----------------------------------------------------------------------------
1440 //----------------------------------------------------------------------------
1441 void vvSlicer::ResetCamera()
1443 this->GetRenderer()->ResetCamera();
1445 //----------------------------------------------------------------------------
1448 //----------------------------------------------------------------------------
1449 void vvSlicer::SetDisplayMode(bool i)
1451 this->GetRenderer()->SetDraw(i);
1452 if (i) UpdateDisplayExtent();
1454 //----------------------------------------------------------------------------
1457 //----------------------------------------------------------------------------
1458 void vvSlicer::FlipHorizontalView()
1460 vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
1462 double *position = cam->GetPosition();
1463 double factor[3] = {1, 1, 1};
1464 factor[this->SliceOrientation] = -1;
1465 cam->SetPosition(factor[0]*position[0],factor[1]*position[1],factor[2]*position[2]);
1467 /* switch (this->SliceOrientation) {
1468 case vtkImageViewer2::SLICE_ORIENTATION_XY:
1469 cam->SetPosition(position[0],position[1],-position[2]);
1472 case vtkImageViewer2::SLICE_ORIENTATION_XZ:
1473 cam->SetPosition(position[0],-position[1],position[2]);
1476 case vtkImageViewer2::SLICE_ORIENTATION_YZ:
1477 cam->SetPosition(-position[0],position[1],position[2]);
1481 this->Renderer->ResetCameraClippingRange();
1482 this->UpdateDisplayExtent();
1485 //----------------------------------------------------------------------------
1488 //----------------------------------------------------------------------------
1489 void vvSlicer::FlipVerticalView()
1491 vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
1493 FlipHorizontalView();
1494 double *viewup = cam->GetViewUp();
1495 cam->SetViewUp(-viewup[0],-viewup[1],-viewup[2]);
1496 this->UpdateDisplayExtent();
1499 //----------------------------------------------------------------------------
1502 //----------------------------------------------------------------------------
1503 void vvSlicer::SetColorWindow(double window)
1505 vtkLookupTable* LUT = static_cast<vtkLookupTable*>(this->GetWindowLevel()->GetLookupTable());
1507 double level = this->GetWindowLevel()->GetLevel();
1508 LUT->SetTableRange(level-fabs(window)/2,level+fabs(window)/2);
1511 this->vtkImageViewer2::SetColorWindow(window);
1513 //----------------------------------------------------------------------------
1515 //----------------------------------------------------------------------------
1516 void vvSlicer::SetColorLevel(double level)
1518 vtkLookupTable* LUT = static_cast<vtkLookupTable*>(this->GetWindowLevel()->GetLookupTable());
1520 double window = this->GetWindowLevel()->GetWindow();
1521 LUT->SetTableRange(level-fabs(window)/2,level+fabs(window)/2);
1524 this->vtkImageViewer2::SetColorLevel(level);
1526 //----------------------------------------------------------------------------
1528 //----------------------------------------------------------------------------
1529 double vvSlicer::GetOverlayColorWindow()
1532 return mOverlayMapper->GetWindow();
1536 //----------------------------------------------------------------------------
1538 //----------------------------------------------------------------------------
1539 double vvSlicer::GetOverlayColorLevel()
1542 return mOverlayMapper->GetLevel();
1546 //----------------------------------------------------------------------------
1548 //----------------------------------------------------------------------------
1549 void vvSlicer::SetOverlayColorWindow(double window)
1552 mOverlayMapper->SetWindow(window);
1554 //----------------------------------------------------------------------------
1556 //----------------------------------------------------------------------------
1557 void vvSlicer::SetOverlayColorLevel(double level)
1560 mOverlayMapper->SetLevel(level);
1562 //----------------------------------------------------------------------------
1564 //----------------------------------------------------------------------------
1565 // Returns the min an the max value in a 20%x20% region around the mouse pointer
1566 void vvSlicer::GetExtremasAroundMousePointer(double & min, double & max, vtkImageData *image, vtkTransform *transform)
1568 //Get mouse pointer position in view coordinates
1571 for(int i=0; i<3; i++) {
1572 corner1[i] = mCurrent[i];
1573 corner2[i] = mCurrent[i];
1576 this->Renderer->WorldToView(corner1[0], corner1[1], corner1[2]);
1577 this->Renderer->WorldToView(corner2[0], corner2[1], corner2[2]);
1579 // In view coordinates, x is the slicer width and y is the slicer height are the in-plane axis
1581 this->Renderer->GetTiledSize(&w, &h);
1582 corner1[0] -= 0.2*h/(double)w;
1583 corner2[0] += 0.2*h/(double)w;
1586 this->Renderer->ViewToWorld(corner1[0], corner1[1], corner1[2]);
1587 this->Renderer->ViewToWorld(corner2[0], corner2[1], corner2[2]);
1589 //Convert to image pixel coordinates (rounded)
1590 transform->TransformPoint(corner1, corner1);
1591 transform->TransformPoint(corner2, corner2);
1592 int iLocalExtents[6];
1593 for(int i=0; i<3; i++) {
1594 corner1[i] = (corner1[i] - image->GetOrigin()[i])/image->GetSpacing()[i];
1595 corner2[i] = (corner2[i] - image->GetOrigin()[i])/image->GetSpacing()[i];
1597 iLocalExtents[i*2 ] = lrint(corner1[i]);
1598 iLocalExtents[i*2+1] = lrint(corner2[i]);
1600 if(iLocalExtents[i*2 ]>iLocalExtents[i*2+1])
1601 std::swap(iLocalExtents[i*2], iLocalExtents[i*2+1]);
1603 #if VTK_MAJOR_VERSION > 5
1604 for(int j=0;j<2; j++) {
1605 if(iLocalExtents[i*2+j]< mImageReslice->GetInputInformation()->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT())[2*i])
1606 iLocalExtents[i*2+j] = mImageReslice->GetInputInformation()->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT())[2*i];
1608 if(iLocalExtents[i*2+j]> mImageReslice->GetInputInformation()->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT())[2*i+1])
1609 iLocalExtents[i*2+j] = mImageReslice->GetInputInformation()->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT())[2*i+1];
1614 vtkSmartPointer<vtkExtractVOI> voiFilter = vtkSmartPointer<vtkExtractVOI>::New();
1615 #if VTK_MAJOR_VERSION <= 5
1616 voiFilter->SetInput(image);
1618 voiFilter->SetInputData(image);
1620 voiFilter->SetVOI(iLocalExtents);
1621 voiFilter->Update();
1622 if (!voiFilter->GetOutput()->GetNumberOfPoints()) {
1628 vtkSmartPointer<vtkImageAccumulate> accFilter = vtkSmartPointer<vtkImageAccumulate>::New();
1629 #if VTK_MAJOR_VERSION <= 5
1630 accFilter->SetInput(voiFilter->GetOutput());
1632 accFilter->SetInputConnection(voiFilter->GetOutputPort(0));
1634 accFilter->Update();
1636 min = *(accFilter->GetMin());
1637 max = *(accFilter->GetMax());
1639 //----------------------------------------------------------------------------
1641 //----------------------------------------------------------------------------
1642 double vvSlicer::GetScalarComponentAsDouble(vtkImageData *image, double X, double Y, double Z, int &ix, int &iy, int &iz, int component)
1647 #if VTK_MAJOR_VERSION <= 5
1648 if (ix < image->GetWholeExtent()[0] ||
1649 ix > image->GetWholeExtent()[1] ||
1650 iy < image->GetWholeExtent()[2] ||
1651 iy > image->GetWholeExtent()[3] ||
1652 iz < image->GetWholeExtent()[4] ||
1653 iz > image->GetWholeExtent()[5] )
1654 return std::numeric_limits<double>::quiet_NaN();
1655 image->SetUpdateExtent(ix, ix, iy, iy, iz, iz);
1658 if (ix < image->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[0] ||
1659 ix > image->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[1] ||
1660 iy < image->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[2] ||
1661 iy > image->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[3] ||
1662 iz < image->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[4] ||
1663 iz > image->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[5] )
1664 return std::numeric_limits<double>::quiet_NaN();
1665 //image->SetUpdateExtent(ix, ix, iy, iy, iz, iz);
1668 return image->GetScalarComponentAsDouble(ix, iy, iz, component);
1670 //----------------------------------------------------------------------------
1672 //----------------------------------------------------------------------------
1673 void vvSlicer::Render()
1675 if (this->mFusion && mFusionActor->GetVisibility() && showFusionLegend) {
1676 legend->SetLookupTable(this->GetFusionMapper()->GetLookupTable());
1677 legend->UseOpacityOn();
1678 legend->SetVisibility(1);
1680 else if (this->GetWindowLevel()->GetLookupTable() && !this->mOverlay) {
1681 legend->SetLookupTable(this->GetWindowLevel()->GetLookupTable());
1682 legend->UseOpacityOff();
1683 legend->SetVisibility(1);
1684 } else legend->SetVisibility(0);
1686 if (ca->GetVisibility()) {
1687 std::stringstream worldPos(" ");
1689 mConcatenatedTransform->TransformPoint(mCurrent, pt);
1690 double X = (pt[0] - mImage->GetVTKImages()[mCurrentTSlice]->GetOrigin()[0])/mImage->GetVTKImages()[mCurrentTSlice]->GetSpacing()[0];
1691 double Y = (pt[1] - mImage->GetVTKImages()[mCurrentTSlice]->GetOrigin()[1])/mImage->GetVTKImages()[mCurrentTSlice]->GetSpacing()[1];
1692 double Z = (pt[2] - mImage->GetVTKImages()[mCurrentTSlice]->GetOrigin()[2])/mImage->GetVTKImages()[mCurrentTSlice]->GetSpacing()[2];
1693 #if VTK_MAJOR_VERSION <= 5
1694 if (X >= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[0]-0.5 &&
1695 X <= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[1]+0.5 &&
1696 Y >= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[2]-0.5 &&
1697 Y <= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[3]+0.5 &&
1698 Z >= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[4]-0.5 &&
1699 Z <= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[5]+0.5) {
1701 if (X >= mImage->GetVTKImages()[mCurrentTSlice]->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[0]-0.5 &&
1702 X <= mImage->GetVTKImages()[mCurrentTSlice]->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[1]+0.5 &&
1703 Y >= mImage->GetVTKImages()[mCurrentTSlice]->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[2]-0.5 &&
1704 Y <= mImage->GetVTKImages()[mCurrentTSlice]->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[3]+0.5 &&
1705 Z >= mImage->GetVTKImages()[mCurrentTSlice]->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[4]-0.5 &&
1706 Z <= mImage->GetVTKImages()[mCurrentTSlice]->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[5]+0.5) {
1709 double value = this->GetScalarComponentAsDouble(mImage->GetVTKImages()[mCurrentTSlice], X, Y, Z, ix, iy, iz);
1710 if(ImageActor->GetVisibility())
1711 worldPos << "data value : " << value << std::endl;
1712 worldPos << "mm : " << lrint(mCurrent[0]) << ' '
1713 << lrint(mCurrent[1]) << ' '
1714 << lrint(mCurrent[2]) << ' '
1717 worldPos << "pixel : " << ix << ' '
1724 ca->SetText(1,worldPos.str().c_str());
1726 std::stringstream slicePos;
1727 slicePos << "Slice: " << this->GetSlice();
1728 ca->SetText(2, slicePos.str().c_str());
1731 if (pdmA->GetVisibility()) {
1732 double x = mCursor[0];
1733 double y = mCursor[1];
1734 double z = mCursor[2];
1735 double xCursor = (x - this->GetInput()->GetOrigin()[0])/this->GetInput()->GetSpacing()[0];
1736 double yCursor = (y - this->GetInput()->GetOrigin()[1])/this->GetInput()->GetSpacing()[1];
1737 double zCursor = (z - this->GetInput()->GetOrigin()[2])/this->GetInput()->GetSpacing()[2];
1738 #if VTK_MAJOR_VERSION <= 5
1739 if (xCursor >= this->GetImageActor()->GetDisplayExtent()[0]-0.5 &&
1740 xCursor < this->GetImageActor()->GetDisplayExtent()[1]+0.5 &&
1741 yCursor >= this->GetImageActor()->GetDisplayExtent()[2]-0.5 &&
1742 yCursor < this->GetImageActor()->GetDisplayExtent()[3]+0.5 &&
1743 zCursor >= this->GetImageActor()->GetDisplayExtent()[4]-0.5 &&
1744 zCursor < this->GetImageActor()->GetDisplayExtent()[5]+0.5 ) {
1745 vtkRenderer * renderer = this->Renderer;
1747 renderer->WorldToView(x,y,z);
1748 renderer->ViewToNormalizedViewport(x,y,z);
1749 renderer->NormalizedViewportToViewport(x,y);
1750 renderer->ViewportToNormalizedDisplay(x,y);
1751 renderer->NormalizedDisplayToDisplay(x,y);
1752 crossCursor->SetFocalPoint(x,y,z);
1754 crossCursor->SetFocalPoint(-1,-1,z);
1755 crossCursor->Update();
1758 vtkSmartPointer<vtkOpenGLImageSliceMapper> mapperOpenGL= vtkSmartPointer<vtkOpenGLImageSliceMapper>::New();
1760 mapperOpenGL = dynamic_cast<vtkOpenGLImageSliceMapper*>(GetImageActor()->GetMapper());
1761 } catch (const std::bad_cast& e) {
1762 std::cerr << e.what() << std::endl;
1763 std::cerr << "Conversion error" << std::endl;
1767 if (xCursor >= mapperOpenGL->GetCroppingRegion()[0]-0.5 &&
1768 xCursor < mapperOpenGL->GetCroppingRegion()[1]+0.5 &&
1769 yCursor >= mapperOpenGL->GetCroppingRegion()[2]-0.5 &&
1770 yCursor < mapperOpenGL->GetCroppingRegion()[3]+0.5 &&
1771 zCursor >= mapperOpenGL->GetCroppingRegion()[4]-0.5 &&
1772 zCursor < mapperOpenGL->GetCroppingRegion()[5]+0.5 ) {
1773 vtkRenderer * renderer = this->Renderer;
1775 renderer->WorldToView(x,y,z);
1776 renderer->ViewToNormalizedViewport(x,y,z);
1777 renderer->NormalizedViewportToViewport(x,y);
1778 renderer->ViewportToNormalizedDisplay(x,y);
1779 renderer->NormalizedDisplayToDisplay(x,y);
1780 crossCursor->SetFocalPoint(x,y,z);
1782 crossCursor->SetFocalPoint(-1,-1,z);
1783 crossCursor->Update();
1787 if (mOverlay && mOverlayActor->GetVisibility()) {
1788 if(mLinkOverlayWindowLevel) {
1789 mOverlayMapper->SetWindow(this->GetColorWindow());
1790 mOverlayMapper->SetLevel(this->GetColorLevel());
1792 #if VTK_MAJOR_VERSION <= 5
1793 mOverlayMapper->GetOutput()->SetUpdateExtent(mOverlayActor->GetDisplayExtent());
1794 #elif VTK_MAJOR_VERSION >= 8 || (VTK_MAJOR_VERSION == 7 && VTK_MINOR_VERSION >= 1)
1795 mOverlayMapper->UpdateExtent(mOverlayActor->GetDisplayExtent());
1797 mOverlayMapper->SetUpdateExtent(mOverlayActor->GetDisplayExtent());
1799 mOverlayMapper->Update();
1801 if (mFusion && mFusionActor->GetVisibility()) {
1802 #if VTK_MAJOR_VERSION <= 5
1803 mFusionMapper->GetOutput()->SetUpdateExtent(mFusionActor->GetDisplayExtent());
1804 #elif VTK_MAJOR_VERSION >= 8 || (VTK_MAJOR_VERSION == 7 && VTK_MINOR_VERSION >= 1)
1805 mFusionMapper->UpdateExtent(mFusionActor->GetDisplayExtent());
1807 mFusionMapper->SetUpdateExtent(mFusionActor->GetDisplayExtent());
1809 mFusionMapper->Update();
1816 this->GetRenderWindow()->Render();
1818 //----------------------------------------------------------------------------
1821 //----------------------------------------------------------------------------
1822 void vvSlicer::UpdateCursorPosition()
1824 pdmA->SetVisibility(true);
1825 mCursor[0] = mCurrent[0];
1826 mCursor[1] = mCurrent[1];
1827 mCursor[2] = mCurrent[2];
1828 mCursor[3] = mCurrentTSlice;
1830 //----------------------------------------------------------------------------
1833 //----------------------------------------------------------------------------
1834 void vvSlicer::RemoveLandmarks()
1836 vtkPolyData *pd = static_cast<vtkPolyData*>(mLandmarks->GetOutput());
1837 if (pd->GetPoints()) {
1839 //First remove all captions:
1840 for(unsigned int i=0;i<mLandLabelActors.size();i++) {
1841 this->Renderer->RemoveActor2D(mLandLabelActors[i]);
1842 //allActors2D->Remove (mLandLabelActors[i]);
1844 mLandLabelActors.clear();
1847 //----------------------------------------------------------------------------
1850 //----------------------------------------------------------------------------
1851 void vvSlicer::DisplayLandmarks()
1855 for(unsigned int i=0; i<6; i++)
1856 bounds[i] = ImageActor->GetBounds()[i];
1857 bounds[ this->SliceOrientation*2 ] = ImageActor->GetBounds()[ this->SliceOrientation*2 ]-fabs(this->GetInput()->GetSpacing()[this->SliceOrientation]);
1858 bounds[ this->SliceOrientation*2+1 ] = ImageActor->GetBounds()[ this->SliceOrientation*2+1 ]+fabs(this->GetInput()->GetSpacing()[this->SliceOrientation]);
1859 mClipBox->SetBounds(bounds);
1862 vtkPolyData *pd = static_cast<vtkPolyData*>(mLandmarks->GetOutput());
1863 if (pd->GetPoints()) {
1864 this->GetRenderer()->AddActor(mLandActor);
1865 //mLandGlyph->SetRange(0,1);
1866 //mLandGlyph->Modified();
1867 //mLandGlyph->Update();
1868 mClipBox->Modified();
1869 mLandClipper->Update();
1870 mLandMapper->Update();
1871 //Next add the captions to the displayed points
1872 for (vtkIdType id=0; id<mLandClipper->GetOutput()->GetNumberOfPoints(); id++) {
1873 double *position = mLandClipper->GetOutput()->GetPoint(id);
1874 vtkStdString label = static_cast<vtkStringArray*>(mLandClipper->GetOutput()->GetPointData()->GetAbstractArray("labels"))->GetValue(id);
1875 vtkSmartPointer<vtkCaptionActor2D> label_actor = vtkSmartPointer<vtkCaptionActor2D>::New();
1876 label_actor->SetCaption(label);
1877 label_actor->SetAttachmentPoint(position);
1878 label_actor->GetCaptionTextProperty()->SetColor(1,0,0);
1879 label_actor->GetCaptionTextProperty()->SetOrientation(33.333333);
1880 label_actor->GetCaptionTextProperty()->SetFontFamilyToTimes();
1881 label_actor->GetCaptionTextProperty()->SetBold(0);
1882 label_actor->GetCaptionTextProperty()->SetFontSize(6);
1883 label_actor->BorderOff();
1884 label_actor->LeaderOff();
1885 label_actor->ThreeDimensionalLeaderOff();
1886 mLandLabelActors.push_back(label_actor);
1887 this->Renderer->AddActor2D(mLandLabelActors[id]);
1892 //----------------------------------------------------------------------------
1895 //----------------------------------------------------------------------------
1896 void vvSlicer::SetSlice(int slice)
1898 int *range = this->GetSliceRange();
1900 if (slice < range[0]) {
1902 } else if (slice > range[1]) {
1907 if (this->Slice == slice) {
1911 this->Slice = slice;
1914 this->UpdateDisplayExtent();
1916 // Seems to work without this line
1919 //----------------------------------------------------------------------------
1921 //----------------------------------------------------------------------------
1922 int vvSlicer::GetTMax()
1924 int tmax = (int)mImage->GetVTKImages().size() - 1;
1926 tmax = std::max(tmax, (int)mOverlay->GetVTKImages().size()-1);
1929 //----------------------------------------------------------------------------
1931 //----------------------------------------------------------------------------
1932 void vvSlicer::SetContourSlice()
1934 if (mSurfaceCutActors.size() > 0)
1935 for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
1936 i!=mSurfaceCutActors.end(); i++) {
1938 (*i)->SetSlicingOrientation(this->SliceOrientation);
1939 (*i)->SetCutSlice((this->Slice)*this->GetImage()->GetSpacing()[this->SliceOrientation]+
1940 this->GetImage()->GetOrigin()[this->SliceOrientation]);
1943 //----------------------------------------------------------------------------
1946 //----------------------------------------------------------------------------
1947 void vvSlicer::ForceUpdateDisplayExtent()
1949 this->UpdateDisplayExtent();
1951 //----------------------------------------------------------------------------
1954 //----------------------------------------------------------------------------
1955 int* vvSlicer::GetDisplayExtent()
1957 return this->GetImageActor()->GetDisplayExtent();
1959 //----------------------------------------------------------------------------
1962 //----------------------------------------------------------------------------
1963 void vvSlicer::PrintSelf(ostream& os, vtkIndent indent)
1965 this->Superclass::PrintSelf(os, indent);
1967 //----------------------------------------------------------------------------
1970 //----------------------------------------------------------------------------
1971 void vvSlicer::SetVFColor(double r, double g, double b)
1973 double mVFColorHSV[3];
1978 vtkMath::RGBToHSV(mVFColor, mVFColorHSV);
1979 mVFColorLUT->SetHueRange(mVFColorHSV[0], mVFColorHSV[0]);
1980 mVFColorLUT->SetSaturationRange(mVFColorHSV[1],mVFColorHSV[1]);
1981 mVFColorLUT->SetValueRange(mVFColorHSV[2], mVFColorHSV[2]);
1985 //----------------------------------------------------------------------------
1988 //----------------------------------------------------------------------------
1989 void vvSlicer::SetRegisterExtent(int ext[6])
1991 copyExtent(ext, mRegisterExtent);
1993 //----------------------------------------------------------------------------
1996 //----------------------------------------------------------------------------
1997 void vvSlicer::GetRegisterExtent(int ext[6])
1999 copyExtent(mRegisterExtent, ext);
2001 //----------------------------------------------------------------------------