remote_task_model.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2017, Bielefeld University
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Bielefeld University nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Robert Haschke */
36 
37 #pragma once
38 
39 #include "task_list_model.h"
41 #include <ros/service_client.h>
42 #include <memory>
43 #include <limits>
44 
45 namespace moveit_rviz_plugin {
46 
47 class RemoteSolutionModel;
52 class RemoteTaskModel : public BaseTaskModel
53 {
54  Q_OBJECT
55  struct Node;
56  Node* const root_;
58 
59  std::map<uint32_t, Node*> id_to_stage_;
60  std::map<uint32_t, DisplaySolutionPtr> id_to_solution_;
61 
62  inline Node* node(const QModelIndex& index) const;
63  QModelIndex index(const Node* n) const;
64 
65  Node* node(uint32_t stage_id) const;
66  inline RemoteSolutionModel* getSolutionModel(uint32_t stage_id) const;
67  void setSolutionData(const moveit_task_constructor_msgs::SolutionInfo& info);
68 
69 public:
70  RemoteTaskModel(ros::NodeHandle& nh, const std::string& service_name,
71  const planning_scene::PlanningSceneConstPtr& scene, rviz::DisplayContext* display_context,
72  QObject* parent = nullptr);
73  ~RemoteTaskModel() override;
74 
75  int rowCount(const QModelIndex& parent = QModelIndex()) const override;
76 
77  QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
78  QModelIndex parent(const QModelIndex& index) const override;
79 
80  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
81  bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
82 
83  QModelIndex indexFromStageId(size_t id) const override;
84  void processStageDescriptions(const moveit_task_constructor_msgs::TaskDescription::_stages_type& msg);
85  void processStageStatistics(const moveit_task_constructor_msgs::TaskStatistics::_stages_type& msg);
86  DisplaySolutionPtr processSolutionMessage(const moveit_task_constructor_msgs::Solution& msg);
87 
88  QAbstractItemModel* getSolutionModel(const QModelIndex& index) override;
89  DisplaySolutionPtr getSolution(const QModelIndex& index) override;
90 
91  rviz::PropertyTreeModel* getPropertyModel(const QModelIndex& index) override;
92 };
93 
95 class RemoteSolutionModel : public QAbstractTableModel
96 {
97  Q_OBJECT
98  struct Data
99  {
100  uint32_t id;
101  double cost; // nan if unknown, inf if failed
102  QString comment;
103  uint32_t creation_rank; // rank, ordered by creation
104  uint32_t cost_rank; // rank, ordering by cost
105 
106  Data(uint32_t id, float cost, uint32_t cost_rank, const QString& name = QString())
108 
109  inline bool operator<(const Data& other) const { return this->id < other.id; }
110  };
111  // successful and failed solutions ordered by id / creation
112  using DataList = std::list<Data>;
113  DataList data_;
114  size_t num_failed_data_ = 0; // number of failed solutions in data_
115  size_t num_failed_ = 0; // number of reported failures
116  double total_compute_time_ = 0.0;
117 
118  // solutions ordered (by default according to cost)
119  int sort_column_ = -1;
120  Qt::SortOrder sort_order_ = Qt::AscendingOrder;
121  double max_cost_ = std::numeric_limits<double>::infinity();
122  std::vector<DataList::iterator> sorted_;
123 
124  inline bool isVisible(const Data& item) const;
125  void processSolutionIDs(const std::vector<uint32_t>& ids, bool successful);
126  void sortInternal();
127 
128 public:
129  RemoteSolutionModel(QObject* parent = nullptr);
130 
131  uint numSuccessful() const { return data_.size() - num_failed_data_; }
132  uint numFailed() const { return num_failed_; }
133  double totalComputeTime() const { return total_compute_time_; }
134 
135  int rowCount(const QModelIndex& parent = QModelIndex()) const override;
136  int columnCount(const QModelIndex& parent = QModelIndex()) const override;
137  QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
138  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
139  void sort(int column, Qt::SortOrder order) override;
140 
141  void setSolutionData(uint32_t id, float cost, const QString& comment);
142  void processSolutionIDs(const std::vector<uint32_t>& successful, const std::vector<uint32_t>& failed,
143  size_t num_failed, double total_compute_time);
144 };
145 } // namespace moveit_rviz_plugin
moveit_rviz_plugin::RemoteSolutionModel::setSolutionData
void setSolutionData(uint32_t id, float cost, const QString &comment)
Definition: remote_task_model.cpp:538
moveit_rviz_plugin::RemoteSolutionModel::sortInternal
void sortInternal()
Definition: remote_task_model.cpp:573
rviz::PropertyTreeModel
moveit_rviz_plugin::RemoteSolutionModel::processSolutionIDs
void processSolutionIDs(const std::vector< uint32_t > &ids, bool successful)
Definition: remote_task_model.cpp:645
moveit_rviz_plugin::RemoteTaskModel::data
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition: remote_task_model.cpp:233
moveit_rviz_plugin::RemoteSolutionModel::sort_order_
Qt::SortOrder sort_order_
Definition: remote_task_model.h:152
moveit_rviz_plugin::RemoteTaskModel::node
Node * node(const QModelIndex &index) const
Definition: remote_task_model.cpp:147
moveit_rviz_plugin::RemoteSolutionModel::sorted_
std::vector< DataList::iterator > sorted_
Definition: remote_task_model.h:154
uint32_t
uint32_t
moveit_rviz_plugin::RemoteTaskModel::get_solution_client_
ros::ServiceClient get_solution_client_
Definition: remote_task_model.h:89
moveit_rviz_plugin::RemoteTaskModel::~RemoteTaskModel
~RemoteTaskModel() override
Definition: remote_task_model.cpp:192
moveit_rviz_plugin::RemoteSolutionModel::numFailed
uint numFailed() const
Definition: remote_task_model.h:164
moveit_rviz_plugin::RemoteSolutionModel::Data::cost_rank
uint32_t cost_rank
Definition: remote_task_model.h:136
moveit_rviz_plugin::RemoteSolutionModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: remote_task_model.cpp:465
moveit_rviz_plugin::RemoteTaskModel::RemoteTaskModel
RemoteTaskModel(ros::NodeHandle &nh, const std::string &service_name, const planning_scene::PlanningSceneConstPtr &scene, rviz::DisplayContext *display_context, QObject *parent=nullptr)
Definition: remote_task_model.cpp:183
moveit_rviz_plugin::RemoteSolutionModel::Data::creation_rank
uint32_t creation_rank
Definition: remote_task_model.h:135
moveit_rviz_plugin::RemoteSolutionModel::data_
DataList data_
Definition: remote_task_model.h:145
moveit_rviz_plugin::RemoteTaskModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: remote_task_model.cpp:196
moveit_rviz_plugin::RemoteTaskModel::getSolution
DisplaySolutionPtr getSolution(const QModelIndex &index) override
get solution for given solution index
Definition: remote_task_model.cpp:411
moveit_rviz_plugin::RemoteSolutionModel::Data::comment
QString comment
Definition: remote_task_model.h:134
moveit_rviz_plugin::RemoteSolutionModel::RemoteSolutionModel
RemoteSolutionModel(QObject *parent=nullptr)
Definition: remote_task_model.cpp:463
moveit_rviz_plugin::RemoteSolutionModel::max_cost_
double max_cost_
Definition: remote_task_model.h:153
moveit_rviz_plugin::RemoteTaskModel::getPropertyModel
rviz::PropertyTreeModel * getPropertyModel(const QModelIndex &index) override
get property model for given stage index
Definition: remote_task_model.cpp:438
moveit_rviz_plugin::RemoteSolutionModel::Data::cost
double cost
Definition: remote_task_model.h:133
moveit_rviz_plugin::RemoteSolutionModel::Data::Data
Data(uint32_t id, float cost, uint32_t cost_rank, const QString &name=QString())
Definition: remote_task_model.h:138
moveit_rviz_plugin::RemoteSolutionModel::Data::operator<
bool operator<(const Data &other) const
Definition: remote_task_model.h:141
ros::ServiceClient
moveit_rviz_plugin::RemoteTaskModel::index
QModelIndex index(const Node *n) const
Definition: remote_task_model.cpp:169
moveit_rviz_plugin::RemoteSolutionModel::num_failed_data_
size_t num_failed_data_
Definition: remote_task_model.h:146
rviz::DisplayContext
name
name
moveit_rviz_plugin::RemoteSolutionModel::sort_column_
int sort_column_
Definition: remote_task_model.h:151
moveit_rviz_plugin
moveit_rviz_plugin::RemoteTaskModel::getSolutionModel
RemoteSolutionModel * getSolutionModel(uint32_t stage_id) const
Definition: remote_task_model.cpp:399
moveit_rviz_plugin::RemoteTaskModel::processStageDescriptions
void processStageDescriptions(const moveit_task_constructor_msgs::TaskDescription::_stages_type &msg)
Definition: remote_task_model.cpp:280
task_list_model.h
service_client.h
moveit_rviz_plugin::RemoteSolutionModel::DataList
std::list< Data > DataList
Definition: remote_task_model.h:144
moveit_rviz_plugin::RemoteTaskModel::indexFromStageId
QModelIndex indexFromStageId(size_t id) const override
retrieve model index associated with given stage id
Definition: remote_task_model.cpp:275
moveit_rviz_plugin::RemoteTaskModel::id_to_solution_
std::map< uint32_t, DisplaySolutionPtr > id_to_solution_
Definition: remote_task_model.h:92
moveit_rviz_plugin::RemoteSolutionModel::total_compute_time_
double total_compute_time_
Definition: remote_task_model.h:148
moveit_rviz_plugin::RemoteSolutionModel::isVisible
bool isVisible(const Data &item) const
Definition: remote_task_model.cpp:659
moveit_rviz_plugin::RemoteSolutionModel::numSuccessful
uint numSuccessful() const
Definition: remote_task_model.h:163
moveit_rviz_plugin::RemoteTaskModel::root_
Node *const root_
Definition: remote_task_model.h:87
moveit_rviz_plugin::RemoteSolutionModel::num_failed_
size_t num_failed_
Definition: remote_task_model.h:147
moveit_rviz_plugin::RemoteSolutionModel::columnCount
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: remote_task_model.cpp:469
moveit_rviz_plugin::RemoteSolutionModel::sort
void sort(int column, Qt::SortOrder order) override
Definition: remote_task_model.cpp:563
moveit_rviz_plugin::RemoteSolutionModel::Data::id
uint32_t id
Definition: remote_task_model.h:132
moveit_rviz_plugin::RemoteTaskModel::setData
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Definition: remote_task_model.cpp:265
moveit_rviz_plugin::RemoteTaskModel::processStageStatistics
void processStageStatistics(const moveit_task_constructor_msgs::TaskStatistics::_stages_type &msg)
Definition: remote_task_model.cpp:339
moveit_rviz_plugin::RemoteSolutionModel::data
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition: remote_task_model.cpp:493
moveit_rviz_plugin::RemoteTaskModel::id_to_stage_
std::map< uint32_t, Node * > id_to_stage_
Definition: remote_task_model.h:91
moveit_rviz_plugin::RemoteSolutionModel::totalComputeTime
double totalComputeTime() const
Definition: remote_task_model.h:165
moveit_rviz_plugin::RemoteTaskModel::processSolutionMessage
DisplaySolutionPtr processSolutionMessage(const moveit_task_constructor_msgs::Solution &msg)
Definition: remote_task_model.cpp:366
moveit_rviz_plugin::RemoteTaskModel::setSolutionData
void setSolutionData(const moveit_task_constructor_msgs::SolutionInfo &info)
Definition: remote_task_model.cpp:359
ros::NodeHandle
moveit_rviz_plugin::RemoteTaskModel::parent
QModelIndex parent(const QModelIndex &index) const override
Definition: remote_task_model.cpp:220
moveit_rviz_plugin::RemoteSolutionModel::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Definition: remote_task_model.cpp:473
display_solution.h
moveit_rviz_plugin::RemoteSolutionModel
Definition: remote_task_model.h:127


visualization
Author(s): Robert Haschke
autogenerated on Thu Feb 27 2025 03:39:51