0028470: Foundation Classes, NCollection_Array1 - add Resize() method for re-allocati...
[occt.git] / src / Poly / Poly_CoherentNode.cxx
1 // Created on: 2007-12-14
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2007-2014 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 #include <Poly_CoherentNode.hxx>
17 #include <Poly_CoherentTriangle.hxx>
18
19 #ifdef _MSC_VER
20 #pragma warning(disable:4996)
21 #endif
22
23 //=======================================================================
24 //function : Clear
25 //purpose  : 
26 //=======================================================================
27
28 void Poly_CoherentNode::Clear (const Handle(NCollection_BaseAllocator)& theAlloc)
29 {
30   Poly_CoherentTriPtr::RemoveList (myTriangles, theAlloc);
31   myUV[0] = Precision::Infinite();
32   myUV[1] = Precision::Infinite();
33   myNormal[0] = 0.f;
34   myNormal[1] = 0.f;
35   myNormal[2] = 0.f;
36   SetCoord(0., 0., 0.);
37 }
38
39 //=======================================================================
40 //function : SetNormal
41 //purpose  : Define the normal vector in the Node.
42 //=======================================================================
43
44 void Poly_CoherentNode::SetNormal (const gp_XYZ& theVector)
45 {
46   myNormal[0] = static_cast<Standard_ShortReal>(theVector.X());
47   myNormal[1] = static_cast<Standard_ShortReal>(theVector.Y());
48   myNormal[2] = static_cast<Standard_ShortReal>(theVector.Z());
49 }
50
51 //=======================================================================
52 //function : AddTriangle
53 //purpose  : 
54 //=======================================================================
55
56 void Poly_CoherentNode::AddTriangle
57                         (const Poly_CoherentTriangle&            theTri,
58                          const Handle(NCollection_BaseAllocator)& theAlloc)
59 {
60   if (myTriangles == NULL)
61     myTriangles = new (theAlloc) Poly_CoherentTriPtr(theTri);
62   else
63     myTriangles->Prepend(&theTri, theAlloc);
64 }
65
66 //=======================================================================
67 //function : RemoveTriangle
68 //purpose  : 
69 //=======================================================================
70
71 Standard_Boolean Poly_CoherentNode::RemoveTriangle
72                         (const Poly_CoherentTriangle&            theTri,
73                          const Handle(NCollection_BaseAllocator)& theAlloc)
74 {
75   Standard_Boolean aResult(Standard_False);
76   if (&myTriangles->GetTriangle() == &theTri) {
77     Poly_CoherentTriPtr * aLostPtr = myTriangles;
78     if (myTriangles == &myTriangles->Next())
79       myTriangles = 0L;
80     else
81       myTriangles = &myTriangles->Next();
82     Poly_CoherentTriPtr::Remove(aLostPtr, theAlloc);
83     aResult = Standard_True;
84   } else {
85     Poly_CoherentTriPtr::Iterator anIter(* myTriangles);
86     for (anIter.Next(); anIter.More(); anIter.Next())
87       if (&anIter.Value() == &theTri) {
88         Poly_CoherentTriPtr::Remove
89           (const_cast<Poly_CoherentTriPtr *>(&anIter.PtrValue()), theAlloc);
90         aResult = Standard_True;
91         break;
92       }
93   }
94   return aResult;
95 }
96
97 //=======================================================================
98 //function : Dump
99 //purpose  : 
100 //=======================================================================
101
102 void Poly_CoherentNode::Dump(Standard_OStream& theStream) const
103 {
104   char buf[256];
105   Sprintf (buf, "  X =%9.4f; Y =%9.4f; Z =%9.4f", X(), Y(), Z());
106   theStream << buf << endl;
107   Poly_CoherentTriPtr::Iterator anIter(* myTriangles);
108   for (; anIter.More(); anIter.Next()) {
109     const Poly_CoherentTriangle& aTri = anIter.Value();
110     Sprintf (buf, "      %5d %5d %5d", aTri.Node(0),aTri.Node(1),aTri.Node(2));
111     theStream << buf << endl;
112   }
113 }