0022623: Use of uninitialized variables in HLRBRep_Curve::UpdateMinMax in debug mode
[occt.git] / src / HLRBRep / HLRBRep_PolyHLRToShape.cxx
1 // File:      HLRBRep_PolyHLRToShape.cxx
2 // Created:   Mon Oct 11 16:55:56 1993
3 // Author:    Christophe MARION
4 // Copyright: OPEN CASCADE 2000
5
6 // Modified by cma, Fri Nov 10 17:36:13 1995
7
8 #include <HLRBRep_PolyHLRToShape.ixx>
9 #include <BRep_Builder.hxx>
10 #include <BRepLib_MakeEdge2d.hxx>
11 #include <TopoDS.hxx>
12 #include <TopExp_Explorer.hxx>
13 #include <TopTools_MapOfShape.hxx>
14 #include <HLRBRep_BiPnt2D.hxx>
15 #include <HLRBRep_ListIteratorOfListOfBPnt2D.hxx>
16 #include <HLRAlgo_EdgeStatus.hxx>
17 #include <HLRAlgo_EdgeIterator.hxx>
18
19 #define PntX1 ((Standard_Real*)Coordinates)[0]
20 #define PntY1 ((Standard_Real*)Coordinates)[1]
21 #define PntZ1 ((Standard_Real*)Coordinates)[2]
22 #define PntX2 ((Standard_Real*)Coordinates)[3]
23 #define PntY2 ((Standard_Real*)Coordinates)[4]
24 #define PntZ2 ((Standard_Real*)Coordinates)[5]
25
26 //=======================================================================
27 //function : HLRBRep_PolyHLRToShape
28 //purpose  : 
29 //=======================================================================
30
31 HLRBRep_PolyHLRToShape::HLRBRep_PolyHLRToShape ()
32 {}
33
34 //=======================================================================
35 //function : Update
36 //purpose  : 
37 //=======================================================================
38
39 void HLRBRep_PolyHLRToShape::Update (const Handle(HLRBRep_PolyAlgo)& A)
40 {
41   myAlgo = A;
42   myHideMode = Standard_True;
43   Standard_Real sta,end,XSta,YSta,ZSta,XEnd,YEnd,ZEnd,dx,dy;
44   Standard_ShortReal tolsta,tolend;
45   HLRAlgo_EdgeIterator It;
46   myBiPntVis.Clear();
47   myBiPntHid.Clear();
48   TopoDS_Shape S;
49   Standard_Boolean reg1,regn,outl,intl;
50   const gp_Trsf& T = myAlgo->Projector().Transformation();
51   HLRAlgo_EdgeStatus status;
52   Standard_Address Coordinates;
53
54   for (myAlgo->InitHide(); myAlgo->MoreHide(); myAlgo->NextHide()) {
55     myAlgo->Hide(Coordinates,status,S,reg1,regn,outl,intl);
56     XSta = PntX1;
57     YSta = PntY1;
58     ZSta = PntZ1;
59     XEnd = PntX2;
60     YEnd = PntY2;
61     ZEnd = PntZ2;
62     T.Transforms(XSta,YSta,ZSta);
63     T.Transforms(XEnd,YEnd,ZEnd);
64     dx = XEnd - XSta;
65     dy = YEnd - YSta;
66     if (sqrt(dx * dx + dy * dy) > 1.e-10) {
67     
68       for (It.InitVisible(status);
69            It.MoreVisible();
70            It.NextVisible()) {
71         It.Visible(sta,tolsta,end,tolend);
72         myBiPntVis.Append
73           (HLRBRep_BiPnt2D
74            (XSta + sta * dx,YSta + sta * dy,
75             XSta + end * dx,YSta + end * dy,
76             S,reg1,regn,outl,intl));
77       }
78       
79       for (It.InitHidden(status);
80            It.MoreHidden();
81            It.NextHidden()) {
82         It.Hidden(sta,tolsta,end,tolend);
83         myBiPntHid.Append
84           (HLRBRep_BiPnt2D
85            (XSta + sta * dx,YSta + sta * dy,
86             XSta + end * dx,YSta + end * dy,
87             S,reg1,regn,outl,intl));
88       }
89     }
90   }
91 }
92
93 //=======================================================================
94 //function : InternalCompound
95 //purpose  : 
96 //=======================================================================
97
98 TopoDS_Shape 
99 HLRBRep_PolyHLRToShape::InternalCompound (const Standard_Integer typ,
100                                           const Standard_Boolean visible,
101                                           const TopoDS_Shape& S)
102 {
103   TopTools_MapOfShape Map;
104   if (!S.IsNull()) {
105     TopExp_Explorer ex;
106     for (ex.Init(S,TopAbs_EDGE); ex.More(); ex.Next())
107       Map.Add(ex.Current());
108     for (ex.Init(S,TopAbs_FACE); ex.More(); ex.Next())
109       Map.Add(ex.Current());
110   }
111   Standard_Boolean todraw,reg1,regn,outl,intl;
112   Standard_Boolean added = Standard_False;
113   TopoDS_Shape Result;
114   BRep_Builder B;
115   B.MakeCompound(TopoDS::Compound(Result));
116
117   if (myHideMode) {
118     HLRBRep_ListIteratorOfListOfBPnt2D It;
119     if (visible) It.Initialize(myBiPntVis);
120     else         It.Initialize(myBiPntHid);
121     
122     for (; It.More(); It.Next()) {
123       const HLRBRep_BiPnt2D& BP = It.Value();
124       reg1 = BP.Rg1Line();
125       regn = BP.RgNLine();
126       outl = BP.OutLine();
127       intl = BP.IntLine();
128       if      (typ == 1) todraw =  intl;
129       else if (typ == 2) todraw =  reg1 && !regn && !outl;
130       else if (typ == 3) todraw =  regn && !outl;
131       else               todraw = !(intl || (reg1 && !outl));
132       if (todraw)
133         if (!S.IsNull()) todraw = Map.Contains(BP.Shape());
134       if (todraw) {
135         B.Add(Result,BRepLib_MakeEdge2d(BP.P1(),BP.P2()));
136         added = Standard_True;
137       }
138     }
139   }
140   else {
141     const gp_Trsf& T = myAlgo->Projector().Transformation();
142     TopoDS_Shape SBP;
143     Standard_Real XSta,YSta,ZSta,XEnd,YEnd,ZEnd,dx,dy;
144     Standard_Address Coordinates;
145
146     for (myAlgo->InitShow(); myAlgo->MoreShow(); myAlgo->NextShow()) {
147       myAlgo->Show(Coordinates,SBP,reg1,regn,outl,intl);
148       if      (typ == 1) todraw =  intl;
149       else if (typ == 2) todraw =  reg1 && !regn && !outl;
150       else if (typ == 3) todraw =  regn && !outl;
151       else               todraw = !(intl || (reg1 && !outl));
152       if (todraw)
153         if (!S.IsNull()) todraw = Map.Contains(SBP);
154       if (todraw) {
155         XSta = PntX1;
156         YSta = PntY1;
157         ZSta = PntZ1;
158         XEnd = PntX2;
159         YEnd = PntY2;
160         ZEnd = PntZ2;
161         T.Transforms(XSta,YSta,ZSta);
162         T.Transforms(XEnd,YEnd,ZEnd);
163         dx = XEnd - XSta;
164         dy = YEnd - YSta;
165         if (sqrt(dx * dx + dy * dy) > 1.e-10) {
166           B.Add(Result,BRepLib_MakeEdge2d(gp_Pnt2d(XSta,YSta),
167                                           gp_Pnt2d(XEnd,YEnd)));
168           added = Standard_True;
169         }
170       }
171     }
172   }
173   if (!added) Result = TopoDS_Shape();
174   return Result;
175 }