-// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
// Author: Alexey PETROV
#include "VTKViewer_ExtractUnstructuredGrid.h"
-#include "VTKViewer_CellLocationsArray.h"
+//#include "VTKViewer_CellLocationsArray.h"
#include <vtkUnsignedCharArray.h>
#include <vtkUnstructuredGrid.h>
#define VTK_XVERSION (VTK_MAJOR_VERSION*10000+VTK_MINOR_VERSION*100+VTK_BUILD_VERSION)
-vtkStandardNewMacro(VTKViewer_ExtractUnstructuredGrid);
+vtkStandardNewMacro(VTKViewer_ExtractUnstructuredGrid)
VTKViewer_ExtractUnstructuredGrid::VTKViewer_ExtractUnstructuredGrid():
- myExtractionMode(eCells), myChangeMode(ePassAll)
+ myExtractionMode(eCells), myChangeMode(ePassAll), myStoreMapping( false ), myPassAll( false )
{}
}
}
-vtkIdType VTKViewer_ExtractUnstructuredGrid::GetInputId(int theOutId) const
+vtkIdType VTKViewer_ExtractUnstructuredGrid::GetInputId(vtkIdType theOutId) const
{
- if ( myCellIds.empty() && myCellTypes.empty() )
+ if ( myPassAll || ( myCellIds.empty() && myCellTypes.empty() ))
return theOutId;
- if ( theOutId<0 || theOutId >= (int)myOut2InId.size() )
+ if ( theOutId < 0 || theOutId >= (vtkIdType) myOut2InId.size() )
return -1;
return myOut2InId[theOutId];
}
+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;
+}
+
// vtkIdType VTKViewer_ExtractUnstructuredGrid::GetOutputId(int theInId) const{
// if(myCellIds.empty() && myCellTypes.empty()) return theInId;
// TMapId::const_iterator anIter = myIn2OutId.find(theInId);
// }
-inline int InsertCell(vtkUnstructuredGrid *theInput,
+inline vtkIdType InsertCell(vtkUnstructuredGrid *theInput,
vtkCellArray *theConnectivity,
vtkUnsignedCharArray* theCellTypesArray,
vtkIdTypeArray*& theFaces,
vtkIdTypeArray*& theFaceLocations,
vtkIdType theCellId,
- vtkIdList *theIdList,
+ vtkIdList* /*theIdList*/,
bool theStoreMapping,
- vtkIdType theOutId,
+ vtkIdType /*theOutId*/,
VTKViewer_ExtractUnstructuredGrid::TVectorId& theOut2InId/*,
VTKViewer_ExtractUnstructuredGrid::TMapId& theIn2OutId*/)
{
theFaceLocations->InsertNextValue(theFaces->GetMaxId() + 1);
// insert cell connectivity and faces stream
- vtkIdType nfaces = 0;
- vtkIdType* face = 0;
+ vtkIdType nfaces = 0;
+ const vtkIdType* face = 0;
vtkIdType realnpts;
theInput->GetFaceStream(theCellId, nfaces, face);
vtkUnstructuredGrid::DecomposeAPolyhedronCell(
vtkIdType theCellId,
vtkIdList *theIdList,
bool theStoreMapping,
- vtkIdType theOutId,
+ vtkIdType /*theOutId*/,
VTKViewer_ExtractUnstructuredGrid::TVectorId& theOut2InId/*,
VTKViewer_ExtractUnstructuredGrid::TMapId& theIn2OutId*/)
{
vtkInformation *outInfo = outputVector->GetInformationObject(0);
// get the input and ouptut
- vtkUnstructuredGrid *anInput = vtkUnstructuredGrid::SafeDownCast(
- inInfo->Get(vtkDataObject::DATA_OBJECT()));
- vtkUnstructuredGrid *anOutput = vtkUnstructuredGrid::SafeDownCast(
- outInfo->Get(vtkDataObject::DATA_OBJECT()));
+ vtkUnstructuredGrid *anInput =
+ vtkUnstructuredGrid::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
+ vtkUnstructuredGrid *anOutput =
+ vtkUnstructuredGrid::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
//vtkUnstructuredGrid *anInput = this->GetInput();
//vtkUnstructuredGrid *anOutput = this->GetOutput();
- myOut2InId.clear(); //myIn2OutId.clear();
+ myPassAll = false;
+ TVectorId().swap( myOut2InId );
// use a vector of cellTypes to avoid searching in myCellTypes map
// for a better performance (IPAL53103)
MESSAGE("Execute - myExtractionMode = "<<myExtractionMode);
MESSAGE("Execute - myChangeMode = "<<myChangeMode);
}*/
- if(myExtractionMode == eCells){
+ vtkIdType aNbElems = 0;
+ if(myExtractionMode == eCells)
+ {
+ aNbElems = anInput->GetNumberOfCells();
if(myChangeMode == ePassAll || (myCellIds.empty() && myCellTypes.empty() && myChangeMode == eRemoving)){
- if(vtkIdType aNbElems = anInput->GetNumberOfCells()){
- if(myStoreMapping) myOut2InId.reserve(aNbElems);
+ myPassAll = true;
+ if ( aNbElems > 0 ){
anOutput->ShallowCopy(anInput);
- if(myStoreMapping){
- for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
- myOut2InId.push_back(aCellId);
- //myIn2OutId.insert( myIn2OutId.end(), std::make_pair( aCellId, anOutId ));
- }
- }
+ //if(myStoreMapping) myOut2InId.reserve(aNbElems);
+ // if(myStoreMapping){
+ // for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
+ // myOut2InId.push_back(aCellId);
+ // //myIn2OutId.insert( myIn2OutId.end(), std::make_pair( aCellId, anOutId ));
+ // }
+ // }
}
}else{
vtkIdList *anIdList = vtkIdList::New();
vtkCellArray *aConnectivity = vtkCellArray::New();
- vtkIdType aNbElems = anInput->GetNumberOfCells();
aConnectivity->Allocate(2*aNbElems,0);
vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
aCellTypesArray->SetNumberOfComponents(1);
}
}
}
- if((aNbElems = aConnectivity->GetNumberOfCells())){
- VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
+ if ( vtkIdType newNbElems = aConnectivity->GetNumberOfCells() ) {
+ vtkIdTypeArray* aCellLocationsArray = vtkIdTypeArray::New();
aCellLocationsArray->SetNumberOfComponents(1);
- aCellLocationsArray->SetNumberOfTuples(aNbElems);
+ aCellLocationsArray->SetNumberOfTuples(newNbElems);
aConnectivity->InitTraversal();
- for(vtkIdType i = 0, *pts, npts; aConnectivity->GetNextCell(npts,pts); i++){
+ vtkIdType const *pts(nullptr);
+ for(vtkIdType i = 0, npts; aConnectivity->GetNextCell(npts,pts); i++){
aCellLocationsArray->SetValue(i,aConnectivity->GetTraversalLocation(npts));
}
#if VTK_XVERSION > 50700
if ( newFaceLocations ) newFaceLocations->Delete();
if ( newFaces ) newFaces->Delete();
}
- }else{
+ }
+ else
+ {
vtkIdList *anIdList = vtkIdList::New();
anIdList->SetNumberOfIds(1);
vtkCellArray *aConnectivity = vtkCellArray::New();
- vtkIdType aNbElems = anInput->GetNumberOfPoints();
+ aNbElems = anInput->GetNumberOfPoints();
aConnectivity->Allocate(2*aNbElems,0);
vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
aCellTypesArray->SetNumberOfComponents(1);
// note that it is significant only when myExtractionMode == ePoints
if(myChangeMode == ePassAll || (myCellIds.empty() && myCellTypes.empty() && myChangeMode == eRemoving) ||
!anInput->GetCellTypesArray()){
- if(myStoreMapping) myOut2InId.reserve(aNbElems);
+ myPassAll = true;
+ //if(myStoreMapping) myOut2InId.reserve(aNbElems);
for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
InsertPointCell(aConnectivity,aCellTypesArray,aCellId,anIdList,
- myStoreMapping,anOutId,myOut2InId/*,myIn2OutId*/);
+ /*theStoreMapping=*/false,anOutId,myOut2InId/*,myIn2OutId*/);
}
}else if(!myCellIds.empty() && myCellTypes.empty()){
if(myStoreMapping) myOut2InId.reserve(myCellIds.size());
}
}
}
- if((aNbElems = aConnectivity->GetNumberOfCells())){
- VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
+ if (vtkIdType newNbElems = aConnectivity->GetNumberOfCells() ) {
+ vtkIdTypeArray* aCellLocationsArray = vtkIdTypeArray::New();
aCellLocationsArray->SetNumberOfComponents(1);
- aCellLocationsArray->SetNumberOfTuples(aNbElems);
+ aCellLocationsArray->SetNumberOfTuples( newNbElems );
aConnectivity->InitTraversal();
- for(vtkIdType i = 0, *pts, npts; aConnectivity->GetNextCell(npts,pts); i++){
+ vtkIdType const *pts(nullptr);
+ for(vtkIdType i = 0, npts; aConnectivity->GetNextCell(npts,pts); i++){
aCellLocationsArray->SetValue(i,aConnectivity->GetTraversalLocation(npts));
}
#if VTK_XVERSION > 50700
aConnectivity->Delete();
anIdList->Delete();
}
+
+ if ( aNbElems == (vtkIdType) myOut2InId.size() )
+ {
+ myPassAll = true;
+ TVectorId().swap( myOut2InId );
+ }
/* if(MYDEBUG){
MESSAGE("Execute - anOutput->GetNumberOfCells() = "<<anOutput->GetNumberOfCells());
if(myStoreMapping){