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.hxx>
19 #include <BRepMesh_IncrementalMesh.hxx>
20 #include <Graphic3d_ArrayOfSegments.hxx>
21 #include <Graphic3d_Group.hxx>
22 #include <HLRAlgo_EdgeIterator.hxx>
23 #include <HLRAlgo_EdgeStatus.hxx>
24 #include <HLRBRep_BiPoint.hxx>
25 #include <HLRBRep_ListIteratorOfListOfBPoint.hxx>
26 #include <HLRBRep_ListOfBPoint.hxx>
27 #include <HLRBRep_PolyAlgo.hxx>
28 #include <Prs3d_LineAspect.hxx>
29 #include <Prs3d_Presentation.hxx>
30 #include <StdPrs_ToolTriangulatedShape.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 IMPLEMENT_STANDARD_RTTIEXT(StdPrs_HLRPolyShape, StdPrs_HLRShapeI)
46 //=======================================================================
49 //=======================================================================
50 void StdPrs_HLRPolyShape::ComputeHLR (const Handle(Prs3d_Presentation)& aPresentation,
51 const TopoDS_Shape& aShape,
52 const Handle(Prs3d_Drawer)& aDrawer,
53 const Handle(Graphic3d_Camera)& theProjector) const
55 gp_Dir aBackDir = -theProjector->Direction();
56 gp_Dir aXpers = theProjector->Up().Crossed (aBackDir);
57 gp_Ax3 anAx3 (theProjector->Center(), aBackDir, aXpers);
59 aTrsf.SetTransformation (anAx3);
60 const HLRAlgo_Projector aProj (aTrsf, !theProjector->IsOrthographic(), theProjector->Scale());
62 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(aPresentation);
66 // find vertices not under ancestors.
67 TopAbs_ShapeEnum E = aShape.ShapeType();
68 if (E == TopAbs_COMPOUND) {
69 // it is necessary to present isolated vertexes instead of hiding them.
70 for (ex.Init(aShape, TopAbs_VERTEX, TopAbs_EDGE); ex.More(); ex.Next()) {
71 StdPrs_WFShape::Add(aPresentation, ex.Current(), aDrawer);
75 if (aDrawer->IsAutoTriangulation())
77 StdPrs_ToolTriangulatedShape::Tessellate (aShape, aDrawer);
80 Handle(HLRBRep_PolyAlgo) hider = new HLRBRep_PolyAlgo(aShape);
81 hider->Projector (aProj);
83 Standard_Real sta,end,dx,dy,dz;
84 Standard_ShortReal tolsta, tolend;
85 HLRAlgo_EdgeStatus status;
86 HLRAlgo_EdgeIterator It;
87 Standard_Boolean reg1,regn,outl, intl;
88 Standard_Address Coordinates;
91 HLRBRep_ListOfBPoint BiPntVis, BiPntHid;
93 for (hider->InitHide(); hider->MoreHide(); hider->NextHide())
95 Coordinates = &hider->Hide(status, S, reg1, regn, outl, intl);
101 for (It.InitVisible(status); It.MoreVisible(); It.NextVisible())
103 It.Visible(sta,tolsta,end,tolend);
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));
111 for (It.InitHidden(status); It.MoreHidden(); It.NextHidden())
113 It.Hidden(sta,tolsta,end,tolend);
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));
122 // storage in the group
123 if (aDrawer->DrawHiddenLine())
125 Standard_Integer aNbHiddenSegments = 0;
126 for (HLRBRep_ListIteratorOfListOfBPoint aBPntHidIter (BiPntHid); aBPntHidIter.More(); aBPntHidIter.Next())
128 const HLRBRep_BiPoint& aBPnt = aBPntHidIter.Value();
135 if (aNbHiddenSegments > 0)
137 Handle(Graphic3d_ArrayOfSegments) aHiddenArray = new Graphic3d_ArrayOfSegments (aNbHiddenSegments * 2);
138 for (HLRBRep_ListIteratorOfListOfBPoint aBPntHidIter (BiPntHid); aBPntHidIter.More(); aBPntHidIter.Next())
140 const HLRBRep_BiPoint& aBPnt = aBPntHidIter.Value();
144 aHiddenArray->AddVertex (aBPnt.P1());
145 aHiddenArray->AddVertex (aBPnt.P2());
149 aGroup->SetPrimitivesAspect (aDrawer->HiddenLineAspect()->Aspect());
150 aGroup->AddPrimitiveArray (aHiddenArray);
154 Standard_Integer aNbSeenSegments = 0;
155 for (HLRBRep_ListIteratorOfListOfBPoint aBPntVisIter (BiPntVis); aBPntVisIter.More(); aBPntVisIter.Next())
157 const HLRBRep_BiPoint& aBPnt = aBPntVisIter.Value();
164 if (aNbSeenSegments > 0)
166 Handle(Graphic3d_ArrayOfSegments) aSeenArray = new Graphic3d_ArrayOfSegments (aNbSeenSegments * 2);
167 for (HLRBRep_ListIteratorOfListOfBPoint aBPntVisIter (BiPntVis); aBPntVisIter.More(); aBPntVisIter.Next())
169 const HLRBRep_BiPoint& aBPnt = aBPntVisIter.Value();
173 aSeenArray->AddVertex (aBPnt.P1());
174 aSeenArray->AddVertex (aBPnt.P2());
177 aGroup->SetPrimitivesAspect (aDrawer->SeenLineAspect()->Aspect());
178 aGroup->AddPrimitiveArray (aSeenArray);