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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
23 #include "SMDS_MeshNode.hxx"
24 #include "SMDS_SpacePosition.hxx"
25 #include "SMDS_IteratorOfElements.hxx"
29 //=======================================================================
30 //function : SMDS_MeshNode
32 //=======================================================================
34 SMDS_MeshNode::SMDS_MeshNode(double x, double y, double z):
35 myX(x), myY(y), myZ(z),
36 myPosition(SMDS_SpacePosition::originSpacePosition())
40 //=======================================================================
41 //function : RemoveInverseElement
43 //=======================================================================
45 void SMDS_MeshNode::RemoveInverseElement(const SMDS_MeshElement * parent)
47 myInverseElements.erase(parent);
50 //=======================================================================
53 //=======================================================================
55 void SMDS_MeshNode::Print(ostream & OS) const
57 OS << "Node <" << GetID() << "> : X = " << myX << " Y = "
58 << myY << " Z = " << myZ << endl;
61 //=======================================================================
62 //function : SetPosition
64 //=======================================================================
66 void SMDS_MeshNode::SetPosition(const SMDS_PositionPtr& aPos)
71 //=======================================================================
72 //function : GetPosition
74 //=======================================================================
76 const SMDS_PositionPtr& SMDS_MeshNode::GetPosition() const
81 class SMDS_MeshNode_MyInvIterator:public SMDS_ElemIterator
83 const set<const SMDS_MeshElement*>& mySet;
84 set<const SMDS_MeshElement*>::iterator myIterator;
86 SMDS_MeshNode_MyInvIterator(const set<const SMDS_MeshElement*>& s):
89 myIterator=mySet.begin();
94 return myIterator!=mySet.end();
97 const SMDS_MeshElement* next()
99 const SMDS_MeshElement* current=*myIterator;
105 SMDS_ElemIteratorPtr SMDS_MeshNode::
106 GetInverseElementIterator() const
108 return SMDS_ElemIteratorPtr(new SMDS_MeshNode_MyInvIterator(myInverseElements));
111 // Same as GetInverseElementIterator but the create iterator only return
112 // wanted type elements.
113 class SMDS_MeshNode_MyIterator:public SMDS_ElemIterator
115 set<const SMDS_MeshElement*> mySet;
116 set<const SMDS_MeshElement*>::iterator myIterator;
118 SMDS_MeshNode_MyIterator(SMDSAbs_ElementType type,
119 const set<const SMDS_MeshElement*>& s)
121 const SMDS_MeshElement * e;
123 set<const SMDS_MeshElement*>::iterator it=s.begin();
129 case SMDSAbs_Edge: toInsert=true; break;
130 case SMDSAbs_Face: toInsert=(e->GetType()!=SMDSAbs_Edge); break;
131 case SMDSAbs_Volume: toInsert=(e->GetType()==SMDSAbs_Volume); break;
133 if(toInsert) mySet.insert(e);
136 myIterator=mySet.begin();
141 return myIterator!=mySet.end();
144 const SMDS_MeshElement* next()
146 const SMDS_MeshElement* current=*myIterator;
152 SMDS_ElemIteratorPtr SMDS_MeshNode::
153 elementsIterator(SMDSAbs_ElementType type) const
155 if(type==SMDSAbs_Node)
156 return SMDS_MeshElement::elementsIterator(SMDSAbs_Node);
158 return SMDS_ElemIteratorPtr
159 (new SMDS_IteratorOfElements
161 SMDS_ElemIteratorPtr(new SMDS_MeshNode_MyIterator(type, myInverseElements))));
164 int SMDS_MeshNode::NbNodes() const
169 double SMDS_MeshNode::X() const
174 double SMDS_MeshNode::Y() const
179 double SMDS_MeshNode::Z() const
184 void SMDS_MeshNode::setXYZ(double x, double y, double z)
191 SMDSAbs_ElementType SMDS_MeshNode::GetType() const
196 //=======================================================================
197 //function : AddInverseElement
199 //=======================================================================
200 void SMDS_MeshNode::AddInverseElement(const SMDS_MeshElement* ME)
202 myInverseElements.insert(ME);
205 //=======================================================================
206 //function : ClearInverseElements
208 //=======================================================================
209 void SMDS_MeshNode::ClearInverseElements()
211 myInverseElements.clear();
214 bool SMDS_MeshNode::emptyInverseElements()
216 return myInverseElements.empty();
219 ///////////////////////////////////////////////////////////////////////////////
220 /// To be used with STL set
221 ///////////////////////////////////////////////////////////////////////////////
222 bool operator<(const SMDS_MeshNode& e1, const SMDS_MeshNode& e2)
224 return e1.GetID()<e2.GetID();
225 /*if(e1.myX<e2.myX) return true;
226 else if(e1.myX==e2.myX)
228 if(e1.myY<e2.myY) return true;
229 else if(e1.myY==e2.myY) return (e1.myZ<e2.myZ);