vtkFloatArray *aFArr=vtkFloatArray::New();
aFArr->SetNumberOfComponents(aNumberOfComponents);
aFArr->SetNumberOfTuples(aNbTuples);
- aFArr->SetName("FIELD");
+ aFArr->SetName("VISU_FIELD");
aDataSetAttributes->AddArray(aFArr);
aFArr->Delete();
//
aDataSetAttributes = theSource->GetCellData();
}
//
- int aNumberOfComponents=theField->myNbComp;
+ int aNbComp = theField->myNbComp;
vtkFloatArray *aFloatArray = vtkFloatArray::New();
- switch(aNumberOfComponents) {
+ switch(aNbComp){
case 1:
aFloatArray->SetNumberOfComponents(1);
aDataSetAttributes->SetScalars(aFloatArray);
aFloatArray->SetNumberOfComponents(3);
aDataSetAttributes->SetVectors(aFloatArray);
}
- aFloatArray->Delete();
aFloatArray->SetNumberOfTuples(aNbTuples);
aFloatArray->SetName(aFieldName.c_str());
//
- vtkFloatArray *aFArr=vtkFloatArray::New();
- aFArr->SetNumberOfComponents(theField->myNbComp);
- aFArr->SetNumberOfTuples(aNbTuples);
- aFArr->SetName("FIELD");
- aDataSetAttributes->AddArray(aFArr);
- aFArr->Delete();
+ vtkFloatArray *aDataArray = vtkFloatArray::New();
+ aDataArray->SetNumberOfComponents(aNbComp);
+ aDataArray->SetNumberOfTuples(aNbTuples);
+ aDataSetAttributes->AddArray(aDataArray);
+ aDataArray->SetName("VISU_FIELD");
//
- TGeom2Value& aGeom2Value = theValForTime->myGeom2Value;
+ const TGeom2Value& aGeom2Value = theValForTime->myGeom2Value;
PGaussMeshImpl aGaussMesh = theValForTime->myGaussMesh;
const TGeom2GaussSubMesh& aGeom2GaussSubMesh = aGaussMesh->myGeom2GaussSubMesh;
TGeom2GaussSubMesh::const_iterator anIter = aGeom2GaussSubMesh.begin();
- int aTupleIdx = 0, aTupleId = 0;
- vector<float>aVal(aNumberOfComponents);
+ TVector<float> aDataValues(aNbComp);
//
- for(; anIter != aGeom2GaussSubMesh.end(); anIter++){
+ for(int aTupleId = 0; anIter != aGeom2GaussSubMesh.end(); anIter++){
vtkIdType aGeom = anIter->first;
PGaussSubMeshImpl aGaussSubMesh = anIter->second;
if(!aGaussSubMesh->myIsDone)
"GetTimeStampOnGaussMesh >> Can't find values for corresponding Gauss Points SubMesh");
}
const TMeshValue& aMeshValue = anIter2->second;
- int aNbElem = aMeshValue.myNbElem;
int aNbGauss = aMeshValue.myNbGauss;
- //int aNbComp = aMeshValue.myNbComp;
+ int aNbElem = aMeshValue.myNbElem;
if(aNbGauss < 1)
continue;
INITMSG(MYDEBUG,"- aGeom = "<<aGeom<<
"; aNbElem = "<<aNbElem<<
- "; aNbComp = "<<aNumberOfComponents<<
+ "; aNbComp = "<<aNbComp<<
"; aNbGauss = "<<aNbGauss<<
endl);
//
- int aNbComp2=aNumberOfComponents;
- if (aNumberOfComponents==2 || aNumberOfComponents==4) {
- aNbComp2 = 2;
- }
- else if (aNumberOfComponents>4){
+ int aNbComp2 = aNbComp;
+ switch(aNbComp){
+ case 2:
+ case 4:
+ aNbComp2 = 2;
+ break;
+ default:
aNbComp2 = 3;
}
//
- int iE, iG, iC;
- for(iE=0; iE<aNbElem; iE++){
- //aFloatArray
- for(iC=0; iC<aNumberOfComponents; iC++) {
- aVal[iC]=0.;
- }
- TCValueSliceArr aValueSliceArr = aMeshValue.GetGaussValueSliceArr(iE);
- for(iG=0; iG<aNbGauss; iG++){
- const TCValueSlice& aValueSlice=aValueSliceArr[iG];
- for(iC=0; iC<aNbComp2; iC++) {
- aVal[iC] += aValueSlice[iC];
+ for(int iElem = 0; iElem < aNbElem; iElem++){
+ float aValue[] = {0.0, 0.0, 0.0};
+ TCValueSliceArr aValueSliceArr = aMeshValue.GetGaussValueSliceArr(iElem);
+ for(int iGauss = 0; iGauss < aNbGauss; iGauss++, aTupleId++){
+ const TCValueSlice& aValueSlice = aValueSliceArr[iGauss];
+ for(int iComp = 0; iComp < aNbComp2; iComp++){
+ aValue[iComp] += aValueSlice[iComp];
}
- aFloatArray->SetTuple(aTupleId++, &aVal[0]);
- }
- //aFArr
- for(iC=0; iC<aNumberOfComponents; iC++) {
- aVal[iC]=0.;
- }
- for(iG=0; iG<aNbGauss; iG++){
- const TCValueSlice& aValueSlice=aValueSliceArr[iG];
- for(iC=0; iC<aNumberOfComponents; iC++) {
- aVal[iC] += aValueSlice[iC];
+ for(int iComp = 0; iComp < aNbComp; iComp++){
+ aDataValues[iComp] = aValueSlice[iComp];
}
- aFArr->SetTuple(aTupleIdx++, &aVal[0]);
+ aFloatArray->SetTuple(aTupleId,aValue);
+ aDataArray->SetTuple(aTupleId,&aDataValues[0]);
}
}
- }// for(int aTupleId = 0; anIter != aGeom2GaussSubMesh.end(); anIter++){
-
+ }
+ aFloatArray->Delete();
+ aDataArray->Delete();
}
}
template<typename TypeData> void
-execute(int theNbComp, int theScalarMode, TypeData* theInputData, TypeData* theOutputData){
- vtkFloatArray *aFArr=
- dynamic_cast<vtkFloatArray *>(theInputData->GetArray("FIELD"));
- if (!aFArr || theNbComp < 1 ) {
+execute(int theNbElems,
+ int theScalarMode,
+ TypeData* theInputData,
+ TypeData* theOutputData)
+{
+ if(theNbElems < 1 )
return;
- }
-
- int aNumberOfComponents=aFArr->GetNumberOfComponents();
- vector<float>v(aNumberOfComponents);
- //
- vtkFloatArray *newScalars = vtkFloatArray::New();
- ostringstream aName;
- aName<<aFArr->GetName(); aName<<", "; aName<<theScalarMode;
- newScalars->SetName(aName.str().c_str());
- newScalars->SetNumberOfComponents(1);
- newScalars->SetNumberOfTuples(theNbComp);
- //
- for (int ptId = 0; ptId < theNbComp; ptId++) {
- float s;
- aFArr->GetTuple (ptId, &v[0]);
- if (!theScalarMode) {
- //if ( theScalarMode < 1 || theScalarMode > 3) {
- s = sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
- }
- else {
- s = v[theScalarMode - 1];
+ vtkDataArray* aVectors = theInputData->GetVectors();
+ vtkDataArray* aFieldArray = theInputData->GetArray("VISU_FIELD");
+ if(vtkDataArray* aDataArray = aVectors){
+ if(vtkFloatArray *aFloatArray = dynamic_cast<vtkFloatArray*>(aDataArray)){
+ int aNbComp = aFloatArray->GetNumberOfComponents();
+ std::vector<float> anArray(aNbComp);
+ //
+ vtkFloatArray *aScalars = vtkFloatArray::New();
+ aScalars->SetNumberOfTuples(theNbElems);
+ aScalars->SetNumberOfComponents(1);
+ //
+ if(!theScalarMode){
+ for(int anId = 0; anId < theNbElems; anId++){
+ aFloatArray->GetTuple(anId,&anArray[0]);
+ float aVector[3] = {anArray[0], anArray[1], anArray[2]};
+ float aScalar = sqrt(aVector[0]*aVector[0] + aVector[1]*aVector[1] + aVector[2]*aVector[2]);
+ aScalars->SetTuple1(anId,aScalar);
+ }
+ }else{
+ for(int anId = 0; anId < theNbElems; anId++){
+ aFloatArray->GetTuple(anId,&anArray[0]);
+ aScalars->SetTuple1(anId,anArray[theScalarMode - 1]);
+ }
+ }
+ theOutputData->SetScalars(aScalars);
+ aScalars->Delete();
}
- newScalars->SetTuple1(ptId, s);
}
- theOutputData->SetScalars(newScalars);
- newScalars->Delete();
}
void VISU_Extractor::Execute(){
output->GetCellData()->CopyAllOff();
if(input->GetPointData()->GetNumberOfArrays()){
output->GetPointData()->CopyVectorsOn();
- int nbComp = input->GetNumberOfPoints();
+ int aNbElems = input->GetNumberOfPoints();
vtkPointData *inData = input->GetPointData(), *outData = output->GetPointData();
if(inData->GetAttribute(vtkDataSetAttributes::VECTORS))
- execute(nbComp,myScalarMode,inData,outData);
+ execute(aNbElems,myScalarMode,inData,outData);
else
output->GetPointData()->CopyScalarsOn();
outData->PassData(inData);
}else{
output->GetCellData()->CopyVectorsOn();
- int nbComp = input->GetNumberOfCells();
+ int aNbElems = input->GetNumberOfCells();
vtkCellData *inData = input->GetCellData(), *outData = output->GetCellData();
if(inData->GetAttribute(vtkDataSetAttributes::VECTORS))
- execute(nbComp,myScalarMode,inData,outData);
+ execute(aNbElems,myScalarMode,inData,outData);
else
output->GetCellData()->CopyScalarsOn();
outData->PassData(inData);