]> Creatis software - clitk.git/commitdiff
solved bug 375 (Binarize after crop)
authorRomulo Pinho <pinho@lyon.fnclcc.fr>
Wed, 8 Jun 2011 16:25:37 +0000 (18:25 +0200)
committerRomulo Pinho <pinho@lyon.fnclcc.fr>
Wed, 8 Jun 2011 16:25:37 +0000 (18:25 +0200)
- 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

tools/clitkCropImage.cxx
tools/clitkCropImage.ggo
tools/clitkCropImageGenericFilter.cxx
vv/vvImageContour.cxx
vv/vvToolCropImage.cxx

index 8e557139501b3ba72393231faecfd1221a1881ff..3c6725cdccd056c1c501f373e1d2d84716db0634 100644 (file)
@@ -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;
index e8650de42447336cd1b09755ac4cabdc99313f33..a674f8bbef5b5450493a3c0eae14ccde4acb0579 100644 (file)
@@ -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  
index b062976b678b4dac3abe72804dd6dbda572c81aa..5c78d4ea436355e1d8e459ba8a69e9eac3f5d36d 100644 (file)
@@ -79,6 +79,7 @@ namespace clitk
   { 
     // Reading input
     typename ImageType::Pointer input = this->template GetInput<ImageType>(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; i<ImageType::ImageDimension; i++) {
             lSize[i] = mArgsInfo.boundingBox_arg[2*i];
-            uSize[i] = input->GetLargestPossibleRegion().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<ImageType, ImageType> CropImageFilterType;
         typename CropImageFilterType::Pointer filter=CropImageFilterType::New();
         filter->SetInput(input);
@@ -157,6 +164,14 @@ namespace clitk
       origin.Fill(itk::NumericTraits<double>::Zero);
       output->SetOrigin(origin);
     }
+    
+    // force index to zero
+    typename ImageType::RegionType region;
+    region = output->GetLargestPossibleRegion();
+    typename ImageType::IndexType index;
+    index.Fill(itk::NumericTraits<double>::Zero);
+    region.SetIndex(index);
+    output->SetRegions(region);
 
     // Write/Save results
     this->template SetNextOutput<ImageType>(output); 
index 27703963c345be05e09715957a59423295319d38..94129031759648c7808a40f6216b12b95ef74d1d 100644 (file)
@@ -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();
-  
-  
 }
 //------------------------------------------------------------------------------
 
index 9d6d891bbadd2bafe01892278c72ffc2f1d09738..c3b55709722033a6445b9b3d0fb0c239ec1d5628 100644 (file)
@@ -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();
 }
 //------------------------------------------------------------------------------