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