5ad8c033 |
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 _StdPrs_Isolines_H__ |
17 | #define _StdPrs_Isolines_H__ |
18 | |
19 | #include <BRepAdaptor_HSurface.hxx> |
20 | #include <Geom_Surface.hxx> |
21 | #include <Prs3d_Drawer.hxx> |
22 | #include <Prs3d_Presentation.hxx> |
23 | #include <Prs3d_LineAspect.hxx> |
24 | #include <Prs3d_Root.hxx> |
25 | #include <Prs3d_NListOfSequenceOfPnt.hxx> |
26 | #include <Poly_Triangulation.hxx> |
1b9f5d95 |
27 | #include <StdPrs_DeflectionCurve.hxx> |
5ad8c033 |
28 | #include <StdPrs_ToolTriangulatedShape.hxx> |
29 | #include <TColStd_Array1OfInteger.hxx> |
30 | #include <TColgp_Array1OfPnt2d.hxx> |
31 | #include <TColStd_SequenceOfReal.hxx> |
32 | |
33 | class Poly_Triangle; |
34 | class TopoDS_Face; |
35 | class TopLoc_Location; |
36 | |
37 | //! Tool for computing isoline representation for a face or surface. |
38 | //! Depending on a flags set to the given Prs3d_Drawer instance, on-surface (is used |
39 | //! by default) or on-triangulation isoline builder algorithm will be used. |
40 | //! If the given shape is not triangulated, on-surface isoline builder will be applied |
41 | //! regardless of Prs3d_Drawer flags. |
42 | class StdPrs_Isolines : public Prs3d_Root |
43 | { |
44 | public: |
45 | |
46 | //! Computes isolines presentation for a TopoDS face. |
47 | //! This method chooses proper version of isoline builder algorithm : on triangulation |
48 | //! or surface depending on the flag passed from Prs3d_Drawer attributes. |
49 | //! This method is a default way to display isolines for a given TopoDS face. |
50 | //! @param thePresentation [in] the presentation. |
51 | //! @param theFace [in] the face. |
52 | //! @param theDrawer [in] the display settings. |
53 | //! @param theDeflection [in] the deflection for isolines-on-surface version. |
54 | inline static void Add (const Handle(Prs3d_Presentation)& thePresentation, |
55 | const TopoDS_Face& theFace, |
56 | const Handle(Prs3d_Drawer)& theDrawer, |
57 | const Standard_Real theDeflection) |
58 | { |
59 | if (theDrawer->IsoOnTriangulation() && StdPrs_ToolTriangulatedShape::IsTriangulated (theFace)) |
60 | { |
61 | AddOnTriangulation (thePresentation, theFace, theDrawer); |
62 | } |
63 | else |
64 | { |
65 | AddOnSurface (thePresentation, theFace, theDrawer, theDeflection); |
66 | } |
67 | } |
68 | |
1b9f5d95 |
69 | //! Computes isolines presentation for a TopoDS face. |
70 | //! This method chooses proper version of isoline builder algorithm : on triangulation |
71 | //! or surface depending on the flag passed from Prs3d_Drawer attributes. |
72 | //! This method is a default way to display isolines for a given TopoDS face. |
73 | //! @param theFace [in] the face. |
74 | //! @param theDrawer [in] the display settings. |
75 | //! @param theDeflection [in] the deflection for isolines-on-surface version. |
76 | static void Add (const TopoDS_Face& theFace, |
77 | const Handle(Prs3d_Drawer)& theDrawer, |
78 | const Standard_Real theDeflection, |
79 | Prs3d_NListOfSequenceOfPnt& theUPolylines, |
80 | Prs3d_NListOfSequenceOfPnt& theVPolylines) |
81 | { |
82 | if (theDrawer->IsoOnTriangulation() && StdPrs_ToolTriangulatedShape::IsTriangulated (theFace)) |
83 | { |
84 | AddOnTriangulation (theFace, theDrawer, theUPolylines, theVPolylines); |
85 | } |
86 | else |
87 | { |
88 | AddOnSurface (theFace, theDrawer, theDeflection, theUPolylines, theVPolylines); |
89 | } |
90 | } |
91 | |
5ad8c033 |
92 | //! Computes isolines on triangulation and adds them to a presentation. |
93 | //! @param thePresentation [in] the presentation. |
94 | //! @param theFace [in] the face. |
95 | //! @param theDrawer [in] the display settings. |
96 | Standard_EXPORT static void AddOnTriangulation (const Handle(Prs3d_Presentation)& thePresentation, |
97 | const TopoDS_Face& theFace, |
98 | const Handle(Prs3d_Drawer)& theDrawer); |
99 | |
1b9f5d95 |
100 | //! Computes isolines on triangulation. |
101 | //! @param theFace [in] the face. |
102 | //! @param theDrawer [in] the display settings. |
103 | //! @param theUPolylines [out] the sequence of result polylines |
104 | //! @param theVPolylines [out] the sequence of result polylines |
105 | Standard_EXPORT static void AddOnTriangulation (const TopoDS_Face& theFace, |
106 | const Handle(Prs3d_Drawer)& theDrawer, |
107 | Prs3d_NListOfSequenceOfPnt& theUPolylines, |
108 | Prs3d_NListOfSequenceOfPnt& theVPolylines); |
109 | |
5ad8c033 |
110 | //! Computes isolines on triangulation and adds them to a presentation. |
111 | //! @param thePresentation [in] the presentation. |
112 | //! @param theTriangulation [in] the triangulation. |
113 | //! @param theSurface [in] the definition of triangulated surface. The surface |
114 | //! adapter is used to precisely evaluate isoline points using surface |
115 | //! law and fit them on triangulation. If NULL is passed, the method will |
116 | //! use linear interpolation of triangle node's UV coordinates to evaluate |
117 | //! isoline points. |
118 | //! @param theLocation [in] the location transformation defined for triangulation (surface). |
119 | //! @param theDrawer [in] the display settings. |
120 | //! @param theUIsoParams [in] the parameters of u isolines to compute. |
121 | //! @param theVIsoParams [in] the parameters of v isolines to compute. |
122 | Standard_EXPORT static void AddOnTriangulation (const Handle(Prs3d_Presentation)& thePresentation, |
123 | const Handle(Poly_Triangulation)& theTriangulation, |
124 | const Handle(Geom_Surface)& theSurface, |
125 | const TopLoc_Location& theLocation, |
126 | const Handle(Prs3d_Drawer)& theDrawer, |
127 | const TColStd_SequenceOfReal& theUIsoParams, |
128 | const TColStd_SequenceOfReal& theVIsoParams); |
129 | |
130 | //! Computes isolines on surface and adds them to presentation. |
131 | //! @param thePresentation [in] the presentation. |
132 | //! @param theFace [in] the face. |
133 | //! @param theDrawer [in] the display settings. |
134 | //! @param theDeflection [in] the deflection value. |
135 | Standard_EXPORT static void AddOnSurface (const Handle(Prs3d_Presentation)& thePresentation, |
136 | const TopoDS_Face& theFace, |
137 | const Handle(Prs3d_Drawer)& theDrawer, |
138 | const Standard_Real theDeflection); |
139 | |
1b9f5d95 |
140 | //! Computes isolines on surface and adds them to presentation. |
141 | //! @param theFace [in] the face |
142 | //! @param theDrawer [in] the display settings |
143 | //! @param theDeflection [in] the deflection value |
144 | //! @param theUPolylines [out] the sequence of result polylines |
145 | //! @param theVPolylines [out] the sequence of result polylines |
146 | Standard_EXPORT static void AddOnSurface (const TopoDS_Face& theFace, |
147 | const Handle(Prs3d_Drawer)& theDrawer, |
148 | const Standard_Real theDeflection, |
149 | Prs3d_NListOfSequenceOfPnt& theUPolylines, |
150 | Prs3d_NListOfSequenceOfPnt& theVPolylines); |
151 | |
5ad8c033 |
152 | //! Computes isolines on surface and adds them to presentation. |
153 | //! @param thePresentation [in] the presentation. |
154 | //! @param theSurface [in] the surface. |
155 | //! @param theDrawer [in] the display settings. |
156 | //! @param theDeflection [in] the deflection value. |
157 | //! @param theUIsoParams [in] the parameters of u isolines to compute. |
158 | //! @param theVIsoParams [in] the parameters of v isolines to compute. |
159 | Standard_EXPORT static void AddOnSurface (const Handle(Prs3d_Presentation)& thePresentation, |
160 | const Handle(BRepAdaptor_HSurface)& theSurface, |
161 | const Handle(Prs3d_Drawer)& theDrawer, |
162 | const Standard_Real theDeflection, |
163 | const TColStd_SequenceOfReal& theUIsoParams, |
164 | const TColStd_SequenceOfReal& theVIsoParams); |
165 | |
166 | //! Evalute sequence of parameters for drawing uv isolines for a given face. |
167 | //! @param theFace [in] the face. |
168 | //! @param theNbIsoU [in] the number of u isolines. |
169 | //! @param theNbIsoV [in] the number of v isolines. |
170 | //! @param theUVLimit [in] the u, v parameter value limit. |
171 | //! @param theUIsoParams [out] the sequence of u isoline parameters. |
172 | //! @param theVIsoParams [out] the sequence of v isoline parameters. |
173 | Standard_EXPORT static void UVIsoParameters (const TopoDS_Face& theFace, |
174 | const Standard_Integer theNbIsoU, |
175 | const Standard_Integer theNbIsoV, |
176 | const Standard_Real theUVLimit, |
177 | TColStd_SequenceOfReal& theUIsoParams, |
178 | TColStd_SequenceOfReal& theVIsoParams); |
179 | |
1b9f5d95 |
180 | public: |
181 | |
182 | //! Auxiliary structure defining 3D point on isoline. |
183 | struct PntOnIso |
184 | { |
185 | gp_Pnt Pnt; //!< 3D point |
186 | double Param; //!< parameter along the line (for sorting) |
187 | }; |
188 | |
189 | //! Auxiliary structure defining segment of isoline. |
190 | struct SegOnIso |
191 | { |
192 | |
193 | PntOnIso Pnts[2]; |
194 | |
195 | operator PntOnIso*() { return Pnts; } |
196 | operator const PntOnIso*() const { return Pnts; } |
197 | |
198 | bool operator< (const SegOnIso& theOther) const |
199 | { |
200 | return Pnts[1].Param < theOther.Pnts[0].Param; |
201 | } |
202 | |
203 | }; |
204 | |
5ad8c033 |
205 | private: |
206 | |
1b9f5d95 |
207 | //! Computes isolines on surface. |
208 | //! @param theSurface [in] the surface |
209 | //! @param theDrawer [in] the display settings |
210 | //! @param theDeflection [in] the deflection value |
211 | //! @param theUIsoParams [in] the parameters of u isolines to compute |
212 | //! @param theVIsoParams [in] the parameters of v isolines to compute |
213 | //! @param theUPolylines [out] the sequence of result polylines |
214 | //! @param theVPolylines [out] the sequence of result polylines |
215 | Standard_EXPORT static void addOnSurface (const Handle(BRepAdaptor_HSurface)& theSurface, |
216 | const Handle(Prs3d_Drawer)& theDrawer, |
217 | const Standard_Real theDeflection, |
218 | const TColStd_SequenceOfReal& theUIsoParams, |
219 | const TColStd_SequenceOfReal& theVIsoParams, |
220 | Prs3d_NListOfSequenceOfPnt& theUPolylines, |
221 | Prs3d_NListOfSequenceOfPnt& theVPolylines); |
222 | |
223 | //! Computes isolines on triangulation. |
224 | //! @param thePresentation [in] the presentation |
225 | //! @param theTriangulation [in] the triangulation |
226 | //! @param theSurface [in] the definition of triangulated surface. The surface |
227 | //! adapter is used to precisely evaluate isoline points using surface |
228 | //! law and fit them on triangulation. If NULL is passed, the method will |
229 | //! use linear interpolation of triangle node's UV coordinates to evaluate |
230 | //! isoline points |
231 | //! @param theLocation [in] the location transformation defined for triangulation (surface) |
232 | //! @param theDrawer [in] the display settings |
233 | //! @param theUIsoParams [in] the parameters of u isolines to compute |
234 | //! @param theVIsoParams [in] the parameters of v isolines to compute |
235 | //! @param theUPolylines [out] the sequence of result polylines |
236 | //! @param theVPolylines [out] the sequence of result polylines |
237 | Standard_EXPORT static void addOnTriangulation (const Handle(Poly_Triangulation)& theTriangulation, |
238 | const Handle(Geom_Surface)& theSurface, |
239 | const TopLoc_Location& theLocation, |
240 | const TColStd_SequenceOfReal& theUIsoParams, |
241 | const TColStd_SequenceOfReal& theVIsoParams, |
242 | Prs3d_NListOfSequenceOfPnt& theUPolylines, |
243 | Prs3d_NListOfSequenceOfPnt& theVPolylines); |
244 | |
5ad8c033 |
245 | //! Find isoline segment on a triangle. |
246 | //! @param theSurface [in] the surface. |
1b9f5d95 |
247 | //! @param theIsU [in] when true than U isoline is specified, V isoline otherwise |
5ad8c033 |
248 | //! @param theIsoline [in] the isoline in uv coordinates. |
249 | //! @param theNodesXYZ [in] the XYZ coordinates of triangle nodes. |
250 | //! @param theNodesUV [in] the UV coordinates of triangle nodes. |
251 | //! @param theSegment [out] the XYZ points of crossed triangle's links. |
1b9f5d95 |
252 | //! with U cross point parameter for V isoline |
253 | //! or V parameters for U isoline (depending on theIsU) |
5ad8c033 |
254 | //! @return TRUE if the isoline passes through the triangle. |
255 | Standard_EXPORT static Standard_Boolean findSegmentOnTriangulation (const Handle(Geom_Surface)& theSurface, |
1b9f5d95 |
256 | const bool theIsU, |
5ad8c033 |
257 | const gp_Lin2d& theIsoline, |
258 | const gp_Pnt* theNodesXYZ, |
259 | const gp_Pnt2d* theNodesUV, |
1b9f5d95 |
260 | SegOnIso& theSegment); |
5ad8c033 |
261 | }; |
262 | |
263 | #endif // _StdPrs_Isolines_H__ |