| 212 | #define VTK_TOLERANCE 1.0e-03 |
| 213 | |
| 214 | void vtkTextureMapToPlane::ComputeNormal(vtkDataSet* output) |
| 215 | { |
| 216 | vtkIdType numPts = output->GetNumberOfPoints(); |
| 217 | double m[9], v[3], x[3]; |
| 218 | vtkIdType ptId; |
| 219 | int dir = 0, i; |
| 220 | double length, w, *c1, *c2, *c3, det; |
| 221 | |
| 222 | // First thing to do is to get an initial normal and point to define |
| 223 | // the plane. Then, use this information to construct better |
| 224 | // matrices. If problem occurs, then the point and plane becomes the |
| 225 | // fallback value. |
| 226 | // |
| 227 | // Get minimum width of bounding box. |
| 228 | const double* bounds = output->GetBounds(); |
| 229 | length = output->GetLength(); |
| 230 | |
| 231 | for (w = length, i = 0; i < 3; i++) |
| 232 | { |
| 233 | this->Normal[i] = 0.0; |
| 234 | if ((bounds[2 * i + 1] - bounds[2 * i]) < w) |
| 235 | { |
| 236 | dir = i; |
| 237 | w = bounds[2 * i + 1] - bounds[2 * i]; |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | // If the bounds is perpendicular to one of the axes, then can |
| 242 | // quickly compute normal. |
| 243 | // |
| 244 | this->Normal[dir] = 1.0; |
| 245 | if (w <= (length * VTK_TOLERANCE)) |
| 246 | { |
| 247 | return; |
| 248 | } |
| 249 | |
| 250 | // Need to compute least squares approximation. Depending on major |
| 251 | // normal direction (dir), construct matrices appropriately. |
| 252 | // |
| 253 | // Compute 3x3 least squares matrix |
| 254 | v[0] = v[1] = v[2] = 0.0; |
| 255 | for (i = 0; i < 9; i++) |
| 256 | { |
| 257 | m[i] = 0.0; |
| 258 | } |
| 259 | |
| 260 | for (ptId = 0; ptId < numPts; ptId++) |
| 261 | { |
| 262 | output->GetPoint(ptId, x); |
| 263 | |
| 264 | v[0] += x[0] * x[2]; |
| 265 | v[1] += x[1] * x[2]; |
| 266 | v[2] += x[2]; |
| 267 | |
| 268 | m[0] += x[0] * x[0]; |
| 269 | m[1] += x[0] * x[1]; |
| 270 | m[2] += x[0]; |
| 271 |
no test coverage detected