OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
libvgcode Namespace Reference

|/ Copyright (c) Prusa Research 2023 Enrico Turri @enricoturri1966, Pavel Mikuš @Godrak |/ |/ libvgcode is released under the terms of the AGPLv3 or higher |/ More...

Classes

struct  ColorPrint
class  ColorRange
struct  GCodeInputData
struct  PathVertex
class  Viewer
struct  BitSet
class  ExtrusionRoles
class  Layers
class  OpenGLWrapper
class  OptionTemplate
class  Range
class  SegmentTemplate
struct  Settings
class  ViewerImpl
class  ViewRange
struct  VerticesData
class  WipeTowerHelper
class  ObjectHelper

Typedefs

using Vec3 = std::array<float, 3>
using Vec4 = std::array<float, 4>
using Mat4x4 = std::array<float, 16>
using Color = std::array<uint8_t, 3>
using Palette = std::vector<Color>
using ColorWithAlpha = std::array<uint8_t, 4>
using PaletteWithAlpha = std::vector<ColorWithAlpha>
using AABox = std::array<Vec3, 2>
using Interval = std::array<std::size_t, 2>
template<class T, class O = T>
using IntegerOnly = std::enable_if_t<std::is_integral<T>::value, O>

Enumerations

enum class  EViewType : uint8_t {
  Summary , FeatureType , ColorPrint , Speed ,
  ActualSpeed , Height , Width , VolumetricFlowRate ,
  ActualVolumetricFlowRate , LayerTimeLinear , LayerTimeLogarithmic , FanSpeed ,
  Temperature , PressureAdvance , Acceleration , Jerk ,
  Tool , COUNT
}
enum class  EMoveType : uint8_t {
  Noop , Retract , Unretract , Seam ,
  ToolChange , ColorChange , PausePrint , CustomGCode ,
  Travel , Wipe , Extrude , COUNT
}
enum class  EGCodeExtrusionRole : uint8_t {
  None , Perimeter , ExternalPerimeter , OverhangPerimeter ,
  InternalInfill , SolidInfill , TopSolidInfill , Ironing ,
  BridgeInfill , GapFill , Skirt , SupportMaterial ,
  SupportMaterialInterface , WipeTower , Custom , BottomSurface ,
  InternalBridgeInfill , Brim , SupportTransition , Mixed ,
  COUNT
}
enum class  EOptionType : uint8_t {
  Travels , Wipes , Retractions , Unretractions ,
  Seams , ToolChanges , ColorChanges , PausePrints ,
  CustomGCodes , COUNT
}
enum class  ETimeMode : uint8_t { Normal , Stealth , COUNT }
enum class  EColorRangeType : uint8_t { Linear , Logarithmic , COUNT }

Functions

EOptionType move_type_to_option (EMoveType type)
Color lerp (const Color &c1, const Color &c2, float t)
static float get_step_size (const ColorRange &color_range)
static bool is_colorprint_option (const PathVertex &v)
void glAssertRecentCallImpl (const char *file_name, unsigned int line, const char *function_name)
void glAssertRecentCall ()
static uint8_t lerp (uint8_t f1, uint8_t f2, float t)
void add_vertex (const Vec3 &position, const Vec3 &normal, std::vector< float > &vertices)
void add_triangle (uint16_t v1, uint16_t v2, uint16_t v3, std::vector< uint16_t > &indices)
Vec3 normalize (const Vec3 &v)
float dot (const Vec3 &v1, const Vec3 &v2)
float length (const Vec3 &v)
bool operator== (const Vec3 &v1, const Vec3 &v2)
bool operator!= (const Vec3 &v1, const Vec3 &v2)
Vec3 operator+ (const Vec3 &v1, const Vec3 &v2)
Vec3 operator- (const Vec3 &v1, const Vec3 &v2)
Vec3 operator* (float f, const Vec3 &v)
template<typename I>
IntegerOnly< I, I > fast_round_up (double a)
static float round_to_bin (const float value)
static Mat4x4 inverse (const Mat4x4 &m)
std::string check_shader (GLuint handle)
std::string check_program (GLuint handle)
unsigned int init_shader (const std::string &shader_name, const char *vertex_shader, const char *fragment_shader, const std::vector< const char * > &fragment_outputs={})
static void delete_textures (unsigned int &id)
static void delete_buffers (unsigned int &id)
static std::string with_define (const char *source, const char *define)
static bool is_line (const std::vector< PathVertex > &vertices, size_t i)
static bool is_joint (const std::vector< PathVertex > &vertices, size_t i)
static void extract_pos_and_or_hwa (const std::vector< PathVertex > &vertices, float travels_radius, float wipes_radius, BitSet<> &valid_lines_bitset, std::vector< Vec4 > *positions=nullptr, std::vector< Vec4 > *heights_widths_angles=nullptr, bool update_bitset=false)
static bool is_visible (const PathVertex &v, const Settings &settings)
Vec3 convert (const Slic3r::Vec3f &v)
Slic3r::Vec3f convert (const Vec3 &v)
Mat4x4 convert (const Slic3r::Matrix4f &m)
Slic3r::ColorRGBA convert (const Color &c)
Color convert (const Slic3r::ColorRGBA &c)
Slic3r::ColorRGBA convert (const ColorWithAlpha &c)
PaletteWithAlpha convert_filament_colors (const std::vector< std::string > &colors_str)
Slic3r::ExtrusionRole convert (EGCodeExtrusionRole role)
EGCodeExtrusionRole convert (Slic3r::ExtrusionRole role)
EMoveType convert (Slic3r::EMoveType type)
ETimeMode convert (const Slic3r::PrintEstimatedStatistics::ETimeMode &mode)
Slic3r::PrintEstimatedStatistics::ETimeMode convert (const ETimeMode &mode)
static bool starts_path (const Slic3r::GCodeProcessorResult::MoveVertex &prev, const Slic3r::GCodeProcessorResult::MoveVertex &curr, bool first_move)
GCodeInputData convert (const Slic3r::GCodeProcessorResult &result, const std::vector< std::string > &str_tool_colors, const std::vector< std::string > &str_color_print_colors, const Viewer &viewer, const Slic3r::Transform3d *belt_xform)
static void convert_lines_to_vertices (const Slic3r::Lines &lines, const std::vector< float > &widths, const std::vector< float > &heights, float top_z, size_t layer_id, size_t extruder_id, size_t color_id, EGCodeExtrusionRole extrusion_role, bool closed, std::vector< PathVertex > &vertices)
static void convert_to_vertices (const Slic3r::ExtrusionPath &extrusion_path, float print_z, size_t layer_id, size_t extruder_id, size_t color_id, EGCodeExtrusionRole extrusion_role, const Slic3r::Point &shift, std::vector< PathVertex > &vertices)
static void convert_to_vertices (const Slic3r::ExtrusionMultiPath &extrusion_multi_path, float print_z, size_t layer_id, size_t extruder_id, size_t color_id, EGCodeExtrusionRole extrusion_role, const Slic3r::Point &shift, std::vector< PathVertex > &vertices)
static void convert_to_vertices (const Slic3r::ExtrusionLoop &extrusion_loop, float print_z, size_t layer_id, size_t extruder_id, size_t color_id, EGCodeExtrusionRole extrusion_role, const Slic3r::Point &shift, std::vector< PathVertex > &vertices)
static void convert_to_vertices (const Slic3r::ExtrusionEntityCollection &extrusion_entity_collection, float print_z, size_t layer_id, size_t extruder_id, size_t color_id, EGCodeExtrusionRole extrusion_role, const Slic3r::Point &shift, std::vector< PathVertex > &vertices)
static void convert_to_vertices (const Slic3r::ExtrusionEntity &extrusion_entity, float print_z, size_t layer_id, size_t extruder_id, size_t color_id, EGCodeExtrusionRole extrusion_role, const Slic3r::Point &shift, std::vector< PathVertex > &vertices)
static void convert_brim_skirt_to_vertices (const Slic3r::Print &print, std::vector< VerticesData > &vertices_data)
static void convert_wipe_tower_to_vertices (const Slic3r::Print &print, const std::vector< std::string > &str_tool_colors, std::vector< VerticesData > &vertices_data)
static void convert_object_to_vertices (const Slic3r::PrintObject &object, const std::vector< std::string > &str_tool_colors, const std::vector< std::string > &str_color_print_colors, const std::vector< Slic3r::CustomGCode::Item > &color_print_values, size_t extruders_count, VerticesData &data)
static void convert_objects_to_vertices (const Slic3r::ConstPrintObjectPtrsAdaptor &objects, const std::vector< std::string > &str_tool_colors, const std::vector< std::string > &str_color_print_colors, const std::vector< Slic3r::CustomGCode::Item > &color_print_values, size_t extruders_count, std::vector< VerticesData > &data)
GCodeInputData convert (const Slic3r::Print &print, const std::vector< std::string > &str_tool_colors, const std::vector< std::string > &str_color_print_colors, const std::vector< Slic3r::CustomGCode::Item > &color_print_values, size_t extruders_count)

Variables

static const Palette DEFAULT_RANGES_COLORS
static constexpr float PI = 3.141592f
static constexpr float DEFAULT_TRAVELS_RADIUS_MM = 0.1f
static constexpr float MIN_TRAVELS_RADIUS_MM = 0.05f
static constexpr float MAX_TRAVELS_RADIUS_MM = 1.0f
static constexpr float DEFAULT_WIPES_RADIUS_MM = 0.1f
static constexpr float MIN_WIPES_RADIUS_MM = 0.05f
static constexpr float MAX_WIPES_RADIUS_MM = 1.0f
static constexpr std::size_t VIEW_TYPES_COUNT = static_cast<std::size_t>(EViewType::COUNT)
static constexpr std::size_t MOVE_TYPES_COUNT = static_cast<std::size_t>(EMoveType::COUNT)
static constexpr std::size_t GCODE_EXTRUSION_ROLES_COUNT = static_cast<std::size_t>(EGCodeExtrusionRole::COUNT)
static constexpr std::size_t OPTION_TYPES_COUNT = static_cast<std::size_t>(EOptionType::COUNT)
static constexpr std::size_t TIME_MODES_COUNT = static_cast<std::size_t>(ETimeMode::COUNT)
static constexpr std::size_t COLOR_RANGE_TYPES_COUNT = static_cast<std::size_t>(EColorRangeType::COUNT)
static const Color DUMMY_COLOR { 64, 64, 64 }
template<typename T>
auto constexpr is_atomic = false
template<typename T>
auto constexpr is_atomic< std::atomic< T > > = true
static const char * OPENGL_ES_PREFIXES [] = { "OpenGL ES-CM ", "OpenGL ES-CL ", "OpenGL ES ", nullptr }
static constexpr const std::array< uint32_t, 8 > VERTEX_DATA = { 0, 1, 2, 3, 4, 5, 6, 7 }
static constexpr const std::array< uint16_t, 24 > INDEX_DATA
static const char * Segments_Vertex_Shader
static const char * Segments_Shadow_Caster_Vertex_Shader
static const char * Segments_Shadow_Caster_Fragment_Shader
static const char * Segments_Fragment_Shader
static const char * Translucent_Composite_Vertex_Shader
static const char * Translucent_Composite_Fragment_Shader
static const char * Options_Vertex_Shader
static const char * Options_Fragment_Shader
static const char * Segments_Vertex_Shader_ES
static const char * Segments_Shadow_Caster_Vertex_Shader_ES
static const char * Segments_Shadow_Caster_Fragment_Shader_ES
static const char * Segments_Fragment_Shader_ES
static const char * Options_Vertex_Shader_ES
static const char * Options_Fragment_Shader_ES
static constexpr int TRANSLUCENT_TEXTURE_UNIT = 5
static const std::array< Color, size_t(EGCodeExtrusionRole::COUNT)> DEFAULT_EXTRUSION_ROLES_COLORS
static const std::array< Color, size_t(EOptionType::COUNT)> DEFAULT_OPTIONS_COLORS

Detailed Description

|/ Copyright (c) Prusa Research 2023 Enrico Turri @enricoturri1966, Pavel Mikuš @Godrak |/ |/ libvgcode is released under the terms of the AGPLv3 or higher |/

|/ Copyright (c) Prusa Research 2020 - 2023 Enrico Turri @enricoturri1966 |/ |/ PrusaSlicer is released under the terms of the AGPLv3 or higher |/

|/ Copyright (c) Prusa Research 2023 Enrico Turri @enricoturri1966, Pavel Mikuš @Godrak, Vojtěch Bubník @bubnikv, Oleksandra Iushchenko @YuSanka |/ |/ libvgcode is released under the terms of the AGPLv3 or higher |/

|/ Copyright (c) Prusa Research 2023 Enrico Turri @enricoturri1966, Pavel Mikuš @Godrak, Vojtěch Bubník @bubnikv |/ |/ libvgcode is released under the terms of the AGPLv3 or higher |/

|/ Copyright (c) Prusa Research 2023 Enrico Turri @enricoturri1966 |/ |/ libvgcode is released under the terms of the AGPLv3 or higher |/


Class Documentation

◆ libvgcode::ColorPrint

struct libvgcode::ColorPrint
Collaboration diagram for libvgcode::ColorPrint:
Class Members
uint8_t color_id { 0 }
uint8_t extruder_id { 0 }
uint32_t layer_id { 0 }
array< float, TIME_MODES_COUNT > times { 0.0f, 0.0f }

◆ libvgcode::GCodeInputData

struct libvgcode::GCodeInputData
Collaboration diagram for libvgcode::GCodeInputData:
Class Members
PaletteWithAlpha color_print_colors
bool spiral_vase_mode { false }
PaletteWithAlpha tools_colors
vector< PathVertex > vertices

◆ libvgcode::Settings

struct libvgcode::Settings
Collaboration diagram for libvgcode::Settings:
Class Members
bool dim_previous_layers { false }
float dim_previous_layers_brightness { 0.4f }
array< bool, size_t(COUNT)> extrusion_roles_visibility
array< bool, size_t(COUNT)> options_visibility
bool spiral_vase_mode { false }
ETimeMode time_mode { ETimeMode::Normal }
bool top_layer_only_view_range { false }
bool translucent_filaments { true }
bool update_colors { true }
bool update_enabled_entities { true }
bool update_view_full_range { true }
EViewType view_type { EViewType::FeatureType }

◆ libvgcode::VerticesData

struct libvgcode::VerticesData
Collaboration diagram for libvgcode::VerticesData:
Class Members
vector< float > layers_zs
vector< PathVertex > vertices

Typedef Documentation

◆ AABox

using libvgcode::AABox = std::array<Vec3, 2>

◆ Color

using libvgcode::Color = std::array<uint8_t, 3>

◆ ColorWithAlpha

using libvgcode::ColorWithAlpha = std::array<uint8_t, 4>

◆ IntegerOnly

template<class T, class O = T>
using libvgcode::IntegerOnly = std::enable_if_t<std::is_integral<T>::value, O>

◆ Interval

using libvgcode::Interval = std::array<std::size_t, 2>

◆ Mat4x4

using libvgcode::Mat4x4 = std::array<float, 16>

