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

Commit aadd6420 authored by Yumin Yuan's avatar Yumin Yuan

Made cmb parser and writer in discrete to handle full 3D topology.

CMB parsers and writers in discrete bridge could not handle full 3D models,
meaning they can't write and read a 3D model with faces, edges and vertices.
This constraint prevented the 3D discrete model being processed by meshers
that require full 3D topolgy. With this commit, 3D models with edges can now
be written and loaded with the cmb writers and parsers.
parent 315fb5b5
......@@ -125,7 +125,9 @@ void vtkCMBModelWriterV2::SetAnalysisGridData(vtkDiscreteModel* model, vtkPolyDa
vtkIdTypeArray* pointMap = analysisGridInfo->GetModelPointToAnalysisPoint();
vtkIdTypeArray* cellMap = analysisGridInfo->GetModelCellToAnalysisCells();
vtkCharArray* cellSides = analysisGridInfo->GetModelCellToAnalysisCellSides();
if(pointMap != NULL && cellMap != NULL && cellSides != NULL)
if((pointMap != NULL && pointMap->GetNumberOfTuples() == poly->GetNumberOfPoints()) &&
(cellMap != NULL && cellMap->GetNumberOfTuples() == poly->GetNumberOfCells()) &&
(cellSides != NULL && cellSides->GetNumberOfTuples() == poly->GetNumberOfCells()))
{
pointMap->SetName(vtkDiscreteModel::GetPointMapArrayName());
poly->GetPointData()->AddArray(pointMap);
......
......@@ -59,7 +59,7 @@ void vtkCMBModelWriterV5::SetModelEdgeData(vtkDiscreteModel* model, vtkPolyData*
for(edges->Begin();!edges->IsAtEnd();edges->Next())
{
vtkDiscreteModelEdge* edge = vtkDiscreteModelEdge::SafeDownCast(edges->GetCurrentItem());
if(edge->GetModelRegion() != NULL || model->GetModelDimension() == 2)
// if(edge->GetModelRegion() != NULL || model->GetModelDimension() == 2)
{
entities.push_back(edge);
}
......@@ -116,7 +116,7 @@ void vtkCMBModelWriterV5::SetModelEdgeData(vtkDiscreteModel* model, vtkPolyData*
void vtkCMBModelWriterV5::SetModelFaceData(vtkDiscreteModel* Model, vtkPolyData* Poly)
{
std::vector<vtkModelEntity*> Entities;
if(Model->GetModelDimension() == 2)
// if(Model->GetModelDimension() == 2)
{
// the adjacent edge ids for each model face is separated by a -1
vtkIdTypeArray* ModelFaceAdjacentEdgesId = vtkIdTypeArray::New();
......@@ -130,7 +130,10 @@ void vtkCMBModelWriterV5::SetModelFaceData(vtkDiscreteModel* Model, vtkPolyData*
vtkDiscreteModelFace* Face = vtkDiscreteModelFace::SafeDownCast(Faces->GetCurrentItem());
Entities.push_back(Face);
vtkModelMaterial* Material = Face->GetMaterial();
ModelFaceMaterialIds->InsertNextValue(Material->GetUniquePersistentId());
if(Material)
{
ModelFaceMaterialIds->InsertNextValue(Material->GetUniquePersistentId());
}
// Loop Information is encoded as follows: nL l0e0 l0e1 ... -1 l1e0 ...
// Where nL is the number of loops in the face followed by the edges in
// loop (for example l0e0 is edge 0 of loop 0) - with each loop separated by -1
......@@ -173,12 +176,14 @@ void vtkCMBModelWriterV5::SetModelFaceData(vtkDiscreteModel* Model, vtkPolyData*
ModelEdgeDirections->SetName(ModelParserHelper::GetModelEdgeDirectionsString());
Poly->GetFieldData()->AddArray(ModelEdgeDirections);
ModelEdgeDirections->Delete();
ModelFaceMaterialIds->SetName(ModelParserHelper::GetFaceMaterialIdString());
Poly->GetFieldData()->AddArray(ModelFaceMaterialIds);
if(ModelFaceMaterialIds->GetNumberOfTuples())
{
ModelFaceMaterialIds->SetName(ModelParserHelper::GetFaceMaterialIdString());
Poly->GetFieldData()->AddArray(ModelFaceMaterialIds);
}
ModelFaceMaterialIds->Delete();
}
else if(Model->GetModelDimension() == 3)
if(Model->GetModelDimension() == 3)
{
vtkIdTypeArray* ModelFaceAdjacentRegionsId = vtkIdTypeArray::New();
ModelFaceAdjacentRegionsId->SetNumberOfComponents(2);
......@@ -187,7 +192,7 @@ void vtkCMBModelWriterV5::SetModelFaceData(vtkDiscreteModel* Model, vtkPolyData*
for(Faces->Begin();!Faces->IsAtEnd();Faces->Next())
{
vtkDiscreteModelFace* Face = vtkDiscreteModelFace::SafeDownCast(Faces->GetCurrentItem());
Entities.push_back(Face);
// Entities.push_back(Face);
vtkIdType ids[2] = {-1, -1};
for(int j=0;j<2;j++)
{
......
......@@ -224,34 +224,11 @@ bool vtkCMBParserV5::Parse(vtkPolyData* MasterPoly, vtkDiscreteModel* Model,
// Create the face
vtkDiscreteModelFace* face;
if(FaceMaterials && FaceMaterials->GetValue(i) >= 0)
{ // a model face in a 2D model
// First get the number of loops
int nLoops = EdgesOfModelFace->GetValue(ArrayCounter++);
int loop;
{
vtkModelMaterial* Material = vtkModelMaterial::SafeDownCast(
Model->GetModelEntity(vtkModelMaterialType, FaceMaterials->GetValue(i)));
face = vtkDiscreteModelFace::SafeDownCast(
Model->BuildModelFace(0, NULL, NULL, Material) );
// Process each face loop (assume that the first loop is the outer one
for (loop = 0; loop < nLoops; ++loop)
{
int EdgeCounter = 0;
while(ArrayCounter < EdgesOfModelFace->GetNumberOfTuples() &&
EdgesOfModelFace->GetValue(ArrayCounter) >= 0)
{
vtkIdType EdgeId = EdgesOfModelFace->GetValue(ArrayCounter);
Edges[EdgeCounter] =
vtkModelEdge::SafeDownCast(Model->GetModelEntity(vtkModelEdgeType, EdgeId));
EdgeDirs[EdgeCounter] = EdgeDirections->GetValue(ArrayCounter);
ArrayCounter++;
EdgeCounter++;
}
ArrayCounter++; // incremented because we want to skip the -1 value
bool blockEvent = Model->GetBlockModelGeometricEntityEvent();
Model->SetBlockModelGeometricEntityEvent(true);
face->AddLoop(EdgeCounter, &Edges[0], &EdgeDirs[0]);
Model->SetBlockModelGeometricEntityEvent(blockEvent);
}
}
else
{ // a model face in a 3D model
......@@ -277,8 +254,36 @@ bool vtkCMBParserV5::Parse(vtkPolyData* MasterPoly, vtkDiscreteModel* Model,
}
}
}
if(EdgesOfModelFace && EdgesOfModelFace->GetNumberOfTuples() > 0)
{ // a model face in a 2D model
// First get the number of loops
int nLoops = EdgesOfModelFace->GetValue(ArrayCounter++);
int loop;
// Process each face loop (assume that the first loop is the outer one
for (loop = 0; loop < nLoops; ++loop)
{
int EdgeCounter = 0;
while(ArrayCounter < EdgesOfModelFace->GetNumberOfTuples() &&
EdgesOfModelFace->GetValue(ArrayCounter) >= 0)
{
vtkIdType EdgeId = EdgesOfModelFace->GetValue(ArrayCounter);
Edges[EdgeCounter] =
vtkModelEdge::SafeDownCast(Model->GetModelEntity(vtkModelEdgeType, EdgeId));
EdgeDirs[EdgeCounter] = EdgeDirections->GetValue(ArrayCounter);
ArrayCounter++;
EdgeCounter++;
}
ArrayCounter++; // incremented because we want to skip the -1 value
bool blockEvent = Model->GetBlockModelGeometricEntityEvent();
Model->SetBlockModelGeometricEntityEvent(true);
face->AddLoop(EdgeCounter, &Edges[0], &EdgeDirs[0]);
Model->SetBlockModelGeometricEntityEvent(blockEvent);
}
}
ModelEntities[i] = face;
}
if(EdgesOfModelFace)
{
EdgesOfModelFace->Delete();
......
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