Merge remote-tracking branch 'remotes/origin/opengl_to_cpp'

This commit is contained in:
bubnikv 2018-07-17 09:37:38 +02:00
commit 83f9813f56
24 changed files with 832 additions and 2768 deletions

View file

@ -2,6 +2,8 @@
#include <algorithm>
#include <assert.h>
#include <Eigen/Dense>
namespace Slic3r {
template BoundingBoxBase<Point>::BoundingBoxBase(const std::vector<Point> &points);
@ -251,4 +253,41 @@ void BoundingBox::align_to_grid(const coord_t cell_size)
}
}
BoundingBoxf3 BoundingBoxf3::transformed(const std::vector<float>& matrix) const
{
Eigen::Matrix<float, 3, 8> vertices;
vertices(0, 0) = (float)min.x; vertices(1, 0) = (float)min.y; vertices(2, 0) = (float)min.z;
vertices(0, 1) = (float)max.x; vertices(1, 1) = (float)min.y; vertices(2, 1) = (float)min.z;
vertices(0, 2) = (float)max.x; vertices(1, 2) = (float)max.y; vertices(2, 2) = (float)min.z;
vertices(0, 3) = (float)min.x; vertices(1, 3) = (float)max.y; vertices(2, 3) = (float)min.z;
vertices(0, 4) = (float)min.x; vertices(1, 4) = (float)min.y; vertices(2, 4) = (float)max.z;
vertices(0, 5) = (float)max.x; vertices(1, 5) = (float)min.y; vertices(2, 5) = (float)max.z;
vertices(0, 6) = (float)max.x; vertices(1, 6) = (float)max.y; vertices(2, 6) = (float)max.z;
vertices(0, 7) = (float)min.x; vertices(1, 7) = (float)max.y; vertices(2, 7) = (float)max.z;
Eigen::Transform<float, 3, Eigen::Affine> m;
::memcpy((void*)m.data(), (const void*)matrix.data(), 16 * sizeof(float));
Eigen::Matrix<float, 3, 8> transf_vertices = m * vertices.colwise().homogeneous();
float min_x = transf_vertices(0, 0);
float max_x = transf_vertices(0, 0);
float min_y = transf_vertices(1, 0);
float max_y = transf_vertices(1, 0);
float min_z = transf_vertices(2, 0);
float max_z = transf_vertices(2, 0);
for (int i = 1; i < 8; ++i)
{
min_x = std::min(min_x, transf_vertices(0, i));
max_x = std::max(max_x, transf_vertices(0, i));
min_y = std::min(min_y, transf_vertices(1, i));
max_y = std::max(max_y, transf_vertices(1, i));
min_z = std::min(min_z, transf_vertices(2, i));
max_z = std::max(max_z, transf_vertices(2, i));
}
return BoundingBoxf3(Pointf3((coordf_t)min_x, (coordf_t)min_y, (coordf_t)min_z), Pointf3((coordf_t)max_x, (coordf_t)max_y, (coordf_t)max_z));
}
}

View file

@ -148,6 +148,8 @@ public:
BoundingBoxf3() : BoundingBox3Base<Pointf3>() {};
BoundingBoxf3(const Pointf3 &pmin, const Pointf3 &pmax) : BoundingBox3Base<Pointf3>(pmin, pmax) {};
BoundingBoxf3(const std::vector<Pointf3> &points) : BoundingBox3Base<Pointf3>(points) {};
BoundingBoxf3 transformed(const std::vector<float>& matrix) const;
};
template<typename VT>

View file

@ -13,9 +13,7 @@
#include <boost/filesystem/operations.hpp>
#include <boost/algorithm/string.hpp>
//############################################################################################################################################
#include <boost/nowide/fstream.hpp>
//############################################################################################################################################
#include <miniz/miniz_zip.h>
#if 0

View file