◆ Palette

using libvgcode::Palette = std::vector<Color>

◆ PaletteWithAlpha

◆ Vec3

using libvgcode::Vec3 = std::array<float, 3>

◆ Vec4

using libvgcode::Vec4 = std::array<float, 4>

Enumeration Type Documentation

◆ EColorRangeType

enum class libvgcode::EColorRangeType : uint8_t
strong
Enumerator
Linear 
Logarithmic 
COUNT 
212{
213 Linear,
215 COUNT
216};
@ Linear
Definition PrintConfig.hpp:304
@ Logarithmic
Definition Types.hpp:214
@ COUNT
Definition Types.hpp:112

◆ EGCodeExtrusionRole

enum class libvgcode::EGCodeExtrusionRole : uint8_t
strong
Enumerator
None 
Perimeter 
ExternalPerimeter 
OverhangPerimeter 
InternalInfill 
SolidInfill 
TopSolidInfill 
Ironing 
BridgeInfill 
GapFill 
Skirt 
SupportMaterial 
SupportMaterialInterface 
WipeTower 
Custom 
BottomSurface 
InternalBridgeInfill 
Brim 
SupportTransition 
Mixed 
COUNT 
142{
143 // This enum is used as in index into extrusion_roles_visibility.
144 // Better only add things to the end.
145 None,
146 Perimeter,
152 Ironing,
154 GapFill,
155 Skirt,
158 WipeTower,
159 Custom,
160 // ORCA
163 Brim,
165 Mixed,
166 COUNT
167};
@ Custom
Definition CustomGCode.hpp:23
@ None
Definition SketchEngine.hpp:180
@ SolidInfill
Definition Types.hpp:150
@ InternalInfill
Definition Types.hpp:149
@ ExternalPerimeter
Definition Types.hpp:147
@ Brim
Definition Types.hpp:163
@ SupportTransition
Definition Types.hpp:164
@ SupportMaterialInterface
Definition Types.hpp:157
@ InternalBridgeInfill
Definition Types.hpp:162
@ Mixed
Definition Types.hpp:165
@ GapFill
Definition Types.hpp:154
@ TopSolidInfill
Definition Types.hpp:151
@ Perimeter
Definition Types.hpp:146
@ OverhangPerimeter
Definition Types.hpp:148
@ BridgeInfill
Definition Types.hpp:153
@ WipeTower
Definition Types.hpp:158
@ Skirt
Definition Types.hpp:155
@ Ironing
Definition Types.hpp:152
@ BottomSurface
Definition Types.hpp:161
@ SupportMaterial
Definition Types.hpp:156

◆ EMoveType

enum class libvgcode::EMoveType : uint8_t
strong
Enumerator
Noop 
Retract 
Unretract 
Seam 
ToolChange 
ColorChange 
PausePrint 
CustomGCode 
Travel 
Wipe 
Extrude 
COUNT 
121{
122 Noop,
123 Retract,
124 Unretract,
125 Seam,
130 Travel,
131 Wipe,
132 Extrude,
133 COUNT
134};
@ PausePrint
Definition CustomGCode.hpp:20
@ ToolChange
Definition CustomGCode.hpp:21
@ ColorChange
Definition CustomGCode.hpp:19
@ Travel
Definition ExclusionVolumePathCheck.hpp:17
@ Retract
Definition GCodeProcessor.hpp:55
@ Noop
Definition GCodeProcessor.hpp:54
@ Unretract
Definition GCodeProcessor.hpp:56
@ Wipe
Definition GCodeProcessor.hpp:63
@ Seam
Definition GCodeProcessor.hpp:57
@ Extrude
Definition CadDocument.hpp:26
@ CustomGCode
Definition Types.hpp:129

◆ EOptionType

enum class libvgcode::EOptionType : uint8_t
strong
Enumerator
Travels 
Wipes 
Retractions 
Unretractions 
Seams 
ToolChanges 
ColorChanges 
PausePrints 
CustomGCodes 
COUNT 
175{
176 // This enum is used as in index into options_visibility.
177 // Better only add things to the end.
178 Travels,
179 Wipes,
182 Seams,
187#if VGCODE_ENABLE_COG_AND_TOOL_MARKERS
188 CenterOfGravity,
189 ToolMarker,
190#endif // VGCODE_ENABLE_COG_AND_TOOL_MARKERS
191 COUNT
192};
@ ToolChanges
Definition Types.hpp:183
@ Wipes
Definition Types.hpp:179
@ Seams
Definition Types.hpp:182
@ ColorChanges
Definition Types.hpp:184
@ CustomGCodes
Definition Types.hpp:186
@ Unretractions
Definition Types.hpp:181
@ Travels
Definition Types.hpp:178
@ Retractions
Definition Types.hpp:180
@ PausePrints
Definition Types.hpp:185

◆ ETimeMode

enum class libvgcode::ETimeMode : uint8_t
strong
Enumerator
Normal 
Stealth 
COUNT 
200{
201 Normal,
202 Stealth,
203 COUNT
204};
@ Normal
Definition PrePrintChecker.hpp:15
@ Stealth
Definition Types.hpp:202

◆ EViewType

enum class libvgcode::EViewType : uint8_t
strong
Enumerator
Summary 
FeatureType 
ColorPrint 
Speed 
ActualSpeed 
Height 
Width 
VolumetricFlowRate 
ActualVolumetricFlowRate 
LayerTimeLinear 
LayerTimeLogarithmic 
FanSpeed 
Temperature 
PressureAdvance 
Acceleration 
Jerk 
Tool 
COUNT 
91{
92 Summary, // ORCA
95 Speed,
97 Height,
98 Width,
103 FanSpeed,
105// ORCA: Add Pressure Advance visualization support
107 // ORCA: Add Acceleration visualization support
109 // ORCA: Add Jerk visualization support
110 Jerk,
111 Tool,
112 COUNT
113};
@ ColorPrint
Definition Types.hpp:94
@ Summary
Definition Types.hpp:92
@ Width
Definition Types.hpp:98
@ Acceleration
Definition Types.hpp:108
@ Speed
Definition Types.hpp:95
@ ActualVolumetricFlowRate
Definition Types.hpp:100
@ LayerTimeLogarithmic
Definition Types.hpp:102
@ PressureAdvance
Definition Types.hpp:106
@ ActualSpeed
Definition Types.hpp:96
@ Jerk
Definition Types.hpp:110
@ LayerTimeLinear
Definition Types.hpp:101
@ FeatureType
Definition Types.hpp:93
@ Tool
Definition Types.hpp:111
@ FanSpeed
Definition Types.hpp:103
@ VolumetricFlowRate
Definition Types.hpp:99
@ Temperature
Definition Types.hpp:104
@ Height
Definition Types.hpp:97

Function Documentation

◆ add_triangle()

void libvgcode::add_triangle ( uint16_t v1,
uint16_t v2,
uint16_t v3,
std::vector< uint16_t > & indices )
26{
27 indices.emplace_back(v1);
28 indices.emplace_back(v2);
29 indices.emplace_back(v3);
30}

◆ add_vertex()

void libvgcode::add_vertex ( const Vec3 & position,
const Vec3 & normal,
std::vector< float > & vertices )
16{
17 vertices.emplace_back(position[0]);
18 vertices.emplace_back(position[1]);
19 vertices.emplace_back(position[2]);
20 vertices.emplace_back(normal[0]);
21 vertices.emplace_back(normal[1]);
22 vertices.emplace_back(normal[2]);
23}

Referenced by libvgcode::OptionTemplate::init().

Here is the caller graph for this function:

◆ check_program()

std::string libvgcode::check_program ( GLuint handle)
222{
223 std::string ret;
224 GLint params;
225 glsafe(glGetProgramiv(handle, GL_LINK_STATUS, &params));
226 if (params == GL_FALSE) {
227 glsafe(glGetProgramiv(handle, GL_INFO_LOG_LENGTH, &params));
228 ret.resize(params);
229 glsafe(glGetProgramInfoLog(handle, params, &params, ret.data()));
230 }
231 return ret;
232}
#define glsafe(cmd)
Definition OpenGLUtils.hpp:25
#define glGetProgramiv
Definition gl.h:3945
int GLint
Definition gl.h:2062
#define GL_FALSE
Definition gl.h:648
#define glGetProgramInfoLog
Definition gl.h:3925
#define GL_LINK_STATUS
Definition gl.h:950
#define GL_INFO_LOG_LENGTH
Definition gl.h:848

References GL_FALSE, GL_INFO_LOG_LENGTH, GL_LINK_STATUS, glGetProgramInfoLog, glGetProgramiv, and glsafe.

◆ check_shader()

std::string libvgcode::check_shader ( GLuint handle)
209{
210 std::string ret;
211 GLint params;
212 glsafe(glGetShaderiv(handle, GL_COMPILE_STATUS, &params));
213 if (params == GL_FALSE) {
214 glsafe(glGetShaderiv(handle, GL_INFO_LOG_LENGTH, &params));
215 ret.resize(params);
216 glsafe(glGetShaderInfoLog(handle, params, &params, ret.data()));
217 }
218 return ret;
219}
#define glGetShaderInfoLog
Definition gl.h:3979
#define GL_COMPILE_STATUS
Definition gl.h:431
#define glGetShaderiv
Definition gl.h:3985

References GL_COMPILE_STATUS, GL_FALSE, GL_INFO_LOG_LENGTH, glGetShaderInfoLog, glGetShaderiv, and glsafe.

◆ convert() [1/13]

Slic3r::ColorRGBA libvgcode::convert ( const Color & c)
63{
64 static const float inv_255 = 1.0f / 255.0f;
65 return { c[0] * inv_255, c[1] * inv_255, c[2] * inv_255, 1.0f };
66}

◆ convert() [2/13]

Slic3r::ColorRGBA libvgcode::convert ( const ColorWithAlpha & c)
78{
79 static const float inv_255 = 1.0f / 255.0f;
80 return { c[0] * inv_255, c[1] * inv_255, c[2] * inv_255, c[3] * inv_255 };
81}

◆ convert() [3/13]

◆ convert() [4/13]

Color libvgcode::convert ( const Slic3r::ColorRGBA & c)
69{
70 // ORCA: Fix dark color rendering. Ensure minimal brightness.
71 auto safe_val = [](float v) -> uint8_t {
72 return std::max((uint8_t)(v * 255.0f), (uint8_t)48);
73 };
74 return { safe_val(c.r()), safe_val(c.g()), safe_val(c.b()) };
75}
float b() const
Definition Color.hpp:107
float r() const
Definition Color.hpp:105
float g() const
Definition Color.hpp:106

References Slic3r::ColorRGBA::b(), Slic3r::ColorRGBA::g(), and Slic3r::ColorRGBA::r().

Here is the call graph for this function:

◆ convert() [5/13]

