#if defined (_MSC_VER) && (_MSC_VER >= 1000) #pragma once #endif #ifndef _INC_PHYSICS #define _INC_PHYSICS #include "Geometric.h" #include "Deformation.h" #include "stdafx.h" #include "itkSmartPointer.h" #include #include //Not to be confused with VNL vectors namespace mial { //!Simluates the deformation dynamics, thereby, modifying actual positions of nodes belonging to the organism /*! The physical layer of a deformable organism handles the simulation of the deformation dynamics. That is to say, it manipulates the nodes, or surfaces housed by the geometrical layer. It also maintains a list of available deformations which can be invoked on the model via the runDeformation method. This class is currently classified as stable. Error reporting is handled by the Error structure, containing an error string, the deformation number concerned, and the deformations Error structure itself. \param Type The data type to be used for internal storage. \param nDims The number of dimensions used for simulations. \param MType The type of matrix used for internal storage. Defaults to vnl_matrix, the only supported type at this time. \param VType The type of vector used for internal storage. Defaults to vnl_vector, the only supported type at this time. */ template, class VType = vnl_vector > class Physics:public itk::LightObject { public: //Smartpointers typedef Physics Self; typedef itk::SmartPointer Pointer; typedef itk::SmartPointer ConstPointer; typedef itk::WeakPointer ConstWeakPointer; //itkNewMacro(Self); //****************************************** //Define the types //****************************************** //! The type of deformation's used. Notice they must be of the same internal storage types and dimension as the physics class. typedef Deformation DeformationType; //! A structure containing error information that should be filled and thrown whenever an error in the simulation occurs. /*! \param msg A text description of the error, should also be written to std::cerr \param deformationNumber The deformation's number in the deformation list. 0-numDeformations \param deformationError The deformation's error information. */ struct Error{ std::string msg; int deformationNumber; typename DeformationType::Error * deformationError; }; typedef MType MatrixType; typedef VType VectorType; //! The type of geometric layer used. Notice that it must be of the same internal storage types and dimension as the physics class. typedef Geometric GeometryType; //*************************************** //Define the methods //*************************************** //! The destructor in charge of correctly removing the deformation list from the heap before an instantiation of the class is removed from memory. ~Physics(); //! Public member. Used by a behaviour to execute a particular deformation by name. /*! Runs a deformation on the attached geometric layer. \param args The marshaled argument list. */ virtual bool runDeformation(const std::string defName,typename DeformationType::deformationIn* const i,std::stringstream * const s = NULL)=0; //! Public member for adding a new deformation virtual bool addDeformation(Deformation * def); //! Simulate the deformation dynamics virtual bool simulate() =0; //! Public pure virtual function for setting the external forces used during simulations of the deformation dynamics. /*! The external force image is used to provide external forces to the organism during the deformation process. These could be gradient based, or a distance transform from a point of interest, etc. \param img The image to be used as an external force. Derived classes must publicly define the expected type, and then typecast the input to this function. */ virtual void setExternalForces(void * img)=0; //! Public method for setting the geometric type. void setGeometry(GeometryType* a){ if(a !=NULL){geom = a;}else{Error e; e.msg="Cannot add null geometric layer"; throw & e;}}; double getTime(){return time;}; protected: //! The default constructor Physics(); //! The number of deformations currently invocable. int numDeformations; //! The geometric layer typename GeometryType::Pointer geom; //! The list of deformations invocable by a particular physics layer. A list of smart pointers. //use stl vectors std::vector::Pointer> deformationsList; //! Keep track of the time double time; }; } // end namespace mial #include "Physics.cxx" #endif /* _INC_PHYSICS*/