Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::GUI::Camera Struct Reference

#include <src/slic3r/GUI/Camera.hpp>

+ Collaboration diagram for Slic3r::GUI::Camera:

Public Types

enum class  EType : unsigned char { Unknown , Ortho , Perspective , Num_types }
 

Public Member Functions

 Camera ()
 
EType get_type () const
 
std::string get_type_as_string () const
 
void set_type (EType type)
 
void set_type (const std::string &type)
 
void select_next_type ()
 
void enable_update_config_on_type_change (bool enable)
 
const Vec3dget_target () const
 
void set_target (const Vec3d &target)
 
double get_distance () const
 
double get_gui_scale () const
 
double get_zoom () const
 
double get_inv_zoom () const
 
void update_zoom (double delta_zoom)
 
void set_zoom (double zoom)
 
const BoundingBoxf3get_scene_box () const
 
void set_scene_box (const BoundingBoxf3 &box)
 
void select_view (const std::string &direction)
 
const std::array< int, 4 > & get_viewport () const
 
const Transform3dget_view_matrix () const
 
const Transform3dget_projection_matrix () const
 
Vec3d get_dir_right () const
 
Vec3d get_dir_up () const
 
Vec3d get_dir_forward () const
 
Vec3d get_position () const
 
double get_near_z () const
 
double get_far_z () const
 
const std::pair< double, double > & get_z_range () const
 
double get_near_left () const
 
double get_near_right () const
 
double get_near_top () const
 
double get_near_bottom () const
 
double get_near_width () const
 
double get_near_height () const
 
double get_fov () const
 
void set_viewport (int x, int y, unsigned int w, unsigned int h)
 
void apply_viewport () const
 
void apply_projection (const BoundingBoxf3 &box, double near_z=-1.0, double far_z=-1.0)
 
void apply_projection (double left, double right, double bottom, double top, double near_z, double far_z)
 
void zoom_to_box (const BoundingBoxf3 &box, double margin_factor=DefaultZoomToBoxMarginFactor)
 
void zoom_to_volumes (const GLVolumePtrs &volumes, double margin_factor=DefaultZoomToVolumesMarginFactor)
 
void translate_world (const Vec3d &displacement)
 
void rotate_on_sphere (double delta_azimut_rad, double delta_zenit_rad, bool apply_limits)
 
void rotate_local_around_target (const Vec3d &rotation_rad)
 
bool is_looking_downward () const
 
void recover_from_free_camera ()
 
void look_at (const Vec3d &position, const Vec3d &target, const Vec3d &up)
 
double max_zoom () const
 
double min_zoom () const
 

Public Attributes

bool requires_zoom_to_bed { false }
 

Static Public Attributes

static const double DefaultDistance = 1000.0
 
static const double DefaultZoomToBoxMarginFactor = 1.025
 
static const double DefaultZoomToVolumesMarginFactor = 1.025
 
static double FrustrumMinZRange = 50.0
 
static double FrustrumMinNearZ = 100.0
 
static double FrustrumZMargin = 10.0
 
static double MaxFovDeg = 60.0
 

Private Member Functions

std::pair< double, double > calc_tight_frustrum_zs_around (const BoundingBoxf3 &box)
 
double calc_zoom_to_bounding_box_factor (const BoundingBoxf3 &box, double margin_factor=DefaultZoomToBoxMarginFactor) const
 
double calc_zoom_to_volumes_factor (const GLVolumePtrs &volumes, Vec3d &center, double margin_factor=DefaultZoomToVolumesMarginFactor) const
 
void set_distance (double distance)
 
void set_default_orientation ()
 
Vec3d validate_target (const Vec3d &target) const
 
void update_zenit ()
 

Private Attributes

EType m_type { EType::Perspective }
 
bool m_update_config_on_type_change_enabled { false }
 
Vec3d m_target { Vec3d::Zero() }
 
float m_zenit { 45.0f }
 
double m_zoom { 1.0 }
 
double m_distance { DefaultDistance }
 
double m_gui_scale { 1.0 }
 
std::array< int, 4 > m_viewport
 
Transform3d m_view_matrix { Transform3d::Identity() }
 
Eigen::Quaterniond m_view_rotation { 1.0, 0.0, 0.0, 0.0 }
 
Transform3d m_projection_matrix { Transform3d::Identity() }
 
std::pair< double, double > m_frustrum_zs
 
BoundingBoxf3 m_scene_box
 

Detailed Description

Member Enumeration Documentation

◆ EType

enum class Slic3r::GUI::Camera::EType : unsigned char
strong
Enumerator
Unknown 
Ortho 
Perspective 
Num_types 

Constructor & Destructor Documentation

◆ Camera()

Slic3r::GUI::Camera::Camera ( )
inline
void set_default_orientation()
Definition Camera.cpp:568

References set_default_orientation().

+ Here is the call graph for this function:

Member Function Documentation

◆ apply_projection() [1/2]

void Slic3r::GUI::Camera::apply_projection ( const BoundingBoxf3 box,
double  near_z = -1.0,
double  far_z = -1.0 
)
187{
188 double w = 0.0;
189 double h = 0.0;
190
192
193 if (near_z > 0.0)
194 m_frustrum_zs.first = std::max(std::min(m_frustrum_zs.first, near_z), FrustrumMinNearZ);
195
196 if (far_z > 0.0)
197 m_frustrum_zs.second = std::max(m_frustrum_zs.second, far_z);
198
199 w = 0.5 * (double)m_viewport[2];
200 h = 0.5 * (double)m_viewport[3];
201
202 const double inv_zoom = get_inv_zoom();
203 w *= inv_zoom;
204 h *= inv_zoom;
205
206 switch (m_type)
207 {
208 default:
209 case EType::Ortho:
210 {
211 m_gui_scale = 1.0;
212 break;
213 }
215 {
216 // scale near plane to keep w and h constant on the plane at z = m_distance
217 const double scale = m_frustrum_zs.first / m_distance;
218 w *= scale;
219 h *= scale;
221 break;
222 }
223 }
224
225 apply_projection(-w, w, -h, h, m_frustrum_zs.first, m_frustrum_zs.second);
226}
int scale(const int val)
Definition WipeTowerDialog.cpp:14
double m_distance
Definition Camera.hpp:38
std::array< int, 4 > m_viewport
Definition Camera.hpp:41
EType m_type
Definition Camera.hpp:32
void apply_projection(const BoundingBoxf3 &box, double near_z=-1.0, double far_z=-1.0)
Definition Camera.cpp:186
std::pair< double, double > calc_tight_frustrum_zs_around(const BoundingBoxf3 &box)
Definition Camera.cpp:367
double m_gui_scale
Definition Camera.hpp:39
double get_inv_zoom() const
Definition Camera.hpp:69
std::pair< double, double > m_frustrum_zs
Definition Camera.hpp:46
static double FrustrumMinNearZ
Definition Camera.hpp:17

References apply_projection(), calc_tight_frustrum_zs_around(), FrustrumMinNearZ, get_inv_zoom(), m_distance, m_frustrum_zs, m_gui_scale, m_type, m_viewport, Ortho, Perspective, and scale().

Referenced by Slic3r::GUI::GLCanvas3D::_rectangular_selection_picking_pass(), Slic3r::GUI::GLCanvas3D::_render_thumbnail_internal(), apply_projection(), and Slic3r::GUI::GLCanvas3D::render().

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

