Salome HOME
[EDF26707] : unpolygonize of input dataset before writing it
authorAnthony Geay <anthony.geay@edf.fr>
Thu, 26 Jan 2023 17:17:33 +0000 (18:17 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Thu, 26 Jan 2023 17:17:33 +0000 (18:17 +0100)
src/Plugins/MEDWriter/plugin/MEDWriterIO/vtkMEDWriter.cxx
src/Plugins/MEDWriter/plugin/MEDWriterIO/vtkMEDWriter.h
src/Plugins/MEDWriter/plugin/writers.xml

index b2af16f139361bfc4d94c6f81a891dd29aae1cbb..3b1b235d5ee1c3fd62e6f58bfd33b8d66def9a27 100644 (file)
@@ -55,6 +55,7 @@
 #include <vtkUnstructuredGrid.h>
 #include <vtkVariantArray.h>
 #include <vtkWarpScalar.h>
+#include <vtkAppendDataSets.h>
 
 #include "MEDCouplingFieldDouble.hxx"
 #include "MEDCouplingFieldFloat.hxx"
@@ -183,7 +184,7 @@ static void LoadFamGrpMapInfo(vtkMutableDirectedGraph* sil, std::string& meshNam
 }
 
 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,6 +273,22 @@ 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());
     VTKToMEDMemWriter::WriteMEDFileFromVTKGDS(mfd, input, timeStep, this->CurrentTimeIndex);
     VTKToMEDMemWriter::PutFamGrpInfoIfAny(mfd, meshName, groups, fams);
index 0521bde75bba029d50f2ac7e6df08a137f70beb9..381572830981195c664467552f50b31a8d055c2c 100644 (file)
@@ -37,6 +37,8 @@ public:
   int Write();
   vtkGetMacro(WriteAllTimeSteps, int);
   vtkSetMacro(WriteAllTimeSteps, int);
+  vtkGetMacro(UnPolygonize, int);
+  vtkSetMacro(UnPolygonize, int);
   vtkBooleanMacro(WriteAllTimeSteps, int);
 protected:
   vtkMEDWriter();
@@ -49,6 +51,7 @@ private:
   vtkMEDWriter(const vtkMEDWriter&);
   void operator=(const vtkMEDWriter&); // Not implemented.
  private:
+  int UnPolygonize;
   int WriteAllTimeSteps;
   int NumberOfTimeSteps;
   int CurrentTimeIndex;
index 29239b8a4d51102256a69e2ceac4afa998818188..895478f80c947dfdadf4925548b8b1018709747d 100644 (file)
        <BooleanDomain name="bool" />
        <Documentation>When WriteAllTimeSteps is turned ON, the writer is executed once for each timestep available from the reader.</Documentation>
      </IntVectorProperty>
+     <IntVectorProperty command="SetUnPolygonize" default_values="0" name="UnPolygonize" number_of_elements="1">
+       <BooleanDomain name="bool" />
+       <Documentation>When UnPolygonize is turned ON, the writer preprocess input Data by converting it from PolyData to UnstructuredData. Doing so polygons will be converted into triangles or quadrangles</Documentation>
+     </IntVectorProperty>
      <Hints>
        <Property name="Input" show="0" />
        <Property name="FileName" show="0" />