ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
vtkBoundedPlaneSource.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
9 
10 #include "vtkBoundedVolumeSource.h"
11 #include "vtkBoundingBox.h"
12 #include "vtkFlyingEdgesPlaneCutter.h"
13 #include "vtkImageData.h"
14 #include "vtkNew.h"
15 #include "vtkObjectFactory.h"
16 #include "vtkPlane.h"
17 #include "vtkPolyData.h"
18 #include "vtkVector.h"
19 
21 //----------------------------------------------------------------------------
23  this->SetNumberOfInputPorts(0);
24  this->SetNumberOfOutputPorts(1);
25 
26  this->Center[0] = this->Center[1] = this->Center[2] = 0.0;
27  this->Normal[0] = this->Normal[1] = 0.0;
28  this->Normal[1] = 1.0;
29  this->Resolution = 100;
31  this->CellSize = 1.0;
32  this->Padding = 0;
33 }
34 
35 //----------------------------------------------------------------------------
37 
38 //----------------------------------------------------------------------------
40  vtkInformationVector**,
41  vtkInformationVector* outputVector) {
42  vtkPolyData* output = vtkPolyData::GetData(outputVector, 0);
43 
44  vtkBoundingBox bbox(this->BoundingBox);
45  bbox.Inflate(this->Padding);
46  if (!bbox.IsValid()) {
47  vtkErrorMacro(
48  "Invalid bounding box specified. Please choose a valid "
49  "BoundingBox.");
50  return 0;
51  }
52 
53  vtkNew<vtkImageData> image;
54 
55  if (this->RefinementMode == USE_RESOLUTION) {
57  image, bbox, vtkVector3i(this->Resolution))) {
58  vtkErrorMacro("Failed to determine image parameters.");
59  return 0;
60  }
61  } else {
63  this->CellSize)) {
64  vtkErrorMacro("Failed to determine image parameters.");
65  return 0;
66  }
67  }
68 
69  // AllocateScalars, alas, is needed since vtkFlyingEdgesPlaneCutter cannot
70  // work without scalars.
71  image->AllocateScalars(VTK_CHAR, 1);
72 
73  vtkNew<vtkPlane> plane;
74  plane->SetOrigin(this->Center);
75  plane->SetNormal(this->Normal);
76 
77  vtkNew<vtkFlyingEdgesPlaneCutter> cutter;
78  cutter->SetPlane(plane.Get());
79  cutter->SetInputDataObject(image.Get());
80  cutter->ComputeNormalsOff();
81  cutter->InterpolateAttributesOff();
82  cutter->Update();
83  output->CopyStructure(cutter->GetOutput(0));
84  return 1;
85 }
86 
87 //----------------------------------------------------------------------------
88 void vtkBoundedPlaneSource::PrintSelf(ostream& os, vtkIndent indent) {
89  this->Superclass::PrintSelf(os, indent);
90  os << indent << "Center: " << this->Center[0] << ", " << this->Center[1]
91  << ", " << this->Center[2] << endl;
92  os << indent << "Normal: " << this->Normal[0] << ", " << this->Normal[1]
93  << ", " << this->Normal[2] << endl;
94  os << indent << "BoundingBox: " << this->BoundingBox[0] << ", "
95  << this->BoundingBox[1] << ", " << this->BoundingBox[2] << ", "
96  << this->BoundingBox[3] << ", " << this->BoundingBox[4] << ", "
97  << this->BoundingBox[5] << endl;
98  os << indent << "RefinementMode: " << this->RefinementMode << endl;
99  os << indent << "Resolution: " << this->Resolution << endl;
100  os << indent << "CellSize: " << this->CellSize << endl;
101  os << indent << "Padding: " << this->Padding << endl;
102 }
std::shared_ptr< core::Tensor > image
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
void PrintSelf(ostream &os, vtkIndent indent) override
static bool SetImageParameters(vtkImageData *image, const vtkBoundingBox &bbox, const vtkVector3i &resolution)
QTextStream & endl(QTextStream &stream)
Definition: QtCompat.h:718
vtkStandardNewMacro(vtkBoundedPlaneSource)