]> SALOME platform Git repositories - modules/paravis.git/commitdiff
Salome HOME
New extract cell type kw/newExtractCellType
authorMathieu Westphal <mathieu.westphal@kitware.com>
Tue, 21 Sep 2021 14:14:27 +0000 (16:14 +0200)
committerChristophe Bourcier <christophe.bourcier@cea.fr>
Tue, 15 Mar 2022 10:32:58 +0000 (11:32 +0100)
Update tests with new extractCellType types names

src/Plugins/MEDReader/plugin/MEDReaderIO/vtk.module
src/Plugins/MEDReader/plugin/MEDReaderIO/vtkExtractCellType.cxx
src/Plugins/MEDReader/plugin/MEDReaderIO/vtkExtractCellType.h
src/Plugins/MEDReader/plugin/Test/testMEDReader19.py
src/Plugins/MEDReader/plugin/Test/testMEDReader8.py

index af3c08251dd71e88eadd26fcc63daabe61f2c16d..6072a2b27807a49f01da529d315063999f833b18 100644 (file)
@@ -2,6 +2,7 @@ NAME
   MEDReaderIO
 DEPENDS
   VTK::FiltersGeneral
+  VTK::FiltersExtraction
   VTK::IOLegacy
   ParaView::RemotingCore
 PRIVATE_DEPENDS
index 310de97b06e31d52909a6472a59ec2f051516809..29308087c406d0fbd02ca26a227d83ea8badf374 100644 (file)
-// Copyright (C) 2010-2021  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
-
 #include "vtkExtractCellType.h"
-#include "MEDFileFieldRepresentationTree.hxx"
-#include "MEDFileFieldOverView.hxx"
-
-#include "vtkAdjacentVertexIterator.h"
-#include "vtkAOSDataArrayTemplate.h"
-#include "vtkIntArray.h"
-#include "vtkCellData.h"
-#include "vtkPointData.h"
-
-#include "vtkStreamingDemandDrivenPipeline.h"
-#include "vtkUnstructuredGrid.h"
-#include  "vtkMultiBlockDataSet.h"
 
-#include "vtkInformationStringKey.h"
-#include "vtkAlgorithmOutput.h"
-#include "vtkObjectFactory.h"
-#include "vtkMutableDirectedGraph.h"
-#include "vtkMultiBlockDataSet.h"
+#include "vtkCell.h"
+#include "vtkCellTypes.h"
+#include "vtkCompositeDataSet.h"
+#include "vtkCompositeDataIterator.h"
+#include "vtkDataArraySelection.h"
 #include "vtkDataSet.h"
-#include "vtkInformationVector.h"
+#include "vtkExtractSelection.h"
+#include "vtkIdTypeArray.h"
 #include "vtkInformation.h"
-#include "vtkDataArraySelection.h"
-#include "vtkTimeStamp.h"
-#include "vtkInEdgeIterator.h"
-#include "vtkInformationDataObjectKey.h"
-#include "vtkExecutive.h"
-#include "vtkVariantArray.h"
-#include "vtkStringArray.h"
-#include "vtkDoubleArray.h"
-#include "vtkCharArray.h"
-#include "vtkUnsignedCharArray.h"
-#include "vtkDataSetAttributes.h"
-#include "vtkDemandDrivenPipeline.h"
-#include "vtkDataObjectTreeIterator.h"
-#include "vtkThreshold.h"
-
-#include <map>
-#include <deque>
-
-vtkStandardNewMacro(vtkExtractCellType)
+#include "vtkObjectFactory.h"
+#include "vtkSelection.h"
+#include "vtkSelectionNode.h"
 
-vtkCxxSetObjectMacro(vtkExtractCellType, SIL, vtkMutableDirectedGraph)
+vtkStandardNewMacro(vtkExtractCellType);
 
-///////////////////
+//----------------------------------------------------------------------------
+vtkExtractCellType::vtkExtractCellType(){}
 
