[test] add optional csv output to view buffer test cases in qgis

This commit is contained in:
Barend Gehrels 2022-08-10 14:24:05 +02:00
parent d1abd75a8a
commit b18db001b8
4 changed files with 179 additions and 18 deletions

View File

@ -0,0 +1,35 @@
// 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_ALGORITHMS_BUFFER_DEBUG_BUFFER_INFO_HPP
#define BOOST_GEOMETRY_TEST_ALGORITHMS_BUFFER_DEBUG_BUFFER_INFO_HPP
namespace boost { namespace geometry { namespace debug
{
// Helper method to translate enumeration to character
inline char piece_type_char(strategy::buffer::piece_type const& type)
{
using namespace strategy::buffer;
switch(type)
{
case buffered_segment : return 's';
case buffered_join : return 'j';
case buffered_round_end : return 'r';
case buffered_flat_end : return 'f';
case buffered_point : return 'p';
case buffered_concave : return 'c';
default : return '?';
}
}
}}}
#endif

View File

@ -58,6 +58,10 @@ const double same_distance = -999;
# include "test_buffer_svg_per_turn.hpp" # include "test_buffer_svg_per_turn.hpp"
#endif #endif
#if defined(TEST_WITH_CSV)
# include "test_buffer_csv.hpp"
#endif
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <typename JoinStrategy> template <typename JoinStrategy>
struct JoinTestProperties struct JoinTestProperties
@ -213,7 +217,10 @@ void test_buffer(std::string const& caseid,
//std::cout << complete.str() << std::endl; //std::cout << complete.str() << std::endl;
#if defined(TEST_WITH_SVG_PER_TURN) #if defined(TEST_WITH_CSV)
detail::buffer_visitor_csv visitor("/tmp/csv/" + caseid + "_");
#elif defined(TEST_WITH_SVG_PER_TURN)
save_turns_visitor<point_type> visitor; save_turns_visitor<point_type> visitor;
#elif defined(TEST_WITH_SVG) #elif defined(TEST_WITH_SVG)
@ -268,7 +275,8 @@ void test_buffer(std::string const& caseid,
rescale_policy, rescale_policy,
visitor); visitor);
#if defined(TEST_WITH_SVG) #if defined(TEST_WITH_CSV)
#elif defined(TEST_WITH_SVG)
buffer_mapper.map_input_output(mapper, geometry, buffered, distance_strategy.negative()); buffer_mapper.map_input_output(mapper, geometry, buffered, distance_strategy.negative());
#endif #endif
@ -340,7 +348,9 @@ void test_buffer(std::string const& caseid,
BOOST_CHECK_MESSAGE(bg::is_valid(buffered), complete.str() << " is not valid"); BOOST_CHECK_MESSAGE(bg::is_valid(buffered), complete.str() << " is not valid");
} }
#if defined(TEST_WITH_SVG_PER_TURN) #if defined(TEST_WITH_CSV)
visitor.write_input_output(geometry, buffered);
#elif defined(TEST_WITH_SVG_PER_TURN)
{ {
// Create a per turn visitor to map per turn, and buffer again with it // Create a per turn visitor to map per turn, and buffer again with it
per_turn_visitor<point_type> ptv(complete.str(), visitor.get_points()); per_turn_visitor<point_type> ptv(complete.str(), visitor.get_points());

View File

@ -0,0 +1,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_turn_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

View File

@ -28,6 +28,7 @@
# endif # endif
#endif #endif
#include "debug_buffer_info.hpp"
#include <boost/geometry/io/svg/svg_mapper.hpp> #include <boost/geometry/io/svg/svg_mapper.hpp>
#include <boost/geometry/algorithms/buffer.hpp> #include <boost/geometry/algorithms/buffer.hpp>
#include <boost/geometry/algorithms/intersection.hpp> #include <boost/geometry/algorithms/intersection.hpp>
@ -85,20 +86,6 @@ get_labelpoint(Ring const& ring, Piece const& piece)
} }
} }
inline char piece_type_char(bg::strategy::buffer::piece_type const& type)
{
using namespace bg::strategy::buffer;
switch(type)
{
case buffered_segment : return 's';
case buffered_join : return 'j';
case buffered_round_end : return 'r';
case buffered_flat_end : return 'f';
case buffered_point : return 'p';
case buffered_concave : return 'c';
default : return '?';
}
}
template <typename SvgMapper, typename Box> template <typename SvgMapper, typename Box>
class svg_visitor class svg_visitor
@ -297,7 +284,7 @@ private :
out << piece.index out << piece.index
<< (piece.is_flat_start ? " FS" : "") << (piece.is_flat_start ? " FS" : "")
<< (piece.is_flat_end ? " FE" : "") << (piece.is_flat_end ? " FE" : "")
<< " (" << piece_type_char(piece.type) << ") " << " (" << bg::debug::piece_type_char(piece.type) << ") "
<< piece.first_seg_id.segment_index << piece.first_seg_id.segment_index
<< ".." << piece.beyond_last_segment_index - 1 << ".." << piece.beyond_last_segment_index - 1
; ;