aPointCellIds.clear();
vtkCell* aCell = inputUGrid->GetCell(idCell);
vtkIdList* ptIds = aCell->GetPointIds();
- int aMaxId = ptIds->GetNumberOfIds();
- int* aPointer = ptIds->GetPointer(0);
- int* anEndPointer = ptIds->GetPointer(aMaxId + 1);
- TSortedArray aSortedArray(aPointer, anEndPointer);
- std::sort(aSortedArray.begin(), aSortedArray.end());
-
- int aMaxLength = std::max(aSortedArray.size(), aSortedPointIds.size());
- TSortedArray anIntersectionArray(aMaxLength);
- TSortedArray::iterator anArrayIter = anIntersectionArray.begin();
- anArrayIter = std::set_intersection(aSortedArray.begin(),
- aSortedArray.end(),
- aSortedPointIds.begin(),
- aSortedPointIds.end(),
- anArrayIter);
- anIntersectionArray.erase(anArrayIter, anIntersectionArray.end());
- if(anIntersectionArray.size() == aSortedArray.size())
+ int nbPointsInCell = ptIds->GetNumberOfIds();
+ bool aGoodCell = true;
+ for(int i=0;i<nbPointsInCell;i++){
+ int aSearchingId = ptIds->GetId(i);
+ TSortedArray::iterator aResult = find(aSortedPointIds.begin(),aSortedPointIds.end(),aSearchingId);
+ if(aResult == aSortedPointIds.end()){
+ aGoodCell = false;
+ break;
+ }
+ }
+ if(aGoodCell)
aOutputCellIds.push_back(idCell);
+ else
+ continue;
}
outputSortedArray.swap(aOutputCellIds);
int nbPointsInGeometr = anInput->GetNumberOfPoints();
vtkCellData *aCellData = anInput->GetCellData();
+ vtkDataArray* aScalarsOnCellsArray = NULL;
+ if(aInputScalars->GetCellData())
+ aScalarsOnCellsArray = aInputScalars->GetCellData()->GetArray("VISU_FIELD");
+ vtkDataArray* aScalarsOnPointsArray = NULL;
+ if(aInputScalars->GetPointData())
+ aScalarsOnPointsArray = aInputScalars->GetPointData()->GetArray("VISU_FIELD");
+
vtkDataArray *aPointMapper = aPointData->GetArray("VISU_POINTS_MAPPER");
vtkIntArray *aGeometryPointMapper = dynamic_cast<vtkIntArray*>(aPointMapper);
vtkDataArray *aCellMapper = aCellData->GetArray("VISU_CELLS_MAPPER");
vtkIntArray *aGeometryCellMapper = dynamic_cast<vtkIntArray*>(aCellMapper);
- if(aGeometryCellMapper && (nbPointsInScalars == nbPointsInGeometr)){
+
+ if(aGeometryCellMapper && aScalarsOnCellsArray && (nbPointsInScalars == nbPointsInGeometr)){
vtkIntArray* aDataCellMapper = NULL;
VISU::TFieldListIterator anIter(this->FieldList);
for(anIter.Begin(); !anIter.End() ; anIter.Next()){
break;
}
}
-
+
bool anIsDifferent = aDataCellMapper &&
aDataCellMapper->GetNumberOfTuples() != aGeometryCellMapper->GetNumberOfTuples();
- if(anIsDifferent || IsMergingInputs()){
+
+ if(anIsDifferent || IsMergingInputs() ){
+ // The situation for merging CELLS from anInput as Geometry
+ // and scalars on cell data
TSortedArray aGeometryCellArray;
GetSortedArray(aGeometryCellMapper, aGeometryCellArray);
return;
}
}
+ } else if (aGeometryCellMapper && aScalarsOnPointsArray && (nbPointsInScalars == nbPointsInGeometr)) {
+ // The situation for merging CELLS from anInput as Geometry
+ // and scalars on point data
+ vtkPointData* aInputScalarsPointData = aInputScalars->GetPointData();
+
+ vtkIntArray* aDataPointMapper = NULL;
+ VISU::TFieldListIterator anIter(this->FieldList);
+ for(anIter.Begin(); !anIter.End() ; anIter.Next()){
+ const char* aFieldName = anIter.Get()->GetName();
+ if(strcmp(aFieldName, "VISU_POINTS_MAPPER") == 0){
+ vtkDataArray *aPointMapper = aInputScalarsPointData->GetArray(aFieldName);
+ aDataPointMapper = dynamic_cast<vtkIntArray*>(aPointMapper);
+ break;
+ }
+ }
+
+ if(aDataPointMapper){
+ TSortedArray aGeometryPointArray;
+ GetSortedArray(aGeometryPointMapper, aGeometryPointArray);
+
+ TSortedArray aDataPointArray;
+ GetSortedArray(aDataPointMapper, aDataPointArray);
+
+ {
+ TId2IdMap anObj2VTKGeometryPointsMap;
+ vtkIdType aNbCells = aDataPointMapper->GetNumberOfTuples();
+ for(int aCellId = 0; aCellId < aNbCells; aCellId++){
+ vtkIdType anObjID = aDataPointMapper->GetValue(aCellId);
+ anObj2VTKGeometryPointsMap[anObjID] = aCellId;
+ }
+
+ TId2IdMap anObj2VTKGeometryCellsMap;
+ aNbCells = aGeometryCellMapper->GetNumberOfTuples();
+ for(int aCellId = 0; aCellId < aNbCells; aCellId++){
+ vtkIdType anObjID = aGeometryCellMapper->GetValue(aCellId);
+ anObj2VTKGeometryCellsMap[anObjID] = aCellId;
+ }
+
+ // copy points to output
+ vtkUnstructuredGrid* aUnstructuredScalars = dynamic_cast<vtkUnstructuredGrid*>(aInputScalars);
+ if(aUnstructuredScalars)
+ anOutput->SetPoints(aUnstructuredScalars->GetPoints());
+ anOutput->GetPointData()->ShallowCopy(aInputScalars->GetPointData());
+
+ // Calculate output cells
+ int nbCells=0;
+ TSortedArray aCellIdsForCopy_fromCellMapper;
+ GetSortedArray(aGeometryCellMapper, aCellIdsForCopy_fromCellMapper);
+ nbCells = aCellIdsForCopy_fromCellMapper.size();
+
+ TSortedArray aCellIdsForCopy;
+ for(int i=0;i<nbCells;i++)
+ aCellIdsForCopy.push_back(anObj2VTKGeometryCellsMap[aCellIdsForCopy_fromCellMapper[i]]);
+
+ // copy cells to output
+ anOutput->Allocate(nbCells);
+ vtkIntArray* theOuputIDSArray = vtkIntArray::New();
+ theOuputIDSArray->SetName("VISU_CELLS_MAPPER");
+ theOuputIDSArray->SetNumberOfComponents(1);
+ theOuputIDSArray->SetNumberOfTuples(nbCells);
+
+ if(nbCells>0)
+ CopyElementsToOutput(anInput,
+ nbCells,
+ aCellIdsForCopy,
+ anObj2VTKGeometryPointsMap,
+ theOuputIDSArray,
+ anOutput);
+ theOuputIDSArray->Delete();
+
+ return;
+ }
+ }
} else if (aGeometryCellMapper && (nbPointsInScalars < nbPointsInGeometr)) {
+ // The situation for merging CELLS from anInput as Geometry
+ // and scalars on point data (there the number of points of point data less than
+ // number of points of Geometry)
vtkPointData* aInputScalarsPointData = aInputScalars->GetPointData();
{
TId2IdMap anObj2VTKGeometryMap;
- vtkIdType aNbCells = aDataPointMapper/*aGeometryPointMapper*/->GetNumberOfTuples();
+ vtkIdType aNbCells = aDataPointMapper->GetNumberOfTuples();
for(int aCellId = 0; aCellId < aNbCells; aCellId++){
- vtkIdType anObjID = aDataPointMapper/*aGeometryPointMapper*/->GetValue(aCellId);
+ vtkIdType anObjID = aDataPointMapper->GetValue(aCellId);
anObj2VTKGeometryMap[anObjID] = aCellId;
}