1 // Created on: 1995-09-19
2 // Created by: Laurent PAINNOT
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
23 #include <StdPrs_HLRPolyShape.ixx>
25 #include <StdPrs_WFShape.hxx>
27 #include <TopExp_Explorer.hxx>
28 #include <Graphic3d_Group.hxx>
29 #include <Graphic3d_ArrayOfPolylines.hxx>
30 #include <Prs3d_LineAspect.hxx>
31 #include <BRepMesh_IncrementalMesh.hxx>
32 #include <HLRBRep_PolyAlgo.hxx>
33 #include <HLRBRep_ListOfBPoint.hxx>
34 #include <HLRBRep_BiPoint.hxx>
35 #include <HLRAlgo_EdgeStatus.hxx>
36 #include <HLRAlgo_EdgeIterator.hxx>
37 #include <HLRBRep_ListIteratorOfListOfBPoint.hxx>
38 #include <TColgp_SequenceOfPnt.hxx>
40 #define PntX1 ((Standard_Real*)Coordinates)[0]
41 #define PntY1 ((Standard_Real*)Coordinates)[1]
42 #define PntZ1 ((Standard_Real*)Coordinates)[2]
43 #define PntX2 ((Standard_Real*)Coordinates)[3]
44 #define PntY2 ((Standard_Real*)Coordinates)[4]
45 #define PntZ2 ((Standard_Real*)Coordinates)[5]
47 //=======================================================================
50 //=======================================================================
52 void StdPrs_HLRPolyShape::Add(const Handle (Prs3d_Presentation)& aPresentation,
53 const TopoDS_Shape& aShape,
54 const Handle (Prs3d_Drawer)& aDrawer,
55 const Handle (Prs3d_Projector)& aProjector)
57 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(aPresentation);
61 // find vertices not under ancestors.
62 TopAbs_ShapeEnum E = aShape.ShapeType();
63 if (E == TopAbs_COMPOUND) {
64 // it is necessary to present isolated vertexes instead of hiding them.
65 for (ex.Init(aShape, TopAbs_VERTEX, TopAbs_EDGE); ex.More(); ex.Next()) {
66 StdPrs_WFShape::Add(aPresentation, ex.Current(), aDrawer);
70 TColgp_SequenceOfPnt HiddenPnts;
71 TColgp_SequenceOfPnt SeenPnts;
73 const Standard_Boolean rel = aDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE;
74 Standard_Real def = rel? aDrawer->HLRDeviationCoefficient() : aDrawer->MaximalChordialDeviation();
75 BRepMesh_IncrementalMesh mesh(aShape, def, rel, aDrawer->HLRAngle());
77 Handle(HLRBRep_PolyAlgo) hider = new HLRBRep_PolyAlgo(aShape);
79 hider->Projector(aProjector->Projector());
80 hider->Angle(aDrawer->HLRAngle());
82 Standard_Real sta,end,dx,dy,dz;
83 Standard_ShortReal tolsta, tolend;
84 HLRAlgo_EdgeStatus status;
85 HLRAlgo_EdgeIterator It;
86 Standard_Boolean reg1,regn,outl, intl;
87 Standard_Address Coordinates;
90 HLRBRep_ListOfBPoint BiPntVis, BiPntHid;
92 for (hider->InitHide(); hider->MoreHide(); hider->NextHide())
94 hider->Hide(Coordinates, status, S, reg1, regn, outl, intl);
100 for (It.InitVisible(status); It.MoreVisible(); It.NextVisible())
102 It.Visible(sta,tolsta,end,tolend);
105 (PntX1 + sta * dx,PntY1 + sta * dy,PntZ1 + sta * dz,
106 PntX1 + end * dx,PntY1 + end * dy,PntZ1 + end * dz,
107 S,reg1,regn,outl,intl));
110 for (It.InitHidden(status); It.MoreHidden(); It.NextHidden())
112 It.Hidden(sta,tolsta,end,tolend);
115 (PntX1 + sta * dx,PntY1 + sta * dy,PntZ1 + sta * dz,
116 PntX1 + end * dx,PntY1 + end * dy,PntZ1 + end * dz,
117 S,reg1,regn,outl,intl));
121 // storage in the group:
122 HLRBRep_ListIteratorOfListOfBPoint ItB;
124 if (aDrawer->DrawHiddenLine()) {
125 for (ItB.Initialize(BiPntHid); ItB.More(); ItB.Next()) {
126 const HLRBRep_BiPoint& BP = ItB.Value();
127 if (!BP.RgNLine() || BP.OutLine()) {
128 HiddenPnts.Append(BP.P1());
129 HiddenPnts.Append(BP.P2());
134 for (ItB.Initialize(BiPntVis); ItB.More(); ItB.Next()) {
135 const HLRBRep_BiPoint& BP = ItB.Value();
136 if (!BP.RgNLine() || BP.OutLine()) {
137 SeenPnts.Append(BP.P1());
138 SeenPnts.Append(BP.P2());
142 Standard_Integer nbVertices = HiddenPnts.Length();
144 Handle(Graphic3d_ArrayOfPolylines) HiddenArray = new Graphic3d_ArrayOfPolylines(nbVertices, (Standard_Integer)nbVertices/2);
145 for(int i=1; i<=nbVertices; i+=2) {
146 HiddenArray->AddBound(2);
147 HiddenArray->AddVertex(HiddenPnts.Value(i));
148 HiddenArray->AddVertex(HiddenPnts.Value(i+1));
150 aGroup->SetPrimitivesAspect(aDrawer->HiddenLineAspect()->Aspect());
151 aGroup->AddPrimitiveArray(HiddenArray);
153 nbVertices = SeenPnts.Length();
155 Handle(Graphic3d_ArrayOfPolylines) SeenArray = new Graphic3d_ArrayOfPolylines(nbVertices, (Standard_Integer)nbVertices/2);
156 for(int i=1; i<=nbVertices; i+=2) {
157 SeenArray->AddBound(2);
158 SeenArray->AddVertex(SeenPnts.Value(i));
159 SeenArray->AddVertex(SeenPnts.Value(i+1));
161 aGroup->SetPrimitivesAspect(aDrawer->SeenLineAspect()->Aspect());
162 aGroup->AddPrimitiveArray(SeenArray);