Salome HOME
Little refactoring of progeny mechanism to avoid if.
[modules/med.git] / src / MEDCoupling / MEDCouplingCurveLinearMesh.cxx
index ee9848dfb970e5a6df919a425d0be8c029bd349e..60ab76f40d4f0af01563998040622c31a7b6a912 100644 (file)
@@ -87,11 +87,10 @@ std::size_t MEDCouplingCurveLinearMesh::getHeapMemorySizeWithoutChildren() const
   return ret;
 }
 
-std::vector<const BigMemoryObject *> MEDCouplingCurveLinearMesh::getDirectChildren() const
+std::vector<const BigMemoryObject *> MEDCouplingCurveLinearMesh::getDirectChildrenWithNull() const
 {
   std::vector<const BigMemoryObject *> ret;
-  if((const DataArrayDouble *)_coords)
-    ret.push_back((const DataArrayDouble *)_coords);
+  ret.push_back((const DataArrayDouble *)_coords);
   return ret;
 }
 
@@ -160,7 +159,7 @@ bool MEDCouplingCurveLinearMesh::isEqualWithoutConsideringStr(const MEDCouplingM
 }
 
 void MEDCouplingCurveLinearMesh::checkDeepEquivalWith(const MEDCouplingMesh *other, int cellCompPol, double prec,
-                                            DataArrayInt *&cellCor, DataArrayInt *&nodeCor) const throw(INTERP_KERNEL::Exception)
+                                                      DataArrayInt *&cellCor, DataArrayInt *&nodeCor) const
 {
   if(!isEqualWithoutConsideringStr(other,prec))
     throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::checkDeepEquivalWith : Meshes are not the same !");
@@ -168,14 +167,13 @@ void MEDCouplingCurveLinearMesh::checkDeepEquivalWith(const MEDCouplingMesh *oth
 
 /*!
  * Nothing is done here (except to check that the other is a ParaMEDMEM::MEDCouplingCurveLinearMesh instance too).
- * The user intend that the nodes are the same, so by construction of ParaMEDMEM::MEDCouplingCurveLinearMesh, 'this' and 'other' are the same !
+ * The user intend that the nodes are the same, so by construction of ParaMEDMEM::MEDCouplingCurveLinearMesh, \a this and \a other are the same !
  */
 void MEDCouplingCurveLinearMesh::checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *other, int cellCompPol, double prec,
-                                                       DataArrayInt *&cellCor) const throw(INTERP_KERNEL::Exception)
+                                                                 DataArrayInt *&cellCor) const
 {
-  const MEDCouplingCurveLinearMesh *otherC=dynamic_cast<const MEDCouplingCurveLinearMesh *>(other);
-  if(!otherC)
-    throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::checkDeepEquivalOnSameNodesWith : other is NOT a cartesian mesh ! Impossible to check equivalence !");
+  if(!isEqualWithoutConsideringStr(other,prec))
+    throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::checkDeepEquivalOnSameNodesWith : Meshes are not the same !");
 }
 
 void MEDCouplingCurveLinearMesh::checkCoherency() const
@@ -215,43 +213,13 @@ void MEDCouplingCurveLinearMesh::checkCoherency2(double eps) const
 int MEDCouplingCurveLinearMesh::getNumberOfCells() const
 {
   checkCoherency();
-  std::size_t nbOfCells=1,i=0;
-  for(std::vector<int>::const_iterator it=_structure.begin();it!=_structure.end();it++,i++)
-    nbOfCells*=(*it)-1;
-  return (int)nbOfCells;
+  return MEDCouplingStructuredMesh::getNumberOfCells();
 }
 
 int MEDCouplingCurveLinearMesh::getNumberOfNodes() const
 {
   checkCoherency();
-  std::size_t nbOfNodes=1;
-  for(std::vector<int>::const_iterator it=_structure.begin();it!=_structure.end();it++)
-    nbOfNodes*=(*it);
-  return (int)nbOfNodes;
-}
-
-void MEDCouplingCurveLinearMesh::getSplitCellValues(int *res) const
-{
-  int meshDim=getMeshDimension();
-  for(int l=0;l<meshDim;l++)
-    {
-      int val=1;
-      for(int p=0;p<meshDim-l-1;p++)
-        val*=_structure[p]-1;
-      res[meshDim-l-1]=val;
-    }
-}
-
-void MEDCouplingCurveLinearMesh::getSplitNodeValues(int *res) const
-{
-  int meshDim=getMeshDimension();
-  for(int l=0;l<meshDim;l++)
-    {
-      int val=1;
-      for(int p=0;p<meshDim-l-1;p++)
-        val*=_structure[p];
-      res[meshDim-l-1]=val;
-    }
+  return MEDCouplingStructuredMesh::getNumberOfNodes();
 }
 
 void MEDCouplingCurveLinearMesh::getNodeGridStructure(int *res) const
@@ -259,6 +227,12 @@ void MEDCouplingCurveLinearMesh::getNodeGridStructure(int *res) const
   std::copy(_structure.begin(),_structure.end(),res);
 }
 
