1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
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>
70 vtkCxxRevisionMacro(vvSlicer, "DummyRevision");
71 vtkStandardNewMacro(vvSlicer);
73 //------------------------------------------------------------------------------
76 this->UnInstallPipeline();
79 mUseReducedExtent = false;
81 mCurrent[0] = -VTK_DOUBLE_MAX;
82 mCurrent[1] = -VTK_DOUBLE_MAX;
83 mCurrent[2] = -VTK_DOUBLE_MAX;
85 mCursor[0] = -VTK_DOUBLE_MAX;
86 mCursor[1] = -VTK_DOUBLE_MAX;
87 mCursor[2] = -VTK_DOUBLE_MAX;
88 mCursor[3] = -VTK_DOUBLE_MAX;
95 std::string text = "F1 = sagital; F2 = coronal; F3 = axial\n";
96 text += "F5 = horizontal flip; F6 = vertical flip\n\n";
97 text += "0,1,2,3,4,5 : preset windowing\n";
98 text += "6,7,8,9 : preset colormap\n";
99 text += "z : local windowing\n";
100 text += "r : reset view\n";
101 text += "l : reload image\n";
102 text += "f : fly to mouse position\n";
103 text += "g : go to cross hair position\n\n";
104 text += "Up,down : change slice\n";
105 text += "Left,right : change tenporal slice\n\n";
106 text += "Scrollbar (or w/x) : zoom in/out\n";
107 text += "left button : synchronize all views\n";
108 text += "middle button : grab image\n";
109 text += "right button : change windowing\n";
111 crossCursor = vtkSmartPointer<vtkCursor2D>::New();
112 crossCursor->AllOff();
113 crossCursor->AxesOn();
114 crossCursor->SetTranslationMode(1);
115 crossCursor->SetRadius(2);
117 pdm = vtkSmartPointer<vtkPolyDataMapper2D>::New();
118 pdm->SetInput(crossCursor->GetOutput());
120 pdmA = vtkSmartPointer<vtkActor2D>::New();
121 pdmA->SetMapper(pdm);
122 pdmA->GetProperty()->SetColor(255,10,212);
123 pdmA->SetVisibility(0);
124 pdmA->SetPickable(0);
126 ca = vtkSmartPointer<vtkCornerAnnotation>::New();
127 ca->GetTextProperty()->SetColor(255,10,212);
128 ca->SetVisibility(1);
136 legend = vtkSmartPointer<vtkScalarBarActor>::New();
137 //legend->SetTitle("test!");
138 legend->SetPosition(0.82,0.18);
139 legend->SetWidth(0.1);
140 legend->SetVisibility(0);
141 legend->SetLabelFormat("%.1f");
142 this->GetRenderer()->AddActor(legend);
144 this->WindowLevel->Delete();
145 this->WindowLevel = vvImageMapToWLColors::New();
147 this->InstallPipeline();
149 //------------------------------------------------------------------------------
152 //------------------------------------------------------------------------------
153 vtkImageMapToWindowLevelColors* vvSlicer::GetOverlayMapper()
155 return mOverlayMapper.GetPointer();
157 //------------------------------------------------------------------------------
160 //------------------------------------------------------------------------------
161 vvBlendImageActor* vvSlicer::GetOverlayActor()
163 return mOverlayActor.GetPointer();
165 //------------------------------------------------------------------------------
168 //------------------------------------------------------------------------------
169 vtkImageMapToWindowLevelColors* vvSlicer::GetFusionMapper()
171 return mFusionMapper.GetPointer();
173 //------------------------------------------------------------------------------
176 //------------------------------------------------------------------------------
177 vtkImageActor* vvSlicer::GetFusionActor()
179 return mFusionActor.GetPointer();
181 //------------------------------------------------------------------------------
184 //------------------------------------------------------------------------------
185 vtkActor* vvSlicer::GetVFActor()
187 return mVFActor.GetPointer();
189 //------------------------------------------------------------------------------
192 //------------------------------------------------------------------------------
193 vtkCornerAnnotation* vvSlicer::GetAnnotation()
195 return ca.GetPointer();
197 //------------------------------------------------------------------------------
200 //------------------------------------------------------------------------------
201 void vvSlicer::EnableReducedExtent(bool b)
203 mUseReducedExtent = b;
205 //------------------------------------------------------------------------------
208 //------------------------------------------------------------------------------
209 void vvSlicer::SetReducedExtent(int * ext)
211 mReducedExtent = ext;
213 //------------------------------------------------------------------------------
216 //------------------------------------------------------------------------------
217 void vvSlicer::AddContour(vvMesh::Pointer contour,bool propagate)
220 mSurfaceCutActors.push_back(new vvMeshActor());
222 mSurfaceCutActors.back()->Init(contour,mCurrentTSlice,mVF);
224 mSurfaceCutActors.back()->Init(contour,mCurrentTSlice);
225 mSurfaceCutActors.back()->SetSlicingOrientation(SliceOrientation);
226 this->GetRenderer()->AddActor(mSurfaceCutActors.back()->GetActor());
230 //------------------------------------------------------------------------------
233 //------------------------------------------------------------------------------
234 void vvSlicer::ToggleContourSuperposition()
236 for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
237 i!=mSurfaceCutActors.end(); i++)
238 (*i)->ToggleSuperposition();
240 //------------------------------------------------------------------------------
243 //------------------------------------------------------------------------------
244 void vvSlicer::SetCursorColor(int r,int g, int b)
246 pdmA->GetProperty()->SetColor(r,g,b);
248 //------------------------------------------------------------------------------
251 //------------------------------------------------------------------------------
252 void vvSlicer::SetCursorVisibility(bool s)
254 pdmA->SetVisibility(s);
256 //------------------------------------------------------------------------------
259 //------------------------------------------------------------------------------
260 bool vvSlicer::GetCursorVisibility()
262 return pdmA->GetVisibility();
264 //------------------------------------------------------------------------------
267 //------------------------------------------------------------------------------
268 vvSlicer::~vvSlicer()
270 for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
271 i!=mSurfaceCutActors.end(); i++)
274 //------------------------------------------------------------------------------
277 //------------------------------------------------------------------------------
278 void vvSlicer::SetCurrentPosition(double x, double y, double z, int t)
285 //------------------------------------------------------------------------------
288 //------------------------------------------------------------------------------
289 void vvSlicer::SetImage(vvImage::Pointer image)
291 if (image->GetVTKImages().size()) {
293 this->Superclass::SetInput(image->GetVTKImages()[0]);
295 // Prevent crash when reload -> change slice if outside extent
297 this->GetInput()->GetWholeExtent(extent);
298 if (SliceOrientation == 0) {
299 if (Slice >= extent[1]) {
300 Slice = (extent[1]-extent[0])/2.0;
303 if (SliceOrientation == 1) {
304 if (Slice >= extent[3]) {
305 Slice = (extent[3]-extent[2])/2.0;
308 if (SliceOrientation == 2) {
309 if (Slice >= extent[5]) {
310 Slice = (extent[5]-extent[4])/2.0;
314 this->UpdateDisplayExtent();
316 ca->SetText(0,mFileName.c_str());
319 //------------------------------------------------------------------------------
322 //------------------------------------------------------------------------------
323 void vvSlicer::SetOverlay(vvImage::Pointer overlay)
325 if (overlay->GetVTKImages().size()) {
329 mOverlayMapper = vtkSmartPointer<vtkImageMapToWindowLevelColors>::New();
330 mOverlayMapper->SetInput(overlay->GetVTKImages()[0]);
332 if (!mOverlayActor) {
333 mOverlayActor = vtkSmartPointer<vvBlendImageActor>::New();
334 mOverlayActor->SetInput(mOverlayMapper->GetOutput());
335 mOverlayActor->SetPickable(0);
336 mOverlayActor->SetVisibility(false);
337 mOverlayActor->SetOpacity(0.5);
338 this->UpdateDisplayExtent();
341 //stupid but necessary : the Overlay need to be rendered before fusion
343 this->GetRenderer()->RemoveActor(mFusionActor);
344 this->GetRenderer()->AddActor(mOverlayActor);
345 this->GetRenderer()->AddActor(mFusionActor);
347 this->GetRenderer()->AddActor(mOverlayActor);
350 SetTSlice(mCurrentTSlice);
353 //------------------------------------------------------------------------------
356 //------------------------------------------------------------------------------
357 void vvSlicer::SetFusion(vvImage::Pointer fusion)
359 if (fusion->GetVTKImages().size()) {
363 mFusionMapper = vtkSmartPointer<vtkImageMapToWindowLevelColors>::New();
364 mFusionMapper->SetInput(fusion->GetVTKImages()[0]);
367 mFusionActor = vtkSmartPointer<vtkImageActor>::New();
368 mFusionActor->SetInput(mFusionMapper->GetOutput());
369 mFusionActor->SetPickable(0);
370 mFusionActor->SetVisibility(false);
371 mFusionActor->SetOpacity(0.7);
372 this->UpdateDisplayExtent();
373 this->GetRenderer()->AddActor(mFusionActor);
377 SetTSlice(mCurrentTSlice);
380 //------------------------------------------------------------------------------
383 //------------------------------------------------------------------------------
384 void vvSlicer::SetActorVisibility(const std::string& actor_type, int overlay_index ,bool vis)
386 if (actor_type == "vector") {
387 this->mVFActor->SetVisibility(vis);
389 if (actor_type == "overlay") {
390 this->mOverlayActor->SetVisibility(vis);
392 if (actor_type == "fusion") {
393 this->mFusionActor->SetVisibility(vis);
395 if (actor_type == "contour")
396 this->mSurfaceCutActors[overlay_index]->GetActor()->SetVisibility(vis);
397 UpdateDisplayExtent();
399 //------------------------------------------------------------------------------
402 //------------------------------------------------------------------------------
403 void vvSlicer::SetVF(vvImage::Pointer vf)
405 if (vf->GetVTKImages().size()) {
409 mAAFilter= vtkSmartPointer<vtkAssignAttribute>::New();
410 mVOIFilter = vtkSmartPointer<vtkExtractVOI>::New();
411 mVOIFilter->SetSampleRate(mSubSampling,mSubSampling,mSubSampling);
413 mVOIFilter->SetInput(vf->GetVTKImages()[0]);
414 mAAFilter->SetInput(mVOIFilter->GetOutput());
415 ///This tells VTK to use the scalar (pixel) data of the image to draw the little arrows
416 mAAFilter->Assign(vtkDataSetAttributes::SCALARS, vtkDataSetAttributes::VECTORS, vtkAssignAttribute::POINT_DATA);
419 mArrow = vtkSmartPointer<vvGlyphSource>::New();
420 mArrow->SetGlyphTypeToSpecificArrow();
421 mArrow->SetScale(mScale);
424 // Glyph the gradient vector (with arrows)
426 mGlyphFilter = vtkSmartPointer<vvGlyph2D>::New();
427 mGlyphFilter->SetInput(mAAFilter->GetOutput());
428 mGlyphFilter->SetSource(mArrow->GetOutput());
429 mGlyphFilter->ScalingOn();
430 mGlyphFilter->SetScaleModeToScaleByVector();
431 mGlyphFilter->OrientOn();
432 mGlyphFilter->SetVectorModeToUseVector();
433 mGlyphFilter->SetColorModeToColorByVector();
436 mVFMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
437 //mVFMapper->SetInputConnection(mGlyphFilter->GetOutputPort());
438 mVFMapper->SetInput(mGlyphFilter->GetOutput());
439 mVFMapper->ImmediateModeRenderingOn();
442 mVFActor = vtkSmartPointer<vtkActor>::New();
443 mVFActor->SetMapper(mVFMapper);
444 mVFActor->SetPickable(0);
445 mVFActor->GetProperty()->SetLineWidth(mVFWidth);
446 this->UpdateDisplayExtent();
447 this->GetRenderer()->AddActor(mVFActor);
450 SetTSlice(mCurrentTSlice);
453 //------------------------------------------------------------------------------
456 //------------------------------------------------------------------------------
457 void vvSlicer::SetLandmarks(vvLandmarks* landmarks)
459 mLandmarks = landmarks;
463 mCross = vtkSmartPointer<vtkCursor3D>::New();
464 mCross->SetFocalPoint(0.0,0.0,0.0);
465 mCross->SetModelBounds(-10,10,-10,10,-10,10);
470 mLandGlyph = vtkSmartPointer<vtkGlyph3D>::New();
471 mLandGlyph->SetSource(mCross->GetOutput());
472 mLandGlyph->SetInput(landmarks->GetOutput());
473 //mLandGlyph->SetIndexModeToScalar();
474 mLandGlyph->SetRange(0,1);
475 mLandGlyph->ScalingOff();
477 mLandGlyph->SetColorModeToColorByScalar();
480 mClipBox = vtkSmartPointer<vtkBox>::New();
482 mLandClipper = vtkSmartPointer<vtkClipPolyData>::New();
483 mLandClipper->InsideOutOn();
484 mLandClipper->SetInput(mLandGlyph->GetOutput());
485 mLandClipper->SetClipFunction(mClipBox);
488 mLandMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
489 mLandMapper->SetInputConnection(mLandClipper->GetOutputPort());
490 //mLandMapper->ScalarVisibilityOff();
493 mLandActor = vtkSmartPointer<vtkActor>::New();
494 mLandActor->SetMapper(mLandMapper);
495 mLandActor->GetProperty()->SetColor(255,10,212);
496 mLandActor->SetPickable(0);
497 mLandActor->SetVisibility(true);
498 this->UpdateDisplayExtent();
499 this->GetRenderer()->AddActor(mLandActor);
502 //------------------------------------------------------------------------------
504 //------------------------------------------------------------------------------
505 //FIXME: this function leaks memory, we should fix it someday :)
506 void vvSlicer::RemoveActor(const std::string& actor_type, int overlay_index)
508 if (actor_type == "vector") {
509 Renderer->RemoveActor(mVFActor);
518 if (actor_type == "overlay") {
519 Renderer->RemoveActor(mOverlayActor);
521 mOverlayActor = NULL;
522 mOverlayMapper = NULL;
524 if (actor_type == "fusion") {
525 Renderer->RemoveActor(mFusionActor);
528 mFusionMapper = NULL;
530 if (actor_type == "contour") {
531 Renderer->RemoveActor(this->mSurfaceCutActors[overlay_index]->GetActor());
532 mSurfaceCutActors.erase(mSurfaceCutActors.begin()+overlay_index);
535 //------------------------------------------------------------------------------
538 //------------------------------------------------------------------------------
539 void vvSlicer::SetVFSubSampling(int sub)
542 mVOIFilter->SetSampleRate(mSubSampling,mSubSampling,mSubSampling);
545 UpdateDisplayExtent();
548 //------------------------------------------------------------------------------
551 //------------------------------------------------------------------------------
552 void vvSlicer::SetVFScale(int scale)
556 mArrow->SetScale(mScale);
557 UpdateDisplayExtent();
560 //------------------------------------------------------------------------------
562 //------------------------------------------------------------------------------
563 void vvSlicer::SetVFWidth(int width)
567 mVFActor->GetProperty()->SetLineWidth(mVFWidth);
568 UpdateDisplayExtent();
571 //------------------------------------------------------------------------------
574 //------------------------------------------------------------------------------
575 void vvSlicer::SetVFLog(int log)
579 mGlyphFilter->SetUseLog(mVFLog);
580 mGlyphFilter->Modified();
582 UpdateDisplayExtent();
585 //------------------------------------------------------------------------------
588 //------------------------------------------------------------------------------
589 void vvSlicer::SetTSlice(int t)
593 else if ((unsigned int)t >= mImage->GetVTKImages().size())
594 t = mImage->GetVTKImages().size() -1;
596 if (mCurrentTSlice == t) return;
599 this->SetInput(mImage->GetVTKImages()[t]);
600 if (mVF && mVFActor->GetVisibility()) {
601 if (mVF->GetVTKImages().size() > (unsigned int)mCurrentTSlice)
602 mVOIFilter->SetInput(mVF->GetVTKImages()[mCurrentTSlice]);
604 if (mOverlay && mOverlayActor->GetVisibility()) {
605 if (mOverlay->GetVTKImages().size() > (unsigned int)mCurrentTSlice)
606 mOverlayMapper->SetInput(mOverlay->GetVTKImages()[mCurrentTSlice]);
608 if (mFusion && mFusionActor->GetVisibility()) {
609 if (mFusion->GetVTKImages().size() > (unsigned int)mCurrentTSlice)
610 mFusionMapper->SetInput(mFusion->GetVTKImages()[mCurrentTSlice]);
612 if (mSurfaceCutActors.size() > 0)
613 for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
614 i!=mSurfaceCutActors.end(); i++)
615 (*i)->SetTimeSlice(mCurrentTSlice);
616 UpdateDisplayExtent();
618 //------------------------------------------------------------------------------
621 //------------------------------------------------------------------------------
622 int vvSlicer::GetTSlice()
624 return mCurrentTSlice;
626 //------------------------------------------------------------------------------
629 //------------------------------------------------------------------------------
630 void vvSlicer::SetSliceOrientation(int orientation)
632 //if 2D image, force to watch in Axial View
634 this->GetInput()->GetWholeExtent(extent);
635 if (extent[5]-extent[4] <= 2)
638 if (orientation < vtkImageViewer2::SLICE_ORIENTATION_YZ ||
639 orientation > vtkImageViewer2::SLICE_ORIENTATION_XY) {
640 vtkErrorMacro("Error - invalid slice orientation " << orientation);
644 this->SliceOrientation = orientation;
647 int *range = this->GetSliceRange();
649 this->Slice = static_cast<int>((range[0] + range[1]) * 0.5);
651 // Go to current cursor position
652 // double* cursorPos = GetCursorPosition();
653 // DDV(cursorPos, 3);
654 // SetCurrentPosition(cursorPos[0],cursorPos[1],cursorPos[2],cursorPos[3]);
656 this->UpdateOrientation();
657 this->UpdateDisplayExtent();
659 if (this->Renderer && this->GetInput()) {
660 double scale = this->Renderer->GetActiveCamera()->GetParallelScale();
661 this->Renderer->ResetCamera();
662 this->Renderer->GetActiveCamera()->SetParallelScale(scale);
667 //----------------------------------------------------------------------------
670 //----------------------------------------------------------------------------
671 int * vvSlicer::GetExtent()
674 if (mUseReducedExtent) {
675 w_ext = mReducedExtent;
676 } else w_ext = GetInput()->GetWholeExtent();
679 //----------------------------------------------------------------------------
682 //----------------------------------------------------------------------------
683 int vvSlicer::GetOrientation()
685 return this->SliceOrientation;
687 //----------------------------------------------------------------------------
690 //----------------------------------------------------------------------------
691 void vvSlicer::UpdateDisplayExtent()
693 vtkImageData *input = this->GetInput();
694 if (!input || !this->ImageActor) {
697 input->UpdateInformation();
698 int *w_ext;// = input->GetWholeExtent();
700 if (mUseReducedExtent) {
701 w_ext = mReducedExtent;
702 } else w_ext = input->GetWholeExtent();
704 switch (this->SliceOrientation) {
705 case vtkImageViewer2::SLICE_ORIENTATION_XY:
706 this->ImageActor->SetDisplayExtent(
707 w_ext[0], w_ext[1], w_ext[2], w_ext[3], this->Slice, this->Slice);
708 if (mVF && mVFActor->GetVisibility()) {
710 ComputeVFDisplayedExtent(w_ext[0], w_ext[1], w_ext[2], w_ext[3], this->Slice, this->Slice,vfExtent);
711 mVOIFilter->SetVOI(vfExtent);
712 mGlyphFilter->SetOrientation(1,1,0);
714 // put the vector field between the image and the camera
715 if (Renderer->GetActiveCamera()->GetPosition()[2] > this->Slice)
716 mVFActor->SetPosition(0,0,ImageActor->GetBounds()[5]+2);
718 mVFActor->SetPosition(0,0,ImageActor->GetBounds()[4]-2);
720 if (mOverlay && mOverlayActor->GetVisibility()) {
722 ComputeOverlayDisplayedExtent(w_ext[0], w_ext[1], w_ext[2], w_ext[3], this->Slice, this->Slice,overExtent);
723 mOverlayActor->SetDisplayExtent(overExtent);
724 if (Renderer->GetActiveCamera()->GetPosition()[2] > this->Slice)
725 mOverlayActor->SetPosition(0,0,1);
727 mOverlayActor->SetPosition(0,0,-1);
729 if (mFusion && mFusionActor->GetVisibility()) {
731 ComputeFusionDisplayedExtent(w_ext[0], w_ext[1], w_ext[2], w_ext[3], this->Slice, this->Slice,fusExtent);
732 mFusionActor->SetDisplayExtent(fusExtent);
733 if (Renderer->GetActiveCamera()->GetPosition()[2] > this->Slice)
734 mFusionActor->SetPosition(0,0,1.5);
736 mFusionActor->SetPosition(0,0,-1.5);
741 bounds[0] = ImageActor->GetBounds()[0];
742 bounds[1] = ImageActor->GetBounds()[1];
743 bounds[2] = ImageActor->GetBounds()[2];
744 bounds[3] = ImageActor->GetBounds()[3];
745 bounds[4] = ImageActor->GetBounds()[4]-fabs(0.5/this->GetInput()->GetSpacing()[2]);
746 bounds[5] = ImageActor->GetBounds()[5]+fabs(0.5/this->GetInput()->GetSpacing()[2]);
747 mClipBox->SetBounds(bounds);
750 if (Renderer->GetActiveCamera()->GetPosition()[2] > this->Slice)
751 mLandActor->SetPosition(0,0,1.5);
753 mLandActor->SetPosition(0,0,-1.5);
757 case vtkImageViewer2::SLICE_ORIENTATION_XZ:
758 this->ImageActor->SetDisplayExtent(
759 w_ext[0], w_ext[1], this->Slice, this->Slice, w_ext[4], w_ext[5]);
760 if (mVF && mVFActor->GetVisibility()) {
762 ComputeVFDisplayedExtent(w_ext[0], w_ext[1], this->Slice, this->Slice, w_ext[4], w_ext[5],vfExtent);
763 mVOIFilter->SetVOI(vfExtent);
764 mGlyphFilter->SetOrientation(1,0,1);
766 // put the vector field between the image aSpacingnd the camera
767 if (Renderer->GetActiveCamera()->GetPosition()[1] > this->Slice)
768 mVFActor->SetPosition(0,ImageActor->GetBounds()[3]+2,0);
770 mVFActor->SetPosition(0,ImageActor->GetBounds()[2]-2,0);
772 if (mOverlay && mOverlayActor->GetVisibility()) {
774 ComputeOverlayDisplayedExtent(w_ext[0], w_ext[1], this->Slice, this->Slice, w_ext[4], w_ext[5],overExtent);
775 mOverlayActor->SetDisplayExtent(overExtent);
776 if (Renderer->GetActiveCamera()->GetPosition()[1] > this->Slice)
777 mOverlayActor->SetPosition(0,1,0);
779 mOverlayActor->SetPosition(0,-1,0);
781 if (mFusion && mFusionActor->GetVisibility()) {
783 ComputeFusionDisplayedExtent(w_ext[0], w_ext[1], this->Slice, this->Slice, w_ext[4], w_ext[5],fusExtent);
784 mFusionActor->SetDisplayExtent(fusExtent);
785 if (Renderer->GetActiveCamera()->GetPosition()[1] > this->Slice)
786 mFusionActor->SetPosition(0,1.5,0);
788 mFusionActor->SetPosition(0,-1.5,0);
793 bounds[0] = ImageActor->GetBounds()[0];
794 bounds[1] = ImageActor->GetBounds()[1];
795 bounds[2] = ImageActor->GetBounds()[2]-fabs(0.5/this->GetInput()->GetSpacing()[1]);
796 bounds[3] = ImageActor->GetBounds()[3]+fabs(0.5/this->GetInput()->GetSpacing()[1]);
797 bounds[4] = ImageActor->GetBounds()[4];
798 bounds[5] = ImageActor->GetBounds()[5];
799 mClipBox->SetBounds(bounds);
802 if (Renderer->GetActiveCamera()->GetPosition()[1] > this->Slice)
803 mLandActor->SetPosition(0,1.5,0);
805 mLandActor->SetPosition(0,-1.5,0);
809 case vtkImageViewer2::SLICE_ORIENTATION_YZ:
810 this->ImageActor->SetDisplayExtent(
811 this->Slice, this->Slice, w_ext[2], w_ext[3], w_ext[4], w_ext[5]);
812 if (mVF && mVFActor->GetVisibility()) {
814 ComputeVFDisplayedExtent(this->Slice, this->Slice, w_ext[2], w_ext[3], w_ext[4], w_ext[5],vfExtent);
815 mVOIFilter->SetVOI(vfExtent);
816 mGlyphFilter->SetOrientation(0,1,1);
818 // put the vector field between the image and the camera
819 if (Renderer->GetActiveCamera()->GetPosition()[0] > this->Slice)
820 mVFActor->SetPosition(ImageActor->GetBounds()[1]+2,0,0);
822 mVFActor->SetPosition(ImageActor->GetBounds()[0]-2,0,0);
824 if (mOverlay && mOverlayActor->GetVisibility()) {
826 ComputeOverlayDisplayedExtent(this->Slice, this->Slice, w_ext[2], w_ext[3], w_ext[4], w_ext[5],overExtent);
827 mOverlayActor->SetDisplayExtent(overExtent);
828 if (Renderer->GetActiveCamera()->GetPosition()[0] > this->Slice)
829 mOverlayActor->SetPosition(1,0,0);
831 mOverlayActor->SetPosition(-1,0,0);
833 if (mFusion && mFusionActor->GetVisibility()) {
835 ComputeFusionDisplayedExtent(this->Slice, this->Slice, w_ext[2], w_ext[3], w_ext[4], w_ext[5],fusExtent);
836 mFusionActor->SetDisplayExtent(fusExtent);
837 if (Renderer->GetActiveCamera()->GetPosition()[0] > this->Slice)
838 mFusionActor->SetPosition(1.5,0,0);
840 mFusionActor->SetPosition(-1.5,0,0);
845 bounds[0] = ImageActor->GetBounds()[0]-fabs(0.5/this->GetInput()->GetSpacing()[0]);
846 bounds[1] = ImageActor->GetBounds()[1]+fabs(0.5/this->GetInput()->GetSpacing()[0]);
847 bounds[2] = ImageActor->GetBounds()[2];
848 bounds[3] = ImageActor->GetBounds()[3];
849 bounds[4] = ImageActor->GetBounds()[4];
850 bounds[5] = ImageActor->GetBounds()[5];
851 mClipBox->SetBounds(bounds);
854 if (Renderer->GetActiveCamera()->GetPosition()[0] > this->Slice)
855 mLandActor->SetPosition(1.5,0,0);
857 mLandActor->SetPosition(-1.5,0,0);
862 // Figure out the correct clipping range
864 if (this->Renderer) {
865 if (this->InteractorStyle &&
866 this->InteractorStyle->GetAutoAdjustCameraClippingRange()) {
867 this->Renderer->ResetCameraClippingRange();
869 vtkCamera *cam = this->Renderer->GetActiveCamera();
872 this->ImageActor->GetBounds(bounds);
873 double spos = (double)bounds[this->SliceOrientation * 2];
874 double cpos = (double)cam->GetPosition()[this->SliceOrientation];
875 double range = fabs(spos - cpos);
876 double *spacing = input->GetSpacing();
878 ((double)spacing[0] + (double)spacing[1] + (double)spacing[2]) / 3.0;
879 cam->SetClippingRange(
880 range - avg_spacing * 3.0, range + avg_spacing * 3.0);
885 //----------------------------------------------------------------------------
888 //----------------------------------------------------------------------------
889 void vvSlicer::ComputeVFDisplayedExtent(int x1,int x2,int y1,int y2,int z1,int z2,int vfExtent[6])
891 vtkImageData* image=this->GetInput();
892 vfExtent[0] = (( image->GetOrigin()[0] + x1*image->GetSpacing()[0] ) - mVF->GetOrigin()[0]) /
893 mVF->GetSpacing()[0];
894 vfExtent[1] = (( image->GetOrigin()[0] + x2*image->GetSpacing()[0] ) - mVF->GetOrigin()[0]) /
895 mVF->GetSpacing()[0];
896 vfExtent[2] = (( image->GetOrigin()[1] + y1*image->GetSpacing()[1] ) - mVF->GetOrigin()[1]) /
897 mVF->GetSpacing()[1];
898 vfExtent[3] = (( image->GetOrigin()[1] + y2*image->GetSpacing()[1] ) - mVF->GetOrigin()[1]) /
899 mVF->GetSpacing()[1];
900 vfExtent[4] = (( image->GetOrigin()[2] + z1*image->GetSpacing()[2] ) - mVF->GetOrigin()[2]) /
901 mVF->GetSpacing()[2];
902 vfExtent[5] = (( image->GetOrigin()[2] + z2*image->GetSpacing()[2] ) - mVF->GetOrigin()[2]) /
903 mVF->GetSpacing()[2];
905 ClipDisplayedExtent(vfExtent,mVOIFilter->GetInput()->GetWholeExtent());
907 //----------------------------------------------------------------------------
910 //----------------------------------------------------------------------------
911 void vvSlicer::ComputeOverlayDisplayedExtent(int x1,int x2,int y1,int y2,int z1,int z2,int overExtent[6])
913 vtkImageData* image=this->GetInput();
914 overExtent[0] = (( image->GetOrigin()[0] + x1*image->GetSpacing()[0] ) - mOverlay->GetOrigin()[0]) /
915 mOverlay->GetSpacing()[0];
916 overExtent[1] = (( image->GetOrigin()[0] + x2*image->GetSpacing()[0] ) - mOverlay->GetOrigin()[0]) /
917 mOverlay->GetSpacing()[0];
918 overExtent[2] = (( image->GetOrigin()[1] + y1*image->GetSpacing()[1] ) - mOverlay->GetOrigin()[1]) /
919 mOverlay->GetSpacing()[1];
920 overExtent[3] = (( image->GetOrigin()[1] + y2*image->GetSpacing()[1] ) - mOverlay->GetOrigin()[1]) /
921 mOverlay->GetSpacing()[1];
922 overExtent[4] = (( image->GetOrigin()[2] + z1*image->GetSpacing()[2] ) - mOverlay->GetOrigin()[2]) /
923 mOverlay->GetSpacing()[2];
924 overExtent[5] = (( image->GetOrigin()[2] + z2*image->GetSpacing()[2] ) - mOverlay->GetOrigin()[2]) /
925 mOverlay->GetSpacing()[2];
926 ClipDisplayedExtent(overExtent, mOverlayMapper->GetInput()->GetWholeExtent());
928 //----------------------------------------------------------------------------
931 //----------------------------------------------------------------------------
932 void vvSlicer::ComputeFusionDisplayedExtent(int x1,int x2,int y1,int y2,int z1,int z2,int fusExtent[6])
934 vtkImageData* image=this->GetInput();
935 fusExtent[0] = (( image->GetOrigin()[0] + x1*image->GetSpacing()[0] ) - mFusion->GetOrigin()[0]) /
936 mFusion->GetSpacing()[0];
937 fusExtent[1] = (( image->GetOrigin()[0] + x2*image->GetSpacing()[0] ) - mFusion->GetOrigin()[0]) /
938 mFusion->GetSpacing()[0];
939 fusExtent[2] = (( image->GetOrigin()[1] + y1*image->GetSpacing()[1] ) - mFusion->GetOrigin()[1]) /
940 mFusion->GetSpacing()[1];
941 fusExtent[3] = (( image->GetOrigin()[1] + y2*image->GetSpacing()[1] ) - mFusion->GetOrigin()[1]) /
942 mFusion->GetSpacing()[1];
943 fusExtent[4] = (( image->GetOrigin()[2] + z1*image->GetSpacing()[2] ) - mFusion->GetOrigin()[2]) /
944 mFusion->GetSpacing()[2];
945 fusExtent[5] = (( image->GetOrigin()[2] + z2*image->GetSpacing()[2] ) - mFusion->GetOrigin()[2]) /
946 mFusion->GetSpacing()[2];
947 ClipDisplayedExtent(fusExtent, mFusionMapper->GetInput()->GetWholeExtent());
949 //----------------------------------------------------------------------------
952 //----------------------------------------------------------------------------
953 void vvSlicer::ClipDisplayedExtent(int extent[6], int refExtent[6])
958 //2D overlay on 3D image specific case
959 if (refExtent[4] == refExtent[5]) {
961 extent[4] = refExtent[4];
962 extent[5] = refExtent[5];
965 for (int i = 0; i < maxBound; i = i+2) {
966 //if we are totally outside the image
967 if ( extent[i] > refExtent[i+1] || extent[i+1] < refExtent[i] ) {
971 //crop to the limit of the image
972 extent[i] = (extent[i] > refExtent[i]) ? extent[i] : refExtent[i];
973 extent[i] = (extent[i] < refExtent[i+1]) ? extent[i] : refExtent[i+1];
974 extent[i+1] = (extent[i+1] > refExtent[i]) ? extent[i+1] : refExtent[i];
975 extent[i+1] = (extent[i+1] < refExtent[i+1]) ? extent[i+1] : refExtent[i+1];
978 for (int i = 0; i < maxBound; i = i+2) {
979 extent[i] = refExtent[i];
980 extent[i+1] = refExtent[i];
983 //----------------------------------------------------------------------------
986 //----------------------------------------------------------------------------
987 void vvSlicer::UpdateOrientation()
989 // Set the camera position
990 vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
992 switch (this->SliceOrientation) {
993 case vtkImageViewer2::SLICE_ORIENTATION_XY:
994 cam->SetFocalPoint(0,0,0);
995 cam->SetPosition(0,0,-1); // -1 if medical ?
996 cam->SetViewUp(0,-1,0);
999 case vtkImageViewer2::SLICE_ORIENTATION_XZ:
1000 cam->SetFocalPoint(0,0,0);
1001 cam->SetPosition(0,-1,0); // 1 if medical ?
1002 cam->SetViewUp(0,0,1);
1005 case vtkImageViewer2::SLICE_ORIENTATION_YZ:
1006 cam->SetFocalPoint(0,0,0);
1007 cam->SetPosition(-1,0,0); // -1 if medical ?
1008 cam->SetViewUp(0,0,1);
1013 //----------------------------------------------------------------------------
1016 //----------------------------------------------------------------------------
1017 void vvSlicer::SetOpacity(double s)
1019 this->GetImageActor()->SetOpacity(s);
1021 //----------------------------------------------------------------------------
1024 //----------------------------------------------------------------------------
1025 void vvSlicer::SetRenderWindow(int orientation, vtkRenderWindow * rw)
1027 this->Superclass::SetRenderWindow(rw);
1028 this->SetupInteractor(rw->GetInteractor());
1029 ca->SetImageActor(this->GetImageActor());
1030 ca->SetWindowLevel(this->GetWindowLevel());
1031 ca->SetText(2, "<slice>");
1032 ca->SetText(3, "<window>\n<level>");
1044 crossCursor->SetModelBounds(bounds);
1045 this->GetRenderer()->AddActor(pdmA);
1046 this->GetRenderer()->AddActor(ca);
1047 this->GetRenderer()->ResetCamera();
1049 //this is just a mapping between the labeling of the orientations presented to the user and
1050 //the one used by vtk
1051 SetSliceOrientation(2-(orientation%3));
1054 //----------------------------------------------------------------------------
1057 //----------------------------------------------------------------------------
1058 void vvSlicer::ResetCamera()
1060 if (this->GetInput()) {
1061 double* input_bounds=this->GetInput()->GetBounds();
1062 double bmax=input_bounds[1]-input_bounds[0];
1063 if (bmax < input_bounds[3]-input_bounds[2]) bmax=input_bounds[3]-input_bounds[2];
1064 if (bmax < input_bounds[5]-input_bounds[4]) bmax=input_bounds[5]-input_bounds[4];
1065 this->GetRenderer()->ResetCamera();
1066 this->GetRenderer()->GetActiveCamera()->SetParallelScale(bmax/2);
1069 //----------------------------------------------------------------------------
1072 //----------------------------------------------------------------------------
1073 void vvSlicer::SetDisplayMode(bool i)
1075 this->GetImageActor()->SetVisibility(i);
1076 this->GetAnnotation()->SetVisibility(i);
1077 this->GetRenderer()->SetDraw(i);
1079 mLandActor->SetVisibility(i);
1080 pdmA->SetVisibility(i);
1082 UpdateDisplayExtent();
1084 //----------------------------------------------------------------------------
1087 //----------------------------------------------------------------------------
1088 void vvSlicer::FlipHorizontalView()
1090 vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
1092 double *position = cam->GetPosition();
1093 switch (this->SliceOrientation) {
1094 case vtkImageViewer2::SLICE_ORIENTATION_XY:
1095 cam->SetPosition(position[0],position[1],-position[2]);
1098 case vtkImageViewer2::SLICE_ORIENTATION_XZ:
1099 cam->SetPosition(position[0],-position[1],position[2]);
1102 case vtkImageViewer2::SLICE_ORIENTATION_YZ:
1103 cam->SetPosition(-position[0],position[1],position[2]);
1106 this->Renderer->ResetCameraClippingRange();
1107 this->UpdateDisplayExtent();
1110 //----------------------------------------------------------------------------
1113 //----------------------------------------------------------------------------
1114 void vvSlicer::FlipVerticalView()
1116 vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
1118 FlipHorizontalView();
1119 double *viewup = cam->GetViewUp();
1120 cam->SetViewUp(-viewup[0],-viewup[1],-viewup[2]);
1121 this->UpdateDisplayExtent();
1124 //----------------------------------------------------------------------------
1127 //----------------------------------------------------------------------------
1128 void vvSlicer::SetColorWindow(double window)
1130 vtkLookupTable* LUT = static_cast<vtkLookupTable*>(this->GetWindowLevel()->GetLookupTable());
1132 double level = this->GetWindowLevel()->GetLevel();
1133 LUT->SetTableRange(level-fabs(window)/4,level+fabs(window)/4);
1136 this->vtkImageViewer2::SetColorWindow(window);
1138 //----------------------------------------------------------------------------
1141 //----------------------------------------------------------------------------
1142 void vvSlicer::SetColorLevel(double level)
1144 vtkLookupTable* LUT = static_cast<vtkLookupTable*>(this->GetWindowLevel()->GetLookupTable());
1146 double window = this->GetWindowLevel()->GetWindow();
1147 LUT->SetTableRange(level-fabs(window)/4,level+fabs(window)/4);
1150 this->vtkImageViewer2::SetColorLevel(level);
1152 //----------------------------------------------------------------------------
1154 //----------------------------------------------------------------------------
1155 // Returns the min an the max value in a 41x41 region around the mouse pointer
1156 void vvSlicer::GetExtremasAroundMousePointer(double & min, double & max)
1158 //Get mouse pointer position in view coordinates
1159 double fLocalExtents[6];
1160 for(int i=0; i<3; i++) {
1161 fLocalExtents[i*2 ] = mCurrent[i];
1162 fLocalExtents[i*2+1] = mCurrent[i];
1164 this->Renderer->WorldToView(fLocalExtents[0], fLocalExtents[2], fLocalExtents[4]);
1165 this->Renderer->WorldToView(fLocalExtents[1], fLocalExtents[3], fLocalExtents[5]);
1166 for(int i=0; i<3; i++) {
1167 if (i!=SliceOrientation) { //SR: assumes that SliceOrientation is valid in ViewCoordinates (???)
1168 fLocalExtents[i*2 ] -= 0.2;
1169 fLocalExtents[i*2+1] += 0.2;
1172 this->Renderer->ViewToWorld(fLocalExtents[0], fLocalExtents[2], fLocalExtents[4]);
1173 this->Renderer->ViewToWorld(fLocalExtents[1], fLocalExtents[3], fLocalExtents[5]);
1175 //Convert to image pixel coordinates (rounded)
1176 int iLocalExtents[6];
1177 for(int i=0; i<3; i++) {
1178 fLocalExtents[i*2 ] = (fLocalExtents[i*2 ] - this->GetInput()->GetOrigin()[i])/this->GetInput()->GetSpacing()[i];
1179 fLocalExtents[i*2+1] = (fLocalExtents[i*2+1] - this->GetInput()->GetOrigin()[i])/this->GetInput()->GetSpacing()[i];
1181 iLocalExtents[i*2 ] = lrint(fLocalExtents[i*2 ]);
1182 iLocalExtents[i*2+1] = lrint(fLocalExtents[i*2+1]);
1184 if(iLocalExtents[i*2 ]>iLocalExtents[i*2+1])
1185 std::swap(iLocalExtents[i*2], iLocalExtents[i*2+1]);
1188 vtkSmartPointer<vtkExtractVOI> voiFilter = vtkSmartPointer<vtkExtractVOI>::New();
1189 voiFilter->SetInput(this->GetInput());
1190 voiFilter->SetVOI(iLocalExtents);
1191 voiFilter->Update();
1192 if (!voiFilter->GetOutput()->GetNumberOfPoints()) {
1198 vtkSmartPointer<vtkImageAccumulate> accFilter = vtkSmartPointer<vtkImageAccumulate>::New();
1199 accFilter->SetInput(voiFilter->GetOutput());
1200 accFilter->Update();
1202 min = *(accFilter->GetMin());
1203 max = *(accFilter->GetMax());
1205 //----------------------------------------------------------------------------
1207 //----------------------------------------------------------------------------
1208 void vvSlicer::Render()
1210 // DD("vvSlicer::Render");
1211 // DD(SliceOrientation);
1212 if (this->GetWindowLevel()->GetLookupTable() && !this->mOverlay && !this->mFusion) {
1213 legend->SetLookupTable(this->GetWindowLevel()->GetLookupTable());
1214 legend->SetVisibility(1);
1215 } else legend->SetVisibility(0);
1217 if (ca->GetVisibility()) {
1218 std::string worldPos = "";
1219 std::stringstream world1;
1220 std::stringstream world2;
1221 std::stringstream world3;
1222 world1 << (int)mCurrent[0];
1223 world2 << (int)mCurrent[1];
1224 world3 << (int)mCurrent[2];
1225 double X = (mCurrent[0] - this->GetInput()->GetOrigin()[0])/this->GetInput()->GetSpacing()[0];
1226 double Y = (mCurrent[1] - this->GetInput()->GetOrigin()[1])/this->GetInput()->GetSpacing()[1];
1227 double Z = (mCurrent[2] - this->GetInput()->GetOrigin()[2])/this->GetInput()->GetSpacing()[2];
1229 if (pdmA->GetVisibility()) {
1230 double x = mCursor[0];
1231 double y = mCursor[1];
1232 double z = mCursor[2];
1233 double xCursor = (x - this->GetInput()->GetOrigin()[0])/this->GetInput()->GetSpacing()[0];
1234 double yCursor = (y - this->GetInput()->GetOrigin()[1])/this->GetInput()->GetSpacing()[1];
1235 double zCursor = (z - this->GetInput()->GetOrigin()[2])/this->GetInput()->GetSpacing()[2];
1237 if (xCursor >= this->GetImageActor()->GetDisplayExtent()[0] &&
1238 xCursor < this->GetImageActor()->GetDisplayExtent()[1]+1 &&
1239 yCursor >= this->GetImageActor()->GetDisplayExtent()[2] &&
1240 yCursor < this->GetImageActor()->GetDisplayExtent()[3]+1 &&
1241 zCursor >= this->GetImageActor()->GetDisplayExtent()[4] &&
1242 zCursor < this->GetImageActor()->GetDisplayExtent()[5]+1 ) {
1243 vtkRenderer * renderer = this->Renderer;
1245 renderer->WorldToView(x,y,z);
1246 renderer->ViewToNormalizedViewport(x,y,z);
1247 renderer->NormalizedViewportToViewport(x,y);
1248 renderer->ViewportToNormalizedDisplay(x,y);
1249 renderer->NormalizedDisplayToDisplay(x,y);
1250 crossCursor->SetFocalPoint(x,y,z);
1252 crossCursor->SetFocalPoint(-1,-1,z);
1255 if (X >= this->GetInput()->GetWholeExtent()[0] &&
1256 X <= this->GetInput()->GetWholeExtent()[1] &&
1257 Y >= this->GetInput()->GetWholeExtent()[2] &&
1258 Y <= this->GetInput()->GetWholeExtent()[3] &&
1259 Z >= this->GetInput()->GetWholeExtent()[4] &&
1260 Z <= this->GetInput()->GetWholeExtent()[5]) {
1261 std::stringstream pixel1;
1262 std::stringstream pixel2;
1263 std::stringstream pixel3;
1264 std::stringstream temps;
1268 temps << mCurrentTSlice;
1269 double value = this->GetInput()->GetScalarComponentAsDouble(lrint(X),
1273 std::stringstream val;
1275 worldPos += "data value : " + val.str();
1276 worldPos += "\n mm : " + world1.str() + " " + world2.str() + " " +
1277 world3.str() + " " + temps.str();
1278 worldPos += "\n pixel : " + pixel1.str() + " " + pixel2.str() + " " +
1279 pixel3.str() + " " + temps.str();
1281 ca->SetText(1,worldPos.c_str());
1283 if (mOverlay && mOverlayActor->GetVisibility()) {
1284 mOverlayMapper->SetWindow(this->GetColorWindow());
1285 mOverlayMapper->SetLevel(this->GetColorLevel());
1286 mOverlayMapper->Update();
1290 //this->Superclass::Render();
1291 this->GetRenderWindow()->Render();
1293 //----------------------------------------------------------------------------
1296 //----------------------------------------------------------------------------
1297 void vvSlicer::UpdateCursorPosition()
1299 if (this->GetImageActor()->GetVisibility()) {
1300 pdmA->SetVisibility(true);
1301 mCursor[0] = mCurrent[0];
1302 mCursor[1] = mCurrent[1];
1303 mCursor[2] = mCurrent[2];
1304 mCursor[3] = mCurrentTSlice;
1307 //----------------------------------------------------------------------------
1310 //----------------------------------------------------------------------------
1311 void vvSlicer::UpdateLandmarks()
1313 vtkPolyData *pd = static_cast<vtkPolyData*>(mLandClipper->GetInput());
1314 if (pd->GetPoints()) {
1315 mLandGlyph->SetRange(0,1);
1316 mLandGlyph->Modified();
1317 mLandGlyph->Update();
1319 mClipBox->Modified();
1320 mLandClipper->Update();
1321 mLandMapper->Update();
1325 //----------------------------------------------------------------------------
1328 //----------------------------------------------------------------------------
1329 void vvSlicer::SetSlice(int slice)
1331 int *range = this->GetSliceRange();
1333 if (slice < range[0]) {
1335 } else if (slice > range[1]) {
1340 if (this->Slice == slice) {
1344 this->Slice = slice;
1347 this->UpdateDisplayExtent();
1349 // DD("SetSlice de slicer = Render");
1351 // Seems to work without this line
1354 //----------------------------------------------------------------------------
1357 //----------------------------------------------------------------------------
1358 void vvSlicer::SetContourSlice()
1360 if (mSurfaceCutActors.size() > 0)
1361 for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
1362 i!=mSurfaceCutActors.end(); i++)
1363 (*i)->SetCutSlice((this->Slice)*this->GetImage()->GetSpacing()[this->SliceOrientation]+
1364 this->GetImage()->GetOrigin()[this->SliceOrientation]);
1366 //----------------------------------------------------------------------------
1369 //----------------------------------------------------------------------------
1370 void vvSlicer::ForceUpdateDisplayExtent()
1372 this->UpdateDisplayExtent();
1374 //----------------------------------------------------------------------------
1377 //----------------------------------------------------------------------------
1378 int* vvSlicer::GetDisplayExtent()
1380 return this->GetImageActor()->GetDisplayExtent();
1382 //----------------------------------------------------------------------------
1385 //----------------------------------------------------------------------------
1386 void vvSlicer::PrintSelf(ostream& os, vtkIndent indent)
1388 this->Superclass::PrintSelf(os, indent);
1390 //----------------------------------------------------------------------------