diff --git a/docs/changelog/coords-are-fields.md b/docs/changelog/coords-are-fields.md new file mode 100644 index 000000000..06d2261d1 --- /dev/null +++ b/docs/changelog/coords-are-fields.md @@ -0,0 +1,29 @@ +# Coordiante systems are stored as Fields + +Previously, `DataSet` managed `CoordinateSystem`s separately from `Field`s. +However, a `CoordinateSystem` is really just a `Field` with some special +attributes. Thus, coordiante systems are now just listed along with the +rest of the fields, and the coordinate systems are simply strings that +point back to the appropriate field. (This was actually the original +concept for `DataSet`, but the coordinate systems were separated from +fields for some now obsolete reasons.) + +This change should not be very noticible, but there are a few consequences +that should be noted. + +1. The `GetCoordinateSystem` methods no longer return a reference to a + `CoordinateSystem` object. This is because the `CoordinateSystem` object + is made on the fly from the field. +2. When mapping fields in filters, the coordinate systems get mapped as + part of this process. This has allowed us to remove some of the special + cases needed to set the coordinate system in the output. +3. If a filter is generating a coordinate system in a special way + (different than mapping other point fields), then it can use the special + `CreateResultCoordianteSystem` method to attach this custom coordinate + system to the output. +4. The `DataSet::GetCoordianteSystems()` method to get a `vector<>` of all + coordiante systems is removed. `DataSet` no longer internally has this + structure. Although it could be built, the only reason for its existance + was to support passing coordinate systems in filters. Now that this is + done autmoatically, the method is no longer needed. + diff --git a/tutorial/extract_edges.cxx b/tutorial/extract_edges.cxx index ee31224ed..15f8247eb 100644 --- a/tutorial/extract_edges.cxx +++ b/tutorial/extract_edges.cxx @@ -195,7 +195,7 @@ VTKM_CONT vtkm::cont::DataSet ExtractEdges::DoExecute(const vtkm::cont::DataSet& auto mapper = [&](auto& outDataSet, const auto& f) { DoMapField(outDataSet, f, outputToInputCellMap, cellToEdgeKeys); }; - return this->CreateResult(inData, outCellSet, inData.GetCoordinateSystems(), mapper); + return this->CreateResult(inData, outCellSet, mapper); } int main(int argc, char** argv) diff --git a/vtkm/cont/CoordinateSystem.cxx b/vtkm/cont/CoordinateSystem.cxx index 44badd57b..b4128e296 100644 --- a/vtkm/cont/CoordinateSystem.cxx +++ b/vtkm/cont/CoordinateSystem.cxx @@ -11,6 +11,7 @@ #include #include #include +#include namespace vtkm { @@ -22,6 +23,15 @@ VTKM_CONT CoordinateSystem::CoordinateSystem() { } +VTKM_CONT CoordinateSystem::CoordinateSystem(const vtkm::cont::Field& src) + : Superclass(src) +{ + if (src.GetAssociation() != vtkm::cont::Field::Association::Points) + { + throw vtkm::cont::ErrorBadValue("CoordinateSystems can only be point field."); + } +} + VTKM_CONT CoordinateSystem::CoordinateSystem(std::string name, const vtkm::cont::UnknownArrayHandle& data) : Superclass(name, Association::Points, data) diff --git a/vtkm/cont/CoordinateSystem.h b/vtkm/cont/CoordinateSystem.h index 7f1a2ff06..34b8008d1 100644 --- a/vtkm/cont/CoordinateSystem.h +++ b/vtkm/cont/CoordinateSystem.h @@ -31,6 +31,9 @@ public: VTKM_CONT CoordinateSystem(); + // It's OK for regular _point_ fields to become a CoordinateSystem object. + VTKM_CONT CoordinateSystem(const vtkm::cont::Field& src); + VTKM_CONT CoordinateSystem(std::string name, const vtkm::cont::UnknownArrayHandle& data); template diff --git a/vtkm/cont/DataSet.cxx b/vtkm/cont/DataSet.cxx index 26ae43976..f2bdb0693 100644 --- a/vtkm/cont/DataSet.cxx +++ b/vtkm/cont/DataSet.cxx @@ -9,8 +9,11 @@ //============================================================================ #include +#include #include +#include + namespace { @@ -84,7 +87,7 @@ VTKM_CONT void SetGlobalGhostCellFieldName(const std::string& name) noexcept void DataSet::Clear() { - this->CoordSystems.clear(); + this->CoordSystemNames.clear(); this->Fields.Clear(); this->CellSet = this->CellSet.NewInstance(); } @@ -158,10 +161,31 @@ const vtkm::cont::Field& DataSet::GetGhostCellField() const } } -void DataSet::AddCoordinateSystem(const vtkm::cont::CoordinateSystem& cs) +vtkm::IdComponent DataSet::AddCoordinateSystem(const vtkm::cont::CoordinateSystem& cs) { - CheckFieldSize(this->CellSet, cs); - this->CoordSystems.push_back(cs); + this->AddField(cs); + return this->AddCoordinateSystem(cs.GetName()); +} + +vtkm::IdComponent DataSet::AddCoordinateSystem(const std::string& pointFieldName) +{ + // Check to see if we already have this coordinate system. + vtkm::IdComponent index = this->GetCoordinateSystemIndex(pointFieldName); + if (index >= 0) + { + return index; + } + + // Check to make sure this is a valid point field. + if (!this->HasPointField(pointFieldName)) + { + throw vtkm::cont::ErrorBadValue("Cannot set point field named `" + pointFieldName + + "` as a coordinate system because it does not exist."); + } + + // Add the field to the list of coordinates. + this->CoordSystemNames.push_back(pointFieldName); + return static_cast(this->CoordSystemNames.size() - 1); } void DataSet::SetCellSetImpl(const vtkm::cont::UnknownCellSet& cellSet) @@ -211,67 +235,82 @@ void DataSet::SetGhostCellField(const vtkm::cont::UnknownArrayHandle& field) this->SetGhostCellField(GetGlobalGhostCellFieldName(), field); } -void DataSet::CopyStructure(const vtkm::cont::DataSet& source) +void DataSet::CopyPartsFromExcept(const vtkm::cont::DataSet& source, + vtkm::cont::DataSet::Parts partMask) { - this->CoordSystems = source.CoordSystems; - this->CellSet = source.CellSet; - this->GhostCellName = source.GhostCellName; + if ((partMask & vtkm::cont::DataSet::Parts::CellSet) == vtkm::cont::DataSet::Parts::None) + { + this->CellSet = source.CellSet; + } + if ((partMask & vtkm::cont::DataSet::Parts::GhostCellName) == vtkm::cont::DataSet::Parts::None) + { + this->GhostCellName = source.GhostCellName; + } + + if ((partMask & vtkm::cont::DataSet::Parts::Fields) == vtkm::cont::DataSet::Parts::None) + { + vtkm::IdComponent numFields = source.GetNumberOfFields(); + for (vtkm::IdComponent fIndex = 0; fIndex < numFields; ++fIndex) + { + this->AddField(source.GetField(fIndex)); + } + } + + if ((partMask & vtkm::cont::DataSet::Parts::Coordinates) == vtkm::cont::DataSet::Parts::None) + { + vtkm::IdComponent numCoords = source.GetNumberOfCoordinateSystems(); + for (vtkm::IdComponent cIndex = 0; cIndex < numCoords; ++cIndex) + { + std::string coordName = source.GetCoordinateSystemName(cIndex); + if (this->HasPointField(coordName)) + { + this->AddCoordinateSystem(coordName); + } + else + { + this->AddCoordinateSystem(source.GetCoordinateSystem(cIndex)); + } + } + } CheckFieldSizes(this->CellSet, this->Fields); } -const vtkm::cont::CoordinateSystem& DataSet::GetCoordinateSystem(vtkm::Id index) const +vtkm::cont::CoordinateSystem DataSet::GetCoordinateSystem(vtkm::Id index) const { VTKM_ASSERT((index >= 0) && (index < this->GetNumberOfCoordinateSystems())); - return this->CoordSystems[static_cast(index)]; + return this->GetPointField(this->CoordSystemNames[static_cast(index)]); } -vtkm::cont::CoordinateSystem& DataSet::GetCoordinateSystem(vtkm::Id index) +vtkm::IdComponent DataSet::GetCoordinateSystemIndex(const std::string& name) const { - VTKM_ASSERT((index >= 0) && (index < this->GetNumberOfCoordinateSystems())); - return this->CoordSystems[static_cast(index)]; -} - -vtkm::Id DataSet::GetCoordinateSystemIndex(const std::string& name) const -{ - vtkm::Id index = -1; - for (auto i = this->CoordSystems.begin(); i != this->CoordSystems.end(); ++i) + auto nameIter = std::find(this->CoordSystemNames.begin(), this->CoordSystemNames.end(), name); + if (nameIter != this->CoordSystemNames.end()) { - if (i->GetName() == name) - { - index = static_cast(std::distance(this->CoordSystems.begin(), i)); - break; - } + return static_cast(std::distance(this->CoordSystemNames.begin(), nameIter)); + } + else + { + return -1; } - return index; } -const vtkm::cont::CoordinateSystem& DataSet::GetCoordinateSystem(const std::string& name) const +const std::string& DataSet::GetCoordinateSystemName(vtkm::Id index) const +{ + VTKM_ASSERT((index >= 0) && (index < this->GetNumberOfCoordinateSystems())); + return this->CoordSystemNames[static_cast(index)]; +} + +vtkm::cont::CoordinateSystem DataSet::GetCoordinateSystem(const std::string& name) const { vtkm::Id index = this->GetCoordinateSystemIndex(name); if (index < 0) { std::string error_message("No coordinate system with the name " + name + " valid names are: \n"); - for (const auto& cs : this->CoordSystems) + for (const auto& csn : this->CoordSystemNames) { - error_message += cs.GetName() + "\n"; - } - throw vtkm::cont::ErrorBadValue(error_message); - } - return this->GetCoordinateSystem(index); -} - -vtkm::cont::CoordinateSystem& DataSet::GetCoordinateSystem(const std::string& name) -{ - vtkm::Id index = this->GetCoordinateSystemIndex(name); - if (index < 0) - { - std::string error_message("No coordinate system with the name " + name + - " valid names are: \n"); - for (const auto& cs : this->CoordSystems) - { - error_message += cs.GetName() + "\n"; + error_message += csn + "\n"; } throw vtkm::cont::ErrorBadValue(error_message); } @@ -281,11 +320,13 @@ vtkm::cont::CoordinateSystem& DataSet::GetCoordinateSystem(const std::string& na void DataSet::PrintSummary(std::ostream& out) const { out << "DataSet:\n"; - out << " CoordSystems[" << this->CoordSystems.size() << "]\n"; - for (std::size_t index = 0; index < this->CoordSystems.size(); index++) + out << " CoordSystems[" << this->CoordSystemNames.size() << "]\n"; + out << " "; + for (const auto& csn : this->CoordSystemNames) { - this->CoordSystems[index].PrintSummary(out); + out << " " << csn; } + out << "\n"; out << " CellSet \n"; this->GetCellSet().PrintSummary(out); diff --git a/vtkm/cont/DataSet.h b/vtkm/cont/DataSet.h index a23ae3381..36fb0fd2a 100644 --- a/vtkm/cont/DataSet.h +++ b/vtkm/cont/DataSet.h @@ -44,6 +44,19 @@ public: vtkm::cont::DataSet& operator=(const vtkm::cont::DataSet&) = default; + /// \brief An enumeration that can be used to refer to the parts of a `DataSet`. + /// + /// The items can be or'ed together (`|`) to refer to multiple parts. + enum struct Parts : vtkm::UInt32 + { + None = 0x00, + CellSet = 0x01, + Fields = 0x02, + Coordinates = 0x04, + GhostCellName = 0x08, + All = 0xFF + }; + VTKM_CONT void Clear(); /// Get the number of cells contained in this DataSet @@ -259,8 +272,21 @@ public: } + /// \brief Adds the given `CoordinateSystem` to the `DataSet`. + /// + /// The coordinate system will also be added as a point field of the same name. + /// + /// \returns the index assigned to the added coordinate system. VTKM_CONT - void AddCoordinateSystem(const vtkm::cont::CoordinateSystem& cs); + vtkm::IdComponent AddCoordinateSystem(const vtkm::cont::CoordinateSystem& cs); + + /// \brief Marks the point field with the given name as a coordinate system. + /// + /// If no such point field exists or the point field is of the wrong format, an exception + /// will be throw. + /// + /// \returns the index assigned to the added coordinate system. + VTKM_CONT vtkm::IdComponent AddCoordinateSystem(const std::string& pointFieldName); VTKM_CONT bool HasCoordinateSystem(const std::string& name) const @@ -269,34 +295,20 @@ public: } VTKM_CONT - const vtkm::cont::CoordinateSystem& GetCoordinateSystem(vtkm::Id index = 0) const; + vtkm::cont::CoordinateSystem GetCoordinateSystem(vtkm::Id index = 0) const; - VTKM_CONT - vtkm::cont::CoordinateSystem& GetCoordinateSystem(vtkm::Id index = 0); - - /// Returns the index for the first CoordinateSystem whose + /// Returns the index for the CoordinateSystem whose /// name matches the provided string. /// Will return -1 if no match is found VTKM_CONT - vtkm::Id GetCoordinateSystemIndex(const std::string& name) const; + vtkm::IdComponent GetCoordinateSystemIndex(const std::string& name) const; - /// Returns the first CoordinateSystem that matches the provided name. + VTKM_CONT const std::string& GetCoordinateSystemName(vtkm::Id index = 0) const; + + /// Returns the CoordinateSystem that matches the provided name. /// Will throw an exception if no match is found - ///@{ VTKM_CONT - const vtkm::cont::CoordinateSystem& GetCoordinateSystem(const std::string& name) const; - - VTKM_CONT - vtkm::cont::CoordinateSystem& GetCoordinateSystem(const std::string& name); - ///@} - - /// Returns an `std::vector` of `CoordinateSystem`s held in this `DataSet`. - /// - VTKM_CONT - std::vector GetCoordinateSystems() const - { - return this->CoordSystems; - } + vtkm::cont::CoordinateSystem GetCoordinateSystem(const std::string& name) const; template VTKM_CONT void SetCellSet(const CellSetType& cellSet) @@ -317,13 +329,35 @@ public: VTKM_CONT vtkm::IdComponent GetNumberOfCoordinateSystems() const { - return static_cast(this->CoordSystems.size()); + return static_cast(this->CoordSystemNames.size()); } /// Copies the structure i.e. coordinates systems and cellset from the source /// dataset. The fields are left unchanged. + VTKM_DEPRECATED(2.0, "Use CopyPartsFromExcept(source, vtkm::cont::DataSet::Parts::Fields)") VTKM_CONT - void CopyStructure(const vtkm::cont::DataSet& source); + void CopyStructure(const vtkm::cont::DataSet& source) + { + this->CopyPartsFromExcept(source, vtkm::cont::DataSet::Parts::Fields); + } + + /// \brief Copy parts from a source data set. + /// + /// Data from the `source` `DataSet` are copied into this `DataSet`. Where possible, + /// parts like `Field`s and `CoordinateSystem`s from the source are added. Parts that + /// only have one instance in the `DataSet`, such as the `CellSet`, are replaced. + /// + /// By default, all parts are copied. A `partMask` is provided that + /// specifies which parts _not_ to copy. For example, to copy only the structure + /// but not any of the fields, specify to not copy the fields or coordinates as so. + /// + /// ```cpp + /// dest.CopyPartsFromExcept( + /// src, vtkm::cont::DataSet::Parts::Fields | vtkm::cont::DataSet::Parts::Coordinates); + /// ``` + /// + VTKM_CONT + void CopyPartsFromExcept(const vtkm::cont::DataSet& source, vtkm::cont::DataSet::Parts partMask); /// \brief Convert the structures in this data set to expected types. /// @@ -344,7 +378,7 @@ public: void PrintSummary(std::ostream& out) const; private: - std::vector CoordSystems; + std::vector CoordSystemNames; vtkm::cont::internal::FieldCollection Fields{ vtkm::cont::Field::Association::WholeDataSet, vtkm::cont::Field::Association::Points, vtkm::cont::Field::Association::Cells }; @@ -355,6 +389,20 @@ private: VTKM_CONT void SetCellSetImpl(const vtkm::cont::UnknownCellSet& cellSet); }; +VTKM_CONT inline vtkm::cont::DataSet::Parts operator|(vtkm::cont::DataSet::Parts lhs, + vtkm::cont::DataSet::Parts rhs) +{ + using T = std::underlying_type_t; + return static_cast(static_cast(lhs) | static_cast(rhs)); +} + +VTKM_CONT inline vtkm::cont::DataSet::Parts operator&(vtkm::cont::DataSet::Parts lhs, + vtkm::cont::DataSet::Parts rhs) +{ + using T = std::underlying_type_t; + return static_cast(static_cast(lhs) & static_cast(rhs)); +} + } // namespace cont } // namespace vtkm @@ -396,13 +444,6 @@ public: { const auto& dataset = serializable.DataSet; - vtkm::IdComponent numberOfCoordinateSystems = dataset.GetNumberOfCoordinateSystems(); - vtkmdiy::save(bb, numberOfCoordinateSystems); - for (vtkm::IdComponent i = 0; i < numberOfCoordinateSystems; ++i) - { - vtkmdiy::save(bb, dataset.GetCoordinateSystem(i)); - } - vtkmdiy::save(bb, dataset.GetCellSet().ResetCellSetList(CellSetTypesList{})); vtkm::IdComponent numberOfFields = dataset.GetNumberOfFields(); @@ -411,6 +452,13 @@ public: { vtkmdiy::save(bb, dataset.GetField(i)); } + + vtkm::IdComponent numberOfCoordinateSystems = dataset.GetNumberOfCoordinateSystems(); + vtkmdiy::save(bb, numberOfCoordinateSystems); + for (vtkm::IdComponent i = 0; i < numberOfCoordinateSystems; ++i) + { + vtkmdiy::save(bb, dataset.GetCoordinateSystemName(i)); + } } static VTKM_CONT void load(BinaryBuffer& bb, Type& serializable) @@ -418,15 +466,6 @@ public: auto& dataset = serializable.DataSet; dataset = {}; // clear - vtkm::IdComponent numberOfCoordinateSystems = 0; - vtkmdiy::load(bb, numberOfCoordinateSystems); - for (vtkm::IdComponent i = 0; i < numberOfCoordinateSystems; ++i) - { - vtkm::cont::CoordinateSystem coords; - vtkmdiy::load(bb, coords); - dataset.AddCoordinateSystem(coords); - } - vtkm::cont::UncertainCellSet cells; vtkmdiy::load(bb, cells); dataset.SetCellSet(cells); @@ -439,6 +478,15 @@ public: vtkmdiy::load(bb, field); dataset.AddField(field); } + + vtkm::IdComponent numberOfCoordinateSystems = 0; + vtkmdiy::load(bb, numberOfCoordinateSystems); + for (vtkm::IdComponent i = 0; i < numberOfCoordinateSystems; ++i) + { + std::string coordName; + vtkmdiy::load(bb, coordName); + dataset.AddCoordinateSystem(coordName); + } } }; diff --git a/vtkm/cont/testing/UnitTestDataSetBuilderCurvilinear.cxx b/vtkm/cont/testing/UnitTestDataSetBuilderCurvilinear.cxx index 222ebb572..e60c8f9a8 100644 --- a/vtkm/cont/testing/UnitTestDataSetBuilderCurvilinear.cxx +++ b/vtkm/cont/testing/UnitTestDataSetBuilderCurvilinear.cxx @@ -29,7 +29,7 @@ void ValidateDataSet(const vtkm::cont::DataSet& ds, { //Verify basics.. - VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 2, "Wrong number of fields."); + VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 3, "Wrong number of fields."); VTKM_TEST_ASSERT(ds.GetNumberOfCoordinateSystems() == 1, "Wrong number of coordinate systems."); VTKM_TEST_ASSERT(ds.GetNumberOfPoints() == numPoints, "Wrong number of coordinates."); VTKM_TEST_ASSERT(ds.GetNumberOfCells() == numCells, "Wrong number of cells."); diff --git a/vtkm/cont/testing/UnitTestDataSetBuilderExplicit.cxx b/vtkm/cont/testing/UnitTestDataSetBuilderExplicit.cxx index 6acb61586..641444f37 100644 --- a/vtkm/cont/testing/UnitTestDataSetBuilderExplicit.cxx +++ b/vtkm/cont/testing/UnitTestDataSetBuilderExplicit.cxx @@ -37,7 +37,7 @@ void ValidateDataSet(const vtkm::cont::DataSet& ds, const vtkm::Bounds& bounds) { //Verify basics.. - VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 2, "Wrong number of fields."); + VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 3, "Wrong number of fields."); VTKM_TEST_ASSERT(ds.GetNumberOfCoordinateSystems() == 1, "Wrong number of coordinate systems."); VTKM_TEST_ASSERT(ds.GetNumberOfPoints() == numPoints, "Wrong number of coordinates."); VTKM_TEST_ASSERT(ds.GetNumberOfCells() == numCells, "Wrong number of cells."); diff --git a/vtkm/cont/testing/UnitTestDataSetBuilderRectilinear.cxx b/vtkm/cont/testing/UnitTestDataSetBuilderRectilinear.cxx index b9c97785d..dd0d2a04e 100644 --- a/vtkm/cont/testing/UnitTestDataSetBuilderRectilinear.cxx +++ b/vtkm/cont/testing/UnitTestDataSetBuilderRectilinear.cxx @@ -30,7 +30,7 @@ void ValidateDataSet(const vtkm::cont::DataSet& ds, { //Verify basics.. - VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 2, "Wrong number of fields."); + VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 3, "Wrong number of fields."); VTKM_TEST_ASSERT(ds.GetNumberOfCoordinateSystems() == 1, "Wrong number of coordinate systems."); VTKM_TEST_ASSERT(ds.GetNumberOfPoints() == numPoints, "Wrong number of coordinates."); VTKM_TEST_ASSERT(ds.GetNumberOfCells() == numCells, "Wrong number of cells."); diff --git a/vtkm/cont/testing/UnitTestDataSetBuilderUniform.cxx b/vtkm/cont/testing/UnitTestDataSetBuilderUniform.cxx index c35fa48bf..a7195b7be 100644 --- a/vtkm/cont/testing/UnitTestDataSetBuilderUniform.cxx +++ b/vtkm/cont/testing/UnitTestDataSetBuilderUniform.cxx @@ -31,7 +31,7 @@ void ValidateDataSet(const vtkm::cont::DataSet& ds, { //Verify basics.. - VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 2, "Wrong number of fields."); + VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 3, "Wrong number of fields."); VTKM_TEST_ASSERT(ds.GetNumberOfCoordinateSystems() == 1, "Wrong number of coordinate systems."); VTKM_TEST_ASSERT(ds.GetNumberOfPoints() == numPoints, "Wrong number of coordinates."); VTKM_TEST_ASSERT(ds.GetNumberOfCells() == numCells, "Wrong number of cells."); diff --git a/vtkm/cont/testing/UnitTestDataSetExplicit.cxx b/vtkm/cont/testing/UnitTestDataSetExplicit.cxx index 56abcf63a..0fc67d86f 100644 --- a/vtkm/cont/testing/UnitTestDataSetExplicit.cxx +++ b/vtkm/cont/testing/UnitTestDataSetExplicit.cxx @@ -44,7 +44,7 @@ void TestDataSet_Explicit() vtkm::cont::testing::MakeTestDataSet tds; vtkm::cont::DataSet ds = tds.Make3DExplicitDataSet0(); - VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 2, "Incorrect number of fields"); + VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 3, "Incorrect number of fields"); // test various field-getting methods and associations const vtkm::cont::Field& f1 = ds.GetField("pointvar"); diff --git a/vtkm/cont/testing/UnitTestDataSetRectilinear.cxx b/vtkm/cont/testing/UnitTestDataSetRectilinear.cxx index 68b8f8588..f1aa27f25 100644 --- a/vtkm/cont/testing/UnitTestDataSetRectilinear.cxx +++ b/vtkm/cont/testing/UnitTestDataSetRectilinear.cxx @@ -42,7 +42,7 @@ static void TwoDimRectilinearTest() vtkm::cont::CellSetStructured<2> cellSet; dataSet.GetCellSet().AsCellSet(cellSet); - VTKM_TEST_ASSERT(dataSet.GetNumberOfFields() == 2, "Incorrect number of fields"); + VTKM_TEST_ASSERT(dataSet.GetNumberOfFields() == 3, "Incorrect number of fields"); VTKM_TEST_ASSERT(dataSet.GetNumberOfCoordinateSystems() == 1, "Incorrect number of coordinate systems"); VTKM_TEST_ASSERT(cellSet.GetNumberOfPoints() == 6, "Incorrect number of points"); @@ -128,7 +128,7 @@ static void ThreeDimRectilinearTest() vtkm::cont::CellSetStructured<3> cellSet; dataSet.GetCellSet().AsCellSet(cellSet); - VTKM_TEST_ASSERT(dataSet.GetNumberOfFields() == 2, "Incorrect number of fields"); + VTKM_TEST_ASSERT(dataSet.GetNumberOfFields() == 3, "Incorrect number of fields"); VTKM_TEST_ASSERT(dataSet.GetNumberOfCoordinateSystems() == 1, "Incorrect number of coordinate systems"); diff --git a/vtkm/cont/testing/UnitTestDataSetUniform.cxx b/vtkm/cont/testing/UnitTestDataSetUniform.cxx index f97dfc775..ff400c015 100644 --- a/vtkm/cont/testing/UnitTestDataSetUniform.cxx +++ b/vtkm/cont/testing/UnitTestDataSetUniform.cxx @@ -43,7 +43,7 @@ static void TwoDimUniformTest() vtkm::cont::CellSetStructured<2> cellSet; dataSet.GetCellSet().AsCellSet(cellSet); - VTKM_TEST_ASSERT(dataSet.GetNumberOfFields() == 2, "Incorrect number of fields"); + VTKM_TEST_ASSERT(dataSet.GetNumberOfFields() == 3, "Incorrect number of fields"); VTKM_TEST_ASSERT(dataSet.GetNumberOfCoordinateSystems() == 1, "Incorrect number of coordinate systems"); VTKM_TEST_ASSERT(cellSet.GetNumberOfPoints() == 6, "Incorrect number of points"); @@ -132,7 +132,7 @@ static void ThreeDimUniformTest() vtkm::cont::CellSetStructured<3> cellSet; dataSet.GetCellSet().AsCellSet(cellSet); - VTKM_TEST_ASSERT(dataSet.GetNumberOfFields() == 2, "Incorrect number of fields"); + VTKM_TEST_ASSERT(dataSet.GetNumberOfFields() == 3, "Incorrect number of fields"); VTKM_TEST_ASSERT(dataSet.GetNumberOfCoordinateSystems() == 1, "Incorrect number of coordinate systems"); diff --git a/vtkm/cont/testing/UnitTestPartitionedDataSet.cxx b/vtkm/cont/testing/UnitTestPartitionedDataSet.cxx index 49a336669..78c1c760c 100644 --- a/vtkm/cont/testing/UnitTestPartitionedDataSet.cxx +++ b/vtkm/cont/testing/UnitTestPartitionedDataSet.cxx @@ -224,6 +224,11 @@ void DataSet_Compare(vtkm::cont::DataSet& leftDataSet, vtkm::cont::DataSet& righ { for (vtkm::Id j = 0; j < leftDataSet.GetNumberOfFields(); j++) { + if (leftDataSet.HasCoordinateSystem(leftDataSet.GetField(j).GetName())) + { + // Skip coordinate systems, which have a different array type. + continue; + } vtkm::cont::ArrayHandle lDataArray; leftDataSet.GetField(j).GetData().AsArrayHandle(lDataArray); vtkm::cont::ArrayHandle rDataArray; diff --git a/vtkm/filter/NewFilter.cxx b/vtkm/filter/NewFilter.cxx index cea0a3dd7..77b6ba396 100644 --- a/vtkm/filter/NewFilter.cxx +++ b/vtkm/filter/NewFilter.cxx @@ -109,11 +109,14 @@ vtkm::cont::PartitionedDataSet NewFilter::Execute(const vtkm::cont::PartitionedD vtkm::cont::DataSet NewFilter::CreateResult(const vtkm::cont::DataSet& inDataSet) const { vtkm::cont::DataSet clone; - clone.CopyStructure(inDataSet); - this->MapFieldsOntoOutput( - inDataSet, clone, [](vtkm::cont::DataSet& out, const vtkm::cont::Field& fieldToPass) { - out.AddField(fieldToPass); - }); + clone.CopyPartsFromExcept( + inDataSet, vtkm::cont::DataSet::Parts::Fields | vtkm::cont::DataSet::Parts::Coordinates); + this->MapFieldsOntoOutput(inDataSet, + this->GetFieldsToPass(), + clone, + [](vtkm::cont::DataSet& out, const vtkm::cont::Field& fieldToPass) { + out.AddField(fieldToPass); + }); return clone; } diff --git a/vtkm/filter/NewFilter.h b/vtkm/filter/NewFilter.h index 1b2458cda..44654f965 100644 --- a/vtkm/filter/NewFilter.h +++ b/vtkm/filter/NewFilter.h @@ -150,7 +150,7 @@ namespace filter /// }; /// // This passes coordinate systems directly from input to output. If the points of /// // the cell set change at all, they will have to be mapped by hand. -/// return this->CreateResult(input, outCellSet, input.GetCoordinateSystems(), mapper); +/// return this->CreateResult(input, outCellSet, mapper); /// } /// \endcode /// @@ -188,15 +188,15 @@ namespace filter /// // thus making it thread-safe. /// SharedStates states; /// -/// vtkm::cont::DataSet output; -/// output = ... // Generation of the new DataSet and store interpolation parameters in `states` +/// vtkm::cont::CellSetExplicit<> cellSet; +/// cellSet = ... // Generation of the new DataSet and store interpolation parameters in `states` /// /// // Lambda capture of `states`, effectively passing the shared states to the Mapper. /// auto mapper = [&states](auto& outputDs, const auto& inputField) { /// auto outputField = ... // Use `states` for mapping input field to output field /// output.AddField(outputField); /// }; -/// this->MapFieldsOntoOutput(input, output, mapper); +/// this->CreateOutput(input, cellSet, mapper); /// /// return output; /// } @@ -292,6 +292,21 @@ public: vtkm::filter::FieldSelection& GetFieldsToPass() { return this->FieldsToPass; } ///@} + ///@{ + /// \brief Specify whether to always pass coordinate systems. + /// + /// `CoordinateSystem`s in a `DataSet` are really just point fields marked as being a + /// coordinate system. Thus, a coordinate system is passed if and only if the associated + /// field is passed. + /// + /// By default, the filter will pass all fields associated with a coordinate system + /// regardless of the `FieldsToPass` marks the field as passing. If this option is set + /// to `false`, then coordinate systems will only be passed if it is marked so by + /// `FieldsToPass`. + VTKM_CONT void SetPassCoordinateSystems(bool flag) { this->PassCoordinateSystems = flag; } + VTKM_CONT bool GetPassCoordinateSystems() const { return this->PassCoordinateSystems; } + ///@} + ///@{ /// Executes the filter on the input and produces a result dataset. /// @@ -357,7 +372,6 @@ protected: /// argument and a `Field` as its second argument. The `PartitionedDataSet` is the data being /// created and will eventually be returned by `CreateResult`. The `Field` comes from `input`. /// - template VTKM_CONT vtkm::cont::PartitionedDataSet CreateResult( const vtkm::cont::PartitionedDataSet& input, @@ -365,7 +379,7 @@ protected: FieldMapper&& fieldMapper) const { vtkm::cont::PartitionedDataSet output(resultPartitions.GetPartitions()); - this->MapFieldsOntoOutput(input, output, fieldMapper); + this->MapFieldsOntoOutput(input, this->GetFieldsToPass(), output, fieldMapper); return output; } @@ -376,9 +390,6 @@ protected: /// being created and a `Field` from the input and then applies any necessary transformations to /// the field array and adds it to the `DataSet`. /// - /// This form of `CreateResult` returns a `DataSet` with _no_ coordinate systems. The calling - /// program must add any necessary `CoordinateSystem`s. - /// /// \param[in] inDataSet The input data set being modified (usually the one passed /// into `DoExecute`). The returned `DataSet` is filled with fields of `inDataSet` /// (as selected by the `FieldsToPass` state of the filter). @@ -396,8 +407,12 @@ protected: FieldMapper&& fieldMapper) const { vtkm::cont::DataSet outDataSet; + outDataSet.CopyPartsFromExcept(inDataSet, + vtkm::cont::DataSet::Parts::Fields | + vtkm::cont::DataSet::Parts::Coordinates | + vtkm::cont::DataSet::Parts::CellSet); outDataSet.SetCellSet(resultCellSet); - this->MapFieldsOntoOutput(inDataSet, outDataSet, fieldMapper); + this->MapFieldsOntoOutput(inDataSet, this->GetFieldsToPass(), outDataSet, fieldMapper); return outDataSet; } @@ -436,6 +451,7 @@ protected: return outDataSet; } + ///@{ /// \brief Create the output data set for `DoExecute`. /// /// This form of `CreateResult` will create an output data set with the given `CellSet` @@ -457,31 +473,89 @@ protected: /// the function should do nothing. /// template - VTKM_CONT vtkm::cont::DataSet CreateResult(const vtkm::cont::DataSet& inDataSet, - const vtkm::cont::UnknownCellSet& resultCellSet, - const vtkm::cont::CoordinateSystem& resultCoordSystem, - FieldMapper&& fieldMapper) const + VTKM_CONT vtkm::cont::DataSet CreateResultCoordinateSystem( + const vtkm::cont::DataSet& inDataSet, + const vtkm::cont::UnknownCellSet& resultCellSet, + const vtkm::cont::CoordinateSystem& resultCoordSystem, + FieldMapper&& fieldMapper) const { - return this->CreateResult(inDataSet, - resultCellSet, - std::vector{ resultCoordSystem }, - fieldMapper); + vtkm::cont::DataSet outDataSet; + outDataSet.CopyPartsFromExcept(inDataSet, + vtkm::cont::DataSet::Parts::Fields | + vtkm::cont::DataSet::Parts::Coordinates | + vtkm::cont::DataSet::Parts::CellSet); + outDataSet.SetCellSet(resultCellSet); + outDataSet.AddCoordinateSystem(resultCoordSystem); + vtkm::filter::FieldSelection fieldSelection = this->GetFieldsToPass(); + fieldSelection.AddField(resultCoordSystem, vtkm::filter::FieldSelection::Mode::Exclude); + this->MapFieldsOntoOutput(inDataSet, fieldSelection, outDataSet, fieldMapper); + return outDataSet; } + template + VTKM_CONT vtkm::cont::DataSet CreateResultCoordinateSystem( + const vtkm::cont::DataSet& inDataSet, + const vtkm::cont::UnknownCellSet& resultCellSet, + const std::string& coordsName, + const vtkm::cont::UnknownArrayHandle& coordsData, + FieldMapper&& fieldMapper) const + { + return this->CreateResultCoordinateSystem( + inDataSet, + resultCellSet, + vtkm::cont::CoordinateSystem{ coordsName, coordsData }, + fieldMapper); + } + ///@} + VTKM_CONT virtual vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& inData) = 0; VTKM_CONT virtual vtkm::cont::PartitionedDataSet DoExecutePartitions( const vtkm::cont::PartitionedDataSet& inData); private: - template - VTKM_CONT void MapFieldsOntoOutput(const DataSetType& input, - DataSetType& output, + template + VTKM_CONT void MapFieldsOntoOutput(const vtkm::cont::DataSet& input, + const vtkm::filter::FieldSelection& fieldSelection, + vtkm::cont::DataSet& output, FieldMapper&& fieldMapper) const { for (vtkm::IdComponent cc = 0; cc < input.GetNumberOfFields(); ++cc) { auto field = input.GetField(cc); - if (this->GetFieldsToPass().IsFieldSelected(field)) + if (fieldSelection.IsFieldSelected(field)) + { + fieldMapper(output, field); + } + } + + for (vtkm::IdComponent csIndex = 0; csIndex < input.GetNumberOfCoordinateSystems(); ++csIndex) + { + auto coords = input.GetCoordinateSystem(csIndex); + if (!output.HasCoordinateSystem(coords.GetName())) + { + if (!output.HasPointField(coords.GetName()) && + (this->GetPassCoordinateSystems() || this->GetFieldsToPass().IsFieldSelected(coords))) + { + fieldMapper(output, coords); + } + if (output.HasPointField(coords.GetName())) + { + output.AddCoordinateSystem(coords.GetName()); + } + } + } + } + + template + VTKM_CONT void MapFieldsOntoOutput(const vtkm::cont::PartitionedDataSet& input, + const vtkm::filter::FieldSelection& fieldSelection, + vtkm::cont::PartitionedDataSet& output, + FieldMapper&& fieldMapper) const + { + for (vtkm::IdComponent cc = 0; cc < input.GetNumberOfFields(); ++cc) + { + auto field = input.GetField(cc); + if (fieldSelection.IsFieldSelected(field)) { fieldMapper(output, field); } @@ -493,6 +567,7 @@ private: vtkm::filter::FieldSelection FieldsToPass = vtkm::filter::FieldSelection::Mode::All; + bool PassCoordinateSystems = true; bool RunFilterWithMultipleThreads = false; vtkm::Id NumThreadsPerCPU = 4; vtkm::Id NumThreadsPerGPU = 8; diff --git a/vtkm/filter/NewFilterField.h b/vtkm/filter/NewFilterField.h index 0c5f8ba9c..49c24b32b 100644 --- a/vtkm/filter/NewFilterField.h +++ b/vtkm/filter/NewFilterField.h @@ -133,7 +133,12 @@ protected: { if (this->UseCoordinateSystemAsField[index]) { - return input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex(index)); + // Note that we cannot use input.GetCoordinateSystem because that does not return + // a reference to a field. Instead, get the field name for the coordinate system + // and return the field. + const std::string& coordSystemName = + input.GetCoordinateSystemName(this->GetActiveCoordinateSystemIndex(index)); + return input.GetPointField(coordSystemName); } else { diff --git a/vtkm/filter/clean_grid/testing/UnitTestCleanGrid.cxx b/vtkm/filter/clean_grid/testing/UnitTestCleanGrid.cxx index 2145a34ce..740e6d9dc 100644 --- a/vtkm/filter/clean_grid/testing/UnitTestCleanGrid.cxx +++ b/vtkm/filter/clean_grid/testing/UnitTestCleanGrid.cxx @@ -76,7 +76,7 @@ void TestPointMerging() //filter for uniform data always does point merging vtkm::cont::ArrayHandle newcoords; vtkm::cont::ArrayCopy(baseData.GetCoordinateSystem().GetData(), newcoords); - baseData.GetCoordinateSystem().SetData(newcoords); + baseData.AddPointField(baseData.GetCoordinateSystemName(), newcoords); vtkm::filter::contour::Contour marchingCubes; marchingCubes.SetIsoValue(0.05); diff --git a/vtkm/filter/contour/Contour.cxx b/vtkm/filter/contour/Contour.cxx index d16778bc9..4dbb51149 100644 --- a/vtkm/filter/contour/Contour.cxx +++ b/vtkm/filter/contour/Contour.cxx @@ -144,8 +144,8 @@ vtkm::cont::DataSet Contour::DoExecute(const vtkm::cont::DataSet& inDataSet) resolveFieldType); auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f, worklet); }; - vtkm::cont::DataSet output = this->CreateResult( - inDataSet, outputCells, vtkm::cont::CoordinateSystem{ "coordinates", vertices }, mapper); + vtkm::cont::DataSet output = this->CreateResultCoordinateSystem( + inDataSet, outputCells, inputCoords.GetName(), vertices, mapper); if (this->GenerateNormals) { diff --git a/vtkm/filter/contour/MIRFilter.cxx b/vtkm/filter/contour/MIRFilter.cxx index dcac6fb44..ea2e18dfc 100644 --- a/vtkm/filter/contour/MIRFilter.cxx +++ b/vtkm/filter/contour/MIRFilter.cxx @@ -335,7 +335,8 @@ VTKM_CONT vtkm::cont::DataSet MIRFilter::DoExecute(const vtkm::cont::DataSet& in auto mapper = [&](auto& outDataSet, const auto& f) { this->DoMapField(outDataSet, f, filterCellInterp, MIRWeights, MIRIDs); }; - auto output = this->CreateResult(input, saved.GetCellSet(), saved.GetCoordinateSystems(), mapper); + auto output = this->CreateResultCoordinateSystem( + input, saved.GetCellSet(), saved.GetCoordinateSystem(), mapper); output.AddField(saved.GetField(this->GetOutputFieldName())); return output; diff --git a/vtkm/filter/contour/testing/UnitTestClipWithFieldFilter.cxx b/vtkm/filter/contour/testing/UnitTestClipWithFieldFilter.cxx index bef6f0975..3e854f9d0 100644 --- a/vtkm/filter/contour/testing/UnitTestClipWithFieldFilter.cxx +++ b/vtkm/filter/contour/testing/UnitTestClipWithFieldFilter.cxx @@ -63,7 +63,7 @@ void TestClipExplicit() VTKM_TEST_ASSERT(outputData.GetNumberOfCoordinateSystems() == 1, "Wrong number of coordinate systems in the output dataset"); - VTKM_TEST_ASSERT(outputData.GetNumberOfFields() == 1, + VTKM_TEST_ASSERT(outputData.GetNumberOfFields() == 2, "Wrong number of fields in the output dataset"); auto temp = outputData.GetField("scalars").GetData(); diff --git a/vtkm/filter/contour/testing/UnitTestClipWithImplicitFunctionFilter.cxx b/vtkm/filter/contour/testing/UnitTestClipWithImplicitFunctionFilter.cxx index 36feba3e4..d8f0e834b 100644 --- a/vtkm/filter/contour/testing/UnitTestClipWithImplicitFunctionFilter.cxx +++ b/vtkm/filter/contour/testing/UnitTestClipWithImplicitFunctionFilter.cxx @@ -62,7 +62,7 @@ void TestClipStructured(vtkm::Float64 offset) VTKM_TEST_ASSERT(outputData.GetNumberOfCoordinateSystems() == 1, "Wrong number of coordinate systems in the output dataset"); - VTKM_TEST_ASSERT(outputData.GetNumberOfFields() == 1, + VTKM_TEST_ASSERT(outputData.GetNumberOfFields() == 2, "Wrong number of fields in the output dataset"); VTKM_TEST_ASSERT(outputData.GetNumberOfCells() == 8, "Wrong number of cells in the output dataset"); @@ -98,7 +98,7 @@ void TestClipStructuredInverted() clip.SetFieldsToPass("scalars"); auto outputData = clip.Execute(ds); - VTKM_TEST_ASSERT(outputData.GetNumberOfFields() == 1, + VTKM_TEST_ASSERT(outputData.GetNumberOfFields() == 2, "Wrong number of fields in the output dataset"); VTKM_TEST_ASSERT(outputData.GetNumberOfCells() == 4, "Wrong number of cells in the output dataset"); diff --git a/vtkm/filter/contour/testing/UnitTestContourFilter.cxx b/vtkm/filter/contour/testing/UnitTestContourFilter.cxx index d99445d68..9d93c8ea8 100644 --- a/vtkm/filter/contour/testing/UnitTestContourFilter.cxx +++ b/vtkm/filter/contour/testing/UnitTestContourFilter.cxx @@ -50,7 +50,7 @@ public: VTKM_TEST_ASSERT(result.GetNumberOfCoordinateSystems() == 1, "Wrong number of coordinate systems in the output dataset"); //since normals is on we have one field - VTKM_TEST_ASSERT(result.GetNumberOfFields() == 1, + VTKM_TEST_ASSERT(result.GetNumberOfFields() == 2, "Wrong number of fields in the output dataset"); } @@ -61,7 +61,7 @@ public: const bool isMapped = result.HasField("tangle"); VTKM_TEST_ASSERT(isMapped, "mapping should pass"); - VTKM_TEST_ASSERT(result.GetNumberOfFields() == 3, + VTKM_TEST_ASSERT(result.GetNumberOfFields() == 4, "Wrong number of fields in the output dataset"); //verify the cellvar result diff --git a/vtkm/filter/entity_extraction/ExternalFaces.cxx b/vtkm/filter/entity_extraction/ExternalFaces.cxx index d5711c6da..9c2d4a527 100644 --- a/vtkm/filter/entity_extraction/ExternalFaces.cxx +++ b/vtkm/filter/entity_extraction/ExternalFaces.cxx @@ -60,7 +60,7 @@ vtkm::cont::DataSet ExternalFaces::GenerateOutput(const vtkm::cont::DataSet& inp // New Design: We are still using the old MapFieldOntoOutput to demonstrate the transition this->MapFieldOntoOutput(result, f); }; - return this->CreateResult(input, outCellSet, input.GetCoordinateSystems(), mapper); + return this->CreateResult(input, outCellSet, mapper); } //----------------------------------------------------------------------------- diff --git a/vtkm/filter/entity_extraction/ExtractGeometry.cxx b/vtkm/filter/entity_extraction/ExtractGeometry.cxx index 9361c115f..4e2d0229d 100644 --- a/vtkm/filter/entity_extraction/ExtractGeometry.cxx +++ b/vtkm/filter/entity_extraction/ExtractGeometry.cxx @@ -70,7 +70,7 @@ vtkm::cont::DataSet ExtractGeometry::DoExecute(const vtkm::cont::DataSet& input) // create the output dataset auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f, worklet); }; - return this->CreateResult(input, outCells, input.GetCoordinateSystems(), mapper); + return this->CreateResult(input, outCells, mapper); } } // namespace entity_extraction diff --git a/vtkm/filter/entity_extraction/ExtractPoints.cxx b/vtkm/filter/entity_extraction/ExtractPoints.cxx index 4f0c95d50..25648b383 100644 --- a/vtkm/filter/entity_extraction/ExtractPoints.cxx +++ b/vtkm/filter/entity_extraction/ExtractPoints.cxx @@ -59,8 +59,7 @@ vtkm::cont::DataSet ExtractPoints::DoExecute(const vtkm::cont::DataSet& input) // create the output dataset auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f); }; - vtkm::cont::DataSet output = - this->CreateResult(input, outCellSet, input.GetCoordinateSystems(), mapper); + vtkm::cont::DataSet output = this->CreateResult(input, outCellSet, mapper); // compact the unused points in the output dataset if (this->CompactPoints) diff --git a/vtkm/filter/entity_extraction/ExtractStructured.cxx b/vtkm/filter/entity_extraction/ExtractStructured.cxx index 399ab9b3e..a1962fb51 100644 --- a/vtkm/filter/entity_extraction/ExtractStructured.cxx +++ b/vtkm/filter/entity_extraction/ExtractStructured.cxx @@ -15,27 +15,45 @@ namespace { -VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result, +VTKM_CONT void DoMapField(vtkm::cont::DataSet& result, const vtkm::cont::Field& field, const vtkm::cont::ArrayHandle& CellFieldMap, - const vtkm::cont::ArrayHandle& PointFieldMap) + const vtkm::cont::ArrayHandle& PointFieldMap, + const vtkm::worklet::ExtractStructured& worklet) { if (field.IsPointField()) { - return vtkm::filter::MapFieldPermutation(field, PointFieldMap, result); + vtkm::cont::UnknownArrayHandle array = field.GetData(); + using UniformCoordinatesArrayHandle = + vtkm::worklet::ExtractStructured::UniformCoordinatesArrayHandle; + using RectilinearCoordinatesArrayHandle = + vtkm::worklet::ExtractStructured::RectilinearCoordinatesArrayHandle; + if (array.CanConvert()) + { + // Special case that is more efficient for uniform coordinate arrays. + UniformCoordinatesArrayHandle newCoords = + worklet.MapCoordinatesUniform(array.AsArrayHandle()); + result.AddField(vtkm::cont::Field(field.GetName(), field.GetAssociation(), newCoords)); + } + else if (array.CanConvert()) + { + // Special case that is more efficient for uniform coordinate arrays. + RectilinearCoordinatesArrayHandle newCoords = + worklet.MapCoordinatesRectilinear(array.AsArrayHandle()); + result.AddField(vtkm::cont::Field(field.GetName(), field.GetAssociation(), newCoords)); + } + else + { + vtkm::filter::MapFieldPermutation(field, PointFieldMap, result); + } } else if (field.IsCellField()) { - return vtkm::filter::MapFieldPermutation(field, CellFieldMap, result); + vtkm::filter::MapFieldPermutation(field, CellFieldMap, result); } else if (field.IsWholeDataSetField()) { result.AddField(field); - return true; - } - else - { - return false; } } } // anonymous namespace @@ -50,7 +68,6 @@ namespace entity_extraction vtkm::cont::DataSet ExtractStructured::DoExecute(const vtkm::cont::DataSet& input) { const vtkm::cont::UnknownCellSet& cells = input.GetCellSet(); - const vtkm::cont::CoordinateSystem& coordinates = input.GetCoordinateSystem(); vtkm::worklet::ExtractStructured worklet; auto cellset = worklet.Run(cells.ResetCellSetList(), @@ -59,9 +76,6 @@ vtkm::cont::DataSet ExtractStructured::DoExecute(const vtkm::cont::DataSet& inpu this->IncludeBoundary, this->IncludeOffset); - auto coords = worklet.MapCoordinates(coordinates); - vtkm::cont::CoordinateSystem outputCoordinates(coordinates.GetName(), coords); - // Create map arrays for mapping fields. Could potentially save some time to first check to see // if these arrays would be used. auto CellFieldMap = @@ -70,9 +84,9 @@ vtkm::cont::DataSet ExtractStructured::DoExecute(const vtkm::cont::DataSet& inpu worklet.ProcessPointField(vtkm::cont::ArrayHandleIndex(input.GetNumberOfPoints())); auto mapper = [&](auto& result, const auto& f) { - DoMapField(result, f, CellFieldMap, PointFieldMap); + DoMapField(result, f, CellFieldMap, PointFieldMap, worklet); }; - return this->CreateResult(input, cellset, outputCoordinates, mapper); + return this->CreateResult(input, cellset, mapper); } } // namespace entity_extraction diff --git a/vtkm/filter/entity_extraction/GhostCellRemove.cxx b/vtkm/filter/entity_extraction/GhostCellRemove.cxx index 546e898b7..1d6a8ffb7 100644 --- a/vtkm/filter/entity_extraction/GhostCellRemove.cxx +++ b/vtkm/filter/entity_extraction/GhostCellRemove.cxx @@ -367,7 +367,7 @@ VTKM_CONT vtkm::cont::DataSet GhostCellRemove::DoExecute(const vtkm::cont::DataS } auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f, worklet); }; - return this->CreateResult(input, cellOut, input.GetCoordinateSystems(), mapper); + return this->CreateResult(input, cellOut, mapper); } } diff --git a/vtkm/filter/entity_extraction/Mask.cxx b/vtkm/filter/entity_extraction/Mask.cxx index 44dc79b19..b7f89d467 100644 --- a/vtkm/filter/entity_extraction/Mask.cxx +++ b/vtkm/filter/entity_extraction/Mask.cxx @@ -51,7 +51,7 @@ VTKM_CONT vtkm::cont::DataSet Mask::DoExecute(const vtkm::cont::DataSet& input) // create the output dataset auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f, worklet); }; - return this->CreateResult(input, cellOut, input.GetCoordinateSystems(), mapper); + return this->CreateResult(input, cellOut, mapper); } } // namespace entity_extraction } // namespace filter diff --git a/vtkm/filter/entity_extraction/MaskPoints.cxx b/vtkm/filter/entity_extraction/MaskPoints.cxx index 564656f3e..7b8f977d7 100644 --- a/vtkm/filter/entity_extraction/MaskPoints.cxx +++ b/vtkm/filter/entity_extraction/MaskPoints.cxx @@ -56,8 +56,7 @@ VTKM_CONT vtkm::cont::DataSet MaskPoints::DoExecute(const vtkm::cont::DataSet& i // create the output dataset auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f); }; - vtkm::cont::DataSet output = - this->CreateResult(input, outCellSet, input.GetCoordinateSystems(), mapper); + vtkm::cont::DataSet output = this->CreateResult(input, outCellSet, mapper); // compact the unused points in the output dataset if (this->CompactPoints) diff --git a/vtkm/filter/entity_extraction/Threshold.cxx b/vtkm/filter/entity_extraction/Threshold.cxx index 8a86c5a8a..1d3c5765a 100644 --- a/vtkm/filter/entity_extraction/Threshold.cxx +++ b/vtkm/filter/entity_extraction/Threshold.cxx @@ -148,7 +148,7 @@ vtkm::cont::DataSet Threshold::DoExecute(const vtkm::cont::DataSet& input) vtkm::ListForEach(callWithArrayBaseComponent, vtkm::TypeListScalarAll{}); auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f, worklet); }; - return this->CreateResult(input, cellOut, input.GetCoordinateSystems(), mapper); + return this->CreateResult(input, cellOut, mapper); } } // namespace entity_extraction } // namespace filter diff --git a/vtkm/filter/entity_extraction/ThresholdPoints.cxx b/vtkm/filter/entity_extraction/ThresholdPoints.cxx index 173e4af3d..ecceddc0a 100644 --- a/vtkm/filter/entity_extraction/ThresholdPoints.cxx +++ b/vtkm/filter/entity_extraction/ThresholdPoints.cxx @@ -174,8 +174,7 @@ VTKM_CONT vtkm::cont::DataSet ThresholdPoints::DoExecute(const vtkm::cont::DataS // create the output dataset auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f); }; - vtkm::cont::DataSet output = - this->CreateResult(input, outCellSet, input.GetCoordinateSystems(), mapper); + vtkm::cont::DataSet output = this->CreateResult(input, outCellSet, mapper); // compact the unused points in the output dataset if (this->CompactPoints) diff --git a/vtkm/filter/entity_extraction/testing/UnitTestThresholdFilter.cxx b/vtkm/filter/entity_extraction/testing/UnitTestThresholdFilter.cxx index 8ace0db57..9ade1efb0 100644 --- a/vtkm/filter/entity_extraction/testing/UnitTestThresholdFilter.cxx +++ b/vtkm/filter/entity_extraction/testing/UnitTestThresholdFilter.cxx @@ -49,7 +49,7 @@ public: if (returnAllInRange) { - VTKM_TEST_ASSERT(output.GetNumberOfFields() == 1, + VTKM_TEST_ASSERT(output.GetNumberOfFields() == 2, "Wrong number of fields in the output dataset"); vtkm::cont::ArrayHandle cellFieldArray; @@ -61,7 +61,7 @@ public: } else { - VTKM_TEST_ASSERT(output.GetNumberOfFields() == 1, + VTKM_TEST_ASSERT(output.GetNumberOfFields() == 2, "Wrong number of fields in the output dataset"); vtkm::cont::ArrayHandle cellFieldArray; @@ -105,7 +105,7 @@ public: if (returnAllInRange) { - VTKM_TEST_ASSERT(output.GetNumberOfFields() == 1, + VTKM_TEST_ASSERT(output.GetNumberOfFields() == 2, "Wrong number of fields in the output dataset"); vtkm::cont::ArrayHandle cellFieldArray; @@ -119,7 +119,7 @@ public: } else { - VTKM_TEST_ASSERT(output.GetNumberOfFields() == 1, + VTKM_TEST_ASSERT(output.GetNumberOfFields() == 2, "Wrong number of fields in the output dataset"); vtkm::cont::ArrayHandle cellFieldArray; @@ -150,7 +150,7 @@ public: threshold.SetFieldsToPass("cellvar"); auto output = threshold.Execute(dataset); - VTKM_TEST_ASSERT(output.GetNumberOfFields() == 1, + VTKM_TEST_ASSERT(output.GetNumberOfFields() == 2, "Wrong number of fields in the output dataset"); vtkm::cont::ArrayHandle cellFieldArray; @@ -180,7 +180,7 @@ public: threshold.SetFieldsToPass("cellvar"); auto output = threshold.Execute(dataset); - VTKM_TEST_ASSERT(output.GetNumberOfFields() == 1, + VTKM_TEST_ASSERT(output.GetNumberOfFields() == 2, "Wrong number of fields in the output dataset"); vtkm::cont::ArrayHandle cellFieldArray; diff --git a/vtkm/filter/entity_extraction/testing/UnitTestThresholdPointsFilter.cxx b/vtkm/filter/entity_extraction/testing/UnitTestThresholdPointsFilter.cxx index 2a7b7eeaa..3c751b99b 100644 --- a/vtkm/filter/entity_extraction/testing/UnitTestThresholdPointsFilter.cxx +++ b/vtkm/filter/entity_extraction/testing/UnitTestThresholdPointsFilter.cxx @@ -97,7 +97,7 @@ public: thresholdPoints.SetActiveField("pointvar"); thresholdPoints.SetFieldsToPass("pointvar"); auto output = thresholdPoints.Execute(dataset); - VTKM_TEST_ASSERT(output.GetNumberOfFields() == 1, + VTKM_TEST_ASSERT(output.GetNumberOfFields() == 2, "Wrong number of fields in the output dataset"); VTKM_TEST_ASSERT(test_equal(output.GetNumberOfCells(), 0), "Wrong result for ThresholdPoints"); } diff --git a/vtkm/filter/entity_extraction/worklet/ExtractStructured.h b/vtkm/filter/entity_extraction/worklet/ExtractStructured.h index 50b46aef8..f312422cd 100644 --- a/vtkm/filter/entity_extraction/worklet/ExtractStructured.h +++ b/vtkm/filter/entity_extraction/worklet/ExtractStructured.h @@ -415,7 +415,6 @@ public: return output; } -private: using UniformCoordinatesArrayHandle = vtkm::cont::ArrayHandleUniformPointCoordinates; using RectilinearCoordinatesArrayHandle = @@ -424,7 +423,8 @@ private: vtkm::cont::ArrayHandle>; - UniformCoordinatesArrayHandle MapCoordinatesUniform(const UniformCoordinatesArrayHandle& coords) + UniformCoordinatesArrayHandle MapCoordinatesUniform( + const UniformCoordinatesArrayHandle& coords) const { using CoordsArray = vtkm::cont::ArrayHandleUniformPointCoordinates; using CoordType = CoordsArray::ValueType; @@ -444,7 +444,7 @@ private: } RectilinearCoordinatesArrayHandle MapCoordinatesRectilinear( - const RectilinearCoordinatesArrayHandle& coords) + const RectilinearCoordinatesArrayHandle& coords) const { // For structured datasets, the cellsets are of different types based on // its dimensionality, but the coordinates are always 3 dimensional. @@ -479,41 +479,6 @@ private: return vtkm::cont::make_ArrayHandleCartesianProduct(xyzs[0], xyzs[1], xyzs[2]); } - struct MapCoordinatesFunctor - { - template - VTKM_CONT void operator()(const vtkm::cont::ArrayHandle& coords, - ExtractStructured& self, - vtkm::cont::UnknownArrayHandle& output) const - { - output = self.ProcessPointField(coords); - } - - VTKM_CONT void operator()(const UniformCoordinatesArrayHandle::Superclass& coords, - ExtractStructured& self, - vtkm::cont::UnknownArrayHandle& output) const - { - output = self.MapCoordinatesUniform(coords); - } - - VTKM_CONT void operator()(const RectilinearCoordinatesArrayHandle::Superclass& coords, - ExtractStructured& self, - vtkm::cont::UnknownArrayHandle& output) const - { - output = self.MapCoordinatesRectilinear(coords); - } - }; - - friend MapCoordinatesFunctor; - -public: - vtkm::cont::UnknownArrayHandle MapCoordinates(const vtkm::cont::CoordinateSystem& coordinates) - { - vtkm::cont::UnknownArrayHandle output; - vtkm::cont::CastAndCall(coordinates, MapCoordinatesFunctor{}, *this, output); - return output; - } - public: template vtkm::cont::ArrayHandle ProcessPointField( diff --git a/vtkm/filter/field_transform/CylindricalCoordinateTransform.cxx b/vtkm/filter/field_transform/CylindricalCoordinateTransform.cxx index 739876232..98a553c0b 100644 --- a/vtkm/filter/field_transform/CylindricalCoordinateTransform.cxx +++ b/vtkm/filter/field_transform/CylindricalCoordinateTransform.cxx @@ -8,6 +8,7 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ +#include #include #include @@ -18,10 +19,21 @@ namespace filter namespace field_transform { +CylindricalCoordinateTransform::CylindricalCoordinateTransform() +{ + this->SetUseCoordinateSystemAsField(true); +} + vtkm::cont::DataSet CylindricalCoordinateTransform::DoExecute(const vtkm::cont::DataSet& inDataSet) { vtkm::cont::UnknownArrayHandle outArray; + const vtkm::cont::Field& inField = this->GetFieldFromDataSet(inDataSet); + if (!inField.IsPointField()) + { + throw vtkm::cont::ErrorBadValue("CylindricalCoordinateTransform only applies to point data."); + } + auto resolveType = [&](const auto& concrete) { // use std::decay to remove const ref from the decltype of concrete. using T = typename std::decay_t::ValueType; @@ -32,15 +44,21 @@ vtkm::cont::DataSet CylindricalCoordinateTransform::DoExecute(const vtkm::cont:: this->Invoke(vtkm::worklet::CylToCar{}, concrete, result); outArray = result; }; - this->CastAndCallVecField<3>(this->GetFieldFromDataSet(inDataSet), resolveType); + this->CastAndCallVecField<3>(inField, resolveType); - vtkm::cont::DataSet outDataSet = - this->CreateResult(inDataSet, - inDataSet.GetCellSet(), - vtkm::cont::CoordinateSystem("coordinates", outArray), - [](vtkm::cont::DataSet& out, const vtkm::cont::Field& fieldToPass) { - out.AddField(fieldToPass); - }); + std::string coordinateName = this->GetOutputFieldName(); + if (coordinateName.empty()) + { + coordinateName = inField.GetName(); + } + + vtkm::cont::DataSet outDataSet = this->CreateResultCoordinateSystem( + inDataSet, + inDataSet.GetCellSet(), + vtkm::cont::CoordinateSystem(coordinateName, outArray), + [](vtkm::cont::DataSet& out, const vtkm::cont::Field& fieldToPass) { + out.AddField(fieldToPass); + }); return outDataSet; } diff --git a/vtkm/filter/field_transform/CylindricalCoordinateTransform.h b/vtkm/filter/field_transform/CylindricalCoordinateTransform.h index 260300b4a..2e11b6ed3 100644 --- a/vtkm/filter/field_transform/CylindricalCoordinateTransform.h +++ b/vtkm/filter/field_transform/CylindricalCoordinateTransform.h @@ -27,6 +27,8 @@ class VTKM_FILTER_FIELD_TRANSFORM_EXPORT CylindricalCoordinateTransform : public vtkm::filter::NewFilterField { public: + VTKM_CONT CylindricalCoordinateTransform(); + VTKM_CONT void SetCartesianToCylindrical() { CartesianToCylindrical = true; } VTKM_CONT void SetCylindricalToCartesian() { CartesianToCylindrical = false; } diff --git a/vtkm/filter/field_transform/PointTransform.cxx b/vtkm/filter/field_transform/PointTransform.cxx index c1babc4d5..0acd6d6de 100644 --- a/vtkm/filter/field_transform/PointTransform.cxx +++ b/vtkm/filter/field_transform/PointTransform.cxx @@ -51,8 +51,9 @@ VTKM_CONT vtkm::cont::DataSet PointTransform::DoExecute(const vtkm::cont::DataSe const auto& field = this->GetFieldFromDataSet(inDataSet); this->CastAndCallVecField<3>(field, resolveType); - vtkm::cont::DataSet outData = this->CreateResultField( - inDataSet, this->GetOutputFieldName(), field.GetAssociation(), outArray); + auto passMapper = [](auto& d, const auto& f) { d.AddField(f); }; + vtkm::cont::DataSet outData = this->CreateResultCoordinateSystem( + inDataSet, inDataSet.GetCellSet(), this->GetOutputFieldName(), outArray, passMapper); if (this->GetChangeCoordinateSystem()) { diff --git a/vtkm/filter/field_transform/SphericalCoordinateTransform.cxx b/vtkm/filter/field_transform/SphericalCoordinateTransform.cxx index 1a571dd80..af1730050 100644 --- a/vtkm/filter/field_transform/SphericalCoordinateTransform.cxx +++ b/vtkm/filter/field_transform/SphericalCoordinateTransform.cxx @@ -8,6 +8,7 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ +#include #include #include @@ -17,10 +18,22 @@ namespace filter { namespace field_transform { + +SphericalCoordinateTransform::SphericalCoordinateTransform() +{ + this->SetUseCoordinateSystemAsField(true); +} + vtkm::cont::DataSet SphericalCoordinateTransform::DoExecute(const vtkm::cont::DataSet& inDataSet) { vtkm::cont::UnknownArrayHandle outArray; + const vtkm::cont::Field& inField = this->GetFieldFromDataSet(inDataSet); + if (!inField.IsPointField()) + { + throw vtkm::cont::ErrorBadValue("SphericalCoordinateTransform only applies to point data."); + } + auto resolveType = [&](const auto& concrete) { // use std::decay to remove const ref from the decltype of concrete. using T = typename std::decay_t::ValueType; @@ -31,15 +44,21 @@ vtkm::cont::DataSet SphericalCoordinateTransform::DoExecute(const vtkm::cont::Da this->Invoke(vtkm::worklet::SphereToCar{}, concrete, result); outArray = result; }; - this->CastAndCallVecField<3>(this->GetFieldFromDataSet(inDataSet), resolveType); + this->CastAndCallVecField<3>(inField, resolveType); - vtkm::cont::DataSet outDataSet = - this->CreateResult(inDataSet, - inDataSet.GetCellSet(), - vtkm::cont::CoordinateSystem("coordinates", outArray), - [](vtkm::cont::DataSet& out, const vtkm::cont::Field& fieldToPass) { - out.AddField(fieldToPass); - }); + std::string coordinateName = this->GetOutputFieldName(); + if (coordinateName.empty()) + { + coordinateName = inField.GetName(); + } + + vtkm::cont::DataSet outDataSet = this->CreateResultCoordinateSystem( + inDataSet, + inDataSet.GetCellSet(), + vtkm::cont::CoordinateSystem(coordinateName, outArray), + [](vtkm::cont::DataSet& out, const vtkm::cont::Field& fieldToPass) { + out.AddField(fieldToPass); + }); return outDataSet; } } // namespace field_transform diff --git a/vtkm/filter/field_transform/SphericalCoordinateTransform.h b/vtkm/filter/field_transform/SphericalCoordinateTransform.h index b599ef86d..e76cfa78a 100644 --- a/vtkm/filter/field_transform/SphericalCoordinateTransform.h +++ b/vtkm/filter/field_transform/SphericalCoordinateTransform.h @@ -25,6 +25,8 @@ class VTKM_FILTER_FIELD_TRANSFORM_EXPORT SphericalCoordinateTransform : public vtkm::filter::NewFilterField { public: + VTKM_CONT SphericalCoordinateTransform(); + VTKM_CONT void SetCartesianToSpherical() { CartesianToSpherical = true; } VTKM_CONT void SetSphericalToCartesian() { CartesianToSpherical = false; } diff --git a/vtkm/filter/flow/Lagrangian.cxx b/vtkm/filter/flow/Lagrangian.cxx index b1fba866c..19a1fc7f8 100644 --- a/vtkm/filter/flow/Lagrangian.cxx +++ b/vtkm/filter/flow/Lagrangian.cxx @@ -262,7 +262,7 @@ VTKM_CONT vtkm::cont::DataSet Lagrangian::DoExecute(const vtkm::cont::DataSet& i auto fieldmapper = [&](vtkm::cont::DataSet& dataset, const vtkm::cont::Field& fieldToPass) { MapField(dataset, fieldToPass); }; - outputData = this->CreateResult(input, outCellSet, outCoords, fieldmapper); + outputData = this->CreateResultCoordinateSystem(input, outCellSet, outCoords, fieldmapper); outputData.AddPointField("valid", this->BasisParticlesValidity); outputData.AddPointField("displacement", basisParticlesDisplacement); diff --git a/vtkm/filter/flow/LagrangianStructures.cxx b/vtkm/filter/flow/LagrangianStructures.cxx index a9f330e07..e1cea5861 100644 --- a/vtkm/filter/flow/LagrangianStructures.cxx +++ b/vtkm/filter/flow/LagrangianStructures.cxx @@ -174,8 +174,8 @@ VTKM_CONT vtkm::cont::DataSet LagrangianStructures::DoExecute(const vtkm::cont:: auto fieldmapper = [&](vtkm::cont::DataSet& dataset, const vtkm::cont::Field& field) { MapField(dataset, field); }; - vtkm::cont::DataSet output = - this->CreateResult(input, lcsInput.GetCellSet(), lcsInput.GetCoordinateSystem(), fieldmapper); + vtkm::cont::DataSet output = this->CreateResultCoordinateSystem( + input, lcsInput.GetCellSet(), lcsInput.GetCoordinateSystem(), fieldmapper); output.AddPointField(this->GetOutputFieldName(), outputField); return output; } diff --git a/vtkm/filter/flow/testing/UnitTestLagrangianFilter.cxx b/vtkm/filter/flow/testing/UnitTestLagrangianFilter.cxx index cd7699659..ddb850c83 100644 --- a/vtkm/filter/flow/testing/UnitTestLagrangianFilter.cxx +++ b/vtkm/filter/flow/testing/UnitTestLagrangianFilter.cxx @@ -69,7 +69,7 @@ void TestLagrangianFilterMultiStepInterval() "Wrong number of coordinate systems in the output dataset."); VTKM_TEST_ASSERT(extractedBasisFlows.GetNumberOfPoints() == 512, "Wrong number of basis flows extracted."); - VTKM_TEST_ASSERT(extractedBasisFlows.GetNumberOfFields() == 2, "Wrong number of fields."); + VTKM_TEST_ASSERT(extractedBasisFlows.GetNumberOfFields() == 3, "Wrong number of fields."); } else { diff --git a/vtkm/filter/geometry_refinement/VertexClustering.cxx b/vtkm/filter/geometry_refinement/VertexClustering.cxx index cb751e7f1..7effbe102 100644 --- a/vtkm/filter/geometry_refinement/VertexClustering.cxx +++ b/vtkm/filter/geometry_refinement/VertexClustering.cxx @@ -62,8 +62,8 @@ VTKM_CONT vtkm::cont::DataSet VertexClustering::DoExecute(const vtkm::cont::Data outCoords); auto mapper = [&](auto& result, const auto& f) { DoMapField(result, f, worklet); }; - return this->CreateResult( - input, outCellSet, vtkm::cont::CoordinateSystem("coordinates", outCoords), mapper); + return this->CreateResultCoordinateSystem( + input, outCellSet, input.GetCoordinateSystem().GetName(), outCoords, mapper); } } // namespace geometry_refinement } // namespace filter diff --git a/vtkm/filter/resampling/Probe.cxx b/vtkm/filter/resampling/Probe.cxx index 3a59ef899..0c134ef3d 100644 --- a/vtkm/filter/resampling/Probe.cxx +++ b/vtkm/filter/resampling/Probe.cxx @@ -76,8 +76,8 @@ vtkm::cont::DataSet Probe::DoExecute(const vtkm::cont::DataSet& input) auto mapper = [&](auto& outDataSet, const auto& f) { DoMapField(outDataSet, f, worklet, this->InvalidValue); }; - auto output = this->CreateResult( - input, this->Geometry.GetCellSet(), this->Geometry.GetCoordinateSystems(), mapper); + auto output = this->CreateResultCoordinateSystem( + input, this->Geometry.GetCellSet(), this->Geometry.GetCoordinateSystem(), mapper); output.AddField(vtkm::cont::make_FieldPoint("HIDDEN", worklet.GetHiddenPointsField())); output.AddField( vtkm::cont::make_FieldCell("HIDDEN", worklet.GetHiddenCellsField(output.GetCellSet()))); diff --git a/vtkm/filter/resampling/Probe.h b/vtkm/filter/resampling/Probe.h index 2b896a260..9593bf88a 100644 --- a/vtkm/filter/resampling/Probe.h +++ b/vtkm/filter/resampling/Probe.h @@ -26,7 +26,7 @@ public: void SetGeometry(const vtkm::cont::DataSet& geometry) { this->Geometry = vtkm::cont::DataSet(); - this->Geometry.CopyStructure(geometry); + this->Geometry.CopyPartsFromExcept(geometry, vtkm::cont::DataSet::Parts::Fields); } VTKM_CONT diff --git a/vtkm/io/VTKDataSetWriter.cxx b/vtkm/io/VTKDataSetWriter.cxx index 78650e6ee..daaf261dc 100644 --- a/vtkm/io/VTKDataSetWriter.cxx +++ b/vtkm/io/VTKDataSetWriter.cxx @@ -320,6 +320,12 @@ void WritePointFields(std::ostream& out, continue; } + if (field.GetName() == dataSet.GetCoordinateSystemName()) + { + // Do not write out the first coordinate system as a field. + continue; + } + vtkm::Id npoints = field.GetNumberOfValues(); int ncomps = field.GetData().GetNumberOfComponentsFlat(); diff --git a/vtkm/io/testing/UnitTestBOVDataSetReader.cxx b/vtkm/io/testing/UnitTestBOVDataSetReader.cxx index f1851ac90..606acd2de 100644 --- a/vtkm/io/testing/UnitTestBOVDataSetReader.cxx +++ b/vtkm/io/testing/UnitTestBOVDataSetReader.cxx @@ -45,7 +45,7 @@ void TestReadingBOVDataSet() auto const& ds = readBOVDataSet(bovFile.data()); - VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 1, "Incorrect number of fields"); + VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 2, "Incorrect number of fields"); // See the .bov file: DATA SIZE: 50 50 50 VTKM_TEST_ASSERT(ds.GetNumberOfPoints() == 50 * 50 * 50, "Incorrect number of points"); VTKM_TEST_ASSERT(ds.GetCellSet().GetNumberOfPoints() == 50 * 50 * 50, @@ -53,7 +53,7 @@ void TestReadingBOVDataSet() VTKM_TEST_ASSERT(ds.GetNumberOfCells() == 49 * 49 * 49, "Incorrect number of cells"); // See the .bov file: VARIABLE: "var" VTKM_TEST_ASSERT(ds.HasField("var"), "Should have field 'var', but does not."); - VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 1, "There is only one field in noise.bov"); + VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 2, "There is only one field in noise.bov"); VTKM_TEST_ASSERT(ds.GetNumberOfCoordinateSystems() == 1, "There is only one coordinate system in noise.bov"); diff --git a/vtkm/io/testing/UnitTestVTKDataSetReader.cxx b/vtkm/io/testing/UnitTestVTKDataSetReader.cxx index 0d3dadadd..7270ddffc 100644 --- a/vtkm/io/testing/UnitTestVTKDataSetReader.cxx +++ b/vtkm/io/testing/UnitTestVTKDataSetReader.cxx @@ -53,7 +53,7 @@ void TestReadingPolyData(Format format) vtkm::cont::DataSet ds = readVTKDataSet(testFileName); - VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 5, "Incorrect number of fields"); + VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 6, "Incorrect number of fields"); VTKM_TEST_ASSERT(ds.GetNumberOfPoints() == 8, "Incorrect number of points"); VTKM_TEST_ASSERT(ds.GetCellSet().GetNumberOfPoints() == 8, "Incorrect number of points (from cell set)"); @@ -70,7 +70,7 @@ void TestReadingPolyDataEmpty() VTKM_TEST_ASSERT(data.GetNumberOfPoints() == 8); VTKM_TEST_ASSERT(data.GetNumberOfCells() == 0); VTKM_TEST_ASSERT(data.GetCellSet().GetNumberOfPoints() == 8); - VTKM_TEST_ASSERT(data.GetNumberOfFields() == 1); + VTKM_TEST_ASSERT(data.GetNumberOfFields() == 2); } void TestReadingStructuredPoints(Format format) @@ -81,7 +81,7 @@ void TestReadingStructuredPoints(Format format) vtkm::cont::DataSet ds = readVTKDataSet(testFileName); - VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 1, "Incorrect number of fields"); + VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 2, "Incorrect number of fields"); VTKM_TEST_ASSERT(ds.GetNumberOfPoints() == 72, "Incorrect number of points"); VTKM_TEST_ASSERT(ds.GetCellSet().GetNumberOfPoints() == 72, "Incorrect number of points (from cell set)"); @@ -99,7 +99,7 @@ void TestReadingStructuredPointsVisIt(Format format) vtkm::cont::DataSet ds = readVTKDataSet(testFileName); - VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 1, "Incorrect number of fields"); + VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 2, "Incorrect number of fields"); VTKM_TEST_ASSERT(ds.GetNumberOfPoints() == 64, "Incorrect number of points"); VTKM_TEST_ASSERT(ds.GetCellSet().GetNumberOfPoints() == 64, "Incorrect number of points (from cell set)"); @@ -116,7 +116,7 @@ void TestReadingUnstructuredGrid(Format format) vtkm::cont::DataSet ds = readVTKDataSet(testFileName); - VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 2, "Incorrect number of fields"); + VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 3, "Incorrect number of fields"); VTKM_TEST_ASSERT(ds.GetNumberOfPoints() == 26, "Incorrect number of points"); VTKM_TEST_ASSERT(ds.GetCellSet().GetNumberOfPoints() == 26, "Incorrect number of points (from cell set)"); @@ -133,7 +133,7 @@ void TestReadingV5Format(Format format) vtkm::cont::DataSet ds = readVTKDataSet(testFileName); - VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 6, "Incorrect number of fields"); + VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 7, "Incorrect number of fields"); VTKM_TEST_ASSERT(ds.GetNumberOfPoints() == 26, "Incorrect number of points"); VTKM_TEST_ASSERT(ds.GetCellSet().GetNumberOfPoints() == 26, "Incorrect number of points (from cell set)"); @@ -173,7 +173,7 @@ void TestReadingUnstructuredGridEmpty() VTKM_TEST_ASSERT(data.GetNumberOfPoints() == 26); VTKM_TEST_ASSERT(data.GetNumberOfCells() == 0); VTKM_TEST_ASSERT(data.GetCellSet().GetNumberOfPoints() == 26); - VTKM_TEST_ASSERT(data.GetNumberOfFields() == 2); + VTKM_TEST_ASSERT(data.GetNumberOfFields() == 3); } void TestReadingUnstructuredPixels() @@ -291,7 +291,7 @@ void TestReadingUnstructuredGridVisIt(Format format) vtkm::cont::DataSet ds = readVTKDataSet(testFileName); - VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 2, "Incorrect number of fields"); + VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 3, "Incorrect number of fields"); VTKM_TEST_ASSERT(ds.GetNumberOfPoints() == 26, "Incorrect number of points"); VTKM_TEST_ASSERT(ds.GetCellSet().GetNumberOfPoints() == 26, "Incorrect number of points (from cell set)"); @@ -309,7 +309,7 @@ void TestReadingRectilinearGrid1(Format format) vtkm::cont::DataSet ds = readVTKDataSet(testFileName); - VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 2, "Incorrect number of fields"); + VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 3, "Incorrect number of fields"); VTKM_TEST_ASSERT(ds.GetNumberOfPoints() == 125, "Incorrect number of points"); VTKM_TEST_ASSERT(ds.GetCellSet().GetNumberOfPoints() == 125, "Incorrect number of points (from cell set)"); @@ -327,7 +327,7 @@ void TestReadingRectilinearGrid2(Format format) vtkm::cont::DataSet ds = readVTKDataSet(testFileName); - VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 2, "Incorrect number of fields"); + VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 3, "Incorrect number of fields"); VTKM_TEST_ASSERT(ds.GetNumberOfPoints() == 24, "Incorrect number of points"); VTKM_TEST_ASSERT(ds.GetCellSet().GetNumberOfPoints() == 24, "Incorrect number of points (from cell set)"); @@ -343,7 +343,7 @@ void TestReadingStructuredGridASCII() vtkm::cont::DataSet ds = readVTKDataSet(testFileName); - VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 2, "Incorrect number of fields"); + VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 3, "Incorrect number of fields"); VTKM_TEST_ASSERT(ds.GetNumberOfPoints() == 6, "Incorrect number of points"); VTKM_TEST_ASSERT(ds.GetCellSet().GetNumberOfPoints() == 6, "Incorrect number of points (from cell set)"); @@ -359,7 +359,7 @@ void TestReadingStructuredGridBin() vtkm::cont::DataSet ds = readVTKDataSet(testFileName); - VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 2, "Incorrect number of fields"); + VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 3, "Incorrect number of fields"); VTKM_TEST_ASSERT(ds.GetNumberOfPoints() == 18, "Incorrect number of points"); VTKM_TEST_ASSERT(ds.GetCellSet().GetNumberOfPoints() == 18, "Incorrect number of points (from cell set)"); @@ -379,7 +379,7 @@ void TestReadingFishTank() VTKM_TEST_ASSERT(ds.GetNumberOfPoints() == 50 * 50 * 50, "Incorrect number of points"); VTKM_TEST_ASSERT(ds.GetCellSet().GetNumberOfPoints() == 50 * 50 * 50, "Incorrect number of points (from cell set)"); - VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 2, "Incorrect number of fields"); + VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 3, "Incorrect number of fields"); VTKM_TEST_ASSERT(ds.HasField("vec"), "The vtk file has a field 'vec', but the dataset does not."); VTKM_TEST_ASSERT(ds.HasField("vec_magnitude"), "The vtk file has a field 'vec_magnitude', but the dataset does not."); @@ -622,7 +622,7 @@ void TestSkppingStringFields(Format format) vtkm::cont::DataSet ds = readVTKDataSet(testFileName); - VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 1, "Incorrect number of fields"); + VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 2, "Incorrect number of fields"); VTKM_TEST_ASSERT(ds.GetNumberOfPoints() == 72, "Incorrect number of points"); VTKM_TEST_ASSERT(ds.GetCellSet().GetNumberOfPoints() == 72, "Incorrect number of points (from cell set)"); diff --git a/vtkm/io/testing/UnitTestVTKDataSetWriter.cxx b/vtkm/io/testing/UnitTestVTKDataSetWriter.cxx index 45f6436a3..06caecd69 100644 --- a/vtkm/io/testing/UnitTestVTKDataSetWriter.cxx +++ b/vtkm/io/testing/UnitTestVTKDataSetWriter.cxx @@ -112,6 +112,13 @@ void CheckWrittenReadData(const vtkm::cont::DataSet& originalData, for (vtkm::IdComponent fieldId = 0; fieldId < originalData.GetNumberOfFields(); ++fieldId) { vtkm::cont::Field originalField = originalData.GetField(fieldId); + if (originalField.IsPointField() && + (originalField.GetName() == originalData.GetCoordinateSystemName())) + { + // Do not check the field that is the first coordinate system. It is likely to have + // changed name because VTK does not name coordinate systems. + continue; + } VTKM_TEST_ASSERT(fileData.HasField(originalField.GetName(), originalField.GetAssociation())); vtkm::cont::Field fileField = fileData.GetField(originalField.GetName(), originalField.GetAssociation()); diff --git a/vtkm/rendering/ConnectivityProxy.cxx b/vtkm/rendering/ConnectivityProxy.cxx index 8ac1186d2..751b3ceab 100644 --- a/vtkm/rendering/ConnectivityProxy.cxx +++ b/vtkm/rendering/ConnectivityProxy.cxx @@ -39,20 +39,16 @@ protected: bool CompositeBackground; public: - InternalsType(vtkm::cont::DataSet& dataSet) + InternalsType(const vtkm::cont::DataSet& dataSet, const std::string& fieldName) { Dataset = dataSet; Cells = dataSet.GetCellSet(); Coords = dataSet.GetCoordinateSystem(); Mode = RenderMode::Volume; CompositeBackground = true; - // - // Just grab a default scalar field - // - - if (Dataset.GetNumberOfFields() > 0) + if (!fieldName.empty()) { - this->SetScalarField(Dataset.GetField(0).GetName()); + this->SetScalarField(fieldName); } } @@ -243,8 +239,9 @@ public: VTKM_CONT -ConnectivityProxy::ConnectivityProxy(vtkm::cont::DataSet& dataSet) - : Internals(new InternalsType(dataSet)) +ConnectivityProxy::ConnectivityProxy(const vtkm::cont::DataSet& dataSet, + const std::string& fieldName) + : Internals(new InternalsType(dataSet, fieldName)) { } @@ -259,7 +256,7 @@ ConnectivityProxy::ConnectivityProxy(const vtkm::cont::UnknownCellSet& cellset, dataset.AddCoordinateSystem(coords); dataset.AddField(scalarField); - Internals = std::shared_ptr(new InternalsType(dataset)); + Internals = std::shared_ptr(new InternalsType(dataset, scalarField.GetName())); } VTKM_CONT diff --git a/vtkm/rendering/ConnectivityProxy.h b/vtkm/rendering/ConnectivityProxy.h index 8aaa55cdd..de41793d2 100644 --- a/vtkm/rendering/ConnectivityProxy.h +++ b/vtkm/rendering/ConnectivityProxy.h @@ -31,7 +31,7 @@ using PartialVector32 = std::vectorFilterPoints(cellset, coords, scalarField); vtkm::cont::UnknownCellSet processedCellSet = processedDataSet.GetCellSet(); vtkm::cont::CoordinateSystem processedCoords = processedDataSet.GetCoordinateSystem(); - vtkm::cont::Field processedField = processedDataSet.GetField(0); + vtkm::cont::Field processedField = processedDataSet.GetField(scalarField.GetName()); if (this->ScaleByValue) { diff --git a/vtkm/rendering/MapperGlyphVector.cxx b/vtkm/rendering/MapperGlyphVector.cxx index 873d1eaec..4152608ad 100644 --- a/vtkm/rendering/MapperGlyphVector.cxx +++ b/vtkm/rendering/MapperGlyphVector.cxx @@ -86,7 +86,7 @@ void MapperGlyphVector::RenderCells(const vtkm::cont::UnknownCellSet& cellset, vtkm::cont::DataSet processedDataSet = this->FilterPoints(cellset, coords, field); vtkm::cont::UnknownCellSet processedCellSet = processedDataSet.GetCellSet(); vtkm::cont::CoordinateSystem processedCoords = processedDataSet.GetCoordinateSystem(); - vtkm::cont::Field processedField = processedDataSet.GetField(0); + vtkm::cont::Field processedField = processedDataSet.GetField(field.GetName()); if (this->ScaleByValue) { diff --git a/vtkm/rendering/MapperWireframer.cxx b/vtkm/rendering/MapperWireframer.cxx index 9f79c3913..73b91a051 100644 --- a/vtkm/rendering/MapperWireframer.cxx +++ b/vtkm/rendering/MapperWireframer.cxx @@ -303,7 +303,7 @@ void MapperWireframer::RenderCells(const vtkm::cont::UnknownCellSet& inCellSet, externalFaces.SetPassPolyData(true); vtkm::cont::DataSet output = externalFaces.Execute(dataSet); cellSet = output.GetCellSet(); - actualField = output.GetField(0); + actualField = output.GetField(inScalarField.GetName()); } // Extract unique edges from the cell set.