Salome HOME
23104: EDF SMESH: Pre-study for Netgen 5x
[plugins/netgenplugin.git] / src / NETGEN / netgen53ForSalome.patch
1 diff -NaurwB netgen-5.3.1_orig/Makefile.am netgen-5.3.1_new/Makefile.am
2 --- netgen-5.3.1_orig/Makefile.am       2016-10-21 17:32:01.000000000 +0300
3 +++ netgen-5.3.1_new/Makefile.am        2016-10-21 17:31:54.000000000 +0300
4 @@ -2,7 +2,7 @@
5  
6  METASOURCES = AUTO
7  
8 -SUBDIRS = libsrc ng tutorials doc windows nglib
9 +SUBDIRS = libsrc nglib #tutorials doc windows nglib
10  
11  # TESTS = ng/netgen -batchmode
12  
13 diff -NaurwB netgen-5.3.1_orig/Makefile.in netgen-5.3.1_new/Makefile.in
14 --- netgen-5.3.1_orig/Makefile.in       2014-10-06 15:04:37.000000000 +0400
15 +++ netgen-5.3.1_new/Makefile.in        2016-10-03 16:17:10.164707368 +0300
16 @@ -280,7 +280,7 @@
17  top_srcdir = @top_srcdir@
18  ACLOCAL_AMFLAGS = -I m4
19  METASOURCES = AUTO
20 -SUBDIRS = libsrc ng tutorials doc windows nglib
21 +SUBDIRS = libsrc nglib #tutorials doc windows nglib
22  all: config.h
23         $(MAKE) $(AM_MAKEFLAGS) all-recursive
24  
25 diff -NaurwB netgen-5.3.1_orig/configure.ac netgen-5.3.1_new/configure.ac
26 --- netgen-5.3.1_orig/configure.ac      2014-10-06 15:00:17.000000000 +0400
27 +++ netgen-5.3.1_new/configure.ac       2016-09-29 14:34:11.957389447 +0300
28 @@ -42,8 +42,8 @@
29  
30  if test a$occon = atrue ; then
31  
32 -       AC_SUBST([OCCFLAGS], ["-DOCCGEOMETRY -I$occdir/inc -I/usr/include/opencascade"])
33 -       AC_SUBST([OCCLIBS], ["-L$occdir/lib -lTKernel -lTKGeomBase -lTKMath -lTKG2d -lTKG3d -lTKXSBase -lTKOffset -lTKFillet -lTKShHealing -lTKMesh -lTKMeshVS -lTKTopAlgo -lTKGeomAlgo -lTKBool -lTKPrim -lTKBO -lTKIGES -lTKBRep -lTKSTEPBase -lTKSTEP -lTKSTL -lTKSTEPAttr -lTKSTEP209 -lTKXDESTEP -lTKXDEIGES -lTKXCAF -lTKLCAF -lFWOSPlugin"])
34 +       AC_SUBST([OCCFLAGS], ["-DOCCGEOMETRY -I$occdir/include/opencascade"])
35 +       AC_SUBST([OCCLIBS], ["-L$occdir/lib -lTKernel -lTKGeomBase -lTKMath -lTKG2d -lTKG3d -lTKXSBase -lTKOffset -lTKFillet -lTKShHealing -lTKMesh -lTKMeshVS -lTKTopAlgo -lTKGeomAlgo -lTKBool -lTKPrim -lTKBO -lTKIGES -lTKBRep -lTKSTEPBase -lTKSTEP -lTKSTL -lTKSTEPAttr -lTKSTEP209 -lTKXDESTEP -lTKXDEIGES -lTKXCAF -lTKLCAF"])
36         AC_SUBST([OCCLIBS], ["-L$occdir/lib -lTKernel -lTKGeomBase -lTKMath -lTKG2d -lTKG3d -lTKXSBase -lTKOffset -lTKFillet -lTKShHealing -lTKMesh -lTKMeshVS -lTKTopAlgo -lTKGeomAlgo -lTKBool -lTKPrim -lTKBO -lTKIGES -lTKBRep -lTKSTEPBase -lTKSTEP -lTKSTL -lTKSTEPAttr -lTKSTEP209 -lTKXDESTEP -lTKXDEIGES -lTKXCAF -lTKLCAF -lFWOSPlugin"])
37  
38  #  -lTKDCAF
39 diff -NaurwB netgen-5.3.1_orig/libsrc/meshing/findip.hpp netgen-5.3.1_new/libsrc/meshing/findip.hpp
40 --- netgen-5.3.1_orig/libsrc/meshing/findip.hpp 2014-08-29 13:54:05.000000000 +0400
41 +++ netgen-5.3.1_new/libsrc/meshing/findip.hpp  2016-09-30 20:38:56.662234111 +0300
42 @@ -75,6 +75,9 @@
43    static int timer = NgProfiler::CreateTimer ("FindInnerPoint");
44    NgProfiler::RegionTimer reg (timer);
45  
46 +  if ( points.Size() < 3 )
47 +    return 0;
48 +
49    Array<Vec3d> a;
50    Array<double> c;
51    Mat<3> m, inv;
52 diff -NaurwB netgen-5.3.1_orig/libsrc/meshing/improve3.cpp netgen-5.3.1_new/libsrc/meshing/improve3.cpp
53 --- netgen-5.3.1_orig/libsrc/meshing/improve3.cpp       2014-08-29 13:54:05.000000000 +0400
54 +++ netgen-5.3.1_new/libsrc/meshing/improve3.cpp        2016-10-03 16:16:57.636639300 +0300
55 @@ -1219,6 +1219,7 @@
56  
57               tetused = 0;
58               tetused[0] = 1;
59 +              int nbtetused = 0;
60  
61               for (int l = 2; l < nsuround; l++)
62                 {
63 @@ -1239,10 +1240,12 @@
64                               
65                               tetused[k] = 1; 
66                               suroundpts[l] = newpi;
67 +                              ++nbtetused;
68                             }                   
69                       }
70                 }
71 -
72 +              if ( nbtetused < nsuround )
73 +                continue;
74               
75               bad1 = 0;
76               for (int k = 0; k < nsuround; k++)
77 diff -NaurwB netgen-5.3.1_orig/libsrc/meshing/meshtype.cpp netgen-5.3.1_new/libsrc/meshing/meshtype.cpp
78 --- netgen-5.3.1_orig/libsrc/meshing/meshtype.cpp       2014-08-29 13:54:05.000000000 +0400
79 +++ netgen-5.3.1_new/libsrc/meshing/meshtype.cpp        2016-09-29 14:04:51.500148293 +0300
80 @@ -1,4 +1,5 @@
81  #include <mystdlib.h>
82 +#include <float.h> // to get DBL_MIN defined
83  
84  #include "meshing.hpp"  
85  
86 @@ -666,7 +667,8 @@
87  
88          double det = trans.Det();
89  
90 -        if (det <= 0)
91 +        // if (det <= 0)
92 +        if (det <= DBL_MIN) // avoid FPE
93            err += 1e12;
94          else
95            err += frob * frob / det;
96 @@ -722,7 +724,8 @@
97  
98              double det = trans(0,0)*trans(1,1)-trans(1,0)*trans(0,1);
99  
100 -            if (det <= 0)
101 +            // if (det <= 0)
102 +            if (det <= DBL_MIN)  // avoid FPE
103                {
104                  dd = 0;
105                  return 1e12;
106 @@ -806,7 +809,8 @@
107            = dtrans(0,0) * trans(1,1) - trans(0,1) * dtrans(1,0)
108            + trans(0,0) * dtrans(1,1) - dtrans(0,1) * trans(1,0);
109  
110 -        if (det <= 0)
111 +        // if (det <= 0)
112 +        if (det <= DBL_MIN) // avoid FPE
113            err += 1e12;
114          else
115            {
116 @@ -856,7 +860,8 @@
117          frob /= 2;
118  
119          double det = trans.Det();
120 -        if (det <= 0)
121 +        //if (det <= 0)
122 +        if (det <= DBL_MIN) // avoid FPE
123            err += 1e12;
124          else
125            err += frob * frob / det;
126 @@ -1864,7 +1869,8 @@
127        case PYRAMID:
128          {
129            double noz = 1-p(2);
130 -          if (noz == 0.0) noz = 1e-10;
131 +          //if (noz == 0.0) noz = 1e-10;
132 +          if (noz <= DBL_MIN) noz = 1e-10; // avoid FPE
133  
134            double xi  = p(0) / noz;
135            double eta = p(1) / noz;
136 @@ -2030,7 +2036,8 @@
137  
138          double det = -trans.Det();
139        
140 -        if (det <= 0)
141 +        //if (det <= 0)
142 +        if (det <= DBL_MIN) // avoid FPE
143            err += 1e12;
144          else
145            err += frob * frob * frob / det;
146 @@ -2102,7 +2109,8 @@
147          ddet *= -1;
148  
149        
150 -        if (det <= 0)
151 +        //if (det <= 0)
152 +        if (det <= DBL_MIN) // avoid FPE
153            err += 1e12;
154          else
155            {
156 @@ -2184,7 +2192,7 @@
157        
158          det *= -1;
159        
160 -        if (det <= 0)
161 +        if (det <= DBL_MIN)
162            err += 1e12;
163          else
164            {
165 diff -NaurwB netgen-5.3.1_orig/libsrc/meshing/meshtype.hpp netgen-5.3.1_new/libsrc/meshing/meshtype.hpp
166 --- netgen-5.3.1_orig/libsrc/meshing/meshtype.hpp       2014-08-29 13:54:05.000000000 +0400
167 +++ netgen-5.3.1_new/libsrc/meshing/meshtype.hpp        2016-09-30 14:28:09.147575801 +0300
168 @@ -15,6 +15,7 @@
169      Classes for NETGEN
170    */
171  
172 +class Mesh; // added due to compilation errors on some platforms
173  
174  
175    enum ELEMENT_TYPE { 
176 @@ -360,7 +361,7 @@
177          {
178  #ifdef DEBUG
179            if (typ != QUAD && typ != QUAD6 && typ != QUAD8)
180 -            PrintSysError ("element2d::GetNV not implemented for typ", typ)
181 +            PrintSysError ("element2d::GetNV not implemented for typ", typ);
182  #endif
183            return 4;
184          }
185 @@ -618,7 +619,7 @@
186           return 8;
187         default:
188  #ifdef DEBUG
189 -         PrintSysError ("Element3d::GetNV not implemented for typ ", typ)
190 +         PrintSysError ("Element3d::GetNV not implemented for typ ", typ);
191  #endif
192             ;
193         }
194 @@ -682,7 +683,7 @@
195         case PRISM12: return 5;
196         default:
197  #ifdef DEBUG
198 -         PrintSysError ("element3d::GetNFaces not implemented for typ", typ)
199 +         PrintSysError ("element3d::GetNFaces not implemented for typ", typ);
200  #endif
201             ;
202         }
203 diff -NaurwB netgen-5.3.1_orig/libsrc/occ/Partition_Inter2d.cxx netgen-5.3.1_new/libsrc/occ/Partition_Inter2d.cxx
204 --- netgen-5.3.1_orig/libsrc/occ/Partition_Inter2d.cxx  2014-08-29 13:54:03.000000000 +0400
205 +++ netgen-5.3.1_new/libsrc/occ/Partition_Inter2d.cxx   2016-09-29 14:44:01.996464598 +0300
206 @@ -47,9 +47,7 @@
207  #include <TopOpeBRep_EdgesIntersector.hxx>
208  #include <TopOpeBRep_Point2d.hxx>
209  #include <TopTools_ListIteratorOfListOfShape.hxx>
210 -#include <TopTools_ListOfShape.hxx>
211  #include <TopTools_MapIteratorOfMapOfShape.hxx>
212 -#include <TopTools_MapOfShape.hxx>
213  #include <TopoDS.hxx>
214  #include <TopoDS_Edge.hxx>
215  #include <TopoDS_Vertex.hxx>
216 diff -NaurwB netgen-5.3.1_orig/libsrc/occ/Partition_Inter2d.hxx netgen-5.3.1_new/libsrc/occ/Partition_Inter2d.hxx
217 --- netgen-5.3.1_orig/libsrc/occ/Partition_Inter2d.hxx  2014-08-29 13:54:03.000000000 +0400
218 +++ netgen-5.3.1_new/libsrc/occ/Partition_Inter2d.hxx   2016-09-29 14:44:01.996464598 +0300
219 @@ -27,7 +27,9 @@
220  #ifndef _Partition_Inter2d_HeaderFile
221  #define _Partition_Inter2d_HeaderFile
222  
223 -#ifndef _Handle_BRepAlgo_AsDes_HeaderFile
224 +#include <Standard_Version.hxx>
225 +
226 +#if OCC_VERSION_MAJOR < 7
227  #include <Handle_BRepAlgo_AsDes.hxx>
228  #endif
229  #ifndef _Standard_Real_HeaderFile
230 @@ -36,11 +38,13 @@
231  #ifndef _Standard_Boolean_HeaderFile
232  #include <Standard_Boolean.hxx>
233  #endif
234 +
235 +#include <TopTools_MapOfShape.hxx>
236 +#include <TopTools_ListOfShape.hxx>
237 +
238  class BRepAlgo_AsDes;
239  class TopoDS_Face;
240 -class TopTools_MapOfShape;
241  class TopoDS_Vertex;
242 -class TopTools_ListOfShape;
243  class TopoDS_Edge;
244  
245  
246 diff -NaurwB netgen-5.3.1_orig/libsrc/occ/Partition_Inter3d.cxx netgen-5.3.1_new/libsrc/occ/Partition_Inter3d.cxx
247 --- netgen-5.3.1_orig/libsrc/occ/Partition_Inter3d.cxx  2014-08-29 13:54:03.000000000 +0400
248 +++ netgen-5.3.1_new/libsrc/occ/Partition_Inter3d.cxx   2016-09-29 14:44:02.000464619 +0300
249 @@ -48,7 +48,6 @@
250  #include <TopOpeBRepTool_BoxSort.hxx>
251  #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
252  #include <TopTools_ListIteratorOfListOfShape.hxx>
253 -#include <TopTools_ListOfShape.hxx>
254  #include <TopoDS.hxx>
255  #include <TopoDS_Compound.hxx>
256  #include <TopoDS_Edge.hxx>
257 @@ -206,7 +205,7 @@
258    Handle (Geom_Surface) S   = BRep_Tool::Surface(F,L);
259  
260    if (S->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
261 -    S = (*(Handle_Geom_RectangularTrimmedSurface*)&S)->BasisSurface();
262 +    S = Handle(Geom_RectangularTrimmedSurface)::DownCast (S)->BasisSurface();
263    }
264    if (!S->IsUPeriodic() && !S->IsVPeriodic())
265      return;
266 diff -NaurwB netgen-5.3.1_orig/libsrc/occ/Partition_Inter3d.hxx netgen-5.3.1_new/libsrc/occ/Partition_Inter3d.hxx
267 --- netgen-5.3.1_orig/libsrc/occ/Partition_Inter3d.hxx  2014-08-29 13:54:03.000000000 +0400
268 +++ netgen-5.3.1_new/libsrc/occ/Partition_Inter3d.hxx   2016-09-29 14:44:02.000464619 +0300
269 @@ -27,7 +27,9 @@
270  #ifndef _Partition_Inter3d_HeaderFile
271  #define _Partition_Inter3d_HeaderFile
272  
273 -#ifndef _Handle_BRepAlgo_AsDes_HeaderFile
274 +#include <Standard_Version.hxx>
275 +
276 +#if OCC_VERSION_MAJOR < 7
277  #include <Handle_BRepAlgo_AsDes.hxx>
278  #endif
279  #ifndef _TopTools_DataMapOfShapeListOfShape_HeaderFile
280 @@ -36,6 +38,9 @@
281  #ifndef _TopTools_MapOfShape_HeaderFile
282  #include <TopTools_MapOfShape.hxx>
283  #endif
284 +#ifndef _TopTools_ListOfShape_HeaderFile
285 +#include <TopTools_ListOfShape.hxx>
286 +#endif
287  #ifndef _TopTools_DataMapOfShapeShape_HeaderFile
288  #include <TopTools_DataMapOfShapeShape.hxx>
289  #endif
290 @@ -43,10 +48,7 @@
291  #include <Standard_Boolean.hxx>
292  #endif
293  class BRepAlgo_AsDes;
294 -class TopTools_ListOfShape;
295 -class TopTools_DataMapOfShapeShape;
296  class TopoDS_Face;
297 -class TopTools_MapOfShape;
298  class TopoDS_Shape;
299  class TopoDS_Vertex;
300  class TopoDS_Edge;
301 @@ -83,13 +85,13 @@
302     void FacesPartition(const TopoDS_Face& F1,const TopoDS_Face& F2) ;
303     Standard_Boolean IsDone(const TopoDS_Face& F1,const TopoDS_Face& F2) const;
304     TopTools_MapOfShape& TouchedFaces() ;
305 -   Handle_BRepAlgo_AsDes AsDes() const;
306 +   Handle(BRepAlgo_AsDes) AsDes() const;
307     TopTools_MapOfShape& NewEdges() ;
308     Standard_Boolean HasSameDomainF(const TopoDS_Shape& F) const;
309     Standard_Boolean IsSameDomainF(const TopoDS_Shape& F1,const TopoDS_Shape& F2) const;
310     const TopTools_ListOfShape& SameDomain(const TopoDS_Face& F) const;
311     TopoDS_Vertex ReplaceSameDomainV(const TopoDS_Vertex& V,const TopoDS_Edge& E) const;
312 -   Handle_BRepAlgo_AsDes SectionEdgesAD() const;
313 +   Handle(BRepAlgo_AsDes) SectionEdgesAD() const;
314     Standard_Boolean IsSectionEdge(const TopoDS_Edge& E) const;
315     Standard_Boolean HasSectionEdge(const TopoDS_Face& F) const;
316     Standard_Boolean IsSplitOn(const TopoDS_Edge& NewE,const TopoDS_Edge& OldE,const TopoDS_Face& F) const;
317 @@ -121,11 +123,11 @@
318  
319     // Fields PRIVATE
320     //
321 -   Handle_BRepAlgo_AsDes myAsDes;
322 +   Handle(BRepAlgo_AsDes) myAsDes;
323     TopTools_DataMapOfShapeListOfShape myDone;
324     TopTools_MapOfShape myTouched;
325     TopTools_MapOfShape myNewEdges;
326 -   Handle_BRepAlgo_AsDes mySectionEdgesAD;
327 +   Handle(BRepAlgo_AsDes) mySectionEdgesAD;
328     TopTools_DataMapOfShapeListOfShape mySameDomainFM;
329     TopTools_DataMapOfShapeShape mySameDomainVM;
330  
331 diff -NaurwB netgen-5.3.1_orig/libsrc/occ/Partition_Loop.hxx netgen-5.3.1_new/libsrc/occ/Partition_Loop.hxx
332 --- netgen-5.3.1_orig/libsrc/occ/Partition_Loop.hxx     2014-08-29 13:54:03.000000000 +0400
333 +++ netgen-5.3.1_new/libsrc/occ/Partition_Loop.hxx      2016-09-29 14:44:02.000464619 +0300
334 @@ -38,8 +38,6 @@
335  #endif
336  class TopoDS_Face;
337  class TopoDS_Edge;
338 -class TopTools_ListOfShape;
339 -
340  
341  #ifndef _Standard_HeaderFile
342  #include <Standard.hxx>
343 diff -NaurwB netgen-5.3.1_orig/libsrc/occ/Partition_Loop2d.cxx netgen-5.3.1_new/libsrc/occ/Partition_Loop2d.cxx
344 --- netgen-5.3.1_orig/libsrc/occ/Partition_Loop2d.cxx   2014-08-29 13:54:03.000000000 +0400
345 +++ netgen-5.3.1_new/libsrc/occ/Partition_Loop2d.cxx    2016-09-29 14:04:51.504148314 +0300
346 @@ -210,7 +210,7 @@
347      Cc->D1(uc, PC, CTg1);
348      if (!isForward) CTg1.Reverse();
349  
350 -    Standard_Real anglemin = 3 * PI, tolAng = 1.e-8;
351 +    Standard_Real anglemin = 3 * M_PI, tolAng = 1.e-8;
352  
353      // select an edge whose first derivative is most left of CTg1
354      // ie an angle between Tg1 and CTg1 is least
355 @@ -234,7 +234,7 @@
356        // -PI < angle < PI
357        Standard_Real angle = Tg1.Angle(CTg1);
358  
359 -      if (PI - Abs(angle) <= tolAng)
360 +      if (M_PI - Abs(angle) <= tolAng)
361        {
362          // an angle is too close to PI; assure that an angle sign really
363          // reflects an edge position: +PI - an edge is worst,
364 diff -NaurwB netgen-5.3.1_orig/libsrc/occ/Partition_Loop2d.hxx netgen-5.3.1_new/libsrc/occ/Partition_Loop2d.hxx
365 --- netgen-5.3.1_orig/libsrc/occ/Partition_Loop2d.hxx   2014-08-29 13:54:03.000000000 +0400
366 +++ netgen-5.3.1_new/libsrc/occ/Partition_Loop2d.hxx    2016-09-29 14:44:02.000464619 +0300
367 @@ -24,7 +24,6 @@
368  #endif
369  class TopoDS_Face;
370  class TopoDS_Edge;
371 -class TopTools_ListOfShape;
372  class BRepAlgo_Image;
373  
374  
375 diff -NaurwB netgen-5.3.1_orig/libsrc/occ/Partition_Loop3d.hxx netgen-5.3.1_new/libsrc/occ/Partition_Loop3d.hxx
376 --- netgen-5.3.1_orig/libsrc/occ/Partition_Loop3d.hxx   2014-08-29 13:54:03.000000000 +0400
377 +++ netgen-5.3.1_new/libsrc/occ/Partition_Loop3d.hxx    2016-09-29 14:44:02.000464619 +0300
378 @@ -13,6 +13,9 @@
379  #ifndef _TopTools_ListOfShape_HeaderFile
380  #include <TopTools_ListOfShape.hxx>
381  #endif
382 +#ifndef _TopTools_MapOfOrientedShape_HeaderFile
383 +#include <TopTools_MapOfOrientedShape.hxx>
384 +#endif
385  #ifndef _TopTools_IndexedDataMapOfShapeListOfShape_HeaderFile
386  #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
387  #endif
388 @@ -23,8 +26,6 @@
389  #include <Standard_Real.hxx>
390  #endif
391  class TopoDS_Shape;
392 -class TopTools_ListOfShape;
393 -class TopTools_MapOfOrientedShape;
394  class TopoDS_Edge;
395  class TopoDS_Face;
396  class gp_Vec;
397 diff -NaurwB netgen-5.3.1_orig/libsrc/occ/Partition_Spliter.cxx netgen-5.3.1_new/libsrc/occ/Partition_Spliter.cxx
398 --- netgen-5.3.1_orig/libsrc/occ/Partition_Spliter.cxx  2014-08-29 13:54:03.000000000 +0400
399 +++ netgen-5.3.1_new/libsrc/occ/Partition_Spliter.cxx   2016-09-29 14:44:02.000464619 +0300
400 @@ -48,7 +48,6 @@
401  #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
402  #include <TopTools_IndexedMapOfShape.hxx>
403  #include <TopTools_ListIteratorOfListOfShape.hxx>
404 -#include <TopTools_ListOfShape.hxx>
405  #include <TopTools_MapIteratorOfMapOfShape.hxx>
406  #include <TopTools_SequenceOfShape.hxx>
407  
408 diff -NaurwB netgen-5.3.1_orig/libsrc/occ/Partition_Spliter.hxx netgen-5.3.1_new/libsrc/occ/Partition_Spliter.hxx
409 --- netgen-5.3.1_orig/libsrc/occ/Partition_Spliter.hxx  2014-08-29 13:54:03.000000000 +0400
410 +++ netgen-5.3.1_new/libsrc/occ/Partition_Spliter.hxx   2016-09-29 14:44:02.004464639 +0300
411 @@ -28,9 +28,6 @@
412  #ifndef _TopTools_DataMapOfShapeShape_HeaderFile
413  #include <TopTools_DataMapOfShapeShape.hxx>
414  #endif
415 -#ifndef _Handle_BRepAlgo_AsDes_HeaderFile
416 -#include <Handle_BRepAlgo_AsDes.hxx>
417 -#endif
418  #ifndef _BRepAlgo_Image_HeaderFile
419  #include <BRepAlgo_Image.hxx>
420  #endif
421 @@ -45,7 +42,6 @@
422  #endif
423  class BRepAlgo_AsDes;
424  class TopoDS_Shape;
425 -class TopTools_ListOfShape;
426  class TopoDS_Edge;
427  
428  
429 @@ -129,7 +125,7 @@
430     TopTools_DataMapOfShapeShape myFaceShapeMap;
431     TopTools_DataMapOfShapeShape myInternalFaces;
432     TopTools_DataMapOfShapeShape myIntNotClFaces;
433 -   Handle_BRepAlgo_AsDes myAsDes;
434 +   Handle(BRepAlgo_AsDes) myAsDes;
435     BRepAlgo_Image myImagesFaces;
436     BRepAlgo_Image myImagesEdges;
437     BRepAlgo_Image myImageShape;
438 diff -NaurwB netgen-5.3.1_orig/libsrc/occ/occconstruction.cpp netgen-5.3.1_new/libsrc/occ/occconstruction.cpp
439 --- netgen-5.3.1_orig/libsrc/occ/occconstruction.cpp    2014-08-29 13:54:03.000000000 +0400
440 +++ netgen-5.3.1_new/libsrc/occ/occconstruction.cpp     2016-09-29 14:04:51.500148293 +0300
441 @@ -28,7 +28,7 @@
442  #include <BRepAlgoAPI_Common.hxx>
443  #include <BRepAlgoAPI_Fuse.hxx>
444  #include <BRepAlgoAPI_Section.hxx>
445 -#include <BRepOffsetAPI_Sewing.hxx>
446 +//#include <BRepOffsetAPI_Sewing.hxx>
447  //#include <BRepAlgo_Sewing.hxx>
448  #include <BRepOffsetAPI_MakeOffsetShape.hxx>
449  #include <ShapeFix_Shape.hxx>
450 diff -NaurwB netgen-5.3.1_orig/libsrc/occ/occgenmesh.cpp netgen-5.3.1_new/libsrc/occ/occgenmesh.cpp
451 --- netgen-5.3.1_orig/libsrc/occ/occgenmesh.cpp 2014-08-29 13:54:03.000000000 +0400
452 +++ netgen-5.3.1_new/libsrc/occ/occgenmesh.cpp  2016-09-29 14:04:51.500148293 +0300
453 @@ -171,8 +171,8 @@
454           if(h < 1e-4*maxside)\r
455              return;\r
456  \r
457 -\r
458 -         if (h > 30) return;\r
459 +         // commented to restrict H on a large sphere for example
460 +         //if (h > 30) return;
461        }\r
462  \r
463        if (h < maxside && depth < 10)\r
464 @@ -250,8 +250,8 @@
465        hvalue[0] = 0;\r
466        pnt = c->Value(s0);\r
467  \r
468 -      double olddist = 0;\r
469 -      double dist = 0;\r
470 +      //double olddist = 0; -- useless variables
471 +      //double dist = 0;
472  \r
473        int tmpVal = (int)(DIVIDEEDGESECTIONS);\r
474  \r
475 @@ -259,15 +259,19 @@
476        {\r
477           oldpnt = pnt;\r
478           pnt = c->Value(s0+(i/double(DIVIDEEDGESECTIONS))*(s1-s0));\r
479 +         // -- no more than 1 segment per <edge length>/DIVIDEEDGESECTIONS
480           hvalue[i] = hvalue[i-1] +\r
481 +         //   1.0/mesh.GetH(Point3d(pnt.X(), pnt.Y(), pnt.Z()))*
482 +         //   pnt.Distance(oldpnt);
483 +           min( 1.0,
484              1.0/mesh.GetH(Point3d(pnt.X(), pnt.Y(), pnt.Z()))*\r
485 -            pnt.Distance(oldpnt);\r
486 +                pnt.Distance(oldpnt));
487  \r
488           //(*testout) << "mesh.GetH(Point3d(pnt.X(), pnt.Y(), pnt.Z())) " << mesh.GetH(Point3d(pnt.X(), pnt.Y(), pnt.Z()))\r
489           //       <<  " pnt.Distance(oldpnt) " << pnt.Distance(oldpnt) << endl;\r
490  \r
491 -         olddist = dist;\r
492 -         dist = pnt.Distance(oldpnt);\r
493 +         //olddist = dist; -- useless variables
494 +         //dist = pnt.Distance(oldpnt);
495        }\r
496  \r
497        //  nsubedges = int(ceil(hvalue[DIVIDEEDGESECTIONS]));\r
498 @@ -282,7 +286,10 @@
499        {\r
500           if (hvalue[i1]/hvalue[DIVIDEEDGESECTIONS]*nsubedges >= i)\r
501           {\r
502 -            params[i] = s0+(i1/double(DIVIDEEDGESECTIONS))*(s1-s0);\r
503 +            // -- for nsubedges comparable to DIVIDEEDGESECTIONS
504 +            //params[i] = s0+(i1/double(DIVIDEEDGESECTIONS))*(s1-s0);
505 +            double d1 = i1 - (hvalue[i1] - i*hvalue[DIVIDEEDGESECTIONS]/nsubedges)/(hvalue[i1]-hvalue[i1-1]);
506 +            params[i] = s0+(d1/double(DIVIDEEDGESECTIONS))*(s1-s0);
507              pnt = c->Value(params[i]);\r
508              ps[i-1] = MeshPoint (Point3d(pnt.X(), pnt.Y(), pnt.Z()));\r
509              i++;\r
510 @@ -326,6 +333,9 @@
511        (*testout) << "nedges = " << nedges << endl;\r
512  \r
513        double eps = 1e-6 * geom.GetBoundingBox().Diam();\r
514 +      const double eps2 = eps * eps; // -- small optimization
515 +
516 +      int first_vp = mesh.GetNP()+1; // -- to support SALOME sub-meshes
517  \r
518        for (int i = 1; i <= nvertices; i++)\r
519        {\r
520 @@ -335,7 +345,8 @@
521           bool exists = 0;\r
522           if (merge_solids)\r
523              for (PointIndex pi = 1; pi <= mesh.GetNP(); pi++)\r
524 -               if ( Dist2 (mesh[pi], Point<3>(mp)) < eps*eps)\r
525 +               //if ( Dist2 (mesh[pi], Point<3>(mp)) < eps*eps)              
526 +               if ( Dist2 (mesh[pi], Point<3>(mp)) < eps2 ) // -- small optimization
527                 {\r
528                    exists = 1;\r
529                    break;\r
530 @@ -365,6 +376,7 @@
531           {\r
532              TopoDS_Face face = TopoDS::Face(exp1.Current());\r
533              int facenr = geom.fmap.FindIndex(face);\r
534 +            if ( facenr < 1 ) continue; // -- to support SALOME sub-meshes
535  \r
536              if (face2solid[0][facenr-1] == 0)\r
537                 face2solid[0][facenr-1] = solidnr;\r
538 @@ -384,6 +396,7 @@
539        int facenr = 0;\r
540        int edgenr = 0;\r
541  \r
542 +      edgenr = mesh.GetNSeg(); // to support SALOME sub-meshes
543  \r
544        (*testout) << "faces = " << geom.fmap.Extent() << endl;\r
545        int curr = 0;\r
546 @@ -445,6 +458,7 @@
547                    //(*testout) << "ignoring degenerated edge" << endl;\r
548                    continue;\r
549                 }\r
550 +               if ( geom.emap.FindIndex(edge) < 1 ) continue; // to support SALOME sub-meshes
551  \r
552                 if (geom.vmap.FindIndex(TopExp::FirstVertex (edge)) ==\r
553                    geom.vmap.FindIndex(TopExp::LastVertex (edge)))\r
554 @@ -477,20 +491,104 @@
555  \r
556                 if (!merge_solids)\r
557                 {\r
558 -                  pnums[0] = geom.vmap.FindIndex (TopExp::FirstVertex (edge));\r
559 -                  pnums[pnums.Size()-1] = geom.vmap.FindIndex (TopExp::LastVertex (edge));\r
560 +                 //pnums[0] = geom.vmap.FindIndex (TopExp::FirstVertex (edge));
561 +                 //pnums[pnums.Size()-1] = geom.vmap.FindIndex (TopExp::LastVertex (edge));
562 +                 MeshPoint dfltP ( Point<3> ( 0, 0, 0 ) );
563 +                 int *ipp[] = { &pnums[0], &pnums[pnums.Size()-1] };
564 +                 TopoDS_Iterator vIt( edge, false );
565 +                 TopoDS_Vertex v[2];
566 +                 v[0] = TopoDS::Vertex( vIt.Value() ); vIt.Next();
567 +                 v[1] = TopoDS::Vertex( vIt.Value() );
568 +                 if ( v[0].Orientation() == TopAbs_REVERSED )
569 +                   std::swap( v[0], v[1] );
570 +                 for ( int i = 0; i < 2; ++i)
571 +                 {
572 +                   int &ip = *ipp[i];
573 +                   ip = geom.vmap.FindIndex ( v[i] );
574 +                   if ( ip == 0 || ip > nvertices )
575 +                   {
576 +                     int iv = ip;
577 +                     if ( ip == 0 )
578 +                       ip = iv = geom.vmap.Add( v[i] );
579 +                     gp_Pnt pnt = BRep_Tool::Pnt( v[i] );
580 +                     MeshPoint mp( Point<3>(pnt.X(), pnt.Y(), pnt.Z()) );
581 +                     for (PointIndex pi = 1; pi < first_vp; pi++)
582 +                       if ( Dist2 (mesh.Point(pi), Point<3>(mp)) < 1e-100 )
583 +                       {
584 +                         ip = pi;
585 +                         if ( mesh.Point(ip).GetLayer() != dfltP.GetLayer() && mesh.Point(ip).GetLayer() != iv )
586 +                           continue;
587 +                         if ( mesh.Point(ip).GetLayer() == dfltP.GetLayer())
588 +                           mesh.Point(ip) = MeshPoint( mesh.Point(ip), iv );
589 +                         break;
590 +                       }
591                 }\r
592                 else\r
593                 {\r
594 -                  Point<3> fp = occ2ng (BRep_Tool::Pnt (TopExp::FirstVertex (edge)));\r
595 -                  Point<3> lp = occ2ng (BRep_Tool::Pnt (TopExp::LastVertex (edge)));\r
596 +                     ip += first_vp - 1;
597 +                   }
598 +                 }
599 +               }
600 +               else
601 +               {
602 +                 TopoDS_Iterator vIt( edge, false );
603 +                 TopoDS_Vertex v1 = TopoDS::Vertex( vIt.Value() ); vIt.Next();
604 +                 TopoDS_Vertex v2 = TopoDS::Vertex( vIt.Value() );
605 +                 if ( v1.Orientation() == TopAbs_REVERSED )
606 +                   std::swap( v1, v2 );
607 +                 const bool isClosedEdge = v1.IsSame( v2 );
608 +                 
609 +                  Point<3> fp = occ2ng (BRep_Tool::Pnt (v1));
610 +                  Point<3> lp = occ2ng (BRep_Tool::Pnt (v2));
611 +                  double tol2 = std::min( eps*eps, 1e-6 * Dist2( fp, lp ));
612 +                  if ( isClosedEdge )
613 +                    tol2 = BRep_Tool::Tolerance( v1 ) * BRep_Tool::Tolerance( v1 );
614  \r
615                    pnums[0] = -1;\r
616                    pnums.Last() = -1;\r
617                    for (PointIndex pi = 1; pi < first_ep; pi++)\r
618                    {\r
619 -                     if (Dist2 (mesh[pi], fp) < eps*eps) pnums[0] = pi;\r
620 -                     if (Dist2 (mesh[pi], lp) < eps*eps) pnums.Last() = pi;\r
621 +                    if (Dist2 (mesh[pi], fp) < tol2) pnums[0] = pi;
622 +                    if (Dist2 (mesh[pi], lp) < tol2) pnums.Last() = pi;
623 +                  }
624 +                  if (( isClosedEdge && pnums[0] != pnums.Last() ) ||
625 +                      ( !isClosedEdge && pnums[0] == pnums.Last() ))
626 +                    pnums[0] = pnums.Last() = -1;
627 +                  if ( pnums[0] == -1 || pnums.Last() == -1 )
628 +                  {
629 +                    // take into account a possible large gap between a vertex and an edge curve
630 +                    // end and a large vertex tolerance covering the whole edge
631 +                    if ( pnums[0] == -1 )
632 +                    {
633 +                      double tol = BRep_Tool::Tolerance( v1 );
634 +                      for (PointIndex pi = 1; pi < first_ep; pi++)
635 +                        if (pi != pnums.Last() && Dist2 (mesh[pi], fp) < 2*tol*tol)
636 +                          pnums[0] = pi;
637 +
638 +                      if ( pnums[0] == -1 )
639 +                        pnums[0] = first_ep-1- nvertices + geom.vmap.FindIndex ( v1 );
640 +                    }
641 +                    if ( isClosedEdge )
642 +                    {
643 +                      pnums.Last() = pnums[0];
644 +                    }
645 +                    else
646 +                    {
647 +                      if ( pnums.Last() == -1 )
648 +                      {
649 +                        double tol = BRep_Tool::Tolerance( v2 );
650 +                        for (PointIndex pi = 1; pi < first_ep; pi++)
651 +                          if (pi != pnums[0] && Dist2 (mesh[pi], lp) < 2*tol*tol)
652 +                            pnums.Last() = pi;
653 +
654 +                        if ( pnums.Last() == -1 )
655 +                          pnums.Last() = first_ep-1-nvertices + geom.vmap.FindIndex ( v2 );
656 +                      }
657 +
658 +                      if ( Dist2( fp, mesh[PointIndex(pnums[0])]) >
659 +                           Dist2( lp, mesh[PointIndex(pnums.Last())]))
660 +                      std::swap( pnums[0], pnums.Last() );
661 +                    }
662                    }\r
663                 }\r
664  \r
665 @@ -500,17 +598,20 @@
666                    bool exists = 0;\r
667                    int j;\r
668                    for (j = first_ep; j <= mesh.GetNP(); j++)\r
669 +                  {
670 +                     if (!merge_solids && mesh.Point(j).GetLayer() != geomedgenr ) continue; // to support SALOME fuse edges
671                       if ((mesh.Point(j)-Point<3>(mp[i-1])).Length() < eps)\r
672                       {\r
673                          exists = 1;\r
674                          break;\r
675                       }\r
676 +                  }
677  \r
678                       if (exists)\r
679                          pnums[i] = j;\r
680                       else\r
681                       {\r
682 -                        mesh.AddPoint (mp[i-1]);\r
683 +                        mesh.AddPoint (mp[i-1], geomedgenr); // to support SALOME fuse edges
684                          (*testout) << "add meshpoint " << mp[i-1] << endl;\r
685                          pnums[i] = mesh.GetNP();\r
686                       }\r
687 @@ -594,6 +695,8 @@
688        //               (*testout) << "edge " << mesh.LineSegment(i).edgenr << " face " << mesh.LineSegment(i).si\r
689        //                               << " p1 " << mesh.LineSegment(i)[0] << " p2 " << mesh.LineSegment(i)[1] << endl;\r
690        //       exit(10);\r
691 +      for (int j = 1; j <= mesh.GetNP(); j++) // to support SALOME fuse edges: set level to zero
692 +        mesh.Point(j) = MeshPoint( (Point<3>&) mesh.Point(j) );
693  \r
694        mesh.CalcSurfacesOfNode();\r
695        multithread.task = savetask;\r
696 diff -NaurwB netgen-5.3.1_orig/libsrc/occ/occgeom.cpp netgen-5.3.1_new/libsrc/occ/occgeom.cpp
697 --- netgen-5.3.1_orig/libsrc/occ/occgeom.cpp    2014-08-29 13:54:03.000000000 +0400
698 +++ netgen-5.3.1_new/libsrc/occ/occgeom.cpp     2016-09-29 16:22:31.636328123 +0300
699 @@ -8,6 +8,8 @@
700  #include "ShapeAnalysis_CheckSmallFace.hxx"\r
701  #include "ShapeAnalysis_DataMapOfShapeListOfReal.hxx"\r
702  #include "ShapeAnalysis_Surface.hxx"\r
703 +#include <BRepTopAdaptor_FClass2d.hxx> // -- to optimize Project() and FastProject()
704 +#include <TopAbs_State.hxx>
705  #include "BRepAlgoAPI_Fuse.hxx"\r
706  #include "BRepCheck_Analyzer.hxx"\r
707  #include "BRepLib.hxx"\r
708 @@ -16,9 +18,16 @@
709  #include "ShapeFix_FixSmallFace.hxx"\r
710  #include "Partition_Spliter.hxx"\r
711  \r
712 -\r
713  namespace netgen\r
714  {\r
715 +  // free data used to optimize Project() and FastProject()
716 +  OCCGeometry::~OCCGeometry()
717 +  {
718 +    NCollection_DataMap<int,BRepTopAdaptor_FClass2d*>::Iterator it(fclsmap);
719 +    for (; it.More(); it.Next())
720 +      delete it.Value();
721 +  }
722 +
723     void OCCGeometry :: PrintNrShapes ()\r
724     {\r
725        TopExp_Explorer e;\r
726 @@ -112,7 +121,7 @@
727        double surfacecont = 0;\r
728  \r
729        {\r
730 -         Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape;\r
731 +         Handle(ShapeBuild_ReShape) rebuild = new ShapeBuild_ReShape;
732           rebuild->Apply(shape);\r
733           for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next())\r
734           {\r
735 @@ -143,7 +152,7 @@
736           cout << endl << "- repairing faces" << endl;\r
737  \r
738           Handle(ShapeFix_Face) sff;\r
739 -         Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape;\r
740 +         Handle(ShapeBuild_ReShape) rebuild = new ShapeBuild_ReShape;
741           rebuild->Apply(shape);\r
742  \r
743  \r
744 @@ -200,7 +209,7 @@
745  \r
746  \r
747        {\r
748 -         Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape;\r
749 +         Handle(ShapeBuild_ReShape) rebuild = new ShapeBuild_ReShape;
750           rebuild->Apply(shape);\r
751           for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next())\r
752           {\r
753 @@ -217,7 +226,7 @@
754           cout << endl << "- fixing small edges" << endl;\r
755  \r
756           Handle(ShapeFix_Wire) sfw;\r
757 -         Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape;\r
758 +         Handle(ShapeBuild_ReShape) rebuild = new ShapeBuild_ReShape;
759           rebuild->Apply(shape);\r
760  \r
761  \r
762 @@ -284,7 +293,7 @@
763  \r
764           {\r
765              BuildFMap();\r
766 -            Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape;\r
767 +            Handle(ShapeBuild_ReShape) rebuild = new ShapeBuild_ReShape;
768              rebuild->Apply(shape);\r
769  \r
770              for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next())\r
771 @@ -312,7 +321,7 @@
772  \r
773  \r
774           {\r
775 -            Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape;\r
776 +            Handle(ShapeBuild_ReShape) rebuild = new ShapeBuild_ReShape;
777              rebuild->Apply(shape);\r
778              for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next())\r
779              {\r
780 @@ -438,7 +447,7 @@
781  \r
782  \r
783        {\r
784 -         Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape;\r
785 +         Handle(ShapeBuild_ReShape) rebuild = new ShapeBuild_ReShape;
786           rebuild->Apply(shape);\r
787           for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next())\r
788           {\r
789 @@ -483,7 +492,7 @@
790                    TopoDS_Solid solid = TopoDS::Solid(exp0.Current());\r
791                    TopoDS_Solid newsolid = solid;\r
792                    BRepLib::OrientClosedSolid (newsolid);\r
793 -                  Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape;\r
794 +                  Handle(ShapeBuild_ReShape) rebuild = new ShapeBuild_ReShape;
795                    //             rebuild->Apply(shape);\r
796                    rebuild->Replace(solid, newsolid, Standard_False);\r
797                    TopoDS_Shape newshape = rebuild->Apply(shape, TopAbs_COMPSOLID);//, 1);\r
798 @@ -906,7 +915,7 @@
799              TopoDS_Solid solid = TopoDS::Solid(exp0.Current());\r
800              TopoDS_Solid newsolid = solid;\r
801              BRepLib::OrientClosedSolid (newsolid);\r
802 -            Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape;\r
803 +            Handle(ShapeBuild_ReShape) rebuild = new ShapeBuild_ReShape;
804              rebuild->Replace(solid, newsolid, Standard_False);\r
805  \r
806              TopoDS_Shape newshape = rebuild->Apply(shape, TopAbs_SHAPE, 1);\r
807 @@ -951,25 +960,58 @@
808     }\r
809  \r
810  \r
811 +   // returns a projector and a classifier for the given surface
812 +   void OCCGeometry::GetFaceTools(int surfi, Handle(ShapeAnalysis_Surface)& proj,
813 +                                  BRepTopAdaptor_FClass2d*& cls) const
814 +   {
815 +     //MSV: organize caching projector in the map
816 +     if (fprjmap.IsBound(surfi))
817 +     {
818 +       proj = fprjmap.Find(surfi);
819 +       cls = fclsmap.Find(surfi);
820 +     }
821 +     else
822 +     {
823 +       const TopoDS_Face& aFace = TopoDS::Face(fmap(surfi));
824 +       Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
825 +       proj = new ShapeAnalysis_Surface(aSurf);
826 +       fprjmap.Bind(surfi, proj);
827 +       cls = new BRepTopAdaptor_FClass2d(aFace,Precision::Confusion());
828 +       fclsmap.Bind(surfi, cls);
829 +     }
830 +   }
831  \r
832 -\r
833 -   void OCCGeometry :: Project (int surfi, Point<3> & p) const\r
834 +   // void OCCGeometry :: Project (int surfi, Point<3> & p) const
835 +   bool OCCGeometry :: Project (int surfi, Point<3> & p, double& u, double& v) const
836     {\r
837        static int cnt = 0;\r
838        if (++cnt % 1000 == 0) cout << "Project cnt = " << cnt << endl;\r
839  \r
840        gp_Pnt pnt(p(0), p(1), p(2));\r
841  \r
842 -      double u,v;\r
843 -      Handle( Geom_Surface ) thesurf = BRep_Tool::Surface(TopoDS::Face(fmap(surfi)));\r
844 -      Handle( ShapeAnalysis_Surface ) su = new ShapeAnalysis_Surface( thesurf );\r
845 -      gp_Pnt2d suval = su->ValueOfUV ( pnt, BRep_Tool::Tolerance( TopoDS::Face(fmap(surfi)) ) );\r
846 -      suval.Coord( u, v);\r
847 -      pnt = thesurf->Value( u, v );\r
848 +      // -- Optimization: use cached projector and classifier
849 +      // double u,v;
850 +      // Handle( Geom_Surface ) thesurf = BRep_Tool::Surface(TopoDS::Face(fmap(surfi)));
851 +      // Handle( ShapeAnalysis_Surface ) su = new ShapeAnalysis_Surface( thesurf );
852 +      // gp_Pnt2d suval = su->ValueOfUV ( pnt, BRep_Tool::Tolerance( TopoDS::Face(fmap(surfi)) ) );
853 +      // suval.Coord( u, v);
854 +      // pnt = thesurf->Value( u, v );  
855 +
856 +      Handle(ShapeAnalysis_Surface) proj;
857 +      BRepTopAdaptor_FClass2d *cls;
858 +      GetFaceTools(surfi, proj, cls);
859  \r
860 +      gp_Pnt2d p2d = proj->ValueOfUV(pnt, Precision::Confusion());
861 +      if (cls->Perform(p2d) == TopAbs_OUT)
862 +      {
863 +        return false;
864 +      }
865 +      pnt = proj->Value(p2d);
866 +      p2d.Coord(u, v);
867  \r
868        p = Point<3> (pnt.X(), pnt.Y(), pnt.Z());\r
869  \r
870 +      return true;
871     }\r
872  \r
873  \r
874 @@ -979,54 +1021,69 @@
875     {\r
876        gp_Pnt p(ap(0), ap(1), ap(2));\r
877  \r
878 -      Handle(Geom_Surface) surface = BRep_Tool::Surface(TopoDS::Face(fmap(surfi)));\r
879 -\r
880 -      gp_Pnt x = surface->Value (u,v);\r
881 -\r
882 -      if (p.SquareDistance(x) <= sqr(PROJECTION_TOLERANCE)) return true;\r
883 -\r
884 -      gp_Vec du, dv;\r
885 +      // -- Optimization: use cached projector and classifier
886 +      // Handle(Geom_Surface) surface = BRep_Tool::Surface(TopoDS::Face(fmap(surfi)));
887 +      // 
888 +      // gp_Pnt x = surface->Value (u,v);
889 +      // 
890 +      // if (p.SquareDistance(x) <= sqr(PROJECTION_TOLERANCE)) return true;
891 +      // 
892 +      // gp_Vec du, dv;
893 +      // 
894 +      // surface->D1(u,v,x,du,dv);
895 +      // 
896 +      // int count = 0;
897 +      // 
898 +      // gp_Pnt xold;
899 +      // gp_Vec n;
900 +      // double det, lambda, mu;
901 +      // 
902 +      // do {
903 +      //    count++;
904 +      // 
905 +      //    n = du^dv;
906 +      // 
907 +      //    det = Det3 (n.X(), du.X(), dv.X(),
908 +      //       n.Y(), du.Y(), dv.Y(),
909 +      //       n.Z(), du.Z(), dv.Z());
910 +      // 
911 +      //    if (det < 1e-15) return false;
912 +      // 
913 +      //    lambda = Det3 (n.X(), p.X()-x.X(), dv.X(),
914 +      //       n.Y(), p.Y()-x.Y(), dv.Y(),
915 +      //       n.Z(), p.Z()-x.Z(), dv.Z())/det;
916 +      // 
917 +      //    mu     = Det3 (n.X(), du.X(), p.X()-x.X(),
918 +      //       n.Y(), du.Y(), p.Y()-x.Y(),
919 +      //       n.Z(), du.Z(), p.Z()-x.Z())/det;
920 +      // 
921 +      //    u += lambda;
922 +      //    v += mu;
923 +      // 
924 +      //    xold = x;
925 +      //    surface->D1(u,v,x,du,dv);
926 +      // 
927 +      // } while (xold.SquareDistance(x) > sqr(PROJECTION_TOLERANCE) && count < 50);
928 +      // 
929 +      // //    (*testout) << "FastProject count: " << count << endl;
930 +      // 
931 +      // if (count == 50) return false;
932 +      // 
933 +      // ap = Point<3> (x.X(), x.Y(), x.Z());
934 +      Handle(ShapeAnalysis_Surface) proj;
935 +      BRepTopAdaptor_FClass2d *cls;
936 +      GetFaceTools(surfi, proj, cls);
937  \r
938 -      surface->D1(u,v,x,du,dv);\r
939 -\r
940 -      int count = 0;\r
941 -\r
942 -      gp_Pnt xold;\r
943 -      gp_Vec n;\r
944 -      double det, lambda, mu;\r
945 -\r
946 -      do {\r
947 -         count++;\r
948 -\r
949 -         n = du^dv;\r
950 -\r
951 -         det = Det3 (n.X(), du.X(), dv.X(),\r
952 -            n.Y(), du.Y(), dv.Y(),\r
953 -            n.Z(), du.Z(), dv.Z());\r
954 -\r
955 -         if (det < 1e-15) return false;\r
956 -\r
957 -         lambda = Det3 (n.X(), p.X()-x.X(), dv.X(),\r
958 -            n.Y(), p.Y()-x.Y(), dv.Y(),\r
959 -            n.Z(), p.Z()-x.Z(), dv.Z())/det;\r
960 -\r
961 -         mu     = Det3 (n.X(), du.X(), p.X()-x.X(),\r
962 -            n.Y(), du.Y(), p.Y()-x.Y(),\r
963 -            n.Z(), du.Z(), p.Z()-x.Z())/det;\r
964 -\r
965 -         u += lambda;\r
966 -         v += mu;\r
967 -\r
968 -         xold = x;\r
969 -         surface->D1(u,v,x,du,dv);\r
970 -\r
971 -      } while (xold.SquareDistance(x) > sqr(PROJECTION_TOLERANCE) && count < 50);\r
972 -\r
973 -      //    (*testout) << "FastProject count: " << count << endl;\r
974 -\r
975 -      if (count == 50) return false;\r
976 +      gp_Pnt2d p2d = proj->NextValueOfUV(gp_Pnt2d(u,v), p, Precision::Confusion());
977 +      if (cls->Perform(p2d) == TopAbs_OUT)
978 +      {
979 +        //cout << "Projection fails" << endl;
980 +        return false;
981 +      }
982  \r
983 -      ap = Point<3> (x.X(), x.Y(), x.Z());\r
984 +      p = proj->Value(p2d);
985 +      p2d.Coord(u, v);
986 +      ap = Point<3> (p.X(), p.Y(), p.Z());
987  \r
988        return true;\r
989     }\r
990 @@ -1038,9 +1095,9 @@
991     {\r
992        cout << "writing stl..."; cout.flush();\r
993        StlAPI_Writer writer;\r
994 -      writer.RelativeMode() = Standard_False;\r
995 +      //writer.RelativeMode() = Standard_False;
996  \r
997 -      writer.SetDeflection(0.02);\r
998 +      //writer.SetDeflection(0.02);
999        writer.Write(shape,filename);\r
1000  \r
1001        cout << "done" << endl;\r
1002 @@ -1059,10 +1116,10 @@
1003        occgeo = new OCCGeometry;\r
1004  \r
1005        // Initiate a dummy XCAF Application to handle the IGES XCAF Document\r
1006 -      static Handle_XCAFApp_Application dummy_app = XCAFApp_Application::GetApplication();\r
1007 +      static Handle(XCAFApp_Application) dummy_app = XCAFApp_Application::GetApplication();
1008  \r
1009        // Create an XCAF Document to contain the IGES file itself\r
1010 -      Handle_TDocStd_Document iges_doc;\r
1011 +      Handle(TDocStd_Document) iges_doc;
1012  \r
1013        // Check if a IGES File is already open under this handle, if so, close it to prevent\r
1014        // Segmentation Faults when trying to create a new document\r
1015 @@ -1089,8 +1146,8 @@
1016        reader.Transfer(iges_doc);\r
1017  \r
1018        // Read in the shape(s) and the colours present in the IGES File\r
1019 -      Handle_XCAFDoc_ShapeTool iges_shape_contents = XCAFDoc_DocumentTool::ShapeTool(iges_doc->Main());\r
1020 -      Handle_XCAFDoc_ColorTool iges_colour_contents = XCAFDoc_DocumentTool::ColorTool(iges_doc->Main());\r
1021 +      Handle(XCAFDoc_ShapeTool) iges_shape_contents = XCAFDoc_DocumentTool::ShapeTool(iges_doc->Main());
1022 +      Handle(XCAFDoc_ColorTool) iges_colour_contents = XCAFDoc_DocumentTool::ColorTool(iges_doc->Main());
1023  \r
1024        TDF_LabelSequence iges_shapes;\r
1025        iges_shape_contents->GetShapes(iges_shapes);\r
1026 @@ -1137,10 +1194,10 @@
1027        occgeo = new OCCGeometry;\r
1028  \r
1029        // Initiate a dummy XCAF Application to handle the STEP XCAF Document\r
1030 -      static Handle_XCAFApp_Application dummy_app = XCAFApp_Application::GetApplication();\r
1031 +      static Handle(XCAFApp_Application) dummy_app = XCAFApp_Application::GetApplication();
1032  \r
1033        // Create an XCAF Document to contain the STEP file itself\r
1034 -      Handle_TDocStd_Document step_doc;\r
1035 +      Handle(TDocStd_Document) step_doc;
1036  \r
1037        // Check if a STEP File is already open under this handle, if so, close it to prevent\r
1038        // Segmentation Faults when trying to create a new document\r
1039 @@ -1167,8 +1224,8 @@
1040        reader.Transfer(step_doc);\r
1041  \r
1042        // Read in the shape(s) and the colours present in the STEP File\r
1043 -      Handle_XCAFDoc_ShapeTool step_shape_contents = XCAFDoc_DocumentTool::ShapeTool(step_doc->Main());\r
1044 -      Handle_XCAFDoc_ColorTool step_colour_contents = XCAFDoc_DocumentTool::ColorTool(step_doc->Main());\r
1045 +      Handle(XCAFDoc_ShapeTool) step_shape_contents = XCAFDoc_DocumentTool::ShapeTool(step_doc->Main());
1046 +      Handle(XCAFDoc_ColorTool) step_colour_contents = XCAFDoc_DocumentTool::ColorTool(step_doc->Main());
1047  \r
1048        TDF_LabelSequence step_shapes;\r
1049        step_shape_contents->GetShapes(step_shapes);\r
1050 @@ -1221,7 +1278,7 @@
1051        // Fixed a bug in the OpenCascade XDE Colour handling when \r
1052        // opening BREP Files, since BREP Files have no colour data.\r
1053        // Hence, the face_colours Handle needs to be created as a NULL handle.\r
1054 -      occgeo->face_colours = Handle_XCAFDoc_ColorTool();\r
1055 +      occgeo->face_colours = Handle(XCAFDoc_ColorTool)();
1056        occgeo->face_colours.Nullify();\r
1057        occgeo->changed = 1;\r
1058        occgeo->BuildFMap();\r
1059 diff -NaurwB netgen-5.3.1_orig/libsrc/occ/occgeom.hpp netgen-5.3.1_new/libsrc/occ/occgeom.hpp
1060 --- netgen-5.3.1_orig/libsrc/occ/occgeom.hpp    2014-08-29 13:54:03.000000000 +0400
1061 +++ netgen-5.3.1_new/libsrc/occ/occgeom.hpp     2016-09-29 14:44:01.996464598 +0300
1062 @@ -15,8 +15,8 @@
1063  #include "Geom_Curve.hxx"\r
1064  #include "Geom2d_Curve.hxx"\r
1065  #include "Geom_Surface.hxx"\r
1066 -#include "GeomAPI_ProjectPointOnSurf.hxx"\r
1067 -#include "GeomAPI_ProjectPointOnCurve.hxx"\r
1068 +// #include "GeomAPI_ProjectPointOnSurf.hxx"
1069 +// #include "GeomAPI_ProjectPointOnCurve.hxx"
1070  #include "BRepTools.hxx"\r
1071  #include "TopExp.hxx"\r
1072  #include "BRepBuilderAPI_MakeVertex.hxx"\r
1073 @@ -42,8 +42,8 @@
1074  #include "Geom_Curve.hxx"\r
1075  #include "Geom2d_Curve.hxx"\r
1076  #include "Geom_Surface.hxx"\r
1077 -#include "GeomAPI_ProjectPointOnSurf.hxx"\r
1078 -#include "GeomAPI_ProjectPointOnCurve.hxx"\r
1079 +// #include "GeomAPI_ProjectPointOnSurf.hxx"
1080 +// #include "GeomAPI_ProjectPointOnCurve.hxx"
1081  #include "TopoDS_Wire.hxx"\r
1082  #include "BRepTools_WireExplorer.hxx"\r
1083  #include "BRepTools.hxx"\r
1084 @@ -68,18 +68,26 @@
1085  #include "IGESToBRep_Reader.hxx"\r
1086  #include "Interface_Static.hxx"\r
1087  #include "GeomAPI_ExtremaCurveCurve.hxx"\r
1088 -#include "Standard_ErrorHandler.hxx"\r
1089 +//#include "Standard_ErrorHandler.hxx"
1090  #include "Standard_Failure.hxx"\r
1091  #include "ShapeUpgrade_ShellSewing.hxx"\r
1092  #include "ShapeFix_Shape.hxx"\r
1093  #include "ShapeFix_Wireframe.hxx"\r
1094 +#include <Standard_Version.hxx>
1095 +#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) <= 0x060702
1096 +// porting to OCCT6.7.3
1097  #include "BRepMesh.hxx"\r
1098 +#endif
1099  #include "BRepMesh_IncrementalMesh.hxx"\r
1100  #include "BRepBndLib.hxx"\r
1101  #include "Bnd_Box.hxx"\r
1102  #include "ShapeAnalysis.hxx"\r
1103  #include "ShapeBuild_ReShape.hxx"\r
1104  \r
1105 +// -- Optimization: to use cached projector and classifier
1106 +#include <NCollection_DataMap.hxx>
1107 +class ShapeAnalysis_Surface;
1108 +class BRepTopAdaptor_FClass2d;
1109  \r
1110  // Philippose - 29/01/2009\r
1111  // OpenCascade XDE Support\r
1112 @@ -192,6 +200,9 @@
1113     class OCCGeometry : public NetgenGeometry\r
1114     {\r
1115        Point<3> center;\r
1116 +      // -- Optimization: to use cached projector and classifier
1117 +      mutable NCollection_DataMap<int,Handle(ShapeAnalysis_Surface)> fprjmap;
1118 +      mutable NCollection_DataMap<int,BRepTopAdaptor_FClass2d*> fclsmap;
1119  \r
1120     public:\r
1121        TopoDS_Shape shape;\r
1122 @@ -203,7 +214,7 @@
1123        // OpenCascade XDE Support\r
1124        // XCAF Handle to make the face colours available to the rest of\r
1125        // the system\r
1126 -      Handle_XCAFDoc_ColorTool face_colours;\r
1127 +      Handle(XCAFDoc_ColorTool) face_colours;
1128  \r
1129       mutable int changed;\r
1130        Array<int> facemeshstatus;\r
1131 @@ -247,6 +258,8 @@
1132       virtual void Save (string filename) const;\r
1133  \r
1134  \r
1135 +      ~OCCGeometry();      // -- to free cached projector and classifier
1136 +
1137        void BuildFMap();\r
1138  \r
1139        Box<3> GetBoundingBox()\r
1140 @@ -266,9 +279,14 @@
1141        Point<3> Center()\r
1142        {  return center;}\r
1143  \r
1144 -      void Project (int surfi, Point<3> & p) const;\r
1145 +      // void Project (int surfi, Point<3> & p) const; -- optimization
1146 +      bool Project (int surfi, Point<3> & p, double& u, double& v) const;
1147        bool FastProject (int surfi, Point<3> & ap, double& u, double& v) const;\r
1148  \r
1149 +      // -- Optimization: to use cached projector and classifier
1150 +      void GetFaceTools(int surfi, Handle(ShapeAnalysis_Surface)& proj,
1151 +                        BRepTopAdaptor_FClass2d*& cls) const;
1152 +
1153        OCCSurface GetSurface (int surfi)\r
1154        {\r
1155           cout << "OCCGeometry::GetSurface using PLANESPACE" << endl;\r
1156 diff -NaurwB netgen-5.3.1_orig/libsrc/occ/occmeshsurf.cpp netgen-5.3.1_new/libsrc/occ/occmeshsurf.cpp
1157 --- netgen-5.3.1_orig/libsrc/occ/occmeshsurf.cpp        2014-08-29 13:54:03.000000000 +0400
1158 +++ netgen-5.3.1_new/libsrc/occ/occmeshsurf.cpp 2016-09-29 14:08:00.045144560 +0300
1159 @@ -6,6 +6,7 @@
1160  #include <meshing.hpp>
1161  #include <GeomLProp_SLProps.hxx>
1162  #include <ShapeAnalysis_Surface.hxx>
1163 +#include <GeomAPI_ProjectPointOnCurve.hxx> // -- moved here from occgeom.hpp
1164  
1165  
1166  namespace netgen
1167 @@ -96,13 +97,16 @@
1168  
1169         n.Normalize();
1170        }
1171 -    else
1172 +    else if ( lprop.IsNormalDefined() )
1173        {
1174         n(0)=lprop.Normal().X();
1175         n(1)=lprop.Normal().Y();
1176         n(2)=lprop.Normal().Z();
1177        }
1178 -
1179 +    else
1180 +      {
1181 +        n = 0;
1182 +      }
1183      if(glob_testout)
1184        {
1185         (*testout) << "u " << geominfo.u << " v " << geominfo.v 
1186 @@ -434,23 +435,33 @@
1187  
1188    void MeshOptimize2dOCCSurfaces :: ProjectPoint (INDEX surfind, Point<3> & p) const
1189    {
1190 -    geometry.Project (surfind, p);
1191 +    // geometry.Project (surfind, p); -- signature of Project() changed for optimization
1192 +    double u, v;
1193 +    geometry.Project (surfind, p, u, v);
1194    }
1195  
1196  
1197    int MeshOptimize2dOCCSurfaces :: ProjectPointGI (INDEX surfind, Point<3> & p, PointGeomInfo & gi) const
1198    {
1199 -    double u = gi.u;
1200 -    double v = gi.v;
1201 +    //double u = gi.u;
1202 +    //double v = gi.v;
1203  
1204      Point<3> hp = p;
1205 -    if (geometry.FastProject (surfind, hp, u, v))
1206 -      {
1207 +    // -- u and v are computed by FastProject() and Project(), no need to call CalcPointGeomInfo()
1208 +    // if (geometry.FastProject (surfind, hp, u, v))
1209 +    //   {
1210 +    //    p = hp;
1211 +    //    return 1;
1212 +    //   }
1213 +    // ProjectPoint (surfind, p); 
1214 +    // return CalcPointGeomInfo (surfind, gi, p); 
1215 +    bool ok;
1216 +    if (gi.trignum > 0)
1217 +      ok = geometry.FastProject (surfind, hp, gi.u, gi.v);
1218 +    else
1219 +      ok = geometry.Project (surfind, hp, gi.u, gi.v);
1220         p = hp;
1221 -       return 1;
1222 -      }
1223 -    ProjectPoint (surfind, p); 
1224 -    return CalcPointGeomInfo (surfind, gi, p); 
1225 +    return ok;
1226    }
1227  
1228  
1229 @@ -680,7 +691,8 @@
1230         if (!geometry.FastProject (surfi, hnewp, u, v))
1231           {
1232           //  cout << "Fast projection to surface fails! Using OCC projection" << endl;
1233 -           geometry.Project (surfi, hnewp);
1234 +           // geometry.Project (surfi, hnewp); -- Project() changed for optimization
1235 +           geometry.Project (surfi, hnewp, u, v);
1236           }
1237  
1238         newgi.trignum = 1;
1239 @@ -689,7 +701,7 @@
1240        }
1241    
1242      newp = hnewp;
1243 -  }
1244 +  }//; -- to compile with -Wall -pedantic
1245  
1246  
1247    void OCCRefinementSurfaces :: 
1248 @@ -708,14 +720,18 @@
1249      hnewp = Point<3> (pnt.X(), pnt.Y(), pnt.Z());
1250      newp = hnewp;
1251      newgi = ap1;
1252 -  };
1253 +  }//; -- to compile with -Wall -pedantic
1254  
1255  
1256    void OCCRefinementSurfaces :: ProjectToSurface (Point<3> & p, int surfi) const
1257    {
1258      if (surfi > 0)
1259 -      geometry.Project (surfi, p);
1260 -  };
1261 +      //geometry.Project (surfi, p);
1262 +    {
1263 +      double u, v;
1264 +      geometry.Project (surfi, p, u, v);
1265 +    }
1266 +  }//; -- to compile with -Wall -pedantic
1267  
1268    void OCCRefinementSurfaces :: ProjectToSurface (Point<3> & p, int surfi, PointGeomInfo & gi) const
1269    {
1270 @@ -723,9 +739,10 @@
1271        if (!geometry.FastProject (surfi, p, gi.u, gi.v))
1272         {
1273           cout << "Fast projection to surface fails! Using OCC projection" << endl;
1274 -         geometry.Project (surfi, p);
1275 +          double u, v;
1276 +         geometry.Project (surfi, p, u, v);
1277 +       }
1278         }
1279 -  };
1280  
1281  
1282  
1283 diff -NaurwB netgen-5.3.1_orig/libsrc/occ/utilities.h netgen-5.3.1_new/libsrc/occ/utilities.h
1284 --- netgen-5.3.1_orig/libsrc/occ/utilities.h    2014-08-29 13:54:03.000000000 +0400
1285 +++ netgen-5.3.1_new/libsrc/occ/utilities.h     2016-09-29 14:04:51.504148314 +0300
1286 @@ -33,6 +33,7 @@
1287  
1288  #include <string>
1289  #include <iostream>
1290 +#include <iomanip>
1291  #include <cstdlib>
1292  // #include "SALOME_Log.hxx"
1293  
1294 diff -NaurwB netgen-5.3.1_orig/nglib/nglib.h netgen-5.3.1_new/nglib/nglib.h
1295 --- netgen-5.3.1_orig/nglib/nglib.h     2014-08-29 13:54:00.000000000 +0400
1296 +++ netgen-5.3.1_new/nglib/nglib.h      2016-09-29 14:04:51.504148314 +0300
1297 @@ -24,7 +24,7 @@
1298  // Philippose - 14.02.2009\r
1299  // Modifications for creating a DLL in Windows\r
1300  #ifdef WIN32\r
1301 -   #ifdef NGLIB_EXPORTS || nglib_EXPORTS\r
1302 +   #if defined NGLIB_EXPORTS || defined nglib_EXPORTS
1303        #define DLL_HEADER   __declspec(dllexport)\r
1304     #else\r
1305        #define DLL_HEADER   __declspec(dllimport)\r