Salome HOME
0cc0d1883b0109d3d689f5bfc03b4dbde26441a4
[modules/gui.git] / src / VTKViewer / VTKViewer_ExtractUnstructuredGrid.cxx
1 // Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // File:    VTKViewer_ExtractUnstructuredGrid.cxx
24 // Author:  Alexey PETROV
25
26 #include "VTKViewer_ExtractUnstructuredGrid.h"
27 //#include "VTKViewer_CellLocationsArray.h"
28
29 #include <vtkUnsignedCharArray.h>
30 #include <vtkUnstructuredGrid.h>
31 #include <vtkObjectFactory.h>
32 #include <vtkCellArray.h>
33 #include <vtkIdList.h>
34 #include <vtkCell.h>
35 #include <vtkCellData.h>
36 #include <vtkInformation.h>
37 #include <vtkInformationVector.h>
38 #include <vtkVersion.h>
39
40 #include "utilities.h"
41
42 #if defined __GNUC__
43   #if __GNUC__ == 2
44     #define __GNUC_2__
45   #endif
46 #endif
47
48 #define VTK_XVERSION (VTK_MAJOR_VERSION*10000+VTK_MINOR_VERSION*100+VTK_BUILD_VERSION)
49
50 vtkStandardNewMacro(VTKViewer_ExtractUnstructuredGrid)
51
52
53 VTKViewer_ExtractUnstructuredGrid::VTKViewer_ExtractUnstructuredGrid():
54   myExtractionMode(eCells), myChangeMode(ePassAll), myStoreMapping( false ), myPassAll( false )
55 {}
56
57
58 VTKViewer_ExtractUnstructuredGrid::~VTKViewer_ExtractUnstructuredGrid()
59 {}
60
61 void VTKViewer_ExtractUnstructuredGrid::RegisterCell(vtkIdType theCellId)
62 {
63   if ( myCellIds.insert(theCellId).second )
64     Modified();
65 }
66
67
68 void VTKViewer_ExtractUnstructuredGrid::RegisterCellsWithType(vtkIdType theCellType)
69 {
70   if ( myCellTypes.insert(theCellType).second )
71     Modified();
72 }
73
74
75 void VTKViewer_ExtractUnstructuredGrid::SetStoreMapping(int theStoreMapping)
76 {
77   if ( myStoreMapping != ( theStoreMapping != 0 ))
78   {
79     myStoreMapping = theStoreMapping != 0;
80     Modified();
81   }
82 }
83
84 vtkIdType VTKViewer_ExtractUnstructuredGrid::GetInputId(vtkIdType theOutId) const
85 {
86   if ( myPassAll || ( myCellIds.empty() && myCellTypes.empty() ))
87     return theOutId;
88
89   if ( theOutId < 0 || theOutId >= (vtkIdType) myOut2InId.size() )
90     return -1;
91   return myOut2InId[theOutId];
92 }
93
94 void VTKViewer_ExtractUnstructuredGrid::BuildOut2InMap()
95 {
96   if ( myPassAll || !myOut2InId.empty() ) return;
97
98   vtkUnstructuredGrid *anInput = dynamic_cast< vtkUnstructuredGrid*>( this->GetInput() );
99   if ( !anInput ) return;
100
101   // use a vector of cellTypes to avoid searching in myCellTypes map
102   // for a better performance (IPAL53103)
103   TVectorId cellTypesVec( VTK_NUMBER_OF_CELL_TYPES, -1 );
104   for ( TSetId::iterator type = myCellTypes.begin(); type != myCellTypes.end(); ++type )
105   {
106     if ( *type >= (int)cellTypesVec.size() ) cellTypesVec.resize( *type+1, -1 );
107     if ( *type > 0 )
108       cellTypesVec[ *type ] = *type;
109   }
110
111   // same code as in RequestData() excluding cells copying
112   vtkIdType aNbElems = 0;
113   if ( myExtractionMode == eCells )
114   {
115     aNbElems = anInput->GetNumberOfCells();
116     if (( myChangeMode == ePassAll ) ||
117         ( myCellIds.empty() && myCellTypes.empty() && myChangeMode == eRemoving))
118     {
119       myPassAll = true;
120     }
121     else
122     {
123       if ( !myCellIds.empty() && myCellTypes.empty() )
124       {
125         if ( myChangeMode == eAdding )
126         {
127           myOut2InId.reserve(myCellIds.size());
128
129           for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++)
130             if ( myCellIds.find(aCellId) != myCellIds.end() )
131               myOut2InId.push_back( aCellId );
132         }
133         else
134         {
135           myOut2InId.reserve( std::max( vtkIdType(0), vtkIdType(aNbElems - myCellIds.size())));
136
137           for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++)
138             if ( myCellIds.find(aCellId) == myCellIds.end() )
139               myOut2InId.push_back( aCellId );
140         }
141       }
142       else if ( myCellIds.empty() && !myCellTypes.empty() )
143       {
144         myOut2InId.reserve( aNbElems );
145         if ( myChangeMode == eAdding )
146         {
147           for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++)
148           {
149             vtkIdType aType = anInput->GetCellType(aCellId);
150             if ( cellTypesVec[ aType ] == aType )
151               myOut2InId.push_back( aCellId );
152           }
153         }
154         else
155         {
156           for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++)
157           {
158             vtkIdType aType = anInput->GetCellType(aCellId);
159             if ( cellTypesVec[ aType ] != aType )
160               myOut2InId.push_back( aCellId );
161           }
162         }
163       }
164       else if ( !myCellIds.empty() && !myCellTypes.empty())
165       {
166         myOut2InId.reserve( aNbElems );
167
168         if ( myChangeMode == eAdding )
169         {
170           for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++)
171           {
172             vtkIdType aType = anInput->GetCellType(aCellId);
173             if ( cellTypesVec[ aType ] == aType )
174               if ( myCellIds.find(aCellId) != myCellIds.end() )
175                 myOut2InId.push_back( aCellId );
176           }
177         }
178         else
179         {
180           for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++)
181           {
182             vtkIdType aType = anInput->GetCellType(aCellId);
183             if ( cellTypesVec[ aType ] != aType )
184               if ( myCellIds.find(aCellId) == myCellIds.end())
185                 myOut2InId.push_back( aCellId );
186           }
187         }
188       }
189     } // not ePassAll 
190   }
191   else // nodes
192   {
193     aNbElems = anInput->GetNumberOfPoints();
194
195     if (( myChangeMode == ePassAll ) ||
196         ( myCellIds.empty() && myCellTypes.empty() && myChangeMode == eRemoving) ||
197         ( !anInput->GetCellTypesArray() ))
198     {
199       myPassAll = true;
200     }
201     else if ( !myCellIds.empty() && myCellTypes.empty())
202     {
203       if ( myChangeMode == eAdding )
204       {
205         myOut2InId.reserve( myCellIds.size() );
206
207         for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++)
208           if ( myCellIds.find(aCellId) != myCellIds.end())
209             myOut2InId.push_back( aCellId );
210       }
211       else
212       {
213         myOut2InId.reserve( std::max( vtkIdType(0), vtkIdType(aNbElems - myCellIds.size())));
214
215         for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++)
216           if ( myCellIds.find(aCellId) == myCellIds.end())
217             myOut2InId.push_back( aCellId );
218       }
219     }
220     else if ( myCellIds.empty() && !myCellTypes.empty())
221     {
222       myOut2InId.reserve( aNbElems );
223
224       if ( myChangeMode == eAdding )
225       {
226         for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++)
227         {
228           vtkIdType aType = anInput->GetCellType(aCellId);
229           if ( cellTypesVec[ aType ] == aType )
230             myOut2InId.push_back( aCellId );
231         }
232       }
233       else
234       {
235         for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++)
236         {
237           vtkIdType aType = anInput->GetCellType(aCellId);
238           if ( cellTypesVec[ aType ] != aType )
239             myOut2InId.push_back( aCellId );
240         }
241       }
242     }
243     else if ( !myCellIds.empty() && !myCellTypes.empty() )
244     {
245       if ( myChangeMode == eAdding )
246       {
247         for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++)
248         {
249           vtkIdType aType = anInput->GetCellType(aCellId);
250           if ( cellTypesVec[ aType ] == aType )
251             if ( myCellIds.find(aCellId) != myCellIds.end())
252               myOut2InId.push_back( aCellId );
253         }
254       }
255       else
256       {
257         for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++)
258         {
259           vtkIdType aType = anInput->GetCellType(aCellId);
260           if ( cellTypesVec[ aType ] != aType )
261             if ( myCellIds.find(aCellId) == myCellIds.end())
262               myOut2InId.push_back( aCellId );
263         }
264       }
265     }
266   } // nodes
267
268   if ((vtkIdType) myOut2InId.size() == aNbElems )
269   {
270     myPassAll = true;
271     TVectorId().swap( myOut2InId );
272   }
273   return;
274 }
275
276 // vtkIdType VTKViewer_ExtractUnstructuredGrid::GetOutputId(int theInId) const{
277 //   if(myCellIds.empty() && myCellTypes.empty()) return theInId;
278 //   TMapId::const_iterator anIter = myIn2OutId.find(theInId);
279 //   if(anIter == myIn2OutId.end()) return -1;
280 //   return anIter->second;
281 // }
282
283
284 inline vtkIdType InsertCell(vtkUnstructuredGrid *theInput,
285                       vtkCellArray *theConnectivity,
286                       vtkUnsignedCharArray* theCellTypesArray,
287                       vtkIdTypeArray*& theFaces,
288                       vtkIdTypeArray*& theFaceLocations,
289                       vtkIdType theCellId,
290                       vtkIdList* /*theIdList*/,
291                       bool theStoreMapping,
292                       vtkIdType /*theOutId*/,
293                       VTKViewer_ExtractUnstructuredGrid::TVectorId& theOut2InId/*,
294                       VTKViewer_ExtractUnstructuredGrid::TMapId& theIn2OutId*/)
295 {
296   vtkCell      *aCell = theInput->GetCell(theCellId);
297   vtkIdType aCellType = aCell->GetCellType();
298   vtkIdType  aCellId = -1;
299 #if VTK_XVERSION > 50700
300   if (aCellType != VTK_POLYHEDRON)
301   {
302 #endif
303     aCellId = theConnectivity->InsertNextCell( aCell->GetPointIds() ); //theIdList);
304     if (theFaceLocations)
305       theFaceLocations->InsertNextValue(-1);
306 #if VTK_XVERSION > 50700
307   }
308   else
309   {
310     //MESSAGE("InsertCell type VTK_POLYHEDRON " << theStoreMapping);
311     if (!theFaces)
312     {
313       theFaces = vtkIdTypeArray::New();
314       theFaces->Allocate(theCellTypesArray->GetSize());
315       theFaceLocations = vtkIdTypeArray::New();
316       theFaceLocations->Allocate(theCellTypesArray->GetSize());
317       // FaceLocations must be padded until the current position
318       for (vtkIdType i = 0; i <= theCellTypesArray->GetMaxId(); i++)
319       {
320         theFaceLocations->InsertNextValue(-1);
321       }
322     }
323     // insert face location
324     theFaceLocations->InsertNextValue(theFaces->GetMaxId() + 1);
325
326     // insert cell connectivity and faces stream
327     vtkIdType       nfaces = 0;
328     const vtkIdType*  face = 0;
329     vtkIdType realnpts;
330     theInput->GetFaceStream(theCellId, nfaces, face);
331     vtkUnstructuredGrid::DecomposeAPolyhedronCell(
332                                                   nfaces, face, realnpts, theConnectivity, theFaces);
333   }
334 #endif
335
336   /*vtkIdType anID = */theCellTypesArray->InsertNextValue(aCellType);
337   if(theStoreMapping){
338     theOut2InId.push_back( theCellId );
339     //theIn2OutId.insert( theIn2OutId.end(), std::make_pair( theCellId, theOutId ));
340   }
341   return aCellId;
342 }
343
344 inline void InsertPointCell(vtkCellArray *theConnectivity, 
345                             vtkUnsignedCharArray* theCellTypesArray,
346                             vtkIdType theCellId,
347                             vtkIdList *theIdList,
348                             bool theStoreMapping,
349                             vtkIdType /*theOutId*/, 
350                             VTKViewer_ExtractUnstructuredGrid::TVectorId& theOut2InId/*,
351                             VTKViewer_ExtractUnstructuredGrid::TMapId& theIn2OutId*/)
352 {
353   theIdList->SetId(0,theCellId);
354   theConnectivity->InsertNextCell(theIdList);
355   theCellTypesArray->InsertNextValue(VTK_VERTEX);
356   if(theStoreMapping){
357     theOut2InId.push_back(theCellId);
358     //theIn2OutId.insert( theIn2OutId.end(), std::make_pair( theCellId, theOutId ));
359   }
360 }
361
362
363 int VTKViewer_ExtractUnstructuredGrid::RequestData(vtkInformation *vtkNotUsed(request),
364                                                    vtkInformationVector **inputVector,
365                                                    vtkInformationVector *outputVector)
366 {
367   // get the info objects
368   vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
369   vtkInformation *outInfo = outputVector->GetInformationObject(0);
370
371   // get the input and ouptut
372   vtkUnstructuredGrid *anInput =
373     vtkUnstructuredGrid::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
374   vtkUnstructuredGrid *anOutput =
375     vtkUnstructuredGrid::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
376
377   //vtkUnstructuredGrid *anInput = this->GetInput();
378   //vtkUnstructuredGrid *anOutput = this->GetOutput();
379
380   myPassAll = false;
381   TVectorId().swap( myOut2InId );
382
383   // use a vector of cellTypes to avoid searching in myCellTypes map
384   // for a better performance (IPAL53103)
385   TVectorId cellTypesVec( VTK_NUMBER_OF_CELL_TYPES, -1 );
386   for ( TSetId::iterator type = myCellTypes.begin(); type != myCellTypes.end(); ++type )
387   {
388     if ( *type >= (int)cellTypesVec.size() ) cellTypesVec.resize( *type+1, -1 );
389     if ( *type > 0 )
390       cellTypesVec[ *type ] = *type;
391   }
392
393 /*  
394     MESSAGE("Execute - anInput->GetNumberOfCells() = "<<anInput->GetNumberOfCells());
395     MESSAGE("Execute - myCellTypes.size() = "<<myCellTypes.size());
396     MESSAGE("Execute - myCellIds.size() = "<<myCellIds.size());
397     MESSAGE("Execute - myExtractionMode = "<<myExtractionMode);
398     MESSAGE("Execute - myChangeMode = "<<myChangeMode);
399 */
400   vtkIdType aNbElems = 0;
401   if(myExtractionMode == eCells)
402   {
403     aNbElems = anInput->GetNumberOfCells();
404     if(myChangeMode == ePassAll || (myCellIds.empty() && myCellTypes.empty() && myChangeMode == eRemoving)){
405       myPassAll = true;
406       if ( aNbElems > 0 ){
407         anOutput->ShallowCopy(anInput);
408         //if(myStoreMapping) myOut2InId.reserve(aNbElems);
409         // if(myStoreMapping){
410         //   for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
411         //     myOut2InId.push_back(aCellId);
412         //     //myIn2OutId.insert( myIn2OutId.end(), std::make_pair( aCellId, anOutId ));
413         //   }
414         // }
415       }
416     }else{
417       vtkIdList *anIdList = vtkIdList::New();
418       vtkCellArray *aConnectivity = vtkCellArray::New();
419       aConnectivity->Allocate(2*aNbElems,0);
420       vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
421       aCellTypesArray->SetNumberOfComponents(1);
422       aCellTypesArray->Allocate(aNbElems*aCellTypesArray->GetNumberOfComponents());
423       anOutput->GetCellData()->CopyAllocate(anInput->GetCellData(),aNbElems,aNbElems/2);
424
425       vtkIdTypeArray *newFaces = 0;
426       vtkIdTypeArray *newFaceLocations = 0;
427
428       if(!myCellIds.empty() && myCellTypes.empty()){
429         if(myStoreMapping) myOut2InId.reserve(myCellIds.size());
430         if(myChangeMode == eAdding){
431           for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
432             if(myCellIds.find(aCellId) != myCellIds.end()){
433               vtkIdType newId = InsertCell(anInput,aConnectivity,aCellTypesArray,newFaces,newFaceLocations,aCellId,anIdList,
434                                            myStoreMapping,anOutId,myOut2InId/*,myIn2OutId*/);
435               anOutput->GetCellData()->CopyData(anInput->GetCellData(),aCellId,newId);
436             }
437           }
438         }else{
439           for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
440             if(myCellIds.find(aCellId) == myCellIds.end()){
441               vtkIdType newId = InsertCell(anInput,aConnectivity,aCellTypesArray,newFaces,newFaceLocations,aCellId,anIdList,
442                                            myStoreMapping,anOutId,myOut2InId/*,myIn2OutId*/);
443               anOutput->GetCellData()->CopyData(anInput->GetCellData(),aCellId,newId);
444             }
445           }
446         }
447       }else if(myCellIds.empty() && !myCellTypes.empty()){
448         if(myChangeMode == eAdding){
449           for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
450             vtkIdType aType = anInput->GetCellType(aCellId);
451             if ( cellTypesVec[ aType ] == aType ) {
452               vtkIdType newId = InsertCell(anInput,aConnectivity,aCellTypesArray,newFaces,newFaceLocations,aCellId,anIdList,
453                                            myStoreMapping,anOutId,myOut2InId/*,myIn2OutId*/);
454               anOutput->GetCellData()->CopyData(anInput->GetCellData(),aCellId,newId);
455             }
456           }
457         }else{
458           for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
459             vtkIdType aType = anInput->GetCellType(aCellId);
460             if ( cellTypesVec[ aType ] != aType ) {
461               vtkIdType newId = InsertCell(anInput,aConnectivity,aCellTypesArray,newFaces,newFaceLocations,aCellId,anIdList,
462                                            myStoreMapping,anOutId,myOut2InId/*,myIn2OutId*/);
463               anOutput->GetCellData()->CopyData(anInput->GetCellData(),aCellId,newId);
464             }
465           }
466         }
467       }else if(!myCellIds.empty() && !myCellTypes.empty()){
468         if(myChangeMode == eAdding){
469           for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
470             vtkIdType aType = anInput->GetCellType(aCellId);
471             if ( cellTypesVec[ aType ] == aType ) {
472               if(myCellIds.find(aCellId) != myCellIds.end()){
473                 vtkIdType newId = InsertCell(anInput,aConnectivity,aCellTypesArray,newFaces,newFaceLocations,aCellId,anIdList,
474                                              myStoreMapping,anOutId,myOut2InId/*,myIn2OutId*/);
475                 anOutput->GetCellData()->CopyData(anInput->GetCellData(),aCellId,newId);
476               }
477             }
478           }
479         }else{
480           for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
481             vtkIdType aType = anInput->GetCellType(aCellId);
482             if ( cellTypesVec[ aType ] != aType ) {
483               if(myCellIds.find(aCellId) == myCellIds.end()){
484                 vtkIdType newId = InsertCell(anInput,aConnectivity,aCellTypesArray,newFaces,newFaceLocations,aCellId,anIdList,
485                                              myStoreMapping,anOutId,myOut2InId/*,myIn2OutId*/);
486                 anOutput->GetCellData()->CopyData(anInput->GetCellData(),aCellId,newId);
487               }
488             }
489           }
490         }
491       }
492       if ( vtkIdType newNbElems = aConnectivity->GetNumberOfCells() ) {
493         vtkIdTypeArray* aCellLocationsArray = vtkIdTypeArray::New();
494         aCellLocationsArray->SetNumberOfComponents(1);
495         aCellLocationsArray->SetNumberOfTuples(newNbElems);
496         aConnectivity->InitTraversal();
497         vtkIdType const *pts(nullptr);
498         for(vtkIdType i = 0, npts; aConnectivity->GetNextCell(npts,pts); i++){
499           aCellLocationsArray->SetValue(i,aConnectivity->GetTraversalLocation(npts));
500         }
501 #if VTK_XVERSION > 50700
502         anOutput->SetCells(aCellTypesArray,aCellLocationsArray,aConnectivity,newFaceLocations,newFaces);
503 #else
504         anOutput->SetCells(aCellTypesArray,aCellLocationsArray,aConnectivity);
505 #endif
506         anOutput->SetPoints(anInput->GetPoints());
507         aCellLocationsArray->Delete();
508       }
509       aCellTypesArray->Delete();
510       aConnectivity->Delete();
511       anIdList->Delete();
512       if ( newFaceLocations ) newFaceLocations->Delete();
513       if ( newFaces ) newFaces->Delete();
514     }
515   }
516   else
517   {
518     vtkIdList *anIdList = vtkIdList::New();
519     anIdList->SetNumberOfIds(1);
520     vtkCellArray *aConnectivity = vtkCellArray::New();
521     aNbElems = anInput->GetNumberOfPoints();
522     aConnectivity->Allocate(2*aNbElems,0);
523     vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
524     aCellTypesArray->SetNumberOfComponents(1);
525     aCellTypesArray->Allocate(aNbElems*aCellTypesArray->GetNumberOfComponents());
526     // additional condition has been added to treat a case described in IPAL21372
527     // note that it is significant only when myExtractionMode == ePoints
528     if(myChangeMode == ePassAll || (myCellIds.empty() && myCellTypes.empty() && myChangeMode == eRemoving) ||
529        !anInput->GetCellTypesArray()){
530       myPassAll = true;
531       //if(myStoreMapping) myOut2InId.reserve(aNbElems);
532       for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
533         InsertPointCell(aConnectivity,aCellTypesArray,aCellId,anIdList,
534                         /*theStoreMapping=*/false,anOutId,myOut2InId/*,myIn2OutId*/);
535       }
536     }else if(!myCellIds.empty() && myCellTypes.empty()){
537       if(myStoreMapping) myOut2InId.reserve(myCellIds.size());
538       if(myChangeMode == eAdding){
539         for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
540           if(myCellIds.find(aCellId) != myCellIds.end()){
541             InsertPointCell(aConnectivity,aCellTypesArray,aCellId,anIdList,
542                             myStoreMapping,anOutId,myOut2InId/*,myIn2OutId*/);
543           }
544         }
545       }else{
546         for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
547           if(myCellIds.find(aCellId) == myCellIds.end()){
548             InsertPointCell(aConnectivity,aCellTypesArray,aCellId,anIdList,
549                             myStoreMapping,anOutId,myOut2InId/*,myIn2OutId*/);
550           }
551         }
552       }
553     }else if(myCellIds.empty() && !myCellTypes.empty()){
554       if(myChangeMode == eAdding){
555         for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
556           vtkIdType aType = anInput->GetCellType(aCellId);
557           if ( cellTypesVec[ aType ] == aType ) {
558             InsertPointCell(aConnectivity,aCellTypesArray,aCellId,anIdList,
559                             myStoreMapping,anOutId,myOut2InId/*,myIn2OutId*/);
560           }
561         }
562       }else{
563         for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
564           vtkIdType aType = anInput->GetCellType(aCellId);
565           if ( cellTypesVec[ aType ] != aType ) {
566             InsertPointCell(aConnectivity,aCellTypesArray,aCellId,anIdList,
567                             myStoreMapping,anOutId,myOut2InId/*,myIn2OutId*/);
568           }
569         }
570       }
571     }else if(!myCellIds.empty() && !myCellTypes.empty()){
572       if(myChangeMode == eAdding){
573         for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
574           vtkIdType aType = anInput->GetCellType(aCellId);
575           if ( cellTypesVec[ aType ] == aType ) {
576             if(myCellIds.find(aCellId) != myCellIds.end()){
577               InsertPointCell(aConnectivity,aCellTypesArray,aCellId,anIdList,
578                               myStoreMapping,anOutId,myOut2InId/*,myIn2OutId*/);
579             }
580           }
581         }
582       }else{
583         for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
584           vtkIdType aType = anInput->GetCellType(aCellId);
585           if ( cellTypesVec[ aType ] != aType ) {
586             if(myCellIds.find(aCellId) == myCellIds.end()){
587               InsertPointCell(aConnectivity,aCellTypesArray,aCellId,anIdList,
588                               myStoreMapping,anOutId,myOut2InId/*,myIn2OutId*/);
589             }
590           }
591         }
592       }
593     }
594     if (vtkIdType newNbElems = aConnectivity->GetNumberOfCells() ) {
595       vtkIdTypeArray* aCellLocationsArray = vtkIdTypeArray::New();
596       aCellLocationsArray->SetNumberOfComponents(1);
597       aCellLocationsArray->SetNumberOfTuples( newNbElems );
598       aConnectivity->InitTraversal();
599       vtkIdType const *pts(nullptr);
600       for(vtkIdType i = 0, npts; aConnectivity->GetNextCell(npts,pts); i++){
601         aCellLocationsArray->SetValue(i,aConnectivity->GetTraversalLocation(npts));
602       }
603 #if VTK_XVERSION > 50700
604       anOutput->SetCells(aCellTypesArray,aCellLocationsArray,aConnectivity,0, 0);
605 #else
606       anOutput->SetCells(aCellTypesArray,aCellLocationsArray,aConnectivity);
607 #endif
608       anOutput->SetPoints(anInput->GetPoints());
609       aCellLocationsArray->Delete();
610     }
611     aCellTypesArray->Delete();
612     aConnectivity->Delete();
613     anIdList->Delete();
614   }
615
616   if ( aNbElems == (vtkIdType) myOut2InId.size() )
617   {
618     myPassAll = true;
619     TVectorId().swap( myOut2InId );
620   }
621 /*
622     MESSAGE("Execute - anOutput->GetNumberOfCells() = "<<anOutput->GetNumberOfCells());
623     if(myStoreMapping){
624       MESSAGE("Execute - myOut2InId.size() = "<<myOut2InId.size());
625       MESSAGE("Execute - myIn2OutId.size() = "<<myIn2OutId.size());
626     }
627 */
628   return 1;
629 }