| 71 | } |
| 72 | |
| 73 | int vtkArrayNorm::RequestData( |
| 74 | vtkInformation*, vtkInformationVector** inputVector, vtkInformationVector* outputVector) |
| 75 | { |
| 76 | try |
| 77 | { |
| 78 | // Test our preconditions ... |
| 79 | vtkArrayData* const input_data = vtkArrayData::GetData(inputVector[0]); |
| 80 | if (!input_data) |
| 81 | throw std::runtime_error("Missing vtkArrayData on input port 0."); |
| 82 | if (input_data->GetNumberOfArrays() != 1) |
| 83 | throw std::runtime_error("vtkArrayData on input port 0 must contain exactly one vtkArray."); |
| 84 | vtkTypedArray<double>* const input_array = |
| 85 | vtkTypedArray<double>::SafeDownCast(input_data->GetArray(static_cast<vtkIdType>(0))); |
| 86 | if (!input_array) |
| 87 | throw std::runtime_error("vtkArray on input port 0 must be a vtkTypedArray<double>."); |
| 88 | if (input_array->GetDimensions() != 2) |
| 89 | throw std::runtime_error("vtkArray on input port 0 must be a matrix."); |
| 90 | |
| 91 | const vtkIdType vector_dimension = this->Dimension; |
| 92 | if (vector_dimension < 0 || vector_dimension > 1) |
| 93 | throw std::runtime_error("Dimension must be zero or one."); |
| 94 | const vtkIdType element_dimension = 1 - vector_dimension; |
| 95 | |
| 96 | // Setup our output ... |
| 97 | std::ostringstream array_name; |
| 98 | array_name << "L" << this->L << "_norm"; |
| 99 | |
| 100 | vtkDenseArray<double>* const output_array = vtkDenseArray<double>::New(); |
| 101 | output_array->SetName(array_name.str()); |
| 102 | output_array->Resize(input_array->GetExtent(vector_dimension)); |
| 103 | output_array->Fill(0.0); |
| 104 | |
| 105 | vtkArrayData* const output = vtkArrayData::GetData(outputVector); |
| 106 | output->ClearArrays(); |
| 107 | output->AddArray(output_array); |
| 108 | output_array->Delete(); |
| 109 | |
| 110 | // Make it happen ... |
| 111 | vtkArrayCoordinates coordinates; |
| 112 | const vtkIdType non_null_count = input_array->GetNonNullSize(); |
| 113 | for (vtkIdType n = 0; n != non_null_count; ++n) |
| 114 | { |
| 115 | input_array->GetCoordinatesN(n, coordinates); |
| 116 | if (!this->Window.Contains(coordinates[element_dimension])) |
| 117 | continue; |
| 118 | output_array->SetValue(coordinates[vector_dimension], |
| 119 | output_array->GetValue(coordinates[vector_dimension]) + |
| 120 | pow(input_array->GetValueN(n), this->L)); |
| 121 | } |
| 122 | |
| 123 | for (vtkArray::SizeT n = 0; n != output_array->GetNonNullSize(); ++n) |
| 124 | { |
| 125 | output_array->SetValueN(n, pow(output_array->GetValueN(n), 1.0 / this->L)); |
| 126 | } |
| 127 | |
| 128 | // Optionally invert the output vector |
| 129 | if (this->Invert) |
| 130 | { |
nothing calls this directly
no test coverage detected