b311480e |
1 | // Created on: 2007-12-14 |
2 | // Created by: Alexander GRIGORIEV |
973c2be1 |
3 | // Copyright (c) 2007-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
16 | #include <Poly_CoherentNode.hxx> |
17 | #include <Poly_CoherentTriangle.hxx> |
18 | |
7fd59977 |
19 | //======================================================================= |
20 | //function : Clear |
21 | //purpose : |
22 | //======================================================================= |
23 | |
857ffd5e |
24 | void Poly_CoherentNode::Clear (const Handle(NCollection_BaseAllocator)& theAlloc) |
7fd59977 |
25 | { |
26 | Poly_CoherentTriPtr::RemoveList (myTriangles, theAlloc); |
27 | myUV[0] = Precision::Infinite(); |
28 | myUV[1] = Precision::Infinite(); |
29 | myNormal[0] = 0.f; |
30 | myNormal[1] = 0.f; |
31 | myNormal[2] = 0.f; |
32 | SetCoord(0., 0., 0.); |
33 | } |
34 | |
35 | //======================================================================= |
36 | //function : SetNormal |
37 | //purpose : Define the normal vector in the Node. |
38 | //======================================================================= |
39 | |
40 | void Poly_CoherentNode::SetNormal (const gp_XYZ& theVector) |
41 | { |
42 | myNormal[0] = static_cast<Standard_ShortReal>(theVector.X()); |
43 | myNormal[1] = static_cast<Standard_ShortReal>(theVector.Y()); |
44 | myNormal[2] = static_cast<Standard_ShortReal>(theVector.Z()); |
45 | } |
46 | |
47 | //======================================================================= |
48 | //function : AddTriangle |
49 | //purpose : |
50 | //======================================================================= |
51 | |
52 | void Poly_CoherentNode::AddTriangle |
53 | (const Poly_CoherentTriangle& theTri, |
857ffd5e |
54 | const Handle(NCollection_BaseAllocator)& theAlloc) |
7fd59977 |
55 | { |
56 | if (myTriangles == NULL) |
57 | myTriangles = new (theAlloc) Poly_CoherentTriPtr(theTri); |
58 | else |
59 | myTriangles->Prepend(&theTri, theAlloc); |
60 | } |
61 | |
62 | //======================================================================= |
63 | //function : RemoveTriangle |
64 | //purpose : |
65 | //======================================================================= |
66 | |
67 | Standard_Boolean Poly_CoherentNode::RemoveTriangle |
68 | (const Poly_CoherentTriangle& theTri, |
857ffd5e |
69 | const Handle(NCollection_BaseAllocator)& theAlloc) |
7fd59977 |
70 | { |
71 | Standard_Boolean aResult(Standard_False); |
72 | if (&myTriangles->GetTriangle() == &theTri) { |
73 | Poly_CoherentTriPtr * aLostPtr = myTriangles; |
74 | if (myTriangles == &myTriangles->Next()) |
75 | myTriangles = 0L; |
76 | else |
77 | myTriangles = &myTriangles->Next(); |
78 | Poly_CoherentTriPtr::Remove(aLostPtr, theAlloc); |
79 | aResult = Standard_True; |
80 | } else { |
81 | Poly_CoherentTriPtr::Iterator anIter(* myTriangles); |
82 | for (anIter.Next(); anIter.More(); anIter.Next()) |
83 | if (&anIter.Value() == &theTri) { |
84 | Poly_CoherentTriPtr::Remove |
85 | (const_cast<Poly_CoherentTriPtr *>(&anIter.PtrValue()), theAlloc); |
86 | aResult = Standard_True; |
87 | break; |
88 | } |
89 | } |
90 | return aResult; |
91 | } |
92 | |
93 | //======================================================================= |
94 | //function : Dump |
95 | //purpose : |
96 | //======================================================================= |
97 | |
98 | void Poly_CoherentNode::Dump(Standard_OStream& theStream) const |
99 | { |
100 | char buf[256]; |
91322f44 |
101 | Sprintf (buf, " X =%9.4f; Y =%9.4f; Z =%9.4f", X(), Y(), Z()); |
7fd59977 |
102 | theStream << buf << endl; |
103 | Poly_CoherentTriPtr::Iterator anIter(* myTriangles); |
104 | for (; anIter.More(); anIter.Next()) { |
105 | const Poly_CoherentTriangle& aTri = anIter.Value(); |
91322f44 |
106 | Sprintf (buf, " %5d %5d %5d", aTri.Node(0),aTri.Node(1),aTri.Node(2)); |
7fd59977 |
107 | theStream << buf << endl; |
108 | } |
109 | } |