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
|
/**
*
* 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 "TulipGraphDimension.h"
#include <tulip/DoubleProperty.h>
#include <tulip/IntegerProperty.h>
#include <tulip/StringProperty.h>
#include <set>
using namespace tlp;
using namespace std;
namespace pocore {
map<Graph *, unsigned int> TulipGraphDimension::graphDimensionsMap;
TulipGraphDimension::TulipGraphDimension(Graph *graph, const string& dimName) : graph(graph), dimName(dimName) {
nodeSorter = TulipNodeMetricSorter::getInstance(graph);
nodeSorter->sortNodesForProperty(dimName);
propertyType = graph->getProperty(dimName)->getTypename();
if (graphDimensionsMap.find(graph) == graphDimensionsMap.end()) {
graphDimensionsMap[graph] = 1;
}
else {
++graphDimensionsMap[graph];
}
}
TulipGraphDimension::~TulipGraphDimension() {
--graphDimensionsMap[graph];
if (graphDimensionsMap[graph] == 0) {
delete nodeSorter;
graphDimensionsMap.erase(graph);
}
}
void TulipGraphDimension::updateNodesRank() {
nodeSorter->sortNodesForProperty(dimName);
}
unsigned int TulipGraphDimension::numberOfItems() const {
return graph->numberOfNodes();
}
unsigned int TulipGraphDimension::numberOfValues() const {
return nodeSorter->getNbValuesForProperty(dimName);
}
template <typename PROPERTY>
double TulipGraphDimension::getNodeValue(const node n) const {
PROPERTY *dimValues = graph->getProperty<PROPERTY>(dimName);
double d = dimValues->getNodeValue(n);
double delta = maxValue() - minValue();
return (d - minValue()) / delta;
}
std::string TulipGraphDimension::getItemLabelAtRank(const unsigned int rank) const {
node n = nodeSorter->getNodeAtRankForProperty(rank, dimName);
string label = graph->getProperty<StringProperty>("viewLabel")->getNodeValue(n);
return label;
}
std::string TulipGraphDimension::getItemLabel(const unsigned int itemId) const {
string label = graph->getProperty<StringProperty>("viewLabel")->getNodeValue(node(itemId));
return label;
}
double TulipGraphDimension::getItemValue(const unsigned int itemId) const {
if (propertyType == "double") {
return getNodeValue<DoubleProperty>(node(itemId));
}
else if (propertyType == "int") {
return getNodeValue<IntegerProperty>(node(itemId));
}
else {
return 0;
}
}
double TulipGraphDimension::getItemValueAtRank(const unsigned int rank) const {
node n = nodeSorter->getNodeAtRankForProperty(rank, dimName);
if (propertyType == "double") {
return getNodeValue<DoubleProperty>(n);
}
else if (propertyType == "int") {
return getNodeValue<IntegerProperty>(n);
}
else {
return 0;
}
}
unsigned int TulipGraphDimension::getItemIdAtRank(const unsigned int rank) {
node n = nodeSorter->getNodeAtRankForProperty(rank, dimName);
return n.id;
}
unsigned int TulipGraphDimension::getRankForItem(const unsigned int itemId) {
return nodeSorter->getNodeRankForProperty(node(itemId), dimName);
}
double TulipGraphDimension::minValue() const {
if (propertyType == "double") {
return graph->getProperty<DoubleProperty>(dimName)->getNodeMin(graph);
}
else if (propertyType == "int") {
return graph->getProperty<IntegerProperty>(dimName)->getNodeMin(graph);
}
else {
return 0;
}
}
double TulipGraphDimension::maxValue() const {
if (propertyType == "double") {
return graph->getProperty<DoubleProperty>(dimName)->getNodeMax(graph);
}
else if (propertyType == "int") {
return graph->getProperty<IntegerProperty>(dimName)->getNodeMax(graph);
}
else {
return 0;
}
}
vector<unsigned int> TulipGraphDimension::links(const unsigned int itemId) const {
vector<unsigned int> v;
Iterator<node> *inNodesIt = graph->getInNodes(node(itemId));
while (inNodesIt->hasNext()) {
v.push_back(inNodesIt->next().id);
}
delete inNodesIt;
Iterator<node> *outNodesIt = graph->getOutNodes(node(itemId));
while (outNodesIt->hasNext()) {
v.push_back(outNodesIt->next().id);
}
delete outNodesIt;
return v;
}
}
|