-/// \cond PRIVATE
-class ExtractCellTypeStatus
-{
-public:
-  ExtractCellTypeStatus():_status(false),_vtkt(-1),_mct(INTERP_KERNEL::NORM_ERROR) { }
-  ExtractCellTypeStatus(int vtkt, INTERP_KERNEL::NormalizedCellType mct);
-  bool isSame(int vtkt, INTERP_KERNEL::NormalizedCellType mct) const { return _vtkt==vtkt && _mct==mct; }
-  bool getStatus() const { return _status; }
-  void setStatus(bool status) const { _status=status; }
-  void cpyStatusFrom(const ExtractCellTypeStatus& other) { _status=other._status; }
-  std::string getKey() const { return _type_str; }
-  const char *getKeyOfEntry() const { return _type_str.c_str(); }
-  int getVTKCellType() const { return _vtkt; }
-  void printMySelf(std::ostream& os) const;
-  bool isSameAs(const ExtractCellTypeStatus& other) const;
-  void feedSIL(vtkMutableDirectedGraph *sil, vtkIdType root, vtkVariantArray *childEdge, std::vector<std::string>& names) const;
-protected:
-  mutable bool _status;
-  int _vtkt;
-  INTERP_KERNEL::NormalizedCellType _mct;
-  std::string _type_str;
-};
+//----------------------------------------------------------------------------
+vtkExtractCellType::~vtkExtractCellType(){}
 
-class vtkExtractCellType::vtkExtractCellTypeInternal
+//----------------------------------------------------------------------------
+void vtkExtractCellType::AppendToGeoTypes(vtkDataSet* dataset)
 {
-public:
-  vtkExtractCellTypeInternal():_ref_mtime(0) { }
-  int getNumberOfEntries() const;
-  const char *getKeyOfEntry(int i) const;
-  bool getStatusOfEntryStr(const char *entry) const;
-  void setStatusOfEntryStr(const char *entry, bool status) const;
-  void feedSIL(vtkMutableDirectedGraph *sil) const;
-  std::vector<int> getIdsToKeep() const;
-  void printMySelf(std::ostream& os) const;
-  bool setRefTime(vtkObject *input) const;
-  // non const methods
-  void loadFrom(const std::map<int,INTERP_KERNEL::NormalizedCellType>& m);
-private:
-  const ExtractCellTypeStatus& getEntry(const char *entry) const;
-  bool checkSame(const std::map<int,INTERP_KERNEL::NormalizedCellType>& m) const;
-private:
-  std::vector<ExtractCellTypeStatus> _types;
-  mutable unsigned long _ref_mtime;
-};
+  for(int i = 0; i < dataset->GetNumberOfCells(); i++)
+  {
+    vtkCell* cell = dataset->GetCell(i);
 
-bool vtkExtractCellType::vtkExtractCellTypeInternal::setRefTime(vtkObject *input) const
-{
-  unsigned long mtime(input->GetMTime());
-  if(mtime>_ref_mtime)
+    // TODO use MEDCoupling CellType API
+    const char* cellType = vtkCellTypes::GetClassNameFromTypeId(cell->GetCellType());
+    if (!this->FieldSelection->ArrayExists(cellType))
     {
-      _ref_mtime=mtime;
-      return true;
+      this->FieldSelection->AddArray(cellType, false);
     }
-  else
-    return false;
+  }
 }
 
