-SMDS_Position *SMDS_MeshNode::GetPosition()
-{
- return myPosition;
-}
-
-const SMDS_Position *SMDS_MeshNode::GetPosition() const
-{
- return myPosition;
-}
-/**
-*/
-SMDS_Iterator<const SMDS_MeshElement*> * SMDS_MeshNode::
- GetInverseElementIterator() const
-{
- class SMDS_InverseElementIterator:public SMDS_Iterator<const SMDS_MeshElement*>
- {
- const set<const SMDS_MeshElement*>& mySet;
- set<const SMDS_MeshElement*>::iterator myIterator;
- public:
- SMDS_InverseElementIterator(const set<const SMDS_MeshElement*>& s):mySet(s)
- {
- myIterator=mySet.begin();
- }
-
- bool more()
- {
- myIterator!=mySet.end();
- }
-
- const SMDS_MeshElement* next()
- {
- const SMDS_MeshElement* current=*myIterator;
- myIterator++;
- return current;
- }
- };
- return new SMDS_InverseElementIterator(myInverseElements);
-}
-
-SMDS_Iterator<const SMDS_MeshElement *> * SMDS_MeshNode::
- elementsIterator(SMDSAbs_ElementType type) const
-{
- // Same as GetInverseElementIterator but the create iterator only return
- // wanted type elements.
- class MyIterator:public SMDS_Iterator<const SMDS_MeshElement*>
- {
- set<const SMDS_MeshElement*> mySet;
- set<const SMDS_MeshElement*>::iterator myIterator;
- public:
- MyIterator(SMDSAbs_ElementType type,
- const set<const SMDS_MeshElement*>& s)
- {
- const SMDS_MeshElement * e;
- bool toInsert;
- set<const SMDS_MeshElement*>::iterator it=s.begin();
- while(it!=s.end())
- {
- e=*it;
- switch(type)
- {
- case SMDSAbs_Edge: toInsert=true; break;
- case SMDSAbs_Face: toInsert=(e->GetType()!=SMDSAbs_Edge); break;
- case SMDSAbs_Volume: toInsert=(e->GetType()==SMDSAbs_Volume); break;
- }
- if(toInsert) mySet.insert(e);
- it++;
- }
- myIterator=mySet.begin();
- }
-
- bool more()
- {
- myIterator!=mySet.end();
- }
-
- const SMDS_MeshElement* next()
- {
- const SMDS_MeshElement* current=*myIterator;
- myIterator++;
- return current;
- }
- };
-
- if(type==SMDSAbs_Node)
- return SMDS_MeshElement::elementsIterator(SMDSAbs_Node);
- else
- return new SMDS_IteratorOfElements(this,type,
- new MyIterator(type, myInverseElements));
+const SMDS_PositionPtr& SMDS_MeshNode::GetPosition() const
+{
+ return myPosition;
+}
+
+//=======================================================================
+/*!
+ * \brief Iterator on list of elements
+ */
+//=======================================================================
+
+class SMDS_MeshNode_MyInvIterator: public SMDS_ElemIterator
+{
+private:
+ SMDS_Mesh* myMesh;
+ vtkIdType* myCells;
+ int myNcells;
+ SMDSAbs_ElementType myType;
+ int iter;
+ vector<vtkIdType> cellList;
+
+public:
+ SMDS_MeshNode_MyInvIterator(SMDS_Mesh *mesh, vtkIdType* cells, int ncells, SMDSAbs_ElementType type) :
+ myMesh(mesh), myCells(cells), myNcells(ncells), myType(type), iter(0)
+ {
+ //MESSAGE("SMDS_MeshNode_MyInvIterator : ncells " << myNcells);
+ cellList.clear();
+ if (type == SMDSAbs_All)
+ for (int i = 0; i < ncells; i++)
+ cellList.push_back(cells[i]);
+ else for (int i = 0; i < ncells; i++)
+ {
+ int vtkId = cells[i];
+ int smdsId = myMesh->fromVtkToSmds(vtkId);
+ const SMDS_MeshElement* elem = myMesh->FindElement(smdsId);
+ if (elem->GetType() == type)
+ {
+ //MESSAGE("Add element vtkId " << vtkId << " " << elem->GetType())
+ cellList.push_back(vtkId);
+ }
+ }
+ myCells = cellList.empty() ? 0 : &cellList[0];
+ myNcells = cellList.size();
+ //MESSAGE("myNcells="<<myNcells);
+ }
+
+ bool more()
+ {
+ //MESSAGE("iter " << iter << " ncells " << myNcells);
+ return (iter < myNcells);
+ }
+
+ const SMDS_MeshElement* next()
+ {
+ int vtkId = myCells[iter];
+ int smdsId = myMesh->fromVtkToSmds(vtkId);
+ const SMDS_MeshElement* elem = myMesh->FindElement(smdsId);
+ if (!elem)
+ {
+ MESSAGE("SMDS_MeshNode_MyInvIterator problem Null element");
+ throw SALOME_Exception("SMDS_MeshNode_MyInvIterator problem Null element");
+ }
+ //MESSAGE("vtkId " << vtkId << " smdsId " << smdsId << " " << elem->GetType());
+ iter++;
+ return elem;
+ }
+};
+
+SMDS_ElemIteratorPtr SMDS_MeshNode::
+ GetInverseElementIterator(SMDSAbs_ElementType type) const
+{
+ vtkCellLinks::Link l = SMDS_Mesh::_meshList[myMeshId]->getGrid()->GetCellLinks()->GetLink(myVtkID);
+ //MESSAGE("myID " << myID << " ncells " << l.ncells);
+ return SMDS_ElemIteratorPtr(new SMDS_MeshNode_MyInvIterator(SMDS_Mesh::_meshList[myMeshId], l.cells, l.ncells, type));
+}
+
+// Same as GetInverseElementIterator but the create iterator only return
+// wanted type elements.
+class SMDS_MeshNode_MyIterator:public SMDS_ElemIterator
+{
+private:
+ SMDS_Mesh* myMesh;
+ vtkIdType* myCells;
+ int myNcells;
+ SMDSAbs_ElementType myType;
+ int iter;
+ vector<SMDS_MeshElement*> myFiltCells;
+
+ public:
+ SMDS_MeshNode_MyIterator(SMDS_Mesh *mesh,
+ vtkIdType* cells,
+ int ncells,
+ SMDSAbs_ElementType type):
+ myMesh(mesh), myCells(cells), myNcells(ncells), myType(type), iter(0)
+ {
+ //MESSAGE("myNcells " << myNcells);
+ for (; iter<ncells; iter++)
+ {
+ int vtkId = myCells[iter];
+ int smdsId = myMesh->fromVtkToSmds(vtkId);
+ //MESSAGE("vtkId " << vtkId << " smdsId " << smdsId);
+ const SMDS_MeshElement* elem = myMesh->FindElement(smdsId);
+ if (elem->GetType() == type)
+ myFiltCells.push_back((SMDS_MeshElement*)elem);
+ }
+ myNcells = myFiltCells.size();
+ //MESSAGE("myNcells " << myNcells);
+ iter = 0;
+ //MESSAGE("SMDS_MeshNode_MyIterator (filter) " << ncells << " " << myNcells);
+ }
+
+ bool more()
+ {
+ return (iter< myNcells);
+ }
+
+ const SMDS_MeshElement* next()
+ {
+ const SMDS_MeshElement* elem = myFiltCells[iter];
+ iter++;
+ return elem;
+ }
+};
+
+SMDS_ElemIteratorPtr SMDS_MeshNode::
+ elementsIterator(SMDSAbs_ElementType type) const
+{
+ if(type==SMDSAbs_Node)
+ return SMDS_MeshElement::elementsIterator(SMDSAbs_Node);
+ else
+ {
+ vtkCellLinks::Link l = SMDS_Mesh::_meshList[myMeshId]->getGrid()->GetCellLinks()->GetLink(myVtkID);
+ return SMDS_ElemIteratorPtr(new SMDS_MeshNode_MyIterator(SMDS_Mesh::_meshList[myMeshId], l.cells, l.ncells, type));
+ }