Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
igl::Camera Class Reference

#include <src/libigl/igl/Camera.h>

Public Member Functions

 Camera ()
 
virtual ~Camera ()
 
Eigen::Matrix4d projection () const
 
Eigen::Affine3d affine () const
 
Eigen::Affine3d inverse () const
 
Eigen::Vector3d eye () const
 
Eigen::Vector3d at () const
 
Eigen::Vector3d up () const
 
Eigen::Vector3d unit_plane () const
 
void dolly (const Eigen::Vector3d &dv)
 
void push_away (const double s)
 
void dolly_zoom (const double da)
 
void turn_eye (const Eigen::Quaterniond &q)
 
void orbit (const Eigen::Quaterniond &q)
 
void look_at (const Eigen::Vector3d &eye, const Eigen::Vector3d &at, const Eigen::Vector3d &up)
 

Public Attributes

double m_angle
 
double m_aspect
 
double m_near
 
double m_far
 
double m_at_dist
 
bool m_orthographic
 
Eigen::Quaterniond m_rotation_conj
 
Eigen::Vector3d m_translation
 

Detailed Description

Constructor & Destructor Documentation

◆ Camera()

igl::Camera::Camera ( )
inline
153 :
154 m_angle(45.0),m_aspect(1),m_near(1e-2),m_far(100),m_at_dist(1),
155 m_orthographic(false),
156 m_rotation_conj(1,0,0,0),
157 m_translation(0,0,1)
158{
159}
double m_aspect
Definition Camera.h:45
double m_far
Definition Camera.h:45
double m_near
Definition Camera.h:45
double m_at_dist
Definition Camera.h:45
bool m_orthographic
Definition Camera.h:46
Eigen::Quaterniond m_rotation_conj
Definition Camera.h:47
double m_angle
Definition Camera.h:45
Eigen::Vector3d m_translation
Definition Camera.h:48

◆ ~Camera()

virtual igl::Camera::~Camera ( )
inlinevirtual
51{}

Member Function Documentation

◆ affine()

Eigen::Affine3d igl::Camera::affine ( ) const
inline
200{
201 using namespace Eigen;
202 Affine3d t = Affine3d::Identity();
205 return t;
206}
EIGEN_DEVICE_FUNC Transform & rotate(const RotationType &rotation)
EIGEN_DEVICE_FUNC Quaternion< Scalar > conjugate() const
Definition Quaternion.h:695
EIGEN_DEVICE_FUNC Transform & translate(const MatrixBase< OtherDerived > &other)
Represents an homogeneous transformation in a N dimensional space.
Definition Transform.h:202
Definition LDLT.h:16

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

+ Here is the call graph for this function:

◆ at()

Eigen::Vector3d igl::Camera::at ( ) const
inline
224{
225 using namespace Eigen;
226 return affine() * (Vector3d(0,0,-1)*m_at_dist);
227}
Eigen::Affine3d affine() const
Definition Camera.h:199

◆ dolly()

void igl::Camera::dolly ( const Eigen::Vector3d &  dv)
inline
250{
251 m_translation += dv;
252}

◆ dolly_zoom()

void igl::Camera::dolly_zoom ( const double  da)
inline
267{
268 using namespace std;
269 using namespace Eigen;
270#ifndef NDEBUG
271 Vector3d old_at = at();
272#endif
273 const double old_angle = m_angle;
274 if(old_angle + da < IGL_CAMERA_MIN_ANGLE)
275 {
276 m_orthographic = true;
277 }else if(old_angle + da > IGL_CAMERA_MIN_ANGLE)
278 {
279 m_orthographic = false;
280 }
281 if(!m_orthographic)
282 {
283 m_angle += da;
285 // change in distance
286 const double s =
287 (2.*tan(old_angle/2./180.*igl::PI)) /
288 (2.*tan(m_angle/2./180.*igl::PI)) ;
289 const double old_at_dist = m_at_dist;
290 m_at_dist = old_at_dist * s;
291 dolly(Vector3d(0,0,1)*(m_at_dist - old_at_dist));
292 assert((old_at-at()).squaredNorm() < DOUBLE_EPS);
293 }
294}
EIGEN_DEVICE_FUNC const TanReturnType tan() const
Definition ArrayCwiseUnaryOps.h:234
#define IGL_CAMERA_MIN_ANGLE
Definition Camera.h:21
Eigen::Vector3d at() const
Definition Camera.h:223
void dolly(const Eigen::Vector3d &dv)
Definition Camera.h:249
IGL_INLINE void min(const Eigen::SparseMatrix< AType > &A, const int dim, Eigen::PlainObjectBase< DerivedB > &B, Eigen::PlainObjectBase< DerivedI > &I)
Definition min.cpp:6
IGL_INLINE void max(const Eigen::SparseMatrix< AType > &A, const int dim, Eigen::PlainObjectBase< DerivedB > &B, Eigen::PlainObjectBase< DerivedI > &I)
Definition max.cpp:6
const double PI
Definition PI.h:16
const double DOUBLE_EPS
Definition EPS.h:14
STL namespace.

