27#include <easy3d/viewer/viewer.h>
28#include <easy3d/renderer/camera.h>
29#include <easy3d/core/surface_mesh.h>
30#include <easy3d/renderer/drawable_points.h>
31#include <easy3d/renderer/drawable_lines.h>
32#include <easy3d/renderer/renderer.h>
33#include <easy3d/algo/tessellator.h>
34#include <easy3d/util/initializer.h>
47typedef std::vector<vec3> Hole;
59 for (
auto f : mesh->
faces()) {
62 tessellator.set_winding_rule(Tessellator::WINDING_NONZERO);
63 tessellator.begin_contour();
68 tessellator.end_contour();
70 if (holes && holes[f].size() >= 3) {
71 tessellator.set_winding_rule(Tessellator::WINDING_ODD);
72 tessellator.begin_contour();
73 for (
const auto& p : holes[f])
74 tessellator.add_vertex(p);
75 tessellator.end_contour();
78 tessellator.end_polygon();
86 const auto& triangles = tessellator.elements();
87 if (triangles.empty())
90 const auto &vts = tessellator.vertices();
94 for (
const auto &t: triangles) {
104int main(
int argc,
char **argv) {
110 Viewer viewer(EXAMPLE_TITLE);
111 viewer.camera()->setUpVector(
vec3(0, 1, 0));
112 viewer.camera()->setViewDirection(
vec3(0, 0, -1));
120 auto v1 = mesh->add_vertex(
vec3(800, 0, 0));
121 auto v2 = mesh->add_vertex(
vec3(800, 800, 0));
122 auto v3 = mesh->add_vertex(
vec3(600, 300, 0));
123 mesh->add_quad(v0, v1, v2, v3);
128 mesh->add_vertex(
vec3(1500, 0, 0)),
129 mesh->add_vertex(
vec3(1300, 800, 0)),
130 mesh->add_vertex(
vec3(1100, 0, 0)),
131 mesh->add_vertex(
vec3(1700, 500, 0)),
132 mesh->add_vertex(
vec3(900, 500, 0))
134 mesh->add_face(vertices);
139 mesh->add_vertex(
vec3(1800, 0, 0)),
140 mesh->add_vertex(
vec3(2200, 0, 0)),
141 mesh->add_vertex(
vec3(2200, 700, 0)),
142 mesh->add_vertex(
vec3(1800, 700, 0))
144 auto f = mesh->add_face(vertices);
147 auto holes = mesh->add_face_property<Hole>(
"f:holes");
163 viewer.add_model(mesh,
true);
166 mesh->renderer()->get_points_drawable(
"vertices")->set_visible(
true);
167 mesh->renderer()->get_points_drawable(
"vertices")->set_impostor_type(easy3d::PointsDrawable::SPHERE);
168 mesh->renderer()->get_points_drawable(
"vertices")->set_point_size(12);
170 mesh->renderer()->get_lines_drawable(
"edges")->set_visible(
true);
172 mesh->renderer()->get_lines_drawable(
"borders")->set_visible(
true);
int idx() const
Get the underlying index of this handle.
Definition: surface_mesh.h:67
A halfedge data structure for polygonal meshes of 2-manifold.
Definition: surface_mesh.h:52
const vec3 & position(Vertex v) const
position of a vertex (read only)
Definition: surface_mesh.h:1928
FaceProperty< T > get_face_property(const std::string &name) const
Definition: surface_mesh.h:1435
FaceContainer faces() const
returns face container for C++11 range-based for-loops
Definition: surface_mesh.h:1685
void update_face_normals()
compute face normals by calling compute_face_normal(Face) for each face.
Definition: surface_mesh.cpp:1011
Vertex target(Halfedge h) const
returns the vertex the halfedge h points to
Definition: surface_mesh.h:1211
HalfedgeContainer halfedges() const
returns halfedge container for C++11 range-based for-loops
Definition: surface_mesh.h:1649
FaceProperty< T > face_property(const std::string &name, const T t=T())
Definition: surface_mesh.h:1475
Face add_triangle(Vertex v1, Vertex v2, Vertex v3)
Definition: surface_mesh.cpp:491
Vertex add_vertex(const vec3 &p)
add a new vertex with position p
Definition: surface_mesh.h:1034
void clear()
Removes all vertices, edges, faces, and properties (and resets garbage state).
Definition: surface_mesh.cpp:302
Tessellator subdivides concave planar polygons, polygons with holes, or polygons with intersecting ed...
Definition: tessellator.h:56
void begin_polygon(const vec3 &normal)
Begin the tessellation of a complex polygon.
Definition: tessellator.cpp:143
The built-in Easy3D viewer.
Definition: viewer.h:61
Definition: collider.cpp:182
void initialize(bool use_log_file, bool use_setting_file, const std::string &resource_dir)
Initialization of Easy3D.
Definition: initializer.cpp:35
Definition: surface_mesh.h:104