0030907: Visualization Algorithms - failure on attempt to compute iso-lines for an...
[occt.git] / src / StdPrs / StdPrs_Isolines.hxx
CommitLineData
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
33class Poly_Triangle;
34class TopoDS_Face;
35class 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.
42class StdPrs_Isolines : public Prs3d_Root
43{
44public:
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
140 //! Computes isolines on surface and adds them to presentation.
1b9f5d95 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
152 //! Computes isolines on surface and adds them to presentation.
5ad8c033 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.
e774a553 173 //! @param theUmin [out] the lower U boundary of theFace.
174 //! @param theUmax [out] the upper U boundary of theFace.
175 //! @param theVmin [out] the lower V boundary of theFace.
176 //! @param theVmax [out] the upper V boundary of theFace.
5ad8c033 177 Standard_EXPORT static void UVIsoParameters (const TopoDS_Face& theFace,
178 const Standard_Integer theNbIsoU,
179 const Standard_Integer theNbIsoV,
180 const Standard_Real theUVLimit,
181 TColStd_SequenceOfReal& theUIsoParams,
e774a553 182 TColStd_SequenceOfReal& theVIsoParams,
183 Standard_Real& theUmin,
184 Standard_Real& theUmax,
185 Standard_Real& theVmin,
186 Standard_Real& theVmax);
5ad8c033 187
1b9f5d95 188public:
189
190 //! Auxiliary structure defining 3D point on isoline.
191 struct PntOnIso
192 {
193 gp_Pnt Pnt; //!< 3D point
194 double Param; //!< parameter along the line (for sorting)
195 };
196
197 //! Auxiliary structure defining segment of isoline.
198 struct SegOnIso
199 {
200
201 PntOnIso Pnts[2];
202
203 operator PntOnIso*() { return Pnts; }
204 operator const PntOnIso*() const { return Pnts; }
205
206 bool operator< (const SegOnIso& theOther) const
207 {
208 return Pnts[1].Param < theOther.Pnts[0].Param;
209 }
210
211 };
212
5ad8c033 213private:
214
1b9f5d95 215 //! Computes isolines on surface.
216 //! @param theSurface [in] the surface
217 //! @param theDrawer [in] the display settings
218 //! @param theDeflection [in] the deflection value
219 //! @param theUIsoParams [in] the parameters of u isolines to compute
220 //! @param theVIsoParams [in] the parameters of v isolines to compute
221 //! @param theUPolylines [out] the sequence of result polylines
222 //! @param theVPolylines [out] the sequence of result polylines
223 Standard_EXPORT static void addOnSurface (const Handle(BRepAdaptor_HSurface)& theSurface,
224 const Handle(Prs3d_Drawer)& theDrawer,
225 const Standard_Real theDeflection,
226 const TColStd_SequenceOfReal& theUIsoParams,
227 const TColStd_SequenceOfReal& theVIsoParams,
228 Prs3d_NListOfSequenceOfPnt& theUPolylines,
229 Prs3d_NListOfSequenceOfPnt& theVPolylines);
230
231 //! Computes isolines on triangulation.
232 //! @param thePresentation [in] the presentation
233 //! @param theTriangulation [in] the triangulation
234 //! @param theSurface [in] the definition of triangulated surface. The surface
235 //! adapter is used to precisely evaluate isoline points using surface
236 //! law and fit them on triangulation. If NULL is passed, the method will
237 //! use linear interpolation of triangle node's UV coordinates to evaluate
238 //! isoline points
239 //! @param theLocation [in] the location transformation defined for triangulation (surface)
240 //! @param theDrawer [in] the display settings
241 //! @param theUIsoParams [in] the parameters of u isolines to compute
242 //! @param theVIsoParams [in] the parameters of v isolines to compute
243 //! @param theUPolylines [out] the sequence of result polylines
244 //! @param theVPolylines [out] the sequence of result polylines
245 Standard_EXPORT static void addOnTriangulation (const Handle(Poly_Triangulation)& theTriangulation,
246 const Handle(Geom_Surface)& theSurface,
247 const TopLoc_Location& theLocation,
248 const TColStd_SequenceOfReal& theUIsoParams,
249 const TColStd_SequenceOfReal& theVIsoParams,
250 Prs3d_NListOfSequenceOfPnt& theUPolylines,
251 Prs3d_NListOfSequenceOfPnt& theVPolylines);
252
5ad8c033 253 //! Find isoline segment on a triangle.
254 //! @param theSurface [in] the surface.
1b9f5d95 255 //! @param theIsU [in] when true than U isoline is specified, V isoline otherwise
5ad8c033 256 //! @param theIsoline [in] the isoline in uv coordinates.
257 //! @param theNodesXYZ [in] the XYZ coordinates of triangle nodes.
258 //! @param theNodesUV [in] the UV coordinates of triangle nodes.
259 //! @param theSegment [out] the XYZ points of crossed triangle's links.
1b9f5d95 260 //! with U cross point parameter for V isoline
261 //! or V parameters for U isoline (depending on theIsU)
5ad8c033 262 //! @return TRUE if the isoline passes through the triangle.
263 Standard_EXPORT static Standard_Boolean findSegmentOnTriangulation (const Handle(Geom_Surface)& theSurface,
1b9f5d95 264 const bool theIsU,
5ad8c033 265 const gp_Lin2d& theIsoline,
266 const gp_Pnt* theNodesXYZ,
267 const gp_Pnt2d* theNodesUV,
1b9f5d95 268 SegOnIso& theSegment);
5ad8c033 269};
270
271#endif // _StdPrs_Isolines_H__