References igl::DOUBLE_EPS, IGL_CAMERA_MIN_ANGLE, igl::max(), igl::min(), igl::PI, and tan().

+ Here is the call graph for this function:

◆ eye()

Eigen::Vector3d igl::Camera::eye ( ) const
inline
218{
219 using namespace Eigen;
220 return affine() * Vector3d(0,0,0);
221}

◆ inverse()

Eigen::Affine3d igl::Camera::inverse ( ) const
inline
209{
210 using namespace Eigen;
211 Affine3d t = Affine3d::Identity();
214 return t;
215}

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

+ Here is the call graph for this function:

◆ look_at()

void igl::Camera::look_at ( const Eigen::Vector3d &  eye,
const Eigen::Vector3d &  at,
const Eigen::Vector3d &  up 
)
inline
329{
330 using namespace Eigen;
331 using namespace std;
332 // http://www.opengl.org/sdk/docs/man2/xhtml/gluLookAt.xml
333 // Normalize vector from at to eye
334 Vector3d F = eye-at;
335 m_at_dist = F.norm();
336 F.normalize();
337 // Project up onto plane orthogonal to F and normalize
338 assert(up.cross(F).norm() > DOUBLE_EPS && "(eye-at) x up ≈ 0");
339 const Vector3d proj_up = (up-(up.dot(F))*F).normalized();
341 a.setFromTwoVectors(Vector3d(0,0,-1),-F);
342 b.setFromTwoVectors(a*Vector3d(0,1,0),proj_up);
345 //cout<<"m_at_dist: "<<m_at_dist<<endl;
346 //cout<<"proj_up: "<<proj_up.transpose()<<endl;
347 //cout<<"F: "<<F.transpose()<<endl;
348 //cout<<"eye(): "<<this->eye().transpose()<<endl;
349 //cout<<"at(): "<<this->at().transpose()<<endl;
350 //cout<<"eye()-at(): "<<(this->eye()-this->at()).normalized().transpose()<<endl;
351 //cout<<"eye-this->eye(): "<<(eye-this->eye()).squaredNorm()<<endl;
352 assert( (eye-this->eye()).squaredNorm() < DOUBLE_EPS);
353 //assert((F-(this->eye()-this->at()).normalized()).squaredNorm() <
354 // DOUBLE_EPS);
355 assert( (at-this->at()).squaredNorm() < DOUBLE_EPS);
356 //assert( (proj_up-this->up()).squaredNorm() < DOUBLE_EPS);
357}
EIGEN_DEVICE_FUNC ConjugateReturnType conjugate() const
Definition CommonCwiseUnaryOps.h:74
Eigen::Vector3d eye() const
Definition Camera.h:217
Eigen::Vector3d up() const
Definition Camera.h:229
The quaternion class used to represent 3D orientations and rotations.
Definition Quaternion.h:233
@ F
Definition libslic3r.h:102

References conjugate(), and igl::DOUBLE_EPS.

+ Here is the call graph for this function:

◆ orbit()

void igl::Camera::orbit ( const Eigen::Quaterniond q)
inline
310{
311 using namespace Eigen;
312 Vector3d old_at = at();
313 // at should be fixed
314 //
315 // at_1 = R_1 * t_1 - R_1 * z = at_0
316 // t_1 = R_1' * (at_0 + R_1 * z)
320 (old_at +
321 m_rotation_conj.conjugate() * Vector3d(0,0,1) * m_at_dist);
322 assert((old_at - at()).squaredNorm() < DOUBLE_EPS);
323}

References Eigen::QuaternionBase< Derived >::conjugate(), and igl::DOUBLE_EPS.

