MCPcopy Create free account
hub / github.com/Kitware/VTK / PrepareRender

Method PrepareRender

Rendering/Core/vtkLabeledContourMapper.cxx:548–653  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

546
547//------------------------------------------------------------------------------
548bool vtkLabeledContourMapper::PrepareRender(vtkRenderer* ren, vtkActor* act)
549{
550 if (!this->Internal->SetViewInfo(ren, act))
551 {
552 return false;
553 }
554
555 // Already checked that these exist in CheckInputs()
556 vtkPolyData* input = this->GetInput();
557 vtkCellArray* lines = input->GetLines();
558 vtkDataArray* scalars = input->GetPointData()->GetScalars();
559 vtkTextRenderer* tren = vtkTextRenderer::GetInstance();
560 if (!tren)
561 {
562 vtkErrorMacro(<< "Text renderer unavailable.");
563 return false;
564 }
565
566 // Maps scalar values to text properties:
567 typedef std::map<double, vtkTextProperty*> LabelPropertyMapType;
568 LabelPropertyMapType labelMap;
569
570 // Initialize with the user-requested mapping, if it exists.
571 if (this->TextPropertyMapping != nullptr)
572 {
573 vtkDoubleArray::Iterator valIt = this->TextPropertyMapping->Begin();
574 vtkDoubleArray::Iterator valItEnd = this->TextPropertyMapping->End();
575 TextPropLoop tprops(this->TextProperties);
576 for (; valIt != valItEnd; ++valIt)
577 {
578 labelMap.insert(std::make_pair(*valIt, tprops.Next()));
579 }
580 }
581
582 // Create the list of metrics, but no text property information yet.
583 vtkIdType numPts;
584 const vtkIdType* ids;
585 for (lines->InitTraversal(); lines->GetNextCell(numPts, ids);)
586 {
587 this->Internal->LabelMetrics.emplace_back();
588 LabelMetric& metric = this->Internal->LabelMetrics.back();
589 if (!(metric.Valid = (numPts > 0)))
590 {
591 // Mark as invalid and skip if there are no points.
592 continue;
593 }
594 metric.Value = scalars->GetComponent(ids[0], 0);
595 metric.Value = std::fabs(metric.Value) > 1e-6 ? metric.Value : 0.0;
596 std::ostringstream str;
597 str << metric.Value;
598 metric.Text = str.str();
599
600 // Beware future maintainers: The following line of code has been carefully
601 // crafted to reach a zen-like harmony of compatibility between various
602 // compilers that have differing syntactic requirements for creating a
603 // pair containing a nullptr:
604 // - Pedantically strict C++11 compilers (e.g. MSVC 2012) will not compile:
605 // std::make_pair<double, X*>(someDouble, nullptr);

Callers 1

RenderMethod · 0.95

Calls 15

GetInputMethod · 0.95
GetRenderedDPIFunction · 0.85
backMethod · 0.80
assertFunction · 0.50
SetViewInfoMethod · 0.45
GetLinesMethod · 0.45
GetScalarsMethod · 0.45
GetPointDataMethod · 0.45
BeginMethod · 0.45
EndMethod · 0.45
insertMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected