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 2013-05-31 11:28:04.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 2013-05-31 11:28:04.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 2013-05-31 11:28:04.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/Partition_Inter3d.cxx netgen-4.9.13_new/libsrc/occ/Partition_Inter3d.cxx
166 --- netgen-4.9.13_orig/libsrc/occ/Partition_Inter3d.cxx 2009-08-24 06:12:24.000000000 +0400
167 +++ netgen-4.9.13_new/libsrc/occ/Partition_Inter3d.cxx 2013-05-31 11:28:04.000000000 +0400
169 #include <TopOpeBRepTool_OutCurveType.hxx>
170 #include <TopOpeBRep_DSFiller.hxx>
171 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
173 +#include <Standard_Version.hxx>
177 //=======================================================================
179 Standard_Integer i, nbExt = anExtPS.NbExt();
180 Extrema_POnSurf aPOnSurf;
181 for (i = 1; i <= nbExt; ++i )
182 +#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060400
183 +// porting to OCCT6.5.1
184 + if (anExtPS.SquareDistance( i ) <= TolE * TolE) {
186 if (anExtPS.Value( i ) <= TolE) {
188 aPOnSurf = anExtPS.Point( i );
191 diff -Naur netgen-4.9.13_orig/libsrc/occ/Partition_Loop.cxx netgen-4.9.13_new/libsrc/occ/Partition_Loop.cxx
192 --- netgen-4.9.13_orig/libsrc/occ/Partition_Loop.cxx 2009-08-24 06:12:24.000000000 +0400
193 +++ netgen-4.9.13_new/libsrc/occ/Partition_Loop.cxx 2013-05-31 11:28:04.000000000 +0400
198 - Standard_Real anglemax = - PI;
199 + Standard_Real anglemax = - M_PI;
200 TopoDS_Edge SelectedEdge;
201 for ( itl.Initialize(LE); itl.More(); itl.Next()) {
202 const TopoDS_Edge& E = TopoDS::Edge(itl.Value());
203 diff -Naur netgen-4.9.13_orig/libsrc/occ/Partition_Loop2d.cxx netgen-4.9.13_new/libsrc/occ/Partition_Loop2d.cxx
204 --- netgen-4.9.13_orig/libsrc/occ/Partition_Loop2d.cxx 2009-08-24 06:12:24.000000000 +0400
205 +++ netgen-4.9.13_new/libsrc/occ/Partition_Loop2d.cxx 2013-05-31 11:28:04.000000000 +0400
207 #include <BRepAdaptor_Surface.hxx>
208 #include <BRepAlgo_AsDes.hxx>
209 #include <BRepAlgo_FaceRestrictor.hxx>
210 -#include <BRepOffset_DataMapOfShapeReal.hxx>
211 #include <BRepTopAdaptor_FClass2d.hxx>
212 #include <BRep_Builder.hxx>
213 #include <BRep_Tool.hxx>
215 #include <gp_Pnt.hxx>
216 #include <gp_Pnt2d.hxx>
218 +#include <Standard_Version.hxx>
220 +#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060400
221 +// porting to OCCT6.5.1
222 +#include <TopTools_DataMapOfShapeReal.hxx>
224 +#include <BRepOffset_DataMapOfShapeReal.hxx>
227 //=======================================================================
228 //function : Partition_Loop2d
231 Cc->D1(uc, PC, CTg1);
232 if (!isForward) CTg1.Reverse();
234 - Standard_Real anglemin = 3 * PI, tolAng = 1.e-8;
235 + Standard_Real anglemin = 3 * M_PI, tolAng = 1.e-8;
237 // select an edge whose first derivative is most left of CTg1
238 // ie an angle between Tg1 and CTg1 is least
241 Standard_Real angle = Tg1.Angle(CTg1);
243 - if (PI - Abs(angle) <= tolAng)
244 + if (M_PI - Abs(angle) <= tolAng)
246 // an angle is too close to PI; assure that an angle sign really
247 // reflects an edge position: +PI - an edge is worst,
249 DC.Initialize( DegEdge, F );
251 // avoid intersecting twice the same edge
252 +#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060400
253 +// porting to OCCT6.5.1
254 + TopTools_DataMapOfShapeReal EUMap ( EdgesList.Extent() );
256 BRepOffset_DataMapOfShapeReal EUMap ( EdgesList.Extent() );
259 Standard_Real U, f, l;
260 BRep_Tool::Range (DegEdge, f, l);
261 diff -Naur netgen-4.9.13_orig/libsrc/occ/Partition_Spliter.cxx netgen-4.9.13_new/libsrc/occ/Partition_Spliter.cxx
262 --- netgen-4.9.13_orig/libsrc/occ/Partition_Spliter.cxx 2009-08-24 06:12:24.000000000 +0400
263 +++ netgen-4.9.13_new/libsrc/occ/Partition_Spliter.cxx 2013-05-31 11:28:04.000000000 +0400
265 #include <GeomAdaptor_Curve.hxx>
266 #include <TopOpeBRepTool_CurveTool.hxx>
268 +#include <Standard_Version.hxx>
273 @@ -1169,7 +1171,12 @@
274 for (; j<=nbj && ok; ++j) {
275 if (Extrema.IsMin(j)) {
276 hasMin = Standard_True;
277 +#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060400
278 +// porting to OCCT6.5.1
279 + ok = Extrema.SquareDistance(j) <= tol * tol;
281 ok = Extrema.Value(j) <= tol;
286 diff -Naur netgen-4.9.13_orig/libsrc/occ/occconstruction.cpp netgen-4.9.13_new/libsrc/occ/occconstruction.cpp
287 --- netgen-4.9.13_orig/libsrc/occ/occconstruction.cpp 2009-08-24 06:32:47.000000000 +0400
288 +++ netgen-4.9.13_new/libsrc/occ/occconstruction.cpp 2013-05-31 11:28:04.000000000 +0400
290 #include <BRepAlgoAPI_Common.hxx>
291 #include <BRepAlgoAPI_Fuse.hxx>
292 #include <BRepAlgoAPI_Section.hxx>
293 -#include <BRepOffsetAPI_Sewing.hxx>
294 +//#include <BRepOffsetAPI_Sewing.hxx>
295 //#include <BRepAlgo_Sewing.hxx>
296 #include <BRepOffsetAPI_MakeOffsetShape.hxx>
297 #include <ShapeFix_Shape.hxx>
298 diff -Naur netgen-4.9.13_orig/libsrc/occ/occgenmesh.cpp netgen-4.9.13_new/libsrc/occ/occgenmesh.cpp
299 --- netgen-4.9.13_orig/libsrc/occ/occgenmesh.cpp 2010-03-16 09:30:07.000000000 +0300
300 +++ netgen-4.9.13_new/libsrc/occ/occgenmesh.cpp 2013-05-31 11:28:04.000000000 +0400
303 #define DIVIDEEDGESECTIONS 1000
304 #define IGNORECURVELENGTH 1e-4
305 +// a small value used to avoid FPE
306 +#define VSMALL 1e-10
309 bool merge_solids = 1;
313 Point<3> p = p0 + 0.5*n;
314 - double lambda = (p-l.p0)*n / nq;
315 + // double lambda = (p-l.p0)*n / nq; -- avoid FPE
316 + double lambda = (fabs(nq) > 1e-10) ? (p-l.p0)*n / nq : -1;
318 if (lambda >= 0 && lambda <= 1)
325 + static // useless out of this file
326 double ComputeH (double kappa)
330 if (mparam.maxh * kappa < 1)
334 + // hret = 1 / kappa; -- avoid FPE
335 + hret = 1 / (kappa + VSMALL);
337 if (mparam.maxh < hret)
345 + static // useless out of this file
346 void RestrictHTriangle (gp_Pnt2d & par0, gp_Pnt2d & par1, gp_Pnt2d & par2,
347 BRepLProp_SLProps * prop, Mesh & mesh, int depth, double h = 0)
354 - if (h > 30) return;
355 + // commented to restrict H on a large sphere for example
356 + //if (h > 30) return;
359 if (h < maxside && depth < 10)
364 + static // useless out of this file
365 void DivideEdge (TopoDS_Edge & edge, Array<MeshPoint> & ps,
366 Array<double> & params, Mesh & mesh)
372 - double olddist = 0;
374 + //double olddist = 0; -- useless variables
377 int tmpVal = (int)(DIVIDEEDGESECTIONS);
379 @@ -256,15 +262,19 @@
382 pnt = c->Value(s0+(i/double(DIVIDEEDGESECTIONS))*(s1-s0));
383 + // -- no more than 1 segment per <edge length>/DIVIDEEDGESECTIONS
384 hvalue[i] = hvalue[i-1] +
385 - 1.0/mesh.GetH(Point3d(pnt.X(), pnt.Y(), pnt.Z()))*
386 - pnt.Distance(oldpnt);
387 + // 1.0/mesh.GetH(Point3d(pnt.X(), pnt.Y(), pnt.Z()))*
388 + // pnt.Distance(oldpnt);
390 + 1.0/mesh.GetH(Point3d(pnt.X(), pnt.Y(), pnt.Z()))*
391 + pnt.Distance(oldpnt));
393 //(*testout) << "mesh.GetH(Point3d(pnt.X(), pnt.Y(), pnt.Z())) " << mesh.GetH(Point3d(pnt.X(), pnt.Y(), pnt.Z()))
394 // << " pnt.Distance(oldpnt) " << pnt.Distance(oldpnt) << endl;
397 - dist = pnt.Distance(oldpnt);
398 + //olddist = dist; -- useless variables
399 + //dist = pnt.Distance(oldpnt);
402 // nsubedges = int(ceil(hvalue[DIVIDEEDGESECTIONS]));
405 if (hvalue[i1]/hvalue[DIVIDEEDGESECTIONS]*nsubedges >= i)
407 - params[i] = s0+(i1/double(DIVIDEEDGESECTIONS))*(s1-s0);
408 + // -- for nsubedges comparable to DIVIDEEDGESECTIONS
409 + //params[i] = s0+(i1/double(DIVIDEEDGESECTIONS))*(s1-s0);
410 + double d1 = i1 - (hvalue[i1] - i*hvalue[DIVIDEEDGESECTIONS]/nsubedges)/(hvalue[i1]-hvalue[i1-1]);
411 + params[i] = s0+(d1/double(DIVIDEEDGESECTIONS))*(s1-s0);
412 pnt = c->Value(params[i]);
413 ps[i-1] = MeshPoint (Point3d(pnt.X(), pnt.Y(), pnt.Z()));
416 (*testout) << "nedges = " << nedges << endl;
418 double eps = 1e-6 * geom.GetBoundingBox().Diam();
419 + const double eps2 = eps * eps; // -- small optimization
421 for (int i = 1; i <= nvertices; i++)
426 for (PointIndex pi = 1; pi <= mesh.GetNP(); pi++)
427 - if ( Dist2 (mesh[pi], Point<3>(mp)) < eps*eps)
428 + //if ( Dist2 (mesh[pi], Point<3>(mp)) < eps*eps)
429 + if ( Dist2 (mesh[pi], Point<3>(mp)) < eps2 ) // -- small optimization
435 TopoDS_Face face = TopoDS::Face(exp1.Current());
436 int facenr = geom.fmap.FindIndex(face);
437 + if ( facenr < 1 ) continue; // -- to support SALOME sub-meshes
439 if (face2solid[0][facenr-1] == 0)
440 face2solid[0][facenr-1] = solidnr;
445 + edgenr = mesh.GetNSeg(); // to support SALOME sub-meshes
447 (*testout) << "faces = " << geom.fmap.Extent() << endl;
450 //(*testout) << "ignoring degenerated edge" << endl;
453 + if ( geom.emap.FindIndex(edge) < 1 ) continue; // to support SALOME sub-meshes
455 if (geom.vmap.FindIndex(TopExp::FirstVertex (edge)) ==
456 geom.vmap.FindIndex(TopExp::LastVertex (edge)))
457 @@ -479,15 +497,64 @@
461 - Point<3> fp = occ2ng (BRep_Tool::Pnt (TopExp::FirstVertex (edge)));
462 - Point<3> lp = occ2ng (BRep_Tool::Pnt (TopExp::LastVertex (edge)));
463 + TopoDS_Iterator vIt( edge, false );
464 + TopoDS_Vertex v1 = TopoDS::Vertex( vIt.Value() ); vIt.Next();
465 + TopoDS_Vertex v2 = TopoDS::Vertex( vIt.Value() );
466 + if ( v1.Orientation() == TopAbs_REVERSED )
467 + std::swap( v1, v2 );
468 + const bool isClosedEdge = v1.IsSame( v2 );
470 + Point<3> fp = occ2ng (BRep_Tool::Pnt (v1));
471 + Point<3> lp = occ2ng (BRep_Tool::Pnt (v2));
472 + double tol2 = std::min( eps*eps, 1e-6 * Dist2( fp, lp ));
473 + if ( isClosedEdge )
474 + tol2 = BRep_Tool::Tolerance( v1 ) * BRep_Tool::Tolerance( v1 );
478 for (PointIndex pi = 1; pi < first_ep; pi++)
480 - if (Dist2 (mesh[pi], fp) < eps*eps) pnums[0] = pi;
481 - if (Dist2 (mesh[pi], lp) < eps*eps) pnums.Last() = pi;
482 + if (Dist2 (mesh[pi], fp) < tol2) pnums[0] = pi;
483 + if (Dist2 (mesh[pi], lp) < tol2) pnums.Last() = pi;
485 + if (( isClosedEdge && pnums[0] != pnums.Last() ) ||
486 + ( !isClosedEdge && pnums[0] == pnums.Last() ))
487 + pnums[0] = pnums.Last() = -1;
488 + if ( pnums[0] == -1 || pnums.Last() == -1 )
490 + // take into account a possible large gap between a vertex and an edge curve
491 + // end and a large vertex tolerance covering the whole edge
492 + if ( pnums[0] == -1 )
494 + double tol = BRep_Tool::Tolerance( v1 );
495 + for (PointIndex pi = 1; pi < first_ep; pi++)
496 + if (pi != pnums.Last() && Dist2 (mesh[pi], fp) < 2*tol*tol)
499 + if ( pnums[0] == -1 )
500 + pnums[0] = first_ep-1- nvertices + geom.vmap.FindIndex ( v1 );
502 + if ( isClosedEdge )
504 + pnums.Last() = pnums[0];
508 + if ( pnums.Last() == -1 )
510 + double tol = BRep_Tool::Tolerance( v2 );
511 + for (PointIndex pi = 1; pi < first_ep; pi++)
512 + if (pi != pnums[0] && Dist2 (mesh[pi], lp) < 2*tol*tol)
515 + if ( pnums.Last() == -1 )
516 + pnums.Last() = first_ep-1-nvertices + geom.vmap.FindIndex ( v2 );
519 + if ( Dist2( fp, mesh[PointIndex(pnums[0])]) >
520 + Dist2( lp, mesh[PointIndex(pnums.Last())]))
521 + std::swap( pnums[0], pnums.Last() );
529 (*testout) << "mesh face " << k << endl;
530 - multithread.percent = 100 * k / (mesh.GetNFD()+1e-10);
531 + // multithread.percent = 100 * k / (mesh.GetNFD()+1e-10); -- avoid FPE
532 + multithread.percent = 100 * k / (mesh.GetNFD() + VSMALL);
533 geom.facemeshstatus[k-1] = -1;
537 // if (k != 36) continue;
539 // (*testout) << "optimize face " << k << endl;
540 - multithread.percent = 100 * k / (mesh.GetNFD()+1e-10);
541 + //multithread.percent = 100 * k / (mesh.GetNFD()+1e-10); -- avoid FPE
542 + multithread.percent = 100 * k / (mesh.GetNFD() + VSMALL);
544 FaceDescriptor & fd = mesh.GetFaceDescriptor(k);
546 @@ -1456,3 +1525,4 @@
551 diff -Naur netgen-4.9.13_orig/libsrc/occ/occgeom.cpp netgen-4.9.13_new/libsrc/occ/occgeom.cpp
552 --- netgen-4.9.13_orig/libsrc/occ/occgeom.cpp 2010-03-05 16:16:21.000000000 +0300
553 +++ netgen-4.9.13_new/libsrc/occ/occgeom.cpp 2013-05-31 11:28:04.000000000 +0400
555 #include "ShapeAnalysis_CheckSmallFace.hxx"
556 #include "ShapeAnalysis_DataMapOfShapeListOfReal.hxx"
557 #include "ShapeAnalysis_Surface.hxx"
558 +#include <BRepTopAdaptor_FClass2d.hxx> // -- to optimize Project() and FastProject()
559 +#include <TopAbs_State.hxx>
560 #include "BRepAlgoAPI_Fuse.hxx"
561 #include "BRepCheck_Analyzer.hxx"
562 #include "BRepLib.hxx"
564 #include "ShapeFix_FixSmallFace.hxx"
565 #include "Partition_Spliter.hxx"
570 - void OCCGeometry :: PrintNrShapes ()
571 + // free data used to optimize Project() and FastProject()
572 + OCCGeometry::~OCCGeometry()
574 + NCollection_DataMap<int,BRepTopAdaptor_FClass2d*>::Iterator it(fclsmap);
575 + for (; it.More(); it.Next())
579 + void OCCGeometry :: PrintNrShapes ()
583 @@ -951,25 +960,58 @@
587 + // returns a projector and a classifier for the given surface
588 + void OCCGeometry::GetFaceTools(int surfi, Handle(ShapeAnalysis_Surface)& proj,
589 + BRepTopAdaptor_FClass2d*& cls) const
591 + //MSV: organize caching projector in the map
592 + if (fprjmap.IsBound(surfi))
594 + proj = fprjmap.Find(surfi);
595 + cls = fclsmap.Find(surfi);
599 + const TopoDS_Face& aFace = TopoDS::Face(fmap(surfi));
600 + Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
601 + proj = new ShapeAnalysis_Surface(aSurf);
602 + fprjmap.Bind(surfi, proj);
603 + cls = new BRepTopAdaptor_FClass2d(aFace,Precision::Confusion());
604 + fclsmap.Bind(surfi, cls);
609 - void OCCGeometry :: Project (int surfi, Point<3> & p) const
610 + // void OCCGeometry :: Project (int surfi, Point<3> & p) const
611 + bool OCCGeometry :: Project (int surfi, Point<3> & p, double& u, double& v) const
614 if (++cnt % 1000 == 0) cout << "Project cnt = " << cnt << endl;
616 gp_Pnt pnt(p(0), p(1), p(2));
619 - Handle( Geom_Surface ) thesurf = BRep_Tool::Surface(TopoDS::Face(fmap(surfi)));
620 - Handle( ShapeAnalysis_Surface ) su = new ShapeAnalysis_Surface( thesurf );
621 - gp_Pnt2d suval = su->ValueOfUV ( pnt, BRep_Tool::Tolerance( TopoDS::Face(fmap(surfi)) ) );
622 - suval.Coord( u, v);
623 - pnt = thesurf->Value( u, v );
626 + // -- Optimization: use cached projector and classifier
628 + // Handle( Geom_Surface ) thesurf = BRep_Tool::Surface(TopoDS::Face(fmap(surfi)));
629 + // Handle( ShapeAnalysis_Surface ) su = new ShapeAnalysis_Surface( thesurf );
630 + // gp_Pnt2d suval = su->ValueOfUV ( pnt, BRep_Tool::Tolerance( TopoDS::Face(fmap(surfi)) ) );
631 + // suval.Coord( u, v);
632 + // pnt = thesurf->Value( u, v );
634 + Handle(ShapeAnalysis_Surface) proj;
635 + BRepTopAdaptor_FClass2d *cls;
636 + GetFaceTools(surfi, proj, cls);
638 + gp_Pnt2d p2d = proj->ValueOfUV(pnt, Precision::Confusion());
639 + if (cls->Perform(p2d) == TopAbs_OUT)
643 + pnt = proj->Value(p2d);
646 p = Point<3> (pnt.X(), pnt.Y(), pnt.Z());
652 @@ -979,54 +1021,69 @@
654 gp_Pnt p(ap(0), ap(1), ap(2));
656 - Handle(Geom_Surface) surface = BRep_Tool::Surface(TopoDS::Face(fmap(surfi)));
658 - gp_Pnt x = surface->Value (u,v);
660 - if (p.SquareDistance(x) <= sqr(PROJECTION_TOLERANCE)) return true;
664 - surface->D1(u,v,x,du,dv);
670 - double det, lambda, mu;
677 - det = Det3 (n.X(), du.X(), dv.X(),
678 - n.Y(), du.Y(), dv.Y(),
679 - n.Z(), du.Z(), dv.Z());
681 - if (det < 1e-15) return false;
683 - lambda = Det3 (n.X(), p.X()-x.X(), dv.X(),
684 - n.Y(), p.Y()-x.Y(), dv.Y(),
685 - n.Z(), p.Z()-x.Z(), dv.Z())/det;
687 - mu = Det3 (n.X(), du.X(), p.X()-x.X(),
688 - n.Y(), du.Y(), p.Y()-x.Y(),
689 - n.Z(), du.Z(), p.Z()-x.Z())/det;
695 - surface->D1(u,v,x,du,dv);
697 - } while (xold.SquareDistance(x) > sqr(PROJECTION_TOLERANCE) && count < 50);
699 - // (*testout) << "FastProject count: " << count << endl;
701 - if (count == 50) return false;
703 - ap = Point<3> (x.X(), x.Y(), x.Z());
704 + // -- Optimization: use cached projector and classifier
705 + // Handle(Geom_Surface) surface = BRep_Tool::Surface(TopoDS::Face(fmap(surfi)));
707 + // gp_Pnt x = surface->Value (u,v);
709 + // if (p.SquareDistance(x) <= sqr(PROJECTION_TOLERANCE)) return true;
713 + // surface->D1(u,v,x,du,dv);
719 + // double det, lambda, mu;
726 + // det = Det3 (n.X(), du.X(), dv.X(),
727 + // n.Y(), du.Y(), dv.Y(),
728 + // n.Z(), du.Z(), dv.Z());
730 + // if (det < 1e-15) return false;
732 + // lambda = Det3 (n.X(), p.X()-x.X(), dv.X(),
733 + // n.Y(), p.Y()-x.Y(), dv.Y(),
734 + // n.Z(), p.Z()-x.Z(), dv.Z())/det;
736 + // mu = Det3 (n.X(), du.X(), p.X()-x.X(),
737 + // n.Y(), du.Y(), p.Y()-x.Y(),
738 + // n.Z(), du.Z(), p.Z()-x.Z())/det;
744 + // surface->D1(u,v,x,du,dv);
746 + // } while (xold.SquareDistance(x) > sqr(PROJECTION_TOLERANCE) && count < 50);
748 + // // (*testout) << "FastProject count: " << count << endl;
750 + // if (count == 50) return false;
752 + // ap = Point<3> (x.X(), x.Y(), x.Z());
753 + Handle(ShapeAnalysis_Surface) proj;
754 + BRepTopAdaptor_FClass2d *cls;
755 + GetFaceTools(surfi, proj, cls);
757 + gp_Pnt2d p2d = proj->NextValueOfUV(gp_Pnt2d(u,v), p, Precision::Confusion());
758 + if (cls->Perform(p2d) == TopAbs_OUT)
760 + //cout << "Projection fails" << endl;
764 + p = proj->Value(p2d);
766 + ap = Point<3> (p.X(), p.Y(), p.Z());
770 diff -Naur netgen-4.9.13_orig/libsrc/occ/occgeom.hpp netgen-4.9.13_new/libsrc/occ/occgeom.hpp
771 --- netgen-4.9.13_orig/libsrc/occ/occgeom.hpp 2010-01-14 19:56:19.000000000 +0300
772 +++ netgen-4.9.13_new/libsrc/occ/occgeom.hpp 2013-05-31 11:28:04.000000000 +0400
774 #include "Geom_Curve.hxx"
775 #include "Geom2d_Curve.hxx"
776 #include "Geom_Surface.hxx"
777 -#include "GeomAPI_ProjectPointOnSurf.hxx"
778 -#include "GeomAPI_ProjectPointOnCurve.hxx"
779 +// #include "GeomAPI_ProjectPointOnSurf.hxx"
780 +// #include "GeomAPI_ProjectPointOnCurve.hxx"
781 #include "BRepTools.hxx"
782 #include "TopExp.hxx"
783 #include "BRepBuilderAPI_MakeVertex.hxx"
785 #include "Geom_Curve.hxx"
786 #include "Geom2d_Curve.hxx"
787 #include "Geom_Surface.hxx"
788 -#include "GeomAPI_ProjectPointOnSurf.hxx"
789 -#include "GeomAPI_ProjectPointOnCurve.hxx"
790 +// #include "GeomAPI_ProjectPointOnSurf.hxx"
791 +// #include "GeomAPI_ProjectPointOnCurve.hxx"
792 #include "TopoDS_Wire.hxx"
793 #include "BRepTools_WireExplorer.hxx"
794 #include "BRepTools.hxx"
796 #include "IGESToBRep_Reader.hxx"
797 #include "Interface_Static.hxx"
798 #include "GeomAPI_ExtremaCurveCurve.hxx"
799 -#include "Standard_ErrorHandler.hxx"
800 +//#include "Standard_ErrorHandler.hxx"
801 #include "Standard_Failure.hxx"
802 #include "ShapeUpgrade_ShellSewing.hxx"
803 #include "ShapeFix_Shape.hxx"
805 #include "ShapeAnalysis.hxx"
806 #include "ShapeBuild_ReShape.hxx"
808 +// -- Optimization: to use cached projector and classifier
809 +#include <NCollection_DataMap.hxx>
810 +class Handle_ShapeAnalysis_Surface;
811 +class BRepTopAdaptor_FClass2d;
813 // Philippose - 29/01/2009
814 // OpenCascade XDE Support
816 class OCCGeometry : public NetgenGeometry
819 + // -- Optimization: to use cached projector and classifier
820 + mutable NCollection_DataMap<int,Handle_ShapeAnalysis_Surface> fprjmap;
821 + mutable NCollection_DataMap<int,BRepTopAdaptor_FClass2d*> fclsmap;
829 + ~OCCGeometry(); // -- to free cached projector and classifier
833 Box<3> GetBoundingBox()
838 - void Project (int surfi, Point<3> & p) const;
839 + // void Project (int surfi, Point<3> & p) const; -- optimization
840 + bool Project (int surfi, Point<3> & p, double& u, double& v) const;
841 bool FastProject (int surfi, Point<3> & ap, double& u, double& v) const;
843 + // -- Optimization: to use cached projector and classifier
844 + void GetFaceTools(int surfi, Handle(ShapeAnalysis_Surface)& proj,
845 + BRepTopAdaptor_FClass2d*& cls) const;
847 OCCSurface GetSurface (int surfi)
849 cout << "OCCGeometry::GetSurface using PLANESPACE" << endl;
850 diff -Naur netgen-4.9.13_orig/libsrc/occ/occmeshsurf.cpp netgen-4.9.13_new/libsrc/occ/occmeshsurf.cpp
851 --- netgen-4.9.13_orig/libsrc/occ/occmeshsurf.cpp 2009-08-24 06:32:47.000000000 +0400
852 +++ netgen-4.9.13_new/libsrc/occ/occmeshsurf.cpp 2013-05-31 11:28:04.000000000 +0400
854 #include <meshing.hpp>
855 #include <GeomLProp_SLProps.hxx>
856 #include <ShapeAnalysis_Surface.hxx>
857 +#include <GeomAPI_ProjectPointOnCurve.hxx> // -- moved here from occgeom.hpp
861 @@ -434,23 +435,33 @@
863 void MeshOptimize2dOCCSurfaces :: ProjectPoint (INDEX surfind, Point<3> & p) const
865 - geometry.Project (surfind, p);
866 + // geometry.Project (surfind, p); -- signature of Project() changed for optimization
868 + geometry.Project (surfind, p, u, v);
872 int MeshOptimize2dOCCSurfaces :: ProjectPointGI (INDEX surfind, Point<3> & p, PointGeomInfo & gi) const
880 - if (geometry.FastProject (surfind, hp, u, v))
885 - ProjectPoint (surfind, p);
886 - return CalcPointGeomInfo (surfind, gi, p);
887 + // -- u and v are computed by FastProject() and Project(), no need to call CalcPointGeomInfo()
888 + // if (geometry.FastProject (surfind, hp, u, v))
893 + // ProjectPoint (surfind, p);
894 + // return CalcPointGeomInfo (surfind, gi, p);
896 + if (gi.trignum > 0)
897 + ok = geometry.FastProject (surfind, hp, gi.u, gi.v);
899 + ok = geometry.Project (surfind, hp, gi.u, gi.v);
906 if (!geometry.FastProject (surfi, hnewp, u, v))
908 // cout << "Fast projection to surface fails! Using OCC projection" << endl;
909 - geometry.Project (surfi, hnewp);
910 + // geometry.Project (surfi, hnewp); -- Project() changed for optimization
911 + geometry.Project (surfi, hnewp, u, v);
920 + }//; -- to compile with -Wall -pedantic
923 void OCCRefinementSurfaces ::
924 @@ -708,14 +720,18 @@
925 hnewp = Point<3> (pnt.X(), pnt.Y(), pnt.Z());
932 void OCCRefinementSurfaces :: ProjectToSurface (Point<3> & p, int surfi)
935 - geometry.Project (surfi, p);
937 + // geometry.Project (surfi, p); -- Project() changed for optimization
940 + geometry.Project (surfi, p, u, v);
942 + }//; -- to compile with -Wall -pedantic
944 void OCCRefinementSurfaces :: ProjectToSurface (Point<3> & p, int surfi, PointGeomInfo & gi)
947 if (!geometry.FastProject (surfi, p, gi.u, gi.v))
949 cout << "Fast projection to surface fails! Using OCC projection" << endl;
950 - geometry.Project (surfi, p);
952 + geometry.Project (surfi, p, u, v);
959 diff -Naur netgen-4.9.13_orig/libsrc/occ/utilities.h netgen-4.9.13_new/libsrc/occ/utilities.h
960 --- netgen-4.9.13_orig/libsrc/occ/utilities.h 2009-08-24 06:12:24.000000000 +0400
961 +++ netgen-4.9.13_new/libsrc/occ/utilities.h 2013-05-31 11:28:04.000000000 +0400
968 // #include "SALOME_Log.hxx"
970 diff -Naur netgen-4.9.13_orig/libsrc/stlgeom/stlgeommesh.cpp netgen-4.9.13_new/libsrc/stlgeom/stlgeommesh.cpp
971 --- netgen-4.9.13_orig/libsrc/stlgeom/stlgeommesh.cpp 2009-08-10 15:40:51.000000000 +0400
972 +++ netgen-4.9.13_new/libsrc/stlgeom/stlgeommesh.cpp 2013-05-31 11:28:04.000000000 +0400
973 @@ -1435,7 +1435,8 @@
975 if (!optstring || strlen(optstring) == 0)
977 - mparam.optimize2d = "smcm";
978 + //mparam.optimize2d = (char*)"smcm";
979 + mparam.optimize2d = (char*)"smcm";
983 @@ -1451,7 +1452,8 @@
985 mesh -> LoadLocalMeshSize (mparam.meshsizefilename);
986 mesh -> CalcLocalHFromSurfaceCurvature (stlparam.resthsurfmeshcurvfac);
987 - mparam.optimize2d = "cmsmSm";
988 + //mparam.optimize2d = (char*)"cmsmSm";
989 + mparam.optimize2d = (char*)"cmsmSm";
990 STLSurfaceOptimization (*stlgeometry, *mesh, mparam);
992 (*statout) << GetTime() << " & ";
993 @@ -1557,7 +1559,8 @@
995 if (!optstring || strlen(optstring) == 0)
997 - mparam.optimize3d = "cmdmstm";
998 + //mparam.optimize3d = "cmdmstm";
999 + mparam.optimize3d = (char*)"cmdmstm";
1003 diff -Naur netgen-4.9.13_orig/nglib/nglib.cpp netgen-4.9.13_new/nglib/nglib.cpp
1004 --- netgen-4.9.13_orig/nglib/nglib.cpp 2010-05-18 15:19:15.000000000 +0400
1005 +++ netgen-4.9.13_new/nglib/nglib.cpp 2013-05-31 11:33:44.000000000 +0400
1009 // initialize, deconstruct Netgen library:
1010 - DLL_HEADER void Ng_Init ()
1011 + DLL_HEADER void Ng_Init ( const char* filename )
1014 + if ( filename == "" ) {
1017 + mycout = new ofstream ( filename );
1018 + cout << "NOTE: netgen output was redirected to file " << filename << endl;
1021 // netgen::testout->SetOutStream (new ofstream ("test.out"));
1022 testout = new ofstream ("test.out");
1023 diff -Naur netgen-4.9.13_orig/nglib/nglib.h netgen-4.9.13_new/nglib/nglib.h
1024 --- netgen-4.9.13_orig/nglib/nglib.h 2010-05-18 15:20:25.000000000 +0400
1025 +++ netgen-4.9.13_new/nglib/nglib.h 2013-05-31 11:29:26.000000000 +0400
1027 // Philippose - 14.02.2009
1028 // Modifications for creating a DLL in Windows
1030 - #ifdef NGLIB_EXPORTS || nglib_EXPORTS
1031 + #if defined NGLIB_EXPORTS || defined nglib_EXPORTS
1032 #define DLL_HEADER __declspec(dllexport)
1034 #define DLL_HEADER __declspec(dllimport)
1036 program before beginning to use the other Netgen
1039 -DLL_HEADER void Ng_Init ();
1040 +DLL_HEADER void Ng_Init ( const char* filename = "" );
1043 /*! \brief Exit the Netgen meshing kernel in a clean manner