-std::vector<int> vtkExtractCellType::vtkExtractCellTypeInternal::getIdsToKeep() const
+//----------------------------------------------------------------------------
+void vtkExtractCellType::SelectIds(vtkDataSet* dataset, vtkIdTypeArray* selArr)
 {
-  std::vector<int> ret;
-  for(std::vector<ExtractCellTypeStatus>::const_iterator it=_types.begin();it!=_types.end();it++)
-    {
-      if((*it).getStatus())
-        ret.push_back((*it).getVTKCellType());
-    }
-  return ret;
-}
+  for(int i = 0; i < dataset->GetNumberOfCells(); i++)
+  {
+    vtkCell* cell = dataset->GetCell(i);
+    
+    // TODO use MEDCoupling CellType API
+    const char* cellType = vtkCellTypes::GetClassNameFromTypeId(cell->GetCellType());
 
-void vtkExtractCellType::vtkExtractCellTypeInternal::feedSIL(vtkMutableDirectedGraph *sil) const
-{
-  vtkSmartPointer<vtkVariantArray> childEdge(vtkSmartPointer<vtkVariantArray>::New());
-  childEdge->InsertNextValue(0);
-  vtkSmartPointer<vtkVariantArray> crossEdge(vtkSmartPointer<vtkVariantArray>::New());
-  crossEdge->InsertNextValue(1);
-  // CrossEdge is an edge linking hierarchies.
-  vtkUnsignedCharArray* crossEdgesArray=vtkUnsignedCharArray::New();
-  crossEdgesArray->SetName("CrossEdges");
-  sil->GetEdgeData()->AddArray(crossEdgesArray);
-  crossEdgesArray->Delete();
-  std::vector<std::string> names;
-  // Add global fields root
-  vtkIdType root(sil->AddVertex());
-  names.push_back("CellTypesTree");
-  //
-  for(std::vector<ExtractCellTypeStatus>::const_iterator it=_types.begin();it!=_types.end();it++)
+    // Needed as append to geotypes may not have been done in request information
+    // when loading state
+    if (!this->FieldSelection->ArrayExists(cellType))
     {
-      (*it).feedSIL(sil,root,childEdge,names);
+      this->FieldSelection->AddArray(cellType, false);
     }
-  // This array is used to assign names to nodes.
-  vtkStringArray *namesArray(vtkStringArray::New());
-  namesArray->SetName("Names");
-  namesArray->SetNumberOfTuples(sil->GetNumberOfVertices());
-  sil->GetVertexData()->AddArray(namesArray);
-  namesArray->Delete();
-  std::vector<std::string>::const_iterator iter;
-  vtkIdType cc;
-  for(cc=0, iter=names.begin(); iter!=names.end(); ++iter, ++cc)
-    namesArray->SetValue(cc,(*iter).c_str());
-}
-
-void vtkExtractCellType::vtkExtractCellTypeInternal::loadFrom(const std::map<int,INTERP_KERNEL::NormalizedCellType>& m)
-{
-  if(checkSame(m))
-    return;
-  //
-  std::size_t sz(m.size()),ii(0);
-  _types.resize(sz);
-  for(std::map<int,INTERP_KERNEL::NormalizedCellType>::const_iterator it=m.begin();it!=m.end();it++,ii++)
+    else if(this->FieldSelection->ArrayIsEnabled(cellType))
     {
-      ExtractCellTypeStatus elt((*it).first,(*it).second);
-      _types[ii]=elt;
+      selArr->InsertNextValue(i);
     }
+  }
 }
 
-int vtkExtractCellType::vtkExtractCellTypeInternal::getNumberOfEntries() const
-{
-  return (int) _types.size();
-}
-
-const char *vtkExtractCellType::vtkExtractCellTypeInternal::getKeyOfEntry(int i) const
-{
-  return _types[i].getKeyOfEntry();
-}
-
-bool vtkExtractCellType::vtkExtractCellTypeInternal::checkSame(const std::map<int,INTERP_KERNEL::NormalizedCellType>& m) const
-{
-  std::size_t sz(m.size());
-  if(sz!=_types.size())
-    return false;
-  bool ret(true);
-  std::map<int,INTERP_KERNEL::NormalizedCellType>::const_iterator it(m.begin());
-  for(std::size_t i=0;i<sz && ret;i++,it++)
-    ret=_types[i].isSame((*it).first,(*it).second);
-  return ret;
-}
-
-const ExtractCellTypeStatus& vtkExtractCellType::vtkExtractCellTypeInternal::getEntry(const char *entry) const
-{
-  std::string entryCpp(entry);
-  for(std::vector<ExtractCellTypeStatus>::const_iterator it0=_types.begin();it0!=_types.end();it0++)
-    if(entryCpp==(*it0).getKey())
-      return *it0;
-  std::ostringstream oss; oss << "vtkExtractCellTypeInternal::getEntry : no such entry \"" << entry << "\"!";
-  throw INTERP_KERNEL::Exception(oss.str().c_str());
-}
-
-bool vtkExtractCellType::vtkExtractCellTypeInternal::getStatusOfEntryStr(const char *entry) const
+//----------------------------------------------------------------------------
+int vtkExtractCellType::RequestInformation(vtkInformation* req, vtkInformationVector** inputVector, vtkInformationVector* outputVector)
 {
-  try 
-    {
-      const ExtractCellTypeStatus& elt(getEntry(entry));
-      return elt.getStatus();
-    }  
-  catch (INTERP_KERNEL::Exception& /*e*/)
-    {      
-      //std::cerr << vtkDebugMacro"Exception has been thrown in vtkExtractCellType::vtkExtractCellTypeInternal::getStatusOfEntryStr : " << e.what() << std::endl;
-      return false;
-    }
-}
+  vtkDataSet* inputDS = vtkDataSet::GetData(inputVector[0]);
+  vtkCompositeDataSet* inputComposite = vtkCompositeDataSet::GetData(inputVector[0]);
 
