}
}
+template<int SPACEDIM>
+int DataArrayDouble::ComputeBasicClosestTupleIdAlg(const std::vector<int>& elems, const double *thisPt, const double *zePt)
+{
+ double val=std::numeric_limits<double>::max();
+ int ret=-1;
+ for(std::vector<int>::const_iterator it=elems.begin();it!=elems.end();it++)
+ {
+ double tmp=0.;
+ for(int j=0;j<SPACEDIM;j++) tmp+=thisPt[SPACEDIM*(*it)+j]-zePt[j];
+ if(tmp<val)
+ { val=tmp; ret=*it; }
+ }
+ return ret;
+}
+
+template<int SPACEDIM>
+void DataArrayDouble::FindClosestTupleIdAlg(const BBTree<SPACEDIM,int>& myTree, double dist, const double *pos, int nbOfTuples, const double *thisPt, int thisNbOfTuples, int *res)
+{
+ double distOpt(dist);
+ const double *p(pos);
+ int *r(res);
+ double bbox[2*SPACEDIM];
+ for(int i=0;i<nbOfTuples;i++,p+=SPACEDIM,r++)
+ {
+ double failVal(distOpt),okVal(std::numeric_limits<double>::max());
+ int nbOfTurn=15;
+ while(nbOfTurn>0)
+ {
+ for(int j=0;j<SPACEDIM;j++) { bbox[2*j]=p[j]-distOpt; bbox[2*j]=p[j]+distOpt; }
+ std::vector<int> elems;
+ myTree.getIntersectingElems(bbox,elems); nbOfTurn--;
+ if(elems.empty())
+ { failVal=distOpt; distOpt=okVal==std::numeric_limits<double>::max()?2*distOpt:(okVal+failVal)/2.; continue; }
+ if( elems.size()<=15 || nbOfTurn>0)
+ { *r=ComputeBasicClosestTupleIdAlg<SPACEDIM>(elems,thisPt,p); break; }
+ else
+ { okVal=distOpt; distOpt=(distOpt+failVal)/2.; continue; }
+ }
+ }
+}
+
std::size_t DataArray::getHeapMemorySize() const
{
std::size_t sz1=_name.capacity();
return ret.retn();
}
+/*!
+ * 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.
+ *
+ * \return a newly allocated (new object to be dealt by the caller) DataArrayInt having \c other->getNumberOfTuples() tuples and one components.
+ */
+DataArrayInt *DataArrayDouble::findClosestTupleId(const DataArrayDouble *other) const throw(INTERP_KERNEL::Exception)
+{
+ 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)/thisNbOfTuples,1./3.);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> bbox=computeBBoxPerTuple(characSize*1e-12);
+ BBTree<3,int> myTree(bbox->getConstPointer(),0,0,getNumberOfTuples(),characSize*1e-12);
+ FindClosestTupleIdAlg<3>(myTree,2.*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*delta)/thisNbOfTuples);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> bbox=computeBBoxPerTuple(characSize*1e-12);
+ BBTree<2,int> myTree(bbox->getConstPointer(),0,0,getNumberOfTuples(),characSize*1e-12);
+ FindClosestTupleIdAlg<2>(myTree,2.*characSize,other->begin(),nbOfTuples,begin(),thisNbOfTuples,ret->getPointer());
+ break;
+ }
+ case 1:
+ {
+ double characSize=fabs(bounds[1]-bounds[0])/thisNbOfTuples;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> bbox=computeBBoxPerTuple(characSize*1e-12);
+ BBTree<1,int> myTree(bbox->getConstPointer(),0,0,getNumberOfTuples(),characSize*1e-12);
+ FindClosestTupleIdAlg<1>(myTree,2.*characSize,other->begin(),nbOfTuples,begin(),thisNbOfTuples,ret->getPointer());
+ break;
+ }
+ default:
+ throw INTERP_KERNEL::Exception("Unexpected spacedim of coords for findClosestTupleId. Must be 1, 2 or 3.");
+ }
+ return ret.retn();
+}
+
/*!
* This method returns a newly allocated object the user should deal with.
* This method works for arrays which have number of components into [1,2,3]. If not an exception will be thrown.
const int *cptr=getConstPointer();
std::vector<int> res;
int nbOfTuples=getNumberOfTuples();
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
for(int i=0;i<nbOfTuples;i++,cptr++)
if(vals2.find(*cptr)!=vals2.end())
- res.push_back(i);
- DataArrayInt *ret=DataArrayInt::New();
- ret->alloc((int)res.size(),1);
- std::copy(res.begin(),res.end(),ret->getPointer());
- return ret;
+ ret->pushBackSilent(i);
+ return ret.retn();
}
DataArrayInt *DataArrayInt::getIdsNotEqualList(const int *valsBg, const int *valsEnd) const throw(INTERP_KERNEL::Exception)
const int *cptr=getConstPointer();
std::vector<int> res;
int nbOfTuples=getNumberOfTuples();
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
for(int i=0;i<nbOfTuples;i++,cptr++)
if(vals2.find(*cptr)==vals2.end())
- res.push_back(i);
- DataArrayInt *ret=DataArrayInt::New();
- ret->alloc((int)res.size(),1);
- std::copy(res.begin(),res.end(),ret->getPointer());
- return ret;
+ ret->pushBackSilent(i);
+ return ret.retn();
}
/*!
MEDCOUPLING_EXPORT void findCommonTuples(double prec, int limitTupleId, DataArrayInt *&comm, DataArrayInt *&commIndex) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT DataArrayDouble *duplicateEachTupleNTimes(int nbTimes) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT DataArrayDouble *getDifferentValues(double prec, int limitTupleId=-1) const throw(INTERP_KERNEL::Exception);
+ MEDCOUPLING_EXPORT DataArrayInt *findClosestTupleId(const DataArrayDouble *other) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void setSelectedComponents(const DataArrayDouble *a, const std::vector<int>& compoIds) throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void setPartOfValues1(const DataArrayDouble *a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare=true) throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void setPartOfValuesSimple1(double a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception);
template<int SPACEDIM>
void findCommonTuplesAlg(const double *bbox, int nbNodes, int limitNodeId, double prec, DataArrayInt *c, DataArrayInt *cI) const;
template<int SPACEDIM>
+ static void FindClosestTupleIdAlg(const BBTree<SPACEDIM,int>& myTree, double dist, const double *pos, int nbOfTuples, const double *thisPt, int thisNbOfTuples, int *res);
+ template<int SPACEDIM>
+ static int ComputeBasicClosestTupleIdAlg(const std::vector<int>& elems, const double *thisPt, const double *zePt);
+ template<int SPACEDIM>
static void FindTupleIdsNearTuplesAlg(const BBTree<SPACEDIM,int>& myTree, const double *pos, int nbOfTuples, double eps,
DataArrayInt *c, DataArrayInt *cI);
private:
namespace ParaMEDMEM
{
+ typedef enum
+ {
+ IK_ONLY_PREFERED = 0,
+ NOT_IK_ONLY_PREFERED = 1,
+ IK_ONLY_FORCED = 2,
+ NOT_IK_ONLY_FORCED =3
+ } InterpolationMatrixPolicy;
+
class MEDCouplingRemapper : public TimeLabel, public INTERP_KERNEL::InterpolationOptions
{
private:
void reverseTransfer(MEDCouplingFieldDouble *srcField, const MEDCouplingFieldDouble *targetField, double dftValue) throw(INTERP_KERNEL::Exception);
MEDCouplingFieldDouble *transferField(const MEDCouplingFieldDouble *srcField, double dftValue) throw(INTERP_KERNEL::Exception);
MEDCouplingFieldDouble *reverseTransferField(const MEDCouplingFieldDouble *targetField, double dftValue) throw(INTERP_KERNEL::Exception);
- bool setOptionInt(const std::string& key, int value);
- bool setOptionDouble(const std::string& key, double value);
- bool setOptionString(const std::string& key, const std::string& value);
+ bool setOptionInt(const std::string& key, int value) throw(INTERP_KERNEL::Exception);
+ bool setOptionDouble(const std::string& key, double value) throw(INTERP_KERNEL::Exception);
+ bool setOptionString(const std::string& key, const std::string& value) throw(INTERP_KERNEL::Exception);
+ int getInterpolationMatrixPolicy() const throw(INTERP_KERNEL::Exception);
+ void setInterpolationMatrixPolicy(int newInterpMatPol) throw(INTERP_KERNEL::Exception);
//
int nullifiedTinyCoeffInCrudeMatrixAbs(double maxValAbs) throw(INTERP_KERNEL::Exception);
int nullifiedTinyCoeffInCrudeMatrix(double scaleFactor) throw(INTERP_KERNEL::Exception);
double getMaxValueInCrudeMatrix() const throw(INTERP_KERNEL::Exception);
%extend
{
- PyObject *getCrudeMatrix() const
+ PyObject *getCrudeMatrix() const throw(INTERP_KERNEL::Exception)
{
const std::vector<std::map<int,double> >& m=self->getCrudeMatrix();
std::size_t sz=m.size();