From 365492537957a174a27fdb9fad432768f0738852 Mon Sep 17 00:00:00 2001 From: jfa Date: Mon, 26 Oct 2009 14:12:58 +0000 Subject: [PATCH] Bug 0020164: EDF 954 VISU : Constant field with Gauss points. Fix changed to correctly process small values (that are displayed in exponential form). Now we use sprinf() and atof() functions to trim values. --- src/PIPELINE/VISU_Extractor.cxx | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/PIPELINE/VISU_Extractor.cxx b/src/PIPELINE/VISU_Extractor.cxx index 24f6ecab..aafb7d55 100644 --- a/src/PIPELINE/VISU_Extractor.cxx +++ b/src/PIPELINE/VISU_Extractor.cxx @@ -41,6 +41,7 @@ #include #include +#define USE_SPRINTF 1 //---------------------------------------------------------------------------- vtkStandardNewMacro(VISU_Extractor); @@ -104,10 +105,18 @@ vtkFloatingPointType CutValue (vtkFloatingPointType theValue, int theDecimals) { vtkFloatingPointType v = theValue; +#ifdef USE_SPRINTF + char aFormat[16]; + sprintf(aFormat, "%%.%dg", theDecimals); + char aStr [256]; + sprintf(aStr, aFormat, theValue); + v = atof(aStr); +#else + #ifndef USE_OLD_ALGORITHM - // + // // VSR 19/10/2009: new algorithm does not use long long type - // + // long n1 = 0; // calculate order of the integral part while ( v > 1. ) { @@ -128,10 +137,10 @@ vtkFloatingPointType CutValue (vtkFloatingPointType theValue, int theDecimals) else while ( n2++ < 0 ) v = v * 10.; #else - // - // VSR 19/10/2009: old algorithm uses long long type - + // + // VSR 19/10/2009: old algorithm uses long long type - // causes incompatibility with some platforms (Windows?) - // + // vtkFloatingPointType aDegree = 0.0; if (abs((long long)v) > 1) aDegree = (long long)log10((double)abs((long long)v)) + 1; @@ -141,13 +150,15 @@ vtkFloatingPointType CutValue (vtkFloatingPointType theValue, int theDecimals) aDegree = pow(10, aDegree); v = ((vtkFloatingPointType)((long long)(v * aDegree))) / aDegree; //printf("$$$ 2 v = %.20g , aDegree = %lld \n", v, (long long)aDegree); +#endif + #endif return v; } //---------------------------------------------------------------------------- -template +template void Module2Scalars(vtkDataArray *theInputDataArray, TValueType* theOutputPtr, @@ -158,8 +169,8 @@ Module2Scalars(vtkDataArray *theInputDataArray, for(vtkIdType aTupleId = 0; aTupleId < theNbOfTuples; aTupleId++){ theInputDataArray->GetTuple(aTupleId, &anArray[0]); vtkFloatingPointType aVector[3] = {anArray[0], anArray[1], anArray[2]}; - vtkFloatingPointType aScalar = sqrt(aVector[0]*aVector[0] + - aVector[1]*aVector[1] + + vtkFloatingPointType aScalar = sqrt(aVector[0]*aVector[0] + + aVector[1]*aVector[1] + aVector[2]*aVector[2]); *theOutputPtr = TValueType(aScalar); theOutputPtr++; -- 2.39.2