From 234e123c1cd0e5800c265aca9d0525c49a34f2b6 Mon Sep 17 00:00:00 2001 From: enk Date: Fri, 10 Nov 2006 07:05:12 +0000 Subject: [PATCH] Fix for Bug IPAL13723: enk/PRSMERGER: white scalar map on groups. --- src/PIPELINE/VISU_Extractor.cxx | 2 +- src/PIPELINE/VISU_PrsMergerPL.cxx | 291 +++++++----------------------- 2 files changed, 62 insertions(+), 231 deletions(-) diff --git a/src/PIPELINE/VISU_Extractor.cxx b/src/PIPELINE/VISU_Extractor.cxx index 82eec5dc..c33d071a 100644 --- a/src/PIPELINE/VISU_Extractor.cxx +++ b/src/PIPELINE/VISU_Extractor.cxx @@ -100,7 +100,7 @@ void VISU_Extractor::Execute(){ output->GetPointData()->CopyVectorsOn(); int aNbElems = input->GetNumberOfPoints(); vtkPointData *inData = input->GetPointData(), *outData = output->GetPointData(); - if(inData->GetAttribute(vtkDataSetAttributes::VECTORS)) + if(!inData->GetAttribute(vtkDataSetAttributes::SCALARS)) execute(aNbElems,myScalarMode,inData,outData); else output->GetPointData()->CopyScalarsOn(); diff --git a/src/PIPELINE/VISU_PrsMergerPL.cxx b/src/PIPELINE/VISU_PrsMergerPL.cxx index def0ac48..229a7287 100644 --- a/src/PIPELINE/VISU_PrsMergerPL.cxx +++ b/src/PIPELINE/VISU_PrsMergerPL.cxx @@ -89,7 +89,7 @@ VISU_PrsMergerPL { VISU_PrsMergerPL* aPipeLine = dynamic_cast(thePipeLine); if(this == aPipeLine){ - Superclass::ShallowCopy(thePipeLine); + TSupperClass::ShallowCopy(thePipeLine); return; } if(aPipeLine){ @@ -101,7 +101,7 @@ VISU_PrsMergerPL } SetScalars(aPipeLine->GetScalars(),true); } - Superclass::ShallowCopy(thePipeLine); + TSupperClass::ShallowCopy(thePipeLine); } bool @@ -129,7 +129,8 @@ VISU_PrsMergerPL if(theGeometry == NULL) return -1; int aGeomNum = this->GetGeometryNumber(theGeometry); if(aGeomNum == -1){ - if(this->checkGeometry(theGeometry)){ + bool aCheckGeom = this->checkGeometry(theGeometry); + if(aCheckGeom){ myMeshGeometryList.push_back(theGeometry); if(theUpdate) @@ -301,260 +302,90 @@ VISU_PrsMergerPL if(myMeshGeometryList.size() != 0) { - - VISU_MergeFilter* aMergeFilter = VISU_MergeFilter::New(); - // Build mesh - typedef std::vector TVec; - - TVec aObjIds;// object ids from geometries - int anbGeoms; - int aGeomNbCells,aAllGeomNbCells,aScalarNbCells; - int aScalarNodeTuplesNum,aScalarCellTuplesNum,aScalarCellComponentNum; - VTKViewer_AppendFilter* aMergeGeoms = VTKViewer_AppendFilter::New(); - aAllGeomNbCells = 0; + typedef std::vector TVec; + vtkUnstructuredGrid* output = vtkUnstructuredGrid::New(); + TVec aObjIds; // vector with object ids + vtkFloatArray* newArray = vtkFloatArray::New(); + VISU_ScalarMapPL* aScalarMap = dynamic_cast(this->GetScalars()); const VISU::PIDMapper& aScalarMapper = myScalars->GetIDMapper(); - - anbGeoms = this->GetNbGeometry(); - - // aObjIds follows. + + // copy points to output from input scalar map + output->SetPoints(aScalarMapper->GetVTKOutput()->GetPoints()); + + int newCellId; + int anbGeoms = this->GetNbGeometry(); for(int i=0; i < anbGeoms; i++) { VISU_PipeLine* aCurrGeometry = this->GetGeometry(i); - if (aCurrGeometry) { - aCurrGeometry->Update(); - const VISU::PIDMapper& aGM = aCurrGeometry->GetIDMapper(); - int aNbCells = aGM->GetVTKOutput()->GetNumberOfCells(); - if(MYDEBUG) MESSAGE("Geom["<GetVTKOutput()->GetNumberOfPoints() << endl; - cout << "\tnumber of cells :" << aGeomMapper->GetVTKOutput()->GetNumberOfCells() << " cell type=" << aGeomMapper->GetVTKOutput()->GetCell(0)->GetCellType() << endl; - int aNbCells = aGeomNbCells; - for(int i=0; iGetElemObjID(i); - int aVTKID = aGeomMapper->GetElemVTKID(anObjID); - cout <<"\t\t" << anObjID << ";"<GetVTKOutput()->GetNumberOfCells(); - cout << "myScalars:" << endl; - cout << "\tnumber of points:" << aScalarMapper->GetVTKOutput()->GetNumberOfPoints() << endl; - cout << "\tnumber of cells :" << aNbCells << endl; - for(int i=0; iGetElemObjID(i); - int aVTKID = aScalarMapper->GetElemVTKID(anObjID); - cout <<"\t\t" << anObjID << ";"<GetIDMapper(); + int aNbCells = aGM->GetVTKOutput()->GetNumberOfCells(); + if (aNbCells >0 ) + if (aGM->GetVTKOutput()->GetCell(0)->GetCellType() == VTK_VERTEX ) + continue; - vtkCellData* aScalarMapCD = aScalarMapper->GetVTKOutput()->GetCellData(); - - vtkUnstructuredGrid* aDSScalars = vtkUnstructuredGrid::New(); - vtkUnstructuredGrid* aDSVectors = vtkUnstructuredGrid::New(); - vtkCellData* aCDScalars = aDSScalars->GetCellData(); - vtkCellData* aCDVectors = aDSVectors->GetCellData(); - vtkPointData* aPDScalars = aDSScalars->GetPointData(); - vtkPointData* aPDVectors = aDSVectors->GetPointData(); - vtkUnstructuredGrid* aDSArrays = vtkUnstructuredGrid::New(); - vtkFloatArray* aArrays = vtkFloatArray::New(); - vtkFloatArray *aVISU_FIELD_Array = NULL; - - // shallow copy of point data - if(aScalarMap != NULL){ - aPDScalars->ShallowCopy(aScalarMap->GetOutput()->GetPointData()); - aPDVectors->ShallowCopy(aScalarMap->GetOutput()->GetPointData()); - } + vtkIdList* ptIds = vtkIdList::New(); + ptIds->Allocate(VTK_CELL_SIZE); - aCDScalars->Initialize(); - aCDVectors->Initialize(); - - - /* - *copy arrays from point data - */ - vtkPointData* aPDInput = aScalarMapper->GetVTKOutput()->GetPointData(); - aDSArrays->GetPointData()->SetScalars(aPDInput->GetScalars()); - aDSArrays->GetPointData()->SetVectors(aPDInput->GetVectors()); - int anbPArr = aPDInput->GetNumberOfArrays(); - if(anbPArr>0){ - vtkDataArray* aFieldArray = aPDInput->GetArray("VISU_FIELD"); - if(vtkFloatArray* aArr = dynamic_cast(aFieldArray)) - aDSArrays->GetPointData()->AddArray(aArr); - } + for(int j=0; j < aNbCells; j++){ - /* - *copy array VISU_FIELD from cell data - */ - int anbArr = aScalarMapCD->GetNumberOfArrays(); - if(anbArr>0){ - vtkDataArray* aFieldArray = aScalarMapCD->GetArray("VISU_FIELD"); - if(aVISU_FIELD_Array = dynamic_cast(aFieldArray)){ - if(MYDEBUG) MESSAGE("Copy VISU_FIELD ........."); - int aNbComp = aVISU_FIELD_Array->GetNumberOfComponents(); - int nbTuple = aVISU_FIELD_Array->GetNumberOfTuples(); - aArrays->SetName(aVISU_FIELD_Array->GetName()); - aArrays->SetNumberOfComponents(aNbComp); - aArrays->SetNumberOfTuples(aAllGeomNbCells); - - TVec::const_iterator aIdsIter = aObjIds.begin(); - for(int i=0; aIdsIter != aObjIds.end(); aIdsIter++){ - int anObjID = *aIdsIter; - int aVTKID = aScalarMapper->GetElemVTKID(anObjID); - float* aTuple = aVISU_FIELD_Array->GetTuple(aVTKID); - if(MYDEBUG){ - cout <<"\t\t" << anObjID << ";"<SetTuple(i,aTuple); - i++; - } - aDSArrays->GetCellData()->AddArray(aArrays); - if(MYDEBUG) MESSAGE("Copy VISU_FIELD .........done"); + int anObjID = aGM->GetElemObjID(j); + aObjIds.push_back(anObjID); + + // copy cells to output from input geoms + aGM->GetVTKOutput()->GetCellPoints(j, ptIds); + newCellId = output->InsertNextCell(aGM->GetVTKOutput()->GetCellType(j),ptIds); } - } - + ptIds->Delete(); + } + - /* - *copy scalars from cell data - */ - aScalarCellTuplesNum = 0; - int compNum = 0; - if(aScalarMapCD->GetScalars()){ - aScalarCellTuplesNum = aScalarMapCD->GetScalars()->GetNumberOfTuples(); - compNum = aScalarMapCD->GetScalars()->GetNumberOfComponents(); + //copy array values + vtkDataArray* da; + if((da = aScalarMapper->GetVTKOutput()->GetPointData()->GetArray("VISU_FIELD"))){ + output->GetPointData()->AddArray(da); + vtkDataArray* vc = aScalarMapper->GetVTKOutput()->GetPointData()->GetVectors(); + if(vc) + output->GetPointData()->SetVectors(vc); } - if (aScalarCellTuplesNum > 0) { - if(MYDEBUG) MESSAGE("Copy Scalars ........."); - if(MYDEBUG) MESSAGE("\taScalarCellTuplesNum="<GetElemVTKID(anObjID); - float* aTuple = aScalarMapCD->GetScalars()->GetTuple(aVTKID); - if(MYDEBUG){ - cout <<"\t\t" << anObjID << ";"<SetTuple(i,aTuple); - i++; + if((da = aScalarMapper->GetVTKOutput()->GetCellData()->GetArray("VISU_FIELD"))){ + if(MYDEBUG){ + MESSAGE("aScalarMapper NumberOfComponents="<GetNumberOfComponents()); + MESSAGE("aScalarMapper NumberOfTuples ="<GetNumberOfTuples()); } - aCDScalars->SetScalars(aNewScalars); - aCDScalars->AddArray(aArrays); - aNewScalars->Delete(); - if(MYDEBUG) MESSAGE("Copy Scalars .........Done"); - } - - /* - * copy vectors from cell data - */ - aScalarCellTuplesNum = 0; - if(aScalarMapCD->GetVectors()) { - aScalarCellTuplesNum = aScalarMapCD->GetVectors()->GetNumberOfTuples(); - compNum = aScalarMapCD->GetVectors()->GetNumberOfComponents(); - } - if (aScalarCellTuplesNum > 0) { - if(MYDEBUG) MESSAGE("Copy Vectors ........."); - if(MYDEBUG) MESSAGE("\taScalarCellTuplesNum="<GetElemVTKID(anObjID); - float* aTuple = aScalarMapCD->GetVectors()->GetTuple(aVTKID); - if(MYDEBUG){ - cout <<"\t\t" << anObjID << ";"<SetTuple(i,aTuple); + newArray->SetTuple(i,da->GetTuple(aVTKID)); i++; } - aCDVectors->SetVectors(aNewVectors); - aCDVectors->AddArray(aArrays); - aDSArrays->GetCellData()->AddArray(aArrays); - aNewVectors->Delete(); - if(MYDEBUG) MESSAGE("Copy Vectors .........Done"); - } - - aMergeFilter->SetGeometry(aMergeGeoms->GetOutput()); + output->GetCellData()->AddArray(newArray); - aMergeGeoms->AddInput(aDSScalars); - aMergeGeoms->AddInput(aDSVectors); - - if(aArrays->GetNumberOfTuples()>0) - aMergeFilter->AddField("VISU_FIELD",aDSArrays); - - if(MYDEBUG){ - MESSAGE("PointData:"); - aDSArrays->GetPointData()->Print(cout); - MESSAGE("CellData:"); - aDSArrays->GetCellData()->Print(cout); + // need in vectors array and scalars array + if(vtkDataArray* vc = aScalarMapper->GetVTKOutput()->GetCellData()->GetVectors()){ + output->GetCellData()->SetVectors(newArray); + } + else if(vtkDataArray* sc = aScalarMapper->GetVTKOutput()->GetCellData()->GetScalars()) + output->GetCellData()->SetScalars(newArray); } - aMergeFilter->SetScalars(aDSScalars); - aMergeFilter->SetVectors(aDSVectors); - aMergeFilter->Update(); - + if(MYDEBUG){ - MESSAGE("Output tuples:"); - int nbTuples = aMergeFilter->GetUnstructuredGridOutput()->GetCellData()->GetNumberOfTuples(); - for(int i=0;iGetUnstructuredGridOutput()->GetCellData()->GetNumberOfComponents(); - float* aTuple = aMergeFilter->GetUnstructuredGridOutput()->GetCellData()->GetTuple(i); - cout << "\t\tTuple["<Print(cout); } - SetInput(aMergeFilter->GetUnstructuredGridOutput()); - aMergeGeoms->Delete(); - aDSScalars->Delete(); - aDSVectors->Delete(); - - aDSArrays->Delete(); - aArrays->Delete(); + SetInput(output); - aMergeFilter->Delete(); + output->Delete(); + newArray->Delete(); } else { -- 2.39.2