GCodeInputData libvgcode::convert ( const Slic3r::GCodeProcessorResult & result,
const std::vector< std::string > & str_tool_colors,
const std::vector< std::string > & str_color_print_colors,
const Viewer & viewer,
const Slic3r::Transform3d * belt_xform )
241{
242 GCodeInputData ret;
243
244 // Belt printers: optionally map each vertex DISPLAY position from machine
245 // (G-code) space back to model/Cartesian space using the general belt
246 // back-transform (handles any mesh rotation + shear + axis remap, not just
247 // 45 deg). Only the rendered position is transformed; layer_id, times and
248 // the volumetric/flow math below keep the original machine-space values.
249 auto xform_pos = [belt_xform](const Slic3r::Vec3f& v) -> Vec3 {
250 if (belt_xform != nullptr)
251 return convert(Slic3r::Vec3f((*belt_xform * v.cast<double>()).cast<float>()));
252 return convert(v);
253 };
254
255 ret.tools_colors = convert_filament_colors(str_tool_colors);
256 ret.color_print_colors = convert_filament_colors(str_color_print_colors.empty() ? str_tool_colors : str_color_print_colors);
257
258 const std::vector<Slic3r::GCodeProcessorResult::MoveVertex>& moves = result.moves;
259 // One vertex per move after the first, plus a phantom in front of every path start. Reserving
260 // the exact count leaves nothing to shrink afterwards, and shrinking would copy the whole array
261 // while both copies are alive.
262 size_t vertices_count = moves.empty() ? 0 : moves.size() - 1;
263 for (size_t i = 1; i < moves.size(); ++i)
264 if (starts_path(moves[i - 1], moves[i], i == 1))
265 ++vertices_count;
266 ret.vertices.reserve(vertices_count);
267 // libvgcode numbers its layers from the vertices it is given and expects them to
268 // arrive one layer after the other with consecutive ids: a layer without any move
269 // (a belt file can carry layer changes that print nothing) would leave a gap, and
270 // every later vertex would then be folded into the last layer created. Renumber
271 // the ids consecutively over the moves that exist.
272 uint32_t src_layer_id = std::numeric_limits<uint32_t>::max();
273 uint32_t layer_id = 0;
274 for (size_t i = 1; i < moves.size(); ++i) {
275 const Slic3r::GCodeProcessorResult::MoveVertex& curr = moves[i];
276 const Slic3r::GCodeProcessorResult::MoveVertex& prev = moves[i - 1];
277 const EMoveType curr_type = convert(curr.type);
278 if (curr.layer_id != src_layer_id) {
279 if (src_layer_id != std::numeric_limits<uint32_t>::max())
280 ++ layer_id;
281 src_layer_id = curr.layer_id;
282 }
283 if (starts_path(prev, curr, i == 1)) {
284 // to allow libvgcode to properly detect the start/end of a path we need to add a 'phantom' vertex
285 // equal to the current one with the exception of the position, which should match the previous move position,
286 // and the times, which are set to zero
287#if VGCODE_ENABLE_COG_AND_TOOL_MARKERS
288 const libvgcode::PathVertex vertex = { xform_pos(prev.position), curr.height, curr.width, curr.feedrate, prev.actual_feedrate,
289 curr.mm3_per_mm, curr.fan_speed, curr.temperature, 0.0f, convert(curr.extrusion_role), curr_type,
290 static_cast<uint32_t>(curr.gcode_id), layer_id,
291 static_cast<uint8_t>(curr.extruder_id), static_cast<uint8_t>(curr.cp_color_id), { 0.0f, 0.0f },
292 /* ORCA: Add Pressure Advance visualization support */ 0.0f, curr.pressure_advance,
293 /* ORCA: Add Acceleration visualization support */ curr.acceleration,
294 /* ORCA: Add Jerk visualization support */ curr.jerk };
295#else
296 const libvgcode::PathVertex vertex = { xform_pos(prev.position), curr.height, curr.width, curr.feedrate, prev.actual_feedrate,
297 curr.mm3_per_mm, curr.fan_speed, curr.temperature, convert(curr.extrusion_role), curr_type,
298 static_cast<uint32_t>(curr.gcode_id), layer_id,
299 static_cast<uint8_t>(curr.extruder_id), static_cast<uint8_t>(curr.cp_color_id), { 0.0f, 0.0f },
300 /* ORCA: Add Pressure Advance visualization support */ 0.0f, curr.pressure_advance,
301 /* ORCA: Add Acceleration visualization support */ curr.acceleration,
302 /* ORCA: Add Jerk visualization support */ curr.jerk };
303#endif // VGCODE_ENABLE_COG_AND_TOOL_MARKERS
304 ret.vertices.emplace_back(vertex);
305 }
306
307#if VGCODE_ENABLE_COG_AND_TOOL_MARKERS
308 const libvgcode::PathVertex vertex = { xform_pos(curr.position), curr.height, curr.width, curr.feedrate, curr.actual_feedrate,
309 curr.mm3_per_mm, curr.fan_speed, curr.temperature,
310 result.filament_densities[curr.extruder_id] * curr.mm3_per_mm * (curr.position - prev.position).norm(),
311 convert(curr.extrusion_role), curr_type, static_cast<uint32_t>(curr.gcode_id), layer_id,
312 static_cast<uint8_t>(curr.extruder_id), static_cast<uint8_t>(curr.cp_color_id), curr.time,
313 /* ORCA: Add Pressure Advance visualization support */ 0.0f, curr.pressure_advance,
314 /* ORCA: Add Acceleration visualization support */ curr.acceleration,
315 /* ORCA: Add Jerk visualization support */ curr.jerk };
316#else
317 const libvgcode::PathVertex vertex = { xform_pos(curr.position), curr.height, curr.width, curr.feedrate, curr.actual_feedrate,
318 curr.mm3_per_mm, curr.fan_speed, curr.temperature, convert(curr.extrusion_role), curr_type,
319 static_cast<uint32_t>(curr.gcode_id), layer_id,
320 static_cast<uint8_t>(curr.extruder_id), static_cast<uint8_t>(curr.cp_color_id), curr.time,
321 /* ORCA: Add Pressure Advance visualization support */ 0.0f, curr.pressure_advance,
322 /* ORCA: Add Acceleration visualization support */ curr.acceleration,
323 /* ORCA: Add Jerk visualization support */ curr.jerk };
324#endif // VGCODE_ENABLE_COG_AND_TOOL_MARKERS
325 ret.vertices.emplace_back(vertex);
326 }
327 assert(ret.vertices.size() == vertices_count);
328 // A no-op when the count above is exact; restores the exact fit if the count ever drifts.
329 ret.vertices.shrink_to_fit();
330
331 // Note: the belt designed-view anchoring (recovering the per-object placement/
332 // lift translation the linear back-transform cannot) is folded into belt_xform
333 // by the caller (GCodeViewer::load_as_gcode), which anchors onto the upright
334 // model bounding box. Nothing extra to do here.
335
337
338 return ret;
339}
Eigen::Matrix< float, 3, 1, Eigen::DontAlign > Vec3f
Definition Point.hpp:65
EMoveType
Definition Types.hpp:121
bool spiral_vase_mode
Definition GCodeInputData.hpp:20
std::vector< PathVertex > vertices
Definition GCodeInputData.hpp:25
PaletteWithAlpha color_print_colors
Definition GCodeInputData.hpp:33
PaletteWithAlpha convert_filament_colors(const std::vector< std::string > &colors_str)
Definition LibVGCodeWrapper.cpp:83
std::array< float, 3 > Vec3
Definition Types.hpp:40
PaletteWithAlpha tools_colors
Definition GCodeInputData.hpp:29
static bool starts_path(const Slic3r::GCodeProcessorResult::MoveVertex &prev, const Slic3r::GCodeProcessorResult::MoveVertex &curr, bool first_move)
Definition LibVGCodeWrapper.cpp:227
Vec3 convert(const Slic3r::Vec3f &v)
Definition LibVGCodeWrapper.cpp:45
Definition GCodeInputData.hpp:15
Definition GCodeProcessor.hpp:237
unsigned char extruder_id
Definition GCodeProcessor.hpp:241
unsigned char cp_color_id
Definition GCodeProcessor.hpp:242
Vec3f position
Definition GCodeProcessor.hpp:243
float pressure_advance
Definition GCodeProcessor.hpp:254
float feedrate
Definition GCodeProcessor.hpp:245
unsigned int gcode_id
Definition GCodeProcessor.hpp:238
EMoveType type
Definition GCodeProcessor.hpp:239
float mm3_per_mm
Definition GCodeProcessor.hpp:249
float jerk
Definition GCodeProcessor.hpp:258
float width
Definition GCodeProcessor.hpp:247
ExtrusionRole extrusion_role
Definition GCodeProcessor.hpp:240
float actual_feedrate
Definition GCodeProcessor.hpp:246
unsigned int layer_id
Definition GCodeProcessor.hpp:261
float temperature
Definition GCodeProcessor.hpp:252
float acceleration
Definition GCodeProcessor.hpp:256
float fan_speed
Definition GCodeProcessor.hpp:251
float height
Definition GCodeProcessor.hpp:248
std::array< float, static_cast< size_t >(PrintEstimatedStatistics::ETimeMode::Count)> time
Definition GCodeProcessor.hpp:259
std::vector< float > filament_densities
Definition GCodeProcessor.hpp:368
std::vector< MoveVertex > moves
Definition GCodeProcessor.hpp:313
bool spiral_vase_mode
Definition GCodeProcessor.hpp:375

References Slic3r::GCodeProcessorResult::MoveVertex::acceleration, Slic3r::GCodeProcessorResult::MoveVertex::actual_feedrate, libvgcode::GCodeInputData::color_print_colors, convert(), convert_filament_colors(), Slic3r::GCodeProcessorResult::MoveVertex::cp_color_id, Slic3r::GCodeProcessorResult::MoveVertex::extruder_id, Slic3r::GCodeProcessorResult::MoveVertex::extrusion_role, Slic3r::GCodeProcessorResult::MoveVertex::fan_speed, Slic3r::GCodeProcessorResult::MoveVertex::feedrate, Slic3r::GCodeProcessorResult::filament_densities, Slic3r::GCodeProcessorResult::MoveVertex::gcode_id, Slic3r::GCodeProcessorResult::MoveVertex::height, Slic3r::GCodeProcessorResult::MoveVertex::jerk, Slic3r::GCodeProcessorResult::MoveVertex::layer_id, Slic3r::GCodeProcessorResult::MoveVertex::mm3_per_mm, Slic3r::GCodeProcessorResult::moves, Slic3r::GCodeProcessorResult::MoveVertex::position, Slic3r::GCodeProcessorResult::MoveVertex::pressure_advance, libvgcode::GCodeInputData::spiral_vase_mode, Slic3r::GCodeProcessorResult::spiral_vase_mode, starts_path(), Slic3r::GCodeProcessorResult::MoveVertex::temperature, Slic3r::GCodeProcessorResult::MoveVertex::time, libvgcode::GCodeInputData::tools_colors, Slic3r::GCodeProcessorResult::MoveVertex::type, libvgcode::GCodeInputData::vertices, and Slic3r::GCodeProcessorResult::MoveVertex::width.

Here is the call graph for this function:

◆ convert() [6/13]

Mat4x4 libvgcode::convert ( const Slic3r::Matrix4f & m)
56{
57 Mat4x4 ret;
58 std::memcpy(ret.data(), m.data(), 16 * sizeof(float));
59 return ret;
60}
std::array< float, 16 > Mat4x4
Definition Types.hpp:51

◆ convert() [7/13]

GCodeInputData libvgcode::convert ( const Slic3r::Print & print,
const std::vector< std::string > & str_tool_colors,
const std::vector< std::string > & str_color_print_colors,
const std::vector< Slic3r::CustomGCode::Item > & color_print_values,
size_t extruders_count )
843{
844 GCodeInputData ret;
845 std::vector<VerticesData> data;
846 if (print.is_step_done(Slic3r::psSkirtBrim) && (print.has_skirt() || print.has_brim()))
847 // extract vertices and layers zs from skirt/brim
849 if (!print.wipe_tower_data().tool_changes.empty() && print.is_step_done(Slic3r::psWipeTower))
850 // extract vertices and layers zs from wipe tower
851 convert_wipe_tower_to_vertices(print, str_tool_colors, data);
852 // extract vertices and layers zs from objects
853 convert_objects_to_vertices(print.objects(), str_tool_colors, str_color_print_colors, color_print_values, extruders_count, data);
854
855 // collect layers zs
856 std::vector<float> layers;
857 for (const VerticesData& d : data) {
858 layers.reserve(layers.size() + d.layers_zs.size());
859 std::copy(d.layers_zs.begin(), d.layers_zs.end(), std::back_inserter(layers));
860 }
862
863 // Now we need to copy the vertices into ret.vertices to be consumed by the preliminary G-code preview.
864 // We need to collect vertices in the first layer for all objects, push them into the output vector
865 // and then do the same for all the layers. The algorithm relies on the fact that the vertices from
866 // lower layers are always placed after vertices from the higher layer.
867 std::vector<size_t> vert_indices(data.size(), 0);
868 for (size_t layer_id = 0; layer_id < layers.size(); ++layer_id) {
869 const float layer_z = layers[layer_id];
870 for (size_t obj_idx = 0; obj_idx < data.size(); ++obj_idx) {
871 // d contains PathVertices for one object. Let's stuff everything below this layer_z into ret.vertices.
872 const size_t start_idx = vert_indices[obj_idx];
873 size_t idx = start_idx;
874 while (idx < data[obj_idx].vertices.size() && data[obj_idx].vertices[idx].position[2] <= layer_z)
875 ++idx;
876 // We have found a vertex above current layer_z. Let's copy the vertices into the output
877 // and remember where to start when we process another layer.
878 ret.vertices.insert(ret.vertices.end(),
879 data[obj_idx].vertices.begin() + start_idx,
880 data[obj_idx].vertices.begin() + idx);
881 vert_indices[obj_idx] = idx;
882 }
883 }
884
885
886 ret.tools_colors = convert_filament_colors(str_tool_colors);
887 ret.color_print_colors = convert_filament_colors(str_color_print_colors.empty() ? str_tool_colors : str_color_print_colors);
888
889 return ret;
890}
ConstPrintObjectPtrsAdaptor objects() const
Definition Print.hpp:1134
bool has_skirt() const
Definition Print.cpp:841
const WipeTowerData & wipe_tower_data(size_t filaments_cnt=0) const
Definition Print.cpp:5205
bool is_step_done(PrintStep step) const
Definition Print.hpp:1092
bool has_brim() const
Definition Print.cpp:849
@ psWipeTower
Definition Print.hpp:109
@ psSkirtBrim
Definition Print.hpp:114
void sort_remove_duplicates(std::vector< T > &vec)
Definition libslic3r.h:231
static void convert_wipe_tower_to_vertices(const Slic3r::Print &print, const std::vector< std::string > &str_tool_colors, std::vector< VerticesData > &vertices_data)
Definition LibVGCodeWrapper.cpp:556
static void convert_brim_skirt_to_vertices(const Slic3r::Print &print, std::vector< VerticesData > &vertices_data)
Definition LibVGCodeWrapper.cpp:477
static void convert_objects_to_vertices(const Slic3r::ConstPrintObjectPtrsAdaptor &objects, const std::vector< std::string > &str_tool_colors, const std::vector< std::string > &str_color_print_colors, const std::vector< Slic3r::CustomGCode::Item > &color_print_values, size_t extruders_count, std::vector< VerticesData > &data)
Definition LibVGCodeWrapper.cpp:827
Definition LibVGCodeWrapper.cpp:472
std::vector< std::vector< WipeTower::ToolChangeResult > > tool_changes
Definition Print.hpp:914

References libvgcode::GCodeInputData::color_print_colors, convert(), convert_brim_skirt_to_vertices(), convert_filament_colors(), convert_objects_to_vertices(), convert_wipe_tower_to_vertices(), Slic3r::Print::has_brim(), Slic3r::Print::has_skirt(), Slic3r::Print::is_step_done(), Slic3r::Print::objects(), Slic3r::psSkirtBrim, Slic3r::psWipeTower, Slic3r::sort_remove_duplicates(), Slic3r::WipeTowerData::tool_changes, libvgcode::GCodeInputData::tools_colors, libvgcode::GCodeInputData::vertices, and Slic3r::Print::wipe_tower_data().

Here is the call graph for this function:

◆ convert() [8/13]

◆ convert() [9/13]

◆ convert() [10/13]

Slic3r::Vec3f libvgcode::convert ( const Vec3 & v)
51{
52 return { v[0], v[1], v[2] };
53}

◆ convert() [11/13]

Slic3r::ExtrusionRole libvgcode::convert ( EGCodeExtrusionRole role)
102{
103 switch (role)
104 {
120 // ORCA
126 default: { return Slic3r::ExtrusionRole::erNone; }
127 }
128}
@ erMixed
Definition ExtrusionEntity.hpp:47
@ erBottomSurface
Definition ExtrusionEntity.hpp:34
@ erExternalPerimeter
Definition ExtrusionEntity.hpp:29
@ erGapFill
Definition ExtrusionEntity.hpp:38
@ erCustom
Definition ExtrusionEntity.hpp:45
@ erSupportMaterialInterface
Definition ExtrusionEntity.hpp:42
@ erSupportMaterial
Definition ExtrusionEntity.hpp:41
@ erWipeTower
Definition ExtrusionEntity.hpp:44
@ erBrim
Definition ExtrusionEntity.hpp:40
@ erSolidInfill
Definition ExtrusionEntity.hpp:32
@ erBridgeInfill
Definition ExtrusionEntity.hpp:36
@ erInternalBridgeInfill
Definition ExtrusionEntity.hpp:37
@ erTopSolidInfill
Definition ExtrusionEntity.hpp:33
@ erSkirt
Definition ExtrusionEntity.hpp:39
@ erSupportTransition
Definition ExtrusionEntity.hpp:43
@ erNone
Definition ExtrusionEntity.hpp:27
@ erOverhangPerimeter
Definition ExtrusionEntity.hpp:30
@ erIroning
Definition ExtrusionEntity.hpp:35
@ erPerimeter
Definition ExtrusionEntity.hpp:28
@ erInternalInfill
Definition ExtrusionEntity.hpp:31
@ None
Definition Types.hpp:145
@ Custom
Definition Types.hpp:159

References BottomSurface, BridgeInfill, Brim, Custom, Slic3r::erBottomSurface, Slic3r::erBridgeInfill, Slic3r::erBrim, Slic3r::erCustom, Slic3r::erExternalPerimeter, Slic3r::erGapFill, Slic3r::erInternalBridgeInfill, Slic3r::erInternalInfill, Slic3r::erIroning, Slic3r::erMixed, Slic3r::erNone, Slic3r::erOverhangPerimeter, Slic3r::erPerimeter, Slic3r::erSkirt, Slic3r::erSolidInfill, Slic3r::erSupportMaterial, Slic3r::erSupportMaterialInterface, Slic3r::erSupportTransition, Slic3r::erTopSolidInfill, Slic3r::erWipeTower, ExternalPerimeter, GapFill, InternalBridgeInfill, InternalInfill, Ironing, Mixed, None, OverhangPerimeter, Perimeter, Skirt, SolidInfill, SupportMaterial, SupportMaterialInterface, SupportTransition, TopSolidInfill, and WipeTower.