◆ apply_projection() [2/2]

void Slic3r::GUI::Camera::apply_projection ( double  left,
double  right,
double  bottom,
double  top,
double  near_z,
double  far_z 
)
229{
230 assert(left != right && bottom != top && near_z != far_z);
231 const double inv_dx = 1.0 / (right - left);
232 const double inv_dy = 1.0 / (top - bottom);
233 const double inv_dz = 1.0 / (far_z - near_z);
234
235 switch (m_type)
236 {
237 default:
238 case EType::Ortho:
239 {
240 m_projection_matrix.matrix() << 2.0 * inv_dx, 0.0, 0.0, -(left + right) * inv_dx,
241 0.0, 2.0 * inv_dy, 0.0, -(bottom + top) * inv_dy,
242 0.0, 0.0, -2.0 * inv_dz, -(near_z + far_z) * inv_dz,
243 0.0, 0.0, 0.0, 1.0;
244 break;
245 }
247 {
248 m_projection_matrix.matrix() << 2.0 * near_z * inv_dx, 0.0, (left + right) * inv_dx, 0.0,
249 0.0, 2.0 * near_z * inv_dy, (bottom + top) * inv_dy, 0.0,
250 0.0, 0.0, -(near_z + far_z) * inv_dz, -2.0 * near_z * far_z * inv_dz,
251 0.0, 0.0, -1.0, 0.0;
252 break;
253 }
254 }
255}
EIGEN_DEVICE_FUNC const MatrixType & matrix() const
Definition Transform.h:395
Transform3d m_projection_matrix
Definition Camera.hpp:45

References m_projection_matrix, m_type, Eigen::Transform< _Scalar, _Dim, _Mode, _Options >::matrix(), Ortho, and Perspective.

+ Here is the call graph for this function:

◆ apply_viewport()

void Slic3r::GUI::Camera::apply_viewport ( ) const
182{
183 glsafe(::glViewport(m_viewport[0], m_viewport[1], m_viewport[2], m_viewport[3]));
184}
#define glsafe(cmd)
Definition 3DScene.hpp:25

References glsafe, and m_viewport.

Referenced by Slic3r::GUI::GLCanvas3D::_rectangular_selection_picking_pass(), Slic3r::GUI::GLCanvas3D::_render_thumbnail_internal(), and Slic3r::GUI::GLCanvas3D::render().

+ Here is the caller graph for this function:

◆ calc_tight_frustrum_zs_around()

std::pair< double, double > Slic3r::GUI::Camera::calc_tight_frustrum_zs_around ( const BoundingBoxf3 box)
private
368{
369 std::pair<double, double> ret;
370 auto& [near_z, far_z] = ret;
371
372 // box in eye space
373 const BoundingBoxf3 eye_box = box.transformed(m_view_matrix);
374 near_z = -eye_box.max.z();
375 far_z = -eye_box.min.z();
376
377 // apply margin
378 near_z -= FrustrumZMargin;
379 far_z += FrustrumZMargin;
380
381 // ensure min size
382 if (far_z - near_z < FrustrumMinZRange) {
383 const double mid_z = 0.5 * (near_z + far_z);
384 const double half_size = 0.5 * FrustrumMinZRange;
385 near_z = mid_z - half_size;
386 far_z = mid_z + half_size;
387 }
388
389 if (near_z < FrustrumMinNearZ) {
390 const double delta = FrustrumMinNearZ - near_z;
391 set_distance(m_distance + delta);
392 near_z += delta;
393 far_z += delta;
394 }
395// The following is commented out because it causes flickering of the 3D scene GUI
396// when the bounding box of the scene gets large enough
397// We need to introduce some smarter code to move the camera back and forth in such case
398// else if (near_z > 2.0 * FrustrumMinNearZ && m_distance > DefaultDistance) {
399// float delta = m_distance - DefaultDistance;
400// set_distance(DefaultDistance);
401// near_z -= delta;
402// far_z -= delta;
403// }
404
405 return ret;
406}
Transform3d m_view_matrix
Definition Camera.hpp:42
void set_distance(double distance)
Definition Camera.cpp:523
static double FrustrumMinZRange
Definition Camera.hpp:16
static double FrustrumZMargin
Definition Camera.hpp:18

References FrustrumMinNearZ, FrustrumMinZRange, FrustrumZMargin, m_distance, m_view_matrix, Slic3r::BoundingBoxBase< PointType, APointsType >::max, Slic3r::BoundingBoxBase< PointType, APointsType >::min, set_distance(), and Slic3r::BoundingBoxf3::transformed().

Referenced by apply_projection().

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

◆ calc_zoom_to_bounding_box_factor()

double Slic3r::GUI::Camera::calc_zoom_to_bounding_box_factor ( const BoundingBoxf3 box,
double  margin_factor = DefaultZoomToBoxMarginFactor 
) const
private
409{
410 const double max_bb_size = box.max_size();
411 if (max_bb_size == 0.0)
412 return -1.0;
413
414 // project the box vertices on a plane perpendicular to the camera forward axis
415 // then calculates the vertices coordinate on this plane along the camera xy axes
416
417 const Vec3d right = get_dir_right();
418 const Vec3d up = get_dir_up();
419 const Vec3d forward = get_dir_forward();
420 const Vec3d bb_center = box.center();
421
422 // box vertices in world space
423 const std::vector<Vec3d> vertices = {
424 box.min,
425 { box.max(0), box.min(1), box.min(2) },
426 { box.max(0), box.max(1), box.min(2) },
427 { box.min(0), box.max(1), box.min(2) },
428 { box.min(0), box.min(1), box.max(2) },
429 { box.max(0), box.min(1), box.max(2) },
430 box.max,
431 { box.min(0), box.max(1), box.max(2) }
432 };
433
434 double min_x = DBL_MAX;
435 double min_y = DBL_MAX;
436 double max_x = -DBL_MAX;
437 double max_y = -DBL_MAX;
438
439 for (const Vec3d& v : vertices) {
440 // project vertex on the plane perpendicular to camera forward axis
441 const Vec3d pos = v - bb_center;
442 const Vec3d proj_on_plane = pos - pos.dot(forward) * forward;
443
444 // calculates vertex coordinate along camera xy axes
445 const double x_on_plane = proj_on_plane.dot(right);
446 const double y_on_plane = proj_on_plane.dot(up);
447
448 min_x = std::min(min_x, x_on_plane);
449 min_y = std::min(min_y, y_on_plane);
450 max_x = std::max(max_x, x_on_plane);
451 max_y = std::max(max_y, y_on_plane);
452 }
453
454 double dx = max_x - min_x;
455 double dy = max_y - min_y;
456 if (dx <= 0.0 || dy <= 0.0)
457 return -1.0f;
458
459 dx *= margin_factor;
460 dy *= margin_factor;
461
462 return std::min((double)m_viewport[2] / dx, (double)m_viewport[3] / dy);
463}
Vec3d pos(const Pt &p)
Definition ReprojectPointsOnMesh.hpp:14
Eigen::Matrix< double, 3, 1, Eigen::DontAlign > Vec3d
Definition Point.hpp:52
Vec3d get_dir_forward() const
Definition Camera.hpp:84
Vec3d get_dir_right() const
Definition Camera.hpp:82
Vec3d get_dir_up() const
Definition Camera.hpp:83

