Salome HOME
Generalization of meshes without cells but only nodes
[modules/paravis.git] / src / Plugins / MEDWriter / IO / vtkMEDWriter.cxx
index 8fd42052078a0b53cac292ba4135329cc7a2e6d8..69e1cba972de2130a23de132e524909984f7c71c 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "vtkAdjacentVertexIterator.h"
 #include "vtkIntArray.h"
+#include "vtkLongArray.h"
 #include "vtkCellData.h"
 #include "vtkPointData.h"
 #include "vtkFloatArray.h"
@@ -60,6 +61,7 @@
 #include "MEDFileField.hxx"
 #include "MEDFileData.hxx"
 #include "MEDCouplingMemArray.hxx"
+#include "MEDCouplingFieldInt.hxx"
 #include "MEDCouplingFieldDouble.hxx"
 #include "MEDCouplingRefCountObject.hxx"
 
@@ -86,6 +88,7 @@ using MEDCoupling::MEDCouplingMesh;
 using MEDCoupling::MEDCouplingUMesh;
 using MEDCoupling::MEDCouplingCMesh;
 using MEDCoupling::MEDCouplingFieldDouble;
+using MEDCoupling::MEDCouplingFieldInt;
 using MEDCoupling::MCAuto;
 
 vtkStandardNewMacro(vtkMEDWriter);
@@ -150,6 +153,13 @@ DataArrayInt *ConvertVTKArrayToMCArrayInt(vtkDataArray *data)
       std::copy(pt,pt+nbElts,ptOut);
       return ret.retn();
     }
+  vtkLongArray *d1(vtkLongArray::SafeDownCast(data));
+  if(d1)
+    {
+      const long *pt(d1->GetPointer(0));
+      std::copy(pt,pt+nbElts,ptOut);
+      return ret.retn();
+    }
   std::ostringstream oss;
   oss << "ConvertVTKArrayToMCArrayInt : unrecognized array \"" << typeid(*data).name() << "\" type !";
   throw MZCException(oss.str());
@@ -199,7 +209,8 @@ DataArray *ConvertVTKArrayToMCArray(vtkDataArray *data)
   if(d0 || d1)
     return ConvertVTKArrayToMCArrayDouble(data);
   vtkIntArray *d2(vtkIntArray::SafeDownCast(data));
-  if(d2)
+  vtkLongArray *d3(vtkLongArray::SafeDownCast(data));
+  if(d2 || d3)
     return ConvertVTKArrayToMCArrayInt(data);
   std::ostringstream oss;
   oss << "ConvertVTKArrayToMCArray : unrecognized array \"" << typeid(*data).name() << "\" type !";
@@ -343,17 +354,21 @@ void AppendMCFieldFrom(MEDCoupling::TypeOfField tf, MEDCouplingMesh *mesh, MEDFi
       fieldName=daiPtr->getName();
       if((fieldName!=FAMFIELD_FOR_CELLS || tf!=MEDCoupling::ON_CELLS) && (fieldName!=FAMFIELD_FOR_NODES || tf!=MEDCoupling::ON_NODES))
         {
-          MCAuto<MEDCouplingFieldDouble> f(MEDCouplingFieldDouble::New(tf));
+          MCAuto<MEDCouplingFieldInt> f(MEDCouplingFieldInt::New(tf));
           f->setName(fieldName);
           f->setMesh(mesh);
           MCAuto<MEDFileIntFieldMultiTS> fmts(MEDFileIntFieldMultiTS::New());
           MCAuto<MEDFileIntField1TS> f1ts(MEDFileIntField1TS::New());
           if(!n2oPtr)
-            f1ts->setFieldNoProfileSBT(f,daiPtr);
+            {
+              f->setArray(dai);
+              f1ts->setFieldNoProfileSBT(f);
+            }
           else
             {
               MCAuto<DataArrayInt> dai2(daiPtr->selectByTupleId(n2oPtr->begin(),n2oPtr->end()));
-              f1ts->setFieldNoProfileSBT(f,dai2);
+              f->setArray(dai2);
+              f1ts->setFieldNoProfileSBT(f);
             }
           fmts->pushBackTimeStep(f1ts);
           fs->pushField(fmts);
@@ -480,7 +495,14 @@ void AddNodeFields(MEDFileData *mfd, vtkDataSetAttributes *dsa)
   MEDFileUMesh *mmu(dynamic_cast<MEDFileUMesh *>(mm));
   if(!mmu)
     throw MZCException("AddNodeFields : internal error 2 !");
-  MCAuto<MEDCouplingUMesh> mesh(mmu->getMeshAtLevel(0));
+  MCAuto<MEDCouplingUMesh> mesh;
+  if(!mmu->getNonEmptyLevels().empty())
+    mesh=mmu->getMeshAtLevel(0);
+  else
+    {
+      mesh=MEDCouplingUMesh::Build0DMeshFromCoords(mmu->getCoords());
+      mesh->setName(mmu->getName());
+    }
   int nba(dsa->GetNumberOfArrays());
   for(int i=0;i<nba;i++)
     {
@@ -699,7 +721,6 @@ void ConvertFromUnstructuredGrid(MEDFileData *ret, vtkUnstructuredGrid *ds, cons
         }
     }
   int dummy(0);
-  int meshDim(lev->getMaxValue(dummy));
   MCAuto<DataArrayInt> levs(lev->getDifferentValues());
   std::vector< MicroField > ms;
   vtkIdTypeArray *faces(ds->GetFaces()),*faceLoc(ds->GetFaceLocations());