-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
version: 6.0.1
windows
vs2022
my code:
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Optimal_transportation_reconstruction_2.h>
#include <iostream>
#include <fstream>
#include <string>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::FT FT;
typedef K::Point_2 KPoint;
typedef CGAL::Optimal_transportation_reconstruction_2<K> Otr_2;
using namespace std;
static std::vector<std::string> split_string(const std::string& str, const std::string& delim) {
std::vector<std::string> res;
if ("" == str) return res;
char* strs = new char[str.length() + 1];
strcpy(strs, str.c_str());
char* d = new char[delim.length() + 1];
strcpy(d, delim.c_str());
char* p = strtok(strs, d);
while (p) {
std::string s = p;
res.push_back(s);
p = strtok(NULL, d);
}
return res;
}
void main() {
for (int i = 0; i < 10; i++)
{
std::vector<KPoint> points;
std::ifstream inputFile("data.ply");
std::string line;
while (std::getline(inputFile, line)) {
std::vector<std::string> str_vec = split_string(line, " ");
float x = atof(str_vec[1].c_str());
float y = atof(str_vec[2].c_str());
points.push_back({ x, y });
}
inputFile.close();
Otr_2 otr2(points);
otr2.run_under_wasserstein_tolerance(3 * 1.25);
std::vector<KPoint> vertices;
std::vector<size_t> isolated_vertices;
std::vector<std::pair<size_t, size_t> > edges;
otr2.indexed_output(
std::back_inserter(vertices),
std::back_inserter(isolated_vertices),
std::back_inserter(edges));
std::string save_ply_name = "floorplan_2d_" + std::to_string(i) + ".obj";
std::ofstream output_obj(save_ply_name);
{
std::vector<KPoint>::iterator vit;
for (vit = vertices.begin(); vit != vertices.end(); vit++) {
output_obj << "v " << vit->x() << " " << vit->y() << " " << 0 << "\n";
}
std::vector<std::pair<size_t, size_t>>::iterator eit;
for (eit = edges.begin(); eit != edges.end(); eit++) {
output_obj << "l " << eit->first + 1 << " " << eit->second + 1 << std::endl;
}
}
output_obj.close();
}
}input data file:
get the result:
the result of 2kb file is right,
the result of 16kb file is very bad, missing many line.


