Merge pull request #4282 from mathisloge/feature/clang-format
Feature clang format
This commit is contained in:
commit
d7b83c0f7d
811 changed files with 37143 additions and 37859 deletions
94
.clang-format
Normal file
94
.clang-format
Normal file
|
@ -0,0 +1,94 @@
|
|||
Language: Cpp
|
||||
AccessModifierOffset: -2
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignArrayOfStructures: None
|
||||
AlignConsecutiveAssignments: None
|
||||
AlignConsecutiveDeclarations: None
|
||||
AlignConsecutiveMacros: Consecutive
|
||||
AlignEscapedNewlines: Right
|
||||
AlignOperands: Align
|
||||
AlignTrailingComments: true
|
||||
AllowAllArgumentsOnNextLine: false
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AllowShortBlocksOnASingleLine: Empty
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortEnumsOnASingleLine: true
|
||||
AllowShortFunctionsOnASingleLine: Inline
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortLambdasOnASingleLine: Inline
|
||||
# AlwaysBreakAfterReturnType:
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
BinPackArguments: false
|
||||
BitFieldColonSpacing: After
|
||||
BreakBeforeBraces: Custom
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: true
|
||||
AfterControlStatement: Always
|
||||
AfterEnum: false # see AllowShortEnumsOnASingleLine
|
||||
AfterFunction: true # see AllowShortFunctionsOnASingleLine
|
||||
AfterNamespace: false
|
||||
AfterStruct: true
|
||||
AfterExternBlock: true
|
||||
BeforeCatch: false
|
||||
BeforeElse: true
|
||||
BeforeLambdaBody: false
|
||||
BeforeWhile: false
|
||||
SplitEmptyFunction: false
|
||||
SplitEmptyRecord: false
|
||||
SplitEmptyNamespace: false
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeConceptDeclarations: false
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
BreakInheritanceList: AfterComma
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 120
|
||||
CompactNamespaces: false
|
||||
ContinuationIndentWidth: 2
|
||||
Cpp11BracedListStyle: true
|
||||
DeriveLineEnding: true
|
||||
EmptyLineAfterAccessModifier: Leave
|
||||
EmptyLineBeforeAccessModifier: LogicalBlock
|
||||
FixNamespaceComments: true
|
||||
IncludeBlocks: Preserve
|
||||
IndentCaseBlocks: false
|
||||
IndentCaseLabels: true
|
||||
IndentExternBlock: NoIndent
|
||||
IndentPPDirectives: None
|
||||
IndentRequires: true
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
LambdaBodyIndentation: Signature
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
# PackConstructorInitializers: CurrentLine # only clang-format > 14
|
||||
PointerAlignment: Left
|
||||
#QualifierAlignment: Left # only clang-format > 14
|
||||
ReferenceAlignment: Left
|
||||
ReflowComments: true
|
||||
SortIncludes: Never
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: false
|
||||
SpaceBeforeInheritanceColon: true
|
||||
Standard: c++14
|
||||
BinPackParameters: false
|
||||
BreakBeforeInheritanceComma: false
|
||||
IncludeCategories:
|
||||
# Headers in <> without extension.
|
||||
- Regex: '<([A-Za-z0-9\Q/-_\E])+>'
|
||||
Priority: 1
|
||||
# Headers in <> from specific external libraries.
|
||||
- Regex: '<(boost)\/'
|
||||
Priority: 2
|
||||
# Headers in <> from specific external libraries.
|
||||
- Regex: '<(mapnik)\/'
|
||||
Priority: 3
|
||||
# Headers in <> with extension.
|
||||
- Regex: '<([A-Za-z0-9.\Q/-_\E])+>'
|
||||
Priority: 4
|
||||
# Headers in "" with extension.
|
||||
- Regex: '"([A-Za-z0-9.\Q/-_\E])+"'
|
||||
Priority: 5
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
// stl
|
||||
#include <chrono>
|
||||
#include <cmath> // log10, round
|
||||
#include <cmath> // log10, round
|
||||
#include <cstdio> // snprintf
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
|
@ -22,36 +22,28 @@
|
|||
|
||||
namespace benchmark {
|
||||
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
using milliseconds = std::chrono::duration<T, std::milli>;
|
||||
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
using seconds = std::chrono::duration<T>;
|
||||
|
||||
class test_case
|
||||
{
|
||||
protected:
|
||||
protected:
|
||||
mapnik::parameters params_;
|
||||
std::size_t threads_;
|
||||
std::size_t iterations_;
|
||||
public:
|
||||
|
||||
public:
|
||||
test_case(mapnik::parameters const& params)
|
||||
: params_(params),
|
||||
threads_(mapnik::safe_cast<std::size_t>(*params.get<mapnik::value_integer>("threads", 0))),
|
||||
iterations_(mapnik::safe_cast<std::size_t>(*params.get<mapnik::value_integer>("iterations", 0)))
|
||||
{}
|
||||
std::size_t threads() const
|
||||
{
|
||||
return threads_;
|
||||
}
|
||||
std::size_t iterations() const
|
||||
{
|
||||
return iterations_;
|
||||
}
|
||||
mapnik::parameters const& params() const
|
||||
{
|
||||
return params_;
|
||||
}
|
||||
: params_(params)
|
||||
, threads_(mapnik::safe_cast<std::size_t>(*params.get<mapnik::value_integer>("threads", 0)))
|
||||
, iterations_(mapnik::safe_cast<std::size_t>(*params.get<mapnik::value_integer>("iterations", 0)))
|
||||
{}
|
||||
std::size_t threads() const { return threads_; }
|
||||
std::size_t iterations() const { return iterations_; }
|
||||
mapnik::parameters const& params() const { return params_; }
|
||||
virtual bool validate() const = 0;
|
||||
virtual bool operator()() const = 0;
|
||||
};
|
||||
|
@ -59,21 +51,25 @@ public:
|
|||
// gathers --long-option values in 'params';
|
||||
// returns the index of the first non-option argument,
|
||||
// or negated index of an ill-formed option argument
|
||||
inline int parse_args(int argc, char** argv, mapnik::parameters & params)
|
||||
inline int parse_args(int argc, char** argv, mapnik::parameters& params)
|
||||
{
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
for (int i = 1; i < argc; ++i)
|
||||
{
|
||||
const char* opt = argv[i];
|
||||
if (opt[0] != '-') {
|
||||
if (opt[0] != '-')
|
||||
{
|
||||
// non-option argument, return its index
|
||||
return i;
|
||||
}
|
||||
if (opt[1] != '-') {
|
||||
if (opt[1] != '-')
|
||||
{
|
||||
// we only accept --long-options, but instead of throwing,
|
||||
// just issue a warning and let the caller decide what to do
|
||||
std::clog << argv[0] << ": invalid option '" << opt << "'\n";
|
||||
return -i; // negative means ill-formed option #i
|
||||
}
|
||||
if (opt[2] == '\0') {
|
||||
if (opt[2] == '\0')
|
||||
{
|
||||
// option-list terminator '--'
|
||||
return i + 1;
|
||||
}
|
||||
|
@ -81,15 +77,18 @@ inline int parse_args(int argc, char** argv, mapnik::parameters & params)
|
|||
// take option name without the leading '--'
|
||||
std::string key(opt + 2);
|
||||
size_t eq = key.find('=');
|
||||
if (eq != std::string::npos) {
|
||||
if (eq != std::string::npos)
|
||||
{
|
||||
// one-argument form '--foo=bar'
|
||||
params[key.substr(0, eq)] = key.substr(eq + 1);
|
||||
}
|
||||
else if (i + 1 < argc) {
|
||||
else if (i + 1 < argc)
|
||||
{
|
||||
// two-argument form '--foo' 'bar'
|
||||
params[key] = std::string(argv[++i]);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
// missing second argument
|
||||
std::clog << argv[0] << ": missing option '" << opt << "' value\n";
|
||||
return -i; // negative means ill-formed option #i
|
||||
|
@ -100,7 +99,8 @@ inline int parse_args(int argc, char** argv, mapnik::parameters & params)
|
|||
|
||||
inline void handle_common_args(mapnik::parameters const& params)
|
||||
{
|
||||
if (auto severity = params.get<std::string>("log")) {
|
||||
if (auto severity = params.get<std::string>("log"))
|
||||
{
|
||||
if (*severity == "debug")
|
||||
mapnik::logger::set_severity(mapnik::logger::debug);
|
||||
else if (*severity == "warn")
|
||||
|
@ -110,37 +110,35 @@ inline void handle_common_args(mapnik::parameters const& params)
|
|||
else if (*severity == "none")
|
||||
mapnik::logger::set_severity(mapnik::logger::none);
|
||||
else
|
||||
std::clog << "ignoring option --log='" << *severity
|
||||
<< "' (allowed values are: debug, warn, error, none)\n";
|
||||
std::clog << "ignoring option --log='" << *severity << "' (allowed values are: debug, warn, error, none)\n";
|
||||
}
|
||||
}
|
||||
|
||||
inline int handle_args(int argc, char** argv, mapnik::parameters & params)
|
||||
inline int handle_args(int argc, char** argv, mapnik::parameters& params)
|
||||
{
|
||||
int res = parse_args(argc, argv, params);
|
||||
handle_common_args(params);
|
||||
return res;
|
||||
}
|
||||
|
||||
#define BENCHMARK(test_class,name) \
|
||||
int main(int argc, char** argv) \
|
||||
{ \
|
||||
try \
|
||||
{ \
|
||||
mapnik::parameters params; \
|
||||
benchmark::handle_args(argc,argv,params); \
|
||||
test_class test_runner(params); \
|
||||
auto result = run(test_runner,name); \
|
||||
testing::run_cleanup(); \
|
||||
return result; \
|
||||
} \
|
||||
catch (std::exception const& ex) \
|
||||
{ \
|
||||
std::clog << ex.what() << "\n"; \
|
||||
testing::run_cleanup(); \
|
||||
return -1; \
|
||||
} \
|
||||
} \
|
||||
#define BENCHMARK(test_class, name) \
|
||||
int main(int argc, char** argv) \
|
||||
{ \
|
||||
try \
|
||||
{ \
|
||||
mapnik::parameters params; \
|
||||
benchmark::handle_args(argc, argv, params); \
|
||||
test_class test_runner(params); \
|
||||
auto result = run(test_runner, name); \
|
||||
testing::run_cleanup(); \
|
||||
return result; \
|
||||
} catch (std::exception const& ex) \
|
||||
{ \
|
||||
std::clog << ex.what() << "\n"; \
|
||||
testing::run_cleanup(); \
|
||||
return -1; \
|
||||
} \
|
||||
}
|
||||
|
||||
struct big_number_fmt
|
||||
{
|
||||
|
@ -149,7 +147,9 @@ struct big_number_fmt
|
|||
const char* u;
|
||||
|
||||
big_number_fmt(int width, double value, int base = 1000)
|
||||
: w(width), v(value), u("")
|
||||
: w(width)
|
||||
, v(value)
|
||||
, u("")
|
||||
{
|
||||
static const char* suffixes = "\0\0k\0M\0G\0T\0P\0E\0Z\0Y\0\0";
|
||||
u = suffixes;
|
||||
|
@ -165,7 +165,7 @@ struct big_number_fmt
|
|||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
int run(T const& test_runner, std::string const& name)
|
||||
{
|
||||
try
|
||||
|
@ -196,8 +196,7 @@ int run(T const& test_runner, std::string const& name)
|
|||
std::mutex mtx_ready;
|
||||
std::unique_lock<std::mutex> lock_ready(mtx_ready);
|
||||
|
||||
auto stub = [&](T const& test_copy)
|
||||
{
|
||||
auto stub = [&](T const& test_copy) {
|
||||
// workers will wait on this mutex until the main thread
|
||||
// constructs all of them and starts measuring time
|
||||
std::unique_lock<std::mutex> my_lock(mtx_ready);
|
||||
|
@ -207,14 +206,14 @@ int run(T const& test_runner, std::string const& name)
|
|||
|
||||
std::vector<std::thread> tg;
|
||||
tg.reserve(num_threads);
|
||||
for (auto i = num_threads; i-- > 0; )
|
||||
for (auto i = num_threads; i-- > 0;)
|
||||
{
|
||||
tg.emplace_back(stub, test_runner);
|
||||
}
|
||||
start = std::chrono::high_resolution_clock::now();
|
||||
lock_ready.unlock();
|
||||
// wait for all workers to finish
|
||||
for (auto & t : tg)
|
||||
for (auto& t : tg)
|
||||
{
|
||||
if (t.joinable())
|
||||
t.join();
|
||||
|
@ -228,7 +227,8 @@ int run(T const& test_runner, std::string const& name)
|
|||
else
|
||||
{
|
||||
start = std::chrono::high_resolution_clock::now();
|
||||
do {
|
||||
do
|
||||
{
|
||||
test_runner();
|
||||
elapsed = std::chrono::high_resolution_clock::now() - start;
|
||||
total_iters += num_iters;
|
||||
|
@ -243,21 +243,27 @@ int run(T const& test_runner, std::string const& name)
|
|||
|
||||
std::clog << std::left << std::setw(43) << name;
|
||||
std::clog << std::resetiosflags(std::ios::adjustfield);
|
||||
if (num_threads > 0) {
|
||||
std::clog << ' ' << std::setw(3) << num_threads
|
||||
<< " worker" << (num_threads > 1 ? "s" : " ");
|
||||
if (num_threads > 0)
|
||||
{
|
||||
std::clog << ' ' << std::setw(3) << num_threads << " worker" << (num_threads > 1 ? "s" : " ");
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
std::clog << " main thread";
|
||||
}
|
||||
std::snprintf(msg, sizeof(msg),
|
||||
" %*.0f%s iters %6.0f milliseconds %*.0f%s i/t/s\n",
|
||||
itersf.w, itersf.v, itersf.u, dur_total,
|
||||
ips.w, ips.v, ips.u);
|
||||
std::snprintf(msg,
|
||||
sizeof(msg),
|
||||
" %*.0f%s iters %6.0f milliseconds %*.0f%s i/t/s\n",
|
||||
itersf.w,
|
||||
itersf.v,
|
||||
itersf.u,
|
||||
dur_total,
|
||||
ips.w,
|
||||
ips.v,
|
||||
ips.u);
|
||||
std::clog << msg;
|
||||
return 0;
|
||||
}
|
||||
catch (std::exception const& ex)
|
||||
} catch (std::exception const& ex)
|
||||
{
|
||||
std::clog << "test runner did not complete: " << ex.what() << "\n";
|
||||
return 4;
|
||||
|
@ -267,18 +273,15 @@ int run(T const& test_runner, std::string const& name)
|
|||
struct sequencer
|
||||
{
|
||||
sequencer(int argc, char** argv)
|
||||
: exit_code_(0)
|
||||
: exit_code_(0)
|
||||
{
|
||||
benchmark::handle_args(argc, argv, params_);
|
||||
}
|
||||
|
||||
int done() const
|
||||
{
|
||||
return exit_code_;
|
||||
}
|
||||
int done() const { return exit_code_; }
|
||||
|
||||
template <typename Test, typename... Args>
|
||||
sequencer & run(std::string const& name, Args && ...args)
|
||||
template<typename Test, typename... Args>
|
||||
sequencer& run(std::string const& name, Args&&... args)
|
||||
{
|
||||
// Test instance lifetime is confined to this function
|
||||
Test test_runner(params_, std::forward<Args>(args)...);
|
||||
|
@ -287,11 +290,11 @@ struct sequencer
|
|||
return *this; // allow chaining calls
|
||||
}
|
||||
|
||||
protected:
|
||||
protected:
|
||||
mapnik::parameters params_;
|
||||
int exit_code_;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace benchmark
|
||||
|
||||
#endif // MAPNIK_BENCH_FRAMEWORK_HPP
|
||||
|
|
|
@ -5,32 +5,31 @@
|
|||
#include <mapnik/image_util.hpp>
|
||||
#include <mapnik/image_reader.hpp>
|
||||
|
||||
|
||||
namespace benchmark {
|
||||
|
||||
bool compare_images(std::string const& src_fn,std::string const& dest_fn)
|
||||
bool compare_images(std::string const& src_fn, std::string const& dest_fn)
|
||||
{
|
||||
std::unique_ptr<mapnik::image_reader> reader1(mapnik::get_image_reader(dest_fn, "png"));
|
||||
if (!reader1.get())
|
||||
{
|
||||
std::unique_ptr<mapnik::image_reader> reader1(mapnik::get_image_reader(dest_fn,"png"));
|
||||
if (!reader1.get())
|
||||
{
|
||||
throw mapnik::image_reader_exception("Failed to load: " + dest_fn);
|
||||
}
|
||||
|
||||
std::unique_ptr<mapnik::image_reader> reader2(mapnik::get_image_reader(src_fn,"png"));
|
||||
if (!reader2.get())
|
||||
{
|
||||
throw mapnik::image_reader_exception("Failed to load: " + src_fn);
|
||||
}
|
||||
|
||||
const mapnik::image_any desc_any = reader1->read(0,0,reader1->width(), reader1->height());
|
||||
const mapnik::image_any src_any = reader2->read(0,0,reader2->width(), reader2->height());
|
||||
|
||||
mapnik::image_rgba8 const& dest = mapnik::util::get<mapnik::image_rgba8>(desc_any);
|
||||
mapnik::image_rgba8 const& src = mapnik::util::get<mapnik::image_rgba8>(src_any);
|
||||
|
||||
return compare(dest, src, 0, true) == 0;
|
||||
throw mapnik::image_reader_exception("Failed to load: " + dest_fn);
|
||||
}
|
||||
|
||||
std::unique_ptr<mapnik::image_reader> reader2(mapnik::get_image_reader(src_fn, "png"));
|
||||
if (!reader2.get())
|
||||
{
|
||||
throw mapnik::image_reader_exception("Failed to load: " + src_fn);
|
||||
}
|
||||
|
||||
const mapnik::image_any desc_any = reader1->read(0, 0, reader1->width(), reader1->height());
|
||||
const mapnik::image_any src_any = reader2->read(0, 0, reader2->width(), reader2->height());
|
||||
|
||||
mapnik::image_rgba8 const& dest = mapnik::util::get<mapnik::image_rgba8>(desc_any);
|
||||
mapnik::image_rgba8 const& src = mapnik::util::get<mapnik::image_rgba8>(src_any);
|
||||
|
||||
return compare(dest, src, 0, true) == 0;
|
||||
}
|
||||
|
||||
} // namespace benchmark
|
||||
|
||||
#endif // MAPNIK_COMPARE_IMAGES_HPP
|
||||
|
|
|
@ -2,20 +2,23 @@
|
|||
|
||||
#include <mapnik/util/math.hpp>
|
||||
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
struct bench_func : benchmark::test_case
|
||||
{
|
||||
T (* const func_)(T);
|
||||
T (*const func_)(T);
|
||||
T const value_;
|
||||
|
||||
bench_func(mapnik::parameters const& params, T (*func)(T), T value)
|
||||
: test_case(params), func_(func), value_(value) {}
|
||||
: test_case(params)
|
||||
, func_(func)
|
||||
, value_(value)
|
||||
{}
|
||||
|
||||
bool validate() const { return true; }
|
||||
|
||||
bool operator() () const
|
||||
bool operator()() const
|
||||
{
|
||||
for (auto i = this->iterations_; i-- > 0; )
|
||||
for (auto i = this->iterations_; i-- > 0;)
|
||||
{
|
||||
func_(value_);
|
||||
}
|
||||
|
@ -23,47 +26,46 @@ struct bench_func : benchmark::test_case
|
|||
}
|
||||
};
|
||||
|
||||
#define BENCH_FUNC1(func, value) \
|
||||
run<bench_func<double>>(#func "(" #value ")", func, value)
|
||||
#define BENCH_FUNC1(func, value) run<bench_func<double>>(#func "(" #value ")", func, value)
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
return benchmark::sequencer(argc, argv)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +3)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +6)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +9)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +12)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +15)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +20)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +30)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +40)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +50)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +70)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +90)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +110)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +130)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +157)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +209)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +314)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +628)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +942)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -3)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -6)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -9)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -12)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -15)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -20)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -30)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -40)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -50)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -70)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -90)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -110)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -130)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -157)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -209)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -314)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -628)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -942)
|
||||
.done();
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +3)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +6)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +9)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +12)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +15)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +20)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +30)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +40)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +50)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +70)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +90)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +110)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +130)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +157)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +209)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +314)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +628)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +942)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -3)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -6)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -9)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -12)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -15)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -20)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -30)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -40)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -50)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -70)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -90)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -110)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -130)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -157)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -209)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -314)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -628)
|
||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -942)
|
||||
.done();
|
||||
}
|
||||
|
|
|
@ -14,15 +14,19 @@
|
|||
|
||||
#define FULL_ZERO_CHECK
|
||||
|
||||
inline void ensure_zero(uint8_t * data, uint32_t size) {
|
||||
inline void ensure_zero(uint8_t* data, uint32_t size)
|
||||
{
|
||||
#ifdef FULL_ZERO_CHECK
|
||||
for (std::size_t i=0;i<size;++i) {
|
||||
if (data[i] != 0) {
|
||||
for (std::size_t i = 0; i < size; ++i)
|
||||
{
|
||||
if (data[i] != 0)
|
||||
{
|
||||
throw std::runtime_error("found non zero value");
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (data[0] != 0) {
|
||||
if (data[0] != 0)
|
||||
{
|
||||
throw std::runtime_error("found non zero value");
|
||||
}
|
||||
#endif
|
||||
|
@ -30,274 +34,262 @@ inline void ensure_zero(uint8_t * data, uint32_t size) {
|
|||
|
||||
class test1 : public benchmark::test_case
|
||||
{
|
||||
public:
|
||||
public:
|
||||
uint32_t size_;
|
||||
std::vector<uint8_t> array_;
|
||||
test1(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
size_(*params.get<mapnik::value_integer>("size",256*256)),
|
||||
array_(size_,0) { }
|
||||
bool validate() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
: test_case(params)
|
||||
, size_(*params.get<mapnik::value_integer>("size", 256 * 256))
|
||||
, array_(size_, 0)
|
||||
{}
|
||||
bool validate() const { return true; }
|
||||
bool operator()() const
|
||||
{
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
// NOTE: sizeof(uint8_t) == 1
|
||||
uint8_t *data = (uint8_t *)malloc(sizeof(uint8_t)*size_);
|
||||
memcpy(data, &array_[0], size_);
|
||||
ensure_zero(data,size_);
|
||||
free(data);
|
||||
}
|
||||
return true;
|
||||
for (std::size_t i = 0; i < iterations_; ++i)
|
||||
{
|
||||
// NOTE: sizeof(uint8_t) == 1
|
||||
uint8_t* data = (uint8_t*)malloc(sizeof(uint8_t) * size_);
|
||||
memcpy(data, &array_[0], size_);
|
||||
ensure_zero(data, size_);
|
||||
free(data);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class test1b : public benchmark::test_case
|
||||
{
|
||||
public:
|
||||
public:
|
||||
uint32_t size_;
|
||||
std::vector<uint8_t> array_;
|
||||
test1b(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
size_(*params.get<mapnik::value_integer>("size",256*256)),
|
||||
array_(size_,0) { }
|
||||
bool validate() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
: test_case(params)
|
||||
, size_(*params.get<mapnik::value_integer>("size", 256 * 256))
|
||||
, array_(size_, 0)
|
||||
{}
|
||||
bool validate() const { return true; }
|
||||
bool operator()() const
|
||||
{
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
// NOTE: sizeof(uint8_t) == 1
|
||||
uint8_t *data = (uint8_t *)malloc(sizeof(uint8_t)*size_);
|
||||
memset(data, 0, sizeof(uint8_t)*size_);
|
||||
ensure_zero(data,size_);
|
||||
free(data);
|
||||
}
|
||||
return true;
|
||||
for (std::size_t i = 0; i < iterations_; ++i)
|
||||
{
|
||||
// NOTE: sizeof(uint8_t) == 1
|
||||
uint8_t* data = (uint8_t*)malloc(sizeof(uint8_t) * size_);
|
||||
memset(data, 0, sizeof(uint8_t) * size_);
|
||||
ensure_zero(data, size_);
|
||||
free(data);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class test1c : public benchmark::test_case
|
||||
{
|
||||
public:
|
||||
public:
|
||||
uint32_t size_;
|
||||
std::vector<uint8_t> array_;
|
||||
test1c(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
size_(*params.get<mapnik::value_integer>("size",256*256)),
|
||||
array_(size_,0) { }
|
||||
bool validate() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
: test_case(params)
|
||||
, size_(*params.get<mapnik::value_integer>("size", 256 * 256))
|
||||
, array_(size_, 0)
|
||||
{}
|
||||
bool validate() const { return true; }
|
||||
bool operator()() const
|
||||
{
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
uint8_t *data = static_cast<uint8_t *>(::operator new(sizeof(uint8_t) * size_));
|
||||
std::fill(data,data + size_,0);
|
||||
ensure_zero(data,size_);
|
||||
::operator delete(data);
|
||||
}
|
||||
return true;
|
||||
for (std::size_t i = 0; i < iterations_; ++i)
|
||||
{
|
||||
uint8_t* data = static_cast<uint8_t*>(::operator new(sizeof(uint8_t) * size_));
|
||||
std::fill(data, data + size_, 0);
|
||||
ensure_zero(data, size_);
|
||||
::operator delete(data);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class test2 : public benchmark::test_case
|
||||
{
|
||||
public:
|
||||
public:
|
||||
uint32_t size_;
|
||||
std::vector<uint8_t> array_;
|
||||
test2(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
size_(*params.get<mapnik::value_integer>("size",256*256)),
|
||||
array_(size_,0) { }
|
||||
bool validate() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
: test_case(params)
|
||||
, size_(*params.get<mapnik::value_integer>("size", 256 * 256))
|
||||
, array_(size_, 0)
|
||||
{}
|
||||
bool validate() const { return true; }
|
||||
bool operator()() const
|
||||
{
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
uint8_t * data = static_cast<uint8_t*>(::operator new(sizeof(uint8_t)*size_));
|
||||
memcpy(data, &array_[0], size_);
|
||||
ensure_zero(data,size_);
|
||||
::operator delete(data),data=0;
|
||||
}
|
||||
return true;
|
||||
for (std::size_t i = 0; i < iterations_; ++i)
|
||||
{
|
||||
uint8_t* data = static_cast<uint8_t*>(::operator new(sizeof(uint8_t) * size_));
|
||||
memcpy(data, &array_[0], size_);
|
||||
ensure_zero(data, size_);
|
||||
::operator delete(data), data = 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class test3 : public benchmark::test_case
|
||||
{
|
||||
public:
|
||||
public:
|
||||
uint32_t size_;
|
||||
std::vector<uint8_t> array_;
|
||||
test3(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
size_(*params.get<mapnik::value_integer>("size",256*256)),
|
||||
array_(size_,0) { }
|
||||
bool validate() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
: test_case(params)
|
||||
, size_(*params.get<mapnik::value_integer>("size", 256 * 256))
|
||||
, array_(size_, 0)
|
||||
{}
|
||||
bool validate() const { return true; }
|
||||
bool operator()() const
|
||||
{
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
std::vector<uint8_t> data(size_);
|
||||
ensure_zero(&data[0],data.size());
|
||||
}
|
||||
return true;
|
||||
for (std::size_t i = 0; i < iterations_; ++i)
|
||||
{
|
||||
std::vector<uint8_t> data(size_);
|
||||
ensure_zero(&data[0], data.size());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class test3b : public benchmark::test_case
|
||||
{
|
||||
public:
|
||||
public:
|
||||
uint32_t size_;
|
||||
std::vector<uint8_t> array_;
|
||||
test3b(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
size_(*params.get<mapnik::value_integer>("size",256*256)),
|
||||
array_(size_,0) { }
|
||||
bool validate() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
: test_case(params)
|
||||
, size_(*params.get<mapnik::value_integer>("size", 256 * 256))
|
||||
, array_(size_, 0)
|
||||
{}
|
||||
bool validate() const { return true; }
|
||||
bool operator()() const
|
||||
{
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
std::vector<uint8_t> data(0);
|
||||
data.resize(size_,0);
|
||||
ensure_zero(&data[0],data.size());
|
||||
}
|
||||
return true;
|
||||
for (std::size_t i = 0; i < iterations_; ++i)
|
||||
{
|
||||
std::vector<uint8_t> data(0);
|
||||
data.resize(size_, 0);
|
||||
ensure_zero(&data[0], data.size());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class test3c : public benchmark::test_case
|
||||
{
|
||||
public:
|
||||
public:
|
||||
uint32_t size_;
|
||||
std::vector<uint8_t> array_;
|
||||
test3c(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
size_(*params.get<mapnik::value_integer>("size",256*256)),
|
||||
array_(size_,0) { }
|
||||
bool validate() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
: test_case(params)
|
||||
, size_(*params.get<mapnik::value_integer>("size", 256 * 256))
|
||||
, array_(size_, 0)
|
||||
{}
|
||||
bool validate() const { return true; }
|
||||
bool operator()() const
|
||||
{
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
std::vector<uint8_t> data(0);
|
||||
data.assign(size_,0);
|
||||
ensure_zero(&data[0],data.size());
|
||||
}
|
||||
return true;
|
||||
for (std::size_t i = 0; i < iterations_; ++i)
|
||||
{
|
||||
std::vector<uint8_t> data(0);
|
||||
data.assign(size_, 0);
|
||||
ensure_zero(&data[0], data.size());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class test3d : public benchmark::test_case
|
||||
{
|
||||
public:
|
||||
public:
|
||||
uint32_t size_;
|
||||
std::vector<uint8_t> array_;
|
||||
test3d(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
size_(*params.get<mapnik::value_integer>("size",256*256)),
|
||||
array_(size_,0) { }
|
||||
bool validate() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
: test_case(params)
|
||||
, size_(*params.get<mapnik::value_integer>("size", 256 * 256))
|
||||
, array_(size_, 0)
|
||||
{}
|
||||
bool validate() const { return true; }
|
||||
bool operator()() const
|
||||
{
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
std::deque<uint8_t> data(size_);
|
||||
for (std::size_t i=0;i<size_;++i) {
|
||||
if (data[i] != 0) {
|
||||
throw std::runtime_error("found non zero value");
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
for (std::size_t i = 0; i < iterations_; ++i)
|
||||
{
|
||||
std::deque<uint8_t> data(size_);
|
||||
for (std::size_t i = 0; i < size_; ++i)
|
||||
{
|
||||
if (data[i] != 0)
|
||||
{
|
||||
throw std::runtime_error("found non zero value");
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class test4 : public benchmark::test_case
|
||||
{
|
||||
public:
|
||||
public:
|
||||
uint32_t size_;
|
||||
std::vector<uint8_t> array_;
|
||||
test4(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
size_(*params.get<mapnik::value_integer>("size",256*256)),
|
||||
array_(size_,0) { }
|
||||
bool validate() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
: test_case(params)
|
||||
, size_(*params.get<mapnik::value_integer>("size", 256 * 256))
|
||||
, array_(size_, 0)
|
||||
{}
|
||||
bool validate() const { return true; }
|
||||
bool operator()() const
|
||||
{
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
uint8_t *data = (uint8_t *)calloc(size_,sizeof(uint8_t));
|
||||
ensure_zero(data,size_);
|
||||
free(data);
|
||||
}
|
||||
return true;
|
||||
for (std::size_t i = 0; i < iterations_; ++i)
|
||||
{
|
||||
uint8_t* data = (uint8_t*)calloc(size_, sizeof(uint8_t));
|
||||
ensure_zero(data, size_);
|
||||
free(data);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class test5 : public benchmark::test_case
|
||||
{
|
||||
public:
|
||||
public:
|
||||
uint32_t size_;
|
||||
std::vector<uint8_t> array_;
|
||||
test5(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
size_(*params.get<mapnik::value_integer>("size",256*256)),
|
||||
array_(size_,0) { }
|
||||
bool validate() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
: test_case(params)
|
||||
, size_(*params.get<mapnik::value_integer>("size", 256 * 256))
|
||||
, array_(size_, 0)
|
||||
{}
|
||||
bool validate() const { return true; }
|
||||
bool operator()() const
|
||||
{
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
std::string data(array_.begin(),array_.end());
|
||||
ensure_zero((uint8_t *)&data[0],size_);
|
||||
}
|
||||
return true;
|
||||
for (std::size_t i = 0; i < iterations_; ++i)
|
||||
{
|
||||
std::string data(array_.begin(), array_.end());
|
||||
ensure_zero((uint8_t*)&data[0], size_);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class test5b : public benchmark::test_case
|
||||
{
|
||||
public:
|
||||
public:
|
||||
uint32_t size_;
|
||||
std::vector<char> array_;
|
||||
test5b(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
size_(*params.get<mapnik::value_integer>("size",256*256)),
|
||||
array_(size_,0) { }
|
||||
bool validate() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
: test_case(params)
|
||||
, size_(*params.get<mapnik::value_integer>("size", 256 * 256))
|
||||
, array_(size_, 0)
|
||||
{}
|
||||
bool validate() const { return true; }
|
||||
bool operator()() const
|
||||
{
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
std::string data(&array_[0],array_.size());
|
||||
ensure_zero((uint8_t *)&data[0],size_);
|
||||
}
|
||||
return true;
|
||||
for (std::size_t i = 0; i < iterations_; ++i)
|
||||
{
|
||||
std::string data(&array_[0], array_.size());
|
||||
ensure_zero((uint8_t*)&data[0], size_);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -308,24 +300,23 @@ public:
|
|||
|
||||
class test6 : public benchmark::test_case
|
||||
{
|
||||
public:
|
||||
public:
|
||||
uint32_t size_;
|
||||
std::vector<uint8_t> array_;
|
||||
test6(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
size_(*params.get<mapnik::value_integer>("size",256*256)),
|
||||
array_(size_,0) { }
|
||||
bool validate() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
: test_case(params)
|
||||
, size_(*params.get<mapnik::value_integer>("size", 256 * 256))
|
||||
, array_(size_, 0)
|
||||
{}
|
||||
bool validate() const { return true; }
|
||||
bool operator()() const
|
||||
{
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
std::valarray<uint8_t> data(static_cast<uint8_t>(0),static_cast<size_t>(size_));
|
||||
ensure_zero(&data[0],size_);
|
||||
}
|
||||
return true;
|
||||
for (std::size_t i = 0; i < iterations_; ++i)
|
||||
{
|
||||
std::valarray<uint8_t> data(static_cast<uint8_t>(0), static_cast<size_t>(size_));
|
||||
ensure_zero(&data[0], size_);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -335,24 +326,23 @@ public:
|
|||
|
||||
class test7 : public benchmark::test_case
|
||||
{
|
||||
public:
|
||||
public:
|
||||
uint32_t size_;
|
||||
std::vector<uint8_t> array_;
|
||||
test7(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
size_(*params.get<mapnik::value_integer>("size",256*256)),
|
||||
array_(size_,0) { }
|
||||
bool validate() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
: test_case(params)
|
||||
, size_(*params.get<mapnik::value_integer>("size", 256 * 256))
|
||||
, array_(size_, 0)
|
||||
{}
|
||||
bool validate() const { return true; }
|
||||
bool operator()() const
|
||||
{
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
boost::container::static_vector<uint8_t,256*256> data(size_,0);
|
||||
ensure_zero(&data[0],size_);
|
||||
}
|
||||
return true;
|
||||
for (std::size_t i = 0; i < iterations_; ++i)
|
||||
{
|
||||
boost::container::static_vector<uint8_t, 256 * 256> data(size_, 0);
|
||||
ensure_zero(&data[0], size_);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
@ -360,20 +350,20 @@ public:
|
|||
int main(int argc, char** argv)
|
||||
{
|
||||
return benchmark::sequencer(argc, argv)
|
||||
.run<test4>("calloc")
|
||||
.run<test1>("malloc/memcpy")
|
||||
.run<test1b>("malloc/memset")
|
||||
.run<test1c>("operator new/std::fill")
|
||||
.run<test2>("operator new/memcpy")
|
||||
.run<test3>("vector(N)")
|
||||
.run<test3b>("vector/resize")
|
||||
.run<test3c>("vector/assign")
|
||||
.run<test3d>("deque(N)")
|
||||
.run<test5>("std::string range")
|
||||
.run<test5b>("std::string &[0]")
|
||||
.run<test6>("valarray")
|
||||
.run<test4>("calloc")
|
||||
.run<test1>("malloc/memcpy")
|
||||
.run<test1b>("malloc/memset")
|
||||
.run<test1c>("operator new/std::fill")
|
||||
.run<test2>("operator new/memcpy")
|
||||
.run<test3>("vector(N)")
|
||||
.run<test3b>("vector/resize")
|
||||
.run<test3c>("vector/assign")
|
||||
.run<test3d>("deque(N)")
|
||||
.run<test5>("std::string range")
|
||||
.run<test5b>("std::string &[0]")
|
||||
.run<test6>("valarray")
|
||||
#if BOOST_VERSION >= 105400
|
||||
.run<test7>("static_vector")
|
||||
.run<test7>("static_vector")
|
||||
#endif
|
||||
.done();
|
||||
.done();
|
||||
}
|
||||
|
|
|
@ -7,10 +7,12 @@
|
|||
class test : public benchmark::test_case
|
||||
{
|
||||
std::string expr_;
|
||||
public:
|
||||
|
||||
public:
|
||||
test(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
expr_("((([mapnik::geometry_type]=2) and ([oneway]=1)) and ([class]='path'))") {}
|
||||
: test_case(params)
|
||||
, expr_("((([mapnik::geometry_type]=2) and ([oneway]=1)) and ([class]='path'))")
|
||||
{}
|
||||
bool validate() const
|
||||
{
|
||||
mapnik::expression_ptr expr = mapnik::parse_expression(expr_);
|
||||
|
@ -18,24 +20,24 @@ public:
|
|||
bool ret = (result == expr_);
|
||||
if (!ret)
|
||||
{
|
||||
std::clog << result << " != " << expr_ << "\n";
|
||||
std::clog << result << " != " << expr_ << "\n";
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
bool operator()() const
|
||||
{
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
mapnik::expression_ptr expr = mapnik::parse_expression(expr_);
|
||||
}
|
||||
return true;
|
||||
for (std::size_t i = 0; i < iterations_; ++i)
|
||||
{
|
||||
mapnik::expression_ptr expr = mapnik::parse_expression(expr_);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
mapnik::parameters params;
|
||||
benchmark::handle_args(argc,argv,params);
|
||||
benchmark::handle_args(argc, argv, params);
|
||||
test test_runner(params);
|
||||
return run(test_runner,"expr parsing");
|
||||
return run(test_runner, "expr parsing");
|
||||
}
|
||||
|
|
|
@ -4,9 +4,10 @@
|
|||
|
||||
class test : public benchmark::test_case
|
||||
{
|
||||
public:
|
||||
public:
|
||||
test(mapnik::parameters const& params)
|
||||
: test_case(params) {}
|
||||
: test_case(params)
|
||||
{}
|
||||
bool validate() const
|
||||
{
|
||||
std::size_t count = 0;
|
||||
|
@ -22,14 +23,15 @@ public:
|
|||
font_cache,
|
||||
mapnik::freetype_engine::get_mapping(),
|
||||
mapnik::freetype_engine::get_cache());
|
||||
if (f) ++count;
|
||||
if (f)
|
||||
++count;
|
||||
}
|
||||
return count == expected_count;
|
||||
}
|
||||
bool operator()() const
|
||||
{
|
||||
std::size_t expected_count = mapnik::freetype_engine::face_names().size();
|
||||
for (unsigned i=0;i<iterations_;++i)
|
||||
for (unsigned i = 0; i < iterations_; ++i)
|
||||
{
|
||||
std::size_t count = 0;
|
||||
mapnik::freetype_engine::font_file_mapping_type font_file_mapping;
|
||||
|
@ -43,9 +45,11 @@ public:
|
|||
font_cache,
|
||||
mapnik::freetype_engine::get_mapping(),
|
||||
mapnik::freetype_engine::get_cache());
|
||||
if (f) ++count;
|
||||
if (f)
|
||||
++count;
|
||||
}
|
||||
if (count != expected_count) {
|
||||
if (count != expected_count)
|
||||
{
|
||||
std::clog << "warning: face creation not working as expected\n";
|
||||
}
|
||||
}
|
||||
|
@ -56,14 +60,14 @@ public:
|
|||
int main(int argc, char** argv)
|
||||
{
|
||||
mapnik::parameters params;
|
||||
benchmark::handle_args(argc,argv,params);
|
||||
benchmark::handle_args(argc, argv, params);
|
||||
bool success = mapnik::freetype_engine::register_fonts("./fonts", true);
|
||||
if (!success) {
|
||||
std::clog << "warning, did not register any new fonts!\n";
|
||||
return -1;
|
||||
}
|
||||
if (!success)
|
||||
{
|
||||
std::clog << "warning, did not register any new fonts!\n";
|
||||
return -1;
|
||||
}
|
||||
std::size_t face_count = mapnik::freetype_engine::face_names().size();
|
||||
test test_runner(params);
|
||||
return run(test_runner,(boost::format("font_engine: creating %ld faces") % (face_count)).str());
|
||||
return run(test_runner, (boost::format("font_engine: creating %ld faces") % (face_count)).str());
|
||||
}
|
||||
|
||||
|
|
|
@ -5,17 +5,15 @@
|
|||
|
||||
class test : public benchmark::test_case
|
||||
{
|
||||
public:
|
||||
public:
|
||||
test(mapnik::parameters const& params)
|
||||
: test_case(params) {}
|
||||
bool validate() const
|
||||
{
|
||||
return mapnik::freetype_engine::register_fonts("./fonts", true);
|
||||
}
|
||||
: test_case(params)
|
||||
{}
|
||||
bool validate() const { return mapnik::freetype_engine::register_fonts("./fonts", true); }
|
||||
bool operator()() const
|
||||
{
|
||||
unsigned long count = 0;
|
||||
for (unsigned i=0;i<iterations_;++i)
|
||||
for (unsigned i = 0; i < iterations_; ++i)
|
||||
{
|
||||
mapnik::freetype_engine::register_fonts("./fonts", true);
|
||||
count++;
|
||||
|
@ -24,4 +22,4 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
BENCHMARK(test,"font registration")
|
||||
BENCHMARK(test, "font registration")
|
||||
|
|
|
@ -1,22 +1,20 @@
|
|||
#include "bench_framework.hpp"
|
||||
#include "../plugins/input/csv/csv_getline.hpp"
|
||||
|
||||
|
||||
|
||||
class test : public benchmark::test_case
|
||||
{
|
||||
public:
|
||||
public:
|
||||
std::string line_data_;
|
||||
test(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
line_data_("this is one line\nand this is a second line\nand a third line")
|
||||
{
|
||||
boost::optional<std::string> line_data = params.get<std::string>("line");
|
||||
if (line_data)
|
||||
{
|
||||
line_data_ = *line_data;
|
||||
}
|
||||
}
|
||||
: test_case(params)
|
||||
, line_data_("this is one line\nand this is a second line\nand a third line")
|
||||
{
|
||||
boost::optional<std::string> line_data = params.get<std::string>("line");
|
||||
if (line_data)
|
||||
{
|
||||
line_data_ = *line_data;
|
||||
}
|
||||
}
|
||||
|
||||
bool validate() const
|
||||
{
|
||||
|
@ -25,14 +23,15 @@ public:
|
|||
std::string csv_line;
|
||||
std::stringstream s;
|
||||
s << line_data_;
|
||||
std::getline(s,csv_line,newline);
|
||||
std::getline(s, csv_line, newline);
|
||||
if (csv_line != first)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::clog << "Error: the parsed line (" << csv_line << ") should be a subset of the original line (" << line_data_ << ") (ensure you pass a line with a \\n)\n";
|
||||
std::clog << "Error: the parsed line (" << csv_line << ") should be a subset of the original line ("
|
||||
<< line_data_ << ") (ensure you pass a line with a \\n)\n";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -42,29 +41,28 @@ public:
|
|||
std::string csv_line;
|
||||
std::stringstream s;
|
||||
s << line_data_;
|
||||
for (unsigned i=0;i<iterations_;++i)
|
||||
for (unsigned i = 0; i < iterations_; ++i)
|
||||
{
|
||||
std::getline(s,csv_line,newline);
|
||||
std::getline(s, csv_line, newline);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class test2 : public benchmark::test_case
|
||||
{
|
||||
public:
|
||||
public:
|
||||
std::string line_data_;
|
||||
test2(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
line_data_("this is one line\nand this is a second line\nand a third line")
|
||||
{
|
||||
boost::optional<std::string> line_data = params.get<std::string>("line");
|
||||
if (line_data)
|
||||
{
|
||||
line_data_ = *line_data;
|
||||
}
|
||||
}
|
||||
: test_case(params)
|
||||
, line_data_("this is one line\nand this is a second line\nand a third line")
|
||||
{
|
||||
boost::optional<std::string> line_data = params.get<std::string>("line");
|
||||
if (line_data)
|
||||
{
|
||||
line_data_ = *line_data;
|
||||
}
|
||||
}
|
||||
|
||||
bool validate() const
|
||||
{
|
||||
|
@ -74,14 +72,15 @@ public:
|
|||
std::string csv_line;
|
||||
std::stringstream s;
|
||||
s << line_data_;
|
||||
csv_utils::getline_csv(s,csv_line,newline,quote);
|
||||
csv_utils::getline_csv(s, csv_line, newline, quote);
|
||||
if (csv_line != first)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::clog << "Error: the parsed line (" << csv_line << ") should be a subset of the original line (" << line_data_ << ") (ensure you pass a line with a \\n)\n";
|
||||
std::clog << "Error: the parsed line (" << csv_line << ") should be a subset of the original line ("
|
||||
<< line_data_ << ") (ensure you pass a line with a \\n)\n";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -92,9 +91,9 @@ public:
|
|||
std::string csv_line;
|
||||
std::stringstream s;
|
||||
s << line_data_;
|
||||
for (unsigned i=0;i<iterations_;++i)
|
||||
for (unsigned i = 0; i < iterations_; ++i)
|
||||
{
|
||||
csv_utils::getline_csv(s,csv_line,newline,quote);
|
||||
csv_utils::getline_csv(s, csv_line, newline, quote);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -106,17 +105,16 @@ int main(int argc, char** argv)
|
|||
try
|
||||
{
|
||||
mapnik::parameters params;
|
||||
benchmark::handle_args(argc,argv,params);
|
||||
benchmark::handle_args(argc, argv, params);
|
||||
{
|
||||
test test_runner(params);
|
||||
return_value = return_value | run(test_runner,"std::getline");
|
||||
return_value = return_value | run(test_runner, "std::getline");
|
||||
}
|
||||
{
|
||||
test2 test_runner2(params);
|
||||
return_value = return_value | run(test_runner2,"csv_utils::getline_csv");
|
||||
return_value = return_value | run(test_runner2, "csv_utils::getline_csv");
|
||||
}
|
||||
}
|
||||
catch (std::exception const& ex)
|
||||
} catch (std::exception const& ex)
|
||||
{
|
||||
std::clog << ex.what() << "\n";
|
||||
return -1;
|
||||
|
|
|
@ -4,34 +4,32 @@
|
|||
class test : public benchmark::test_case
|
||||
{
|
||||
std::vector<std::string> images_;
|
||||
public:
|
||||
|
||||
public:
|
||||
test(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
images_{
|
||||
"./test/data/images/dummy.jpg",
|
||||
"./test/data/images/dummy.jpeg",
|
||||
"./test/data/images/dummy.png",
|
||||
"./test/data/images/dummy.tif",
|
||||
"./test/data/images/dummy.tiff",
|
||||
//"./test/data/images/landusepattern.jpeg", // will fail since it is a png
|
||||
//"./test/data/images/xcode-CgBI.png", // will fail since its an invalid png
|
||||
"./test/data/svg/octocat.svg",
|
||||
"./test/data/svg/place-of-worship-24.svg",
|
||||
"./test/data/svg/point_sm.svg",
|
||||
"./test/data/svg/point.svg",
|
||||
"./test/data/svg/airfield-12.svg"
|
||||
} {}
|
||||
bool validate() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
: test_case(params)
|
||||
, images_{"./test/data/images/dummy.jpg",
|
||||
"./test/data/images/dummy.jpeg",
|
||||
"./test/data/images/dummy.png",
|
||||
"./test/data/images/dummy.tif",
|
||||
"./test/data/images/dummy.tiff",
|
||||
//"./test/data/images/landusepattern.jpeg", // will fail since it is a png
|
||||
//"./test/data/images/xcode-CgBI.png", // will fail since its an invalid png
|
||||
"./test/data/svg/octocat.svg",
|
||||
"./test/data/svg/place-of-worship-24.svg",
|
||||
"./test/data/svg/point_sm.svg",
|
||||
"./test/data/svg/point.svg",
|
||||
"./test/data/svg/airfield-12.svg"}
|
||||
{}
|
||||
bool validate() const { return true; }
|
||||
bool operator()() const
|
||||
{
|
||||
unsigned count = 0;
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
for (std::size_t i = 0; i < iterations_; ++i)
|
||||
{
|
||||
for (auto filename : images_)
|
||||
{
|
||||
auto marker = mapnik::marker_cache::instance().find(filename,true);
|
||||
auto marker = mapnik::marker_cache::instance().find(filename, true);
|
||||
}
|
||||
++count;
|
||||
}
|
||||
|
@ -39,4 +37,4 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
BENCHMARK(test,"marker cache")
|
||||
BENCHMARK(test, "marker cache")
|
|
@ -14,40 +14,38 @@
|
|||
|
||||
class test : public benchmark::test_case
|
||||
{
|
||||
public:
|
||||
public:
|
||||
test(mapnik::parameters const& params)
|
||||
: test_case(params) {}
|
||||
: test_case(params)
|
||||
{}
|
||||
|
||||
bool validate() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool validate() const { return true; }
|
||||
bool operator()() const
|
||||
{
|
||||
mapnik::Map m(256,256,"epsg:3857");
|
||||
mapnik::Map m(256, 256, "epsg:3857");
|
||||
|
||||
mapnik::parameters params;
|
||||
params["type"]="memory";
|
||||
params["type"] = "memory";
|
||||
auto ds = std::make_shared<mapnik::memory_datasource>(params);
|
||||
// add whitespace to trigger phony "reprojection"
|
||||
mapnik::layer lay("layer",m.srs() + " ");
|
||||
mapnik::layer lay("layer", m.srs() + " ");
|
||||
lay.set_datasource(ds);
|
||||
lay.add_style("style");
|
||||
m.add_layer(lay);
|
||||
// dummy style to ensure that layer is processed
|
||||
m.insert_style("style",mapnik::feature_type_style());
|
||||
m.insert_style("style", mapnik::feature_type_style());
|
||||
// dummy bbox, but "valid" because minx and miny are less
|
||||
// with an invalid bbox then layer.visible() returns false
|
||||
// and the initial rendering setup is not run
|
||||
m.zoom_to_box(mapnik::box2d<double>(-1,-1,0,0));
|
||||
for (unsigned i=0;i<iterations_;++i)
|
||||
m.zoom_to_box(mapnik::box2d<double>(-1, -1, 0, 0));
|
||||
for (unsigned i = 0; i < iterations_; ++i)
|
||||
{
|
||||
mapnik::image_rgba8 im(256,256);
|
||||
mapnik::agg_renderer<mapnik::image_rgba8> ren(m,im);
|
||||
mapnik::image_rgba8 im(256, 256);
|
||||
mapnik::agg_renderer<mapnik::image_rgba8> ren(m, im);
|
||||
ren.apply();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
BENCHMARK(test,"rendering with reprojection")
|
||||
BENCHMARK(test, "rendering with reprojection")
|
||||
|
|
|
@ -9,23 +9,25 @@ class test_static : public benchmark::test_case
|
|||
{
|
||||
double step_;
|
||||
std::uint8_t start_;
|
||||
public:
|
||||
|
||||
public:
|
||||
test_static(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
step_(STEP_NUM),
|
||||
start_(START_NUM) {}
|
||||
bool validate() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
: test_case(params)
|
||||
, step_(STEP_NUM)
|
||||
, start_(START_NUM)
|
||||
{}
|
||||
bool validate() const { return true; }
|
||||
bool operator()() const
|
||||
{
|
||||
double value_ = 0.0;
|
||||
std::uint8_t x;
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
for (std::size_t i = 0; i < iterations_; ++i)
|
||||
{
|
||||
double c = static_cast<double>(start_) * value_;
|
||||
if (c >= 256.0) c = 255.0;
|
||||
if (c < 0.0) c = 0.0;
|
||||
if (c >= 256.0)
|
||||
c = 255.0;
|
||||
if (c < 0.0)
|
||||
c = 0.0;
|
||||
x = static_cast<std::uint8_t>(c);
|
||||
value_ += step_;
|
||||
}
|
||||
|
@ -33,35 +35,34 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
using boost::numeric::positive_overflow;
|
||||
using boost::numeric::negative_overflow;
|
||||
using boost::numeric::positive_overflow;
|
||||
|
||||
class test_numeric : public benchmark::test_case
|
||||
{
|
||||
double step_;
|
||||
std::uint8_t start_;
|
||||
public:
|
||||
|
||||
public:
|
||||
test_numeric(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
step_(STEP_NUM),
|
||||
start_(START_NUM) {}
|
||||
bool validate() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
: test_case(params)
|
||||
, step_(STEP_NUM)
|
||||
, start_(START_NUM)
|
||||
{}
|
||||
bool validate() const { return true; }
|
||||
bool operator()() const
|
||||
{
|
||||
double value_ = 0.0;
|
||||
std::uint8_t x;
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
try {
|
||||
for (std::size_t i = 0; i < iterations_; ++i)
|
||||
{
|
||||
try
|
||||
{
|
||||
x = boost::numeric_cast<std::uint8_t>(start_ * value_);
|
||||
}
|
||||
catch(negative_overflow&)
|
||||
} catch (negative_overflow&)
|
||||
{
|
||||
x = std::numeric_limits<std::uint8_t>::min();
|
||||
}
|
||||
catch(positive_overflow&)
|
||||
} catch (positive_overflow&)
|
||||
{
|
||||
x = std::numeric_limits<std::uint8_t>::max();
|
||||
}
|
||||
|
@ -73,8 +74,5 @@ public:
|
|||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
return benchmark::sequencer(argc, argv)
|
||||
.run<test_static>("static_cast")
|
||||
.run<test_numeric>("numeric_cast")
|
||||
.done();
|
||||
return benchmark::sequencer(argc, argv).run<test_static>("static_cast").run<test_numeric>("numeric_cast").done();
|
||||
}
|
||||
|
|
|
@ -14,31 +14,36 @@ struct fake_path
|
|||
cont_type::iterator itr_;
|
||||
|
||||
fake_path(std::initializer_list<double> l)
|
||||
: fake_path(l.begin(), l.size()) {
|
||||
}
|
||||
: fake_path(l.begin(), l.size())
|
||||
{}
|
||||
|
||||
fake_path(std::vector<double> const &v)
|
||||
: fake_path(v.begin(), v.size()) {
|
||||
}
|
||||
fake_path(std::vector<double> const& v)
|
||||
: fake_path(v.begin(), v.size())
|
||||
{}
|
||||
|
||||
template <typename Itr>
|
||||
fake_path(Itr itr, size_t sz) {
|
||||
template<typename Itr>
|
||||
fake_path(Itr itr, size_t sz)
|
||||
{
|
||||
size_t num_coords = sz >> 1;
|
||||
vertices_.reserve(num_coords);
|
||||
|
||||
for (size_t i = 0; i < num_coords; ++i) {
|
||||
for (size_t i = 0; i < num_coords; ++i)
|
||||
{
|
||||
double x = *itr++;
|
||||
double y = *itr++;
|
||||
unsigned cmd = (i == 0) ? mapnik::SEG_MOVETO : mapnik::SEG_LINETO;
|
||||
vertices_.push_back(std::make_tuple(x, y, cmd));
|
||||
if (i == num_coords - 1) cmd = mapnik::SEG_END;
|
||||
if (i == num_coords - 1)
|
||||
cmd = mapnik::SEG_END;
|
||||
vertices_.push_back(std::make_tuple(x, y, cmd));
|
||||
}
|
||||
itr_ = vertices_.begin();
|
||||
}
|
||||
|
||||
unsigned vertex(double *x, double *y) {
|
||||
if (itr_ == vertices_.end()) {
|
||||
unsigned vertex(double* x, double* y)
|
||||
{
|
||||
if (itr_ == vertices_.end())
|
||||
{
|
||||
return mapnik::SEG_END;
|
||||
}
|
||||
*x = std::get<0>(*itr_);
|
||||
|
@ -48,33 +53,30 @@ struct fake_path
|
|||
return cmd;
|
||||
}
|
||||
|
||||
void rewind(unsigned) {
|
||||
itr_ = vertices_.begin();
|
||||
}
|
||||
void rewind(unsigned) { itr_ = vertices_.begin(); }
|
||||
};
|
||||
|
||||
class test_offset : public benchmark::test_case
|
||||
{
|
||||
public:
|
||||
public:
|
||||
test_offset(mapnik::parameters const& params)
|
||||
: test_case(params) {}
|
||||
bool validate() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
: test_case(params)
|
||||
{}
|
||||
bool validate() const { return true; }
|
||||
bool operator()() const
|
||||
{
|
||||
std::vector<double> path;
|
||||
int mysize = 2500;
|
||||
int x1 = 0;
|
||||
path.reserve(mysize*2);
|
||||
for( int i = 0; i < mysize; i++ )
|
||||
path.reserve(mysize * 2);
|
||||
for (int i = 0; i < mysize; i++)
|
||||
{
|
||||
path.push_back( i );
|
||||
path.push_back( 0 );
|
||||
path.push_back(i);
|
||||
path.push_back(0);
|
||||
}
|
||||
fake_path fpath(path);
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
for (std::size_t i = 0; i < iterations_; ++i)
|
||||
{
|
||||
mapnik::offset_converter<fake_path> off_path(fpath);
|
||||
off_path.set_offset(10);
|
||||
unsigned cmd;
|
||||
|
@ -88,15 +90,14 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
mapnik::parameters params;
|
||||
benchmark::handle_args(argc,argv,params);
|
||||
benchmark::handle_args(argc, argv, params);
|
||||
int return_value = 0;
|
||||
{
|
||||
test_offset test_runner(params);
|
||||
return_value = run(test_runner,"offset_test");
|
||||
return_value = run(test_runner, "offset_test");
|
||||
}
|
||||
return return_value;
|
||||
}
|
||||
|
|
|
@ -4,23 +4,23 @@
|
|||
class test : public benchmark::test_case
|
||||
{
|
||||
mapnik::image_rgba8 im_;
|
||||
public:
|
||||
|
||||
public:
|
||||
test(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
im_(256,256) {}
|
||||
bool validate() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
: test_case(params)
|
||||
, im_(256, 256)
|
||||
{}
|
||||
bool validate() const { return true; }
|
||||
bool operator()() const
|
||||
{
|
||||
std::string out;
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
for (std::size_t i = 0; i < iterations_; ++i)
|
||||
{
|
||||
out.clear();
|
||||
out = mapnik::save_to_string(im_,"png8:m=h:z=1");
|
||||
out = mapnik::save_to_string(im_, "png8:m=h:z=1");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
BENCHMARK(test,"encoding blank png")
|
||||
BENCHMARK(test, "encoding blank png")
|
||||
|
|
|
@ -4,34 +4,37 @@
|
|||
class test : public benchmark::test_case
|
||||
{
|
||||
std::shared_ptr<mapnik::image_rgba8> im_;
|
||||
public:
|
||||
|
||||
public:
|
||||
test(mapnik::parameters const& params)
|
||||
: test_case(params) {
|
||||
: test_case(params)
|
||||
{
|
||||
std::string filename("./benchmark/data/multicolor.png");
|
||||
std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(filename,"png"));
|
||||
std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(filename, "png"));
|
||||
if (!reader.get())
|
||||
{
|
||||
throw mapnik::image_reader_exception("Failed to load: " + filename);
|
||||
}
|
||||
im_ = std::make_shared<mapnik::image_rgba8>(reader->width(),reader->height());
|
||||
reader->read(0,0,*im_);
|
||||
im_ = std::make_shared<mapnik::image_rgba8>(reader->width(), reader->height());
|
||||
reader->read(0, 0, *im_);
|
||||
}
|
||||
bool validate() const
|
||||
{
|
||||
std::string expected("./benchmark/data/multicolor-hextree-expected.png");
|
||||
std::string actual("./benchmark/data/multicolor-hextree-actual.png");
|
||||
mapnik::save_to_file(*im_,actual, "png8:m=h:z=1");
|
||||
return benchmark::compare_images(actual,expected);
|
||||
mapnik::save_to_file(*im_, actual, "png8:m=h:z=1");
|
||||
return benchmark::compare_images(actual, expected);
|
||||
}
|
||||
bool operator()() const
|
||||
{
|
||||
std::string out;
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
for (std::size_t i = 0; i < iterations_; ++i)
|
||||
{
|
||||
out.clear();
|
||||
out = mapnik::save_to_string(*im_,"png8:m=h:z=1");
|
||||
out = mapnik::save_to_string(*im_, "png8:m=h:z=1");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
BENCHMARK(test,"encoding multicolor png")
|
||||
BENCHMARK(test, "encoding multicolor png")
|
||||
|
|
|
@ -39,30 +39,31 @@ void render(mapnik::geometry::multi_polygon<double> const& geom,
|
|||
mapnik::box2d<double> const& extent,
|
||||
std::string const& name)
|
||||
{
|
||||
using path_type = mapnik::transform_path_adapter<mapnik::view_transform,mapnik::geometry::polygon_vertex_adapter<double>>;
|
||||
using path_type =
|
||||
mapnik::transform_path_adapter<mapnik::view_transform, mapnik::geometry::polygon_vertex_adapter<double>>;
|
||||
using ren_base = agg::renderer_base<agg::pixfmt_rgba32_plain>;
|
||||
using renderer = agg::renderer_scanline_aa_solid<ren_base>;
|
||||
mapnik::image_rgba8 im(256,256);
|
||||
mapnik::image_rgba8 im(256, 256);
|
||||
mapnik::fill(im, mapnik::color("white"));
|
||||
mapnik::box2d<double> padded_extent(155,134,665,466);//extent;
|
||||
mapnik::box2d<double> padded_extent(155, 134, 665, 466); // extent;
|
||||
padded_extent.pad(10);
|
||||
mapnik::view_transform tr(im.width(),im.height(),padded_extent,0,0);
|
||||
agg::rendering_buffer buf(im.bytes(),im.width(),im.height(), im.row_size());
|
||||
mapnik::view_transform tr(im.width(), im.height(), padded_extent, 0, 0);
|
||||
agg::rendering_buffer buf(im.bytes(), im.width(), im.height(), im.row_size());
|
||||
agg::pixfmt_rgba32_plain pixf(buf);
|
||||
ren_base renb(pixf);
|
||||
renderer ren(renb);
|
||||
mapnik::proj_transform prj_trans(mapnik::projection("epsg:4326"),mapnik::projection("epsg:4326"));
|
||||
ren.color(agg::rgba8(127,127,127,255));
|
||||
mapnik::proj_transform prj_trans(mapnik::projection("epsg:4326"), mapnik::projection("epsg:4326"));
|
||||
ren.color(agg::rgba8(127, 127, 127, 255));
|
||||
agg::rasterizer_scanline_aa<> ras;
|
||||
for (auto const& poly : geom)
|
||||
{
|
||||
mapnik::geometry::polygon_vertex_adapter<double> va(poly);
|
||||
path_type path(tr,va,prj_trans);
|
||||
path_type path(tr, va, prj_trans);
|
||||
ras.add_path(path);
|
||||
}
|
||||
agg::scanline_u8 sl;
|
||||
agg::render_scanlines(ras, sl, ren);
|
||||
mapnik::save_to_file(im,name);
|
||||
mapnik::save_to_file(im, name);
|
||||
}
|
||||
|
||||
class test1 : public benchmark::test_case
|
||||
|
@ -70,15 +71,15 @@ class test1 : public benchmark::test_case
|
|||
std::string wkt_in_;
|
||||
mapnik::box2d<double> extent_;
|
||||
std::string expected_;
|
||||
public:
|
||||
|
||||
public:
|
||||
using conv_clip = agg::conv_clip_polygon<mapnik::geometry::polygon_vertex_adapter<double>>;
|
||||
test1(mapnik::parameters const& params,
|
||||
std::string const& wkt_in,
|
||||
mapnik::box2d<double> const& extent)
|
||||
: test_case(params),
|
||||
wkt_in_(wkt_in),
|
||||
extent_(extent),
|
||||
expected_("./benchmark/data/polygon_clipping_agg") {}
|
||||
test1(mapnik::parameters const& params, std::string const& wkt_in, mapnik::box2d<double> const& extent)
|
||||
: test_case(params)
|
||||
, wkt_in_(wkt_in)
|
||||
, extent_(extent)
|
||||
, expected_("./benchmark/data/polygon_clipping_agg")
|
||||
{}
|
||||
bool validate() const
|
||||
{
|
||||
mapnik::geometry::geometry<double> geom;
|
||||
|
@ -99,14 +100,8 @@ public:
|
|||
mapnik::geometry::polygon<double> const& poly = mapnik::util::get<mapnik::geometry::polygon<double>>(geom);
|
||||
mapnik::geometry::polygon_vertex_adapter<double> va(poly);
|
||||
|
||||
|
||||
conv_clip clipped(va);
|
||||
clipped.clip_box(
|
||||
extent_.minx(),
|
||||
extent_.miny(),
|
||||
extent_.maxx(),
|
||||
extent_.maxy());
|
||||
|
||||
clipped.clip_box(extent_.minx(), extent_.miny(), extent_.maxx(), extent_.maxy());
|
||||
|
||||
clipped.rewind(0);
|
||||
mapnik::geometry::polygon<double> poly2;
|
||||
|
@ -118,7 +113,8 @@ public:
|
|||
{
|
||||
if (cmd == mapnik::SEG_MOVETO)
|
||||
{
|
||||
x0 = x; y0 = y;
|
||||
x0 = x;
|
||||
y0 = y;
|
||||
}
|
||||
|
||||
if (cmd == mapnik::SEG_CLOSE)
|
||||
|
@ -126,7 +122,7 @@ public:
|
|||
ring.emplace_back(x0, y0);
|
||||
break;
|
||||
}
|
||||
ring.emplace_back(x,y);
|
||||
ring.emplace_back(x, y);
|
||||
}
|
||||
poly2.push_back(std::move(ring));
|
||||
// interior rings
|
||||
|
@ -135,30 +131,31 @@ public:
|
|||
{
|
||||
if (cmd == mapnik::SEG_MOVETO)
|
||||
{
|
||||
x0 = x; y0 = y;
|
||||
x0 = x;
|
||||
y0 = y;
|
||||
}
|
||||
else if (cmd == mapnik::SEG_CLOSE)
|
||||
{
|
||||
ring.emplace_back(x0,y0);
|
||||
ring.emplace_back(x0, y0);
|
||||
poly2.push_back(std::move(ring));
|
||||
ring.clear();
|
||||
continue;
|
||||
}
|
||||
ring.emplace_back(x,y);
|
||||
ring.emplace_back(x, y);
|
||||
}
|
||||
|
||||
std::string expect = expected_+".png";
|
||||
std::string actual = expected_+"_actual.png";
|
||||
std::string expect = expected_ + ".png";
|
||||
std::string actual = expected_ + "_actual.png";
|
||||
mapnik::geometry::multi_polygon<double> mp;
|
||||
mp.emplace_back(poly2);
|
||||
auto env = mapnik::geometry::envelope(mp);
|
||||
if (!mapnik::util::exists(expect) || (std::getenv("UPDATE") != nullptr))
|
||||
{
|
||||
std::clog << "generating expected image: " << expect << "\n";
|
||||
render(mp,env,expect);
|
||||
render(mp, env, expect);
|
||||
}
|
||||
render(mp,env,actual);
|
||||
return benchmark::compare_images(actual,expect);
|
||||
render(mp, env, actual);
|
||||
return benchmark::compare_images(actual, expect);
|
||||
}
|
||||
bool operator()() const
|
||||
{
|
||||
|
@ -178,29 +175,28 @@ public:
|
|||
return false;
|
||||
}
|
||||
bool valid = true;
|
||||
for (unsigned i=0;i<iterations_;++i)
|
||||
for (unsigned i = 0; i < iterations_; ++i)
|
||||
{
|
||||
unsigned count = 0;
|
||||
mapnik::geometry::polygon<double> const& poly = mapnik::util::get<mapnik::geometry::polygon<double>>(geom);
|
||||
mapnik::geometry::polygon_vertex_adapter<double> va(poly);
|
||||
conv_clip clipped(va);
|
||||
clipped.clip_box(
|
||||
extent_.minx(),
|
||||
extent_.miny(),
|
||||
extent_.maxx(),
|
||||
extent_.maxy());
|
||||
clipped.clip_box(extent_.minx(), extent_.miny(), extent_.maxx(), extent_.maxy());
|
||||
unsigned cmd;
|
||||
double x,y;
|
||||
double x, y;
|
||||
// NOTE: this rewind is critical otherwise
|
||||
// agg_conv_adapter_vpgen will give garbage
|
||||
// values for the first vertex
|
||||
clipped.rewind(0);
|
||||
while ((cmd = clipped.vertex(&x, &y)) != mapnik::SEG_END) {
|
||||
while ((cmd = clipped.vertex(&x, &y)) != mapnik::SEG_END)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
unsigned expected_count = 30;
|
||||
if (count != expected_count) {
|
||||
std::clog << "test1: clipping failed: processed " << count << " verticies but expected " << expected_count << "\n";
|
||||
if (count != expected_count)
|
||||
{
|
||||
std::clog << "test1: clipping failed: processed " << count << " verticies but expected "
|
||||
<< expected_count << "\n";
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
|
@ -208,20 +204,19 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
class test3 : public benchmark::test_case
|
||||
{
|
||||
std::string wkt_in_;
|
||||
mapnik::box2d<double> extent_;
|
||||
std::string expected_;
|
||||
public:
|
||||
test3(mapnik::parameters const& params,
|
||||
std::string const& wkt_in,
|
||||
mapnik::box2d<double> const& extent)
|
||||
: test_case(params),
|
||||
wkt_in_(wkt_in),
|
||||
extent_(extent),
|
||||
expected_("./benchmark/data/polygon_clipping_boost") {}
|
||||
|
||||
public:
|
||||
test3(mapnik::parameters const& params, std::string const& wkt_in, mapnik::box2d<double> const& extent)
|
||||
: test_case(params)
|
||||
, wkt_in_(wkt_in)
|
||||
, extent_(extent)
|
||||
, expected_("./benchmark/data/polygon_clipping_boost")
|
||||
{}
|
||||
bool validate() const
|
||||
{
|
||||
mapnik::geometry::geometry<double> geom;
|
||||
|
@ -234,12 +229,12 @@ public:
|
|||
std::clog << "empty geom!\n";
|
||||
return false;
|
||||
}
|
||||
if (!geom.is<mapnik::geometry::polygon<double> >())
|
||||
if (!geom.is<mapnik::geometry::polygon<double>>())
|
||||
{
|
||||
std::clog << "not a polygon!\n";
|
||||
return false;
|
||||
}
|
||||
mapnik::geometry::polygon<double> & poly = mapnik::util::get<mapnik::geometry::polygon<double> >(geom);
|
||||
mapnik::geometry::polygon<double>& poly = mapnik::util::get<mapnik::geometry::polygon<double>>(geom);
|
||||
mapnik::geometry::correct(poly);
|
||||
|
||||
mapnik::geometry::linear_ring<double> bbox;
|
||||
|
@ -249,15 +244,15 @@ public:
|
|||
bbox.emplace_back(extent_.maxx(), extent_.miny());
|
||||
bbox.emplace_back(extent_.minx(), extent_.miny());
|
||||
|
||||
std::deque<mapnik::geometry::polygon<double> > result;
|
||||
std::deque<mapnik::geometry::polygon<double>> result;
|
||||
boost::geometry::intersection(bbox, poly, result);
|
||||
|
||||
std::string expect = expected_+".png";
|
||||
std::string actual = expected_+"_actual.png";
|
||||
std::string expect = expected_ + ".png";
|
||||
std::string actual = expected_ + "_actual.png";
|
||||
mapnik::geometry::multi_polygon<double> mp;
|
||||
for (auto const& _geom: result)
|
||||
for (auto const& _geom : result)
|
||||
{
|
||||
//std::clog << boost::geometry::dsv(geom) << "\n";
|
||||
// std::clog << boost::geometry::dsv(geom) << "\n";
|
||||
mp.emplace_back(_geom);
|
||||
}
|
||||
mapnik::geometry::geometry<double> geom2(mp);
|
||||
|
@ -265,10 +260,10 @@ public:
|
|||
if (!mapnik::util::exists(expect) || (std::getenv("UPDATE") != nullptr))
|
||||
{
|
||||
std::clog << "generating expected image: " << expect << "\n";
|
||||
render(mp,env,expect);
|
||||
render(mp, env, expect);
|
||||
}
|
||||
render(mp,env,actual);
|
||||
return benchmark::compare_images(actual,expect);
|
||||
render(mp, env, actual);
|
||||
return benchmark::compare_images(actual, expect);
|
||||
}
|
||||
bool operator()() const
|
||||
{
|
||||
|
@ -282,12 +277,12 @@ public:
|
|||
std::clog << "empty geom!\n";
|
||||
return false;
|
||||
}
|
||||
if (!geom.is<mapnik::geometry::polygon<double> >())
|
||||
if (!geom.is<mapnik::geometry::polygon<double>>())
|
||||
{
|
||||
std::clog << "not a polygon!\n";
|
||||
return false;
|
||||
}
|
||||
mapnik::geometry::polygon<double> & poly = mapnik::util::get<mapnik::geometry::polygon<double> >(geom);
|
||||
mapnik::geometry::polygon<double>& poly = mapnik::util::get<mapnik::geometry::polygon<double>>(geom);
|
||||
mapnik::geometry::correct(poly);
|
||||
|
||||
mapnik::geometry::linear_ring<double> bbox;
|
||||
|
@ -298,22 +293,25 @@ public:
|
|||
bbox.emplace_back(extent_.minx(), extent_.miny());
|
||||
|
||||
bool valid = true;
|
||||
for (unsigned i=0;i<iterations_;++i)
|
||||
for (unsigned i = 0; i < iterations_; ++i)
|
||||
{
|
||||
std::deque<mapnik::geometry::polygon<double> > result;
|
||||
std::deque<mapnik::geometry::polygon<double>> result;
|
||||
boost::geometry::intersection(bbox, poly, result);
|
||||
unsigned count = 0;
|
||||
for (auto const& _geom : result)
|
||||
{
|
||||
mapnik::geometry::polygon_vertex_adapter<double> va(_geom);
|
||||
unsigned cmd;
|
||||
double x,y;
|
||||
while ((cmd = va.vertex(&x, &y)) != mapnik::SEG_END) {
|
||||
double x, y;
|
||||
while ((cmd = va.vertex(&x, &y)) != mapnik::SEG_END)
|
||||
{
|
||||
++count;
|
||||
}
|
||||
unsigned expected_count = 29;
|
||||
if (count != expected_count) {
|
||||
std::clog << "test3: clipping failed: processed " << count << " verticies but expected " << expected_count << "\n";
|
||||
if (count != expected_count)
|
||||
{
|
||||
std::clog << "test3: clipping failed: processed " << count << " verticies but expected "
|
||||
<< expected_count << "\n";
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
|
@ -500,8 +498,8 @@ public:
|
|||
}
|
||||
unsigned expected_count = 29;
|
||||
if (count != expected_count) {
|
||||
std::clog << "test3: clipping failed: processed " << count << " verticies but expected " << expected_count << "\n";
|
||||
valid = false;
|
||||
std::clog << "test3: clipping failed: processed " << count << " verticies but expected " <<
|
||||
expected_count << "\n"; valid = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -513,13 +511,16 @@ public:
|
|||
int main(int argc, char** argv)
|
||||
{
|
||||
mapnik::parameters params;
|
||||
benchmark::handle_args(argc,argv,params);
|
||||
benchmark::handle_args(argc, argv, params);
|
||||
|
||||
// polygon/rect clipping
|
||||
// IN : POLYGON ((155 203, 233 454, 315 340, 421 446, 463 324, 559 466, 665 253, 528 178, 394 229, 329 138, 212 134, 183 228, 200 264, 155 203),(313 190, 440 256, 470 248, 510 305, 533 237, 613 263, 553 397, 455 262, 405 378, 343 287, 249 334, 229 191, 313 190))
|
||||
// RECT : POLYGON ((181 106, 181 470, 631 470, 631 106, 181 106))
|
||||
// OUT (expected)
|
||||
// POLYGON ((181 286.6666666666667, 233 454, 315 340, 421 446, 463 324, 559 466, 631 321.3207547169811, 631 234.38686131386862, 528 178, 394 229, 329 138, 212 134, 183 228, 200 264, 181 238.24444444444444, 181 286.6666666666667),(313 190, 440 256, 470 248, 510 305, 533 237, 613 263, 553 397, 455 262, 405 378, 343 287, 249 334, 229 191, 313 190))
|
||||
// IN : POLYGON ((155 203, 233 454, 315 340, 421 446, 463 324, 559 466, 665 253, 528 178, 394 229, 329 138, 212 134,
|
||||
// 183 228, 200 264, 155 203),(313 190, 440 256, 470 248, 510 305, 533 237, 613 263, 553 397, 455 262, 405 378, 343
|
||||
// 287, 249 334, 229 191, 313 190)) RECT : POLYGON ((181 106, 181 470, 631 470, 631 106, 181 106)) OUT (expected)
|
||||
// POLYGON ((181 286.6666666666667, 233 454, 315 340, 421 446, 463 324, 559 466, 631 321.3207547169811, 631
|
||||
// 234.38686131386862, 528 178, 394 229, 329 138, 212 134, 183 228, 200 264, 181 238.24444444444444, 181
|
||||
// 286.6666666666667),(313 190, 440 256, 470 248, 510 305, 533 237, 613 263, 553 397, 455 262, 405 378, 343 287, 249
|
||||
// 334, 229 191, 313 190))
|
||||
#if 0
|
||||
mapnik::box2d<double> clipping_box(181,106,631,470);
|
||||
std::string filename_("./benchmark/data/polygon.wkt");
|
||||
|
@ -544,5 +545,5 @@ int main(int argc, char** argv)
|
|||
}
|
||||
*/
|
||||
#endif
|
||||
return 0;// return_value;
|
||||
return 0; // return_value;
|
||||
}
|
||||
|
|
|
@ -8,53 +8,51 @@ class test : public benchmark::test_case
|
|||
{
|
||||
std::string xml_;
|
||||
mapnik::box2d<double> extent_;
|
||||
public:
|
||||
test(mapnik::parameters const& params,
|
||||
std::string const& xml,
|
||||
mapnik::box2d<double> const& extent)
|
||||
: test_case(params),
|
||||
xml_(xml),
|
||||
extent_(extent)
|
||||
{}
|
||||
|
||||
public:
|
||||
test(mapnik::parameters const& params, std::string const& xml, mapnik::box2d<double> const& extent)
|
||||
: test_case(params)
|
||||
, xml_(xml)
|
||||
, extent_(extent)
|
||||
{}
|
||||
bool validate() const
|
||||
{
|
||||
mapnik::Map m(256,256);
|
||||
mapnik::load_map(m,xml_);
|
||||
mapnik::Map m(256, 256);
|
||||
mapnik::load_map(m, xml_);
|
||||
m.zoom_to_box(extent_);
|
||||
mapnik::image_rgba8 im(m.width(),m.height());
|
||||
mapnik::agg_renderer<mapnik::image_rgba8> ren(m,im);
|
||||
mapnik::image_rgba8 im(m.width(), m.height());
|
||||
mapnik::agg_renderer<mapnik::image_rgba8> ren(m, im);
|
||||
ren.apply();
|
||||
//mapnik::save_to_file(im.data(),"test.png");
|
||||
// mapnik::save_to_file(im.data(),"test.png");
|
||||
return true;
|
||||
}
|
||||
bool operator()() const
|
||||
{
|
||||
mapnik::Map m(256,256);
|
||||
mapnik::load_map(m,xml_);
|
||||
mapnik::Map m(256, 256);
|
||||
mapnik::load_map(m, xml_);
|
||||
m.zoom_to_box(extent_);
|
||||
for (unsigned i=0;i<iterations_;++i)
|
||||
for (unsigned i = 0; i < iterations_; ++i)
|
||||
{
|
||||
mapnik::image_rgba8 im(m.width(),m.height());
|
||||
mapnik::agg_renderer<mapnik::image_rgba8> ren(m,im);
|
||||
mapnik::image_rgba8 im(m.width(), m.height());
|
||||
mapnik::agg_renderer<mapnik::image_rgba8> ren(m, im);
|
||||
ren.apply();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
mapnik::parameters params;
|
||||
benchmark::handle_args(argc,argv,params);
|
||||
benchmark::handle_args(argc, argv, params);
|
||||
mapnik::datasource_cache::instance().register_datasources("./plugins/input/");
|
||||
mapnik::box2d<double> z1(-20037508.3428,-8317435.0606,20037508.3428,18399242.7298);
|
||||
mapnik::box2d<double> z1(-20037508.3428, -8317435.0606, 20037508.3428, 18399242.7298);
|
||||
// bbox for 16/10491/22911.png
|
||||
mapnik::box2d<double> z16(-13622912.929097254,6026906.8062295765,-13621689.93664469,6028129.79868214);
|
||||
mapnik::box2d<double> z16(-13622912.929097254, 6026906.8062295765, -13621689.93664469, 6028129.79868214);
|
||||
return benchmark::sequencer(argc, argv)
|
||||
.run<test>("polygon clip render z1", "benchmark/data/polygon_rendering_clip.xml", z1)
|
||||
.run<test>("polygon noclip render z1", "benchmark/data/polygon_rendering_no_clip.xml", z1)
|
||||
.run<test>("polygon clip render z16", "benchmark/data/polygon_rendering_clip.xml", z16)
|
||||
.run<test>("polygon noclip render z16", "benchmark/data/polygon_rendering_no_clip.xml", z16)
|
||||
.done();
|
||||
.run<test>("polygon clip render z1", "benchmark/data/polygon_rendering_clip.xml", z1)
|
||||
.run<test>("polygon noclip render z1", "benchmark/data/polygon_rendering_no_clip.xml", z1)
|
||||
.run<test>("polygon clip render z16", "benchmark/data/polygon_rendering_clip.xml", z16)
|
||||
.run<test>("polygon noclip render z16", "benchmark/data/polygon_rendering_no_clip.xml", z16)
|
||||
.done();
|
||||
}
|
||||
|
|
|
@ -10,45 +10,46 @@ class test : public benchmark::test_case
|
|||
mapnik::box2d<double> from_;
|
||||
mapnik::box2d<double> to_;
|
||||
bool defer_proj_init_;
|
||||
public:
|
||||
|
||||
public:
|
||||
test(mapnik::parameters const& params,
|
||||
std::string const& src,
|
||||
std::string const& dest,
|
||||
mapnik::box2d<double> const& from,
|
||||
mapnik::box2d<double> const& to,
|
||||
bool defer_proj)
|
||||
: test_case(params),
|
||||
src_(src),
|
||||
dest_(dest),
|
||||
from_(from),
|
||||
to_(to),
|
||||
defer_proj_init_(defer_proj) {}
|
||||
: test_case(params)
|
||||
, src_(src)
|
||||
, dest_(dest)
|
||||
, from_(from)
|
||||
, to_(to)
|
||||
, defer_proj_init_(defer_proj)
|
||||
{}
|
||||
bool validate() const
|
||||
{
|
||||
mapnik::projection src(src_,defer_proj_init_);
|
||||
mapnik::projection dest(dest_,defer_proj_init_);
|
||||
mapnik::proj_transform tr(src,dest);
|
||||
mapnik::projection src(src_, defer_proj_init_);
|
||||
mapnik::projection dest(dest_, defer_proj_init_);
|
||||
mapnik::proj_transform tr(src, dest);
|
||||
mapnik::box2d<double> bbox = from_;
|
||||
if (!tr.forward(bbox)) return false;
|
||||
return ((std::fabs(bbox.minx() - to_.minx()) < .5) &&
|
||||
(std::fabs(bbox.maxx() - to_.maxx()) < .5) &&
|
||||
(std::fabs(bbox.miny() - to_.miny()) < .5) &&
|
||||
(std::fabs(bbox.maxy() - to_.maxy()) < .5)
|
||||
);
|
||||
if (!tr.forward(bbox))
|
||||
return false;
|
||||
return ((std::fabs(bbox.minx() - to_.minx()) < .5) && (std::fabs(bbox.maxx() - to_.maxx()) < .5) &&
|
||||
(std::fabs(bbox.miny() - to_.miny()) < .5) && (std::fabs(bbox.maxy() - to_.maxy()) < .5));
|
||||
}
|
||||
bool operator()() const
|
||||
{
|
||||
mapnik::projection src(src_,defer_proj_init_);
|
||||
mapnik::projection dest(dest_,defer_proj_init_);
|
||||
mapnik::proj_transform tr(src,dest);
|
||||
for (std::size_t i=0;i<iterations_;++i)
|
||||
mapnik::projection src(src_, defer_proj_init_);
|
||||
mapnik::projection dest(dest_, defer_proj_init_);
|
||||
mapnik::proj_transform tr(src, dest);
|
||||
for (std::size_t i = 0; i < iterations_; ++i)
|
||||
{
|
||||
for (int j=-180;j<180;j=j+5)
|
||||
for (int j = -180; j < 180; j = j + 5)
|
||||
{
|
||||
for (int k=-85;k<85;k=k+5)
|
||||
for (int k = -85; k < 85; k = k + 5)
|
||||
{
|
||||
mapnik::box2d<double> box(j,k,j,k);
|
||||
if (!tr.forward(box)) throw std::runtime_error("could not transform coords");
|
||||
mapnik::box2d<double> box(j, k, j, k);
|
||||
if (!tr.forward(box))
|
||||
throw std::runtime_error("could not transform coords");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,16 +60,17 @@ public:
|
|||
// echo -180 -60 | cs2cs -f "%.10f" epsg:4326 +to epsg:3857
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
mapnik::box2d<double> from(-180,-80,180,80);
|
||||
mapnik::box2d<double> to(-20037508.3427892476,-15538711.0963092316,20037508.3427892476,15538711.0963092316);
|
||||
mapnik::box2d<double> from(-180, -80, 180, 80);
|
||||
mapnik::box2d<double> to(-20037508.3427892476, -15538711.0963092316, 20037508.3427892476, 15538711.0963092316);
|
||||
std::string from_str("epsg:4326");
|
||||
std::string to_str("epsg:3857");
|
||||
std::string from_str2("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs");
|
||||
std::string to_str2("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over");
|
||||
std::string to_str2("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m "
|
||||
"+nadgrids=@null +wktext +no_defs +over");
|
||||
return benchmark::sequencer(argc, argv)
|
||||
.run<test>("lonlat->merc epsg (internal)", from_str, to_str, from, to, true)
|
||||
.run<test>("lonlat->merc literal (libproj)", from_str2, to_str2, from, to, true)
|
||||
.run<test>("merc->lonlat epsg (internal)", to_str, from_str, to, from, true)
|
||||
.run<test>("merc->lonlat literal (libproj)", to_str2, from_str2, to, from, true)
|
||||
.done();
|
||||
.run<test>("lonlat->merc epsg (internal)", from_str, to_str, from, to, true)
|
||||
.run<test>("lonlat->merc literal (libproj)", from_str2, to_str2, from, to, true)
|
||||
.run<test>("merc->lonlat epsg (internal)", to_str, from_str, to, from, true)
|
||||
.run<test>("merc->lonlat literal (libproj)", to_str2, from_str2, to, from, true)
|
||||
.done();
|
||||
}
|
||||
|
|
|
@ -6,43 +6,41 @@ using quad_tree_type = mapnik::quad_tree<std::size_t>;
|
|||
|
||||
class test : public benchmark::test_case
|
||||
{
|
||||
public:
|
||||
public:
|
||||
test(mapnik::parameters const& params)
|
||||
: test_case(params) {}
|
||||
: test_case(params)
|
||||
{}
|
||||
|
||||
bool validate() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool validate() const { return true; }
|
||||
|
||||
bool operator()() const
|
||||
{
|
||||
std::random_device rd;
|
||||
std::default_random_engine engine(rd());
|
||||
std::uniform_int_distribution<int> uniform_dist(0, 2048);
|
||||
quad_tree_type tree(mapnik::box2d<double>(0,0,2048,2048));
|
||||
//populate
|
||||
quad_tree_type tree(mapnik::box2d<double>(0, 0, 2048, 2048));
|
||||
// populate
|
||||
for (size_t i = 0; i < iterations_; ++i)
|
||||
{
|
||||
int cx = uniform_dist(engine);
|
||||
int cy = uniform_dist(engine);
|
||||
int sx = 0.2 * uniform_dist(engine);
|
||||
int sy = 0.2 * uniform_dist(engine);
|
||||
mapnik::box2d<double> box(cx - sx,cy - sy, cx + sx, cy + sy);
|
||||
mapnik::box2d<double> box(cx - sx, cy - sy, cx + sx, cy + sy);
|
||||
tree.insert(i, box);
|
||||
}
|
||||
// bounding box query
|
||||
std::size_t count=0;
|
||||
std::size_t count = 0;
|
||||
for (size_t i = 0; i < iterations_; ++i)
|
||||
{
|
||||
int cx = uniform_dist(engine);
|
||||
int cy = uniform_dist(engine);
|
||||
int sx = 0.4 * uniform_dist(engine);
|
||||
int sy = 0.4 * uniform_dist(engine);
|
||||
mapnik::box2d<double> box(cx - sx,cy - sy, cx + sx, cy + sy);
|
||||
mapnik::box2d<double> box(cx - sx, cy - sy, cx + sx, cy + sy);
|
||||
auto itr = tree.query_in_box(box);
|
||||
auto end = tree.query_end();
|
||||
for ( ;itr != end; ++itr)
|
||||
for (; itr != end; ++itr)
|
||||
{
|
||||
++count;
|
||||
}
|
||||
|
@ -51,4 +49,4 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
BENCHMARK(test,"quad_tree creation")
|
||||
BENCHMARK(test, "quad_tree creation")
|
||||
|
|
|
@ -15,16 +15,17 @@ class test : public benchmark::test_case
|
|||
mapnik::value_integer height_;
|
||||
double scale_factor_;
|
||||
std::string preview_;
|
||||
public:
|
||||
|
||||
public:
|
||||
test(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
xml_(),
|
||||
extent_(),
|
||||
width_(*params.get<mapnik::value_integer>("width",256)),
|
||||
height_(*params.get<mapnik::value_integer>("height",256)),
|
||||
scale_factor_(*params.get<mapnik::value_double>("scale_factor",1.0)),
|
||||
preview_(*params.get<std::string>("preview",""))
|
||||
{
|
||||
: test_case(params)
|
||||
, xml_()
|
||||
, extent_()
|
||||
, width_(*params.get<mapnik::value_integer>("width", 256))
|
||||
, height_(*params.get<mapnik::value_integer>("height", 256))
|
||||
, scale_factor_(*params.get<mapnik::value_double>("scale_factor", 1.0))
|
||||
, preview_(*params.get<std::string>("preview", ""))
|
||||
{
|
||||
boost::optional<std::string> map = params.get<std::string>("map");
|
||||
if (!map)
|
||||
{
|
||||
|
@ -43,70 +44,75 @@ public:
|
|||
{
|
||||
throw std::runtime_error("please provide a --extent=<minx,miny,maxx,maxy> arg");
|
||||
}*/
|
||||
|
||||
}
|
||||
}
|
||||
bool validate() const
|
||||
{
|
||||
mapnik::Map m(width_,height_);
|
||||
mapnik::load_map(m,xml_,true);
|
||||
if (extent_.valid()) {
|
||||
mapnik::Map m(width_, height_);
|
||||
mapnik::load_map(m, xml_, true);
|
||||
if (extent_.valid())
|
||||
{
|
||||
m.zoom_to_box(extent_);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
m.zoom_all();
|
||||
}
|
||||
mapnik::image_rgba8 im(m.width(),m.height());
|
||||
mapnik::agg_renderer<mapnik::image_rgba8> ren(m,im,scale_factor_);
|
||||
mapnik::image_rgba8 im(m.width(), m.height());
|
||||
mapnik::agg_renderer<mapnik::image_rgba8> ren(m, im, scale_factor_);
|
||||
ren.apply();
|
||||
if (!preview_.empty()) {
|
||||
if (!preview_.empty())
|
||||
{
|
||||
std::clog << "preview available at " << preview_ << "\n";
|
||||
mapnik::save_to_file(im,preview_);
|
||||
mapnik::save_to_file(im, preview_);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool operator()() const
|
||||
{
|
||||
if (!preview_.empty()) {
|
||||
if (!preview_.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
mapnik::Map m(width_,height_);
|
||||
mapnik::load_map(m,xml_);
|
||||
if (extent_.valid()) {
|
||||
mapnik::Map m(width_, height_);
|
||||
mapnik::load_map(m, xml_);
|
||||
if (extent_.valid())
|
||||
{
|
||||
m.zoom_to_box(extent_);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
m.zoom_all();
|
||||
}
|
||||
for (unsigned i=0;i<iterations_;++i)
|
||||
for (unsigned i = 0; i < iterations_; ++i)
|
||||
{
|
||||
mapnik::image_rgba8 im(m.width(),m.height());
|
||||
mapnik::agg_renderer<mapnik::image_rgba8> ren(m,im,scale_factor_);
|
||||
mapnik::image_rgba8 im(m.width(), m.height());
|
||||
mapnik::agg_renderer<mapnik::image_rgba8> ren(m, im, scale_factor_);
|
||||
ren.apply();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int return_value = 0;
|
||||
try
|
||||
{
|
||||
mapnik::parameters params;
|
||||
benchmark::handle_args(argc,argv,params);
|
||||
benchmark::handle_args(argc, argv, params);
|
||||
boost::optional<std::string> name = params.get<std::string>("name");
|
||||
if (!name)
|
||||
{
|
||||
std::clog << "please provide a name for this test\n";
|
||||
return -1;
|
||||
}
|
||||
mapnik::freetype_engine::register_fonts("./fonts/",true);
|
||||
mapnik::freetype_engine::register_fonts("./fonts/", true);
|
||||
mapnik::datasource_cache::instance().register_datasources("./plugins/input/");
|
||||
{
|
||||
test test_runner(params);
|
||||
return_value = run(test_runner,*name);
|
||||
return_value = run(test_runner, *name);
|
||||
}
|
||||
}
|
||||
catch (std::exception const& ex)
|
||||
} catch (std::exception const& ex)
|
||||
{
|
||||
std::clog << ex.what() << "\n";
|
||||
return -1;
|
||||
|
|
|
@ -12,14 +12,15 @@
|
|||
#include <mapnik/datasource_cache.hpp>
|
||||
#include <stdexcept>
|
||||
|
||||
template <typename Renderer> void process_layers(Renderer & ren,
|
||||
mapnik::request const& m_req,
|
||||
mapnik::projection const& map_proj,
|
||||
std::vector<mapnik::layer> const& layers,
|
||||
double scale_denom)
|
||||
template<typename Renderer>
|
||||
void process_layers(Renderer& ren,
|
||||
mapnik::request const& m_req,
|
||||
mapnik::projection const& map_proj,
|
||||
std::vector<mapnik::layer> const& layers,
|
||||
double scale_denom)
|
||||
{
|
||||
unsigned layers_size = layers.size();
|
||||
for (unsigned i=0; i < layers_size; ++i)
|
||||
for (unsigned i = 0; i < layers_size; ++i)
|
||||
{
|
||||
mapnik::layer const& lyr = layers[i];
|
||||
if (lyr.visible(scale_denom))
|
||||
|
@ -50,17 +51,18 @@ class test : public benchmark::test_case
|
|||
double scale_factor_;
|
||||
std::string preview_;
|
||||
mutable mapnik::image_rgba8 im_;
|
||||
public:
|
||||
|
||||
public:
|
||||
test(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
xml_(),
|
||||
extent_(),
|
||||
width_(*params.get<mapnik::value_integer>("width",256)),
|
||||
height_(*params.get<mapnik::value_integer>("height",256)),
|
||||
m_(new mapnik::Map(width_,height_)),
|
||||
scale_factor_(*params.get<mapnik::value_double>("scale_factor",2.0)),
|
||||
preview_(*params.get<std::string>("preview","")),
|
||||
im_(m_->width(),m_->height())
|
||||
: test_case(params)
|
||||
, xml_()
|
||||
, extent_()
|
||||
, width_(*params.get<mapnik::value_integer>("width", 256))
|
||||
, height_(*params.get<mapnik::value_integer>("height", 256))
|
||||
, m_(new mapnik::Map(width_, height_))
|
||||
, scale_factor_(*params.get<mapnik::value_double>("scale_factor", 2.0))
|
||||
, preview_(*params.get<std::string>("preview", ""))
|
||||
, im_(m_->width(), m_->height())
|
||||
{
|
||||
boost::optional<std::string> map = params.get<std::string>("map");
|
||||
if (!map)
|
||||
|
@ -70,7 +72,7 @@ public:
|
|||
xml_ = *map;
|
||||
|
||||
boost::optional<std::string> ext = params.get<std::string>("extent");
|
||||
mapnik::load_map(*m_,xml_,true);
|
||||
mapnik::load_map(*m_, xml_, true);
|
||||
if (ext && !ext->empty())
|
||||
{
|
||||
if (!extent_.from_string(*ext))
|
||||
|
@ -87,42 +89,44 @@ public:
|
|||
|
||||
bool validate() const
|
||||
{
|
||||
mapnik::request m_req(width_,height_,extent_);
|
||||
mapnik::request m_req(width_, height_, extent_);
|
||||
mapnik::attributes variables;
|
||||
m_req.set_buffer_size(m_->buffer_size());
|
||||
mapnik::projection map_proj(m_->srs(),true);
|
||||
double scale_denom = mapnik::scale_denominator(m_req.scale(),map_proj.is_geographic());
|
||||
mapnik::projection map_proj(m_->srs(), true);
|
||||
double scale_denom = mapnik::scale_denominator(m_req.scale(), map_proj.is_geographic());
|
||||
scale_denom *= scale_factor_;
|
||||
mapnik::agg_renderer<mapnik::image_rgba8> ren(*m_,m_req,variables,im_,scale_factor_);
|
||||
mapnik::agg_renderer<mapnik::image_rgba8> ren(*m_, m_req, variables, im_, scale_factor_);
|
||||
ren.start_map_processing(*m_);
|
||||
std::vector<mapnik::layer> const& layers = m_->layers();
|
||||
process_layers(ren,m_req,map_proj,layers,scale_denom);
|
||||
process_layers(ren, m_req, map_proj, layers, scale_denom);
|
||||
ren.end_map_processing(*m_);
|
||||
if (!preview_.empty()) {
|
||||
if (!preview_.empty())
|
||||
{
|
||||
std::clog << "preview available at " << preview_ << "\n";
|
||||
mapnik::save_to_file(im_,preview_);
|
||||
mapnik::save_to_file(im_, preview_);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator()() const
|
||||
{
|
||||
if (!preview_.empty()) {
|
||||
if (!preview_.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (unsigned i=0;i<iterations_;++i)
|
||||
for (unsigned i = 0; i < iterations_; ++i)
|
||||
{
|
||||
mapnik::request m_req(width_,height_,extent_);
|
||||
mapnik::image_rgba8 im(m_->width(),m_->height());
|
||||
mapnik::request m_req(width_, height_, extent_);
|
||||
mapnik::image_rgba8 im(m_->width(), m_->height());
|
||||
mapnik::attributes variables;
|
||||
m_req.set_buffer_size(m_->buffer_size());
|
||||
mapnik::projection map_proj(m_->srs(),true);
|
||||
double scale_denom = mapnik::scale_denominator(m_req.scale(),map_proj.is_geographic());
|
||||
mapnik::projection map_proj(m_->srs(), true);
|
||||
double scale_denom = mapnik::scale_denominator(m_req.scale(), map_proj.is_geographic());
|
||||
scale_denom *= scale_factor_;
|
||||
mapnik::agg_renderer<mapnik::image_rgba8> ren(*m_,m_req,variables,im,scale_factor_);
|
||||
mapnik::agg_renderer<mapnik::image_rgba8> ren(*m_, m_req, variables, im, scale_factor_);
|
||||
ren.start_map_processing(*m_);
|
||||
std::vector<mapnik::layer> const& layers = m_->layers();
|
||||
process_layers(ren,m_req,map_proj,layers,scale_denom);
|
||||
process_layers(ren, m_req, map_proj, layers, scale_denom);
|
||||
ren.end_map_processing(*m_);
|
||||
bool diff = false;
|
||||
mapnik::image_rgba8 const& dest = im;
|
||||
|
@ -133,37 +137,37 @@ public:
|
|||
const unsigned int* row_to = dest.get_row(y);
|
||||
for (unsigned int x = 0; x < width_; ++x)
|
||||
{
|
||||
if (row_from[x] != row_to[x]) diff = true;
|
||||
if (row_from[x] != row_to[x])
|
||||
diff = true;
|
||||
}
|
||||
}
|
||||
if (diff) throw std::runtime_error("images differ");
|
||||
if (diff)
|
||||
throw std::runtime_error("images differ");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int return_value = 0;
|
||||
try
|
||||
{
|
||||
mapnik::parameters params;
|
||||
benchmark::handle_args(argc,argv,params);
|
||||
benchmark::handle_args(argc, argv, params);
|
||||
boost::optional<std::string> name = params.get<std::string>("name");
|
||||
if (!name)
|
||||
{
|
||||
std::clog << "please provide a name for this test\n";
|
||||
return -1;
|
||||
}
|
||||
mapnik::freetype_engine::register_fonts("./fonts/",true);
|
||||
mapnik::freetype_engine::register_fonts("./fonts/", true);
|
||||
mapnik::datasource_cache::instance().register_datasources("./plugins/input/");
|
||||
{
|
||||
test test_runner(params);
|
||||
return_value = run(test_runner,*name);
|
||||
return_value = run(test_runner, *name);
|
||||
}
|
||||
}
|
||||
catch (std::exception const& ex)
|
||||
} catch (std::exception const& ex)
|
||||
{
|
||||
std::clog << ex.what() << "\n";
|
||||
return -1;
|
||||
|
|
|
@ -4,27 +4,31 @@
|
|||
class test : public benchmark::test_case
|
||||
{
|
||||
std::string value_;
|
||||
public:
|
||||
|
||||
public:
|
||||
test(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
value_("true") {}
|
||||
: test_case(params)
|
||||
, value_("true")
|
||||
{}
|
||||
bool validate() const
|
||||
{
|
||||
bool result = false;
|
||||
mapnik::util::string2bool(value_.data(),value_.data()+value_.size(),result);
|
||||
if (!result) return result;
|
||||
mapnik::util::string2bool(value_,result);
|
||||
mapnik::util::string2bool(value_.data(), value_.data() + value_.size(), result);
|
||||
if (!result)
|
||||
return result;
|
||||
mapnik::util::string2bool(value_, result);
|
||||
return (result == true);
|
||||
}
|
||||
bool operator()() const
|
||||
{
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
for (std::size_t i = 0; i < iterations_; ++i)
|
||||
{
|
||||
bool result = false;
|
||||
mapnik::util::string2bool(value_,result);
|
||||
mapnik::util::string2bool(value_.data(),value_.data()+value_.size(),result);
|
||||
mapnik::util::string2bool(value_, result);
|
||||
mapnik::util::string2bool(value_.data(), value_.data() + value_.size(), result);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
BENCHMARK(test,"string->bool")
|
||||
BENCHMARK(test, "string->bool")
|
||||
|
|
|
@ -4,29 +4,36 @@
|
|||
class test : public benchmark::test_case
|
||||
{
|
||||
std::string value_;
|
||||
public:
|
||||
|
||||
public:
|
||||
test(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
value_("1.23456789") {}
|
||||
: test_case(params)
|
||||
, value_("1.23456789")
|
||||
{}
|
||||
bool validate() const
|
||||
{
|
||||
double result = 0;
|
||||
if (!mapnik::util::string2double(value_.data(),value_.data()+value_.size(),result)) return false;
|
||||
if (result != 1.23456789) return false;
|
||||
if (!mapnik::util::string2double(value_.data(), value_.data() + value_.size(), result))
|
||||
return false;
|
||||
if (result != 1.23456789)
|
||||
return false;
|
||||
result = 0;
|
||||
if (!mapnik::util::string2double(value_,result)) return false;
|
||||
if (result != 1.23456789) return false;
|
||||
if (!mapnik::util::string2double(value_, result))
|
||||
return false;
|
||||
if (result != 1.23456789)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
bool operator()() const
|
||||
{
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
for (std::size_t i = 0; i < iterations_; ++i)
|
||||
{
|
||||
double result = 0;
|
||||
mapnik::util::string2double(value_,result);
|
||||
mapnik::util::string2double(value_.data(),value_.data()+value_.size(),result);
|
||||
mapnik::util::string2double(value_, result);
|
||||
mapnik::util::string2double(value_.data(), value_.data() + value_.size(), result);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
BENCHMARK(test,"string->double")
|
||||
BENCHMARK(test, "string->double")
|
||||
|
|
|
@ -4,29 +4,36 @@
|
|||
class test : public benchmark::test_case
|
||||
{
|
||||
std::string value_;
|
||||
public:
|
||||
|
||||
public:
|
||||
test(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
value_("123456789") {}
|
||||
: test_case(params)
|
||||
, value_("123456789")
|
||||
{}
|
||||
bool validate() const
|
||||
{
|
||||
mapnik::value_integer result = 0;
|
||||
if (!mapnik::util::string2int(value_.data(),value_.data()+value_.size(),result)) return false;
|
||||
if (result != 123456789) return false;
|
||||
if (!mapnik::util::string2int(value_.data(), value_.data() + value_.size(), result))
|
||||
return false;
|
||||
if (result != 123456789)
|
||||
return false;
|
||||
result = 0;
|
||||
if (!mapnik::util::string2int(value_,result)) return false;
|
||||
if (result != 123456789) return false;
|
||||
if (!mapnik::util::string2int(value_, result))
|
||||
return false;
|
||||
if (result != 123456789)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
bool operator()() const
|
||||
{
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
for (std::size_t i = 0; i < iterations_; ++i)
|
||||
{
|
||||
mapnik::value_integer result = 0;
|
||||
mapnik::util::string2int(value_,result);
|
||||
mapnik::util::string2int(value_.data(),value_.data()+value_.size(),result);
|
||||
mapnik::util::string2int(value_, result);
|
||||
mapnik::util::string2int(value_.data(), value_.data() + value_.size(), result);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
BENCHMARK(test,"string->int")
|
||||
BENCHMARK(test, "string->int")
|
||||
|
|
|
@ -4,25 +4,28 @@
|
|||
class test : public benchmark::test_case
|
||||
{
|
||||
double value_;
|
||||
public:
|
||||
|
||||
public:
|
||||
test(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
value_(-0.1234) {}
|
||||
: test_case(params)
|
||||
, value_(-0.1234)
|
||||
{}
|
||||
bool validate() const
|
||||
{
|
||||
std::string s;
|
||||
mapnik::util::to_string(s,value_);
|
||||
mapnik::util::to_string(s, value_);
|
||||
return (s == "-0.1234");
|
||||
}
|
||||
bool operator()() const
|
||||
{
|
||||
std::string out;
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
for (std::size_t i = 0; i < iterations_; ++i)
|
||||
{
|
||||
out.clear();
|
||||
mapnik::util::to_string(out,value_);
|
||||
mapnik::util::to_string(out, value_);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
BENCHMARK(test,"to_string double->string")
|
||||
BENCHMARK(test, "to_string double->string")
|
||||
|
|
|
@ -4,10 +4,12 @@
|
|||
class test : public benchmark::test_case
|
||||
{
|
||||
double value_;
|
||||
public:
|
||||
|
||||
public:
|
||||
test(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
value_(-0.1234) {}
|
||||
: test_case(params)
|
||||
, value_(-0.1234)
|
||||
{}
|
||||
bool validate() const
|
||||
{
|
||||
std::ostringstream s;
|
||||
|
@ -17,7 +19,8 @@ public:
|
|||
bool operator()() const
|
||||
{
|
||||
std::string out;
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
for (std::size_t i = 0; i < iterations_; ++i)
|
||||
{
|
||||
std::ostringstream s;
|
||||
s << value_;
|
||||
out = s.str();
|
||||
|
@ -26,4 +29,4 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
BENCHMARK(test,"ostringstream double->string")
|
||||
BENCHMARK(test, "ostringstream double->string")
|
||||
|
|
|
@ -13,27 +13,29 @@ using mapnik::util::from_u8string;
|
|||
class test : public benchmark::test_case
|
||||
{
|
||||
std::string utf8_;
|
||||
public:
|
||||
|
||||
public:
|
||||
test(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
utf8_(from_u8string(u8"שלום")) {}
|
||||
: test_case(params)
|
||||
, utf8_(from_u8string(u8"שלום"))
|
||||
{}
|
||||
bool validate() const
|
||||
{
|
||||
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> utf32conv;
|
||||
std::u32string utf32 = utf32conv.from_bytes(utf8_);
|
||||
if (utf32.size() != 4) return false;
|
||||
if (utf32[0] != 0x5e9 &&
|
||||
utf32[1] != 0x5dc &&
|
||||
utf32[2] != 0x5d5 &&
|
||||
utf32[3] != 0x5dd) return false;
|
||||
if (utf32.size() != 4)
|
||||
return false;
|
||||
if (utf32[0] != 0x5e9 && utf32[1] != 0x5dc && utf32[2] != 0x5d5 && utf32[3] != 0x5dd)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
bool operator()() const
|
||||
{
|
||||
std::u32string utf32;
|
||||
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> utf32conv;
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
utf32 = utf32conv.from_bytes(utf8_);
|
||||
for (std::size_t i = 0; i < iterations_; ++i)
|
||||
{
|
||||
utf32 = utf32conv.from_bytes(utf8_);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -44,26 +46,28 @@ public:
|
|||
class test2 : public benchmark::test_case
|
||||
{
|
||||
std::string utf8_;
|
||||
public:
|
||||
|
||||
public:
|
||||
test2(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
utf8_(from_u8string(u8"שלום")) {}
|
||||
: test_case(params)
|
||||
, utf8_(from_u8string(u8"שלום"))
|
||||
{}
|
||||
bool validate() const
|
||||
{
|
||||
std::u32string utf32 = boost::locale::conv::utf_to_utf<char32_t>(utf8_);
|
||||
if (utf32.size() != 4) return false;
|
||||
if (utf32[0] != 0x5e9 &&
|
||||
utf32[1] != 0x5dc &&
|
||||
utf32[2] != 0x5d5 &&
|
||||
utf32[3] != 0x5dd) return false;
|
||||
if (utf32.size() != 4)
|
||||
return false;
|
||||
if (utf32[0] != 0x5e9 && utf32[1] != 0x5dc && utf32[2] != 0x5d5 && utf32[3] != 0x5dd)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
bool operator()() const
|
||||
{
|
||||
std::u32string utf32;
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
utf32 = boost::locale::conv::utf_to_utf<char32_t>(utf8_);
|
||||
}
|
||||
std::u32string utf32;
|
||||
for (std::size_t i = 0; i < iterations_; ++i)
|
||||
{
|
||||
utf32 = boost::locale::conv::utf_to_utf<char32_t>(utf8_);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
@ -71,28 +75,30 @@ public:
|
|||
class test3 : public benchmark::test_case
|
||||
{
|
||||
std::string utf8_;
|
||||
public:
|
||||
|
||||
public:
|
||||
test3(mapnik::parameters const& params)
|
||||
: test_case(params),
|
||||
utf8_(from_u8string(u8"שלום")) {}
|
||||
: test_case(params)
|
||||
, utf8_(from_u8string(u8"שלום"))
|
||||
{}
|
||||
bool validate() const
|
||||
{
|
||||
mapnik::transcoder tr_("utf-8");
|
||||
mapnik::value_unicode_string utf32 = tr_.transcode(utf8_.data(),utf8_.size());
|
||||
//std::u32string utf32 = boost::locale::conv::utf_to_utf<char32_t>(utf8_);
|
||||
if (utf32.length() != 4) return false;
|
||||
if (utf32[0] != 0x5e9 &&
|
||||
utf32[1] != 0x5dc &&
|
||||
utf32[2] != 0x5d5 &&
|
||||
utf32[3] != 0x5dd) return false;
|
||||
mapnik::value_unicode_string utf32 = tr_.transcode(utf8_.data(), utf8_.size());
|
||||
// std::u32string utf32 = boost::locale::conv::utf_to_utf<char32_t>(utf8_);
|
||||
if (utf32.length() != 4)
|
||||
return false;
|
||||
if (utf32[0] != 0x5e9 && utf32[1] != 0x5dc && utf32[2] != 0x5d5 && utf32[3] != 0x5dd)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
bool operator()() const
|
||||
{
|
||||
mapnik::transcoder tr_("utf-8");
|
||||
mapnik::value_unicode_string utf32;
|
||||
for (std::size_t i=0;i<iterations_;++i) {
|
||||
utf32 = tr_.transcode(utf8_.data(),utf8_.size());
|
||||
for (std::size_t i = 0; i < iterations_; ++i)
|
||||
{
|
||||
utf32 = tr_.transcode(utf8_.data(), utf8_.size());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -101,17 +107,17 @@ public:
|
|||
int main(int argc, char** argv)
|
||||
{
|
||||
mapnik::parameters params;
|
||||
benchmark::handle_args(argc,argv,params);
|
||||
benchmark::handle_args(argc, argv, params);
|
||||
int return_value = 0;
|
||||
#ifndef __linux__
|
||||
test test_runner(params);
|
||||
return_value = return_value | run(test_runner,"utf encode std::codecvt");
|
||||
return_value = return_value | run(test_runner, "utf encode std::codecvt");
|
||||
#else
|
||||
std::clog << "skipping 'utf encode std::codecvt' test since <codecvt> is not supported on __linux__\n";
|
||||
#endif
|
||||
test2 test_runner2(params);
|
||||
return_value = return_value | run(test_runner2,"utf encode boost::locale");
|
||||
return_value = return_value | run(test_runner2, "utf encode boost::locale");
|
||||
test3 test_runner3(params);
|
||||
return_value = return_value | run(test_runner3,"utf encode ICU");
|
||||
return_value = return_value | run(test_runner3, "utf encode ICU");
|
||||
return return_value;
|
||||
}
|
||||
|
|
|
@ -2,16 +2,12 @@
|
|||
|
||||
class test : public benchmark::test_case
|
||||
{
|
||||
public:
|
||||
public:
|
||||
test(mapnik::parameters const& params)
|
||||
: test_case(params) {}
|
||||
bool validate() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
void operator()() const
|
||||
{
|
||||
}
|
||||
: test_case(params)
|
||||
{}
|
||||
bool validate() const { return true; }
|
||||
void operator()() const {}
|
||||
};
|
||||
|
||||
BENCHMARK(test,"test name")
|
||||
BENCHMARK(test, "test name")
|
||||
|
|
16
cmake/clang-format.cmake
Normal file
16
cmake/clang-format.cmake
Normal file
|
@ -0,0 +1,16 @@
|
|||
function(format_dir dir)
|
||||
file(GLOB_RECURSE sources
|
||||
"${dir}/*.cpp"
|
||||
"${dir}/*.hpp"
|
||||
)
|
||||
execute_process(COMMAND clang-format -style=file -i ${sources})
|
||||
endfunction()
|
||||
|
||||
|
||||
format_dir(benchmark)
|
||||
format_dir(demo)
|
||||
format_dir(include)
|
||||
format_dir(plugins)
|
||||
format_dir(src)
|
||||
format_dir(test)
|
||||
format_dir(utils)
|
|
@ -45,19 +45,21 @@
|
|||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
int main ( int, char** )
|
||||
int main(int, char**)
|
||||
{
|
||||
using namespace mapnik;
|
||||
const std::string srs_lcc="+proj=lcc +ellps=GRS80 +lat_0=49 +lon_0=-95 +lat+1=49 +lat_2=77 +datum=NAD83 +units=m +no_defs";
|
||||
const std::string srs_merc="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over";
|
||||
const std::string srs_lcc =
|
||||
"+proj=lcc +ellps=GRS80 +lat_0=49 +lon_0=-95 +lat+1=49 +lat_2=77 +datum=NAD83 +units=m +no_defs";
|
||||
const std::string srs_merc = "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 "
|
||||
"+units=m +nadgrids=@null +wktext +no_defs +over";
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
std::cout << " running demo ... \n";
|
||||
datasource_cache::instance().register_datasources("plugins/input/");
|
||||
freetype_engine::register_font("fonts/dejavu-fonts-ttf-2.37/ttf/DejaVuSans.ttf");
|
||||
|
||||
Map m(800,600);
|
||||
Map m(800, 600);
|
||||
m.set_background(parse_color("white"));
|
||||
m.set_srs(srs_merc);
|
||||
// create styles
|
||||
|
@ -93,13 +95,13 @@ int main ( int, char** )
|
|||
rule r;
|
||||
{
|
||||
line_symbolizer line_sym;
|
||||
put(line_sym,keys::stroke,color(0,0,0));
|
||||
put(line_sym,keys::stroke_width,1.0);
|
||||
put(line_sym, keys::stroke, color(0, 0, 0));
|
||||
put(line_sym, keys::stroke_width, 1.0);
|
||||
dash_array dash;
|
||||
dash.emplace_back(8,4);
|
||||
dash.emplace_back(2,2);
|
||||
dash.emplace_back(2,2);
|
||||
put(line_sym,keys::stroke_dasharray,dash);
|
||||
dash.emplace_back(8, 4);
|
||||
dash.emplace_back(2, 2);
|
||||
dash.emplace_back(2, 2);
|
||||
put(line_sym, keys::stroke_dasharray, dash);
|
||||
r.append(std::move(line_sym));
|
||||
}
|
||||
provlines_style.add_rule(std::move(r));
|
||||
|
@ -127,10 +129,10 @@ int main ( int, char** )
|
|||
r.set_filter(parse_expression("[CLASS] = 3 or [CLASS] = 4"));
|
||||
{
|
||||
line_symbolizer line_sym;
|
||||
put(line_sym,keys::stroke,color(171,158,137));
|
||||
put(line_sym,keys::stroke_width,2.0);
|
||||
put(line_sym,keys::stroke_linecap,ROUND_CAP);
|
||||
put(line_sym,keys::stroke_linejoin,ROUND_JOIN);
|
||||
put(line_sym, keys::stroke, color(171, 158, 137));
|
||||
put(line_sym, keys::stroke_width, 2.0);
|
||||
put(line_sym, keys::stroke_linecap, ROUND_CAP);
|
||||
put(line_sym, keys::stroke_linejoin, ROUND_JOIN);
|
||||
r.append(std::move(line_sym));
|
||||
}
|
||||
roads34_style.add_rule(std::move(r));
|
||||
|
@ -144,10 +146,10 @@ int main ( int, char** )
|
|||
r.set_filter(parse_expression("[CLASS] = 2"));
|
||||
{
|
||||
line_symbolizer line_sym;
|
||||
put(line_sym,keys::stroke,color(171,158,137));
|
||||
put(line_sym,keys::stroke_width,4.0);
|
||||
put(line_sym,keys::stroke_linecap,ROUND_CAP);
|
||||
put(line_sym,keys::stroke_linejoin,ROUND_JOIN);
|
||||
put(line_sym, keys::stroke, color(171, 158, 137));
|
||||
put(line_sym, keys::stroke_width, 4.0);
|
||||
put(line_sym, keys::stroke_linecap, ROUND_CAP);
|
||||
put(line_sym, keys::stroke_linejoin, ROUND_JOIN);
|
||||
r.append(std::move(line_sym));
|
||||
}
|
||||
roads2_style_1.add_rule(std::move(r));
|
||||
|
@ -160,10 +162,10 @@ int main ( int, char** )
|
|||
r.set_filter(parse_expression("[CLASS] = 2"));
|
||||
{
|
||||
line_symbolizer line_sym;
|
||||
put(line_sym,keys::stroke,color(255,250,115));
|
||||
put(line_sym,keys::stroke_width,2.0);
|
||||
put(line_sym,keys::stroke_linecap,ROUND_CAP);
|
||||
put(line_sym,keys::stroke_linejoin,ROUND_JOIN);
|
||||
put(line_sym, keys::stroke, color(255, 250, 115));
|
||||
put(line_sym, keys::stroke_width, 2.0);
|
||||
put(line_sym, keys::stroke_linecap, ROUND_CAP);
|
||||
put(line_sym, keys::stroke_linejoin, ROUND_JOIN);
|
||||
r.append(std::move(line_sym));
|
||||
}
|
||||
roads2_style_2.add_rule(std::move(r));
|
||||
|
@ -177,10 +179,10 @@ int main ( int, char** )
|
|||
r.set_filter(parse_expression("[CLASS] = 1"));
|
||||
{
|
||||
line_symbolizer line_sym;
|
||||
put(line_sym,keys::stroke,color(188,149,28));
|
||||
put(line_sym,keys::stroke_width,7.0);
|
||||
put(line_sym,keys::stroke_linecap,ROUND_CAP);
|
||||
put(line_sym,keys::stroke_linejoin,ROUND_JOIN);
|
||||
put(line_sym, keys::stroke, color(188, 149, 28));
|
||||
put(line_sym, keys::stroke_width, 7.0);
|
||||
put(line_sym, keys::stroke_linecap, ROUND_CAP);
|
||||
put(line_sym, keys::stroke_linejoin, ROUND_JOIN);
|
||||
r.append(std::move(line_sym));
|
||||
}
|
||||
roads1_style_1.add_rule(std::move(r));
|
||||
|
@ -193,10 +195,10 @@ int main ( int, char** )
|
|||
r.set_filter(parse_expression("[CLASS] = 1"));
|
||||
{
|
||||
line_symbolizer line_sym;
|
||||
put(line_sym,keys::stroke,color(242,191,36));
|
||||
put(line_sym,keys::stroke_width,5.0);
|
||||
put(line_sym,keys::stroke_linecap,ROUND_CAP);
|
||||
put(line_sym,keys::stroke_linejoin,ROUND_JOIN);
|
||||
put(line_sym, keys::stroke, color(242, 191, 36));
|
||||
put(line_sym, keys::stroke_width, 5.0);
|
||||
put(line_sym, keys::stroke_linecap, ROUND_CAP);
|
||||
put(line_sym, keys::stroke_linejoin, ROUND_JOIN);
|
||||
r.append(std::move(line_sym));
|
||||
}
|
||||
roads1_style_2.add_rule(std::move(r));
|
||||
|
@ -212,10 +214,11 @@ int main ( int, char** )
|
|||
text_placements_ptr placement_finder = std::make_shared<text_placements_dummy>();
|
||||
placement_finder->defaults.format_defaults.face_name = "DejaVu Sans Book";
|
||||
placement_finder->defaults.format_defaults.text_size = 10.0;
|
||||
placement_finder->defaults.format_defaults.fill = color(0,0,0);
|
||||
placement_finder->defaults.format_defaults.halo_fill = color(255,255,200);
|
||||
placement_finder->defaults.format_defaults.fill = color(0, 0, 0);
|
||||
placement_finder->defaults.format_defaults.halo_fill = color(255, 255, 200);
|
||||
placement_finder->defaults.format_defaults.halo_radius = 1.0;
|
||||
placement_finder->defaults.set_format_tree(std::make_shared<mapnik::formatting::text_node>(parse_expression("[GEONAME]")));
|
||||
placement_finder->defaults.set_format_tree(
|
||||
std::make_shared<mapnik::formatting::text_node>(parse_expression("[GEONAME]")));
|
||||
put<text_placements_ptr>(text_sym, keys::text_placements_, placement_finder);
|
||||
r.append(std::move(text_sym));
|
||||
}
|
||||
|
@ -228,9 +231,9 @@ int main ( int, char** )
|
|||
// Provincial polygons
|
||||
{
|
||||
parameters p;
|
||||
p["type"]="shape";
|
||||
p["file"]="demo/data/boundaries";
|
||||
p["encoding"]="utf8";
|
||||
p["type"] = "shape";
|
||||
p["file"] = "demo/data/boundaries";
|
||||
p["encoding"] = "utf8";
|
||||
|
||||
layer lyr("Provinces");
|
||||
lyr.set_datasource(datasource_cache::instance().create(p));
|
||||
|
@ -242,8 +245,8 @@ int main ( int, char** )
|
|||
// Drainage
|
||||
{
|
||||
parameters p;
|
||||
p["type"]="shape";
|
||||
p["file"]="demo/data/qcdrainage";
|
||||
p["type"] = "shape";
|
||||
p["file"] = "demo/data/qcdrainage";
|
||||
layer lyr("Quebec Hydrography");
|
||||
lyr.set_datasource(datasource_cache::instance().create(p));
|
||||
lyr.set_srs(srs_lcc);
|
||||
|
@ -253,8 +256,8 @@ int main ( int, char** )
|
|||
|
||||
{
|
||||
parameters p;
|
||||
p["type"]="shape";
|
||||
p["file"]="demo/data/ontdrainage";
|
||||
p["type"] = "shape";
|
||||
p["file"] = "demo/data/ontdrainage";
|
||||
layer lyr("Ontario Hydrography");
|
||||
lyr.set_datasource(datasource_cache::instance().create(p));
|
||||
lyr.set_srs(srs_lcc);
|
||||
|
@ -265,8 +268,8 @@ int main ( int, char** )
|
|||
// Provincial boundaries
|
||||
{
|
||||
parameters p;
|
||||
p["type"]="shape";
|
||||
p["file"]="demo/data/boundaries_l";
|
||||
p["type"] = "shape";
|
||||
p["file"] = "demo/data/boundaries_l";
|
||||
layer lyr("Provincial borders");
|
||||
lyr.set_srs(srs_lcc);
|
||||
lyr.set_datasource(datasource_cache::instance().create(p));
|
||||
|
@ -277,8 +280,8 @@ int main ( int, char** )
|
|||
// Roads
|
||||
{
|
||||
parameters p;
|
||||
p["type"]="shape";
|
||||
p["file"]="demo/data/roads";
|
||||
p["type"] = "shape";
|
||||
p["file"] = "demo/data/roads";
|
||||
layer lyr("Roads");
|
||||
lyr.set_srs(srs_lcc);
|
||||
lyr.set_datasource(datasource_cache::instance().create(p));
|
||||
|
@ -293,8 +296,8 @@ int main ( int, char** )
|
|||
// popplaces
|
||||
{
|
||||
parameters p;
|
||||
p["type"]="shape";
|
||||
p["file"]="demo/data/popplaces";
|
||||
p["type"] = "shape";
|
||||
p["file"] = "demo/data/popplaces";
|
||||
p["encoding"] = "utf8";
|
||||
layer lyr("Populated Places");
|
||||
lyr.set_srs(srs_lcc);
|
||||
|
@ -303,28 +306,28 @@ int main ( int, char** )
|
|||
m.add_layer(lyr);
|
||||
}
|
||||
|
||||
m.zoom_to_box(box2d<double>(-8024477.28459,5445190.38849,-7381388.20071,5662941.44855));
|
||||
m.zoom_to_box(box2d<double>(-8024477.28459, 5445190.38849, -7381388.20071, 5662941.44855));
|
||||
|
||||
image_rgba8 buf(m.width(),m.height());
|
||||
agg_renderer<image_rgba8> ren(m,buf);
|
||||
image_rgba8 buf(m.width(), m.height());
|
||||
agg_renderer<image_rgba8> ren(m, buf);
|
||||
ren.apply();
|
||||
std::string msg("These maps have been rendered using AGG in the current directory:\n");
|
||||
#ifdef HAVE_JPEG
|
||||
save_to_file(buf,"demo.jpg","jpeg");
|
||||
save_to_file(buf, "demo.jpg", "jpeg");
|
||||
msg += "- demo.jpg\n";
|
||||
#endif
|
||||
#ifdef HAVE_PNG
|
||||
save_to_file(buf,"demo.png","png");
|
||||
save_to_file(buf,"demo256.png","png8");
|
||||
save_to_file(buf, "demo.png", "png");
|
||||
save_to_file(buf, "demo256.png", "png8");
|
||||
msg += "- demo.png\n";
|
||||
msg += "- demo256.png\n";
|
||||
#endif
|
||||
#ifdef HAVE_TIFF
|
||||
save_to_file(buf,"demo.tif","tiff");
|
||||
save_to_file(buf, "demo.tif", "tiff");
|
||||
msg += "- demo.tif\n";
|
||||
#endif
|
||||
#ifdef HAVE_WEBP
|
||||
save_to_file(buf,"demo.webp","webp");
|
||||
save_to_file(buf, "demo.webp", "webp");
|
||||
msg += "- demo.webp\n";
|
||||
#endif
|
||||
msg += "Have a look!\n";
|
||||
|
@ -332,8 +335,8 @@ int main ( int, char** )
|
|||
|
||||
#if defined(HAVE_CAIRO)
|
||||
// save to pdf/svg files
|
||||
save_to_cairo_file(m,"cairo-demo.pdf");
|
||||
save_to_cairo_file(m,"cairo-demo.svg");
|
||||
save_to_cairo_file(m, "cairo-demo.pdf");
|
||||
save_to_cairo_file(m, "cairo-demo.svg");
|
||||
|
||||
/* we could also do:
|
||||
|
||||
|
@ -342,38 +345,36 @@ int main ( int, char** )
|
|||
but instead let's build up a surface for more flexibility
|
||||
*/
|
||||
|
||||
cairo_surface_ptr image_surface(
|
||||
cairo_image_surface_create(CAIRO_FORMAT_ARGB32,m.width(),m.height()),
|
||||
cairo_surface_closer());
|
||||
cairo_surface_ptr image_surface(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, m.width(), m.height()),
|
||||
cairo_surface_closer());
|
||||
double scale_factor = 1.0;
|
||||
cairo_ptr image_context(create_context(image_surface));
|
||||
mapnik::cairo_renderer<cairo_ptr> png_render(m,image_context,scale_factor);
|
||||
mapnik::cairo_renderer<cairo_ptr> png_render(m, image_context, scale_factor);
|
||||
png_render.apply();
|
||||
// we can now write to png with cairo functionality
|
||||
cairo_surface_write_to_png(&*image_surface, "cairo-demo.png");
|
||||
// but we can also benefit from quantization by converting
|
||||
// to a mapnik image object and then saving that
|
||||
mapnik::image_rgba8 im_data(cairo_image_surface_get_width(&*image_surface), cairo_image_surface_get_height(&*image_surface));
|
||||
mapnik::image_rgba8 im_data(cairo_image_surface_get_width(&*image_surface),
|
||||
cairo_image_surface_get_height(&*image_surface));
|
||||
cairo_image_to_rgba8(im_data, image_surface);
|
||||
save_to_file(im_data, "cairo-demo256.png","png8");
|
||||
save_to_file(im_data, "cairo-demo256.png", "png8");
|
||||
cairo_surface_finish(&*image_surface);
|
||||
|
||||
std::cout << "Three maps have been rendered using Cairo in the current directory:\n"
|
||||
"- cairo-demo.png\n"
|
||||
"- cairo-demo256.png\n"
|
||||
"- cairo-demo.pdf\n"
|
||||
"- cairo-demo.svg\n"
|
||||
"Have a look!\n";
|
||||
"- cairo-demo.png\n"
|
||||
"- cairo-demo256.png\n"
|
||||
"- cairo-demo.pdf\n"
|
||||
"- cairo-demo.svg\n"
|
||||
"Have a look!\n";
|
||||
#endif
|
||||
// save map definition (data + style)
|
||||
save_map(m, "map.xml");
|
||||
}
|
||||
catch ( std::exception const& ex )
|
||||
} catch (std::exception const& ex)
|
||||
{
|
||||
std::cerr << "### std::exception: " << ex.what() << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
catch ( ... )
|
||||
} catch (...)
|
||||
{
|
||||
std::cerr << "### Unknown exception." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
|
|
|
@ -17,12 +17,10 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#include "about_dialog.hpp"
|
||||
|
||||
|
||||
about_dialog::about_dialog(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
about_dialog::about_dialog(QWidget* parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
ui.setupUi(this);
|
||||
}
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#if !defined ABOUT_DIALOG_HPP
|
||||
#define ABOUT_DIALOG_HPP
|
||||
|
||||
|
@ -27,12 +25,12 @@
|
|||
|
||||
class about_dialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
about_dialog(QWidget * parent = 0);
|
||||
private:
|
||||
Ui::Dialog ui;
|
||||
Q_OBJECT
|
||||
public:
|
||||
about_dialog(QWidget* parent = 0);
|
||||
|
||||
private:
|
||||
Ui::Dialog ui;
|
||||
};
|
||||
|
||||
|
||||
#endif //ABOUT_DIALOG_HPP
|
||||
#endif // ABOUT_DIALOG_HPP
|
||||
|
|
|
@ -17,24 +17,22 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#include "info_dialog.hpp"
|
||||
|
||||
|
||||
info_dialog::info_dialog(QVector<QPair<QString,QString> > const& info, QWidget *parent)
|
||||
: QDialog(parent)
|
||||
info_dialog::info_dialog(QVector<QPair<QString, QString>> const& info, QWidget* parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
ui.tableWidget->setHorizontalHeaderItem(0,new QTableWidgetItem("Name"));
|
||||
ui.tableWidget->setHorizontalHeaderItem(1,new QTableWidgetItem("Value"));
|
||||
ui.setupUi(this);
|
||||
ui.tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem("Name"));
|
||||
ui.tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem("Value"));
|
||||
|
||||
ui.tableWidget->setRowCount(info.size());
|
||||
ui.tableWidget->setColumnCount(2);
|
||||
for (int i=0;i<info.size();++i)
|
||||
{
|
||||
QTableWidgetItem *keyItem = new QTableWidgetItem(info[i].first);
|
||||
QTableWidgetItem *valueItem = new QTableWidgetItem(info[i].second);
|
||||
ui.tableWidget->setItem(i,0,keyItem);
|
||||
ui.tableWidget->setItem(i,1,valueItem);
|
||||
}
|
||||
ui.tableWidget->setRowCount(info.size());
|
||||
ui.tableWidget->setColumnCount(2);
|
||||
for (int i = 0; i < info.size(); ++i)
|
||||
{
|
||||
QTableWidgetItem* keyItem = new QTableWidgetItem(info[i].first);
|
||||
QTableWidgetItem* valueItem = new QTableWidgetItem(info[i].second);
|
||||
ui.tableWidget->setItem(i, 0, keyItem);
|
||||
ui.tableWidget->setItem(i, 1, valueItem);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef INFO_DIALOG_HPP
|
||||
#define INFO_DIALOG_HPP
|
||||
|
||||
|
@ -27,12 +25,12 @@
|
|||
|
||||
class info_dialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
info_dialog(QVector<QPair<QString,QString> > const& info,QWidget * parent = 0);
|
||||
private:
|
||||
Ui::InfoDialog ui;
|
||||
info_dialog(QVector<QPair<QString, QString>> const& info, QWidget* parent = 0);
|
||||
|
||||
private:
|
||||
Ui::InfoDialog ui;
|
||||
};
|
||||
|
||||
|
||||
#endif //INFO_DIALOG_HPP
|
||||
#endif // INFO_DIALOG_HPP
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#include "layer_info_dialog.hpp"
|
||||
|
||||
// mapnik
|
||||
|
@ -26,14 +25,13 @@
|
|||
#include <mapnik/params_impl.hpp>
|
||||
#include <mapnik/layer.hpp>
|
||||
|
||||
|
||||
layer_info_dialog::layer_info_dialog(mapnik::layer& lay, QWidget *parent)
|
||||
: QDialog(parent)
|
||||
layer_info_dialog::layer_info_dialog(mapnik::layer& lay, QWidget* parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
|
||||
ui.tableWidget->setHorizontalHeaderItem(0,new QTableWidgetItem("Name"));
|
||||
ui.tableWidget->setHorizontalHeaderItem(1,new QTableWidgetItem("Value"));
|
||||
ui.tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem("Name"));
|
||||
ui.tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem("Value"));
|
||||
|
||||
// Layer name
|
||||
ui.layerNameEdit->setText(QString(lay.name().c_str()));
|
||||
|
@ -50,17 +48,17 @@ layer_info_dialog::layer_info_dialog(mapnik::layer& lay, QWidget *parent)
|
|||
ui.tableWidget->setColumnCount(2);
|
||||
|
||||
mapnik::parameters::const_iterator pos;
|
||||
int index=0;
|
||||
for (pos = ps.begin();pos != ps.end();++pos)
|
||||
int index = 0;
|
||||
for (pos = ps.begin(); pos != ps.end(); ++pos)
|
||||
{
|
||||
boost::optional<std::string> result;
|
||||
mapnik::util::apply_visitor(mapnik::value_extractor_visitor<std::string>(result),pos->second);
|
||||
mapnik::util::apply_visitor(mapnik::value_extractor_visitor<std::string>(result), pos->second);
|
||||
if (result)
|
||||
{
|
||||
QTableWidgetItem *keyItem = new QTableWidgetItem(QString(pos->first.c_str()));
|
||||
QTableWidgetItem *valueItem = new QTableWidgetItem(QString((*result).c_str()));
|
||||
ui.tableWidget->setItem(index,0,keyItem);
|
||||
ui.tableWidget->setItem(index,1,valueItem);
|
||||
QTableWidgetItem* keyItem = new QTableWidgetItem(QString(pos->first.c_str()));
|
||||
QTableWidgetItem* valueItem = new QTableWidgetItem(QString((*result).c_str()));
|
||||
ui.tableWidget->setItem(index, 0, keyItem);
|
||||
ui.tableWidget->setItem(index, 1, valueItem);
|
||||
++index;
|
||||
}
|
||||
}
|
||||
|
@ -69,5 +67,5 @@ layer_info_dialog::layer_info_dialog(mapnik::layer& lay, QWidget *parent)
|
|||
|
||||
Ui::LayerInfoDialog& layer_info_dialog::getUI()
|
||||
{
|
||||
return ui;
|
||||
return ui;
|
||||
}
|
||||
|
|
|
@ -17,28 +17,25 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef LAYER_INFO_DIALOG_HPP
|
||||
#define LAYER_INFO_DIALOG_HPP
|
||||
|
||||
#include "ui_layer_info.h"
|
||||
#include <QDialog>
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
namespace mapnik {
|
||||
class layer;
|
||||
}
|
||||
|
||||
class layer_info_dialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
layer_info_dialog(mapnik::layer& l, QWidget * parent = 0);
|
||||
layer_info_dialog(mapnik::layer& l, QWidget* parent = 0);
|
||||
Ui::LayerInfoDialog& getUI();
|
||||
private:
|
||||
Ui::LayerInfoDialog ui;
|
||||
|
||||
private:
|
||||
Ui::LayerInfoDialog ui;
|
||||
};
|
||||
|
||||
|
||||
#endif //LAYER_INFO_DIALOG_HPP
|
||||
#endif // LAYER_INFO_DIALOG_HPP
|
||||
|
|
|
@ -17,38 +17,32 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#include <QtGui>
|
||||
#include "layerdelegate.hpp"
|
||||
|
||||
LayerDelegate::LayerDelegate(QObject *parent)
|
||||
LayerDelegate::LayerDelegate(QObject* parent)
|
||||
: QAbstractItemDelegate(parent)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
void LayerDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const
|
||||
void LayerDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
painter->setPen(QPen(QColor(255,0,0),1));
|
||||
painter->setPen(QPen(QColor(255, 0, 0), 1));
|
||||
|
||||
if (option.state & QStyle::State_Selected)
|
||||
painter->setBrush(QBrush(QColor(0, 0, 255, 64)));
|
||||
else
|
||||
painter->setBrush(QBrush(QColor(255, 0, 0, 64)));
|
||||
|
||||
|
||||
painter->drawRoundedRect(option.rect,4,4);
|
||||
painter->drawRoundedRect(option.rect, 4, 4);
|
||||
|
||||
if (option.state & QStyle::State_Selected)
|
||||
painter->setBrush(option.palette.highlightedText());
|
||||
else
|
||||
painter->setBrush(QBrush(QColor(255, 120, 0, 127)));
|
||||
|
||||
}
|
||||
|
||||
QSize LayerDelegate::sizeHint(const QStyleOptionViewItem & /* option */,
|
||||
const QModelIndex & /* index */) const
|
||||
QSize LayerDelegate::sizeHint(const QStyleOptionViewItem& /* option */, const QModelIndex& /* index */) const
|
||||
{
|
||||
return QSize(120,24);
|
||||
return QSize(120, 24);
|
||||
}
|
||||
|
|
|
@ -33,12 +33,10 @@ class LayerDelegate : public QAbstractItemDelegate
|
|||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
LayerDelegate(QObject *parent = 0);
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const;
|
||||
QSize sizeHint(const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index ) const;
|
||||
public:
|
||||
LayerDelegate(QObject* parent = 0);
|
||||
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
||||
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
||||
};
|
||||
|
||||
#endif //LAYER_DELEGATE_HPP
|
||||
#endif // LAYER_DELEGATE_HPP
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "layerlistmodel.hpp"
|
||||
#include <QIcon>
|
||||
#include <QBrush>
|
||||
|
@ -26,14 +24,16 @@
|
|||
|
||||
using mapnik::Map;
|
||||
|
||||
LayerListModel::LayerListModel(std::shared_ptr<Map> map, QObject *parent)
|
||||
: QAbstractListModel(parent),
|
||||
map_(map) {}
|
||||
LayerListModel::LayerListModel(std::shared_ptr<Map> map, QObject* parent)
|
||||
: QAbstractListModel(parent)
|
||||
, map_(map)
|
||||
{}
|
||||
|
||||
int LayerListModel::rowCount(QModelIndex const&) const
|
||||
{
|
||||
if (map_) return map_->layers().size();
|
||||
return 0;
|
||||
if (map_)
|
||||
return map_->layers().size();
|
||||
return 0;
|
||||
}
|
||||
|
||||
QVariant LayerListModel::data(QModelIndex const& index, int role) const
|
||||
|
@ -59,9 +59,9 @@ QVariant LayerListModel::data(QModelIndex const& index, int role) const
|
|||
else if (role == Qt::CheckStateRole)
|
||||
{
|
||||
if (map_->layers().at(index.row()).active())
|
||||
return QVariant(Qt::Checked);
|
||||
return QVariant(Qt::Checked);
|
||||
else
|
||||
return QVariant(Qt::Unchecked);
|
||||
return QVariant(Qt::Unchecked);
|
||||
}
|
||||
else if (role == Qt::ForegroundRole)
|
||||
{
|
||||
|
@ -76,8 +76,7 @@ QVariant LayerListModel::data(QModelIndex const& index, int role) const
|
|||
}
|
||||
}
|
||||
|
||||
QVariant LayerListModel::headerData(int section, Qt::Orientation orientation,
|
||||
int role) const
|
||||
QVariant LayerListModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
|
@ -88,37 +87,37 @@ QVariant LayerListModel::headerData(int section, Qt::Orientation orientation,
|
|||
return QString("TODO Row %1").arg(section);
|
||||
}
|
||||
|
||||
bool LayerListModel::setData(const QModelIndex &index,
|
||||
const QVariant &value, int role)
|
||||
bool LayerListModel::setData(const QModelIndex& index, const QVariant& value, int role)
|
||||
{
|
||||
if (!map_) return false;
|
||||
if (!map_)
|
||||
return false;
|
||||
|
||||
if (index.isValid() && role == Qt::CheckStateRole)
|
||||
{
|
||||
int status = value.toInt();
|
||||
std::vector<mapnik::layer> & layers = const_cast<std::vector<mapnik::layer>& >(map_->layers());
|
||||
layers.at(index.row()).set_active(status);
|
||||
emit dataChanged(index, index);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
if (index.isValid() && role == Qt::CheckStateRole)
|
||||
{
|
||||
int status = value.toInt();
|
||||
std::vector<mapnik::layer>& layers = const_cast<std::vector<mapnik::layer>&>(map_->layers());
|
||||
layers.at(index.row()).set_active(status);
|
||||
emit dataChanged(index, index);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Qt::ItemFlags LayerListModel::flags(QModelIndex const& index) const
|
||||
{
|
||||
Qt::ItemFlags flags = QAbstractItemModel::flags(index);
|
||||
if (index.isValid())
|
||||
flags |= Qt::ItemIsUserCheckable;
|
||||
flags |= Qt::ItemIsUserCheckable;
|
||||
return flags;
|
||||
}
|
||||
|
||||
boost::optional<mapnik::layer&> LayerListModel::map_layer(int i)
|
||||
{
|
||||
if (map_)
|
||||
{
|
||||
std::vector<mapnik::layer> & layers = const_cast<std::vector<mapnik::layer>& >(map_->layers());
|
||||
if (i < int(layers.size()))
|
||||
return boost::optional<mapnik::layer&>(layers[i]);
|
||||
}
|
||||
return boost::optional<mapnik::layer&>();
|
||||
if (map_)
|
||||
{
|
||||
std::vector<mapnik::layer>& layers = const_cast<std::vector<mapnik::layer>&>(map_->layers());
|
||||
if (i < int(layers.size()))
|
||||
return boost::optional<mapnik::layer&>(layers[i]);
|
||||
}
|
||||
return boost::optional<mapnik::layer&>();
|
||||
}
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef LAYER_LIST_MODEL_HPP
|
||||
#define LAYER_LIST_MODEL_HPP
|
||||
|
||||
|
@ -32,20 +30,18 @@
|
|||
|
||||
class LayerListModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
LayerListModel(std::shared_ptr<mapnik::Map> map, QObject * parent = 0);
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const;
|
||||
bool setData(const QModelIndex &index, const QVariant &value,
|
||||
int role = Qt::EditRole);
|
||||
Qt::ItemFlags flags(QModelIndex const& index) const;
|
||||
boost::optional<mapnik::layer&> map_layer(int i);
|
||||
Q_OBJECT
|
||||
public:
|
||||
LayerListModel(std::shared_ptr<mapnik::Map> map, QObject* parent = 0);
|
||||
int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
||||
QVariant data(const QModelIndex& index, int role) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
||||
Qt::ItemFlags flags(QModelIndex const& index) const;
|
||||
boost::optional<mapnik::layer&> map_layer(int i);
|
||||
|
||||
private:
|
||||
std::shared_ptr<mapnik::Map> map_;
|
||||
private:
|
||||
std::shared_ptr<mapnik::Map> map_;
|
||||
};
|
||||
|
||||
#endif //LAYER_LIST_MODEL_HPP
|
||||
#endif // LAYER_LIST_MODEL_HPP
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#include "layerwidget.hpp"
|
||||
#include <qabstractitemdelegate.h>
|
||||
#include <qapplication.h>
|
||||
|
@ -33,65 +32,59 @@
|
|||
#include "layer_info_dialog.hpp"
|
||||
|
||||
LayerTab::LayerTab(QWidget* parent)
|
||||
: QListView(parent) {}
|
||||
: QListView(parent)
|
||||
{}
|
||||
|
||||
|
||||
void LayerTab::paintEvent(QPaintEvent *e)
|
||||
void LayerTab::paintEvent(QPaintEvent* e)
|
||||
{
|
||||
QListView::paintEvent(e);
|
||||
}
|
||||
|
||||
void LayerTab::dataChanged(const QModelIndex &topLeft,
|
||||
const QModelIndex &bottomRight,
|
||||
const QVector<int> &roles)
|
||||
void LayerTab::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles)
|
||||
{
|
||||
emit update_mapwidget();
|
||||
QListView::dataChanged(topLeft, bottomRight, roles);
|
||||
}
|
||||
|
||||
void LayerTab::selectionChanged(const QItemSelection & selected, const QItemSelection &)
|
||||
void LayerTab::selectionChanged(const QItemSelection& selected, const QItemSelection&)
|
||||
{
|
||||
QModelIndexList list = selected.indexes();
|
||||
if (list.size() != 0)
|
||||
{
|
||||
qDebug("SELECTED LAYER -> %d",list[0].row());
|
||||
emit layerSelected(list[0].row());
|
||||
}
|
||||
QModelIndexList list = selected.indexes();
|
||||
if (list.size() != 0)
|
||||
{
|
||||
qDebug("SELECTED LAYER -> %d", list[0].row());
|
||||
emit layerSelected(list[0].row());
|
||||
}
|
||||
}
|
||||
|
||||
void LayerTab::layerInfo()
|
||||
{
|
||||
qDebug("Layer info");
|
||||
QModelIndexList indexes = selectedIndexes();
|
||||
if (indexes.size() > 0)
|
||||
{
|
||||
qDebug("id = %d",indexes[0].row());
|
||||
|
||||
}
|
||||
qDebug("Layer info");
|
||||
QModelIndexList indexes = selectedIndexes();
|
||||
if (indexes.size() > 0)
|
||||
{
|
||||
qDebug("id = %d", indexes[0].row());
|
||||
}
|
||||
}
|
||||
|
||||
void LayerTab::layerInfo2(QModelIndex const& index)
|
||||
{
|
||||
qDebug("LayerInfo id = %d",index.row());
|
||||
QVector<QPair<QString,QString> > params;
|
||||
QVector<QString> style_names;
|
||||
unsigned i = index.row();
|
||||
LayerListModel * model = static_cast<LayerListModel*>(this->model());
|
||||
boost::optional<mapnik::layer&> layer = model->map_layer(i);
|
||||
qDebug("LayerInfo id = %d", index.row());
|
||||
QVector<QPair<QString, QString>> params;
|
||||
QVector<QString> style_names;
|
||||
unsigned i = index.row();
|
||||
LayerListModel* model = static_cast<LayerListModel*>(this->model());
|
||||
boost::optional<mapnik::layer&> layer = model->map_layer(i);
|
||||
|
||||
if (layer)
|
||||
{
|
||||
layer_info_dialog dlg(*layer,this);
|
||||
dlg.exec();
|
||||
}
|
||||
if (layer)
|
||||
{
|
||||
layer_info_dialog dlg(*layer, this);
|
||||
dlg.exec();
|
||||
}
|
||||
}
|
||||
|
||||
StyleTab::StyleTab(QWidget*)
|
||||
StyleTab::StyleTab(QWidget*) {}
|
||||
|
||||
void StyleTab::contextMenuEvent(QContextMenuEvent* event)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void StyleTab::contextMenuEvent(QContextMenuEvent * event )
|
||||
{
|
||||
qDebug("test");
|
||||
qDebug("test");
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef LAYERWIDGET_HPP
|
||||
#define LAYERWIDGET_HPP
|
||||
|
||||
|
@ -28,27 +27,28 @@
|
|||
class LayerTab : public QListView
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
LayerTab(QWidget* parent=0);
|
||||
void paintEvent(QPaintEvent *e);
|
||||
signals:
|
||||
public:
|
||||
LayerTab(QWidget* parent = 0);
|
||||
void paintEvent(QPaintEvent* e);
|
||||
signals:
|
||||
void update_mapwidget();
|
||||
void layerSelected(int) const;
|
||||
public slots:
|
||||
public slots:
|
||||
void layerInfo();
|
||||
void layerInfo2(QModelIndex const&);
|
||||
protected slots:
|
||||
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
|
||||
void selectionChanged(const QItemSelection & selected, const QItemSelection &);
|
||||
protected slots:
|
||||
void dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles);
|
||||
void selectionChanged(const QItemSelection& selected, const QItemSelection&);
|
||||
};
|
||||
|
||||
class StyleTab : public QTreeView
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
StyleTab(QWidget* parent=0);
|
||||
protected:
|
||||
void contextMenuEvent(QContextMenuEvent * event );
|
||||
public:
|
||||
StyleTab(QWidget* parent = 0);
|
||||
|
||||
protected:
|
||||
void contextMenuEvent(QContextMenuEvent* event);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
// qt
|
||||
#include <QApplication>
|
||||
#include <QStringList>
|
||||
|
@ -26,27 +25,26 @@
|
|||
#include <mapnik/font_engine_freetype.hpp>
|
||||
#include "mainwindow.hpp"
|
||||
|
||||
int main( int argc, char **argv )
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
using mapnik::datasource_cache;
|
||||
using mapnik::freetype_engine;
|
||||
try
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
|
||||
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
#endif
|
||||
#endif
|
||||
QCoreApplication::setOrganizationName("Mapnik");
|
||||
QCoreApplication::setOrganizationDomain("mapnik.org");
|
||||
QCoreApplication::setApplicationName("Viewer");
|
||||
QSettings settings("viewer.ini",QSettings::IniFormat);
|
||||
QSettings settings("viewer.ini", QSettings::IniFormat);
|
||||
|
||||
// register input plug-ins
|
||||
QString plugins_dir = settings.value("mapnik/plugins_dir",
|
||||
QVariant("/usr/local/lib/mapnik/input/")).toString();
|
||||
QString plugins_dir = settings.value("mapnik/plugins_dir", QVariant("/usr/local/lib/mapnik/input/")).toString();
|
||||
datasource_cache::instance().register_datasources(plugins_dir.toStdString());
|
||||
// register fonts
|
||||
int count = settings.beginReadArray("mapnik/fonts");
|
||||
for (int index=0; index < count; ++index)
|
||||
for (int index = 0; index < count; ++index)
|
||||
{
|
||||
settings.setArrayIndex(index);
|
||||
QString font_dir = settings.value("dir").toString();
|
||||
|
@ -54,37 +52,40 @@ int main( int argc, char **argv )
|
|||
}
|
||||
settings.endArray();
|
||||
|
||||
QApplication app( argc, argv );
|
||||
QApplication app(argc, argv);
|
||||
MainWindow window;
|
||||
window.show();
|
||||
if (argc > 1) window.open(argv[1]);
|
||||
if (argc > 1)
|
||||
window.open(argv[1]);
|
||||
if (argc >= 3)
|
||||
{
|
||||
QStringList list = QString(argv[2]).split(",");
|
||||
if (list.size()==4)
|
||||
if (list.size() == 4)
|
||||
{
|
||||
bool ok;
|
||||
double x0 = list[0].toDouble(&ok);
|
||||
double y0 = list[1].toDouble(&ok);
|
||||
double x1 = list[2].toDouble(&ok);
|
||||
double y1 = list[3].toDouble(&ok);
|
||||
if (ok) window.set_default_extent(x0,y0,x1,y1);
|
||||
if (ok)
|
||||
window.set_default_extent(x0, y0, x1, y1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::shared_ptr<mapnik::Map> map = window.get_map();
|
||||
if (map) map->zoom_all();
|
||||
if (map)
|
||||
map->zoom_all();
|
||||
}
|
||||
if (argc == 4)
|
||||
{
|
||||
bool ok;
|
||||
double scaling_factor = QString(argv[3]).toDouble(&ok);
|
||||
if (ok) window.set_scaling_factor(scaling_factor);
|
||||
if (ok)
|
||||
window.set_scaling_factor(scaling_factor);
|
||||
}
|
||||
return app.exec();
|
||||
}
|
||||
catch (std::exception const& ex)
|
||||
} catch (std::exception const& ex)
|
||||
{
|
||||
std::cerr << "Could not start viewer: '" << ex.what() << "'\n";
|
||||
return 1;
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
// stl
|
||||
#include <iostream>
|
||||
|
||||
|
@ -58,27 +57,27 @@
|
|||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
MainWindow::MainWindow()
|
||||
: filename_(),
|
||||
default_extent_(-20037508.3428,-20037508.3428,20037508.3428,20037508.3428)
|
||||
: filename_()
|
||||
, default_extent_(-20037508.3428, -20037508.3428, 20037508.3428, 20037508.3428)
|
||||
{
|
||||
mapWidget_ = new MapWidget(this);
|
||||
QSplitter *splitter = new QSplitter(this);
|
||||
QTabWidget *tabWidget=new QTabWidget;
|
||||
QSplitter* splitter = new QSplitter(this);
|
||||
QTabWidget* tabWidget = new QTabWidget;
|
||||
layerTab_ = new LayerTab;
|
||||
layerTab_->setFocusPolicy(Qt::NoFocus);
|
||||
layerTab_->setIconSize(QSize(16,16));
|
||||
layerTab_->setIconSize(QSize(16, 16));
|
||||
|
||||
//LayerDelegate *delegate = new LayerDelegate(this);
|
||||
//layerTab_->setItemDelegate(delegate);
|
||||
//layerTab_->setItemDelegate(new QItemDelegate(this));
|
||||
//layerTab_->setViewMode(QListView::IconMode);
|
||||
// LayerDelegate *delegate = new LayerDelegate(this);
|
||||
// layerTab_->setItemDelegate(delegate);
|
||||
// layerTab_->setItemDelegate(new QItemDelegate(this));
|
||||
// layerTab_->setViewMode(QListView::IconMode);
|
||||
|
||||
layerTab_->setFlow(QListView::TopToBottom);
|
||||
tabWidget->addTab(layerTab_,tr("Layers"));
|
||||
tabWidget->addTab(layerTab_, tr("Layers"));
|
||||
|
||||
// Styles tab
|
||||
styleTab_ = new StyleTab;
|
||||
tabWidget->addTab(styleTab_,tr("Styles"));
|
||||
tabWidget->addTab(styleTab_, tr("Styles"));
|
||||
splitter->addWidget(tabWidget);
|
||||
splitter->addWidget(mapWidget_);
|
||||
QList<int> list;
|
||||
|
@ -89,7 +88,7 @@ MainWindow::MainWindow()
|
|||
mapWidget_->setFocusPolicy(Qt::StrongFocus);
|
||||
mapWidget_->setFocus();
|
||||
|
||||
//setCentralWidget(mapWidget_);
|
||||
// setCentralWidget(mapWidget_);
|
||||
setCentralWidget(splitter);
|
||||
createActions();
|
||||
createMenus();
|
||||
|
@ -97,29 +96,28 @@ MainWindow::MainWindow()
|
|||
createContextMenu();
|
||||
|
||||
setWindowTitle(tr("Mapnik Viewer"));
|
||||
status=new QStatusBar(this);
|
||||
status = new QStatusBar(this);
|
||||
status->showMessage(tr(""));
|
||||
setStatusBar(status);
|
||||
resize(800,600);
|
||||
resize(800, 600);
|
||||
|
||||
//connect mapview to layerlist
|
||||
connect(mapWidget_, SIGNAL(mapViewChanged()),layerTab_, SLOT(update()));
|
||||
// connect mapview to layerlist
|
||||
connect(mapWidget_, SIGNAL(mapViewChanged()), layerTab_, SLOT(update()));
|
||||
// slider
|
||||
connect(slider_,SIGNAL(valueChanged(int)),mapWidget_,SLOT(zoomToLevel(int)));
|
||||
connect(slider_, SIGNAL(valueChanged(int)), mapWidget_, SLOT(zoomToLevel(int)));
|
||||
// renderer selector
|
||||
connect(renderer_selector_,SIGNAL(currentIndexChanged(QString const&)),
|
||||
mapWidget_, SLOT(updateRenderer(QString const&)));
|
||||
connect(renderer_selector_,
|
||||
SIGNAL(currentIndexChanged(QString const&)),
|
||||
mapWidget_,
|
||||
SLOT(updateRenderer(QString const&)));
|
||||
|
||||
// scale factor
|
||||
connect(scale_factor_,SIGNAL(valueChanged(double)),
|
||||
mapWidget_, SLOT(updateScaleFactor(double)));
|
||||
connect(scale_factor_, SIGNAL(valueChanged(double)), mapWidget_, SLOT(updateScaleFactor(double)));
|
||||
//
|
||||
connect(layerTab_,SIGNAL(update_mapwidget()),mapWidget_,SLOT(updateMap()));
|
||||
connect(layerTab_,SIGNAL(layerSelected(int)),
|
||||
mapWidget_,SLOT(layerSelected(int)));
|
||||
connect(layerTab_, SIGNAL(update_mapwidget()), mapWidget_, SLOT(updateMap()));
|
||||
connect(layerTab_, SIGNAL(layerSelected(int)), mapWidget_, SLOT(layerSelected(int)));
|
||||
}
|
||||
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete mapWidget_;
|
||||
|
@ -141,8 +139,7 @@ void MainWindow::open(QString const& path)
|
|||
{
|
||||
if (path.isNull())
|
||||
{
|
||||
filename_ = QFileDialog::getOpenFileName(this,tr("Open Mapnik file"),
|
||||
currentPath,"*.xml");
|
||||
filename_ = QFileDialog::getOpenFileName(this, tr("Open Mapnik file"), currentPath, "*.xml");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -151,18 +148,15 @@ void MainWindow::open(QString const& path)
|
|||
|
||||
if (!filename_.isEmpty())
|
||||
{
|
||||
|
||||
load_map_file(filename_);
|
||||
setWindowTitle(tr("%1 - Mapnik Viewer").arg(filename_));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::reload()
|
||||
{
|
||||
if (!filename_.isEmpty())
|
||||
{
|
||||
|
||||
mapnik::box2d<double> bbox = mapWidget_->getMap()->get_current_extent();
|
||||
load_map_file(filename_);
|
||||
mapWidget_->zoomToBox(bbox);
|
||||
|
@ -173,39 +167,37 @@ void MainWindow::reload()
|
|||
void MainWindow::save()
|
||||
{
|
||||
QString initialPath = QDir::currentPath() + "/untitled.xml";
|
||||
QString filename = QFileDialog::getSaveFileName(this, tr("Save"),
|
||||
QString filename = QFileDialog::getSaveFileName(this,
|
||||
tr("Save"),
|
||||
initialPath,
|
||||
tr("%1 Files (*.xml)")
|
||||
.arg(QString("Mapnik definition")));
|
||||
tr("%1 Files (*.xml)").arg(QString("Mapnik definition")));
|
||||
if (!filename.isEmpty())
|
||||
{
|
||||
std::cout<<"saving "<< filename.toStdString() << std::endl;
|
||||
mapnik::save_map(*mapWidget_->getMap(),filename.toStdString());
|
||||
std::cout << "saving " << filename.toStdString() << std::endl;
|
||||
mapnik::save_map(*mapWidget_->getMap(), filename.toStdString());
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::load_map_file(QString const& filename)
|
||||
{
|
||||
std::cout << "loading "<< filename.toStdString() << std::endl;
|
||||
std::cout << "loading " << filename.toStdString() << std::endl;
|
||||
unsigned width = mapWidget_->width();
|
||||
unsigned height = mapWidget_->height();
|
||||
std::shared_ptr<mapnik::Map> map(new mapnik::Map(width,height));
|
||||
std::shared_ptr<mapnik::Map> map(new mapnik::Map(width, height));
|
||||
mapWidget_->setMap(map);
|
||||
try
|
||||
{
|
||||
mapnik::auto_cpu_timer t(std::clog, "loading map took: ");
|
||||
mapnik::load_map(*map,filename.toStdString());
|
||||
}
|
||||
catch (std::exception const& ex)
|
||||
mapnik::load_map(*map, filename.toStdString());
|
||||
} catch (std::exception const& ex)
|
||||
{
|
||||
std::cout << ex.what() << "\n";
|
||||
}
|
||||
catch (...)
|
||||
} catch (...)
|
||||
{
|
||||
std::cerr << "Exception caught in load_map\n";
|
||||
}
|
||||
layerTab_->setModel(new LayerListModel(map,this));
|
||||
styleTab_->setModel(new StyleModel(map,this));
|
||||
layerTab_->setModel(new LayerListModel(map, this));
|
||||
styleTab_->setModel(new StyleModel(map, this));
|
||||
zoom_all();
|
||||
}
|
||||
|
||||
|
@ -252,15 +244,15 @@ void MainWindow::about()
|
|||
|
||||
void MainWindow::export_as()
|
||||
{
|
||||
QAction *action = qobject_cast<QAction *>(sender());
|
||||
QAction* action = qobject_cast<QAction*>(sender());
|
||||
QByteArray fileFormat = action->data().toByteArray();
|
||||
QString initialPath = QDir::currentPath() + "/map." + fileFormat;
|
||||
|
||||
QString fileName = QFileDialog::getSaveFileName(this, tr("Export As"),
|
||||
initialPath,
|
||||
tr("%1 Files (*.%2);;All Files (*)")
|
||||
.arg(QString(fileFormat.toUpper()))
|
||||
.arg(QString(fileFormat)));
|
||||
QString fileName = QFileDialog::getSaveFileName(
|
||||
this,
|
||||
tr("Export As"),
|
||||
initialPath,
|
||||
tr("%1 Files (*.%2);;All Files (*)").arg(QString(fileFormat.toUpper())).arg(QString(fileFormat)));
|
||||
if (!fileName.isEmpty())
|
||||
{
|
||||
QPixmap const& pix = mapWidget_->pixmap();
|
||||
|
@ -270,77 +262,76 @@ void MainWindow::export_as()
|
|||
|
||||
void MainWindow::print()
|
||||
{
|
||||
|
||||
//Q_ASSERT(mapWidget_->pixmap());
|
||||
//QPrintDialog dialog(&printer, this);
|
||||
//if (dialog.exec()) {
|
||||
// QPainter painter(&printer);
|
||||
// QRect rect = painter.viewport();
|
||||
// QSize size = mapWidget_->pixmap()->size();
|
||||
// size.scale(rect.size(), Qt::KeepAspectRatio);
|
||||
// painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
|
||||
// painter.setWindow(mapWidget_->pixmap()->rect());
|
||||
// painter.drawPixmap(0, 0, *mapWidget_->pixmap());
|
||||
//}
|
||||
// Q_ASSERT(mapWidget_->pixmap());
|
||||
// QPrintDialog dialog(&printer, this);
|
||||
// if (dialog.exec()) {
|
||||
// QPainter painter(&printer);
|
||||
// QRect rect = painter.viewport();
|
||||
// QSize size = mapWidget_->pixmap()->size();
|
||||
// size.scale(rect.size(), Qt::KeepAspectRatio);
|
||||
// painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
|
||||
// painter.setWindow(mapWidget_->pixmap()->rect());
|
||||
// painter.drawPixmap(0, 0, *mapWidget_->pixmap());
|
||||
// }
|
||||
}
|
||||
|
||||
void MainWindow::createActions()
|
||||
{
|
||||
//exportAct = new QAction(tr("&Export as ..."),this);
|
||||
//exportAct->setShortcut(tr("Ctrl+E"));
|
||||
//connect(exportAct, SIGNAL(triggered()), this, SLOT(export_as()));
|
||||
zoomAllAct = new QAction(QIcon(":/images/home.png"),tr("Zoom All"),this);
|
||||
// exportAct = new QAction(tr("&Export as ..."),this);
|
||||
// exportAct->setShortcut(tr("Ctrl+E"));
|
||||
// connect(exportAct, SIGNAL(triggered()), this, SLOT(export_as()));
|
||||
zoomAllAct = new QAction(QIcon(":/images/home.png"), tr("Zoom All"), this);
|
||||
connect(zoomAllAct, SIGNAL(triggered()), this, SLOT(zoom_all()));
|
||||
|
||||
zoomBoxAct = new QAction(QIcon(":/images/zoombox.png"),tr("Zoom To Box"),this);
|
||||
zoomBoxAct = new QAction(QIcon(":/images/zoombox.png"), tr("Zoom To Box"), this);
|
||||
zoomBoxAct->setCheckable(true);
|
||||
connect(zoomBoxAct, SIGNAL(triggered()), this, SLOT(zoom_to_box()));
|
||||
|
||||
panAct = new QAction(QIcon(":/images/pan.png"),tr("Pan"),this);
|
||||
panAct = new QAction(QIcon(":/images/pan.png"), tr("Pan"), this);
|
||||
panAct->setCheckable(true);
|
||||
connect(panAct, SIGNAL(triggered()), this, SLOT(pan()));
|
||||
|
||||
infoAct = new QAction(QIcon(":/images/info.png"),tr("Info"),this);
|
||||
infoAct = new QAction(QIcon(":/images/info.png"), tr("Info"), this);
|
||||
infoAct->setCheckable(true);
|
||||
connect(infoAct, SIGNAL(triggered()), this, SLOT(info()));
|
||||
|
||||
toolsGroup=new QActionGroup(this);
|
||||
toolsGroup = new QActionGroup(this);
|
||||
toolsGroup->addAction(zoomBoxAct);
|
||||
toolsGroup->addAction(panAct);
|
||||
toolsGroup->addAction(infoAct);
|
||||
zoomBoxAct->setChecked(true);
|
||||
|
||||
openAct=new QAction(tr("Open Map definition"),this);
|
||||
connect(openAct,SIGNAL(triggered()),this,SLOT(open()));
|
||||
saveAct=new QAction(tr("Save Map definition"),this);
|
||||
connect(saveAct,SIGNAL(triggered()),this,SLOT(save()));
|
||||
openAct = new QAction(tr("Open Map definition"), this);
|
||||
connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
|
||||
saveAct = new QAction(tr("Save Map definition"), this);
|
||||
connect(saveAct, SIGNAL(triggered()), this, SLOT(save()));
|
||||
|
||||
panLeftAct = new QAction(QIcon(":/images/left.png"),tr("&Pan Left"),this);
|
||||
panLeftAct = new QAction(QIcon(":/images/left.png"), tr("&Pan Left"), this);
|
||||
connect(panLeftAct, SIGNAL(triggered()), this, SLOT(pan_left()));
|
||||
panRightAct = new QAction(QIcon(":/images/right.png"),tr("&Pan Right"),this);
|
||||
panRightAct = new QAction(QIcon(":/images/right.png"), tr("&Pan Right"), this);
|
||||
connect(panRightAct, SIGNAL(triggered()), this, SLOT(pan_right()));
|
||||
panUpAct = new QAction(QIcon(":/images/up.png"),tr("&Pan Up"),this);
|
||||
panUpAct = new QAction(QIcon(":/images/up.png"), tr("&Pan Up"), this);
|
||||
connect(panUpAct, SIGNAL(triggered()), this, SLOT(pan_up()));
|
||||
panDownAct = new QAction(QIcon(":/images/down.png"),tr("&Pan Down"),this);
|
||||
panDownAct = new QAction(QIcon(":/images/down.png"), tr("&Pan Down"), this);
|
||||
connect(panDownAct, SIGNAL(triggered()), this, SLOT(pan_down()));
|
||||
|
||||
reloadAct = new QAction(QIcon(":/images/reload.png"),tr("Reload"),this);
|
||||
reloadAct = new QAction(QIcon(":/images/reload.png"), tr("Reload"), this);
|
||||
connect(reloadAct, SIGNAL(triggered()), this, SLOT(reload()));
|
||||
|
||||
layerInfo = new QAction(QIcon(":/images/info.png"),tr("&Layer info"),layerTab_);
|
||||
connect(layerInfo, SIGNAL(triggered()), layerTab_,SLOT(layerInfo()));
|
||||
connect(layerTab_, SIGNAL(doubleClicked(QModelIndex const&)), layerTab_,SLOT(layerInfo2(QModelIndex const&)));
|
||||
layerInfo = new QAction(QIcon(":/images/info.png"), tr("&Layer info"), layerTab_);
|
||||
connect(layerInfo, SIGNAL(triggered()), layerTab_, SLOT(layerInfo()));
|
||||
connect(layerTab_, SIGNAL(doubleClicked(QModelIndex const&)), layerTab_, SLOT(layerInfo2(QModelIndex const&)));
|
||||
foreach (QByteArray format, QImageWriter::supportedImageFormats())
|
||||
{
|
||||
QString text = tr("%1...").arg(QString(format).toUpper());
|
||||
|
||||
QAction *action = new QAction(text, this);
|
||||
QAction* action = new QAction(text, this);
|
||||
action->setData(format);
|
||||
connect(action, SIGNAL(triggered()), this, SLOT(export_as()));
|
||||
exportAsActs.append(action);
|
||||
}
|
||||
|
||||
printAct = new QAction(QIcon(":/images/print.png"),tr("&Print ..."),this);
|
||||
printAct = new QAction(QIcon(":/images/print.png"), tr("&Print ..."), this);
|
||||
printAct->setShortcut(tr("Ctrl+E"));
|
||||
connect(printAct, SIGNAL(triggered()), this, SLOT(print()));
|
||||
|
||||
|
@ -348,17 +339,17 @@ void MainWindow::createActions()
|
|||
exitAct->setShortcut(tr("Ctrl+Q"));
|
||||
connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
|
||||
|
||||
aboutAct = new QAction(QIcon(":/images/about.png"),tr("&About"), this);
|
||||
aboutAct = new QAction(QIcon(":/images/about.png"), tr("&About"), this);
|
||||
connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
|
||||
}
|
||||
|
||||
void MainWindow::createMenus()
|
||||
{
|
||||
exportMenu = new QMenu(tr("&Export As"), this);
|
||||
foreach (QAction *action, exportAsActs)
|
||||
foreach (QAction* action, exportAsActs)
|
||||
exportMenu->addAction(action);
|
||||
|
||||
fileMenu = new QMenu(tr("&File"),this);
|
||||
fileMenu = new QMenu(tr("&File"), this);
|
||||
fileMenu->addAction(openAct);
|
||||
fileMenu->addAction(saveAct);
|
||||
fileMenu->addMenu(exportMenu);
|
||||
|
@ -402,8 +393,8 @@ void MainWindow::createToolBars()
|
|||
scale_factor_->setValue(1.0);
|
||||
|
||||
fileToolBar->addWidget(scale_factor_);
|
||||
slider_ = new QSlider(Qt::Horizontal,fileToolBar);
|
||||
slider_->setRange(1,18);
|
||||
slider_ = new QSlider(Qt::Horizontal, fileToolBar);
|
||||
slider_->setRange(1, 18);
|
||||
slider_->setTickPosition(QSlider::TicksBelow);
|
||||
slider_->setTickInterval(1);
|
||||
slider_->setTracking(false);
|
||||
|
@ -411,9 +402,7 @@ void MainWindow::createToolBars()
|
|||
fileToolBar->addAction(aboutAct);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MainWindow::set_default_extent(double x0,double y0, double x1, double y1)
|
||||
void MainWindow::set_default_extent(double x0, double y0, double x1, double y1)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -423,12 +412,12 @@ void MainWindow::set_default_extent(double x0,double y0, double x1, double y1)
|
|||
mapnik::projection prj(map_ptr->srs());
|
||||
prj.forward(x0, y0);
|
||||
prj.forward(x1, y1);
|
||||
default_extent_=mapnik::box2d<double>(x0, y0, x1, y1);
|
||||
default_extent_ = mapnik::box2d<double>(x0, y0, x1, y1);
|
||||
mapWidget_->zoomToBox(default_extent_);
|
||||
std::cout << "SET DEFAULT EXT:" << default_extent_ << std::endl;
|
||||
}
|
||||
}
|
||||
catch (...) {}
|
||||
} catch (...)
|
||||
{}
|
||||
}
|
||||
|
||||
void MainWindow::set_scaling_factor(double scaling_factor)
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MAINWINDOW_HPP
|
||||
#define MAINWINDOW_HPP
|
||||
|
||||
|
@ -30,7 +29,7 @@
|
|||
|
||||
#include "mapwidget.hpp"
|
||||
|
||||
//using namespace mapnik;
|
||||
// using namespace mapnik;
|
||||
|
||||
class LayerTab;
|
||||
class StyleTab;
|
||||
|
@ -41,22 +40,24 @@ class QDoubleSpinBox;
|
|||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
public:
|
||||
MainWindow();
|
||||
virtual ~MainWindow();
|
||||
void set_default_extent(double x0,double y0,double x1, double y1);
|
||||
void set_default_extent(double x0, double y0, double x1, double y1);
|
||||
void set_scaling_factor(double scaling_factor);
|
||||
public :
|
||||
|
||||
public:
|
||||
std::shared_ptr<mapnik::Map> get_map();
|
||||
protected:
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent* event);
|
||||
public slots:
|
||||
public slots:
|
||||
void zoom_all();
|
||||
void zoom_to_box();
|
||||
void pan();
|
||||
void info();
|
||||
void export_as();
|
||||
void open(QString const& path = QString());
|
||||
void open(QString const& path = QString());
|
||||
void reload();
|
||||
void save();
|
||||
void print();
|
||||
|
@ -65,7 +66,8 @@ public slots:
|
|||
void pan_right();
|
||||
void pan_up();
|
||||
void pan_down();
|
||||
private:
|
||||
|
||||
private:
|
||||
void createActions();
|
||||
void createMenus();
|
||||
void createToolBars();
|
||||
|
@ -74,43 +76,42 @@ private:
|
|||
|
||||
QString currentPath;
|
||||
QString filename_;
|
||||
QAbstractItemModel *model;
|
||||
LayerTab *layerTab_;
|
||||
StyleTab * styleTab_;
|
||||
MapWidget * mapWidget_;
|
||||
//actions
|
||||
QList<QAction *> exportAsActs;
|
||||
QActionGroup *toolsGroup;
|
||||
QAbstractItemModel* model;
|
||||
LayerTab* layerTab_;
|
||||
StyleTab* styleTab_;
|
||||
MapWidget* mapWidget_;
|
||||
// actions
|
||||
QList<QAction*> exportAsActs;
|
||||
QActionGroup* toolsGroup;
|
||||
|
||||
QAction *zoomAllAct;
|
||||
QAction *zoomBoxAct;
|
||||
QAction *panAct;
|
||||
QAction *infoAct;
|
||||
QAction *openAct;
|
||||
QAction *saveAct;
|
||||
QAction *printAct;
|
||||
QAction *exitAct;
|
||||
QAction *aboutAct;
|
||||
QAction *panLeftAct;
|
||||
QAction *panRightAct;
|
||||
QAction *panUpAct;
|
||||
QAction *panDownAct;
|
||||
QAction *reloadAct;
|
||||
QAction *layerInfo;
|
||||
//toolbars
|
||||
QToolBar *fileToolBar;
|
||||
QToolBar *editToolBar;
|
||||
//menus
|
||||
QMenu *exportMenu;
|
||||
QMenu *fileMenu;
|
||||
QMenu *helpMenu;
|
||||
//status bar
|
||||
QStatusBar *status;
|
||||
QSlider * slider_;
|
||||
QComboBox * renderer_selector_;
|
||||
QDoubleSpinBox * scale_factor_;
|
||||
QAction* zoomAllAct;
|
||||
QAction* zoomBoxAct;
|
||||
QAction* panAct;
|
||||
QAction* infoAct;
|
||||
QAction* openAct;
|
||||
QAction* saveAct;
|
||||
QAction* printAct;
|
||||
QAction* exitAct;
|
||||
QAction* aboutAct;
|
||||
QAction* panLeftAct;
|
||||
QAction* panRightAct;
|
||||
QAction* panUpAct;
|
||||
QAction* panDownAct;
|
||||
QAction* reloadAct;
|
||||
QAction* layerInfo;
|
||||
// toolbars
|
||||
QToolBar* fileToolBar;
|
||||
QToolBar* editToolBar;
|
||||
// menus
|
||||
QMenu* exportMenu;
|
||||
QMenu* fileMenu;
|
||||
QMenu* helpMenu;
|
||||
// status bar
|
||||
QStatusBar* status;
|
||||
QSlider* slider_;
|
||||
QComboBox* renderer_selector_;
|
||||
QDoubleSpinBox* scale_factor_;
|
||||
mapnik::box2d<double> default_extent_;
|
||||
};
|
||||
|
||||
|
||||
#endif //MAINWINDOW_HPP
|
||||
#endif // MAINWINDOW_HPP
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#include <QtGui>
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
|
@ -41,153 +40,139 @@
|
|||
#include "mapwidget.hpp"
|
||||
#include "info_dialog.hpp"
|
||||
|
||||
using mapnik::image_rgba8;
|
||||
using mapnik::Map;
|
||||
using mapnik::layer;
|
||||
using mapnik::box2d;
|
||||
using mapnik::coord2d;
|
||||
using mapnik::feature_kv_iterator;
|
||||
using mapnik::feature_ptr;
|
||||
using mapnik::view_transform;
|
||||
using mapnik::image_rgba8;
|
||||
using mapnik::layer;
|
||||
using mapnik::Map;
|
||||
using mapnik::projection;
|
||||
using mapnik::scale_denominator;
|
||||
using mapnik::feature_kv_iterator;
|
||||
using mapnik::view_transform;
|
||||
|
||||
double scales [] = {279541132.014,
|
||||
139770566.007,
|
||||
69885283.0036,
|
||||
34942641.5018,
|
||||
17471320.7509,
|
||||
8735660.37545,
|
||||
4367830.18772,
|
||||
2183915.09386,
|
||||
1091957.54693,
|
||||
545978.773466,
|
||||
272989.386733,
|
||||
136494.693366,
|
||||
68247.3466832,
|
||||
34123.6733416,
|
||||
17061.8366708,
|
||||
8530.9183354,
|
||||
4265.4591677,
|
||||
2132.72958385,
|
||||
1066.36479192,
|
||||
533.182395962};
|
||||
double scales[] = {279541132.014, 139770566.007, 69885283.0036, 34942641.5018, 17471320.7509,
|
||||
8735660.37545, 4367830.18772, 2183915.09386, 1091957.54693, 545978.773466,
|
||||
272989.386733, 136494.693366, 68247.3466832, 34123.6733416, 17061.8366708,
|
||||
8530.9183354, 4265.4591677, 2132.72958385, 1066.36479192, 533.182395962};
|
||||
|
||||
MapWidget::MapWidget(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
map_(),
|
||||
selected_(1),
|
||||
extent_(),
|
||||
cur_tool_(ZoomToBox),
|
||||
start_x_(0),
|
||||
start_y_(0),
|
||||
end_x_(0),
|
||||
end_y_(0),
|
||||
drag_(false),
|
||||
first_(true),
|
||||
pen_(QColor(0,0,255,96)),
|
||||
selectedLayer_(-1),
|
||||
scaling_factor_(1.0),
|
||||
cur_renderer_(AGG)
|
||||
MapWidget::MapWidget(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, map_()
|
||||
, selected_(1)
|
||||
, extent_()
|
||||
, cur_tool_(ZoomToBox)
|
||||
, start_x_(0)
|
||||
, start_y_(0)
|
||||
, end_x_(0)
|
||||
, end_y_(0)
|
||||
, drag_(false)
|
||||
, first_(true)
|
||||
, pen_(QColor(0, 0, 255, 96))
|
||||
, selectedLayer_(-1)
|
||||
, scaling_factor_(1.0)
|
||||
, cur_renderer_(AGG)
|
||||
{
|
||||
pen_.setWidth(3);
|
||||
pen_.setCapStyle(Qt::RoundCap);
|
||||
pen_.setJoinStyle(Qt::RoundJoin);
|
||||
pen_.setWidth(3);
|
||||
pen_.setCapStyle(Qt::RoundCap);
|
||||
pen_.setJoinStyle(Qt::RoundJoin);
|
||||
}
|
||||
|
||||
void MapWidget::setTool(eTool tool)
|
||||
{
|
||||
cur_tool_=tool;
|
||||
cur_tool_ = tool;
|
||||
}
|
||||
|
||||
void MapWidget::paintEvent(QPaintEvent*)
|
||||
{
|
||||
QPainter painter(this);
|
||||
QPainter painter(this);
|
||||
|
||||
if (drag_)
|
||||
{
|
||||
if (cur_tool_ == ZoomToBox)
|
||||
{
|
||||
unsigned width = end_x_-start_x_;
|
||||
unsigned height = end_y_-start_y_;
|
||||
painter.drawPixmap(QPoint(0, 0),pix_);
|
||||
painter.setPen(pen_);
|
||||
painter.setBrush(QColor(200,200,255,128));
|
||||
painter.drawRect(start_x_,start_y_,width,height);
|
||||
}
|
||||
else if (cur_tool_ == Pan)
|
||||
{
|
||||
int dx = end_x_-start_x_;
|
||||
int dy = end_y_-start_y_;
|
||||
painter.setBrush(QColor(200,200,200,128));
|
||||
painter.drawRect(0,0,width(),height());
|
||||
painter.drawPixmap(QPoint(dx,dy),pix_);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
painter.drawPixmap(QPoint(0, 0),pix_);
|
||||
}
|
||||
painter.end();
|
||||
if (drag_)
|
||||
{
|
||||
if (cur_tool_ == ZoomToBox)
|
||||
{
|
||||
unsigned width = end_x_ - start_x_;
|
||||
unsigned height = end_y_ - start_y_;
|
||||
painter.drawPixmap(QPoint(0, 0), pix_);
|
||||
painter.setPen(pen_);
|
||||
painter.setBrush(QColor(200, 200, 255, 128));
|
||||
painter.drawRect(start_x_, start_y_, width, height);
|
||||
}
|
||||
else if (cur_tool_ == Pan)
|
||||
{
|
||||
int dx = end_x_ - start_x_;
|
||||
int dy = end_y_ - start_y_;
|
||||
painter.setBrush(QColor(200, 200, 200, 128));
|
||||
painter.drawRect(0, 0, width(), height());
|
||||
painter.drawPixmap(QPoint(dx, dy), pix_);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
painter.drawPixmap(QPoint(0, 0), pix_);
|
||||
}
|
||||
painter.end();
|
||||
}
|
||||
|
||||
void MapWidget::resizeEvent(QResizeEvent * ev)
|
||||
void MapWidget::resizeEvent(QResizeEvent* ev)
|
||||
{
|
||||
if (map_)
|
||||
{
|
||||
map_->resize(ev->size().width(),ev->size().height());
|
||||
updateMap();
|
||||
}
|
||||
if (map_)
|
||||
{
|
||||
map_->resize(ev->size().width(), ev->size().height());
|
||||
updateMap();
|
||||
}
|
||||
}
|
||||
|
||||
void MapWidget::mousePressEvent(QMouseEvent* e)
|
||||
{
|
||||
if (e->button()==Qt::LeftButton)
|
||||
{
|
||||
if (cur_tool_ == ZoomToBox || cur_tool_==Pan)
|
||||
{
|
||||
start_x_ = e->x();
|
||||
start_y_ = e->y();
|
||||
drag_=true;
|
||||
}
|
||||
else if (cur_tool_==Info)
|
||||
{
|
||||
if (map_)
|
||||
{
|
||||
QVector<QPair<QString,QString> > info;
|
||||
|
||||
projection map_proj(map_->srs(), true); // map projection
|
||||
double scale_denom = scale_denominator(map_->scale(),map_proj.is_geographic());
|
||||
view_transform t(map_->width(),map_->height(),map_->get_current_extent());
|
||||
|
||||
for (unsigned index = 0; index < map_->layer_count();++index)
|
||||
if (e->button() == Qt::LeftButton)
|
||||
{
|
||||
if (cur_tool_ == ZoomToBox || cur_tool_ == Pan)
|
||||
{
|
||||
start_x_ = e->x();
|
||||
start_y_ = e->y();
|
||||
drag_ = true;
|
||||
}
|
||||
else if (cur_tool_ == Info)
|
||||
{
|
||||
if (map_)
|
||||
{
|
||||
if (int(index) != selectedLayer_) continue;
|
||||
QVector<QPair<QString, QString>> info;
|
||||
|
||||
layer & layer = map_->layers()[index];
|
||||
if (!layer.visible(scale_denom)) continue;
|
||||
std::string name = layer.name();
|
||||
double x = e->x();
|
||||
double y = e->y();
|
||||
std::cout << "query at " << x << "," << y << "\n";
|
||||
projection layer_proj(layer.srs(), true);
|
||||
mapnik::proj_transform prj_trans(map_proj,layer_proj);
|
||||
//std::auto_ptr<mapnik::memory_datasource> data(new mapnik::memory_datasource);
|
||||
mapnik::featureset_ptr fs = map_->query_map_point(index,x,y);
|
||||
projection map_proj(map_->srs(), true); // map projection
|
||||
double scale_denom = scale_denominator(map_->scale(), map_proj.is_geographic());
|
||||
view_transform t(map_->width(), map_->height(), map_->get_current_extent());
|
||||
|
||||
if (fs)
|
||||
{
|
||||
feature_ptr feat = fs->next();
|
||||
if (feat)
|
||||
{
|
||||
feature_kv_iterator itr(*feat,true);
|
||||
feature_kv_iterator end(*feat);
|
||||
for (unsigned index = 0; index < map_->layer_count(); ++index)
|
||||
{
|
||||
if (int(index) != selectedLayer_)
|
||||
continue;
|
||||
|
||||
for ( ;itr!=end; ++itr)
|
||||
{
|
||||
info.push_back(QPair<QString,QString>(QString(std::get<0>(*itr).c_str()),
|
||||
std::get<1>(*itr).to_string().c_str()));
|
||||
}
|
||||
layer& layer = map_->layers()[index];
|
||||
if (!layer.visible(scale_denom))
|
||||
continue;
|
||||
std::string name = layer.name();
|
||||
double x = e->x();
|
||||
double y = e->y();
|
||||
std::cout << "query at " << x << "," << y << "\n";
|
||||
projection layer_proj(layer.srs(), true);
|
||||
mapnik::proj_transform prj_trans(map_proj, layer_proj);
|
||||
// std::auto_ptr<mapnik::memory_datasource> data(new mapnik::memory_datasource);
|
||||
mapnik::featureset_ptr fs = map_->query_map_point(index, x, y);
|
||||
|
||||
if (fs)
|
||||
{
|
||||
feature_ptr feat = fs->next();
|
||||
if (feat)
|
||||
{
|
||||
feature_kv_iterator itr(*feat, true);
|
||||
feature_kv_iterator end(*feat);
|
||||
|
||||
for (; itr != end; ++itr)
|
||||
{
|
||||
info.push_back(QPair<QString, QString>(QString(std::get<0>(*itr).c_str()),
|
||||
std::get<1>(*itr).to_string().c_str()));
|
||||
}
|
||||
|
||||
#if 0 //
|
||||
using path_type = mapnik::transform_path_adapter<mapnik::view_transform,mapnik::vertex_adapter>;
|
||||
|
@ -219,288 +204,285 @@ void MapWidget::mousePressEvent(QMouseEvent* e)
|
|||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (info.size() > 0)
|
||||
{
|
||||
info_dialog info_dlg(info,this);
|
||||
info_dlg.exec();
|
||||
break;
|
||||
}
|
||||
if (info.size() > 0)
|
||||
{
|
||||
info_dialog info_dlg(info, this);
|
||||
info_dlg.exec();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// remove annotation layer
|
||||
map_->layers().erase(
|
||||
remove_if(map_->layers().begin(), map_->layers().end(), bind(&layer::name, _1) == "*annotations*"),
|
||||
map_->layers().end());
|
||||
}
|
||||
|
||||
// remove annotation layer
|
||||
map_->layers().erase(remove_if(map_->layers().begin(),
|
||||
map_->layers().end(),
|
||||
bind(&layer::name,_1) == "*annotations*")
|
||||
, map_->layers().end());
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (e->button()==Qt::RightButton)
|
||||
{
|
||||
//updateMap();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (e->button() == Qt::RightButton)
|
||||
{
|
||||
// updateMap();
|
||||
}
|
||||
}
|
||||
|
||||
void MapWidget::mouseMoveEvent(QMouseEvent* e)
|
||||
{
|
||||
if (cur_tool_ == ZoomToBox || cur_tool_==Pan)
|
||||
{
|
||||
end_x_ = e->x();
|
||||
end_y_ = e->y();
|
||||
update();
|
||||
}
|
||||
if (cur_tool_ == ZoomToBox || cur_tool_ == Pan)
|
||||
{
|
||||
end_x_ = e->x();
|
||||
end_y_ = e->y();
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void MapWidget::mouseReleaseEvent(QMouseEvent* e)
|
||||
{
|
||||
if (e->button()==Qt::LeftButton)
|
||||
{
|
||||
end_x_ = e->x();
|
||||
end_y_ = e->y();
|
||||
if (cur_tool_ == ZoomToBox)
|
||||
{
|
||||
drag_=false;
|
||||
if (map_)
|
||||
{
|
||||
view_transform t(map_->width(),map_->height(),map_->get_current_extent());
|
||||
box2d<double> box = t.backward(box2d<double>(start_x_,start_y_,end_x_,end_y_));
|
||||
map_->zoom_to_box(box);
|
||||
updateMap();
|
||||
}
|
||||
}
|
||||
else if (cur_tool_==Pan)
|
||||
{
|
||||
drag_=false;
|
||||
if (map_)
|
||||
{
|
||||
int cx = int(0.5 * map_->width());
|
||||
int cy = int(0.5 * map_->height());
|
||||
int dx = end_x_ - start_x_;
|
||||
int dy = end_y_ - start_y_;
|
||||
map_->pan(cx - dx ,cy - dy);
|
||||
updateMap();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e->button() == Qt::LeftButton)
|
||||
{
|
||||
end_x_ = e->x();
|
||||
end_y_ = e->y();
|
||||
if (cur_tool_ == ZoomToBox)
|
||||
{
|
||||
drag_ = false;
|
||||
if (map_)
|
||||
{
|
||||
view_transform t(map_->width(), map_->height(), map_->get_current_extent());
|
||||
box2d<double> box = t.backward(box2d<double>(start_x_, start_y_, end_x_, end_y_));
|
||||
map_->zoom_to_box(box);
|
||||
updateMap();
|
||||
}
|
||||
}
|
||||
else if (cur_tool_ == Pan)
|
||||
{
|
||||
drag_ = false;
|
||||
if (map_)
|
||||
{
|
||||
int cx = int(0.5 * map_->width());
|
||||
int cy = int(0.5 * map_->height());
|
||||
int dx = end_x_ - start_x_;
|
||||
int dy = end_y_ - start_y_;
|
||||
map_->pan(cx - dx, cy - dy);
|
||||
updateMap();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MapWidget::wheelEvent(QWheelEvent* e)
|
||||
{
|
||||
if (!map_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
QPointF corner(map_->width(), map_->height());
|
||||
QPointF zoomCoords;
|
||||
double zoom;
|
||||
if (e->angleDelta().y() > 0)
|
||||
{
|
||||
zoom = 0.5;
|
||||
QPointF center = corner / 2;
|
||||
QPointF delta = e->position() - center;
|
||||
zoomCoords = zoom * delta + center;
|
||||
}
|
||||
else
|
||||
{
|
||||
zoom = 2.0;
|
||||
zoomCoords = corner - e->position();
|
||||
}
|
||||
if (!map_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
QPointF corner(map_->width(), map_->height());
|
||||
QPointF zoomCoords;
|
||||
double zoom;
|
||||
if (e->angleDelta().y() > 0)
|
||||
{
|
||||
zoom = 0.5;
|
||||
QPointF center = corner / 2;
|
||||
QPointF delta = e->position() - center;
|
||||
zoomCoords = zoom * delta + center;
|
||||
}
|
||||
else
|
||||
{
|
||||
zoom = 2.0;
|
||||
zoomCoords = corner - e->position();
|
||||
}
|
||||
#else
|
||||
QPoint corner(map_->width(), map_->height());
|
||||
QPoint zoomCoords;
|
||||
double zoom;
|
||||
if (e->delta() > 0)
|
||||
{
|
||||
zoom = 0.5;
|
||||
QPoint center = corner / 2;
|
||||
QPoint delta = e->pos() - center;
|
||||
zoomCoords = zoom * delta + center;
|
||||
}
|
||||
else
|
||||
{
|
||||
zoom = 2.0;
|
||||
zoomCoords = corner - e->pos();
|
||||
}
|
||||
QPoint corner(map_->width(), map_->height());
|
||||
QPoint zoomCoords;
|
||||
double zoom;
|
||||
if (e->delta() > 0)
|
||||
{
|
||||
zoom = 0.5;
|
||||
QPoint center = corner / 2;
|
||||
QPoint delta = e->pos() - center;
|
||||
zoomCoords = zoom * delta + center;
|
||||
}
|
||||
else
|
||||
{
|
||||
zoom = 2.0;
|
||||
zoomCoords = corner - e->pos();
|
||||
}
|
||||
#endif
|
||||
|
||||
map_->pan_and_zoom(zoomCoords.x(), zoomCoords.y(), zoom);
|
||||
updateMap();
|
||||
map_->pan_and_zoom(zoomCoords.x(), zoomCoords.y(), zoom);
|
||||
updateMap();
|
||||
}
|
||||
|
||||
void MapWidget::keyPressEvent(QKeyEvent *e)
|
||||
void MapWidget::keyPressEvent(QKeyEvent* e)
|
||||
{
|
||||
std::cout << "key pressed:"<< e->key()<<"\n";
|
||||
switch (e->key()) {
|
||||
case Qt::Key_Minus:
|
||||
zoomOut();
|
||||
break;
|
||||
case Qt::Key_Plus:
|
||||
case 61:
|
||||
zoomIn();
|
||||
break;
|
||||
case 65:
|
||||
defaultView();
|
||||
break;
|
||||
case Qt::Key_Up:
|
||||
panUp();
|
||||
break;
|
||||
case Qt::Key_Down:
|
||||
panDown();
|
||||
break;
|
||||
case Qt::Key_Left:
|
||||
panLeft();
|
||||
break;
|
||||
case Qt::Key_Right:
|
||||
panRight();
|
||||
break;
|
||||
case 49:
|
||||
zoomToLevel(10);
|
||||
break;
|
||||
case 50:
|
||||
zoomToLevel(11);
|
||||
break;
|
||||
case 51:
|
||||
zoomToLevel(12);
|
||||
break;
|
||||
case 52:
|
||||
zoomToLevel(13);
|
||||
break;
|
||||
case 53:
|
||||
zoomToLevel(14);
|
||||
break;
|
||||
case 54:
|
||||
zoomToLevel(15);
|
||||
break;
|
||||
case 55:
|
||||
zoomToLevel(16);
|
||||
break;
|
||||
case 56:
|
||||
zoomToLevel(17);
|
||||
break;
|
||||
case 57:
|
||||
zoomToLevel(18);
|
||||
break;
|
||||
default:
|
||||
QWidget::keyPressEvent(e);
|
||||
}
|
||||
|
||||
|
||||
std::cout << "key pressed:" << e->key() << "\n";
|
||||
switch (e->key())
|
||||
{
|
||||
case Qt::Key_Minus:
|
||||
zoomOut();
|
||||
break;
|
||||
case Qt::Key_Plus:
|
||||
case 61:
|
||||
zoomIn();
|
||||
break;
|
||||
case 65:
|
||||
defaultView();
|
||||
break;
|
||||
case Qt::Key_Up:
|
||||
panUp();
|
||||
break;
|
||||
case Qt::Key_Down:
|
||||
panDown();
|
||||
break;
|
||||
case Qt::Key_Left:
|
||||
panLeft();
|
||||
break;
|
||||
case Qt::Key_Right:
|
||||
panRight();
|
||||
break;
|
||||
case 49:
|
||||
zoomToLevel(10);
|
||||
break;
|
||||
case 50:
|
||||
zoomToLevel(11);
|
||||
break;
|
||||
case 51:
|
||||
zoomToLevel(12);
|
||||
break;
|
||||
case 52:
|
||||
zoomToLevel(13);
|
||||
break;
|
||||
case 53:
|
||||
zoomToLevel(14);
|
||||
break;
|
||||
case 54:
|
||||
zoomToLevel(15);
|
||||
break;
|
||||
case 55:
|
||||
zoomToLevel(16);
|
||||
break;
|
||||
case 56:
|
||||
zoomToLevel(17);
|
||||
break;
|
||||
case 57:
|
||||
zoomToLevel(18);
|
||||
break;
|
||||
default:
|
||||
QWidget::keyPressEvent(e);
|
||||
}
|
||||
}
|
||||
|
||||
void MapWidget::zoomToBox(mapnik::box2d<double> const& bbox)
|
||||
{
|
||||
if (map_)
|
||||
{
|
||||
map_->zoom_to_box(bbox);
|
||||
updateMap();
|
||||
}
|
||||
if (map_)
|
||||
{
|
||||
map_->zoom_to_box(bbox);
|
||||
updateMap();
|
||||
}
|
||||
}
|
||||
|
||||
void MapWidget::defaultView()
|
||||
{
|
||||
if (map_)
|
||||
{
|
||||
map_->resize(width(),height());
|
||||
map_->zoom_all();
|
||||
updateMap();
|
||||
}
|
||||
if (map_)
|
||||
{
|
||||
map_->resize(width(), height());
|
||||
map_->zoom_all();
|
||||
updateMap();
|
||||
}
|
||||
}
|
||||
|
||||
void MapWidget::zoomIn()
|
||||
{
|
||||
if (map_)
|
||||
{
|
||||
map_->zoom(0.5);
|
||||
updateMap();
|
||||
}
|
||||
if (map_)
|
||||
{
|
||||
map_->zoom(0.5);
|
||||
updateMap();
|
||||
}
|
||||
}
|
||||
|
||||
void MapWidget::zoomOut()
|
||||
{
|
||||
if (map_)
|
||||
{
|
||||
map_->zoom(2.0);
|
||||
updateMap();
|
||||
}
|
||||
if (map_)
|
||||
{
|
||||
map_->zoom(2.0);
|
||||
updateMap();
|
||||
}
|
||||
}
|
||||
|
||||
void MapWidget::panUp()
|
||||
{
|
||||
if (map_)
|
||||
{
|
||||
double cx = 0.5*map_->width();
|
||||
double cy = 0.5*map_->height();
|
||||
map_->pan(int(cx),int(cy - cy*0.25));
|
||||
updateMap();
|
||||
}
|
||||
if (map_)
|
||||
{
|
||||
double cx = 0.5 * map_->width();
|
||||
double cy = 0.5 * map_->height();
|
||||
map_->pan(int(cx), int(cy - cy * 0.25));
|
||||
updateMap();
|
||||
}
|
||||
}
|
||||
|
||||
void MapWidget::panDown()
|
||||
{
|
||||
if (map_)
|
||||
{
|
||||
double cx = 0.5*map_->width();
|
||||
double cy = 0.5*map_->height();
|
||||
map_->pan(int(cx),int(cy + cy*0.25));
|
||||
updateMap();
|
||||
}
|
||||
if (map_)
|
||||
{
|
||||
double cx = 0.5 * map_->width();
|
||||
double cy = 0.5 * map_->height();
|
||||
map_->pan(int(cx), int(cy + cy * 0.25));
|
||||
updateMap();
|
||||
}
|
||||
}
|
||||
|
||||
void MapWidget::panLeft()
|
||||
{
|
||||
if (map_)
|
||||
{
|
||||
double cx = 0.5*map_->width();
|
||||
double cy = 0.5*map_->height();
|
||||
map_->pan(int(cx - cx * 0.25),int(cy));
|
||||
updateMap();
|
||||
}
|
||||
if (map_)
|
||||
{
|
||||
double cx = 0.5 * map_->width();
|
||||
double cy = 0.5 * map_->height();
|
||||
map_->pan(int(cx - cx * 0.25), int(cy));
|
||||
updateMap();
|
||||
}
|
||||
}
|
||||
|
||||
void MapWidget::panRight()
|
||||
{
|
||||
if (map_)
|
||||
{
|
||||
double cx = 0.5*map_->width();
|
||||
double cy = 0.5*map_->height();
|
||||
map_->pan(int(cx + cx * 0.25),int(cy));
|
||||
updateMap();
|
||||
}
|
||||
if (map_)
|
||||
{
|
||||
double cx = 0.5 * map_->width();
|
||||
double cy = 0.5 * map_->height();
|
||||
map_->pan(int(cx + cx * 0.25), int(cy));
|
||||
updateMap();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MapWidget::zoomToLevel(int level)
|
||||
{
|
||||
if ( map_ && level >= 0 && level < 19 )
|
||||
{
|
||||
double scale_denom = scales[level];
|
||||
std::cerr << "scale denominator = " << scale_denom << "\n";
|
||||
mapnik::box2d<double> ext = map_->get_current_extent();
|
||||
double width = static_cast<double>(map_->width());
|
||||
double height= static_cast<double>(map_->height());
|
||||
mapnik::coord2d pt = ext.center();
|
||||
if (map_ && level >= 0 && level < 19)
|
||||
{
|
||||
double scale_denom = scales[level];
|
||||
std::cerr << "scale denominator = " << scale_denom << "\n";
|
||||
mapnik::box2d<double> ext = map_->get_current_extent();
|
||||
double width = static_cast<double>(map_->width());
|
||||
double height = static_cast<double>(map_->height());
|
||||
mapnik::coord2d pt = ext.center();
|
||||
|
||||
double res = scale_denom * 0.00028;
|
||||
double res = scale_denom * 0.00028;
|
||||
|
||||
mapnik::box2d<double> box(pt.x - 0.5 * width * res,
|
||||
pt.y - 0.5 * height*res,
|
||||
pt.x + 0.5 * width * res,
|
||||
pt.y + 0.5 * height*res);
|
||||
map_->zoom_to_box(box);
|
||||
updateMap();
|
||||
}
|
||||
mapnik::box2d<double> box(pt.x - 0.5 * width * res,
|
||||
pt.y - 0.5 * height * res,
|
||||
pt.x + 0.5 * width * res,
|
||||
pt.y + 0.5 * height * res);
|
||||
map_->zoom_to_box(box);
|
||||
updateMap();
|
||||
}
|
||||
}
|
||||
|
||||
void MapWidget::export_to_file(unsigned ,unsigned ,std::string const&,std::string const&)
|
||||
void MapWidget::export_to_file(unsigned, unsigned, std::string const&, std::string const&)
|
||||
{
|
||||
//image_rgba8 image(width,height);
|
||||
//agg_renderer renderer(map,image);
|
||||
//renderer.apply();
|
||||
//image.saveToFile(filename,type);
|
||||
// image_rgba8 image(width,height);
|
||||
// agg_renderer renderer(map,image);
|
||||
// renderer.apply();
|
||||
// image.saveToFile(filename,type);
|
||||
std::cout << "Export to file .." << std::endl;
|
||||
}
|
||||
|
||||
|
@ -509,47 +491,44 @@ void MapWidget::set_scaling_factor(double scaling_factor)
|
|||
scaling_factor_ = scaling_factor;
|
||||
}
|
||||
|
||||
void render_agg(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
|
||||
void render_agg(mapnik::Map const& map, double scaling_factor, QPixmap& pix)
|
||||
{
|
||||
unsigned width=map.width();
|
||||
unsigned height=map.height();
|
||||
unsigned width = map.width();
|
||||
unsigned height = map.height();
|
||||
|
||||
image_rgba8 buf(width,height);
|
||||
mapnik::agg_renderer<image_rgba8> ren(map,buf,scaling_factor);
|
||||
image_rgba8 buf(width, height);
|
||||
mapnik::agg_renderer<image_rgba8> ren(map, buf, scaling_factor);
|
||||
|
||||
try
|
||||
{
|
||||
mapnik::auto_cpu_timer t(std::clog, "rendering took: ");
|
||||
ren.apply();
|
||||
QImage image((uchar*)buf.data(),width,height,QImage::Format_ARGB32);
|
||||
QImage image((uchar*)buf.data(), width, height, QImage::Format_ARGB32);
|
||||
pix = QPixmap::fromImage(image.rgbSwapped());
|
||||
}
|
||||
//catch (mapnik::config_error & ex)
|
||||
// catch (mapnik::config_error & ex)
|
||||
//{
|
||||
// std::cerr << ex.what() << std::endl;
|
||||
//}
|
||||
// std::cerr << ex.what() << std::endl;
|
||||
// }
|
||||
catch (std::exception const& ex)
|
||||
{
|
||||
std::cerr << "exception: " << ex.what() << std::endl;
|
||||
}
|
||||
catch (...)
|
||||
} catch (...)
|
||||
{
|
||||
std::cerr << "Unknown exception caught!\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void render_grid(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
|
||||
void render_grid(mapnik::Map const& map, double scaling_factor, QPixmap& pix)
|
||||
{
|
||||
std::cerr << "Not supported" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void render_cairo(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
|
||||
void render_cairo(mapnik::Map const& map, double scaling_factor, QPixmap& pix)
|
||||
{
|
||||
// FIXME
|
||||
#ifdef HAVE_CAIRO
|
||||
mapnik::cairo_surface_ptr image_surface(cairo_image_surface_create(CAIRO_FORMAT_ARGB32,map.width(),map.height()),
|
||||
mapnik::cairo_surface_ptr image_surface(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, map.width(), map.height()),
|
||||
mapnik::cairo_surface_closer());
|
||||
mapnik::cairo_ptr cairo = mapnik::create_context(image_surface);
|
||||
if (cairo)
|
||||
|
@ -560,16 +539,19 @@ void render_cairo(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
|
|||
}
|
||||
mapnik::image_rgba8 data(map.width(), map.height());
|
||||
mapnik::cairo_image_to_rgba8(data, image_surface);
|
||||
QImage image((uchar*)data.bytes(),data.width(),data.height(),QImage::Format_ARGB32);
|
||||
QImage image((uchar*)data.bytes(), data.width(), data.height(), QImage::Format_ARGB32);
|
||||
pix = QPixmap::fromImage(image.rgbSwapped());
|
||||
#endif
|
||||
}
|
||||
|
||||
void MapWidget::updateRenderer(QString const& txt)
|
||||
{
|
||||
if (txt == "AGG") cur_renderer_ = AGG;
|
||||
else if (txt == "Cairo") cur_renderer_ = Cairo;
|
||||
else if (txt == "Grid") cur_renderer_ = Grid;
|
||||
if (txt == "AGG")
|
||||
cur_renderer_ = AGG;
|
||||
else if (txt == "Cairo")
|
||||
cur_renderer_ = Cairo;
|
||||
else if (txt == "Grid")
|
||||
cur_renderer_ = Grid;
|
||||
std::cerr << "Update renderer called" << std::endl;
|
||||
updateMap();
|
||||
}
|
||||
|
@ -582,50 +564,49 @@ void MapWidget::updateScaleFactor(double scale_factor)
|
|||
|
||||
void MapWidget::updateMap()
|
||||
{
|
||||
if (map_)
|
||||
{
|
||||
if (cur_renderer_== AGG)
|
||||
{
|
||||
render_agg(*map_, scaling_factor_, pix_);
|
||||
}
|
||||
else if (cur_renderer_ == Cairo)
|
||||
{
|
||||
render_cairo(*map_, scaling_factor_, pix_);
|
||||
}
|
||||
else if (cur_renderer_ == Grid)
|
||||
{
|
||||
render_grid(*map_, scaling_factor_, pix_);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Unknown renderer..." << std::endl;
|
||||
}
|
||||
if (map_)
|
||||
{
|
||||
if (cur_renderer_ == AGG)
|
||||
{
|
||||
render_agg(*map_, scaling_factor_, pix_);
|
||||
}
|
||||
else if (cur_renderer_ == Cairo)
|
||||
{
|
||||
render_cairo(*map_, scaling_factor_, pix_);
|
||||
}
|
||||
else if (cur_renderer_ == Grid)
|
||||
{
|
||||
render_grid(*map_, scaling_factor_, pix_);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Unknown renderer..." << std::endl;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
projection prj(map_->srs(), true); // map projection
|
||||
box2d<double> ext = map_->get_current_extent();
|
||||
double x0 = ext.minx();
|
||||
double y0 = ext.miny();
|
||||
double x1 = ext.maxx();
|
||||
double y1 = ext.maxy();
|
||||
double z = 0;
|
||||
std::string dest_srs = {"epsg:4326"};
|
||||
mapnik::proj_transform proj_tr(map_->srs(), dest_srs);
|
||||
try
|
||||
{
|
||||
projection prj(map_->srs(), true); // map projection
|
||||
box2d<double> ext = map_->get_current_extent();
|
||||
double x0 = ext.minx();
|
||||
double y0 = ext.miny();
|
||||
double x1 = ext.maxx();
|
||||
double y1 = ext.maxy();
|
||||
double z = 0;
|
||||
std::string dest_srs = {"epsg:4326"};
|
||||
mapnik::proj_transform proj_tr(map_->srs(), dest_srs);
|
||||
|
||||
proj_tr.forward(x0, y0, z);
|
||||
proj_tr.forward(x1, y1, z);
|
||||
std::cout << "MAP SIZE:" << map_->width() << "," << map_->height() << std::endl;
|
||||
std::cout << "BBOX (WGS84): " << x0 << "," << y0 << "," << x1 << "," << y1 << "\n";
|
||||
update();
|
||||
// emit signal to interested widgets
|
||||
emit mapViewChanged();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cerr << "Unknown exception caught!\n";
|
||||
}
|
||||
}
|
||||
proj_tr.forward(x0, y0, z);
|
||||
proj_tr.forward(x1, y1, z);
|
||||
std::cout << "MAP SIZE:" << map_->width() << "," << map_->height() << std::endl;
|
||||
std::cout << "BBOX (WGS84): " << x0 << "," << y0 << "," << x1 << "," << y1 << "\n";
|
||||
update();
|
||||
// emit signal to interested widgets
|
||||
emit mapViewChanged();
|
||||
} catch (...)
|
||||
{
|
||||
std::cerr << "Unknown exception caught!\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Map> MapWidget::getMap()
|
||||
|
@ -638,7 +619,6 @@ void MapWidget::setMap(std::shared_ptr<Map> map)
|
|||
map_ = map;
|
||||
}
|
||||
|
||||
|
||||
void MapWidget::layerSelected(int index)
|
||||
{
|
||||
selectedLayer_ = index;
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MAP_WIDGET_HPP
|
||||
#define MAP_WIDGET_HPP
|
||||
|
||||
|
@ -30,7 +29,6 @@
|
|||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
|
||||
#ifndef Q_MOC_RUN
|
||||
#include <mapnik/map.hpp>
|
||||
#endif
|
||||
|
@ -39,22 +37,16 @@ class MapWidget : public QWidget
|
|||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum eTool
|
||||
{
|
||||
public:
|
||||
enum eTool {
|
||||
ZoomToBox = 1,
|
||||
Pan,
|
||||
Info,
|
||||
};
|
||||
|
||||
enum eRenderer
|
||||
{
|
||||
AGG,
|
||||
Cairo,
|
||||
Grid
|
||||
};
|
||||
enum eRenderer { AGG, Cairo, Grid };
|
||||
|
||||
private:
|
||||
private:
|
||||
std::shared_ptr<mapnik::Map> map_;
|
||||
int selected_;
|
||||
QPixmap pix_;
|
||||
|
@ -70,11 +62,12 @@ private:
|
|||
int selectedLayer_;
|
||||
double scaling_factor_;
|
||||
eRenderer cur_renderer_;
|
||||
public:
|
||||
MapWidget(QWidget *parent=0);
|
||||
|
||||
public:
|
||||
MapWidget(QWidget* parent = 0);
|
||||
void setTool(eTool tool);
|
||||
std::shared_ptr<mapnik::Map> getMap();
|
||||
inline QPixmap const& pixmap() const { return pix_;}
|
||||
inline QPixmap const& pixmap() const { return pix_; }
|
||||
void setMap(std::shared_ptr<mapnik::Map> map);
|
||||
void defaultView();
|
||||
void zoomToBox(mapnik::box2d<double> const& box);
|
||||
|
@ -85,26 +78,24 @@ public:
|
|||
void panUp();
|
||||
void panDown();
|
||||
void set_scaling_factor(double);
|
||||
public slots:
|
||||
public slots:
|
||||
void zoomToLevel(int level);
|
||||
void updateMap();
|
||||
void layerSelected(int);
|
||||
void updateRenderer(QString const& txt);
|
||||
void updateScaleFactor(double scale_factor);
|
||||
signals:
|
||||
signals:
|
||||
void mapViewChanged();
|
||||
protected:
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* ev);
|
||||
void resizeEvent(QResizeEvent* ev);
|
||||
void mousePressEvent(QMouseEvent* e);
|
||||
void mouseMoveEvent(QMouseEvent* e);
|
||||
void mouseReleaseEvent(QMouseEvent* e);
|
||||
void wheelEvent(QWheelEvent* e);
|
||||
void keyPressEvent(QKeyEvent *e);
|
||||
void export_to_file(unsigned width,
|
||||
unsigned height,
|
||||
std::string const& filename,
|
||||
std::string const& type);
|
||||
void keyPressEvent(QKeyEvent* e);
|
||||
void export_to_file(unsigned width, unsigned height, std::string const& filename, std::string const& type);
|
||||
};
|
||||
|
||||
#endif // MAP_WIDGET_HPP
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#include "styles_model.hpp"
|
||||
#include <mapnik/config.hpp>
|
||||
#include <mapnik/util/variant.hpp>
|
||||
|
@ -39,70 +38,50 @@ class node : private mapnik::util::noncopyable
|
|||
{
|
||||
struct node_base
|
||||
{
|
||||
virtual QString name() const=0;
|
||||
virtual QIcon icon() const=0;
|
||||
virtual QString name() const = 0;
|
||||
virtual QIcon icon() const = 0;
|
||||
virtual ~node_base() {}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
struct wrap : public node_base
|
||||
{
|
||||
wrap(T const& obj)
|
||||
: obj_(obj) {}
|
||||
wrap(T const& obj)
|
||||
: obj_(obj)
|
||||
{}
|
||||
|
||||
~wrap() {}
|
||||
~wrap() {}
|
||||
|
||||
QString name () const
|
||||
{
|
||||
return obj_.name();
|
||||
}
|
||||
QString name() const { return obj_.name(); }
|
||||
|
||||
QIcon icon() const
|
||||
{
|
||||
return obj_.icon();
|
||||
}
|
||||
QIcon icon() const { return obj_.icon(); }
|
||||
|
||||
T obj_;
|
||||
T obj_;
|
||||
};
|
||||
|
||||
public:
|
||||
template <typename T>
|
||||
node ( T const& obj, node * parent=0)
|
||||
: impl_(new wrap<T>(obj)),
|
||||
parent_(parent)
|
||||
public:
|
||||
template<typename T>
|
||||
node(T const& obj, node* parent = 0)
|
||||
: impl_(new wrap<T>(obj))
|
||||
, parent_(parent)
|
||||
{}
|
||||
|
||||
QString name() const
|
||||
{
|
||||
return impl_->name();
|
||||
}
|
||||
QString name() const { return impl_->name(); }
|
||||
|
||||
QIcon icon() const
|
||||
{
|
||||
return impl_->icon();
|
||||
}
|
||||
QIcon icon() const { return impl_->icon(); }
|
||||
|
||||
unsigned num_children() const
|
||||
{
|
||||
return children_.count();
|
||||
}
|
||||
unsigned num_children() const { return children_.count(); }
|
||||
|
||||
node * child(unsigned row) const
|
||||
{
|
||||
return children_.value(row);
|
||||
}
|
||||
node* child(unsigned row) const { return children_.value(row); }
|
||||
|
||||
node * parent() const
|
||||
{
|
||||
return parent_;
|
||||
}
|
||||
node* parent() const { return parent_; }
|
||||
|
||||
node * add_child(node * child)
|
||||
node* add_child(node* child)
|
||||
{
|
||||
children_.push_back(child);
|
||||
return child;
|
||||
}
|
||||
int row () const
|
||||
int row() const
|
||||
{
|
||||
if (parent_)
|
||||
return parent_->children_.indexOf(const_cast<node*>(this));
|
||||
|
@ -110,94 +89,90 @@ public:
|
|||
return 0;
|
||||
}
|
||||
|
||||
~node()
|
||||
{
|
||||
qDeleteAll(children_);
|
||||
}
|
||||
~node() { qDeleteAll(children_); }
|
||||
|
||||
private:
|
||||
private:
|
||||
const std::unique_ptr<node_base> impl_;
|
||||
QList<node*> children_;
|
||||
node * parent_;
|
||||
node* parent_;
|
||||
};
|
||||
|
||||
|
||||
struct symbolizer_info
|
||||
{
|
||||
QString operator() (mapnik::point_symbolizer const& sym) const
|
||||
QString operator()(mapnik::point_symbolizer const& sym) const
|
||||
{
|
||||
boost::ignore_unused_variable_warning(sym);
|
||||
return QString("PointSymbolizer");
|
||||
}
|
||||
|
||||
QString operator() (mapnik::line_symbolizer const& sym) const
|
||||
QString operator()(mapnik::line_symbolizer const& sym) const
|
||||
{
|
||||
boost::ignore_unused_variable_warning(sym);
|
||||
return QString("LineSymbolizer");
|
||||
}
|
||||
|
||||
QString operator() (mapnik::line_pattern_symbolizer const& sym) const
|
||||
QString operator()(mapnik::line_pattern_symbolizer const& sym) const
|
||||
{
|
||||
boost::ignore_unused_variable_warning(sym);
|
||||
return QString("LinePatternSymbolizer");
|
||||
}
|
||||
|
||||
QString operator() (mapnik::polygon_symbolizer const& sym) const
|
||||
QString operator()(mapnik::polygon_symbolizer const& sym) const
|
||||
{
|
||||
boost::ignore_unused_variable_warning(sym);
|
||||
return QString("PolygonSymbolizer");
|
||||
}
|
||||
|
||||
QString operator() (mapnik::polygon_pattern_symbolizer const& sym) const
|
||||
QString operator()(mapnik::polygon_pattern_symbolizer const& sym) const
|
||||
{
|
||||
boost::ignore_unused_variable_warning(sym);
|
||||
return QString("PolygonSymbolizer");
|
||||
}
|
||||
|
||||
QString operator() (mapnik::text_symbolizer const& sym) const
|
||||
QString operator()(mapnik::text_symbolizer const& sym) const
|
||||
{
|
||||
boost::ignore_unused_variable_warning(sym);
|
||||
return QString("TextSymbolizer");
|
||||
}
|
||||
|
||||
QString operator() (mapnik::shield_symbolizer const& sym) const
|
||||
QString operator()(mapnik::shield_symbolizer const& sym) const
|
||||
{
|
||||
boost::ignore_unused_variable_warning(sym);
|
||||
return QString("ShieldSymbolizer");
|
||||
}
|
||||
|
||||
QString operator() (mapnik::markers_symbolizer const& sym) const
|
||||
QString operator()(mapnik::markers_symbolizer const& sym) const
|
||||
{
|
||||
boost::ignore_unused_variable_warning(sym);
|
||||
return QString("MarkersSymbolizer");
|
||||
}
|
||||
|
||||
QString operator() (mapnik::building_symbolizer const& sym) const
|
||||
QString operator()(mapnik::building_symbolizer const& sym) const
|
||||
{
|
||||
boost::ignore_unused_variable_warning(sym);
|
||||
return QString("BuildingSymbolizer");
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
QString operator() (T const& ) const
|
||||
template<typename T>
|
||||
QString operator()(T const&) const
|
||||
{
|
||||
return QString ("FIXME");
|
||||
return QString("FIXME");
|
||||
}
|
||||
};
|
||||
|
||||
struct symbolizer_icon
|
||||
{
|
||||
QIcon operator() (mapnik::polygon_symbolizer const& sym) const
|
||||
QIcon operator()(mapnik::polygon_symbolizer const& sym) const
|
||||
{
|
||||
QPixmap pix(16,16);
|
||||
QPixmap pix(16, 16);
|
||||
QPainter painter(&pix);
|
||||
mapnik::color const& fill = mapnik::get<mapnik::color>(sym, mapnik::keys::fill);
|
||||
QBrush brush(QColor(fill.red(),fill.green(),fill.blue(),fill.alpha()));
|
||||
QBrush brush(QColor(fill.red(), fill.green(), fill.blue(), fill.alpha()));
|
||||
painter.fillRect(0, 0, 16, 16, brush);
|
||||
return QIcon(pix);
|
||||
}
|
||||
|
||||
QIcon operator() (mapnik::point_symbolizer const& sym) const
|
||||
QIcon operator()(mapnik::point_symbolizer const& sym) const
|
||||
{
|
||||
// FIXME!
|
||||
/*
|
||||
|
@ -212,55 +187,57 @@ struct symbolizer_icon
|
|||
*/
|
||||
return QIcon();
|
||||
}
|
||||
QIcon operator() (mapnik::line_symbolizer const& sym) const
|
||||
QIcon operator()(mapnik::line_symbolizer const& sym) const
|
||||
{
|
||||
QPixmap pix(48,16);
|
||||
QPixmap pix(48, 16);
|
||||
pix.fill();
|
||||
QPainter painter(&pix);
|
||||
//mapnik::stroke const& strk = sym.get_stroke();
|
||||
// mapnik::stroke const& strk = sym.get_stroke();
|
||||
mapnik::color const& col = mapnik::get<mapnik::color>(sym, mapnik::keys::stroke);
|
||||
QPen pen(QColor(col.red(),col.green(),col.blue(),col.alpha()));
|
||||
QPen pen(QColor(col.red(), col.green(), col.blue(), col.alpha()));
|
||||
pen.setWidth(mapnik::get<double>(sym, mapnik::keys::width));
|
||||
painter.setPen(pen);
|
||||
painter.drawLine(0,7,47,7);
|
||||
//painter.drawLine(7,15,12,0);
|
||||
//painter.drawLine(12,0,8,15);
|
||||
painter.drawLine(0, 7, 47, 7);
|
||||
// painter.drawLine(7,15,12,0);
|
||||
// painter.drawLine(12,0,8,15);
|
||||
return QIcon(pix);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
QIcon operator() (T const& ) const
|
||||
template<typename T>
|
||||
QIcon operator()(T const&) const
|
||||
{
|
||||
return QIcon (":/images/filter.png");
|
||||
return QIcon(":/images/filter.png");
|
||||
}
|
||||
};
|
||||
|
||||
class symbolizer_node
|
||||
{
|
||||
public:
|
||||
symbolizer_node(mapnik::symbolizer const & sym)
|
||||
: sym_(sym) {}
|
||||
~symbolizer_node(){}
|
||||
public:
|
||||
symbolizer_node(mapnik::symbolizer const& sym)
|
||||
: sym_(sym)
|
||||
{}
|
||||
~symbolizer_node() {}
|
||||
|
||||
QString name() const
|
||||
{
|
||||
//return QString("Symbolizer:fixme");
|
||||
return mapnik::util::apply_visitor(symbolizer_info(),sym_);
|
||||
// return QString("Symbolizer:fixme");
|
||||
return mapnik::util::apply_visitor(symbolizer_info(), sym_);
|
||||
}
|
||||
|
||||
QIcon icon() const
|
||||
{
|
||||
return mapnik::util::apply_visitor(symbolizer_icon(),sym_);//QIcon(":/images/filter.png");
|
||||
return mapnik::util::apply_visitor(symbolizer_icon(), sym_); // QIcon(":/images/filter.png");
|
||||
}
|
||||
mapnik::symbolizer const& sym_;
|
||||
};
|
||||
|
||||
class rule_node
|
||||
{
|
||||
public:
|
||||
rule_node(QString name,mapnik::rule const & r)
|
||||
: name_(name),
|
||||
rule_(r) {}
|
||||
public:
|
||||
rule_node(QString name, mapnik::rule const& r)
|
||||
: name_(name)
|
||||
, rule_(r)
|
||||
{}
|
||||
~rule_node() {}
|
||||
QString name() const
|
||||
{
|
||||
|
@ -268,81 +245,68 @@ public:
|
|||
return QString(mapnik::to_expression_string(*filter).c_str());
|
||||
}
|
||||
|
||||
QIcon icon() const
|
||||
{
|
||||
return QIcon(":/images/filter.png");
|
||||
}
|
||||
QIcon icon() const { return QIcon(":/images/filter.png"); }
|
||||
|
||||
private:
|
||||
private:
|
||||
QString name_;
|
||||
mapnik::rule const& rule_;
|
||||
};
|
||||
|
||||
class style_node
|
||||
{
|
||||
public:
|
||||
public:
|
||||
style_node(QString name, mapnik::feature_type_style const& style)
|
||||
: name_(name),
|
||||
style_(style) {}
|
||||
: name_(name)
|
||||
, style_(style)
|
||||
{}
|
||||
|
||||
~style_node() {}
|
||||
|
||||
QString name() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
QString name() const { return name_; }
|
||||
|
||||
QIcon icon() const
|
||||
{
|
||||
return QIcon(":/images/style.png");
|
||||
}
|
||||
QIcon icon() const { return QIcon(":/images/style.png"); }
|
||||
|
||||
private:
|
||||
private:
|
||||
QString name_;
|
||||
mapnik::feature_type_style const& style_;
|
||||
};
|
||||
|
||||
class map_node
|
||||
{
|
||||
public:
|
||||
public:
|
||||
explicit map_node(std::shared_ptr<mapnik::Map> map)
|
||||
: map_(map) {}
|
||||
: map_(map)
|
||||
{}
|
||||
~map_node() {}
|
||||
|
||||
QString name() const
|
||||
{
|
||||
return QString("Map");
|
||||
}
|
||||
QString name() const { return QString("Map"); }
|
||||
|
||||
QIcon icon() const
|
||||
{
|
||||
return QIcon(":/images/map.png");
|
||||
}
|
||||
QIcon icon() const { return QIcon(":/images/map.png"); }
|
||||
|
||||
private:
|
||||
private:
|
||||
std::shared_ptr<mapnik::Map> map_;
|
||||
};
|
||||
|
||||
StyleModel::StyleModel(std::shared_ptr<mapnik::Map> map, QObject * parent)
|
||||
: QAbstractItemModel(parent),
|
||||
root_(new node(map_node(map)))
|
||||
StyleModel::StyleModel(std::shared_ptr<mapnik::Map> map, QObject* parent)
|
||||
: QAbstractItemModel(parent)
|
||||
, root_(new node(map_node(map)))
|
||||
{
|
||||
using style_type = std::map<std::string,mapnik::feature_type_style>;
|
||||
style_type const & styles = map->styles();
|
||||
using style_type = std::map<std::string, mapnik::feature_type_style>;
|
||||
style_type const& styles = map->styles();
|
||||
style_type::const_iterator itr = styles.begin();
|
||||
style_type::const_iterator end = styles.end();
|
||||
for (; itr != end; ++itr)
|
||||
{
|
||||
node * style_n = root_->add_child(new node(style_node(QString(itr->first.c_str()),itr->second),root_.get()));
|
||||
node* style_n = root_->add_child(new node(style_node(QString(itr->first.c_str()), itr->second), root_.get()));
|
||||
mapnik::rules const& rules = itr->second.get_rules();
|
||||
mapnik::rules::const_iterator itr2 = rules.begin();
|
||||
for ( ; itr2 != rules.end();++itr2)
|
||||
for (; itr2 != rules.end(); ++itr2)
|
||||
{
|
||||
node* rule_n = style_n->add_child(new node(rule_node(QString("Rule"),*itr2),style_n));
|
||||
node* rule_n = style_n->add_child(new node(rule_node(QString("Rule"), *itr2), style_n));
|
||||
mapnik::rule::symbolizers::const_iterator itr3 = (*itr2).begin();
|
||||
for ( ; itr3 !=itr2->end();++itr3)
|
||||
for (; itr3 != itr2->end(); ++itr3)
|
||||
{
|
||||
rule_n->add_child(new node(symbolizer_node(*itr3),rule_n));
|
||||
rule_n->add_child(new node(symbolizer_node(*itr3), rule_n));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -351,38 +315,39 @@ StyleModel::StyleModel(std::shared_ptr<mapnik::Map> map, QObject * parent)
|
|||
StyleModel::~StyleModel() {}
|
||||
|
||||
// interface
|
||||
QModelIndex StyleModel::index (int row, int col, QModelIndex const& parent) const
|
||||
QModelIndex StyleModel::index(int row, int col, QModelIndex const& parent) const
|
||||
{
|
||||
// qDebug("index() row=%d col=%d parent::internalId() = %lld", row,col,parent.internalId());
|
||||
node * parent_node;
|
||||
// qDebug("index() row=%d col=%d parent::internalId() = %lld", row,col,parent.internalId());
|
||||
node* parent_node;
|
||||
|
||||
if (!parent.isValid())
|
||||
parent_node = root_.get();
|
||||
else
|
||||
parent_node = static_cast<node*>(parent.internalPointer());
|
||||
|
||||
node * child_node = parent_node->child(row);
|
||||
node* child_node = parent_node->child(row);
|
||||
if (child_node)
|
||||
return createIndex(row,col,child_node);
|
||||
return createIndex(row, col, child_node);
|
||||
else
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
QModelIndex StyleModel::parent (QModelIndex const& index) const
|
||||
QModelIndex StyleModel::parent(QModelIndex const& index) const
|
||||
{
|
||||
node * child_node = static_cast<node*>(index.internalPointer());
|
||||
node * parent_node = child_node->parent();
|
||||
node* child_node = static_cast<node*>(index.internalPointer());
|
||||
node* parent_node = child_node->parent();
|
||||
if (parent_node == root_.get())
|
||||
return QModelIndex();
|
||||
|
||||
return createIndex(parent_node->row(),0,parent_node);
|
||||
return createIndex(parent_node->row(), 0, parent_node);
|
||||
}
|
||||
|
||||
int StyleModel::rowCount(QModelIndex const& parent) const
|
||||
{
|
||||
//qDebug("rowCount");
|
||||
node * parent_node;
|
||||
if (parent.column() > 0) return 0;
|
||||
// qDebug("rowCount");
|
||||
node* parent_node;
|
||||
if (parent.column() > 0)
|
||||
return 0;
|
||||
if (!parent.isValid())
|
||||
parent_node = root_.get();
|
||||
else
|
||||
|
@ -390,25 +355,24 @@ int StyleModel::rowCount(QModelIndex const& parent) const
|
|||
return parent_node->num_children();
|
||||
}
|
||||
|
||||
int StyleModel::columnCount( QModelIndex const&) const
|
||||
int StyleModel::columnCount(QModelIndex const&) const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
QVariant StyleModel::data(const QModelIndex & index, int role) const
|
||||
QVariant StyleModel::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
//qDebug("data index::internalId() = %lld", index.internalId());
|
||||
// qDebug("data index::internalId() = %lld", index.internalId());
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
node * cur_node = static_cast<node*>(index.internalPointer());
|
||||
node* cur_node = static_cast<node*>(index.internalPointer());
|
||||
if (cur_node)
|
||||
{
|
||||
if (role == Qt::DisplayRole)
|
||||
{
|
||||
|
||||
return QVariant(cur_node->name());
|
||||
}
|
||||
else if ( role == Qt::DecorationRole)
|
||||
else if (role == Qt::DecorationRole)
|
||||
{
|
||||
return cur_node->icon();
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef STYLE_MODEL_HPP
|
||||
#define STYLE_MODEL_HPP
|
||||
|
||||
|
@ -27,24 +26,23 @@
|
|||
#include <mapnik/map.hpp>
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
class node;
|
||||
class StyleModel : public QAbstractItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
StyleModel(std::shared_ptr<mapnik::Map> map, QObject * parent=0);
|
||||
~StyleModel();
|
||||
// interface
|
||||
QModelIndex index (int row, int col, QModelIndex const& parent = QModelIndex()) const;
|
||||
QModelIndex parent (QModelIndex const& child) const;
|
||||
int rowCount( QModelIndex const& parent = QModelIndex()) const;
|
||||
int columnCount( QModelIndex const& parent = QModelIndex()) const;
|
||||
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
|
||||
private:
|
||||
//std::shared_ptr<mapnik::Map> map_;
|
||||
const std::unique_ptr<node> root_;
|
||||
StyleModel(std::shared_ptr<mapnik::Map> map, QObject* parent = 0);
|
||||
~StyleModel();
|
||||
// interface
|
||||
QModelIndex index(int row, int col, QModelIndex const& parent = QModelIndex()) const;
|
||||
QModelIndex parent(QModelIndex const& child) const;
|
||||
int rowCount(QModelIndex const& parent = QModelIndex()) const;
|
||||
int columnCount(QModelIndex const& parent = QModelIndex()) const;
|
||||
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
||||
|
||||
private:
|
||||
// std::shared_ptr<mapnik::Map> map_;
|
||||
const std::unique_ptr<node> root_;
|
||||
};
|
||||
|
||||
#endif // STYLE_MODEL_HPP
|
||||
|
|
|
@ -9,8 +9,7 @@ MAPNIK_DISABLE_WARNING_PUSH
|
|||
#include "agg_conv_smooth_poly1.h"
|
||||
MAPNIK_DISABLE_WARNING_POP
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
namespace mapnik {
|
||||
|
||||
struct vcgen_smooth_calucate_adaptive
|
||||
{
|
||||
|
@ -57,12 +56,8 @@ struct vcgen_smooth_calucate_adaptive
|
|||
}
|
||||
}
|
||||
|
||||
return {
|
||||
{v1.x + s1 * smooth_value * (v2.x - xm1),
|
||||
v1.y + s1 * smooth_value * (v2.y - ym1)},
|
||||
{v2.x + s2 * smooth_value * (v1.x - xm2),
|
||||
v2.y + s2 * smooth_value * (v1.y - ym2)}
|
||||
};
|
||||
return {{v1.x + s1 * smooth_value * (v2.x - xm1), v1.y + s1 * smooth_value * (v2.y - ym1)},
|
||||
{v2.x + s2 * smooth_value * (v1.x - xm2), v2.y + s2 * smooth_value * (v1.y - ym2)}};
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -71,7 +66,7 @@ using vcgen_smooth_adaptive = agg::vcgen_smooth<vcgen_smooth_calucate_adaptive>;
|
|||
template<class VertexSource>
|
||||
using conv_smooth_adaptive = agg::conv_smooth_curve<VertexSource, vcgen_smooth_adaptive>;
|
||||
|
||||
template <typename Geometry>
|
||||
template<typename Geometry>
|
||||
class smooth_converter
|
||||
{
|
||||
Geometry geom_;
|
||||
|
@ -81,9 +76,9 @@ class smooth_converter
|
|||
using impl_type = util::variant<basic_impl_type, adaptive_impl_type>;
|
||||
impl_type impl_;
|
||||
|
||||
impl_type init_impl(smooth_algorithm_enum algo, Geometry & geom) const
|
||||
impl_type init_impl(smooth_algorithm_enum algo, Geometry& geom) const
|
||||
{
|
||||
switch(algo)
|
||||
switch (algo)
|
||||
{
|
||||
case SMOOTH_ALGORITHM_ADAPTIVE:
|
||||
return adaptive_impl_type(geom);
|
||||
|
@ -94,46 +89,35 @@ class smooth_converter
|
|||
return basic_impl_type(geom);
|
||||
}
|
||||
|
||||
public:
|
||||
smooth_converter(Geometry & geom) :
|
||||
geom_(geom),
|
||||
impl_(std::move(init_impl(SMOOTH_ALGORITHM_BASIC, geom)))
|
||||
public:
|
||||
smooth_converter(Geometry& geom)
|
||||
: geom_(geom)
|
||||
, impl_(std::move(init_impl(SMOOTH_ALGORITHM_BASIC, geom)))
|
||||
{}
|
||||
|
||||
void algorithm(smooth_algorithm_enum algo)
|
||||
{
|
||||
impl_ = init_impl(algo, geom_);
|
||||
}
|
||||
void algorithm(smooth_algorithm_enum algo) { impl_ = init_impl(algo, geom_); }
|
||||
|
||||
void smooth_value(double v)
|
||||
{
|
||||
return util::apply_visitor([=](auto & impl) {
|
||||
impl.smooth_value(v);
|
||||
}, impl_);
|
||||
return util::apply_visitor([=](auto& impl) { impl.smooth_value(v); }, impl_);
|
||||
}
|
||||
|
||||
void rewind(unsigned path_id)
|
||||
{
|
||||
return util::apply_visitor([=](auto & impl) {
|
||||
return impl.rewind(path_id);
|
||||
}, impl_);
|
||||
return util::apply_visitor([=](auto& impl) { return impl.rewind(path_id); }, impl_);
|
||||
}
|
||||
|
||||
unsigned vertex(double* x, double* y)
|
||||
{
|
||||
return util::apply_visitor([=](auto & impl) {
|
||||
return impl.vertex(x, y);
|
||||
}, impl_);
|
||||
return util::apply_visitor([=](auto& impl) { return impl.vertex(x, y); }, impl_);
|
||||
}
|
||||
|
||||
unsigned type() const
|
||||
{
|
||||
return util::apply_visitor([](auto const& impl) {
|
||||
return impl.type();
|
||||
}, impl_);
|
||||
return util::apply_visitor([](auto const& impl) { return impl.type(); }, impl_);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_ADAPTIVE_SMOOTH_HPP
|
||||
|
|
|
@ -69,7 +69,7 @@ struct agg_pattern_base
|
|||
}
|
||||
};
|
||||
|
||||
template <typename VertexConverter>
|
||||
template<typename VertexConverter>
|
||||
struct agg_polygon_pattern : agg_pattern_base
|
||||
{
|
||||
using color_type = agg::rgba8;
|
||||
|
@ -78,41 +78,40 @@ struct agg_polygon_pattern : agg_pattern_base
|
|||
using pixfmt_type = agg::pixfmt_custom_blend_rgba<blender_type, agg::rendering_buffer>;
|
||||
using wrap_x_type = agg::wrap_mode_repeat;
|
||||
using wrap_y_type = agg::wrap_mode_repeat;
|
||||
using img_source_type = agg::image_accessor_wrap<agg::pixfmt_rgba32_pre,
|
||||
wrap_x_type,
|
||||
wrap_y_type>;
|
||||
using img_source_type = agg::image_accessor_wrap<agg::pixfmt_rgba32_pre, wrap_x_type, wrap_y_type>;
|
||||
using span_gen_type = agg::span_pattern_rgba<img_source_type>;
|
||||
using renderer_base = agg::renderer_base<pixfmt_type>;
|
||||
using renderer_type = agg::renderer_scanline_aa_alpha<renderer_base,
|
||||
agg::span_allocator<agg::rgba8>,
|
||||
span_gen_type>;
|
||||
using renderer_type =
|
||||
agg::renderer_scanline_aa_alpha<renderer_base, agg::span_allocator<agg::rgba8>, span_gen_type>;
|
||||
|
||||
agg_polygon_pattern(image_rgba8 const& pattern_img,
|
||||
renderer_common const& common,
|
||||
symbolizer_base const& sym,
|
||||
mapnik::feature_impl const& feature,
|
||||
proj_transform const& prj_trans)
|
||||
: agg_pattern_base{pattern_img, common, sym, feature, prj_trans},
|
||||
clip_(get<value_bool, keys::clip>(sym_, feature_, common_.vars_)),
|
||||
clip_box_(clipping_extent(common)),
|
||||
tr_(geom_transform()),
|
||||
converter_(clip_box_, sym, common.t_, prj_trans, tr_,
|
||||
feature, common.vars_, common.scale_factor_)
|
||||
: agg_pattern_base{pattern_img, common, sym, feature, prj_trans}
|
||||
, clip_(get<value_bool, keys::clip>(sym_, feature_, common_.vars_))
|
||||
, clip_box_(clipping_extent(common))
|
||||
, tr_(geom_transform())
|
||||
, converter_(clip_box_, sym, common.t_, prj_trans, tr_, feature, common.vars_, common.scale_factor_)
|
||||
{
|
||||
value_double simplify_tolerance = get<value_double, keys::simplify_tolerance>(sym_, feature_, common_.vars_);
|
||||
value_double smooth = get<value_double, keys::smooth>(sym_, feature_, common_.vars_);
|
||||
|
||||
if (simplify_tolerance > 0.0) converter_.template set<simplify_tag>();
|
||||
if (simplify_tolerance > 0.0)
|
||||
converter_.template set<simplify_tag>();
|
||||
converter_.template set<affine_transform_tag>();
|
||||
if (smooth > 0.0) converter_.template set<smooth_tag>();
|
||||
if (smooth > 0.0)
|
||||
converter_.template set<smooth_tag>();
|
||||
}
|
||||
|
||||
void render(renderer_base & ren_base, rasterizer & ras)
|
||||
void render(renderer_base& ren_base, rasterizer& ras)
|
||||
{
|
||||
coord<double, 2> offset(pattern_offset(sym_, feature_, prj_trans_, common_,
|
||||
pattern_img_.width(), pattern_img_.height()));
|
||||
coord<double, 2> offset(
|
||||
pattern_offset(sym_, feature_, prj_trans_, common_, pattern_img_.width(), pattern_img_.height()));
|
||||
agg::rendering_buffer pattern_rbuf((agg::int8u*)pattern_img_.bytes(),
|
||||
pattern_img_.width(), pattern_img_.height(),
|
||||
pattern_img_.width(),
|
||||
pattern_img_.height(),
|
||||
pattern_img_.width() * 4);
|
||||
agg::pixfmt_rgba32_pre pixf_pattern(pattern_rbuf);
|
||||
img_source_type img_src(pixf_pattern);
|
||||
|
@ -122,8 +121,7 @@ struct agg_polygon_pattern : agg_pattern_base
|
|||
value_double opacity = get<double, keys::opacity>(sym_, feature_, common_.vars_);
|
||||
renderer_type rp(ren_base, sa, sg, unsigned(opacity * 255));
|
||||
|
||||
using apply_vertex_converter_type = detail::apply_vertex_converter<
|
||||
VertexConverter, rasterizer>;
|
||||
using apply_vertex_converter_type = detail::apply_vertex_converter<VertexConverter, rasterizer>;
|
||||
using vertex_processor_type = geometry::vertex_processor<apply_vertex_converter_type>;
|
||||
apply_vertex_converter_type apply(converter_, ras);
|
||||
mapnik::util::apply_visitor(vertex_processor_type(apply), feature_.get_geometry());
|
||||
|
@ -139,5 +137,4 @@ struct agg_polygon_pattern : agg_pattern_base
|
|||
|
||||
} // namespace mapnik
|
||||
|
||||
|
||||
#endif // MAPNIK_RENDER_POLYGON_PATTERN_HPP
|
||||
|
|
|
@ -34,31 +34,31 @@ MAPNIK_DISABLE_WARNING_POP
|
|||
|
||||
namespace mapnik {
|
||||
|
||||
template <typename T>
|
||||
void set_gamma_method(T & ras_ptr, double gamma, gamma_method_enum method)
|
||||
template<typename T>
|
||||
void set_gamma_method(T& ras_ptr, double gamma, gamma_method_enum method)
|
||||
{
|
||||
switch (method)
|
||||
{
|
||||
case GAMMA_POWER:
|
||||
ras_ptr->gamma(agg::gamma_power(gamma));
|
||||
break;
|
||||
case GAMMA_LINEAR:
|
||||
ras_ptr->gamma(agg::gamma_linear(0.0, gamma));
|
||||
break;
|
||||
case GAMMA_NONE:
|
||||
ras_ptr->gamma(agg::gamma_none());
|
||||
break;
|
||||
case GAMMA_THRESHOLD:
|
||||
ras_ptr->gamma(agg::gamma_threshold(gamma));
|
||||
break;
|
||||
case GAMMA_MULTIPLY:
|
||||
ras_ptr->gamma(agg::gamma_multiply(gamma));
|
||||
break;
|
||||
default:
|
||||
ras_ptr->gamma(agg::gamma_power(gamma));
|
||||
case GAMMA_POWER:
|
||||
ras_ptr->gamma(agg::gamma_power(gamma));
|
||||
break;
|
||||
case GAMMA_LINEAR:
|
||||
ras_ptr->gamma(agg::gamma_linear(0.0, gamma));
|
||||
break;
|
||||
case GAMMA_NONE:
|
||||
ras_ptr->gamma(agg::gamma_none());
|
||||
break;
|
||||
case GAMMA_THRESHOLD:
|
||||
ras_ptr->gamma(agg::gamma_threshold(gamma));
|
||||
break;
|
||||
case GAMMA_MULTIPLY:
|
||||
ras_ptr->gamma(agg::gamma_multiply(gamma));
|
||||
break;
|
||||
default:
|
||||
ras_ptr->gamma(agg::gamma_power(gamma));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_AGG_HELPERS_HPP
|
||||
|
|
|
@ -33,36 +33,31 @@ MAPNIK_DISABLE_WARNING_PUSH
|
|||
#include "agg_color_rgba.h"
|
||||
MAPNIK_DISABLE_WARNING_POP
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
namespace mapnik {
|
||||
|
||||
class pattern_source : private util::noncopyable
|
||||
{
|
||||
public:
|
||||
public:
|
||||
pattern_source(image_rgba8 const& pattern, double opacity = 1.0)
|
||||
: pattern_(pattern),
|
||||
opacity_(opacity) {}
|
||||
: pattern_(pattern)
|
||||
, opacity_(opacity)
|
||||
{}
|
||||
|
||||
unsigned int width() const
|
||||
{
|
||||
return pattern_.width();
|
||||
}
|
||||
unsigned int height() const
|
||||
{
|
||||
return pattern_.height();
|
||||
}
|
||||
unsigned int width() const { return pattern_.width(); }
|
||||
unsigned int height() const { return pattern_.height(); }
|
||||
agg::rgba8 pixel(int x, int y) const
|
||||
{
|
||||
unsigned c = pattern_(x,y);
|
||||
unsigned c = pattern_(x, y);
|
||||
return agg::rgba8(static_cast<unsigned>((c & 0xff) * opacity_),
|
||||
static_cast<unsigned>(((c >> 8) & 0xff) * opacity_),
|
||||
static_cast<unsigned>(((c >> 16) & 0xff) * opacity_),
|
||||
static_cast<unsigned>(((c >> 24) & 0xff) * opacity_));
|
||||
}
|
||||
private:
|
||||
|
||||
private:
|
||||
image_rgba8 const& pattern_;
|
||||
double opacity_;
|
||||
};
|
||||
}
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_AGG_PATTERN_SOURCE_HPP
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
// mapnik
|
||||
#include <mapnik/util/noncopyable.hpp>
|
||||
|
||||
|
||||
#include <mapnik/warning.hpp>
|
||||
MAPNIK_DISABLE_WARNING_PUSH
|
||||
#include <mapnik/warning_ignore_agg.hpp>
|
||||
|
@ -35,8 +34,10 @@ MAPNIK_DISABLE_WARNING_POP
|
|||
|
||||
namespace mapnik {
|
||||
|
||||
struct rasterizer : agg::rasterizer_scanline_aa<agg::rasterizer_sl_clip_int_sat>, util::noncopyable {};
|
||||
struct rasterizer : agg::rasterizer_scanline_aa<agg::rasterizer_sl_clip_int_sat>,
|
||||
util::noncopyable
|
||||
{};
|
||||
|
||||
}
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_AGG_RASTERIZER_HPP
|
||||
|
|
|
@ -52,10 +52,14 @@ MAPNIK_DISABLE_WARNING_POP
|
|||
|
||||
namespace mapnik {
|
||||
|
||||
template <typename SvgRenderer, typename RasterizerType, typename RendererBaseType>
|
||||
void render_vector_marker(SvgRenderer & svg_renderer, RasterizerType & ras, RendererBaseType & renb,
|
||||
box2d<double> const& bbox, agg::trans_affine const& tr,
|
||||
double opacity, bool snap_to_pixels)
|
||||
template<typename SvgRenderer, typename RasterizerType, typename RendererBaseType>
|
||||
void render_vector_marker(SvgRenderer& svg_renderer,
|
||||
RasterizerType& ras,
|
||||
RendererBaseType& renb,
|
||||
box2d<double> const& bbox,
|
||||
agg::trans_affine const& tr,
|
||||
double opacity,
|
||||
bool snap_to_pixels)
|
||||
{
|
||||
agg::scanline_u8 sl;
|
||||
if (snap_to_pixels)
|
||||
|
@ -72,23 +76,25 @@ void render_vector_marker(SvgRenderer & svg_renderer, RasterizerType & ras, Rend
|
|||
}
|
||||
}
|
||||
|
||||
template <typename RendererType, typename RasterizerType>
|
||||
void render_raster_marker(RendererType renb, RasterizerType & ras, image_rgba8 const& src,
|
||||
agg::trans_affine const& tr, double opacity,
|
||||
float scale_factor, bool snap_to_pixels)
|
||||
template<typename RendererType, typename RasterizerType>
|
||||
void render_raster_marker(RendererType renb,
|
||||
RasterizerType& ras,
|
||||
image_rgba8 const& src,
|
||||
agg::trans_affine const& tr,
|
||||
double opacity,
|
||||
float scale_factor,
|
||||
bool snap_to_pixels)
|
||||
{
|
||||
using color_type = agg::rgba8;
|
||||
using const_rendering_buffer = util::rendering_buffer<image_rgba8>;
|
||||
using pixfmt_pre = agg::pixfmt_alpha_blend_rgba<agg::blender_rgba32_pre, const_rendering_buffer, agg::pixel32_type>;
|
||||
|
||||
agg::scanline_u8 sl;
|
||||
double width = src.width();
|
||||
double width = src.width();
|
||||
double height = src.height();
|
||||
if (std::fabs(1.0 - scale_factor) < 0.001
|
||||
&& (std::fabs(1.0 - tr.sx) < agg::affine_epsilon)
|
||||
&& (std::fabs(0.0 - tr.shy) < agg::affine_epsilon)
|
||||
&& (std::fabs(0.0 - tr.shx) < agg::affine_epsilon)
|
||||
&& (std::fabs(1.0 - tr.sy) < agg::affine_epsilon))
|
||||
if (std::fabs(1.0 - scale_factor) < 0.001 && (std::fabs(1.0 - tr.sx) < agg::affine_epsilon) &&
|
||||
(std::fabs(0.0 - tr.shy) < agg::affine_epsilon) && (std::fabs(0.0 - tr.shx) < agg::affine_epsilon) &&
|
||||
(std::fabs(1.0 - tr.sy) < agg::affine_epsilon))
|
||||
{
|
||||
const_rendering_buffer src_buffer(src);
|
||||
pixfmt_pre pixf_mask(src_buffer);
|
||||
|
@ -98,32 +104,31 @@ void render_raster_marker(RendererType renb, RasterizerType & ras, image_rgba8 c
|
|||
0,
|
||||
static_cast<int>(std::floor(tr.tx + .5)),
|
||||
static_cast<int>(std::floor(tr.ty + .5)),
|
||||
unsigned(255*opacity));
|
||||
unsigned(255 * opacity));
|
||||
}
|
||||
else
|
||||
{
|
||||
renb.blend_from(pixf_mask,
|
||||
0,
|
||||
static_cast<int>(tr.tx),
|
||||
static_cast<int>(tr.ty),
|
||||
unsigned(255*opacity));
|
||||
renb.blend_from(pixf_mask, 0, static_cast<int>(tr.tx), static_cast<int>(tr.ty), unsigned(255 * opacity));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
using img_accessor_type = agg::image_accessor_clone<pixfmt_pre>;
|
||||
using interpolator_type = agg::span_interpolator_linear<>;
|
||||
//using span_gen_type = agg::span_image_filter_rgba_2x2<img_accessor_type,interpolator_type>;
|
||||
// using span_gen_type = agg::span_image_filter_rgba_2x2<img_accessor_type,interpolator_type>;
|
||||
using span_gen_type = agg::span_image_resample_rgba_affine<img_accessor_type>;
|
||||
using renderer_type = agg::renderer_scanline_aa_alpha<RendererType,
|
||||
agg::span_allocator<color_type>,
|
||||
span_gen_type>;
|
||||
using renderer_type =
|
||||
agg::renderer_scanline_aa_alpha<RendererType, agg::span_allocator<color_type>, span_gen_type>;
|
||||
|
||||
double p[8];
|
||||
p[0] = 0; p[1] = 0;
|
||||
p[2] = width; p[3] = 0;
|
||||
p[4] = width; p[5] = height;
|
||||
p[6] = 0; p[7] = height;
|
||||
p[0] = 0;
|
||||
p[1] = 0;
|
||||
p[2] = width;
|
||||
p[3] = 0;
|
||||
p[4] = width;
|
||||
p[5] = height;
|
||||
p[6] = 0;
|
||||
p[7] = height;
|
||||
tr.transform(&p[0], &p[1]);
|
||||
tr.transform(&p[2], &p[3]);
|
||||
tr.transform(&p[4], &p[5]);
|
||||
|
@ -137,20 +142,20 @@ void render_raster_marker(RendererType renb, RasterizerType & ras, image_rgba8 c
|
|||
agg::trans_affine final_tr(p, 0, 0, width, height);
|
||||
if (snap_to_pixels)
|
||||
{
|
||||
final_tr.tx = std::floor(final_tr.tx+.5);
|
||||
final_tr.ty = std::floor(final_tr.ty+.5);
|
||||
final_tr.tx = std::floor(final_tr.tx + .5);
|
||||
final_tr.ty = std::floor(final_tr.ty + .5);
|
||||
}
|
||||
interpolator_type interpolator(final_tr);
|
||||
span_gen_type sg(ia, interpolator, filter);
|
||||
renderer_type rp(renb, sa, sg, unsigned(opacity*255));
|
||||
ras.move_to_d(p[0],p[1]);
|
||||
ras.line_to_d(p[2],p[3]);
|
||||
ras.line_to_d(p[4],p[5]);
|
||||
ras.line_to_d(p[6],p[7]);
|
||||
renderer_type rp(renb, sa, sg, unsigned(opacity * 255));
|
||||
ras.move_to_d(p[0], p[1]);
|
||||
ras.line_to_d(p[2], p[3]);
|
||||
ras.line_to_d(p[4], p[5]);
|
||||
ras.line_to_d(p[6], p[7]);
|
||||
agg::render_scanlines(ras, sl, rp);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_AGG_RENDER_MARKER_HPP
|
||||
|
|
|
@ -24,13 +24,13 @@
|
|||
#define MAPNIK_AGG_RENDERER_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/config.hpp> // for MAPNIK_DECL
|
||||
#include <mapnik/config.hpp> // for MAPNIK_DECL
|
||||
#include <mapnik/feature_style_processor.hpp>
|
||||
#include <mapnik/util/noncopyable.hpp> // for noncopyable
|
||||
#include <mapnik/util/noncopyable.hpp> // for noncopyable
|
||||
#include <mapnik/rule.hpp> // for rule, symbolizers
|
||||
#include <mapnik/geometry/box2d.hpp> // for box2d
|
||||
#include <mapnik/geometry/box2d.hpp> // for box2d
|
||||
#include <mapnik/view_transform.hpp> // for view_transform
|
||||
#include <mapnik/image_compositing.hpp> // for composite_mode_e
|
||||
#include <mapnik/image_compositing.hpp> // for composite_mode_e
|
||||
#include <mapnik/pixel_position.hpp>
|
||||
#include <mapnik/request.hpp>
|
||||
#include <mapnik/symbolizer_enumerations.hpp>
|
||||
|
@ -41,38 +41,40 @@
|
|||
#include <stack>
|
||||
|
||||
// fwd declaration to avoid dependence on agg headers
|
||||
namespace agg { struct trans_affine; }
|
||||
namespace agg {
|
||||
struct trans_affine;
|
||||
}
|
||||
|
||||
// fwd declarations to speed up compile
|
||||
namespace mapnik {
|
||||
class Map;
|
||||
class feature_impl;
|
||||
class feature_type_style;
|
||||
class label_collision_detector4;
|
||||
class layer;
|
||||
class color;
|
||||
struct marker;
|
||||
class proj_transform;
|
||||
struct rasterizer;
|
||||
struct rgba8_t;
|
||||
template<typename T> class image;
|
||||
}
|
||||
class Map;
|
||||
class feature_impl;
|
||||
class feature_type_style;
|
||||
class label_collision_detector4;
|
||||
class layer;
|
||||
class color;
|
||||
struct marker;
|
||||
class proj_transform;
|
||||
struct rasterizer;
|
||||
struct rgba8_t;
|
||||
template<typename T>
|
||||
class image;
|
||||
} // namespace mapnik
|
||||
|
||||
namespace mapnik {
|
||||
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
class buffer_stack
|
||||
{
|
||||
public:
|
||||
public:
|
||||
buffer_stack(std::size_t width, std::size_t height)
|
||||
: width_(width),
|
||||
height_(height),
|
||||
buffers_(),
|
||||
position_(buffers_.begin())
|
||||
{
|
||||
}
|
||||
: width_(width)
|
||||
, height_(height)
|
||||
, buffers_()
|
||||
, position_(buffers_.begin())
|
||||
{}
|
||||
|
||||
T & push()
|
||||
T& push()
|
||||
{
|
||||
if (position_ == buffers_.begin())
|
||||
{
|
||||
|
@ -86,10 +88,7 @@ public:
|
|||
}
|
||||
return *position_;
|
||||
}
|
||||
bool in_range() const
|
||||
{
|
||||
return (position_ != buffers_.end());
|
||||
}
|
||||
bool in_range() const { return (position_ != buffers_.end()); }
|
||||
|
||||
void pop()
|
||||
{
|
||||
|
@ -98,34 +97,44 @@ public:
|
|||
++position_;
|
||||
}
|
||||
|
||||
T & top() const
|
||||
{
|
||||
return *position_;
|
||||
}
|
||||
T& top() const { return *position_; }
|
||||
|
||||
private:
|
||||
private:
|
||||
const std::size_t width_;
|
||||
const std::size_t height_;
|
||||
std::deque<T> buffers_;
|
||||
typename std::deque<T>::iterator position_;
|
||||
};
|
||||
|
||||
template <typename T0, typename T1=label_collision_detector4>
|
||||
class MAPNIK_DECL agg_renderer : public feature_style_processor<agg_renderer<T0> >,
|
||||
template<typename T0, typename T1 = label_collision_detector4>
|
||||
class MAPNIK_DECL agg_renderer : public feature_style_processor<agg_renderer<T0>>,
|
||||
private util::noncopyable
|
||||
{
|
||||
|
||||
public:
|
||||
public:
|
||||
using buffer_type = T0;
|
||||
using processor_impl_type = agg_renderer<T0>;
|
||||
using detector_type = T1;
|
||||
// create with default, empty placement detector
|
||||
agg_renderer(Map const& m, buffer_type & pixmap, double scale_factor=1.0, unsigned offset_x=0, unsigned offset_y=0);
|
||||
agg_renderer(Map const& m,
|
||||
buffer_type& pixmap,
|
||||
double scale_factor = 1.0,
|
||||
unsigned offset_x = 0,
|
||||
unsigned offset_y = 0);
|
||||
// create with external placement detector, possibly non-empty
|
||||
agg_renderer(Map const &m, buffer_type & pixmap, std::shared_ptr<detector_type> detector,
|
||||
double scale_factor=1.0, unsigned offset_x=0, unsigned offset_y=0);
|
||||
agg_renderer(Map const& m,
|
||||
buffer_type& pixmap,
|
||||
std::shared_ptr<detector_type> detector,
|
||||
double scale_factor = 1.0,
|
||||
unsigned offset_x = 0,
|
||||
unsigned offset_y = 0);
|
||||
// pass in mapnik::request object to provide the mutable things per render
|
||||
agg_renderer(Map const& m, request const& req, attributes const& vars, buffer_type & pixmap, double scale_factor=1.0, unsigned offset_x=0, unsigned offset_y=0);
|
||||
agg_renderer(Map const& m,
|
||||
request const& req,
|
||||
attributes const& vars,
|
||||
buffer_type& pixmap,
|
||||
double scale_factor = 1.0,
|
||||
unsigned offset_x = 0,
|
||||
unsigned offset_y = 0);
|
||||
~agg_renderer();
|
||||
void start_map_processing(Map const& map);
|
||||
void end_map_processing(Map const& map);
|
||||
|
@ -135,52 +144,27 @@ public:
|
|||
void start_style_processing(feature_type_style const& st);
|
||||
void end_style_processing(feature_type_style const& st);
|
||||
|
||||
void render_marker(pixel_position const& pos, marker const& marker, agg::trans_affine const& tr,
|
||||
double opacity, composite_mode_e comp_op);
|
||||
void render_marker(pixel_position const& pos,
|
||||
marker const& marker,
|
||||
agg::trans_affine const& tr,
|
||||
double opacity,
|
||||
composite_mode_e comp_op);
|
||||
|
||||
void process(point_symbolizer const& sym,
|
||||
mapnik::feature_impl & feature,
|
||||
proj_transform const& prj_trans);
|
||||
void process(line_symbolizer const& sym,
|
||||
mapnik::feature_impl & feature,
|
||||
proj_transform const& prj_trans);
|
||||
void process(line_pattern_symbolizer const& sym,
|
||||
mapnik::feature_impl & feature,
|
||||
proj_transform const& prj_trans);
|
||||
void process(polygon_symbolizer const& sym,
|
||||
mapnik::feature_impl & feature,
|
||||
proj_transform const& prj_trans);
|
||||
void process(polygon_pattern_symbolizer const& sym,
|
||||
mapnik::feature_impl & feature,
|
||||
proj_transform const& prj_trans);
|
||||
void process(raster_symbolizer const& sym,
|
||||
mapnik::feature_impl & feature,
|
||||
proj_transform const& prj_trans);
|
||||
void process(shield_symbolizer const& sym,
|
||||
mapnik::feature_impl & feature,
|
||||
proj_transform const& prj_trans);
|
||||
void process(text_symbolizer const& sym,
|
||||
mapnik::feature_impl & feature,
|
||||
proj_transform const& prj_trans);
|
||||
void process(building_symbolizer const& sym,
|
||||
mapnik::feature_impl & feature,
|
||||
proj_transform const& prj_trans);
|
||||
void process(markers_symbolizer const& sym,
|
||||
mapnik::feature_impl & feature,
|
||||
proj_transform const& prj_trans);
|
||||
void process(group_symbolizer const& sym,
|
||||
mapnik::feature_impl & feature,
|
||||
proj_transform const& prj_trans);
|
||||
void process(debug_symbolizer const& sym,
|
||||
feature_impl & feature,
|
||||
proj_transform const& prj_trans);
|
||||
void process(dot_symbolizer const& sym,
|
||||
mapnik::feature_impl & feature,
|
||||
proj_transform const& prj_trans);
|
||||
void process(point_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||
void process(line_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||
void process(line_pattern_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||
void process(polygon_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||
void process(polygon_pattern_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||
void process(raster_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||
void process(shield_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||
void process(text_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||
void process(building_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||
void process(markers_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||
void process(group_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||
void process(debug_symbolizer const& sym, feature_impl& feature, proj_transform const& prj_trans);
|
||||
void process(dot_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||
|
||||
inline bool process(rule::symbolizers const&,
|
||||
mapnik::feature_impl&,
|
||||
proj_transform const& )
|
||||
inline bool process(rule::symbolizers const&, mapnik::feature_impl&, proj_transform const&)
|
||||
{
|
||||
// agg renderer doesn't support processing of multiple symbolizers.
|
||||
return false;
|
||||
|
@ -189,29 +173,19 @@ public:
|
|||
void painted(bool painted);
|
||||
bool painted();
|
||||
|
||||
inline eAttributeCollectionPolicy attribute_collection_policy() const
|
||||
{
|
||||
return DEFAULT;
|
||||
}
|
||||
inline eAttributeCollectionPolicy attribute_collection_policy() const { return DEFAULT; }
|
||||
|
||||
inline double scale_factor() const
|
||||
{
|
||||
return common_.scale_factor_;
|
||||
}
|
||||
inline double scale_factor() const { return common_.scale_factor_; }
|
||||
|
||||
inline attributes const& variables() const
|
||||
{
|
||||
return common_.vars_;
|
||||
}
|
||||
protected:
|
||||
template <typename R>
|
||||
void debug_draw_box(R& buf, box2d<double> const& extent,
|
||||
double x, double y, double angle = 0.0);
|
||||
void debug_draw_box(box2d<double> const& extent,
|
||||
double x, double y, double angle = 0.0);
|
||||
void draw_geo_extent(box2d<double> const& extent,mapnik::color const& color);
|
||||
inline attributes const& variables() const { return common_.vars_; }
|
||||
|
||||
private:
|
||||
protected:
|
||||
template<typename R>
|
||||
void debug_draw_box(R& buf, box2d<double> const& extent, double x, double y, double angle = 0.0);
|
||||
void debug_draw_box(box2d<double> const& extent, double x, double y, double angle = 0.0);
|
||||
void draw_geo_extent(box2d<double> const& extent, mapnik::color const& color);
|
||||
|
||||
private:
|
||||
std::stack<std::reference_wrapper<buffer_type>> buffers_;
|
||||
buffer_stack<buffer_type> internal_buffers_;
|
||||
std::unique_ptr<buffer_type> inflated_buffer_;
|
||||
|
@ -219,7 +193,7 @@ private:
|
|||
gamma_method_enum gamma_method_;
|
||||
double gamma_;
|
||||
renderer_common common_;
|
||||
void setup(Map const & m, buffer_type & pixmap);
|
||||
void setup(Map const& m, buffer_type& pixmap);
|
||||
};
|
||||
|
||||
extern template class MAPNIK_DECL agg_renderer<image<rgba8_t>>;
|
||||
|
|
|
@ -37,20 +37,21 @@ struct attribute
|
|||
{
|
||||
std::string name_;
|
||||
explicit attribute(std::string const& _name)
|
||||
: name_(_name) {}
|
||||
: name_(_name)
|
||||
{}
|
||||
|
||||
template <typename V ,typename F>
|
||||
template<typename V, typename F>
|
||||
V const& value(F const& f) const
|
||||
{
|
||||
return f.get(name_);
|
||||
}
|
||||
|
||||
std::string const& name() const { return name_;}
|
||||
std::string const& name() const { return name_; }
|
||||
};
|
||||
|
||||
struct geometry_type_attribute
|
||||
{
|
||||
template <typename V, typename F>
|
||||
template<typename V, typename F>
|
||||
V value(F const& f) const
|
||||
{
|
||||
return static_cast<mapnik::value_integer>(util::to_ds_type(f.get_geometry()));
|
||||
|
@ -61,10 +62,11 @@ struct global_attribute
|
|||
{
|
||||
std::string name;
|
||||
explicit global_attribute(std::string const& name_)
|
||||
: name(name_) {}
|
||||
: name(name_)
|
||||
{}
|
||||
|
||||
template <typename V, typename C>
|
||||
V const& operator() (C const& ctx)
|
||||
template<typename V, typename C>
|
||||
V const& operator()(C const& ctx)
|
||||
{
|
||||
return ctx.get(name);
|
||||
}
|
||||
|
@ -72,6 +74,6 @@ struct global_attribute
|
|||
|
||||
using attributes = std::unordered_map<std::string, value>;
|
||||
|
||||
}
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_ATTRIBUTE_HPP
|
||||
|
|
|
@ -28,11 +28,11 @@
|
|||
#include <mapnik/util/noncopyable.hpp>
|
||||
#include <mapnik/attribute.hpp>
|
||||
#include <mapnik/symbolizer.hpp>
|
||||
#include <mapnik/expression.hpp> // for expression_ptr, etc
|
||||
#include <mapnik/expression.hpp> // for expression_ptr, etc
|
||||
#include <mapnik/expression_node.hpp>
|
||||
#include <mapnik/parse_path.hpp> // for path_processor_type
|
||||
#include <mapnik/path_expression.hpp> // for path_expression_ptr
|
||||
#include <mapnik/text/placements/base.hpp> // for text_placements
|
||||
#include <mapnik/parse_path.hpp> // for path_processor_type
|
||||
#include <mapnik/path_expression.hpp> // for path_expression_ptr
|
||||
#include <mapnik/text/placements/base.hpp> // for text_placements
|
||||
#include <mapnik/image_scaling.hpp>
|
||||
#include <mapnik/group/group_symbolizer_properties.hpp>
|
||||
#include <mapnik/group/group_rule.hpp>
|
||||
|
@ -51,76 +51,71 @@ MAPNIK_DISABLE_WARNING_POP
|
|||
|
||||
namespace mapnik {
|
||||
|
||||
template <typename Container>
|
||||
template<typename Container>
|
||||
struct expression_attributes
|
||||
{
|
||||
explicit expression_attributes(Container& names)
|
||||
: names_(names) {}
|
||||
: names_(names)
|
||||
{}
|
||||
|
||||
void operator() (attribute const& attr) const
|
||||
{
|
||||
names_.emplace(attr.name());
|
||||
}
|
||||
void operator()(attribute const& attr) const { names_.emplace(attr.name()); }
|
||||
|
||||
template <typename Tag>
|
||||
void operator() (binary_node<Tag> const& x) const
|
||||
template<typename Tag>
|
||||
void operator()(binary_node<Tag> const& x) const
|
||||
{
|
||||
util::apply_visitor(*this, x.left);
|
||||
util::apply_visitor(*this, x.right);
|
||||
}
|
||||
|
||||
template <typename Tag>
|
||||
void operator() (unary_node<Tag> const& x) const
|
||||
template<typename Tag>
|
||||
void operator()(unary_node<Tag> const& x) const
|
||||
{
|
||||
util::apply_visitor(*this, x.expr);
|
||||
}
|
||||
|
||||
void operator() (regex_match_node const& x) const
|
||||
{
|
||||
util::apply_visitor(*this, x.expr);
|
||||
}
|
||||
void operator()(regex_match_node const& x) const { util::apply_visitor(*this, x.expr); }
|
||||
|
||||
void operator() (regex_replace_node const& x) const
|
||||
{
|
||||
util::apply_visitor(*this, x.expr);
|
||||
}
|
||||
void operator()(regex_replace_node const& x) const { util::apply_visitor(*this, x.expr); }
|
||||
|
||||
template <typename T>
|
||||
void operator() (T const&) const {}
|
||||
template<typename T>
|
||||
void operator()(T const&) const
|
||||
{}
|
||||
|
||||
private:
|
||||
private:
|
||||
Container& names_;
|
||||
};
|
||||
|
||||
class group_attribute_collector : public util::noncopyable
|
||||
{
|
||||
private:
|
||||
private:
|
||||
std::set<std::string>& names_;
|
||||
bool expand_index_columns_;
|
||||
public:
|
||||
group_attribute_collector(std::set<std::string>& names,
|
||||
bool expand_index_columns)
|
||||
: names_(names),
|
||||
expand_index_columns_(expand_index_columns) {}
|
||||
|
||||
void operator() (group_symbolizer const& sym);
|
||||
public:
|
||||
group_attribute_collector(std::set<std::string>& names, bool expand_index_columns)
|
||||
: names_(names)
|
||||
, expand_index_columns_(expand_index_columns)
|
||||
{}
|
||||
|
||||
void operator()(group_symbolizer const& sym);
|
||||
};
|
||||
|
||||
template <typename Container>
|
||||
template<typename Container>
|
||||
struct extract_attribute_names
|
||||
{
|
||||
explicit extract_attribute_names(Container& names)
|
||||
: names_(names),
|
||||
f_attr_(names) {}
|
||||
: names_(names)
|
||||
, f_attr_(names)
|
||||
{}
|
||||
|
||||
void operator() (mapnik::expression_ptr const& expr) const
|
||||
void operator()(mapnik::expression_ptr const& expr) const
|
||||
{
|
||||
if (expr)
|
||||
{
|
||||
util::apply_visitor(f_attr_, *expr);
|
||||
}
|
||||
}
|
||||
void operator() (mapnik::transform_type const& expr) const
|
||||
void operator()(mapnik::transform_type const& expr) const
|
||||
{
|
||||
if (expr)
|
||||
{
|
||||
|
@ -128,7 +123,7 @@ struct extract_attribute_names
|
|||
}
|
||||
}
|
||||
|
||||
void operator() (mapnik::text_placements_ptr const& expr) const
|
||||
void operator()(mapnik::text_placements_ptr const& expr) const
|
||||
{
|
||||
if (expr)
|
||||
{
|
||||
|
@ -136,39 +131,41 @@ struct extract_attribute_names
|
|||
expression_set expressions;
|
||||
// TODO - optimize (dane)
|
||||
expr->add_expressions(expressions);
|
||||
for (it=expressions.begin(); it != expressions.end(); ++it)
|
||||
for (it = expressions.begin(); it != expressions.end(); ++it)
|
||||
{
|
||||
if (*it) util::apply_visitor(f_attr_, **it);
|
||||
if (*it)
|
||||
util::apply_visitor(f_attr_, **it);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void operator() (mapnik::path_expression_ptr const& expr) const
|
||||
void operator()(mapnik::path_expression_ptr const& expr) const
|
||||
{
|
||||
if (expr)
|
||||
{
|
||||
path_processor_type::collect_attributes(*expr,names_);
|
||||
path_processor_type::collect_attributes(*expr, names_);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void operator() (T const&) const {}
|
||||
template<typename T>
|
||||
void operator()(T const&) const
|
||||
{}
|
||||
|
||||
private:
|
||||
private:
|
||||
Container& names_;
|
||||
expression_attributes<std::set<std::string> > f_attr_;
|
||||
expression_attributes<std::set<std::string>> f_attr_;
|
||||
};
|
||||
|
||||
struct symbolizer_attributes
|
||||
{
|
||||
symbolizer_attributes(std::set<std::string>& names,
|
||||
double & filter_factor)
|
||||
: filter_factor_(filter_factor),
|
||||
f_attrs_(names),
|
||||
g_attrs_(names, true) {}
|
||||
symbolizer_attributes(std::set<std::string>& names, double& filter_factor)
|
||||
: filter_factor_(filter_factor)
|
||||
, f_attrs_(names)
|
||||
, g_attrs_(names, true)
|
||||
{}
|
||||
|
||||
template <typename T>
|
||||
void operator () (T const& sym)
|
||||
template<typename T>
|
||||
void operator()(T const& sym)
|
||||
{
|
||||
for (auto const& prop : sym.properties)
|
||||
{
|
||||
|
@ -176,7 +173,7 @@ struct symbolizer_attributes
|
|||
}
|
||||
}
|
||||
|
||||
void operator () (raster_symbolizer const& sym)
|
||||
void operator()(raster_symbolizer const& sym)
|
||||
{
|
||||
boost::optional<double> filter_factor = get_optional<double>(sym, keys::filter_factor);
|
||||
if (filter_factor)
|
||||
|
@ -197,57 +194,51 @@ struct symbolizer_attributes
|
|||
}
|
||||
}
|
||||
|
||||
void operator () (group_symbolizer const& sym)
|
||||
{
|
||||
g_attrs_(sym);
|
||||
}
|
||||
void operator()(group_symbolizer const& sym) { g_attrs_(sym); }
|
||||
|
||||
private:
|
||||
double & filter_factor_;
|
||||
extract_attribute_names<std::set<std::string> > f_attrs_;
|
||||
private:
|
||||
double& filter_factor_;
|
||||
extract_attribute_names<std::set<std::string>> f_attrs_;
|
||||
group_attribute_collector g_attrs_;
|
||||
};
|
||||
|
||||
|
||||
class attribute_collector : public util::noncopyable
|
||||
{
|
||||
private:
|
||||
std::set<std::string> & names_;
|
||||
private:
|
||||
std::set<std::string>& names_;
|
||||
double filter_factor_;
|
||||
expression_attributes<std::set<std::string> > f_attr;
|
||||
public:
|
||||
expression_attributes<std::set<std::string>> f_attr;
|
||||
|
||||
public:
|
||||
|
||||
attribute_collector(std::set<std::string>& names)
|
||||
: names_(names),
|
||||
filter_factor_(1.0),
|
||||
f_attr(names) {}
|
||||
template <typename RuleType>
|
||||
void operator() (RuleType const& r)
|
||||
: names_(names)
|
||||
, filter_factor_(1.0)
|
||||
, f_attr(names)
|
||||
{}
|
||||
template<typename RuleType>
|
||||
void operator()(RuleType const& r)
|
||||
{
|
||||
typename RuleType::symbolizers const& symbols = r.get_symbolizers();
|
||||
symbolizer_attributes s_attr(names_,filter_factor_);
|
||||
symbolizer_attributes s_attr(names_, filter_factor_);
|
||||
for (auto const& sym : symbols)
|
||||
{
|
||||
util::apply_visitor(std::ref(s_attr), sym);
|
||||
}
|
||||
|
||||
expression_ptr const& expr = r.get_filter();
|
||||
util::apply_visitor(f_attr,*expr);
|
||||
util::apply_visitor(f_attr, *expr);
|
||||
}
|
||||
|
||||
double get_filter_factor() const
|
||||
{
|
||||
return filter_factor_;
|
||||
}
|
||||
double get_filter_factor() const { return filter_factor_; }
|
||||
};
|
||||
|
||||
|
||||
inline void group_attribute_collector::operator() (group_symbolizer const& sym)
|
||||
inline void group_attribute_collector::operator()(group_symbolizer const& sym)
|
||||
{
|
||||
// find all column names referenced in the group symbolizer
|
||||
std::set<std::string> group_columns;
|
||||
attribute_collector column_collector(group_columns);
|
||||
expression_attributes<std::set<std::string> > rk_attr(group_columns);
|
||||
expression_attributes<std::set<std::string>> rk_attr(group_columns);
|
||||
|
||||
// get columns from symbolizer repeat key
|
||||
expression_ptr repeat_key = get<mapnik::expression_ptr>(sym, keys::repeat_key);
|
||||
|
@ -289,7 +280,7 @@ inline void group_attribute_collector::operator() (group_symbolizer const& sym)
|
|||
for (value_integer col_idx = start; col_idx < end; ++col_idx)
|
||||
{
|
||||
std::string col_idx_str;
|
||||
if (mapnik::util::to_string(col_idx_str,col_idx))
|
||||
if (mapnik::util::to_string(col_idx_str, col_idx))
|
||||
{
|
||||
std::string col_idx_name = col_name;
|
||||
boost::replace_all(col_idx_name, "%", col_idx_str);
|
||||
|
|
|
@ -27,35 +27,30 @@
|
|||
|
||||
namespace mapnik {
|
||||
|
||||
enum eAttributeType {
|
||||
Integer=1,
|
||||
Float =2,
|
||||
Double =3,
|
||||
String =4,
|
||||
Boolean =5,
|
||||
Geometry=6,
|
||||
Object=7
|
||||
};
|
||||
enum eAttributeType { Integer = 1, Float = 2, Double = 3, String = 4, Boolean = 5, Geometry = 6, Object = 7 };
|
||||
|
||||
class attribute_descriptor
|
||||
{
|
||||
public:
|
||||
attribute_descriptor(std::string const& name,unsigned type,
|
||||
bool primary_key=false,
|
||||
int size=-1,
|
||||
int precision=-1)
|
||||
: name_(name),
|
||||
type_(type),
|
||||
size_(size),
|
||||
precision_(precision),
|
||||
primary_key_(primary_key) {}
|
||||
public:
|
||||
attribute_descriptor(std::string const& name,
|
||||
unsigned type,
|
||||
bool primary_key = false,
|
||||
int size = -1,
|
||||
int precision = -1)
|
||||
: name_(name)
|
||||
, type_(type)
|
||||
, size_(size)
|
||||
, precision_(precision)
|
||||
, primary_key_(primary_key)
|
||||
{}
|
||||
|
||||
attribute_descriptor(attribute_descriptor const& other)
|
||||
: name_(other.name_),
|
||||
type_(other.type_),
|
||||
size_(other.size_),
|
||||
precision_(other.precision_),
|
||||
primary_key_(other.primary_key_) {}
|
||||
: name_(other.name_)
|
||||
, type_(other.type_)
|
||||
, size_(other.size_)
|
||||
, precision_(other.precision_)
|
||||
, primary_key_(other.primary_key_)
|
||||
{}
|
||||
|
||||
attribute_descriptor& operator=(attribute_descriptor rhs)
|
||||
{
|
||||
|
@ -68,32 +63,17 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
std::string const& get_name() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
std::string const& get_name() const { return name_; }
|
||||
|
||||
unsigned int get_type() const
|
||||
{
|
||||
return type_;
|
||||
}
|
||||
unsigned int get_type() const { return type_; }
|
||||
|
||||
bool is_primary_key() const
|
||||
{
|
||||
return primary_key_;
|
||||
}
|
||||
bool is_primary_key() const { return primary_key_; }
|
||||
|
||||
int get_size() const
|
||||
{
|
||||
return size_;
|
||||
}
|
||||
int get_size() const { return size_; }
|
||||
|
||||
int get_precision() const
|
||||
{
|
||||
return precision_;
|
||||
}
|
||||
int get_precision() const { return precision_; }
|
||||
|
||||
private:
|
||||
private:
|
||||
std::string name_;
|
||||
unsigned int type_;
|
||||
int size_;
|
||||
|
@ -101,6 +81,6 @@ private:
|
|||
bool primary_key_;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_ATTRIBUTE_DESCRIPTOR_HPP
|
||||
|
|
|
@ -30,25 +30,24 @@
|
|||
#include <iosfwd>
|
||||
#include <string>
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
namespace mapnik {
|
||||
|
||||
class MAPNIK_DECL boolean_type
|
||||
{
|
||||
public:
|
||||
public:
|
||||
boolean_type()
|
||||
: b_(false) {}
|
||||
: b_(false)
|
||||
{}
|
||||
boolean_type(bool b)
|
||||
: b_(b) {}
|
||||
: b_(b)
|
||||
{}
|
||||
boolean_type(boolean_type const& b)
|
||||
: b_(b.b_) {}
|
||||
: b_(b.b_)
|
||||
{}
|
||||
|
||||
operator bool() const
|
||||
{
|
||||
return b_;
|
||||
}
|
||||
operator bool() const { return b_; }
|
||||
|
||||
boolean_type & operator =(boolean_type const& other)
|
||||
boolean_type& operator=(boolean_type const& other)
|
||||
{
|
||||
if (this == &other)
|
||||
return *this;
|
||||
|
@ -56,33 +55,32 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
bool b_;
|
||||
};
|
||||
|
||||
// Special stream input operator for boolean_type values
|
||||
template <typename charT, typename traits>
|
||||
std::basic_istream<charT, traits> &
|
||||
operator >> ( std::basic_istream<charT, traits> & s, boolean_type & b )
|
||||
template<typename charT, typename traits>
|
||||
std::basic_istream<charT, traits>& operator>>(std::basic_istream<charT, traits>& s, boolean_type& b)
|
||||
{
|
||||
if ( s )
|
||||
if (s)
|
||||
{
|
||||
std::string word;
|
||||
s >> word;
|
||||
bool result;
|
||||
if (util::string2bool(word,result)) b = result;
|
||||
if (util::string2bool(word, result))
|
||||
b = result;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
template <typename charT, typename traits>
|
||||
std::basic_ostream<charT, traits> &
|
||||
operator << ( std::basic_ostream<charT, traits> & s, boolean_type const& b )
|
||||
template<typename charT, typename traits>
|
||||
std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& s, boolean_type const& b)
|
||||
{
|
||||
s << ( b ? "true" : "false" );
|
||||
s << (b ? "true" : "false");
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_BOOLEAN_HPP
|
||||
|
|
|
@ -23,17 +23,21 @@
|
|||
#ifndef MAPNIK_BOOST_SPIRIT_INSTANTIATE_HPP
|
||||
#define MAPNIK_BOOST_SPIRIT_INSTANTIATE_HPP
|
||||
|
||||
namespace boost { namespace spirit { namespace x3
|
||||
{
|
||||
namespace boost {
|
||||
namespace spirit {
|
||||
namespace x3 {
|
||||
// helper macro
|
||||
#define BOOST_SPIRIT_INSTANTIATE_UNUSED(rule_type, Iterator, Context) \
|
||||
template bool parse_rule<Iterator, Context, boost::spirit::x3::unused_type const>( \
|
||||
rule_type rule_ \
|
||||
, Iterator& first, Iterator const& last \
|
||||
, Context const& context, boost::spirit::x3::unused_type const& ); \
|
||||
#define BOOST_SPIRIT_INSTANTIATE_UNUSED(rule_type, Iterator, Context) \
|
||||
template bool parse_rule<Iterator, Context, boost::spirit::x3::unused_type const>( \
|
||||
rule_type rule_, \
|
||||
Iterator & first, \
|
||||
Iterator const& last, \
|
||||
Context const& context, \
|
||||
boost::spirit::x3::unused_type const&); \
|
||||
/***/
|
||||
|
||||
}}}
|
||||
|
||||
} // namespace x3
|
||||
} // namespace spirit
|
||||
} // namespace boost
|
||||
|
||||
#endif // MAPNIK_BOOST_SPIRIT_INSTANTIATE_HPP
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
#ifndef MAPNIK_CAIRO_CONTEXT_HPP
|
||||
#define MAPNIK_CAIRO_CONTEXT_HPP
|
||||
|
||||
|
@ -57,7 +56,8 @@ MAPNIK_DISABLE_WARNING_POP
|
|||
|
||||
namespace mapnik {
|
||||
|
||||
template <typename T> class box2d;
|
||||
template<typename T>
|
||||
class box2d;
|
||||
|
||||
using ErrorStatus = cairo_status_t;
|
||||
|
||||
|
@ -67,10 +67,10 @@ inline void throw_exception(ErrorStatus status)
|
|||
throw std::runtime_error(std::string("cairo: ") + cairo_status_to_string(status));
|
||||
}
|
||||
|
||||
//We inline this because it is called so often.
|
||||
// We inline this because it is called so often.
|
||||
inline void check_status_and_throw_exception(ErrorStatus status)
|
||||
{
|
||||
if(status != CAIRO_STATUS_SUCCESS)
|
||||
if (status != CAIRO_STATUS_SUCCESS)
|
||||
throw_exception(status);
|
||||
}
|
||||
|
||||
|
@ -82,60 +82,65 @@ void check_object_status_and_throw_exception(T const& object)
|
|||
|
||||
class cairo_face : private util::noncopyable
|
||||
{
|
||||
public:
|
||||
public:
|
||||
cairo_face(std::shared_ptr<font_library> const& library, face_ptr const& face);
|
||||
~cairo_face();
|
||||
cairo_font_face_t * face() const;
|
||||
private:
|
||||
cairo_font_face_t* face() const;
|
||||
|
||||
private:
|
||||
class handle
|
||||
{
|
||||
public:
|
||||
public:
|
||||
handle(std::shared_ptr<font_library> const& library, face_ptr const& face)
|
||||
: library_(library), face_(face) {}
|
||||
: library_(library)
|
||||
, face_(face)
|
||||
{}
|
||||
|
||||
private:
|
||||
private:
|
||||
std::shared_ptr<font_library> library_;
|
||||
face_ptr face_;
|
||||
};
|
||||
|
||||
static void destroy(void *data)
|
||||
static void destroy(void* data)
|
||||
{
|
||||
handle *h = static_cast<handle *>(data);
|
||||
handle* h = static_cast<handle*>(data);
|
||||
delete h;
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
face_ptr face_;
|
||||
cairo_font_face_t *c_face_;
|
||||
cairo_font_face_t* c_face_;
|
||||
};
|
||||
|
||||
using cairo_face_ptr = std::shared_ptr<cairo_face>;
|
||||
|
||||
class cairo_face_manager : private util::noncopyable
|
||||
{
|
||||
public:
|
||||
public:
|
||||
cairo_face_manager(std::shared_ptr<font_library> library);
|
||||
cairo_face_ptr get_face(face_ptr face);
|
||||
|
||||
private:
|
||||
using cairo_face_cache = std::map<face_ptr,cairo_face_ptr>;
|
||||
private:
|
||||
using cairo_face_cache = std::map<face_ptr, cairo_face_ptr>;
|
||||
std::shared_ptr<font_library> font_library_;
|
||||
cairo_face_cache cache_;
|
||||
};
|
||||
|
||||
struct cairo_closer
|
||||
{
|
||||
void operator() (cairo_t * obj)
|
||||
void operator()(cairo_t* obj)
|
||||
{
|
||||
if (obj) cairo_destroy(obj);
|
||||
if (obj)
|
||||
cairo_destroy(obj);
|
||||
}
|
||||
};
|
||||
|
||||
struct cairo_surface_closer
|
||||
{
|
||||
void operator() (cairo_surface_t * surface)
|
||||
void operator()(cairo_surface_t* surface)
|
||||
{
|
||||
if (surface) cairo_surface_destroy(surface);
|
||||
if (surface)
|
||||
cairo_surface_destroy(surface);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -144,28 +149,25 @@ using cairo_surface_ptr = std::shared_ptr<cairo_surface_t>;
|
|||
|
||||
inline cairo_ptr create_context(cairo_surface_ptr const& surface)
|
||||
{
|
||||
return cairo_ptr(cairo_create(&*surface),cairo_closer());
|
||||
return cairo_ptr(cairo_create(&*surface), cairo_closer());
|
||||
}
|
||||
|
||||
class cairo_pattern : private util::noncopyable
|
||||
{
|
||||
public:
|
||||
public:
|
||||
explicit cairo_pattern(image_rgba8 const& data, double opacity = 1.0)
|
||||
{
|
||||
std::size_t pixels = data.width() * data.height();
|
||||
const unsigned int *in_ptr = data.data();
|
||||
const unsigned int *in_end = in_ptr + pixels;
|
||||
unsigned int *out_ptr;
|
||||
const unsigned int* in_ptr = data.data();
|
||||
const unsigned int* in_end = in_ptr + pixels;
|
||||
unsigned int* out_ptr;
|
||||
|
||||
surface_ = cairo_surface_ptr(
|
||||
cairo_image_surface_create(
|
||||
CAIRO_FORMAT_ARGB32,
|
||||
static_cast<int>(data.width()),
|
||||
static_cast<int>(data.height())),
|
||||
cairo_surface_closer());
|
||||
surface_ = cairo_surface_ptr(cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
|
||||
static_cast<int>(data.width()),
|
||||
static_cast<int>(data.height())),
|
||||
cairo_surface_closer());
|
||||
|
||||
out_ptr = reinterpret_cast<unsigned int *>(
|
||||
cairo_image_surface_get_data(surface_.get()));
|
||||
out_ptr = reinterpret_cast<unsigned int*>(cairo_image_surface_get_data(surface_.get()));
|
||||
|
||||
while (in_ptr < in_end)
|
||||
{
|
||||
|
@ -175,9 +177,9 @@ public:
|
|||
unsigned int b = static_cast<unsigned>(((in >> 16) & 0xff) * opacity);
|
||||
unsigned int a = static_cast<unsigned>(((in >> 24) & 0xff) * opacity);
|
||||
|
||||
//r = r * a / 255;
|
||||
//g = g * a / 255;
|
||||
//b = b * a / 255;
|
||||
// r = r * a / 255;
|
||||
// g = g * a / 255;
|
||||
// b = b * a / 255;
|
||||
|
||||
*out_ptr++ = (a << 24) | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
|
@ -186,78 +188,65 @@ public:
|
|||
pattern_ = cairo_pattern_create_for_surface(surface_.get());
|
||||
}
|
||||
|
||||
cairo_pattern(cairo_surface_ptr const& surface) :
|
||||
surface_(surface),
|
||||
pattern_(cairo_pattern_create_for_surface(surface_.get()))
|
||||
{
|
||||
}
|
||||
cairo_pattern(cairo_surface_ptr const& surface)
|
||||
: surface_(surface)
|
||||
, pattern_(cairo_pattern_create_for_surface(surface_.get()))
|
||||
{}
|
||||
|
||||
~cairo_pattern()
|
||||
{
|
||||
if (pattern_) cairo_pattern_destroy(pattern_);
|
||||
if (pattern_)
|
||||
cairo_pattern_destroy(pattern_);
|
||||
}
|
||||
|
||||
void set_matrix(cairo_matrix_t const& matrix)
|
||||
{
|
||||
cairo_pattern_set_matrix(pattern_, &matrix);
|
||||
}
|
||||
void set_matrix(cairo_matrix_t const& matrix) { cairo_pattern_set_matrix(pattern_, &matrix); }
|
||||
|
||||
void set_origin(double x, double y)
|
||||
{
|
||||
cairo_matrix_t matrix;
|
||||
cairo_pattern_get_matrix(pattern_,&matrix);
|
||||
cairo_pattern_get_matrix(pattern_, &matrix);
|
||||
matrix.x0 = -x;
|
||||
matrix.y0 = -y;
|
||||
cairo_pattern_set_matrix(pattern_,&matrix);
|
||||
cairo_pattern_set_matrix(pattern_, &matrix);
|
||||
}
|
||||
|
||||
void set_extend(cairo_extend_t extend)
|
||||
{
|
||||
cairo_pattern_set_extend(pattern_, extend);
|
||||
}
|
||||
void set_extend(cairo_extend_t extend) { cairo_pattern_set_extend(pattern_, extend); }
|
||||
|
||||
void set_filter(cairo_filter_t filter)
|
||||
{
|
||||
cairo_pattern_set_filter(pattern_, filter);
|
||||
}
|
||||
void set_filter(cairo_filter_t filter) { cairo_pattern_set_filter(pattern_, filter); }
|
||||
|
||||
cairo_pattern_t * pattern() const
|
||||
{
|
||||
return pattern_;
|
||||
}
|
||||
cairo_pattern_t* pattern() const { return pattern_; }
|
||||
|
||||
private:
|
||||
private:
|
||||
cairo_surface_ptr surface_;
|
||||
cairo_pattern_t * pattern_;
|
||||
cairo_pattern_t* pattern_;
|
||||
};
|
||||
|
||||
|
||||
class cairo_gradient : private util::noncopyable
|
||||
{
|
||||
public:
|
||||
cairo_gradient(mapnik::gradient const& grad, double opacity=1.0)
|
||||
public:
|
||||
cairo_gradient(mapnik::gradient const& grad, double opacity = 1.0)
|
||||
{
|
||||
double x1,x2,y1,y2,rad;
|
||||
grad.get_control_points(x1,y1,x2,y2,rad);
|
||||
double x1, x2, y1, y2, rad;
|
||||
grad.get_control_points(x1, y1, x2, y2, rad);
|
||||
if (grad.get_gradient_type() == LINEAR)
|
||||
{
|
||||
pattern_ = cairo_pattern_create_linear(x1, y1, x2, y2);
|
||||
}
|
||||
else
|
||||
{
|
||||
pattern_ = cairo_pattern_create_radial(x1, y1, 0, x2, y2, rad);
|
||||
pattern_ = cairo_pattern_create_radial(x1, y1, 0, x2, y2, rad);
|
||||
}
|
||||
|
||||
units_ = grad.get_units();
|
||||
|
||||
for ( mapnik::stop_pair const& st : grad.get_stop_array() )
|
||||
for (mapnik::stop_pair const& st : grad.get_stop_array())
|
||||
{
|
||||
mapnik::color const& stop_color = st.second;
|
||||
double r= static_cast<double> (stop_color.red())/255.0;
|
||||
double g= static_cast<double> (stop_color.green())/255.0;
|
||||
double b= static_cast<double> (stop_color.blue())/255.0;
|
||||
double a= static_cast<double> (stop_color.alpha())/255.0;
|
||||
cairo_pattern_add_color_stop_rgba(pattern_,st.first, r, g, b, a*opacity);
|
||||
double r = static_cast<double>(stop_color.red()) / 255.0;
|
||||
double g = static_cast<double>(stop_color.green()) / 255.0;
|
||||
double b = static_cast<double>(stop_color.blue()) / 255.0;
|
||||
double a = static_cast<double>(stop_color.alpha()) / 255.0;
|
||||
cairo_pattern_add_color_stop_rgba(pattern_, st.first, r, g, b, a * opacity);
|
||||
}
|
||||
|
||||
double m[6];
|
||||
|
@ -265,7 +254,7 @@ public:
|
|||
tr.invert();
|
||||
tr.store_to(m);
|
||||
cairo_matrix_t matrix;
|
||||
cairo_matrix_init(&matrix,m[0],m[1],m[2],m[3],m[4],m[5]);
|
||||
cairo_matrix_init(&matrix, m[0], m[1], m[2], m[3], m[4], m[5]);
|
||||
cairo_pattern_set_matrix(pattern_, &matrix);
|
||||
}
|
||||
|
||||
|
@ -275,43 +264,32 @@ public:
|
|||
cairo_pattern_destroy(pattern_);
|
||||
}
|
||||
|
||||
cairo_pattern_t* gradient() const { return pattern_; }
|
||||
|
||||
cairo_pattern_t * gradient() const
|
||||
{
|
||||
return pattern_;
|
||||
}
|
||||
gradient_unit_e units() const { return units_; }
|
||||
|
||||
gradient_unit_e units() const
|
||||
{
|
||||
return units_;
|
||||
}
|
||||
|
||||
private:
|
||||
cairo_pattern_t * pattern_;
|
||||
private:
|
||||
cairo_pattern_t* pattern_;
|
||||
gradient_unit_e units_;
|
||||
|
||||
};
|
||||
|
||||
class cairo_context : private util::noncopyable
|
||||
{
|
||||
public:
|
||||
public:
|
||||
cairo_context(cairo_ptr const& cairo);
|
||||
|
||||
inline ErrorStatus get_status() const
|
||||
{
|
||||
return cairo_status(cairo_.get());
|
||||
}
|
||||
inline ErrorStatus get_status() const { return cairo_status(cairo_.get()); }
|
||||
|
||||
void clip();
|
||||
void show_page();
|
||||
void set_color(color const &color, double opacity = 1.0);
|
||||
void set_color(color const& color, double opacity = 1.0);
|
||||
void set_color(double r, double g, double b, double opacity = 1.0);
|
||||
void set_operator(composite_mode_e comp_op);
|
||||
void set_line_join(line_join_e join);
|
||||
void set_line_cap(line_cap_e cap);
|
||||
void set_miter_limit(double limit);
|
||||
void set_line_width(double width);
|
||||
void set_dash(dash_array const &dashes, double scale_factor);
|
||||
void set_dash(dash_array const& dashes, double scale_factor);
|
||||
void set_fill_rule(cairo_fill_rule_t fill_rule);
|
||||
void move_to(double x, double y);
|
||||
void curve_to(double ct1_x, double ct1_y, double ct2_x, double ct2_y, double end_x, double end_y);
|
||||
|
@ -326,7 +304,7 @@ public:
|
|||
void set_gradient(cairo_gradient const& pattern, box2d<double> const& bbox);
|
||||
void add_image(double x, double y, image_rgba8 const& data, double opacity = 1.0);
|
||||
void add_image(agg::trans_affine const& tr, image_rgba8 const& data, double opacity = 1.0);
|
||||
void set_font_face(cairo_face_manager & manager, face_ptr face);
|
||||
void set_font_face(cairo_face_manager& manager, face_ptr face);
|
||||
void set_font_matrix(cairo_matrix_t const& matrix);
|
||||
void set_matrix(cairo_matrix_t const& matrix);
|
||||
void transform(cairo_matrix_t const& matrix);
|
||||
|
@ -336,7 +314,7 @@ public:
|
|||
void show_glyph(unsigned long index, pixel_position const& pos);
|
||||
void glyph_path(unsigned long index, pixel_position const& pos);
|
||||
void add_text(glyph_positions const& pos,
|
||||
cairo_face_manager & manager,
|
||||
cairo_face_manager& manager,
|
||||
composite_mode_e comp_op = src_over,
|
||||
composite_mode_e halo_comp_op = src_over,
|
||||
double scale_factor = 1.0);
|
||||
|
@ -344,7 +322,7 @@ public:
|
|||
void push_group();
|
||||
void pop_group();
|
||||
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
void add_path(T& path, unsigned start_index = 0)
|
||||
{
|
||||
double x, y;
|
||||
|
@ -366,11 +344,11 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
void add_agg_path(T& path, unsigned start_index = 0)
|
||||
{
|
||||
double x=0;
|
||||
double y=0;
|
||||
double x = 0;
|
||||
double y = 0;
|
||||
|
||||
path.rewind(start_index);
|
||||
|
||||
|
@ -384,26 +362,26 @@ public:
|
|||
{
|
||||
if (agg::is_curve3(cm))
|
||||
{
|
||||
double end_x=0;
|
||||
double end_y=0;
|
||||
double end_x = 0;
|
||||
double end_y = 0;
|
||||
|
||||
MAPNIK_LOG_WARN(cairo_renderer) << "Curve 3 not implemented";
|
||||
|
||||
path.vertex(&end_x, &end_y);
|
||||
|
||||
curve_to(x,y,x,y,end_x,end_y);
|
||||
curve_to(x, y, x, y, end_x, end_y);
|
||||
}
|
||||
else if (agg::is_curve4(cm))
|
||||
{
|
||||
double ct2_x=0;
|
||||
double ct2_y=0;
|
||||
double end_x=0;
|
||||
double end_y=0;
|
||||
double ct2_x = 0;
|
||||
double ct2_y = 0;
|
||||
double end_x = 0;
|
||||
double end_y = 0;
|
||||
|
||||
path.vertex(&ct2_x, &ct2_y);
|
||||
path.vertex(&end_x, &end_y);
|
||||
|
||||
curve_to(x,y,ct2_x,ct2_y,end_x,end_y);
|
||||
curve_to(x, y, ct2_x, ct2_y, end_x, end_y);
|
||||
}
|
||||
else if (agg::is_line_to(cm))
|
||||
{
|
||||
|
@ -426,21 +404,22 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
cairo_ptr cairo_;
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
template<typename Context>
|
||||
struct line_pattern_rasterizer
|
||||
{
|
||||
line_pattern_rasterizer(Context & context, cairo_pattern & pattern, unsigned width, unsigned height)
|
||||
: context_(context),
|
||||
pattern_(pattern),
|
||||
width_(width),
|
||||
height_(height) {}
|
||||
line_pattern_rasterizer(Context& context, cairo_pattern& pattern, unsigned width, unsigned height)
|
||||
: context_(context)
|
||||
, pattern_(pattern)
|
||||
, width_(width)
|
||||
, height_(height)
|
||||
{}
|
||||
|
||||
template <typename T>
|
||||
void add_path(T & path, unsigned start_index = 0)
|
||||
template<typename T>
|
||||
void add_path(T& path, unsigned start_index = 0)
|
||||
{
|
||||
double length = 0.0;
|
||||
double x0 = 0.0;
|
||||
|
@ -479,13 +458,12 @@ struct line_pattern_rasterizer
|
|||
}
|
||||
}
|
||||
|
||||
Context & context_;
|
||||
cairo_pattern & pattern_;
|
||||
Context& context_;
|
||||
cairo_pattern& pattern_;
|
||||
unsigned width_;
|
||||
unsigned height_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_CAIRO_CONTEXT_HPP
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
#ifndef MAPNIK_CAIRO_IMAGE_UTIL_HPP
|
||||
#define MAPNIK_CAIRO_IMAGE_UTIL_HPP
|
||||
|
||||
|
@ -33,8 +32,7 @@
|
|||
|
||||
namespace mapnik {
|
||||
|
||||
static inline void cairo_image_to_rgba8(mapnik::image_rgba8 & data,
|
||||
cairo_surface_ptr const& surface)
|
||||
static inline void cairo_image_to_rgba8(mapnik::image_rgba8& data, cairo_surface_ptr const& surface)
|
||||
{
|
||||
if (cairo_image_surface_get_format(&*surface) != CAIRO_FORMAT_ARGB32)
|
||||
{
|
||||
|
@ -50,7 +48,7 @@ static inline void cairo_image_to_rgba8(mapnik::image_rgba8 & data,
|
|||
int stride = cairo_image_surface_get_stride(&*surface) / 4;
|
||||
|
||||
const std::unique_ptr<unsigned int[]> out_row(new unsigned int[data.width()]);
|
||||
const unsigned int *in_row = (const unsigned int *)cairo_image_surface_get_data(&*surface);
|
||||
const unsigned int* in_row = (const unsigned int*)cairo_image_surface_get_data(&*surface);
|
||||
|
||||
for (unsigned int row = 0; row < data.height(); row++, in_row += stride)
|
||||
{
|
||||
|
@ -62,11 +60,16 @@ static inline void cairo_image_to_rgba8(mapnik::image_rgba8 & data,
|
|||
unsigned int g = (in >> 8) & 0xff;
|
||||
unsigned int b = (in >> 0) & 0xff;
|
||||
|
||||
#define DE_ALPHA(x) do { \
|
||||
if (a == 0) x = 0; \
|
||||
else x = x * 255 / a; \
|
||||
if (x > 255) x = 255; \
|
||||
} while(0)
|
||||
#define DE_ALPHA(x) \
|
||||
do \
|
||||
{ \
|
||||
if (a == 0) \
|
||||
x = 0; \
|
||||
else \
|
||||
x = x * 255 / a; \
|
||||
if (x > 255) \
|
||||
x = 255; \
|
||||
} while (0)
|
||||
|
||||
DE_ALPHA(r);
|
||||
DE_ALPHA(g);
|
||||
|
@ -78,7 +81,6 @@ static inline void cairo_image_to_rgba8(mapnik::image_rgba8 & data,
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_CAIRO_IMAGE_UTIL_HPP
|
||||
|
|
|
@ -32,12 +32,14 @@ namespace mapnik {
|
|||
|
||||
class cairo_context;
|
||||
|
||||
void render_vector_marker(cairo_context & context, svg_path_adapter & svg_path,
|
||||
void render_vector_marker(cairo_context& context,
|
||||
svg_path_adapter& svg_path,
|
||||
svg_attribute_type const& attributes,
|
||||
box2d<double> const& bbox, agg::trans_affine const& tr,
|
||||
box2d<double> const& bbox,
|
||||
agg::trans_affine const& tr,
|
||||
double opacity);
|
||||
|
||||
}
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_CAIRO_RENDER_VECTOR_HPP
|
||||
|
||||
|
|
|
@ -53,42 +53,35 @@ class request;
|
|||
struct pixel_position;
|
||||
struct cairo_save_restore
|
||||
{
|
||||
cairo_save_restore(cairo_context & context)
|
||||
cairo_save_restore(cairo_context& context)
|
||||
: context_(context)
|
||||
{
|
||||
context_.save();
|
||||
}
|
||||
~cairo_save_restore()
|
||||
{
|
||||
context_.restore();
|
||||
}
|
||||
cairo_context & context_;
|
||||
~cairo_save_restore() { context_.restore(); }
|
||||
cairo_context& context_;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class MAPNIK_DECL cairo_renderer : public feature_style_processor<cairo_renderer<T> >,
|
||||
template<typename T>
|
||||
class MAPNIK_DECL cairo_renderer : public feature_style_processor<cairo_renderer<T>>,
|
||||
private util::noncopyable
|
||||
{
|
||||
public:
|
||||
public:
|
||||
using processor_impl_type = cairo_renderer<T>;
|
||||
cairo_renderer(Map const& m,
|
||||
T const& obj,
|
||||
double scale_factor=1.0,
|
||||
unsigned offset_x=0,
|
||||
unsigned offset_y=0);
|
||||
cairo_renderer(Map const& m, T const& obj, double scale_factor = 1.0, unsigned offset_x = 0, unsigned offset_y = 0);
|
||||
cairo_renderer(Map const& m,
|
||||
request const& req,
|
||||
attributes const& vars,
|
||||
T const& obj,
|
||||
double scale_factor=1.0,
|
||||
unsigned offset_x=0,
|
||||
unsigned offset_y=0);
|
||||
double scale_factor = 1.0,
|
||||
unsigned offset_x = 0,
|
||||
unsigned offset_y = 0);
|
||||
cairo_renderer(Map const& m,
|
||||
T const& obj,
|
||||
std::shared_ptr<label_collision_detector4> detector,
|
||||
double scale_factor=1.0,
|
||||
unsigned offset_x=0,
|
||||
unsigned offset_y=0);
|
||||
double scale_factor = 1.0,
|
||||
unsigned offset_x = 0,
|
||||
unsigned offset_y = 0);
|
||||
|
||||
~cairo_renderer();
|
||||
void start_map_processing(Map const& map);
|
||||
|
@ -97,93 +90,56 @@ public:
|
|||
void end_layer_processing(layer const& lay);
|
||||
void start_style_processing(feature_type_style const& st);
|
||||
void end_style_processing(feature_type_style const& st);
|
||||
void process(point_symbolizer const& sym,
|
||||
mapnik::feature_impl & feature,
|
||||
proj_transform const& prj_trans);
|
||||
void process(line_symbolizer const& sym,
|
||||
mapnik::feature_impl & feature,
|
||||
proj_transform const& prj_trans);
|
||||
void process(line_pattern_symbolizer const& sym,
|
||||
mapnik::feature_impl & feature,
|
||||
proj_transform const& prj_trans);
|
||||
void process(polygon_symbolizer const& sym,
|
||||
mapnik::feature_impl & feature,
|
||||
proj_transform const& prj_trans);
|
||||
void process(polygon_pattern_symbolizer const& sym,
|
||||
mapnik::feature_impl & feature,
|
||||
proj_transform const& prj_trans);
|
||||
void process(raster_symbolizer const& sym,
|
||||
mapnik::feature_impl & feature,
|
||||
proj_transform const& prj_trans);
|
||||
void process(shield_symbolizer const& sym,
|
||||
mapnik::feature_impl & feature,
|
||||
proj_transform const& prj_trans);
|
||||
void process(text_symbolizer const& sym,
|
||||
mapnik::feature_impl & feature,
|
||||
proj_transform const& prj_trans);
|
||||
void process(building_symbolizer const& sym,
|
||||
mapnik::feature_impl & feature,
|
||||
proj_transform const& prj_trans);
|
||||
void process(markers_symbolizer const& sym,
|
||||
mapnik::feature_impl & feature,
|
||||
proj_transform const& prj_trans);
|
||||
void process(group_symbolizer const& sym,
|
||||
mapnik::feature_impl & feature,
|
||||
proj_transform const& prj_trans);
|
||||
void process(debug_symbolizer const& sym,
|
||||
mapnik::feature_impl & feature,
|
||||
proj_transform const& prj_trans);
|
||||
inline bool process(rule::symbolizers const& /*syms*/,
|
||||
mapnik::feature_impl & /*feature*/,
|
||||
proj_transform const& /*prj_trans*/)
|
||||
void process(point_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||
void process(line_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||
void process(line_pattern_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||
void process(polygon_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||
void process(polygon_pattern_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||
void process(raster_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||
void process(shield_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||
void process(text_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||
void process(building_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||
void process(markers_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||
void process(group_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||
void process(debug_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||
inline bool
|
||||
process(rule::symbolizers const& /*syms*/, mapnik::feature_impl& /*feature*/, proj_transform const& /*prj_trans*/)
|
||||
{
|
||||
// cairo renderer doesn't support processing of multiple symbolizers.
|
||||
return false;
|
||||
}
|
||||
|
||||
bool painted()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool painted() { return true; }
|
||||
|
||||
void painted(bool /*painted*/)
|
||||
{
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
inline eAttributeCollectionPolicy attribute_collection_policy() const
|
||||
{
|
||||
return DEFAULT;
|
||||
}
|
||||
inline eAttributeCollectionPolicy attribute_collection_policy() const { return DEFAULT; }
|
||||
|
||||
inline double scale_factor() const
|
||||
{
|
||||
return common_.scale_factor_;
|
||||
}
|
||||
inline double scale_factor() const { return common_.scale_factor_; }
|
||||
|
||||
inline attributes const& variables() const
|
||||
{
|
||||
return common_.vars_;
|
||||
}
|
||||
inline attributes const& variables() const { return common_.vars_; }
|
||||
|
||||
void render_marker(pixel_position const& pos,
|
||||
marker const& marker,
|
||||
agg::trans_affine const& mtx,
|
||||
double opacity=1.0,
|
||||
bool recenter=true);
|
||||
protected:
|
||||
double opacity = 1.0,
|
||||
bool recenter = true);
|
||||
|
||||
protected:
|
||||
Map const& m_;
|
||||
cairo_context context_;
|
||||
renderer_common common_;
|
||||
cairo_face_manager face_manager_;
|
||||
bool style_level_compositing_;
|
||||
void setup(Map const& m);
|
||||
|
||||
};
|
||||
|
||||
extern template class MAPNIK_DECL cairo_renderer<cairo_ptr>;
|
||||
|
||||
}
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_CAIRO_RENDERER_HPP
|
||||
|
||||
|
|
|
@ -36,36 +36,31 @@ namespace mapnik {
|
|||
|
||||
struct cairo_renderer_process_visitor_p
|
||||
{
|
||||
cairo_renderer_process_visitor_p(agg::trans_affine const& image_tr,
|
||||
double opacity)
|
||||
: image_tr_(image_tr),
|
||||
opacity_(opacity)
|
||||
cairo_renderer_process_visitor_p(agg::trans_affine const& image_tr, double opacity)
|
||||
: image_tr_(image_tr)
|
||||
, opacity_(opacity)
|
||||
{}
|
||||
|
||||
cairo_surface_ptr operator()(marker_svg const & marker) const
|
||||
cairo_surface_ptr operator()(marker_svg const& marker) const
|
||||
{
|
||||
box2d<double> bbox(marker.bounding_box());
|
||||
agg::trans_affine tr(transform(bbox));
|
||||
|
||||
double width = std::max(1.0, std::round(bbox.width()));
|
||||
double height = std::max(1.0, std::round(bbox.height()));
|
||||
cairo_rectangle_t extent { 0, 0, width, height };
|
||||
cairo_surface_ptr surface(
|
||||
cairo_recording_surface_create(
|
||||
CAIRO_CONTENT_COLOR_ALPHA, &extent),
|
||||
cairo_surface_closer());
|
||||
cairo_rectangle_t extent{0, 0, width, height};
|
||||
cairo_surface_ptr surface(cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, &extent),
|
||||
cairo_surface_closer());
|
||||
|
||||
cairo_ptr cairo = create_context(surface);
|
||||
cairo_context context(cairo);
|
||||
|
||||
svg_storage_type & svg = *marker.get_data();
|
||||
svg_storage_type& svg = *marker.get_data();
|
||||
svg_attribute_type const& svg_attributes = svg.attributes();
|
||||
svg::vertex_stl_adapter<svg::svg_path_storage> stl_storage(
|
||||
svg.source());
|
||||
svg::vertex_stl_adapter<svg::svg_path_storage> stl_storage(svg.source());
|
||||
svg::svg_path_adapter svg_path(stl_storage);
|
||||
|
||||
render_vector_marker(context, svg_path, svg_attributes,
|
||||
bbox, tr, opacity_);
|
||||
render_vector_marker(context, svg_path, svg_attributes, bbox, tr, opacity_);
|
||||
|
||||
return surface;
|
||||
}
|
||||
|
@ -75,11 +70,9 @@ struct cairo_renderer_process_visitor_p
|
|||
box2d<double> bbox(marker.bounding_box());
|
||||
agg::trans_affine tr(transform(bbox));
|
||||
|
||||
cairo_rectangle_t extent { 0, 0, bbox.width(), bbox.height() };
|
||||
cairo_surface_ptr surface(
|
||||
cairo_recording_surface_create(
|
||||
CAIRO_CONTENT_COLOR_ALPHA, &extent),
|
||||
cairo_surface_closer());
|
||||
cairo_rectangle_t extent{0, 0, bbox.width(), bbox.height()};
|
||||
cairo_surface_ptr surface(cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, &extent),
|
||||
cairo_surface_closer());
|
||||
|
||||
cairo_ptr cairo = create_context(surface);
|
||||
cairo_context context(cairo);
|
||||
|
@ -89,25 +82,21 @@ struct cairo_renderer_process_visitor_p
|
|||
return surface;
|
||||
}
|
||||
|
||||
cairo_surface_ptr operator() (marker_null const&) const
|
||||
cairo_surface_ptr operator()(marker_null const&) const
|
||||
{
|
||||
cairo_surface_ptr surface(
|
||||
cairo_recording_surface_create(
|
||||
CAIRO_CONTENT_COLOR_ALPHA, nullptr),
|
||||
cairo_surface_closer());
|
||||
cairo_surface_ptr surface(cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, nullptr),
|
||||
cairo_surface_closer());
|
||||
cairo_ptr cairo = create_context(surface);
|
||||
cairo_context context(cairo);
|
||||
return surface;
|
||||
}
|
||||
|
||||
private:
|
||||
agg::trans_affine transform(box2d<double> & bbox) const
|
||||
private:
|
||||
agg::trans_affine transform(box2d<double>& bbox) const
|
||||
{
|
||||
bbox *= image_tr_;
|
||||
coord<double, 2> c = bbox.center();
|
||||
agg::trans_affine mtx = agg::trans_affine_translation(
|
||||
0.5 * bbox.width() - c.x,
|
||||
0.5 * bbox.height() - c.y);
|
||||
agg::trans_affine mtx = agg::trans_affine_translation(0.5 * bbox.width() - c.x, 0.5 * bbox.height() - c.y);
|
||||
return image_tr_ * mtx;
|
||||
}
|
||||
|
||||
|
@ -135,7 +124,7 @@ struct cairo_pattern_base
|
|||
}
|
||||
};
|
||||
|
||||
template <typename VertexConverter>
|
||||
template<typename VertexConverter>
|
||||
struct cairo_polygon_pattern : cairo_pattern_base
|
||||
{
|
||||
cairo_polygon_pattern(mapnik::marker const& marker,
|
||||
|
@ -143,22 +132,23 @@ struct cairo_polygon_pattern : cairo_pattern_base
|
|||
symbolizer_base const& sym,
|
||||
mapnik::feature_impl const& feature,
|
||||
proj_transform const& prj_trans)
|
||||
: cairo_pattern_base{marker, common, sym, feature, prj_trans},
|
||||
clip_(get<value_bool, keys::clip>(sym_, feature_, common_.vars_)),
|
||||
clip_box_(clipping_extent(common)),
|
||||
tr_(geom_transform()),
|
||||
converter_(clip_box_, sym, common.t_, prj_trans, tr_,
|
||||
feature, common.vars_, common.scale_factor_)
|
||||
: cairo_pattern_base{marker, common, sym, feature, prj_trans}
|
||||
, clip_(get<value_bool, keys::clip>(sym_, feature_, common_.vars_))
|
||||
, clip_box_(clipping_extent(common))
|
||||
, tr_(geom_transform())
|
||||
, converter_(clip_box_, sym, common.t_, prj_trans, tr_, feature, common.vars_, common.scale_factor_)
|
||||
{
|
||||
value_double simplify_tolerance = get<value_double, keys::simplify_tolerance>(sym, feature, common_.vars_);
|
||||
value_double smooth = get<value_double, keys::smooth>(sym, feature, common_.vars_);
|
||||
|
||||
converter_.template set<affine_transform_tag>();
|
||||
if (simplify_tolerance > 0.0) converter_.template set<simplify_tag>();
|
||||
if (smooth > 0.0) converter_.template set<smooth_tag>();
|
||||
if (simplify_tolerance > 0.0)
|
||||
converter_.template set<simplify_tag>();
|
||||
if (smooth > 0.0)
|
||||
converter_.template set<smooth_tag>();
|
||||
}
|
||||
|
||||
void render(cairo_fill_rule_t fill_rule, cairo_context & context)
|
||||
void render(cairo_fill_rule_t fill_rule, cairo_context& context)
|
||||
{
|
||||
value_double opacity = get<value_double, keys::opacity>(sym_, feature_, common_.vars_);
|
||||
agg::trans_affine image_tr = agg::trans_affine_scaling(common_.scale_factor_);
|
||||
|
@ -181,8 +171,12 @@ struct cairo_polygon_pattern : cairo_pattern_base
|
|||
cairo_rectangle_t pattern_surface_extent;
|
||||
if (cairo_recording_surface_get_extents(surface.get(), &pattern_surface_extent))
|
||||
{
|
||||
offset = pattern_offset(sym_, feature_, prj_trans_, common_,
|
||||
pattern_surface_extent.width, pattern_surface_extent.height);
|
||||
offset = pattern_offset(sym_,
|
||||
feature_,
|
||||
prj_trans_,
|
||||
common_,
|
||||
pattern_surface_extent.width,
|
||||
pattern_surface_extent.height);
|
||||
}
|
||||
|
||||
cairo_pattern pattern(surface);
|
||||
|
@ -193,7 +187,7 @@ struct cairo_polygon_pattern : cairo_pattern_base
|
|||
using apply_vertex_converter_type = detail::apply_vertex_converter<VertexConverter, cairo_context>;
|
||||
using vertex_processor_type = geometry::vertex_processor<apply_vertex_converter_type>;
|
||||
apply_vertex_converter_type apply(converter_, context);
|
||||
mapnik::util::apply_visitor(vertex_processor_type(apply),feature_.get_geometry());
|
||||
mapnik::util::apply_visitor(vertex_processor_type(apply), feature_.get_geometry());
|
||||
// fill polygon
|
||||
context.set_fill_rule(fill_rule);
|
||||
context.fill();
|
||||
|
@ -207,5 +201,4 @@ struct cairo_polygon_pattern : cairo_pattern_base
|
|||
|
||||
} // namespace mapnik
|
||||
|
||||
|
||||
#endif // MAPNIK_CAIRO_RENDER_POLYGON_PATTERN_HPP
|
||||
|
|
|
@ -35,15 +35,15 @@ namespace mapnik {
|
|||
#if defined(HAVE_CAIRO)
|
||||
MAPNIK_DECL void save_to_cairo_file(mapnik::Map const& map,
|
||||
std::string const& filename,
|
||||
double scale_factor=1.0,
|
||||
double scale_denominator=0.0);
|
||||
double scale_factor = 1.0,
|
||||
double scale_denominator = 0.0);
|
||||
MAPNIK_DECL void save_to_cairo_file(mapnik::Map const& map,
|
||||
std::string const& filename,
|
||||
std::string const& type,
|
||||
double scale_factor=1.0,
|
||||
double scale_denominator=0.0);
|
||||
double scale_factor = 1.0,
|
||||
double scale_denominator = 0.0);
|
||||
#endif
|
||||
|
||||
} // end ns
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_CAIRO_IO_HPP
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace mapnik {
|
|||
|
||||
class MAPNIK_DECL color : boost::equality_comparable<color>
|
||||
{
|
||||
public:
|
||||
public:
|
||||
std::uint8_t red_;
|
||||
std::uint8_t green_;
|
||||
std::uint8_t blue_;
|
||||
|
@ -50,46 +50,52 @@ public:
|
|||
|
||||
// default ctor
|
||||
color()
|
||||
: red_(0xff),
|
||||
green_(0xff),
|
||||
blue_(0xff),
|
||||
alpha_(0xff),
|
||||
premultiplied_(false)
|
||||
{}
|
||||
: red_(0xff)
|
||||
, green_(0xff)
|
||||
, blue_(0xff)
|
||||
, alpha_(0xff)
|
||||
, premultiplied_(false)
|
||||
{}
|
||||
|
||||
color(std::uint8_t _red, std::uint8_t _green, std::uint8_t _blue, std::uint8_t _alpha = 0xff, bool premultiplied = false)
|
||||
: red_(_red),
|
||||
green_(_green),
|
||||
blue_(_blue),
|
||||
alpha_(_alpha),
|
||||
premultiplied_(premultiplied)
|
||||
{}
|
||||
color(std::uint8_t _red,
|
||||
std::uint8_t _green,
|
||||
std::uint8_t _blue,
|
||||
std::uint8_t _alpha = 0xff,
|
||||
bool premultiplied = false)
|
||||
: red_(_red)
|
||||
, green_(_green)
|
||||
, blue_(_blue)
|
||||
, alpha_(_alpha)
|
||||
, premultiplied_(premultiplied)
|
||||
{}
|
||||
|
||||
color(std::uint32_t _rgba, bool premultiplied = false)
|
||||
: red_(_rgba & 0xff),
|
||||
green_((_rgba >> 8) & 0xff),
|
||||
blue_((_rgba >> 16) & 0xff),
|
||||
alpha_((_rgba >> 24) & 0xff),
|
||||
premultiplied_(premultiplied) {}
|
||||
: red_(_rgba & 0xff)
|
||||
, green_((_rgba >> 8) & 0xff)
|
||||
, blue_((_rgba >> 16) & 0xff)
|
||||
, alpha_((_rgba >> 24) & 0xff)
|
||||
, premultiplied_(premultiplied)
|
||||
{}
|
||||
|
||||
// copy ctor
|
||||
color(const color& rhs)
|
||||
: red_(rhs.red_),
|
||||
green_(rhs.green_),
|
||||
blue_(rhs.blue_),
|
||||
alpha_(rhs.alpha_),
|
||||
premultiplied_(rhs.premultiplied_)
|
||||
{}
|
||||
: red_(rhs.red_)
|
||||
, green_(rhs.green_)
|
||||
, blue_(rhs.blue_)
|
||||
, alpha_(rhs.alpha_)
|
||||
, premultiplied_(rhs.premultiplied_)
|
||||
{}
|
||||
|
||||
// move ctor
|
||||
color(color && rhs)
|
||||
: red_(std::move(rhs.red_)),
|
||||
green_(std::move(rhs.green_)),
|
||||
blue_(std::move(rhs.blue_)),
|
||||
alpha_(std::move(rhs.alpha_)),
|
||||
premultiplied_(std::move(rhs.premultiplied_)) {}
|
||||
color(color&& rhs)
|
||||
: red_(std::move(rhs.red_))
|
||||
, green_(std::move(rhs.green_))
|
||||
, blue_(std::move(rhs.blue_))
|
||||
, alpha_(std::move(rhs.alpha_))
|
||||
, premultiplied_(std::move(rhs.premultiplied_))
|
||||
{}
|
||||
|
||||
color( std::string const& str, bool premultiplied = false);
|
||||
color(std::string const& str, bool premultiplied = false);
|
||||
|
||||
std::string to_string() const;
|
||||
std::string to_hex_string() const;
|
||||
|
@ -104,78 +110,45 @@ public:
|
|||
|
||||
inline bool operator==(color const& rhs) const
|
||||
{
|
||||
return (red_== rhs.red_) &&
|
||||
(green_ == rhs.green_) &&
|
||||
(blue_ == rhs.blue_) &&
|
||||
(alpha_ == rhs.alpha_) &&
|
||||
(premultiplied_ == rhs.premultiplied_);
|
||||
return (red_ == rhs.red_) && (green_ == rhs.green_) && (blue_ == rhs.blue_) && (alpha_ == rhs.alpha_) &&
|
||||
(premultiplied_ == rhs.premultiplied_);
|
||||
}
|
||||
|
||||
inline std::uint8_t red() const
|
||||
{
|
||||
return red_;
|
||||
}
|
||||
inline std::uint8_t red() const { return red_; }
|
||||
|
||||
inline std::uint8_t green() const
|
||||
{
|
||||
return green_;
|
||||
}
|
||||
inline std::uint8_t green() const { return green_; }
|
||||
|
||||
inline std::uint8_t blue() const
|
||||
{
|
||||
return blue_;
|
||||
}
|
||||
inline std::uint8_t blue() const { return blue_; }
|
||||
|
||||
inline std::uint8_t alpha() const
|
||||
{
|
||||
return alpha_;
|
||||
}
|
||||
inline std::uint8_t alpha() const { return alpha_; }
|
||||
|
||||
inline void set_red(std::uint8_t _red)
|
||||
{
|
||||
red_ = _red;
|
||||
}
|
||||
inline void set_red(std::uint8_t _red) { red_ = _red; }
|
||||
|
||||
inline void set_green(std::uint8_t _green)
|
||||
{
|
||||
green_ = _green;
|
||||
}
|
||||
inline void set_green(std::uint8_t _green) { green_ = _green; }
|
||||
|
||||
inline void set_blue(std::uint8_t _blue)
|
||||
{
|
||||
blue_ = _blue;
|
||||
}
|
||||
inline void set_alpha(std::uint8_t _alpha)
|
||||
{
|
||||
alpha_ = _alpha;
|
||||
}
|
||||
inline bool get_premultiplied() const
|
||||
{
|
||||
return premultiplied_;
|
||||
}
|
||||
inline void set_premultiplied(bool val)
|
||||
{
|
||||
premultiplied_ = val;
|
||||
}
|
||||
inline void set_blue(std::uint8_t _blue) { blue_ = _blue; }
|
||||
inline void set_alpha(std::uint8_t _alpha) { alpha_ = _alpha; }
|
||||
inline bool get_premultiplied() const { return premultiplied_; }
|
||||
inline void set_premultiplied(bool val) { premultiplied_ = val; }
|
||||
|
||||
inline unsigned rgba() const
|
||||
{
|
||||
return static_cast<unsigned>((alpha_ << 24) | (blue_ << 16) | (green_ << 8) | (red_)) ;
|
||||
return static_cast<unsigned>((alpha_ << 24) | (blue_ << 16) | (green_ << 8) | (red_));
|
||||
}
|
||||
private:
|
||||
void swap(color & rhs)
|
||||
|
||||
private:
|
||||
void swap(color& rhs)
|
||||
{
|
||||
std::swap(red_, rhs.red_);
|
||||
std::swap(green_,rhs.green_);
|
||||
std::swap(blue_,rhs.blue_);
|
||||
std::swap(alpha_,rhs.alpha_);
|
||||
std::swap(green_, rhs.green_);
|
||||
std::swap(blue_, rhs.blue_);
|
||||
std::swap(alpha_, rhs.alpha_);
|
||||
std::swap(premultiplied_, rhs.premultiplied_);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename charT, typename traits>
|
||||
std::basic_ostream<charT, traits> &
|
||||
operator << ( std::basic_ostream<charT, traits> & s, mapnik::color const& c )
|
||||
template<typename charT, typename traits>
|
||||
std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& s, mapnik::color const& c)
|
||||
{
|
||||
s << c.to_string();
|
||||
return s;
|
||||
|
@ -187,6 +160,6 @@ inline std::size_t hash_value(color const& c)
|
|||
return c.rgba();
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_COLOR_HPP
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
// mapnik
|
||||
#include <mapnik/color.hpp>
|
||||
|
||||
//stl
|
||||
// stl
|
||||
#include <string>
|
||||
|
||||
namespace mapnik {
|
||||
|
|
|
@ -26,28 +26,28 @@
|
|||
// Windows DLL support
|
||||
|
||||
#ifdef _WIN32
|
||||
# define MAPNIK_EXP __declspec (dllexport)
|
||||
# define MAPNIK_IMP __declspec (dllimport)
|
||||
# ifdef MAPNIK_EXPORTS
|
||||
# define MAPNIK_DECL __declspec (dllexport)
|
||||
# else
|
||||
# define MAPNIK_DECL __declspec (dllimport)
|
||||
# endif
|
||||
# pragma warning( disable: 4251 )
|
||||
# pragma warning( disable: 4275 )
|
||||
# if (_MSC_VER >= 1400) // vc8
|
||||
# pragma warning(disable : 4996) //_CRT_SECURE_NO_DEPRECATE
|
||||
# endif
|
||||
#define MAPNIK_EXP __declspec(dllexport)
|
||||
#define MAPNIK_IMP __declspec(dllimport)
|
||||
#ifdef MAPNIK_EXPORTS
|
||||
#define MAPNIK_DECL __declspec(dllexport)
|
||||
#else
|
||||
# if __GNUC__ >= 4
|
||||
# define MAPNIK_EXP __attribute__ ((visibility ("default")))
|
||||
# define MAPNIK_DECL __attribute__ ((visibility ("default")))
|
||||
# define MAPNIK_IMP __attribute__ ((visibility ("default")))
|
||||
# else
|
||||
# define MAPNIK_EXP
|
||||
# define MAPNIK_DECL
|
||||
# define MAPNIK_IMP
|
||||
# endif
|
||||
#define MAPNIK_DECL __declspec(dllimport)
|
||||
#endif
|
||||
#pragma warning(disable: 4251)
|
||||
#pragma warning(disable: 4275)
|
||||
#if (_MSC_VER >= 1400) // vc8
|
||||
#pragma warning(disable: 4996) //_CRT_SECURE_NO_DEPRECATE
|
||||
#endif
|
||||
#else
|
||||
#if __GNUC__ >= 4
|
||||
#define MAPNIK_EXP __attribute__((visibility("default")))
|
||||
#define MAPNIK_DECL __attribute__((visibility("default")))
|
||||
#define MAPNIK_IMP __attribute__((visibility("default")))
|
||||
#else
|
||||
#define MAPNIK_EXP
|
||||
#define MAPNIK_DECL
|
||||
#define MAPNIK_IMP
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define PROJ_ENVELOPE_POINTS 20
|
||||
|
|
|
@ -34,19 +34,17 @@ class xml_node;
|
|||
|
||||
class config_error : public std::exception
|
||||
{
|
||||
public:
|
||||
public:
|
||||
config_error(std::string const& what);
|
||||
config_error(std::string const& what,
|
||||
xml_node const& node);
|
||||
config_error(std::string const& what,
|
||||
unsigned line_number,
|
||||
std::string const& filename);
|
||||
config_error(std::string const& what, xml_node const& node);
|
||||
config_error(std::string const& what, unsigned line_number, std::string const& filename);
|
||||
virtual ~config_error() {}
|
||||
virtual const char * what() const noexcept;
|
||||
virtual const char* what() const noexcept;
|
||||
void append_context(std::string const& ctx) const;
|
||||
void append_context(std::string const& ctx, xml_node const& node) const;
|
||||
void append_context(xml_node const& node) const;
|
||||
protected:
|
||||
|
||||
protected:
|
||||
mutable std::string what_;
|
||||
mutable unsigned line_number_;
|
||||
mutable std::string file_;
|
||||
|
@ -54,6 +52,6 @@ protected:
|
|||
mutable std::string msg_;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_CONFIG_ERROR_HPP
|
||||
|
|
|
@ -30,150 +30,173 @@ MAPNIK_DISABLE_WARNING_PUSH
|
|||
MAPNIK_DISABLE_WARNING_POP
|
||||
|
||||
namespace mapnik {
|
||||
template <typename T,int dim>
|
||||
struct coord {
|
||||
template<typename T, int dim>
|
||||
struct coord
|
||||
{
|
||||
using type = T;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct coord<T,2>
|
||||
: boost::addable<coord<T,2>,
|
||||
boost::addable2<coord<T,2>,T,
|
||||
boost::subtractable<coord<T,2>,
|
||||
boost::subtractable2<coord<T,2>,T,
|
||||
boost::dividable2<coord<T,2>, T,
|
||||
boost::multipliable2<coord<T,2>, T > > > > > >
|
||||
template<typename T>
|
||||
struct coord<T, 2>
|
||||
: boost::addable<
|
||||
coord<T, 2>,
|
||||
boost::addable2<
|
||||
coord<T, 2>,
|
||||
T,
|
||||
boost::subtractable<
|
||||
coord<T, 2>,
|
||||
boost::
|
||||
subtractable2<coord<T, 2>, T, boost::dividable2<coord<T, 2>, T, boost::multipliable2<coord<T, 2>, T>>>>>>
|
||||
|
||||
{
|
||||
using type = T;
|
||||
T x;
|
||||
T y;
|
||||
public:
|
||||
|
||||
public:
|
||||
coord()
|
||||
: x(),y() {}
|
||||
coord(T x_,T y_)
|
||||
: x(x_),y(y_) {}
|
||||
: x()
|
||||
, y()
|
||||
{}
|
||||
coord(T x_, T y_)
|
||||
: x(x_)
|
||||
, y(y_)
|
||||
{}
|
||||
|
||||
coord(coord<T,2> const& rhs)
|
||||
: x(rhs.x),
|
||||
y(rhs.y) {}
|
||||
coord(coord<T, 2> const& rhs)
|
||||
: x(rhs.x)
|
||||
, y(rhs.y)
|
||||
{}
|
||||
|
||||
template <typename T2>
|
||||
coord (coord<T2,2> const& rhs)
|
||||
: x(type(rhs.x)),
|
||||
y(type(rhs.y)) {}
|
||||
template<typename T2>
|
||||
coord(coord<T2, 2> const& rhs)
|
||||
: x(type(rhs.x))
|
||||
, y(type(rhs.y))
|
||||
{}
|
||||
|
||||
coord(coord<T,2> && rhs) noexcept
|
||||
: x(std::move(rhs.x)),
|
||||
y(std::move(rhs.y)) {}
|
||||
coord(coord<T, 2>&& rhs) noexcept
|
||||
: x(std::move(rhs.x))
|
||||
, y(std::move(rhs.y))
|
||||
{}
|
||||
|
||||
coord<T,2>& operator=(coord<T,2> rhs)
|
||||
coord<T, 2>& operator=(coord<T, 2> rhs)
|
||||
{
|
||||
swap(rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T2>
|
||||
coord<T,2>& operator=(const coord<T2,2>& rhs)
|
||||
template<typename T2>
|
||||
coord<T, 2>& operator=(const coord<T2, 2>& rhs)
|
||||
{
|
||||
coord<T,2> tmp(rhs);
|
||||
coord<T, 2> tmp(rhs);
|
||||
swap(rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T2>
|
||||
bool operator==(coord<T2,2> const& rhs)
|
||||
template<typename T2>
|
||||
bool operator==(coord<T2, 2> const& rhs)
|
||||
{
|
||||
return x == rhs.x && y == rhs.y;
|
||||
}
|
||||
|
||||
coord<T,2>& operator+=(coord<T,2> const& rhs)
|
||||
coord<T, 2>& operator+=(coord<T, 2> const& rhs)
|
||||
{
|
||||
x+=rhs.x;
|
||||
y+=rhs.y;
|
||||
x += rhs.x;
|
||||
y += rhs.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
coord<T,2>& operator+=(T rhs)
|
||||
coord<T, 2>& operator+=(T rhs)
|
||||
{
|
||||
x+=rhs;
|
||||
y+=rhs;
|
||||
x += rhs;
|
||||
y += rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
coord<T,2>& operator-=(coord<T,2> const& rhs)
|
||||
coord<T, 2>& operator-=(coord<T, 2> const& rhs)
|
||||
{
|
||||
x-=rhs.x;
|
||||
y-=rhs.y;
|
||||
x -= rhs.x;
|
||||
y -= rhs.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
coord<T,2>& operator-=(T rhs)
|
||||
coord<T, 2>& operator-=(T rhs)
|
||||
{
|
||||
x-=rhs;
|
||||
y-=rhs;
|
||||
x -= rhs;
|
||||
y -= rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
coord<T,2>& operator*=(T t)
|
||||
coord<T, 2>& operator*=(T t)
|
||||
{
|
||||
x*=t;
|
||||
y*=t;
|
||||
x *= t;
|
||||
y *= t;
|
||||
return *this;
|
||||
}
|
||||
coord<T,2>& operator/=(T t)
|
||||
coord<T, 2>& operator/=(T t)
|
||||
{
|
||||
x/=t;
|
||||
y/=t;
|
||||
x /= t;
|
||||
y /= t;
|
||||
return *this;
|
||||
}
|
||||
private:
|
||||
void swap(coord<T,2> & rhs)
|
||||
|
||||
private:
|
||||
void swap(coord<T, 2>& rhs)
|
||||
{
|
||||
std::swap(this->x, rhs.x);
|
||||
std::swap(this->y, rhs.y);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct coord<T,3>
|
||||
template<typename T>
|
||||
struct coord<T, 3>
|
||||
{
|
||||
using type = T;
|
||||
T x;
|
||||
T y;
|
||||
T z;
|
||||
public:
|
||||
|
||||
public:
|
||||
coord()
|
||||
: x(),y(),z() {}
|
||||
coord(T x_,T y_,T z_)
|
||||
: x(x_),y(y_),z(z_) {}
|
||||
: x()
|
||||
, y()
|
||||
, z()
|
||||
{}
|
||||
coord(T x_, T y_, T z_)
|
||||
: x(x_)
|
||||
, y(y_)
|
||||
, z(z_)
|
||||
{}
|
||||
|
||||
template <typename T2>
|
||||
coord (coord<T2,3> const& rhs)
|
||||
: x(type(rhs.x)),
|
||||
y(type(rhs.y)),
|
||||
z(type(rhs.z)) {}
|
||||
template<typename T2>
|
||||
coord(coord<T2, 3> const& rhs)
|
||||
: x(type(rhs.x))
|
||||
, y(type(rhs.y))
|
||||
, z(type(rhs.z))
|
||||
{}
|
||||
|
||||
coord(coord<T,3> && rhs) noexcept
|
||||
: x(std::move(rhs.x)),
|
||||
y(std::move(rhs.y)),
|
||||
z(std::move(rhs.z)) {}
|
||||
coord(coord<T, 3>&& rhs) noexcept
|
||||
: x(std::move(rhs.x))
|
||||
, y(std::move(rhs.y))
|
||||
, z(std::move(rhs.z))
|
||||
{}
|
||||
|
||||
coord<T,3> operator=(coord<T,3> rhs)
|
||||
coord<T, 3> operator=(coord<T, 3> rhs)
|
||||
{
|
||||
swap(rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T2>
|
||||
coord<T,3>& operator=(coord<T2,3> const& rhs)
|
||||
template<typename T2>
|
||||
coord<T, 3>& operator=(coord<T2, 3> const& rhs)
|
||||
{
|
||||
coord<T,3> tmp(rhs);
|
||||
coord<T, 3> tmp(rhs);
|
||||
swap(tmp);
|
||||
return *this;
|
||||
}
|
||||
private:
|
||||
void swap(coord<T,3> & rhs)
|
||||
|
||||
private:
|
||||
void swap(coord<T, 3>& rhs)
|
||||
{
|
||||
std::swap(this->x, rhs.x);
|
||||
std::swap(this->y, rhs.y);
|
||||
|
@ -181,10 +204,10 @@ private:
|
|||
}
|
||||
};
|
||||
|
||||
using coord2d = coord<double,2>;
|
||||
using coord2f = coord<float,2>;
|
||||
using coord2i = coord<int,2>;
|
||||
using coord2d = coord<double, 2>;
|
||||
using coord2f = coord<float, 2>;
|
||||
using coord2i = coord<int, 2>;
|
||||
|
||||
}
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_COORD_HPP
|
||||
|
|
|
@ -31,13 +31,11 @@ MAPNIK_DISABLE_WARNING_PUSH
|
|||
#include <boost/spirit/home/x3.hpp>
|
||||
MAPNIK_DISABLE_WARNING_POP
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
namespace mapnik {
|
||||
|
||||
namespace x3 = boost::spirit::x3;
|
||||
|
||||
namespace css_color_grammar
|
||||
{
|
||||
namespace css_color_grammar {
|
||||
|
||||
struct css_color_class;
|
||||
using css_color_grammar_type = x3::rule<css_color_class, mapnik::color>;
|
||||
|
@ -46,6 +44,7 @@ css_color_grammar_type const css_color = "css_color";
|
|||
|
||||
BOOST_SPIRIT_DECLARE(css_color_grammar_type);
|
||||
|
||||
}}
|
||||
} // namespace css_color_grammar
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_CSS_COLOR_GRAMMAR_X3_HPP
|
||||
|
|
|
@ -37,13 +37,8 @@ MAPNIK_DISABLE_WARNING_PUSH
|
|||
#include <boost/fusion/adapted/std_tuple.hpp>
|
||||
MAPNIK_DISABLE_WARNING_POP
|
||||
|
||||
BOOST_FUSION_ADAPT_STRUCT (
|
||||
mapnik::color,
|
||||
(std::uint8_t, red_)
|
||||
(std::uint8_t, green_)
|
||||
(std::uint8_t, blue_)
|
||||
(std::uint8_t, alpha_)
|
||||
)
|
||||
BOOST_FUSION_ADAPT_STRUCT(mapnik::color,
|
||||
(std::uint8_t, red_)(std::uint8_t, green_)(std::uint8_t, blue_)(std::uint8_t, alpha_))
|
||||
|
||||
namespace mapnik {
|
||||
|
||||
|
@ -51,20 +46,21 @@ namespace x3 = boost::spirit::x3;
|
|||
|
||||
namespace css_color_grammar {
|
||||
|
||||
using x3::lit;
|
||||
using x3::uint_parser;
|
||||
using x3::hex;
|
||||
using x3::symbols;
|
||||
using x3::omit;
|
||||
using x3::attr;
|
||||
using x3::double_;
|
||||
using x3::hex;
|
||||
using x3::lit;
|
||||
using x3::no_case;
|
||||
using x3::no_skip;
|
||||
using x3::omit;
|
||||
using x3::symbols;
|
||||
using x3::uint_parser;
|
||||
|
||||
struct named_colors_ : x3::symbols<color>
|
||||
{
|
||||
named_colors_()
|
||||
{
|
||||
// clang-format off
|
||||
add
|
||||
("aliceblue", color(240, 248, 255))
|
||||
("antiquewhite", color(250, 235, 215))
|
||||
|
@ -216,6 +212,7 @@ struct named_colors_ : x3::symbols<color>
|
|||
("yellowgreen", color(154, 205, 50))
|
||||
("transparent", color(0, 0, 0, 0))
|
||||
;
|
||||
// clang-format on
|
||||
}
|
||||
} named_colors;
|
||||
|
||||
|
@ -226,7 +223,7 @@ x3::uint_parser<std::uint16_t, 10, 1, 3> dec3;
|
|||
// rules
|
||||
x3::rule<class hex2_color, color> const hex2_color("hex2_color");
|
||||
x3::rule<class hex1_color, color> const hex1_color("hex1_color");
|
||||
x3::rule<class rgb_color, color> const rgb_color("rgb_color");
|
||||
x3::rule<class rgb_color, color> const rgb_color("rgb_color");
|
||||
x3::rule<class rgba_color, color> const rgba_color("rgba_color");
|
||||
x3::rule<class rgb_color_percent, color> const rgb_color_percent("rgb_color_percent");
|
||||
x3::rule<class rgba_color_percent, color> const rgba_color_percent("rgba_color_percent");
|
||||
|
@ -235,97 +232,80 @@ struct clip_opacity
|
|||
{
|
||||
static double call(double val)
|
||||
{
|
||||
if (val > 1.0) return 1.0;
|
||||
if (val < 0.0) return 0.0;
|
||||
if (val > 1.0)
|
||||
return 1.0;
|
||||
if (val < 0.0)
|
||||
return 0.0;
|
||||
return val;
|
||||
}
|
||||
};
|
||||
|
||||
struct percent_converter
|
||||
{
|
||||
static std::uint8_t call(double val)
|
||||
{
|
||||
return safe_cast<std::uint8_t>(std::lround((255.0 * val)/100.0));
|
||||
}
|
||||
static std::uint8_t call(double val) { return safe_cast<std::uint8_t>(std::lround((255.0 * val) / 100.0)); }
|
||||
};
|
||||
|
||||
auto dec_red = [](auto& ctx)
|
||||
{
|
||||
auto dec_red = [](auto& ctx) {
|
||||
_val(ctx).red_ = _attr(ctx);
|
||||
};
|
||||
|
||||
auto dec_green = [](auto& ctx)
|
||||
{
|
||||
auto dec_green = [](auto& ctx) {
|
||||
_val(ctx).green_ = _attr(ctx);
|
||||
};
|
||||
|
||||
auto dec_blue = [](auto& ctx)
|
||||
{
|
||||
auto dec_blue = [](auto& ctx) {
|
||||
_val(ctx).blue_ = _attr(ctx);
|
||||
};
|
||||
|
||||
auto opacity = [](auto& ctx)
|
||||
{
|
||||
auto opacity = [](auto& ctx) {
|
||||
_val(ctx).alpha_ = uint8_t((255.0 * clip_opacity::call(_attr(ctx))) + 0.5);
|
||||
};
|
||||
|
||||
auto percent_red = [] (auto & ctx)
|
||||
{
|
||||
auto percent_red = [](auto& ctx) {
|
||||
_val(ctx).red_ = percent_converter::call(_attr(ctx));
|
||||
};
|
||||
|
||||
auto percent_green = [] (auto & ctx)
|
||||
{
|
||||
auto percent_green = [](auto& ctx) {
|
||||
_val(ctx).green_ = percent_converter::call(_attr(ctx));
|
||||
};
|
||||
|
||||
auto percent_blue = [] (auto & ctx)
|
||||
{
|
||||
auto percent_blue = [](auto& ctx) {
|
||||
_val(ctx).blue_ = percent_converter::call(_attr(ctx));
|
||||
};
|
||||
|
||||
auto hex1_red = [](auto& ctx)
|
||||
{
|
||||
auto hex1_red = [](auto& ctx) {
|
||||
_val(ctx).red_ = _attr(ctx) | _attr(ctx) << 4;
|
||||
};
|
||||
|
||||
auto hex1_green = [](auto& ctx)
|
||||
{
|
||||
auto hex1_green = [](auto& ctx) {
|
||||
_val(ctx).green_ = _attr(ctx) | _attr(ctx) << 4;
|
||||
};
|
||||
|
||||
auto hex1_blue = [](auto& ctx)
|
||||
{
|
||||
auto hex1_blue = [](auto& ctx) {
|
||||
_val(ctx).blue_ = _attr(ctx) | _attr(ctx) << 4;
|
||||
};
|
||||
|
||||
auto hex1_opacity = [](auto& ctx)
|
||||
{
|
||||
auto hex1_opacity = [](auto& ctx) {
|
||||
_val(ctx).alpha_ = _attr(ctx) | _attr(ctx) << 4;
|
||||
};
|
||||
|
||||
auto hex2_red = [](auto& ctx)
|
||||
{
|
||||
auto hex2_red = [](auto& ctx) {
|
||||
_val(ctx).red_ = _attr(ctx);
|
||||
};
|
||||
|
||||
auto hex2_green = [](auto& ctx)
|
||||
{
|
||||
auto hex2_green = [](auto& ctx) {
|
||||
_val(ctx).green_ = _attr(ctx);
|
||||
};
|
||||
|
||||
auto hex2_blue = [](auto& ctx)
|
||||
{
|
||||
auto hex2_blue = [](auto& ctx) {
|
||||
_val(ctx).blue_ = _attr(ctx);
|
||||
};
|
||||
|
||||
auto hex2_opacity = [](auto& ctx)
|
||||
{
|
||||
auto hex2_opacity = [](auto& ctx) {
|
||||
_val(ctx).alpha_ = _attr(ctx);
|
||||
};
|
||||
|
||||
auto hsl_to_rgba = [] (auto& ctx)
|
||||
{
|
||||
auto hsl_to_rgba = [](auto& ctx) {
|
||||
double h = std::get<0>(_attr(ctx));
|
||||
double s = std::get<1>(_attr(ctx));
|
||||
double l = std::get<2>(_attr(ctx));
|
||||
|
@ -341,20 +321,20 @@ auto hsl_to_rgba = [] (auto& ctx)
|
|||
}
|
||||
else
|
||||
{
|
||||
m2 = l + s - l*s;
|
||||
m2 = l + s - l * s;
|
||||
}
|
||||
m1 = l * 2 - m2;
|
||||
|
||||
double r = hue_to_rgb(m1, m2, h + 1.0/3.0);
|
||||
double r = hue_to_rgb(m1, m2, h + 1.0 / 3.0);
|
||||
double g = hue_to_rgb(m1, m2, h);
|
||||
double b = hue_to_rgb(m1, m2, h - 1.0/3.0);
|
||||
double b = hue_to_rgb(m1, m2, h - 1.0 / 3.0);
|
||||
uint8_t alpha = uint8_t((255.0 * clip_opacity::call(std::get<3>(_attr(ctx)))) + 0.5);
|
||||
_val(ctx) = color(safe_cast<uint8_t>(std::lround(255.0 * r)),
|
||||
safe_cast<uint8_t>(std::lround(255.0 * g)),
|
||||
safe_cast<uint8_t>(std::lround(255.0 * b)),
|
||||
alpha);
|
||||
};
|
||||
|
||||
// clang-format off
|
||||
auto const hex2_color_def = no_skip[lit('#')
|
||||
>> hex2[hex2_red]
|
||||
>> hex2[hex2_green]
|
||||
|
@ -429,21 +409,13 @@ auto const css_color_def =
|
|||
|
|
||||
hsla_color
|
||||
;
|
||||
|
||||
// clang-format on
|
||||
MAPNIK_DISABLE_WARNING_PUSH
|
||||
#include <mapnik/warning_ignore.hpp>
|
||||
BOOST_SPIRIT_DEFINE(
|
||||
css_color,
|
||||
hex2_color,
|
||||
hex1_color,
|
||||
rgb_color,
|
||||
rgba_color,
|
||||
rgb_color_percent,
|
||||
rgba_color_percent
|
||||
);
|
||||
BOOST_SPIRIT_DEFINE(css_color, hex2_color, hex1_color, rgb_color, rgba_color, rgb_color_percent, rgba_color_percent);
|
||||
MAPNIK_DISABLE_WARNING_POP
|
||||
|
||||
} // ns
|
||||
} //ns mapnik
|
||||
} // namespace css_color_grammar
|
||||
} // namespace mapnik
|
||||
|
||||
#endif //MAPNIK_CSS_COLOR_GRAMMAR_X3_DEF_HPP
|
||||
#endif // MAPNIK_CSS_COLOR_GRAMMAR_X3_DEF_HPP
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*****************************************************************************
|
||||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
|
@ -31,8 +31,7 @@ MAPNIK_DISABLE_WARNING_PUSH
|
|||
#include <boost/spirit/home/x3.hpp>
|
||||
MAPNIK_DISABLE_WARNING_POP
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
namespace mapnik {
|
||||
using property_value_type = boost::iterator_range<char const*>;
|
||||
using css_key_value = std::pair<std::string, property_value_type>;
|
||||
using definition_type = std::vector<css_key_value>;
|
||||
|
@ -40,8 +39,7 @@ using css_data = std::unordered_multimap<std::string, definition_type>;
|
|||
|
||||
namespace x3 = boost::spirit::x3;
|
||||
|
||||
namespace css_grammar
|
||||
{
|
||||
namespace css_grammar {
|
||||
|
||||
class css_tag;
|
||||
class ident_tag;
|
||||
|
@ -58,17 +56,14 @@ css_grammar_type const css_grammar{"css"};
|
|||
css_skipper_type const css_skipper{"css skipper"};
|
||||
css_classes_type const css_classes{"css classes"};
|
||||
|
||||
BOOST_SPIRIT_DECLARE(ident_grammar_type,
|
||||
css_classes_type,
|
||||
css_grammar_type,
|
||||
css_skipper_type);
|
||||
BOOST_SPIRIT_DECLARE(ident_grammar_type, css_classes_type, css_grammar_type, css_skipper_type);
|
||||
|
||||
}
|
||||
} // namespace css_grammar
|
||||
|
||||
css_grammar::ident_grammar_type const ident_grammar();
|
||||
css_grammar::css_classes_type const classes();
|
||||
css_grammar::css_grammar_type const grammar();
|
||||
css_grammar::css_skipper_type const skipper();
|
||||
}
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_CSS_GRAMMAR_X3_HPP
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
#ifndef MAPNIK_CSS_GRAMMAR_X3_DEF_HPP
|
||||
#define MAPNIK_CSS_GRAMMAR_X3_DEF_HPP
|
||||
|
||||
|
@ -33,9 +32,10 @@ MAPNIK_DISABLE_WARNING_PUSH
|
|||
#include <boost/fusion/adapted/std_pair.hpp>
|
||||
MAPNIK_DISABLE_WARNING_POP
|
||||
|
||||
|
||||
/*
|
||||
The grammar below is LL(1) (but note that most UA's should not use it directly, since it doesn't express the parsing conventions, only the CSS1 syntax). The format of the productions is optimized for human consumption and some shorthand notation beyond yacc [15] is used:
|
||||
The grammar below is LL(1) (but note that most UA's should not use it directly, since it doesn't express the parsing
|
||||
conventions, only the CSS1 syntax). The format of the productions is optimized for human consumption and some shorthand
|
||||
notation beyond yacc [15] is used:
|
||||
|
||||
* : 0 or more
|
||||
+ : 1 or more
|
||||
|
@ -148,46 +148,48 @@ namespace x3 = boost::spirit::x3;
|
|||
|
||||
namespace css_grammar {
|
||||
|
||||
using x3::lit;
|
||||
using x3::alnum;
|
||||
using x3::alpha;
|
||||
using x3::attr;
|
||||
using x3::char_;
|
||||
using x3::lexeme;
|
||||
using x3::lit;
|
||||
using x3::no_case;
|
||||
using x3::no_skip;
|
||||
using x3::lexeme;
|
||||
using x3::alpha;
|
||||
using x3::alnum;
|
||||
using x3::char_;
|
||||
using x3::raw;
|
||||
using x3::standard::space;
|
||||
|
||||
// import unicode string rule
|
||||
namespace { auto const& css_string = mapnik::json::grammar::unicode_string; }
|
||||
namespace {
|
||||
auto const& css_string = mapnik::json::grammar::unicode_string;
|
||||
}
|
||||
|
||||
auto assign_def = [] (auto const& ctx)
|
||||
{
|
||||
auto assign_def = [](auto const& ctx) {
|
||||
for (auto const& k : std::get<0>(_attr(ctx)))
|
||||
{
|
||||
_val(ctx).emplace(k, std::get<1>(_attr(ctx)));
|
||||
}
|
||||
};
|
||||
|
||||
auto assign_key = [] (auto const& ctx)
|
||||
{
|
||||
auto assign_key = [](auto const& ctx) {
|
||||
_val(ctx).first = std::move(_attr(ctx));
|
||||
};
|
||||
|
||||
auto assign_value = [] (auto const& ctx) {_val(ctx).second = std::move(_attr(ctx));};
|
||||
auto assign_value = [](auto const& ctx) {
|
||||
_val(ctx).second = std::move(_attr(ctx));
|
||||
};
|
||||
|
||||
// rules
|
||||
x3::rule<class simple_selector_tag, std::string> const simple_selector {"Simple selector"};
|
||||
x3::rule<class selector_tag, std::vector<std::string>> const selector {"Selector"};
|
||||
x3::rule<class value_tag, property_value_type> const value {"Value"};
|
||||
x3::rule<class key_value_tag, css_key_value> const key_value {"CSS Key/Value"};
|
||||
x3::rule<class definition_tag, std::pair<std::vector<std::string>, definition_type>> const definition {"CSS Definition"};
|
||||
x3::rule<class simple_selector_tag, std::string> const simple_selector{"Simple selector"};
|
||||
x3::rule<class selector_tag, std::vector<std::string>> const selector{"Selector"};
|
||||
x3::rule<class value_tag, property_value_type> const value{"Value"};
|
||||
x3::rule<class key_value_tag, css_key_value> const key_value{"CSS Key/Value"};
|
||||
x3::rule<class definition_tag, std::pair<std::vector<std::string>, definition_type>> const definition{"CSS Definition"};
|
||||
|
||||
auto const ident_def = alpha >> *(alnum | char_('-'));
|
||||
auto const simple_selector_def = lexeme[ident >> -((char_('.') | char_('#') | char_(':')) >> ident)]
|
||||
| lexeme[char_('#') >> ident >> -((char_('.') | char_(':')) >> ident)]
|
||||
| lexeme[char_('.') >> ident >> -(char_(':') >> ident)];
|
||||
auto const simple_selector_def = lexeme[ident >> -((char_('.') | char_('#') | char_(':')) >> ident)] |
|
||||
lexeme[char_('#') >> ident >> -((char_('.') | char_(':')) >> ident)] |
|
||||
lexeme[char_('.') >> ident >> -(char_(':') >> ident)];
|
||||
|
||||
auto const selector_def = simple_selector % lit(',');
|
||||
auto const value_def = raw[lexeme[+~char_(";}")]];
|
||||
|
@ -202,21 +204,19 @@ auto const css_classes_def = +lexeme[ident];
|
|||
#include <mapnik/warning.hpp>
|
||||
MAPNIK_DISABLE_WARNING_PUSH
|
||||
#include <mapnik/warning_ignore.hpp>
|
||||
BOOST_SPIRIT_DEFINE(
|
||||
ident,
|
||||
css_classes,
|
||||
simple_selector,
|
||||
selector,
|
||||
value,
|
||||
key_value,
|
||||
definition,
|
||||
css_grammar,
|
||||
css_skipper
|
||||
);
|
||||
BOOST_SPIRIT_DEFINE(ident,
|
||||
css_classes,
|
||||
simple_selector,
|
||||
selector,
|
||||
value,
|
||||
key_value,
|
||||
definition,
|
||||
css_grammar,
|
||||
css_skipper);
|
||||
|
||||
MAPNIK_DISABLE_WARNING_POP
|
||||
|
||||
} //css_grammar
|
||||
} //mapnik
|
||||
} // namespace css_grammar
|
||||
} // namespace mapnik
|
||||
|
||||
#endif //MAPNIK_CSS_GRAMMAR_X3_DEF_HPP
|
||||
#endif // MAPNIK_CSS_GRAMMAR_X3_DEF_HPP
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
#ifndef MAPNIK_CSS_UNIT_VALUE_HPP
|
||||
#define MAPNIK_CSS_UNIT_VALUE_HPP
|
||||
|
||||
|
@ -36,15 +35,15 @@ struct css_unit_value : x3::symbols<double>
|
|||
constexpr static double DPI = 96;
|
||||
css_unit_value()
|
||||
{
|
||||
add
|
||||
("px", 1.0) // pixels
|
||||
("pt", DPI/72.0) // points
|
||||
("pc", DPI/6.0) // picas
|
||||
("mm", DPI/25.4) // milimeters
|
||||
("Q" , DPI/101.6)// quarter-milimeters
|
||||
("cm", DPI/2.54) // centimeters
|
||||
("in", static_cast<double>(DPI)) // inches
|
||||
;
|
||||
add //
|
||||
("px", 1.0) // pixels
|
||||
("pt", DPI / 72.0) // points
|
||||
("pc", DPI / 6.0) // picas
|
||||
("mm", DPI / 25.4) // milimeters
|
||||
("Q", DPI / 101.6) // quarter-milimeters
|
||||
("cm", DPI / 2.54) // centimeters
|
||||
("in", static_cast<double>(DPI)) // inches
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -53,15 +52,15 @@ struct css_absolute_size : x3::symbols<double>
|
|||
constexpr static double EM = 10.0; // 1em == 10px
|
||||
css_absolute_size()
|
||||
{
|
||||
add
|
||||
("xx-small", 0.6 * EM)
|
||||
("x-small", 0.75 * EM)
|
||||
("small", 0.88 * EM)
|
||||
("medium", 1.0 * EM)
|
||||
("large", 1.2 * EM)
|
||||
("x-large", 1.5 * EM)
|
||||
("xx-large", 2.0 * EM)
|
||||
;
|
||||
add //
|
||||
("xx-small", 0.6 * EM) //
|
||||
("x-small", 0.75 * EM) //
|
||||
("small", 0.88 * EM) //
|
||||
("medium", 1.0 * EM) //
|
||||
("large", 1.2 * EM) //
|
||||
("x-large", 1.5 * EM) //
|
||||
("xx-large", 2.0 * EM) //
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -69,13 +68,12 @@ struct css_relative_size : x3::symbols<double>
|
|||
{
|
||||
css_relative_size()
|
||||
{
|
||||
add
|
||||
("larger", 1.2)
|
||||
("smaller", 0.8)
|
||||
;
|
||||
add //
|
||||
("larger", 1.2) //
|
||||
("smaller", 0.8);
|
||||
}
|
||||
};
|
||||
|
||||
} //mapnik
|
||||
} // namespace mapnik
|
||||
|
||||
#endif //MAPNIK_CSS_GRAMMAR_X3_DEF_HPP
|
||||
#endif // MAPNIK_CSS_GRAMMAR_X3_DEF_HPP
|
||||
|
|
|
@ -35,9 +35,8 @@ struct csv_white_space_skipper : x3::parser<csv_white_space_skipper>
|
|||
using attribute_type = x3::unused_type;
|
||||
static bool const has_attribute = false;
|
||||
|
||||
template <typename Iterator, typename Context, typename Attribute>
|
||||
bool parse(Iterator& first, Iterator const& last,
|
||||
Context const& context, x3::unused_type, Attribute& ) const
|
||||
template<typename Iterator, typename Context, typename Attribute>
|
||||
bool parse(Iterator& first, Iterator const& last, Context const& context, x3::unused_type, Attribute&) const
|
||||
{
|
||||
x3::skip_over(first, last, context);
|
||||
if (first != last && *first == ' ')
|
||||
|
@ -64,6 +63,7 @@ csv_line_grammar_type const line = "csv-line";
|
|||
|
||||
BOOST_SPIRIT_DECLARE(csv_line_grammar_type);
|
||||
|
||||
}}
|
||||
} // namespace grammar
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_CSV_GRAMMAR_X3_HPP
|
||||
|
|
|
@ -29,45 +29,44 @@ MAPNIK_DISABLE_WARNING_PUSH
|
|||
#include <mapnik/csv/csv_grammar_x3.hpp>
|
||||
MAPNIK_DISABLE_WARNING_POP
|
||||
|
||||
|
||||
namespace mapnik { namespace grammar {
|
||||
namespace mapnik {
|
||||
namespace grammar {
|
||||
|
||||
namespace x3 = boost::spirit::x3;
|
||||
namespace standard = boost::spirit::x3::standard;
|
||||
|
||||
using x3::lit;
|
||||
using x3::lexeme;
|
||||
using standard::char_;
|
||||
using x3::lexeme;
|
||||
using x3::lit;
|
||||
|
||||
struct unesc_char_ : x3::symbols<char>
|
||||
{
|
||||
unesc_char_()
|
||||
{
|
||||
add("\\a", '\a')
|
||||
("\\b", '\b')
|
||||
("\\f", '\f')
|
||||
("\\n", '\n')
|
||||
("\\r", '\r')
|
||||
("\\t", '\t')
|
||||
("\\v", '\v')
|
||||
("\\\\",'\\')
|
||||
("\\\'", '\'')
|
||||
("\\\"", '\"')
|
||||
("\"\"", '\"') // double quote
|
||||
;
|
||||
add("\\a", '\a') //
|
||||
("\\b", '\b') //
|
||||
("\\f", '\f') //
|
||||
("\\n", '\n') //
|
||||
("\\r", '\r') //
|
||||
("\\t", '\t') //
|
||||
("\\v", '\v') //
|
||||
("\\\\", '\\') //
|
||||
("\\\'", '\'') //
|
||||
("\\\"", '\"') //
|
||||
("\"\"", '\"') // double quote
|
||||
;
|
||||
}
|
||||
} unesc_char;
|
||||
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
struct literal : x3::parser<literal<T>>
|
||||
{
|
||||
using attribute_type = x3::unused_type;
|
||||
using context_tag = T;
|
||||
static bool const has_attribute = false;
|
||||
|
||||
template <typename Iterator, typename Context, typename Attribute>
|
||||
bool parse(Iterator& first, Iterator const& last,
|
||||
Context const& context, x3::unused_type, Attribute& ) const
|
||||
template<typename Iterator, typename Context, typename Attribute>
|
||||
bool parse(Iterator& first, Iterator const& last, Context const& context, x3::unused_type, Attribute&) const
|
||||
{
|
||||
x3::skip_over(first, last, context);
|
||||
if (first != last && *first == x3::get<context_tag>(context))
|
||||
|
@ -87,27 +86,18 @@ x3::rule<class csv_column, csv_value> const column("csv-column");
|
|||
x3::rule<class csv_text, csv_value> const text("csv-text");
|
||||
x3::rule<class csc_quoted_text, csv_value> const quoted_text("csv-quoted-text");
|
||||
|
||||
auto const line_def = -lit('\r') > -lit('\n') > lexeme[column] % separator
|
||||
;
|
||||
auto const line_def = -lit('\r') > -lit('\n') > lexeme[column] % separator;
|
||||
|
||||
auto const column_def = quoted_text | *(char_ - separator)
|
||||
;
|
||||
auto const column_def = quoted_text | *(char_ - separator);
|
||||
|
||||
auto const quoted_text_def = quote > text > quote // support unmatched quotes or not (??)
|
||||
;
|
||||
;
|
||||
|
||||
auto const text_def = *(unesc_char | (char_ - quote))
|
||||
;
|
||||
auto const text_def = *(unesc_char | (char_ - quote));
|
||||
|
||||
BOOST_SPIRIT_DEFINE (
|
||||
line,
|
||||
column,
|
||||
quoted_text,
|
||||
text
|
||||
);
|
||||
BOOST_SPIRIT_DEFINE(line, column, quoted_text, text);
|
||||
|
||||
} // grammar
|
||||
} // namespace grammar
|
||||
} // namespace mapnik
|
||||
|
||||
|
||||
#endif // MAPNIK_CSV_GRAMMAR_X3_DEF_HPP
|
||||
|
|
|
@ -32,6 +32,6 @@ using csv_value = std::string;
|
|||
using csv_line = std::vector<csv_value>;
|
||||
using csv_data = std::vector<csv_line>;
|
||||
|
||||
}
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_CSV_TYPES_HPP
|
||||
|
|
|
@ -43,31 +43,27 @@ namespace mapnik {
|
|||
|
||||
class MAPNIK_DECL datasource_exception : public std::exception
|
||||
{
|
||||
public:
|
||||
public:
|
||||
datasource_exception(std::string const& message)
|
||||
: message_(message)
|
||||
: message_(message)
|
||||
{}
|
||||
|
||||
~datasource_exception() {}
|
||||
|
||||
virtual const char* what() const noexcept
|
||||
{
|
||||
return message_.c_str();
|
||||
}
|
||||
private:
|
||||
virtual const char* what() const noexcept { return message_.c_str(); }
|
||||
|
||||
private:
|
||||
std::string message_;
|
||||
};
|
||||
|
||||
class MAPNIK_DECL datasource : private util::noncopyable
|
||||
{
|
||||
public:
|
||||
enum datasource_t : std::uint8_t {
|
||||
Vector,
|
||||
Raster
|
||||
};
|
||||
public:
|
||||
enum datasource_t : std::uint8_t { Vector, Raster };
|
||||
|
||||
datasource (parameters const& _params)
|
||||
: params_(_params) {}
|
||||
datasource(parameters const& _params)
|
||||
: params_(_params)
|
||||
{}
|
||||
|
||||
/*!
|
||||
* @brief Get the configuration parameters of the data source.
|
||||
|
@ -76,25 +72,13 @@ public:
|
|||
*
|
||||
* @return The configuration parameters of the data source.
|
||||
*/
|
||||
parameters const& params() const
|
||||
{
|
||||
return params_;
|
||||
}
|
||||
parameters const& params() const { return params_; }
|
||||
|
||||
parameters & params()
|
||||
{
|
||||
return params_;
|
||||
}
|
||||
parameters& params() { return params_; }
|
||||
|
||||
bool operator==(datasource const& rhs) const
|
||||
{
|
||||
return params_ == rhs.params();
|
||||
}
|
||||
bool operator==(datasource const& rhs) const { return params_ == rhs.params(); }
|
||||
|
||||
bool operator!=(datasource const& rhs) const
|
||||
{
|
||||
return !(*this == rhs);
|
||||
}
|
||||
bool operator!=(datasource const& rhs) const { return !(*this == rhs); }
|
||||
|
||||
/*!
|
||||
* @brief Get the type of the datasource
|
||||
|
@ -113,43 +97,32 @@ public:
|
|||
virtual box2d<double> envelope() const = 0;
|
||||
virtual layer_descriptor get_descriptor() const = 0;
|
||||
virtual ~datasource() {}
|
||||
protected:
|
||||
|
||||
protected:
|
||||
parameters params_;
|
||||
};
|
||||
|
||||
using datasource_name = const char* (*)();
|
||||
using create_ds = datasource* (*) (parameters const&);
|
||||
using destroy_ds = void (*) (datasource *);
|
||||
using create_ds = datasource* (*)(parameters const&);
|
||||
using destroy_ds = void (*)(datasource*);
|
||||
|
||||
class datasource_deleter
|
||||
{
|
||||
public:
|
||||
void operator() (datasource* ds)
|
||||
{
|
||||
delete ds;
|
||||
}
|
||||
public:
|
||||
void operator()(datasource* ds) { delete ds; }
|
||||
};
|
||||
|
||||
using datasource_ptr = std::shared_ptr<datasource>;
|
||||
|
||||
#ifdef MAPNIK_STATIC_PLUGINS
|
||||
#define DATASOURCE_PLUGIN(classname)
|
||||
#define DATASOURCE_PLUGIN(classname)
|
||||
#else
|
||||
#define DATASOURCE_PLUGIN(classname) \
|
||||
extern "C" MAPNIK_EXP const char * datasource_name() \
|
||||
{ \
|
||||
return classname::name(); \
|
||||
} \
|
||||
extern "C" MAPNIK_EXP datasource* create(parameters const& params) \
|
||||
{ \
|
||||
return new classname(params); \
|
||||
} \
|
||||
extern "C" MAPNIK_EXP void destroy(datasource *ds) \
|
||||
{ \
|
||||
delete ds; \
|
||||
}
|
||||
#define DATASOURCE_PLUGIN(classname) \
|
||||
extern "C" MAPNIK_EXP const char* datasource_name() { return classname::name(); } \
|
||||
extern "C" MAPNIK_EXP datasource* create(parameters const& params) { return new classname(params); } \
|
||||
extern "C" MAPNIK_EXP void destroy(datasource* ds) { delete ds; }
|
||||
#endif
|
||||
|
||||
}
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_DATASOURCE_HPP
|
||||
|
|
|
@ -41,21 +41,22 @@ class datasource;
|
|||
class parameters;
|
||||
class PluginInfo;
|
||||
|
||||
class MAPNIK_DECL datasource_cache
|
||||
: public singleton<datasource_cache, CreateStatic>,
|
||||
private util::noncopyable
|
||||
class MAPNIK_DECL datasource_cache : public singleton<datasource_cache, CreateStatic>,
|
||||
private util::noncopyable
|
||||
{
|
||||
friend class CreateStatic<datasource_cache>;
|
||||
public:
|
||||
|
||||
public:
|
||||
std::vector<std::string> plugin_names();
|
||||
std::string plugin_directories();
|
||||
bool register_datasources(std::string const& path, bool recurse = false);
|
||||
bool register_datasource(std::string const& path);
|
||||
std::shared_ptr<datasource> create(parameters const& params);
|
||||
private:
|
||||
|
||||
private:
|
||||
datasource_cache();
|
||||
~datasource_cache();
|
||||
std::map<std::string,std::shared_ptr<PluginInfo> > plugins_;
|
||||
std::map<std::string, std::shared_ptr<PluginInfo>> plugins_;
|
||||
std::set<std::string> plugin_directories_;
|
||||
// the singleton has a mutex protecting the instance pointer,
|
||||
// but the instance also needs its own mutex to protect the
|
||||
|
@ -66,6 +67,6 @@ private:
|
|||
|
||||
extern template class MAPNIK_DECL singleton<datasource_cache, CreateStatic>;
|
||||
|
||||
}
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_DATASOURCE_CACHE_HPP
|
||||
|
|
|
@ -27,15 +27,8 @@
|
|||
|
||||
namespace mapnik {
|
||||
|
||||
enum datasource_geometry_t : std::uint8_t {
|
||||
Unknown = 0,
|
||||
Point = 1,
|
||||
LineString = 2,
|
||||
Polygon = 3,
|
||||
Collection = 4
|
||||
};
|
||||
enum datasource_geometry_t : std::uint8_t { Unknown = 0, Point = 1, LineString = 2, Polygon = 3, Collection = 4 };
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // MAPNIK_DATASOURCE_GEOMETRY_TYPE_HPP
|
||||
|
|
|
@ -42,35 +42,21 @@
|
|||
|
||||
namespace mapnik {
|
||||
|
||||
|
||||
// Global logger class that holds the configuration of severity, format
|
||||
// and file/console redirection.
|
||||
|
||||
class MAPNIK_DECL logger :
|
||||
public singleton<logger,CreateStatic>,
|
||||
private util::noncopyable
|
||||
class MAPNIK_DECL logger : public singleton<logger, CreateStatic>,
|
||||
private util::noncopyable
|
||||
{
|
||||
public:
|
||||
enum severity_type
|
||||
{
|
||||
debug = 0,
|
||||
warn = 1,
|
||||
error = 2,
|
||||
none = 3
|
||||
};
|
||||
public:
|
||||
enum severity_type { debug = 0, warn = 1, error = 2, none = 3 };
|
||||
|
||||
using severity_map = std::unordered_map<std::string, severity_type>;
|
||||
|
||||
// global security level
|
||||
static severity_type get_severity()
|
||||
{
|
||||
return severity_level_;
|
||||
}
|
||||
static severity_type get_severity() { return severity_level_; }
|
||||
|
||||
static void set_severity(severity_type severity_level)
|
||||
{
|
||||
severity_level_ = severity_level;
|
||||
}
|
||||
static void set_severity(severity_type severity_level) { severity_level_ = severity_level; }
|
||||
|
||||
// per object security levels
|
||||
static severity_type get_object_severity(std::string const& object_name)
|
||||
|
@ -89,8 +75,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
static void set_object_severity(std::string const& object_name,
|
||||
severity_type const& security_level)
|
||||
static void set_object_severity(std::string const& object_name, severity_type const& security_level)
|
||||
{
|
||||
if (!object_name.empty())
|
||||
{
|
||||
|
@ -111,10 +96,7 @@ public:
|
|||
}
|
||||
|
||||
// format
|
||||
static std::string const& get_format()
|
||||
{
|
||||
return format_;
|
||||
}
|
||||
static std::string const& get_format() { return format_; }
|
||||
|
||||
static void set_format(std::string const& format)
|
||||
{
|
||||
|
@ -131,7 +113,7 @@ public:
|
|||
static void use_file(std::string const& filepath);
|
||||
static void use_console();
|
||||
|
||||
private:
|
||||
private:
|
||||
static severity_map object_severity_level_;
|
||||
static std::string format_;
|
||||
static std::ofstream file_output_;
|
||||
|
@ -151,7 +133,6 @@ private:
|
|||
#endif
|
||||
};
|
||||
|
||||
|
||||
namespace detail {
|
||||
|
||||
// Default sink, it regulates access to clog
|
||||
|
@ -159,7 +140,7 @@ namespace detail {
|
|||
template<class Ch, class Tr, class A>
|
||||
class clog_sink
|
||||
{
|
||||
public:
|
||||
public:
|
||||
using stream_buffer = std::basic_ostringstream<Ch, Tr, A>;
|
||||
|
||||
void operator()(logger::severity_type const& /*severity*/, stream_buffer const& s)
|
||||
|
@ -177,14 +158,14 @@ public:
|
|||
// This is used for debug/warn reporting that should not output
|
||||
// anything when not compiling for speed.
|
||||
|
||||
template<template <class Ch, class Tr, class A> class OutputPolicy,
|
||||
template<template<class Ch, class Tr, class A> class OutputPolicy,
|
||||
logger::severity_type Severity,
|
||||
class Ch = char,
|
||||
class Tr = std::char_traits<Ch>,
|
||||
class A = std::allocator<Ch> >
|
||||
class A = std::allocator<Ch>>
|
||||
class base_log : public util::noncopyable
|
||||
{
|
||||
public:
|
||||
public:
|
||||
using output_policy = OutputPolicy<Ch, Tr, A>;
|
||||
|
||||
base_log() {}
|
||||
|
@ -198,9 +179,7 @@ public:
|
|||
}
|
||||
}
|
||||
#else
|
||||
base_log(const char* /*object_name*/)
|
||||
{
|
||||
}
|
||||
base_log(const char* /*object_name*/) {}
|
||||
#endif
|
||||
|
||||
~base_log()
|
||||
|
@ -215,45 +194,38 @@ public:
|
|||
|
||||
template<class T>
|
||||
#ifdef MAPNIK_LOG
|
||||
base_log &operator<<(T const& x)
|
||||
base_log& operator<<(T const& x)
|
||||
{
|
||||
|
||||
streambuf_ << x;
|
||||
return *this;
|
||||
}
|
||||
#else
|
||||
base_log &operator<<(T const& /*x*/)
|
||||
base_log& operator<<(T const& /*x*/)
|
||||
{
|
||||
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
private:
|
||||
#ifdef MAPNIK_LOG
|
||||
inline bool check_severity()
|
||||
{
|
||||
return Severity >= logger::get_object_severity(object_name_);
|
||||
}
|
||||
inline bool check_severity() { return Severity >= logger::get_object_severity(object_name_); }
|
||||
|
||||
typename output_policy::stream_buffer streambuf_;
|
||||
std::string object_name_;
|
||||
#endif
|
||||
};
|
||||
|
||||
// Base log class that always log, regardless of MAPNIK_LOG.
|
||||
// This is used for error reporting that should always log something
|
||||
|
||||
|
||||
//Base log class that always log, regardless of MAPNIK_LOG.
|
||||
//This is used for error reporting that should always log something
|
||||
|
||||
template<template <class Ch, class Tr, class A> class OutputPolicy,
|
||||
template<template<class Ch, class Tr, class A> class OutputPolicy,
|
||||
logger::severity_type Severity,
|
||||
class Ch = char,
|
||||
class Tr = std::char_traits<Ch>,
|
||||
class A = std::allocator<Ch> >
|
||||
class A = std::allocator<Ch>>
|
||||
class base_log_always : public util::noncopyable
|
||||
{
|
||||
public:
|
||||
public:
|
||||
using output_policy = OutputPolicy<Ch, Tr, A>;
|
||||
|
||||
base_log_always() {}
|
||||
|
@ -275,56 +247,63 @@ public:
|
|||
}
|
||||
|
||||
template<class T>
|
||||
base_log_always &operator<<(T const& x)
|
||||
base_log_always& operator<<(T const& x)
|
||||
{
|
||||
streambuf_ << x;
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
inline bool check_severity()
|
||||
{
|
||||
return Severity >= logger::get_object_severity(object_name_);
|
||||
}
|
||||
private:
|
||||
inline bool check_severity() { return Severity >= logger::get_object_severity(object_name_); }
|
||||
|
||||
typename output_policy::stream_buffer streambuf_;
|
||||
std::string object_name_;
|
||||
};
|
||||
|
||||
|
||||
using base_log_debug = base_log<clog_sink, logger::debug>;
|
||||
using base_log_warn = base_log<clog_sink, logger::warn>;
|
||||
using base_log_error = base_log_always<clog_sink, logger::error>;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
|
||||
// real interfaces
|
||||
class MAPNIK_DECL warn : public detail::base_log_warn
|
||||
{
|
||||
public:
|
||||
warn() : detail::base_log_warn() {}
|
||||
warn(const char* object_name) : detail::base_log_warn(object_name) {}
|
||||
public:
|
||||
warn()
|
||||
: detail::base_log_warn()
|
||||
{}
|
||||
warn(const char* object_name)
|
||||
: detail::base_log_warn(object_name)
|
||||
{}
|
||||
};
|
||||
|
||||
class MAPNIK_DECL debug : public detail::base_log_debug
|
||||
{
|
||||
public:
|
||||
debug() : detail::base_log_debug() {}
|
||||
debug(const char* object_name) : detail::base_log_debug(object_name) {}
|
||||
public:
|
||||
debug()
|
||||
: detail::base_log_debug()
|
||||
{}
|
||||
debug(const char* object_name)
|
||||
: detail::base_log_debug(object_name)
|
||||
{}
|
||||
};
|
||||
|
||||
class MAPNIK_DECL error : public detail::base_log_error
|
||||
{
|
||||
public:
|
||||
error() : detail::base_log_error() {}
|
||||
error(const char* object_name) : detail::base_log_error(object_name) {}
|
||||
public:
|
||||
error()
|
||||
: detail::base_log_error()
|
||||
{}
|
||||
error(const char* object_name)
|
||||
: detail::base_log_error(object_name)
|
||||
{}
|
||||
};
|
||||
|
||||
// logging helpers
|
||||
#define MAPNIK_LOG_DEBUG(s) mapnik::debug(#s)
|
||||
#define MAPNIK_LOG_WARN(s) mapnik::warn(#s)
|
||||
#define MAPNIK_LOG_WARN(s) mapnik::warn(#s)
|
||||
#define MAPNIK_LOG_ERROR(s) mapnik::error(#s)
|
||||
}
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_DEBUG_HPP
|
||||
|
|
|
@ -38,26 +38,22 @@ namespace mapnik {
|
|||
|
||||
class illegal_enum_value : public std::exception
|
||||
{
|
||||
public:
|
||||
illegal_enum_value():
|
||||
what_() {}
|
||||
public:
|
||||
illegal_enum_value()
|
||||
: what_()
|
||||
{}
|
||||
|
||||
illegal_enum_value( std::string const& _what ) :
|
||||
what_( _what )
|
||||
{
|
||||
}
|
||||
illegal_enum_value(std::string const& _what)
|
||||
: what_(_what)
|
||||
{}
|
||||
virtual ~illegal_enum_value() {}
|
||||
|
||||
virtual const char * what() const noexcept
|
||||
{
|
||||
return what_.c_str();
|
||||
}
|
||||
virtual const char* what() const noexcept { return what_.c_str(); }
|
||||
|
||||
protected:
|
||||
protected:
|
||||
std::string what_;
|
||||
};
|
||||
|
||||
|
||||
/** Slim wrapper for enumerations. It creates a new type from a native enum and
|
||||
* a char pointer array. It almost exactly behaves like a native enumeration
|
||||
* type. It supports string conversion through stream operators. This is useful
|
||||
|
@ -137,42 +133,34 @@ protected:
|
|||
* @endcode
|
||||
*/
|
||||
|
||||
template <typename ENUM, int THE_MAX>
|
||||
class MAPNIK_DECL enumeration {
|
||||
public:
|
||||
template<typename ENUM, int THE_MAX>
|
||||
class MAPNIK_DECL enumeration
|
||||
{
|
||||
public:
|
||||
using native_type = ENUM;
|
||||
|
||||
enumeration()
|
||||
: value_() {}
|
||||
: value_()
|
||||
{}
|
||||
|
||||
enumeration( ENUM v )
|
||||
: value_(v) {}
|
||||
enumeration(ENUM v)
|
||||
: value_(v)
|
||||
{}
|
||||
|
||||
enumeration( enumeration const& other )
|
||||
: value_(other.value_) {}
|
||||
enumeration(enumeration const& other)
|
||||
: value_(other.value_)
|
||||
{}
|
||||
|
||||
/** Assignment operator for native enum values. */
|
||||
void operator=(ENUM v)
|
||||
{
|
||||
value_ = v;
|
||||
}
|
||||
void operator=(ENUM v) { value_ = v; }
|
||||
|
||||
/** Assignment operator. */
|
||||
void operator=(enumeration const& other)
|
||||
{
|
||||
value_ = other.value_;
|
||||
}
|
||||
void operator=(enumeration const& other) { value_ = other.value_; }
|
||||
|
||||
/** Conversion operator for native enum values. */
|
||||
operator ENUM() const
|
||||
{
|
||||
return value_;
|
||||
}
|
||||
operator ENUM() const { return value_; }
|
||||
|
||||
enum Max
|
||||
{
|
||||
MAX = THE_MAX
|
||||
};
|
||||
enum Max { MAX = THE_MAX };
|
||||
|
||||
/** Converts @p str to an enum.
|
||||
* @throw illegal_enum_value @p str is not a legal identifier.
|
||||
|
@ -190,113 +178,114 @@ public:
|
|||
}
|
||||
for (unsigned i = 0; i < THE_MAX; ++i)
|
||||
{
|
||||
|
||||
MAPNIK_DISABLE_WARNING_PUSH
|
||||
MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS
|
||||
MAPNIK_DISABLE_WARNING_PRAGMAS
|
||||
MAPNIK_DISABLE_LONG_LONG
|
||||
MAPNIK_DISABLE_WARNING_PUSH
|
||||
MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS
|
||||
MAPNIK_DISABLE_WARNING_PRAGMAS
|
||||
MAPNIK_DISABLE_LONG_LONG
|
||||
if (str_copy == our_strings_[i])
|
||||
MAPNIK_DISABLE_WARNING_POP
|
||||
{
|
||||
value_ = static_cast<ENUM>(i);
|
||||
if (deprecated)
|
||||
MAPNIK_DISABLE_WARNING_POP
|
||||
{
|
||||
MAPNIK_LOG_ERROR(enumerations) << "enumeration value (" << str << ") using \"_\" is deprecated and will be removed in Mapnik 4.x, use '" << str_copy << "' instead";
|
||||
value_ = static_cast<ENUM>(i);
|
||||
if (deprecated)
|
||||
{
|
||||
MAPNIK_LOG_ERROR(enumerations)
|
||||
<< "enumeration value (" << str
|
||||
<< ") using \"_\" is deprecated and will be removed in Mapnik 4.x, use '" << str_copy
|
||||
<< "' instead";
|
||||
}
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
MAPNIK_DISABLE_WARNING_PUSH
|
||||
MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS
|
||||
MAPNIK_DISABLE_WARNING_PRAGMAS
|
||||
MAPNIK_DISABLE_LONG_LONG
|
||||
throw illegal_enum_value(std::string("Illegal enumeration value '") +
|
||||
str + "' for enum " + our_name_);
|
||||
MAPNIK_DISABLE_WARNING_POP
|
||||
MAPNIK_DISABLE_WARNING_PUSH
|
||||
MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS
|
||||
MAPNIK_DISABLE_WARNING_PRAGMAS
|
||||
MAPNIK_DISABLE_LONG_LONG
|
||||
throw illegal_enum_value(std::string("Illegal enumeration value '") + str + "' for enum " + our_name_);
|
||||
MAPNIK_DISABLE_WARNING_POP
|
||||
}
|
||||
|
||||
/** Returns the current value as a string identifier. */
|
||||
std::string as_string() const
|
||||
{
|
||||
MAPNIK_DISABLE_WARNING_PUSH
|
||||
MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS
|
||||
MAPNIK_DISABLE_WARNING_PRAGMAS
|
||||
MAPNIK_DISABLE_LONG_LONG
|
||||
MAPNIK_DISABLE_WARNING_PUSH
|
||||
MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS
|
||||
MAPNIK_DISABLE_WARNING_PRAGMAS
|
||||
MAPNIK_DISABLE_LONG_LONG
|
||||
return our_strings_[value_];
|
||||
MAPNIK_DISABLE_WARNING_POP
|
||||
MAPNIK_DISABLE_WARNING_POP
|
||||
}
|
||||
|
||||
/** Static helper function to iterate over valid identifiers. */
|
||||
static const char * get_string(unsigned i)
|
||||
{
|
||||
return our_strings_[i];
|
||||
}
|
||||
static const char* get_string(unsigned i) { return our_strings_[i]; }
|
||||
|
||||
/** Performs some simple checks and quits the application if
|
||||
* any error is detected. Tries to print helpful error messages.
|
||||
*/
|
||||
static bool verify_mapnik_enum(const char * filename, unsigned line_no)
|
||||
static bool verify_mapnik_enum(const char* filename, unsigned line_no)
|
||||
{
|
||||
for (unsigned i = 0; i < THE_MAX; ++i)
|
||||
{
|
||||
if (our_strings_[i] == 0 )
|
||||
if (our_strings_[i] == 0)
|
||||
{
|
||||
std::cerr << "### FATAL: Not enough strings for enum "
|
||||
<< our_name_ << " defined in file '" << filename
|
||||
std::cerr << "### FATAL: Not enough strings for enum " << our_name_ << " defined in file '" << filename
|
||||
<< "' at line " << line_no;
|
||||
}
|
||||
}
|
||||
if ( std::string("") != our_strings_[THE_MAX])
|
||||
if (std::string("") != our_strings_[THE_MAX])
|
||||
{
|
||||
std::cerr << "### FATAL: The string array for enum " << our_name_
|
||||
<< " defined in file '" << filename << "' at line " << line_no
|
||||
<< " has too many items or is not terminated with an "
|
||||
std::cerr << "### FATAL: The string array for enum " << our_name_ << " defined in file '" << filename
|
||||
<< "' at line " << line_no << " has too many items or is not terminated with an "
|
||||
<< "empty string";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
ENUM value_;
|
||||
static const char ** our_strings_ ;
|
||||
static std::string our_name_ ;
|
||||
static bool our_verified_flag_;
|
||||
static const char** our_strings_;
|
||||
static std::string our_name_;
|
||||
static bool our_verified_flag_;
|
||||
};
|
||||
|
||||
/** ostream operator for enumeration
|
||||
* @relates mapnik::enumeration
|
||||
*/
|
||||
template <class ENUM, int THE_MAX>
|
||||
std::ostream &
|
||||
operator<<(std::ostream & os, const mapnik::enumeration<ENUM, THE_MAX> & e)
|
||||
template<class ENUM, int THE_MAX>
|
||||
std::ostream& operator<<(std::ostream& os, const mapnik::enumeration<ENUM, THE_MAX>& e)
|
||||
{
|
||||
return os << e.as_string();
|
||||
}
|
||||
|
||||
} // end of namespace
|
||||
} // namespace mapnik
|
||||
|
||||
/** Helper macro.
|
||||
* @relates mapnik::enumeration
|
||||
*/
|
||||
#ifdef _MSC_VER
|
||||
#define DEFINE_ENUM( name, e) \
|
||||
template enumeration<e, e ## _MAX>; \
|
||||
using name = enumeration<e, e ## _MAX>;
|
||||
#define DEFINE_ENUM(name, e) \
|
||||
template enumeration<e, e##_MAX>; \
|
||||
using name = enumeration<e, e##_MAX>;
|
||||
#else
|
||||
#define DEFINE_ENUM( name, e) \
|
||||
using name = enumeration<e, e ## _MAX>; \
|
||||
template <> MAPNIK_DECL const char ** name ::our_strings_; \
|
||||
template <> MAPNIK_DECL std::string name ::our_name_; \
|
||||
template <> MAPNIK_DECL bool name ::our_verified_flag_;
|
||||
#define DEFINE_ENUM(name, e) \
|
||||
using name = enumeration<e, e##_MAX>; \
|
||||
template<> \
|
||||
MAPNIK_DECL const char** name ::our_strings_; \
|
||||
template<> \
|
||||
MAPNIK_DECL std::string name ::our_name_; \
|
||||
template<> \
|
||||
MAPNIK_DECL bool name ::our_verified_flag_;
|
||||
#endif
|
||||
|
||||
/** Helper macro. Runs the verify_mapnik_enum() method during static initialization.
|
||||
* @relates mapnik::enumeration
|
||||
*/
|
||||
|
||||
#define IMPLEMENT_ENUM( name, strings ) \
|
||||
template <> MAPNIK_DECL const char ** name ::our_strings_ = strings; \
|
||||
template <> MAPNIK_DECL std::string name ::our_name_ = #name; \
|
||||
template <> MAPNIK_DECL bool name ::our_verified_flag_( name ::verify_mapnik_enum(__FILE__, __LINE__));
|
||||
#define IMPLEMENT_ENUM(name, strings) \
|
||||
template<> \
|
||||
MAPNIK_DECL const char** name ::our_strings_ = strings; \
|
||||
template<> \
|
||||
MAPNIK_DECL std::string name ::our_name_ = #name; \
|
||||
template<> \
|
||||
MAPNIK_DECL bool name ::our_verified_flag_(name ::verify_mapnik_enum(__FILE__, __LINE__));
|
||||
|
||||
#endif // MAPNIK_ENUMERATION_HPP
|
||||
|
|
|
@ -38,93 +38,91 @@ namespace mapnik {
|
|||
|
||||
namespace {
|
||||
|
||||
template <typename T, typename Attributes>
|
||||
template<typename T, typename Attributes>
|
||||
struct evaluate_expression
|
||||
{
|
||||
using value_type = T;
|
||||
|
||||
explicit evaluate_expression(Attributes const& attrs)
|
||||
: attrs_(attrs) {}
|
||||
: attrs_(attrs)
|
||||
{}
|
||||
|
||||
value_type operator() (attribute const&) const
|
||||
value_type operator()(attribute const&) const
|
||||
{
|
||||
throw std::runtime_error("can't evaluate feature attributes in this context");
|
||||
}
|
||||
|
||||
value_type operator() (global_attribute const& attr) const
|
||||
value_type operator()(global_attribute const& attr) const
|
||||
{
|
||||
auto itr = attrs_.find(attr.name);
|
||||
if (itr != attrs_.end())
|
||||
{
|
||||
return itr->second;
|
||||
}
|
||||
return value_type();// throw?
|
||||
return value_type(); // throw?
|
||||
}
|
||||
|
||||
value_type operator() (geometry_type_attribute const&) const
|
||||
value_type operator()(geometry_type_attribute const&) const
|
||||
{
|
||||
throw std::runtime_error("can't evaluate geometry_type attributes in this context");
|
||||
}
|
||||
|
||||
value_type operator() (binary_node<tags::logical_and> const & x) const
|
||||
value_type operator()(binary_node<tags::logical_and> const& x) const
|
||||
{
|
||||
return (util::apply_visitor(*this, x.left).to_bool())
|
||||
&& (util::apply_visitor(*this, x.right).to_bool());
|
||||
return (util::apply_visitor(*this, x.left).to_bool()) && (util::apply_visitor(*this, x.right).to_bool());
|
||||
}
|
||||
|
||||
value_type operator() (binary_node<tags::logical_or> const & x) const
|
||||
value_type operator()(binary_node<tags::logical_or> const& x) const
|
||||
{
|
||||
return (util::apply_visitor(*this,x.left).to_bool())
|
||||
|| (util::apply_visitor(*this,x.right).to_bool());
|
||||
return (util::apply_visitor(*this, x.left).to_bool()) || (util::apply_visitor(*this, x.right).to_bool());
|
||||
}
|
||||
|
||||
template <typename Tag>
|
||||
value_type operator() (binary_node<Tag> const& x) const
|
||||
template<typename Tag>
|
||||
value_type operator()(binary_node<Tag> const& x) const
|
||||
{
|
||||
typename make_op<Tag>::type operation;
|
||||
return operation(util::apply_visitor(*this, x.left),
|
||||
util::apply_visitor(*this, x.right));
|
||||
return operation(util::apply_visitor(*this, x.left), util::apply_visitor(*this, x.right));
|
||||
}
|
||||
|
||||
template <typename Tag>
|
||||
value_type operator() (unary_node<Tag> const& x) const
|
||||
template<typename Tag>
|
||||
value_type operator()(unary_node<Tag> const& x) const
|
||||
{
|
||||
typename make_op<Tag>::type func;
|
||||
return func(util::apply_visitor(*this, x.expr));
|
||||
}
|
||||
|
||||
value_type operator() (unary_node<tags::logical_not> const& x) const
|
||||
value_type operator()(unary_node<tags::logical_not> const& x) const
|
||||
{
|
||||
return ! (util::apply_visitor(*this,x.expr).to_bool());
|
||||
return !(util::apply_visitor(*this, x.expr).to_bool());
|
||||
}
|
||||
|
||||
value_type operator() (regex_match_node const& x) const
|
||||
value_type operator()(regex_match_node const& x) const
|
||||
{
|
||||
value_type v = util::apply_visitor(*this, x.expr);
|
||||
return x.apply(v);
|
||||
}
|
||||
|
||||
value_type operator() (regex_replace_node const& x) const
|
||||
value_type operator()(regex_replace_node const& x) const
|
||||
{
|
||||
value_type v = util::apply_visitor(*this, x.expr);
|
||||
return x.apply(v);
|
||||
}
|
||||
|
||||
value_type operator() (unary_function_call const& call) const
|
||||
value_type operator()(unary_function_call const& call) const
|
||||
{
|
||||
value_type arg = util::apply_visitor(*this, call.arg);
|
||||
return call.fun(arg);
|
||||
}
|
||||
|
||||
value_type operator() (binary_function_call const& call) const
|
||||
value_type operator()(binary_function_call const& call) const
|
||||
{
|
||||
value_type arg1 = util::apply_visitor(*this, call.arg1);
|
||||
value_type arg2 = util::apply_visitor(*this, call.arg2);
|
||||
return call.fun(arg1, arg2);
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
value_type operator() (ValueType const& val) const
|
||||
template<typename ValueType>
|
||||
value_type operator()(ValueType const& val) const
|
||||
{
|
||||
return value_type(val);
|
||||
}
|
||||
|
@ -132,87 +130,84 @@ struct evaluate_expression
|
|||
Attributes const& attrs_;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
struct evaluate_expression<T, boost::none_t>
|
||||
{
|
||||
using value_type = T;
|
||||
|
||||
evaluate_expression(boost::none_t) {}
|
||||
|
||||
value_type operator() (attribute const&) const
|
||||
value_type operator()(attribute const&) const
|
||||
{
|
||||
throw std::runtime_error("can't evaluate feature attributes in this context");
|
||||
}
|
||||
|
||||
value_type operator() (global_attribute const&) const
|
||||
value_type operator()(global_attribute const&) const
|
||||
{
|
||||
throw std::runtime_error("can't evaluate feature attributes in this context");
|
||||
}
|
||||
|
||||
value_type operator() (geometry_type_attribute const&) const
|
||||
value_type operator()(geometry_type_attribute const&) const
|
||||
{
|
||||
throw std::runtime_error("can't evaluate geometry_type attributes in this context");
|
||||
}
|
||||
|
||||
value_type operator() (binary_node<tags::logical_and> const & x) const
|
||||
value_type operator()(binary_node<tags::logical_and> const& x) const
|
||||
{
|
||||
return (util::apply_visitor(*this, x.left).to_bool())
|
||||
&& (util::apply_visitor(*this, x.right).to_bool());
|
||||
return (util::apply_visitor(*this, x.left).to_bool()) && (util::apply_visitor(*this, x.right).to_bool());
|
||||
}
|
||||
|
||||
value_type operator() (binary_node<tags::logical_or> const & x) const
|
||||
value_type operator()(binary_node<tags::logical_or> const& x) const
|
||||
{
|
||||
return (util::apply_visitor(*this,x.left).to_bool())
|
||||
|| (util::apply_visitor(*this,x.right).to_bool());
|
||||
return (util::apply_visitor(*this, x.left).to_bool()) || (util::apply_visitor(*this, x.right).to_bool());
|
||||
}
|
||||
|
||||
template <typename Tag>
|
||||
value_type operator() (binary_node<Tag> const& x) const
|
||||
template<typename Tag>
|
||||
value_type operator()(binary_node<Tag> const& x) const
|
||||
{
|
||||
typename make_op<Tag>::type operation;
|
||||
return operation(util::apply_visitor(*this, x.left),
|
||||
util::apply_visitor(*this, x.right));
|
||||
return operation(util::apply_visitor(*this, x.left), util::apply_visitor(*this, x.right));
|
||||
}
|
||||
|
||||
template <typename Tag>
|
||||
value_type operator() (unary_node<Tag> const& x) const
|
||||
template<typename Tag>
|
||||
value_type operator()(unary_node<Tag> const& x) const
|
||||
{
|
||||
typename make_op<Tag>::type func;
|
||||
return func(util::apply_visitor(*this, x.expr));
|
||||
}
|
||||
|
||||
value_type operator() (unary_node<tags::logical_not> const& x) const
|
||||
value_type operator()(unary_node<tags::logical_not> const& x) const
|
||||
{
|
||||
return ! (util::apply_visitor(*this,x.expr).to_bool());
|
||||
return !(util::apply_visitor(*this, x.expr).to_bool());
|
||||
}
|
||||
|
||||
value_type operator() (regex_match_node const& x) const
|
||||
value_type operator()(regex_match_node const& x) const
|
||||
{
|
||||
value_type v = util::apply_visitor(*this, x.expr);
|
||||
return x.apply(v);
|
||||
}
|
||||
|
||||
value_type operator() (regex_replace_node const& x) const
|
||||
value_type operator()(regex_replace_node const& x) const
|
||||
{
|
||||
value_type v = util::apply_visitor(*this, x.expr);
|
||||
return x.apply(v);
|
||||
}
|
||||
|
||||
value_type operator() (unary_function_call const& call) const
|
||||
value_type operator()(unary_function_call const& call) const
|
||||
{
|
||||
value_type arg = util::apply_visitor(*this, call.arg);
|
||||
return call.fun(arg);
|
||||
}
|
||||
|
||||
value_type operator() (binary_function_call const& call) const
|
||||
value_type operator()(binary_function_call const& call) const
|
||||
{
|
||||
value_type arg1 = util::apply_visitor(*this, call.arg1);
|
||||
value_type arg2 = util::apply_visitor(*this, call.arg2);
|
||||
return call.fun(arg1, arg2);
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
value_type operator() (ValueType const& val) const
|
||||
template<typename ValueType>
|
||||
value_type operator()(ValueType const& val) const
|
||||
{
|
||||
return value_type(val);
|
||||
}
|
||||
|
@ -221,90 +216,98 @@ struct evaluate_expression<T, boost::none_t>
|
|||
struct assign_value
|
||||
{
|
||||
template<typename Attributes>
|
||||
static void apply(symbolizer_base::value_type & val, expression_ptr const& expr, Attributes const& attrs, property_types target )
|
||||
static void apply(symbolizer_base::value_type& val,
|
||||
expression_ptr const& expr,
|
||||
Attributes const& attrs,
|
||||
property_types target)
|
||||
{
|
||||
|
||||
switch (target)
|
||||
{
|
||||
case property_types::target_color:
|
||||
{
|
||||
// evaluate expression as a string then parse as css color
|
||||
std::string str = util::apply_visitor(mapnik::evaluate_expression<mapnik::value,
|
||||
Attributes>(attrs),*expr).to_string();
|
||||
try { val = parse_color(str); }
|
||||
catch (...) { val = color(0,0,0);}
|
||||
break;
|
||||
}
|
||||
case property_types::target_double:
|
||||
{
|
||||
val = util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs),*expr).to_double();
|
||||
break;
|
||||
}
|
||||
case property_types::target_integer:
|
||||
{
|
||||
val = util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs),*expr).to_int();
|
||||
break;
|
||||
}
|
||||
case property_types::target_bool:
|
||||
{
|
||||
val = util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs),*expr).to_bool();
|
||||
break;
|
||||
}
|
||||
default: // no-op
|
||||
break;
|
||||
case property_types::target_color: {
|
||||
// evaluate expression as a string then parse as css color
|
||||
std::string str =
|
||||
util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs), *expr).to_string();
|
||||
try
|
||||
{
|
||||
val = parse_color(str);
|
||||
} catch (...)
|
||||
{
|
||||
val = color(0, 0, 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case property_types::target_double: {
|
||||
val =
|
||||
util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs), *expr).to_double();
|
||||
break;
|
||||
}
|
||||
case property_types::target_integer: {
|
||||
val =
|
||||
util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs), *expr).to_int();
|
||||
break;
|
||||
}
|
||||
case property_types::target_bool: {
|
||||
val =
|
||||
util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs), *expr).to_bool();
|
||||
break;
|
||||
}
|
||||
default: // no-op
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
||||
template <typename T>
|
||||
std::tuple<T,bool> pre_evaluate_expression (expression_ptr const& expr)
|
||||
template<typename T>
|
||||
std::tuple<T, bool> pre_evaluate_expression(expression_ptr const& expr)
|
||||
{
|
||||
try
|
||||
{
|
||||
return std::make_tuple(util::apply_visitor(mapnik::evaluate_expression<T, boost::none_t>(boost::none),*expr), true);
|
||||
}
|
||||
catch (...)
|
||||
return std::make_tuple(util::apply_visitor(mapnik::evaluate_expression<T, boost::none_t>(boost::none), *expr),
|
||||
true);
|
||||
} catch (...)
|
||||
{
|
||||
return std::make_tuple(T(),false);
|
||||
return std::make_tuple(T(), false);
|
||||
}
|
||||
}
|
||||
|
||||
struct evaluate_global_attributes : util::noncopyable
|
||||
{
|
||||
template <typename Attributes>
|
||||
template<typename Attributes>
|
||||
struct evaluator
|
||||
{
|
||||
evaluator(symbolizer_base::cont_type::value_type & prop, Attributes const& attrs)
|
||||
: prop_(prop),
|
||||
attrs_(attrs) {}
|
||||
evaluator(symbolizer_base::cont_type::value_type& prop, Attributes const& attrs)
|
||||
: prop_(prop)
|
||||
, attrs_(attrs)
|
||||
{}
|
||||
|
||||
void operator() (expression_ptr const& expr) const
|
||||
void operator()(expression_ptr const& expr) const
|
||||
{
|
||||
auto const& meta = get_meta(prop_.first);
|
||||
assign_value::apply(prop_.second, expr, attrs_, std::get<2>(meta));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void operator() (T const&) const
|
||||
template<typename T>
|
||||
void operator()(T const&) const
|
||||
{
|
||||
// no-op
|
||||
}
|
||||
symbolizer_base::cont_type::value_type & prop_;
|
||||
symbolizer_base::cont_type::value_type& prop_;
|
||||
Attributes const& attrs_;
|
||||
};
|
||||
|
||||
template <typename Attributes>
|
||||
template<typename Attributes>
|
||||
struct extract_symbolizer
|
||||
{
|
||||
extract_symbolizer(Attributes const& attrs)
|
||||
: attrs_(attrs) {}
|
||||
: attrs_(attrs)
|
||||
{}
|
||||
|
||||
template <typename Symbolizer>
|
||||
void operator() (Symbolizer & sym) const
|
||||
template<typename Symbolizer>
|
||||
void operator()(Symbolizer& sym) const
|
||||
{
|
||||
for (auto & prop : sym.properties)
|
||||
for (auto& prop : sym.properties)
|
||||
{
|
||||
util::apply_visitor(evaluator<Attributes>(prop, attrs_), prop.second);
|
||||
}
|
||||
|
@ -312,14 +315,14 @@ struct evaluate_global_attributes : util::noncopyable
|
|||
Attributes const& attrs_;
|
||||
};
|
||||
|
||||
template <typename Attributes>
|
||||
static void apply(Map & m, Attributes const& attrs)
|
||||
template<typename Attributes>
|
||||
static void apply(Map& m, Attributes const& attrs)
|
||||
{
|
||||
for ( auto & val : m.styles() )
|
||||
for (auto& val : m.styles())
|
||||
{
|
||||
for (auto & rule : val.second.get_rules_nonconst())
|
||||
for (auto& rule : val.second.get_rules_nonconst())
|
||||
{
|
||||
for (auto & sym : rule)
|
||||
for (auto& sym : rule)
|
||||
{
|
||||
util::apply_visitor(extract_symbolizer<Attributes>(attrs), sym);
|
||||
}
|
||||
|
@ -328,6 +331,6 @@ struct evaluate_global_attributes : util::noncopyable
|
|||
}
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_EVALUATE_GLOBAL_ATTRIBUTES_HPP
|
||||
|
|
|
@ -34,14 +34,13 @@
|
|||
#include <string>
|
||||
#include <set>
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
namespace mapnik {
|
||||
|
||||
// fwd declare to reduce compile time
|
||||
using expression_ptr = std::shared_ptr<expr_node>;
|
||||
using expression_set = std::set<expression_ptr>;
|
||||
|
||||
MAPNIK_DECL expression_ptr parse_expression (std::string const& wkt);
|
||||
}
|
||||
MAPNIK_DECL expression_ptr parse_expression(std::string const& wkt);
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_EXPRESSION_HPP
|
||||
|
|
|
@ -31,10 +31,9 @@
|
|||
#include <mapnik/util/variant.hpp>
|
||||
#include <mapnik/feature.hpp>
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
namespace mapnik {
|
||||
|
||||
template <typename T0, typename T1, typename T2>
|
||||
template<typename T0, typename T1, typename T2>
|
||||
struct evaluate
|
||||
{
|
||||
using feature_type = T0;
|
||||
|
@ -42,105 +41,85 @@ struct evaluate
|
|||
using variable_type = T2;
|
||||
using result_type = T1; // we need this because automatic result_type deduction fails
|
||||
explicit evaluate(feature_type const& f, variable_type const& v)
|
||||
: feature_(f),
|
||||
vars_(v) {}
|
||||
: feature_(f)
|
||||
, vars_(v)
|
||||
{}
|
||||
|
||||
value_type operator() (value_integer val) const
|
||||
{
|
||||
return val;
|
||||
}
|
||||
value_type operator()(value_integer val) const { return val; }
|
||||
|
||||
value_type operator() (value_double val) const
|
||||
{
|
||||
return val;
|
||||
}
|
||||
value_type operator()(value_double val) const { return val; }
|
||||
|
||||
value_type operator() (value_bool val) const
|
||||
{
|
||||
return val;
|
||||
}
|
||||
value_type operator()(value_bool val) const { return val; }
|
||||
|
||||
value_type operator() (value_null val) const
|
||||
{
|
||||
return val;
|
||||
}
|
||||
value_type operator()(value_null val) const { return val; }
|
||||
|
||||
value_type operator() (value_unicode_string const& str) const
|
||||
{
|
||||
return str;
|
||||
}
|
||||
value_type operator()(value_unicode_string const& str) const { return str; }
|
||||
|
||||
value_type operator() (attribute const& attr) const
|
||||
{
|
||||
return attr.value<value_type,feature_type>(feature_);
|
||||
}
|
||||
value_type operator()(attribute const& attr) const { return attr.value<value_type, feature_type>(feature_); }
|
||||
|
||||
value_type operator() (global_attribute const& attr) const
|
||||
value_type operator()(global_attribute const& attr) const
|
||||
{
|
||||
auto itr = vars_.find(attr.name);
|
||||
if (itr != vars_.end())
|
||||
{
|
||||
return itr->second;
|
||||
}
|
||||
return value_type();// throw?
|
||||
return value_type(); // throw?
|
||||
}
|
||||
|
||||
value_type operator() (geometry_type_attribute const& geom) const
|
||||
value_type operator()(geometry_type_attribute const& geom) const
|
||||
{
|
||||
return geom.value<value_type,feature_type>(feature_);
|
||||
return geom.value<value_type, feature_type>(feature_);
|
||||
}
|
||||
|
||||
value_type operator() (binary_node<tags::logical_and> const& x) const
|
||||
value_type operator()(binary_node<tags::logical_and> const& x) const
|
||||
{
|
||||
return (util::apply_visitor(*this, x.left).to_bool())
|
||||
&& (util::apply_visitor(*this, x.right).to_bool());
|
||||
return (util::apply_visitor(*this, x.left).to_bool()) && (util::apply_visitor(*this, x.right).to_bool());
|
||||
}
|
||||
|
||||
value_type operator() (binary_node<tags::logical_or> const& x) const
|
||||
value_type operator()(binary_node<tags::logical_or> const& x) const
|
||||
{
|
||||
return (util::apply_visitor(*this, x.left).to_bool())
|
||||
|| (util::apply_visitor(*this, x.right).to_bool());
|
||||
return (util::apply_visitor(*this, x.left).to_bool()) || (util::apply_visitor(*this, x.right).to_bool());
|
||||
}
|
||||
|
||||
template <typename Tag>
|
||||
value_type operator() (binary_node<Tag> const& x) const
|
||||
template<typename Tag>
|
||||
value_type operator()(binary_node<Tag> const& x) const
|
||||
{
|
||||
typename make_op<Tag>::type operation;
|
||||
return operation(util::apply_visitor(*this, x.left),
|
||||
util::apply_visitor(*this, x.right));
|
||||
return operation(util::apply_visitor(*this, x.left), util::apply_visitor(*this, x.right));
|
||||
}
|
||||
|
||||
template <typename Tag>
|
||||
value_type operator() (unary_node<Tag> const& x) const
|
||||
template<typename Tag>
|
||||
value_type operator()(unary_node<Tag> const& x) const
|
||||
{
|
||||
typename make_op<Tag>::type func;
|
||||
return func(util::apply_visitor(*this, x.expr));
|
||||
}
|
||||
|
||||
value_type operator() (unary_node<tags::logical_not> const& x) const
|
||||
value_type operator()(unary_node<tags::logical_not> const& x) const
|
||||
{
|
||||
return ! (util::apply_visitor(*this,x.expr).to_bool());
|
||||
return !(util::apply_visitor(*this, x.expr).to_bool());
|
||||
}
|
||||
|
||||
value_type operator() (regex_match_node const& x) const
|
||||
value_type operator()(regex_match_node const& x) const
|
||||
{
|
||||
value_type v = util::apply_visitor(*this, x.expr);
|
||||
return x.apply(v);
|
||||
}
|
||||
|
||||
value_type operator() (regex_replace_node const& x) const
|
||||
value_type operator()(regex_replace_node const& x) const
|
||||
{
|
||||
value_type v = util::apply_visitor(*this, x.expr);
|
||||
return x.apply(v);
|
||||
}
|
||||
|
||||
value_type operator() (unary_function_call const& call) const
|
||||
value_type operator()(unary_function_call const& call) const
|
||||
{
|
||||
value_type arg = util::apply_visitor(*this, call.arg);
|
||||
return call.fun(arg);
|
||||
}
|
||||
|
||||
value_type operator() (binary_function_call const& call) const
|
||||
value_type operator()(binary_function_call const& call) const
|
||||
{
|
||||
value_type arg1 = util::apply_visitor(*this, call.arg1);
|
||||
value_type arg2 = util::apply_visitor(*this, call.arg2);
|
||||
|
@ -151,6 +130,6 @@ struct evaluate
|
|||
variable_type const& vars_;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_EXPRESSION_EVALUATOR_HPP
|
||||
|
|
|
@ -31,7 +31,8 @@ MAPNIK_DISABLE_WARNING_PUSH
|
|||
#include <boost/spirit/home/x3.hpp>
|
||||
MAPNIK_DISABLE_WARNING_POP
|
||||
|
||||
namespace mapnik { namespace grammar {
|
||||
namespace mapnik {
|
||||
namespace grammar {
|
||||
|
||||
#if BOOST_VERSION >= 106700
|
||||
using transcoder_type = mapnik::transcoder;
|
||||
|
@ -39,7 +40,6 @@ using transcoder_type = mapnik::transcoder;
|
|||
using transcoder_type = std::reference_wrapper<mapnik::transcoder const>;
|
||||
#endif
|
||||
|
||||
|
||||
namespace x3 = boost::spirit::x3;
|
||||
struct transcoder_tag;
|
||||
struct expression_class; // top-most ID
|
||||
|
@ -49,6 +49,7 @@ expression_grammar_type const expression("expression");
|
|||
|
||||
BOOST_SPIRIT_DECLARE(expression_grammar_type);
|
||||
|
||||
}}
|
||||
} // namespace grammar
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_EXPRESSIONS_GRAMMAR_X3_HPP
|
||||
|
|
|
@ -26,16 +26,16 @@
|
|||
#include <mapnik/expression_grammar_x3.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace mapnik { namespace grammar {
|
||||
namespace mapnik {
|
||||
namespace grammar {
|
||||
|
||||
namespace x3 = boost::spirit::x3;
|
||||
using iterator_type = std::string::const_iterator;
|
||||
using phrase_context_type = x3::phrase_parse_context<x3::ascii::space_type>::type;
|
||||
// define combined context
|
||||
using context_type = x3::context<transcoder_tag,
|
||||
transcoder_type const,
|
||||
phrase_context_type>;
|
||||
using context_type = x3::context<transcoder_tag, transcoder_type const, phrase_context_type>;
|
||||
|
||||
}}
|
||||
} // namespace grammar
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_EXPRESSIONS_GRAMMAR_X3_CONFIG_HPP
|
||||
|
|
|
@ -24,299 +24,272 @@
|
|||
#define MAPNIK_EXPRESSIONS_GRAMMAR_X3_DEF_HPP
|
||||
|
||||
#include <mapnik/expression_grammar_x3.hpp>
|
||||
#include <mapnik/json/unicode_string_grammar_x3_def.hpp>
|
||||
#include <mapnik/expression_node.hpp>
|
||||
#include <mapnik/function_call.hpp>
|
||||
#include <mapnik/json/unicode_string_grammar_x3_def.hpp>
|
||||
#include <mapnik/unicode.hpp>
|
||||
|
||||
#include <mapnik/warning.hpp>
|
||||
MAPNIK_DISABLE_WARNING_PUSH
|
||||
#include <mapnik/warning_ignore.hpp>
|
||||
#include <boost/spirit/home/x3.hpp>
|
||||
#include <boost/spirit/home/x3/support/ast/variant.hpp>
|
||||
#include <boost/fusion/include/adapt_struct.hpp>
|
||||
#include <boost/fusion/include/std_pair.hpp>
|
||||
#include <boost/spirit/home/x3.hpp>
|
||||
#include <boost/spirit/home/x3/support/ast/variant.hpp>
|
||||
#include <mapnik/warning_ignore.hpp>
|
||||
MAPNIK_DISABLE_WARNING_POP
|
||||
|
||||
BOOST_FUSION_ADAPT_STRUCT(mapnik::unary_function_call,
|
||||
(mapnik::unary_function_impl, fun)
|
||||
(mapnik::unary_function_call::argument_type, arg))
|
||||
(mapnik::unary_function_impl, fun)(mapnik::unary_function_call::argument_type, arg))
|
||||
|
||||
BOOST_FUSION_ADAPT_STRUCT(mapnik::binary_function_call,
|
||||
(mapnik::binary_function_impl, fun)
|
||||
(mapnik::binary_function_call::argument_type, arg1)
|
||||
(mapnik::binary_function_call::argument_type, arg2))
|
||||
(mapnik::binary_function_impl, fun)(mapnik::binary_function_call::argument_type,
|
||||
arg1)(mapnik::binary_function_call::argument_type, arg2))
|
||||
|
||||
namespace mapnik {
|
||||
namespace grammar {
|
||||
|
||||
namespace mapnik { namespace grammar {
|
||||
namespace x3 = boost::spirit::x3;
|
||||
namespace ascii = boost::spirit::x3::ascii;
|
||||
using ascii::char_;
|
||||
using ascii::string;
|
||||
using x3::_attr;
|
||||
using x3::_val;
|
||||
using x3::alnum;
|
||||
using x3::alpha;
|
||||
using x3::bool_;
|
||||
using x3::double_;
|
||||
using x3::int_;
|
||||
using x3::lexeme;
|
||||
using x3::lit;
|
||||
using x3::no_case;
|
||||
using x3::no_skip;
|
||||
x3::uint_parser<char, 16, 2, 2> const hex2{};
|
||||
|
||||
namespace x3 = boost::spirit::x3;
|
||||
namespace ascii = boost::spirit::x3::ascii;
|
||||
using ascii::char_;
|
||||
using ascii::string;
|
||||
using x3::lit;
|
||||
using x3::double_;
|
||||
using x3::int_;
|
||||
using x3::bool_;
|
||||
using x3::_attr;
|
||||
using x3::_val;
|
||||
using x3::no_skip;
|
||||
using x3::lexeme;
|
||||
using x3::no_case;
|
||||
using x3::alpha;
|
||||
using x3::alnum;
|
||||
x3::uint_parser<char, 16, 2, 2> const hex2 {};
|
||||
namespace {
|
||||
auto const& escaped_unicode = json::grammar::escaped_unicode;
|
||||
}
|
||||
|
||||
namespace {
|
||||
auto const& escaped_unicode = json::grammar::escaped_unicode;
|
||||
template<typename Context>
|
||||
inline mapnik::transcoder const& extract_transcoder(Context const& ctx)
|
||||
{
|
||||
return x3::get<transcoder_tag>(ctx);
|
||||
}
|
||||
|
||||
auto append = [](auto const& ctx) {
|
||||
_val(ctx) += _attr(ctx);
|
||||
};
|
||||
|
||||
auto do_assign = [](auto const& ctx) {
|
||||
_val(ctx) = std::move(_attr(ctx));
|
||||
};
|
||||
|
||||
auto do_negate = [](auto const& ctx) {
|
||||
_val(ctx) = std::move(unary_node<mapnik::tags::negate>(_attr(ctx)));
|
||||
};
|
||||
|
||||
auto do_attribute = [](auto const& ctx) {
|
||||
auto const& attr = _attr(ctx);
|
||||
if (attr == "mapnik::geometry_type")
|
||||
{
|
||||
_val(ctx) = std::move(geometry_type_attribute());
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
inline mapnik::transcoder const& extract_transcoder(Context const& ctx)
|
||||
else
|
||||
{
|
||||
return x3::get<transcoder_tag>(ctx);
|
||||
_val(ctx) = std::move(attribute(attr));
|
||||
}
|
||||
};
|
||||
|
||||
auto append = [](auto const& ctx)
|
||||
{
|
||||
_val(ctx) += _attr(ctx);
|
||||
};
|
||||
auto do_global_attribute = [](auto const& ctx) {
|
||||
_val(ctx) = std::move(global_attribute(_attr(ctx)));
|
||||
};
|
||||
|
||||
auto do_assign = [] (auto const& ctx)
|
||||
{
|
||||
_val(ctx) = std::move(_attr(ctx));
|
||||
};
|
||||
auto do_add = [](auto const& ctx) {
|
||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::plus>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||
};
|
||||
|
||||
auto do_negate = [] (auto const& ctx)
|
||||
{
|
||||
_val(ctx) = std::move(unary_node<mapnik::tags::negate>(_attr(ctx)));
|
||||
};
|
||||
auto do_subt = [](auto const& ctx) {
|
||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::minus>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||
};
|
||||
|
||||
auto do_attribute = [] (auto const& ctx)
|
||||
{
|
||||
auto const& attr = _attr(ctx);
|
||||
if (attr == "mapnik::geometry_type")
|
||||
{
|
||||
_val(ctx) = std::move(geometry_type_attribute());
|
||||
}
|
||||
else
|
||||
{
|
||||
_val(ctx) = std::move(attribute(attr));
|
||||
}
|
||||
};
|
||||
auto do_mult = [](auto const& ctx) {
|
||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::mult>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||
};
|
||||
|
||||
auto do_global_attribute = [] (auto const& ctx)
|
||||
{
|
||||
_val(ctx) = std::move(global_attribute(_attr(ctx)));
|
||||
};
|
||||
auto do_div = [](auto const& ctx) {
|
||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::div>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||
};
|
||||
|
||||
auto do_add = [] (auto const& ctx)
|
||||
{
|
||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::plus>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||
};
|
||||
auto do_mod = [](auto const& ctx) {
|
||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::mod>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||
};
|
||||
|
||||
auto do_subt = [] (auto const& ctx)
|
||||
{
|
||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::minus>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||
};
|
||||
auto do_unicode = [](auto const& ctx) {
|
||||
auto const& tr = extract_transcoder(ctx);
|
||||
_val(ctx) = std::move(tr.transcode(_attr(ctx).c_str()));
|
||||
};
|
||||
|
||||
auto do_mult = [] (auto const& ctx)
|
||||
{
|
||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::mult>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||
};
|
||||
auto do_null = [](auto const& ctx) {
|
||||
_val(ctx) = std::move(mapnik::value_null());
|
||||
};
|
||||
|
||||
auto do_div = [] (auto const& ctx)
|
||||
{
|
||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::div>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||
};
|
||||
auto do_not = [](auto const& ctx) {
|
||||
mapnik::unary_node<mapnik::tags::logical_not> node(_attr(ctx));
|
||||
_val(ctx) = std::move(node);
|
||||
};
|
||||
|
||||
auto do_mod = [] (auto const& ctx)
|
||||
{
|
||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::mod>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||
};
|
||||
auto do_and = [](auto const& ctx) {
|
||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::logical_and>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||
};
|
||||
|
||||
auto do_unicode = [] (auto const& ctx)
|
||||
{
|
||||
auto const& tr = extract_transcoder(ctx);
|
||||
_val(ctx) = std::move(tr.transcode(_attr(ctx).c_str()));
|
||||
};
|
||||
auto do_or = [](auto const& ctx) {
|
||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::logical_or>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||
};
|
||||
|
||||
auto do_null = [] (auto const& ctx)
|
||||
{
|
||||
_val(ctx) = std::move(mapnik::value_null());
|
||||
};
|
||||
auto do_equal = [](auto const& ctx) {
|
||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::equal_to>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||
};
|
||||
|
||||
auto do_not = [] (auto const& ctx)
|
||||
{
|
||||
mapnik::unary_node<mapnik::tags::logical_not> node(_attr(ctx));
|
||||
_val(ctx) = std::move(node);
|
||||
};
|
||||
auto do_not_equal = [](auto const& ctx) {
|
||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::not_equal_to>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||
};
|
||||
|
||||
auto do_and = [] (auto const& ctx)
|
||||
{
|
||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::logical_and>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||
};
|
||||
auto do_less = [](auto const& ctx) {
|
||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::less>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||
};
|
||||
|
||||
auto do_or = [] (auto const& ctx)
|
||||
{
|
||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::logical_or>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||
};
|
||||
auto do_less_equal = [](auto const& ctx) {
|
||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::less_equal>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||
};
|
||||
|
||||
auto do_equal = [] (auto const& ctx)
|
||||
{
|
||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::equal_to>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||
};
|
||||
auto do_greater = [](auto const& ctx) {
|
||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::greater>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||
};
|
||||
|
||||
auto do_not_equal = [] (auto const& ctx)
|
||||
{
|
||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::not_equal_to>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||
};
|
||||
|
||||
auto do_less = [] (auto const& ctx)
|
||||
{
|
||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::less>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||
};
|
||||
|
||||
auto do_less_equal = [] (auto const& ctx)
|
||||
{
|
||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::less_equal>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||
};
|
||||
|
||||
auto do_greater = [] (auto const& ctx)
|
||||
{
|
||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::greater>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||
};
|
||||
|
||||
auto do_greater_equal = [] (auto const& ctx)
|
||||
{
|
||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::greater_equal>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||
};
|
||||
auto do_greater_equal = [](auto const& ctx) {
|
||||
_val(ctx) =
|
||||
std::move(mapnik::binary_node<mapnik::tags::greater_equal>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||
};
|
||||
|
||||
// regex
|
||||
auto do_regex_match = [] (auto const& ctx)
|
||||
{
|
||||
auto const& tr = extract_transcoder(ctx);
|
||||
_val(ctx) = std::move(mapnik::regex_match_node(tr, std::move(_val(ctx)) , std::move(_attr(ctx))));
|
||||
};
|
||||
auto do_regex_match = [](auto const& ctx) {
|
||||
auto const& tr = extract_transcoder(ctx);
|
||||
_val(ctx) = std::move(mapnik::regex_match_node(tr, std::move(_val(ctx)), std::move(_attr(ctx))));
|
||||
};
|
||||
|
||||
auto do_regex_replace = [] (auto const& ctx)
|
||||
{
|
||||
auto const& tr = extract_transcoder(ctx);
|
||||
auto const& pair = _attr(ctx);
|
||||
auto const& pattern = std::get<0>(pair);
|
||||
auto const& format = std::get<1>(pair);
|
||||
_val(ctx) = mapnik::regex_replace_node(tr, _val(ctx) , pattern, format);
|
||||
};
|
||||
auto do_regex_replace = [](auto const& ctx) {
|
||||
auto const& tr = extract_transcoder(ctx);
|
||||
auto const& pair = _attr(ctx);
|
||||
auto const& pattern = std::get<0>(pair);
|
||||
auto const& format = std::get<1>(pair);
|
||||
_val(ctx) = mapnik::regex_replace_node(tr, _val(ctx), pattern, format);
|
||||
};
|
||||
|
||||
// mapnik::value_integer
|
||||
auto const mapnik_int = x3::int_parser<value_integer,10,1,-1>();
|
||||
auto const mapnik_int = x3::int_parser<value_integer, 10, 1, -1>();
|
||||
// mapnik::value_double
|
||||
auto const mapnik_double = x3::real_parser<value_double, x3::strict_real_policies<value_double>>();
|
||||
auto const mapnik_double = x3::real_parser<value_double, x3::strict_real_policies<value_double>>();
|
||||
// mapnik::value_bool
|
||||
struct boolean_ : x3::symbols<mapnik::value_bool>
|
||||
struct boolean_ : x3::symbols<mapnik::value_bool>
|
||||
{
|
||||
boolean_()
|
||||
{
|
||||
boolean_()
|
||||
{
|
||||
add
|
||||
("true", true)
|
||||
("false", false)
|
||||
;
|
||||
}
|
||||
} boolean;
|
||||
add("true", true) //
|
||||
("false", false) //
|
||||
;
|
||||
}
|
||||
} boolean;
|
||||
|
||||
struct floating_point_constants : x3::symbols<mapnik::value_double>
|
||||
struct floating_point_constants : x3::symbols<mapnik::value_double>
|
||||
{
|
||||
floating_point_constants()
|
||||
{
|
||||
floating_point_constants()
|
||||
{
|
||||
add
|
||||
("pi", 3.1415926535897932384626433832795)
|
||||
("deg_to_rad",0.017453292519943295769236907684886)
|
||||
("rad_to_deg",57.295779513082320876798154814105)
|
||||
;
|
||||
}
|
||||
} float_const;
|
||||
add("pi", 3.1415926535897932384626433832795) //
|
||||
("deg_to_rad", 0.017453292519943295769236907684886) //
|
||||
("rad_to_deg", 57.295779513082320876798154814105) //
|
||||
;
|
||||
}
|
||||
} float_const;
|
||||
|
||||
// unary functions
|
||||
struct unary_function_types_ : x3::symbols<unary_function_impl>
|
||||
struct unary_function_types_ : x3::symbols<unary_function_impl>
|
||||
{
|
||||
unary_function_types_()
|
||||
{
|
||||
unary_function_types_()
|
||||
{
|
||||
add
|
||||
("sin", sin_impl())
|
||||
("cos", cos_impl())
|
||||
("tan", tan_impl())
|
||||
("atan", atan_impl())
|
||||
("exp", exp_impl())
|
||||
("log", log_impl())
|
||||
("abs", abs_impl())
|
||||
("length",length_impl())
|
||||
;
|
||||
}
|
||||
} unary_func_types ;
|
||||
|
||||
add("sin", sin_impl()) //
|
||||
("cos", cos_impl()) //
|
||||
("tan", tan_impl()) //
|
||||
("atan", atan_impl()) //
|
||||
("exp", exp_impl()) //
|
||||
("log", log_impl()) //
|
||||
("abs", abs_impl()) //
|
||||
("length", length_impl()) //
|
||||
;
|
||||
}
|
||||
} unary_func_types;
|
||||
|
||||
// binary functions
|
||||
|
||||
struct binary_function_types_ : x3::symbols<binary_function_impl>
|
||||
struct binary_function_types_ : x3::symbols<binary_function_impl>
|
||||
{
|
||||
binary_function_types_()
|
||||
{
|
||||
binary_function_types_()
|
||||
{
|
||||
add
|
||||
("min", binary_function_impl(min_impl))
|
||||
("max", binary_function_impl(max_impl))
|
||||
("pow", binary_function_impl(pow_impl))
|
||||
;
|
||||
}
|
||||
} binary_func_types;
|
||||
add("min", binary_function_impl(min_impl)) //
|
||||
("max", binary_function_impl(max_impl)) //
|
||||
("pow", binary_function_impl(pow_impl)) //
|
||||
;
|
||||
}
|
||||
} binary_func_types;
|
||||
|
||||
// geometry types
|
||||
struct geometry_types_ : x3::symbols<mapnik::value_integer>
|
||||
struct geometry_types_ : x3::symbols<mapnik::value_integer>
|
||||
{
|
||||
geometry_types_()
|
||||
{
|
||||
geometry_types_()
|
||||
{
|
||||
add
|
||||
("point", 1)
|
||||
("linestring", 2)
|
||||
("polygon",3)
|
||||
("collection",4)
|
||||
;
|
||||
}
|
||||
} geometry_type;
|
||||
add("point", 1) //
|
||||
("linestring", 2) //
|
||||
("polygon", 3) //
|
||||
("collection", 4) //
|
||||
;
|
||||
}
|
||||
} geometry_type;
|
||||
|
||||
struct unesc_chars_ : x3::symbols<char>
|
||||
struct unesc_chars_ : x3::symbols<char>
|
||||
{
|
||||
unesc_chars_()
|
||||
{
|
||||
unesc_chars_()
|
||||
{
|
||||
add
|
||||
("\\a", '\a')
|
||||
("\\b", '\b')
|
||||
("\\f", '\f')
|
||||
("\\n", '\n')
|
||||
("\\r", '\r')
|
||||
("\\t", '\t')
|
||||
("\\v", '\v')
|
||||
("\\\\", '\\')
|
||||
("\\\'", '\'')
|
||||
("\\\"", '\"')
|
||||
;
|
||||
}
|
||||
} unesc_char;
|
||||
|
||||
// rules
|
||||
x3::rule<class logical_expression, mapnik::expr_node> const logical_expression("logical expression");
|
||||
x3::rule<class not_expression, mapnik::expr_node> const not_expression("not expression");
|
||||
x3::rule<class conditional_expression, mapnik::expr_node> const conditional_expression("conditional expression");
|
||||
x3::rule<class equality_expression, mapnik::expr_node> const equality_expression("equality expression");
|
||||
x3::rule<class relational_expression, mapnik::expr_node> const relational_expression("relational expression");
|
||||
x3::rule<class additive_expression, mapnik::expr_node> const additive_expression("additive expression");
|
||||
x3::rule<class multiplicative_expression, mapnik::expr_node> const multiplicative_expression("multiplicative expression");
|
||||
x3::rule<class unary_func_expression, mapnik::unary_function_call> const unary_func_expression("unary function expression");
|
||||
x3::rule<class binary_func_expression, mapnik::binary_function_call> const binary_func_expression("binary function expression");
|
||||
x3::rule<class unary_expression, mapnik::expr_node> const unary_expression("unary expression");
|
||||
x3::rule<class primary_expression, mapnik::expr_node> const primary_expression("primary expression");
|
||||
x3::rule<class regex_match_expression, std::string> const regex_match_expression("regex match expression");
|
||||
x3::rule<class regex_replace_expression, std::pair<std::string,std::string> > const regex_replace_expression("regex replace expression");
|
||||
add("\\a", '\a') //
|
||||
("\\b", '\b') //
|
||||
("\\f", '\f') //
|
||||
("\\n", '\n') //
|
||||
("\\r", '\r') //
|
||||
("\\t", '\t') //
|
||||
("\\v", '\v') //
|
||||
("\\\\", '\\') //
|
||||
("\\\'", '\'') //
|
||||
("\\\"", '\"') //
|
||||
;
|
||||
}
|
||||
} unesc_char;
|
||||
|
||||
// rules
|
||||
x3::rule<class logical_expression, mapnik::expr_node> const logical_expression("logical expression");
|
||||
x3::rule<class not_expression, mapnik::expr_node> const not_expression("not expression");
|
||||
x3::rule<class conditional_expression, mapnik::expr_node> const conditional_expression("conditional expression");
|
||||
x3::rule<class equality_expression, mapnik::expr_node> const equality_expression("equality expression");
|
||||
x3::rule<class relational_expression, mapnik::expr_node> const relational_expression("relational expression");
|
||||
x3::rule<class additive_expression, mapnik::expr_node> const additive_expression("additive expression");
|
||||
x3::rule<class multiplicative_expression, mapnik::expr_node> const
|
||||
multiplicative_expression("multiplicative expression");
|
||||
x3::rule<class unary_func_expression, mapnik::unary_function_call> const
|
||||
unary_func_expression("unary function expression");
|
||||
x3::rule<class binary_func_expression, mapnik::binary_function_call> const
|
||||
binary_func_expression("binary function expression");
|
||||
x3::rule<class unary_expression, mapnik::expr_node> const unary_expression("unary expression");
|
||||
x3::rule<class primary_expression, mapnik::expr_node> const primary_expression("primary expression");
|
||||
x3::rule<class regex_match_expression, std::string> const regex_match_expression("regex match expression");
|
||||
x3::rule<class regex_replace_expression, std::pair<std::string, std::string>> const
|
||||
regex_replace_expression("regex replace expression");
|
||||
// clang-format off
|
||||
// strings
|
||||
auto const single_quoted_string = x3::rule<class single_quoted_string, std::string> {} = lit('\'')
|
||||
>> no_skip[*(unesc_char[append]
|
||||
|
@ -431,24 +404,23 @@ namespace mapnik { namespace grammar {
|
|||
unquoted_ustring[do_unicode]
|
||||
// ^ https://github.com/mapnik/mapnik/pull/3389
|
||||
;
|
||||
// clang-format on
|
||||
BOOST_SPIRIT_DEFINE(expression,
|
||||
logical_expression,
|
||||
not_expression,
|
||||
conditional_expression,
|
||||
equality_expression,
|
||||
relational_expression,
|
||||
additive_expression,
|
||||
regex_match_expression,
|
||||
regex_replace_expression,
|
||||
multiplicative_expression,
|
||||
unary_func_expression,
|
||||
binary_func_expression,
|
||||
unary_expression,
|
||||
primary_expression);
|
||||
|
||||
BOOST_SPIRIT_DEFINE (
|
||||
expression,
|
||||
logical_expression,
|
||||
not_expression,
|
||||
conditional_expression,
|
||||
equality_expression,
|
||||
relational_expression,
|
||||
additive_expression,
|
||||
regex_match_expression,
|
||||
regex_replace_expression,
|
||||
multiplicative_expression,
|
||||
unary_func_expression,
|
||||
binary_func_expression,
|
||||
unary_expression,
|
||||
primary_expression
|
||||
);
|
||||
} // namespace grammar
|
||||
} // namespace mapnik
|
||||
|
||||
}}
|
||||
|
||||
#endif // MAPNIK_EXPRESSIONS_GRAMMAR_X3_DEF_HPP
|
||||
#endif // MAPNIK_EXPRESSIONS_GRAMMAR_X3_DEF_HPP
|
||||
|
|
|
@ -34,61 +34,119 @@
|
|||
// stl
|
||||
#include <memory>
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
namespace mapnik {
|
||||
|
||||
using value_type = mapnik::value;
|
||||
|
||||
template <typename Tag> struct make_op;
|
||||
template <> struct make_op<mapnik::tags::negate> { using type = std::negate<value_type>;};
|
||||
template <> struct make_op<mapnik::tags::plus> { using type = std::plus<value_type>;};
|
||||
template <> struct make_op<mapnik::tags::minus> { using type = std::minus<value_type>;};
|
||||
template <> struct make_op<mapnik::tags::mult> { using type = std::multiplies<value_type>;};
|
||||
template <> struct make_op<mapnik::tags::div> { using type = std::divides<value_type>;};
|
||||
template <> struct make_op<mapnik::tags::mod> { using type = std::modulus<value_type>;};
|
||||
template <> struct make_op<mapnik::tags::less> { using type = std::less<value_type>;};
|
||||
template <> struct make_op<mapnik::tags::less_equal> { using type = std::less_equal<value_type>;};
|
||||
template <> struct make_op<mapnik::tags::greater> { using type = std::greater<value_type>;};
|
||||
template <> struct make_op<mapnik::tags::greater_equal> { using type = std::greater_equal<value_type>;};
|
||||
template <> struct make_op<mapnik::tags::equal_to> { using type = std::equal_to<value_type>;};
|
||||
template <> struct make_op<mapnik::tags::not_equal_to> { using type = std::not_equal_to<value_type>;};
|
||||
template <> struct make_op<mapnik::tags::logical_not> { using type = std::logical_not<value_type>;};
|
||||
template <> struct make_op<mapnik::tags::logical_and> { using type = std::logical_and<value_type>;};
|
||||
template <> struct make_op<mapnik::tags::logical_or> { using type = std::logical_or<value_type>;};
|
||||
template<typename Tag>
|
||||
struct make_op;
|
||||
template<>
|
||||
struct make_op<mapnik::tags::negate>
|
||||
{
|
||||
using type = std::negate<value_type>;
|
||||
};
|
||||
template<>
|
||||
struct make_op<mapnik::tags::plus>
|
||||
{
|
||||
using type = std::plus<value_type>;
|
||||
};
|
||||
template<>
|
||||
struct make_op<mapnik::tags::minus>
|
||||
{
|
||||
using type = std::minus<value_type>;
|
||||
};
|
||||
template<>
|
||||
struct make_op<mapnik::tags::mult>
|
||||
{
|
||||
using type = std::multiplies<value_type>;
|
||||
};
|
||||
template<>
|
||||
struct make_op<mapnik::tags::div>
|
||||
{
|
||||
using type = std::divides<value_type>;
|
||||
};
|
||||
template<>
|
||||
struct make_op<mapnik::tags::mod>
|
||||
{
|
||||
using type = std::modulus<value_type>;
|
||||
};
|
||||
template<>
|
||||
struct make_op<mapnik::tags::less>
|
||||
{
|
||||
using type = std::less<value_type>;
|
||||
};
|
||||
template<>
|
||||
struct make_op<mapnik::tags::less_equal>
|
||||
{
|
||||
using type = std::less_equal<value_type>;
|
||||
};
|
||||
template<>
|
||||
struct make_op<mapnik::tags::greater>
|
||||
{
|
||||
using type = std::greater<value_type>;
|
||||
};
|
||||
template<>
|
||||
struct make_op<mapnik::tags::greater_equal>
|
||||
{
|
||||
using type = std::greater_equal<value_type>;
|
||||
};
|
||||
template<>
|
||||
struct make_op<mapnik::tags::equal_to>
|
||||
{
|
||||
using type = std::equal_to<value_type>;
|
||||
};
|
||||
template<>
|
||||
struct make_op<mapnik::tags::not_equal_to>
|
||||
{
|
||||
using type = std::not_equal_to<value_type>;
|
||||
};
|
||||
template<>
|
||||
struct make_op<mapnik::tags::logical_not>
|
||||
{
|
||||
using type = std::logical_not<value_type>;
|
||||
};
|
||||
template<>
|
||||
struct make_op<mapnik::tags::logical_and>
|
||||
{
|
||||
using type = std::logical_and<value_type>;
|
||||
};
|
||||
template<>
|
||||
struct make_op<mapnik::tags::logical_or>
|
||||
{
|
||||
using type = std::logical_or<value_type>;
|
||||
};
|
||||
|
||||
template <typename Tag>
|
||||
template<typename Tag>
|
||||
struct unary_node
|
||||
{
|
||||
unary_node (expr_node && a)
|
||||
: expr(std::move(a)) {}
|
||||
unary_node(expr_node&& a)
|
||||
: expr(std::move(a))
|
||||
{}
|
||||
|
||||
unary_node (expr_node const& a)
|
||||
: expr(a) {}
|
||||
unary_node(expr_node const& a)
|
||||
: expr(a)
|
||||
{}
|
||||
|
||||
static const char* type()
|
||||
{
|
||||
return Tag::str();
|
||||
}
|
||||
static const char* type() { return Tag::str(); }
|
||||
|
||||
expr_node expr;
|
||||
};
|
||||
|
||||
template <typename Tag>
|
||||
template<typename Tag>
|
||||
struct binary_node
|
||||
{
|
||||
binary_node(expr_node && a, expr_node && b)
|
||||
: left(std::move(a)),
|
||||
right(std::move(b)) {}
|
||||
binary_node(expr_node&& a, expr_node&& b)
|
||||
: left(std::move(a))
|
||||
, right(std::move(b))
|
||||
{}
|
||||
|
||||
binary_node(expr_node const& a, expr_node const& b)
|
||||
: left(a),
|
||||
right(b) {}
|
||||
: left(a)
|
||||
, right(b)
|
||||
{}
|
||||
|
||||
static const char* type()
|
||||
{
|
||||
return Tag::str();
|
||||
}
|
||||
expr_node left,right;
|
||||
static const char* type() { return Tag::str(); }
|
||||
expr_node left, right;
|
||||
};
|
||||
|
||||
struct unary_function_call
|
||||
|
@ -96,7 +154,9 @@ struct unary_function_call
|
|||
using argument_type = expr_node;
|
||||
unary_function_call() = default;
|
||||
unary_function_call(unary_function_impl _fun, argument_type const& _arg)
|
||||
: fun(_fun), arg(_arg) {}
|
||||
: fun(_fun)
|
||||
, arg(_arg)
|
||||
{}
|
||||
|
||||
unary_function_impl fun;
|
||||
argument_type arg;
|
||||
|
@ -107,7 +167,10 @@ struct binary_function_call
|
|||
using argument_type = expr_node;
|
||||
binary_function_call() = default;
|
||||
binary_function_call(binary_function_impl _fun, argument_type const& _arg1, argument_type const& _arg2)
|
||||
: fun(_fun), arg1(_arg1), arg2(_arg2) {}
|
||||
: fun(_fun)
|
||||
, arg1(_arg1)
|
||||
, arg2(_arg2)
|
||||
{}
|
||||
binary_function_impl fun;
|
||||
argument_type arg1;
|
||||
argument_type arg2;
|
||||
|
@ -137,7 +200,6 @@ struct MAPNIK_DECL regex_replace_node
|
|||
std::shared_ptr<_regex_replace_impl> impl_;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace mapnik
|
||||
|
||||
|
||||
#endif //MAPNIK_EXPRESSION_NODE_HPP
|
||||
#endif // MAPNIK_EXPRESSION_NODE_HPP
|
||||
|
|
|
@ -28,136 +28,90 @@
|
|||
#include <mapnik/value/types.hpp>
|
||||
#include <mapnik/util/variant.hpp>
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
namespace mapnik {
|
||||
|
||||
namespace tags {
|
||||
namespace tags {
|
||||
struct negate
|
||||
{
|
||||
static const char* str()
|
||||
{
|
||||
return "-";
|
||||
}
|
||||
static const char* str() { return "-"; }
|
||||
};
|
||||
|
||||
struct plus
|
||||
{
|
||||
static const char* str()
|
||||
{
|
||||
return "+";
|
||||
}
|
||||
static const char* str() { return "+"; }
|
||||
};
|
||||
|
||||
struct minus
|
||||
{
|
||||
static const char* str()
|
||||
{
|
||||
return "-";
|
||||
}
|
||||
static const char* str() { return "-"; }
|
||||
};
|
||||
|
||||
struct mult
|
||||
{
|
||||
static const char* str()
|
||||
{
|
||||
return "*";
|
||||
}
|
||||
static const char* str() { return "*"; }
|
||||
};
|
||||
|
||||
struct div
|
||||
{
|
||||
static const char* str()
|
||||
{
|
||||
return "/";
|
||||
}
|
||||
static const char* str() { return "/"; }
|
||||
};
|
||||
|
||||
|
||||
struct mod
|
||||
struct mod
|
||||
{
|
||||
static const char* str()
|
||||
{
|
||||
return "%";
|
||||
}
|
||||
static const char* str() { return "%"; }
|
||||
};
|
||||
|
||||
struct less
|
||||
{
|
||||
static const char* str()
|
||||
{
|
||||
return "<";
|
||||
}
|
||||
static const char* str() { return "<"; }
|
||||
};
|
||||
|
||||
struct less_equal
|
||||
{
|
||||
static const char* str()
|
||||
{
|
||||
return "<=";
|
||||
}
|
||||
static const char* str() { return "<="; }
|
||||
};
|
||||
|
||||
struct greater
|
||||
{
|
||||
static const char* str()
|
||||
{
|
||||
return ">";
|
||||
}
|
||||
static const char* str() { return ">"; }
|
||||
};
|
||||
|
||||
struct greater_equal
|
||||
{
|
||||
static const char* str()
|
||||
{
|
||||
return ">=";
|
||||
}
|
||||
static const char* str() { return ">="; }
|
||||
};
|
||||
|
||||
struct equal_to
|
||||
{
|
||||
static const char* str()
|
||||
{
|
||||
return "=";
|
||||
}
|
||||
static const char* str() { return "="; }
|
||||
};
|
||||
|
||||
struct not_equal_to
|
||||
{
|
||||
static const char* str()
|
||||
{
|
||||
return "!=";
|
||||
}
|
||||
static const char* str() { return "!="; }
|
||||
};
|
||||
|
||||
struct logical_not
|
||||
{
|
||||
static const char* str()
|
||||
{
|
||||
return "not ";
|
||||
}
|
||||
static const char* str() { return "not "; }
|
||||
};
|
||||
|
||||
struct logical_and
|
||||
{
|
||||
static const char* str()
|
||||
{
|
||||
return " and ";
|
||||
}
|
||||
static const char* str() { return " and "; }
|
||||
};
|
||||
|
||||
struct logical_or
|
||||
{
|
||||
static const char* str()
|
||||
{
|
||||
return " or ";
|
||||
}
|
||||
static const char* str() { return " or "; }
|
||||
};
|
||||
|
||||
} // end operation tags
|
||||
} // namespace tags
|
||||
|
||||
|
||||
template <typename Tag> struct binary_node;
|
||||
template <typename Tag> struct unary_node;
|
||||
template<typename Tag>
|
||||
struct binary_node;
|
||||
template<typename Tag>
|
||||
struct unary_node;
|
||||
struct regex_match_node;
|
||||
struct regex_replace_node;
|
||||
struct attribute;
|
||||
|
@ -166,37 +120,34 @@ struct geometry_type_attribute;
|
|||
struct unary_function_call;
|
||||
struct binary_function_call;
|
||||
|
||||
using expr_node = util::variant<
|
||||
value_null,
|
||||
value_bool,
|
||||
value_integer,
|
||||
value_double,
|
||||
value_unicode_string,
|
||||
attribute,
|
||||
global_attribute,
|
||||
geometry_type_attribute,
|
||||
util::recursive_wrapper<unary_node<mapnik::tags::negate> >,
|
||||
util::recursive_wrapper<binary_node<mapnik::tags::plus> >,
|
||||
util::recursive_wrapper<binary_node<mapnik::tags::minus> >,
|
||||
util::recursive_wrapper<binary_node<mapnik::tags::mult> >,
|
||||
util::recursive_wrapper<binary_node<mapnik::tags::div> >,
|
||||
util::recursive_wrapper<binary_node<mapnik::tags::mod> >,
|
||||
util::recursive_wrapper<binary_node<mapnik::tags::less> >,
|
||||
util::recursive_wrapper<binary_node<mapnik::tags::less_equal> >,
|
||||
util::recursive_wrapper<binary_node<mapnik::tags::greater> >,
|
||||
util::recursive_wrapper<binary_node<mapnik::tags::greater_equal> >,
|
||||
util::recursive_wrapper<binary_node<mapnik::tags::equal_to> >,
|
||||
util::recursive_wrapper<binary_node<mapnik::tags::not_equal_to> >,
|
||||
util::recursive_wrapper<unary_node<mapnik::tags::logical_not> >,
|
||||
util::recursive_wrapper<binary_node<mapnik::tags::logical_and> >,
|
||||
util::recursive_wrapper<binary_node<mapnik::tags::logical_or> >,
|
||||
util::recursive_wrapper<regex_match_node>,
|
||||
util::recursive_wrapper<regex_replace_node>,
|
||||
util::recursive_wrapper<unary_function_call>,
|
||||
util::recursive_wrapper<binary_function_call>
|
||||
>;
|
||||
|
||||
}
|
||||
using expr_node = util::variant<value_null,
|
||||
value_bool,
|
||||
value_integer,
|
||||
value_double,
|
||||
value_unicode_string,
|
||||
attribute,
|
||||
global_attribute,
|
||||
geometry_type_attribute,
|
||||
util::recursive_wrapper<unary_node<mapnik::tags::negate>>,
|
||||
util::recursive_wrapper<binary_node<mapnik::tags::plus>>,
|
||||
util::recursive_wrapper<binary_node<mapnik::tags::minus>>,
|
||||
util::recursive_wrapper<binary_node<mapnik::tags::mult>>,
|
||||
util::recursive_wrapper<binary_node<mapnik::tags::div>>,
|
||||
util::recursive_wrapper<binary_node<mapnik::tags::mod>>,
|
||||
util::recursive_wrapper<binary_node<mapnik::tags::less>>,
|
||||
util::recursive_wrapper<binary_node<mapnik::tags::less_equal>>,
|
||||
util::recursive_wrapper<binary_node<mapnik::tags::greater>>,
|
||||
util::recursive_wrapper<binary_node<mapnik::tags::greater_equal>>,
|
||||
util::recursive_wrapper<binary_node<mapnik::tags::equal_to>>,
|
||||
util::recursive_wrapper<binary_node<mapnik::tags::not_equal_to>>,
|
||||
util::recursive_wrapper<unary_node<mapnik::tags::logical_not>>,
|
||||
util::recursive_wrapper<binary_node<mapnik::tags::logical_and>>,
|
||||
util::recursive_wrapper<binary_node<mapnik::tags::logical_or>>,
|
||||
util::recursive_wrapper<regex_match_node>,
|
||||
util::recursive_wrapper<regex_replace_node>,
|
||||
util::recursive_wrapper<unary_function_call>,
|
||||
util::recursive_wrapper<binary_function_call>>;
|
||||
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_EXPRESSION_NODE_HPP
|
||||
|
|
|
@ -35,8 +35,7 @@
|
|||
#include <string>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
namespace mapnik {
|
||||
MAPNIK_DECL std::string to_expression_string(expr_node const& node);
|
||||
|
||||
/*
|
||||
|
@ -48,7 +47,7 @@ implicit pointer-to-bool conversion, thus any non-null pointer
|
|||
would yield "true".
|
||||
*/
|
||||
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
std::string to_expression_string(T const* expr_node_ptr)
|
||||
{
|
||||
throw std::logic_error("to_expression_string() called with pointer argument");
|
||||
|
@ -56,13 +55,13 @@ std::string to_expression_string(T const* expr_node_ptr)
|
|||
return expr_node_ptr; // to_expression_string() called with pointer argument
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
std::string to_expression_string(std::shared_ptr<T> const& expr_node_ptr)
|
||||
{
|
||||
throw std::logic_error("to_expression_string() called with pointer argument");
|
||||
// compile error intended here; comment on the next line shows in clang output
|
||||
return expr_node_ptr; // to_expression_string() called with pointer argument
|
||||
}
|
||||
}
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_EXPRESSION_STRING_HPP
|
||||
|
|
|
@ -38,108 +38,122 @@ MAPNIK_DISABLE_WARNING_POP
|
|||
// stl
|
||||
#include <cmath>
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
namespace mapnik {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
namespace detail {
|
||||
|
||||
namespace msm = boost::msm;
|
||||
namespace mpl = boost::mpl;
|
||||
using namespace msm::front;
|
||||
|
||||
template <typename T>
|
||||
T extend(T const & v1, T const & v2, double length)
|
||||
template<typename T>
|
||||
T extend(T const& v1, T const& v2, double length)
|
||||
{
|
||||
double dx = v2.x - v1.x;
|
||||
double dy = v2.y - v1.y;
|
||||
double l12 = std::sqrt(dx * dx + dy * dy);
|
||||
double coef = 1.0 + length / l12;
|
||||
return vertex2d(v1.x + dx * coef,
|
||||
v1.y + dy * coef, v2.cmd);
|
||||
return vertex2d(v1.x + dx * coef, v1.y + dy * coef, v2.cmd);
|
||||
}
|
||||
|
||||
namespace events
|
||||
namespace events {
|
||||
struct vertex_event
|
||||
{
|
||||
struct vertex_event
|
||||
{
|
||||
vertex_event(vertex2d const & vertex) : vertex(vertex) { }
|
||||
vertex2d const & vertex;
|
||||
};
|
||||
vertex_event(vertex2d const& vertex)
|
||||
: vertex(vertex)
|
||||
{}
|
||||
vertex2d const& vertex;
|
||||
};
|
||||
|
||||
struct move_to : vertex_event { using vertex_event::vertex_event; };
|
||||
struct line_to : vertex_event { using vertex_event::vertex_event; };
|
||||
struct close : vertex_event { using vertex_event::vertex_event; };
|
||||
struct end : vertex_event { using vertex_event::vertex_event; };
|
||||
}
|
||||
|
||||
namespace actions
|
||||
struct move_to : vertex_event
|
||||
{
|
||||
struct store
|
||||
{
|
||||
template <class FSM, class EVT, class SourceState, class TargetState>
|
||||
void operator()(EVT const & e, FSM & m, SourceState&, TargetState&)
|
||||
{
|
||||
m.v2 = m.v1;
|
||||
m.v1 = e.vertex;
|
||||
m.output = boost::none;
|
||||
}
|
||||
};
|
||||
using vertex_event::vertex_event;
|
||||
};
|
||||
struct line_to : vertex_event
|
||||
{
|
||||
using vertex_event::vertex_event;
|
||||
};
|
||||
struct close : vertex_event
|
||||
{
|
||||
using vertex_event::vertex_event;
|
||||
};
|
||||
struct end : vertex_event
|
||||
{
|
||||
using vertex_event::vertex_event;
|
||||
};
|
||||
} // namespace events
|
||||
|
||||
struct output
|
||||
namespace actions {
|
||||
struct store
|
||||
{
|
||||
template<class FSM, class EVT, class SourceState, class TargetState>
|
||||
void operator()(EVT const& e, FSM& m, SourceState&, TargetState&)
|
||||
{
|
||||
template <class FSM, class EVT, class SourceState, class TargetState>
|
||||
void operator()(EVT const & e, FSM & m, SourceState&, TargetState&)
|
||||
{
|
||||
m.output = e.vertex;
|
||||
}
|
||||
};
|
||||
m.v2 = m.v1;
|
||||
m.v1 = e.vertex;
|
||||
m.output = boost::none;
|
||||
}
|
||||
};
|
||||
|
||||
struct store_and_output
|
||||
struct output
|
||||
{
|
||||
template<class FSM, class EVT, class SourceState, class TargetState>
|
||||
void operator()(EVT const& e, FSM& m, SourceState&, TargetState&)
|
||||
{
|
||||
template <class FSM, class EVT, class SourceState, class TargetState>
|
||||
void operator()(EVT const & e, FSM & m, SourceState&, TargetState&)
|
||||
{
|
||||
m.v2 = m.v1;
|
||||
m.v1 = e.vertex;
|
||||
m.output = m.v2;
|
||||
}
|
||||
};
|
||||
m.output = e.vertex;
|
||||
}
|
||||
};
|
||||
|
||||
struct output_begin
|
||||
struct store_and_output
|
||||
{
|
||||
template<class FSM, class EVT, class SourceState, class TargetState>
|
||||
void operator()(EVT const& e, FSM& m, SourceState&, TargetState&)
|
||||
{
|
||||
template <class FSM, class EVT, class SourceState, class TargetState>
|
||||
void operator()(EVT const & e, FSM & m, SourceState&, TargetState&)
|
||||
{
|
||||
m.v2 = m.v1;
|
||||
m.v1 = e.vertex;
|
||||
m.output = extend(m.v1, m.v2, m.extend_length);
|
||||
}
|
||||
};
|
||||
m.v2 = m.v1;
|
||||
m.v1 = e.vertex;
|
||||
m.output = m.v2;
|
||||
}
|
||||
};
|
||||
|
||||
struct output_end
|
||||
struct output_begin
|
||||
{
|
||||
template<class FSM, class EVT, class SourceState, class TargetState>
|
||||
void operator()(EVT const& e, FSM& m, SourceState&, TargetState&)
|
||||
{
|
||||
template <class FSM, class EVT, class SourceState, class TargetState>
|
||||
void operator()(EVT const & e, FSM & m, SourceState&, TargetState&)
|
||||
{
|
||||
m.output = extend(m.v2, m.v1, m.extend_length);
|
||||
m.v1 = e.vertex;
|
||||
}
|
||||
};
|
||||
}
|
||||
m.v2 = m.v1;
|
||||
m.v1 = e.vertex;
|
||||
m.output = extend(m.v1, m.v2, m.extend_length);
|
||||
}
|
||||
};
|
||||
|
||||
struct output_end
|
||||
{
|
||||
template<class FSM, class EVT, class SourceState, class TargetState>
|
||||
void operator()(EVT const& e, FSM& m, SourceState&, TargetState&)
|
||||
{
|
||||
m.output = extend(m.v2, m.v1, m.extend_length);
|
||||
m.v1 = e.vertex;
|
||||
}
|
||||
};
|
||||
} // namespace actions
|
||||
|
||||
struct extender_def : public msm::front::state_machine_def<extender_def>
|
||||
{
|
||||
using no_exception_thrown = int;
|
||||
using no_message_queue = int;
|
||||
|
||||
struct initial : public msm::front::state<> { };
|
||||
struct vertex_one : public msm::front::state<> { };
|
||||
struct vertex_two : public msm::front::state<> { };
|
||||
struct end : public msm::front::state<> { };
|
||||
struct initial : public msm::front::state<>
|
||||
{};
|
||||
struct vertex_one : public msm::front::state<>
|
||||
{};
|
||||
struct vertex_two : public msm::front::state<>
|
||||
{};
|
||||
struct end : public msm::front::state<>
|
||||
{};
|
||||
|
||||
using initial_state = initial;
|
||||
|
||||
// clang-format off
|
||||
struct transition_table : mpl::vector<
|
||||
// Start Event Next Action Guard
|
||||
// +------------+-----------------+------------+--------------------+------+
|
||||
|
@ -157,11 +171,11 @@ struct extender_def : public msm::front::state_machine_def<extender_def>
|
|||
Row < vertex_two , events::end , end , actions::output_end >,
|
||||
Row < end , events::end , end , actions::output >
|
||||
> {};
|
||||
// clang-format on
|
||||
|
||||
extender_def(double extend_length)
|
||||
: extend_length(extend_length)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
boost::optional<vertex2d> output;
|
||||
vertex2d v1, v2;
|
||||
|
@ -170,25 +184,23 @@ struct extender_def : public msm::front::state_machine_def<extender_def>
|
|||
|
||||
using extender = msm::back::state_machine<extender_def>;
|
||||
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
template <typename Geometry>
|
||||
template<typename Geometry>
|
||||
struct extend_converter
|
||||
{
|
||||
extend_converter(Geometry & geom)
|
||||
extend_converter(Geometry& geom)
|
||||
: extend_converter(geom, 0)
|
||||
{}
|
||||
|
||||
extend_converter(Geometry & geom, double extend)
|
||||
: geom_(geom), extender_(extend)
|
||||
extend_converter(Geometry& geom, double extend)
|
||||
: geom_(geom)
|
||||
, extender_(extend)
|
||||
{}
|
||||
|
||||
void set_extend(double extend)
|
||||
{
|
||||
extender_.extend_length = extend;
|
||||
}
|
||||
void set_extend(double extend) { extender_.extend_length = extend; }
|
||||
|
||||
unsigned vertex(double * x, double * y)
|
||||
unsigned vertex(double* x, double* y)
|
||||
{
|
||||
using namespace detail;
|
||||
vertex2d v;
|
||||
|
@ -210,9 +222,9 @@ struct extend_converter
|
|||
extender_.process_event(events::end(v));
|
||||
break;
|
||||
}
|
||||
} while(!extender_.output);
|
||||
} while (!extender_.output);
|
||||
|
||||
vertex2d const & output = *extender_.output;
|
||||
vertex2d const& output = *extender_.output;
|
||||
*x = output.x;
|
||||
*y = output.y;
|
||||
return output.cmd;
|
||||
|
@ -224,11 +236,11 @@ struct extend_converter
|
|||
extender_.start();
|
||||
}
|
||||
|
||||
private:
|
||||
Geometry & geom_;
|
||||
private:
|
||||
Geometry& geom_;
|
||||
detail::extender extender_;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_EXTEND_CONVERTER_HPP
|
||||
|
|
|
@ -32,41 +32,33 @@
|
|||
|
||||
namespace mapnik {
|
||||
|
||||
template
|
||||
<
|
||||
typename product_type,
|
||||
typename key_type,
|
||||
typename ...Args >
|
||||
class factory : public singleton<factory <product_type,
|
||||
key_type,
|
||||
Args...> >
|
||||
template<typename product_type, typename key_type, typename... Args>
|
||||
class factory : public singleton<factory<product_type, key_type, Args...>>
|
||||
{
|
||||
private:
|
||||
using product_creator = product_type* (*) (Args...);
|
||||
using product_map = std::map<key_type,product_creator>;
|
||||
private:
|
||||
using product_creator = product_type* (*)(Args...);
|
||||
using product_map = std::map<key_type, product_creator>;
|
||||
product_map map_;
|
||||
public:
|
||||
|
||||
public:
|
||||
|
||||
bool register_product(key_type const& key, product_creator creator)
|
||||
{
|
||||
return map_.insert(typename product_map::value_type(key,creator)).second;
|
||||
return map_.insert(typename product_map::value_type(key, creator)).second;
|
||||
}
|
||||
|
||||
bool unregister_product(const key_type& key)
|
||||
{
|
||||
return map_.erase(key)==1;
|
||||
}
|
||||
bool unregister_product(const key_type& key) { return map_.erase(key) == 1; }
|
||||
|
||||
product_type* create_object(key_type const& key, Args...args)
|
||||
product_type* create_object(key_type const& key, Args... args)
|
||||
{
|
||||
typename product_map::const_iterator pos=map_.find(key);
|
||||
if (pos!=map_.end())
|
||||
typename product_map::const_iterator pos = map_.find(key);
|
||||
if (pos != map_.end())
|
||||
{
|
||||
return (pos->second)(args...);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_FACTORY_HPP
|
||||
|
|
|
@ -38,9 +38,9 @@
|
|||
#include <memory>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <ostream> // for basic_ostream, operator<<, etc
|
||||
#include <sstream> // for basic_stringstream
|
||||
#include <stdexcept> // for out_of_range
|
||||
#include <ostream> // for basic_ostream, operator<<, etc
|
||||
#include <sstream> // for basic_stringstream
|
||||
#include <stdexcept> // for out_of_range
|
||||
#include <iostream>
|
||||
|
||||
namespace mapnik {
|
||||
|
@ -50,12 +50,13 @@ class feature_impl;
|
|||
|
||||
using raster_ptr = std::shared_ptr<raster>;
|
||||
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
class context : private util::noncopyable
|
||||
|
||||
{
|
||||
friend class feature_impl;
|
||||
public:
|
||||
|
||||
public:
|
||||
using map_type = T;
|
||||
using value_type = typename map_type::value_type;
|
||||
using key_type = typename map_type::key_type;
|
||||
|
@ -65,7 +66,8 @@ public:
|
|||
using const_iterator = typename map_type::const_iterator;
|
||||
|
||||
context()
|
||||
: mapping_() {}
|
||||
: mapping_()
|
||||
{}
|
||||
|
||||
inline size_type push(key_type const& name)
|
||||
{
|
||||
|
@ -74,20 +76,17 @@ public:
|
|||
return index;
|
||||
}
|
||||
|
||||
inline void add(key_type const& name, size_type index)
|
||||
{
|
||||
mapping_.emplace(name, index);
|
||||
}
|
||||
inline void add(key_type const& name, size_type index) { mapping_.emplace(name, index); }
|
||||
|
||||
inline size_type size() const { return mapping_.size(); }
|
||||
inline const_iterator begin() const { return mapping_.begin();}
|
||||
inline const_iterator end() const { return mapping_.end();}
|
||||
inline const_iterator begin() const { return mapping_.begin(); }
|
||||
inline const_iterator end() const { return mapping_.end(); }
|
||||
|
||||
private:
|
||||
private:
|
||||
map_type mapping_;
|
||||
};
|
||||
|
||||
using context_type = context<std::map<std::string,std::size_t> >;
|
||||
using context_type = context<std::map<std::string, std::size_t>>;
|
||||
using context_ptr = std::shared_ptr<context_type>;
|
||||
|
||||
static const value default_feature_value{};
|
||||
|
@ -95,38 +94,39 @@ static const value default_feature_value{};
|
|||
class MAPNIK_DECL feature_impl : private util::noncopyable
|
||||
{
|
||||
friend class feature_kv_iterator;
|
||||
public:
|
||||
|
||||
public:
|
||||
|
||||
using value_type = mapnik::value;
|
||||
using cont_type = std::vector<value_type>;
|
||||
using iterator = feature_kv_iterator;
|
||||
|
||||
feature_impl(context_ptr const& ctx, mapnik::value_integer _id)
|
||||
: id_(_id),
|
||||
ctx_(ctx),
|
||||
data_(ctx_->mapping_.size()),
|
||||
geom_(geometry::geometry_empty()),
|
||||
raster_() {}
|
||||
: id_(_id)
|
||||
, ctx_(ctx)
|
||||
, data_(ctx_->mapping_.size())
|
||||
, geom_(geometry::geometry_empty())
|
||||
, raster_()
|
||||
{}
|
||||
|
||||
inline mapnik::value_integer id() const { return id_;}
|
||||
inline void set_id(mapnik::value_integer _id) { id_ = _id;}
|
||||
template <typename T>
|
||||
inline mapnik::value_integer id() const { return id_; }
|
||||
inline void set_id(mapnik::value_integer _id) { id_ = _id; }
|
||||
template<typename T>
|
||||
inline void put(context_type::key_type const& key, T const& val)
|
||||
{
|
||||
put(key, value(val));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
inline void put_new(context_type::key_type const& key, T const& val)
|
||||
{
|
||||
put_new(key, value(val));
|
||||
}
|
||||
|
||||
inline void put(context_type::key_type const& key, value && val)
|
||||
inline void put(context_type::key_type const& key, value&& val)
|
||||
{
|
||||
context_type::map_type::const_iterator itr = ctx_->mapping_.find(key);
|
||||
if (itr != ctx_->mapping_.end()
|
||||
&& itr->second < data_.size())
|
||||
if (itr != ctx_->mapping_.end() && itr->second < data_.size())
|
||||
{
|
||||
data_[itr->second] = std::move(val);
|
||||
}
|
||||
|
@ -136,11 +136,10 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
inline void put_new(context_type::key_type const& key, value && val)
|
||||
inline void put_new(context_type::key_type const& key, value&& val)
|
||||
{
|
||||
context_type::map_type::const_iterator itr = ctx_->mapping_.find(key);
|
||||
if (itr != ctx_->mapping_.end()
|
||||
&& itr->second < data_.size())
|
||||
if (itr != ctx_->mapping_.end() && itr->second < data_.size())
|
||||
{
|
||||
data_[itr->second] = std::move(val);
|
||||
}
|
||||
|
@ -152,10 +151,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
inline bool has_key(context_type::key_type const& key) const
|
||||
{
|
||||
return (ctx_->mapping_.count(key) == 1);
|
||||
}
|
||||
inline bool has_key(context_type::key_type const& key) const { return (ctx_->mapping_.count(key) == 1); }
|
||||
|
||||
inline value_type const& get(context_type::key_type const& key) const
|
||||
{
|
||||
|
@ -173,70 +169,31 @@ public:
|
|||
return default_feature_value;
|
||||
}
|
||||
|
||||
inline std::size_t size() const
|
||||
{
|
||||
return data_.size();
|
||||
}
|
||||
inline std::size_t size() const { return data_.size(); }
|
||||
|
||||
inline cont_type const& get_data() const
|
||||
{
|
||||
return data_;
|
||||
}
|
||||
inline cont_type const& get_data() const { return data_; }
|
||||
|
||||
inline void set_data(cont_type const& data)
|
||||
{
|
||||
data_ = data;
|
||||
}
|
||||
inline void set_data(cont_type const& data) { data_ = data; }
|
||||
|
||||
inline context_ptr context() const
|
||||
{
|
||||
return ctx_;
|
||||
}
|
||||
inline context_ptr context() const { return ctx_; }
|
||||
|
||||
inline void set_geometry(geometry::geometry<double> && geom)
|
||||
{
|
||||
geom_ = std::move(geom);
|
||||
}
|
||||
inline void set_geometry(geometry::geometry<double>&& geom) { geom_ = std::move(geom); }
|
||||
|
||||
inline void set_geometry_copy(geometry::geometry<double> const& geom)
|
||||
{
|
||||
geom_ = geom;
|
||||
}
|
||||
inline void set_geometry_copy(geometry::geometry<double> const& geom) { geom_ = geom; }
|
||||
|
||||
inline geometry::geometry<double> const& get_geometry() const
|
||||
{
|
||||
return geom_;
|
||||
}
|
||||
inline geometry::geometry<double> const& get_geometry() const { return geom_; }
|
||||
|
||||
inline geometry::geometry<double> & get_geometry()
|
||||
{
|
||||
return geom_;
|
||||
}
|
||||
inline geometry::geometry<double>& get_geometry() { return geom_; }
|
||||
|
||||
inline box2d<double> envelope() const
|
||||
{
|
||||
return mapnik::geometry::envelope(geom_);
|
||||
}
|
||||
inline box2d<double> envelope() const { return mapnik::geometry::envelope(geom_); }
|
||||
|
||||
inline raster_ptr const& get_raster() const
|
||||
{
|
||||
return raster_;
|
||||
}
|
||||
inline raster_ptr const& get_raster() const { return raster_; }
|
||||
|
||||
inline void set_raster(raster_ptr const& raster)
|
||||
{
|
||||
raster_ = raster;
|
||||
}
|
||||
inline void set_raster(raster_ptr const& raster) { raster_ = raster; }
|
||||
|
||||
inline feature_kv_iterator begin() const
|
||||
{
|
||||
return feature_kv_iterator(*this,true);
|
||||
}
|
||||
inline feature_kv_iterator begin() const { return feature_kv_iterator(*this, true); }
|
||||
|
||||
inline feature_kv_iterator end() const
|
||||
{
|
||||
return feature_kv_iterator(*this);
|
||||
}
|
||||
inline feature_kv_iterator end() const { return feature_kv_iterator(*this); }
|
||||
|
||||
std::string to_string() const
|
||||
{
|
||||
|
@ -249,11 +206,11 @@ public:
|
|||
{
|
||||
if (data_[kv.second] == mapnik::value_null())
|
||||
{
|
||||
ss << " " << kv.first << ":null" << std::endl;
|
||||
ss << " " << kv.first << ":null" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
ss << " " << kv.first << ":" << data_[kv.second] << std::endl;
|
||||
ss << " " << kv.first << ":" << data_[kv.second] << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -261,7 +218,7 @@ public:
|
|||
return ss.str();
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
mapnik::value_integer id_;
|
||||
context_ptr ctx_;
|
||||
cont_type data_;
|
||||
|
@ -269,8 +226,7 @@ private:
|
|||
raster_ptr raster_;
|
||||
};
|
||||
|
||||
|
||||
inline std::ostream& operator<< (std::ostream & out,feature_impl const& f)
|
||||
inline std::ostream& operator<<(std::ostream& out, feature_impl const& f)
|
||||
{
|
||||
out << f.to_string();
|
||||
return out;
|
||||
|
@ -278,6 +234,6 @@ inline std::ostream& operator<< (std::ostream & out,feature_impl const& f)
|
|||
|
||||
using feature_ptr = std::shared_ptr<feature_impl>;
|
||||
|
||||
}
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_FEATURE_HPP
|
||||
|
|
|
@ -30,17 +30,16 @@
|
|||
// boost
|
||||
//#include <boost/pool/pool_alloc.hpp>
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
namespace mapnik {
|
||||
struct feature_factory
|
||||
{
|
||||
static std::shared_ptr<feature_impl> create (context_ptr const& ctx, mapnik::value_integer fid)
|
||||
static std::shared_ptr<feature_impl> create(context_ptr const& ctx, mapnik::value_integer fid)
|
||||
{
|
||||
//return boost::allocate_shared<feature_impl>(boost::pool_allocator<feature_impl>(),fid);
|
||||
//return boost::allocate_shared<feature_impl>(boost::fast_pool_allocator<feature_impl>(),fid);
|
||||
return std::make_shared<feature_impl>(ctx,fid);
|
||||
// return boost::allocate_shared<feature_impl>(boost::pool_allocator<feature_impl>(),fid);
|
||||
// return boost::allocate_shared<feature_impl>(boost::fast_pool_allocator<feature_impl>(),fid);
|
||||
return std::make_shared<feature_impl>(ctx, fid);
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_FEATURE_FACTORY_HPP
|
||||
|
|
|
@ -45,32 +45,31 @@ namespace mapnik {
|
|||
|
||||
class feature_impl;
|
||||
|
||||
class MAPNIK_DECL feature_kv_iterator :
|
||||
public boost::iterator_facade<feature_kv_iterator,
|
||||
std::tuple<std::string, value> const,
|
||||
boost::forward_traversal_tag>
|
||||
class MAPNIK_DECL feature_kv_iterator : public boost::iterator_facade<feature_kv_iterator,
|
||||
std::tuple<std::string, value> const,
|
||||
boost::forward_traversal_tag>
|
||||
{
|
||||
public:
|
||||
using value_type = std::tuple<std::string,value>;
|
||||
feature_kv_iterator (feature_impl const& f, bool begin = false);
|
||||
private:
|
||||
public:
|
||||
using value_type = std::tuple<std::string, value>;
|
||||
feature_kv_iterator(feature_impl const& f, bool begin = false);
|
||||
|
||||
private:
|
||||
friend class boost::iterator_core_access;
|
||||
void increment();
|
||||
void decrement();
|
||||
void advance(boost::iterator_difference<feature_kv_iterator>::type);
|
||||
bool equal( feature_kv_iterator const& other) const;
|
||||
bool equal(feature_kv_iterator const& other) const;
|
||||
|
||||
value_type const& dereference() const;
|
||||
|
||||
feature_impl const& f_;
|
||||
std::map<std::string,std::size_t>::const_iterator itr_;
|
||||
std::map<std::string, std::size_t>::const_iterator itr_;
|
||||
mutable value_type kv_;
|
||||
|
||||
};
|
||||
|
||||
struct value_not_null
|
||||
{
|
||||
bool operator() (feature_kv_iterator::value_type const& kv) const
|
||||
bool operator()(feature_kv_iterator::value_type const& kv) const
|
||||
{
|
||||
return !util::apply_visitor(mapnik::detail::is_null_visitor(), std::get<1>(kv));
|
||||
}
|
||||
|
@ -78,6 +77,6 @@ struct value_not_null
|
|||
|
||||
using feature_kv_iterator2 = boost::filter_iterator<value_not_null, feature_kv_iterator>;
|
||||
|
||||
}
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_FEATURE_KV_ITERATOR_HPP
|
||||
|
|
|
@ -32,90 +32,65 @@
|
|||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
namespace mapnik {
|
||||
|
||||
class layer_descriptor
|
||||
{
|
||||
public:
|
||||
public:
|
||||
layer_descriptor(std::string const& name, std::string const& encoding)
|
||||
: name_(name),
|
||||
encoding_(encoding),
|
||||
descriptors_(),
|
||||
extra_params_() {}
|
||||
: name_(name)
|
||||
, encoding_(encoding)
|
||||
, descriptors_()
|
||||
, extra_params_()
|
||||
{}
|
||||
|
||||
layer_descriptor(layer_descriptor const& other)
|
||||
: name_(other.name_),
|
||||
encoding_(other.encoding_),
|
||||
descriptors_(other.descriptors_),
|
||||
extra_params_(other.extra_params_) {}
|
||||
: name_(other.name_)
|
||||
, encoding_(other.encoding_)
|
||||
, descriptors_(other.descriptors_)
|
||||
, extra_params_(other.extra_params_)
|
||||
{}
|
||||
|
||||
void set_name(std::string const& name)
|
||||
{
|
||||
name_ = name;
|
||||
}
|
||||
void set_name(std::string const& name) { name_ = name; }
|
||||
|
||||
std::string const& get_name() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
std::string const& get_name() const { return name_; }
|
||||
|
||||
void set_encoding(std::string const& encoding)
|
||||
{
|
||||
encoding_ = encoding;
|
||||
}
|
||||
void set_encoding(std::string const& encoding) { encoding_ = encoding; }
|
||||
|
||||
std::string const& get_encoding() const
|
||||
{
|
||||
return encoding_;
|
||||
}
|
||||
std::string const& get_encoding() const { return encoding_; }
|
||||
|
||||
void add_descriptor(attribute_descriptor const& desc)
|
||||
{
|
||||
descriptors_.push_back(desc);
|
||||
}
|
||||
void add_descriptor(attribute_descriptor const& desc) { descriptors_.push_back(desc); }
|
||||
|
||||
std::vector<attribute_descriptor> const& get_descriptors() const
|
||||
{
|
||||
return descriptors_;
|
||||
}
|
||||
std::vector<attribute_descriptor> const& get_descriptors() const { return descriptors_; }
|
||||
|
||||
std::vector<attribute_descriptor>& get_descriptors()
|
||||
{
|
||||
return descriptors_;
|
||||
}
|
||||
std::vector<attribute_descriptor>& get_descriptors() { return descriptors_; }
|
||||
|
||||
parameters const& get_extra_parameters() const
|
||||
{
|
||||
return extra_params_;
|
||||
}
|
||||
parameters const& get_extra_parameters() const { return extra_params_; }
|
||||
|
||||
parameters& get_extra_parameters()
|
||||
{
|
||||
return extra_params_;
|
||||
}
|
||||
parameters& get_extra_parameters() { return extra_params_; }
|
||||
|
||||
bool has_name(std::string const& name) const
|
||||
{
|
||||
auto result = std::find_if(std::begin(descriptors_), std::end(descriptors_),
|
||||
[&name](attribute_descriptor const& desc) { return name == desc.get_name();});
|
||||
auto result = std::find_if(std::begin(descriptors_),
|
||||
std::end(descriptors_),
|
||||
[&name](attribute_descriptor const& desc) { return name == desc.get_name(); });
|
||||
return result != std::end(descriptors_);
|
||||
}
|
||||
void order_by_name()
|
||||
{
|
||||
std::sort(std::begin(descriptors_), std::end(descriptors_),
|
||||
[](attribute_descriptor const& d0, attribute_descriptor const& d1)
|
||||
{
|
||||
return d0.get_name() < d1.get_name();
|
||||
});
|
||||
std::sort(
|
||||
std::begin(descriptors_),
|
||||
std::end(descriptors_),
|
||||
[](attribute_descriptor const& d0, attribute_descriptor const& d1) { return d0.get_name() < d1.get_name(); });
|
||||
}
|
||||
private:
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
std::string encoding_;
|
||||
std::vector<attribute_descriptor> descriptors_;
|
||||
parameters extra_params_;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_FEATURE_LAYER_DESC_HPP
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue