1 // SMESH SMDS : implementaion of Salome mesh data structure
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #pragma warning(disable:4786)
26 #include "SMDS_MeshNode.hxx"
27 #include "SMDS_SpacePosition.hxx"
28 #include "SMDS_IteratorOfElements.hxx"
32 //=======================================================================
33 //function : SMDS_MeshNode
35 //=======================================================================
37 SMDS_MeshNode::SMDS_MeshNode(double x, double y, double z):
38 myX(x), myY(y), myZ(z),
39 myPosition(SMDS_SpacePosition::originSpacePosition())
43 //=======================================================================
44 //function : RemoveInverseElement
46 //=======================================================================
48 void SMDS_MeshNode::RemoveInverseElement(const SMDS_MeshElement * parent)
50 NCollection_List<const SMDS_MeshElement*>::Iterator it(myInverseElements);
52 const SMDS_MeshElement* elem = it.Value();
54 myInverseElements.Remove(it);
60 //=======================================================================
63 //=======================================================================
65 void SMDS_MeshNode::Print(ostream & OS) const
67 OS << "Node <" << GetID() << "> : X = " << myX << " Y = "
68 << myY << " Z = " << myZ << endl;
71 //=======================================================================
72 //function : SetPosition
74 //=======================================================================
76 void SMDS_MeshNode::SetPosition(const SMDS_PositionPtr& aPos)
81 //=======================================================================
82 //function : GetPosition
84 //=======================================================================
86 const SMDS_PositionPtr& SMDS_MeshNode::GetPosition() const
91 //=======================================================================
93 * \brief Iterator on list of elements
95 //=======================================================================
97 class SMDS_MeshNode_MyInvIterator:public SMDS_ElemIterator
99 NCollection_List<const SMDS_MeshElement*>::Iterator myIterator;
100 SMDSAbs_ElementType myType;
102 SMDS_MeshNode_MyInvIterator(const NCollection_List<const SMDS_MeshElement*>& s,
103 SMDSAbs_ElementType type):
104 myIterator(s), myType(type)
109 if ( myType != SMDSAbs_All ) {
110 while ( myIterator.More() && myIterator.Value()->GetType() != myType)
113 return myIterator.More() != Standard_False;
116 const SMDS_MeshElement* next()
118 const SMDS_MeshElement* current=myIterator.Value();
124 SMDS_ElemIteratorPtr SMDS_MeshNode::
125 GetInverseElementIterator(SMDSAbs_ElementType type) const
127 return SMDS_ElemIteratorPtr(new SMDS_MeshNode_MyInvIterator(myInverseElements,type));
130 // Same as GetInverseElementIterator but the create iterator only return
131 // wanted type elements.
132 class SMDS_MeshNode_MyIterator:public SMDS_ElemIterator
134 NCollection_List<const SMDS_MeshElement*> mySet;
135 NCollection_List<const SMDS_MeshElement*>::Iterator myIterator;
137 SMDS_MeshNode_MyIterator(SMDSAbs_ElementType type,
138 const NCollection_List<const SMDS_MeshElement*>& s)
140 const SMDS_MeshElement * e;
142 NCollection_List<const SMDS_MeshElement*>::Iterator it(s);
143 for(; it.More(); it.Next())
148 case SMDSAbs_Edge: toInsert=true; break;
149 case SMDSAbs_Face: toInsert=(e->GetType()!=SMDSAbs_Edge); break;
150 case SMDSAbs_Volume: toInsert=(e->GetType()==SMDSAbs_Volume); break;
152 if(toInsert) mySet.Append(e);
154 myIterator.Init(mySet);
159 return myIterator.More() != Standard_False;
162 const SMDS_MeshElement* next()
164 const SMDS_MeshElement* current=myIterator.Value();
170 SMDS_ElemIteratorPtr SMDS_MeshNode::
171 elementsIterator(SMDSAbs_ElementType type) const
173 if(type==SMDSAbs_Node)
174 return SMDS_MeshElement::elementsIterator(SMDSAbs_Node);
176 return SMDS_ElemIteratorPtr
177 (new SMDS_IteratorOfElements
179 SMDS_ElemIteratorPtr(new SMDS_MeshNode_MyIterator(type, myInverseElements))));
182 int SMDS_MeshNode::NbNodes() const
187 double SMDS_MeshNode::X() const
192 double SMDS_MeshNode::Y() const
197 double SMDS_MeshNode::Z() const
202 void SMDS_MeshNode::setXYZ(double x, double y, double z)
209 SMDSAbs_ElementType SMDS_MeshNode::GetType() const
214 //=======================================================================
215 //function : AddInverseElement
217 //=======================================================================
218 void SMDS_MeshNode::AddInverseElement(const SMDS_MeshElement* ME)
220 NCollection_List<const SMDS_MeshElement*>::Iterator it(myInverseElements);
221 for (; it.More(); it.Next()) {
222 const SMDS_MeshElement* elem = it.Value();
226 myInverseElements.Append(ME);
229 //=======================================================================
230 //function : ClearInverseElements
232 //=======================================================================
233 void SMDS_MeshNode::ClearInverseElements()
235 myInverseElements.Clear();
238 bool SMDS_MeshNode::emptyInverseElements()
240 return myInverseElements.IsEmpty() != Standard_False;
243 //================================================================================
245 * \brief Count inverse elements of given type
247 //================================================================================
249 int SMDS_MeshNode::NbInverseNodes(SMDSAbs_ElementType type) const
251 if ( type == SMDSAbs_All )
252 return myInverseElements.Extent();
254 NCollection_List<const SMDS_MeshElement*>::Iterator it( myInverseElements );
255 for ( ; it.More(); it.Next() )
256 if ( it.Value()->GetType() == type )
261 ///////////////////////////////////////////////////////////////////////////////
262 /// To be used with STL set
263 ///////////////////////////////////////////////////////////////////////////////
264 bool operator<(const SMDS_MeshNode& e1, const SMDS_MeshNode& e2)
266 return e1.GetID()<e2.GetID();
267 /*if(e1.myX<e2.myX) return true;
268 else if(e1.myX==e2.myX)
270 if(e1.myY<e2.myY) return true;
271 else if(e1.myY==e2.myY) return (e1.myZ<e2.myZ);