File: vtkCellGridSidesQuery.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 (215 lines) | stat: -rw-r--r-- 5,435 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
#include "vtkCellGridSidesQuery.h"

#include "vtkBoundingBox.h"
#include "vtkCellGridSidesCache.h"
#include "vtkIdTypeArray.h"
#include "vtkMath.h"
#include "vtkObjectFactory.h"

#include <array>
#include <sstream>

VTK_ABI_NAMESPACE_BEGIN

using namespace vtk::literals;

vtkStandardNewMacro(vtkCellGridSidesQuery);

vtkCellGridSidesQuery::~vtkCellGridSidesQuery()
{
  this->SetSideCache(nullptr);
}

void vtkCellGridSidesQuery::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
  os << indent << "SideCache: " << this->SideCache << "\n";
  os << indent << "Sides: " << this->Sides.size() << "\n";
  os << indent << "PreserveRenderableInputs: " << (this->PreserveRenderableInputs ? "Y" : "N")
     << "\n";
  os << indent
     << "OmitSidesForRenderableInputs: " << (this->OmitSidesForRenderableInputs ? "Y" : "N")
     << "\n";
  os << indent << "OutputDimensionControl: " << std::hex << this->OutputDimensionControl << std::dec
     << "\n";
  os << indent
     << "SelectionType: " << vtkCellGridSidesQuery::SelectionModeToLabel(this->SelectionType).Data()
     << "\n";
  os << indent
     << "SummaryStrategy: " << vtkCellGridSidesQuery::SummaryStrategyToLabel(this->Strategy).Data()
     << "\n";
}

bool vtkCellGridSidesQuery::Initialize()
{
  bool ok = this->Superclass::Initialize(); // Reset Pass number.
  // If we don't have a side-cache, make one as responders should be able to
  // assume it exists. But warn if we have to create one; this is really the
  // job of the filter.
  if (!this->SideCache)
  {
    this->TemporarySideCache = true;
    auto* sideCache = vtkCellGridSidesCache::New();
    this->SideCache = sideCache;
    vtkWarningMacro("No side cache was provided; creating a temporary.");
  }
  else
  {
    // If the cache is older than the query, reset the cache.
    // Otherwise, allow responders to skip hashing their sides.
    if (this->GetMTime() > this->SideCache->GetMTime())
    {
      this->SideCache->Initialize();
    }
  }

  return ok;
}

void vtkCellGridSidesQuery::StartPass()
{
  this->vtkCellGridQuery::StartPass();
  auto work = static_cast<PassWork>(this->Pass);
  switch (work)
  {
    case PassWork::HashSides:
    case PassWork::GenerateSideSets:
      // No work to do.
      break;
    case PassWork::Summarize:
      this->Sides.clear();
      break;
  }
}

bool vtkCellGridSidesQuery::IsAnotherPassRequired()
{
  return this->Pass < PassWork::GenerateSideSets;
}

bool vtkCellGridSidesQuery::Finalize()
{
  this->Sides.clear();
  if (this->TemporarySideCache)
  {
    this->SideCache->Delete();
    this->SideCache = nullptr;
  }
  return true;
}

std::vector<vtkCellGridSidesQuery::SideSetArray> vtkCellGridSidesQuery::GetSideSetArrays(
  vtkStringToken cellType)
{
  std::vector<SideSetArray> result;
  auto cellTypeIt = this->Sides.find(cellType);
  if (cellTypeIt == this->Sides.end())
  {
    return result;
  }

  for (const auto& sideShapeEntry : cellTypeIt->second)
  {
    vtkIdType sideCount = 0;
    for (const auto& entry : sideShapeEntry.second)
    {
      sideCount += entry.second.size();
    }
    auto sideArray = vtkSmartPointer<vtkIdTypeArray>::New();
    sideArray->SetName("conn");
    sideArray->SetNumberOfComponents(2); // tuples are (cell ID, side ID)
    sideArray->SetNumberOfTuples(sideCount);
    vtkIdType sideId = 0;
    std::array<vtkIdType, 2> sideTuple;
    for (const auto& entry : sideShapeEntry.second)
    {
      sideTuple[0] = entry.first;
      for (const auto& ss : entry.second)
      {
        sideTuple[1] = ss;
        sideArray->SetTypedTuple(sideId, sideTuple.data());
        ++sideId;
      }
    }
    result.push_back({ cellTypeIt->first, sideShapeEntry.first, sideArray });
  }

  return result;
}

vtkStringToken vtkCellGridSidesQuery::SelectionModeToLabel(SelectionMode mode)
{
  switch (mode)
  {
    default:
    case SelectionMode::Input:
      return "Input";
    case SelectionMode::Output:
      return "Output";
  }
}

vtkCellGridSidesQuery::SelectionMode vtkCellGridSidesQuery::SelectionModeFromLabel(
  vtkStringToken token)
{
  switch (token.GetId())
  {
    default:
    case "Input"_hash:
      return SelectionMode::Input;
    case "Output"_hash:
      return SelectionMode::Output;
  }
}

vtkStringToken vtkCellGridSidesQuery::SummaryStrategyToLabel(SummaryStrategy strategy)
{
  switch (strategy)
  {
    case SummaryStrategy::Winding:
      return "Winding";
    case SummaryStrategy::AnyOccurrence:
      return "AnyOccurrence";
    default:
    case SummaryStrategy::Boundary:
      return "Boundary";
  }
}

vtkCellGridSidesQuery::SummaryStrategy vtkCellGridSidesQuery::SummaryStrategyFromLabel(
  vtkStringToken token)
{
  switch (token.GetId())
  {
    case "Winding"_hash:
      return SummaryStrategy::Winding;
    case "AnyOccurrence"_hash:
      return SummaryStrategy::AnyOccurrence;
    default:
    case "Boundary"_hash:
      return SummaryStrategy::Boundary;
  }
}

void vtkCellGridSidesQuery::SetSideCache(vtkCellGridSidesCache* cache)
{
  if (this->SideCache == cache)
  {
    return;
  }
  if (this->SideCache)
  {
    this->SideCache->Delete();
  }
  this->SideCache = cache;
  this->TemporarySideCache = !cache;
  if (this->SideCache)
  {
    this->SideCache->Register(this);
  }
  this->Modified();
}

VTK_ABI_NAMESPACE_END