mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-25 15:44:12 -06:00
Merge remote-tracking branch 'origin/dev2' into dev_native
This commit is contained in:
commit
20d0f046d2
34 changed files with 1300 additions and 694 deletions
|
@ -1284,6 +1284,9 @@ namespace Slic3r {
|
|||
transform(1, 0) * inv_sx, transform(1, 1) * inv_sy, transform(1, 2) * inv_sz,
|
||||
transform(2, 0) * inv_sx, transform(2, 1) * inv_sy, transform(2, 2) * inv_sz;
|
||||
|
||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
Vec3d rotation = m3x3.eulerAngles(0, 1, 2);
|
||||
#else
|
||||
Eigen::AngleAxisd rotation;
|
||||
rotation.fromRotationMatrix(m3x3);
|
||||
|
||||
|
@ -1292,6 +1295,7 @@ namespace Slic3r {
|
|||
return;
|
||||
|
||||
double angle_z = (rotation.axis() == Vec3d::UnitZ()) ? rotation.angle() : -rotation.angle();
|
||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
|
||||
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
||||
instance.set_offset(offset);
|
||||
|
@ -1300,7 +1304,11 @@ namespace Slic3r {
|
|||
instance.offset(1) = offset_y;
|
||||
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
|
||||
instance.scaling_factor = sx;
|
||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
instance.set_rotation(rotation);
|
||||
#else
|
||||
instance.rotation = angle_z;
|
||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
}
|
||||
|
||||
bool _3MF_Importer::_handle_start_config(const char** attributes, unsigned int num_attributes)
|
||||
|
|
|
@ -30,7 +30,12 @@
|
|||
// 0 : .amf, .amf.xml and .zip.amf files saved by older slic3r. No version definition in them.
|
||||
// 1 : Introduction of amf versioning. No other change in data saved into amf files.
|
||||
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
// 2 : Added z component of offset
|
||||
// Added x and y components of rotation
|
||||
#else
|
||||
// 2 : Added z component of offset.
|
||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
const unsigned int VERSION_AMF = 2;
|
||||
#else
|
||||
const unsigned int VERSION_AMF = 1;
|
||||
|
@ -127,6 +132,10 @@ struct AMFParserContext
|
|||
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
||||
NODE_TYPE_DELTAZ, // amf/constellation/instance/deltaz
|
||||
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
|
||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
NODE_TYPE_RX, // amf/constellation/instance/rx
|
||||
NODE_TYPE_RY, // amf/constellation/instance/ry
|
||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
NODE_TYPE_RZ, // amf/constellation/instance/rz
|
||||
NODE_TYPE_SCALE, // amf/constellation/instance/scale
|
||||
NODE_TYPE_METADATA, // anywhere under amf/*/metadata
|
||||
|
@ -134,7 +143,11 @@ struct AMFParserContext
|
|||
|
||||
struct Instance {
|
||||
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
Instance() : deltax_set(false), deltay_set(false), deltaz_set(false), rx_set(false), ry_set(false), rz_set(false), scale_set(false) {}
|
||||
#else
|
||||
Instance() : deltax_set(false), deltay_set(false), deltaz_set(false), rz_set(false), scale_set(false) {}
|
||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
#else
|
||||
Instance() : deltax_set(false), deltay_set(false), rz_set(false), scale_set(false) {}
|
||||
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
|
||||
|
@ -149,6 +162,14 @@ struct AMFParserContext
|
|||
float deltaz;
|
||||
bool deltaz_set;
|
||||
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
|
||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
// Rotation around the X axis.
|
||||
float rx;
|
||||
bool rx_set;
|
||||
// Rotation around the Y axis.
|
||||
float ry;
|
||||
bool ry_set;
|
||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
// Rotation around the Z axis.
|
||||
float rz;
|
||||
bool rz_set;
|
||||
|
@ -275,6 +296,12 @@ void AMFParserContext::startElement(const char *name, const char **atts)
|
|||
else if (strcmp(name, "deltaz") == 0)
|
||||
node_type_new = NODE_TYPE_DELTAZ;
|
||||
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
|
||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
else if (strcmp(name, "rx") == 0)
|
||||
node_type_new = NODE_TYPE_RX;
|
||||
else if (strcmp(name, "ry") == 0)
|
||||
node_type_new = NODE_TYPE_RY;
|
||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
else if (strcmp(name, "rz") == 0)
|
||||
node_type_new = NODE_TYPE_RZ;
|
||||
else if (strcmp(name, "scale") == 0)
|
||||
|
@ -339,7 +366,11 @@ void AMFParserContext::characters(const XML_Char *s, int len)
|
|||
if (m_path.back() == NODE_TYPE_DELTAX ||
|
||||
m_path.back() == NODE_TYPE_DELTAY ||
|
||||
m_path.back() == NODE_TYPE_DELTAZ ||
|
||||
m_path.back() == NODE_TYPE_RZ ||
|
||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
m_path.back() == NODE_TYPE_RX ||
|
||||
m_path.back() == NODE_TYPE_RY ||
|
||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
m_path.back() == NODE_TYPE_RZ ||
|
||||
m_path.back() == NODE_TYPE_SCALE)
|
||||
#else
|
||||
if (m_path.back() == NODE_TYPE_DELTAX || m_path.back() == NODE_TYPE_DELTAY || m_path.back() == NODE_TYPE_RZ || m_path.back() == NODE_TYPE_SCALE)
|
||||
|
@ -391,6 +422,20 @@ void AMFParserContext::endElement(const char * /* name */)
|
|||
m_value[0].clear();
|
||||
break;
|
||||
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
|
||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
case NODE_TYPE_RX:
|
||||
assert(m_instance);
|
||||
m_instance->rx = float(atof(m_value[0].c_str()));
|
||||
m_instance->rx_set = true;
|
||||
m_value[0].clear();
|
||||
break;
|
||||
case NODE_TYPE_RY:
|
||||
assert(m_instance);
|
||||
m_instance->ry = float(atof(m_value[0].c_str()));
|
||||
m_instance->ry_set = true;
|
||||
m_value[0].clear();
|
||||
break;
|
||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
case NODE_TYPE_RZ:
|
||||
assert(m_instance);
|
||||
m_instance->rz = float(atof(m_value[0].c_str()));
|
||||
|
@ -542,12 +587,16 @@ void AMFParserContext::endDocument()
|
|||
if (instance.deltax_set && instance.deltay_set) {
|
||||
ModelInstance *mi = m_model.objects[object.second.idx]->add_instance();
|
||||
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
||||
mi->set_offset(Vec3d((double)instance.deltax, (double)instance.deltay, (double)instance.deltaz));
|
||||
mi->set_offset(Vec3d(instance.deltax_set ? (double)instance.deltax : 0.0, instance.deltay_set ? (double)instance.deltay : 0.0, instance.deltaz_set ? (double)instance.deltaz : 0.0));
|
||||
#else
|
||||
mi->offset(0) = instance.deltax;
|
||||
mi->offset(1) = instance.deltay;
|
||||
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
|
||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
mi->set_rotation(Vec3d(instance.rx_set ? (double)instance.rx : 0.0, instance.ry_set ? (double)instance.ry : 0.0, instance.rz_set ? (double)instance.rz : 0.0));
|
||||
#else
|
||||
mi->rotation = instance.rz_set ? instance.rz : 0.f;
|
||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
mi->scaling_factor = instance.scale_set ? instance.scale : 1.f;
|
||||
}
|
||||
}
|
||||
|
@ -851,6 +900,10 @@ bool store_amf(const char *path, Model *model, Print* print, bool export_print_c
|
|||
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
||||
" <deltaz>%lf</deltaz>\n"
|
||||
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
|
||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
" <rx>%lf</rx>\n"
|
||||
" <ry>%lf</ry>\n"
|
||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
" <rz>%lf</rz>\n"
|
||||
" <scale>%lf</scale>\n"
|
||||
" </instance>\n",
|
||||
|
@ -863,8 +916,15 @@ bool store_amf(const char *path, Model *model, Print* print, bool export_print_c
|
|||
instance->offset(0),
|
||||
instance->offset(1),
|
||||
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
|
||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
instance->get_rotation(X),
|
||||
instance->get_rotation(Y),
|
||||
instance->get_rotation(Z),
|
||||
#else
|
||||
instance->rotation,
|
||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
instance->scaling_factor);
|
||||
|
||||
//FIXME missing instance->scaling_factor
|
||||
instances.append(buf);
|
||||
}
|
||||
|
|
|
@ -164,7 +164,11 @@ bool load_prus(const char *path, Model *model)
|
|||
const char *zero_tag = "<zero>";
|
||||
const char *zero_xml = strstr(scene_xml_data.data(), zero_tag);
|
||||
float trafo[3][4] = { 0 };
|
||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
Vec3d instance_rotation = Vec3d::Zero();
|
||||
#else
|
||||
double instance_rotation = 0.;
|
||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
double instance_scaling_factor = 1.f;
|
||||
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
||||
Vec3d instance_offset = Vec3d::Zero();
|
||||
|
@ -197,10 +201,14 @@ bool load_prus(const char *path, Model *model)
|
|||
instance_scaling_factor = scale[0];
|
||||
scale[0] = scale[1] = scale[2] = 1.;
|
||||
}
|
||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
instance_rotation = Vec3d(-(double)rotation[0], -(double)rotation[1], -(double)rotation[2]);
|
||||
#else
|
||||
if (rotation[0] == 0. && rotation[1] == 0.) {
|
||||
instance_rotation = - rotation[2];
|
||||
rotation[2] = 0.;
|
||||
}
|
||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
Eigen::Matrix3f mat_rot, mat_scale, mat_trafo;
|
||||
mat_rot = Eigen::AngleAxisf(-rotation[2], Eigen::Vector3f::UnitZ()) *
|
||||
Eigen::AngleAxisf(-rotation[1], Eigen::Vector3f::UnitY()) *
|
||||
|
@ -366,8 +374,12 @@ bool load_prus(const char *path, Model *model)
|
|||
model_object = model->add_object(name_utf8.data(), path, std::move(mesh));
|
||||
volume = model_object->volumes.front();
|
||||
ModelInstance *instance = model_object->add_instance();
|
||||
instance->rotation = instance_rotation;
|
||||
instance->scaling_factor = instance_scaling_factor;
|
||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
instance->set_rotation(instance_rotation);
|
||||
#else
|
||||
instance->rotation = instance_rotation;
|
||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
instance->scaling_factor = instance_scaling_factor;
|
||||
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
||||
instance->set_offset(instance_offset);
|
||||
#else
|
||||
|
|
|
@ -1066,6 +1066,29 @@ size_t ModelVolume::split(unsigned int max_extruders)
|
|||
return idx;
|
||||
}
|
||||
|
||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
void ModelInstance::set_rotation(const Vec3d& rotation)
|
||||
{
|
||||
set_rotation(X, rotation(0));
|
||||
set_rotation(Y, rotation(1));
|
||||
set_rotation(Z, rotation(2));
|
||||
}
|
||||
|
||||
void ModelInstance::set_rotation(Axis axis, double rotation)
|
||||
{
|
||||
static const double TWO_PI = 2.0 * (double)PI;
|
||||
while (rotation < 0.0)
|
||||
{
|
||||
rotation += TWO_PI;
|
||||
}
|
||||
while (TWO_PI < rotation)
|
||||
{
|
||||
rotation -= TWO_PI;
|
||||
}
|
||||
m_rotation(axis) = rotation;
|
||||
}
|
||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
|
||||
void ModelInstance::transform_mesh(TriangleMesh* mesh, bool dont_translate) const
|
||||
{
|
||||
mesh->transform(world_matrix(dont_translate).cast<float>());
|
||||
|
@ -1110,7 +1133,12 @@ Vec3d ModelInstance::transform_vector(const Vec3d& v, bool dont_translate) const
|
|||
|
||||
void ModelInstance::transform_polygon(Polygon* polygon) const
|
||||
{
|
||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
// CHECK_ME -> Is the following correct or it should take in account all three rotations ?
|
||||
polygon->rotate(this->m_rotation(2)); // rotate around polygon origin
|
||||
#else
|
||||
polygon->rotate(this->rotation); // rotate around polygon origin
|
||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
polygon->scale(this->scaling_factor); // scale around polygon origin
|
||||
}
|
||||
|
||||
|
@ -1126,7 +1154,15 @@ Transform3d ModelInstance::world_matrix(bool dont_translate, bool dont_rotate, b
|
|||
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
|
||||
|
||||
if (!dont_rotate)
|
||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
{
|
||||
m.rotate(Eigen::AngleAxisd(m_rotation(2), Vec3d::UnitZ()));
|
||||
m.rotate(Eigen::AngleAxisd(m_rotation(1), Vec3d::UnitY()));
|
||||
m.rotate(Eigen::AngleAxisd(m_rotation(0), Vec3d::UnitX()));
|
||||
}
|
||||
#else
|
||||
m.rotate(Eigen::AngleAxisd(rotation, Vec3d::UnitZ()));
|
||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
|
||||
if (!dont_scale)
|
||||
m.scale(scaling_factor);
|
||||
|
|
|
@ -248,11 +248,16 @@ public:
|
|||
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
||||
private:
|
||||
Vec3d m_offset; // in unscaled coordinates
|
||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
Vec3d m_rotation; // Rotation around the three axes, in radians around mesh center point
|
||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
|
||||
public:
|
||||
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
|
||||
|
||||
#if !ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
double rotation; // Rotation around the Z axis, in radians around mesh center point
|
||||
#endif // !ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
double scaling_factor;
|
||||
#if !ENABLE_MODELINSTANCE_3D_OFFSET
|
||||
Vec2d offset; // in unscaled coordinates
|
||||
|
@ -271,6 +276,14 @@ public:
|
|||
void set_offset(Axis axis, double offset) { m_offset(axis) = offset; }
|
||||
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
|
||||
|
||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
const Vec3d& get_rotation() const { return m_rotation; }
|
||||
double get_rotation(Axis axis) const { return m_rotation(axis); }
|
||||
|
||||
void set_rotation(const Vec3d& rotation);
|
||||
void set_rotation(Axis axis, double rotation);
|
||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
|
||||
// To be called on an external mesh
|
||||
void transform_mesh(TriangleMesh* mesh, bool dont_translate = false) const;
|
||||
// Calculate a bounding box of a transformed mesh. To be called on an external mesh.
|
||||
|
@ -291,9 +304,15 @@ private:
|
|||
ModelObject* object;
|
||||
|
||||
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
ModelInstance(ModelObject *object) : m_rotation(Vec3d::Zero()), scaling_factor(1), m_offset(Vec3d::Zero()), object(object), print_volume_state(PVS_Inside) {}
|
||||
ModelInstance(ModelObject *object, const ModelInstance &other) :
|
||||
m_rotation(other.m_rotation), scaling_factor(other.scaling_factor), m_offset(other.m_offset), object(object), print_volume_state(PVS_Inside) {}
|
||||
#else
|
||||
ModelInstance(ModelObject *object) : rotation(0), scaling_factor(1), m_offset(Vec3d::Zero()), object(object), print_volume_state(PVS_Inside) {}
|
||||
ModelInstance(ModelObject *object, const ModelInstance &other) :
|
||||
rotation(other.rotation), scaling_factor(other.scaling_factor), m_offset(other.m_offset), object(object), print_volume_state(PVS_Inside) {}
|
||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
#else
|
||||
ModelInstance(ModelObject *object) : rotation(0), scaling_factor(1), offset(Vec2d::Zero()), object(object), print_volume_state(PVS_Inside) {}
|
||||
ModelInstance(ModelObject *object, const ModelInstance &other) :
|
||||
|
|
|
@ -292,59 +292,59 @@ protected:
|
|||
using Distance = TCoord<PointImpl>;
|
||||
using Pile = sl::Shapes<PolygonImpl>;
|
||||
|
||||
Packer pck_;
|
||||
PConfig pconf_; // Placement configuration
|
||||
double bin_area_;
|
||||
SpatIndex rtree_;
|
||||
SpatIndex smallsrtree_;
|
||||
double norm_;
|
||||
Pile merged_pile_;
|
||||
Box pilebb_;
|
||||
ItemGroup remaining_;
|
||||
ItemGroup items_;
|
||||
Packer m_pck;
|
||||
PConfig m_pconf; // Placement configuration
|
||||
double m_bin_area;
|
||||
SpatIndex m_rtree;
|
||||
SpatIndex m_smallsrtree;
|
||||
double m_norm;
|
||||
Pile m_merged_pile;
|
||||
Box m_pilebb;
|
||||
ItemGroup m_remaining;
|
||||
ItemGroup m_items;
|
||||
public:
|
||||
|
||||
_ArrBase(const TBin& bin, Distance dist,
|
||||
std::function<void(unsigned)> progressind,
|
||||
std::function<bool(void)> stopcond):
|
||||
pck_(bin, dist), bin_area_(sl::area(bin)),
|
||||
norm_(std::sqrt(sl::area(bin)))
|
||||
m_pck(bin, dist), m_bin_area(sl::area(bin)),
|
||||
m_norm(std::sqrt(sl::area(bin)))
|
||||
{
|
||||
fillConfig(pconf_);
|
||||
fillConfig(m_pconf);
|
||||
|
||||
pconf_.before_packing =
|
||||
m_pconf.before_packing =
|
||||
[this](const Pile& merged_pile, // merged pile
|
||||
const ItemGroup& items, // packed items
|
||||
const ItemGroup& remaining) // future items to be packed
|
||||
{
|
||||
items_ = items;
|
||||
merged_pile_ = merged_pile;
|
||||
remaining_ = remaining;
|
||||
m_items = items;
|
||||
m_merged_pile = merged_pile;
|
||||
m_remaining = remaining;
|
||||
|
||||
pilebb_ = sl::boundingBox(merged_pile);
|
||||
m_pilebb = sl::boundingBox(merged_pile);
|
||||
|
||||
rtree_.clear();
|
||||
smallsrtree_.clear();
|
||||
m_rtree.clear();
|
||||
m_smallsrtree.clear();
|
||||
|
||||
// We will treat big items (compared to the print bed) differently
|
||||
auto isBig = [this](double a) {
|
||||
return a/bin_area_ > BIG_ITEM_TRESHOLD ;
|
||||
return a/m_bin_area > BIG_ITEM_TRESHOLD ;
|
||||
};
|
||||
|
||||
for(unsigned idx = 0; idx < items.size(); ++idx) {
|
||||
Item& itm = items[idx];
|
||||
if(isBig(itm.area())) rtree_.insert({itm.boundingBox(), idx});
|
||||
smallsrtree_.insert({itm.boundingBox(), idx});
|
||||
if(isBig(itm.area())) m_rtree.insert({itm.boundingBox(), idx});
|
||||
m_smallsrtree.insert({itm.boundingBox(), idx});
|
||||
}
|
||||
};
|
||||
|
||||
pck_.progressIndicator(progressind);
|
||||
pck_.stopCondition(stopcond);
|
||||
m_pck.progressIndicator(progressind);
|
||||
m_pck.stopCondition(stopcond);
|
||||
}
|
||||
|
||||
template<class...Args> inline IndexedPackGroup operator()(Args&&...args) {
|
||||
rtree_.clear();
|
||||
return pck_.executeIndexed(std::forward<Args>(args)...);
|
||||
m_rtree.clear();
|
||||
return m_pck.executeIndexed(std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -358,18 +358,18 @@ public:
|
|||
_ArrBase<Box>(bin, dist, progressind, stopcond)
|
||||
{
|
||||
|
||||
pconf_.object_function = [this, bin] (const Item &item) {
|
||||
m_pconf.object_function = [this, bin] (const Item &item) {
|
||||
|
||||
auto result = objfunc(bin.center(),
|
||||
merged_pile_,
|
||||
pilebb_,
|
||||
items_,
|
||||
m_merged_pile,
|
||||
m_pilebb,
|
||||
m_items,
|
||||
item,
|
||||
bin_area_,
|
||||
norm_,
|
||||
rtree_,
|
||||
smallsrtree_,
|
||||
remaining_);
|
||||
m_bin_area,
|
||||
m_norm,
|
||||
m_rtree,
|
||||
m_smallsrtree,
|
||||
m_remaining);
|
||||
|
||||
double score = std::get<0>(result);
|
||||
auto& fullbb = std::get<1>(result);
|
||||
|
@ -381,7 +381,7 @@ public:
|
|||
return score;
|
||||
};
|
||||
|
||||
pck_.configure(pconf_);
|
||||
m_pck.configure(m_pconf);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -396,27 +396,27 @@ public:
|
|||
std::function<bool(void)> stopcond):
|
||||
_ArrBase<lnCircle>(bin, dist, progressind, stopcond) {
|
||||
|
||||
pconf_.object_function = [this, &bin] (const Item &item) {
|
||||
m_pconf.object_function = [this, &bin] (const Item &item) {
|
||||
|
||||
auto result = objfunc(bin.center(),
|
||||
merged_pile_,
|
||||
pilebb_,
|
||||
items_,
|
||||
m_merged_pile,
|
||||
m_pilebb,
|
||||
m_items,
|
||||
item,
|
||||
bin_area_,
|
||||
norm_,
|
||||
rtree_,
|
||||
smallsrtree_,
|
||||
remaining_);
|
||||
m_bin_area,
|
||||
m_norm,
|
||||
m_rtree,
|
||||
m_smallsrtree,
|
||||
m_remaining);
|
||||
|
||||
double score = std::get<0>(result);
|
||||
|
||||
auto isBig = [this](const Item& itm) {
|
||||
return itm.area()/bin_area_ > BIG_ITEM_TRESHOLD ;
|
||||
return itm.area()/m_bin_area > BIG_ITEM_TRESHOLD ;
|
||||
};
|
||||
|
||||
if(isBig(item)) {
|
||||
auto mp = merged_pile_;
|
||||
auto mp = m_merged_pile;
|
||||
mp.push_back(item.transformedShape());
|
||||
auto chull = sl::convexHull(mp);
|
||||
double miss = Placer::overfit(chull, bin);
|
||||
|
@ -427,7 +427,7 @@ public:
|
|||
return score;
|
||||
};
|
||||
|
||||
pck_.configure(pconf_);
|
||||
m_pck.configure(m_pconf);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -439,25 +439,25 @@ public:
|
|||
std::function<bool(void)> stopcond):
|
||||
_ArrBase<PolygonImpl>(bin, dist, progressind, stopcond)
|
||||
{
|
||||
pconf_.object_function = [this, &bin] (const Item &item) {
|
||||
m_pconf.object_function = [this, &bin] (const Item &item) {
|
||||
|
||||
auto binbb = sl::boundingBox(bin);
|
||||
auto result = objfunc(binbb.center(),
|
||||
merged_pile_,
|
||||
pilebb_,
|
||||
items_,
|
||||
m_merged_pile,
|
||||
m_pilebb,
|
||||
m_items,
|
||||
item,
|
||||
bin_area_,
|
||||
norm_,
|
||||
rtree_,
|
||||
smallsrtree_,
|
||||
remaining_);
|
||||
m_bin_area,
|
||||
m_norm,
|
||||
m_rtree,
|
||||
m_smallsrtree,
|
||||
m_remaining);
|
||||
double score = std::get<0>(result);
|
||||
|
||||
return score;
|
||||
};
|
||||
|
||||
pck_.configure(pconf_);
|
||||
m_pck.configure(m_pconf);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -469,22 +469,22 @@ public:
|
|||
std::function<bool(void)> stopcond):
|
||||
_ArrBase<Box>(Box(0, 0), dist, progressind, stopcond)
|
||||
{
|
||||
this->pconf_.object_function = [this] (const Item &item) {
|
||||
this->m_pconf.object_function = [this] (const Item &item) {
|
||||
|
||||
auto result = objfunc({0, 0},
|
||||
merged_pile_,
|
||||
pilebb_,
|
||||
items_,
|
||||
m_merged_pile,
|
||||
m_pilebb,
|
||||
m_items,
|
||||
item,
|
||||
0,
|
||||
norm_,
|
||||
rtree_,
|
||||
smallsrtree_,
|
||||
remaining_);
|
||||
m_norm,
|
||||
m_rtree,
|
||||
m_smallsrtree,
|
||||
m_remaining);
|
||||
return std::get<0>(result);
|
||||
};
|
||||
|
||||
this->pck_.configure(pconf_);
|
||||
this->m_pck.configure(m_pconf);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -527,14 +527,19 @@ ShapeData2D projectModelFromTop(const Slic3r::Model &model) {
|
|||
|
||||
// Invalid geometries would throw exceptions when arranging
|
||||
if(item.vertexCount() > 3) {
|
||||
item.rotation(objinst->rotation);
|
||||
item.translation( {
|
||||
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
||||
ClipperLib::cInt(objinst->get_offset(X) / SCALING_FACTOR),
|
||||
ClipperLib::cInt(objinst->get_offset(Y) / SCALING_FACTOR)
|
||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
// CHECK_ME -> is the following correct or it should take in account all three rotations ?
|
||||
item.rotation(objinst->get_rotation(Z));
|
||||
#else
|
||||
ClipperLib::cInt(objinst->offset(0)/SCALING_FACTOR),
|
||||
ClipperLib::cInt(objinst->offset(1)/SCALING_FACTOR)
|
||||
item.rotation(objinst->rotation);
|
||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
item.translation({
|
||||
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
||||
ClipperLib::cInt(objinst->get_offset(X)/SCALING_FACTOR),
|
||||
ClipperLib::cInt(objinst->get_offset(Y)/SCALING_FACTOR)
|
||||
#else
|
||||
ClipperLib::cInt(objinst->offset(0)/SCALING_FACTOR),
|
||||
ClipperLib::cInt(objinst->offset(1)/SCALING_FACTOR)
|
||||
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
|
||||
});
|
||||
ret.emplace_back(objinst, item);
|
||||
|
@ -668,18 +673,25 @@ void applyResult(
|
|||
// Get the model instance from the shapemap using the index
|
||||
ModelInstance *inst_ptr = shapemap[idx].first;
|
||||
|
||||
// Get the tranformation data from the item object and scale it
|
||||
// Get the transformation data from the item object and scale it
|
||||
// appropriately
|
||||
auto off = item.translation();
|
||||
Radians rot = item.rotation();
|
||||
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
||||
Vec3d foff(off.X*SCALING_FACTOR + batch_offset, off.Y*SCALING_FACTOR, 0.0);
|
||||
Vec3d foff(off.X*SCALING_FACTOR + batch_offset,
|
||||
off.Y*SCALING_FACTOR,
|
||||
0.0);
|
||||
#else
|
||||
Vec2d foff(off.X*SCALING_FACTOR + batch_offset, off.Y*SCALING_FACTOR);
|
||||
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
|
||||
|
||||
// write the tranformation data into the model instance
|
||||
// write the transformation data into the model instance
|
||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
// CHECK_ME -> Is the following correct ?
|
||||
inst_ptr->set_rotation(Vec3d(0.0, 0.0, rot));
|
||||
#else
|
||||
inst_ptr->rotation = rot;
|
||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
||||
inst_ptr->set_offset(foff);
|
||||
#else
|
||||
|
@ -695,7 +707,7 @@ void applyResult(
|
|||
* The arrangement considers multiple bins (aka. print beds) for placing all
|
||||
* the items provided in the model argument. If the items don't fit on one
|
||||
* print bed, the remaining will be placed onto newly created print beds.
|
||||
* The first_bin_only parameter, if set to true, disables this behaviour and
|
||||
* The first_bin_only parameter, if set to true, disables this behavior and
|
||||
* makes sure that only one print bed is filled and the remaining items will be
|
||||
* untouched. When set to false, the items which could not fit onto the
|
||||
* print bed will be placed next to the print bed so the user should see a
|
||||
|
@ -741,6 +753,7 @@ bool arrange(Model &model, coordf_t min_obj_distance,
|
|||
|
||||
IndexedPackGroup result;
|
||||
|
||||
// If there is no hint about the shape, we will try to guess
|
||||
if(bedhint.type == BedShapeType::WHO_KNOWS) bedhint = bedShape(bed);
|
||||
|
||||
BoundingBox bbb(bed);
|
||||
|
|
|
@ -32,10 +32,10 @@ template<FilePrinterFormat format, class LayerFormat = void>
|
|||
class FilePrinter {
|
||||
public:
|
||||
|
||||
void printConfig(const Print&);
|
||||
void print_config(const Print&);
|
||||
|
||||
// Draw an ExPolygon which is a polygon inside a slice on the specified layer.
|
||||
void drawPolygon(const ExPolygon& p, unsigned lyr);
|
||||
void draw_polygon(const ExPolygon& p, unsigned lyr);
|
||||
|
||||
// Tell the printer how many layers should it consider.
|
||||
void layers(unsigned layernum);
|
||||
|
@ -47,45 +47,47 @@ public:
|
|||
* specified layer number than an appropriate number of layers will be
|
||||
* allocated in the printer.
|
||||
*/
|
||||
void beginLayer(unsigned layer);
|
||||
void begin_layer(unsigned layer);
|
||||
|
||||
// Allocate a new layer on top of the last and switch to it.
|
||||
void beginLayer();
|
||||
void begin_layer();
|
||||
|
||||
/*
|
||||
* Finish the selected layer. It means that no drawing is allowed on that
|
||||
* layer anymore. This fact can be used to prepare the file system output
|
||||
* data like png comprimation and so on.
|
||||
*/
|
||||
void finishLayer(unsigned layer);
|
||||
void finish_layer(unsigned layer);
|
||||
|
||||
// Finish the top layer.
|
||||
void finishLayer();
|
||||
void finish_layer();
|
||||
|
||||
// Save all the layers into the file (or dir) specified in the path argument
|
||||
void save(const std::string& path);
|
||||
|
||||
// Save only the selected layer to the file specified in path argument.
|
||||
void saveLayer(unsigned lyr, const std::string& path);
|
||||
void save_layer(unsigned lyr, const std::string& path);
|
||||
};
|
||||
|
||||
template<class T = void> struct VeryFalse { static const bool value = false; };
|
||||
|
||||
// This has to be explicitly implemented in the gui layer or a default zlib
|
||||
// based implementation is needed.
|
||||
template<class Backend> class Zipper {
|
||||
template<class Backend> class LayerWriter {
|
||||
public:
|
||||
|
||||
Zipper(const std::string& /*zipfile_path*/) {
|
||||
LayerWriter(const std::string& /*zipfile_path*/) {
|
||||
static_assert(VeryFalse<Backend>::value,
|
||||
"No zipper implementation provided!");
|
||||
"No layer writer implementation provided!");
|
||||
}
|
||||
|
||||
void next_entry(const std::string& /*fname*/) {}
|
||||
|
||||
std::string get_name() { return ""; }
|
||||
|
||||
template<class T> Zipper& operator<<(const T& /*arg*/) {
|
||||
bool is_ok() { return false; }
|
||||
|
||||
template<class T> LayerWriter& operator<<(const T& /*arg*/) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -110,22 +112,22 @@ template<class LyrFormat> class FilePrinter<FilePrinterFormat::PNG, LyrFormat> {
|
|||
|
||||
// We will save the compressed PNG data into stringstreams which can be done
|
||||
// in parallel. Later we can write every layer to the disk sequentially.
|
||||
std::vector<Layer> layers_rst_;
|
||||
Raster::Resolution res_;
|
||||
Raster::PixelDim pxdim_;
|
||||
const Print *print_ = nullptr;
|
||||
double exp_time_s_ = .0, exp_time_first_s_ = .0;
|
||||
std::vector<Layer> m_layers_rst;
|
||||
Raster::Resolution m_res;
|
||||
Raster::PixelDim m_pxdim;
|
||||
const Print *m_print = nullptr;
|
||||
double m_exp_time_s = .0, m_exp_time_first_s = .0;
|
||||
|
||||
std::string createIniContent(const std::string& projectname) {
|
||||
double layer_height = print_?
|
||||
print_->default_object_config().layer_height.getFloat() :
|
||||
double layer_height = m_print?
|
||||
m_print->default_object_config().layer_height.getFloat() :
|
||||
0.05;
|
||||
|
||||
using std::string;
|
||||
using std::to_string;
|
||||
|
||||
auto expt_str = to_string(exp_time_s_);
|
||||
auto expt_first_str = to_string(exp_time_first_s_);
|
||||
auto expt_str = to_string(m_exp_time_s);
|
||||
auto expt_first_str = to_string(m_exp_time_first_s);
|
||||
auto stepnum_str = to_string(static_cast<unsigned>(800*layer_height));
|
||||
auto layerh_str = to_string(layer_height);
|
||||
|
||||
|
@ -153,117 +155,84 @@ public:
|
|||
inline FilePrinter(double width_mm, double height_mm,
|
||||
unsigned width_px, unsigned height_px,
|
||||
double exp_time, double exp_time_first):
|
||||
res_(width_px, height_px),
|
||||
pxdim_(width_mm/width_px, height_mm/height_px),
|
||||
exp_time_s_(exp_time),
|
||||
exp_time_first_s_(exp_time_first)
|
||||
m_res(width_px, height_px),
|
||||
m_pxdim(width_mm/width_px, height_mm/height_px),
|
||||
m_exp_time_s(exp_time),
|
||||
m_exp_time_first_s(exp_time_first)
|
||||
{
|
||||
}
|
||||
|
||||
FilePrinter(const FilePrinter& ) = delete;
|
||||
FilePrinter(FilePrinter&& m):
|
||||
layers_rst_(std::move(m.layers_rst_)),
|
||||
res_(m.res_),
|
||||
pxdim_(m.pxdim_) {}
|
||||
m_layers_rst(std::move(m.m_layers_rst)),
|
||||
m_res(m.m_res),
|
||||
m_pxdim(m.m_pxdim) {}
|
||||
|
||||
inline void layers(unsigned cnt) { if(cnt > 0) layers_rst_.resize(cnt); }
|
||||
inline unsigned layers() const { return unsigned(layers_rst_.size()); }
|
||||
inline void layers(unsigned cnt) { if(cnt > 0) m_layers_rst.resize(cnt); }
|
||||
inline unsigned layers() const { return unsigned(m_layers_rst.size()); }
|
||||
|
||||
void printConfig(const Print& printconf) { print_ = &printconf; }
|
||||
void print_config(const Print& printconf) { m_print = &printconf; }
|
||||
|
||||
inline void drawPolygon(const ExPolygon& p, unsigned lyr) {
|
||||
assert(lyr < layers_rst_.size());
|
||||
layers_rst_[lyr].first.draw(p);
|
||||
inline void draw_polygon(const ExPolygon& p, unsigned lyr) {
|
||||
assert(lyr < m_layers_rst.size());
|
||||
m_layers_rst[lyr].first.draw(p);
|
||||
}
|
||||
|
||||
inline void beginLayer(unsigned lyr) {
|
||||
if(layers_rst_.size() <= lyr) layers_rst_.resize(lyr+1);
|
||||
layers_rst_[lyr].first.reset(res_, pxdim_, ORIGIN);
|
||||
inline void begin_layer(unsigned lyr) {
|
||||
if(m_layers_rst.size() <= lyr) m_layers_rst.resize(lyr+1);
|
||||
m_layers_rst[lyr].first.reset(m_res, m_pxdim, ORIGIN);
|
||||
}
|
||||
|
||||
inline void beginLayer() {
|
||||
layers_rst_.emplace_back();
|
||||
layers_rst_.front().first.reset(res_, pxdim_, ORIGIN);
|
||||
inline void begin_layer() {
|
||||
m_layers_rst.emplace_back();
|
||||
m_layers_rst.front().first.reset(m_res, m_pxdim, ORIGIN);
|
||||
}
|
||||
|
||||
inline void finishLayer(unsigned lyr_id) {
|
||||
assert(lyr_id < layers_rst_.size());
|
||||
layers_rst_[lyr_id].first.save(layers_rst_[lyr_id].second,
|
||||
inline void finish_layer(unsigned lyr_id) {
|
||||
assert(lyr_id < m_layers_rst.size());
|
||||
m_layers_rst[lyr_id].first.save(m_layers_rst[lyr_id].second,
|
||||
Raster::Compression::PNG);
|
||||
layers_rst_[lyr_id].first.reset();
|
||||
m_layers_rst[lyr_id].first.reset();
|
||||
}
|
||||
|
||||
inline void finishLayer() {
|
||||
if(!layers_rst_.empty()) {
|
||||
layers_rst_.back().first.save(layers_rst_.back().second,
|
||||
inline void finish_layer() {
|
||||
if(!m_layers_rst.empty()) {
|
||||
m_layers_rst.back().first.save(m_layers_rst.back().second,
|
||||
Raster::Compression::PNG);
|
||||
layers_rst_.back().first.reset();
|
||||
m_layers_rst.back().first.reset();
|
||||
}
|
||||
}
|
||||
|
||||
inline void save(const std::string& path) {
|
||||
try {
|
||||
Zipper<LyrFormat> zipper(path);
|
||||
LayerWriter<LyrFormat> writer(path);
|
||||
|
||||
std::string project = zipper.get_name();
|
||||
std::string project = writer.get_name();
|
||||
|
||||
zipper.next_entry(project);
|
||||
zipper << createIniContent(project);
|
||||
writer.next_entry("config.ini");
|
||||
writer << createIniContent(project);
|
||||
|
||||
for(unsigned i = 0; i < layers_rst_.size(); i++) {
|
||||
if(layers_rst_[i].second.rdbuf()->in_avail() > 0) {
|
||||
for(unsigned i = 0; i < m_layers_rst.size(); i++) {
|
||||
if(m_layers_rst[i].second.rdbuf()->in_avail() > 0) {
|
||||
char lyrnum[6];
|
||||
std::sprintf(lyrnum, "%.5d", i);
|
||||
auto zfilename = project + lyrnum + ".png";
|
||||
zipper.next_entry(zfilename);
|
||||
zipper << layers_rst_[i].second.rdbuf();
|
||||
layers_rst_[i].second.str("");
|
||||
writer.next_entry(zfilename);
|
||||
writer << m_layers_rst[i].second.rdbuf();
|
||||
m_layers_rst[i].second.str("");
|
||||
}
|
||||
}
|
||||
|
||||
zipper.close();
|
||||
} catch(std::exception&) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Can't create zip file for layers! "
|
||||
<< path;
|
||||
writer.close();
|
||||
} catch(std::exception& e) {
|
||||
BOOST_LOG_TRIVIAL(error) << e.what();
|
||||
return;
|
||||
}
|
||||
|
||||
// wxFileName filepath(path);
|
||||
|
||||
// wxFFileOutputStream zipfile(path);
|
||||
|
||||
// std::string project = filepath.GetName().ToStdString();
|
||||
|
||||
// if(!zipfile.IsOk()) {
|
||||
// BOOST_LOG_TRIVIAL(error) << "Can't create zip file for layers! "
|
||||
// << path;
|
||||
// return;
|
||||
// }
|
||||
|
||||
// wxZipOutputStream zipstream(zipfile);
|
||||
// wxStdOutputStream pngstream(zipstream);
|
||||
|
||||
// zipstream.PutNextEntry("config.ini");
|
||||
// pngstream << createIniContent(project);
|
||||
|
||||
// for(unsigned i = 0; i < layers_rst_.size(); i++) {
|
||||
// if(layers_rst_[i].second.rdbuf()->in_avail() > 0) {
|
||||
// char lyrnum[6];
|
||||
// std::sprintf(lyrnum, "%.5d", i);
|
||||
// auto zfilename = project + lyrnum + ".png";
|
||||
// zipstream.PutNextEntry(zfilename);
|
||||
// pngstream << layers_rst_[i].second.rdbuf();
|
||||
// layers_rst_[i].second.str("");
|
||||
// }
|
||||
// }
|
||||
|
||||
// zipstream.Close();
|
||||
// zipfile.Close();
|
||||
}
|
||||
|
||||
void saveLayer(unsigned lyr, const std::string& path) {
|
||||
void save_layer(unsigned lyr, const std::string& path) {
|
||||
unsigned i = lyr;
|
||||
assert(i < layers_rst_.size());
|
||||
assert(i < m_layers_rst.size());
|
||||
|
||||
char lyrnum[6];
|
||||
std::sprintf(lyrnum, "%.5d", lyr);
|
||||
|
@ -271,19 +240,19 @@ public:
|
|||
|
||||
std::fstream out(loc, std::fstream::out | std::fstream::binary);
|
||||
if(out.good()) {
|
||||
layers_rst_[i].first.save(out, Raster::Compression::PNG);
|
||||
m_layers_rst[i].first.save(out, Raster::Compression::PNG);
|
||||
} else {
|
||||
BOOST_LOG_TRIVIAL(error) << "Can't create file for layer";
|
||||
}
|
||||
|
||||
out.close();
|
||||
layers_rst_[i].first.reset();
|
||||
m_layers_rst[i].first.reset();
|
||||
}
|
||||
};
|
||||
|
||||
// Let's shadow this eigen interface
|
||||
inline coord_t px(const Point& p) { return p(0); }
|
||||
inline coord_t py(const Point& p) { return p(1); }
|
||||
inline coord_t px(const Point& p) { return p(0); }
|
||||
inline coord_t py(const Point& p) { return p(1); }
|
||||
inline coordf_t px(const Vec2d& p) { return p(0); }
|
||||
inline coordf_t py(const Vec2d& p) { return p(1); }
|
||||
|
||||
|
@ -337,7 +306,7 @@ void print_to(Print& print,
|
|||
FilePrinter<format, LayerFormat> printer(width_mm, height_mm,
|
||||
std::forward<Args>(args)...);
|
||||
|
||||
printer.printConfig(print);
|
||||
printer.print_config(print);
|
||||
|
||||
printer.layers(layers.size()); // Allocate space for all the layers
|
||||
|
||||
|
@ -358,7 +327,7 @@ void print_to(Print& print,
|
|||
{
|
||||
LayerPtrs lrange = layers[keys[layer_id]];
|
||||
|
||||
printer.beginLayer(layer_id); // Switch to the appropriate layer
|
||||
printer.begin_layer(layer_id); // Switch to the appropriate layer
|
||||
|
||||
for(Layer *lp : lrange) {
|
||||
Layer& l = *lp;
|
||||
|
@ -379,7 +348,7 @@ void print_to(Print& print,
|
|||
slice.translate(-px(print_bb.min) + cx,
|
||||
-py(print_bb.min) + cy);
|
||||
|
||||
printer.drawPolygon(slice, layer_id);
|
||||
printer.draw_polygon(slice, layer_id);
|
||||
}
|
||||
|
||||
/*if(print.has_support_material() && layer_id > 0) {
|
||||
|
@ -392,7 +361,7 @@ void print_to(Print& print,
|
|||
|
||||
}
|
||||
|
||||
printer.finishLayer(layer_id); // Finish the layer for later saving it.
|
||||
printer.finish_layer(layer_id); // Finish the layer for later saving it.
|
||||
|
||||
auto st = static_cast<int>(layer_id*80.0/layers.size());
|
||||
m.lock();
|
||||
|
|
|
@ -37,37 +37,37 @@ public:
|
|||
using Origin = Raster::Origin;
|
||||
|
||||
private:
|
||||
Raster::Resolution resolution_;
|
||||
Raster::PixelDim pxdim_;
|
||||
TBuffer buf_;
|
||||
TRawBuffer rbuf_;
|
||||
TPixelRenderer pixfmt_;
|
||||
TRawRenderer raw_renderer_;
|
||||
TRendererAA renderer_;
|
||||
Origin o_;
|
||||
std::function<void(agg::path_storage&)> flipy_ = [](agg::path_storage&) {};
|
||||
Raster::Resolution m_resolution;
|
||||
Raster::PixelDim m_pxdim;
|
||||
TBuffer m_buf;
|
||||
TRawBuffer m_rbuf;
|
||||
TPixelRenderer m_pixfmt;
|
||||
TRawRenderer m_raw_renderer;
|
||||
TRendererAA m_renderer;
|
||||
Origin m_o;
|
||||
std::function<void(agg::path_storage&)> m_flipy = [](agg::path_storage&) {};
|
||||
public:
|
||||
inline Impl(const Raster::Resolution& res, const Raster::PixelDim &pd,
|
||||
Origin o):
|
||||
resolution_(res), pxdim_(pd),
|
||||
buf_(res.pixels()),
|
||||
rbuf_(reinterpret_cast<TPixelRenderer::value_type*>(buf_.data()),
|
||||
m_resolution(res), m_pxdim(pd),
|
||||
m_buf(res.pixels()),
|
||||
m_rbuf(reinterpret_cast<TPixelRenderer::value_type*>(m_buf.data()),
|
||||
res.width_px, res.height_px,
|
||||
res.width_px*TPixelRenderer::num_components),
|
||||
pixfmt_(rbuf_),
|
||||
raw_renderer_(pixfmt_),
|
||||
renderer_(raw_renderer_),
|
||||
o_(o)
|
||||
m_pixfmt(m_rbuf),
|
||||
m_raw_renderer(m_pixfmt),
|
||||
m_renderer(m_raw_renderer),
|
||||
m_o(o)
|
||||
{
|
||||
renderer_.color(ColorWhite);
|
||||
m_renderer.color(ColorWhite);
|
||||
|
||||
// If we would like to play around with gamma
|
||||
// ras.gamma(agg::gamma_power(1.0));
|
||||
|
||||
clear();
|
||||
|
||||
if(o_ == Origin::TOP_LEFT) flipy_ = [this](agg::path_storage& path) {
|
||||
path.flip_y(0, resolution_.height_px);
|
||||
if(m_o == Origin::TOP_LEFT) m_flipy = [this](agg::path_storage& path) {
|
||||
path.flip_y(0, m_resolution.height_px);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -76,35 +76,35 @@ public:
|
|||
agg::scanline_p8 scanlines;
|
||||
|
||||
auto&& path = to_path(poly.contour);
|
||||
flipy_(path);
|
||||
m_flipy(path);
|
||||
ras.add_path(path);
|
||||
|
||||
for(auto h : poly.holes) {
|
||||
auto&& holepath = to_path(h);
|
||||
flipy_(holepath);
|
||||
m_flipy(holepath);
|
||||
ras.add_path(holepath);
|
||||
}
|
||||
|
||||
agg::render_scanlines(ras, scanlines, renderer_);
|
||||
agg::render_scanlines(ras, scanlines, m_renderer);
|
||||
}
|
||||
|
||||
inline void clear() {
|
||||
raw_renderer_.clear(ColorBlack);
|
||||
m_raw_renderer.clear(ColorBlack);
|
||||
}
|
||||
|
||||
inline TBuffer& buffer() { return buf_; }
|
||||
inline TBuffer& buffer() { return m_buf; }
|
||||
|
||||
inline const Raster::Resolution resolution() { return resolution_; }
|
||||
inline const Raster::Resolution resolution() { return m_resolution; }
|
||||
|
||||
inline Origin origin() const /*noexcept*/ { return o_; }
|
||||
inline Origin origin() const /*noexcept*/ { return m_o; }
|
||||
|
||||
private:
|
||||
double getPx(const Point& p) {
|
||||
return p(0) * SCALING_FACTOR/pxdim_.w_mm;
|
||||
return p(0) * SCALING_FACTOR/m_pxdim.w_mm;
|
||||
}
|
||||
|
||||
double getPy(const Point& p) {
|
||||
return p(1) * SCALING_FACTOR/pxdim_.h_mm;
|
||||
return p(1) * SCALING_FACTOR/m_pxdim.h_mm;
|
||||
}
|
||||
|
||||
agg::path_storage to_path(const Polygon& poly) {
|
||||
|
@ -124,57 +124,57 @@ const Raster::Impl::TPixel Raster::Impl::ColorWhite = Raster::Impl::TPixel(255);
|
|||
const Raster::Impl::TPixel Raster::Impl::ColorBlack = Raster::Impl::TPixel(0);
|
||||
|
||||
Raster::Raster(const Resolution &r, const PixelDim &pd, Origin o):
|
||||
impl_(new Impl(r, pd, o)) {}
|
||||
m_impl(new Impl(r, pd, o)) {}
|
||||
|
||||
Raster::Raster() {}
|
||||
|
||||
Raster::~Raster() {}
|
||||
|
||||
Raster::Raster(Raster &&m):
|
||||
impl_(std::move(m.impl_)) {}
|
||||
m_impl(std::move(m.m_impl)) {}
|
||||
|
||||
void Raster::reset(const Raster::Resolution &r, const Raster::PixelDim &pd)
|
||||
{
|
||||
// Free up the unnecessary memory and make sure it stays clear after
|
||||
// an exception
|
||||
auto o = impl_? impl_->origin() : Origin::TOP_LEFT;
|
||||
auto o = m_impl? m_impl->origin() : Origin::TOP_LEFT;
|
||||
reset(r, pd, o);
|
||||
}
|
||||
|
||||
void Raster::reset(const Raster::Resolution &r, const Raster::PixelDim &pd,
|
||||
Raster::Origin o)
|
||||
{
|
||||
impl_.reset();
|
||||
impl_.reset(new Impl(r, pd, o));
|
||||
m_impl.reset();
|
||||
m_impl.reset(new Impl(r, pd, o));
|
||||
}
|
||||
|
||||
void Raster::reset()
|
||||
{
|
||||
impl_.reset();
|
||||
m_impl.reset();
|
||||
}
|
||||
|
||||
Raster::Resolution Raster::resolution() const
|
||||
{
|
||||
if(impl_) return impl_->resolution();
|
||||
if(m_impl) return m_impl->resolution();
|
||||
|
||||
return Resolution(0, 0);
|
||||
}
|
||||
|
||||
void Raster::clear()
|
||||
{
|
||||
assert(impl_);
|
||||
impl_->clear();
|
||||
assert(m_impl);
|
||||
m_impl->clear();
|
||||
}
|
||||
|
||||
void Raster::draw(const ExPolygon &poly)
|
||||
{
|
||||
assert(impl_);
|
||||
impl_->draw(poly);
|
||||
assert(m_impl);
|
||||
m_impl->draw(poly);
|
||||
}
|
||||
|
||||
void Raster::save(std::ostream& stream, Compression comp)
|
||||
{
|
||||
assert(impl_);
|
||||
assert(m_impl);
|
||||
switch(comp) {
|
||||
case Compression::PNG: {
|
||||
|
||||
|
@ -188,7 +188,7 @@ void Raster::save(std::ostream& stream, Compression comp)
|
|||
|
||||
wr.write_info();
|
||||
|
||||
auto& b = impl_->buffer();
|
||||
auto& b = m_impl->buffer();
|
||||
auto ptr = reinterpret_cast<png::byte*>( b.data() );
|
||||
unsigned stride =
|
||||
sizeof(Impl::TBuffer::value_type) * resolution().width_px;
|
||||
|
@ -201,12 +201,12 @@ void Raster::save(std::ostream& stream, Compression comp)
|
|||
}
|
||||
case Compression::RAW: {
|
||||
stream << "P5 "
|
||||
<< impl_->resolution().width_px << " "
|
||||
<< impl_->resolution().height_px << " "
|
||||
<< m_impl->resolution().width_px << " "
|
||||
<< m_impl->resolution().height_px << " "
|
||||
<< "255 ";
|
||||
|
||||
stream.write(reinterpret_cast<const char*>(impl_->buffer().data()),
|
||||
impl_->buffer().size()*sizeof(Impl::TBuffer::value_type));
|
||||
stream.write(reinterpret_cast<const char*>(m_impl->buffer().data()),
|
||||
m_impl->buffer().size()*sizeof(Impl::TBuffer::value_type));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ class ExPolygon;
|
|||
*/
|
||||
class Raster {
|
||||
class Impl;
|
||||
std::unique_ptr<Impl> impl_;
|
||||
std::unique_ptr<Impl> m_impl;
|
||||
public:
|
||||
|
||||
/// Supported compression types
|
||||
|
@ -65,7 +65,7 @@ public:
|
|||
|
||||
/**
|
||||
* Release the allocated resources. Drawing in this state ends in
|
||||
* unspecified behaviour.
|
||||
* unspecified behavior.
|
||||
*/
|
||||
void reset();
|
||||
|
||||
|
|
|
@ -6,6 +6,10 @@
|
|||
|
||||
// Add z coordinate to model instances' offset
|
||||
#define ENABLE_MODELINSTANCE_3D_OFFSET (1 && ENABLE_1_42_0)
|
||||
// Add double click on gizmo grabbers to reset transformation components to their default value
|
||||
#define ENABLE_GIZMOS_RESET (1 && ENABLE_1_42_0)
|
||||
// Add x and y rotation components to model instances' offset
|
||||
#define ENABLE_MODELINSTANCE_3D_ROTATION (1 && ENABLE_MODELINSTANCE_3D_OFFSET)
|
||||
|
||||
#endif // _technologies_h_
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue