Updates will be applied - 3:30pm EDT (UTC -400). No downtime expected.

Commit 70ac860f authored by Yumin Yuan's avatar Yumin Yuan

Refactor how discrete session load models and keeps model records

Instead of using a static session object in cmbParserV5, the session object is passed into
the reading operation so that it can 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 session
parent 1247c19f
......@@ -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:
......
......@@ -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(
std::vector<vtkModelItem*>(ModelEntities.begin(), ModelEntities.end()),
MasterPoly->GetFieldData()->GetArray(ModelParserHelper::GetModelFaceUUIDsString()));
if(session)
{
session->assignUUIDs(
std::vector<vtkModelItem*>(ModelEntities.begin(), ModelEntities.end()),
MasterPoly->GetFieldData()->GetArray(ModelParserHelper::GetModelFaceUUIDsString()));
}
// now that the ids are properly set we can add the cells to the model faces and/or edges
CellToModelType CellToModelEntityIds; //classification
......@@ -374,9 +383,12 @@ bool vtkCMBParserV5::Parse(vtkPolyData* MasterPoly, vtkDiscreteModel* Model)
RegionMaterials->Delete();
RegionMaterials = 0;
this->SetModelEntityData(MasterPoly, ModelEntities, "ModelRegion", Model);
vtkCMBParserV5::s_session->assignUUIDs(
std::vector<vtkModelItem*>(ModelEntities.begin(), ModelEntities.end()),
MasterPoly->GetFieldData()->GetArray(ModelParserHelper::GetModelRegionUUIDsString()));
if(session)
{
session->assignUUIDs(
std::vector<vtkModelItem*>(ModelEntities.begin(), ModelEntities.end()),
MasterPoly->GetFieldData()->GetArray(ModelParserHelper::GetModelRegionUUIDsString()));
}
}
// next associate any floating edges with their region
......@@ -457,9 +469,12 @@ bool vtkCMBParserV5::Parse(vtkPolyData* MasterPoly, vtkDiscreteModel* Model)
GroupedEntityIds->Delete();
GroupedEntityIds = 0;
this->SetModelEntityData(MasterPoly, ModelEntities, "ModelEntityGroup", Model);
vtkCMBParserV5::s_session->assignUUIDs(
std::vector<vtkModelItem*>(ModelEntities.begin(), ModelEntities.end()),
MasterPoly->GetFieldData()->GetArray(ModelParserHelper::GetModelGroupUUIDsString()));
if(session)
{
session->assignUUIDs(
std::vector<vtkModelItem*>(ModelEntities.begin(), ModelEntities.end()),
MasterPoly->GetFieldData()->GetArray(ModelParserHelper::GetModelGroupUUIDsString()));
}
}
// TODO: Handle uses and shells whose UUIDs are also in field-data arrays.
......
......@@ -19,20 +19,10 @@
#include "vtkCMBParserBase.h"
#include <vector>
#include "smtk/SharedPtr.h"
class vtkDiscreteModel;
class vtkModelEntity;
class vtkPolyData;
namespace smtk {
namespace bridge {
namespace discrete {
class Session;
}
}
}
class SMTKDISCRETESESSION_EXPORT vtkCMBParserV5 : public vtkCMBParserBase
{
public:
......@@ -40,7 +30,8 @@ public:
vtkTypeMacro(vtkCMBParserV5,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:
vtkCMBParserV5();
......@@ -59,8 +50,6 @@ protected:
// is "more" complete.
void SetAnalysisGridData(vtkPolyData* masterPoly, vtkDiscreteModel* model);
static smtk::shared_ptr<smtk::bridge::discrete::Session> s_session;
private:
vtkCMBParserV5(const vtkCMBParserV5&); // Not implemented.
void operator=(const vtkCMBParserV5&); // Not implemented.
......
......@@ -69,7 +69,7 @@ OperatorResult ReadOperator::operateInternal()
// Create a new model to hold the result.
vtkNew<vtkDiscreteModelWrapper> mod;
this->m_op->Operate(mod.GetPointer());
this->m_op->Operate(mod.GetPointer(), this->discreteSession());
// Now assign a UUID to the model and associate its filename with
// a URL property (if things went OK).
......
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