00001
00002
00003 #ifndef _GEOM_ATOM_HPP_
00004 #define _GEOM_ATOM_HPP_
00005
00006 #include <jmath/jblas.hpp>
00007
00008 #include <geom/AtomVisitor.hpp>
00009 #include <geom/Declarations.hpp>
00010 #include <geom/Transformable.hpp>
00011
00012 namespace jafar {
00013 namespace geom {
00027 template<int dimension>
00028 class Atom {
00029 public:
00030 static const unsigned int NO_ID = -1;
00031 public:
00032 typedef boost::numeric::ublas::bounded_vector<double,dimension + 1> HomogenousVecD;
00033 typedef boost::numeric::ublas::bounded_vector<double,dimension> VecD;
00034 typedef boost::numeric::ublas::bounded_matrix<double,dimension + 1 ,dimension + 1> HomogenousMatrixD;
00035 typedef boost::numeric::ublas::bounded_matrix<double,dimension, dimension> MatrixD;
00036 typedef boost::numeric::ublas::bounded_matrix<double,1 ,dimension + 1> HomogenousMatrix1D;
00037 typedef boost::numeric::ublas::bounded_matrix<double,dimension + 1, 1> HomogenousMatrixD1;
00038 typedef jblas::bounded_symmetric_matrix<double, dimension + 1 > HomogenousSymMatrixD;
00039 typedef jblas::bounded_symmetric_matrix<double, dimension > SymMatrixD;
00040 typedef Repere<dimension> RepereD;
00041 typedef Transformable<dimension> TransformableD;
00042 static const int Dimension = dimension;
00043 public:
00047 enum Type {
00048 T_Point,
00049 T_Line,
00050 T_HyperPlane,
00051 T_OrientedPlan,
00052 T_PolyLine,
00053 T_Segment,
00054 T_Facet,
00055 T_Repere
00056 };
00057 public:
00061 class Driver {
00062 public:
00063 Driver() {}
00064 virtual ~Driver() {}
00065 virtual const RepereD* reference( ) const = 0;
00069 virtual bool hasCov() const = 0;
00070 };
00071 public:
00072 Atom(Driver* driver) : Epsilon(1e-6), m_driver(0), m_transformable( 0), m_id(NO_ID) { setDriver( driver); }
00073 virtual ~Atom() { delete m_driver; }
00077 inline const RepereD* reference( ) const;
00078 #ifdef _TEST_ATOM_
00079 inline Driver* driver() { return m_driver; }
00080 #endif
00081
00084 virtual Type type() const = 0;
00088 virtual BoundingBox<dimension> boundingBox() const = 0;
00089 public:
00090 virtual void accept( AtomVisitorInterface<dimension>* ) const = 0;
00091 public:
00099 virtual double distance( const Atom<dimension>& ) const;
00104 virtual double distance( const Point<dimension>& ) const = 0;
00109 virtual double distance( const Line<dimension>& ) const = 0;
00114 virtual double distance( const HyperPlane<dimension>& ) const = 0;
00119 virtual double distance( const Segment<dimension>& ) const = 0;
00124 virtual double distance( const PolyLine<dimension>& ) const = 0;
00129 virtual double distance( const Facet<dimension>& ) const = 0;
00134 virtual double distance( const RepereD& ) const = 0;
00139 virtual double angle( const Line<dimension>& ) const = 0;
00144 virtual double angle( const HyperPlane<dimension>& ) const = 0;
00149 virtual double angle( const Segment<dimension>& ) const = 0;
00154 virtual double angle( const PolyLine<dimension>& ) const = 0;
00159 virtual double angle( const Facet<dimension>& ) const = 0;
00164 virtual double angle( const RepereD& ) const = 0;
00165 public:
00169 inline bool hasCov() const;
00170 public:
00171 virtual std::string toString() const;
00172 static std::string type2String( Type type );
00173 public:
00174 void setId( unsigned int _id ) { m_id = _id; }
00175 unsigned id() const { return m_id; }
00180 void applyTransformation( const HomogenousMatrixD& _transformation );
00184 bool isTransformable() const;
00185 protected:
00186 const double Epsilon;
00187 protected:
00188 void setDriver(Driver* d);
00189 private:
00190 Driver* m_driver;
00191 Transformable<dimension>* m_transformable;
00192 unsigned int m_id;
00193 };
00194 typedef Atom<2> Atom2D;
00195 typedef Atom<3> Atom3D;
00196
00197 template<int dimension>
00198 std::ostream& operator<<(std::ostream& s, const Atom<dimension>&);
00199 }
00200 }
00201
00202 #include "AtomImpl.hpp"
00203
00204 #endif