Salome HOME
0023159: EDF 11434 - Problem with Extract Group
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 23 Sep 2015 10:07:47 +0000 (12:07 +0200)
committervsr <vsr@opencascade.com>
Thu, 24 Sep 2015 09:20:15 +0000 (12:20 +0300)
src/Plugins/MEDReader/IO/vtkExtractGroup.cxx
src/Plugins/MEDReader/Test/CMakeLists.txt
src/Plugins/MEDReader/Test/CTestTestfileInstall.cmake
src/Plugins/MEDReader/Test/testMEDReader18.py [new file with mode: 0644]

index d1135d2ed94ae7a5b76f465ae253daaaf9335722..8c7fe1472c7b626918595d5e6228433d9f120270 100644 (file)
@@ -52,6 +52,8 @@
 #include "vtkDemandDrivenPipeline.h"
 #include "vtkDataObjectTreeIterator.h"
 #include "vtkThreshold.h"
+#include "vtkMultiBlockDataGroupFilter.h"
+#include "vtkCompositeDataToUnstructuredGridFilter.h"
 
 #include <map>
 #include <deque>
@@ -471,14 +473,14 @@ void vtkExtractGroup::SetSIL(vtkMutableDirectedGraph *mdg)
 }
 
 template<class CellPointExtractor>
