Commit 0f45595d authored by T.J. Corona's avatar T.J. Corona

smtk::mesh::MeshSet: add name/setName methods

parent 8c6c6073
......@@ -51,6 +51,11 @@ const smtk::resource::ResourcePtr Component::resource() const
return std::static_pointer_cast<smtk::resource::Resource>(m_collection.lock());
}
std::string Component::name() const
{
return this->mesh().name();
}
const smtk::mesh::MeshSet Component::mesh() const
{
if (auto collection = m_collection.lock())
......
......@@ -68,6 +68,8 @@ public:
return true;
}
std::string name() const override;
/// Access the meshset represented by this component.
const smtk::mesh::MeshSet mesh() const;
smtk::mesh::MeshSet mesh();
......
......@@ -364,6 +364,9 @@ public:
//xyz needs to be allocated to 3*points.size()
virtual bool setCoordinates(const smtk::mesh::HandleRange& points, const float* const xyz) = 0;
virtual std::string name(const smtk::mesh::Handle& meshset) const = 0;
virtual bool setName(const smtk::mesh::Handle& meshset, const std::string& name) = 0;
virtual std::vector<std::string> computeNames(const smtk::mesh::HandleRange& meshsets) const = 0;
virtual std::vector<smtk::mesh::Domain> computeDomainValues(
......
......@@ -180,6 +180,18 @@ bool MeshSet::is_empty() const
return m_range.empty();
}
std::string MeshSet::name() const
{
const smtk::mesh::InterfacePtr& iface = m_parent->interface();
return iface->name(m_handle);
}
bool MeshSet::setName(const std::string& name)
{
const smtk::mesh::InterfacePtr& iface = m_parent->interface();
return iface->setName(m_handle, name);
}
std::size_t MeshSet::size() const
{
return m_range.size();
......
......@@ -90,6 +90,10 @@ public:
bool is_empty() const;
//set/get the name of this meshset
std::string name() const;
bool setName(const std::string&);
//number of meshes
std::size_t size() const;
......
......@@ -334,6 +334,17 @@ bool Interface::setCoordinates(const smtk::mesh::HandleRange&, const float* cons
return false;
}
std::string Interface::name(const smtk::mesh::Handle& meshset) const
{
//TODO
return std::string();
}
bool Interface::setName(const smtk::mesh::Handle& meshset, const std::string& name)
{
return false;
}
std::vector<std::string> Interface::computeNames(const smtk::mesh::HandleRange&) const
{
return std::vector<std::string>();
......
......@@ -181,6 +181,9 @@ public:
std::vector<std::string> computeNames(const smtk::mesh::HandleRange& meshsets) const override;
std::string name(const smtk::mesh::Handle& meshset) const override;
bool setName(const smtk::mesh::Handle& meshset, const std::string& name) override;
std::vector<smtk::mesh::Domain> computeDomainValues(
const smtk::mesh::HandleRange& meshsets) const override;
......
......@@ -677,6 +677,27 @@ bool Interface::setCoordinates(const smtk::mesh::HandleRange& points, const floa
return false;
}
std::string Interface::name(const smtk::mesh::Handle& meshset) const
{
//construct a name tag query helper class
tag::QueryNameTag query_name(this->moabInterface());
if (query_name.fetch_name(meshset))
{
return std::string(query_name.current_name());
}
return std::string();
}
bool Interface::setName(const smtk::mesh::Handle& meshset, const std::string& name)
{
//construct a name tag query helper class
tag::QueryNameTag query_name(this->moabInterface());
return query_name.set_name(meshset, name);
}
std::vector<std::string> Interface::computeNames(const smtk::mesh::HandleRange& meshsets) const
{
//construct a name tag query helper class
......
......@@ -187,6 +187,9 @@ public:
//xyz needs to be allocated to 3*points.size()
bool setCoordinates(const smtk::mesh::HandleRange& points, const float* const xyz) override;
std::string name(const smtk::mesh::Handle& meshset) const override;
bool setName(const smtk::mesh::Handle& meshset, const std::string& name) override;
std::vector<std::string> computeNames(const smtk::mesh::HandleRange& meshsets) const override;
std::vector<smtk::mesh::Domain> computeDomainValues(
......
......@@ -66,10 +66,24 @@ public:
{
return false;
}
::moab::ErrorCode rval = m_iface->tag_get_data(m_tag, &entity, 1, &m_tagData);
return (rval == ::moab::MB_SUCCESS);
}
bool set_name(const smtk::mesh::Handle& entity, const std::string& name)
{
if (!m_tag)
{
return false;
}
strcpy(m_tagData, name.substr(0, 32).c_str());
::moab::ErrorCode rval = m_iface->tag_set_data(m_tag, &entity, 1, &m_tagData);
return (rval == ::moab::MB_SUCCESS);
}
const char* current_name() const { return m_tagData; }
};
......
......@@ -153,7 +153,7 @@ PySharedPtrClass< smtk::mesh::Interface > pybind11_init_smtk_mesh_Interface(py::
.def("isModified", &smtk::mesh::Interface::isModified)
.def("mergeCoincidentContactPoints", &smtk::mesh::Interface::mergeCoincidentContactPoints, py::arg("meshes"), py::arg("tolerance"))
.def("meshForEach", &smtk::mesh::Interface::meshForEach, py::arg("meshes"), py::arg("filter"))
.def("name", &smtk::mesh::Interface::name)
.def("name", (std::string (smtk::mesh::Interface::*)() const) &smtk::mesh::Interface::name)
.def("numMeshes", &smtk::mesh::Interface::numMeshes, py::arg("handle"))
.def("pointDifference", &smtk::mesh::Interface::pointDifference, py::arg("a"), py::arg("b"), py::arg("bpc"), py::arg("containsFunctor"))
.def("pointForEach", &smtk::mesh::Interface::pointForEach, py::arg("points"), py::arg("filter"))
......
......@@ -69,6 +69,7 @@ PySharedPtrClass< smtk::mesh::MeshSet > pybind11_init_smtk_mesh_MeshSet(py::modu
.def("modelEntities", (bool (smtk::mesh::MeshSet::*)(smtk::model::EntityRefArray&)) &smtk::mesh::MeshSet::modelEntities, py::arg("arg0"))
.def("modelEntities", [](const smtk::mesh::MeshSet& ms){ smtk::model::EntityRefArray refs; ms.modelEntities(refs); return refs; })
.def("modelEntityIds", &smtk::mesh::MeshSet::modelEntityIds)
.def("name", &smtk::mesh::MeshSet::name)
.def("names", &smtk::mesh::MeshSet::names)
.def("neumanns", &smtk::mesh::MeshSet::neumanns)
.def("pointConnectivity", &smtk::mesh::MeshSet::pointConnectivity)
......@@ -80,6 +81,7 @@ PySharedPtrClass< smtk::mesh::MeshSet > pybind11_init_smtk_mesh_MeshSet(py::modu
.def("setDomain", &smtk::mesh::MeshSet::setDomain, py::arg("d"))
.def("setModelEntity", &smtk::mesh::MeshSet::setModelEntity, py::arg("arg0"))
.def("setModelEntityId", &smtk::mesh::MeshSet::setModelEntityId, py::arg("arg0"))
.def("setName", &smtk::mesh::MeshSet::setName)
.def("setNeumann", &smtk::mesh::MeshSet::setNeumann, py::arg("n"))
.def("size", &smtk::mesh::MeshSet::size)
.def("subset", (smtk::mesh::MeshSet (smtk::mesh::MeshSet::*)(::smtk::mesh::DimensionType) const) &smtk::mesh::MeshSet::subset, py::arg("dim"))
......
......@@ -414,6 +414,33 @@ void verify_meshset_visit(const smtk::mesh::CollectionPtr& c)
test(numMeshesIteratedOver == c->meshes().size());
}
void verify_meshset_set_names(const smtk::mesh::CollectionPtr& c)
{
std::size_t numMeshesIteratedOver = 0;
smtk::resource::Component::Visitor setMeshNames = [&](
const smtk::resource::ComponentPtr& component) {
auto meshComponent = std::dynamic_pointer_cast<smtk::mesh::Component>(component);
std::stringstream s;
s << "meshset " << numMeshesIteratedOver;
meshComponent->mesh().setName(s.str());
numMeshesIteratedOver++;
};
c->visit(setMeshNames);
numMeshesIteratedOver = 0;
smtk::resource::Component::Visitor checkMeshNames = [&](
const smtk::resource::ComponentPtr& component) {
auto meshComponent = std::dynamic_pointer_cast<smtk::mesh::Component>(component);
std::stringstream s;
s << "meshset " << numMeshesIteratedOver;
test(meshComponent->name() == s.str());
numMeshesIteratedOver++;
};
c->visit(checkMeshNames);
}
}
int UnitTestMeshSet(int, char** const)
......@@ -436,6 +463,7 @@ int UnitTestMeshSet(int, char** const)
verify_meshset_for_each(c);
verify_meshset_visit(c);
verify_meshset_set_names(c);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment