+void VTKViewer_ExtractUnstructuredGrid::BuildOut2InMap()
+{
+ if ( myPassAll || !myOut2InId.empty() ) return;
+
+ vtkUnstructuredGrid *anInput = dynamic_cast< vtkUnstructuredGrid*>( this->GetInput() );
+ if ( !anInput ) return;
+
+ // use a vector of cellTypes to avoid searching in myCellTypes map
+ // for a better performance (IPAL53103)
+ TVectorId cellTypesVec( VTK_NUMBER_OF_CELL_TYPES, -1 );
+ for ( TSetId::iterator type = myCellTypes.begin(); type != myCellTypes.end(); ++type )
+ {
+ if ( *type >= (int)cellTypesVec.size() ) cellTypesVec.resize( *type+1, -1 );
+ if ( *type > 0 )
+ cellTypesVec[ *type ] = *type;
+ }
+
+ // same code as in RequestData() excluding cells copying
+ vtkIdType aNbElems = 0;
+ if ( myExtractionMode == eCells )
+ {
+ aNbElems = anInput->GetNumberOfCells();
+ if (( myChangeMode == ePassAll ) ||
+ ( myCellIds.empty() && myCellTypes.empty() && myChangeMode == eRemoving))
+ {
+ myPassAll = true;
+ }
+ else
+ {
+ if ( !myCellIds.empty() && myCellTypes.empty() )
+ {
+ if ( myChangeMode == eAdding )
+ {
+ myOut2InId.reserve(myCellIds.size());
+
+ for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++)
+ if ( myCellIds.find(aCellId) != myCellIds.end() )
+ myOut2InId.push_back( aCellId );
+ }
+ else
+ {
+ myOut2InId.reserve( std::max( vtkIdType(0), vtkIdType(aNbElems - myCellIds.size())));
+
+ for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++)
+ if ( myCellIds.find(aCellId) == myCellIds.end() )
+ myOut2InId.push_back( aCellId );
+ }
+ }
+ else if ( myCellIds.empty() && !myCellTypes.empty() )
+ {
+ myOut2InId.reserve( aNbElems );
+ if ( myChangeMode == eAdding )
+ {
+ for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++)
+ {
+ vtkIdType aType = anInput->GetCellType(aCellId);
+ if ( cellTypesVec[ aType ] == aType )
+ myOut2InId.push_back( aCellId );
+ }
+ }
+ else
+ {
+ for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++)
+ {
+ vtkIdType aType = anInput->GetCellType(aCellId);
+ if ( cellTypesVec[ aType ] != aType )
+ myOut2InId.push_back( aCellId );
+ }
+ }
+ }
+ else if ( !myCellIds.empty() && !myCellTypes.empty())
+ {
+ myOut2InId.reserve( aNbElems );
+
+ if ( myChangeMode == eAdding )
+ {
+ for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++)
+ {
+ vtkIdType aType = anInput->GetCellType(aCellId);
+ if ( cellTypesVec[ aType ] == aType )
+ if ( myCellIds.find(aCellId) != myCellIds.end() )
+ myOut2InId.push_back( aCellId );
+ }
+ }
+ else
+ {
+ for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++)
+ {
+ vtkIdType aType = anInput->GetCellType(aCellId);
+ if ( cellTypesVec[ aType ] != aType )
+ if ( myCellIds.find(aCellId) == myCellIds.end())
+ myOut2InId.push_back( aCellId );
+ }
+ }
+ }
+ } // not ePassAll
+ }
+ else // nodes
+ {
+ aNbElems = anInput->GetNumberOfPoints();
+
+ if (( myChangeMode == ePassAll ) ||
+ ( myCellIds.empty() && myCellTypes.empty() && myChangeMode == eRemoving) ||
+ ( !anInput->GetCellTypesArray() ))
+ {
+ myPassAll = true;
+ }
+ else if ( !myCellIds.empty() && myCellTypes.empty())
+ {
+ if ( myChangeMode == eAdding )
+ {
+ myOut2InId.reserve( myCellIds.size() );
+
+ for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++)
+ if ( myCellIds.find(aCellId) != myCellIds.end())
+ myOut2InId.push_back( aCellId );
+ }
+ else
+ {
+ myOut2InId.reserve( std::max( vtkIdType(0), vtkIdType(aNbElems - myCellIds.size())));
+
+ for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++)
+ if ( myCellIds.find(aCellId) == myCellIds.end())
+ myOut2InId.push_back( aCellId );
+ }
+ }
+ else if ( myCellIds.empty() && !myCellTypes.empty())
+ {
+ myOut2InId.reserve( aNbElems );
+
+ if ( myChangeMode == eAdding )
+ {
+ for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++)
+ {
+ vtkIdType aType = anInput->GetCellType(aCellId);
+ if ( cellTypesVec[ aType ] == aType )
+ myOut2InId.push_back( aCellId );
+ }
+ }
+ else
+ {
+ for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++)
+ {
+ vtkIdType aType = anInput->GetCellType(aCellId);
+ if ( cellTypesVec[ aType ] != aType )
+ myOut2InId.push_back( aCellId );
+ }
+ }
+ }
+ else if ( !myCellIds.empty() && !myCellTypes.empty() )
+ {
+ if ( myChangeMode == eAdding )
+ {
+ for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++)
+ {
+ vtkIdType aType = anInput->GetCellType(aCellId);
+ if ( cellTypesVec[ aType ] == aType )
+ if ( myCellIds.find(aCellId) != myCellIds.end())
+ myOut2InId.push_back( aCellId );
+ }
+ }
+ else
+ {
+ for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++)
+ {
+ vtkIdType aType = anInput->GetCellType(aCellId);
+ if ( cellTypesVec[ aType ] != aType )
+ if ( myCellIds.find(aCellId) == myCellIds.end())
+ myOut2InId.push_back( aCellId );
+ }
+ }
+ }
+ } // nodes
+
+ if ((vtkIdType) myOut2InId.size() == aNbElems )
+ {
+ myPassAll = true;
+ TVectorId().swap( myOut2InId );
+ }
+ return;