The code fails to compile when I use want to get an ".obj" format triangle mesh

49 Views Asked by At

Issue

I used the "GDAL" to read a shpfile file which has one feature. I have got all of this feature's points, and then I want to use the them to generate a ".obj" format mesh file. Interestingly, when I use the "PMP::triangulate_faces(mesh)" to triangulate this mesh, I get some errors like these:

CGAL error: precondition violation! 
Expression : vaa != vbb 
File : D:\Programs\dev\CGAL-5.5.1\include\CGAL\Constrained_triangulation_2.h 
Line : 813 
Explanation: Refer to the bug-reporting instructions at https://www.cgal.org/bug_report.html

Thus, I abandoned the above mentioned method and replaced it with the "CGAL::convex_hull_3()" method to generate ".obj" format Polyhedron_3. Unfortunately, this time I couldn't even get the compilation to go through, and I get some errors like these:

C2530 "v": References must be initialized   property_map.hpp 304
C2678 Binary "[": no operator found that accepts a left operand of type "const PropertyMap" (or no acceptable conversion)   property_map.h 304
C2678 Binary "[": no operator found that accepts a left operand of type "const PropertyMap" (or no acceptable conversion)   property_map.h 311

The code for both methods I used I will give below, I hope both methods will get the appropriate solution

source code 1

namespace PMP = CGAL::Polygon_mesh_processing;
typedef K::Point_3 Point;
typedef CGAL::Surface_mesh<Point> Mesh;

Mesh mesh;
for (int k = 0; k < num; k++)
{
  double x = poline->getX(k);
  double y = poline->getY(k);
  double z = poline->getZ(k);
  coordTransform->Transform(1, &x, &y, 0);
  mesh.add_vertex(Point(y - *(center + 1), x - *center, 0 - *(center + 2)));
}                    
string filename = "E:/point/output/泰森多边形/";
filename = filename + "_" + to_string(i)+".obj";
char* path = new char[strlen(filename.c_str()) + 1];
strcpy(path, filename.c_str());
            
mesh.add_face(mesh.vertices());
if (!CGAL::is_triangle_mesh(mesh))//未三角化的三角化
{   
  std::cout << "Input mesh is not triangulated." << std::endl;
  PMP::triangulate_faces(mesh);
}
CGAL::IO::write_polygon_mesh(path, outmesh2, CGAL::parameters::stream_precision(17));

source code2

typedef CGAL::Exact_predicates_exact_constructions_kernel K;
typedef CGAL::Polyhedron_3<K>  PHD;

PHD mesh;
vector<Point> points;
for (int k = 0; k < num; k++)
{
  double x = poline->getX(k);
  double y = poline->getY(k);
  double z = poline->getZ(k);
  coordTransform->Transform(1, &x, &y, 0);
  points.push_back(Point(y - *(center + 1), x - *center, 0 - *(center + 2)));

}
CGAL::convex_hull_3(points.begin(), points.end(), mesh);
CGAL::IO::write_polygon_mesh(path, outmesh2, CGAL::parameters::stream_precision(17));

Environment

Operating system (Windows/Mac/Linux, 32/64 bits): Windows 64 bits Compiler: Visual Studio 2019 Release or debug mode: debug Specific CGAL version: 5.5.1 Boost version: 1.71.0 Other libraries versions if used (Eigen, TBB, etc.): Eigen 3

tips:

1.the above code are built on the basis of the main header files have been introduced, if the error is caused by missing header files, I hope you can tell me in detail. 2.if you need to provide experimental data, you can contact me, I can share the data through the wetransfer

0

There are 0 best solutions below