Skip to content

Commit

Permalink
[UPDATE] draw softpoint intervals
Browse files Browse the repository at this point in the history
  • Loading branch information
sarthou committed Jun 24, 2020
1 parent 1256632 commit 9707314
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 6 deletions.
7 changes: 7 additions & 0 deletions include/mementar/core/memGraphs/Branchs/types/SoftPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_; }
Expand Down
4 changes: 3 additions & 1 deletion include/mementar/graphical/timeline/EventReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/graphical/timeline/EventReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContextualizedEvent*>(evt)->isPartOfAction() == false)
{
auto event = dynamic_cast<ContextualizedEvent*>(evt);
group_evt.data += (group_evt.data == "" ? "" : " -- ") + event->Fact::toString();
if(event->getTransitionDuration() > group_evt.time_point.getTransitionDuration())
group_evt.time_point = SoftPoint(event);
}
}

Expand Down
32 changes: 31 additions & 1 deletion src/graphical/timeline/TimelineDrawer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/graphical/timeline/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 9707314

Please sign in to comment.