Commit 5d42650d authored by Joachim Pouderoux's avatar Joachim Pouderoux

Fix bag plot and functional bag plots tests.

Use precomputed table of densities to avoid precision differences
on some machines.
Also remove unuseful normalization step in the plot and algorithm.

Change-Id: Ifb28b82b276ee93b66f4ddf8f4375f7b3b465b94
parent 33c0d2ef
......@@ -24,6 +24,28 @@
#include "vtkRenderWindowInteractor.h"
#include "vtkTable.h"
const double densities[] = {
-0.42, -0.349997, -0.289995, -0.229993, -0.16999, -0.119988, -0.079985, -0.0499825, -0.01998, -0.0099775, 2.5e-005, -0.0099725, -0.01997, -0.0499675, -0.079965, -0.119963, -0.16996, -0.229958, -0.289955, -0.349953,
-0.34995, -0.279948, -0.209945, -0.149943, -0.08994, -0.0299375, 0.010065, 0.0500675, 0.07007, 0.0900725, 0.090075, 0.0900775, 0.07008, 0.0500825, 0.010085, -0.0299125, -0.08991, -0.149908, -0.209905, -0.279903,
-0.2899, -0.209897, -0.139895, -0.0698925, 0.00011, 0.0501125, 0.100115, 0.140118, 0.17012, 0.190123, 0.190125, 0.190128, 0.17013, 0.140133, 0.100135, 0.0501375, 0.00014, -0.0698575, -0.139855, -0.209853,
-0.22985, -0.149847, -0.069845, 0.0101575, 0.07016, 0.130163, 0.190165, 0.230168, 0.27017, 0.290173, 0.300175, 0.290177, 0.27018, 0.230183, 0.190185, 0.130188, 0.07019, 0.0101925, -0.069805, -0.149803,
-0.1698, -0.0897975, 0.000205, 0.0702075, 0.15021, 0.210213, 0.270215, 0.320217, 0.36022, 0.390223, 0.400225, 0.390228, 0.36023, 0.320233, 0.270235, 0.210237, 0.15024, 0.0702425, 0.000245, -0.0897525,
-0.11975, -0.0297475, 0.050255, 0.130258, 0.21026, 0.290262, 0.350265, 0.410267, 0.46027, 0.490273, 0.500275, 0.490277, 0.46028, 0.410282, 0.350285, 0.290287, 0.21029, 0.130293, 0.050295, -0.0297025,
-0.0797, 0.0103025, 0.100305, 0.190307, 0.27031, 0.350312, 0.430315, 0.500317, 0.55032, 0.580322, 0.600325, 0.580328, 0.55033, 0.500332, 0.430335, 0.350337, 0.27034, 0.190343, 0.100345, 0.0103475,
-0.04965, 0.0503525, 0.140355, 0.230358, 0.32036, 0.410362, 0.500365, 0.570367, 0.63037, 0.680373, 0.700375, 0.680378, 0.63038, 0.570382, 0.500385, 0.410387, 0.32039, 0.230393, 0.140395, 0.0503975,
-0.0196, 0.0704025, 0.170405, 0.270408, 0.36041, 0.460413, 0.550415, 0.630417, 0.71042, 0.770423, 0.800425, 0.770428, 0.71043, 0.630432, 0.550435, 0.460438, 0.36044, 0.270443, 0.170445, 0.0704475,
-0.00955, 0.0904525, 0.190455, 0.290457, 0.39046, 0.490462, 0.580465, 0.680468, 0.77047, 0.850472, 0.900475, 0.850478, 0.77048, 0.680483, 0.580485, 0.490487, 0.39049, 0.290492, 0.190495, 0.0904975,
0.0005, 0.0905025, 0.190505, 0.300507, 0.40051, 0.500513, 0.600515, 0.700517, 0.80052, 0.900523, 1.00053, 0.900528, 0.80053, 0.700533, 0.600535, 0.500537, 0.40054, 0.300542, 0.190545, 0.0905475,
-0.00945, 0.0905525, 0.190555, 0.290557, 0.39056, 0.490563, 0.580565, 0.680568, 0.77057, 0.850572, 0.900575, 0.850577, 0.77058, 0.680583, 0.580585, 0.490588, 0.39059, 0.290592, 0.190595, 0.0905975,
-0.0194, 0.0706025, 0.170605, 0.270608, 0.36061, 0.460613, 0.550615, 0.630618, 0.71062, 0.770622, 0.800625, 0.770628, 0.71063, 0.630633, 0.550635, 0.460638, 0.36064, 0.270643, 0.170645, 0.0706475,
-0.04935, 0.0506525, 0.140655, 0.230658, 0.32066, 0.410662, 0.500665, 0.570667, 0.63067, 0.680673, 0.700675, 0.680678, 0.63068, 0.570682, 0.500685, 0.410687, 0.32069, 0.230693, 0.140695, 0.0506975,
-0.0793, 0.0107025, 0.100705, 0.190708, 0.27071, 0.350712, 0.430715, 0.500718, 0.55072, 0.580722, 0.600725, 0.580727, 0.55073, 0.500733, 0.430735, 0.350737, 0.27074, 0.190743, 0.100745, 0.0107475,
-0.11925, -0.0292475, 0.050755, 0.130758, 0.21076, 0.290762, 0.350765, 0.410767, 0.46077, 0.490773, 0.500775, 0.490777, 0.46078, 0.410782, 0.350785, 0.290787, 0.21079, 0.130793, 0.050795, -0.0292025,
-0.1692, -0.0891975, 0.000805, 0.0708075, 0.15081, 0.210812, 0.270815, 0.320818, 0.36082, 0.390823, 0.400825, 0.390827, 0.36083, 0.320833, 0.270835, 0.210837, 0.15084, 0.0708425, 0.000845, -0.0891525,
-0.22915, -0.149147, -0.069145, 0.0108575, 0.07086, 0.130862, 0.190865, 0.230868, 0.27087, 0.290872, 0.300875, 0.290877, 0.27088, 0.230883, 0.190885, 0.130888, 0.07089, 0.0108925, -0.069105, -0.149103,
-0.2891, -0.209097, -0.139095, -0.0690925, 0.00091, 0.0509125, 0.100915, 0.140918, 0.17092, 0.190922, 0.190925, 0.190928, 0.17093, 0.140933, 0.100935, 0.0509375, 0.00094, -0.0690575, -0.139055, -0.209053,
-0.34905, -0.279048, -0.209045, -0.149042, -0.08904, -0.0290375, 0.010965, 0.0509675, 0.07097, 0.0909725, 0.090975, 0.0909775, 0.07098, 0.0509825, 0.010985, -0.0290125, -0.08901, -0.149007, -0.209005, -0.279003,
};
//----------------------------------------------------------------------------
int TestBagPlot(int, char * [])
{
......@@ -63,13 +85,15 @@ int TestBagPlot(int, char * [])
{
table->SetValue(i + j * numDataI, 0, i); //X
table->SetValue(i + j * numDataI, 1, j); //Y
double dx = (numDataI / 2. - i) / (numDataI / 2.);
double dy = (numDataJ / 2. - j) / (numDataJ / 2.);
double d = 1. - sqrt(dx * dx + dy * dy);
d = floor(d * 100.) / 100.; // to avoid conflicts
d += (i + j * numDataI) / (double)(1000. * numDataI * numDataJ);
//double dx = (numDataI / 2. - i) / (numDataI / 2.);
//double dy = (numDataJ / 2. - j) / (numDataJ / 2.);
//double d = 1. - sqrt(dx * dx + dy * dy);
//d = floor(d * 100.) / 100.; // to avoid conflicts
//d += (i + j * numDataI) / (double)(1000. * numDataI * numDataJ);
double d = densities[i + j * numDataI];
table->SetValue(i + j * numDataI, 2, d); // Density
}
cout << endl;
}
vtkNew<vtkPlotBag> bagPlot;
......
......@@ -127,27 +127,11 @@ void vtkPlotBag::UpdateTableCache(vtkDataArray* density)
// Sort the density array
std::vector<vtkIdType> ids;
ids.resize(nbPoints);
double sum = 0.0;
for (vtkIdType i = 0; i < nbPoints; i++)
{
sum += density->GetTuple1(i);
ids[i] = i;
}
vtkNew<vtkDoubleArray> nDensity;
// Normalize the density array if needed
if (fabs(sum - 1.0) > 1.0e-12)
{
sum = 1.0 / sum;
nDensity->SetNumberOfComponents(1);
nDensity->SetNumberOfTuples(nbPoints);
for (vtkIdType i = 0; i < nbPoints; i++)
{
nDensity->SetTuple1(i, density->GetTuple1(ids[i]) * sum);
}
density = nDensity.GetPointer();
}
// Sort array by density
ArraySorter arraySorter(density);
std::sort(ids.begin(), ids.end(), arraySorter);
......
......@@ -24,6 +24,30 @@
#include <sstream>
//----------------------------------------------------------------------------
const double densities[] = {
0.00013383,
0.000611902,
0.00238409,
0.00791545,
0.0223945,
0.053991,
0.110921,
0.194186,
0.289692,
0.36827,
0.398942,
0.36827,
0.289692,
0.194186,
0.110921,
0.053991,
0.0223945,
0.00791545,
0.00238409,
0.000611902
};
//----------------------------------------------------------------------------
int TestExtractFunctionalBagPlot(int , char * [])
{
......@@ -67,9 +91,10 @@ int TestExtractFunctionalBagPlot(int , char * [])
varName->SetNumberOfValues(numCols);
for (int j = 0; j < numCols; j++)
{
double x = j * 8. / static_cast<double>(numCols) - 4.;
double y = (1. / sqrt(vtkMath::Pi() * 2.)) * exp(-(x*x) / 2.);
density->SetValue(j, y);
//double x = j * 8. / static_cast<double>(numCols) - 4.;
//double d = (1. / sqrt(vtkMath::Pi() * 2.)) * exp(-(x*x) / 2.);
double d = densities[j];
density->SetValue(j, d);
varName->SetValue(j, table->GetColumn(j)->GetName());
}
......
......@@ -103,27 +103,11 @@ int vtkExtractFunctionalBagPlot::RequestData(vtkInformation* /*request*/,
// Sort the density array
std::vector<vtkIdType> ids;
ids.resize(nbPoints);
double sum = 0.0;
for (vtkIdType i = 0; i < nbPoints; i++)
{
sum += density->GetTuple1(i);
ids[i] = i;
}
vtkNew<vtkDoubleArray> nDensity;
// Normalize the density array if needed
if (fabs(sum - 1.0) > 1.0e-12)
{
sum = 1.0 / sum;
nDensity->SetNumberOfComponents(1);
nDensity->SetNumberOfTuples(nbPoints);
for (vtkIdType i = 0; i < nbPoints; i++)
{
nDensity->SetTuple1(i, density->GetTuple1(ids[i]) * sum);
}
density = nDensity.GetPointer();
}
// Fetch and sort arrays according their density
std::vector<DensityVal> varNames;
for (int i = 0; i < varName->GetNumberOfValues(); i++)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment