X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=vv%2FvvSlicer.cxx;h=dc7bea75eab2d265885a1f6fd9330562cb353408;hb=40faa70ff55ab09a7d95023d44672a1c8366ee87;hp=575fdacfdf38403002f01b2e1698988a3cfbc122;hpb=05413db25dc1daf6d79b45caa2a75668bf5e13e7;p=clitk.git diff --git a/vv/vvSlicer.cxx b/vv/vvSlicer.cxx index 575fdac..dc7bea7 100644 --- a/vv/vvSlicer.cxx +++ b/vv/vvSlicer.cxx @@ -95,7 +95,7 @@ vvSlicer::vvSlicer() this->UnInstallPipeline(); mImage = NULL; mReducedExtent = new int[6]; - mRegisterExtent = new int[6]; + mRegisterExtent = NULL; mCurrentTSlice = 0; mCurrentFusionTSlice = 0; mCurrentOverlayTSlice = 0; @@ -312,7 +312,6 @@ vvSlicer::~vvSlicer() i!=mSurfaceCutActors.end(); i++) delete (*i); delete [] mReducedExtent; - delete [] mRegisterExtent; } //------------------------------------------------------------------------------ @@ -381,7 +380,6 @@ void vvSlicer::SetImage(vvImage::Pointer image) // Make sure that the required part image has been computed extent[SliceOrientation*2] = Slice; extent[SliceOrientation*2+1] = Slice; - #if VTK_MAJOR_VERSION <= 5 mImageReslice->GetOutput()->SetUpdateExtent(extent); mImageReslice->GetOutput()->Update(); @@ -1073,21 +1071,28 @@ int vvSlicer::GetOrientation() void vvSlicer::UpdateDisplayExtent() { vtkImageData *input = this->GetInput(); - if (!input || !this->ImageActor) { return; } - + #if VTK_MAJOR_VERSION <= 5 input->UpdateInformation(); +#else + mRegisterExtent = mImageReslice->GetOutputInformation(0)->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT()); #endif this->SetSlice( this->GetSlice() ); //SR: make sure the update let the slice in extents // Local copy of extent int w_ext[6]; +#if VTK_MAJOR_VERSION <= 5 int* ext = GetExtent(); +#else + int* ext = mImageReslice->GetOutputInformation(0)->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT()); +#endif copyExtent(ext, w_ext); - + if (mUseReducedExtent) { + copyExtent(mReducedExtent, w_ext); + } // Set slice value w_ext[ this->SliceOrientation*2 ] = this->Slice; @@ -1096,31 +1101,6 @@ void vvSlicer::UpdateDisplayExtent() // Image actor this->ImageActor->SetVisibility(mImageVisibility); this->ImageActor->SetDisplayExtent(w_ext); -#if VTK_MAJOR_VERSION >= 6 - vtkSmartPointer mapperOpenGL= vtkSmartPointer::New(); - - try { - mapperOpenGL = dynamic_cast(GetImageActor()->GetMapper()); - } catch (const std::bad_cast& e) { - std::cerr << e.what() << std::endl; - std::cerr << "Conversion error" << std::endl; - return; - } - if (mFirstSetSliceOrientation) { - copyExtent(ext, mRegisterExtent); - } else { - int w_croppingRegion[6]; - if (mUseReducedExtent) { - copyExtent(mReducedExtent, w_croppingRegion); - } else { - copyExtent(mRegisterExtent, w_croppingRegion); - } - this->ImageActor->SetDisplayExtent(w_ext); - w_croppingRegion[ this->SliceOrientation*2 ] = this->Slice; - w_croppingRegion[ this->SliceOrientation*2+1 ] = this->Slice; - mapperOpenGL->SetCroppingRegion(w_croppingRegion); - } -#endif #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10) // Fix for bug #1882 @@ -1131,11 +1111,12 @@ void vvSlicer::UpdateDisplayExtent() if (mOverlay && mOverlayVisibility) { AdjustResliceToSliceOrientation(mOverlayReslice); int overExtent[6]; - this->ConvertImageToImageDisplayExtent(input, w_ext, mOverlayReslice->GetOutput(), overExtent); #if VTK_MAJOR_VERSION <= 5 + this->ConvertImageToImageDisplayExtent(input, w_ext, mOverlayReslice->GetOutput(), overExtent); bool out = ClipDisplayedExtent(overExtent, mOverlayMapper->GetInput()->GetWholeExtent()); #else - bool out = ClipDisplayedExtent(overExtent, mImage->GetVTKImages()[mCurrentTSlice]->GetInformation()->Get(vtkDataObject::DATA_EXTENT())); + this->ConvertImageToImageDisplayExtent(mImageReslice->GetOutputInformation(0), w_ext, mOverlayReslice->GetOutput(), overExtent); + bool out = ClipDisplayedExtent(overExtent, mOverlayMapper->GetInputInformation()->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT())); #endif mOverlayActor->SetVisibility(!out); mOverlayActor->SetDisplayExtent( overExtent ); @@ -1151,11 +1132,12 @@ void vvSlicer::UpdateDisplayExtent() if (mFusion && mFusionVisibility) { AdjustResliceToSliceOrientation(mFusionReslice); int fusExtent[6]; - this->ConvertImageToImageDisplayExtent(input, w_ext, mFusionReslice->GetOutput(), fusExtent); #if VTK_MAJOR_VERSION <= 5 + this->ConvertImageToImageDisplayExtent(input, w_ext, mFusionReslice->GetOutput(), fusExtent); bool out = ClipDisplayedExtent(fusExtent, mFusionMapper->GetInput()->GetWholeExtent()); #else - bool out = ClipDisplayedExtent(fusExtent, mImage->GetVTKImages()[mCurrentTSlice]->GetInformation()->Get(vtkDataObject::DATA_EXTENT())); + this->ConvertImageToImageDisplayExtent(mImageReslice->GetOutputInformation(0), w_ext, mFusionReslice->GetOutput(), fusExtent); + bool out = ClipDisplayedExtent(fusExtent, mFusionMapper->GetInputInformation()->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT())); #endif mFusionActor->SetVisibility(!out); mFusionActor->SetDisplayExtent( fusExtent ); @@ -1188,14 +1170,12 @@ void vvSlicer::UpdateDisplayExtent() int vfExtent[6]; #if VTK_MAJOR_VERSION <= 5 mVF->GetVTKImages()[0]->UpdateInformation(); -#else - //this->UpdateInformation(); -#endif this->ConvertImageToImageDisplayExtent(input, w_ext, mVF->GetVTKImages()[0], vfExtent); -#if VTK_MAJOR_VERSION <= 5 bool out = ClipDisplayedExtent(vfExtent, mVOIFilter->GetInput()->GetWholeExtent()); #else - bool out = ClipDisplayedExtent(vfExtent, mImage->GetVTKImages()[mCurrentTSlice]->GetInformation()->Get(vtkDataObject::DATA_EXTENT())); + //this->UpdateInformation(); + this->ConvertImageToImageDisplayExtent(mImageReslice->GetOutputInformation(0), w_ext, mVF->GetVTKImages()[0], vfExtent); + bool out = ClipDisplayedExtent(vfExtent, mVOIFilter->GetInputInformation()->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT())); #endif mVFActor->SetVisibility(!out); mVOIFilter->SetVOI(vfExtent); @@ -1250,9 +1230,35 @@ void vvSlicer::UpdateDisplayExtent() //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- -void vvSlicer::ConvertImageToImageDisplayExtent(vtkImageData *sourceImage, const int sourceExtent[6], +void vvSlicer::ConvertImageToImageDisplayExtent(vtkInformation *sourceImage, const int sourceExtent[6], vtkImageData *targetImage, int targetExtent[6]) { + double dExtents[6]; + double *origin, *spacing; + origin = sourceImage->Get(vtkDataObject::ORIGIN()); + spacing = sourceImage->Get(vtkDataObject::SPACING()); + for(unsigned int i=0; i<6; i++) { + // From source voxel coordinates to world coordinates + dExtents[i] = origin[i/2] + spacing[i/2] * sourceExtent[i]; + + // From world coordinates to floating point target voxel coordinates + dExtents[i] = (dExtents[i]- targetImage->GetOrigin()[i/2]) / targetImage->GetSpacing()[i/2]; + + // Round to current slice or larger extent + if(i/2==this->GetOrientation()) + targetExtent[i] = itk::Math::Round(dExtents[i]); + else if(i%2==1) + targetExtent[i] = itk::Math::Ceil(dExtents[i]); + else + targetExtent[i] = itk::Math::Floor(dExtents[i]); + } +} +//---------------------------------------------------------------------------- + +//---------------------------------------------------------------------------- +void vvSlicer::ConvertImageToImageDisplayExtent(vtkImageData *sourceImage, const int sourceExtent[6], + vtkImageData *targetImage, int targetExtent[6]) +{ double dExtents[6]; for(unsigned int i=0; i<6; i++) { // From source voxel coordinates to world coordinates @@ -1596,7 +1602,6 @@ double vvSlicer::GetScalarComponentAsDouble(vtkImageData *image, double X, doubl //---------------------------------------------------------------------------- void vvSlicer::Render() { - if (this->mFusion && mFusionActor->GetVisibility() && showFusionLegend) { legend->SetLookupTable(this->GetFusionMapper()->GetLookupTable()); legend->UseOpacityOn(); @@ -1609,6 +1614,7 @@ void vvSlicer::Render() } else legend->SetVisibility(0); if (ca->GetVisibility()) { + std::stringstream worldPos(" "); double pt[3]; mConcatenatedTransform->TransformPoint(mCurrent, pt); @@ -1648,7 +1654,7 @@ void vvSlicer::Render() Y <= mImage->GetVTKImages()[mCurrentTSlice]->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[3]+0.5 && Z >= mImage->GetVTKImages()[mCurrentTSlice]->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[4]-0.5 && Z <= mImage->GetVTKImages()[mCurrentTSlice]->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[5]+0.5) { - + int ix, iy, iz; double value = this->GetScalarComponentAsDouble(mImage->GetVTKImages()[mCurrentTSlice], X, Y, Z, ix, iy, iz); @@ -1710,6 +1716,7 @@ void vvSlicer::Render() std::cerr << "Conversion error" << std::endl; return; } + if (xCursor >= mapperOpenGL->GetCroppingRegion()[0]-0.5 && xCursor < mapperOpenGL->GetCroppingRegion()[1]+0.5 && yCursor >= mapperOpenGL->GetCroppingRegion()[2]-0.5 &&