References Slic3r::BoundingBox3Base< PointType >::center(), get_dir_forward(), get_dir_right(), get_dir_up(), m_viewport, Slic3r::BoundingBoxBase< PointType, APointsType >::max, Slic3r::BoundingBox3Base< PointType >::max_size(), and Slic3r::BoundingBoxBase< PointType, APointsType >::min.

Referenced by min_zoom(), and zoom_to_box().

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

◆ calc_zoom_to_volumes_factor()

double Slic3r::GUI::Camera::calc_zoom_to_volumes_factor ( const GLVolumePtrs volumes,
Vec3d center,
double  margin_factor = DefaultZoomToVolumesMarginFactor 
) const
private
466{
467 if (volumes.empty())
468 return -1.0;
469
470 // project the volumes vertices on a plane perpendicular to the camera forward axis
471 // then calculates the vertices coordinate on this plane along the camera xy axes
472
473 const Vec3d right = get_dir_right();
474 const Vec3d up = get_dir_up();
475 const Vec3d forward = get_dir_forward();
476
477 BoundingBoxf3 box;
478 for (const GLVolume* volume : volumes) {
479 box.merge(volume->transformed_bounding_box());
480 }
481 center = box.center();
482
483 double min_x = DBL_MAX;
484 double min_y = DBL_MAX;
485 double max_x = -DBL_MAX;
486 double max_y = -DBL_MAX;
487
488 for (const GLVolume* volume : volumes) {
489 const Transform3d& transform = volume->world_matrix();
490 const TriangleMesh* hull = volume->convex_hull();
491 if (hull == nullptr)
492 continue;
493
494 for (const Vec3f& vertex : hull->its.vertices) {
495 const Vec3d v = transform * vertex.cast<double>();
496
497 // project vertex on the plane perpendicular to camera forward axis
498 const Vec3d pos = v - center;
499 const Vec3d proj_on_plane = pos - pos.dot(forward) * forward;
500
501 // calculates vertex coordinate along camera xy axes
502 const double x_on_plane = proj_on_plane.dot(right);
503 const double y_on_plane = proj_on_plane.dot(up);
504
505 min_x = std::min(min_x, x_on_plane);
506 min_y = std::min(min_y, y_on_plane);
507 max_x = std::max(max_x, x_on_plane);
508 max_y = std::max(max_y, y_on_plane);
509 }
510 }
511
512 center += 0.5 * (max_x + min_x) * right + 0.5 * (max_y + min_y) * up;
513
514 const double dx = margin_factor * (max_x - min_x);
515 const double dy = margin_factor * (max_y - min_y);
516
517 if (dx <= 0.0 || dy <= 0.0)
518 return -1.0f;
519
520 return std::min((double)m_viewport[2] / dx, (double)m_viewport[3] / dy);
521}
Eigen::Transform< double, 3, Eigen::Affine, Eigen::DontAlign > Transform3d
Definition Point.hpp:81
Eigen::Matrix< float, 3, 1, Eigen::DontAlign > Vec3f
Definition Point.hpp:49
Linef3 transform(const Linef3 &line, const Transform3d &t)
Definition Line.cpp:10
IGL_INLINE void volume(const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedT > &T, Eigen::PlainObjectBase< Derivedvol > &vol)
Definition volume.cpp:15
TPoint< S > & vertex(S &sh, unsigned long idx, const PolygonTag &)
Definition geometry_traits.hpp:1180

References Slic3r::BoundingBox3Base< PointType >::center(), get_dir_forward(), get_dir_right(), get_dir_up(), Slic3r::TriangleMesh::its, m_viewport, Slic3r::BoundingBox3Base< PointType >::merge(), Slic3r::transform(), and indexed_triangle_set::vertices.

Referenced by zoom_to_volumes().

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

◆ enable_update_config_on_type_change()

void Slic3r::GUI::Camera::enable_update_config_on_type_change ( bool  enable)
inline
bool m_update_config_on_type_change_enabled
Definition Camera.hpp:33

References m_update_config_on_type_change_enabled.

◆ get_dir_forward()

Vec3d Slic3r::GUI::Camera::get_dir_forward ( ) const
inline
84{ return -m_view_matrix.matrix().block(0, 0, 3, 3).row(2); }

References m_view_matrix, and Eigen::Transform< _Scalar, _Dim, _Mode, _Options >::matrix().

Referenced by priv::apply_camera_dir(), calc_zoom_to_bounding_box_factor(), calc_zoom_to_volumes_factor(), Slic3r::GUI::MeshRaycaster::get_unobscured_idxs(), Slic3r::GUI::SceneRaycaster::hit(), is_looking_downward(), Slic3r::GUI::GLGizmoCut3D::is_looking_forward(), Slic3r::GUI::GLCanvas3D::on_mouse(), Slic3r::GUI::CameraUtils::ray_from_ortho_screen_pos(), Slic3r::GUI::GLGizmoCut3D::PartSelection::render(), set_distance(), and update_zenit().

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

◆ get_dir_right()

Vec3d Slic3r::GUI::Camera::get_dir_right ( ) const
inline
82{ return m_view_matrix.matrix().block(0, 0, 3, 3).row(0); }

References m_view_matrix, and Eigen::Transform< _Scalar, _Dim, _Mode, _Options >::matrix().

Referenced by Slic3r::GUI::Mouse3DController::State::apply(), calc_zoom_to_bounding_box_factor(), calc_zoom_to_volumes_factor(), Slic3r::GUI::GLCanvas3D::on_mouse(), recover_from_free_camera(), and rotate_on_sphere().

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

◆ get_dir_up()

Vec3d Slic3r::GUI::Camera::get_dir_up ( ) const
inline
83{ return m_view_matrix.matrix().block(0, 0, 3, 3).row(1); }

References m_view_matrix, and Eigen::Transform< _Scalar, _Dim, _Mode, _Options >::matrix().

Referenced by Slic3r::GUI::GLCanvas3D::_rectangular_selection_picking_pass(), Slic3r::GUI::Mouse3DController::State::apply(), calc_zoom_to_bounding_box_factor(), calc_zoom_to_volumes_factor(), and Slic3r::GUI::GLCanvas3D::on_mouse().

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

◆ get_distance()

double Slic3r::GUI::Camera::get_distance ( ) const
inline
65{ return (get_position() - m_target).norm(); }
Vec3d m_target
Definition Camera.hpp:34
Vec3d get_position() const
Definition Camera.hpp:86

References get_position(), and m_target.

+ Here is the call graph for this function:

◆ get_far_z()

double Slic3r::GUI::Camera::get_far_z ( ) const
inline
89{ return m_frustrum_zs.second; }

References m_frustrum_zs.

Referenced by Slic3r::GUI::GLCanvas3D::_rectangular_selection_picking_pass().

+ Here is the caller graph for this function:

◆ get_fov()

double Slic3r::GUI::Camera::get_fov ( ) const
165{
166 switch (m_type)
167 {
169 return 2.0 * Geometry::rad2deg(std::atan(1.0 / m_projection_matrix.matrix()(1, 1)));
170 default:
171 case EType::Ortho:
172 return 0.0;
173 };
174}
T rad2deg(T angle)
Definition Geometry.hpp:288

