/**************************************** itkLocalDistanceMapImageFilter.h Authors: Eric Billet, Andriy Fedorov PI: Nikos Chrisochoides Copyright (c) 2008 College of William and Mary All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the College of William and Mary nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. **********************************************************************/ #ifndef __itkLocalGrayscaleDistanceMapImageFilter_h #define __itkLocalGrayscaleDistanceMapImageFilter_h #include "itkImageToImageFilter.h" #include "itkImage.h" #include "itkNumericTraits.h" #include "itkCountImageFilter.h" /**define structure used for search index */ struct coord{ double dist; std::vector coords; bool operator<(coord const &other)const { return dist < other.dist; } }; namespace itk { /** \class LocalGrayscaleDistanceMapImageFilter * \brief computes a Grayscale Hausdorff based Local Distance Map * * Computes a grayscale image from a binary image and then outputs * an image where a given pixel is the grayscale Hausdorff distance * of the the corresponding pixels in the grayscale image. * * \ingroup IntensityImageFilters */ template class ITK_EXPORT LocalGrayscaleDistanceMapImageFilter : public ImageToImageFilter { public: /** Extract dimension from input and output image. */ itkStaticConstMacro(Edge1Dimension, unsigned int, TEdge1::ImageDimension); itkStaticConstMacro(Edge2Dimension, unsigned int, TEdge2::ImageDimension); itkStaticConstMacro(OutputImageDimension, unsigned int, TOutputImage::ImageDimension); /** Convenient typedefs for simplifying declarations. */ typedef TEdge1 Edge1Type; typedef TEdge2 Edge2Type; typedef TOutputImage OutputImageType; /** Standard class typedefs. */ typedef LocalGrayscaleDistanceMapImageFilter Self; typedef ImageToImageFilter< Edge1Type, OutputImageType> Superclass; typedef SmartPointer Pointer; typedef SmartPointer ConstPointer; /** Method for creation through the object factory. */ itkNewMacro(Self); /** Run-time type information (and related methods). */ itkTypeMacro(LocalGrayscaleDistanceMapImageFilter, ImageToImageFilter); /** Image typedef support. */ typedef typename Edge1Type::PixelType Edge1PixelType; typedef typename Edge2Type::PixelType Edge2PixelType; typedef typename OutputImageType::PixelType OutputPixelType; typedef typename Edge1Type::RegionType Edge1RegionType; typedef typename Edge2Type::RegionType Edge2RegionType; typedef typename OutputImageType::RegionType OutputImageRegionType; typedef typename Edge1Type::SizeType InputSizeType; typedef ConstNeighborhoodIterator NeighborhoodIteratorType; typedef ImageRegionConstIterator< Edge1Type > IteratorTypeC; typedef ImageRegionConstIteratorWithIndex< Edge1Type > IteratorTypeI; typedef ImageRegionIterator< OutputImageType > IteratorType; typedef CountImageFilter CountFilterType; typedef MaskImageFilter MaskFilter; typedef ImageFileWriter< OutputImageType > WriterType; /** Set the input files */ void SetInput1(const TEdge1 * edge1); void SetInput2(const TEdge2 * edge2); const Edge1Type * GetInput1(void); const Edge2Type * GetInput2(void); /** Set and get the radius of the neighborhood used to search for nearest neighbor. */ itkSetMacro(MaxDef, short); itkGetConstReferenceMacro(MaxDef, short); /** Set and Get the tolerance of the grayscale algorithm. */ itkSetMacro(Tol, short); itkGetConstReferenceMacro(Tol, short); /** Set and Get the radius for creation of the grayscale images. */ itkSetMacro(Radius, short); itkGetConstReferenceMacro(Radius, short); protected: LocalGrayscaleDistanceMapImageFilter(); virtual ~LocalGrayscaleDistanceMapImageFilter() {} void PrintSelf(std::ostream& os, Indent indent) const; /** LocalGrayscaleDistanceMapImageFilter can be implemented as a multithreaded filter. * Therefore, this implementation provides a ThreadedGenerateData() * routine which is called for each processing thread. The output * image data is allocated automatically by the superclass prior to * calling ThreadedGenerateData(). ThreadedGenerateData can only * write to the portion of the output image specified by the * parameter "outputRegionForThread" * */ void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId ); void BeforeThreadedGenerateData(); private: LocalGrayscaleDistanceMapImageFilter(const Self&); //purposely not implemented void operator=(const Self&); //purposely not implemented short m_MaxDef; std::vector coord_list; short m_Tol; typename Edge1Type::Pointer m_gray1; typename Edge1Type::Pointer m_gray2; short m_Radius; }; } // end namespace itk #ifndef ITK_MANUAL_INSTANTIATION #include "itkLocalGrayscaleDistanceMapImageFilter.txx" #endif #endif