+ findCommonTuplesAlg<1>(begin(),nbOfTuples,limitTupleId,prec,c,cI);
+ break;
+ default:
+ throw INTERP_KERNEL::Exception("DataArrayDouble::findCommonTuples : nb of components managed are 1,2,3 and 4 ! not implemented for other number of components !");
+ }
+ comm=c.retn();
+ commIndex=cI.retn();
+}
+
+/*!
+ *
+ * \param [in] nbTimes specifies the nb of times each tuples in \a this will be duplicated contiguouly in returned DataArrayDouble instance.
+ * \a nbTimes should be at least equal to 1.
+ * \return a newly allocated DataArrayDouble having one component and number of tuples equal to \a nbTimes * \c this->getNumberOfTuples.
+ * \throw if \a this is not allocated or if \a this has not number of components set to one or if \a nbTimes is lower than 1.
+ */
+DataArrayDouble *DataArrayDouble::duplicateEachTupleNTimes(int nbTimes) const
+{
+ checkAllocated();
+ if(getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::duplicateEachTupleNTimes : this should have only one component !");
+ if(nbTimes<1)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::duplicateEachTupleNTimes : nb times should be >= 1 !");
+ int nbTuples=getNumberOfTuples();
+ const double *inPtr=getConstPointer();
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New(); ret->alloc(nbTimes*nbTuples,1);
+ double *retPtr=ret->getPointer();
+ for(int i=0;i<nbTuples;i++,inPtr++)
+ {
+ double val=*inPtr;
+ for(int j=0;j<nbTimes;j++,retPtr++)
+ *retPtr=val;
+ }
+ ret->copyStringInfoFrom(*this);
+ return ret.retn();
+}
+
+/*!
+ * This methods returns the minimal distance between the two set of points \a this and \a other.
+ * So \a this and \a other have to have the same number of components. If not an INTERP_KERNEL::Exception will be thrown.
+ * This method works only if number of components of \a this (equal to those of \a other) is in 1, 2 or 3.
+ *
+ * \param [out] thisTupleId the tuple id in \a this corresponding to the returned minimal distance
+ * \param [out] otherTupleId the tuple id in \a other corresponding to the returned minimal distance
+ * \return the minimal distance between the two set of points \a this and \a other.
+ * \sa DataArrayDouble::findClosestTupleId
+ */
+double DataArrayDouble::minimalDistanceTo(const DataArrayDouble *other, int& thisTupleId, int& otherTupleId) const
+{
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> part1=findClosestTupleId(other);
+ int nbOfCompo(getNumberOfComponents());
+ int otherNbTuples(other->getNumberOfTuples());
+ const double *thisPt(begin()),*otherPt(other->begin());
+ const int *part1Pt(part1->begin());
+ double ret=std::numeric_limits<double>::max();
+ for(int i=0;i<otherNbTuples;i++,part1Pt++,otherPt+=nbOfCompo)
+ {
+ double tmp(0.);
+ for(int j=0;j<nbOfCompo;j++)
+ tmp+=(otherPt[j]-thisPt[nbOfCompo*(*part1Pt)+j])*(otherPt[j]-thisPt[nbOfCompo*(*part1Pt)+j]);
+ if(tmp<ret)
+ { ret=tmp; thisTupleId=*part1Pt; otherTupleId=i; }
+ }
+ return sqrt(ret);
+}
+
+/*!
+ * This methods returns for each tuple in \a other which tuple in \a this is the closest.
+ * So \a this and \a other have to have the same number of components. If not an INTERP_KERNEL::Exception will be thrown.
+ * This method works only if number of components of \a this (equal to those of \a other) is in 1, 2 or 3.
+ *
+ * \return a newly allocated (new object to be dealt by the caller) DataArrayInt having \c other->getNumberOfTuples() tuples and one components.
+ * \sa DataArrayDouble::minimalDistanceTo
+ */
+DataArrayInt *DataArrayDouble::findClosestTupleId(const DataArrayDouble *other) const
+{
+ if(!other)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::findClosestTupleId : other instance is NULL !");
+ checkAllocated(); other->checkAllocated();
+ int nbOfCompo=getNumberOfComponents();
+ if(nbOfCompo!=other->getNumberOfComponents())
+ {
+ std::ostringstream oss; oss << "DataArrayDouble::findClosestTupleId : number of components in this is " << nbOfCompo;
+ oss << ", whereas number of components in other is " << other->getNumberOfComponents() << "! Should be equal !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ int nbOfTuples=other->getNumberOfTuples();
+ int thisNbOfTuples=getNumberOfTuples();
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(nbOfTuples,1);
+ double bounds[6];
+ getMinMaxPerComponent(bounds);
+ switch(nbOfCompo)
+ {
+ case 3:
+ {
+ double xDelta(fabs(bounds[1]-bounds[0])),yDelta(fabs(bounds[3]-bounds[2])),zDelta(fabs(bounds[5]-bounds[4]));
+ double delta=std::max(xDelta,yDelta); delta=std::max(delta,zDelta);
+ double characSize=pow((delta*delta*delta)/((double)thisNbOfTuples),1./3.);
+ BBTreePts<3,int> myTree(begin(),0,0,getNumberOfTuples(),characSize*1e-12);
+ FindClosestTupleIdAlg<3>(myTree,3.*characSize*characSize,other->begin(),nbOfTuples,begin(),thisNbOfTuples,ret->getPointer());
+ break;
+ }
+ case 2:
+ {
+ double xDelta(fabs(bounds[1]-bounds[0])),yDelta(fabs(bounds[3]-bounds[2]));
+ double delta=std::max(xDelta,yDelta);
+ double characSize=sqrt(delta/(double)thisNbOfTuples);
+ BBTreePts<2,int> myTree(begin(),0,0,getNumberOfTuples(),characSize*1e-12);
+ FindClosestTupleIdAlg<2>(myTree,2.*characSize*characSize,other->begin(),nbOfTuples,begin(),thisNbOfTuples,ret->getPointer());
+ break;
+ }
+ case 1:
+ {
+ double characSize=fabs(bounds[1]-bounds[0])/thisNbOfTuples;
+ BBTreePts<1,int> myTree(begin(),0,0,getNumberOfTuples(),characSize*1e-12);
+ FindClosestTupleIdAlg<1>(myTree,1.*characSize*characSize,other->begin(),nbOfTuples,begin(),thisNbOfTuples,ret->getPointer());
+ break;
+ }