Simplify does not touch ModelVolume all the time (runs, but needs polishing)

This commit is contained in:
Lukas Matena 2021-10-29 17:58:05 +02:00
parent ab260d005e
commit 7bcab6f795
2 changed files with 173 additions and 200 deletions

View file

@ -49,12 +49,16 @@ protected:
virtual CommonGizmosDataID on_get_requirements() const;
private:
void after_apply();
void apply_simplify();
void close();
void process();
void set_its(const indexed_triangle_set &its);
void stop_worker_thread(bool wait);
void worker_finished();
void create_gui_cfg();
void request_rerender();
void init_model(const indexed_triangle_set& its);
void set_center_position();
// move to global functions
@ -64,59 +68,54 @@ private:
// return false when volume was deleted
static bool exist_volume(const ModelVolume *volume);
std::atomic_bool m_is_valid_result; // differ what to do in apply
std::atomic_bool m_exist_preview; // set when process end
bool m_move_to_center; // opening gizmo
ModelVolume *m_volume; // keep pointer to actual working volume
size_t m_obj_index;
std::optional<indexed_triangle_set> m_original_its;
bool m_show_wireframe;
GLModel m_glmodel;
std::atomic<bool> m_need_reload; // after simplify, glReload must be on main thread
struct State {
enum Status {
settings,
preview, // simplify to show preview
close_on_end, // simplify with close on end
canceling // after button click, before canceled
};
Status status;
int progress; // percent of done work
indexed_triangle_set result;
};
std::thread m_worker;
std::mutex m_state_mutex; // guards m_state
State m_state;
struct Configuration
{
bool use_count = false;
// minimal triangle count
float decimate_ratio = 50.f; // in percent
uint32_t wanted_count = 0; // initialize by percents
uint32_t wanted_count = 0; // initialize by percents
float max_error = 1.; // maximal quadric error
// maximal quadric error
float max_error = 1.;
void fix_count_by_ratio(size_t triangle_count)
{
if (decimate_ratio <= 0.f)
wanted_count = static_cast<uint32_t>(triangle_count);
else if (decimate_ratio >= 100.f)
wanted_count = 0;
else
wanted_count = static_cast<uint32_t>(std::round(
triangle_count * (100.f - decimate_ratio) / 100.f));
void fix_count_by_ratio(size_t triangle_count);
bool operator==(const Configuration& rhs) {
return (use_count == rhs.use_count && decimate_ratio == rhs.decimate_ratio
&& wanted_count == rhs.wanted_count && max_error == rhs.max_error);
}
} m_configuration;
};
Configuration m_configuration;
bool m_move_to_center; // opening gizmo
ModelVolume *m_volume; // keep pointer to actual working volume
bool m_show_wireframe;
GLModel m_glmodel;
size_t m_triangle_count; // triangle count of the model currently shown
// Following struct is accessed by both UI and worker thread.
// Accesses protected by a mutex.
struct State {
enum Status {
idle,
running,
cancelling
};
Status status = idle;
int progress = 0; // percent of done work
Configuration config; // Configuration we started with.
std::unique_ptr<indexed_triangle_set> result;
};
std::thread m_worker;
std::mutex m_state_mutex; // guards m_state
State m_state; // accessed by both threads
// Following variable is accessed by UI only.
bool m_is_worker_running = false;
// This configs holds GUI layout size given by translated texts.
// etc. When language changes, GUI is recreated and this class constructed again,
@ -145,8 +144,6 @@ private:
const std::string tr_detail_level;
const std::string tr_decimate_ratio;
void init_model();
// cancel exception
class SimplifyCanceledException: public std::exception
{