File: vtkContextDevice2D.cxx

package info (click to toggle)
paraview 5.11.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 497,236 kB
  • sloc: cpp: 3,171,290; ansic: 1,315,072; python: 134,290; xml: 103,324; sql: 65,887; sh: 5,286; javascript: 4,901; yacc: 4,383; java: 3,977; perl: 2,363; lex: 1,909; f90: 1,255; objc: 143; makefile: 119; tcl: 59; pascal: 50; fortran: 29
file content (195 lines) | stat: -rw-r--r-- 5,983 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkContextDevice2D.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/

#include "vtkContextDevice2D.h"
#include "vtkAbstractMapper.h" // for VTK_SCALAR_MODE defines
#include "vtkBrush.h"
#include "vtkCellIterator.h"
#include "vtkMathTextUtilities.h"
#include "vtkPen.h"
#include "vtkPolyData.h"
#include "vtkRect.h"
#include "vtkTextProperty.h"
#include "vtkUnsignedCharArray.h"

#include "vtkObjectFactory.h"
#include <cassert>
#include <vector>

VTK_ABI_NAMESPACE_BEGIN
vtkAbstractObjectFactoryNewMacro(vtkContextDevice2D);

vtkContextDevice2D::vtkContextDevice2D()
{
  this->Geometry[0] = 0;
  this->Geometry[1] = 0;
  this->BufferId = nullptr;
  this->Pen = vtkPen::New();
  this->Brush = vtkBrush::New();
  this->TextProp = vtkTextProperty::New();
}

//------------------------------------------------------------------------------
vtkContextDevice2D::~vtkContextDevice2D()
{
  this->Pen->Delete();
  this->Brush->Delete();
  this->TextProp->Delete();
}

//------------------------------------------------------------------------------
bool vtkContextDevice2D::MathTextIsSupported()
{
  return vtkMathTextUtilities::GetInstance() != nullptr;
}

//------------------------------------------------------------------------------
void vtkContextDevice2D::DrawPolyData(
  float p[2], float scale, vtkPolyData* polyData, vtkUnsignedCharArray* colors, int scalarMode)
{
  std::vector<float> verts;
  std::vector<unsigned char> vertColors;

  vtkCellIterator* cell = polyData->NewCellIterator();
  cell->InitTraversal();
  for (; !cell->IsDoneWithTraversal(); cell->GoToNextCell())
  {
    // To match the original implementation on the OpenGL2 backend, we only
    // handle polygons and lines:
    int cellType = cell->GetCellType();
    switch (cellType)
    {
      case VTK_LINE:
      case VTK_POLY_LINE:
      case VTK_TRIANGLE:
      case VTK_QUAD:
      case VTK_POLYGON:
        break;

      default:
        continue;
    }

    // Allocate temporary arrays:
    vtkIdType numPoints = cell->GetNumberOfPoints();
    if (numPoints == 0)
    {
      continue;
    }
    verts.resize(static_cast<size_t>(numPoints) * 2);
    vertColors.resize(static_cast<size_t>(numPoints) * 4);

    vtkIdType cellId = cell->GetCellId();
    vtkIdList* pointIds = cell->GetPointIds();
    vtkPoints* points = cell->GetPoints();

    for (vtkIdType i = 0; i < numPoints; ++i)
    {
      const size_t vertsIdx = 2 * static_cast<size_t>(i);
      const size_t colorIdx = 4 * static_cast<size_t>(i);

      const double* point = points->GetPoint(i);
      verts[vertsIdx] = (static_cast<float>(point[0]) + p[0]) * scale;
      verts[vertsIdx + 1] = (static_cast<float>(point[1]) + p[1]) * scale;

      if (scalarMode == VTK_SCALAR_MODE_USE_POINT_DATA)
      {
        colors->GetTypedTuple(pointIds->GetId(i), vertColors.data() + colorIdx);
      }
      else
      {
        colors->GetTypedTuple(cellId, vertColors.data() + colorIdx);
      }
    }

    if (cellType == VTK_LINE || cellType == VTK_POLY_LINE)
    {
      this->DrawPoly(verts.data(), numPoints, vertColors.data(), 4);
    }
    else
    {
      this->DrawColoredPolygon(verts.data(), numPoints, vertColors.data(), 4);
    }
  }
  cell->Delete();
}

//------------------------------------------------------------------------------
void vtkContextDevice2D::ApplyPen(vtkPen* pen)
{
  this->Pen->DeepCopy(pen);
}

//------------------------------------------------------------------------------
void vtkContextDevice2D::ApplyBrush(vtkBrush* brush)
{
  this->Brush->DeepCopy(brush);
}

//------------------------------------------------------------------------------
void vtkContextDevice2D::ApplyTextProp(vtkTextProperty* prop)
{
  // This is a deep copy, but is called shallow for some reason...
  this->TextProp->ShallowCopy(prop);
}

//------------------------------------------------------------------------------
bool vtkContextDevice2D::GetBufferIdMode() const
{
  return this->BufferId != nullptr;
}

//------------------------------------------------------------------------------
void vtkContextDevice2D::BufferIdModeBegin(vtkAbstractContextBufferId* bufferId)
{
  assert("pre: not_yet" && !this->GetBufferIdMode());
  assert("pre: bufferId_exists" && bufferId != nullptr);

  this->BufferId = bufferId;

  assert("post: started" && this->GetBufferIdMode());
}

//------------------------------------------------------------------------------
void vtkContextDevice2D::BufferIdModeEnd()
{
  assert("pre: started" && this->GetBufferIdMode());

  this->BufferId = nullptr;

  assert("post: done" && !this->GetBufferIdMode());
}

//------------------------------------------------------------------------------
void vtkContextDevice2D::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
  os << indent << "Pen: ";
  this->Pen->PrintSelf(os, indent.GetNextIndent());
  os << indent << "Brush: ";
  this->Brush->PrintSelf(os, indent.GetNextIndent());
  os << indent << "Text Property: ";
  this->TextProp->PrintSelf(os, indent.GetNextIndent());
}

//------------------------------------------------------------------------------
void vtkContextDevice2D::DrawMarkers(int, bool, float*, int, unsigned char*, int) {}

//------------------------------------------------------------------------------
void vtkContextDevice2D::DrawColoredPolygon(float*, int, unsigned char*, int)
{
  vtkErrorMacro("DrawColoredPolygon not implemented on this device.");
}
VTK_ABI_NAMESPACE_END