2014-08-03 17:42:29 +00:00
|
|
|
#ifndef _libslic3r_h_
|
|
|
|
#define _libslic3r_h_
|
|
|
|
|
|
|
|
// this needs to be included early for MSVC (listing it in Build.PL is not enough)
|
|
|
|
#include <ostream>
|
|
|
|
#include <iostream>
|
2016-11-27 14:25:22 +00:00
|
|
|
#include <math.h>
|
2016-11-26 15:07:36 +00:00
|
|
|
#include <queue>
|
2014-08-03 17:42:29 +00:00
|
|
|
#include <sstream>
|
2016-10-20 16:34:33 +00:00
|
|
|
#include <cstdio>
|
2016-10-20 16:38:44 +00:00
|
|
|
#include <stdint.h>
|
2016-10-20 15:44:46 +00:00
|
|
|
#include <stdarg.h>
|
2016-11-26 15:07:36 +00:00
|
|
|
#include <vector>
|
2017-02-15 10:03:19 +00:00
|
|
|
#include <iterator>
|
|
|
|
#include <utility>
|
2016-11-26 15:07:36 +00:00
|
|
|
#include <boost/thread.hpp>
|
2014-08-03 17:42:29 +00:00
|
|
|
|
2016-10-21 14:53:42 +00:00
|
|
|
#define SLIC3R_FORK_NAME "Slic3r Prusa Edition"
|
2016-11-20 22:06:56 +00:00
|
|
|
#define SLIC3R_VERSION "1.31.6"
|
2014-11-09 19:41:27 +00:00
|
|
|
|
2016-09-13 11:30:00 +00:00
|
|
|
//FIXME This epsilon value is used for many non-related purposes:
|
|
|
|
// For a threshold of a squared Euclidean distance,
|
|
|
|
// for a trheshold in a difference of radians,
|
|
|
|
// for a threshold of a cross product of two non-normalized vectors etc.
|
2014-08-03 17:42:29 +00:00
|
|
|
#define EPSILON 1e-4
|
2016-09-13 11:30:00 +00:00
|
|
|
// Scaling factor for a conversion from coord_t to coordf_t: 10e-6
|
|
|
|
// This scaling generates a following fixed point representation with for a 32bit integer:
|
|
|
|
// 0..4294mm with 1nm resolution
|
2016-10-18 14:44:05 +00:00
|
|
|
// int32_t fits an interval of (-2147.48mm, +2147.48mm)
|
2014-08-03 17:42:29 +00:00
|
|
|
#define SCALING_FACTOR 0.000001
|
2016-09-13 11:30:00 +00:00
|
|
|
// RESOLUTION, SCALED_RESOLUTION: Used as an error threshold for a Douglas-Peucker polyline simplification algorithm.
|
2015-07-02 16:57:40 +00:00
|
|
|
#define RESOLUTION 0.0125
|
|
|
|
#define SCALED_RESOLUTION (RESOLUTION / SCALING_FACTOR)
|
2014-08-03 17:42:29 +00:00
|
|
|
#define PI 3.141592653589793238
|
2016-09-13 11:30:00 +00:00
|
|
|
// When extruding a closed loop, the loop is interrupted and shortened a bit to reduce the seam.
|
2015-07-02 18:24:16 +00:00
|
|
|
#define LOOP_CLIPPING_LENGTH_OVER_NOZZLE_DIAMETER 0.15
|
2016-09-13 11:30:00 +00:00
|
|
|
// Maximum perimeter length for the loop to apply the small perimeter speed.
|
2015-07-02 18:24:16 +00:00
|
|
|
#define SMALL_PERIMETER_LENGTH (6.5 / SCALING_FACTOR) * 2 * PI
|
2015-07-03 20:58:29 +00:00
|
|
|
#define INSET_OVERLAP_TOLERANCE 0.4
|
2016-09-26 10:42:44 +00:00
|
|
|
// 3mm ring around the top / bottom / bridging areas.
|
|
|
|
//FIXME This is quite a lot.
|
|
|
|
#define EXTERNAL_INFILL_MARGIN 3.
|
2015-12-19 13:49:29 +00:00
|
|
|
#define scale_(val) ((val) / SCALING_FACTOR)
|
|
|
|
#define unscale(val) ((val) * SCALING_FACTOR)
|
2014-08-03 17:42:29 +00:00
|
|
|
#define SCALED_EPSILON scale_(EPSILON)
|
|
|
|
typedef long coord_t;
|
|
|
|
typedef double coordf_t;
|
|
|
|
|
|
|
|
/* Implementation of CONFESS("foo"): */
|
2016-08-21 19:46:17 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define CONFESS(...) confess_at(__FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define CONFESS(...) confess_at(__FILE__, __LINE__, __func__, __VA_ARGS__)
|
|
|
|
#endif
|
2014-08-03 17:42:29 +00:00
|
|
|
void confess_at(const char *file, int line, const char *func, const char *pat, ...);
|
|
|
|
/* End implementation of CONFESS("foo"): */
|
|
|
|
|
2016-04-10 17:07:34 +00:00
|
|
|
// Which C++ version is supported?
|
|
|
|
// For example, could optimized functions with move semantics be used?
|
|
|
|
#if __cplusplus==201402L
|
|
|
|
#define SLIC3R_CPPVER 14
|
2016-11-07 21:49:11 +00:00
|
|
|
#define STDMOVE(WHAT) std::move(WHAT)
|
2016-04-10 17:07:34 +00:00
|
|
|
#elif __cplusplus==201103L
|
|
|
|
#define SLIC3R_CPPVER 11
|
2016-11-07 21:49:11 +00:00
|
|
|
#define STDMOVE(WHAT) std::move(WHAT)
|
2016-04-10 17:07:34 +00:00
|
|
|
#else
|
|
|
|
#define SLIC3R_CPPVER 0
|
2016-11-07 21:49:11 +00:00
|
|
|
#define STDMOVE(WHAT) (WHAT)
|
2016-04-10 17:07:34 +00:00
|
|
|
#endif
|
|
|
|
|
2016-10-21 08:18:01 +00:00
|
|
|
#define SLIC3R_DEBUG_OUT_PATH_PREFIX "out/"
|
2016-10-20 15:44:46 +00:00
|
|
|
|
|
|
|
inline std::string debug_out_path(const char *name, ...)
|
|
|
|
{
|
|
|
|
char buffer[2048];
|
|
|
|
va_list args;
|
|
|
|
va_start(args, name);
|
2016-10-20 16:34:33 +00:00
|
|
|
std::vsprintf(buffer, name, args);
|
2016-10-20 15:44:46 +00:00
|
|
|
va_end(args);
|
2016-10-21 08:18:01 +00:00
|
|
|
return std::string(SLIC3R_DEBUG_OUT_PATH_PREFIX) + std::string(buffer);
|
2016-10-20 15:44:46 +00:00
|
|
|
}
|
|
|
|
|
2016-11-02 09:47:00 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
// Visual Studio older than 2015 does not support the prinf type specifier %zu. Use %Iu instead.
|
|
|
|
#define PRINTF_ZU "%Iu"
|
|
|
|
#else
|
|
|
|
#define PRINTF_ZU "%zu"
|
|
|
|
#endif
|
|
|
|
|
2016-09-26 11:56:24 +00:00
|
|
|
// Write slices as SVG images into out directory during the 2D processing of the slices.
|
2016-09-30 13:23:18 +00:00
|
|
|
// #define SLIC3R_DEBUG_SLICE_PROCESSING
|
2016-09-26 11:56:24 +00:00
|
|
|
|
2016-11-26 15:07:36 +00:00
|
|
|
namespace Slic3r {
|
|
|
|
|
|
|
|
enum Axis { X=0, Y, Z };
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
inline void append_to(std::vector<T> &dst, const std::vector<T> &src)
|
|
|
|
{
|
|
|
|
dst.insert(dst.end(), src.begin(), src.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T> void
|
|
|
|
_parallelize_do(std::queue<T>* queue, boost::mutex* queue_mutex, boost::function<void(T)> func)
|
|
|
|
{
|
|
|
|
//std::cout << "THREAD STARTED: " << boost::this_thread::get_id() << std::endl;
|
|
|
|
while (true) {
|
|
|
|
T i;
|
|
|
|
{
|
|
|
|
boost::lock_guard<boost::mutex> l(*queue_mutex);
|
|
|
|
if (queue->empty()) return;
|
|
|
|
i = queue->front();
|
|
|
|
queue->pop();
|
|
|
|
}
|
|
|
|
//std::cout << " Thread " << boost::this_thread::get_id() << " processing item " << i << std::endl;
|
|
|
|
func(i);
|
|
|
|
boost::this_thread::interruption_point();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T> void
|
|
|
|
parallelize(std::queue<T> queue, boost::function<void(T)> func,
|
|
|
|
int threads_count = boost::thread::hardware_concurrency())
|
|
|
|
{
|
2016-11-27 14:25:22 +00:00
|
|
|
if (threads_count == 0) threads_count = 2;
|
2016-11-26 15:07:36 +00:00
|
|
|
boost::mutex queue_mutex;
|
|
|
|
boost::thread_group workers;
|
2016-12-20 11:19:13 +00:00
|
|
|
for (int i = 0; i < std::min(threads_count, int(queue.size())); ++ i)
|
2016-11-26 15:07:36 +00:00
|
|
|
workers.add_thread(new boost::thread(&_parallelize_do<T>, &queue, &queue_mutex, func));
|
|
|
|
workers.join_all();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T> void
|
|
|
|
parallelize(T start, T end, boost::function<void(T)> func,
|
|
|
|
int threads_count = boost::thread::hardware_concurrency())
|
|
|
|
{
|
|
|
|
std::queue<T> queue;
|
|
|
|
for (T i = start; i <= end; ++i) queue.push(i);
|
|
|
|
parallelize(queue, func, threads_count);
|
|
|
|
}
|
|
|
|
|
2017-02-15 10:03:19 +00:00
|
|
|
template <typename T>
|
|
|
|
void append(std::vector<T>& dest, const std::vector<T>& src)
|
|
|
|
{
|
|
|
|
if (dest.empty())
|
|
|
|
dest = src;
|
|
|
|
else
|
|
|
|
dest.insert(std::end(dest), std::cbegin(src), std::cend(src));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void append(std::vector<T>& dest, std::vector<T>&& src)
|
|
|
|
{
|
|
|
|
if (dest.empty())
|
|
|
|
dest = std::move(src);
|
|
|
|
else
|
|
|
|
dest.insert(std::end(dest),
|
|
|
|
std::make_move_iterator(std::begin(src)),
|
|
|
|
std::make_move_iterator(std::end(src)));
|
|
|
|
src.clear();
|
|
|
|
src.shrink_to_fit();
|
|
|
|
}
|
|
|
|
|
2016-11-26 15:07:36 +00:00
|
|
|
} // namespace Slic3r
|
|
|
|
|
2014-08-03 17:42:29 +00:00
|
|
|
#endif
|