File: test_buffer_csv.hpp

package info (click to toggle)
boost1.90 1.90.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 593,120 kB
  • sloc: cpp: 4,190,908; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,774; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (129 lines) | stat: -rw-r--r-- 3,887 bytes parent folder | download | duplicates (3)
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
// Boost.Geometry
// Unit Test Helper

// Copyright (c) 2022 Barend Gehrels, Amsterdam, the Netherlands.

// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#ifndef BOOST_GEOMETRY_TEST_BUFFER_CSV_HPP
#define BOOST_GEOMETRY_TEST_BUFFER_CSV_HPP

#include <fstream>
#include <iomanip>

#include "debug_buffer_info.hpp"
#include <boost/geometry/algorithms/detail/overlay/debug_turn_info.hpp>
#include <boost/geometry/io/wkt/wkt.hpp>


namespace detail
{

class buffer_visitor_csv
{
public:
    buffer_visitor_csv(const std::string &path)
        : m_path(path)
    {
    }

    template <typename PieceCollection>
    inline void apply(PieceCollection const& collection, int phase)
    {
        if (phase == 0)
        {
            write_pieces(collection.m_pieces, collection.offsetted_rings);
        }
        if (phase == 1)
        {
            write_turns(collection.m_turns);
        }
    }

    template <typename Geometry, typename GeometryBuffer>
    inline void write_input_output(Geometry const& input, GeometryBuffer const& buffer)
    {
        std::ofstream stream(m_path + "_geometries.csv");
        if (! stream.good())
        {
            return;
        }

        stream << std::setprecision(16)
            << "id;role;wkt" << std::endl
            << "1;input;" << bg::wkt(input) << std::endl
            << "2;output;" << bg::wkt(buffer) << std::endl;
    }

private:

    template <typename Turns>
    inline void write_turns(Turns const& turns)
    {
        std::ofstream stream(m_path + "_turns.csv");
        if (! stream.good())
        {
            return;
        }
        std::size_t id = 1;
        stream << std::setprecision(16) << "id;wkt;piece_indices;method;operations;cluster_id;traversable;blocked" << std::endl;
        for (const auto &turn : turns)
        {
            stream << id++ << ";"
                   << bg::wkt(turn.point) << ";"
                   << turn.operations[0].piece_index << "/" << turn.operations[1].piece_index << ";"
                   << bg::method_char(turn.method) << ";"
                   << bg::operation_char(turn.operations[0].operation) << "/" << bg::operation_char(turn.operations[1].operation) << ";"
                   << turn.cluster_id << ";"
                   << turn.is_traversable << ";"
                   << turn.blocked() << ";"
                   << std::endl;
        }
    }

    template <typename Pieces, typename OffsettedRings>
    inline void write_pieces(Pieces const& pieces, OffsettedRings const& offsetted_rings)
    {
        std::ofstream stream(m_path + "_pieces.csv");
        if (! stream.good())
        {
            return;
        }

        std::size_t id = 1;
        stream << std::setprecision(16) << "id;wkt;index;start;end;type;segment_indices" << std::endl;
        for (auto const& piece : pieces)
        {
            bg::segment_identifier const& seg_id = piece.first_seg_id;
            if (seg_id.segment_index < 0)
            {
                continue;
            }
            // NOTE: ring is returned by copy here
            auto const corner = piece.m_piece_border.get_full_ring();
            if (corner.empty())
            {
                continue;
            }

            auto const& ring = offsetted_rings[seg_id.multi_index];

            stream << id++ << ";"
                   << bg::wkt(corner) << ";"
                   << piece.index << ";"
                   << piece.is_flat_start << ";"
                   << piece.is_flat_end << ";"
                   << bg::debug::piece_type_char(piece.type) << ";"
                   << piece.first_seg_id.segment_index << ".." << piece.beyond_last_segment_index - 1
                   << std::endl;
        }
    }

    std::string m_path;
};

}

#endif