当前位置: 首页>>代码示例>>C++>>正文


C++ GraphAttributes::x方法代码示例

本文整理汇总了C++中GraphAttributes::x方法的典型用法代码示例。如果您正苦于以下问题:C++ GraphAttributes::x方法的具体用法?C++ GraphAttributes::x怎么用?C++ GraphAttributes::x使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GraphAttributes的用法示例。


在下文中一共展示了GraphAttributes::x方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: EdgeOrthogonalityCriterium

/*
 * calculate edge orthogonality criterium
 */
double EdgeOrthogonalityCriterium(Graph& G, GraphAttributes& GA) {
	double sum = 0;

	for (edge e : G.edges) {
		node s = e->source();
		node t = e->target();

		double s_x = GA.x(s);
		double s_y = GA.y(s);

		double t_x = GA.x(t);
		double t_y = GA.y(t);

		double angle = abs(atan2(s_y - t_y, t_x - s_x) * 180 / PI);
		Array<double> values = { angle, abs(90.0 - angle), abs(180.0 - angle) };
		double *deviation = min_element(begin(values), end(values));
		*deviation = *deviation / 45;

		sum += *deviation;
	}
	
	double Neo = 1.0 - ((1.0 / G.edges.size()) * sum);

	return Neo;
}
开发者ID:bartvdput,项目名称:scriptie,代码行数:28,代码来源:scriptie.cpp

示例2: pivotMDSLayout

void PivotMDS::pivotMDSLayout(GraphAttributes& GA)
{
	const Graph& G = GA.constGraph();
	bool use3D = GA.has(GraphAttributes::threeD) && DIMENSION_COUNT > 2;

	const int n = G.numberOfNodes();

	// trivial cases
	if (n == 0)
		return;

	if (n == 1) {
		node v1 = G.firstNode();
		GA.x(v1) = 0.0;
		GA.y(v1) = 0.0;
		if (use3D)
			GA.z(v1) = 0.0;
		return;
	}

	// check whether the graph is a path or not
	const node head = getRootedPath(G);
	if (head != nullptr) {
		doPathLayout(GA, head);
	}
	else {
		Array<Array<double> > pivDistMatrix;
		// compute the pivot matrix
		getPivotDistanceMatrix(GA, pivDistMatrix);
		// center the pivot matrix
		centerPivotmatrix(pivDistMatrix);
		// init the coordinate matrix
		Array<Array<double> > coord(DIMENSION_COUNT);
		for (int i = 0; i < coord.size(); i++) {
			coord[i].init(n);
		}
		// init the eigen values array
		Array<double> eVals(DIMENSION_COUNT);
		singularValueDecomposition(pivDistMatrix, coord, eVals);
		// compute the correct aspect ratio
		for (int i = 0; i < coord.size(); i++) {
			eVals[i] = sqrt(eVals[i]);
			for (int j = 0; j < n; j++) {
				coord[i][j] *= eVals[i];
			}
		}
		// set the new positions to the graph
		int i = 0;
		for (node v : G.nodes)
		{
			GA.x(v) = coord[0][i];
			GA.y(v) = coord[1][i];
			if (use3D){
				GA.z(v) = coord[2][i];//cout << coord[2][i] << "\n";
			}
			++i;
		}
	}
}
开发者ID:marvin2k,项目名称:ogdf,代码行数:59,代码来源:PivotMDS.cpp

示例3: computeFirstRadius

//chooses the initial radius of the disk as half the maximum of width and height of
//the initial layout or depending on the value of m_fineTune
void DavidsonHarel::computeFirstRadius(const GraphAttributes &AG)
{
	const Graph &G = AG.constGraph();
	node vFirst = G.firstNode();
	double minX = AG.x(vFirst);
	double minY = AG.y(vFirst);
	double maxX = minX;
	double maxY = minY;
	for(node v : G.nodes) {
		Math::updateMin(minX, AG.x(v));
		Math::updateMax(maxX, AG.x(v));
		Math::updateMin(minY, AG.y(v));
		Math::updateMax(maxY, AG.y(v));
	}
	// compute bounding box of current layout
	// make values nonzero
	double w = maxX-minX+1.0;
	double h = maxY-minY+1.0;

	double ratio = h/w;

	double W = sqrt(G.numberOfNodes() / ratio);

	m_diskRadius = W / 5.0;//allow to move by a significant part of current layout size
	Math::updateMax(m_diskRadius, max(maxX-minX, maxY-minY) / 5.0);

	//TODO: also use node sizes
#if 0
	double lengthSum(0.0);
	for(node v : m_G.nodes) {
		const DRectIntersection &i = shape(v);
		lengthSum += i.width();
		lengthSum += i.width();
		}
		lengthSum /= (2*m_G.numberOfNodes());
		// lengthSum is now the average of all lengths and widths
#endif

	//change the initial radius depending on the settings
	//this is legacy crap
#if 0
	double divo = 2.0;
	if (m_fineTune == tpCoarse) {
		m_diskRadius = 1000.0;
		divo = 0.5;
	}
	if (m_fineTune == tpFine) {
		m_diskRadius = 10.0;
		divo = 15.0;
	}
#if 0
	Math::updateMax(m_diskRadius, max(maxX-minX,maxY-minY));
#endif
	m_diskRadius = max(maxX-minX,maxY-minY);
	m_diskRadius /= divo;
#endif
}
开发者ID:ogdf,项目名称:ogdf,代码行数:59,代码来源:DavidsonHarel.cpp

