-
Notifications
You must be signed in to change notification settings - Fork 31
Feature/edge colors #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
278fb09
first draft of edge color adapters
Schmluk a18f4c4
revert interlayer use color in config
Schmluk d036324
Update hydra_visualizer/src/drawing.cpp
Schmluk 20ec440
implement edge color type
Schmluk 5a1d1da
PR feedback
Schmluk eaf4a46
fix compilation and test
Schmluk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,60 +1,69 @@ | ||
| --- | ||
| renderer: | ||
| layer_z_step: 5.5 # unit separation between layers | ||
| collapse_layers: false # whether or not to apply offsets to each of the layers | ||
| layer_z_step: 5.5 # unit separation between layers | ||
| collapse_layers: false # whether or not to apply offsets to each of the layers | ||
| layers: | ||
| 2: | ||
| z_offset_scale: 2.0 | ||
| visualize: true | ||
| nodes: {scale: 0.40, color: {type: LabelColorAdapter}, alpha: 0.8, use_sphere: false} | ||
| text: {draw: true, collapse: true, adapter: {type: LabelTextAdapter}, height: 0.5, scale: 0.45} | ||
| bounding_boxes: {draw: true, collapse: true, scale: 0.05, edge_scale: 0.05, alpha: 0.9, edge_break_ratio: 0.5} | ||
| edges: {interlayer_use_source: true, interlayer_scale: 0.08, interlayer_alpha: 0.9, interlayer_use_color: true} | ||
| nodes: { scale: 0.40, color: { type: LabelColorAdapter }, alpha: 0.8, use_sphere: false } | ||
| text: { draw: true, collapse: true, adapter: { type: LabelTextAdapter }, height: 0.5, scale: 0.45 } | ||
| bounding_boxes: { draw: true, collapse: true, scale: 0.05, edge_scale: 0.05, alpha: 0.9, edge_break_ratio: 0.5 } | ||
| edges: { interlayer_use_source: true, interlayer_scale: 0.08, interlayer_alpha: 0.9 } | ||
| 3: | ||
| z_offset_scale: 3.0 | ||
| visualize: true | ||
| nodes: {scale: 0.2, color: {type: ParentColorAdapter, colormap: {palette: colorbrewer}}, alpha: 0.9, use_sphere: true} | ||
| nodes: | ||
| { | ||
| scale: 0.2, | ||
| color: { type: ParentColorAdapter, colormap: { palette: colorbrewer } }, | ||
| alpha: 0.9, | ||
| use_sphere: true, | ||
| } | ||
| edges: | ||
| scale: 0.01 | ||
| alpha: 0.5 | ||
| use_color: false | ||
| color: { type: UniformEdgeColorAdapter } | ||
| interlayer_use_source: false | ||
| interlayer_scale: 0.08 | ||
| interlayer_alpha: 0.4 | ||
| interlayer_use_color: true | ||
| interlayer_insertion_skip: 0 | ||
| 4: | ||
| z_offset_scale: 4.2 | ||
| visualize: true | ||
| nodes: {scale: 0.6, color: {type: IdColorAdapter, colormap: {palette: colorbrewer}}, alpha: 0.8, use_sphere: false} | ||
| text: {draw: true, height: 1.25, scale: 1.0} | ||
| nodes: | ||
| { | ||
| scale: 0.6, | ||
| color: { type: IdColorAdapter, colormap: { palette: colorbrewer } }, | ||
| alpha: 0.8, | ||
| use_sphere: false, | ||
| } | ||
| text: { draw: true, height: 1.25, scale: 1.0 } | ||
| edges: | ||
| scale: 0.1 | ||
| alpha: 0.2 | ||
| use_color: false | ||
| color: { type: UniformEdgeColorAdapter } | ||
| interlayer_use_source: true | ||
| interlayer_scale: 0.08 | ||
| interlayer_alpha: 0.4 | ||
| interlayer_use_color: true | ||
| interlayer_insertion_skip: 0 | ||
| partitions: | ||
| 2: | ||
| z_offset_scale: 0.0 | ||
| visualize: true | ||
| nodes: {scale: 0.15, alpha: 0.9, use_sphere: false, color: {type: PartitionColorAdapter}} | ||
| edges: {scale: 0.05, alpha: 0.9, draw_interlayer: false} | ||
| text: {draw_layer: true, height: 0.9, scale: 0.8} | ||
| nodes: { scale: 0.15, alpha: 0.9, use_sphere: false, color: { type: PartitionColorAdapter } } | ||
| edges: { scale: 0.05, alpha: 0.9, draw_interlayer: false } | ||
| text: { draw_layer: true, height: 0.9, scale: 0.8 } | ||
| 3: | ||
| z_offset_scale: 3.0 | ||
| visualize: true | ||
| nodes: {scale: 0.2, color: {type: LabelColorAdapter}, alpha: 0.9, use_sphere: true} | ||
| boundaries: {draw: true, collapse: false, wireframe_scale: 0.1, use_node_color: true, alpha: 1.0} | ||
| nodes: { scale: 0.2, color: { type: LabelColorAdapter }, alpha: 0.9, use_sphere: true } | ||
| boundaries: { draw: true, collapse: false, wireframe_scale: 0.1, use_node_color: true, alpha: 1.0 } | ||
| edges: | ||
| scale: 0.01 | ||
| alpha: 0.5 | ||
| use_color: false | ||
| color: { type: UniformEdgeColorAdapter } | ||
| interlayer_use_source: false | ||
| interlayer_scale: 0.08 | ||
| interlayer_alpha: 0.4 | ||
| interlayer_use_color: true | ||
| interlayer_insertion_skip: 0 | ||
131 changes: 131 additions & 0 deletions
131
hydra_visualizer/include/hydra_visualizer/adapters/edge_color.h
This file contains hidden or 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,131 @@ | ||
| /* ----------------------------------------------------------------------------- | ||
| * Copyright 2022 Massachusetts Institute of Technology. | ||
| * All Rights Reserved | ||
| * | ||
| * Redistribution and use in source and binary forms, with or without | ||
| * modification, are permitted provided that the following conditions are met: | ||
| * | ||
| * 1. Redistributions of source code must retain the above copyright notice, | ||
| * this list of conditions and the following disclaimer. | ||
| * | ||
| * 2. Redistributions in binary form must reproduce the above copyright notice, | ||
| * this list of conditions and the following disclaimer in the documentation | ||
| * and/or other materials provided with the distribution. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
| * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
| * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
| * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
| * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
| * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
| * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
| * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| * | ||
| * Research was sponsored by the United States Air Force Research Laboratory and | ||
| * the United States Air Force Artificial Intelligence Accelerator and was | ||
| * accomplished under Cooperative Agreement Number FA8750-19-2-1000. The views | ||
| * and conclusions contained in this document are those of the authors and should | ||
| * not be interpreted as representing the official policies, either expressed or | ||
| * implied, of the United States Air Force or the U.S. Government. The U.S. | ||
| * Government is authorized to reproduce and distribute reprints for Government | ||
| * purposes notwithstanding any copyright notation herein. | ||
| * -------------------------------------------------------------------------- */ | ||
| #pragma once | ||
| #include <config_utilities/factory.h> | ||
| #include <spark_dsg/color.h> | ||
| #include <spark_dsg/dynamic_scene_graph.h> | ||
|
|
||
| #include <memory> | ||
|
|
||
| #include "hydra_visualizer/color/colormap_utilities.h" | ||
|
|
||
| namespace hydra { | ||
|
|
||
| #define REGISTER_COLOR_ADAPTER(adapter) \ | ||
| inline static const auto registration_ = \ | ||
| config::RegistrationWithConfig<EdgeColorAdapter, adapter, Config>(#adapter) | ||
|
|
||
| struct EdgeColorAdapter { | ||
| using Ptr = std::shared_ptr<EdgeColorAdapter>; | ||
| using EdgeColor = std::pair<spark_dsg::Color, spark_dsg::Color>; | ||
|
|
||
| virtual ~EdgeColorAdapter() = default; | ||
|
|
||
| /** | ||
| * @brief Get color for an edge. | ||
| * @param graph Current scene graph node is from | ||
| * @param edge Edge to get color for | ||
| * @returns Visualizer color for source and target ends of the edge. | ||
| */ | ||
| virtual EdgeColor getColor(const spark_dsg::DynamicSceneGraph& graph, | ||
| const spark_dsg::SceneGraphEdge& edge) const = 0; | ||
|
|
||
| /** | ||
| * @brief Set any pre-draw information | ||
| * @param graph Graph to get information for | ||
| * | ||
| * Allows color adapters to gather statistics about the scene graph before generating | ||
| * any edge colors when drawing the scene graph | ||
| */ | ||
| virtual void setGraph(const spark_dsg::DynamicSceneGraph& /* graph */, | ||
| spark_dsg::LayerId /* layer */) {} | ||
| }; | ||
|
|
||
| struct UniformEdgeColorAdapter : EdgeColorAdapter { | ||
| struct Config { | ||
| // TODO(lschmid): Consider using the named colors, or even better integrate | ||
| // optionally named colors directly into the config utilities parsing. | ||
| spark_dsg::Color color; | ||
| } const config; | ||
|
|
||
| explicit UniformEdgeColorAdapter(const Config& config); | ||
| EdgeColor getColor(const spark_dsg::DynamicSceneGraph& graph, | ||
| const spark_dsg::SceneGraphEdge& edge) const override; | ||
|
|
||
| private: | ||
| REGISTER_COLOR_ADAPTER(UniformEdgeColorAdapter); | ||
| }; | ||
|
|
||
| void declare_config(UniformEdgeColorAdapter::Config& config); | ||
|
|
||
| struct EdgeValueFunctor { | ||
| virtual ~EdgeValueFunctor() = default; | ||
| virtual double eval(const spark_dsg::DynamicSceneGraph& graph, | ||
| const spark_dsg::SceneGraphEdge& edge) const = 0; | ||
| }; | ||
|
|
||
| struct EdgeWeightFunctor : EdgeValueFunctor { | ||
| double eval(const spark_dsg::DynamicSceneGraph& graph, | ||
| const spark_dsg::SceneGraphEdge& edge) const override; | ||
|
|
||
| inline static const auto registration = | ||
| config::Registration<EdgeValueFunctor, EdgeWeightFunctor>("weight"); | ||
| }; | ||
|
|
||
| struct ValueEdgeColorAdapter : EdgeColorAdapter { | ||
| struct Config { | ||
| visualizer::RangeColormap::Config colormap; | ||
| std::string value_functor{"weight"}; | ||
| } const config; | ||
|
|
||
| explicit ValueEdgeColorAdapter(const Config& config); | ||
| void setGraph(const spark_dsg::DynamicSceneGraph& graph, | ||
| spark_dsg::LayerId layer) override; | ||
| EdgeColor getColor(const spark_dsg::DynamicSceneGraph& graph, | ||
| const spark_dsg::SceneGraphEdge& edge) const override; | ||
|
|
||
| private: | ||
| double min_value_; | ||
| double max_value_; | ||
| std::unique_ptr<EdgeValueFunctor> functor_; | ||
| const visualizer::RangeColormap colormap_; | ||
| REGISTER_COLOR_ADAPTER(ValueEdgeColorAdapter); | ||
| }; | ||
|
|
||
| void declare_config(ValueEdgeColorAdapter::Config& config); | ||
|
|
||
| #undef REGISTER_COLOR_ADAPTER | ||
|
|
||
| } // namespace hydra |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd probably just checkout the config from develop for now and/or delete
use_colorfrom the config (given that the uniform color functor is the default). I think vs code has a different yaml formatter configured than I do for pre-commit and/or something is weird