Giter Site home page Giter Site logo

Comments (9)

pentacular avatar pentacular commented on June 14, 2024

Use CGAL::Polygon_triangulation_decomposition_2 to produce triangles, use Plane_3 to_3d to produce faces, and add_face on the Surface_mesh.

from cgal.

pentacular avatar pentacular commented on June 14, 2024

Ah, but it might be faster to just write a function to print a Polygon_with_holes_2 in obj format, as that is very simple.

from cgal.

BeginCGAL avatar BeginCGAL commented on June 14, 2024

I am a beginner,could you please write a demo (i could't find the demo about Polygon_triangulation_decomposition_2 )? thank you

from cgal.

pentacular avatar pentacular commented on June 14, 2024

Perhaps something like this:

bool PolygonsWithHolesToSurfaceMesh(const Plane& plane,
                                    std::vector<Polygon_with_holes_2>& polygons,
                                    Surface_mesh& result,
                                    Vertex_map& vertex_map, bool flip = false) {
  CGAL::Polygon_triangulation_decomposition_2<Kernel> triangulator;
  for (const Polygon_with_holes_2& polygon : polygons) {
    std::vector<Polygon_2> facets;
    triangulator(polygon, std::back_inserter(facets));
    for (auto& facet : facets) {
      if (facet.orientation() != CGAL::Sign::POSITIVE) {
        facet.reverse_orientation();
      }
      std::vector<Vertex_index> vertices;
      for (const auto& point : facet) {
        vertices.push_back(
            ensureVertex(result, vertex_map, plane.to_3d(point)));
      }
      if (flip) {
        std::reverse(vertices.begin(), vertices.end());
      }
      if (result.add_face(vertices) == Surface_mesh::null_face()) {
        return false;
      }
    }   
  }     
  return true;
} 

But I think you're still going about this the wrong way.

Generating an OBJ file from a Polygon_with_holes_2 should be simpler. :)

from cgal.

BeginCGAL avatar BeginCGAL commented on June 14, 2024

thank you, by the way could you tell me the simpler way Generating an OBJ file from a Polygon_with_holes_2?

from cgal.

pentacular avatar pentacular commented on June 14, 2024
v  0  0  0
v  1  0  0
v  1  1  0
v  0  1  0
v  0.5  0.5  1.6

f  5  2  3
f  4  5  3
f  6  3  2
f  5  6  2
f  4  6  5
f  6  4  3

Just write out the vertices (v) and the faces (f).

You'll still need to do the triangular decomposition since obj doesn't handle holes, but it's very simple.

from cgal.

BeginCGAL avatar BeginCGAL commented on June 14, 2024

i know .obj file format, and i know how to get all vertices . But i don't konw how to get the vertexIndex of every face such as "f 5 2 3", and how to get the "vn" value such as "vn -0.116639 0.196368 -0.973568".

from cgal.

pentacular avatar pentacular commented on June 14, 2024

Just go through all of the vertices and write them out.
The first vertex you write out has index 1, the second has index 2, and so on.

Next go through all of the triangles, mapping each vertex to its index.

Now you're done.

You don't need to add vertex normals, but vn 0 0 1 should be correct since this is a 2d polygon.

from cgal.

BeginCGAL avatar BeginCGAL commented on June 14, 2024

thank you , i have achieved the aim

from cgal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.