-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
C++ Example setup, examples for point3d/arrow3d/disconnectedspace (#2908
) ### What Adds C++ example build setup and examples for: * Point3D #2789 * Arrow3D #2785 * DisconnectedSpace #2791 as before Point2D example is blocked on rects for the moment. Generating a bunch more methods now for better usability. Still lacking user extensions though, in particular Point3D construction is poor right now Examples can be built in bulk with ` ./tests/cpp/build_all_doc_examples.sh` Then run with `./build/tests/cpp/doc_example_point3d_EXAMPLE_NAME` They all connect to localhost on default port for now. Point3D Simple: <img width="1336" alt="image" src="https://github.com/rerun-io/rerun/assets/1220815/61ca8dba-690f-4bcf-96d2-25cb010881fb"> Point3D Random: <img width="1341" alt="image" src="https://github.com/rerun-io/rerun/assets/1220815/48fa902d-7858-4580-b64b-69815dab47e3"> Arrow3D: <img width="1360" alt="image" src="https://github.com/rerun-io/rerun/assets/1220815/131d0efa-af94-418a-b08f-653c1d9eafb0"> Disconnected Space: <img width="1339" alt="image" src="https://github.com/rerun-io/rerun/assets/1220815/5da1bb64-984a-4ff5-903a-1ea060dd296a"> Dependent on #2906 ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/2908) (if applicable) - [PR Build Summary](https://build.rerun.io/pr/2908) - [Docs preview](https://rerun.io/preview/pr%3Aandreas%2Fcpp%2Fexamplesv2/docs) - [Examples preview](https://rerun.io/preview/pr%3Aandreas%2Fcpp%2Fexamplesv2/examples)
- Loading branch information
Showing
83 changed files
with
1,158 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Log a batch of 3D arrows. | ||
|
||
#include <rerun.hpp> | ||
|
||
#include <cmath> | ||
#include <numeric> | ||
|
||
namespace rr = rerun; | ||
|
||
int main() { | ||
auto rr_stream = rr::RecordingStream("arrow3d"); | ||
rr_stream.connect("127.0.0.1:9876"); | ||
|
||
std::vector<rr::components::Vector3D> vectors; | ||
std::vector<rr::components::Color> colors; | ||
|
||
for (int i = 0; i < 100; ++i) { | ||
float angle = 2.0 * M_PI * i * 0.01f; | ||
float length = log2f(i + 1); | ||
vectors.push_back(rr::datatypes::Vec3D{length * sinf(angle), 0.0, length * cosf(angle)}); | ||
|
||
// TODO(andreas): provide `unmultiplied_rgba` | ||
uint8_t c = static_cast<uint8_t>((angle / (2.0 * M_PI) * 255.0) + 0.5); | ||
uint32_t color = ((255 - c) << 24) + (c << 16) + (128 << 8) + (128 << 0); | ||
colors.push_back(color); | ||
} | ||
|
||
rr_stream.log("arrows", rr::archetypes::Arrows3D(vectors).with_colors(colors)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Disconnect two spaces. | ||
|
||
#include <rerun.hpp> | ||
|
||
namespace rr = rerun; | ||
|
||
int main() { | ||
auto rr_stream = rr::RecordingStream("disconnected_space"); | ||
rr_stream.connect("127.0.0.1:9876"); | ||
|
||
// These two points can be projected into the same space.. | ||
rr_stream.log( | ||
"world/room1/point", | ||
rr::archetypes::Points3D(rr::datatypes::Vec3D{0.0f, 0.0f, 0.0f}) | ||
); | ||
rr_stream.log( | ||
"world/room2/point", | ||
rr::archetypes::Points3D(rr::datatypes::Vec3D{1.0f, 1.0f, 1.0f}) | ||
); | ||
|
||
// ..but this one lives in a completely separate space! | ||
rr_stream.log("world/wormhole", rr::archetypes::DisconnectedSpace(true)); | ||
rr_stream.log( | ||
"world/wormhole/point", | ||
rr::archetypes::Points3D(rr::datatypes::Vec3D{2.0f, 2.0f, 2.0f}) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Log some random points with color and radii. | ||
|
||
#include <rerun.hpp> | ||
|
||
#include <algorithm> | ||
#include <random> | ||
|
||
namespace rr = rerun; | ||
|
||
int main() { | ||
auto rr_stream = rr::RecordingStream("points3d_random"); | ||
rr_stream.connect("127.0.0.1:9876"); | ||
|
||
std::default_random_engine gen; | ||
std::uniform_real_distribution<float> dist_pos(-5.0, 5.0); | ||
std::uniform_real_distribution<float> dist_radius(0.1, 1.0); | ||
std::uniform_int_distribution<uint8_t> dist_color(0, 255); | ||
|
||
std::vector<rr::components::Point3D> points3d(10); | ||
std::generate(points3d.begin(), points3d.end(), [&] { | ||
return rr::datatypes::Vec3D{dist_pos(gen), dist_pos(gen), dist_pos(gen)}; | ||
}); | ||
std::vector<rr::components::Color> colors(10); | ||
std::generate(colors.begin(), colors.end(), [&] { | ||
// TODO(andreas): provide a `rgb` factory method. | ||
return (dist_color(gen) << 24) + (dist_color(gen) << 16) + (dist_color(gen) << 8) + 255; | ||
}); | ||
std::vector<rr::components::Radius> radii(10); | ||
std::generate(radii.begin(), radii.end(), [&] { return dist_radius(gen); }); | ||
|
||
rr_stream.log( | ||
"random", | ||
rr::archetypes::Points3D(points3d).with_colors(colors).with_radii(radii) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Log some very simple points. | ||
|
||
#include <rerun.hpp> | ||
|
||
namespace rr = rerun; | ||
|
||
int main() { | ||
auto rr_stream = rr::RecordingStream("points3d_simple"); | ||
rr_stream.connect("127.0.0.1:9876"); | ||
|
||
rr_stream.log( | ||
"points", | ||
rr::archetypes::Points3D( | ||
{rr::datatypes::Vec3D{0.0f, 0.0f, 0.0f}, rr::datatypes::Vec3D{1.0f, 1.0f, 1.0f}} | ||
) | ||
); | ||
} |
Oops, something went wrong.