-void vtkExtractCellType::vtkExtractCellTypeInternal::setStatusOfEntryStr(const char *entry, bool status) const
-{
-  try 
+  if (inputDS)
+  {
+    this->AppendToGeoTypes(inputDS);
+  }
+  else if(inputComposite)
+  {
+    vtkSmartPointer<vtkCompositeDataIterator> iter;
+    iter.TakeReference(inputComposite->NewIterator());
+    for (iter->InitTraversal(); !iter->IsDoneWithTraversal(); iter->GoToNextItem())
     {
-      const ExtractCellTypeStatus& elt(getEntry(entry));
-      elt.setStatus(status);
-    }
-  catch (INTERP_KERNEL::Exception& /*e*/)
-    {      
-      //std::cerr << "Exception has been thrown in vtkExtractCellType::vtkExtractCellTypeInternal::setStatusOfEntryStr : " << e.what() << std::endl;
+      this->AppendToGeoTypes(vtkDataSet::SafeDownCast(inputComposite->GetDataSet(iter)));
     }
-}
-
-void vtkExtractCellType::vtkExtractCellTypeInternal::printMySelf(std::ostream& os) const
-{
-  for(std::vector<ExtractCellTypeStatus>::const_iterator it0=_types.begin();it0!=_types.end();it0++)
-    (*it0).printMySelf(os);
-}
-
-ExtractCellTypeStatus::ExtractCellTypeStatus(int vtkt, INTERP_KERNEL::NormalizedCellType mct):_status(false),_vtkt(vtkt),_mct(mct)
-{
-  std::string name(INTERP_KERNEL::CellModel::GetCellModel(mct).getRepr());
-  _type_str=name.substr(5);//skip "NORM_"
-}
-
-void ExtractCellTypeStatus::printMySelf(std::ostream& os) const
-{
-  os << "      -" << _type_str << "(";
-  if(_status)
-    os << "X";
-  else
-    os << " ";
-  os << ")" << std::endl;
-}
-
-bool ExtractCellTypeStatus::isSameAs(const ExtractCellTypeStatus& other) const
-{
-  return _vtkt==other._vtkt && _mct==other._mct;
-}
-
-void ExtractCellTypeStatus::feedSIL(vtkMutableDirectedGraph *sil, vtkIdType root, vtkVariantArray *childEdge, std::vector<std::string>& names) const
-{
-  vtkIdType InfoGeoType(sil->AddChild(root,childEdge));
-  names.push_back(_type_str);
-  /*vtkIdType InfoVTKID(*/sil->AddChild(InfoGeoType,childEdge)/*)*/; // todo: unused
-  std::ostringstream oss; oss << _vtkt;
-  names.push_back(oss.str());
-}
-/// \endcond PRIVATE
-
-////////////////////
-
-vtkExtractCellType::vtkExtractCellType():SIL(NULL),Internal(new vtkExtractCellTypeInternal),InsideOut(0)
-{
-}
+  }
 
-vtkExtractCellType::~vtkExtractCellType()
-{
-  if(this->SIL)
-    this->SIL->Delete();
-  delete this->Internal;
+  return 1;
 }
 
