1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #include "MEDCouplingUMesh.hxx"
22 #include "MEDCouplingCMesh.hxx"
23 #include "MEDCoupling1GTUMesh.hxx"
24 #include "MEDCouplingFieldDouble.hxx"
25 #include "MEDCouplingSkyLineArray.hxx"
26 #include "CellModel.hxx"
27 #include "VolSurfUser.txx"
28 #include "InterpolationUtils.hxx"
29 #include "PointLocatorAlgos.txx"
31 #include "BBTreeDst.txx"
32 #include "SplitterTetra.hxx"
33 #include "DiameterCalculator.hxx"
34 #include "DirectedBoundingBox.hxx"
35 #include "InterpKernelMatrixTools.hxx"
36 #include "InterpKernelMeshQuality.hxx"
37 #include "InterpKernelCellSimplify.hxx"
38 #include "InterpKernelGeo2DEdgeArcCircle.hxx"
39 #include "InterpKernelAutoPtr.hxx"
40 #include "InterpKernelGeo2DNode.hxx"
41 #include "InterpKernelGeo2DEdgeLin.hxx"
42 #include "InterpKernelGeo2DEdgeArcCircle.hxx"
43 #include "InterpKernelGeo2DQuadraticPolygon.hxx"
44 #include "MEDCouplingUMesh_internal.hxx"
53 using namespace MEDCoupling;
56 * This method checks that all arrays are set. If yes nothing done if no an exception is thrown.
58 void MEDCouplingUMesh::checkFullyDefined() const
60 if(!_nodal_connec_index || !_nodal_connec || !_coords)
61 throw INTERP_KERNEL::Exception("Reverse nodal connectivity computation requires full connectivity and coordinates set in unstructured mesh.");
65 * This method checks that all connectivity arrays are set. If yes nothing done if no an exception is thrown.
67 void MEDCouplingUMesh::checkConnectivityFullyDefined() const
69 if(!_nodal_connec_index || !_nodal_connec)
70 throw INTERP_KERNEL::Exception("Reverse nodal connectivity computation requires full connectivity set in unstructured mesh.");
73 void MEDCouplingUMesh::reprConnectivityOfThisLL(std::ostringstream& stream) const
75 if(_nodal_connec!=0 && _nodal_connec_index!=0)
77 int nbOfCells=getNumberOfCells();
78 const int *c=_nodal_connec->getConstPointer();
79 const int *ci=_nodal_connec_index->getConstPointer();
80 for(int i=0;i<nbOfCells;i++)
82 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel((INTERP_KERNEL::NormalizedCellType)c[ci[i]]);
83 stream << "Cell #" << i << " " << cm.getRepr() << " : ";
84 std::copy(c+ci[i]+1,c+ci[i+1],std::ostream_iterator<int>(stream," "));
89 stream << "Connectivity not defined !\n";
94 * This method implements policy 0 of virtual method MEDCoupling::MEDCouplingUMesh::simplexize.
96 DataArrayInt *MEDCouplingUMesh::simplexizePol0()
98 checkConnectivityFullyDefined();
99 if(getMeshDimension()!=2)
100 throw INTERP_KERNEL::Exception("MEDCouplingUMesh::simplexizePol0 : this policy is only available for mesh with meshdim == 2 !");
101 int nbOfCells=getNumberOfCells();
102 MCAuto<DataArrayInt> ret=DataArrayInt::New();
103 int nbOfCutCells=getNumberOfCellsWithType(INTERP_KERNEL::NORM_QUAD4);
104 ret->alloc(nbOfCells+nbOfCutCells,1);
105 if(nbOfCutCells==0) { ret->iota(0); return ret.retn(); }
106 int *retPt=ret->getPointer();
107 MCAuto<DataArrayInt> newConn=DataArrayInt::New();
108 MCAuto<DataArrayInt> newConnI=DataArrayInt::New();
109 newConnI->alloc(nbOfCells+nbOfCutCells+1,1);
110 newConn->alloc(getNodalConnectivityArrayLen()+3*nbOfCutCells,1);
111 int *pt=newConn->getPointer();
112 int *ptI=newConnI->getPointer();
114 const int *oldc=_nodal_connec->begin();
115 const int *ci=_nodal_connec_index->begin();
116 for(int i=0;i<nbOfCells;i++,ci++)
118 if((INTERP_KERNEL::NormalizedCellType)oldc[ci[0]]==INTERP_KERNEL::NORM_QUAD4)
120 const int tmp[8]={(int)INTERP_KERNEL::NORM_TRI3,oldc[ci[0]+1],oldc[ci[0]+2],oldc[ci[0]+3],
121 (int)INTERP_KERNEL::NORM_TRI3,oldc[ci[0]+1],oldc[ci[0]+3],oldc[ci[0]+4]};
122 pt=std::copy(tmp,tmp+8,pt);
131 pt=std::copy(oldc+ci[0],oldc+ci[1],pt);
132 ptI[1]=ptI[0]+ci[1]-ci[0];
137 _nodal_connec->decrRef();
138 _nodal_connec=newConn.retn();
139 _nodal_connec_index->decrRef();
140 _nodal_connec_index=newConnI.retn();
147 * This method implements policy 1 of virtual method MEDCoupling::MEDCouplingUMesh::simplexize.
149 DataArrayInt *MEDCouplingUMesh::simplexizePol1()
151 checkConnectivityFullyDefined();
152 if(getMeshDimension()!=2)
153 throw INTERP_KERNEL::Exception("MEDCouplingUMesh::simplexizePol0 : this policy is only available for mesh with meshdim == 2 !");
154 int nbOfCells=getNumberOfCells();
155 MCAuto<DataArrayInt> ret=DataArrayInt::New();
156 int nbOfCutCells=getNumberOfCellsWithType(INTERP_KERNEL::NORM_QUAD4);
157 ret->alloc(nbOfCells+nbOfCutCells,1);
158 if(nbOfCutCells==0) { ret->iota(0); return ret.retn(); }
159 int *retPt=ret->getPointer();
160 MCAuto<DataArrayInt> newConn=DataArrayInt::New();
161 MCAuto<DataArrayInt> newConnI=DataArrayInt::New();
162 newConnI->alloc(nbOfCells+nbOfCutCells+1,1);
163 newConn->alloc(getNodalConnectivityArrayLen()+3*nbOfCutCells,1);
164 int *pt=newConn->getPointer();
165 int *ptI=newConnI->getPointer();
167 const int *oldc=_nodal_connec->begin();
168 const int *ci=_nodal_connec_index->begin();
169 for(int i=0;i<nbOfCells;i++,ci++)
171 if((INTERP_KERNEL::NormalizedCellType)oldc[ci[0]]==INTERP_KERNEL::NORM_QUAD4)
173 const int tmp[8]={(int)INTERP_KERNEL::NORM_TRI3,oldc[ci[0]+1],oldc[ci[0]+2],oldc[ci[0]+4],
174 (int)INTERP_KERNEL::NORM_TRI3,oldc[ci[0]+2],oldc[ci[0]+3],oldc[ci[0]+4]};
175 pt=std::copy(tmp,tmp+8,pt);
184 pt=std::copy(oldc+ci[0],oldc+ci[1],pt);
185 ptI[1]=ptI[0]+ci[1]-ci[0];
190 _nodal_connec->decrRef();
191 _nodal_connec=newConn.retn();
192 _nodal_connec_index->decrRef();
193 _nodal_connec_index=newConnI.retn();
200 * This method implements policy INTERP_KERNEL::PLANAR_FACE_5 of virtual method MEDCoupling::MEDCouplingUMesh::simplexize.
202 DataArrayInt *MEDCouplingUMesh::simplexizePlanarFace5()
204 checkConnectivityFullyDefined();
205 if(getMeshDimension()!=3)
206 throw INTERP_KERNEL::Exception("MEDCouplingUMesh::simplexizePlanarFace5 : this policy is only available for mesh with meshdim == 3 !");
207 int nbOfCells=getNumberOfCells();
208 MCAuto<DataArrayInt> ret=DataArrayInt::New();
209 int nbOfCutCells=getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8);
210 ret->alloc(nbOfCells+4*nbOfCutCells,1);
211 if(nbOfCutCells==0) { ret->iota(0); return ret.retn(); }
212 int *retPt=ret->getPointer();
213 MCAuto<DataArrayInt> newConn=DataArrayInt::New();
214 MCAuto<DataArrayInt> newConnI=DataArrayInt::New();
215 newConnI->alloc(nbOfCells+4*nbOfCutCells+1,1);
216 newConn->alloc(getNodalConnectivityArrayLen()+16*nbOfCutCells,1);//21
217 int *pt=newConn->getPointer();
218 int *ptI=newConnI->getPointer();
220 const int *oldc=_nodal_connec->begin();
221 const int *ci=_nodal_connec_index->begin();
222 for(int i=0;i<nbOfCells;i++,ci++)
224 if((INTERP_KERNEL::NormalizedCellType)oldc[ci[0]]==INTERP_KERNEL::NORM_HEXA8)
226 for(int j=0;j<5;j++,pt+=5,ptI++)
228 pt[0]=(int)INTERP_KERNEL::NORM_TETRA4;
229 pt[1]=oldc[ci[0]+INTERP_KERNEL::SPLIT_NODES_5_WO[4*j+0]+1]; pt[2]=oldc[ci[0]+INTERP_KERNEL::SPLIT_NODES_5_WO[4*j+1]+1]; pt[3]=oldc[ci[0]+INTERP_KERNEL::SPLIT_NODES_5_WO[4*j+2]+1]; pt[4]=oldc[ci[0]+INTERP_KERNEL::SPLIT_NODES_5_WO[4*j+3]+1];
236 pt=std::copy(oldc+ci[0],oldc+ci[1],pt);
237 ptI[1]=ptI[0]+ci[1]-ci[0];
242 _nodal_connec->decrRef();
243 _nodal_connec=newConn.retn();
244 _nodal_connec_index->decrRef();
245 _nodal_connec_index=newConnI.retn();
252 * This method implements policy INTERP_KERNEL::PLANAR_FACE_6 of virtual method MEDCoupling::MEDCouplingUMesh::simplexize.
254 DataArrayInt *MEDCouplingUMesh::simplexizePlanarFace6()
256 checkConnectivityFullyDefined();
257 if(getMeshDimension()!=3)
258 throw INTERP_KERNEL::Exception("MEDCouplingUMesh::simplexizePlanarFace6 : this policy is only available for mesh with meshdim == 3 !");
259 int nbOfCells=getNumberOfCells();
260 MCAuto<DataArrayInt> ret=DataArrayInt::New();
261 int nbOfCutCells=getNumberOfCellsWithType(INTERP_KERNEL::NORM_HEXA8);
262 ret->alloc(nbOfCells+5*nbOfCutCells,1);
263 if(nbOfCutCells==0) { ret->iota(0); return ret.retn(); }
264 int *retPt=ret->getPointer();
265 MCAuto<DataArrayInt> newConn=DataArrayInt::New();
266 MCAuto<DataArrayInt> newConnI=DataArrayInt::New();
267 newConnI->alloc(nbOfCells+5*nbOfCutCells+1,1);
268 newConn->alloc(getNodalConnectivityArrayLen()+21*nbOfCutCells,1);
269 int *pt=newConn->getPointer();
270 int *ptI=newConnI->getPointer();
272 const int *oldc=_nodal_connec->begin();
273 const int *ci=_nodal_connec_index->begin();
274 for(int i=0;i<nbOfCells;i++,ci++)
276 if((INTERP_KERNEL::NormalizedCellType)oldc[ci[0]]==INTERP_KERNEL::NORM_HEXA8)
278 for(int j=0;j<6;j++,pt+=5,ptI++)
280 pt[0]=(int)INTERP_KERNEL::NORM_TETRA4;
281 pt[1]=oldc[ci[0]+INTERP_KERNEL::SPLIT_NODES_6_WO[4*j+0]+1]; pt[2]=oldc[ci[0]+INTERP_KERNEL::SPLIT_NODES_6_WO[4*j+1]+1]; pt[3]=oldc[ci[0]+INTERP_KERNEL::SPLIT_NODES_6_WO[4*j+2]+1]; pt[4]=oldc[ci[0]+INTERP_KERNEL::SPLIT_NODES_6_WO[4*j+3]+1];
288 pt=std::copy(oldc+ci[0],oldc+ci[1],pt);
289 ptI[1]=ptI[0]+ci[1]-ci[0];
294 _nodal_connec->decrRef();
295 _nodal_connec=newConn.retn();
296 _nodal_connec_index->decrRef();
297 _nodal_connec_index=newConnI.retn();
304 * Tessellates \a this 2D mesh by dividing not straight edges of quadratic faces,
305 * so that the number of cells remains the same. Quadratic faces are converted to
306 * polygons. This method works only for 2D meshes in
307 * 2D space. If no cells are quadratic (INTERP_KERNEL::NORM_QUAD8,
308 * INTERP_KERNEL::NORM_TRI6, INTERP_KERNEL::NORM_QPOLYG ), \a this mesh remains unchanged.
309 * \warning This method can lead to a huge amount of nodes if \a eps is very low.
310 * \param [in] eps - specifies the maximal angle (in radians) between 2 sub-edges of
311 * a polylinized edge constituting the input polygon.
312 * \throw If the coordinates array is not set.
313 * \throw If the nodal connectivity of cells is not defined.
314 * \throw If \a this->getMeshDimension() != 2.
315 * \throw If \a this->getSpaceDimension() != 2.
317 void MEDCouplingUMesh::tessellate2DInternal(double eps)
320 if(getMeshDimension()!=2 || getSpaceDimension()!=2)
321 throw INTERP_KERNEL::Exception("MEDCouplingUMesh::tessellate2DInternal works on umeshes with meshdim equal to 2 and spaceDim equal to 2 too!");
322 double epsa=fabs(eps);
323 if(epsa<std::numeric_limits<double>::min())
324 throw INTERP_KERNEL::Exception("MEDCouplingUMesh::tessellate2DInternal : epsilon is null ! Please specify a higher epsilon. If too tiny it can lead to a huge amount of nodes and memory !");
325 MCAuto<DataArrayInt> desc1(DataArrayInt::New()),descIndx1(DataArrayInt::New()),revDesc1(DataArrayInt::New()),revDescIndx1(DataArrayInt::New());
326 MCAuto<MEDCouplingUMesh> mDesc(buildDescendingConnectivity2(desc1,descIndx1,revDesc1,revDescIndx1));
327 revDesc1=0; revDescIndx1=0;
328 mDesc->tessellate2D(eps);
329 subDivide2DMesh(mDesc->_nodal_connec->begin(),mDesc->_nodal_connec_index->begin(),desc1->begin(),descIndx1->begin());
330 setCoords(mDesc->getCoords());
334 * Tessellates \a this 1D mesh in 2D space by dividing not straight quadratic edges.
335 * \warning This method can lead to a huge amount of nodes if \a eps is very low.
336 * \param [in] eps - specifies the maximal angle (in radian) between 2 sub-edges of
337 * a sub-divided edge.
338 * \throw If the coordinates array is not set.
339 * \throw If the nodal connectivity of cells is not defined.
340 * \throw If \a this->getMeshDimension() != 1.
341 * \throw If \a this->getSpaceDimension() != 2.
343 void MEDCouplingUMesh::tessellate2DCurveInternal(double eps)
346 if(getMeshDimension()!=1 || getSpaceDimension()!=2)
347 throw INTERP_KERNEL::Exception("MEDCouplingUMesh::tessellate2DCurveInternal works on umeshes with meshdim equal to 1 and spaceDim equal to 2 too!");
348 double epsa=fabs(eps);
349 if(epsa<std::numeric_limits<double>::min())
350 throw INTERP_KERNEL::Exception("MEDCouplingUMesh::tessellate2DCurveInternal : epsilon is null ! Please specify a higher epsilon. If too tiny it can lead to a huge amount of nodes and memory !");
351 INTERP_KERNEL::QUADRATIC_PLANAR::_arc_detection_precision=1.e-10;
352 int nbCells=getNumberOfCells();
353 int nbNodes=getNumberOfNodes();
354 const int *conn=_nodal_connec->begin();
355 const int *connI=_nodal_connec_index->begin();
356 const double *coords=_coords->begin();
357 std::vector<double> addCoo;
358 std::vector<int> newConn;//no direct DataArrayInt because interface with Geometric2D
359 MCAuto<DataArrayInt> newConnI(DataArrayInt::New());
360 newConnI->alloc(nbCells+1,1);
361 int *newConnIPtr=newConnI->getPointer();
364 INTERP_KERNEL::Node *tmp2[3];
365 std::set<INTERP_KERNEL::NormalizedCellType> types;
366 for(int i=0;i<nbCells;i++,newConnIPtr++)
368 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel((INTERP_KERNEL::NormalizedCellType)conn[connI[i]]);
370 {//assert(connI[i+1]-connI[i]-1==3)
371 tmp1[0]=conn[connI[i]+1+0]; tmp1[1]=conn[connI[i]+1+1]; tmp1[2]=conn[connI[i]+1+2];
372 tmp2[0]=new INTERP_KERNEL::Node(coords[2*tmp1[0]],coords[2*tmp1[0]+1]);
373 tmp2[1]=new INTERP_KERNEL::Node(coords[2*tmp1[1]],coords[2*tmp1[1]+1]);
374 tmp2[2]=new INTERP_KERNEL::Node(coords[2*tmp1[2]],coords[2*tmp1[2]+1]);
375 INTERP_KERNEL::EdgeArcCircle *eac=INTERP_KERNEL::EdgeArcCircle::BuildFromNodes(tmp2[0],tmp2[2],tmp2[1]);
378 eac->tesselate(tmp1,nbNodes,epsa,newConn,addCoo);
379 types.insert((INTERP_KERNEL::NormalizedCellType)newConn[newConnIPtr[0]]);
381 newConnIPtr[1]=(int)newConn.size();
385 types.insert(INTERP_KERNEL::NORM_SEG2);
386 newConn.push_back(INTERP_KERNEL::NORM_SEG2);
387 newConn.insert(newConn.end(),conn+connI[i]+1,conn+connI[i]+3);
388 newConnIPtr[1]=newConnIPtr[0]+3;
393 types.insert((INTERP_KERNEL::NormalizedCellType)conn[connI[i]]);
394 newConn.insert(newConn.end(),conn+connI[i],conn+connI[i+1]);
395 newConnIPtr[1]=newConnIPtr[0]+3;
398 if(addCoo.empty() && newConn.size()==_nodal_connec->getNumberOfTuples())//nothing happens during tessellation : no update needed
401 DataArrayInt::SetArrayIn(newConnI,_nodal_connec_index);
402 MCAuto<DataArrayInt> newConnArr=DataArrayInt::New();
403 newConnArr->alloc((int)newConn.size(),1);
404 std::copy(newConn.begin(),newConn.end(),newConnArr->getPointer());
405 DataArrayInt::SetArrayIn(newConnArr,_nodal_connec);
406 MCAuto<DataArrayDouble> newCoords=DataArrayDouble::New();
407 newCoords->alloc(nbNodes+((int)addCoo.size())/2,2);
408 double *work=std::copy(_coords->begin(),_coords->end(),newCoords->getPointer());
409 std::copy(addCoo.begin(),addCoo.end(),work);
410 DataArrayDouble::SetArrayIn(newCoords,_coords);
416 * This private method is used to subdivide edges of a mesh with meshdim==2. If \a this has no a meshdim equal to 2 an exception will be thrown.
417 * This method completly ignore coordinates.
418 * \param nodeSubdived is the nodal connectivity of subdivision of edges
419 * \param nodeIndxSubdived is the nodal connectivity index of subdivision of edges
420 * \param desc is descending connectivity in format specified in MEDCouplingUMesh::buildDescendingConnectivity2
421 * \param descIndex is descending connectivity index in format specified in MEDCouplingUMesh::buildDescendingConnectivity2
423 void MEDCouplingUMesh::subDivide2DMesh(const int *nodeSubdived, const int *nodeIndxSubdived, const int *desc, const int *descIndex)
426 if(getMeshDimension()!=2)
427 throw INTERP_KERNEL::Exception("MEDCouplingUMesh::subDivide2DMesh : works only on umesh with meshdim==2 !");
428 int nbOfCells=getNumberOfCells();
429 int *connI=_nodal_connec_index->getPointer();
431 for(int i=0;i<nbOfCells;i++,connI++)
433 int offset=descIndex[i];
434 int nbOfEdges=descIndex[i+1]-offset;
436 bool ddirect=desc[offset+nbOfEdges-1]>0;
437 int eedgeId=std::abs(desc[offset+nbOfEdges-1])-1;
438 int ref=ddirect?nodeSubdived[nodeIndxSubdived[eedgeId+1]-1]:nodeSubdived[nodeIndxSubdived[eedgeId]+1];
439 for(int j=0;j<nbOfEdges;j++)
441 bool direct=desc[offset+j]>0;
442 int edgeId=std::abs(desc[offset+j])-1;
443 if(!INTERP_KERNEL::CellModel::GetCellModel((INTERP_KERNEL::NormalizedCellType)nodeSubdived[nodeIndxSubdived[edgeId]]).isQuadratic())
445 int id1=nodeSubdived[nodeIndxSubdived[edgeId]+1];
446 int id2=nodeSubdived[nodeIndxSubdived[edgeId+1]-1];
447 int ref2=direct?id1:id2;
450 int nbOfSubNodes=nodeIndxSubdived[edgeId+1]-nodeIndxSubdived[edgeId]-1;
451 newConnLgth+=nbOfSubNodes-1;
456 std::ostringstream oss; oss << "MEDCouplingUMesh::subDivide2DMesh : On polygon #" << i << " edgeid #" << j << " subedges mismatch : end subedge k!=start subedge k+1 !";
457 throw INTERP_KERNEL::Exception(oss.str());
462 throw INTERP_KERNEL::Exception("MEDCouplingUMesh::subDivide2DMesh : this method only subdivides into linear edges !");
465 newConnLgth++;//+1 is for cell type
466 connI[1]=newConnLgth;
469 MCAuto<DataArrayInt> newConn=DataArrayInt::New();
470 newConn->alloc(newConnLgth,1);
471 int *work=newConn->getPointer();
472 for(int i=0;i<nbOfCells;i++)
474 *work++=INTERP_KERNEL::NORM_POLYGON;
475 int offset=descIndex[i];
476 int nbOfEdges=descIndex[i+1]-offset;
477 for(int j=0;j<nbOfEdges;j++)
479 bool direct=desc[offset+j]>0;
480 int edgeId=std::abs(desc[offset+j])-1;
482 work=std::copy(nodeSubdived+nodeIndxSubdived[edgeId]+1,nodeSubdived+nodeIndxSubdived[edgeId+1]-1,work);
485 int nbOfSubNodes=nodeIndxSubdived[edgeId+1]-nodeIndxSubdived[edgeId]-1;
486 std::reverse_iterator<const int *> it(nodeSubdived+nodeIndxSubdived[edgeId+1]);
487 work=std::copy(it,it+nbOfSubNodes-1,work);
491 DataArrayInt::SetArrayIn(newConn,_nodal_connec);
494 _types.insert(INTERP_KERNEL::NORM_POLYGON);
498 * Keeps from \a this only cells which constituing point id are in the ids specified by [ \a begin,\a end ).
499 * The resulting cell ids are stored at the end of the 'cellIdsKept' parameter.
500 * Parameter \a fullyIn specifies if a cell that has part of its nodes in ids array is kept or not.
501 * If \a fullyIn is true only cells whose ids are \b fully contained in [ \a begin,\a end ) tab will be kept.
503 * \param [in] begin input start of array of node ids.
504 * \param [in] end input end of array of node ids.
505 * \param [in] fullyIn input that specifies if all node ids must be in [ \a begin,\a end ) array to consider cell to be in.
506 * \param [in,out] cellIdsKeptArr array where all candidate cell ids are put at the end.
508 void MEDCouplingUMesh::fillCellIdsToKeepFromNodeIds(const int *begin, const int *end, bool fullyIn, DataArrayInt *&cellIdsKeptArr) const
510 MCAuto<DataArrayInt> cellIdsKept=DataArrayInt::New(); cellIdsKept->alloc(0,1);
511 checkConnectivityFullyDefined();
513 int sz=getNodalConnectivity()->getMaxValue(tmp); sz=std::max(sz,0)+1;
514 std::vector<bool> fastFinder(sz,false);
515 for(const int *work=begin;work!=end;work++)
516 if(*work>=0 && *work<sz)
517 fastFinder[*work]=true;
518 int nbOfCells=getNumberOfCells();
519 const int *conn=getNodalConnectivity()->getConstPointer();
520 const int *connIndex=getNodalConnectivityIndex()->getConstPointer();
521 for(int i=0;i<nbOfCells;i++)
524 for(const int *work2=conn+connIndex[i]+1;work2!=conn+connIndex[i+1];work2++)
528 if(fastFinder[*work2])
531 if((ref==nbOfHit && fullyIn) || (nbOfHit!=0 && !fullyIn))
532 cellIdsKept->pushBackSilent(i);
534 cellIdsKeptArr=cellIdsKept.retn();
538 * This method works on a 3D curve linear mesh that is to say (meshDim==1 and spaceDim==3).
539 * If it is not the case an exception will be thrown.
540 * This method is non const because the coordinate of \a this can be appended with some new points issued from
541 * intersection of plane defined by ('origin','vec').
542 * This method has one in/out parameter : 'cut3DCurve'.
543 * Param 'cut3DCurve' is expected to be of size 'this->getNumberOfCells()'. For each i in [0,'this->getNumberOfCells()')
544 * if cut3DCurve[i]==-2, it means that for cell #i in \a this nothing has been detected previously.
545 * if cut3DCurve[i]==-1, it means that cell#i has been already detected to be fully part of plane defined by ('origin','vec').
546 * This method will throw an exception if \a this contains a non linear segment.
548 void MEDCouplingUMesh::split3DCurveWithPlane(const double *origin, const double *vec, double eps, std::vector<int>& cut3DCurve)
551 if(getMeshDimension()!=1 || getSpaceDimension()!=3)
552 throw INTERP_KERNEL::Exception("MEDCouplingUMesh::split3DCurveWithPlane works on umeshes with meshdim equal to 1 and spaceDim equal to 3 !");
553 int ncells=getNumberOfCells();
554 int nnodes=getNumberOfNodes();
555 double vec2[3],vec3[3],vec4[3];
556 double normm=sqrt(vec[0]*vec[0]+vec[1]*vec[1]+vec[2]*vec[2]);
558 throw INTERP_KERNEL::Exception("MEDCouplingUMesh::split3DCurveWithPlane : parameter 'vec' should have a norm2 greater than 1e-6 !");
559 vec2[0]=vec[0]/normm; vec2[1]=vec[1]/normm; vec2[2]=vec[2]/normm;
560 const int *conn=_nodal_connec->getConstPointer();
561 const int *connI=_nodal_connec_index->getConstPointer();
562 const double *coo=_coords->getConstPointer();
563 std::vector<double> addCoo;
564 for(int i=0;i<ncells;i++)
566 if(conn[connI[i]]==(int)INTERP_KERNEL::NORM_SEG2)
568 if(cut3DCurve[i]==-2)
570 int st=conn[connI[i]+1],endd=conn[connI[i]+2];
571 vec3[0]=coo[3*endd]-coo[3*st]; vec3[1]=coo[3*endd+1]-coo[3*st+1]; vec3[2]=coo[3*endd+2]-coo[3*st+2];
572 double normm2=sqrt(vec3[0]*vec3[0]+vec3[1]*vec3[1]+vec3[2]*vec3[2]);
573 double colin=std::abs((vec3[0]*vec2[0]+vec3[1]*vec2[1]+vec3[2]*vec2[2])/normm2);
574 if(colin>eps)//if colin<=eps -> current SEG2 is colinear to the input plane
576 const double *st2=coo+3*st;
577 vec4[0]=st2[0]-origin[0]; vec4[1]=st2[1]-origin[1]; vec4[2]=st2[2]-origin[2];
578 double pos=-(vec4[0]*vec2[0]+vec4[1]*vec2[1]+vec4[2]*vec2[2])/((vec3[0]*vec2[0]+vec3[1]*vec2[1]+vec3[2]*vec2[2]));
579 if(pos>eps && pos<1-eps)
581 int nNode=((int)addCoo.size())/3;
582 vec4[0]=st2[0]+pos*vec3[0]; vec4[1]=st2[1]+pos*vec3[1]; vec4[2]=st2[2]+pos*vec3[2];
583 addCoo.insert(addCoo.end(),vec4,vec4+3);
584 cut3DCurve[i]=nnodes+nNode;
590 throw INTERP_KERNEL::Exception("MEDCouplingUMesh::split3DCurveWithPlane : this method is only available for linear cell (NORM_SEG2) !");
594 int newNbOfNodes=nnodes+((int)addCoo.size())/3;
595 MCAuto<DataArrayDouble> coo2=DataArrayDouble::New();
596 coo2->alloc(newNbOfNodes,3);
597 double *tmp=coo2->getPointer();
598 tmp=std::copy(_coords->begin(),_coords->end(),tmp);
599 std::copy(addCoo.begin(),addCoo.end(),tmp);
600 DataArrayDouble::SetArrayIn(coo2,_coords);
605 * This method incarnates the policy 0 for MEDCouplingUMesh::buildExtrudedMesh method.
606 * \param mesh1D is the input 1D mesh used for translation computation.
607 * \return newCoords new coords filled by this method.
609 DataArrayDouble *MEDCouplingUMesh::fillExtCoordsUsingTranslation(const MEDCouplingUMesh *mesh1D, bool isQuad) const
611 int oldNbOfNodes=getNumberOfNodes();
612 int nbOf1DCells=mesh1D->getNumberOfCells();
613 int spaceDim=getSpaceDimension();
614 DataArrayDouble *ret=DataArrayDouble::New();
615 std::vector<bool> isQuads;
616 int nbOfLevsInVec=isQuad?2*nbOf1DCells+1:nbOf1DCells+1;
617 ret->alloc(oldNbOfNodes*nbOfLevsInVec,spaceDim);
618 double *retPtr=ret->getPointer();
619 const double *coords=getCoords()->getConstPointer();
620 double *work=std::copy(coords,coords+spaceDim*oldNbOfNodes,retPtr);
622 std::vector<double> c;
626 for(int i=0;i<nbOf1DCells;i++)
629 mesh1D->getNodeIdsOfCell(i,v);
631 mesh1D->getCoordinatesOfNode(v[isQuad?2:1],c);
632 mesh1D->getCoordinatesOfNode(v[0],c);
633 std::transform(c.begin(),c.begin()+spaceDim,c.begin()+spaceDim,vec,std::minus<double>());
634 for(int j=0;j<oldNbOfNodes;j++)
635 work=std::transform(vec,vec+spaceDim,retPtr+spaceDim*(i*oldNbOfNodes+j),work,std::plus<double>());
639 mesh1D->getCoordinatesOfNode(v[1],c);
640 mesh1D->getCoordinatesOfNode(v[0],c);
641 std::transform(c.begin(),c.begin()+spaceDim,c.begin()+spaceDim,vec,std::minus<double>());
642 for(int j=0;j<oldNbOfNodes;j++)
643 work=std::transform(vec,vec+spaceDim,retPtr+spaceDim*(i*oldNbOfNodes+j),work,std::plus<double>());
646 ret->copyStringInfoFrom(*getCoords());
651 * This method incarnates the policy 1 for MEDCouplingUMesh::buildExtrudedMesh method.
652 * \param mesh1D is the input 1D mesh used for translation and automatic rotation computation.
653 * \return newCoords new coords filled by this method.
655 DataArrayDouble *MEDCouplingUMesh::fillExtCoordsUsingTranslAndAutoRotation(const MEDCouplingUMesh *mesh1D, bool isQuad) const
657 if(mesh1D->getSpaceDimension()==2)
658 return fillExtCoordsUsingTranslAndAutoRotation2D(mesh1D,isQuad);
659 if(mesh1D->getSpaceDimension()==3)
660 return fillExtCoordsUsingTranslAndAutoRotation3D(mesh1D,isQuad);
661 throw INTERP_KERNEL::Exception("Not implemented rotation and translation alg. for spacedim other than 2 and 3 !");
665 * This method incarnates the policy 1 for MEDCouplingUMesh::buildExtrudedMesh method.
666 * \param mesh1D is the input 1D mesh used for translation and automatic rotation computation.
667 * \return newCoords new coords filled by this method.
669 DataArrayDouble *MEDCouplingUMesh::fillExtCoordsUsingTranslAndAutoRotation2D(const MEDCouplingUMesh *mesh1D, bool isQuad) const
672 throw INTERP_KERNEL::Exception("MEDCouplingUMesh::fillExtCoordsUsingTranslAndAutoRotation2D : not implemented for quadratic cells !");
673 int oldNbOfNodes=getNumberOfNodes();
674 int nbOf1DCells=mesh1D->getNumberOfCells();
676 throw INTERP_KERNEL::Exception("MEDCouplingUMesh::fillExtCoordsUsingTranslAndAutoRotation2D : impossible to detect any angle of rotation ! Change extrusion policy 1->0 !");
677 MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
678 int nbOfLevsInVec=nbOf1DCells+1;
679 ret->alloc(oldNbOfNodes*nbOfLevsInVec,2);
680 double *retPtr=ret->getPointer();
681 retPtr=std::copy(getCoords()->getConstPointer(),getCoords()->getConstPointer()+getCoords()->getNbOfElems(),retPtr);
682 MCAuto<MEDCouplingUMesh> tmp=MEDCouplingUMesh::New();
683 MCAuto<DataArrayDouble> tmp2=getCoords()->deepCopy();
684 tmp->setCoords(tmp2);
685 const double *coo1D=mesh1D->getCoords()->getConstPointer();
686 const int *conn1D=mesh1D->getNodalConnectivity()->getConstPointer();
687 const int *connI1D=mesh1D->getNodalConnectivityIndex()->getConstPointer();
688 for(int i=1;i<nbOfLevsInVec;i++)
690 const double *begin=coo1D+2*conn1D[connI1D[i-1]+1];
691 const double *end=coo1D+2*conn1D[connI1D[i-1]+2];
692 const double *third=i+1<nbOfLevsInVec?coo1D+2*conn1D[connI1D[i]+2]:coo1D+2*conn1D[connI1D[i-2]+1];
693 const double vec[2]={end[0]-begin[0],end[1]-begin[1]};
695 double tmp3[2],radius,alpha,alpha0;
696 const double *p0=i+1<nbOfLevsInVec?begin:third;
697 const double *p1=i+1<nbOfLevsInVec?end:begin;
698 const double *p2=i+1<nbOfLevsInVec?third:end;
699 INTERP_KERNEL::EdgeArcCircle::GetArcOfCirclePassingThru(p0,p1,p2,tmp3,radius,alpha,alpha0);
700 double cosangle=i+1<nbOfLevsInVec?(p0[0]-tmp3[0])*(p1[0]-tmp3[0])+(p0[1]-tmp3[1])*(p1[1]-tmp3[1]):(p2[0]-tmp3[0])*(p1[0]-tmp3[0])+(p2[1]-tmp3[1])*(p1[1]-tmp3[1]);
701 double angle=acos(cosangle/(radius*radius));
702 tmp->rotate(end,0,angle);
703 retPtr=std::copy(tmp2->getConstPointer(),tmp2->getConstPointer()+tmp2->getNbOfElems(),retPtr);
709 * This method incarnates the policy 1 for MEDCouplingUMesh::buildExtrudedMesh method.
710 * \param mesh1D is the input 1D mesh used for translation and automatic rotation computation.
711 * \return newCoords new coords filled by this method.
713 DataArrayDouble *MEDCouplingUMesh::fillExtCoordsUsingTranslAndAutoRotation3D(const MEDCouplingUMesh *mesh1D, bool isQuad) const
716 throw INTERP_KERNEL::Exception("MEDCouplingUMesh::fillExtCoordsUsingTranslAndAutoRotation3D : not implemented for quadratic cells !");
717 int oldNbOfNodes=getNumberOfNodes();
718 int nbOf1DCells=mesh1D->getNumberOfCells();
720 throw INTERP_KERNEL::Exception("MEDCouplingUMesh::fillExtCoordsUsingTranslAndAutoRotation3D : impossible to detect any angle of rotation ! Change extrusion policy 1->0 !");
721 MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
722 int nbOfLevsInVec=nbOf1DCells+1;
723 ret->alloc(oldNbOfNodes*nbOfLevsInVec,3);
724 double *retPtr=ret->getPointer();
725 retPtr=std::copy(getCoords()->getConstPointer(),getCoords()->getConstPointer()+getCoords()->getNbOfElems(),retPtr);
726 MCAuto<MEDCouplingUMesh> tmp=MEDCouplingUMesh::New();
727 MCAuto<DataArrayDouble> tmp2=getCoords()->deepCopy();
728 tmp->setCoords(tmp2);
729 const double *coo1D=mesh1D->getCoords()->getConstPointer();
730 const int *conn1D=mesh1D->getNodalConnectivity()->getConstPointer();
731 const int *connI1D=mesh1D->getNodalConnectivityIndex()->getConstPointer();
732 for(int i=1;i<nbOfLevsInVec;i++)
734 const double *begin=coo1D+3*conn1D[connI1D[i-1]+1];
735 const double *end=coo1D+3*conn1D[connI1D[i-1]+2];
736 const double *third=i+1<nbOfLevsInVec?coo1D+3*conn1D[connI1D[i]+2]:coo1D+3*conn1D[connI1D[i-2]+1];
737 const double vec[3]={end[0]-begin[0],end[1]-begin[1],end[2]-begin[2]};
739 double tmp3[2],radius,alpha,alpha0;
740 const double *p0=i+1<nbOfLevsInVec?begin:third;
741 const double *p1=i+1<nbOfLevsInVec?end:begin;
742 const double *p2=i+1<nbOfLevsInVec?third:end;
744 (p1[1]-p0[1])*(p2[2]-p1[2])-(p1[2]-p0[2])*(p2[1]-p1[1]),
745 (p1[2]-p0[2])*(p2[0]-p1[0])-(p1[0]-p0[0])*(p2[2]-p1[2]),
746 (p1[0]-p0[0])*(p2[1]-p1[1])-(p1[1]-p0[1])*(p2[0]-p1[0]),
748 double norm=sqrt(vecPlane[0]*vecPlane[0]+vecPlane[1]*vecPlane[1]+vecPlane[2]*vecPlane[2]);
751 vecPlane[0]/=norm; vecPlane[1]/=norm; vecPlane[2]/=norm;
752 double norm2=sqrt(vecPlane[0]*vecPlane[0]+vecPlane[1]*vecPlane[1]);
753 double vec2[2]={vecPlane[1]/norm2,-vecPlane[0]/norm2};
755 double c2=cos(asin(s2));
757 {vec2[0]*vec2[0]*(1-c2)+c2, vec2[0]*vec2[1]*(1-c2), vec2[1]*s2},
758 {vec2[0]*vec2[1]*(1-c2), vec2[1]*vec2[1]*(1-c2)+c2, -vec2[0]*s2},
759 {-vec2[1]*s2, vec2[0]*s2, c2}
761 double p0r[3]={m[0][0]*p0[0]+m[0][1]*p0[1]+m[0][2]*p0[2], m[1][0]*p0[0]+m[1][1]*p0[1]+m[1][2]*p0[2], m[2][0]*p0[0]+m[2][1]*p0[1]+m[2][2]*p0[2]};
762 double p1r[3]={m[0][0]*p1[0]+m[0][1]*p1[1]+m[0][2]*p1[2], m[1][0]*p1[0]+m[1][1]*p1[1]+m[1][2]*p1[2], m[2][0]*p1[0]+m[2][1]*p1[1]+m[2][2]*p1[2]};
763 double p2r[3]={m[0][0]*p2[0]+m[0][1]*p2[1]+m[0][2]*p2[2], m[1][0]*p2[0]+m[1][1]*p2[1]+m[1][2]*p2[2], m[2][0]*p2[0]+m[2][1]*p2[1]+m[2][2]*p2[2]};
764 INTERP_KERNEL::EdgeArcCircle::GetArcOfCirclePassingThru(p0r,p1r,p2r,tmp3,radius,alpha,alpha0);
765 double cosangle=i+1<nbOfLevsInVec?(p0r[0]-tmp3[0])*(p1r[0]-tmp3[0])+(p0r[1]-tmp3[1])*(p1r[1]-tmp3[1]):(p2r[0]-tmp3[0])*(p1r[0]-tmp3[0])+(p2r[1]-tmp3[1])*(p1r[1]-tmp3[1]);
766 double angle=acos(cosangle/(radius*radius));
767 tmp->rotate(end,vecPlane,angle);
769 retPtr=std::copy(tmp2->getConstPointer(),tmp2->getConstPointer()+tmp2->getNbOfElems(),retPtr);
775 * This method is private because not easy to use for end user. This method is const contrary to
776 * MEDCouplingUMesh::buildExtrudedMesh method because this->_coords are expected to contain
777 * the coords sorted slice by slice.
778 * \param isQuad specifies presence of quadratic cells.
780 MEDCouplingUMesh *MEDCouplingUMesh::buildExtrudedMeshFromThisLowLev(int nbOfNodesOf1Lev, bool isQuad) const
782 int nbOf1DCells(getNumberOfNodes()/nbOfNodesOf1Lev-1);
783 int nbOf2DCells(getNumberOfCells());
784 int nbOf3DCells(nbOf2DCells*nbOf1DCells);
785 MEDCouplingUMesh *ret(MEDCouplingUMesh::New("Extruded",getMeshDimension()+1));
786 const int *conn(_nodal_connec->begin()),*connI(_nodal_connec_index->begin());
787 MCAuto<DataArrayInt> newConn(DataArrayInt::New()),newConnI(DataArrayInt::New());
788 newConnI->alloc(nbOf3DCells+1,1);
789 int *newConnIPtr(newConnI->getPointer());
791 std::vector<int> newc;
792 for(int j=0;j<nbOf2DCells;j++)
794 AppendExtrudedCell(conn+connI[j],conn+connI[j+1],nbOfNodesOf1Lev,isQuad,newc);
795 *newConnIPtr++=(int)newc.size();
797 newConn->alloc((int)(newc.size())*nbOf1DCells,1);
798 int *newConnPtr(newConn->getPointer());
799 int deltaPerLev(isQuad?2*nbOfNodesOf1Lev:nbOfNodesOf1Lev);
800 newConnIPtr=newConnI->getPointer();
801 for(int iz=0;iz<nbOf1DCells;iz++)
804 std::transform(newConnIPtr+1,newConnIPtr+1+nbOf2DCells,newConnIPtr+1+iz*nbOf2DCells,std::bind2nd(std::plus<int>(),newConnIPtr[iz*nbOf2DCells]));
805 const int *posOfTypeOfCell(newConnIPtr);
806 for(std::vector<int>::const_iterator iter=newc.begin();iter!=newc.end();iter++,newConnPtr++)
808 int icell((int)(iter-newc.begin()));//std::distance unfortunately cannot been called here in C++98
809 if(icell!=*posOfTypeOfCell)
812 *newConnPtr=(*iter)+iz*deltaPerLev;
823 ret->setConnectivity(newConn,newConnI,true);
824 ret->setCoords(getCoords());
830 * This method find in candidate pool defined by 'candidates' the cells equal following the polycy 'compType'.
831 * If any true is returned and the results will be put at the end of 'result' output parameter. If not false is returned
832 * and result remains unchanged.
833 * The semantic of 'compType' is specified in MEDCouplingPointSet::zipConnectivityTraducer method.
834 * If in 'candidates' pool -1 value is considered as an empty value.
835 * WARNING this method returns only ONE set of result !
837 bool MEDCouplingUMesh::AreCellsEqualInPool(const std::vector<int>& candidates, int compType, const int *conn, const int *connI, DataArrayInt *result)
839 if(candidates.size()<1)
842 std::vector<int>::const_iterator iter=candidates.begin();
844 for(;iter!=candidates.end();iter++)
846 int status=AreCellsEqual(conn,connI,start,*iter,compType);
851 result->pushBackSilent(start);
855 result->pushBackSilent(*iter);
857 result->pushBackSilent(status==2?(*iter+1):-(*iter+1));
864 * This is the low algorithm of MEDCouplingUMesh::buildPartOfMySelf.
865 * Keeps from \a this only cells which constituing point id are in the ids specified by [ \a begin,\a end ).
866 * The return newly allocated mesh will share the same coordinates as \a this.
868 MEDCouplingUMesh *MEDCouplingUMesh::buildPartOfMySelfKeepCoords(const int *begin, const int *end) const
870 checkConnectivityFullyDefined();
871 int ncell=getNumberOfCells();
872 MCAuto<MEDCouplingUMesh> ret=MEDCouplingUMesh::New();
873 ret->_mesh_dim=_mesh_dim;
874 ret->setCoords(_coords);
875 std::size_t nbOfElemsRet=std::distance(begin,end);
876 int *connIndexRet=(int *)malloc((nbOfElemsRet+1)*sizeof(int));
878 const int *conn=_nodal_connec->getConstPointer();
879 const int *connIndex=_nodal_connec_index->getConstPointer();
881 for(const int *work=begin;work!=end;work++,newNbring++)
883 if(*work>=0 && *work<ncell)
884 connIndexRet[newNbring+1]=connIndexRet[newNbring]+connIndex[*work+1]-connIndex[*work];
888 std::ostringstream oss; oss << "MEDCouplingUMesh::buildPartOfMySelfKeepCoords : On pos #" << std::distance(begin,work) << " input cell id =" << *work << " should be in [0," << ncell << ") !";
889 throw INTERP_KERNEL::Exception(oss.str());
892 int *connRet=(int *)malloc(connIndexRet[nbOfElemsRet]*sizeof(int));
893 int *connRetWork=connRet;
894 std::set<INTERP_KERNEL::NormalizedCellType> types;
895 for(const int *work=begin;work!=end;work++)
897 types.insert((INTERP_KERNEL::NormalizedCellType)conn[connIndex[*work]]);
898 connRetWork=std::copy(conn+connIndex[*work],conn+connIndex[*work+1],connRetWork);
900 MCAuto<DataArrayInt> connRetArr=DataArrayInt::New();
901 connRetArr->useArray(connRet,true,C_DEALLOC,connIndexRet[nbOfElemsRet],1);
902 MCAuto<DataArrayInt> connIndexRetArr=DataArrayInt::New();
903 connIndexRetArr->useArray(connIndexRet,true,C_DEALLOC,(int)nbOfElemsRet+1,1);
904 ret->setConnectivity(connRetArr,connIndexRetArr,false);
906 ret->copyTinyInfoFrom(this);
911 * This is the low algorithm of MEDCouplingUMesh::buildPartOfMySelfSlice.
912 * CellIds are given using range specified by a start an end and step.
914 MEDCouplingUMesh *MEDCouplingUMesh::buildPartOfMySelfKeepCoordsSlice(int start, int end, int step) const
917 int ncell=getNumberOfCells();
918 MCAuto<MEDCouplingUMesh> ret=MEDCouplingUMesh::New();
919 ret->_mesh_dim=_mesh_dim;
920 ret->setCoords(_coords);
921 int newNbOfCells=DataArray::GetNumberOfItemGivenBESRelative(start,end,step,"MEDCouplingUMesh::buildPartOfMySelfKeepCoordsSlice : ");
922 MCAuto<DataArrayInt> newConnI=DataArrayInt::New(); newConnI->alloc(newNbOfCells+1,1);
923 int *newConnIPtr=newConnI->getPointer(); *newConnIPtr=0;
925 const int *conn=_nodal_connec->getConstPointer();
926 const int *connIndex=_nodal_connec_index->getConstPointer();
927 for(int i=0;i<newNbOfCells;i++,newConnIPtr++,work+=step)
929 if(work>=0 && work<ncell)
931 newConnIPtr[1]=newConnIPtr[0]+connIndex[work+1]-connIndex[work];
935 std::ostringstream oss; oss << "MEDCouplingUMesh::buildPartOfMySelfKeepCoordsSlice : On pos #" << i << " input cell id =" << work << " should be in [0," << ncell << ") !";
936 throw INTERP_KERNEL::Exception(oss.str());
939 MCAuto<DataArrayInt> newConn=DataArrayInt::New(); newConn->alloc(newConnIPtr[0],1);
940 int *newConnPtr=newConn->getPointer();
941 std::set<INTERP_KERNEL::NormalizedCellType> types;
943 for(int i=0;i<newNbOfCells;i++,newConnIPtr++,work+=step)
945 types.insert((INTERP_KERNEL::NormalizedCellType)conn[connIndex[work]]);
946 newConnPtr=std::copy(conn+connIndex[work],conn+connIndex[work+1],newConnPtr);
948 ret->setConnectivity(newConn,newConnI,false);
950 ret->copyTinyInfoFrom(this);
955 int MEDCouplingFastNbrer(int id, unsigned nb, const INTERP_KERNEL::CellModel& cm, bool compute, const int *conn1, const int *conn2)
960 int MEDCouplingOrientationSensitiveNbrer(int id, unsigned nb, const INTERP_KERNEL::CellModel& cm, bool compute, const int *conn1, const int *conn2)
966 if(cm.getOrientationStatus(nb,conn1,conn2))
975 * Implementes \a conversionType 0 for meshes with meshDim = 1, of MEDCouplingUMesh::convertLinearCellsToQuadratic method.
976 * \return a newly created DataArrayInt instance that the caller should deal with containing cell ids of converted cells.
977 * \sa MEDCouplingUMesh::convertLinearCellsToQuadratic.
979 DataArrayInt *MEDCouplingUMesh::convertLinearCellsToQuadratic1D0(DataArrayInt *&conn, DataArrayInt *&connI, DataArrayDouble *& coords, std::set<INTERP_KERNEL::NormalizedCellType>& types) const
981 MCAuto<DataArrayDouble> bary=computeCellCenterOfMass();
982 MCAuto<DataArrayInt> newConn=DataArrayInt::New(); newConn->alloc(0,1);
983 MCAuto<DataArrayInt> newConnI=DataArrayInt::New(); newConnI->alloc(1,1); newConnI->setIJ(0,0,0);
984 MCAuto<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(0,1);
985 int nbOfCells=getNumberOfCells();
986 int nbOfNodes=getNumberOfNodes();
987 const int *cPtr=_nodal_connec->begin();
988 const int *icPtr=_nodal_connec_index->begin();
989 int lastVal=0,offset=nbOfNodes;
990 for(int i=0;i<nbOfCells;i++,icPtr++)
992 INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)cPtr[*icPtr];
993 if(type==INTERP_KERNEL::NORM_SEG2)
995 types.insert(INTERP_KERNEL::NORM_SEG3);
996 newConn->pushBackSilent((int)INTERP_KERNEL::NORM_SEG3);
997 newConn->pushBackValsSilent(cPtr+icPtr[0]+1,cPtr+icPtr[0]+3);
998 newConn->pushBackSilent(offset++);
1000 newConnI->pushBackSilent(lastVal);
1001 ret->pushBackSilent(i);
1006 lastVal+=(icPtr[1]-icPtr[0]);
1007 newConnI->pushBackSilent(lastVal);
1008 newConn->pushBackValsSilent(cPtr+icPtr[0],cPtr+icPtr[1]);
1011 MCAuto<DataArrayDouble> tmp=bary->selectByTupleIdSafe(ret->begin(),ret->end());
1012 coords=DataArrayDouble::Aggregate(getCoords(),tmp); conn=newConn.retn(); connI=newConnI.retn();
1016 DataArrayInt *MEDCouplingUMesh::convertLinearCellsToQuadratic2DAnd3D0(const MEDCouplingUMesh *m1D, const DataArrayInt *desc, const DataArrayInt *descI, DataArrayInt *&conn, DataArrayInt *&connI, DataArrayDouble *& coords, std::set<INTERP_KERNEL::NormalizedCellType>& types) const
1018 MCAuto<DataArrayInt> newConn=DataArrayInt::New(); newConn->alloc(0,1);
1019 MCAuto<DataArrayInt> newConnI=DataArrayInt::New(); newConnI->alloc(1,1); newConnI->setIJ(0,0,0);
1020 MCAuto<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(0,1);
1022 const int *descPtr(desc->begin()),*descIPtr(descI->begin());
1023 DataArrayInt *conn1D=0,*conn1DI=0;
1024 std::set<INTERP_KERNEL::NormalizedCellType> types1D;
1025 DataArrayDouble *coordsTmp=0;
1026 MCAuto<DataArrayInt> ret1D=m1D->convertLinearCellsToQuadratic1D0(conn1D,conn1DI,coordsTmp,types1D); ret1D=0;
1027 MCAuto<DataArrayDouble> coordsTmpSafe(coordsTmp);
1028 MCAuto<DataArrayInt> conn1DSafe(conn1D),conn1DISafe(conn1DI);
1029 const int *c1DPtr=conn1D->begin();
1030 const int *c1DIPtr=conn1DI->begin();
1031 int nbOfCells=getNumberOfCells();
1032 const int *cPtr=_nodal_connec->begin();
1033 const int *icPtr=_nodal_connec_index->begin();
1035 for(int i=0;i<nbOfCells;i++,icPtr++,descIPtr++)
1037 INTERP_KERNEL::NormalizedCellType typ=(INTERP_KERNEL::NormalizedCellType)cPtr[*icPtr];
1038 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
1039 if(!cm.isQuadratic())
1041 INTERP_KERNEL::NormalizedCellType typ2=cm.getQuadraticType();
1042 types.insert(typ2); newConn->pushBackSilent(typ2);
1043 newConn->pushBackValsSilent(cPtr+icPtr[0]+1,cPtr+icPtr[1]);
1044 for(const int *d=descPtr+descIPtr[0];d!=descPtr+descIPtr[1];d++)
1045 newConn->pushBackSilent(c1DPtr[c1DIPtr[*d]+3]);
1046 lastVal+=(icPtr[1]-icPtr[0])+(descIPtr[1]-descIPtr[0]);
1047 newConnI->pushBackSilent(lastVal);
1048 ret->pushBackSilent(i);
1053 lastVal+=(icPtr[1]-icPtr[0]);
1054 newConnI->pushBackSilent(lastVal);
1055 newConn->pushBackValsSilent(cPtr+icPtr[0],cPtr+icPtr[1]);
1058 conn=newConn.retn(); connI=newConnI.retn(); coords=coordsTmpSafe.retn();
1063 * Implementes \a conversionType 0 for meshes with meshDim = 2, of MEDCouplingUMesh::convertLinearCellsToQuadratic method.
1064 * \return a newly created DataArrayInt instance that the caller should deal with containing cell ids of converted cells.
1065 * \sa MEDCouplingUMesh::convertLinearCellsToQuadratic.
1067 DataArrayInt *MEDCouplingUMesh::convertLinearCellsToQuadratic2D0(DataArrayInt *&conn, DataArrayInt *&connI, DataArrayDouble *& coords, std::set<INTERP_KERNEL::NormalizedCellType>& types) const
1069 MCAuto<DataArrayInt> desc(DataArrayInt::New()),descI(DataArrayInt::New()),tmp2(DataArrayInt::New()),tmp3(DataArrayInt::New());
1070 MCAuto<MEDCouplingUMesh> m1D=buildDescendingConnectivity(desc,descI,tmp2,tmp3); tmp2=0; tmp3=0;
1071 return convertLinearCellsToQuadratic2DAnd3D0(m1D,desc,descI,conn,connI,coords,types);
1074 DataArrayInt *MEDCouplingUMesh::convertLinearCellsToQuadratic2D1(DataArrayInt *&conn, DataArrayInt *&connI, DataArrayDouble *& coords, std::set<INTERP_KERNEL::NormalizedCellType>& types) const
1076 MCAuto<DataArrayInt> desc(DataArrayInt::New()),descI(DataArrayInt::New()),tmp2(DataArrayInt::New()),tmp3(DataArrayInt::New());
1077 MCAuto<MEDCouplingUMesh> m1D=buildDescendingConnectivity(desc,descI,tmp2,tmp3); tmp2=0; tmp3=0;
1079 MCAuto<DataArrayInt> newConn=DataArrayInt::New(); newConn->alloc(0,1);
1080 MCAuto<DataArrayInt> newConnI=DataArrayInt::New(); newConnI->alloc(1,1); newConnI->setIJ(0,0,0);
1081 MCAuto<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(0,1);
1083 MCAuto<DataArrayDouble> bary=computeCellCenterOfMass();
1084 const int *descPtr(desc->begin()),*descIPtr(descI->begin());
1085 DataArrayInt *conn1D=0,*conn1DI=0;
1086 std::set<INTERP_KERNEL::NormalizedCellType> types1D;
1087 DataArrayDouble *coordsTmp=0;
1088 MCAuto<DataArrayInt> ret1D=m1D->convertLinearCellsToQuadratic1D0(conn1D,conn1DI,coordsTmp,types1D); ret1D=0;
1089 MCAuto<DataArrayDouble> coordsTmpSafe(coordsTmp);
1090 MCAuto<DataArrayInt> conn1DSafe(conn1D),conn1DISafe(conn1DI);
1091 const int *c1DPtr=conn1D->begin();
1092 const int *c1DIPtr=conn1DI->begin();
1093 int nbOfCells=getNumberOfCells();
1094 const int *cPtr=_nodal_connec->begin();
1095 const int *icPtr=_nodal_connec_index->begin();
1096 int lastVal=0,offset=coordsTmpSafe->getNumberOfTuples();
1097 for(int i=0;i<nbOfCells;i++,icPtr++,descIPtr++)
1099 INTERP_KERNEL::NormalizedCellType typ=(INTERP_KERNEL::NormalizedCellType)cPtr[*icPtr];
1100 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
1101 if(!cm.isQuadratic())
1103 INTERP_KERNEL::NormalizedCellType typ2=cm.getQuadraticType2();
1104 types.insert(typ2); newConn->pushBackSilent(typ2);
1105 newConn->pushBackValsSilent(cPtr+icPtr[0]+1,cPtr+icPtr[1]);
1106 for(const int *d=descPtr+descIPtr[0];d!=descPtr+descIPtr[1];d++)
1107 newConn->pushBackSilent(c1DPtr[c1DIPtr[*d]+3]);
1108 newConn->pushBackSilent(offset+ret->getNumberOfTuples());
1109 lastVal+=(icPtr[1]-icPtr[0])+(descIPtr[1]-descIPtr[0])+1;
1110 newConnI->pushBackSilent(lastVal);
1111 ret->pushBackSilent(i);
1116 lastVal+=(icPtr[1]-icPtr[0]);
1117 newConnI->pushBackSilent(lastVal);
1118 newConn->pushBackValsSilent(cPtr+icPtr[0],cPtr+icPtr[1]);
1121 MCAuto<DataArrayDouble> tmp=bary->selectByTupleIdSafe(ret->begin(),ret->end());
1122 coords=DataArrayDouble::Aggregate(coordsTmpSafe,tmp); conn=newConn.retn(); connI=newConnI.retn();
1127 * Implementes \a conversionType 0 for meshes with meshDim = 3, of MEDCouplingUMesh::convertLinearCellsToQuadratic method.
1128 * \return a newly created DataArrayInt instance that the caller should deal with containing cell ids of converted cells.
1129 * \sa MEDCouplingUMesh::convertLinearCellsToQuadratic.
1131 DataArrayInt *MEDCouplingUMesh::convertLinearCellsToQuadratic3D0(DataArrayInt *&conn, DataArrayInt *&connI, DataArrayDouble *& coords, std::set<INTERP_KERNEL::NormalizedCellType>& types) const
1133 MCAuto<DataArrayInt> desc(DataArrayInt::New()),descI(DataArrayInt::New()),tmp2(DataArrayInt::New()),tmp3(DataArrayInt::New());
1134 MCAuto<MEDCouplingUMesh> m1D=explode3DMeshTo1D(desc,descI,tmp2,tmp3); tmp2=0; tmp3=0;
1135 return convertLinearCellsToQuadratic2DAnd3D0(m1D,desc,descI,conn,connI,coords,types);
1138 DataArrayInt *MEDCouplingUMesh::convertLinearCellsToQuadratic3D1(DataArrayInt *&conn, DataArrayInt *&connI, DataArrayDouble *& coords, std::set<INTERP_KERNEL::NormalizedCellType>& types) const
1140 MCAuto<DataArrayInt> desc2(DataArrayInt::New()),desc2I(DataArrayInt::New()),tmp2(DataArrayInt::New()),tmp3(DataArrayInt::New());
1141 MCAuto<MEDCouplingUMesh> m2D=buildDescendingConnectivityGen<MinusOneSonsGeneratorBiQuadratic>(desc2,desc2I,tmp2,tmp3,MEDCouplingFastNbrer); tmp2=0; tmp3=0;
1142 MCAuto<DataArrayInt> desc1(DataArrayInt::New()),desc1I(DataArrayInt::New()),tmp4(DataArrayInt::New()),tmp5(DataArrayInt::New());
1143 MCAuto<MEDCouplingUMesh> m1D=explode3DMeshTo1D(desc1,desc1I,tmp4,tmp5); tmp4=0; tmp5=0;
1145 MCAuto<DataArrayInt> newConn=DataArrayInt::New(); newConn->alloc(0,1);
1146 MCAuto<DataArrayInt> newConnI=DataArrayInt::New(); newConnI->alloc(1,1); newConnI->setIJ(0,0,0);
1147 MCAuto<DataArrayInt> ret=DataArrayInt::New(),ret2=DataArrayInt::New(); ret->alloc(0,1); ret2->alloc(0,1);
1149 MCAuto<DataArrayDouble> bary=computeCellCenterOfMass();
1150 const int *descPtr(desc1->begin()),*descIPtr(desc1I->begin()),*desc2Ptr(desc2->begin()),*desc2IPtr(desc2I->begin());
1151 DataArrayInt *conn1D=0,*conn1DI=0,*conn2D=0,*conn2DI=0;
1152 std::set<INTERP_KERNEL::NormalizedCellType> types1D,types2D;
1153 DataArrayDouble *coordsTmp=0,*coordsTmp2=0;
1154 MCAuto<DataArrayInt> ret1D=m1D->convertLinearCellsToQuadratic1D0(conn1D,conn1DI,coordsTmp,types1D); ret1D=DataArrayInt::New(); ret1D->alloc(0,1);
1155 MCAuto<DataArrayInt> conn1DSafe(conn1D),conn1DISafe(conn1DI);
1156 MCAuto<DataArrayDouble> coordsTmpSafe(coordsTmp);
1157 MCAuto<DataArrayInt> ret2D=m2D->convertLinearCellsToQuadratic2D1(conn2D,conn2DI,coordsTmp2,types2D); ret2D=DataArrayInt::New(); ret2D->alloc(0,1);
1158 MCAuto<DataArrayDouble> coordsTmp2Safe(coordsTmp2);
1159 MCAuto<DataArrayInt> conn2DSafe(conn2D),conn2DISafe(conn2DI);
1160 const int *c1DPtr=conn1D->begin(),*c1DIPtr=conn1DI->begin(),*c2DPtr=conn2D->begin(),*c2DIPtr=conn2DI->begin();
1161 int nbOfCells=getNumberOfCells();
1162 const int *cPtr=_nodal_connec->begin();
1163 const int *icPtr=_nodal_connec_index->begin();
1164 int lastVal=0,offset=coordsTmpSafe->getNumberOfTuples();
1165 for(int i=0;i<nbOfCells;i++,icPtr++,descIPtr++,desc2IPtr++)
1167 INTERP_KERNEL::NormalizedCellType typ=(INTERP_KERNEL::NormalizedCellType)cPtr[*icPtr];
1168 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
1169 if(!cm.isQuadratic())
1171 INTERP_KERNEL::NormalizedCellType typ2=cm.getQuadraticType2();
1172 if(typ2==INTERP_KERNEL::NORM_ERROR)
1174 std::ostringstream oss; oss << "MEDCouplingUMesh::convertLinearCellsToQuadratic3D1 : On cell #" << i << " the linear cell type does not support advanced quadratization !";
1175 throw INTERP_KERNEL::Exception(oss.str());
1177 types.insert(typ2); newConn->pushBackSilent(typ2);
1178 newConn->pushBackValsSilent(cPtr+icPtr[0]+1,cPtr+icPtr[1]);
1179 for(const int *d=descPtr+descIPtr[0];d!=descPtr+descIPtr[1];d++)
1180 newConn->pushBackSilent(c1DPtr[c1DIPtr[*d]+3]);
1181 for(const int *d=desc2Ptr+desc2IPtr[0];d!=desc2Ptr+desc2IPtr[1];d++)
1183 int nodeId2=c2DPtr[c2DIPtr[(*d)+1]-1];
1184 int tmpPos=newConn->getNumberOfTuples();
1185 newConn->pushBackSilent(nodeId2);
1186 ret2D->pushBackSilent(nodeId2); ret1D->pushBackSilent(tmpPos);
1188 newConn->pushBackSilent(offset+ret->getNumberOfTuples());
1189 lastVal+=(icPtr[1]-icPtr[0])+(descIPtr[1]-descIPtr[0])+(desc2IPtr[1]-desc2IPtr[0])+1;
1190 newConnI->pushBackSilent(lastVal);
1191 ret->pushBackSilent(i);
1196 lastVal+=(icPtr[1]-icPtr[0]);
1197 newConnI->pushBackSilent(lastVal);
1198 newConn->pushBackValsSilent(cPtr+icPtr[0],cPtr+icPtr[1]);
1201 MCAuto<DataArrayInt> diffRet2D=ret2D->getDifferentValues();
1202 MCAuto<DataArrayInt> o2nRet2D=diffRet2D->invertArrayN2O2O2N(coordsTmp2Safe->getNumberOfTuples());
1203 coordsTmp2Safe=coordsTmp2Safe->selectByTupleId(diffRet2D->begin(),diffRet2D->end());
1204 MCAuto<DataArrayDouble> tmp=bary->selectByTupleIdSafe(ret->begin(),ret->end());
1205 std::vector<const DataArrayDouble *> v(3); v[0]=coordsTmpSafe; v[1]=coordsTmp2Safe; v[2]=tmp;
1206 int *c=newConn->getPointer();
1207 const int *cI(newConnI->begin());
1208 for(const int *elt=ret1D->begin();elt!=ret1D->end();elt++)
1209 c[*elt]=o2nRet2D->getIJ(c[*elt],0)+offset;
1210 offset=coordsTmp2Safe->getNumberOfTuples();
1211 for(const int *elt=ret->begin();elt!=ret->end();elt++)
1212 c[cI[(*elt)+1]-1]+=offset;
1213 coords=DataArrayDouble::Aggregate(v); conn=newConn.retn(); connI=newConnI.retn();
1217 DataArrayInt *MEDCouplingUMesh::buildUnionOf2DMeshLinear(const MEDCouplingUMesh *skin, const DataArrayInt *n2o) const
1219 int nbOfNodesExpected(skin->getNumberOfNodes());
1220 const int *n2oPtr(n2o->begin());
1221 MCAuto<DataArrayInt> revNodal(DataArrayInt::New()),revNodalI(DataArrayInt::New());
1222 skin->getReverseNodalConnectivity(revNodal,revNodalI);
1223 const int *revNodalPtr(revNodal->begin()),*revNodalIPtr(revNodalI->begin());
1224 const int *nodalPtr(skin->getNodalConnectivity()->begin());
1225 const int *nodalIPtr(skin->getNodalConnectivityIndex()->begin());
1226 MCAuto<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(nbOfNodesExpected+1,1);
1227 int *work(ret->getPointer()); *work++=INTERP_KERNEL::NORM_POLYGON;
1228 if(nbOfNodesExpected<1)
1230 int prevCell(0),prevNode(nodalPtr[nodalIPtr[0]+1]);
1231 *work++=n2oPtr[prevNode];
1232 for(int i=1;i<nbOfNodesExpected;i++)
1234 if(nodalIPtr[prevCell+1]-nodalIPtr[prevCell]==3)
1236 std::set<int> conn(nodalPtr+nodalIPtr[prevCell]+1,nodalPtr+nodalIPtr[prevCell]+3);
1237 conn.erase(prevNode);
1240 int curNode(*(conn.begin()));
1241 *work++=n2oPtr[curNode];
1242 std::set<int> shar(revNodalPtr+revNodalIPtr[curNode],revNodalPtr+revNodalIPtr[curNode+1]);
1243 shar.erase(prevCell);
1246 prevCell=*(shar.begin());
1250 throw INTERP_KERNEL::Exception("MEDCouplingUMesh::buildUnionOf2DMeshLinear : presence of unexpected 2 !");
1253 throw INTERP_KERNEL::Exception("MEDCouplingUMesh::buildUnionOf2DMeshLinear : presence of unexpected 1 !");
1256 throw INTERP_KERNEL::Exception("MEDCouplingUMesh::buildUnionOf2DMeshLinear : presence of unexpected cell !");
1261 DataArrayInt *MEDCouplingUMesh::buildUnionOf2DMeshQuadratic(const MEDCouplingUMesh *skin, const DataArrayInt *n2o) const
1263 int nbOfNodesExpected(skin->getNumberOfNodes());
1264 int nbOfTurn(nbOfNodesExpected/2);
1265 const int *n2oPtr(n2o->begin());
1266 MCAuto<DataArrayInt> revNodal(DataArrayInt::New()),revNodalI(DataArrayInt::New());
1267 skin->getReverseNodalConnectivity(revNodal,revNodalI);
1268 const int *revNodalPtr(revNodal->begin()),*revNodalIPtr(revNodalI->begin());
1269 const int *nodalPtr(skin->getNodalConnectivity()->begin());
1270 const int *nodalIPtr(skin->getNodalConnectivityIndex()->begin());
1271 MCAuto<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(nbOfNodesExpected+1,1);
1272 int *work(ret->getPointer()); *work++=INTERP_KERNEL::NORM_QPOLYG;
1273 if(nbOfNodesExpected<1)
1275 int prevCell(0),prevNode(nodalPtr[nodalIPtr[0]+1]);
1276 *work=n2oPtr[prevNode]; work[nbOfTurn]=n2oPtr[nodalPtr[nodalIPtr[0]+3]]; work++;
1277 for(int i=1;i<nbOfTurn;i++)
1279 if(nodalIPtr[prevCell+1]-nodalIPtr[prevCell]==4)
1281 std::set<int> conn(nodalPtr+nodalIPtr[prevCell]+1,nodalPtr+nodalIPtr[prevCell]+3);
1282 conn.erase(prevNode);
1285 int curNode(*(conn.begin()));
1286 *work=n2oPtr[curNode];
1287 std::set<int> shar(revNodalPtr+revNodalIPtr[curNode],revNodalPtr+revNodalIPtr[curNode+1]);
1288 shar.erase(prevCell);
1291 int curCell(*(shar.begin()));
1292 work[nbOfTurn]=n2oPtr[nodalPtr[nodalIPtr[curCell]+3]];
1298 throw INTERP_KERNEL::Exception("MEDCouplingUMesh::buildUnionOf2DMeshQuadratic : presence of unexpected 2 !");
1301 throw INTERP_KERNEL::Exception("MEDCouplingUMesh::buildUnionOf2DMeshQuadratic : presence of unexpected 1 !");
1304 throw INTERP_KERNEL::Exception("MEDCouplingUMesh::buildUnionOf2DMeshQuadratic : presence of unexpected cell !");
1309 MEDCouplingUMesh *MEDCouplingUMesh::MergeUMeshesLL(const std::vector<const MEDCouplingUMesh *>& a)
1312 throw INTERP_KERNEL::Exception("MEDCouplingUMesh::MergeUMeshes : input array must be NON EMPTY !");
1313 std::vector<const MEDCouplingUMesh *>::const_iterator it=a.begin();
1314 int meshDim=(*it)->getMeshDimension();
1315 int nbOfCells=(*it)->getNumberOfCells();
1316 int meshLgth=(*it++)->getNodalConnectivityArrayLen();
1317 for(;it!=a.end();it++)
1319 if(meshDim!=(*it)->getMeshDimension())
1320 throw INTERP_KERNEL::Exception("Mesh dimensions mismatches, MergeUMeshes impossible !");
1321 nbOfCells+=(*it)->getNumberOfCells();
1322 meshLgth+=(*it)->getNodalConnectivityArrayLen();
1324 std::vector<const MEDCouplingPointSet *> aps(a.size());
1325 std::copy(a.begin(),a.end(),aps.begin());
1326 MCAuto<DataArrayDouble> pts=MergeNodesArray(aps);
1327 MCAuto<MEDCouplingUMesh> ret=MEDCouplingUMesh::New("merge",meshDim);
1328 ret->setCoords(pts);
1329 MCAuto<DataArrayInt> c=DataArrayInt::New();
1330 c->alloc(meshLgth,1);
1331 int *cPtr=c->getPointer();
1332 MCAuto<DataArrayInt> cI=DataArrayInt::New();
1333 cI->alloc(nbOfCells+1,1);
1334 int *cIPtr=cI->getPointer();
1338 for(it=a.begin();it!=a.end();it++)
1340 int curNbOfCell=(*it)->getNumberOfCells();
1341 const int *curCI=(*it)->_nodal_connec_index->begin();
1342 const int *curC=(*it)->_nodal_connec->begin();
1343 cIPtr=std::transform(curCI+1,curCI+curNbOfCell+1,cIPtr,std::bind2nd(std::plus<int>(),offset));
1344 for(int j=0;j<curNbOfCell;j++)
1346 const int *src=curC+curCI[j];
1348 for(;src!=curC+curCI[j+1];src++,cPtr++)
1356 offset+=curCI[curNbOfCell];
1357 offset2+=(*it)->getNumberOfNodes();
1360 ret->setConnectivity(c,cI,true);
1366 * \param [in] pt the start pointer (included) of the coordinates of the point
1367 * \param [in] cellIdsBg the start pointer (included) of cellIds
1368 * \param [in] cellIdsEnd the end pointer (excluded) of cellIds
1369 * \param [in] nc nodal connectivity
1370 * \param [in] ncI nodal connectivity index
1371 * \param [in,out] ret0 the min distance between \a this and the external input point
1372 * \param [out] cellId that corresponds to minimal distance. If the closer node is not linked to any cell in \a this -1 is returned.
1373 * \sa MEDCouplingUMesh::distanceToPoint, MEDCouplingUMesh::distanceToPoints
1375 void MEDCouplingUMesh::DistanceToPoint3DSurfAlg(const double *pt, const int *cellIdsBg, const int *cellIdsEnd, const double *coords, const int *nc, const int *ncI, double& ret0, int& cellId)
1378 ret0=std::numeric_limits<double>::max();
1379 for(const int *zeCell=cellIdsBg;zeCell!=cellIdsEnd;zeCell++)
1381 switch((INTERP_KERNEL::NormalizedCellType)nc[ncI[*zeCell]])
1383 case INTERP_KERNEL::NORM_TRI3:
1385 double tmp=INTERP_KERNEL::DistanceFromPtToTriInSpaceDim3(pt,coords+3*nc[ncI[*zeCell]+1],coords+3*nc[ncI[*zeCell]+2],coords+3*nc[ncI[*zeCell]+3]);
1387 { ret0=tmp; cellId=*zeCell; }
1390 case INTERP_KERNEL::NORM_QUAD4:
1391 case INTERP_KERNEL::NORM_POLYGON:
1393 double tmp=INTERP_KERNEL::DistanceFromPtToPolygonInSpaceDim3(pt,nc+ncI[*zeCell]+1,nc+ncI[*zeCell+1],coords);
1395 { ret0=tmp; cellId=*zeCell; }
1399 throw INTERP_KERNEL::Exception("MEDCouplingUMesh::distanceToPoint3DSurfAlg : not managed cell type ! Supporting TRI3, QUAD4 and POLYGON !");
1405 * \param [in] pt the start pointer (included) of the coordinates of the point
1406 * \param [in] cellIdsBg the start pointer (included) of cellIds
1407 * \param [in] cellIdsEnd the end pointer (excluded) of cellIds
1408 * \param [in] nc nodal connectivity
1409 * \param [in] ncI nodal connectivity index
1410 * \param [in,out] ret0 the min distance between \a this and the external input point
1411 * \param [out] cellId that corresponds to minimal distance. If the closer node is not linked to any cell in \a this -1 is returned.
1412 * \sa MEDCouplingUMesh::distanceToPoint, MEDCouplingUMesh::distanceToPoints
1414 void MEDCouplingUMesh::DistanceToPoint2DCurveAlg(const double *pt, const int *cellIdsBg, const int *cellIdsEnd, const double *coords, const int *nc, const int *ncI, double& ret0, int& cellId)
1417 ret0=std::numeric_limits<double>::max();
1418 for(const int *zeCell=cellIdsBg;zeCell!=cellIdsEnd;zeCell++)
1420 switch((INTERP_KERNEL::NormalizedCellType)nc[ncI[*zeCell]])
1422 case INTERP_KERNEL::NORM_SEG2:
1424 std::size_t uselessEntry=0;
1425 double tmp=INTERP_KERNEL::SquareDistanceFromPtToSegInSpaceDim2(pt,coords+2*nc[ncI[*zeCell]+1],coords+2*nc[ncI[*zeCell]+2],uselessEntry);
1428 { ret0=tmp; cellId=*zeCell; }
1432 throw INTERP_KERNEL::Exception("MEDCouplingUMesh::distanceToPoint2DCurveAlg : not managed cell type ! Supporting SEG2 !");
1436 DataArrayInt *MEDCouplingUMesh::ComputeSpreadZoneGraduallyFromSeedAlg(std::vector<bool>& fetched, const int *seedBg, const int *seedEnd, const DataArrayInt *arrIn, const DataArrayInt *arrIndxIn, int nbOfDepthPeeling, int& nbOfDepthPeelingPerformed)
1438 nbOfDepthPeelingPerformed=0;
1439 if(!seedBg || !seedEnd || !arrIn || !arrIndxIn)
1440 throw INTERP_KERNEL::Exception("MEDCouplingUMesh::ComputeSpreadZoneGraduallyFromSeedAlg : some input pointer is NULL !");
1441 int nbOfTuples=arrIndxIn->getNumberOfTuples()-1;
1442 std::vector<bool> fetched2(nbOfTuples,false);
1444 for(const int *seedElt=seedBg;seedElt!=seedEnd;seedElt++,i++)
1446 if(*seedElt>=0 && *seedElt<nbOfTuples)
1447 { fetched[*seedElt]=true; fetched2[*seedElt]=true; }
1449 { std::ostringstream oss; oss << "MEDCouplingUMesh::ComputeSpreadZoneGraduallyFromSeedAlg : At pos #" << i << " of seeds value is " << *seedElt << "! Should be in [0," << nbOfTuples << ") !"; throw INTERP_KERNEL::Exception(oss.str()); }
1451 const int *arrInPtr=arrIn->begin();
1452 const int *arrIndxPtr=arrIndxIn->begin();
1453 int targetNbOfDepthPeeling=nbOfDepthPeeling!=-1?nbOfDepthPeeling:std::numeric_limits<int>::max();
1454 std::vector<int> idsToFetch1(seedBg,seedEnd);
1455 std::vector<int> idsToFetch2;
1456 std::vector<int> *idsToFetch=&idsToFetch1;
1457 std::vector<int> *idsToFetchOther=&idsToFetch2;
1458 while(!idsToFetch->empty() && nbOfDepthPeelingPerformed<targetNbOfDepthPeeling)
1460 for(std::vector<int>::const_iterator it=idsToFetch->begin();it!=idsToFetch->end();it++)
1461 for(const int *it2=arrInPtr+arrIndxPtr[*it];it2!=arrInPtr+arrIndxPtr[*it+1];it2++)
1463 { fetched[*it2]=true; fetched2[*it2]=true; idsToFetchOther->push_back(*it2); }
1464 std::swap(idsToFetch,idsToFetchOther);
1465 idsToFetchOther->clear();
1466 nbOfDepthPeelingPerformed++;
1468 int lgth=(int)std::count(fetched2.begin(),fetched2.end(),true);
1470 MCAuto<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(lgth,1);
1471 int *retPtr=ret->getPointer();
1472 for(std::vector<bool>::const_iterator it=fetched2.begin();it!=fetched2.end();it++,i++)
1479 * This method put in zip format into parameter 'zipFrmt' in full interlace mode.
1480 * This format is often asked by INTERP_KERNEL algorithms to avoid many indirections into coordinates array.
1482 void MEDCouplingUMesh::FillInCompact3DMode(int spaceDim, int nbOfNodesInCell, const int *conn, const double *coo, double *zipFrmt)
1486 for(int i=0;i<nbOfNodesInCell;i++)
1487 w=std::copy(coo+3*conn[i],coo+3*conn[i]+3,w);
1488 else if(spaceDim==2)
1490 for(int i=0;i<nbOfNodesInCell;i++)
1492 w=std::copy(coo+2*conn[i],coo+2*conn[i]+2,w);
1497 throw INTERP_KERNEL::Exception("MEDCouplingUMesh::FillInCompact3DMode : Invalid spaceDim specified : must be 2 or 3 !");
1501 * This method takes in input a cell defined by its MEDcouplingUMesh connectivity [ \a connBg , \a connEnd ) and returns its extruded cell by inserting the result at the end of ret.
1502 * \param nbOfNodesPerLev in parameter that specifies the number of nodes of one slice of global dataset
1503 * \param isQuad specifies the policy of connectivity.
1504 * @ret in/out parameter in which the result will be append
1506 void MEDCouplingUMesh::AppendExtrudedCell(const int *connBg, const int *connEnd, int nbOfNodesPerLev, bool isQuad, std::vector<int>& ret)
1508 INTERP_KERNEL::NormalizedCellType flatType=(INTERP_KERNEL::NormalizedCellType)connBg[0];
1509 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(flatType);
1510 ret.push_back(cm.getExtrudedType());
1511 int deltaz=isQuad?2*nbOfNodesPerLev:nbOfNodesPerLev;
1514 case INTERP_KERNEL::NORM_POINT1:
1516 ret.push_back(connBg[1]);
1517 ret.push_back(connBg[1]+nbOfNodesPerLev);
1520 case INTERP_KERNEL::NORM_SEG2:
1522 int conn[4]={connBg[1],connBg[2],connBg[2]+deltaz,connBg[1]+deltaz};
1523 ret.insert(ret.end(),conn,conn+4);
1526 case INTERP_KERNEL::NORM_SEG3:
1528 int conn[8]={connBg[1],connBg[3],connBg[3]+deltaz,connBg[1]+deltaz,connBg[2],connBg[3]+nbOfNodesPerLev,connBg[2]+deltaz,connBg[1]+nbOfNodesPerLev};
1529 ret.insert(ret.end(),conn,conn+8);
1532 case INTERP_KERNEL::NORM_QUAD4:
1534 int conn[8]={connBg[1],connBg[2],connBg[3],connBg[4],connBg[1]+deltaz,connBg[2]+deltaz,connBg[3]+deltaz,connBg[4]+deltaz};
1535 ret.insert(ret.end(),conn,conn+8);
1538 case INTERP_KERNEL::NORM_TRI3:
1540 int conn[6]={connBg[1],connBg[2],connBg[3],connBg[1]+deltaz,connBg[2]+deltaz,connBg[3]+deltaz};
1541 ret.insert(ret.end(),conn,conn+6);
1544 case INTERP_KERNEL::NORM_TRI6:
1546 int conn[15]={connBg[1],connBg[2],connBg[3],connBg[1]+deltaz,connBg[2]+deltaz,connBg[3]+deltaz,connBg[4],connBg[5],connBg[6],connBg[4]+deltaz,connBg[5]+deltaz,connBg[6]+deltaz,
1547 connBg[1]+nbOfNodesPerLev,connBg[2]+nbOfNodesPerLev,connBg[3]+nbOfNodesPerLev};
1548 ret.insert(ret.end(),conn,conn+15);
1551 case INTERP_KERNEL::NORM_QUAD8:
1554 connBg[1],connBg[2],connBg[3],connBg[4],connBg[1]+deltaz,connBg[2]+deltaz,connBg[3]+deltaz,connBg[4]+deltaz,
1555 connBg[5],connBg[6],connBg[7],connBg[8],connBg[5]+deltaz,connBg[6]+deltaz,connBg[7]+deltaz,connBg[8]+deltaz,
1556 connBg[1]+nbOfNodesPerLev,connBg[2]+nbOfNodesPerLev,connBg[3]+nbOfNodesPerLev,connBg[4]+nbOfNodesPerLev
1558 ret.insert(ret.end(),conn,conn+20);
1561 case INTERP_KERNEL::NORM_POLYGON:
1563 std::back_insert_iterator< std::vector<int> > ii(ret);
1564 std::copy(connBg+1,connEnd,ii);
1566 std::reverse_iterator<const int *> rConnBg(connEnd);
1567 std::reverse_iterator<const int *> rConnEnd(connBg+1);
1568 std::transform(rConnBg,rConnEnd,ii,std::bind2nd(std::plus<int>(),deltaz));
1569 std::size_t nbOfRadFaces=std::distance(connBg+1,connEnd);
1570 for(std::size_t i=0;i<nbOfRadFaces;i++)
1573 int conn[4]={connBg[(i+1)%nbOfRadFaces+1],connBg[i+1],connBg[i+1]+deltaz,connBg[(i+1)%nbOfRadFaces+1]+deltaz};
1574 std::copy(conn,conn+4,ii);
1579 throw INTERP_KERNEL::Exception("A flat type has been detected that has not its extruded representation !");
1585 * This method is part of the Slice3D algorithm. It is the first step of assembly process, ones coordinates have been computed (by MEDCouplingUMesh::split3DCurveWithPlane method).
1586 * This method allows to compute given the status of 3D curve cells and the descending connectivity 3DSurf->3DCurve to deduce the intersection of each 3D surf cells
1587 * with a plane. The result will be put in 'cut3DSuf' out parameter.
1588 * \param [in] cut3DCurve input paramter that gives for each 3DCurve cell if it owns fully to the plane or partially.
1589 * \param [out] nodesOnPlane, returns all the nodes that are on the plane.
1590 * \param [in] nodal3DSurf is the nodal connectivity of 3D surf mesh.
1591 * \param [in] nodalIndx3DSurf is the nodal connectivity index of 3D surf mesh.
1592 * \param [in] nodal3DCurve is the nodal connectivity of 3D curve mesh.
1593 * \param [in] nodal3DIndxCurve is the nodal connectivity index of 3D curve mesh.
1594 * \param [in] desc is the descending connectivity 3DSurf->3DCurve
1595 * \param [in] descIndx is the descending connectivity index 3DSurf->3DCurve
1596 * \param [out] cut3DSuf input/output param.
1598 void MEDCouplingUMesh::AssemblyForSplitFrom3DCurve(const std::vector<int>& cut3DCurve, std::vector<int>& nodesOnPlane, const int *nodal3DSurf, const int *nodalIndx3DSurf,
1599 const int *nodal3DCurve, const int *nodalIndx3DCurve,
1600 const int *desc, const int *descIndx,
1601 std::vector< std::pair<int,int> >& cut3DSurf)
1603 std::set<int> nodesOnP(nodesOnPlane.begin(),nodesOnPlane.end());
1604 int nbOf3DSurfCell=(int)cut3DSurf.size();
1605 for(int i=0;i<nbOf3DSurfCell;i++)
1607 std::vector<int> res;
1608 int offset=descIndx[i];
1609 int nbOfSeg=descIndx[i+1]-offset;
1610 for(int j=0;j<nbOfSeg;j++)
1612 int edgeId=desc[offset+j];
1613 int status=cut3DCurve[edgeId];
1617 res.push_back(status);
1620 res.push_back(nodal3DCurve[nodalIndx3DCurve[edgeId]+1]);
1621 res.push_back(nodal3DCurve[nodalIndx3DCurve[edgeId]+2]);
1629 cut3DSurf[i].first=res[0]; cut3DSurf[i].second=res[1];
1635 std::set<int> s1(nodal3DSurf+nodalIndx3DSurf[i]+1,nodal3DSurf+nodalIndx3DSurf[i+1]);
1636 std::set_intersection(nodesOnP.begin(),nodesOnP.end(),s1.begin(),s1.end(),std::back_insert_iterator< std::vector<int> >(res));
1639 cut3DSurf[i].first=res[0]; cut3DSurf[i].second=res[1];
1643 cut3DSurf[i].first=-1; cut3DSurf[i].second=-1;
1648 {// case when plane is on a multi colinear edge of a polyhedron
1649 if((int)res.size()==2*nbOfSeg)
1651 cut3DSurf[i].first=-2; cut3DSurf[i].second=i;
1654 throw INTERP_KERNEL::Exception("MEDCouplingUMesh::AssemblyPointsFrom3DCurve : unexpected situation !");
1662 * \a this is expected to be a mesh with spaceDim==3 and meshDim==3. If not an exception will be thrown.
1663 * This method is part of the Slice3D algorithm. It is the second step of assembly process, ones coordinates have been computed (by MEDCouplingUMesh::split3DCurveWithPlane method).
1664 * This method allows to compute given the result of 3D surf cells with plane and the descending connectivity 3D->3DSurf to deduce the intersection of each 3D cells
1665 * with a plane. The result will be put in 'nodalRes' 'nodalResIndx' and 'cellIds' out parameters.
1666 * \param cut3DSurf input paramter that gives for each 3DSurf its intersection with plane (result of MEDCouplingUMesh::AssemblyForSplitFrom3DCurve).
1667 * \param desc is the descending connectivity 3D->3DSurf
1668 * \param descIndx is the descending connectivity index 3D->3DSurf
1670 void MEDCouplingUMesh::assemblyForSplitFrom3DSurf(const std::vector< std::pair<int,int> >& cut3DSurf,
1671 const int *desc, const int *descIndx,
1672 DataArrayInt *nodalRes, DataArrayInt *nodalResIndx, DataArrayInt *cellIds) const
1674 checkFullyDefined();
1675 if(getMeshDimension()!=3 || getSpaceDimension()!=3)
1676 throw INTERP_KERNEL::Exception("MEDCouplingUMesh::assemblyForSplitFrom3DSurf works on umeshes with meshdim equal to 3 and spaceDim equal to 3 too!");
1677 const int *nodal3D(_nodal_connec->begin()),*nodalIndx3D(_nodal_connec_index->begin());
1678 int nbOfCells(getNumberOfCells());
1679 for(int i=0;i<nbOfCells;i++)
1681 std::map<int, std::set<int> > m;
1682 int offset=descIndx[i];
1683 int nbOfFaces=descIndx[i+1]-offset;
1686 for(int j=0;j<nbOfFaces;j++)
1688 const std::pair<int,int>& p=cut3DSurf[desc[offset+j]];
1689 if(p.first!=-1 && p.second!=-1)
1693 start=p.first; end=p.second;
1694 m[p.first].insert(p.second);
1695 m[p.second].insert(p.first);
1699 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel((INTERP_KERNEL::NormalizedCellType)nodal3D[nodalIndx3D[i]]);
1700 int sz=nodalIndx3D[i+1]-nodalIndx3D[i]-1;
1701 INTERP_KERNEL::AutoPtr<int> tmp=new int[sz];
1702 INTERP_KERNEL::NormalizedCellType cmsId;
1703 unsigned nbOfNodesSon=cm.fillSonCellNodalConnectivity2(j,nodal3D+nodalIndx3D[i]+1,sz,tmp,cmsId);
1704 start=tmp[0]; end=tmp[nbOfNodesSon-1];
1705 for(unsigned k=0;k<nbOfNodesSon;k++)
1707 m[tmp[k]].insert(tmp[(k+1)%nbOfNodesSon]);
1708 m[tmp[(k+1)%nbOfNodesSon]].insert(tmp[k]);
1715 std::vector<int> conn(1,(int)INTERP_KERNEL::NORM_POLYGON);
1719 std::map<int, std::set<int> >::const_iterator it=m.find(start);
1720 const std::set<int>& s=(*it).second;
1721 std::set<int> s2; s2.insert(prev);
1723 std::set_difference(s.begin(),s.end(),s2.begin(),s2.end(),inserter(s3,s3.begin()));
1726 int val=*s3.begin();
1727 conn.push_back(start);
1734 conn.push_back(end);
1737 nodalRes->insertAtTheEnd(conn.begin(),conn.end());
1738 nodalResIndx->pushBackSilent(nodalRes->getNumberOfTuples());
1739 cellIds->pushBackSilent(i);
1745 void MEDCouplingUMesh::ComputeAllTypesInternal(std::set<INTERP_KERNEL::NormalizedCellType>& types, const DataArrayInt *nodalConnec, const DataArrayInt *nodalConnecIndex)
1747 if(nodalConnec && nodalConnecIndex)
1750 const int *conn(nodalConnec->begin()),*connIndex(nodalConnecIndex->begin());
1751 int nbOfElem(nodalConnecIndex->getNbOfElems()-1);
1753 for(const int *pt=connIndex;pt!=connIndex+nbOfElem;pt++)
1754 types.insert((INTERP_KERNEL::NormalizedCellType)conn[*pt]);