-// Copyright (C) 2007-2015 CEA/DEN, EDF R&D
+// Copyright (C) 2007-2016 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
#include "SplitterTetra.hxx"
#include "DiameterCalculator.hxx"
+#include "OrientationInverter.hxx"
#include "InterpKernelAutoPtr.hxx"
using namespace MEDCoupling;
/*!
* Returns nb of cells having the geometric type \a type. No throw if no cells in \a this has the geometric type \a type.
*/
-int MEDCoupling1GTUMesh::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const
+std::size_t MEDCoupling1GTUMesh::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const
{
return type==getCellModelEnum()?getNumberOfCells():0;
}
* \return INTERP_KERNEL::NormalizedCellType - enumeration item describing the cell type.
* \throw If \a cellId is invalid. Valid range is [0, \a this->getNumberOfCells() ).
*/
-INTERP_KERNEL::NormalizedCellType MEDCoupling1GTUMesh::getTypeOfCell(int cellId) const
+INTERP_KERNEL::NormalizedCellType MEDCoupling1GTUMesh::getTypeOfCell(std::size_t cellId) const
{
- if(cellId>=0 && cellId<getNumberOfCells())
+ if(cellId<getNumberOfCells())
return getCellModelEnum();
std::ostringstream oss; oss << "MEDCoupling1GTUMesh::getTypeOfCell : Requesting type of cell #" << cellId << " but it should be in [0," << getNumberOfCells() << ") !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
*/
int MEDCoupling1GTUMesh::getCellContainingPoint(const double *pos, double eps) const
{
- MCAuto<MEDCouplingUMesh> m=buildUnstructured();
+ MCAuto<MEDCouplingUMesh> m(buildUnstructured());
return m->getCellContainingPoint(pos,eps);
}
+/*!
+ * to improve perf !
+ */
+void MEDCoupling1GTUMesh::getCellsContainingPoint(const double *pos, double eps, std::vector<int>& elts) const
+{
+ MCAuto<MEDCouplingUMesh> m(buildUnstructured());
+ return m->getCellsContainingPoint(pos,eps,elts);
+}
+
MEDCouplingFieldDouble *MEDCoupling1GTUMesh::buildOrthogonalField() const
{
MCAuto<MEDCouplingUMesh> m=buildUnstructured();
m->findCommonCells(compType,startCellId,commonCellsArr,commonCellsIArr);
}
-int MEDCoupling1GTUMesh::getNodalConnectivityLength() const
+std::size_t MEDCoupling1GTUMesh::getNodalConnectivityLength() const
{
const DataArrayInt *c1(getNodalConnectivity());
if(!c1)
}
}
-int MEDCoupling1SGTUMesh::getNumberOfCells() const
+std::size_t MEDCoupling1SGTUMesh::getNumberOfCells() const
{
- int nbOfTuples=getNodalConnectivityLength();
- int nbOfNodesPerCell=getNumberOfNodesPerCell();
+ std::size_t nbOfTuples(getNodalConnectivityLength());
+ int nbOfNodesPerCell(getNumberOfNodesPerCell());
if(nbOfTuples%nbOfNodesPerCell!=0)
{
std::ostringstream oss; oss << "MEDCoupling1SGTUMesh:getNumberOfCells: : the nb of tuples in conn is " << nbOfTuples << " and number of nodes per cell is " << nbOfNodesPerCell << ". But " << nbOfTuples << "%" << nbOfNodesPerCell << " !=0 !";
return ret.retn();
}
-void MEDCoupling1SGTUMesh::getNodeIdsOfCell(int cellId, std::vector<int>& conn) const
+void MEDCoupling1SGTUMesh::getNodeIdsOfCell(std::size_t cellId, std::vector<int>& conn) const
{
int sz=getNumberOfNodesPerCell();
conn.resize(sz);
- if(cellId>=0 && cellId<getNumberOfCells())
+ if(cellId<getNumberOfCells())
std::copy(_conn->begin()+cellId*sz,_conn->begin()+(cellId+1)*sz,conn.begin());
else
{
return ret.retn();
}
+/*!
+ * This method invert orientation of all cells in \a this.
+ * After calling this method the absolute value of measure of cells in \a this are the same than before calling.
+ * This method only operates on the connectivity so coordinates are not touched at all.
+ */
+void MEDCoupling1SGTUMesh::invertOrientationOfAllCells()
+{
+ checkConsistencyOfConnectivity();
+ INTERP_KERNEL::AutoCppPtr<INTERP_KERNEL::OrientationInverter> oi(INTERP_KERNEL::OrientationInverter::BuildInstanceFrom(getCellModelEnum()));
+ int nbOfNodesPerCell((int)_cm->getNumberOfNodes()),nbCells(getNumberOfCells());
+ int *conn(_conn->getPointer());
+ for(int i=0;i<nbCells;i++)
+ oi->operate(conn+i*nbOfNodesPerCell,conn+(i+1)*nbOfNodesPerCell);
+ updateTime();
+}
+
//==
MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::New()
if(c1->getInfoOnComponent(0)!="")
throw INTERP_KERNEL::Exception("Nodal connectivity index array is expected to have no info on its single component !");
int f=c1->front(),ll=c1->back();
- if(f<0 || f>=sz2)
+ if(f<0 || (sz2>0 && f>=sz2))
{
std::ostringstream oss; oss << "Nodal connectivity index array first value (" << f << ") is expected to be exactly in [0," << sz2 << ") !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
}
-int MEDCoupling1DGTUMesh::getNumberOfCells() const
+std::size_t MEDCoupling1DGTUMesh::getNumberOfCells() const
{
checkConsistencyOfConnectivity();//do not remove
return _conn_indx->getNumberOfTuples()-1;
return ret.retn();
}
-void MEDCoupling1DGTUMesh::getNodeIdsOfCell(int cellId, std::vector<int>& conn) const
+void MEDCoupling1DGTUMesh::getNodeIdsOfCell(std::size_t cellId, std::vector<int>& conn) const
{
- int nbOfCells(getNumberOfCells());//performs checks
- if(cellId>=0 && cellId<nbOfCells)
+ std::size_t nbOfCells(getNumberOfCells());//performs checks
+ if(cellId<nbOfCells)
{
int strt=_conn_indx->getIJ(cellId,0),stp=_conn_indx->getIJ(cellId+1,0);
int nbOfNodes=stp-strt;
*/
void MEDCoupling1DGTUMesh::insertNextCell(const int *nodalConnOfCellBg, const int *nodalConnOfCellEnd)
{
- int sz=(int)std::distance(nodalConnOfCellBg,nodalConnOfCellEnd);
+ std::size_t sz(std::distance(nodalConnOfCellBg,nodalConnOfCellEnd));
DataArrayInt *c(_conn),*c2(_conn_indx);
if(c && c2)
{
int pos=c2->back();
- if(pos==c->getNumberOfTuples())
+ if(pos==(int)c->getNumberOfTuples())
{
c->pushBackValsSilent(nodalConnOfCellBg,nodalConnOfCellEnd);
c2->pushBackSilent(pos+sz);
bool MEDCoupling1DGTUMesh::isPacked() const
{
checkConsistencyLight();
- return _conn_indx->front()==0 && _conn_indx->back()==_conn->getNumberOfTuples();
+ return _conn_indx->front()==0 && _conn_indx->back()==(int)_conn->getNumberOfTuples();
}
MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::Merge1DGTUMeshes(const MEDCoupling1DGTUMesh *mesh1, const MEDCoupling1DGTUMesh *mesh2)
return ret;
}
+/*!
+ * This method invert orientation of all cells in \a this.
+ * After calling this method the absolute value of measure of cells in \a this are the same than before calling.
+ * This method only operates on the connectivity so coordinates are not touched at all.
+ */
+void MEDCoupling1DGTUMesh::invertOrientationOfAllCells()
+{
+ checkConsistencyOfConnectivity();
+ INTERP_KERNEL::AutoCppPtr<INTERP_KERNEL::OrientationInverter> oi(INTERP_KERNEL::OrientationInverter::BuildInstanceFrom(getCellModelEnum()));
+ int nbCells(getNumberOfCells());
+ const int *connI(_conn_indx->begin());
+ int *conn(_conn->getPointer());
+ for(int i=0;i<nbCells;i++)
+ oi->operate(conn+connI[i],conn+connI[i+1]);
+ updateTime();
+}
+
/*!
* This method performs an aggregation of \a nodalConns (as DataArrayInt::Aggregate does) but in addition of that a shift is applied on the
* values contained in \a nodalConns using corresponding offset specified in input \a offsetInNodeIdsPerElt.