Jafar
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
AtomImpl.hpp
00001 /* $Id$ */
00002 
00003 #include "geom/Angle.hpp"
00004 #include "geom/Distance.hpp"
00005 
00006 #include "geom/Facet.hpp"
00007 #include "geom/HyperPlane.hpp"
00008 #include "geom/Line.hpp"
00009 #include "geom/Point.hpp"
00010 #include "geom/PolyLine.hpp"
00011 #include "geom/Repere.hpp"
00012 #include "geom/Segment.hpp"
00013 
00014 #define GEOMETRIC_RELATION(Type) \
00015   { \
00016     const jafar::geom::Type<dimension>* o = dynamic_cast<const jafar::geom::Type<dimension>* >(&atom); \
00017     if(o) \
00018     { \
00019       return GeometricRelation( distance(*o), angle(*o) ); \
00020     } \
00021   }
00022   
00023 #define ATOM_TO_ATOM_DISTANCE(Type) \
00024   { \
00025     const jafar::geom::Type<dimension>* o = dynamic_cast<const jafar::geom::Type<dimension>* >(&atom); \
00026     if(o) \
00027     { \
00028       return distance(*o); \
00029     } \
00030   }
00031 
00032 namespace jafar {
00033   namespace geom {
00034     template<int dimension>
00035     inline const Repere<dimension>* Atom<dimension>::reference( ) const
00036     {
00037       if(m_driver)
00038       {
00039         return m_driver->reference();
00040       } else {
00041         return RepereD::global();
00042       }
00043     }
00044     #if 0
00045     template<int dimension>
00046     GeometricRelation Atom<dimension>::relation(const Atom<dimension>& atom) const
00047     {
00048       const Point<dimension>* pt = dynamic_cast<const Point<dimension>* >(&atom);
00049       if(pt)
00050       {
00051         return GeometricRelation( distance( *pt ) , 0.0);
00052       }
00053       GEOMETRIC_RELATION(Segment); // Allways before Line !
00054       GEOMETRIC_RELATION(Line);
00055       GEOMETRIC_RELATION(Facet);
00056       GEOMETRIC_RELATION(HyperPlane);
00057       GEOMETRIC_RELATION(PolyLine);
00058       GEOMETRIC_RELATION(Repere);
00059       return GeometricRelation();
00060     }
00061     #endif
00062     template<int dimension>
00063     double Atom<dimension>::distance( const Atom<dimension>& atom) const
00064     {
00065       ATOM_TO_ATOM_DISTANCE(Point);
00066       ATOM_TO_ATOM_DISTANCE(Segment);
00067       ATOM_TO_ATOM_DISTANCE(Line);
00068       ATOM_TO_ATOM_DISTANCE(Facet);
00069       ATOM_TO_ATOM_DISTANCE(HyperPlane);
00070       ATOM_TO_ATOM_DISTANCE(PolyLine);
00071       ATOM_TO_ATOM_DISTANCE(Repere);
00072       JFR_ASSERT(false, "Unknonw object: distance wasn't correctly computed.");
00073       return 0.0;
00074     }
00075     template<int dimension>
00076     void Atom<dimension>::setDriver(Driver* d)
00077     {
00078       delete m_driver;
00079       m_driver = d;
00080       m_transformable = dynamic_cast<TransformableD*>( m_driver);
00081     }
00082     
00083     template<int dimension>
00084     bool Atom<dimension>::hasCov() const
00085     {
00086       return m_driver->hasCov();
00087     }
00088     
00089     template<int dimension>
00090     std::string Atom<dimension>::toString() const
00091     {
00092       return "Type = " + type2String( type() );
00093     }
00094     
00095     template<int dimension>
00096     std::string Atom<dimension>::type2String( Type type )
00097     {
00098       switch(type)
00099       {
00100         case T_Point:
00101           return "Point";
00102         case T_Line:
00103           return "Line";
00104         case T_HyperPlane:
00105           return "HyperPlane";
00106         case T_OrientedPlan:
00107           return "OrientedPlan";
00108         case T_PolyLine:
00109           return "PolyLine";
00110         case T_Segment:
00111           return "Segment";
00112         case T_Facet:
00113           return "Facet";
00114         case T_Repere:
00115           return "Repere";
00116       }
00117       return "";
00118     }
00119     
00120     template<int dimension>
00121     void Atom<dimension>::applyTransformation( const HomogenousMatrixD& _transformation )
00122     {
00123       m_transformable->applyTransformation( _transformation );
00124     }
00125     
00126     template<int dimension>
00127     bool Atom<dimension>::isTransformable() const
00128     {
00129       return m_transformable;
00130     }
00131     
00132     template<int dimension>
00133     std::ostream& operator<<(std::ostream& s, const Atom<dimension>& atom)
00134     {
00135       s << "[atom type=(" << atom.type() << ", " << Atom<dimension>::type2String( atom.type()) << "), boundingBox=" << atom.boundingBox() << " ]";
00136       return s;
00137     }
00138   }
00139 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Wed Oct 15 2014 00:37:19 for Jafar by doxygen 1.7.6.1
LAAS-CNRS