From: apo Date: Thu, 26 Jan 2006 07:56:53 +0000 (+0000) Subject: To avoid division by zero X-Git-Tag: mergeto_trunk_07Feb06~28 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8b9433898839198e653caa42f1a312477d961e09;p=modules%2Fvisu.git To avoid division by zero --- diff --git a/src/PIPELINE/VISU_FieldTransform.cxx b/src/PIPELINE/VISU_FieldTransform.cxx index 195cc657..82081859 100644 --- a/src/PIPELINE/VISU_FieldTransform.cxx +++ b/src/PIPELINE/VISU_FieldTransform.cxx @@ -141,64 +141,78 @@ VISU_FieldTransform template void ExecVectors(VISU_FieldTransform::TTransformFun theFunction, VTKViewer_Transform* theTransform, - float theScalarRange[2], int theNbComponent, - TypeData* theInputData, TypeData* theOutputData) + float theScalarRange[2], + int theNbOfTuples, + TypeData* theInputData, + TypeData* theOutputData) { - vtkDataArray *inVectors = theInputData->GetVectors(); - if ( !inVectors || theNbComponent < 1 ) return; - vtkFloatArray *newVectors = vtkFloatArray::New(); - newVectors->SetNumberOfComponents(3); - newVectors->SetNumberOfTuples(theNbComponent); + vtkDataArray *anInVectors = theInputData->GetVectors(); + if ( !anInVectors || theNbOfTuples < 1 ) + return; + vtkFloatArray *aNewVectors = vtkFloatArray::New(); + aNewVectors->SetNumberOfComponents(3); + aNewVectors->SetNumberOfTuples(theNbOfTuples); float aScalarRange[2] = {(*theFunction)(theScalarRange[0]),(*theFunction)(theScalarRange[1])}; - float *V, v[3], vMag, aDelta = aScalarRange[1] - aScalarRange[0]; + float aDelta = aScalarRange[1] - aScalarRange[0]; float aScale[3] = {1.0, 1.0, 1.0}; + static float EPS = 1.0 / VTK_LARGE_FLOAT; if(theTransform){ aScale[0] = theTransform->GetScale()[0]; aScale[1] = theTransform->GetScale()[1]; aScale[2] = theTransform->GetScale()[2]; } if(theFunction == &(VISU_FieldTransform::Ident)){ - for (int ptId = 0; ptId < theNbComponent; ptId++) { - V = inVectors->GetTuple3(ptId); - v[0] = V[0]*aScale[0]; - v[1] = V[1]*aScale[1]; - v[2] = V[2]*aScale[2]; - newVectors->SetTuple3(ptId, v[0], v[1], v[2]); + for (int aTupleId = 0; aTupleId < theNbOfTuples; aTupleId++) { + float anInVec[3]; + anInVectors->GetTuple(aTupleId,anInVec); + float anNewVec[3]; + anNewVec[0] = anInVec[0]*aScale[0]; + anNewVec[1] = anInVec[1]*aScale[1]; + anNewVec[2] = anInVec[2]*aScale[2]; + aNewVectors->SetTuple(aTupleId,anNewVec); } }else{ - for (int ptId = 0; ptId < theNbComponent; ptId++) { - V = inVectors->GetTuple3(ptId); - vMag = vtkMath::Norm(V); - vMag = ((*theFunction)(vMag) - aScalarRange[0]) / aDelta * theScalarRange[1] / vMag; - if(vMag <= 0.0) vMag = 0.0; - v[0] = V[0]*vMag*aScale[0]; - v[1] = V[1]*vMag*aScale[1]; - v[2] = V[2]*vMag*aScale[2]; - newVectors->SetTuple3(ptId, v[0], v[1], v[2]); + for (int aTupleId = 0; aTupleId < theNbOfTuples; aTupleId++) { + float anInVec[3]; + anInVectors->GetTuple(aTupleId,anInVec); + float aMagn = vtkMath::Norm(anInVec); + if(aMagn > EPS) + aMagn = ((*theFunction)(aMagn) - aScalarRange[0]) / aDelta * theScalarRange[1] / aMagn; + if(aMagn < 0.0) + aMagn = 0.0; + float anNewVec[3]; + anNewVec[0] = anInVec[0]*aMagn*aScale[0]; + anNewVec[1] = anInVec[1]*aMagn*aScale[1]; + anNewVec[2] = anInVec[2]*aMagn*aScale[2]; + aNewVectors->SetTuple(aTupleId,anNewVec); } } - theOutputData->SetVectors(newVectors); - newVectors->Delete(); + theOutputData->SetVectors(aNewVectors); + aNewVectors->Delete(); } template void -ExecScalars(VISU_FieldTransform::TTransformFun theFunction, float theScalarRange[2], - int theNbComponent, TypeData* theInputData, TypeData* theOutputData) +ExecScalars(VISU_FieldTransform::TTransformFun theFunction, + float theScalarRange[2], + int theNbOfTuples, + TypeData* theInputData, + TypeData* theOutputData) { - vtkDataArray *inScalars = theInputData->GetScalars(); - if ( !inScalars || theNbComponent < 1 ) + vtkDataArray *anInScalars = theInputData->GetScalars(); + if ( !anInScalars || theNbOfTuples < 1 ) return; - vtkFloatArray *newScalars = vtkFloatArray::New(); - newScalars->SetNumberOfComponents(1); - newScalars->SetNumberOfTuples(theNbComponent); + vtkFloatArray *aNewScalars = vtkFloatArray::New(); + aNewScalars->SetNumberOfComponents(1); + aNewScalars->SetNumberOfTuples(theNbOfTuples); float aScalarRange[2] = {(*theFunction)(theScalarRange[0]),(*theFunction)(theScalarRange[1])}; - for (int ptId = 0; ptId < theNbComponent; ptId++) { - float s = (*theFunction)(inScalars->GetTuple1(ptId )); - if(s < aScalarRange[0]) s = aScalarRange[0]; - newScalars->SetTuple1(ptId, s); + for (int aTupleId = 0; aTupleId < theNbOfTuples; aTupleId++) { + float aScalar = (*theFunction)(anInScalars->GetTuple1(aTupleId)); + if(aScalar < aScalarRange[0]) + aScalar = aScalarRange[0]; + aNewScalars->SetTuple1(aTupleId,aScalar); } - theOutputData->SetScalars(newScalars); - newScalars->Delete(); + theOutputData->SetScalars(aNewScalars); + aNewScalars->Delete(); } void