Salome HOME
23418: [OCC] Mesh: Minimization of memory usage of SMESH
[modules/smesh.git] / src / SMDS / SMDS_PolygonalFaceOfNodes.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SMESH SMDS : implementation of Salome mesh data structure
24 //
25 #ifdef _MSC_VER
26 #pragma warning(disable:4786)
27 #endif
28
29 #include "SMDS_PolygonalFaceOfNodes.hxx"
30
31 #include "SMDS_SetIterator.hxx"
32 #include "SMDS_Mesh.hxx"
33
34 #include <boost/make_shared.hpp>
35
36 #include <utilities.h>
37
38 //=======================================================================
39 //function : Constructor
40 //purpose  : 
41 //=======================================================================
42 SMDS_PolygonalFaceOfNodes::
43 SMDS_PolygonalFaceOfNodes (const std::vector<const SMDS_MeshNode *>& nodes)
44 {
45   myNodes = nodes;
46 }
47
48 //=======================================================================
49 //function : GetType
50 //purpose  : 
51 //=======================================================================
52 SMDSAbs_ElementType SMDS_PolygonalFaceOfNodes::GetType() const
53 {
54   return SMDSAbs_Face;
55 }
56
57 //=======================================================================
58 //function : ChangeNodes
59 //purpose  : 
60 //=======================================================================
61 // bool SMDS_PolygonalFaceOfNodes::ChangeNodes (std::vector<const SMDS_MeshNode *> nodes)
62 // {
63 //   if (nodes.size() < 3)
64 //     return false;
65
66 //   myNodes = nodes;
67
68 //   return true;
69 // }
70
71 //=======================================================================
72 //function : ChangeNodes
73 //purpose  : to support the same interface, as SMDS_FaceOfNodes
74 //=======================================================================
75 // bool SMDS_PolygonalFaceOfNodes::ChangeNodes (const SMDS_MeshNode* nodes[],
76 //                                              const int            nbNodes)
77 // {
78 //   if (nbNodes < 3)
79 //     return false;
80
81 //   myNodes.resize(nbNodes);
82 //   int i = 0;
83 //   for (; i < nbNodes; i++) {
84 //     myNodes[i] = nodes[i];
85 //   }
86
87 //   return true;
88 // }
89
90 //=======================================================================
91 //function : NbNodes
92 //purpose  : 
93 //=======================================================================
94 int SMDS_PolygonalFaceOfNodes::NbNodes() const
95 {
96   return myNodes.size();
97 }
98
99 //=======================================================================
100 //function : NbEdges
101 //purpose  : 
102 //=======================================================================
103 int SMDS_PolygonalFaceOfNodes::NbEdges() const
104 {
105   return NbNodes();
106 }
107
108 //=======================================================================
109 //function : NbFaces
110 //purpose  : 
111 //=======================================================================
112 int SMDS_PolygonalFaceOfNodes::NbFaces() const
113 {
114   return 1;
115 }
116
117 //=======================================================================
118 //function : Print
119 //purpose  : 
120 //=======================================================================
121 void SMDS_PolygonalFaceOfNodes::Print(ostream & OS) const
122 {
123   OS << "polygonal face <" << GetID() << " > : ";
124   int i, nbNodes = myNodes.size();
125   for (i = 0; i < nbNodes - 1; i++)
126     OS << myNodes[i] << ",";
127   OS << myNodes[i] << ") " << endl;
128 }
129
130 /// ===================================================================
131 /*!
132  * \brief Iterator on edges of face
133  */
134 /// ===================================================================
135
136 /*!
137  * \brief Return node by its index
138  * \param ind - node index
139  * \retval const SMDS_MeshNode* - the node
140  */
141 const SMDS_MeshNode* SMDS_PolygonalFaceOfNodes::GetNode(const int ind) const
142 {
143   return myNodes[ WrappedIndex( ind )];
144 }
145
146 SMDS_ElemIteratorPtr SMDS_PolygonalFaceOfNodes::nodesIterator() const
147 {
148   return boost::make_shared< SMDS_NodeArrayElemIterator >( &myNodes[0], &myNodes[0] + NbNodes() );
149 }
150
151 SMDS_NodeIteratorPtr SMDS_PolygonalFaceOfNodes::nodeIterator() const
152 {
153   return boost::make_shared< SMDS_NodeArrayIterator >( &myNodes[0], &myNodes[0] + NbNodes() );
154 }