Salome HOME
3ad008aed45ad0bf628bd319c49ffc1310362462
[modules/geom.git] / src / GEOMImpl / GEOMImpl_Block6Explorer.hxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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 //  File   : GEOMImpl_Block6Explorer.hxx
23 //  Module : GEOMImpl
24 //
25 #ifndef GEOMImpl_Block6Explorer_HeaderFile
26 #define GEOMImpl_Block6Explorer_HeaderFile
27
28 #include <TopoDS_Shape.hxx>
29 #include <TopoDS_Wire.hxx>
30 #include <TopTools_Array1OfShape.hxx>
31 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
32 #include <gp_Trsf.hxx>
33
34   //  Class GEOMImpl_Block6Explorer gives easy and fast access to a certain sub-elements of hexahedral solid
35   //  Each face   can be accessed by its global ID [1-6]
36   //  Each edge   can be accessed by its global ID [1-12] or by its local NB [1-4] inside certain face
37   //  Each vertex can be accessed by its global ID [1-8] or  by its local NB [1-4] inside certain face
38   //  Numeration of the sub-shapes is defined in constructors, see they comments
39   //
40   //                  face 2       face 4          |           4 face     2 face                   |
41   //                       |           /           |            \         |                        |
42   //                      \|/        |/_           |            _\|      \|/                       |
43   //                       '         '             |              '       '                        |
44   //                    8_______7__7               |               7__7_______8                    |
45   //                   /|         /|               |               |\         |\                   |
46   //                  8 12       6 11              |              11 6       12 8                  |
47   //                 /  |       /  |               |               |  \       |  \                 |
48   //               5/______5__6/   |               |               |   \6__5______\5               |
49   //  face 5 --->  |    |     |    |  <--- 6 face  |  face 6 --->  |    |     |    |  <--- 5 face  |
50   //               |    |__3__|____|               |               |____|__3__|    |               |
51   //               |   /4     |   /3               |               3\   |     4\   |               |
52   //               |  /       |  /                 |                 \  |       \  |               |
53   //               9 4       10 2                  |                  2 10       4 9               |
54   //               |/__1______|/                   |                   \|______1__\|               |
55   //               1          2                    |                    2          1               |
56   //            _.        .                        |                        .       ._             |
57   //            /|       /|\                       |                       /|\      |\             |
58   //           /          |                        |                        |         \            |
59   //          3 face      1 face                   |                   face 1     face 3           |
60   //                                               |                                               |
61   //  Picture 1 (right orientation)                |  Picture 2 (left orientation)                 |
62   //                                                                                               |
63   //  For the moment, the orientation of numbering is not controlled
64
65   // Faces: 1 - bottom, 2 - top, 3 - front, 4 - back, 5 - left (right), 6 - right (left)
66
67   //
68   //                             4_______3__3         2 ______2__3
69   //                            /          /          |          |
70   //                           4          2           1          3
71   //                          /          /            |          |
72   //                        1/______1__2/             |          |
73   //                                                  |          |
74   //                                                  | __4______|
75   //                           face 2       face 4    1          4
76   //                                |           /
77   //                               \|/        |/_
78   //                                '         '
79   //        3                    8_______7__7                    3
80   //       /|                   /|         /|                   /|
81   //      3 2                  8 12       6 11                 3 2
82   //     /  |                 /  |       /  |                 /  |
83   //   4/   |               5/______5__6/   |               4/   |
84   //   |    |  face 5 --->  |    |     |    |  <--- 6 face  |    |
85   //   |    |               |    |__3__|____|               |    |
86   //   |   /2               |   /4     |   /3               |   /2
87   //   |  /                 |  /       |  /                 |  /
88   //   4 1                  9 4       10 2                  4 1
89   //   |/                   |/__1______|/                   |/
90   //   1                    1          2                    1
91   //                     _.        .
92   //                     /|       /|\
93   //                    /          |
94   //   2 ______2__3    3 face      1 face
95   //   |          |
96   //   |          |               __3_______
97   //   |          |             /4         /3
98   //   |          |            /          /
99   //   1          3           4          2
100   //   | __4______|          /__1______ /
101   //   1          4         1          2
102   //
103   //  Picture 3 (On periferal pictures the local
104   //  numeration of edges and vertices is shown)
105
106 class GEOMImpl_Block6Explorer
107 {
108  public:
109   // ---------- PUBLIC METHODS ----------
110
111   GEOMImpl_Block6Explorer ();
112   // Constructor.
113
114   // Initialization by existing solid,
115   // sub-elements regulate numeration
116
117   void InitByBlock (const TopoDS_Shape& theBlock);
118   // Init by hexahedral solid. First face, edge and vertex is defined randomly
119
120   void InitByBlockAndFace (const TopoDS_Shape& theBlock,
121                            const TopoDS_Shape& theFace);
122   // Constructor from hexahedral solid, making theFace the first face.
123   // First edge and vertex is defined randomly from theFace entities
124
125   void InitByBlockAndEdges (const TopoDS_Shape& theBlock,
126                             const TopoDS_Shape& theEdge1,
127                             const TopoDS_Shape& theEdge2);
128   // Init by hexahedral solid, making theEdge1 the first, theEdge2 the fird.
129   // First vertex is defined randomly from theEdge1 vertices
130   // (Picture 1 and Picture 2 shows two possible cases)
131
132   void InitByBlockAndVertices (const TopoDS_Shape& theBlock,
133                                const TopoDS_Shape& theVertex1,
134                                const TopoDS_Shape& theVertex2,
135                                const TopoDS_Shape& theVertex3);
136   // Init by hexahedral solid, making theVertex1 the first,
137   // theVertex2 the second and theVertex3 the fird vertices.
138
139   // Initialization by parts of solid to be built
140
141   void InitByTwoFaces (const TopoDS_Shape& theFace1,
142                        const TopoDS_Shape& theFace2);
143   // Init by two faces. TheFace1 will be the first,
144   // theFace2 will be the second.
145   // First edge and vertex is defined randomly from theFace1 entities.
146
147   // Access to vertices
148   TopoDS_Shape GetVertex (const Standard_Integer theVertexID); // [1-8]
149
150   Standard_Integer GetVertexID (const TopoDS_Shape& theVertex);
151
152   Standard_Integer GetVertexID (const Standard_Integer theFaceID, // [1-6]
153                                 const Standard_Integer theVertexNB); // [1-4]
154
155   Standard_Integer GetVertexOnEdgeID (const Standard_Integer theEdgeID, // [1-12]
156                                       const Standard_Integer theVertexNB); // [1-2]
157
158   // Access to edges
159   TopoDS_Shape GetEdge (const Standard_Integer theEdgeID, // [1-12]
160                         const Standard_Boolean doMake = Standard_False);
161
162   Standard_Integer GetEdgeID (const TopoDS_Shape& theEdge);
163
164   Standard_Integer GetEdgeID (const Standard_Integer theFaceID, // [1-6]
165                               const Standard_Integer theEdgeNB); // [1-4]
166
167   Standard_Integer FindEdgeID (const Standard_Integer theVertex1ID,
168                                const Standard_Integer theVertex2ID);
169
170   Standard_Integer FindCommonEdgeID (const Standard_Integer theFace1ID,
171                                      const Standard_Integer theFace2ID);
172
173   // Access to faces
174   TopoDS_Shape GetFace (const Standard_Integer theFaceID, // [1-6]
175                         const Standard_Boolean doMake = Standard_False);
176
177   Standard_Integer GetFaceID (const TopoDS_Shape& theFace);
178
179   Standard_Integer FindFaceID (const Standard_Integer theEdge1ID,
180                                const Standard_Integer theEdge2ID);
181
182   Standard_Integer GetOppositeFaceID (const Standard_Integer theFaceID);
183
184   // Check Block
185   Standard_Boolean IsSimilarFaces (const Standard_Integer theFace1ID,
186                                    const Standard_Integer theFace2ID,
187                                    const gp_Trsf          theTransformation);
188   // returns true, if theFace1, transformed
189   // by theTransformation, coincides with theFace2
190  public:
191   // ---------- STATIC PUBLIC METHODS ----------
192   static void MapShapesAndAncestors (const TopoDS_Shape& S,
193                                      const TopAbs_ShapeEnum TS,
194                                      const TopAbs_ShapeEnum TA,
195                                      TopTools_IndexedDataMapOfShapeListOfShape& M);
196
197   static Standard_Boolean IsSimilarEdges (const TopoDS_Shape& E1, 
198                                           const TopoDS_Shape& E2);
199
200   static Standard_Integer FindEdge (TopoDS_Shape&       theResult,
201                                     const TopoDS_Shape& V1,
202                                     const TopoDS_Shape& V2,
203                                     const TopTools_IndexedDataMapOfShapeListOfShape& MVE,
204                                     const Standard_Boolean findAll = Standard_False);
205   // returns number of found edges
206
207   static Standard_Integer FindFace (TopoDS_Shape&       theResult,
208                                     const TopoDS_Shape& V1,
209                                     const TopoDS_Shape& V2,
210                                     const TopoDS_Shape& V3,
211                                     const TopoDS_Shape& V4,
212                                     const TopTools_IndexedDataMapOfShapeListOfShape& MVF,
213                                     const Standard_Boolean findAll = Standard_False);
214   // returns number of found faces
215
216   static void MakeFace (const TopoDS_Wire&     theWire,
217                         const Standard_Boolean isPlanarWanted,
218                         TopoDS_Shape&          theResult);
219
220  private:
221   // ---------- PRIVATE FIELDS ----------
222
223   TopTools_Array1OfShape myFaces;
224   TopTools_Array1OfShape myEdges;
225   TopTools_Array1OfShape myVertices;
226 };
227
228 #endif