From 97073140a16caa6b9ea6b63f946f136363a8ef27 Mon Sep 17 00:00:00 2001 From: Guillaume Sarthou Date: Wed, 24 Jun 2020 11:14:12 +0200 Subject: [PATCH] [UPDATE] draw softpoint intervals --- .../core/memGraphs/Branchs/types/SoftPoint.h | 7 ++++ .../mementar/graphical/timeline/EventReader.h | 4 ++- src/graphical/timeline/EventReader.cpp | 5 +-- src/graphical/timeline/TimelineDrawer.cpp | 32 ++++++++++++++++++- src/graphical/timeline/main.cpp | 4 +-- 5 files changed, 46 insertions(+), 6 deletions(-) diff --git a/include/mementar/core/memGraphs/Branchs/types/SoftPoint.h b/include/mementar/core/memGraphs/Branchs/types/SoftPoint.h index 95acc6f..e4dbca5 100644 --- a/include/mementar/core/memGraphs/Branchs/types/SoftPoint.h +++ b/include/mementar/core/memGraphs/Branchs/types/SoftPoint.h @@ -26,6 +26,13 @@ class SoftPoint t_ = t_start_ + (t_end_.value_or(t_start_) - t_start_) / 2; } + SoftPoint(const SoftPoint* other) + { + t_start_ = other->t_start_; + t_end_ = other->t_end_; + t_ = t_start_ + (t_end_.value_or(t_start_) - t_start_) / 2; + } + bool isInstantaneous() const { return t_end_ == std::experimental::nullopt; } Ttime getTime() const { return t_; } Ttime getTimeStart() const { return t_start_; } diff --git a/include/mementar/graphical/timeline/EventReader.h b/include/mementar/graphical/timeline/EventReader.h index 50d17ca..23320dc 100644 --- a/include/mementar/graphical/timeline/EventReader.h +++ b/include/mementar/graphical/timeline/EventReader.h @@ -12,8 +12,10 @@ namespace mementar { struct event_t { + event_t(SoftPoint::Ttime time) : time_point(time) {} + std::string data; - size_t time_point; + SoftPoint time_point; }; class EventReader diff --git a/src/graphical/timeline/EventReader.cpp b/src/graphical/timeline/EventReader.cpp index 47cc5e7..45d48ee 100644 --- a/src/graphical/timeline/EventReader.cpp +++ b/src/graphical/timeline/EventReader.cpp @@ -11,14 +11,15 @@ void EventReader::read(EventGraph* graph, CvFont* font) while(node != nullptr) { - event_t group_evt; - group_evt.time_point = node->getKey(); + event_t group_evt(node->getKey()); for(auto evt : node->getData()) { if(dynamic_cast(evt)->isPartOfAction() == false) { auto event = dynamic_cast(evt); group_evt.data += (group_evt.data == "" ? "" : " -- ") + event->Fact::toString(); + if(event->getTransitionDuration() > group_evt.time_point.getTransitionDuration()) + group_evt.time_point = SoftPoint(event); } } diff --git a/src/graphical/timeline/TimelineDrawer.cpp b/src/graphical/timeline/TimelineDrawer.cpp index 11c9142..2469ba6 100644 --- a/src/graphical/timeline/TimelineDrawer.cpp +++ b/src/graphical/timeline/TimelineDrawer.cpp @@ -108,6 +108,26 @@ void TimelineDrawer::drawAction(const action_t& action, size_t line_pose, size_t cvScalar(32, 20, 122), 4); } + if(action.start.isInstantaneous() == false) + { + size_t y_soft_start_pose = MARGIN + (action.start.getTimeStart() - start_time) * UNIT_SPACE; + size_t y_soft_end_pose = MARGIN + (action.start.getTimeEnd() - start_time) * UNIT_SPACE; + + cvLine(image_, cvPoint(line_pose - 4, y_soft_start_pose), + cvPoint(line_pose - 4, y_soft_end_pose), + cvScalar(114,102,204), 8); + } + + if(action.end.value().isInstantaneous() == false) + { + size_t y_soft_start_pose = MARGIN + (action.end.value().getTimeStart() - start_time) * UNIT_SPACE; + size_t y_soft_end_pose = MARGIN + (action.end.value().getTimeEnd() - start_time) * UNIT_SPACE; + + cvLine(image_, cvPoint(line_pose - 4, y_soft_start_pose), + cvPoint(line_pose - 4, y_soft_end_pose), + cvScalar(114,102,204), 8); + } + CvFont font; cvInitFont(&font, CV_FONT_HERSHEY_COMPLEX, 1, 1, 0, 2); cvPutText(image_, action.name.c_str(), cvPoint(x_start_pose - getTextSize(action.name, &font) - 2, y_mid_pose), &font, @@ -119,12 +139,22 @@ void TimelineDrawer::drawEvent(const event_t& event, size_t line_pose, size_t st size_t x_start_pose = line_pose; size_t x_end_pose = x_start_pose + SIDE_SPACE; - size_t y_pose = MARGIN + (event.time_point - start_time) * UNIT_SPACE; + size_t y_pose = MARGIN + (event.time_point.getTime() - start_time) * UNIT_SPACE; cvLine(image_, cvPoint(x_start_pose, y_pose), cvPoint(x_end_pose, y_pose), cvScalar(89, 26, 16), 4); + if(event.time_point.isInstantaneous() == false) + { + size_t y_soft_start_pose = MARGIN + (event.time_point.getTimeStart() - start_time) * UNIT_SPACE; + size_t y_soft_end_pose = MARGIN + (event.time_point.getTimeEnd() - start_time) * UNIT_SPACE; + + cvLine(image_, cvPoint(line_pose + 4, y_soft_start_pose), + cvPoint(line_pose + 4, y_soft_end_pose), + cvScalar(149,86,86), 8); + } + CvFont font; cvInitFont(&font, CV_FONT_HERSHEY_COMPLEX, 1, 1, 0, 2); cvPutText(image_, event.data.c_str(), cvPoint(x_end_pose + 2, y_pose), &font, diff --git a/src/graphical/timeline/main.cpp b/src/graphical/timeline/main.cpp index 5feefa2..03498e7 100644 --- a/src/graphical/timeline/main.cpp +++ b/src/graphical/timeline/main.cpp @@ -42,7 +42,7 @@ mementar::Timeline* getTimeline() timeline->events.add(new mementar::ContextualizedEvent("e8", mementar::Event(mementar::Fact("tape_1|isOn|Table_1", false), 37))); timeline->events.add(new mementar::ContextualizedEvent("e9", mementar::Event("tape_1|isOn|Table_1", 38, 42))); timeline->events.add(new mementar::ContextualizedEvent("e10", mementar::Event("tape_1|isBehind|grey_box", 38))); - timeline->events.add(new mementar::ContextualizedEvent("e11", mementar::Event(mementar::Fact("tape_1|isInHand|hum_blue", false), 42))); + timeline->events.add(new mementar::ContextualizedEvent("e11", mementar::Event(mementar::Fact("tape_1|isInHand|hum_blue", false), mementar::SoftPoint(41, 42)))); timeline->events.add(new mementar::ContextualizedEvent("e12", mementar::Event(mementar::Fact("hum_blue|isInRoom|expe_room", false), mementar::SoftPoint(51,52)))); timeline->events.add(new mementar::ContextualizedEvent("e13", mementar::Event("hum_green|isInRoom|expe_room", 53))); timeline->events.add(new mementar::ContextualizedEvent("e14", mementar::Event("tape_2|isInGripper|pr2", 86))); @@ -137,7 +137,7 @@ mementar::Timeline* getTimeline() timeline->events.add(new mementar::ContextualizedEvent("e8", mementar::Event(mementar::Fact("tape_1|isOn|Table_1", false), 37))); timeline->events.add(new mementar::ContextualizedEvent("e9", mementar::Event("tape_1|isOn|Table_1", 38, 42))); timeline->events.add(new mementar::ContextualizedEvent("e10", mementar::Event("tape_1|isBehind|grey_box", 38))); - timeline->events.add(new mementar::ContextualizedEvent("e11", mementar::Event(mementar::Fact("tape_1|isInHand|hum_blue", false), 42))); + timeline->events.add(new mementar::ContextualizedEvent("e11", mementar::Event(mementar::Fact("tape_1|isInHand|hum_blue", false), mementar::SoftPoint(41, 42)))); timeline->events.add(new mementar::ContextualizedEvent("e12", mementar::Event(mementar::Fact("hum_blue|isInRoom|expe_room", false), mementar::SoftPoint(51,52)))); return timeline;