File: PixelOrientedOverview.cpp

package info (click to toggle)
tulip 4.8.0dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 179,264 kB
  • ctags: 64,517
  • sloc: cpp: 600,444; ansic: 36,311; makefile: 22,136; python: 1,304; sh: 946; yacc: 522; xml: 337; pascal: 157; php: 66; lex: 55
file content (234 lines) | stat: -rw-r--r-- 7,719 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/**
 *
 * This file is part of Tulip (www.tulip-software.org)
 *
 * Authors: David Auber and the Tulip development Team
 * from LaBRI, University of Bordeaux
 *
 * Tulip is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation, either version 3
 * of the License, or (at your option) any later version.
 *
 * Tulip is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 */

#include <tulip/GlTextureManager.h>
#include <tulip/Gl2DRect.h>
#include <tulip/ForEach.h>
#include <tulip/GlLabel.h>
#include <tulip/GlProgressBar.h>
#include <tulip/GlMainWidget.h>
#include <tulip/GlOffscreenRenderer.h>
#include <tulip/GlGraphComposite.h>

#include "PixelOrientedOverview.h"


using namespace pocore;
using namespace std;

template <typename T>
std::string getStringFromNumber(T number) {
  std::ostringstream oss;
  oss.precision(5);
  oss << number;
  return oss.str();
}

static void setGraphView (tlp::GlGraphComposite *glGraph) {
  tlp::GlGraphRenderingParameters param = glGraph->getRenderingParameters ();
  param.setAntialiasing (true);
  param.setViewNodeLabel (false);
  param.setFontsType (2);
  param.setSelectedNodesStencil(1);
  param.setNodesStencil(0xFFFF);
  param.setNodesLabelStencil(0xFFFF);
  param.setDisplayEdges(false);
  param.setDisplayNodes(true);
  glGraph->setRenderingParameters (param);
}

