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 ===========================================================================**/
19 #include <QMessageBox>
24 #include "vvSlicerManagerCommand.h"
25 #include "vvGlyphSource.h"
26 #include "vvGlyph2D.h"
28 #include <vtkTextProperty.h>
29 #include <vtkTextActor.h>
30 #include <vtkTextSource.h>
31 #include <vtkActor2D.h>
32 #include <vtkCursor2D.h>
33 #include <vtkPolyDataMapper2D.h>
34 #include <vtkProperty2D.h>
35 #include <vtkCornerAnnotation.h>
36 #include <vtkImageMapToWindowLevelColors.h>
37 #include <vtkImageData.h>
38 #include <vtkImageActor.h>
39 #include <vvBlendImageActor.h>
40 #include <vtkToolkits.h>
41 #include <vtkObjectFactory.h>
42 #include <vtkPointData.h>
43 #include <vtkDataArray.h>
44 #include <vtkFloatArray.h>
45 #include <vtkClipPolyData.h>
46 #include <vtkActor2DCollection.h>
47 #include <vtkGlyph3D.h>
49 #include <vtkCursor3D.h>
50 #include <vtkProperty.h>
52 #include <vtkLightCollection.h>
53 #include <vtkScalarBarActor.h>
54 #include <vtkLookupTable.h>
56 #include <vtkRenderer.h>
57 #include <vtkRendererCollection.h>
58 #include <vtkRenderWindow.h>
59 #include <vtkRenderWindowInteractor.h>
60 #include <vtkCamera.h>
61 #include <vtkCallbackCommand.h>
62 #include <vtkCommand.h>
63 #include <vtkPolyDataMapper.h>
66 #include <vtkExtractVOI.h>
67 #include <vtkSphereSource.h>
68 #include <vtkCutter.h>
69 #include <vtkAssignAttribute.h>
70 #include <vtkImageAccumulate.h>
71 #include <vtkImageReslice.h>
72 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
73 # include <vtkImageMapper3D.h>
76 vtkCxxRevisionMacro(vvSlicer, "DummyRevision");
77 vtkStandardNewMacro(vvSlicer);
78 static void copyExtent(int* in, int* to){
79 for(int i=0; i<6; ++i) to[i]=in[i];
81 //------------------------------------------------------------------------------
84 mFusionSequenceCode = -1;
85 this->UnInstallPipeline();
87 mReducedExtent = new int[6];
89 mCurrentFusionTSlice = 0;
90 mCurrentOverlayTSlice = 0;
91 mUseReducedExtent = false;
93 mCurrent[0] = -VTK_DOUBLE_MAX;
94 mCurrent[1] = -VTK_DOUBLE_MAX;
95 mCurrent[2] = -VTK_DOUBLE_MAX;
97 mCursor[0] = 0;//-VTK_DOUBLE_MAX;
98 mCursor[1] = 0;//-VTK_DOUBLE_MAX;
99 mCursor[2] = 0;//-VTK_DOUBLE_MAX;
100 mCursor[3] = 0;//-VTK_DOUBLE_MAX;
110 crossCursor = vtkSmartPointer<vtkCursor2D>::New();
111 crossCursor->AllOff();
112 crossCursor->AxesOn();
113 crossCursor->SetTranslationMode(1);
114 crossCursor->SetRadius(2);
116 pdm = vtkSmartPointer<vtkPolyDataMapper2D>::New();
117 pdm->SetInput(crossCursor->GetOutput());
119 pdmA = vtkSmartPointer<vtkActor2D>::New();
120 pdmA->SetMapper(pdm);
121 pdmA->GetProperty()->SetColor(255,10,212);
122 pdmA->SetVisibility(0);
123 pdmA->SetPickable(0);
125 ca = vtkSmartPointer<vtkCornerAnnotation>::New();
126 ca->GetTextProperty()->SetColor(255,10,212);
127 ca->SetVisibility(1);
135 legend = vtkSmartPointer<vtkScalarBarActor>::New();
136 //legend->SetTitle("test!");
137 legend->SetPosition(0.82,0.18);
138 legend->SetWidth(0.1);
139 legend->SetVisibility(0);
140 legend->SetLabelFormat("%.1f");
141 this->GetRenderer()->AddActor(legend);
142 showFusionLegend = false;
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);
315 if (t>=0) SetTSlice(t);
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, int fusionSequenceCode)
420 mFusionSequenceCode = fusionSequenceCode;
421 if (fusion->GetVTKImages().size()) {
424 if (!mFusionReslice) {
425 mFusionReslice = vtkSmartPointer<vtkImageReslice>::New();
426 mFusionReslice->SetInterpolationModeToLinear();
427 mFusionReslice->AutoCropOutputOn();
428 mFusionReslice->SetBackgroundColor(-1000,-1000,-1000,1);
431 mConcatenatedFusionTransform->Identity();
432 mConcatenatedFusionTransform->Concatenate(mFusion->GetTransform()[0]);
433 mConcatenatedFusionTransform->Concatenate(mSlicingTransform);
434 mFusionReslice->SetResliceTransform(mConcatenatedFusionTransform);
435 mFusionReslice->SetInput(0, mFusion->GetFirstVTKImageData());
436 mFusionReslice->UpdateInformation();
439 mFusionMapper = vtkSmartPointer<vtkImageMapToColors>::New();
441 vtkSmartPointer<vtkLookupTable> lut = vtkLookupTable::New();
443 lut->SetValueRange(0, 1);
444 lut->SetSaturationRange(0, 0);
446 mFusionMapper->SetLookupTable(lut);
447 mFusionMapper->SetInput(mFusionReslice->GetOutput());
450 mFusionActor = vtkSmartPointer<vtkImageActor>::New();
451 mFusionActor->SetInput(mFusionMapper->GetOutput());
452 mFusionActor->SetPickable(0);
453 mFusionActor->SetVisibility(true);
454 mFusionActor->SetOpacity(0.7);
455 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
456 mFusionActor->GetMapper()->BorderOn();
458 this->GetRenderer()->AddActor(mFusionActor);
461 //Synchronize orientation and slice
462 AdjustResliceToSliceOrientation(mFusionReslice);
463 this->UpdateDisplayExtent();
464 this->SetTSlice(mCurrentTSlice);
467 //------------------------------------------------------------------------------
470 //------------------------------------------------------------------------------
471 bool vvSlicer::GetActorVisibility(const std::string& actor_type, int overlay_index)
474 if (actor_type == "image") {
475 vis = this->ImageActor->GetVisibility();
477 else if (actor_type == "vector") {
478 vis = this->mVFActor->GetVisibility();
480 else if (actor_type == "overlay") {
481 vis = this->mOverlayActor->GetVisibility();
483 else if ( (actor_type == "fusion") || (actor_type == "fusionSequence") ){
484 vis = this->mFusionActor->GetVisibility();
486 else if (actor_type == "contour")
487 vis = this->mSurfaceCutActors[overlay_index]->GetActor()->GetVisibility();
491 //------------------------------------------------------------------------------
493 //------------------------------------------------------------------------------
494 void vvSlicer::SetActorVisibility(const std::string& actor_type, int overlay_index ,bool vis)
496 if (actor_type == "image") {
497 this->ImageActor->SetVisibility(vis);
499 else if (actor_type == "vector") {
500 this->mVFActor->SetVisibility(vis);
502 else if (actor_type == "overlay") {
503 this->mOverlayActor->SetVisibility(vis);
505 else if ( (actor_type == "fusion") || (actor_type == "fusionSequence") ){
506 this->mFusionActor->SetVisibility(vis);
508 else if (actor_type == "contour")
509 this->mSurfaceCutActors[overlay_index]->GetActor()->SetVisibility(vis);
510 UpdateDisplayExtent();
512 //------------------------------------------------------------------------------
514 //------------------------------------------------------------------------------
515 void vvSlicer::SetVF(vvImage::Pointer vf)
517 if (vf->GetVTKImages().size()) {
521 mAAFilter= vtkSmartPointer<vtkAssignAttribute>::New();
522 mVOIFilter = vtkSmartPointer<vtkExtractVOI>::New();
523 mVOIFilter->SetSampleRate(mSubSampling,mSubSampling,mSubSampling);
525 mVOIFilter->SetInput(vf->GetFirstVTKImageData());
526 mAAFilter->SetInput(mVOIFilter->GetOutput());
527 ///This tells VTK to use the scalar (pixel) data of the image to draw the little arrows
528 mAAFilter->Assign(vtkDataSetAttributes::SCALARS, vtkDataSetAttributes::VECTORS, vtkAssignAttribute::POINT_DATA);
531 mArrow = vtkSmartPointer<vvGlyphSource>::New();
532 mArrow->SetGlyphTypeToSpecificArrow();
533 mArrow->SetScale(mScale);
536 // Glyph the gradient vector (with arrows)
538 mGlyphFilter = vtkSmartPointer<vvGlyph2D>::New();
539 mGlyphFilter->SetInput(mAAFilter->GetOutput());
540 mGlyphFilter->SetSource(mArrow->GetOutput());
541 mGlyphFilter->ScalingOn();
542 mGlyphFilter->SetScaleModeToScaleByVector();
543 mGlyphFilter->OrientOn();
544 mGlyphFilter->SetVectorModeToUseVector();
545 mGlyphFilter->SetColorModeToColorByVector();
548 mVFColorLUT = vtkSmartPointer<vtkLookupTable>::New();
550 double mVFColorHSV[3];
551 vtkMath::RGBToHSV(mVFColor, mVFColorHSV);
552 mVFColorLUT->SetHueRange(mVFColorHSV[0], mVFColorHSV[0]);
553 mVFColorLUT->SetSaturationRange(mVFColorHSV[1],mVFColorHSV[1]);
554 mVFColorLUT->SetValueRange(mVFColorHSV[2], mVFColorHSV[2]);
557 mVFMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
558 mVFMapper->SetInput(mGlyphFilter->GetOutput());
559 mVFMapper->ImmediateModeRenderingOn();
560 mVFMapper->SetLookupTable(mVFColorLUT);
563 mVFActor = vtkSmartPointer<vtkActor>::New();
564 mVFActor->SetMapper(mVFMapper);
565 mVFActor->SetPickable(0);
566 mVFActor->GetProperty()->SetLineWidth(mVFWidth);
567 this->UpdateDisplayExtent();
568 this->GetRenderer()->AddActor(mVFActor);
571 SetTSlice(mCurrentTSlice);
574 //------------------------------------------------------------------------------
577 //------------------------------------------------------------------------------
578 void vvSlicer::SetLandmarks(vvLandmarks* landmarks)
580 mLandmarks = landmarks;
584 mCross = vtkSmartPointer<vtkCursor3D>::New();
586 mClipBox = vtkSmartPointer<vtkBox>::New();
588 mLandClipper = vtkSmartPointer<vvClipPolyData>::New();
590 mLandGlyph = vtkSmartPointer<vtkGlyph3D>::New();
592 mLandMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
594 mLandActor = vtkSmartPointer<vtkActor>::New();
596 mCross->SetFocalPoint(0.0,0.0,0.0);
597 mCross->SetModelBounds(-10,10,-10,10,-10,10);
601 mLandClipper->SetClipFunction(mClipBox);
602 mLandClipper->InsideOutOn();
603 mLandClipper->SetInput(mLandmarks->GetOutput());
605 mLandGlyph->SetSource(mCross->GetOutput());
606 mLandGlyph->SetInput(mLandClipper->GetOutput());
607 //mLandGlyph->SetIndexModeToScalar();
608 //mLandGlyph->SetRange(0,1);
609 //mLandGlyph->ScalingOff();
611 //mLandGlyph->SetColorModeToColorByScalar();
613 mLandGlyph->SetScaleModeToDataScalingOff();
614 mLandGlyph->SetIndexModeToOff();
616 mLandMapper->SetInputConnection(mLandGlyph->GetOutputPort());
617 //mLandMapper->ScalarVisibilityOff();
619 mLandActor->SetMapper(mLandMapper);
620 mLandActor->GetProperty()->SetColor(255,10,212);
621 mLandActor->SetPickable(0);
622 mLandActor->SetVisibility(true);
623 this->UpdateDisplayExtent();
624 this->GetRenderer()->AddActor(mLandActor);
627 //------------------------------------------------------------------------------
629 //------------------------------------------------------------------------------
630 //FIXME: this function leaks memory, we should fix it someday :)
631 void vvSlicer::RemoveActor(const std::string& actor_type, int overlay_index)
633 if (actor_type == "vector") {
634 Renderer->RemoveActor(mVFActor);
643 if (actor_type == "overlay") {
644 Renderer->RemoveActor(mOverlayActor);
646 mOverlayActor = NULL;
647 mOverlayMapper = NULL;
649 if ( (actor_type == "fusion") || (actor_type == "fusionSequence") ) {
650 Renderer->RemoveActor(mFusionActor);
653 mFusionMapper = NULL;
655 if (actor_type == "contour") {
656 Renderer->RemoveActor(this->mSurfaceCutActors[overlay_index]->GetActor());
657 mSurfaceCutActors.erase(mSurfaceCutActors.begin()+overlay_index);
660 //------------------------------------------------------------------------------
663 //------------------------------------------------------------------------------
664 void vvSlicer::SetVFSubSampling(int sub)
667 mVOIFilter->SetSampleRate(mSubSampling,mSubSampling,mSubSampling);
670 UpdateDisplayExtent();
673 //------------------------------------------------------------------------------
676 //------------------------------------------------------------------------------
677 void vvSlicer::SetVFScale(int scale)
681 mArrow->SetScale(mScale);
682 UpdateDisplayExtent();
685 //------------------------------------------------------------------------------
687 //------------------------------------------------------------------------------
688 void vvSlicer::SetVFWidth(int width)
692 mVFActor->GetProperty()->SetLineWidth(mVFWidth);
693 UpdateDisplayExtent();
696 //------------------------------------------------------------------------------
699 //------------------------------------------------------------------------------
700 void vvSlicer::SetVFLog(int log)
704 mGlyphFilter->SetUseLog(mVFLog);
705 mGlyphFilter->Modified();
707 UpdateDisplayExtent();
710 //------------------------------------------------------------------------------
713 //------------------------------------------------------------------------------
714 void vvSlicer::SetTSlice(int t, bool updateLinkedImages)
716 if (!updateLinkedImages) {
718 mImageReslice->SetInput( mImage->GetVTKImages()[mCurrentTSlice] );
720 mConcatenatedTransform->Identity();
721 mConcatenatedTransform->Concatenate(mImage->GetTransform()[mCurrentTSlice]);
722 mConcatenatedTransform->Concatenate(mSlicingTransform);
723 UpdateDisplayExtent();
729 else if ((unsigned int)t >= mImage->GetVTKImages().size())
730 mCurrentTSlice = mImage->GetVTKImages().size() -1;
735 mConcatenatedTransform->Identity();
736 mConcatenatedTransform->Concatenate(mImage->GetTransform()[mCurrentTSlice]);
737 mConcatenatedTransform->Concatenate(mSlicingTransform);
740 mImageReslice->SetInput( mImage->GetVTKImages()[mCurrentTSlice] );
741 if (mVF && mVFActor->GetVisibility()) {
742 if (mVF->GetVTKImages().size() > (unsigned int)mCurrentTSlice)
743 mVOIFilter->SetInput(mVF->GetVTKImages()[mCurrentTSlice]);
746 if (mOverlay && mOverlayActor->GetVisibility()) {
747 if (mOverlay->GetVTKImages().size() > (unsigned int)t) {
748 mCurrentOverlayTSlice = t;
749 mOverlayReslice->SetInput( mOverlay->GetVTKImages()[mCurrentOverlayTSlice] );
751 // Update overlay transform
752 mConcatenatedOverlayTransform->Identity();
753 mConcatenatedOverlayTransform->Concatenate(mOverlay->GetTransform()[mCurrentOverlayTSlice]);
754 mConcatenatedOverlayTransform->Concatenate(mSlicingTransform);
757 //update the fusion ; except in case this is a fusionSequence, in which case both 'times' should be independent.
758 if (mFusion && mFusionActor->GetVisibility() && (mFusionSequenceCode<0)) {
759 if (mFusion->GetVTKImages().size() > (unsigned int)t) {
760 mCurrentFusionTSlice = t;
761 mFusionReslice->SetInput( mFusion->GetVTKImages()[mCurrentFusionTSlice]);
763 // Update fusion transform
764 mConcatenatedFusionTransform->Identity();
765 mConcatenatedFusionTransform->Concatenate(mFusion->GetTransform()[mCurrentFusionTSlice]);
766 mConcatenatedFusionTransform->Concatenate(mSlicingTransform);
769 if (mSurfaceCutActors.size() > 0)
770 for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
771 i!=mSurfaceCutActors.end(); i++)
772 (*i)->SetTimeSlice(mCurrentTSlice);
773 UpdateDisplayExtent();
775 //------------------------------------------------------------------------------
778 //------------------------------------------------------------------------------
779 void vvSlicer::SetFusionSequenceTSlice(int t)
781 if (mFusion && mFusionActor->GetVisibility() && (mFusionSequenceCode>=0)) {
782 if (mFusion->GetVTKImages().size() > (unsigned int)t) {
783 mCurrentFusionTSlice = t;
784 mFusionReslice->SetInput( mFusion->GetVTKImages()[mCurrentFusionTSlice] );
785 // Update fusion transform
786 mConcatenatedFusionTransform->Identity();
787 mConcatenatedFusionTransform->Concatenate(mFusion->GetTransform()[mCurrentFusionTSlice]); //not really useful...
788 mConcatenatedFusionTransform->Concatenate(mSlicingTransform);
792 UpdateDisplayExtent();
794 //------------------------------------------------------------------------------
797 //------------------------------------------------------------------------------
798 int vvSlicer::GetTSlice()
800 return mCurrentTSlice;
802 //------------------------------------------------------------------------------
804 //------------------------------------------------------------------------------
805 int vvSlicer::GetMaxCurrentTSlice()
807 int t = mCurrentTSlice;
809 t = std::max(t, mCurrentOverlayTSlice);
810 if(mFusion&& (mFusionSequenceCode<0)) //ignore fusionSequence data: for these, the times are not to be related (this way)
811 t = std::max(t, mCurrentFusionTSlice);
814 //------------------------------------------------------------------------------
816 //------------------------------------------------------------------------------
817 int vvSlicer::GetFusionTSlice()
819 return mCurrentFusionTSlice;
821 //------------------------------------------------------------------------------
823 //------------------------------------------------------------------------------
824 int vvSlicer::GetOverlayTSlice()
826 return mCurrentOverlayTSlice;
828 //------------------------------------------------------------------------------
830 //------------------------------------------------------------------------------
831 void vvSlicer::SetSliceOrientation(int orientation)
833 //if 2D image, force to watch in Axial View
835 this->GetInput()->GetWholeExtent(extent);
836 if (extent[5]-extent[4] <= 2)
837 orientation = vtkImageViewer2::SLICE_ORIENTATION_XY;
839 if (orientation < vtkImageViewer2::SLICE_ORIENTATION_YZ ||
840 orientation > vtkImageViewer2::SLICE_ORIENTATION_XY) {
841 vtkErrorMacro("Error - invalid slice orientation " << orientation);
845 this->SliceOrientation = orientation;
848 AdjustResliceToSliceOrientation(mFusionReslice);
851 AdjustResliceToSliceOrientation(mOverlayReslice);
855 // Go to current cursor position
856 // double* cursorPos = GetCursorPosition();
857 // DDV(cursorPos, 3);
858 // SetCurrentPosition(cursorPos[0],cursorPos[1],cursorPos[2],cursorPos[3]);
860 if (this->Renderer && this->GetInput()) {
861 double s = mCursor[orientation];
862 double sCursor = (s - this->GetInput()->GetOrigin()[orientation])/this->GetInput()->GetSpacing()[orientation];
863 this->Slice = static_cast<int>(sCursor);
866 // int *range = this->GetSliceRange();
868 // this->Slice = static_cast<int>((range[0] + range[1]) * 0.5);
870 this->UpdateOrientation();
871 this->UpdateDisplayExtent();
873 if (this->Renderer && this->GetInput()) {
874 double scale = this->Renderer->GetActiveCamera()->GetParallelScale();
875 this->Renderer->ResetCamera();
876 this->Renderer->GetActiveCamera()->SetParallelScale(scale);
881 //----------------------------------------------------------------------------
883 //------------------------------------------------------------------------------
884 // This function ensures that we sample the slices of a vtkImageReslice filter
885 // in the direction of the slicer (SliceOrientation) similarly as mImageReslice.
886 // In other words, we change the grid of the reslice in the same way as the grid
887 // of the displayed image in the slicing direction.
888 void vvSlicer::AdjustResliceToSliceOrientation(vtkImageReslice *reslice)
890 // Reset autocrop and update output information
891 reslice->SetOutputOriginToDefault();
892 reslice->SetOutputSpacingToDefault();
893 reslice->GetOutput()->UpdateInformation();
895 // Ge new origin / spacing
898 reslice->GetOutput()->GetOrigin(origin);
899 reslice->GetOutput()->GetSpacing(spacing);
901 // Use similar spacing as the image in the direction SliceOrientation
902 spacing[this->SliceOrientation] = mImageReslice->GetOutput()->GetSpacing()[this->SliceOrientation];
904 // Modify origin to be on the image grid in the direction SliceOrientation in 3 steps
905 // Step 1: from world coordinates to image coordinates
906 origin[this->SliceOrientation] -= mImageReslice->GetOutput()->GetOrigin()[this->SliceOrientation];
907 origin[this->SliceOrientation] /= mImageReslice->GetOutput()->GetSpacing()[this->SliceOrientation];
908 // Step 2: round to superior grid positionInc
909 origin[this->SliceOrientation] = itk::Math::Ceil<double>(origin[this->SliceOrientation]);
910 // Step 3: back to world coordinates
911 origin[this->SliceOrientation] *= mImageReslice->GetOutput()->GetSpacing()[this->SliceOrientation];
912 origin[this->SliceOrientation] += mImageReslice->GetOutput()->GetOrigin()[this->SliceOrientation];
914 // Set new spacing and origin
915 reslice->SetOutputOrigin(origin);
916 reslice->SetOutputSpacing(spacing);
917 reslice->UpdateInformation();
918 reslice->GetOutput()->UpdateInformation();
920 //------------------------------------------------------------------------------
922 //----------------------------------------------------------------------------
923 int * vvSlicer::GetExtent(){
925 if (mUseReducedExtent) {
926 w_ext = mReducedExtent;
927 } else w_ext = GetInput()->GetWholeExtent();
930 //----------------------------------------------------------------------------
933 //----------------------------------------------------------------------------
934 int vvSlicer::GetOrientation()
936 return this->SliceOrientation;
938 //----------------------------------------------------------------------------
941 //----------------------------------------------------------------------------
942 void vvSlicer::UpdateDisplayExtent()
944 vtkImageData *input = this->GetInput();
945 if (!input || !this->ImageActor) {
948 input->UpdateInformation();
949 this->SetSlice( this->GetSlice() ); //SR: make sure the update let the slice in extents
951 // Local copy of extent
953 int* ext = GetExtent();
954 copyExtent(ext, w_ext);
956 w_ext[ this->SliceOrientation*2 ] = this->Slice;
957 w_ext[ this->SliceOrientation*2+1 ] = this->Slice;
960 this->ImageActor->SetDisplayExtent(w_ext);
962 // Overlay image actor
963 if (mOverlay && mOverlayActor->GetVisibility()) {
964 AdjustResliceToSliceOrientation(mOverlayReslice);
966 this->ConvertImageToImageDisplayExtent(input, w_ext, mOverlayReslice->GetOutput(), overExtent);
967 ClipDisplayedExtent(overExtent, mOverlayMapper->GetInput()->GetWholeExtent());
968 mOverlayActor->SetDisplayExtent( overExtent );
971 // Fusion image actor
972 if (mFusion && mFusionActor->GetVisibility()) {
973 AdjustResliceToSliceOrientation(mFusionReslice);
975 this->ConvertImageToImageDisplayExtent(input, w_ext, mFusionReslice->GetOutput(), fusExtent);
976 ClipDisplayedExtent(fusExtent, mFusionMapper->GetInput()->GetWholeExtent());
977 mFusionActor->SetDisplayExtent(fusExtent);
980 // Vector field actor
981 double* camera = Renderer->GetActiveCamera()->GetPosition();
982 double* image_bounds = ImageActor->GetBounds();
983 double position[3] = {0, 0, 0};
984 position[this->SliceOrientation] = image_bounds[this->SliceOrientation*2];
986 //print_vector<double, 6>("camera", camera);
987 //print_vector<double, 6>("image_bounds", image_bounds);
988 //print_vector<double, 3>("position", position);
990 // find where to place the VF actor. to deal with
991 // z-buffer issues, the VF is placed right in front of the image,
992 // subject to a small offset. the position actually depends on the
993 // the location of the camera relative to the image.
995 if (camera[this->SliceOrientation] < image_bounds[this->SliceOrientation*2])
998 if (mVF && mVFActor->GetVisibility()) {
1000 mVF->GetVTKImages()[0]->UpdateInformation();
1001 this->ConvertImageToImageDisplayExtent(input, w_ext, mVF->GetVTKImages()[0], vfExtent);
1002 ClipDisplayedExtent(vfExtent, mVOIFilter->GetInput()->GetWholeExtent());
1003 mVOIFilter->SetVOI(vfExtent);
1004 int orientation[3] = {1,1,1};
1005 orientation[this->SliceOrientation] = 0;
1006 mGlyphFilter->SetOrientation(orientation[0], orientation[1], orientation[2]);
1007 mVFMapper->Update();
1009 position[this->SliceOrientation] += offset;
1010 mVFActor->SetPosition(position);
1017 for(unsigned int i=0; i<6; i++)
1018 bounds[i] = ImageActor->GetBounds()[i];
1019 bounds[ this->SliceOrientation*2 ] = ImageActor->GetBounds()[ this->SliceOrientation*2 ]-fabs(this->GetInput()->GetSpacing()[this->SliceOrientation]);
1020 bounds[ this->SliceOrientation*2+1 ] = ImageActor->GetBounds()[ this->SliceOrientation*2+1 ]+fabs(this->GetInput()->GetSpacing()[this->SliceOrientation]);
1021 mClipBox->SetBounds(bounds);
1025 position[this->SliceOrientation] = offset;
1026 mLandActor->SetPosition(position);
1029 // Figure out the correct clipping range
1030 if (this->Renderer) {
1031 if (this->InteractorStyle &&
1032 this->InteractorStyle->GetAutoAdjustCameraClippingRange()) {
1033 this->Renderer->ResetCameraClippingRange();
1035 vtkCamera *cam = this->Renderer->GetActiveCamera();
1038 this->ImageActor->GetBounds(bounds);
1039 double spos = (double)bounds[this->SliceOrientation * 2];
1040 double cpos = (double)cam->GetPosition()[this->SliceOrientation];
1041 double range = fabs(spos - cpos);
1042 double *spacing = input->GetSpacing();
1043 double sumSpacing = spacing[0] + spacing[1] + spacing[2];
1044 cam->SetClippingRange(range - sumSpacing, range + sumSpacing);
1049 //----------------------------------------------------------------------------
1051 //----------------------------------------------------------------------------
1052 void vvSlicer::ConvertImageToImageDisplayExtent(vtkImageData *sourceImage, const int sourceExtent[6],
1053 vtkImageData *targetImage, int targetExtent[6])
1056 for(unsigned int i=0; i<6; i++) {
1057 // From source voxel coordinates to world coordinates
1058 dExtents[i] = sourceImage->GetOrigin()[i/2] + sourceImage->GetSpacing()[i/2] * sourceExtent[i];
1060 // From world coordinates to floating point target voxel coordinates
1061 dExtents[i] = (dExtents[i]- targetImage->GetOrigin()[i/2]) / targetImage->GetSpacing()[i/2];
1064 //targetExtent[i] = itk::Math::Round<double>(dExtents[i]);
1065 targetExtent[i] = itk::Math::Floor<double>(dExtents[i]);
1068 //----------------------------------------------------------------------------
1070 //----------------------------------------------------------------------------
1071 void vvSlicer::ClipDisplayedExtent(int extent[6], int refExtent[6])
1076 //2D overlay on 3D image specific case
1077 if (refExtent[4] == refExtent[5]) {
1079 extent[4] = refExtent[4];
1080 extent[5] = refExtent[5];
1083 for (int i = 0; i < maxBound; i = i+2) {
1084 //if we are totally outside the image
1085 if ( extent[i] > refExtent[i+1] || extent[i+1] < refExtent[i] ) {
1089 //crop to the limit of the image
1090 extent[i] = (extent[i] > refExtent[i]) ? extent[i] : refExtent[i];
1091 extent[i] = (extent[i] < refExtent[i+1]) ? extent[i] : refExtent[i+1];
1092 extent[i+1] = (extent[i+1] > refExtent[i]) ? extent[i+1] : refExtent[i];
1093 extent[i+1] = (extent[i+1] < refExtent[i+1]) ? extent[i+1] : refExtent[i+1];
1096 for (int i = 0; i < maxBound; i = i+2) {
1097 extent[i] = refExtent[i];
1098 extent[i+1] = refExtent[i];
1101 //----------------------------------------------------------------------------
1104 //----------------------------------------------------------------------------
1105 void vvSlicer::UpdateOrientation()
1107 // Set the camera position
1108 vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
1110 switch (this->SliceOrientation) {
1111 case vtkImageViewer2::SLICE_ORIENTATION_XY:
1112 cam->SetFocalPoint(0,0,0);
1113 cam->SetPosition(0,0,-1); // -1 if medical ?
1114 cam->SetViewUp(0,-1,0);
1117 case vtkImageViewer2::SLICE_ORIENTATION_XZ:
1118 cam->SetFocalPoint(0,0,0);
1119 cam->SetPosition(0,-1,0); // 1 if medical ?
1120 cam->SetViewUp(0,0,1);
1123 case vtkImageViewer2::SLICE_ORIENTATION_YZ:
1124 cam->SetFocalPoint(0,0,0);
1125 cam->SetPosition(-1,0,0); // -1 if medical ?
1126 cam->SetViewUp(0,0,1);
1131 //----------------------------------------------------------------------------
1134 //----------------------------------------------------------------------------
1135 void vvSlicer::SetOpacity(double s)
1137 this->GetImageActor()->SetOpacity(s);
1139 //----------------------------------------------------------------------------
1142 //----------------------------------------------------------------------------
1143 void vvSlicer::SetRenderWindow(int orientation, vtkRenderWindow * rw)
1145 this->Superclass::SetRenderWindow(rw);
1146 this->SetupInteractor(rw->GetInteractor());
1147 ca->SetImageActor(this->GetImageActor());
1148 ca->SetWindowLevel(this->GetWindowLevel());
1149 ca->SetText(2, "<slice>");
1150 ca->SetText(3, "<window>\n<level>");
1162 crossCursor->SetModelBounds(bounds);
1163 this->GetRenderer()->AddActor(pdmA);
1164 this->GetRenderer()->AddActor(ca);
1165 this->GetRenderer()->ResetCamera();
1167 //this is just a mapping between the labeling of the orientations presented to the user and
1168 //the one used by vtk
1169 SetSliceOrientation(2-(orientation%3));
1172 //----------------------------------------------------------------------------
1175 //----------------------------------------------------------------------------
1176 void vvSlicer::ResetCamera()
1178 this->GetRenderer()->ResetCamera();
1180 //----------------------------------------------------------------------------
1183 //----------------------------------------------------------------------------
1184 void vvSlicer::SetDisplayMode(bool i)
1186 this->GetRenderer()->SetDraw(i);
1187 if (i) UpdateDisplayExtent();
1189 //----------------------------------------------------------------------------
1192 //----------------------------------------------------------------------------
1193 void vvSlicer::FlipHorizontalView()
1195 vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
1197 double *position = cam->GetPosition();
1198 double factor[3] = {1, 1, 1};
1199 factor[this->SliceOrientation] = -1;
1200 cam->SetPosition(factor[0]*position[0],factor[1]*position[1],factor[2]*position[2]);
1202 /* switch (this->SliceOrientation) {
1203 case vtkImageViewer2::SLICE_ORIENTATION_XY:
1204 cam->SetPosition(position[0],position[1],-position[2]);
1207 case vtkImageViewer2::SLICE_ORIENTATION_XZ:
1208 cam->SetPosition(position[0],-position[1],position[2]);
1211 case vtkImageViewer2::SLICE_ORIENTATION_YZ:
1212 cam->SetPosition(-position[0],position[1],position[2]);
1216 this->Renderer->ResetCameraClippingRange();
1217 this->UpdateDisplayExtent();
1220 //----------------------------------------------------------------------------
1223 //----------------------------------------------------------------------------
1224 void vvSlicer::FlipVerticalView()
1226 vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
1228 FlipHorizontalView();
1229 double *viewup = cam->GetViewUp();
1230 cam->SetViewUp(-viewup[0],-viewup[1],-viewup[2]);
1231 this->UpdateDisplayExtent();
1234 //----------------------------------------------------------------------------
1237 //----------------------------------------------------------------------------
1238 void vvSlicer::SetColorWindow(double window)
1240 vtkLookupTable* LUT = static_cast<vtkLookupTable*>(this->GetWindowLevel()->GetLookupTable());
1242 double level = this->GetWindowLevel()->GetLevel();
1243 LUT->SetTableRange(level-fabs(window)/2,level+fabs(window)/2);
1246 this->vtkImageViewer2::SetColorWindow(window);
1248 //----------------------------------------------------------------------------
1250 //----------------------------------------------------------------------------
1251 void vvSlicer::SetColorLevel(double level)
1253 vtkLookupTable* LUT = static_cast<vtkLookupTable*>(this->GetWindowLevel()->GetLookupTable());
1255 double window = this->GetWindowLevel()->GetWindow();
1256 LUT->SetTableRange(level-fabs(window)/2,level+fabs(window)/2);
1259 this->vtkImageViewer2::SetColorLevel(level);
1261 //----------------------------------------------------------------------------
1263 //----------------------------------------------------------------------------
1264 double vvSlicer::GetOverlayColorWindow()
1267 return mOverlayMapper->GetWindow();
1271 //----------------------------------------------------------------------------
1273 //----------------------------------------------------------------------------
1274 double vvSlicer::GetOverlayColorLevel()
1277 return mOverlayMapper->GetLevel();
1281 //----------------------------------------------------------------------------
1283 //----------------------------------------------------------------------------
1284 void vvSlicer::SetOverlayColorWindow(double window)
1286 mOverlayMapper->SetWindow(window);
1288 //----------------------------------------------------------------------------
1290 //----------------------------------------------------------------------------
1291 void vvSlicer::SetOverlayColorLevel(double level)
1293 mOverlayMapper->SetLevel(level);
1295 //----------------------------------------------------------------------------
1297 //----------------------------------------------------------------------------
1298 // Returns the min an the max value in a 20%x20% region around the mouse pointer
1299 void vvSlicer::GetExtremasAroundMousePointer(double & min, double & max, vtkImageData *image, vtkTransform *transform)
1301 //Get mouse pointer position in view coordinates
1304 for(int i=0; i<3; i++) {
1305 corner1[i] = mCurrent[i];
1306 corner2[i] = mCurrent[i];
1309 this->Renderer->WorldToView(corner1[0], corner1[1], corner1[2]);
1310 this->Renderer->WorldToView(corner2[0], corner2[1], corner2[2]);
1312 // In view coordinates, x is the slicer width and y is the slicer height are the in-plane axis
1314 this->Renderer->GetTiledSize(&w, &h);
1315 corner1[0] -= 0.2*h/(double)w;
1316 corner2[0] += 0.2*h/(double)w;
1319 this->Renderer->ViewToWorld(corner1[0], corner1[1], corner1[2]);
1320 this->Renderer->ViewToWorld(corner2[0], corner2[1], corner2[2]);
1322 //Convert to image pixel coordinates (rounded)
1323 transform->TransformPoint(corner1, corner1);
1324 transform->TransformPoint(corner2, corner2);
1325 int iLocalExtents[6];
1326 for(int i=0; i<3; i++) {
1327 corner1[i] = (corner1[i] - image->GetOrigin()[i])/image->GetSpacing()[i];
1328 corner2[i] = (corner2[i] - image->GetOrigin()[i])/image->GetSpacing()[i];
1330 iLocalExtents[i*2 ] = lrint(corner1[i]);
1331 iLocalExtents[i*2+1] = lrint(corner2[i]);
1333 if(iLocalExtents[i*2 ]>iLocalExtents[i*2+1])
1334 std::swap(iLocalExtents[i*2], iLocalExtents[i*2+1]);
1337 vtkSmartPointer<vtkExtractVOI> voiFilter = vtkSmartPointer<vtkExtractVOI>::New();
1338 voiFilter->SetInput(image);
1339 voiFilter->SetVOI(iLocalExtents);
1340 voiFilter->Update();
1341 if (!voiFilter->GetOutput()->GetNumberOfPoints()) {
1347 vtkSmartPointer<vtkImageAccumulate> accFilter = vtkSmartPointer<vtkImageAccumulate>::New();
1348 accFilter->SetInput(voiFilter->GetOutput());
1349 accFilter->Update();
1351 min = *(accFilter->GetMin());
1352 max = *(accFilter->GetMax());
1354 //----------------------------------------------------------------------------
1356 //----------------------------------------------------------------------------
1357 double vvSlicer::GetScalarComponentAsDouble(vtkImageData *image, double X, double Y, double Z, int &ix, int &iy, int &iz, int component)
1363 if (ix < image->GetWholeExtent()[0] ||
1364 ix > image->GetWholeExtent()[1] ||
1365 iy < image->GetWholeExtent()[2] ||
1366 iy > image->GetWholeExtent()[3] ||
1367 iz < image->GetWholeExtent()[4] ||
1368 iz > image->GetWholeExtent()[5] )
1369 return std::numeric_limits<double>::quiet_NaN();
1371 image->SetUpdateExtent(ix, ix, iy, iy, iz, iz);
1373 return image->GetScalarComponentAsDouble(ix, iy, iz, component);
1375 //----------------------------------------------------------------------------
1377 //----------------------------------------------------------------------------
1378 void vvSlicer::Render()
1380 if (this->mFusion && mFusionActor->GetVisibility() && showFusionLegend) {
1381 legend->SetLookupTable(this->GetFusionMapper()->GetLookupTable());
1382 legend->UseOpacityOn();
1383 legend->SetVisibility(1);
1385 else if (this->GetWindowLevel()->GetLookupTable() && !this->mOverlay) {
1386 legend->SetLookupTable(this->GetWindowLevel()->GetLookupTable());
1387 legend->UseOpacityOff();
1388 legend->SetVisibility(1);
1389 } else legend->SetVisibility(0);
1391 if (ca->GetVisibility()) {
1392 std::stringstream worldPos;
1394 mConcatenatedTransform->TransformPoint(mCurrent, pt);
1395 double X = (pt[0] - mImage->GetVTKImages()[mCurrentTSlice]->GetOrigin()[0])/mImage->GetVTKImages()[mCurrentTSlice]->GetSpacing()[0];
1396 double Y = (pt[1] - mImage->GetVTKImages()[mCurrentTSlice]->GetOrigin()[1])/mImage->GetVTKImages()[mCurrentTSlice]->GetSpacing()[1];
1397 double Z = (pt[2] - mImage->GetVTKImages()[mCurrentTSlice]->GetOrigin()[2])/mImage->GetVTKImages()[mCurrentTSlice]->GetSpacing()[2];
1399 if (X >= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[0]-0.5 &&
1400 X <= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[1]+0.5 &&
1401 Y >= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[2]-0.5 &&
1402 Y <= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[3]+0.5 &&
1403 Z >= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[4]-0.5 &&
1404 Z <= mImage->GetVTKImages()[mCurrentTSlice]->GetWholeExtent()[5]+0.5) {
1408 double value = this->GetScalarComponentAsDouble(mImage->GetVTKImages()[mCurrentTSlice], X, Y, Z, ix, iy, iz);
1410 if(ImageActor->GetVisibility())
1411 worldPos << "data value : " << value << std::endl;
1413 worldPos << "mm : " << lrint(mCurrentBeforeSlicingTransform[0]) << ' '
1414 << lrint(mCurrentBeforeSlicingTransform[1]) << ' '
1415 << lrint(mCurrentBeforeSlicingTransform[2]) << ' '
1418 worldPos << "pixel : " << ix << ' '
1424 ca->SetText(1,worldPos.str().c_str());
1427 if (pdmA->GetVisibility()) {
1428 double x = mCursor[0];
1429 double y = mCursor[1];
1430 double z = mCursor[2];
1431 double xCursor = (x - this->GetInput()->GetOrigin()[0])/this->GetInput()->GetSpacing()[0];
1432 double yCursor = (y - this->GetInput()->GetOrigin()[1])/this->GetInput()->GetSpacing()[1];
1433 double zCursor = (z - this->GetInput()->GetOrigin()[2])/this->GetInput()->GetSpacing()[2];
1435 if (xCursor >= this->GetImageActor()->GetDisplayExtent()[0]-0.5 &&
1436 xCursor < this->GetImageActor()->GetDisplayExtent()[1]+0.5 &&
1437 yCursor >= this->GetImageActor()->GetDisplayExtent()[2]-0.5 &&
1438 yCursor < this->GetImageActor()->GetDisplayExtent()[3]+0.5 &&
1439 zCursor >= this->GetImageActor()->GetDisplayExtent()[4]-0.5 &&
1440 zCursor < this->GetImageActor()->GetDisplayExtent()[5]+0.5 ) {
1441 vtkRenderer * renderer = this->Renderer;
1443 renderer->WorldToView(x,y,z);
1444 renderer->ViewToNormalizedViewport(x,y,z);
1445 renderer->NormalizedViewportToViewport(x,y);
1446 renderer->ViewportToNormalizedDisplay(x,y);
1447 renderer->NormalizedDisplayToDisplay(x,y);
1448 crossCursor->SetFocalPoint(x,y,z);
1450 crossCursor->SetFocalPoint(-1,-1,z);
1454 if (mOverlay && mOverlayActor->GetVisibility()) {
1455 if(mLinkOverlayWindowLevel) {
1456 mOverlayMapper->SetWindow(this->GetColorWindow());
1457 mOverlayMapper->SetLevel(this->GetColorLevel());
1459 mOverlayMapper->GetOutput()->SetUpdateExtent(mOverlayActor->GetDisplayExtent());
1460 mOverlayMapper->GetOutput()->Update();
1461 mOverlayMapper->Update();
1466 this->GetRenderWindow()->Render();
1468 //----------------------------------------------------------------------------
1471 //----------------------------------------------------------------------------
1472 void vvSlicer::UpdateCursorPosition()
1474 pdmA->SetVisibility(true);
1475 mCursor[0] = mCurrent[0];
1476 mCursor[1] = mCurrent[1];
1477 mCursor[2] = mCurrent[2];
1478 mCursor[3] = mCurrentTSlice;
1480 //----------------------------------------------------------------------------
1483 //----------------------------------------------------------------------------
1484 void vvSlicer::UpdateLandmarks()
1486 vtkPolyData *pd = static_cast<vtkPolyData*>(mLandClipper->GetInput());
1487 if (pd->GetPoints()) {
1488 //mLandGlyph->SetRange(0,1);
1489 //mLandGlyph->Modified();
1490 //mLandGlyph->Update();
1492 mClipBox->Modified();
1493 mLandClipper->Update();
1494 mLandMapper->Update();
1495 //Let's add the captions
1496 //First remove all captions:
1497 for(unsigned int i=0;i<mLandLabelActors.size();i++) {
1498 this->Renderer->RemoveActor2D(mLandLabelActors[i]);
1499 //allActors2D->Remove (mLandLabelActors[i]);
1501 mLandLabelActors.clear();
1502 //Next add the captions to the displayed points
1503 for (vtkIdType id=0; id<mLandClipper->GetOutput()->GetNumberOfPoints(); id++) {
1504 double *position = mLandClipper->GetOutput()->GetPoint(id);
1505 vtkStdString label = static_cast<vtkStringArray*>(mLandClipper->GetOutput()->GetPointData()->GetAbstractArray("labels"))->GetValue(id);
1506 vtkSmartPointer<vtkCaptionActor2D> label_actor = vtkSmartPointer<vtkCaptionActor2D>::New();
1507 label_actor->SetCaption(label);
1508 label_actor->SetAttachmentPoint(position);
1509 label_actor->GetCaptionTextProperty()->SetColor(1,0,0);
1510 label_actor->GetCaptionTextProperty()->SetOrientation(33.333333);
1511 label_actor->GetCaptionTextProperty()->SetFontFamilyToTimes();
1512 label_actor->GetCaptionTextProperty()->SetBold(0);
1513 label_actor->GetCaptionTextProperty()->SetFontSize(6);
1514 label_actor->BorderOff();
1515 label_actor->LeaderOff();
1516 label_actor->ThreeDimensionalLeaderOff();
1517 mLandLabelActors.push_back(label_actor);
1518 this->Renderer->AddActor2D(mLandLabelActors[id]);
1523 //----------------------------------------------------------------------------
1526 //----------------------------------------------------------------------------
1527 void vvSlicer::SetSlice(int slice)
1529 int *range = this->GetSliceRange();
1531 if (slice < range[0]) {
1533 } else if (slice > range[1]) {
1538 if (this->Slice == slice) {
1542 this->Slice = slice;
1545 this->UpdateDisplayExtent();
1547 // Seems to work without this line
1550 //----------------------------------------------------------------------------
1552 //----------------------------------------------------------------------------
1553 int vvSlicer::GetTMax() {
1554 int tmax = (int)mImage->GetVTKImages().size() - 1;
1556 tmax = std::max(tmax, (int)mOverlay->GetVTKImages().size()-1);
1559 //----------------------------------------------------------------------------
1561 //----------------------------------------------------------------------------
1562 void vvSlicer::SetContourSlice()
1564 if (mSurfaceCutActors.size() > 0)
1565 for (std::vector<vvMeshActor*>::iterator i=mSurfaceCutActors.begin();
1566 i!=mSurfaceCutActors.end(); i++) {
1568 (*i)->SetSlicingOrientation(this->SliceOrientation);
1569 (*i)->SetCutSlice((this->Slice)*this->GetImage()->GetSpacing()[this->SliceOrientation]+
1570 this->GetImage()->GetOrigin()[this->SliceOrientation]);
1573 //----------------------------------------------------------------------------
1576 //----------------------------------------------------------------------------
1577 void vvSlicer::ForceUpdateDisplayExtent()
1579 this->UpdateDisplayExtent();
1581 //----------------------------------------------------------------------------
1584 //----------------------------------------------------------------------------
1585 int* vvSlicer::GetDisplayExtent()
1587 return this->GetImageActor()->GetDisplayExtent();
1589 //----------------------------------------------------------------------------
1592 //----------------------------------------------------------------------------
1593 void vvSlicer::PrintSelf(ostream& os, vtkIndent indent)
1595 this->Superclass::PrintSelf(os, indent);
1597 //----------------------------------------------------------------------------
1599 //----------------------------------------------------------------------------
1600 void vvSlicer::SetVFColor(double r, double g, double b)
1602 double mVFColorHSV[3];
1607 vtkMath::RGBToHSV(mVFColor, mVFColorHSV);
1608 mVFColorLUT->SetHueRange(mVFColorHSV[0], mVFColorHSV[0]);
1609 mVFColorLUT->SetSaturationRange(mVFColorHSV[1],mVFColorHSV[1]);
1610 mVFColorLUT->SetValueRange(mVFColorHSV[2], mVFColorHSV[2]);