mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-14 09:02:06 +00:00
Port libvgcode from PrusaSlicer 2.8.0
Includes (but is not limited to) the following commits: SPE-2218 - libvgcode - Fixed color of wipe moves for speed range view SPE-2218 - libvgcode - Fixed detection of fan speed range SPE-2218 - libvgcode - Fixed detection of temperature range SPE-2218 - libvgcode - Fixed colors for Actual volumetric flow rate view SPE-2214 - Fixed detection of toolpaths bounding box in GCodeViewer SPE-2206 - Modified LibBGCode.cmake to get latest version of libbgcode which fixed parsing of gcode lines G4 libvgcode - Fixed potential out of bound access in ViewerImpl::update_view_full_range() Tech ENABLE_GL_CORE_PROFILE set as default Tech ENABLE_OPENGL_ES replaced by build option SLIC3R_OPENGL_ES libvgcode - Precompiler definition of ENABLE_OPENGL_ES moved into CMakeLists.txt Added missing include libvgcode - Textures setup modified to work when building using emscripten libvgcode - small optimization libvgcode - fixed OpenGLWrapper::unload_opengl() libvgcode - CMakeLists.txt modified to work with emscripten libvgcode - Replace 'glVertexAttribIPointer()' with 'glVertexAttribPointer()' in SegmentTemplate::init() for OpenGL ES libvgcode - Replace 'xor' with '^' Bitset.hpp libvgcode - Newer glad library for OpenGL 4.6 and OpenGL ES 3.0 libvgcode - Alternate fix in method ViewerImpl::update_heights_widths() for OpenGL ES libvgcode - Fixes in glAssertRecentCallImpl() libvgcode - Fixes in method ViewerImpl::update_heights_widths() for OpenGL ES Fixed ES shaders so they work with OpenGL ES 3.0 libvgcode - Use multiple plain textures in place of texture buffers for OpenGL ES libvgcode - Use plain textures in place of texture buffers for OpenGL ES (partial implementation using one texture per buffer) libvgcode - refactoring of class OpenGLWrapper libvgcode - small refactoring in shaders libvgcode - replacement of glMapBuffer() call for OpenGL ES Fixed warning libvgcode - Changes into CMakeLists.txt Fixed debug export of gcode data to be configuration indipendent Disabled tech ENABLE_NEW_GCODE_VIEWER_DEBUG Removed obsolete tech ENABLE_GCODE_VIEWER_DATA_CHECKING Code cleanup and techs removal - completed Code cleanup and techs removal - step 1 SPE-1872: Implemented G2/G3 lines discretization for gcfMarlinFirmware firmware flavour SPE-1872: Corrections into GCodeProcessor::process_G2_G3() to match firmware code SPE-1872: Actual speed profile - Further enhancements of imgui debug window SPE-1872: Actual speed profile - Rework in its calculation + enhanced imgui debug window SPE-1872: New imgui widget to show actual speed profile SPE-1872: Fixed actual speed for seam moves and at extrusion/travel/wipe start SPE-1872: Fixed rendering of wipe moves when actual speed view is selected SPE-1872: Actual speed profile extended to travel and wipe moves SPE-1872: Fixes in function recalculate_trapezoids() and method GCodeProcessor::TimeMachine::calculate_time() to smooth actual speed profile SPE-1872: Added debug graphic to show move actual speed profile SPE-1872: libvgcode library: replace volumetric flow rate data with mm3_per_mm to reduce memory usage SPE-1872: Added visualization of actual volumetric flow rate SPE-1872: Fixes in calculating actual speed SPE-1872: Added visualization of actual speed in gcode preview SPE-2124: Added command line option 'opengl-aa' to allow the user to turn on the automatic selection of max number of supported samples for OpenGL antialising #12117: Reduced moire patterns by using the highest number of samples available for multisampling New gcode visualization integration - Partially enabled imgui debug window New gcode visualization integration - Fixed center of gravity calculation and rendering New gcode visualization library - Interface for estimated times New gcode visualization library - Tool marker rendering New gcode visualization library - Axes aligned bounding boxes calculation Removed obsolete debug code New gcode visualization library - Added statistic of used memory New gcode visualization library - Separation of tool colors and color changes colors to simplify client code Added missing include New gcode visualization library - Added print color changes detection New gcode visualization library - Modified OpenGL ES context detection New gcode visualization library - Another makefile cleanup New gcode visualization library - Makefiles cleanup New gcode visualization library - Added suppression of error 'This function or variable may be unsafe' in VS2022 New gcode visualization library - Compatibility with OpenGL ES New gcode visualization library - Interface cleanup and documentation New gcode visualization library - Extended interface to give access to estimated times New gcode visualization integration - Toggling of top layer only view state New gcode visualization integration - Removed imperial units from tool position data Small refactoring New gcode visualization library - Custom values for travel and wipe moves radius New gcode visualization library - Allow customization of range colors New gcode visualization library - Partial update of interface comments/documentation New gcode visualization integration - Follow-up of 35ee55e29bb231fd01a2eb71ae293832a37ca65d - Better fix for toolpaths visible range when toggling options' visibility New gcode visualization integration - Fixed toolpaths reset New gcode visualization library - Fixed method set_option_color() New gcode visualization library - Fixed method ViewerImpl::set_extrusion_role_color() New gcode visualization library - Added methods to release gpu resources on demand. New gcode visualization library - Travel and wipe moves as options New gcode visualization integration - Fixed toolpaths visible range when toggling options' visibility New gcode visualization integration - Fixed management of gcode preview view type New gcode visualization - Fixed wrong include New gcode visualization - Added missing headers New gcode visualization - Refactoring + added missing headers New gcode visualization - New code set as standalone library + embed glad library to load OpenGL functions New gcode visualization - Fixed errors and warnings when building the new code as a standalone library New gcode visualization integration - Fixed layers ordering in pre-gcode preview New gcode visualization integration - Fixed objects' tool colors in pre-gcode preview Code cleanup New gcode visualization integration - Tool position properties data window New gcode visualization integration - Fixed in export toolpaths to obj New gcode visualization - Inlining in source code Refactoring New gcode visualization integration - Export toolpaths to obj Some refactoring and warning fix New gcode visualization integration - Customizable travel moves colors New gcode visualization integration - Customizable options colors New gcode visualization integration - Customizable extrusion roles colors New gcode visualization integration - Fixed pre-gcode preview layers times New gcode visualization integration - Modify pre-gcode preview to use the new toolpaths renderer, objects WIP New gcode visualization - Modify pre-gcode preview to use the new toolpaths renderer, WIP (brim/skirt/wipe tower) New gcode visualization integration - Do not reset visible range when toggling options/roles visibility New gcode visualization - Fixed color of first vertex of top layer (when top layer only option is enabled) New gcode visualization - Customizable travels and wipes segment radius New gcode visualization integration - Removed tech ENABLE_GCODE_VIEWER_STATISTICS New gcode visualization integration - Added check of OpenGL version New gcode visualization integration - Removed GCodeProcessorResult::spiral_vase_layers Another bunch of warnings fixes Fixed warnings New gcode visualization integration - Removal of old visualization Fixed includes New gcode visualization integration - File structure of new code separated in api + src New gcode visualization integration - View ranges management moved to new visualizer New gcode visualization integration - Fixed top layer only visualization for MMU printers New gcode visualization integration - Removed dependency on imgui from new visualizer Some refactoring New gcode visualization integration - Removed dependency on Slic3r::GCodeProcessorResult from new visualizer New gcode visualization integration - Moves' data conversion moved to client side New gcode visualization: layers times refactoring A bunch of fixes for the new gcode visualization New gcode visualization: render in gray color layers containing pause print or custom gcode options when in Color Print view New gcode visualization integration - Tool colors New gcode visualization integration - Layers times New gcode visualization integration - Travels and Extrusion roles times Fixed detection of start/end of contiguous extrusion paths New gcode visualization integration - Extrusion roles New gcode visualization integration - Colors New gcode visualization integration - Tool position Center of gravity and tool marker may both be rendered with fixed screen size and a scaling factor Fixed rendering of options in new gcode visualization Tool marker NOT rendered by the new visualization code Center of gravity marker NOT rendered by the new visualization code Fixed toolpaths_cog shaders Tool position window for new gcode visualization Top layer only coloring for neww gcode visualization Refactoring in preview's new visualization Hidden imgui debug dialog for new visualization in preview Synchronization of moves between old and new visualization Fixed missing gcode window in new visualization Rendering of debug imgui dialog moved from class libvgcode::Viewer to class libvgcode::Toolpaths + warnings fixing Some functionality moved from class libvgcode::Viewer to class libvgcode::Toolpaths Some refactoring and cleanup Refatoring of PathVertex and Toolpaths::load() SPE-1982: Tech ENABLE_NEW_GCODE_VIEWER - 1st installment of new toolpaths rendering code (WIP)
This commit is contained in:
22
src/libvgcode/include/ColorPrint.hpp
Normal file
22
src/libvgcode/include/ColorPrint.hpp
Normal file
@@ -0,0 +1,22 @@
|
||||
///|/ Copyright (c) Prusa Research 2023 Enrico Turri @enricoturri1966, Pavel Mikuš @Godrak
|
||||
///|/
|
||||
///|/ libvgcode is released under the terms of the AGPLv3 or higher
|
||||
///|/
|
||||
#ifndef VGCODE_COLORPRINT_HPP
|
||||
#define VGCODE_COLORPRINT_HPP
|
||||
|
||||
#include "../include/Types.hpp"
|
||||
|
||||
namespace libvgcode {
|
||||
|
||||
struct ColorPrint
|
||||
{
|
||||
uint8_t extruder_id{ 0 };
|
||||
uint8_t color_id{ 0 };
|
||||
uint32_t layer_id{ 0 };
|
||||
std::array<float, TIME_MODES_COUNT> times{ 0.0f, 0.0f };
|
||||
};
|
||||
|
||||
} // namespace libvgcode
|
||||
|
||||
#endif // VGCODE_COLORPRINT_HPP
|
||||
107
src/libvgcode/include/ColorRange.hpp
Normal file
107
src/libvgcode/include/ColorRange.hpp
Normal file
@@ -0,0 +1,107 @@
|
||||
///|/ Copyright (c) Prusa Research 2023 Enrico Turri @enricoturri1966, Pavel Mikuš @Godrak
|
||||
///|/
|
||||
///|/ libvgcode is released under the terms of the AGPLv3 or higher
|
||||
///|/
|
||||
#ifndef VGCODE_COLORRANGE_HPP
|
||||
#define VGCODE_COLORRANGE_HPP
|
||||
|
||||
#include "../include/Types.hpp"
|
||||
|
||||
#include <cfloat>
|
||||
|
||||
namespace libvgcode {
|
||||
|
||||
static const Palette DEFAULT_RANGES_COLORS{ {
|
||||
{ 11, 44, 122 }, // bluish
|
||||
{ 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 } // reddish
|
||||
} };
|
||||
|
||||
class ColorRange
|
||||
{
|
||||
public:
|
||||
//
|
||||
// Constructor
|
||||
//
|
||||
explicit ColorRange(EColorRangeType type = EColorRangeType::Linear);
|
||||
//
|
||||
// Return the type of this ColorRange.
|
||||
//
|
||||
EColorRangeType get_type() const;
|
||||
//
|
||||
// Return the palette used by this ColorRange.
|
||||
// Default is DEFAULT_RANGES_COLORS
|
||||
//
|
||||
const Palette& get_palette() const;
|
||||
//
|
||||
// Set the palette to be used by this ColorRange.
|
||||
// The given palette must contain at least two colors.
|
||||
//
|
||||
void set_palette(const Palette& palette);
|
||||
//
|
||||
// Return the interpolated color at the given value.
|
||||
// Value is clamped to [get_range()[0]..get_range()[1]].
|
||||
//
|
||||
Color get_color_at(float value) const;
|
||||
//
|
||||
// Return the range of this ColorRange.
|
||||
// The range is detected during the call to Viewer::load().
|
||||
// [0] -> min
|
||||
// [1] -> max
|
||||
//
|
||||
const std::array<float, 2>& get_range() const;
|
||||
//
|
||||
// Return the values corresponding to the detected color bins of this ColorRange.
|
||||
// The size of the returned vector can be:
|
||||
// 1 - If only one value was detected while setting up this ColorRange.
|
||||
// 2 - If only two values were detected while setting up this ColorRange.
|
||||
// get_palette().size() - If more than two distinct values were detected while setting up this ColorRange.
|
||||
//
|
||||
std::vector<float> get_values() const;
|
||||
//
|
||||
// Return the size of the palette, in bytes
|
||||
//
|
||||
std::size_t size_in_bytes_cpu() const;
|
||||
|
||||
static const ColorRange DUMMY_COLOR_RANGE;
|
||||
|
||||
private:
|
||||
EColorRangeType m_type{ EColorRangeType::Linear };
|
||||
//
|
||||
// The palette used by this ColorRange
|
||||
//
|
||||
Palette m_palette;
|
||||
//
|
||||
// [0] = min
|
||||
// [1] = max
|
||||
//
|
||||
std::array<float, 2> m_range{ FLT_MAX, -FLT_MAX };
|
||||
//
|
||||
// Count of different values passed to update()
|
||||
//
|
||||
std::size_t m_count{ 0 };
|
||||
|
||||
//
|
||||
// Use the passed value to update the range.
|
||||
//
|
||||
void update(float value);
|
||||
//
|
||||
// Reset the range
|
||||
// Call this method before reuse an instance of ColorRange.
|
||||
//
|
||||
void reset();
|
||||
|
||||
friend class ViewerImpl;
|
||||
};
|
||||
|
||||
} // namespace libvgcode
|
||||
|
||||
#endif // VGCODE_COLORRANGE_HPP
|
||||
36
src/libvgcode/include/GCodeInputData.hpp
Normal file
36
src/libvgcode/include/GCodeInputData.hpp
Normal file
@@ -0,0 +1,36 @@
|
||||
///|/ Copyright (c) Prusa Research 2023 Enrico Turri @enricoturri1966
|
||||
///|/
|
||||
///|/ libvgcode is released under the terms of the AGPLv3 or higher
|
||||
///|/
|
||||
#ifndef VGCODE_GCODEINPUTDATA_HPP
|
||||
#define VGCODE_GCODEINPUTDATA_HPP
|
||||
|
||||
#include "PathVertex.hpp"
|
||||
|
||||
namespace libvgcode {
|
||||
|
||||
struct GCodeInputData
|
||||
{
|
||||
//
|
||||
// Whether or not the gcode was generated with spiral vase mode enabled.
|
||||
// Required to properly detect fictitious layer changes when spiral vase mode is enabled.
|
||||
//
|
||||
bool spiral_vase_mode{ false };
|
||||
//
|
||||
// List of path vertices (gcode moves)
|
||||
// See: PathVertex
|
||||
//
|
||||
std::vector<PathVertex> vertices;
|
||||
//
|
||||
// Palette for extruders colors
|
||||
//
|
||||
Palette tools_colors;
|
||||
//
|
||||
// Palette for color print colors
|
||||
//
|
||||
Palette color_print_colors;
|
||||
};
|
||||
|
||||
} // namespace libvgcode
|
||||
|
||||
#endif // VGCODE_BITSET_HPP
|
||||
121
src/libvgcode/include/PathVertex.hpp
Normal file
121
src/libvgcode/include/PathVertex.hpp
Normal file
@@ -0,0 +1,121 @@
|
||||
///|/ Copyright (c) Prusa Research 2023 Enrico Turri @enricoturri1966, Pavel Mikuš @Godrak
|
||||
///|/
|
||||
///|/ libvgcode is released under the terms of the AGPLv3 or higher
|
||||
///|/
|
||||
#ifndef VGCODE_PATHVERTEX_HPP
|
||||
#define VGCODE_PATHVERTEX_HPP
|
||||
|
||||
#include "Types.hpp"
|
||||
|
||||
#include <cfloat>
|
||||
|
||||
namespace libvgcode {
|
||||
|
||||
//
|
||||
// Struct representating a gcode move (toolpath segment)
|
||||
//
|
||||
struct PathVertex
|
||||
{
|
||||
//
|
||||
// Segment end position
|
||||
//
|
||||
Vec3 position{ FLT_MAX, FLT_MAX, FLT_MAX };
|
||||
//
|
||||
// Segment height
|
||||
//
|
||||
float height{ 0.0f };
|
||||
//
|
||||
// Segment width
|
||||
//
|
||||
float width{ 0.0f };
|
||||
//
|
||||
// Segment speed
|
||||
//
|
||||
float feedrate{ 0.0f };
|
||||
//
|
||||
// Segment actual speed
|
||||
//
|
||||
float actual_feedrate{ 0.0f };
|
||||
//
|
||||
// Segment mm3_per_mm
|
||||
//
|
||||
float mm3_per_mm{ 0.0f };
|
||||
//
|
||||
// Segment fan speed
|
||||
//
|
||||
float fan_speed{ 0.0f };
|
||||
//
|
||||
// Segment temperature
|
||||
//
|
||||
float temperature{ 0.0f };
|
||||
#if VGCODE_ENABLE_COG_AND_TOOL_MARKERS
|
||||
//
|
||||
// Segment weight
|
||||
//
|
||||
float weight{ 0.0f };
|
||||
#endif // VGCODE_ENABLE_COG_AND_TOOL_MARKERS
|
||||
//
|
||||
// Segment extrusion role
|
||||
//
|
||||
EGCodeExtrusionRole role{ EGCodeExtrusionRole::None };
|
||||
//
|
||||
// Segment move type
|
||||
//
|
||||
EMoveType type{ EMoveType::Noop };
|
||||
//
|
||||
// Segment gcode line id
|
||||
//
|
||||
uint32_t gcode_id{ 0 };
|
||||
//
|
||||
// Segment layer id
|
||||
//
|
||||
uint32_t layer_id{ 0 };
|
||||
//
|
||||
// Segment extruder id
|
||||
//
|
||||
uint8_t extruder_id{ 0 };
|
||||
//
|
||||
// Segment color id
|
||||
//
|
||||
uint8_t color_id{ 0 };
|
||||
//
|
||||
// Segment estimated times
|
||||
//
|
||||
std::array<float, TIME_MODES_COUNT> times{ 0.0f, 0.0f };
|
||||
|
||||
//
|
||||
// Return true if the segment is an extrusion move
|
||||
//
|
||||
bool is_extrusion() const;
|
||||
//
|
||||
// Return true if the segment is an travel move
|
||||
//
|
||||
bool is_travel() const;
|
||||
//
|
||||
// Return true if the segment is an option
|
||||
// See: EOptionType
|
||||
//
|
||||
bool is_option() const;
|
||||
//
|
||||
// Return true if the segment is a wipe move
|
||||
//
|
||||
bool is_wipe() const;
|
||||
//
|
||||
// Return true if the segment was generated by custom gcode
|
||||
//
|
||||
bool is_custom_gcode() const;
|
||||
//
|
||||
// Return the volumetric flow rate of the segment
|
||||
//
|
||||
float volumetric_rate() const { return feedrate * mm3_per_mm; }
|
||||
//
|
||||
// Return the acutal volumetric flow rate of the segment
|
||||
//
|
||||
float actual_volumetric_rate() const { return actual_feedrate * mm3_per_mm; }
|
||||
|
||||
static const PathVertex DUMMY_PATH_VERTEX;
|
||||
};
|
||||
|
||||
} // namespace libvgcode
|
||||
|
||||
#endif // VGCODE_PATHVERTEX_HPP
|
||||
218
src/libvgcode/include/Types.hpp
Normal file
218
src/libvgcode/include/Types.hpp
Normal file
@@ -0,0 +1,218 @@
|
||||
///|/ Copyright (c) Prusa Research 2023 Enrico Turri @enricoturri1966, Pavel Mikuš @Godrak
|
||||
///|/
|
||||
///|/ libvgcode is released under the terms of the AGPLv3 or higher
|
||||
///|/
|
||||
#ifndef VGCODE_TYPES_HPP
|
||||
#define VGCODE_TYPES_HPP
|
||||
|
||||
#define VGCODE_ENABLE_COG_AND_TOOL_MARKERS 0
|
||||
|
||||
#include <array>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
|
||||
namespace libvgcode {
|
||||
|
||||
static constexpr float PI = 3.141592f;
|
||||
|
||||
//
|
||||
// Predefined values for the radius, in mm, of the cylinders used to render the travel moves.
|
||||
//
|
||||
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;
|
||||
|
||||
//
|
||||
// Predefined values for the radius, in mm, of the cylinders used to render the wipe moves.
|
||||
//
|
||||
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;
|
||||
|
||||
//
|
||||
// Vector in 3 dimensions
|
||||
// [0] -> x
|
||||
// [1] -> y
|
||||
// [2] -> z
|
||||
// Used for positions, displacements and so on.
|
||||
//
|
||||
using Vec3 = std::array<float, 3>;
|
||||
|
||||
//
|
||||
// 4x4 square matrix with elements in column-major order:
|
||||
// | a[0] a[4] a[8] a[12] |
|
||||
// | a[1] a[5] a[9] a[13] |
|
||||
// | a[2] a[6] a[10] a[14] |
|
||||
// | a[3] a[7] a[11] a[15] |
|
||||
//
|
||||
using Mat4x4 = std::array<float, 16>;
|
||||
|
||||
//
|
||||
// RGB color
|
||||
// [0] -> red
|
||||
// [1] -> green
|
||||
// [2] -> blue
|
||||
//
|
||||
using Color = std::array<uint8_t, 3>;
|
||||
|
||||
//
|
||||
// Color palette
|
||||
//
|
||||
using Palette = std::vector<Color>;
|
||||
|
||||
//
|
||||
// Axis aligned box in 3 dimensions
|
||||
// [0] -> { min_x, min_y, min_z }
|
||||
// [1] -> { max_x, max_y, max_z }
|
||||
//
|
||||
using AABox = std::array<Vec3, 2>;
|
||||
|
||||
//
|
||||
// One dimensional natural numbers interval
|
||||
// [0] -> min
|
||||
// [1] -> max
|
||||
//
|
||||
using Interval = std::array<std::size_t, 2>;
|
||||
|
||||
//
|
||||
// View types
|
||||
//
|
||||
enum class EViewType : uint8_t
|
||||
{
|
||||
FeatureType,
|
||||
Height,
|
||||
Width,
|
||||
Speed,
|
||||
ActualSpeed,
|
||||
FanSpeed,
|
||||
Temperature,
|
||||
VolumetricFlowRate,
|
||||
ActualVolumetricFlowRate,
|
||||
LayerTimeLinear,
|
||||
LayerTimeLogarithmic,
|
||||
Tool,
|
||||
ColorPrint,
|
||||
COUNT
|
||||
};
|
||||
|
||||
static constexpr std::size_t VIEW_TYPES_COUNT = static_cast<std::size_t>(EViewType::COUNT);
|
||||
|
||||
//
|
||||
// Move types
|
||||
//
|
||||
enum class EMoveType : uint8_t
|
||||
{
|
||||
Noop,
|
||||
Retract,
|
||||
Unretract,
|
||||
Seam,
|
||||
ToolChange,
|
||||
ColorChange,
|
||||
PausePrint,
|
||||
CustomGCode,
|
||||
Travel,
|
||||
Wipe,
|
||||
Extrude,
|
||||
COUNT
|
||||
};
|
||||
|
||||
static constexpr std::size_t MOVE_TYPES_COUNT = static_cast<std::size_t>(EMoveType::COUNT);
|
||||
|
||||
//
|
||||
// Extrusion roles
|
||||
//
|
||||
enum class EGCodeExtrusionRole : uint8_t
|
||||
{
|
||||
// This enum is used as in index into extrusion_roles_visibility.
|
||||
// Better only add things to the end.
|
||||
None,
|
||||
Perimeter,
|
||||
ExternalPerimeter,
|
||||
OverhangPerimeter,
|
||||
InternalInfill,
|
||||
SolidInfill,
|
||||
TopSolidInfill,
|
||||
Ironing,
|
||||
BridgeInfill,
|
||||
GapFill,
|
||||
Skirt,
|
||||
SupportMaterial,
|
||||
SupportMaterialInterface,
|
||||
WipeTower,
|
||||
Custom,
|
||||
COUNT
|
||||
};
|
||||
|
||||
static constexpr std::size_t GCODE_EXTRUSION_ROLES_COUNT = static_cast<std::size_t>(EGCodeExtrusionRole::COUNT);
|
||||
|
||||
//
|
||||
// Option types
|
||||
//
|
||||
enum class EOptionType : uint8_t
|
||||
{
|
||||
// This enum is used as in index into options_visibility.
|
||||
// Better only add things to the end.
|
||||
Travels,
|
||||
Wipes,
|
||||
Retractions,
|
||||
Unretractions,
|
||||
Seams,
|
||||
ToolChanges,
|
||||
ColorChanges,
|
||||
PausePrints,
|
||||
CustomGCodes,
|
||||
#if VGCODE_ENABLE_COG_AND_TOOL_MARKERS
|
||||
CenterOfGravity,
|
||||
ToolMarker,
|
||||
#endif // VGCODE_ENABLE_COG_AND_TOOL_MARKERS
|
||||
COUNT
|
||||
};
|
||||
|
||||
static constexpr std::size_t OPTION_TYPES_COUNT = static_cast<std::size_t>(EOptionType::COUNT);
|
||||
|
||||
//
|
||||
// Time modes
|
||||
//
|
||||
enum class ETimeMode : uint8_t
|
||||
{
|
||||
Normal,
|
||||
Stealth,
|
||||
COUNT
|
||||
};
|
||||
|
||||
static constexpr std::size_t TIME_MODES_COUNT = static_cast<std::size_t>(ETimeMode::COUNT);
|
||||
|
||||
//
|
||||
// Color range types
|
||||
//
|
||||
enum class EColorRangeType : uint8_t
|
||||
{
|
||||
Linear,
|
||||
Logarithmic,
|
||||
COUNT
|
||||
};
|
||||
|
||||
static constexpr std::size_t COLOR_RANGE_TYPES_COUNT = static_cast<std::size_t>(EColorRangeType::COUNT);
|
||||
|
||||
//
|
||||
// Predefined colors
|
||||
//
|
||||
static const Color DUMMY_COLOR{ 64, 64, 64 };
|
||||
|
||||
//
|
||||
// Mapping from EMoveType to EOptionType
|
||||
// Returns EOptionType::COUNT if the given move type does not correspond
|
||||
// to any option type.
|
||||
//
|
||||
extern EOptionType move_type_to_option(EMoveType type);
|
||||
|
||||
//
|
||||
// Returns the linear interpolation between the two given colors
|
||||
// at the given t.
|
||||
// t is clamped in the range [0..1]
|
||||
//
|
||||
extern Color lerp(const Color& c1, const Color& c2, float t);
|
||||
|
||||
} // namespace libvgcode
|
||||
|
||||
#endif // VGCODE_TYPES_HPP
|
||||
419
src/libvgcode/include/Viewer.hpp
Normal file
419
src/libvgcode/include/Viewer.hpp
Normal file
@@ -0,0 +1,419 @@
|
||||
///|/ Copyright (c) Prusa Research 2023 Enrico Turri @enricoturri1966, Pavel Mikuš @Godrak
|
||||
///|/
|
||||
///|/ libvgcode is released under the terms of the AGPLv3 or higher
|
||||
///|/
|
||||
#ifndef VGCODE_VIEWER_HPP
|
||||
#define VGCODE_VIEWER_HPP
|
||||
|
||||
#include "Types.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace libvgcode {
|
||||
|
||||
class ViewerImpl;
|
||||
struct GCodeInputData;
|
||||
struct PathVertex;
|
||||
class ColorRange;
|
||||
struct ColorPrint;
|
||||
|
||||
class Viewer
|
||||
{
|
||||
public:
|
||||
Viewer();
|
||||
~Viewer();
|
||||
Viewer(const Viewer& other) = delete;
|
||||
Viewer(Viewer&& other) = delete;
|
||||
Viewer& operator = (const Viewer& other) = delete;
|
||||
Viewer& operator = (Viewer&& other) = delete;
|
||||
|
||||
//
|
||||
// Initialize the viewer.
|
||||
// Param opengl_context_version must be the string returned by glGetString(GL_VERSION).
|
||||
// This method must be called after a valid OpenGL context has been already created
|
||||
// and before calling any other method of the viewer.
|
||||
// Throws an std::runtime_error exception if:
|
||||
// * the method is called before creating an OpenGL context
|
||||
// * the created OpenGL context does not support OpenGL 3.2 or greater
|
||||
// * when using OpenGL ES, the created OpenGL ES context does not support OpenGL ES 2.0 or greater
|
||||
// * any of the shaders fails to compile
|
||||
//
|
||||
void init(const std::string& opengl_context_version);
|
||||
//
|
||||
// Release the resources used by the viewer.
|
||||
// This method must be called before releasing the OpenGL context if the viewer
|
||||
// goes out of scope after releasing it.
|
||||
//
|
||||
void shutdown();
|
||||
//
|
||||
// Reset the contents of the viewer.
|
||||
// Automatically called by load() method.
|
||||
//
|
||||
void reset();
|
||||
//
|
||||
// Setup the viewer content from the given data.
|
||||
// See: GCodeInputData
|
||||
//
|
||||
void load(GCodeInputData&& gcode_data);
|
||||
//
|
||||
// Render the toolpaths according to the current settings and
|
||||
// using the given camera matrices.
|
||||
//
|
||||
void render(const Mat4x4& view_matrix, const Mat4x4& projection_matrix);
|
||||
|
||||
//
|
||||
// ************************************************************************
|
||||
// Settings
|
||||
// The following methods can be used to query/customize the parameters
|
||||
// used to render the toolpaths.
|
||||
// ************************************************************************
|
||||
//
|
||||
|
||||
//
|
||||
// View type
|
||||
// See: EViewType
|
||||
//
|
||||
EViewType get_view_type() const;
|
||||
void set_view_type(EViewType type);
|
||||
//
|
||||
// Time mode
|
||||
// See: ETimeMode
|
||||
//
|
||||
ETimeMode get_time_mode() const;
|
||||
void set_time_mode(ETimeMode mode);
|
||||
//
|
||||
// Top layer only
|
||||
// Whether or not the visible range is limited to the current top layer only.
|
||||
//
|
||||
bool is_top_layer_only_view_range() const;
|
||||
//
|
||||
// Toggle the top layer only state.
|
||||
//
|
||||
void toggle_top_layer_only_view_range();
|
||||
//
|
||||
// Returns true if the given option is visible.
|
||||
//
|
||||
bool is_option_visible(EOptionType type) const;
|
||||
//
|
||||
// Toggle the visibility state of the given option.
|
||||
//
|
||||
void toggle_option_visibility(EOptionType type);
|
||||
//
|
||||
// Returns true if the given extrusion role is visible.
|
||||
//
|
||||
bool is_extrusion_role_visible(EGCodeExtrusionRole role) const;
|
||||
//
|
||||
// Toggle the visibility state of the given extrusion role.
|
||||
//
|
||||
void toggle_extrusion_role_visibility(EGCodeExtrusionRole role);
|
||||
//
|
||||
// Return the color used to render the given extrusion rols.
|
||||
//
|
||||
const Color& get_extrusion_role_color(EGCodeExtrusionRole role) const;
|
||||
//
|
||||
// Set the color used to render the given extrusion role.
|
||||
//
|
||||
void set_extrusion_role_color(EGCodeExtrusionRole role, const Color& color);
|
||||
//
|
||||
// Reset the colors used to render the extrusion roles to the default value.
|
||||
//
|
||||
void reset_default_extrusion_roles_colors();
|
||||
//
|
||||
// Return the color used to render the given option.
|
||||
//
|
||||
const Color& get_option_color(EOptionType type) const;
|
||||
//
|
||||
// Set the color used to render the given option.
|
||||
//
|
||||
void set_option_color(EOptionType type, const Color& color);
|
||||
//
|
||||
// Reset the colors used to render the options to the default value.
|
||||
//
|
||||
void reset_default_options_colors();
|
||||
//
|
||||
// Return the count of colors in the palette used to render
|
||||
// the toolpaths when the view type is EViewType::Tool.
|
||||
//
|
||||
size_t get_tool_colors_count() const;
|
||||
//
|
||||
// Return the palette used to render the toolpaths when
|
||||
// the view type is EViewType::Tool.
|
||||
//
|
||||
const Palette& get_tool_colors() const;
|
||||
//
|
||||
// Set the palette used to render the toolpaths when
|
||||
// the view type is EViewType::Tool with the given one.
|
||||
//
|
||||
void set_tool_colors(const Palette& colors);
|
||||
//
|
||||
// Return the count of colors in the palette used to render
|
||||
// the toolpaths when the view type is EViewType::ColorPrint.
|
||||
//
|
||||
size_t get_color_print_colors_count() const;
|
||||
//
|
||||
// Return the palette used to render the toolpaths when
|
||||
// the view type is EViewType::ColorPrint.
|
||||
//
|
||||
const Palette& get_color_print_colors() const;
|
||||
//
|
||||
// Set the palette used to render the toolpaths when
|
||||
// the view type is EViewType::ColorPrint with the given one.
|
||||
//
|
||||
void set_color_print_colors(const Palette& colors);
|
||||
//
|
||||
// Get the color range for the given view type.
|
||||
// Valid view types are:
|
||||
// EViewType::Height
|
||||
// EViewType::Width
|
||||
// EViewType::Speed
|
||||
// EViewType::ActualSpeed
|
||||
// EViewType::FanSpeed
|
||||
// EViewType::Temperature
|
||||
// EViewType::VolumetricFlowRate
|
||||
// EViewType::ActualVolumetricFlowRate
|
||||
// EViewType::LayerTimeLinear
|
||||
// EViewType::LayerTimeLogarithmic
|
||||
//
|
||||
const ColorRange& get_color_range(EViewType type) const;
|
||||
//
|
||||
// Set the palette for the color range corresponding to the given view type
|
||||
// with the given value.
|
||||
// Valid view types are:
|
||||
// EViewType::Height
|
||||
// EViewType::Width
|
||||
// EViewType::Speed
|
||||
// EViewType::ActualSpeed
|
||||
// EViewType::FanSpeed
|
||||
// EViewType::Temperature
|
||||
// EViewType::VolumetricFlowRate
|
||||
// EViewType::ActualVolumetricFlowRate
|
||||
// EViewType::LayerTimeLinear
|
||||
// EViewType::LayerTimeLogarithmic
|
||||
//
|
||||
void set_color_range_palette(EViewType type, const Palette& palette);
|
||||
//
|
||||
// Get the radius, in mm, of the cylinders used to render the travel moves.
|
||||
//
|
||||
float get_travels_radius() const;
|
||||
//
|
||||
// Set the radius, in mm, of the cylinders used to render the travel moves.
|
||||
// Radius is clamped to [MIN_TRAVELS_RADIUS_MM..MAX_TRAVELS_RADIUS_MM]
|
||||
//
|
||||
void set_travels_radius(float radius);
|
||||
//
|
||||
// Get the radius, in mm, of the cylinders used to render the wipe moves.
|
||||
//
|
||||
float get_wipes_radius() const;
|
||||
//
|
||||
// Set the radius, in mm, of the cylinders used to render the wipe moves.
|
||||
// Radius is clamped to [MIN_WIPES_RADIUS_MM..MAX_WIPES_RADIUS_MM]
|
||||
//
|
||||
void set_wipes_radius(float radius);
|
||||
//
|
||||
// Return the count of detected layers.
|
||||
//
|
||||
size_t get_layers_count() const;
|
||||
//
|
||||
// Return the current visible layers range.
|
||||
//
|
||||
const Interval& get_layers_view_range() const;
|
||||
//
|
||||
// Set the current visible layers range with the given interval.
|
||||
// Values are clamped to [0..get_layers_count() - 1].
|
||||
//
|
||||
void set_layers_view_range(const Interval& range);
|
||||
//
|
||||
// Set the current visible layers range with the given min and max values.
|
||||
// Values are clamped to [0..get_layers_count() - 1].
|
||||
//
|
||||
void set_layers_view_range(Interval::value_type min, Interval::value_type max);
|
||||
//
|
||||
// Return the current visible range.
|
||||
// Three ranges are defined: full, enabled and visible.
|
||||
// For all of them the range endpoints represent:
|
||||
// [0] -> min vertex id
|
||||
// [1] -> max vertex id
|
||||
// Full is the range of vertices that could potentially be visualized accordingly to the current settings.
|
||||
// Enabled is the part of the full range that is selected for visualization accordingly to the current settings.
|
||||
// Visible is the part of the enabled range that is actually visualized accordingly to the current settings.
|
||||
//
|
||||
const Interval& get_view_visible_range() const;
|
||||
//
|
||||
// Set the current visible range.
|
||||
// Values are clamped to the current view enabled range;
|
||||
//
|
||||
void set_view_visible_range(Interval::value_type min, Interval::value_type max);
|
||||
//
|
||||
// Return the current full range.
|
||||
//
|
||||
const Interval& get_view_full_range() const;
|
||||
//
|
||||
// Return the current enabled range.
|
||||
//
|
||||
const Interval& get_view_enabled_range() const;
|
||||
|
||||
//
|
||||
// ************************************************************************
|
||||
// Property getters
|
||||
// The following methods can be used to query detected properties.
|
||||
// ************************************************************************
|
||||
//
|
||||
|
||||
//
|
||||
// Spiral vase mode
|
||||
// Whether or not the gcode was generated with spiral vase mode enabled.
|
||||
// See: GCodeInputData
|
||||
//
|
||||
bool is_spiral_vase_mode() const;
|
||||
//
|
||||
// Return the z of the layer with the given id
|
||||
// or 0.0f if the id does not belong to [0..get_layers_count() - 1].
|
||||
//
|
||||
float get_layer_z(size_t layer_id) const;
|
||||
//
|
||||
// Return the list of zs of the detected layers.
|
||||
//
|
||||
std::vector<float> get_layers_zs() const;
|
||||
//
|
||||
// Return the id of the layer closest to the given z.
|
||||
//
|
||||
size_t get_layer_id_at(float z) const;
|
||||
//
|
||||
// Return the count of detected used extruders.
|
||||
//
|
||||
size_t get_used_extruders_count() const;
|
||||
//
|
||||
// Return the list of ids of the detected used extruders.
|
||||
//
|
||||
std::vector<uint8_t> get_used_extruders_ids() const;
|
||||
//
|
||||
// Return the list of detected time modes.
|
||||
//
|
||||
std::vector<ETimeMode> get_time_modes() const;
|
||||
//
|
||||
// Return the count of vertices used to render the toolpaths
|
||||
//
|
||||
size_t get_vertices_count() const;
|
||||
//
|
||||
// Return the vertex pointed by the max value of the view visible range
|
||||
//
|
||||
const PathVertex& get_current_vertex() const;
|
||||
//
|
||||
// Return the index of vertex pointed by the max value of the view visible range
|
||||
//
|
||||
size_t get_current_vertex_id() const;
|
||||
//
|
||||
// Return the vertex at the given index
|
||||
//
|
||||
const PathVertex& get_vertex_at(size_t id) const;
|
||||
//
|
||||
// Return the total estimated time, in seconds, using the current time mode.
|
||||
//
|
||||
float get_estimated_time() const;
|
||||
//
|
||||
// Return the estimated time, in seconds, at the vertex with the given index
|
||||
// using the current time mode.
|
||||
//
|
||||
float get_estimated_time_at(size_t id) const;
|
||||
//
|
||||
// Return the color used to render the given vertex with the current settings.
|
||||
//
|
||||
Color get_vertex_color(const PathVertex& vertex) const;
|
||||
//
|
||||
// Return the count of detected extrusion roles
|
||||
//
|
||||
size_t get_extrusion_roles_count() const;
|
||||
//
|
||||
// Return the list of detected extrusion roles
|
||||
//
|
||||
std::vector<EGCodeExtrusionRole> get_extrusion_roles() const;
|
||||
//
|
||||
// Return the count of detected options.
|
||||
//
|
||||
size_t get_options_count() const;
|
||||
//
|
||||
// Return the list of detected options.
|
||||
//
|
||||
const std::vector<EOptionType>& get_options() const;
|
||||
//
|
||||
// Return the count of detected color prints.
|
||||
//
|
||||
size_t get_color_prints_count(uint8_t extruder_id) const;
|
||||
//
|
||||
// Return the list of detected color prints.
|
||||
//
|
||||
std::vector<ColorPrint> get_color_prints(uint8_t extruder_id) const;
|
||||
//
|
||||
// Return the estimated time for the given role and the current time mode.
|
||||
//
|
||||
float get_extrusion_role_estimated_time(EGCodeExtrusionRole role) const;
|
||||
//
|
||||
// Return the estimated time for the travel moves and the current time mode.
|
||||
//
|
||||
float get_travels_estimated_time() const;
|
||||
//
|
||||
// Return the list of layers time for the current time mode.
|
||||
//
|
||||
std::vector<float> get_layers_estimated_times() const;
|
||||
//
|
||||
// Return the axes aligned bounding box containing all the given types.
|
||||
//
|
||||
AABox get_bounding_box(const std::vector<EMoveType>& types = {
|
||||
EMoveType::Retract, EMoveType::Unretract, EMoveType::Seam, EMoveType::ToolChange,
|
||||
EMoveType::ColorChange, EMoveType::PausePrint, EMoveType::CustomGCode, EMoveType::Travel,
|
||||
EMoveType::Wipe, EMoveType::Extrude }) const;
|
||||
//
|
||||
// Return the axes aligned bounding box containing all the extrusions with the given roles.
|
||||
//
|
||||
AABox get_extrusion_bounding_box(const std::vector<EGCodeExtrusionRole>& roles = {
|
||||
EGCodeExtrusionRole::Perimeter, EGCodeExtrusionRole::ExternalPerimeter, EGCodeExtrusionRole::OverhangPerimeter,
|
||||
EGCodeExtrusionRole::InternalInfill, EGCodeExtrusionRole::SolidInfill, EGCodeExtrusionRole::TopSolidInfill,
|
||||
EGCodeExtrusionRole::Ironing, EGCodeExtrusionRole::BridgeInfill, EGCodeExtrusionRole::GapFill,
|
||||
EGCodeExtrusionRole::Skirt, EGCodeExtrusionRole::SupportMaterial, EGCodeExtrusionRole::SupportMaterialInterface,
|
||||
EGCodeExtrusionRole::WipeTower, EGCodeExtrusionRole::Custom }) const;
|
||||
//
|
||||
// Return the size of the used cpu memory, in bytes
|
||||
//
|
||||
size_t get_used_cpu_memory() const;
|
||||
//
|
||||
// Return the size of the used gpu memory, in bytes
|
||||
//
|
||||
size_t get_used_gpu_memory() const;
|
||||
|
||||
#if VGCODE_ENABLE_COG_AND_TOOL_MARKERS
|
||||
//
|
||||
// Returns the position of the center of gravity of the toolpaths.
|
||||
// It does not take in account extrusions of type:
|
||||
// Skirt
|
||||
// Support Material
|
||||
// Support Material Interface
|
||||
// WipeTower
|
||||
// Custom
|
||||
//
|
||||
Vec3 get_cog_position() const;
|
||||
|
||||
float get_cog_marker_scale_factor() const;
|
||||
void set_cog_marker_scale_factor(float factor);
|
||||
|
||||
const Vec3& get_tool_marker_position() const;
|
||||
|
||||
float get_tool_marker_offset_z() const;
|
||||
void set_tool_marker_offset_z(float offset_z);
|
||||
|
||||
float get_tool_marker_scale_factor() const;
|
||||
void set_tool_marker_scale_factor(float factor);
|
||||
|
||||
const Color& get_tool_marker_color() const;
|
||||
void set_tool_marker_color(const Color& color);
|
||||
|
||||
float get_tool_marker_alpha() const;
|
||||
void set_tool_marker_alpha(float alpha);
|
||||
#endif // VGCODE_ENABLE_COG_AND_TOOL_MARKERS
|
||||
|
||||
private:
|
||||
ViewerImpl* m_impl{ nullptr };
|
||||
};
|
||||
|
||||
} // namespace libvgcode
|
||||
|
||||
#endif // VGCODE_VIEWER_HPP
|
||||
Reference in New Issue
Block a user