From: apo Date: Tue, 27 Mar 2007 14:19:01 +0000 (+0000) Subject: To fix Bug NPAL15278 - "EDF 347 : ScalarMaponDeformedShape" X-Git-Tag: V3_2_6pre3~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2b2ccadfdfe9ff107de3e2c2b79957e608944caa;p=modules%2Fvisu.git To fix Bug NPAL15278 - "EDF 347 : ScalarMaponDeformedShape" --- diff --git a/src/CONVERTOR/VISU_ConvertorUtils.cxx b/src/CONVERTOR/VISU_ConvertorUtils.cxx index f406e557..a926628f 100644 --- a/src/CONVERTOR/VISU_ConvertorUtils.cxx +++ b/src/CONVERTOR/VISU_ConvertorUtils.cxx @@ -28,6 +28,9 @@ #include #include +#include +#include +#include #ifdef _DEBUG_ static int MYDEBUG = 0; @@ -50,6 +53,26 @@ namespace VISU } + bool + IsDataOnPoints(vtkDataSet* theDataSet) + { + theDataSet->Update(); + if(theDataSet->GetPointData()->GetArray("VISU_POINTS_MAPPER")) + return theDataSet->GetPointData()->GetNumberOfArrays() > 1; + return theDataSet->GetPointData()->GetNumberOfArrays() > 0; + } + + + bool + IsDataOnCells(vtkDataSet* theDataSet) + { + theDataSet->Update(); + if(theDataSet->GetCellData()->GetArray("VISU_CELLS_MAPPER")) + return theDataSet->GetCellData()->GetNumberOfArrays() > 1; + return theDataSet->GetCellData()->GetNumberOfArrays() > 0; + } + + TTimerLog ::TTimerLog(int theIsDebug, const std::string& theName): diff --git a/src/CONVERTOR/VISU_ConvertorUtils.hxx b/src/CONVERTOR/VISU_ConvertorUtils.hxx index c44d5c43..2a86f810 100644 --- a/src/CONVERTOR/VISU_ConvertorUtils.hxx +++ b/src/CONVERTOR/VISU_ConvertorUtils.hxx @@ -35,17 +35,25 @@ class vtkUnstructuredGrid; class vtkTimerLog; +class vtkDataSet; namespace MED { class PrefixPrinter; } -namespace VISU{ +namespace VISU +{ void WriteToFile(vtkUnstructuredGrid* theDataSet, const std::string& theFileName); + bool + IsDataOnCells(vtkDataSet* theDataSet); + + bool + IsDataOnPoints(vtkDataSet* theDataSet); + class TTimerLog { int myIsDebug; diff --git a/src/CONVERTOR/VISU_Convertor_impl.cxx b/src/CONVERTOR/VISU_Convertor_impl.cxx index d3f33022..242e03f3 100644 --- a/src/CONVERTOR/VISU_Convertor_impl.cxx +++ b/src/CONVERTOR/VISU_Convertor_impl.cxx @@ -149,7 +149,7 @@ namespace VISU ::GetVTKOutput() { GetFilter()->Update(); - return GetFilter()->GetUnstructuredGridOutput(); + return GetFilter()->GetOutput(); } @@ -411,8 +411,10 @@ namespace VISU aFilter->SetScalars(aDataSet); aFilter->SetVectors(aDataSet); aFilter->AddField("VISU_FIELD",aDataSet); + aFilter->AddField("VISU_CELLS_MAPPER",aDataSet); + aFilter->AddField("VISU_POINTS_MAPPER",aDataSet); } - return myFilter->GetUnstructuredGridOutput(); + return myFilter->GetOutput(); } vtkIdType @@ -1209,6 +1211,20 @@ namespace aCellTypesArray->SetValue(anID,(unsigned char)theGeom); } + { + int aNbTuples = aNbCells; + vtkIntArray *aDataArray = vtkIntArray::New(); + aDataArray->SetName("VISU_CELLS_MAPPER"); + aDataArray->SetNumberOfComponents(1); + aDataArray->SetNumberOfTuples(aNbTuples); + for(int aTupleId = 0; aTupleId < aNbTuples; aTupleId++){ + int anObjID = theSubMesh->GetElemObjID(aTupleId); + aDataArray->SetValue(aTupleId, anObjID); + } + theSource->GetCellData()->AddArray(aDataArray); + aDataArray->Delete(); + } + vtkIdType *pts = 0, npts = 0; VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New(); aCellLocationsArray->SetNumberOfComponents(1); @@ -1321,6 +1337,38 @@ namespace { int aNbTuples = theField->myDataSize/theField->myNbComp; std::string aFieldName = GenerateFieldName(theField,theValForTime); + + { + PIDMapperFilter anIDMapperFilter = theValForTime->myIDMapperFilter; + VISU::TVTKOutput* anOutput = anIDMapperFilter->GetVTKOutput(); + anOutput->Update(); + { + int aNbTuples = anOutput->GetNumberOfCells(); + vtkIntArray *aDataArray = vtkIntArray::New(); + aDataArray->SetName("VISU_CELLS_MAPPER"); + aDataArray->SetNumberOfComponents(1); + aDataArray->SetNumberOfTuples(aNbTuples); + for(int aTupleId = 0; aTupleId < aNbTuples; aTupleId++){ + int anObjID = anIDMapperFilter->GetElemObjID(aTupleId); + aDataArray->SetValue(aTupleId, anObjID); + } + theSource->GetCellData()->AddArray(aDataArray); + aDataArray->Delete(); + } + { + int aNbTuples = anOutput->GetNumberOfPoints(); + vtkIntArray *aDataArray = vtkIntArray::New(); + aDataArray->SetName("VISU_POINTS_MAPPER"); + aDataArray->SetNumberOfComponents(1); + aDataArray->SetNumberOfTuples(aNbTuples); + for(int aTupleId = 0; aTupleId < aNbTuples; aTupleId++){ + int anObjID = anIDMapperFilter->GetNodeObjID(aTupleId); + aDataArray->SetValue(aTupleId, anObjID); + } + theSource->GetPointData()->AddArray(aDataArray); + aDataArray->Delete(); + } + } vtkDataSetAttributes* aDataSetAttributes; switch(theEntity){ @@ -1456,6 +1504,20 @@ namespace aCellLocationsArray->SetValue(i,aConnectivity->GetTraversalLocation(npts)); theSource->SetCells(aCellTypesArray,aCellLocationsArray,aConnectivity); + { + int aNbTuples = aNbCells; + vtkIntArray *aDataArray = vtkIntArray::New(); + aDataArray->SetName("VISU_CELLS_MAPPER"); + aDataArray->SetNumberOfComponents(1); + aDataArray->SetNumberOfTuples(aNbTuples); + for(int aTupleId = 0; aTupleId < aNbTuples; aTupleId++){ + int anObjID = theSubProfile->GetElemObjID(aTupleId); + aDataArray->SetValue(aTupleId, anObjID); + } + theSource->GetCellData()->AddArray(aDataArray); + aDataArray->Delete(); + } + aCellLocationsArray->Delete(); aCellTypesArray->Delete(); aConnectivity->Delete(); @@ -1899,7 +1961,7 @@ VISU_Convertor_impl //ENK: 23.11.2006 const TVTKSource& aSource = aSubMesh->GetSource(); aSource->SetPoints(GetPoints(aMesh)); - GetCellsOnSubMesh(aSource,aMeshOnEntity,aSubMesh,aVGeom); + GetCellsOnSubMesh(aSource, aMeshOnEntity, aSubMesh, aVGeom); anAppendFilter->AddInput(aSource.GetPointer()); aSubMesh->myStartID = aCellID; diff --git a/src/CONVERTOR/VISU_MergeFilter.cxx b/src/CONVERTOR/VISU_MergeFilter.cxx index 4cabc7fb..b294411a 100644 --- a/src/CONVERTOR/VISU_MergeFilter.cxx +++ b/src/CONVERTOR/VISU_MergeFilter.cxx @@ -37,6 +37,13 @@ #include #include +#include +#include + +#include +#include +#include + namespace VISU { @@ -231,163 +238,330 @@ void VISU_MergeFilter::AddField(const char* name, vtkDataSet* input) this->FieldList->Add(name, input); } -void VISU_MergeFilter::Execute() +namespace { - vtkIdType numPts, numScalars=0, numVectors=0, numNormals=0, numTCoords=0; - vtkIdType numTensors=0; - vtkIdType numCells, numCellScalars=0, numCellVectors=0, numCellNormals=0; - vtkIdType numCellTCoords=0, numCellTensors=0; - vtkPointData *pd; - vtkDataArray *scalars = NULL; - vtkDataArray *vectors = NULL; - vtkDataArray *normals = NULL; - vtkDataArray *tcoords = NULL; - vtkDataArray *tensors = NULL; - vtkCellData *cd; - vtkDataArray *cellScalars = NULL; - vtkDataArray *cellVectors = NULL; - vtkDataArray *cellNormals = NULL; - vtkDataArray *cellTCoords = NULL; - vtkDataArray *cellTensors = NULL; - vtkDataSet *output = this->GetOutput(); - vtkPointData *outputPD = output->GetPointData(); - vtkCellData *outputCD = output->GetCellData(); - - vtkDebugMacro(<<"Merging data!"); + typedef std::vector TSortedArray; - // geometry needs to be copied - output->CopyStructure(this->GetInput()); - if ( (numPts = this->GetInput()->GetNumberOfPoints()) < 1 ) - { - vtkWarningMacro(<<"Nothing to merge!"); - } - numCells = this->GetInput()->GetNumberOfCells(); - - if ( this->GetScalars() ) - { - pd = this->GetScalars()->GetPointData(); - scalars = pd->GetScalars(); - if ( scalars != NULL ) - { - numScalars = scalars->GetNumberOfTuples(); - } - cd = this->GetScalars()->GetCellData(); - cellScalars = cd->GetScalars(); - if ( cellScalars != NULL ) - { - numCellScalars = cellScalars->GetNumberOfTuples(); - } - } + inline + void + GetSortedArray(vtkIntArray *theArray, TSortedArray& theSortedArray) + { + int aMaxId = theArray->GetMaxId(); + int* aPointer = theArray->GetPointer(0); + int* anEndPointer = theArray->GetPointer(aMaxId + 1); + TSortedArray aSortedArray(aPointer, anEndPointer); + std::sort(aSortedArray.begin(), aSortedArray.end()); + theSortedArray.swap(aSortedArray); + } - if ( this->GetVectors() ) - { - pd = this->GetVectors()->GetPointData(); - vectors = pd->GetVectors(); - if ( vectors != NULL ) - { - numVectors= vectors->GetNumberOfTuples(); - } - cd = this->GetVectors()->GetCellData(); - cellVectors = cd->GetVectors(); - if ( cellVectors != NULL ) - { - numCellVectors = cellVectors->GetNumberOfTuples(); - } - } + typedef std::map TId2IdMap; - if ( this->GetNormals() ) - { - pd = this->GetNormals()->GetPointData(); - normals = pd->GetNormals(); - if ( normals != NULL ) - { - numNormals= normals->GetNumberOfTuples(); - } - cd = this->GetNormals()->GetCellData(); - cellNormals = cd->GetNormals(); - if ( cellNormals != NULL ) - { - numCellNormals = cellNormals->GetNumberOfTuples(); + template + void DeepCopyArrayOfDifferentType(IT *theInputPtr, OT *theOutputPtr, + const TSortedArray& theIntersection, + const TId2IdMap& theObj2VTKMap, + vtkIdType theNbComp) + { + vtkIdType aNbIds = theIntersection.size(); + for(vtkIdType aTargetTupleId = 0; aTargetTupleId < aNbIds; aTargetTupleId++){ + vtkIdType anObjId = theIntersection[aTargetTupleId]; + TId2IdMap::const_iterator anIter = theObj2VTKMap.find(anObjId); + vtkIdType aSourceTupleId = anIter->second; + for(vtkIdType aComp = 0; aComp < theNbComp; aComp++) + theOutputPtr[aTargetTupleId*theNbComp + aComp] = + static_cast(theInputPtr[aSourceTupleId*theNbComp + aComp]); + } + } + + template + void DeepCopySwitchOnOutput(IT *theInputPtr, vtkDataArray *theDataArray, + const TSortedArray& theIntersection, + const TId2IdMap& theObj2VTKMap, + vtkIdType theNbComp) + { + void *anOutputPtr = theDataArray->GetVoidPointer(0); + switch(theDataArray->GetDataType()){ + vtkTemplateMacro5(DeepCopyArrayOfDifferentType, theInputPtr, (VTK_TT*)anOutputPtr, + theIntersection, theObj2VTKMap, + theNbComp); + default: + vtkGenericWarningMacro(<<"Unsupported data type!"); + } + } + + typedef vtkDataArray* (vtkDataSetAttributes::* TGetAttribute)(); + typedef int (vtkDataSetAttributes::* TSetAttribute)(vtkDataArray*); + + void + DeepCopyArray(vtkDataArray* theDataArray, + vtkDataSetAttributes* theOutput, TSetAttribute theSetAttribute, + const TSortedArray& theIntersection, const TId2IdMap& theObj2VTKMap) + { + if(theDataArray){ + vtkIdType aNbTuples = theDataArray->GetNumberOfTuples(); + vtkIdType aNbComp = theDataArray->GetNumberOfComponents(); + + vtkDataArray *aDataArray = vtkDataArray::CreateDataArray(theDataArray->GetDataType()); + aDataArray->SetNumberOfTuples(aNbTuples); + aDataArray->SetNumberOfComponents(aNbComp); + void *anInputPtr = theDataArray->GetVoidPointer(0); + + switch(theDataArray->GetDataType()){ + vtkTemplateMacro5(DeepCopySwitchOnOutput, (VTK_TT*)anInputPtr, aDataArray, + theIntersection, theObj2VTKMap, + aNbComp); + default: + vtkGenericWarningMacro(<<"Unsupported data type!"); } + + (theOutput->*theSetAttribute)(aDataArray); + aDataArray->Delete(); } + } - if ( this->GetTCoords() ) - { - pd = this->GetTCoords()->GetPointData(); - tcoords = pd->GetTCoords(); - if ( tcoords != NULL ) - { - numTCoords= tcoords->GetNumberOfTuples(); - } - cd = this->GetTCoords()->GetCellData(); - cellTCoords = cd->GetTCoords(); - if ( cellTCoords != NULL ) - { - numCellTCoords = cellTCoords->GetNumberOfTuples(); + void + DeepCopyAttribute(vtkDataSetAttributes* theInput, TGetAttribute theGetAttribute, + vtkDataSetAttributes* theOutput, TSetAttribute theSetAttribute, + const TSortedArray& theIntersection, const TId2IdMap& theObj2VTKMap) + { + DeepCopyArray((theInput->*theGetAttribute)(), + theOutput, theSetAttribute, + theIntersection, theObj2VTKMap); + } + + inline + void + 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); + } + + void + DeepCopyField(vtkDataSetAttributes* theInput, const char* theFieldName, vtkDataSetAttributes* theOutput, + const TSortedArray& theIntersection, const TId2IdMap& 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) + { + DeepCopyField(theInput->GetPointData(), theFieldName, theOutput->GetPointData(), + theIntersection, theObj2VTKMap); + 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) + { + if(vtkDataSet* aDataSet = theFilter->GetScalars()) + DeepCopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetScalars, + theFilterOutput, &vtkDataSetAttributes::SetScalars, + theIntersection, theObj2VTKMap); + + if(vtkDataSet* aDataSet = theFilter->GetVectors()) + DeepCopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetVectors, + theFilterOutput, &vtkDataSetAttributes::SetVectors, + theIntersection, theObj2VTKMap); + + if(vtkDataSet* aDataSet = theFilter->GetNormals()) + DeepCopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetNormals, + theFilterOutput, &vtkDataSetAttributes::SetNormals, + theIntersection, theObj2VTKMap); + + if(vtkDataSet* aDataSet = theFilter->GetTCoords()) + DeepCopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetTCoords, + theFilterOutput, &vtkDataSetAttributes::SetTCoords, + theIntersection, theObj2VTKMap); + + if(vtkDataSet* aDataSet = theFilter->GetTensors()) + 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); + } + } +} + +void VISU_MergeFilter::Execute() +{ + vtkUnstructuredGrid *anInput = this->GetInput(); + vtkUnstructuredGrid *anOutput = this->GetOutput(); + + 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()){ + 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); + break; } } + if(aDataCellMapper){ + TSortedArray aDataCellArray; + GetSortedArray(aDataCellMapper, aDataCellArray); + //cout<GetTensors() ) - { - pd = this->GetTensors()->GetPointData(); - tensors = pd->GetTensors(); - if ( tensors != NULL ) - { - numTensors = tensors->GetNumberOfTuples(); - } - cd = this->GetTensors()->GetCellData(); - cellTensors = cd->GetTensors(); - if ( cellTensors != NULL ) - { - numCellTensors = cellTensors->GetNumberOfTuples(); + bool anIsCompletelyCoincide = + anIntersectionArray.size() == aGeometryCellArray.size() && + anIntersectionArray.size() == aDataCellArray.size(); + + if(!anIsCompletelyCoincide){ + { + TId2IdMap anObj2VTKGeometryMap; + vtkIdType aNbCells = aGeometryCellMapper->GetNumberOfTuples(); + for(int aCellId = 0; aCellId < aNbCells; aCellId++){ + vtkIdType anObjID = aGeometryCellMapper->GetValue(aCellId); + anObj2VTKGeometryMap[anObjID] = aCellId; + } + + vtkIdType aNbTuples = anIntersectionArray.size(); + anOutput->Allocate(aNbTuples); + vtkIdList *aCellIds = vtkIdList::New(); + for(int aTupleId = 0; aTupleId < aNbTuples; aTupleId++){ + vtkIdType anObjID = anIntersectionArray[aTupleId]; + vtkIdType aCellId = anObj2VTKGeometryMap[anObjID]; + vtkCell *aCell = anInput->GetCell(aCellId); + aCellIds->Reset(); + vtkIdType aNbPointIds = aCell->PointIds->GetNumberOfIds(); + for(vtkIdType aPointId = 0; aPointId < aNbPointIds; aPointId++) + aCellIds->InsertNextId(aCell->GetPointIds()->GetId(aPointId)); + anOutput->InsertNextCell(anInput->GetCellType(aCellId), aCellIds); + } + aCellIds->Delete(); + anOutput->SetPoints(anInput->GetPoints()); + } + { + TId2IdMap anObj2VTKDataMap; + vtkIdType aNbCells = aDataCellMapper->GetNumberOfTuples(); + for(int aCellId = 0; aCellId < aNbCells; aCellId++){ + vtkIdType anObjID = aDataCellMapper->GetValue(aCellId); + anObj2VTKDataMap[anObjID] = aCellId; + } + + DeepCopyDataSetAttributes(this, anOutput, this->FieldList, + anIntersectionArray, anObj2VTKDataMap); + } + return; } } + } - // merge data only if it is consistent - if ( numPts == numScalars ) - { - outputPD->SetScalars(scalars); - } - if ( numCells == numCellScalars ) - { - outputCD->SetScalars(cellScalars); - } + anOutput->CopyStructure(anInput); + this->BasicExecute(anOutput); +} - if ( numPts == numVectors ) - { - outputPD->SetVectors(vectors); - } - if ( numCells == numCellVectors ) - { - outputCD->SetVectors(cellVectors); - } - - if ( numPts == numNormals ) - { - outputPD->SetNormals(normals); - } - if ( numCells == numCellNormals ) - { - outputCD->SetNormals(cellNormals); +namespace +{ + inline + void + CopyAttribute(vtkDataSetAttributes* theInput, TGetAttribute theGetAttribute, + vtkDataSetAttributes* theOutput, TSetAttribute theSetAttribute, + vtkIdType theFixedNbTuples) + { + if(vtkDataArray *anAttribute = (theInput->*theGetAttribute)()){ + vtkIdType aNbTuples = anAttribute->GetNumberOfTuples(); + if(theFixedNbTuples == aNbTuples) + (theOutput->*theSetAttribute)(anAttribute); } + } - if ( numPts == numTCoords ) - { - outputPD->SetTCoords(tcoords); - } - if ( numCells == numCellTCoords ) - { - outputCD->SetTCoords(cellTCoords); - } + inline + void + CopyDataSetAttribute(vtkDataSet *theInput, TGetAttribute theGetAttribute, + vtkDataSet *theOutput, TSetAttribute theSetAttribute, + vtkIdType theNbPoints, vtkIdType theNbCells) + { + CopyAttribute(theInput->GetPointData(), theGetAttribute, + theOutput->GetPointData(), theSetAttribute, + theNbPoints); + CopyAttribute(theInput->GetCellData(), theGetAttribute, + theOutput->GetCellData(), theSetAttribute, + theNbCells); + } +} - if ( numPts == numTensors ) - { - outputPD->SetTensors(tensors); - } - if ( numCells == numCellTensors ) +void VISU_MergeFilter::BasicExecute(vtkDataSet *output) +{ + vtkIdType numPts, numCells; + vtkPointData *outputPD = output->GetPointData(); + vtkCellData *outputCD = output->GetCellData(); + + vtkDebugMacro(<<"Merging data!"); + + if ( (numPts = output->GetNumberOfPoints()) < 1 ) { - outputCD->SetTensors(cellTensors); + vtkWarningMacro(<<"Nothing to merge!"); } + numCells = output->GetNumberOfCells(); + + // merge data only if it is consistent + if(vtkDataSet* aDataSet = this->GetScalars()) + CopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetScalars, + output, &vtkDataSetAttributes::SetScalars, + numPts, numCells); + + if(vtkDataSet* aDataSet = this->GetVectors()) + CopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetVectors, + output, &vtkDataSetAttributes::SetVectors, + numPts, numCells); + + if(vtkDataSet* aDataSet = this->GetNormals()) + CopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetNormals, + output, &vtkDataSetAttributes::SetNormals, + numPts, numCells); + + if(vtkDataSet* aDataSet = this->GetTCoords()) + 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; @@ -395,8 +569,8 @@ void VISU_MergeFilter::Execute() vtkIdType num; for(it.Begin(); !it.End() ; it.Next()) { - pd = it.Get()->Ptr->GetPointData(); - cd = it.Get()->Ptr->GetCellData(); + vtkPointData *pd = it.Get()->Ptr->GetPointData(); + vtkCellData *cd = it.Get()->Ptr->GetCellData(); name = it.Get()->GetName(); if ( (da=pd->GetArray(name)) ) { diff --git a/src/CONVERTOR/VISU_MergeFilter.hxx b/src/CONVERTOR/VISU_MergeFilter.hxx index 29c4b701..21d583e1 100644 --- a/src/CONVERTOR/VISU_MergeFilter.hxx +++ b/src/CONVERTOR/VISU_MergeFilter.hxx @@ -29,7 +29,9 @@ #ifndef VISU_MergeFilter_H #define VISU_MergeFilter_H -#include +#include + +class vtkDataSet; namespace VISU { @@ -39,16 +41,16 @@ namespace VISU // Following class was redefined in order to fix VTK bug // (see code for more details) -class VISU_MergeFilter : public vtkDataSetToDataSetFilter +class VISU_MergeFilter : public vtkUnstructuredGridToUnstructuredGridFilter { public: static VISU_MergeFilter *New(); - vtkTypeMacro(VISU_MergeFilter,vtkDataSetToDataSetFilter); + vtkTypeMacro(VISU_MergeFilter,vtkUnstructuredGridToUnstructuredGridFilter); // Description: // Specify object from which to extract geometry information. - void SetGeometry(vtkDataSet *input) {this->SetInput(input);}; - vtkDataSet *GetGeometry() {return this->GetInput();}; + void SetGeometry(vtkUnstructuredGrid *input) {this->SetInput(input);}; + vtkUnstructuredGrid *GetGeometry() {return this->GetInput();}; // Description: // Specify object from which to extract scalar information. @@ -86,6 +88,7 @@ protected: ~VISU_MergeFilter(); // Usual data generation method + void BasicExecute(vtkDataSet *output); void Execute(); VISU::TFieldList* FieldList; diff --git a/src/PIPELINE/VISU_Extractor.cxx b/src/PIPELINE/VISU_Extractor.cxx index c33d071a..f8d0940d 100644 --- a/src/PIPELINE/VISU_Extractor.cxx +++ b/src/PIPELINE/VISU_Extractor.cxx @@ -25,6 +25,7 @@ #include "VISU_Extractor.hxx" #include "VISU_PipeLineUtils.hxx" +#include "VISU_ConvertorUtils.hxx" #include @@ -91,13 +92,14 @@ execute(int theNbElems, } } -void VISU_Extractor::Execute(){ +void VISU_Extractor::Execute() +{ vtkDataSet *input = this->GetInput(), *output = this->GetOutput(); output->CopyStructure(input); - output->GetPointData()->CopyAllOff(); - output->GetCellData()->CopyAllOff(); - if(input->GetPointData()->GetNumberOfArrays()){ + if(VISU::IsDataOnPoints(input)){ output->GetPointData()->CopyVectorsOn(); + output->GetPointData()->CopyScalarsOff(); + int aNbElems = input->GetNumberOfPoints(); vtkPointData *inData = input->GetPointData(), *outData = output->GetPointData(); if(!inData->GetAttribute(vtkDataSetAttributes::SCALARS)) @@ -108,6 +110,8 @@ void VISU_Extractor::Execute(){ outData->AddArray(inData->GetArray("VISU_FIELD")); }else{ output->GetCellData()->CopyVectorsOn(); + output->GetCellData()->CopyScalarsOff(); + int aNbElems = input->GetNumberOfCells(); vtkCellData *inData = input->GetCellData(), *outData = output->GetCellData(); if(inData->GetAttribute(vtkDataSetAttributes::VECTORS)) @@ -117,4 +121,10 @@ void VISU_Extractor::Execute(){ outData->PassData(inData); outData->AddArray(inData->GetArray("VISU_FIELD")); } + + if(vtkDataArray *aDataArray = input->GetCellData()->GetArray("VISU_CELLS_MAPPER")) + output->GetCellData()->AddArray(aDataArray); + + if(vtkDataArray *aDataArray = input->GetPointData()->GetArray("VISU_POINTS_MAPPER")) + output->GetPointData()->AddArray(aDataArray); } diff --git a/src/PIPELINE/VISU_FieldTransform.cxx b/src/PIPELINE/VISU_FieldTransform.cxx index 598a36e2..12a69310 100644 --- a/src/PIPELINE/VISU_FieldTransform.cxx +++ b/src/PIPELINE/VISU_FieldTransform.cxx @@ -237,19 +237,18 @@ VISU_FieldTransform vtkDataSet *input = this->GetInput(), *output = this->GetOutput(); output->CopyStructure(input); if(myFunction != &Ident || (myTransform && !myTransform->IsIdentity())){ - output->GetPointData()->CopyAllOff(); - output->GetCellData()->CopyAllOff(); + output->GetPointData()->CopyScalarsOff(); + output->GetPointData()->CopyVectorsOff(); + + output->GetCellData()->CopyScalarsOff(); + output->GetCellData()->CopyVectorsOff(); ExecScalars(myFunction,myScalarRange,input->GetNumberOfPoints(),input->GetPointData(),output->GetPointData()); ExecVectors(myFunction,myTransform,myScalarRange,input->GetNumberOfPoints(),input->GetPointData(),output->GetPointData()); ExecScalars(myFunction,myScalarRange,input->GetNumberOfCells(),input->GetCellData(),output->GetCellData()); ExecVectors(myFunction,myTransform,myScalarRange,input->GetNumberOfCells(),input->GetCellData(),output->GetCellData()); - }else{ - output->GetPointData()->CopyAllOn(); - output->GetCellData()->CopyAllOn(); - - output->GetPointData()->PassData(input->GetPointData()); - output->GetCellData()->PassData(input->GetCellData()); } + output->GetPointData()->PassData(input->GetPointData()); + output->GetCellData()->PassData(input->GetCellData()); } diff --git a/src/PIPELINE/VISU_PipeLineUtils.hxx b/src/PIPELINE/VISU_PipeLineUtils.hxx index 57e6347b..7b87e362 100644 --- a/src/PIPELINE/VISU_PipeLineUtils.hxx +++ b/src/PIPELINE/VISU_PipeLineUtils.hxx @@ -30,6 +30,7 @@ #include "VISU_FieldTransform.hxx" #include "VISU_LookupTable.hxx" #include "VISU_Extractor.hxx" +#include "VISU_ConvertorUtils.hxx" #include #include @@ -74,7 +75,7 @@ namespace VISU vtkDataSet* theDataSet, VISU_FieldTransform *theFieldTransform) { - if(theDataSet->GetCellData()->GetNumberOfArrays()){ + if(VISU::IsDataOnCells(theDataSet)){ theFilter->SetInput(theFieldTransform->GetUnstructuredGridOutput()); theFilter->PassCellDataOn(); theTItem->SetInput(theFilter->GetUnstructuredGridOutput()); @@ -89,7 +90,7 @@ namespace VISU vtkDataSet* theDataSet, VISU_FieldTransform *theFieldTransform) { - if(theDataSet->GetCellData()->GetNumberOfArrays()){ + if(VISU::IsDataOnCells(theDataSet)){ theFilter->SetInput(theFieldTransform->GetUnstructuredGridOutput()); theFilter->VertexCellsOn(); theTItem->SetInput(theFilter->GetOutput()); diff --git a/src/PIPELINE/VISU_Plot3DPL.cxx b/src/PIPELINE/VISU_Plot3DPL.cxx index e5de36c4..4d0ebf65 100644 --- a/src/PIPELINE/VISU_Plot3DPL.cxx +++ b/src/PIPELINE/VISU_Plot3DPL.cxx @@ -182,7 +182,7 @@ Update() } if ( !myIsContour ) // surface prs { - if(aPolyData->GetCellData()->GetNumberOfArrays()) { + if(VISU::IsDataOnCells(aPolyData)) { myCellDataToPointData->SetInput(aPolyData); myCellDataToPointData->PassCellDataOn(); myWarpScalar->SetInput(myCellDataToPointData->GetPolyDataOutput()); @@ -191,7 +191,7 @@ Update() } else // contour prs { - if(aPolyData->GetCellData()->GetNumberOfArrays()) { + if(VISU::IsDataOnCells(aPolyData)) { myCellDataToPointData->SetInput(aPolyData); myCellDataToPointData->PassCellDataOn(); myContourFilter->SetInput(myCellDataToPointData->GetOutput()); diff --git a/src/PIPELINE/VISU_ScalarMapOnDeformedShapePL.cxx b/src/PIPELINE/VISU_ScalarMapOnDeformedShapePL.cxx index 60c3bf5b..1a0e3e4b 100644 --- a/src/PIPELINE/VISU_ScalarMapOnDeformedShapePL.cxx +++ b/src/PIPELINE/VISU_ScalarMapOnDeformedShapePL.cxx @@ -26,17 +26,19 @@ #include "VISU_ScalarMapOnDeformedShapePL.hxx" #include "VISU_DeformedShapePL.hxx" +#include "VISU_MergeFilter.hxx" + #include "VISU_PipeLineUtils.hxx" #include "VTKViewer_TransformFilter.h" #include "VTKViewer_Transform.h" #include -#include #include #include #include -#include +#include "VISU_Convertor.hxx" +#include "VISU_ConvertorUtils.hxx" vtkStandardNewMacro(VISU_ScalarMapOnDeformedShapePL) @@ -52,7 +54,7 @@ VISU_ScalarMapOnDeformedShapePL ::VISU_ScalarMapOnDeformedShapePL() { myDeformVectors = vtkWarpVector::New(); - myMergeFilter = vtkMergeFilter::New(); + myMergeFilter = VISU_MergeFilter::New(); myExtractorScalars = VISU_Extractor::New(); myCellDataToPointData = vtkCellDataToPointData::New(); } @@ -119,8 +121,11 @@ VISU_ScalarMapOnDeformedShapePL GetInput2(),myFieldTransform); // Sets geometry for merge filter - myMergeFilter->SetGeometry(myDeformVectors->GetOutput()); + myMergeFilter->SetGeometry(myDeformVectors->GetUnstructuredGridOutput()); myMergeFilter->SetScalars(myExtractorScalars->GetOutput()); + myMergeFilter->AddField("VISU_CELLS_MAPPER", myExtractorScalars->GetOutput()); + myMergeFilter->Update(); + // Sets data to mapper myMapper->SetInput(myMergeFilter->GetOutput()); } @@ -189,6 +194,8 @@ VISU_ScalarMapOnDeformedShapePL vtkUnstructuredGrid* aScalars = GetScalarsUnstructuredGrid(); vtkCellData *aInCellData = GetInput()->GetCellData(); + std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-SetScalars.vtk"; + VISU::WriteToFile(aScalars, aFileName); if(aScalars->GetPointData()->GetScalars()) myExtractorScalars->SetInput(aScalars); else if(aScalars->GetCellData()->GetScalars() && diff --git a/src/PIPELINE/VISU_ScalarMapOnDeformedShapePL.hxx b/src/PIPELINE/VISU_ScalarMapOnDeformedShapePL.hxx index 3f6750b5..6e731ab7 100644 --- a/src/PIPELINE/VISU_ScalarMapOnDeformedShapePL.hxx +++ b/src/PIPELINE/VISU_ScalarMapOnDeformedShapePL.hxx @@ -29,7 +29,7 @@ #include "VISU_PrsMergerPL.hxx" -class vtkMergeFilter; +class VISU_MergeFilter; class vtkWarpVector; class vtkUnstructuredGrid; class vtkCellDataToPointData; @@ -89,7 +89,7 @@ public: protected: vtkFloatingPointType myScaleFactor; vtkWarpVector *myDeformVectors; - vtkMergeFilter *myMergeFilter; + VISU_MergeFilter *myMergeFilter; vtkSmartPointer myScalars; VISU_Extractor* myExtractorScalars; vtkCellDataToPointData* myCellDataToPointData; diff --git a/src/PIPELINE/VISU_ScalarMapPL.cxx b/src/PIPELINE/VISU_ScalarMapPL.cxx index 0c6b9903..0fa68d13 100644 --- a/src/PIPELINE/VISU_ScalarMapPL.cxx +++ b/src/PIPELINE/VISU_ScalarMapPL.cxx @@ -95,10 +95,10 @@ void VISU_ScalarMapPL ::SetScalarMode(int theScalarMode) { - vtkDataSet *input = GetInput(); - if (input){ - if(input->GetPointData()->GetNumberOfArrays()){ - vtkPointData *inData = input->GetPointData(); + vtkDataSet *anInput = GetInput(); + if(anInput){ + if(VISU::IsDataOnPoints(anInput)){ + vtkPointData *inData = anInput->GetPointData(); if(!inData->GetAttribute(vtkDataSetAttributes::VECTORS)) { if (theScalarMode==0){ return; @@ -106,7 +106,7 @@ VISU_ScalarMapPL } } else { - vtkCellData *inData = input->GetCellData(); + vtkCellData *inData = anInput->GetCellData(); if(!inData->GetAttribute(vtkDataSetAttributes::VECTORS)){ if (theScalarMode==0){ return; diff --git a/src/PIPELINE/VISU_StreamLinesPL.cxx b/src/PIPELINE/VISU_StreamLinesPL.cxx index 6cae0bd7..c9cdc8ed 100644 --- a/src/PIPELINE/VISU_StreamLinesPL.cxx +++ b/src/PIPELINE/VISU_StreamLinesPL.cxx @@ -177,7 +177,7 @@ VISU_StreamLinesPL if((!isOnlyTry && isAccepted) || (isOnlyTry && isAccepted == 1)){ mySource = theSource; myPercents = thePercents; - if(GetInput2()->GetCellData()->GetNumberOfArrays()){ + if(VISU::IsDataOnCells(GetInput2())){ myCenters->SetInput(aDataSet); myCenters->VertexCellsOn(); aDataSet = myCenters->GetOutput();