Fréchet View  1.6.0
A Tool for Exploring Fréchet Distance Algorithms
intervalview.cpp
Go to the documentation of this file.
1 
2 #include <intervalview.h>
3 #include <freespaceview.h>
4 
5 #include <QPen>
6 #include <QGraphicsScene>
7 
8 using namespace frechet;
9 using namespace data;
10 using namespace view;
11 
12 //const double IntervalView::ROW_HEIGHT = 3.0;
13 //const QPen IntervalView::LINE_PEN (Qt::black,2.0,Qt::SolidLine,Qt::FlatCap);
14 
15 IntervalView::IntervalView(frechet::Grid::ptr agrid,
17  Palette* apalette,
18  double pen_width,
19  QGraphicsItem* parent)
20  : QGraphicsItemGroup(parent),
21  orientation(orient),
22  grid(agrid),
23  stack(), stack_watermark(0),
24  palette(apalette), itemPool()
25 {
26  LINE_PEN = QPen(Qt::black,pen_width,Qt::SolidLine,Qt::FlatCap);
27  ROW_HEIGHT = pen_width*3/2;
28 }
29 
31  stack.clear();
32  // remove all children
33  foreach(QGraphicsItem* item, childItems())
34  releaseItem(item);
35 }
36 
37 QGraphicsLineItem* IntervalView::createItem()
38 {
39  if (itemPool.isEmpty())
40  return new QGraphicsLineItem(this);
41  else
42  return itemPool.takeFirst();
43 }
44 
45 void IntervalView::releaseItem(QGraphicsItem* item)
46 {
47  removeFromGroup(item);
48  scene()->removeItem(item);
49  itemPool.append((QGraphicsLineItem*)item);
50 }
51 
52 
53 void IntervalView::add(const Interval& ival, size_t component) {
54  if (!ival)
55  return;
56 
57  Interval gval;
58  // map to view coordinates
60  gval = grid->hor().map(ival);
61  else
62  gval = grid->vert().map(ival);
63  // convert to boost interval
64  boost_ival bval(gval.lower(),gval.upper());
65 
66  // add a QGraphicsLine
67  QGraphicsLineItem* line = createItem();
68  line->setLine(insert(bval));
69  line->setData(0,(int)component);
70  setItemColor(line, (*palette)[component]);
71 
72  addToGroup(line);
73 }
74 
76 {
77  add(mval, mval.componentID);
78 }
79 
81 {
82  for(frechet::k::IntervalMap::const_iterator i = mvals.begin(); i != mvals.end(); ++i)
83  add(*i);
84 }
85 
86 
87 
88 void IntervalView::setItemColor(QGraphicsLineItem* item, QColor col)
89 {
90  QPen pen = LINE_PEN;
91  pen.setColor(col);
92  item->setPen(pen);
93 }
94 
95 void IntervalView::showResult(const BitSet* resultSet)
96 {
97  foreach(QGraphicsItem* line, childItems())
98  {
99  size_t component = line->data(0).toUInt();
100  setItemColor((QGraphicsLineItem*)line,
101  !resultSet || resultSet->contains(component) ?
102  (*palette)[component] : FreeSpaceView::LIGHT_GRAY);
103  }
104 }
105 
106 
107 QLineF IntervalView::insert(const boost_ival& ival)
108 {
109  int row = findRow(ival);
110  stack[row].insert(ival);
111  if (orientation==HORIZONTAL)
112  return QLineF(
113  ival.lower(), -(row+1)*ROW_HEIGHT,
114  ival.upper(), -(row+1)*ROW_HEIGHT);
115  else
116  return QLineF(
117  -(row+1)*ROW_HEIGHT, ival.lower(),
118  -(row+1)*ROW_HEIGHT, ival.upper());
119 }
120 
122 {
123  // find a free location in the stack
124  for(int row=0; row < stack.size(); ++row)
125  {
126  if (ival.lower()==ival.upper())
127  {
128  if (stack[row].find(ival.lower()) == stack[row].end())
129  return row;
130  }
131  else
132  {
133  if (stack[row].find(ival) == stack[row].end())
134  return row;
135  }
136  }
137  // create a new row
138  stack.push_back(boost::icl::interval_set<double>());
139  if (stack.size() > stack_watermark)
140  stack_watermark = stack.size();
141  return stack.size()-1;
142 }
void add(const Interval &ival, size_t component)
add an interval
static const QColor LIGHT_GRAY
used for disabled components (k-Frechet)
boost::icl::continuous_interval< double > boost_ival
what's this?
Definition: intervalview.h:45
global definitions for all algorithms.
std::vector< MappedInterval > IntervalMap
a vector of MappedInterval objects. Usually these are sorted according to the natural ordering impose...
Definition: kalgorithm.h:71
Palette * palette
color palette
Definition: intervalview.h:54
Orientation
orientation: horizontal or vertical
Definition: intervalview.h:37
attaches a component ID to an interval
Definition: kalgorithm.h:32
std::vector< boost_ivalset > stack
stack of intervals
Definition: intervalview.h:50
double upper() const
Definition: interval.h:96
void setItemColor(QGraphicsLineItem *item, QColor col)
update ttem color
double ROW_HEIGHT
height of a row
Definition: intervalview.h:39
a color map.
Definition: palette.h:17
bool contains(int offset) const
Definition: bitset.cpp:71
int findRow(const boost_ival &ival)
place a new interval in a free space
double lower() const
Definition: interval.h:92
void showResult(const frechet::data::BitSet *resultSet)
highlight result set of a k-Frechet algorithm. All intervals that are not part of the result set are ...
enum frechet::view::IntervalView::Orientation orientation
boost::shared_ptr< Grid > ptr
smart pointer to a Grid object
Definition: grid.h:128
QQueue< QGraphicsLineItem * > itemPool
pool of unused QGraphicsItems
Definition: intervalview.h:56
int stack_watermark
stack watermark
Definition: intervalview.h:52
void addAll(const k::IntervalMap &mvals)
add a set of intervals
A simple bit vector of fixed size.
Definition: bitset.h:16
void releaseItem(QGraphicsItem *)
release item
QGraphicsLineItem * createItem()
create a line item
QLineF insert(const boost_ival &ival)
insert an interval
QPen LINE_PEN
pen for drawing lines
Definition: intervalview.h:58
an interval of two double values.
Definition: interval.h:31
Grid::ptr grid
coordinate grid
Definition: intervalview.h:48
void clear()
remove all intervals