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


C++ VertexList::find方法代码示例

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


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

示例1: dump_graph_to_png_file

void dump_graph_to_png_file(const AdjacencyList &adjacency_list,
                            const VertexList &vertex_list,
                            const char *png_filename)
{
    auto bbox = get_aabb(vertex_list);

    double width = bbox.maxx - bbox.minx;
    double height = bbox.maxy - bbox.miny;

    auto surface = std::shared_ptr<cairo_surface_t>(
        cairo_image_surface_create(CAIRO_FORMAT_RGB24, width, height),
        cairo_surface_destroy);
    check_cairo_surface_status(surface.get());

    auto cr = std::shared_ptr<cairo_t>(
        cairo_create(surface.get()),
        cairo_destroy);
    check_cairo_status(cr.get());

    cairo_set_line_width(cr.get(), 1.0);

    for (const auto &edge: adjacency_list) {
        auto u = vertex_list.find(std::get<0>(edge));

        if (u == vertex_list.end()) {
            std::cout << "[WARNING] reference to non-existing vertex "
                      << std::get<0>(edge) << std::endl;
            continue;
        }

        for (const auto &way: std::get<1>(edge)) {
            auto v = vertex_list.find(way.destination);

            if (v == vertex_list.end()) {
                std::cout << "[WARNING] reference to non-existing vertex "
                          << way.destination << std::endl;
                continue;
            }

            switch (way.type) {
            case 0:
                cairo_set_source_rgb(cr.get(), 1.0, 0.0, 0.0);
                break;

            case 1:
                cairo_set_source_rgb(cr.get(), 0.0, 1.0, 0.0);
                break;

            case 2:
                cairo_set_source_rgb(cr.get(), 0.0, 0.0, 1.0);
                break;

            default:
                std::cout << "[WARNING] Wrong type of arc" << std::endl;
            }

            cairo_move_to(cr.get(),
                          u->second.x - bbox.minx,
                          height - (u->second.y - bbox.miny));
            cairo_line_to(cr.get(),
                          v->second.x - bbox.minx,
                          height - (v->second.y - bbox.miny));
            cairo_stroke(cr.get());
        }
    }

    {
        auto status = cairo_surface_write_to_png(surface.get(), png_filename);
        cairo_status_to_exception(status);
    }
}
开发者ID:rexim,项目名称:routes-drawer,代码行数:71,代码来源:graph_dumper.cpp


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