#if defined (_MSC_VER) && (_MSC_VER >= 1000) #pragma once #endif #ifndef _INC_Phys_Euler_422B64F703C8_INCLUDED #define _INC_Phys_Euler_422B64F703C8_INCLUDED #include "stdafx.h" #include "Physics.h" #include "SpringMassDeformation.h" /*#include #include #include #include */ #include #include #define DEBUG 0 #define BOUND_CHECKING 1 namespace mial { //! A derived physics class capable of carrying out deformations of a spring mass system. /*! A derived class of the physical ABC, this class provides the framework with the ability to simulate deformation dynamics of any dimension on a spring mass system. It assumes any node in the geometrical layer to represent a mass and any connection present to represent a spring between connected masses. This class is considered to be relatively stable, in that additional functionality may be added but current functionality will remain. See [1] for details on the simulation dynamics and examples of possible controled deformation types. [1] Ghassan Hamarneh and Chris McIntosh. Physics-based deformable organisms for medical image analysis. SPIE Medical Imaging, 5747:326335, 2005. \param Type The data type to be used for internal storage. \param TGradientImage The data type used for external forces. \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 Phys_Euler: public Physics { //***************************/ // Public definitions //***************************/ public: //Smart pointers typedef Phys_Euler Self; typedef itk::SmartPointer Pointer; typedef itk::SmartPointer ConstPointer; typedef itk::WeakPointer ConstWeakPointer; itkNewMacro(Self); typedef SpringMassDeformation DeformationType; //Use spring mass deformations specificially typedef MType MatrixType; typedef VType VectorType; typedef TGradientImage GradientImageType; struct Error: public Physics::Error { // TODO fill in }; //***************************/ // Member Variables //***************************/ protected: //! Typedef for the type of gradient image smart pointer used typedef typename GradientImageType::Pointer GradientImageTypePointer; //! A matrix of nodes MatrixType nodes; //! A matrix of node velocities MatrixType nodesV; //! A matrix of node forces MatrixType nodesF; //! A matrix of node deformation forces MatrixType nodesFDef; //! A matrix of node accelerations MatrixType nodesA; //! A matrix of node masses VectorType nodesM; //! The default mass DataType defaultMass; //! A vector of spring rest lengths VectorType springsRest; //! A vector of spring dampening amounts VectorType springsDamp; //! The default dampening amount DataType defaultDamp; //! A matrix describing how the springs and masses are connected. e.g. spring1: node 1 --> node 2, spring2: node 2 --> node 3 MatrixType springsNodes; //! A vector of current spring lengths VectorType springLengths; //! A vector of Hooke constants for each spring VectorType springsK; //! The default Hooke constant DataType defaultK; //! The default drag force DataType defaultDrag; //! How large a time step to take during the simulations. Position = PositionOld + (VelocityOld + acceleartion*timeStep)*timeStep; double timeStep; //! The pointer to the gradient image GradientImageTypePointer gradientPointer; //! Whether or not image forces are enabled. bool imageForces; //***************************/ // Member Functions //***************************/ public: //! Run a deformation /*! Assemble the neccessary inputs and run the named deformation. Typically, only behaviors call this method. Note that only one of i,s can be non-null, while s is only optionally supported. \param defName the name of the deformation \param i The deformations argument list prepared by the behavior requesting the run \param s The deformations argument list in stream format. */ virtual bool runDeformation(const std::string defName,typename DeformationType::deformationIn* const i,std::stringstream * const s = NULL); //! Set the restlengths of the specified springs to the specified values. /*! \param a the indices of the springs \param values the values to use \param n the number of springs being set */ virtual void setRestLengths(int* a, DataType* values, int n); //! Set the restlengths of the specified springs to the specified values. /*! \param a the indices of the springs \param values the values to use */ virtual void setRestLengths(VectorType a, VectorType values); //! Set the time step /*! \param a the new time step. */ virtual void setTimeStep(double a){timeStep = a;} //! Set the lengths of the specified springs to the specified values. /*! \param a the indices of the springs \param values the values to use \param n the number of springs being set */ virtual void setSpringLengths(int* a, DataType* values, int n); //! Set the lengths of the specified springs to the specified values. /*! \param a the indices of the springs \param values the values to use */ virtual void setSpringLengths(VectorType a, VectorType values); //! Set the Hooke's constants of the specified springs to the specified values. /*! \param a the indices of the springs \param values the values to use \param n the number of springs being set */ virtual void setSpringsK(int* a, DataType* values, int n); //! Set the Hooke's constants of the specified springs to the specified values. /*! \param a the indices of the springs \param values the values to use */ virtual void setSpringsK(VectorType a, VectorType values); //! enable image forces (defaultly enabled) virtual void enableImageForces(){imageForces = true;}; //! disable image forces (defaultly enabled) virtual void disableImageForces(){imageForces = false;}; //! Simulate the deformation dynamics virtual bool simulate(); //! Set the external forces to be used during the simulation. virtual void setExternalForces(void * f){gradientPointer = *((GradientImageTypePointer *) f);}; protected: Phys_Euler(int numNodes =0 ,int numSprings = 0, int numPossibleDeformations = 0, int defK = 35); private: virtual void updateSpringsFromGeometric(); }; } // end namespace mial #include "Phys_Euler.cxx" #endif /* _INC_Phys_Euler_422B64F703C8_INCLUDED */