1 // Copyright (C) 2007-2010 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
23 // SMESH SMDS : implementaion of Salome mesh data structure
26 #pragma warning(disable:4786)
29 #include "SMDS_MeshNode.hxx"
30 #include "SMDS_SpacePosition.hxx"
31 #include "SMDS_IteratorOfElements.hxx"
35 //=======================================================================
36 //function : SMDS_MeshNode
38 //=======================================================================
40 SMDS_MeshNode::SMDS_MeshNode(double x, double y, double z):
41 myX(x), myY(y), myZ(z),
42 myPosition(SMDS_SpacePosition::originSpacePosition())
46 //=======================================================================
47 //function : RemoveInverseElement
49 //=======================================================================
51 void SMDS_MeshNode::RemoveInverseElement(const SMDS_MeshElement * parent)
53 NCollection_List<const SMDS_MeshElement*>::Iterator it(myInverseElements);
55 const SMDS_MeshElement* elem = it.Value();
57 myInverseElements.Remove(it);
63 //=======================================================================
66 //=======================================================================
68 void SMDS_MeshNode::Print(ostream & OS) const
70 OS << "Node <" << GetID() << "> : X = " << myX << " Y = "
71 << myY << " Z = " << myZ << endl;
74 //=======================================================================
75 //function : SetPosition
77 //=======================================================================
79 void SMDS_MeshNode::SetPosition(const SMDS_PositionPtr& aPos)
84 //=======================================================================
85 //function : GetPosition
87 //=======================================================================
89 const SMDS_PositionPtr& SMDS_MeshNode::GetPosition() const
94 //=======================================================================
96 * \brief Iterator on list of elements
98 //=======================================================================
100 class SMDS_MeshNode_MyInvIterator:public SMDS_ElemIterator
102 NCollection_List<const SMDS_MeshElement*>::Iterator myIterator;
103 SMDSAbs_ElementType myType;
105 SMDS_MeshNode_MyInvIterator(const NCollection_List<const SMDS_MeshElement*>& s,
106 SMDSAbs_ElementType type):
107 myIterator(s), myType(type)
112 if ( myType != SMDSAbs_All ) {
113 while ( myIterator.More() && myIterator.Value()->GetType() != myType)
116 return myIterator.More() != Standard_False;
119 const SMDS_MeshElement* next()
121 if ( !more() ) return 0;
122 const SMDS_MeshElement* current=myIterator.Value();
128 SMDS_ElemIteratorPtr SMDS_MeshNode::
129 GetInverseElementIterator(SMDSAbs_ElementType type) const
131 return SMDS_ElemIteratorPtr(new SMDS_MeshNode_MyInvIterator(myInverseElements,type));
134 // Same as GetInverseElementIterator but the create iterator only return
135 // wanted type elements.
136 class SMDS_MeshNode_MyIterator:public SMDS_ElemIterator
138 NCollection_List<const SMDS_MeshElement*> mySet;
139 NCollection_List<const SMDS_MeshElement*>::Iterator myIterator;
141 SMDS_MeshNode_MyIterator(SMDSAbs_ElementType type,
142 const NCollection_List<const SMDS_MeshElement*>& s)
144 const SMDS_MeshElement * e;
146 NCollection_List<const SMDS_MeshElement*>::Iterator it(s);
147 for(; it.More(); it.Next())
152 case SMDSAbs_Edge: toInsert=true; break;
153 case SMDSAbs_Face: toInsert=(e->GetType()!=SMDSAbs_Edge); break;
154 case SMDSAbs_Volume: toInsert=(e->GetType()==SMDSAbs_Volume); break;
156 if(toInsert) mySet.Append(e);
158 myIterator.Init(mySet);
163 return myIterator.More() != Standard_False;
166 const SMDS_MeshElement* next()
168 const SMDS_MeshElement* current=myIterator.Value();
174 SMDS_ElemIteratorPtr SMDS_MeshNode::
175 elementsIterator(SMDSAbs_ElementType type) const
177 if(type==SMDSAbs_Node)
178 return SMDS_MeshElement::elementsIterator(SMDSAbs_Node);
180 return SMDS_ElemIteratorPtr
181 (new SMDS_IteratorOfElements
183 SMDS_ElemIteratorPtr(new SMDS_MeshNode_MyIterator(type, myInverseElements))));
186 int SMDS_MeshNode::NbNodes() const
191 double SMDS_MeshNode::X() const
196 double SMDS_MeshNode::Y() const
201 double SMDS_MeshNode::Z() const
206 void SMDS_MeshNode::setXYZ(double x, double y, double z)
213 SMDSAbs_ElementType SMDS_MeshNode::GetType() const
218 //=======================================================================
219 //function : AddInverseElement
221 //=======================================================================
222 void SMDS_MeshNode::AddInverseElement(const SMDS_MeshElement* ME)
224 NCollection_List<const SMDS_MeshElement*>::Iterator it(myInverseElements);
225 for (; it.More(); it.Next()) {
226 const SMDS_MeshElement* elem = it.Value();
230 myInverseElements.Append(ME);
233 //=======================================================================
234 //function : ClearInverseElements
236 //=======================================================================
237 void SMDS_MeshNode::ClearInverseElements()
239 myInverseElements.Clear();
242 bool SMDS_MeshNode::emptyInverseElements()
244 return myInverseElements.IsEmpty() != Standard_False;
247 //================================================================================
249 * \brief Count inverse elements of given type
251 //================================================================================
253 int SMDS_MeshNode::NbInverseElements(SMDSAbs_ElementType type) const
255 if ( type == SMDSAbs_All )
256 return myInverseElements.Extent();
258 NCollection_List<const SMDS_MeshElement*>::Iterator it( myInverseElements );
259 for ( ; it.More(); it.Next() )
260 if ( it.Value()->GetType() == type )
265 ///////////////////////////////////////////////////////////////////////////////
266 /// To be used with STL set
267 ///////////////////////////////////////////////////////////////////////////////
268 bool operator<(const SMDS_MeshNode& e1, const SMDS_MeshNode& e2)
270 return e1.GetID()<e2.GetID();
271 /*if(e1.myX<e2.myX) return true;
272 else if(e1.myX==e2.myX)
274 if(e1.myY<e2.myY) return true;
275 else if(e1.myY==e2.myY) return (e1.myZ<e2.myZ);