b311480e |
1 | // Created on: 1999-02-25 |
2 | // Created by: Pavel DURANDIN |
3 | // Copyright (c) 1999-1999 Matra Datavision |
4 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
5 | // |
6 | // The content of this file is subject to the Open CASCADE Technology Public |
7 | // License Version 6.5 (the "License"). You may not use the content of this file |
8 | // except in compliance with the License. Please obtain a copy of the License |
9 | // at http://www.opencascade.org and read it completely before using this file. |
10 | // |
11 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
12 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
13 | // |
14 | // The Original Code and all software distributed under the License is |
15 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
16 | // Initial Developer hereby disclaims all such warranties, including without |
17 | // limitation, any warranties of merchantability, fitness for a particular |
18 | // purpose or non-infringement. Please see the License for the specific terms |
19 | // and conditions governing the rights and limitations under the License. |
20 | |
7fd59977 |
21 | //szv#4 S4163 |
22 | |
23 | #include <ShapeAnalysis_ShapeContents.ixx> |
24 | #include <ShapeExtend_WireData.hxx> |
25 | #include <ShapeAnalysis_Wire.hxx> |
26 | #include <TopExp_Explorer.hxx> |
27 | #include <TopTools_MapOfShape.hxx> |
28 | #include <TopoDS_Solid.hxx> |
29 | #include <TopoDS.hxx> |
30 | #include <BRep_Tool.hxx> |
31 | #include <Geom_RectangularTrimmedSurface.hxx> |
32 | #include <Geom_Surface.hxx> |
33 | #include <Geom_BSplineSurface.hxx> |
34 | #include <Geom_ElementarySurface.hxx> |
35 | #include <Geom_OffsetSurface.hxx> |
36 | #include <Geom_BezierSurface.hxx> |
37 | #include <TopoDS_Wire.hxx> |
38 | #include <TopoDS_Edge.hxx> |
39 | #include <Geom_TrimmedCurve.hxx> |
40 | #include <Geom_Curve.hxx> |
41 | #include <Geom2d_Curve.hxx> |
42 | #include <Geom2d_OffsetCurve.hxx> |
43 | #include <Geom2d_TrimmedCurve.hxx> |
44 | #include <Geom_OffsetCurve.hxx> |
45 | #include <TopTools_HSequenceOfShape.hxx> |
46 | #include <TopoDS_Shell.hxx> |
47 | #include <TopoDS_Vertex.hxx> |
48 | |
49 | |
50 | |
51 | |
52 | ShapeAnalysis_ShapeContents::ShapeAnalysis_ShapeContents() |
53 | { |
54 | myBigSplineSec = new TopTools_HSequenceOfShape; |
55 | myIndirectSec = new TopTools_HSequenceOfShape; |
56 | myOffsetSurfaceSec = new TopTools_HSequenceOfShape; |
57 | myTrimmed3dSec = new TopTools_HSequenceOfShape; |
58 | myOffsetCurveSec = new TopTools_HSequenceOfShape; |
59 | myTrimmed2dSec = new TopTools_HSequenceOfShape; |
60 | ClearFlags(); |
61 | } |
62 | |
63 | void ShapeAnalysis_ShapeContents::Clear() |
64 | { |
65 | myNbSolids = 0; |
66 | myNbShells = 0; |
67 | myNbFaces = 0; |
68 | myNbWires = 0; |
69 | myNbEdges = 0; |
70 | myNbVertices = 0; |
71 | myNbSolidsWithVoids = 0; |
72 | myNbBigSplines = 0; |
73 | myNbC0Surfaces = 0; |
74 | myNbC0Curves = 0; |
75 | myNbOffsetSurf = 0; |
76 | myNbIndirectSurf = 0; |
77 | myNbOffsetCurves = 0; |
78 | myNbTrimmedCurve2d = 0; |
79 | myNbTrimmedCurve3d =0; |
80 | myNbBSplibeSurf = 0; |
81 | myNbBezierSurf = 0; |
82 | myNbTrimSurf = 0; |
83 | myNbWireWitnSeam = 0; |
84 | myNbWireWithSevSeams = 0; |
85 | myNbFaceWithSevWires = 0; |
86 | myNbNoPCurve = 0; |
87 | myNbFreeFaces = 0; |
88 | myNbFreeWires = 0; |
89 | myNbFreeEdges = 0; |
90 | |
91 | myNbSharedSolids = 0; |
92 | myNbSharedShells = 0; |
93 | myNbSharedFaces = 0; |
94 | myNbSharedWires = 0; |
95 | myNbSharedFreeWires = 0; |
96 | myNbSharedFreeEdges = 0; |
97 | myNbSharedEdges = 0; |
98 | myNbSharedVertices = 0; |
99 | |
100 | myBigSplineSec->Clear(); |
101 | myIndirectSec->Clear(); |
102 | myOffsetSurfaceSec->Clear(); |
103 | myTrimmed3dSec->Clear(); |
104 | myOffsetCurveSec->Clear(); |
105 | myTrimmed2dSec->Clear(); |
106 | } |
107 | |
108 | |
109 | void ShapeAnalysis_ShapeContents::ClearFlags() |
110 | { |
111 | myBigSplineMode = Standard_False; |
112 | myIndirectMode = Standard_False; |
113 | myOffestSurfaceMode = Standard_False; |
114 | myTrimmed3dMode = Standard_False; |
115 | myOffsetCurveMode = Standard_False; |
116 | myTrimmed2dMode = Standard_False; |
117 | } |
118 | |
119 | |
120 | void ShapeAnalysis_ShapeContents::Perform(const TopoDS_Shape& Shape) |
121 | { |
122 | Clear(); |
123 | // On y va |
124 | TopExp_Explorer exp; |
125 | TopTools_MapOfShape mapsh; |
126 | // On note pour les SOLIDES : ceux qui ont des trous (plus d un SHELL) |
127 | |
128 | for (exp.Init (Shape,TopAbs_SOLID); exp.More(); exp.Next()) { |
129 | TopoDS_Solid sol = TopoDS::Solid (exp.Current()); |
130 | sol.Location(TopLoc_Location()); |
131 | mapsh.Add(sol); |
132 | Standard_Integer nbs = 0; |
133 | for (TopExp_Explorer shel (sol,TopAbs_SHELL); shel.More(); shel.Next()) |
134 | nbs ++; |
135 | if (nbs > 1) myNbSolidsWithVoids++; |
136 | myNbSolids++; |
137 | } |
138 | myNbSharedSolids = mapsh.Extent(); |
139 | |
140 | // Pour les SHELLS, on compte les faces dans les SHELLS |
141 | // Ensuite une soustraction, et on a les faces libres |
142 | mapsh.Clear(); |
143 | Standard_Integer nbfaceshell = 0; |
144 | for (exp.Init (Shape,TopAbs_SHELL); exp.More(); exp.Next()) { |
145 | myNbShells++; |
146 | TopoDS_Shell she = TopoDS::Shell(exp.Current()); |
147 | she.Location(TopLoc_Location()); |
148 | mapsh.Add(she); |
149 | for (TopExp_Explorer shel (she,TopAbs_FACE); shel.More(); shel.Next()) |
150 | nbfaceshell ++; |
151 | } |
152 | myNbSharedShells = mapsh.Extent(); |
153 | // On note pour les FACES pas mal de choses (surface, topologie) |
154 | // * Surface BSpline > 8192 poles |
155 | // * Surface BSpline "OnlyC0" (not yet impl) |
156 | // * Surface Offset |
157 | // * Surface Elementaire INDIRECTE |
158 | // * Presence de COUTURES; en particulier WIRE A PLUS D UNE COUTURE |
159 | // * Edge : OffsetCurve |
160 | |
161 | mapsh.Clear(); |
162 | for (exp.Init (Shape,TopAbs_FACE); exp.More(); exp.Next()) { |
163 | TopoDS_Face face = TopoDS::Face(exp.Current()); |
164 | myNbFaces++; |
165 | TopLoc_Location loc; |
166 | Handle(Geom_Surface) surf = BRep_Tool::Surface (face,loc); |
167 | face.Location(TopLoc_Location()); |
168 | mapsh.Add(face); |
169 | Handle(Geom_RectangularTrimmedSurface) trsu = |
170 | Handle(Geom_RectangularTrimmedSurface)::DownCast (surf); |
171 | if (!trsu.IsNull()) { |
172 | myNbTrimSurf++; |
173 | surf = trsu->BasisSurface(); |
174 | } |
175 | //#10 rln 27/02/98 BUC50003 entity 56 |
176 | //C0 if at least in one direction (U or V) |
177 | if (!surf.IsNull() && !(surf->IsCNu(1) && surf->IsCNv(1))) { |
178 | myNbC0Surfaces++; |
179 | } |
180 | |
181 | Handle(Geom_BSplineSurface) bsps = Handle(Geom_BSplineSurface)::DownCast(surf); |
182 | if (!bsps.IsNull()) { |
183 | myNbBSplibeSurf++; |
184 | if (bsps->NbUPoles() * bsps->NbVPoles() > 8192) { |
185 | myNbBigSplines++; |
186 | if (myBigSplineMode) myBigSplineSec->Append(face); |
187 | } |
188 | } |
189 | Handle(Geom_ElementarySurface) els = Handle(Geom_ElementarySurface)::DownCast(surf); |
190 | if (!els.IsNull()) { |
191 | if (!els->Position().Direct()) { |
192 | myNbIndirectSurf++; |
193 | if (myIndirectMode) myIndirectSec->Append(face); |
194 | } |
195 | } |
196 | if (surf->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) { |
197 | myNbOffsetSurf++; |
198 | if (myOffestSurfaceMode) myOffsetSurfaceSec->Append(face); |
199 | } |
200 | else if (surf->IsKind(STANDARD_TYPE(Geom_BezierSurface))) { |
201 | myNbBezierSurf++; |
202 | } |
203 | |
204 | Standard_Integer maxseam = 0, nbwires = 0; |
205 | for (TopExp_Explorer wires(face,TopAbs_WIRE); wires.More(); wires.Next()) { |
206 | TopoDS_Wire wire = TopoDS::Wire (wires.Current()); |
207 | Standard_Integer nbseam = 0; |
208 | nbwires ++; |
209 | for (TopExp_Explorer edg(wire,TopAbs_EDGE); edg.More(); edg.Next()) { |
210 | TopoDS_Edge edge = TopoDS::Edge (edg.Current()); |
211 | Standard_Real first,last; |
212 | if (BRep_Tool::IsClosed (edge,face)) nbseam ++; |
213 | Handle(Geom_Curve) c3d = BRep_Tool::Curve (edge,first,last); |
214 | if (!c3d.IsNull()) { |
215 | if (c3d->IsKind (STANDARD_TYPE(Geom_TrimmedCurve))) { |
216 | myNbTrimmedCurve3d++; |
217 | if (myTrimmed3dMode) myTrimmed3dSec->Append(face); |
218 | } |
219 | } |
220 | Handle(Geom2d_Curve) c2d = BRep_Tool::CurveOnSurface (edge,face,first,last); |
221 | if (c2d.IsNull()) myNbNoPCurve++; |
222 | else if (c2d->IsKind (STANDARD_TYPE(Geom2d_OffsetCurve))) { |
223 | myNbOffsetCurves++; |
224 | if (myOffsetCurveMode) myOffsetCurveSec->Append(face); |
225 | } |
226 | else if (c2d->IsKind (STANDARD_TYPE(Geom2d_TrimmedCurve))) { |
227 | myNbTrimmedCurve2d++; |
228 | if (myTrimmed2dMode) myTrimmed2dSec->Append(face); |
229 | } |
230 | } |
231 | if (nbseam > maxseam) maxseam = nbseam; |
232 | } |
233 | if (maxseam == 1) myNbWireWitnSeam++; |
234 | else if (maxseam > 1) |
235 | myNbWireWithSevSeams++; |
236 | if (nbwires > 1) myNbFaceWithSevWires++; |
237 | } |
238 | myNbSharedFaces = mapsh.Extent(); |
239 | |
240 | mapsh.Clear(); |
241 | for (exp.Init (Shape,TopAbs_WIRE); exp.More(); exp.Next()) { |
242 | TopoDS_Wire wire = TopoDS::Wire(exp.Current()); |
243 | wire.Location(TopLoc_Location()); |
244 | mapsh.Add(wire); |
245 | myNbWires++; |
246 | } |
247 | myNbSharedWires = mapsh.Extent(); |
248 | |
249 | // Ne pas oublier les FACES : |
250 | myNbFreeFaces = myNbFaces - nbfaceshell; |
251 | |
252 | mapsh.Clear(); |
253 | for (exp.Init (Shape,TopAbs_EDGE); exp.More(); exp.Next()) { |
254 | TopoDS_Edge edge = TopoDS::Edge (exp.Current()); |
255 | edge.Location(TopLoc_Location()); |
256 | mapsh.Add (edge); |
257 | TopLoc_Location loc; |
258 | Standard_Real first,last; |
259 | myNbEdges++; |
260 | Handle(Geom_Curve) c3d = BRep_Tool::Curve (edge,loc,first,last); |
261 | if (!c3d.IsNull() && c3d->IsKind(STANDARD_TYPE(Geom_OffsetCurve))) { |
262 | myNbOffsetCurves++; |
263 | if (myOffsetCurveMode) myOffsetCurveSec->Append(edge); |
264 | } |
265 | if (!c3d.IsNull() && !c3d->IsCN(1)) myNbC0Curves++; |
266 | } |
267 | myNbSharedEdges=mapsh.Extent(); |
268 | |
269 | mapsh.Clear(); |
270 | for (exp.Init (Shape,TopAbs_VERTEX); exp.More(); exp.Next()) { |
271 | TopoDS_Vertex vert = TopoDS::Vertex(exp.Current()); |
272 | vert.Location(TopLoc_Location()); |
273 | myNbVertices++; |
274 | mapsh.Add (vert); |
275 | } |
276 | myNbSharedVertices=mapsh.Extent(); |
277 | |
278 | mapsh.Clear(); |
279 | for (exp.Init(Shape, TopAbs_EDGE, TopAbs_FACE); exp.More(); exp.Next()) { |
280 | TopoDS_Edge edge = TopoDS::Edge (exp.Current()); |
281 | edge.Location(TopLoc_Location()); |
282 | myNbFreeEdges++; |
283 | mapsh.Add (edge); |
284 | } |
285 | myNbSharedFreeEdges=mapsh.Extent(); |
286 | |
287 | mapsh.Clear(); |
288 | for (exp.Init(Shape, TopAbs_WIRE, TopAbs_FACE); exp.More(); exp.Next()) { |
289 | TopoDS_Wire wire = TopoDS::Wire(exp.Current()); |
290 | wire.Location(TopLoc_Location()); |
291 | myNbFreeWires++; |
292 | mapsh.Add (wire); |
293 | } |
294 | myNbSharedFreeWires=mapsh.Extent(); |
295 | } |