Ejemplo n.º 1
0
void ControlWidget::trimRoads() {
	BBox bbox;
	bbox.addPoint(QVector2D(mainWin->glWidget->vboRenderManager.minPos.x() + 20, mainWin->glWidget->vboRenderManager.minPos.y() + 20));
	bbox.addPoint(QVector2D(mainWin->glWidget->vboRenderManager.maxPos.x() - 20, mainWin->glWidget->vboRenderManager.maxPos.y() - 20));
	Polygon2D polygon;
	boost::geometry::convert(bbox, polygon);
	GraphUtil::trim(mainWin->urbanGeometry->roads, polygon);

	mainWin->urbanGeometry->update(mainWin->glWidget->vboRenderManager);
	mainWin->glWidget->updateGL();
}
Ejemplo n.º 2
0
void PMRoadGenerator::saveRoadImage(RoadGraph& roads, const std::string& filename) {
	BBox bbox;
	RoadVertexIter vi, vend;
	for (boost::tie(vi, vend) = boost::vertices(roads.graph); vi != vend; ++vi) {
		if (!roads.graph[*vi]->valid) continue;

		bbox.addPoint(roads.graph[*vi]->pt);
	}

	cv::Mat result((int)(bbox.dy() + 1), (int)(bbox.dx() + 1), CV_8UC3, cv::Scalar(255, 255, 255));

	RoadEdgeIter ei, eend;
	for (boost::tie(ei, eend) = boost::edges(roads.graph); ei != eend; ++ei) {
		if (!roads.graph[*ei]->valid) continue;

		for (int k = 0; k < roads.graph[*ei]->polyline.size() - 1; ++k) {
			int x1 = roads.graph[*ei]->polyline[k].x() - bbox.minPt.x();
			int y1 = roads.graph[*ei]->polyline[k].y() - bbox.minPt.y();
			int x2 = roads.graph[*ei]->polyline[k + 1].x() - bbox.minPt.x();
			int y2 = roads.graph[*ei]->polyline[k + 1].y() - bbox.minPt.y();

			cv::line(result, cv::Point(x1, y1), cv::Point(x2, y2), cv::Scalar(0, 0, 0), 1, cv::LINE_AA);
		}
	}

	for (boost::tie(vi, vend) = boost::vertices(roads.graph); vi != vend; ++vi) {
		if (!roads.graph[*vi]->valid) continue;

		int count = 0;
		RoadOutEdgeIter oi, oend;
		for (boost::tie(oi, oend) = boost::out_edges(*vi, roads.graph); oi != oend; ++oi) {
			if (roads.graph[*oi]->valid) count++;
		}

		if (count == 2) continue;

		int x = roads.graph[*vi]->pt.x() - bbox.minPt.x();
		int y = roads.graph[*vi]->pt.y() - bbox.minPt.x();
		cv::circle(result, cv::Point(x, y), 5, cv::Scalar(255, 0, 0), 1, cv::LINE_AA);

		QString text = QString::number(count);
		cv::putText(result, text.toUtf8().constData(), cv::Point(x, y), cv::FONT_HERSHEY_PLAIN, 2, cv::Scalar(0, 0, 0), 1, cv::LINE_AA);
	}

	cv::imwrite(filename.c_str(), result);
}