File: vtkImageDataOutlineFilter.cxx

package info (click to toggle)
vtk9 9.5.2%2Bdfsg3-6
  • links: PTS, VCS
  • area: main
  • in suites: 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 (212 lines) | stat: -rw-r--r-- 6,124 bytes parent folder | download | duplicates (5)
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
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
#include "vtkImageDataOutlineFilter.h"

#include "vtkCompositeDataIterator.h"
#include "vtkCompositeDataSet.h"
#include "vtkDataObjectTreeIterator.h"
#include "vtkDataSet.h"
#include "vtkImageData.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkNew.h"
#include "vtkPolyData.h"

VTK_ABI_NAMESPACE_BEGIN
vtkStandardNewMacro(vtkImageDataOutlineFilter);

//------------------------------------------------------------------------------
vtkImageDataOutlineFilter::vtkImageDataOutlineFilter()
{
  this->GenerateFaces = 0;
  this->OutputPointsPrecision = SINGLE_PRECISION;
}

//------------------------------------------------------------------------------
vtkImageDataOutlineFilter::~vtkImageDataOutlineFilter() = default;

//------------------------------------------------------------------------------
// Core method to produce an oriented vtkImageData outline.
namespace
{

void ProduceOutline(vtkImageData* input, vtkTypeBool genFaces, vtkPoints* points,
  vtkCellArray* lines, vtkCellArray* faces)
{
  // Keep track of inserted point ids
  vtkIdType ptIds[8];

  // Produce the eight vtkImageData points, possibly oriented. Use the
  // corner indices of the volume.
  double x[3];
  int ext[6];
  input->GetExtent(ext);

  input->TransformIndexToPhysicalPoint(ext[0], ext[2], ext[4], x);
  ptIds[0] = points->InsertNextPoint(x);

  input->TransformIndexToPhysicalPoint(ext[1], ext[2], ext[4], x);
  ptIds[1] = points->InsertNextPoint(x);

  input->TransformIndexToPhysicalPoint(ext[0], ext[3], ext[4], x);
  ptIds[2] = points->InsertNextPoint(x);

  input->TransformIndexToPhysicalPoint(ext[1], ext[3], ext[4], x);
  ptIds[3] = points->InsertNextPoint(x);

  input->TransformIndexToPhysicalPoint(ext[0], ext[2], ext[5], x);
  ptIds[4] = points->InsertNextPoint(x);

  input->TransformIndexToPhysicalPoint(ext[1], ext[2], ext[5], x);
  ptIds[5] = points->InsertNextPoint(x);

  input->TransformIndexToPhysicalPoint(ext[0], ext[3], ext[5], x);
  ptIds[6] = points->InsertNextPoint(x);

  input->TransformIndexToPhysicalPoint(ext[1], ext[3], ext[5], x);
  ptIds[7] = points->InsertNextPoint(x);

  // Produce topology, lines plus optional quad faces
  vtkIdType pts[4];

  // Always generate wire edges. This is a historical behavior.
  pts[0] = ptIds[0];
  pts[1] = ptIds[1];
  lines->InsertNextCell(2, pts);
  pts[0] = ptIds[2];
  pts[1] = ptIds[3];
  lines->InsertNextCell(2, pts);
  pts[0] = ptIds[4];
  pts[1] = ptIds[5];
  lines->InsertNextCell(2, pts);
  pts[0] = ptIds[6];
  pts[1] = ptIds[7];
  lines->InsertNextCell(2, pts);
  pts[0] = ptIds[0];
  pts[1] = ptIds[2];
  lines->InsertNextCell(2, pts);
  pts[0] = ptIds[1];
  pts[1] = ptIds[3];
  lines->InsertNextCell(2, pts);
  pts[0] = ptIds[4];
  pts[1] = ptIds[6];
  lines->InsertNextCell(2, pts);
  pts[0] = ptIds[5];
  pts[1] = ptIds[7];
  lines->InsertNextCell(2, pts);
  pts[0] = ptIds[0];
  pts[1] = ptIds[4];
  lines->InsertNextCell(2, pts);
  pts[0] = ptIds[1];
  pts[1] = ptIds[5];
  lines->InsertNextCell(2, pts);
  pts[0] = ptIds[2];
  pts[1] = ptIds[6];
  lines->InsertNextCell(2, pts);
  pts[0] = ptIds[3];
  pts[1] = ptIds[7];
  lines->InsertNextCell(2, pts);

  if (genFaces)
  {
    pts[0] = ptIds[1];
    pts[1] = ptIds[0];
    pts[2] = ptIds[2];
    pts[3] = ptIds[3];
    faces->InsertNextCell(4, pts);
    pts[0] = ptIds[0];
    pts[1] = ptIds[1];
    pts[2] = ptIds[5];
    pts[3] = ptIds[4];
    faces->InsertNextCell(4, pts);
    pts[0] = ptIds[2];
    pts[1] = ptIds[0];
    pts[2] = ptIds[4];
    pts[3] = ptIds[6];
    faces->InsertNextCell(4, pts);
    pts[0] = ptIds[3];
    pts[1] = ptIds[2];
    pts[2] = ptIds[6];
    pts[3] = ptIds[7];
    faces->InsertNextCell(4, pts);
    pts[0] = ptIds[1];
    pts[1] = ptIds[3];
    pts[2] = ptIds[7];
    pts[3] = ptIds[5];
    faces->InsertNextCell(4, pts);
    pts[0] = ptIds[7];
    pts[1] = ptIds[6];
    pts[2] = ptIds[4];
    pts[3] = ptIds[5];
    faces->InsertNextCell(4, pts);
  }
}

} // anonymous

//------------------------------------------------------------------------------
int vtkImageDataOutlineFilter::RequestData(vtkInformation* vtkNotUsed(request),
  vtkInformationVector** inputVector, vtkInformationVector* outputVector)
{
  // get the info objects
  vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
  vtkInformation* outInfo = outputVector->GetInformationObject(0);

  // get the input and output. Differentiate between composite and typical datasets.
  vtkImageData* input = vtkImageData::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
  if (input == nullptr)
  {
    vtkErrorMacro(<< "Invalid or missing input");
    return 0;
  }
  vtkPolyData* output = vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));

  vtkDebugMacro(<< "Creating outline");

  // Set the desired precision for the points in the output.
  vtkNew<vtkPoints> pts;
  if (this->OutputPointsPrecision == vtkAlgorithm::DOUBLE_PRECISION)
  {
    pts->SetDataType(VTK_DOUBLE);
  }
  else
  {
    pts->SetDataType(VTK_FLOAT);
  }

  vtkNew<vtkCellArray> lines;
  vtkNew<vtkCellArray> faces;

  // Generate the outline
  ProduceOutline(input, this->GenerateFaces, pts, lines, faces);

  // Define output
  output->SetPoints(pts);
  output->SetLines(lines);

  if (this->GenerateFaces)
  {
    output->SetPolys(faces);
  }

  this->CheckAbort();

  return 1;
}

//------------------------------------------------------------------------------
int vtkImageDataOutlineFilter::FillInputPortInformation(int, vtkInformation* info)
{
  info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkImageData");
  return 1;
}

//------------------------------------------------------------------------------
void vtkImageDataOutlineFilter::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);

  os << indent << "Generate Faces: " << (this->GenerateFaces ? "On\n" : "Off\n");
  os << indent << "Output Points Precision: " << this->OutputPointsPrecision << "\n";
}
VTK_ABI_NAMESPACE_END