20 namespace visualization {
21 namespace visualizer {
24 rendering::MaterialRecord MakeMaterial() {
25 rendering::MaterialRecord m;
26 m.shader =
"defaultUnlit";
27 m.base_color = {1.0f, 0.0f, 1.0f, 1.0f};
34 : widget3d_(widget3d) {}
40 sets_.push_back({
name, {}});
41 if (current_set_index_ < 0) {
42 current_set_index_ = int(sets_.size()) - 1;
48 if (scene->HasGeometry(sets_[index].name)) {
49 scene->RemoveGeometry(sets_[index].
name);
51 sets_.erase(sets_.begin() + index);
52 current_set_index_ =
std::min(
int(sets_.size()) - 1, current_set_index_);
54 if (!sets_.empty() && scene->HasGeometry(sets_[current_set_index_].name)) {
55 scene->ShowGeometry(sets_[current_set_index_].
name,
true);
61 if (scene->HasGeometry(sets_[current_set_index_].name)) {
62 scene->ShowGeometry(sets_[current_set_index_].
name,
false);
65 current_set_index_ = index;
67 if (!sets_.empty() && scene->HasGeometry(sets_[current_set_index_].name)) {
68 scene->ShowGeometry(sets_[current_set_index_].
name,
true);
75 const std::map<std::string,
76 std::vector<std::pair<size_t, Eigen::Vector3d>>>
79 auto &selection = sets_[current_set_index_];
80 for (
auto &name_indices : indices) {
81 auto &
name = name_indices.first;
82 for (
auto idx_pt : name_indices.second) {
83 auto &idx = idx_pt.first;
84 auto &p = idx_pt.second;
85 selection.indices[
name].insert({idx, pick_order_, p});
90 UpdateSelectionGeometry();
95 const std::map<std::string,
96 std::vector<std::pair<size_t, Eigen::Vector3d>>>
99 auto &selection = sets_[current_set_index_];
100 for (
auto &name_indices : indices) {
101 auto &
name = name_indices.first;
102 for (
auto idx_pt : name_indices.second) {
103 auto &idx = idx_pt.first;
104 auto &p = idx_pt.second;
105 selection.indices[
name].erase({idx, pick_order_, p});
110 UpdateSelectionGeometry();
114 void O3DVisualizerSelections::UpdateSelectionGeometry() {
116 auto &selection = sets_[current_set_index_];
117 if (scene->HasGeometry(selection.name)) {
118 scene->RemoveGeometry(selection.name);
120 std::vector<Eigen::Vector3d>
points;
121 points.reserve(selection.indices.size());
122 for (
auto &kv : selection.indices) {
123 for (
auto &i : kv.second) {
124 points.push_back(i.point);
130 spheres.CreateInternalCloud();
136 scene->AddGeometry(selection.name, &spheres, MakeMaterial());
137 scene->GetScene()->GeometryShadows(selection.name,
false,
false);
143 std::vector<O3DVisualizerSelections::SelectionSet>
145 std::vector<SelectionSet> all;
146 all.reserve(sets_.size());
147 for (
auto &s : sets_) {
148 all.push_back(s.indices);
154 point_size_ = radius_world;
158 point_size_changed_ =
true;
171 if (point_size_changed_) {
173 point_size_changed_ =
false;
176 auto &selection = sets_[current_set_index_];
177 if (scene->HasGeometry(selection.name)) {
178 scene->ShowGeometry(selection.name,
true);
187 auto &selection = sets_[current_set_index_];
188 if (scene->HasGeometry(selection.name)) {
189 scene->ShowGeometry(selection.name,
false);
196 const std::vector<gui::SceneWidget::PickableGeometry> &geometry) {
200 void O3DVisualizerSelections::UpdatePointSize() { UpdateSelectionGeometry(); }
static std::shared_ptr< ccMesh > CreateSphere(double radius=1.0, int resolution=20, bool create_uv_map=false)
void SetPointSize(double radius_world)
O3DVisualizerSelections(gui::SceneWidget &widget3d)
void SelectSet(int index)
~O3DVisualizerSelections()
void SelectIndices(const std::map< std::string, std::vector< std::pair< size_t, Eigen::Vector3d >>> &indices)
void SetSelectableGeometry(const std::vector< gui::SceneWidget::PickableGeometry > &geometry)
size_t GetNumberOfSets() const
std::vector< SelectionSet > GetSets()
void RemoveSet(int index)
void UnselectIndices(const std::map< std::string, std::vector< std::pair< size_t, Eigen::Vector3d >>> &indices)
Generic file read and write utility for python interface.
std::string to_string(const T &n)