return ret.retn();
}
+/*!
+ * \b WARNING this method is a \b non \a const \b method. This method works tuple by tuple. Each tuple is expected to be pairs (number of components must be equal to 2).
+ * This method rearrange each pair in \a this so that, tuple with id \b tid will be after the call \c this->getIJ(tid,0)==this->getIJ(tid-1,1) and \c this->getIJ(tid,1)==this->getIJ(tid+1,0).
+ * If it is impossible to reach such condition an exception will be thrown ! \b WARNING In case of throw \a this can be partially modified !
+ * If this method has correctly worked, \a this will be able to be considered as a linked list.
+ * This method does nothing if number of tuples is lower of equal to 1.
+ *
+ * This method is useful for users having an unstructured mesh having only SEG2 to rearrange internaly the connectibity without any coordinates consideration.
+ *
+ * \sa MEDCouplingUMesh::orderConsecutiveCells1D
+ */
+void DataArrayInt::sortEachPairToMakeALinkedList()
+{
+ checkAllocated();
+ if(getNumberOfComponents()!=2)
+ throw INTERP_KERNEL::Exception("DataArrayInt::sortEachPairToMakeALinkedList : Only works on DataArrayInt instance with nb of components equal to 2 !");
+ int nbOfTuples(getNumberOfTuples());
+ if(nbOfTuples<=1)
+ return ;
+ int *conn(getPointer());
+ for(int i=1;i<nbOfTuples;i++,conn+=2)
+ {
+ if(i>1)
+ {
+ if(conn[2]==conn[3])
+ {
+ std::ostringstream oss; oss << "DataArrayInt::sortEachPairToMakeALinkedList : In the tuple #" << i << " presence of a pair filled with same ids !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ if(conn[2]!=conn[1] && conn[3]==conn[1] && conn[2]!=conn[0])
+ std::swap(conn[2],conn[3]);
+ //not(conn[2]==conn[1] && conn[3]!=conn[1] && conn[3]!=conn[0])
+ if(conn[2]!=conn[1] || conn[3]==conn[1] || conn[3]==conn[0])
+ {
+ std::ostringstream oss; oss << "DataArrayInt::sortEachPairToMakeALinkedList : In the tuple #" << i << " something is invalid !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ else
+ {
+ if(conn[0]==conn[1] || conn[2]==conn[3])
+ throw INTERP_KERNEL::Exception("DataArrayInt::sortEachPairToMakeALinkedList : In the 2 first tuples presence of a pair filled with same ids !");
+ int tmp[4];
+ std::set<int> s;
+ s.insert(conn,conn+4);
+ if(s.size()!=3)
+ throw INTERP_KERNEL::Exception("DataArrayInt::sortEachPairToMakeALinkedList : This can't be considered as a linked list regarding 2 first tuples !");
+ if(std::count(conn,conn+4,conn[0])==2)
+ {
+ tmp[0]=conn[1];
+ tmp[1]=conn[0];
+ tmp[2]=conn[0];
+ if(conn[2]==conn[0])
+ { tmp[3]=conn[3]; }
+ else
+ { tmp[3]=conn[2];}
+ std::copy(tmp,tmp+4,conn);
+ }
+ }
+ }
+}
+
/*!
*
* \param [in] nbTimes specifies the nb of times each tuples in \a this will be duplicated contiguouly in returned DataArrayInt instance.
MEDCOUPLING_EXPORT DataArrayInt *buildExplicitArrOfSliceOnScaledArr(int begin, int stop, int step) const;
MEDCOUPLING_EXPORT DataArrayInt *findRangeIdForEachTuple(const DataArrayInt *ranges) const;
MEDCOUPLING_EXPORT DataArrayInt *findIdInRangeForEachTuple(const DataArrayInt *ranges) const;
+ MEDCOUPLING_EXPORT void sortEachPairToMakeALinkedList();
MEDCOUPLING_EXPORT DataArrayInt *duplicateEachTupleNTimes(int nbTimes) const;
MEDCOUPLING_EXPORT DataArrayInt *getDifferentValues() const;
MEDCOUPLING_EXPORT std::vector<DataArrayInt *> partitionByDifferentValues(std::vector<int>& differentIds) const;
if(angle>eps)
{
MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coo=_coords->deepCpy();
- MEDCouplingPointSet::Rotate3DAlg(origin,vec2,angle,coo->getNumberOfTuples(),coo->getPointer());
+ double normm2(sqrt(vec2[0]*vec2[0]+vec2[1]*vec2[1]+vec2[2]*vec2[2]));
+ if(normm2/normm>1e-6)
+ MEDCouplingPointSet::Rotate3DAlg(origin,vec2,angle,coo->getNumberOfTuples(),coo->getPointer());
MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mw=clone(false);//false -> shallow copy
mw->setCoords(coo);
mw->getBoundingBox(bbox);
* \throw If the nodal connectivity of the cells is not defined.
* \throw If m1 is not a mesh of dimension 2, or m1 is not a mesh of dimension 1
* \throw If m2 is not a (piecewise) line (i.e. if a point has more than 2 adjacent segments)
+ *
+ * \sa DataArrayInt::sortEachPairToMakeALinkedList
*/
DataArrayInt *MEDCouplingUMesh::orderConsecutiveCells1D() const
{
self.assertTrue(pd.toDAI().isEqual(DataArrayInt([2,4,5,6,10,12,14,20])))
pass
+ def testSwig2SortEachPairToMakeALinkedList1(self):
+ d=DataArrayInt([(50,49),(50,51),(51,52),(53,52),(53,54),(55,54),(55,56),(56,57),(58,57),(58,59),(60,59),(60,61),(61,62),(63,62),(63,64),(65,64),(65,66),(66,67)])
+ d.sortEachPairToMakeALinkedList()
+ self.assertTrue(d.isEqual(DataArrayInt([(49,50),(50,51),(51,52),(52,53),(53,54),(54,55),(55,56),(56,57),(57,58),(58,59),(59,60),(60,61),(61,62),(62,63),(63,64),(64,65),(65,66),(66,67)])))
+ pass
+
pass
if __name__ == '__main__':
DataArrayInt *buildExplicitArrByRanges(const DataArrayInt *offsets) const throw(INTERP_KERNEL::Exception);
DataArrayInt *findRangeIdForEachTuple(const DataArrayInt *ranges) const throw(INTERP_KERNEL::Exception);
DataArrayInt *findIdInRangeForEachTuple(const DataArrayInt *ranges) const throw(INTERP_KERNEL::Exception);
+ void sortEachPairToMakeALinkedList() throw(INTERP_KERNEL::Exception);
DataArrayInt *duplicateEachTupleNTimes(int nbTimes) const throw(INTERP_KERNEL::Exception);
DataArrayInt *getDifferentValues() const throw(INTERP_KERNEL::Exception);
static DataArrayInt *Add(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception);