Compare commits

..

No commits in common. "5ad9c708256dd629353b26b07e5e51933001e4b9" and "340cdbd7ed2b41baa14621c89707edcd30010979" have entirely different histories.

2 changed files with 4 additions and 15 deletions

View File

@ -1,30 +1,18 @@
#include "aspect_ratio_filter.h" #include "aspect_ratio_filter.h"
#include "vtkDataObject.h"
#include <vtkUnstructuredGrid.h> #include <vtkUnstructuredGrid.h>
#include <vtkPointData.h> #include <vtkPointData.h>
#include <vtkCellData.h> #include <vtkCellData.h>
#include <vtkDoubleArray.h> #include <vtkDoubleArray.h>
#include <vtkCellIterator.h> #include <vtkCellIterator.h>
#include <vtkInformation.h>
#include <vtkInformationVector.h>
vtkStandardNewMacro(AspectRatioFilter); vtkStandardNewMacro(AspectRatioFilter);
// Ensure there is an "angles", 12 floats tuple array in the DataCell.
int AspectRatioFilter::FillInputPortInformation(int port, vtkInformation *info) { int AspectRatioFilter::FillInputPortInformation(int port, vtkInformation *info) {
vtkUnstructuredGridAlgorithm::FillInputPortInformation(port, info); vtkUnstructuredGridAlgorithm::FillInputPortInformation(port, info);
vtkNew<vtkInformation> anglesField; // Ensure there is an "angles" array in the DataCell.
anglesField->Set(vtkDataObject::FIELD_ASSOCIATION(), vtkDataObject::FIELD_ASSOCIATION_CELLS);
anglesField->Set(vtkDataObject::FIELD_NAME(), "angles");
anglesField->Set(vtkDataObject::FIELD_NUMBER_OF_COMPONENTS(), 12);
anglesField->Set(vtkDataObject::FIELD_ARRAY_TYPE(), VTK_DOUBLE);
vtkNew<vtkInformationVector> fields;
fields->Append(anglesField);
info->Set(vtkAlgorithm::INPUT_REQUIRED_FIELDS(), fields);
return 1; return 1;
} }

View File

@ -14,6 +14,7 @@
#include <vtkOpenGLProjectedTetrahedraMapper.h> #include <vtkOpenGLProjectedTetrahedraMapper.h>
#include <vtkUnstructuredGridReader.h> #include <vtkUnstructuredGridReader.h>
#include <vtkPiecewiseFunction.h> #include <vtkPiecewiseFunction.h>
#include <vtkDoubleArray.h>
#include <array> #include <array>
#include <vector> #include <vector>
@ -59,7 +60,7 @@ int main(int argc, char **argv) {
/* Display angles in console. */ /* Display angles in console. */
anglesFilter->Update(); anglesFilter->Update();
vtkUnstructuredGrid *grid = anglesFilter->GetOutput(); vtkUnstructuredGrid *grid = anglesFilter->GetOutput();
auto *angles = grid->GetCellData()->GetArray("angles"); auto *angles = vtkDoubleArray::SafeDownCast(grid->GetCellData()->GetArray("angles"));
for (ssize_t i = 0; i < angles->GetNumberOfTuples(); i++) { for (ssize_t i = 0; i < angles->GetNumberOfTuples(); i++) {
std::cout << "cell " << i << ": "; std::cout << "cell " << i << ": ";
for (ssize_t j = 0; j < angles->GetNumberOfComponents(); j++) { for (ssize_t j = 0; j < angles->GetNumberOfComponents(); j++) {
@ -75,7 +76,7 @@ int main(int argc, char **argv) {
/* Display aspect ratios in console. */ /* Display aspect ratios in console. */
aspectRatioFilter->Update(); aspectRatioFilter->Update();
grid = aspectRatioFilter->GetOutput(); grid = aspectRatioFilter->GetOutput();
auto *aspectRatios = grid->GetCellData()->GetArray("aspect_ratio"); auto *aspectRatios = vtkDoubleArray::SafeDownCast(grid->GetCellData()->GetArray("aspect_ratio"));
for (ssize_t i = 0; i < aspectRatios->GetNumberOfTuples(); i++) { for (ssize_t i = 0; i < aspectRatios->GetNumberOfTuples(); i++) {
std::cout << "cell " << i << ": " std::cout << "cell " << i << ": "
<< aspectRatios->GetTuple1(i) << "\n"; << aspectRatios->GetTuple1(i) << "\n";