1 // Copyright (c) 2013 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #ifndef _StdPrs_ToolTriangulatedShape_HeaderFile
15 #define _StdPrs_ToolTriangulatedShape_HeaderFile
17 #include <Poly_Connect.hxx>
18 #include <Poly_Triangulation.hxx>
19 #include <Prs3d_Drawer.hxx>
20 #include <Standard.hxx>
21 #include <Standard_Macro.hxx>
22 #include <TColgp_Array1OfDir.hxx>
27 class Poly_Triangulation;
29 class StdPrs_ToolTriangulatedShape
33 //! Similar to BRepTools::Triangulation() but without extra checks.
34 //! @return true if all faces within shape are triangulated.
35 Standard_EXPORT static Standard_Boolean IsTriangulated (const TopoDS_Shape& theShape);
37 //! Checks back faces visibility for specified shape (to activate back-face culling). <br>
38 //! @return true if shape is closed manifold Solid or compound of such Solids. <br>
39 Standard_EXPORT static Standard_Boolean IsClosed (const TopoDS_Shape& theShape);
41 //! Computes nodal normals for Poly_Triangulation structure using UV coordinates and surface.
42 //! Does nothing if triangulation already defines normals.
43 //! @param theFace [in] the face
44 //! @param theTris [in] the definition of a face triangulation
45 static void ComputeNormals (const TopoDS_Face& theFace,
46 const Handle(Poly_Triangulation)& theTris)
48 Poly_Connect aPolyConnect;
49 ComputeNormals (theFace, theTris, aPolyConnect);
52 //! Computes nodal normals for Poly_Triangulation structure using UV coordinates and surface.
53 //! Does nothing if triangulation already defines normals.
54 //! @param theFace [in] the face
55 //! @param theTris [in] the definition of a face triangulation
56 //! @param thePolyConnect [in,out] optional, initialized tool for exploring triangulation
57 Standard_EXPORT static void ComputeNormals (const TopoDS_Face& theFace,
58 const Handle(Poly_Triangulation)& theTris,
59 Poly_Connect& thePolyConnect);
61 //! Evaluate normals for a triangle of a face.
62 //! @param[in] theFace the face.
63 //! @param[in] thePolyConnect the definition of a face triangulation.
64 //! @param[out] theNormals the array of normals for each triangle.
65 Standard_EXPORT static void Normal (const TopoDS_Face& theFace,
66 Poly_Connect& thePolyConnect,
67 TColgp_Array1OfDir& theNormals);
69 //! Computes the absolute deflection value depending on the type of deflection in theDrawer:
71 //! <li><b>Aspect_TOD_RELATIVE</b>: the absolute deflection is computed using the relative
72 //! deviation coefficient from theDrawer and the shape's bounding box;</li>
73 //! <li><b>Aspect_TOD_ABSOLUTE</b>: the maximal chordial deviation from theDrawer is returned.</li>
75 //! In case of the type of deflection in theDrawer computed relative deflection for shape is stored as absolute deflection.
76 //! It is necessary to use it later on for sub-shapes.
77 //! This function should always be used to compute the deflection value for building
78 //! discrete representations of the shape (triangualtion, wireframe) to avoid incosistencies
79 //! between different representations of the shape and undesirable visual artifacts.
80 Standard_EXPORT static Standard_Real GetDeflection (const TopoDS_Shape& theShape,
81 const Handle(Prs3d_Drawer)& theDrawer);
83 //! Checks whether the shape is properly triangulated for a given display settings.
84 //! @param theShape [in] the shape.
85 //! @param theDrawer [in] the display settings.
86 Standard_EXPORT static Standard_Boolean IsTessellated (const TopoDS_Shape& theShape,
87 const Handle(Prs3d_Drawer)& theDrawer);
89 //! Validates triangulation within the shape and performs tessellation if necessary.
90 //! @param theShape [in] the shape.
91 //! @param theDrawer [in] the display settings.
92 //! @return true if tesselation was recomputed and false otherwise.
93 Standard_EXPORT static Standard_Boolean Tessellate (const TopoDS_Shape& theShape,
94 const Handle(Prs3d_Drawer)& theDrawer);
96 //! If presentation has own deviation coefficient and IsAutoTriangulation() is true,
97 //! function will compare actual coefficients with previous values and will clear triangulation on their change
98 //! (regardless actual tessellation quality).
99 //! Function is placed here for compatibility reasons - new code should avoid using IsAutoTriangulation().
100 //! @param theShape [in] the shape
101 //! @param theDrawer [in] the display settings
102 //! @param theToResetCoeff [in] updates coefficients in theDrawer to actual state to avoid redundant recomputations
103 Standard_EXPORT static void ClearOnOwnDeflectionChange (const TopoDS_Shape& theShape,
104 const Handle(Prs3d_Drawer)& theDrawer,
105 const Standard_Boolean theToResetCoeff);