Commit c4bbb0fc authored by Yumin Yuan's avatar Yumin Yuan Committed by David Thompson
Browse files

Parsing inner loop info from input while creating faces

parent 78f3a796
......@@ -36,7 +36,9 @@
#include "smtk/bridge/polygon/Import_xml.h"
#include "vtkCellArray.h"
#include "vtkCellData.h"
#include "vtkDataSetSurfaceFilter.h"
#include "vtkIdTypeArray.h"
#include "vtkNew.h"
#include "vtkPDataSetReader.h"
#include "vtkPolyData.h"
......@@ -54,44 +56,116 @@ namespace smtk {
//----------------------------------------------------------------------------
int polyLines2modelEdges(vtkPolyData *mesh,
smtk::model::Operator::Ptr edgeOp,
smtk::model::EntityRefArray& createdEds,
smtk::attribute::DoubleItem::Ptr pointsItem,
vtkIdType *pts, vtkIdType npts,
smtk::io::Logger& logger)
{
double p[3];
// create edge for current line cell
std::vector<double> ptscoords;
for (vtkIdType j=0; j < npts; ++j)
{
mesh->GetPoint(pts[j],p);
ptscoords.insert(ptscoords.end(), &p[0], p+3);
}
pointsItem->setValues(ptscoords.begin(), ptscoords.end());
OperatorResult edgeResult = edgeOp->operate();
if (edgeResult->findInt("outcome")->value() != OPERATION_SUCCEEDED)
{
smtkDebugMacro(logger, "\"create edge\" op failed to creat edge with given line cells.");
return 0;
}
smtk::attribute::ModelEntityItem::Ptr newEdges = edgeResult->findModelEntity("created");
createdEds.insert(createdEds.end(), newEdges->begin(), newEdges->end());
return newEdges->numberOfValues();
}
//----------------------------------------------------------------------------
int polyLines2modelEdgesAndFaces(vtkPolyData *mesh,
smtk::model::Model& model,
smtk::bridge::polygon::Session* sess)
smtk::bridge::polygon::Session* sess,
smtk::io::Logger& logger)
{
int numEdges = 0;
vtkCellArray *lines = mesh->GetLines();
double p[3];
if (lines)
{
smtk::model::Operator::Ptr edgeOp = sess->op("create edge");
smtk::attribute::AttributePtr spec = edgeOp->specification();
spec->associateEntity(model);
smtk::attribute::IntItem::Ptr constructMethod = spec->findInt("construction method");
constructMethod->setValue(0); // "points coornidates"
constructMethod->setDiscreteIndex(0); // "points coornidates"
smtk::attribute::IntItem::Ptr numCoords = spec->findInt("coordinates");
numCoords->setValue(3); // number of elements in coordinates
smtk::attribute::DoubleItem::Ptr pointsItem = spec->findDouble("points");
smtk::model::Operator::Ptr faceOp = sess->op("force create face");
smtk::attribute::AttributePtr faceSpec = faceOp->specification();
faceSpec->findInt("construction method")->setDiscreteIndex(1); // "edges"
vtkIdTypeArray* pedigreeIds = vtkIdTypeArray::SafeDownCast(
mesh->GetCellData()->GetPedigreeIds());
vtkIdType numPedIDs = pedigreeIds ? pedigreeIds->GetNumberOfTuples() : 0;
vtkIdType* pedigree = numPedIDs == lines->GetNumberOfCells() ?
pedigreeIds->GetPointer(0) : NULL;
/*
std::cout << "number of line cells: " << lines->GetNumberOfCells() << std::endl;
if(pedigreeIds)
{
std::cout << "number of pedigreeIds: " << numPedIDs << std::endl;
}
*/
vtkIdType pidx = 0;
vtkIdType *pts,npts;
for (lines->SetTraversalLocation(0);lines->GetNextCell(npts,pts);)
for (lines->SetTraversalLocation(0);lines->GetNextCell(npts,pts); ++pidx)
{
std::vector<double> ptscoords;
for (vtkIdType j=0; j < npts; ++j)
smtk::model::EntityRefArray createdEds;
// create edge for current line cell
int numNewEdges = polyLines2modelEdges(mesh, edgeOp, createdEds, pointsItem,
pts, npts, logger);
// peek at next pedigree id if possible, to see if the pedId is the same, if yes,
// the next cell is the inner loop
if (pedigree && numNewEdges > 0)
{
mesh->GetPoint(pts[j],p);
ptscoords.insert(ptscoords.end(), &p[0], p+3);
vtkIdType pedId = pedigree[pidx];
// std::cout << "pedid: " << pedId << std::endl;
while(pidx < numPedIDs - 1 && pedId == pedigree[pidx + 1])
{
// The next line cell is an inner loop
if(lines->GetNextCell(npts,pts))
{
numNewEdges += polyLines2modelEdges(mesh, edgeOp, createdEds, pointsItem,
pts, npts, logger);
}
// std::cout << "inner pedid: " << pedId << std::endl;
++pidx;
}
}
pointsItem->setValues(ptscoords.begin(), ptscoords.end());
OperatorResult edgeResult = edgeOp->operate();
if (edgeResult->findInt("outcome")->value() == OPERATION_SUCCEEDED)
if (numNewEdges > 0)
{
numEdges += edgeResult->findModelEntity("created")->numberOfValues();
numEdges += numNewEdges;
faceSpec->associations()->setValues(createdEds.begin(), createdEds.end());
// std::cout << "number of created new edges: " << createdEds.size() << std::endl;
smtk::attribute::IntItem::Ptr orientArr = faceSpec->findInt("orientations");
std::vector<int> orients (numNewEdges, -1);
//orients[0] = 1; // first one is outer loop
orientArr->setValues(orients.begin(), orients.end());
OperatorResult faceResult = faceOp->operate();
if (faceResult->findInt("outcome")->value() != OPERATION_SUCCEEDED)
{
smtkDebugMacro(logger, "\"force create face\" op failed to creat face with given edges.");
}
}
}
}
return numEdges;
}
Import::Import()
{
}
......@@ -307,8 +381,8 @@ OperatorResult Import::operateInternal()
result = this->createResult(OPERATION_FAILED);
}
smtk::model::Model model = modResult->findModelEntity("created")->value();
int numEdges = polyLines2modelEdges(polyOutput, model, sess);
std::cout << "Number of edges: " << numEdges << "\n";
int numEdges = polyLines2modelEdgesAndFaces(polyOutput, model, sess, log());
smtkDebugMacro(log(), "Number of edges: " << numEdges << "\n");
result = this->createResult(OPERATION_SUCCEEDED);
this->addEntityToResult(result, model, CREATED);
......
......@@ -176,11 +176,12 @@ int vtkCMBPolygonModelImporter::RequestData(
vtkNew<vtkTableWriter> twr;
*/
rdr->SetFileName(fileNameStr.c_str());
//rdr->AddFeatureIdsOn();
rdr->AddFeatureIdsOn();
rdr->SetAppendFeatures(1);
rdr->Update();
cln->SetInputConnection(rdr->GetOutputPort());
// cln->PointMergingOn();
cln->Update();
vtkMultiBlockDataSet* mbds =
vtkMultiBlockDataSet::SafeDownCast(
......
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