From: enk Date: Wed, 11 Apr 2007 14:36:04 +0000 (+0000) Subject: Fix for Bug NPAL14169: X-Git-Tag: V3_2_6pre4~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=26b2db29dfa08de79368f049d897191443f80e2e;p=modules%2Fvisu.git Fix for Bug NPAL14169: EDF VISU 256 : No continuum on a scalarmap The adapted for scalar map on group --- diff --git a/src/CONVERTOR/VISU_MergeFilter.cxx b/src/CONVERTOR/VISU_MergeFilter.cxx index cd324302..ec2d61f3 100644 --- a/src/CONVERTOR/VISU_MergeFilter.cxx +++ b/src/CONVERTOR/VISU_MergeFilter.cxx @@ -492,6 +492,87 @@ namespace 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;idCellGetCell(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(theInputUG->GetCellData()->GetArray("VISU_CELLS_MAPPER")); + + int* aInputCellsMapperPointer = aInputCellsMapper->GetPointer(0); + + for(int aCellIndex=0;aCellIndexGetCell(aCellId)->GetPointIds(); + vtkIdList* aNewPointIds = vtkIdList::New(); + int nbPointIds = aOldPointIds->GetNumberOfIds(); + aNewPointIds->SetNumberOfIds(nbPointIds); + for(int j=0;jGetId(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 @@ -518,17 +599,25 @@ void VISU_MergeFilter::Execute() 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(aPointMapper); vtkDataArray *aCellMapper = aCellData->GetArray("VISU_CELLS_MAPPER"); - if(vtkIntArray *aGeometryCellMapper = dynamic_cast(aCellMapper)){ + vtkIntArray *aGeometryCellMapper = dynamic_cast(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(aCellMapper); + vtkDataArray *aCellMapper_tmp = aCellData->GetArray(aFieldName); + aDataCellMapper = dynamic_cast(aCellMapper_tmp); break; } } @@ -599,6 +688,100 @@ void VISU_MergeFilter::Execute() 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(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(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(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); diff --git a/src/PIPELINE/VISU_PrsMergerPL.cxx b/src/PIPELINE/VISU_PrsMergerPL.cxx index f9d21555..61aa4fcd 100644 --- a/src/PIPELINE/VISU_PrsMergerPL.cxx +++ b/src/PIPELINE/VISU_PrsMergerPL.cxx @@ -114,7 +114,9 @@ bool 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()="<GetGeometry(0)->GetIDMapper()); @@ -132,6 +134,7 @@ int VISU_PrsMergerPL ::AddBackGeometry(VISU_PipeLine* theGeometry,bool theUpdate) { + if(MYDEBUG) MESSAGE("VISU_PrsMergerPL::AddBackGeometry() "<GetGeometryNumber(theGeometry); if(aGeomNum == -1){ @@ -261,17 +264,19 @@ VISU_PrsMergerPL { 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; } @@ -281,12 +286,14 @@ VISU_PrsMergerPL { 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; } @@ -309,22 +316,25 @@ VISU_PrsMergerPL 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); @@ -335,6 +345,7 @@ VISU_PrsMergerPL myMergeFilter->RemoveFields(); myMergeFilter->AddField("VISU_FIELD", aScalarsOutput); myMergeFilter->AddField("VISU_CELLS_MAPPER", aScalarsOutput); + myMergeFilter->AddField("VISU_POINTS_MAPPER", aScalarsOutput); myMergeFilter->Update(); SetInput(myMergeFilter->GetOutput());