-void vtkExtractCellType::SetInsideOut(int val)
+//----------------------------------------------------------------------------
+int vtkExtractCellType::RequestData(vtkInformation* req, vtkInformationVector** inputVector, vtkInformationVector* outputVector)
 {
-  if(this->InsideOut!=val)
-    {
-      this->InsideOut=val;
-      this->Modified();
-    }
-}
+  // Get the input and output data objects.
+  vtkDataSet* input = vtkDataSet::GetData(inputVector[0]);
+  vtkDataSet* output = vtkDataSet::GetData(outputVector);
 
-int vtkExtractCellType::RequestInformation(vtkInformation * /*request*/, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
-{
-  try
-    {
-      //std::cerr << "########################################## vtkExtractCellType::RequestInformation ##########################################" << std::endl;
-      vtkInformation *outInfo(outputVector->GetInformationObject(0));
-      vtkInformation *inputInfo(inputVector[0]->GetInformationObject(0));
-      vtkDataSet *input(0);
-      {
-       vtkDataObject *inp(inputInfo->Get(vtkDataObject::DATA_OBJECT()));
-       if(vtkDataSet::SafeDownCast(inp))
-         input=vtkDataSet::SafeDownCast(inp);
-       else
-         {
-           vtkMultiBlockDataSet *inputTmp(vtkMultiBlockDataSet::SafeDownCast(inp));
-           if(inputTmp)
-             {
-               if(inputTmp->GetNumberOfBlocks()!=1)
-                 {
-                   vtkDebugMacro("vtkExtractCellType::RequestInformation : input vtkMultiBlockDataSet must contain exactly 1 block !");
-                   return 0;
-                 }
-               vtkDataSet *blk0(vtkDataSet::SafeDownCast(inputTmp->GetBlock(0)));
-               if(!blk0)
-                 {
-                   vtkDebugMacro("vtkExtractCellType::RequestInformation : the single block in input vtkMultiBlockDataSet must be a vtkDataSet instance !");
-                   return 0;
-                 }
-               input=blk0;
-             }
-           else
-             {
-               vtkDebugMacro("vtkExtractCellType::RequestInformation : supported input are vtkDataSet or vtkMultiBlockDataSet !");
-               return 0;
-             }
-         }
-      }
-      if(this->Internal->setRefTime(input))
-       {
-         vtkIdType nbOfCells(input->GetNumberOfCells());
-         std::map<int,INTERP_KERNEL::NormalizedCellType> m;
-         for(vtkIdType cellId=0;cellId<nbOfCells;cellId++)
-           {
-             int vtkCt(input->GetCellType(cellId));
-             const std::map<int,INTERP_KERNEL::NormalizedCellType>::const_iterator it(m.find(vtkCt));
-             if(it==m.end())
-               {
-                 const unsigned char *pos(std::find(MEDCoupling::MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE,MEDCoupling::MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE+MEDCoupling::MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE_LGTH,vtkCt));
-                 if(pos==MEDCoupling::MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE+MEDCoupling::MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE_LGTH)
-                   {
-                     vtkDebugMacro("vtkExtractCellType::RequestInformation : cell #" << cellId << " has unrecognized type !");
-                     return 0;
-                   }
-                 m[vtkCt]=(INTERP_KERNEL::NormalizedCellType)std::distance(MEDCoupling::MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE,pos);
-            }
-           }
-         this->Internal->loadFrom(m);
-         if(this->SIL)
-           this->SIL->Delete();
-         this->SIL=vtkMutableDirectedGraph::New();
-         this->Internal->feedSIL(this->SIL);
-         //
-         outInfo->Set(vtkDataObject::SIL(),this->SIL);
-       }
-    }
-  catch(INTERP_KERNEL::Exception& e)
-    {
-      std::cerr << "Exception has been thrown in vtkExtractCellType::RequestInformation : " << e.what() << std::endl;
-      return 0;
-    }
-  return 1;
-}
+  // Create a selection, sel1, of cells with indices 7643-7499-7355-7211
+  vtkNew<vtkIdTypeArray> selArr1;
 
-vtkDataSet *FilterFamilies(vtkDataSet *input, const std::vector<int>& idsToKeep, bool insideOut)
-{
-  const int VTK_DATA_ARRAY_DELETE=vtkAOSDataArrayTemplate<double>::VTK_DATA_ARRAY_DELETE;
-  const char ZE_SELECTION_ARR_NAME[]="@@ZeSelection@@";
-  vtkDataSet *output(input->NewInstance());
-  output->ShallowCopy(input);
-  vtkSmartPointer<vtkThreshold> thres(vtkSmartPointer<vtkThreshold>::New());
-  thres->SetInputData(output);
-  //vtkDataSetAttributes *dscIn(input->GetCellData()),*dscIn2(input->GetPointData()); // todo: unused
-  //vtkDataSetAttributes *dscOut(output->GetCellData()),*dscOut2(output->GetPointData()); // todo: unused
-  //
-  double vMin(insideOut==0?1.:0.),vMax(insideOut==0?2.:1.);
-  thres->ThresholdBetween(vMin,vMax);
-  // OK for the output 
-  vtkIdType nbOfCells(input->GetNumberOfCells());
-  vtkCharArray *zeSelection(vtkCharArray::New());
-  zeSelection->SetName(ZE_SELECTION_ARR_NAME);
-  zeSelection->SetNumberOfComponents(1);
-  char *pt(new char[nbOfCells]);
-  zeSelection->SetArray(pt,nbOfCells,0,VTK_DATA_ARRAY_DELETE);
-  std::fill(pt,pt+nbOfCells,0);
-  std::vector<bool> pt2(nbOfCells,false);
-  for(std::vector<int>::const_iterator it=idsToKeep.begin();it!=idsToKeep.end();it++)
-    {
-      for(vtkIdType ii=0;ii<nbOfCells;ii++)
-        {
-          if(input->GetCellType(ii)==*it)
-            pt2[ii]=true;
-        }
-    }
-  for(int ii=0;ii<nbOfCells;ii++)
-    if(pt2[ii])
-      pt[ii]=2;
-  int idx(output->GetCellData()->AddArray(zeSelection));
-  output->GetCellData()->SetActiveAttribute(idx,vtkDataSetAttributes::SCALARS);
-  output->GetCellData()->CopyScalarsOff();
-  zeSelection->Delete();
-  //
-  thres->SetInputArrayToProcess(idx,0,0,"vtkDataObject::FIELD_ASSOCIATION_CELLS",ZE_SELECTION_ARR_NAME);
-  thres->Update();
-  vtkUnstructuredGrid *zeComputedOutput(thres->GetOutput());
-  zeComputedOutput->GetCellData()->RemoveArray(idx);
-  output->Delete();
-  zeComputedOutput->Register(0);
-  return zeComputedOutput;
-}
+  vtkDataSet* inputDS = vtkDataSet::GetData(inputVector[0]);
+  vtkCompositeDataSet* inputComposite = vtkCompositeDataSet::GetData(inputVector[0]);
 
-int vtkExtractCellType::RequestData(vtkInformation * /*request*/, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
-{
-  try
+  if (inputDS)
+  {
+    this->SelectIds(inputDS, selArr1);
+  }
+  else if(inputComposite)
+  {
+    vtkSmartPointer<vtkCompositeDataIterator> iter;
+    iter.TakeReference(inputComposite->NewIterator());
+    for (iter->InitTraversal(); !iter->IsDoneWithTraversal(); iter->GoToNextItem())
     {
-      //std::cerr << "########################################## vtkExtractCellType::RequestData        ##########################################" << std::endl;
-      vtkInformation* inputInfo=inputVector[0]->GetInformationObject(0);
-      vtkDataSet *input(vtkDataSet::SafeDownCast(inputInfo->Get(vtkDataObject::DATA_OBJECT())));
-      //vtkInformation *info(input->GetInformation()); // todo: unused
-      vtkInformation *outInfo(outputVector->GetInformationObject(0));
-      vtkDataSet *output(vtkDataSet::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT())));
-      std::vector<int> idsToKeep(this->Internal->getIdsToKeep());
-      vtkDataSet *tryOnCell(FilterFamilies(input,idsToKeep,this->InsideOut));
-      // first shrink the input
-      output->ShallowCopy(tryOnCell);
-      tryOnCell->Delete();
-    }
-  catch(INTERP_KERNEL::Exception& e)
-    {
-      std::cerr << "Exception has been thrown in vtkExtractCellType::RequestData : " << e.what() << std::endl;
-      return 0;
+      this->SelectIds(vtkDataSet::SafeDownCast(inputComposite->GetDataSet(iter)), selArr1);
     }
+  }
+
+  vtkNew<vtkSelectionNode> selNode1;
+  selNode1->SetContentType(vtkSelectionNode::INDICES);
+  selNode1->SetFieldType(vtkSelectionNode::CELL);
+  selNode1->GetProperties()->Set(vtkSelectionNode::COMPOSITE_INDEX(), 1);
+  selNode1->GetProperties()->Set(vtkSelectionNode::INVERSE(), this->InsideOut);
+  selNode1->SetSelectionList(selArr1);
+  vtkNew<vtkSelection> sel1;
+  sel1->AddNode(selNode1);
+
+  this->SetInputData(1, sel1);
+  this->Superclass::RequestData(req, inputVector, outputVector);
   return 1;
 }
 
