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 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
|
/**
*
* 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/TulipPluginHeaders.h>
#include <tulip/StringCollection.h>
using namespace std;
using namespace tlp;
namespace {
const char * paramHelp[] = {
// property
HTML_HELP_OPEN() \
HTML_HELP_DEF( "type", "NumericProperty" ) \
HTML_HELP_DEF( "default", "\"viewMetric\"" ) \
HTML_HELP_BODY() \
"Metric to map to size." \
HTML_HELP_CLOSE(),
// input
HTML_HELP_OPEN() \
HTML_HELP_DEF( "type", "SizeProperty" ) \
HTML_HELP_DEF( "default", "\"viewSize\"" ) \
HTML_HELP_BODY() \
"If not all dimensions (width, height, depth) are checked below, the dimensions not computed are copied from this property." \
HTML_HELP_CLOSE(),
// width, height, depth
HTML_HELP_OPEN() \
HTML_HELP_DEF( "type", "boolean" ) \
HTML_HELP_DEF( "values", "true/false" ) \
HTML_HELP_DEF( "default", "true" ) \
HTML_HELP_BODY() \
"Each checked dimension is adjusted to represent property, each unchecked dimension is copied from input." \
HTML_HELP_CLOSE(),
// min
HTML_HELP_OPEN() \
HTML_HELP_DEF( "type", "double" ) \
HTML_HELP_BODY() \
"Gives the minimum value of the range of computed sizes." \
HTML_HELP_CLOSE(),
// max
HTML_HELP_OPEN() \
HTML_HELP_DEF( "type", "double" ) \
HTML_HELP_BODY() \
"Gives the maximum value of the range of computed sizes." \
HTML_HELP_CLOSE(),
// Mapping type
HTML_HELP_OPEN() \
HTML_HELP_DEF( "type", "Boolean" ) \
HTML_HELP_DEF( "values", "true / false" ) \
HTML_HELP_DEF( "default", "true" ) \
HTML_HELP_BODY() \
"Type of mapping." \
"<ul><li>true: linear mapping (min value of property is mapped to min size, max to max size, and a linear interpolation is used in between.)</li>" \
"<li>false: uniform quantification (the values of property are sorted, and the same size increment is used between consecutive values).</li></ul>" \
HTML_HELP_CLOSE(),
// Mapping type
HTML_HELP_OPEN() \
HTML_HELP_DEF( "type", "Boolean" ) \
HTML_HELP_DEF( "values", "true / false" ) \
HTML_HELP_DEF( "default", "true" ) \
HTML_HELP_BODY() \
"If true the algorithm will compute the size of nodes else it will compute the size of edges :" \
"<ul><li>true : node size</li><li>false: edge size</li></ul>" \
HTML_HELP_CLOSE(),
//proportional mapping
HTML_HELP_OPEN() \
HTML_HELP_DEF( "type", "string" ) \
HTML_HELP_DEF( "default", "Area Proportional" ) \
HTML_HELP_BODY() \
"The mapping can either be area/volume proportional, or square/cubic;" \
"i.e. the areas/volumes will be proportional, or the dimensions (width, height and depth) will be." \
HTML_HELP_CLOSE(),
};
}
// error msg for invalid range value
static const string rangeSizeErrorMsg = "max size must be greater than min size";
static const string rangeMetricErrorMsg = "All values are the same";
static const string AREA_PROPORTIONAL = "Area Proportional";
/** \addtogroup size */
/// Size Mapping - Compute size of elements according to a metric.
/** This plugin enables to set the size of the graph's elements
* according to a metric.
*
*/
class MetricSizeMapping:public SizeAlgorithm {
public:
PLUGININFORMATION("Size Mapping","Auber","08/08/2003","Maps the sizes of the graph elements onto the values of a given numeric property.","2.0", "Size")
MetricSizeMapping(const PluginContext* context):SizeAlgorithm(context),
entryMetric(NULL), entrySize(NULL), xaxis(true), yaxis(true), zaxis(true),
mappingType(true), min(1), max(10), range(0), shift(0), nodeoredge(true) {
addInParameter<NumericProperty*>("property", paramHelp[0], "viewMetric");
addInParameter<SizeProperty>("input", paramHelp[1], "viewSize");
addInParameter<bool>("width", paramHelp[2],"true");
addInParameter<bool>("height", paramHelp[2],"true");
addInParameter<bool>("depth", paramHelp[2],"false");
addInParameter<double>("min size",paramHelp[3],"1");
addInParameter<double>("max size",paramHelp[4],"10");
addInParameter<bool>("type", paramHelp[5],"true");
addInParameter<bool>("node/edge", paramHelp[6],"true");
addInParameter<StringCollection>("area proportional", paramHelp[7], "Area Proportional;Quadratic/Cubic");
}
bool check(std::string &errorMsg) {
xaxis=yaxis=zaxis=true;
min=1;
max=10;
nodeoredge = true;
proportional = "Area Proportional";
entryMetric = NULL;
entrySize = NULL;
mappingType = true;
StringCollection proportionalType;
if ( dataSet!=NULL ) {
dataSet->get("property",entryMetric);
dataSet->get("input",entrySize);
dataSet->get("width",xaxis);
dataSet->get("height",yaxis);
dataSet->get("depth",zaxis);
dataSet->get("min size",min);
dataSet->get("max size",max);
dataSet->get("type",mappingType);
dataSet->get("node/edge",nodeoredge);
dataSet->get("area proportional",proportionalType);
proportional = proportionalType.getCurrentString();
}
if (!entryMetric)
entryMetric=graph->getProperty<DoubleProperty>("viewMetric");
if (!entrySize)
entrySize=graph->getProperty<SizeProperty>("viewSize");
if (min >= max) {
errorMsg = rangeSizeErrorMsg;
return false;
}
if (nodeoredge)
range = entryMetric->getNodeDoubleMax(graph) - entryMetric->getNodeDoubleMin(graph);
else
range = entryMetric->getEdgeDoubleMax(graph) - entryMetric->getEdgeDoubleMin(graph);
if (!range) {
errorMsg = rangeMetricErrorMsg;
return false;
}
if(!xaxis && !yaxis && !zaxis) {
errorMsg = "You need at least one axis to map on.";
return false;
}
if(proportional == AREA_PROPORTIONAL) {
max = max*max;
}
return true;
}
bool run() {
NumericProperty *tmp = NULL;
if (!mappingType) {
tmp = entryMetric->copyProperty(graph);
tmp->uniformQuantification(300);
entryMetric = tmp;
}
unsigned int maxIter = graph->numberOfNodes() + graph->numberOfEdges();
unsigned int iter = 0;
pluginProgress->showPreview(false);
if(nodeoredge) {
shift = entryMetric->getNodeDoubleMin(graph);
// compute size of nodes
Iterator<node> *itN=graph->getNodes();
while(itN->hasNext()) {
node itn=itN->next();
double sizos = 0;
if (proportional == AREA_PROPORTIONAL) {
const double power = 1.0 / (float(xaxis) + float(yaxis) + float(zaxis));
sizos = min + pow((entryMetric->getNodeDoubleValue(itn)-shift)*(max-min)/range, power);
}
else {
sizos = min + (entryMetric->getNodeDoubleValue(itn)-shift)*(max-min)/range;
}
Size size=entrySize->getNodeValue(itn);
if (xaxis) size[0]=static_cast<float>(sizos);
if (yaxis) size[1]=static_cast<float>(sizos);
if (zaxis) size[2]=static_cast<float>(sizos);
result->setNodeValue(itn, size);
if ((++iter % 500 == 0) &&
(pluginProgress->progress(iter, maxIter)!=TLP_CONTINUE)) {
delete itN;
if (!mappingType) delete tmp;
return false;
}
}
delete itN;
edge e;
forEach(e, graph->getEdges()) {
result->setEdgeValue(e, entrySize->getEdgeValue(e));
if ((++iter % 500 == 0) &&
(pluginProgress->progress(iter, maxIter)!=TLP_CONTINUE)) {
if (!mappingType) delete tmp;
return false;
}
}
}
else {
shift = entryMetric->getEdgeDoubleMin(graph);
// compute size of edges
Iterator<edge> *itE=graph->getEdges();
while(itE->hasNext()) {
edge ite=itE->next();
double sizos =
min+(entryMetric->getEdgeDoubleValue(ite)-shift)*(max-min)/range;
Size size = entrySize->getEdgeValue(ite);
size[0] = static_cast<float>(sizos);
size[1] = static_cast<float>(sizos);
result->setEdgeValue(ite, size);
if ((++iter % 500 == 0) &&
(pluginProgress->progress(iter, maxIter)!=TLP_CONTINUE)) {
delete itE;
if (!mappingType) delete tmp;
return pluginProgress->state()!=TLP_CANCEL;
}
}
delete itE;
node n;
forEach(n, graph->getNodes()) {
result->setNodeValue(n, entrySize->getNodeValue(n));
if ((++iter % 500 == 0) &&
(pluginProgress->progress(iter, maxIter)!=TLP_CONTINUE)) {
if (!mappingType) delete tmp;
return pluginProgress->state()!=TLP_CANCEL;
}
}
}
if (!mappingType) delete tmp;
return true;
}
private:
NumericProperty *entryMetric;
SizeProperty *entrySize;
bool xaxis,yaxis,zaxis,mappingType;
double min,max;
double range;
double shift;
bool nodeoredge;
std::string proportional;
};
PLUGIN(MetricSizeMapping)
|