Skip to content

Commit b64f657

Browse files
committed
issue4 --max-iterations heremaps#66
2 parents 4c21cc4 + 20e4a9e commit b64f657

File tree

5 files changed

+21
-12
lines changed

5 files changed

+21
-12
lines changed

include/tntn/TerraMesh.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class TerraMesh : public TerraBaseMesh
2929
const double no_data_value);
3030

3131
public:
32-
void greedy_insert(double max_error);
32+
void greedy_insert(double max_error, int max_iterations);
3333
void scan_triangle(dt_ptr t) override;
3434
std::unique_ptr<Mesh> convert_to_mesh();
3535
};

include/tntn/terra_meshing.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
namespace tntn {
1010

11-
std::unique_ptr<Mesh> generate_tin_terra(std::unique_ptr<RasterDouble> raster, double max_error);
11+
std::unique_ptr<Mesh> generate_tin_terra(std::unique_ptr<RasterDouble> raster, double max_error, int max_iterations=0);
1212

1313
std::unique_ptr<Mesh> generate_tin_terra(std::unique_ptr<SurfacePoints> surface_points,
14-
double max_error);
15-
std::unique_ptr<Mesh> generate_tin_terra(const SurfacePoints& surface_points, double max_error);
14+
double max_error, int max_iterations=0);
15+
std::unique_ptr<Mesh> generate_tin_terra(const SurfacePoints& surface_points, double max_error, int max_iterations=0);
1616

1717
} //namespace tntn

src/TerraMesh.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
namespace tntn {
1414
namespace terra {
1515

16-
void TerraMesh::greedy_insert(double max_error)
16+
void TerraMesh::greedy_insert(double max_error, int max_iterations)
1717
{
1818
m_max_error = max_error;
1919
m_counter = 0;
@@ -56,12 +56,14 @@ void TerraMesh::greedy_insert(double max_error)
5656
t = t->getLink();
5757
}
5858

59+
int iterations_count = 0;
5960
// Iterate until the error threshold is met
6061
while(!m_candidates.empty())
6162
{
6263
Candidate candidate = m_candidates.grab_greatest();
6364

6465
if(candidate.importance < m_max_error) continue;
66+
if(max_iterations && iterations_count >= max_iterations) continue;
6567

6668
// Skip if the candidate is not the latest
6769
if(m_token.value(candidate.y, candidate.x) != candidate.token) continue;
@@ -70,6 +72,7 @@ void TerraMesh::greedy_insert(double max_error)
7072

7173
//TNTN_LOG_DEBUG("inserting point: ({}, {}, {})", candidate.x, candidate.y, candidate.z);
7274
this->insert(glm::dvec2(candidate.x, candidate.y), candidate.triangle);
75+
iterations_count++;
7376
}
7477

7578
TNTN_LOG_INFO("finished greedy insertion");

src/cmd.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ static int subcommand_dem2tin(bool need_help,
287287
("output", po::value<std::string>(), "output filename")
288288
("output-format", po::value<std::string>()->default_value("auto"), "output file format, can be any of: auto, obj, off, terrain (quantized mesh), json/geojson")
289289
("max-error", po::value<double>(), "max error parameter when using terra or zemlya method")
290+
("max-iterations", po::value<int>()->default_value(0), "max add point iterations when using terra or zemlya method")
290291
("step", po::value<int>(), "grid spacing in pixels when using dense method")
291292
#if defined(TNTN_USE_ADDONS) && TNTN_USE_ADDONS
292293
("threshold", po::value<double>(), "threshold when using curvature method")
@@ -363,6 +364,11 @@ static int subcommand_dem2tin(bool need_help,
363364

364365
const auto t_start = std::chrono::high_resolution_clock::now();
365366

367+
if(method != "terra" && local_varmap.count("max-iterations"))
368+
{
369+
throw po::error("parameter --max-iterations implemented for terra method only");
370+
}
371+
366372
if(method == "terra" || method == "zemlya")
367373
{
368374
double max_error = raster->get_cell_size();
@@ -374,7 +380,7 @@ static int subcommand_dem2tin(bool need_help,
374380
if("terra" == method)
375381
{
376382
TNTN_LOG_INFO("performing terra meshing...");
377-
mesh = generate_tin_terra(std::move(raster), max_error);
383+
mesh = generate_tin_terra(std::move(raster), max_error, local_varmap["max-iterations"].as<int>());
378384
}
379385
else if("zemlya" == method)
380386
{

src/terra_meshing.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,34 @@
55

66
namespace tntn {
77

8-
std::unique_ptr<Mesh> generate_tin_terra(std::unique_ptr<RasterDouble> raster, double max_error)
8+
std::unique_ptr<Mesh> generate_tin_terra(std::unique_ptr<RasterDouble> raster, double max_error, int max_iterations)
99
{
1010
TNTN_ASSERT(raster != nullptr);
1111
terra::TerraMesh g;
1212
g.load_raster(std::move(raster));
13-
g.greedy_insert(max_error);
13+
g.greedy_insert(max_error, max_iterations);
1414
return g.convert_to_mesh();
1515
}
1616

1717
std::unique_ptr<Mesh> generate_tin_terra(std::unique_ptr<SurfacePoints> surface_points,
18-
double max_error)
18+
double max_error, int max_iterations)
1919
{
2020
auto raster = surface_points->to_raster();
2121
surface_points.reset();
2222

2323
terra::TerraMesh g;
2424
g.load_raster(std::move(raster));
25-
g.greedy_insert(max_error);
25+
g.greedy_insert(max_error, max_iterations);
2626
return g.convert_to_mesh();
2727
}
2828

29-
std::unique_ptr<Mesh> generate_tin_terra(const SurfacePoints& surface_points, double max_error)
29+
std::unique_ptr<Mesh> generate_tin_terra(const SurfacePoints& surface_points, double max_error, int max_iterations)
3030
{
3131
auto raster = surface_points.to_raster();
3232

3333
terra::TerraMesh g;
3434
g.load_raster(std::move(raster));
35-
g.greedy_insert(max_error);
35+
g.greedy_insert(max_error, max_iterations);
3636
return g.convert_to_mesh();
3737
}
3838

0 commit comments

Comments
 (0)