| 43 | } |
| 44 | |
| 45 | int vtkBoostLogWeighting::RequestData( |
| 46 | vtkInformation*, vtkInformationVector** inputVector, vtkInformationVector* outputVector) |
| 47 | { |
| 48 | try |
| 49 | { |
| 50 | vtkArrayData* const input_data = vtkArrayData::GetData(inputVector[0]); |
| 51 | if (!input_data) |
| 52 | throw std::runtime_error("Missing input vtkArrayData on port 0."); |
| 53 | if (input_data->GetNumberOfArrays() != 1) |
| 54 | throw std::runtime_error("Input vtkArrayData must contain exactly one array."); |
| 55 | vtkTypedArray<double>* const input_array = |
| 56 | vtkTypedArray<double>::SafeDownCast(input_data->GetArray(0)); |
| 57 | if (!input_array) |
| 58 | throw std::runtime_error("Unsupported input array type."); |
| 59 | |
| 60 | vtkTypedArray<double>* const output_array = |
| 61 | vtkTypedArray<double>::SafeDownCast(input_array->DeepCopy()); |
| 62 | vtkArrayData* const output = vtkArrayData::GetData(outputVector); |
| 63 | output->ClearArrays(); |
| 64 | output->AddArray(output_array); |
| 65 | output_array->Delete(); |
| 66 | |
| 67 | const vtkIdType value_count = input_array->GetNonNullSize(); |
| 68 | switch (this->Base) |
| 69 | { |
| 70 | case BASE_E: |
| 71 | { |
| 72 | if (this->EmitProgress) |
| 73 | { |
| 74 | for (vtkIdType i = 0; i != value_count; ++i) |
| 75 | { |
| 76 | output_array->SetValueN(i, boost::math::log1p(output_array->GetValueN(i))); |
| 77 | |
| 78 | double progress = static_cast<double>(i) / static_cast<double>(value_count); |
| 79 | this->InvokeEvent(vtkCommand::ProgressEvent, &progress); |
| 80 | } |
| 81 | } |
| 82 | else |
| 83 | { |
| 84 | for (vtkIdType i = 0; i != value_count; ++i) |
| 85 | { |
| 86 | output_array->SetValueN(i, boost::math::log1p(output_array->GetValueN(i))); |
| 87 | } |
| 88 | } |
| 89 | break; |
| 90 | } |
| 91 | case BASE_2: |
| 92 | { |
| 93 | const double ln2 = log(2.0); |
| 94 | if (this->EmitProgress) |
| 95 | { |
| 96 | for (vtkIdType i = 0; i != value_count; ++i) |
| 97 | { |
| 98 | output_array->SetValueN(i, 1.0 + log(output_array->GetValueN(i)) / ln2); |
| 99 | |
| 100 | double progress = static_cast<double>(i) / static_cast<double>(value_count); |
| 101 | this->InvokeEvent(vtkCommand::ProgressEvent, &progress); |
| 102 | } |
nothing calls this directly
no test coverage detected