From 3671e1eb133edb36a4acd411050ef5a935659651 Mon Sep 17 00:00:00 2001 From: "T.J. Corona" Date: Mon, 29 Oct 2018 17:03:39 -0400 Subject: [PATCH 1/2] Introduce smtk::mesh::Component The current pattern in SMTK is to have resources and components. To retrofit smtk::mesh to fit this pattern, we introduce smtk::mesh::Component, a lightweight, shared object that provides access to a meshset. --- doc/release/notes/smtk-mesh-component.md | 11 ++ smtk/mesh/CMakeLists.txt | 4 +- smtk/mesh/core/Collection.cxx | 12 +-- smtk/mesh/core/Component.cxx | 84 +++++++++++++++ smtk/mesh/core/Component.h | 83 ++++++++++++++ smtk/mesh/moab/Interface.cxx | 12 +++ smtk/mesh/operators/ElevateMesh.cxx | 27 ++--- smtk/mesh/operators/ElevateMesh.sbt | 10 +- smtk/mesh/pybind11/PybindComponent.h | 44 ++++++++ smtk/mesh/pybind11/PybindMesh.cxx | 2 + smtk/mesh/resource/MeshComponent.cxx | 102 ------------------ smtk/mesh/resource/MeshComponent.h | 90 ---------------- smtk/mesh/testing/cxx/TestElevateMesh.cxx | 9 +- .../cxx/TestElevateMeshOnStructuredGrid.cxx | 3 +- smtk/mesh/testing/cxx/TestWarpMesh.cxx | 3 +- .../python/elevateMeshOnStructuredGrid.py | 2 +- 16 files changed, 270 insertions(+), 228 deletions(-) create mode 100644 doc/release/notes/smtk-mesh-component.md create mode 100644 smtk/mesh/core/Component.cxx create mode 100644 smtk/mesh/core/Component.h create mode 100644 smtk/mesh/pybind11/PybindComponent.h delete mode 100644 smtk/mesh/resource/MeshComponent.cxx delete mode 100644 smtk/mesh/resource/MeshComponent.h diff --git a/doc/release/notes/smtk-mesh-component.md b/doc/release/notes/smtk-mesh-component.md new file mode 100644 index 0000000000..ec202cb256 --- /dev/null +++ b/doc/release/notes/smtk-mesh-component.md @@ -0,0 +1,11 @@ +# Introduce smtk::mesh::Component + +To adhere to the Resource/Component paradigm in SMTK 3.0, we have +introduced the lightweight class smtk::mesh::Component, which +facilitates the ability to pass meshsets as component items in an +attribute. + +### User-facing changes + +`smtk::mesh::Component` is now used to send/retrieve meshsets to/from +attributes. diff --git a/smtk/mesh/CMakeLists.txt b/smtk/mesh/CMakeLists.txt index d26aa4947a..fd2f2f3bdc 100644 --- a/smtk/mesh/CMakeLists.txt +++ b/smtk/mesh/CMakeLists.txt @@ -4,6 +4,7 @@ set(meshSrcs core/CellField.cxx core/CellTypes.cxx core/Collection.cxx + core/Component.cxx core/ForEachTypes.cxx core/Handle.cxx core/MeshSet.cxx @@ -46,7 +47,6 @@ set(meshSrcs operators/UndoElevateMesh.cxx operators/WriteMesh.cxx - resource/MeshComponent.cxx resource/Registrar.cxx utility/ApplyToMesh.cxx @@ -63,6 +63,7 @@ set(meshHeaders core/CellTraits.h core/CellTypes.h core/Collection.h + core/Component.h core/DimensionTypes.h core/FieldTypes.h core/ForEachTypes.h @@ -101,7 +102,6 @@ set(meshHeaders operators/UndoElevateMesh.h operators/WriteMesh.h - resource/MeshComponent.h resource/PropertyData.h resource/Registrar.h diff --git a/smtk/mesh/core/Collection.cxx b/smtk/mesh/core/Collection.cxx index a0816e6ab3..6222aae3ea 100644 --- a/smtk/mesh/core/Collection.cxx +++ b/smtk/mesh/core/Collection.cxx @@ -10,7 +10,7 @@ #include "smtk/mesh/core/Collection.h" -#include "smtk/mesh/resource/MeshComponent.h" +#include "smtk/mesh/core/Component.h" #include "smtk/mesh/moab/Interface.h" @@ -105,14 +105,8 @@ Collection::~Collection() smtk::resource::ComponentPtr Collection::find(const smtk::common::UUID& compId) const { - const smtk::mesh::InterfacePtr& iface = m_internals->mesh_iface(); - smtk::mesh::Handle handle; - if (iface->findById(m_internals->mesh_root_handle(), compId, handle)) - { - return smtk::mesh::MeshComponent::create(this->shared_from_this(), handle); - } - - return smtk::resource::ComponentPtr(); + return std::static_pointer_cast( + Component::create(std::const_pointer_cast(shared_from_this()), compId)); } std::function Collection::queryOperation( diff --git a/smtk/mesh/core/Component.cxx b/smtk/mesh/core/Component.cxx new file mode 100644 index 0000000000..65ed5fe5bd --- /dev/null +++ b/smtk/mesh/core/Component.cxx @@ -0,0 +1,84 @@ +//========================================================================= +// Copyright (c) Kitware, Inc. +// All rights reserved. +// See LICENSE.txt 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 "smtk/mesh/core/Component.h" + +#include "smtk/common/UUIDGenerator.h" + +namespace smtk +{ +namespace mesh +{ + +Component::Component(const smtk::mesh::CollectionPtr& collection, const smtk::common::UUID& id) + : m_collection(collection) + , m_id(id) +{ +} + +Component::Component(const smtk::mesh::MeshSet& meshset) + : Component(meshset.collection(), meshset.id()) +{ + if (m_id == smtk::common::UUID::null()) + { + m_id = smtk::common::UUIDGenerator::instance().random(); + const_cast(meshset).setId(m_id); + } +} + +std::shared_ptr Component::create( + const smtk::mesh::CollectionPtr& collection, const smtk::common::UUID& id) +{ + std::shared_ptr shared(new Component(collection, id)); + return std::static_pointer_cast(shared); +} + +std::shared_ptr Component::create(const smtk::mesh::MeshSet& meshset) +{ + std::shared_ptr shared(new Component(meshset)); + return std::static_pointer_cast(shared); +} + +const smtk::resource::ResourcePtr Component::resource() const +{ + return std::static_pointer_cast(m_collection.lock()); +} + +const smtk::mesh::MeshSet Component::mesh() const +{ + if (auto collection = m_collection.lock()) + { + const smtk::mesh::InterfacePtr& iface = collection->interface(); + smtk::mesh::Handle handle; + if (iface->findById(iface->getRoot(), m_id, handle)) + { + return smtk::mesh::MeshSet(collection, handle); + } + } + + return smtk::mesh::MeshSet(); +} + +smtk::mesh::MeshSet Component::mesh() +{ + if (auto collection = m_collection.lock()) + { + const smtk::mesh::InterfacePtr& iface = collection->interface(); + smtk::mesh::Handle handle; + if (iface->findById(iface->getRoot(), m_id, handle)) + { + return smtk::mesh::MeshSet(collection, handle); + } + } + + return smtk::mesh::MeshSet(); +} +} +} diff --git a/smtk/mesh/core/Component.h b/smtk/mesh/core/Component.h new file mode 100644 index 0000000000..3f5f9a3600 --- /dev/null +++ b/smtk/mesh/core/Component.h @@ -0,0 +1,83 @@ +//========================================================================= +// Copyright (c) Kitware, Inc. +// All rights reserved. +// See LICENSE.txt 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. +//========================================================================= + +#ifndef __smtk_mesh_Component_h +#define __smtk_mesh_Component_h + +#include "smtk/CoreExports.h" +#include "smtk/PublicPointerDefs.h" +#include "smtk/TupleTraits.h" + +#include "smtk/resource/Component.h" + +#include "smtk/mesh/core/Collection.h" +#include "smtk/mesh/core/MeshSet.h" + +namespace smtk +{ +namespace mesh +{ +class Component; + +typedef std::vector ComponentList; +typedef std::set Components; + +/// A lightweight object for representing meshset information as a resource +/// component. This is useful for constructing links between meshsets and other +/// resources/components and for representing meshsets within smtk's attribute +/// system. +class SMTKCORE_EXPORT Component : public smtk::resource::Component +{ +protected: + Component(const smtk::mesh::CollectionPtr&, const smtk::common::UUID&); + Component(const smtk::mesh::MeshSet&); + +public: + smtkTypeMacro(Component); + smtkSharedFromThisMacro(smtk::resource::Component); + + /// Construct a mesh component corresponding to a meshset from the input + /// collection and id. No checking is performed that the collection has a + /// meshset with this id; if this is the case, the resolved mesh() will return + /// a default-constructed (and invalid) mesh. + static std::shared_ptr create( + const smtk::mesh::CollectionPtr&, const smtk::common::UUID&); + + /// Construct a mesh component correpsonding to the input meshset. + static std::shared_ptr create(const smtk::mesh::MeshSet&); + + /// Access the component's resource. + const smtk::resource::ResourcePtr resource() const override; + + /// Access the component's id. + const smtk::common::UUID& id() const override { return m_id; } + + /// Set the component's id. No checking is performed that the collection has a + /// meshset with this id; if this is the case, the resolved mesh() will return + /// a default-constructed (and invalid) mesh. + bool setId(const smtk::common::UUID& myID) override + { + m_id = myID; + return true; + } + + /// Access the meshset represented by this component. + const smtk::mesh::MeshSet mesh() const; + smtk::mesh::MeshSet mesh(); + +private: + std::weak_ptr m_collection; + smtk::common::UUID m_id; +}; + +} // namespace mesh +} // namespace smtk + +#endif diff --git a/smtk/mesh/moab/Interface.cxx b/smtk/mesh/moab/Interface.cxx index fc403cd66e..cc1d40eec7 100644 --- a/smtk/mesh/moab/Interface.cxx +++ b/smtk/mesh/moab/Interface.cxx @@ -1026,10 +1026,22 @@ bool Interface::findById( tag::QueryIdTag mtag(id, this->moabInterface()); ::moab::ErrorCode rval; + rval = m_iface->get_entities_by_type_and_tag( root, ::moab::MBENTITYSET, mtag.moabTagPtr(), mtag.moabTagValuePtr(), 1, result); + if (rval != ::moab::MB_SUCCESS || result.size() != 1) { + // The above call does not check the root if it has the tag value. Let's do + // that before we give up. + smtk::common::UUID rootId = + detail::computeDenseOpaqueTagValue(mtag, root, this->moabInterface()); + if (rootId != smtk::common::UUID::null()) + { + meshset = root; + return true; + } + return false; } meshset = *result.begin(); diff --git a/smtk/mesh/operators/ElevateMesh.cxx b/smtk/mesh/operators/ElevateMesh.cxx index 8f6d055203..61f05bcde5 100644 --- a/smtk/mesh/operators/ElevateMesh.cxx +++ b/smtk/mesh/operators/ElevateMesh.cxx @@ -17,11 +17,13 @@ #include "smtk/attribute/GroupItem.h" #include "smtk/attribute/IntItem.h" #include "smtk/attribute/MeshItem.h" +#include "smtk/attribute/ReferenceItem.h" #include "smtk/attribute/StringItem.h" #include "smtk/attribute/VoidItem.h" #include "smtk/mesh/core/CellField.h" #include "smtk/mesh/core/Collection.h" +#include "smtk/mesh/core/Component.h" #include "smtk/mesh/core/MeshSet.h" #include "smtk/mesh/core/PointField.h" @@ -122,13 +124,6 @@ bool ElevateMesh::ableToOperate() { return false; } - - smtk::attribute::MeshItem::Ptr meshItem = this->parameters()->findMesh("mesh"); - if (!meshItem || meshItem->numberOfValues() == 0) - { - return false; - } - return true; } @@ -138,7 +133,9 @@ ElevateMesh::Result ElevateMesh::operateInternal() smtk::attribute::StringItem::Ptr inputDataItem = this->parameters()->findString("input data"); // Access the mesh to elevate - smtk::attribute::MeshItem::Ptr meshItem = this->parameters()->findMesh("mesh"); + smtk::attribute::ReferenceItem::Ptr meshItem = this->parameters()->associations(); + smtk::mesh::MeshSet meshset = meshItem->valueAs()->mesh(); + smtk::mesh::Collection::Ptr collection = meshset.collection(); // Access the string describing the interpolation scheme smtk::attribute::StringItem::Ptr interpolationSchemeItem = @@ -207,7 +204,7 @@ ElevateMesh::Result ElevateMesh::operateInternal() { // Compute the radial average function interpolation = radialAverageFrom( - auxGeo, radiusItem->value(), prefilter, meshItem->value().collection()->interface()); + auxGeo, radiusItem->value(), prefilter, collection->interface()); } else if (interpolationSchemeItem->value() == "inverse distance weighting") { @@ -231,7 +228,7 @@ ElevateMesh::Result ElevateMesh::operateInternal() { // Compute the radial average function interpolation = radialAverageFrom( - fileName, radiusItem->value(), prefilter, meshItem->value().collection()->interface()); + fileName, radiusItem->value(), prefilter, collection->interface()); } else if (interpolationSchemeItem->value() == "inverse distance weighting") { @@ -273,8 +270,7 @@ ElevateMesh::Result ElevateMesh::operateInternal() if (interpolationSchemeItem->value() == "radial average") { interpolation = smtk::mesh::RadialAverage( - smtk::mesh::Collection::create(meshItem->value().collection()->interface()), pointcloud, - radiusItem->value()); + smtk::mesh::Collection::create(collection->interface()), pointcloud, radiusItem->value()); } else if (interpolationSchemeItem->value() == "inverse distance weighting") { @@ -364,8 +360,6 @@ ElevateMesh::Result ElevateMesh::operateInternal() // Access the attribute associated with the modified meshes Result result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - smtk::attribute::MeshItem::Ptr modifiedMeshes = result->findMesh("mesh_modified"); - modifiedMeshes->setNumberOfValues(meshItem->numberOfValues()); // Access the attribute associated with the modified model smtk::attribute::ComponentItem::Ptr modified = result->findComponent("modified"); @@ -377,11 +371,12 @@ ElevateMesh::Result ElevateMesh::operateInternal() // apply the interpolator to the meshes and populate the result attributes for (std::size_t i = 0; i < meshItem->numberOfValues(); i++) { - smtk::mesh::MeshSet mesh = meshItem->value(i); + auto meshComponent = meshItem->valueAs(i); + auto mesh = meshComponent->mesh(); smtk::mesh::utility::applyWarp(fn, mesh, true); - modifiedMeshes->appendValue(mesh); + modified->appendObjectValue(meshComponent); smtk::model::EntityRefArray entities; bool entitiesAreValid = mesh.modelEntities(entities); diff --git a/smtk/mesh/operators/ElevateMesh.sbt b/smtk/mesh/operators/ElevateMesh.sbt index a926591dc9..7335d2d4bd 100644 --- a/smtk/mesh/operators/ElevateMesh.sbt +++ b/smtk/mesh/operators/ElevateMesh.sbt @@ -16,6 +16,11 @@ data set, and it computes new z-coordinates at each mesh node as a radial average of the scalar values in the external data set. + + + + + @@ -110,10 +115,6 @@ - - The mesh to elevate. - - The interpolation scheme to apply to the input data @@ -260,7 +261,6 @@ - diff --git a/smtk/mesh/pybind11/PybindComponent.h b/smtk/mesh/pybind11/PybindComponent.h new file mode 100644 index 0000000000..9c0f918b9e --- /dev/null +++ b/smtk/mesh/pybind11/PybindComponent.h @@ -0,0 +1,44 @@ +//========================================================================= +// Copyright (c) Kitware, Inc. +// All rights reserved. +// See LICENSE.txt 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. +//========================================================================= + +#ifndef pybind_smtk_mesh_Component_h +#define pybind_smtk_mesh_Component_h + +#include + +#include "smtk/mesh/core/Component.h" + +#include "smtk/common/UUID.h" +#include "smtk/common/pybind11/PybindUUIDTypeCaster.h" +#include "smtk/mesh/core/Collection.h" +#include "smtk/resource/Component.h" + +namespace py = pybind11; + +PySharedPtrClass< smtk::mesh::Component, smtk::resource::Component > pybind11_init_smtk_mesh_Component(py::module &m) +{ + PySharedPtrClass< smtk::mesh::Component, smtk::resource::Component > instance(m, "Component"); + instance + .def(py::init<::smtk::mesh::Component const &>()) + .def("deepcopy", (smtk::mesh::Component & (smtk::mesh::Component::*)(::smtk::mesh::Component const &)) &smtk::mesh::Component::operator=) + .def("shared_from_this", (std::shared_ptr (smtk::mesh::Component::*)()) &smtk::mesh::Component::shared_from_this) + .def("shared_from_this", (std::shared_ptr (smtk::mesh::Component::*)() const) &smtk::mesh::Component::shared_from_this) + .def_static("create", (std::shared_ptr (*)(const smtk::mesh::CollectionPtr&, const smtk::common::UUID&)) &smtk::mesh::Component::create, py::arg("collection"), py::arg("id")) + .def_static("create", (std::shared_ptr (*)(const smtk::mesh::MeshSet&)) &smtk::mesh::Component::create, py::arg("meshset")) + .def("resource", &smtk::mesh::Component::resource) + .def("mesh", (smtk::mesh::MeshSet (smtk::mesh::Component::*)()) &smtk::mesh::Component::mesh) + .def_static("CastTo", [](const std::shared_ptr i) { + return std::dynamic_pointer_cast(i); + }) + ; + return instance; +} + +#endif diff --git a/smtk/mesh/pybind11/PybindMesh.cxx b/smtk/mesh/pybind11/PybindMesh.cxx index bb64784d53..b1cd5f28d6 100644 --- a/smtk/mesh/pybind11/PybindMesh.cxx +++ b/smtk/mesh/pybind11/PybindMesh.cxx @@ -27,6 +27,7 @@ using PySharedPtrClass = py::class_, Args...>; #include "PybindCellSet.h" #include "PybindCellTypes.h" #include "PybindCollection.h" +#include "PybindComponent.h" #include "PybindDimensionTypes.h" #include "PybindExtractMeshConstants.h" #include "PybindExtractTessellation.h" @@ -156,6 +157,7 @@ PYBIND11_MODULE(_smtkPybindMesh, mesh) PySharedPtrClass< smtk::mesh::Neumann > smtk_mesh_Neumann = pybind11_init_smtk_mesh_Neumann(mesh, smtk_mesh_IntegerTag); PySharedPtrClass< smtk::mesh::UUIDTag > smtk_mesh_UUIDTag = pybind11_init_smtk_mesh_UUIDTag(mesh, smtk_mesh_OpaqueTag_16_); PySharedPtrClass< smtk::mesh::Model > smtk_mesh_Model = pybind11_init_smtk_mesh_Model(mesh, smtk_mesh_UUIDTag); + PySharedPtrClass< smtk::mesh::Component > smtk_mesh_Component = pybind11_init_smtk_mesh_Component(mesh); PySharedPtrClass< smtk::mesh::DeleteMesh, smtk::operation::XMLOperation > smtk_mesh_DeleteMesh = pybind11_init_smtk_mesh_DeleteMesh(mesh); PySharedPtrClass< smtk::mesh::ElevateMesh, smtk::operation::XMLOperation > smtk_mesh_ElevateMesh = pybind11_init_smtk_mesh_ElevateMesh(mesh); diff --git a/smtk/mesh/resource/MeshComponent.cxx b/smtk/mesh/resource/MeshComponent.cxx deleted file mode 100644 index 4b9c3b8d36..0000000000 --- a/smtk/mesh/resource/MeshComponent.cxx +++ /dev/null @@ -1,102 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt 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 "smtk/mesh/resource/MeshComponent.h" - -#include "smtk/mesh/core/Collection.h" - -namespace smtk -{ -namespace mesh -{ - -MeshComponent::MeshComponent(smtk::mesh::MeshSet meshset) - : smtk::resource::Component() - , m_meshset(meshset) -{ -} - -MeshComponent::MeshComponent(const smtk::common::UUID& id, smtk::mesh::MeshSet meshset) - : smtk::resource::Component() - , m_meshset(meshset) -{ - this->setId(id); -} - -const smtk::resource::ResourcePtr MeshComponent::resource() const -{ - return std::dynamic_pointer_cast(m_meshset.collection()); -} - -/**\brief Return an array of model entity UUIDs associated with meshset members. - * - */ -smtk::common::UUIDArray MeshComponent::modelEntityIds() const -{ - if (!m_meshset.collection()) - { - return smtk::common::UUIDArray(); - } - - const smtk::mesh::InterfacePtr& iface = m_meshset.collection()->interface(); - return iface->computeModelEntities(m_meshset.range()); -} - -/**\brief Return the model entities associated with meshset members. - * - * warning Note that the parent collection of the meshset must have - * its model resource set to a valid value or the result will - * be an array of invalid entries. - */ -bool MeshComponent::modelEntities(smtk::model::EntityRefArray& array) const -{ - if (!m_meshset.collection()) - { - return false; - } - - smtk::model::ResourcePtr resource = m_meshset.collection()->modelResource(); - smtk::common::UUIDArray uids = this->modelEntityIds(); - for (smtk::common::UUIDArray::const_iterator it = uids.begin(); it != uids.end(); ++it) - { - array.push_back(smtk::model::EntityRef(resource, *it)); - } - return (resource != nullptr); -} - -/**\brief Set the model entity for each meshset member to \a ent. - * - */ -bool MeshComponent::setModelEntity(const smtk::model::EntityRef& ent) -{ - if (!m_meshset.collection()) - { - return false; - } - - const smtk::mesh::InterfacePtr& iface = m_meshset.collection()->interface(); - return iface->setAssociation(ent.entity(), m_meshset.range()); -} - -/**\brief Set the model entity for each meshset member to \a ent. - * - */ -bool MeshComponent::setModelEntityId(const smtk::common::UUID& id) -{ - if (!m_meshset.collection()) - { - return false; - } - - const smtk::mesh::InterfacePtr& iface = m_meshset.collection()->interface(); - return iface->setAssociation(id, m_meshset.range()); -} -} -} diff --git a/smtk/mesh/resource/MeshComponent.h b/smtk/mesh/resource/MeshComponent.h deleted file mode 100644 index dc786a0d52..0000000000 --- a/smtk/mesh/resource/MeshComponent.h +++ /dev/null @@ -1,90 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt 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. -//========================================================================= - -#ifndef __smtk_mesh_MeshComponent_h -#define __smtk_mesh_MeshComponent_h - -#include "smtk/CoreExports.h" -#include "smtk/PublicPointerDefs.h" - -#include "smtk/resource/Component.h" - -#include "smtk/mesh/core/MeshSet.h" - -namespace smtk -{ -namespace mesh -{ -class MeshComponent; - -typedef std::vector MeshComponentList; -typedef std::set MeshComponents; - -class SMTKCORE_EXPORT MeshComponent : public smtk::resource::Component -{ -protected: - MeshComponent(smtk::mesh::MeshSet meshset = smtk::mesh::MeshSet()); - MeshComponent(const smtk::common::UUID& id, smtk::mesh::MeshSet ms = smtk::mesh::MeshSet()); - - // Expose all MeshSet constructors - template - MeshComponent(T&&... all) - : MeshComponent(MeshSet(std::forward(all)...)) - { - } - - template - MeshComponent(const smtk::common::UUID& id, T&&... all) - : MeshComponent(id, MeshSet(std::forward(all)...)) - { - } - -public: - typedef smtk::shared_ptr MeshComponentPtr; - - smtkTypeMacro(MeshComponent); - smtkSharedPtrCreateMacro(smtk::resource::Component); - - // Expose all constructors as static create methods - template - static MeshComponentPtr create(T&&... all) - { - return MeshComponentPtr(new MeshComponent(std::forward(all)...)); - } - - const smtk::resource::ResourcePtr resource() const override; - - smtk::common::UUIDArray modelEntityIds() const; - - // Append the passed EntityRefArray with the model entities associated with - // this meshset, and return true on success. If the MeshSet's parent collection - // does not have its ModelManager set, this method will fail even though - // modelEntityIds() will still be valid. - bool modelEntities(smtk::model::EntityRefArray&) const; - bool setModelEntityId(const smtk::common::UUID&); - bool setModelEntity(const smtk::model::EntityRef&); - - const smtk::common::UUID& id() const override { return m_meshset.id(); } - bool setId(const smtk::common::UUID& id) override - { - m_meshset.setId(id); - return true; - } - - smtk::mesh::MeshSet meshes() const { return m_meshset; } - -private: - smtk::mesh::MeshSet m_meshset; -}; - -} // namespace mesh -} // namespace smtk - -#endif diff --git a/smtk/mesh/testing/cxx/TestElevateMesh.cxx b/smtk/mesh/testing/cxx/TestElevateMesh.cxx index 8417691647..710de56603 100644 --- a/smtk/mesh/testing/cxx/TestElevateMesh.cxx +++ b/smtk/mesh/testing/cxx/TestElevateMesh.cxx @@ -29,6 +29,7 @@ #include "smtk/io/ExportMesh.h" #include "smtk/mesh/core/Collection.h" +#include "smtk/mesh/core/Component.h" #include "smtk/mesh/core/ForEachTypes.h" #include "smtk/mesh/operators/ElevateMesh.h" #include "smtk/mesh/operators/UndoElevateMesh.h" @@ -223,13 +224,19 @@ int TestElevateMesh(int argc, char* argv[]) } // set input values for the elevate mesh operator + elevateMesh->parameters()->associate(smtk::mesh::Component::create(mesh)); elevateMesh->parameters()->findString("input data")->setToDefault(); elevateMesh->parameters() ->findComponent("auxiliary geometry") ->setObjectValue(auxGeo2dm.component()); elevateMesh->parameters()->findString("interpolation scheme")->setToDefault(); elevateMesh->parameters()->findDouble("radius")->setValue(7.); - elevateMesh->parameters()->findMesh("mesh")->appendValue(mesh); + + if (elevateMesh->ableToOperate() == false) + { + std::cerr << "Elevate mesh operator could not operate\n"; + return 1; + } smtk::operation::Operation::Result bathyResult = elevateMesh->operate(); if (bathyResult->findInt("outcome")->value() != diff --git a/smtk/mesh/testing/cxx/TestElevateMeshOnStructuredGrid.cxx b/smtk/mesh/testing/cxx/TestElevateMeshOnStructuredGrid.cxx index 10aeb38689..61d078dafc 100644 --- a/smtk/mesh/testing/cxx/TestElevateMeshOnStructuredGrid.cxx +++ b/smtk/mesh/testing/cxx/TestElevateMeshOnStructuredGrid.cxx @@ -29,6 +29,7 @@ #include "smtk/io/ExportMesh.h" #include "smtk/mesh/core/Collection.h" +#include "smtk/mesh/core/Component.h" #include "smtk/mesh/core/ForEachTypes.h" #include "smtk/mesh/operators/ElevateMesh.h" #include "smtk/mesh/operators/UndoElevateMesh.h" @@ -215,6 +216,7 @@ int TestElevateMeshOnStructuredGrid(int argc, char* argv[]) } // set input values for the elevate mesh operator + elevateMesh->parameters()->associate(smtk::mesh::Component::create(mesh)); elevateMesh->parameters()->findString("input data")->setToDefault(); elevateMesh->parameters() ->findComponent("auxiliary geometry") @@ -223,7 +225,6 @@ int TestElevateMeshOnStructuredGrid(int argc, char* argv[]) elevateMesh->parameters()->findDouble("radius")->setValue(7.); elevateMesh->parameters()->findString("external point values")->setValue("set to value"); elevateMesh->parameters()->findDouble("external point value")->setValue(-1.); - elevateMesh->parameters()->findMesh("mesh")->appendValue(mesh); smtk::operation::Operation::Result bathyResult = elevateMesh->operate(); if (bathyResult->findInt("outcome")->value() != diff --git a/smtk/mesh/testing/cxx/TestWarpMesh.cxx b/smtk/mesh/testing/cxx/TestWarpMesh.cxx index b2ceb671e4..8532fe429d 100644 --- a/smtk/mesh/testing/cxx/TestWarpMesh.cxx +++ b/smtk/mesh/testing/cxx/TestWarpMesh.cxx @@ -25,6 +25,7 @@ #include "smtk/mesh/core/CellField.h" #include "smtk/mesh/core/Collection.h" +#include "smtk/mesh/core/Component.h" #include "smtk/mesh/core/ForEachTypes.h" #include "smtk/mesh/operators/ElevateMesh.h" @@ -146,7 +147,7 @@ int main(int argc, char* argv[]) // Set the operator's input mesh smtk::mesh::MeshSet mesh = collection->meshes(); - bool valueSet = elevateMeshOp->parameters()->findMesh("mesh")->appendValue(mesh); + bool valueSet = elevateMeshOp->parameters()->associate(smtk::mesh::Component::create(mesh)); if (!valueSet) { diff --git a/smtk/mesh/testing/python/elevateMeshOnStructuredGrid.py b/smtk/mesh/testing/python/elevateMeshOnStructuredGrid.py index d6f9650c06..4f51288543 100644 --- a/smtk/mesh/testing/python/elevateMeshOnStructuredGrid.py +++ b/smtk/mesh/testing/python/elevateMeshOnStructuredGrid.py @@ -128,7 +128,7 @@ class ElevateMeshOnStructuredGrid(smtk.testing.TestCase): op.parameters().find("external point values").setToDefault() # Set the mesh - op.parameters().find("mesh").appendValue(self.mesh) + op.parameters().associate(smtk.mesh.Component.create(self.mesh)) # Clamp the elevation values between -/+ 2 outputFilter = op.parameters().find("output filter") -- GitLab From e80a524f297af25bf760a1d39f1e76227e9ac631 Mon Sep 17 00:00:00 2001 From: "T.J. Corona" Date: Tue, 30 Oct 2018 08:32:35 -0400 Subject: [PATCH 2/2] Use mesh::Component for mesh operations --- smtk/mesh/operators/DeleteMesh.cxx | 33 +++++++++++-------- smtk/mesh/operators/DeleteMesh.sbt | 7 ++-- smtk/mesh/operators/ExportMesh.cxx | 15 ++++----- smtk/mesh/operators/ExportMesh.sbt | 4 ++- smtk/mesh/operators/GenerateHotStartData.cxx | 22 ++++--------- smtk/mesh/operators/GenerateHotStartData.sbt | 9 ++--- smtk/mesh/operators/InterpolateOntoMesh.cxx | 26 ++++++--------- smtk/mesh/operators/InterpolateOntoMesh.sbt | 10 +++--- smtk/mesh/operators/UndoElevateMesh.cxx | 14 ++++---- smtk/mesh/operators/UndoElevateMesh.sbt | 7 ++-- smtk/mesh/operators/WriteMesh.cxx | 25 ++++---------- smtk/mesh/operators/WriteMesh.sbt | 4 ++- smtk/mesh/testing/cxx/TestElevateMesh.cxx | 2 +- .../cxx/TestElevateMeshOnStructuredGrid.cxx | 2 +- .../testing/cxx/TestGenerateHotStartData.cxx | 4 +-- .../testing/cxx/TestInterpolateOntoMesh.cxx | 4 +-- .../testing/cxx/unitExportMeshOperation.cxx | 4 ++- 17 files changed, 89 insertions(+), 103 deletions(-) diff --git a/smtk/mesh/operators/DeleteMesh.cxx b/smtk/mesh/operators/DeleteMesh.cxx index 9eafeb2740..4e6209c43f 100644 --- a/smtk/mesh/operators/DeleteMesh.cxx +++ b/smtk/mesh/operators/DeleteMesh.cxx @@ -10,13 +10,15 @@ #include "smtk/mesh/operators/DeleteMesh.h" #include "smtk/mesh/core/Collection.h" +#include "smtk/mesh/core/Component.h" #include "smtk/mesh/core/MeshSet.h" #include "smtk/model/Session.h" #include "smtk/model/Session.h" #include "smtk/attribute/Attribute.h" -#include "smtk/attribute/MeshItem.h" +#include "smtk/attribute/ComponentItem.h" +#include "smtk/attribute/IntItem.h" #include "smtk/mesh/DeleteMesh_xml.h" @@ -27,23 +29,28 @@ namespace mesh smtk::mesh::DeleteMesh::Result DeleteMesh::operateInternal() { - // ableToOperate should have verified that mesh(s) are set - smtk::attribute::MeshItem::Ptr meshItem = this->parameters()->findMesh("mesh"); + Result result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - smtk::mesh::MeshSets expunged; - bool success = true; - for (attribute::MeshItem::const_mesh_it mit = meshItem->begin(); mit != meshItem->end(); ++mit) + smtk::attribute::ReferenceItem::Ptr meshItem = this->parameters()->associations(); + bool allRemoved = true; + for (std::size_t i = 0; i < meshItem->numberOfValues(); i++) { - // all mesh items are guaranteed to have a valid associated collection by ableToOperate - smtk::mesh::CollectionPtr collec = mit->collection(); - } + smtk::mesh::Component::Ptr meshComponent = meshItem->valueAs(i); + smtk::mesh::MeshSet meshset = meshComponent->mesh(); + bool removed = meshset.collection()->removeMeshes(meshset); + + if (removed) + { + result->findComponent("expunged")->appendValue(meshComponent); + } - Result result = this->createResult(success ? smtk::operation::Operation::Outcome::SUCCEEDED - : smtk::operation::Operation::Outcome::FAILED); + allRemoved &= removed; + } - if (success) + if (allRemoved == false) { - result->findMesh("mesh_expunged")->appendValues(expunged); + result->findInt("outcome")->setValue( + 0, static_cast(smtk::operation::Operation::Outcome::FAILED)); } return result; } diff --git a/smtk/mesh/operators/DeleteMesh.sbt b/smtk/mesh/operators/DeleteMesh.sbt index b24881690a..bf7182da6b 100644 --- a/smtk/mesh/operators/DeleteMesh.sbt +++ b/smtk/mesh/operators/DeleteMesh.sbt @@ -4,9 +4,9 @@ - - - + + + Remove a mesh from the model instance. @@ -20,7 +20,6 @@ - diff --git a/smtk/mesh/operators/ExportMesh.cxx b/smtk/mesh/operators/ExportMesh.cxx index 7a0a4e841b..5a0f645cb5 100644 --- a/smtk/mesh/operators/ExportMesh.cxx +++ b/smtk/mesh/operators/ExportMesh.cxx @@ -20,6 +20,7 @@ #include "smtk/mesh/ExportMesh_xml.h" #include "smtk/mesh/core/Collection.h" +#include "smtk/mesh/core/Component.h" #include "smtk/mesh/core/MeshSet.h" #include "smtk/model/Resource.h" @@ -58,28 +59,27 @@ bool ExportMesh::ableToOperate() { return false; } - smtk::attribute::MeshItem::Ptr meshItem = this->parameters()->findMesh("mesh"); - return meshItem && meshItem->numberOfValues() > 0; + return true; } ExportMesh::Result ExportMesh::operateInternal() { std::string outputfile = this->parameters()->findFile("filename")->value(); - // ableToOperate should have verified that mesh(s) are set - smtk::attribute::MeshItem::Ptr meshItem = this->parameters()->findMesh("mesh"); + smtk::attribute::ReferenceItem::Ptr meshItem = this->parameters()->associations(); // for multiple meshes, we suffix the file name root with ascending integers std::string root = outputfile.substr(0, outputfile.find_last_of(".")); std::string ext = outputfile.substr(outputfile.find_last_of(".")); int index = 0; - smtk::mesh::MeshSets written; std::vector generatedFiles; - for (attribute::MeshItem::const_mesh_it mit = meshItem->begin(); mit != meshItem->end(); ++mit) + for (std::size_t i = 0; i < meshItem->numberOfValues(); i++) { - smtk::mesh::CollectionPtr collection = mit->collection(); + smtk::mesh::Component::Ptr meshComponent = meshItem->valueAs(i); + smtk::mesh::CollectionPtr collection = + std::dynamic_pointer_cast(meshComponent->resource()); bool fileExportSuccess = false; if (collection) @@ -98,7 +98,6 @@ ExportMesh::Result ExportMesh::operateInternal() { ++index; generatedFiles.push_back(outputfile); - written.insert(*mit); } } diff --git a/smtk/mesh/operators/ExportMesh.sbt b/smtk/mesh/operators/ExportMesh.sbt index a16ea29e54..e4a35a1f6f 100644 --- a/smtk/mesh/operators/ExportMesh.sbt +++ b/smtk/mesh/operators/ExportMesh.sbt @@ -15,8 +15,10 @@ mesh is not guaranteed to contain all of the information from the original mesh. + + + - diff --git a/smtk/mesh/operators/GenerateHotStartData.cxx b/smtk/mesh/operators/GenerateHotStartData.cxx index ac1954c2ff..c1668a1059 100644 --- a/smtk/mesh/operators/GenerateHotStartData.cxx +++ b/smtk/mesh/operators/GenerateHotStartData.cxx @@ -21,6 +21,7 @@ #include "smtk/mesh/GenerateHotStartData_xml.h" #include "smtk/mesh/core/CellField.h" +#include "smtk/mesh/core/Component.h" #include "smtk/mesh/core/MeshSet.h" #include "smtk/mesh/core/PointField.h" @@ -188,20 +189,13 @@ bool GenerateHotStartData::ableToOperate() { return false; } - - smtk::attribute::MeshItem::Ptr meshItem = this->parameters()->findMesh("mesh"); - if (!meshItem || meshItem->numberOfValues() == 0) - { - return false; - } - return true; } GenerateHotStartData::Result GenerateHotStartData::operateInternal() { // Access the mesh to elevate - smtk::attribute::MeshItem::Ptr meshItem = this->parameters()->findMesh("mesh"); + smtk::attribute::ReferenceItem::Ptr meshItem = this->parameters()->associations(); // Access the data set type smtk::attribute::StringItem::Ptr typeItem = this->parameters()->findString("dstype"); @@ -249,7 +243,7 @@ GenerateHotStartData::Result GenerateHotStartData::operateInternal() bool meshIsContainedByPointCloud = true; for (std::size_t i = 0; i < meshItem->numberOfValues(); i++) { - smtk::mesh::MeshSet mesh = meshItem->value(i); + smtk::mesh::MeshSet mesh = meshItem->valueAs(i)->mesh(); std::array mesh_bounds = bounds(mesh); for (std::size_t j = 0; j < 3; j++) @@ -271,10 +265,8 @@ GenerateHotStartData::Result GenerateHotStartData::operateInternal() // Construct an instance of our interpolator and set its parameters smtk::mesh::InverseDistanceWeighting interpolator(pointcloud, powerItem->value()); - // Access the attribute associated with the modified meshes + // Construct a result object to hold our output Result result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - smtk::attribute::MeshItem::Ptr modifiedMeshes = result->findMesh("mesh_modified"); - modifiedMeshes->setNumberOfValues(meshItem->numberOfValues()); // Access the attribute associated with the modified model smtk::attribute::ComponentItem::Ptr modified = result->findComponent("modified"); @@ -310,11 +302,11 @@ GenerateHotStartData::Result GenerateHotStartData::operateInternal() // apply the interpolator to the meshes and populate the result attributes for (std::size_t i = 0; i < meshItem->numberOfValues(); i++) { - smtk::mesh::MeshSet mesh = meshItem->value(i); - + smtk::mesh::Component::Ptr meshComponent = meshItem->valueAs(i); + smtk::mesh::MeshSet mesh = meshComponent->mesh(); smtk::mesh::utility::applyScalarPointField(fn, name, mesh); - modifiedMeshes->appendValue(mesh); + modified->appendValue(meshComponent); smtk::model::EntityRefArray entities; bool entitiesAreValid = mesh.modelEntities(entities); diff --git a/smtk/mesh/operators/GenerateHotStartData.sbt b/smtk/mesh/operators/GenerateHotStartData.sbt index 4c7d7948fd..30f967edd2 100644 --- a/smtk/mesh/operators/GenerateHotStartData.sbt +++ b/smtk/mesh/operators/GenerateHotStartData.sbt @@ -18,11 +18,12 @@ onto either the points or the cells of the mesh. The input points can be inserted manually or read from a CSV file. - - - The mesh to elevate. - + + + + + The name of the data set. diff --git a/smtk/mesh/operators/InterpolateOntoMesh.cxx b/smtk/mesh/operators/InterpolateOntoMesh.cxx index cb4f0f143d..96a9eba819 100644 --- a/smtk/mesh/operators/InterpolateOntoMesh.cxx +++ b/smtk/mesh/operators/InterpolateOntoMesh.cxx @@ -16,13 +16,13 @@ #include "smtk/attribute/FileItem.h" #include "smtk/attribute/GroupItem.h" #include "smtk/attribute/IntItem.h" -#include "smtk/attribute/MeshItem.h" #include "smtk/attribute/StringItem.h" #include "smtk/attribute/VoidItem.h" #include "smtk/mesh/InterpolateOntoMesh_xml.h" #include "smtk/mesh/core/CellField.h" #include "smtk/mesh/core/Collection.h" +#include "smtk/mesh/core/Component.h" #include "smtk/mesh/core/MeshSet.h" #include "smtk/mesh/core/PointField.h" @@ -130,12 +130,6 @@ bool InterpolateOntoMesh::ableToOperate() return false; } - smtk::attribute::MeshItem::Ptr meshItem = this->parameters()->findMesh("mesh"); - if (!meshItem || meshItem->numberOfValues() == 0) - { - return false; - } - return true; } @@ -145,7 +139,9 @@ InterpolateOntoMesh::Result InterpolateOntoMesh::operateInternal() smtk::attribute::StringItem::Ptr inputDataItem = this->parameters()->findString("input data"); // Access the mesh to elevate - smtk::attribute::MeshItem::Ptr meshItem = this->parameters()->findMesh("mesh"); + smtk::attribute::ReferenceItem::Ptr meshItem = this->parameters()->associations(); + smtk::mesh::MeshSet meshset = meshItem->valueAs()->mesh(); + smtk::mesh::Collection::Ptr collection = meshset.collection(); // Access the string describing the interpolation scheme smtk::attribute::StringItem::Ptr interpolationSchemeItem = @@ -220,7 +216,7 @@ InterpolateOntoMesh::Result InterpolateOntoMesh::operateInternal() { // Compute the radial average function interpolation = radialAverageFrom( - auxGeo, radiusItem->value(), prefilter, meshItem->value().collection()->interface()); + auxGeo, radiusItem->value(), prefilter, collection->interface()); } else if (interpolationSchemeItem->value() == "inverse distance weighting") { @@ -244,7 +240,7 @@ InterpolateOntoMesh::Result InterpolateOntoMesh::operateInternal() { // Compute the radial average function interpolation = radialAverageFrom( - fileName, radiusItem->value(), prefilter, meshItem->value().collection()->interface()); + fileName, radiusItem->value(), prefilter, collection->interface()); } else if (interpolationSchemeItem->value() == "inverse distance weighting") { @@ -286,8 +282,7 @@ InterpolateOntoMesh::Result InterpolateOntoMesh::operateInternal() if (interpolationSchemeItem->value() == "radial average") { interpolation = smtk::mesh::RadialAverage( - smtk::mesh::Collection::create(meshItem->value().collection()->interface()), pointcloud, - radiusItem->value()); + smtk::mesh::Collection::create(collection->interface()), pointcloud, radiusItem->value()); } else if (interpolationSchemeItem->value() == "inverse distance weighting") { @@ -364,8 +359,6 @@ InterpolateOntoMesh::Result InterpolateOntoMesh::operateInternal() // Access the attribute associated with the modified meshes Result result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - smtk::attribute::MeshItem::Ptr modifiedMeshes = result->findMesh("mesh_modified"); - modifiedMeshes->setNumberOfValues(meshItem->numberOfValues()); // Access the attribute associated with the modified model smtk::attribute::ComponentItem::Ptr modified = result->findComponent("modified"); @@ -388,7 +381,8 @@ InterpolateOntoMesh::Result InterpolateOntoMesh::operateInternal() // apply the interpolator to the meshes and populate the result attributes for (std::size_t i = 0; i < meshItem->numberOfValues(); i++) { - smtk::mesh::MeshSet mesh = meshItem->value(i); + smtk::mesh::Component::Ptr meshComponent = meshItem->valueAs(i); + smtk::mesh::MeshSet mesh = meshComponent->mesh(); if (modeItem->value(0) == CELL_FIELD) { @@ -399,7 +393,7 @@ InterpolateOntoMesh::Result InterpolateOntoMesh::operateInternal() smtk::mesh::utility::applyScalarPointField(fn, nameItem->value(), mesh); } - modifiedMeshes->appendValue(mesh); + modified->appendValue(meshComponent); smtk::model::EntityRefArray entities; bool entitiesAreValid = mesh.modelEntities(entities); diff --git a/smtk/mesh/operators/InterpolateOntoMesh.sbt b/smtk/mesh/operators/InterpolateOntoMesh.sbt index 8aabd36a0d..e5c0a6044d 100644 --- a/smtk/mesh/operators/InterpolateOntoMesh.sbt +++ b/smtk/mesh/operators/InterpolateOntoMesh.sbt @@ -17,6 +17,11 @@ Shepard's method for interpolation. The input points can be inserted manually or read from a CSV file. + + + + + @@ -111,10 +116,6 @@ - - The mesh onto which the data is interpolated. - - The interpolation scheme to apply to the input data @@ -274,7 +275,6 @@ - diff --git a/smtk/mesh/operators/UndoElevateMesh.cxx b/smtk/mesh/operators/UndoElevateMesh.cxx index 01123bf72b..82aac09a34 100644 --- a/smtk/mesh/operators/UndoElevateMesh.cxx +++ b/smtk/mesh/operators/UndoElevateMesh.cxx @@ -17,6 +17,7 @@ #include "smtk/io/Logger.h" #include "smtk/mesh/UndoElevateMesh_xml.h" +#include "smtk/mesh/core/Component.h" #include "smtk/mesh/core/MeshSet.h" #include "smtk/mesh/core/PointField.h" #include "smtk/mesh/utility/ApplyToMesh.h" @@ -35,7 +36,7 @@ bool UndoElevateMesh::ableToOperate() return false; } - smtk::attribute::MeshItem::Ptr meshItem = this->parameters()->findMesh("mesh"); + smtk::attribute::ReferenceItem::Ptr meshItem = this->parameters()->associations(); if (!meshItem || meshItem->numberOfValues() == 0) { return false; @@ -43,7 +44,7 @@ bool UndoElevateMesh::ableToOperate() for (std::size_t i = 0; i < meshItem->numberOfValues(); i++) { - smtk::mesh::MeshSet mesh = meshItem->value(i); + smtk::mesh::MeshSet mesh = meshItem->valueAs(i)->mesh(); smtk::mesh::PointField prior = mesh.pointField("_prior"); if (!prior.isValid()) { @@ -57,12 +58,10 @@ bool UndoElevateMesh::ableToOperate() UndoElevateMesh::Result UndoElevateMesh::operateInternal() { // Access the mesh - smtk::attribute::MeshItem::Ptr meshItem = this->parameters()->findMesh("mesh"); + smtk::attribute::ReferenceItem::Ptr meshItem = this->parameters()->associations(); // Access the attribute associated with the modified meshes Result result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - smtk::attribute::MeshItem::Ptr modifiedMeshes = result->findMesh("mesh_modified"); - modifiedMeshes->setNumberOfValues(meshItem->numberOfValues()); // Access the attribute associated with the modified model smtk::attribute::ComponentItem::Ptr modified = result->findComponent("modified"); @@ -74,7 +73,8 @@ UndoElevateMesh::Result UndoElevateMesh::operateInternal() // apply the interpolator to the meshes and populate the result attributes for (std::size_t i = 0; i < meshItem->numberOfValues(); i++) { - smtk::mesh::MeshSet mesh = meshItem->value(i); + smtk::mesh::Component::Ptr meshComponent = meshItem->valueAs(i); + smtk::mesh::MeshSet mesh = meshComponent->mesh(); bool success = smtk::mesh::utility::undoWarp(mesh); @@ -84,7 +84,7 @@ UndoElevateMesh::Result UndoElevateMesh::operateInternal() return this->createResult(smtk::operation::Operation::Outcome::FAILED); } - modifiedMeshes->appendValue(mesh); + modified->appendValue(meshComponent); smtk::model::EntityRefArray entities; bool entitiesAreValid = mesh.modelEntities(entities); diff --git a/smtk/mesh/operators/UndoElevateMesh.sbt b/smtk/mesh/operators/UndoElevateMesh.sbt index 9b021ed41b..6c636153c1 100644 --- a/smtk/mesh/operators/UndoElevateMesh.sbt +++ b/smtk/mesh/operators/UndoElevateMesh.sbt @@ -15,17 +15,16 @@ (e.g. Mesh - Elevate). This operator removes the elevateing applied by these operators. + + + - - The mesh to restore. - - diff --git a/smtk/mesh/operators/WriteMesh.cxx b/smtk/mesh/operators/WriteMesh.cxx index 9f414a4f83..2bd1fbb6c5 100644 --- a/smtk/mesh/operators/WriteMesh.cxx +++ b/smtk/mesh/operators/WriteMesh.cxx @@ -13,13 +13,13 @@ #include "smtk/attribute/Attribute.h" #include "smtk/attribute/FileItem.h" #include "smtk/attribute/IntItem.h" -#include "smtk/attribute/MeshItem.h" #include "smtk/io/WriteMesh.h" #include "smtk/io/mesh/MeshIO.h" #include "smtk/mesh/WriteMesh_xml.h" #include "smtk/mesh/core/Collection.h" +#include "smtk/mesh/core/Component.h" #include "smtk/mesh/core/MeshSet.h" #include "smtk/model/Resource.h" @@ -58,8 +58,7 @@ bool WriteMesh::ableToOperate() { return false; } - smtk::attribute::MeshItem::Ptr meshItem = this->parameters()->findMesh("mesh"); - return meshItem && meshItem->numberOfValues() > 0; + return true; } WriteMesh::Result WriteMesh::operateInternal() @@ -69,20 +68,20 @@ WriteMesh::Result WriteMesh::operateInternal() smtk::io::mesh::Subset componentToWrite = static_cast(this->parameters()->findInt("write-component")->value()); - // ableToOperate should have verified that mesh(s) are set - smtk::attribute::MeshItem::Ptr meshItem = this->parameters()->findMesh("mesh"); + smtk::attribute::ReferenceItem::Ptr meshItem = this->parameters()->associations(); // for multiple meshes, we suffix the file name root with ascending integers std::string root = outputfile.substr(0, outputfile.find_last_of(".")); std::string ext = outputfile.substr(outputfile.find_last_of(".")); int index = 0; - smtk::mesh::MeshSets written; std::vector generatedFiles; - for (attribute::MeshItem::const_mesh_it mit = meshItem->begin(); mit != meshItem->end(); ++mit) + for (std::size_t i = 0; i < meshItem->numberOfValues(); i++) { - smtk::mesh::CollectionPtr collection = mit->collection(); + smtk::mesh::Component::Ptr meshComponent = meshItem->valueAs(i); + smtk::mesh::CollectionPtr collection = + std::dynamic_pointer_cast(meshComponent->resource()); bool fileWriteSuccess = false; if (collection) @@ -101,7 +100,6 @@ WriteMesh::Result WriteMesh::operateInternal() { ++index; generatedFiles.push_back(outputfile); - written.insert(*mit); } } @@ -115,16 +113,7 @@ WriteMesh::Result WriteMesh::operateInternal() } } - // We mark the written meshes as "modified" so that the containing collection's URL can - // be properly updated. Result result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED); - smtk::attribute::MeshItem::Ptr modifiedMeshes = result->findMesh("mesh_modified"); - modifiedMeshes->setNumberOfValues(written.size()); - for (auto& mesh : written) - { - modifiedMeshes->appendValue(mesh); - } - return result; } diff --git a/smtk/mesh/operators/WriteMesh.sbt b/smtk/mesh/operators/WriteMesh.sbt index f09797731a..6af3ad7310 100644 --- a/smtk/mesh/operators/WriteMesh.sbt +++ b/smtk/mesh/operators/WriteMesh.sbt @@ -16,8 +16,10 @@ mesh is guaranteed to contain all of the information from the original mesh. + + + - diff --git a/smtk/mesh/testing/cxx/TestElevateMesh.cxx b/smtk/mesh/testing/cxx/TestElevateMesh.cxx index 710de56603..aca40b4fdc 100644 --- a/smtk/mesh/testing/cxx/TestElevateMesh.cxx +++ b/smtk/mesh/testing/cxx/TestElevateMesh.cxx @@ -269,7 +269,7 @@ int TestElevateMesh(int argc, char* argv[]) return 1; } - undoElevateMesh->parameters()->findMesh("mesh")->appendValue(mesh); + undoElevateMesh->parameters()->associate(smtk::mesh::Component::create(mesh)); smtk::operation::Operation::Result result = undoElevateMesh->operate(); if (result->findInt("outcome")->value() != diff --git a/smtk/mesh/testing/cxx/TestElevateMeshOnStructuredGrid.cxx b/smtk/mesh/testing/cxx/TestElevateMeshOnStructuredGrid.cxx index 61d078dafc..2d00b109a5 100644 --- a/smtk/mesh/testing/cxx/TestElevateMeshOnStructuredGrid.cxx +++ b/smtk/mesh/testing/cxx/TestElevateMeshOnStructuredGrid.cxx @@ -260,7 +260,7 @@ int TestElevateMeshOnStructuredGrid(int argc, char* argv[]) return 1; } - undoElevateMesh->parameters()->findMesh("mesh")->appendValue(mesh); + undoElevateMesh->parameters()->associate(smtk::mesh::Component::create(mesh)); smtk::operation::Operation::Result result = undoElevateMesh->operate(); if (result->findInt("outcome")->value() != diff --git a/smtk/mesh/testing/cxx/TestGenerateHotStartData.cxx b/smtk/mesh/testing/cxx/TestGenerateHotStartData.cxx index 1cc70f007a..8a9cd2d24c 100644 --- a/smtk/mesh/testing/cxx/TestGenerateHotStartData.cxx +++ b/smtk/mesh/testing/cxx/TestGenerateHotStartData.cxx @@ -15,7 +15,6 @@ #include "smtk/attribute/FileItem.h" #include "smtk/attribute/GroupItem.h" #include "smtk/attribute/IntItem.h" -#include "smtk/attribute/MeshItem.h" #include "smtk/attribute/StringItem.h" #include "smtk/io/ModelToMesh.h" @@ -23,6 +22,7 @@ #include "smtk/mesh/core/CellField.h" #include "smtk/mesh/core/Collection.h" +#include "smtk/mesh/core/Component.h" #include "smtk/mesh/core/ForEachTypes.h" #include "smtk/mesh/core/PointField.h" #include "smtk/mesh/operators/GenerateHotStartData.h" @@ -170,7 +170,7 @@ int main(int argc, char* argv[]) // Set the operator's input mesh smtk::mesh::MeshSet mesh = collection->meshes(); - valueSet = generateHotStartDataOp->parameters()->findMesh("mesh")->setValue(mesh); + valueSet = generateHotStartDataOp->parameters()->associate(smtk::mesh::Component::create(mesh)); if (!valueSet) { diff --git a/smtk/mesh/testing/cxx/TestInterpolateOntoMesh.cxx b/smtk/mesh/testing/cxx/TestInterpolateOntoMesh.cxx index 62fc166dda..77171da3ec 100644 --- a/smtk/mesh/testing/cxx/TestInterpolateOntoMesh.cxx +++ b/smtk/mesh/testing/cxx/TestInterpolateOntoMesh.cxx @@ -15,7 +15,6 @@ #include "smtk/attribute/FileItem.h" #include "smtk/attribute/GroupItem.h" #include "smtk/attribute/IntItem.h" -#include "smtk/attribute/MeshItem.h" #include "smtk/attribute/StringItem.h" #include "smtk/io/ModelToMesh.h" @@ -26,6 +25,7 @@ #include "smtk/mesh/core/CellField.h" #include "smtk/mesh/core/Collection.h" +#include "smtk/mesh/core/Component.h" #include "smtk/mesh/core/ForEachTypes.h" #include "smtk/mesh/core/PointField.h" #include "smtk/mesh/operators/InterpolateOntoMesh.h" @@ -194,7 +194,7 @@ int main(int argc, char* argv[]) // Set the operator's input mesh smtk::mesh::MeshSet mesh = collection->meshes(); - valueSet = interpolateOntoMeshOp->parameters()->findMesh("mesh")->setValue(mesh); + valueSet = interpolateOntoMeshOp->parameters()->associate(smtk::mesh::Component::create(mesh)); if (!valueSet) { diff --git a/smtk/model/testing/cxx/unitExportMeshOperation.cxx b/smtk/model/testing/cxx/unitExportMeshOperation.cxx index 4a495a39e0..b83f8b782c 100644 --- a/smtk/model/testing/cxx/unitExportMeshOperation.cxx +++ b/smtk/model/testing/cxx/unitExportMeshOperation.cxx @@ -21,6 +21,7 @@ #include "smtk/model/json/jsonResource.h" #include "smtk/mesh/core/Collection.h" +#include "smtk/mesh/core/Component.h" #include "smtk/mesh/operators/ExportMesh.h" #include "smtk/model/Resource.h" @@ -107,7 +108,8 @@ int main(int argc, char* argv[]) std::string export_path = std::string(write_root + "/testmesh.2dm"); exportMeshOp->parameters()->findFile("filename")->setValue(export_path); - bool valueSet = exportMeshOp->parameters()->findMesh("mesh")->setValue(collection->meshes()); + bool valueSet = + exportMeshOp->parameters()->associate(smtk::mesh::Component::create(collection->meshes())); if (!valueSet) { -- GitLab