mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-01 04:22:04 +08:00
New gcode visualization - Fixed errors and warnings when building the new code as a standalone library
This commit is contained in:
parent
82fb23fa8e
commit
2e13c44895
@ -105,7 +105,7 @@ public:
|
||||
//
|
||||
// Return the count of detected extrusion roles
|
||||
//
|
||||
uint32_t get_extrusion_roles_count() const;
|
||||
size_t get_extrusion_roles_count() const;
|
||||
|
||||
//
|
||||
// Return the list of detected extrusion roles
|
||||
|
@ -20,7 +20,7 @@ template<typename T = unsigned long long>
|
||||
struct BitSet
|
||||
{
|
||||
BitSet() = default;
|
||||
BitSet(unsigned int size) : size(size), blocks(1 + (size / (sizeof(T) * 8))) { clear(); }
|
||||
BitSet(size_t size) : size(size), blocks(1 + (size / (sizeof(T) * 8))) { clear(); }
|
||||
|
||||
void clear() {
|
||||
for (size_t i = 0; i < blocks.size(); ++i) {
|
||||
@ -35,24 +35,24 @@ struct BitSet
|
||||
}
|
||||
|
||||
//return true if bit changed
|
||||
bool set(unsigned int index) {
|
||||
bool set(size_t index) {
|
||||
const auto [block_idx, bit_idx] = get_coords(index);
|
||||
T mask = (T(1) << bit_idx);
|
||||
const T mask = (T(1) << bit_idx);
|
||||
bool flip = mask xor blocks[block_idx];
|
||||
blocks[block_idx] |= mask;
|
||||
return flip;
|
||||
}
|
||||
|
||||
//return true if bit changed
|
||||
bool reset(unsigned int index) {
|
||||
bool reset(size_t index) {
|
||||
const auto [block_idx, bit_idx] = get_coords(index);
|
||||
T mask = (T(1) << bit_idx);
|
||||
bool flip = mask xor blocks[block_idx];
|
||||
const T mask = (T(1) << bit_idx);
|
||||
const bool flip = mask xor blocks[block_idx];
|
||||
blocks[block_idx] &= (~mask);
|
||||
return flip;
|
||||
}
|
||||
|
||||
bool operator [] (unsigned int index) const {
|
||||
bool operator [] (size_t index) const {
|
||||
const auto [block_idx, bit_idx] = get_coords(index);
|
||||
return ((blocks[block_idx] >> bit_idx) & 1) != 0;
|
||||
}
|
||||
@ -68,30 +68,30 @@ struct BitSet
|
||||
|
||||
// Atomic set operation (enabled only for atomic types), return true if bit changed
|
||||
template<typename U = T>
|
||||
inline typename std::enable_if<is_atomic<U>, bool>::type set_atomic(unsigned int index) {
|
||||
inline typename std::enable_if<is_atomic<U>, bool>::type set_atomic(size_t index) {
|
||||
const auto [block_idx, bit_idx] = get_coords(index);
|
||||
T mask = static_cast<T>(1) << bit_idx;
|
||||
T oldval = blocks[block_idx].fetch_or(mask, std::memory_order_relaxed);
|
||||
const T mask = static_cast<T>(1) << bit_idx;
|
||||
const T oldval = blocks[block_idx].fetch_or(mask, std::memory_order_relaxed);
|
||||
return oldval xor (oldval or mask);
|
||||
}
|
||||
|
||||
// Atomic reset operation (enabled only for atomic types), return true if bit changed
|
||||
template<typename U = T>
|
||||
inline typename std::enable_if<is_atomic<U>, bool>::type reset_atomic(unsigned int index) {
|
||||
inline typename std::enable_if<is_atomic<U>, bool>::type reset_atomic(size_t index) {
|
||||
const auto [block_idx, bit_idx] = get_coords(index);
|
||||
T mask = ~(static_cast<T>(1) << bit_idx);
|
||||
T oldval = blocks[block_idx].fetch_and(mask, std::memory_order_relaxed);
|
||||
const T mask = ~(static_cast<T>(1) << bit_idx);
|
||||
const T oldval = blocks[block_idx].fetch_and(mask, std::memory_order_relaxed);
|
||||
return oldval xor (oldval and mask);
|
||||
}
|
||||
|
||||
std::pair<unsigned int, unsigned int> get_coords(unsigned int index) const
|
||||
std::pair<size_t, size_t> get_coords(size_t index) const
|
||||
{
|
||||
unsigned int block_idx = index / (sizeof(T) * 8);
|
||||
unsigned int bit_idx = index % (sizeof(T) * 8);
|
||||
return std::make_pair(block_idx, bit_idx);
|
||||
const size_t block_idx = index / (sizeof(T) * 8);
|
||||
const size_t bit_idx = index % (sizeof(T) * 8);
|
||||
return { block_idx, bit_idx };
|
||||
}
|
||||
|
||||
unsigned int size{ 0 };
|
||||
size_t size{ 0 };
|
||||
std::vector<T> blocks{ 0 };
|
||||
};
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <assert.h>
|
||||
#include <cmath>
|
||||
|
||||
namespace libvgcode {
|
||||
|
||||
@ -45,7 +46,7 @@ Color ColorRange::get_color_at(float value) const
|
||||
if (step > 0.0f) {
|
||||
if (m_type == EColorRangeType::Logarithmic) {
|
||||
if (m_range[0] != 0.0f)
|
||||
global_t = log(value / m_range[0]) / step;
|
||||
global_t = std::log(value / m_range[0]) / step;
|
||||
}
|
||||
else
|
||||
global_t = (value - m_range[0]) / step;
|
||||
@ -54,7 +55,7 @@ Color ColorRange::get_color_at(float value) const
|
||||
const size_t color_max_idx = Ranges_Colors.size() - 1;
|
||||
|
||||
// Compute the two colors just below (low) and above (high) the input value
|
||||
const size_t color_low_idx = std::clamp<size_t>(global_t, 0, color_max_idx);
|
||||
const size_t color_low_idx = std::clamp<size_t>(static_cast<size_t>(global_t), 0, color_max_idx);
|
||||
const size_t color_high_idx = std::clamp<size_t>(color_low_idx + 1, 0, color_max_idx);
|
||||
|
||||
// Interpolate between the low and high colors to find exactly which color the input value should get
|
||||
|
@ -18,7 +18,7 @@ extern void glAssertRecentCallImpl(const char* file_name, unsigned int line, con
|
||||
inline void glAssertRecentCall() { glAssertRecentCallImpl(__FILE__, __LINE__, __FUNCTION__); }
|
||||
#define glsafe(cmd) do { cmd; glAssertRecentCallImpl(__FILE__, __LINE__, __FUNCTION__); } while (false)
|
||||
#define glcheck() do { glAssertRecentCallImpl(__FILE__, __LINE__, __FUNCTION__); } while (false)
|
||||
#else // HAS_GLSAFE
|
||||
#else
|
||||
inline void glAssertRecentCall() { }
|
||||
#define glsafe(cmd) cmd
|
||||
#define glcheck()
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
namespace libvgcode {
|
||||
|
||||
@ -43,7 +44,7 @@ void OptionTemplate::init(uint8_t resolution)
|
||||
add_vertex({ 0.0f, 0.0f, 0.5f }, { 0.0f, 0.0f, 1.0f }, top_vertices);
|
||||
for (uint8_t i = 0; i <= m_resolution; ++i) {
|
||||
const float ii = float(i) * step;
|
||||
const Vec3 pos = { 0.5f * ::cos(ii), 0.5f * ::sin(ii), 0.0f };
|
||||
const Vec3 pos = { 0.5f * std::cos(ii), 0.5f * std::sin(ii), 0.0f };
|
||||
const Vec3 norm = normalize(pos);
|
||||
add_vertex(pos, norm, top_vertices);
|
||||
}
|
||||
@ -56,7 +57,7 @@ void OptionTemplate::init(uint8_t resolution)
|
||||
add_vertex({ 0.0f, 0.0f, -0.5f }, { 0.0f, 0.0f, -1.0f }, bottom_vertices);
|
||||
for (uint8_t i = 0; i <= m_resolution; ++i) {
|
||||
const float ii = -float(i) * step;
|
||||
const Vec3 pos = { 0.5f * ::cos(ii), 0.5f * ::sin(ii), 0.0f };
|
||||
const Vec3 pos = { 0.5f * std::cos(ii), 0.5f * std::sin(ii), 0.0f };
|
||||
const Vec3 norm = normalize(pos);
|
||||
add_vertex(pos, norm, bottom_vertices);
|
||||
}
|
||||
@ -103,10 +104,9 @@ void OptionTemplate::render(size_t count)
|
||||
glsafe(glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &curr_vertex_array));
|
||||
|
||||
glsafe(glBindVertexArray(m_top_vao_id));
|
||||
glsafe(glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, m_vertices_count, count));
|
||||
glsafe(glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, static_cast<GLsizei>(m_vertices_count), static_cast<GLsizei>(count)));
|
||||
glsafe(glBindVertexArray(m_bottom_vao_id));
|
||||
glsafe(glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, m_vertices_count, count));
|
||||
|
||||
glsafe(glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, static_cast<GLsizei>(m_vertices_count), static_cast<GLsizei>(count)));
|
||||
glsafe(glBindVertexArray(curr_vertex_array));
|
||||
}
|
||||
|
||||
|
@ -67,8 +67,7 @@ void SegmentTemplate::render(size_t count)
|
||||
glsafe(glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &curr_vertex_array));
|
||||
|
||||
glsafe(glBindVertexArray(m_vao_id));
|
||||
glsafe(glDrawArraysInstanced(GL_TRIANGLES, 0, VERTEX_DATA.size(), count));
|
||||
|
||||
glsafe(glDrawArraysInstanced(GL_TRIANGLES, 0, static_cast<GLsizei>(VERTEX_DATA.size()), static_cast<GLsizei>(count)));
|
||||
glsafe(glBindVertexArray(curr_vertex_array));
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include "OpenGLUtils.hpp"
|
||||
#include "Utils.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS
|
||||
|
||||
@ -49,8 +49,8 @@ void ToolMarker::init(uint16_t resolution, float tip_radius, float tip_height, f
|
||||
|
||||
for (uint16_t i = 0; i < resolution; ++i) {
|
||||
const float angle = angle_step * float(i);
|
||||
cosines[i] = ::cos(angle);
|
||||
sines[i] = -::sin(angle);
|
||||
cosines[i] = std::cos(angle);
|
||||
sines[i] = -std::sin(angle);
|
||||
}
|
||||
|
||||
const float total_height = tip_height + stem_height;
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "../include/Types.hpp"
|
||||
|
||||
#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS
|
||||
#include <algorithm>
|
||||
|
||||
namespace libvgcode {
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
///|/
|
||||
#include "Utils.hpp"
|
||||
|
||||
#include <assert.h>
|
||||
#include <cmath>
|
||||
|
||||
namespace libvgcode {
|
||||
|
@ -202,7 +202,7 @@ const Interval& Viewer::get_enabled_options_range() const
|
||||
return m_impl->get_enabled_options_range();
|
||||
}
|
||||
|
||||
uint32_t Viewer::get_extrusion_roles_count() const
|
||||
size_t Viewer::get_extrusion_roles_count() const
|
||||
{
|
||||
return m_impl->get_extrusion_roles_count();
|
||||
}
|
||||
|
@ -10,10 +10,11 @@
|
||||
|
||||
#include <map>
|
||||
#include <assert.h>
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
namespace libvgcode {
|
||||
|
||||
@ -180,7 +181,7 @@ static Mat4x4 inverse(const Mat4x4& m)
|
||||
float det = m[0] * inv[0] + m[1] * inv[4] + m[2] * inv[8] + m[3] * inv[12];
|
||||
assert(det != 0.0f);
|
||||
|
||||
det = 1.0 / det;
|
||||
det = 1.0f / det;
|
||||
|
||||
std::array<float, 16> ret = {};
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
@ -534,10 +535,10 @@ void ViewerImpl::load(GCodeInputData&& gcode_data)
|
||||
Vec3 position = v.position;
|
||||
if (move_type == EMoveType::Extrude)
|
||||
// push down extrusion vertices by half height to render them at the right z
|
||||
position[2] -= 0.5 * v.height;
|
||||
position[2] -= 0.5f * v.height;
|
||||
positions.emplace_back(position);
|
||||
|
||||
const float angle = atan2(prev_line[0] * this_line[1] - prev_line[1] * this_line[0], dot(prev_line, this_line));
|
||||
const float angle = std::atan2(prev_line[0] * this_line[1] - prev_line[1] * this_line[0], dot(prev_line, this_line));
|
||||
heights_widths_angles.push_back({ v.height, v.width, angle });
|
||||
}
|
||||
|
||||
@ -612,7 +613,7 @@ void ViewerImpl::update_enabled_entities()
|
||||
--range[0];
|
||||
}
|
||||
|
||||
for (uint32_t i = range[0]; i < range[1]; ++i) {
|
||||
for (size_t i = range[0]; i < range[1]; ++i) {
|
||||
const PathVertex& v = m_vertices[i];
|
||||
|
||||
if (!m_valid_lines_bitset[i] && !v.is_option())
|
||||
@ -637,9 +638,9 @@ void ViewerImpl::update_enabled_entities()
|
||||
continue;
|
||||
|
||||
if (v.is_option())
|
||||
enabled_options.push_back(i);
|
||||
enabled_options.push_back(static_cast<uint32_t>(i));
|
||||
else
|
||||
enabled_segments.push_back(i);
|
||||
enabled_segments.push_back(static_cast<uint32_t>(i));
|
||||
}
|
||||
|
||||
m_enabled_segments_count = enabled_segments.size();
|
||||
|
Loading…
x
Reference in New Issue
Block a user