Commit 0cc6827b authored by Yumin Yuan's avatar Yumin Yuan

Merge pull request #253 from yumin/discrete_error_checks

More error checks in discrete operations
parents 5d14f5ad efc9f34d
......@@ -59,10 +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)
{
entities.push_back(edge);
}
entities.push_back(edge);
}
edges->Delete();
vtkIdTypeArray* pointIdArray = vtkIdTypeArray::New();
......@@ -116,73 +113,71 @@ void vtkCMBModelWriterV5::SetModelEdgeData(vtkDiscreteModel* model, vtkPolyData*
void vtkCMBModelWriterV5::SetModelFaceData(vtkDiscreteModel* Model, vtkPolyData* Poly)
{
std::vector<vtkModelEntity*> Entities;
// if(Model->GetModelDimension() == 2)
{
// the adjacent edge ids for each model face is separated by a -1
vtkIdTypeArray* ModelFaceAdjacentEdgesId = vtkIdTypeArray::New();
vtkIntArray* ModelEdgeDirections = vtkIntArray::New();
// the adjacent edge ids for each model face is separated by a -1
vtkIdTypeArray* ModelFaceAdjacentEdgesId = vtkIdTypeArray::New();
vtkIntArray* ModelEdgeDirections = vtkIntArray::New();
vtkIdTypeArray* ModelFaceMaterialIds = vtkIdTypeArray::New();
vtkIdTypeArray* ModelFaceMaterialIds = vtkIdTypeArray::New();
vtkModelItemIterator* Faces = Model->NewIterator(vtkModelFaceType);
for(Faces->Begin();!Faces->IsAtEnd();Faces->Next())
vtkModelItemIterator* Faces = Model->NewIterator(vtkModelFaceType);
for(Faces->Begin();!Faces->IsAtEnd();Faces->Next())
{
vtkDiscreteModelFace* Face = vtkDiscreteModelFace::SafeDownCast(Faces->GetCurrentItem());
Entities.push_back(Face);
vtkModelMaterial* Material = Face->GetMaterial();
if(Material)
{
vtkDiscreteModelFace* Face = vtkDiscreteModelFace::SafeDownCast(Faces->GetCurrentItem());
Entities.push_back(Face);
vtkModelMaterial* Material = Face->GetMaterial();
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
// The ModelEdgeDirections has the same number of tuples as ModelFaceAdjacentEdgesId
// with -1 put in for nL and the -1 flag to indicate the end of a loop for
// the corresponding entry in ModelfaceAdjacentEdgesId. This is done as a
// safeguard to make sure we're reading ModelEdgeDirections properly.
vtkModelFaceUse* faceUse1 = Face->GetModelFaceUse(1);
int nLoops = faceUse1->GetNumberOfLoopUses();
ModelFaceAdjacentEdgesId->InsertNextValue(nLoops);
ModelEdgeDirections->InsertNextValue(-1);
if (nLoops != 0)
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
// The ModelEdgeDirections has the same number of tuples as ModelFaceAdjacentEdgesId
// with -1 put in for nL and the -1 flag to indicate the end of a loop for
// the corresponding entry in ModelfaceAdjacentEdgesId. This is done as a
// safeguard to make sure we're reading ModelEdgeDirections properly.
vtkModelFaceUse* faceUse1 = Face->GetModelFaceUse(1);
int nLoops = faceUse1->GetNumberOfLoopUses();
ModelFaceAdjacentEdgesId->InsertNextValue(nLoops);
ModelEdgeDirections->InsertNextValue(-1);
if (nLoops != 0)
{
vtkModelItemIterator *liter = faceUse1->NewLoopUseIterator();
vtkModelLoopUse* lu;
for (liter->Begin(); !liter->IsAtEnd(); liter->Next())
{
vtkModelItemIterator *liter = faceUse1->NewLoopUseIterator();
vtkModelLoopUse* lu;
for (liter->Begin(); !liter->IsAtEnd(); liter->Next())
lu = vtkModelLoopUse::SafeDownCast(liter->GetCurrentItem());
vtkModelItemIterator* EdgeUses = lu->NewModelEdgeUseIterator();
for(EdgeUses->Begin();!EdgeUses->IsAtEnd();EdgeUses->Next())
{
lu = vtkModelLoopUse::SafeDownCast(liter->GetCurrentItem());
vtkModelItemIterator* EdgeUses = lu->NewModelEdgeUseIterator();
for(EdgeUses->Begin();!EdgeUses->IsAtEnd();EdgeUses->Next())
{
vtkModelEdgeUse* EdgeUse = vtkModelEdgeUse::SafeDownCast(EdgeUses->GetCurrentItem());
ModelFaceAdjacentEdgesId->InsertNextValue(
EdgeUse->GetModelEdge()->GetUniquePersistentId());
ModelEdgeDirections->InsertNextValue(EdgeUse->GetDirection());
}
ModelFaceAdjacentEdgesId->InsertNextValue(-1);
ModelEdgeDirections->InsertNextValue(-1);
EdgeUses->Delete();
vtkModelEdgeUse* EdgeUse = vtkModelEdgeUse::SafeDownCast(EdgeUses->GetCurrentItem());
ModelFaceAdjacentEdgesId->InsertNextValue(
EdgeUse->GetModelEdge()->GetUniquePersistentId());
ModelEdgeDirections->InsertNextValue(EdgeUse->GetDirection());
}
liter->Delete();
ModelFaceAdjacentEdgesId->InsertNextValue(-1);
ModelEdgeDirections->InsertNextValue(-1);
EdgeUses->Delete();
}
liter->Delete();
}
Faces->Delete();
}
Faces->Delete();
ModelFaceAdjacentEdgesId->SetName(ModelParserHelper::GetModelFaceEdgesString());
Poly->GetFieldData()->AddArray(ModelFaceAdjacentEdgesId);
ModelFaceAdjacentEdgesId->Delete();
ModelFaceAdjacentEdgesId->SetName(ModelParserHelper::GetModelFaceEdgesString());
Poly->GetFieldData()->AddArray(ModelFaceAdjacentEdgesId);
ModelFaceAdjacentEdgesId->Delete();
ModelEdgeDirections->SetName(ModelParserHelper::GetModelEdgeDirectionsString());
Poly->GetFieldData()->AddArray(ModelEdgeDirections);
ModelEdgeDirections->Delete();
if(ModelFaceMaterialIds->GetNumberOfTuples())
{
ModelFaceMaterialIds->SetName(ModelParserHelper::GetFaceMaterialIdString());
Poly->GetFieldData()->AddArray(ModelFaceMaterialIds);
}
ModelFaceMaterialIds->Delete();
ModelEdgeDirections->SetName(ModelParserHelper::GetModelEdgeDirectionsString());
Poly->GetFieldData()->AddArray(ModelEdgeDirections);
ModelEdgeDirections->Delete();
if(ModelFaceMaterialIds->GetNumberOfTuples())
{
ModelFaceMaterialIds->SetName(ModelParserHelper::GetFaceMaterialIdString());
Poly->GetFieldData()->AddArray(ModelFaceMaterialIds);
}
ModelFaceMaterialIds->Delete();
if(Model->GetModelDimension() == 3)
{
vtkIdTypeArray* ModelFaceAdjacentRegionsId = vtkIdTypeArray::New();
......@@ -192,7 +187,6 @@ void vtkCMBModelWriterV5::SetModelFaceData(vtkDiscreteModel* Model, vtkPolyData*
for(Faces->Begin();!Faces->IsAtEnd();Faces->Next())
{
vtkDiscreteModelFace* Face = vtkDiscreteModelFace::SafeDownCast(Faces->GetCurrentItem());
// Entities.push_back(Face);
vtkIdType ids[2] = {-1, -1};
for(int j=0;j<2;j++)
{
......
......@@ -255,7 +255,7 @@ bool vtkCMBParserV5::Parse(vtkPolyData* MasterPoly, vtkDiscreteModel* Model,
}
}
if(EdgesOfModelFace && EdgesOfModelFace->GetNumberOfTuples() > 0)
if(EdgesOfModelFace && ArrayCounter < EdgesOfModelFace->GetNumberOfTuples())
{ // a model face in a 2D model
// First get the number of loops
int nLoops = EdgesOfModelFace->GetValue(ArrayCounter++);
......
......@@ -41,13 +41,35 @@ CreateEdgesOperator::CreateEdgesOperator()
bool CreateEdgesOperator::ableToOperate()
{
smtk::model::Model model;
return
// The SMTK model must be valid
(model = this->specification()->findModelEntity("model")->value().as<smtk::model::Model>()).isValid() &&
// The CMB model must exist:
this->discreteSession()->findModelEntity(model.entity())
;
smtk::model::Model model = this->specification()->findModelEntity(
"model")->value().as<smtk::model::Model>();
if(!model.isValid())
{
return false;
}
vtkDiscreteModelWrapper* modelWrapper =
this->discreteSession()->findModelEntity(model.entity());
if(!modelWrapper)
{
return false;
}
bool operable = true;
// verify that faces in the model do not have edges already.
vtkModelItemIterator* iter = modelWrapper->GetModel()->NewIterator(vtkModelFaceType);
for(iter->Begin();!iter->IsAtEnd();iter->Next())
{
vtkModelFace* face =
vtkModelFace::SafeDownCast(iter->GetCurrentItem());
if(face && face->GetNumberOfModelEdges() > 0)
{
operable = false;
break;
}
}
iter->Delete();
return operable;
}
OperatorResult CreateEdgesOperator::operateInternal()
......
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