theObj2VTKMap);
}
}
+
+ inline
+ void
+ GetIdsForCopy(vtkUnstructuredGrid *inputUGrid,
+ vtkIntArray* inputPointIds,
+ TSortedArray& outputSortedArray)
+ {
+ if(inputUGrid){
+ TSortedArray aSortedPointIds;
+ TSortedArray aOutputCellIds;
+ GetSortedArray(inputPointIds,aSortedPointIds);
+
+ int nbInputCells = inputUGrid->GetNumberOfCells();
+
+ TSortedArray aPointCellIds;
+ for(int idCell=0;idCell<nbInputCells;idCell++){
+ 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())
+ aOutputCellIds.push_back(idCell);
+ }
+
+ outputSortedArray.swap(aOutputCellIds);
+ }
+ }
+
+ inline
+ void
+ CopyElementsToOutput(vtkUnstructuredGrid* theInputUG,
+ int& theNbElements,
+ TSortedArray& theElementIdsForCopy,
+ TId2IdMap& theOldId2NewIdPointsMap,
+ vtkIntArray* theOuputIDSArray,
+ vtkUnstructuredGrid* theOutputUG)
+ {
+ vtkIntArray* aInputCellsMapper =
+ dynamic_cast<vtkIntArray*>(theInputUG->GetCellData()->GetArray("VISU_CELLS_MAPPER"));
+
+ int* aInputCellsMapperPointer = aInputCellsMapper->GetPointer(0);
+
+ for(int aCellIndex=0;aCellIndex<theNbElements;aCellIndex++){
+ int aCellId = theElementIdsForCopy[aCellIndex];
+ vtkIdList* aOldPointIds = theInputUG->GetCell(aCellId)->GetPointIds();
+ vtkIdList* aNewPointIds = vtkIdList::New();
+ int nbPointIds = aOldPointIds->GetNumberOfIds();
+ aNewPointIds->SetNumberOfIds(nbPointIds);
+ for(int j=0;j<nbPointIds;j++){
+ int aOldId = aOldPointIds->GetId(j);
+ int aNewId = theOldId2NewIdPointsMap[aOldId];
+ aNewPointIds->SetId(j,aNewId);
+ }
+ const int aOldCellId = theElementIdsForCopy[aCellIndex];
+ theOutputUG->InsertNextCell(theInputUG->GetCellType(aOldCellId),
+ aNewPointIds);
+ if(aInputCellsMapperPointer)
+ theOuputIDSArray->InsertNextValue(aInputCellsMapperPointer[aOldCellId]);
+ else
+ theOuputIDSArray->InsertNextValue(aOldCellId);
+
+ aNewPointIds->Delete();
+ }
+ theOutputUG->GetCellData()->AddArray(theOuputIDSArray);
+ }
+
+
}
void
vtkUnstructuredGrid *anInput = this->GetInput();
vtkUnstructuredGrid *anOutput = this->GetOutput();
+ vtkPointData *aPointData = anInput->GetPointData();
+ vtkDataSet* aInputScalars = this->GetScalars();
+ int nbPointsInScalars = aInputScalars->GetNumberOfPoints();
+ int nbPointsInGeometr = anInput->GetNumberOfPoints();
vtkCellData *aCellData = anInput->GetCellData();
+
+ vtkDataArray *aPointMapper = aPointData->GetArray("VISU_POINTS_MAPPER");
+ vtkIntArray *aGeometryPointMapper = dynamic_cast<vtkIntArray*>(aPointMapper);
vtkDataArray *aCellMapper = aCellData->GetArray("VISU_CELLS_MAPPER");
- if(vtkIntArray *aGeometryCellMapper = dynamic_cast<vtkIntArray*>(aCellMapper)){
+ vtkIntArray *aGeometryCellMapper = dynamic_cast<vtkIntArray*>(aCellMapper);
+ if(aGeometryCellMapper && (nbPointsInScalars == nbPointsInGeometr)){
vtkIntArray* aDataCellMapper = NULL;
VISU::TFieldListIterator anIter(this->FieldList);
for(anIter.Begin(); !anIter.End() ; anIter.Next()){
vtkCellData *aCellData = anIter.Get()->Ptr->GetCellData();
const char* aFieldName = anIter.Get()->GetName();
if(strcmp(aFieldName, "VISU_CELLS_MAPPER") == 0){
- vtkDataArray *aCellMapper = aCellData->GetArray(aFieldName);
- aDataCellMapper = dynamic_cast<vtkIntArray*>(aCellMapper);
+ vtkDataArray *aCellMapper_tmp = aCellData->GetArray(aFieldName);
+ aDataCellMapper = dynamic_cast<vtkIntArray*>(aCellMapper_tmp);
break;
}
}
return;
}
}
+ } else if (aGeometryCellMapper && (nbPointsInScalars < nbPointsInGeometr)) {
+
+ 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;
+ }
+ }
+ vtkIntArray* aDataCellMapper = NULL;
+ VISU::TFieldListIterator anIter2(this->FieldList);
+ for(anIter2.Begin(); !anIter2.End() ; anIter2.Next()){
+ vtkCellData *aCellData = anIter2.Get()->Ptr->GetCellData();
+ const char* aFieldName = anIter2.Get()->GetName();
+ if(strcmp(aFieldName, "VISU_CELLS_MAPPER") == 0){
+ vtkDataArray *aCellMapper_tmp = aInputScalarsPointData->GetArray(aFieldName);
+ aDataCellMapper = dynamic_cast<vtkIntArray*>(aCellMapper_tmp);
+ break;
+ }
+ }
+
+ bool anIsDifferent = aDataPointMapper &&
+ aDataPointMapper->GetNumberOfTuples() != aGeometryPointMapper->GetNumberOfTuples();
+ if(anIsDifferent){
+ TSortedArray aGeometryPointArray;
+ GetSortedArray(aGeometryPointMapper, aGeometryPointArray);
+
+ TSortedArray aDataPointArray;
+ GetSortedArray(aDataPointMapper, aDataPointArray);
+
+ int aMaxLength = std::max(aGeometryPointArray.size(), aDataPointArray.size());
+ TSortedArray anIntersectionArray(aMaxLength);
+ TSortedArray::iterator anArrayIter = anIntersectionArray.begin();
+ anArrayIter = std::set_intersection(aGeometryPointArray.begin(),
+ aGeometryPointArray.end(),
+ aDataPointArray.begin(),
+ aDataPointArray.end(),
+ anArrayIter);
+
+ anIntersectionArray.erase(anArrayIter, anIntersectionArray.end());
+
+ {
+ TId2IdMap anObj2VTKGeometryMap;
+ vtkIdType aNbCells = aDataPointMapper/*aGeometryPointMapper*/->GetNumberOfTuples();
+ for(int aCellId = 0; aCellId < aNbCells; aCellId++){
+ vtkIdType anObjID = aDataPointMapper/*aGeometryPointMapper*/->GetValue(aCellId);
+ anObj2VTKGeometryMap[anObjID] = aCellId;
+ }
+
+ vtkIdType aNbTuples = anIntersectionArray.size();
+
+ if ( aNbTuples == nbPointsInScalars ){
+ 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;
+ GetIdsForCopy(anInput,aDataPointMapper,aCellIdsForCopy);
+ nbCells = aCellIdsForCopy.size();
+
+ // 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,
+ anObj2VTKGeometryMap,
+ theOuputIDSArray,
+ anOutput);
+ theOuputIDSArray->Delete();
+ return;
+
+ } else {
+ // not implemented yet
+ }
+
+
+
+ }
+
+ }
}
anOutput->CopyStructure(anInput);
VISU_PrsMergerPL
::SetGeometry(VISU_PipeLine* theGeometry,bool theUpdate)
{
+ if(MYDEBUG) MESSAGE("VISU_PrsMergerPL::SetGeometry()");
myMeshGeometryList.clear();
+
if(this->checkGeometry(theGeometry)){
myMeshGeometryList.push_back(theGeometry);
if (MYDEBUG) MESSAGE("this->GetGeometry(0)->GetIDMapper()="<<this->GetGeometry(0)->GetIDMapper());
VISU_PrsMergerPL
::AddBackGeometry(VISU_PipeLine* theGeometry,bool theUpdate)
{
+ if(MYDEBUG) MESSAGE("VISU_PrsMergerPL::AddBackGeometry() "<<theGeometry);
if(theGeometry == NULL) return -1;
int aGeomNum = this->GetGeometryNumber(theGeometry);
if(aGeomNum == -1){
{
const VISU::PIDMapper& aMapper = thePipeLine->GetIDMapper();
int aNbPoints = aMapper->GetVTKOutput()->GetNumberOfPoints();
- if (this->GetNbGeometry() > 0){
- const VISU::PIDMapper& aMapper2 = this->GetGeometry(0)->GetIDMapper();
- int aNbPoints2 = aMapper2->GetVTKOutput()->GetNumberOfPoints();
- if(aNbPoints2 != aNbPoints)
- return false;
- } else if (this->GetScalars()) {
- const VISU::PIDMapper& aMapper2 = this->GetScalars()->GetIDMapper();
- int aNbPoints2 = aMapper2->GetVTKOutput()->GetNumberOfPoints();
- if(aNbPoints2 != aNbPoints)
- return false;
- }
+// if (this->GetNbGeometry() > 0){
+// const VISU::PIDMapper& aMapper2 = this->GetGeometry(0)->GetIDMapper();
+// int aNbPoints2 = aMapper2->GetVTKOutput()->GetNumberOfPoints();
+// if(aNbPoints2 != aNbPoints)
+// return false;
+// } else if (this->GetScalars()) {
+// const VISU::PIDMapper& aMapper2 = this->GetScalars()->GetIDMapper();
+// int aNbPoints2 = aMapper2->GetVTKOutput()->GetNumberOfPoints();
+// if(aNbPoints2 != aNbPoints)
+// return false;
+// }
+ if(aNbPoints < 1)
+ return false;
return true;
}
{
const VISU::PIDMapper& aMapper = thePipeLine->GetIDMapper();
int aNbPoints = aMapper->GetVTKOutput()->GetNumberOfPoints();
- if (this->GetNbGeometry() > 0){
- const VISU::PIDMapper& aMapper2 = this->GetGeometry(0)->GetIDMapper();
- int aNbPoints2 = aMapper2->GetVTKOutput()->GetNumberOfPoints();
- if(aNbPoints2 != aNbPoints)
- return false;
- }
+// if (this->GetNbGeometry() > 0){
+// const VISU::PIDMapper& aMapper2 = this->GetGeometry(0)->GetIDMapper();
+// int aNbPoints2 = aMapper2->GetVTKOutput()->GetNumberOfPoints();
+// if(aNbPoints2 != aNbPoints)
+// return false;
+// }
+ if(aNbPoints < 1)
+ return false;
return true;
}
const VISU::PIDMapper& aScalarsIDMapper = myScalars->GetIDMapper();
VISU::TVTKOutput* aScalarsOutput = aScalarsIDMapper->GetVTKOutput();
- // copy points to output from input scalar map
- myAppendFilter->SetSharedPointsDataSet(aScalarsOutput);
-
+ // copy points to output from input first geometry
+
+ VISU::TVTKOutput* aGeomOutput = NULL;
vtkIdType aNbGeoms = this->GetNbGeometry();
for(vtkIdType aGeomId = 0; aGeomId < aNbGeoms; aGeomId++){
VISU_PipeLine* aGeomPipeLine = this->GetGeometry(aGeomId);
const VISU::PIDMapper& aGeomIDMapper = aGeomPipeLine->GetIDMapper();
- VISU::TVTKOutput* aGeomOutput = aGeomIDMapper->GetVTKOutput();
+ aGeomOutput = aGeomIDMapper->GetVTKOutput();
vtkIdType aNbCells = aGeomOutput->GetNumberOfCells();
- if(aNbCells > 0)
- if(aGeomOutput->GetCell(0)->GetCellType() == VTK_VERTEX )
- continue;
+// if(aNbCells > 0)
+// if(aGeomOutput->GetCell(0)->GetCellType() == VTK_VERTEX )
+// continue;
myAppendFilter->AddInput(aGeomOutput);
}
+
+ myAppendFilter->SetSharedPointsDataSet(aGeomOutput);
myAppendFilter->Update();
+
vtkUnstructuredGrid* aGeomDataSet = myAppendFilter->GetOutput();
myMergeFilter->SetGeometry(aGeomDataSet);
myMergeFilter->RemoveFields();
myMergeFilter->AddField("VISU_FIELD", aScalarsOutput);
myMergeFilter->AddField("VISU_CELLS_MAPPER", aScalarsOutput);
+ myMergeFilter->AddField("VISU_POINTS_MAPPER", aScalarsOutput);
myMergeFilter->Update();
SetInput(myMergeFilter->GetOutput());