Visual Computing Library  devel
Loading...
Searching...
No Matches
drawable_lines.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_BGFX_DRAWABLE_DRAWABLE_LINES_H
24#define VCL_BGFX_DRAWABLE_DRAWABLE_LINES_H
25
26#include <vclib/bgfx/context.h>
27#include <vclib/bgfx/primitives/lines.h>
28#include <vclib/render/drawable/drawable_object.h>
29
30#include <bgfx/bgfx.h>
31
32namespace vcl {
33
35{
36 bool mVisible = true;
37 bool mUseLineIndices = false; // true whether a vector of line indices has
38 // been provided (even if empty)
39
40 std::vector<float> mVertCoords;
41 std::vector<uint> mVertColors;
42 std::vector<float> mVertNormals;
43 std::vector<uint> mLineColors;
44 std::vector<uint> mLineIndices;
45
46public:
47 DrawableLines() = default;
48
50 const std::vector<float>& vertCoords,
51 const std::vector<float>& vertNormals = std::vector<float>(),
52 const std::vector<uint>& vertColors = std::vector<uint>(),
53 const std::vector<uint>& lineColors = std::vector<uint>())
54 {
56 }
57
59 const std::vector<float>& vertCoords,
60 const std::vector<uint>& lineIndices,
61 const std::vector<float>& vertNormals = std::vector<float>(),
62 const std::vector<uint>& vertColors = std::vector<uint>(),
63 const std::vector<uint>& lineColors = std::vector<uint>())
64 {
66 }
67
69 DrawableObject(other), mVertCoords(other.mVertCoords),
70 Lines(
71 other.mVertCoords,
72 other.mLineIndices,
73 other.mVertNormals,
74 other.mVertColors,
75 other.mLineColors,
76 other.thickness(),
77 other.shadingPerVertex(),
78 other.colorToUse(),
79 other.implementationType()),
80 mVisible(other.mVisible), mUseLineIndices(other.mUseLineIndices),
81 mVertColors(other.mVertColors), mVertNormals(other.mVertNormals),
82 mLineColors(other.mLineColors), mLineIndices(other.mLineIndices)
83 {
84 }
85
87
88 ~DrawableLines() = default;
89
91 {
92 swap(other);
93 return *this;
94 }
95
96 void swap(DrawableLines& other)
97 {
98 using std::swap;
100 swap(static_cast<Lines&>(*this), static_cast<Lines&>(other));
101
102 swap(mVisible, other.mVisible);
103 swap(mUseLineIndices, other.mUseLineIndices);
104
105 swap(mVertCoords, other.mVertCoords);
106 swap(mLineIndices, other.mLineIndices);
107 swap(mVertColors, other.mVertColors);
108 swap(mVertNormals, other.mVertNormals);
109 swap(mLineColors, other.mLineColors);
110 }
111
112 friend void swap(DrawableLines& first, DrawableLines& second)
113 {
114 first.swap(second);
115 }
116
117 void setPoints(
118 const std::vector<float>& vertCoords,
119 const std::vector<float>& vertNormals,
120 const std::vector<uint>& vertColors,
121 const std::vector<uint>& lineColors)
122 {
123 mUseLineIndices = false;
124 mVertCoords = vertCoords;
125 mVertColors = vertColors;
126 mVertNormals = vertNormals;
127 mLineColors = lineColors;
129 }
130
131 void setPoints(
132 const std::vector<float>& vertCoords,
133 const std::vector<uint>& lineIndices,
134 const std::vector<float>& vertNormals,
135 const std::vector<uint>& vertColors,
136 const std::vector<uint>& lineColors)
137 {
138 mUseLineIndices = true;
139 mVertCoords = vertCoords;
140 mLineIndices = lineIndices;
141 mVertColors = vertColors;
142 mVertNormals = vertNormals;
143 mLineColors = lineColors;
146 }
147
148 // DrawableObject interface
149
150 void draw(const DrawObjectSettings& settings) const override
151 {
152 Lines::draw(settings.viewId);
153 }
154
155 vcl::Box3d boundingBox() const override
156 {
157 return vcl::Box3d(vcl::Point3d(-1, -1, -1), vcl::Point3d(1, 1, 1));
158 }
159
160 std::shared_ptr<DrawableObject> clone() const& override
161 {
162 return std::make_shared<DrawableLines>(*this);
163 }
164
165 std::shared_ptr<DrawableObject> clone() && override
166 {
167 return std::make_shared<DrawableLines>(std::move(*this));
168 }
169
170 bool isVisible() const override { return mVisible; }
171
172 void setVisibility(bool vis) override { mVisible = vis; }
173
174 void setImplementationType(ImplementationType type)
175 {
176 if (mUseLineIndices) {
178 mVertCoords,
179 mLineIndices,
180 mVertNormals,
181 mVertColors,
182 mLineColors,
183 type);
184 }
185 else {
187 mVertCoords, mVertNormals, mVertColors, mLineColors, type);
188 }
189 }
190};
191
192} // namespace vcl
193
194#endif // VCL_BGFX_DRAWABLE_DRAWABLE_LINES_H
A class representing a box in N-dimensional space.
Definition box.h:46
Definition drawable_lines.h:35
vcl::Box3d boundingBox() const override
This member function is used to find a good camera position to render object. It should return the th...
Definition drawable_lines.h:155
std::shared_ptr< DrawableObject > clone() &&override
This member function is used to create a new DrawableObject that is a moved from the current one....
Definition drawable_lines.h:165
std::shared_ptr< DrawableObject > clone() const &override
This member function is used to create a new copy of the DrawableObject. Each derived class must impl...
Definition drawable_lines.h:160
void draw(const DrawObjectSettings &settings) const override
This member function must draw the object. It will be called at every frame.
Definition drawable_lines.h:150
void setVisibility(bool vis) override
This member function is used to set the visibility of the object.
Definition drawable_lines.h:172
bool isVisible() const override
This member function is used to check if the object is visible.
Definition drawable_lines.h:170
The DrawableObject class is the base class for all the objects that can be drawn in a 3D viewer.
Definition drawable_object.h:57
void swap(DrawableObject &other)
Utility swap function that allows to swap the content of two DrawableObject instances.
Definition drawable_object.h:195
DrawableObject()=default
Empty constructor.
The Lines class provides an abstraction for rendering 3D lines with variable thickness and different ...
Definition lines.h:56
void draw(uint viewId) const
Draws in the given view the lines with the current settings.
Definition lines.h:427
void setPoints(const std::vector< float > &vertCoords, const std::vector< float > &vertNormals, const std::vector< uint > &vertColors, const std::vector< uint > &lineColors, ImplementationType type=ImplementationType::COUNT)
Sets the points of the lines.
Definition lines.h:236
The Point class represents an N-dimensional point containing N scalar values.
Definition point.h:55