File: vtkCellGridRangeQuery.cxx

package info (click to toggle)
vtk9 9.5.2%2Bdfsg3-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 205,984 kB
  • sloc: cpp: 2,336,570; ansic: 327,116; python: 111,200; yacc: 4,104; java: 3,977; sh: 3,032; xml: 2,771; perl: 2,189; lex: 1,787; makefile: 181; javascript: 165; objc: 153; tcl: 59
file content (180 lines) | stat: -rw-r--r-- 4,821 bytes parent folder | download | duplicates (2)
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
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
#include "vtkCellGridRangeQuery.h"

#include "vtkBoundingBox.h"
#include "vtkCellGrid.h"
#include "vtkMath.h"
#include "vtkObjectFactory.h"

#include <algorithm>

VTK_ABI_NAMESPACE_BEGIN

vtkStandardNewMacro(vtkCellGridRangeQuery);
vtkCxxSetObjectMacro(vtkCellGridRangeQuery, CellGrid, vtkCellGrid);

vtkCellGridRangeQuery::~vtkCellGridRangeQuery()
{
  this->SetCellAttribute(nullptr);
  this->SetCellGrid(nullptr);
}

void vtkCellGridRangeQuery::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
  os << indent << "Component: " << this->Component << "\n";
  os << indent << "FiniteRange: " << (this->FiniteRange ? "ON" : "OFF") << "\n";
  os << indent << "CellGrid: " << this->CellGrid << "\n";
  os << indent << "CellAttribute: " << this->CellAttribute << "\n";
  os << indent << "Ranges:\n";
  vtkIndent i2 = indent.GetNextIndent();
  int cc = -2;
  for (const auto& range : this->Ranges)
  {
    os << i2;
    if (cc == -2)
    {
      os << "L₂-norm";
    }
    else if (cc == -1)
    {
      os << "L₁-norm";
    }
    else
    {
      os << "Component " << cc;
    }
    os << ": " << range[0] << " " << range[1] << "\n";
    ++cc;
  }
}

bool vtkCellGridRangeQuery::Initialize()
{
  bool ok = this->Superclass::Initialize();
  if (!this->CellAttribute)
  {
    vtkErrorMacro("No attribute provided for range computation.");
    return false;
  }
  // Allocate space for all components plus L₁ and L₂ norms.
  this->Ranges.resize(this->CellAttribute->GetNumberOfComponents() + 2);
  // Invalidate the range each time we run.
  for (auto& range : this->Ranges)
  {
    range[0] = vtkMath::Inf();
    range[1] = -vtkMath::Inf();
  }
  return ok;
}

bool vtkCellGridRangeQuery::Finalize()
{
  if (this->CellGrid && this->CellAttribute)
  {
    // Always overwrite the requested component:
    if (this->FiniteRange)
    {
      this->CellGrid->GetRangeCache()[this->CellAttribute][this->Component + 2].FiniteRange =
        this->Ranges[this->Component + 2];
      this->CellGrid->GetRangeCache()[this->CellAttribute][this->Component + 2]
        .FiniteRangeTime.Modified();
    }
    else
    {
      this->CellGrid->GetRangeCache()[this->CellAttribute][this->Component + 2].EntireRange =
        this->Ranges[this->Component + 2];
      this->CellGrid->GetRangeCache()[this->CellAttribute][this->Component + 2]
        .EntireRangeTime.Modified();
    }
    // If any other components have a valid range, copy them as well.
    // (Some range responders may choose to process all components of an array
    // at once instead of individually.)
    int cc = -2;
    for (auto& range : this->Ranges)
    {
      if (range[1] >= range[0])
      {
        if (this->FiniteRange)
        {
          this->CellGrid->GetRangeCache()[this->CellAttribute][cc + 2].FiniteRange = range;
          this->CellGrid->GetRangeCache()[this->CellAttribute][cc + 2].FiniteRangeTime.Modified();
        }
        else
        {
          this->CellGrid->GetRangeCache()[this->CellAttribute][cc + 2].EntireRange = range;
          this->CellGrid->GetRangeCache()[this->CellAttribute][cc + 2].EntireRangeTime.Modified();
        }
      }
      ++cc;
    }
  }
  return true;
}

void vtkCellGridRangeQuery::GetRange(int component, double* bds)
{
  if (!bds)
  {
    return;
  }

  if (component < -2 || component >= this->CellAttribute->GetNumberOfComponents())
  {
    // Provide an invalid range.
    bds[0] = 1;
    bds[1] = 0;
    return;
  }

  std::copy(this->Ranges[component].begin(), this->Ranges[component].end(), bds);
}

const std::array<double, 2>& vtkCellGridRangeQuery::GetRange(int component) const
{
  static const std::array<double, 2> invalid{ 1, 0 };
  if (component < -2 || component >= this->CellAttribute->GetNumberOfComponents())
  {
    return invalid;
  }
  return this->Ranges[component + 2];
}

void vtkCellGridRangeQuery::AddRange(const std::array<double, 2>& range)
{
  this->AddRange(this->Component, range);
}

void vtkCellGridRangeQuery::AddRange(int component, const std::array<double, 2>& range)
{
  // Ignore invalid ranges:
  if (range[1] < range[0])
  {
    return;
  }

  // Ignore invalid components:
  if (component < -2 || component >= this->CellAttribute->GetNumberOfComponents())
  {
    return;
  }

  // If this->Range is invalid, just copy the \a range.
  if (this->Ranges[component + 2][1] < this->Ranges[component + 2][0])
  {
    this->Ranges[component + 2] = range;
    return;
  }

  if (this->Ranges[component + 2][0] > range[0])
  {
    this->Ranges[component + 2][0] = range[0];
  }
  if (this->Ranges[component + 2][1] < range[1])
  {
    this->Ranges[component + 2][1] = range[1];
  }
}

VTK_ABI_NAMESPACE_END