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.
18 #include <BRepMesh_IncrementalMesh.hxx>
19 #include <Graphic3d_ArrayOfPolylines.hxx>
20 #include <Graphic3d_Group.hxx>
21 #include <HLRAlgo_EdgeIterator.hxx>
22 #include <HLRAlgo_EdgeStatus.hxx>
23 #include <HLRBRep_BiPoint.hxx>
24 #include <HLRBRep_ListIteratorOfListOfBPoint.hxx>
25 #include <HLRBRep_ListOfBPoint.hxx>
26 #include <HLRBRep_PolyAlgo.hxx>
27 #include <Prs3d_LineAspect.hxx>
28 #include <Prs3d_Presentation.hxx>
29 #include <Prs3d_Projector.hxx>
30 #include <StdPrs_HLRPolyShape.hxx>
31 #include <StdPrs_WFShape.hxx>
32 #include <TColgp_SequenceOfPnt.hxx>
34 #include <TopExp_Explorer.hxx>
35 #include <TopoDS_Shape.hxx>
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]
44 //=======================================================================
47 //=======================================================================
49 void 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)
54 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(aPresentation);
58 // find vertices not under ancestors.
59 TopAbs_ShapeEnum E = aShape.ShapeType();
60 if (E == TopAbs_COMPOUND) {
61 // it is necessary to present isolated vertexes instead of hiding them.
62 for (ex.Init(aShape, TopAbs_VERTEX, TopAbs_EDGE); ex.More(); ex.Next()) {
63 StdPrs_WFShape::Add(aPresentation, ex.Current(), aDrawer);
67 TColgp_SequenceOfPnt HiddenPnts;
68 TColgp_SequenceOfPnt SeenPnts;
70 if (aDrawer->IsAutoTriangulation())
72 const Standard_Boolean aRel = aDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE;
73 Standard_Real aDef = aRel ? aDrawer->HLRDeviationCoefficient() : aDrawer->MaximalChordialDeviation();
74 BRepMesh_IncrementalMesh mesh(aShape, aDef, aRel, 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);