-int vtkExtractCellType::GetSILUpdateStamp()
-{
-  return (int)this->SILTime;
-}
-
+//----------------------------------------------------------------------------
 void vtkExtractCellType::PrintSelf(ostream& os, vtkIndent indent)
 {
   this->Superclass::PrintSelf(os, indent);
 }
-
+//------------------------------------------------------------------------------
 int vtkExtractCellType::GetNumberOfGeoTypesArrays()
 {
-  int ret(this->Internal->getNumberOfEntries());
-  //std::cerr << "vtkExtractCellType::GetNumberOfGeoTypesArrays() -> " << ret << std::endl;
-  return ret;
+  return this->FieldSelection->GetNumberOfArrays();
 }
 
+//------------------------------------------------------------------------------
 const char *vtkExtractCellType::GetGeoTypesArrayName(int index)
 {
-  const char *ret(this->Internal->getKeyOfEntry(index));
-  //std::cerr << "vtkExtractCellType::GetGeoTypesArrayName(" << index << ") -> " << ret << std::endl;
-  return ret;
+  return this->FieldSelection->GetArrayName(index) + 3;  // String parsing -- remove "vtk"
 }
 
+//------------------------------------------------------------------------------
 int vtkExtractCellType::GetGeoTypesArrayStatus(const char *name)
 {
-  int ret((int)this->Internal->getStatusOfEntryStr(name));
-  //std::cerr << "vtkExtractCellType::GetGeoTypesArrayStatus(" << name << ") -> " << ret << std::endl;
-  return ret;
+  return this->FieldSelection->ArrayIsEnabled(name);
 }
 
