+ static const int DUAL_TRI_0[6]={0,2, 1,0, 2,1};
+ static const int DUAL_TRI_1[6]={-3,+5, +3,-4, +4,-5};
+ static const int FACEID_NOT_SH_NODE[3]={1,2,0};
+ if(getCellModelEnum()!=INTERP_KERNEL::NORM_TRI3)
+ throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::computeDualMesh2D : only TRI3 supported !");
+ checkFullyDefined();
+ MCAuto<MEDCouplingUMesh> thisu(buildUnstructured());
+ MCAuto<DataArrayInt> revNodArr(DataArrayInt::New()),revNodIArr(DataArrayInt::New());
+ thisu->getReverseNodalConnectivity(revNodArr,revNodIArr);
+ const int *revNod(revNodArr->begin()),*revNodI(revNodIArr->begin()),*nodal(_conn->begin());
+ MCAuto<DataArrayInt> d2Arr(DataArrayInt::New()),di2Arr(DataArrayInt::New()),rd2Arr(DataArrayInt::New()),rdi2Arr(DataArrayInt::New());
+ MCAuto<MEDCouplingUMesh> edges(thisu->buildDescendingConnectivity(d2Arr,di2Arr,rd2Arr,rdi2Arr)); thisu=0;
+ const int *d2(d2Arr->begin()),*rdi2(rdi2Arr->begin());
+ MCAuto<DataArrayDouble> edgesBaryArr(edges->computeCellCenterOfMass()),baryArr(computeCellCenterOfMass());
+ const int nbOfNodes(getNumberOfNodes()),offset0(nbOfNodes+edges->getNumberOfCells());
+ edges=0;
+ std::vector<const DataArrayDouble *> v(3); v[0]=getCoords(); v[1]=edgesBaryArr; v[2]=baryArr;
+ MCAuto<DataArrayDouble> zeArr(DataArrayDouble::Aggregate(v)); baryArr=0; edgesBaryArr=0;
+ std::string name("DualOf_"); name+=getName();
+ MCAuto<MEDCoupling1DGTUMesh> ret(MEDCoupling1DGTUMesh::New(name,INTERP_KERNEL::NORM_POLYGON)); ret->setCoords(zeArr);
+ MCAuto<DataArrayInt> cArr(DataArrayInt::New()),ciArr(DataArrayInt::New()); ciArr->alloc(nbOfNodes+1,1); ciArr->setIJ(0,0,0); cArr->alloc(0,1);
+ for(int i=0;i<nbOfNodes;i++,revNodI++)
+ {
+ int nbOfCellsSharingNode(revNodI[1]-revNodI[0]);
+ if(nbOfCellsSharingNode==0)
+ {
+ std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::computeDualMesh2D : Node #" << i << " is orphan !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ std::vector< std::vector<int> > polyg;
+ for(int j=0;j<nbOfCellsSharingNode;j++)
+ {
+ int curCellId(revNod[revNodI[0]+j]);
+ const int *connOfCurCell(nodal+3*curCellId);
+ std::size_t nodePosInCurCell(std::distance(connOfCurCell,std::find(connOfCurCell,connOfCurCell+4,i)));
+ std::vector<int> locV(3);
+ locV[0]=d2[3*curCellId+DUAL_TRI_0[2*nodePosInCurCell+0]]+nbOfNodes; locV[1]=curCellId+offset0; locV[2]=d2[3*curCellId+DUAL_TRI_0[2*nodePosInCurCell+1]]+nbOfNodes;
+ polyg.push_back(locV);
+ int kk(0);
+ for(int k=0;k<3;k++)
+ {
+ if(FACEID_NOT_SH_NODE[nodePosInCurCell]!=k)
+ {
+ const int *edgeId(d2+3*curCellId+k);
+ if(rdi2[*edgeId+1]-rdi2[*edgeId]==1)
+ {
+ std::vector<int> locV2(2);
+ int zeLocEdgeIdRel(DUAL_TRI_1[2*nodePosInCurCell+kk]);
+ if(zeLocEdgeIdRel>0)
+ { locV2[0]=d2[3*curCellId+zeLocEdgeIdRel-3]+nbOfNodes; locV2[1]=i; }
+ else
+ { locV2[0]=i; locV2[1]=d2[3*curCellId-zeLocEdgeIdRel-3]+nbOfNodes; }
+ polyg.push_back(locV2);
+ }
+ kk++;
+ }
+ }
+ }
+ std::vector<int> zePolyg(MEDCoupling1DGTUMesh::BuildAPolygonFromParts(polyg));
+ cArr->insertAtTheEnd(zePolyg.begin(),zePolyg.end());
+ ciArr->setIJ(i+1,0,cArr->getNumberOfTuples());
+ }
+ ret->setNodalConnectivity(cArr,ciArr);
+ return ret.retn();
+}
+
+/*!
+ * This method aggregate the bbox of each cell and put it into bbox
+ *
+ * \param [in] arcDetEps - a parameter specifying in case of 2D quadratic polygon cell the detection limit between linear and arc circle. (By default 1e-12)
+ * For all other cases this input parameter is ignored.
+ * \return DataArrayDouble * - newly created object (to be managed by the caller) \a this number of cells tuples and 2*spacedim components.
+ *
+ * \throw If \a this is not fully set (coordinates and connectivity).
+ * \throw If a cell in \a this has no valid nodeId.
+ */
+DataArrayDouble *MEDCoupling1SGTUMesh::getBoundingBoxForBBTree(double arcDetEps) const
+{
+ int spaceDim(getSpaceDimension()),nbOfCells(getNumberOfCells()),nbOfNodes(getNumberOfNodes()),nbOfNodesPerCell(getNumberOfNodesPerCell());
+ MCAuto<DataArrayDouble> ret(DataArrayDouble::New()); ret->alloc(nbOfCells,2*spaceDim);
+ double *bbox(ret->getPointer());
+ for(int i=0;i<nbOfCells*spaceDim;i++)
+ {
+ bbox[2*i]=std::numeric_limits<double>::max();
+ bbox[2*i+1]=-std::numeric_limits<double>::max();
+ }
+ const double *coordsPtr(_coords->getConstPointer());
+ const int *conn(_conn->getConstPointer());
+ for(int i=0;i<nbOfCells;i++)
+ {
+ int kk(0);
+ for(int j=0;j<nbOfNodesPerCell;j++,conn++)
+ {
+ int nodeId(*conn);
+ if(nodeId>=0 && nodeId<nbOfNodes)
+ {
+ for(int k=0;k<spaceDim;k++)
+ {
+ bbox[2*spaceDim*i+2*k]=std::min(bbox[2*spaceDim*i+2*k],coordsPtr[spaceDim*nodeId+k]);
+ bbox[2*spaceDim*i+2*k+1]=std::max(bbox[2*spaceDim*i+2*k+1],coordsPtr[spaceDim*nodeId+k]);
+ }
+ kk++;
+ }
+ }
+ if(kk==0)
+ {
+ std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::getBoundingBoxForBBTree : cell #" << i << " contains no valid nodeId !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ return ret.retn();
+}
+
+/*!
+ * Returns the cell field giving for each cell in \a this its diameter. Diameter means the max length of all possible SEG2 in the cell.
+ *
+ * \return a new instance of field containing the result. The returned instance has to be deallocated by the caller.
+ */
+MEDCouplingFieldDouble *MEDCoupling1SGTUMesh::computeDiameterField() const
+{
+ checkFullyDefined();
+ MCAuto<MEDCouplingFieldDouble> ret(MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME));
+ int nbCells(getNumberOfCells());
+ MCAuto<DataArrayDouble> arr(DataArrayDouble::New());
+ arr->alloc(nbCells,1);
+ INTERP_KERNEL::AutoCppPtr<INTERP_KERNEL::DiameterCalculator> dc(_cm->buildInstanceOfDiameterCalulator(getSpaceDimension()));
+ dc->computeFor1SGTUMeshFrmt(nbCells,_conn->begin(),getCoords()->begin(),arr->getPointer());
+ ret->setMesh(this);
+ ret->setArray(arr);
+ ret->setName("Diameter");
+ return ret.retn();
+}
+
+/*!
+ * This method invert orientation of all cells in \a this.
+ * After calling this method the absolute value of measure of cells in \a this are the same than before calling.
+ * This method only operates on the connectivity so coordinates are not touched at all.
+ */
+void MEDCoupling1SGTUMesh::invertOrientationOfAllCells()
+{
+ checkConsistencyOfConnectivity();
+ INTERP_KERNEL::AutoCppPtr<INTERP_KERNEL::OrientationInverter> oi(INTERP_KERNEL::OrientationInverter::BuildInstanceFrom(getCellModelEnum()));
+ int nbOfNodesPerCell((int)_cm->getNumberOfNodes()),nbCells(getNumberOfCells());
+ int *conn(_conn->getPointer());
+ for(int i=0;i<nbCells;i++)
+ oi->operate(conn+i*nbOfNodesPerCell,conn+(i+1)*nbOfNodesPerCell);
+ updateTime();
+}
+
+//==
+
+MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::New()
+{
+ return new MEDCoupling1DGTUMesh;
+}
+
+MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::New(const std::string& name, INTERP_KERNEL::NormalizedCellType type)
+{
+ if(type==INTERP_KERNEL::NORM_ERROR)
+ throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::New : NORM_ERROR is not a valid type to be used as base geometric type for a mesh !");
+ const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
+ if(!cm.isDynamic())
+ {
+ std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::New : the input geometric type " << cm.getRepr() << " is static ! Only dynamic types are allowed here !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ return new MEDCoupling1DGTUMesh(name,cm);
+}
+
+MEDCoupling1DGTUMesh::MEDCoupling1DGTUMesh()
+{
+}
+
+MEDCoupling1DGTUMesh::MEDCoupling1DGTUMesh(const std::string& name, const INTERP_KERNEL::CellModel& cm):MEDCoupling1GTUMesh(name,cm)
+{
+}
+
+MEDCoupling1DGTUMesh::MEDCoupling1DGTUMesh(const MEDCoupling1DGTUMesh& other, bool recDeepCpy):MEDCoupling1GTUMesh(other,recDeepCpy),_conn_indx(other._conn_indx),_conn(other._conn)
+{
+ if(recDeepCpy)
+ {
+ const DataArrayInt *c(other._conn);
+ if(c)
+ _conn=c->deepCopy();
+ c=other._conn_indx;
+ if(c)
+ _conn_indx=c->deepCopy();
+ }
+}
+
+MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::clone(bool recDeepCpy) const
+{
+ return new MEDCoupling1DGTUMesh(*this,recDeepCpy);
+}
+
+/*!
+ * This method behaves mostly like MEDCoupling1DGTUMesh::deepCopy method, except that only nodal connectivity arrays are deeply copied.
+ * The coordinates are shared between \a this and the returned instance.
+ *
+ * \return MEDCoupling1DGTUMesh * - A new object instance holding the copy of \a this (deep for connectivity, shallow for coordiantes)
+ * \sa MEDCoupling1DGTUMesh::deepCopy
+ */
+MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::deepCopyConnectivityOnly() const
+{
+ checkConsistencyLight();
+ MCAuto<MEDCoupling1DGTUMesh> ret(clone(false));
+ MCAuto<DataArrayInt> c(_conn->deepCopy()),ci(_conn_indx->deepCopy());
+ ret->setNodalConnectivity(c,ci);
+ return ret.retn();