b311480e |
1 | // Created on: 2002-07-18 |
2 | // Created by: QA Admin |
973c2be1 |
3 | // Copyright (c) 2002-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
b311480e |
15 | |
1cd84fee |
16 | #include <QABugs.hxx> |
7fd59977 |
17 | |
91322f44 |
18 | #include <Draw.hxx> |
7fd59977 |
19 | #include <Draw_Interpretor.hxx> |
20 | #include <DBRep.hxx> |
21 | #include <DrawTrSurf.hxx> |
22 | #include <AIS_InteractiveContext.hxx> |
23 | #include <ViewerTest.hxx> |
24 | #include <AIS_Shape.hxx> |
25 | #include <TopoDS_Shape.hxx> |
26 | #include <TopoDS_Vertex.hxx> |
27 | |
28 | #include <TopExp_Explorer.hxx> |
29 | #include <TopoDS_Face.hxx> |
30 | #include <TopoDS.hxx> |
31 | #include <BRepBndLib.hxx> |
32 | #include <gp_Pln.hxx> |
33 | #include <BRep_Tool.hxx> |
34 | #include <BRepAlgoAPI_Section.hxx> |
35 | #include <BRepAlgo_Section.hxx> |
b9c1e440 |
36 | #include <BRepMesh_IncrementalMesh.hxx> |
7fd59977 |
37 | #include <Precision.hxx> |
38 | #include <Standard_ErrorHandler.hxx> |
39 | |
40 | #include <stdio.h> |
41 | |
42 | //======================================================================= |
43 | //function : OCC527 |
44 | //purpose : |
45 | //======================================================================= |
46 | static Standard_Integer OCC527(Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
47 | { |
48 | try |
49 | { |
50 | OCC_CATCH_SIGNALS |
51 | // 1. Verify amount of arguments of the command |
52 | //if (argc < 2) { di << "OCC527 FAULTY. Use : OCC527 shape "; return 0;} |
53 | if (argc < 2 || argc > 3) { |
586db386 |
54 | di << "Usage : " << argv[0] << " shape [BRepAlgoAPI/BRepAlgo = 1/0]\n"; |
7fd59977 |
55 | return 1; |
56 | } |
57 | Standard_Boolean IsBRepAlgoAPI = Standard_True; |
58 | if (argc == 3) { |
91322f44 |
59 | Standard_Integer IsB = Draw::Atoi(argv[2]); |
7fd59977 |
60 | if (IsB != 1) { |
61 | IsBRepAlgoAPI = Standard_False; |
62 | //#if ! defined(BRepAlgo_def04) |
586db386 |
63 | // di << "Error: There is not BRepAlgo_Section class\n"; |
7fd59977 |
64 | // return 1; |
65 | //#endif |
66 | } |
67 | } |
68 | |
69 | // 2. Get selected shape |
70 | TopoDS_Shape aShape = DBRep::Get(argv[1]); |
71 | if(aShape.IsNull()) { di << "OCC527 FAULTY. Entry shape is NULL"; return 0;} |
72 | |
73 | // 3. Explode entry shape on faces and build sections from Zmin to Zmax with step aStep |
74 | const Standard_Real Zmin = -40.228173882121, Zmax = 96.408126285268, aStep = 1.0; |
91322f44 |
75 | char str[100]; str[0] = 0; Sprintf(str,"Test range: [%f, %f] with step %f\n",Zmin,Zmax,aStep); di << str; |
7fd59977 |
76 | int nbf = 0; |
77 | TopExp_Explorer aExp1; |
78 | for (aExp1.Init(aShape,TopAbs_FACE); aExp1.More(); aExp1.Next()) |
79 | { |
80 | // Process one face |
91322f44 |
81 | str[0] = 0; Sprintf(str,"Face #%d: \t",nbf++); di << str; |
7fd59977 |
82 | TopoDS_Face aFace = TopoDS::Face(aExp1.Current()); |
83 | |
84 | // Build BndBox in order to avoid try of building section |
85 | // if plane of the one does not intersect BndBox of the face |
86 | Bnd_Box aFaceBox; |
87 | BRepBndLib::Add(aFace,aFaceBox); |
88 | Standard_Real X1,X2,Y1,Y2,Z1,Z2; |
89 | aFaceBox.Get(X1,Y1,Z1,X2,Y2,Z2); |
90 | |
91 | // Build sections from Zmin to Zmax with step aStep |
7fd59977 |
92 | double gmaxdist = 0.0, gzmax = Zmax; |
93 | for (double zcur = Zmax; zcur > Zmin; zcur -= aStep) |
94 | { |
95 | // If plane of the section does not intersect BndBox of the face do nothing |
96 | if(zcur < Z1 || zcur > Z2 ) continue; |
97 | |
98 | // Build current section |
99 | gp_Pln pl(0,0,1,-zcur); |
100 | //#if ! defined(BRepAlgoAPI_def01) |
101 | // BRepAlgoAPI_Section aSection(aFace,pl,Standard_False); |
102 | //#else |
103 | // BRepAlgo_Section aSection(aFace,pl,Standard_False); |
104 | //#endif |
105 | // aSection.Approximation(Standard_True); |
106 | // aSection.Build(); |
107 | // // If section was built meassure distance between vertexes and plane of the one. Max distance is stored. |
108 | // if (aSection.IsDone()) |
109 | |
110 | Standard_Boolean IsDone; |
111 | TopoDS_Shape aResult; |
112 | if (IsBRepAlgoAPI) { |
586db386 |
113 | di << "BRepAlgoAPI_Section aSection(aFace,pl,Standard_False)\n"; |
7fd59977 |
114 | BRepAlgoAPI_Section aSection(aFace,pl,Standard_False); |
115 | aSection.Approximation(Standard_True); |
116 | aSection.Build(); |
117 | IsDone = aSection.IsDone(); |
118 | aResult = aSection.Shape(); |
119 | } else { |
586db386 |
120 | di << "BRepAlgo_Section aSection(aFace,pl,Standard_False)\n"; |
7fd59977 |
121 | BRepAlgo_Section aSection(aFace,pl,Standard_False); |
122 | aSection.Approximation(Standard_True); |
123 | aSection.Build(); |
124 | IsDone = aSection.IsDone(); |
125 | aResult = aSection.Shape(); |
126 | } |
127 | |
128 | if (IsDone) |
129 | { |
130 | // TopoDS_Shape aResult = aSection.Shape(); |
131 | if (!aResult.IsNull()) |
132 | { |
133 | double lmaxdist = 0.0; |
7fd59977 |
134 | TopExp_Explorer aExp2; |
135 | for (aExp2.Init(aResult,TopAbs_VERTEX); aExp2.More(); aExp2.Next()) |
136 | { |
137 | TopoDS_Vertex aV = TopoDS::Vertex(aExp2.Current()); |
138 | Standard_Real toler = BRep_Tool::Tolerance(aV); |
139 | double dist = pl.Distance(BRep_Tool::Pnt(aV)); |
140 | if (dist > lmaxdist) lmaxdist = dist; |
7fd59977 |
141 | // If section was built check distance beetwen vertexes and plane of the one |
142 | str[0] =0; |
143 | // if (wasBuilt) |
144 | // { |
145 | // if(gmaxdist > Precision::Confusion()) |
91322f44 |
146 | // Sprintf(str,"Dist=%f, Param=%f FAULTY\n",gmaxdist,gzmax); |
7fd59977 |
147 | // else |
91322f44 |
148 | // Sprintf(str,"Dist=%f, Param=%f\n",gmaxdist,gzmax); |
7fd59977 |
149 | if(dist > toler) |
91322f44 |
150 | Sprintf(str,"Dist=%f, Toler=%f, Param=%f FAULTY\n",dist,toler,gzmax); |
7fd59977 |
151 | else |
91322f44 |
152 | Sprintf(str,"Dist=%f, Toler=%f, Param=%f\n",dist,toler,gzmax); |
7fd59977 |
153 | // } |
91322f44 |
154 | // else Sprintf(str,"No result\n"); |
7fd59977 |
155 | di << str; |
156 | } |
157 | if (lmaxdist > gmaxdist) |
158 | { |
159 | gmaxdist = lmaxdist; |
160 | gzmax = zcur; |
161 | } |
162 | } |
163 | } |
164 | } |
165 | } |
166 | } |
167 | catch (Standard_Failure) {di << "OCC527 Exception \n" ;return 0;} |
168 | |
169 | return 0; |
170 | } |
171 | |
172 | #include <StlMesh_Mesh.hxx> |
173 | #include <StlTransfer.hxx> |
174 | //======================================================================= |
175 | //function : OCC1048 |
176 | //purpose : |
177 | //======================================================================= |
178 | static Standard_Integer OCC1048 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
179 | { |
180 | // Verify amount of arguments of the command |
181 | if (argc < 2) { di << "Usage : " << argv[0] <<" shape"; return 1;} |
182 | |
183 | TopoDS_Shape aShape = DBRep::Get(argv[1]); |
184 | |
185 | Standard_Real theDeflection = 0.006; |
186 | Handle(StlMesh_Mesh) theStlMesh = new StlMesh_Mesh; |
b9c1e440 |
187 | BRepMesh_IncrementalMesh aMesh(aShape, theDeflection); |
188 | StlTransfer::RetrieveMesh(aShape, theStlMesh); |
7fd59977 |
189 | Standard_Integer NBTRIANGLES = theStlMesh->NbTriangles(); |
190 | di<<"Info: Number of triangles = "<<NBTRIANGLES<<"\n"; |
191 | |
192 | return 0; |
193 | } |
194 | |
1cd84fee |
195 | void QABugs::Commands_2(Draw_Interpretor& theCommands) { |
1365140b |
196 | const char *group = "QABugs"; |
7fd59977 |
197 | |
198 | //theCommands.Add("OCC527", "OCC527 shape", __FILE__, OCC527, group); |
199 | theCommands.Add("OCC527", "OCC527 shape [BRepAlgoAPI/BRepAlgo = 1/0]", __FILE__, OCC527, group); |
200 | theCommands.Add("OCC1048", "OCC1048 shape", __FILE__, OCC1048, group); |
201 | return; |
202 | } |