示例4: 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);
			 }
		 }
开发者ID:15375514460,项目名称:TortoiseGit,代码行数:56,代码来源:ComponentSplitterLayout.cpp

示例5: computeFirstRadius

	//chooses the initial radius of the disk as half the maximum of width and height of
	//the initial layout or depending on the value of m_fineTune
	void DavidsonHarel::computeFirstRadius(const GraphAttributes &AG)
	{
		const Graph &G = AG.constGraph();
		node v = G.firstNode();
		double minX = AG.x(v);
		double minY = AG.y(v);
		double maxX = minX;
		double maxY = minY;
		forall_nodes(v,G) {
			minX = min(minX,AG.x(v));
			maxX = max(maxX,AG.x(v));
			minY = min(minY,AG.y(v));
			maxY = max(maxY,AG.y(v));
		}
开发者ID:mneumann,项目名称:tulip,代码行数:16,代码来源:DavidsonHarel.cpp

示例6: 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;
	}
}
开发者ID:ogdf,项目名称:ogdf,代码行数:50,代码来源:DavidsonHarel.cpp

示例7: 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);
	}
}
开发者ID:ogdf,项目名称:ogdf,代码行数:26,代码来源:MultilevelGraph.cpp

示例8: call

void StressMinimization::call(GraphAttributes& GA)
{
	const Graph& G = GA.constGraph();
	// if the graph has at most one node nothing to do
	if (G.numberOfNodes() <= 1) {
		// make it exception save
		for(node v : G.nodes)
		{
			GA.x(v) = 0;
			GA.y(v) = 0;
		}
		return;
	}
	if (m_componentLayout && !isConnected(G)) {
		OGDF_THROW(PreconditionViolatedException);
		return;
	}
	NodeArray<NodeArray<double> > shortestPathMatrix(G);
	NodeArray<NodeArray<double> > weightMatrix(G);
	initMatrices(G, shortestPathMatrix, weightMatrix);
	// if the edge costs are defined by the attribute copy it to an array and
	// construct the proper shortest path matrix
	if (m_hasEdgeCostsAttribute) {
		if (!GA.has(GraphAttributes::edgeDoubleWeight)) {
			OGDF_THROW(PreconditionViolatedException);
			return;
		}
		m_avgEdgeCosts = dijkstra_SPAP(GA, shortestPathMatrix);
		// compute shortest path all pairs
	} else {
		m_avgEdgeCosts = m_edgeCosts;
		bfs_SPAP(G, shortestPathMatrix, m_edgeCosts);
	}
	call(GA, shortestPathMatrix, weightMatrix);
}
开发者ID:marvin2k,项目名称:ogdf,代码行数:35,代码来源:StressMinimization.cpp

示例9: is

