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 ===========================================================================**/
21 #include "vvSlicerManagerCommand.h"
22 #include "vvGlyphSource.h"
23 #include "vvGlyph2D.h"
24 #include "vvImageMapToWLColors.h"
26 #include <vtkTextProperty.h>
27 #include <vtkTextActor.h>
28 #include <vtkTextSource.h>
29 #include <vtkActor2D.h>
30 #include <vtkCursor2D.h>
31 #include <vtkPolyDataMapper2D.h>
32 #include <vtkProperty2D.h>
33 #include <vtkCornerAnnotation.h>
34 #include <vtkImageMapToWindowLevelColors.h>
35 #include <vtkImageData.h>
36 #include <vtkImageActor.h>
37 #include <vvBlendImageActor.h>
38 #include <vtkToolkits.h>
39 #include <vtkObjectFactory.h>
40 #include <vtkPointData.h>
41 #include <vtkDataArray.h>
42 #include <vtkFloatArray.h>
43 #include <vtkClipPolyData.h>
44 #include <vtkGlyph3D.h>
46 #include <vtkCursor3D.h>
47 #include <vtkProperty.h>
49 #include <vtkLightCollection.h>
50 #include <vtkScalarBarActor.h>
51 #include <vtkLookupTable.h>
53 #include <vtkRenderer.h>
54 #include <vtkRendererCollection.h>
55 #include <vtkRenderWindow.h>
56 #include <vtkRenderWindowInteractor.h>
57 #include <vtkCamera.h>
58 #include <vtkCallbackCommand.h>
59 #include <vtkCommand.h>
60 #include <vtkPolyDataMapper.h>
63 #include <vtkExtractVOI.h>
64 #include <vtkSphereSource.h>
65 #include <vtkCutter.h>
66 #include <vtkAssignAttribute.h>
67 #include <vtkImageAccumulate.h>
68 #include <vtkImageReslice.h>
69 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
70 # include <vtkImageMapper3D.h>
73 vtkCxxRevisionMacro(vvSlicer, "DummyRevision");
74 vtkStandardNewMacro(vvSlicer);
75 static void copyExtent(int* in, int* to){
76 for(int i=0; i<6; ++i) to[i]=in[i];
78 //------------------------------------------------------------------------------
81 this->UnInstallPipeline();
83 mReducedExtent = new int[6];
85 mUseReducedExtent = false;
87 mCurrent[0] = -VTK_DOUBLE_MAX;
88 mCurrent[1] = -VTK_DOUBLE_MAX;
89 mCurrent[2] = -VTK_DOUBLE_MAX;
91 mCursor[0] = -VTK_DOUBLE_MAX;
92 mCursor[1] = -VTK_DOUBLE_MAX;
93 mCursor[2] = -VTK_DOUBLE_MAX;
94 mCursor[3] = -VTK_DOUBLE_MAX;
104 crossCursor = vtkSmartPointer<vtkCursor2D>::New();
105 crossCursor->AllOff();
106 crossCursor->AxesOn();
107 crossCursor->SetTranslationMode(1);
108 crossCursor->SetRadius(2);
110 pdm = vtkSmartPointer<vtkPolyDataMapper2D>::New();
111 pdm->SetInput(crossCursor->GetOutput());
113 pdmA = vtkSmartPointer<vtkActor2D>::New();
114 pdmA->SetMapper(pdm);
115 pdmA->GetProperty()->SetColor(255,10,212);
116 pdmA->SetVisibility(0);
117 pdmA->SetPickable(0);
119 ca = vtkSmartPointer<vtkCornerAnnotation>::New();
120 ca->GetTextProperty()->SetColor(255,10,212);
121 ca->SetVisibility(1);
129 legend = vtkSmartPointer<vtkScalarBarActor>::New();
130 //legend->SetTitle("test!");
131 legend->SetPosition(0.82,0.18);
132 legend->SetWidth(0.1);
133 legend->SetVisibility(0);
134 legend->SetLabelFormat("%.1f");
135 this->GetRenderer()->AddActor(legend);
136 showFusionLegend = false;
138 this->WindowLevel->Delete();
139 this->WindowLevel = vvImageMapToWLColors::New();
141 this->InstallPipeline();
143 mLinkOverlayWindowLevel = true;
145 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
146 this->GetImageActor()->GetMapper()->BorderOn();
149 mSlicingTransform = vtkSmartPointer<vtkTransform>::New();
150 mConcatenatedTransform = vtkSmartPointer<vtkTransform>::New();
152 //------------------------------------------------------------------------------
155 //------------------------------------------------------------------------------
156 vtkImageMapToWindowLevelColors* vvSlicer::GetOverlayMapper()
158 return mOverlayMapper.GetPointer();
160 //------------------------------------------------------------------------------
163 //------------------------------------------------------------------------------
164 vvBlendImageActor* vvSlicer::GetOverlayActor()
166 return mOverlayActor.GetPointer();
168 //------------------------------------------------------------------------------
171 //------------------------------------------------------------------------------
172 vtkImageMapToColors* vvSlicer::GetFusionMapper()
174 return mFusionMapper.GetPointer();
176 //------------------------------------------------------------------------------
179 //------------------------------------------------------------------------------
180 vtkImageActor* vvSlicer::GetFusionActor()
182 return mFusionActor.GetPointer();
184 //------------------------------------------------------------------------------
187 //------------------------------------------------------------------------------
188 vtkActor* vvSlicer::GetVFActor()
190 return mVFActor.GetPointer();
192 //------------------------------------------------------------------------------
195 //------------------------------------------------------------------------------
196 vtkCornerAnnotation* vvSlicer::GetAnnotation()
198 return ca.GetPointer();
200 //------------------------------------------------------------------------------
203 //------------------------------------------------------------------------------
204 void vvSlicer::EnableReducedExtent(bool b)
206 mUseReducedExtent = b;
208 //------------------------------------------------------------------------------
211 //------------------------------------------------------------------------------
212 void vvSlicer::SetReducedExtent(int * ext)
214 copyExtent(ext, mReducedExtent);
216 //------------------------------------------------------------------------------
219 //------------------------------------------------------------------------------
220 void vvSlicer::AddContour(vvMesh::Pointer contour,bool propagate)
223 mSurfaceCutActors.push_back(new vvMeshActor());
225 mSurfaceCutActors.back()->Init(contour,mCurrentTSlice,mVF);
227 mSurfaceCutActors.back()->Init(contour,mCurrentTSlice);
228 mSurfaceCutActors.back()->SetSlicingOrientation(SliceOrientation);
229 this->GetRenderer()->AddActor(mSurfaceCutActors.back()->GetActor());
233 //------------------------------------------------------------------------------
236 //------------------------------------------------------------------------------
237 void vvSlicer::ToggleContourSuperposition()
239 for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
240 i!=mSurfaceCutActors.end(); i++)
241 (*i)->ToggleSuperposition();
243 //------------------------------------------------------------------------------
246 //------------------------------------------------------------------------------
247 void vvSlicer::SetCursorColor(int r,int g, int b)
249 pdmA->GetProperty()->SetColor(r,g,b);
251 //------------------------------------------------------------------------------
254 //------------------------------------------------------------------------------
255 void vvSlicer::SetCursorVisibility(bool s)
257 pdmA->SetVisibility(s);
259 //------------------------------------------------------------------------------
262 //------------------------------------------------------------------------------
263 bool vvSlicer::GetCursorVisibility()
265 return pdmA->GetVisibility();
267 //------------------------------------------------------------------------------
270 //------------------------------------------------------------------------------
271 void vvSlicer::SetCornerAnnotationVisibility(bool s)
273 ca->SetVisibility(s);
275 //------------------------------------------------------------------------------
278 //------------------------------------------------------------------------------
279 bool vvSlicer::GetCornerAnnotationVisibility()
281 return ca->GetVisibility();
283 //------------------------------------------------------------------------------
286 //------------------------------------------------------------------------------
287 vvSlicer::~vvSlicer()
289 for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
290 i!=mSurfaceCutActors.end(); i++)
292 delete [] mReducedExtent;
294 //------------------------------------------------------------------------------
296 //------------------------------------------------------------------------------
297 double* vvSlicer::GetCurrentPosition()
299 return mCurrentBeforeSlicingTransform;
301 //------------------------------------------------------------------------------
303 //------------------------------------------------------------------------------
304 void vvSlicer::SetCurrentPosition(double x, double y, double z, int t)
306 mCurrentBeforeSlicingTransform[0]=x;
307 mCurrentBeforeSlicingTransform[1]=y;
308 mCurrentBeforeSlicingTransform[2]=z;
309 mSlicingTransform->GetInverse()->TransformPoint(mCurrentBeforeSlicingTransform,mCurrent);
312 //------------------------------------------------------------------------------
315 //------------------------------------------------------------------------------
316 void vvSlicer::SetImage(vvImage::Pointer image)
318 if (image->GetVTKImages().size()) {
321 if (!mImageReslice) {
322 mImageReslice = vtkSmartPointer<vtkImageReslice>::New();
323 mImageReslice->SetInterpolationModeToLinear();
324 mImageReslice->AutoCropOutputOn();
325 mImageReslice->SetBackgroundColor(-1000,-1000,-1000,1);
328 mConcatenatedTransform->Identity();
329 mConcatenatedTransform->Concatenate(mImage->GetTransform());
330 mConcatenatedTransform->Concatenate(mSlicingTransform);
331 mImageReslice->SetResliceTransform(mConcatenatedTransform);
332 mImageReslice->SetInput(0, mImage->GetFirstVTKImageData());
333 mImageReslice->UpdateInformation();
335 this->Superclass::SetInput(mImageReslice->GetOutput());
338 this->GetInput()->GetWholeExtent(extent);
340 // Prevent crash when reload -> change slice if outside extent
341 if (Slice < extent[SliceOrientation*2] || Slice>=extent[SliceOrientation*2+1]) {
342 Slice = (extent[SliceOrientation*2+1]+extent[SliceOrientation*2])/2.0;
345 // Make sure that the required part image has been computed
346 extent[SliceOrientation*2] = Slice;
347 extent[SliceOrientation*2+1] = Slice;
348 mImageReslice->GetOutput()->SetUpdateExtent(extent);
349 mImageReslice->GetOutput()->Update();
351 this->UpdateDisplayExtent();
354 ca->SetText(0,mFileName.c_str());
357 //------------------------------------------------------------------------------
360 //------------------------------------------------------------------------------
361 void vvSlicer::SetOverlay(vvImage::Pointer overlay)
363 if (overlay->GetVTKImages().size()) {
366 if (!mOverlayReslice) {
367 mOverlayReslice = vtkSmartPointer<vtkImageReslice>::New();
368 mOverlayReslice->SetInterpolationModeToLinear();
369 mOverlayReslice->AutoCropOutputOn();
370 mOverlayReslice->SetBackgroundColor(-1000,-1000,-1000,1);
372 mOverlayReslice->SetResliceTransform(mOverlay->GetTransform());
373 mOverlayReslice->SetInput(0, mOverlay->GetFirstVTKImageData());
376 mOverlayMapper = vtkSmartPointer<vtkImageMapToWindowLevelColors>::New();
377 mOverlayMapper->SetInput(mOverlayReslice->GetOutput());
379 if (!mOverlayActor) {
380 mOverlayActor = vtkSmartPointer<vvBlendImageActor>::New();
381 mOverlayActor->SetInput(mOverlayMapper->GetOutput());
382 mOverlayActor->SetPickable(0);
383 mOverlayActor->SetVisibility(true);
384 mOverlayActor->SetOpacity(0.5);
385 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
386 mOverlayActor->GetMapper()->BorderOn();
390 //stupid but necessary : the Overlay need to be rendered before fusion
392 this->GetRenderer()->RemoveActor(mFusionActor);
393 this->GetRenderer()->AddActor(mOverlayActor);
394 this->GetRenderer()->AddActor(mFusionActor);
396 this->GetRenderer()->AddActor(mOverlayActor);
398 //Synchronize orientation and slice
399 AdjustResliceToSliceOrientation(mOverlayReslice);
400 this->UpdateDisplayExtent();
401 this->SetTSlice(mCurrentTSlice);
404 //------------------------------------------------------------------------------
407 //------------------------------------------------------------------------------
408 void vvSlicer::SetFusion(vvImage::Pointer fusion)
410 if (fusion->GetVTKImages().size()) {
413 if (!mFusionReslice) {
414 mFusionReslice = vtkSmartPointer<vtkImageReslice>::New();
415 mFusionReslice->SetInterpolationModeToLinear();
416 mFusionReslice->AutoCropOutputOn();
417 mFusionReslice->SetBackgroundColor(-1000,-1000,-1000,1);
419 mFusionReslice->SetResliceTransform(mFusion->GetTransform());
420 mFusionReslice->SetInput(0, mFusion->GetFirstVTKImageData());
423 mFusionMapper = vtkSmartPointer<vtkImageMapToColors>::New();
425 vtkSmartPointer<vtkLookupTable> lut = vtkLookupTable::New();
427 lut->SetValueRange(0, 1);
428 lut->SetSaturationRange(0, 0);
430 mFusionMapper->SetLookupTable(lut);
431 mFusionMapper->SetInput(mFusionReslice->GetOutput());
434 mFusionActor = vtkSmartPointer<vtkImageActor>::New();
435 mFusionActor->SetInput(mFusionMapper->GetOutput());
436 mFusionActor->SetPickable(0);
437 mFusionActor->SetVisibility(true);
438 mFusionActor->SetOpacity(0.7);
439 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
440 mFusionActor->GetMapper()->BorderOn();
442 this->GetRenderer()->AddActor(mFusionActor);
445 //Synchronize orientation and slice
446 AdjustResliceToSliceOrientation(mFusionReslice);
447 this->UpdateDisplayExtent();
448 this->SetTSlice(mCurrentTSlice);
451 //------------------------------------------------------------------------------
454 //------------------------------------------------------------------------------
455 bool vvSlicer::GetActorVisibility(const std::string& actor_type, int overlay_index)
458 if (actor_type == "image") {
459 vis = this->ImageActor->GetVisibility();
461 else if (actor_type == "vector") {
462 vis = this->mVFActor->GetVisibility();
464 else if (actor_type == "overlay") {
465 vis = this->mOverlayActor->GetVisibility();
467 else if (actor_type == "fusion") {
468 vis = this->mFusionActor->GetVisibility();
470 else if (actor_type == "contour")
471 vis = this->mSurfaceCutActors[overlay_index]->GetActor()->GetVisibility();
475 //------------------------------------------------------------------------------
477 //------------------------------------------------------------------------------
478 void vvSlicer::SetActorVisibility(const std::string& actor_type, int overlay_index ,bool vis)
480 if (actor_type == "image") {
481 this->ImageActor->SetVisibility(vis);
483 else if (actor_type == "vector") {
484 this->mVFActor->SetVisibility(vis);
486 else if (actor_type == "overlay") {
487 this->mOverlayActor->SetVisibility(vis);
489 else if (actor_type == "fusion") {
490 this->mFusionActor->SetVisibility(vis);
492 else if (actor_type == "contour")
493 this->mSurfaceCutActors[overlay_index]->GetActor()->SetVisibility(vis);
494 UpdateDisplayExtent();
496 //------------------------------------------------------------------------------
498 //------------------------------------------------------------------------------
499 void vvSlicer::SetVF(vvImage::Pointer vf)
501 if (vf->GetVTKImages().size()) {
505 mAAFilter= vtkSmartPointer<vtkAssignAttribute>::New();
506 mVOIFilter = vtkSmartPointer<vtkExtractVOI>::New();
507 mVOIFilter->SetSampleRate(mSubSampling,mSubSampling,mSubSampling);
509 mVOIFilter->SetInput(vf->GetFirstVTKImageData());
510 mAAFilter->SetInput(mVOIFilter->GetOutput());
511 ///This tells VTK to use the scalar (pixel) data of the image to draw the little arrows
512 mAAFilter->Assign(vtkDataSetAttributes::SCALARS, vtkDataSetAttributes::VECTORS, vtkAssignAttribute::POINT_DATA);
515 mArrow = vtkSmartPointer<vvGlyphSource>::New();
516 mArrow->SetGlyphTypeToSpecificArrow();
517 mArrow->SetScale(mScale);
520 // Glyph the gradient vector (with arrows)
522 mGlyphFilter = vtkSmartPointer<vvGlyph2D>::New();
523 mGlyphFilter->SetInput(mAAFilter->GetOutput());
524 mGlyphFilter->SetSource(mArrow->GetOutput());
525 mGlyphFilter->ScalingOn();
526 mGlyphFilter->SetScaleModeToScaleByVector();
527 mGlyphFilter->OrientOn();
528 mGlyphFilter->SetVectorModeToUseVector();
529 mGlyphFilter->SetColorModeToColorByVector();
532 mVFColorLUT = vtkSmartPointer<vtkLookupTable>::New();
534 double mVFColorHSV[3];
535 vtkMath::RGBToHSV(mVFColor, mVFColorHSV);
536 mVFColorLUT->SetHueRange(mVFColorHSV[0], mVFColorHSV[0]);
537 mVFColorLUT->SetSaturationRange(mVFColorHSV[1],mVFColorHSV[1]);
538 mVFColorLUT->SetValueRange(mVFColorHSV[2], mVFColorHSV[2]);
541 mVFMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
542 mVFMapper->SetInput(mGlyphFilter->GetOutput());
543 mVFMapper->ImmediateModeRenderingOn();
544 mVFMapper->SetLookupTable(mVFColorLUT);
547 mVFActor = vtkSmartPointer<vtkActor>::New();
548 mVFActor->SetMapper(mVFMapper);
549 mVFActor->SetPickable(0);
550 mVFActor->GetProperty()->SetLineWidth(mVFWidth);
551 this->UpdateDisplayExtent();
552 this->GetRenderer()->AddActor(mVFActor);
555 SetTSlice(mCurrentTSlice);
558 //------------------------------------------------------------------------------
561 //------------------------------------------------------------------------------
562 void vvSlicer::SetLandmarks(vvLandmarks* landmarks)
564 mLandmarks = landmarks;
568 mCross = vtkSmartPointer<vtkCursor3D>::New();
569 mCross->SetFocalPoint(0.0,0.0,0.0);
570 mCross->SetModelBounds(-10,10,-10,10,-10,10);
575 mLandGlyph = vtkSmartPointer<vtkGlyph3D>::New();
576 mLandGlyph->SetSource(mCross->GetOutput());
577 mLandGlyph->SetInput(landmarks->GetOutput());
578 //mLandGlyph->SetIndexModeToScalar();
579 mLandGlyph->SetRange(0,1);
580 mLandGlyph->ScalingOff();
582 mLandGlyph->SetColorModeToColorByScalar();
585 mClipBox = vtkSmartPointer<vtkBox>::New();
587 mLandClipper = vtkSmartPointer<vtkClipPolyData>::New();
588 mLandClipper->InsideOutOn();
589 mLandClipper->SetInput(mLandGlyph->GetOutput());
590 mLandClipper->SetClipFunction(mClipBox);
593 mLandMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
594 mLandMapper->SetInputConnection(mLandClipper->GetOutputPort());
595 //mLandMapper->ScalarVisibilityOff();
598 mLandActor = vtkSmartPointer<vtkActor>::New();
599 mLandActor->SetMapper(mLandMapper);
600 mLandActor->GetProperty()->SetColor(255,10,212);
601 mLandActor->SetPickable(0);
602 mLandActor->SetVisibility(true);
603 this->UpdateDisplayExtent();
604 this->GetRenderer()->AddActor(mLandActor);
607 //------------------------------------------------------------------------------
609 //------------------------------------------------------------------------------
610 //FIXME: this function leaks memory, we should fix it someday :)
611 void vvSlicer::RemoveActor(const std::string& actor_type, int overlay_index)
613 if (actor_type == "vector") {
614 Renderer->RemoveActor(mVFActor);
623 if (actor_type == "overlay") {
624 Renderer->RemoveActor(mOverlayActor);
626 mOverlayActor = NULL;
627 mOverlayMapper = NULL;
629 if (actor_type == "fusion") {
630 Renderer->RemoveActor(mFusionActor);
633 mFusionMapper = NULL;
635 if (actor_type == "contour") {
636 Renderer->RemoveActor(this->mSurfaceCutActors[overlay_index]->GetActor());
637 mSurfaceCutActors.erase(mSurfaceCutActors.begin()+overlay_index);
640 //------------------------------------------------------------------------------
643 //------------------------------------------------------------------------------
644 void vvSlicer::SetVFSubSampling(int sub)
647 mVOIFilter->SetSampleRate(mSubSampling,mSubSampling,mSubSampling);
650 UpdateDisplayExtent();
653 //------------------------------------------------------------------------------
656 //------------------------------------------------------------------------------
657 void vvSlicer::SetVFScale(int scale)
661 mArrow->SetScale(mScale);
662 UpdateDisplayExtent();
665 //------------------------------------------------------------------------------
667 //------------------------------------------------------------------------------
668 void vvSlicer::SetVFWidth(int width)
672 mVFActor->GetProperty()->SetLineWidth(mVFWidth);
673 UpdateDisplayExtent();
676 //------------------------------------------------------------------------------
679 //------------------------------------------------------------------------------
680 void vvSlicer::SetVFLog(int log)
684 mGlyphFilter->SetUseLog(mVFLog);
685 mGlyphFilter->Modified();
687 UpdateDisplayExtent();
690 //------------------------------------------------------------------------------
693 //------------------------------------------------------------------------------
694 void vvSlicer::SetTSlice(int t)
698 else if ((unsigned int)t >= mImage->GetVTKImages().size())
699 t = mImage->GetVTKImages().size() -1;
702 mImageReslice->SetInput( mImage->GetVTKImages()[mCurrentTSlice] );
703 if (mVF && mVFActor->GetVisibility()) {
704 if (mVF->GetVTKImages().size() > (unsigned int)mCurrentTSlice)
705 mVOIFilter->SetInput(mVF->GetVTKImages()[mCurrentTSlice]);
707 if (mOverlay && mOverlayActor->GetVisibility()) {
708 if (mOverlay->GetVTKImages().size() > (unsigned int)mCurrentTSlice)
709 mOverlayReslice->SetInput( mOverlay->GetVTKImages()[mCurrentTSlice] );
711 if (mFusion && mFusionActor->GetVisibility()) {
712 if (mFusion->GetVTKImages().size() > (unsigned int)mCurrentTSlice)
713 mFusionReslice->SetInput( mFusion->GetVTKImages()[mCurrentTSlice]);
715 if (mSurfaceCutActors.size() > 0)
716 for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
717 i!=mSurfaceCutActors.end(); i++)
718 (*i)->SetTimeSlice(mCurrentTSlice);
719 UpdateDisplayExtent();
721 //------------------------------------------------------------------------------
724 //------------------------------------------------------------------------------
725 int vvSlicer::GetTSlice()
727 return mCurrentTSlice;
729 //------------------------------------------------------------------------------
731 //------------------------------------------------------------------------------
732 void vvSlicer::SetSliceOrientation(int orientation)
734 //if 2D image, force to watch in Axial View
736 this->GetInput()->GetWholeExtent(extent);
737 if (extent[5]-extent[4] <= 2)
738 orientation = vtkImageViewer2::SLICE_ORIENTATION_XY;
740 if (orientation < vtkImageViewer2::SLICE_ORIENTATION_YZ ||
741 orientation > vtkImageViewer2::SLICE_ORIENTATION_XY) {
742 vtkErrorMacro("Error - invalid slice orientation " << orientation);
746 this->SliceOrientation = orientation;
749 AdjustResliceToSliceOrientation(mFusionReslice);
752 AdjustResliceToSliceOrientation(mOverlayReslice);
755 int *range = this->GetSliceRange();
757 this->Slice = static_cast<int>((range[0] + range[1]) * 0.5);
759 // Go to current cursor position
760 // double* cursorPos = GetCursorPosition();
761 // DDV(cursorPos, 3);
762 // SetCurrentPosition(cursorPos[0],cursorPos[1],cursorPos[2],cursorPos[3]);
764 this->UpdateOrientation();
765 this->UpdateDisplayExtent();
767 if (this->Renderer && this->GetInput()) {
768 double scale = this->Renderer->GetActiveCamera()->GetParallelScale();
769 this->Renderer->ResetCamera();
770 this->Renderer->GetActiveCamera()->SetParallelScale(scale);
775 //----------------------------------------------------------------------------
777 //------------------------------------------------------------------------------
778 // This function ensures that we sample the slices of a vtkImageReslice filter
779 // in the direction of the slicer (SliceOrientation) similarly as mImageReslice.
780 // In other words, we change the grid of the reslice in the same way as the grid
781 // of the displayed image in the slicing direction.
782 void vvSlicer::AdjustResliceToSliceOrientation(vtkImageReslice *reslice)
784 // Reset autocrop and update output information
785 reslice->SetOutputOriginToDefault();
786 reslice->SetOutputSpacingToDefault();
787 reslice->GetOutput()->UpdateInformation();
789 // Ge new origin / spacing
792 reslice->GetOutput()->GetOrigin(origin);
793 reslice->GetOutput()->GetSpacing(spacing);
795 // Use similar spacing as the image in the direction SliceOrientation
796 spacing[this->SliceOrientation] = mImageReslice->GetOutput()->GetSpacing()[this->SliceOrientation];
798 // Modify origin to be on the image grid in the direction SliceOrientation in 3 steps
799 // Step 1: from world coordinates to image coordinates
800 origin[this->SliceOrientation] -= mImageReslice->GetOutput()->GetOrigin()[this->SliceOrientation];
801 origin[this->SliceOrientation] /= mImageReslice->GetOutput()->GetSpacing()[this->SliceOrientation];
802 // Step 2: round to superior grid positionInc
803 origin[this->SliceOrientation] = itk::Math::Ceil<double>(origin[this->SliceOrientation]);
804 // Step 3: back to world coordinates
805 origin[this->SliceOrientation] *= mImageReslice->GetOutput()->GetSpacing()[this->SliceOrientation];
806 origin[this->SliceOrientation] += mImageReslice->GetOutput()->GetOrigin()[this->SliceOrientation];
808 // Set new spacing and origin
809 reslice->SetOutputOrigin(origin);
810 reslice->SetOutputSpacing(spacing);
811 reslice->UpdateInformation();
812 reslice->GetOutput()->UpdateInformation();
814 //------------------------------------------------------------------------------
816 //----------------------------------------------------------------------------
817 int * vvSlicer::GetExtent(){
819 if (mUseReducedExtent) {
820 w_ext = mReducedExtent;
821 } else w_ext = GetInput()->GetWholeExtent();
824 //----------------------------------------------------------------------------
827 //----------------------------------------------------------------------------
828 int vvSlicer::GetOrientation()
830 return this->SliceOrientation;
832 //----------------------------------------------------------------------------
835 //----------------------------------------------------------------------------
836 void vvSlicer::UpdateDisplayExtent()
838 vtkImageData *input = this->GetInput();
839 if (!input || !this->ImageActor) {
842 input->UpdateInformation();
844 // Local copy of extent
846 int* ext = GetExtent();
847 copyExtent(ext, w_ext);
849 int s = this->Slice > ext[this->SliceOrientation*2+1] ? ext[this->SliceOrientation*2 + 1] : this->Slice;
850 w_ext[ this->SliceOrientation*2 ] = s;
851 w_ext[ this->SliceOrientation*2+1 ] = s;
854 this->ImageActor->SetDisplayExtent(w_ext);
856 // Overlay image actor
857 if (mOverlay && mOverlayActor->GetVisibility()) {
858 AdjustResliceToSliceOrientation(mOverlayReslice);
860 this->ConvertImageToImageDisplayExtent(input, w_ext, mOverlayReslice->GetOutput(), overExtent);
861 ClipDisplayedExtent(overExtent, mOverlayMapper->GetInput()->GetWholeExtent());
862 mOverlayActor->SetDisplayExtent( overExtent );
865 // Fusion image actor
866 if (mFusion && mFusionActor->GetVisibility()) {
867 AdjustResliceToSliceOrientation(mFusionReslice);
869 this->ConvertImageToImageDisplayExtent(input, w_ext, mFusionReslice->GetOutput(), fusExtent);
870 ClipDisplayedExtent(fusExtent, mFusionMapper->GetInput()->GetWholeExtent());
871 mFusionActor->SetDisplayExtent(fusExtent);
874 // Vector field actor
875 double* camera = Renderer->GetActiveCamera()->GetPosition();
876 double* image_bounds = ImageActor->GetBounds();
877 double position[3] = {0, 0, 0};
878 position[this->SliceOrientation] = image_bounds[this->SliceOrientation*2];
880 //print_vector<double, 6>("camera", camera);
881 //print_vector<double, 6>("image_bounds", image_bounds);
882 //print_vector<double, 3>("position", position);
884 // find where to place the VF actor. to deal with
885 // z-buffer issues, the VF is placed right in front of the image,
886 // subject to a small offset. the position actually depends on the
887 // the location of the camera relative to the image.
889 if (camera[this->SliceOrientation] < image_bounds[this->SliceOrientation*2])
892 if (mVF && mVFActor->GetVisibility()) {
894 mVF->GetVTKImages()[0]->UpdateInformation();
895 this->ConvertImageToImageDisplayExtent(input, w_ext, mVF->GetVTKImages()[0], vfExtent);
896 ClipDisplayedExtent(vfExtent, mVOIFilter->GetInput()->GetWholeExtent());
897 mVOIFilter->SetVOI(vfExtent);
898 int orientation[3] = {1,1,1};
899 orientation[this->SliceOrientation] = 0;
900 mGlyphFilter->SetOrientation(orientation[0], orientation[1], orientation[2]);
903 position[this->SliceOrientation] += offset;
904 mVFActor->SetPosition(position);
911 for(unsigned int i=0; i<6; i++)
912 bounds[i] = ImageActor->GetBounds()[i];
913 bounds[ this->SliceOrientation*2 ] = ImageActor->GetBounds()[ this->SliceOrientation*2 ]-fabs(this->GetInput()->GetSpacing()[this->SliceOrientation]);
914 bounds[ this->SliceOrientation*2+1 ] = ImageActor->GetBounds()[ this->SliceOrientation*2+1 ]+fabs(this->GetInput()->GetSpacing()[this->SliceOrientation]);
915 mClipBox->SetBounds(bounds);
919 position[this->SliceOrientation] = offset;
920 mLandActor->SetPosition(position);
923 // Figure out the correct clipping range
924 if (this->Renderer) {
925 if (this->InteractorStyle &&
926 this->InteractorStyle->GetAutoAdjustCameraClippingRange()) {
927 this->Renderer->ResetCameraClippingRange();
929 vtkCamera *cam = this->Renderer->GetActiveCamera();
932 this->ImageActor->GetBounds(bounds);
933 double spos = (double)bounds[this->SliceOrientation * 2];
934 double cpos = (double)cam->GetPosition()[this->SliceOrientation];
935 double range = fabs(spos - cpos);
936 double *spacing = input->GetSpacing();
937 double sumSpacing = spacing[0] + spacing[1] + spacing[2];
938 cam->SetClippingRange(range - sumSpacing, range + sumSpacing);
944 //----------------------------------------------------------------------------
946 //----------------------------------------------------------------------------
947 void vvSlicer::ConvertImageToImageDisplayExtent(vtkImageData *sourceImage, const int sourceExtent[6],
948 vtkImageData *targetImage, int targetExtent[6])
951 for(unsigned int i=0; i<6; i++) {
952 // From source voxel coordinates to world coordinates
953 dExtents[i] = sourceImage->GetOrigin()[i/2] + sourceImage->GetSpacing()[i/2] * sourceExtent[i];
955 // From world coordinates to floating point target voxel coordinates
956 dExtents[i] = (dExtents[i]- targetImage->GetOrigin()[i/2]) / targetImage->GetSpacing()[i/2];
959 //targetExtent[i] = itk::Math::Round<double>(dExtents[i]);
960 targetExtent[i] = itk::Math::Floor<double>(dExtents[i]);
963 //----------------------------------------------------------------------------
965 //----------------------------------------------------------------------------
966 void vvSlicer::ClipDisplayedExtent(int extent[6], int refExtent[6])
971 //2D overlay on 3D image specific case
972 if (refExtent[4] == refExtent[5]) {
974 extent[4] = refExtent[4];
975 extent[5] = refExtent[5];
978 for (int i = 0; i < maxBound; i = i+2) {
979 //if we are totally outside the image
980 if ( extent[i] > refExtent[i+1] || extent[i+1] < refExtent[i] ) {
984 //crop to the limit of the image
985 extent[i] = (extent[i] > refExtent[i]) ? extent[i] : refExtent[i];
986 extent[i] = (extent[i] < refExtent[i+1]) ? extent[i] : refExtent[i+1];
987 extent[i+1] = (extent[i+1] > refExtent[i]) ? extent[i+1] : refExtent[i];
988 extent[i+1] = (extent[i+1] < refExtent[i+1]) ? extent[i+1] : refExtent[i+1];
991 for (int i = 0; i < maxBound; i = i+2) {
992 extent[i] = refExtent[i];
993 extent[i+1] = refExtent[i];
996 //----------------------------------------------------------------------------
999 //----------------------------------------------------------------------------
1000 void vvSlicer::UpdateOrientation()
1002 // Set the camera position
1003 vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
1005 switch (this->SliceOrientation) {
1006 case vtkImageViewer2::SLICE_ORIENTATION_XY:
1007 cam->SetFocalPoint(0,0,0);
1008 cam->SetPosition(0,0,-1); // -1 if medical ?
1009 cam->SetViewUp(0,-1,0);
1012 case vtkImageViewer2::SLICE_ORIENTATION_XZ:
1013 cam->SetFocalPoint(0,0,0);
1014 cam->SetPosition(0,-1,0); // 1 if medical ?
1015 cam->SetViewUp(0,0,1);
1018 case vtkImageViewer2::SLICE_ORIENTATION_YZ:
1019 cam->SetFocalPoint(0,0,0);
1020 cam->SetPosition(-1,0,0); // -1 if medical ?
1021 cam->SetViewUp(0,0,1);
1026 //----------------------------------------------------------------------------
1029 //----------------------------------------------------------------------------
1030 void vvSlicer::SetOpacity(double s)
1032 this->GetImageActor()->SetOpacity(s);
1034 //----------------------------------------------------------------------------
1037 //----------------------------------------------------------------------------
1038 void vvSlicer::SetRenderWindow(int orientation, vtkRenderWindow * rw)
1040 this->Superclass::SetRenderWindow(rw);
1041 this->SetupInteractor(rw->GetInteractor());
1042 ca->SetImageActor(this->GetImageActor());
1043 ca->SetWindowLevel(this->GetWindowLevel());
1044 ca->SetText(2, "<slice>");
1045 ca->SetText(3, "<window>\n<level>");
1057 crossCursor->SetModelBounds(bounds);
1058 this->GetRenderer()->AddActor(pdmA);
1059 this->GetRenderer()->AddActor(ca);
1060 this->GetRenderer()->ResetCamera();
1062 //this is just a mapping between the labeling of the orientations presented to the user and
1063 //the one used by vtk
1064 SetSliceOrientation(2-(orientation%3));
1067 //----------------------------------------------------------------------------
1070 //----------------------------------------------------------------------------
1071 void vvSlicer::ResetCamera()
1073 this->GetRenderer()->ResetCamera();
1075 //----------------------------------------------------------------------------
1078 //----------------------------------------------------------------------------
1079 void vvSlicer::SetDisplayMode(bool i)
1081 this->GetRenderer()->SetDraw(i);
1083 UpdateDisplayExtent();
1085 //----------------------------------------------------------------------------
1088 //----------------------------------------------------------------------------
1089 void vvSlicer::FlipHorizontalView()
1091 vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
1093 double *position = cam->GetPosition();
1094 double factor[3] = {1, 1, 1};
1095 factor[this->SliceOrientation] = -1;
1096 cam->SetPosition(factor[0]*position[0],factor[1]*position[1],factor[2]*position[2]);
1098 /* switch (this->SliceOrientation) {
1099 case vtkImageViewer2::SLICE_ORIENTATION_XY:
1100 cam->SetPosition(position[0],position[1],-position[2]);
1103 case vtkImageViewer2::SLICE_ORIENTATION_XZ:
1104 cam->SetPosition(position[0],-position[1],position[2]);
1107 case vtkImageViewer2::SLICE_ORIENTATION_YZ:
1108 cam->SetPosition(-position[0],position[1],position[2]);
1112 this->Renderer->ResetCameraClippingRange();
1113 this->UpdateDisplayExtent();
1116 //----------------------------------------------------------------------------
1119 //----------------------------------------------------------------------------
1120 void vvSlicer::FlipVerticalView()
1122 vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
1124 FlipHorizontalView();
1125 double *viewup = cam->GetViewUp();
1126 cam->SetViewUp(-viewup[0],-viewup[1],-viewup[2]);
1127 this->UpdateDisplayExtent();
1130 //----------------------------------------------------------------------------
1133 //----------------------------------------------------------------------------
1134 void vvSlicer::SetColorWindow(double window)
1136 vtkLookupTable* LUT = static_cast<vtkLookupTable*>(this->GetWindowLevel()->GetLookupTable());
1138 double level = this->GetWindowLevel()->GetLevel();
1139 LUT->SetTableRange(level-fabs(window)/2,level+fabs(window)/2);
1142 this->vtkImageViewer2::SetColorWindow(window);
1144 //----------------------------------------------------------------------------
1146 //----------------------------------------------------------------------------
1147 void vvSlicer::SetColorLevel(double level)
1149 vtkLookupTable* LUT = static_cast<vtkLookupTable*>(this->GetWindowLevel()->GetLookupTable());
1151 double window = this->GetWindowLevel()->GetWindow();
1152 LUT->SetTableRange(level-fabs(window)/2,level+fabs(window)/2);
1155 this->vtkImageViewer2::SetColorLevel(level);
1157 //----------------------------------------------------------------------------
1159 //----------------------------------------------------------------------------
1160 double vvSlicer::GetOverlayColorWindow()
1163 return mOverlayMapper->GetWindow();
1167 //----------------------------------------------------------------------------
1169 //----------------------------------------------------------------------------
1170 double vvSlicer::GetOverlayColorLevel()
1173 return mOverlayMapper->GetLevel();
1177 //----------------------------------------------------------------------------
1179 //----------------------------------------------------------------------------
1180 void vvSlicer::SetOverlayColorWindow(double window)
1182 mOverlayMapper->SetWindow(window);
1184 //----------------------------------------------------------------------------
1186 //----------------------------------------------------------------------------
1187 void vvSlicer::SetOverlayColorLevel(double level)
1189 mOverlayMapper->SetLevel(level);
1191 //----------------------------------------------------------------------------
1193 //----------------------------------------------------------------------------
1194 // Returns the min an the max value in a 41x41 region around the mouse pointer
1195 void vvSlicer::GetExtremasAroundMousePointer(double & min, double & max, vtkImageData *image, vtkTransform *transform)
1197 //Get mouse pointer position in view coordinates
1200 for(int i=0; i<3; i++) {
1201 corner1[i] = mCurrent[i];
1202 corner2[i] = mCurrent[i];
1205 this->Renderer->WorldToView(corner1[0], corner1[1], corner1[2]);
1206 this->Renderer->WorldToView(corner2[0], corner2[1], corner2[2]);
1208 // In view coordinates, x is the slicer width and y is the slicer height are the in-plane axis
1210 this->Renderer->GetTiledSize(&w, &h);
1211 corner1[0] -= 0.2*h/(double)w;
1212 corner2[0] += 0.2*h/(double)w;
1215 this->Renderer->ViewToWorld(corner1[0], corner1[1], corner1[2]);
1216 this->Renderer->ViewToWorld(corner2[0], corner2[1], corner2[2]);
1218 //Convert to image pixel coordinates (rounded)
1219 transform->TransformPoint(corner1, corner1);
1220 transform->TransformPoint(corner2, corner2);
1221 int iLocalExtents[6];
1222 for(int i=0; i<3; i++) {
1223 corner1[i] = (corner1[i] - image->GetOrigin()[i])/image->GetSpacing()[i];
1224 corner2[i] = (corner2[i] - image->GetOrigin()[i])/image->GetSpacing()[i];
1226 iLocalExtents[i*2 ] = lrint(corner1[i]);
1227 iLocalExtents[i*2+1] = lrint(corner2[i]);
1229 if(iLocalExtents[i*2 ]>iLocalExtents[i*2+1])
1230 std::swap(iLocalExtents[i*2], iLocalExtents[i*2+1]);
1233 vtkSmartPointer<vtkExtractVOI> voiFilter = vtkSmartPointer<vtkExtractVOI>::New();
1234 voiFilter->SetInput(image);
1235 voiFilter->SetVOI(iLocalExtents);
1236 voiFilter->Update();
1237 if (!voiFilter->GetOutput()->GetNumberOfPoints()) {
1243 vtkSmartPointer<vtkImageAccumulate> accFilter = vtkSmartPointer<vtkImageAccumulate>::New();
1244 accFilter->SetInput(voiFilter->GetOutput());
1245 accFilter->Update();
1247 min = *(accFilter->GetMin());
1248 max = *(accFilter->GetMax());
1250 //----------------------------------------------------------------------------
1252 //----------------------------------------------------------------------------
1253 double vvSlicer::GetScalarComponentAsDouble(vtkImageData *image, double X, double Y, double Z, int &ix, int &iy, int &iz, int component)
1258 if (ix < image->GetWholeExtent()[0] ||
1259 ix > image->GetWholeExtent()[1] ||
1260 iy < image->GetWholeExtent()[2] ||
1261 iy > image->GetWholeExtent()[3] ||
1262 iz < image->GetWholeExtent()[4] ||
1263 iz > image->GetWholeExtent()[5] )
1264 return std::numeric_limits<double>::quiet_NaN();
1266 image->SetUpdateExtent(ix, ix, iy, iy, iz, iz);
1268 return image->GetScalarComponentAsDouble(ix, iy, iz, component);
1270 //----------------------------------------------------------------------------
1272 //----------------------------------------------------------------------------
1273 void vvSlicer::Render()
1275 if (this->mFusion && mFusionActor->GetVisibility() && showFusionLegend) {
1276 legend->SetLookupTable(this->GetFusionMapper()->GetLookupTable());
1277 legend->UseOpacityOn();
1278 legend->SetVisibility(1);
1280 else if (this->GetWindowLevel()->GetLookupTable() && !this->mOverlay) {
1281 legend->SetLookupTable(this->GetWindowLevel()->GetLookupTable());
1282 legend->UseOpacityOff();
1283 legend->SetVisibility(1);
1284 } else legend->SetVisibility(0);
1286 if (ca->GetVisibility()) {
1287 std::stringstream worldPos;
1289 mConcatenatedTransform->TransformPoint(mCurrent, pt);
1290 double X = (pt[0] - mImage->GetVTKImages()[mCurrentTSlice]->GetOrigin()[0])/mImage->GetVTKImages()[mCurrentTSlice]->GetSpacing()[0];
1291 double Y = (pt[1] - mImage->GetVTKImages()[mCurrentTSlice]->GetOrigin()[1])/mImage->GetVTKImages()[mCurrentTSlice]->GetSpacing()[1];
1292 double Z = (pt[2] - mImage->GetVTKImages()[mCurrentTSlice]->GetOrigin()[2])/mImage->GetVTKImages()[mCurrentTSlice]->GetSpacing()[2];
1294 if (X >= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[0]-0.5 &&
1295 X <= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[1]+0.5 &&
1296 Y >= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[2]-0.5 &&
1297 Y <= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[3]+0.5 &&
1298 Z >= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[4]-0.5 &&
1299 Z <= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[5]+0.5) {
1303 double value = this->GetScalarComponentAsDouble(mImage->GetVTKImages()[mCurrentTSlice], X, Y, Z, ix, iy, iz);
1305 if(ImageActor->GetVisibility())
1306 worldPos << "data value : " << value << std::endl;
1308 worldPos << "mm : " << lrint(mCurrentBeforeSlicingTransform[0]) << ' '
1309 << lrint(mCurrentBeforeSlicingTransform[1]) << ' '
1310 << lrint(mCurrentBeforeSlicingTransform[2]) << ' '
1313 worldPos << "pixel : " << ix << ' '
1319 ca->SetText(1,worldPos.str().c_str());
1322 if (pdmA->GetVisibility()) {
1323 double x = mCursor[0];
1324 double y = mCursor[1];
1325 double z = mCursor[2];
1326 double xCursor = (x - this->GetInput()->GetOrigin()[0])/this->GetInput()->GetSpacing()[0];
1327 double yCursor = (y - this->GetInput()->GetOrigin()[1])/this->GetInput()->GetSpacing()[1];
1328 double zCursor = (z - this->GetInput()->GetOrigin()[2])/this->GetInput()->GetSpacing()[2];
1330 if (xCursor >= this->GetImageActor()->GetDisplayExtent()[0] &&
1331 xCursor < this->GetImageActor()->GetDisplayExtent()[1]+1 &&
1332 yCursor >= this->GetImageActor()->GetDisplayExtent()[2] &&
1333 yCursor < this->GetImageActor()->GetDisplayExtent()[3]+1 &&
1334 zCursor >= this->GetImageActor()->GetDisplayExtent()[4] &&
1335 zCursor < this->GetImageActor()->GetDisplayExtent()[5]+1 ) {
1336 vtkRenderer * renderer = this->Renderer;
1338 renderer->WorldToView(x,y,z);
1339 renderer->ViewToNormalizedViewport(x,y,z);
1340 renderer->NormalizedViewportToViewport(x,y);
1341 renderer->ViewportToNormalizedDisplay(x,y);
1342 renderer->NormalizedDisplayToDisplay(x,y);
1343 crossCursor->SetFocalPoint(x,y,z);
1345 crossCursor->SetFocalPoint(-1,-1,z);
1349 if (mOverlay && mOverlayActor->GetVisibility()) {
1350 if(mLinkOverlayWindowLevel) {
1351 mOverlayMapper->SetWindow(this->GetColorWindow());
1352 mOverlayMapper->SetLevel(this->GetColorLevel());
1354 mOverlayMapper->GetOutput()->SetUpdateExtent(mOverlayActor->GetDisplayExtent());
1355 mOverlayMapper->GetOutput()->Update();
1356 mOverlayMapper->Update();
1361 this->GetRenderWindow()->Render();
1363 //----------------------------------------------------------------------------
1366 //----------------------------------------------------------------------------
1367 void vvSlicer::UpdateCursorPosition()
1369 pdmA->SetVisibility(true);
1370 mCursor[0] = mCurrent[0];
1371 mCursor[1] = mCurrent[1];
1372 mCursor[2] = mCurrent[2];
1373 mCursor[3] = mCurrentTSlice;
1375 //----------------------------------------------------------------------------
1378 //----------------------------------------------------------------------------
1379 void vvSlicer::UpdateLandmarks()
1381 vtkPolyData *pd = static_cast<vtkPolyData*>(mLandClipper->GetInput());
1382 if (pd->GetPoints()) {
1383 mLandGlyph->SetRange(0,1);
1384 mLandGlyph->Modified();
1385 mLandGlyph->Update();
1387 mClipBox->Modified();
1388 mLandClipper->Update();
1389 mLandMapper->Update();
1393 //----------------------------------------------------------------------------
1396 //----------------------------------------------------------------------------
1397 void vvSlicer::SetSlice(int slice)
1399 int *range = this->GetSliceRange();
1401 if (slice < range[0]) {
1403 } else if (slice > range[1]) {
1408 if (this->Slice == slice) {
1412 this->Slice = slice;
1415 this->UpdateDisplayExtent();
1417 // Seems to work without this line
1420 //----------------------------------------------------------------------------
1423 //----------------------------------------------------------------------------
1424 void vvSlicer::SetContourSlice()
1426 if (mSurfaceCutActors.size() > 0)
1427 for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
1428 i!=mSurfaceCutActors.end(); i++) {
1430 (*i)->SetSlicingOrientation(this->SliceOrientation);
1431 (*i)->SetCutSlice((this->Slice)*this->GetImage()->GetSpacing()[this->SliceOrientation]+
1432 this->GetImage()->GetOrigin()[this->SliceOrientation]);
1435 //----------------------------------------------------------------------------
1438 //----------------------------------------------------------------------------
1439 void vvSlicer::ForceUpdateDisplayExtent()
1441 this->UpdateDisplayExtent();
1443 //----------------------------------------------------------------------------
1446 //----------------------------------------------------------------------------
1447 int* vvSlicer::GetDisplayExtent()
1449 return this->GetImageActor()->GetDisplayExtent();
1451 //----------------------------------------------------------------------------
1454 //----------------------------------------------------------------------------
1455 void vvSlicer::PrintSelf(ostream& os, vtkIndent indent)
1457 this->Superclass::PrintSelf(os, indent);
1459 //----------------------------------------------------------------------------
1461 //----------------------------------------------------------------------------
1462 void vvSlicer::SetVFColor(double r, double g, double b)
1464 double mVFColorHSV[3];
1469 vtkMath::RGBToHSV(mVFColor, mVFColorHSV);
1470 mVFColorLUT->SetHueRange(mVFColorHSV[0], mVFColorHSV[0]);
1471 mVFColorLUT->SetSaturationRange(mVFColorHSV[1],mVFColorHSV[1]);
1472 mVFColorLUT->SetValueRange(mVFColorHSV[2], mVFColorHSV[2]);