本文整理汇总了C++中GraphAttributes::width方法的典型用法代码示例。如果您正苦于以下问题:C++ GraphAttributes::width方法的具体用法?C++ GraphAttributes::width怎么用?C++ GraphAttributes::width使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GraphAttributes
的用法示例。
在下文中一共展示了GraphAttributes::width方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: exportAttributesSimple
// assumes, that the Graphs of MultilevelGraph and GA are the same, not copies!
void MultilevelGraph::exportAttributesSimple(GraphAttributes &GA) const
{
OGDF_ASSERT(&(GA.constGraph()) == m_G);
prepareGraphAttributes(GA);
for(node v : m_G->nodes) {
GA.x(v) = m_GA->x(v);
GA.y(v) = m_GA->y(v);
//TODO: Check what this w,h computation does
double w = GA.width(v);
double h = GA.height(v);
if(w > 0 || h > 0) {
double factor = m_radius[v] / sqrt(w*w + h*h) * 2.0f;
w *= factor;
h *= factor;
} else {
w = h = m_radius[v] * sqrt(2.0f);
}
GA.width(v) = w;
GA.height(v) = h;
GA.weight(v) = m_reverseNodeMergeWeight[v->index()];
}
for(edge e : m_G->edges) {
GA.doubleWeight(e) = m_weight[e];
}
}
示例2: importAttributesSimple
void MultilevelGraph::importAttributesSimple(const GraphAttributes &GA)
{
OGDF_ASSERT(&(GA.constGraph()) == m_G);
m_avgRadius = 0.0;
for(node v : m_G->nodes) {
double w = GA.width(v);
double h = GA.height(v);
if(w > 0 || h > 0) {
m_radius[v] = sqrt(w*w + h*h) / 2.0f;
} else {
m_radius[v] = 1.0f;
}
m_avgRadius += m_radius[v];
m_GA->x(v) = GA.x(v);
m_GA->y(v) = GA.y(v);
m_GA->width(v) = GA.width(v);
m_GA->height(v) = GA.height(v);
}
m_avgRadius /= m_G->numberOfNodes();
for(edge e : m_G->edges) {
m_weight[e] = GA.doubleWeight(e);
}
}
示例3: computeAutoEdgeLength
void FastMultipoleMultilevelEmbedder::computeAutoEdgeLength(const GraphAttributes& GA, EdgeArray<float>& edgeLength, float factor)
{
for(edge e : GA.constGraph().edges)
{
node v = e->source();
node w = e->target();
float radius_v = (float)sqrt(GA.width(v)*GA.width(v) + GA.height(v)*GA.height(v)) * 0.5f;
float radius_w = (float)sqrt(GA.width(w)*GA.width(w) + GA.height(w)*GA.height(w)) * 0.5f;
float sum = radius_v + radius_w;
if (OGDF_GEOM_ET.equal(sum, (float) 0))
sum = 1.0;
edgeLength[e] = factor*(sum);
}
}
示例4: placeIsolatedNodes
//the vertices with degree zero are placed below all other vertices on a horizontal
// line centered with repect to the rest of the drawing
void DavidsonHarel::placeIsolatedNodes(GraphAttributes &AG) const {
double minX = 0.0;
double minY = 0.0;
double maxX = 0.0;
if (!m_nonIsolatedNodes.empty()) {
//compute a rectangle that includes all non-isolated vertices
node vFirst = m_nonIsolatedNodes.front();
minX = AG.x(vFirst);
minY = AG.y(vFirst);
maxX = minX;
double maxY = minY;
for (node v : m_nonIsolatedNodes) {
double xVal = AG.x(v);
double yVal = AG.y(v);
double halfHeight = AG.height(v) / 2.0;
double halfWidth = AG.width(v) / 2.0;
if (xVal - halfWidth < minX) minX = xVal - halfWidth;
if (xVal + halfWidth > maxX) maxX = xVal + halfWidth;
if (yVal - halfHeight < minY) minY = yVal - halfHeight;
if (yVal + halfHeight > maxY) maxY = yVal + halfHeight;
}
}
// compute the width and height of the largest isolated node
List<node> isolated;
const Graph &G = AG.constGraph();
double maxWidth = 0;
double maxHeight = 0;
for (node v : G.nodes)
if (v->degree() == 0) {
isolated.pushBack(v);
if (AG.height(v) > maxHeight) maxHeight = AG.height(v);
if (AG.width(v) > maxWidth) maxWidth = AG.width(v);
}
// The nodes are placed on a line in the middle under the non isolated vertices.
// Each node gets a box sized 2 maxWidth.
double boxWidth = 2.0*maxWidth;
double commonYCoord = minY - (1.5*maxHeight);
double XCenterOfDrawing = minX + ((maxX - minX) / 2.0);
double startXCoord = XCenterOfDrawing - 0.5*(isolated.size()*boxWidth);
double xcoord = startXCoord;
for (node v : isolated) {
AG.x(v) = xcoord;
AG.y(v) = commonYCoord;
xcoord += boxWidth;
}
}
示例5: ComputeDiameters
void RadialTreeLayout::ComputeDiameters(GraphAttributes &AG)
{
const Graph &G = AG.constGraph();
m_diameter.init(G);
m_nodes.init(m_numLevels);
m_width.init(m_numLevels);
m_width.fill(0);
for(node v : G.nodes)
{
int i = m_level[v];
m_nodes[i].pushBack(v);
double w = AG.width(v);
double h = AG.height(v);
m_diameter[v] = sqrt(w*w+h*h);
double m = max(w, h);
m = max(m, sqrt(w*w+h*h));
if(m_diameter[v] > m_width[i])
m_width[i] = m_diameter[v];
}
}
示例6: call
void FastMultipoleEmbedder::call(GraphAttributes &GA)
{
EdgeArray<float> edgeLength(GA.constGraph());
NodeArray<float> nodeSize(GA.constGraph());
for(node v : GA.constGraph().nodes)
{
nodeSize[v] = (float)sqrt(GA.width(v)*GA.width(v) + GA.height(v)*GA.height(v)) * 0.5f;
}
for(edge e : GA.constGraph().edges)
{
edgeLength[e] = nodeSize[e->source()] + nodeSize[e->target()];
}
call(GA, edgeLength, nodeSize);
}
示例7: readColor
static inline bool readVizAttribute(
GraphAttributes &GA,
node v,
const pugi::xml_node tag)
{
const long attrs = GA.attributes();
if(string(tag.name()) == "viz:position") {
if(attrs & GraphAttributes::nodeGraphics) {
pugi::xml_attribute xAttr = tag.attribute("x");
pugi::xml_attribute yAttr = tag.attribute("y");
pugi::xml_attribute zAttr = tag.attribute("z");
if(!xAttr || !yAttr) {
GraphIO::logger.lout() << "Missing \"x\" or \"y\" in position tag." << std::endl;
return false;
}
GA.x(v) = xAttr.as_int();
GA.y(v) = yAttr.as_int();
// z attribute is optional and avaliable only in \a threeD mode
GA.y(v) = yAttr.as_int();
if (zAttr && (attrs & GraphAttributes::threeD)) {
GA.z(v) = zAttr.as_int();
}
}
} else if(string(tag.name()) == "viz:size") {
if(attrs & GraphAttributes::nodeGraphics) {
pugi::xml_attribute valueAttr = tag.attribute("value");
if (!valueAttr) {
GraphIO::logger.lout() << "\"size\" attribute is missing a value." << std::endl;
return false;
}
double size = valueAttr.as_double();
GA.width(v) = size * LayoutStandards::defaultNodeWidth();
GA.height(v) = size * LayoutStandards::defaultNodeHeight();
}
} else if(string(tag.name()) == "viz:shape") {
if(attrs & GraphAttributes::nodeGraphics) {
pugi::xml_attribute valueAttr = tag.attribute("value");
if(!valueAttr) {
GraphIO::logger.lout() << "\"shape\" attribute is missing a value." << std::endl;
return false;
}
GA.shape(v) = toShape(valueAttr.value());
}
} else if(string(tag.name()) == "viz:color") {
if(attrs & GraphAttributes::nodeStyle) {
return readColor(GA.fillColor(v), tag);
}
} else {
GraphIO::logger.lout() << "Incorrect tag: \"" << tag.name() << "\"." << std::endl;
return false;
}
return true;
}
示例8: compact
void DominanceLayout::compact(const UpwardPlanRep &UPR, GraphAttributes &GA)
{
double maxNodeSize = 0;
for(node v : GA.constGraph().nodes) {
if (GA.width(v) > maxNodeSize || GA.height(v) > maxNodeSize)
maxNodeSize = max(GA.width(v), GA.height(v));
}
int gridDist = m_grid_dist;
if (gridDist < maxNodeSize+1)
gridDist = (int) maxNodeSize+1;
xCoord.init(UPR);
yCoord.init(UPR);
//ASSIGN X COORDINATE
OGDF_ASSERT(!xNodes.empty());
node v = xNodes.popFrontRet();
xCoord[v] = 0;
while (!xNodes.empty()) {
node u = xNodes.popFrontRet();
if ( (yPreCoord[v] > yPreCoord[u]) || (firstout[v] == lastout[v] && firstin[u] == lastin[u] && m_L <= m_R)) {
xCoord[u] = xCoord[v] + gridDist;
}
else
xCoord[u] = xCoord[v];
v = u;
}
//ASSIGN Y COORDINATE
OGDF_ASSERT(!yNodes.empty());
v = yNodes.popFrontRet();
yCoord[v] = 0;
while (!yNodes.empty()) {
node u = yNodes.popFrontRet();
if ( (xPreCoord[v] > xPreCoord[u]) || (firstout[v] == lastout[v] && firstin[u] == lastin[u] && m_L > m_R)) {
yCoord[u] = yCoord[v] + gridDist;
}
else
yCoord[u] = yCoord[v];
v = u;
}
}
示例9: importAttributes
void MultilevelGraph::importAttributes(const GraphAttributes &GA)
{
OGDF_ASSERT(GA.constGraph().numberOfNodes() == m_G->numberOfNodes());
OGDF_ASSERT(GA.constGraph().numberOfEdges() == m_G->numberOfEdges());
m_avgRadius = 0.0;
std::vector<node> tempNodeAssociations;
const Graph &cG = GA.constGraph();
tempNodeAssociations.resize(cG.maxNodeIndex()+1, nullptr);
for(node v : cG.nodes) {
tempNodeAssociations[v->index()] = v;
}
for(node v : m_G->nodes) {
double w = GA.width(tempNodeAssociations[m_nodeAssociations[v]]);
double h = GA.height(tempNodeAssociations[m_nodeAssociations[v]]);
if(w > 0 || h > 0) {
m_radius[v] = sqrt(w*w + h*h) / 2.0f;
} else {
m_radius[v] = 1.0f;
}
m_avgRadius += m_radius[v];
m_GA->x(v) = GA.x(tempNodeAssociations[m_nodeAssociations[v]]);
m_GA->y(v) = GA.y(tempNodeAssociations[m_nodeAssociations[v]]);
m_GA->width(v) = GA.width(tempNodeAssociations[m_nodeAssociations[v]]);
m_GA->height(v) = GA.height(tempNodeAssociations[m_nodeAssociations[v]]);
}
m_avgRadius /= m_G->numberOfNodes();
std::vector<edge> tempEdgeAssociations;
tempEdgeAssociations.resize(cG.maxEdgeIndex()+1, nullptr);
for(edge e : cG.edges) {
tempEdgeAssociations[e->index()] = e;
}
for(edge e : m_G->edges) {
m_weight[e] = GA.doubleWeight(tempEdgeAssociations[m_edgeAssociations[e]]);
}
}
示例10: call
void TutteLayout::call(GraphAttributes &AG)
{
const Graph &G = AG.constGraph();
List<node> fixedNodes;
List<DPoint> positions;
double diam =
sqrt((m_bbox.width()) * (m_bbox.width())
+ (m_bbox.height()) * (m_bbox.height()));
// handle graphs with less than two nodes
switch (G.numberOfNodes()) {
case 0:
return;
case 1:
node v = G.firstNode();
DPoint center(0.5 * m_bbox.width(),0.5 * m_bbox.height());
center = center + m_bbox.p1();
AG.x(v) = center.m_x;
AG.y(v) = center.m_y;
return;
}
// increase radius to have no overlap on the outer circle
node v = G.firstNode();
double r = diam/2.8284271;
int n = G.numberOfNodes();
double nodeDiam = 2.0*sqrt((AG.width(v)) * (AG.width(v))
+ (AG.height(v)) * (AG.height(v)));
if(r<nodeDiam/(2*sin(2*Math::pi/n))) {
r=nodeDiam/(2*sin(2*Math::pi/n));
m_bbox = DRect (0.0, 0.0, 2*r, 2*r);
}
setFixedNodes(G,fixedNodes,positions,r);
doCall(AG,fixedNodes,positions);
}
示例11: call
void ComponentSplitterLayout::call(GraphAttributes &GA)
{
// Only do preparations and call if layout is valid
if (m_secondaryLayout.valid())
{
//first we split the graph into its components
const Graph& G = GA.constGraph();
NodeArray<int> componentNumber(G);
m_numberOfComponents = connectedComponents(G, componentNumber);
if (m_numberOfComponents == 0) {
return;
}
//std::vector< std::vector<node> > componentArray;
//componentArray.resize(numComponents);
//Array<GraphAttributes *> components(numComponents);
//
// intialize the array of lists of nodes contained in a CC
nodesInCC.init(m_numberOfComponents);
node v;
forall_nodes(v,G)
nodesInCC[componentNumber[v]].pushBack(v);
// Create copies of the connected components and corresponding
// GraphAttributes
GraphCopy GC;
GC.createEmpty(G);
EdgeArray<edge> auxCopy(G);
for (int i = 0; i < m_numberOfComponents; i++)
{
GC.initByNodes(nodesInCC[i],auxCopy);
GraphAttributes cGA(GC);
//copy information into copy GA
forall_nodes(v, GC)
{
cGA.width(v) = GA.width(GC.original(v));
cGA.height(v) = GA.height(GC.original(v));
cGA.x(v) = GA.x(GC.original(v));
cGA.y(v) = GA.y(GC.original(v));
}
m_secondaryLayout.get().call(cGA);
//copy layout information back into GA
forall_nodes(v, GC)
{
node w = GC.original(v);
if (w != 0)
GA.x(w) = cGA.x(v);
GA.y(w) = cGA.y(v);
}
}
示例12: exportAttributes
void MultilevelGraph::exportAttributes(GraphAttributes &GA) const
{
OGDF_ASSERT(GA.constGraph().numberOfNodes() == m_G->numberOfNodes());
OGDF_ASSERT(GA.constGraph().numberOfEdges() == m_G->numberOfEdges());
prepareGraphAttributes(GA);
std::vector<node> tempNodeAssociations;
const Graph &cG = GA.constGraph();
tempNodeAssociations.resize(cG.maxNodeIndex()+1, nullptr);
for(node v : cG.nodes) {
tempNodeAssociations[v->index()] = v;
}
for(node v : m_G->nodes) {
GA.x(tempNodeAssociations[m_nodeAssociations[v]]) = m_GA->x(v);
GA.y(tempNodeAssociations[m_nodeAssociations[v]]) = m_GA->y(v);
double w = GA.width(tempNodeAssociations[m_nodeAssociations[v]]);
double h = GA.height(tempNodeAssociations[m_nodeAssociations[v]]);
if(w > 0 || h > 0) {
double factor = m_radius[v] / sqrt(w*w + h*h) * 2.0f;
w *= factor;
h *= factor;
} else {
w = h = m_radius[v] * sqrt(2.0f);
}
GA.width(tempNodeAssociations[m_nodeAssociations[v]]) = w;
GA.height(tempNodeAssociations[m_nodeAssociations[v]]) = h;
GA.weight(tempNodeAssociations[m_nodeAssociations[v]]) = m_reverseNodeMergeWeight[v->index()];
}
std::vector<edge> tempEdgeAssociations;
tempEdgeAssociations.resize(cG.maxEdgeIndex()+1, nullptr);
for(edge e :cG.edges) {
tempEdgeAssociations[e->index()] = e;
}
for(edge e : m_G->edges) {
GA.doubleWeight(tempEdgeAssociations[m_edgeAssociations[e]]) = m_weight[e];
}
}
示例13: compute_bounding_box
static void compute_bounding_box(const GraphAttributes &A, double &xmin, double &ymin, double &xmax, double &ymax)
{
const Graph &G = A.constGraph();
if(G.numberOfNodes() == 0) {
xmin = xmax = ymin = ymax = 0;
return;
}
node v = G.firstNode();
xmin = xmax = A.x(v),
ymin = ymax = A.y(v);
forall_nodes(v, G) {
double lw = (A.attributes() & GraphAttributes::nodeStyle) ? 0.5*A.strokeWidth(v) : 0.5;
xmax = max(xmax, A.x(v) + A.width (v)/2 + lw);
ymax = max(ymax, A.y(v) + A.height(v)/2 + lw);
xmin = min(xmin, A.x(v) - A.width (v)/2 - lw);
ymin = min(ymin, A.y(v) - A.height(v)/2 - lw);
}
示例14:
inline void FMMMLayout :: import_NodeAttributes(const Graph& G, GraphAttributes& GA,
NodeArray<NodeAttributes>& A)
{
node v;
DPoint position;
forall_nodes(v,G)
{
position.m_x = GA.x(v);
position.m_y = GA.y(v);
A[v].set_NodeAttributes(GA.width(v),GA.height(v),position,NULL,NULL);
}
示例15: mapGridLayout
void GridLayoutModule::mapGridLayout(const Graph &G,
GridLayout &gridLayout,
GraphAttributes &AG)
{
double maxWidth = 0; // maximum width of columns and rows;
double yMax = 0;
node v;
forall_nodes(v,G) {
if (AG.width (v) > maxWidth) maxWidth = AG.width (v);
if (AG.height(v) > maxWidth) maxWidth = AG.height(v);
if (gridLayout.y(v) > yMax) yMax = gridLayout.y(v);
}
maxWidth += m_separation;
// set position of nodes
forall_nodes(v,G) {
AG.x(v) = gridLayout.x(v) * maxWidth;
AG.y(v) = (yMax - gridLayout.y(v)) * maxWidth;
}