Salome HOME
Adding a MEDReader Group Reader that reads a file series of .med into a multiblock
authorMathieu Westphal <mathieu.westphal@kitware.com>
Wed, 21 Sep 2022 08:01:26 +0000 (08:01 +0000)
committerMathieu Westphal <mathieu.westphal@kitware.com>
Wed, 21 Sep 2022 08:01:26 +0000 (08:01 +0000)
src/Plugins/MEDReader/plugin/MEDReaderIO/CMakeLists.txt
src/Plugins/MEDReader/plugin/MEDReaderIO/vtk.module
src/Plugins/MEDReader/plugin/MEDReaderIO/vtkFileSeriesGroupReader.cxx [new file with mode: 0644]
src/Plugins/MEDReader/plugin/MEDReaderIO/vtkFileSeriesGroupReader.h [new file with mode: 0644]
src/Plugins/MEDReader/plugin/ParaViewPlugin/Resources/MEDReaderServer.xml

index f42fda2954b0de06cc1654bcb2a50d407f7493b0..00b3baf1039e55bcdc7eb4a87a6b400af93017ef 100644 (file)
@@ -29,6 +29,7 @@ set(classes
   vtkGroupAsMultiBlock
   vtkGroupsNames
   vtkUgSelectCellIds
+  vtkFileSeriesGroupReader
 )
 
 vtk_module_add_module(MEDReaderIO
index 6072a2b27807a49f01da529d315063999f833b18..849f959d27f4faf6ff21bc9748d091558307ca8c 100644 (file)
@@ -5,7 +5,9 @@ DEPENDS
   VTK::FiltersExtraction
   VTK::IOLegacy
   ParaView::RemotingCore
+  ParaView::VTKExtensionsIOCore
 PRIVATE_DEPENDS
   VTK::IOLegacy
   ParaView::VTKExtensionsFiltersRendering
+  ParaView::VTKExtensionsFiltersGeneral
   ParaView::VTKExtensionsMisc
diff --git a/src/Plugins/MEDReader/plugin/MEDReaderIO/vtkFileSeriesGroupReader.cxx b/src/Plugins/MEDReader/plugin/MEDReaderIO/vtkFileSeriesGroupReader.cxx
new file mode 100644 (file)
index 0000000..0bd9080
--- /dev/null
@@ -0,0 +1,133 @@
+#include "vtkFileSeriesGroupReader.h"
+
+#include <vtkInformation.h>
+#include <vtkInformationVector.h>
+#include <vtkMultiBlockDataSet.h>
+#include <vtkObjectFactory.h>
+#include <vtkSmartPointer.h>
+#include <vtkStreamingDemandDrivenPipeline.h>
+
+#include <vector>
+#include <string>
+
+vtkStandardNewMacro(vtkFileSeriesGroupReader);
+
+//=============================================================================
+struct vtkFileSeriesGroupReaderInternals
+{
+  std::vector<std::string> FileNames;
+};
+
+//=============================================================================
+vtkFileSeriesGroupReader::vtkFileSeriesGroupReader()
+  : Internals(new vtkFileSeriesGroupReaderInternals())
+{
+  this->SetNumberOfInputPorts(0);
+  this->SetNumberOfOutputPorts(1);
+}
+
+//-----------------------------------------------------------------------------
+vtkFileSeriesGroupReader::~vtkFileSeriesGroupReader() = default;
+
+//----------------------------------------------------------------------------
+void vtkFileSeriesGroupReader::AddFileName(const char* name)
+{
+  // Make sure the reader always has a filename set
+  this->ReaderSetFileName(name);
+
+  this->AddFileNameInternal(name);
+  this->Modified();
+}
+
+//----------------------------------------------------------------------------
+void vtkFileSeriesGroupReader::RemoveAllFileNames()
+{
+  this->RemoveAllFileNamesInternal();
+  this->Modified();
+}
+
+//----------------------------------------------------------------------------
+void vtkFileSeriesGroupReader::RemoveAllFileNamesInternal()
+{
+  this->Internals->FileNames.clear();
+}
+
+//----------------------------------------------------------------------------
+void vtkFileSeriesGroupReader::AddFileNameInternal(const char* name)
+{
+  this->Internals->FileNames.emplace_back(name);
+}
+
+//----------------------------------------------------------------------------
+unsigned int vtkFileSeriesGroupReader::GetNumberOfFileNames()
+{
+  return static_cast<unsigned int>(this->Internals->FileNames.size());
+}
+
+//----------------------------------------------------------------------------
+const char* vtkFileSeriesGroupReader::GetFileName(unsigned int idx)
+{
+  if (idx >= this->Internals->FileNames.size())
+  {
+    return nullptr;
+  }
+  return this->Internals->FileNames[idx].c_str();
+}
+
+//----------------------------------------------------------------------------
+int vtkFileSeriesGroupReader::CanReadFile(const char* filename)
+{
+  if (!this->Reader)
+  {
+    return 0;
+  }
+
+  return this->ReaderCanReadFile(filename);
+}
+
+//----------------------------------------------------------------------------
+int vtkFileSeriesGroupReader::RequestInformation(
+  vtkInformation* request, vtkInformationVector** inputVector, vtkInformationVector* outputVector)
+{
+  return this->Reader->ProcessRequest(request, inputVector, outputVector);
+}
+
+//----------------------------------------------------------------------------
+int vtkFileSeriesGroupReader::RequestData(vtkInformation* vtkNotUsed(request),
+  vtkInformationVector** vtkNotUsed(inputVector), vtkInformationVector* outputVector)
+{
+  auto output = vtkMultiBlockDataSet::GetData(outputVector, 0);
+  output->SetNumberOfBlocks(this->GetNumberOfFileNames());
+
+  vtkInformation* info = outputVector->GetInformationObject(0);
+  double time = info->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP());
+
+  for (unsigned int i = 0; i < this->GetNumberOfFileNames(); i++)
+  {
+    this->ReaderSetFileName(this->GetFileName(i));
+    this->Reader->UpdateTimeStep(time);
+    vtkDataObject* outputReader = this->Reader->GetOutputDataObject(0);
+    vtkSmartPointer<vtkDataObject> outputLeaf = vtkSmartPointer<vtkDataObject>::Take(outputReader->NewInstance());
+    outputLeaf->DeepCopy(outputReader);
+    output->SetBlock(i, outputLeaf);
+  }
+
+  return 1;
+}
+//------------------------------------------------------------------------------
+int vtkFileSeriesGroupReader::FillOutputPortInformation(
+  int vtkNotUsed(port), vtkInformation* info)
+{
+  info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkMultiBlockDataSet");
+  return 1;
+}
+
+//-----------------------------------------------------------------------------
+void vtkFileSeriesGroupReader::PrintSelf(ostream& os, vtkIndent indent)
+{
+  this->Superclass::PrintSelf(os, indent);
+
+  os << indent << "MetaFileName: " << (this->_MetaFileName ? this->_MetaFileName : "(none)")
+     << endl;
+}
diff --git a/src/Plugins/MEDReader/plugin/MEDReaderIO/vtkFileSeriesGroupReader.h b/src/Plugins/MEDReader/plugin/MEDReaderIO/vtkFileSeriesGroupReader.h
new file mode 100644 (file)
index 0000000..709e23e
--- /dev/null
@@ -0,0 +1,64 @@
+#ifndef vtkFileSeriesGroupReader_h
+#define vtkFileSeriesGroupReader_h
+
+#include "vtkMetaReader.h"
+
+#include <memory>
+
+struct vtkFileSeriesGroupReaderInternals;
+
+class VTK_EXPORT vtkFileSeriesGroupReader : public vtkMetaReader
+{
+public:
+  static vtkFileSeriesGroupReader* New();
+  vtkTypeMacro(vtkFileSeriesGroupReader, vtkMetaReader);
+  void PrintSelf(ostream& os, vtkIndent indent) override;
+
+  /**
+   * CanReadFile is forwarded to the internal reader if it supports it.
+   */
+  virtual int CanReadFile(const char* filename);
+
+  /**
+   * Adds names of files to be read. The files are read in the order
+   * they are added.
+   */
+  virtual void AddFileName(const char* fname);
+
+  /**
+   * Remove all file names.
+   */
+  virtual void RemoveAllFileNames();
+
+  /**
+   * Returns the number of file names added by AddFileName.
+   */
+  virtual unsigned int GetNumberOfFileNames();
+
+  /**
+   * Returns the name of a file with index idx.
+   */
+  virtual const char* GetFileName(unsigned int idx);
+
+protected:
+  vtkFileSeriesGroupReader();
+  ~vtkFileSeriesGroupReader() override;
+
+  /**
+   * Add/Remove filenames without changing the MTime.
+   */
+  void RemoveAllFileNamesInternal();
+  void AddFileNameInternal(const char*);
+
+  int RequestInformation(vtkInformation* request, vtkInformationVector** inputVector, vtkInformationVector* outputVector);
+  int RequestData(vtkInformation* vtkNotUsed(request), vtkInformationVector** inputVector, vtkInformationVector* outputVector);
+  int FillOutputPortInformation(int vtkNotUsed(port), vtkInformation* info);
+
+private:
+  vtkFileSeriesGroupReader(const vtkFileSeriesGroupReader&) = delete;
+  void operator=(const vtkFileSeriesGroupReader&) = delete;
+
+  std::unique_ptr<vtkFileSeriesGroupReaderInternals> Internals;
+};
+
+#endif
index 346d0e80fd801a0cd3a6c70640cebe531226de87..fe4a62ec5a550255614a15fda036848893023743 100644 (file)
       </IntVectorProperty>
 
    </SourceProxy>
