------------------------------------------------------------------------------ Description: Return the error at the mid-point. The type of error depends on the state of the concrete error metric. For instance, it can return an absolute or relative error metric. See RequiresEdgeSubdivision() for a description of the arguments. \post positive_result: result>=0
| 152 | // See RequiresEdgeSubdivision() for a description of the arguments. |
| 153 | // \post positive_result: result>=0 |
| 154 | double vtkAttributesErrorMetric::GetError( |
| 155 | double* leftPoint, double* midPoint, double* rightPoint, double alpha) |
| 156 | { |
| 157 | assert("pre: leftPoint_exists" && leftPoint != nullptr); |
| 158 | assert("pre: midPoint_exists" && midPoint != nullptr); |
| 159 | assert("pre: rightPoint_exists" && rightPoint != nullptr); |
| 160 | assert("pre: clamped_alpha" && alpha > 0 && alpha < 1); |
| 161 | |
| 162 | double ae; |
| 163 | vtkGenericAttributeCollection* ac; |
| 164 | |
| 165 | this->ComputeSquareAbsoluteAttributeTolerance(); |
| 166 | |
| 167 | constexpr int ATTRIBUTE_OFFSET = 6; |
| 168 | |
| 169 | ac = this->DataSet->GetAttributes(); |
| 170 | vtkGenericAttribute* a = ac->GetAttribute(ac->GetActiveAttribute()); |
| 171 | |
| 172 | if (this->GenericCell->IsAttributeLinear(a)) |
| 173 | { |
| 174 | // don't need to do anything: |
| 175 | ae = 0; |
| 176 | } |
| 177 | else |
| 178 | { |
| 179 | if (ac->GetActiveComponent() >= 0) // one component |
| 180 | { |
| 181 | int i = ac->GetAttributeIndex(ac->GetActiveAttribute()) + ac->GetActiveComponent() + |
| 182 | ATTRIBUTE_OFFSET; |
| 183 | double tmp = leftPoint[i] + alpha * (rightPoint[i] - leftPoint[i]) - midPoint[i]; |
| 184 | ae = tmp * tmp; |
| 185 | } |
| 186 | else // module of the vector |
| 187 | { |
| 188 | // If x and y are two vectors, we compute: |x-y| |
| 189 | // We should compute ||x|-|y|| but |x-y| is usually enough |
| 190 | // and tends to produce less degenerated edges. |
| 191 | // Remind that: ||x|-|y||<=|x-y| |
| 192 | int i = ac->GetAttributeIndex(ac->GetActiveAttribute()) + ATTRIBUTE_OFFSET; |
| 193 | int j = 0; |
| 194 | int c = ac->GetNumberOfComponents(); |
| 195 | double tmp; |
| 196 | |
| 197 | ae = 0; |
| 198 | while (j < c) |
| 199 | { |
| 200 | tmp = leftPoint[i + j] + alpha * (rightPoint[i + j] - leftPoint[i + j]) - midPoint[i + j]; |
| 201 | ae += tmp * tmp; |
| 202 | ++j; |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | double result; |
| 208 | |
| 209 | if (this->Range != 0) |
| 210 | { |
| 211 | result = sqrt(ae) / this->Range; |
nothing calls this directly
no test coverage detected