7f24b768 |
1 | // Created on: 2014-10-14 |
2 | // Created by: Anton POLETAEV |
3 | // Copyright (c) 2013-2014 OPEN CASCADE SAS |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
12 | // |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
15 | |
16 | #ifndef _Prs3d_BndBox_H__ |
17 | #define _Prs3d_BndBox_H__ |
18 | |
19 | #include <Bnd_OBB.hxx> |
20 | #include <Graphic3d_ArrayOfSegments.hxx> |
21 | #include <Graphic3d_ArrayOfTriangles.hxx> |
22 | #include <Prs3d_Drawer.hxx> |
23 | #include <Prs3d_Presentation.hxx> |
24 | #include <Prs3d_Root.hxx> |
25 | |
26 | //! Tool for computing bounding box presentation. |
27 | class Prs3d_BndBox : public Prs3d_Root |
28 | { |
29 | public: |
30 | |
31 | //! Computes presentation of a bounding box. |
32 | //! @param thePresentation [in] the presentation. |
33 | //! @param theBndBox [in] the bounding box. |
34 | //! @param theDrawer [in] the drawer. |
35 | Standard_EXPORT static void Add (const Handle(Prs3d_Presentation)& thePresentation, |
36 | const Bnd_Box& theBndBox, |
37 | const Handle(Prs3d_Drawer)& theDrawer); |
38 | |
39 | //! Computes presentation of a bounding box. |
40 | //! @param thePresentation [in] the presentation. |
41 | //! @param theBndBox [in] the bounding box. |
42 | //! @param theDrawer [in] the drawer. |
43 | Standard_EXPORT static void Add (const Handle(Prs3d_Presentation)& thePresentation, |
44 | const Bnd_OBB& theBndBox, |
45 | const Handle(Prs3d_Drawer)& theDrawer); |
46 | |
47 | public: |
48 | |
49 | //! Create primitive array with line segments for displaying a box. |
50 | //! @param theBox [in] the box to add |
51 | static Handle(Graphic3d_ArrayOfSegments) FillSegments (const Bnd_OBB& theBox) |
52 | { |
53 | if (theBox.IsVoid()) |
54 | { |
55 | return Handle(Graphic3d_ArrayOfSegments)(); |
56 | } |
57 | |
58 | Handle(Graphic3d_ArrayOfSegments) aSegs = new Graphic3d_ArrayOfSegments (8, 12 * 2); |
59 | FillSegments (aSegs, theBox); |
60 | return aSegs; |
61 | } |
62 | |
63 | //! Create primitive array with line segments for displaying a box. |
64 | //! @param theBox [in] the box to add |
65 | static Handle(Graphic3d_ArrayOfSegments) FillSegments (const Bnd_Box& theBox) |
66 | { |
67 | if (theBox.IsVoid()) |
68 | { |
69 | return Handle(Graphic3d_ArrayOfSegments)(); |
70 | } |
71 | |
72 | Handle(Graphic3d_ArrayOfSegments) aSegs = new Graphic3d_ArrayOfSegments (8, 12 * 2); |
73 | FillSegments (aSegs, theBox); |
74 | return aSegs; |
75 | } |
76 | |
77 | //! Create primitive array with line segments for displaying a box. |
78 | //! @param theSegments [in] [out] primitive array to be filled; |
79 | //! should be at least 8 nodes and 24 edges in size |
80 | //! @param theBox [in] the box to add |
81 | static void FillSegments (const Handle(Graphic3d_ArrayOfSegments)& theSegments, const Bnd_OBB& theBox) |
82 | { |
83 | if (!theBox.IsVoid()) |
84 | { |
85 | gp_Pnt aXYZ[8]; |
86 | theBox.GetVertex (aXYZ); |
87 | fillSegments (theSegments, aXYZ); |
88 | } |
89 | } |
90 | |
91 | //! Create primitive array with line segments for displaying a box. |
92 | //! @param theSegments [in] [out] primitive array to be filled; |
93 | //! should be at least 8 nodes and 24 edges in size |
94 | //! @param theBox [in] the box to add |
95 | static void FillSegments (const Handle(Graphic3d_ArrayOfSegments)& theSegments, const Bnd_Box& theBox) |
96 | { |
97 | if (!theBox.IsVoid()) |
98 | { |
99 | const gp_Pnt aMin = theBox.CornerMin(); |
100 | const gp_Pnt aMax = theBox.CornerMax(); |
101 | const gp_Pnt aXYZ[8] = |
102 | { |
103 | gp_Pnt (aMin.X(), aMin.Y(), aMin.Z()), |
104 | gp_Pnt (aMax.X(), aMin.Y(), aMin.Z()), |
105 | gp_Pnt (aMin.X(), aMax.Y(), aMin.Z()), |
106 | gp_Pnt (aMax.X(), aMax.Y(), aMin.Z()), |
107 | gp_Pnt (aMin.X(), aMin.Y(), aMax.Z()), |
108 | gp_Pnt (aMax.X(), aMin.Y(), aMax.Z()), |
109 | gp_Pnt (aMin.X(), aMax.Y(), aMax.Z()), |
110 | gp_Pnt (aMax.X(), aMax.Y(), aMax.Z()), |
111 | }; |
112 | fillSegments (theSegments, aXYZ); |
113 | } |
114 | } |
115 | |
116 | public: |
117 | |
118 | //! Create primitive array with line segments for displaying a box. |
119 | //! @param theSegments [in] [out] primitive array to be filled; |
120 | //! should be at least 8 nodes and 24 edges in size |
121 | //! @param theBox [in] the box to add |
122 | static void fillSegments (const Handle(Graphic3d_ArrayOfSegments)& theSegments, const gp_Pnt* theBox) |
123 | { |
124 | const Standard_Integer aFrom = theSegments->VertexNumber(); |
125 | for (int aVertIter = 0; aVertIter < 8; ++aVertIter) |
126 | { |
127 | theSegments->AddVertex (theBox[aVertIter]); |
128 | } |
129 | |
130 | theSegments->AddEdges (aFrom + 1, aFrom + 2); |
131 | theSegments->AddEdges (aFrom + 3, aFrom + 4); |
132 | theSegments->AddEdges (aFrom + 5, aFrom + 6); |
133 | theSegments->AddEdges (aFrom + 7, aFrom + 8); |
134 | // |
135 | theSegments->AddEdges (aFrom + 1, aFrom + 3); |
136 | theSegments->AddEdges (aFrom + 2, aFrom + 4); |
137 | theSegments->AddEdges (aFrom + 5, aFrom + 7); |
138 | theSegments->AddEdges (aFrom + 6, aFrom + 8); |
139 | // |
140 | theSegments->AddEdges (aFrom + 1, aFrom + 5); |
141 | theSegments->AddEdges (aFrom + 2, aFrom + 6); |
142 | theSegments->AddEdges (aFrom + 3, aFrom + 7); |
143 | theSegments->AddEdges (aFrom + 4, aFrom + 8); |
144 | } |
145 | |
146 | }; |
147 | |
148 | #endif // _Prs3d_BndBox_H__ |