static bool inline readAttribute(
	GraphAttributes &GA, node v,
	const NodeAttribute &attr, const std::string &value)
{
	const long attrs = GA.attributes();
	switch(attr) {
	case na_name:
		// Not really an attribute, handled elsewhere.
		break;
	case na_label:
		if(attrs & GraphAttributes::nodeLabel) {
			GA.label(v) = value;
		}
		break;
	case na_x:
		if(attrs & GraphAttributes::nodeGraphics) {
			std::istringstream is(value);
			is >> GA.x(v);
		}
		break;
	case na_y:
		if(attrs & GraphAttributes::nodeGraphics) {
			std::istringstream is(value);
			is >> GA.y(v);
		}
开发者ID:marvin2k,项目名称:ogdf,代码行数:25,代码来源:GdfParser.cpp

示例10: doPathLayout

void PivotMDS::doPathLayout(GraphAttributes& GA, const node& v)
{
	double xPos = 0;
	node prev = v;
	node cur = v;
	// since the given node is the beginning of the path just
	// use bfs and increment the x coordinate by the average
	// edge costs.
	do {
		GA.x(cur) = xPos;
		GA.y(cur) = 0;
		for(adjEntry adj : cur->adjEntries) {
			node w = adj->twinNode();
			if (!(w == prev) || w == cur) {
				prev = cur;
				cur = w;
				if(m_hasEdgeCostsAttribute) {
					xPos+=GA.doubleWeight(adj->theEdge());
				} else {
					xPos += m_edgeCosts;
				}
				break;
			}
			prev = cur;
		}
	} while (prev != cur);
}
开发者ID:marvin2k,项目名称:ogdf,代码行数:27,代码来源:PivotMDS.cpp

示例11: BendPromotion

void BendPromotion(Graph& G, GraphAttributes& GA) {
	List<edge> edges;
	G.allEdges(edges);

	while (!edges.empty()) {
		edge e = edges.popFrontRet();
		DPolyline bends_e = GA.bends(e);
		node s = e->source();
		node t = e->target();

		//check if an edge has bendpoints
		if (!bends_e.empty()) {
			while (!bends_e.empty()) {
				DPoint p = bends_e.front();

				//insert new node
				node n = G.newNode();
				GA.x(n) = p.m_x;
				GA.y(n) = p.m_y;

				edge e_ = G.newEdge(s, n);
				GA.arrowType(e_) = ogdf::EdgeArrow::None;
				GA.strokeColor(e_) = Color("#bababa");
				s = n;

				bends_e.popFront();
			}
			edge e_ = G.newEdge(s, t);
			GA.arrowType(e_) = ogdf::EdgeArrow::None;
			GA.strokeColor(e_) = Color("#bababa");

			G.delEdge(e);
		}
	}
}
开发者ID:bartvdput,项目名称:scriptie,代码行数:35,代码来源:scriptie.cpp

示例12: 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];
	}
}
开发者ID:ogdf,项目名称:ogdf,代码行数:29,代码来源:MultilevelGraph.cpp

示例13: 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;
}
开发者ID:ogdf,项目名称:ogdf,代码行数:60,代码来源:GexfParser.cpp

示例14: readData

bool GraphMLParser::readData(
	GraphAttributes &GA,
	const node &v, const XmlTagObject &nodeData)
{
	XmlAttributeObject *keyId;
	nodeData.findXmlAttributeObjectByName("key", keyId);

	if(keyId == NULL) {
		cerr << "ERROR: Node data does not have a key.\n";
		return false;
	}

	const long attrs = GA.attributes();
	std::stringstream value(nodeData.getValue());

	switch (graphml::toAttribute(m_attrName[keyId->getValue()])) {
	case graphml::a_nodeLabel:
		if(attrs & GraphAttributes::nodeLabel) {
			value >> GA.label(v);
		}
		break;
	case graphml::a_x:
		if(attrs & GraphAttributes::nodeGraphics) {
			value >> GA.x(v);
		}
开发者ID:mneumann,项目名称:tulip,代码行数:25,代码来源:GraphMLParser.cpp

示例15: edgeLengths

	double LayoutStatistics::edgeLengths(
		const GraphAttributes &ga,
		double *pMinLength,
		double *pMaxLength,
		double *pAvgLength,
		double *pStdDeviation,
		bool    considerSelfLoops)
	{
		const Graph &G = ga.constGraph();
		int m = G.numberOfEdges();

		double totalLength = 0, minLength = numeric_limits<double>::max(), maxLength = -numeric_limits<double>::max();

		EdgeArray<double> len(G);
		int nSelfLoops = 0;

		for(edge e : G.edges) {
			if(!considerSelfLoops && e->isSelfLoop()) {
				nSelfLoops++;
				continue;
			}

			const DPolyline &dpl = ga.bends(e);

			if(!dpl.empty()) {
				len[e] = dpl.length();

			} else {
				DPoint pv = DPoint(ga.x(e->source()),ga.y(e->source()));
				DPoint pw = DPoint(ga.x(e->target()),ga.y(e->target()));
				len[e] = pv.distance(pw);
			}

			totalLength += len[e];
			minLength = min(minLength, len[e]);
			maxLength = max(maxLength, len[e]);
		}

		m -= nSelfLoops;

		double avgEdgeLength = totalLength / m;
		if(pAvgLength) *pAvgLength = avgEdgeLength;
		if(pMinLength) *pMinLength = minLength;
		if(pMaxLength) *pMaxLength = maxLength;

		if(pStdDeviation) {
			double sum = 0;
			for(edge e : G.edges) {
				if(!considerSelfLoops && e->isSelfLoop())
					continue;
				double d = len[e] - avgEdgeLength;
				sum += d*d;
			}

			*pStdDeviation = sqrt(sum / m);
		}

		return totalLength;
	}
开发者ID:marvin2k,项目名称:ogdf,代码行数:59,代码来源:LayoutStatistics.cpp


注:本文中的GraphAttributes::x方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。