From: Romulo Pinho Date: Wed, 8 Jun 2011 16:25:37 +0000 (+0200) Subject: solved bug 375 (Binarize after crop) X-Git-Tag: v1.3.0~323 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=842bd9736b8c4a9e249dd4f026794d473ba095f7;p=clitk.git solved bug 375 (Binarize after crop) - image index is now forced to zero after passing through cropping filter + apparently solved other crop-related bugs... (please test!) - also did some refactoring and clean-up --- diff --git a/tools/clitkCropImage.cxx b/tools/clitkCropImage.cxx index 8e55713..3c6725c 100644 --- a/tools/clitkCropImage.cxx +++ b/tools/clitkCropImage.cxx @@ -34,7 +34,7 @@ int main(int argc, char * argv[]) filter->SetArgsInfo(args_info); - try { + try { filter->Update(); } catch(std::runtime_error e) { std::cout << e.what() << std::endl; diff --git a/tools/clitkCropImage.ggo b/tools/clitkCropImage.ggo index e8650de..a674f8b 100644 --- a/tools/clitkCropImage.ggo +++ b/tools/clitkCropImage.ggo @@ -15,7 +15,7 @@ option "input" i "Input image filename" string yes option "output" o "Output image filename" string yes section "Used determined crop" -option "boundingBox" b "Bounding box of the crop region (in 2D: =x1,y2, x2,y2)" int no multiple +option "boundingBox" b "Bounding box of the crop region (in 3D: =x1,x2,y1,y2,z1,z2)" int no multiple option "lower" l "Size of the lower crop region (multiple values)" int no multiple option "upper" u "Size of the upper crop region (multiple values)" int no multiple option "origin" - "Set new origin to zero" flag off diff --git a/tools/clitkCropImageGenericFilter.cxx b/tools/clitkCropImageGenericFilter.cxx index b062976..5c78d4e 100644 --- a/tools/clitkCropImageGenericFilter.cxx +++ b/tools/clitkCropImageGenericFilter.cxx @@ -79,6 +79,7 @@ namespace clitk { // Reading input typename ImageType::Pointer input = this->template GetInput(0); + typename ImageType::RegionType input_region = input->GetLargestPossibleRegion(); // Check options if (mArgsInfo.BG_given && mArgsInfo.like_given) @@ -123,10 +124,11 @@ namespace clitk // ------------------------------------------------ typename ImageType::SizeType lSize; typename ImageType::SizeType uSize; + if (mArgsInfo.verbose_flag) std::cout << "input region " << input_region << std::endl; if (mArgsInfo.boundingBox_given) { for(unsigned int i=0; iGetLargestPossibleRegion().GetSize()[i]-mArgsInfo.boundingBox_arg[2*i+1]-1; + uSize[i] = input_region.GetSize()[i]-mArgsInfo.boundingBox_arg[2*i+1]-1; } } else { @@ -141,6 +143,11 @@ namespace clitk } else uSize.Fill(0); } + + if (mArgsInfo.verbose_flag) { + std::cout << "lower " << lSize << " upper " << uSize << std::endl; + } + typedef itk::CropImageFilter CropImageFilterType; typename CropImageFilterType::Pointer filter=CropImageFilterType::New(); filter->SetInput(input); @@ -157,6 +164,14 @@ namespace clitk origin.Fill(itk::NumericTraits::Zero); output->SetOrigin(origin); } + + // force index to zero + typename ImageType::RegionType region; + region = output->GetLargestPossibleRegion(); + typename ImageType::IndexType index; + index.Fill(itk::NumericTraits::Zero); + region.SetIndex(index); + output->SetRegions(region); // Write/Save results this->template SetNextOutput(output); diff --git a/vv/vvImageContour.cxx b/vv/vvImageContour.cxx index 2770396..9412903 100644 --- a/vv/vvImageContour.cxx +++ b/vv/vvImageContour.cxx @@ -267,6 +267,7 @@ void vvImageContour::CreateNewActor(int numImage) { clipper->SetInput(mHiddenImage->GetVTKImages()[0]); else clipper->SetInput(mSlicer->GetImage()->GetVTKImages()[numImage]); + squares->SetInput(clipper->GetOutput()); squaresMapper->SetInput(squares->GetOutput()); squaresMapper->ScalarVisibilityOff(); @@ -333,8 +334,6 @@ void vvImageContour::UpdateActor(vtkActor * actor, clipper->SetOutputWholeExtent(extent2[0],extent2[1],extent2[2], extent2[3],extent2[4],extent2[5]); - //std::cout << mTSlice << " " << mSlice << " " << extent2[0] << " " << extent2[1] << " " << extent2[2] << " " << extent2[3] << " " << extent2[4] << " " << extent2[5] << std::endl; - if (mHiddenImageIsUsed) delete extent2; // Move the actor to be visible @@ -342,47 +341,7 @@ void vvImageContour::UpdateActor(vtkActor * actor, position[orientation] = -1; actor->SetPosition(position); -// switch (orientation) { -// case 0: -// actor->SetPosition(-1,0,0); -// /* -// // DD(mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[0]); -// if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[0] > slice) { -// actor->SetPosition(1,0,0); -// } else { -// actor->SetPosition(-1,0,0); -// }*/ -// break; -// case 1: -// actor->SetPosition(0,-1,0); -// /* -// // DD(mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[1]); -// if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[1] > slice) { -// actor->SetPosition(0,1,0); -// } else { -// actor->SetPosition(0,-1,0); -// } -// */ -// break; -// case 2: -// actor->SetPosition(0,0,-1); -// /* -// DD(mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[2]); -// if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[2] > slice) { -// DD("1"); -// actor->SetPosition(0,0,1); -// } else { -// DD("-1"); -// actor->SetPosition(0,0,-1); -// } -// */ -// break; -// } - mapper->Update(); - - - } //------------------------------------------------------------------------------ diff --git a/vv/vvToolCropImage.cxx b/vv/vvToolCropImage.cxx index 9d6d891..c3b5570 100644 --- a/vv/vvToolCropImage.cxx +++ b/vv/vvToolCropImage.cxx @@ -274,15 +274,19 @@ void vvToolCropImage::apply() catch(clitk::ExceptionObject & e) { DD(e.what()); QApplication::restoreOverrideCursor(); + delete [] mArgsInfo.boundingBox_arg; close(); } std::ostringstream croppedImageName; croppedImageName << "Cropped_" << mCurrentSlicerManager->GetSlicer(0)->GetFileName() << ".mhd"; // Retrieve result and display it vvImage::Pointer output = filter->GetOutputVVImage(); + AddImage(output,croppedImageName.str()); + // End QApplication::restoreOverrideCursor(); + delete [] mArgsInfo.boundingBox_arg; close(); } //------------------------------------------------------------------------------