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"
29 #include <vtkVersion.h>
30 #include <vtkExtentTranslator.h>
31 #include <vtkAlgorithm.h>
32 #include <vtkExecutive.h>
33 #include <vtkStreamingDemandDrivenPipeline.h>
34 #include <vtkInformation.h>
35 #include <vtkTextProperty.h>
36 #include <vtkTextActor.h>
37 #include <vtkTextSource.h>
38 #include <vtkActor2D.h>
39 #include <vtkCursor2D.h>
40 #include <vtkPolyDataMapper2D.h>
41 #include <vtkProperty2D.h>
42 #include <vtkCornerAnnotation.h>
43 #include <vtkImageMapToWindowLevelColors.h>
44 #include <vtkImageData.h>
45 #include <vtkImageActor.h>
46 #include <vvBlendImageActor.h>
47 #include <vtkToolkits.h>
48 #include <vtkObjectFactory.h>
49 #include <vtkPointData.h>
50 #include <vtkDataArray.h>
51 #include <vtkFloatArray.h>
52 #include <vtkClipPolyData.h>
53 #include <vtkActor2DCollection.h>
54 #include <vtkGlyph3D.h>
56 #include <vtkCursor3D.h>
57 #include <vtkProperty.h>
59 #include <vtkLightCollection.h>
60 #include <vtkScalarBarActor.h>
61 #include <vtkImageProperty.h>
62 #include <vtkLookupTable.h>
64 #include <vtkRenderer.h>
65 #include <vtkRendererCollection.h>
66 #include <vtkRenderWindow.h>
67 #include <vtkRenderWindowInteractor.h>
68 #include <vtkCamera.h>
69 #include <vtkCallbackCommand.h>
70 #include <vtkCommand.h>
71 #include <vtkPolyDataMapper.h>
74 #include <vtkExtractVOI.h>
75 #include <vtkSphereSource.h>
76 #include <vtkCutter.h>
77 #include <vtkAssignAttribute.h>
78 #include <vtkImageAccumulate.h>
79 #include <vtkImageReslice.h>
80 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
81 # include <vtkOpenGLImageSliceMapper.h>
82 # include <vtkImageMapper3D.h>
83 # include <vtkImageSliceMapper.h>
86 vtkStandardNewMacro(vvSlicer);
87 static void copyExtent(int* in, int* to){
88 for(int i=0; i<6; ++i)
93 //------------------------------------------------------------------------------
96 mFusionSequenceCode = -1;
97 this->UnInstallPipeline();
99 mReducedExtent = new int[6];
100 mRegisterExtent = NULL;
102 mCurrentFusionTSlice = 0;
103 mCurrentOverlayTSlice = 0;
104 mUseReducedExtent = false;
106 mCurrent[0] = -VTK_DOUBLE_MAX;
107 mCurrent[1] = -VTK_DOUBLE_MAX;
108 mCurrent[2] = -VTK_DOUBLE_MAX;
110 mCursor[0] = 0;//-VTK_DOUBLE_MAX;
111 mCursor[1] = 0;//-VTK_DOUBLE_MAX;
112 mCursor[2] = 0;//-VTK_DOUBLE_MAX;
113 mCursor[3] = 0;//-VTK_DOUBLE_MAX;
123 crossCursor = vtkSmartPointer<vtkCursor2D>::New();
124 crossCursor->AllOff();
125 crossCursor->AxesOn();
126 crossCursor->SetTranslationMode(1);
127 crossCursor->SetRadius(2);
129 pdm = vtkSmartPointer<vtkPolyDataMapper2D>::New();
130 #if VTK_MAJOR_VERSION <= 5
131 pdm->SetInput(crossCursor->GetOutput());
133 pdm->SetInputConnection(crossCursor->GetOutputPort(0));
136 pdmA = vtkSmartPointer<vtkActor2D>::New();
137 pdmA->SetMapper(pdm);
138 pdmA->GetProperty()->SetColor(255,10,212);
139 pdmA->SetVisibility(0);
140 pdmA->SetPickable(0);
142 ca = vtkSmartPointer<vtkCornerAnnotation>::New();
143 ca->GetTextProperty()->SetColor(255,10,212);
144 ca->SetVisibility(1);
152 legend = vtkSmartPointer<vtkScalarBarActor>::New();
153 //legend->SetTitle("test!");
154 legend->SetPosition(0.82,0.08);
155 //legend->SetWidth(0.1);
156 legend->SetVisibility(0);
157 legend->SetLabelFormat("%.1e");
158 this->GetRenderer()->AddActor(legend);
159 showFusionLegend = false;
161 this->InstallPipeline();
163 mLinkOverlayWindowLevel = true;
164 mImageVisibility = true;
166 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
167 this->GetImageActor()->GetMapper()->BorderOn();
170 mSlicingTransform = vtkSmartPointer<vtkTransform>::New();
171 mConcatenatedTransform = vtkSmartPointer<vtkTransform>::New();
172 mConcatenatedFusionTransform = vtkSmartPointer<vtkTransform>::New();
173 mConcatenatedOverlayTransform = vtkSmartPointer<vtkTransform>::New();
174 mConcatenatedVFTransform = vtkSmartPointer<vtkTransform>::New();
175 mFirstSetSliceOrientation = true;
177 //------------------------------------------------------------------------------
180 //------------------------------------------------------------------------------
181 vtkImageMapToWindowLevelColors* vvSlicer::GetOverlayMapper()
183 return mOverlayMapper.GetPointer();
185 //------------------------------------------------------------------------------
188 //------------------------------------------------------------------------------
189 vvBlendImageActor* vvSlicer::GetOverlayActor()
191 return mOverlayActor.GetPointer();
193 //------------------------------------------------------------------------------
196 //------------------------------------------------------------------------------
197 vtkImageMapToColors* vvSlicer::GetFusionMapper()
199 return mFusionMapper.GetPointer();
201 //------------------------------------------------------------------------------
204 //------------------------------------------------------------------------------
205 vtkImageActor* vvSlicer::GetFusionActor()
207 return mFusionActor.GetPointer();
209 //------------------------------------------------------------------------------
212 //------------------------------------------------------------------------------
213 vtkActor* vvSlicer::GetVFActor()
215 return mVFActor.GetPointer();
217 //------------------------------------------------------------------------------
220 //------------------------------------------------------------------------------
221 vtkCornerAnnotation* vvSlicer::GetAnnotation()
223 return ca.GetPointer();
225 //------------------------------------------------------------------------------
228 //------------------------------------------------------------------------------
229 void vvSlicer::EnableReducedExtent(bool b)
231 mUseReducedExtent = b;
233 //------------------------------------------------------------------------------
236 //------------------------------------------------------------------------------
237 void vvSlicer::SetReducedExtent(int * ext)
239 copyExtent(ext, mReducedExtent);
241 //------------------------------------------------------------------------------
244 //------------------------------------------------------------------------------
245 void vvSlicer::AddContour(vvMesh::Pointer contour,bool propagate)
248 mSurfaceCutActors.push_back(new vvMeshActor());
250 mSurfaceCutActors.back()->Init(contour,mCurrentTSlice,mVF);
252 mSurfaceCutActors.back()->Init(contour,mCurrentTSlice);
253 mSurfaceCutActors.back()->SetSlicingOrientation(SliceOrientation);
254 this->GetRenderer()->AddActor(mSurfaceCutActors.back()->GetActor());
258 //------------------------------------------------------------------------------
261 //------------------------------------------------------------------------------
262 void vvSlicer::ToggleContourSuperposition()
264 for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
265 i!=mSurfaceCutActors.end(); i++)
266 (*i)->ToggleSuperposition();
268 //------------------------------------------------------------------------------
271 //------------------------------------------------------------------------------
272 void vvSlicer::SetCursorColor(int r,int g, int b)
274 pdmA->GetProperty()->SetColor(r,g,b);
276 //------------------------------------------------------------------------------
279 //------------------------------------------------------------------------------
280 void vvSlicer::SetCursorVisibility(bool s)
282 pdmA->SetVisibility(s);
284 //------------------------------------------------------------------------------
287 //------------------------------------------------------------------------------
288 bool vvSlicer::GetCursorVisibility()
290 return pdmA->GetVisibility();
292 //------------------------------------------------------------------------------
295 //------------------------------------------------------------------------------
296 void vvSlicer::SetCornerAnnotationVisibility(bool s)
298 ca->SetVisibility(s);
300 //------------------------------------------------------------------------------
303 //------------------------------------------------------------------------------
304 bool vvSlicer::GetCornerAnnotationVisibility()
306 return ca->GetVisibility();
308 //------------------------------------------------------------------------------
311 //------------------------------------------------------------------------------
312 vvSlicer::~vvSlicer()
314 for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
315 i!=mSurfaceCutActors.end(); i++)
317 delete [] mReducedExtent;
319 //------------------------------------------------------------------------------
321 //------------------------------------------------------------------------------
322 double* vvSlicer::GetCurrentPosition()
324 return mCurrentBeforeSlicingTransform;
326 //------------------------------------------------------------------------------
328 //------------------------------------------------------------------------------
329 void vvSlicer::SetInterpolationImageReslice(int interpolation)
331 mImageReslice->SetInterpolationMode(interpolation);
333 //------------------------------------------------------------------------------
335 //------------------------------------------------------------------------------
336 void vvSlicer::SetCurrentPosition(double x, double y, double z, int t)
338 mCurrentBeforeSlicingTransform[0]=x;
339 mCurrentBeforeSlicingTransform[1]=y;
340 mCurrentBeforeSlicingTransform[2]=z;
341 mSlicingTransform->GetInverse()->TransformPoint(mCurrentBeforeSlicingTransform,mCurrent);
342 if (t>=0) SetTSlice(t);
344 //------------------------------------------------------------------------------
347 //------------------------------------------------------------------------------
348 void vvSlicer::SetImage(vvImage::Pointer image)
350 if (image->GetVTKImages().size()) {
353 if (!mImageReslice) {
354 mImageReslice = vtkSmartPointer<vtkImageReslice>::New();
355 mImageReslice->SetInterpolationModeToLinear();
356 SetInterpolationImageReslice(getInterpolationFavoriteStatus());
357 GetImageActor()->SetInterpolate(getInterpolationFavoriteStatus());
358 mImageReslice->AutoCropOutputOn();
359 mImageReslice->SetBackgroundColor(-1000,-1000,-1000,1);
362 mConcatenatedTransform->Identity();
363 mConcatenatedTransform->Concatenate(mImage->GetTransform()[0]);
364 mConcatenatedTransform->Concatenate(mSlicingTransform);
365 mImageReslice->SetResliceAxes(mConcatenatedTransform->GetMatrix());
366 #if VTK_MAJOR_VERSION <= 5
367 mImageReslice->SetInput(0, mImage->GetFirstVTKImageData());
369 mImageReslice->SetInputData(0, mImage->GetFirstVTKImageData());
371 mImageReslice->UpdateInformation();
373 #if VTK_MAJOR_VERSION <= 5
374 this->Superclass::SetInput(mImageReslice->GetOutput());
376 this->Superclass::SetInputConnection(mImageReslice->GetOutputPort());
380 #if VTK_MAJOR_VERSION <= 5
381 this->GetInput()->GetWholeExtent(extent);
383 mImageReslice->GetOutput()->GetExtent(extent);
386 // Prevent crash when reload -> change slice if outside extent
387 if (Slice < extent[SliceOrientation*2] || Slice>=extent[SliceOrientation*2+1]) {
388 Slice = (extent[SliceOrientation*2+1]+extent[SliceOrientation*2])/2.0;
391 // Make sure that the required part image has been computed
392 extent[SliceOrientation*2] = Slice;
393 extent[SliceOrientation*2+1] = Slice;
394 #if VTK_MAJOR_VERSION <= 5
395 mImageReslice->GetOutput()->SetUpdateExtent(extent);
396 mImageReslice->GetOutput()->Update();
397 #elif VTK_MAJOR_VERSION >= 8 || (VTK_MAJOR_VERSION == 7 && VTK_MINOR_VERSION >= 1)
398 mImageReslice->UpdateExtent(extent);
399 mImageReslice->Update();
401 mImageReslice->SetUpdateExtent(extent);
402 mImageReslice->Update();
405 this->UpdateDisplayExtent();
408 ca->SetText(0,mFileName.c_str());
411 //------------------------------------------------------------------------------
414 //------------------------------------------------------------------------------
415 void vvSlicer::SetOverlay(vvImage::Pointer overlay)
417 if (overlay->GetVTKImages().size()) {
419 mOverlayVisibility = true;
421 if (!mOverlayReslice) {
422 mOverlayReslice = vtkSmartPointer<vtkImageReslice>::New();
423 mOverlayReslice->SetInterpolationModeToLinear();
424 mOverlayReslice->AutoCropOutputOn();
425 mOverlayReslice->SetBackgroundColor(-1000,-1000,-1000,1);
428 mConcatenatedOverlayTransform->Identity();
429 mConcatenatedOverlayTransform->Concatenate(mOverlay->GetTransform()[0]);
430 mConcatenatedOverlayTransform->Concatenate(mSlicingTransform);
431 mOverlayReslice->SetResliceAxes(mConcatenatedOverlayTransform->GetMatrix());
432 #if VTK_MAJOR_VERSION <= 5
433 mOverlayReslice->SetInput(0, mOverlay->GetFirstVTKImageData());
434 mImageReslice->UpdateInformation();
436 mOverlayReslice->SetInputData(0, mOverlay->GetFirstVTKImageData());
438 mOverlayReslice->Update();
441 mOverlayMapper = vtkSmartPointer<vtkImageMapToWindowLevelColors>::New();
442 #if VTK_MAJOR_VERSION <= 5
443 mOverlayMapper->SetInput(mOverlayReslice->GetOutput());
445 mOverlayMapper->SetInputConnection(mOverlayReslice->GetOutputPort(0));
448 if (!mOverlayActor) {
449 mOverlayActor = vtkSmartPointer<vvBlendImageActor>::New();
450 #if VTK_MAJOR_VERSION <= 5
451 mOverlayActor->SetInput(mOverlayMapper->GetOutput());
453 mOverlayActor->GetMapper()->SetInputConnection(mOverlayMapper->GetOutputPort());
455 mOverlayActor->SetPickable(0);
456 mOverlayActor->SetVisibility(true);
457 mOverlayActor->SetOpacity(0.5);
458 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
459 mOverlayActor->GetMapper()->BorderOn();
461 mOverlayActor->SetInterpolate(getInterpolationFavoriteStatus());
464 //stupid but necessary : the Overlay need to be rendered before fusion
466 this->GetRenderer()->RemoveActor(mFusionActor);
467 this->GetRenderer()->AddActor(mOverlayActor);
468 this->GetRenderer()->AddActor(mFusionActor);
470 this->GetRenderer()->AddActor(mOverlayActor);
472 //Synchronize orientation and slice
473 AdjustResliceToSliceOrientation(mOverlayReslice);
474 this->UpdateDisplayExtent();
475 this->SetTSlice(mCurrentTSlice);
478 //------------------------------------------------------------------------------
481 //------------------------------------------------------------------------------
482 void vvSlicer::SetFusion(vvImage::Pointer fusion, int fusionSequenceCode)
484 mFusionSequenceCode = fusionSequenceCode;
485 if (fusion->GetVTKImages().size()) {
487 mFusionVisibility = true;
489 if (!mFusionReslice) {
490 mFusionReslice = vtkSmartPointer<vtkImageReslice>::New();
491 mFusionReslice->SetInterpolationModeToLinear();
492 mFusionReslice->AutoCropOutputOn();
493 mFusionReslice->SetBackgroundColor(-1000,-1000,-1000,1);
496 mConcatenatedFusionTransform->Identity();
497 mConcatenatedFusionTransform->Concatenate(mFusion->GetTransform()[0]);
498 mConcatenatedFusionTransform->Concatenate(mSlicingTransform);
499 mFusionReslice->SetResliceAxes(mConcatenatedFusionTransform->GetMatrix());
500 #if VTK_MAJOR_VERSION <= 5
501 mFusionReslice->SetInput(0, mFusion->GetFirstVTKImageData());
502 mFusionReslice->UpdateInformation();
504 mFusionReslice->SetInputData(0, mFusion->GetFirstVTKImageData());
506 mFusionReslice->Update();
509 mFusionMapper = vtkSmartPointer<vtkImageMapToColors>::New();
511 vtkSmartPointer<vtkLookupTable> lut = vtkLookupTable::New();
513 lut->SetValueRange(0, 1);
514 lut->SetSaturationRange(0, 0);
516 mFusionMapper->SetLookupTable(lut);
517 #if VTK_MAJOR_VERSION <= 5
518 mFusionMapper->SetInput(mFusionReslice->GetOutput());
520 mFusionMapper->SetInputConnection(mFusionReslice->GetOutputPort(0));
524 mFusionActor = vtkSmartPointer<vtkImageActor>::New();
525 #if VTK_MAJOR_VERSION <= 5
526 mFusionActor->SetInput(mFusionMapper->GetOutput());
528 mFusionActor->GetMapper()->SetInputConnection(mFusionMapper->GetOutputPort());
530 mFusionActor->SetPickable(0);
531 mFusionActor->SetVisibility(true);
532 mFusionActor->SetOpacity(0.7);
533 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
534 mFusionActor->GetMapper()->BorderOn();
537 mFusionActor->SetInterpolate(getInterpolationFavoriteStatus());
538 this->GetRenderer()->AddActor(mFusionActor);
541 //Synchronize orientation and slice
542 AdjustResliceToSliceOrientation(mFusionReslice);
543 this->UpdateDisplayExtent();
544 this->SetTSlice(mCurrentTSlice);
547 //------------------------------------------------------------------------------
550 //------------------------------------------------------------------------------
551 bool vvSlicer::GetActorVisibility(const std::string& actor_type, int overlay_index)
554 if (actor_type == "image")
555 vis = mImageVisibility;
556 else if (actor_type == "vector")
558 else if (actor_type == "overlay")
559 vis = mOverlayVisibility;
560 else if ( (actor_type == "fusion") || (actor_type == "fusionSequence") )
561 vis = mFusionVisibility;
562 else if (actor_type == "contour")
563 vis = this->mSurfaceCutActors[overlay_index]->GetActor()->GetVisibility();
566 //------------------------------------------------------------------------------
568 //------------------------------------------------------------------------------
569 void vvSlicer::SetActorVisibility(const std::string& actor_type, int overlay_index ,bool vis)
571 if (actor_type == "image")
572 mImageVisibility = vis;
573 else if (actor_type == "vector")
575 else if (actor_type == "overlay")
576 mOverlayVisibility = vis;
577 else if ( (actor_type == "fusion") || (actor_type == "fusionSequence") )
578 mFusionVisibility = vis;
579 else if (actor_type == "contour")
580 this->mSurfaceCutActors[overlay_index]->GetActor()->SetVisibility(vis);
581 UpdateDisplayExtent();
583 //------------------------------------------------------------------------------
585 //------------------------------------------------------------------------------
586 void vvSlicer::SetVF(vvImage::Pointer vf)
588 if (vf->GetVTKImages().size()) {
590 mVFVisibility = true;
593 mVFReslice = vtkSmartPointer<vtkImageReslice>::New();
594 mVFReslice->SetInterpolationModeToLinear();
595 mVFReslice->AutoCropOutputOn();
596 mVFReslice->SetBackgroundColor(-1000,-1000,-1000,1);
597 mAAFilter= vtkSmartPointer<vtkAssignAttribute>::New();
598 mVOIFilter = vtkSmartPointer<vtkExtractVOI>::New();
599 mVOIFilter->SetSampleRate(mSubSampling,mSubSampling,mSubSampling);
602 mConcatenatedVFTransform->Identity();
603 mConcatenatedVFTransform->Concatenate(mVF->GetTransform()[0]);
604 mConcatenatedVFTransform->Concatenate(mSlicingTransform);
605 mVFReslice->SetResliceAxes(mConcatenatedVFTransform->GetMatrix());
606 #if VTK_MAJOR_VERSION <= 5
607 mVFReslice->SetInput(0, mVF->GetFirstVTKImageData());
609 mVFReslice->SetInputData(0, mVF->GetFirstVTKImageData());
611 mVFReslice->Update();
613 #if VTK_MAJOR_VERSION <= 5
614 mVOIFilter->SetInput(mVFReslice->GetOutput());
615 mAAFilter->SetInput(mVOIFilter->GetOutput());
617 mVOIFilter->SetInputConnection(mVFReslice->GetOutputPort());
618 mAAFilter->SetInputConnection(mVOIFilter->GetOutputPort());
620 ///This tells VTK to use the scalar (pixel) data of the image to draw the little arrows
621 mAAFilter->Assign(vtkDataSetAttributes::SCALARS, vtkDataSetAttributes::VECTORS, vtkAssignAttribute::POINT_DATA);
624 mArrow = vtkSmartPointer<vvGlyphSource>::New();
625 mArrow->SetGlyphTypeToSpecificArrow();
626 mArrow->SetScale(mScale);
629 // Glyph the gradient vector (with arrows)
631 mGlyphFilter = vtkSmartPointer<vvGlyph2D>::New();
632 #if VTK_MAJOR_VERSION <= 5
633 mGlyphFilter->SetInput(mAAFilter->GetOutput());
634 mGlyphFilter->SetSource(mArrow->GetOutput());
636 mGlyphFilter->SetInputConnection(mAAFilter->GetOutputPort());
637 mGlyphFilter->SetSourceConnection(mArrow->GetOutputPort());
639 mGlyphFilter->ScalingOn();
640 mGlyphFilter->SetScaleModeToScaleByVector();
641 mGlyphFilter->OrientOn();
642 mGlyphFilter->SetVectorModeToUseVector();
643 mGlyphFilter->SetColorModeToColorByVector();
646 mVFColorLUT = vtkSmartPointer<vtkLookupTable>::New();
648 double mVFColorHSV[3];
649 vtkMath::RGBToHSV(mVFColor, mVFColorHSV);
650 mVFColorLUT->SetHueRange(mVFColorHSV[0], mVFColorHSV[0]);
651 mVFColorLUT->SetSaturationRange(mVFColorHSV[1],mVFColorHSV[1]);
652 mVFColorLUT->SetValueRange(mVFColorHSV[2], mVFColorHSV[2]);
655 mVFMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
656 #if VTK_MAJOR_VERSION <= 5
657 mVFMapper->SetInput(mGlyphFilter->GetOutput());
659 mVFMapper->SetInputConnection(mGlyphFilter->GetOutputPort());
662 mVFMapper->ImmediateModeRenderingOn();
664 mVFMapper->SetLookupTable(mVFColorLUT);
667 mVFActor = vtkSmartPointer<vtkActor>::New();
668 mVFActor->SetMapper(mVFMapper);
669 mVFActor->SetPickable(0);
670 mVFActor->GetProperty()->SetLineWidth(mVFWidth);
671 this->UpdateDisplayExtent();
672 this->GetRenderer()->AddActor(mVFActor);
675 SetTSlice(mCurrentTSlice);
678 //------------------------------------------------------------------------------
681 //------------------------------------------------------------------------------
682 void vvSlicer::SetLandmarks(vvLandmarks* landmarks)
684 mLandmarks = landmarks;
688 mCross = vtkSmartPointer<vtkCursor3D>::New();
690 mClipBox = vtkSmartPointer<vtkBox>::New();
692 mLandClipper = vtkSmartPointer<vvClipPolyData>::New();
694 mLandGlyph = vtkSmartPointer<vtkGlyph3D>::New();
696 mLandMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
698 mLandActor = vtkSmartPointer<vtkActor>::New();
700 mCross->SetFocalPoint(0.0,0.0,0.0);
701 mCross->SetModelBounds(-10,10,-10,10,-10,10);
705 mLandClipper->SetClipFunction(mClipBox);
706 mLandClipper->InsideOutOn();
707 #if VTK_MAJOR_VERSION <= 5
708 mLandmarkTransform = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
709 mLandmarkTransform->SetInput(mLandmarks->GetOutput());
710 mConcatenatedTransform->Identity();
711 mConcatenatedTransform->Concatenate(mImage->GetTransform()[0]);
712 mConcatenatedTransform->Concatenate(mSlicingTransform);
713 mLandmarkTransform->SetTransform(mConcatenatedTransform->GetInverse());
714 mLandClipper->SetInput(mLandmarkTransform->GetOutput());
716 mLandGlyph->SetSource(mCross->GetOutput());
717 mLandGlyph->SetInput(mLandClipper->GetOutput());
719 mLandmarkTransform = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
720 mLandmarkTransform->SetInputData(mLandmarks->GetOutput());
721 mConcatenatedTransform->Identity();
722 mConcatenatedTransform->Concatenate(mImage->GetTransform()[0]);
723 mConcatenatedTransform->Concatenate(mSlicingTransform);
724 mLandmarkTransform->SetTransform(mConcatenatedTransform->GetInverse());
725 mLandClipper->SetInputConnection(mLandmarkTransform->GetOutputPort());
727 mLandGlyph->SetSourceConnection(mCross->GetOutputPort());
728 mLandGlyph->SetInputConnection(mLandClipper->GetOutputPort());
730 //mLandGlyph->SetIndexModeToScalar();
731 //mLandGlyph->SetRange(0,1);
732 //mLandGlyph->ScalingOff();
734 //mLandGlyph->SetColorModeToColorByScalar();
736 mLandGlyph->SetScaleModeToDataScalingOff();
737 mLandGlyph->SetIndexModeToOff();
739 mLandMapper->SetInputConnection(mLandGlyph->GetOutputPort());
740 //mLandMapper->ScalarVisibilityOff();
742 mLandActor->SetMapper(mLandMapper);
743 mLandActor->GetProperty()->SetOpacity(0.995); //in order to get VTK to turn on the alpha-blending in OpenGL
744 mLandActor->GetProperty()->SetColor(255,10,212);
745 mLandActor->SetPickable(0);
746 mLandActor->SetVisibility(true);
747 this->UpdateDisplayExtent();
750 //------------------------------------------------------------------------------
752 //------------------------------------------------------------------------------
753 //FIXME: this function leaks memory, we should fix it someday :)
754 void vvSlicer::RemoveActor(const std::string& actor_type, int overlay_index)
756 if (actor_type == "vector") {
757 Renderer->RemoveActor(mVFActor);
766 if (actor_type == "overlay") {
767 Renderer->RemoveActor(mOverlayActor);
769 mOverlayActor = NULL;
770 mOverlayMapper = NULL;
772 if ( (actor_type == "fusion") || (actor_type == "fusionSequence") ) {
773 Renderer->RemoveActor(mFusionActor);
776 mFusionMapper = NULL;
778 if (actor_type == "contour") {
779 Renderer->RemoveActor(this->mSurfaceCutActors[overlay_index]->GetActor());
780 mSurfaceCutActors.erase(mSurfaceCutActors.begin()+overlay_index);
783 //------------------------------------------------------------------------------
786 //------------------------------------------------------------------------------
787 void vvSlicer::SetVFSubSampling(int sub)
790 mVOIFilter->SetSampleRate(mSubSampling,mSubSampling,mSubSampling);
793 UpdateDisplayExtent();
796 //------------------------------------------------------------------------------
799 //------------------------------------------------------------------------------
800 void vvSlicer::SetVFScale(int scale)
804 mArrow->SetScale(mScale);
805 UpdateDisplayExtent();
808 //------------------------------------------------------------------------------
810 //------------------------------------------------------------------------------
811 void vvSlicer::SetVFWidth(int width)
815 mVFActor->GetProperty()->SetLineWidth(mVFWidth);
816 UpdateDisplayExtent();
819 //------------------------------------------------------------------------------
822 //------------------------------------------------------------------------------
823 void vvSlicer::SetVFLog(int log)
827 mGlyphFilter->SetUseLog(mVFLog);
828 mGlyphFilter->Modified();
830 UpdateDisplayExtent();
833 //------------------------------------------------------------------------------
836 //------------------------------------------------------------------------------
837 void vvSlicer::SetTSlice(int t, bool updateLinkedImages)
839 if (!updateLinkedImages) {
841 #if VTK_MAJOR_VERSION <= 5
842 mImageReslice->SetInput( mImage->GetVTKImages()[mCurrentTSlice] );
844 mImageReslice->SetInputData( mImage->GetVTKImages()[mCurrentTSlice] );
847 mConcatenatedTransform->Identity();
848 mConcatenatedTransform->Concatenate(mImage->GetTransform()[mCurrentTSlice]);
849 mConcatenatedTransform->Concatenate(mSlicingTransform);
850 UpdateDisplayExtent();
855 else if ((unsigned int)t >= mImage->GetVTKImages().size())
856 mCurrentTSlice = mImage->GetVTKImages().size() -1;
861 mConcatenatedTransform->Identity();
862 mConcatenatedTransform->Concatenate(mImage->GetTransform()[mCurrentTSlice]);
863 mConcatenatedTransform->Concatenate(mSlicingTransform);
866 #if VTK_MAJOR_VERSION <= 5
867 mImageReslice->SetInput( mImage->GetVTKImages()[mCurrentTSlice] );
869 mImageReslice->SetInputData( mImage->GetVTKImages()[mCurrentTSlice] );
871 if (mVF && mVFActor->GetVisibility()) {
872 if (mVF->GetVTKImages().size() > (unsigned int)mCurrentTSlice)
873 #if VTK_MAJOR_VERSION <= 5
874 mVFReslice->SetInput(mVF->GetVTKImages()[mCurrentTSlice]);
876 mVFReslice->SetInputData(mVF->GetVTKImages()[mCurrentTSlice]);
878 // Update overlay transform
879 mConcatenatedVFTransform->Identity();
880 mConcatenatedVFTransform->Concatenate(mVF->GetTransform()[mCurrentTSlice]);
881 mConcatenatedVFTransform->Concatenate(mSlicingTransform);
884 if (mOverlay && mOverlayActor->GetVisibility()) {
885 if (mOverlay->GetVTKImages().size() > (unsigned int)t) {
886 mCurrentOverlayTSlice = t;
887 #if VTK_MAJOR_VERSION <= 5
888 mOverlayReslice->SetInput( mOverlay->GetVTKImages()[mCurrentOverlayTSlice] );
890 mOverlayReslice->SetInputData( mOverlay->GetVTKImages()[mCurrentOverlayTSlice] );
892 // Update overlay transform
893 mConcatenatedOverlayTransform->Identity();
894 mConcatenatedOverlayTransform->Concatenate(mOverlay->GetTransform()[mCurrentOverlayTSlice]);
895 mConcatenatedOverlayTransform->Concatenate(mSlicingTransform);
898 //update the fusion ; except in case this is a fusionSequence, in which case both 'times' should be independent.
899 if (mFusion && mFusionActor->GetVisibility() && (mFusionSequenceCode<0)) {
900 if (mFusion->GetVTKImages().size() > (unsigned int)t) {
901 mCurrentFusionTSlice = t;
902 #if VTK_MAJOR_VERSION <= 5
903 mFusionReslice->SetInput( mFusion->GetVTKImages()[mCurrentFusionTSlice]);
905 mFusionReslice->SetInputData( mFusion->GetVTKImages()[mCurrentFusionTSlice]);
908 // Update fusion transform
909 mConcatenatedFusionTransform->Identity();
910 mConcatenatedFusionTransform->Concatenate(mFusion->GetTransform()[mCurrentFusionTSlice]);
911 mConcatenatedFusionTransform->Concatenate(mSlicingTransform);
914 if (mSurfaceCutActors.size() > 0)
915 for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
916 i!=mSurfaceCutActors.end(); i++)
917 (*i)->SetTimeSlice(mCurrentTSlice);
918 UpdateDisplayExtent();
920 //------------------------------------------------------------------------------
923 //------------------------------------------------------------------------------
924 void vvSlicer::SetFusionSequenceTSlice(int t)
926 if (mFusion && mFusionActor->GetVisibility() && (mFusionSequenceCode>=0)) {
927 if (mFusion->GetVTKImages().size() > (unsigned int)t) {
928 mCurrentFusionTSlice = t;
929 #if VTK_MAJOR_VERSION <= 5
930 mFusionReslice->SetInput( mFusion->GetVTKImages()[mCurrentFusionTSlice] );
932 mFusionReslice->SetInputData( mFusion->GetVTKImages()[mCurrentFusionTSlice] );
934 // Update fusion transform
935 mConcatenatedFusionTransform->Identity();
936 mConcatenatedFusionTransform->Concatenate(mFusion->GetTransform()[mCurrentFusionTSlice]); //not really useful...
937 mConcatenatedFusionTransform->Concatenate(mSlicingTransform);
941 UpdateDisplayExtent();
943 //------------------------------------------------------------------------------
946 //------------------------------------------------------------------------------
947 int vvSlicer::GetTSlice()
949 return mCurrentTSlice;
951 //------------------------------------------------------------------------------
953 //------------------------------------------------------------------------------
954 int vvSlicer::GetMaxCurrentTSlice()
956 int t = mCurrentTSlice;
957 if(mOverlay && mOverlayActor->GetVisibility())
958 t = std::max(t, mCurrentOverlayTSlice);
959 if(mFusion&& (mFusionSequenceCode<0) && mFusionActor->GetVisibility()) //ignore fusionSequence data: for these, the times are not to be related (this way)
960 t = std::max(t, mCurrentFusionTSlice);
963 //------------------------------------------------------------------------------
965 //------------------------------------------------------------------------------
966 int vvSlicer::GetFusionTSlice()
968 return mCurrentFusionTSlice;
970 //------------------------------------------------------------------------------
972 //------------------------------------------------------------------------------
973 int vvSlicer::GetOverlayTSlice()
975 return mCurrentOverlayTSlice;
977 //------------------------------------------------------------------------------
979 //------------------------------------------------------------------------------
980 void vvSlicer::SetSliceOrientation(int orientation)
982 //if 2D image, force to watch in Axial View
984 #if VTK_MAJOR_VERSION <= 5
985 this->GetInput()->GetWholeExtent(extent);
987 int* ext = mImageReslice->GetInputInformation()->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT());
988 copyExtent(ext, extent);
991 if (extent[5]-extent[4] <= 2)
992 orientation = vtkImageViewer2::SLICE_ORIENTATION_XY;
994 if (orientation < vtkImageViewer2::SLICE_ORIENTATION_YZ ||
995 orientation > vtkImageViewer2::SLICE_ORIENTATION_XY) {
996 vtkErrorMacro("Error - invalid slice orientation " << orientation);
1000 this->SliceOrientation = orientation;
1003 AdjustResliceToSliceOrientation(mFusionReslice);
1006 AdjustResliceToSliceOrientation(mOverlayReslice);
1009 AdjustResliceToSliceOrientation(mVFReslice);
1011 // Update the viewer
1013 // Go to current cursor position
1014 // double* cursorPos = GetCursorPosition();
1015 // DDV(cursorPos, 3);
1016 // SetCurrentPosition(cursorPos[0],cursorPos[1],cursorPos[2],cursorPos[3]);
1018 if (mFirstSetSliceOrientation) {
1019 int *range = this->GetSliceRange();
1021 this->Slice = static_cast<int>((range[0] + range[1]) * 0.5);
1022 #if VTK_MAJOR_VERSION <= 5
1023 mFirstSetSliceOrientation = false;
1026 else if (this->Renderer && this->GetInput()) {
1027 double s = mCursor[orientation];
1028 double sCursor = (s - this->GetInput()->GetOrigin()[orientation])/this->GetInput()->GetSpacing()[orientation];
1029 this->Slice = static_cast<int>(sCursor);
1032 this->UpdateOrientation();
1034 this->UpdateDisplayExtent();
1036 if (mFirstSetSliceOrientation) {
1037 mFirstSetSliceOrientation = false;
1040 if (this->Renderer && this->GetInput()) {
1041 double scale = this->Renderer->GetActiveCamera()->GetParallelScale();
1042 this->Renderer->ResetCamera();
1043 this->Renderer->GetActiveCamera()->SetParallelScale(scale);
1048 //----------------------------------------------------------------------------
1050 //------------------------------------------------------------------------------
1051 // This function ensures that we sample the slices of a vtkImageReslice filter
1052 // in the direction of the slicer (SliceOrientation) similarly as mImageReslice.
1053 // In other words, we change the grid of the reslice in the same way as the grid
1054 // of the displayed image in the slicing direction.
1055 void vvSlicer::AdjustResliceToSliceOrientation(vtkImageReslice *reslice)
1057 // Reset autocrop and update output information
1058 reslice->SetOutputOriginToDefault();
1059 reslice->SetOutputSpacingToDefault();
1060 #if VTK_MAJOR_VERSION <= 5
1061 reslice->GetOutput()->UpdateInformation();
1063 reslice->UpdateInformation();
1066 // Ge new origin / spacing
1069 reslice->GetOutput()->GetOrigin(origin);
1070 reslice->GetOutput()->GetSpacing(spacing);
1072 // Use similar spacing as the image in the direction SliceOrientation
1073 spacing[this->SliceOrientation] = mImageReslice->GetOutput()->GetSpacing()[this->SliceOrientation];
1075 // Modify origin to be on the image grid in the direction SliceOrientation in 3 steps
1076 // Step 1: from world coordinates to image coordinates
1077 origin[this->SliceOrientation] -= mImageReslice->GetOutput()->GetOrigin()[this->SliceOrientation];
1078 origin[this->SliceOrientation] /= mImageReslice->GetOutput()->GetSpacing()[this->SliceOrientation];
1080 // Step 2: round to nearest grid positionInc. This has been validated as the only
1081 // way to have something consistent with the thickness of a 2D slice visible on the
1082 // other slices. The thickness is accounted for so if the 2D slice is to thin and
1083 // between two slices, one will never be able to see this 2D slice (bug #1883).
1084 origin[this->SliceOrientation] = itk::Math::Round<double>(origin[this->SliceOrientation]);
1086 // Step 3: back to world coordinates
1087 origin[this->SliceOrientation] *= mImageReslice->GetOutput()->GetSpacing()[this->SliceOrientation];
1088 origin[this->SliceOrientation] += mImageReslice->GetOutput()->GetOrigin()[this->SliceOrientation];
1090 // Set new spacing and origin
1091 reslice->SetOutputOrigin(origin);
1092 reslice->SetOutputSpacing(spacing);
1093 reslice->UpdateInformation();
1094 #if VTK_MAJOR_VERSION <= 5
1095 reslice->GetOutput()->UpdateInformation();
1098 //------------------------------------------------------------------------------
1100 //----------------------------------------------------------------------------
1101 int * vvSlicer::GetExtent()
1104 if (mUseReducedExtent) {
1105 w_ext = mReducedExtent;
1108 #if VTK_MAJOR_VERSION <= 5
1109 w_ext = GetInput()->GetWholeExtent();
1111 w_ext = mImageReslice->GetInputInformation()->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT());
1116 //----------------------------------------------------------------------------
1119 //----------------------------------------------------------------------------
1120 int vvSlicer::GetOrientation()
1122 return this->SliceOrientation;
1124 //----------------------------------------------------------------------------
1127 //----------------------------------------------------------------------------
1128 void vvSlicer::UpdateDisplayExtent()
1130 emit UpdateDisplayExtentBegin(mSlicerNumber);
1131 vtkImageData *input = this->GetInput();
1132 if (!input || !this->ImageActor) {
1136 #if VTK_MAJOR_VERSION <= 5
1137 input->UpdateInformation();
1139 mRegisterExtent = mImageReslice->GetOutputInformation(0)->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT());
1141 this->SetSlice( this->GetSlice() ); //SR: make sure the update let the slice in extents
1143 // Local copy of extent
1145 #if VTK_MAJOR_VERSION <= 5
1146 int* ext = GetExtent();
1148 int* ext = mImageReslice->GetOutputInformation(0)->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT());
1150 copyExtent(ext, w_ext);
1151 if (mUseReducedExtent) {
1152 copyExtent(mReducedExtent, w_ext);
1156 w_ext[ this->SliceOrientation*2 ] = this->Slice;
1157 w_ext[ this->SliceOrientation*2+1 ] = this->Slice;
1160 this->ImageActor->SetVisibility(mImageVisibility);
1161 this->ImageActor->SetDisplayExtent(w_ext);
1163 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
1164 // Fix for bug #1882
1165 dynamic_cast<vtkImageSliceMapper *>(this->ImageActor->GetMapper())->SetOrientation(this->GetOrientation());
1168 // Overlay image actor
1169 if (mOverlay && mOverlayVisibility) {
1170 AdjustResliceToSliceOrientation(mOverlayReslice);
1172 #if VTK_MAJOR_VERSION <= 5
1173 this->ConvertImageToImageDisplayExtent(input, w_ext, mOverlayReslice->GetOutput(), overExtent);
1174 bool out = ClipDisplayedExtent(overExtent, mOverlayMapper->GetInput()->GetWholeExtent());
1176 this->ConvertImageToImageDisplayExtent(mImageReslice->GetOutputInformation(0), w_ext, mOverlayReslice->GetOutput(), overExtent);
1177 bool out = ClipDisplayedExtent(overExtent, mOverlayMapper->GetInputInformation()->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT()));
1179 mOverlayActor->SetVisibility(!out);
1180 mOverlayActor->SetDisplayExtent( overExtent );
1181 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
1182 // Fix for bug #1882
1183 dynamic_cast<vtkImageSliceMapper *>(mOverlayActor->GetMapper())->SetOrientation(this->GetOrientation());
1187 mOverlayActor->SetVisibility(false);
1189 // Fusion image actor
1190 if (mFusion && mFusionVisibility) {
1191 AdjustResliceToSliceOrientation(mFusionReslice);
1193 #if VTK_MAJOR_VERSION <= 5
1194 this->ConvertImageToImageDisplayExtent(input, w_ext, mFusionReslice->GetOutput(), fusExtent);
1195 bool out = ClipDisplayedExtent(fusExtent, mFusionMapper->GetInput()->GetWholeExtent());
1197 this->ConvertImageToImageDisplayExtent(mImageReslice->GetOutputInformation(0), w_ext, mFusionReslice->GetOutput(), fusExtent);
1198 bool out = ClipDisplayedExtent(fusExtent, mFusionMapper->GetInputInformation()->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT()));
1200 mFusionActor->SetVisibility(!out);
1201 mFusionActor->SetDisplayExtent( fusExtent );
1202 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
1203 // Fix for bug #1882
1204 dynamic_cast<vtkImageSliceMapper *>(mFusionActor->GetMapper())->SetOrientation(this->GetOrientation());
1208 mFusionActor->SetVisibility(false);
1209 // Vector field actor
1210 double* camera = Renderer->GetActiveCamera()->GetPosition();
1211 double* image_bounds = ImageActor->GetBounds();
1212 double position[3] = {0, 0, 0};
1213 position[this->SliceOrientation] = image_bounds[this->SliceOrientation*2];
1215 //print_vector<double, 6>("camera", camera);
1216 //print_vector<double, 6>("image_bounds", image_bounds);
1217 //print_vector<double, 3>("position", position);
1219 // find where to place the VF actor. to deal with
1220 // z-buffer issues, the VF is placed right in front of the image,
1221 // subject to a small offset. the position actually depends on the
1222 // the location of the camera relative to the image.
1224 if (camera[this->SliceOrientation] < image_bounds[this->SliceOrientation*2])
1227 if (mVF && mVFVisibility) {
1228 AdjustResliceToSliceOrientation(mVFReslice);
1230 #if VTK_MAJOR_VERSION <= 5
1231 mVF->GetVTKImages()[0]->UpdateInformation();
1232 this->ConvertImageToImageDisplayExtent(input, w_ext, mVFReslice->GetOutput(), vfExtent);
1233 bool out = ClipDisplayedExtent(vfExtent, mVOIFilter->GetInput()->GetWholeExtent());
1235 mVOIFilter->Update();
1236 this->ConvertImageToImageDisplayExtent(mImageReslice->GetOutputInformation(0), w_ext, mVFReslice->GetOutput(), vfExtent);
1237 bool out = ClipDisplayedExtent(vfExtent, mVOIFilter->GetInputInformation()->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT()));
1239 mVFActor->SetVisibility(!out);
1240 mVOIFilter->SetVOI(vfExtent);
1241 int orientation[3] = {1,1,1};
1242 orientation[this->SliceOrientation] = 0;
1243 mGlyphFilter->SetOrientation(orientation[0], orientation[1], orientation[2]);
1244 position[this->SliceOrientation] += offset;
1245 mVFActor->SetPosition(position);
1246 mVFActor->GetProperty()->SetOpacity(0.995); //in order to get VTK to turn on the alpha-blending in OpenGL
1247 mVFMapper->Update();
1251 mVFActor->SetVisibility(false);
1255 for(unsigned int i=0; i<6; i++)
1256 boundsT[i] = ImageActor->GetBounds()[i];
1257 boundsT[ this->SliceOrientation*2 ] = ImageActor->GetBounds()[ this->SliceOrientation*2 ]-fabs(this->GetInput()->GetSpacing()[this->SliceOrientation]);
1258 boundsT[ this->SliceOrientation*2+1 ] = ImageActor->GetBounds()[ this->SliceOrientation*2+1 ]+fabs(this->GetInput()->GetSpacing()[this->SliceOrientation]);
1267 position[this->SliceOrientation] = offset;
1268 mLandActor->SetPosition(position);
1271 // Figure out the correct clipping range
1272 if (this->Renderer) {
1273 if (this->InteractorStyle &&
1274 this->InteractorStyle->GetAutoAdjustCameraClippingRange()) {
1275 this->Renderer->ResetCameraClippingRange();
1277 vtkCamera *cam = this->Renderer->GetActiveCamera();
1280 this->ImageActor->GetBounds(bounds);
1281 double spos = (double)bounds[this->SliceOrientation * 2];
1282 double cpos = (double)cam->GetPosition()[this->SliceOrientation];
1283 double range = fabs(spos - cpos);
1284 double *spacing = input->GetSpacing();
1285 double sumSpacing = spacing[0] + spacing[1] + spacing[2];
1286 cam->SetClippingRange(range - sumSpacing, range + sumSpacing);
1296 emit UpdateDisplayExtentEnd(mSlicerNumber);
1298 //----------------------------------------------------------------------------
1300 //----------------------------------------------------------------------------
1301 void vvSlicer::ConvertImageToImageDisplayExtent(vtkInformation *sourceImage, const int sourceExtent[6],
1302 vtkImageData *targetImage, int targetExtent[6])
1305 double *origin, *spacing;
1306 origin = sourceImage->Get(vtkDataObject::ORIGIN());
1307 spacing = sourceImage->Get(vtkDataObject::SPACING());
1308 for(unsigned int i=0; i<6; i++) {
1309 // From source voxel coordinates to world coordinates
1310 dExtents[i] = origin[i/2] + spacing[i/2] * sourceExtent[i];
1312 // From world coordinates to floating point target voxel coordinates
1313 dExtents[i] = (dExtents[i]- targetImage->GetOrigin()[i/2]) / targetImage->GetSpacing()[i/2];
1315 // Round to current slice or larger extent
1316 if(i/2==this->GetOrientation())
1317 targetExtent[i] = itk::Math::Round<double>(dExtents[i]);
1319 targetExtent[i] = itk::Math::Ceil<double>(dExtents[i]);
1321 targetExtent[i] = itk::Math::Floor<double>(dExtents[i]);
1324 //----------------------------------------------------------------------------
1326 //----------------------------------------------------------------------------
1327 void vvSlicer::ConvertImageToImageDisplayExtent(vtkImageData *sourceImage, const int sourceExtent[6],
1328 vtkImageData *targetImage, int targetExtent[6])
1331 for(unsigned int i=0; i<6; i++) {
1332 // From source voxel coordinates to world coordinates
1333 dExtents[i] = sourceImage->GetOrigin()[i/2] + sourceImage->GetSpacing()[i/2] * sourceExtent[i];
1335 // From world coordinates to floating point target voxel coordinates
1336 dExtents[i] = (dExtents[i]- targetImage->GetOrigin()[i/2]) / targetImage->GetSpacing()[i/2];
1338 // Round to current slice or larger extent
1339 if(i/2==this->GetOrientation())
1340 targetExtent[i] = itk::Math::Round<double>(dExtents[i]);
1342 targetExtent[i] = itk::Math::Ceil<double>(dExtents[i]);
1344 targetExtent[i] = itk::Math::Floor<double>(dExtents[i]);
1347 //----------------------------------------------------------------------------
1349 //----------------------------------------------------------------------------
1350 bool vvSlicer::ClipDisplayedExtent(int extent[6], int refExtent[6])
1355 for (int i = 0; i < maxBound; i = i+2) {
1356 //if we are totally outside the image
1357 if ( extent[i] > refExtent[i+1] || extent[i+1] < refExtent[i] ) {
1361 //crop to the limit of the image
1362 extent[i] = std::max(extent[i], refExtent[i]);
1363 extent[i] = std::min(extent[i], refExtent[i+1]);;
1364 extent[i+1] = std::max(extent[i+1], refExtent[i]);
1365 extent[i+1] = std::min(extent[i+1], refExtent[i+1]);;
1368 for (int i = 0; i < maxBound; i = i+2) {
1369 extent[i] = refExtent[i];
1370 extent[i+1] = refExtent[i];
1374 //----------------------------------------------------------------------------
1377 //----------------------------------------------------------------------------
1378 void vvSlicer::UpdateOrientation()
1380 // Set the camera position
1381 vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
1383 switch (this->SliceOrientation) {
1384 case vtkImageViewer2::SLICE_ORIENTATION_XY:
1385 cam->SetFocalPoint(0,0,0);
1386 cam->SetPosition(0,0,-1); // -1 if medical ?
1387 cam->SetViewUp(0,-1,0);
1390 case vtkImageViewer2::SLICE_ORIENTATION_XZ:
1391 cam->SetFocalPoint(0,0,0);
1392 cam->SetPosition(0,-1,0); // 1 if medical ?
1393 cam->SetViewUp(0,0,1);
1396 case vtkImageViewer2::SLICE_ORIENTATION_YZ:
1397 cam->SetFocalPoint(0,0,0);
1398 cam->SetPosition(-1,0,0); // -1 if medical ?
1399 cam->SetViewUp(0,0,1);
1404 //----------------------------------------------------------------------------
1407 //----------------------------------------------------------------------------
1408 void vvSlicer::SetOpacity(double s)
1410 this->GetImageActor()->SetOpacity(s);
1412 //----------------------------------------------------------------------------
1415 //----------------------------------------------------------------------------
1416 void vvSlicer::SetRenderWindow(int orientation, vtkRenderWindow * rw)
1418 this->Superclass::SetRenderWindow(rw);
1419 this->SetupInteractor(rw->GetInteractor());
1420 ca->SetImageActor(this->GetImageActor());
1421 ca->SetWindowLevel(this->GetWindowLevel());
1422 ca->SetText(3, "<window>\n<level>");
1433 crossCursor->SetModelBounds(bounds);
1435 this->GetRenderer()->AddActor(pdmA);
1436 this->GetRenderer()->AddActor(ca);
1437 this->GetRenderer()->ResetCamera();
1439 //this is just a mapping between the labeling of the orientations presented to the user and
1440 //the one used by vtk
1441 SetSliceOrientation(2-(orientation%3));
1444 //----------------------------------------------------------------------------
1447 //----------------------------------------------------------------------------
1448 void vvSlicer::ResetCamera()
1450 this->GetRenderer()->ResetCamera();
1452 //----------------------------------------------------------------------------
1455 //----------------------------------------------------------------------------
1456 void vvSlicer::SetDisplayMode(bool i)
1458 this->GetRenderer()->SetDraw(i);
1459 if (i) UpdateDisplayExtent();
1461 //----------------------------------------------------------------------------
1464 //----------------------------------------------------------------------------
1465 void vvSlicer::FlipHorizontalView()
1467 vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
1469 double *position = cam->GetPosition();
1470 double factor[3] = {1, 1, 1};
1471 factor[this->SliceOrientation] = -1;
1472 cam->SetPosition(factor[0]*position[0],factor[1]*position[1],factor[2]*position[2]);
1474 /* switch (this->SliceOrientation) {
1475 case vtkImageViewer2::SLICE_ORIENTATION_XY:
1476 cam->SetPosition(position[0],position[1],-position[2]);
1479 case vtkImageViewer2::SLICE_ORIENTATION_XZ:
1480 cam->SetPosition(position[0],-position[1],position[2]);
1483 case vtkImageViewer2::SLICE_ORIENTATION_YZ:
1484 cam->SetPosition(-position[0],position[1],position[2]);
1488 this->Renderer->ResetCameraClippingRange();
1489 this->UpdateDisplayExtent();
1492 //----------------------------------------------------------------------------
1495 //----------------------------------------------------------------------------
1496 void vvSlicer::FlipVerticalView()
1498 vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
1500 FlipHorizontalView();
1501 double *viewup = cam->GetViewUp();
1502 cam->SetViewUp(-viewup[0],-viewup[1],-viewup[2]);
1503 this->UpdateDisplayExtent();
1506 //----------------------------------------------------------------------------
1509 //----------------------------------------------------------------------------
1510 void vvSlicer::SetColorWindow(double window)
1512 vtkLookupTable* LUT = static_cast<vtkLookupTable*>(this->GetWindowLevel()->GetLookupTable());
1514 double level = this->GetWindowLevel()->GetLevel();
1515 LUT->SetTableRange(level-fabs(window)/2,level+fabs(window)/2);
1518 this->vtkImageViewer2::SetColorWindow(window);
1520 //----------------------------------------------------------------------------
1522 //----------------------------------------------------------------------------
1523 void vvSlicer::SetColorLevel(double level)
1525 vtkLookupTable* LUT = static_cast<vtkLookupTable*>(this->GetWindowLevel()->GetLookupTable());
1527 double window = this->GetWindowLevel()->GetWindow();
1528 LUT->SetTableRange(level-fabs(window)/2,level+fabs(window)/2);
1531 this->vtkImageViewer2::SetColorLevel(level);
1533 //----------------------------------------------------------------------------
1535 //----------------------------------------------------------------------------
1536 double vvSlicer::GetOverlayColorWindow()
1539 return mOverlayMapper->GetWindow();
1543 //----------------------------------------------------------------------------
1545 //----------------------------------------------------------------------------
1546 double vvSlicer::GetOverlayColorLevel()
1549 return mOverlayMapper->GetLevel();
1553 //----------------------------------------------------------------------------
1555 //----------------------------------------------------------------------------
1556 void vvSlicer::SetOverlayColorWindow(double window)
1559 mOverlayMapper->SetWindow(window);
1561 //----------------------------------------------------------------------------
1563 //----------------------------------------------------------------------------
1564 void vvSlicer::SetOverlayColorLevel(double level)
1567 mOverlayMapper->SetLevel(level);
1569 //----------------------------------------------------------------------------
1571 //----------------------------------------------------------------------------
1572 // Returns the min an the max value in a 20%x20% region around the mouse pointer
1573 void vvSlicer::GetExtremasAroundMousePointer(double & min, double & max, vtkImageData *image, vtkTransform *transform)
1575 //Get mouse pointer position in view coordinates
1578 for(int i=0; i<3; i++) {
1579 corner1[i] = mCurrent[i];
1580 corner2[i] = mCurrent[i];
1583 this->Renderer->WorldToView(corner1[0], corner1[1], corner1[2]);
1584 this->Renderer->WorldToView(corner2[0], corner2[1], corner2[2]);
1586 // In view coordinates, x is the slicer width and y is the slicer height are the in-plane axis
1588 this->Renderer->GetTiledSize(&w, &h);
1589 corner1[0] -= 0.2*h/(double)w;
1590 corner2[0] += 0.2*h/(double)w;
1593 this->Renderer->ViewToWorld(corner1[0], corner1[1], corner1[2]);
1594 this->Renderer->ViewToWorld(corner2[0], corner2[1], corner2[2]);
1596 //Convert to image pixel coordinates (rounded)
1597 transform->TransformPoint(corner1, corner1);
1598 transform->TransformPoint(corner2, corner2);
1599 int iLocalExtents[6];
1600 for(int i=0; i<3; i++) {
1601 corner1[i] = (corner1[i] - image->GetOrigin()[i])/image->GetSpacing()[i];
1602 corner2[i] = (corner2[i] - image->GetOrigin()[i])/image->GetSpacing()[i];
1604 iLocalExtents[i*2 ] = lrint(corner1[i]);
1605 iLocalExtents[i*2+1] = lrint(corner2[i]);
1607 if(iLocalExtents[i*2 ]>iLocalExtents[i*2+1])
1608 std::swap(iLocalExtents[i*2], iLocalExtents[i*2+1]);
1610 #if VTK_MAJOR_VERSION > 5
1611 for(int j=0;j<2; j++) {
1612 if(iLocalExtents[i*2+j]< mImageReslice->GetInputInformation()->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT())[2*i])
1613 iLocalExtents[i*2+j] = mImageReslice->GetInputInformation()->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT())[2*i];
1615 if(iLocalExtents[i*2+j]> mImageReslice->GetInputInformation()->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT())[2*i+1])
1616 iLocalExtents[i*2+j] = mImageReslice->GetInputInformation()->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT())[2*i+1];
1621 vtkSmartPointer<vtkExtractVOI> voiFilter = vtkSmartPointer<vtkExtractVOI>::New();
1622 #if VTK_MAJOR_VERSION <= 5
1623 voiFilter->SetInput(image);
1625 voiFilter->SetInputData(image);
1627 voiFilter->SetVOI(iLocalExtents);
1628 voiFilter->Update();
1629 if (!voiFilter->GetOutput()->GetNumberOfPoints()) {
1635 vtkSmartPointer<vtkImageAccumulate> accFilter = vtkSmartPointer<vtkImageAccumulate>::New();
1636 #if VTK_MAJOR_VERSION <= 5
1637 accFilter->SetInput(voiFilter->GetOutput());
1639 accFilter->SetInputConnection(voiFilter->GetOutputPort(0));
1641 accFilter->Update();
1643 min = *(accFilter->GetMin());
1644 max = *(accFilter->GetMax());
1646 //----------------------------------------------------------------------------
1648 //----------------------------------------------------------------------------
1649 double vvSlicer::GetScalarComponentAsDouble(vtkImageData *image, double X, double Y, double Z, int &ix, int &iy, int &iz, int component)
1654 #if VTK_MAJOR_VERSION <= 5
1655 if (ix < image->GetWholeExtent()[0] ||
1656 ix > image->GetWholeExtent()[1] ||
1657 iy < image->GetWholeExtent()[2] ||
1658 iy > image->GetWholeExtent()[3] ||
1659 iz < image->GetWholeExtent()[4] ||
1660 iz > image->GetWholeExtent()[5] )
1661 return std::numeric_limits<double>::quiet_NaN();
1662 image->SetUpdateExtent(ix, ix, iy, iy, iz, iz);
1665 if (ix < image->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[0] ||
1666 ix > image->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[1] ||
1667 iy < image->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[2] ||
1668 iy > image->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[3] ||
1669 iz < image->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[4] ||
1670 iz > image->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[5] )
1671 return std::numeric_limits<double>::quiet_NaN();
1672 //image->SetUpdateExtent(ix, ix, iy, iy, iz, iz);
1675 return image->GetScalarComponentAsDouble(ix, iy, iz, component);
1677 //----------------------------------------------------------------------------
1679 //----------------------------------------------------------------------------
1680 void vvSlicer::Render()
1682 if (this->mFusion && mFusionActor->GetVisibility() && showFusionLegend) {
1683 legend->SetLookupTable(this->GetFusionMapper()->GetLookupTable());
1684 legend->UseOpacityOn();
1685 legend->SetVisibility(1);
1687 else if (this->GetWindowLevel()->GetLookupTable() && !this->mOverlay) {
1688 legend->SetLookupTable(this->GetWindowLevel()->GetLookupTable());
1689 legend->UseOpacityOff();
1690 legend->SetVisibility(1);
1691 } else legend->SetVisibility(0);
1693 if (ca->GetVisibility()) {
1694 std::stringstream worldPos(" ");
1696 mConcatenatedTransform->TransformPoint(mCurrent, pt);
1697 double X = (pt[0] - mImage->GetVTKImages()[mCurrentTSlice]->GetOrigin()[0])/mImage->GetVTKImages()[mCurrentTSlice]->GetSpacing()[0];
1698 double Y = (pt[1] - mImage->GetVTKImages()[mCurrentTSlice]->GetOrigin()[1])/mImage->GetVTKImages()[mCurrentTSlice]->GetSpacing()[1];
1699 double Z = (pt[2] - mImage->GetVTKImages()[mCurrentTSlice]->GetOrigin()[2])/mImage->GetVTKImages()[mCurrentTSlice]->GetSpacing()[2];
1700 #if VTK_MAJOR_VERSION <= 5
1701 if (X >= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[0]-0.5 &&
1702 X <= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[1]+0.5 &&
1703 Y >= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[2]-0.5 &&
1704 Y <= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[3]+0.5 &&
1705 Z >= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[4]-0.5 &&
1706 Z <= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[5]+0.5) {
1708 if (X >= mImage->GetVTKImages()[mCurrentTSlice]->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[0]-0.5 &&
1709 X <= mImage->GetVTKImages()[mCurrentTSlice]->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[1]+0.5 &&
1710 Y >= mImage->GetVTKImages()[mCurrentTSlice]->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[2]-0.5 &&
1711 Y <= mImage->GetVTKImages()[mCurrentTSlice]->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[3]+0.5 &&
1712 Z >= mImage->GetVTKImages()[mCurrentTSlice]->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[4]-0.5 &&
1713 Z <= mImage->GetVTKImages()[mCurrentTSlice]->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[5]+0.5) {
1716 double value = this->GetScalarComponentAsDouble(mImage->GetVTKImages()[mCurrentTSlice], X, Y, Z, ix, iy, iz);
1717 if(ImageActor->GetVisibility())
1718 worldPos << "data value : " << value << std::endl;
1719 worldPos << "mm : " << lrint(mCurrent[0]) << ' '
1720 << lrint(mCurrent[1]) << ' '
1721 << lrint(mCurrent[2]) << ' '
1724 worldPos << "pixel : " << ix << ' '
1731 ca->SetText(1,worldPos.str().c_str());
1733 std::stringstream slicePos;
1734 slicePos << "Slice: " << this->GetSlice();
1735 ca->SetText(2, slicePos.str().c_str());
1738 if (pdmA->GetVisibility()) {
1739 double x = mCursor[0];
1740 double y = mCursor[1];
1741 double z = mCursor[2];
1742 double xCursor = (x - this->GetInput()->GetOrigin()[0])/this->GetInput()->GetSpacing()[0];
1743 double yCursor = (y - this->GetInput()->GetOrigin()[1])/this->GetInput()->GetSpacing()[1];
1744 double zCursor = (z - this->GetInput()->GetOrigin()[2])/this->GetInput()->GetSpacing()[2];
1745 #if VTK_MAJOR_VERSION <= 5
1746 if (xCursor >= this->GetImageActor()->GetDisplayExtent()[0]-0.5 &&
1747 xCursor < this->GetImageActor()->GetDisplayExtent()[1]+0.5 &&
1748 yCursor >= this->GetImageActor()->GetDisplayExtent()[2]-0.5 &&
1749 yCursor < this->GetImageActor()->GetDisplayExtent()[3]+0.5 &&
1750 zCursor >= this->GetImageActor()->GetDisplayExtent()[4]-0.5 &&
1751 zCursor < this->GetImageActor()->GetDisplayExtent()[5]+0.5 ) {
1752 vtkRenderer * renderer = this->Renderer;
1754 renderer->WorldToView(x,y,z);
1755 renderer->ViewToNormalizedViewport(x,y,z);
1756 renderer->NormalizedViewportToViewport(x,y);
1757 renderer->ViewportToNormalizedDisplay(x,y);
1758 renderer->NormalizedDisplayToDisplay(x,y);
1759 crossCursor->SetFocalPoint(x,y,z);
1761 crossCursor->SetFocalPoint(-1,-1,z);
1762 crossCursor->Update();
1765 vtkSmartPointer<vtkOpenGLImageSliceMapper> mapperOpenGL= vtkSmartPointer<vtkOpenGLImageSliceMapper>::New();
1767 mapperOpenGL = dynamic_cast<vtkOpenGLImageSliceMapper*>(GetImageActor()->GetMapper());
1768 } catch (const std::bad_cast& e) {
1769 std::cerr << e.what() << std::endl;
1770 std::cerr << "Conversion error" << std::endl;
1774 if (xCursor >= mapperOpenGL->GetCroppingRegion()[0]-0.5 &&
1775 xCursor < mapperOpenGL->GetCroppingRegion()[1]+0.5 &&
1776 yCursor >= mapperOpenGL->GetCroppingRegion()[2]-0.5 &&
1777 yCursor < mapperOpenGL->GetCroppingRegion()[3]+0.5 &&
1778 zCursor >= mapperOpenGL->GetCroppingRegion()[4]-0.5 &&
1779 zCursor < mapperOpenGL->GetCroppingRegion()[5]+0.5 ) {
1780 vtkRenderer * renderer = this->Renderer;
1782 renderer->WorldToView(x,y,z);
1783 renderer->ViewToNormalizedViewport(x,y,z);
1784 renderer->NormalizedViewportToViewport(x,y);
1785 renderer->ViewportToNormalizedDisplay(x,y);
1786 renderer->NormalizedDisplayToDisplay(x,y);
1787 crossCursor->SetFocalPoint(x,y,z);
1789 crossCursor->SetFocalPoint(-1,-1,z);
1790 crossCursor->Update();
1794 if (mOverlay && mOverlayActor->GetVisibility()) {
1795 if(mLinkOverlayWindowLevel) {
1796 mOverlayMapper->SetWindow(this->GetColorWindow());
1797 mOverlayMapper->SetLevel(this->GetColorLevel());
1799 #if VTK_MAJOR_VERSION <= 5
1800 mOverlayMapper->GetOutput()->SetUpdateExtent(mOverlayActor->GetDisplayExtent());
1801 #elif VTK_MAJOR_VERSION >= 8 || (VTK_MAJOR_VERSION == 7 && VTK_MINOR_VERSION >= 1)
1802 mOverlayMapper->UpdateExtent(mOverlayActor->GetDisplayExtent());
1804 mOverlayMapper->SetUpdateExtent(mOverlayActor->GetDisplayExtent());
1806 mOverlayMapper->Update();
1808 if (mFusion && mFusionActor->GetVisibility()) {
1809 #if VTK_MAJOR_VERSION <= 5
1810 mFusionMapper->GetOutput()->SetUpdateExtent(mFusionActor->GetDisplayExtent());
1811 #elif VTK_MAJOR_VERSION >= 8 || (VTK_MAJOR_VERSION == 7 && VTK_MINOR_VERSION >= 1)
1812 mFusionMapper->UpdateExtent(mFusionActor->GetDisplayExtent());
1814 mFusionMapper->SetUpdateExtent(mFusionActor->GetDisplayExtent());
1816 mFusionMapper->Update();
1823 this->GetRenderWindow()->Render();
1825 //----------------------------------------------------------------------------
1828 //----------------------------------------------------------------------------
1829 void vvSlicer::UpdateCursorPosition()
1831 pdmA->SetVisibility(true);
1832 mCursor[0] = mCurrent[0];
1833 mCursor[1] = mCurrent[1];
1834 mCursor[2] = mCurrent[2];
1835 mCursor[3] = mCurrentTSlice;
1837 //----------------------------------------------------------------------------
1840 //----------------------------------------------------------------------------
1841 void vvSlicer::RemoveLandmarks()
1843 vtkPolyData *pd = static_cast<vtkPolyData*>(mLandmarks->GetOutput());
1844 if (pd->GetPoints()) {
1846 //First remove all captions:
1847 for(unsigned int i=0;i<mLandLabelActors.size();i++) {
1848 this->Renderer->RemoveActor2D(mLandLabelActors[i]);
1849 //allActors2D->Remove (mLandLabelActors[i]);
1851 mLandLabelActors.clear();
1854 //----------------------------------------------------------------------------
1857 //----------------------------------------------------------------------------
1858 void vvSlicer::DisplayLandmarks()
1862 for(unsigned int i=0; i<6; i++)
1863 bounds[i] = ImageActor->GetBounds()[i];
1864 bounds[ this->SliceOrientation*2 ] = ImageActor->GetBounds()[ this->SliceOrientation*2 ]-fabs(this->GetInput()->GetSpacing()[this->SliceOrientation]);
1865 bounds[ this->SliceOrientation*2+1 ] = ImageActor->GetBounds()[ this->SliceOrientation*2+1 ]+fabs(this->GetInput()->GetSpacing()[this->SliceOrientation]);
1866 mClipBox->SetBounds(bounds);
1869 vtkPolyData *pd = static_cast<vtkPolyData*>(mLandmarks->GetOutput());
1870 if (pd->GetPoints()) {
1871 this->GetRenderer()->AddActor(mLandActor);
1872 //mLandGlyph->SetRange(0,1);
1873 //mLandGlyph->Modified();
1874 //mLandGlyph->Update();
1875 mClipBox->Modified();
1876 mLandClipper->Update();
1877 mLandMapper->Update();
1878 //Next add the captions to the displayed points
1879 for (vtkIdType id=0; id<mLandClipper->GetOutput()->GetNumberOfPoints(); id++) {
1880 double *position = mLandClipper->GetOutput()->GetPoint(id);
1881 vtkStdString label = static_cast<vtkStringArray*>(mLandClipper->GetOutput()->GetPointData()->GetAbstractArray("labels"))->GetValue(id);
1882 vtkSmartPointer<vtkCaptionActor2D> label_actor = vtkSmartPointer<vtkCaptionActor2D>::New();
1883 label_actor->SetCaption(label);
1884 label_actor->SetAttachmentPoint(position);
1885 label_actor->GetCaptionTextProperty()->SetColor(1,0,0);
1886 label_actor->GetCaptionTextProperty()->SetOrientation(33.333333);
1887 label_actor->GetCaptionTextProperty()->SetFontFamilyToTimes();
1888 label_actor->GetCaptionTextProperty()->SetBold(0);
1889 label_actor->GetCaptionTextProperty()->SetFontSize(6);
1890 label_actor->BorderOff();
1891 label_actor->LeaderOff();
1892 label_actor->ThreeDimensionalLeaderOff();
1893 mLandLabelActors.push_back(label_actor);
1894 this->Renderer->AddActor2D(mLandLabelActors[id]);
1899 //----------------------------------------------------------------------------
1902 //----------------------------------------------------------------------------
1903 void vvSlicer::SetSlice(int slice)
1905 int *range = this->GetSliceRange();
1907 if (slice < range[0]) {
1909 } else if (slice > range[1]) {
1914 if (this->Slice == slice) {
1918 this->Slice = slice;
1921 this->UpdateDisplayExtent();
1923 // Seems to work without this line
1926 //----------------------------------------------------------------------------
1928 //----------------------------------------------------------------------------
1929 int vvSlicer::GetTMax()
1931 int tmax = (int)mImage->GetVTKImages().size() - 1;
1933 tmax = std::max(tmax, (int)mOverlay->GetVTKImages().size()-1);
1936 //----------------------------------------------------------------------------
1938 //----------------------------------------------------------------------------
1939 void vvSlicer::SetContourSlice()
1941 if (mSurfaceCutActors.size() > 0)
1942 for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
1943 i!=mSurfaceCutActors.end(); i++) {
1945 (*i)->SetSlicingOrientation(this->SliceOrientation);
1946 (*i)->SetCutSlice((this->Slice)*this->GetImage()->GetSpacing()[this->SliceOrientation]+
1947 this->GetImage()->GetOrigin()[this->SliceOrientation]);
1950 //----------------------------------------------------------------------------
1953 //----------------------------------------------------------------------------
1954 void vvSlicer::ForceUpdateDisplayExtent()
1956 this->UpdateDisplayExtent();
1958 //----------------------------------------------------------------------------
1961 //----------------------------------------------------------------------------
1962 int* vvSlicer::GetDisplayExtent()
1964 return this->GetImageActor()->GetDisplayExtent();
1966 //----------------------------------------------------------------------------
1969 //----------------------------------------------------------------------------
1970 void vvSlicer::PrintSelf(ostream& os, vtkIndent indent)
1972 this->Superclass::PrintSelf(os, indent);
1974 //----------------------------------------------------------------------------
1977 //----------------------------------------------------------------------------
1978 void vvSlicer::SetVFColor(double r, double g, double b)
1980 double mVFColorHSV[3];
1985 vtkMath::RGBToHSV(mVFColor, mVFColorHSV);
1986 mVFColorLUT->SetHueRange(mVFColorHSV[0], mVFColorHSV[0]);
1987 mVFColorLUT->SetSaturationRange(mVFColorHSV[1],mVFColorHSV[1]);
1988 mVFColorLUT->SetValueRange(mVFColorHSV[2], mVFColorHSV[2]);
1992 //----------------------------------------------------------------------------
1995 //----------------------------------------------------------------------------
1996 void vvSlicer::SetRegisterExtent(int ext[6])
1998 copyExtent(ext, mRegisterExtent);
2000 //----------------------------------------------------------------------------
2003 //----------------------------------------------------------------------------
2004 void vvSlicer::GetRegisterExtent(int ext[6])
2006 copyExtent(mRegisterExtent, ext);
2008 //----------------------------------------------------------------------------