References m_projection_matrix, m_type, Eigen::Transform< _Scalar, _Dim, _Mode, _Options >::matrix(), Ortho, Perspective, and Slic3r::Geometry::rad2deg().

+ Here is the call graph for this function:

◆ get_gui_scale()

double Slic3r::GUI::Camera::get_gui_scale ( ) const
inline
66{ return m_gui_scale; }

References m_gui_scale.

◆ get_inv_zoom()

double Slic3r::GUI::Camera::get_inv_zoom ( ) const
inline
69{ assert(m_zoom != 0.0); return 1.0 / m_zoom; }
double m_zoom
Definition Camera.hpp:36

References m_zoom.

Referenced by apply_projection(), Slic3r::GUI::GLGizmoMeasure::on_render(), Slic3r::GUI::GCodeViewer::COG::render(), Slic3r::GUI::CoordAxes::render(), and Slic3r::GUI::GLGizmoMeasure::render_dimensioning().

+ Here is the caller graph for this function:

◆ get_near_bottom()

double Slic3r::GUI::Camera::get_near_bottom ( ) const
129{
130 switch (m_type)
131 {
133 return m_frustrum_zs.first * (m_projection_matrix.matrix()(1, 2) - 1.0) / m_projection_matrix.matrix()(1, 1);
134 default:
135 case EType::Ortho:
136 return -1.0 / m_projection_matrix.matrix()(1, 1) - 0.5 * m_projection_matrix.matrix()(1, 1) * m_projection_matrix.matrix()(1, 3);
137 }
138}

References m_frustrum_zs, m_projection_matrix, m_type, Eigen::Transform< _Scalar, _Dim, _Mode, _Options >::matrix(), Ortho, and Perspective.

Referenced by Slic3r::GUI::GLCanvas3D::_rectangular_selection_picking_pass().

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

◆ get_near_height()

double Slic3r::GUI::Camera::get_near_height ( ) const
153{
154 switch (m_type)
155 {
157 return 2.0 * m_frustrum_zs.first / m_projection_matrix.matrix()(1, 1);
158 default:
159 case EType::Ortho:
160 return 2.0 / m_projection_matrix.matrix()(1, 1);
161 }
162}

References m_frustrum_zs, m_projection_matrix, m_type, Eigen::Transform< _Scalar, _Dim, _Mode, _Options >::matrix(), Ortho, and Perspective.

Referenced by Slic3r::GUI::GLCanvas3D::_rectangular_selection_picking_pass().

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

◆ get_near_left()

double Slic3r::GUI::Camera::get_near_left ( ) const
93{
94 switch (m_type)
95 {
97 return m_frustrum_zs.first * (m_projection_matrix.matrix()(0, 2) - 1.0) / m_projection_matrix.matrix()(0, 0);
98 default:
99 case EType::Ortho:
100 return -1.0 / m_projection_matrix.matrix()(0, 0) - 0.5 * m_projection_matrix.matrix()(0, 0) * m_projection_matrix.matrix()(0, 3);
101 }
102}

References m_frustrum_zs, m_projection_matrix, m_type, Eigen::Transform< _Scalar, _Dim, _Mode, _Options >::matrix(), Ortho, and Perspective.

Referenced by Slic3r::GUI::GLCanvas3D::_rectangular_selection_picking_pass().

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

◆ get_near_right()

double Slic3r::GUI::Camera::get_near_right ( ) const
105{
106 switch (m_type)
107 {
109 return m_frustrum_zs.first * (m_projection_matrix.matrix()(0, 2) + 1.0) / m_projection_matrix.matrix()(0, 0);
110 default:
111 case EType::Ortho:
112 return 1.0 / m_projection_matrix.matrix()(0, 0) - 0.5 * m_projection_matrix.matrix()(0, 0) * m_projection_matrix.matrix()(0, 3);
113 }
114}

References m_frustrum_zs, m_projection_matrix, m_type, Eigen::Transform< _Scalar, _Dim, _Mode, _Options >::matrix(), Ortho, and Perspective.

+ Here is the call graph for this function:

◆ get_near_top()

double Slic3r::GUI::Camera::get_near_top ( ) const
117{
118 switch (m_type)
119 {
121 return m_frustrum_zs.first * (m_projection_matrix.matrix()(1, 2) + 1.0) / m_projection_matrix.matrix()(1, 1);
122 default:
123 case EType::Ortho:
124 return 1.0 / m_projection_matrix.matrix()(1, 1) - 0.5 * m_projection_matrix.matrix()(1, 1) * m_projection_matrix.matrix()(1, 3);
125 }
126}

References m_frustrum_zs, m_projection_matrix, m_type, Eigen::Transform< _Scalar, _Dim, _Mode, _Options >::matrix(), Ortho, and Perspective.

+ Here is the call graph for this function:

◆ get_near_width()

double Slic3r::GUI::Camera::get_near_width ( ) const
141{
142 switch (m_type)
143 {
145 return 2.0 * m_frustrum_zs.first / m_projection_matrix.matrix()(0, 0);
146 default:
147 case EType::Ortho:
148 return 2.0 / m_projection_matrix.matrix()(0, 0);
149 }
150}

References m_frustrum_zs, m_projection_matrix, m_type, Eigen::Transform< _Scalar, _Dim, _Mode, _Options >::matrix(), Ortho, and Perspective.

Referenced by Slic3r::GUI::GLCanvas3D::_rectangular_selection_picking_pass().

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

◆ get_near_z()

double Slic3r::GUI::Camera::get_near_z ( ) const
inline
88{ return m_frustrum_zs.first; }

References m_frustrum_zs.

Referenced by Slic3r::GUI::GLCanvas3D::_rectangular_selection_picking_pass().

+ Here is the caller graph for this function:

◆ get_position()

Vec3d Slic3r::GUI::Camera::get_position ( ) const
inline
86{ return m_view_matrix.matrix().inverse().block(0, 3, 3, 1); }

References m_view_matrix, and Eigen::Transform< _Scalar, _Dim, _Mode, _Options >::matrix().

Referenced by Slic3r::GUI::GLCanvas3D::_rectangular_selection_picking_pass(), get_distance(), Slic3r::GUI::GLGizmoPainterBase::gizmo_event(), Slic3r::GUI::SceneRaycaster::hit(), Slic3r::GUI::CameraUtils::ray_from_persp_screen_pos(), recover_from_free_camera(), Slic3r::GUI::GLGizmoCut3D::PartSelection::toggle_selection(), and Slic3r::GUI::GLGizmoPainterBase::update_raycast_cache().

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

◆ get_projection_matrix()

const Transform3d & Slic3r::GUI::Camera::get_projection_matrix ( ) const
inline
80{ return m_projection_matrix; }

References m_projection_matrix.

