Commit cce49843 authored by T.J. Corona's avatar T.J. Corona
Browse files

Update mesh session to conform to updates in smtk::mesh

parent 02679683
......@@ -164,7 +164,7 @@ int TestElevateMeshOnStructuredGrid(int argc, char* argv[])
return 1;
}
smtk::mesh::CollectionPtr collection = resource->session()->topology(model)->m_collection;
smtk::mesh::CollectionPtr collection = resource->collection();
smtk::mesh::MeshSet mesh = collection->meshes();
// add auxiliary geometry
......
......@@ -77,7 +77,7 @@ class ElevateMeshOnStructuredGrid(smtk.testing.TestCase):
modelEntity.modelResource(), modelEntity.id())
# Access the mesh set from the collection that comprises the model
self.mesh = self.resource.collectionForModel(self.model).meshes()
self.mesh = self.resource.collection().meshes()
# Import auxiliary geometry describing the demographic data of the mesh
op = smtk.model.AddAuxiliaryGeometry.create()
......
......@@ -33,6 +33,11 @@ void Resource::setSession(const Session::Ptr& session)
m_session = session->shared_from_this();
this->registerSession(m_session);
}
const smtk::mesh::CollectionPtr& Resource::collection() const
{
return m_session->topology(shared_from_this())->m_collection;
}
}
}
}
......@@ -37,6 +37,8 @@ public:
const Session::Ptr& session() const { return m_session; }
void setSession(const Session::Ptr&);
const smtk::mesh::CollectionPtr& collection() const;
protected:
Resource(const smtk::common::UUID&, smtk::resource::Manager::Ptr manager = nullptr);
Resource(smtk::resource::Manager::Ptr manager = nullptr);
......
......@@ -10,6 +10,7 @@
//
//=============================================================================
#include "smtk/session/mesh/Session.h"
#include "smtk/session/mesh/Resource.h"
#include "smtk/model/Edge.h"
#include "smtk/model/Face.h"
......@@ -28,13 +29,21 @@ Session::Session()
{
}
Topology* Session::topology(smtk::model::Model& model)
Topology* Session::topology(const smtk::session::mesh::Resource::Ptr& modelResource)
{
std::vector<Topology>::iterator it = find_if(m_topologies.begin(), m_topologies.end(),
[&](const Topology& t) { return t.m_collection->entity() == model.entity(); });
std::vector<Topology>::iterator it =
find_if(m_topologies.begin(), m_topologies.end(), [&](const Topology& t) {
return modelResource->links().isLinkedTo(
t.m_collection, smtk::model::Resource::TessellationRole);
});
return (it == m_topologies.end() ? nullptr : &(*it));
}
Topology* Session::topology(const std::shared_ptr<const Resource>& modelResource)
{
return this->topology(std::const_pointer_cast<Resource>(modelResource));
}
smtk::model::SessionInfoBits Session::transcribeInternal(
const smtk::model::EntityRef& entityRef, SessionInfoBits requestedInfo, int depth)
{
......
......@@ -26,6 +26,8 @@ namespace session
namespace mesh
{
class Resource;
class SMTKMESHSESSION_EXPORT Session : public smtk::model::Session
{
public:
......@@ -38,7 +40,8 @@ public:
virtual ~Session() {}
void addTopology(Topology t) { m_topologies.push_back(t); }
Topology* topology(smtk::model::Model& model);
Topology* topology(const std::shared_ptr<Resource>& modelResource);
Topology* topology(const std::shared_ptr<const Resource>& modelResource);
std::string defaultFileExtension(const smtk::model::Model&) const override { return ""; }
......
......@@ -49,7 +49,7 @@ EulerCharacteristicRatio::Result EulerCharacteristicRatio::operateInternal()
smtk::session::mesh::Session::Ptr session = resource->session();
// Access the underlying mesh collection for the model.
smtk::mesh::CollectionPtr collection = resource->session()->topology(model)->m_collection;
smtk::mesh::CollectionPtr collection = resource->collection();
if (collection == nullptr || !collection->isValid())
{
smtkErrorMacro(this->log(), "No collection associated with this model.");
......
......@@ -66,7 +66,7 @@ smtk::session::mesh::Export::Result Export::operateInternal()
std::static_pointer_cast<smtk::session::mesh::Resource>(dataset.component()->resource());
smtk::session::mesh::Session::Ptr session = resource->session();
smtk::mesh::CollectionPtr collection = resource->session()->topology(dataset)->m_collection;
smtk::mesh::CollectionPtr collection = resource->collection();
if (collection == nullptr || !collection->isValid())
{
......
......@@ -138,6 +138,9 @@ Import::Result Import::operateInternal()
// Assign its model resource to the one associated with this session
collection->setModelResource(resource);
// Also assign the collection to be the model's tessellation
resource->setMeshTessellations(collection);
// Construct the topology
session->addTopology(Topology(collection, constructHierarchy));
......
......@@ -81,7 +81,7 @@ Write::Result Write::operateInternal()
smtk::model::Model model = models[0];
std::string meshFilename = resource->session()->topology(model)->m_collection->location();
std::string meshFilename = resource->collection()->location();
if (meshFilename.empty())
{
......
......@@ -25,9 +25,7 @@ PySharedPtrClass< smtk::session::mesh::Resource, smtk::model::Resource > pybind1
.def_static("create", (std::shared_ptr<smtk::session::mesh::Resource> (*)(::std::shared_ptr<smtk::session::mesh::Resource> &)) &smtk::session::mesh::Resource::create, py::arg("ref"))
.def("session", &smtk::session::mesh::Resource::session)
.def("setSession", &smtk::session::mesh::Resource::setSession)
.def("collectionForModel", [](const std::shared_ptr<smtk::session::mesh::Resource>& i, smtk::model::Model& model){
return i->session()->topology(model)->m_collection;
})
.def("collection", &smtk::session::mesh::Resource::collection)
.def_static("CastTo", [](const std::shared_ptr<smtk::resource::Resource> i) {
return std::dynamic_pointer_cast<smtk::session::mesh::Resource>(i);
})
......
......@@ -26,7 +26,8 @@ PySharedPtrClass< smtk::session::mesh::Session, smtk::model::Session > pybind11_
.def("addTopology", &smtk::session::mesh::Session::addTopology, py::arg("t"))
.def_static("create", (std::shared_ptr<smtk::session::mesh::Session> (*)()) &smtk::session::mesh::Session::create)
.def_static("create", (std::shared_ptr<smtk::session::mesh::Session> (*)(::std::shared_ptr<smtk::session::mesh::Session> &)) &smtk::session::mesh::Session::create, py::arg("ref"))
.def("topology", &smtk::session::mesh::Session::topology, py::arg("model"))
.def("topology", (smtk::session::mesh::Topology* (smtk::session::mesh::Session::*)(const std::shared_ptr<::smtk::session::mesh::Resource>&)) &smtk::session::mesh::Session::topology, py::return_value_policy::reference)
.def("topology", (smtk::session::mesh::Topology* (smtk::session::mesh::Session::*)(const std::shared_ptr<const ::smtk::session::mesh::Resource>&)) &smtk::session::mesh::Session::topology, py::return_value_policy::reference)
;
return instance;
}
......
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