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