#if defined (_MSC_VER) && (_MSC_VER >= 1000) #pragma once #endif #ifndef _INC_CONTROLCENTER #define _INC_CONTROLCENTER #include "Behavior.h" #include "Physics.h" #include "Sensor.h" #include "itkSmartPointer.h" #include #include //Not to be confused with VNL vectors namespace mial{ //! The brain of the organism responsible for making decisions and taking action based upon their outcome. /*! The cognitive layer of deformable organism is responsible for the decision making process. Essentially, this is the brain of the organism. It monitors the status, of the behaviors, deformations and sensors and makes decisions based upon their states and outputs. This class exploits much of the complex versatility of the framework obtained through the use of ABCs, and IO streams and structures. Through a single list of sensors and behaviors, the cognitive center can perform a variety of actions on any defined geometrical or physical type. For example, the decision to "translate" will trigger a translate behavior, which will in turn trigger the appropriate translate deformation as it pertains to the particular physical layer of the model. By that same notion, the decision to sense the eccentricity of the model will trigger the appropriate sensor. */ template class ControlCenter:public itk::LightObject { public: //Smartpointers typedef ControlCenter Self; typedef itk::SmartPointer Pointer; typedef itk::SmartPointer ConstPointer; typedef itk::WeakPointer ConstWeakPointer; //itkNewMacro(Self); //! Default destructor responsible for correctly destroying both behavior and sensor lists. ~ControlCenter(); //! Update the cognitive layer (think!) /*! If there is no current behavior, decide on one and run. Otherwise, if the behavior is finished clean it up then decide and run a new one. Otherwise keep running the current. */ virtual bool update(){ if(behaviorToRun.IsNull()) {decideNextBehavior();runNextBehavior();} else if(behaviorToRun->isFinished()) {behaviorToRun->cleanUp();decideNextBehavior();runNextBehavior();} else {updateCurrentBehavior();} return false;}; //! Set all the behaviors to have the provided physics layer virtual bool setAllPhysics(Physics *p){for(int i=0;isetPhysLayer(p);} return false;}; //! finds and returns a behavior with a particular name /*! \param name The name of the behavior to locate */ virtual Behavior* findBehavior(const std::string name); //! Accessor returning the number of known behaviors. virtual int getNumBehaviors(){return numBehaviors;}; // inline //! Add a behavior to the list of known behaviors. /*! \param b The behavior to be added. */ virtual bool addBehavior(Behavior * b); protected: //! Default constructor ControlCenter(); //! The list of behaviors known to the cognitive center /*! The cognitive center maintains a list of named behaviors that it may run. Consequently, each behavior must be of the appropriate data type and dimensionality. */ std::vector::Pointer> behaviorList; //! A list of sensors available to the control center. std::vector sensorList; //! The behavior to run next. typename Behavior::Pointer behaviorToRun; //! The arguments for the behavior to run next. This is the default behavior. //std::stringstream behaviorToRunArgs; typename Behavior::behaviorIn* behaviorToRunStruct; //! The arguments for the behavior to run next in string format. std::stringstream * behaviorToRunStream; //! Set true if the behavior is being run by stream, false otherwise. //bool runBehaviorByStream; //! The current state of the cognitive center. int state; //! The number of known behaviors. int numBehaviors; //! Set behavior to run stream void setBehaviorToRunStream(std::stringstream *a){behaviorToRunStream = a;}; //! Pure virtual member function, decides what behavior will be run after the current behavior is completed. virtual bool decideNextBehavior()=0; //! Run the next behavior decided upon by decideNextBehavior(). Will also run the current running behaviors clean up method (if the behavior is finished). virtual bool runNextBehavior(){if(behaviorToRun.IsNotNull()){behaviorToRun->run(behaviorToRunStruct,behaviorToRunStream);}return false;}; //! Update the current behavior virtual bool updateCurrentBehavior(){behaviorToRun->update();return false;}; }; }//end mial #include "ControlCenter.cxx" #endif /* _INC_CONTROLCENTER*/