Fixed conflicts after merging with branch eigenize

This commit is contained in:
Enrico Turri 2018-08-23 15:37:38 +02:00
commit 66ce638439
211 changed files with 4309 additions and 4920 deletions

View file

@ -319,7 +319,7 @@ void AppController::arrange_model()
auto& bedpoints = print_ctl()->config().bed_shape.values;
Polyline bed; bed.points.reserve(bedpoints.size());
for(auto& v : bedpoints)
bed.append(Point::new_scale(v.x, v.y));
bed.append(Point::new_scale(v(0), v(1)));
if(pind) pind->update(0, _(L("Arranging objects...")));

View file

@ -32,17 +32,17 @@ void Bed_2D::repaint()
cw--;
ch--;
auto cbb = BoundingBoxf(Pointf(0, 0),Pointf(cw, ch));
auto cbb = BoundingBoxf(Vec2d(0, 0),Vec2d(cw, ch));
// leave space for origin point
cbb.min.translate(4, 0);
cbb.max.translate(-4, -4);
cbb.min(0) += 4;
cbb.max -= Vec2d(4., 4.);
// leave space for origin label
cbb.max.translate(0, -13);
cbb.max(1) -= 13;
// read new size
cw = cbb.size().x;
ch = cbb.size().y;
cw = cbb.size()(0);
ch = cbb.size()(1);
auto ccenter = cbb.center();
@ -50,20 +50,20 @@ void Bed_2D::repaint()
auto bed_shape = m_bed_shape;
auto bed_polygon = Polygon::new_scale(m_bed_shape);
auto bb = BoundingBoxf(m_bed_shape);
bb.merge(Pointf(0, 0)); // origin needs to be in the visible area
auto bw = bb.size().x;
auto bh = bb.size().y;
bb.merge(Vec2d(0, 0)); // origin needs to be in the visible area
auto bw = bb.size()(0);
auto bh = bb.size()(1);
auto bcenter = bb.center();
// calculate the scaling factor for fitting bed shape in canvas area
auto sfactor = std::min(cw/bw, ch/bh);
auto shift = Pointf(
ccenter.x - bcenter.x * sfactor,
ccenter.y - bcenter.y * sfactor
auto shift = Vec2d(
ccenter(0) - bcenter(0) * sfactor,
ccenter(1) - bcenter(1) * sfactor
);
m_scale_factor = sfactor;
m_shift = Pointf(shift.x + cbb.min.x,
shift.y - (cbb.max.y - GetSize().GetHeight()));
m_shift = Vec2d(shift(0) + cbb.min(0),
shift(1) - (cbb.max(1) - GetSize().GetHeight()));
// draw bed fill
dc.SetBrush(wxBrush(wxColour(255, 255, 255), wxSOLID));
@ -71,19 +71,18 @@ void Bed_2D::repaint()
for (auto pt: m_bed_shape)
{
Point pt_pix = to_pixels(pt);
pt_list.push_back(new wxPoint(pt_pix.x, pt_pix.y));
pt_list.push_back(new wxPoint(pt_pix(0), pt_pix(1)));
}
dc.DrawPolygon(&pt_list, 0, 0);
// draw grid
auto step = 10; // 1cm grid
Polylines polylines;
for (auto x = bb.min.x - fmod(bb.min.x, step) + step; x < bb.max.x; x += step) {
Polyline pl = Polyline::new_scale({ Pointf(x, bb.min.y), Pointf(x, bb.max.y) });
polylines.push_back(pl);
for (auto x = bb.min(0) - fmod(bb.min(0), step) + step; x < bb.max(0); x += step) {
polylines.push_back(Polyline::new_scale({ Vec2d(x, bb.min(1)), Vec2d(x, bb.max(1)) }));
}
for (auto y = bb.min.y - fmod(bb.min.y, step) + step; y < bb.max.y; y += step) {
polylines.push_back(Polyline::new_scale({ Pointf(bb.min.x, y), Pointf(bb.max.x, y) }));
for (auto y = bb.min(1) - fmod(bb.min(1), step) + step; y < bb.max(1); y += step) {
polylines.push_back(Polyline::new_scale({ Vec2d(bb.min(0), y), Vec2d(bb.max(0), y) }));
}
polylines = intersection_pl(polylines, bed_polygon);
@ -91,9 +90,9 @@ void Bed_2D::repaint()
for (auto pl : polylines)
{
for (size_t i = 0; i < pl.points.size()-1; i++){
Point pt1 = to_pixels(Pointf::new_unscale(pl.points[i]));
Point pt2 = to_pixels(Pointf::new_unscale(pl.points[i+1]));
dc.DrawLine(pt1.x, pt1.y, pt2.x, pt2.y);
Point pt1 = to_pixels(unscale(pl.points[i]));
Point pt2 = to_pixels(unscale(pl.points[i+1]));
dc.DrawLine(pt1(0), pt1(1), pt2(0), pt2(1));
}
}
@ -102,65 +101,59 @@ void Bed_2D::repaint()
dc.SetBrush(wxBrush(wxColour(0, 0, 0), wxTRANSPARENT));
dc.DrawPolygon(&pt_list, 0, 0);
auto origin_px = to_pixels(Pointf(0, 0));
auto origin_px = to_pixels(Vec2d(0, 0));
// draw axes
auto axes_len = 50;
auto arrow_len = 6;
auto arrow_angle = Geometry::deg2rad(45.0);
dc.SetPen(wxPen(wxColour(255, 0, 0), 2, wxSOLID)); // red
auto x_end = Pointf(origin_px.x + axes_len, origin_px.y);
dc.DrawLine(wxPoint(origin_px.x, origin_px.y), wxPoint(x_end.x, x_end.y));
auto x_end = Vec2d(origin_px(0) + axes_len, origin_px(1));
dc.DrawLine(wxPoint(origin_px(0), origin_px(1)), wxPoint(x_end(0), x_end(1)));
for (auto angle : { -arrow_angle, arrow_angle }){
auto end = x_end;
end.translate(-arrow_len, 0);
end.rotate(angle, x_end);
dc.DrawLine(wxPoint(x_end.x, x_end.y), wxPoint(end.x, end.y));
auto end = Eigen::Translation2d(x_end) * Eigen::Rotation2Dd(angle) * Eigen::Translation2d(- x_end) * Eigen::Vector2d(x_end(0) - arrow_len, x_end(1));
dc.DrawLine(wxPoint(x_end(0), x_end(1)), wxPoint(end(0), end(1)));
}
dc.SetPen(wxPen(wxColour(0, 255, 0), 2, wxSOLID)); // green
auto y_end = Pointf(origin_px.x, origin_px.y - axes_len);
dc.DrawLine(wxPoint(origin_px.x, origin_px.y), wxPoint(y_end.x, y_end.y));
auto y_end = Vec2d(origin_px(0), origin_px(1) - axes_len);
dc.DrawLine(wxPoint(origin_px(0), origin_px(1)), wxPoint(y_end(0), y_end(1)));
for (auto angle : { -arrow_angle, arrow_angle }) {
auto end = y_end;
end.translate(0, +arrow_len);
end.rotate(angle, y_end);
dc.DrawLine(wxPoint(y_end.x, y_end.y), wxPoint(end.x, end.y));
auto end = Eigen::Translation2d(y_end) * Eigen::Rotation2Dd(angle) * Eigen::Translation2d(- y_end) * Eigen::Vector2d(y_end(0), y_end(1) + arrow_len);
dc.DrawLine(wxPoint(y_end(0), y_end(1)), wxPoint(end(0), end(1)));
}
// draw origin
dc.SetPen(wxPen(wxColour(0, 0, 0), 1, wxSOLID));
dc.SetBrush(wxBrush(wxColour(0, 0, 0), wxSOLID));
dc.DrawCircle(origin_px.x, origin_px.y, 3);
dc.DrawCircle(origin_px(0), origin_px(1), 3);
static const auto origin_label = wxString("(0,0)");
dc.SetTextForeground(wxColour(0, 0, 0));
dc.SetFont(wxFont(10, wxDEFAULT, wxNORMAL, wxNORMAL));
auto extent = dc.GetTextExtent(origin_label);
const auto origin_label_x = origin_px.x <= cw / 2 ? origin_px.x + 1 : origin_px.x - 1 - extent.GetWidth();
const auto origin_label_y = origin_px.y <= ch / 2 ? origin_px.y + 1 : origin_px.y - 1 - extent.GetHeight();
const auto origin_label_x = origin_px(0) <= cw / 2 ? origin_px(0) + 1 : origin_px(0) - 1 - extent.GetWidth();
const auto origin_label_y = origin_px(1) <= ch / 2 ? origin_px(1) + 1 : origin_px(1) - 1 - extent.GetHeight();
dc.DrawText(origin_label, origin_label_x, origin_label_y);
// draw current position
if (m_pos!= Pointf(0, 0)) {
if (m_pos!= Vec2d(0, 0)) {
auto pos_px = to_pixels(m_pos);
dc.SetPen(wxPen(wxColour(200, 0, 0), 2, wxSOLID));
dc.SetBrush(wxBrush(wxColour(200, 0, 0), wxTRANSPARENT));
dc.DrawCircle(pos_px.x, pos_px.y, 5);
dc.DrawCircle(pos_px(0), pos_px(1), 5);
dc.DrawLine(pos_px.x - 15, pos_px.y, pos_px.x + 15, pos_px.y);
dc.DrawLine(pos_px.x, pos_px.y - 15, pos_px.x, pos_px.y + 15);
dc.DrawLine(pos_px(0) - 15, pos_px(1), pos_px(0) + 15, pos_px(1));
dc.DrawLine(pos_px(0), pos_px(1) - 15, pos_px(0), pos_px(1) + 15);
}
m_painted = true;
}
// convert G - code coordinates into pixels
Point Bed_2D::to_pixels(Pointf point){
auto p = Pointf(point);
p.scale(m_scale_factor);
p.translate(m_shift);
return Point(p.x, GetSize().GetHeight() - p.y);
Point Bed_2D::to_pixels(Vec2d point){
auto p = point * m_scale_factor + m_shift;
return Point(p(0), GetSize().GetHeight() - p(1));
}
void Bed_2D::mouse_event(wxMouseEvent event){
@ -168,7 +161,7 @@ void Bed_2D::mouse_event(wxMouseEvent event){
if (!m_painted) return;
auto pos = event.GetPosition();
auto point = to_units(Point(pos.x, pos.y));
auto point = to_units(Point(pos.x, pos.y));
if (event.LeftDown() || event.Dragging()) {
if (m_on_move)
m_on_move(point) ;
@ -177,14 +170,11 @@ void Bed_2D::mouse_event(wxMouseEvent event){
}
// convert pixels into G - code coordinates
Pointf Bed_2D::to_units(Point point){
auto p = Pointf(point.x, GetSize().GetHeight() - point.y);
p.translate(m_shift.negative());
p.scale(1 / m_scale_factor);
return p;
Vec2d Bed_2D::to_units(Point point){
return (Vec2d(point(0), GetSize().GetHeight() - point(1)) - m_shift) * (1. / m_scale_factor);
}
void Bed_2D::set_pos(Pointf pos){
void Bed_2D::set_pos(Vec2d pos){
m_pos = pos;
Refresh();
}

View file

@ -14,15 +14,15 @@ class Bed_2D : public wxPanel
bool m_painted = false;
bool m_interactive = false;
double m_scale_factor;
Pointf m_shift;
Pointf m_pos;
std::function<void(Pointf)> m_on_move = nullptr;
Vec2d m_shift = Vec2d::Zero();
Vec2d m_pos = Vec2d::Zero();
std::function<void(Vec2d)> m_on_move = nullptr;
Point to_pixels(Pointf point);
Pointf to_units(Point point);
Point to_pixels(Vec2d point);
Vec2d to_units(Point point);
void repaint();
void mouse_event(wxMouseEvent event);
void set_pos(Pointf pos);
void set_pos(Vec2d pos);
public:
Bed_2D(wxWindow* parent)
@ -41,7 +41,7 @@ public:
}
~Bed_2D(){}
std::vector<Pointf> m_bed_shape;
std::vector<Vec2d> m_bed_shape;
};

View file

@ -26,11 +26,6 @@
#include "GUI.hpp"
static const float UNIT_MATRIX[] = { 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f };
namespace Slic3r {
void GLIndexedVertexArray::load_mesh_flat_shading(const TriangleMesh &mesh)
@ -44,7 +39,7 @@ void GLIndexedVertexArray::load_mesh_flat_shading(const TriangleMesh &mesh)
for (int i = 0; i < mesh.stl.stats.number_of_facets; ++ i) {
const stl_facet &facet = mesh.stl.facet_start[i];
for (int j = 0; j < 3; ++ j)
this->push_geometry(facet.vertex[j].x, facet.vertex[j].y, facet.vertex[j].z, facet.normal.x, facet.normal.y, facet.normal.z);
this->push_geometry(facet.vertex[j](0), facet.vertex[j](1), facet.vertex[j](2), facet.normal(0), facet.normal(1), facet.normal(2));
}
}
@ -60,7 +55,7 @@ void GLIndexedVertexArray::load_mesh_full_shading(const TriangleMesh &mesh)
for (int i = 0; i < mesh.stl.stats.number_of_facets; ++i) {
const stl_facet &facet = mesh.stl.facet_start[i];
for (int j = 0; j < 3; ++j)
this->push_geometry(facet.vertex[j].x, facet.vertex[j].y, facet.vertex[j].z, facet.normal.x, facet.normal.y, facet.normal.z);
this->push_geometry(facet.vertex[j](0), facet.vertex[j](1), facet.vertex[j](2), facet.normal(0), facet.normal(1), facet.normal(2));
this->push_triangle(vertices_count, vertices_count + 1, vertices_count + 2);
vertices_count += 3;
@ -200,7 +195,8 @@ const float GLVolume::OUTSIDE_COLOR[4] = { 0.0f, 0.38f, 0.8f, 1.0f };
const float GLVolume::SELECTED_OUTSIDE_COLOR[4] = { 0.19f, 0.58f, 1.0f, 1.0f };
GLVolume::GLVolume(float r, float g, float b, float a)
: m_angle_z(0.0f)
: m_origin(0, 0, 0)
, m_angle_z(0.0f)
, m_scale_factor(1.0f)
, m_transformed_bounding_box_dirty(true)
, m_transformed_convex_hull_bounding_box_dirty(true)
@ -257,12 +253,12 @@ void GLVolume::set_render_color()
set_render_color(color, 4);
}
const Pointf3& GLVolume::get_origin() const
const Vec3d& GLVolume::get_origin() const
{
return m_origin;
}
void GLVolume::set_origin(const Pointf3& origin)
void GLVolume::set_origin(const Vec3d& origin)
{
if (m_origin != origin)
{
@ -297,15 +293,13 @@ void GLVolume::set_convex_hull(const TriangleMesh& convex_hull)
m_convex_hull = &convex_hull;
}
std::vector<float> GLVolume::world_matrix() const
Transform3d GLVolume::world_matrix() const
{
std::vector<float> world_mat(UNIT_MATRIX, std::end(UNIT_MATRIX));
Eigen::Transform<float, 3, Eigen::Affine> m = Eigen::Transform<float, 3, Eigen::Affine>::Identity();
m.translate(Eigen::Vector3f((float)m_origin.x, (float)m_origin.y, (float)m_origin.z));
m.rotate(Eigen::AngleAxisf(m_angle_z, Eigen::Vector3f::UnitZ()));
m.scale(m_scale_factor);
::memcpy((void*)world_mat.data(), (const void*)m.data(), 16 * sizeof(float));
return world_mat;
Transform3d matrix = Transform3d::Identity();
matrix.translate(m_origin);
matrix.rotate(Eigen::AngleAxisd((double)m_angle_z, Vec3d::UnitZ()));
matrix.scale((double)m_scale_factor);
return matrix;
}
BoundingBoxf3 GLVolume::transformed_bounding_box() const
@ -376,7 +370,7 @@ void GLVolume::render() const
::glCullFace(GL_BACK);
::glPushMatrix();
::glTranslated(m_origin.x, m_origin.y, m_origin.z);
::glTranslated(m_origin(0), m_origin(1), m_origin(2));
::glRotatef(m_angle_z * 180.0f / PI, 0.0f, 0.0f, 1.0f);
::glScalef(m_scale_factor, m_scale_factor, m_scale_factor);
if (this->indexed_vertex_array.indexed())
@ -410,7 +404,7 @@ void GLVolume::render_using_layer_height() const
glUniform1f(z_texture_row_to_normalized_id, (GLfloat)(1.0f / layer_height_texture_height()));
if (z_cursor_id >= 0)
glUniform1f(z_cursor_id, (GLfloat)(layer_height_texture_data.print_object->model_object()->bounding_box().max.z * layer_height_texture_data.z_cursor_relative));
glUniform1f(z_cursor_id, (GLfloat)(layer_height_texture_data.print_object->model_object()->bounding_box().max(2) * layer_height_texture_data.z_cursor_relative));
if (z_cursor_band_width_id >= 0)
glUniform1f(z_cursor_band_width_id, (GLfloat)layer_height_texture_data.edit_band_width);
@ -502,7 +496,7 @@ void GLVolume::render_VBOs(int color_id, int detection_id, int worldmatrix_id) c
::glNormalPointer(GL_FLOAT, 6 * sizeof(float), nullptr);
::glPushMatrix();
::glTranslated(m_origin.x, m_origin.y, m_origin.z);
::glTranslated(m_origin(0), m_origin(1), m_origin(2));
::glRotatef(m_angle_z * 180.0f / PI, 0.0f, 0.0f, 1.0f);
::glScalef(m_scale_factor, m_scale_factor, m_scale_factor);
@ -547,7 +541,7 @@ void GLVolume::render_legacy() const
::glNormalPointer(GL_FLOAT, 6 * sizeof(float), indexed_vertex_array.vertices_and_normals_interleaved.data());
::glPushMatrix();
::glTranslated(m_origin.x, m_origin.y, m_origin.z);
::glTranslated(m_origin(0), m_origin(1), m_origin(2));
::glRotatef(m_angle_z * 180.0f / PI, 0.0f, 0.0f, 1.0f);
::glScalef(m_scale_factor, m_scale_factor, m_scale_factor);
@ -562,7 +556,7 @@ void GLVolume::render_legacy() const
double GLVolume::layer_height_texture_z_to_row_id() const
{
return (this->layer_height_texture.get() == nullptr) ? 0.0 : double(this->layer_height_texture->cells - 1) / (double(this->layer_height_texture->width) * this->layer_height_texture_data.print_object->model_object()->bounding_box().max.z);
return (this->layer_height_texture.get() == nullptr) ? 0.0 : double(this->layer_height_texture->cells - 1) / (double(this->layer_height_texture->width) * this->layer_height_texture_data.print_object->model_object()->bounding_box().max(2));
}
void GLVolume::generate_layer_height_texture(PrintObject *print_object, bool force)
@ -667,7 +661,7 @@ std::vector<int> GLVolumeCollection::load_object(
}
v.is_modifier = model_volume->modifier;
v.shader_outside_printer_detection_enabled = !model_volume->modifier;
v.set_origin(Pointf3(instance->offset.x, instance->offset.y, 0.0));
v.set_origin(Vec3d(instance->offset(0), instance->offset(1), 0.0));
v.set_angle_z(instance->rotation);
v.set_scale_factor(instance->scaling_factor);
}
@ -698,16 +692,16 @@ int GLVolumeCollection::load_wipe_tower_preview(
// We'll now create the box with jagged edge. y-coordinates of the pre-generated model are shifted so that the front
// edge has y=0 and centerline of the back edge has y=depth:
Pointf3s points;
std::vector<Point3> facets;
std::vector<Vec3crd> facets;
float out_points_idx[][3] = {{0, -depth, 0}, {0, 0, 0}, {38.453, 0, 0}, {61.547, 0, 0}, {100, 0, 0}, {100, -depth, 0}, {55.7735, -10, 0}, {44.2265, 10, 0},
{38.453, 0, 1}, {0, 0, 1}, {0, -depth, 1}, {100, -depth, 1}, {100, 0, 1}, {61.547, 0, 1}, {55.7735, -10, 1}, {44.2265, 10, 1}};
int out_facets_idx[][3] = {{0, 1, 2}, {3, 4, 5}, {6, 5, 0}, {3, 5, 6}, {6, 2, 7}, {6, 0, 2}, {8, 9, 10}, {11, 12, 13}, {10, 11, 14}, {14, 11, 13}, {15, 8, 14},
{8, 10, 14}, {3, 12, 4}, {3, 13, 12}, {6, 13, 3}, {6, 14, 13}, {7, 14, 6}, {7, 15, 14}, {2, 15, 7}, {2, 8, 15}, {1, 8, 2}, {1, 9, 8},
{0, 9, 1}, {0, 10, 9}, {5, 10, 0}, {5, 11, 10}, {4, 11, 5}, {4, 12, 11}};
for (int i=0;i<16;++i)
points.push_back(Pointf3(out_points_idx[i][0] / (100.f/min_width), out_points_idx[i][1] + depth, out_points_idx[i][2]));
points.push_back(Vec3d(out_points_idx[i][0] / (100.f/min_width), out_points_idx[i][1] + depth, out_points_idx[i][2]));
for (int i=0;i<28;++i)
facets.push_back(Point3(out_facets_idx[i][0], out_facets_idx[i][1], out_facets_idx[i][2]));
facets.push_back(Vec3crd(out_facets_idx[i][0], out_facets_idx[i][1], out_facets_idx[i][2]));
TriangleMesh tooth_mesh(points, facets);
// We have the mesh ready. It has one tooth and width of min_width. We will now append several of these together until we are close to
@ -718,7 +712,7 @@ int GLVolumeCollection::load_wipe_tower_preview(
tooth_mesh.translate(min_width, 0.f, 0.f);
}
mesh.scale(Pointf3(width/(n*min_width), 1.f, height)); // Scaling to proper width
mesh.scale(Vec3d(width/(n*min_width), 1.f, height)); // Scaling to proper width
}
else
mesh = make_cube(width, depth, height);
@ -738,7 +732,7 @@ int GLVolumeCollection::load_wipe_tower_preview(
else
v.indexed_vertex_array.load_mesh_flat_shading(mesh);
v.set_origin(Pointf3(pos_x, pos_y, 0.));
v.set_origin(Vec3d(pos_x, pos_y, 0.));
// finalize_geometry() clears the vertex arrays, therefore the bounding box has to be computed before finalize_geometry().
v.bounding_box = v.indexed_vertex_array.bounding_box();
@ -824,9 +818,9 @@ bool GLVolumeCollection::check_outside_state(const DynamicPrintConfig* config, M
return false;
BoundingBox bed_box_2D = get_extents(Polygon::new_scale(opt->values));
BoundingBoxf3 print_volume(Pointf3(unscale(bed_box_2D.min.x), unscale(bed_box_2D.min.y), 0.0), Pointf3(unscale(bed_box_2D.max.x), unscale(bed_box_2D.max.y), config->opt_float("max_print_height")));
BoundingBoxf3 print_volume(unscale(bed_box_2D.min(0), bed_box_2D.min(1), 0.0), unscale(bed_box_2D.max(0), bed_box_2D.max(1), unscale<double>(config->opt_float("max_print_height"))));
// Allow the objects to protrude below the print bed
print_volume.min.z = -1e10;
print_volume.min(2) = -1e10;
ModelInstance::EPrintVolumeState state = ModelInstance::PVS_Inside;
bool all_contained = true;
@ -989,8 +983,8 @@ static void thick_lines_to_indexed_vertex_array(
// right, left, top, bottom
int idx_prev[4] = { -1, -1, -1, -1 };
double bottom_z_prev = 0.;
Pointf b1_prev;
Vectorf v_prev;
Vec2d b1_prev(Vec2d::Zero());
Vec2d v_prev(Vec2d::Zero());
int idx_initial[4] = { -1, -1, -1, -1 };
double width_initial = 0.;
double bottom_z_initial = 0.0;
@ -1000,7 +994,7 @@ static void thick_lines_to_indexed_vertex_array(
for (size_t ii = 0; ii < lines_end; ++ ii) {
size_t i = (ii == lines.size()) ? 0 : ii;
const Line &line = lines[i];
double len = unscale(line.length());
double len = unscale<double>(line.length());
double inv_len = 1.0 / len;
double bottom_z = top_z - heights[i];
double middle_z = 0.5 * (top_z + bottom_z);
@ -1010,29 +1004,29 @@ static void thick_lines_to_indexed_vertex_array(
bool is_last = (ii == lines_end - 1);
bool is_closing = closed && is_last;
Vectorf v = Vectorf::new_unscale(line.vector());
v.scale(inv_len);
Vec2d v = unscale(line.vector());
v *= inv_len;
Pointf a = Pointf::new_unscale(line.a);
Pointf b = Pointf::new_unscale(line.b);
Pointf a1 = a;
Pointf a2 = a;
Pointf b1 = b;
Pointf b2 = b;
Vec2d a = unscale(line.a);
Vec2d b = unscale(line.b);
Vec2d a1 = a;
Vec2d a2 = a;
Vec2d b1 = b;
Vec2d b2 = b;
{
double dist = 0.5 * width; // scaled
double dx = dist * v.x;
double dy = dist * v.y;
a1.translate(+dy, -dx);
a2.translate(-dy, +dx);
b1.translate(+dy, -dx);
b2.translate(-dy, +dx);
double dx = dist * v(0);
double dy = dist * v(1);
a1 += Vec2d(+dy, -dx);
a2 += Vec2d(-dy, +dx);
b1 += Vec2d(+dy, -dx);
b2 += Vec2d(-dy, +dx);
}
// calculate new XY normals
Vector n = line.normal();
Vectorf3 xy_right_normal = Vectorf3::new_unscale(n.x, n.y, 0);
xy_right_normal.scale(inv_len);
Vec3d xy_right_normal = unscale(n(0), n(1), 0);
xy_right_normal *= inv_len;
int idx_a[4];
int idx_b[4];
@ -1050,7 +1044,7 @@ static void thick_lines_to_indexed_vertex_array(
// Share top / bottom vertices if possible.
if (is_first) {
idx_a[TOP] = idx_last++;
volume.push_geometry(a.x, a.y, top_z , 0., 0., 1.);
volume.push_geometry(a(0), a(1), top_z , 0., 0., 1.);
} else {
idx_a[TOP] = idx_prev[TOP];
}
@ -1058,11 +1052,11 @@ static void thick_lines_to_indexed_vertex_array(
if (is_first || bottom_z_different) {
// Start of the 1st line segment or a change of the layer thickness while maintaining the print_z.
idx_a[BOTTOM] = idx_last ++;
volume.push_geometry(a.x, a.y, bottom_z, 0., 0., -1.);
volume.push_geometry(a(0), a(1), bottom_z, 0., 0., -1.);
idx_a[LEFT ] = idx_last ++;
volume.push_geometry(a2.x, a2.y, middle_z, -xy_right_normal.x, -xy_right_normal.y, -xy_right_normal.z);
volume.push_geometry(a2(0), a2(1), middle_z, -xy_right_normal(0), -xy_right_normal(1), -xy_right_normal(2));
idx_a[RIGHT] = idx_last ++;
volume.push_geometry(a1.x, a1.y, middle_z, xy_right_normal.x, xy_right_normal.y, xy_right_normal.z);
volume.push_geometry(a1(0), a1(1), middle_z, xy_right_normal(0), xy_right_normal(1), xy_right_normal(2));
}
else {
idx_a[BOTTOM] = idx_prev[BOTTOM];
@ -1076,16 +1070,16 @@ static void thick_lines_to_indexed_vertex_array(
} else {
// Continuing a previous segment.
// Share left / right vertices if possible.
double v_dot = dot(v_prev, v);
double v_dot = v_prev.dot(v);
bool sharp = v_dot < 0.707; // sin(45 degrees)
if (sharp) {
if (!bottom_z_different)
{
// Allocate new left / right points for the start of this segment as these points will receive their own normals to indicate a sharp turn.
idx_a[RIGHT] = idx_last++;
volume.push_geometry(a1.x, a1.y, middle_z, xy_right_normal.x, xy_right_normal.y, xy_right_normal.z);
volume.push_geometry(a1(0), a1(1), middle_z, xy_right_normal(0), xy_right_normal(1), xy_right_normal(2));
idx_a[LEFT] = idx_last++;
volume.push_geometry(a2.x, a2.y, middle_z, -xy_right_normal.x, -xy_right_normal.y, -xy_right_normal.z);
volume.push_geometry(a2(0), a2(1), middle_z, -xy_right_normal(0), -xy_right_normal(1), -xy_right_normal(2));
}
}
if (v_dot > 0.9) {
@ -1101,32 +1095,32 @@ static void thick_lines_to_indexed_vertex_array(
{
// Create a sharp corner with an overshot and average the left / right normals.
// At the crease angle of 45 degrees, the overshot at the corner will be less than (1-1/cos(PI/8)) = 8.2% over an arc.
Pointf intersection;
Vec2d intersection(Vec2d::Zero());
Geometry::ray_ray_intersection(b1_prev, v_prev, a1, v, intersection);
a1 = intersection;
a2 = 2. * a - intersection;
assert(length(a1.vector_to(a)) < width);
assert(length(a2.vector_to(a)) < width);
assert((a - a1).norm() < width);
assert((a - a2).norm() < width);
float *n_left_prev = volume.vertices_and_normals_interleaved.data() + idx_prev[LEFT ] * 6;
float *p_left_prev = n_left_prev + 3;
float *n_right_prev = volume.vertices_and_normals_interleaved.data() + idx_prev[RIGHT] * 6;
float *p_right_prev = n_right_prev + 3;
p_left_prev [0] = float(a2.x);
p_left_prev [1] = float(a2.y);
p_right_prev[0] = float(a1.x);
p_right_prev[1] = float(a1.y);
xy_right_normal.x += n_right_prev[0];
xy_right_normal.y += n_right_prev[1];
xy_right_normal.scale(1. / length(xy_right_normal));
n_left_prev [0] = float(-xy_right_normal.x);
n_left_prev [1] = float(-xy_right_normal.y);
n_right_prev[0] = float( xy_right_normal.x);
n_right_prev[1] = float( xy_right_normal.y);
p_left_prev [0] = float(a2(0));
p_left_prev [1] = float(a2(1));
p_right_prev[0] = float(a1(0));
p_right_prev[1] = float(a1(1));
xy_right_normal(0) += n_right_prev[0];
xy_right_normal(1) += n_right_prev[1];
xy_right_normal *= 1. / xy_right_normal.norm();
n_left_prev [0] = float(-xy_right_normal(0));
n_left_prev [1] = float(-xy_right_normal(1));
n_right_prev[0] = float( xy_right_normal(0));
n_right_prev[1] = float( xy_right_normal(1));
idx_a[LEFT ] = idx_prev[LEFT ];
idx_a[RIGHT] = idx_prev[RIGHT];
}
}
else if (cross(v_prev, v) > 0.) {
else if (cross2(v_prev, v) > 0.) {
// Right turn. Fill in the right turn wedge.
volume.push_triangle(idx_prev[RIGHT], idx_a [RIGHT], idx_prev[TOP] );
volume.push_triangle(idx_prev[RIGHT], idx_prev[BOTTOM], idx_a [RIGHT] );
@ -1162,20 +1156,20 @@ static void thick_lines_to_indexed_vertex_array(
idx_b[TOP] = idx_initial[TOP];
} else {
idx_b[TOP] = idx_last ++;
volume.push_geometry(b.x, b.y, top_z , 0., 0., 1.);
volume.push_geometry(b(0), b(1), top_z , 0., 0., 1.);
}
if (is_closing && (width == width_initial) && (bottom_z == bottom_z_initial)) {
idx_b[BOTTOM] = idx_initial[BOTTOM];
} else {
idx_b[BOTTOM] = idx_last ++;
volume.push_geometry(b.x, b.y, bottom_z, 0., 0., -1.);
volume.push_geometry(b(0), b(1), bottom_z, 0., 0., -1.);
}
// Generate new vertices for the end of this line segment.
idx_b[LEFT ] = idx_last ++;
volume.push_geometry(b2.x, b2.y, middle_z, -xy_right_normal.x, -xy_right_normal.y, -xy_right_normal.z);
volume.push_geometry(b2(0), b2(1), middle_z, -xy_right_normal(0), -xy_right_normal(1), -xy_right_normal(2));
idx_b[RIGHT ] = idx_last ++;
volume.push_geometry(b1.x, b1.y, middle_z, xy_right_normal.x, xy_right_normal.y, xy_right_normal.z);
volume.push_geometry(b1(0), b1(1), middle_z, xy_right_normal(0), xy_right_normal(1), xy_right_normal(2));
memcpy(idx_prev, idx_b, 4 * sizeof(int));
bottom_z_prev = bottom_z;
@ -1234,15 +1228,15 @@ static void thick_lines_to_indexed_vertex_array(const Lines3& lines,
int idx_initial[4] = { -1, -1, -1, -1 };
int idx_prev[4] = { -1, -1, -1, -1 };
double z_prev = 0.0;
Vectorf3 n_right_prev;
Vectorf3 n_top_prev;
Vectorf3 unit_v_prev;
Vec3d n_right_prev = Vec3d::Zero();
Vec3d n_top_prev = Vec3d::Zero();
Vec3d unit_v_prev = Vec3d::Zero();
double width_initial = 0.0;
// new vertices around the line endpoints
// left, right, top, bottom
Pointf3 a[4];
Pointf3 b[4];
Vec3d a[4] = { Vec3d::Zero(), Vec3d::Zero(), Vec3d::Zero(), Vec3d::Zero() };
Vec3d b[4] = { Vec3d::Zero(), Vec3d::Zero(), Vec3d::Zero(), Vec3d::Zero() };
// loop once more in case of closed loops
size_t lines_end = closed ? (lines.size() + 1) : lines.size();
@ -1254,29 +1248,29 @@ static void thick_lines_to_indexed_vertex_array(const Lines3& lines,
double height = heights[i];
double width = widths[i];
Vectorf3 unit_v = normalize(Vectorf3::new_unscale(line.vector()));
Vec3d unit_v = unscale(line.vector()).normalized();
Vectorf3 n_top;
Vectorf3 n_right;
Vectorf3 unit_positive_z(0.0, 0.0, 1.0);
Vec3d n_top = Vec3d::Zero();
Vec3d n_right = Vec3d::Zero();
Vec3d unit_positive_z(0.0, 0.0, 1.0);
if ((line.a.x == line.b.x) && (line.a.y == line.b.y))
if ((line.a(0) == line.b(0)) && (line.a(1) == line.b(1)))
{
// vertical segment
n_right = (line.a.z < line.b.z) ? Vectorf3(-1.0, 0.0, 0.0) : Vectorf3(1.0, 0.0, 0.0);
n_top = Vectorf3(0.0, 1.0, 0.0);
n_right = (line.a(2) < line.b(2)) ? Vec3d(-1.0, 0.0, 0.0) : Vec3d(1.0, 0.0, 0.0);
n_top = Vec3d(0.0, 1.0, 0.0);
}
else
{
// generic segment
n_right = normalize(cross(unit_v, unit_positive_z));
n_top = normalize(cross(n_right, unit_v));
n_right = unit_v.cross(unit_positive_z).normalized();
n_top = n_right.cross(unit_v).normalized();
}
Vectorf3 rl_displacement = 0.5 * width * n_right;
Vectorf3 tb_displacement = 0.5 * height * n_top;
Pointf3 l_a = Pointf3::new_unscale(line.a);
Pointf3 l_b = Pointf3::new_unscale(line.b);
Vec3d rl_displacement = 0.5 * width * n_right;
Vec3d tb_displacement = 0.5 * height * n_top;
Vec3d l_a = unscale(line.a);
Vec3d l_b = unscale(line.b);
a[RIGHT] = l_a + rl_displacement;
a[LEFT] = l_a - rl_displacement;
@ -1287,15 +1281,15 @@ static void thick_lines_to_indexed_vertex_array(const Lines3& lines,
b[TOP] = l_b + tb_displacement;
b[BOTTOM] = l_b - tb_displacement;
Vectorf3 n_bottom = -n_top;
Vectorf3 n_left = -n_right;
Vec3d n_bottom = -n_top;
Vec3d n_left = -n_right;
int idx_a[4];
int idx_b[4];
int idx_last = int(volume.vertices_and_normals_interleaved.size() / 6);
bool z_different = (z_prev != l_a.z);
z_prev = l_b.z;
bool z_different = (z_prev != l_a(2));
z_prev = l_b(2);
// Share top / bottom vertices if possible.
if (ii == 0)
@ -1329,9 +1323,9 @@ static void thick_lines_to_indexed_vertex_array(const Lines3& lines,
{
// Continuing a previous segment.
// Share left / right vertices if possible.
double v_dot = dot(unit_v_prev, unit_v);
double v_dot = unit_v_prev.dot(unit_v);
bool is_sharp = v_dot < 0.707; // sin(45 degrees)
bool is_right_turn = dot(n_top_prev, cross(unit_v_prev, unit_v)) > 0.0;
bool is_right_turn = n_top_prev.dot(unit_v_prev.cross(unit_v)) > 0.0;
if (is_sharp)
{
@ -1354,9 +1348,9 @@ static void thick_lines_to_indexed_vertex_array(const Lines3& lines,
// At the crease angle of 45 degrees, the overshot at the corner will be less than (1-1/cos(PI/8)) = 8.2% over an arc.
// averages normals
Vectorf3 average_n_right = normalize(0.5 * (n_right + n_right_prev));
Vectorf3 average_n_left = -average_n_right;
Vectorf3 average_rl_displacement = 0.5 * width * average_n_right;
Vec3d average_n_right = 0.5 * (n_right + n_right_prev).normalized();
Vec3d average_n_left = -average_n_right;
Vec3d average_rl_displacement = 0.5 * width * average_n_right;
// updates vertices around a
a[RIGHT] = l_a + average_rl_displacement;
@ -1364,25 +1358,25 @@ static void thick_lines_to_indexed_vertex_array(const Lines3& lines,
// updates previous line normals
float* normal_left_prev = volume.vertices_and_normals_interleaved.data() + idx_prev[LEFT] * 6;
normal_left_prev[0] = float(average_n_left.x);
normal_left_prev[1] = float(average_n_left.y);
normal_left_prev[2] = float(average_n_left.z);
normal_left_prev[0] = float(average_n_left(0));
normal_left_prev[1] = float(average_n_left(1));
normal_left_prev[2] = float(average_n_left(2));
float* normal_right_prev = volume.vertices_and_normals_interleaved.data() + idx_prev[RIGHT] * 6;
normal_right_prev[0] = float(average_n_right.x);
normal_right_prev[1] = float(average_n_right.y);
normal_right_prev[2] = float(average_n_right.z);
normal_right_prev[0] = float(average_n_right(0));
normal_right_prev[1] = float(average_n_right(1));
normal_right_prev[2] = float(average_n_right(2));
// updates previous line's vertices around b
float* b_left_prev = normal_left_prev + 3;
b_left_prev[0] = float(a[LEFT].x);
b_left_prev[1] = float(a[LEFT].y);
b_left_prev[2] = float(a[LEFT].z);
b_left_prev[0] = float(a[LEFT](0));
b_left_prev[1] = float(a[LEFT](1));
b_left_prev[2] = float(a[LEFT](2));
float* b_right_prev = normal_right_prev + 3;
b_right_prev[0] = float(a[RIGHT].x);
b_right_prev[1] = float(a[RIGHT].y);
b_right_prev[2] = float(a[RIGHT].z);
b_right_prev[0] = float(a[RIGHT](0));
b_right_prev[1] = float(a[RIGHT](1));
b_right_prev[2] = float(a[RIGHT](2));
idx_a[LEFT] = idx_prev[LEFT];
idx_a[RIGHT] = idx_prev[RIGHT];
@ -1479,14 +1473,14 @@ static void thick_lines_to_indexed_vertex_array(const Lines3& lines,
#undef BOTTOM
}
static void point_to_indexed_vertex_array(const Point3& point,
static void point_to_indexed_vertex_array(const Vec3crd& point,
double width,
double height,
GLIndexedVertexArray& volume)
{
// builds a double piramid, with vertices on the local axes, around the point
Pointf3 center = Pointf3::new_unscale(point);
Vec3d center = unscale(point);
double scale_factor = 1.0;
double w = scale_factor * width;
@ -1500,13 +1494,13 @@ static void point_to_indexed_vertex_array(const Point3& point,
idxs[i] = idx_last + i;
}
Vectorf3 displacement_x(w, 0.0, 0.0);
Vectorf3 displacement_y(0.0, w, 0.0);
Vectorf3 displacement_z(0.0, 0.0, h);
Vec3d displacement_x(w, 0.0, 0.0);
Vec3d displacement_y(0.0, w, 0.0);
Vec3d displacement_z(0.0, 0.0, h);
Vectorf3 unit_x(1.0, 0.0, 0.0);
Vectorf3 unit_y(0.0, 1.0, 0.0);
Vectorf3 unit_z(0.0, 0.0, 1.0);
Vec3d unit_x(1.0, 0.0, 0.0);
Vec3d unit_y(0.0, 1.0, 0.0);
Vec3d unit_z(0.0, 0.0, 1.0);
// vertices
volume.push_geometry(center - displacement_x, -unit_x); // idxs[0]
@ -1549,7 +1543,7 @@ void _3DScene::thick_lines_to_verts(const Lines3& lines,
thick_lines_to_indexed_vertex_array(lines, widths, heights, closed, volume.indexed_vertex_array);
}
static void thick_point_to_verts(const Point3& point,
static void thick_point_to_verts(const Vec3crd& point,
double width,
double height,
GLVolume& volume)
@ -1655,7 +1649,7 @@ void _3DScene::polyline3_to_verts(const Polyline3& polyline, double width, doubl
thick_lines_to_verts(lines, widths, heights, false, volume);
}
void _3DScene::point3_to_verts(const Point3& point, double width, double height, GLVolume& volume)
void _3DScene::point3_to_verts(const Vec3crd& point, double width, double height, GLVolume& volume)
{
thick_point_to_verts(point, width, height, volume);
}

View file

@ -119,8 +119,8 @@ public:
push_geometry(float(x), float(y), float(z), float(nx), float(ny), float(nz));
}
inline void push_geometry(const Pointf3& p, const Vectorf3& n) {
push_geometry(p.x, p.y, p.z, n.x, n.y, n.z);
inline void push_geometry(const Vec3d& p, const Vec3d& n) {
push_geometry(p(0), p(1), p(2), n(0), n(1), n(2));
}
inline void push_triangle(int idx1, int idx2, int idx3) {
@ -176,17 +176,17 @@ public:
BoundingBoxf3 bbox;
if (! this->vertices_and_normals_interleaved.empty()) {
bbox.defined = true;
bbox.min.x = bbox.max.x = this->vertices_and_normals_interleaved[3];
bbox.min.y = bbox.max.y = this->vertices_and_normals_interleaved[4];
bbox.min.z = bbox.max.z = this->vertices_and_normals_interleaved[5];
bbox.min(0) = bbox.max(0) = this->vertices_and_normals_interleaved[3];
bbox.min(1) = bbox.max(1) = this->vertices_and_normals_interleaved[4];
bbox.min(2) = bbox.max(2) = this->vertices_and_normals_interleaved[5];
for (size_t i = 9; i < this->vertices_and_normals_interleaved.size(); i += 6) {
const float *verts = this->vertices_and_normals_interleaved.data() + i;
bbox.min.x = std::min<coordf_t>(bbox.min.x, verts[0]);
bbox.min.y = std::min<coordf_t>(bbox.min.y, verts[1]);
bbox.min.z = std::min<coordf_t>(bbox.min.z, verts[2]);
bbox.max.x = std::max<coordf_t>(bbox.max.x, verts[0]);
bbox.max.y = std::max<coordf_t>(bbox.max.y, verts[1]);
bbox.max.z = std::max<coordf_t>(bbox.max.z, verts[2]);
bbox.min(0) = std::min<coordf_t>(bbox.min(0), verts[0]);
bbox.min(1) = std::min<coordf_t>(bbox.min(1), verts[1]);
bbox.min(2) = std::min<coordf_t>(bbox.min(2), verts[2]);
bbox.max(0) = std::max<coordf_t>(bbox.max(0), verts[0]);
bbox.max(1) = std::max<coordf_t>(bbox.max(1), verts[1]);
bbox.max(2) = std::max<coordf_t>(bbox.max(2), verts[2]);
}
}
return bbox;
@ -255,7 +255,7 @@ public:
private:
// Offset of the volume to be rendered.
Pointf3 m_origin;
Vec3d m_origin;
// Rotation around Z axis of the volume to be rendered.
float m_angle_z;
// Scale factor of the volume to be rendered.
@ -323,8 +323,8 @@ public:
// Sets render color in dependence of current state
void set_render_color();
const Pointf3& get_origin() const;
void set_origin(const Pointf3& origin);
const Vec3d& get_origin() const;
void set_origin(const Vec3d& origin);
void set_angle_z(float angle_z);
void set_scale_factor(float scale_factor);
void set_convex_hull(const TriangleMesh& convex_hull);
@ -333,7 +333,7 @@ public:
int volume_idx() const { return (this->composite_id / 1000) % 1000; }
int instance_idx() const { return this->composite_id % 1000; }
std::vector<float> world_matrix() const;
Transform3d world_matrix() const;
BoundingBoxf3 transformed_bounding_box() const;
BoundingBoxf3 transformed_convex_hull_bounding_box() const;
@ -577,7 +577,7 @@ public:
static void extrusionentity_to_verts(const ExtrusionEntityCollection& extrusion_entity_collection, float print_z, const Point& copy, GLVolume& volume);
static void extrusionentity_to_verts(const ExtrusionEntity* extrusion_entity, float print_z, const Point& copy, GLVolume& volume);
static void polyline3_to_verts(const Polyline3& polyline, double width, double height, GLVolume& volume);
static void point3_to_verts(const Point3& point, double width, double height, GLVolume& volume);
static void point3_to_verts(const Vec3crd& point, double width, double height, GLVolume& volume);
};
}

View file

@ -48,14 +48,14 @@ void BedShapePanel::build_panel(ConfigOptionPoints* default_pt)
auto optgroup = init_shape_options_page(_(L("Rectangular")));
ConfigOptionDef def;
def.type = coPoints;
def.default_value = new ConfigOptionPoints{ Pointf(200, 200) };
def.default_value = new ConfigOptionPoints{ Vec2d(200, 200) };
def.label = L("Size");
def.tooltip = L("Size in X and Y of the rectangular plate.");
Option option(def, "rect_size");
optgroup->append_single_option_line(option);
def.type = coPoints;
def.default_value = new ConfigOptionPoints{ Pointf(0, 0) };
def.default_value = new ConfigOptionPoints{ Vec2d(0, 0) };
def.label = L("Origin");
def.tooltip = L("Distance of the 0,0 G-code coordinate from the front left corner of the rectangle.");
option = Option(def, "rect_origin");
@ -149,21 +149,21 @@ void BedShapePanel::set_shape(ConfigOptionPoints* points)
// okay, it's a rectangle
// find origin
coordf_t x_min, x_max, y_min, y_max;
x_max = x_min = points->values[0].x;
y_max = y_min = points->values[0].y;
x_max = x_min = points->values[0](0);
y_max = y_min = points->values[0](1);
for (auto pt : points->values)
{
x_min = std::min(x_min, pt.x);
x_max = std::max(x_max, pt.x);
y_min = std::min(y_min, pt.y);
y_max = std::max(y_max, pt.y);
x_min = std::min(x_min, pt(0));
x_max = std::max(x_max, pt(0));
y_min = std::min(y_min, pt(1));
y_max = std::max(y_max, pt(1));
}
auto origin = new ConfigOptionPoints{ Pointf(-x_min, -y_min) };
auto origin = new ConfigOptionPoints{ Vec2d(-x_min, -y_min) };
m_shape_options_book->SetSelection(SHAPE_RECTANGULAR);
auto optgroup = m_optgroups[SHAPE_RECTANGULAR];
optgroup->set_value("rect_size", new ConfigOptionPoints{ Pointf(x_max - x_min, y_max - y_min) });//[x_max - x_min, y_max - y_min]);
optgroup->set_value("rect_size", new ConfigOptionPoints{ Vec2d(x_max - x_min, y_max - y_min) });//[x_max - x_min, y_max - y_min]);
optgroup->set_value("rect_origin", origin);
update_shape();
return;
@ -178,7 +178,7 @@ void BedShapePanel::set_shape(ConfigOptionPoints* points)
double avg_dist = 0;
for (auto pt: polygon.points)
{
double distance = center.distance_to(pt);
double distance = (pt - center).cast<double>().norm();
vertex_distances.push_back(distance);
avg_dist += distance;
}
@ -195,7 +195,7 @@ void BedShapePanel::set_shape(ConfigOptionPoints* points)
// all vertices are equidistant to center
m_shape_options_book->SetSelection(SHAPE_CIRCULAR);
auto optgroup = m_optgroups[SHAPE_CIRCULAR];
boost::any ret = wxNumberFormatter::ToString(unscale(avg_dist * 2), 0);
boost::any ret = wxNumberFormatter::ToString(unscale<double>(avg_dist * 2), 0);
optgroup->set_value("diameter", ret);
update_shape();
return;
@ -206,8 +206,8 @@ void BedShapePanel::set_shape(ConfigOptionPoints* points)
// Invalid polygon.Revert to default bed dimensions.
m_shape_options_book->SetSelection(SHAPE_RECTANGULAR);
auto optgroup = m_optgroups[SHAPE_RECTANGULAR];
optgroup->set_value("rect_size", new ConfigOptionPoints{ Pointf(200, 200) });
optgroup->set_value("rect_origin", new ConfigOptionPoints{ Pointf(0, 0) });
optgroup->set_value("rect_size", new ConfigOptionPoints{ Vec2d(200, 200) });
optgroup->set_value("rect_origin", new ConfigOptionPoints{ Vec2d(0, 0) });
update_shape();
return;
}
@ -230,19 +230,21 @@ void BedShapePanel::update_shape()
{
auto page_idx = m_shape_options_book->GetSelection();
if (page_idx == SHAPE_RECTANGULAR) {
Pointf rect_size, rect_origin;
Vec2d rect_size(Vec2d::Zero());
Vec2d rect_origin(Vec2d::Zero());
try{
rect_size = boost::any_cast<Pointf>(m_optgroups[SHAPE_RECTANGULAR]->get_value("rect_size")); }
rect_size = boost::any_cast<Vec2d>(m_optgroups[SHAPE_RECTANGULAR]->get_value("rect_size")); }
catch (const std::exception &e){
return;}
return;
}
try{
rect_origin = boost::any_cast<Pointf>(m_optgroups[SHAPE_RECTANGULAR]->get_value("rect_origin"));
rect_origin = boost::any_cast<Vec2d>(m_optgroups[SHAPE_RECTANGULAR]->get_value("rect_origin"));
}
catch (const std::exception &e){
return;}
auto x = rect_size.x;
auto y = rect_size.y;
auto x = rect_size(0);
auto y = rect_size(1);
// empty strings or '-' or other things
if (x == 0 || y == 0) return;
double x0 = 0.0;
@ -250,17 +252,17 @@ void BedShapePanel::update_shape()
double x1 = x;
double y1 = y;
auto dx = rect_origin.x;
auto dy = rect_origin.y;
auto dx = rect_origin(0);
auto dy = rect_origin(1);
x0 -= dx;
x1 -= dx;
y0 -= dy;
y1 -= dy;
m_canvas->m_bed_shape = { Pointf(x0, y0),
Pointf(x1, y0),
Pointf(x1, y1),
Pointf(x0, y1)};
m_canvas->m_bed_shape = { Vec2d(x0, y0),
Vec2d(x1, y0),
Vec2d(x1, y1),
Vec2d(x0, y1)};
}
else if(page_idx == SHAPE_CIRCULAR) {
double diameter;
@ -274,10 +276,10 @@ void BedShapePanel::update_shape()
auto r = diameter / 2;
auto twopi = 2 * PI;
auto edges = 60;
std::vector<Pointf> points;
std::vector<Vec2d> points;
for (size_t i = 1; i <= 60; ++i){
auto angle = i * twopi / edges;
points.push_back(Pointf(r*cos(angle), r*sin(angle)));
points.push_back(Vec2d(r*cos(angle), r*sin(angle)));
}
m_canvas->m_bed_shape = points;
}
@ -330,9 +332,9 @@ void BedShapePanel::load_stl()
}
auto polygon = expolygons[0].contour;
std::vector<Pointf> points;
std::vector<Vec2d> points;
for (auto pt : polygon.points)
points.push_back(Pointf::new_unscale(pt));
points.push_back(unscale(pt));
m_canvas->m_bed_shape = points;
update_preview();
}

View file

@ -34,7 +34,7 @@ public:
void load_stl();
// Returns the resulting bed shape polygon. This value will be stored to the ini file.
std::vector<Pointf> GetValue() { return m_canvas->m_bed_shape; }
std::vector<Vec2d> GetValue() { return m_canvas->m_bed_shape; }
};
class BedShapeDialog : public wxDialog
@ -46,7 +46,7 @@ public:
~BedShapeDialog(){ }
void build_dialog(ConfigOptionPoints* default_pt);
std::vector<Pointf> GetValue() { return m_panel->GetValue(); }
std::vector<Vec2d> GetValue() { return m_panel->GetValue(); }
};
} // GUI

View file

@ -632,9 +632,9 @@ void PointCtrl::BUILD()
wxSize field_size(40, -1);
auto default_pt = static_cast<ConfigOptionPoints*>(m_opt.default_value)->values.at(0);
double val = default_pt.x;
double val = default_pt(0);
wxString X = val - int(val) == 0 ? wxString::Format(_T("%i"), int(val)) : wxNumberFormatter::ToString(val, 2, wxNumberFormatter::Style_None);
val = default_pt.y;
val = default_pt(1);
wxString Y = val - int(val) == 0 ? wxString::Format(_T("%i"), int(val)) : wxNumberFormatter::ToString(val, 2, wxNumberFormatter::Style_None);
x_textctrl = new wxTextCtrl(m_parent, wxID_ANY, X, wxDefaultPosition, field_size);
@ -655,13 +655,13 @@ void PointCtrl::BUILD()
y_textctrl->SetToolTip(get_tooltip_text(X+", "+Y));
}
void PointCtrl::set_value(const Pointf& value, bool change_event)
void PointCtrl::set_value(const Vec2d& value, bool change_event)
{
m_disable_change_event = !change_event;
double val = value.x;
double val = value(0);
x_textctrl->SetValue(val - int(val) == 0 ? wxString::Format(_T("%i"), int(val)) : wxNumberFormatter::ToString(val, 2, wxNumberFormatter::Style_None));
val = value.y;
val = value(1);
y_textctrl->SetValue(val - int(val) == 0 ? wxString::Format(_T("%i"), int(val)) : wxNumberFormatter::ToString(val, 2, wxNumberFormatter::Style_None));
m_disable_change_event = false;
@ -669,8 +669,8 @@ void PointCtrl::set_value(const Pointf& value, bool change_event)
void PointCtrl::set_value(const boost::any& value, bool change_event)
{
Pointf pt;
const Pointf *ptf = boost::any_cast<Pointf>(&value);
Vec2d pt(Vec2d::Zero());
const Vec2d *ptf = boost::any_cast<Vec2d>(&value);
if (!ptf)
{
ConfigOptionPoints* pts = boost::any_cast<ConfigOptionPoints*>(value);
@ -683,13 +683,10 @@ void PointCtrl::set_value(const boost::any& value, bool change_event)
boost::any& PointCtrl::get_value()
{
Pointf ret_point;
double val;
x_textctrl->GetValue().ToDouble(&val);
ret_point.x = val;
y_textctrl->GetValue().ToDouble(&val);
ret_point.y = val;
return m_value = ret_point;
double x, y;
x_textctrl->GetValue().ToDouble(&x);
y_textctrl->GetValue().ToDouble(&y);
return m_value = Vec2d(x, y);
}
void StaticText::BUILD()

View file

@ -372,7 +372,7 @@ public:
void BUILD() override;
void set_value(const Pointf& value, bool change_event = false);
void set_value(const Vec2d& value, bool change_event = false);
void set_value(const boost::any& value, bool change_event = false);
boost::any& get_value() override;

View file

@ -71,8 +71,8 @@ bool GeometryBuffer::set_from_triangles(const Polygons& triangles, float z, bool
if (generate_tex_coords)
m_tex_coords = std::vector<float>(t_size, 0.0f);
float min_x = (float)unscale(triangles[0].points[0].x);
float min_y = (float)unscale(triangles[0].points[0].y);
float min_x = unscale<float>(triangles[0].points[0](0));
float min_y = unscale<float>(triangles[0].points[0](1));
float max_x = min_x;
float max_y = min_y;
@ -83,8 +83,8 @@ bool GeometryBuffer::set_from_triangles(const Polygons& triangles, float z, bool
for (unsigned int v = 0; v < 3; ++v)
{
const Point& p = t.points[v];
float x = (float)unscale(p.x);
float y = (float)unscale(p.y);
float x = unscale<float>(p(0));
float y = unscale<float>(p(1));
m_vertices[v_coord++] = x;
m_vertices[v_coord++] = y;
@ -137,11 +137,11 @@ bool GeometryBuffer::set_from_lines(const Lines& lines, float z)
unsigned int coord = 0;
for (const Line& l : lines)
{
m_vertices[coord++] = (float)unscale(l.a.x);
m_vertices[coord++] = (float)unscale(l.a.y);
m_vertices[coord++] = unscale<float>(l.a(0));
m_vertices[coord++] = unscale<float>(l.a(1));
m_vertices[coord++] = z;
m_vertices[coord++] = (float)unscale(l.b.x);
m_vertices[coord++] = (float)unscale(l.b.y);
m_vertices[coord++] = unscale<float>(l.b(0));
m_vertices[coord++] = unscale<float>(l.b(1));
m_vertices[coord++] = z;
}
@ -317,9 +317,9 @@ bool GLCanvas3D::Bed::set_shape(const Pointfs& shape)
_calc_bounding_box();
ExPolygon poly;
for (const Pointf& p : m_shape)
for (const Vec2d& p : m_shape)
{
poly.contour.append(Point(scale_(p.x), scale_(p.y)));
poly.contour.append(Point(scale_(p(0)), scale_(p(1))));
}
_calc_triangles(poly);
@ -373,9 +373,9 @@ void GLCanvas3D::Bed::render(float theta) const
void GLCanvas3D::Bed::_calc_bounding_box()
{
m_bounding_box = BoundingBoxf3();
for (const Pointf& p : m_shape)
for (const Vec2d& p : m_shape)
{
m_bounding_box.merge(Pointf3(p.x, p.y, 0.0));
m_bounding_box.merge(Vec3d(p(0), p(1), 0.0));
}
}
@ -391,18 +391,18 @@ void GLCanvas3D::Bed::_calc_triangles(const ExPolygon& poly)
void GLCanvas3D::Bed::_calc_gridlines(const ExPolygon& poly, const BoundingBox& bed_bbox)
{
Polylines axes_lines;
for (coord_t x = bed_bbox.min.x; x <= bed_bbox.max.x; x += scale_(10.0))
for (coord_t x = bed_bbox.min(0); x <= bed_bbox.max(0); x += scale_(10.0))
{
Polyline line;
line.append(Point(x, bed_bbox.min.y));
line.append(Point(x, bed_bbox.max.y));
line.append(Point(x, bed_bbox.min(1)));
line.append(Point(x, bed_bbox.max(1)));
axes_lines.push_back(line);
}
for (coord_t y = bed_bbox.min.y; y <= bed_bbox.max.y; y += scale_(10.0))
for (coord_t y = bed_bbox.min(1); y <= bed_bbox.max(1); y += scale_(10.0))
{
Polyline line;
line.append(Point(bed_bbox.min.x, y));
line.append(Point(bed_bbox.max.x, y));
line.append(Point(bed_bbox.min(0), y));
line.append(Point(bed_bbox.max(0), y));
axes_lines.push_back(line);
}
@ -591,7 +591,7 @@ bool GLCanvas3D::Bed::_are_equal(const Pointfs& bed_1, const Pointfs& bed_2)
}
GLCanvas3D::Axes::Axes()
: length(0.0f)
: origin(0, 0, 0), length(0.0f)
{
}
@ -606,12 +606,12 @@ void GLCanvas3D::Axes::render(bool depth_test) const
::glBegin(GL_LINES);
// draw line for x axis
::glColor3f(1.0f, 0.0f, 0.0f);
::glVertex3f((GLfloat)origin.x, (GLfloat)origin.y, (GLfloat)origin.z);
::glVertex3f((GLfloat)origin.x + length, (GLfloat)origin.y, (GLfloat)origin.z);
::glVertex3f((GLfloat)origin(0), (GLfloat)origin(1), (GLfloat)origin(2));
::glVertex3f((GLfloat)origin(0) + length, (GLfloat)origin(1), (GLfloat)origin(2));
// draw line for y axis
::glColor3f(0.0f, 1.0f, 0.0f);
::glVertex3f((GLfloat)origin.x, (GLfloat)origin.y, (GLfloat)origin.z);
::glVertex3f((GLfloat)origin.x, (GLfloat)origin.y + length, (GLfloat)origin.z);
::glVertex3f((GLfloat)origin(0), (GLfloat)origin(1), (GLfloat)origin(2));
::glVertex3f((GLfloat)origin(0), (GLfloat)origin(1) + length, (GLfloat)origin(2));
::glEnd();
// draw line for Z axis
// (re-enable depth test so that axis is correctly shown when objects are behind it)
@ -620,8 +620,8 @@ void GLCanvas3D::Axes::render(bool depth_test) const
::glBegin(GL_LINES);
::glColor3f(0.0f, 0.0f, 1.0f);
::glVertex3f((GLfloat)origin.x, (GLfloat)origin.y, (GLfloat)origin.z);
::glVertex3f((GLfloat)origin.x, (GLfloat)origin.y, (GLfloat)origin.z + length);
::glVertex3f((GLfloat)origin(0), (GLfloat)origin(1), (GLfloat)origin(2));
::glVertex3f((GLfloat)origin(0), (GLfloat)origin(1), (GLfloat)origin(2) + length);
::glEnd();
}
@ -655,10 +655,10 @@ void GLCanvas3D::CuttingPlane::_render_plane(const BoundingBoxf3& bb) const
::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
float margin = 20.0f;
float min_x = bb.min.x - margin;
float max_x = bb.max.x + margin;
float min_y = bb.min.y - margin;
float max_y = bb.max.y + margin;
float min_x = bb.min(0) - margin;
float max_x = bb.max(0) + margin;
float min_y = bb.min(1) - margin;
float max_y = bb.max(1) + margin;
::glBegin(GL_QUADS);
::glColor4f(0.8f, 0.8f, 0.8f, 0.5f);
@ -869,8 +869,8 @@ float GLCanvas3D::LayersEditing::get_cursor_z_relative(const GLCanvas3D& canvas)
{
const Point& mouse_pos = canvas.get_local_mouse_position();
const Rect& rect = get_bar_rect_screen(canvas);
float x = (float)mouse_pos.x;
float y = (float)mouse_pos.y;
float x = (float)mouse_pos(0);
float y = (float)mouse_pos(1);
float t = rect.get_top();
float b = rect.get_bottom();
@ -979,7 +979,7 @@ void GLCanvas3D::LayersEditing::_render_reset_texture(const Rect& reset_rect) co
void GLCanvas3D::LayersEditing::_render_active_object_annotations(const GLCanvas3D& canvas, const GLVolume& volume, const PrintObject& print_object, const Rect& bar_rect) const
{
float max_z = print_object.model_object()->bounding_box().max.z;
float max_z = print_object.model_object()->bounding_box().max(2);
m_shader.start_using();
@ -1040,7 +1040,7 @@ void GLCanvas3D::LayersEditing::_render_profile(const PrintObject& print_object,
// Make the vertical bar a bit wider so the layer height curve does not touch the edge of the bar region.
layer_height_max *= 1.12;
coordf_t max_z = unscale(print_object.size.z);
coordf_t max_z = unscale<double>(print_object.size(2));
double layer_height = dynamic_cast<const ConfigOptionFloat*>(print_object.config.option("layer_height"))->value;
float l = bar_rect.get_left();
float w = bar_rect.get_right() - l;
@ -1075,11 +1075,12 @@ void GLCanvas3D::LayersEditing::_render_profile(const PrintObject& print_object,
}
const Point GLCanvas3D::Mouse::Drag::Invalid_2D_Point(INT_MAX, INT_MAX);
const Pointf3 GLCanvas3D::Mouse::Drag::Invalid_3D_Point(DBL_MAX, DBL_MAX, DBL_MAX);
const Vec3d GLCanvas3D::Mouse::Drag::Invalid_3D_Point(DBL_MAX, DBL_MAX, DBL_MAX);
GLCanvas3D::Mouse::Drag::Drag()
: start_position_2D(Invalid_2D_Point)
, start_position_3D(Invalid_3D_Point)
, volume_center_offset(0, 0, 0)
, move_with_shift(false)
, move_volume_idx(-1)
, gizmo_volume_idx(-1)
@ -1175,7 +1176,7 @@ void GLCanvas3D::Gizmos::set_enabled(bool enable)
m_enabled = enable;
}
void GLCanvas3D::Gizmos::update_hover_state(const GLCanvas3D& canvas, const Pointf& mouse_pos)
void GLCanvas3D::Gizmos::update_hover_state(const GLCanvas3D& canvas, const Vec2d& mouse_pos)
{
if (!m_enabled)
return;
@ -1194,14 +1195,14 @@ void GLCanvas3D::Gizmos::update_hover_state(const GLCanvas3D& canvas, const Poin
// we currently use circular icons for gizmo, so we check the radius
if (it->second->get_state() != GLGizmoBase::On)
{
bool inside = length(Pointf(OverlayOffsetX + half_tex_size, top_y + half_tex_size).vector_to(mouse_pos)) < half_tex_size;
bool inside = (mouse_pos - Vec2d(OverlayOffsetX + half_tex_size, top_y + half_tex_size)).norm() < half_tex_size;
it->second->set_state(inside ? GLGizmoBase::Hover : GLGizmoBase::Off);
}
top_y += (tex_size + OverlayGapY);
}
}
void GLCanvas3D::Gizmos::update_on_off_state(const GLCanvas3D& canvas, const Pointf& mouse_pos)
void GLCanvas3D::Gizmos::update_on_off_state(const GLCanvas3D& canvas, const Vec2d& mouse_pos)
{
if (!m_enabled)
return;
@ -1218,7 +1219,7 @@ void GLCanvas3D::Gizmos::update_on_off_state(const GLCanvas3D& canvas, const Poi
float half_tex_size = 0.5f * tex_size;
// we currently use circular icons for gizmo, so we check the radius
if (length(Pointf(OverlayOffsetX + half_tex_size, top_y + half_tex_size).vector_to(mouse_pos)) < half_tex_size)
if ((mouse_pos - Vec2d(OverlayOffsetX + half_tex_size, top_y + half_tex_size)).norm() < half_tex_size)
{
if ((it->second->get_state() == GLGizmoBase::On))
{
@ -1267,7 +1268,7 @@ void GLCanvas3D::Gizmos::set_hover_id(int id)
}
}
bool GLCanvas3D::Gizmos::overlay_contains_mouse(const GLCanvas3D& canvas, const Pointf& mouse_pos) const
bool GLCanvas3D::Gizmos::overlay_contains_mouse(const GLCanvas3D& canvas, const Vec2d& mouse_pos) const
{
if (!m_enabled)
return false;
@ -1284,7 +1285,7 @@ bool GLCanvas3D::Gizmos::overlay_contains_mouse(const GLCanvas3D& canvas, const
float half_tex_size = 0.5f * tex_size;
// we currently use circular icons for gizmo, so we check the radius
if (length(Pointf(OverlayOffsetX + half_tex_size, top_y + half_tex_size).vector_to(mouse_pos)) < half_tex_size)
if ((mouse_pos - Vec2d(OverlayOffsetX + half_tex_size, top_y + half_tex_size)).norm() < half_tex_size)
return true;
top_y += (tex_size + OverlayGapY);
@ -2078,7 +2079,7 @@ void GLCanvas3D::set_bed_shape(const Pointfs& shape)
bool new_shape = m_bed.set_shape(shape);
// Set the origin and size for painting of the coordinate system axes.
m_axes.origin = Pointf3(0.0, 0.0, (coordf_t)GROUND_Z);
m_axes.origin = Vec3d(0.0, 0.0, (coordf_t)GROUND_Z);
set_axes_length(0.3f * (float)m_bed.get_bounding_box().max_size());
if (new_shape)
@ -2098,19 +2099,19 @@ void GLCanvas3D::set_auto_bed_shape()
// draw a default square bed around object center
const BoundingBoxf3& bbox = volumes_bounding_box();
coordf_t max_size = bbox.max_size();
const Pointf3& center = bbox.center();
const Vec3d center = bbox.center();
Pointfs bed_shape;
bed_shape.reserve(4);
bed_shape.emplace_back(center.x - max_size, center.y - max_size);
bed_shape.emplace_back(center.x + max_size, center.y - max_size);
bed_shape.emplace_back(center.x + max_size, center.y + max_size);
bed_shape.emplace_back(center.x - max_size, center.y + max_size);
bed_shape.emplace_back(center(0) - max_size, center(1) - max_size);
bed_shape.emplace_back(center(0) + max_size, center(1) - max_size);
bed_shape.emplace_back(center(0) + max_size, center(1) + max_size);
bed_shape.emplace_back(center(0) - max_size, center(1) + max_size);
set_bed_shape(bed_shape);
// Set the origin for painting of the coordinate system axes.
m_axes.origin = Pointf3(center.x, center.y, (coordf_t)GROUND_Z);
m_axes.origin = Vec3d(center(0), center(1), (coordf_t)GROUND_Z);
}
void GLCanvas3D::set_axes_length(float length)
@ -2462,7 +2463,7 @@ void GLCanvas3D::reload_scene(bool force)
if ((extruders_count > 1) && semm && wt && !co)
{
// Height of a print (Show at least a slab)
coordf_t height = std::max(m_model->bounding_box().max.z, 10.0);
coordf_t height = std::max(m_model->bounding_box().max(2), 10.0);
float x = dynamic_cast<const ConfigOptionFloat*>(m_config->option("wipe_tower_x"))->value;
float y = dynamic_cast<const ConfigOptionFloat*>(m_config->option("wipe_tower_y"))->value;
@ -2948,7 +2949,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
else if (evt.Leaving())
{
// to remove hover on objects when the mouse goes out of this canvas
m_mouse.position = Pointf(-1.0, -1.0);
m_mouse.position = Vec2d(-1.0, -1.0);
m_dirty = true;
}
else if (evt.LeftDClick() && (m_hover_volume_id != -1))
@ -2964,14 +2965,14 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
// on a volume or not.
int volume_idx = m_hover_volume_id;
m_layers_editing.state = LayersEditing::Unknown;
if ((layer_editing_object_idx != -1) && m_layers_editing.bar_rect_contains(*this, pos.x, pos.y))
if ((layer_editing_object_idx != -1) && m_layers_editing.bar_rect_contains(*this, pos(0), pos(1)))
{
// A volume is selected and the mouse is inside the layer thickness bar.
// Start editing the layer height.
m_layers_editing.state = LayersEditing::Editing;
_perform_layer_editing_action(&evt);
}
else if ((layer_editing_object_idx != -1) && m_layers_editing.reset_rect_contains(*this, pos.x, pos.y))
else if ((layer_editing_object_idx != -1) && m_layers_editing.reset_rect_contains(*this, pos(0), pos(1)))
{
if (evt.LeftDown())
{
@ -3039,7 +3040,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
{
// The mouse_to_3d gets the Z coordinate from the Z buffer at the screen coordinate pos x, y,
// an converts the screen space coordinate to unscaled object space.
Pointf3 pos3d = (volume_idx == -1) ? Pointf3(DBL_MAX, DBL_MAX) : _mouse_to_3d(pos);
Vec3d pos3d = (volume_idx == -1) ? Vec3d(DBL_MAX, DBL_MAX, DBL_MAX) : _mouse_to_3d(pos);
// Only accept the initial position, if it is inside the volume bounding box.
BoundingBoxf3 volume_bbox = m_volumes.volumes[volume_idx]->transformed_bounding_box();
@ -3052,20 +3053,20 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
m_mouse.drag.start_position_3D = pos3d;
// Remember the shift to to the object center.The object center will later be used
// to limit the object placement close to the bed.
m_mouse.drag.volume_center_offset = pos3d.vector_to(volume_bbox.center());
m_mouse.drag.volume_center_offset = volume_bbox.center() - pos3d;
}
}
else if (evt.RightDown())
{
// forces a frame render to ensure that m_hover_volume_id is updated even when the user right clicks while
// the context menu is already shown, ensuring it to disappear if the mouse is outside any volume
m_mouse.position = Pointf((coordf_t)pos.x, (coordf_t)pos.y);
m_mouse.position = Vec2d((double)pos(0), (double)pos(1));
render();
if (m_hover_volume_id != -1)
{
// if right clicking on volume, propagate event through callback (shows context menu)
if (m_volumes.volumes[volume_idx]->hover)
m_on_right_click_callback.call(pos.x, pos.y);
m_on_right_click_callback.call(pos(0), pos(1));
}
}
}
@ -3078,21 +3079,21 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
// Get new position at the same Z of the initial click point.
float z0 = 0.0f;
float z1 = 1.0f;
Pointf3 cur_pos = Linef3(_mouse_to_3d(pos, &z0), _mouse_to_3d(pos, &z1)).intersect_plane(m_mouse.drag.start_position_3D.z);
Vec3d cur_pos = Linef3(_mouse_to_3d(pos, &z0), _mouse_to_3d(pos, &z1)).intersect_plane(m_mouse.drag.start_position_3D(2));
// Clip the new position, so the object center remains close to the bed.
cur_pos.translate(m_mouse.drag.volume_center_offset);
Point cur_pos2(scale_(cur_pos.x), scale_(cur_pos.y));
cur_pos += m_mouse.drag.volume_center_offset;
Point cur_pos2(scale_(cur_pos(0)), scale_(cur_pos(1)));
if (!m_bed.contains(cur_pos2))
{
Point ip = m_bed.point_projection(cur_pos2);
cur_pos.x = unscale(ip.x);
cur_pos.y = unscale(ip.y);
cur_pos(0) = unscale<double>(ip(0));
cur_pos(1) = unscale<double>(ip(1));
}
cur_pos.translate(m_mouse.drag.volume_center_offset.negative());
cur_pos -= m_mouse.drag.volume_center_offset;
// Calculate the translation vector.
Vectorf3 vector = m_mouse.drag.start_position_3D.vector_to(cur_pos);
Vec3d vector = cur_pos - m_mouse.drag.start_position_3D;
// Get the volume being dragged.
GLVolume* volume = m_volumes.volumes[m_mouse.drag.move_volume_idx];
// Get all volumes belonging to the same group, if any.
@ -3114,11 +3115,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
// Apply new temporary volume origin and ignore Z.
for (GLVolume* v : volumes)
{
Pointf3 origin = v->get_origin();
origin.translate(vector.x, vector.y, 0.0);
v->set_origin(origin);
}
v->set_origin(v->get_origin() + Vec3d(vector(0), vector(1), 0.0));
m_mouse.drag.start_position_3D = cur_pos;
m_gizmos.refresh();
@ -3180,8 +3177,8 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
{
bb.merge(volume->transformed_bounding_box());
}
const Pointf3& size = bb.size();
m_on_update_geometry_info_callback.call(size.x, size.y, size.z, m_gizmos.get_scale());
const Vec3d& size = bb.size();
m_on_update_geometry_info_callback.call(size(0), size(1), size(2), m_gizmos.get_scale());
}
if ((m_gizmos.get_current_type() != Gizmos::Rotate) && (volumes.size() > 1))
@ -3203,15 +3200,15 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
// if dragging over blank area with left button, rotate
if (m_mouse.is_start_position_3D_defined())
{
const Pointf3& orig = m_mouse.drag.start_position_3D;
m_camera.phi += (((float)pos.x - (float)orig.x) * TRACKBALLSIZE);
m_camera.set_theta(m_camera.get_theta() - ((float)pos.y - (float)orig.y) * TRACKBALLSIZE);
const Vec3d& orig = m_mouse.drag.start_position_3D;
m_camera.phi += (((float)pos(0) - (float)orig(0)) * TRACKBALLSIZE);
m_camera.set_theta(m_camera.get_theta() - ((float)pos(1) - (float)orig(1)) * TRACKBALLSIZE);
m_on_viewport_changed_callback.call();
m_dirty = true;
}
m_mouse.drag.start_position_3D = Pointf3((coordf_t)pos.x, (coordf_t)pos.y, 0.0);
m_mouse.drag.start_position_3D = Vec3d((coordf_t)pos(0), (coordf_t)pos(1), 0.0);
}
else if (evt.MiddleIsDown() || evt.RightIsDown())
{
@ -3220,11 +3217,9 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
{
// get point in model space at Z = 0
float z = 0.0f;
const Pointf3& cur_pos = _mouse_to_3d(pos, &z);
Pointf3 orig = _mouse_to_3d(m_mouse.drag.start_position_2D, &z);
Pointf3 camera_target = m_camera.target;
camera_target.translate(orig.vector_to(cur_pos).negative());
m_camera.target = camera_target;
const Vec3d& cur_pos = _mouse_to_3d(pos, &z);
Vec3d orig = _mouse_to_3d(m_mouse.drag.start_position_2D, &z);
m_camera.target += orig - cur_pos;
m_on_viewport_changed_callback.call();
@ -3307,7 +3302,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
}
else if (evt.Moving())
{
m_mouse.position = Pointf((coordf_t)pos.x, (coordf_t)pos.y);
m_mouse.position = Vec2d((coordf_t)pos(0), (coordf_t)pos(1));
// Only refresh if picking is enabled, in that case the objects may get highlighted if the mouse cursor hovers over.
if (m_picking_enabled)
m_dirty = true;
@ -3676,25 +3671,25 @@ float GLCanvas3D::_get_zoom_to_bounding_box_factor(const BoundingBoxf3& bbox) co
::glGetFloatv(GL_MODELVIEW_MATRIX, matrix);
// camera axes
Pointf3 right((coordf_t)matrix[0], (coordf_t)matrix[4], (coordf_t)matrix[8]);
Pointf3 up((coordf_t)matrix[1], (coordf_t)matrix[5], (coordf_t)matrix[9]);
Pointf3 forward((coordf_t)matrix[2], (coordf_t)matrix[6], (coordf_t)matrix[10]);
Vec3d right((coordf_t)matrix[0], (coordf_t)matrix[4], (coordf_t)matrix[8]);
Vec3d up((coordf_t)matrix[1], (coordf_t)matrix[5], (coordf_t)matrix[9]);
Vec3d forward((coordf_t)matrix[2], (coordf_t)matrix[6], (coordf_t)matrix[10]);
Pointf3 bb_min = bbox.min;
Pointf3 bb_max = bbox.max;
Pointf3 bb_center = bbox.center();
Vec3d bb_min = bbox.min;
Vec3d bb_max = bbox.max;
Vec3d bb_center = bbox.center();
// bbox vertices in world space
std::vector<Pointf3> vertices;
std::vector<Vec3d> vertices;
vertices.reserve(8);
vertices.push_back(bb_min);
vertices.emplace_back(bb_max.x, bb_min.y, bb_min.z);
vertices.emplace_back(bb_max.x, bb_max.y, bb_min.z);
vertices.emplace_back(bb_min.x, bb_max.y, bb_min.z);
vertices.emplace_back(bb_min.x, bb_min.y, bb_max.z);
vertices.emplace_back(bb_max.x, bb_min.y, bb_max.z);
vertices.emplace_back(bb_max(0), bb_min(1), bb_min(2));
vertices.emplace_back(bb_max(0), bb_max(1), bb_min(2));
vertices.emplace_back(bb_min(0), bb_max(1), bb_min(2));
vertices.emplace_back(bb_min(0), bb_min(1), bb_max(2));
vertices.emplace_back(bb_max(0), bb_min(1), bb_max(2));
vertices.push_back(bb_max);
vertices.emplace_back(bb_min.x, bb_max.y, bb_max.z);
vertices.emplace_back(bb_min(0), bb_max(1), bb_max(2));
coordf_t max_x = 0.0;
coordf_t max_y = 0.0;
@ -3702,15 +3697,15 @@ float GLCanvas3D::_get_zoom_to_bounding_box_factor(const BoundingBoxf3& bbox) co
// margin factor to give some empty space around the bbox
coordf_t margin_factor = 1.25;
for (const Pointf3 v : vertices)
for (const Vec3d v : vertices)
{
// project vertex on the plane perpendicular to camera forward axis
Pointf3 pos(v.x - bb_center.x, v.y - bb_center.y, v.z - bb_center.z);
Pointf3 proj_on_plane = pos - dot(pos, forward) * forward;
Vec3d pos(v(0) - bb_center(0), v(1) - bb_center(1), v(2) - bb_center(2));
Vec3d proj_on_plane = pos - pos.dot(forward) * forward;
// calculates vertex coordinate along camera xy axes
coordf_t x_on_plane = dot(proj_on_plane, right);
coordf_t y_on_plane = dot(proj_on_plane, up);
coordf_t x_on_plane = proj_on_plane.dot(right);
coordf_t y_on_plane = proj_on_plane.dot(up);
max_x = std::max(max_x, margin_factor * std::abs(x_on_plane));
max_y = std::max(max_y, margin_factor * std::abs(y_on_plane));
@ -3802,15 +3797,15 @@ void GLCanvas3D::_camera_tranform() const
::glRotatef(-m_camera.get_theta(), 1.0f, 0.0f, 0.0f); // pitch
::glRotatef(m_camera.phi, 0.0f, 0.0f, 1.0f); // yaw
Pointf3 neg_target = m_camera.target.negative();
::glTranslatef((GLfloat)neg_target.x, (GLfloat)neg_target.y, (GLfloat)neg_target.z);
Vec3d neg_target = - m_camera.target;
::glTranslatef((GLfloat)neg_target(0), (GLfloat)neg_target(1), (GLfloat)neg_target(2));
}
void GLCanvas3D::_picking_pass() const
{
const Pointf& pos = m_mouse.position;
const Vec2d& pos = m_mouse.position;
if (m_picking_enabled && !m_mouse.dragging && (pos != Pointf(DBL_MAX, DBL_MAX)))
if (m_picking_enabled && !m_mouse.dragging && (pos != Vec2d(DBL_MAX, DBL_MAX)))
{
// Render the object for picking.
// FIXME This cannot possibly work in a multi - sampled context as the color gets mangled by the anti - aliasing.
@ -3838,10 +3833,10 @@ void GLCanvas3D::_picking_pass() const
GLubyte color[4] = { 0, 0, 0, 0 };
const Size& cnv_size = get_canvas_size();
bool inside = (0 <= pos.x) && (pos.x < cnv_size.get_width()) && (0 <= pos.y) && (pos.y < cnv_size.get_height());
bool inside = (0 <= pos(0)) && (pos(0) < cnv_size.get_width()) && (0 <= pos(1)) && (pos(1) < cnv_size.get_height());
if (inside)
{
::glReadPixels(pos.x, cnv_size.get_height() - pos.y - 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, (void*)color);
::glReadPixels(pos(0), cnv_size.get_height() - pos(1) - 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, (void*)color);
volume_id = color[0] + color[1] * 256 + color[2] * 256 * 256;
}
@ -3939,7 +3934,7 @@ void GLCanvas3D::_render_objects() const
if (m_config != nullptr)
{
const BoundingBoxf3& bed_bb = m_bed.get_bounding_box();
m_volumes.set_print_box((float)bed_bb.min.x, (float)bed_bb.min.y, 0.0f, (float)bed_bb.max.x, (float)bed_bb.max.y, (float)m_config->opt_float("max_print_height"));
m_volumes.set_print_box((float)bed_bb.min(0), (float)bed_bb.min(1), 0.0f, (float)bed_bb.max(0), (float)bed_bb.max(1), (float)m_config->opt_float("max_print_height"));
m_volumes.check_outside_state(m_config, nullptr);
}
// do not cull backfaces to show broken geometry, if any
@ -4107,7 +4102,7 @@ void GLCanvas3D::_perform_layer_editing_action(wxMouseEvent* evt)
{
const Rect& rect = LayersEditing::get_bar_rect_screen(*this);
float b = rect.get_bottom();
m_layers_editing.last_z = unscale(selected_obj->size.z) * (b - evt->GetY() - 1.0f) / (b - rect.get_top());
m_layers_editing.last_z = unscale<double>(selected_obj->size(2)) * (b - evt->GetY() - 1.0f) / (b - rect.get_top());
m_layers_editing.last_action = evt->ShiftDown() ? (evt->RightIsDown() ? 3 : 2) : (evt->RightIsDown() ? 0 : 1);
}
@ -4137,10 +4132,10 @@ void GLCanvas3D::_perform_layer_editing_action(wxMouseEvent* evt)
_start_timer();
}
Pointf3 GLCanvas3D::_mouse_to_3d(const Point& mouse_pos, float* z)
Vec3d GLCanvas3D::_mouse_to_3d(const Point& mouse_pos, float* z)
{
if (m_canvas == nullptr)
return Pointf3(DBL_MAX, DBL_MAX, DBL_MAX);
return Vec3d(DBL_MAX, DBL_MAX, DBL_MAX);
_camera_tranform();
@ -4151,19 +4146,19 @@ Pointf3 GLCanvas3D::_mouse_to_3d(const Point& mouse_pos, float* z)
GLdouble projection_matrix[16];
::glGetDoublev(GL_PROJECTION_MATRIX, projection_matrix);
GLint y = viewport[3] - (GLint)mouse_pos.y;
GLint y = viewport[3] - (GLint)mouse_pos(1);
GLfloat mouse_z;
if (z == nullptr)
::glReadPixels((GLint)mouse_pos.x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, (void*)&mouse_z);
::glReadPixels((GLint)mouse_pos(0), y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, (void*)&mouse_z);
else
mouse_z = *z;
GLdouble out_x, out_y, out_z;
::gluUnProject((GLdouble)mouse_pos.x, (GLdouble)y, (GLdouble)mouse_z, modelview_matrix, projection_matrix, viewport, &out_x, &out_y, &out_z);
return Pointf3((coordf_t)out_x, (coordf_t)out_y, (coordf_t)out_z);
::gluUnProject((GLdouble)mouse_pos(0), (GLdouble)y, (GLdouble)mouse_z, modelview_matrix, projection_matrix, viewport, &out_x, &out_y, &out_z);
return Vec3d((coordf_t)out_x, (coordf_t)out_y, (coordf_t)out_z);
}
Pointf3 GLCanvas3D::_mouse_to_bed_3d(const Point& mouse_pos)
Vec3d GLCanvas3D::_mouse_to_bed_3d(const Point& mouse_pos)
{
return mouse_ray(mouse_pos).intersect_plane(0.0);
}
@ -4883,7 +4878,7 @@ bool GLCanvas3D::_travel_paths_by_type(const GCodePreviewData& preview_data)
TypesList::iterator type = std::find(types.begin(), types.end(), Type(polyline.type));
if (type != types.end())
{
type->volume->print_zs.push_back(unscale(polyline.polyline.bounding_box().min.z));
type->volume->print_zs.push_back(unscale<double>(polyline.polyline.bounding_box().min(2)));
type->volume->offsets.push_back(type->volume->indexed_vertex_array.quad_indices.size());
type->volume->offsets.push_back(type->volume->indexed_vertex_array.triangle_indices.size());
@ -4949,7 +4944,7 @@ bool GLCanvas3D::_travel_paths_by_feedrate(const GCodePreviewData& preview_data)
FeedratesList::iterator feedrate = std::find(feedrates.begin(), feedrates.end(), Feedrate(polyline.feedrate));
if (feedrate != feedrates.end())
{
feedrate->volume->print_zs.push_back(unscale(polyline.polyline.bounding_box().min.z));
feedrate->volume->print_zs.push_back(unscale<double>(polyline.polyline.bounding_box().min(2)));
feedrate->volume->offsets.push_back(feedrate->volume->indexed_vertex_array.quad_indices.size());
feedrate->volume->offsets.push_back(feedrate->volume->indexed_vertex_array.triangle_indices.size());
@ -5015,7 +5010,7 @@ bool GLCanvas3D::_travel_paths_by_tool(const GCodePreviewData& preview_data, con
ToolsList::iterator tool = std::find(tools.begin(), tools.end(), Tool(polyline.extruder_id));
if (tool != tools.end())
{
tool->volume->print_zs.push_back(unscale(polyline.polyline.bounding_box().min.z));
tool->volume->print_zs.push_back(unscale<double>(polyline.polyline.bounding_box().min(2)));
tool->volume->offsets.push_back(tool->volume->indexed_vertex_array.quad_indices.size());
tool->volume->offsets.push_back(tool->volume->indexed_vertex_array.triangle_indices.size());
@ -5040,11 +5035,11 @@ void GLCanvas3D::_load_gcode_retractions(const GCodePreviewData& preview_data)
m_volumes.volumes.emplace_back(volume);
GCodePreviewData::Retraction::PositionsList copy(preview_data.retraction.positions);
std::sort(copy.begin(), copy.end(), [](const GCodePreviewData::Retraction::Position& p1, const GCodePreviewData::Retraction::Position& p2){ return p1.position.z < p2.position.z; });
std::sort(copy.begin(), copy.end(), [](const GCodePreviewData::Retraction::Position& p1, const GCodePreviewData::Retraction::Position& p2){ return p1.position(2) < p2.position(2); });
for (const GCodePreviewData::Retraction::Position& position : copy)
{
volume->print_zs.push_back(unscale(position.position.z));
volume->print_zs.push_back(unscale<double>(position.position(2)));
volume->offsets.push_back(volume->indexed_vertex_array.quad_indices.size());
volume->offsets.push_back(volume->indexed_vertex_array.triangle_indices.size());
@ -5071,11 +5066,11 @@ void GLCanvas3D::_load_gcode_unretractions(const GCodePreviewData& preview_data)
m_volumes.volumes.emplace_back(volume);
GCodePreviewData::Retraction::PositionsList copy(preview_data.unretraction.positions);
std::sort(copy.begin(), copy.end(), [](const GCodePreviewData::Retraction::Position& p1, const GCodePreviewData::Retraction::Position& p2){ return p1.position.z < p2.position.z; });
std::sort(copy.begin(), copy.end(), [](const GCodePreviewData::Retraction::Position& p1, const GCodePreviewData::Retraction::Position& p2){ return p1.position(2) < p2.position(2); });
for (const GCodePreviewData::Retraction::Position& position : copy)
{
volume->print_zs.push_back(unscale(position.position.z));
volume->print_zs.push_back(unscale<double>(position.position(2)));
volume->offsets.push_back(volume->indexed_vertex_array.quad_indices.size());
volume->offsets.push_back(volume->indexed_vertex_array.triangle_indices.size());
@ -5115,7 +5110,7 @@ void GLCanvas3D::_load_shells()
}
// adds wipe tower's volume
coordf_t max_z = m_print->objects[0]->model_object()->get_model()->bounding_box().max.z;
coordf_t max_z = m_print->objects[0]->model_object()->get_model()->bounding_box().max(2);
const PrintConfig& config = m_print->config;
unsigned int extruders_count = config.nozzle_diameter.size();
if ((extruders_count > 1) && config.single_extruder_multi_material && config.wipe_tower && !config.complete_objects) {
@ -5198,9 +5193,9 @@ void GLCanvas3D::_update_toolpath_volumes_outside_state()
if (opt != nullptr)
{
BoundingBox bed_box_2D = get_extents(Polygon::new_scale(opt->values));
print_volume = BoundingBoxf3(Pointf3(unscale(bed_box_2D.min.x) - tolerance_x, unscale(bed_box_2D.min.y) - tolerance_y, 0.0), Pointf3(unscale(bed_box_2D.max.x) + tolerance_x, unscale(bed_box_2D.max.y) + tolerance_y, m_config->opt_float("max_print_height")));
print_volume = BoundingBoxf3(Vec3d(unscale<double>(bed_box_2D.min(0)) - tolerance_x, unscale<double>(bed_box_2D.min(1)) - tolerance_y, 0.0), Vec3d(unscale<double>(bed_box_2D.max(0)) + tolerance_x, unscale<double>(bed_box_2D.max(1)) + tolerance_y, m_config->opt_float("max_print_height")));
// Allow the objects to protrude below the print bed
print_volume.min.z = -1e10;
print_volume.min(2) = -1e10;
}
}
@ -5231,7 +5226,7 @@ void GLCanvas3D::_on_move(const std::vector<int>& volume_idxs)
std::set<std::string> done; // prevent moving instances twice
bool object_moved = false;
Pointf3 wipe_tower_origin(0.0, 0.0, 0.0);
Vec3d wipe_tower_origin(0.0, 0.0, 0.0);
for (int volume_idx : volume_idxs)
{
GLVolume* volume = m_volumes.volumes[volume_idx];
@ -5250,8 +5245,8 @@ void GLCanvas3D::_on_move(const std::vector<int>& volume_idxs)
{
// Move a regular object.
ModelObject* model_object = m_model->objects[obj_idx];
const Pointf3& origin = volume->get_origin();
model_object->instances[instance_idx]->offset = Pointf(origin.x, origin.y);
const Vec3d& origin = volume->get_origin();
model_object->instances[instance_idx]->offset = Vec2d(origin(0), origin(1));
model_object->invalidate_bounding_box();
object_moved = true;
}
@ -5263,8 +5258,8 @@ void GLCanvas3D::_on_move(const std::vector<int>& volume_idxs)
if (object_moved)
m_on_instance_moved_callback.call();
if (wipe_tower_origin != Pointf3(0.0, 0.0, 0.0))
m_on_wipe_tower_moved_callback.call(wipe_tower_origin.x, wipe_tower_origin.y);
if (wipe_tower_origin != Vec3d(0.0, 0.0, 0.0))
m_on_wipe_tower_moved_callback.call(wipe_tower_origin(0), wipe_tower_origin(1));
}
void GLCanvas3D::_on_select(int volume_idx)

View file

@ -120,7 +120,7 @@ public:
float zoom;
float phi;
// float distance;
Pointf3 target;
Vec3d target;
private:
float m_theta;
@ -185,7 +185,7 @@ public:
struct Axes
{
Pointf3 origin;
Vec3d origin;
float length;
Axes();
@ -299,11 +299,11 @@ public:
struct Drag
{
static const Point Invalid_2D_Point;
static const Pointf3 Invalid_3D_Point;
static const Vec3d Invalid_3D_Point;
Point start_position_2D;
Pointf3 start_position_3D;
Vectorf3 volume_center_offset;
Vec3d start_position_3D;
Vec3d volume_center_offset;
bool move_with_shift;
int move_volume_idx;
@ -314,7 +314,7 @@ public:
};
bool dragging;
Pointf position;
Vec2d position;
Drag drag;
Mouse();
@ -357,13 +357,13 @@ public:
bool is_enabled() const;
void set_enabled(bool enable);
void update_hover_state(const GLCanvas3D& canvas, const Pointf& mouse_pos);
void update_on_off_state(const GLCanvas3D& canvas, const Pointf& mouse_pos);
void update_hover_state(const GLCanvas3D& canvas, const Vec2d& mouse_pos);
void update_on_off_state(const GLCanvas3D& canvas, const Vec2d& mouse_pos);
void reset_all_states();
void set_hover_id(int id);
bool overlay_contains_mouse(const GLCanvas3D& canvas, const Pointf& mouse_pos) const;
bool overlay_contains_mouse(const GLCanvas3D& canvas, const Vec2d& mouse_pos) const;
bool grabber_contains_mouse() const;
void update(const Linef3& mouse_ray);
void refresh();
@ -691,10 +691,10 @@ private:
// Convert the screen space coordinate to an object space coordinate.
// If the Z screen space coordinate is not provided, a depth buffer value is substituted.
Pointf3 _mouse_to_3d(const Point& mouse_pos, float* z = nullptr);
Vec3d _mouse_to_3d(const Point& mouse_pos, float* z = nullptr);
// Convert the screen space coordinate to world coordinate on the bed.
Pointf3 _mouse_to_bed_3d(const Point& mouse_pos);
Vec3d _mouse_to_bed_3d(const Point& mouse_pos);
// Returns the view ray line, in world coordinate, at the given mouse position.
Linef3 mouse_ray(const Point& mouse_pos);

View file

@ -23,7 +23,7 @@ const float GLGizmoBase::Grabber::HalfSize = 2.0f;
const float GLGizmoBase::Grabber::DraggingScaleFactor = 1.25f;
GLGizmoBase::Grabber::Grabber()
: center(Pointf3(0.0, 0.0, 0.0))
: center(0.0, 0.0, 0.0)
, angle_x(0.0f)
, angle_y(0.0f)
, angle_z(0.0f)
@ -73,7 +73,7 @@ void GLGizmoBase::Grabber::render(const float* render_color) const
::glColor3f((GLfloat)render_color[0], (GLfloat)render_color[1], (GLfloat)render_color[2]);
::glPushMatrix();
::glTranslatef((GLfloat)center.x, (GLfloat)center.y, (GLfloat)center.z);
::glTranslatef((GLfloat)center(0), (GLfloat)center(1), (GLfloat)center(2));
float rad_to_deg = 180.0f / (GLfloat)PI;
::glRotatef((GLfloat)angle_x * rad_to_deg, 1.0f, 0.0f, 0.0f);
@ -249,7 +249,7 @@ GLGizmoRotate::GLGizmoRotate(GLGizmoRotate::Axis axis)
: GLGizmoBase()
, m_axis(axis)
, m_angle(0.0f)
, m_center(Pointf3(0.0, 0.0, 0.0))
, m_center(0.0, 0.0, 0.0)
, m_radius(0.0f)
, m_keep_initial_values(false)
{
@ -287,18 +287,18 @@ bool GLGizmoRotate::on_init()
}
void GLGizmoRotate::on_update(const Linef3& mouse_ray)
{
Pointf mouse_pos = mouse_position_in_local_plane(mouse_ray);
{
Vec2d mouse_pos = to_2d(mouse_position_in_local_plane(mouse_ray));
Vectorf orig_dir(1.0, 0.0);
Vectorf new_dir = normalize(mouse_pos);
Vec2d orig_dir = Vec2d::UnitX();
Vec2d new_dir = mouse_pos.normalized();
coordf_t theta = ::acos(clamp(-1.0, 1.0, dot(new_dir, orig_dir)));
if (cross(orig_dir, new_dir) < 0.0)
double theta = ::acos(clamp(-1.0, 1.0, new_dir.dot(orig_dir)));
if (cross2(orig_dir, new_dir) < 0.0)
theta = 2.0 * (coordf_t)PI - theta;
// snap
double len = length(mouse_pos);
double len = mouse_pos.norm();
double in_radius = (double)m_radius / 3.0;
double out_radius = 2.0 * (double)in_radius;
if ((in_radius <= len) && (len <= out_radius))
@ -323,16 +323,16 @@ void GLGizmoRotate::on_render(const BoundingBoxf3& box) const
if (!m_keep_initial_values)
{
const Pointf3& size = box.size();
m_center = box.center();
#if !ENABLE_GIZMOS_3D
m_center.z = 0.0;
const Vec3d& size = box.size();
m_center(2) = 0.0;
#endif // !ENABLE_GIZMOS_3D
#if ENABLE_GIZMOS_3D
m_radius = Offset + box.radius();
#else
m_radius = Offset + ::sqrt(sqr(0.5f * size.x) + sqr(0.5f * size.y));
m_radius = Offset + ::sqrt(sqr(0.5f * (float)size(0)) + sqr(0.5f * (float)size(1)));
#endif // ENABLE_GIZMOS_3D
m_keep_initial_values = true;
}
@ -481,7 +481,7 @@ void GLGizmoRotate::render_angle() const
void GLGizmoRotate::render_grabber() const
{
float grabber_radius = m_radius + GrabberOffset;
m_grabbers[0].center = Pointf3(::cos(m_angle) * grabber_radius, ::sin(m_angle) * grabber_radius, 0.0f);
m_grabbers[0].center = Vec3d(::cos(m_angle) * grabber_radius, ::sin(m_angle) * grabber_radius, 0.0);
m_grabbers[0].angle_z = m_angle;
#if ENABLE_GIZMOS_3D
@ -492,7 +492,7 @@ void GLGizmoRotate::render_grabber() const
::glBegin(GL_LINES);
::glVertex3f(0.0f, 0.0f, 0.0f);
::glVertex3f((GLfloat)m_grabbers[0].center.x, (GLfloat)m_grabbers[0].center.y, (GLfloat)m_grabbers[0].center.z);
::glVertex3f((GLfloat)m_grabbers[0].center(0), (GLfloat)m_grabbers[0].center(1), (GLfloat)m_grabbers[0].center(2));
::glEnd();
::memcpy((void*)m_grabbers[0].color, (const void*)m_highlight_color, 3 * sizeof(float));
@ -501,7 +501,7 @@ void GLGizmoRotate::render_grabber() const
void GLGizmoRotate::transform_to_local() const
{
::glTranslatef((GLfloat)m_center.x, (GLfloat)m_center.y, (GLfloat)m_center.z);
::glTranslatef((GLfloat)m_center(0), (GLfloat)m_center(1), (GLfloat)m_center(2));
switch (m_axis)
{
@ -526,24 +526,24 @@ void GLGizmoRotate::transform_to_local() const
}
}
Pointf GLGizmoRotate::mouse_position_in_local_plane(const Linef3& mouse_ray) const
Vec3d GLGizmoRotate::mouse_position_in_local_plane(const Linef3& mouse_ray) const
{
float half_pi = 0.5f * (float)PI;
double half_pi = 0.5 * (double)PI;
Eigen::Transform<float, 3, Eigen::Affine> m = Eigen::Transform<float, 3, Eigen::Affine>::Identity();
Transform3d m = Transform3d::Identity();
switch (m_axis)
{
case X:
{
m.rotate(Eigen::AngleAxisf(-half_pi, Eigen::Vector3f::UnitZ()));
m.rotate(Eigen::AngleAxisf(-half_pi, Eigen::Vector3f::UnitY()));
m.rotate(Eigen::AngleAxisd(-half_pi, Vec3d::UnitZ()));
m.rotate(Eigen::AngleAxisd(-half_pi, Vec3d::UnitY()));
break;
}
case Y:
{
m.rotate(Eigen::AngleAxisf(-(float)PI, Eigen::Vector3f::UnitZ()));
m.rotate(Eigen::AngleAxisf(-half_pi, Eigen::Vector3f::UnitX()));
m.rotate(Eigen::AngleAxisd(-(double)PI, Vec3d::UnitZ()));
m.rotate(Eigen::AngleAxisd(-half_pi, Vec3d::UnitX()));
break;
}
default:
@ -554,19 +554,19 @@ Pointf GLGizmoRotate::mouse_position_in_local_plane(const Linef3& mouse_ray) con
}
}
m.translate(Eigen::Vector3f((float)-m_center.x, (float)-m_center.y, (float)-m_center.z));
m.translate(-m_center);
Eigen::Matrix<float, 3, 2> world_ray;
Eigen::Matrix<float, 3, 2> local_ray;
world_ray(0, 0) = (float)mouse_ray.a.x;
world_ray(1, 0) = (float)mouse_ray.a.y;
world_ray(2, 0) = (float)mouse_ray.a.z;
world_ray(0, 1) = (float)mouse_ray.b.x;
world_ray(1, 1) = (float)mouse_ray.b.y;
world_ray(2, 1) = (float)mouse_ray.b.z;
Eigen::Matrix<double, 3, 2> world_ray;
Eigen::Matrix<double, 3, 2> local_ray;
world_ray(0, 0) = mouse_ray.a(0);
world_ray(1, 0) = mouse_ray.a(1);
world_ray(2, 0) = mouse_ray.a(2);
world_ray(0, 1) = mouse_ray.b(0);
world_ray(1, 1) = mouse_ray.b(1);
world_ray(2, 1) = mouse_ray.b(2);
local_ray = m * world_ray.colwise().homogeneous();
return Linef3(Pointf3(local_ray(0, 0), local_ray(1, 0), local_ray(2, 0)), Pointf3(local_ray(0, 1), local_ray(1, 1), local_ray(2, 1))).intersect_plane(0.0);
return Linef3(Vec3d(local_ray(0, 0), local_ray(1, 0), local_ray(2, 0)), Vec3d(local_ray(0, 1), local_ray(1, 1), local_ray(2, 1))).intersect_plane(0.0);
}
GLGizmoRotate3D::GLGizmoRotate3D()
@ -708,17 +708,17 @@ bool GLGizmoScale::on_init()
void GLGizmoScale::on_start_dragging()
{
if (m_hover_id != -1)
m_starting_drag_position = m_grabbers[m_hover_id].center;
m_starting_drag_position = to_2d(m_grabbers[m_hover_id].center);
}
void GLGizmoScale::on_update(const Linef3& mouse_ray)
{
Pointf mouse_pos = mouse_ray.intersect_plane(0.0);
Pointf center(0.5 * (m_grabbers[1].center.x + m_grabbers[0].center.x), 0.5 * (m_grabbers[3].center.y + m_grabbers[0].center.y));
Vec2d mouse_pos = to_2d(mouse_ray.intersect_plane(0.0));
Vec2d center(0.5 * (m_grabbers[1].center(0) + m_grabbers[0].center(0)), 0.5 * (m_grabbers[3].center(1) + m_grabbers[0].center(1)));
coordf_t orig_len = length(m_starting_drag_position - center);
coordf_t new_len = length(mouse_pos - center);
coordf_t ratio = (orig_len != 0.0) ? new_len / orig_len : 1.0;
double orig_len = (m_starting_drag_position - center).norm();
double new_len = (mouse_pos - center).norm();
double ratio = (orig_len != 0.0) ? new_len / orig_len : 1.0;
m_scale = m_starting_scale * (float)ratio;
}
@ -727,15 +727,15 @@ void GLGizmoScale::on_render(const BoundingBoxf3& box) const
{
::glDisable(GL_DEPTH_TEST);
coordf_t min_x = box.min.x - (coordf_t)Offset;
coordf_t max_x = box.max.x + (coordf_t)Offset;
coordf_t min_y = box.min.y - (coordf_t)Offset;
coordf_t max_y = box.max.y + (coordf_t)Offset;
double min_x = box.min(0) - (double)Offset;
double max_x = box.max(0) + (double)Offset;
double min_y = box.min(1) - (double)Offset;
double max_y = box.max(1) + (double)Offset;
m_grabbers[0].center = Pointf3(min_x, min_y, 0.0f);
m_grabbers[1].center = Pointf3(max_x, min_y, 0.0f);
m_grabbers[2].center = Pointf3(max_x, max_y, 0.0f);
m_grabbers[3].center = Pointf3(min_x, max_y, 0.0f);
m_grabbers[0].center = Vec3d(min_x, min_y, 0.0);
m_grabbers[1].center = Vec3d(max_x, min_y, 0.0);
m_grabbers[2].center = Vec3d(max_x, max_y, 0.0);
m_grabbers[3].center = Vec3d(min_x, max_y, 0.0);
::glLineWidth(2.0f);
::glColor3fv(m_drag_color);
@ -744,7 +744,7 @@ void GLGizmoScale::on_render(const BoundingBoxf3& box) const
::glBegin(GL_LINE_LOOP);
for (unsigned int i = 0; i < 4; ++i)
{
::glVertex3f((GLfloat)m_grabbers[i].center.x, (GLfloat)m_grabbers[i].center.y, 0.0f);
::glVertex3f((GLfloat)m_grabbers[i].center(0), (GLfloat)m_grabbers[i].center(1), 0.0f);
}
::glEnd();
@ -841,34 +841,34 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const
{
::glEnable(GL_DEPTH_TEST);
Vectorf3 offset_vec((coordf_t)Offset, (coordf_t)Offset, (coordf_t)Offset);
Vec3d offset_vec((double)Offset, (double)Offset, (double)Offset);
m_box = BoundingBoxf3(box.min - offset_vec, box.max + offset_vec);
const Pointf3& center = m_box.center();
const Vec3d& center = m_box.center();
// x axis
m_grabbers[0].center = Pointf3(m_box.min.x, center.y, center.z);
m_grabbers[1].center = Pointf3(m_box.max.x, center.y, center.z);
m_grabbers[0].center = Vec3d(m_box.min(0), center(1), center(2));
m_grabbers[1].center = Vec3d(m_box.max(0), center(1), center(2));
::memcpy((void*)m_grabbers[0].color, (const void*)RED, 3 * sizeof(float));
::memcpy((void*)m_grabbers[1].color, (const void*)RED, 3 * sizeof(float));
// y axis
m_grabbers[2].center = Pointf3(center.x, m_box.min.y, center.z);
m_grabbers[3].center = Pointf3(center.x, m_box.max.y, center.z);
m_grabbers[2].center = Vec3d(center(0), m_box.min(1), center(2));
m_grabbers[3].center = Vec3d(center(0), m_box.max(1), center(2));
::memcpy((void*)m_grabbers[2].color, (const void*)GREEN, 3 * sizeof(float));
::memcpy((void*)m_grabbers[3].color, (const void*)GREEN, 3 * sizeof(float));
// z axis
m_grabbers[4].center = Pointf3(center.x, center.y, m_box.min.z);
m_grabbers[5].center = Pointf3(center.x, center.y, m_box.max.z);
m_grabbers[4].center = Vec3d(center(0), center(1), m_box.min(2));
m_grabbers[5].center = Vec3d(center(0), center(1), m_box.max(2));
::memcpy((void*)m_grabbers[4].color, (const void*)BLUE, 3 * sizeof(float));
::memcpy((void*)m_grabbers[5].color, (const void*)BLUE, 3 * sizeof(float));
// uniform
m_grabbers[6].center = Pointf3(m_box.min.x, m_box.min.y, m_box.min.z);
m_grabbers[7].center = Pointf3(m_box.max.x, m_box.min.y, m_box.min.z);
m_grabbers[8].center = Pointf3(m_box.max.x, m_box.max.y, m_box.min.z);
m_grabbers[9].center = Pointf3(m_box.min.x, m_box.max.y, m_box.min.z);
m_grabbers[6].center = Vec3d(m_box.min(0), m_box.min(1), m_box.min(2));
m_grabbers[7].center = Vec3d(m_box.max(0), m_box.min(1), m_box.min(2));
m_grabbers[8].center = Vec3d(m_box.max(0), m_box.max(1), m_box.min(2));
m_grabbers[9].center = Vec3d(m_box.min(0), m_box.max(1), m_box.min(2));
for (int i = 6; i < 10; ++i)
{
::memcpy((void*)m_grabbers[i].color, (const void*)m_highlight_color, 3 * sizeof(float));
@ -942,26 +942,26 @@ void GLGizmoScale3D::render_box() const
{
// bottom face
::glBegin(GL_LINE_LOOP);
::glVertex3f((GLfloat)m_box.min.x, (GLfloat)m_box.min.y, (GLfloat)m_box.min.z);
::glVertex3f((GLfloat)m_box.min.x, (GLfloat)m_box.max.y, (GLfloat)m_box.min.z);
::glVertex3f((GLfloat)m_box.max.x, (GLfloat)m_box.max.y, (GLfloat)m_box.min.z);
::glVertex3f((GLfloat)m_box.max.x, (GLfloat)m_box.min.y, (GLfloat)m_box.min.z);
::glVertex3f((GLfloat)m_box.min(0), (GLfloat)m_box.min(1), (GLfloat)m_box.min(2));
::glVertex3f((GLfloat)m_box.min(0), (GLfloat)m_box.max(1), (GLfloat)m_box.min(2));
::glVertex3f((GLfloat)m_box.max(0), (GLfloat)m_box.max(1), (GLfloat)m_box.min(2));
::glVertex3f((GLfloat)m_box.max(0), (GLfloat)m_box.min(1), (GLfloat)m_box.min(2));
::glEnd();
// top face
::glBegin(GL_LINE_LOOP);
::glVertex3f((GLfloat)m_box.min.x, (GLfloat)m_box.min.y, (GLfloat)m_box.max.z);
::glVertex3f((GLfloat)m_box.min.x, (GLfloat)m_box.max.y, (GLfloat)m_box.max.z);
::glVertex3f((GLfloat)m_box.max.x, (GLfloat)m_box.max.y, (GLfloat)m_box.max.z);
::glVertex3f((GLfloat)m_box.max.x, (GLfloat)m_box.min.y, (GLfloat)m_box.max.z);
::glVertex3f((GLfloat)m_box.min(0), (GLfloat)m_box.min(1), (GLfloat)m_box.max(2));
::glVertex3f((GLfloat)m_box.min(0), (GLfloat)m_box.max(1), (GLfloat)m_box.max(2));
::glVertex3f((GLfloat)m_box.max(0), (GLfloat)m_box.max(1), (GLfloat)m_box.max(2));
::glVertex3f((GLfloat)m_box.max(0), (GLfloat)m_box.min(1), (GLfloat)m_box.max(2));
::glEnd();
// vertical edges
::glBegin(GL_LINES);
::glVertex3f((GLfloat)m_box.min.x, (GLfloat)m_box.min.y, (GLfloat)m_box.min.z); ::glVertex3f((GLfloat)m_box.min.x, (GLfloat)m_box.min.y, (GLfloat)m_box.max.z);
::glVertex3f((GLfloat)m_box.min.x, (GLfloat)m_box.max.y, (GLfloat)m_box.min.z); ::glVertex3f((GLfloat)m_box.min.x, (GLfloat)m_box.max.y, (GLfloat)m_box.max.z);
::glVertex3f((GLfloat)m_box.max.x, (GLfloat)m_box.max.y, (GLfloat)m_box.min.z); ::glVertex3f((GLfloat)m_box.max.x, (GLfloat)m_box.max.y, (GLfloat)m_box.max.z);
::glVertex3f((GLfloat)m_box.max.x, (GLfloat)m_box.min.y, (GLfloat)m_box.min.z); ::glVertex3f((GLfloat)m_box.max.x, (GLfloat)m_box.min.y, (GLfloat)m_box.max.z);
::glVertex3f((GLfloat)m_box.min(0), (GLfloat)m_box.min(1), (GLfloat)m_box.min(2)); ::glVertex3f((GLfloat)m_box.min(0), (GLfloat)m_box.min(1), (GLfloat)m_box.max(2));
::glVertex3f((GLfloat)m_box.min(0), (GLfloat)m_box.max(1), (GLfloat)m_box.min(2)); ::glVertex3f((GLfloat)m_box.min(0), (GLfloat)m_box.max(1), (GLfloat)m_box.max(2));
::glVertex3f((GLfloat)m_box.max(0), (GLfloat)m_box.max(1), (GLfloat)m_box.min(2)); ::glVertex3f((GLfloat)m_box.max(0), (GLfloat)m_box.max(1), (GLfloat)m_box.max(2));
::glVertex3f((GLfloat)m_box.max(0), (GLfloat)m_box.min(1), (GLfloat)m_box.min(2)); ::glVertex3f((GLfloat)m_box.max(0), (GLfloat)m_box.min(1), (GLfloat)m_box.max(2));
::glEnd();
}
@ -971,25 +971,25 @@ void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int
if ((id_1 < grabbers_count) && (id_2 < grabbers_count))
{
::glBegin(GL_LINES);
::glVertex3f((GLfloat)m_grabbers[id_1].center.x, (GLfloat)m_grabbers[id_1].center.y, (GLfloat)m_grabbers[id_1].center.z);
::glVertex3f((GLfloat)m_grabbers[id_2].center.x, (GLfloat)m_grabbers[id_2].center.y, (GLfloat)m_grabbers[id_2].center.z);
::glVertex3f((GLfloat)m_grabbers[id_1].center(0), (GLfloat)m_grabbers[id_1].center(1), (GLfloat)m_grabbers[id_1].center(2));
::glVertex3f((GLfloat)m_grabbers[id_2].center(0), (GLfloat)m_grabbers[id_2].center(1), (GLfloat)m_grabbers[id_2].center(2));
::glEnd();
}
}
Linef3 transform(const Linef3& line, const Eigen::Transform<float, 3, Eigen::Affine>& t)
Linef3 transform(const Linef3& line, const Transform3d& t)
{
Eigen::Matrix<float, 3, 2> world_line;
Eigen::Matrix<float, 3, 2> local_line;
world_line(0, 0) = (float)line.a.x;
world_line(1, 0) = (float)line.a.y;
world_line(2, 0) = (float)line.a.z;
world_line(0, 1) = (float)line.b.x;
world_line(1, 1) = (float)line.b.y;
world_line(2, 1) = (float)line.b.z;
Eigen::Matrix<double, 3, 2> world_line;
Eigen::Matrix<double, 3, 2> local_line;
world_line(0, 0) = line.a(0);
world_line(1, 0) = line.a(1);
world_line(2, 0) = line.a(2);
world_line(0, 1) = line.b(0);
world_line(1, 1) = line.b(1);
world_line(2, 1) = line.b(2);
local_line = t * world_line.colwise().homogeneous();
return Linef3(Pointf3(local_line(0, 0), local_line(1, 0), local_line(2, 0)), Pointf3(local_line(0, 1), local_line(1, 1), local_line(2, 1)));
return Linef3(Vec3d(local_line(0, 0), local_line(1, 0), local_line(2, 0)), Vec3d(local_line(0, 1), local_line(1, 1), local_line(2, 1)));
}
void GLGizmoScale3D::do_scale_x(const Linef3& mouse_ray)
@ -1020,8 +1020,8 @@ void GLGizmoScale3D::do_scale_z(const Linef3& mouse_ray)
void GLGizmoScale3D::do_scale_uniform(const Linef3& mouse_ray)
{
Pointf3 center = m_starting_center;
center.z = m_box.min.z;
Vec3d center = m_starting_center;
center(2) = m_box.min(2);
double ratio = calc_ratio(0, mouse_ray, center);
if (ratio > 0.0)
@ -1032,17 +1032,17 @@ void GLGizmoScale3D::do_scale_uniform(const Linef3& mouse_ray)
}
}
double GLGizmoScale3D::calc_ratio(unsigned int preferred_plane_id, const Linef3& mouse_ray, const Pointf3& center) const
double GLGizmoScale3D::calc_ratio(unsigned int preferred_plane_id, const Linef3& mouse_ray, const Vec3d& center) const
{
double ratio = 0.0;
Vectorf3 starting_vec = m_starting_drag_position - center;
double len_starting_vec = length(starting_vec);
Vec3d starting_vec = m_starting_drag_position - center;
double len_starting_vec = starting_vec.norm();
if (len_starting_vec == 0.0)
return ratio;
Vectorf3 starting_vec_dir = normalize(starting_vec);
Vectorf3 mouse_dir = mouse_ray.unit_vector();
Vec3d starting_vec_dir = starting_vec.normalized();
Vec3d mouse_dir = mouse_ray.unit_vector();
unsigned int plane_id = preferred_plane_id;
// 1st try to see if the mouse direction is close enough to the preferred plane normal
@ -1051,17 +1051,17 @@ double GLGizmoScale3D::calc_ratio(unsigned int preferred_plane_id, const Linef3&
{
case 0:
{
dot_to_normal = std::abs(dot(mouse_dir, Vectorf3(0.0, 0.0, 1.0)));
dot_to_normal = std::abs(mouse_dir.dot(Vec3d::UnitZ()));
break;
}
case 1:
{
dot_to_normal = std::abs(dot(mouse_dir, Vectorf3(0.0, -1.0, 0.0)));
dot_to_normal = std::abs(mouse_dir.dot(-Vec3d::UnitY()));
break;
}
case 2:
{
dot_to_normal = std::abs(dot(mouse_dir, Vectorf3(1.0, 0.0, 0.0)));
dot_to_normal = std::abs(mouse_dir.dot(Vec3d::UnitX()));
break;
}
}
@ -1073,9 +1073,9 @@ double GLGizmoScale3D::calc_ratio(unsigned int preferred_plane_id, const Linef3&
typedef std::map<double, unsigned int> ProjsMap;
ProjsMap projs_map;
projs_map.insert(ProjsMap::value_type(std::abs(dot(mouse_dir, Vectorf3(0.0, 0.0, 1.0))), 0)); // plane xy
projs_map.insert(ProjsMap::value_type(std::abs(dot(mouse_dir, Vectorf3(0.0, -1.0, 0.0))), 1)); // plane xz
projs_map.insert(ProjsMap::value_type(std::abs(dot(mouse_dir, Vectorf3(1.0, 0.0, 0.0))), 2)); // plane yz
projs_map.insert(ProjsMap::value_type(std::abs(mouse_dir.dot(Vec3d::UnitZ())), 0)); // plane xy
projs_map.insert(ProjsMap::value_type(std::abs(mouse_dir.dot(-Vec3d::UnitY())), 1)); // plane xz
projs_map.insert(ProjsMap::value_type(std::abs(mouse_dir.dot(Vec3d::UnitX())), 2)); // plane yz
plane_id = projs_map.rbegin()->second;
}
@ -1084,36 +1084,36 @@ double GLGizmoScale3D::calc_ratio(unsigned int preferred_plane_id, const Linef3&
case 0:
{
// calculates the intersection of the mouse ray with the plane parallel to plane XY and passing through the given center
Eigen::Transform<float, 3, Eigen::Affine> m = Eigen::Transform<float, 3, Eigen::Affine>::Identity();
m.translate(Eigen::Vector3f(-(float)center.x, -(float)center.y, -(float)center.z));
Pointf mouse_pos_2d = transform(mouse_ray, m).intersect_plane(0.0);
Transform3d m = Transform3d::Identity();
m.translate(-center);
Vec2d mouse_pos_2d = to_2d(transform(mouse_ray, m).intersect_plane(0.0));
// ratio is given by the projection of the calculated intersection on the starting vector divided by the starting vector length
ratio = dot(Vectorf3(mouse_pos_2d.x, mouse_pos_2d.y, 0.0), starting_vec_dir) / len_starting_vec;
ratio = starting_vec_dir.dot(Vec3d(mouse_pos_2d(0), mouse_pos_2d(1), 0.0)) / len_starting_vec;
break;
}
case 1:
{
// calculates the intersection of the mouse ray with the plane parallel to plane XZ and passing through the given center
Eigen::Transform<float, 3, Eigen::Affine> m = Eigen::Transform<float, 3, Eigen::Affine>::Identity();
m.rotate(Eigen::AngleAxisf(-0.5f * (float)PI, Eigen::Vector3f::UnitX()));
m.translate(Eigen::Vector3f(-(float)center.x, -(float)center.y, -(float)center.z));
Pointf mouse_pos_2d = transform(mouse_ray, m).intersect_plane(0.0);
Transform3d m = Transform3d::Identity();
m.rotate(Eigen::AngleAxisd(-0.5 * (double)PI, Vec3d::UnitX()));
m.translate(-center);
Vec2d mouse_pos_2d = to_2d(transform(mouse_ray, m).intersect_plane(0.0));
// ratio is given by the projection of the calculated intersection on the starting vector divided by the starting vector length
ratio = dot(Vectorf3(mouse_pos_2d.x, 0.0, mouse_pos_2d.y), starting_vec_dir) / len_starting_vec;
ratio = starting_vec_dir.dot(Vec3d(mouse_pos_2d(0), 0.0, mouse_pos_2d(1))) / len_starting_vec;
break;
}
case 2:
{
// calculates the intersection of the mouse ray with the plane parallel to plane YZ and passing through the given center
Eigen::Transform<float, 3, Eigen::Affine> m = Eigen::Transform<float, 3, Eigen::Affine>::Identity();
m.rotate(Eigen::AngleAxisf(-0.5f * (float)PI, Eigen::Vector3f::UnitY()));
m.translate(Eigen::Vector3f(-(float)center.x, -(float)center.y, -(float)center.z));
Pointf mouse_pos_2d = transform(mouse_ray, m).intersect_plane(0.0);
Transform3d m = Transform3d::Identity();
m.rotate(Eigen::AngleAxisd(-0.5f * (double)PI, Vec3d::UnitY()));
m.translate(-center);
Vec2d mouse_pos_2d = to_2d(transform(mouse_ray, m).intersect_plane(0.0));
// ratio is given by the projection of the calculated intersection on the starting vector divided by the starting vector length
ratio = dot(Vectorf3(0.0, mouse_pos_2d.y, -mouse_pos_2d.x), starting_vec_dir) / len_starting_vec;
ratio = starting_vec_dir.dot(Vec3d(0.0, mouse_pos_2d(1), -mouse_pos_2d(0))) / len_starting_vec;
break;
}
}

View file

@ -12,7 +12,6 @@
namespace Slic3r {
class BoundingBoxf3;
class Pointf3;
class Linef3;
namespace GUI {
@ -25,7 +24,7 @@ protected:
static const float HalfSize;
static const float DraggingScaleFactor;
Pointf3 center;
Vec3d center;
float angle_x;
float angle_y;
float angle_z;
@ -142,7 +141,7 @@ private:
Axis m_axis;
float m_angle;
mutable Pointf3 m_center;
mutable Vec3d m_center;
mutable float m_radius;
mutable bool m_keep_initial_values;
@ -169,7 +168,8 @@ private:
void render_grabber() const;
void transform_to_local() const;
Pointf mouse_position_in_local_plane(const Linef3& mouse_ray) const;
// returns the intersection of the mouse ray with the plane perpendicular to the gizmo axis, in local coordinate
Vec3d mouse_position_in_local_plane(const Linef3& mouse_ray) const;
};
class GLGizmoRotate3D : public GLGizmoBase
@ -234,7 +234,7 @@ class GLGizmoScale : public GLGizmoBase
float m_scale;
float m_starting_scale;
Pointf m_starting_drag_position;
Vec2d m_starting_drag_position;
public:
GLGizmoScale();
@ -264,8 +264,8 @@ class GLGizmoScale3D : public GLGizmoBase
float m_starting_scale_y;
float m_starting_scale_z;
Pointf3 m_starting_drag_position;
Pointf3 m_starting_center;
Vec3d m_starting_drag_position;
Vec3d m_starting_center;
public:
GLGizmoScale3D();
@ -302,7 +302,7 @@ private:
void do_scale_z(const Linef3& mouse_ray);
void do_scale_uniform(const Linef3& mouse_ray);
double calc_ratio(unsigned int preferred_plane_id, const Linef3& mouse_ray, const Pointf3& center) const;
double calc_ratio(unsigned int preferred_plane_id, const Linef3& mouse_ray, const Vec3d& center) const;
};
} // namespace GUI

View file

@ -1,5 +1,7 @@
#include "../../libslic3r/point.hpp"
#include "GLToolbar.hpp"
#include "../../libslic3r/libslic3r.h"
#include "../../slic3r/GUI/GLCanvas3D.hpp"
#include <GL/glew.h>
@ -267,7 +269,7 @@ bool GLToolbar::is_item_pressed(const std::string& name) const
return false;
}
void GLToolbar::update_hover_state(const Pointf& mouse_pos)
void GLToolbar::update_hover_state(const Vec2d& mouse_pos)
{
if (!m_enabled)
return;
@ -288,7 +290,7 @@ void GLToolbar::update_hover_state(const Pointf& mouse_pos)
}
}
int GLToolbar::contains_mouse(const Pointf& mouse_pos) const
int GLToolbar::contains_mouse(const Vec2d& mouse_pos) const
{
if (!m_enabled)
return -1;
@ -342,7 +344,6 @@ void GLToolbar::do_action(unsigned int item_id)
}
void GLToolbar::render() const
//void GLToolbar::render(const Pointf& mouse_pos) const
{
if (!m_enabled || m_items.empty())
return;
@ -407,13 +408,13 @@ float GLToolbar::_get_main_size() const
return size;
}
void GLToolbar::_update_hover_state_horizontal(const Pointf& mouse_pos)
void GLToolbar::_update_hover_state_horizontal(const Vec2d& mouse_pos)
{
float zoom = m_parent.get_camera_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
Size cnv_size = m_parent.get_canvas_size();
Pointf scaled_mouse_pos((mouse_pos.x - 0.5f * (float)cnv_size.get_width()) * inv_zoom, (0.5f * (float)cnv_size.get_height() - mouse_pos.y) * inv_zoom);
Vec2d scaled_mouse_pos((mouse_pos(0) - 0.5 * (double)cnv_size.get_width()) * inv_zoom, (0.5 * (double)cnv_size.get_height() - mouse_pos(1)) * inv_zoom);
float scaled_icons_size = (float)m_icons_texture.items_icon_size * inv_zoom;
float scaled_separator_size = m_layout.separator_size * inv_zoom;
@ -437,7 +438,7 @@ void GLToolbar::_update_hover_state_horizontal(const Pointf& mouse_pos)
float bottom = top - scaled_icons_size;
GLToolbarItem::EState state = item->get_state();
bool inside = (left <= scaled_mouse_pos.x) && (scaled_mouse_pos.x <= right) && (bottom <= scaled_mouse_pos.y) && (scaled_mouse_pos.y <= top);
bool inside = (left <= (float)scaled_mouse_pos(0)) && ((float)scaled_mouse_pos(0) <= right) && (bottom <= (float)scaled_mouse_pos(1)) && ((float)scaled_mouse_pos(1) <= top);
switch (state)
{
@ -487,13 +488,13 @@ void GLToolbar::_update_hover_state_horizontal(const Pointf& mouse_pos)
m_parent.set_tooltip(tooltip);
}
void GLToolbar::_update_hover_state_vertical(const Pointf& mouse_pos)
void GLToolbar::_update_hover_state_vertical(const Vec2d& mouse_pos)
{
float zoom = m_parent.get_camera_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
Size cnv_size = m_parent.get_canvas_size();
Pointf scaled_mouse_pos((mouse_pos.x - 0.5f * (float)cnv_size.get_width()) * inv_zoom, (0.5f * (float)cnv_size.get_height() - mouse_pos.y) * inv_zoom);
Vec2d scaled_mouse_pos((mouse_pos(0) - 0.5 * (double)cnv_size.get_width()) * inv_zoom, (0.5 * (double)cnv_size.get_height() - mouse_pos(1)) * inv_zoom);
float scaled_icons_size = (float)m_icons_texture.items_icon_size * inv_zoom;
float scaled_separator_size = m_layout.separator_size * inv_zoom;
@ -517,7 +518,7 @@ void GLToolbar::_update_hover_state_vertical(const Pointf& mouse_pos)
float bottom = top - scaled_icons_size;
GLToolbarItem::EState state = item->get_state();
bool inside = (left <= scaled_mouse_pos.x) && (scaled_mouse_pos.x <= right) && (bottom <= scaled_mouse_pos.y) && (scaled_mouse_pos.y <= top);
bool inside = (left <= (float)scaled_mouse_pos(0)) && ((float)scaled_mouse_pos(0) <= right) && (bottom <= (float)scaled_mouse_pos(1)) && ((float)scaled_mouse_pos(1) <= top);
switch (state)
{
@ -567,13 +568,13 @@ void GLToolbar::_update_hover_state_vertical(const Pointf& mouse_pos)
m_parent.set_tooltip(tooltip);
}
int GLToolbar::_contains_mouse_horizontal(const Pointf& mouse_pos) const
int GLToolbar::_contains_mouse_horizontal(const Vec2d& mouse_pos) const
{
float zoom = m_parent.get_camera_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
Size cnv_size = m_parent.get_canvas_size();
Pointf scaled_mouse_pos((mouse_pos.x - 0.5f * (float)cnv_size.get_width()) * inv_zoom, (0.5f * (float)cnv_size.get_height() - mouse_pos.y) * inv_zoom);
Vec2d scaled_mouse_pos((mouse_pos(0) - 0.5 * (double)cnv_size.get_width()) * inv_zoom, (0.5 * (double)cnv_size.get_height() - mouse_pos(1)) * inv_zoom);
float scaled_icons_size = (float)m_icons_texture.items_icon_size * inv_zoom;
float scaled_separator_size = m_layout.separator_size * inv_zoom;
@ -598,7 +599,7 @@ int GLToolbar::_contains_mouse_horizontal(const Pointf& mouse_pos) const
float right = left + scaled_icons_size;
float bottom = top - scaled_icons_size;
if ((left <= scaled_mouse_pos.x) && (scaled_mouse_pos.x <= right) && (bottom <= scaled_mouse_pos.y) && (scaled_mouse_pos.y <= top))
if ((left <= (float)scaled_mouse_pos(0)) && ((float)scaled_mouse_pos(0) <= right) && (bottom <= (float)scaled_mouse_pos(1)) && ((float)scaled_mouse_pos(1) <= top))
return id;
left += icon_stride;
@ -608,13 +609,13 @@ int GLToolbar::_contains_mouse_horizontal(const Pointf& mouse_pos) const
return -1;
}
int GLToolbar::_contains_mouse_vertical(const Pointf& mouse_pos) const
int GLToolbar::_contains_mouse_vertical(const Vec2d& mouse_pos) const
{
float zoom = m_parent.get_camera_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
Size cnv_size = m_parent.get_canvas_size();
Pointf scaled_mouse_pos((mouse_pos.x - 0.5f * (float)cnv_size.get_width()) * inv_zoom, (0.5f * (float)cnv_size.get_height() - mouse_pos.y) * inv_zoom);
Vec2d scaled_mouse_pos((mouse_pos(0) - 0.5 * (double)cnv_size.get_width()) * inv_zoom, (0.5 * (double)cnv_size.get_height() - mouse_pos(1)) * inv_zoom);
float scaled_icons_size = (float)m_icons_texture.items_icon_size * inv_zoom;
float scaled_separator_size = m_layout.separator_size * inv_zoom;
@ -639,7 +640,7 @@ int GLToolbar::_contains_mouse_vertical(const Pointf& mouse_pos) const
float right = left + scaled_icons_size;
float bottom = top - scaled_icons_size;
if ((left <= scaled_mouse_pos.x) && (scaled_mouse_pos.x <= right) && (bottom <= scaled_mouse_pos.y) && (scaled_mouse_pos.y <= top))
if ((left <= (float)scaled_mouse_pos(0)) && ((float)scaled_mouse_pos(0) <= right) && (bottom <= (float)scaled_mouse_pos(1)) && ((float)scaled_mouse_pos(1) <= top))
return id;
top -= icon_stride;

View file

@ -8,9 +8,6 @@
#include <vector>
namespace Slic3r {
class Pointf;
namespace GUI {
class GLCanvas3D;
@ -148,10 +145,10 @@ public:
bool is_item_pressed(const std::string& name) const;
void update_hover_state(const Pointf& mouse_pos);
void update_hover_state(const Vec2d& mouse_pos);
// returns the id of the item under the given mouse position or -1 if none
int contains_mouse(const Pointf& mouse_pos) const;
int contains_mouse(const Vec2d& mouse_pos) const;
void do_action(unsigned int item_id);
@ -163,10 +160,11 @@ private:
float _get_height_horizontal() const;
float _get_height_vertical() const;
float _get_main_size() const;
void _update_hover_state_horizontal(const Pointf& mouse_pos);
void _update_hover_state_vertical(const Pointf& mouse_pos);
int _contains_mouse_horizontal(const Pointf& mouse_pos) const;
int _contains_mouse_vertical(const Pointf& mouse_pos) const;
void _update_hover_state_horizontal(const Vec2d& mouse_pos);
void _update_hover_state_vertical(const Vec2d& mouse_pos);
int _contains_mouse_horizontal(const Vec2d& mouse_pos) const;
int _contains_mouse_vertical(const Vec2d& mouse_pos) const;
void _render_horizontal() const;
void _render_vertical() const;
};

View file

@ -610,10 +610,10 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt
break;
case coPoints:{
if (opt_key.compare("bed_shape") == 0){
config.option<ConfigOptionPoints>(opt_key)->values = boost::any_cast<std::vector<Pointf>>(value);
config.option<ConfigOptionPoints>(opt_key)->values = boost::any_cast<std::vector<Vec2d>>(value);
break;
}
ConfigOptionPoints* vec_new = new ConfigOptionPoints{ boost::any_cast<Pointf>(value) };
ConfigOptionPoints* vec_new = new ConfigOptionPoints{ boost::any_cast<Vec2d>(value) };
config.option<ConfigOptionPoints>(opt_key)->set_at(vec_new, opt_index, 0);
}
break;
@ -895,10 +895,10 @@ void add_frequently_changed_parameters(wxWindow* parent, wxBoxSizer* sizer, wxFl
g_wiping_dialog_button->Bind(wxEVT_BUTTON, ([parent](wxCommandEvent& e)
{
auto &config = g_PresetBundle->project_config;
std::vector<double> init_matrix = (config.option<ConfigOptionFloats>("wiping_volumes_matrix"))->values;
std::vector<double> init_extruders = (config.option<ConfigOptionFloats>("wiping_volumes_extruders"))->values;
const std::vector<double> &init_matrix = (config.option<ConfigOptionFloats>("wiping_volumes_matrix"))->values;
const std::vector<double> &init_extruders = (config.option<ConfigOptionFloats>("wiping_volumes_extruders"))->values;
WipingDialog dlg(parent,std::vector<float>(init_matrix.begin(),init_matrix.end()),std::vector<float>(init_extruders.begin(),init_extruders.end()));
WipingDialog dlg(parent,cast<float>(init_matrix),cast<float>(init_extruders));
if (dlg.ShowModal() == wxID_OK) {
std::vector<float> matrix = dlg.get_matrix();

View file

@ -261,7 +261,7 @@ std::vector<float> Chart::get_ramming_speed(float sampling) const {
std::vector<std::pair<float,float>> Chart::get_buttons() const {
std::vector<std::pair<float, float>> buttons_out;
for (const auto& button : m_buttons)
buttons_out.push_back(std::make_pair(button.get_pos().m_x,button.get_pos().m_y));
buttons_out.push_back(std::make_pair(float(button.get_pos().m_x),float(button.get_pos().m_y)));
return buttons_out;
}