◆ convert() [12/13]

EMoveType libvgcode::convert ( Slic3r::EMoveType type)
160{
161 switch (type)
162 {
174 default: { return EMoveType::COUNT; }
175 }
176}
@ Travel
Definition GCodeProcessor.hpp:62
@ Custom_GCode
Definition GCodeProcessor.hpp:61
@ Pause_Print
Definition GCodeProcessor.hpp:60
@ Tool_change
Definition GCodeProcessor.hpp:58
@ Color_change
Definition GCodeProcessor.hpp:59
@ Extrude
Definition GCodeProcessor.hpp:64
@ Retract
Definition Types.hpp:123
@ Travel
Definition Types.hpp:130
@ Noop
Definition Types.hpp:122
@ COUNT
Definition Types.hpp:133
@ Unretract
Definition Types.hpp:124
@ ToolChange
Definition Types.hpp:126
@ PausePrint
Definition Types.hpp:128
@ Wipe
Definition Types.hpp:131
@ Seam
Definition Types.hpp:125
@ ColorChange
Definition Types.hpp:127
@ Extrude
Definition Types.hpp:132

References Slic3r::Color_change, ColorChange, COUNT, Slic3r::Custom_GCode, CustomGCode, Extrude, Slic3r::Extrude, Noop, Slic3r::Noop, Slic3r::Pause_Print, PausePrint, Retract, Slic3r::Retract, Seam, Slic3r::Seam, Slic3r::Tool_change, ToolChange, Travel, Slic3r::Travel, Unretract, Slic3r::Unretract, Wipe, and Slic3r::Wipe.

◆ convert() [13/13]

EGCodeExtrusionRole libvgcode::convert ( Slic3r::ExtrusionRole role)
131{
132 switch (role)
133 {
149 // ORCA
155 default: { return EGCodeExtrusionRole::None; }
156 }
157}

References BottomSurface, BridgeInfill, Brim, Custom, Slic3r::erBottomSurface, Slic3r::erBridgeInfill, Slic3r::erBrim, Slic3r::erCustom, Slic3r::erExternalPerimeter, Slic3r::erGapFill, Slic3r::erInternalBridgeInfill, Slic3r::erInternalInfill, Slic3r::erIroning, Slic3r::erMixed, Slic3r::erNone, Slic3r::erOverhangPerimeter, Slic3r::erPerimeter, Slic3r::erSkirt, Slic3r::erSolidInfill, Slic3r::erSupportMaterial, Slic3r::erSupportMaterialInterface, Slic3r::erSupportTransition, Slic3r::erTopSolidInfill, Slic3r::erWipeTower, ExternalPerimeter, GapFill, InternalBridgeInfill, InternalInfill, Ironing, Mixed, None, OverhangPerimeter, Perimeter, Skirt, SolidInfill, SupportMaterial, SupportMaterialInterface, SupportTransition, TopSolidInfill, and WipeTower.

◆ convert_brim_skirt_to_vertices()

