Commit d5b25273 authored by T.J. Corona's avatar T.J. Corona

Adapt smtk::mesh to use resources.

parent 15d5a40b
......@@ -224,6 +224,8 @@ public:
bool isAboutToBeDeleted() const { return this->m_aboutToBeDeleted; }
common::UUID id() const override { return m_id; }
protected:
Attribute(const std::string& myName, smtk::attribute::DefinitionPtr myDefinition,
const smtk::common::UUID& myId);
......@@ -248,6 +250,8 @@ protected:
this->m_references.erase(attRefItem);
}
void setId(const common::UUID& myID) override { m_id = myID; }
std::string m_name;
std::vector<smtk::attribute::ItemPtr> m_items;
ModelEntityItemPtr m_associations;
......@@ -262,6 +266,7 @@ protected:
// would need to be done otherwise
bool m_aboutToBeDeleted;
double m_color[4];
smtk::common::UUID m_id;
};
inline smtk::simulation::UserDataPtr Attribute::userData(const std::string& key) const
......
......@@ -1097,6 +1097,10 @@ public:
//write out the boundary conditions of this meshset
writeBoundaryConditions(parent, mesh);
//list out the model associations that this mesheset contains
smtk::common::UUID id = mesh.id();
cJSON_AddItemToObject(parent, "id", cJSON_CreateString(id.toString().c_str()));
//list out the model associations that this mesheset contains
smtk::common::UUIDArray modelEntityIds = mesh.modelEntityIds();
writeUUIDValues(parent, modelEntityIds, std::string("modelEntityIds"));
......
......@@ -10,6 +10,7 @@ set(meshSrcs
ForEachTypes.cxx
Handle.cxx
Manager.cxx
MeshComponent.cxx
MeshSet.cxx
Metrics.cxx
PointConnectivity.cxx
......@@ -62,6 +63,7 @@ set(meshHeaders
Handle.h
Interface.h
Manager.h
MeshComponent.h
MeshSet.h
Metrics.h
PointConnectivity.h
......
......@@ -10,6 +10,7 @@
#include "smtk/mesh/Collection.h"
#include "smtk/mesh/Manager.h"
#include "smtk/mesh/MeshComponent.h"
#include "smtk/mesh/moab/Interface.h"
......@@ -109,6 +110,18 @@ Collection::~Collection()
}
}
smtk::resource::ComponentPtr Collection::find(const smtk::common::UUID& compId) const
{
const smtk::mesh::InterfacePtr& iface = this->m_internals->mesh_iface();
smtk::mesh::moab::Handle handle;
if (iface->findById(this->m_internals->mesh_root_handle(), compId, handle))
{
return smtk::mesh::MeshComponent::create(this->shared_from_this(), handle);
}
return smtk::resource::ComponentPtr();
}
const smtk::mesh::InterfacePtr& Collection::interface() const
{
return this->m_internals->mesh_iface();
......@@ -503,7 +516,8 @@ smtk::common::UUID Collection::associatedModel() const
return iface->rootAssociation();
}
smtk::mesh::MeshSet Collection::createMesh(const smtk::mesh::CellSet& cells)
smtk::mesh::MeshSet Collection::createMesh(
const smtk::mesh::CellSet& cells, const smtk::common::UUID& uuid)
{
const smtk::mesh::InterfacePtr& iface = this->m_internals->mesh_iface();
......@@ -515,6 +529,14 @@ smtk::mesh::MeshSet Collection::createMesh(const smtk::mesh::CellSet& cells)
if (meshCreated)
{
entities.insert(meshSetHandle);
if (uuid)
{
iface->setId(meshCreated, uuid);
}
else
{
iface->setId(meshCreated, smtk::common::UUIDGenerator::instance().random());
}
}
}
return smtk::mesh::MeshSet(
......
......@@ -31,6 +31,8 @@
#include "smtk/model/Manager.h"
#include "smtk/model/Model.h"
#include "smtk/resource/Resource.h"
#include <vector>
namespace smtk
......@@ -54,7 +56,7 @@ namespace mesh
//Flyweight interface around a moab database of meshes. When constructed
//becomes registered with a manager with a weak relationship.
class SMTKCORE_EXPORT Collection : public smtk::enable_shared_from_this<Collection>
class SMTKCORE_EXPORT Collection : public smtk::resource::Resource
{
//default constructor generates an invalid collection
Collection();
......@@ -70,12 +72,14 @@ class SMTKCORE_EXPORT Collection : public smtk::enable_shared_from_this<Collecti
smtk::mesh::ManagerPtr mngr);
public:
smtkTypeMacroBase(Collection);
//construct an invalid collection
smtkCreateMacro(Collection);
smtkTypeMacro(smtk::mesh::Collection);
smtkSharedPtrCreateMacro(smtk::resource::Resource);
~Collection();
resource::Resource::Type type() const override { return resource::Resource::MESH; }
resource::ComponentPtr find(const common::UUID& compId) const override;
//determine if the given Collection is valid and is properly associated
//to a manager.
bool isValid() const;
......@@ -220,7 +224,8 @@ public:
//we will return an empty MeshSet.
//Asking to create a MeshSet from a CellSet that is empty will fail, and
//we will return an empty MeshSet.
smtk::mesh::MeshSet createMesh(const smtk::mesh::CellSet& cells);
smtk::mesh::MeshSet createMesh(
const smtk::mesh::CellSet& cells, const smtk::common::UUID& uuid = smtk::common::UUID::null());
// Deletion of Items
//given a collection of meshes this will delete all meshes and any cell or vert
......
......@@ -404,6 +404,13 @@ public:
virtual bool setNeumann(
const smtk::mesh::HandleRange& meshsets, const smtk::mesh::Neumann& neumann) const = 0;
virtual bool setId(const smtk::mesh::Handle& meshset, const smtk::common::UUID& id) const = 0;
virtual smtk::common::UUID getId(const smtk::mesh::Handle& meshset) const = 0;
virtual bool findById(const smtk::mesh::Handle& root, const smtk::common::UUID& id,
smtk::mesh::Handle& meshset) const = 0;
// Specify for a given sets of handles what the associated model entity is.
// This allows for a model region, face, or edge to be associated with a
// given set of meshes.
......
//=========================================================================
// 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/MeshComponent.h"
#include "smtk/mesh/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(id)
, m_meshset(meshset)
{
}
const smtk::resource::ResourcePtr MeshComponent::resource() const
{
return std::dynamic_pointer_cast<smtk::resource::Resource>(this->m_meshset.collection());
}
/**\brief Return an array of model entity UUIDs associated with meshset members.
*
*/
smtk::common::UUIDArray MeshComponent::modelEntityIds() const
{
if (!this->m_meshset.collection())
{
return smtk::common::UUIDArray();
}
const smtk::mesh::InterfacePtr& iface = this->m_meshset.collection()->interface();
return iface->computeModelEntities(this->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 manager set to a valid value or the result will
* be an array of invalid entries.
*/
bool MeshComponent::modelEntities(smtk::model::EntityRefArray& array) const
{
if (!this->m_meshset.collection())
{
return false;
}
smtk::model::ManagerPtr mgr = this->m_meshset.collection()->modelManager();
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(mgr, *it));
}
return (mgr != nullptr);
}
/**\brief Set the model entity for each meshset member to \a ent.
*
*/
bool MeshComponent::setModelEntity(const smtk::model::EntityRef& ent)
{
if (!this->m_meshset.collection())
{
return false;
}
const smtk::mesh::InterfacePtr& iface = this->m_meshset.collection()->interface();
return iface->setAssociation(ent.entity(), this->m_meshset.range());
}
/**\brief Set the model entity for each meshset member to \a ent.
*
*/
bool MeshComponent::setModelEntityId(const smtk::common::UUID& id)
{
if (!this->m_meshset.collection())
{
return false;
}
const smtk::mesh::InterfacePtr& iface = this->m_meshset.collection()->interface();
return iface->setAssociation(id, this->m_meshset.range());
}
}
}
//=========================================================================
// 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/MeshSet.h"
namespace smtk
{
namespace mesh
{
class MeshComponent;
typedef std::vector<smtk::mesh::MeshComponent> MeshComponentList;
typedef std::set<smtk::mesh::MeshComponent> 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 <typename... T>
MeshComponent(T&&... all)
: MeshComponent(MeshSet(std::forward<T>(all)...))
{
}
template <typename... T>
MeshComponent(const smtk::common::UUID& id, T&&... all)
: MeshComponent(id, MeshSet(std::forward<T>(all)...))
{
}
public:
typedef smtk::shared_ptr<MeshComponent> MeshComponentPtr;
smtkTypeMacro(MeshComponent);
smtkSharedPtrCreateMacro(smtk::resource::Component);
// Expose all constructors as static create methods
template <typename... T>
static MeshComponentPtr create(T&&... all)
{
return MeshComponentPtr(new MeshComponent(std::forward<T>(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&);
smtk::common::UUID id() const override { return this->m_meshset.id(); }
smtk::mesh::MeshSet meshes() const { return this->m_meshset; }
protected:
void setId(const smtk::common::UUID& id) override { this->m_meshset.setId(id); }
private:
smtk::mesh::MeshSet m_meshset;
};
} // namespace mesh
} // namespace smtk
#endif
......@@ -222,6 +222,24 @@ bool MeshSet::setNeumann(const smtk::mesh::Neumann& n)
return iface->setNeumann(this->m_range, n);
}
/**\brief Return the meshset's UUID.
*
*/
smtk::common::UUID MeshSet::id() const
{
const smtk::mesh::InterfacePtr& iface = this->m_parent->interface();
return iface->getId(this->m_handle);
}
/**\brief Set the meshset's UUID.
*
*/
void MeshSet::setId(const smtk::common::UUID& id)
{
const smtk::mesh::InterfacePtr& iface = this->m_parent->interface();
iface->setId(this->m_handle, id);
}
/**\brief Return an array of model entity UUIDs associated with meshset members.
*
*/
......
......@@ -103,6 +103,8 @@ public:
bool setDirichlet(const smtk::mesh::Dirichlet& d);
bool setNeumann(const smtk::mesh::Neumann& n);
smtk::common::UUID id() const;
void setId(const smtk::common::UUID&);
smtk::common::UUIDArray modelEntityIds() const;
//append the passed EntityRefArray with the model entities associated with
......
......@@ -130,6 +130,15 @@ public:
}
};
class SMTKCORE_EXPORT Id : public UUIDTag
{
public:
explicit Id(const smtk::common::UUID& value)
: UUIDTag(value)
{
}
};
class SMTKCORE_EXPORT Model : public UUIDTag
{
public:
......
......@@ -482,6 +482,41 @@ bool Interface::setNeumann(const smtk::mesh::HandleRange&, const smtk::mesh::Neu
return false;
}
bool Interface::setId(const smtk::mesh::Handle&, const smtk::common::UUID&) const
{
return false;
}
smtk::common::UUID Interface::getId(const smtk::mesh::Handle& meshset) const
{
smtk::mesh::HandleRange meshes;
MeshInfoVecType::const_iterator i;
for (i = this->m_meshInfo.begin(); i != this->m_meshInfo.end(); ++i)
{
if (i->mesh() == meshset)
{
return i->id();
}
}
return smtk::common::UUID::null();
}
bool Interface::findById(
const smtk::mesh::Handle&, const smtk::common::UUID& id, smtk::mesh::Handle& meshset) const
{
smtk::mesh::HandleRange meshes;
MeshInfoVecType::const_iterator i;
for (i = this->m_meshInfo.begin(); i != this->m_meshInfo.end(); ++i)
{
if (i->id() == id)
{
meshset = i->mesh();
return true;
}
}
return false;
}
/**\brief Set the model entity assigned to each meshset member to \a ent.
*/
bool Interface::setAssociation(const smtk::common::UUID&, const smtk::mesh::HandleRange&) const
......
......@@ -216,6 +216,13 @@ public:
bool setNeumann(
const smtk::mesh::HandleRange& meshsets, const smtk::mesh::Neumann& neumann) const override;
bool setId(const smtk::mesh::Handle& meshset, const smtk::common::UUID& id) const override;
smtk::common::UUID getId(const smtk::mesh::Handle& meshset) const override;
bool findById(const smtk::mesh::Handle& root, const smtk::common::UUID& id,
smtk::mesh::Handle& meshset) const override;
bool setAssociation(
const smtk::common::UUID& modelUUID, const smtk::mesh::HandleRange& meshsets) const override;
......
......@@ -22,6 +22,7 @@ namespace json
MeshInfo::MeshInfo()
: m_mesh()
, m_uuid()
, m_cells()
, m_points()
, m_types()
......@@ -32,9 +33,11 @@ MeshInfo::MeshInfo()
{
}
MeshInfo::MeshInfo(smtk::mesh::Handle meshId, const smtk::mesh::HandleRange& cells,
const smtk::mesh::HandleRange& points, smtk::mesh::TypeSet types)
MeshInfo::MeshInfo(smtk::mesh::Handle meshId, const smtk::common::UUID& uuid,
const smtk::mesh::HandleRange& cells, const smtk::mesh::HandleRange& points,
smtk::mesh::TypeSet types)
: m_mesh(meshId)
, m_uuid(uuid)
, m_cells(cells)
, m_points(points)
, m_types(types)
......
......@@ -32,8 +32,9 @@ class SMTKCORE_EXPORT MeshInfo
public:
MeshInfo();
MeshInfo(smtk::mesh::Handle meshId, const smtk::mesh::HandleRange& cells,
const smtk::mesh::HandleRange& points, smtk::mesh::TypeSet types);
MeshInfo(smtk::mesh::Handle meshId, const smtk::common::UUID& uuid,
const smtk::mesh::HandleRange& cells, const smtk::mesh::HandleRange& points,
smtk::mesh::TypeSet types);
smtk::mesh::Handle mesh() const { return this->m_mesh; }
......@@ -54,6 +55,7 @@ public:
const std::vector<smtk::mesh::Dirichlet>& dirichlets() const { return this->m_dirichlets; }
const std::vector<smtk::mesh::Neumann>& neumanns() const { return this->m_neumanns; }
const smtk::common::UUIDArray& modelUUIDS() const { return this->m_uuids; }
const smtk::common::UUID& id() const { return this->m_uuid; }
void set(const std::vector<smtk::mesh::Domain>& ds) { this->m_domains = ds; }
void set(const std::vector<smtk::mesh::Dirichlet>& bcs) { this->m_dirichlets = bcs; }
......@@ -64,6 +66,7 @@ public:
private:
smtk::mesh::Handle m_mesh;
smtk::common::UUID m_uuid;
smtk::mesh::HandleRange m_cells;
smtk::mesh::HandleRange m_points;
smtk::mesh::TypeSet m_types;
......
......@@ -91,6 +91,14 @@ bool parse_meshInfo(cJSON* info, std::vector<smtk::mesh::json::MeshInfo>& result
smtk::mesh::HandleRange cells = smtk::mesh::from_json(cJSON_GetObjectItem(child, "cells"));
smtk::mesh::HandleRange points = smtk::mesh::from_json(cJSON_GetObjectItem(child, "points"));
//get the uuid of the mesh
smtk::common::UUID id = smtk::common::UUID::null();
cJSON* uidRec = cJSON_GetObjectItem(child, "id");
if (uidRec && uidRec->type == cJSON_String && uidRec->valuestring && uidRec->valuestring[0])
{
id = smtk::common::UUID(uidRec->valuestring);
}
//get any model entity ids that are associated to this mesh
smtk::common::UUIDArray modelEnts;
{
......@@ -147,7 +155,7 @@ bool parse_meshInfo(cJSON* info, std::vector<smtk::mesh::json::MeshInfo>& result
const bool valid = (!cells.empty() && !points.empty());
if (valid)
{
smtk::mesh::json::MeshInfo minfo(meshIds[meshIdIdx], cells, points, types);
smtk::mesh::json::MeshInfo minfo(meshIds[meshIdIdx], id, cells, points, types);
//specify the optional parts of the mesh info
if (!modelEnts.empty())
{
......
......@@ -947,6 +947,61 @@ bool Interface::setNeumann(
return tagged;
}
/**\brief Set the id for a meshset to \a id.
*/
bool Interface::setId(const smtk::mesh::Handle& meshset, const smtk::common::UUID& id) const
{
if (!id)
{
return false;
}
tag::QueryIdTag mtag(id, this->moabInterface());
//Tag the meshsets
bool tagged = detail::setDenseOpaqueTagValue(mtag, meshset, this->moabInterface());
if (tagged)
{
this->m_modified = true;
}
return tagged;
}
/**\brief Get the id for a meshset.
*/
smtk::common::UUID Interface::getId(const smtk::mesh::Handle& meshset) const
{
tag::QueryIdTag mtag(this->moabInterface());
return detail::computeDenseOpaqueTagValue<smtk::common::UUID>(
mtag, meshset, this->moabInterface());
}
/**\brief Find a mesh entity using its id.
*
*/
bool Interface::findById(
const smtk::mesh::Handle& root, const smtk::common::UUID& id, smtk::mesh::Handle& meshset) const
{
if (!id)
{
return false;
}
smtk::mesh::HandleRange result;
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)
{
return false;
}
meshset = *result.begin();
return true;
}
/**\brief Set the model entity assigned to each meshset member to \a ent.
*/
bool Interface::setAssociation(
......
......@@ -225,6 +225,13 @@ public:
bool setNeumann(
const smtk::mesh::HandleRange& meshsets, const smtk::mesh::Neumann& neumann) const override;
bool setId(const smtk::mesh::Handle& meshset, const smtk::common::UUID& id) const override;
smtk::common::UUID getId(const smtk::mesh::Handle& meshset) const override;
bool findById(const smtk::mesh::Handle& root, const smtk::common::UUID& id,
smtk::mesh::Handle& meshset) const override;
bool setAssociation(
const smtk::common::UUID& modelUUID, const smtk::mesh::HandleRange& range) const override;
......
......@@ -179,6 +179,24 @@ public:
const char* value() const { return this->m_value; }
};
class QueryIdTag : public QueryOpaqueTag<smtk::common::UUID::SIZE>
{
public:
QueryIdTag(::moab::Interface* iface)
: QueryOpaqueTag("ID", reinterpret_cast<const char*>(smtk::common::UUID::null().begin()), iface)
{
}
QueryIdTag(const smtk::common::UUID& v, ::moab::Interface* iface)
: QueryOpaqueTag("ID", reinterpret_cast<const char*>(v.begin()), iface)
{
}
smtk::common::UUID uuid() const
{
return smtk::common::UUID(reinterpret_cast<const unsigned char*>(this->value()),
reinterpret_cast<const unsigned char*>(this->value()) + smtk::common::UUID::SIZE);
}
};
class QueryEntRefTag : public QueryOpaqueTag<smtk::common::UUID::SIZE>
{
public:
......
......@@ -15,6 +15,8 @@
#include "smtk/mesh/Collection.h"
#include "smtk/common/UUID.h"
#include "smtk/mesh/Manager.h"
#include "smtk/model/EntityIterator.h"
......@@ -36,7 +38,7 @@ PySharedPtrClass< smtk::mesh::Collection > pybind11_init_smtk_mesh_Collection(py
.def("clearReadWriteLocations", &smtk::mesh::Collection::clearReadWriteLocations)
.def_static("create", (std::shared_ptr<smtk::mesh::Collection> (*)()) &smtk::mesh::Collection::create)
.def_static("create", (std::shared_ptr<smtk::mesh::Collection> (*)(::std::shared_ptr<smtk::mesh::Collection> &)) &smtk::mesh::Collection::create, py::arg("ref"))
.def("createMesh", &smtk::mesh::Collection::createMesh, py::arg("cells"))
.def("createMesh", &smtk::mesh::Collection::createMesh, py::arg("cells"), py::arg("uuid") = smtk::common::UUID::null())
.def("dirichletMeshes", &smtk::mesh::Collection::dirichletMeshes, py::arg("d"))
.def("dirichlets", &smtk::mesh::Collection::dirichlets)
.def("domainMeshes", &smtk::mesh::Collection::domainMeshes, py::arg("m"))
......
......@@ -45,6 +45,8 @@ namespace model
*/
class SMTKCORE_EXPORT Entity : public smtk::resource::Component
{
friend class smtk::model::Manager;
public:
using UUID = smtk::common::UUID;
using ResourcePtr = smtk::resource::ResourcePtr;
......@@ -125,15 +127,19 @@ public:
const KindsToArrangements& arrangementMap() const { return this->m_arrangements; }
common::UUID id() const override { return m_id; }
protected:
Entity();
int consumeInvalidIndex(const smtk::common::UUID& uid);
void setId(const common::UUID& myID) override { m_id = myID; }
BitFlags m_entityFlags;
smtk::common::UUIDArray m_relations;
smtk::model::WeakManagerPtr m_resource;
KindsToArrangements m_arrangements;
int m_firstInvalid;
smtk::common::UUID m_id;
};
/// An abbreviation for the record type used by maps of Entity records.
......
......@@ -33,19 +33,18 @@ namespace resource
class SMTKCORE_EXPORT Component : smtkEnableSharedPtr(Component)
{
friend class Resource;
friend class smtk::model::Manager;
public:
smtkTypeMacroBase(Component);
virtual ~Component();
virtual const ResourcePtr resource() const = 0;
const common::UUID& id() const { return this->m_id; }
virtual common::UUID id() const = 0;
protected:
Component(const common::UUID& myID);
Component();
void setId(const common::UUID& myID) { this->m_id = myID; }
virtual void setId(const common::UUID& myID) = 0;
private:
common::UUID m_id;
......
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