1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
22 // SMESH SMDS : implementaion of Salome mesh data structure
25 #pragma warning(disable:4786)
28 #include "SMDS_MeshNode.hxx"
29 #include "SMDS_SpacePosition.hxx"
30 #include "SMDS_IteratorOfElements.hxx"
34 //=======================================================================
35 //function : SMDS_MeshNode
37 //=======================================================================
39 SMDS_MeshNode::SMDS_MeshNode(double x, double y, double z):
40 myX(x), myY(y), myZ(z),
41 myPosition(SMDS_SpacePosition::originSpacePosition())
45 //=======================================================================
46 //function : RemoveInverseElement
48 //=======================================================================
50 void SMDS_MeshNode::RemoveInverseElement(const SMDS_MeshElement * parent)
52 NCollection_List<const SMDS_MeshElement*>::Iterator it(myInverseElements);
54 const SMDS_MeshElement* elem = it.Value();
56 myInverseElements.Remove(it);
62 //=======================================================================
65 //=======================================================================
67 void SMDS_MeshNode::Print(ostream & OS) const
69 OS << "Node <" << GetID() << "> : X = " << myX << " Y = "
70 << myY << " Z = " << myZ << endl;
73 //=======================================================================
74 //function : SetPosition
76 //=======================================================================
78 void SMDS_MeshNode::SetPosition(const SMDS_PositionPtr& aPos)
83 //=======================================================================
84 //function : GetPosition
86 //=======================================================================
88 const SMDS_PositionPtr& SMDS_MeshNode::GetPosition() const
93 //=======================================================================
95 * \brief Iterator on list of elements
97 //=======================================================================
99 class SMDS_MeshNode_MyInvIterator:public SMDS_ElemIterator
101 NCollection_List<const SMDS_MeshElement*>::Iterator myIterator;
102 SMDSAbs_ElementType myType;
104 SMDS_MeshNode_MyInvIterator(const NCollection_List<const SMDS_MeshElement*>& s,
105 SMDSAbs_ElementType type):
106 myIterator(s), myType(type)
111 if ( myType != SMDSAbs_All ) {
112 while ( myIterator.More() && myIterator.Value()->GetType() != myType)
115 return myIterator.More() != Standard_False;
118 const SMDS_MeshElement* next()
120 if ( !more() ) return 0;
121 const SMDS_MeshElement* current=myIterator.Value();
127 SMDS_ElemIteratorPtr SMDS_MeshNode::
128 GetInverseElementIterator(SMDSAbs_ElementType type) const
130 return SMDS_ElemIteratorPtr(new SMDS_MeshNode_MyInvIterator(myInverseElements,type));
133 // Same as GetInverseElementIterator but the create iterator only return
134 // wanted type elements.
135 class SMDS_MeshNode_MyIterator:public SMDS_ElemIterator
137 NCollection_List<const SMDS_MeshElement*> mySet;
138 NCollection_List<const SMDS_MeshElement*>::Iterator myIterator;
140 SMDS_MeshNode_MyIterator(SMDSAbs_ElementType type,
141 const NCollection_List<const SMDS_MeshElement*>& s)
143 const SMDS_MeshElement * e;
145 NCollection_List<const SMDS_MeshElement*>::Iterator it(s);
146 for(; it.More(); it.Next())
151 case SMDSAbs_Edge: toInsert=true; break;
152 case SMDSAbs_Face: toInsert=(e->GetType()!=SMDSAbs_Edge); break;
153 case SMDSAbs_Volume: toInsert=(e->GetType()==SMDSAbs_Volume); break;
155 if(toInsert) mySet.Append(e);
157 myIterator.Init(mySet);
162 return myIterator.More() != Standard_False;
165 const SMDS_MeshElement* next()
167 const SMDS_MeshElement* current=myIterator.Value();
173 SMDS_ElemIteratorPtr SMDS_MeshNode::
174 elementsIterator(SMDSAbs_ElementType type) const
176 if(type==SMDSAbs_Node)
177 return SMDS_MeshElement::elementsIterator(SMDSAbs_Node);
179 return SMDS_ElemIteratorPtr
180 (new SMDS_IteratorOfElements
182 SMDS_ElemIteratorPtr(new SMDS_MeshNode_MyIterator(type, myInverseElements))));
185 int SMDS_MeshNode::NbNodes() const
190 double SMDS_MeshNode::X() const
195 double SMDS_MeshNode::Y() const
200 double SMDS_MeshNode::Z() const
205 void SMDS_MeshNode::setXYZ(double x, double y, double z)
212 SMDSAbs_ElementType SMDS_MeshNode::GetType() const
217 //=======================================================================
218 //function : AddInverseElement
220 //=======================================================================
221 void SMDS_MeshNode::AddInverseElement(const SMDS_MeshElement* ME)
223 NCollection_List<const SMDS_MeshElement*>::Iterator it(myInverseElements);
224 for (; it.More(); it.Next()) {
225 const SMDS_MeshElement* elem = it.Value();
229 myInverseElements.Append(ME);
232 //=======================================================================
233 //function : ClearInverseElements
235 //=======================================================================
236 void SMDS_MeshNode::ClearInverseElements()
238 myInverseElements.Clear();
241 bool SMDS_MeshNode::emptyInverseElements()
243 return myInverseElements.IsEmpty() != Standard_False;
246 //================================================================================
248 * \brief Count inverse elements of given type
250 //================================================================================
252 int SMDS_MeshNode::NbInverseElements(SMDSAbs_ElementType type) const
254 if ( type == SMDSAbs_All )
255 return myInverseElements.Extent();
257 NCollection_List<const SMDS_MeshElement*>::Iterator it( myInverseElements );
258 for ( ; it.More(); it.Next() )
259 if ( it.Value()->GetType() == type )
264 ///////////////////////////////////////////////////////////////////////////////
265 /// To be used with STL set
266 ///////////////////////////////////////////////////////////////////////////////
267 bool operator<(const SMDS_MeshNode& e1, const SMDS_MeshNode& e2)
269 return e1.GetID()<e2.GetID();
270 /*if(e1.myX<e2.myX) return true;
271 else if(e1.myX==e2.myX)
273 if(e1.myY<e2.myY) return true;
274 else if(e1.myY==e2.myY) return (e1.myZ<e2.myZ);