Referenced by Slic3r::GUI::GLCanvas3D::_mouse_to_3d(), Slic3r::GUI::GLCanvas3D::_rectangular_selection_picking_pass(), Slic3r::GUI::GLCanvas3D::_render_objects(), Slic3r::GUI::GLCanvas3D::_render_sla_slices(), Slic3r::GUI::GLCanvas3D::_render_thumbnail_internal(), Slic3r::GUI::GLCanvas3D::_render_volumes_for_picking(), Slic3r::GUI::Selection::get_screen_space_bounding_box(), Slic3r::GUI::GLGizmoFlatten::on_render(), Slic3r::GUI::GLGizmoMeasure::on_render(), Slic3r::GUI::GLGizmoMove3D::on_render(), Slic3r::GUI::GLGizmoRotate::on_render(), Slic3r::GUI::GLGizmoScale3D::on_render(), Slic3r::GUI::GLGizmoSimplify::on_render(), Slic3r::GUI::CameraUtils::project(), Slic3r::GUI::CameraUtils::ray_from_ortho_screen_pos(), Slic3r::GUI::CameraUtils::ray_from_persp_screen_pos(), Slic3r::GLVolume::SinkingContours::render(), Slic3r::GLVolume::NonManifoldEdges::render(), Slic3r::GUI::GCodeViewer::COG::render(), Slic3r::GUI::GCodeViewer::SequentialView::Marker::render(), Slic3r::GUI::GLCanvas3D::SequentialPrintClearance::render(), Slic3r::GUI::GLCanvas3D::render(), Slic3r::GUI::GLCanvas3D::Labels::render(), Slic3r::GUI::CoordAxes::render(), Slic3r::GUI::GLGizmoCut3D::PartSelection::render(), Slic3r::GUI::GLGizmoBase::Grabber::render(), Slic3r::GUI::TriangleSelectorMmGui::render(), Slic3r::GUI::Selection::render_bounding_box(), Slic3r::GUI::MeshClipper::render_contour(), Slic3r::GUI::GLGizmoPainterBase::render_cursor_sphere(), Slic3r::GUI::MeshClipper::render_cut(), Slic3r::GUI::GLGizmoCut3D::render_cut_plane(), Slic3r::GUI::GLGizmoMeasure::render_dimensioning(), Slic3r::GUI::TriangleSelectorGUI::render_paint_contour(), Slic3r::GUI::GLGizmoHollow::render_points(), Slic3r::GUI::GLGizmoSlaSupports::render_points(), Slic3r::GUI::GLGizmoCut3D::render_rotation_snapping(), Slic3r::GUI::GCodeViewer::render_shells(), Slic3r::GUI::Selection::render_sidebar_layers_hints(), Slic3r::GUI::Selection::render_sidebar_position_hints(), Slic3r::GUI::Selection::render_sidebar_rotation_hints(), Slic3r::GUI::Selection::render_sidebar_scale_hints(), Slic3r::GUI::GCodeViewer::render_toolpaths(), Slic3r::GUI::GLGizmoPainterBase::render_triangles(), Slic3r::GUI::GLGizmoMmuSegmentation::render_triangles(), Slic3r::GUI::GLGizmoSlaBase::render_volumes(), and Slic3r::GUI::GLCanvas3D::LayersEditing::render_volumes().

+ Here is the caller graph for this function:

◆ get_scene_box()

const BoundingBoxf3 & Slic3r::GUI::Camera::get_scene_box ( ) const
inline
73{ return m_scene_box; }
BoundingBoxf3 m_scene_box
Definition Camera.hpp:48

References m_scene_box.

◆ get_target()

const Vec3d & Slic3r::GUI::Camera::get_target ( ) const
inline
62{ return m_target; }

References m_target.

Referenced by Slic3r::GUI::GLCanvas3D::_rectangular_selection_picking_pass(), Slic3r::GUI::Mouse3DController::State::apply(), and Slic3r::GUI::GLCanvas3D::on_mouse().

+ Here is the caller graph for this function:

◆ get_type()

EType Slic3r::GUI::Camera::get_type ( ) const
inline
53{ return m_type; }

References m_type.

Referenced by Slic3r::GUI::GLCanvas3D::_rectangular_selection_picking_pass(), Slic3r::GUI::CameraUtils::ray_from_ortho_screen_pos(), Slic3r::GUI::CameraUtils::ray_from_persp_screen_pos(), Slic3r::GUI::CameraUtils::ray_from_screen_pos(), and Slic3r::GUI::GLCanvas3D::Labels::render().

+ Here is the caller graph for this function:

◆ get_type_as_string()

std::string Slic3r::GUI::Camera::get_type_as_string ( ) const
25{
26 switch (m_type)
27 {
28 case EType::Unknown: return "unknown";
29 case EType::Perspective: return "perspective";
30 default:
31 case EType::Ortho: return "orthographic";
32 };
33}

References m_type, Ortho, Perspective, and Unknown.

◆ get_view_matrix()

const Transform3d & Slic3r::GUI::Camera::get_view_matrix ( ) const
inline
79{ return m_view_matrix; }

References m_view_matrix.

Referenced by Slic3r::GUI::GLCanvas3D::_mouse_to_3d(), Slic3r::GUI::GLCanvas3D::_rectangular_selection_picking_pass(), Slic3r::GUI::GLCanvas3D::_render_objects(), Slic3r::GUI::GLCanvas3D::_render_sla_slices(), Slic3r::GUI::GLCanvas3D::_render_thumbnail_internal(), Slic3r::GUI::GLCanvas3D::_render_volumes_for_picking(), Slic3r::GUI::Selection::get_screen_space_bounding_box(), Slic3r::GUI::GLGizmoFlatten::on_render(), Slic3r::GUI::GLGizmoMeasure::on_render(), Slic3r::GUI::GLGizmoMove3D::on_render(), Slic3r::GUI::GLGizmoRotate::on_render(), Slic3r::GUI::GLGizmoScale3D::on_render(), Slic3r::GUI::GLGizmoSimplify::on_render(), Slic3r::GUI::CameraUtils::project(), Slic3r::GUI::CameraUtils::ray_from_ortho_screen_pos(), Slic3r::GUI::CameraUtils::ray_from_persp_screen_pos(), Slic3r::GLVolume::SinkingContours::render(), Slic3r::GLVolume::NonManifoldEdges::render(), Slic3r::GUI::GCodeViewer::COG::render(), Slic3r::GUI::GCodeViewer::SequentialView::Marker::render(), Slic3r::GUI::GLCanvas3D::SequentialPrintClearance::render(), Slic3r::GUI::GLCanvas3D::render(), Slic3r::GUI::GLCanvas3D::Labels::render(), Slic3r::GUI::CoordAxes::render(), Slic3r::GUI::GLGizmoCut3D::PartSelection::render(), Slic3r::GUI::GLGizmoBase::Grabber::render(), Slic3r::GUI::TriangleSelectorMmGui::render(), Slic3r::GUI::Selection::render_bounding_box(), Slic3r::GUI::GLGizmoCut3D::render_connectors(), Slic3r::GUI::MeshClipper::render_contour(), Slic3r::GUI::GLGizmoPainterBase::render_cursor_sphere(), Slic3r::GUI::MeshClipper::render_cut(), Slic3r::GUI::GLGizmoCut3D::render_cut_plane(), Slic3r::GUI::GLGizmoMeasure::render_dimensioning(), Slic3r::GUI::TriangleSelectorGUI::render_paint_contour(), Slic3r::GUI::GLGizmoHollow::render_points(), Slic3r::GUI::GLGizmoSlaSupports::render_points(), Slic3r::GUI::GLGizmoCut3D::render_rotation_snapping(), Slic3r::GUI::GCodeViewer::render_shells(), Slic3r::GUI::Selection::render_sidebar_layers_hints(), Slic3r::GUI::Selection::render_sidebar_position_hints(), Slic3r::GUI::Selection::render_sidebar_rotation_hints(), Slic3r::GUI::Selection::render_sidebar_scale_hints(), Slic3r::GUI::GCodeViewer::render_toolpaths(), Slic3r::GUI::GLGizmoPainterBase::render_triangles(), Slic3r::GUI::GLGizmoMmuSegmentation::render_triangles(), Slic3r::GUI::GLGizmoSlaBase::render_volumes(), and Slic3r::GUI::GLCanvas3D::LayersEditing::render_volumes().