void libvgcode::convert_brim_skirt_to_vertices ( const Slic3r::Print & print,
std::vector< VerticesData > & vertices_data )
static
478{
479 vertices_data.emplace_back(VerticesData());
480 VerticesData& data = vertices_data.back();
481
482 // number of skirt layers
483 size_t total_layer_count = 0;
484 for (const Slic3r::PrintObject* print_object : print.objects()) {
485 total_layer_count = std::max(total_layer_count, print_object->total_layer_count());
486 }
487 size_t skirt_height = print.has_infinite_skirt() ? total_layer_count : std::min<size_t>(print.config().skirt_height.value, total_layer_count);
488 if (skirt_height == 0 && print.has_brim())
489 skirt_height = 1;
490
491 // Get first skirt_height layers.
492 //FIXME This code is fishy. It may not work for multiple objects with different layering due to variable layer height feature.
493 // This is not critical as this is just an initial preview.
494 const Slic3r::PrintObject* highest_object = *std::max_element(print.objects().begin(), print.objects().end(),
495 [](auto l, auto r) { return l->layers().size() < r->layers().size(); });
496 data.layers_zs.reserve(skirt_height * 2);
497 for (size_t i = 0; i < std::min(skirt_height, highest_object->layers().size()); ++i) {
498 data.layers_zs.emplace_back(float(highest_object->layers()[i]->print_z));
499 }
500 // Only add skirt for the raft layers.
501 for (size_t i = 0; i < std::min(skirt_height, std::min(highest_object->slicing_parameters().raft_layers(), highest_object->support_layers().size())); ++i) {
502 data.layers_zs.emplace_back(float(highest_object->support_layers()[i]->print_z));
503 }
505 skirt_height = std::min(skirt_height, data.layers_zs.size());
506 data.layers_zs.erase(data.layers_zs.begin() + skirt_height, data.layers_zs.end());
507
508 for (size_t i = 0; i < skirt_height; ++i) {
509 // TODO - brim map?
510 // if (i == 0)
511 // convert_to_vertices(print.brim(), data.layers_zs[i], i, 0, 0, EGCodeExtrusionRole::Skirt, Slic3r::Point(0, 0), data.vertices);
512 convert_to_vertices(print.skirt(), data.layers_zs[i], i, 0, 0, EGCodeExtrusionRole::Skirt, Slic3r::Point(0, 0), data.vertices);
513 }
514}
T *const * begin() const
Definition Print.hpp:205
T *const * end() const
Definition Print.hpp:206
size_t size() const
Definition Print.hpp:210
Definition Print.hpp:365
ConstLayerPtrsAdaptor layers() const
Definition Print.hpp:374
ConstSupportLayerPtrsAdaptor support_layers() const
Definition Print.hpp:375
const SlicingParameters & slicing_parameters() const
Definition Print.hpp:496
bool has_infinite_skirt() const
Definition Print.cpp:830
const ExtrusionEntityCollection & skirt() const
Definition Print.hpp:1170
const PrintConfig & config() const
Definition Print.hpp:1131
zaa_minimize_perimeter_height skirt_height((ConfigOptionInt, skirt_loops))((ConfigOptionEnum< SkirtType >
static void convert_to_vertices(const Slic3r::ExtrusionPath &extrusion_path, float print_z, size_t layer_id, size_t extruder_id, size_t color_id, EGCodeExtrusionRole extrusion_role, const Slic3r::Point &shift, std::vector< PathVertex > &vertices)
Definition LibVGCodeWrapper.cpp:385
std::vector< PathVertex > vertices
Definition LibVGCodeWrapper.cpp:473
std::vector< float > layers_zs
Definition LibVGCodeWrapper.cpp:474
size_t raft_layers() const
Definition Slicing.hpp:44

References Slic3r::ConstVectorOfPtrsAdaptor< T >::begin(), Slic3r::Print::config(), convert_to_vertices(), Slic3r::ConstVectorOfPtrsAdaptor< T >::end(), Slic3r::Print::has_brim(), Slic3r::Print::has_infinite_skirt(), Slic3r::PrintObject::layers(), libvgcode::VerticesData::layers_zs, Slic3r::Print::objects(), Slic3r::SlicingParameters::raft_layers(), Slic3r::ConstVectorOfPtrsAdaptor< T >::size(), Skirt, Slic3r::Print::skirt(), Slic3r::PrintObject::slicing_parameters(), Slic3r::sort_remove_duplicates(), Slic3r::PrintObject::support_layers(), and libvgcode::VerticesData::vertices.

Referenced by convert().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ convert_filament_colors()

PaletteWithAlpha libvgcode::convert_filament_colors ( const std::vector< std::string > & colors_str)
84{
86 ret.reserve(colors_str.size());
87 for (const std::string& color_str : colors_str) {
88 Slic3r::ColorRGBA color_rgba;
89 if (!decode_color(color_str, color_rgba)) {
90 ret.push_back({ DUMMY_COLOR[0], DUMMY_COLOR[1], DUMMY_COLOR[2], 255 });
91 continue;
92 }
93 // as the 3D view draws it: a clear color kept at the least opacity, black lifted
94 color_rgba = adjust_color_for_rendering(color_rgba);
95 const Color color = convert(color_rgba);
96 ret.push_back({ color[0], color[1], color[2], static_cast<uint8_t>(std::lround(255.0f * color_rgba.a())) });
97 }
98 return ret;
99}
Slic3r::ColorRGBA adjust_color_for_rendering(const Slic3r::ColorRGBA &colors)
Definition 3DScene.cpp:112
Definition Color.hpp:80
float a() const
Definition Color.hpp:108
std::array< uint8_t, 3 > Color
Definition Types.hpp:59
std::vector< ColorWithAlpha > PaletteWithAlpha
Definition Types.hpp:71
static const Color DUMMY_COLOR
Definition Types.hpp:223

References Slic3r::ColorRGBA::a(), adjust_color_for_rendering(), convert(), and DUMMY_COLOR.

Referenced by convert(), convert(), and Slic3r::GUI::GCodeViewer::load_as_gcode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ convert_lines_to_vertices()

void libvgcode::convert_lines_to_vertices ( const Slic3r::Lines & lines,
const std::vector< float > & widths,
const std::vector< float > & heights,
float top_z,
size_t layer_id,
size_t extruder_id,
size_t color_id,
EGCodeExtrusionRole extrusion_role,
bool closed,
std::vector< PathVertex > & vertices )
static
343{
344 if (lines.empty())
345 return;
346
347 // loop once more in case of closed loops
348 const size_t lines_end = closed ? (lines.size() + 1) : lines.size();
349 for (size_t ii = 0; ii < lines_end; ++ii) {
350 const size_t i = (ii == lines.size()) ? 0 : ii;
351 const Slic3r::Line& line = lines[i];
352 // first segment of the polyline
353 if (ii == 0) {
354 // add a dummy vertex at the start, to separate the current line from the others
355 const Slic3r::Vec2f a = unscale(line.a).cast<float>();
356#if VGCODE_ENABLE_COG_AND_TOOL_MARKERS
357 libvgcode::PathVertex vertex = { convert(Slic3r::Vec3f(a.x(), a.y(), top_z)), heights[i], widths[i], 0.0f, 0.0f,
358 0.0f, 0.0f, 0.0f, 0.0f, extrusion_role, EMoveType::Noop, 0, static_cast<uint32_t>(layer_id),
359 static_cast<uint8_t>(extruder_id), static_cast<uint8_t>(color_id), { 0.0f, 0.0f } };
360#else
361 libvgcode::PathVertex vertex = { convert(Slic3r::Vec3f(a.x(), a.y(), top_z)), heights[i], widths[i], 0.0f, 0.0f,
362 0.0f, 0.0f, 0.0f, extrusion_role, EMoveType::Noop, 0, static_cast<uint32_t>(layer_id),
363 static_cast<uint8_t>(extruder_id), static_cast<uint8_t>(color_id), { 0.0f, 0.0f } };
364#endif // VGCODE_ENABLE_COG_AND_TOOL_MARKERS
365 vertices.emplace_back(vertex);
366 // add the starting vertex of the segment
367 vertex.type = EMoveType::Extrude;
368 vertices.emplace_back(vertex);
369 }
370 // add the ending vertex of the segment
371 const Slic3r::Vec2f b = unscale(line.b).cast<float>();
372#if VGCODE_ENABLE_COG_AND_TOOL_MARKERS
373 const libvgcode::PathVertex vertex = { convert(Slic3r::Vec3f(b.x(), b.y(), top_z)), heights[i], widths[i], 0.0f, 0.0f,
374 0.0f, 0.0f, 0.0f, 0.0f, extrusion_role, EMoveType::Extrude, 0, static_cast<uint32_t>(layer_id),
375 static_cast<uint8_t>(extruder_id), static_cast<uint8_t>(color_id), { 0.0f, 0.0f } };
376#else
377 const libvgcode::PathVertex vertex = { convert(Slic3r::Vec3f(b.x(), b.y(), top_z)), heights[i], widths[i], 0.0f, 0.0f,
378 0.0f, 0.0f, 0.0f, extrusion_role, EMoveType::Extrude, 0, static_cast<uint32_t>(layer_id),
379 static_cast<uint8_t>(extruder_id), static_cast<uint8_t>(color_id), { 0.0f, 0.0f } };
380#endif // VGCODE_ENABLE_COG_AND_TOOL_MARKERS
381 vertices.emplace_back(vertex);
382 }
383}
Definition Line.hpp:156
Point b
Definition Line.hpp:199
Point a
Definition Line.hpp:198
T unscale(Q v)
Definition libslic3r.h:138
Eigen::Matrix< float, 2, 1, Eigen::DontAlign > Vec2f
Definition Point.hpp:64
Definition PathVertex.hpp:20
EMoveType type
Definition PathVertex.hpp:66

References Slic3r::Line::a, Slic3r::Line::b, convert(), Extrude, and Noop.

Referenced by convert_to_vertices(), convert_to_vertices(), convert_to_vertices(), and convert_wipe_tower_to_vertices().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ convert_object_to_vertices()

void libvgcode::convert_object_to_vertices ( const Slic3r::PrintObject & object,
const std::vector< std::string > & str_tool_colors,
const std::vector< std::string > & str_color_print_colors,
const std::vector< Slic3r::CustomGCode::Item > & color_print_values,
size_t extruders_count,
VerticesData & data )
static
739{
740 const bool has_perimeters = object.is_step_done(Slic3r::posPerimeters);
741 const bool has_infill = object.is_step_done(Slic3r::posInfill);
742 const bool has_support = object.is_step_done(Slic3r::posSupportMaterial);
743
744 // order layers by print_z
745 std::vector<const Slic3r::Layer*> layers;
746 if (has_perimeters || has_infill) {
747 layers.reserve(layers.size() + object.layers().size());
748 std::copy(object.layers().begin(), object.layers().end(), std::back_inserter(layers));
749 }
750 if (has_support) {
751 layers.reserve(layers.size() + object.support_layers().size());
752 std::copy(object.support_layers().begin(), object.support_layers().end(), std::back_inserter(layers));
753 }
754 std::sort(layers.begin(), layers.end(), [](const Slic3r::Layer* l1, const Slic3r::Layer* l2) { return l1->print_z < l2->print_z; });
755
756 ObjectHelper object_helper(color_print_values, str_tool_colors.size(), str_color_print_colors.size(), extruders_count);
757
758 data.layers_zs.reserve(layers.size());
759 for (const Slic3r::Layer* layer : layers) {
760 data.layers_zs.emplace_back(static_cast<float>(layer->print_z));
761 }
762
764
765 for (const Slic3r::Layer* layer : layers) {
766 const size_t old_vertices_count = data.vertices.size();
767 const float layer_z = static_cast<float>(layer->print_z);
768 const auto it = std::find(data.layers_zs.begin(), data.layers_zs.end(), layer_z);
769 assert(it != data.layers_zs.end());
770 const size_t layer_id = (it != data.layers_zs.end()) ? std::distance(data.layers_zs.begin(), it) : 0;
771 for (const Slic3r::PrintInstance& instance : object.instances()) {
772 const Slic3r::Point& copy = instance.shift;
773 for (const Slic3r::LayerRegion* layerm : layer->regions()) {
774 if (layerm->slices.empty())
775 continue;
776 const Slic3r::PrintRegionConfig& cfg = layerm->region().config();
777 if (has_perimeters) {
778 const size_t extruder_id = static_cast<size_t>(std::max(cfg.outer_wall_filament_id.value - 1, 0));
779 convert_to_vertices(layerm->perimeters, layer_z, layer_id, extruder_id,
780 object_helper.color_id(layer_z, extruder_id), EGCodeExtrusionRole::ExternalPerimeter,
781 copy, data.vertices);
782 }
783 if (has_infill) {
784 for (const Slic3r::ExtrusionEntity* ee : layerm->fills) {
785 // fill represents infill extrusions of a single island.
786 const auto& fill = *dynamic_cast<const Slic3r::ExtrusionEntityCollection*>(ee);
787 if (!fill.entities.empty()) {
788 const Slic3r::ExtrusionRole role = fill.entities.front()->role();
789 const bool is_solid_infill = Slic3r::is_solid_infill(role);
790 const size_t extruder_id = is_solid_infill ?
791 static_cast<size_t>(std::max((role == Slic3r::erTopSolidInfill || role == Slic3r::erIroning ? cfg.top_surface_filament_id.value :
792 role == Slic3r::erBottomSurface ? cfg.bottom_surface_filament_id.value :
793 cfg.internal_solid_filament_id.value) - 1, 0)) :
794 static_cast<size_t>(std::max(cfg.sparse_infill_filament_id.value - 1, 0));
795 convert_to_vertices(fill, layer_z, layer_id, extruder_id,
796 object_helper.color_id(layer_z, extruder_id),
798 copy, data.vertices);
799 }
800 }
801 }
802 }
803 if (has_support) {
804 const Slic3r::SupportLayer* support_layer = dynamic_cast<const Slic3r::SupportLayer*>(layer);
805 if (support_layer == nullptr)
806 continue;
807 const Slic3r::PrintObjectConfig& cfg = support_layer->object()->config();
808 for (const Slic3r::ExtrusionEntity* extrusion_entity : support_layer->support_fills.entities) {
809 const bool is_support_material = extrusion_entity->role() == Slic3r::ExtrusionRole::erSupportMaterial;
810 const size_t extruder_id = is_support_material ?
811 static_cast<size_t>(std::max(cfg.support_filament.value - 1, 0)) :
812 static_cast<size_t>(std::max(cfg.support_interface_filament.value - 1, 0));
813 convert_to_vertices(*extrusion_entity, layer_z, layer_id,
814 extruder_id, object_helper.color_id(layer_z, extruder_id),
816 copy, data.vertices);
817 }
818 }
819 }
820 // filter out empty layers
821 const size_t new_vertices_count = data.vertices.size();
822 if (new_vertices_count == old_vertices_count)
823 data.layers_zs.erase(data.layers_zs.begin() + layer_id);
824 }
825}
ExtrusionEntitiesPtr entities
Definition ExtrusionEntityCollection.hpp:39
virtual ExtrusionRole role() const =0
PrintObject * object()
Definition Layer.hpp:143
const PrintObjectConfig & config() const
Definition Print.hpp:372
ExtrusionEntityCollection support_fills
Definition Layer.hpp:309
Definition LibVGCodeWrapper.cpp:618
double layer_z(const SlicingParameters &slicing_params, const TreeSupportSettings &config, const size_t layer_idx)
Definition TreeSupportCommon.hpp:626
sparse_infill_filament_id((ConfigOptionFloatOrPercent, sparse_infill_line_width))((ConfigOptionPercent
zaa_minimize_perimeter_height PrintRegionConfig
Definition PrintConfig.hpp:2183
ExtrusionRole
Definition ExtrusionEntity.hpp:26
zaa_minimize_perimeter_height PrintObjectConfig
Definition PrintConfig.hpp:2183
@ posInfill
Definition Print.hpp:125
@ posPerimeters
Definition Print.hpp:124
@ posSupportMaterial
Definition Print.hpp:125
bool is_solid_infill(ExtrusionRole role)
Definition ExtrusionEntity.hpp:95

References libvgcode::ObjectHelper::color_id(), Slic3r::PrintObject::config(), convert_object_to_vertices(), convert_to_vertices(), Slic3r::ExtrusionEntityCollection::entities, Slic3r::erBottomSurface, Slic3r::erIroning, Slic3r::erSupportMaterial, Slic3r::erTopSolidInfill, ExternalPerimeter, InternalInfill, Slic3r::is_solid_infill(), libvgcode::VerticesData::layers_zs, Slic3r::Layer::object(), Slic3r::posInfill, Slic3r::posPerimeters, Slic3r::posSupportMaterial, Slic3r::PrintObjectConfig, Slic3r::PrintRegionConfig, Slic3r::ExtrusionEntity::role(), SolidInfill, Slic3r::sort_remove_duplicates(), Slic3r::SupportLayer::support_fills, SupportMaterial, SupportMaterialInterface, and libvgcode::VerticesData::vertices.

Referenced by convert_object_to_vertices(), and convert_objects_to_vertices().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ convert_objects_to_vertices()

void libvgcode::convert_objects_to_vertices ( const Slic3r::ConstPrintObjectPtrsAdaptor & objects,
const std::vector< std::string > & str_tool_colors,
const std::vector< std::string > & str_color_print_colors,
const std::vector< Slic3r::CustomGCode::Item > & color_print_values,
size_t extruders_count,
std::vector< VerticesData > & data )
static
830{
831 // extract vertices and layers zs object by object
832 data.reserve(data.size() + objects.size());
833 for (size_t i = 0; i < objects.size(); ++i) {
834 data.emplace_back(VerticesData());
835 convert_object_to_vertices(*objects[i], str_tool_colors, str_color_print_colors, color_print_values, extruders_count, data.back());
836 }
837}
static void convert_object_to_vertices(const Slic3r::PrintObject &object, const std::vector< std::string > &str_tool_colors, const std::vector< std::string > &str_color_print_colors, const std::vector< Slic3r::CustomGCode::Item > &color_print_values, size_t extruders_count, VerticesData &data)
Definition LibVGCodeWrapper.cpp:736

References convert_object_to_vertices(), convert_objects_to_vertices(), and Slic3r::ConstVectorOfPtrsAdaptor< T >::size().

Referenced by convert(), and convert_objects_to_vertices().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ convert_to_vertices() [1/5]

void libvgcode::convert_to_vertices ( const Slic3r::ExtrusionEntity & extrusion_entity,
float print_z,
size_t layer_id,
size_t extruder_id,
size_t color_id,
EGCodeExtrusionRole extrusion_role,
const Slic3r::Point & shift,
std::vector< PathVertex > & vertices )
static
439{
440 auto* extrusion_path = dynamic_cast<const Slic3r::ExtrusionPath*>(&extrusion_entity);
441 if (extrusion_path != nullptr)
442 convert_to_vertices(*extrusion_path, print_z, layer_id, extruder_id, color_id, extrusion_role, shift, vertices);
443 else {
444 auto* extrusion_loop = dynamic_cast<const Slic3r::ExtrusionLoop*>(&extrusion_entity);
445 if (extrusion_loop != nullptr)
446 convert_to_vertices(*extrusion_loop, print_z, layer_id, extruder_id, color_id, extrusion_role, shift, vertices);
447 else {
448 auto* extrusion_multi_path = dynamic_cast<const Slic3r::ExtrusionMultiPath*>(&extrusion_entity);
449 if (extrusion_multi_path != nullptr)
450 convert_to_vertices(*extrusion_multi_path, print_z, layer_id, extruder_id, color_id, extrusion_role, shift, vertices);
451 else {
452 auto* extrusion_entity_collection = dynamic_cast<const Slic3r::ExtrusionEntityCollection*>(&extrusion_entity);
453 if (extrusion_entity_collection != nullptr)
454 convert_to_vertices(*extrusion_entity_collection, print_z, layer_id, extruder_id, color_id, extrusion_role, shift, vertices);
455 else
456 throw Slic3r::RuntimeError("Found unexpected extrusion_entity type");
457 }
458 }
459 }
460}
Definition ExtrusionEntityCollection.hpp:33
Definition ExtrusionEntity.hpp:468
Definition ExtrusionEntity.hpp:399
Definition ExtrusionEntity.hpp:175

References convert_to_vertices().

Here is the call graph for this function:

◆ convert_to_vertices() [2/5]

void libvgcode::convert_to_vertices ( const Slic3r::ExtrusionEntityCollection & extrusion_entity_collection,
float print_z,
size_t layer_id,
size_t extruder_id,
size_t color_id,
EGCodeExtrusionRole extrusion_role,
const Slic3r::Point & shift,
std::vector< PathVertex > & vertices )
static
464{
465 for (const Slic3r::ExtrusionEntity* extrusion_entity : extrusion_entity_collection.entities) {
466 if (extrusion_entity != nullptr)
467 convert_to_vertices(*extrusion_entity, print_z, layer_id, extruder_id, color_id, extrusion_role, shift, vertices);
468 }
469}
Definition ExtrusionEntity.hpp:121

References convert_to_vertices(), and Slic3r::ExtrusionEntityCollection::entities.

Here is the call graph for this function:

◆ convert_to_vertices() [3/5]

void libvgcode::convert_to_vertices ( const Slic3r::ExtrusionLoop & extrusion_loop,
float print_z,
size_t layer_id,
size_t extruder_id,
size_t color_id,
EGCodeExtrusionRole extrusion_role,
const Slic3r::Point & shift,
std::vector< PathVertex > & vertices )
static
417{
418 Slic3r::Lines lines;
419 std::vector<float> widths;
420 std::vector<float> heights;
421 for (const Slic3r::ExtrusionPath& extrusion_path : extrusion_loop.paths) {
422 Slic3r::Polyline polyline = extrusion_path.polyline.to_polyline();
423 polyline.remove_duplicate_points();
424 polyline.translate(shift);
425 const Slic3r::Lines lines_this = polyline.lines();
426 append(lines, lines_this);
427 widths.insert(widths.end(), lines_this.size(), extrusion_path.width);
428 heights.insert(heights.end(), lines_this.size(), extrusion_path.height);
429 }
430 convert_lines_to_vertices(lines, widths, heights, print_z, layer_id, extruder_id, color_id, extrusion_role, true, vertices);
431}
ExtrusionPaths paths
Definition ExtrusionEntity.hpp:470
Polyline3 polyline
Definition ExtrusionEntity.hpp:177
float width
Definition ExtrusionEntity.hpp:183
float height
Definition ExtrusionEntity.hpp:185
void translate(double x, double y)
Definition MultiPoint.hpp:38
bool remove_duplicate_points()
Definition MultiPoint.cpp:113
Polyline to_polyline() const
Definition Polyline.cpp:682
Definition Polyline.hpp:25
Lines lines() const override
Definition Polyline.cpp:31
std::vector< Line > Lines
Definition Line.hpp:20
static void convert_lines_to_vertices(const Slic3r::Lines &lines, const std::vector< float > &widths, const std::vector< float > &heights, float top_z, size_t layer_id, size_t extruder_id, size_t color_id, EGCodeExtrusionRole extrusion_role, bool closed, std::vector< PathVertex > &vertices)
Definition LibVGCodeWrapper.cpp:341

References convert_lines_to_vertices(), Slic3r::ExtrusionPath::height, Slic3r::Polyline::lines(), Slic3r::ExtrusionLoop::paths, Slic3r::ExtrusionPath::polyline, Slic3r::MultiPoint::remove_duplicate_points(), Slic3r::Polyline3::to_polyline(), Slic3r::MultiPoint::translate(), and Slic3r::ExtrusionPath::width.

Here is the call graph for this function:

◆ convert_to_vertices() [4/5]

void libvgcode::convert_to_vertices ( const Slic3r::ExtrusionMultiPath & extrusion_multi_path,
float print_z,
size_t layer_id,
size_t extruder_id,
size_t color_id,
EGCodeExtrusionRole extrusion_role,
const Slic3r::Point & shift,
std::vector< PathVertex > & vertices )
static
399{
400 Slic3r::Lines lines;
401 std::vector<float> widths;
402 std::vector<float> heights;
403 for (const Slic3r::ExtrusionPath& extrusion_path : extrusion_multi_path.paths) {
404 Slic3r::Polyline polyline = extrusion_path.polyline.to_polyline();
405 polyline.remove_duplicate_points();
406 polyline.translate(shift);
407 const Slic3r::Lines lines_this = polyline.lines();
408 append(lines, lines_this);
409 widths.insert(widths.end(), lines_this.size(), extrusion_path.width);
410 heights.insert(heights.end(), lines_this.size(), extrusion_path.height);
411 }
412 convert_lines_to_vertices(lines, widths, heights, print_z, layer_id, extruder_id, color_id, extrusion_role, false, vertices);
413}
ExtrusionPaths paths
Definition ExtrusionEntity.hpp:401

References convert_lines_to_vertices(), Slic3r::ExtrusionPath::height, Slic3r::Polyline::lines(), Slic3r::ExtrusionMultiPath::paths, Slic3r::ExtrusionPath::polyline, Slic3r::MultiPoint::remove_duplicate_points(), Slic3r::Polyline3::to_polyline(), Slic3r::MultiPoint::translate(), and Slic3r::ExtrusionPath::width.

Here is the call graph for this function:

◆ convert_to_vertices() [5/5]

void libvgcode::convert_to_vertices ( const Slic3r::ExtrusionPath & extrusion_path,
float print_z,
size_t layer_id,
size_t extruder_id,
size_t color_id,
EGCodeExtrusionRole extrusion_role,
const Slic3r::Point & shift,
std::vector< PathVertex > & vertices )
static
387{
388 Slic3r::Polyline polyline = extrusion_path.polyline.to_polyline();
389 polyline.remove_duplicate_points();
390 polyline.translate(shift);
391 const Slic3r::Lines lines = polyline.lines();
392 std::vector<float> widths(lines.size(), extrusion_path.width);
393 std::vector<float> heights(lines.size(), extrusion_path.height);
394 convert_lines_to_vertices(lines, widths, heights, print_z, layer_id, extruder_id, color_id, extrusion_role, false, vertices);
395}

References convert_lines_to_vertices(), Slic3r::ExtrusionPath::height, Slic3r::Polyline::lines(), Slic3r::ExtrusionPath::polyline, Slic3r::MultiPoint::remove_duplicate_points(), Slic3r::Polyline3::to_polyline(), Slic3r::MultiPoint::translate(), and Slic3r::ExtrusionPath::width.

Referenced by convert_brim_skirt_to_vertices(), convert_object_to_vertices(), convert_to_vertices(), and convert_to_vertices().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ convert_wipe_tower_to_vertices()

void libvgcode::convert_wipe_tower_to_vertices ( const Slic3r::Print & print,
const std::vector< std::string > & str_tool_colors,
std::vector< VerticesData > & vertices_data )
static
558{
559 vertices_data.emplace_back(VerticesData());
560 VerticesData& data = vertices_data.back();
561
562 WipeTowerHelper wipe_tower_helper(print);
563 const float angle = wipe_tower_helper.get_angle();
564 const Slic3r::Vec2f& position = wipe_tower_helper.get_position();
565
566 for (size_t item = 0; item < wipe_tower_helper.get_layers_count(); ++item) {
567 const std::vector<Slic3r::WipeTower::ToolChangeResult>& layer = wipe_tower_helper.tool_change(item);
568 for (const Slic3r::WipeTower::ToolChangeResult& extrusions : layer) {
569 data.layers_zs.emplace_back(extrusions.print_z);
570 for (size_t i = 1; i < extrusions.extrusions.size(); /*no increment*/) {
571 const Slic3r::WipeTower::Extrusion& e = extrusions.extrusions[i];
572 if (e.width == 0.0f) {
573 ++i;
574 continue;
575 }
576 size_t j = i + 1;
577 if (str_tool_colors.empty())
578 for (; j < extrusions.extrusions.size() && extrusions.extrusions[j].width > 0.0f; ++j);
579 else
580 for (; j < extrusions.extrusions.size() && extrusions.extrusions[j].tool == e.tool && extrusions.extrusions[j].width > 0.0f; ++j);
581
582 const size_t n_lines = j - i;
583 Slic3r::Lines lines;
584 std::vector<float> widths;
585 std::vector<float> heights;
586 lines.reserve(n_lines);
587 widths.reserve(n_lines);
588 heights.assign(n_lines, extrusions.layer_height);
589 Slic3r::WipeTower::Extrusion e_prev = extrusions.extrusions[i - 1];
590
591 if (!extrusions.priming) { // wipe tower extrusions describe the wipe tower at the origin with no rotation
592 e_prev.pos = Eigen::Rotation2Df(angle) * e_prev.pos;
593 e_prev.pos += position;
594 }
595
596 for (; i < j; ++i) {
597 Slic3r::WipeTower::Extrusion ee = extrusions.extrusions[i];
598 assert(ee.width > 0.0f);
599 if (!extrusions.priming) {
600 ee.pos = Eigen::Rotation2Df(angle) * ee.pos;
601 ee.pos += position;
602 }
603 lines.emplace_back(Slic3r::Point::new_scale(e_prev.pos.x(), e_prev.pos.y()), Slic3r::Point::new_scale(ee.pos.x(), ee.pos.y()));
604 widths.emplace_back(ee.width);
605 e_prev = ee;
606 }
607
608 convert_lines_to_vertices(lines, widths, heights, extrusions.print_z, item, static_cast<size_t>(e.tool), 0,
609 EGCodeExtrusionRole::WipeTower, lines.front().a == lines.back().b, data.vertices);
610 }
611 }
612 }
613
615}
static Point new_scale(coordf_t x, coordf_t y)
Definition Point.hpp:214
Definition LibVGCodeWrapper.cpp:517
Definition WipeTower.hpp:89
unsigned int tool
Definition WipeTower.hpp:97
Vec2f pos
Definition WipeTower.hpp:92
float width
Definition WipeTower.hpp:95
Definition WipeTower.hpp:114

References convert_lines_to_vertices(), convert_wipe_tower_to_vertices(), libvgcode::WipeTowerHelper::get_angle(), libvgcode::WipeTowerHelper::get_layers_count(), libvgcode::WipeTowerHelper::get_position(), libvgcode::VerticesData::layers_zs, Slic3r::Point::new_scale(), Slic3r::WipeTower::Extrusion::pos, Slic3r::sort_remove_duplicates(), Slic3r::WipeTower::Extrusion::tool, libvgcode::WipeTowerHelper::tool_change(), libvgcode::VerticesData::vertices, Slic3r::WipeTower::Extrusion::width, and WipeTower.

Referenced by convert(), and convert_wipe_tower_to_vertices().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ delete_buffers()

void libvgcode::delete_buffers ( unsigned int & id)
static
294{
295 if (id != 0) {
296 glsafe(glDeleteBuffers(1, &id));
297 id = 0;
298 }
299}
#define glDeleteBuffers
Definition gl.h:3563

References glDeleteBuffers, and glsafe.

Referenced by libvgcode::ViewerImpl::reset().

Here is the caller graph for this function:

◆ delete_textures()

void libvgcode::delete_textures ( unsigned int & id)
static
286{
287 if (id != 0) {
288 glsafe(glDeleteTextures(1, &id));
289 id = 0;
290 }
291}
#define glDeleteTextures
Definition gl.h:3587

References glDeleteTextures, and glsafe.

Referenced by libvgcode::ViewerImpl::TranslucentTargets::release(), and libvgcode::ViewerImpl::reset().

Here is the caller graph for this function:

◆ dot()

float libvgcode::dot ( const Vec3 & v1,
const Vec3 & v2 )
41{
42 return v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2];
43}

Referenced by extract_pos_and_or_hwa(), length(), and normalize().

Here is the caller graph for this function:

◆ extract_pos_and_or_hwa()

void libvgcode::extract_pos_and_or_hwa ( const std::vector< PathVertex > & vertices,
float travels_radius,
float wipes_radius,
BitSet<> & valid_lines_bitset,
std::vector< Vec4 > * positions = nullptr,
std::vector< Vec4 > * heights_widths_angles = nullptr,
bool update_bitset = false )
static
1049 {
1050 static constexpr const Vec3 ZERO = { 0.0f, 0.0f, 0.0f };
1051 if (positions == nullptr && heights_widths_angles == nullptr)
1052 return;
1053 if (vertices.empty())
1054 return;
1055 if (travels_radius <= 0.0f || wipes_radius <= 0.0f)
1056 return;
1057
1058 if (positions != nullptr)
1059 positions->reserve(vertices.size());
1060 if (heights_widths_angles != nullptr)
1061 heights_widths_angles->reserve(vertices.size());
1062 for (size_t i = 0; i < vertices.size(); ++i) {
1063 const PathVertex& v = vertices[i];
1064 const EMoveType move_type = v.type;
1065 const bool prev_line_valid = i > 0 && valid_lines_bitset[i - 1];
1066 const Vec3 prev_line = prev_line_valid ? v.position - vertices[i - 1].position : ZERO;
1067 const bool this_line_valid = is_line(vertices, i);
1068 const Vec3 this_line = this_line_valid ? vertices[i + 1].position - v.position : ZERO;
1069
1070 if (this_line_valid) {
1071 // there is a valid path between point i and i+1.
1072 }
1073 else {
1074 // the connection is invalid, there should be no line rendered, ever
1075 if (update_bitset)
1076 valid_lines_bitset.reset(i);
1077 }
1078
1079 if (positions != nullptr) {
1080 // ORCA: the last component, there to comply with GL_RGBA32F format, carries the layer the shaders grey and dim by,
1081 // plus 0.5 at the joint of two segments, which the shaders read as an int, see joint_a in Segments_Vertex_Shader
1082 Vec4 position = { v.position[0], v.position[1], v.position[2],
1083 static_cast<float>(v.layer_id) + (is_joint(vertices, i) ? 0.5f : 0.0f) };
1084 if (move_type == EMoveType::Extrude)
1085 // push down extrusion vertices by half height to render them at the right z
1086 position[2] -= 0.5f * v.height;
1087 positions->emplace_back(position);
1088 }
1089
1090 if (heights_widths_angles != nullptr) {
1091 float height = 0.0f;
1092 float width = 0.0f;
1093 if (v.is_travel()) {
1094 height = travels_radius;
1095 width = travels_radius;
1096 }
1097 else if (v.is_wipe()) {
1098 height = wipes_radius;
1099 width = wipes_radius;
1100 }
1101 else {
1102 height = v.height;
1103 width = v.width;
1104 }
1105
1106 // ORCA: Set bias for wipes and options to avoid z-fighting
1107 float bias = 0.0f;
1108 if (v.is_wipe())
1109 bias = 0.05f;
1110 else if (v.is_option())
1111 bias = 0.1f;
1112
1113 // the last component is a dummy float to comply with GL_RGBA32F format
1114 // ORCA: Pass bias to shader
1115 heights_widths_angles->push_back({ height, width,
1116 std::atan2(prev_line[0] * this_line[1] - prev_line[1] * this_line[0], dot(prev_line, this_line)), bias });
1117 }
1118 }
1119}
coord_t width(const BoundingBox &box)
Definition Arrange.cpp:1184
coord_t height(const BoundingBox &box)
Definition Arrange.cpp:1185
static bool is_line(const std::vector< PathVertex > &vertices, size_t i)
Definition ViewerImpl.cpp:1030
std::array< float, 4 > Vec4
Definition Types.hpp:42
float dot(const Vec3 &v1, const Vec3 &v2)
Definition Utils.cpp:40
static bool is_joint(const std::vector< PathVertex > &vertices, size_t i)
Definition ViewerImpl.cpp:1038

References dot(), Extrude, libvgcode::PathVertex::height, is_joint(), is_line(), libvgcode::PathVertex::is_option(), libvgcode::PathVertex::is_travel(), libvgcode::PathVertex::is_wipe(), libvgcode::PathVertex::layer_id, libvgcode::PathVertex::position, libvgcode::PathVertex::type, and libvgcode::PathVertex::width.

Referenced by libvgcode::ViewerImpl::load(), and libvgcode::ViewerImpl::update_heights_widths().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fast_round_up()

template<typename I>
IntegerOnly< I, I > libvgcode::fast_round_up ( double a)
inline
51{
52 // Why does Java Math.round(0.49999999999999994) return 1?
53 // https://stackoverflow.com/questions/9902968/why-does-math-round0-49999999999999994-return-1
54 return a == 0.49999999999999994 ? I(0) : I(floor(a + 0.5));
55}

Referenced by round_to_bin().

Here is the caller graph for this function:

◆ get_step_size()

float libvgcode::get_step_size ( const ColorRange & color_range)
static
23{
24 const std::array<float, 2>& range = color_range.get_range();
25 const Palette& palette = color_range.get_palette();
26 switch (color_range.get_type())
27 {
28 default:
30 {
31 return (range[1] - range[0]) / (static_cast<float>(palette.size()) - 1.0f);
32 }
34 {
35 return (range[0] != 0.0f) ? std::log(range[1] / range[0]) / (static_cast<float>(palette.size()) - 1.0f) : 0.0f;
36 }
37 }
38}
const std::array< float, 2 > & get_range() const
Definition ColorRange.cpp:87
EColorRangeType get_type() const
Definition ColorRange.cpp:46
const Palette & get_palette() const
Definition ColorRange.cpp:51
std::vector< Color > Palette
Definition Types.hpp:64
@ Linear
Definition Types.hpp:213

References libvgcode::ColorRange::get_palette(), libvgcode::ColorRange::get_range(), libvgcode::ColorRange::get_type(), Linear, and Logarithmic.

Referenced by libvgcode::ColorRange::get_color_at(), and libvgcode::ColorRange::get_values().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ glAssertRecentCall()

void libvgcode::glAssertRecentCall ( )
inline
24{ glAssertRecentCallImpl(__FILE__, __LINE__, __FUNCTION__); }
void glAssertRecentCallImpl(const char *file_name, unsigned int line, const char *function_name)
Definition OpenGLUtils.cpp:18

References glAssertRecentCallImpl().

Here is the call graph for this function:

◆ glAssertRecentCallImpl()

void libvgcode::glAssertRecentCallImpl ( const char * file_name,
unsigned int line,
const char * function_name )
19{
20 const GLenum err = glGetError();
21 if (err == GL_NO_ERROR)
22 return;
23 const char* sErr = 0;
24 switch (err) {
25 case GL_INVALID_ENUM: { sErr = "Invalid Enum"; break; }
26 case GL_INVALID_VALUE: { sErr = "Invalid Value"; break; }
27 // be aware that GL_INVALID_OPERATION is generated if glGetError is executed between the execution of glBegin / glEnd
28 case GL_INVALID_OPERATION: { sErr = "Invalid Operation"; break; }
29 case GL_OUT_OF_MEMORY: { sErr = "Out Of Memory"; break; }
30 case GL_INVALID_FRAMEBUFFER_OPERATION: { sErr = "Invalid framebuffer operation"; break; }
31#if !defined(ENABLE_OPENGL_ES)
32 case GL_STACK_OVERFLOW: { sErr = "Stack Overflow"; break; }
33 case GL_STACK_UNDERFLOW: { sErr = "Stack Underflow"; break; }
34#endif // ENABLE_OPENGL_ES
35 default: { sErr = "Unknown"; break; }
36 }
37 std::cout << "OpenGL error in " << file_name << ":" << line << ", function " << function_name << "() : " << (int)err << " - " << sErr << "\n";
38 assert(false);
39}
#define GL_INVALID_VALUE
Definition gl.h:904
#define glGetError
Definition gl.h:3849
#define GL_INVALID_OPERATION
Definition gl.h:903
#define GL_STACK_OVERFLOW
Definition gl.h:1630
unsigned int GLenum
Definition gl.h:2054
#define GL_NO_ERROR
Definition gl.h:1217
#define GL_INVALID_FRAMEBUFFER_OPERATION
Definition gl.h:900
#define GL_OUT_OF_MEMORY
Definition gl.h:1251
#define GL_INVALID_ENUM
Definition gl.h:899
#define GL_STACK_UNDERFLOW
Definition gl.h:1631

References GL_INVALID_ENUM, GL_INVALID_FRAMEBUFFER_OPERATION, GL_INVALID_OPERATION, GL_INVALID_VALUE, GL_NO_ERROR, GL_OUT_OF_MEMORY, GL_STACK_OVERFLOW, GL_STACK_UNDERFLOW, and glGetError.

Referenced by glAssertRecentCall().

Here is the caller graph for this function:

◆ init_shader()

unsigned int libvgcode::init_shader ( const std::string & shader_name,
const char * vertex_shader,
const char * fragment_shader,
const std::vector< const char * > & fragment_outputs = {} )
236 {})
237{
239 glcheck();
240 glsafe(glShaderSource(vs_id, 1, &vertex_shader, nullptr));
241 glsafe(glCompileShader(vs_id));
242 std::string res = check_shader(vs_id);
243 if (!res.empty()) {
244 glsafe(glDeleteShader(vs_id));
245 throw std::runtime_error("LibVGCode: Unable to compile vertex shader:\n" + shader_name + "\n" + res + "\n");
246 }
247
249 glcheck();
250 glsafe(glShaderSource(fs_id, 1, &fragment_shader, nullptr));
251 glsafe(glCompileShader(fs_id));
252 res = check_shader(fs_id);
253 if (!res.empty()) {
254 glsafe(glDeleteShader(vs_id));
255 glsafe(glDeleteShader(fs_id));
256 throw std::runtime_error("LibVGCode: Unable to compile fragment shader:\n" + shader_name + "\n" + res + "\n");
257 }
258
259 const GLuint shader_id = glCreateProgram();
260 glcheck();
261 glsafe(glAttachShader(shader_id, vs_id));
262 glsafe(glAttachShader(shader_id, fs_id));
263#ifndef ENABLE_OPENGL_ES
264 for (size_t i = 0; i < fragment_outputs.size(); ++i)
265 glsafe(glBindFragDataLocation(shader_id, static_cast<GLuint>(i), fragment_outputs[i]));
266#endif // ENABLE_OPENGL_ES
267 glsafe(glLinkProgram(shader_id));
268 res = check_program(shader_id);
269 if (!res.empty()) {
270 glsafe(glDetachShader(shader_id, vs_id));
271 glsafe(glDetachShader(shader_id, fs_id));
272 glsafe(glDeleteShader(vs_id));
273 glsafe(glDeleteShader(fs_id));
274 glsafe(glDeleteProgram(shader_id));
275 throw std::runtime_error("LibVGCode: Unable to link shader program:\n" + shader_name + "\n" + res + "\n");
276 }
277
278 glsafe(glDetachShader(shader_id, vs_id));
279 glsafe(glDetachShader(shader_id, fs_id));
280 glsafe(glDeleteShader(vs_id));
281 glsafe(glDeleteShader(fs_id));
282 return shader_id;
283}
#define glcheck()
Definition OpenGLUtils.hpp:26
#define glAttachShader
Definition gl.h:3253
#define GL_FRAGMENT_SHADER
Definition gl.h:701
#define glShaderSource
Definition gl.h:4769
#define glCreateShader
Definition gl.h:3545
#define glBindFragDataLocation
Definition gl.h:3277
#define glDeleteProgram
Definition gl.h:3571
unsigned int GLuint
Definition gl.h:2063
#define glDeleteShader
Definition gl.h:3583
#define GL_VERTEX_SHADER
Definition gl.h:2014
#define glCompileShader
Definition gl.h:3487
#define glCreateProgram
Definition gl.h:3535
#define glLinkProgram
Definition gl.h:4217
#define glDetachShader
Definition gl.h:3605
std::string check_shader(GLuint handle)
Definition ViewerImpl.cpp:208
std::string check_program(GLuint handle)
Definition ViewerImpl.cpp:221

Referenced by libvgcode::ViewerImpl::init().

Here is the caller graph for this function:

◆ inverse()

Mat4x4 libvgcode::inverse ( const Mat4x4 & m)
static
78{
79 // ref: https://stackoverflow.com/questions/1148309/inverting-a-4x4-matrix
80
81 Mat4x4 inv;
82
83 inv[0] = m[5] * m[10] * m[15] -
84 m[5] * m[11] * m[14] -
85 m[9] * m[6] * m[15] +
86 m[9] * m[7] * m[14] +
87 m[13] * m[6] * m[11] -
88 m[13] * m[7] * m[10];
89
90 inv[4] = -m[4] * m[10] * m[15] +
91 m[4] * m[11] * m[14] +
92 m[8] * m[6] * m[15] -
93 m[8] * m[7] * m[14] -
94 m[12] * m[6] * m[11] +
95 m[12] * m[7] * m[10];
96
97 inv[8] = m[4] * m[9] * m[15] -
98 m[4] * m[11] * m[13] -
99 m[8] * m[5] * m[15] +
100 m[8] * m[7] * m[13] +
101 m[12] * m[5] * m[11] -
102 m[12] * m[7] * m[9];
103
104 inv[12] = -m[4] * m[9] * m[14] +
105 m[4] * m[10] * m[13] +
106 m[8] * m[5] * m[14] -
107 m[8] * m[6] * m[13] -
108 m[12] * m[5] * m[10] +
109 m[12] * m[6] * m[9];
110
111 inv[1] = -m[1] * m[10] * m[15] +
112 m[1] * m[11] * m[14] +
113 m[9] * m[2] * m[15] -
114 m[9] * m[3] * m[14] -
115 m[13] * m[2] * m[11] +
116 m[13] * m[3] * m[10];
117
118 inv[5] = m[0] * m[10] * m[15] -
119 m[0] * m[11] * m[14] -
120 m[8] * m[2] * m[15] +
121 m[8] * m[3] * m[14] +
122 m[12] * m[2] * m[11] -
123 m[12] * m[3] * m[10];
124
125 inv[9] = -m[0] * m[9] * m[15] +
126 m[0] * m[11] * m[13] +
127 m[8] * m[1] * m[15] -
128 m[8] * m[3] * m[13] -
129 m[12] * m[1] * m[11] +
130 m[12] * m[3] * m[9];
131
132 inv[13] = m[0] * m[9] * m[14] -
133 m[0] * m[10] * m[13] -
134 m[8] * m[1] * m[14] +
135 m[8] * m[2] * m[13] +
136 m[12] * m[1] * m[10] -
137 m[12] * m[2] * m[9];
138
139 inv[2] = m[1] * m[6] * m[15] -
140 m[1] * m[7] * m[14] -
141 m[5] * m[2] * m[15] +
142 m[5] * m[3] * m[14] +
143 m[13] * m[2] * m[7] -
144 m[13] * m[3] * m[6];
145
146 inv[6] = -m[0] * m[6] * m[15] +
147 m[0] * m[7] * m[14] +
148 m[4] * m[2] * m[15] -
149 m[4] * m[3] * m[14] -
150 m[12] * m[2] * m[7] +
151 m[12] * m[3] * m[6];
152
153 inv[10] = m[0] * m[5] * m[15] -
154 m[0] * m[7] * m[13] -
155 m[4] * m[1] * m[15] +
156 m[4] * m[3] * m[13] +
157 m[12] * m[1] * m[7] -
158 m[12] * m[3] * m[5];
159
160 inv[14] = -m[0] * m[5] * m[14] +
161 m[0] * m[6] * m[13] +
162 m[4] * m[1] * m[14] -
163 m[4] * m[2] * m[13] -
164 m[12] * m[1] * m[6] +
165 m[12] * m[2] * m[5];
166
167 inv[3] = -m[1] * m[6] * m[11] +
168 m[1] * m[7] * m[10] +
169 m[5] * m[2] * m[11] -
170 m[5] * m[3] * m[10] -
171 m[9] * m[2] * m[7] +
172 m[9] * m[3] * m[6];
173
174 inv[7] = m[0] * m[6] * m[11] -
175 m[0] * m[7] * m[10] -
176 m[4] * m[2] * m[11] +
177 m[4] * m[3] * m[10] +
178 m[8] * m[2] * m[7] -
179 m[8] * m[3] * m[6];
180
181 inv[11] = -m[0] * m[5] * m[11] +
182 m[0] * m[7] * m[9] +
183 m[4] * m[1] * m[11] -
184 m[4] * m[3] * m[9] -
185 m[8] * m[1] * m[7] +
186 m[8] * m[3] * m[5];
187
188 inv[15] = m[0] * m[5] * m[10] -
189 m[0] * m[6] * m[9] -
190 m[4] * m[1] * m[10] +
191 m[4] * m[2] * m[9] +
192 m[8] * m[1] * m[6] -
193 m[8] * m[2] * m[5];
194
195 float det = m[0] * inv[0] + m[1] * inv[4] + m[2] * inv[8] + m[3] * inv[12];
196 assert(det != 0.0f);
197
198 det = 1.0f / det;
199
200 std::array<float, 16> ret = {};
201 for (int i = 0; i < 16; ++i) {
202 ret[i] = inv[i] * det;
203 }
204
205 return ret;
206}

Referenced by libvgcode::ViewerImpl::render(), and libvgcode::ViewerImpl::render_translucent().

Here is the caller graph for this function:

◆ is_colorprint_option()

bool libvgcode::is_colorprint_option ( const PathVertex & v)
static
21{
23}

References CustomGCode, PausePrint, and libvgcode::PathVertex::type.

Referenced by libvgcode::Layers::update().

Here is the caller graph for this function:

◆ is_joint()

bool libvgcode::is_joint ( const std::vector< PathVertex > & vertices,
size_t i )
static
1039{
1040 auto repeated = [&vertices](size_t j) {
1041 return j + 1 < vertices.size() && vertices[j + 1].position == vertices[j].position && vertices[j + 1].type == vertices[j].type;
1042 };
1043 const bool before = i > 0 && (is_line(vertices, i - 1) || (i > 1 && repeated(i - 1) && is_line(vertices, i - 2)));
1044 const bool after = is_line(vertices, i) || (repeated(i) && is_line(vertices, i + 1));
1045 return before && after;
1046}

References is_line().

Referenced by extract_pos_and_or_hwa().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_line()

bool libvgcode::is_line ( const std::vector< PathVertex > & vertices,
size_t i )
static
1031{
1032 return i + 1 < vertices.size() && vertices[i + 1].position != vertices[i].position &&
1033 vertices[i + 1].type == vertices[i].type && vertices[i].type != EMoveType::Seam;
1034}

References Seam.

Referenced by extract_pos_and_or_hwa(), and is_joint().

Here is the caller graph for this function:

◆ is_visible()

bool libvgcode::is_visible ( const PathVertex & v,
const Settings & settings )
static
2008{
2009 const EOptionType option_type = move_type_to_option(v.type);
2010 try
2011 {
2012 return (option_type == EOptionType::COUNT) ?
2013 (v.type == EMoveType::Extrude) ? settings.extrusion_roles_visibility[size_t(v.role)] : false :
2014 settings.options_visibility[size_t(option_type)];
2015 }
2016 catch (...)
2017 {
2018 return false;
2019 }
2020}
std::array< bool, std::size_t(EGCodeExtrusionRole::COUNT)> extrusion_roles_visibility
Definition Settings.hpp:58
EOptionType move_type_to_option(EMoveType type)
Definition Types.cpp:13
std::array< bool, std::size_t(EOptionType::COUNT)> options_visibility
Definition Settings.hpp:42
EOptionType
Definition Types.hpp:175
@ COUNT
Definition Types.hpp:191
EGCodeExtrusionRole role
Definition PathVertex.hpp:62

References COUNT, Extrude, libvgcode::Settings::extrusion_roles_visibility, move_type_to_option(), libvgcode::Settings::options_visibility, libvgcode::PathVertex::role, and libvgcode::PathVertex::type.

Referenced by libvgcode::ViewerImpl::update_view_full_range().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ length()

float libvgcode::length ( const Vec3 & v)
46{
47 return std::sqrt(dot(v, v));
48}

References dot().

Referenced by libvgcode::OpenGLWrapper::load_opengl(), and normalize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lerp() [1/2]

Color libvgcode::lerp ( const Color & c1,
const Color & c2,
float t )
extern
38{
39 t = std::clamp(t, 0.0f, 1.0f);
40 return { lerp(c1[0], c2[0], t), lerp(c1[1], c2[1], t), lerp(c1[2], c2[2], t) };
41}
Color lerp(const Color &c1, const Color &c2, float t)
Definition Types.cpp:37

References lerp().

Referenced by libvgcode::ColorRange::get_color_at(), and lerp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lerp() [2/2]

uint8_t libvgcode::lerp ( uint8_t f1,
uint8_t f2,
float t )
static
31{
32 const float one_minus_t = 1.0f - t;
33 return static_cast<uint8_t>(one_minus_t * static_cast<float>(f1) + t * static_cast<float>(f2));
34}

◆ move_type_to_option()

EOptionType libvgcode::move_type_to_option ( EMoveType type)
extern
14{
15 switch (type)
16 {
18 case EMoveType::Wipe: { return EOptionType::Wipes; }
21 case EMoveType::Seam: { return EOptionType::Seams; }
26 default: { return EOptionType::COUNT; }
27 }
28}

References ColorChange, ColorChanges, COUNT, CustomGCode, CustomGCodes, PausePrint, PausePrints, Retract, Retractions, Seam, Seams, ToolChange, ToolChanges, Travel, Travels, Unretract, Unretractions, Wipe, and Wipes.

Referenced by libvgcode::ViewerImpl::get_vertex_color(), is_visible(), libvgcode::ViewerImpl::load(), starts_path(), and libvgcode::ViewerImpl::update_enabled_entities().

Here is the caller graph for this function:

◆ normalize()

Vec3 libvgcode::normalize ( const Vec3 & v)
33{
34 const float length = std::sqrt(dot(v, v));
35 assert(length > 0.0f);
36 const float inv_length = 1.0f / length;
37 return { v[0] * inv_length, v[1] * inv_length, v[2] * inv_length };
38}
float length(const Vec3 &v)
Definition Utils.cpp:45

References dot(), and length().

Referenced by libvgcode::OptionTemplate::init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator!=()

bool libvgcode::operator!= ( const Vec3 & v1,
const Vec3 & v2 )
54 {
55 return v1[0] != v2[0] || v1[1] != v2[1] || v1[2] != v2[2];
56}

◆ operator*()

Vec3 libvgcode::operator* ( float f,
const Vec3 & v )
66 {
67 return { f * v[0], f * v[1], f * v[2] };
68}

◆ operator+()

Vec3 libvgcode::operator+ ( const Vec3 & v1,
const Vec3 & v2 )
58 {
59 return { v1[0] + v2[0], v1[1] + v2[1], v1[2] + v2[2] };
60}

◆ operator-()

Vec3 libvgcode::operator- ( const Vec3 & v1,
const Vec3 & v2 )
62 {
63 return { v1[0] - v2[0], v1[1] - v2[1], v1[2] - v2[2] };
64}

◆ operator==()

bool libvgcode::operator== ( const Vec3 & v1,
const Vec3 & v2 )
50 {
51 return v1[0] == v2[0] && v1[1] == v2[1] && v1[2] == v2[2];
52}

◆ round_to_bin()

float libvgcode::round_to_bin ( const float value)
static
60{
61// assert(value >= 0);
62 constexpr float const scale[5] = { 100.f, 1000.f, 10000.f, 100000.f, 1000000.f };
63 constexpr float const invscale[5] = { 0.01f, 0.001f, 0.0001f, 0.00001f, 0.000001f };
64 constexpr float const threshold[5] = { 0.095f, 0.0095f, 0.00095f, 0.000095f, 0.0000095f };
65 // Scaling factor, pointer to the tables above.
66 int i = 0;
67 // While the scaling factor is not yet large enough to get two integer digits after scaling and rounding:
68 for (; value < threshold[i] && i < 4; ++i);
69 // At least on MSVC std::round() calls a complex function, which is pretty expensive.
70 // our fast_round_up is much cheaper and it could be inlined.
71// return std::round(value * scale[i]) * invscale[i];
72 double a = value * scale[i];
73 assert(std::abs(a) < double(std::numeric_limits<int64_t>::max()));
74 return fast_round_up<int64_t>(a) * invscale[i];
75}
int scale(const int val)
Definition WipeTowerDialog.cpp:58
IntegerOnly< I, I > fast_round_up(double a)
Definition ViewerImpl.cpp:50

References fast_round_up(), and scale().

Referenced by libvgcode::ViewerImpl::update_color_ranges().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ starts_path()

bool libvgcode::starts_path ( const Slic3r::GCodeProcessorResult::MoveVertex & prev,
const Slic3r::GCodeProcessorResult::MoveVertex & curr,
bool first_move )
static
229{
230 const EOptionType option_type = move_type_to_option(convert(curr.type));
231 if (option_type != EOptionType::COUNT && option_type != EOptionType::Travels && option_type != EOptionType::Wipes)
232 return false;
233 return first_move || prev.type != curr.type || prev.extrusion_role != curr.extrusion_role
234 // ORCA: Split the path when a preview value changes.
235 || prev.mm3_per_mm != curr.mm3_per_mm || prev.acceleration != curr.acceleration || prev.jerk != curr.jerk;
236}

References Slic3r::GCodeProcessorResult::MoveVertex::acceleration, convert(), COUNT, Slic3r::GCodeProcessorResult::MoveVertex::extrusion_role, Slic3r::GCodeProcessorResult::MoveVertex::jerk, Slic3r::GCodeProcessorResult::MoveVertex::mm3_per_mm, move_type_to_option(), Travels, Slic3r::GCodeProcessorResult::MoveVertex::type, and Wipes.

Referenced by convert().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ with_define()

std::string libvgcode::with_define ( const char * source,
const char * define )
static
308{
309 const std::string src(source);
310 const size_t body = src.find('\n') + 1;
311 return src.substr(0, body) + "#define " + define + "\n" + src.substr(body);
312}

Referenced by libvgcode::ViewerImpl::init().

Here is the caller graph for this function:

Variable Documentation

◆ COLOR_RANGE_TYPES_COUNT

std::size_t libvgcode::COLOR_RANGE_TYPES_COUNT = static_cast<std::size_t>(EColorRangeType::COUNT)
staticconstexpr

◆ DEFAULT_EXTRUSION_ROLES_COLORS

const std::array<Color, size_t(EGCodeExtrusionRole::COUNT)> libvgcode::DEFAULT_EXTRUSION_ROLES_COLORS
static
Initial value:
= { {
{ 230, 179, 179 },
{ 255, 230, 77 },
{ 255, 125, 56 },
{ 31, 31, 255 },
{ 176, 48, 41 },
{ 150, 84, 204 },
{ 240, 64, 64 },
{ 255, 140, 105 },
{ 77, 128, 186 },
{ 255, 255, 255 },
{ 0, 135, 110 },
{ 0, 255, 0 },
{ 0, 128, 0 },
{ 179, 227, 171 },
{ 94, 209, 148 },
{ 102, 92, 199 },
{ 77, 128, 186 },
{ 0, 59, 110 },
{ 0, 64, 0 },
{ 128, 128, 128 },
} }
315 { {
316 { 230, 179, 179 }, // None
317 { 255, 230, 77 }, // Perimeter
318 { 255, 125, 56 }, // ExternalPerimeter
319 { 31, 31, 255 }, // OverhangPerimeter
320 { 176, 48, 41 }, // InternalInfill
321 { 150, 84, 204 }, // SolidInfill
322 { 240, 64, 64 }, // TopSolidInfill
323 { 255, 140, 105 }, // Ironing
324 { 77, 128, 186 }, // BridgeInfill
325 { 255, 255, 255 }, // GapFill
326 { 0, 135, 110 }, // Skirt
327 { 0, 255, 0 }, // SupportMaterial
328 { 0, 128, 0 }, // SupportMaterialInterface
329 { 179, 227, 171 }, // WipeTower
330 { 94, 209, 148 }, // Custom
331 // ORCA
332 { 102, 92, 199 }, // BottomSurface
333 { 77, 128, 186 }, // InternalBridgeInfill
334 { 0, 59, 110 }, // Brim
335 { 0, 64, 0 }, // SupportTransition
336 { 128, 128, 128 }, // Mixed
337} };

Referenced by libvgcode::ViewerImpl::reset_default_extrusion_roles_colors().

◆ DEFAULT_OPTIONS_COLORS

const std::array<Color, size_t(EOptionType::COUNT)> libvgcode::DEFAULT_OPTIONS_COLORS
static
Initial value:
{ {
{ 56, 72, 155 },
{ 255, 255, 0 },
{ 205, 34, 214 },
{ 73, 173, 207 },
{ 230, 230, 230 },
{ 193, 190, 99 },
{ 218, 148, 139 },
{ 82, 240, 131 },
{ 226, 210, 67 }
} }
339 { {
340 { 56, 72, 155 }, // Travels
341 { 255, 255, 0 }, // Wipes
342 { 205, 34, 214 }, // Retractions
343 { 73, 173, 207 }, // Unretractions
344 { 230, 230, 230 }, // Seams
345 { 193, 190, 99 }, // ToolChanges
346 { 218, 148, 139 }, // ColorChanges
347 { 82, 240, 131 }, // PausePrints
348 { 226, 210, 67 } // CustomGCodes
349} };

Referenced by libvgcode::ViewerImpl::reset_default_options_colors().

◆ DEFAULT_RANGES_COLORS

const Palette libvgcode::DEFAULT_RANGES_COLORS
static
Initial value:
{ {
{ 11, 44, 122 },
{ 19, 89, 133 },
{ 28, 136, 145 },
{ 4, 214, 15 },
{ 170, 242, 0 },
{ 252, 249, 3 },
{ 245, 206, 10 },
{ 227, 136, 32 },
{ 209, 104, 48 },
{ 194, 82, 60 },
{ 148, 38, 22 }
} }
17 { {
18 { 11, 44, 122 }, // bluish
19 { 19, 89, 133 },
20 { 28, 136, 145 },
21 { 4, 214, 15 },
22 { 170, 242, 0 },
23 { 252, 249, 3 },
24 { 245, 206, 10 },
25 { 227, 136, 32 },
26 { 209, 104, 48 },
27 { 194, 82, 60 },
28 { 148, 38, 22 } // reddish
29} };

Referenced by libvgcode::ColorRange::ColorRange().

◆ DEFAULT_TRAVELS_RADIUS_MM

float libvgcode::DEFAULT_TRAVELS_RADIUS_MM = 0.1f
staticconstexpr

◆ DEFAULT_WIPES_RADIUS_MM

float libvgcode::DEFAULT_WIPES_RADIUS_MM = 0.1f
staticconstexpr

◆ DUMMY_COLOR

◆ GCODE_EXTRUSION_ROLES_COUNT

std::size_t libvgcode::GCODE_EXTRUSION_ROLES_COUNT = static_cast<std::size_t>(EGCodeExtrusionRole::COUNT)
staticconstexpr

◆ INDEX_DATA

const std::array<uint16_t, 24> libvgcode::INDEX_DATA
staticconstexpr
Initial value:
= {
0, 1, 2,
0, 2, 3,
0, 3, 4,
0, 4, 5,
0, 5, 6,
0, 6, 1,
5, 4, 7,
5, 7, 6,
}
28 {
29 0, 1, 2, // front spike
30 0, 2, 3, // front spike
31 0, 3, 4, // right/bottom body
32 0, 4, 5, // right/bottom body
33 0, 5, 6, // left/top body
34 0, 6, 1, // left/top body
35 5, 4, 7, // back spike
36 5, 7, 6, // back spike
37};

Referenced by libvgcode::SegmentTemplate::init(), and libvgcode::SegmentTemplate::render().

◆ is_atomic

template<typename T>
auto constexpr libvgcode::is_atomic = false
constexpr

◆ is_atomic< std::atomic< T > >

template<typename T>
auto constexpr libvgcode::is_atomic< std::atomic< T > > = true
constexpr

◆ MAX_TRAVELS_RADIUS_MM

float libvgcode::MAX_TRAVELS_RADIUS_MM = 1.0f
staticconstexpr

◆ MAX_WIPES_RADIUS_MM

float libvgcode::MAX_WIPES_RADIUS_MM = 1.0f
staticconstexpr

◆ MIN_TRAVELS_RADIUS_MM

float libvgcode::MIN_TRAVELS_RADIUS_MM = 0.05f
staticconstexpr

◆ MIN_WIPES_RADIUS_MM

float libvgcode::MIN_WIPES_RADIUS_MM = 0.05f
staticconstexpr

◆ MOVE_TYPES_COUNT

std::size_t libvgcode::MOVE_TYPES_COUNT = static_cast<std::size_t>(EMoveType::COUNT)
staticconstexpr

◆ OPENGL_ES_PREFIXES

const char* libvgcode::OPENGL_ES_PREFIXES[] = { "OpenGL ES-CM ", "OpenGL ES-CL ", "OpenGL ES ", nullptr }
static
42{ "OpenGL ES-CM ", "OpenGL ES-CL ", "OpenGL ES ", nullptr };

Referenced by libvgcode::OpenGLWrapper::load_opengl().

◆ OPTION_TYPES_COUNT

std::size_t libvgcode::OPTION_TYPES_COUNT = static_cast<std::size_t>(EOptionType::COUNT)
staticconstexpr

◆ Options_Fragment_Shader

const char* libvgcode::Options_Fragment_Shader
static
Initial value:
=
"#version 150\n"
"in vec3 color;\n"
"in float clipping_plane_dot;\n"
"out vec4 fragment_color;\n"
"void main() {\n"
" if (clipping_plane_dot < 0.0)\n"
" discard;\n"
" fragment_color = vec4(color, 1.0);\n"
"}\n"

Referenced by libvgcode::ViewerImpl::init().

◆ Options_Fragment_Shader_ES

const char* libvgcode::Options_Fragment_Shader_ES
static
Initial value:
=
"#version 300 es\n"
"precision highp float;\n"
"in vec3 color;\n"
"in float clipping_plane_dot;\n"
"out vec4 fragment_color;\n"
"void main() {\n"
" if (clipping_plane_dot < 0.0)\n"
" discard;\n"
" fragment_color = vec4(color, 1.0);\n"
"}\n"

Referenced by libvgcode::ViewerImpl::init().

◆ Options_Vertex_Shader

const char* libvgcode::Options_Vertex_Shader
static

◆ Options_Vertex_Shader_ES

const char* libvgcode::Options_Vertex_Shader_ES
static

◆ PI

float libvgcode::PI = 3.141592f
staticconstexpr

◆ Segments_Fragment_Shader

const char* libvgcode::Segments_Fragment_Shader
static

◆ Segments_Fragment_Shader_ES

const char* libvgcode::Segments_Fragment_Shader_ES
static

◆ Segments_Shadow_Caster_Fragment_Shader

const char* libvgcode::Segments_Shadow_Caster_Fragment_Shader
static
Initial value:
=
"#version 150\n"
"uniform vec4 clipping_plane;\n"
"in vec3 world_position;\n"
"flat in float alpha;\n"
"flat in int segment_id;\n"
"const float BAYER[16] = float[](0.0, 8.0, 2.0, 10.0, 12.0, 4.0, 14.0, 6.0, 3.0, 11.0, 1.0, 9.0, 15.0, 7.0, 13.0, 5.0);\n"
"void main() {\n"
" if (dot(vec4(world_position, 1.0), clipping_plane) < 0.0)\n"
" discard;\n"
" ivec2 cell = (ivec2(gl_FragCoord.xy) + ivec2(segment_id, segment_id >> 2)) & 3;\n"
" if (alpha < 1.0 && (BAYER[4 * cell.y + cell.x] + 0.5) / 16.0 > alpha)\n"
" discard;\n"
"}\n"

Referenced by libvgcode::ViewerImpl::init().

◆ Segments_Shadow_Caster_Fragment_Shader_ES

const char* libvgcode::Segments_Shadow_Caster_Fragment_Shader_ES
static
Initial value:
=
"#version 300 es\n"
"precision highp float;\n"
"precision highp int;\n"
"uniform vec4 clipping_plane;\n"
"in vec3 world_position;\n"
"flat in float alpha;\n"
"flat in int segment_id;\n"
"const float BAYER[16] = float[](0.0, 8.0, 2.0, 10.0, 12.0, 4.0, 14.0, 6.0, 3.0, 11.0, 1.0, 9.0, 15.0, 7.0, 13.0, 5.0);\n"
"void main() {\n"
" if (dot(vec4(world_position, 1.0), clipping_plane) < 0.0)\n"
" discard;\n"
" ivec2 cell = (ivec2(gl_FragCoord.xy) + ivec2(segment_id, segment_id >> 2)) & 3;\n"
" if (alpha < 1.0 && (BAYER[4 * cell.y + cell.x] + 0.5) / 16.0 > alpha)\n"
" discard;\n"
"}\n"

Referenced by libvgcode::ViewerImpl::init().

◆ Segments_Shadow_Caster_Vertex_Shader

const char* libvgcode::Segments_Shadow_Caster_Vertex_Shader
static

◆ Segments_Shadow_Caster_Vertex_Shader_ES

const char* libvgcode::Segments_Shadow_Caster_Vertex_Shader_ES
static

◆ Segments_Vertex_Shader

const char* libvgcode::Segments_Vertex_Shader
static

◆ Segments_Vertex_Shader_ES

const char* libvgcode::Segments_Vertex_Shader_ES
static

◆ TIME_MODES_COUNT

◆ Translucent_Composite_Fragment_Shader

const char* libvgcode::Translucent_Composite_Fragment_Shader
static
Initial value:
=
"#version 150\n"
"uniform sampler2D accum_tex;\n"
"uniform sampler2D reveal_tex;\n"
"uniform sampler2D front_tex;\n"
"uniform ivec2 origin;\n"
"out vec4 fragment_color;\n"
"void main() {\n"
" ivec2 coord = ivec2(gl_FragCoord.xy) - origin;\n"
" vec4 front = texelFetch(front_tex, coord, 0);\n"
" vec4 accum = texelFetch(accum_tex, coord, 0);\n"
" if (front.a <= 0.0 && accum.a <= 0.0)\n"
" discard;\n"
" float coverage = accum.a > 0.0 ? 1.0 - exp(-texelFetch(reveal_tex, coord, 0).r) : 0.0;\n"
" vec3 behind = accum.a > 0.0 ? accum.rgb / accum.a * coverage : vec3(0.0);\n"
" float front_alpha = min(front.a, 1.0);\n"
" fragment_color = vec4(front.rgb + (1.0 - front_alpha) * behind, 1.0 - (1.0 - front_alpha) * (1.0 - coverage));\n"
"}\n"

Referenced by libvgcode::ViewerImpl::init().

◆ Translucent_Composite_Vertex_Shader

const char* libvgcode::Translucent_Composite_Vertex_Shader
static
Initial value:
=
"#version 150\n"
"void main() {\n"
" vec2 corner = vec2((gl_VertexID << 1) & 2, gl_VertexID & 2);\n"
" gl_Position = vec4(2.0 * corner - 1.0, 0.0, 1.0);\n"
"}\n"

Referenced by libvgcode::ViewerImpl::init().

◆ TRANSLUCENT_TEXTURE_UNIT

int libvgcode::TRANSLUCENT_TEXTURE_UNIT = 5
staticconstexpr

◆ VERTEX_DATA

const std::array<uint32_t, 8> libvgcode::VERTEX_DATA = { 0, 1, 2, 3, 4, 5, 6, 7 }
staticconstexpr
24{ 0, 1, 2, 3, 4, 5, 6, 7 };

Referenced by libvgcode::SegmentTemplate::init().

◆ VIEW_TYPES_COUNT

std::size_t libvgcode::VIEW_TYPES_COUNT = static_cast<std::size_t>(EViewType::COUNT)
staticconstexpr