+/*!
+ * MEDCouplingCurveLinearMesh has the property to define 2 space dimensions. One coming from its coordinates. The other coming from the node structure.
+ * Normally they should be equal ! This method returns the space dimension from coordinates. If the other one is requested call getSpaceDimensionOnNodeStruct.
+ *
+ * \sa MEDCouplingStructuredMesh::getSpaceDimensionOnNodeStruct
+ */
 int MEDCouplingCurveLinearMesh::getSpaceDimension() const
 {
   if(!((const DataArrayDouble *)_coords))
@@ -266,11 +240,6 @@ int MEDCouplingCurveLinearMesh::getSpaceDimension() const
   return _coords->getNumberOfComponents();
 }
 
-int MEDCouplingCurveLinearMesh::getMeshDimension() const
-{
-  return (int)_structure.size();
-}
-
 void MEDCouplingCurveLinearMesh::getCoordinatesOfNode(int nodeId, std::vector<double>& coo) const
 {
   if(!((const DataArrayDouble *)_coords))
@@ -350,11 +319,11 @@ std::vector<int> MEDCouplingCurveLinearMesh::getNodeGridStructure() const
 MEDCouplingStructuredMesh *MEDCouplingCurveLinearMesh::buildStructuredSubPart(const std::vector< std::pair<int,int> >& cellPart) const
 {
   checkCoherency();
-  int dim(getMeshDimension());
+  int dim(getSpaceDimension());
   std::vector<int> dims(getMeshDimension());
   if(dim!=(int)cellPart.size())
     {
-      std::ostringstream oss; oss << "MEDCouplingCurveLinearMesh::buildStructuredSubPart : the mesh dimension is " << dim << " and cell part size is " << cellPart.size() << " !";
+      std::ostringstream oss; oss << "MEDCouplingCurveLinearMesh::buildStructuredSubPart : the space dimension is " << dim << " and cell part size is " << cellPart.size() << " !";
       throw INTERP_KERNEL::Exception(oss.str().c_str());
     }
   std::vector< std::pair<int,int> > nodePartFormat(cellPart);
@@ -393,7 +362,7 @@ MEDCouplingFieldDouble *MEDCouplingCurveLinearMesh::getMeasureField(bool isAbs)
   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
   field->setName(name); field->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(this)); field->synchronizeTimeWithMesh();
   switch(meshDim)
-    {
+  {
     case 3:
       { getMeasureFieldMeshDim3(isAbs,field); return field.retn(); }
     case 2:
@@ -402,7 +371,7 @@ MEDCouplingFieldDouble *MEDCouplingCurveLinearMesh::getMeasureField(bool isAbs)
       { getMeasureFieldMeshDim1(isAbs,field); return field.retn(); }
     default:
       throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::getMeasureField : mesh dimension must be in [1,2,3] !");
-    }
+  }
 }
 
 /*!
@@ -550,7 +519,7 @@ int MEDCouplingCurveLinearMesh::getCellContainingPoint(const double *pos, double
   if(nbOfNodes==1)
     throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::getCellContainingPoint : No cells in this !");
   switch(getMeshDimension())
-    {
+  {
     case 1:
       if(spaceDim==1)
         {
@@ -662,7 +631,7 @@ int MEDCouplingCurveLinearMesh::getCellContainingPoint(const double *pos, double
       }
     default:
       throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::getCellContainingPoint : mesh dimension managed are 1, 2 or 3 !");
-    }
+  }
 }
 
 void MEDCouplingCurveLinearMesh::rotate(const double *center, const double *vector, double angle)
@@ -740,7 +709,7 @@ DataArrayDouble *MEDCouplingCurveLinearMesh::getBarycenterAndOwner() const
   ret->alloc(nbOfCells,spaceDim);
   ret->copyStringInfoFrom(*getCoords());
   switch(meshDim)
-    {
+  {
     case 3:
       { getBarycenterAndOwnerMeshDim3(ret); return ret.retn(); }
     case 2:
@@ -749,7 +718,7 @@ DataArrayDouble *MEDCouplingCurveLinearMesh::getBarycenterAndOwner() const
       { getBarycenterAndOwnerMeshDim1(ret); return ret.retn(); }
     default:
       throw INTERP_KERNEL::Exception("MEDCouplingCurveLinearMesh::getBarycenterAndOwner : mesh dimension must be in [1,2,3] !");
-    }
+  }
 }
 
 DataArrayDouble *MEDCouplingCurveLinearMesh::computeIsoBarycenterOfNodesPerCell() const
@@ -948,6 +917,11 @@ void MEDCouplingCurveLinearMesh::reprQuickOverview(std::ostream& stream) const
   coo->reprQuickOverviewData(stream,200);
 }
 
+std::string MEDCouplingCurveLinearMesh::getVTKFileExtension() const
+{
+  return std::string("vts");
+}
+
 std::string MEDCouplingCurveLinearMesh::getVTKDataSetType() const
 {
   return std::string("StructuredGrid");