1 // Created on: 1996-02-21
2 // Created by: Laurent PAINNOT
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _Poly_PolygonOnTriangulation_HeaderFile
18 #define _Poly_PolygonOnTriangulation_HeaderFile
20 #include <Standard_NullObject.hxx>
21 #include <Standard_Type.hxx>
22 #include <Standard_Transient.hxx>
23 #include <TColStd_Array1OfInteger.hxx>
24 #include <TColStd_HArray1OfReal.hxx>
26 DEFINE_STANDARD_HANDLE(Poly_PolygonOnTriangulation, Standard_Transient)
28 //! This class provides a polygon in 3D space, based on the triangulation
29 //! of a surface. It may be the approximate representation of a
30 //! curve on the surface, or more generally the shape.
31 //! A PolygonOnTriangulation is defined by a table of
32 //! nodes. Each node is an index in the table of nodes specific
33 //! to a triangulation, and represents a point on the surface. If
34 //! the polygon is closed, the index of the point of closure is
35 //! repeated at the end of the table of nodes.
36 //! If the polygon is an approximate representation of a curve
37 //! on a surface, you can associate with each of its nodes the
38 //! value of the parameter of the corresponding point on the
39 //! curve.represents a 3d Polygon
40 class Poly_PolygonOnTriangulation : public Standard_Transient
42 DEFINE_STANDARD_RTTIEXT(Poly_PolygonOnTriangulation, Standard_Transient)
45 //! Constructs a 3D polygon on the triangulation of a shape with specified size of nodes.
46 Standard_EXPORT Poly_PolygonOnTriangulation (const Standard_Integer theNbNodes,
47 const Standard_Boolean theHasParams);
49 //! Constructs a 3D polygon on the triangulation of a shape,
50 //! defined by the table of nodes, <Nodes>.
51 Standard_EXPORT Poly_PolygonOnTriangulation(const TColStd_Array1OfInteger& Nodes);
53 //! Constructs a 3D polygon on the triangulation of a shape, defined by:
54 //! - the table of nodes, Nodes, and the table of parameters, <Parameters>.
56 //! - a node value is an index in the table of nodes specific
57 //! to an existing triangulation of a shape
58 //! - and a parameter value is the value of the parameter of
59 //! the corresponding point on the curve approximated by
60 //! the constructed polygon.
62 //! The tables Nodes and Parameters must be the same size.
63 //! This property is not checked at construction time.
64 Standard_EXPORT Poly_PolygonOnTriangulation(const TColStd_Array1OfInteger& Nodes, const TColStd_Array1OfReal& Parameters);
66 //! Creates a copy of current polygon
67 Standard_EXPORT virtual Handle(Poly_PolygonOnTriangulation) Copy() const;
69 //! Returns the deflection of this polygon
70 Standard_Real Deflection() const { return myDeflection; }
72 //! Sets the deflection of this polygon.
73 //! See more on deflection in Poly_Polygones2D.
74 void Deflection (const Standard_Real theDefl) { myDeflection = theDefl; }
76 //! Returns the number of nodes for this polygon.
77 //! Note: If the polygon is closed, the point of closure is
78 //! repeated at the end of its table of nodes. Thus, on a closed
79 //! triangle, the function NbNodes returns 4.
80 Standard_Integer NbNodes() const { return myNodes.Length(); }
82 //! Returns node at the given index.
83 Standard_Integer Node (Standard_Integer theIndex) const { return myNodes.Value (theIndex); }
85 //! Sets node at the given index.
86 void SetNode (Standard_Integer theIndex,
87 Standard_Integer theNode)
89 myNodes.SetValue (theIndex, theNode);
92 //! Returns true if parameters are associated with the nodes in this polygon.
93 Standard_Boolean HasParameters() const { return !myParameters.IsNull(); }
95 //! Returns parameter at the given index.
96 Standard_Real Parameter (Standard_Integer theIndex) const
98 Standard_NullObject_Raise_if (myParameters.IsNull(), "Poly_PolygonOnTriangulation::Parameter : parameters is NULL");
99 return myParameters->Value (theIndex);
102 //! Sets parameter at the given index.
103 void SetParameter (Standard_Integer theIndex,
104 Standard_Real theValue)
106 Standard_NullObject_Raise_if (myParameters.IsNull(), "Poly_PolygonOnTriangulation::Parameter : parameters is NULL");
107 myParameters->SetValue (theIndex, theValue);
110 //! Sets the table of the parameters associated with each node in this polygon.
111 //! Raises exception if array size doesn't much number of polygon nodes.
112 Standard_EXPORT void SetParameters (const Handle(TColStd_HArray1OfReal)& theParameters);
114 //! Dumps the content of me into the stream
115 Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
119 //! Returns the table of nodes for this polygon.
120 //! A node value is an index in the table of nodes specific to an existing triangulation of a shape.
121 const TColStd_Array1OfInteger& Nodes() const { return myNodes; }
123 //! Returns the table of the parameters associated with each node in this polygon.
124 //! Warning! Use the function HasParameters to check if parameters are associated with the nodes in this polygon.
125 const Handle(TColStd_HArray1OfReal)& Parameters() const { return myParameters; }
127 Standard_DEPRECATED("Deprecated method, SetNode() should be used instead")
128 TColStd_Array1OfInteger& ChangeNodes() { return myNodes; }
130 Standard_DEPRECATED("Deprecated method, SetParameter() should be used instead")
131 TColStd_Array1OfReal& ChangeParameters() { return myParameters->ChangeArray1(); }
135 Standard_Real myDeflection;
136 TColStd_Array1OfInteger myNodes;
137 Handle(TColStd_HArray1OfReal) myParameters;
141 #endif // _Poly_PolygonOnTriangulation_HeaderFile