ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
LineSet.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 "LineSet.h"
9 
10 #include <numeric>
11 
12 #include "ecvBBox.h"
13 #include "ecvDisplayTools.h"
14 #include "ecvOrientedBBox.h"
15 
16 namespace cloudViewer {
17 namespace geometry {
18 
20  points_.clear();
21  lines_.clear();
22  colors_.clear();
23  return *this;
24 }
25 
26 ccBBox LineSet::getOwnBB(bool withGLFeatures) {
28 }
29 
31  bool is_empty = !HasPoints() || !HasLines();
32 
33  if (is_empty) return;
34 
36  if (isColorOverridden()) {
37  context.defaultPolylineColor = getTempColor();
38  } /*
39  else if (colorsShown() && HasColors())
40  {
41  context.defaultPolylineColor =
42  ecvColor::Rgb::FromEigen(colors_[0]);
43  }*/
44  context.currentLineWidth = 1;
46  }
47 }
48 
49 Eigen::Vector3d LineSet::GetMinBound() const {
50  return ComputeMinBound(points_);
51 }
52 
53 Eigen::Vector3d LineSet::GetMaxBound() const {
54  return ComputeMaxBound(points_);
55 }
56 
57 Eigen::Vector3d LineSet::GetCenter() const { return ComputeCenter(points_); }
58 
61 }
62 
65 }
66 
67 LineSet &LineSet::Transform(const Eigen::Matrix4d &transformation) {
68  TransformPoints(transformation, points_);
69  return *this;
70 }
71 
72 LineSet &LineSet::Translate(const Eigen::Vector3d &translation, bool relative) {
73  TranslatePoints(translation, points_, relative);
74  return *this;
75 }
76 
77 LineSet &LineSet::Scale(const double s, const Eigen::Vector3d &center) {
78  ScalePoints(s, points_, center);
79  return *this;
80 }
81 
82 LineSet &LineSet::Rotate(const Eigen::Matrix3d &R,
83  const Eigen::Vector3d &center) {
84  RotatePoints(R, points_, center);
85  return *this;
86 }
87 
89  if (lineset.IsEmpty()) return (*this);
90  size_t old_point_num = points_.size();
91  size_t add_point_num = lineset.points_.size();
92  size_t new_point_num = old_point_num + add_point_num;
93  size_t old_line_num = lines_.size();
94  size_t add_line_num = lineset.lines_.size();
95  size_t new_line_num = old_line_num + add_line_num;
96 
97  if ((!HasLines() || HasColors()) && lineset.HasColors()) {
98  colors_.resize(new_line_num);
99  for (size_t i = 0; i < add_line_num; i++) {
100  colors_[old_line_num + i] = lineset.colors_[i];
101  }
102  } else {
103  colors_.clear();
104  }
105  points_.resize(new_point_num);
106  for (size_t i = 0; i < add_point_num; i++) {
107  points_[old_point_num + i] = lineset.points_[i];
108  }
109  lines_.resize(new_line_num);
110  for (size_t i = 0; i < add_line_num; i++) {
111  lines_[old_line_num + i] =
112  Eigen::Vector2i(lineset.lines_[i](0) + (int)old_point_num,
113  lineset.lines_[i](1) + (int)old_point_num);
114  }
115  return (*this);
116 }
117 
118 LineSet LineSet::operator+(const LineSet &lineset) const {
119  return (LineSet(*this) += lineset);
120 }
121 
122 } // namespace geometry
123 } // namespace cloudViewer
Bounding box structure.
Definition: ecvBBox.h:25
static ccBBox CreateFromPoints(const std::vector< CCVector3 > &points)
Definition: ecvBBox.cpp:82
virtual bool isColorOverridden() const
virtual const ecvColor::Rgb & getTempColor() const
Returns current temporary (unique) color.
static Eigen::Vector3d ComputeMinBound(const std::vector< Eigen::Vector3d > &points)
Compute min bound of a list points.
Definition: ecvHObject.cpp:272
static Eigen::Vector3d ComputeCenter(const std::vector< Eigen::Vector3d > &points)
Computer center of a list of points.
Definition: ecvHObject.cpp:296
static void TranslatePoints(const Eigen::Vector3d &translation, std::vector< Eigen::Vector3d > &points, bool relative)
Apply translation to the geometry coordinates.
Definition: ecvHObject.cpp:333
static void RotatePoints(const Eigen::Matrix3d &R, std::vector< Eigen::Vector3d > &points, const Eigen::Vector3d &center)
Rotate all points with the rotation matrix R.
Definition: ecvHObject.cpp:353
static void TransformPoints(const Eigen::Matrix4d &transformation, std::vector< Eigen::Vector3d > &points)
Transforms all points with the transformation matrix.
Definition: ecvHObject.cpp:307
static void ScalePoints(const double scale, std::vector< Eigen::Vector3d > &points, const Eigen::Vector3d &center)
Scale the coordinates of all points by the scaling factor scale.
Definition: ecvHObject.cpp:345
static Eigen::Vector3d ComputeMaxBound(const std::vector< Eigen::Vector3d > &points)
Compute max bound of a list points.
Definition: ecvHObject.cpp:284
LineSet define a sets of lines in 3D. A typical application is to display the point cloud corresponde...
Definition: LineSet.h:29
bool HasColors() const
Returns true if the objects lines contains colors.
Definition: LineSet.h:85
virtual void drawMeOnly(CC_DRAW_CONTEXT &context) override
Draws the entity only (not its children)
Definition: LineSet.cpp:30
virtual bool IsEmpty() const override
Definition: LineSet.h:61
LineSet & operator+=(const LineSet &lineset)
Definition: LineSet.cpp:88
virtual ecvOrientedBBox GetOrientedBoundingBox() const override
Definition: LineSet.cpp:63
virtual LineSet & Rotate(const Eigen::Matrix3d &R, const Eigen::Vector3d &center) override
Apply rotation to the geometry coordinates and normals. Given a rotation matrix , and center ,...
Definition: LineSet.cpp:82
std::vector< Eigen::Vector3d > points_
Points coordinates.
Definition: LineSet.h:156
std::vector< Eigen::Vector3d > colors_
RGB colors of lines.
Definition: LineSet.h:160
LineSet(const char *name="LineSet")
Default Constructor.
Definition: LineSet.h:32
bool HasLines() const
Returns true if the object contains lines.
Definition: LineSet.h:82
virtual Eigen::Vector3d GetCenter() const override
Returns the center of the geometry coordinates.
Definition: LineSet.cpp:57
LineSet operator+(const LineSet &lineset) const
Definition: LineSet.cpp:118
std::vector< Eigen::Vector2i > lines_
Lines denoted by the index of points forming the line.
Definition: LineSet.h:158
virtual Eigen::Vector3d GetMaxBound() const override
Returns max bounds for geometry coordinates.
Definition: LineSet.cpp:53
virtual ccBBox getOwnBB(bool withGLFeatures=false) override
Returns the entity's own bounding-box.
Definition: LineSet.cpp:26
virtual LineSet & Scale(const double s, const Eigen::Vector3d &center) override
Apply scaling to the geometry coordinates. Given a scaling factor , and center , a given point is tr...
Definition: LineSet.cpp:77
virtual LineSet & Translate(const Eigen::Vector3d &translation, bool relative=true) override
Apply translation to the geometry coordinates.
Definition: LineSet.cpp:72
virtual LineSet & Transform(const Eigen::Matrix4d &transformation) override
Apply transformation (4x4 matrix) to the geometry coordinates.
Definition: LineSet.cpp:67
virtual ccBBox GetAxisAlignedBoundingBox() const override
Returns an axis-aligned bounding box of the geometry.
Definition: LineSet.cpp:59
bool HasPoints() const
Returns true if the object contains points.
Definition: LineSet.h:79
virtual Eigen::Vector3d GetMinBound() const override
Returns min bounds for geometry coordinates.
Definition: LineSet.cpp:49
static void Draw(const CC_DRAW_CONTEXT &context, const ccHObject *obj)
static QWidget * GetMainScreen()
static ecvOrientedBBox CreateFromPoints(const std::vector< Eigen::Vector3d > &points)
#define MACRO_Draw3D(context)
ImGuiContext * context
Definition: Window.cpp:76
Generic file read and write utility for python interface.
Eigen::Matrix< Index, 2, 1 > Vector2i
Definition: knncpp.h:29
Display context.