1 // Created on: 2016-11-10
2 // Created by: Anton KOZULIN
3 // Copyright (c) 2016 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <TDataXtd_Triangulation.hxx>
17 #include <Standard_GUID.hxx>
18 #include <Standard_Type.hxx>
19 #include <TDF_Attribute.hxx>
20 #include <TDF_Label.hxx>
21 #include <TDF_RelocationTable.hxx>
23 //=======================================================================
25 //purpose : Returns the ID of the triangulation attribute.
26 //=======================================================================
27 const Standard_GUID& TDataXtd_Triangulation::GetID()
29 static Standard_GUID TDataXtd_TriangulationID ("27AE2C44-60B0-41AE-AC18-BA3FDA538D03");
30 return TDataXtd_TriangulationID;
33 //=======================================================================
35 //purpose : Finds or creates a triangulation attribute.
36 //=======================================================================
37 Handle(TDataXtd_Triangulation) TDataXtd_Triangulation::Set(const TDF_Label& theLabel)
39 Handle(TDataXtd_Triangulation) A;
40 if (!theLabel.FindAttribute (TDataXtd_Triangulation::GetID(), A))
42 A = new TDataXtd_Triangulation;
43 theLabel.AddAttribute(A);
48 //=======================================================================
50 //purpose : Finds or creates a triangulation attribute.
51 // Initializes the attribute by a Poly_Triangulation object.
52 //=======================================================================
53 Handle(TDataXtd_Triangulation) TDataXtd_Triangulation::Set(const TDF_Label& theLabel, const Handle(Poly_Triangulation)& theMesh)
55 Handle(TDataXtd_Triangulation) M = TDataXtd_Triangulation::Set(theLabel);
60 //=======================================================================
61 //function : TDataXtd_Triangulation
62 //purpose : A constructor.
63 // Don't use it directly,
64 // use please the static method Set(),
65 // which returns the attribute attached to a label.
66 //=======================================================================
67 TDataXtd_Triangulation::TDataXtd_Triangulation()
72 //=======================================================================
73 //function : TDataXtd_Triangulation
74 //purpose : Sets the triangulation.
75 //=======================================================================
76 void TDataXtd_Triangulation::Set(const Handle(Poly_Triangulation)& theTriangulation)
79 myTriangulation = theTriangulation;
82 //=======================================================================
83 //function : TDataXtd_Triangulation
84 //purpose : Returns the underlying mesh.
85 //=======================================================================
86 const Handle(Poly_Triangulation)& TDataXtd_Triangulation::Get() const
88 return myTriangulation;
91 // Poly_Triangulation methods
93 // The methods are "covered" by this attribute to prevent direct modification of the mesh.
94 // There is no performance problem to call Poly_Triangulation method through this attribute.
95 // The most of the methods are considered as "inline" by the compiler in release mode.
97 //=======================================================================
98 //function : Deflection
99 //purpose : Returns the deflection of this triangulation.
100 //=======================================================================
101 Standard_Real TDataXtd_Triangulation::Deflection() const
103 return myTriangulation->Deflection();
106 //=======================================================================
107 //function : Deflection
108 //purpose : Sets the deflection of this triangulation to theDeflection.
109 // See more on deflection in Polygon2D
110 //=======================================================================
111 void TDataXtd_Triangulation::Deflection (const Standard_Real theDeflection)
114 myTriangulation->Deflection(theDeflection);
117 //=======================================================================
118 //function : RemoveUVNodes
119 //purpose : Deallocates the UV nodes.
120 //=======================================================================
121 void TDataXtd_Triangulation::RemoveUVNodes()
124 myTriangulation->RemoveUVNodes();
127 //=======================================================================
129 //purpose : return the number of nodes for this triangulation.
130 //=======================================================================
131 Standard_Integer TDataXtd_Triangulation::NbNodes() const
133 return myTriangulation->NbNodes();
136 //=======================================================================
137 //function : NbTriangles
138 //purpose : return the number of triangles for this triangulation.
139 //=======================================================================
140 Standard_Integer TDataXtd_Triangulation::NbTriangles() const
142 return myTriangulation->NbTriangles();
145 //=======================================================================
146 //function : HasUVNodes
147 //purpose : return Standard_True if 2D nodes are associated with 3D nodes for this triangulation.
148 //=======================================================================
149 Standard_Boolean TDataXtd_Triangulation::HasUVNodes() const
151 return myTriangulation->HasUVNodes();
154 //=======================================================================
156 //purpose : return node at the given index.
157 // Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes.
158 //=======================================================================
159 const gp_Pnt& TDataXtd_Triangulation::Node (const Standard_Integer theIndex) const
161 return myTriangulation->Node(theIndex);
164 //=======================================================================
166 //purpose : The method differs from Poly_Triangulation
167 // Sets a node at the given index.
168 // Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes.
169 //=======================================================================
170 void TDataXtd_Triangulation::SetNode (const Standard_Integer theIndex, const gp_Pnt& theNode)
173 myTriangulation->ChangeNode(theIndex) = theNode;
176 //=======================================================================
178 //purpose : return UVNode at the given index.
179 // Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes.
180 //=======================================================================
181 const gp_Pnt2d& TDataXtd_Triangulation::UVNode (const Standard_Integer theIndex) const
183 return myTriangulation->UVNode(theIndex);
186 //=======================================================================
187 //function : SetUVNode
188 //purpose : The method differs from Poly_Triangulation
189 // Sets a UVNode at the given index.
190 // Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbNodes.
191 //=======================================================================
192 void TDataXtd_Triangulation::SetUVNode (const Standard_Integer theIndex, const gp_Pnt2d& theUVNode)
195 myTriangulation->ChangeUVNode(theIndex) = theUVNode;
198 //=======================================================================
199 //function : Triangle
200 //purpose : return triangle at the given index.
201 // Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbTriangles.
202 //=======================================================================
203 const Poly_Triangle& TDataXtd_Triangulation::Triangle (const Standard_Integer theIndex) const
205 return myTriangulation->Triangle(theIndex);
208 //=======================================================================
209 //function : SetTriangle
210 //purpose : The method differs from Poly_Triangulation
211 // Sets a triangle at the given index.
212 // Raises Standard_OutOfRange exception if theIndex is less than 1 or greater than NbTriangles.
213 //=======================================================================
214 void TDataXtd_Triangulation::SetTriangle (const Standard_Integer theIndex, const Poly_Triangle& theTriangle)
217 myTriangulation->ChangeTriangle(theIndex) = theTriangle;
220 //=======================================================================
221 //function : SetNormals
222 //purpose : Sets the table of node normals.
223 // Raises exception if length of theNormals = 3 * NbNodes
224 //=======================================================================
225 void TDataXtd_Triangulation::SetNormals (const Handle(TShort_HArray1OfShortReal)& theNormals)
228 myTriangulation->SetNormals(theNormals);
231 //=======================================================================
232 //function : SetNormal
233 //purpose : Changes normal at the given index.
234 // Raises Standard_OutOfRange exception.
235 //=======================================================================
236 void TDataXtd_Triangulation::SetNormal (const Standard_Integer theIndex,
237 const gp_Dir& theNormal)
240 myTriangulation->SetNormal(theIndex, theNormal);
243 //=======================================================================
244 //function : HasNormals
245 //purpose : Returns Standard_True if nodal normals are defined.
246 //=======================================================================
247 Standard_Boolean TDataXtd_Triangulation::HasNormals() const
249 return myTriangulation->HasNormals();
252 //=======================================================================
254 //purpose : return normal at the given index.
255 // Raises Standard_OutOfRange exception.
256 //=======================================================================
257 const gp_Dir TDataXtd_Triangulation::Normal (const Standard_Integer theIndex) const
259 return myTriangulation->Normal(theIndex);
262 //=======================================================================
265 //=======================================================================
266 const Standard_GUID& TDataXtd_Triangulation::ID () const
271 //=======================================================================
272 //function : NewEmpty
274 //=======================================================================
275 Handle(TDF_Attribute) TDataXtd_Triangulation::NewEmpty () const
277 return new TDataXtd_Triangulation();
280 //=======================================================================
283 //=======================================================================
284 void TDataXtd_Triangulation::Restore(const Handle(TDF_Attribute)& theAttribute)
286 myTriangulation.Nullify();
287 Handle(TDataXtd_Triangulation) M = Handle(TDataXtd_Triangulation)::DownCast(theAttribute);
288 if (!M->myTriangulation.IsNull())
290 Handle(Poly_Triangulation) T = M->myTriangulation->Copy();
296 //=======================================================================
299 //=======================================================================
300 void TDataXtd_Triangulation::Paste (const Handle(TDF_Attribute)& theIntoAttribute,
301 const Handle(TDF_RelocationTable)& ) const
303 Handle(TDataXtd_Triangulation) M = Handle(TDataXtd_Triangulation)::DownCast(theIntoAttribute);
304 M->myTriangulation.Nullify();
305 if (!myTriangulation.IsNull())
307 Handle(Poly_Triangulation) T = myTriangulation->Copy();
309 M->myTriangulation = T;
313 //=======================================================================
316 //=======================================================================
317 Standard_OStream& TDataXtd_Triangulation::Dump (Standard_OStream& anOS) const
319 anOS << "Triangulation";
320 //TODO: Make a good dump.