/[ff3d]/ff3d/solver/Vertex.hpp
ViewVC logotype

Diff of /ff3d/solver/Vertex.hpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by delpinux, Fri Aug 1 17:49:05 2003 UTC revision 1.3 by delpinux, Fri Aug 8 08:39:56 2003 UTC
# Line 23  Line 23 
23  #define VERTEX_HPP  #define VERTEX_HPP
24    
25  #include <TinyVector.hpp>  #include <TinyVector.hpp>
26  #include <TinyMatrix.hpp>  #include <StreamCenter.hpp>
27    
28  #include <cassert>  #include <cassert>
29    
 #include <StreamCenter.hpp>  
   
30  /**  /**
31   * @file   Vertex.hpp   * @file   Vertex.hpp
32   * @author Stephane Del Pino   * @author Stephane Del Pino
# Line 36  Line 34 
34   *   *
35   * @brief  Vertices management   * @brief  Vertices management
36   *   *
  * @warning Check ReferenceCounting cost  
37   */   */
38    
39  class Vertex  class Vertex
40      : public TinyVector<3, real_t>
41  {  {
42   private:   private:
43    //! The Vertex coordinates.    size_t __reference;           /**< The reference of the vertex */
   TinyVector<3> __x;  
44    
   //! The Vertex reference.  
   size_t __reference;  
45   public:   public:
46    /*! Read-only acces to TinyVector<3> of coordinates.    /**
47      \todo Change the name of this member.     * Compares two vertices. Result is false if vertices are not the
48       * same variable in memory.
49       *
50       * @param V the vertex to compare with
51       *
52       * @return true if the two vertices are the \b same
53     */     */
   inline const TinyVector<3>& Vector3() const  
   {  
     return __x;  
   }  
   
   /*! Acces to TinyVector<3> of coordinates.  
     \todo Change the name of this member.  
   */  
   inline TinyVector<3>& Vector3()  
   {  
     return __x;  
   }  
   
   //! Acces to the coordinate \a i.  
   inline real_t& operator[](const int& i)  
   {  
     return __x[i];  
   }  
   
   //! Read-only acces to the coordinate \a i.  
   inline const real_t& operator[](const int& i) const  
   {  
     return __x[i];  
   }  
   
   /*! Compares to the Vertex \a V.  
     \returns \p true if the two vertices \b are the same (got same address).  
   */  
54    inline const bool operator == (const Vertex& V) const    inline const bool operator == (const Vertex& V) const
55    {    {
56      return (&V == this);      return (&V == this);
57    }    }
58    
59    //! Affectes the Vertex \a V.    /**
60       * Sets the vertex equal to a given one
61       *
62       * @param V the model vertex
63       *
64       * @return the modified \f$ U := V \f$ vertex
65       */
66    inline const Vertex& operator = (const Vertex& V)    inline const Vertex& operator = (const Vertex& V)
67    {    {
68      for (int i=0; i<3; i++)      TinyVector<3, real_t>::operator = (V);
       __x[i] = V.__x[i];  
69      __reference = V.__reference;      __reference = V.__reference;
70      return (*this);      return (*this);
71    }    }
72    
73    /*! Computes the Vertex which coordinates are the sum of two vertices    /**
74      coordinates.     * Access to the first coordinate of the vertex
75      \warning should use \p TinyVector<3>'s operator +=.     *
76       *
77       * @return \$f U_1 \$
78     */     */
79    inline Vertex operator + (const Vertex& V) const    inline real_t& x()
80    {    {
81      Vertex W(*this);      return (*this)[0];
     for (int i=0; i<3; i++)  
       W.__x[i] += V.__x[i];  
     return W;  
82    }    }
83    
84    /*! Computes the Vertex which coordinates which is the result of translation    /**
85      along the \p TinyVector<3> \a V.     * Access to the second coordinate of the vertex
86      \warning should use \p TinyVector<3>'s operator +=.     *
87       *
88       * @return \$f U_2 \$
89     */     */
90    inline Vertex operator + (const TinyVector<3>& V) const    inline real_t& y()
91    {    {
92      Vertex W(*this);      return (*this)[1];
     for (int i=0; i<3; i++)  
       W.__x[i] += V[i];  
     return W;  
93    }    }
94    
   /*! Computes the Vertex which coordinates which is the result of translation  
     along the \p TinyVector<3>  -\a V.  
     \warning should use \p TinyVector<3>'s operator -=.  
    */  
   inline Vertex operator - (const TinyVector<3>& V) const  
   {  
     Vertex W(*this);  
     for (int i=0; i<3; i++)  
       W.__x[i] -= V[i];  
     return W;  
   }  
95    
96    //! Access to the first coordinate of the Vertex.    /**
97    inline real_t& X()     * Access to the third coordinate of the vertex
98    {     *
99      return __x[0];     *
100    }     * @return \$f U_3 \$
101       */
102    //! Access to the second coordinate of the Vertex.    inline real_t& z()
   inline real_t& Y()  
   {  
     return __x[1];  
   }  
   
   //! Access to the third coordinate of the Vertex.  
   inline real_t& Z()  
103    {    {
104      return __x[2];      return (*this)[2];
105    }    }
106    
107    //! Read-only access to the first coordinate of the Vertex.    /**
108    inline const real_t& X() const     * Read-only access to the first coordinate of the vertex
109       *
110       *
111       * @return \$f U_1 \$
112       */
113      inline const real_t& x() const
114    {    {
115      return __x[0];      return (*this)[0];
116    }    }
117    
118    //! Read-only access to the second coordinate of the Vertex.    /**
119    inline const real_t& Y() const     * Read-only access to the second coordinate of the vertex
120       *
121       *
122       * @return \$f U_2 \$
123       */
124      inline const real_t& y() const
125    {    {
126      return __x[1];      return (*this)[1];
127    }    }
128    
129    //! Read-only access to the third coordinate of the Vertex.    /**
130    inline const real_t& Z() const     * Read-only access to the third coordinate of the vertex
131       *
132       *
133       * @return \$f U_3 \$
134       */
135      inline const real_t& z() const
136    {    {
137      return __x[2];      return (*this)[2];
138    }    }
139    
140    //! Access to the reference of the Vertex.    /**
141    inline size_t& Ref()     * Access to the reference of the vertex
142       *
143       *
144       * @return the reference
145       */
146      inline size_t& reference()
147    {    {
148      return __reference;      return __reference;
149    }    }
150    
151    //! Read-only access to the reference of the Vertex.    /**
152    inline const size_t& Ref() const     * Read-only access to the reference of the vertex
153       *
154       *
155       * @return the reference
156       */
157      inline const size_t& reference() const
158    {    {
159      return __reference;      return __reference;
160    }    }
161    
162    /*! Constructs the Vertex whose coordinates are (\a X, \a Y, \a Z)    /**
163      and without precising references     * Default constructor. Coordinates and references are set to 0
164       *
165     */     */
166    Vertex()    Vertex()
167      : __x(0,0,0),      : TinyVector<3, real_t>(0,0,0),
168        __reference(0)        __reference(0)
169    {    {
170      ;      ;
171    }    }
172    
173    /*! Constructs the Vertex whose coordinates are (\a X, \a Y, \a Z)    /**
174      and without precising references     * Constructor
175     */     *
176    Vertex(const real_t& X, const real_t& Y, const real_t& Z)     * @param X first coordinate
177      : __x(X,Y,Z),     * @param Y second coordinate
178        __reference(0)     * @param Z third coordinate
179    {     * @param reference the reference
180      ;     *
181    }     * @note reference is optionnal, if omitted it is 0
   
   /*! Constructs the Vertex whose coordinates are (\a X, \a Y, \a Z) and whose  
     reference is \a Ref.  
182     */     */
183    Vertex(const real_t& X, const real_t& Y, const real_t& Z,    Vertex(const real_t& X, const real_t& Y, const real_t& Z,
184           const size_t& reference)           const size_t& ref = 0)
185      : __x(X,Y,Z),      : TinyVector<3, real_t>(X,Y,Z),
186        __reference(reference)        __reference(ref)
187    {    {
188      ;      ;
189    }    }
190    
191    /*! Constructs the Vertex whose coordinates are given using the \p    /**
192      TinyVector<3> \a X without precising references     * Constructor
193       *
194       * @param V coordinates
195       * @param reference the reference
196       *
197       * @note reference is optionnal, if omitted it is 0
198     */     */
199    Vertex(const TinyVector<3> X)    Vertex(const TinyVector<3, real_t>& V,
200      : __x(X),           const size_t& ref=0)
201        __reference(0)      : TinyVector<3, real_t>(V),
202          __reference(ref)
203    {    {
204      ;      ;
205    }    }
206    
207    /*! Constructs the Vertex whose coordinates are given using the \p    /**
208      TinyVector<3> \a X and whose reference is \a Ref.     * Copy constructor
209       *
210       * @param V a given vertex
211       *
212     */     */
   Vertex(const TinyVector<3> X,  
          const size_t& reference)  
     : __x(X),  
       __reference(reference)  
   {  
     ;  
   }  
   
   //! Copy constructor.  
213    Vertex(const Vertex& V)    Vertex(const Vertex& V)
214      : __x(V.__x),      : TinyVector<3, real_t>(V),
215        __reference(V.__reference)        __reference(V.__reference)
216    {    {
217      ;      ;
218    }    }
219    
220    //! Destructor.    /**
221       * Destructor
222       *
223       */
224    ~Vertex()    ~Vertex()
225    {    {
226      ;      ;
227    }    }
228    
229    //! Computes the Euclidean distance to the Vertex \a v.    /**
230    inline const real_t distance(const Vertex& v) const     * Computes the of the distance to another point
231    {     *
232      return std::sqrt((v.X()-X())*(v.X()-X())     * @param V the point to compute the distance with
233                       +(v.Y()-Y())*(v.Y()-Y())     *
234                       +(v.Z()-Z())*(v.Z()-Z()));     * @return \f$ ||U-V||^2 \f$
235       */
236      inline const real_t distance(const TinyVector<3, real_t>& V) const
237      {
238        return std::sqrt((V[0]-x())*(V[0]-x())
239                         +(V[1]-y())*(V[1]-y())
240                         +(V[2]-z())*(V[2]-z()));
241      }
242    
243      /**
244       * Computes the \b square of the distance to another point
245       *
246       * @param V the vertex to compute the distance with
247       *
248       * @return \f$ ||U-V||^2 \f$
249       */
250      inline real_t distance2(const TinyVector<3, real_t>& V) const
251      {
252        return ((V[0]-x())*(V[0]-x())
253                +(V[1]-y())*(V[1]-y())
254                +(V[2]-z())*(V[2]-z()));
255    }    }
256    
   //! Computes the square to the Euclidean distance to the Vertex \a v.  
   inline const real_t distance2(const Vertex& v) const  
   {  
     return ((v.X()-X())*(v.X()-X())  
             +(v.Y()-Y())*(v.Y()-Y())  
             +(v.Z()-Z())*(v.Z()-Z()));  
   }  
257    
258    //! Computes the square to the Euclidean distance to the TinyVector<3> \a v.    /**
259    inline const real_t distance2(const TinyVector<3>& v) const     * Prints a given vertex to a stream
260    {     *
261      return ((v[0]-X())*(v[0]-X())     * @param os the given stream
262              +(v[1]-Y())*(v[1]-Y())     * @param V the vertex
263              +(v[2]-Z())*(v[2]-Z()));     *
264    }     * @return the modified stream
   /*! Computes TinyMatrix<3,3> Vertex product.  
     \todo remove this from the class since it has no sens in term of Vertex.  
265     */     */
   friend Vertex operator*(const TinyMatrix<3,3>& M, const Vertex& V)  
   {  
     Vertex W;  
     for (int i=0; i<3; i++)  
       for (int j=0; j<3; j++) {  
         W[i] += M(i,j) * V[j];  
       }  
     return W;  
   }  
   
   //! Prints the Vertex \a v to the \p std::ostream \a os.  
266    friend std::ostream& operator<< (std::ostream& os,    friend std::ostream& operator<< (std::ostream& os,
267                                     const Vertex& v);                                     const Vertex& V);
268  };  };
269    
270    

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26