core/vcsl/vcsl_spatial.h
Go to the documentation of this file.
00001 // This is core/vcsl/vcsl_spatial.h
00002 #ifndef vcsl_spatial_h_
00003 #define vcsl_spatial_h_
00004 //:
00005 // \file
00006 // \brief A spatial coordinate system
00007 // \author François BERTEL
00008 //
00009 // \verbatim
00010 //  Modifications
00011 //   2000/07/10 François BERTEL Creation
00012 //   2001/04/10 Ian Scott (Manchester) Converted perceps header to doxygen
00013 //   2002/01/22 Peter Vanroose - return type of from_local_to_cs() changed from ptr to non-ptr
00014 //   2002/01/28 Peter Vanroose - vcl_vector members changed from ptr to non-ptr
00015 //   2004/09/17 Peter Vanroose - made beat(), parent(), motion() non-virtual: they just return a member and should not be overloaded
00016 // \endverbatim
00017 
00018 #include <vcsl/vcsl_coordinate_system.h>
00019 #include <vcsl/vcsl_spatial_sptr.h>
00020 #include <vcsl/vcsl_spatial_transformation_sptr.h>
00021 #include <vcsl/vcsl_graph_sptr.h>
00022 #include <vnl/vnl_vector.h>
00023 #include <vcl_vector.h>
00024 class vcsl_cartesian_2d;
00025 class vcsl_polar;
00026 class vcsl_cartesian_3d;
00027 class vcsl_cylindrical;
00028 class vcsl_spherical;
00029 
00030 
00031 // This is needed for icc-7.0 to solve a strange link problem.
00032 #include <vcl_compiler.h>
00033 #ifdef VCL_ICC
00034 // Link problem occurs with either vcl_vector<bool> or std::vector<bool>
00035 #define VCSL_SPATIAL_VECTOR_BOOL vcl_vector<int>
00036 #else
00037 #define VCSL_SPATIAL_VECTOR_BOOL vcl_vector<bool>
00038 #endif
00039 
00040 
00041 //: A spatial coordinate system
00042 // class invariants:
00043 // (parent_.size()==motion_.size())&&(parent_.size()+1==beat_.size())
00044 
00045 class vcsl_spatial
00046   :public vcsl_coordinate_system
00047 {
00048  public:
00049   //***************************************************************************
00050   // Constructors/Destructor
00051   //***************************************************************************
00052 
00053   // Default constructor
00054   vcsl_spatial() {}
00055 
00056   // Destructor
00057   virtual ~vcsl_spatial();
00058 
00059   //***************************************************************************
00060   // Because VXL does not necessarily use dynamic_cast<>
00061   //***************************************************************************
00062 
00063   virtual const vcsl_spatial *cast_to_spatial() const { return this; }
00064   virtual const vcsl_cartesian_2d *cast_to_cartesian_2d() const {return 0; }
00065   virtual const vcsl_polar *cast_to_polar() const {return 0; }
00066   virtual const vcsl_cartesian_3d *cast_to_cartesian_3d() const {return 0; }
00067   virtual const vcsl_cylindrical *cast_to_cylindrical() const {return 0; }
00068   virtual const vcsl_spherical *cast_to_spherical() const {return 0; }
00069 
00070   //***************************************************************************
00071   // Status report
00072   //***************************************************************************
00073 
00074   //: Return the list of time clocks
00075   vcl_vector<double> beat() const { return beat_; }
00076 
00077   //: Return the time duration
00078   unsigned int duration() const { return (unsigned int)(beat_.size()); }
00079 
00080   //: Return the list of parent coordinate system along the time
00081   vcl_vector<vcsl_spatial_sptr> parent() const { return parent_; }
00082 
00083   //: Return the list of transformations along the time
00084   vcl_vector<vcsl_spatial_transformation_sptr> motion() const {return motion_;}
00085 
00086   //: Is `time' between the two time bounds ?
00087   bool valid_time(double time) const;
00088 
00089   //***************************************************************************
00090   // Status setting
00091   //***************************************************************************
00092 
00093   //: Set the list of time clocks
00094   void set_beat(vcl_vector<double> const& new_beat) { beat_=new_beat; }
00095 
00096   //: Set the list of parent coordinate system along the time
00097   void set_parent(vcl_vector<vcsl_spatial_sptr> const& new_parent);
00098 
00099   //: Set the list of transformations along the time
00100   void set_motion(vcl_vector<vcsl_spatial_transformation_sptr> const& m) { motion_=m; }
00101 
00102   //: Set the unique parent and the unique motion
00103   //
00104   // Can be called to initialize a CS for the first time.  Dynamically
00105   // allocates space for parent_ and motion_.  Makes new_parent and new_motion
00106   // the first element of each, respectively.
00107   //
00108   // Does not set beat_.  Effectively, new_parent and new_motion are valid for
00109   // all times.  However, a subsequent call to set_beat() could add a list of
00110   // clocks with a time corresponding to (*parent_)[0] and (*motion_)[0].
00111   //
00112   // \param new_parent CS that 'this' is derived from.
00113   // \param new_motion The transformation from new_parent to 'this'.
00114   void set_unique(const vcsl_spatial_sptr &new_parent,
00115                   const vcsl_spatial_transformation_sptr &new_motion);
00116 
00117   //***************************************************************************
00118   // Basic operations
00119   //***************************************************************************
00120 
00121   //: Return the index of the beat inferior or equal to `time'
00122   //  REQUIRE: parent().size()!=0
00123   //  REQUIRE: valid_time(time)
00124   virtual int matching_interval(double time) const;
00125 
00126   //: Does a path from `this' to `other' exist ?
00127   virtual bool path_from_local_to_cs_exists(const vcsl_spatial_sptr &other,
00128                                             double time);
00129 
00130   //: Is `this' an absolute spatial coordinate system at time `time'?
00131   //  REQUIRE: valid_time(time)
00132   virtual bool is_absolute(double time) const;
00133 
00134 
00135   //: Return v but expressed in the spatial coordinate system `other'
00136   //  REQUIRE: path_from_local_to_cs_exists(other,time)
00137   virtual vnl_vector<double> from_local_to_cs(const vnl_vector<double> &v,
00138                                               const vcsl_spatial_sptr &other,
00139                                               double time);
00140 
00141   virtual void set_graph(const vcsl_graph_sptr &new_graph);
00142 
00143  private:
00144   // Only used by vcsl_spatial and vcsl_graph
00145   void set_reached(const bool &new_reached) { reached_=new_reached; }
00146   bool reached() const { return reached_; }
00147   friend class vcsl_graph;
00148 
00149   //***************************************************************************
00150   // Implementation
00151   //***************************************************************************
00152  protected:
00153   //: Does a path from `this' to `other' exist ?
00154   // Called only by path_to_cs_exists()
00155   virtual bool
00156   recursive_path_from_local_to_cs_exists(const vcsl_spatial_sptr &other,
00157                                          double time);
00158   //: Find the sequence of transformations from `this' to `other'
00159   //  REQUIRE: path.size()==0 and sens.size()==0
00160   //  REQUIRE: path_from_local_to_cs_exists()
00161   virtual void
00162   path_from_local_to_cs(const vcsl_spatial_sptr &other,
00163                         double time,
00164                         vcl_vector<vcsl_spatial_transformation_sptr> &path,
00165                         VCSL_SPATIAL_VECTOR_BOOL &sens);
00166 
00167   //: Find the sequence of transformations from `this' to `other'
00168   //  Called only by path_from_local_to_cs()
00169   virtual bool
00170   recursive_path_from_local_to_cs(const vcsl_spatial_sptr &other,
00171                                   double time,
00172                                   vcl_vector<vcsl_spatial_transformation_sptr> &path,
00173                                   VCSL_SPATIAL_VECTOR_BOOL &sens);
00174 
00175   //: successive parents of `this' along the time
00176   vcl_vector<vcsl_spatial_sptr> parent_;
00177 
00178   //: Clock times
00179   vcl_vector<double> beat_;
00180 
00181   //: successive transformations from `this' to `parent' along the time
00182   vcl_vector<vcsl_spatial_transformation_sptr> motion_;
00183 
00184   //: List of spatial coordinate system that can be child of `this' at a time
00185   vcl_vector<vcsl_spatial_sptr> potential_children_;
00186 
00187   //: List of all the spatial coordinate system of the graph
00188   vcsl_graph_sptr graph_;
00189 
00190   //: True if `this' is already reached during the search path algorithm
00191   bool reached_;
00192 };
00193 
00194 #endif // vcsl_spatial_h_