]> SALOME platform Git repositories - modules/hexablock.git/blob - src/HEXABLOCK/HexVertex.hxx
Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/hexablock.git] / src / HEXABLOCK / HexVertex.hxx
1
2 // Class : Gestion des sommets 
3
4 // Copyright (C) 2009-2012  CEA/DEN, EDF R&D
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifndef __VERTEX_H_
24 #define __VERTEX_H_
25
26 #include "HexEltBase.hxx"
27
28 BEGIN_NAMESPACE_HEXA
29
30 class Vertex : public EltBase 
31 {
32 public :
33    double getX()   { return v_x; }
34    double getY()   { return v_y; }
35    double getZ()   { return v_z; }
36    double getCoord (int dir);
37
38    virtual int     countVertex ()       { return 1; }
39    virtual Vertex* getVertex (int nro)  { return this; }
40
41
42    void setX (double v)   { v_x = v ; }
43    void setY (double v)   { v_y = v ; }
44    void setZ (double v)   { v_z = v ; }
45  
46    void assoCoord (double x, double y, double z);
47    void assoCoord (double* pnt); 
48
49 public :
50    Vertex (Document* prev, double x=0.0, double y=0.0, double z=0.0); 
51    Vertex (Document* cible, Vertex* other);
52    Vertex (Vertex* other);
53    virtual ~Vertex () {}
54    virtual void dump () ;
55    virtual void saveXml (XmlWriter* xml);
56
57    void    setScalar (double val)             { v_scalar = val ; }
58    double  getScalar ()                       { return v_scalar ; }
59    void    setColor  (double valeur)          { setScalar (valeur) ; }
60    double* getPoint (double point[]);
61
62    void setCoord  (double x, double y, double z);
63    bool isin      (double xmin, double xmax, double ymin, double ymax, 
64                                             double zmin, double zmax);
65    Edge* getParent (int nro); 
66    Vertex* makeSymetric (Vertex* other);
67    void    translate (Vector* vecteur, double fact=1.0);
68    void    replace   (Vertex* old);
69
70    Vertex* getClone ()              {  return v_clone ; }
71    void    duplicate (Document* doc);
72
73    static Vertex* createMiddle (Vertex* left, Vertex* right);
74    bool   definedBy (double px, double py, double pz, double eps2=1e-4);
75
76 private :
77     double v_x;
78     double v_y;
79     double v_z;
80
81     double  v_scalar;
82     Vertex* v_clone;
83     double  gc_x, gc_y, gc_z;
84     bool    gc_ass;
85 };
86 // ========================================================= Constructeur bis 
87 inline Vertex::Vertex (Vertex* other)
88       : EltBase (other->dad(), EL_VERTEX)
89 {
90    if (other!= NULL)
91       {
92       v_x = other->v_x;
93       v_y = other->v_y;
94       v_z = other->v_z;
95       v_scalar = other->v_scalar;
96       gc_ass = other->gc_ass;
97       gc_x   = other->gc_x;
98       gc_y   = other->gc_y;
99       gc_z   = other->gc_z;
100       }
101    else 
102       {
103       v_x  = v_y  = v_z  = 0;
104       gc_x = gc_y = gc_z = 0;
105       v_scalar = 0;
106       gc_ass = false;
107       }
108 }
109 // ===================================================== getCoord
110 inline double Vertex::getCoord (int dir) 
111 {
112    double val = 0;
113    switch (dir)
114           {
115           case dir_x : val = v_x; 
116                break;
117           case dir_y : val = v_y; 
118                break;
119           case dir_z : val = v_z; 
120                break;
121           }
122    return val;
123 }
124 // ========================================================= dump 
125 inline void Vertex::dump ()
126 {
127    printName (" = ");
128    if (NOT isHere ())
129       {
130       printf ("(*** deleted ***)\n");
131       return;
132       }
133
134    printf ("(%g, %g, %g)", v_x,v_y,v_z);
135    dumpRef ();
136 }
137 // ========================================================= setCoord 
138 inline void Vertex::setCoord (double x, double y, double z)
139 {
140    v_x = x;
141    v_y = y;
142    v_z = z;
143 }
144 // ========================================================= assoCoord 
145 inline void Vertex::assoCoord (double* coord)
146 {
147    assoCoord (coord[dir_x], coord[dir_y], coord[dir_z]);
148 }
149 // ========================================================= assoCoord 
150 inline void Vertex::assoCoord (double x, double y, double z)
151 {
152    gc_ass = true;
153    gc_x = x;
154    gc_y = y;
155    gc_z = z;
156 }
157 // ========================================================= isin 
158 inline bool Vertex::isin  (double xmin, double xmax, double ymin, double ymax, 
159                                              double zmin, double zmax)
160 {
161    bool   rep =   v_x >= xmin && v_x <= xmax
162                && v_y >= ymin && v_y <= ymax
163                && v_z >= zmin && v_z <= zmax;
164    return rep;
165 }
166 // ========================================================= getPoint
167 inline double* Vertex::getPoint (double point[])
168 {
169    point [dir_x] = v_x;
170    point [dir_y] = v_y;
171    point [dir_z] = v_z;
172    return point;
173 }
174 // ========================================================= duplicate 
175 inline void Vertex::duplicate (Document* cible)
176 {
177    v_clone = new Vertex (cible, v_x, v_y, v_z);
178    v_clone->v_scalar = v_scalar;
179 }
180 // ========================================================= duplicate 
181 inline bool Vertex::definedBy (double px, double py, double pz, double eps2)
182 {
183    double dist2 = carre (v_x-px) + carre (v_y-py) + carre (v_z-pz);
184    return dist2 < eps2;
185 }
186 END_NAMESPACE_HEXA
187 #endif