Skip to content

Commit

Permalink
Added new parameter Round Max Angle for creating outline "ridges"
Browse files Browse the repository at this point in the history
  • Loading branch information
dov committed Jan 13, 2021
1 parent fd0c1d2 commit 826ff53
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 6 deletions.
16 changes: 16 additions & 0 deletions src/main-input.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#include "main-input.h"
#include "dov-mm-macros.h"
#include <math.h>
#include <fmt/core.h>

using namespace fmt;

constexpr double DEG2RAD = M_PI/180;

static Gtk::Widget* mmLabelAligned(const gchar *markup, double xAlign)
{
auto w_label = mm<Gtk::Label>();
Expand Down Expand Up @@ -81,6 +84,14 @@ MainInput::MainInput()
m_num_radius_steps.signal_value_changed().connect(sigc::mem_fun(*this,
&MainInput::on_profile_input_changed));

// Setup the round max angle steps
m_round_max_angle_in_degrees.set_digits(0);
m_round_max_angle_in_degrees.set_range(0,180);
m_round_max_angle_in_degrees.set_increments(1,10);
m_round_max_angle_in_degrees.set_value(90);
m_round_max_angle_in_degrees.signal_value_changed().connect(sigc::mem_fun(*this,
&MainInput::on_profile_input_changed));

// Setup the radius button
m_zdepth.set_digits(1);
m_zdepth.set_range(0,1000);
Expand Down Expand Up @@ -129,6 +140,10 @@ MainInput::MainInput()
w_grid->attach(*mmLabelRight("Num radius steps:"), 0,row);
w_grid->attach(m_num_radius_steps, 1,row);
row++;
w_grid->attach(*mmLabelRight("Round max angle:"), 0,row);
w_grid->attach(m_round_max_angle_in_degrees, 1,row);
w_grid->attach(*mmLabelLeft("[Degrees]"), 2, row);
row++;
w_grid->attach(*mmLabelRight("Z-depth:"), 0,row);
w_grid->attach(m_zdepth, 1,row);
row++;
Expand Down Expand Up @@ -161,6 +176,7 @@ void MainInput::on_button_skeleton_clicked()
void MainInput::on_button_profile_clicked()
{
m_signal_build_profile(m_radius.get_value(),
m_round_max_angle_in_degrees.get_value()*DEG2RAD,
int(m_num_radius_steps.get_value()),
m_zdepth.get_value());
}
Expand Down
2 changes: 2 additions & 0 deletions src/main-input.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class MainInput : public Gtk::Box

using type_signal_build_profile = sigc::signal<void(
double, // Radius
double, // Round max angle in radians
int, // Num radius steps
double // ZDepth
)>;
Expand All @@ -39,6 +40,7 @@ class MainInput : public Gtk::Box
Gtk::FontButton m_font_picker;
Gtk::SpinButton m_radius;
Gtk::SpinButton m_num_radius_steps;
Gtk::SpinButton m_round_max_angle_in_degrees;
Gtk::SpinButton m_zdepth;
Gtk::SpinButton m_linear_limit;
Gtk::Label m_skeleton_status_label;
Expand Down
11 changes: 6 additions & 5 deletions src/pangocairo-to-contour.cc
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,10 @@ Mesh TeXtrusion::skeleton_to_mesh(const vector<PHoleInfo>& phole_infos,

// The upper surface Loop over the offsets
double epsilon = 1e-5;
double angle_span = profile_round_max_angle;
for (int d_idx=0; d_idx<this->profile_num_radius_steps+1; d_idx++) {
double angle_start = M_PI/2 * d_idx/this->profile_num_radius_steps;
double angle_end = M_PI/2 * (d_idx+1)/this->profile_num_radius_steps;
double angle_start = angle_span * d_idx/this->profile_num_radius_steps;
double angle_end = angle_span * (d_idx+1)/this->profile_num_radius_steps;
double offs_start = profile_radius*(1-cos(angle_start));
double offs_end = profile_radius*(1-cos(angle_end));
if (d_idx == this->profile_num_radius_steps)
Expand Down Expand Up @@ -434,9 +435,9 @@ Mesh TeXtrusion::skeleton_to_mesh(const vector<PHoleInfo>& phole_infos,

// Transform z
double r = profile_radius;
if (z > r)
z = r;
else
if (z > r - r * cos(angle_span))
z = r * sin(angle_span);
else
z = sqrt(r*r-(z-r)*(z-r));

// Do the 2-i to get the correct direction
Expand Down
1 change: 1 addition & 0 deletions src/pangocairo-to-contour.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ class TeXtrusion {
std::string markup;
Pango::FontDescription font_description;
double profile_radius = 3.0;
double profile_round_max_angle = M_PI/2;
double profile_num_radius_steps = 10;
std::string giv_filename;
double zdepth = 2;
Expand Down
6 changes: 5 additions & 1 deletion src/pomelo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ void Pomelo::on_build_skeleton(Glib::ustring text_string,
}

void Pomelo::on_build_profile(double radius,
double round_max_angle,
int num_radius_steps,
double zdepth)
{
Expand All @@ -255,7 +256,10 @@ void Pomelo::on_build_profile(double radius,
m_worker_action = ACTION_PROFILE;
m_worker_skeleton_thread = make_unique<std::thread>(
[=] {
m_worker_skeleton.do_work_profile(radius,num_radius_steps,zdepth);
m_worker_skeleton.do_work_profile(radius,
round_max_angle,
num_radius_steps,
zdepth);
});

m_main_input.set_profile_ready_state(true);
Expand Down
1 change: 1 addition & 0 deletions src/pomelo.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class Pomelo : public Gtk::Window
double linear_limit,
Pango::FontDescription font_description);
void on_build_profile(double radius,
double round_max_angle,
int num_radius_steps,
double zdepth);

Expand Down
2 changes: 2 additions & 0 deletions src/worker-skeleton.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ void WorkerSkeleton::do_work_skeleton(

void WorkerSkeleton::do_work_profile(
double radius,
double round_max_angle,
int num_radius_steps,
double zdepth
)
Expand All @@ -140,6 +141,7 @@ void WorkerSkeleton::do_work_profile(

m_textrusion->zdepth = zdepth;
m_textrusion->profile_radius = radius;
m_textrusion->profile_round_max_angle = round_max_angle;
m_textrusion->profile_num_radius_steps = num_radius_steps;

// Do the time consuming tasks
Expand Down
1 change: 1 addition & 0 deletions src/worker-skeleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class WorkerSkeleton
Glib::ustring markup);
// Do the profile part of the shaping
void do_work_profile(double radius,
double round_max_angle,
int num_radius_steps,
double zdepth);

Expand Down

0 comments on commit 826ff53

Please sign in to comment.