------------------------------------------------------------------------------
| 329 | |
| 330 | //------------------------------------------------------------------------------ |
| 331 | int vtkBarChartActor::PlaceAxes(vtkViewport* viewport, const int* vtkNotUsed(size)) |
| 332 | { |
| 333 | vtkIdType i; |
| 334 | vtkDataObject* input = this->GetInput(); |
| 335 | vtkFieldData* field = input->GetFieldData(); |
| 336 | double v = 0.0; |
| 337 | |
| 338 | this->Initialize(); |
| 339 | |
| 340 | if (!field) |
| 341 | { |
| 342 | return 0; |
| 343 | } |
| 344 | |
| 345 | // Retrieve the appropriate data array |
| 346 | vtkDataArray* da = field->GetArray(this->ArrayNumber); |
| 347 | if (!da) |
| 348 | { |
| 349 | return 0; |
| 350 | } |
| 351 | |
| 352 | // Determine the number of independent variables |
| 353 | this->N = da->GetNumberOfTuples(); |
| 354 | if (this->N <= 0 || this->N >= VTK_ID_MAX) |
| 355 | { |
| 356 | this->N = 0; |
| 357 | vtkErrorMacro(<< "No field data to plot"); |
| 358 | return 0; |
| 359 | } |
| 360 | |
| 361 | // We need to loop over the field to determine the total |
| 362 | this->Heights = new double[this->N]; |
| 363 | this->MaxHeight = -VTK_FLOAT_MAX; |
| 364 | this->MinHeight = VTK_FLOAT_MAX; |
| 365 | for (i = 0; i < this->N; i++) |
| 366 | { |
| 367 | v = fabs(da->GetComponent(i, this->ComponentNumber)); |
| 368 | this->Heights[i] = v; |
| 369 | this->MinHeight = (v < this->MinHeight ? v : this->MinHeight); |
| 370 | this->MaxHeight = (v > this->MaxHeight ? v : this->MaxHeight); |
| 371 | } |
| 372 | if (this->MaxHeight > 0.0) |
| 373 | { |
| 374 | // compress the heights into the (0.10->1.0) range for aesthetic reasons |
| 375 | // (i.e., you always want to see the minimum bar). |
| 376 | for (i = 0; i < this->N; i++) |
| 377 | { |
| 378 | this->Heights[i] = |
| 379 | 0.10 + 0.90 * (this->Heights[i] - this->MinHeight) / (this->MaxHeight - this->MinHeight); |
| 380 | } |
| 381 | this->MinHeight -= 0.10 * (this->MaxHeight - this->MinHeight); |
| 382 | } |
| 383 | |
| 384 | // Get the location of the corners of the box; make sure they are sane |
| 385 | double* p1 = this->PositionCoordinate->GetComputedDoubleViewportValue(viewport); |
| 386 | double* p2 = this->Position2Coordinate->GetComputedDoubleViewportValue(viewport); |
| 387 | this->P1[0] = (p1[0] < p2[0] ? p1[0] : p2[0]); |
| 388 | this->P1[1] = (p1[1] < p2[1] ? p1[1] : p2[1]); |
no test coverage detected