Filter to cut an image with a plane. More...
#include <mitkPlaneCutFilter.h>
Public Types | |
enum | FillMode { FILL, FILL_INVERSE } |
typedef PlaneCutFilter | Self |
typedef ImageToImageFilter | Superclass |
typedef itk::SmartPointer< Self > | Pointer |
typedef itk::SmartPointer < const Self > | ConstPointer |
Public Member Functions | |
virtual const char * | GetClassName () const |
virtual void | SetBackgroundLevel (float _arg) |
Set background grey level. | |
virtual float | GetBackgroundLevel () |
virtual void | SetFillMode (FillMode _arg) |
virtual FillMode | GetFillMode () |
virtual void | SetPlane (const PlaneGeometry *_arg) |
virtual const PlaneGeometry * | GetPlane () |
Static Public Member Functions | |
static Pointer | New () |
Protected Member Functions | |
PlaneCutFilter () | |
~PlaneCutFilter () | |
virtual void | GenerateData () |
A version of GenerateData() specific for image processing filters. | |
template<typename TPixel , unsigned int VImageDimension> | |
void | _computeIntersection (itk::Image< TPixel, VImageDimension > *itkImage, const PlaneGeometry *plane, const Geometry3D *geometry) |
Protected Attributes | |
float | m_BackgroundLevel |
PlaneGeometry::ConstPointer | m_Plane |
FillMode | m_FillMode |
Filter to cut an image with a plane.
Everything in the direction of the normal of the planes (if fill mode is set to "FILL") will be set to a specified value.
Definition at line 40 of file mitkPlaneCutFilter.h.
typedef itk::SmartPointer<const Self> mitk::PlaneCutFilter::ConstPointer |
Definition at line 43 of file mitkPlaneCutFilter.h.
typedef itk::SmartPointer<Self> mitk::PlaneCutFilter::Pointer |
Definition at line 43 of file mitkPlaneCutFilter.h.
Definition at line 43 of file mitkPlaneCutFilter.h.
Definition at line 43 of file mitkPlaneCutFilter.h.
Definition at line 48 of file mitkPlaneCutFilter.h.
{FILL, FILL_INVERSE} FillMode;
mitk::PlaneCutFilter::PlaneCutFilter | ( | ) | [protected] |
Definition at line 49 of file mitkPlaneCutFilter.cpp.
: m_BackgroundLevel(0.0f), m_Plane(0), m_FillMode(FILL) { }
mitk::PlaneCutFilter::~PlaneCutFilter | ( | ) | [protected] |
Definition at line 54 of file mitkPlaneCutFilter.cpp.
{ }
void mitk::PlaneCutFilter::_computeIntersection | ( | itk::Image< TPixel, VImageDimension > * | itkImage, |
const PlaneGeometry * | plane, | ||
const Geometry3D * | geometry | ||
) | [protected] |
Definition at line 59 of file mitkPlaneCutFilter.cpp.
References mitk::Geometry3D::IndexToWorld(), mitk::PlaneGeometry::IntersectionPoint(), mitk::PlaneGeometry::IsAbove(), roundf, mitk::Line< TCoordRep, NPointDimension >::SetPoints(), and mitk::Geometry3D::WorldToIndex().
Referenced by GenerateData().
{ typedef itk::Image<TPixel, VImageDimension> ImageType; const typename ImageType::RegionType &image_region = image->GetLargestPossibleRegion(); const typename ImageType::SizeValueType max_x = image_region.GetSize(0ul), max_y = image_region.GetSize(1ul), max_z = image_region.GetSize(2ul), img_size = max_x * max_y; TPixel *data = image->GetBufferPointer(); Point3D p1, p2; //TODO: Better solution required! TPixel casted_background_level = static_cast<TPixel>(this->m_BackgroundLevel); p1[0] = 0; p2[0] = max_x - 1ul; if (FILL == this->m_FillMode) { for (unsigned long z = 0ul; z < max_z; ++z) { p1[2] = z; p2[2] = z; for (unsigned long y = 0ul; y < max_y; ++y) { p1[1] = y; p2[1] = y; Point3D p1_t, p2_t; geometry->IndexToWorld(p1, p1_t); geometry->IndexToWorld(p2, p2_t); if (plane->IsAbove(p1_t)) { if (plane->IsAbove(p2_t)) { if (0.0f == this->m_BackgroundLevel) { memset(&data[(y * max_x) + (z * img_size)], 0, max_x * sizeof(TPixel)); } else { TPixel *subdata = &data[(y * max_x) + (z * img_size)]; for (unsigned long x = 0; x < max_x; ++x) { subdata[x] = casted_background_level; } } } else { Point3D intersection; Line3D line; line.SetPoints(p1_t, p2_t); plane->IntersectionPoint(line, intersection); geometry->WorldToIndex(intersection, intersection); if (0.0f == this->m_BackgroundLevel) { memset(&data[(y * max_x) + (z * img_size)], 0, (static_cast<unsigned long>(roundf(intersection[0])) + 1u) * sizeof(TPixel)); } else { TPixel *subdata = &data[(y * max_x) + (z * img_size)]; const unsigned long x_size = static_cast<unsigned long>(roundf(intersection[0])) + 1u; for (unsigned long x = 0; x < x_size; ++x) { subdata[x] = casted_background_level; } } } } else if (plane->IsAbove(p2_t)) { Point3D intersection; Line3D line; line.SetPoints(p1_t, p2_t); plane->IntersectionPoint(line, intersection); geometry->WorldToIndex(intersection, intersection); if (0.0f == this->m_BackgroundLevel) { unsigned long x = static_cast<unsigned long>(roundf(intersection[0])); memset(&data[x + (y * max_x) + (z * img_size)], 0, (max_x - x) * sizeof(TPixel)); } else { unsigned long x = static_cast<unsigned long>(roundf(intersection[0])); TPixel *subdata = &data[x + (y * max_x) + (z * img_size)]; const unsigned long x_size = max_x - x; for (x = 0; x < x_size; ++x) { subdata[x] = casted_background_level; } } } } } } else { for (unsigned long z = 0ul; z < max_z; ++z) { p1[2] = z; p2[2] = z; for (unsigned long y = 0ul; y < max_y; ++y) { p1[1] = y; p2[1] = y; Point3D p1_t, p2_t; geometry->IndexToWorld(p1, p1_t); geometry->IndexToWorld(p2, p2_t); if (!plane->IsAbove(p1_t)) { if (!plane->IsAbove(p2_t)) { if (0.0f == this->m_BackgroundLevel) { memset(&data[(y * max_x) + (z * img_size)], 0, max_x * sizeof(TPixel)); } else { TPixel *subdata = &data[(y * max_x) + (z * img_size)]; for (unsigned long x = 0; x < max_x; ++x) { subdata[x] = casted_background_level; } } } else { Point3D intersection; Line3D line; line.SetPoints(p1_t, p2_t); plane->IntersectionPoint(line, intersection); geometry->WorldToIndex(intersection, intersection); if (0.0f == this->m_BackgroundLevel) { memset(&data[(y * max_x) + (z * img_size)], 0, (static_cast<unsigned long>(roundf(intersection[0])) + 1u) * sizeof(TPixel)); } else { TPixel *subdata = &data[(y * max_x) + (z * img_size)]; const unsigned long x_size = static_cast<unsigned long>(roundf(intersection[0])) + 1u; for (unsigned long x = 0; x < x_size; ++x) { subdata[x] = casted_background_level; } } } } else if (!plane->IsAbove(p2_t)) { Point3D intersection; Line3D line; line.SetPoints(p1_t, p2_t); plane->IntersectionPoint(line, intersection); geometry->WorldToIndex(intersection, intersection); if (0.0f == this->m_BackgroundLevel) { unsigned long x = static_cast<unsigned long>(roundf(intersection[0])); memset(&data[x + (y * max_x) + (z * img_size)], 0, (max_x - x) * sizeof(TPixel)); } else { unsigned long x = static_cast<unsigned long>(roundf(intersection[0])); TPixel *subdata = &data[x + (y * max_x) + (z * img_size)]; const unsigned long x_size = max_x - x; for (x = 0; x < x_size; ++x) { subdata[x] = casted_background_level; } } } } } } }
void mitk::PlaneCutFilter::GenerateData | ( | ) | [protected, virtual] |
A version of GenerateData() specific for image processing filters.
This implementation will split the processing across multiple threads. The buffer is allocated by this method. Then the BeforeThreadedGenerateData() method is called (if provided). Then, a series of threads are spawned each calling ThreadedGenerateData(). After all the threads have completed processing, the AfterThreadedGenerateData() method is called (if provided). If an image processing filter cannot be threaded, the filter should provide an implementation of GenerateData(). That implementation is responsible for allocating the output buffer. If a filter an be threaded, it should NOT provide a GenerateData() method but should provide a ThreadedGenerateData() instead.
Reimplemented from mitk::ImageSource.
Definition at line 25 of file mitkPlaneCutFilter.cpp.
References _computeIntersection(), AccessByItk_2, mitk::Image::GetData(), mitk::BaseData::GetGeometry(), mitk::ImageToImageFilter::GetInput(), mitk::ImageSource::GetOutput(), mitk::Image::Initialize(), m_Plane, and mitk::Image::SetImportVolume().
{ if (!this->m_Plane) { return; } InputImageType *input = const_cast<InputImageType*>(this->GetInput()); if (!input) { return; } //Allocate output. OutputImageType *output = this->GetOutput(); output->Initialize(input); output->SetImportVolume(input->GetData()); //Do the intersection. AccessByItk_2(output, _computeIntersection, this->m_Plane, input->GetGeometry()); }
virtual float mitk::PlaneCutFilter::GetBackgroundLevel | ( | ) | [virtual] |
virtual const char* mitk::PlaneCutFilter::GetClassName | ( | ) | const [virtual] |
virtual FillMode mitk::PlaneCutFilter::GetFillMode | ( | ) | [virtual] |
virtual const PlaneGeometry* mitk::PlaneCutFilter::GetPlane | ( | ) | [virtual] |
static Pointer mitk::PlaneCutFilter::New | ( | ) | [static] |
Method for creation through the object factory.
Reimplemented from mitk::ImageToImageFilter.
virtual void mitk::PlaneCutFilter::SetBackgroundLevel | ( | float | _arg ) | [virtual] |
Set background grey level.
virtual void mitk::PlaneCutFilter::SetFillMode | ( | FillMode | _arg ) | [virtual] |
virtual void mitk::PlaneCutFilter::SetPlane | ( | const PlaneGeometry * | _arg ) | [virtual] |
float mitk::PlaneCutFilter::m_BackgroundLevel [protected] |
Definition at line 59 of file mitkPlaneCutFilter.h.
FillMode mitk::PlaneCutFilter::m_FillMode [protected] |
Definition at line 63 of file mitkPlaneCutFilter.h.
Definition at line 62 of file mitkPlaneCutFilter.h.
Referenced by GenerateData().