ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvShiftedObject.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 // Local
11 #include "ecvHObject.h"
12 
14 
19 public:
21  ccShiftedObject(QString name = QString());
24 
26 
29 
31 
33  virtual inline void setGlobalShift(double x, double y, double z) {
34  return setGlobalShift(CCVector3d(x, y, z));
35  }
36 
38 
41  virtual void setGlobalShift(const CCVector3d& shift);
42 
44 
46  virtual const CCVector3d& getGlobalShift() const { return m_globalShift; }
47 
50  virtual void setGlobalScale(double scale);
51 
53  virtual double getGlobalScale() const { return m_globalScale; }
54 
56  inline bool isShifted() const {
57  const CCVector3d& globalShift = getGlobalShift();
58  return (globalShift.x != 0 || globalShift.y != 0 ||
59  globalShift.z != 0 || getGlobalScale() != 1.0);
60  }
61 
63  template <typename T>
64  inline CCVector3d toGlobal3d(const Vector3Tpl<T>& Plocal) const {
65  // Pglobal = Plocal/scale - shift
66  return Plocal.toDouble() / getGlobalScale() - getGlobalShift();
67  }
68 
70  template <typename T>
71  inline CCVector3d toLocal3d(const Vector3Tpl<T>& Pglobal) const {
72  // Plocal = (Pglobal + shift) * scale
73  return (Pglobal.toDouble() + getGlobalShift()) * getGlobalScale();
74  }
76  template <typename T>
77  inline CCVector3 toLocal3pc(const Vector3Tpl<T>& Pglobal) const {
78  CCVector3d Plocal =
79  Pglobal.toDouble() * getGlobalScale() + getGlobalShift();
80  return Plocal.toPC();
81  }
82 
83  // inherited from ccHObject
84  bool getOwnGlobalBB(CCVector3d& minCorner, CCVector3d& maxCorner) override;
85  GlobalBoundingBox getOwnGlobalBB(bool withGLFeatures = false) override;
86 
87 protected:
89  bool saveShiftInfoToFile(QFile& out) const;
91  bool loadShiftInfoFromFile(QFile& in);
92 
95 
97  double m_globalScale;
98 };
Vector3Tpl< double > CCVector3d
Double 3D Vector.
Definition: CVGeom.h:804
#define CV_DB_LIB_API
Definition: CV_db.h:15
std::string name
Type y
Definition: CVGeom.h:137
Type x
Definition: CVGeom.h:137
Type z
Definition: CVGeom.h:137
Vector3Tpl< PointCoordinateType > toPC() const
Definition: CVGeom.h:263
Vector3Tpl< double > toDouble() const
Cast operator to a double vector (explicit call version)
Definition: CVGeom.h:255
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
Shifted entity interface.
double m_globalScale
Global scale (typically applied at loading time)
CCVector3d m_globalShift
Global shift (typically applied at loading time)
ccShiftedObject(const ccShiftedObject &s)
Copy constructor.
bool loadShiftInfoFromFile(QFile &in)
Serialization helper (input)
virtual void setGlobalScale(double scale)
bool getOwnGlobalBB(CCVector3d &minCorner, CCVector3d &maxCorner) override
CCVector3d toGlobal3d(const Vector3Tpl< T > &Plocal) const
Returns the point back-projected into the original coordinates system.
CCVector3 toLocal3pc(const Vector3Tpl< T > &Pglobal) const
Returns the point projected into the local (shifted) coordinates system.
CCVector3d toLocal3d(const Vector3Tpl< T > &Pglobal) const
Returns the point projected into the local (shifted) coordinates system.
GlobalBoundingBox getOwnGlobalBB(bool withGLFeatures=false) override
bool isShifted() const
Returns whether the cloud is shifted or not.
virtual void setGlobalShift(double x, double y, double z)
Sets shift applied to original coordinates (information storage only)
virtual const CCVector3d & getGlobalShift() const
Returns the shift applied to original coordinates.
virtual void setGlobalShift(const CCVector3d &shift)
Sets shift applied to original coordinates (information storage only)
virtual double getGlobalScale() const
Returns the scale applied to original coordinates.
void copyGlobalShiftAndScale(const ccShiftedObject &s)
Copies the Global Shift and Scale from another entity.
ccShiftedObject(QString name=QString())
Default constructor.
bool saveShiftInfoToFile(QFile &out) const
Serialization helper (output)
Bounding box structure.
Definition: BoundingBox.h:25