0026007: Standard attribute for surface meshes in TDataStd
[occt.git] / src / TDataXtd / TDataXtd_Triangulation.hxx
1 // Created on: 2016-11-10
2 // Created by: Anton KOZULIN
3 // Copyright (c) 2016 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 _TDataXtd_Triangulation_HeaderFile
17 #define _TDataXtd_Triangulation_HeaderFile
18
19 #include <Standard.hxx>
20 #include <Standard_Type.hxx>
21
22 #include <Poly_Triangulation.hxx>
23 #include <TDF_Attribute.hxx>
24 #include <Standard_Boolean.hxx>
25 #include <Standard_Integer.hxx>
26 #include <Standard_OStream.hxx>
27 class Standard_GUID;
28 class TDF_Label;
29 class TDF_Attribute;
30 class TDF_RelocationTable;
31
32 class TDataXtd_Triangulation;
33 DEFINE_STANDARD_HANDLE(TDataXtd_Triangulation, TDF_Attribute)
34
35 //! An Ocaf attribute containing a mesh (Poly_Triangulation).
36 //! It duplicates all methods from Poly_Triangulation.
37 //! It is highly recommended to modify the mesh through the methods of this attribute,
38 //! but not directly via the underlying Poly_Triangulation object.
39 //! In this case Undo/Redo will work fine and robust.
40 class TDataXtd_Triangulation : public TDF_Attribute
41 {
42 public:
43
44   //! Static methods
45   //  ==============
46
47   //! Returns the ID of the triangulation attribute.
48   Standard_EXPORT static const Standard_GUID& GetID();
49   
50   //! Finds or creates a triangulation attribute.
51   Standard_EXPORT static Handle(TDataXtd_Triangulation) Set(const TDF_Label& theLabel);
52
53   //! Finds or creates a triangulation attribute.
54   //! Initializes the attribute by a Poly_Triangulation object.
55   Standard_EXPORT static Handle(TDataXtd_Triangulation) Set(const TDF_Label& theLabel, const Handle(Poly_Triangulation)& theTriangulation);
56
57   //! Object methods
58   //  ==============
59
60   //! A constructor.
61   //! Don't use it directly, 
62   //! use please the static method Set(),
63   //! which returns the attribute attached to a label.
64   Standard_EXPORT TDataXtd_Triangulation();
65
66   //! Sets the triangulation.
67   Standard_EXPORT void Set(const Handle(Poly_Triangulation)& theTriangulation);
68
69   //! Returns the underlying triangulation.
70   Standard_EXPORT const Handle(Poly_Triangulation)& Get() const;
71
72
73   //! Poly_Triangulation methods
74   //  =================
75
76   //! The methods are "covered" by this attribute to prevent direct modification of the mesh.
77   //! There is no performance problem to call Poly_Triangulation method through this attribute.
78   //! The most of the methods are considered as "inline" by the compiler in release mode.
79
80   //! Returns the deflection of this triangulation.
81   Standard_EXPORT Standard_Real Deflection() const;
82
83   //! Sets the deflection of this triangulation to theDeflection.
84   //! See more on deflection in Polygon2D
85   Standard_EXPORT void Deflection (const Standard_Real theDeflection);
86
87   //! Deallocates the UV nodes.
88   Standard_EXPORT void RemoveUVNodes();
89
90   //! @return the number of nodes for this triangulation.
91   Standard_EXPORT Standard_Integer NbNodes() const;
92
93   //! @return the number of triangles for this triangulation.
94   Standard_EXPORT Standard_Integer NbTriangles() const;
95
96   //! @return Standard_True if 2D nodes are associated with 3D nodes for this triangulation.
97   Standard_EXPORT Standard_Boolean HasUVNodes() const;
98
99   //! @return node at the given index.
100   //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes.
101   Standard_EXPORT const gp_Pnt& Node (const Standard_Integer theIndex) const;
102
103   //! The method differs from Poly_Triangulation!
104   //! Sets a node at the given index.
105   //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes.
106   Standard_EXPORT void SetNode (const Standard_Integer theIndex, const gp_Pnt& theNode);
107
108   //! @return UVNode at the given index.
109   //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes.
110   Standard_EXPORT const gp_Pnt2d& UVNode (const Standard_Integer theIndex) const;
111
112   //! The method differs from Poly_Triangulation!
113   //! Sets a UVNode at the given index.
114   //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes.
115   Standard_EXPORT void SetUVNode (const Standard_Integer theIndex, const gp_Pnt2d& theUVNode);
116
117   //! @return triangle at the given index.
118   //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbTriangles.
119   Standard_EXPORT const Poly_Triangle& Triangle (const Standard_Integer theIndex) const;
120
121   //! The method differs from Poly_Triangulation!
122   //! Sets a triangle at the given index.
123   //! Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbTriangles.
124   Standard_EXPORT void SetTriangle (const Standard_Integer theIndex, const Poly_Triangle& theTriangle);
125
126   //! Sets the table of node normals.
127   //! Raises exception if length of theNormals != 3 * NbNodes
128   Standard_EXPORT void SetNormals (const Handle(TShort_HArray1OfShortReal)& theNormals);
129
130   //! Changes normal at the given index.
131   //! Raises Standard_OutOfRange exception.
132   Standard_EXPORT void SetNormal (const Standard_Integer theIndex,
133                                   const gp_Dir&          theNormal);
134
135   //! Returns Standard_True if nodal normals are defined.
136   Standard_EXPORT Standard_Boolean HasNormals() const;
137
138   //! @return normal at the given index.
139   //! Raises Standard_OutOfRange exception.
140   Standard_EXPORT const gp_Dir Normal (const Standard_Integer theIndex) const;
141
142   //! Inherited attribute methods
143   //  ===========================
144
145   Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE;
146
147   Standard_EXPORT void Restore (const Handle(TDF_Attribute)& theAttribute) Standard_OVERRIDE;
148
149   Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
150
151   Standard_EXPORT void Paste (const Handle(TDF_Attribute)& Into, const Handle(TDF_RelocationTable)& RT) const Standard_OVERRIDE;
152
153   Standard_EXPORT virtual Standard_OStream& Dump (Standard_OStream& anOS) const Standard_OVERRIDE;
154
155   DEFINE_STANDARD_RTTI_INLINE(TDataXtd_Triangulation,TDF_Attribute)
156
157 private:
158
159   Handle(Poly_Triangulation) myTriangulation;
160 };
161
162 #endif // _TDataXtd_Triangulation_HeaderFile