------------------------------------------------------------------------------
| 425 | |
| 426 | //------------------------------------------------------------------------------ |
| 427 | bool vtkLabeledContourPolyDataItem::PrepareRender() |
| 428 | { |
| 429 | vtkAbstractContextItem* parent = this->GetParent(); |
| 430 | vtkContextTransform* transform = vtkContextTransform::SafeDownCast(parent); |
| 431 | |
| 432 | if (transform == nullptr) |
| 433 | { |
| 434 | vtkErrorMacro(<< "No parent or parent is not a vtkContextTransform"); |
| 435 | return false; |
| 436 | } |
| 437 | |
| 438 | if (!this->Internal->SetViewInfo(this->GetScene(), transform)) |
| 439 | { |
| 440 | return false; |
| 441 | } |
| 442 | |
| 443 | // Already checked that these exist in CheckInputs() |
| 444 | vtkPolyData* input = this->PolyData; |
| 445 | vtkCellArray* lines = input->GetLines(); |
| 446 | vtkDataArray* scalars = input->GetPointData()->GetScalars(); |
| 447 | vtkTextRenderer* tren = vtkTextRenderer::GetInstance(); |
| 448 | if (!tren) |
| 449 | { |
| 450 | vtkErrorMacro(<< "Text renderer unavailable."); |
| 451 | return false; |
| 452 | } |
| 453 | |
| 454 | // Maps scalar values to text properties: |
| 455 | typedef std::map<double, vtkTextProperty*> LabelPropertyMapType; |
| 456 | LabelPropertyMapType labelMap; |
| 457 | |
| 458 | // Initialize with the user-requested mapping, if it exists. |
| 459 | if (this->TextPropertyMapping != nullptr) |
| 460 | { |
| 461 | vtkDoubleArray::Iterator valIt = this->TextPropertyMapping->Begin(); |
| 462 | vtkDoubleArray::Iterator valItEnd = this->TextPropertyMapping->End(); |
| 463 | TextPropLoop tprops(this->TextProperties); |
| 464 | for (; valIt != valItEnd; ++valIt) |
| 465 | { |
| 466 | labelMap.insert(std::make_pair(*valIt, tprops.Next())); |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | // Create the list of metrics, but no text property information yet. |
| 471 | vtkIdType numPts; |
| 472 | const vtkIdType* ids; |
| 473 | for (lines->InitTraversal(); lines->GetNextCell(numPts, ids);) |
| 474 | { |
| 475 | this->Internal->LabelMetrics.emplace_back(); |
| 476 | PDILabelMetric& metric = this->Internal->LabelMetrics.back(); |
| 477 | if (!(metric.Valid = (numPts > 0))) |
| 478 | { |
| 479 | // Mark as invalid and skip if there are no points. |
| 480 | continue; |
| 481 | } |
| 482 | metric.Value = scalars->GetComponent(ids[0], 0); |
| 483 | metric.Value = std::fabs(metric.Value) > 1e-6 ? metric.Value : 0.0; |
| 484 | std::ostringstream str; |
no test coverage detected