mirror of https://github.com/CGAL/cgal
rearrange seeding by number
This commit is contained in:
parent
e4428e2dd7
commit
bcb59d7db4
|
|
@ -64,19 +64,8 @@ int main(int argc, char *argv[])
|
|||
std::cerr << "start initialization" << std::endl;
|
||||
t0.reset();
|
||||
t0.start();
|
||||
switch(init) {
|
||||
case 0:
|
||||
l21_vsa.seed_random(num_proxies);
|
||||
break;
|
||||
case 1:
|
||||
l21_vsa.seed_incremental(num_proxies, 5);
|
||||
break;
|
||||
case 2:
|
||||
l21_vsa.seed_hierarchical(num_proxies, 5);
|
||||
break;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
l21_vsa.seeding_by_number(
|
||||
static_cast<L21VSA::Initialization>(init), num_proxies);
|
||||
t0.stop();
|
||||
std::cerr << "initialization time " << t0.time() << " sec." << std::endl;
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ int main()
|
|||
l21_approx.set_metric(metric, proxy_fitting);
|
||||
|
||||
// initialize proxies randomly on the mesh
|
||||
l21_approx.seed_random(100);
|
||||
l21_approx.seeding_by_number(L21VSA::RandomInit, 100);
|
||||
|
||||
// run the iteration to minimize the error
|
||||
for (std::size_t i = 0; i < 30; ++i)
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ int main()
|
|||
compact_approx.set_metric(metric, proxy_fitting);
|
||||
|
||||
// using 200 proxies to approximate the shape
|
||||
compact_approx.seed_hierarchical(200, 5);
|
||||
compact_approx.seeding_by_number(CompactVSA::HierarchicalInit, 200);
|
||||
for (std::size_t i = 0; i < 30; ++i)
|
||||
compact_approx.run_one_step();
|
||||
|
||||
|
|
|
|||
|
|
@ -310,81 +310,26 @@ public:
|
|||
}
|
||||
|
||||
/*!
|
||||
* @brief Random initialize proxies.
|
||||
* @param num_seed number of proxies seed
|
||||
* @return number of proxies initialized
|
||||
*/
|
||||
std::size_t seed_random(const std::size_t num_seed) {
|
||||
proxies.clear();
|
||||
if (num_faces(*m_pmesh) < num_seed)
|
||||
return 0;
|
||||
|
||||
const std::size_t interval = num_faces(*m_pmesh) / num_seed;
|
||||
std::size_t index = 0;
|
||||
BOOST_FOREACH(face_descriptor f, faces(*m_pmesh)) {
|
||||
if ((index++) % interval == 0) {
|
||||
proxies.push_back(fit_new_proxy(f));
|
||||
}
|
||||
if (proxies.size() >= num_seed)
|
||||
break;
|
||||
}
|
||||
return proxies.size();
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Incremental initialize proxies.
|
||||
* @param num_seed number of proxies seed
|
||||
* @brief Seeding by targeted number of proxies.
|
||||
* @param method seeding method
|
||||
* @param num_seed target number of proxies seed
|
||||
* @param num_iterations number of iterations of coarse re-fitting
|
||||
* before each incremental proxy insertion
|
||||
* @return number of proxies initialized
|
||||
*/
|
||||
std::size_t seed_incremental(const std::size_t num_seed,
|
||||
std::size_t seeding_by_number(
|
||||
const Initialization method,
|
||||
const std::size_t num_seed,
|
||||
const std::size_t num_iterations = 5) {
|
||||
proxies.clear();
|
||||
if (num_faces(*m_pmesh) < num_seed)
|
||||
return 0;
|
||||
|
||||
// initialize a proxy and the proxy map to prepare for the insertion
|
||||
proxies.push_back(fit_new_proxy(*(faces(*m_pmesh).first)));
|
||||
BOOST_FOREACH(face_descriptor f, faces(*m_pmesh))
|
||||
fproxy_map[f] = 0;
|
||||
|
||||
insert_proxy_furthest(num_seed - 1, num_iterations);
|
||||
return proxies.size();
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Hierarchical initialize proxies.
|
||||
* @param num_seed number of proxies seed
|
||||
* @param num_iterations number of iterations of coarse re-fitting
|
||||
* before each hierarchical proxy insertion
|
||||
* @return number of proxies initialized
|
||||
*/
|
||||
std::size_t seed_hierarchical(const std::size_t num_seed,
|
||||
const std::size_t num_iterations = 5) {
|
||||
proxies.clear();
|
||||
if (num_faces(*m_pmesh) < num_seed)
|
||||
return 0;
|
||||
|
||||
// initialize 2 proxy
|
||||
typename boost::graph_traits<TriangleMesh>::face_iterator
|
||||
fitr = faces(*m_pmesh).first;
|
||||
proxies.push_back(fit_new_proxy(*fitr));
|
||||
proxies.push_back(fit_new_proxy(*(++fitr)));
|
||||
|
||||
while (proxies.size() < num_seed) {
|
||||
for (std::size_t i = 0; i < num_iterations; ++i) {
|
||||
partition();
|
||||
fit();
|
||||
}
|
||||
|
||||
// add proxies by error diffusion
|
||||
const std::size_t num_proxies = proxies.size();
|
||||
const std::size_t num_proxies_to_be_added =
|
||||
(num_proxies * 2 < num_seed) ? num_proxies : (num_seed - num_proxies);
|
||||
insert_proxy_hierarchical(num_proxies_to_be_added);
|
||||
switch (method) {
|
||||
case RandomInit:
|
||||
return seed_random(num_seed);
|
||||
case IncrementalInit:
|
||||
return seed_incremental(num_seed, num_iterations);
|
||||
case HierarchicalInit:
|
||||
return seed_hierarchical(num_seed, num_iterations);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return proxies.size();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -862,6 +807,84 @@ public:
|
|||
|
||||
// private member functions
|
||||
private:
|
||||
/*!
|
||||
* @brief Random initialize proxies.
|
||||
* @param num_seed number of proxies seed
|
||||
* @return number of proxies initialized
|
||||
*/
|
||||
std::size_t seed_random(const std::size_t num_seed) {
|
||||
proxies.clear();
|
||||
if (num_faces(*m_pmesh) < num_seed)
|
||||
return 0;
|
||||
|
||||
const std::size_t interval = num_faces(*m_pmesh) / num_seed;
|
||||
std::size_t index = 0;
|
||||
BOOST_FOREACH(face_descriptor f, faces(*m_pmesh)) {
|
||||
if ((index++) % interval == 0) {
|
||||
proxies.push_back(fit_new_proxy(f));
|
||||
}
|
||||
if (proxies.size() >= num_seed)
|
||||
break;
|
||||
}
|
||||
return proxies.size();
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Incremental initialize proxies.
|
||||
* @param num_seed number of proxies seed
|
||||
* @param num_iterations number of iterations of coarse re-fitting
|
||||
* before each incremental proxy insertion
|
||||
* @return number of proxies initialized
|
||||
*/
|
||||
std::size_t seed_incremental(const std::size_t num_seed,
|
||||
const std::size_t num_iterations = 5) {
|
||||
proxies.clear();
|
||||
if (num_faces(*m_pmesh) < num_seed)
|
||||
return 0;
|
||||
|
||||
// initialize a proxy and the proxy map to prepare for the insertion
|
||||
proxies.push_back(fit_new_proxy(*(faces(*m_pmesh).first)));
|
||||
BOOST_FOREACH(face_descriptor f, faces(*m_pmesh))
|
||||
fproxy_map[f] = 0;
|
||||
|
||||
insert_proxy_furthest(num_seed - 1, num_iterations);
|
||||
return proxies.size();
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Hierarchical initialize proxies.
|
||||
* @param num_seed number of proxies seed
|
||||
* @param num_iterations number of iterations of coarse re-fitting
|
||||
* before each hierarchical proxy insertion
|
||||
* @return number of proxies initialized
|
||||
*/
|
||||
std::size_t seed_hierarchical(const std::size_t num_seed,
|
||||
const std::size_t num_iterations = 5) {
|
||||
proxies.clear();
|
||||
if (num_faces(*m_pmesh) < num_seed)
|
||||
return 0;
|
||||
|
||||
// initialize 2 proxy
|
||||
typename boost::graph_traits<TriangleMesh>::face_iterator
|
||||
fitr = faces(*m_pmesh).first;
|
||||
proxies.push_back(fit_new_proxy(*fitr));
|
||||
proxies.push_back(fit_new_proxy(*(++fitr)));
|
||||
|
||||
while (proxies.size() < num_seed) {
|
||||
for (std::size_t i = 0; i < num_iterations; ++i) {
|
||||
partition();
|
||||
fit();
|
||||
}
|
||||
|
||||
// add proxies by error diffusion
|
||||
const std::size_t num_proxies = proxies.size();
|
||||
const std::size_t num_proxies_to_be_added =
|
||||
(num_proxies * 2 < num_seed) ? num_proxies : (num_seed - num_proxies);
|
||||
insert_proxy_hierarchical(num_proxies_to_be_added);
|
||||
}
|
||||
return proxies.size();
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Initialize by targeted error drop.
|
||||
* @param target_drop targeted error drop to initial state, usually in range (0, 1)
|
||||
|
|
|
|||
|
|
@ -92,21 +92,9 @@ bool vsa_mesh_approximation(const TriangleMesh &tm_in,
|
|||
std::size_t num_iterations = choose_param(get_param(np, internal_np::number_of_iterations), 10);
|
||||
std::cout << "#px = " << num_proxies << ", #itr = " << num_iterations << std::endl;
|
||||
|
||||
std::size_t init = choose_param(get_param(np, internal_np::init_method), 0);
|
||||
switch (static_cast<typename VSAL21::Initialization>(init)) {
|
||||
case VSAL21::RandomInit:
|
||||
vsa_l21.seed_random(num_proxies);
|
||||
break;
|
||||
case VSAL21::IncrementalInit:
|
||||
vsa_l21.seed_incremental(num_proxies, 5);
|
||||
break;
|
||||
case VSAL21::HierarchicalInit:
|
||||
vsa_l21.seed_hierarchical(num_proxies, 5);
|
||||
break;
|
||||
default:
|
||||
std::cout << "Error: invalid initialization method parameter." << std::endl;
|
||||
return false;
|
||||
}
|
||||
int init = choose_param(get_param(np, internal_np::init_method), 0);
|
||||
vsa_l21.seeding_by_number(
|
||||
static_cast<typename VSAL21::Initialization>(init), num_proxies, 5);
|
||||
for (std::size_t i = 0; i < num_iterations; ++i)
|
||||
vsa_l21.run_one_step();
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ int main()
|
|||
|
||||
// random init and run
|
||||
std::cout << "random init and run" << std::endl;
|
||||
l2_approx.seed_random(10);
|
||||
l2_approx.seeding_by_number(L2VSA::RandomInit, 10);
|
||||
for (std::size_t i = 0; i < 10; ++i)
|
||||
l2_approx.run_one_step();
|
||||
if (l2_approx.get_proxies_size() != 10)
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ int main()
|
|||
L21ProxyFitting l21_fitting(mesh);
|
||||
vsa_l21.set_metric(l21_metric, l21_fitting);
|
||||
|
||||
vsa_l21.seed_random(100);
|
||||
vsa_l21.seeding_by_number(L21VSA::RandomInit, 100);
|
||||
std::vector<FT> error;
|
||||
for (std::size_t i = 0; i < 30; ++i)
|
||||
error.push_back(vsa_l21.run_one_step());
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ int main()
|
|||
compact_approx.set_metric(metric, proxy_fitting);
|
||||
|
||||
std::cout << "random init and run" << std::endl;
|
||||
compact_approx.seed_random(20);
|
||||
compact_approx.seeding_by_number(CompactVSA::RandomInit, 20);
|
||||
for (std::size_t i = 0; i < 20; ++i)
|
||||
compact_approx.run_one_step();
|
||||
if (compact_approx.get_proxies_size() != 20)
|
||||
|
|
|
|||
Loading…
Reference in New Issue