#if !defined(_GEOM_MESHSPATIALOBJECT) #define _GEOM_MESHSPATIALOBJECT #include "Geometric.h" #include #include #include #include #include #include "itkLineCell.h" #include "itkTriangleCell.h" #include "itkImage.h" #include #include #include "vnl/vnl_cross.h" #include "itkImageRegionConstIterator.h" #include "itkImageRegionIterator.h" #include "itkTriangleMeshToBinaryImageFilter.h" namespace mial{ //! Derived geometric class based on a spatial object. /*! A derived class of the Geometrical ABC, this class provides the framework with the functionality of ITK mesh spatial objects. Creating a deformable organism is made easy with this class, as it can import any triangulated mesh spatial object contained in a meta file. It can also convert triangulated BYU surfaces to meta format, and import those. The primary restriction of this class is that it must be a triangulated mesh and, as such, parts of this classes functionality are currently restricted to 3D. Specifically, its ability to generate binary images from mesh objects. This class is also designed specifically to complement the Phys_LevelSet class. This class is currently classified as unstable, since it is constantly evolving to meet the changing needs of our framework. \param dType The data type used for numerical storage. \param nDims The number of dimensions. \param MType The matrix type used for internal matrix storage. Defaults to vnl_matrix. Only vnl is supported at this time. \param VType The vector type used for internal vector storage. Defaults to vnl_vector. Only vnl is supported at this time. */ template < class dType, int nDims, class MType = vnl_matrix, class VType = vnl_vector > class Geom_MeshSpatialObject : public Geometric< dType, nDims, MType, VType > { /**************************************************** MEMBERS *****************************************************/ public: //Smartpointer typedef Geom_MeshSpatialObject Self; typedef itk::SmartPointer Pointer; typedef itk::SmartPointer ConstPointer; typedef itk::WeakPointer ConstWeakPointer; itkNewMacro(Self); typedef MType MatrixType; typedef VType VectorType; typedef itk::DefaultDynamicMeshTraits< dType, nDims, nDims > MeshTrait; typedef itk::Mesh< dType, nDims, MeshTrait > MeshType; typedef typename MeshType::PointType PointType; typedef typename itk::MeshSpatialObject< MeshType > MeshSpatialObjectType; typedef typename MeshSpatialObjectType::Pointer MeshSpatialObjectPointerType; typename MeshSpatialObjectType::Pointer theMeshSpatialObject; typename MeshType::Pointer theMesh; //Note you need to overwrite this whenever you overwrite the spatialobjects mesh typedef typename MeshType::CellType CellType; typedef typename CellType::CoordRepType CoordRepType; //typedef itk::LineCell< CellType > LineType; typedef itk::TriangleCell TriangleType; typedef typename CellType::CellAutoPointer CellAutoPointer; typedef typename MeshType::CellsContainer::ConstIterator CellIterator; typedef itk::GroupSpatialObject< nDims > GroupType; typedef itk::SpatialObjectReader ReaderType; typedef itk::SpatialObjectWriter< nDims, dType, MeshTrait > WriterType; typename WriterType::Pointer writer; typedef typename Geometric< dType, nDims >::BinaryImageType BinaryImageType; typedef typename BinaryImageType::Pointer BinaryImageTypePointer; /***************************************************** METHODS ******************************************************/ public: virtual MatrixType getMatrixNodePositions(); virtual void writeNodesToFile(std::string fileName); virtual void readNodesFromFile(std::string fileName); virtual bool readTopologyFromFile(std::string fileName); virtual bool setMatrixNodePositions(MatrixType,int *); virtual bool setMatrixNodePositions(MatrixType); virtual void writeObjectToFile(std::string fileName); //TODO Fix to use correct type virtual typename itk::Image< unsigned char, nDims>::Pointer generateBinaryImageFromTopology( typename BinaryImageType::SizeType size); virtual void generateTopologyFromBinaryImage( BinaryImageTypePointer binaryInputImage ); // TODO fill in code for adding/removing nodes virtual bool removeNode(int nodeNumber){return false;}; virtual bool addNodes(MatrixType node,VectorType classes); virtual bool addConnection(int,int); virtual MatrixType getMatrixConnections(){/* TODO fill in implmentation.*/ return this->mConnections;}; virtual bool isInside(VectorType p); private: virtual void updateMatrixNodePositions(); virtual void updateMeshNodePositions(); virtual void updateMatrixConnections(); virtual bool intersectWithLine( VectorType L, VectorType P, TriangleType* tri); dType m_IsInsidePrecision; protected: //! The default constructor /*! \param p The precision used to check if a point lies inside the object for conversion to a binary image. */ Geom_MeshSpatialObject(dType p=0.001); }; }//end mial #include "Geom_MeshSpatialObject.cxx" #endif