Skip to content

Commit

Permalink
Add convenience methods addVertex/prependVertex taking Vertex3d (open…
Browse files Browse the repository at this point in the history
  • Loading branch information
kintel authored Jan 13, 2024
1 parent bf0dddc commit ffafe74
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 25 deletions.
8 changes: 4 additions & 4 deletions src/core/SurfaceNode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,13 @@ std::unique_ptr<const Geometry> SurfaceNode::createGeometry() const
if (columns > 1 && lines > 1) {
builder.appendPoly(2 * (columns - 1) + 2 * (lines - 1) );
for (int i = 0; i < columns - 1; ++i)
builder.prependVertex(builder.vertexIndex(Vector3d(ox + i, oy + 0, min_val)));
builder.prependVertex(Vector3d(ox + i, oy + 0, min_val));
for (int i = 0; i < lines - 1; ++i)
builder.prependVertex(builder.vertexIndex(Vector3d(ox + columns - 1, oy + i, min_val)));
builder.prependVertex(Vector3d(ox + columns - 1, oy + i, min_val));
for (int i = columns - 1; i > 0; i--)
builder.prependVertex(builder.vertexIndex(Vector3d(ox + i, oy + lines - 1, min_val)));
builder.prependVertex(Vector3d(ox + i, oy + lines - 1, min_val));
for (int i = lines - 1; i > 0; i--)
builder.prependVertex(builder.vertexIndex(Vector3d(ox + 0, oy + i, min_val)));
builder.prependVertex(Vector3d(ox + 0, oy + i, min_val));
}

return builder.build();
Expand Down
10 changes: 5 additions & 5 deletions src/core/primitives.cc
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ std::unique_ptr<const Geometry> SphereNode::createGeometry() const

builder.appendPoly(fragments);
for (int i = 0; i < fragments; ++i)
builder.appendVertex(builder.vertexIndex(Vector3d(ring[0].points[i][0], ring[0].points[i][1], ring[0].z)));
builder.appendVertex(Vector3d(ring[0].points[i][0], ring[0].points[i][1], ring[0].z));

for (int i = 0; i < rings - 1; ++i) {
auto r1 = &ring[i];
Expand Down Expand Up @@ -247,7 +247,7 @@ std::unique_ptr<const Geometry> SphereNode::createGeometry() const

builder.appendPoly(fragments);
for (int i = 0; i < fragments; ++i) {
builder.prependVertex( builder.vertexIndex(Vector3d(ring[rings - 1].points[i][0], ring[rings - 1].points[i][1], ring[rings - 1].z)));
builder.prependVertex(Vector3d(ring[rings - 1].points[i][0], ring[rings - 1].points[i][1], ring[rings - 1].z));
}

return builder.build();
Expand Down Expand Up @@ -314,7 +314,7 @@ std::unique_ptr<const Geometry> CylinderNode::createGeometry() const
if (r1 == r2) {
builder.appendPoly(4);
for(int k=0;k<4;k++)
builder.prependVertex(builder.vertexIndex(Vector3d(circle1[k&2?j:i][0], circle1[k&2?j:i][1], (k+1)&2?z2:z1)));
builder.prependVertex(Vector3d(circle1[k&2?j:i][0], circle1[k&2?j:i][1], (k+1)&2?z2:z1));
} else {
if (r1 > 0) {
builder.appendPoly({
Expand All @@ -336,13 +336,13 @@ std::unique_ptr<const Geometry> CylinderNode::createGeometry() const
if (this->r1 > 0) {
builder.appendPoly(fragments);
for (int i = 0; i < fragments; ++i)
builder.prependVertex(builder.vertexIndex(Vector3d(circle1[i][0], circle1[i][1], z1)));
builder.prependVertex(Vector3d(circle1[i][0], circle1[i][1], z1));
}

if (this->r2 > 0) {
builder.appendPoly(fragments);
for (int i = 0; i < fragments; ++i)
builder.appendVertex(builder.vertexIndex(Vector3d(circle2[i][0], circle2[i][1], z2)));
builder.appendVertex(Vector3d(circle2[i][0], circle2[i][1], z2));
}

return builder.build();
Expand Down
10 changes: 10 additions & 0 deletions src/geometry/PolySetBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,21 @@ void PolySetBuilder::appendVertex(int ind)
indices_.back().push_back(ind);
}

void PolySetBuilder::appendVertex(const Vector3d &v)
{
appendVertex(vertexIndex(v));
}

void PolySetBuilder::prependVertex(int ind)
{
indices_.back().insert(indices_.back().begin(), ind);
}

void PolySetBuilder::prependVertex(const Vector3d &v)
{
prependVertex(vertexIndex(v));
}

void PolySetBuilder::append(const PolySet& ps)
{
for (const auto& poly : ps.indices) {
Expand Down
2 changes: 2 additions & 0 deletions src/geometry/PolySetBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ class PolySetBuilder
void appendGeometry(const std::shared_ptr<const Geometry>& geom);
void appendPoly(const std::vector<Vector3d>& v);
void appendVertex(int n);
void appendVertex(const Vector3d &v);
void prependVertex(int n);
void prependVertex(const Vector3d &v);
std::unique_ptr<PolySet> build();
private:
Reindexer<Vector3d> vertices_;
Expand Down
2 changes: 1 addition & 1 deletion src/geometry/cgal/Polygon2d-CGAL.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ std::unique_ptr<PolySet> Polygon2d::tessellate() const
if (fit->info().in_domain()) {
builder.appendPoly(3);
for (int i = 0; i < 3; ++i) {
builder.appendVertex(builder.vertexIndex(Vector3d(fit->vertex(i)->point()[0], fit->vertex(i)->point()[1], 0)));
builder.appendVertex(Vector3d(fit->vertex(i)->point()[0], fit->vertex(i)->point()[1], 0));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/geometry/cgal/cgalutils-mesh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ std::unique_ptr<PolySet> createPolySetFromMesh(const TriangleMesh& mesh)
double x = CGAL::to_double(v.x());
double y = CGAL::to_double(v.y());
double z = CGAL::to_double(v.z());
builder.appendVertex(builder.vertexIndex(Vector3d(x, y, z)));
builder.appendVertex(Vector3d(x, y, z));
}
}
return builder.build();
Expand Down
2 changes: 1 addition & 1 deletion src/geometry/cgal/cgalutils-polyhedron.cc
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ std::unique_ptr<PolySet> createPolySetFromPolyhedron(const Polyhedron& p)
double x = CGAL::to_double(v.point().x());
double y = CGAL::to_double(v.point().y());
double z = CGAL::to_double(v.point().z());
builder.appendVertex(builder.vertexIndex(Vector3d(x, y, z)));
builder.appendVertex(Vector3d(x, y, z));
} while (hc != hc_end);
}
return builder.build();
Expand Down
16 changes: 8 additions & 8 deletions src/geometry/cgal/cgalutils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,12 @@ std::unique_ptr<PolySet> createPolySetFromNefPolyhedron3(const CGAL::Nef_polyhed

PolySetBuilder builder(verts.size(),allTriangles.size());
std::vector<int> indMap;
for(int i=0;i<verts.size();i++)
indMap.push_back(builder.vertexIndex({verts[i][0],verts[i][1],verts[i][2]}));

for(int i=0;i<allTriangles.size();i++) {
const auto &tri=allTriangles[i];
builder.appendPoly({indMap[tri[0]],indMap[tri[1]],indMap[tri[2]]});
indMap.reserve(verts.size());
for (const auto &v : verts) {
indMap.push_back(builder.vertexIndex({v[0], v[1], v[2]}));
}
for (const auto& tri : allTriangles) {
builder.appendPoly({indMap[tri[0]], indMap[tri[1]], indMap[tri[2]]});
}

#if 0 // For debugging
Expand Down Expand Up @@ -492,8 +492,8 @@ std::shared_ptr<const PolySet> getGeometryAsPolySet(const std::shared_ptr<const
auto ps = std::make_shared<PolySet>(3);
if (!N->isEmpty()) {
if (auto ps = CGALUtils::createPolySetFromNefPolyhedron3(*N->p3)) {
ps->setConvexity(N->getConvexity());
return ps;
ps->setConvexity(N->getConvexity());
return ps;
}
LOG(message_group::Error, "Nef->PolySet failed.");
}
Expand Down
2 changes: 1 addition & 1 deletion src/geometry/roof_vd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ std::unique_ptr<PolySet> voronoi_diagram_roof(const Polygon2d& poly, double fa,
for (const IndexedFace& triangle : tess->indices) {
std::vector<int> roof;
for (int tvind : triangle) {
Vector3d tv=tess->vertices[tvind];
Vector3d tv=tess->vertices[tvind];
Vector2d v;
v << tv[0], tv[1];
if (!(inner_faces.heights.find(v) != inner_faces.heights.end())) {
Expand Down
4 changes: 2 additions & 2 deletions src/io/import_3mf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ std::unique_ptr<Geometry> import_3mf(const std::string& filename, const Location
if (lib3mf_meshobject_getvertex(object, triangle.m_nIndices[i], &vertex) != LIB3MF_OK) {
return import_3mf_error(model, object_it);
}
builder.appendVertex(builder.vertexIndex(Vector3d(vertex.m_fPosition[0], vertex.m_fPosition[1], vertex.m_fPosition[2])));
builder.appendVertex(Vector3d(vertex.m_fPosition[0], vertex.m_fPosition[1], vertex.m_fPosition[2]));
}
}

Expand Down Expand Up @@ -316,7 +316,7 @@ std::unique_ptr<Geometry> import_3mf(const std::string& filename, const Location

for(int i=0;i<3;i++) {
Lib3MF::sPosition vertex = object->GetVertex(triangle.m_Indices[i]);
builder.appendVertex(builder.vertexIndex(Vector3d(vertex.m_Coordinates[0], vertex.m_Coordinates[1], vertex.m_Coordinates[2])));
builder.appendVertex(Vector3d(vertex.m_Coordinates[0], vertex.m_Coordinates[1], vertex.m_Coordinates[2]));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/io/import_amf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void AmfImporter::end_triangle(AmfImporter *importer, const xmlChar *)

importer->builder->appendPoly(3);
for(int i=0;i<3;i++) // TODO set vertex array first
importer->builder->appendVertex(importer->builder->vertexIndex(Vector3d(v[idx[i]].x(), v[idx[i]].y(), v[idx[i]].z())));
importer->builder->appendVertex(Vector3d(v[idx[i]].x(), v[idx[i]].y(), v[idx[i]].z()));
}

void AmfImporter::processNode(xmlTextReaderPtr reader)
Expand Down
2 changes: 1 addition & 1 deletion src/io/import_stl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ std::unique_ptr<PolySet> import_stl(const std::string& filename, const Location&
if (++i == 3) {
builder.appendPoly(3);
for(int j=0;j<3;j++)
builder.appendVertex(builder.vertexIndex(Vector3d(vdata[j][0], vdata[j][1], vdata[j][2])));
builder.appendVertex(Vector3d(vdata[j][0], vdata[j][1], vdata[j][2]));
}
} catch (const boost::bad_lexical_cast& blc) {
AsciiError("can't parse vertex");
Expand Down

0 comments on commit ffafe74

Please sign in to comment.