From 4695e5f2b5e87e9cf06137e714888ebee70c6b78 Mon Sep 17 00:00:00 2001 From: ageay Date: Thu, 31 Jan 2013 14:23:15 +0000 Subject: [PATCH] distance from point to mesh implementation --- src/INTERP_KERNEL/VolSurfUser.cxx | 101 +++++++++++++++++ src/INTERP_KERNEL/VolSurfUser.hxx | 9 ++ src/MEDCoupling/MEDCouplingMemArray.cxx | 39 +++++++ src/MEDCoupling/MEDCouplingMemArray.hxx | 1 + src/MEDCoupling/MEDCouplingUMesh.cxx | 138 ++++++++++++++++++++++- src/MEDCoupling/MEDCouplingUMesh.hxx | 3 + src/MEDCoupling_Swig/MEDCouplingCommon.i | 61 ++++++++-- 7 files changed, 336 insertions(+), 16 deletions(-) create mode 100644 src/INTERP_KERNEL/VolSurfUser.cxx diff --git a/src/INTERP_KERNEL/VolSurfUser.cxx b/src/INTERP_KERNEL/VolSurfUser.cxx new file mode 100644 index 000000000..582d1c31a --- /dev/null +++ b/src/INTERP_KERNEL/VolSurfUser.cxx @@ -0,0 +1,101 @@ +// Copyright (C) 2007-2012 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 +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Anthony Geay (CEA/DEN) + +#include "VolSurfUser.hxx" + +#include +#include + +namespace INTERP_KERNEL +{ + double DistanceFromPtToSegInSpaceDim2(const double *pt, const double *pt0Seg2, const double *pt1Seg2) throw(INTERP_KERNEL::Exception) + { + double dx=pt1Seg2[0]-pt0Seg2[0],dy=pt1Seg2[1]-pt0Seg2[1]; + double norm=sqrt(dx*dx+dy*dy); + if(norm==0.) + return std::numeric_limits::max(); + dx/=norm; dy/=norm; + double dx2=pt[0]-pt0Seg2[0],dy2=pt[1]-pt0Seg2[1]; + double dotP=(dx2*dx+dy2*dy); + if(dotP<0. || dotP>norm) + return std::numeric_limits::max(); + double x=pt0Seg2[0]+dotP*dx,y=pt0Seg2[1]+dotP*dy; + return sqrt((x-pt[0])*(x-pt[0])+(y-pt[1])*(y-pt[1])); + } + + double DistanceFromPtToTriInSpaceDim3(const double *pt, const double *pt0Tri3, const double *pt1Tri3, const double *pt2Tri3) throw(INTERP_KERNEL::Exception) + { + double matrix[12]; + if(!ComputeRotTranslationMatrixToPut3PointsOnOXY(pt0Tri3,pt1Tri3,pt2Tri3,matrix)) + return std::numeric_limits::max(); + double xy0[2],xy1[2],xy2[2],xy[2]; xy0[0]=0.; xy0[1]=0.; + xy1[0]=matrix[0]*pt1Tri3[0]+matrix[1]*pt1Tri3[1]+matrix[2]*pt1Tri3[2]+matrix[3]; xy1[1]=0.; + xy2[0]=matrix[0]*pt2Tri3[0]+matrix[1]*pt2Tri3[1]+matrix[2]*pt2Tri3[2]+matrix[3]; + xy2[1]=matrix[4]*pt2Tri3[0]+matrix[5]*pt2Tri3[1]+matrix[6]*pt2Tri3[2]+matrix[7]; + xy[0]=matrix[0]*pt[0]+matrix[1]*pt[1]+matrix[2]*pt[2]+matrix[3]; + xy[1]=matrix[4]*pt[0]+matrix[5]*pt[1]+matrix[6]*pt[2]+matrix[7]; + double z=matrix[8]*pt[0]+matrix[9]*pt[1]+matrix[10]*pt[2]+matrix[11]; + double ret=std::numeric_limits::max(); + int nbOfHint=0; + if(xy[0]>0. && xy[0]::max()) + { ret=std::min(ret,tmp); nbOfHint++; } + tmp=DistanceFromPtToSegInSpaceDim2(xy,xy2,xy0);//distance pt to edge [pt2Tri3,pt0Tri3] + if(tmp!=std::numeric_limits::max()) + { ret=std::min(ret,tmp); nbOfHint++; } + if(nbOfHint==3) + ret=std::min(ret,fabs(z)); + return ret; + } + + double DistanceFromPtToPolygonInSpaceDim3(const double *pt, const int *connOfPolygonBg, const int *connOfPolygonEnd, const double *coords) throw(INTERP_KERNEL::Exception) + { + return 0.; + } + + bool ComputeRotTranslationMatrixToPut3PointsOnOXY(const double *p0, const double *p1, const double *p2, double *matrix) + { + double norm=sqrt((p1[0]-p0[0])*(p1[0]-p0[0])+(p1[1]-p0[1])*(p1[1]-p0[1])+(p1[2]-p0[2])*(p1[2]-p0[2])); + double c=(p1[0]-p0[0])/norm; + double s=sqrt(1-c*c); + double y=p1[2]-p0[2],z=p0[1]-p1[1]; + norm=sqrt(y*y+z*z); y/=norm; z/=norm; + double r0[9]={c,-z*s,y*s, + z*s,y*y*(1-c)+c,y*z*(1-c), + -y*s,z*y*(1-c),z*z*(1-c)+c}; + // 2nd rotation matrix + double x=p2[0]-p0[0]; + y=p2[1]-p0[1]; z=p2[2]-p0[2]; + double y1=x*r0[3]+y*r0[4]+z*r0[5],z1=x*r0[6]+y*r0[7]+z*r0[8]; + c=y1/sqrt(y1*y1+z1*z1); + s=sqrt(1.-c*c); + // + std::copy(r0,r0+3,matrix); + matrix[4]=c*r0[3]-s*r0[6]; matrix[5]=c*r0[4]-s*r0[7]; matrix[6]=c*r0[5]-s*r0[8]; + matrix[8]=s*r0[3]+c*r0[6]; matrix[9]=s*r0[4]+c*r0[7]; matrix[10]=s*r0[5]+c*r0[8]; + matrix[3]=-p0[0]*matrix[0]-p0[1]*matrix[1]-p0[2]*matrix[2]; + matrix[7]=-p0[0]*matrix[4]-p0[1]*matrix[5]-p0[2]*matrix[6]; + matrix[11]=-p0[0]*matrix[8]-p0[1]*matrix[9]-p0[2]*matrix[10]; + return true; + } +} + diff --git a/src/INTERP_KERNEL/VolSurfUser.hxx b/src/INTERP_KERNEL/VolSurfUser.hxx index e6f877bf4..fea0f9886 100644 --- a/src/INTERP_KERNEL/VolSurfUser.hxx +++ b/src/INTERP_KERNEL/VolSurfUser.hxx @@ -21,6 +21,7 @@ #ifndef __VOLSURFUSER_HXX__ #define __VOLSURFUSER_HXX__ +#include "InterpKernelException.hxx" #include "NormalizedUnstructuredMesh.hxx" namespace INTERP_KERNEL @@ -36,6 +37,14 @@ namespace INTERP_KERNEL template void computeBarycenter2(NormalizedCellType type, const ConnType *connec, int lgth, const double *coords, int spaceDim, double *res); + + double DistanceFromPtToSegInSpaceDim2(const double *pt, const double *pt0Seg2, const double *pt1Seg2) throw(INTERP_KERNEL::Exception); + + double DistanceFromPtToTriInSpaceDim3(const double *pt, const double *pt0Tri3, const double *pt1Tri3, const double *pt2Tri3) throw(INTERP_KERNEL::Exception); + + double DistanceFromPtToPolygonInSpaceDim3(const double *pt, const int *connOfPolygonBg, const int *connOfPolygonEnd, const double *coords) throw(INTERP_KERNEL::Exception); + + bool ComputeRotTranslationMatrixToPut3PointsOnOXY(const double *pt0Tri3, const double *pt1Tri3, const double *pt2Tri3, double *matrix); } #endif diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index c3d433633..4436fa7d1 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -1956,6 +1956,45 @@ void DataArrayDouble::accumulate(double *res) const throw(INTERP_KERNEL::Excepti std::transform(ptr+i*nbComps,ptr+(i+1)*nbComps,res,res,std::plus()); } +/*! + * This method returns the min distance from an external tuple defined by [ \a tupleBg , \a tupleEnd ) to \a this and + * the first tuple in \a this that matches the returned distance. If there is no tuples in \a this an exception will be thrown. + * + * + * \a this is expected to be allocated and expected to have a number of components equal to the distance from \a tupleBg to + * \a tupleEnd. If not an exception will be thrown. + * + * \param [in] tupleBg start pointer (included) of input external tuple + * \param [in] tupleEnd end pointer (not included) of input external tuple + * \param [out] tupleId the tuple id in \a this that matches the min of distance between \a this and input external tuple + * \return the min distance. + * \sa MEDCouplingUMesh::distanceToPoint + */ +double DataArrayDouble::distanceToTuple(const double *tupleBg, const double *tupleEnd, int& tupleId) const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + int nbTuple=getNumberOfTuples(); + int nbComps=getNumberOfComponents(); + if(nbComps!=(int)std::distance(tupleBg,tupleEnd)) + { std::ostringstream oss; oss << "DataArrayDouble::distanceToTuple : size of input tuple is " << std::distance(tupleBg,tupleEnd) << " should be equal to the number of components in this : " << nbComps << " !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } + if(nbTuple==0) + throw INTERP_KERNEL::Exception("DataArrayDouble::distanceToTuple : no tuple in this ! No distance to compute !"); + double ret0=std::numeric_limits::max(); + tupleId=-1; + const double *work=getConstPointer(); + for(int i=0;i=ret0) + continue; + else + { ret0=val; tupleId=i; } + } + return sqrt(ret0); +} + double DataArrayDouble::accumulate(int compId) const throw(INTERP_KERNEL::Exception) { checkAllocated(); diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index adcaf01f5..eaa272724 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -258,6 +258,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT double normMax() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void accumulate(double *res) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT double accumulate(int compId) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT double distanceToTuple(const double *tupleBg, const double *tupleEnd, int& tupleId) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayDouble *fromPolarToCart() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayDouble *fromCylToCart() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayDouble *fromSpherToCart() const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index 9e741347a..5401b44f6 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -1068,7 +1068,7 @@ void MEDCouplingUMesh::simplifyPolyhedra(double eps) throw(INTERP_KERNEL::Except MEDCouplingAutoRefCountObjectPtr connINew=DataArrayInt::New(); connINew->alloc(nbOfCells+1,1); int *connINewPtr=connINew->getPointer(); *connINewPtr++=0; - MEDCouplingAutoRefCountObjectPtr connNew=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr connNew=DataArrayInt::New(); connNew->alloc(0,1); bool changed=false; for(int i=0;i commonCells=DataArrayInt::New(),commonCellsI=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr commonCells=DataArrayInt::New(),commonCellsI=DataArrayInt::New(); commonCells->alloc(0,1); int nbOfCells=nodalI->getNumberOfTuples()-1; commonCellsI->reserve(1); commonCellsI->pushBackSilent(0); const int *revNodalPtr=revNodal->getConstPointer(),*revNodalIPtr=revNodalI->getConstPointer(); @@ -1908,7 +1908,7 @@ DataArrayInt *MEDCouplingUMesh::getCellIdsFullyIncludedInNodeIds(const int *part */ void MEDCouplingUMesh::fillCellIdsToKeepFromNodeIds(const int *begin, const int *end, bool fullyIn, DataArrayInt *&cellIdsKeptArr) const { - MEDCouplingAutoRefCountObjectPtr cellIdsKept=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr cellIdsKept=DataArrayInt::New(); cellIdsKept->alloc(0,1); checkConnectivityFullyDefined(); int tmp=-1; int sz=getNodalConnectivity()->getMaxValue(tmp); sz=std::max(sz,0)+1; @@ -3319,7 +3319,7 @@ MEDCouplingUMesh *MEDCouplingUMesh::buildSlice3D(const double *origin, const dou mDesc1->getNodalConnectivity()->getConstPointer(),mDesc1->getNodalConnectivityIndex()->getConstPointer(), desc1->getConstPointer(),descIndx1->getConstPointer(),cut3DSurf); MEDCouplingAutoRefCountObjectPtr conn(DataArrayInt::New()),connI(DataArrayInt::New()),cellIds2(DataArrayInt::New()); - connI->pushBackSilent(0); + connI->pushBackSilent(0); conn->alloc(0,1); cellIds2->alloc(0,1); subMesh->assemblyForSplitFrom3DSurf(cut3DSurf,desc2->getConstPointer(),descIndx2->getConstPointer(),conn,connI,cellIds2); if(cellIds2->empty()) throw INTERP_KERNEL::Exception("MEDCouplingUMesh::buildSlice3D : No 3D cells in this intercepts the specified plane !"); @@ -3374,6 +3374,7 @@ MEDCouplingUMesh *MEDCouplingUMesh::buildSlice3DSurf(const double *origin, const mDesc1->getNodalConnectivity()->getConstPointer(),mDesc1->getNodalConnectivityIndex()->getConstPointer(), desc1->getConstPointer(),descIndx1->getConstPointer(),cut3DSurf); MEDCouplingAutoRefCountObjectPtr conn(DataArrayInt::New()),connI(DataArrayInt::New()),cellIds2(DataArrayInt::New()); connI->pushBackSilent(0); + conn->alloc(0,1); const int *nodal=subMesh->getNodalConnectivity()->getConstPointer(); const int *nodalI=subMesh->getNodalConnectivityIndex()->getConstPointer(); for(int i=0;idecrRef(); } +/*! + * This method computes the distance from a point \a pt to \a this and the first \a cellId and \a nodeId in \a this corresponding to the returned distance. + * \a this is expected to be a mesh so that its space dimension is equal to its + * mesh dimension + 1. Furthermore only mesh dimension 1 and 2 are supported for the moment. + * Distance from \a ptBg to \a ptEnd is expected to be equal to the space dimension. \a this is also expected to be fully defined (connectivity and coordinates). + * + * This method firstly find the closer node in \a this to the requested point whose coordinates are defined by [ \a ptBg, \a ptEnd ). Then for this node found + * the cells sharing this node (if any) are considered to find if the distance to these cell are smaller than the result found previously. If no cells are linked + * to the node that minimizes distance with the input point then -1 is returned in cellId. + * + * So this method is more accurate (so, more costly) than simply searching for the closest point in \a this. + * If only this information is enough for you simply call \c getCoords()->distanceToTuple on \a this. + * + * \param [in] ptBg the start pointer (included) of the coordinates of the point + * \param [in] ptEnd the end pointer (not included) of the coordinates of the point + * \param [out] cellId that corresponds to minimal distance. If the closer node is not linked to any cell in \a this -1 is returned. + * \return the positive value of the distance. + * \throw if distance from \a ptBg to \a ptEnd is not equal to the space dimension. An exception is also thrown if mesh dimension of \a this is not equal to space + * dimension - 1. + * \sa DataArrayDouble::distanceToTuple + */ +double MEDCouplingUMesh::distanceToPoint(const double *ptBg, const double *ptEnd, int& cellId, int& nodeId) const throw(INTERP_KERNEL::Exception) +{ + int meshDim=getMeshDimension(),spaceDim=getSpaceDimension(); + if(meshDim!=spaceDim-1) + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::distanceToPoint works only for spaceDim=meshDim+1 !"); + if(meshDim!=2 && meshDim!=1) + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::distanceToPoint : only mesh dimension 2 and 1 are implemented !"); + checkFullyDefined(); + if((int)std::distance(ptBg,ptEnd)!=spaceDim) + { std::ostringstream oss; oss << "MEDCouplingUMesh::distanceToPoint : input point has to have dimension equal to the space dimension of this (" << spaceDim << ") !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } + nodeId=-1; + double ret0=_coords->distanceToTuple(ptBg,ptEnd,nodeId); + if(nodeId==-1) + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::distanceToPoint : something wrong with nodes in this !"); + MEDCouplingAutoRefCountObjectPtr cellIds=getCellIdsLyingOnNodes(&nodeId,&nodeId+1,false); + switch(meshDim) + { + case 2: + { + distanceToPoint3DSurfAlg(ptBg,cellIds,ret0,cellId); + return ret0; + } + case 1: + { + distanceToPoint2DCurveAlg(ptBg,cellIds,ret0,cellId); + return ret0; + } + default: + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::distanceToPoint : only mesh dimension 2 and 1 are implemented !"); + } + + return ret0; +} + + +/*! + * \param [in] pt the start pointer (included) of the coordinates of the point + * \param [in] cellIds + * \param [in,out] ret0 the min distance between \a this and the external input point + * \param [out] cellId that corresponds to minimal distance. If the closer node is not linked to any cell in \a this -1 is returned. + * \sa MEDCouplingUMesh::distanceToPoint + */ +void MEDCouplingUMesh::distanceToPoint3DSurfAlg(const double *pt, const DataArrayInt *cellIds, double& ret0, int& cellId) const throw(INTERP_KERNEL::Exception) +{ + const double *coords=_coords->getConstPointer(); + cellId=-1; + if(cellIds->empty()) + return; + const int *ptr=_nodal_connec->getConstPointer(); + const int *ptrI=_nodal_connec_index->getConstPointer(); + for(const int *zeCell=cellIds->begin();zeCell!=cellIds->end();zeCell++) + { + switch((INTERP_KERNEL::NormalizedCellType)ptr[ptrI[*zeCell]]) + { + case INTERP_KERNEL::NORM_TRI3: + { + double tmp=INTERP_KERNEL::DistanceFromPtToTriInSpaceDim3(pt,coords+3*ptr[ptrI[*zeCell]+1],coords+3*ptr[ptrI[*zeCell]+2],coords+3*ptr[ptrI[*zeCell]+3]); + if(tmpgetConstPointer(); + if(cellIds->empty()) + { cellId=-1; return; } + const int *ptr=_nodal_connec->getConstPointer(); + const int *ptrI=_nodal_connec_index->getConstPointer(); + for(const int *zeCell=cellIds->begin();zeCell!=cellIds->end();zeCell++) + { + switch((INTERP_KERNEL::NormalizedCellType)ptr[ptrI[*zeCell]]) + { + case INTERP_KERNEL::NORM_SEG2: + { + double tmp=INTERP_KERNEL::DistanceFromPtToSegInSpaceDim2(pt,coords+2*ptr[ptrI[*zeCell]+1],coords+2*ptr[ptrI[*zeCell]+2]); + if(tmpgetConstPointer(); std::set types; MEDCouplingAutoRefCountObjectPtr isChanged(DataArrayInt::New()); + isChanged->alloc(0,1); for(int i=0;igetNumberOfTuples(); @@ -5628,6 +5757,7 @@ MEDCouplingUMesh *MEDCouplingUMesh::AggregateSortedByTypeMeshesOnSameCoords(cons std::vector< MEDCouplingAutoRefCountObjectPtr > m1ssmSingleAuto; int fake=0,rk=0; MEDCouplingAutoRefCountObjectPtr ret1(DataArrayInt::New()),ret2(DataArrayInt::New()); + ret1->alloc(0,1); ret2->alloc(0,1); for(std::vector::const_iterator it=ms2.begin();it!=ms2.end();it++,rk++) { if(meshDim!=(*it)->getMeshDimension()) diff --git a/src/MEDCoupling/MEDCouplingUMesh.hxx b/src/MEDCoupling/MEDCouplingUMesh.hxx index 47b00110b..c36681d6f 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.hxx +++ b/src/MEDCoupling/MEDCouplingUMesh.hxx @@ -159,6 +159,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayInt *getCellIdsCrossingPlane(const double *origin, const double *vec, double eps) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool isContiguous1D() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void project1D(const double *pt, const double *v, double eps, double *res) const; + MEDCOUPLING_EXPORT double distanceToPoint(const double *ptBg, const double *ptEnd, int& cellId, int& nodeId) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int getCellContainingPoint(const double *pos, double eps) const; MEDCOUPLING_EXPORT void getCellsContainingPoint(const double *pos, double eps, std::vector& elts) const; MEDCOUPLING_EXPORT void getCellsContainingPoints(const double *pos, int nbOfPoints, double eps, std::vector& elts, std::vector& eltsIndex) const; @@ -275,6 +276,8 @@ namespace ParaMEDMEM MEDCouplingUMesh *buildDescendingConnectivityGen(DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *revDesc, DataArrayInt *revDescIndx, DimM1DescNbrer nbrer) const throw(INTERP_KERNEL::Exception); DataArrayInt *buildUnionOf2DMesh() const throw(INTERP_KERNEL::Exception); DataArrayInt *buildUnionOf3DMesh() const throw(INTERP_KERNEL::Exception); + void distanceToPoint3DSurfAlg(const double *pt, const DataArrayInt *cellIds, double& ret0, int& cellId) const throw(INTERP_KERNEL::Exception); + void distanceToPoint2DCurveAlg(const double *pt, const DataArrayInt *cellIds, double& ret0, int& cellId) const throw(INTERP_KERNEL::Exception); static void FillInCompact3DMode(int spaceDim, int nbOfNodesInCell, const int *conn, const double *coo, double *zipFrmt) throw(INTERP_KERNEL::Exception); static void AppendExtrudedCell(const int *connBg, const int *connEnd, int nbOfNodesPerLev, bool isQuad, std::vector& ret); static void IntersectDescending2DMeshes(const MEDCouplingUMesh *m1, const MEDCouplingUMesh *m2, double eps, diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 093cf40e3..ff44fd30b 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -811,18 +811,18 @@ namespace ParaMEDMEM return ret; } - void translate(PyObject *vector) throw(INTERP_KERNEL::Exception) - { - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - int spaceDim=self->getSpaceDimension(); - const char msg[]="Python wrap of MEDCouplingPointSet::translate : "; - const double *vectorPtr=convertObjToPossibleCpp5_Safe(vector,sw,val,a,aa,bb,msg,1,spaceDim,true); - self->translate(vectorPtr); - } + void translate(PyObject *vector) throw(INTERP_KERNEL::Exception) + { + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + int spaceDim=self->getSpaceDimension(); + const char msg[]="Python wrap of MEDCouplingPointSet::translate : "; + const double *vectorPtr=convertObjToPossibleCpp5_Safe(vector,sw,val,a,aa,bb,msg,1,spaceDim,true); + self->translate(vectorPtr); + } void rotate(PyObject *center, double alpha) throw(INTERP_KERNEL::Exception) { @@ -1730,6 +1730,25 @@ namespace ParaMEDMEM PyList_SetItem(res,1,SWIG_NewPointerObj(SWIG_as_voidptr(v1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); return res; } + + PyObject *distanceToPoint(PyObject *point) const throw(INTERP_KERNEL::Exception) + { + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + int nbOfCompo=self->getSpaceDimension(); + const double *pt=convertObjToPossibleCpp5_Safe(point,sw,val,a,aa,bb,"Python wrap of MEDCouplingUMesh::distanceToPoint",1,nbOfCompo,true); + // + int cellId=-1,nodeId=-1; + double ret0=self->distanceToPoint(pt,pt+nbOfCompo,cellId,nodeId); + PyObject *ret=PyTuple_New(3); + PyTuple_SetItem(ret,0,PyFloat_FromDouble(ret0)); + PyTuple_SetItem(ret,1,PyInt_FromLong(cellId)); + PyTuple_SetItem(ret,2,PyInt_FromLong(nodeId)); + return ret; + } PyObject *mergeNodes(double precision) throw(INTERP_KERNEL::Exception) { @@ -3275,6 +3294,24 @@ namespace ParaMEDMEM return res; } + PyObject *distanceToTuple(PyObject *tuple) const throw(INTERP_KERNEL::Exception) + { + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + int tupleId=-1,nbTuples=-1,nbOfCompo=self->getNumberOfComponents(); + const double *pt=convertObjToPossibleCpp5_Safe(tuple,sw,val,a,aa,bb,"Python wrap of DataArrayDouble::distanceToTuple",1,nbOfCompo,true); + // + int cellId=-1,nodeId=-1; + double ret0=self->distanceToTuple(pt,pt+nbOfCompo,tupleId); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,PyFloat_FromDouble(ret0)); + PyTuple_SetItem(ret,1,PyInt_FromLong(tupleId)); + return ret; + } + void setSelectedComponents(const DataArrayDouble *a, PyObject *li) throw(INTERP_KERNEL::Exception) { std::vector tmp; -- 2.39.2