@ -21,6 +21,7 @@
// #include <benchmark.h>
#include "SVG.hpp"
#include <Eigen/Dense>
namespace Slic3r {
@ -990,10 +991,7 @@ void ModelObject::clear_instances()
// Returns the bounding box of the transformed instances.
// This bounding box is approximate and not snug.
//========================================================================================================
const BoundingBoxf3& ModelObject::bounding_box() const
//const BoundingBoxf3& ModelObject::bounding_box()
//========================================================================================================
{
if (! m_bounding_box_valid) {
BoundingBoxf3 raw_bbox;
@ -1435,32 +1433,16 @@ BoundingBoxf3 ModelInstance::transform_mesh_bounding_box(const TriangleMesh* mes
BoundingBoxf3 ModelInstance::transform_bounding_box(const BoundingBoxf3 &bbox, bool dont_translate) const
{
// rotate around mesh origin
double c = cos(this->rotation);
double s = sin(this->rotation);
Pointf3 pts[4] = {
bbox.min,
bbox.max,
Pointf3(bbox.min.x, bbox.max.y, bbox.min.z),
Pointf3(bbox.max.x, bbox.min.y, bbox.max.z)
};
BoundingBoxf3 out;
for (int i = 0; i < 4; ++ i) {
Pointf3 &v = pts[i];
double xold = v.x;
double yold = v.y;
v.x = float(c * xold - s * yold);
v.y = float(s * xold + c * yold);
v.x *= this->scaling_factor;
v.y *= this->scaling_factor;
v.z *= this->scaling_factor;
if (! dont_translate) {
v.x += this->offset.x;
v.y += this->offset.y;
}
out.merge(v);
}
return out;
Eigen::Transform<float, 3, Eigen::Affine> matrix = Eigen::Transform<float, 3, Eigen::Affine>::Identity();
if (!dont_translate)
matrix.translate(Eigen::Vector3f((float)offset.x, (float)offset.y, 0.0f));
matrix.rotate(Eigen::AngleAxisf(rotation, Eigen::Vector3f::UnitZ()));
matrix.scale(scaling_factor);
std::vector<float> m(16, 0.0f);
::memcpy((void*)m.data(), (const void*)matrix.data(), 16 * sizeof(float));
return bbox.transformed(m);
}
void ModelInstance::transform_polygon(Polygon* polygon) const

View file

@ -103,10 +103,7 @@ public:
// Returns the bounding box of the transformed instances.
// This bounding box is approximate and not snug.
// This bounding box is being cached.
//========================================================================================================
const BoundingBoxf3& bounding_box() const;
// const BoundingBoxf3& bounding_box();
//========================================================================================================
void invalidate_bounding_box() { m_bounding_box_valid = false; }
// Returns a snug bounding box of the transformed instances.
// This bounding box is not being cached.
@ -148,10 +145,9 @@ private:
// Parent object, owning this ModelObject.
Model *m_model;
// Bounding box, cached.
//========================================================================================================
mutable BoundingBoxf3 m_bounding_box;
mutable bool m_bounding_box_valid;
//========================================================================================================
};
// An object STL, or a modifier volume, over which a different set of parameters shall be applied.

View file

@ -96,7 +96,8 @@ public:
void call(int i, int j) const;
void call(const std::vector<int>& ints) const;
void call(double d) const;
void call(double x, double y) const;
void call(double a, double b) const;
void call(double a, double b, double c, double d) const;
void call(bool b) const;
private:
void *m_callback;

View file

@ -266,7 +266,7 @@ void PerlCallback::call(double d) const
LEAVE;
}
void PerlCallback::call(double x, double y) const
void PerlCallback::call(double a, double b) const
{
if (!m_callback)
return;
@ -274,8 +274,26 @@ void PerlCallback::call(double x, double y) const
ENTER;
SAVETMPS;
PUSHMARK(SP);
XPUSHs(sv_2mortal(newSVnv(x)));
XPUSHs(sv_2mortal(newSVnv(y)));
XPUSHs(sv_2mortal(newSVnv(a)));
XPUSHs(sv_2mortal(newSVnv(b)));
PUTBACK;
perl_call_sv(SvRV((SV*)m_callback), G_DISCARD);
FREETMPS;
LEAVE;
}
void PerlCallback::call(double a, double b, double c, double d) const
{
if (!m_callback)
return;
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
XPUSHs(sv_2mortal(newSVnv(a)));
XPUSHs(sv_2mortal(newSVnv(b)));
XPUSHs(sv_2mortal(newSVnv(c)));
XPUSHs(sv_2mortal(newSVnv(d)));
PUTBACK;
perl_call_sv(SvRV((SV*)m_callback), G_DISCARD);
FREETMPS;