10 #include "vtkBoundingBox.h"
11 #include "vtkImageData.h"
12 #include "vtkInformation.h"
13 #include "vtkInformationVector.h"
15 #include "vtkObjectFactory.h"
16 #include "vtkStreamingDemandDrivenPipeline.h"
17 #include "vtkVectorOperators.h"
22 this->SetNumberOfInputPorts(0);
37 vtkInformationVector**,
38 vtkInformationVector* outputVector) {
44 vtkNew<vtkImageData> tmp;
57 vtkInformation* outInfo = outputVector->GetInformationObject(0);
58 outInfo->Set(vtkDataObject::ORIGIN(), tmp->GetOrigin(), 3);
59 outInfo->Set(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(),
61 outInfo->Set(vtkDataObject::SPACING(), tmp->GetSpacing(), 3);
62 vtkDataObject::SetPointDataActiveScalarInfo(outInfo, VTK_FLOAT, 1);
63 outInfo->Set(CAN_PRODUCE_SUB_EXTENT(), 1);
69 vtkDataObject* vtkNotUsed(odata), vtkInformation* outInfo) {
75 vtkImageData*
data = vtkImageData::GetData(outInfo);
79 vtkErrorMacro(
"Failed to determine image parameters.");
85 vtkErrorMacro(
"Failed to determine image parameters.");
92 outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_EXTENT());
93 data->SetExtent(updateExt);
98 const vtkBoundingBox& bbox,
99 const vtkVector3i& resolution) {
100 if (
image ==
nullptr || !bbox.IsValid() || resolution[0] < 1 ||
101 resolution[1] < 1 || resolution[2] < 1) {
105 image->SetExtent(0, resolution[0], 0, resolution[1], 0, resolution[2]);
108 bbox.GetLengths(lengths.GetData());
114 const vtkVector3d resolutionD(
static_cast<double>(resolution[0]),
115 static_cast<double>(resolution[1]),
116 static_cast<double>(resolution[2]));
117 vtkVector3d spacing = lengths / resolutionD;
118 image->SetSpacing(spacing.GetData());
124 const vtkBoundingBox& bbox,
125 const double cellSize) {
126 if (
image ==
nullptr || !bbox.IsValid() || cellSize <= 0) {
131 bbox.GetLengths(lengths.GetData());
133 vtkVector3i resolution;
134 resolution[0] =
static_cast<int>(
std::ceil(lengths[0] / cellSize));
135 resolution[1] =
static_cast<int>(
std::ceil(lengths[1] / cellSize));
136 resolution[2] =
static_cast<int>(
std::ceil(lengths[2] / cellSize));
137 assert(resolution[0] > 0 && resolution[1] > 0 && resolution[2] > 0);
139 image->SetExtent(0, resolution[0], 0, resolution[1], 0, resolution[2]);
144 bbox.GetCenter(center.GetData());
146 lengths[0] = resolution[0] * cellSize;
147 lengths[1] = resolution[1] * cellSize;
148 lengths[2] = resolution[2] * cellSize;
149 vtkVector3d
origin = center - (lengths / vtkVector3d(2.0));
151 image->SetSpacing(cellSize, cellSize, cellSize);
157 this->Superclass::PrintSelf(os, indent);
158 os << indent <<
"Origin: " << this->
Origin[0] <<
", " << this->
Origin[1]
160 os << indent <<
"Scale: " << this->
Scale[0] <<
", " << this->
Scale[1]
163 os << indent <<
"Resolution: " << this->
Resolution[0] <<
", "
std::shared_ptr< core::Tensor > image
int RequestInformation(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
void ExecuteDataWithInformation(vtkDataObject *data, vtkInformation *outInfo) override
~vtkBoundedVolumeSource() override
void PrintSelf(ostream &os, vtkIndent indent) override
static bool SetImageParameters(vtkImageData *image, const vtkBoundingBox &bbox, const vtkVector3i &resolution)
QTextStream & endl(QTextStream &stream)
MiniVec< float, N > ceil(const MiniVec< float, N > &a)
vtkStandardNewMacro(vtkBoundedVolumeSource)