+ Here is the caller graph for this function:

◆ get_viewport()

◆ get_z_range()

const std::pair< double, double > & Slic3r::GUI::Camera::get_z_range ( ) const
inline
90{ return m_frustrum_zs; }

References m_frustrum_zs.

◆ get_zoom()

double Slic3r::GUI::Camera::get_zoom ( ) const
inline
68{ return m_zoom; }

References m_zoom.

Referenced by Slic3r::GUI::Mouse3DController::State::apply(), Slic3r::GUI::GCodeViewer::render_toolpaths(), and Slic3r::GUI::GLCanvas3D::update_ui_from_settings().

+ Here is the caller graph for this function:

◆ is_looking_downward()

bool Slic3r::GUI::Camera::is_looking_downward ( ) const
inline
127{ return get_dir_forward().dot(Vec3d::UnitZ()) < 0.0; }

References get_dir_forward().

Referenced by Slic3r::GUI::GLCanvas3D::_rectangular_selection_picking_pass(), Slic3r::GUI::GLCanvas3D::_render_thumbnail_internal(), Slic3r::GUI::SceneRaycaster::hit(), and Slic3r::GUI::GLCanvas3D::render().

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

◆ look_at()

void Slic3r::GUI::Camera::look_at ( const Vec3d position,
const Vec3d target,
const Vec3d up 
)
532{
533 const Vec3d unit_z = (position - target).normalized();
534 const Vec3d unit_x = up.cross(unit_z).normalized();
535 const Vec3d unit_y = unit_z.cross(unit_x).normalized();
536
537 m_target = target;
538 m_distance = (position - target).norm();
539 const Vec3d new_position = m_target + m_distance * unit_z;
540
541 m_view_matrix(0, 0) = unit_x.x();
542 m_view_matrix(0, 1) = unit_x.y();
543 m_view_matrix(0, 2) = unit_x.z();
544 m_view_matrix(0, 3) = -unit_x.dot(new_position);
545
546 m_view_matrix(1, 0) = unit_y.x();
547 m_view_matrix(1, 1) = unit_y.y();
548 m_view_matrix(1, 2) = unit_y.z();
549 m_view_matrix(1, 3) = -unit_y.dot(new_position);
550
551 m_view_matrix(2, 0) = unit_z.x();
552 m_view_matrix(2, 1) = unit_z.y();
553 m_view_matrix(2, 2) = unit_z.z();
554 m_view_matrix(2, 3) = -unit_z.dot(new_position);
555
556 m_view_matrix(3, 0) = 0.0;
557 m_view_matrix(3, 1) = 0.0;
558 m_view_matrix(3, 2) = 0.0;
559 m_view_matrix(3, 3) = 1.0;
560
561 // Initialize the rotation quaternion from the rotation submatrix of of m_view_matrix.
562 m_view_rotation = Eigen::Quaterniond(m_view_matrix.matrix().template block<3, 3>(0, 0));
564
565 update_zenit();
566}
EIGEN_DEVICE_FUNC void normalize()
Definition Quaternion.h:129
Quaternion< double > Quaterniond
Definition Quaternion.h:310
Eigen::Quaterniond m_view_rotation
Definition Camera.hpp:44
void update_zenit()
Definition Camera.cpp:594

References m_distance, m_target, m_view_matrix, m_view_rotation, Eigen::Transform< _Scalar, _Dim, _Mode, _Options >::matrix(), Eigen::QuaternionBase< Derived >::normalize(), and update_zenit().

Referenced by Slic3r::GUI::GLCanvas3D::_rectangular_selection_picking_pass(), recover_from_free_camera(), and select_view().

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

◆ max_zoom()

double Slic3r::GUI::Camera::max_zoom ( ) const
inline
137{ return 250.0; }

Referenced by set_zoom().

+ Here is the caller graph for this function:

◆ min_zoom()

double Slic3r::GUI::Camera::min_zoom ( ) const
inline
double calc_zoom_to_bounding_box_factor(const BoundingBoxf3 &box, double margin_factor=DefaultZoomToBoxMarginFactor) const
Definition Camera.cpp:408

References calc_zoom_to_bounding_box_factor(), and m_scene_box.

Referenced by Slic3r::GUI::Mouse3DController::State::apply(), and set_zoom().

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

◆ recover_from_free_camera()

void Slic3r::GUI::Camera::recover_from_free_camera ( )
inline
130 {
131 if (std::abs(get_dir_right()(2)) > EPSILON)
132 look_at(get_position(), m_target, Vec3d::UnitZ());
133 }
static constexpr double EPSILON
Definition libslic3r.h:51
void look_at(const Vec3d &position, const Vec3d &target, const Vec3d &up)
Definition Camera.cpp:531

References EPSILON, get_dir_right(), get_position(), look_at(), and m_target.

Referenced by Slic3r::GUI::Mouse3DController::disconnect_device(), and Slic3r::GUI::GLCanvas3D::on_mouse().

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

◆ rotate_local_around_target()

void Slic3r::GUI::Camera::rotate_local_around_target ( const Vec3d rotation_rad)
355{
356 const double angle = rotation_rad.norm();
357 if (std::abs(angle) > EPSILON) {
358 const Vec3d translation = m_view_matrix.translation() + m_view_rotation * m_target;
359 const Vec3d axis = m_view_rotation.conjugate() * rotation_rad.normalized();
363 update_zenit();
364 }
365}
EIGEN_DEVICE_FUNC Transform & fromPositionOrientationScale(const MatrixBase< PositionDerived > &position, const OrientationType &orientation, const MatrixBase< ScaleDerived > &scale)
EIGEN_DEVICE_FUNC Quaternion< Scalar > conjugate() const
Definition Quaternion.h:695
EIGEN_DEVICE_FUNC ConstTranslationPart translation() const
Definition Transform.h:410
Represents a 3D rotation as a rotation angle around an arbitrary 3D axis.
Definition AngleAxis.h:50
double angle(const Eigen::MatrixBase< Derived > &v1, const Eigen::MatrixBase< Derived2 > &v2)
Definition Point.hpp:112

References Slic3r::angle(), Eigen::QuaternionBase< Derived >::conjugate(), EPSILON, Eigen::Transform< _Scalar, _Dim, _Mode, _Options >::fromPositionOrientationScale(), m_target, m_view_matrix, m_view_rotation, Eigen::QuaternionBase< Derived >::normalize(), Eigen::Transform< _Scalar, _Dim, _Mode, _Options >::translation(), and update_zenit().

Referenced by Slic3r::GUI::Mouse3DController::State::apply().

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

◆ rotate_on_sphere()

