updateTime();
}
+/*!
+ * Entry point for iteration over cells of this. Warning the returned cell iterator should be deallocated.
+ */
+MEDCouplingUMeshCellIterator *MEDCouplingUMesh::cellIterator()
+{
+ return new MEDCouplingUMeshCellIterator(this);
+}
+
std::set<INTERP_KERNEL::NormalizedCellType> MEDCouplingUMesh::getAllGeoTypes() const
{
return _types;
else
throw INTERP_KERNEL::Exception("MEDCouplingUMesh::fillInCompact3DMode : Invalid spaceDim specified : must be 2 or 3 !");
}
+
+MEDCouplingUMeshCellIterator::MEDCouplingUMeshCellIterator(MEDCouplingUMesh *mesh):_mesh(mesh),_cell(new MEDCouplingUMeshCell(mesh)),
+ _cell_id(-1),_nb_cell(0)
+{
+ if(mesh)
+ {
+ mesh->incrRef();
+ _nb_cell=mesh->getNumberOfCells();
+ }
+}
+
+MEDCouplingUMeshCellIterator::~MEDCouplingUMeshCellIterator()
+{
+ if(_mesh)
+ _mesh->decrRef();
+ delete _cell;
+}
+
+MEDCouplingUMeshCell *MEDCouplingUMeshCellIterator::nextt()
+{
+ _cell_id++;
+ if(_cell_id<_nb_cell)
+ {
+ _cell->next();
+ return _cell;
+ }
+ else
+ return 0;
+}
+
+MEDCouplingUMeshCell::MEDCouplingUMeshCell(MEDCouplingUMesh *mesh):_conn(0),_conn_indx(0),_conn_lgth(NOTICABLE_FIRST_VAL)
+{
+ if(mesh)
+ {
+ _conn=mesh->getNodalConnectivity()->getPointer();
+ _conn_indx=mesh->getNodalConnectivityIndex()->getPointer();
+ }
+}
+
+void MEDCouplingUMeshCell::next()
+{
+ if(_conn_lgth!=NOTICABLE_FIRST_VAL)
+ {
+ _conn+=_conn_lgth;
+ _conn_indx++;
+ }
+ _conn_lgth=_conn_indx[1]-_conn_indx[0];
+}
+
+std::string MEDCouplingUMeshCell::repr() const
+{
+ if(_conn_lgth!=NOTICABLE_FIRST_VAL)
+ {
+ std::ostringstream oss; oss << "Cell Type " << INTERP_KERNEL::CellModel::GetCellModel((INTERP_KERNEL::NormalizedCellType)_conn[0]).getRepr();
+ oss << " : ";
+ std::copy(_conn+1,_conn+_conn_lgth,std::ostream_iterator<int>(oss," "));
+ return oss.str();
+ }
+ else
+ return std::string("MEDCouplingUMeshCell::repr : Invalid pos");
+}
+
+INTERP_KERNEL::NormalizedCellType MEDCouplingUMeshCell::getType() const
+{
+ if(_conn_lgth!=NOTICABLE_FIRST_VAL)
+ return (INTERP_KERNEL::NormalizedCellType)_conn[0];
+ else
+ return INTERP_KERNEL::NORM_ERROR;
+}
+
+const int *MEDCouplingUMeshCell::getAllConn(int& lgth) const
+{
+ lgth=_conn_lgth;
+ if(_conn_lgth!=NOTICABLE_FIRST_VAL)
+ return _conn;
+ else
+ return 0;
+}
+
namespace ParaMEDMEM
{
+ class MEDCouplingUMeshCellIterator;
+
class MEDCouplingUMesh : public MEDCouplingPointSet
{
public:
MEDCOUPLING_EXPORT void allocateCells(int nbOfCells);
MEDCOUPLING_EXPORT void insertNextCell(INTERP_KERNEL::NormalizedCellType type, int size, const int *nodalConnOfCell) throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void finishInsertingCells();
+ MEDCOUPLING_EXPORT MEDCouplingUMeshCellIterator *cellIterator();
MEDCOUPLING_EXPORT const std::set<INTERP_KERNEL::NormalizedCellType>& getAllTypes() const { return _types; }
MEDCOUPLING_EXPORT std::set<INTERP_KERNEL::NormalizedCellType> getAllGeoTypes() const;
MEDCOUPLING_EXPORT std::set<INTERP_KERNEL::NormalizedCellType> getTypesOfPart(const int *begin, const int *end) const throw(INTERP_KERNEL::Exception);
public:
static double EPS_FOR_POLYH_ORIENTATION;
};
+
+ class MEDCouplingUMeshCell;
+
+ class MEDCouplingUMeshCellIterator
+ {
+ public:
+ MEDCouplingUMeshCellIterator(MEDCouplingUMesh *mesh);
+ ~MEDCouplingUMeshCellIterator();
+ MEDCouplingUMeshCell *nextt();
+ private:
+ MEDCouplingUMesh *_mesh;
+ MEDCouplingUMeshCell *_cell;
+ int _cell_id;
+ int _nb_cell;
+ };
+
+ class MEDCouplingUMeshCell
+ {
+ public:
+ MEDCouplingUMeshCell(MEDCouplingUMesh *mesh);
+ void next();
+ std::string repr() const;
+ INTERP_KERNEL::NormalizedCellType getType() const;
+ const int *getAllConn(int& lgth) const;
+ private:
+ int *_conn;
+ int *_conn_indx;
+ int _conn_lgth;
+ static const int NOTICABLE_FIRST_VAL=-7;
+ };
}
#endif
%newobject ParaMEDMEM::MEDCouplingUMesh::getNodalConnectivity;
%newobject ParaMEDMEM::MEDCouplingUMesh::getNodalConnectivityIndex;
%newobject ParaMEDMEM::MEDCouplingUMesh::clone;
+%newobject ParaMEDMEM::MEDCouplingUMesh::__iter__;
%newobject ParaMEDMEM::MEDCouplingUMesh::zipConnectivityTraducer;
%newobject ParaMEDMEM::MEDCouplingUMesh::buildDescendingConnectivity;
%newobject ParaMEDMEM::MEDCouplingUMesh::buildExtrudedMesh;
}
}
};
+
+ class MEDCouplingUMeshCell
+ {
+ public:
+ INTERP_KERNEL::NormalizedCellType getType() const;
+ %extend
+ {
+ std::string __str__() const
+ {
+ return self->repr();
+ }
+
+ PyObject *getAllConn() const
+ {
+ int ret2;
+ const int *r=self->getAllConn(ret2);
+ PyObject *ret=PyTuple_New(ret2);
+ for(int i=0;i<ret2;i++)
+ PyTuple_SetItem(ret,i,PyInt_FromLong(r[i]));
+ return ret;
+ }
+ }
+ };
+
+ class MEDCouplingUMeshCellIterator
+ {
+ public:
+ %extend
+ {
+ PyObject *next()
+ {
+ MEDCouplingUMeshCell *ret=self->nextt();
+ if(ret)
+ return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMeshCell,0|0);
+ else
+ {
+ PyErr_SetString(PyExc_StopIteration,"No more data.");
+ return 0;
+ }
+ }
+ }
+ };
class MEDCouplingUMesh : public ParaMEDMEM::MEDCouplingPointSet
{
{
return self->simpleRepr();
}
+
+ MEDCouplingUMeshCellIterator *__iter__()
+ {
+ return self->cellIterator();
+ }
+
void insertNextCell(INTERP_KERNEL::NormalizedCellType type, int size, PyObject *li) throw(INTERP_KERNEL::Exception)
{
int sz;
pass
self.assertEqual([2, 3, 7, 5, 6, 7, 8, 9, 7, 11, 12, 7],da.getValues())
pass
- pass
+
+ def testSwigUMeshIterator1(self):
+ m=MEDCouplingDataForTest.build2DTargetMesh_1()
+ li1=[]
+ li2=[]
+ for cell in m:
+ li1+=cell.getAllConn()[1:]
+ li2+=[cell.getType()]
+ pass
+ self.assertEqual(li1,[0, 3, 4, 1, 1, 4, 2, 4, 5, 2, 6, 7, 4, 3, 7, 8, 5, 4])
+ self.assertEqual(li2,[4, 3, 3, 4, 4])
+ pass
def testDAIAggregateMulti1(self):
a=DataArrayInt.New()