From: apo Date: Wed, 28 Mar 2007 06:00:25 +0000 (+0000) Subject: In context of fix for Bug NPAL15278 - "EDF 347 : ScalarMaponDeformedShape" X-Git-Tag: V3_2_6pre3~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=911c3924cac943967f2144e23ea2b02ad32accfc;p=modules%2Fvisu.git In context of fix for Bug NPAL15278 - "EDF 347 : ScalarMaponDeformedShape" VTK PointData need to be processed in a usual way, because the same points are shared among all VTK data sets belonged to the given MED file --- diff --git a/src/CONVERTOR/VISU_MergeFilter.cxx b/src/CONVERTOR/VISU_MergeFilter.cxx index b294411a..3ede1c4d 100644 --- a/src/CONVERTOR/VISU_MergeFilter.cxx +++ b/src/CONVERTOR/VISU_MergeFilter.cxx @@ -244,7 +244,8 @@ namespace inline void - GetSortedArray(vtkIntArray *theArray, TSortedArray& theSortedArray) + GetSortedArray(vtkIntArray *theArray, + TSortedArray& theSortedArray) { int aMaxId = theArray->GetMaxId(); int* aPointer = theArray->GetPointer(0); @@ -257,7 +258,8 @@ namespace typedef std::map TId2IdMap; template - void DeepCopyArrayOfDifferentType(IT *theInputPtr, OT *theOutputPtr, + void DeepCopyArrayOfDifferentType(IT *theInputPtr, + OT *theOutputPtr, const TSortedArray& theIntersection, const TId2IdMap& theObj2VTKMap, vtkIdType theNbComp) @@ -274,7 +276,8 @@ namespace } template - void DeepCopySwitchOnOutput(IT *theInputPtr, vtkDataArray *theDataArray, + void DeepCopySwitchOnOutput(IT *theInputPtr, + vtkDataArray *theDataArray, const TSortedArray& theIntersection, const TId2IdMap& theObj2VTKMap, vtkIdType theNbComp) @@ -292,10 +295,39 @@ namespace typedef vtkDataArray* (vtkDataSetAttributes::* TGetAttribute)(); typedef int (vtkDataSetAttributes::* TSetAttribute)(vtkDataArray*); + inline + void + CopyArray(vtkDataArray* theDataArray, + vtkDataSetAttributes* theOutput, + TSetAttribute theSetAttribute, + vtkIdType theFixedNbTuples) + { + if(theDataArray){ + vtkIdType aNbTuples = theDataArray->GetNumberOfTuples(); + if(theFixedNbTuples == aNbTuples) + (theOutput->*theSetAttribute)(theDataArray); + } + } + + inline + void + CopyAttribute(vtkDataSetAttributes* theInput, + TGetAttribute theGetAttribute, + vtkDataSetAttributes* theOutput, + TSetAttribute theSetAttribute, + vtkIdType theFixedNbTuples) + { + CopyArray((theInput->*theGetAttribute)(), + theOutput, theSetAttribute, + theFixedNbTuples); + } + void DeepCopyArray(vtkDataArray* theDataArray, - vtkDataSetAttributes* theOutput, TSetAttribute theSetAttribute, - const TSortedArray& theIntersection, const TId2IdMap& theObj2VTKMap) + vtkDataSetAttributes* theOutput, + TSetAttribute theSetAttribute, + const TSortedArray& theIntersection, + const TId2IdMap& theObj2VTKMap) { if(theDataArray){ vtkIdType aNbTuples = theDataArray->GetNumberOfTuples(); @@ -320,85 +352,143 @@ namespace } void - DeepCopyAttribute(vtkDataSetAttributes* theInput, TGetAttribute theGetAttribute, - vtkDataSetAttributes* theOutput, TSetAttribute theSetAttribute, - const TSortedArray& theIntersection, const TId2IdMap& theObj2VTKMap) + DeepCopyAttribute(vtkDataSetAttributes* theInput, + TGetAttribute theGetAttribute, + vtkDataSetAttributes* theOutput, + TSetAttribute theSetAttribute, + const TSortedArray& theIntersection, + const TId2IdMap& theObj2VTKMap) { DeepCopyArray((theInput->*theGetAttribute)(), - theOutput, theSetAttribute, - theIntersection, theObj2VTKMap); + theOutput, + theSetAttribute, + theIntersection, + theObj2VTKMap); } inline void - DeepCopyDataSetAttribute(vtkDataSet* theInput, TGetAttribute theGetAttribute, - vtkDataSet* theOutput, TSetAttribute theSetAttribute, - const TSortedArray& theIntersection, const TId2IdMap& theObj2VTKMap) + DeepCopyDataSetAttribute(vtkDataSet* theInput, + TGetAttribute theGetAttribute, + vtkDataSet* theOutput, + TSetAttribute theSetAttribute, + const TSortedArray& theIntersection, + const TId2IdMap& theObj2VTKMap) { - DeepCopyAttribute(theInput->GetPointData(), theGetAttribute, - theOutput->GetPointData(), theSetAttribute, - theIntersection, theObj2VTKMap); - DeepCopyAttribute(theInput->GetCellData(), theGetAttribute, - theOutput->GetCellData(), theSetAttribute, - theIntersection, theObj2VTKMap); + CopyAttribute(theInput->GetPointData(), + theGetAttribute, + theOutput->GetPointData(), + theSetAttribute, + theInput->GetNumberOfPoints()); + DeepCopyAttribute(theInput->GetCellData(), + theGetAttribute, + theOutput->GetCellData(), + theSetAttribute, + theIntersection, + theObj2VTKMap); } + inline void - DeepCopyField(vtkDataSetAttributes* theInput, const char* theFieldName, vtkDataSetAttributes* theOutput, - const TSortedArray& theIntersection, const TId2IdMap& theObj2VTKMap) + DeepCopyField(vtkDataSetAttributes* theInput, + const char* theFieldName, + vtkDataSetAttributes* theOutput, + const TSortedArray& theIntersection, + const TId2IdMap& theObj2VTKMap) { - DeepCopyArray(theInput->GetArray(theFieldName), theOutput, &vtkDataSetAttributes::AddArray, - theIntersection, theObj2VTKMap); + DeepCopyArray(theInput->GetArray(theFieldName), + theOutput, + &vtkDataSetAttributes::AddArray, + theIntersection, + theObj2VTKMap); } inline void - DeepCopyDataSetField(vtkDataSet* theInput, const char* theFieldName, vtkDataSet* theOutput, - const TSortedArray& theIntersection, const TId2IdMap& theObj2VTKMap) + CopyField(vtkDataSetAttributes* theInput, + const char* theFieldName, + vtkDataSetAttributes* theOutput, + vtkIdType theFixedNbTuples) { - DeepCopyField(theInput->GetPointData(), theFieldName, theOutput->GetPointData(), - theIntersection, theObj2VTKMap); - DeepCopyField(theInput->GetCellData(), theFieldName, theOutput->GetCellData(), + CopyArray(theInput->GetArray(theFieldName), + theOutput, + &vtkDataSetAttributes::AddArray, + theFixedNbTuples); + } + + inline + void + DeepCopyDataSetField(vtkDataSet* theInput, + const char* theFieldName, + vtkDataSet* theOutput, + const TSortedArray& theIntersection, + const TId2IdMap& theObj2VTKMap) + { + CopyField(theInput->GetPointData(), theFieldName, + theOutput->GetPointData(), + theInput->GetNumberOfPoints()); + DeepCopyField(theInput->GetCellData(), theFieldName, + theOutput->GetCellData(), theIntersection, theObj2VTKMap); } inline void DeepCopyDataSetAttributes(VISU_MergeFilter *theFilter, - vtkDataSet *theFilterOutput, VISU::TFieldList* theFieldList, - const TSortedArray& theIntersection, const TId2IdMap& theObj2VTKMap) + vtkDataSet *theFilterOutput, + VISU::TFieldList* theFieldList, + const TSortedArray& theIntersection, + const TId2IdMap& theObj2VTKMap) { if(vtkDataSet* aDataSet = theFilter->GetScalars()) - DeepCopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetScalars, - theFilterOutput, &vtkDataSetAttributes::SetScalars, - theIntersection, theObj2VTKMap); + DeepCopyDataSetAttribute(aDataSet, + &vtkDataSetAttributes::GetScalars, + theFilterOutput, + &vtkDataSetAttributes::SetScalars, + theIntersection, + theObj2VTKMap); if(vtkDataSet* aDataSet = theFilter->GetVectors()) - DeepCopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetVectors, - theFilterOutput, &vtkDataSetAttributes::SetVectors, - theIntersection, theObj2VTKMap); + DeepCopyDataSetAttribute(aDataSet, + &vtkDataSetAttributes::GetVectors, + theFilterOutput, + &vtkDataSetAttributes::SetVectors, + theIntersection, + theObj2VTKMap); if(vtkDataSet* aDataSet = theFilter->GetNormals()) - DeepCopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetNormals, - theFilterOutput, &vtkDataSetAttributes::SetNormals, - theIntersection, theObj2VTKMap); + DeepCopyDataSetAttribute(aDataSet, + &vtkDataSetAttributes::GetNormals, + theFilterOutput, + &vtkDataSetAttributes::SetNormals, + theIntersection, + theObj2VTKMap); if(vtkDataSet* aDataSet = theFilter->GetTCoords()) - DeepCopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetTCoords, - theFilterOutput, &vtkDataSetAttributes::SetTCoords, - theIntersection, theObj2VTKMap); + DeepCopyDataSetAttribute(aDataSet, + &vtkDataSetAttributes::GetTCoords, + theFilterOutput, + &vtkDataSetAttributes::SetTCoords, + theIntersection, + theObj2VTKMap); if(vtkDataSet* aDataSet = theFilter->GetTensors()) - DeepCopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetTensors, - theFilterOutput, &vtkDataSetAttributes::SetTensors, - theIntersection, theObj2VTKMap); + DeepCopyDataSetAttribute(aDataSet, + &vtkDataSetAttributes::GetTensors, + theFilterOutput, + &vtkDataSetAttributes::SetTensors, + theIntersection, + theObj2VTKMap); VISU::TFieldListIterator anIter(theFieldList); for(anIter.Begin(); !anIter.End() ; anIter.Next()){ vtkDataSet *aDataSet = anIter.Get()->Ptr; const char* aFieldName = anIter.Get()->GetName(); - DeepCopyDataSetField(aDataSet, aFieldName, theFilterOutput, - theIntersection, theObj2VTKMap); + DeepCopyDataSetField(aDataSet, + aFieldName, + theFilterOutput, + theIntersection, + theObj2VTKMap); } } } @@ -411,10 +501,6 @@ void VISU_MergeFilter::Execute() vtkCellData *aCellData = anInput->GetCellData(); vtkDataArray *aCellMapper = aCellData->GetArray("VISU_CELLS_MAPPER"); if(vtkIntArray *aGeometryCellMapper = dynamic_cast(aCellMapper)){ - TSortedArray aGeometryCellArray; - GetSortedArray(aGeometryCellMapper, aGeometryCellArray); - //cout<FieldList); for(anIter.Begin(); !anIter.End() ; anIter.Next()){ @@ -426,7 +512,14 @@ void VISU_MergeFilter::Execute() break; } } - if(aDataCellMapper){ + + bool anIsDifferent = aDataCellMapper && + aDataCellMapper->GetNumberOfTuples() != aGeometryCellMapper->GetNumberOfTuples(); + if(anIsDifferent){ + TSortedArray aGeometryCellArray; + GetSortedArray(aGeometryCellMapper, aGeometryCellArray); + //cout<*theGetAttribute)()){ - vtkIdType aNbTuples = anAttribute->GetNumberOfTuples(); - if(theFixedNbTuples == aNbTuples) - (theOutput->*theSetAttribute)(anAttribute); - } + CopyAttribute(theInput->GetPointData(), + theGetAttribute, + theOutput->GetPointData(), + theSetAttribute, + theNbPoints); + CopyAttribute(theInput->GetCellData(), + theGetAttribute, + theOutput->GetCellData(), + theSetAttribute, + theNbCells); } inline void - CopyDataSetAttribute(vtkDataSet *theInput, TGetAttribute theGetAttribute, - vtkDataSet *theOutput, TSetAttribute theSetAttribute, - vtkIdType theNbPoints, vtkIdType theNbCells) + CopyDataSetField(vtkDataSet* theInput, + const char* theFieldName, + vtkDataSet* theOutput, + vtkIdType theNbPoints, + vtkIdType theNbCells) { - CopyAttribute(theInput->GetPointData(), theGetAttribute, - theOutput->GetPointData(), theSetAttribute, - theNbPoints); - CopyAttribute(theInput->GetCellData(), theGetAttribute, - theOutput->GetCellData(), theSetAttribute, - theNbCells); + CopyField(theInput->GetPointData(), theFieldName, + theOutput->GetPointData(), + theNbPoints); + CopyField(theInput->GetCellData(), theFieldName, + theOutput->GetCellData(), + theNbCells); } + } void VISU_MergeFilter::BasicExecute(vtkDataSet *output) { vtkIdType numPts, numCells; - vtkPointData *outputPD = output->GetPointData(); - vtkCellData *outputCD = output->GetCellData(); vtkDebugMacro(<<"Merging data!"); @@ -539,54 +641,53 @@ void VISU_MergeFilter::BasicExecute(vtkDataSet *output) // merge data only if it is consistent if(vtkDataSet* aDataSet = this->GetScalars()) - CopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetScalars, - output, &vtkDataSetAttributes::SetScalars, - numPts, numCells); + CopyDataSetAttribute(aDataSet, + &vtkDataSetAttributes::GetScalars, + output, + &vtkDataSetAttributes::SetScalars, + numPts, + numCells); if(vtkDataSet* aDataSet = this->GetVectors()) - CopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetVectors, - output, &vtkDataSetAttributes::SetVectors, - numPts, numCells); + CopyDataSetAttribute(aDataSet, + &vtkDataSetAttributes::GetVectors, + output, + &vtkDataSetAttributes::SetVectors, + numPts, + numCells); if(vtkDataSet* aDataSet = this->GetNormals()) - CopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetNormals, - output, &vtkDataSetAttributes::SetNormals, - numPts, numCells); + CopyDataSetAttribute(aDataSet, + &vtkDataSetAttributes::GetNormals, + output, + &vtkDataSetAttributes::SetNormals, + numPts, + numCells); if(vtkDataSet* aDataSet = this->GetTCoords()) - CopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetTCoords, - output, &vtkDataSetAttributes::SetTCoords, - numPts, numCells); + CopyDataSetAttribute(aDataSet, + &vtkDataSetAttributes::GetTCoords, + output, + &vtkDataSetAttributes::SetTCoords, + numPts, + numCells); if(vtkDataSet* aDataSet = this->GetTensors()) - CopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetTensors, - output, &vtkDataSetAttributes::SetTensors, - numPts, numCells); - - VISU::TFieldListIterator it(this->FieldList); - vtkDataArray* da; - const char* name; - vtkIdType num; - for(it.Begin(); !it.End() ; it.Next()) - { - vtkPointData *pd = it.Get()->Ptr->GetPointData(); - vtkCellData *cd = it.Get()->Ptr->GetCellData(); - name = it.Get()->GetName(); - if ( (da=pd->GetArray(name)) ) - { - num = da->GetNumberOfTuples(); - if (num == numPts) - { - outputPD->AddArray(da); - } - } - if ( (da=cd->GetArray(name)) ) - { - num = da->GetNumberOfTuples(); - if (num == numCells) // To fix a VTK bug - { - outputCD->AddArray(da); - } - } - } + CopyDataSetAttribute(aDataSet, + &vtkDataSetAttributes::GetTensors, + output, + &vtkDataSetAttributes::SetTensors, + numPts, + numCells); + + VISU::TFieldListIterator anIter(this->FieldList); + for(anIter.Begin(); !anIter.End() ; anIter.Next()){ + vtkDataSet *aDataSet = anIter.Get()->Ptr; + const char* aFieldName = anIter.Get()->GetName(); + CopyDataSetField(aDataSet, + aFieldName, + output, + numPts, + numCells); + } }