+
+   <SourceProxy class="vtkFileSeriesGroupReader"
+                 file_name_method="SetFileName"
+                 label="MED Reader Group"
+                 name="MEDReaderGroup"
+                 si_class="vtkSIMetaReaderProxy">
+      <SubProxy>
+        <Proxy name="Reader"
+               proxygroup="sources"
+               proxyname="MEDReader"></Proxy>
+        <ExposedProperties>
+          <Property name="Reload" />
+          <Property name="FieldsTreeInfo" />
+          <Property name="FieldsStatus" />
+          <Property name="VectorsProperty" />
+          <Property name="Separator" />
+          <Property name="TimeModeProperty" />
+          <Property name="TimesFlagsInfo" />
+          <Property name="TimesFlagsStatus" />
+          <Property name="GhostCellGeneratorCallForPara" />
+        </ExposedProperties>
+      </SubProxy>
+      <StringVectorProperty animateable="0"
+                            clean_command="RemoveAllFileNames"
+                            command="AddFileName"
+                            name="FileNames"
+                            number_of_elements="0"
+                            panel_visibility="never"
+                            repeat_command="1">
+        <FileListDomain name="files" />
+        <Documentation>The list of files to be read by the 
+        reader.</Documentation>
+      </StringVectorProperty>
+      <DoubleVectorProperty
+          information_only="1"
+          name="TimestepValues"
+          repeatable="1">
+        <TimeStepsInformationHelper />
+      </DoubleVectorProperty>
+
+      <Hints>
+             <ReaderFactory extensions="med rmed"
+                                  file_description="MED Files">
+        </ReaderFactory>
+      </Hints>
+   </SourceProxy>
   </ProxyGroup>
 
   <ProxyGroup name="filters">