diff --git a/Modules/MitkExt/Algorithms/mitkBoundingObjectToSegmentationFilter.cpp b/Modules/MitkExt/Algorithms/mitkBoundingObjectToSegmentationFilter.cpp index aa342f7cad..3c7b5dbe90 100644 --- a/Modules/MitkExt/Algorithms/mitkBoundingObjectToSegmentationFilter.cpp +++ b/Modules/MitkExt/Algorithms/mitkBoundingObjectToSegmentationFilter.cpp @@ -1,120 +1,120 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision: 27918 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkBoundingObjectToSegmentationFilter.h" #include "mitkImageCast.h" mitk::BoundingObjectToSegmentationFilter::BoundingObjectToSegmentationFilter() { this->SetNumberOfRequiredInputs(1); } mitk::BoundingObjectToSegmentationFilter::~BoundingObjectToSegmentationFilter() { } void mitk::BoundingObjectToSegmentationFilter::SetBoundingObject(mitk::BoundingObject::Pointer boundingObject) { mitk::BoundingObjectGroup* testgroup = dynamic_cast (boundingObject.GetPointer()); if (testgroup) m_boundingObjectGroup = testgroup; else { m_boundingObjectGroup = mitk::BoundingObjectGroup::New(); m_boundingObjectGroup->AddBoundingObject(boundingObject); } } void mitk::BoundingObjectToSegmentationFilter::GenerateData() { typedef itk::Image itkImageType; mitk::Image::Pointer outputImage = this->GetOutput(); mitk::Image::ConstPointer inputImage = this->GetInput(); outputImage->Initialize(inputImage); itkImageType::Pointer itkImage; CastToItkImage(outputImage, itkImage); itkImage->FillBuffer(0); for (unsigned int i=0; iGetCount(); i++) { //create region for boundingobject mitk::BoundingObject::Pointer boundingObject = m_boundingObjectGroup->GetBoundingObjects().at(i); mitk::Geometry3D::Pointer boGeometry = boundingObject->GetGeometry(); mitk::Geometry3D::Pointer inputImageGeometry = inputImage->GetSlicedGeometry(); mitk::BoundingBox::Pointer boToIm = boGeometry->CalculateBoundingBoxRelativeToTransform(inputImageGeometry->GetIndexToWorldTransform()); mitk::BoundingBox::ConstPointer imgBB = inputImageGeometry->GetBoundingBox(); mitk::BoundingBox::PointType minImg = imgBB->GetMinimum(); mitk::BoundingBox::PointType maxImg = imgBB->GetMaximum(); itkImageType::IndexType boIndex; itkImageType::SizeType boSize; mitk::BoundingBox::PointType min = boToIm->GetMinimum(); mitk::BoundingBox::PointType max = boToIm->GetMaximum(); //check if boundingbox is inside imageregion for (int i =0; i<3; i++) { if (min [i] < minImg[i]) min[i] = minImg[i]; if (max [i] < minImg[i]) max[i] = minImg[i]; if (max[i] > maxImg[i]) max[i] = maxImg[i]; if (min [i] > maxImg[i]) min[i] = maxImg[i]-1; } // add 0.5 (boGeometry is no image geometry) boIndex[0] = (mitk::SlicedData::IndexType::IndexValueType)(min[0] + 0.5); boIndex[1] = (mitk::SlicedData::IndexType::IndexValueType)(min[1] + 0.5); boIndex[2] = (mitk::SlicedData::IndexType::IndexValueType)(min[2] + 0.5); // add 1 because we need 0.5 for each index - boSize[0] = (mitk::SlicedData::IndexType::IndexValueType) ((max[0]-min[0]) + 1); - boSize[1] = (mitk::SlicedData::IndexType::IndexValueType) ((max[1]-min[1]) + 1); - boSize[2] = (mitk::SlicedData::IndexType::IndexValueType) ((max[2]-min[2]) + 1); + boSize[0] = (mitk::SlicedData::IndexType::IndexValueType) (max[0]-min[0]); + boSize[1] = (mitk::SlicedData::IndexType::IndexValueType) (max[1]-min[1]); + boSize[2] = (mitk::SlicedData::IndexType::IndexValueType) (max[2]-min[2]); itkImageType::RegionType region(boIndex, boSize); //create region iterator itk::ImageRegionIteratorWithIndex itBoundingObject = itk::ImageRegionIteratorWithIndex(itkImage, region ); itBoundingObject.GoToBegin(); while(!itBoundingObject.IsAtEnd()) { itkImageType::IndexType index = itBoundingObject.GetIndex(); mitk::Point3D p; p[0] = index[0]; p[1] = index[1]; p[2] = index[2]; inputImageGeometry->IndexToWorld(p,p); if (boundingObject->IsInside(p) && boundingObject->GetPositive()) itBoundingObject.Set(1); else if (boundingObject->IsInside(p) && !boundingObject->GetPositive()) itBoundingObject.Set(0); ++itBoundingObject; } } CastToMitkImage(itkImage, outputImage); } \ No newline at end of file