From 1cacb83177e9b9b5ced7fce4358f4b5d06d17c90 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Wed, 12 Aug 2020 08:33:13 +0200 Subject: [PATCH] Into MEDReader plugin NewGroupsNames filter linked with GroupAsMultiBlock filter --- .../plugin/MEDReaderIO/CMakeLists.txt | 1 + .../plugin/MEDReaderIO/vtkGroupsNames.cxx | 147 ++++++++++++++++++ .../plugin/MEDReaderIO/vtkGroupsNames.h | 39 +++++ .../Resources/MEDReaderServer.xml | 15 ++ .../MEDReader/plugin/Test/testMEDReader22.py | 10 ++ 5 files changed, 212 insertions(+) create mode 100644 src/Plugins/MEDReader/plugin/MEDReaderIO/vtkGroupsNames.cxx create mode 100644 src/Plugins/MEDReader/plugin/MEDReaderIO/vtkGroupsNames.h diff --git a/src/Plugins/MEDReader/plugin/MEDReaderIO/CMakeLists.txt b/src/Plugins/MEDReader/plugin/MEDReaderIO/CMakeLists.txt index 6d671f2b..3d9bea0b 100644 --- a/src/Plugins/MEDReader/plugin/MEDReaderIO/CMakeLists.txt +++ b/src/Plugins/MEDReader/plugin/MEDReaderIO/CMakeLists.txt @@ -27,6 +27,7 @@ set(classes vtkMEDReader vtkPVMetaDataInformation vtkGroupAsMultiBlock + vtkGroupsNames vtkUgSelectCellIds ) diff --git a/src/Plugins/MEDReader/plugin/MEDReaderIO/vtkGroupsNames.cxx b/src/Plugins/MEDReader/plugin/MEDReaderIO/vtkGroupsNames.cxx new file mode 100644 index 00000000..3ba75301 --- /dev/null +++ b/src/Plugins/MEDReader/plugin/MEDReaderIO/vtkGroupsNames.cxx @@ -0,0 +1,147 @@ +// Copyright (C) 2020 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Anthony Geay (EDF R&D) + +#include "vtkGroupsNames.h" +#include "ExtractGroupHelper.h" +#include "vtkMEDReader.h" +#include "vtkUgSelectCellIds.h" +#include "MEDFileFieldRepresentationTree.hxx" +#include "VTKMEDTraits.hxx" + +#include +#include +#include "vtkMutableDirectedGraph.h" +#include "vtkInformationDataObjectMetaDataKey.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "vtkTable.h" +#include "vtkStringArray.h" + +class vtkGroupsNamesInternal : public ExtractGroupInternal +{ +}; + +vtkStandardNewMacro(vtkGroupsNames); + +vtkGroupsNames::vtkGroupsNames():Internal(new ExtractGroupInternal) +{ +} + +vtkGroupsNames::~vtkGroupsNames() +{ + delete this->Internal; +} + +int vtkGroupsNames::RequestInformation(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) +{ + vtkInformation *outInfo(outputVector->GetInformationObject(0)); + vtkInformation *inputInfo(inputVector[0]->GetInformationObject(0)); + if(!ExtractGroupInternal::IndependantIsInformationOK(vtkMEDReader::META_DATA(),inputInfo)) + { + vtkErrorMacro("No SIL Data available ! The source of this filter must be MEDReader !"); + return 0; + } + vtkMutableDirectedGraph *mdg(vtkMutableDirectedGraph::SafeDownCast(inputInfo->Get(vtkMEDReader::META_DATA()))); + this->Internal->loadFrom(mdg); + return 1; +} + +int vtkGroupsNames::RequestData(vtkInformation *vtkNotUsed(request), vtkInformationVector **inputVector, vtkInformationVector *outputVector) +{ + vtkInformation* inputInfo=inputVector[0]->GetInformationObject(0); + vtkDataSet *input(nullptr); + vtkMultiBlockDataSet *inputMB(vtkMultiBlockDataSet::SafeDownCast(inputInfo->Get(vtkDataObject::DATA_OBJECT()))); + if(inputMB) + { + if(inputMB->GetNumberOfBlocks()!=1) + { + vtkErrorMacro("vtkGroupsNames::RequestData : input has not the right number of parts ! Expected 1 !"); + return 0; + } + input = vtkDataSet::SafeDownCast(inputMB->GetBlock(0)); + } + else + { + input = vtkDataSet::SafeDownCast(inputInfo->Get(vtkDataObject::DATA_OBJECT())); + } + if(!input) + { + vtkErrorMacro("vtkGroupsNames::RequestData : input is neither a DataSet nor a MultiblockDataSet !"); + return 0; + } + vtkInformation *info(input->GetInformation()); + vtkInformation *outInfo(outputVector->GetInformationObject(0)); + vtkTable *output(vtkTable::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()))); + if(!output) + { + vtkErrorMacro("vtkGroupsNames::RequestData : something wrong !"); + return 0; + } + // + vtkUnstructuredGrid *inputc(vtkUnstructuredGrid::SafeDownCast(input)); + if(!inputc) + { + vtkErrorMacro("vtkGroupsNames::RequestData : Only implemented for vtkUnstructuredGrid !"); + return 0; + } + // + vtkDataArray *famIdsGen(inputc->GetCellData()->GetScalars(MEDFileFieldRepresentationLeavesArrays::FAMILY_ID_CELL_NAME)); + if(!famIdsGen) + { + vtkErrorMacro(<< "vtkGroupsNames::RequestData : Fail to locate " << MEDFileFieldRepresentationLeavesArrays::FAMILY_ID_CELL_NAME << " array !"); + return 0; + } + using vtkMCIdTypeArray = MEDFileVTKTraits::VtkType; + vtkMCIdTypeArray *famIdsArr(vtkMCIdTypeArray::SafeDownCast(famIdsGen)); + if(!famIdsArr) + { + vtkErrorMacro(<< "vtkGroupsNames::RequestData : cell array " << MEDFileFieldRepresentationLeavesArrays::FAMILY_ID_CELL_NAME << " is exepected to be IdType !"); + return 0; + } + // Let's go ! + std::vector< std::pair > > allGroups(this->Internal->getAllGroups()); + vtkNew blockIdArr; + blockIdArr->SetName("Block ID"); + blockIdArr->SetNumberOfTuples(allGroups.size()); + vtkNew groupNameArr; + groupNameArr->SetName("Group Name"); + groupNameArr->SetNumberOfTuples(allGroups.size()); + int blockId(0); + for(const auto& grp : allGroups) + { + blockIdArr->SetValue(blockId,blockId); + groupNameArr->SetValue(blockId,vtkStdString(grp.first)); + blockId++; + } + output->AddColumn(blockIdArr); + output->AddColumn(groupNameArr); + return 1; +} diff --git a/src/Plugins/MEDReader/plugin/MEDReaderIO/vtkGroupsNames.h b/src/Plugins/MEDReader/plugin/MEDReaderIO/vtkGroupsNames.h new file mode 100644 index 00000000..14af366e --- /dev/null +++ b/src/Plugins/MEDReader/plugin/MEDReaderIO/vtkGroupsNames.h @@ -0,0 +1,39 @@ +// Copyright (C) 2020 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Anthony Geay (EDF R&D) + +#pragma once + +#include "vtkTableAlgorithm.h" + +class ExtractGroupInternal; + +class vtkGroupsNames : public vtkTableAlgorithm +{ +public: + static vtkGroupsNames *New(); + vtkTypeMacro(vtkGroupsNames, vtkTableAlgorithm); +protected: + vtkGroupsNames(); + ~vtkGroupsNames(); + int RequestInformation(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override; + int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override; +private: + ExtractGroupInternal *Internal; +}; diff --git a/src/Plugins/MEDReader/plugin/ParaViewPlugin/Resources/MEDReaderServer.xml b/src/Plugins/MEDReader/plugin/ParaViewPlugin/Resources/MEDReaderServer.xml index 44cdcba4..9c4e031f 100644 --- a/src/Plugins/MEDReader/plugin/ParaViewPlugin/Resources/MEDReaderServer.xml +++ b/src/Plugins/MEDReader/plugin/ParaViewPlugin/Resources/MEDReaderServer.xml @@ -212,6 +212,21 @@ + + + + + + + + + + + This property specifies the input to the Level Scalars filter. + + + + diff --git a/src/Plugins/MEDReader/plugin/Test/testMEDReader22.py b/src/Plugins/MEDReader/plugin/Test/testMEDReader22.py index 92ee70f6..343c5dc5 100644 --- a/src/Plugins/MEDReader/plugin/Test/testMEDReader22.py +++ b/src/Plugins/MEDReader/plugin/Test/testMEDReader22.py @@ -70,6 +70,16 @@ def test(): reader.AllArrays = ['TS0/mesh/ComSup0/field@@][@@P0','TS0/mesh/ComSup0/field2@@][@@P1','TS0/mesh/ComSup0/mesh@@][@@P0'] reader.AllTimeSteps = ['0000'] + groupsNames = GroupsNames(Input=reader) + groupsNames.UpdatePipeline() + MyAssert( servermanager.Fetch(groupsNames).GetNumberOfBlocks() == 1 ) + gn = servermanager.Fetch(groupsNames).GetBlock(0) + blockIDS = numpy_support.vtk_to_numpy(gn.GetColumnByName("Block ID")) + MyAssert(np.all(blockIDS==np.array([0,1,2,3],dtype=np.int32))) + grpNames = gn.GetColumnByName("Group Name") + MyAssert(grpNames.GetNumberOfTuples()==4) + MyAssert([grpNames.GetValue(i) for i in range(4)] == ['BottomLeft','BottomRight','TopLeft','TopRight']) + groupsAsMultiBlocks = GroupsAsMultiBlocks(Input=reader) groupsAsMultiBlocks.UpdatePipeline() blocks = servermanager.Fetch(groupsAsMultiBlocks) -- 2.39.2