0023634: Eliminate Polyline and Polygon usage in drawers
[occt.git] / src / StdPrs / StdPrs_HLRPolyShape.cxx
CommitLineData
b311480e 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
5//
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.
10//
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.
13//
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.
20
7fd59977 21
22
23#include <StdPrs_HLRPolyShape.ixx>
24
25#include <StdPrs_WFShape.hxx>
26#include <TopAbs.hxx>
27#include <TopExp_Explorer.hxx>
28#include <Graphic3d_Group.hxx>
7fd59977 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>
39
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]
46
47//=======================================================================
48//function : Add
49//purpose :
50//=======================================================================
51
52void 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)
56{
57 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(aPresentation);
58
59 TopExp_Explorer ex;
60
7fd59977 61 // find vertices not under ancestors.
62 TopAbs_ShapeEnum E = aShape.ShapeType();
63 if (E == TopAbs_COMPOUND) {
81bba717 64 // it is necessary to present isolated vertexes instead of hiding them.
7fd59977 65 for (ex.Init(aShape, TopAbs_VERTEX, TopAbs_EDGE); ex.More(); ex.Next()) {
66 StdPrs_WFShape::Add(aPresentation, ex.Current(), aDrawer);
67 }
68 }
69
7fd59977 70 TColgp_SequenceOfPnt HiddenPnts;
71 TColgp_SequenceOfPnt SeenPnts;
72
b8ddfc2f 73 const Standard_Boolean rel = aDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE;
74 Standard_Real def = rel? aDrawer->HLRDeviationCoefficient() : aDrawer->MaximalChordialDeviation();
7fd59977 75 BRepMesh_IncrementalMesh mesh(aShape, def, rel, aDrawer->HLRAngle());
76
77 Handle(HLRBRep_PolyAlgo) hider = new HLRBRep_PolyAlgo(aShape);
78
79 hider->Projector(aProjector->Projector());
80 hider->Angle(aDrawer->HLRAngle());
81 hider->Update();
7fd59977 82 Standard_Real sta,end,dx,dy,dz;
83 Standard_ShortReal tolsta, tolend;
7fd59977 84 HLRAlgo_EdgeStatus status;
85 HLRAlgo_EdgeIterator It;
86 Standard_Boolean reg1,regn,outl, intl;
87 Standard_Address Coordinates;
88 TopoDS_Shape S;
89
90 HLRBRep_ListOfBPoint BiPntVis, BiPntHid;
91
b8ddfc2f 92 for (hider->InitHide(); hider->MoreHide(); hider->NextHide())
93 {
7fd59977 94 hider->Hide(Coordinates, status, S, reg1, regn, outl, intl);
95
96 dx = PntX2 - PntX1;
97 dy = PntY2 - PntY1;
98 dz = PntZ2 - PntZ1;
99
b8ddfc2f 100 for (It.InitVisible(status); It.MoreVisible(); It.NextVisible())
101 {
7fd59977 102 It.Visible(sta,tolsta,end,tolend);
103 BiPntVis.Append
b8ddfc2f 104 (HLRBRep_BiPoint
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));
7fd59977 108 }
109
b8ddfc2f 110 for (It.InitHidden(status); It.MoreHidden(); It.NextHidden())
111 {
7fd59977 112 It.Hidden(sta,tolsta,end,tolend);
113 BiPntHid.Append
b8ddfc2f 114 (HLRBRep_BiPoint
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));
7fd59977 118 }
119 }
120
81bba717 121 // storage in the group:
7fd59977 122 HLRBRep_ListIteratorOfListOfBPoint ItB;
123
124 if (aDrawer->DrawHiddenLine()) {
7fd59977 125 for (ItB.Initialize(BiPntHid); ItB.More(); ItB.Next()) {
126 const HLRBRep_BiPoint& BP = ItB.Value();
127 if (!BP.RgNLine() || BP.OutLine()) {
b8ddfc2f 128 HiddenPnts.Append(BP.P1());
129 HiddenPnts.Append(BP.P2());
7fd59977 130 }
131 }
7fd59977 132 }
133
7fd59977 134 for (ItB.Initialize(BiPntVis); ItB.More(); ItB.Next()) {
135 const HLRBRep_BiPoint& BP = ItB.Value();
136 if (!BP.RgNLine() || BP.OutLine()) {
b8ddfc2f 137 SeenPnts.Append(BP.P1());
138 SeenPnts.Append(BP.P2());
7fd59977 139 }
140 }
b8ddfc2f 141
142 Standard_Integer nbVertices = HiddenPnts.Length();
143 if(nbVertices > 0) {
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));
7fd59977 149 }
b8ddfc2f 150 aGroup->SetPrimitivesAspect(aDrawer->HiddenLineAspect()->Aspect());
151 aGroup->AddPrimitiveArray(HiddenArray);
152 }
153 nbVertices = SeenPnts.Length();
154 if(nbVertices > 0) {
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));
7fd59977 160 }
b8ddfc2f 161 aGroup->SetPrimitivesAspect(aDrawer->SeenLineAspect()->Aspect());
162 aGroup->AddPrimitiveArray(SeenArray);
7fd59977 163 }
164}