Skip to content

Commit c4b6c52

Browse files
author
Ilija Puaca
authored
Doc additions, minor tuneups (#171)
1 parent 73579fe commit c4b6c52

36 files changed

+290
-190
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ endif()
207207
# BUNDLE LIBRARY #
208208
##################
209209

210-
# TODO: Should be a shared lib. Generate an empty source file?
210+
# Currently only used internally to link against for testing purposes
211211
add_library(deckgl-bundle INTERFACE)
212212

213213
# Define module libs

cpp/modules/deck.gl/core/src/arrow/row.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ auto Row::_getChunk(const std::string& columnName) const -> std::shared_ptr<arro
147147

148148
// Iterate over column chunks and find the chunk that contains row data
149149
int64_t offset = 0;
150-
for (auto chunk : column->chunks()) {
150+
for (const auto& chunk : column->chunks()) {
151151
if (this->_rowIndex >= offset && this->_rowIndex < offset + chunk->length()) {
152-
// TODO(ilija@unfolded.ai): Cache
152+
// TODO(ilija@unfolded.ai): Cache chunks once Rows are being reused properly
153153
return chunk;
154154
}
155155

@@ -183,7 +183,7 @@ auto Row::_getRowChunkData(const std::shared_ptr<arrow::Table>& table, int64_t r
183183
throw std::logic_error("Invalid chunk lookup");
184184
}
185185

186-
// TODO(ilija@unfolded.ai): Sacrificing performance and precision for conciseness, revisit
186+
// Sacrificing performance and precision for conciseness. Revisit if this becomes a bottleneck
187187
auto Row::_getDouble(const std::shared_ptr<arrow::Array>& chunk) const -> std::optional<double> {
188188
switch (chunk->type_id()) {
189189
case arrow::Type::DOUBLE:

cpp/modules/deck.gl/core/src/arrow/row.h

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
namespace deckgl {
3737

38+
/// \brief Utility structure that holds metadata of a generic list array.
3839
struct ListArrayMetadata {
3940
public:
4041
ListArrayMetadata(int32_t offset, int32_t length, const std::shared_ptr<arrow::Array>& values)
@@ -45,36 +46,88 @@ struct ListArrayMetadata {
4546
std::shared_ptr<arrow::Array> values;
4647
};
4748

49+
/// \brief Represents a single row within a given table, which can be queried for easy access to typed data.
4850
class Row {
4951
public:
5052
Row(const std::shared_ptr<arrow::Table>& table, int64_t rowIndex);
5153

54+
/// \brief Attempts to get an integer value in this row, for a given columnName.
55+
/// If the value is of a different type, best effort will be used to convert it to an integer.
56+
/// \param columnName Name of the column to get the data for.
57+
/// \param defaultValue Default value that'll be returned if data could not be found.
58+
/// \returns Integer value found in this row for the given columnName, or defaultValue if one isn't found.
5259
auto getInt(const std::string& columnName, int defaultValue = 0) const -> int;
60+
61+
/// \brief Attempts to get a float value in this row, for a given columnName.
62+
/// If the value is of a different type, best effort will be used to convert it to a float.
63+
/// \param columnName Name of the column to get the data for.
64+
/// \param defaultValue Default value that'll be returned if data could not be found.
65+
/// \returns Float value found in this row for the given columnName, or defaultValue if one isn't found.
5366
auto getFloat(const std::string& columnName, float defaultValue = 0.0) const -> float;
67+
68+
/// \brief Attempts to get a double value in this row, for a given columnName.
69+
/// If the value is of a different type, best effort will be used to convert it to a double.
70+
/// \param columnName Name of the column to get the data for.
71+
/// \param defaultValue Default value that'll be returned if data could not be found.
72+
/// \returns Double value found in this row for the given columnName, or defaultValue if one isn't found.
5473
auto getDouble(const std::string& columnName, double defaultValue = 0.0) const -> double;
74+
75+
/// \brief Attempts to get a boolean value in this row, for a given columnName.
76+
/// If the value is of a different type, best effort will be used to convert it to a boolean.
77+
/// \param columnName Name of the column to get the data for.
78+
/// \param defaultValue Default value that'll be returned if data could not be found.
79+
/// \returns Boolean value found in this row for the given columnName, or defaultValue if one isn't found.
5580
auto getBool(const std::string& columnName, bool defaultValue = false) const -> bool;
81+
82+
/// \brief Attempts to get a string value in this row, for a given columnName.
83+
/// \param columnName Name of the column to get the data for.
84+
/// \param defaultValue Default value that'll be returned if data could not be found.
85+
/// \returns String value found in this row for the given columnName, or defaultValue if one isn't found.
5686
auto getString(const std::string& columnName, const std::string& defaultValue = "") const -> std::string;
5787

88+
/// \brief Attempts to get vector data out of a list array found in this row, for a given columnName.
89+
/// \param columnName Name of the column to get the data for.
90+
/// \param defaultValue Default value that'll be returned if data could not be found.
91+
/// \returns Vector data, potentially padded with zeros if the list was not of a sufficient length,
92+
/// or defaultValue if data could not be found.
5893
template <typename T>
5994
auto getVector2(const std::string& columnName, const mathgl::Vector2<T>& defaultValue = {}) const
6095
-> mathgl::Vector2<T> {
6196
auto data = this->getListData<T>(columnName, {defaultValue.x, defaultValue.y});
6297
return mathgl::Vector2<T>{data.size() > 0 ? data.at(0) : 0, data.size() > 1 ? data.at(1) : 0};
6398
}
99+
100+
/// \brief Attempts to get vector data out of a list array found in this row, for a given columnName.
101+
/// \param columnName Name of the column to get the data for.
102+
/// \param defaultValue Default value that'll be returned if data could not be found.
103+
/// \returns Vector data, potentially padded with zeros if the list was not of a sufficient length,
104+
/// or defaultValue if data could not be found.
64105
template <typename T>
65106
auto getVector3(const std::string& columnName, const mathgl::Vector3<T>& defaultValue = {}) const
66107
-> mathgl::Vector3<T> {
67108
auto data = this->getListData<T>(columnName, {defaultValue.x, defaultValue.y, defaultValue.z});
68109
return mathgl::Vector3<T>{data.size() > 0 ? data.at(0) : 0, data.size() > 1 ? data.at(1) : 0,
69110
data.size() > 2 ? data.at(2) : 0};
70111
}
112+
113+
/// \brief Attempts to get vector data out of a list array found in this row, for a given columnName.
114+
/// \param columnName Name of the column to get the data for.
115+
/// \param defaultValue Default value that'll be returned if data could not be found.
116+
/// \returns Vector data, potentially padded with zeros if the list was not of a sufficient length,
117+
/// or defaultValue if data could not be found.
71118
template <typename T>
72119
auto getVector4(const std::string& columnName, const mathgl::Vector4<T>& defaultValue = {}) const
73120
-> mathgl::Vector4<T> {
74121
auto data = this->getListData<T>(columnName, {defaultValue.x, defaultValue.y, defaultValue.z, defaultValue.w});
75122
return mathgl::Vector4<T>{data.size() > 0 ? data.at(0) : 0, data.size() > 1 ? data.at(1) : 0,
76123
data.size() > 2 ? data.at(2) : 0, data.size() > 3 ? data.at(3) : 0};
77124
}
125+
126+
/// \brief Attempts to get a set of vector data out of a nested list array found in this row, for a given columnName.
127+
/// \param columnName Name of the column to get the data for.
128+
/// \param defaultValue Default value that'll be returned if data could not be found.
129+
/// \returns A collection of vector data, potentially padded with zeros if the list was not of a sufficient length,
130+
/// or defaultValue if data could not be found.
78131
template <typename T>
79132
auto getVector2List(const std::string& columnName, const std::vector<mathgl::Vector2<T>>& defaultValue = {}) const
80133
-> std::vector<mathgl::Vector2<T>> {
@@ -87,6 +140,12 @@ class Row {
87140

88141
return vectorData;
89142
}
143+
144+
/// \brief Attempts to get a set of vector data out of a nested list array found in this row, for a given columnName.
145+
/// \param columnName Name of the column to get the data for.
146+
/// \param defaultValue Default value that'll be returned if data could not be found.
147+
/// \returns A collection of vector data, potentially padded with zeros if the list was not of a sufficient length,
148+
/// or defaultValue if data could not be found.
90149
template <typename T>
91150
auto getVector3List(const std::string& columnName, const std::vector<mathgl::Vector3<T>>& defaultValue = {}) const
92151
-> std::vector<mathgl::Vector3<T>> {
@@ -100,6 +159,12 @@ class Row {
100159

101160
return vectorData;
102161
}
162+
163+
/// \brief Attempts to get a set of vector data out of a nested list array found in this row, for a given columnName.
164+
/// \param columnName Name of the column to get the data for.
165+
/// \param defaultValue Default value that'll be returned if data could not be found.
166+
/// \returns A collection of vector data, potentially padded with zeros if the list was not of a sufficient length,
167+
/// or defaultValue if data could not be found.
103168
template <typename T>
104169
auto getVector4List(const std::string& columnName, const std::vector<mathgl::Vector4<T>>& defaultValue = {}) const
105170
-> std::vector<mathgl::Vector4<T>> {
@@ -113,6 +178,11 @@ class Row {
113178

114179
return vectorData;
115180
}
181+
182+
/// \brief Attempts to get a variable sized collection of arbitrary data.
183+
/// \param columnName Name of the column to get the data for.
184+
/// \param defaultValue Default value that'll be returned if data could not be found.
185+
/// \returns A collection of requested data type, or defaultValue if data could not be found.
116186
template <typename T>
117187
auto getListData(const std::string& columnName, const std::vector<T>& defaultValue = {}) const -> std::vector<T> {
118188
if (!this->isValid(columnName)) {
@@ -128,6 +198,11 @@ class Row {
128198

129199
return this->_getListData(optionalMetadata.value(), defaultValue);
130200
}
201+
202+
/// \brief Attempts to get a nested, variable sized collection of arbitrary data.
203+
/// \param columnName Name of the column to get the data for.
204+
/// \param defaultValue Default value that'll be returned if data could not be found.
205+
/// \returns A collection of requested data type, or defaultValue if data could not be found.
131206
template <typename T>
132207
auto getNestedListData(const std::string& columnName, const std::vector<std::vector<T>>& defaultValue = {}) const
133208
-> std::vector<std::vector<T>> {
@@ -151,6 +226,7 @@ class Row {
151226
auto isValid(const std::string& columnName) const -> bool;
152227

153228
/// \brief Increments current row index.
229+
/// \param increment Amount to increment the current row index by.
154230
void incrementRowIndex(uint64_t increment = 1);
155231

156232
private:
@@ -249,8 +325,6 @@ class Row {
249325

250326
/// \brief Relative row index in respect to the chunk.
251327
int64_t _chunkRowIndex;
252-
253-
// std::unordered_map<std::string, std::shared_ptr<arrow::Array>> _cache;
254328
};
255329

256330
} // namespace deckgl

cpp/modules/deck.gl/core/src/lib/component.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
using namespace deckgl;
2424

2525
// Setters and getters for properties
26-
// TODO(ib@unfolded.ai): auto generate from language-independent prop definition schema
27-
// TODO(ilija@unfolded.ai): Generate a unique id instead of an empty string for default value?
26+
// TODO(ib@unfolded.ai): Auto generate from language-independent prop definition schema
27+
// TODO(ilija@unfolded.ai): Generate a unique id instead of an empty string for default value of id?
2828
static const std::vector<std::shared_ptr<Property>> propTypeDefs = {std::make_shared<PropertyT<std::string>>(
2929
"id", [](const JSONObject* props) { return dynamic_cast<const Component::Props*>(props)->id; },
3030
[](JSONObject* props, std::string value) { return dynamic_cast<Component::Props*>(props)->id = value; }, "")};

cpp/modules/deck.gl/core/src/lib/component.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
namespace deckgl {
3030

31+
/// \brief A root class for JSON-serialzed components of the API.
3132
class Component {
3233
public:
3334
class Props;

cpp/modules/deck.gl/core/src/lib/constants.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525

2626
namespace deckgl {
2727

28-
// Note: The numeric values here are matched by shader code in the
28+
// NOTE: The numeric values here are matched by shader code in the
2929
// "project" and "project64" shader modules. Both places need to be updated.
3030

31-
// Describes how positions are interpreted. Can be specified per layer
31+
/// \brief Describes how positions are interpreted. Can be specified per layer
3232
enum class COORDINATE_SYSTEM {
3333
DEFAULT = -1, // `LNGLAT` if rendering into a geospatial viewport,
3434
// `CARTESIAN` otherwise
@@ -52,7 +52,7 @@ inline auto fromJson<COORDINATE_SYSTEM>(const Json::Value& jsonValue) -> COORDIN
5252
return static_cast<COORDINATE_SYSTEM>(fromJson<int>(jsonValue));
5353
}
5454

55-
// Describes the common space
55+
/// \brief Describes the common space.
5656
enum class PROJECTION_MODE {
5757
IDENTITY = 0,
5858
WEB_MERCATOR = 1,

cpp/modules/deck.gl/core/src/lib/deck.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
using namespace deckgl;
2929

3030
// Setters and getters for properties
31-
// TODO(ib@unfolded.ai): auto generate from language-independent prop definition schema
31+
// TODO(ib@unfolded.ai): Auto generate from language-independent prop definition schema
3232
static const std::vector<std::shared_ptr<Property>> propTypeDefs = {
3333
std::make_shared<PropertyT<std::list<std::shared_ptr<Layer::Props>>>>(
3434
"layers", [](const JSONObject* props) { return dynamic_cast<const Deck::Props*>(props)->layers; },
@@ -200,9 +200,11 @@ void Deck::_drawLayers(wgpu::RenderPassEncoder pass, std::function<void(Deck*)>
200200
// Expose the current viewport to layers for project* function
201201
this->layerManager->activateViewport(viewport);
202202

203-
for (auto const& layer : this->layerManager->layers) {
204-
// TODO(ilija@unfolded.ai): Pass relevant layer properties to getUniformsFromViewport
205-
auto viewportUniforms = getUniformsFromViewport(viewport, this->animationLoop->devicePixelRatio());
203+
for (auto const& layer : this->layerManager->layers()) {
204+
auto layerProps = layer->props();
205+
auto viewportUniforms = getUniformsFromViewport(viewport, this->animationLoop->devicePixelRatio(),
206+
layerProps->modelMatrix, layerProps->coordinateSystem,
207+
layerProps->coordinateOrigin, layerProps->wrapLongitude);
206208

207209
this->_viewportUniformsBuffer.SetSubData(0, sizeof(ViewportUniforms), &viewportUniforms);
208210
for (auto const& model : layer->models()) {

cpp/modules/deck.gl/core/src/lib/deck.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
namespace deckgl {
3636

37+
/// \brief Deck is a class that takes deck.gl layer instances and viewport parameters, and renders those
38+
/// layers as a transparent overlay.
3739
class Deck : public Component {
3840
public:
3941
class Props;
@@ -55,23 +57,40 @@ class Deck : public Component {
5557
explicit Deck(std::shared_ptr<Deck::Props> props = std::make_shared<Deck::Props>());
5658
~Deck();
5759

60+
/// \brief Returns the current properties attached to this Deck instance.
5861
auto props() { return std::dynamic_pointer_cast<Props>(this->_props); }
62+
63+
/// \brief Sets a new set of properties, picking up all the differences compared to the current one.
64+
/// @param props A new set of properties to use.
5965
void setProps(std::shared_ptr<Deck::Props> props);
6066

67+
/// \brief Runs an animation loop that draws this Deck.
68+
/// \param onAfterRender Function that'll be called whenever frame has been drawn.
6169
void run(std::function<void(Deck*)> onAfterRender = [](Deck*) {});
70+
71+
/// \brief Draws the current Deck state into the given textureView, calling onAfteRender once drawing has finished.
72+
/// \param textureView Texture view to draw the current state into.
73+
/// \param onAfterRender Function that'll be called whenever frame has been drawn.
6274
void draw(
6375
wgpu::TextureView textureView, std::function<void(Deck*)> onAfterRender = [](Deck*) {});
76+
77+
/// \brief Stops the animation loop, if one is currently running.
6478
void stop();
6579

6680
/// \brief Check if a redraw is needed.
6781
/// \param clearRedrawFlags Whether needsRedraw flag should be cleared or not.
6882
/// \returns Returns an optional string summarizing the redraw reason.
6983
auto needsRedraw(bool clearRedrawFlags = false) -> std::optional<std::string>;
7084

85+
/// \brief Gets a list of views that this Deck is viewed from.
86+
/// \returns A list of View instances that this Deck can be viewed from.
7187
auto getViews() -> std::list<std::shared_ptr<View>> { return this->viewManager->getViews(); }
7288

89+
/// \brief Gets the current viewport size of this Deck.
90+
/// \returns Width and height of the current viewport.
7391
auto size() -> lumagl::Size { return this->_size; };
7492

93+
// TODO(ilija@unfolded.ai): These should be get-only?
7594
std::shared_ptr<lumagl::AnimationLoop> animationLoop;
7695
std::shared_ptr<ViewManager> viewManager{new ViewManager()};
7796
std::shared_ptr<LayerContext> context;
@@ -96,13 +115,17 @@ class Deck : public Component {
96115

97116
// Instead of maintaining another structure with options, we reuse the relevant struct from lumagl
98117
using DrawingOptions = lumagl::AnimationLoop::Options;
118+
/// \brief A set of properties that represent a single Deck.
99119
class Deck::Props : public Component::Props {
100120
public:
101121
using super = Component::Props;
102122

103-
int width{100}; // Dummy value, ensure something is visible if user forgets to set window size
123+
/// \brief Width of the viewport, in pixels.
124+
int width{100}; // Dummy value, ensure something is visible if user forgets to set window size
125+
/// \brief Height of the viewport, in pixels.
104126
int height{100}; // Dummy value, ensure something is visible if user forgets to set window size
105127

128+
/// \brief A set of options that customize the drawing of this Deck.
106129
std::shared_ptr<DrawingOptions> drawingOptions;
107130

108131
// Layer/View/Controller settings

cpp/modules/deck.gl/core/src/lib/layer-context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Deck;
3232
class LayerManager;
3333
class Viewport;
3434

35-
/// \brief LayerContext is data shared between all layers.
35+
/// \brief LayerContext contains data shared between all layers.
3636
class LayerContext {
3737
public:
3838
// TODO(ilija@unfolded.ai): Do we need to have this circular dependency here?

0 commit comments

Comments
 (0)