+//------------------------------------------------------------------------------
 void vtkExtractCellType::SetGeoTypesStatus(const char *name, int status)
 {
-  //std::cerr << "vtkExtractCellType::SetGeoTypesStatus(" << name << "," << status << ")" << std::endl;
-  if (GetNumberOfGeoTypesArrays()<1)
-    return;
-  this->Internal->setStatusOfEntryStr(name,(bool)status);
-  if(std::string(name)==GetGeoTypesArrayName(GetNumberOfGeoTypesArrays()-1))
+  std::string complete_name = "vtk";
+  complete_name.append(name);
+  if (this->GetGeoTypesArrayStatus(complete_name.c_str()) != status)
+  {
+    if (status)
+    {
+      this->FieldSelection->EnableArray(complete_name.c_str());
+    }
+    else
     {
-      this->Modified();
-      //this->Internal->printMySelf(std::cerr);
+      this->FieldSelection->DisableArray(complete_name.c_str());
     }
+    this->Modified();
+  }
 }
index 3d556ef74be808f22b37e4fc715b10f8ed461f22..f92584c6e876663ac1325c22753ad6c316999a00 100644 (file)
@@ -1,71 +1,44 @@
-// Copyright (C) 2010-2021  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
-
-#ifndef vtkExtractCellType_h__
-#define vtkExtractCellType_h__
+#ifndef vtkExtractCellType_h
+#define vtkExtractCellType_h
 
+#include "MEDReaderIOModule.h" // for export macro
 #include "vtkDataSetAlgorithm.h"
