Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-18 09:21:49

0001 // Created on: 2014-10-14
0002 // Created by: Anton POLETAEV
0003 // Copyright (c) 2013-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _StdPrs_Isolines_H__
0017 #define _StdPrs_Isolines_H__
0018 
0019 #include <BRepAdaptor_Surface.hxx>
0020 #include <Geom_Surface.hxx>
0021 #include <gp_Lin2d.hxx>
0022 #include <Prs3d_LineAspect.hxx>
0023 #include <gp_Pnt.hxx>
0024 #include <NCollection_Sequence.hxx>
0025 #include <NCollection_HSequence.hxx>
0026 #include <NCollection_List.hxx>
0027 #include <StdPrs_DeflectionCurve.hxx>
0028 #include <StdPrs_ToolTriangulatedShape.hxx>
0029 
0030 class TopLoc_Location;
0031 
0032 //! Tool for computing isoline representation for a face or surface.
0033 //! Depending on a flags set to the given Prs3d_Drawer instance, on-surface (is used
0034 //! by default) or on-triangulation isoline builder algorithm will be used.
0035 //! If the given shape is not triangulated, on-surface isoline builder will be applied
0036 //! regardless of Prs3d_Drawer flags.
0037 class StdPrs_Isolines : public Prs3d_Root
0038 {
0039 public:
0040   //! Computes isolines presentation for a TopoDS face.
0041   //! This method chooses proper version of isoline builder algorithm : on triangulation
0042   //! or surface depending on the flag passed from Prs3d_Drawer attributes.
0043   //! This method is a default way to display isolines for a given TopoDS face.
0044   //! @param[in] thePresentation  the presentation.
0045   //! @param[in] theFace  the face.
0046   //! @param[in] theDrawer  the display settings.
0047   //! @param[in] theDeflection  the deflection for isolines-on-surface version.
0048   inline static void Add(const occ::handle<Prs3d_Presentation>& thePresentation,
0049                          const TopoDS_Face&                     theFace,
0050                          const occ::handle<Prs3d_Drawer>&       theDrawer,
0051                          const double                           theDeflection)
0052   {
0053     if (theDrawer->IsoOnTriangulation() && StdPrs_ToolTriangulatedShape::IsTriangulated(theFace))
0054     {
0055       AddOnTriangulation(thePresentation, theFace, theDrawer);
0056     }
0057     else
0058     {
0059       AddOnSurface(thePresentation, theFace, theDrawer, theDeflection);
0060     }
0061   }
0062 
0063   //! Computes isolines presentation for a TopoDS face.
0064   //! This method chooses proper version of isoline builder algorithm : on triangulation
0065   //! or surface depending on the flag passed from Prs3d_Drawer attributes.
0066   //! This method is a default way to display isolines for a given TopoDS face.
0067   //! @param[in] theFace  the face.
0068   //! @param[in] theDrawer  the display settings.
0069   //! @param[in] theDeflection  the deflection for isolines-on-surface version.
0070   static void Add(const TopoDS_Face&                                            theFace,
0071                   const occ::handle<Prs3d_Drawer>&                              theDrawer,
0072                   const double                                                  theDeflection,
0073                   NCollection_List<occ::handle<NCollection_HSequence<gp_Pnt>>>& theUPolylines,
0074                   NCollection_List<occ::handle<NCollection_HSequence<gp_Pnt>>>& theVPolylines)
0075   {
0076     if (theDrawer->IsoOnTriangulation() && StdPrs_ToolTriangulatedShape::IsTriangulated(theFace))
0077     {
0078       AddOnTriangulation(theFace, theDrawer, theUPolylines, theVPolylines);
0079     }
0080     else
0081     {
0082       AddOnSurface(theFace, theDrawer, theDeflection, theUPolylines, theVPolylines);
0083     }
0084   }
0085 
0086   //! Computes isolines on triangulation and adds them to a presentation.
0087   //! @param[in] thePresentation  the presentation.
0088   //! @param[in] theFace  the face.
0089   //! @param[in] theDrawer  the display settings.
0090   Standard_EXPORT static void AddOnTriangulation(
0091     const occ::handle<Prs3d_Presentation>& thePresentation,
0092     const TopoDS_Face&                     theFace,
0093     const occ::handle<Prs3d_Drawer>&       theDrawer);
0094 
0095   //! Computes isolines on triangulation.
0096   //! @param[in] theFace  the face.
0097   //! @param[in] theDrawer  the display settings.
0098   //! @param[out] theUPolylines  the sequence of result polylines
0099   //! @param[out] theVPolylines  the sequence of result polylines
0100   Standard_EXPORT static void AddOnTriangulation(
0101     const TopoDS_Face&                                            theFace,
0102     const occ::handle<Prs3d_Drawer>&                              theDrawer,
0103     NCollection_List<occ::handle<NCollection_HSequence<gp_Pnt>>>& theUPolylines,
0104     NCollection_List<occ::handle<NCollection_HSequence<gp_Pnt>>>& theVPolylines);
0105 
0106   //! Computes isolines on triangulation and adds them to a presentation.
0107   //! @param[in] thePresentation  the presentation.
0108   //! @param[in] theTriangulation  the triangulation.
0109   //! @param[in] theSurface  the definition of triangulated surface. The surface
0110   //!        adapter is used to precisely evaluate isoline points using surface
0111   //!        law and fit them on triangulation. If NULL is passed, the method will
0112   //!        use linear interpolation of triangle node's UV coordinates to evaluate
0113   //!        isoline points.
0114   //! @param[in] theLocation  the location transformation defined for triangulation (surface).
0115   //! @param[in] theDrawer  the display settings.
0116   //! @param[in] theUIsoParams  the parameters of u isolines to compute.
0117   //! @param[in] theVIsoParams  the parameters of v isolines to compute.
0118   Standard_EXPORT static void AddOnTriangulation(
0119     const occ::handle<Prs3d_Presentation>& thePresentation,
0120     const occ::handle<Poly_Triangulation>& theTriangulation,
0121     const occ::handle<Geom_Surface>&       theSurface,
0122     const TopLoc_Location&                 theLocation,
0123     const occ::handle<Prs3d_Drawer>&       theDrawer,
0124     const NCollection_Sequence<double>&    theUIsoParams,
0125     const NCollection_Sequence<double>&    theVIsoParams);
0126 
0127   //! Computes isolines on surface and adds them to presentation.
0128   //! @param[in] thePresentation  the presentation.
0129   //! @param[in] theFace  the face.
0130   //! @param[in] theDrawer  the display settings.
0131   //! @param[in] theDeflection  the deflection value.
0132   Standard_EXPORT static void AddOnSurface(const occ::handle<Prs3d_Presentation>& thePresentation,
0133                                            const TopoDS_Face&                     theFace,
0134                                            const occ::handle<Prs3d_Drawer>&       theDrawer,
0135                                            const double                           theDeflection);
0136 
0137   //! Computes isolines on surface and adds them to presentation.
0138   //! @param[in] theFace  the face
0139   //! @param[in] theDrawer  the display settings
0140   //! @param[in] theDeflection  the deflection value
0141   //! @param[out] theUPolylines  the sequence of result polylines
0142   //! @param[out] theVPolylines  the sequence of result polylines
0143   Standard_EXPORT static void AddOnSurface(
0144     const TopoDS_Face&                                            theFace,
0145     const occ::handle<Prs3d_Drawer>&                              theDrawer,
0146     const double                                                  theDeflection,
0147     NCollection_List<occ::handle<NCollection_HSequence<gp_Pnt>>>& theUPolylines,
0148     NCollection_List<occ::handle<NCollection_HSequence<gp_Pnt>>>& theVPolylines);
0149 
0150   //! Computes isolines on surface and adds them to presentation.
0151   //! @param[in] thePresentation  the presentation.
0152   //! @param[in] theSurface  the surface.
0153   //! @param[in] theDrawer  the display settings.
0154   //! @param[in] theDeflection  the deflection value.
0155   //! @param[in] theUIsoParams  the parameters of u isolines to compute.
0156   //! @param[in] theVIsoParams  the parameters of v isolines to compute.
0157   Standard_EXPORT static void AddOnSurface(const occ::handle<Prs3d_Presentation>&  thePresentation,
0158                                            const occ::handle<BRepAdaptor_Surface>& theSurface,
0159                                            const occ::handle<Prs3d_Drawer>&        theDrawer,
0160                                            const double                            theDeflection,
0161                                            const NCollection_Sequence<double>&     theUIsoParams,
0162                                            const NCollection_Sequence<double>&     theVIsoParams);
0163 
0164   //! Evaluate sequence of parameters for drawing uv isolines for a given face.
0165   //! @param[in] theFace  the face.
0166   //! @param[in] theNbIsoU  the number of u isolines.
0167   //! @param[in] theNbIsoV  the number of v isolines.
0168   //! @param[in] theUVLimit  the u, v parameter value limit.
0169   //! @param[out] theUIsoParams  the sequence of u isoline parameters.
0170   //! @param[out] theVIsoParams  the sequence of v isoline parameters.
0171   //! @param[out] theUmin  the lower U boundary of  theFace.
0172   //! @param[out] theUmax  the upper U boundary of  theFace.
0173   //! @param[out] theVmin  the lower V boundary of  theFace.
0174   //! @param[out] theVmax  the upper V boundary of  theFace.
0175   Standard_EXPORT static void UVIsoParameters(const TopoDS_Face&            theFace,
0176                                               const int                     theNbIsoU,
0177                                               const int                     theNbIsoV,
0178                                               const double                  theUVLimit,
0179                                               NCollection_Sequence<double>& theUIsoParams,
0180                                               NCollection_Sequence<double>& theVIsoParams,
0181                                               double&                       theUmin,
0182                                               double&                       theUmax,
0183                                               double&                       theVmin,
0184                                               double&                       theVmax);
0185 
0186 public:
0187   //! Auxiliary structure defining 3D point on isoline.
0188   struct PntOnIso
0189   {
0190     gp_Pnt Pnt;   //!< 3D point
0191     double Param; //!< parameter along the line (for sorting)
0192   };
0193 
0194   //! Auxiliary structure defining segment of isoline.
0195   struct SegOnIso
0196   {
0197 
0198     PntOnIso Pnts[2];
0199 
0200     operator PntOnIso*() { return Pnts; }
0201 
0202     operator const PntOnIso*() const { return Pnts; }
0203 
0204     bool operator<(const SegOnIso& theOther) const
0205     {
0206       return Pnts[1].Param < theOther.Pnts[0].Param;
0207     }
0208   };
0209 
0210 private:
0211   //! Computes isolines on surface.
0212   //! @param[in] theSurface  the surface
0213   //! @param[in] theDrawer  the display settings
0214   //! @param[in] theDeflection  the deflection value
0215   //! @param[in] theUIsoParams  the parameters of u isolines to compute
0216   //! @param[in] theVIsoParams  the parameters of v isolines to compute
0217   //! @param[out] theUPolylines  the sequence of result polylines
0218   //! @param[out] theVPolylines  the sequence of result polylines
0219   Standard_EXPORT static void addOnSurface(
0220     const occ::handle<BRepAdaptor_Surface>&                       theSurface,
0221     const occ::handle<Prs3d_Drawer>&                              theDrawer,
0222     const double                                                  theDeflection,
0223     const NCollection_Sequence<double>&                           theUIsoParams,
0224     const NCollection_Sequence<double>&                           theVIsoParams,
0225     NCollection_List<occ::handle<NCollection_HSequence<gp_Pnt>>>& theUPolylines,
0226     NCollection_List<occ::handle<NCollection_HSequence<gp_Pnt>>>& theVPolylines);
0227 
0228   //! Computes isolines on triangulation.
0229   //! @param[in] thePresentation  the presentation
0230   //! @param[in] theTriangulation  the triangulation
0231   //! @param[in] theSurface  the definition of triangulated surface. The surface
0232   //!        adapter is used to precisely evaluate isoline points using surface
0233   //!        law and fit them on triangulation. If NULL is passed, the method will
0234   //!        use linear interpolation of triangle node's UV coordinates to evaluate
0235   //!        isoline points
0236   //! @param[in] theLocation  the location transformation defined for triangulation (surface)
0237   //! @param[in] theDrawer  the display settings
0238   //! @param[in] theUIsoParams  the parameters of u isolines to compute
0239   //! @param[in] theVIsoParams  the parameters of v isolines to compute
0240   //! @param[out] theUPolylines  the sequence of result polylines
0241   //! @param[out] theVPolylines  the sequence of result polylines
0242   Standard_EXPORT static void addOnTriangulation(
0243     const occ::handle<Poly_Triangulation>&                        theTriangulation,
0244     const occ::handle<Geom_Surface>&                              theSurface,
0245     const TopLoc_Location&                                        theLocation,
0246     const NCollection_Sequence<double>&                           theUIsoParams,
0247     const NCollection_Sequence<double>&                           theVIsoParams,
0248     NCollection_List<occ::handle<NCollection_HSequence<gp_Pnt>>>& theUPolylines,
0249     NCollection_List<occ::handle<NCollection_HSequence<gp_Pnt>>>& theVPolylines);
0250 
0251   //! Find isoline segment on a triangle.
0252   //! @param[in] theSurface  the surface.
0253   //! @param[in] theIsU      when true than U isoline is specified, V isoline otherwise
0254   //! @param[in] theIsoline  the isoline in uv coordinates.
0255   //! @param[in] theNodesXYZ  the XYZ coordinates of triangle nodes.
0256   //! @param[in] theNodesUV  the UV coordinates of triangle nodes.
0257   //! @param[out] theSegment  the XYZ points of crossed triangle's links.
0258   //!                         with U cross point parameter for V isoline
0259   //!                         or V parameters for U isoline (depending on theIsU)
0260   //! @return TRUE if the isoline passes through the triangle.
0261   Standard_EXPORT static bool findSegmentOnTriangulation(
0262     const occ::handle<Geom_Surface>& theSurface,
0263     const bool                       theIsU,
0264     const gp_Lin2d&                  theIsoline,
0265     const gp_Pnt*                    theNodesXYZ,
0266     const gp_Pnt2d*                  theNodesUV,
0267     SegOnIso&                        theSegment);
0268 };
0269 
0270 #endif // _StdPrs_Isolines_H__