-execute(int theNbComp, int theScalarMode, TypeData* theInputData, TypeData* theOutputData){
- vtkDataArray *inVectors = theInputData->GetVectors();
- if ( !inVectors || theNbComp < 1 )
- return;
- vtkFloatArray *newScalars = vtkFloatArray::New();
- //newScalars->SetName(inVectors->GetName());
- newScalars->SetNumberOfComponents(1);
- newScalars->SetNumberOfTuples(theNbComp);
- for (int ptId = 0; ptId < theNbComp; ptId++) {
- float v[3], s;
- inVectors->GetTuple(ptId,v);
- if ( theScalarMode < 1 || theScalarMode > 3)
- s = sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
- else
- s = v[theScalarMode - 1];
- newScalars->SetTuple1(ptId, s);
+execute(int theNbElems,
+ int theScalarMode,
+ TypeData* theInputData,
+ TypeData* theOutputData)
+{
+ if(theNbElems < 1 )
+ return;
+ vtkDataArray* aFieldArray = theInputData->GetArray("VISU_FIELD");
+ if(vtkFloatArray *aFloatArray = dynamic_cast<vtkFloatArray*>(aFieldArray)){
+ int aNbComp = aFloatArray->GetNumberOfComponents();
+ std::vector<float> anArray(aNbComp < 3? 3: 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();