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"
25 #include <vtkTextProperty.h>
26 #include <vtkTextActor.h>
27 #include <vtkTextSource.h>
28 #include <vtkActor2D.h>
29 #include <vtkCursor2D.h>
30 #include <vtkPolyDataMapper2D.h>
31 #include <vtkProperty2D.h>
32 #include <vtkCornerAnnotation.h>
33 #include <vtkImageMapToWindowLevelColors.h>
34 #include <vtkImageData.h>
35 #include <vtkImageActor.h>
36 #include <vvBlendImageActor.h>
37 #include <vtkToolkits.h>
38 #include <vtkObjectFactory.h>
39 #include <vtkPointData.h>
40 #include <vtkDataArray.h>
41 #include <vtkFloatArray.h>
42 #include <vtkClipPolyData.h>
43 #include <vtkActor2DCollection.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] = 0;//-VTK_DOUBLE_MAX;
94 mCursor[1] = 0;//-VTK_DOUBLE_MAX;
95 mCursor[2] = 0;//-VTK_DOUBLE_MAX;
96 mCursor[3] = 0;//-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->InstallPipeline();
142 mLinkOverlayWindowLevel = true;
144 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
145 this->GetImageActor()->GetMapper()->BorderOn();
148 mSlicingTransform = vtkSmartPointer<vtkTransform>::New();
149 mConcatenatedTransform = vtkSmartPointer<vtkTransform>::New();
150 mConcatenatedFusionTransform = vtkSmartPointer<vtkTransform>::New();
151 mConcatenatedOverlayTransform = vtkSmartPointer<vtkTransform>::New();
153 //------------------------------------------------------------------------------
156 //------------------------------------------------------------------------------
157 vtkImageMapToWindowLevelColors* vvSlicer::GetOverlayMapper()
159 return mOverlayMapper.GetPointer();
161 //------------------------------------------------------------------------------
164 //------------------------------------------------------------------------------
165 vvBlendImageActor* vvSlicer::GetOverlayActor()
167 return mOverlayActor.GetPointer();
169 //------------------------------------------------------------------------------
172 //------------------------------------------------------------------------------
173 vtkImageMapToColors* vvSlicer::GetFusionMapper()
175 return mFusionMapper.GetPointer();
177 //------------------------------------------------------------------------------
180 //------------------------------------------------------------------------------
181 vtkImageActor* vvSlicer::GetFusionActor()
183 return mFusionActor.GetPointer();
185 //------------------------------------------------------------------------------
188 //------------------------------------------------------------------------------
189 vtkActor* vvSlicer::GetVFActor()
191 return mVFActor.GetPointer();
193 //------------------------------------------------------------------------------
196 //------------------------------------------------------------------------------
197 vtkCornerAnnotation* vvSlicer::GetAnnotation()
199 return ca.GetPointer();
201 //------------------------------------------------------------------------------
204 //------------------------------------------------------------------------------
205 void vvSlicer::EnableReducedExtent(bool b)
207 mUseReducedExtent = b;
209 //------------------------------------------------------------------------------
212 //------------------------------------------------------------------------------
213 void vvSlicer::SetReducedExtent(int * ext)
215 copyExtent(ext, mReducedExtent);
217 //------------------------------------------------------------------------------
220 //------------------------------------------------------------------------------
221 void vvSlicer::AddContour(vvMesh::Pointer contour,bool propagate)
224 mSurfaceCutActors.push_back(new vvMeshActor());
226 mSurfaceCutActors.back()->Init(contour,mCurrentTSlice,mVF);
228 mSurfaceCutActors.back()->Init(contour,mCurrentTSlice);
229 mSurfaceCutActors.back()->SetSlicingOrientation(SliceOrientation);
230 this->GetRenderer()->AddActor(mSurfaceCutActors.back()->GetActor());
234 //------------------------------------------------------------------------------
237 //------------------------------------------------------------------------------
238 void vvSlicer::ToggleContourSuperposition()
240 for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
241 i!=mSurfaceCutActors.end(); i++)
242 (*i)->ToggleSuperposition();
244 //------------------------------------------------------------------------------
247 //------------------------------------------------------------------------------
248 void vvSlicer::SetCursorColor(int r,int g, int b)
250 pdmA->GetProperty()->SetColor(r,g,b);
252 //------------------------------------------------------------------------------
255 //------------------------------------------------------------------------------
256 void vvSlicer::SetCursorVisibility(bool s)
258 pdmA->SetVisibility(s);
260 //------------------------------------------------------------------------------
263 //------------------------------------------------------------------------------
264 bool vvSlicer::GetCursorVisibility()
266 return pdmA->GetVisibility();
268 //------------------------------------------------------------------------------
271 //------------------------------------------------------------------------------
272 void vvSlicer::SetCornerAnnotationVisibility(bool s)
274 ca->SetVisibility(s);
276 //------------------------------------------------------------------------------
279 //------------------------------------------------------------------------------
280 bool vvSlicer::GetCornerAnnotationVisibility()
282 return ca->GetVisibility();
284 //------------------------------------------------------------------------------
287 //------------------------------------------------------------------------------
288 vvSlicer::~vvSlicer()
290 for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
291 i!=mSurfaceCutActors.end(); i++)
293 delete [] mReducedExtent;
295 //------------------------------------------------------------------------------
297 //------------------------------------------------------------------------------
298 double* vvSlicer::GetCurrentPosition()
300 return mCurrentBeforeSlicingTransform;
302 //------------------------------------------------------------------------------
304 //------------------------------------------------------------------------------
305 void vvSlicer::SetCurrentPosition(double x, double y, double z, int t)
307 mCurrentBeforeSlicingTransform[0]=x;
308 mCurrentBeforeSlicingTransform[1]=y;
309 mCurrentBeforeSlicingTransform[2]=z;
310 mSlicingTransform->GetInverse()->TransformPoint(mCurrentBeforeSlicingTransform,mCurrent);
313 //------------------------------------------------------------------------------
316 //------------------------------------------------------------------------------
317 void vvSlicer::SetImage(vvImage::Pointer image)
319 if (image->GetVTKImages().size()) {
322 if (!mImageReslice) {
323 mImageReslice = vtkSmartPointer<vtkImageReslice>::New();
324 mImageReslice->SetInterpolationModeToLinear();
325 mImageReslice->AutoCropOutputOn();
326 mImageReslice->SetBackgroundColor(-1000,-1000,-1000,1);
329 mConcatenatedTransform->Identity();
330 mConcatenatedTransform->Concatenate(mImage->GetTransform()[0]);
331 mConcatenatedTransform->Concatenate(mSlicingTransform);
332 mImageReslice->SetResliceTransform(mConcatenatedTransform);
333 mImageReslice->SetInput(0, mImage->GetFirstVTKImageData());
334 mImageReslice->UpdateInformation();
336 this->Superclass::SetInput(mImageReslice->GetOutput());
339 this->GetInput()->GetWholeExtent(extent);
341 // Prevent crash when reload -> change slice if outside extent
342 if (Slice < extent[SliceOrientation*2] || Slice>=extent[SliceOrientation*2+1]) {
343 Slice = (extent[SliceOrientation*2+1]+extent[SliceOrientation*2])/2.0;
346 // Make sure that the required part image has been computed
347 extent[SliceOrientation*2] = Slice;
348 extent[SliceOrientation*2+1] = Slice;
349 mImageReslice->GetOutput()->SetUpdateExtent(extent);
350 mImageReslice->GetOutput()->Update();
352 this->UpdateDisplayExtent();
355 ca->SetText(0,mFileName.c_str());
358 //------------------------------------------------------------------------------
361 //------------------------------------------------------------------------------
362 void vvSlicer::SetOverlay(vvImage::Pointer overlay)
364 if (overlay->GetVTKImages().size()) {
367 if (!mOverlayReslice) {
368 mOverlayReslice = vtkSmartPointer<vtkImageReslice>::New();
369 mOverlayReslice->SetInterpolationModeToLinear();
370 mOverlayReslice->AutoCropOutputOn();
371 mOverlayReslice->SetBackgroundColor(-1000,-1000,-1000,1);
374 mConcatenatedOverlayTransform->Identity();
375 mConcatenatedOverlayTransform->Concatenate(mOverlay->GetTransform()[0]);
376 mConcatenatedOverlayTransform->Concatenate(mSlicingTransform);
377 mOverlayReslice->SetResliceTransform(mConcatenatedOverlayTransform);
378 mOverlayReslice->SetInput(0, mOverlay->GetFirstVTKImageData());
379 mImageReslice->UpdateInformation();
382 mOverlayMapper = vtkSmartPointer<vtkImageMapToWindowLevelColors>::New();
383 mOverlayMapper->SetInput(mOverlayReslice->GetOutput());
385 if (!mOverlayActor) {
386 mOverlayActor = vtkSmartPointer<vvBlendImageActor>::New();
387 mOverlayActor->SetInput(mOverlayMapper->GetOutput());
388 mOverlayActor->SetPickable(0);
389 mOverlayActor->SetVisibility(true);
390 mOverlayActor->SetOpacity(0.5);
391 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
392 mOverlayActor->GetMapper()->BorderOn();
396 //stupid but necessary : the Overlay need to be rendered before fusion
398 this->GetRenderer()->RemoveActor(mFusionActor);
399 this->GetRenderer()->AddActor(mOverlayActor);
400 this->GetRenderer()->AddActor(mFusionActor);
402 this->GetRenderer()->AddActor(mOverlayActor);
404 //Synchronize orientation and slice
405 AdjustResliceToSliceOrientation(mOverlayReslice);
406 this->UpdateDisplayExtent();
407 this->SetTSlice(mCurrentTSlice);
410 //------------------------------------------------------------------------------
413 //------------------------------------------------------------------------------
414 void vvSlicer::SetFusion(vvImage::Pointer fusion)
416 if (fusion->GetVTKImages().size()) {
419 if (!mFusionReslice) {
420 mFusionReslice = vtkSmartPointer<vtkImageReslice>::New();
421 mFusionReslice->SetInterpolationModeToLinear();
422 mFusionReslice->AutoCropOutputOn();
423 mFusionReslice->SetBackgroundColor(-1000,-1000,-1000,1);
426 mConcatenatedFusionTransform->Identity();
427 mConcatenatedFusionTransform->Concatenate(mFusion->GetTransform()[0]);
428 mConcatenatedFusionTransform->Concatenate(mSlicingTransform);
429 mFusionReslice->SetResliceTransform(mConcatenatedFusionTransform);
430 mFusionReslice->SetInput(0, mFusion->GetFirstVTKImageData());
431 mFusionReslice->UpdateInformation();
434 mFusionMapper = vtkSmartPointer<vtkImageMapToColors>::New();
436 vtkSmartPointer<vtkLookupTable> lut = vtkLookupTable::New();
438 lut->SetValueRange(0, 1);
439 lut->SetSaturationRange(0, 0);
441 mFusionMapper->SetLookupTable(lut);
442 mFusionMapper->SetInput(mFusionReslice->GetOutput());
445 mFusionActor = vtkSmartPointer<vtkImageActor>::New();
446 mFusionActor->SetInput(mFusionMapper->GetOutput());
447 mFusionActor->SetPickable(0);
448 mFusionActor->SetVisibility(true);
449 mFusionActor->SetOpacity(0.7);
450 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
451 mFusionActor->GetMapper()->BorderOn();
453 this->GetRenderer()->AddActor(mFusionActor);
456 //Synchronize orientation and slice
457 AdjustResliceToSliceOrientation(mFusionReslice);
458 this->UpdateDisplayExtent();
459 this->SetTSlice(mCurrentTSlice);
462 //------------------------------------------------------------------------------
465 //------------------------------------------------------------------------------
466 bool vvSlicer::GetActorVisibility(const std::string& actor_type, int overlay_index)
469 if (actor_type == "image") {
470 vis = this->ImageActor->GetVisibility();
472 else if (actor_type == "vector") {
473 vis = this->mVFActor->GetVisibility();
475 else if (actor_type == "overlay") {
476 vis = this->mOverlayActor->GetVisibility();
478 else if (actor_type == "fusion") {
479 vis = this->mFusionActor->GetVisibility();
481 else if (actor_type == "contour")
482 vis = this->mSurfaceCutActors[overlay_index]->GetActor()->GetVisibility();
486 //------------------------------------------------------------------------------
488 //------------------------------------------------------------------------------
489 void vvSlicer::SetActorVisibility(const std::string& actor_type, int overlay_index ,bool vis)
491 if (actor_type == "image") {
492 this->ImageActor->SetVisibility(vis);
494 else if (actor_type == "vector") {
495 this->mVFActor->SetVisibility(vis);
497 else if (actor_type == "overlay") {
498 this->mOverlayActor->SetVisibility(vis);
500 else if (actor_type == "fusion") {
501 this->mFusionActor->SetVisibility(vis);
503 else if (actor_type == "contour")
504 this->mSurfaceCutActors[overlay_index]->GetActor()->SetVisibility(vis);
505 UpdateDisplayExtent();
507 //------------------------------------------------------------------------------
509 //------------------------------------------------------------------------------
510 void vvSlicer::SetVF(vvImage::Pointer vf)
512 if (vf->GetVTKImages().size()) {
516 mAAFilter= vtkSmartPointer<vtkAssignAttribute>::New();
517 mVOIFilter = vtkSmartPointer<vtkExtractVOI>::New();
518 mVOIFilter->SetSampleRate(mSubSampling,mSubSampling,mSubSampling);
520 mVOIFilter->SetInput(vf->GetFirstVTKImageData());
521 mAAFilter->SetInput(mVOIFilter->GetOutput());
522 ///This tells VTK to use the scalar (pixel) data of the image to draw the little arrows
523 mAAFilter->Assign(vtkDataSetAttributes::SCALARS, vtkDataSetAttributes::VECTORS, vtkAssignAttribute::POINT_DATA);
526 mArrow = vtkSmartPointer<vvGlyphSource>::New();
527 mArrow->SetGlyphTypeToSpecificArrow();
528 mArrow->SetScale(mScale);
531 // Glyph the gradient vector (with arrows)
533 mGlyphFilter = vtkSmartPointer<vvGlyph2D>::New();
534 mGlyphFilter->SetInput(mAAFilter->GetOutput());
535 mGlyphFilter->SetSource(mArrow->GetOutput());
536 mGlyphFilter->ScalingOn();
537 mGlyphFilter->SetScaleModeToScaleByVector();
538 mGlyphFilter->OrientOn();
539 mGlyphFilter->SetVectorModeToUseVector();
540 mGlyphFilter->SetColorModeToColorByVector();
543 mVFColorLUT = vtkSmartPointer<vtkLookupTable>::New();
545 double mVFColorHSV[3];
546 vtkMath::RGBToHSV(mVFColor, mVFColorHSV);
547 mVFColorLUT->SetHueRange(mVFColorHSV[0], mVFColorHSV[0]);
548 mVFColorLUT->SetSaturationRange(mVFColorHSV[1],mVFColorHSV[1]);
549 mVFColorLUT->SetValueRange(mVFColorHSV[2], mVFColorHSV[2]);
552 mVFMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
553 mVFMapper->SetInput(mGlyphFilter->GetOutput());
554 mVFMapper->ImmediateModeRenderingOn();
555 mVFMapper->SetLookupTable(mVFColorLUT);
558 mVFActor = vtkSmartPointer<vtkActor>::New();
559 mVFActor->SetMapper(mVFMapper);
560 mVFActor->SetPickable(0);
561 mVFActor->GetProperty()->SetLineWidth(mVFWidth);
562 this->UpdateDisplayExtent();
563 this->GetRenderer()->AddActor(mVFActor);
566 SetTSlice(mCurrentTSlice);
569 //------------------------------------------------------------------------------
572 //------------------------------------------------------------------------------
573 void vvSlicer::SetLandmarks(vvLandmarks* landmarks)
575 mLandmarks = landmarks;
579 mCross = vtkSmartPointer<vtkCursor3D>::New();
581 mClipBox = vtkSmartPointer<vtkBox>::New();
583 mLandClipper = vtkSmartPointer<vvClipPolyData>::New();
585 mLandGlyph = vtkSmartPointer<vtkGlyph3D>::New();
587 mLandMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
589 mLandActor = vtkSmartPointer<vtkActor>::New();
591 mCross->SetFocalPoint(0.0,0.0,0.0);
592 mCross->SetModelBounds(-10,10,-10,10,-10,10);
596 mLandClipper->SetClipFunction(mClipBox);
597 mLandClipper->InsideOutOn();
598 mLandClipper->SetInput(mLandmarks->GetOutput());
600 mLandGlyph->SetSource(mCross->GetOutput());
601 mLandGlyph->SetInput(mLandClipper->GetOutput());
602 //mLandGlyph->SetIndexModeToScalar();
603 //mLandGlyph->SetRange(0,1);
604 //mLandGlyph->ScalingOff();
606 //mLandGlyph->SetColorModeToColorByScalar();
608 mLandGlyph->SetScaleModeToDataScalingOff();
609 mLandGlyph->SetIndexModeToOff();
611 mLandMapper->SetInputConnection(mLandGlyph->GetOutputPort());
612 //mLandMapper->ScalarVisibilityOff();
614 mLandActor->SetMapper(mLandMapper);
615 mLandActor->GetProperty()->SetColor(255,10,212);
616 mLandActor->SetPickable(0);
617 mLandActor->SetVisibility(true);
618 this->UpdateDisplayExtent();
619 this->GetRenderer()->AddActor(mLandActor);
622 //------------------------------------------------------------------------------
624 //------------------------------------------------------------------------------
625 //FIXME: this function leaks memory, we should fix it someday :)
626 void vvSlicer::RemoveActor(const std::string& actor_type, int overlay_index)
628 if (actor_type == "vector") {
629 Renderer->RemoveActor(mVFActor);
638 if (actor_type == "overlay") {
639 Renderer->RemoveActor(mOverlayActor);
641 mOverlayActor = NULL;
642 mOverlayMapper = NULL;
644 if (actor_type == "fusion") {
645 Renderer->RemoveActor(mFusionActor);
648 mFusionMapper = NULL;
650 if (actor_type == "contour") {
651 Renderer->RemoveActor(this->mSurfaceCutActors[overlay_index]->GetActor());
652 mSurfaceCutActors.erase(mSurfaceCutActors.begin()+overlay_index);
655 //------------------------------------------------------------------------------
658 //------------------------------------------------------------------------------
659 void vvSlicer::SetVFSubSampling(int sub)
662 mVOIFilter->SetSampleRate(mSubSampling,mSubSampling,mSubSampling);
665 UpdateDisplayExtent();
668 //------------------------------------------------------------------------------
671 //------------------------------------------------------------------------------
672 void vvSlicer::SetVFScale(int scale)
676 mArrow->SetScale(mScale);
677 UpdateDisplayExtent();
680 //------------------------------------------------------------------------------
682 //------------------------------------------------------------------------------
683 void vvSlicer::SetVFWidth(int width)
687 mVFActor->GetProperty()->SetLineWidth(mVFWidth);
688 UpdateDisplayExtent();
691 //------------------------------------------------------------------------------
694 //------------------------------------------------------------------------------
695 void vvSlicer::SetVFLog(int log)
699 mGlyphFilter->SetUseLog(mVFLog);
700 mGlyphFilter->Modified();
702 UpdateDisplayExtent();
705 //------------------------------------------------------------------------------
708 //------------------------------------------------------------------------------
709 void vvSlicer::SetTSlice(int t)
713 else if ((unsigned int)t >= mImage->GetVTKImages().size())
714 mCurrentTSlice = mImage->GetVTKImages().size() -1;
719 mConcatenatedTransform->Identity();
720 mConcatenatedTransform->Concatenate(mImage->GetTransform()[mCurrentTSlice]);
721 mConcatenatedTransform->Concatenate(mSlicingTransform);
724 mImageReslice->SetInput( mImage->GetVTKImages()[mCurrentTSlice] );
725 if (mVF && mVFActor->GetVisibility()) {
726 if (mVF->GetVTKImages().size() > (unsigned int)mCurrentTSlice)
727 mVOIFilter->SetInput(mVF->GetVTKImages()[mCurrentTSlice]);
729 if (mOverlay && mOverlayActor->GetVisibility()) {
730 if (mOverlay->GetVTKImages().size() > (unsigned int)t) {
731 mCurrentOverlayTSlice = t;
732 mOverlayReslice->SetInput( mOverlay->GetVTKImages()[mCurrentOverlayTSlice] );
734 // Update overlay transform
735 mConcatenatedOverlayTransform->Identity();
736 mConcatenatedOverlayTransform->Concatenate(mOverlay->GetTransform()[mCurrentOverlayTSlice]);
737 mConcatenatedOverlayTransform->Concatenate(mSlicingTransform);
740 if (mFusion && mFusionActor->GetVisibility()) {
741 if (mFusion->GetVTKImages().size() > (unsigned int)t) {
742 mCurrentFusionTSlice = t;
743 mFusionReslice->SetInput( mFusion->GetVTKImages()[mCurrentFusionTSlice]);
745 // Update fusion transform
746 mConcatenatedFusionTransform->Identity();
747 mConcatenatedFusionTransform->Concatenate(mFusion->GetTransform()[mCurrentFusionTSlice]);
748 mConcatenatedFusionTransform->Concatenate(mSlicingTransform);
751 if (mSurfaceCutActors.size() > 0)
752 for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
753 i!=mSurfaceCutActors.end(); i++)
754 (*i)->SetTimeSlice(mCurrentTSlice);
755 UpdateDisplayExtent();
757 //------------------------------------------------------------------------------
760 //------------------------------------------------------------------------------
761 int vvSlicer::GetTSlice()
763 return mCurrentTSlice;
765 //------------------------------------------------------------------------------
767 //------------------------------------------------------------------------------
768 int vvSlicer::GetMaxCurrentTSlice()
770 int t = mCurrentTSlice;
772 t = std::max(t, mCurrentOverlayTSlice);
774 t = std::max(t, mCurrentFusionTSlice);
777 //------------------------------------------------------------------------------
779 //------------------------------------------------------------------------------
780 int vvSlicer::GetFusionTSlice()
782 return mCurrentFusionTSlice;
784 //------------------------------------------------------------------------------
786 //------------------------------------------------------------------------------
787 int vvSlicer::GetOverlayTSlice()
789 return mCurrentOverlayTSlice;
791 //------------------------------------------------------------------------------
793 //------------------------------------------------------------------------------
794 void vvSlicer::SetSliceOrientation(int orientation)
796 //if 2D image, force to watch in Axial View
798 this->GetInput()->GetWholeExtent(extent);
799 if (extent[5]-extent[4] <= 2)
800 orientation = vtkImageViewer2::SLICE_ORIENTATION_XY;
802 if (orientation < vtkImageViewer2::SLICE_ORIENTATION_YZ ||
803 orientation > vtkImageViewer2::SLICE_ORIENTATION_XY) {
804 vtkErrorMacro("Error - invalid slice orientation " << orientation);
808 this->SliceOrientation = orientation;
811 AdjustResliceToSliceOrientation(mFusionReslice);
814 AdjustResliceToSliceOrientation(mOverlayReslice);
818 // Go to current cursor position
819 // double* cursorPos = GetCursorPosition();
820 // DDV(cursorPos, 3);
821 // SetCurrentPosition(cursorPos[0],cursorPos[1],cursorPos[2],cursorPos[3]);
823 if (this->Renderer && this->GetInput()) {
824 double s = mCursor[orientation];
825 double sCursor = (s - this->GetInput()->GetOrigin()[orientation])/this->GetInput()->GetSpacing()[orientation];
826 this->Slice = static_cast<int>(sCursor);
829 // int *range = this->GetSliceRange();
831 // this->Slice = static_cast<int>((range[0] + range[1]) * 0.5);
833 this->UpdateOrientation();
834 this->UpdateDisplayExtent();
836 if (this->Renderer && this->GetInput()) {
837 double scale = this->Renderer->GetActiveCamera()->GetParallelScale();
838 this->Renderer->ResetCamera();
839 this->Renderer->GetActiveCamera()->SetParallelScale(scale);
844 //----------------------------------------------------------------------------
846 //------------------------------------------------------------------------------
847 // This function ensures that we sample the slices of a vtkImageReslice filter
848 // in the direction of the slicer (SliceOrientation) similarly as mImageReslice.
849 // In other words, we change the grid of the reslice in the same way as the grid
850 // of the displayed image in the slicing direction.
851 void vvSlicer::AdjustResliceToSliceOrientation(vtkImageReslice *reslice)
853 // Reset autocrop and update output information
854 reslice->SetOutputOriginToDefault();
855 reslice->SetOutputSpacingToDefault();
856 reslice->GetOutput()->UpdateInformation();
858 // Ge new origin / spacing
861 reslice->GetOutput()->GetOrigin(origin);
862 reslice->GetOutput()->GetSpacing(spacing);
864 // Use similar spacing as the image in the direction SliceOrientation
865 spacing[this->SliceOrientation] = mImageReslice->GetOutput()->GetSpacing()[this->SliceOrientation];
867 // Modify origin to be on the image grid in the direction SliceOrientation in 3 steps
868 // Step 1: from world coordinates to image coordinates
869 origin[this->SliceOrientation] -= mImageReslice->GetOutput()->GetOrigin()[this->SliceOrientation];
870 origin[this->SliceOrientation] /= mImageReslice->GetOutput()->GetSpacing()[this->SliceOrientation];
871 // Step 2: round to superior grid positionInc
872 origin[this->SliceOrientation] = itk::Math::Ceil<double>(origin[this->SliceOrientation]);
873 // Step 3: back to world coordinates
874 origin[this->SliceOrientation] *= mImageReslice->GetOutput()->GetSpacing()[this->SliceOrientation];
875 origin[this->SliceOrientation] += mImageReslice->GetOutput()->GetOrigin()[this->SliceOrientation];
877 // Set new spacing and origin
878 reslice->SetOutputOrigin(origin);
879 reslice->SetOutputSpacing(spacing);
880 reslice->UpdateInformation();
881 reslice->GetOutput()->UpdateInformation();
883 //------------------------------------------------------------------------------
885 //----------------------------------------------------------------------------
886 int * vvSlicer::GetExtent(){
888 if (mUseReducedExtent) {
889 w_ext = mReducedExtent;
890 } else w_ext = GetInput()->GetWholeExtent();
893 //----------------------------------------------------------------------------
896 //----------------------------------------------------------------------------
897 int vvSlicer::GetOrientation()
899 return this->SliceOrientation;
901 //----------------------------------------------------------------------------
904 //----------------------------------------------------------------------------
905 void vvSlicer::UpdateDisplayExtent()
907 vtkImageData *input = this->GetInput();
908 if (!input || !this->ImageActor) {
911 input->UpdateInformation();
912 this->SetSlice( this->GetSlice() ); //SR: make sure the update let the slice in extents
914 // Local copy of extent
916 int* ext = GetExtent();
917 copyExtent(ext, w_ext);
919 w_ext[ this->SliceOrientation*2 ] = this->Slice;
920 w_ext[ this->SliceOrientation*2+1 ] = this->Slice;
923 this->ImageActor->SetDisplayExtent(w_ext);
925 // Overlay image actor
926 if (mOverlay && mOverlayActor->GetVisibility()) {
927 AdjustResliceToSliceOrientation(mOverlayReslice);
929 this->ConvertImageToImageDisplayExtent(input, w_ext, mOverlayReslice->GetOutput(), overExtent);
930 ClipDisplayedExtent(overExtent, mOverlayMapper->GetInput()->GetWholeExtent());
931 mOverlayActor->SetDisplayExtent( overExtent );
934 // Fusion image actor
935 if (mFusion && mFusionActor->GetVisibility()) {
936 AdjustResliceToSliceOrientation(mFusionReslice);
938 this->ConvertImageToImageDisplayExtent(input, w_ext, mFusionReslice->GetOutput(), fusExtent);
939 ClipDisplayedExtent(fusExtent, mFusionMapper->GetInput()->GetWholeExtent());
940 mFusionActor->SetDisplayExtent(fusExtent);
943 // Vector field actor
944 double* camera = Renderer->GetActiveCamera()->GetPosition();
945 double* image_bounds = ImageActor->GetBounds();
946 double position[3] = {0, 0, 0};
947 position[this->SliceOrientation] = image_bounds[this->SliceOrientation*2];
949 //print_vector<double, 6>("camera", camera);
950 //print_vector<double, 6>("image_bounds", image_bounds);
951 //print_vector<double, 3>("position", position);
953 // find where to place the VF actor. to deal with
954 // z-buffer issues, the VF is placed right in front of the image,
955 // subject to a small offset. the position actually depends on the
956 // the location of the camera relative to the image.
958 if (camera[this->SliceOrientation] < image_bounds[this->SliceOrientation*2])
961 if (mVF && mVFActor->GetVisibility()) {
963 mVF->GetVTKImages()[0]->UpdateInformation();
964 this->ConvertImageToImageDisplayExtent(input, w_ext, mVF->GetVTKImages()[0], vfExtent);
965 ClipDisplayedExtent(vfExtent, mVOIFilter->GetInput()->GetWholeExtent());
966 mVOIFilter->SetVOI(vfExtent);
967 int orientation[3] = {1,1,1};
968 orientation[this->SliceOrientation] = 0;
969 mGlyphFilter->SetOrientation(orientation[0], orientation[1], orientation[2]);
972 position[this->SliceOrientation] += offset;
973 mVFActor->SetPosition(position);
980 for(unsigned int i=0; i<6; i++)
981 bounds[i] = ImageActor->GetBounds()[i];
982 bounds[ this->SliceOrientation*2 ] = ImageActor->GetBounds()[ this->SliceOrientation*2 ]-fabs(this->GetInput()->GetSpacing()[this->SliceOrientation]);
983 bounds[ this->SliceOrientation*2+1 ] = ImageActor->GetBounds()[ this->SliceOrientation*2+1 ]+fabs(this->GetInput()->GetSpacing()[this->SliceOrientation]);
984 mClipBox->SetBounds(bounds);
988 position[this->SliceOrientation] = offset;
989 mLandActor->SetPosition(position);
992 // Figure out the correct clipping range
993 if (this->Renderer) {
994 if (this->InteractorStyle &&
995 this->InteractorStyle->GetAutoAdjustCameraClippingRange()) {
996 this->Renderer->ResetCameraClippingRange();
998 vtkCamera *cam = this->Renderer->GetActiveCamera();
1001 this->ImageActor->GetBounds(bounds);
1002 double spos = (double)bounds[this->SliceOrientation * 2];
1003 double cpos = (double)cam->GetPosition()[this->SliceOrientation];
1004 double range = fabs(spos - cpos);
1005 double *spacing = input->GetSpacing();
1006 double sumSpacing = spacing[0] + spacing[1] + spacing[2];
1007 cam->SetClippingRange(range - sumSpacing, range + sumSpacing);
1013 //----------------------------------------------------------------------------
1015 //----------------------------------------------------------------------------
1016 void vvSlicer::ConvertImageToImageDisplayExtent(vtkImageData *sourceImage, const int sourceExtent[6],
1017 vtkImageData *targetImage, int targetExtent[6])
1020 for(unsigned int i=0; i<6; i++) {
1021 // From source voxel coordinates to world coordinates
1022 dExtents[i] = sourceImage->GetOrigin()[i/2] + sourceImage->GetSpacing()[i/2] * sourceExtent[i];
1024 // From world coordinates to floating point target voxel coordinates
1025 dExtents[i] = (dExtents[i]- targetImage->GetOrigin()[i/2]) / targetImage->GetSpacing()[i/2];
1028 //targetExtent[i] = itk::Math::Round<double>(dExtents[i]);
1029 targetExtent[i] = itk::Math::Floor<double>(dExtents[i]);
1032 //----------------------------------------------------------------------------
1034 //----------------------------------------------------------------------------
1035 void vvSlicer::ClipDisplayedExtent(int extent[6], int refExtent[6])
1040 //2D overlay on 3D image specific case
1041 if (refExtent[4] == refExtent[5]) {
1043 extent[4] = refExtent[4];
1044 extent[5] = refExtent[5];
1047 for (int i = 0; i < maxBound; i = i+2) {
1048 //if we are totally outside the image
1049 if ( extent[i] > refExtent[i+1] || extent[i+1] < refExtent[i] ) {
1053 //crop to the limit of the image
1054 extent[i] = (extent[i] > refExtent[i]) ? extent[i] : refExtent[i];
1055 extent[i] = (extent[i] < refExtent[i+1]) ? extent[i] : refExtent[i+1];
1056 extent[i+1] = (extent[i+1] > refExtent[i]) ? extent[i+1] : refExtent[i];
1057 extent[i+1] = (extent[i+1] < refExtent[i+1]) ? extent[i+1] : refExtent[i+1];
1060 for (int i = 0; i < maxBound; i = i+2) {
1061 extent[i] = refExtent[i];
1062 extent[i+1] = refExtent[i];
1065 //----------------------------------------------------------------------------
1068 //----------------------------------------------------------------------------
1069 void vvSlicer::UpdateOrientation()
1071 // Set the camera position
1072 vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
1074 switch (this->SliceOrientation) {
1075 case vtkImageViewer2::SLICE_ORIENTATION_XY:
1076 cam->SetFocalPoint(0,0,0);
1077 cam->SetPosition(0,0,-1); // -1 if medical ?
1078 cam->SetViewUp(0,-1,0);
1081 case vtkImageViewer2::SLICE_ORIENTATION_XZ:
1082 cam->SetFocalPoint(0,0,0);
1083 cam->SetPosition(0,-1,0); // 1 if medical ?
1084 cam->SetViewUp(0,0,1);
1087 case vtkImageViewer2::SLICE_ORIENTATION_YZ:
1088 cam->SetFocalPoint(0,0,0);
1089 cam->SetPosition(-1,0,0); // -1 if medical ?
1090 cam->SetViewUp(0,0,1);
1095 //----------------------------------------------------------------------------
1098 //----------------------------------------------------------------------------
1099 void vvSlicer::SetOpacity(double s)
1101 this->GetImageActor()->SetOpacity(s);
1103 //----------------------------------------------------------------------------
1106 //----------------------------------------------------------------------------
1107 void vvSlicer::SetRenderWindow(int orientation, vtkRenderWindow * rw)
1109 this->Superclass::SetRenderWindow(rw);
1110 this->SetupInteractor(rw->GetInteractor());
1111 ca->SetImageActor(this->GetImageActor());
1112 ca->SetWindowLevel(this->GetWindowLevel());
1113 ca->SetText(2, "<slice>");
1114 ca->SetText(3, "<window>\n<level>");
1126 crossCursor->SetModelBounds(bounds);
1127 this->GetRenderer()->AddActor(pdmA);
1128 this->GetRenderer()->AddActor(ca);
1129 this->GetRenderer()->ResetCamera();
1131 //this is just a mapping between the labeling of the orientations presented to the user and
1132 //the one used by vtk
1133 SetSliceOrientation(2-(orientation%3));
1136 //----------------------------------------------------------------------------
1139 //----------------------------------------------------------------------------
1140 void vvSlicer::ResetCamera()
1142 this->GetRenderer()->ResetCamera();
1144 //----------------------------------------------------------------------------
1147 //----------------------------------------------------------------------------
1148 void vvSlicer::SetDisplayMode(bool i)
1150 this->GetRenderer()->SetDraw(i);
1152 UpdateDisplayExtent();
1154 //----------------------------------------------------------------------------
1157 //----------------------------------------------------------------------------
1158 void vvSlicer::FlipHorizontalView()
1160 vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
1162 double *position = cam->GetPosition();
1163 double factor[3] = {1, 1, 1};
1164 factor[this->SliceOrientation] = -1;
1165 cam->SetPosition(factor[0]*position[0],factor[1]*position[1],factor[2]*position[2]);
1167 /* switch (this->SliceOrientation) {
1168 case vtkImageViewer2::SLICE_ORIENTATION_XY:
1169 cam->SetPosition(position[0],position[1],-position[2]);
1172 case vtkImageViewer2::SLICE_ORIENTATION_XZ:
1173 cam->SetPosition(position[0],-position[1],position[2]);
1176 case vtkImageViewer2::SLICE_ORIENTATION_YZ:
1177 cam->SetPosition(-position[0],position[1],position[2]);
1181 this->Renderer->ResetCameraClippingRange();
1182 this->UpdateDisplayExtent();
1185 //----------------------------------------------------------------------------
1188 //----------------------------------------------------------------------------
1189 void vvSlicer::FlipVerticalView()
1191 vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
1193 FlipHorizontalView();
1194 double *viewup = cam->GetViewUp();
1195 cam->SetViewUp(-viewup[0],-viewup[1],-viewup[2]);
1196 this->UpdateDisplayExtent();
1199 //----------------------------------------------------------------------------
1202 //----------------------------------------------------------------------------
1203 void vvSlicer::SetColorWindow(double window)
1205 vtkLookupTable* LUT = static_cast<vtkLookupTable*>(this->GetWindowLevel()->GetLookupTable());
1207 double level = this->GetWindowLevel()->GetLevel();
1208 LUT->SetTableRange(level-fabs(window)/2,level+fabs(window)/2);
1211 this->vtkImageViewer2::SetColorWindow(window);
1213 //----------------------------------------------------------------------------
1215 //----------------------------------------------------------------------------
1216 void vvSlicer::SetColorLevel(double level)
1218 vtkLookupTable* LUT = static_cast<vtkLookupTable*>(this->GetWindowLevel()->GetLookupTable());
1220 double window = this->GetWindowLevel()->GetWindow();
1221 LUT->SetTableRange(level-fabs(window)/2,level+fabs(window)/2);
1224 this->vtkImageViewer2::SetColorLevel(level);
1226 //----------------------------------------------------------------------------
1228 //----------------------------------------------------------------------------
1229 double vvSlicer::GetOverlayColorWindow()
1232 return mOverlayMapper->GetWindow();
1236 //----------------------------------------------------------------------------
1238 //----------------------------------------------------------------------------
1239 double vvSlicer::GetOverlayColorLevel()
1242 return mOverlayMapper->GetLevel();
1246 //----------------------------------------------------------------------------
1248 //----------------------------------------------------------------------------
1249 void vvSlicer::SetOverlayColorWindow(double window)
1251 mOverlayMapper->SetWindow(window);
1253 //----------------------------------------------------------------------------
1255 //----------------------------------------------------------------------------
1256 void vvSlicer::SetOverlayColorLevel(double level)
1258 mOverlayMapper->SetLevel(level);
1260 //----------------------------------------------------------------------------
1262 //----------------------------------------------------------------------------
1263 // Returns the min an the max value in a 20%x20% region around the mouse pointer
1264 void vvSlicer::GetExtremasAroundMousePointer(double & min, double & max, vtkImageData *image, vtkTransform *transform)
1266 //Get mouse pointer position in view coordinates
1269 for(int i=0; i<3; i++) {
1270 corner1[i] = mCurrent[i];
1271 corner2[i] = mCurrent[i];
1274 this->Renderer->WorldToView(corner1[0], corner1[1], corner1[2]);
1275 this->Renderer->WorldToView(corner2[0], corner2[1], corner2[2]);
1277 // In view coordinates, x is the slicer width and y is the slicer height are the in-plane axis
1279 this->Renderer->GetTiledSize(&w, &h);
1280 corner1[0] -= 0.2*h/(double)w;
1281 corner2[0] += 0.2*h/(double)w;
1284 this->Renderer->ViewToWorld(corner1[0], corner1[1], corner1[2]);
1285 this->Renderer->ViewToWorld(corner2[0], corner2[1], corner2[2]);
1287 //Convert to image pixel coordinates (rounded)
1288 transform->TransformPoint(corner1, corner1);
1289 transform->TransformPoint(corner2, corner2);
1290 int iLocalExtents[6];
1291 for(int i=0; i<3; i++) {
1292 corner1[i] = (corner1[i] - image->GetOrigin()[i])/image->GetSpacing()[i];
1293 corner2[i] = (corner2[i] - image->GetOrigin()[i])/image->GetSpacing()[i];
1295 iLocalExtents[i*2 ] = lrint(corner1[i]);
1296 iLocalExtents[i*2+1] = lrint(corner2[i]);
1298 if(iLocalExtents[i*2 ]>iLocalExtents[i*2+1])
1299 std::swap(iLocalExtents[i*2], iLocalExtents[i*2+1]);
1302 vtkSmartPointer<vtkExtractVOI> voiFilter = vtkSmartPointer<vtkExtractVOI>::New();
1303 voiFilter->SetInput(image);
1304 voiFilter->SetVOI(iLocalExtents);
1305 voiFilter->Update();
1306 if (!voiFilter->GetOutput()->GetNumberOfPoints()) {
1312 vtkSmartPointer<vtkImageAccumulate> accFilter = vtkSmartPointer<vtkImageAccumulate>::New();
1313 accFilter->SetInput(voiFilter->GetOutput());
1314 accFilter->Update();
1316 min = *(accFilter->GetMin());
1317 max = *(accFilter->GetMax());
1319 //----------------------------------------------------------------------------
1321 //----------------------------------------------------------------------------
1322 double vvSlicer::GetScalarComponentAsDouble(vtkImageData *image, double X, double Y, double Z, int &ix, int &iy, int &iz, int component)
1327 if (ix < image->GetWholeExtent()[0] ||
1328 ix > image->GetWholeExtent()[1] ||
1329 iy < image->GetWholeExtent()[2] ||
1330 iy > image->GetWholeExtent()[3] ||
1331 iz < image->GetWholeExtent()[4] ||
1332 iz > image->GetWholeExtent()[5] )
1333 return std::numeric_limits<double>::quiet_NaN();
1335 image->SetUpdateExtent(ix, ix, iy, iy, iz, iz);
1337 return image->GetScalarComponentAsDouble(ix, iy, iz, component);
1339 //----------------------------------------------------------------------------
1341 //----------------------------------------------------------------------------
1342 void vvSlicer::Render()
1344 if (this->mFusion && mFusionActor->GetVisibility() && showFusionLegend) {
1345 legend->SetLookupTable(this->GetFusionMapper()->GetLookupTable());
1346 legend->UseOpacityOn();
1347 legend->SetVisibility(1);
1349 else if (this->GetWindowLevel()->GetLookupTable() && !this->mOverlay) {
1350 legend->SetLookupTable(this->GetWindowLevel()->GetLookupTable());
1351 legend->UseOpacityOff();
1352 legend->SetVisibility(1);
1353 } else legend->SetVisibility(0);
1355 if (ca->GetVisibility()) {
1356 std::stringstream worldPos;
1358 mConcatenatedTransform->TransformPoint(mCurrent, pt);
1359 double X = (pt[0] - mImage->GetVTKImages()[mCurrentTSlice]->GetOrigin()[0])/mImage->GetVTKImages()[mCurrentTSlice]->GetSpacing()[0];
1360 double Y = (pt[1] - mImage->GetVTKImages()[mCurrentTSlice]->GetOrigin()[1])/mImage->GetVTKImages()[mCurrentTSlice]->GetSpacing()[1];
1361 double Z = (pt[2] - mImage->GetVTKImages()[mCurrentTSlice]->GetOrigin()[2])/mImage->GetVTKImages()[mCurrentTSlice]->GetSpacing()[2];
1363 if (X >= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[0]-0.5 &&
1364 X <= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[1]+0.5 &&
1365 Y >= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[2]-0.5 &&
1366 Y <= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[3]+0.5 &&
1367 Z >= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[4]-0.5 &&
1368 Z <= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[5]+0.5) {
1372 double value = this->GetScalarComponentAsDouble(mImage->GetVTKImages()[mCurrentTSlice], X, Y, Z, ix, iy, iz);
1374 if(ImageActor->GetVisibility())
1375 worldPos << "data value : " << value << std::endl;
1377 worldPos << "mm : " << lrint(mCurrentBeforeSlicingTransform[0]) << ' '
1378 << lrint(mCurrentBeforeSlicingTransform[1]) << ' '
1379 << lrint(mCurrentBeforeSlicingTransform[2]) << ' '
1382 worldPos << "pixel : " << ix << ' '
1388 ca->SetText(1,worldPos.str().c_str());
1391 if (pdmA->GetVisibility()) {
1392 double x = mCursor[0];
1393 double y = mCursor[1];
1394 double z = mCursor[2];
1395 double xCursor = (x - this->GetInput()->GetOrigin()[0])/this->GetInput()->GetSpacing()[0];
1396 double yCursor = (y - this->GetInput()->GetOrigin()[1])/this->GetInput()->GetSpacing()[1];
1397 double zCursor = (z - this->GetInput()->GetOrigin()[2])/this->GetInput()->GetSpacing()[2];
1399 if (xCursor >= this->GetImageActor()->GetDisplayExtent()[0] &&
1400 xCursor < this->GetImageActor()->GetDisplayExtent()[1]+1 &&
1401 yCursor >= this->GetImageActor()->GetDisplayExtent()[2] &&
1402 yCursor < this->GetImageActor()->GetDisplayExtent()[3]+1 &&
1403 zCursor >= this->GetImageActor()->GetDisplayExtent()[4] &&
1404 zCursor < this->GetImageActor()->GetDisplayExtent()[5]+1 ) {
1405 vtkRenderer * renderer = this->Renderer;
1407 renderer->WorldToView(x,y,z);
1408 renderer->ViewToNormalizedViewport(x,y,z);
1409 renderer->NormalizedViewportToViewport(x,y);
1410 renderer->ViewportToNormalizedDisplay(x,y);
1411 renderer->NormalizedDisplayToDisplay(x,y);
1412 crossCursor->SetFocalPoint(x,y,z);
1414 crossCursor->SetFocalPoint(-1,-1,z);
1418 if (mOverlay && mOverlayActor->GetVisibility()) {
1419 if(mLinkOverlayWindowLevel) {
1420 mOverlayMapper->SetWindow(this->GetColorWindow());
1421 mOverlayMapper->SetLevel(this->GetColorLevel());
1423 mOverlayMapper->GetOutput()->SetUpdateExtent(mOverlayActor->GetDisplayExtent());
1424 mOverlayMapper->GetOutput()->Update();
1425 mOverlayMapper->Update();
1430 this->GetRenderWindow()->Render();
1432 //----------------------------------------------------------------------------
1435 //----------------------------------------------------------------------------
1436 void vvSlicer::UpdateCursorPosition()
1438 pdmA->SetVisibility(true);
1439 mCursor[0] = mCurrent[0];
1440 mCursor[1] = mCurrent[1];
1441 mCursor[2] = mCurrent[2];
1442 mCursor[3] = mCurrentTSlice;
1444 //----------------------------------------------------------------------------
1447 //----------------------------------------------------------------------------
1448 void vvSlicer::UpdateLandmarks()
1450 vtkPolyData *pd = static_cast<vtkPolyData*>(mLandClipper->GetInput());
1451 if (pd->GetPoints()) {
1452 //mLandGlyph->SetRange(0,1);
1453 //mLandGlyph->Modified();
1454 //mLandGlyph->Update();
1456 mClipBox->Modified();
1457 mLandClipper->Update();
1458 mLandMapper->Update();
1459 //Let's add the captions
1460 //First remove all captions:
1461 for(unsigned int i=0;i<mLandLabelActors.size();i++) {
1462 this->Renderer->RemoveActor2D(mLandLabelActors[i]);
1463 //allActors2D->Remove (mLandLabelActors[i]);
1465 mLandLabelActors.clear();
1466 //Next add the captions to the displayed points
1467 for (vtkIdType id=0; id<mLandClipper->GetOutput()->GetNumberOfPoints(); id++) {
1468 double *position = mLandClipper->GetOutput()->GetPoint(id);
1469 vtkStdString label = static_cast<vtkStringArray*>(mLandClipper->GetOutput()->GetPointData()->GetAbstractArray("labels"))->GetValue(id);
1470 vtkSmartPointer<vtkCaptionActor2D> label_actor = vtkSmartPointer<vtkCaptionActor2D>::New();
1471 label_actor->SetCaption(label);
1472 label_actor->SetAttachmentPoint(position);
1473 label_actor->GetCaptionTextProperty()->SetColor(1,0,0);
1474 label_actor->GetCaptionTextProperty()->SetOrientation(33.333333);
1475 label_actor->GetCaptionTextProperty()->SetFontFamilyToTimes();
1476 label_actor->GetCaptionTextProperty()->SetBold(0);
1477 label_actor->GetCaptionTextProperty()->SetFontSize(6);
1478 label_actor->BorderOff();
1479 label_actor->LeaderOff();
1480 label_actor->ThreeDimensionalLeaderOff();
1481 mLandLabelActors.push_back(label_actor);
1482 this->Renderer->AddActor2D(mLandLabelActors[id]);
1487 //----------------------------------------------------------------------------
1490 //----------------------------------------------------------------------------
1491 void vvSlicer::SetSlice(int slice)
1493 int *range = this->GetSliceRange();
1495 if (slice < range[0]) {
1497 } else if (slice > range[1]) {
1502 if (this->Slice == slice) {
1506 this->Slice = slice;
1509 this->UpdateDisplayExtent();
1511 // Seems to work without this line
1514 //----------------------------------------------------------------------------
1516 //----------------------------------------------------------------------------
1517 int vvSlicer::GetTMax() {
1518 int tmax = (int)mImage->GetVTKImages().size() - 1;
1520 tmax = std::max(tmax, (int)mOverlay->GetVTKImages().size()-1);
1523 //----------------------------------------------------------------------------
1525 //----------------------------------------------------------------------------
1526 void vvSlicer::SetContourSlice()
1528 if (mSurfaceCutActors.size() > 0)
1529 for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
1530 i!=mSurfaceCutActors.end(); i++) {
1532 (*i)->SetSlicingOrientation(this->SliceOrientation);
1533 (*i)->SetCutSlice((this->Slice)*this->GetImage()->GetSpacing()[this->SliceOrientation]+
1534 this->GetImage()->GetOrigin()[this->SliceOrientation]);
1537 //----------------------------------------------------------------------------
1540 //----------------------------------------------------------------------------
1541 void vvSlicer::ForceUpdateDisplayExtent()
1543 this->UpdateDisplayExtent();
1545 //----------------------------------------------------------------------------
1548 //----------------------------------------------------------------------------
1549 int* vvSlicer::GetDisplayExtent()
1551 return this->GetImageActor()->GetDisplayExtent();
1553 //----------------------------------------------------------------------------
1556 //----------------------------------------------------------------------------
1557 void vvSlicer::PrintSelf(ostream& os, vtkIndent indent)
1559 this->Superclass::PrintSelf(os, indent);
1561 //----------------------------------------------------------------------------
1563 //----------------------------------------------------------------------------
1564 void vvSlicer::SetVFColor(double r, double g, double b)
1566 double mVFColorHSV[3];
1571 vtkMath::RGBToHSV(mVFColor, mVFColorHSV);
1572 mVFColorLUT->SetHueRange(mVFColorHSV[0], mVFColorHSV[0]);
1573 mVFColorLUT->SetSaturationRange(mVFColorHSV[1],mVFColorHSV[1]);
1574 mVFColorLUT->SetValueRange(mVFColorHSV[2], mVFColorHSV[2]);