00001
00002
00003 #include <sstream>
00004
00005 namespace jafar {
00006 namespace geom {
00007
00008 template<int dimension>
00009 template<typename _TDriver_>
00010 Facet<dimension>::Facet( _TDriver_* d, const PolyLine<dimension-1>& polyLine ) : OrientedPlanD(d), m_planPolyLine(polyLine), m_spacePolyLine( new typename PolyLine<dimension>::PolyLineNM1Driver( &m_planPolyLine, this->repere() ) )
00011 {
00012 }
00013 template<int dimension>
00014 Facet<dimension>::~Facet()
00015 {
00016 }
00017 template<int dimension>
00018 Facet<dimension>::Facet() : OrientedPlanD(), m_planPolyLine(0), m_spacePolyLine( new typename PolyLine<dimension>::PolyLineNM1Driver( &m_planPolyLine, this->repere() ) )
00019 {
00020 }
00021 template<int dimension>
00022 Facet<dimension>::Facet(const PolyLine<dimension>& polyLine) : OrientedPlanD( new typename OrientedPlan<dimension>::PolyLineDriver(polyLine) ), m_planPolyLine( new typename PolyLine<dimension>::PolyLineNP1Driver(polyLine) ) , m_spacePolyLine(polyLine)
00023 {
00024 }
00025 template<int dimension>
00026 Facet<dimension>::Facet(const Facet& f) : OrientedPlanD(f), m_planPolyLine(f.planPolyLine()), m_spacePolyLine( new typename PolyLine<dimension>::PolyLineNM1Driver( &m_planPolyLine, this->repere() ) )
00027 {
00028 this->setId( f.id() );
00029 }
00030 template<int dimension>
00031 inline Facet<dimension>& Facet<dimension>::operator=(const Facet& rhs)
00032 {
00033 *(OrientedPlanD*)(this) = rhs;
00034 setPlanPolyLine( rhs.planPolyLine() );
00035 this->setId( rhs.id() );
00036 return *this;
00037 }
00038 template<int dimension>
00039 void Facet<dimension>::setPlanPolyLine(const PolyLine<dimension-1>& _planPolyLine)
00040 {
00041 m_planPolyLine = _planPolyLine;
00042 }
00043 template<int dimension>
00044 const PolyLine<dimension-1>& Facet<dimension>::planPolyLine() const
00045 {
00046 return m_planPolyLine;
00047 }
00048 template<int dimension>
00049 const PolyLine<dimension>& Facet<dimension>::spacePolyLine() const
00050 {
00051 return m_spacePolyLine;
00052 }
00053 template<int dimension>
00054 double Facet<dimension>::surface(const typename Facet<dimension>::HomogenousVecDM1& v1, const typename Facet<dimension>::HomogenousVecDM1& v2) const
00055 {
00056 double s = 0.5 * ( v1[ dimension - 2] + v2[ dimension - 2] );
00057 for(int i = 0; i < (dimension - 2); i++)
00058 {
00059 s *= (v2[i] - v1[i]);
00060 }
00061 return s;
00062 }
00063 template<int dimension>
00064 double Facet<dimension>::surface() const
00065 {
00066 std::vector< HomogenousVecDM1 > points_ = m_planPolyLine.points();
00067 double surface_ = 0.0;
00068 for(unsigned int i = 0; i < points_.size() - 1; i++)
00069 {
00070 surface_ += surface(points_[ i ], points_[ i + 1 ]);
00071 }
00072 surface_ += surface(points_[ points_.size() - 1 ], points_[ 0 ]);
00073 return fabs(surface_);
00074 }
00075 template<int dimension>
00076 double Facet<dimension>::perimeter() const
00077 {
00078 return m_planPolyLine.perimeter();
00079 }
00080 template<int dimension>
00081 std::string Facet<dimension>::toString() const
00082 {
00083 std::ostringstream oss;
00084 oss << Atom<dimension>::toString() << " Origin = " << this->origin() << " Surface = " << surface() << " Perimeter = " << perimeter();
00085 return oss.str();
00086 }
00087 template<int dimension>
00088 inline BoundingBox<dimension> Facet<dimension>::boundingBox() const
00089 {
00090 return m_spacePolyLine.boundingBox();
00091 }
00092 }
00093 }