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