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 mCurrentFusionTSlice = 0;
86 mCurrentOverlayTSlice = 0;
87 mUseReducedExtent = false;
89 mCurrent[0] = -VTK_DOUBLE_MAX;
90 mCurrent[1] = -VTK_DOUBLE_MAX;
91 mCurrent[2] = -VTK_DOUBLE_MAX;
93 mCursor[0] = -VTK_DOUBLE_MAX;
94 mCursor[1] = -VTK_DOUBLE_MAX;
95 mCursor[2] = -VTK_DOUBLE_MAX;
96 mCursor[3] = -VTK_DOUBLE_MAX;
106 crossCursor = vtkSmartPointer<vtkCursor2D>::New();
107 crossCursor->AllOff();
108 crossCursor->AxesOn();
109 crossCursor->SetTranslationMode(1);
110 crossCursor->SetRadius(2);
112 pdm = vtkSmartPointer<vtkPolyDataMapper2D>::New();
113 pdm->SetInput(crossCursor->GetOutput());
115 pdmA = vtkSmartPointer<vtkActor2D>::New();
116 pdmA->SetMapper(pdm);
117 pdmA->GetProperty()->SetColor(255,10,212);
118 pdmA->SetVisibility(0);
119 pdmA->SetPickable(0);
121 ca = vtkSmartPointer<vtkCornerAnnotation>::New();
122 ca->GetTextProperty()->SetColor(255,10,212);
123 ca->SetVisibility(1);
131 legend = vtkSmartPointer<vtkScalarBarActor>::New();
132 //legend->SetTitle("test!");
133 legend->SetPosition(0.82,0.18);
134 legend->SetWidth(0.1);
135 legend->SetVisibility(0);
136 legend->SetLabelFormat("%.1f");
137 this->GetRenderer()->AddActor(legend);
138 showFusionLegend = false;
140 this->WindowLevel->Delete();
141 this->WindowLevel = vvImageMapToWLColors::New();
143 this->InstallPipeline();
145 mLinkOverlayWindowLevel = true;
147 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
148 this->GetImageActor()->GetMapper()->BorderOn();
151 mSlicingTransform = vtkSmartPointer<vtkTransform>::New();
152 mConcatenatedTransform = vtkSmartPointer<vtkTransform>::New();
153 mConcatenatedFusionTransform = vtkSmartPointer<vtkTransform>::New();
154 mConcatenatedOverlayTransform = vtkSmartPointer<vtkTransform>::New();
156 //------------------------------------------------------------------------------
159 //------------------------------------------------------------------------------
160 vtkImageMapToWindowLevelColors* vvSlicer::GetOverlayMapper()
162 return mOverlayMapper.GetPointer();
164 //------------------------------------------------------------------------------
167 //------------------------------------------------------------------------------
168 vvBlendImageActor* vvSlicer::GetOverlayActor()
170 return mOverlayActor.GetPointer();
172 //------------------------------------------------------------------------------
175 //------------------------------------------------------------------------------
176 vtkImageMapToColors* vvSlicer::GetFusionMapper()
178 return mFusionMapper.GetPointer();
180 //------------------------------------------------------------------------------
183 //------------------------------------------------------------------------------
184 vtkImageActor* vvSlicer::GetFusionActor()
186 return mFusionActor.GetPointer();
188 //------------------------------------------------------------------------------
191 //------------------------------------------------------------------------------
192 vtkActor* vvSlicer::GetVFActor()
194 return mVFActor.GetPointer();
196 //------------------------------------------------------------------------------
199 //------------------------------------------------------------------------------
200 vtkCornerAnnotation* vvSlicer::GetAnnotation()
202 return ca.GetPointer();
204 //------------------------------------------------------------------------------
207 //------------------------------------------------------------------------------
208 void vvSlicer::EnableReducedExtent(bool b)
210 mUseReducedExtent = b;
212 //------------------------------------------------------------------------------
215 //------------------------------------------------------------------------------
216 void vvSlicer::SetReducedExtent(int * ext)
218 copyExtent(ext, mReducedExtent);
220 //------------------------------------------------------------------------------
223 //------------------------------------------------------------------------------
224 void vvSlicer::AddContour(vvMesh::Pointer contour,bool propagate)
227 mSurfaceCutActors.push_back(new vvMeshActor());
229 mSurfaceCutActors.back()->Init(contour,mCurrentTSlice,mVF);
231 mSurfaceCutActors.back()->Init(contour,mCurrentTSlice);
232 mSurfaceCutActors.back()->SetSlicingOrientation(SliceOrientation);
233 this->GetRenderer()->AddActor(mSurfaceCutActors.back()->GetActor());
237 //------------------------------------------------------------------------------
240 //------------------------------------------------------------------------------
241 void vvSlicer::ToggleContourSuperposition()
243 for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
244 i!=mSurfaceCutActors.end(); i++)
245 (*i)->ToggleSuperposition();
247 //------------------------------------------------------------------------------
250 //------------------------------------------------------------------------------
251 void vvSlicer::SetCursorColor(int r,int g, int b)
253 pdmA->GetProperty()->SetColor(r,g,b);
255 //------------------------------------------------------------------------------
258 //------------------------------------------------------------------------------
259 void vvSlicer::SetCursorVisibility(bool s)
261 pdmA->SetVisibility(s);
263 //------------------------------------------------------------------------------
266 //------------------------------------------------------------------------------
267 bool vvSlicer::GetCursorVisibility()
269 return pdmA->GetVisibility();
271 //------------------------------------------------------------------------------
274 //------------------------------------------------------------------------------
275 void vvSlicer::SetCornerAnnotationVisibility(bool s)
277 ca->SetVisibility(s);
279 //------------------------------------------------------------------------------
282 //------------------------------------------------------------------------------
283 bool vvSlicer::GetCornerAnnotationVisibility()
285 return ca->GetVisibility();
287 //------------------------------------------------------------------------------
290 //------------------------------------------------------------------------------
291 vvSlicer::~vvSlicer()
293 for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
294 i!=mSurfaceCutActors.end(); i++)
296 delete [] mReducedExtent;
298 //------------------------------------------------------------------------------
300 //------------------------------------------------------------------------------
301 double* vvSlicer::GetCurrentPosition()
303 return mCurrentBeforeSlicingTransform;
305 //------------------------------------------------------------------------------
307 //------------------------------------------------------------------------------
308 void vvSlicer::SetCurrentPosition(double x, double y, double z, int t)
310 mCurrentBeforeSlicingTransform[0]=x;
311 mCurrentBeforeSlicingTransform[1]=y;
312 mCurrentBeforeSlicingTransform[2]=z;
313 mSlicingTransform->GetInverse()->TransformPoint(mCurrentBeforeSlicingTransform,mCurrent);
316 //------------------------------------------------------------------------------
319 //------------------------------------------------------------------------------
320 void vvSlicer::SetImage(vvImage::Pointer image)
322 if (image->GetVTKImages().size()) {
325 if (!mImageReslice) {
326 mImageReslice = vtkSmartPointer<vtkImageReslice>::New();
327 mImageReslice->SetInterpolationModeToLinear();
328 mImageReslice->AutoCropOutputOn();
329 mImageReslice->SetBackgroundColor(-1000,-1000,-1000,1);
332 mConcatenatedTransform->Identity();
333 mConcatenatedTransform->Concatenate(mImage->GetTransform()[0]);
334 mConcatenatedTransform->Concatenate(mSlicingTransform);
335 mImageReslice->SetResliceTransform(mConcatenatedTransform);
336 mImageReslice->SetInput(0, mImage->GetFirstVTKImageData());
337 mImageReslice->UpdateInformation();
339 this->Superclass::SetInput(mImageReslice->GetOutput());
342 this->GetInput()->GetWholeExtent(extent);
344 // Prevent crash when reload -> change slice if outside extent
345 if (Slice < extent[SliceOrientation*2] || Slice>=extent[SliceOrientation*2+1]) {
346 Slice = (extent[SliceOrientation*2+1]+extent[SliceOrientation*2])/2.0;
349 // Make sure that the required part image has been computed
350 extent[SliceOrientation*2] = Slice;
351 extent[SliceOrientation*2+1] = Slice;
352 mImageReslice->GetOutput()->SetUpdateExtent(extent);
353 mImageReslice->GetOutput()->Update();
355 this->UpdateDisplayExtent();
358 ca->SetText(0,mFileName.c_str());
361 //------------------------------------------------------------------------------
364 //------------------------------------------------------------------------------
365 void vvSlicer::SetOverlay(vvImage::Pointer overlay)
367 if (overlay->GetVTKImages().size()) {
370 if (!mOverlayReslice) {
371 mOverlayReslice = vtkSmartPointer<vtkImageReslice>::New();
372 mOverlayReslice->SetInterpolationModeToLinear();
373 mOverlayReslice->AutoCropOutputOn();
374 mOverlayReslice->SetBackgroundColor(-1000,-1000,-1000,1);
377 mConcatenatedOverlayTransform->Identity();
378 mConcatenatedOverlayTransform->Concatenate(mOverlay->GetTransform()[0]);
379 mConcatenatedOverlayTransform->Concatenate(mSlicingTransform);
380 mOverlayReslice->SetResliceTransform(mConcatenatedOverlayTransform);
381 mOverlayReslice->SetInput(0, mOverlay->GetFirstVTKImageData());
382 mImageReslice->UpdateInformation();
385 mOverlayMapper = vtkSmartPointer<vtkImageMapToWindowLevelColors>::New();
386 mOverlayMapper->SetInput(mOverlayReslice->GetOutput());
388 if (!mOverlayActor) {
389 mOverlayActor = vtkSmartPointer<vvBlendImageActor>::New();
390 mOverlayActor->SetInput(mOverlayMapper->GetOutput());
391 mOverlayActor->SetPickable(0);
392 mOverlayActor->SetVisibility(true);
393 mOverlayActor->SetOpacity(0.5);
394 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
395 mOverlayActor->GetMapper()->BorderOn();
399 //stupid but necessary : the Overlay need to be rendered before fusion
401 this->GetRenderer()->RemoveActor(mFusionActor);
402 this->GetRenderer()->AddActor(mOverlayActor);
403 this->GetRenderer()->AddActor(mFusionActor);
405 this->GetRenderer()->AddActor(mOverlayActor);
407 //Synchronize orientation and slice
408 AdjustResliceToSliceOrientation(mOverlayReslice);
409 this->UpdateDisplayExtent();
410 this->SetTSlice(mCurrentTSlice);
413 //------------------------------------------------------------------------------
416 //------------------------------------------------------------------------------
417 void vvSlicer::SetFusion(vvImage::Pointer fusion)
419 if (fusion->GetVTKImages().size()) {
422 if (!mFusionReslice) {
423 mFusionReslice = vtkSmartPointer<vtkImageReslice>::New();
424 mFusionReslice->SetInterpolationModeToLinear();
425 mFusionReslice->AutoCropOutputOn();
426 mFusionReslice->SetBackgroundColor(-1000,-1000,-1000,1);
429 mConcatenatedFusionTransform->Identity();
430 mConcatenatedFusionTransform->Concatenate(mFusion->GetTransform()[0]);
431 mConcatenatedFusionTransform->Concatenate(mSlicingTransform);
432 mFusionReslice->SetResliceTransform(mConcatenatedFusionTransform);
433 mFusionReslice->SetInput(0, mFusion->GetFirstVTKImageData());
434 mFusionReslice->UpdateInformation();
437 mFusionMapper = vtkSmartPointer<vtkImageMapToColors>::New();
439 vtkSmartPointer<vtkLookupTable> lut = vtkLookupTable::New();
441 lut->SetValueRange(0, 1);
442 lut->SetSaturationRange(0, 0);
444 mFusionMapper->SetLookupTable(lut);
445 mFusionMapper->SetInput(mFusionReslice->GetOutput());
448 mFusionActor = vtkSmartPointer<vtkImageActor>::New();
449 mFusionActor->SetInput(mFusionMapper->GetOutput());
450 mFusionActor->SetPickable(0);
451 mFusionActor->SetVisibility(true);
452 mFusionActor->SetOpacity(0.7);
453 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
454 mFusionActor->GetMapper()->BorderOn();
456 this->GetRenderer()->AddActor(mFusionActor);
459 //Synchronize orientation and slice
460 AdjustResliceToSliceOrientation(mFusionReslice);
461 this->UpdateDisplayExtent();
462 this->SetTSlice(mCurrentTSlice);
465 //------------------------------------------------------------------------------
468 //------------------------------------------------------------------------------
469 bool vvSlicer::GetActorVisibility(const std::string& actor_type, int overlay_index)
472 if (actor_type == "image") {
473 vis = this->ImageActor->GetVisibility();
475 else if (actor_type == "vector") {
476 vis = this->mVFActor->GetVisibility();
478 else if (actor_type == "overlay") {
479 vis = this->mOverlayActor->GetVisibility();
481 else if (actor_type == "fusion") {
482 vis = this->mFusionActor->GetVisibility();
484 else if (actor_type == "contour")
485 vis = this->mSurfaceCutActors[overlay_index]->GetActor()->GetVisibility();
489 //------------------------------------------------------------------------------
491 //------------------------------------------------------------------------------
492 void vvSlicer::SetActorVisibility(const std::string& actor_type, int overlay_index ,bool vis)
494 if (actor_type == "image") {
495 this->ImageActor->SetVisibility(vis);
497 else if (actor_type == "vector") {
498 this->mVFActor->SetVisibility(vis);
500 else if (actor_type == "overlay") {
501 this->mOverlayActor->SetVisibility(vis);
503 else if (actor_type == "fusion") {
504 this->mFusionActor->SetVisibility(vis);
506 else if (actor_type == "contour")
507 this->mSurfaceCutActors[overlay_index]->GetActor()->SetVisibility(vis);
508 UpdateDisplayExtent();
510 //------------------------------------------------------------------------------
512 //------------------------------------------------------------------------------
513 void vvSlicer::SetVF(vvImage::Pointer vf)
515 if (vf->GetVTKImages().size()) {
519 mAAFilter= vtkSmartPointer<vtkAssignAttribute>::New();
520 mVOIFilter = vtkSmartPointer<vtkExtractVOI>::New();
521 mVOIFilter->SetSampleRate(mSubSampling,mSubSampling,mSubSampling);
523 mVOIFilter->SetInput(vf->GetFirstVTKImageData());
524 mAAFilter->SetInput(mVOIFilter->GetOutput());
525 ///This tells VTK to use the scalar (pixel) data of the image to draw the little arrows
526 mAAFilter->Assign(vtkDataSetAttributes::SCALARS, vtkDataSetAttributes::VECTORS, vtkAssignAttribute::POINT_DATA);
529 mArrow = vtkSmartPointer<vvGlyphSource>::New();
530 mArrow->SetGlyphTypeToSpecificArrow();
531 mArrow->SetScale(mScale);
534 // Glyph the gradient vector (with arrows)
536 mGlyphFilter = vtkSmartPointer<vvGlyph2D>::New();
537 mGlyphFilter->SetInput(mAAFilter->GetOutput());
538 mGlyphFilter->SetSource(mArrow->GetOutput());
539 mGlyphFilter->ScalingOn();
540 mGlyphFilter->SetScaleModeToScaleByVector();
541 mGlyphFilter->OrientOn();
542 mGlyphFilter->SetVectorModeToUseVector();
543 mGlyphFilter->SetColorModeToColorByVector();
546 mVFColorLUT = vtkSmartPointer<vtkLookupTable>::New();
548 double mVFColorHSV[3];
549 vtkMath::RGBToHSV(mVFColor, mVFColorHSV);
550 mVFColorLUT->SetHueRange(mVFColorHSV[0], mVFColorHSV[0]);
551 mVFColorLUT->SetSaturationRange(mVFColorHSV[1],mVFColorHSV[1]);
552 mVFColorLUT->SetValueRange(mVFColorHSV[2], mVFColorHSV[2]);
555 mVFMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
556 mVFMapper->SetInput(mGlyphFilter->GetOutput());
557 mVFMapper->ImmediateModeRenderingOn();
558 mVFMapper->SetLookupTable(mVFColorLUT);
561 mVFActor = vtkSmartPointer<vtkActor>::New();
562 mVFActor->SetMapper(mVFMapper);
563 mVFActor->SetPickable(0);
564 mVFActor->GetProperty()->SetLineWidth(mVFWidth);
565 this->UpdateDisplayExtent();
566 this->GetRenderer()->AddActor(mVFActor);
569 SetTSlice(mCurrentTSlice);
572 //------------------------------------------------------------------------------
575 //------------------------------------------------------------------------------
576 void vvSlicer::SetLandmarks(vvLandmarks* landmarks)
578 mLandmarks = landmarks;
582 mCross = vtkSmartPointer<vtkCursor3D>::New();
583 mCross->SetFocalPoint(0.0,0.0,0.0);
584 mCross->SetModelBounds(-10,10,-10,10,-10,10);
589 mLandGlyph = vtkSmartPointer<vtkGlyph3D>::New();
590 mLandGlyph->SetSource(mCross->GetOutput());
591 mLandGlyph->SetInput(landmarks->GetOutput());
592 //mLandGlyph->SetIndexModeToScalar();
593 mLandGlyph->SetRange(0,1);
594 mLandGlyph->ScalingOff();
596 mLandGlyph->SetColorModeToColorByScalar();
599 mClipBox = vtkSmartPointer<vtkBox>::New();
601 mLandClipper = vtkSmartPointer<vtkClipPolyData>::New();
602 mLandClipper->InsideOutOn();
603 mLandClipper->SetInput(mLandGlyph->GetOutput());
604 mLandClipper->SetClipFunction(mClipBox);
607 mLandMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
608 mLandMapper->SetInputConnection(mLandClipper->GetOutputPort());
609 //mLandMapper->ScalarVisibilityOff();
612 mLandActor = vtkSmartPointer<vtkActor>::New();
613 mLandActor->SetMapper(mLandMapper);
614 mLandActor->GetProperty()->SetColor(255,10,212);
615 mLandActor->SetPickable(0);
616 mLandActor->SetVisibility(true);
617 this->UpdateDisplayExtent();
618 this->GetRenderer()->AddActor(mLandActor);
621 //------------------------------------------------------------------------------
623 //------------------------------------------------------------------------------
624 //FIXME: this function leaks memory, we should fix it someday :)
625 void vvSlicer::RemoveActor(const std::string& actor_type, int overlay_index)
627 if (actor_type == "vector") {
628 Renderer->RemoveActor(mVFActor);
637 if (actor_type == "overlay") {
638 Renderer->RemoveActor(mOverlayActor);
640 mOverlayActor = NULL;
641 mOverlayMapper = NULL;
643 if (actor_type == "fusion") {
644 Renderer->RemoveActor(mFusionActor);
647 mFusionMapper = NULL;
649 if (actor_type == "contour") {
650 Renderer->RemoveActor(this->mSurfaceCutActors[overlay_index]->GetActor());
651 mSurfaceCutActors.erase(mSurfaceCutActors.begin()+overlay_index);
654 //------------------------------------------------------------------------------
657 //------------------------------------------------------------------------------
658 void vvSlicer::SetVFSubSampling(int sub)
661 mVOIFilter->SetSampleRate(mSubSampling,mSubSampling,mSubSampling);
664 UpdateDisplayExtent();
667 //------------------------------------------------------------------------------
670 //------------------------------------------------------------------------------
671 void vvSlicer::SetVFScale(int scale)
675 mArrow->SetScale(mScale);
676 UpdateDisplayExtent();
679 //------------------------------------------------------------------------------
681 //------------------------------------------------------------------------------
682 void vvSlicer::SetVFWidth(int width)
686 mVFActor->GetProperty()->SetLineWidth(mVFWidth);
687 UpdateDisplayExtent();
690 //------------------------------------------------------------------------------
693 //------------------------------------------------------------------------------
694 void vvSlicer::SetVFLog(int log)
698 mGlyphFilter->SetUseLog(mVFLog);
699 mGlyphFilter->Modified();
701 UpdateDisplayExtent();
704 //------------------------------------------------------------------------------
707 //------------------------------------------------------------------------------
708 void vvSlicer::SetTSlice(int t)
712 else if ((unsigned int)t >= mImage->GetVTKImages().size())
713 mCurrentTSlice = mImage->GetVTKImages().size() -1;
718 mConcatenatedTransform->Identity();
719 mConcatenatedTransform->Concatenate(mImage->GetTransform()[mCurrentTSlice]);
720 mConcatenatedTransform->Concatenate(mSlicingTransform);
723 mImageReslice->SetInput( mImage->GetVTKImages()[mCurrentTSlice] );
724 if (mVF && mVFActor->GetVisibility()) {
725 if (mVF->GetVTKImages().size() > (unsigned int)mCurrentTSlice)
726 mVOIFilter->SetInput(mVF->GetVTKImages()[mCurrentTSlice]);
728 if (mOverlay && mOverlayActor->GetVisibility()) {
729 if (mOverlay->GetVTKImages().size() > (unsigned int)t) {
730 mCurrentOverlayTSlice = t;
731 mOverlayReslice->SetInput( mOverlay->GetVTKImages()[mCurrentOverlayTSlice] );
733 // Update overlay transform
734 mConcatenatedOverlayTransform->Identity();
735 mConcatenatedOverlayTransform->Concatenate(mOverlay->GetTransform()[mCurrentOverlayTSlice]);
736 mConcatenatedOverlayTransform->Concatenate(mSlicingTransform);
739 if (mFusion && mFusionActor->GetVisibility()) {
740 if (mFusion->GetVTKImages().size() > (unsigned int)t) {
741 mCurrentFusionTSlice = t;
742 mFusionReslice->SetInput( mFusion->GetVTKImages()[mCurrentFusionTSlice]);
744 // Update fusion transform
745 mConcatenatedFusionTransform->Identity();
746 mConcatenatedFusionTransform->Concatenate(mFusion->GetTransform()[mCurrentFusionTSlice]);
747 mConcatenatedFusionTransform->Concatenate(mSlicingTransform);
750 if (mSurfaceCutActors.size() > 0)
751 for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
752 i!=mSurfaceCutActors.end(); i++)
753 (*i)->SetTimeSlice(mCurrentTSlice);
754 UpdateDisplayExtent();
756 //------------------------------------------------------------------------------
759 //------------------------------------------------------------------------------
760 int vvSlicer::GetTSlice()
762 return mCurrentTSlice;
764 //------------------------------------------------------------------------------
766 //------------------------------------------------------------------------------
767 int vvSlicer::GetMaxCurrentTSlice()
769 int t = mCurrentTSlice;
771 t = std::max(t, mCurrentOverlayTSlice);
773 t = std::max(t, mCurrentFusionTSlice);
776 //------------------------------------------------------------------------------
778 //------------------------------------------------------------------------------
779 int vvSlicer::GetFusionTSlice()
781 return mCurrentFusionTSlice;
783 //------------------------------------------------------------------------------
785 //------------------------------------------------------------------------------
786 int vvSlicer::GetOverlayTSlice()
788 return mCurrentOverlayTSlice;
790 //------------------------------------------------------------------------------
792 //------------------------------------------------------------------------------
793 void vvSlicer::SetSliceOrientation(int orientation)
795 //if 2D image, force to watch in Axial View
797 this->GetInput()->GetWholeExtent(extent);
798 if (extent[5]-extent[4] <= 2)
799 orientation = vtkImageViewer2::SLICE_ORIENTATION_XY;
801 if (orientation < vtkImageViewer2::SLICE_ORIENTATION_YZ ||
802 orientation > vtkImageViewer2::SLICE_ORIENTATION_XY) {
803 vtkErrorMacro("Error - invalid slice orientation " << orientation);
807 this->SliceOrientation = orientation;
810 AdjustResliceToSliceOrientation(mFusionReslice);
813 AdjustResliceToSliceOrientation(mOverlayReslice);
816 int *range = this->GetSliceRange();
818 this->Slice = static_cast<int>((range[0] + range[1]) * 0.5);
820 // Go to current cursor position
821 // double* cursorPos = GetCursorPosition();
822 // DDV(cursorPos, 3);
823 // SetCurrentPosition(cursorPos[0],cursorPos[1],cursorPos[2],cursorPos[3]);
825 this->UpdateOrientation();
826 this->UpdateDisplayExtent();
828 if (this->Renderer && this->GetInput()) {
829 double scale = this->Renderer->GetActiveCamera()->GetParallelScale();
830 this->Renderer->ResetCamera();
831 this->Renderer->GetActiveCamera()->SetParallelScale(scale);
836 //----------------------------------------------------------------------------
838 //------------------------------------------------------------------------------
839 // This function ensures that we sample the slices of a vtkImageReslice filter
840 // in the direction of the slicer (SliceOrientation) similarly as mImageReslice.
841 // In other words, we change the grid of the reslice in the same way as the grid
842 // of the displayed image in the slicing direction.
843 void vvSlicer::AdjustResliceToSliceOrientation(vtkImageReslice *reslice)
845 // Reset autocrop and update output information
846 reslice->SetOutputOriginToDefault();
847 reslice->SetOutputSpacingToDefault();
848 reslice->GetOutput()->UpdateInformation();
850 // Ge new origin / spacing
853 reslice->GetOutput()->GetOrigin(origin);
854 reslice->GetOutput()->GetSpacing(spacing);
856 // Use similar spacing as the image in the direction SliceOrientation
857 spacing[this->SliceOrientation] = mImageReslice->GetOutput()->GetSpacing()[this->SliceOrientation];
859 // Modify origin to be on the image grid in the direction SliceOrientation in 3 steps
860 // Step 1: from world coordinates to image coordinates
861 origin[this->SliceOrientation] -= mImageReslice->GetOutput()->GetOrigin()[this->SliceOrientation];
862 origin[this->SliceOrientation] /= mImageReslice->GetOutput()->GetSpacing()[this->SliceOrientation];
863 // Step 2: round to superior grid positionInc
864 origin[this->SliceOrientation] = itk::Math::Ceil<double>(origin[this->SliceOrientation]);
865 // Step 3: back to world coordinates
866 origin[this->SliceOrientation] *= mImageReslice->GetOutput()->GetSpacing()[this->SliceOrientation];
867 origin[this->SliceOrientation] += mImageReslice->GetOutput()->GetOrigin()[this->SliceOrientation];
869 // Set new spacing and origin
870 reslice->SetOutputOrigin(origin);
871 reslice->SetOutputSpacing(spacing);
872 reslice->UpdateInformation();
873 reslice->GetOutput()->UpdateInformation();
875 //------------------------------------------------------------------------------
877 //----------------------------------------------------------------------------
878 int * vvSlicer::GetExtent(){
880 if (mUseReducedExtent) {
881 w_ext = mReducedExtent;
882 } else w_ext = GetInput()->GetWholeExtent();
885 //----------------------------------------------------------------------------
888 //----------------------------------------------------------------------------
889 int vvSlicer::GetOrientation()
891 return this->SliceOrientation;
893 //----------------------------------------------------------------------------
896 //----------------------------------------------------------------------------
897 void vvSlicer::UpdateDisplayExtent()
899 vtkImageData *input = this->GetInput();
900 if (!input || !this->ImageActor) {
903 input->UpdateInformation();
905 // Local copy of extent
907 int* ext = GetExtent();
908 copyExtent(ext, w_ext);
910 int s = this->Slice > ext[this->SliceOrientation*2+1] ? ext[this->SliceOrientation*2 + 1] : this->Slice;
911 w_ext[ this->SliceOrientation*2 ] = s;
912 w_ext[ this->SliceOrientation*2+1 ] = s;
915 this->ImageActor->SetDisplayExtent(w_ext);
917 // Overlay image actor
918 if (mOverlay && mOverlayActor->GetVisibility()) {
919 AdjustResliceToSliceOrientation(mOverlayReslice);
921 this->ConvertImageToImageDisplayExtent(input, w_ext, mOverlayReslice->GetOutput(), overExtent);
922 ClipDisplayedExtent(overExtent, mOverlayMapper->GetInput()->GetWholeExtent());
923 mOverlayActor->SetDisplayExtent( overExtent );
926 // Fusion image actor
927 if (mFusion && mFusionActor->GetVisibility()) {
928 AdjustResliceToSliceOrientation(mFusionReslice);
930 this->ConvertImageToImageDisplayExtent(input, w_ext, mFusionReslice->GetOutput(), fusExtent);
931 ClipDisplayedExtent(fusExtent, mFusionMapper->GetInput()->GetWholeExtent());
932 mFusionActor->SetDisplayExtent(fusExtent);
935 // Vector field actor
936 double* camera = Renderer->GetActiveCamera()->GetPosition();
937 double* image_bounds = ImageActor->GetBounds();
938 double position[3] = {0, 0, 0};
939 position[this->SliceOrientation] = image_bounds[this->SliceOrientation*2];
941 //print_vector<double, 6>("camera", camera);
942 //print_vector<double, 6>("image_bounds", image_bounds);
943 //print_vector<double, 3>("position", position);
945 // find where to place the VF actor. to deal with
946 // z-buffer issues, the VF is placed right in front of the image,
947 // subject to a small offset. the position actually depends on the
948 // the location of the camera relative to the image.
950 if (camera[this->SliceOrientation] < image_bounds[this->SliceOrientation*2])
953 if (mVF && mVFActor->GetVisibility()) {
955 mVF->GetVTKImages()[0]->UpdateInformation();
956 this->ConvertImageToImageDisplayExtent(input, w_ext, mVF->GetVTKImages()[0], vfExtent);
957 ClipDisplayedExtent(vfExtent, mVOIFilter->GetInput()->GetWholeExtent());
958 mVOIFilter->SetVOI(vfExtent);
959 int orientation[3] = {1,1,1};
960 orientation[this->SliceOrientation] = 0;
961 mGlyphFilter->SetOrientation(orientation[0], orientation[1], orientation[2]);
964 position[this->SliceOrientation] += offset;
965 mVFActor->SetPosition(position);
972 for(unsigned int i=0; i<6; i++)
973 bounds[i] = ImageActor->GetBounds()[i];
974 bounds[ this->SliceOrientation*2 ] = ImageActor->GetBounds()[ this->SliceOrientation*2 ]-fabs(this->GetInput()->GetSpacing()[this->SliceOrientation]);
975 bounds[ this->SliceOrientation*2+1 ] = ImageActor->GetBounds()[ this->SliceOrientation*2+1 ]+fabs(this->GetInput()->GetSpacing()[this->SliceOrientation]);
976 mClipBox->SetBounds(bounds);
980 position[this->SliceOrientation] = offset;
981 mLandActor->SetPosition(position);
984 // Figure out the correct clipping range
985 if (this->Renderer) {
986 if (this->InteractorStyle &&
987 this->InteractorStyle->GetAutoAdjustCameraClippingRange()) {
988 this->Renderer->ResetCameraClippingRange();
990 vtkCamera *cam = this->Renderer->GetActiveCamera();
993 this->ImageActor->GetBounds(bounds);
994 double spos = (double)bounds[this->SliceOrientation * 2];
995 double cpos = (double)cam->GetPosition()[this->SliceOrientation];
996 double range = fabs(spos - cpos);
997 double *spacing = input->GetSpacing();
998 double sumSpacing = spacing[0] + spacing[1] + spacing[2];
999 cam->SetClippingRange(range - sumSpacing, range + sumSpacing);
1005 //----------------------------------------------------------------------------
1007 //----------------------------------------------------------------------------
1008 void vvSlicer::ConvertImageToImageDisplayExtent(vtkImageData *sourceImage, const int sourceExtent[6],
1009 vtkImageData *targetImage, int targetExtent[6])
1012 for(unsigned int i=0; i<6; i++) {
1013 // From source voxel coordinates to world coordinates
1014 dExtents[i] = sourceImage->GetOrigin()[i/2] + sourceImage->GetSpacing()[i/2] * sourceExtent[i];
1016 // From world coordinates to floating point target voxel coordinates
1017 dExtents[i] = (dExtents[i]- targetImage->GetOrigin()[i/2]) / targetImage->GetSpacing()[i/2];
1020 //targetExtent[i] = itk::Math::Round<double>(dExtents[i]);
1021 targetExtent[i] = itk::Math::Floor<double>(dExtents[i]);
1024 //----------------------------------------------------------------------------
1026 //----------------------------------------------------------------------------
1027 void vvSlicer::ClipDisplayedExtent(int extent[6], int refExtent[6])
1032 //2D overlay on 3D image specific case
1033 if (refExtent[4] == refExtent[5]) {
1035 extent[4] = refExtent[4];
1036 extent[5] = refExtent[5];
1039 for (int i = 0; i < maxBound; i = i+2) {
1040 //if we are totally outside the image
1041 if ( extent[i] > refExtent[i+1] || extent[i+1] < refExtent[i] ) {
1045 //crop to the limit of the image
1046 extent[i] = (extent[i] > refExtent[i]) ? extent[i] : refExtent[i];
1047 extent[i] = (extent[i] < refExtent[i+1]) ? extent[i] : refExtent[i+1];
1048 extent[i+1] = (extent[i+1] > refExtent[i]) ? extent[i+1] : refExtent[i];
1049 extent[i+1] = (extent[i+1] < refExtent[i+1]) ? extent[i+1] : refExtent[i+1];
1052 for (int i = 0; i < maxBound; i = i+2) {
1053 extent[i] = refExtent[i];
1054 extent[i+1] = refExtent[i];
1057 //----------------------------------------------------------------------------
1060 //----------------------------------------------------------------------------
1061 void vvSlicer::UpdateOrientation()
1063 // Set the camera position
1064 vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
1066 switch (this->SliceOrientation) {
1067 case vtkImageViewer2::SLICE_ORIENTATION_XY:
1068 cam->SetFocalPoint(0,0,0);
1069 cam->SetPosition(0,0,-1); // -1 if medical ?
1070 cam->SetViewUp(0,-1,0);
1073 case vtkImageViewer2::SLICE_ORIENTATION_XZ:
1074 cam->SetFocalPoint(0,0,0);
1075 cam->SetPosition(0,-1,0); // 1 if medical ?
1076 cam->SetViewUp(0,0,1);
1079 case vtkImageViewer2::SLICE_ORIENTATION_YZ:
1080 cam->SetFocalPoint(0,0,0);
1081 cam->SetPosition(-1,0,0); // -1 if medical ?
1082 cam->SetViewUp(0,0,1);
1087 //----------------------------------------------------------------------------
1090 //----------------------------------------------------------------------------
1091 void vvSlicer::SetOpacity(double s)
1093 this->GetImageActor()->SetOpacity(s);
1095 //----------------------------------------------------------------------------
1098 //----------------------------------------------------------------------------
1099 void vvSlicer::SetRenderWindow(int orientation, vtkRenderWindow * rw)
1101 this->Superclass::SetRenderWindow(rw);
1102 this->SetupInteractor(rw->GetInteractor());
1103 ca->SetImageActor(this->GetImageActor());
1104 ca->SetWindowLevel(this->GetWindowLevel());
1105 ca->SetText(2, "<slice>");
1106 ca->SetText(3, "<window>\n<level>");
1118 crossCursor->SetModelBounds(bounds);
1119 this->GetRenderer()->AddActor(pdmA);
1120 this->GetRenderer()->AddActor(ca);
1121 this->GetRenderer()->ResetCamera();
1123 //this is just a mapping between the labeling of the orientations presented to the user and
1124 //the one used by vtk
1125 SetSliceOrientation(2-(orientation%3));
1128 //----------------------------------------------------------------------------
1131 //----------------------------------------------------------------------------
1132 void vvSlicer::ResetCamera()
1134 this->GetRenderer()->ResetCamera();
1136 //----------------------------------------------------------------------------
1139 //----------------------------------------------------------------------------
1140 void vvSlicer::SetDisplayMode(bool i)
1142 this->GetRenderer()->SetDraw(i);
1144 UpdateDisplayExtent();
1146 //----------------------------------------------------------------------------
1149 //----------------------------------------------------------------------------
1150 void vvSlicer::FlipHorizontalView()
1152 vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
1154 double *position = cam->GetPosition();
1155 double factor[3] = {1, 1, 1};
1156 factor[this->SliceOrientation] = -1;
1157 cam->SetPosition(factor[0]*position[0],factor[1]*position[1],factor[2]*position[2]);
1159 /* switch (this->SliceOrientation) {
1160 case vtkImageViewer2::SLICE_ORIENTATION_XY:
1161 cam->SetPosition(position[0],position[1],-position[2]);
1164 case vtkImageViewer2::SLICE_ORIENTATION_XZ:
1165 cam->SetPosition(position[0],-position[1],position[2]);
1168 case vtkImageViewer2::SLICE_ORIENTATION_YZ:
1169 cam->SetPosition(-position[0],position[1],position[2]);
1173 this->Renderer->ResetCameraClippingRange();
1174 this->UpdateDisplayExtent();
1177 //----------------------------------------------------------------------------
1180 //----------------------------------------------------------------------------
1181 void vvSlicer::FlipVerticalView()
1183 vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
1185 FlipHorizontalView();
1186 double *viewup = cam->GetViewUp();
1187 cam->SetViewUp(-viewup[0],-viewup[1],-viewup[2]);
1188 this->UpdateDisplayExtent();
1191 //----------------------------------------------------------------------------
1194 //----------------------------------------------------------------------------
1195 void vvSlicer::SetColorWindow(double window)
1197 vtkLookupTable* LUT = static_cast<vtkLookupTable*>(this->GetWindowLevel()->GetLookupTable());
1199 double level = this->GetWindowLevel()->GetLevel();
1200 LUT->SetTableRange(level-fabs(window)/2,level+fabs(window)/2);
1203 this->vtkImageViewer2::SetColorWindow(window);
1205 //----------------------------------------------------------------------------
1207 //----------------------------------------------------------------------------
1208 void vvSlicer::SetColorLevel(double level)
1210 vtkLookupTable* LUT = static_cast<vtkLookupTable*>(this->GetWindowLevel()->GetLookupTable());
1212 double window = this->GetWindowLevel()->GetWindow();
1213 LUT->SetTableRange(level-fabs(window)/2,level+fabs(window)/2);
1216 this->vtkImageViewer2::SetColorLevel(level);
1218 //----------------------------------------------------------------------------
1220 //----------------------------------------------------------------------------
1221 double vvSlicer::GetOverlayColorWindow()
1224 return mOverlayMapper->GetWindow();
1228 //----------------------------------------------------------------------------
1230 //----------------------------------------------------------------------------
1231 double vvSlicer::GetOverlayColorLevel()
1234 return mOverlayMapper->GetLevel();
1238 //----------------------------------------------------------------------------
1240 //----------------------------------------------------------------------------
1241 void vvSlicer::SetOverlayColorWindow(double window)
1243 mOverlayMapper->SetWindow(window);
1245 //----------------------------------------------------------------------------
1247 //----------------------------------------------------------------------------
1248 void vvSlicer::SetOverlayColorLevel(double level)
1250 mOverlayMapper->SetLevel(level);
1252 //----------------------------------------------------------------------------
1254 //----------------------------------------------------------------------------
1255 // Returns the min an the max value in a 20%x20% region around the mouse pointer
1256 void vvSlicer::GetExtremasAroundMousePointer(double & min, double & max, vtkImageData *image, vtkTransform *transform)
1258 //Get mouse pointer position in view coordinates
1261 for(int i=0; i<3; i++) {
1262 corner1[i] = mCurrent[i];
1263 corner2[i] = mCurrent[i];
1266 this->Renderer->WorldToView(corner1[0], corner1[1], corner1[2]);
1267 this->Renderer->WorldToView(corner2[0], corner2[1], corner2[2]);
1269 // In view coordinates, x is the slicer width and y is the slicer height are the in-plane axis
1271 this->Renderer->GetTiledSize(&w, &h);
1272 corner1[0] -= 0.2*h/(double)w;
1273 corner2[0] += 0.2*h/(double)w;
1276 this->Renderer->ViewToWorld(corner1[0], corner1[1], corner1[2]);
1277 this->Renderer->ViewToWorld(corner2[0], corner2[1], corner2[2]);
1279 //Convert to image pixel coordinates (rounded)
1280 transform->TransformPoint(corner1, corner1);
1281 transform->TransformPoint(corner2, corner2);
1282 int iLocalExtents[6];
1283 for(int i=0; i<3; i++) {
1284 corner1[i] = (corner1[i] - image->GetOrigin()[i])/image->GetSpacing()[i];
1285 corner2[i] = (corner2[i] - image->GetOrigin()[i])/image->GetSpacing()[i];
1287 iLocalExtents[i*2 ] = lrint(corner1[i]);
1288 iLocalExtents[i*2+1] = lrint(corner2[i]);
1290 if(iLocalExtents[i*2 ]>iLocalExtents[i*2+1])
1291 std::swap(iLocalExtents[i*2], iLocalExtents[i*2+1]);
1294 vtkSmartPointer<vtkExtractVOI> voiFilter = vtkSmartPointer<vtkExtractVOI>::New();
1295 voiFilter->SetInput(image);
1296 voiFilter->SetVOI(iLocalExtents);
1297 voiFilter->Update();
1298 if (!voiFilter->GetOutput()->GetNumberOfPoints()) {
1304 vtkSmartPointer<vtkImageAccumulate> accFilter = vtkSmartPointer<vtkImageAccumulate>::New();
1305 accFilter->SetInput(voiFilter->GetOutput());
1306 accFilter->Update();
1308 min = *(accFilter->GetMin());
1309 max = *(accFilter->GetMax());
1311 //----------------------------------------------------------------------------
1313 //----------------------------------------------------------------------------
1314 double vvSlicer::GetScalarComponentAsDouble(vtkImageData *image, double X, double Y, double Z, int &ix, int &iy, int &iz, int component)
1319 if (ix < image->GetWholeExtent()[0] ||
1320 ix > image->GetWholeExtent()[1] ||
1321 iy < image->GetWholeExtent()[2] ||
1322 iy > image->GetWholeExtent()[3] ||
1323 iz < image->GetWholeExtent()[4] ||
1324 iz > image->GetWholeExtent()[5] )
1325 return std::numeric_limits<double>::quiet_NaN();
1327 image->SetUpdateExtent(ix, ix, iy, iy, iz, iz);
1329 return image->GetScalarComponentAsDouble(ix, iy, iz, component);
1331 //----------------------------------------------------------------------------
1333 //----------------------------------------------------------------------------
1334 void vvSlicer::Render()
1336 if (this->mFusion && mFusionActor->GetVisibility() && showFusionLegend) {
1337 legend->SetLookupTable(this->GetFusionMapper()->GetLookupTable());
1338 legend->UseOpacityOn();
1339 legend->SetVisibility(1);
1341 else if (this->GetWindowLevel()->GetLookupTable() && !this->mOverlay) {
1342 legend->SetLookupTable(this->GetWindowLevel()->GetLookupTable());
1343 legend->UseOpacityOff();
1344 legend->SetVisibility(1);
1345 } else legend->SetVisibility(0);
1347 if (ca->GetVisibility()) {
1348 std::stringstream worldPos;
1350 mConcatenatedTransform->TransformPoint(mCurrent, pt);
1351 double X = (pt[0] - mImage->GetVTKImages()[mCurrentTSlice]->GetOrigin()[0])/mImage->GetVTKImages()[mCurrentTSlice]->GetSpacing()[0];
1352 double Y = (pt[1] - mImage->GetVTKImages()[mCurrentTSlice]->GetOrigin()[1])/mImage->GetVTKImages()[mCurrentTSlice]->GetSpacing()[1];
1353 double Z = (pt[2] - mImage->GetVTKImages()[mCurrentTSlice]->GetOrigin()[2])/mImage->GetVTKImages()[mCurrentTSlice]->GetSpacing()[2];
1355 if (X >= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[0]-0.5 &&
1356 X <= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[1]+0.5 &&
1357 Y >= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[2]-0.5 &&
1358 Y <= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[3]+0.5 &&
1359 Z >= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[4]-0.5 &&
1360 Z <= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[5]+0.5) {
1364 double value = this->GetScalarComponentAsDouble(mImage->GetVTKImages()[mCurrentTSlice], X, Y, Z, ix, iy, iz);
1366 if(ImageActor->GetVisibility())
1367 worldPos << "data value : " << value << std::endl;
1369 worldPos << "mm : " << lrint(mCurrentBeforeSlicingTransform[0]) << ' '
1370 << lrint(mCurrentBeforeSlicingTransform[1]) << ' '
1371 << lrint(mCurrentBeforeSlicingTransform[2]) << ' '
1374 worldPos << "pixel : " << ix << ' '
1380 ca->SetText(1,worldPos.str().c_str());
1383 if (pdmA->GetVisibility()) {
1384 double x = mCursor[0];
1385 double y = mCursor[1];
1386 double z = mCursor[2];
1387 double xCursor = (x - this->GetInput()->GetOrigin()[0])/this->GetInput()->GetSpacing()[0];
1388 double yCursor = (y - this->GetInput()->GetOrigin()[1])/this->GetInput()->GetSpacing()[1];
1389 double zCursor = (z - this->GetInput()->GetOrigin()[2])/this->GetInput()->GetSpacing()[2];
1391 if (xCursor >= this->GetImageActor()->GetDisplayExtent()[0] &&
1392 xCursor < this->GetImageActor()->GetDisplayExtent()[1]+1 &&
1393 yCursor >= this->GetImageActor()->GetDisplayExtent()[2] &&
1394 yCursor < this->GetImageActor()->GetDisplayExtent()[3]+1 &&
1395 zCursor >= this->GetImageActor()->GetDisplayExtent()[4] &&
1396 zCursor < this->GetImageActor()->GetDisplayExtent()[5]+1 ) {
1397 vtkRenderer * renderer = this->Renderer;
1399 renderer->WorldToView(x,y,z);
1400 renderer->ViewToNormalizedViewport(x,y,z);
1401 renderer->NormalizedViewportToViewport(x,y);
1402 renderer->ViewportToNormalizedDisplay(x,y);
1403 renderer->NormalizedDisplayToDisplay(x,y);
1404 crossCursor->SetFocalPoint(x,y,z);
1406 crossCursor->SetFocalPoint(-1,-1,z);
1410 if (mOverlay && mOverlayActor->GetVisibility()) {
1411 if(mLinkOverlayWindowLevel) {
1412 mOverlayMapper->SetWindow(this->GetColorWindow());
1413 mOverlayMapper->SetLevel(this->GetColorLevel());
1415 mOverlayMapper->GetOutput()->SetUpdateExtent(mOverlayActor->GetDisplayExtent());
1416 mOverlayMapper->GetOutput()->Update();
1417 mOverlayMapper->Update();
1422 this->GetRenderWindow()->Render();
1424 //----------------------------------------------------------------------------
1427 //----------------------------------------------------------------------------
1428 void vvSlicer::UpdateCursorPosition()
1430 pdmA->SetVisibility(true);
1431 mCursor[0] = mCurrent[0];
1432 mCursor[1] = mCurrent[1];
1433 mCursor[2] = mCurrent[2];
1434 mCursor[3] = mCurrentTSlice;
1436 //----------------------------------------------------------------------------
1439 //----------------------------------------------------------------------------
1440 void vvSlicer::UpdateLandmarks()
1442 vtkPolyData *pd = static_cast<vtkPolyData*>(mLandClipper->GetInput());
1443 if (pd->GetPoints()) {
1444 mLandGlyph->SetRange(0,1);
1445 mLandGlyph->Modified();
1446 mLandGlyph->Update();
1448 mClipBox->Modified();
1449 mLandClipper->Update();
1450 mLandMapper->Update();
1454 //----------------------------------------------------------------------------
1457 //----------------------------------------------------------------------------
1458 void vvSlicer::SetSlice(int slice)
1460 int *range = this->GetSliceRange();
1462 if (slice < range[0]) {
1464 } else if (slice > range[1]) {
1469 if (this->Slice == slice) {
1473 this->Slice = slice;
1476 this->UpdateDisplayExtent();
1478 // Seems to work without this line
1481 //----------------------------------------------------------------------------
1483 //----------------------------------------------------------------------------
1484 int vvSlicer::GetTMax() {
1485 int tmax = (int)mImage->GetVTKImages().size() - 1;
1487 tmax = std::max(tmax, (int)mOverlay->GetVTKImages().size()-1);
1490 //----------------------------------------------------------------------------
1492 //----------------------------------------------------------------------------
1493 void vvSlicer::SetContourSlice()
1495 if (mSurfaceCutActors.size() > 0)
1496 for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
1497 i!=mSurfaceCutActors.end(); i++) {
1499 (*i)->SetSlicingOrientation(this->SliceOrientation);
1500 (*i)->SetCutSlice((this->Slice)*this->GetImage()->GetSpacing()[this->SliceOrientation]+
1501 this->GetImage()->GetOrigin()[this->SliceOrientation]);
1504 //----------------------------------------------------------------------------
1507 //----------------------------------------------------------------------------
1508 void vvSlicer::ForceUpdateDisplayExtent()
1510 this->UpdateDisplayExtent();
1512 //----------------------------------------------------------------------------
1515 //----------------------------------------------------------------------------
1516 int* vvSlicer::GetDisplayExtent()
1518 return this->GetImageActor()->GetDisplayExtent();
1520 //----------------------------------------------------------------------------
1523 //----------------------------------------------------------------------------
1524 void vvSlicer::PrintSelf(ostream& os, vtkIndent indent)
1526 this->Superclass::PrintSelf(os, indent);
1528 //----------------------------------------------------------------------------
1530 //----------------------------------------------------------------------------
1531 void vvSlicer::SetVFColor(double r, double g, double b)
1533 double mVFColorHSV[3];
1538 vtkMath::RGBToHSV(mVFColor, mVFColorHSV);
1539 mVFColorLUT->SetHueRange(mVFColorHSV[0], mVFColorHSV[0]);
1540 mVFColorLUT->SetSaturationRange(mVFColorHSV[1],mVFColorHSV[1]);
1541 mVFColorLUT->SetValueRange(mVFColorHSV[2], mVFColorHSV[2]);