+ Here is the call graph for this function:

◆ projection()

Eigen::Matrix4d igl::Camera::projection ( ) const
inline
162{
163 Eigen::Matrix4d P;
164 using namespace std;
165 const double far = m_at_dist + m_far;
166 const double near = m_near;
167 // http://stackoverflow.com/a/3738696/148668
169 {
170 const double f = 0.5;
171 const double left = -f*m_aspect;
172 const double right = f*m_aspect;
173 const double bottom = -f;
174 const double top = f;
175 const double tx = (right+left)/(right-left);
176 const double ty = (top+bottom)/(top-bottom);
177 const double tz = (far+near)/(far-near);
178 const double z_fix = 0.5 /m_at_dist / tan(m_angle*0.5 * (igl::PI/180.) );
179 P<<
180 z_fix*2./(right-left), 0, 0, -tx,
181 0, z_fix*2./(top-bottom), 0, -ty,
182 0, 0, -z_fix*2./(far-near), -tz,
183 0, 0, 0, 1;
184 }else
185 {
186 const double yScale = tan(PI*0.5 - 0.5*m_angle*PI/180.);
187 // http://stackoverflow.com/a/14975139/148668
188 const double xScale = yScale/m_aspect;
189 P<<
190 xScale, 0, 0, 0,
191 0, yScale, 0, 0,
192 0, 0, -(far+near)/(far-near), -1,
193 0, 0, -2.*near*far/(far-near), 0;
194 P = P.transpose().eval();
195 }
196 return P;
197}

References igl::PI, and tan().

+ Here is the call graph for this function:

◆ push_away()

void igl::Camera::push_away ( const double  s)
inline
255{
256 using namespace Eigen;
257#ifndef NDEBUG
258 Vector3d old_at = at();
259#endif
260 const double old_at_dist = m_at_dist;
261 m_at_dist = old_at_dist * s;
262 dolly(Vector3d(0,0,1)*(m_at_dist - old_at_dist));
263 assert((old_at-at()).squaredNorm() < DOUBLE_EPS);
264}

References igl::DOUBLE_EPS.

◆ turn_eye()

void igl::Camera::turn_eye ( const Eigen::Quaterniond q)
inline
297{
298 using namespace Eigen;
299 Vector3d old_eye = eye();
300 // eye should be fixed
301 //
302 // eye_1 = R_1 * t_1 = eye_0
303 // t_1 = R_1' * eye_0
305 m_translation = m_rotation_conj * old_eye;
306 assert((old_eye - eye()).squaredNorm() < DOUBLE_EPS);
307}

References Eigen::QuaternionBase< Derived >::conjugate(), and igl::DOUBLE_EPS.

+ Here is the call graph for this function:

◆ unit_plane()

Eigen::Vector3d igl::Camera::unit_plane ( ) const
inline
238{
239 // Distance of center pixel to eye
240 const double d = 1.0;
241 const double a = m_aspect;
242 const double theta = m_angle*PI/180.;
243 const double w =
244 2.*sqrt(-d*d/(a*a*pow(tan(0.5*theta),2.)-1.))*a*tan(0.5*theta);
245 const double h = w/a;
246 return Eigen::Vector3d(w*0.5,h*0.5,-d);
247}
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
Definition ArrayCwiseUnaryOps.h:152
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half pow(const half &a, const half &b)
Definition Half.h:477

References igl::PI, sqrt(), and tan().

+ Here is the call graph for this function:

◆ up()

Eigen::Vector3d igl::Camera::up ( ) const
inline
230{
231 using namespace Eigen;
232 Affine3d t = Affine3d::Identity();
234 return t * Vector3d(0,1,0);
235}

References Eigen::Transform< _Scalar, _Dim, _Mode, _Options >::rotate().

+ Here is the call graph for this function:

Member Data Documentation

◆ m_angle

double igl::Camera::m_angle

◆ m_aspect

double igl::Camera::m_aspect

◆ m_at_dist

double igl::Camera::m_at_dist

◆ m_far

double igl::Camera::m_far

◆ m_near

double igl::Camera::m_near

◆ m_orthographic

bool igl::Camera::m_orthographic

◆ m_rotation_conj

Eigen::Quaterniond igl::Camera::m_rotation_conj

◆ m_translation

Eigen::Vector3d igl::Camera::m_translation

The documentation for this class was generated from the following file: