| 65 | //------------------------------------------------------------------------------ |
| 66 | |
| 67 | int vtkBoostRandomSparseArraySource::RequestData( |
| 68 | vtkInformation*, vtkInformationVector**, vtkInformationVector* outputVector) |
| 69 | { |
| 70 | boost::mt19937 pattern_generator(static_cast<boost::uint32_t>(this->ElementProbabilitySeed)); |
| 71 | boost::bernoulli_distribution<> pattern_distribution(this->ElementProbability); |
| 72 | boost::variate_generator<boost::mt19937&, boost::bernoulli_distribution<>> pattern( |
| 73 | pattern_generator, pattern_distribution); |
| 74 | |
| 75 | boost::mt19937 value_generator(static_cast<boost::uint32_t>(this->ElementValueSeed)); |
| 76 | boost::uniform_real<> value_distribution(this->MinValue, this->MaxValue); |
| 77 | boost::variate_generator<boost::mt19937&, boost::uniform_real<>> values( |
| 78 | value_generator, value_distribution); |
| 79 | |
| 80 | vtkSparseArray<double>* const array = vtkSparseArray<double>::New(); |
| 81 | array->Resize(this->Extents); |
| 82 | |
| 83 | vtkArrayCoordinates coordinates; |
| 84 | for (vtkArray::SizeT n = 0; n != this->Extents.GetSize(); ++n) |
| 85 | { |
| 86 | this->Extents.GetRightToLeftCoordinatesN(n, coordinates); |
| 87 | |
| 88 | // Although it seems wasteful, we calculate a value for every element in the array |
| 89 | // so the results stay consistent as the ElementProbability varies |
| 90 | const double value = values(); |
| 91 | if (pattern()) |
| 92 | { |
| 93 | array->AddValue(coordinates, value); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | vtkArrayData* const output = vtkArrayData::GetData(outputVector); |
| 98 | output->ClearArrays(); |
| 99 | output->AddArray(array); |
| 100 | array->Delete(); |
| 101 | |
| 102 | return 1; |
| 103 | } |
| 104 | VTK_ABI_NAMESPACE_END |
nothing calls this directly
no test coverage detected