1 diff -Naur netgen-4.9.13_orig/libsrc/meshing/meshtype.cpp netgen-4.9.13_new/libsrc/meshing/meshtype.cpp
2 --- netgen-4.9.13_orig/libsrc/meshing/meshtype.cpp 2009-09-13 14:28:38.000000000 +0400
3 +++ netgen-4.9.13_new/libsrc/meshing/meshtype.cpp 2014-07-22 13:01:28.000000000 +0400
6 +#include <float.h> // to get DBL_MIN defined
12 double det = trans.Det();
16 + if (det <= DBL_MIN) // avoid FPE
19 err += frob * frob / det;
22 double det = trans(0,0)*trans(1,1)-trans(1,0)*trans(0,1);
26 + if (det <= DBL_MIN) // avoid FPE
31 = dtrans(0,0) * trans(1,1) - trans(0,1) * dtrans(1,0)
32 + trans(0,0) * dtrans(1,1) - dtrans(0,1) * trans(1,0);
36 + if (det <= DBL_MIN) // avoid FPE
43 double det = trans.Det();
46 + if (det <= DBL_MIN) // avoid FPE
49 err += frob * frob / det;
54 - if (noz == 0.0) noz = 1e-10;
55 + //if (noz == 0.0) noz = 1e-10;
56 + if (noz <= DBL_MIN) noz = 1e-10; // avoid FPE
58 double xi = p(0) / noz;
59 double eta = p(1) / noz;
62 double det = -trans.Det();
66 + if (det <= DBL_MIN) // avoid FPE
69 err += frob * frob * frob / det;
76 + if (det <= DBL_MIN) // avoid FPE
89 @@ -2522,10 +2530,10 @@
91 MeshingParameters :: MeshingParameters ()
93 - optimize3d = "cmdmustm";
94 + optimize3d = (char*)"cmdmustm"; // optimize3d = "cmdmustm";
95 //optimize3d = "cmdmstm";
97 - optimize2d = "smsmsmSmSmSm";
98 + optimize2d = (char*)"smsmsmSmSmSm"; // optimize2d = "smsmsmSmSmSm";
102 diff -Naur netgen-4.9.13_orig/libsrc/meshing/meshtype.hpp netgen-4.9.13_new/libsrc/meshing/meshtype.hpp
103 --- netgen-4.9.13_orig/libsrc/meshing/meshtype.hpp 2009-11-09 13:50:43.000000000 +0300
104 +++ netgen-4.9.13_new/libsrc/meshing/meshtype.hpp 2014-07-22 13:01:28.000000000 +0400
109 +class Mesh; // added due to compilation errors on some platforms
112 SEGMENT = 1, SEGMENT3 = 2,
113 diff -Naur netgen-4.9.13_orig/libsrc/meshing/smoothing2.cpp netgen-4.9.13_new/libsrc/meshing/smoothing2.cpp
114 --- netgen-4.9.13_orig/libsrc/meshing/smoothing2.cpp 2009-11-09 13:47:09.000000000 +0300
115 +++ netgen-4.9.13_new/libsrc/meshing/smoothing2.cpp 2014-07-22 13:01:28.000000000 +0400
120 - meshthis -> GetNormalVector (surfi, sp1, gi1, n);
121 + //normal already computed: meshthis -> GetNormalVector (surfi, sp1, gi1, n);
123 pp1 = sp1 + x(0) * t1 + x(1) * t2;
125 // meshthis -> ProjectPoint (surfi, pp1);
130 - meshthis -> GetNormalVector (surfi, sp1, gi1, n);
131 + //normal already computed: meshthis -> GetNormalVector (surfi, sp1, gi1, n);
134 pp1 = sp1 + x(0) * t1 + x(1) * t2;
140 - meshthis -> GetNormalVector (surfi, sp1, gi1, n);
141 + //normal already computed: meshthis -> GetNormalVector (surfi, sp1, gi1, n);
144 pp1 = sp1 + x(0) * t1 + x(1) * t2;
150 - meshthis -> GetNormalVector (surfi, sp1, gi1, n);
151 + //normal already computed: meshthis -> GetNormalVector (surfi, sp1, gi1, n);
155 // pp1.Add2 (x.Get(1), t1, x.Get(2), t2);
158 mesh[pi] = Point<3> (origp);
161 + break; // exit as <fact> is not used anymore
165 diff -Naur netgen-4.9.13_orig/libsrc/occ/occconstruction.cpp netgen-4.9.13_new/libsrc/occ/occconstruction.cpp
166 --- netgen-4.9.13_orig/libsrc/occ/occconstruction.cpp 2009-08-24 06:32:47.000000000 +0400
167 +++ netgen-4.9.13_new/libsrc/occ/occconstruction.cpp 2014-07-22 13:01:28.000000000 +0400
169 #include <BRepAlgoAPI_Common.hxx>
170 #include <BRepAlgoAPI_Fuse.hxx>
171 #include <BRepAlgoAPI_Section.hxx>
172 -#include <BRepOffsetAPI_Sewing.hxx>
173 +//#include <BRepOffsetAPI_Sewing.hxx>
174 //#include <BRepAlgo_Sewing.hxx>
175 #include <BRepOffsetAPI_MakeOffsetShape.hxx>
176 #include <ShapeFix_Shape.hxx>
177 diff -Naur netgen-4.9.13_orig/libsrc/occ/occgenmesh.cpp netgen-4.9.13_new/libsrc/occ/occgenmesh.cpp
178 --- netgen-4.9.13_orig/libsrc/occ/occgenmesh.cpp 2010-03-16 09:30:07.000000000 +0300
179 +++ netgen-4.9.13_new/libsrc/occ/occgenmesh.cpp 2014-07-22 13:01:28.000000000 +0400
182 #define DIVIDEEDGESECTIONS 1000
183 #define IGNORECURVELENGTH 1e-4
184 +// a small value used to avoid FPE
185 +#define VSMALL 1e-10
188 bool merge_solids = 1;
192 Point<3> p = p0 + 0.5*n;
193 - double lambda = (p-l.p0)*n / nq;
194 + // double lambda = (p-l.p0)*n / nq; -- avoid FPE
195 + double lambda = (fabs(nq) > 1e-10) ? (p-l.p0)*n / nq : -1;
197 if (lambda >= 0 && lambda <= 1)
204 + static // useless out of this file
205 double ComputeH (double kappa)
209 if (mparam.maxh * kappa < 1)
213 + // hret = 1 / kappa; -- avoid FPE
214 + hret = 1 / (kappa + VSMALL);
216 if (mparam.maxh < hret)
224 + static // useless out of this file
225 void RestrictHTriangle (gp_Pnt2d & par0, gp_Pnt2d & par1, gp_Pnt2d & par2,
226 BRepLProp_SLProps * prop, Mesh & mesh, int depth, double h = 0)
233 - if (h > 30) return;
234 + // commented to restrict H on a large sphere for example
235 + //if (h > 30) return;
238 if (h < maxside && depth < 10)
243 + static // useless out of this file
244 void DivideEdge (TopoDS_Edge & edge, Array<MeshPoint> & ps,
245 Array<double> & params, Mesh & mesh)
251 - double olddist = 0;
253 + //double olddist = 0; -- useless variables
256 int tmpVal = (int)(DIVIDEEDGESECTIONS);
258 @@ -256,15 +262,19 @@
261 pnt = c->Value(s0+(i/double(DIVIDEEDGESECTIONS))*(s1-s0));
262 + // -- no more than 1 segment per <edge length>/DIVIDEEDGESECTIONS
263 hvalue[i] = hvalue[i-1] +
264 - 1.0/mesh.GetH(Point3d(pnt.X(), pnt.Y(), pnt.Z()))*
265 - pnt.Distance(oldpnt);
266 + // 1.0/mesh.GetH(Point3d(pnt.X(), pnt.Y(), pnt.Z()))*
267 + // pnt.Distance(oldpnt);
269 + 1.0/mesh.GetH(Point3d(pnt.X(), pnt.Y(), pnt.Z()))*
270 + pnt.Distance(oldpnt));
272 //(*testout) << "mesh.GetH(Point3d(pnt.X(), pnt.Y(), pnt.Z())) " << mesh.GetH(Point3d(pnt.X(), pnt.Y(), pnt.Z()))
273 // << " pnt.Distance(oldpnt) " << pnt.Distance(oldpnt) << endl;
276 - dist = pnt.Distance(oldpnt);
277 + //olddist = dist; -- useless variables
278 + //dist = pnt.Distance(oldpnt);
281 // nsubedges = int(ceil(hvalue[DIVIDEEDGESECTIONS]));
284 if (hvalue[i1]/hvalue[DIVIDEEDGESECTIONS]*nsubedges >= i)
286 - params[i] = s0+(i1/double(DIVIDEEDGESECTIONS))*(s1-s0);
287 + // -- for nsubedges comparable to DIVIDEEDGESECTIONS
288 + //params[i] = s0+(i1/double(DIVIDEEDGESECTIONS))*(s1-s0);
289 + double d1 = i1 - (hvalue[i1] - i*hvalue[DIVIDEEDGESECTIONS]/nsubedges)/(hvalue[i1]-hvalue[i1-1]);
290 + params[i] = s0+(d1/double(DIVIDEEDGESECTIONS))*(s1-s0);
291 pnt = c->Value(params[i]);
292 ps[i-1] = MeshPoint (Point3d(pnt.X(), pnt.Y(), pnt.Z()));
295 (*testout) << "nedges = " << nedges << endl;
297 double eps = 1e-6 * geom.GetBoundingBox().Diam();
298 + const double eps2 = eps * eps; // -- small optimization
300 + int first_vp = mesh.GetNP()+1; // -- to support SALOME sub-meshes
302 for (int i = 1; i <= nvertices; i++)
307 for (PointIndex pi = 1; pi <= mesh.GetNP(); pi++)
308 - if ( Dist2 (mesh[pi], Point<3>(mp)) < eps*eps)
309 + //if ( Dist2 (mesh[pi], Point<3>(mp)) < eps*eps)
310 + if ( Dist2 (mesh[pi], Point<3>(mp)) < eps2 ) // -- small optimization
316 TopoDS_Face face = TopoDS::Face(exp1.Current());
317 int facenr = geom.fmap.FindIndex(face);
318 + if ( facenr < 1 ) continue; // -- to support SALOME sub-meshes
320 if (face2solid[0][facenr-1] == 0)
321 face2solid[0][facenr-1] = solidnr;
326 + edgenr = mesh.GetNSeg(); // to support SALOME sub-meshes
328 (*testout) << "faces = " << geom.fmap.Extent() << endl;
331 //(*testout) << "ignoring degenerated edge" << endl;
334 + if ( geom.emap.FindIndex(edge) < 1 ) continue; // to support SALOME sub-meshes
336 if (geom.vmap.FindIndex(TopExp::FirstVertex (edge)) ==
337 geom.vmap.FindIndex(TopExp::LastVertex (edge)))
338 @@ -474,20 +494,104 @@
342 - pnums[0] = geom.vmap.FindIndex (TopExp::FirstVertex (edge));
343 - pnums[pnums.Size()-1] = geom.vmap.FindIndex (TopExp::LastVertex (edge));
344 + //pnums[0] = geom.vmap.FindIndex (TopExp::FirstVertex (edge));
345 + //pnums[pnums.Size()-1] = geom.vmap.FindIndex (TopExp::LastVertex (edge));
346 + MeshPoint dfltP ( Point<3> ( 0, 0, 0 ) );
347 + int *ipp[] = { &pnums[0], &pnums[pnums.Size()-1] };
348 + TopoDS_Iterator vIt( edge, false );
349 + TopoDS_Vertex v[2];
350 + v[0] = TopoDS::Vertex( vIt.Value() ); vIt.Next();
351 + v[1] = TopoDS::Vertex( vIt.Value() );
352 + if ( v[0].Orientation() == TopAbs_REVERSED )
353 + std::swap( v[0], v[1] );
354 + for ( int i = 0; i < 2; ++i)
357 + ip = geom.vmap.FindIndex ( v[i] );
358 + if ( ip == 0 || ip > nvertices )
362 + ip = iv = geom.vmap.Add( v[i] );
363 + gp_Pnt pnt = BRep_Tool::Pnt( v[i] );
364 + MeshPoint mp( Point<3>(pnt.X(), pnt.Y(), pnt.Z()) );
365 + for (PointIndex pi = 1; pi < first_vp; pi++)
366 + if ( Dist2 (mesh.Point(pi), Point<3>(mp)) < 1e-100 )
369 + if ( mesh.Point(ip).GetLayer() != dfltP.GetLayer() && mesh.Point(ip).GetLayer() != iv )
371 + if ( mesh.Point(ip).GetLayer() == dfltP.GetLayer())
372 + mesh.Point(ip) = MeshPoint( mesh.Point(ip), iv );
378 + ip += first_vp - 1;
384 - Point<3> fp = occ2ng (BRep_Tool::Pnt (TopExp::FirstVertex (edge)));
385 - Point<3> lp = occ2ng (BRep_Tool::Pnt (TopExp::LastVertex (edge)));
386 + TopoDS_Iterator vIt( edge, false );
387 + TopoDS_Vertex v1 = TopoDS::Vertex( vIt.Value() ); vIt.Next();
388 + TopoDS_Vertex v2 = TopoDS::Vertex( vIt.Value() );
389 + if ( v1.Orientation() == TopAbs_REVERSED )
390 + std::swap( v1, v2 );
391 + const bool isClosedEdge = v1.IsSame( v2 );
393 + Point<3> fp = occ2ng (BRep_Tool::Pnt (v1));
394 + Point<3> lp = occ2ng (BRep_Tool::Pnt (v2));
395 + double tol2 = std::min( eps*eps, 1e-6 * Dist2( fp, lp ));
396 + if ( isClosedEdge )
397 + tol2 = BRep_Tool::Tolerance( v1 ) * BRep_Tool::Tolerance( v1 );
401 for (PointIndex pi = 1; pi < first_ep; pi++)
403 - if (Dist2 (mesh[pi], fp) < eps*eps) pnums[0] = pi;
404 - if (Dist2 (mesh[pi], lp) < eps*eps) pnums.Last() = pi;
405 + if (Dist2 (mesh[pi], fp) < tol2) pnums[0] = pi;
406 + if (Dist2 (mesh[pi], lp) < tol2) pnums.Last() = pi;
408 + if (( isClosedEdge && pnums[0] != pnums.Last() ) ||
409 + ( !isClosedEdge && pnums[0] == pnums.Last() ))
410 + pnums[0] = pnums.Last() = -1;
411 + if ( pnums[0] == -1 || pnums.Last() == -1 )
413 + // take into account a possible large gap between a vertex and an edge curve
414 + // end and a large vertex tolerance covering the whole edge
415 + if ( pnums[0] == -1 )
417 + double tol = BRep_Tool::Tolerance( v1 );
418 + for (PointIndex pi = 1; pi < first_ep; pi++)
419 + if (pi != pnums.Last() && Dist2 (mesh[pi], fp) < 2*tol*tol)
422 + if ( pnums[0] == -1 )
423 + pnums[0] = first_ep-1- nvertices + geom.vmap.FindIndex ( v1 );
425 + if ( isClosedEdge )
427 + pnums.Last() = pnums[0];
431 + if ( pnums.Last() == -1 )
433 + double tol = BRep_Tool::Tolerance( v2 );
434 + for (PointIndex pi = 1; pi < first_ep; pi++)
435 + if (pi != pnums[0] && Dist2 (mesh[pi], lp) < 2*tol*tol)
438 + if ( pnums.Last() == -1 )
439 + pnums.Last() = first_ep-1-nvertices + geom.vmap.FindIndex ( v2 );
442 + if ( Dist2( fp, mesh[PointIndex(pnums[0])]) >
443 + Dist2( lp, mesh[PointIndex(pnums.Last())]))
444 + std::swap( pnums[0], pnums.Last() );
449 @@ -497,17 +601,20 @@
452 for (j = first_ep; j <= mesh.GetNP(); j++)
454 + if (!merge_solids && mesh.Point(j).GetLayer() != geomedgenr ) continue; // to support SALOME fuse edges
455 if ((mesh.Point(j)-Point<3>(mp[i-1])).Length() < eps)
466 - mesh.AddPoint (mp[i-1]);
467 + mesh.AddPoint (mp[i-1], geomedgenr); // to support SALOME fuse edges
468 (*testout) << "add meshpoint " << mp[i-1] << endl;
469 pnums[i] = mesh.GetNP();
472 // (*testout) << "edge " << mesh.LineSegment(i).edgenr << " face " << mesh.LineSegment(i).si
473 // << " p1 " << mesh.LineSegment(i)[0] << " p2 " << mesh.LineSegment(i)[1] << endl;
475 + for (int j = 1; j <= mesh.GetNP(); j++) // to support SALOME fuse edges: set level to zero
476 + mesh.Point(j) = MeshPoint( (Point<3>&) mesh.Point(j) );
478 mesh.CalcSurfacesOfNode();
479 multithread.task = savetask;
483 (*testout) << "mesh face " << k << endl;
484 - multithread.percent = 100 * k / (mesh.GetNFD()+1e-10);
485 + // multithread.percent = 100 * k / (mesh.GetNFD()+1e-10); -- avoid FPE
486 + multithread.percent = 100 * k / (mesh.GetNFD() + VSMALL);
487 geom.facemeshstatus[k-1] = -1;
491 // if (k != 36) continue;
493 // (*testout) << "optimize face " << k << endl;
494 - multithread.percent = 100 * k / (mesh.GetNFD()+1e-10);
495 + //multithread.percent = 100 * k / (mesh.GetNFD()+1e-10); -- avoid FPE
496 + multithread.percent = 100 * k / (mesh.GetNFD() + VSMALL);
498 FaceDescriptor & fd = mesh.GetFaceDescriptor(k);
500 @@ -1456,3 +1567,4 @@
505 diff -Naur netgen-4.9.13_orig/libsrc/occ/occgeom.cpp netgen-4.9.13_new/libsrc/occ/occgeom.cpp
506 --- netgen-4.9.13_orig/libsrc/occ/occgeom.cpp 2010-03-05 16:16:21.000000000 +0300
507 +++ netgen-4.9.13_new/libsrc/occ/occgeom.cpp 2014-07-22 13:01:28.000000000 +0400
509 #include "ShapeAnalysis_CheckSmallFace.hxx"
510 #include "ShapeAnalysis_DataMapOfShapeListOfReal.hxx"
511 #include "ShapeAnalysis_Surface.hxx"
512 +#include <BRepTopAdaptor_FClass2d.hxx> // -- to optimize Project() and FastProject()
513 +#include <TopAbs_State.hxx>
514 #include "BRepAlgoAPI_Fuse.hxx"
515 #include "BRepCheck_Analyzer.hxx"
516 #include "BRepLib.hxx"
518 #include "ShapeFix_FixSmallFace.hxx"
519 #include "Partition_Spliter.hxx"
524 - void OCCGeometry :: PrintNrShapes ()
525 + // free data used to optimize Project() and FastProject()
526 + OCCGeometry::~OCCGeometry()
528 + NCollection_DataMap<int,BRepTopAdaptor_FClass2d*>::Iterator it(fclsmap);
529 + for (; it.More(); it.Next())
533 + void OCCGeometry :: PrintNrShapes ()
537 @@ -951,25 +960,58 @@
541 + // returns a projector and a classifier for the given surface
542 + void OCCGeometry::GetFaceTools(int surfi, Handle(ShapeAnalysis_Surface)& proj,
543 + BRepTopAdaptor_FClass2d*& cls) const
545 + //MSV: organize caching projector in the map
546 + if (fprjmap.IsBound(surfi))
548 + proj = fprjmap.Find(surfi);
549 + cls = fclsmap.Find(surfi);
553 + const TopoDS_Face& aFace = TopoDS::Face(fmap(surfi));
554 + Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
555 + proj = new ShapeAnalysis_Surface(aSurf);
556 + fprjmap.Bind(surfi, proj);
557 + cls = new BRepTopAdaptor_FClass2d(aFace,Precision::Confusion());
558 + fclsmap.Bind(surfi, cls);
563 - void OCCGeometry :: Project (int surfi, Point<3> & p) const
564 + // void OCCGeometry :: Project (int surfi, Point<3> & p) const
565 + bool OCCGeometry :: Project (int surfi, Point<3> & p, double& u, double& v) const
568 if (++cnt % 1000 == 0) cout << "Project cnt = " << cnt << endl;
570 gp_Pnt pnt(p(0), p(1), p(2));
573 - Handle( Geom_Surface ) thesurf = BRep_Tool::Surface(TopoDS::Face(fmap(surfi)));
574 - Handle( ShapeAnalysis_Surface ) su = new ShapeAnalysis_Surface( thesurf );
575 - gp_Pnt2d suval = su->ValueOfUV ( pnt, BRep_Tool::Tolerance( TopoDS::Face(fmap(surfi)) ) );
576 - suval.Coord( u, v);
577 - pnt = thesurf->Value( u, v );
580 + // -- Optimization: use cached projector and classifier
582 + // Handle( Geom_Surface ) thesurf = BRep_Tool::Surface(TopoDS::Face(fmap(surfi)));
583 + // Handle( ShapeAnalysis_Surface ) su = new ShapeAnalysis_Surface( thesurf );
584 + // gp_Pnt2d suval = su->ValueOfUV ( pnt, BRep_Tool::Tolerance( TopoDS::Face(fmap(surfi)) ) );
585 + // suval.Coord( u, v);
586 + // pnt = thesurf->Value( u, v );
588 + Handle(ShapeAnalysis_Surface) proj;
589 + BRepTopAdaptor_FClass2d *cls;
590 + GetFaceTools(surfi, proj, cls);
592 + gp_Pnt2d p2d = proj->ValueOfUV(pnt, Precision::Confusion());
593 + if (cls->Perform(p2d) == TopAbs_OUT)
597 + pnt = proj->Value(p2d);
600 p = Point<3> (pnt.X(), pnt.Y(), pnt.Z());
606 @@ -979,54 +1021,69 @@
608 gp_Pnt p(ap(0), ap(1), ap(2));
610 - Handle(Geom_Surface) surface = BRep_Tool::Surface(TopoDS::Face(fmap(surfi)));
612 - gp_Pnt x = surface->Value (u,v);
614 - if (p.SquareDistance(x) <= sqr(PROJECTION_TOLERANCE)) return true;
618 - surface->D1(u,v,x,du,dv);
624 - double det, lambda, mu;
631 - det = Det3 (n.X(), du.X(), dv.X(),
632 - n.Y(), du.Y(), dv.Y(),
633 - n.Z(), du.Z(), dv.Z());
635 - if (det < 1e-15) return false;
637 - lambda = Det3 (n.X(), p.X()-x.X(), dv.X(),
638 - n.Y(), p.Y()-x.Y(), dv.Y(),
639 - n.Z(), p.Z()-x.Z(), dv.Z())/det;
641 - mu = Det3 (n.X(), du.X(), p.X()-x.X(),
642 - n.Y(), du.Y(), p.Y()-x.Y(),
643 - n.Z(), du.Z(), p.Z()-x.Z())/det;
649 - surface->D1(u,v,x,du,dv);
651 - } while (xold.SquareDistance(x) > sqr(PROJECTION_TOLERANCE) && count < 50);
653 - // (*testout) << "FastProject count: " << count << endl;
655 - if (count == 50) return false;
657 - ap = Point<3> (x.X(), x.Y(), x.Z());
658 + // -- Optimization: use cached projector and classifier
659 + // Handle(Geom_Surface) surface = BRep_Tool::Surface(TopoDS::Face(fmap(surfi)));
661 + // gp_Pnt x = surface->Value (u,v);
663 + // if (p.SquareDistance(x) <= sqr(PROJECTION_TOLERANCE)) return true;
667 + // surface->D1(u,v,x,du,dv);
673 + // double det, lambda, mu;
680 + // det = Det3 (n.X(), du.X(), dv.X(),
681 + // n.Y(), du.Y(), dv.Y(),
682 + // n.Z(), du.Z(), dv.Z());
684 + // if (det < 1e-15) return false;
686 + // lambda = Det3 (n.X(), p.X()-x.X(), dv.X(),
687 + // n.Y(), p.Y()-x.Y(), dv.Y(),
688 + // n.Z(), p.Z()-x.Z(), dv.Z())/det;
690 + // mu = Det3 (n.X(), du.X(), p.X()-x.X(),
691 + // n.Y(), du.Y(), p.Y()-x.Y(),
692 + // n.Z(), du.Z(), p.Z()-x.Z())/det;
698 + // surface->D1(u,v,x,du,dv);
700 + // } while (xold.SquareDistance(x) > sqr(PROJECTION_TOLERANCE) && count < 50);
702 + // // (*testout) << "FastProject count: " << count << endl;
704 + // if (count == 50) return false;
706 + // ap = Point<3> (x.X(), x.Y(), x.Z());
707 + Handle(ShapeAnalysis_Surface) proj;
708 + BRepTopAdaptor_FClass2d *cls;
709 + GetFaceTools(surfi, proj, cls);
711 + gp_Pnt2d p2d = proj->NextValueOfUV(gp_Pnt2d(u,v), p, Precision::Confusion());
712 + if (cls->Perform(p2d) == TopAbs_OUT)
714 + //cout << "Projection fails" << endl;
718 + p = proj->Value(p2d);
720 + ap = Point<3> (p.X(), p.Y(), p.Z());
724 @@ -1038,9 +1095,9 @@
726 cout << "writing stl..."; cout.flush();
727 StlAPI_Writer writer;
728 - writer.RelativeMode() = Standard_False;
729 + // writer.RelativeMode() = Standard_False;
731 - writer.SetDeflection(0.02);
732 + // writer.SetDeflection(0.02);
733 writer.Write(shape,filename);
735 cout << "done" << endl;
736 diff -Naur netgen-4.9.13_orig/libsrc/occ/occgeom.hpp netgen-4.9.13_new/libsrc/occ/occgeom.hpp
737 --- netgen-4.9.13_orig/libsrc/occ/occgeom.hpp 2010-01-14 19:56:19.000000000 +0300
738 +++ netgen-4.9.13_new/libsrc/occ/occgeom.hpp 2014-07-22 13:09:03.000000000 +0400
740 #include "Geom_Curve.hxx"
741 #include "Geom2d_Curve.hxx"
742 #include "Geom_Surface.hxx"
743 -#include "GeomAPI_ProjectPointOnSurf.hxx"
744 -#include "GeomAPI_ProjectPointOnCurve.hxx"
745 +// #include "GeomAPI_ProjectPointOnSurf.hxx"
746 +// #include "GeomAPI_ProjectPointOnCurve.hxx"
747 #include "BRepTools.hxx"
748 #include "TopExp.hxx"
749 #include "BRepBuilderAPI_MakeVertex.hxx"
751 #include "Geom_Curve.hxx"
752 #include "Geom2d_Curve.hxx"
753 #include "Geom_Surface.hxx"
754 -#include "GeomAPI_ProjectPointOnSurf.hxx"
755 -#include "GeomAPI_ProjectPointOnCurve.hxx"
756 +// #include "GeomAPI_ProjectPointOnSurf.hxx"
757 +// #include "GeomAPI_ProjectPointOnCurve.hxx"
758 #include "TopoDS_Wire.hxx"
759 #include "BRepTools_WireExplorer.hxx"
760 #include "BRepTools.hxx"
762 #include "IGESToBRep_Reader.hxx"
763 #include "Interface_Static.hxx"
764 #include "GeomAPI_ExtremaCurveCurve.hxx"
765 -#include "Standard_ErrorHandler.hxx"
766 +//#include "Standard_ErrorHandler.hxx"
767 #include "Standard_Failure.hxx"
768 #include "ShapeUpgrade_ShellSewing.hxx"
769 #include "ShapeFix_Shape.hxx"
770 #include "ShapeFix_Wireframe.hxx"
771 +#include <Standard_Version.hxx>
772 +#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) <= 0x060702
773 +// porting to OCCT6.7.3
774 #include "BRepMesh.hxx"
776 #include "BRepMesh_IncrementalMesh.hxx"
777 #include "BRepBndLib.hxx"
778 #include "Bnd_Box.hxx"
779 #include "ShapeAnalysis.hxx"
780 #include "ShapeBuild_ReShape.hxx"
782 +// -- Optimization: to use cached projector and classifier
783 +#include <NCollection_DataMap.hxx>
784 +class Handle_ShapeAnalysis_Surface;
785 +class BRepTopAdaptor_FClass2d;
787 // Philippose - 29/01/2009
788 // OpenCascade XDE Support
790 class OCCGeometry : public NetgenGeometry
793 + // -- Optimization: to use cached projector and classifier
794 + mutable NCollection_DataMap<int,Handle_ShapeAnalysis_Surface> fprjmap;
795 + mutable NCollection_DataMap<int,BRepTopAdaptor_FClass2d*> fclsmap;
803 + ~OCCGeometry(); // -- to free cached projector and classifier
807 Box<3> GetBoundingBox()
812 - void Project (int surfi, Point<3> & p) const;
813 + // void Project (int surfi, Point<3> & p) const; -- optimization
814 + bool Project (int surfi, Point<3> & p, double& u, double& v) const;
815 bool FastProject (int surfi, Point<3> & ap, double& u, double& v) const;
817 + // -- Optimization: to use cached projector and classifier
818 + void GetFaceTools(int surfi, Handle(ShapeAnalysis_Surface)& proj,
819 + BRepTopAdaptor_FClass2d*& cls) const;
821 OCCSurface GetSurface (int surfi)
823 cout << "OCCGeometry::GetSurface using PLANESPACE" << endl;
824 diff -Naur netgen-4.9.13_orig/libsrc/occ/occmeshsurf.cpp netgen-4.9.13_new/libsrc/occ/occmeshsurf.cpp
825 --- netgen-4.9.13_orig/libsrc/occ/occmeshsurf.cpp 2009-08-24 06:32:47.000000000 +0400
826 +++ netgen-4.9.13_new/libsrc/occ/occmeshsurf.cpp 2014-07-22 13:01:28.000000000 +0400
828 #include <meshing.hpp>
829 #include <GeomLProp_SLProps.hxx>
830 #include <ShapeAnalysis_Surface.hxx>
831 +#include <GeomAPI_ProjectPointOnCurve.hxx> // -- moved here from occgeom.hpp
835 @@ -434,23 +435,33 @@
837 void MeshOptimize2dOCCSurfaces :: ProjectPoint (INDEX surfind, Point<3> & p) const
839 - geometry.Project (surfind, p);
840 + // geometry.Project (surfind, p); -- signature of Project() changed for optimization
842 + geometry.Project (surfind, p, u, v);
846 int MeshOptimize2dOCCSurfaces :: ProjectPointGI (INDEX surfind, Point<3> & p, PointGeomInfo & gi) const
854 - if (geometry.FastProject (surfind, hp, u, v))
859 - ProjectPoint (surfind, p);
860 - return CalcPointGeomInfo (surfind, gi, p);
861 + // -- u and v are computed by FastProject() and Project(), no need to call CalcPointGeomInfo()
862 + // if (geometry.FastProject (surfind, hp, u, v))
867 + // ProjectPoint (surfind, p);
868 + // return CalcPointGeomInfo (surfind, gi, p);
870 + if (gi.trignum > 0)
871 + ok = geometry.FastProject (surfind, hp, gi.u, gi.v);
873 + ok = geometry.Project (surfind, hp, gi.u, gi.v);
880 if (!geometry.FastProject (surfi, hnewp, u, v))
882 // cout << "Fast projection to surface fails! Using OCC projection" << endl;
883 - geometry.Project (surfi, hnewp);
884 + // geometry.Project (surfi, hnewp); -- Project() changed for optimization
885 + geometry.Project (surfi, hnewp, u, v);
894 + }//; -- to compile with -Wall -pedantic
897 void OCCRefinementSurfaces ::
898 @@ -708,14 +720,18 @@
899 hnewp = Point<3> (pnt.X(), pnt.Y(), pnt.Z());
906 void OCCRefinementSurfaces :: ProjectToSurface (Point<3> & p, int surfi)
909 - geometry.Project (surfi, p);
911 + // geometry.Project (surfi, p); -- Project() changed for optimization
914 + geometry.Project (surfi, p, u, v);
916 + }//; -- to compile with -Wall -pedantic
918 void OCCRefinementSurfaces :: ProjectToSurface (Point<3> & p, int surfi, PointGeomInfo & gi)
921 if (!geometry.FastProject (surfi, p, gi.u, gi.v))
923 cout << "Fast projection to surface fails! Using OCC projection" << endl;
924 - geometry.Project (surfi, p);
926 + geometry.Project (surfi, p, u, v);
933 diff -Naur netgen-4.9.13_orig/libsrc/occ/Partition_Inter3d.cxx netgen-4.9.13_new/libsrc/occ/Partition_Inter3d.cxx
934 --- netgen-4.9.13_orig/libsrc/occ/Partition_Inter3d.cxx 2009-08-24 06:12:24.000000000 +0400
935 +++ netgen-4.9.13_new/libsrc/occ/Partition_Inter3d.cxx 2014-07-22 13:01:28.000000000 +0400
937 #include <TopOpeBRepTool_OutCurveType.hxx>
938 #include <TopOpeBRep_DSFiller.hxx>
939 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
941 +#include <Standard_Version.hxx>
945 //=======================================================================
947 Standard_Integer i, nbExt = anExtPS.NbExt();
948 Extrema_POnSurf aPOnSurf;
949 for (i = 1; i <= nbExt; ++i )
950 +#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060400
951 +// porting to OCCT6.5.1
952 + if (anExtPS.SquareDistance( i ) <= TolE * TolE) {
954 if (anExtPS.Value( i ) <= TolE) {
956 aPOnSurf = anExtPS.Point( i );
959 diff -Naur netgen-4.9.13_orig/libsrc/occ/Partition_Loop2d.cxx netgen-4.9.13_new/libsrc/occ/Partition_Loop2d.cxx
960 --- netgen-4.9.13_orig/libsrc/occ/Partition_Loop2d.cxx 2009-08-24 06:12:24.000000000 +0400
961 +++ netgen-4.9.13_new/libsrc/occ/Partition_Loop2d.cxx 2014-07-22 13:01:28.000000000 +0400
963 #include <BRepAdaptor_Surface.hxx>
964 #include <BRepAlgo_AsDes.hxx>
965 #include <BRepAlgo_FaceRestrictor.hxx>
966 -#include <BRepOffset_DataMapOfShapeReal.hxx>
967 #include <BRepTopAdaptor_FClass2d.hxx>
968 #include <BRep_Builder.hxx>
969 #include <BRep_Tool.hxx>
971 #include <gp_Pnt.hxx>
972 #include <gp_Pnt2d.hxx>
974 +#include <Standard_Version.hxx>
976 +#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060400
977 +// porting to OCCT6.5.1
978 +#include <TopTools_DataMapOfShapeReal.hxx>
980 +#include <BRepOffset_DataMapOfShapeReal.hxx>
983 //=======================================================================
984 //function : Partition_Loop2d
987 Cc->D1(uc, PC, CTg1);
988 if (!isForward) CTg1.Reverse();
990 - Standard_Real anglemin = 3 * PI, tolAng = 1.e-8;
991 + Standard_Real anglemin = 3 * M_PI, tolAng = 1.e-8;
993 // select an edge whose first derivative is most left of CTg1
994 // ie an angle between Tg1 and CTg1 is least
997 Standard_Real angle = Tg1.Angle(CTg1);
999 - if (PI - Abs(angle) <= tolAng)
1000 + if (M_PI - Abs(angle) <= tolAng)
1002 // an angle is too close to PI; assure that an angle sign really
1003 // reflects an edge position: +PI - an edge is worst,
1004 @@ -519,7 +527,12 @@
1005 DC.Initialize( DegEdge, F );
1007 // avoid intersecting twice the same edge
1008 +#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060400
1009 +// porting to OCCT6.5.1
1010 + TopTools_DataMapOfShapeReal EUMap ( EdgesList.Extent() );
1012 BRepOffset_DataMapOfShapeReal EUMap ( EdgesList.Extent() );
1015 Standard_Real U, f, l;
1016 BRep_Tool::Range (DegEdge, f, l);
1017 diff -Naur netgen-4.9.13_orig/libsrc/occ/Partition_Loop.cxx netgen-4.9.13_new/libsrc/occ/Partition_Loop.cxx
1018 --- netgen-4.9.13_orig/libsrc/occ/Partition_Loop.cxx 2009-08-24 06:12:24.000000000 +0400
1019 +++ netgen-4.9.13_new/libsrc/occ/Partition_Loop.cxx 2014-07-22 13:01:28.000000000 +0400
1024 - Standard_Real anglemax = - PI;
1025 + Standard_Real anglemax = - M_PI;
1026 TopoDS_Edge SelectedEdge;
1027 for ( itl.Initialize(LE); itl.More(); itl.Next()) {
1028 const TopoDS_Edge& E = TopoDS::Edge(itl.Value());
1029 diff -Naur netgen-4.9.13_orig/libsrc/occ/Partition_Spliter.cxx netgen-4.9.13_new/libsrc/occ/Partition_Spliter.cxx
1030 --- netgen-4.9.13_orig/libsrc/occ/Partition_Spliter.cxx 2009-08-24 06:12:24.000000000 +0400
1031 +++ netgen-4.9.13_new/libsrc/occ/Partition_Spliter.cxx 2014-07-22 13:01:28.000000000 +0400
1033 #include <GeomAdaptor_Curve.hxx>
1034 #include <TopOpeBRepTool_CurveTool.hxx>
1036 +#include <Standard_Version.hxx>
1039 //# define PART_PERF
1041 @@ -1169,7 +1171,12 @@
1042 for (; j<=nbj && ok; ++j) {
1043 if (Extrema.IsMin(j)) {
1044 hasMin = Standard_True;
1045 +#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060400
1046 +// porting to OCCT6.5.1
1047 + ok = Extrema.SquareDistance(j) <= tol * tol;
1049 ok = Extrema.Value(j) <= tol;
1054 diff -Naur netgen-4.9.13_orig/libsrc/occ/utilities.h netgen-4.9.13_new/libsrc/occ/utilities.h
1055 --- netgen-4.9.13_orig/libsrc/occ/utilities.h 2009-08-24 06:12:24.000000000 +0400
1056 +++ netgen-4.9.13_new/libsrc/occ/utilities.h 2014-07-22 13:01:28.000000000 +0400
1063 // #include "SALOME_Log.hxx"
1065 diff -Naur netgen-4.9.13_orig/libsrc/stlgeom/stlgeommesh.cpp netgen-4.9.13_new/libsrc/stlgeom/stlgeommesh.cpp
1066 --- netgen-4.9.13_orig/libsrc/stlgeom/stlgeommesh.cpp 2009-08-10 15:40:51.000000000 +0400
1067 +++ netgen-4.9.13_new/libsrc/stlgeom/stlgeommesh.cpp 2014-07-22 13:01:28.000000000 +0400
1068 @@ -1435,7 +1435,8 @@
1070 if (!optstring || strlen(optstring) == 0)
1072 - mparam.optimize2d = "smcm";
1073 + //mparam.optimize2d = (char*)"smcm";
1074 + mparam.optimize2d = (char*)"smcm";
1078 @@ -1451,7 +1452,8 @@
1080 mesh -> LoadLocalMeshSize (mparam.meshsizefilename);
1081 mesh -> CalcLocalHFromSurfaceCurvature (stlparam.resthsurfmeshcurvfac);
1082 - mparam.optimize2d = "cmsmSm";
1083 + //mparam.optimize2d = (char*)"cmsmSm";
1084 + mparam.optimize2d = (char*)"cmsmSm";
1085 STLSurfaceOptimization (*stlgeometry, *mesh, mparam);
1087 (*statout) << GetTime() << " & ";
1088 @@ -1557,7 +1559,8 @@
1090 if (!optstring || strlen(optstring) == 0)
1092 - mparam.optimize3d = "cmdmstm";
1093 + //mparam.optimize3d = "cmdmstm";
1094 + mparam.optimize3d = (char*)"cmdmstm";
1098 diff -Naur netgen-4.9.13_orig/ng/Makefile.in netgen-4.9.13_new/ng/Makefile.in
1099 --- netgen-4.9.13_orig/ng/Makefile.in 2010-05-21 01:29:28.000000000 +0200
1100 +++ netgen-4.9.13_new/ng/Makefile.in 2016-05-26 14:39:47.128141997 +0200
1102 $(top_builddir)/libsrc/gprim/libgprim.la \
1103 $(top_builddir)/libsrc/linalg/libla.la \
1104 $(top_builddir)/libsrc/general/libgen.la \
1105 - $(OCCLIBS) -L$(TK_BIN_DIR)/Togl1.7 $(TOGLLIBDIR) -lTogl1.7 $(LIBGLU) $(TK_LIB_SPEC) $(TCL_LIB_SPEC) $(MPI_LIBS) $(FFMPEG_LIBS) $(JPEGLIB_LIBS) $(PKG_LIBS)
1106 + $(OCCLIBS) -L$(TK_BIN_DIR)/Togl1.7 $(TOGLLIBDIR) -lTogl $(LIBGLU) $(TK_LIB_SPEC) $(TCL_LIB_SPEC) $(MPI_LIBS) $(FFMPEG_LIBS) $(JPEGLIB_LIBS) $(PKG_LIBS)
1109 # add for static linkage of ngsolve:
1110 diff -Naur netgen-4.9.13_orig/nglib/nglib.h netgen-4.9.13_new/nglib/nglib.h
1111 --- netgen-4.9.13_orig/nglib/nglib.h 2010-05-18 15:20:25.000000000 +0400
1112 +++ netgen-4.9.13_new/nglib/nglib.h 2014-07-22 13:01:28.000000000 +0400
1114 // Philippose - 14.02.2009
1115 // Modifications for creating a DLL in Windows
1117 - #ifdef NGLIB_EXPORTS || nglib_EXPORTS
1118 + #if defined NGLIB_EXPORTS || defined nglib_EXPORTS
1119 #define DLL_HEADER __declspec(dllexport)
1121 #define DLL_HEADER __declspec(dllimport)