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