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 #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 class SMDS_MeshNode_MyInvIterator:public SMDS_ElemIterator
93 NCollection_List<const SMDS_MeshElement*>::Iterator myIterator;
95 SMDS_MeshNode_MyInvIterator(const NCollection_List<const SMDS_MeshElement*>& s):
101 return myIterator.More() != Standard_False;
104 const SMDS_MeshElement* next()
106 const SMDS_MeshElement* current=myIterator.Value();
112 SMDS_ElemIteratorPtr SMDS_MeshNode::
113 GetInverseElementIterator() const
115 return SMDS_ElemIteratorPtr(new SMDS_MeshNode_MyInvIterator(myInverseElements));
118 // Same as GetInverseElementIterator but the create iterator only return
119 // wanted type elements.
120 class SMDS_MeshNode_MyIterator:public SMDS_ElemIterator
122 NCollection_List<const SMDS_MeshElement*> mySet;
123 NCollection_List<const SMDS_MeshElement*>::Iterator myIterator;
125 SMDS_MeshNode_MyIterator(SMDSAbs_ElementType type,
126 const NCollection_List<const SMDS_MeshElement*>& s)
128 const SMDS_MeshElement * e;
130 NCollection_List<const SMDS_MeshElement*>::Iterator it(s);
131 for(; it.More(); it.Next())
136 case SMDSAbs_Edge: toInsert=true; break;
137 case SMDSAbs_Face: toInsert=(e->GetType()!=SMDSAbs_Edge); break;
138 case SMDSAbs_Volume: toInsert=(e->GetType()==SMDSAbs_Volume); break;
140 if(toInsert) mySet.Append(e);
142 myIterator.Init(mySet);
147 return myIterator.More() != Standard_False;
150 const SMDS_MeshElement* next()
152 const SMDS_MeshElement* current=myIterator.Value();
158 SMDS_ElemIteratorPtr SMDS_MeshNode::
159 elementsIterator(SMDSAbs_ElementType type) const
161 if(type==SMDSAbs_Node)
162 return SMDS_MeshElement::elementsIterator(SMDSAbs_Node);
164 return SMDS_ElemIteratorPtr
165 (new SMDS_IteratorOfElements
167 SMDS_ElemIteratorPtr(new SMDS_MeshNode_MyIterator(type, myInverseElements))));
170 int SMDS_MeshNode::NbNodes() const
175 double SMDS_MeshNode::X() const
180 double SMDS_MeshNode::Y() const
185 double SMDS_MeshNode::Z() const
190 void SMDS_MeshNode::setXYZ(double x, double y, double z)
197 SMDSAbs_ElementType SMDS_MeshNode::GetType() const
202 //=======================================================================
203 //function : AddInverseElement
205 //=======================================================================
206 void SMDS_MeshNode::AddInverseElement(const SMDS_MeshElement* ME)
208 NCollection_List<const SMDS_MeshElement*>::Iterator it(myInverseElements);
209 for (; it.More(); it.Next()) {
210 const SMDS_MeshElement* elem = it.Value();
214 myInverseElements.Append(ME);
217 //=======================================================================
218 //function : ClearInverseElements
220 //=======================================================================
221 void SMDS_MeshNode::ClearInverseElements()
223 myInverseElements.Clear();
226 bool SMDS_MeshNode::emptyInverseElements()
228 return myInverseElements.IsEmpty() != Standard_False;
231 ///////////////////////////////////////////////////////////////////////////////
232 /// To be used with STL set
233 ///////////////////////////////////////////////////////////////////////////////
234 bool operator<(const SMDS_MeshNode& e1, const SMDS_MeshNode& e2)
236 return e1.GetID()<e2.GetID();
237 /*if(e1.myX<e2.myX) return true;
238 else if(e1.myX==e2.myX)
240 if(e1.myY<e2.myY) return true;
241 else if(e1.myY==e2.myY) return (e1.myZ<e2.myZ);