0027557: Unstable HLR tests
[occt.git] / src / HLRBRep / HLRBRep_Data.cxx
old mode 100755 (executable)
new mode 100644 (file)
index d59aee3..63e7ee0
@@ -1,30 +1,47 @@
-// File:       HLRBRep_Data.cxx
-// Created:    Thu Apr 17 19:17:52 1997
-// Author:     Christophe MARION
-//             <cma@partox.paris1.matra-dtv.fr>
+// Created on: 1997-04-17
+// Created by: Christophe MARION
+// Copyright (c) 1997-1999 Matra Datavision
+// Copyright (c) 1999-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
 
 //#define No_Standard_OutOfRange
 
-#define OCC191 // jfa 26/02/2002 Bug of cone display
-
-#include <HLRBRep_Data.ixx>
-
-#include <StdFail_UndefinedDerivative.hxx>
-#include <Precision.hxx>
-#include <gp_Dir.hxx>
+#include <BRepTopAdaptor_Tool.hxx>
+#include <BRepTopAdaptor_TopolTool.hxx>
+#include <ElCLib.hxx>
 #include <Geom2d_Curve.hxx>
-#include <IntRes2d_IntersectionPoint.hxx>
-#include <IntRes2d_IntersectionSegment.hxx>
-#include <IntCurveSurface_IntersectionPoint.hxx>
-#include <IntCurveSurface_TransitionOnCurve.hxx>
-#include <TColStd_ListIteratorOfListOfInteger.hxx>
+#include <gp.hxx>
+#include <gp_Dir.hxx>
+#include <gp_Dir2d.hxx>
 #include <HLRAlgo.hxx>
+#include <HLRAlgo_Interference.hxx>
 #include <HLRAlgo_ListIteratorOfInterferenceList.hxx>
+#include <HLRAlgo_Projector.hxx>
+#include <HLRBRep_Data.hxx>
+#include <HLRBRep_EdgeData.hxx>
 #include <HLRBRep_EdgeFaceTool.hxx>
-#include <ElCLib.hxx>
-#include <gp.hxx>
+#include <HLRBRep_FaceData.hxx>
+#include <IntCurveSurface_IntersectionPoint.hxx>
+#include <IntCurveSurface_TransitionOnCurve.hxx>
+#include <IntRes2d_IntersectionPoint.hxx>
+#include <IntRes2d_IntersectionSegment.hxx>
+#include <Precision.hxx>
+#include <Standard_Type.hxx>
+#include <StdFail_UndefinedDerivative.hxx>
+#include <TColStd_ListIteratorOfListOfInteger.hxx>
+
 #include <stdio.h>
-#include <BRepTopAdaptor_Tool.hxx>
+IMPLEMENT_STANDARD_RTTIEXT(HLRBRep_Data,MMgt_TShared)
 
 Standard_Integer nbOkIntersection;
 Standard_Integer nbPtIntersection;
@@ -175,26 +192,30 @@ public:
   long unsigned **TabBit;
   Standard_Integer nTabBit;
 
-#ifdef DEB  
+#ifdef OCCT_DEBUG
   Standard_Integer StNbLect,StNbEcr,StNbMax,StNbMoy,StNbMoyNonNul; //-- STAT
 #endif
 
+private:
+  TableauRejection(const TableauRejection&);
+  TableauRejection& operator=(const TableauRejection&);
+
 public:
   //-- ============================================================
   TableauRejection() { 
     N=0; nTabBit=0;  UV=NULL;  nbUV=NULL;  IndUV=NULL; TabBit=NULL;
-#ifdef DEB
+#ifdef OCCT_DEBUG
     StNbLect=StNbEcr=StNbMax=StNbMoy=StNbMoyNonNul=0;
 #endif
   }
   //-- ============================================================
   void SetDim(const Standard_Integer n) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout<<"\n@#@#@#@#@# SetDim "<<n<<endl;
 #endif
     if(UV) 
       Destroy();
