diff --git a/Modules/AlgorithmsExt/files.cmake b/Modules/AlgorithmsExt/files.cmake index 62667e34bc..b94468babe 100644 --- a/Modules/AlgorithmsExt/files.cmake +++ b/Modules/AlgorithmsExt/files.cmake @@ -1,23 +1,24 @@ set(CPP_FILES mitkAutoCropImageFilter.cpp mitkBoundingObjectCutter.cpp mitkBoundingObjectToSegmentationFilter.cpp mitkGeometryClipImageFilter.cpp mitkHeightFieldSurfaceClipImageFilter.cpp + mitkImageToUnstructuredGridFilter.cpp mitkLabeledImageToSurfaceFilter.cpp mitkMaskAndCutRoiImageFilter.cpp mitkMaskImageFilter.cpp mitkMovieGenerator.cpp mitkNonBlockingAlgorithm.cpp mitkPadImageFilter.cpp mitkPlaneLandmarkProjector.cpp mitkPointLocator.cpp mitkSimpleHistogram.cpp mitkSimpleUnstructuredGridHistogram.cpp ) if(WIN32 AND NOT MINGW) list(APPEND CPP_FILES mitkMovieGeneratorWin32.cpp ) endif() diff --git a/Modules/AlgorithmsExt/mitkImageToUnstructuredGridFilter.cpp b/Modules/AlgorithmsExt/mitkImageToUnstructuredGridFilter.cpp new file mode 100644 index 0000000000..7b22c824c0 --- /dev/null +++ b/Modules/AlgorithmsExt/mitkImageToUnstructuredGridFilter.cpp @@ -0,0 +1,120 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#include + +#include +#include +#include + +#include + +#include + + +mitk::ImageToUnstructuredGridFilter::ImageToUnstructuredGridFilter(): +m_NumberOfExtractedPoints(0), +m_Threshold(0.0) +{ + this->m_UnstructGrid = mitk::UnstructuredGrid::New(); +} + +mitk::ImageToUnstructuredGridFilter::~ImageToUnstructuredGridFilter(){} + +void mitk::ImageToUnstructuredGridFilter::GenerateData() +{ + mitk::UnstructuredGrid::Pointer unstructGrid = this->GetOutput(); + const mitk::Image* image = this->GetInput(); + + if(image == NULL || !image->IsInitialized()) + { + MITK_ERROR << "Wrong input image set" << std::endl; + return; + } + + m_Geometry = image->GetGeometry(); + + AccessByItk(image, ExtractPoints) +} + +void mitk::ImageToUnstructuredGridFilter::SetInput(const mitk::Image* image) +{ + this->ProcessObject::SetNthInput(0, const_cast< mitk::Image* >( image ) ); +} + + +const mitk::Image* mitk::ImageToUnstructuredGridFilter::GetInput(void) +{ + if (this->GetNumberOfInputs() < 1) + { + MITK_ERROR << "No input set" << std::endl; + return 0; + } + + return static_cast( this->ProcessObject::GetInput(0) ); +} + +template +void mitk::ImageToUnstructuredGridFilter:: + ExtractPoints(const itk::Image* image) +{ + typedef itk::Image InputImageType; + typename itk::ImageRegionConstIterator it(image, image->GetRequestedRegion()); + + vtkSmartPointer points = vtkSmartPointer::New(); + + it.GoToBegin(); + while( !it.IsAtEnd() ) + { + if(it.Get() > m_Threshold) + { + mitk::Point3D imagePoint; + mitk::Point3D worldPoint; + + imagePoint[0] = it.GetIndex()[0]; + imagePoint[1] = it.GetIndex()[1]; + imagePoint[2] = it.GetIndex()[2]; + + m_Geometry->IndexToWorld(imagePoint, worldPoint); + + points->InsertNextPoint(worldPoint[0],worldPoint[1],worldPoint[2]); + m_NumberOfExtractedPoints++; + } + ++it; + } + + vtkSmartPointer vtkUnstructGrid = vtkSmartPointer::New(); + vtkUnstructGrid->SetPoints(points); + + m_UnstructGrid->SetVtkUnstructuredGrid(vtkUnstructGrid); +} + +void mitk::ImageToUnstructuredGridFilter::SetThreshold(int threshold) +{ + this->m_Threshold = threshold; +} + + +void mitk::ImageToUnstructuredGridFilter::GenerateOutputInformation() +{ + mitk::Image::ConstPointer inputImage = this->GetInput(); + + m_UnstructGrid = this->GetOutput(); + + itkDebugMacro(<<"GenerateOutputInformation()"); + + if(inputImage.IsNull()) return; +} diff --git a/Modules/AlgorithmsExt/mitkImageToUnstructuredGridFilter.h b/Modules/AlgorithmsExt/mitkImageToUnstructuredGridFilter.h new file mode 100644 index 0000000000..637fabba3e --- /dev/null +++ b/Modules/AlgorithmsExt/mitkImageToUnstructuredGridFilter.h @@ -0,0 +1,105 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#ifndef _MITKIMAGETOUNSTRUCTUREDGRIDFILTER_h__ +#define _MITKIMAGETOUNSTRUCTUREDGRIDFILTER_h__ + +#include + +#include + +#include +#include +#include + + +namespace mitk { + /** + * @brief Converts an Image into an UnstructuredGrid represented by Points. + * The filter uses a Threshold to extract every pixel, with value higher than + * the threshold, as point. + * If no threshold is set, every pixel is extracted as a point. + */ + + class MitkAlgorithmsExt_EXPORT ImageToUnstructuredGridFilter + : public UnstructuredGridSource + { + public: + + mitkClassMacro(ImageToUnstructuredGridFilter, UnstructuredGridSource) + itkFactorylessNewMacro(Self) + itkCloneMacro(Self) + + /** This method is called by Update(). */ + virtual void GenerateData(); + + /** Initializes the output information */ + virtual void GenerateOutputInformation(); + + /** Returns a const reference to the input image */ + const mitk::Image* GetInput(void); + + /** Set the source image. As input every mitk 3D image can be used. */ + using itk::ProcessObject::SetInput; + virtual void SetInput(const mitk::Image *image); + + /** + * Set the threshold for extracting points. Every pixel, which value + * is higher than this value, will be a point. + */ + void SetThreshold(int threshold); + + itkGetMacro(Threshold, double) + itkGetMacro(NumberOfExtractedPoints, int) + + protected: + + /** Constructor */ + ImageToUnstructuredGridFilter(); + + /** Destructor */ + virtual ~ImageToUnstructuredGridFilter(); + + /** + * Access method for extracting the points from the input image + */ + template + void ExtractPoints(const itk::Image* image); + + private: + + /** + * Geometry of the input image, needed to tranform the image points + * into world points + */ + mitk::BaseGeometry* m_Geometry; + + /** The number of points extracted by the filter */ + int m_NumberOfExtractedPoints; + + /** Threshold for extracting the points */ + double m_Threshold; + + /** The output of the filter, which contains the extracted points */ + mitk::UnstructuredGrid::Pointer m_UnstructGrid; + + }; + +} // namespace mitk + +#endif //_MITKIMAGETOUNSTRUCTUREDGRIDFILTER_h__ + +