Salome HOME
Bug correction 2 same for MEDReader reader but here for filters in MEDReader with...
[modules/paravis.git] / src / Plugins / MEDReader / IO / vtkExtractGroup.cxx
1 // Copyright (C) 2010-2014  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay
20
21 #include "vtkExtractGroup.h"
22 #include "MEDFileFieldRepresentationTree.hxx"
23
24 #include "vtkAdjacentVertexIterator.h"
25 #include "vtkIntArray.h"
26 #include "vtkCellData.h"
27 #include "vtkPointData.h"
28
29 #include "vtkStreamingDemandDrivenPipeline.h"
30 #include "vtkUnstructuredGrid.h"
31 #include  "vtkMultiBlockDataSet.h"
32
33 #include "vtkInformationStringKey.h"
34 #include "vtkAlgorithmOutput.h"
35 #include "vtkObjectFactory.h"
36 #include "vtkMutableDirectedGraph.h"
37 #include "vtkMultiBlockDataSet.h"
38 #include "vtkDataSet.h"
39 #include "vtkInformationVector.h"
40 #include "vtkInformation.h"
41 #include "vtkDataArraySelection.h"
42 #include "vtkTimeStamp.h"
43 #include "vtkInEdgeIterator.h"
44 #include "vtkInformationDataObjectKey.h"
45 #include "vtkExecutive.h"
46 #include "vtkVariantArray.h"
47 #include "vtkStringArray.h"
48 #include "vtkDoubleArray.h"
49 #include "vtkCharArray.h"
50 #include "vtkUnsignedCharArray.h"
51 #include "vtkDataSetAttributes.h"
52 #include "vtkDemandDrivenPipeline.h"
53 #include "vtkDataObjectTreeIterator.h"
54 #include "vtkThreshold.h"
55
56 #include <map>
57 #include <deque>
58
59 vtkStandardNewMacro(vtkExtractGroup);
60
61 ///////////////////
62
63 class ExtractGroupStatus
64 {
65 public:
66   ExtractGroupStatus():_status(false) { }
67   ExtractGroupStatus(const char *name);
68   bool getStatus() const { return _status; }
69   void setStatus(bool status) { _status=status; }
70   void cpyStatusFrom(const ExtractGroupStatus& other) { _status=other._status; }
71   std::string getName() const { return _name; }
72   const char *getKeyOfEntry() const { return _ze_key_name.c_str(); }
73   virtual void printMySelf(std::ostream& os) const;
74   virtual bool isSameAs(const ExtractGroupStatus& other) const;
75 protected:
76 bool _status;
77 std::string _name;
78 std::string _ze_key_name;
79 };
80
81 class ExtractGroupGrp : public ExtractGroupStatus
82 {
83 public:
84   ExtractGroupGrp(const char *name):ExtractGroupStatus(name) { std::ostringstream oss; oss << START << name; _ze_key_name=oss.str(); }
85   void setFamilies(const std::vector<std::string>& fams) { _fams=fams; }
86   const std::vector<std::string>& getFamiliesLyingOn() const { return _fams; }
87   bool isSameAs(const ExtractGroupGrp& other) const;
88 public:
89   static const char START[];
90   std::vector<std::string> _fams;
91 };
92
93 class ExtractGroupFam : public ExtractGroupStatus
94 {
95 public:
96   ExtractGroupFam(const char *name);
97   void printMySelf(std::ostream& os) const;
98   void fillIdsToKeep(std::set<int>& s) const;
99   int getId() const { return _id; }
100   bool isSameAs(const ExtractGroupFam& other) const;
101 public:
102   static const char START[];
103 private:
104   int _id;
105 };
106
107 class vtkExtractGroup::vtkExtractGroupInternal
108 {
109 public:
110   void loadFrom(vtkMutableDirectedGraph *sil);
111   int getNumberOfEntries() const;
112   const char *getMeshName() const;
113   const char *getKeyOfEntry(int i) const;
114   bool getStatusOfEntryStr(const char *entry) const;
115   void setStatusOfEntryStr(const char *entry, bool status);
116   void printMySelf(std::ostream& os) const;
117   std::set<int> getIdsToKeep() const;
118   int getIdOfFamily(const std::string& famName) const;
119   static bool IsInformationOK(vtkInformation *info);
120 private:
121   std::map<std::string,int> computeFamStrIdMap() const;
122   const ExtractGroupStatus& getEntry(const char *entry) const;
123   ExtractGroupStatus& getEntry(const char *entry);
124 private:
125   std::vector<ExtractGroupGrp> _groups;
126   std::vector<ExtractGroupFam> _fams;
127   std::string _mesh_name;
128 };
129
130 const char ExtractGroupGrp::START[]="GRP_";
131
132 const char ExtractGroupFam::START[]="FAM_";
133
134 ExtractGroupStatus::ExtractGroupStatus(const char *name):_status(false),_name(name)
135 {
136 }
137
138 void ExtractGroupStatus::printMySelf(std::ostream& os) const
139 {
140   os << "      -" << _ze_key_name << "(";
141   if(_status)
142     os << "X";
143   else
144     os << " ";
145   os << ")" << std::endl;
146 }
147
148 bool ExtractGroupStatus::isSameAs(const ExtractGroupStatus& other) const
149 {
150   return _name==other._name && _ze_key_name==other._ze_key_name;
151 }
152
153 bool ExtractGroupGrp::isSameAs(const ExtractGroupGrp& other) const
154 {
155   bool ret(ExtractGroupStatus::isSameAs(other));
156   if(ret)
157     return _fams==other._fams;
158   else
159     return false;
160 }
161
162 bool vtkExtractGroup::vtkExtractGroupInternal::IsInformationOK(vtkInformation *info)
163 {
164   if(!info->Has(vtkDataObject::SIL()))
165     return false;
166   vtkMutableDirectedGraph *sil(vtkMutableDirectedGraph::SafeDownCast(info->Get(vtkDataObject::SIL())));
167   if(!sil)
168     return false;
169   int idNames(0);
170   vtkAbstractArray *verticesNames(sil->GetVertexData()->GetAbstractArray("Names",idNames));
171   vtkStringArray *verticesNames2(vtkStringArray::SafeDownCast(verticesNames));
172   if(!verticesNames2)
173     return false;
174   for(int i=0;i<verticesNames2->GetNumberOfValues();i++)
175     {
176       vtkStdString &st(verticesNames2->GetValue(i));
177       if(st=="MeshesFamsGrps")
178         return true;
179     }
180   return false;
181 }
182
183 const char *vtkExtractGroup::vtkExtractGroupInternal::getMeshName() const
184 {
185   return this->_mesh_name.c_str();
186 }
187
188 void vtkExtractGroup::vtkExtractGroupInternal::loadFrom(vtkMutableDirectedGraph *sil)
189 {
190   std::vector<ExtractGroupGrp> oldGrps(_groups); _groups.clear();
191   std::vector<ExtractGroupFam> oldFams(_fams); _fams.clear();
192   int idNames(0);
193   vtkAbstractArray *verticesNames(sil->GetVertexData()->GetAbstractArray("Names",idNames));
194   vtkStringArray *verticesNames2(vtkStringArray::SafeDownCast(verticesNames));
195   vtkIdType id0;
196   bool found(false);
197   for(int i=0;i<verticesNames2->GetNumberOfValues();i++)
198     {
199       vtkStdString &st(verticesNames2->GetValue(i));
200       if(st=="MeshesFamsGrps")
201         {
202           id0=i;
203           found=true;
204         }
205     }
206   if(!found)
207     throw INTERP_KERNEL::Exception("There is an internal error ! The tree on server side has not the expected look !");
208   vtkAdjacentVertexIterator *it0(vtkAdjacentVertexIterator::New());
209   sil->GetAdjacentVertices(id0,it0);
210   int kk(0),ll(0);
211   while(it0->HasNext())
212     {
213       vtkIdType id1(it0->Next());
214       std::string meshName((const char *)verticesNames2->GetValue(id1));
215       this->_mesh_name=meshName;
216       vtkAdjacentVertexIterator *it1(vtkAdjacentVertexIterator::New());
217       sil->GetAdjacentVertices(id1,it1);
218       vtkIdType idZeGrps(it1->Next());//zeGroups
219       vtkAdjacentVertexIterator *itGrps(vtkAdjacentVertexIterator::New());
220       sil->GetAdjacentVertices(idZeGrps,itGrps);
221       while(itGrps->HasNext())
222         {
223           vtkIdType idg(itGrps->Next());
224           ExtractGroupGrp grp((const char *)verticesNames2->GetValue(idg));
225           vtkAdjacentVertexIterator *itGrps2(vtkAdjacentVertexIterator::New());
226           sil->GetAdjacentVertices(idg,itGrps2);
227           std::vector<std::string> famsOnGroup;
228           while(itGrps2->HasNext())
229             {
230               vtkIdType idgf(itGrps2->Next());
231               famsOnGroup.push_back(std::string((const char *)verticesNames2->GetValue(idgf)));
232             }
233           grp.setFamilies(famsOnGroup);
234           itGrps2->Delete();
235           _groups.push_back(grp);
236         }
237       itGrps->Delete();
238       vtkIdType idZeFams(it1->Next());//zeFams
239       it1->Delete();
240       vtkAdjacentVertexIterator *itFams(vtkAdjacentVertexIterator::New());
241       sil->GetAdjacentVertices(idZeFams,itFams);
242       while(itFams->HasNext())
243         {
244           vtkIdType idf(itFams->Next());
245           ExtractGroupFam fam((const char *)verticesNames2->GetValue(idf));
246           _fams.push_back(fam);
247         }
248       itFams->Delete();
249     }
250   it0->Delete(); 
251   //
252   std::size_t szg(_groups.size()),szf(_fams.size());
253   if(szg==oldGrps.size() && szf==oldFams.size())
254     {
255       bool isSame(true);
256       for(std::size_t i=0;i<szg && isSame;i++)
257         isSame=_groups[i].isSameAs(oldGrps[i]);
258       for(std::size_t i=0;i<szf && isSame;i++)
259         isSame=_fams[i].isSameAs(oldFams[i]);
260       if(isSame)
261         {
262           for(std::size_t i=0;i<szg;i++)
263             _groups[i].cpyStatusFrom(oldGrps[i]);
264           for(std::size_t i=0;i<szf;i++)
265             _fams[i].cpyStatusFrom(oldFams[i]);
266         }
267     }
268 }
269
270 int vtkExtractGroup::vtkExtractGroupInternal::getNumberOfEntries() const
271 {
272   std::size_t sz0(_groups.size()),sz1(_fams.size());
273   return (int)(sz0+sz1);
274 }
275
276 const char *vtkExtractGroup::vtkExtractGroupInternal::getKeyOfEntry(int i) const
277 {
278   int sz0((int)_groups.size());
279   if(i>=0 && i<sz0)
280     return _groups[i].getKeyOfEntry();
281   else
282     return _fams[i-sz0].getKeyOfEntry();
283 }
284
285 bool vtkExtractGroup::vtkExtractGroupInternal::getStatusOfEntryStr(const char *entry) const
286 {
287   const ExtractGroupStatus& elt(getEntry(entry));
288   return elt.getStatus();
289 }
290
291 void vtkExtractGroup::vtkExtractGroupInternal::setStatusOfEntryStr(const char *entry, bool status)
292 {
293   ExtractGroupStatus& elt(getEntry(entry));
294   elt.setStatus(status);
295 }
296
297 const ExtractGroupStatus& vtkExtractGroup::vtkExtractGroupInternal::getEntry(const char *entry) const
298 {
299   std::string entryCpp(entry);
300   for(std::vector<ExtractGroupGrp>::const_iterator it0=_groups.begin();it0!=_groups.end();it0++)
301     if(entryCpp==(*it0).getKeyOfEntry())
302       return *it0;
303   for(std::vector<ExtractGroupFam>::const_iterator it0=_fams.begin();it0!=_fams.end();it0++)
304     if(entryCpp==(*it0).getKeyOfEntry())
305       return *it0;
306   std::ostringstream oss; oss << "vtkExtractGroupInternal::getEntry : no such entry \"" << entry << "\"!";
307   throw INTERP_KERNEL::Exception(oss.str().c_str());
308 }
309
310 ExtractGroupStatus& vtkExtractGroup::vtkExtractGroupInternal::getEntry(const char *entry)
311 {
312   std::string entryCpp(entry);
313   for(std::vector<ExtractGroupGrp>::iterator it0=_groups.begin();it0!=_groups.end();it0++)
314     if(entryCpp==(*it0).getKeyOfEntry())
315       return *it0;
316   for(std::vector<ExtractGroupFam>::iterator it0=_fams.begin();it0!=_fams.end();it0++)
317     if(entryCpp==(*it0).getKeyOfEntry())
318       return *it0;
319   std::ostringstream oss; oss << "vtkExtractGroupInternal::getEntry : no such entry \"" << entry << "\"!";
320   throw INTERP_KERNEL::Exception(oss.str().c_str());
321 }
322
323 void vtkExtractGroup::vtkExtractGroupInternal::printMySelf(std::ostream& os) const
324 {
325   os << "Groups :" << std::endl;
326   for(std::vector<ExtractGroupGrp>::const_iterator it0=_groups.begin();it0!=_groups.end();it0++)
327     (*it0).printMySelf(os);
328   os << "Families :" << std::endl;
329   for(std::vector<ExtractGroupFam>::const_iterator it0=_fams.begin();it0!=_fams.end();it0++)
330     (*it0).printMySelf(os);
331 }
332
333 int vtkExtractGroup::vtkExtractGroupInternal::getIdOfFamily(const std::string& famName) const
334 {
335   for(std::vector<ExtractGroupFam>::const_iterator it=_fams.begin();it!=_fams.end();it++)
336     {
337       if((*it).getName()==famName)
338         return (*it).getId();
339     }
340 }
341
342 ExtractGroupFam::ExtractGroupFam(const char *name):ExtractGroupStatus(name),_id(0)
343 {
344   std::size_t pos(_name.find(MEDFileFieldRepresentationLeavesArrays::ZE_SEP));
345   std::string name0(_name.substr(0,pos)),name1(_name.substr(pos+strlen(MEDFileFieldRepresentationLeavesArrays::ZE_SEP)));
346   std::istringstream iss(name1);
347   iss >> _id;
348   std::ostringstream oss; oss << START << name; _ze_key_name=oss.str(); _name=name0;
349 }
350
351 bool ExtractGroupFam::isSameAs(const ExtractGroupFam& other) const
352 {
353   bool ret(ExtractGroupStatus::isSameAs(other));
354   if(ret)
355     return _id==other._id;
356   else
357     return false;
358 }
359
360 void ExtractGroupFam::printMySelf(std::ostream& os) const
361 {
362   os << "      -" << _ze_key_name << " famName : \"" << _name << "\" id : " << _id << " (";
363   if(_status)
364     os << "X";
365   else
366     os << " ";
367   os << ")" << std::endl;
368 }
369
370 void ExtractGroupFam::fillIdsToKeep(std::set<int>& s) const
371 {
372   s.insert(_id);
373 }
374
375 std::set<int> vtkExtractGroup::vtkExtractGroupInternal::getIdsToKeep() const
376 {
377   std::map<std::string,int> m(this->computeFamStrIdMap());
378   std::set<int> s;
379   for(std::vector<ExtractGroupGrp>::const_iterator it0=_groups.begin();it0!=_groups.end();it0++)
380     {
381       if((*it0).getStatus())
382         {
383           const std::vector<std::string>& fams((*it0).getFamiliesLyingOn());
384           for(std::vector<std::string>::const_iterator it1=fams.begin();it1!=fams.end();it1++)
385             {
386               std::map<std::string,int>::iterator it2(m.find((*it1)));
387               if(it2!=m.end())
388                 s.insert((*it2).second);
389             }
390         }
391      }
392   for(std::vector<ExtractGroupFam>::const_iterator it0=_fams.begin();it0!=_fams.end();it0++)
393     if((*it0).getStatus())
394       (*it0).fillIdsToKeep(s);
395   return s;
396 }
397
398 std::map<std::string,int> vtkExtractGroup::vtkExtractGroupInternal::computeFamStrIdMap() const
399 {
400   std::map<std::string,int> ret;
401   for(std::vector<ExtractGroupFam>::const_iterator it0=_fams.begin();it0!=_fams.end();it0++)
402     ret[(*it0).getName()]=(*it0).getId();
403   return ret;
404 }
405
406 ////////////////////
407
408 vtkExtractGroup::vtkExtractGroup():SIL(NULL),Internal(new vtkExtractGroupInternal),InsideOut(0)
409 {
410 }
411
412 vtkExtractGroup::~vtkExtractGroup()
413 {
414   delete this->Internal;
415 }
416
417 void vtkExtractGroup::SetInsideOut(int val)
418 {
419   if(this->InsideOut!=val)
420     {
421       this->InsideOut=val;
422       this->Modified();
423     }
424 }
425
426 int vtkExtractGroup::RequestInformation(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
427 {
428   vtkUnstructuredGridAlgorithm::RequestInformation(request,inputVector,outputVector);
429   try
430     {
431       //std::cerr << "########################################## vtkExtractGroup::RequestInformation ##########################################" << std::endl;
432       vtkInformation *outInfo(outputVector->GetInformationObject(0));
433       vtkInformation *inputInfo(inputVector[0]->GetInformationObject(0));//unfortunately inputInfo->Has(vtkDataObject::SIL) returns false... use executive to find it !
434       //
435       vtkExecutive *exe(GetExecutive());
436       vtkAlgorithm *alg(this);
437       vtkInformation *infoOnSIL(alg->GetOutputInformation(0));
438       while(!vtkExtractGroup::vtkExtractGroupInternal::IsInformationOK(infoOnSIL))// skipping vtkPVPostFilter
439         {
440           if(exe->GetNumberOfInputConnections(0)<1)
441             {
442               vtkErrorMacro("No SIL Data available ! The source of this filter must be MEDReader !");
443               return 0;
444             }
445           vtkExecutive *exe2(exe->GetInputExecutive(0,0));
446           //
447           alg=exe2->GetAlgorithm(); exe=exe2; infoOnSIL=alg->GetOutputInformation(0);
448         }
449       //
450       this->SetSIL(vtkMutableDirectedGraph::SafeDownCast(infoOnSIL->Get(vtkDataObject::SIL())));
451       this->Internal->loadFrom(this->SIL);
452       //this->Internal->printMySelf(std::cerr);
453       outInfo->Set(vtkDataObject::SIL(),this->SIL);
454     }
455   catch(INTERP_KERNEL::Exception& e)
456     {
457       std::cerr << "Exception has been thrown in vtkExtractGroup::RequestInformation : " << e.what() << std::endl;
458       return 0;
459     }
460   return 1;
461 }
462
463 /*!
464  * Do not use vtkCxxSetObjectMacro macro because input mdg comes from an already managed in the pipeline just a ref on it.
465  */
466 void vtkExtractGroup::SetSIL(vtkMutableDirectedGraph *mdg)
467 {
468   if(this->SIL==mdg)
469     return ;
470   this->SIL=mdg;
471 }
472
473 template<class CellPointExtractor>
474 vtkDataSet *FilterFamilies(vtkDataSet *input, const std::set<int>& idsToKeep, bool insideOut, const char *arrNameOfFamilyField,
475                            const char *associationForThreshold, bool& catchAll, bool& catchSmth)
476 {
477   static const int VTK_DATA_ARRAY_DELETE=vtkDataArrayTemplate<double>::VTK_DATA_ARRAY_DELETE;
478   static const char ZE_SELECTION_ARR_NAME[]="@@ZeSelection@@";
479   vtkDataSet *output(input->NewInstance());
480   output->ShallowCopy(input);
481   vtkSmartPointer<vtkThreshold> thres(vtkSmartPointer<vtkThreshold>::New());
482   thres->SetInputData(output);
483   vtkDataSetAttributes *dscIn(input->GetCellData()),*dscIn2(input->GetPointData());
484   vtkDataSetAttributes *dscOut(output->GetCellData()),*dscOut2(output->GetPointData());
485   //
486   double vMin(insideOut==0?1.:0.),vMax(insideOut==0?2.:1.);
487   thres->ThresholdBetween(vMin,vMax);
488   // OK for the output 
489   //
490   CellPointExtractor cpe2(input);
491   vtkDataArray *da(cpe2.Get()->GetScalars(arrNameOfFamilyField));
492   if(!da)
493     return 0;
494   std::string daName(da->GetName());
495   vtkIntArray *dai(vtkIntArray::SafeDownCast(da));
496   if(daName!=arrNameOfFamilyField || !dai)
497     return 0;
498   //
499   int nbOfTuples(dai->GetNumberOfTuples());
500   vtkCharArray *zeSelection(vtkCharArray::New());
501   zeSelection->SetName(ZE_SELECTION_ARR_NAME);
502   zeSelection->SetNumberOfComponents(1);
503   char *pt(new char[nbOfTuples]);
504   zeSelection->SetArray(pt,nbOfTuples,0,VTK_DATA_ARRAY_DELETE);
505   const int *inPtr(dai->GetPointer(0));
506   std::fill(pt,pt+nbOfTuples,0);
507   catchAll=true; catchSmth=false;
508   std::vector<bool> pt2(nbOfTuples,false);
509   for(std::set<int>::const_iterator it=idsToKeep.begin();it!=idsToKeep.end();it++)
510     {
511       bool catchFid(false);
512       for(int i=0;i<nbOfTuples;i++)
513         if(inPtr[i]==*it)
514           { pt2[i]=true; catchFid=true; }
515       if(!catchFid)
516         catchAll=false;
517       else
518         catchSmth=true;
519     }
520   for(int ii=0;ii<nbOfTuples;ii++)
521     if(pt2[ii])
522       pt[ii]=2;
523   CellPointExtractor cpe3(output);
524   int idx(cpe3.Get()->AddArray(zeSelection));
525   cpe3.Get()->SetActiveAttribute(idx,vtkDataSetAttributes::SCALARS);
526   cpe3.Get()->CopyScalarsOff();
527   zeSelection->Delete();
528   //
529   thres->SetInputArrayToProcess(idx,0,0,associationForThreshold,ZE_SELECTION_ARR_NAME);
530   thres->Update();
531   vtkUnstructuredGrid *zeComputedOutput(thres->GetOutput());
532   CellPointExtractor cpe(zeComputedOutput);
533   cpe.Get()->RemoveArray(idx);
534   output->Delete();
535   zeComputedOutput->Register(0);
536   return zeComputedOutput;
537 }
538
539 class CellExtractor
540 {
541 public:
542   CellExtractor(vtkDataSet *ds):_ds(ds) { }
543   vtkDataSetAttributes *Get() { return _ds->GetCellData(); }
544 private:
545   vtkDataSet *_ds;
546 };
547
548 class PointExtractor
549 {
550 public:
551   PointExtractor(vtkDataSet *ds):_ds(ds) { }
552   vtkDataSetAttributes *Get() { return _ds->GetPointData(); }
553 private:
554   vtkDataSet *_ds;
555 };
556
557 int vtkExtractGroup::RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
558 {
559   try
560     {
561       //std::cerr << "########################################## vtkExtractGroup::RequestData        ##########################################" << std::endl;
562       vtkInformation* inputInfo=inputVector[0]->GetInformationObject(0);
563       vtkDataSet *input(vtkDataSet::SafeDownCast(inputInfo->Get(vtkDataObject::DATA_OBJECT())));
564       vtkInformation *info(input->GetInformation());
565       vtkInformation *outInfo(outputVector->GetInformationObject(0));
566       vtkDataSet *output(vtkDataSet::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT())));
567       std::set<int> idsToKeep(this->Internal->getIdsToKeep());
568       // first shrink the input
569       bool catchAll,catchSmth;
570       vtkDataSet *tryOnCell(FilterFamilies<CellExtractor>(input,idsToKeep,this->InsideOut,
571                                                           MEDFileFieldRepresentationLeavesArrays::FAMILY_ID_CELL_NAME,"vtkDataObject::FIELD_ASSOCIATION_CELLS",catchAll,catchSmth));
572       if(tryOnCell)
573         {
574           if(catchAll)
575             {
576               output->ShallowCopy(tryOnCell);
577               tryOnCell->Delete();//
578               return 1;
579             }
580           else
581             {
582               if(catchSmth)
583                 {
584                   vtkDataSet *tryOnNode(FilterFamilies<PointExtractor>(tryOnCell,idsToKeep,this->InsideOut,
585                                                                        MEDFileFieldRepresentationLeavesArrays::FAMILY_ID_NODE_NAME,"vtkDataObject::FIELD_ASSOCIATION_POINTS",catchAll,catchSmth));
586                   if(tryOnNode && catchSmth)
587                     {
588                       output->ShallowCopy(tryOnNode);
589                       tryOnCell->Delete();
590                       tryOnNode->Delete();//
591                       return 1;
592                     }
593                   else
594                     {
595                       if(tryOnNode)
596                         tryOnNode->Delete();
597                       output->ShallowCopy(tryOnCell);
598                       tryOnCell->Delete();
599                       return 1;
600                     }
601                 }
602               else
603                 {
604                   vtkDataSet *tryOnNode(FilterFamilies<PointExtractor>(input,idsToKeep,this->InsideOut,
605                                                                        MEDFileFieldRepresentationLeavesArrays::FAMILY_ID_NODE_NAME,"vtkDataObject::FIELD_ASSOCIATION_POINTS",catchAll,catchSmth));
606                   if(tryOnNode)
607                     {
608                       tryOnCell->Delete();
609                       output->ShallowCopy(tryOnNode);
610                       tryOnNode->Delete();
611                       return 1;
612                     }
613                   else
614                     {
615                       output->ShallowCopy(tryOnCell);
616                       tryOnCell->Delete();
617                       return 0;
618                     }
619                 }
620             }
621         }
622       else
623         {
624           vtkDataSet *tryOnNode(FilterFamilies<PointExtractor>(input,idsToKeep,this->InsideOut,
625                                                                MEDFileFieldRepresentationLeavesArrays::FAMILY_ID_NODE_NAME,"vtkDataObject::FIELD_ASSOCIATION_POINTS",catchAll,catchSmth));
626           if(tryOnNode)
627             {
628               output->ShallowCopy(tryOnNode);
629               tryOnNode->Delete();//
630               return 1;
631             }
632           else
633             {
634               std::ostringstream oss; oss << "vtkExtractGroup::RequestData : The integer array with name \""<< MEDFileFieldRepresentationLeavesArrays::FAMILY_ID_CELL_NAME;
635               oss << "\" or \"" << MEDFileFieldRepresentationLeavesArrays::FAMILY_ID_NODE_NAME << "\" does not exist ! The extraction of group and/or family is not possible !";
636               if(this->HasObserver("ErrorEvent") )
637                 this->InvokeEvent("ErrorEvent",const_cast<char *>(oss.str().c_str()));
638               else
639                 vtkOutputWindowDisplayErrorText(const_cast<char *>(oss.str().c_str()));
640               vtkObject::BreakOnError();
641               return 0;
642             }
643         }
644     }
645   catch(INTERP_KERNEL::Exception& e)
646     {
647       std::cerr << "Exception has been thrown in vtkExtractGroup::RequestData : " << e.what() << std::endl;
648       return 0;
649     }
650 }
651
652 int vtkExtractGroup::GetSILUpdateStamp()
653 {
654   return this->SILTime;
655 }
656
657 void vtkExtractGroup::PrintSelf(ostream& os, vtkIndent indent)
658 {
659   this->Superclass::PrintSelf(os, indent);
660 }
661
662 int vtkExtractGroup::GetNumberOfGroupsFlagsArrays()
663 {
664   int ret(this->Internal->getNumberOfEntries());
665   //std::cerr << "vtkExtractGroup::GetNumberOfFieldsTreeArrays() -> " << ret << std::endl;
666   return ret;
667 }
668
669 const char *vtkExtractGroup::GetGroupsFlagsArrayName(int index)
670 {
671   const char *ret(this->Internal->getKeyOfEntry(index));
672   //std::cerr << "vtkExtractGroup::GetFieldsTreeArrayName(" << index << ") -> " << ret << std::endl;
673   return ret;
674 }
675
676 int vtkExtractGroup::GetGroupsFlagsArrayStatus(const char *name)
677 {
678   int ret((int)this->Internal->getStatusOfEntryStr(name));
679   //std::cerr << "vtkExtractGroup::GetGroupsFlagsArrayStatus(" << name << ") -> " << ret << std::endl;
680   return ret;
681 }
682
683 void vtkExtractGroup::SetGroupsFlagsStatus(const char *name, int status)
684 {
685   //std::cerr << "vtkExtractGroup::SetFieldsStatus(" << name << "," << status << ")" << std::endl;
686   this->Internal->setStatusOfEntryStr(name,(bool)status);
687   if(std::string(name)==GetGroupsFlagsArrayName(GetNumberOfGroupsFlagsArrays()-1))
688      this->Modified();
689   //this->Internal->printMySelf(std::cerr);
690 }
691
692 const char *vtkExtractGroup::GetMeshName()
693 {
694   return this->Internal->getMeshName();
695 }