Salome HOME
updated copyright message
[modules/paravis.git] / src / Plugins / MEDWriter / plugin / MEDWriterIO / vtkMEDWriter.cxx
index 6e73c6ac7afa4c9c463341990dd82d8edbc06a72..9f5a6c5b632d613802d11ea6cc88290c83598588 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2016-2022  CEA/DEN, EDF R&D
+// Copyright (C) 2016-2023  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -55,6 +55,7 @@
 #include <vtkUnstructuredGrid.h>
 #include <vtkVariantArray.h>
 #include <vtkWarpScalar.h>
+#include <vtkAppendDataSets.h>
 
 #include "MEDCouplingFieldDouble.hxx"
 #include "MEDCouplingFieldFloat.hxx"
@@ -74,12 +75,12 @@ vtkStandardNewMacro(vtkMEDWriter)
 
 using MEDCoupling::MCAuto;
 using MEDCoupling::MEDFileData;
-using VTKToMEDMem::Fam;
-using VTKToMEDMem::Grp;
+using VTKToMEDMemWriter::Fam;
+using VTKToMEDMemWriter::Grp;
 
-vtkInformationDataObjectMetaDataKey* GetMEDReaderMetaDataIfAny()
+static vtkInformationDataObjectMetaDataKey* GetMEDReaderMetaDataIfAny()
 {
-  static const char ZE_KEY[] = "vtkMEDReader::META_DATA";
+  static const char ZE_KEY[] = "vtkFileSeriesGroupReader::META_DATA";
   MEDCoupling::GlobalDict* gd(MEDCoupling::GlobalDict::GetInstance());
   if (!gd->hasKey(ZE_KEY))
     return 0;
@@ -90,7 +91,7 @@ vtkInformationDataObjectMetaDataKey* GetMEDReaderMetaDataIfAny()
   return reinterpret_cast<vtkInformationDataObjectMetaDataKey*>(pt);
 }
 
-bool IsInformationOK(vtkInformation* info)
+static bool IsInformationOK(vtkInformation* info)
 {
   vtkInformationDataObjectMetaDataKey* key(GetMEDReaderMetaDataIfAny());
   if (!key)
@@ -116,7 +117,7 @@ bool IsInformationOK(vtkInformation* info)
   return false;
 }
 
-void LoadFamGrpMapInfo(vtkMutableDirectedGraph* sil, std::string& meshName,
+static void LoadFamGrpMapInfo(vtkMutableDirectedGraph* sil, std::string& meshName,
   std::vector<Grp>& groups, std::vector<Fam>& fams)
 {
   if (!sil)
@@ -183,7 +184,7 @@ void LoadFamGrpMapInfo(vtkMutableDirectedGraph* sil, std::string& meshName,
 }
 
 vtkMEDWriter::vtkMEDWriter()
-  : WriteAllTimeSteps(0)
+  : UnPolygonize(0),WriteAllTimeSteps(0)
   , NumberOfTimeSteps(0)
   , CurrentTimeIndex(0)
   , FileName(0)
@@ -261,8 +262,8 @@ int vtkMEDWriter::RequestData(
       LoadFamGrpMapInfo(famGrpGraph, meshName, groups, fams);
     }
     vtkInformation* outInfo(outputVector->GetInformationObject(0));
-    vtkDataObject* input(vtkDataObject::SafeDownCast(inputInfo->Get(vtkDataObject::DATA_OBJECT())));
-    if (!input)
+    vtkDataObject* inputBase(vtkDataObject::SafeDownCast(inputInfo->Get(vtkDataObject::DATA_OBJECT())));
+    if (!inputBase)
       throw MZCException(
         "Not recognized data object in input of the MEDWriter ! Maybe not implemented yet !");
     double timeStep;
@@ -272,9 +273,25 @@ int vtkMEDWriter::RequestData(
       timeStep = input->GetInformation()->Get(vtkDataObject::DATA_TIME_STEP());
     }
     ////////////
+    vtkDataObject* input = inputBase;
+    vtkSmartPointer<vtkDataObject> inputUnpoly;
+    if(this->UnPolygonize)
+    {
+      vtkPointSet *inputPS = vtkPointSet::SafeDownCast(input);
+      if(!inputPS)
+        throw MZCException("UnPolygonize is activated whereas it is not a PointSet type !");
+      vtkSmartPointer<vtkAppendDataSets> ads = vtkSmartPointer<vtkAppendDataSets>::New();
+      ads->SetInputData(inputPS);
+      ads->Update();
+      vtkDataObject *inputPostPro = ads->GetOutputDataObject(0);
+      inputPostPro->Register(nullptr);
+      inputUnpoly.TakeReference(inputPostPro);
+      input = inputPostPro;
+    }
+    ////////////
     MCAuto<MEDFileData> mfd(MEDFileData::New());
-    WriteMEDFileFromVTKGDS(mfd, input, timeStep, this->CurrentTimeIndex);
-    PutFamGrpInfoIfAny(mfd, meshName, groups, fams);
+    VTKToMEDMemWriter::WriteMEDFileFromVTKGDS(mfd, input, timeStep, this->CurrentTimeIndex);
+    VTKToMEDMemWriter::PutFamGrpInfoIfAny(mfd, meshName, groups, fams);
     if (this->WriteAllTimeSteps == 0 ||
       (this->WriteAllTimeSteps != 0 && this->CurrentTimeIndex == 0))
       mfd->write(this->FileName, 2);