namespace tlp {

int PixelOrientedOverview::overviewCpt(0);

PixelOrientedOverview::PixelOrientedOverview(TulipGraphDimension *data, PixelOrientedMediator *pixelOrientedMediator,
    Coord blCornerPos, const std::string &dimName, const Color &backgroundColor, const Color &textColor)
  : data(data), pixelOrientedMediator(pixelOrientedMediator), blCornerPos(blCornerPos),
    dimName(dimName), frame(NULL), frame2(NULL), overviewGen(false), backgroundColor(backgroundColor), textColor(textColor) {

  if (this->dimName == "") {
    this->dimName = data->getDimensionName();
  }

  overviewId = overviewCpt++;

  textureName = dimName + " texture " + getStringFromNumber(overviewId);

  unsigned int width = pixelOrientedMediator->getImageWidth();
  unsigned int height = pixelOrientedMediator->getImageHeight();

  unsigned int labelHeight = height / 4;

  Graph *graph = data->getTulipGraph();
  pixelLayout = new LayoutProperty(graph);
  pixelSize = new SizeProperty(graph);
  graphComposite = new GlGraphComposite(graph);
  setGraphView(graphComposite);
  GlGraphInputData *glGraphInputData = graphComposite->getInputData();
  glGraphInputData->setElementLayout(pixelLayout);
  glGraphInputData->setElementSize(pixelSize);

  frame = new GlRect(Coord(blCornerPos.getX() - 3, blCornerPos.getY() + height + 3),
                     Coord(blCornerPos.getX() + width + 3, blCornerPos.getY() - 3),
                     Color(0, 0, 0), Color(0, 0, 0), false, true);
  addGlEntity(frame, dimName + "frame");
  frame2 = new GlRect(Coord(blCornerPos.getX() - 4, blCornerPos.getY() + height + 4),
                      Coord(blCornerPos.getX() + width + 4, blCornerPos.getY() - 4),
                      Color(0, 0, 0), Color(0, 0, 0), false, true);
  addGlEntity(frame2, dimName + "frame 2");

  backgroundRect = new GlRect(Coord(blCornerPos.getX(), blCornerPos.getY() + height), Coord(blCornerPos.getX() + width, blCornerPos.getY()), Color(255,255,255), Color(255,255,255), true, false);
  addGlEntity(backgroundRect, "background rect");
  clickLabel = new GlLabel(Coord(blCornerPos.getX() + width / 2, blCornerPos.getY() + height / 2), Size(width, height / 4), Color(0,0,0));
  clickLabel->setText("Double Click to generate overview");
  addGlEntity(clickLabel, "label");


  computeBoundingBox();

  overviewLabel = new GlLabel(Coord(blCornerPos.getX() + width / 2, blCornerPos.getY() - labelHeight / 2), Size(width, labelHeight), textColor);
  overviewLabel->setText(dimName);
  addGlEntity(overviewLabel, "overview label");
}

PixelOrientedOverview::~PixelOrientedOverview() {
  GlTextureManager::getInst().deleteTexture(textureName);
  reset(true);
}

struct NodeCoordXOrdering : public binary_function<pair<node, Coord>, pair<node, Coord>, bool> {
  bool operator()(pair<node, Coord> p1, pair<node, Coord> p2) {
    return p1.second.getX() < p2.second.getX();
  }
};

struct NodeCoordYOrdering : public binary_function<pair<node, Coord>, pair<node, Coord>, bool> {
  bool operator()(pair<node, Coord> p1, pair<node, Coord> p2) {
    return p1.second.getY() > p2.second.getY();
  }
};

void PixelOrientedOverview::computePixelView(GlMainWidget *glWidget) {

  reset(false);

  if (clickLabel != NULL) {
    delete clickLabel;
    clickLabel = NULL;
  }

  if (backgroundRect != NULL) {
    delete backgroundRect;
    backgroundRect = NULL;
  }

  if (frame != NULL) {
    delete frame;
    frame = NULL;
  }

  if (frame2 != NULL) {
    delete frame2;
    frame2 = NULL;
  }

  Graph *graph = data->getTulipGraph();

  unsigned int width = pixelOrientedMediator->getImageWidth();
  unsigned int height = pixelOrientedMediator->getImageHeight();

  GlProgressBar *glProgressBar = NULL;

  if (glWidget != NULL) {
    glProgressBar = new GlProgressBar(Coord(blCornerPos.getX() + width / 2, blCornerPos.getY() + height / 2), width, height, Color(0,0,255));
    glProgressBar->setComment("Generating overview ...");
    addGlEntity(glProgressBar, "progress bar");
  }

  unsigned int currentStep = 0;
  unsigned int maxStep = graph->numberOfNodes();
  unsigned int drawStep = maxStep / 10;

  set<int> xCoordSet;

  for (unsigned int i = 0 ; i < graph->numberOfNodes() ; ++i) {
    node n = node(data->getItemIdAtRank(i));
    pocore::Vec2i pos = pixelOrientedMediator->getPixelPosForRank(i);
    Coord nodeCoord = Coord(pos[0], pos[1], 0);
    xCoordSet.insert(pos[0]);
    pixelLayout->setNodeValue(n, nodeCoord);
    ++currentStep;

    if (glWidget != NULL && currentStep % drawStep == 0) {
      glProgressBar->progress(currentStep, maxStep);
      glWidget->draw();
    }
  }

  if (xCoordSet.size() < 2)
    return;

  set<int>::iterator it = xCoordSet.begin();
  int x1 = *(it++);
  int x2 = *it;
  int size = x2 - x1;

  pixelSize->setAllNodeValue(Size(size,size,size));

  overviewLabel->setColor(textColor);

  GlOffscreenRenderer *glOffscreenRenderer = GlOffscreenRenderer::getInstance();

  glOffscreenRenderer->setViewPortSize(width, height);
  glOffscreenRenderer->clearScene();
  glOffscreenRenderer->setSceneBackgroundColor(backgroundColor);
  glOffscreenRenderer->addGraphCompositeToScene(graphComposite);
  glOffscreenRenderer->renderScene(true);

  if (glWidget != NULL) {
    glProgressBar->progress(maxStep, maxStep);
    glWidget->draw();

    deleteGlEntity(glProgressBar);
    delete glProgressBar;
  }


  GLuint textureId = glOffscreenRenderer->getGLTexture(true);
  GlTextureManager::getInst().deleteTexture(textureName);
  GlTextureManager::getInst().registerExternalTexture(textureName, textureId);

  if (findGlEntity(dimName) == NULL) {
    addGlEntity(new Gl2DRect(blCornerPos.getY() + pixelOrientedMediator->getImageHeight() , blCornerPos.getY()
                             , blCornerPos.getX(), blCornerPos.getX()
                             + pixelOrientedMediator->getImageWidth(), textureName), dimName);
    addGlEntity(overviewLabel, "overview label");
    computeBoundingBox();
  }

  overviewGen = true;
}

void PixelOrientedOverview::setBLCorner(const Coord &blCorner) {
  GlComposite::translate(blCorner - blCornerPos);
  blCornerPos = blCorner;
  computeBoundingBox();
}

}