1 // Created on: 1995-09-19
2 // Created by: Laurent PAINNOT
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <StdPrs_HLRPolyShape.ixx>
19 #include <StdPrs_WFShape.hxx>
21 #include <TopExp_Explorer.hxx>
22 #include <Graphic3d_Group.hxx>
23 #include <Graphic3d_ArrayOfPolylines.hxx>
24 #include <Prs3d_LineAspect.hxx>
25 #include <BRepMesh_IncrementalMesh.hxx>
26 #include <HLRBRep_PolyAlgo.hxx>
27 #include <HLRBRep_ListOfBPoint.hxx>
28 #include <HLRBRep_BiPoint.hxx>
29 #include <HLRAlgo_EdgeStatus.hxx>
30 #include <HLRAlgo_EdgeIterator.hxx>
31 #include <HLRBRep_ListIteratorOfListOfBPoint.hxx>
32 #include <TColgp_SequenceOfPnt.hxx>
34 #define PntX1 ((Standard_Real*)Coordinates)[0]
35 #define PntY1 ((Standard_Real*)Coordinates)[1]
36 #define PntZ1 ((Standard_Real*)Coordinates)[2]
37 #define PntX2 ((Standard_Real*)Coordinates)[3]
38 #define PntY2 ((Standard_Real*)Coordinates)[4]
39 #define PntZ2 ((Standard_Real*)Coordinates)[5]
41 //=======================================================================
44 //=======================================================================
46 void StdPrs_HLRPolyShape::Add(const Handle (Prs3d_Presentation)& aPresentation,
47 const TopoDS_Shape& aShape,
48 const Handle (Prs3d_Drawer)& aDrawer,
49 const Handle (Prs3d_Projector)& aProjector)
51 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(aPresentation);
55 // find vertices not under ancestors.
56 TopAbs_ShapeEnum E = aShape.ShapeType();
57 if (E == TopAbs_COMPOUND) {
58 // it is necessary to present isolated vertexes instead of hiding them.
59 for (ex.Init(aShape, TopAbs_VERTEX, TopAbs_EDGE); ex.More(); ex.Next()) {
60 StdPrs_WFShape::Add(aPresentation, ex.Current(), aDrawer);
64 TColgp_SequenceOfPnt HiddenPnts;
65 TColgp_SequenceOfPnt SeenPnts;
67 const Standard_Boolean rel = aDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE;
68 Standard_Real def = rel? aDrawer->HLRDeviationCoefficient() : aDrawer->MaximalChordialDeviation();
69 BRepMesh_IncrementalMesh mesh(aShape, def, rel, aDrawer->HLRAngle());
71 Handle(HLRBRep_PolyAlgo) hider = new HLRBRep_PolyAlgo(aShape);
73 hider->Projector(aProjector->Projector());
74 hider->Angle(aDrawer->HLRAngle());
76 Standard_Real sta,end,dx,dy,dz;
77 Standard_ShortReal tolsta, tolend;
78 HLRAlgo_EdgeStatus status;
79 HLRAlgo_EdgeIterator It;
80 Standard_Boolean reg1,regn,outl, intl;
81 Standard_Address Coordinates;
84 HLRBRep_ListOfBPoint BiPntVis, BiPntHid;
86 for (hider->InitHide(); hider->MoreHide(); hider->NextHide())
88 hider->Hide(Coordinates, status, S, reg1, regn, outl, intl);
94 for (It.InitVisible(status); It.MoreVisible(); It.NextVisible())
96 It.Visible(sta,tolsta,end,tolend);
99 (PntX1 + sta * dx,PntY1 + sta * dy,PntZ1 + sta * dz,
100 PntX1 + end * dx,PntY1 + end * dy,PntZ1 + end * dz,
101 S,reg1,regn,outl,intl));
104 for (It.InitHidden(status); It.MoreHidden(); It.NextHidden())
106 It.Hidden(sta,tolsta,end,tolend);
109 (PntX1 + sta * dx,PntY1 + sta * dy,PntZ1 + sta * dz,
110 PntX1 + end * dx,PntY1 + end * dy,PntZ1 + end * dz,
111 S,reg1,regn,outl,intl));
115 // storage in the group:
116 HLRBRep_ListIteratorOfListOfBPoint ItB;
118 if (aDrawer->DrawHiddenLine()) {
119 for (ItB.Initialize(BiPntHid); ItB.More(); ItB.Next()) {
120 const HLRBRep_BiPoint& BP = ItB.Value();
121 if (!BP.RgNLine() || BP.OutLine()) {
122 HiddenPnts.Append(BP.P1());
123 HiddenPnts.Append(BP.P2());
128 for (ItB.Initialize(BiPntVis); ItB.More(); ItB.Next()) {
129 const HLRBRep_BiPoint& BP = ItB.Value();
130 if (!BP.RgNLine() || BP.OutLine()) {
131 SeenPnts.Append(BP.P1());
132 SeenPnts.Append(BP.P2());
136 Standard_Integer nbVertices = HiddenPnts.Length();
138 Handle(Graphic3d_ArrayOfPolylines) HiddenArray = new Graphic3d_ArrayOfPolylines(nbVertices, (Standard_Integer)nbVertices/2);
139 for(int i=1; i<=nbVertices; i+=2) {
140 HiddenArray->AddBound(2);
141 HiddenArray->AddVertex(HiddenPnts.Value(i));
142 HiddenArray->AddVertex(HiddenPnts.Value(i+1));
144 aGroup->SetPrimitivesAspect(aDrawer->HiddenLineAspect()->Aspect());
145 aGroup->AddPrimitiveArray(HiddenArray);
147 nbVertices = SeenPnts.Length();
149 Handle(Graphic3d_ArrayOfPolylines) SeenArray = new Graphic3d_ArrayOfPolylines(nbVertices, (Standard_Integer)nbVertices/2);
150 for(int i=1; i<=nbVertices; i+=2) {
151 SeenArray->AddBound(2);
152 SeenArray->AddVertex(SeenPnts.Value(i));
153 SeenArray->AddVertex(SeenPnts.Value(i+1));
155 aGroup->SetPrimitivesAspect(aDrawer->SeenLineAspect()->Aspect());
156 aGroup->AddPrimitiveArray(SeenArray);