diff --git a/source/RobotAPI/components/ViewSelection/ViewSelection.cpp b/source/RobotAPI/components/ViewSelection/ViewSelection.cpp index 5f16a3173d3a9bcdb06990aa00381fe7bc67aab2..2a6cd2d94fd6866e69fbee5b2aaaa3fa9c692471 100644 --- a/source/RobotAPI/components/ViewSelection/ViewSelection.cpp +++ b/source/RobotAPI/components/ViewSelection/ViewSelection.cpp @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * - * @package RobotComponents::ViewSelection + * @package RobotAPI::ViewSelection * @author David Schiebener (schiebener at kit dot edu) * @author Markus Grotz ( markus dot grotz at kit dot edu ) * @date 2015 @@ -311,6 +311,17 @@ void ViewSelection::process() viewSelectionObserver->nextViewTarget(timeOfLastViewChange.toMilliSeconds() + duration); + + + /* + * + while (duration > 0 && !hasNewSaliencyMap) + { + //condition.wait_for(syncMutex , boost::chrono::milliseconds(100)); + duration -= 100; + } + */ + boost::this_thread::sleep(boost::posix_time::milliseconds(duration)); } else @@ -388,7 +399,8 @@ void armarx::ViewSelection::updateSaliencyMap(const SaliencyMapBasePtr& map, con } -void ViewSelection::drawSaliencyMap(const Ice::Current& c) + +void ViewSelection::drawSaliencySphere(const ::Ice::StringSeq& names, const Ice::Current& c) { ARMARX_LOG << "visualizing saliency map"; @@ -401,20 +413,30 @@ void ViewSelection::drawSaliencyMap(const Ice::Current& c) IceUtil::Time currentTime = armarx::TimeUtil::GetTime(); std::vector<std::string> activeSaliencyMaps; - for (const auto & p : saliencyMaps) + if (names.size()) { - if (p.second->validUntil) + for (std::string n : names) { - TimestampVariantPtr time = TimestampVariantPtr::dynamicCast(p.second->validUntil); - if (time->toTime() > currentTime) + activeSaliencyMaps.push_back(n); + } + } + else + { + for (const auto & p : saliencyMaps) + { + if (p.second->validUntil) + { + TimestampVariantPtr time = TimestampVariantPtr::dynamicCast(p.second->validUntil); + if (time->toTime() > currentTime) + { + activeSaliencyMaps.push_back(p.second->name); + } + } + else if ((currentTime - TimestampVariantPtr::dynamicCast(p.second->timeAdded)->toTime()) < IceUtil::Time::seconds(5)) { activeSaliencyMaps.push_back(p.second->name); } } - else if ((currentTime - TimestampVariantPtr::dynamicCast(p.second->timeAdded)->toTime()) < IceUtil::Time::seconds(5)) - { - activeSaliencyMaps.push_back(p.second->name); - } } @@ -447,12 +469,19 @@ void ViewSelection::drawSaliencyMap(const Ice::Current& c) Eigen::Vector3f dim = Eigen::Vector3f::Ones() * 15; DrawColor color = {r, g, b, 1.0}; + // drawer->setLineSetVisu(); + drawer->setBoxVisu("saliencyMap", "node_" + std::to_string(i), new Pose(pose), new Vector3(dim), color); } } +void ViewSelection::clearSaliencySphere(const Ice::Current& c) +{ + drawer->clearLayer("saliencyMap"); +} + void ViewSelection::removeSaliencyMap(const string& name, const Ice::Current& c) { boost::mutex::scoped_lock lock(syncMutex); @@ -465,6 +494,21 @@ void ViewSelection::removeSaliencyMap(const string& name, const Ice::Current& c) condition.notify_all(); } +Ice::StringSeq ViewSelection::getSaliencyMapNames(const Ice::Current& c) +{ + + std::vector<std::string> names; + + boost::mutex::scoped_lock lock(syncMutex); + + for (const auto & p : saliencyMaps) + { + names.push_back(p.second->name); + } + + return names; +} + PropertyDefinitionsPtr ViewSelection::createPropertyDefinitions() { diff --git a/source/RobotAPI/components/ViewSelection/ViewSelection.h b/source/RobotAPI/components/ViewSelection/ViewSelection.h index d04451875506349e89689c52a1614e31c6f59109..6c0d477b439b194572ded8463bfaf83c877fa0c9 100644 --- a/source/RobotAPI/components/ViewSelection/ViewSelection.h +++ b/source/RobotAPI/components/ViewSelection/ViewSelection.h @@ -84,7 +84,7 @@ namespace armarx defineOptionalProperty<std::string>("CameraFrameName", "VirtualCentralGaze", "Name of the frame of the head base in the robot model"); defineOptionalProperty<int>("SleepingTimeBetweenViewDirectionChanges", 2500, "Time between two view changes, to keep the head looking into one direction for a while (in ms)"); defineOptionalProperty<bool>("ActiveAtStartup", true, "Decide whether the automatic view selection will be activated (can be changed via the proxy during runtime)"); - defineOptionalProperty<bool>("VisualizeViewDirection", false, "Draw view ray on DebugLayer."); + defineOptionalProperty<bool>("VisualizeViewDirection", true, "Draw view ray on DebugLayer."); defineOptionalProperty<float>("MaxOverallHeadTiltAngle", 55.0f, "Maximal angle the head and eyes can look down (in degrees)"); defineOptionalProperty<float>("CentralHeadTiltAngle", 110.0f, "Defines the height direction that will be considered 'central' in the reachable area of the head (in degrees). Default is looking 20 degrees downwards"); defineOptionalProperty<float>("ProbabilityToLookForALostObject", 0.03f, "Probability that one of the objects that have been seen but could later not been localized again will be included in the view selection"); @@ -180,7 +180,12 @@ namespace armarx void removeSaliencyMap(const std::string& name, const Ice::Current& c = ::Ice::Current()); - void drawSaliencyMap(const Ice::Current& c = ::Ice::Current()); + ::Ice::StringSeq getSaliencyMapNames(const Ice::Current& c = ::Ice::Current()); + + void drawSaliencySphere(const ::Ice::StringSeq& names, const Ice::Current& c = ::Ice::Current()); + + void clearSaliencySphere(const Ice::Current& c = ::Ice::Current()); + private: diff --git a/source/RobotAPI/gui-plugins/ViewSelection/ViewSelectionWidget.ui b/source/RobotAPI/gui-plugins/ViewSelection/ViewSelectionWidget.ui index e5a6f669f4ad04f08df47c564192044415cac757..9f62637a4f60c7ccd7d8a3da5a717f06bd049a87 100644 --- a/source/RobotAPI/gui-plugins/ViewSelection/ViewSelectionWidget.ui +++ b/source/RobotAPI/gui-plugins/ViewSelection/ViewSelectionWidget.ui @@ -19,28 +19,49 @@ <x>10</x> <y>10</y> <width>360</width> - <height>80</height> + <height>114</height> </rect> </property> <layout class="QVBoxLayout" name="verticalLayout"> <item> <layout class="QHBoxLayout" name="horizontalLayout"> <item> - <widget class="QCheckBox" name="checkBox"> - <property name="text"> - <string>Enable automatic view selection</string> - </property> - </widget> + <widget class="QListWidget" name="listWidget"/> </item> <item> - <widget class="QPushButton" name="pushButton"> - <property name="text"> - <string>Draw Saliency Map</string> - </property> - </widget> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <widget class="QPushButton" name="pushButton_3"> + <property name="text"> + <string>Refresh</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="pushButton"> + <property name="text"> + <string>Draw Saliency Sphere</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="pushButton_2"> + <property name="text"> + <string>Clear Saliency Sphere</string> + </property> + </widget> + </item> + </layout> </item> </layout> </item> + <item> + <widget class="QCheckBox" name="checkBox"> + <property name="text"> + <string>Enable automatic view selection</string> + </property> + </widget> + </item> </layout> </widget> </widget> diff --git a/source/RobotAPI/gui-plugins/ViewSelection/ViewSelectionWidgetController.cpp b/source/RobotAPI/gui-plugins/ViewSelection/ViewSelectionWidgetController.cpp index 9ee4739c7edd0c80869704cc77c02eec4b6e89f5..aa366549f925c7f97406fce61383272ffe3bcf3e 100644 --- a/source/RobotAPI/gui-plugins/ViewSelection/ViewSelectionWidgetController.cpp +++ b/source/RobotAPI/gui-plugins/ViewSelection/ViewSelectionWidgetController.cpp @@ -22,6 +22,7 @@ #include "ViewSelectionWidgetController.h" +#include <QListWidgetItem> #include <string> using namespace armarx; @@ -32,7 +33,12 @@ ViewSelectionWidgetController::ViewSelectionWidgetController() connect(widget.pushButton, SIGNAL(clicked()), this, SLOT(triggerSaliencyMapVisualization())); + connect(widget.pushButton_2, SIGNAL(clicked()), this, SLOT(clearSaliencyMapVisualization())); + + connect(widget.pushButton_3, SIGNAL(clicked()), this, SLOT(updateSaliencyMapNames())); + connect(widget.checkBox, SIGNAL(toggled(bool)), this, SLOT(toggleViewSelection(bool))); + } @@ -69,6 +75,7 @@ void ViewSelectionWidgetController::onInitComponent() { usingProxy(viewSelectionName); usingTopic(viewSelectionName + "Observer"); + } @@ -104,14 +111,46 @@ void ViewSelectionWidgetController::toggleViewSelection(bool isEnabled) } else { - viewSelection->deactivateAutomaticViewSelection(); } } void ViewSelectionWidgetController::triggerSaliencyMapVisualization() { - viewSelection->drawSaliencyMap(); + std::vector<std::string> names; + + for (int r = 0; r < widget.listWidget->count(); r++) + { + QListWidgetItem* item = widget.listWidget->item(r); + + if (item->checkState() == Qt::Checked) + { + names.push_back(item->text().toStdString()); + } + + } + viewSelection->drawSaliencySphere(names); + +} + +void ViewSelectionWidgetController::updateSaliencyMapNames() +{ + std::vector<std::string> names = viewSelection->getSaliencyMapNames(); + + widget.listWidget->clear(); + + for (std::string name : names) + { + QListWidgetItem* item = new QListWidgetItem(QString::fromStdString(name), widget.listWidget); + item->setFlags(item->flags() | Qt::ItemIsUserCheckable); + item->setCheckState(Qt::Unchecked); + } +} + + +void ViewSelectionWidgetController::clearSaliencyMapVisualization() +{ + viewSelection->clearSaliencySphere(); } void armarx::ViewSelectionWidgetController::configured() diff --git a/source/RobotAPI/gui-plugins/ViewSelection/ViewSelectionWidgetController.h b/source/RobotAPI/gui-plugins/ViewSelection/ViewSelectionWidgetController.h index 02bd2dd188d9ca294cafb54788fbab46fe3d6ef7..b0c9ccb75326d33f2bd634c69334f14829ac1df2 100644 --- a/source/RobotAPI/gui-plugins/ViewSelection/ViewSelectionWidgetController.h +++ b/source/RobotAPI/gui-plugins/ViewSelection/ViewSelectionWidgetController.h @@ -117,6 +117,8 @@ namespace armarx public slots: void triggerSaliencyMapVisualization(); + void clearSaliencyMapVisualization(); + void updateSaliencyMapNames(); void toggleViewSelection(bool enabled); /* QT slot declarations */ diff --git a/source/RobotAPI/interface/components/ViewSelectionInterface.ice b/source/RobotAPI/interface/components/ViewSelectionInterface.ice index 19fb28c80c6e54a7ddcf54840276e6143cf4578d..df3fc7d0b05484a8b49c4d52c64c291bfc7f9d3f 100755 --- a/source/RobotAPI/interface/components/ViewSelectionInterface.ice +++ b/source/RobotAPI/interface/components/ViewSelectionInterface.ice @@ -77,8 +77,10 @@ module armarx void updateSaliencyMap(SaliencyMapBase map); void removeSaliencyMap(string name); + ::Ice::StringSeq getSaliencyMapNames(); - void drawSaliencyMap(); + void drawSaliencySphere(::Ice::StringSeq names); + void clearSaliencySphere(); };