+/*!
+ * This method expects that \a this and \a otherBBoxFrmt arrays are bounding box arrays ( as the output of MEDCouplingPointSet::getBoundingBoxForBBTree method ).
+ * This method will return a DataArrayInt array having the same number of tuples than \a this. This returned array tells for each cell in \a this
+ * how many bounding boxes in \a otherBBoxFrmt.
+ * So, this method expects that \a this and \a otherBBoxFrmt have the same number of components.
+ *
+ * \param [in] otherBBoxFrmt - It is an array .
+ * \param [in] eps - the absolute precision of the detection. when eps < 0 the bboxes are enlarged so more interactions are detected. Inversely when > 0 the bboxes are stretched.
+ * \sa MEDCouplingPointSet::getBoundingBoxForBBTree
+ * \throw If \a this and \a otherBBoxFrmt have not the same number of components.
+ * \throw If \a this and \a otherBBoxFrmt number of components is not even (BBox format).
+ */
+DataArrayInt *DataArrayDouble::computeNbOfInteractionsWith(const DataArrayDouble *otherBBoxFrmt, double eps) const
+{
+ if(!otherBBoxFrmt)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::computeNbOfInteractionsWith : input array is NULL !");
+ if(!isAllocated() || !otherBBoxFrmt->isAllocated())
+ throw INTERP_KERNEL::Exception("DataArrayDouble::computeNbOfInteractionsWith : this and input array must be allocated !");
+ int nbOfComp(getNumberOfComponents()),nbOfTuples(getNumberOfTuples());
+ if(nbOfComp!=otherBBoxFrmt->getNumberOfComponents())
+ {
+ std::ostringstream oss; oss << "DataArrayDouble::computeNbOfInteractionsWith : this number of components (" << nbOfComp << ") must be equal to the number of components of input array (" << otherBBoxFrmt->getNumberOfComponents() << ") !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ if(nbOfComp%2!=0)
+ {
+ std::ostringstream oss; oss << "DataArrayDouble::computeNbOfInteractionsWith : Number of components (" << nbOfComp << ") is not even ! It should be to be compatible with bbox format !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(nbOfTuples,1);
+ const double *thisBBPtr(begin());
+ int *retPtr(ret->getPointer());
+ switch(nbOfComp/2)
+ {
+ case 3:
+ {
+ BBTree<3,int> bbt(otherBBoxFrmt->begin(),0,0,otherBBoxFrmt->getNumberOfTuples(),eps);
+ for(int i=0;i<nbOfTuples;i++,retPtr++,thisBBPtr+=nbOfComp)
+ *retPtr=bbt.getNbOfIntersectingElems(thisBBPtr);
+ break;
+ }
+ case 2:
+ {
+ BBTree<2,int> bbt(otherBBoxFrmt->begin(),0,0,otherBBoxFrmt->getNumberOfTuples(),eps);
+ for(int i=0;i<nbOfTuples;i++,retPtr++,thisBBPtr+=nbOfComp)
+ *retPtr=bbt.getNbOfIntersectingElems(thisBBPtr);
+ break;
+ }
+ case 1:
+ {
+ BBTree<1,int> bbt(otherBBoxFrmt->begin(),0,0,otherBBoxFrmt->getNumberOfTuples(),eps);
+ for(int i=0;i<nbOfTuples;i++,retPtr++,thisBBPtr+=nbOfComp)
+ *retPtr=bbt.getNbOfIntersectingElems(thisBBPtr);
+ break;
+ }
+ default:
+ throw INTERP_KERNEL::Exception("DataArrayDouble::computeNbOfInteractionsWith : space dimension supported are [1,2,3] !");
+ }
+
+ return ret.retn();
+}
+