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 <vtkActor2DCollection.h>
45 #include <vtkGlyph3D.h>
47 #include <vtkCursor3D.h>
48 #include <vtkProperty.h>
50 #include <vtkLightCollection.h>
51 #include <vtkScalarBarActor.h>
52 #include <vtkLookupTable.h>
54 #include <vtkRenderer.h>
55 #include <vtkRendererCollection.h>
56 #include <vtkRenderWindow.h>
57 #include <vtkRenderWindowInteractor.h>
58 #include <vtkCamera.h>
59 #include <vtkCallbackCommand.h>
60 #include <vtkCommand.h>
61 #include <vtkPolyDataMapper.h>
64 #include <vtkExtractVOI.h>
65 #include <vtkSphereSource.h>
66 #include <vtkCutter.h>
67 #include <vtkAssignAttribute.h>
68 #include <vtkImageAccumulate.h>
69 #include <vtkImageReslice.h>
70 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
71 # include <vtkImageMapper3D.h>
74 vtkCxxRevisionMacro(vvSlicer, "DummyRevision");
75 vtkStandardNewMacro(vvSlicer);
76 static void copyExtent(int* in, int* to){
77 for(int i=0; i<6; ++i) to[i]=in[i];
79 //------------------------------------------------------------------------------
82 this->UnInstallPipeline();
84 mReducedExtent = new int[6];
86 mCurrentFusionTSlice = 0;
87 mCurrentOverlayTSlice = 0;
88 mUseReducedExtent = false;
90 mCurrent[0] = -VTK_DOUBLE_MAX;
91 mCurrent[1] = -VTK_DOUBLE_MAX;
92 mCurrent[2] = -VTK_DOUBLE_MAX;
94 mCursor[0] = 0;//-VTK_DOUBLE_MAX;
95 mCursor[1] = 0;//-VTK_DOUBLE_MAX;
96 mCursor[2] = 0;//-VTK_DOUBLE_MAX;
97 mCursor[3] = 0;//-VTK_DOUBLE_MAX;
107 crossCursor = vtkSmartPointer<vtkCursor2D>::New();
108 crossCursor->AllOff();
109 crossCursor->AxesOn();
110 crossCursor->SetTranslationMode(1);
111 crossCursor->SetRadius(2);
113 pdm = vtkSmartPointer<vtkPolyDataMapper2D>::New();
114 pdm->SetInput(crossCursor->GetOutput());
116 pdmA = vtkSmartPointer<vtkActor2D>::New();
117 pdmA->SetMapper(pdm);
118 pdmA->GetProperty()->SetColor(255,10,212);
119 pdmA->SetVisibility(0);
120 pdmA->SetPickable(0);
122 ca = vtkSmartPointer<vtkCornerAnnotation>::New();
123 ca->GetTextProperty()->SetColor(255,10,212);
124 ca->SetVisibility(1);
132 legend = vtkSmartPointer<vtkScalarBarActor>::New();
133 //legend->SetTitle("test!");
134 legend->SetPosition(0.82,0.18);
135 legend->SetWidth(0.1);
136 legend->SetVisibility(0);
137 legend->SetLabelFormat("%.1f");
138 this->GetRenderer()->AddActor(legend);
139 showFusionLegend = false;
141 this->WindowLevel->Delete();
142 this->WindowLevel = vvImageMapToWLColors::New();
144 this->InstallPipeline();
146 mLinkOverlayWindowLevel = true;
148 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
149 this->GetImageActor()->GetMapper()->BorderOn();
152 mSlicingTransform = vtkSmartPointer<vtkTransform>::New();
153 mConcatenatedTransform = vtkSmartPointer<vtkTransform>::New();
154 mConcatenatedFusionTransform = vtkSmartPointer<vtkTransform>::New();
155 mConcatenatedOverlayTransform = vtkSmartPointer<vtkTransform>::New();
157 //------------------------------------------------------------------------------
160 //------------------------------------------------------------------------------
161 vtkImageMapToWindowLevelColors* vvSlicer::GetOverlayMapper()
163 return mOverlayMapper.GetPointer();
165 //------------------------------------------------------------------------------
168 //------------------------------------------------------------------------------
169 vvBlendImageActor* vvSlicer::GetOverlayActor()
171 return mOverlayActor.GetPointer();
173 //------------------------------------------------------------------------------
176 //------------------------------------------------------------------------------
177 vtkImageMapToColors* vvSlicer::GetFusionMapper()
179 return mFusionMapper.GetPointer();
181 //------------------------------------------------------------------------------
184 //------------------------------------------------------------------------------
185 vtkImageActor* vvSlicer::GetFusionActor()
187 return mFusionActor.GetPointer();
189 //------------------------------------------------------------------------------
192 //------------------------------------------------------------------------------
193 vtkActor* vvSlicer::GetVFActor()
195 return mVFActor.GetPointer();
197 //------------------------------------------------------------------------------
200 //------------------------------------------------------------------------------
201 vtkCornerAnnotation* vvSlicer::GetAnnotation()
203 return ca.GetPointer();
205 //------------------------------------------------------------------------------
208 //------------------------------------------------------------------------------
209 void vvSlicer::EnableReducedExtent(bool b)
211 mUseReducedExtent = b;
213 //------------------------------------------------------------------------------
216 //------------------------------------------------------------------------------
217 void vvSlicer::SetReducedExtent(int * ext)
219 copyExtent(ext, mReducedExtent);
221 //------------------------------------------------------------------------------
224 //------------------------------------------------------------------------------
225 void vvSlicer::AddContour(vvMesh::Pointer contour,bool propagate)
228 mSurfaceCutActors.push_back(new vvMeshActor());
230 mSurfaceCutActors.back()->Init(contour,mCurrentTSlice,mVF);
232 mSurfaceCutActors.back()->Init(contour,mCurrentTSlice);
233 mSurfaceCutActors.back()->SetSlicingOrientation(SliceOrientation);
234 this->GetRenderer()->AddActor(mSurfaceCutActors.back()->GetActor());
238 //------------------------------------------------------------------------------
241 //------------------------------------------------------------------------------
242 void vvSlicer::ToggleContourSuperposition()
244 for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
245 i!=mSurfaceCutActors.end(); i++)
246 (*i)->ToggleSuperposition();
248 //------------------------------------------------------------------------------
251 //------------------------------------------------------------------------------
252 void vvSlicer::SetCursorColor(int r,int g, int b)
254 pdmA->GetProperty()->SetColor(r,g,b);
256 //------------------------------------------------------------------------------
259 //------------------------------------------------------------------------------
260 void vvSlicer::SetCursorVisibility(bool s)
262 pdmA->SetVisibility(s);
264 //------------------------------------------------------------------------------
267 //------------------------------------------------------------------------------
268 bool vvSlicer::GetCursorVisibility()
270 return pdmA->GetVisibility();
272 //------------------------------------------------------------------------------
275 //------------------------------------------------------------------------------
276 void vvSlicer::SetCornerAnnotationVisibility(bool s)
278 ca->SetVisibility(s);
280 //------------------------------------------------------------------------------
283 //------------------------------------------------------------------------------
284 bool vvSlicer::GetCornerAnnotationVisibility()
286 return ca->GetVisibility();
288 //------------------------------------------------------------------------------
291 //------------------------------------------------------------------------------
292 vvSlicer::~vvSlicer()
294 for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
295 i!=mSurfaceCutActors.end(); i++)
297 delete [] mReducedExtent;
299 //------------------------------------------------------------------------------
301 //------------------------------------------------------------------------------
302 double* vvSlicer::GetCurrentPosition()
304 return mCurrentBeforeSlicingTransform;
306 //------------------------------------------------------------------------------
308 //------------------------------------------------------------------------------
309 void vvSlicer::SetCurrentPosition(double x, double y, double z, int t)
311 mCurrentBeforeSlicingTransform[0]=x;
312 mCurrentBeforeSlicingTransform[1]=y;
313 mCurrentBeforeSlicingTransform[2]=z;
314 mSlicingTransform->GetInverse()->TransformPoint(mCurrentBeforeSlicingTransform,mCurrent);
317 //------------------------------------------------------------------------------
320 //------------------------------------------------------------------------------
321 void vvSlicer::SetImage(vvImage::Pointer image)
323 if (image->GetVTKImages().size()) {
326 if (!mImageReslice) {
327 mImageReslice = vtkSmartPointer<vtkImageReslice>::New();
328 mImageReslice->SetInterpolationModeToLinear();
329 mImageReslice->AutoCropOutputOn();
330 mImageReslice->SetBackgroundColor(-1000,-1000,-1000,1);
333 mConcatenatedTransform->Identity();
334 mConcatenatedTransform->Concatenate(mImage->GetTransform()[0]);
335 mConcatenatedTransform->Concatenate(mSlicingTransform);
336 mImageReslice->SetResliceTransform(mConcatenatedTransform);
337 mImageReslice->SetInput(0, mImage->GetFirstVTKImageData());
338 mImageReslice->UpdateInformation();
340 this->Superclass::SetInput(mImageReslice->GetOutput());
343 this->GetInput()->GetWholeExtent(extent);
345 // Prevent crash when reload -> change slice if outside extent
346 if (Slice < extent[SliceOrientation*2] || Slice>=extent[SliceOrientation*2+1]) {
347 Slice = (extent[SliceOrientation*2+1]+extent[SliceOrientation*2])/2.0;
350 // Make sure that the required part image has been computed
351 extent[SliceOrientation*2] = Slice;
352 extent[SliceOrientation*2+1] = Slice;
353 mImageReslice->GetOutput()->SetUpdateExtent(extent);
354 mImageReslice->GetOutput()->Update();
356 this->UpdateDisplayExtent();
359 ca->SetText(0,mFileName.c_str());
362 //------------------------------------------------------------------------------
365 //------------------------------------------------------------------------------
366 void vvSlicer::SetOverlay(vvImage::Pointer overlay)
368 if (overlay->GetVTKImages().size()) {
371 if (!mOverlayReslice) {
372 mOverlayReslice = vtkSmartPointer<vtkImageReslice>::New();
373 mOverlayReslice->SetInterpolationModeToLinear();
374 mOverlayReslice->AutoCropOutputOn();
375 mOverlayReslice->SetBackgroundColor(-1000,-1000,-1000,1);
378 mConcatenatedOverlayTransform->Identity();
379 mConcatenatedOverlayTransform->Concatenate(mOverlay->GetTransform()[0]);
380 mConcatenatedOverlayTransform->Concatenate(mSlicingTransform);
381 mOverlayReslice->SetResliceTransform(mConcatenatedOverlayTransform);
382 mOverlayReslice->SetInput(0, mOverlay->GetFirstVTKImageData());
383 mImageReslice->UpdateInformation();
386 mOverlayMapper = vtkSmartPointer<vtkImageMapToWindowLevelColors>::New();
387 mOverlayMapper->SetInput(mOverlayReslice->GetOutput());
389 if (!mOverlayActor) {
390 mOverlayActor = vtkSmartPointer<vvBlendImageActor>::New();
391 mOverlayActor->SetInput(mOverlayMapper->GetOutput());
392 mOverlayActor->SetPickable(0);
393 mOverlayActor->SetVisibility(true);
394 mOverlayActor->SetOpacity(0.5);
395 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
396 mOverlayActor->GetMapper()->BorderOn();
400 //stupid but necessary : the Overlay need to be rendered before fusion
402 this->GetRenderer()->RemoveActor(mFusionActor);
403 this->GetRenderer()->AddActor(mOverlayActor);
404 this->GetRenderer()->AddActor(mFusionActor);
406 this->GetRenderer()->AddActor(mOverlayActor);
408 //Synchronize orientation and slice
409 AdjustResliceToSliceOrientation(mOverlayReslice);
410 this->UpdateDisplayExtent();
411 this->SetTSlice(mCurrentTSlice);
414 //------------------------------------------------------------------------------
417 //------------------------------------------------------------------------------
418 void vvSlicer::SetFusion(vvImage::Pointer fusion)
420 if (fusion->GetVTKImages().size()) {
423 if (!mFusionReslice) {
424 mFusionReslice = vtkSmartPointer<vtkImageReslice>::New();
425 mFusionReslice->SetInterpolationModeToLinear();
426 mFusionReslice->AutoCropOutputOn();
427 mFusionReslice->SetBackgroundColor(-1000,-1000,-1000,1);
430 mConcatenatedFusionTransform->Identity();
431 mConcatenatedFusionTransform->Concatenate(mFusion->GetTransform()[0]);
432 mConcatenatedFusionTransform->Concatenate(mSlicingTransform);
433 mFusionReslice->SetResliceTransform(mConcatenatedFusionTransform);
434 mFusionReslice->SetInput(0, mFusion->GetFirstVTKImageData());
435 mFusionReslice->UpdateInformation();
438 mFusionMapper = vtkSmartPointer<vtkImageMapToColors>::New();
440 vtkSmartPointer<vtkLookupTable> lut = vtkLookupTable::New();
442 lut->SetValueRange(0, 1);
443 lut->SetSaturationRange(0, 0);
445 mFusionMapper->SetLookupTable(lut);
446 mFusionMapper->SetInput(mFusionReslice->GetOutput());
449 mFusionActor = vtkSmartPointer<vtkImageActor>::New();
450 mFusionActor->SetInput(mFusionMapper->GetOutput());
451 mFusionActor->SetPickable(0);
452 mFusionActor->SetVisibility(true);
453 mFusionActor->SetOpacity(0.7);
454 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
455 mFusionActor->GetMapper()->BorderOn();
457 this->GetRenderer()->AddActor(mFusionActor);
460 //Synchronize orientation and slice
461 AdjustResliceToSliceOrientation(mFusionReslice);
462 this->UpdateDisplayExtent();
463 this->SetTSlice(mCurrentTSlice);
466 //------------------------------------------------------------------------------
469 //------------------------------------------------------------------------------
470 bool vvSlicer::GetActorVisibility(const std::string& actor_type, int overlay_index)
473 if (actor_type == "image") {
474 vis = this->ImageActor->GetVisibility();
476 else if (actor_type == "vector") {
477 vis = this->mVFActor->GetVisibility();
479 else if (actor_type == "overlay") {
480 vis = this->mOverlayActor->GetVisibility();
482 else if (actor_type == "fusion") {
483 vis = this->mFusionActor->GetVisibility();
485 else if (actor_type == "contour")
486 vis = this->mSurfaceCutActors[overlay_index]->GetActor()->GetVisibility();
490 //------------------------------------------------------------------------------
492 //------------------------------------------------------------------------------
493 void vvSlicer::SetActorVisibility(const std::string& actor_type, int overlay_index ,bool vis)
495 if (actor_type == "image") {
496 this->ImageActor->SetVisibility(vis);
498 else if (actor_type == "vector") {
499 this->mVFActor->SetVisibility(vis);
501 else if (actor_type == "overlay") {
502 this->mOverlayActor->SetVisibility(vis);
504 else if (actor_type == "fusion") {
505 this->mFusionActor->SetVisibility(vis);
507 else if (actor_type == "contour")
508 this->mSurfaceCutActors[overlay_index]->GetActor()->SetVisibility(vis);
509 UpdateDisplayExtent();
511 //------------------------------------------------------------------------------
513 //------------------------------------------------------------------------------
514 void vvSlicer::SetVF(vvImage::Pointer vf)
516 if (vf->GetVTKImages().size()) {
520 mAAFilter= vtkSmartPointer<vtkAssignAttribute>::New();
521 mVOIFilter = vtkSmartPointer<vtkExtractVOI>::New();
522 mVOIFilter->SetSampleRate(mSubSampling,mSubSampling,mSubSampling);
524 mVOIFilter->SetInput(vf->GetFirstVTKImageData());
525 mAAFilter->SetInput(mVOIFilter->GetOutput());
526 ///This tells VTK to use the scalar (pixel) data of the image to draw the little arrows
527 mAAFilter->Assign(vtkDataSetAttributes::SCALARS, vtkDataSetAttributes::VECTORS, vtkAssignAttribute::POINT_DATA);
530 mArrow = vtkSmartPointer<vvGlyphSource>::New();
531 mArrow->SetGlyphTypeToSpecificArrow();
532 mArrow->SetScale(mScale);
535 // Glyph the gradient vector (with arrows)
537 mGlyphFilter = vtkSmartPointer<vvGlyph2D>::New();
538 mGlyphFilter->SetInput(mAAFilter->GetOutput());
539 mGlyphFilter->SetSource(mArrow->GetOutput());
540 mGlyphFilter->ScalingOn();
541 mGlyphFilter->SetScaleModeToScaleByVector();
542 mGlyphFilter->OrientOn();
543 mGlyphFilter->SetVectorModeToUseVector();
544 mGlyphFilter->SetColorModeToColorByVector();
547 mVFColorLUT = vtkSmartPointer<vtkLookupTable>::New();
549 double mVFColorHSV[3];
550 vtkMath::RGBToHSV(mVFColor, mVFColorHSV);
551 mVFColorLUT->SetHueRange(mVFColorHSV[0], mVFColorHSV[0]);
552 mVFColorLUT->SetSaturationRange(mVFColorHSV[1],mVFColorHSV[1]);
553 mVFColorLUT->SetValueRange(mVFColorHSV[2], mVFColorHSV[2]);
556 mVFMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
557 mVFMapper->SetInput(mGlyphFilter->GetOutput());
558 mVFMapper->ImmediateModeRenderingOn();
559 mVFMapper->SetLookupTable(mVFColorLUT);
562 mVFActor = vtkSmartPointer<vtkActor>::New();
563 mVFActor->SetMapper(mVFMapper);
564 mVFActor->SetPickable(0);
565 mVFActor->GetProperty()->SetLineWidth(mVFWidth);
566 this->UpdateDisplayExtent();
567 this->GetRenderer()->AddActor(mVFActor);
570 SetTSlice(mCurrentTSlice);
573 //------------------------------------------------------------------------------
576 //------------------------------------------------------------------------------
577 void vvSlicer::SetLandmarks(vvLandmarks* landmarks)
579 mLandmarks = landmarks;
583 mCross = vtkSmartPointer<vtkCursor3D>::New();
585 mClipBox = vtkSmartPointer<vtkBox>::New();
587 mLandClipper = vtkSmartPointer<vvClipPolyData>::New();
589 mLandGlyph = vtkSmartPointer<vtkGlyph3D>::New();
591 mLandMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
593 mLandActor = vtkSmartPointer<vtkActor>::New();
595 mCross->SetFocalPoint(0.0,0.0,0.0);
596 mCross->SetModelBounds(-10,10,-10,10,-10,10);
600 mLandClipper->SetClipFunction(mClipBox);
601 mLandClipper->InsideOutOn();
602 mLandClipper->SetInput(mLandmarks->GetOutput());
604 mLandGlyph->SetSource(mCross->GetOutput());
605 mLandGlyph->SetInput(mLandClipper->GetOutput());
606 //mLandGlyph->SetIndexModeToScalar();
607 //mLandGlyph->SetRange(0,1);
608 //mLandGlyph->ScalingOff();
610 //mLandGlyph->SetColorModeToColorByScalar();
612 mLandGlyph->SetScaleModeToDataScalingOff();
613 mLandGlyph->SetIndexModeToOff();
615 mLandMapper->SetInputConnection(mLandGlyph->GetOutputPort());
616 //mLandMapper->ScalarVisibilityOff();
618 mLandActor->SetMapper(mLandMapper);
619 mLandActor->GetProperty()->SetColor(255,10,212);
620 mLandActor->SetPickable(0);
621 mLandActor->SetVisibility(true);
622 this->UpdateDisplayExtent();
623 this->GetRenderer()->AddActor(mLandActor);
626 //------------------------------------------------------------------------------
628 //------------------------------------------------------------------------------
629 //FIXME: this function leaks memory, we should fix it someday :)
630 void vvSlicer::RemoveActor(const std::string& actor_type, int overlay_index)
632 if (actor_type == "vector") {
633 Renderer->RemoveActor(mVFActor);
642 if (actor_type == "overlay") {
643 Renderer->RemoveActor(mOverlayActor);
645 mOverlayActor = NULL;
646 mOverlayMapper = NULL;
648 if (actor_type == "fusion") {
649 Renderer->RemoveActor(mFusionActor);
652 mFusionMapper = NULL;
654 if (actor_type == "contour") {
655 Renderer->RemoveActor(this->mSurfaceCutActors[overlay_index]->GetActor());
656 mSurfaceCutActors.erase(mSurfaceCutActors.begin()+overlay_index);
659 //------------------------------------------------------------------------------
662 //------------------------------------------------------------------------------
663 void vvSlicer::SetVFSubSampling(int sub)
666 mVOIFilter->SetSampleRate(mSubSampling,mSubSampling,mSubSampling);
669 UpdateDisplayExtent();
672 //------------------------------------------------------------------------------
675 //------------------------------------------------------------------------------
676 void vvSlicer::SetVFScale(int scale)
680 mArrow->SetScale(mScale);
681 UpdateDisplayExtent();
684 //------------------------------------------------------------------------------
686 //------------------------------------------------------------------------------
687 void vvSlicer::SetVFWidth(int width)
691 mVFActor->GetProperty()->SetLineWidth(mVFWidth);
692 UpdateDisplayExtent();
695 //------------------------------------------------------------------------------
698 //------------------------------------------------------------------------------
699 void vvSlicer::SetVFLog(int log)
703 mGlyphFilter->SetUseLog(mVFLog);
704 mGlyphFilter->Modified();
706 UpdateDisplayExtent();
709 //------------------------------------------------------------------------------
712 //------------------------------------------------------------------------------
713 void vvSlicer::SetTSlice(int t)
717 else if ((unsigned int)t >= mImage->GetVTKImages().size())
718 mCurrentTSlice = mImage->GetVTKImages().size() -1;
723 mConcatenatedTransform->Identity();
724 mConcatenatedTransform->Concatenate(mImage->GetTransform()[mCurrentTSlice]);
725 mConcatenatedTransform->Concatenate(mSlicingTransform);
728 mImageReslice->SetInput( mImage->GetVTKImages()[mCurrentTSlice] );
729 if (mVF && mVFActor->GetVisibility()) {
730 if (mVF->GetVTKImages().size() > (unsigned int)mCurrentTSlice)
731 mVOIFilter->SetInput(mVF->GetVTKImages()[mCurrentTSlice]);
733 if (mOverlay && mOverlayActor->GetVisibility()) {
734 if (mOverlay->GetVTKImages().size() > (unsigned int)t) {
735 mCurrentOverlayTSlice = t;
736 mOverlayReslice->SetInput( mOverlay->GetVTKImages()[mCurrentOverlayTSlice] );
738 // Update overlay transform
739 mConcatenatedOverlayTransform->Identity();
740 mConcatenatedOverlayTransform->Concatenate(mOverlay->GetTransform()[mCurrentOverlayTSlice]);
741 mConcatenatedOverlayTransform->Concatenate(mSlicingTransform);
744 if (mFusion && mFusionActor->GetVisibility()) {
745 if (mFusion->GetVTKImages().size() > (unsigned int)t) {
746 mCurrentFusionTSlice = t;
747 mFusionReslice->SetInput( mFusion->GetVTKImages()[mCurrentFusionTSlice]);
749 // Update fusion transform
750 mConcatenatedFusionTransform->Identity();
751 mConcatenatedFusionTransform->Concatenate(mFusion->GetTransform()[mCurrentFusionTSlice]);
752 mConcatenatedFusionTransform->Concatenate(mSlicingTransform);
755 if (mSurfaceCutActors.size() > 0)
756 for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
757 i!=mSurfaceCutActors.end(); i++)
758 (*i)->SetTimeSlice(mCurrentTSlice);
759 UpdateDisplayExtent();
761 //------------------------------------------------------------------------------
764 //------------------------------------------------------------------------------
765 int vvSlicer::GetTSlice()
767 return mCurrentTSlice;
769 //------------------------------------------------------------------------------
771 //------------------------------------------------------------------------------
772 int vvSlicer::GetMaxCurrentTSlice()
774 int t = mCurrentTSlice;
776 t = std::max(t, mCurrentOverlayTSlice);
778 t = std::max(t, mCurrentFusionTSlice);
781 //------------------------------------------------------------------------------
783 //------------------------------------------------------------------------------
784 int vvSlicer::GetFusionTSlice()
786 return mCurrentFusionTSlice;
788 //------------------------------------------------------------------------------
790 //------------------------------------------------------------------------------
791 int vvSlicer::GetOverlayTSlice()
793 return mCurrentOverlayTSlice;
795 //------------------------------------------------------------------------------
797 //------------------------------------------------------------------------------
798 void vvSlicer::SetSliceOrientation(int orientation)
800 //if 2D image, force to watch in Axial View
802 this->GetInput()->GetWholeExtent(extent);
803 if (extent[5]-extent[4] <= 2)
804 orientation = vtkImageViewer2::SLICE_ORIENTATION_XY;
806 if (orientation < vtkImageViewer2::SLICE_ORIENTATION_YZ ||
807 orientation > vtkImageViewer2::SLICE_ORIENTATION_XY) {
808 vtkErrorMacro("Error - invalid slice orientation " << orientation);
812 this->SliceOrientation = orientation;
815 AdjustResliceToSliceOrientation(mFusionReslice);
818 AdjustResliceToSliceOrientation(mOverlayReslice);
822 // Go to current cursor position
823 // double* cursorPos = GetCursorPosition();
824 // DDV(cursorPos, 3);
825 // SetCurrentPosition(cursorPos[0],cursorPos[1],cursorPos[2],cursorPos[3]);
827 if (this->Renderer && this->GetInput()) {
828 double s = mCursor[orientation];
829 double sCursor = (s - this->GetInput()->GetOrigin()[orientation])/this->GetInput()->GetSpacing()[orientation];
830 this->Slice = static_cast<int>(sCursor);
833 // int *range = this->GetSliceRange();
835 // this->Slice = static_cast<int>((range[0] + range[1]) * 0.5);
837 this->UpdateOrientation();
838 this->UpdateDisplayExtent();
840 if (this->Renderer && this->GetInput()) {
841 double scale = this->Renderer->GetActiveCamera()->GetParallelScale();
842 this->Renderer->ResetCamera();
843 this->Renderer->GetActiveCamera()->SetParallelScale(scale);
848 //----------------------------------------------------------------------------
850 //------------------------------------------------------------------------------
851 // This function ensures that we sample the slices of a vtkImageReslice filter
852 // in the direction of the slicer (SliceOrientation) similarly as mImageReslice.
853 // In other words, we change the grid of the reslice in the same way as the grid
854 // of the displayed image in the slicing direction.
855 void vvSlicer::AdjustResliceToSliceOrientation(vtkImageReslice *reslice)
857 // Reset autocrop and update output information
858 reslice->SetOutputOriginToDefault();
859 reslice->SetOutputSpacingToDefault();
860 reslice->GetOutput()->UpdateInformation();
862 // Ge new origin / spacing
865 reslice->GetOutput()->GetOrigin(origin);
866 reslice->GetOutput()->GetSpacing(spacing);
868 // Use similar spacing as the image in the direction SliceOrientation
869 spacing[this->SliceOrientation] = mImageReslice->GetOutput()->GetSpacing()[this->SliceOrientation];
871 // Modify origin to be on the image grid in the direction SliceOrientation in 3 steps
872 // Step 1: from world coordinates to image coordinates
873 origin[this->SliceOrientation] -= mImageReslice->GetOutput()->GetOrigin()[this->SliceOrientation];
874 origin[this->SliceOrientation] /= mImageReslice->GetOutput()->GetSpacing()[this->SliceOrientation];
875 // Step 2: round to superior grid positionInc
876 origin[this->SliceOrientation] = itk::Math::Ceil<double>(origin[this->SliceOrientation]);
877 // Step 3: back to world coordinates
878 origin[this->SliceOrientation] *= mImageReslice->GetOutput()->GetSpacing()[this->SliceOrientation];
879 origin[this->SliceOrientation] += mImageReslice->GetOutput()->GetOrigin()[this->SliceOrientation];
881 // Set new spacing and origin
882 reslice->SetOutputOrigin(origin);
883 reslice->SetOutputSpacing(spacing);
884 reslice->UpdateInformation();
885 reslice->GetOutput()->UpdateInformation();
887 //------------------------------------------------------------------------------
889 //----------------------------------------------------------------------------
890 int * vvSlicer::GetExtent(){
892 if (mUseReducedExtent) {
893 w_ext = mReducedExtent;
894 } else w_ext = GetInput()->GetWholeExtent();
897 //----------------------------------------------------------------------------
900 //----------------------------------------------------------------------------
901 int vvSlicer::GetOrientation()
903 return this->SliceOrientation;
905 //----------------------------------------------------------------------------
908 //----------------------------------------------------------------------------
909 void vvSlicer::UpdateDisplayExtent()
911 vtkImageData *input = this->GetInput();
912 if (!input || !this->ImageActor) {
915 input->UpdateInformation();
917 // Local copy of extent
919 int* ext = GetExtent();
920 copyExtent(ext, w_ext);
922 int s = this->Slice > ext[this->SliceOrientation*2+1] ? ext[this->SliceOrientation*2 + 1] : this->Slice;
923 w_ext[ this->SliceOrientation*2 ] = s;
924 w_ext[ this->SliceOrientation*2+1 ] = s;
927 this->ImageActor->SetDisplayExtent(w_ext);
929 // Overlay image actor
930 if (mOverlay && mOverlayActor->GetVisibility()) {
931 AdjustResliceToSliceOrientation(mOverlayReslice);
933 this->ConvertImageToImageDisplayExtent(input, w_ext, mOverlayReslice->GetOutput(), overExtent);
934 ClipDisplayedExtent(overExtent, mOverlayMapper->GetInput()->GetWholeExtent());
935 mOverlayActor->SetDisplayExtent( overExtent );
938 // Fusion image actor
939 if (mFusion && mFusionActor->GetVisibility()) {
940 AdjustResliceToSliceOrientation(mFusionReslice);
942 this->ConvertImageToImageDisplayExtent(input, w_ext, mFusionReslice->GetOutput(), fusExtent);
943 ClipDisplayedExtent(fusExtent, mFusionMapper->GetInput()->GetWholeExtent());
944 mFusionActor->SetDisplayExtent(fusExtent);
947 // Vector field actor
948 double* camera = Renderer->GetActiveCamera()->GetPosition();
949 double* image_bounds = ImageActor->GetBounds();
950 double position[3] = {0, 0, 0};
951 position[this->SliceOrientation] = image_bounds[this->SliceOrientation*2];
953 //print_vector<double, 6>("camera", camera);
954 //print_vector<double, 6>("image_bounds", image_bounds);
955 //print_vector<double, 3>("position", position);
957 // find where to place the VF actor. to deal with
958 // z-buffer issues, the VF is placed right in front of the image,
959 // subject to a small offset. the position actually depends on the
960 // the location of the camera relative to the image.
962 if (camera[this->SliceOrientation] < image_bounds[this->SliceOrientation*2])
965 if (mVF && mVFActor->GetVisibility()) {
967 mVF->GetVTKImages()[0]->UpdateInformation();
968 this->ConvertImageToImageDisplayExtent(input, w_ext, mVF->GetVTKImages()[0], vfExtent);
969 ClipDisplayedExtent(vfExtent, mVOIFilter->GetInput()->GetWholeExtent());
970 mVOIFilter->SetVOI(vfExtent);
971 int orientation[3] = {1,1,1};
972 orientation[this->SliceOrientation] = 0;
973 mGlyphFilter->SetOrientation(orientation[0], orientation[1], orientation[2]);
976 position[this->SliceOrientation] += offset;
977 mVFActor->SetPosition(position);
984 for(unsigned int i=0; i<6; i++)
985 bounds[i] = ImageActor->GetBounds()[i];
986 bounds[ this->SliceOrientation*2 ] = ImageActor->GetBounds()[ this->SliceOrientation*2 ]-fabs(this->GetInput()->GetSpacing()[this->SliceOrientation]);
987 bounds[ this->SliceOrientation*2+1 ] = ImageActor->GetBounds()[ this->SliceOrientation*2+1 ]+fabs(this->GetInput()->GetSpacing()[this->SliceOrientation]);
988 mClipBox->SetBounds(bounds);
992 position[this->SliceOrientation] = offset;
993 mLandActor->SetPosition(position);
996 // Figure out the correct clipping range
997 if (this->Renderer) {
998 if (this->InteractorStyle &&
999 this->InteractorStyle->GetAutoAdjustCameraClippingRange()) {
1000 this->Renderer->ResetCameraClippingRange();
1002 vtkCamera *cam = this->Renderer->GetActiveCamera();
1005 this->ImageActor->GetBounds(bounds);
1006 double spos = (double)bounds[this->SliceOrientation * 2];
1007 double cpos = (double)cam->GetPosition()[this->SliceOrientation];
1008 double range = fabs(spos - cpos);
1009 double *spacing = input->GetSpacing();
1010 double sumSpacing = spacing[0] + spacing[1] + spacing[2];
1011 cam->SetClippingRange(range - sumSpacing, range + sumSpacing);
1017 //----------------------------------------------------------------------------
1019 //----------------------------------------------------------------------------
1020 void vvSlicer::ConvertImageToImageDisplayExtent(vtkImageData *sourceImage, const int sourceExtent[6],
1021 vtkImageData *targetImage, int targetExtent[6])
1024 for(unsigned int i=0; i<6; i++) {
1025 // From source voxel coordinates to world coordinates
1026 dExtents[i] = sourceImage->GetOrigin()[i/2] + sourceImage->GetSpacing()[i/2] * sourceExtent[i];
1028 // From world coordinates to floating point target voxel coordinates
1029 dExtents[i] = (dExtents[i]- targetImage->GetOrigin()[i/2]) / targetImage->GetSpacing()[i/2];
1032 //targetExtent[i] = itk::Math::Round<double>(dExtents[i]);
1033 targetExtent[i] = itk::Math::Floor<double>(dExtents[i]);
1036 //----------------------------------------------------------------------------
1038 //----------------------------------------------------------------------------
1039 void vvSlicer::ClipDisplayedExtent(int extent[6], int refExtent[6])
1044 //2D overlay on 3D image specific case
1045 if (refExtent[4] == refExtent[5]) {
1047 extent[4] = refExtent[4];
1048 extent[5] = refExtent[5];
1051 for (int i = 0; i < maxBound; i = i+2) {
1052 //if we are totally outside the image
1053 if ( extent[i] > refExtent[i+1] || extent[i+1] < refExtent[i] ) {
1057 //crop to the limit of the image
1058 extent[i] = (extent[i] > refExtent[i]) ? extent[i] : refExtent[i];
1059 extent[i] = (extent[i] < refExtent[i+1]) ? extent[i] : refExtent[i+1];
1060 extent[i+1] = (extent[i+1] > refExtent[i]) ? extent[i+1] : refExtent[i];
1061 extent[i+1] = (extent[i+1] < refExtent[i+1]) ? extent[i+1] : refExtent[i+1];
1064 for (int i = 0; i < maxBound; i = i+2) {
1065 extent[i] = refExtent[i];
1066 extent[i+1] = refExtent[i];
1069 //----------------------------------------------------------------------------
1072 //----------------------------------------------------------------------------
1073 void vvSlicer::UpdateOrientation()
1075 // Set the camera position
1076 vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
1078 switch (this->SliceOrientation) {
1079 case vtkImageViewer2::SLICE_ORIENTATION_XY:
1080 cam->SetFocalPoint(0,0,0);
1081 cam->SetPosition(0,0,-1); // -1 if medical ?
1082 cam->SetViewUp(0,-1,0);
1085 case vtkImageViewer2::SLICE_ORIENTATION_XZ:
1086 cam->SetFocalPoint(0,0,0);
1087 cam->SetPosition(0,-1,0); // 1 if medical ?
1088 cam->SetViewUp(0,0,1);
1091 case vtkImageViewer2::SLICE_ORIENTATION_YZ:
1092 cam->SetFocalPoint(0,0,0);
1093 cam->SetPosition(-1,0,0); // -1 if medical ?
1094 cam->SetViewUp(0,0,1);
1099 //----------------------------------------------------------------------------
1102 //----------------------------------------------------------------------------
1103 void vvSlicer::SetOpacity(double s)
1105 this->GetImageActor()->SetOpacity(s);
1107 //----------------------------------------------------------------------------
1110 //----------------------------------------------------------------------------
1111 void vvSlicer::SetRenderWindow(int orientation, vtkRenderWindow * rw)
1113 this->Superclass::SetRenderWindow(rw);
1114 this->SetupInteractor(rw->GetInteractor());
1115 ca->SetImageActor(this->GetImageActor());
1116 ca->SetWindowLevel(this->GetWindowLevel());
1117 ca->SetText(2, "<slice>");
1118 ca->SetText(3, "<window>\n<level>");
1130 crossCursor->SetModelBounds(bounds);
1131 this->GetRenderer()->AddActor(pdmA);
1132 this->GetRenderer()->AddActor(ca);
1133 this->GetRenderer()->ResetCamera();
1135 //this is just a mapping between the labeling of the orientations presented to the user and
1136 //the one used by vtk
1137 SetSliceOrientation(2-(orientation%3));
1140 //----------------------------------------------------------------------------
1143 //----------------------------------------------------------------------------
1144 void vvSlicer::ResetCamera()
1146 this->GetRenderer()->ResetCamera();
1148 //----------------------------------------------------------------------------
1151 //----------------------------------------------------------------------------
1152 void vvSlicer::SetDisplayMode(bool i)
1154 this->GetRenderer()->SetDraw(i);
1156 UpdateDisplayExtent();
1158 //----------------------------------------------------------------------------
1161 //----------------------------------------------------------------------------
1162 void vvSlicer::FlipHorizontalView()
1164 vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
1166 double *position = cam->GetPosition();
1167 double factor[3] = {1, 1, 1};
1168 factor[this->SliceOrientation] = -1;
1169 cam->SetPosition(factor[0]*position[0],factor[1]*position[1],factor[2]*position[2]);
1171 /* switch (this->SliceOrientation) {
1172 case vtkImageViewer2::SLICE_ORIENTATION_XY:
1173 cam->SetPosition(position[0],position[1],-position[2]);
1176 case vtkImageViewer2::SLICE_ORIENTATION_XZ:
1177 cam->SetPosition(position[0],-position[1],position[2]);
1180 case vtkImageViewer2::SLICE_ORIENTATION_YZ:
1181 cam->SetPosition(-position[0],position[1],position[2]);
1185 this->Renderer->ResetCameraClippingRange();
1186 this->UpdateDisplayExtent();
1189 //----------------------------------------------------------------------------
1192 //----------------------------------------------------------------------------
1193 void vvSlicer::FlipVerticalView()
1195 vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
1197 FlipHorizontalView();
1198 double *viewup = cam->GetViewUp();
1199 cam->SetViewUp(-viewup[0],-viewup[1],-viewup[2]);
1200 this->UpdateDisplayExtent();
1203 //----------------------------------------------------------------------------
1206 //----------------------------------------------------------------------------
1207 void vvSlicer::SetColorWindow(double window)
1209 vtkLookupTable* LUT = static_cast<vtkLookupTable*>(this->GetWindowLevel()->GetLookupTable());
1211 double level = this->GetWindowLevel()->GetLevel();
1212 LUT->SetTableRange(level-fabs(window)/2,level+fabs(window)/2);
1215 this->vtkImageViewer2::SetColorWindow(window);
1217 //----------------------------------------------------------------------------
1219 //----------------------------------------------------------------------------
1220 void vvSlicer::SetColorLevel(double level)
1222 vtkLookupTable* LUT = static_cast<vtkLookupTable*>(this->GetWindowLevel()->GetLookupTable());
1224 double window = this->GetWindowLevel()->GetWindow();
1225 LUT->SetTableRange(level-fabs(window)/2,level+fabs(window)/2);
1228 this->vtkImageViewer2::SetColorLevel(level);
1230 //----------------------------------------------------------------------------
1232 //----------------------------------------------------------------------------
1233 double vvSlicer::GetOverlayColorWindow()
1236 return mOverlayMapper->GetWindow();
1240 //----------------------------------------------------------------------------
1242 //----------------------------------------------------------------------------
1243 double vvSlicer::GetOverlayColorLevel()
1246 return mOverlayMapper->GetLevel();
1250 //----------------------------------------------------------------------------
1252 //----------------------------------------------------------------------------
1253 void vvSlicer::SetOverlayColorWindow(double window)
1255 mOverlayMapper->SetWindow(window);
1257 //----------------------------------------------------------------------------
1259 //----------------------------------------------------------------------------
1260 void vvSlicer::SetOverlayColorLevel(double level)
1262 mOverlayMapper->SetLevel(level);
1264 //----------------------------------------------------------------------------
1266 //----------------------------------------------------------------------------
1267 // Returns the min an the max value in a 20%x20% region around the mouse pointer
1268 void vvSlicer::GetExtremasAroundMousePointer(double & min, double & max, vtkImageData *image, vtkTransform *transform)
1270 //Get mouse pointer position in view coordinates
1273 for(int i=0; i<3; i++) {
1274 corner1[i] = mCurrent[i];
1275 corner2[i] = mCurrent[i];
1278 this->Renderer->WorldToView(corner1[0], corner1[1], corner1[2]);
1279 this->Renderer->WorldToView(corner2[0], corner2[1], corner2[2]);
1281 // In view coordinates, x is the slicer width and y is the slicer height are the in-plane axis
1283 this->Renderer->GetTiledSize(&w, &h);
1284 corner1[0] -= 0.2*h/(double)w;
1285 corner2[0] += 0.2*h/(double)w;
1288 this->Renderer->ViewToWorld(corner1[0], corner1[1], corner1[2]);
1289 this->Renderer->ViewToWorld(corner2[0], corner2[1], corner2[2]);
1291 //Convert to image pixel coordinates (rounded)
1292 transform->TransformPoint(corner1, corner1);
1293 transform->TransformPoint(corner2, corner2);
1294 int iLocalExtents[6];
1295 for(int i=0; i<3; i++) {
1296 corner1[i] = (corner1[i] - image->GetOrigin()[i])/image->GetSpacing()[i];
1297 corner2[i] = (corner2[i] - image->GetOrigin()[i])/image->GetSpacing()[i];
1299 iLocalExtents[i*2 ] = lrint(corner1[i]);
1300 iLocalExtents[i*2+1] = lrint(corner2[i]);
1302 if(iLocalExtents[i*2 ]>iLocalExtents[i*2+1])
1303 std::swap(iLocalExtents[i*2], iLocalExtents[i*2+1]);
1306 vtkSmartPointer<vtkExtractVOI> voiFilter = vtkSmartPointer<vtkExtractVOI>::New();
1307 voiFilter->SetInput(image);
1308 voiFilter->SetVOI(iLocalExtents);
1309 voiFilter->Update();
1310 if (!voiFilter->GetOutput()->GetNumberOfPoints()) {
1316 vtkSmartPointer<vtkImageAccumulate> accFilter = vtkSmartPointer<vtkImageAccumulate>::New();
1317 accFilter->SetInput(voiFilter->GetOutput());
1318 accFilter->Update();
1320 min = *(accFilter->GetMin());
1321 max = *(accFilter->GetMax());
1323 //----------------------------------------------------------------------------
1325 //----------------------------------------------------------------------------
1326 double vvSlicer::GetScalarComponentAsDouble(vtkImageData *image, double X, double Y, double Z, int &ix, int &iy, int &iz, int component)
1331 if (ix < image->GetWholeExtent()[0] ||
1332 ix > image->GetWholeExtent()[1] ||
1333 iy < image->GetWholeExtent()[2] ||
1334 iy > image->GetWholeExtent()[3] ||
1335 iz < image->GetWholeExtent()[4] ||
1336 iz > image->GetWholeExtent()[5] )
1337 return std::numeric_limits<double>::quiet_NaN();
1339 image->SetUpdateExtent(ix, ix, iy, iy, iz, iz);
1341 return image->GetScalarComponentAsDouble(ix, iy, iz, component);
1343 //----------------------------------------------------------------------------
1345 //----------------------------------------------------------------------------
1346 void vvSlicer::Render()
1348 if (this->mFusion && mFusionActor->GetVisibility() && showFusionLegend) {
1349 legend->SetLookupTable(this->GetFusionMapper()->GetLookupTable());
1350 legend->UseOpacityOn();
1351 legend->SetVisibility(1);
1353 else if (this->GetWindowLevel()->GetLookupTable() && !this->mOverlay) {
1354 legend->SetLookupTable(this->GetWindowLevel()->GetLookupTable());
1355 legend->UseOpacityOff();
1356 legend->SetVisibility(1);
1357 } else legend->SetVisibility(0);
1359 if (ca->GetVisibility()) {
1360 std::stringstream worldPos;
1362 mConcatenatedTransform->TransformPoint(mCurrent, pt);
1363 double X = (pt[0] - mImage->GetVTKImages()[mCurrentTSlice]->GetOrigin()[0])/mImage->GetVTKImages()[mCurrentTSlice]->GetSpacing()[0];
1364 double Y = (pt[1] - mImage->GetVTKImages()[mCurrentTSlice]->GetOrigin()[1])/mImage->GetVTKImages()[mCurrentTSlice]->GetSpacing()[1];
1365 double Z = (pt[2] - mImage->GetVTKImages()[mCurrentTSlice]->GetOrigin()[2])/mImage->GetVTKImages()[mCurrentTSlice]->GetSpacing()[2];
1367 if (X >= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[0]-0.5 &&
1368 X <= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[1]+0.5 &&
1369 Y >= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[2]-0.5 &&
1370 Y <= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[3]+0.5 &&
1371 Z >= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[4]-0.5 &&
1372 Z <= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[5]+0.5) {
1376 double value = this->GetScalarComponentAsDouble(mImage->GetVTKImages()[mCurrentTSlice], X, Y, Z, ix, iy, iz);
1378 if(ImageActor->GetVisibility())
1379 worldPos << "data value : " << value << std::endl;
1381 worldPos << "mm : " << lrint(mCurrentBeforeSlicingTransform[0]) << ' '
1382 << lrint(mCurrentBeforeSlicingTransform[1]) << ' '
1383 << lrint(mCurrentBeforeSlicingTransform[2]) << ' '
1386 worldPos << "pixel : " << ix << ' '
1392 ca->SetText(1,worldPos.str().c_str());
1395 if (pdmA->GetVisibility()) {
1396 double x = mCursor[0];
1397 double y = mCursor[1];
1398 double z = mCursor[2];
1399 double xCursor = (x - this->GetInput()->GetOrigin()[0])/this->GetInput()->GetSpacing()[0];
1400 double yCursor = (y - this->GetInput()->GetOrigin()[1])/this->GetInput()->GetSpacing()[1];
1401 double zCursor = (z - this->GetInput()->GetOrigin()[2])/this->GetInput()->GetSpacing()[2];
1403 if (xCursor >= this->GetImageActor()->GetDisplayExtent()[0] &&
1404 xCursor < this->GetImageActor()->GetDisplayExtent()[1]+1 &&
1405 yCursor >= this->GetImageActor()->GetDisplayExtent()[2] &&
1406 yCursor < this->GetImageActor()->GetDisplayExtent()[3]+1 &&
1407 zCursor >= this->GetImageActor()->GetDisplayExtent()[4] &&
1408 zCursor < this->GetImageActor()->GetDisplayExtent()[5]+1 ) {
1409 vtkRenderer * renderer = this->Renderer;
1411 renderer->WorldToView(x,y,z);
1412 renderer->ViewToNormalizedViewport(x,y,z);
1413 renderer->NormalizedViewportToViewport(x,y);
1414 renderer->ViewportToNormalizedDisplay(x,y);
1415 renderer->NormalizedDisplayToDisplay(x,y);
1416 crossCursor->SetFocalPoint(x,y,z);
1418 crossCursor->SetFocalPoint(-1,-1,z);
1422 if (mOverlay && mOverlayActor->GetVisibility()) {
1423 if(mLinkOverlayWindowLevel) {
1424 mOverlayMapper->SetWindow(this->GetColorWindow());
1425 mOverlayMapper->SetLevel(this->GetColorLevel());
1427 mOverlayMapper->GetOutput()->SetUpdateExtent(mOverlayActor->GetDisplayExtent());
1428 mOverlayMapper->GetOutput()->Update();
1429 mOverlayMapper->Update();
1434 this->GetRenderWindow()->Render();
1436 //----------------------------------------------------------------------------
1439 //----------------------------------------------------------------------------
1440 void vvSlicer::UpdateCursorPosition()
1442 pdmA->SetVisibility(true);
1443 mCursor[0] = mCurrent[0];
1444 mCursor[1] = mCurrent[1];
1445 mCursor[2] = mCurrent[2];
1446 mCursor[3] = mCurrentTSlice;
1448 //----------------------------------------------------------------------------
1451 //----------------------------------------------------------------------------
1452 void vvSlicer::UpdateLandmarks()
1454 vtkPolyData *pd = static_cast<vtkPolyData*>(mLandClipper->GetInput());
1455 if (pd->GetPoints()) {
1456 //mLandGlyph->SetRange(0,1);
1457 //mLandGlyph->Modified();
1458 //mLandGlyph->Update();
1460 mClipBox->Modified();
1461 mLandClipper->Update();
1462 mLandMapper->Update();
1463 //Let's add the captions
1464 //First remove all captions:
1465 for(unsigned int i=0;i<mLandLabelActors.size();i++) {
1466 this->Renderer->RemoveActor2D(mLandLabelActors[i]);
1467 //allActors2D->Remove (mLandLabelActors[i]);
1469 mLandLabelActors.clear();
1470 //Next add the captions to the displayed points
1471 for (vtkIdType id=0; id<mLandClipper->GetOutput()->GetNumberOfPoints(); id++) {
1472 double *position = mLandClipper->GetOutput()->GetPoint(id);
1473 vtkStdString label = static_cast<vtkStringArray*>(mLandClipper->GetOutput()->GetPointData()->GetAbstractArray("labels"))->GetValue(id);
1474 vtkSmartPointer<vtkCaptionActor2D> label_actor = vtkSmartPointer<vtkCaptionActor2D>::New();
1475 label_actor->SetCaption(label);
1476 label_actor->SetAttachmentPoint(position);
1477 label_actor->GetCaptionTextProperty()->SetColor(1,0,0);
1478 label_actor->GetCaptionTextProperty()->SetOrientation(33.333333);
1479 label_actor->GetCaptionTextProperty()->SetFontFamilyToTimes();
1480 label_actor->GetCaptionTextProperty()->SetBold(0);
1481 label_actor->GetCaptionTextProperty()->SetFontSize(6);
1482 label_actor->BorderOff();
1483 label_actor->LeaderOff();
1484 label_actor->ThreeDimensionalLeaderOff();
1485 mLandLabelActors.push_back(label_actor);
1486 this->Renderer->AddActor2D(mLandLabelActors[id]);
1491 //----------------------------------------------------------------------------
1494 //----------------------------------------------------------------------------
1495 void vvSlicer::SetSlice(int slice)
1497 int *range = this->GetSliceRange();
1499 if (slice < range[0]) {
1501 } else if (slice > range[1]) {
1506 if (this->Slice == slice) {
1510 this->Slice = slice;
1513 this->UpdateDisplayExtent();
1515 // Seems to work without this line
1518 //----------------------------------------------------------------------------
1520 //----------------------------------------------------------------------------
1521 int vvSlicer::GetTMax() {
1522 int tmax = (int)mImage->GetVTKImages().size() - 1;
1524 tmax = std::max(tmax, (int)mOverlay->GetVTKImages().size()-1);
1527 //----------------------------------------------------------------------------
1529 //----------------------------------------------------------------------------
1530 void vvSlicer::SetContourSlice()
1532 if (mSurfaceCutActors.size() > 0)
1533 for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
1534 i!=mSurfaceCutActors.end(); i++) {
1536 (*i)->SetSlicingOrientation(this->SliceOrientation);
1537 (*i)->SetCutSlice((this->Slice)*this->GetImage()->GetSpacing()[this->SliceOrientation]+
1538 this->GetImage()->GetOrigin()[this->SliceOrientation]);
1541 //----------------------------------------------------------------------------
1544 //----------------------------------------------------------------------------
1545 void vvSlicer::ForceUpdateDisplayExtent()
1547 this->UpdateDisplayExtent();
1549 //----------------------------------------------------------------------------
1552 //----------------------------------------------------------------------------
1553 int* vvSlicer::GetDisplayExtent()
1555 return this->GetImageActor()->GetDisplayExtent();
1557 //----------------------------------------------------------------------------
1560 //----------------------------------------------------------------------------
1561 void vvSlicer::PrintSelf(ostream& os, vtkIndent indent)
1563 this->Superclass::PrintSelf(os, indent);
1565 //----------------------------------------------------------------------------
1567 //----------------------------------------------------------------------------
1568 void vvSlicer::SetVFColor(double r, double g, double b)
1570 double mVFColorHSV[3];
1575 vtkMath::RGBToHSV(mVFColor, mVFColorHSV);
1576 mVFColorLUT->SetHueRange(mVFColorHSV[0], mVFColorHSV[0]);
1577 mVFColorLUT->SetSaturationRange(mVFColorHSV[1],mVFColorHSV[1]);
1578 mVFColorLUT->SetValueRange(mVFColorHSV[2], mVFColorHSV[2]);