0028895: Visualization, V3d_View::SetComputedMode() - HLR calculation is performed...
[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
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
1eeef710 17#include <StdPrs_HLRPolyShape.hxx>
7fd59977 18
7fd59977 19#include <BRepMesh_IncrementalMesh.hxx>
1eeef710 20#include <Graphic3d_ArrayOfSegments.hxx>
42cf5bc1 21#include <Graphic3d_Group.hxx>
7fd59977 22#include <HLRAlgo_EdgeIterator.hxx>
42cf5bc1 23#include <HLRAlgo_EdgeStatus.hxx>
24#include <HLRBRep_BiPoint.hxx>
7fd59977 25#include <HLRBRep_ListIteratorOfListOfBPoint.hxx>
42cf5bc1 26#include <HLRBRep_ListOfBPoint.hxx>
27#include <HLRBRep_PolyAlgo.hxx>
28#include <Prs3d_LineAspect.hxx>
29#include <Prs3d_Presentation.hxx>
30#include <Prs3d_Projector.hxx>
42cf5bc1 31#include <StdPrs_WFShape.hxx>
7fd59977 32#include <TColgp_SequenceOfPnt.hxx>
42cf5bc1 33#include <TopAbs.hxx>
34#include <TopExp_Explorer.hxx>
35#include <TopoDS_Shape.hxx>
7fd59977 36
37#define PntX1 ((Standard_Real*)Coordinates)[0]
38#define PntY1 ((Standard_Real*)Coordinates)[1]
39#define PntZ1 ((Standard_Real*)Coordinates)[2]
40#define PntX2 ((Standard_Real*)Coordinates)[3]
41#define PntY2 ((Standard_Real*)Coordinates)[4]
42#define PntZ2 ((Standard_Real*)Coordinates)[5]
43
44//=======================================================================
45//function : Add
46//purpose :
47//=======================================================================
48
49void StdPrs_HLRPolyShape::Add(const Handle (Prs3d_Presentation)& aPresentation,
50 const TopoDS_Shape& aShape,
51 const Handle (Prs3d_Drawer)& aDrawer,
52 const Handle (Prs3d_Projector)& aProjector)
53{
54 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(aPresentation);
55
56 TopExp_Explorer ex;
57
7fd59977 58 // find vertices not under ancestors.
59 TopAbs_ShapeEnum E = aShape.ShapeType();
60 if (E == TopAbs_COMPOUND) {
81bba717 61 // it is necessary to present isolated vertexes instead of hiding them.
7fd59977 62 for (ex.Init(aShape, TopAbs_VERTEX, TopAbs_EDGE); ex.More(); ex.Next()) {
63 StdPrs_WFShape::Add(aPresentation, ex.Current(), aDrawer);
64 }
65 }
66
4c513386 67 if (aDrawer->IsAutoTriangulation())
68 {
69 const Standard_Boolean aRel = aDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE;
70 Standard_Real aDef = aRel ? aDrawer->HLRDeviationCoefficient() : aDrawer->MaximalChordialDeviation();
e71669c6 71 BRepMesh_FastDiscret::Parameters aMeshParams;
72 aMeshParams.Relative = aRel;
73 aMeshParams.Angle = aDrawer->HLRAngle();
74 aMeshParams.Deflection = aDef;
75 BRepMesh_IncrementalMesh mesh(aShape, aMeshParams);
4c513386 76 }
7fd59977 77
78 Handle(HLRBRep_PolyAlgo) hider = new HLRBRep_PolyAlgo(aShape);
79
80 hider->Projector(aProjector->Projector());
81 hider->Angle(aDrawer->HLRAngle());
82 hider->Update();
7fd59977 83 Standard_Real sta,end,dx,dy,dz;
84 Standard_ShortReal tolsta, tolend;
7fd59977 85 HLRAlgo_EdgeStatus status;
86 HLRAlgo_EdgeIterator It;
87 Standard_Boolean reg1,regn,outl, intl;
88 Standard_Address Coordinates;
89 TopoDS_Shape S;
90
91 HLRBRep_ListOfBPoint BiPntVis, BiPntHid;
92
b8ddfc2f 93 for (hider->InitHide(); hider->MoreHide(); hider->NextHide())
94 {
681f3919 95 Coordinates = &hider->Hide(status, S, reg1, regn, outl, intl);
7fd59977 96
97 dx = PntX2 - PntX1;
98 dy = PntY2 - PntY1;
99 dz = PntZ2 - PntZ1;
100
b8ddfc2f 101 for (It.InitVisible(status); It.MoreVisible(); It.NextVisible())
102 {
7fd59977 103 It.Visible(sta,tolsta,end,tolend);
104 BiPntVis.Append
b8ddfc2f 105 (HLRBRep_BiPoint
106 (PntX1 + sta * dx,PntY1 + sta * dy,PntZ1 + sta * dz,
107 PntX1 + end * dx,PntY1 + end * dy,PntZ1 + end * dz,
108 S,reg1,regn,outl,intl));
7fd59977 109 }
110
b8ddfc2f 111 for (It.InitHidden(status); It.MoreHidden(); It.NextHidden())
112 {
7fd59977 113 It.Hidden(sta,tolsta,end,tolend);
114 BiPntHid.Append
b8ddfc2f 115 (HLRBRep_BiPoint
116 (PntX1 + sta * dx,PntY1 + sta * dy,PntZ1 + sta * dz,
117 PntX1 + end * dx,PntY1 + end * dy,PntZ1 + end * dz,
118 S,reg1,regn,outl,intl));
7fd59977 119 }
120 }
7fd59977 121
1eeef710 122 // storage in the group
123 if (aDrawer->DrawHiddenLine())
124 {
125 Standard_Integer aNbHiddenSegments = 0;
126 for (HLRBRep_ListIteratorOfListOfBPoint aBPntHidIter (BiPntHid); aBPntHidIter.More(); aBPntHidIter.Next())
127 {
128 const HLRBRep_BiPoint& aBPnt = aBPntHidIter.Value();
129 if (!aBPnt.RgNLine()
130 || aBPnt.OutLine())
131 {
132 ++aNbHiddenSegments;
7fd59977 133 }
134 }
1eeef710 135 if (aNbHiddenSegments > 0)
136 {
137 Handle(Graphic3d_ArrayOfSegments) aHiddenArray = new Graphic3d_ArrayOfSegments (aNbHiddenSegments * 2);
138 for (HLRBRep_ListIteratorOfListOfBPoint aBPntHidIter (BiPntHid); aBPntHidIter.More(); aBPntHidIter.Next())
139 {
140 const HLRBRep_BiPoint& aBPnt = aBPntHidIter.Value();
141 if (!aBPnt.RgNLine()
142 || aBPnt.OutLine())
143 {
144 aHiddenArray->AddVertex (aBPnt.P1());
145 aHiddenArray->AddVertex (aBPnt.P2());
146 }
147 }
7fd59977 148
1eeef710 149 aGroup->SetPrimitivesAspect (aDrawer->HiddenLineAspect()->Aspect());
150 aGroup->AddPrimitiveArray (aHiddenArray);
7fd59977 151 }
152 }
1eeef710 153 {
154 Standard_Integer aNbSeenSegments = 0;
155 for (HLRBRep_ListIteratorOfListOfBPoint aBPntVisIter (BiPntVis); aBPntVisIter.More(); aBPntVisIter.Next())
156 {
157 const HLRBRep_BiPoint& aBPnt = aBPntVisIter.Value();
158 if (!aBPnt.RgNLine()
159 || aBPnt.OutLine())
160 {
161 ++aNbSeenSegments;
162 }
7fd59977 163 }
1eeef710 164 if (aNbSeenSegments > 0)
165 {
166 Handle(Graphic3d_ArrayOfSegments) aSeenArray = new Graphic3d_ArrayOfSegments (aNbSeenSegments * 2);
167 for (HLRBRep_ListIteratorOfListOfBPoint aBPntVisIter (BiPntVis); aBPntVisIter.More(); aBPntVisIter.Next())
168 {
169 const HLRBRep_BiPoint& aBPnt = aBPntVisIter.Value();
170 if (!aBPnt.RgNLine()
171 || aBPnt.OutLine())
172 {
173 aSeenArray->AddVertex (aBPnt.P1());
174 aSeenArray->AddVertex (aBPnt.P2());
175 }
176 }
177 aGroup->SetPrimitivesAspect (aDrawer->SeenLineAspect()->Aspect());
178 aGroup->AddPrimitiveArray (aSeenArray);
7fd59977 179 }
180 }
181}