diff --git a/Documentation/release/dev/add-vtkAttributeDataToTableFilter.md b/Documentation/release/dev/add-vtkAttributeDataToTableFilter.md new file mode 100644 index 0000000000000000000000000000000000000000..e3fc9ac59c35bdc4a6c82020edaa7a81c0d5fb0c --- /dev/null +++ b/Documentation/release/dev/add-vtkAttributeDataToTableFilter.md @@ -0,0 +1,7 @@ +## Move `vtkAttributeDataToTableFilter` from ParaView to VTK + +The `vtkAttributeDataToTableFilter` is now available in VTK. It used to be in the `VTKExtensions` of the ParaView repository. It serves to turn a data object into a table by shallow copying its attributes into row data. + +Seeing as the `vtkAttributeDataToTableFilter` does the same thing as `vtkDataObjectToTable` filter with some added functionnality, **the `vtkDataObjectToTable` filter has been deprecated**. + +Support for `vtkHyperTreeGrid` has also been trivially added to the `vtkAttributeDataToTableFilter`. diff --git a/Examples/GUI/Qt/SimpleView/SimpleView.cxx b/Examples/GUI/Qt/SimpleView/SimpleView.cxx index f3284899673c416fdd0c54ba5d78875cdd0ac8e3..d06411bbb2db90f43a777699f9c3d82731ec27c8 100644 --- a/Examples/GUI/Qt/SimpleView/SimpleView.cxx +++ b/Examples/GUI/Qt/SimpleView/SimpleView.cxx @@ -12,7 +12,7 @@ #include "vtkGenericOpenGLRenderWindow.h" #include "vtkSmartPointer.h" -#include <vtkDataObjectToTable.h> +#include <vtkAttributeDataToTableFilter.h> #include <vtkElevationFilter.h> #include <vtkNew.h> #include <vtkPolyDataMapper.h> @@ -62,9 +62,9 @@ SimpleView::SimpleView() // Just a bit of Qt interest: Culling off the // point data and handing it to a vtkQtTableView - vtkNew<vtkDataObjectToTable> toTable; + vtkNew<vtkAttributeDataToTableFilter> toTable; toTable->SetInputConnection(elevation->GetOutputPort()); - toTable->SetFieldType(vtkDataObjectToTable::POINT_DATA); + toTable->SetFieldAssociation(vtkDataObject::FIELD_ASSOCIATION_POINTS); // Here we take the end of the VTK pipeline and give it to a Qt View this->TableView->SetRepresentationFromInputConnection(toTable->GetOutputPort()); diff --git a/Examples/Infovis/Cxx/CustomLinkView/CustomLinkView.cxx b/Examples/Infovis/Cxx/CustomLinkView/CustomLinkView.cxx index db8b590c5f9412d5fa5077ac983161e5069919b6..5a8ab195c622df2cb512827a5049f6cb8cada42f 100644 --- a/Examples/Infovis/Cxx/CustomLinkView/CustomLinkView.cxx +++ b/Examples/Infovis/Cxx/CustomLinkView/CustomLinkView.cxx @@ -9,8 +9,8 @@ #include "vtkGenericOpenGLRenderWindow.h" #include <vtkAnnotationLink.h> +#include <vtkAttributeDataToTableFilter.h> #include <vtkCommand.h> -#include <vtkDataObjectToTable.h> #include <vtkDataRepresentation.h> #include <vtkEventQtSlotConnect.h> #include <vtkGraphLayoutView.h> @@ -166,9 +166,9 @@ void CustomLinkView::slotOpenXMLFile() this->ColumnView->SetRepresentationFromInputConnection(this->XMLReader->GetOutputPort()); // Extract a table and give to table view - VTK_CREATE(vtkDataObjectToTable, toTable); + VTK_CREATE(vtkAttributeDataToTableFilter, toTable); toTable->SetInputConnection(this->XMLReader->GetOutputPort()); - toTable->SetFieldType(vtkDataObjectToTable::VERTEX_DATA); + toTable->SetFieldAssociation(vtkDataObject::FIELD_ASSOCIATION_VERTICES); this->TableView->SetRepresentationFromInputConnection(toTable->GetOutputPort()); this->SetupCustomLink(); diff --git a/Examples/Infovis/Cxx/EasyView/EasyView.cxx b/Examples/Infovis/Cxx/EasyView/EasyView.cxx index 0598f0168569c7aacdbc252f37e006b5bacf666b..afbb464e91db4580569487f64576f7adbdd6d264 100644 --- a/Examples/Infovis/Cxx/EasyView/EasyView.cxx +++ b/Examples/Infovis/Cxx/EasyView/EasyView.cxx @@ -10,7 +10,7 @@ // VTK includes #include "vtkGenericOpenGLRenderWindow.h" #include <vtkAnnotationLink.h> -#include <vtkDataObjectToTable.h> +#include <vtkAttributeDataToTableFilter.h> #include <vtkDataRepresentation.h> #include <vtkGraphLayoutView.h> #include <vtkQtTableView.h> @@ -158,9 +158,9 @@ void EasyView::slotOpenXMLFile() this->ColumnView->SetRepresentationFromInputConnection(this->XMLReader->GetOutputPort()); // Extract a table and give to table view - VTK_CREATE(vtkDataObjectToTable, toTable); + VTK_CREATE(vtkAttributeDataToTableFilter, toTable); toTable->SetInputConnection(this->XMLReader->GetOutputPort()); - toTable->SetFieldType(vtkDataObjectToTable::VERTEX_DATA); + toTable->SetFieldAssociation(vtkDataObject::FIELD_ASSOCIATION_VERTICES); this->TableView->SetRepresentationFromInputConnection(toTable->GetOutputPort()); this->SetupAnnotationLink(); diff --git a/Examples/Infovis/Cxx/StatsView/StatsView.cxx b/Examples/Infovis/Cxx/StatsView/StatsView.cxx index 5b4bdb38460ef230abe5d5057e7d36907b3c947b..14c1a01173b108235f8c725d8d13f5d393eef3d5 100644 --- a/Examples/Infovis/Cxx/StatsView/StatsView.cxx +++ b/Examples/Infovis/Cxx/StatsView/StatsView.cxx @@ -22,7 +22,6 @@ #include "vtkOrderStatistics.h" // QT includes -#include <vtkDataObjectToTable.h> #include <vtkDataRepresentation.h> #include <vtkQtTableModelAdapter.h> #include <vtkQtTableView.h> diff --git a/Filters/Core/CMakeLists.txt b/Filters/Core/CMakeLists.txt index 6fce86e27fab81666fc59cb604c3a18b1dde9542..b015c6571d50f4e96f4dedb1bc8e7f8109bd24af 100644 --- a/Filters/Core/CMakeLists.txt +++ b/Filters/Core/CMakeLists.txt @@ -11,6 +11,7 @@ set(classes vtkArrayRename vtkAssignAttribute vtkAttributeDataToFieldDataFilter + vtkAttributeDataToTableFilter vtkBinCellDataFilter vtkBinnedDecimation vtkCellCenters diff --git a/Filters/Core/Testing/Cxx/CMakeLists.txt b/Filters/Core/Testing/Cxx/CMakeLists.txt index be0d8012412f97f7af065a8528341f0c69eb92ba..3e72ef10a621736f44d67d78c0b560e3e82e5c01 100644 --- a/Filters/Core/Testing/Cxx/CMakeLists.txt +++ b/Filters/Core/Testing/Cxx/CMakeLists.txt @@ -16,6 +16,8 @@ vtk_add_test_cxx(vtkFiltersCoreCxxTests tests TestArrayCalculator.cxx,NO_VALID TestArrayRename.cxx,NO_VALID TestAssignAttribute.cxx,NO_VALID + TestAttributeDataToTableFilter.cxx,NO_VALID + TestAttributeDataToTableHyperTreeGrid.cxx,NO_VALID TestBinCellDataFilter.cxx,NO_VALID TestCategoricalPointDataToCellData.cxx,NO_VALID TestCategoricalResampleWithDataSet.cxx,NO_VALID diff --git a/Infovis/Core/Testing/Cxx/TestDataObjectToTable.cxx b/Filters/Core/Testing/Cxx/TestAttributeDataToTableFilter.cxx similarity index 84% rename from Infovis/Core/Testing/Cxx/TestDataObjectToTable.cxx rename to Filters/Core/Testing/Cxx/TestAttributeDataToTableFilter.cxx index 450b1c6f18b9699813bd0e08a408ac6d492f5660..ae024dd9be7455ef37e15eaf979e31d50eee107b 100644 --- a/Infovis/Core/Testing/Cxx/TestDataObjectToTable.cxx +++ b/Filters/Core/Testing/Cxx/TestAttributeDataToTableFilter.cxx @@ -1,7 +1,7 @@ /*========================================================================= Program: Visualization Toolkit - Module: TestDataObjectToTable.cxx + Module: TestAttributeDataToTableFilter.cxx Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen All rights reserved. @@ -17,7 +17,7 @@ Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. -------------------------------------------------------------------------*/ -#include "vtkDataObjectToTable.h" +#include "vtkAttributeDataToTableFilter.h" #include "vtkCellArray.h" #include "vtkCellData.h" @@ -31,9 +31,17 @@ #include "vtkSmartPointer.h" #define VTK_CREATE(type, name) vtkSmartPointer<type> name = vtkSmartPointer<type>::New() -int TestDataObjectToTable(int vtkNotUsed(argc), char* vtkNotUsed(argv)[]) +namespace { - VTK_CREATE(vtkDataObjectToTable, toTable); +const std::map<int, int> FIELD_ASSOCIATION_MAP = { { 0, vtkDataObject::FIELD_ASSOCIATION_NONE }, + { 1, vtkDataObject::FIELD_ASSOCIATION_POINTS }, { 2, vtkDataObject::FIELD_ASSOCIATION_CELLS }, + { 3, vtkDataObject::FIELD_ASSOCIATION_VERTICES }, { 4, vtkDataObject::FIELD_ASSOCIATION_EDGES }, + { 5, vtkDataObject::FIELD_ASSOCIATION_ROWS } }; +} + +int TestAttributeDataToTableFilter(int vtkNotUsed(argc), char* vtkNotUsed(argv)[]) +{ + VTK_CREATE(vtkAttributeDataToTableFilter, toTable); cerr << "Creating a simple polydata ..." << endl; VTK_CREATE(vtkPolyData, pd); @@ -81,7 +89,7 @@ int TestDataObjectToTable(int vtkNotUsed(argc), char* vtkNotUsed(argv)[]) break; } cerr << " to a table ..." << endl; - toTable->SetFieldType(type); + toTable->SetFieldAssociation(::FIELD_ASSOCIATION_MAP.at(type)); toTable->Update(); vtkTable* table = toTable->GetOutput(); cerr << "... done" << endl; diff --git a/Filters/Core/Testing/Cxx/TestAttributeDataToTableHyperTreeGrid.cxx b/Filters/Core/Testing/Cxx/TestAttributeDataToTableHyperTreeGrid.cxx new file mode 100644 index 0000000000000000000000000000000000000000..84f4ab5f1c1658e82e14bfaebbba7c78a64731be --- /dev/null +++ b/Filters/Core/Testing/Cxx/TestAttributeDataToTableHyperTreeGrid.cxx @@ -0,0 +1,99 @@ +/*========================================================================= + + Program: Visualization Toolkit + Module: TestAttributeDataToTableHyperTreeGrid.cxx + + Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen + All rights reserved. + See Copyright.txt or http://www.kitware.com/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notice for more information. + +=========================================================================*/ +#include "vtkAttributeDataToTableFilter.h" + +#include "vtkCellData.h" +#include "vtkDataArrayRange.h" +#include "vtkDoubleArray.h" +#include "vtkHyperTreeGrid.h" +#include "vtkHyperTreeGridPreConfiguredSource.h" +#include "vtkIntArray.h" +#include "vtkTable.h" + +#include <cstdlib> +#include <numeric> + +int TestAttributeDataToTableHyperTreeGrid(int vtkNotUsed(argc), char* vtkNotUsed(argv)[]) +{ + vtkNew<vtkHyperTreeGridPreConfiguredSource> source; + source->SetHTGMode(vtkHyperTreeGridPreConfiguredSource::UNBALANCED_3DEPTH_2BRANCH_2X3); + source->Update(); + + vtkHyperTreeGrid* htg = vtkHyperTreeGrid::SafeDownCast(source->GetOutput()); + if (!htg) + { + std::cout << "Problem generating HTG" << std::endl; + return EXIT_FAILURE; + } + + vtkNew<vtkDoubleArray> scalars; + scalars->SetName("ScalarField"); + scalars->SetNumberOfComponents(1); + scalars->SetNumberOfTuples(htg->GetNumberOfCells()); + auto scalRange = vtk::DataArrayValueRange<1>(scalars); + std::iota(scalRange.begin(), scalRange.end(), 0); + + vtkNew<vtkDoubleArray> vectors; + vectors->SetName("VectorField"); + vectors->SetNumberOfComponents(3); + vectors->SetNumberOfTuples(htg->GetNumberOfCells()); + auto vecRange = vtk::DataArrayValueRange<3>(vectors); + std::iota(vecRange.begin(), vecRange.end(), 0); + + htg->GetCellData()->AddArray(scalars); + htg->GetCellData()->AddArray(vectors); + + vtkNew<vtkAttributeDataToTableFilter> toTable; + toTable->SetInputData(htg); + toTable->SetFieldAssociation(vtkDataObject::FIELD_ASSOCIATION_CELLS); + toTable->Update(); + + vtkTable* table = vtkTable::SafeDownCast(toTable->GetOutput()); + + if (!table) + { + std::cout << "vtkAttributeDataToTableFilter did not return a table" << std::endl; + return EXIT_FAILURE; + } + + auto checkIota = [](vtkDataArray* arr) { + if (!arr) + { + return false; + } + auto range = vtk::DataArrayValueRange(arr); + for (vtkIdType iV = 0; iV < range.size(); ++iV) + { + if (range[iV] != static_cast<double>(iV)) + { + return false; + } + } + return true; + }; + + if (!checkIota(table->GetRowData()->GetArray("ScalarField"))) + { + std::cout << "Problem checking iota of ScalarField" << std::endl; + return EXIT_FAILURE; + } + if (!checkIota(table->GetRowData()->GetArray("VectorField"))) + { + std::cout << "Problem checking iota of VectorField" << std::endl; + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} diff --git a/Filters/Core/vtkAttributeDataToTableFilter.cxx b/Filters/Core/vtkAttributeDataToTableFilter.cxx new file mode 100644 index 0000000000000000000000000000000000000000..57435204817c9d93369ba7d4695d7a8b345df30e --- /dev/null +++ b/Filters/Core/vtkAttributeDataToTableFilter.cxx @@ -0,0 +1,397 @@ +/*========================================================================= + +Program: Visualization Toolkit + +Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen +All rights reserved. +See Copyright.txt or http://www.kitware.com/Copyright.htm for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notice for more information. + +=========================================================================*/ +/*========================================================================= + +ParaView project +BSD 3-Clause License +See LICENSE + +Copyright 2008-2023 Kitware, Inc. +All rights reserved. + +=========================================================================*/ +#include "vtkAttributeDataToTableFilter.h" + +#include "vtkCellData.h" +#include "vtkCharArray.h" +#include "vtkCompositeDataPipeline.h" +#include "vtkDataArrayRange.h" +#include "vtkDataSet.h" +#include "vtkIdList.h" +#include "vtkIdTypeArray.h" +#include "vtkImageData.h" +#include "vtkInformation.h" +#include "vtkIntArray.h" +#include "vtkObjectFactory.h" +#include "vtkPointData.h" +#include "vtkPointSet.h" +#include "vtkRectilinearGrid.h" +#include "vtkSMPThreadLocal.h" +#include "vtkSMPThreadLocalObject.h" +#include "vtkSMPTools.h" +#include "vtkSmartPointer.h" +#include "vtkStructuredGrid.h" +#include "vtkTable.h" +#include "vtkUnsignedCharArray.h" + +#include <algorithm> +#include <cmath> +#include <iomanip> +#include <iostream> +#include <sstream> +#include <vector> + +namespace +{ + +const std::string VALID_MASK_PREFIX = "__vtkValidMask__"; + +struct MaxCellSizeWorker +{ + vtkDataSet* Data; + vtkSMPThreadLocalObject<vtkIdList> Points; + vtkSMPThreadLocal<vtkIdType> MaxCellSize; + vtkIdType ReducedMaxCellSize = 0; + + MaxCellSizeWorker(vtkDataSet* data) + : Data(data) + { + } + + void Initialize() {} // do nothing + + void operator()(vtkIdType begin, vtkIdType end) + { + for (vtkIdType idx = begin; idx < end; ++idx) + { + this->Data->GetCellPoints(idx, this->Points.Local()); + this->MaxCellSize.Local() = + std::max(this->MaxCellSize.Local(), this->Points.Local()->GetNumberOfIds()); + } + } + + void Reduce() + { + for (auto iter = this->MaxCellSize.begin(); iter != this->MaxCellSize.end(); ++iter) + { + this->ReducedMaxCellSize = std::max(this->ReducedMaxCellSize, *iter); + } + }; +}; + +} + +VTK_ABI_NAMESPACE_BEGIN + +vtkStandardNewMacro(vtkAttributeDataToTableFilter); + +//---------------------------------------------------------------------------- +vtkAttributeDataToTableFilter::vtkAttributeDataToTableFilter() + : FieldAssociation(vtkDataObject::FIELD_ASSOCIATION_POINTS) +{ +} + +//---------------------------------------------------------------------------- +vtkAttributeDataToTableFilter::~vtkAttributeDataToTableFilter() = default; + +//---------------------------------------------------------------------------- +int vtkAttributeDataToTableFilter::FillInputPortInformation( + int vtkNotUsed(port), vtkInformation* info) +{ + info->Remove(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE()); + info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet"); + info->Append(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkTable"); + info->Append(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkGraph"); + info->Append(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkHyperTreeGrid"); + return 1; +} + +//---------------------------------------------------------------------------- +int vtkAttributeDataToTableFilter::RequestData(vtkInformation* vtkNotUsed(request), + vtkInformationVector** inputVector, vtkInformationVector* outputVector) +{ + vtkDataObject* input = vtkDataObject::GetData(inputVector[0], 0); + vtkTable* output = vtkTable::GetData(outputVector); + if (vtkFieldData* fieldData = input->GetAttributesAsFieldData(this->FieldAssociation)) + { + if (this->FieldAssociation == vtkDataObject::FIELD_ASSOCIATION_NONE) + { + // Field data can have different length arrays, so we need to create + // output vtkTable big enough to fit the largest array. + this->PassFieldData(output->GetRowData(), fieldData); + } + else + { + output->GetRowData()->ShallowCopy(fieldData); + vtkDataSet* ds = vtkDataSet::SafeDownCast(input); + if (this->FieldAssociation == vtkDataObject::FIELD_ASSOCIATION_CELLS && ds != nullptr) + { + this->AddCellTypeAndConnectivity(output, ds); + } + } + + // Clear any attribute markings from the output. This resolves the problem + // that GlobalNodeIds were not showing up in spreadsheet view. + for (int cc = vtkDataSetAttributes::SCALARS; cc < vtkDataSetAttributes::NUM_ATTRIBUTES; cc++) + { + output->GetRowData()->SetActiveAttribute(-1, cc); + } + + if (this->AddMetaData && this->FieldAssociation != vtkDataObject::FIELD_ASSOCIATION_NONE) + { + this->Decorate(output, input); + } + } + return 1; +} + +//---------------------------------------------------------------------------- +void vtkAttributeDataToTableFilter::AddCellTypeAndConnectivity(vtkTable* output, vtkDataSet* ds) +{ + vtkNew<vtkCharArray> celltypes; + celltypes->SetName("Cell Type"); + const vtkIdType numcells = ds->GetNumberOfCells(); + celltypes->SetNumberOfComponents(1); + celltypes->SetNumberOfTuples(numcells); + if (numcells != 0) + { + // for thread safety after + ds->GetCellType(0); + } + vtkSMPTools::For(0, numcells, [&ds, &celltypes](vtkIdType begin, vtkIdType end) { + for (auto idx = begin; idx < end; ++idx) + { + celltypes->SetValue(idx, static_cast<char>(ds->GetCellType(idx))); + } + }); + output->GetRowData()->AddArray(celltypes); + vtkIdType maxpoints = 0; + { + ::MaxCellSizeWorker worker(ds); + vtkSMPTools::For(0, numcells, worker); + maxpoints = worker.ReducedMaxCellSize; + } + + if (this->GenerateCellConnectivity) + { + std::vector<vtkSmartPointer<vtkIdTypeArray>> indices(maxpoints); + int wordSize = 1 + log10(maxpoints); + for (vtkIdType i = 0; i < maxpoints; i++) + { + std::stringstream arrayname; + arrayname << "Point Index " << std::setw(wordSize) << std::setfill('0') << i; + vtkNew<vtkIdTypeArray> idarray; + idarray->SetName(arrayname.str().c_str()); + idarray->SetNumberOfTuples(numcells); + indices[i] = idarray; + } + + vtkSMPTools::For(0, numcells, [&](vtkIdType begin, vtkIdType end) { + vtkNew<vtkIdList> locPoints; + for (vtkIdType cc = begin; cc < end; cc++) + { + ds->GetCellPoints(cc, locPoints); + for (vtkIdType pt = 0; pt < maxpoints; pt++) + { + if (pt < locPoints->GetNumberOfIds()) + { + indices[pt]->SetValue(cc, locPoints->GetId(pt)); + } + else + { + indices[pt]->SetValue(cc, -1); + } + } + } + }); + for (int i = 0; i < maxpoints; i++) + { + this->ConvertToOriginalIds(ds, indices[i]); + output->GetRowData()->AddArray(indices[i]); + } + } +} + +//---------------------------------------------------------------------------- +void vtkAttributeDataToTableFilter::PassFieldData(vtkFieldData* output, vtkFieldData* input) +{ + output->DeepCopy(input); + + // Now resize arrays to match the longest one. + vtkIdType max_count = 0; + for (int cc = 0, max = output->GetNumberOfArrays(); cc < max; ++cc) + { + if (vtkAbstractArray* arr = output->GetAbstractArray(cc)) + { + max_count = std::max(max_count, arr->GetNumberOfTuples()); + } + } + + for (int cc = 0, max = output->GetNumberOfArrays(); cc < max; ++cc) + { + vtkAbstractArray* arr = output->GetAbstractArray(cc); + if (!arr) + { + continue; + } + + const vtkIdType current_count = arr->GetNumberOfTuples(); + if ((current_count != max_count) && arr->Resize(max_count)) + { + arr->SetNumberOfTuples(max_count); + + vtkNew<vtkUnsignedCharArray> maskArray; + maskArray->SetName((::VALID_MASK_PREFIX + std::string(arr->GetName())).c_str()); + maskArray->SetNumberOfTuples(max_count); + maskArray->FillValue(static_cast<unsigned char>(1)); + output->AddArray(maskArray); + + const int num_comps = arr->GetNumberOfComponents(); + vtkDataArray* da = vtkDataArray::SafeDownCast(arr); + if (da != nullptr && num_comps > 0) + { + std::vector<double> tuple(num_comps, 0.0); + vtkSMPTools::For( + current_count, max_count, [&da, &maskArray, &tuple](vtkIdType begin, vtkIdType end) { + for (auto idx = begin; idx < end; ++idx) + { + da->SetTuple(idx, tuple.data()); + maskArray->SetTypedComponent(idx, 0, static_cast<unsigned char>(0)); + } + }); + } + } + } +} + +//---------------------------------------------------------------------------- +void vtkAttributeDataToTableFilter::Decorate(vtkTable* output, vtkDataObject* input) +{ + vtkPointSet* psInput = vtkPointSet::SafeDownCast(input); + vtkRectilinearGrid* rgInput = vtkRectilinearGrid::SafeDownCast(input); + vtkImageData* idInput = vtkImageData::SafeDownCast(input); + vtkStructuredGrid* sgInput = vtkStructuredGrid::SafeDownCast(input); + int dimensions[3] = { -1 }; + if (rgInput) + { + rgInput->GetDimensions(dimensions); + } + else if (idInput) + { + idInput->GetDimensions(dimensions); + } + else if (sgInput) + { + sgInput->GetDimensions(dimensions); + } + bool dimSuccess = !((dimensions[0] < 0) || (dimensions[1] < 0) || (dimensions[2] < 0)); + + int* pDimensions = nullptr; + if (dimSuccess) + { + pDimensions = dimensions; + } + + int cellDims[3]; + if (this->FieldAssociation == vtkDataObject::FIELD_ASSOCIATION_CELLS && dimSuccess) + { + cellDims[0] = std::max(1, (dimensions[0] - 1)); + cellDims[1] = std::max(1, (dimensions[1] - 1)); + cellDims[2] = std::max(1, (dimensions[2] - 1)); + pDimensions = cellDims; + } + + if (this->FieldAssociation == vtkDataObject::FIELD_ASSOCIATION_POINTS && psInput && + psInput->GetPoints()) + { + output->GetRowData()->AddArray(psInput->GetPoints()->GetData()); + } + + if (pDimensions) + { + // Some thought was given here to including the "STRUCTURED_DIMENSIONS" + // parameter in the vtkInformation associated with the table instead of + // FieldData. This is still an option but there were reservations around + // the viability of yet another key propagating through the pipeline. + vtkIntArray* dArray = vtkIntArray::New(); + dArray->SetName("STRUCTURED_DIMENSIONS"); + dArray->SetNumberOfComponents(3); + dArray->SetNumberOfTuples(1); + dArray->SetTypedTuple(0, pDimensions); + output->GetFieldData()->AddArray(dArray); + dArray->Delete(); + } + + if (this->GenerateOriginalIds) + { + // This array is added in order to track the original ids in the data object. + // While incurring a memory cost, this information is very hard to recover + // post table transformation. + + vtkIdTypeArray* indicesArray = vtkIdTypeArray::New(); + indicesArray->SetName("vtkOriginalIndices"); + indicesArray->SetNumberOfComponents(1); + vtkIdType numElements = input->GetNumberOfElements(this->FieldAssociation); + indicesArray->SetNumberOfTuples(numElements); + vtkSMPTools::For(0, numElements, [&indicesArray](vtkIdType begin, vtkIdType end) { + for (vtkIdType idx = begin; idx < end; ++idx) + { + indicesArray->SetValue(idx, idx); + } + }); + output->GetRowData()->AddArray(indicesArray); + indicesArray->FastDelete(); + } +} + +//---------------------------------------------------------------------------- +void vtkAttributeDataToTableFilter::ConvertToOriginalIds( + vtkDataSet* inputDS, vtkIdTypeArray* indices) +{ + vtkPointData* pd = inputDS->GetPointData(); + if (!pd) + { + return; + } + + vtkDataArray* originalIds = pd->GetArray("vtkOriginalPointIds"); + if (!originalIds) + { + originalIds = pd->GetArray("vtkOriginalIndices"); + } + if (originalIds) + { + auto indexRange = vtk::DataArrayValueRange<1>(indices); + auto originalRange = vtk::DataArrayValueRange<1>(originalIds); + vtkSMPTools::Transform( + indexRange.begin(), indexRange.end(), indexRange.begin(), [&originalRange](vtkIdType idx) { + if (idx >= 0 && idx < originalRange.size()) + { + return static_cast<vtkIdType>(originalRange[idx]); + } + return idx; + }); + } +} + +//---------------------------------------------------------------------------- +void vtkAttributeDataToTableFilter::PrintSelf(ostream& os, vtkIndent indent) +{ + this->Superclass::PrintSelf(os, indent); + os << indent << "FieldAssociation: " << this->FieldAssociation << endl; + os << indent << "AddMetaData: " << this->AddMetaData << endl; + os << indent << "GenerateOriginalIds: " << this->GenerateOriginalIds << endl; +} + +VTK_ABI_NAMESPACE_END diff --git a/Filters/Core/vtkAttributeDataToTableFilter.h b/Filters/Core/vtkAttributeDataToTableFilter.h new file mode 100644 index 0000000000000000000000000000000000000000..0aadb75f75034714e9d7524b8926ec600c062518 --- /dev/null +++ b/Filters/Core/vtkAttributeDataToTableFilter.h @@ -0,0 +1,145 @@ +/*========================================================================= + +Program: Visualization Toolkit + +Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen +All rights reserved. +See Copyright.txt or http://www.kitware.com/Copyright.htm for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notice for more information. + +=========================================================================*/ +/*========================================================================= + +ParaView project +BSD 3-Clause License +See LICENSE + +Copyright 2008-2023 Kitware, Inc. +All rights reserved. + +=========================================================================*/ +/** + * @class vtkAttributeDataToTableFilter + * @brief this filter produces a + * vtkTable from the chosen attribute in the input data object. + * + * vtkAttributeDataToTableFilter is a filter that produces a vtkTable from the + * chosen attribute in the input dataobject. This filter can accept composite + * datasets. If the input is a composite dataset, the output is a multiblock + * with vtkTable leaves. + */ + +#ifndef vtkAttributeDataToTableFilter_h +#define vtkAttributeDataToTableFilter_h + +#include "vtkFiltersCoreModule.h" // needed for export macro +#include "vtkTableAlgorithm.h" + +VTK_ABI_NAMESPACE_BEGIN +class vtkDataSet; +class vtkFieldData; +class vtkIdTypeArray; + +class VTKFILTERSCORE_EXPORT vtkAttributeDataToTableFilter : public vtkTableAlgorithm +{ +public: + static vtkAttributeDataToTableFilter* New(); + vtkTypeMacro(vtkAttributeDataToTableFilter, vtkTableAlgorithm); + void PrintSelf(ostream& os, vtkIndent indent) override; + + ///@{ + /** + * Select the attribute type. Accepted values are + * \li vtkDataObject::FIELD_ASSOCIATION_POINTS, + * \li vtkDataObject::FIELD_ASSOCIATION_CELLS, + * \li vtkDataObject::FIELD_ASSOCIATION_NONE, + * \li vtkDataObject::FIELD_ASSOCIATION_VERTICES, + * \li vtkDataObject::FIELD_ASSOCIATION_EDGES, + * \li vtkDataObject::FIELD_ASSOCIATION_ROWS + * If value is vtkDataObject::FIELD_ASSOCIATION_NONE, then FieldData + * associated with the input dataobject is extracted. + * + * Default is vtkDataObject::FIELD_ASSOCIATION_POINTS + */ + vtkSetMacro(FieldAssociation, int); + vtkGetMacro(FieldAssociation, int); + ///@} + + ///@{ + /** + * It is possible for this filter to add additional meta-data to the field + * data such as point coordinates (when point attributes are selected and + * input is pointset) or structured coordinates etc. To enable this addition + * of extra information, turn this flag on. Off by default. + */ + vtkSetMacro(AddMetaData, bool); + vtkGetMacro(AddMetaData, bool); + vtkBooleanMacro(AddMetaData, bool); + ///@} + + ///@{ + /** + * When set (default) the vtkOriginalIndices array will be added to the + * output. Can be overridden by setting this flag to 0. + * This is only respected when AddMetaData is true. + */ + vtkSetMacro(GenerateOriginalIds, bool); + vtkGetMacro(GenerateOriginalIds, bool); + vtkBooleanMacro(GenerateOriginalIds, bool); + ///@} + + ///@{ + /** + * When set to true (default is false) the connectivity of each cell will be added by + * adding a new column for each point. + */ + vtkSetMacro(GenerateCellConnectivity, bool); + vtkGetMacro(GenerateCellConnectivity, bool); + vtkBooleanMacro(GenerateCellConnectivity, bool); + ///@} + +protected: + vtkAttributeDataToTableFilter(); + ~vtkAttributeDataToTableFilter() override; + + /** + * Overridden to indicate to the executive that we accept non-composite + * datasets. We let the executive manage the looping over the composite + * dataset leaves. + */ + int FillInputPortInformation(int port, vtkInformation* info) override; + + /** + * Perform the data processing + */ + int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override; + + /** + * Called when AddMetaData is true. Adds meta-data to the output. + */ + void Decorate(vtkTable* output, vtkDataObject* input); + + void PassFieldData(vtkFieldData* output, vtkFieldData* input); + void AddCellTypeAndConnectivity(vtkTable* output, vtkDataSet* ds); + +private: + vtkAttributeDataToTableFilter(const vtkAttributeDataToTableFilter&) = delete; + void operator=(const vtkAttributeDataToTableFilter&) = delete; + + /** + * If original Ids for points are available (due to selection filtering), + * re-map the indices to original Ids. + */ + void ConvertToOriginalIds(vtkDataSet* inputDS, vtkIdTypeArray* indices); + + int FieldAssociation; + bool AddMetaData = false; + bool GenerateOriginalIds = false; + bool GenerateCellConnectivity = false; +}; +VTK_ABI_NAMESPACE_END + +#endif diff --git a/Infovis/Core/Testing/Cxx/CMakeLists.txt b/Infovis/Core/Testing/Cxx/CMakeLists.txt index b5252af6df795505c6db1f087d430944cffcd2f4..62df3966c7de242dc6349dc9471e2982b877ec1e 100644 --- a/Infovis/Core/Testing/Cxx/CMakeLists.txt +++ b/Infovis/Core/Testing/Cxx/CMakeLists.txt @@ -13,7 +13,6 @@ vtk_add_test_cxx(vtkInfovisCoreCxxTests tests TestArrayNorm.cxx,NO_VALID,NO_DATA TestCollapseVerticesByArray.cxx,NO_VALID TestContinuousScatterPlot.cxx,NO_VALID - TestDataObjectToTable.cxx,NO_VALID TestExtractSelectedTree.cxx,NO_VALID TestExtractSelectedGraph.cxx,NO_VALID TestGraphAlgorithms.cxx @@ -24,6 +23,7 @@ vtk_add_test_cxx(vtkInfovisCoreCxxTests tests TestRemoveIsolatedVertices.cxx,NO_VALID TestStreamGraph.cxx,NO_VALID TestTableToArray.cxx,NO_VALID + TestTableToGraph.cxx TestThresholdTable.cxx,NO_VALID TestTreeDifferenceFilter.cxx,NO_VALID ) diff --git a/Infovis/Core/Testing/Cxx/TestTableToGraph.cxx b/Infovis/Core/Testing/Cxx/TestTableToGraph.cxx index 34dfd1e0407bab80b46513222a3bdecb6542aeac..2bd70f2bbc3420f78fb9ca8006eef9a691eb9111 100644 --- a/Infovis/Core/Testing/Cxx/TestTableToGraph.cxx +++ b/Infovis/Core/Testing/Cxx/TestTableToGraph.cxx @@ -20,9 +20,9 @@ #include "vtkActor.h" #include "vtkActor2D.h" +#include "vtkAttributeDataToTableFilter.h" #include "vtkBitArray.h" #include "vtkCircularLayoutStrategy.h" -#include "vtkDataObjectToTable.h" #include "vtkDataRepresentation.h" #include "vtkDelimitedTextReader.h" #include "vtkGlyph3D.h" @@ -149,7 +149,7 @@ int TestTableToGraph(int argc, char* argv[]) QApplication app(argc, argv); #endif - const char* label = 0; + const char* label = nullptr; bool circular = true; for (int a = 1; a < argc; a++) { @@ -334,17 +334,17 @@ int TestTableToGraph(int argc, char* argv[]) mergeView->SetRepresentationFromInputConnection(merge->GetOutputPort()); mergeView->GetWidget()->show(); - VTK_CREATE(vtkDataObjectToTable, vertToTable); + VTK_CREATE(vtkAttributeDataToTableFilter, vertToTable); vertToTable->SetInputConnection(tableToGraph->GetOutputPort()); - vertToTable->SetFieldType(vtkDataObjectToTable::POINT_DATA); + vertToTable->SetFieldAssociation(vtkDataObject::FIELD_ASSOCIATION_POINTS); VTK_CREATE(vtkQtTableView, vertView); vertView->SetRepresentationFromInputConnection(vertToTable->GetOutputPort()); vertView->GetWidget()->show(); vertView->Update(); - VTK_CREATE(vtkDataObjectToTable, edgeToTable); + VTK_CREATE(vtkAttributeDataToTableFilter, edgeToTable); edgeToTable->SetInputConnection(tableToGraph->GetOutputPort()); - edgeToTable->SetFieldType(vtkDataObjectToTable::CELL_DATA); + edgeToTable->SetFieldAssocitation(vtkDataObject::FIELD_ASSOCIATION_CELLS); VTK_CREATE(vtkQtTableView, edgeView); edgeView->SetRepresentationFromInputConnection(edgeToTable->GetOutputPort()); edgeView->GetWidget()->show(); diff --git a/Infovis/Core/Testing/Data/Baseline/TestTableToGraph.png.sha512 b/Infovis/Core/Testing/Data/Baseline/TestTableToGraph.png.sha512 new file mode 100644 index 0000000000000000000000000000000000000000..aa10689304889721565753a67d8346b8a4b12595 --- /dev/null +++ b/Infovis/Core/Testing/Data/Baseline/TestTableToGraph.png.sha512 @@ -0,0 +1 @@ +3ec338d049533c347b6be0fabfada8372554419d564b777b24e3788f8d5077a4f022a3f6fe5d038fdab2d7dd797c8bf7e0915df6ea999633a2e606493cc83bce diff --git a/Infovis/Core/vtk.module b/Infovis/Core/vtk.module index 128d082879725c195187d342e6195e99a272b05b..86806e098cdf12a76e64c3b51f8fbf8e7d64bcd1 100644 --- a/Infovis/Core/vtk.module +++ b/Infovis/Core/vtk.module @@ -23,5 +23,7 @@ TEST_DEPENDS VTK::InfovisLayout VTK::InteractionImage VTK::InteractionStyle + VTK::RenderingLabel VTK::RenderingOpenGL2 VTK::TestingRendering + VTK::ViewsCore diff --git a/Infovis/Core/vtkDataObjectToTable.cxx b/Infovis/Core/vtkDataObjectToTable.cxx index 8fc447a8ab4d76c5421c48d352bec6b1d55bf500..ccd632e20cc3ac86a885875c88fb494023639f96 100644 --- a/Infovis/Core/vtkDataObjectToTable.cxx +++ b/Infovis/Core/vtkDataObjectToTable.cxx @@ -17,6 +17,8 @@ Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. -------------------------------------------------------------------------*/ +// VTK_DEPRECATED_IN_9_3_0() warnings for this class. +#define VTK_DEPRECATION_LEVEL 0 #include "vtkDataObjectToTable.h" diff --git a/Infovis/Core/vtkDataObjectToTable.h b/Infovis/Core/vtkDataObjectToTable.h index f853a57cce759e9e7f57f9ec0675898ca2b7b6c1..1f7cb90f9991ae9b37833c7d5501243f15775552 100644 --- a/Infovis/Core/vtkDataObjectToTable.h +++ b/Infovis/Core/vtkDataObjectToTable.h @@ -29,11 +29,13 @@ #ifndef vtkDataObjectToTable_h #define vtkDataObjectToTable_h +#include "vtkDeprecation.h" // For deprecation macros #include "vtkInfovisCoreModule.h" // For export macro #include "vtkTableAlgorithm.h" VTK_ABI_NAMESPACE_BEGIN -class VTKINFOVISCORE_EXPORT vtkDataObjectToTable : public vtkTableAlgorithm +class VTK_DEPRECATED_IN_9_3_0("Use vtkAttributeDataToTableFilter instead of vtkDataObjectToTable.") + VTKINFOVISCORE_EXPORT vtkDataObjectToTable : public vtkTableAlgorithm { public: static vtkDataObjectToTable* New(); diff --git a/Views/Qt/Testing/Cxx/TestVtkQtTableView.cxx b/Views/Qt/Testing/Cxx/TestVtkQtTableView.cxx index 7c86bdd20ea1dc9bdbcb23140560cfe92dca58b5..8099d9f9a960088f2e3db254a8ac3a95b7c68eba 100644 --- a/Views/Qt/Testing/Cxx/TestVtkQtTableView.cxx +++ b/Views/Qt/Testing/Cxx/TestVtkQtTableView.cxx @@ -20,7 +20,7 @@ #include "vtkQtTableView.h" -#include "vtkDataObjectToTable.h" +#include "vtkAttributeDataToTableFilter.h" #include "vtkSmartPointer.h" #include "vtkSphereSource.h" #include "vtkTable.h" @@ -37,9 +37,9 @@ int TestVtkQtTableView(int argc, char* argv[]) // Create a sphere and create a vtkTable from its point data (normal vectors) VTK_CREATE(vtkSphereSource, sphereSource); - VTK_CREATE(vtkDataObjectToTable, tableConverter); + VTK_CREATE(vtkAttributeDataToTableFilter, tableConverter); tableConverter->SetInputConnection(sphereSource->GetOutputPort()); - tableConverter->SetFieldType(vtkDataObjectToTable::POINT_DATA); + tableConverter->SetFieldAssociation(vtkDataObject::FIELD_ASSOCIATION_POINTS); tableConverter->Update(); vtkTable* pointTable = tableConverter->GetOutput(); diff --git a/Views/Qt/vtkQtListView.cxx b/Views/Qt/vtkQtListView.cxx index f89a22eb4299e94b73c1eaa4836a746d1ba9827f..2a2dd2a31e23b15d7d61f8f01f39177bfe912432 100644 --- a/Views/Qt/vtkQtListView.cxx +++ b/Views/Qt/vtkQtListView.cxx @@ -32,8 +32,8 @@ #include "vtkAnnotationLayers.h" #include "vtkAnnotationLink.h" #include "vtkApplyColors.h" +#include "vtkAttributeDataToTableFilter.h" #include "vtkConvertSelection.h" -#include "vtkDataObjectToTable.h" #include "vtkDataRepresentation.h" #include "vtkDataSetAttributes.h" #include "vtkGraph.h" @@ -49,6 +49,17 @@ #include "vtkTable.h" #include "vtkViewTheme.h" +namespace +{ +const std::map<int, int> FIELD_ASSOCIATION_MAP = { { vtkQtListView::FIELD_DATA, + vtkDataObject::FIELD_ASSOCIATION_NONE }, + { vtkQtListView::POINT_DATA, vtkDataObject::FIELD_ASSOCIATION_POINTS }, + { vtkQtListView::CELL_DATA, vtkDataObject::FIELD_ASSOCIATION_CELLS }, + { vtkQtListView::VERTEX_DATA, vtkDataObject::FIELD_ASSOCIATION_VERTICES }, + { vtkQtListView::EDGE_DATA, vtkDataObject::FIELD_ASSOCIATION_EDGES }, + { vtkQtListView::ROW_DATA, vtkDataObject::FIELD_ASSOCIATION_ROWS } }; +} + VTK_ABI_NAMESPACE_BEGIN vtkStandardNewMacro(vtkQtListView); @@ -56,10 +67,10 @@ vtkStandardNewMacro(vtkQtListView); vtkQtListView::vtkQtListView() { this->ApplyColors = vtkSmartPointer<vtkApplyColors>::New(); - this->DataObjectToTable = vtkSmartPointer<vtkDataObjectToTable>::New(); + this->DataObjectToTable = vtkSmartPointer<vtkAttributeDataToTableFilter>::New(); this->ApplyColors->SetInputConnection(0, this->DataObjectToTable->GetOutputPort(0)); - this->DataObjectToTable->SetFieldType(vtkDataObjectToTable::VERTEX_DATA); + this->DataObjectToTable->SetFieldAssociation(vtkDataObject::FIELD_ASSOCIATION_VERTICES); this->FieldType = vtkQtListView::VERTEX_DATA; this->ListView = new QListView(); @@ -125,7 +136,7 @@ void vtkQtListView::SetEnableDragDrop(bool state) //------------------------------------------------------------------------------ void vtkQtListView::SetFieldType(int type) { - this->DataObjectToTable->SetFieldType(type); + this->DataObjectToTable->SetFieldAssociation(::FIELD_ASSOCIATION_MAP.at(type)); if (this->FieldType != type) { this->FieldType = type; diff --git a/Views/Qt/vtkQtListView.h b/Views/Qt/vtkQtListView.h index 9c89d6ac5c3fe05515699ed8c91a0b6f80b882bd..276f8c8d8f79cb39b45417f832ad8b90cbb9571d 100644 --- a/Views/Qt/vtkQtListView.h +++ b/Views/Qt/vtkQtListView.h @@ -44,8 +44,8 @@ class QSortFilterProxyModel; class QListView; VTK_ABI_NAMESPACE_BEGIN +class vtkAttributeDataToTableFilter; class vtkApplyColors; -class vtkDataObjectToTable; class vtkQtTableModelAdapter; class VTKVIEWSQT_EXPORT vtkQtListView : public vtkQtView @@ -183,7 +183,7 @@ private: int FieldType; int VisibleColumn; - vtkSmartPointer<vtkDataObjectToTable> DataObjectToTable; + vtkSmartPointer<vtkAttributeDataToTableFilter> DataObjectToTable; vtkSmartPointer<vtkApplyColors> ApplyColors; vtkQtListView(const vtkQtListView&) = delete; diff --git a/Views/Qt/vtkQtRecordView.cxx b/Views/Qt/vtkQtRecordView.cxx index f5ddb985d4b6f72fdb9fd47c76a7fbee2f024197..3ccf55a243ada324ecf6354532ca2fddfc5de472 100644 --- a/Views/Qt/vtkQtRecordView.cxx +++ b/Views/Qt/vtkQtRecordView.cxx @@ -25,9 +25,9 @@ #include "vtkAlgorithm.h" #include "vtkAlgorithmOutput.h" #include "vtkAnnotationLink.h" +#include "vtkAttributeDataToTableFilter.h" #include "vtkCommand.h" #include "vtkConvertSelection.h" -#include "vtkDataObjectToTable.h" #include "vtkDataRepresentation.h" #include "vtkIdTypeArray.h" #include "vtkInformation.h" @@ -37,6 +37,17 @@ #include "vtkSmartPointer.h" #include "vtkTable.h" +namespace +{ +const std::map<int, int> FIELD_ASSOCIATION_MAP = { { vtkQtRecordView::FIELD_DATA, + vtkDataObject::FIELD_ASSOCIATION_NONE }, + { vtkQtRecordView::POINT_DATA, vtkDataObject::FIELD_ASSOCIATION_POINTS }, + { vtkQtRecordView::CELL_DATA, vtkDataObject::FIELD_ASSOCIATION_CELLS }, + { vtkQtRecordView::VERTEX_DATA, vtkDataObject::FIELD_ASSOCIATION_VERTICES }, + { vtkQtRecordView::EDGE_DATA, vtkDataObject::FIELD_ASSOCIATION_EDGES }, + { vtkQtRecordView::ROW_DATA, vtkDataObject::FIELD_ASSOCIATION_ROWS } }; +} + VTK_ABI_NAMESPACE_BEGIN vtkStandardNewMacro(vtkQtRecordView); @@ -44,8 +55,8 @@ vtkStandardNewMacro(vtkQtRecordView); vtkQtRecordView::vtkQtRecordView() { this->TextWidget = new QTextEdit(); - this->DataObjectToTable = vtkSmartPointer<vtkDataObjectToTable>::New(); - this->DataObjectToTable->SetFieldType(vtkDataObjectToTable::VERTEX_DATA); + this->DataObjectToTable = vtkSmartPointer<vtkAttributeDataToTableFilter>::New(); + this->DataObjectToTable->SetFieldAssociation(vtkDataObject::FIELD_ASSOCIATION_VERTICES); this->FieldType = vtkQtRecordView::VERTEX_DATA; this->Text = nullptr; this->CurrentSelectionMTime = 0; @@ -68,7 +79,7 @@ QWidget* vtkQtRecordView::GetWidget() //------------------------------------------------------------------------------ void vtkQtRecordView::SetFieldType(int type) { - this->DataObjectToTable->SetFieldType(type); + this->DataObjectToTable->SetFieldAssociation(::FIELD_ASSOCIATION_MAP.at(type)); if (this->FieldType != type) { this->FieldType = type; diff --git a/Views/Qt/vtkQtRecordView.h b/Views/Qt/vtkQtRecordView.h index d2e3c8a6d318c0d0966b3a5adcf6f516c691fa37..33dc010df5c03d1dd7e2de9a9ee8ca5f5a57b7db 100644 --- a/Views/Qt/vtkQtRecordView.h +++ b/Views/Qt/vtkQtRecordView.h @@ -42,7 +42,7 @@ class QTextEdit; VTK_ABI_NAMESPACE_BEGIN -class vtkDataObjectToTable; +class vtkAttributeDataToTableFilter; class VTKVIEWSQT_EXPORT vtkQtRecordView : public vtkQtView { @@ -95,7 +95,7 @@ protected: void AddRepresentationInternal(vtkDataRepresentation* rep) override; void RemoveRepresentationInternal(vtkDataRepresentation* rep) override; - vtkSmartPointer<vtkDataObjectToTable> DataObjectToTable; + vtkSmartPointer<vtkAttributeDataToTableFilter> DataObjectToTable; QPointer<QTextEdit> TextWidget; diff --git a/Views/Qt/vtkQtTableView.cxx b/Views/Qt/vtkQtTableView.cxx index 0220a72708a4005ae05310f2bb6fc96cf1ce7d80..82440c6987d967d88a027ae37a4febb4e0db15b8 100644 --- a/Views/Qt/vtkQtTableView.cxx +++ b/Views/Qt/vtkQtTableView.cxx @@ -33,8 +33,8 @@ #include "vtkAnnotationLayers.h" #include "vtkAnnotationLink.h" #include "vtkApplyColors.h" +#include "vtkAttributeDataToTableFilter.h" #include "vtkConvertSelection.h" -#include "vtkDataObjectToTable.h" #include "vtkDataRepresentation.h" #include "vtkDataSetAttributes.h" #include "vtkGraph.h" @@ -50,6 +50,17 @@ #include "vtkTable.h" #include "vtkViewTheme.h" +namespace +{ +const std::map<int, int> FIELD_ASSOCIATION_MAP = { { vtkQtTableView::FIELD_DATA, + vtkDataObject::FIELD_ASSOCIATION_NONE }, + { vtkQtTableView::POINT_DATA, vtkDataObject::FIELD_ASSOCIATION_POINTS }, + { vtkQtTableView::CELL_DATA, vtkDataObject::FIELD_ASSOCIATION_CELLS }, + { vtkQtTableView::VERTEX_DATA, vtkDataObject::FIELD_ASSOCIATION_VERTICES }, + { vtkQtTableView::EDGE_DATA, vtkDataObject::FIELD_ASSOCIATION_EDGES }, + { vtkQtTableView::ROW_DATA, vtkDataObject::FIELD_ASSOCIATION_ROWS } }; +} + VTK_ABI_NAMESPACE_BEGIN vtkStandardNewMacro(vtkQtTableView); @@ -57,11 +68,11 @@ vtkStandardNewMacro(vtkQtTableView); vtkQtTableView::vtkQtTableView() { this->ApplyColors = vtkSmartPointer<vtkApplyColors>::New(); - this->DataObjectToTable = vtkSmartPointer<vtkDataObjectToTable>::New(); + this->DataObjectToTable = vtkSmartPointer<vtkAttributeDataToTableFilter>::New(); this->AddSelectedColumn = vtkSmartPointer<vtkAddMembershipArray>::New(); this->AddSelectedColumn->SetInputConnection(0, this->DataObjectToTable->GetOutputPort()); - this->DataObjectToTable->SetFieldType(vtkDataObjectToTable::VERTEX_DATA); + this->DataObjectToTable->SetFieldAssociation(vtkDataObject::FIELD_ASSOCIATION_VERTICES); this->AddSelectedColumn->SetFieldType(vtkAddMembershipArray::VERTEX_DATA); this->FieldType = vtkQtTableView::VERTEX_DATA; this->AddSelectedColumn->SetOutputArrayName("vtkAddMembershipArray membership"); @@ -154,7 +165,7 @@ void vtkQtTableView::SetSortingEnabled(bool state) //------------------------------------------------------------------------------ void vtkQtTableView::SetFieldType(int type) { - this->DataObjectToTable->SetFieldType(type); + this->DataObjectToTable->SetFieldAssociation(::FIELD_ASSOCIATION_MAP.at(type)); this->AddSelectedColumn->SetFieldType(type); if (this->FieldType != type) { diff --git a/Views/Qt/vtkQtTableView.h b/Views/Qt/vtkQtTableView.h index 50fb86275124b67ebd55bc938286235ef59b6a99..2b5e118464f820502c29aa9ae6f82c1affbfcad7 100644 --- a/Views/Qt/vtkQtTableView.h +++ b/Views/Qt/vtkQtTableView.h @@ -45,7 +45,7 @@ class QTableView; VTK_ABI_NAMESPACE_BEGIN class vtkAddMembershipArray; class vtkApplyColors; -class vtkDataObjectToTable; +class vtkAttributeDataToTableFilter; class vtkIdTypeArray; class vtkQtTableModelAdapter; @@ -245,7 +245,7 @@ private: char* ColorArrayNameInternal; vtkSmartPointer<vtkAddMembershipArray> AddSelectedColumn; - vtkSmartPointer<vtkDataObjectToTable> DataObjectToTable; + vtkSmartPointer<vtkAttributeDataToTableFilter> DataObjectToTable; vtkSmartPointer<vtkApplyColors> ApplyColors; vtkQtTableView(const vtkQtTableView&) = delete;