Commit 68b231c8 authored by Yumin Yuan's avatar Yumin Yuan

Merge pull request #244 from yumin/refactor-discrete-session-variables

Refactor static variables related to discrete Session
parents 1247c19f e020148a
......@@ -81,13 +81,6 @@ enum smtkCellTessRole {
SMTK_ROLE_POLYS
};
/// Track which models are tracked by which sessions.
std::map<vtkDiscreteModel*,Session::WeakPtr> Session::s_modelsToSessions;
/// Associate UUIDs to vtkDiscreteModelWrapper instances.
std::map<smtk::common::UUID,vtkSmartPointer<vtkDiscreteModelWrapper> > Session::s_modelIdsToRefs;
/// Associate vtkDiscreteModelWrapper instances to UUIDs.
std::map<vtkSmartPointer<vtkDiscreteModelWrapper>, smtk::common::UUID> Session::s_modelRefsToIds;
// Local helper to uniquely determine an integer "sense" for pairs of edge uses of an edge.
// FIXME: This really should assign the integer so that the pairs form a single cycle.
// For example, consider edge uses a, b, c, d, e, f, g, h that are paired
......@@ -172,15 +165,15 @@ Session::~Session()
}
// Remove any models that this session owned from s_modelsToSessions.
std::map<vtkDiscreteModel*,Session::WeakPtr>::iterator mbit;
for (mbit = Session::s_modelsToSessions.begin(); mbit != Session::s_modelsToSessions.end(); )
for (mbit = this->m_modelsToSessions.begin(); mbit != this->m_modelsToSessions.end(); )
{
if (mbit->second.lock().get() == this)
{
smtk::common::UUID modelId = this->findOrSetEntityUUID(mbit->first);
Session::s_modelsToSessions.erase(mbit++);
vtkSmartPointer<vtkDiscreteModelWrapper> modelPtr = Session::s_modelIdsToRefs[modelId];
Session::s_modelIdsToRefs.erase(modelId);
Session::s_modelRefsToIds.erase(modelPtr);
this->m_modelsToSessions.erase(mbit++);
vtkSmartPointer<vtkDiscreteModelWrapper> modelPtr = this->m_modelIdsToRefs[modelId];
this->m_modelIdsToRefs.erase(modelId);
this->m_modelRefsToIds.erase(modelPtr);
}
else
{
......@@ -263,8 +256,8 @@ vtkUnsignedIntArray* Session::retrieveUUIDs(
vtkDiscreteModel* model, const std::vector<vtkModelItem*>& ents)
{
std::map<vtkDiscreteModel*,WeakPtr>::iterator sessionIt =
Session::s_modelsToSessions.find(model);
if (sessionIt == Session::s_modelsToSessions.end())
this->m_modelsToSessions.find(model);
if (sessionIt == this->m_modelsToSessions.end())
return NULL;
Ptr session = sessionIt->second.lock();
if (!session)
......@@ -322,7 +315,7 @@ int Session::ExportEntitiesToFileOfNameAndType(
if (nfiles > 1)
fname << "_" << i;
wri->SetFileName(fname.str().c_str());
wri->Write(*mit);
wri->Write(*mit, this);
std::cout << "Wrote " << fname.str() << "\n";
}
......@@ -332,7 +325,7 @@ int Session::ExportEntitiesToFileOfNameAndType(
vtkDiscreteModelWrapper* Session::findModelEntity(const smtk::common::UUID& uid) const
{
std::map<smtk::common::UUID,vtkSmartPointer<vtkDiscreteModelWrapper> >::const_iterator it;
if ((it = Session::s_modelIdsToRefs.find(uid)) != Session::s_modelIdsToRefs.end())
if ((it = this->m_modelIdsToRefs.find(uid)) != this->m_modelIdsToRefs.end())
return it->second.GetPointer();
return NULL;
}
......@@ -1077,10 +1070,10 @@ smtk::common::UUID Session::trackModel(
smtk::common::UUID mid = this->findOrSetEntityUUID(dmod);
// Track the model (keep a strong reference to it)
// by UUID as well as the inverse map for quick reference:
Session::s_modelIdsToRefs[mid] = mod;
Session::s_modelRefsToIds[mod] = mid;
this->m_modelIdsToRefs[mid] = mod;
this->m_modelRefsToIds[mod] = mid;
this->m_itemsToRefs[mid] = dmod;
Session::s_modelsToSessions[dmod] = shared_from_this();
this->m_modelsToSessions[dmod] = shared_from_this();
smtk::model::Model smtkModel(mgr, mid);
smtkModel.setSession(
smtk::model::SessionRef(
......@@ -2202,15 +2195,15 @@ bool Session::removeModelEntity(const smtk::model::EntityRef& modRef)
// Remove any models that this session owned from s_modelsToSessions.
std::map<vtkDiscreteModel*,Session::WeakPtr>::iterator mbit;
for (mbit = Session::s_modelsToSessions.begin(); mbit != Session::s_modelsToSessions.end(); ++mbit)
for (mbit = this->m_modelsToSessions.begin(); mbit != this->m_modelsToSessions.end(); ++mbit)
{
if (mbit->first == dmod)
{
smtk::common::UUID modelId = modRef.entity();
Session::s_modelsToSessions.erase(mbit);
vtkSmartPointer<vtkDiscreteModelWrapper> modelPtr = Session::s_modelIdsToRefs[modelId];
Session::s_modelIdsToRefs.erase(modelId);
Session::s_modelRefsToIds.erase(modelPtr);
this->m_modelsToSessions.erase(mbit);
vtkSmartPointer<vtkDiscreteModelWrapper> modelPtr = this->m_modelIdsToRefs[modelId];
this->m_modelIdsToRefs.erase(modelId);
this->m_modelRefsToIds.erase(modelPtr);
break;
}
}
......
......@@ -71,12 +71,12 @@ class BathymetryHelper;
* to load a CMB model. Internally, a CMBModelReadOperator is used to load
* a vtkDiscreteModel (placed inside a vtkDiscreteModelWrapper by the
* CMB operator). The Session instance is associated to the model wrapper
* in the s_modelsToSessions variable.
* in the m_modelsToSessions variable.
* (2) The ReadOperator calls trackModel with the vtkDiscreteModelWrapper
* obtained using CMB's (not SMTK's) "read" operator. Since
* vtkDiscreteModelWrapper is a subclass of vtkObject,
* we can keep it from being destroyed by holding a smart-pointer to
* it (in s_modelIdsToRefs and s_modelRefsToIds).
* it (in m_modelIdsToRefs and m_modelRefsToIds).
* (2) The model and, upon demand, entities contained in the model
* are assigned UUIDs if not present already. The UUIDs are kept
* in the vtkInformation object every vtkModelItem owns (Properties).
......@@ -103,7 +103,7 @@ public:
void assignUUIDs(const std::vector<vtkModelItem*>& ents, vtkAbstractArray* uuidArray);
static vtkUnsignedIntArray* retrieveUUIDs(
vtkUnsignedIntArray* retrieveUUIDs(
vtkDiscreteModel* model, const std::vector<vtkModelItem*>& ents);
int ExportEntitiesToFileOfNameAndType(
......@@ -240,9 +240,12 @@ protected:
smtk::bridge::discrete::BathymetryHelper* m_bathymetryHelper;
static std::map<vtkDiscreteModel*,WeakPtr> s_modelsToSessions;
static std::map<smtk::common::UUID,vtkSmartPointer<vtkDiscreteModelWrapper> > s_modelIdsToRefs;
static std::map<vtkSmartPointer<vtkDiscreteModelWrapper>, smtk::common::UUID> s_modelRefsToIds;
/// Track which models are tracked by which sessions.
std::map<vtkDiscreteModel*,WeakPtr> m_modelsToSessions;
/// Associate UUIDs to vtkDiscreteModelWrapper instances.
std::map<smtk::common::UUID,vtkSmartPointer<vtkDiscreteModelWrapper> > m_modelIdsToRefs;
/// Associate vtkDiscreteModelWrapper instances to UUIDs.
std::map<vtkSmartPointer<vtkDiscreteModelWrapper>, smtk::common::UUID> m_modelRefsToIds;
};
} // namespace discrete
......
......@@ -21,6 +21,7 @@
#include "vtkObjectFactory.h"
#include "vtkPolyData.h"
#include "vtkCMBModelReader.h"
#include "smtk/bridge/discrete/Session.h"
namespace
{
......@@ -45,7 +46,8 @@ const char* vtkCMBModelReadOperator::GetCMBFileVersionString()
return CMBFileVersionString;
}
void vtkCMBModelReadOperator::Operate(vtkDiscreteModelWrapper* ModelWrapper)
void vtkCMBModelReadOperator::Operate(vtkDiscreteModelWrapper* ModelWrapper,
smtk::bridge::discrete::Session* session)
{
if(!ModelWrapper)
{
......@@ -53,14 +55,15 @@ void vtkCMBModelReadOperator::Operate(vtkDiscreteModelWrapper* ModelWrapper)
return;
}
vtkDiscreteModel* Model = ModelWrapper->GetModel();
this->Read(Model);
this->Read(Model, session);
if(this->OperateSucceeded)
{
ModelWrapper->InitializeWithModelGeometry();
}
}
void vtkCMBModelReadOperator::Read(vtkDiscreteModel* Model)
void vtkCMBModelReadOperator::Read(vtkDiscreteModel* Model,
smtk::bridge::discrete::Session* session)
{
vtkDebugMacro("Reading a CMB file into a CMB model.");
this->OperateSucceeded = 0;
......@@ -70,7 +73,6 @@ void vtkCMBModelReadOperator::Read(vtkDiscreteModel* Model)
return;
}
vtkNew<vtkCMBModelReader> reader;
reader->SetFileName(this->GetFileName());
reader->Update();
......@@ -83,7 +85,7 @@ void vtkCMBModelReadOperator::Read(vtkDiscreteModel* Model)
return;
}
this->OperateSucceeded = parser->Parse(MasterPoly, Model);
this->OperateSucceeded = parser->Parse(MasterPoly, Model, session);
Model->SetFileName(this->GetFileName());
parser->Delete();
......
......@@ -19,11 +19,17 @@
#include "smtk/bridge/discrete/Exports.h" // For export macro
#include "vtkObject.h"
class vtkCMBParserBase;
class vtkDiscreteModelWrapper;
class vtkPolyData;
class vtkDiscreteModel;
namespace smtk {
namespace bridge {
namespace discrete {
class Session;
}
}
}
class SMTKDISCRETESESSION_EXPORT vtkCMBModelReadOperator : public vtkObject
{
......@@ -34,12 +40,20 @@ public:
// Description:
// Load the file into Model.
void Operate(vtkDiscreteModelWrapper* ModelWrapper);
// The \a session will be used to assign UUIDs to entities if there are field arrays
// for entity UUIDs; if there is no UUID array for certain entities, the session will create
// and assign new UUIDs for them. This way cmb models will have consistent UUIDs across
// different runs so that entity-attribute associations, which is recorded with UUIDs, will
// be consistent, so is color-by entity UUIDs.
// If the session is NULL, the UUIDs will be different everytime we load a cmb model.
void Operate(vtkDiscreteModelWrapper* ModelWrapper,
smtk::bridge::discrete::Session* session);
//BTX
// Description:
// Load the file into Model.
void Read(vtkDiscreteModel* model);
void Read(vtkDiscreteModel* model,
smtk::bridge::discrete::Session* session);
//ETX
// Description:
......
......@@ -11,6 +11,8 @@
#include "vtkCMBModelWriterBase.h"
#include "smtk/bridge/discrete/Session.h"
#include "vtkDiscreteModel.h"
#include "vtkCMBParserBase.h"
#include "vtkDiscreteModelWrapper.h"
......@@ -36,17 +38,19 @@ vtkCMBModelWriterBase:: ~vtkCMBModelWriterBase()
this->SetFileName(0);
}
void vtkCMBModelWriterBase::Operate(vtkDiscreteModelWrapper* ModelWrapper)
void vtkCMBModelWriterBase::Operate(vtkDiscreteModelWrapper* ModelWrapper,
smtk::bridge::discrete::Session* session)
{
if(!ModelWrapper)
{
vtkErrorMacro("Passed in a null model wrapper.");
return;
}
this->Write(ModelWrapper->GetModel());
this->Write(ModelWrapper->GetModel(), session);
}
void vtkCMBModelWriterBase::Write(vtkDiscreteModel* model)
void vtkCMBModelWriterBase::Write(vtkDiscreteModel* model,
smtk::bridge::discrete::Session* session)
{
vtkDebugMacro("Writing a CMB file.");
this->OperateSucceeded = 0;
......@@ -85,7 +89,7 @@ void vtkCMBModelWriterBase::Write(vtkDiscreteModel* model)
if (writer)
{
writer->SetFileName(this->GetFileName());
this->OperateSucceeded = writer->Write(model);
this->OperateSucceeded = writer->Write(model, session);
writer->Delete();
}
vtkDebugMacro("Finished writing a CMB file.");
......
......@@ -21,6 +21,13 @@
#include "smtk/bridge/discrete/Exports.h" // For export macro
#include "vtkObject.h"
namespace smtk {
namespace bridge {
namespace discrete {
class Session;
}
}
}
class vtkDiscreteModelWrapper;
class vtkPolyData;
......@@ -35,12 +42,17 @@ public:
// Description:
// Write the CMB file out. This is the operator version of writing.
void Operate(vtkDiscreteModelWrapper* ModelWrapper);
// The \a session will be used to retrieve UUIDs data array for entities and
// add it to field data of output.
// NOTE: vtkCMBModelWriterV2 has implementation using the discrete \a session
void Operate(vtkDiscreteModelWrapper* ModelWrapper,
smtk::bridge::discrete::Session* session);
//BTX
// Description:
// Write the CMB file out.
void Write(vtkDiscreteModel* model);
void Write(vtkDiscreteModel* model,
smtk::bridge::discrete::Session* session);
//ETX
// Description:
// Get/Set the name of the output file.
......
......@@ -11,6 +11,8 @@
#include "vtkCMBModelWriterV2.h"
#include "smtk/bridge/discrete/Session.h"
#include "Session.h"
#include "vtkCellData.h"
#include "vtkCharArray.h"
......@@ -52,7 +54,8 @@ vtkCMBModelWriterV2:: ~vtkCMBModelWriterV2()
{
}
bool vtkCMBModelWriterV2::Write(vtkDiscreteModel* Model)
bool vtkCMBModelWriterV2::Write(vtkDiscreteModel* Model,
smtk::bridge::discrete::Session* session)
{
if(!Model)
{
......@@ -103,7 +106,7 @@ bool vtkCMBModelWriterV2::Write(vtkDiscreteModel* Model)
{
this->SetFloatingEdgeData(Model, Poly.GetPointer());
}
this->SetUUIDData(Model, Poly.GetPointer());
this->SetUUIDData(Model, Poly.GetPointer(), session);
vtkNew<vtkXMLPolyDataWriter> Writer;
Writer->SetInputData(0, Poly.GetPointer());
......@@ -314,7 +317,8 @@ void vtkCMBModelWriterV2::SetFloatingEdgeData(vtkDiscreteModel* Model, vtkPolyDa
this->SetModelEntityData(Poly, Entities, "ModelEdge");
}
void vtkCMBModelWriterV2::SetUUIDData(vtkDiscreteModel* model, vtkPolyData* poly)
void vtkCMBModelWriterV2::SetUUIDData(vtkDiscreteModel* model, vtkPolyData* poly,
smtk::bridge::discrete::Session* session)
{
vtkModelItemIterator* itit;
std::vector<vtkModelItem*> entities;
......@@ -325,49 +329,49 @@ void vtkCMBModelWriterV2::SetUUIDData(vtkDiscreteModel* model, vtkPolyData* poly
entities.push_back(itit->GetCurrentItem());
itit->Delete();
this->SetModelItemUUIDs(model, poly, entities, ModelParserHelper::GetModelUUIDsString());
this->SetModelItemUUIDs(model, poly, entities, ModelParserHelper::GetModelUUIDsString(), session);
// Material
entities.clear();
itit = model->NewIterator(vtkModelMaterialType);
for (itit->Begin(); !itit->IsAtEnd(); itit->Next())
entities.push_back(itit->GetCurrentItem());
itit->Delete();
this->SetModelItemUUIDs(model, poly, entities, ModelParserHelper::GetMaterialUUIDsString());
this->SetModelItemUUIDs(model, poly, entities, ModelParserHelper::GetMaterialUUIDsString(), session);
// Groups
entities.clear();
itit = model->NewIterator(vtkDiscreteModelEntityGroupType);
for (itit->Begin(); !itit->IsAtEnd(); itit->Next())
entities.push_back(itit->GetCurrentItem());
itit->Delete();
this->SetModelItemUUIDs(model, poly, entities, ModelParserHelper::GetModelGroupUUIDsString());
this->SetModelItemUUIDs(model, poly, entities, ModelParserHelper::GetModelGroupUUIDsString(), session);
// Regions
entities.clear();
itit = model->NewIterator(vtkModelRegionType);
for (itit->Begin(); !itit->IsAtEnd(); itit->Next())
entities.push_back(itit->GetCurrentItem());
itit->Delete();
this->SetModelItemUUIDs(model, poly, entities, ModelParserHelper::GetModelRegionUUIDsString());
this->SetModelItemUUIDs(model, poly, entities, ModelParserHelper::GetModelRegionUUIDsString(), session);
// Faces
entities.clear();
itit = model->NewIterator(vtkModelFaceType);
for (itit->Begin(); !itit->IsAtEnd(); itit->Next())
entities.push_back(itit->GetCurrentItem());
itit->Delete();
this->SetModelItemUUIDs(model, poly, entities, ModelParserHelper::GetModelFaceUUIDsString());
this->SetModelItemUUIDs(model, poly, entities, ModelParserHelper::GetModelFaceUUIDsString(), session);
// Edges
entities.clear();
itit = model->NewIterator(vtkModelEdgeType);
for (itit->Begin(); !itit->IsAtEnd(); itit->Next())
entities.push_back(itit->GetCurrentItem());
itit->Delete();
this->SetModelItemUUIDs(model, poly, entities, ModelParserHelper::GetModelEdgeUUIDsString());
this->SetModelItemUUIDs(model, poly, entities, ModelParserHelper::GetModelEdgeUUIDsString(), session);
// Vertices
entities.clear();
itit = model->NewIterator(vtkModelVertexType);
for (itit->Begin(); !itit->IsAtEnd(); itit->Next())
entities.push_back(itit->GetCurrentItem());
itit->Delete();
this->SetModelItemUUIDs(model, poly, entities, ModelParserHelper::GetModelVertexUUIDsString());
this->SetModelItemUUIDs(model, poly, entities, ModelParserHelper::GetModelVertexUUIDsString(), session);
// Shell
entities.clear();
......@@ -375,14 +379,14 @@ void vtkCMBModelWriterV2::SetUUIDData(vtkDiscreteModel* model, vtkPolyData* poly
for (itit->Begin(); !itit->IsAtEnd(); itit->Next())
entities.push_back(itit->GetCurrentItem());
itit->Delete();
this->SetModelItemUUIDs(model, poly, entities, ModelParserHelper::GetModelShellUUIDsString());
this->SetModelItemUUIDs(model, poly, entities, ModelParserHelper::GetModelShellUUIDsString(), session);
// Loop
entities.clear();
itit = model->NewIterator(vtkModelLoopUseType);
for (itit->Begin(); !itit->IsAtEnd(); itit->Next())
entities.push_back(itit->GetCurrentItem());
itit->Delete();
this->SetModelItemUUIDs(model, poly, entities, ModelParserHelper::GetModelLoopUUIDsString());
this->SetModelItemUUIDs(model, poly, entities, ModelParserHelper::GetModelLoopUUIDsString(), session);
// Face uses
entities.clear();
......@@ -390,21 +394,21 @@ void vtkCMBModelWriterV2::SetUUIDData(vtkDiscreteModel* model, vtkPolyData* poly
for (itit->Begin(); !itit->IsAtEnd(); itit->Next())
entities.push_back(itit->GetCurrentItem());
itit->Delete();
this->SetModelItemUUIDs(model, poly, entities, ModelParserHelper::GetModelFaceUseUUIDsString());
this->SetModelItemUUIDs(model, poly, entities, ModelParserHelper::GetModelFaceUseUUIDsString(), session);
// Edge uses
entities.clear();
itit = model->NewIterator(vtkModelEdgeUseType);
for (itit->Begin(); !itit->IsAtEnd(); itit->Next())
entities.push_back(itit->GetCurrentItem());
itit->Delete();
this->SetModelItemUUIDs(model, poly, entities, ModelParserHelper::GetModelEdgeUseUUIDsString());
this->SetModelItemUUIDs(model, poly, entities, ModelParserHelper::GetModelEdgeUseUUIDsString(), session);
// Vertex uses
entities.clear();
itit = model->NewIterator(vtkModelVertexUseType);
for (itit->Begin(); !itit->IsAtEnd(); itit->Next())
entities.push_back(itit->GetCurrentItem());
itit->Delete();
this->SetModelItemUUIDs(model, poly, entities, ModelParserHelper::GetModelVertexUseUUIDsString());
this->SetModelItemUUIDs(model, poly, entities, ModelParserHelper::GetModelVertexUseUUIDsString(), session);
}
void vtkCMBModelWriterV2::SetModelEntityData(
......@@ -463,12 +467,16 @@ void vtkCMBModelWriterV2::SetModelItemUUIDs(
vtkDiscreteModel* model,
vtkPolyData* poly,
std::vector<vtkModelItem*> & items,
const char* arrayName)
const char* arrayName,
smtk::bridge::discrete::Session* session)
{
vtkUnsignedIntArray* arr = smtk::bridge::discrete::Session::retrieveUUIDs(model, items);
arr->SetName(arrayName);
poly->GetFieldData()->AddArray(arr);
arr->Delete();
if(session)
{
vtkUnsignedIntArray* arr = session->retrieveUUIDs(model, items);
arr->SetName(arrayName);
poly->GetFieldData()->AddArray(arr);
arr->Delete();
}
}
void vtkCMBModelWriterV2::AddFileVersion(vtkPolyData* Poly)
......
......@@ -33,6 +33,13 @@
#include "vtkObject.h"
#include <vector>
namespace smtk {
namespace bridge {
namespace discrete {
class Session;
}
}
}
class vtkDiscreteModel;
class vtkCMBModelWriterBase;
......@@ -49,7 +56,7 @@ public:
// Description:
// Write the CMB file out.
virtual bool Write(vtkDiscreteModel* Model);
virtual bool Write(vtkDiscreteModel* Model, smtk::bridge::discrete::Session* session);
// Description:
// Get/Set the data mode used for the file's data. The options are
......@@ -112,7 +119,8 @@ protected:
// Description:
// Add arrays to the master \a Poly data containing UUIDs for model entities.
virtual void SetUUIDData(vtkDiscreteModel* Model, vtkPolyData* Poly);
virtual void SetUUIDData(vtkDiscreteModel* Model, vtkPolyData* Poly,
smtk::bridge::discrete::Session* session);
// Description:
// Set the vtkCMBModelFaceData in Poly.
......@@ -128,7 +136,8 @@ protected:
virtual void SetModelItemUUIDs(
vtkDiscreteModel* model, vtkPolyData* poly,
std::vector<vtkModelItem*>& items,
const char* arrayName);
const char* arrayName,
smtk::bridge::discrete::Session* session);
// Description:
// Add the file version to the field data of the poly data
......
......@@ -20,6 +20,14 @@
#include "vtkSmartPointer.h" //needed for classification
#include <map> //needed for classification
namespace smtk {
namespace bridge {
namespace discrete {
class Session;
}
}
}
class vtkCharArray;
class vtkDiscreteModel;
class vtkDiscreteModelGeometricEntity;
......@@ -36,7 +44,16 @@ public:
vtkTypeMacro(vtkCMBParserBase,vtkObject);
void PrintSelf(ostream& os, vtkIndent indent);
virtual bool Parse(vtkPolyData* MasterPoly, vtkDiscreteModel* Model) = 0;
// Description:
// Parse the input \a MasterPoly into the discrete \a Model.
// The \a session will be used to assign UUIDs to entities if there are field arrays
// for entity UUIDs; if there is no UUID array for certain entities, the session will create
// and assign new UUIDs for them. This way cmb models will have consistent UUIDs across
// different runs so that entity-attribute associations, which is recorded with UUIDs, will
// be consistent, so is color-by entity UUIDs.
// NOTE: Currently only vtkCMBParserV5 is using the discrete \a session
virtual bool Parse(vtkPolyData* MasterPoly, vtkDiscreteModel* Model,
smtk::bridge::discrete::Session* session) = 0;
// Description:
// Function to set the geometry of the model so that every parser
......@@ -91,6 +108,7 @@ protected:
void SeparateCellClassification(vtkDiscreteModel* model,
vtkIdTypeArray* cellClassification,
vtkCMBParserBase::CellToModelType& cellToModelMap) const;
private:
vtkCMBParserBase(const vtkCMBParserBase&); // Not implemented.
void operator=(const vtkCMBParserBase&); // Not implemented.
......
......@@ -51,7 +51,8 @@ vtkCMBParserV2:: ~vtkCMBParserV2()
{
}
bool vtkCMBParserV2::Parse(vtkPolyData* MasterPoly, vtkDiscreteModel* Model)
bool vtkCMBParserV2::Parse(vtkPolyData* MasterPoly, vtkDiscreteModel* Model,
smtk::bridge::discrete::Session* vtkNotUsed(session))
{
Model->Reset();
......
......@@ -31,7 +31,8 @@ public:
vtkTypeMacro(vtkCMBParserV2,vtkCMBParserBase);
void PrintSelf(ostream& os, vtkIndent indent);
virtual bool Parse(vtkPolyData* MasterPoly, vtkDiscreteModel* Model);
virtual bool Parse(vtkPolyData* MasterPoly, vtkDiscreteModel* Model,
smtk::bridge::discrete::Session* session);
protected:
vtkCMBParserV2();
......
......@@ -55,7 +55,8 @@ vtkCMBParserV4:: ~vtkCMBParserV4()
{
}
bool vtkCMBParserV4::Parse(vtkPolyData* MasterPoly, vtkDiscreteModel* Model)
bool vtkCMBParserV4::Parse(vtkPolyData* MasterPoly, vtkDiscreteModel* Model,
smtk::bridge::discrete::Session* vtkNotUsed(session))
{
Model->Reset();
......
......@@ -31,7 +31,8 @@ public:
vtkTypeMacro(vtkCMBParserV4,vtkCMBParserBase);
void PrintSelf(ostream& os, vtkIndent indent);
virtual bool Parse(vtkPolyData* MasterPoly, vtkDiscreteModel* Model);
virtual bool Parse(vtkPolyData* MasterPoly, vtkDiscreteModel* Model,
smtk::bridge::discrete::Session* session);
protected:
vtkCMBParserV4();
......
......@@ -11,7 +11,7 @@
#include "vtkCMBParserV5.h"
#include "Session.h"
#include "smtk/bridge/discrete/Session.h"
#include "vtkCharArray.h"
#include "vtkModel3dm2DGridRepresentation.h"
......@@ -48,24 +48,18 @@
#include <stdio.h>
#include <string.h>
/// The parser keeps a single bridge around to track all the models it imports.
smtk::shared_ptr<smtk::bridge::discrete::Session> vtkCMBParserV5::s_session;
vtkStandardNewMacro(vtkCMBParserV5);
vtkCMBParserV5::vtkCMBParserV5()
{
if (!vtkCMBParserV5::s_session)
vtkCMBParserV5::s_session = smtk::bridge::discrete::Session::create();
}
vtkCMBParserV5:: ~vtkCMBParserV5()
{
}
bool vtkCMBParserV5::Parse(vtkPolyData* MasterPoly, vtkDiscreteModel* Model)
bool vtkCMBParserV5::Parse(vtkPolyData* MasterPoly, vtkDiscreteModel* Model,
smtk::bridge::discrete::Session* session)
{
Model->Reset();
......@@ -109,8 +103,11 @@ bool vtkCMBParserV5::Parse(vtkPolyData* MasterPoly, vtkDiscreteModel* Model)
// load in the model's UUID if it exists.
std::vector<vtkModelItem*> modelRecords;
modelRecords.push_back(Model);
vtkCMBParserV5::s_session->assignUUIDs(modelRecords,
MasterPoly->GetFieldData()->GetArray(ModelParserHelper::GetModelUUIDsString()));
if(session)
{
session->assignUUIDs(modelRecords,
MasterPoly->GetFieldData()->GetArray(ModelParserHelper::GetModelUUIDsString()));
}
// TODO: Handle submodels whose UUIDs are also in the field-data array.
// Need to know how the order in the file may be obtained.
......@@ -122,9 +119,12 @@ bool vtkCMBParserV5::Parse(vtkPolyData* MasterPoly, vtkDiscreteModel* Model)
ModelEntities[i] = material;
}
MaterialIdsArray->Delete();
vtkCMBParserV5::s_session->assignUUIDs(
std::vector<vtkModelItem*>(ModelEntities.begin(), ModelEntities.end()),
MasterPoly->GetFieldData()->GetArray(ModelParserHelper::GetMaterialUUIDsString()));
if(session)
{
session->assignUUIDs(
std::vector<vtkModelItem*>(ModelEntities.begin(), ModelEntities.end()),
MasterPoly->GetFieldData()->GetArray(ModelParserHelper::GetMaterialUUIDsString()));
}
this->SetModelEntityData(MasterPoly, ModelEntities, "Material", Model);
// next load in the model vertices
......@@ -152,9 +152,12 @@ bool vtkCMBParserV5::Parse(vtkPolyData* MasterPoly, vtkDiscreteModel* Model)
}
vertexPointIds->Delete();
this->SetModelEntityData(MasterPoly, ModelEntities, "ModelVertex", Model);
vtkCMBParserV5::s_session->assignUUIDs(
std::vector<vtkModelItem*>(ModelEntities.begin(), ModelEntities.end()),
MasterPoly->GetFieldData()->GetArray(ModelParserHelper::GetModelVertexUUIDsString()));
if(session)
{
session->assignUUIDs(
std::vector<vtkModelItem*>(ModelEntities.begin(), ModelEntities.end()),
MasterPoly->GetFieldData()->GetArray(ModelParserHelper::GetModelVertexUUIDsString()));
}
}
VertexIdsArray->Delete();
VertexIdsArray = 0;
......@@ -186,9 +189,12 @@ bool vtkCMBParserV5::Parse(vtkPolyData* MasterPoly, vtkDiscreteModel* Model)
EdgeIdsArray->Delete();
EdgeIdsArray = 0;
this->SetModelEntityData(MasterPoly, ModelEntities, "ModelEdge", Model);
vtkCMBParserV5::s_session->assignUUIDs(
std::vector<vtkModelItem*>(ModelEntities.begin(), ModelEntities.end()),
MasterPoly->GetFieldData()->GetArray(ModelParserHelper::GetModelEdgeUUIDsString()));
if(session)
{
session->assignUUIDs(
std::vector<vtkModelItem*>(ModelEntities.begin(), ModelEntities.end()),
MasterPoly->GetFieldData()->GetArray(ModelParserHelper::GetModelEdgeUUIDsString()));
}
EdgeVertices->Delete();
}
......@@ -291,9 +297,12 @@ bool vtkCMBParserV5::Parse(vtkPolyData* MasterPoly, vtkDiscreteModel* Model)
FaceMaterials = 0;
}
this->SetModelEntityData(MasterPoly, ModelEntities, "ModelFace", Model);
vtkCMBParserV5::s_session->assignUUIDs(