X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCouplingVoronoi.cxx;h=2393d5512a0a9fc3d7b25d6ab9ad7c8b26cd702c;hb=e7a9d4f59978fd384ee98db1dfdd5ec2118331ca;hp=7ec022a57539b9725ccbb90fbd0603fab3c92733;hpb=331685311f395c0b0654223c1cffddd254ed49cb;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MEDCouplingVoronoi.cxx b/src/MEDCoupling/MEDCouplingVoronoi.cxx old mode 100644 new mode 100755 index 7ec022a57..2393d5512 --- a/src/MEDCoupling/MEDCouplingVoronoi.cxx +++ b/src/MEDCoupling/MEDCouplingVoronoi.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2017 CEA/DEN, EDF R&D +// Copyright (C) 2007-2020 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 @@ -21,10 +21,34 @@ #include "MEDCouplingVoronoi.hxx" #include "MEDCoupling1GTUMesh.hxx" #include "MEDCouplingCMesh.hxx" +#include "MEDCouplingFieldDouble.hxx" #include "MCAuto.txx" +#include "MEDCouplingNormalizedUnstructuredMesh.txx" +#include "Interpolation2D.txx" +#include "Interpolation3DSurf.hxx" + using namespace MEDCoupling; +Voronizer::~Voronizer() +{ +} + +int Voronizer1D::getDimension() const +{ + return 1; +} + +int Voronizer2D::getDimension() const +{ + return 2; +} + +int Voronizer3D::getDimension() const +{ + return 3; +} + MCAuto ComputeBigCellFrom(const double pt1[2], const double pt2[2], const std::vector& bbox, double eps) { static const double FACT=1.2; @@ -51,25 +75,67 @@ MCAuto ComputeBigCellFrom(const double pt1[2], const double pt line->setCoords(coo); } line->allocateCells(); - static const int CONN[2]={0,1}; + static const mcIdType CONN[2]={0,1}; line->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,CONN); MCAuto sp2,sp1; { - DataArrayInt *cellNb1(0),*cellNb2(0); + DataArrayIdType *cellNb1(0),*cellNb2(0); MEDCouplingUMesh *sp2Pt(0),*sp1Pt(0); MEDCouplingUMesh::Intersect2DMeshWith1DLine(mu,line,eps,sp2Pt,sp1Pt,cellNb1,cellNb2); sp1=sp1Pt; sp2=sp2Pt; - MCAuto cellNb10(cellNb1),cellNb20(cellNb2); + MCAuto cellNb10(cellNb1),cellNb20(cellNb2); } - std::vector ccp; + std::vector ccp; sp2->getCellsContainingPoint(pt1,eps,ccp); if(ccp.size()!=1) throw INTERP_KERNEL::Exception("ComputeBigCellFrom : expected single element !"); MCAuto ret(sp2->buildPartOfMySelfSlice(ccp[0],ccp[0]+1,1,true)); ret->zipCoords(); + { + MCAuto tmp(ret->getMeasureField(false)); + if(tmp->getArray()->getIJ(0,0)<0) + ret->invertOrientationOfAllCells(); + } return ret; } + +MCAuto MergeVorCells2D(MEDCouplingUMesh *p, double eps, bool isZip) +{ + MCAuto edgeToKeep; + MCAuto p0; + { + MCAuto d(DataArrayIdType::New()),di(DataArrayIdType::New()),rd(DataArrayIdType::New()),rdi(DataArrayIdType::New()); + p0=p->buildDescendingConnectivity(d,di,rd,rdi); + MCAuto dsi(rdi->deltaShiftIndex()); + edgeToKeep=dsi->findIdsEqual(1); + } + MCAuto skinOfRes(p0->buildPartOfMySelf(edgeToKeep->begin(),edgeToKeep->end())); + if(isZip) + { + skinOfRes->zipCoords(); + if(ToIdType(skinOfRes->getNumberOfCells())!=skinOfRes->getNumberOfNodes()) + throw INTERP_KERNEL::Exception("MergeVorCells : result of merge looks bad !"); + } + MCAuto d(skinOfRes->orderConsecutiveCells1D()); + MCAuto skinOfRes2; + { + MCAuto part(skinOfRes->buildPartOfMySelf(d->begin(),d->end())); + skinOfRes2=MEDCoupling1SGTUMesh::New(part); + } + MCAuto c(skinOfRes2->getNodalConnectivity()->deepCopy()); + c->circularPermutation(1); + c->rearrange(2); + std::vector< MCAuto > vdi(c->explodeComponents()); + if(!vdi[0]->isEqual(*vdi[1])) + throw INTERP_KERNEL::Exception("MergeVorCells : internal error !"); + MCAuto m(MEDCouplingUMesh::New("",2)); + m->setCoords(skinOfRes2->getCoords()); + m->allocateCells(); + m->insertNextCell(INTERP_KERNEL::NORM_POLYGON,vdi[0]->getNumberOfTuples(),vdi[0]->begin()); + return m; +} + MCAuto MergeVorCells(const std::vector< MCAuto >& vcs, double eps) { std::size_t sz(vcs.size()); @@ -84,41 +150,226 @@ MCAuto MergeVorCells(const std::vector< MCAutozipCoords(); { - bool dummy; int dummy2; - MCAuto dummy3(p->mergeNodes(eps,dummy,dummy2)); + bool dummy; mcIdType dummy2; + MCAuto dummy3(p->mergeNodes(eps,dummy,dummy2)); } - MCAuto edgeToKeep; + return MergeVorCells2D(p,eps,true); +} + +/*! + * suppress additional sub points on edges + */ +MCAuto SimplifyPolygon(const MEDCouplingUMesh *m, double eps) +{ + if(m->getNumberOfCells()!=1) + throw INTERP_KERNEL::Exception("SimplifyPolygon : internal error !"); + const mcIdType *conn(m->getNodalConnectivity()->begin()),*conni(m->getNodalConnectivityIndex()->begin()); + mcIdType nbPtsInPolygon(conni[1]-conni[0]-1); + const double *coo(m->getCoords()->begin()); + std::vector resConn; + for(mcIdType i=0;ieps) + resConn.push_back(current); + } + MCAuto ret(MEDCouplingUMesh::New("",2)); + ret->setCoords(m->getCoords()); + ret->allocateCells(); + ret->insertNextCell(INTERP_KERNEL::NORM_POLYGON,ToIdType(resConn.size()),&resConn[0]); + return ret; +} + +MCAuto MergeVorCells3D(const std::vector< MCAuto >& vcs, double eps) +{ + std::size_t sz(vcs.size()); + if(sz<1) + throw INTERP_KERNEL::Exception("MergeVorCells : len of input vec expected to be >= 1 !"); + if(sz==1) + return vcs[0]; + MCAuto p; + { + std::vector< const MEDCouplingUMesh * > vcsBis(VecAutoToVecOfCstPt(vcs)); + p=MEDCouplingUMesh::MergeUMeshes(vcsBis); + } + p->zipCoords(); + { + bool dummy; mcIdType dummy2; + MCAuto dummy3(p->mergeNodes(eps,dummy,dummy2)); + } + MCAuto edgeToKeep; MCAuto p0; { - MCAuto d(DataArrayInt::New()),di(DataArrayInt::New()),rd(DataArrayInt::New()),rdi(DataArrayInt::New()); + MCAuto d(DataArrayIdType::New()),di(DataArrayIdType::New()),rd(DataArrayIdType::New()),rdi(DataArrayIdType::New()); p0=p->buildDescendingConnectivity(d,di,rd,rdi); - MCAuto dsi(rdi->deltaShiftIndex()); + MCAuto dsi(rdi->deltaShiftIndex()); edgeToKeep=dsi->findIdsEqual(1); } MCAuto skinOfRes(p0->buildPartOfMySelf(edgeToKeep->begin(),edgeToKeep->end())); - skinOfRes->zipCoords(); - if(skinOfRes->getNumberOfCells()!=skinOfRes->getNumberOfNodes()) - throw INTERP_KERNEL::Exception("MergeVorCells : result of merge looks bad !"); - MCAuto d(skinOfRes->orderConsecutiveCells1D()); - MCAuto skinOfRes2; + MCAuto eqn(skinOfRes->computePlaneEquationOf3DFaces()); + MCAuto comm,commI; { - MCAuto part(skinOfRes->buildPartOfMySelf(d->begin(),d->end())); - skinOfRes2=MEDCoupling1SGTUMesh::New(part); + DataArrayIdType *a(0),*b(0); + eqn->findCommonTuples(eps,0,a,b); + comm=a; commI=b; + //comm=DataArrayIdType::New(); comm->alloc(0,1); commI=DataArrayIdType::New(); commI->alloc(1,1); commI->setIJ(0,0,0); } - MCAuto c(skinOfRes2->getNodalConnectivity()->deepCopy()); - c->circularPermutation(1); - c->rearrange(2); - std::vector< MCAuto > vdi(c->explodeComponents()); - if(!vdi[0]->isEqual(*vdi[1])) - throw INTERP_KERNEL::Exception("MergeVorCells : internal error !"); - MCAuto m(MEDCouplingUMesh::New("",2)); - m->setCoords(skinOfRes2->getCoords()); - m->allocateCells(); - m->insertNextCell(INTERP_KERNEL::NORM_POLYGON,vdi[0]->getNumberOfTuples(),vdi[0]->begin()); - return m; + MCAuto ret(MEDCouplingUMesh::New("",3)); + ret->setCoords(skinOfRes->getCoords()); + ret->allocateCells(); + std::vector conn; + int jj(0); + for(mcIdType i=0;igetNumberOfTuples()-1;i++,jj++) + { + if(jj!=0) + conn.push_back(-1); + MCAuto tmp(skinOfRes->buildPartOfMySelf(comm->begin()+commI->getIJ(i,0),comm->begin()+commI->getIJ(i+1,0),true)); + MCAuto tmp2; + if(commI->getIJ(i+1,0)-commI->getIJ(i,0)==1) + tmp2=tmp; + else + tmp2=MergeVorCells2D(tmp,eps,false); + tmp2=SimplifyPolygon(tmp2,eps); + const mcIdType *cPtr(tmp2->getNodalConnectivity()->begin()),*ciPtr(tmp2->getNodalConnectivityIndex()->begin()); + conn.insert(conn.end(),cPtr+1,cPtr+ciPtr[1]); + } + MCAuto remain(comm->buildComplement(ToIdType(skinOfRes->getNumberOfCells()))); + { + MCAuto tmp(skinOfRes->buildPartOfMySelf(remain->begin(),remain->end(),true)); + const mcIdType *cPtr(tmp->getNodalConnectivity()->begin()),*ciPtr(tmp->getNodalConnectivityIndex()->begin()); + for(mcIdType i=0;igetNumberOfTuples();i++,jj++) + { + if(jj!=0) + conn.push_back(-1); + conn.insert(conn.end(),cPtr+ciPtr[i]+1,cPtr+ciPtr[i+1]); + } + } + ret->insertNextCell(INTERP_KERNEL::NORM_POLYHED,ToIdType(conn.size()),&conn[0]); + return ret; +} + +MCAuto MergeVorCells1D(const std::vector< MCAuto >& vcs, double eps) +{ + static const mcIdType CONN_SEG2_DFT[2]={0,1}; + if(vcs.empty()) + throw INTERP_KERNEL::Exception("MergeVorCells1D : internal error 1 !"); + if(vcs.size()==1) + return vcs[0]; + if(vcs.size()>2) + throw INTERP_KERNEL::Exception("MergeVorCells1D : internal error 2 !"); + double a0,b0,a1,b1; + { + const mcIdType *connPtr(vcs[0]->getNodalConnectivity()->begin()); + const double *coordPtr(vcs[0]->getCoords()->begin()); + a0=coordPtr[connPtr[1]]; b0=coordPtr[connPtr[2]]; + } + { + const mcIdType *connPtr(vcs[1]->getNodalConnectivity()->begin()); + const double *coordPtr(vcs[1]->getCoords()->begin()); + a1=coordPtr[connPtr[1]]; b1=coordPtr[connPtr[2]]; + } + MCAuto ret(MEDCouplingUMesh::New("",1)); ret->allocateCells(); ret->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,CONN_SEG2_DFT); + MCAuto coo(DataArrayDouble::New()); coo->alloc(2,1); ret->setCoords(coo); + if(fabs(b0-a1)setIJ(0,0,a0); coo->setIJ(1,0,b1); } + else if(fabs(b1-a0)setIJ(0,0,b0); coo->setIJ(1,0,a1); } + return ret; +} + +MCAuto MEDCoupling::Voronizer1D::doIt(const MEDCouplingUMesh *m, const DataArrayDouble *points, double eps) const +{ + static const mcIdType CONN_SEG2_DFT[2]={0,1}; + if(!m || !points) + throw INTERP_KERNEL::Exception("Voronoize1D : null pointer !"); + m->checkConsistencyLight(); + points->checkAllocated(); + if(m->getMeshDimension()!=1 || m->getSpaceDimension()!=1 || points->getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("Voronoize1D : spacedim must be equal to 1 and meshdim also equal to 1 !"); + if(m->getNumberOfCells()!=1) + throw INTERP_KERNEL::Exception("Voronoize1D : mesh is expected to have only one cell !"); + mcIdType nbPts(points->getNumberOfTuples()); + if(nbPts<1) + throw INTERP_KERNEL::Exception("Voronoize1D : at least one point expected !"); + std::vector bbox(4); + m->getBoundingBox(&bbox[0]); + std::vector< MCAuto > l0(1,MCAuto(m->deepCopy())); + const double *pts(points->begin()); + for(mcIdType i=1;i vorTess; + { + std::vector< const MEDCouplingUMesh * > l0Bis(VecAutoToVecOfCstPt(l0)); + vorTess=MEDCouplingUMesh::MergeUMeshes(l0Bis); + } + { + bool dummy; + mcIdType newNbNodes; + MCAuto dummy3(vorTess->mergeNodes(eps,dummy,newNbNodes)); + } + std::vector polygsToIterOn; + const double *pt(pts+i); + vorTess->getCellsContainingPoint(pt,eps,polygsToIterOn); + if(polygsToIterOn.empty()) + throw INTERP_KERNEL::Exception("Voronoize1D : a point is outside domain !"); + if(polygsToIterOn.size()>2) + throw INTERP_KERNEL::Exception("Voronoize1D : overlap of points !"); + std::vector< MCAuto > newVorCells; + for(std::vector::const_iterator it=polygsToIterOn.begin();it!=polygsToIterOn.end();it++) + { + mcIdType poly(*it); + // + double seed(pts[poly]),zept(*pt); + double mid((seed+zept)/2.); + // + MCAuto tile(l0[poly]); + tile->zipCoords(); + double a,b; + { + const mcIdType *connPtr(tile->getNodalConnectivity()->begin()); + const double *coordPtr(tile->getCoords()->begin()); + a=coordPtr[connPtr[1]]; b=coordPtr[connPtr[2]]; + } + double pol0[2],pol1[2]; + MCAuto t0(DataArrayDouble::New()); t0->alloc(3,1); t0->setIJ(0,0,zept); t0->setIJ(1,0,mid); t0->setIJ(2,0,seed); + t0->applyLin(1.,-a); + if(t0->isMonotonic(true,eps)) + { pol0[0]=a; pol0[1]=mid; pol1[0]=mid; pol1[1]=b; } + else + { pol1[0]=a; pol1[1]=mid; pol0[0]=mid; pol0[1]=b; } + MCAuto modifiedCell(MEDCouplingUMesh::New("",1)); modifiedCell->allocateCells(); + MCAuto coo1(DataArrayDouble::New()); coo1->alloc(2,1); coo1->setIJ(0,0,pol1[0]); coo1->setIJ(1,0,pol1[1]); + modifiedCell->setCoords(coo1); modifiedCell->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,CONN_SEG2_DFT); + // + MCAuto newVorCell(MEDCouplingUMesh::New("",1)); newVorCell->allocateCells(); + MCAuto coo2(DataArrayDouble::New()); coo2->alloc(2,1); coo2->setIJ(0,0,pol0[0]); coo2->setIJ(1,0,pol0[1]); + newVorCell->setCoords(coo2); newVorCell->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,CONN_SEG2_DFT); + // + l0[poly]=modifiedCell; + newVorCells.push_back(newVorCell); + } + l0.push_back(MergeVorCells1D(newVorCells,eps)); + } + std::vector< const MEDCouplingUMesh * > l0Bis(VecAutoToVecOfCstPt(l0)); + MCAuto ret(MEDCouplingUMesh::MergeUMeshes(l0Bis)); + { + bool dummy; mcIdType dummy2; + MCAuto dummy3(ret->mergeNodes(eps,dummy,dummy2)); + } + return ret; } -MCAuto MEDCoupling::Voronoize2D(const MEDCouplingUMesh *m, const DataArrayDouble *points, double eps) +MCAuto MEDCoupling::Voronizer2D::doIt(const MEDCouplingUMesh *m, const DataArrayDouble *points, double eps) const { if(!m || !points) throw INTERP_KERNEL::Exception("Voronoize2D : null pointer !"); @@ -128,14 +379,14 @@ MCAuto MEDCoupling::Voronoize2D(const MEDCouplingUMesh *m, con throw INTERP_KERNEL::Exception("Voronoize2D : spacedim must be equal to 2 and meshdim also equal to 2 !"); if(m->getNumberOfCells()!=1) throw INTERP_KERNEL::Exception("Voronoize2D : mesh is expected to have only one cell !"); - int nbPts(points->getNumberOfTuples()); + mcIdType nbPts(points->getNumberOfTuples()); if(nbPts<1) throw INTERP_KERNEL::Exception("Voronoize2D : at least one point expected !"); std::vector bbox(4); m->getBoundingBox(&bbox[0]); std::vector< MCAuto > l0(1,MCAuto(m->deepCopy())); const double *pts(points->begin()); - for(int i=1;i vorTess; { @@ -144,46 +395,51 @@ MCAuto MEDCoupling::Voronoize2D(const MEDCouplingUMesh *m, con } { bool dummy; - int newNbNodes; - MCAuto dummy3(vorTess->mergeNodes(eps,dummy,newNbNodes)); + mcIdType newNbNodes; + MCAuto dummy3(vorTess->mergeNodes(eps,dummy,newNbNodes)); } - std::vector polygsToIterOn; + std::vector polygsToIterOn; const double *pt(pts+i*2); vorTess->getCellsContainingPoint(pt,eps,polygsToIterOn); if(polygsToIterOn.size()<1) throw INTERP_KERNEL::Exception("Voronoize2D : presence of a point outside the given cell !"); - std::set elemsToDo,elemsDone; elemsToDo.insert(polygsToIterOn[0]); + std::set elemsToDo,elemsDone; elemsToDo.insert(polygsToIterOn[0]); std::vector< MCAuto > newVorCells; while(!elemsToDo.empty()) { - int poly(*elemsToDo.begin()); elemsToDo.erase(elemsToDo.begin()); elemsDone.insert(poly); + mcIdType poly(*elemsToDo.begin()); elemsToDo.erase(elemsToDo.begin()); elemsDone.insert(poly); const double *seed(pts+2*poly); MCAuto cell(ComputeBigCellFrom(pt,seed,bbox,eps)); MCAuto tile(l0[poly]); tile->zipCoords(); MCAuto a; - MCAuto b,c; + MCAuto b,c; { - DataArrayInt *bPtr(0),*cPtr(0); + DataArrayIdType *bPtr(0),*cPtr(0); a=MEDCouplingUMesh::Intersect2DMeshes(tile,cell,eps,bPtr,cPtr); b=bPtr; c=cPtr; } - MCAuto part(c->findIdsEqual(-1)); + MCAuto part(c->findIdsEqual(-1)); if(part->getNumberOfTuples()!=1) throw INTERP_KERNEL::Exception("Voronoize2D : internal error"); MCAuto newVorCell; { - MCAuto tmp(part->buildComplement(a->getNumberOfCells())); + MCAuto tmp(part->buildComplement(ToIdType(a->getNumberOfCells()))); newVorCell=a->buildPartOfMySelf(tmp->begin(),tmp->end()); } newVorCell->zipCoords(); MCAuto modifiedCell(a->buildPartOfMySelf(part->begin(),part->end())); modifiedCell->zipCoords(); + { + MCAuto tmp(modifiedCell->getMeasureField(false)); + if(tmp->getArray()->getIJ(0,0)<0) + modifiedCell->invertOrientationOfAllCells(); + } l0[poly]=modifiedCell; // - MCAuto ids; + MCAuto ids; { - DataArrayInt *tmp(0); + DataArrayIdType *tmp(0); bool sta(a->getCoords()->areIncludedInMe(cell->getCoords(),eps,tmp)); ids=tmp; if(!sta) @@ -191,28 +447,115 @@ MCAuto MEDCoupling::Voronoize2D(const MEDCouplingUMesh *m, con } MCAuto newCoords; { - MCAuto tmp(ids->buildComplement(a->getNumberOfNodes())); + MCAuto tmp(ids->buildComplement(a->getNumberOfNodes())); newCoords=a->getCoords()->selectByTupleId(tmp->begin(),tmp->end()); } const double *cPtr(newCoords->begin()); - for(int i=0;igetNumberOfTuples();i++,cPtr+=2) + for(mcIdType j=0;jgetNumberOfTuples();j++,cPtr+=2) { - std::set zeCandidates; + std::set zeCandidates; { - std::vector zeCandidatesTmp; + std::vector zeCandidatesTmp; vorTess->getCellsContainingPoint(cPtr,eps,zeCandidatesTmp); zeCandidates.insert(zeCandidatesTmp.begin(),zeCandidatesTmp.end()); } - std::set tmp,newElementsToDo; - std::set_difference(zeCandidates.begin(),zeCandidates.end(),elemsDone.begin(),elemsDone.end(),std::inserter(tmp,tmp.begin())); - std::set_union(elemsToDo.begin(),elemsToDo.end(),tmp.begin(),tmp.end(),std::inserter(newElementsToDo,newElementsToDo.begin())); + std::set tmp2,newElementsToDo; + std::set_difference(zeCandidates.begin(),zeCandidates.end(),elemsDone.begin(),elemsDone.end(),std::inserter(tmp2,tmp2.begin())); + std::set_union(elemsToDo.begin(),elemsToDo.end(),tmp2.begin(),tmp2.end(),std::inserter(newElementsToDo,newElementsToDo.begin())); elemsToDo=newElementsToDo; } newVorCells.push_back(newVorCell); } - l0.push_back(MergeVorCells(newVorCells,eps)); + MCAuto mergedVorCell(MergeVorCells(newVorCells,eps)); + { + MCAuto tmp(mergedVorCell->getMeasureField(false)); + if(tmp->getArray()->getIJ(0,0)<0) + mergedVorCell->invertOrientationOfAllCells(); + } + l0.push_back(mergedVorCell); } std::vector< const MEDCouplingUMesh * > l0Bis(VecAutoToVecOfCstPt(l0)); MCAuto ret(MEDCouplingUMesh::MergeUMeshes(l0Bis)); + { + bool dummy; mcIdType dummy2; + MCAuto dummy3(ret->mergeNodes(eps,dummy,dummy2)); + } + return ret; +} + +MCAuto Split3DCellInParts(const MEDCouplingUMesh *m, const double pt[3], const double seed[3], double eps, mcIdType tmp[2]) +{ + if(m->getMeshDimension()!=3 || m->getSpaceDimension()!=3 || m->getNumberOfCells()!=1) + throw INTERP_KERNEL::Exception("Split3DCellInParts : expecting a 3D with exactly one cell !"); + double middle[3]={(pt[0]+seed[0])/2.,(pt[1]+seed[1])/2.,(pt[2]+seed[2])/2.}; + double vec[3]={pt[0]-seed[0],pt[1]-seed[1],pt[2]-seed[2]}; + MCAuto res(m->clipSingle3DCellByPlane(middle,vec,eps)); + return res; +} + +MCAuto MEDCoupling::Voronizer3D::doIt(const MEDCouplingUMesh *m, const DataArrayDouble *points, double eps) const +{ + //double eps2(1.-sqrt(eps));// 2nd eps for interpolation. Here the eps is computed to feet cos(eps) ~ 1-eps^2 + if(!m || !points) + throw INTERP_KERNEL::Exception("Voronoize3D : null pointer !"); + m->checkConsistencyLight(); + points->checkAllocated(); + if(m->getMeshDimension()!=3 || m->getSpaceDimension()!=3 || points->getNumberOfComponents()!=3) + throw INTERP_KERNEL::Exception("Voronoize3D : spacedim must be equal to 3 and meshdim also equal to 3 !"); + if(m->getNumberOfCells()!=1) + throw INTERP_KERNEL::Exception("Voronoize3D : mesh is expected to have only one cell !"); + mcIdType nbPts(points->getNumberOfTuples()); + if(nbPts<1) + throw INTERP_KERNEL::Exception("Voronoize3D : at least one point expected !"); + std::vector< MCAuto > l0(1,MCAuto(m->deepCopy())); + const double *pts(points->begin()); + for(mcIdType i=1;i vorTess; + { + std::vector< const MEDCouplingUMesh * > l0Bis(VecAutoToVecOfCstPt(l0)); + vorTess=MEDCouplingUMesh::MergeUMeshes(l0Bis); + } + { + bool dummy; + mcIdType newNbNodes; + MCAuto dummy3(vorTess->mergeNodes(eps,dummy,newNbNodes)); + } + std::vector polygsToIterOn; + const double *pt(pts+i*3); + vorTess->getCellsContainingPoint(pt,eps,polygsToIterOn); + if(polygsToIterOn.size()<1) + throw INTERP_KERNEL::Exception("Voronoize3D : presence of a point outside the given cell !"); + std::vector< MCAuto > newVorCells; + for(mcIdType poly=0;polygetNumberOfCells());poly++) + { + const double *seed(pts+3*poly); + MCAuto tile(l0[poly]); + tile->zipCoords(); + mcIdType tmp[2]; + MCAuto cells; + try + { + cells=Split3DCellInParts(tile,pt,seed,eps,tmp); + } + catch(INTERP_KERNEL::Exception&) + { + continue; + } + MCAuto newVorCell(cells->buildPartOfMySelfSlice(1,2,1,true)); + newVorCell->zipCoords(); + MCAuto modifiedCell(cells->buildPartOfMySelfSlice(0,1,1,true)); + modifiedCell->zipCoords(); + newVorCells.push_back(newVorCell); + l0[poly]=modifiedCell; + } + l0.push_back(MergeVorCells3D(newVorCells,eps)); + } + std::vector< const MEDCouplingUMesh * > l0Bis(VecAutoToVecOfCstPt(l0)); + MCAuto ret(MEDCouplingUMesh::MergeUMeshes(l0Bis)); + { + bool dummy; mcIdType dummy2; + MCAuto dummy3(ret->mergeNodes(eps,dummy,dummy2)); + } return ret; }