-#ifdef DEB
+#ifdef OCCT_DEBUG
     StNbLect=StNbEcr=StNbMax=StNbMoy=0;
 #endif
     N=n;
@@ -222,7 +243,7 @@ public:
   } 
   //-- ============================================================
   void Destroy() {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     if(N) { 
       Standard_Integer nnn=0;
       StNbMoy=StNbMoyNonNul=0;
@@ -256,27 +277,31 @@ public:
          free(IndUV[i]);
          IndUV[i]=NULL;
        }
-       else { cout<<" IndUV ~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl; } 
-              
+#ifdef OCCT_DEBUG
+       else
+          cout<<" IndUV ~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
+#endif
       }
       for(i=0;i<N;i++) { 
        if(UV[i]) { 
          free(UV[i]);
          UV[i]=NULL;
        }
+#ifdef OCCT_DEBUG
        else { cout<<" UV ~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl; } 
+#endif
       }
       
-      if(nbUV)  { free(nbUV);  nbUV=NULL; } else { cout<<" nbUV ~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl; } 
-      if(IndUV) { free(IndUV); IndUV=NULL;} else { cout<<" IndUV ~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl; } 
-      if(UV)    { free(UV);    UV=NULL; }  else { cout<<" UV ~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl; } 
+      if(nbUV)  { free(nbUV);  nbUV=NULL; } 
+      if(IndUV) { free(IndUV); IndUV=NULL;}
+      if(UV) { free(UV);    UV=NULL; }
       N=0;
     }
   }
   //-- ============================================================
   void Set(Standard_Integer i0,Standard_Integer j0,const Standard_Real u) { 
     i0--; j0--;
-#ifdef DEB
+#ifdef OCCT_DEBUG
     StNbEcr++;
 #endif
     Standard_Integer k=-1;
@@ -336,7 +361,7 @@ public:
   //-- ============================================================
   Standard_Real Get(Standard_Integer i0,Standard_Integer j0) { 
     i0--; j0--;
-#ifdef DEB
+#ifdef OCCT_DEBUG
     StNbLect++;
 #endif
 
@@ -448,31 +473,10 @@ public:
     }
   }
 };
-
-
-
 //-- ================================================================================
 
 
-//=======================================================================
-//function : FindInList
-//purpose  : 
-//=======================================================================
-// Unused :
-#ifdef DEB
-static Standard_Boolean FindInList (const TColStd_ListOfInteger& L,
-                                   const Standard_Integer V)
-{
-  for (TColStd_ListIteratorOfListOfInteger ILV(L);
-       ILV.More();
-       ILV.Next()) {
-    if (V == ILV.Value())
-      return Standard_True;
-  }
-  return Standard_False;
-}
-#endif
-
 //=======================================================================
 //function : AdjustParameter
 //purpose  : 
@@ -534,10 +538,6 @@ void HLRBRep_Data::Write (const Handle(HLRBRep_Data)& DS,
                          const Standard_Integer de,
                          const Standard_Integer df)
 {
-#ifdef DEB
-  Standard_Integer n1vert = 
-#endif
-    DS->NbVertices();
   Standard_Integer n1edge = DS->NbEdges();
   Standard_Integer n1face = DS->NbFaces();
 
@@ -774,7 +774,7 @@ void HLRBRep_Data::Update (const HLRAlgo_Projector& P)
     Standard_Boolean withOutL = Standard_False;
     
     for (myFaceItr1.InitEdge(*fd);
-        myFaceItr1.MoreEdge() && !cut && !withOutL;
+        myFaceItr1.MoreEdge();
         myFaceItr1.NextEdge()) {
       if (myFaceItr1.Internal()) {
        withOutL = Standard_True;
@@ -828,21 +828,19 @@ void HLRBRep_Data::Update (const HLRAlgo_Projector& P)
        myFEOutLine  = myFaceItr1.OutLine    ();
        myFEInternal = myFaceItr1.Internal   ();
        myFEDouble   = myFaceItr1.Double     ();
-       HLRBRep_EdgeData* ed = &(myEData(myFE));
+       HLRBRep_EdgeData* EDataFE1 = &(myEData(myFE));
        if (!myFEDouble &&
            (myFEOri == TopAbs_FORWARD ||
             myFEOri == TopAbs_REVERSED)) {
-         myFEGeom = &(ed->ChangeGeometry());
-         const HLRBRep_Curve& EC = ed->Geometry();
+         myFEGeom = &(EDataFE1->ChangeGeometry());
+         const HLRBRep_Curve& EC = EDataFE1->Geometry();
          p = EC.Parameter3d((EC.LastParameter () +
                              EC.FirstParameter()) / 2);
          if (HLRBRep_EdgeFaceTool::UVPoint(p,myFEGeom,iFaceGeom,pu,pv)) {
            mySLProps.SetParameters(pu,pv);
            gp_Pnt Pt;
            Pt = EC.Value3D(p);
-#ifdef OCC191
             if (mySLProps.IsNormalDefined())
-#endif
             {
               gp_Vec Nm = mySLProps.Normal();
               Pt.Transform(T);
@@ -894,9 +892,9 @@ void HLRBRep_Data::Update (const HLRAlgo_Projector& P)
         myFaceItr1.MoreEdge();
         myFaceItr1.NextEdge()) {
       myFE = myFaceItr1.Edge();
-      HLRBRep_EdgeData* ed = &(myEData(myFE));
-      if (!fd->Simple()) ed->AutoIntersectionDone(Standard_False);
-      HLRAlgo::DecodeMinMax(ed->MinMax(),
+      HLRBRep_EdgeData* EDataFE2 = &(myEData(myFE));
+      if (!fd->Simple()) EDataFE2->AutoIntersectionDone(Standard_False);
+      HLRAlgo::DecodeMinMax(EDataFE2->MinMax(),
                            (Standard_Address)EdgeMin,
                            (Standard_Address)EdgeMax);
       if (myFaceItr1.BeginningOfWire())
@@ -1225,7 +1223,7 @@ void HLRBRep_Data::NextInterference ()
     if (myFEOri == TopAbs_FORWARD ||
        myFEOri == TopAbs_REVERSED) {
       // Edge from the boundary
-      if (!((HLRBRep_EdgeData*)myFEData)->Vertical() && !myFEDouble) {
+      if (!((HLRBRep_EdgeData*)myFEData)->Vertical() && !(myFEDouble && !myFEOutLine)) {
        // not a vertical edge and not a double Edge
        Standard_Address MinMaxFEdg = ((HLRBRep_EdgeData*)myFEData)->MinMax();
        //-- -----------------------------------------------------------------------
@@ -1367,7 +1365,7 @@ void HLRBRep_Data::NextInterference ()
                  }
                  else {
                    myNbPoints = myNbSegments = 0;
-#ifdef DEB
+#ifdef OCCT_DEBUG
                    cout << "HLRBRep_Data::NextInterference : "; 
                    if (myLE == myFE) 
                      cout << "Edge " << myLE 
@@ -1490,49 +1488,59 @@ void HLRBRep_Data::LocalFEGeometry2D (const Standard_Integer FE,
 //=======================================================================
 
 void HLRBRep_Data::EdgeState (const Standard_Real p1,
-                             const Standard_Real p2,
-                             TopAbs_State& stbef,
-                             TopAbs_State& staft)
+                              const Standard_Real p2,
+                              TopAbs_State& stbef,
+                              TopAbs_State& staft)
 {
   // compute the state of The Edge near the Intersection
   // this method should give the states before and after
   // it should get the parameters on the surface
-  
-  gp_Pnt Pbid;
-  gp_Vec TngEdge;
-  ((HLRBRep_Curve*)myLEGeom)->D1(p1,Pbid,TngEdge);
+
   Standard_Real pu,pv;
-  if (HLRBRep_EdgeFaceTool::UVPoint(p2,myFEGeom,iFaceGeom,pu,pv)) {
+  if (HLRBRep_EdgeFaceTool::UVPoint(p2,myFEGeom,iFaceGeom,pu,pv))
+  {
     mySLProps.SetParameters(pu,pv);
-    gp_Dir NrmFace  = mySLProps.Normal();
-    const gp_Trsf& TI = myProj.InvertedTransformation();
-    gp_Dir V;
-    if (myProj.Perspective()) {
-      gp_Pnt2d P2d;
-      myProj.Project(Pbid,P2d);
-      V = gp_Dir(P2d.X(),P2d.Y(),-myProj.Focus());
+    if (mySLProps.IsNormalDefined())
+    {
+      gp_Dir NrmFace  = mySLProps.Normal();
+
+      gp_Pnt Pbid;
+      gp_Vec TngEdge;
+      ((HLRBRep_Curve*)myLEGeom)->D1(p1,Pbid,TngEdge);
+
+      const gp_Trsf& TI = myProj.InvertedTransformation();
+      gp_Dir V;
+      if (myProj.Perspective()) {
+        gp_Pnt2d P2d;
+        myProj.Project(Pbid,P2d);
+        V = gp_Dir(P2d.X(),P2d.Y(),-myProj.Focus());
+      }
+      else {
+        V = gp_Dir(0,0,-1);
+      }
+      V.Transform(TI);
+      if (NrmFace.Dot(V) > 0.)
+        NrmFace.Reverse();
+    
+      const Standard_Real scal = (TngEdge.SquareMagnitude()>1.e-10)? NrmFace.Dot(gp_Dir(TngEdge)) : 0.;
+
+      if      (scal >  myToler*10) {stbef = TopAbs_IN ;staft = TopAbs_OUT;}
+      else if (scal < -myToler*10) {stbef = TopAbs_OUT;staft = TopAbs_IN ;}
+      else                         {stbef = TopAbs_ON ;staft = TopAbs_ON ;}
     }
     else {
-      V = gp_Dir(0,0,-1);
+      stbef = TopAbs_OUT;
+      staft = TopAbs_OUT;
+#ifdef OCCT_DEBUG
+    cout << "HLRBRep_Data::EdgeState : undefined" << endl;
+#endif
     }
-    V.Transform(TI);
-    if (NrmFace.Dot(V) > 0)
-      NrmFace.Reverse();
-    
-    Standard_Real scal;
-    if(TngEdge.SquareMagnitude()>1e-10) 
-      scal=NrmFace.Dot(gp_Dir(TngEdge));
-    else scal=0.0;
-    
-    if      (scal >  myToler*10) {stbef = TopAbs_IN ;staft = TopAbs_OUT;}
-    else if (scal < -myToler*10) {stbef = TopAbs_OUT;staft = TopAbs_IN ;}
-    else                         {stbef = TopAbs_ON ;staft = TopAbs_ON ;}
   }
   else {
     stbef = TopAbs_OUT;
     staft = TopAbs_OUT; 
-#ifdef DEB
-    cout << "HLRBRep_Data::EdgeState : undefined" << endl; 
+#ifdef OCCT_DEBUG
+    cout << "HLRBRep_Data::EdgeState : undefined" << endl;
 #endif
   }
 }
@@ -1563,22 +1571,15 @@ HLRBRep_Data::HidingStartLevel (const Standard_Integer E,
       Loop = Standard_False;
     else {
       if (Abs(param-sta) > Abs(param-end))
-       end = param;
+        end = param;
       else
-       sta = param;
+        sta = param;
     }
     It.Next();
   }
-  param = (sta + end) / 2;
-#ifndef DEB
+  param = 0.5 * (sta + end);
   Standard_Integer level = 0;
-#else
-  Standard_Integer level;
-#endif
-#ifdef DEB
-  TopAbs_State st = 
-#endif
-    Classify(E,ED,Standard_True,level,param);
+  /*TopAbs_State st = */Classify(E,ED,Standard_True,level,param);
   Loop = Standard_True;
   It.Initialize(IL);
 
@@ -1589,21 +1590,21 @@ HLRBRep_Data::HidingStartLevel (const Standard_Integer E,
       switch (Int.Transition()) {
        
       case TopAbs_FORWARD  :
-       level = level - Int.Intersection().Level();
-       break;
+        level -= Int.Intersection().Level();
+        break;
       case TopAbs_REVERSED :
-       level = level + Int.Intersection().Level();
-       break;
+        level += Int.Intersection().Level();
+        break;
       case TopAbs_EXTERNAL :
       case TopAbs_INTERNAL :
-       default :
-         break;
+         default :
+           break;
       }
     }
     else if (p > param + tolpar)
       Loop = Standard_False;
     else {
-#ifdef DEB  
+#ifdef OCCT_DEBUG
       cout << "HLRBRep_Data::HidingStartLevel : ";
       cout << "Bad Parameter." << endl;
 #endif
@@ -1619,10 +1620,10 @@ HLRBRep_Data::HidingStartLevel (const Standard_Integer E,
 //=======================================================================
 
 TopAbs_State HLRBRep_Data::Compare (const Standard_Integer E,
-                                   const HLRBRep_EdgeData& ED)
+                                    const HLRBRep_EdgeData& ED)
 {
-  Standard_Integer level;
-  Standard_Real parbid = 0;
+  Standard_Integer level = 0;
+  Standard_Real parbid = 0.;
   return Classify(E,ED,Standard_False,level,parbid);
 }
 
@@ -1631,10 +1632,11 @@ TopAbs_State HLRBRep_Data::Compare (const Standard_Integer E,
 //purpose  : 
 //=======================================================================
 
-Standard_Boolean
-HLRBRep_Data::OrientOutLine (const Standard_Integer I,
-                            HLRBRep_FaceData& FD)
+
+Standard_Boolean HLRBRep_Data::OrientOutLine (const Standard_Integer I, HLRBRep_FaceData& FD)
 {
+  (void)I; // avoid compiler warning
+
   const Handle(HLRAlgo_WiresBlock)& wb = FD.Wires();
   Standard_Integer nw = wb->NbWires();
   Standard_Integer iw1,ie1,ne1;
@@ -1686,7 +1688,7 @@ HLRBRep_Data::OrientOutLine (const Standard_Integer I,
            (iFaceGeom,pu,pv,V);
          gp_Vec Nm = mySLProps.Normal();
          if (curv == 0) {
-#ifdef DEB  
+#ifdef OCCT_DEBUG
            cout << "HLRBRep_Data::OrientOutLine " << I;
            cout << " Edge " << myFE << " : ";
            cout << "CurvatureValue == 0." << endl;
@@ -1699,7 +1701,7 @@ HLRBRep_Data::OrientOutLine (const Standard_Integer I,
          Nm.Transform(T);
          Nm.Cross(Tg);
          if (Tg.Magnitude() < gp::Resolution()) {
-#ifdef DEB  
+#ifdef OCCT_DEBUG
            cout << "HLRBRep_Data::OrientOutLine " << I;
            cout << " Edge " << myFE << " : ";
            cout << "Tg.Magnitude() == 0." << endl;
@@ -1721,7 +1723,7 @@ HLRBRep_Data::OrientOutLine (const Standard_Integer I,
          eb1->Orientation(ie1,myFEOri);
        }
        else {
-#ifdef DEB  
+#ifdef OCCT_DEBUG
          cout << "HLRBRep_Data::OrientOutLine " << I;
          cout << " Edge " << myFE << " : ";
          cout << "UVPoint not found, OutLine not Oriented" << endl;
@@ -1781,11 +1783,15 @@ void HLRBRep_Data::OrientOthEdge (const Standard_Integer I,
            eb1->Orientation(ie1,myFEOri);
          }
        }
+#ifdef OCCT_DEBUG
        else {
          cout << "HLRBRep_Data::OrientOthEdge " << I;
          cout << " Edge " << myFE << " : ";
          cout << "UVPoint not found, Edge not Oriented" << endl;
        }
+#else
+        (void)I; // avoid compiler warning
+#endif
       }
     }
   }
@@ -1837,6 +1843,8 @@ HLRBRep_Data::Classify (const Standard_Integer E,
                        Standard_Integer& Level,
                        const Standard_Real param)
 {
+  (void)E; // avoid compiler warning
+
   nbClassification++;
   Standard_Integer VertMin[16],VertMax[16],MinMaxVert[16];
   Standard_Real TotMin[16],TotMax[16];
@@ -1979,10 +1987,8 @@ HLRBRep_Data::Classify (const Standard_Integer E,
     HLRAlgo::EncodeMinMax((Standard_Address)VertMin,
                          (Standard_Address)VertMax,
                          (Standard_Address)MinMaxVert);
-
-
-
-#if 0 
+    /*
+#ifdef OCCT_DEBUG
        {
          Standard_Integer qwe,qwep8,q,q1,q2;
          printf("\n E:%d -------\n",E);
@@ -2021,9 +2027,7 @@ HLRBRep_Data::Classify (const Standard_Integer E,
          cout<<endl;
        }
  #endif
-
-
-
+    */
 
     if (((MaxFace1 - MinVert1) & 0x80008000) != 0 ||
        ((MaxVert1 - MinFace1) & 0x80008000) != 0 ||
@@ -2106,7 +2110,9 @@ HLRBRep_Data::Classify (const Standard_Integer E,
            
            do {
              gp_Pnt2d pnt2d(u,v);
-             if (myClassifier->Classify(pnt2d,0.0)!=TopAbs_OUT) {
+             if (myClassifier->Classify(pnt2d,Precision::PConfusion())
+                  != TopAbs_OUT)
+              {
                InsideRestriction = Standard_True;
                state = TopAbs_IN;
                Level++;
@@ -2133,7 +2139,7 @@ HLRBRep_Data::Classify (const Standard_Integer E,
 //purpose  : 
 //=======================================================================
 
-TopAbs_State HLRBRep_Data::SimplClassify (const Standard_Integer E,
+TopAbs_State HLRBRep_Data::SimplClassify (const Standard_Integer /*E*/,
                                          const HLRBRep_EdgeData& ED,
                                          const Standard_Integer Nbp,
                                          const Standard_Real p1,
@@ -2207,11 +2213,7 @@ HLRBRep_Data::RejectedPoint (const IntRes2d_IntersectionPoint& PInter,
   Standard_Real p1,p2,dz;
   Standard_ShortReal t1,t2;
   TopAbs_State st;
-#ifndef DEB
   TopAbs_Orientation Orie =TopAbs_FORWARD ;
-#else
-  TopAbs_Orientation Orie ;
-#endif
   TopAbs_Orientation Or2 = TopAbs_INTERNAL;
   Standard_Boolean inverted = Standard_False;
   const IntRes2d_Transition* Tr1;
@@ -2287,11 +2289,7 @@ HLRBRep_Data::RejectedPoint (const IntRes2d_IntersectionPoint& PInter,
   }
 
   if (iFaceBack) Orie = TopAbs::Complement(Orie);  // change the transition
-#ifndef DEB
   TopAbs_Orientation Ori = TopAbs_FORWARD;
-#else
-  TopAbs_Orientation Ori;
-#endif
   switch (Tr1->PositionOnCurve()) {
   case IntRes2d_Head   : Ori = TopAbs_FORWARD ; break;
   case IntRes2d_Middle : Ori = TopAbs_INTERNAL; break;
@@ -2446,4 +2444,3 @@ HLRBRep_Data::SameVertex (const Standard_Boolean h1,
   }
   return SameV;
 }
-