3#include <vtkObjectFactory.h>
5#include <vtkInformation.h>
6#include <vtkInformationVector.h>
8#include <vtkSmartPointer.h>
10#include <vtkDataSet.h>
11#include <vtkImageData.h>
12#include <vtkMultiBlockDataSet.h>
13#include <vtkPointSet.h>
20 this->SetNumberOfInputPorts(1);
21 this->SetNumberOfOutputPorts(1);
28 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),
"vtkMultiBlockDataSet");
43 if(input->IsA(
"vtkImageData")) {
44 output->ShallowCopy(input);
45 }
else if(input->IsA(
"vtkPointSet")) {
46 auto outputAsPS = (vtkPointSet *)output;
47 outputAsPS->ShallowCopy(input);
50 points->DeepCopy(outputAsPS->GetPoints());
52 outputAsPS->SetPoints(points);
54 output->DeepCopy(input);
61 const size_t &colAxis,
62 const size_t &rowAxis,
65 auto inputMB = vtkMultiBlockDataSet::SafeDownCast(input);
66 auto inputAsPS = vtkPointSet::SafeDownCast(input);
67 auto inputAsID = vtkImageData::SafeDownCast(input);
70 size_t n = inputMB->GetNumberOfBlocks();
71 for(
size_t i = 0; i < n; i++)
72 if(!this->
TranslateObject(inputMB->GetBlock(i), colAxis, rowAxis, dw, dh))
75 }
else if(inputAsPS) {
76 size_t nCoords = inputAsPS->GetNumberOfPoints() * 3;
77 auto points = inputAsPS->GetPoints();
78 auto pointCoords = (
float *)points->GetVoidPointer(0);
79 for(
size_t i = 0; i < nCoords; i += 3) {
80 pointCoords[i + colAxis] += dw;
81 pointCoords[i + rowAxis] += dh;
84 }
else if(inputAsID) {
85 double origin[3] = {0, 0, 0};
88 inputAsID->SetOrigin(origin);
97 vtkInformationVector **inputVector,
98 vtkInformationVector *outputVector) {
102 auto inputMB = vtkMultiBlockDataSet::GetData(inputVector[0]);
103 auto outputMB = vtkMultiBlockDataSet::GetData(outputVector);
112 double maxHeight = 0;
114 size_t nBlocks = inputMB->GetNumberOfBlocks();
116 this->
printMsg(
"Translating " + std::to_string(nBlocks) +
" object(s)", 0,
119 for(
size_t i = 0; i < nBlocks; i++) {
120 auto block = inputMB->GetBlock(i);
121 if(block->IsA(
"vtkMultiBlockDataSet")) {
122 auto blockAsMB = vtkMultiBlockDataSet::SafeDownCast(block);
123 blockAsMB->GetBounds(bounds);
124 }
else if(block->IsA(
"vtkDataSet")) {
125 auto blockAsDS = vtkDataSet::SafeDownCast(block);
126 blockAsDS->GetBounds(bounds);
128 this->
printErr(
"Unable to determine bounding box of block #"
129 + std::to_string(i) +
" with type "
130 + std::string(block->GetClassName()) +
".");
134 double blockWidth = bounds[colAxis * 2 + 1] - bounds[colAxis * 2];
135 double blockHeight = bounds[rowAxis * 2 + 1] - bounds[rowAxis * 2];
136 if(maxWidth < blockWidth)
137 maxWidth = blockWidth;
138 if(maxHeight < blockHeight)
139 maxHeight = blockHeight;
143 maxWidth += maxWidth * this->
GetColGap() / 100.;
144 maxHeight += maxHeight * this->
GetRowGap() / 100.;
149 const size_t nColumns
150 = nRows == 0 ? std::ceil(std::sqrt(nBlocks)) : std::ceil(nBlocks / nRows);
152 for(
size_t i = 0; i < nBlocks; i++) {
154 auto block = inputMB->GetBlock(i);
159 const size_t row = std::floor(i / nColumns);
160 const size_t col = i % nColumns;
163 outBlock, colAxis, rowAxis, col * maxWidth, row * maxHeight)) {
164 this->
printErr(
"Unable to translate block #" + std::to_string(i)
165 +
" of type '" + std::string(outBlock->GetClassName())
170 outputMB->SetBlock(i, outBlock);
173 this->
printMsg(
"Translating " + std::to_string(nBlocks) +
" object(s)", 1,
#define ttkNotUsed(x)
Mark function/method parameters that are not used in the function body at all.
static vtkInformationIntegerKey * SAME_DATA_TYPE_AS_INPUT_PORT()
TTK VTK-filter that arranges vtkDataSets on a grid.
int CopyObject(vtkDataObject *output, vtkDataObject *input)
~ttkGridLayout() override
int FillInputPortInformation(int port, vtkInformation *info) override
int TranslateObject(vtkDataObject *input, const size_t &colAxis, const size_t &rowAxis, const double &dw, const double &dh)
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
int FillOutputPortInformation(int port, vtkInformation *info) override
virtual double GetRowGap()
virtual double GetColGap()
virtual int GetNumberOfRows()
void setDebugMsgPrefix(const std::string &prefix)
int printMsg(const std::string &msg, const debug::Priority &priority=debug::Priority::INFO, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cout) const
int printErr(const std::string &msg, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cerr) const
vtkStandardNewMacro(ttkGridLayout)