+#include "vtkExtractSelection.h"
+#include "vtkNew.h"
 
-class vtkMutableDirectedGraph;
+class vtkDataArraySelection;
+class vtkIdTypeArray;
 
-class VTK_EXPORT vtkExtractCellType : public vtkDataSetAlgorithm
+class MEDREADERIO_EXPORT vtkExtractCellType : public vtkExtractSelection
 {
 public:
   static vtkExtractCellType* New();
-  vtkTypeMacro(vtkExtractCellType, vtkDataSetAlgorithm)
-  void PrintSelf(ostream& os, vtkIndent indent);
+  vtkTypeMacro(vtkExtractCellType, vtkExtractSelection);
+  void PrintSelf(ostream& os, vtkIndent indent) override;
+
   virtual int GetNumberOfGeoTypesArrays();
   const char *GetGeoTypesArrayName(int index);
   int GetGeoTypesArrayStatus(const char *name);
   virtual void SetGeoTypesStatus(const char *name, int status);
-  void SetInsideOut(int val);
-  // Description:
-  // Every time the SIL is updated a this will return a different value.
-  virtual int GetSILUpdateStamp();
+  
+  vtkSetMacro(InsideOut, bool);
 
 protected:
   vtkExtractCellType();
   ~vtkExtractCellType();
 
-  int RequestInformation(vtkInformation * request,
-      vtkInformationVector **inputVector, vtkInformationVector *outputVector);
+  int RequestInformation(vtkInformation* req, vtkInformationVector** inInfo, vtkInformationVector* outInfo) override;
+  int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;
+
+  void AppendToGeoTypes(vtkDataSet* dataset);
+  void SelectIds(vtkDataSet* dataset, vtkIdTypeArray* selArr);
 
-  int RequestData(vtkInformation * request, vtkInformationVector **inputVector,
-      vtkInformationVector *outputVector);
-  // Description:
-  // This SIL stores the structure of the mesh/groups/cell types
-  // that can be selected.
-  virtual void SetSIL(vtkMutableDirectedGraph*);
-  vtkGetObjectMacro(SIL, vtkMutableDirectedGraph);
-protected:
-  vtkMutableDirectedGraph *SIL;
-  vtkTimeStamp SILTime;
 private:
-  vtkExtractCellType(const vtkExtractCellType&);
-  void operator=(const vtkExtractCellType&); // Not implemented.
- private:
-  //BTX
-  //ETX
-  class vtkExtractCellTypeInternal;
-  vtkExtractCellTypeInternal *Internal;
-  int InsideOut;
+  vtkExtractCellType(const vtkExtractCellType&) = delete;
+  void operator=(const vtkExtractCellType&) = delete;
+  
+  vtkNew<vtkDataArraySelection> FieldSelection;
+  int InsideOut = false;
 };
 
 #endif
index 3a0e735c7a2eaaffb697ce78217af63ce334d9fd..4c94a52683ac7db17b6a5e758b6577c11b97f846 100644 (file)
@@ -78,7 +78,7 @@ def test(baseline_file):
         extractCellType1.AllGeoTypes = []
 
         # Properties modified on extractCellType1
-        extractCellType1.AllGeoTypes = ['TRI3']
+        extractCellType1.AllGeoTypes = ['Triangle']
 
         # show data in view
         extractCellType1Display = Show(extractCellType1, renderView1)
index c2a746ea6d24d1d0780f149ee0e64d18d9bb088c..4db4e790bc69504fa9f9e5b8131a116be4df2e78 100644 (file)
@@ -81,8 +81,8 @@ def test(baseline_file):
 
     extractCT=ExtractCellType(Input=myMedReader)
     extractCT.UpdatePipelineInformation()
-    assert(list(extractCT.GetProperty("GeoTypesInfo"))==['TRI3','0','QUAD4','0'])
-    extractCT.AllGeoTypes=['TRI3']
+    assert(list(extractCT.GetProperty("GeoTypesInfo"))==['Triangle', '0', 'Quad', '0'])
+    extractCT.AllGeoTypes=['Triangle']
 
     extGrp=ExtractGroup(Input=extractCT)
     #extGrp.UpdatePipelineInformation()