Eradicated most of Pointf extras compared to pure Eigen::Vector2d.

This commit is contained in:
bubnikv 2018-08-21 20:34:45 +02:00
parent cb138a20b8
commit cae0806112
21 changed files with 68 additions and 103 deletions

View file

@ -18,7 +18,7 @@ public:
BoundingBoxBase() : defined(false), min(PointClass::Zero()), max(PointClass::Zero()) {}
BoundingBoxBase(const PointClass &pmin, const PointClass &pmax) :
min(pmin), max(pmax), defined(pmin(0) < pmax(0) && pmin(1) < pmax(1)) {}
BoundingBoxBase(const std::vector<PointClass>& points)
BoundingBoxBase(const std::vector<PointClass>& points) : min(PointClass::Zero()), max(PointClass::Zero())
{
if (points.empty())
CONFESS("Empty point set supplied to BoundingBoxBase constructor");

View file

@ -696,7 +696,7 @@ public:
std::istringstream is(str);
std::string point_str;
while (std::getline(is, point_str, ',')) {
Pointf point;
Pointf point(Vec2d::Zero());
std::istringstream iss(point_str);
std::string coord_str;
if (std::getline(iss, coord_str, 'x')) {

View file

@ -125,6 +125,7 @@ private:
class GCode {
public:
GCode() :
m_origin(Vec2d::Zero()),
m_enable_loop_clipping(true),
m_enable_cooling_markers(false),
m_enable_extrusion_role_markers(false),

View file

@ -136,8 +136,9 @@ BoundingBoxf get_wipe_tower_extrusions_extents(const Print &print, const coordf_
{
// Wipe tower extrusions are saved as if the tower was at the origin with no rotation
// We need to get position and angle of the wipe tower to transform them to actual position.
Pointf wipe_tower_pos(print.config.wipe_tower_x.value, print.config.wipe_tower_y.value);
float wipe_tower_angle = print.config.wipe_tower_rotation_angle.value;
Transform2d trafo =
Eigen::Translation2d(print.config.wipe_tower_x.value, print.config.wipe_tower_y.value) *
Eigen::Rotation2Dd(print.config.wipe_tower_rotation_angle.value);
BoundingBoxf bbox;
for (const std::vector<WipeTower::ToolChangeResult> &tool_changes : print.m_wipe_tower_tool_changes) {
@ -147,19 +148,11 @@ BoundingBoxf get_wipe_tower_extrusions_extents(const Print &print, const coordf_
for (size_t i = 1; i < tcr.extrusions.size(); ++ i) {
const WipeTower::Extrusion &e = tcr.extrusions[i];
if (e.width > 0) {
Pointf p1((&e - 1)->pos.x, (&e - 1)->pos.y);
Pointf p2(e.pos.x, e.pos.y);
p1.rotate(wipe_tower_angle);
p1 += wipe_tower_pos;
p2.rotate(wipe_tower_angle);
p2 += wipe_tower_pos;
bbox.merge(p1);
coordf_t radius = 0.5 * e.width;
bbox.min(0) = std::min(bbox.min(0), std::min(p1(0), p2(0)) - radius);
bbox.min(1) = std::min(bbox.min(1), std::min(p1(1), p2(1)) - radius);
bbox.max(0) = std::max(bbox.max(0), std::max(p1(0), p2(0)) + radius);
bbox.max(1) = std::max(bbox.max(1), std::max(p1(1), p2(1)) + radius);
Pointf delta = 0.5 * Vec2d(e.width, e.width);
Pointf p1 = trafo * Vec2d((&e - 1)->pos.x, (&e - 1)->pos.y);
Pointf p2 = trafo * Vec2d(e.pos.x, e.pos.y);
bbox.merge(p1.cwiseMin(p2) - delta);
bbox.merge(p1.cwiseMax(p2) + delta);
}
}
}

View file

@ -410,13 +410,13 @@ Pointfs arrange(size_t num_parts, const Pointf &part_size, coordf_t gap, const B
}
#else
class ArrangeItem {
public:
Pointf pos;
public:
Pointf pos = Vec2d::Zero();
size_t index_x, index_y;
coordf_t dist;
};
class ArrangeItemIndex {
public:
public:
coordf_t index;
ArrangeItem item;
ArrangeItemIndex(coordf_t _index, ArrangeItem _item) : index(_index), item(_item) {};
@ -433,7 +433,7 @@ arrange(size_t total_parts, const Pointf &part_size, coordf_t dist, const Boundi
part(0) += dist;
part(1) += dist;
Pointf area;
Pointf area(Vec2d::Zero());
if (bb != NULL && bb->defined) {
area = bb->size();
} else {

View file

@ -71,7 +71,7 @@ public:
class Linef
{
public:
Linef() {}
Linef() : a(Vec2d::Zero()), b(Vec2d::Zero()) {}
explicit Linef(Pointf _a, Pointf _b): a(_a), b(_b) {}
Pointf a;

View file

@ -726,24 +726,22 @@ void ModelObject::center_around_origin()
if (! v->modifier)
bb.merge(v->mesh.bounding_box());
// first align to origin on XYZ
Vec3d vector(-bb.min(0), -bb.min(1), -bb.min(2));
// then center it on XY
// First align to origin on XYZ, then center it on XY.
Vec3d size = bb.size();
vector(0) -= size(0)/2;
vector(1) -= size(1)/2;
size(2) = 0.;
Vec3d shift3 = - bb.min - 0.5 * size;
// Unaligned vector, for the Rotation2D to work on Visual Studio 2013.
Eigen::Vector2d shift2 = to_2d(shift3);
this->translate(vector);
this->origin_translation += vector;
this->translate(shift3);
this->origin_translation += shift3;
if (!this->instances.empty()) {
for (ModelInstance *i : this->instances) {
// apply rotation and scaling to vector as well before translating instance,
// in order to leave final position unaltered
Vectorf v = - to_2d(vector);
v.rotate(i->rotation);
i->offset += v * i->scaling_factor;
Eigen::Rotation2Dd rot(i->rotation);
i->offset -= rot * shift2 * i->scaling_factor;
}
this->invalidate_bounding_box();
}
@ -762,7 +760,7 @@ void ModelObject::scale(const Vec3d &versor)
for (ModelVolume *v : this->volumes)
v->mesh.scale(versor);
// reset origin translation since it doesn't make sense anymore
this->origin_translation = Vec3d(0,0,0);
this->origin_translation = Vec3d::Zero();
this->invalidate_bounding_box();
}
@ -784,7 +782,7 @@ void ModelObject::rotate(float angle, const Axis &axis)
}
}
this->origin_translation = Vec3d(0, 0, 0);
this->origin_translation = Vec3d::Zero();
this->invalidate_bounding_box();
}

View file

@ -235,7 +235,7 @@ private:
// Parent object, owning this instance.
ModelObject* object;
ModelInstance(ModelObject *object) : rotation(0), scaling_factor(1), object(object), print_volume_state(PVS_Inside) {}
ModelInstance(ModelObject *object) : rotation(0), scaling_factor(1), offset(Vec2d::Zero()), object(object), print_volume_state(PVS_Inside) {}
ModelInstance(ModelObject *object, const ModelInstance &other) :
rotation(other.rotation), scaling_factor(other.scaling_factor), offset(other.offset), object(object), print_volume_state(PVS_Inside) {}
};

View file

@ -153,28 +153,6 @@ std::ostream& operator<<(std::ostream &stm, const Pointf &pointf)
return stm << pointf(0) << "," << pointf(1);
}
void Pointf::rotate(double angle)
{
double cur_x = (*this)(0);
double cur_y = (*this)(1);
double s = ::sin(angle);
double c = ::cos(angle);
(*this)(0) = c * cur_x - s * cur_y;
(*this)(1) = c * cur_y + s * cur_x;
}
void Pointf::rotate(double angle, const Pointf &center)
{
double cur_x = (*this)(0);
double cur_y = (*this)(1);
double s = ::sin(angle);
double c = ::cos(angle);
double dx = cur_x - center(0);
double dy = cur_y - center(1);
(*this)(0) = center(0) + c * dx - s * dy;
(*this)(1) = center(1) + c * dy + s * dx;
}
namespace int128 {
int orient(const Vec2crd &p1, const Vec2crd &p2, const Vec2crd &p3)

View file

@ -47,6 +47,8 @@ typedef Eigen::Transform<double, 2, Eigen::Affine, Eigen::DontAlign> Transform2d
typedef Eigen::Transform<float, 3, Eigen::Affine, Eigen::DontAlign> Transform3f;
typedef Eigen::Transform<double, 3, Eigen::Affine, Eigen::DontAlign> Transform3d;
inline bool operator<(const Vec2d &lhs, const Vec2d &rhs) { return lhs(0) < rhs(0) || (lhs(0) == rhs(0) && lhs(1) < rhs(1)); }
inline int64_t cross2(const Vec2i64 &v1, const Vec2i64 &v2) { return v1(0) * v2(1) - v1(1) * v2(0); }
inline coord_t cross2(const Vec2crd &v1, const Vec2crd &v2) { return v1(0) * v2(1) - v1(1) * v2(0); }
inline float cross2(const Vec2f &v1, const Vec2f &v2) { return v1(0) * v2(1) - v1(1) * v2(0); }
@ -249,7 +251,8 @@ class Pointf : public Vec2d
public:
typedef coordf_t coord_type;
explicit Pointf() { (*this)(0) = (*this)(1) = 0.; }
// explicit Pointf() { (*this)(0) = (*this)(1) = 0.; }
explicit Pointf() { }
explicit Pointf(coordf_t x, coordf_t y) { (*this)(0) = x; (*this)(1) = y; }
// This constructor allows you to construct Pointf from Eigen expressions
template<typename OtherDerived>
@ -263,10 +266,10 @@ public:
return *this;
}
void rotate(double angle);
void rotate(double angle, const Pointf &center);
// void rotate(double angle);
// void rotate(double angle, const Pointf &center);
bool operator< (const Pointf& rhs) const { return (*this)(0) < rhs(0) || ((*this)(0) == rhs(0) && (*this)(1) < rhs(1)); }
private:
};
} // namespace Slic3r

View file

@ -24,11 +24,12 @@ public:
explicit Polygon(const Points &points): MultiPoint(points) {}
Polygon(const Polygon &other) : MultiPoint(other.points) {}
Polygon(Polygon &&other) : MultiPoint(std::move(other.points)) {}
static Polygon new_scale(std::vector<Pointf> points) {
Points int_points;
for (auto pt : points)
int_points.push_back(Point::new_scale(pt(0), pt(1)));
return Polygon(int_points);
static Polygon new_scale(const std::vector<Pointf> &points) {
Polygon pgn;
pgn.points.reserve(points.size());
for (const Pointf &pt : points)
pgn.points.emplace_back(Point::new_scale(pt(0), pt(1)));
return pgn;
}
Polygon& operator=(const Polygon &other) { points = other.points; return *this; }
Polygon& operator=(Polygon &&other) { points = std::move(other.points); return *this; }

View file

@ -23,12 +23,11 @@ public:
explicit Polyline(const Point &p1, const Point &p2) { points.reserve(2); points.emplace_back(p1); points.emplace_back(p2); }
Polyline& operator=(const Polyline &other) { points = other.points; return *this; }
Polyline& operator=(Polyline &&other) { points = std::move(other.points); return *this; }
static Polyline new_scale(std::vector<Pointf> points) {
static Polyline new_scale(const std::vector<Pointf> &points) {
Polyline pl;
Points int_points;
for (auto pt : points)
int_points.push_back(Point::new_scale(pt(0), pt(1)));
pl.append(int_points);
pl.points.reserve(points.size());
for (const Pointf &pt : points)
pl.points.emplace_back(Point::new_scale(pt(0), pt(1)));
return pl;
}

View file

@ -1575,8 +1575,7 @@ TriangleMesh make_cylinder(double r, double h, double fa) {
vertices.emplace_back(Vec3d(sin(0) * r , cos(0) * r, 0));
vertices.emplace_back(Vec3d(sin(0) * r , cos(0) * r, h));
for (double i = 0; i < 2*PI; i+=angle) {
Pointf p(0, r);
p.rotate(i);
Vec2d p = Eigen::Rotation2Dd(i) * Eigen::Vector2d(0, r);
vertices.emplace_back(Vec3d(p(0), p(1), 0.));
vertices.emplace_back(Vec3d(p(0), p(1), h));
id = vertices.size() - 1;
@ -1626,8 +1625,7 @@ TriangleMesh make_sphere(double rho, double fa) {
const double z = -rho + increment*rho*2.0;
// radius of the circle for this step.
const double r = sqrt(abs(rho*rho - z*z));
Pointf b(0, r);
b.rotate(ring[i]);
Vec2d b = Eigen::Rotation2Dd(ring[i]) * Eigen::Vector2d(0, r);
vertices.emplace_back(Vec3d(b(0), b(1), z));
facets.emplace_back((i == 0) ? Point3(1, 0, ring.size()) : Point3(id, 0, id - 1));
++ id;
@ -1639,8 +1637,7 @@ TriangleMesh make_sphere(double rho, double fa) {
const double r = sqrt(abs(rho*rho - z*z));
for (size_t i = 0; i < ring.size(); i++) {
Pointf b(0, r);
b.rotate(ring[i]);
Vec2d b = Eigen::Rotation2Dd(ring[i]) * Eigen::Vector2d(0, r);
vertices.emplace_back(Vec3d(b(0), b(1), z));
if (i == 0) {
// wrap around

View file

@ -270,7 +270,7 @@ bool ConfigBase__set(ConfigBase* THIS, const t_config_option_key &opt_key, SV* v
values.reserve(len);
for (size_t i = 0; i < len; i++) {
SV** elem = av_fetch(av, i, 0);
Pointf point;
Pointf point(Vec2d::Zero());
if (elem == NULL || !from_SV_check(*elem, &point)) return false;
values.emplace_back(point);
}

View file

@ -79,8 +79,7 @@ void Bed_2D::repaint()
auto step = 10; // 1cm grid
Polylines polylines;
for (auto x = bb.min(0) - fmod(bb.min(0), step) + step; x < bb.max(0); x += step) {
Polyline pl = Polyline::new_scale({ Pointf(x, bb.min(1)), Pointf(x, bb.max(1)) });
polylines.push_back(pl);
polylines.push_back(Polyline::new_scale({ Pointf(x, bb.min(1)), Pointf(x, bb.max(1)) }));
}
for (auto y = bb.min(1) - fmod(bb.min(1), step) + step; y < bb.max(1); y += step) {
polylines.push_back(Polyline::new_scale({ Pointf(bb.min(0), y), Pointf(bb.max(0), y) }));
@ -112,9 +111,7 @@ void Bed_2D::repaint()
auto x_end = Pointf(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(0) -= arrow_len;
end.rotate(angle, x_end);
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)));
}
@ -122,9 +119,7 @@ void Bed_2D::repaint()
auto y_end = Pointf(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(1) += arrow_len;
end.rotate(angle, y_end);
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)));
}

View file

@ -14,8 +14,8 @@ class Bed_2D : public wxPanel
bool m_painted = false;
bool m_interactive = false;
double m_scale_factor;
Pointf m_shift;
Pointf m_pos;
Pointf m_shift = Vec2d::Zero();
Pointf m_pos = Vec2d::Zero();
std::function<void(Pointf)> m_on_move = nullptr;
Point to_pixels(Pointf point);

View file

@ -952,8 +952,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;
Pointf b1_prev(Vec2d::Zero());
Vectorf v_prev(Vec2d::Zero());
int idx_initial[4] = { -1, -1, -1, -1 };
double width_initial = 0.;
double bottom_z_initial = 0.0;
@ -1064,7 +1064,7 @@ 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;
Pointf intersection(Vec2d::Zero());
Geometry::ray_ray_intersection(b1_prev, v_prev, a1, v, intersection);
a1 = intersection;
a2 = 2. * a - intersection;

View file

@ -230,11 +230,13 @@ void BedShapePanel::update_shape()
{
auto page_idx = m_shape_options_book->GetSelection();
if (page_idx == SHAPE_RECTANGULAR) {
Pointf rect_size, rect_origin;
Pointf rect_size(Vec2d::Zero());
Pointf rect_origin(Vec2d::Zero());
try{
rect_size = boost::any_cast<Pointf>(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"));
}

View file

@ -667,7 +667,7 @@ void PointCtrl::set_value(const Pointf& value, bool change_event)
void PointCtrl::set_value(const boost::any& value, bool change_event)
{
Pointf pt;
Pointf pt(Vec2d::Zero());
const Pointf *ptf = boost::any_cast<Pointf>(&value);
if (!ptf)
{
@ -681,13 +681,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(0) = val;
y_textctrl->GetValue().ToDouble(&val);
ret_point(1) = val;
return m_value = ret_point;
double x, y;
x_textctrl->GetValue().ToDouble(&x);
y_textctrl->GetValue().ToDouble(&y);
return m_value = Pointf(x, y);
}
void StaticText::BUILD()

View file

@ -396,6 +396,7 @@ GLGizmoScale::GLGizmoScale()
: GLGizmoBase()
, m_scale(1.0f)
, m_starting_scale(1.0f)
, m_starting_drag_position(Vec2d::Zero())
{
}

View file

@ -113,7 +113,7 @@ Point::coincides_with(point_sv)
void scale(double factor)
%code{% *THIS *= factor; %};
void rotate(double angle, Pointf* center)
%code{% THIS->rotate(angle, *center); %};
%code{% *THIS = Eigen::Translation2d(*center) * Eigen::Rotation2Dd(angle) * Eigen::Translation2d(- *center) * Eigen::Vector2d((*THIS)(0), (*THIS)(1)); %};
Pointf* negative()
%code{% RETVAL = new Pointf(- *THIS); %};
Pointf* vector_to(Pointf* point)