ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvShiftedObject.cpp
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 #include "ecvShiftedObject.h"
9 
10 #include <CVLog.h>
11 
12 // LOCAL
13 #include "ecvBBox.h"
14 #include "ecvSerializableObject.h"
15 
17  : ccHObject(name), m_globalShift(0, 0, 0), m_globalScale(1.0) {}
18 
20  : ccHObject(s),
21  m_globalShift(s.m_globalShift),
22  m_globalScale(s.m_globalScale) {}
23 
27 }
28 
30  m_globalShift = shift;
31 }
32 
33 void ccShiftedObject::setGlobalScale(double scale) {
34  if (scale == 0) {
35  CVLog::Warning("[setGlobalScale] Invalid scale (zero)!");
36  m_globalScale = 1.0;
37  } else {
38  m_globalScale = scale;
39  }
40 }
41 
42 bool ccShiftedObject::saveShiftInfoToFile(QFile& out) const {
43  //'coordinates shift'
44  if (out.write((const char*)m_globalShift.u, sizeof(double) * 3) < 0)
46  //'global scale'
47  if (out.write((const char*)&m_globalScale, sizeof(double)) < 0)
49 
50  return true;
51 }
52 
54  //'coordinates shift'
55  if (in.read((char*)m_globalShift.u, sizeof(double) * 3) < 0)
57  //'global scale'
58  if (in.read((char*)&m_globalScale, sizeof(double)) < 0)
60 
61  return true;
62 }
63 
65  CCVector3d& maxCorner) {
66  ccBBox box = getOwnBB(false);
67  minCorner = toGlobal3d(box.minCorner());
68  maxCorner = toGlobal3d(box.maxCorner());
69  return box.isValid();
70 }
71 
73  bool withGLFeatures /*=false*/) {
74  ccBBox box = getOwnBB(false);
75  CCVector3d minCorner = toGlobal3d(box.minCorner());
76  CCVector3d maxCorner = toGlobal3d(box.maxCorner());
77  return GlobalBoundingBox(minCorner, maxCorner);
78 }
std::string name
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
Definition: CVLog.cpp:133
Type u[3]
Definition: CVGeom.h:139
Bounding box structure.
Definition: ecvBBox.h:25
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
cloudViewer::BoundingBoxTpl< double > GlobalBoundingBox
Global (non-shifted) bounding-box.
Definition: ecvHObject.h:436
virtual ccBBox getOwnBB(bool withGLFeatures=false)
Returns the entity's own bounding-box.
Definition: ecvHObject.cpp:757
static bool ReadError()
Sends a custom error message (read error) and returns 'false'.
static bool WriteError()
Sends a custom error message (write error) and returns 'false'.
Shifted entity interface.
double m_globalScale
Global scale (typically applied at loading time)
CCVector3d m_globalShift
Global shift (typically applied at loading time)
bool loadShiftInfoFromFile(QFile &in)
Serialization helper (input)
bool getOwnGlobalBB(CCVector3d &minCorner, CCVector3d &maxCorner) override
CCVector3d toGlobal3d(const Vector3Tpl< T > &Plocal) const
Returns the point back-projected into the original coordinates system.
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 setGlobalScale(double scale)
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
const Vector3Tpl< T > & maxCorner() const
Returns max corner (const)
Definition: BoundingBox.h:156
const Vector3Tpl< T > & minCorner() const
Returns min corner (const)
Definition: BoundingBox.h:154
bool isValid() const
Returns whether bounding box is valid or not.
Definition: BoundingBox.h:203