-vtkDataSet *FilterFamilies(vtkDataSet *input, const std::set<int>& idsToKeep, bool insideOut, const char *arrNameOfFamilyField,
+vtkDataSet *FilterFamilies(vtkSmartPointer<vtkThreshold>& thres,
+                           vtkDataSet *input, const std::set<int>& idsToKeep, bool insideOut, const char *arrNameOfFamilyField,
                            const char *associationForThreshold, bool& catchAll, bool& catchSmth)
 {
   static const int VTK_DATA_ARRAY_DELETE=vtkDataArrayTemplate<double>::VTK_DATA_ARRAY_DELETE;
   static 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());
   vtkDataSetAttributes *dscOut(output->GetCellData()),*dscOut2(output->GetPointData());
@@ -567,7 +569,8 @@ int vtkExtractGroup::RequestData(vtkInformation *request, vtkInformationVector *
       std::set<int> idsToKeep(this->Internal->getIdsToKeep());
       // first shrink the input
       bool catchAll,catchSmth;
-      vtkDataSet *tryOnCell(FilterFamilies<CellExtractor>(input,idsToKeep,this->InsideOut,
+      vtkSmartPointer<vtkThreshold> thres1(vtkSmartPointer<vtkThreshold>::New()),thres2(vtkSmartPointer<vtkThreshold>::New());
+      vtkDataSet *tryOnCell(FilterFamilies<CellExtractor>(thres1,input,idsToKeep,this->InsideOut,
                                                          MEDFileFieldRepresentationLeavesArrays::FAMILY_ID_CELL_NAME,"vtkDataObject::FIELD_ASSOCIATION_CELLS",catchAll,catchSmth));
       if(tryOnCell)
        {
@@ -581,13 +584,20 @@ int vtkExtractGroup::RequestData(vtkInformation *request, vtkInformationVector *
            {
              if(catchSmth)
                {
-                 vtkDataSet *tryOnNode(FilterFamilies<PointExtractor>(tryOnCell,idsToKeep,this->InsideOut,
+                 vtkDataSet *tryOnNode(FilterFamilies<PointExtractor>(thres2,input,idsToKeep,this->InsideOut,
                                                                       MEDFileFieldRepresentationLeavesArrays::FAMILY_ID_NODE_NAME,"vtkDataObject::FIELD_ASSOCIATION_POINTS",catchAll,catchSmth));
                  if(tryOnNode && catchSmth)
                    {
-                     output->ShallowCopy(tryOnNode);
+                      vtkSmartPointer<vtkMultiBlockDataGroupFilter> mb(vtkSmartPointer<vtkMultiBlockDataGroupFilter>::New());
+                      vtkSmartPointer<vtkCompositeDataToUnstructuredGridFilter> cd(vtkSmartPointer<vtkCompositeDataToUnstructuredGridFilter>::New());
+                      mb->AddInputConnection(thres1->GetOutputPort());
+                      mb->AddInputConnection(thres2->GetOutputPort());
+                      cd->SetInputConnection(mb->GetOutputPort());
+                      cd->SetMergePoints(0);
+                      cd->Update();
+                     output->ShallowCopy(cd->GetOutput());
                      tryOnCell->Delete();
-                     tryOnNode->Delete();//
+                     tryOnNode->Delete();
                      return 1;
                    }
                  else
@@ -601,7 +611,7 @@ int vtkExtractGroup::RequestData(vtkInformation *request, vtkInformationVector *
                }
              else
                {
-                 vtkDataSet *tryOnNode(FilterFamilies<PointExtractor>(input,idsToKeep,this->InsideOut,
+                 vtkDataSet *tryOnNode(FilterFamilies<PointExtractor>(thres1,input,idsToKeep,this->InsideOut,
                                                                       MEDFileFieldRepresentationLeavesArrays::FAMILY_ID_NODE_NAME,"vtkDataObject::FIELD_ASSOCIATION_POINTS",catchAll,catchSmth));
                  if(tryOnNode)
                    {
@@ -621,7 +631,7 @@ int vtkExtractGroup::RequestData(vtkInformation *request, vtkInformationVector *
        }
       else
        {
-         vtkDataSet *tryOnNode(FilterFamilies<PointExtractor>(input,idsToKeep,this->InsideOut,
+         vtkDataSet *tryOnNode(FilterFamilies<PointExtractor>(thres1,input,idsToKeep,this->InsideOut,
                                                               MEDFileFieldRepresentationLeavesArrays::FAMILY_ID_NODE_NAME,"vtkDataObject::FIELD_ASSOCIATION_POINTS",catchAll,catchSmth));
          if(tryOnNode)
            {
index c078cf07b59891861d810c19b33165b251dd0dcc..05bb227b3f6ffa5cf7c5634c1ad3c84f69e62209 100644 (file)
@@ -19,7 +19,7 @@
 
 SALOME_GENERATE_TESTS_ENVIRONMENT(tests_env)
 
-SET(TEST_NUMBERS 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17)
+SET(TEST_NUMBERS 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18)
 
 FOREACH(tfile ${TEST_NUMBERS})
   ADD_TEST(testMEDReader${tfile} ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/testMEDReader${tfile}.py)
index 31f92373ce13e42d7cb925590b539067ee57f3ac..588e3429dd2e9d6aa7bdd7a5a79835f212ffa48e 100644 (file)
@@ -21,7 +21,7 @@ SET(SALOME_TEST_DRIVER "$ENV{ABSOLUTE_APPLI_PATH}/bin/salome/appliskel/salome_te
 SET(COMPONENT_NAME MEDREADER)
 SET(TIMEOUT        30)
 
-SET(TEST_NUMBERS 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17)
+SET(TEST_NUMBERS 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18)
 
 FOREACH(tfile ${TEST_NUMBERS})
   SET(TEST_NAME MEDREADER_${tfile})
diff --git a/src/Plugins/MEDReader/Test/testMEDReader18.py b/src/Plugins/MEDReader/Test/testMEDReader18.py
new file mode 100644 (file)
index 0000000..235a404
--- /dev/null
@@ -0,0 +1,52 @@
+#  -*- coding: iso-8859-1 -*-
+# Copyright (C) 2015  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)
+
+# Non regression test for bug EDF11343. Extract group on groups mixing cells entities and node entities.
+
+from MEDLoader import *
+
+fname="testMEDReader18.med"
+arr1=DataArrayDouble(5) ; arr1.iota()
+arr2=DataArrayDouble([0,1])
+m=MEDCouplingCMesh() ; m.setCoords(arr1,arr2)
+m.setName("mesh")
+m=m.buildUnstructured()
+#
+mm=MEDFileUMesh()
+mm[0]=m
+#
+grp0=DataArrayInt([1,2]) ; grp0.setName("grp0")
+grp1=DataArrayInt([3,4,8,9]) ; grp1.setName("grp1")
+#
+mm.addGroup(0,grp0)
+mm.addGroup(1,grp1)
+#
+mm.write(fname,2)
+#####
+from paraview.simple import *
+
+reader=MEDReader(FileName=fname)
+reader.AllArrays=['TS0/mesh/ComSup0/mesh@@][@@P0']
+ExtractGroup1 = ExtractGroup(Input=reader)
+ExtractGroup1.AllGroups=["GRP_grp0","GRP_grp1"]
+ExtractGroup1.UpdatePipelineInformation()
+res=servermanager.Fetch(ExtractGroup1,0)
+assert(res.GetBlock(0).GetNumberOfCells()==3)