diff --git a/Modules/GraphAlgorithms/itkShortestPathCostFunction.h b/Modules/GraphAlgorithms/itkShortestPathCostFunction.h index 7bfef48530..ed8d909467 100644 --- a/Modules/GraphAlgorithms/itkShortestPathCostFunction.h +++ b/Modules/GraphAlgorithms/itkShortestPathCostFunction.h @@ -1,85 +1,85 @@ #ifndef __itkShortestPathCostFunction_h #define __itkShortestPathCostFunction_h #include "itkObject.h" #include "itkObjectFactory.h" #include "itkShapedNeighborhoodIterator.h" #include #include namespace itk { // \brief this is a pure virtual superclass for all cost function for the itkShortestPathImageFilter template - class MitkGraphAlgorithms_EXPORT ShortestPathCostFunction : public Object + class ShortestPathCostFunction : public Object { public: /** Standard class typedefs. */ typedef ShortestPathCostFunction Self; typedef Object Superclass; typedef SmartPointer Pointer; typedef SmartPointer ConstPointer; typedef ShapedNeighborhoodIterator< TInputImageType > itkShapedNeighborhoodIteratorType; /** Run-time type information (and related methods). */ itkTypeMacro(ShortestPathCostFunction, Object); /** Type definition for the input image. */ typedef TInputImageType ImageType; // More typdefs for convenience typedef typename TInputImageType::Pointer ImagePointer; typedef typename TInputImageType::ConstPointer ImageConstPointer; typedef typename TInputImageType::PixelType PixelType; typedef typename TInputImageType::IndexType IndexType; /** Set the input image. */ itkSetConstObjectMacro(Image,TInputImageType); // \brief calculates the costs for going from pixel1 to pixel2 virtual double GetCost( IndexType p1, IndexType p2) = 0; // \brief returns the minimal costs possible (needed for A*) virtual double GetMinCost() = 0; // \brief Initialize the metric virtual void Initialize () = 0; // \brief Set Starpoint for Path void SetStartIndex (const IndexType & StartIndex); // \brief Set Endpoint for Path void SetEndIndex(const IndexType & EndIndex); ShortestPathCostFunction(); protected: virtual ~ShortestPathCostFunction() {}; void PrintSelf(std::ostream& os, Indent indent) const; ImageConstPointer m_Image; IndexType m_StartIndex, m_EndIndex; private: ShortestPathCostFunction(const Self&); //purposely not implemented void operator=(const Self&); //purposely not implemented }; } // end namespace itk #include "itkShortestPathCostFunction.cpp" #endif /* __itkShortestPathCostFunction_h */ diff --git a/Modules/GraphAlgorithms/itkShortestPathCostFunctionTbss.h b/Modules/GraphAlgorithms/itkShortestPathCostFunctionTbss.h index 3c8298bb4d..36bf9305e0 100644 --- a/Modules/GraphAlgorithms/itkShortestPathCostFunctionTbss.h +++ b/Modules/GraphAlgorithms/itkShortestPathCostFunctionTbss.h @@ -1,74 +1,74 @@ #ifndef __itkShortestPathCostFunctionTbss_h #define __itkShortestPathCostFunctionTbss_h #include "itkObject.h" #include "itkObjectFactory.h" #include "itkShapedNeighborhoodIterator.h" #include "itkShortestPathCostFunction.h" // Superclass of Metrics #include #include #include namespace itk { template - class MitkGraphAlgorithms_EXPORT ShortestPathCostFunctionTbss : public ShortestPathCostFunction + class ShortestPathCostFunctionTbss : public ShortestPathCostFunction { public: /** Standard class typedefs. */ typedef ShortestPathCostFunctionTbss Self; typedef ShortestPathCostFunction Superclass; typedef SmartPointer Pointer; typedef SmartPointer ConstPointer; typedef itk::ImageRegionConstIterator ConstIteratorType; typedef typename TInputImageType::IndexType IndexType; typedef itk::Image FloatImageType; /** Method for creation through the object factory. */ itkNewMacro(Self); /** Run-time type information (and related methods). */ itkTypeMacro(Self, Superclass); // \brief calculates the costs for going from p1 to p2 virtual double GetCost( IndexType p1, IndexType p2); // \brief Initialize the metric virtual void Initialize (); // \brief returns the minimal costs possible (needed for A*) virtual double GetMinCost(); void SetThreshold(double t) { m_Threshold = t; } protected: ShortestPathCostFunctionTbss(); virtual ~ShortestPathCostFunctionTbss() {}; double m_Threshold; private: }; } // end namespace itk #include "itkShortestPathCostFunctionTbss.cpp" #endif /* __itkShortestPathCostFunctionTbss_h */ diff --git a/Modules/GraphAlgorithms/itkShortestPathImageFilter.h b/Modules/GraphAlgorithms/itkShortestPathImageFilter.h index 45319b2acf..d66807fc59 100644 --- a/Modules/GraphAlgorithms/itkShortestPathImageFilter.h +++ b/Modules/GraphAlgorithms/itkShortestPathImageFilter.h @@ -1,214 +1,214 @@ #ifndef __itkShortestPathImageFilter_h_ #define __itkShortestPathImageFilter_h_ #include "itkImageToImageFilter.h" #include "itkShortestPathCostFunction.h" #include "itkShortestPathNode.h" #include #include #include // ------- INFORMATION ---------- /// SET FUNCTIONS //void SetInput( ItkImage ) // Compulsory //void SetStartIndex (const IndexType & StartIndex); // Compulsory //void SetEndIndex(const IndexType & EndIndex); // Compulsory //void SetFullNeighborsMode(bool) // Optional (default=false), if false N4, if true N26 //void SetActivateTimeOut(bool) // Optional (default=false), for debug issues: after 30s algorithms terminates. You can have a look at the VectorOrderImage to see how far it came //void SetMakeOutputImage(bool) // Optional (default=true), Generate an outputimage of the path. You can also get the path directoy with GetVectorPath() //void SetCalcAllDistances(bool) // Optional (default=false), Calculate Distances over the whole image. CAREFUL, algorithm time extends a lot. Necessary for GetDistanceImage //void SetStoreVectorOrder(bool) // Optional (default=false), Stores in which order the pixels were checked. Necessary for GetVectorOrderImage //void AddEndIndex(const IndexType & EndIndex) //Optional. By calling this function you can add several endpoints! The algorithm will look for several shortest Pathes. From Start to all Endpoints. // /// GET FUNCTIONS //std::vector< itk::Index<3> > GetVectorPath(); // returns the shortest path as vector //std::vector< std::vector< itk::Index<3> > GetMultipleVectorPathe(); // returns a vector of shortest Pathes (which are vectors of points) //GetDistanceImage // Returns the distance image //GetVectorOrderIMage // Returns the Vector Order image // // EXAMPLE USE // pleae see qmitkmitralvalvesegmentation4dtee bundle namespace itk { template - class MitkGraphAlgorithms_EXPORT ShortestPathImageFilter : + class ShortestPathImageFilter : public ImageToImageFilter { public: //Standard Typedefs typedef ShortestPathImageFilter Self; typedef ImageToImageFilter Superclass; typedef SmartPointer Pointer; typedef SmartPointer ConstPointer; // Typdefs for metric typedef ShortestPathCostFunction< TInputImageType > CostFunctionType; typedef typename CostFunctionType::Pointer CostFunctionTypePointer; // More typdefs for convenience typedef TInputImageType InputImageType; typedef typename TInputImageType::Pointer InputImagePointer; typedef typename TInputImageType::PixelType InputImagePixelType; typedef typename TInputImageType::SizeType InputImageSizeType; typedef typename TInputImageType::IndexType IndexType; typedef typename itk::ImageRegionIteratorWithIndex< InputImageType > InputImageIteratorType; typedef TOutputImageType OutputImageType; typedef typename TOutputImageType::Pointer OutputImagePointer; typedef typename TOutputImageType::PixelType OutputImagePixelType; typedef typename TOutputImageType::IndexType OutputImageIndexType; typedef ImageRegionIteratorWithIndex< OutputImageType > OutputImageIteratorType; typedef itk::ShapedNeighborhoodIterator< TInputImageType > itkShapedNeighborhoodIteratorType; // New Macro for smartpointer instantiation itkNewMacro(Self) // Run-time type information itkTypeMacro(ShortestPathImageFilter, ImageToImageFilter) // Display void PrintSelf( std::ostream& os, Indent indent ) const; // Compare function for A_STAR struct CompareNodeStar { bool operator()(ShortestPathNode *a, ShortestPathNode *b) { return (a->distAndEst > b->distAndEst); } }; // \brief Set Starpoint for ShortestPath Calculation void SetStartIndex (const IndexType & StartIndex); // \brief Adds Endpoint for multiple ShortestPath Calculation void AddEndIndex (const IndexType & index); // \brief Set Endpoint for ShortestPath Calculation void SetEndIndex(const IndexType & EndIndex); // \brief Set FullNeighborsMode. false = no diagonal neighbors, in 2D this means N4 Neigborhood. true = would be N8 in 2D itkSetMacro (FullNeighborsMode, bool); itkGetMacro (FullNeighborsMode, bool); // \brief (default=true), Produce output image, which shows the shortest path. But you can also get the shortest Path directly as vector with the function GetVectorPath itkSetMacro (MakeOutputImage, bool); itkGetMacro (MakeOutputImage, bool); // \brief (default=false), Store an Vector of Order, so you can call getVectorOrderImage after update itkSetMacro (StoreVectorOrder, bool); itkGetMacro (StoreVectorOrder, bool); // \brief (default=false), // Calculate all Distances to all pixels, so you can call getDistanceImage after update (warning algo will take a long time) itkSetMacro (CalcAllDistances, bool); itkGetMacro (CalcAllDistances, bool); // \brief (default=false), for debug issues: after 30s algorithms terminates. You can have a look at the VectorOrderImage to see how far it came itkSetMacro (ActivateTimeOut, bool); itkGetMacro (ActivateTimeOut, bool); // \brief returns shortest Path as vector std::vector< itk::Index<3> > GetVectorPath(); // \brief returns Multiple shortest Paths. You can call this function, when u performed a multiple shortest path search (one start, several ends) std::vector< std::vector< itk::Index<3> > > GetMultipleVectorPaths(); // \brief returns the vector order image. It shows in which order the pixels were checked. good for debugging. Be sure to have m_StoreVectorOrder=true OutputImagePointer GetVectorOrderImage(); // \brief returns the distance image. It shows the distances from the startpoint to all other pixels. Be sure to have m_CalcAllDistances=true OutputImagePointer GetDistanceImage(); // \brief cleans up the filter void CleanUp(); itkSetObjectMacro( CostFunction, CostFunctionType ); // itkSetObjectMacro = set function that uses pointer as parameter itkGetObjectMacro( CostFunction, CostFunctionType ); protected: std::vector< IndexType > m_endPoints; // if you fill this vector, the algo will not rest until all endPoints have been reached std::vector< IndexType > m_endPointsClosed; ShortestPathNode* m_Nodes; // main list that contains all nodes NodeNumType m_Graph_NumberOfNodes; NodeNumType m_Graph_StartNode; NodeNumType m_Graph_EndNode; int m_ImageDimensions; bool m_Graph_fullNeighbors; std::vector m_Graph_DiscoveredNodeList; ShortestPathImageFilter(Self&); // intentionally not implemented void operator=(const Self&); // intentionally not implemented const static int BACKGROUND = 0; const static int FOREGROUND = 255; bool m_FullNeighborsMode; bool m_MakeOutputImage; bool m_StoreVectorOrder; // Store an Vector of Order, so you can call getVectorOrderImage after update bool m_CalcAllDistances; // Calculate all Distances, so you can call getDistanceImage after update (warning algo will take a long time) bool multipleEndPoints; bool m_ActivateTimeOut; // if true, then i search max. 30 secs. then abort CostFunctionTypePointer m_CostFunction; IndexType m_StartIndex, m_EndIndex; std::vector< itk::Index<3> > m_VectorPath; std::vector< std::vector< itk::Index<3> > > m_MultipleVectorPaths; std::vector< NodeNumType > m_VectorOrder; ShortestPathImageFilter(); // \brief Fill m_VectorPath void MakeShortestPathVector(); // \brief Create all the outputs void MakeOutputs(); // \brief Generate Data void GenerateData(); // \brief gets the estimate costs from pixel a to target. double getEstimatedCostsToTarget(const IndexType & a); typename InputImageType::Pointer m_magnitudeImage; // \brief Convert a indexnumber of a node in m_Nodes to image coordinates typename TInputImageType::IndexType NodeToCoord(NodeNumType); // \brief Convert image coordinate to a indexnumber of a node in m_Nodes unsigned int CoordToNode(IndexType); // \brief Returns the neighbors of a node std::vector GetNeighbors(NodeNumType nodeNum, bool FullNeighbors); // \brief Check if coords are in bounds of image bool CoordIsInBounds(IndexType); // \brief Initializes the graph void InitGraph(); // \brief Start ShortestPathSearch void StartShortestPathSearch(); }; } // end of namespace itk #include "itkShortestPathImageFilter.cpp" #endif