void Slic3r::GUI::Camera::rotate_on_sphere ( double  delta_azimut_rad,
double  delta_zenit_rad,
bool  apply_limits 
)
333{
334 m_zenit += Geometry::rad2deg(delta_zenit_rad);
335 if (apply_limits) {
336 if (m_zenit > 90.0f) {
337 delta_zenit_rad -= Geometry::deg2rad(m_zenit - 90.0f);
338 m_zenit = 90.0f;
339 }
340 else if (m_zenit < -90.0f) {
341 delta_zenit_rad -= Geometry::deg2rad(m_zenit + 90.0f);
342 m_zenit = -90.0f;
343 }
344 }
345
346 const Vec3d translation = m_view_matrix.translation() + m_view_rotation * m_target;
347 const auto rot_z = Eigen::AngleAxisd(delta_azimut_rad, Vec3d::UnitZ());
348 m_view_rotation *= rot_z * Eigen::AngleAxisd(delta_zenit_rad, rot_z.inverse() * get_dir_right());
351}
AngleAxis< double > AngleAxisd
Definition AngleAxis.h:160
constexpr T deg2rad(const T angle)
Definition Geometry.hpp:289
float m_zenit
Definition Camera.hpp:35

References Slic3r::Geometry::deg2rad(), Eigen::Transform< _Scalar, _Dim, _Mode, _Options >::fromPositionOrientationScale(), get_dir_right(), m_target, m_view_matrix, m_view_rotation, m_zenit, Eigen::QuaternionBase< Derived >::normalize(), Slic3r::Geometry::rad2deg(), and Eigen::Transform< _Scalar, _Dim, _Mode, _Options >::translation().

Referenced by Slic3r::GUI::GLCanvas3D::on_mouse().

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

◆ select_next_type()

void Slic3r::GUI::Camera::select_next_type ( )
45{
46 unsigned char next = (unsigned char)m_type + 1;
47 if (next == (unsigned char)EType::Num_types)
48 next = 1;
49
50 set_type((EType)next);
51}
EType
Definition Camera.hpp:22
void set_type(EType type)
Definition Camera.cpp:35

References m_type, Num_types, and set_type().

+ Here is the call graph for this function:

◆ select_view()

void Slic3r::GUI::Camera::select_view ( const std::string &  direction)
75{
76 if (direction == "iso")
78 else if (direction == "left")
79 look_at(m_target - m_distance * Vec3d::UnitX(), m_target, Vec3d::UnitZ());
80 else if (direction == "right")
81 look_at(m_target + m_distance * Vec3d::UnitX(), m_target, Vec3d::UnitZ());
82 else if (direction == "top")
83 look_at(m_target + m_distance * Vec3d::UnitZ(), m_target, Vec3d::UnitY());
84 else if (direction == "bottom")
85 look_at(m_target - m_distance * Vec3d::UnitZ(), m_target, -Vec3d::UnitY());
86 else if (direction == "front")
87 look_at(m_target - m_distance * Vec3d::UnitY(), m_target, Vec3d::UnitZ());
88 else if (direction == "rear")
89 look_at(m_target + m_distance * Vec3d::UnitY(), m_target, Vec3d::UnitZ());
90}

References look_at(), m_distance, m_target, and set_default_orientation().

+ Here is the call graph for this function:

◆ set_default_orientation()

void Slic3r::GUI::Camera::set_default_orientation ( )
private
569{
570 m_zenit = 45.0f;
571 const double theta_rad = Geometry::deg2rad(-(double)m_zenit);
572 const double phi_rad = Geometry::deg2rad(45.0);
573 const double sin_theta = ::sin(theta_rad);
574 const Vec3d camera_pos = m_target + m_distance * Vec3d(sin_theta * ::sin(phi_rad), sin_theta * ::cos(phi_rad), ::cos(theta_rad));
575 m_view_rotation = Eigen::AngleAxisd(theta_rad, Vec3d::UnitX()) * Eigen::AngleAxisd(phi_rad, Vec3d::UnitZ());
578}
EIGEN_DEVICE_FUNC const CosReturnType cos() const
Definition ArrayCwiseUnaryOps.h:202
EIGEN_DEVICE_FUNC const SinReturnType sin() const
Definition ArrayCwiseUnaryOps.h:220

References cos(), Slic3r::Geometry::deg2rad(), Eigen::Transform< _Scalar, _Dim, _Mode, _Options >::fromPositionOrientationScale(), m_distance, m_target, m_view_matrix, m_view_rotation, m_zenit, Eigen::QuaternionBase< Derived >::normalize(), and sin().

Referenced by Camera(), and select_view().

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

◆ set_distance()

void Slic3r::GUI::Camera::set_distance ( double  distance)
private
524{
525 if (m_distance != distance) {
528 }
529}
EIGEN_DEVICE_FUNC Transform & translate(const MatrixBase< OtherDerived > &other)
double distance(const P &p1, const P &p2)
Definition geometry_traits.hpp:329

References get_dir_forward(), m_distance, m_view_matrix, and Eigen::Transform< _Scalar, _Dim, _Mode, _Options >::translate().

Referenced by calc_tight_frustrum_zs_around().

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

◆ set_scene_box()

void Slic3r::GUI::Camera::set_scene_box ( const BoundingBoxf3 box)
inline
74{ m_scene_box = box; }

References m_scene_box.

Referenced by Slic3r::GUI::GLCanvas3D::_render_thumbnail_internal().

+ Here is the caller graph for this function:

◆ set_target()

void Slic3r::GUI::Camera::set_target ( const Vec3d target)
54{
55 const Vec3d new_target = validate_target(target);
56 const Vec3d new_displacement = new_target - m_target;
57 if (!new_displacement.isApprox(Vec3d::Zero())) {
58 m_target = new_target;
59 m_view_matrix.translate(-new_displacement);
60 }
61}
Vec3d validate_target(const Vec3d &target) const
Definition Camera.cpp:580

References m_target, m_view_matrix, Eigen::Transform< _Scalar, _Dim, _Mode, _Options >::translate(), and validate_target().

Referenced by Slic3r::GUI::Mouse3DController::State::apply(), Slic3r::GUI::GLCanvas3D::on_mouse(), translate_world(), zoom_to_box(), and zoom_to_volumes().

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

◆ set_type() [1/2]

void Slic3r::GUI::Camera::set_type ( const std::string &  type)
inline
57{ set_type((type == "1") ? EType::Perspective : EType::Ortho); }

References Ortho, Perspective, and set_type().

Referenced by set_type().

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

◆ set_type() [2/2]

void Slic3r::GUI::Camera::set_type ( EType  type)
36{
37 if (m_type != type && (type == EType::Ortho || type == EType::Perspective)) {
38 m_type = type;
40 wxGetApp().app_config->set("use_perspective_camera", (m_type == EType::Perspective) ? "1" : "0");
41 }
42}

References m_type, m_update_config_on_type_change_enabled, Ortho, and Perspective.

Referenced by Slic3r::GUI::GLCanvas3D::_rectangular_selection_picking_pass(), Slic3r::GUI::GLCanvas3D::_render_thumbnail_internal(), and select_next_type().

+ Here is the caller graph for this function:

◆ set_viewport()

void Slic3r::GUI::Camera::set_viewport ( int  x,
int  y,
unsigned int  w,
unsigned int  h 
)
177{
178 m_viewport = { 0, 0, int(w), int(h) };
179}

References m_viewport.

