Commit 2755d8e1 authored by T.J. Corona's avatar T.J. Corona

Mesh session: associate mesh collections with model resources.

parent 843ad0e2
......@@ -34,9 +34,10 @@ void Resource::setSession(const Session::Ptr& session)
this->registerSession(m_session);
}
const smtk::mesh::CollectionPtr& Resource::collection() const
smtk::mesh::CollectionPtr Resource::collection() const
{
return m_session->topology(shared_from_this())->m_collection;
Topology* topology = m_session->topology(shared_from_this());
return (topology != nullptr ? topology->m_collection : smtk::mesh::CollectionPtr());
}
}
}
......
......@@ -37,7 +37,7 @@ public:
const Session::Ptr& session() const { return m_session; }
void setSession(const Session::Ptr&);
const smtk::mesh::CollectionPtr& collection() const;
smtk::mesh::CollectionPtr collection() const;
protected:
Resource(const smtk::common::UUID&, smtk::resource::Manager::Ptr manager = nullptr);
......
......@@ -54,7 +54,7 @@ smtk::model::SessionInfoBits Session::transcribeInternal(
const smtk::session::mesh::Topology* topology = nullptr;
for (const Topology& top : m_topologies)
{
if (entityRef.entity() == top.m_collection->entity())
if (entityRef.entity() == top.m_modelId)
{
// The entity is the model associated with this topology
topology = ⊤
......@@ -85,7 +85,7 @@ smtk::model::SessionInfoBits Session::transcribeInternal(
{
// Check if the entityRef is for the model. If it is, then its UUID will be
// identical to that of the collection that represents the model.
if (mutableEntityRef.entity() == topology->m_collection->entity())
if (mutableEntityRef.entity() == topology->m_modelId)
{
// We have a model. We insert the model using the resource API. It takes
// the UUID of the model, its parametric dimension and its embedded
......
......@@ -216,13 +216,13 @@ struct AddBoundElements
};
}
Topology::Topology(smtk::mesh::CollectionPtr collection, bool constructHierarchy)
: m_collection(collection)
Topology::Topology(
const smtk::common::UUID& modelId, const smtk::mesh::MeshSet& meshset, bool constructHierarchy)
: m_collection(meshset.collection())
, m_modelId(modelId)
{
// Insert the collection as the top-level element representing the model
Element* model =
&(m_elements.insert(std::make_pair(collection->entity(), Element(collection->meshes())))
.first->second);
Element* model = &(m_elements.insert(std::make_pair(modelId, Element(meshset))).first->second);
if (constructHierarchy)
{
......@@ -238,7 +238,7 @@ Topology::Topology(smtk::mesh::CollectionPtr collection, bool constructHierarchy
// all meshes of the highest dimension are considered to be free elements with
// the model as their parent
int dimension = smtk::mesh::DimensionType_MAX - 1;
smtk::mesh::TypeSet types = collection->types();
smtk::mesh::TypeSet types = meshset.types();
while (dimension >= 0 && !types.hasDimension(static_cast<smtk::mesh::DimensionType>(dimension)))
{
--dimension;
......@@ -246,7 +246,7 @@ Topology::Topology(smtk::mesh::CollectionPtr collection, bool constructHierarchy
if (dimension < 0)
{
// We have been passed an empty collection.
// We have been passed an empty meshset
return;
}
......@@ -254,7 +254,7 @@ Topology::Topology(smtk::mesh::CollectionPtr collection, bool constructHierarchy
addFreeElements.setElementShells(elementShells[dimension]);
addFreeElements.setDimension(dimension);
smtk::mesh::for_each(
collection->meshes(static_cast<smtk::mesh::DimensionType>(dimension)), addFreeElements);
meshset.subset(static_cast<smtk::mesh::DimensionType>(dimension)), addFreeElements);
}
AddBoundElements addBoundElements(this);
......@@ -265,7 +265,7 @@ Topology::Topology(smtk::mesh::CollectionPtr collection, bool constructHierarchy
addFreeElements.setDimension(dimension);
smtk::mesh::MeshSet allMeshes =
collection->meshes(static_cast<smtk::mesh::DimensionType>(dimension));
meshset.subset(static_cast<smtk::mesh::DimensionType>(dimension));
smtk::mesh::MeshSet boundMeshes;
for (auto&& shell : *elementShells[dimension + 1])
......@@ -293,7 +293,7 @@ Topology::Topology(smtk::mesh::CollectionPtr collection, bool constructHierarchy
{
addFreeElements.setDimension(dimension);
smtk::mesh::for_each(
collection->meshes(static_cast<smtk::mesh::DimensionType>(dimension)), addFreeElements);
meshset.subset(static_cast<smtk::mesh::DimensionType>(dimension)), addFreeElements);
}
}
......
......@@ -36,7 +36,8 @@ namespace mesh
*/
struct SMTKMESHSESSION_EXPORT Topology
{
Topology(smtk::mesh::CollectionPtr collection, bool constructHierarchy = true);
Topology(const smtk::common::UUID& modelId, const smtk::mesh::MeshSet& meshset,
bool constructHierarchy = true);
struct Element
{
......@@ -52,6 +53,7 @@ struct SMTKMESHSESSION_EXPORT Topology
};
smtk::mesh::CollectionPtr m_collection;
smtk::common::UUID m_modelId;
std::map<smtk::common::UUID, Element> m_elements;
};
}
......
......@@ -151,12 +151,11 @@ CreateUniformGrid::Result CreateUniformGrid::operateInternal()
// session.
collection->setModelResource(resource);
// Construct the topology.
session->addTopology(smtk::session::mesh::Topology(collection, false));
// Create a model with the appropriate dimension
smtk::model::Model model = resource->addModel(3, 3);
// Our collections will already have a UUID, so here we create a model given
// the model resource and uuid.
smtk::model::Model model = resource->insertModel(collection->entity(), 3, 3);
// Construct the topology.
session->addTopology(smtk::session::mesh::Topology(model.entity(), collection->meshes(), false));
// Declare the model as "dangling" so it will be transcribed.
session->declareDanglingEntity(model);
......
......@@ -70,6 +70,7 @@ Import::Result Import::operateInternal()
smtk::session::mesh::Resource::Ptr resource = nullptr;
smtk::session::mesh::Session::Ptr session = nullptr;
smtk::mesh::Collection::Ptr collection = nullptr;
// Modes 2 and 3 requre an existing resource for input
smtk::attribute::ResourceItem::Ptr existingResourceItem =
......@@ -84,17 +85,27 @@ Import::Result Import::operateInternal()
smtk::attribute::StringItem::Ptr sessionOnlyItem =
this->parameters()->findString("session only");
if (sessionOnlyItem->value() == "this file")
if (sessionOnlyItem->value() == "import into this file")
{
// If the "session only" value is set to "this file", then we use the
// existing resource
resource = existingResource;
collection = existingResource->collection();
// It is possible that a mesh session resource does not have a valid
// collection (for example, when it is newly created). In this case, we
// need a new collection instead.
if (collection == nullptr)
{
collection = smtk::mesh::Collection::create();
}
}
else
{
// If the "session only" value is set to "this session", then we create a
// new resource with the session from the exisiting resource
resource = smtk::session::mesh::Resource::create();
collection = smtk::mesh::Collection::create();
resource->setSession(session);
}
}
......@@ -104,6 +115,7 @@ Import::Result Import::operateInternal()
// resource.
resource = smtk::session::mesh::Resource::create();
session = smtk::session::mesh::Session::create();
collection = smtk::mesh::Collection::create();
// Create a new resource for the import
resource->setLocation(filePath);
......@@ -111,8 +123,10 @@ Import::Result Import::operateInternal()
}
// Get the collection from the file
smtk::mesh::CollectionPtr collection = smtk::mesh::Collection::create();
smtk::mesh::MeshSet preexistingMeshes = collection->meshes();
smtk::io::importMesh(filePath, collection, label);
smtk::mesh::MeshSet allMeshes = collection->meshes();
smtk::mesh::MeshSet newMeshes = smtk::mesh::set_difference(allMeshes, preexistingMeshes);
if (!collection || !collection->isValid())
{
......@@ -141,15 +155,14 @@ Import::Result Import::operateInternal()
// Also assign the collection to be the model's tessellation
resource->setMeshTessellations(collection);
// Construct the topology
session->addTopology(Topology(collection, constructHierarchy));
// Determine the model's dimension
int dimension = int(smtk::mesh::utility::highestDimension(collection->meshes()));
// Our collections will already have a UUID, so here we create a model given
// the model resource and uuid
smtk::model::Model model = resource->insertModel(collection->entity(), dimension, dimension);
// Create a model with the appropriate dimension
smtk::model::Model model = resource->addModel(dimension, dimension);
// Construct the topology
session->addTopology(Topology(model.entity(), newMeshes, constructHierarchy));
// Name the model according to the stem of the file
if (!name.empty())
......@@ -207,10 +220,20 @@ Import::Specification Import::createSpecification()
std::stringstream fileFilters;
for (auto& ioType : smtk::io::ImportMesh::SupportedIOTypes())
{
bool firstFormat = true;
for (auto& format : ioType->FileFormats())
{
if (format.CanImport())
{
if (firstFormat)
{
firstFormat = false;
}
else
{
fileFilters << ";;";
}
fileFilters << format.Name << "(";
bool first = true;
for (auto& ext : format.Extensions)
......@@ -225,7 +248,7 @@ Import::Specification Import::createSpecification()
}
fileFilters << "*" << ext;
}
fileFilters << ");;";
fileFilters << ")";
}
}
}
......
......@@ -28,7 +28,7 @@
<String Name="session only" Label="session" Advanced="1">
<DiscreteInfo DefaultIndex="0">
<Structure>
<Value Enum="this file">import into this file </Value>
<Value Enum="this file">import into this file</Value>
</Structure>
<Structure>
<Value Enum="this session">import into a new file using this file's session</Value>
......
......@@ -21,7 +21,6 @@ py::class_< smtk::session::mesh::Topology > pybind11_init_smtk_session_mesh_Topo
{
py::class_< smtk::session::mesh::Topology > instance(m, "Topology");
instance
.def(py::init<::smtk::mesh::CollectionPtr>())
.def(py::init<::smtk::session::mesh::Topology const &>())
.def("deepcopy", (smtk::session::mesh::Topology & (smtk::session::mesh::Topology::*)(::smtk::session::mesh::Topology const &)) &smtk::session::mesh::Topology::operator=)
.def("collection", [](const smtk::session::mesh::Topology& topology){ return topology.m_collection; })
......
......@@ -215,9 +215,9 @@ int UnitTestTopology(int argc, char* argv[])
std::cout << count[2] << " faces" << std::endl;
test(count[2] == 9, "There should be nine faces");
std::cout << count[1] << " edges" << std::endl;
test(count[1] == 7, "There should be seven lines");
test(count[1] == 6, "There should be six lines");
std::cout << count[0] << " vertex groups" << std::endl;
test(count[0] == 1, "There should be one vertex group");
test(count[0] == 0, "There should be no vertex groups");
bool debug = false;
if (debug)
......
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