Commit 75041364 authored by T.J. Corona's avatar T.J. Corona
Browse files

Delaunay: use model tessellation for input.

parent 1757f2d2
......@@ -16,6 +16,10 @@
#include "smtk/mesh/ExtractTessellation.h"
#include "smtk/mesh/MeshSet.h"
#include "smtk/model/Edge.h"
#include "smtk/model/EdgeUse.h"
#include "smtk/model/Loop.h"
#include "Shape/Point.hh"
namespace smtk {
......@@ -23,8 +27,60 @@ namespace extension {
namespace delaunay {
namespace io {
std::vector<Delaunay::Shape::Point> ExportDelaunayMesh::operator()
(const smtk::model::Loop& loop, smtk::mesh::CollectionPtr& collection) const
std::vector<Delaunay::Shape::Point> ExportDelaunayMesh::operator()(
const smtk::model::Loop& loop) const
{
std::vector<Delaunay::Shape::Point> points;
// We collect the points for each edge and insert them at once into our
// points vector. This allows us to properly account for the edge use
// orientation while using smtk::model::Tessellation's forward iterator to
// loop through tessellation cells.
std::vector<Delaunay::Shape::Point> pointsForEdge;
for (auto& eu : loop.edgeUses())
{
const smtk::model::Tessellation* tess = eu.edge().hasTessellation();
std::vector<int> cell_conn;
smtk::model::Tessellation::size_type start_off;
std::vector<std::size_t> numCellsOfType(smtk::mesh::CellType_MAX, 0);
for (start_off = tess->begin();
start_off != tess->end();
start_off = tess->nextCellOffset(start_off))
{
tess->vertexIdsOfCell(start_off, cell_conn);
for (std::size_t j = 0; j < cell_conn.size() - 1; j++)
{
pointsForEdge.push_back(
Delaunay::Shape::Point(tess->coords()[cell_conn[j]*3 + 0],
tess->coords()[cell_conn[j]*3 + 1]));
}
cell_conn.clear();
}
// We transplant the edge's points into the global point vector according to
// the edge use's orientation.
if (eu.orientation() == 1)
{
points.insert(points.end(), pointsForEdge.begin(), pointsForEdge.end());
}
else
{
points.insert(points.end(), pointsForEdge.rbegin(), pointsForEdge.rend());
}
pointsForEdge.clear();
}
// Delaunay polygons do not use a repeated point to denote a loop.
if (points.front() == points.back())
{
points.pop_back();
}
return points;
}
std::vector<Delaunay::Shape::Point> ExportDelaunayMesh::operator()(
const smtk::model::Loop& loop, smtk::mesh::CollectionPtr& collection) const
{
std::int64_t connectivityLength= -1;
std::int64_t numberOfCells = -1;
......@@ -50,7 +106,8 @@ std::vector<Delaunay::Shape::Point> ExportDelaunayMesh::operator()
{
points.push_back(Delaunay::Shape::Point(fpoints[i], fpoints[i+1]));
}
// loops sometimes have a redundant point at the end. We need to remove it.
// Delaunay polygons do not use a repeated point to denote a loop.
if (points.front() == points.back())
{
points.pop_back();
......
......@@ -43,9 +43,12 @@ public:
ExportDelaunayMesh(const ExportDelaunayMesh&) = delete;
ExportDelaunayMesh& operator=(const ExportDelaunayMesh&) = delete;
//Export a model loop with a mesh representation (likely constructed from
// smtk::io::modelToMesh) stored in the collection into a vector of Delaunay
// points.
//Export a model loop with a tessellation into a vector of Delaunay points.
std::vector<Delaunay::Shape::Point> operator()(
const smtk::model::Loop&) const;
//Export a model loop with a mesh representation stored in the given
// collection into a vector of Delaunay points.
std::vector<Delaunay::Shape::Point> operator()(
const smtk::model::Loop&, smtk::mesh::CollectionPtr&) const;
......
......@@ -14,13 +14,9 @@
#include "smtk/extension/delaunay/io/ImportDelaunayMesh.h"
#include "smtk/extension/delaunay/io/ExportDelaunayMesh.h"
#include "smtk/io/ModelToMesh.h"
#include "smtk/mesh/Collection.h"
#include "smtk/mesh/ExtractTessellation.h"
#include "smtk/mesh/Manager.h"
#include "smtk/model/Edge.h"
#include "smtk/model/Face.h"
#include "smtk/model/FaceUse.h"
#include "smtk/model/Loop.h"
......@@ -59,11 +55,6 @@ OperatorResult TessellateFace::operateInternal()
this->specification()->findModelEntity("face")->
value().as<smtk::model::Face>();
smtk::io::ModelToMesh convert;
convert.setIsMerging(false);
smtk::mesh::CollectionPtr collection = convert(this->session()->meshManager(),
this->session()->manager());
// get the face use for the face
smtk::model::FaceUse fu = face.positiveUse();
......@@ -82,7 +73,8 @@ OperatorResult TessellateFace::operateInternal()
// make a polygon from the points in the loop
smtk::extension::delaunay::io::ExportDelaunayMesh exportToDelaunayMesh;
std::vector<Delaunay::Shape::Point> points =
exportToDelaunayMesh(exteriorLoop, collection);
exportToDelaunayMesh(exteriorLoop);
Delaunay::Shape::Polygon p(points);
// if the orientation is not ccw, flip the orientation
if (Delaunay::Shape::Orientation(p) != 1)
......@@ -100,7 +92,7 @@ OperatorResult TessellateFace::operateInternal()
for (auto& loop : exteriorLoop.containedLoops())
{
std::vector<Delaunay::Shape::Point> points_sub =
exportToDelaunayMesh(loop, collection);
exportToDelaunayMesh(loop);
Delaunay::Shape::Polygon p_sub(points_sub);
// if the orientation is not ccw, flip the orientation
if (Delaunay::Shape::Orientation(p_sub) != 1)
......@@ -110,9 +102,6 @@ OperatorResult TessellateFace::operateInternal()
excise(p_sub, mesh);
}
// remove the original collection
this->session()->meshManager()->removeCollection(collection);
// Use the delaunay mesh to retessellate the face
smtk::extension::delaunay::io::ImportDelaunayMesh importFromDelaunayMesh;
importFromDelaunayMesh(mesh, face);
......
......@@ -14,13 +14,9 @@
#include "smtk/extension/delaunay/io/ImportDelaunayMesh.h"
#include "smtk/extension/delaunay/io/ExportDelaunayMesh.h"
#include "smtk/io/ModelToMesh.h"
#include "smtk/mesh/Collection.h"
#include "smtk/mesh/ExtractTessellation.h"
#include "smtk/mesh/Manager.h"
#include "smtk/model/Edge.h"
#include "smtk/model/Face.h"
#include "smtk/model/FaceUse.h"
#include "smtk/model/Loop.h"
......@@ -59,11 +55,6 @@ OperatorResult TriangulateFace::operateInternal()
this->specification()->findModelEntity("face")->
value().as<smtk::model::Face>();
smtk::io::ModelToMesh convert;
convert.setIsMerging(false);
smtk::mesh::CollectionPtr collection = convert(this->session()->meshManager(),
this->session()->manager());
// get the face use for the face
smtk::model::FaceUse fu = face.positiveUse();
......@@ -82,7 +73,8 @@ OperatorResult TriangulateFace::operateInternal()
// make a polygon from the points in the loop
smtk::extension::delaunay::io::ExportDelaunayMesh exportToDelaunayMesh;
std::vector<Delaunay::Shape::Point> points =
exportToDelaunayMesh(exteriorLoop, collection);
exportToDelaunayMesh(exteriorLoop);
Delaunay::Shape::Polygon p(points);
// if the orientation is not ccw, flip the orientation
if (Delaunay::Shape::Orientation(p) != 1)
......@@ -100,7 +92,7 @@ OperatorResult TriangulateFace::operateInternal()
for (auto& loop : exteriorLoop.containedLoops())
{
std::vector<Delaunay::Shape::Point> points_sub =
exportToDelaunayMesh(loop, collection);
exportToDelaunayMesh(loop);
Delaunay::Shape::Polygon p_sub(points_sub);
// if the orientation is not ccw, flip the orientation
if (Delaunay::Shape::Orientation(p_sub) != 1)
......@@ -112,9 +104,8 @@ OperatorResult TriangulateFace::operateInternal()
// remove the original collection and grab the collection with the same id as
// the model
this->session()->meshManager()->removeCollection(collection);
collection = this->session()->meshManager()->collection(
face.model().entity());
smtk::mesh::CollectionPtr collection =
this->session()->meshManager()->collection(face.model().entity());
if (!collection)
{
// If we can't find this collection, we can create it
......
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