Referenced by Slic3r::GUI::GLCanvas3D::_rectangular_selection_picking_pass(), Slic3r::GUI::GLCanvas3D::_render_thumbnail_internal(), and Slic3r::GUI::GLCanvas3D::render().

+ Here is the caller graph for this function:

◆ set_zoom()

void Slic3r::GUI::Camera::set_zoom ( double  zoom)
64{
65 // Don't allow to zoom too far outside the scene.
66 const double zoom_min = min_zoom();
67 if (zoom_min > 0.0)
68 zoom = std::max(zoom, zoom_min);
69
70 // Don't allow to zoom too close to the scene.
71 m_zoom = std::min(zoom, max_zoom());
72}
double min_zoom() const
Definition Camera.hpp:138
double max_zoom() const
Definition Camera.hpp:137

References m_zoom, max_zoom(), and min_zoom().

Referenced by Slic3r::GUI::GLCanvas3D::update_ui_from_settings(), and update_zoom().

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

◆ translate_world()

void Slic3r::GUI::Camera::translate_world ( const Vec3d displacement)
inline
116{ set_target(m_target + displacement); }
void set_target(const Vec3d &target)
Definition Camera.cpp:53

References m_target, and set_target().

+ Here is the call graph for this function:

◆ update_zenit()

void Slic3r::GUI::Camera::update_zenit ( )
private
595{
596 m_zenit = Geometry::rad2deg(0.5 * M_PI - std::acos(std::clamp(-get_dir_forward().dot(Vec3d::UnitZ()), -1.0, 1.0)));
597}
#define M_PI
Definition ExtrusionSimulator.cpp:20
T dot(const boost::geometry::model::d2::point_xy< T > &v1, const boost::geometry::model::d2::point_xy< T > &v2)
Definition ExtrusionSimulator.cpp:143

References Slic3r::dot(), get_dir_forward(), M_PI, m_zenit, and Slic3r::Geometry::rad2deg().

Referenced by look_at(), and rotate_local_around_target().

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

◆ update_zoom()

void Slic3r::GUI::Camera::update_zoom ( double  delta_zoom)
inline
70{ set_zoom(m_zoom / (1.0 - std::max(std::min(delta_zoom, 4.0), -4.0) * 0.1)); }
void set_zoom(double zoom)
Definition Camera.cpp:63

References m_zoom, and set_zoom().

Referenced by Slic3r::GUI::Mouse3DController::State::apply().

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

◆ validate_target()

Vec3d Slic3r::GUI::Camera::validate_target ( const Vec3d target) const
private
581{
582 BoundingBoxf3 test_box = m_scene_box;
583 test_box.translate(-m_scene_box.center());
584 // We may let this factor be customizable
585 static const double ScaleFactor = 1.5;
586 test_box.scale(ScaleFactor);
587 test_box.translate(m_scene_box.center());
588
589 return { std::clamp(target(0), test_box.min(0), test_box.max(0)),
590 std::clamp(target(1), test_box.min(1), test_box.max(1)),
591 std::clamp(target(2), test_box.min(2), test_box.max(2)) };
592}
PointType center() const
Definition BoundingBox.cpp:203
void translate(coordf_t x, coordf_t y, coordf_t z)
Definition BoundingBox.hpp:123

References Slic3r::BoundingBox3Base< PointType >::center(), m_scene_box, Slic3r::BoundingBoxBase< PointType, APointsType >::max, Slic3r::BoundingBoxBase< PointType, APointsType >::min, Slic3r::BoundingBoxBase< PointType, APointsType >::scale(), and Slic3r::BoundingBox3Base< PointType >::translate().

Referenced by set_target().

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

◆ zoom_to_box()

void Slic3r::GUI::Camera::zoom_to_box ( const BoundingBoxf3 box,
double  margin_factor = DefaultZoomToBoxMarginFactor 
)
258{
259 // Calculate the zoom factor needed to adjust the view around the given box.
260 const double zoom = calc_zoom_to_bounding_box_factor(box, margin_factor);
261 if (zoom > 0.0) {
262 m_zoom = zoom;
263 // center view around box center
264 set_target(box.center());
265 }
266}

References calc_zoom_to_bounding_box_factor(), Slic3r::BoundingBox3Base< PointType >::center(), m_zoom, and set_target().

Referenced by Slic3r::GUI::GLCanvas3D::_render_thumbnail_internal().

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

◆ zoom_to_volumes()

void Slic3r::GUI::Camera::zoom_to_volumes ( const GLVolumePtrs volumes,
double  margin_factor = DefaultZoomToVolumesMarginFactor 
)
269{
270 Vec3d center;
271 const double zoom = calc_zoom_to_volumes_factor(volumes, center, margin_factor);
272 if (zoom > 0.0) {
273 m_zoom = zoom;
274 // center view around the calculated center
275 set_target(center);
276 }
277}
double calc_zoom_to_volumes_factor(const GLVolumePtrs &volumes, Vec3d &center, double margin_factor=DefaultZoomToVolumesMarginFactor) const
Definition Camera.cpp:465

References calc_zoom_to_volumes_factor(), m_zoom, and set_target().

+ Here is the call graph for this function:

Member Data Documentation

◆ DefaultDistance

const double Slic3r::GUI::Camera::DefaultDistance = 1000.0
static

◆ DefaultZoomToBoxMarginFactor

const double Slic3r::GUI::Camera::DefaultZoomToBoxMarginFactor = 1.025
static

◆ DefaultZoomToVolumesMarginFactor

const double Slic3r::GUI::Camera::DefaultZoomToVolumesMarginFactor = 1.025
static

◆ FrustrumMinNearZ

double Slic3r::GUI::Camera::FrustrumMinNearZ = 100.0
static

◆ FrustrumMinZRange

double Slic3r::GUI::Camera::FrustrumMinZRange = 50.0
static

◆ FrustrumZMargin

double Slic3r::GUI::Camera::FrustrumZMargin = 10.0
static

◆ m_distance

◆ m_frustrum_zs

std::pair<double, double> Slic3r::GUI::Camera::m_frustrum_zs
private

◆ m_gui_scale

double Slic3r::GUI::Camera::m_gui_scale { 1.0 }
private

Referenced by apply_projection(), and get_gui_scale().

◆ m_projection_matrix

◆ m_scene_box

BoundingBoxf3 Slic3r::GUI::Camera::m_scene_box
private

◆ m_target

◆ m_type

◆ m_update_config_on_type_change_enabled

bool Slic3r::GUI::Camera::m_update_config_on_type_change_enabled { false }
private

◆ m_view_matrix

◆ m_view_rotation

Eigen::Quaterniond Slic3r::GUI::Camera::m_view_rotation { 1.0, 0.0, 0.0, 0.0 }
private

◆ m_viewport

std::array<int, 4> Slic3r::GUI::Camera::m_viewport
private

◆ m_zenit

float Slic3r::GUI::Camera::m_zenit { 45.0f }
private

◆ m_zoom

double Slic3r::GUI::Camera::m_zoom { 1.0 }
private

◆ MaxFovDeg

double Slic3r::GUI::Camera::MaxFovDeg = 60.0
static

◆ requires_zoom_to_bed

bool Slic3r::GUI::Camera::requires_zoom_to_bed { false }

The documentation for this struct was generated from the following files: