Salome HOME
Merge remote branch 'origin/master'
[modules/paravis.git] / src / Plugins / MEDReader / IO / vtkExtractGroup.cxx
index 83c32a6ced9839b2d568d7596725a03f69b6c324..1db4ee4975a34415338d9e917fc951cafa492f14 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2010-2014  CEA/DEN, EDF R&D
+// Copyright (C) 2010-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
 #include "vtkDemandDrivenPipeline.h"
 #include "vtkDataObjectTreeIterator.h"
 #include "vtkThreshold.h"
+#include "vtkMultiBlockDataGroupFilter.h"
+#include "vtkCompositeDataToUnstructuredGridFilter.h"
 
 #include <map>
 #include <deque>
 
 vtkStandardNewMacro(vtkExtractGroup);
 
-vtkCxxSetObjectMacro(vtkExtractGroup, SIL, vtkMutableDirectedGraph);
-
 ///////////////////
 
 class ExtractGroupStatus
@@ -111,6 +111,7 @@ class vtkExtractGroup::vtkExtractGroupInternal
 public:
   void loadFrom(vtkMutableDirectedGraph *sil);
   int getNumberOfEntries() const;
+  const char *getMeshName() const;
   const char *getKeyOfEntry(int i) const;
   bool getStatusOfEntryStr(const char *entry) const;
   void setStatusOfEntryStr(const char *entry, bool status);
@@ -125,6 +126,7 @@ private:
 private:
   std::vector<ExtractGroupGrp> _groups;
   std::vector<ExtractGroupFam> _fams;
+  std::string _mesh_name;
 };
 
 const char ExtractGroupGrp::START[]="GRP_";
@@ -180,6 +182,11 @@ bool vtkExtractGroup::vtkExtractGroupInternal::IsInformationOK(vtkInformation *i
   return false;
 }
 
+const char *vtkExtractGroup::vtkExtractGroupInternal::getMeshName() const
+{
+  return this->_mesh_name.c_str();
+}
+
 void vtkExtractGroup::vtkExtractGroupInternal::loadFrom(vtkMutableDirectedGraph *sil)
 {
   std::vector<ExtractGroupGrp> oldGrps(_groups); _groups.clear();
@@ -207,6 +214,7 @@ void vtkExtractGroup::vtkExtractGroupInternal::loadFrom(vtkMutableDirectedGraph
     {
       vtkIdType id1(it0->Next());
       std::string meshName((const char *)verticesNames2->GetValue(id1));
+      this->_mesh_name=meshName;
       vtkAdjacentVertexIterator *it1(vtkAdjacentVertexIterator::New());
       sil->GetAdjacentVertices(id1,it1);
       vtkIdType idZeGrps(it1->Next());//zeGroups
@@ -419,6 +427,7 @@ void vtkExtractGroup::SetInsideOut(int val)
 
 int vtkExtractGroup::RequestInformation(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
 {
+  vtkUnstructuredGridAlgorithm::RequestInformation(request,inputVector,outputVector);
   try
     {
       //std::cerr << "########################################## vtkExtractGroup::RequestInformation ##########################################" << std::endl;
@@ -453,15 +462,25 @@ int vtkExtractGroup::RequestInformation(vtkInformation *request, vtkInformationV
   return 1;
 }
 
+/*!
+ * Do not use vtkCxxSetObjectMacro macro because input mdg comes from an already managed in the pipeline just a ref on it.
+ */
+void vtkExtractGroup::SetSIL(vtkMutableDirectedGraph *mdg)
+{
+  if(this->SIL==mdg)
+    return ;
+  this->SIL=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());
@@ -550,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)
        {
@@ -564,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
@@ -584,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)
                    {
@@ -604,7 +631,7 @@ int vtkExtractGroup::RequestData(vtkInformation *request, vtkInformationVector *
        }
       else
        {
-         vtkDataSet *tryOnNode(FilterFamilies<PointExtractor>(tryOnCell,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)
            {
@@ -666,8 +693,15 @@ int vtkExtractGroup::GetGroupsFlagsArrayStatus(const char *name)
 void vtkExtractGroup::SetGroupsFlagsStatus(const char *name, int status)
 {
   //std::cerr << "vtkExtractGroup::SetFieldsStatus(" << name << "," << status << ")" << std::endl;
+  if (GetNumberOfGroupsFlagsArrays()<1)
+    return;
   this->Internal->setStatusOfEntryStr(name,(bool)status);
   if(std::string(name)==GetGroupsFlagsArrayName(GetNumberOfGroupsFlagsArrays()-1))
      this->Modified();
   //this->Internal->printMySelf(std::cerr);
 }
+
+const char *vtkExtractGroup::GetMeshName()
+{
+  return this->Internal->getMeshName();
+}