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
|
// stl
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cmath> // log10, round
|
#include <cmath> // log10, round
|
||||||
#include <cstdio> // snprintf
|
#include <cstdio> // snprintf
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -22,36 +22,28 @@
|
||||||
|
|
||||||
namespace benchmark {
|
namespace benchmark {
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
using milliseconds = std::chrono::duration<T, std::milli>;
|
using milliseconds = std::chrono::duration<T, std::milli>;
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
using seconds = std::chrono::duration<T>;
|
using seconds = std::chrono::duration<T>;
|
||||||
|
|
||||||
class test_case
|
class test_case
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
mapnik::parameters params_;
|
mapnik::parameters params_;
|
||||||
std::size_t threads_;
|
std::size_t threads_;
|
||||||
std::size_t iterations_;
|
std::size_t iterations_;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
test_case(mapnik::parameters const& params)
|
test_case(mapnik::parameters const& params)
|
||||||
: params_(params),
|
: params_(params)
|
||||||
threads_(mapnik::safe_cast<std::size_t>(*params.get<mapnik::value_integer>("threads", 0))),
|
, 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)))
|
, iterations_(mapnik::safe_cast<std::size_t>(*params.get<mapnik::value_integer>("iterations", 0)))
|
||||||
{}
|
{}
|
||||||
std::size_t threads() const
|
std::size_t threads() const { return threads_; }
|
||||||
{
|
std::size_t iterations() const { return iterations_; }
|
||||||
return threads_;
|
mapnik::parameters const& params() const { return params_; }
|
||||||
}
|
|
||||||
std::size_t iterations() const
|
|
||||||
{
|
|
||||||
return iterations_;
|
|
||||||
}
|
|
||||||
mapnik::parameters const& params() const
|
|
||||||
{
|
|
||||||
return params_;
|
|
||||||
}
|
|
||||||
virtual bool validate() const = 0;
|
virtual bool validate() const = 0;
|
||||||
virtual bool operator()() const = 0;
|
virtual bool operator()() const = 0;
|
||||||
};
|
};
|
||||||
|
@ -59,21 +51,25 @@ public:
|
||||||
// gathers --long-option values in 'params';
|
// gathers --long-option values in 'params';
|
||||||
// returns the index of the first non-option argument,
|
// returns the index of the first non-option argument,
|
||||||
// or negated index of an ill-formed 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];
|
const char* opt = argv[i];
|
||||||
if (opt[0] != '-') {
|
if (opt[0] != '-')
|
||||||
|
{
|
||||||
// non-option argument, return its index
|
// non-option argument, return its index
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
if (opt[1] != '-') {
|
if (opt[1] != '-')
|
||||||
|
{
|
||||||
// we only accept --long-options, but instead of throwing,
|
// we only accept --long-options, but instead of throwing,
|
||||||
// just issue a warning and let the caller decide what to do
|
// just issue a warning and let the caller decide what to do
|
||||||
std::clog << argv[0] << ": invalid option '" << opt << "'\n";
|
std::clog << argv[0] << ": invalid option '" << opt << "'\n";
|
||||||
return -i; // negative means ill-formed option #i
|
return -i; // negative means ill-formed option #i
|
||||||
}
|
}
|
||||||
if (opt[2] == '\0') {
|
if (opt[2] == '\0')
|
||||||
|
{
|
||||||
// option-list terminator '--'
|
// option-list terminator '--'
|
||||||
return i + 1;
|
return i + 1;
|
||||||
}
|
}
|
||||||
|
@ -81,15 +77,18 @@ inline int parse_args(int argc, char** argv, mapnik::parameters & params)
|
||||||
// take option name without the leading '--'
|
// take option name without the leading '--'
|
||||||
std::string key(opt + 2);
|
std::string key(opt + 2);
|
||||||
size_t eq = key.find('=');
|
size_t eq = key.find('=');
|
||||||
if (eq != std::string::npos) {
|
if (eq != std::string::npos)
|
||||||
|
{
|
||||||
// one-argument form '--foo=bar'
|
// one-argument form '--foo=bar'
|
||||||
params[key.substr(0, eq)] = key.substr(eq + 1);
|
params[key.substr(0, eq)] = key.substr(eq + 1);
|
||||||
}
|
}
|
||||||
else if (i + 1 < argc) {
|
else if (i + 1 < argc)
|
||||||
|
{
|
||||||
// two-argument form '--foo' 'bar'
|
// two-argument form '--foo' 'bar'
|
||||||
params[key] = std::string(argv[++i]);
|
params[key] = std::string(argv[++i]);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
// missing second argument
|
// missing second argument
|
||||||
std::clog << argv[0] << ": missing option '" << opt << "' value\n";
|
std::clog << argv[0] << ": missing option '" << opt << "' value\n";
|
||||||
return -i; // negative means ill-formed option #i
|
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)
|
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")
|
if (*severity == "debug")
|
||||||
mapnik::logger::set_severity(mapnik::logger::debug);
|
mapnik::logger::set_severity(mapnik::logger::debug);
|
||||||
else if (*severity == "warn")
|
else if (*severity == "warn")
|
||||||
|
@ -110,37 +110,35 @@ inline void handle_common_args(mapnik::parameters const& params)
|
||||||
else if (*severity == "none")
|
else if (*severity == "none")
|
||||||
mapnik::logger::set_severity(mapnik::logger::none);
|
mapnik::logger::set_severity(mapnik::logger::none);
|
||||||
else
|
else
|
||||||
std::clog << "ignoring option --log='" << *severity
|
std::clog << "ignoring option --log='" << *severity << "' (allowed values are: debug, warn, error, none)\n";
|
||||||
<< "' (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);
|
int res = parse_args(argc, argv, params);
|
||||||
handle_common_args(params);
|
handle_common_args(params);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define BENCHMARK(test_class,name) \
|
#define BENCHMARK(test_class, name) \
|
||||||
int main(int argc, char** argv) \
|
int main(int argc, char** argv) \
|
||||||
{ \
|
{ \
|
||||||
try \
|
try \
|
||||||
{ \
|
{ \
|
||||||
mapnik::parameters params; \
|
mapnik::parameters params; \
|
||||||
benchmark::handle_args(argc,argv,params); \
|
benchmark::handle_args(argc, argv, params); \
|
||||||
test_class test_runner(params); \
|
test_class test_runner(params); \
|
||||||
auto result = run(test_runner,name); \
|
auto result = run(test_runner, name); \
|
||||||
testing::run_cleanup(); \
|
testing::run_cleanup(); \
|
||||||
return result; \
|
return result; \
|
||||||
} \
|
} catch (std::exception const& ex) \
|
||||||
catch (std::exception const& ex) \
|
{ \
|
||||||
{ \
|
std::clog << ex.what() << "\n"; \
|
||||||
std::clog << ex.what() << "\n"; \
|
testing::run_cleanup(); \
|
||||||
testing::run_cleanup(); \
|
return -1; \
|
||||||
return -1; \
|
} \
|
||||||
} \
|
}
|
||||||
} \
|
|
||||||
|
|
||||||
struct big_number_fmt
|
struct big_number_fmt
|
||||||
{
|
{
|
||||||
|
@ -149,7 +147,9 @@ struct big_number_fmt
|
||||||
const char* u;
|
const char* u;
|
||||||
|
|
||||||
big_number_fmt(int width, double value, int base = 1000)
|
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";
|
static const char* suffixes = "\0\0k\0M\0G\0T\0P\0E\0Z\0Y\0\0";
|
||||||
u = suffixes;
|
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)
|
int run(T const& test_runner, std::string const& name)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -196,8 +196,7 @@ int run(T const& test_runner, std::string const& name)
|
||||||
std::mutex mtx_ready;
|
std::mutex mtx_ready;
|
||||||
std::unique_lock<std::mutex> lock_ready(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
|
// workers will wait on this mutex until the main thread
|
||||||
// constructs all of them and starts measuring time
|
// constructs all of them and starts measuring time
|
||||||
std::unique_lock<std::mutex> my_lock(mtx_ready);
|
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;
|
std::vector<std::thread> tg;
|
||||||
tg.reserve(num_threads);
|
tg.reserve(num_threads);
|
||||||
for (auto i = num_threads; i-- > 0; )
|
for (auto i = num_threads; i-- > 0;)
|
||||||
{
|
{
|
||||||
tg.emplace_back(stub, test_runner);
|
tg.emplace_back(stub, test_runner);
|
||||||
}
|
}
|
||||||
start = std::chrono::high_resolution_clock::now();
|
start = std::chrono::high_resolution_clock::now();
|
||||||
lock_ready.unlock();
|
lock_ready.unlock();
|
||||||
// wait for all workers to finish
|
// wait for all workers to finish
|
||||||
for (auto & t : tg)
|
for (auto& t : tg)
|
||||||
{
|
{
|
||||||
if (t.joinable())
|
if (t.joinable())
|
||||||
t.join();
|
t.join();
|
||||||
|
@ -228,7 +227,8 @@ int run(T const& test_runner, std::string const& name)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
start = std::chrono::high_resolution_clock::now();
|
start = std::chrono::high_resolution_clock::now();
|
||||||
do {
|
do
|
||||||
|
{
|
||||||
test_runner();
|
test_runner();
|
||||||
elapsed = std::chrono::high_resolution_clock::now() - start;
|
elapsed = std::chrono::high_resolution_clock::now() - start;
|
||||||
total_iters += num_iters;
|
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::left << std::setw(43) << name;
|
||||||
std::clog << std::resetiosflags(std::ios::adjustfield);
|
std::clog << std::resetiosflags(std::ios::adjustfield);
|
||||||
if (num_threads > 0) {
|
if (num_threads > 0)
|
||||||
std::clog << ' ' << std::setw(3) << num_threads
|
{
|
||||||
<< " worker" << (num_threads > 1 ? "s" : " ");
|
std::clog << ' ' << std::setw(3) << num_threads << " worker" << (num_threads > 1 ? "s" : " ");
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
std::clog << " main thread";
|
std::clog << " main thread";
|
||||||
}
|
}
|
||||||
std::snprintf(msg, sizeof(msg),
|
std::snprintf(msg,
|
||||||
" %*.0f%s iters %6.0f milliseconds %*.0f%s i/t/s\n",
|
sizeof(msg),
|
||||||
itersf.w, itersf.v, itersf.u, dur_total,
|
" %*.0f%s iters %6.0f milliseconds %*.0f%s i/t/s\n",
|
||||||
ips.w, ips.v, ips.u);
|
itersf.w,
|
||||||
|
itersf.v,
|
||||||
|
itersf.u,
|
||||||
|
dur_total,
|
||||||
|
ips.w,
|
||||||
|
ips.v,
|
||||||
|
ips.u);
|
||||||
std::clog << msg;
|
std::clog << msg;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
} catch (std::exception const& ex)
|
||||||
catch (std::exception const& ex)
|
|
||||||
{
|
{
|
||||||
std::clog << "test runner did not complete: " << ex.what() << "\n";
|
std::clog << "test runner did not complete: " << ex.what() << "\n";
|
||||||
return 4;
|
return 4;
|
||||||
|
@ -267,18 +273,15 @@ int run(T const& test_runner, std::string const& name)
|
||||||
struct sequencer
|
struct sequencer
|
||||||
{
|
{
|
||||||
sequencer(int argc, char** argv)
|
sequencer(int argc, char** argv)
|
||||||
: exit_code_(0)
|
: exit_code_(0)
|
||||||
{
|
{
|
||||||
benchmark::handle_args(argc, argv, params_);
|
benchmark::handle_args(argc, argv, params_);
|
||||||
}
|
}
|
||||||
|
|
||||||
int done() const
|
int done() const { return exit_code_; }
|
||||||
{
|
|
||||||
return exit_code_;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Test, typename... Args>
|
template<typename Test, typename... Args>
|
||||||
sequencer & run(std::string const& name, Args && ...args)
|
sequencer& run(std::string const& name, Args&&... args)
|
||||||
{
|
{
|
||||||
// Test instance lifetime is confined to this function
|
// Test instance lifetime is confined to this function
|
||||||
Test test_runner(params_, std::forward<Args>(args)...);
|
Test test_runner(params_, std::forward<Args>(args)...);
|
||||||
|
@ -287,11 +290,11 @@ struct sequencer
|
||||||
return *this; // allow chaining calls
|
return *this; // allow chaining calls
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
mapnik::parameters params_;
|
mapnik::parameters params_;
|
||||||
int exit_code_;
|
int exit_code_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace benchmark
|
||||||
|
|
||||||
#endif // MAPNIK_BENCH_FRAMEWORK_HPP
|
#endif // MAPNIK_BENCH_FRAMEWORK_HPP
|
||||||
|
|
|
@ -5,32 +5,31 @@
|
||||||
#include <mapnik/image_util.hpp>
|
#include <mapnik/image_util.hpp>
|
||||||
#include <mapnik/image_reader.hpp>
|
#include <mapnik/image_reader.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace benchmark {
|
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"));
|
throw mapnik::image_reader_exception("Failed to load: " + dest_fn);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
#endif // MAPNIK_COMPARE_IMAGES_HPP
|
||||||
|
|
|
@ -2,20 +2,23 @@
|
||||||
|
|
||||||
#include <mapnik/util/math.hpp>
|
#include <mapnik/util/math.hpp>
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
struct bench_func : benchmark::test_case
|
struct bench_func : benchmark::test_case
|
||||||
{
|
{
|
||||||
T (* const func_)(T);
|
T (*const func_)(T);
|
||||||
T const value_;
|
T const value_;
|
||||||
|
|
||||||
bench_func(mapnik::parameters const& params, T (*func)(T), T 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 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_);
|
func_(value_);
|
||||||
}
|
}
|
||||||
|
@ -23,47 +26,46 @@ struct bench_func : benchmark::test_case
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#define BENCH_FUNC1(func, value) \
|
#define BENCH_FUNC1(func, value) run<bench_func<double>>(#func "(" #value ")", func, value)
|
||||||
run<bench_func<double>>(#func "(" #value ")", func, value)
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
return benchmark::sequencer(argc, argv)
|
return benchmark::sequencer(argc, argv)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +3)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, +3)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +6)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, +6)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +9)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, +9)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +12)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, +12)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +15)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, +15)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +20)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, +20)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +30)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, +30)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +40)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, +40)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +50)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, +50)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +70)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, +70)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +90)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, +90)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +110)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, +110)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +130)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, +130)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +157)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, +157)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +209)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, +209)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +314)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, +314)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +628)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, +628)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, +942)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, +942)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -3)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, -3)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -6)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, -6)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -9)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, -9)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -12)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, -12)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -15)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, -15)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -20)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, -20)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -30)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, -30)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -40)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, -40)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -50)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, -50)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -70)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, -70)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -90)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, -90)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -110)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, -110)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -130)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, -130)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -157)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, -157)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -209)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, -209)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -314)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, -314)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -628)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, -628)
|
||||||
.BENCH_FUNC1(mapnik::util::normalize_angle, -942)
|
.BENCH_FUNC1(mapnik::util::normalize_angle, -942)
|
||||||
.done();
|
.done();
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,15 +14,19 @@
|
||||||
|
|
||||||
#define FULL_ZERO_CHECK
|
#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
|
#ifdef FULL_ZERO_CHECK
|
||||||
for (std::size_t i=0;i<size;++i) {
|
for (std::size_t i = 0; i < size; ++i)
|
||||||
if (data[i] != 0) {
|
{
|
||||||
|
if (data[i] != 0)
|
||||||
|
{
|
||||||
throw std::runtime_error("found non zero value");
|
throw std::runtime_error("found non zero value");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (data[0] != 0) {
|
if (data[0] != 0)
|
||||||
|
{
|
||||||
throw std::runtime_error("found non zero value");
|
throw std::runtime_error("found non zero value");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -30,274 +34,262 @@ inline void ensure_zero(uint8_t * data, uint32_t size) {
|
||||||
|
|
||||||
class test1 : public benchmark::test_case
|
class test1 : public benchmark::test_case
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
uint32_t size_;
|
uint32_t size_;
|
||||||
std::vector<uint8_t> array_;
|
std::vector<uint8_t> array_;
|
||||||
test1(mapnik::parameters const& params)
|
test1(mapnik::parameters const& params)
|
||||||
: test_case(params),
|
: test_case(params)
|
||||||
size_(*params.get<mapnik::value_integer>("size",256*256)),
|
, size_(*params.get<mapnik::value_integer>("size", 256 * 256))
|
||||||
array_(size_,0) { }
|
, array_(size_, 0)
|
||||||
bool validate() const
|
{}
|
||||||
{
|
bool validate() const { return true; }
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
for (std::size_t i=0;i<iterations_;++i) {
|
for (std::size_t i = 0; i < iterations_; ++i)
|
||||||
// NOTE: sizeof(uint8_t) == 1
|
{
|
||||||
uint8_t *data = (uint8_t *)malloc(sizeof(uint8_t)*size_);
|
// NOTE: sizeof(uint8_t) == 1
|
||||||
memcpy(data, &array_[0], size_);
|
uint8_t* data = (uint8_t*)malloc(sizeof(uint8_t) * size_);
|
||||||
ensure_zero(data,size_);
|
memcpy(data, &array_[0], size_);
|
||||||
free(data);
|
ensure_zero(data, size_);
|
||||||
}
|
free(data);
|
||||||
return true;
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class test1b : public benchmark::test_case
|
class test1b : public benchmark::test_case
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
uint32_t size_;
|
uint32_t size_;
|
||||||
std::vector<uint8_t> array_;
|
std::vector<uint8_t> array_;
|
||||||
test1b(mapnik::parameters const& params)
|
test1b(mapnik::parameters const& params)
|
||||||
: test_case(params),
|
: test_case(params)
|
||||||
size_(*params.get<mapnik::value_integer>("size",256*256)),
|
, size_(*params.get<mapnik::value_integer>("size", 256 * 256))
|
||||||
array_(size_,0) { }
|
, array_(size_, 0)
|
||||||
bool validate() const
|
{}
|
||||||
{
|
bool validate() const { return true; }
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
for (std::size_t i=0;i<iterations_;++i) {
|
for (std::size_t i = 0; i < iterations_; ++i)
|
||||||
// NOTE: sizeof(uint8_t) == 1
|
{
|
||||||
uint8_t *data = (uint8_t *)malloc(sizeof(uint8_t)*size_);
|
// NOTE: sizeof(uint8_t) == 1
|
||||||
memset(data, 0, sizeof(uint8_t)*size_);
|
uint8_t* data = (uint8_t*)malloc(sizeof(uint8_t) * size_);
|
||||||
ensure_zero(data,size_);
|
memset(data, 0, sizeof(uint8_t) * size_);
|
||||||
free(data);
|
ensure_zero(data, size_);
|
||||||
}
|
free(data);
|
||||||
return true;
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class test1c : public benchmark::test_case
|
class test1c : public benchmark::test_case
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
uint32_t size_;
|
uint32_t size_;
|
||||||
std::vector<uint8_t> array_;
|
std::vector<uint8_t> array_;
|
||||||
test1c(mapnik::parameters const& params)
|
test1c(mapnik::parameters const& params)
|
||||||
: test_case(params),
|
: test_case(params)
|
||||||
size_(*params.get<mapnik::value_integer>("size",256*256)),
|
, size_(*params.get<mapnik::value_integer>("size", 256 * 256))
|
||||||
array_(size_,0) { }
|
, array_(size_, 0)
|
||||||
bool validate() const
|
{}
|
||||||
{
|
bool validate() const { return true; }
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
for (std::size_t i=0;i<iterations_;++i) {
|
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);
|
uint8_t* data = static_cast<uint8_t*>(::operator new(sizeof(uint8_t) * size_));
|
||||||
ensure_zero(data,size_);
|
std::fill(data, data + size_, 0);
|
||||||
::operator delete(data);
|
ensure_zero(data, size_);
|
||||||
}
|
::operator delete(data);
|
||||||
return true;
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class test2 : public benchmark::test_case
|
class test2 : public benchmark::test_case
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
uint32_t size_;
|
uint32_t size_;
|
||||||
std::vector<uint8_t> array_;
|
std::vector<uint8_t> array_;
|
||||||
test2(mapnik::parameters const& params)
|
test2(mapnik::parameters const& params)
|
||||||
: test_case(params),
|
: test_case(params)
|
||||||
size_(*params.get<mapnik::value_integer>("size",256*256)),
|
, size_(*params.get<mapnik::value_integer>("size", 256 * 256))
|
||||||
array_(size_,0) { }
|
, array_(size_, 0)
|
||||||
bool validate() const
|
{}
|
||||||
{
|
bool validate() const { return true; }
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
for (std::size_t i=0;i<iterations_;++i) {
|
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_);
|
uint8_t* data = static_cast<uint8_t*>(::operator new(sizeof(uint8_t) * size_));
|
||||||
ensure_zero(data,size_);
|
memcpy(data, &array_[0], size_);
|
||||||
::operator delete(data),data=0;
|
ensure_zero(data, size_);
|
||||||
}
|
::operator delete(data), data = 0;
|
||||||
return true;
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class test3 : public benchmark::test_case
|
class test3 : public benchmark::test_case
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
uint32_t size_;
|
uint32_t size_;
|
||||||
std::vector<uint8_t> array_;
|
std::vector<uint8_t> array_;
|
||||||
test3(mapnik::parameters const& params)
|
test3(mapnik::parameters const& params)
|
||||||
: test_case(params),
|
: test_case(params)
|
||||||
size_(*params.get<mapnik::value_integer>("size",256*256)),
|
, size_(*params.get<mapnik::value_integer>("size", 256 * 256))
|
||||||
array_(size_,0) { }
|
, array_(size_, 0)
|
||||||
bool validate() const
|
{}
|
||||||
{
|
bool validate() const { return true; }
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
for (std::size_t i=0;i<iterations_;++i) {
|
for (std::size_t i = 0; i < iterations_; ++i)
|
||||||
std::vector<uint8_t> data(size_);
|
{
|
||||||
ensure_zero(&data[0],data.size());
|
std::vector<uint8_t> data(size_);
|
||||||
}
|
ensure_zero(&data[0], data.size());
|
||||||
return true;
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class test3b : public benchmark::test_case
|
class test3b : public benchmark::test_case
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
uint32_t size_;
|
uint32_t size_;
|
||||||
std::vector<uint8_t> array_;
|
std::vector<uint8_t> array_;
|
||||||
test3b(mapnik::parameters const& params)
|
test3b(mapnik::parameters const& params)
|
||||||
: test_case(params),
|
: test_case(params)
|
||||||
size_(*params.get<mapnik::value_integer>("size",256*256)),
|
, size_(*params.get<mapnik::value_integer>("size", 256 * 256))
|
||||||
array_(size_,0) { }
|
, array_(size_, 0)
|
||||||
bool validate() const
|
{}
|
||||||
{
|
bool validate() const { return true; }
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
for (std::size_t i=0;i<iterations_;++i) {
|
for (std::size_t i = 0; i < iterations_; ++i)
|
||||||
std::vector<uint8_t> data(0);
|
{
|
||||||
data.resize(size_,0);
|
std::vector<uint8_t> data(0);
|
||||||
ensure_zero(&data[0],data.size());
|
data.resize(size_, 0);
|
||||||
}
|
ensure_zero(&data[0], data.size());
|
||||||
return true;
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class test3c : public benchmark::test_case
|
class test3c : public benchmark::test_case
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
uint32_t size_;
|
uint32_t size_;
|
||||||
std::vector<uint8_t> array_;
|
std::vector<uint8_t> array_;
|
||||||
test3c(mapnik::parameters const& params)
|
test3c(mapnik::parameters const& params)
|
||||||
: test_case(params),
|
: test_case(params)
|
||||||
size_(*params.get<mapnik::value_integer>("size",256*256)),
|
, size_(*params.get<mapnik::value_integer>("size", 256 * 256))
|
||||||
array_(size_,0) { }
|
, array_(size_, 0)
|
||||||
bool validate() const
|
{}
|
||||||
{
|
bool validate() const { return true; }
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
for (std::size_t i=0;i<iterations_;++i) {
|
for (std::size_t i = 0; i < iterations_; ++i)
|
||||||
std::vector<uint8_t> data(0);
|
{
|
||||||
data.assign(size_,0);
|
std::vector<uint8_t> data(0);
|
||||||
ensure_zero(&data[0],data.size());
|
data.assign(size_, 0);
|
||||||
}
|
ensure_zero(&data[0], data.size());
|
||||||
return true;
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class test3d : public benchmark::test_case
|
class test3d : public benchmark::test_case
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
uint32_t size_;
|
uint32_t size_;
|
||||||
std::vector<uint8_t> array_;
|
std::vector<uint8_t> array_;
|
||||||
test3d(mapnik::parameters const& params)
|
test3d(mapnik::parameters const& params)
|
||||||
: test_case(params),
|
: test_case(params)
|
||||||
size_(*params.get<mapnik::value_integer>("size",256*256)),
|
, size_(*params.get<mapnik::value_integer>("size", 256 * 256))
|
||||||
array_(size_,0) { }
|
, array_(size_, 0)
|
||||||
bool validate() const
|
{}
|
||||||
{
|
bool validate() const { return true; }
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
for (std::size_t i=0;i<iterations_;++i) {
|
for (std::size_t i = 0; i < iterations_; ++i)
|
||||||
std::deque<uint8_t> data(size_);
|
{
|
||||||
for (std::size_t i=0;i<size_;++i) {
|
std::deque<uint8_t> data(size_);
|
||||||
if (data[i] != 0) {
|
for (std::size_t i = 0; i < size_; ++i)
|
||||||
throw std::runtime_error("found non zero value");
|
{
|
||||||
}
|
if (data[i] != 0)
|
||||||
}
|
{
|
||||||
}
|
throw std::runtime_error("found non zero value");
|
||||||
return true;
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class test4 : public benchmark::test_case
|
class test4 : public benchmark::test_case
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
uint32_t size_;
|
uint32_t size_;
|
||||||
std::vector<uint8_t> array_;
|
std::vector<uint8_t> array_;
|
||||||
test4(mapnik::parameters const& params)
|
test4(mapnik::parameters const& params)
|
||||||
: test_case(params),
|
: test_case(params)
|
||||||
size_(*params.get<mapnik::value_integer>("size",256*256)),
|
, size_(*params.get<mapnik::value_integer>("size", 256 * 256))
|
||||||
array_(size_,0) { }
|
, array_(size_, 0)
|
||||||
bool validate() const
|
{}
|
||||||
{
|
bool validate() const { return true; }
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
for (std::size_t i=0;i<iterations_;++i) {
|
for (std::size_t i = 0; i < iterations_; ++i)
|
||||||
uint8_t *data = (uint8_t *)calloc(size_,sizeof(uint8_t));
|
{
|
||||||
ensure_zero(data,size_);
|
uint8_t* data = (uint8_t*)calloc(size_, sizeof(uint8_t));
|
||||||
free(data);
|
ensure_zero(data, size_);
|
||||||
}
|
free(data);
|
||||||
return true;
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class test5 : public benchmark::test_case
|
class test5 : public benchmark::test_case
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
uint32_t size_;
|
uint32_t size_;
|
||||||
std::vector<uint8_t> array_;
|
std::vector<uint8_t> array_;
|
||||||
test5(mapnik::parameters const& params)
|
test5(mapnik::parameters const& params)
|
||||||
: test_case(params),
|
: test_case(params)
|
||||||
size_(*params.get<mapnik::value_integer>("size",256*256)),
|
, size_(*params.get<mapnik::value_integer>("size", 256 * 256))
|
||||||
array_(size_,0) { }
|
, array_(size_, 0)
|
||||||
bool validate() const
|
{}
|
||||||
{
|
bool validate() const { return true; }
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
for (std::size_t i=0;i<iterations_;++i) {
|
for (std::size_t i = 0; i < iterations_; ++i)
|
||||||
std::string data(array_.begin(),array_.end());
|
{
|
||||||
ensure_zero((uint8_t *)&data[0],size_);
|
std::string data(array_.begin(), array_.end());
|
||||||
}
|
ensure_zero((uint8_t*)&data[0], size_);
|
||||||
return true;
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class test5b : public benchmark::test_case
|
class test5b : public benchmark::test_case
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
uint32_t size_;
|
uint32_t size_;
|
||||||
std::vector<char> array_;
|
std::vector<char> array_;
|
||||||
test5b(mapnik::parameters const& params)
|
test5b(mapnik::parameters const& params)
|
||||||
: test_case(params),
|
: test_case(params)
|
||||||
size_(*params.get<mapnik::value_integer>("size",256*256)),
|
, size_(*params.get<mapnik::value_integer>("size", 256 * 256))
|
||||||
array_(size_,0) { }
|
, array_(size_, 0)
|
||||||
bool validate() const
|
{}
|
||||||
{
|
bool validate() const { return true; }
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
for (std::size_t i=0;i<iterations_;++i) {
|
for (std::size_t i = 0; i < iterations_; ++i)
|
||||||
std::string data(&array_[0],array_.size());
|
{
|
||||||
ensure_zero((uint8_t *)&data[0],size_);
|
std::string data(&array_[0], array_.size());
|
||||||
}
|
ensure_zero((uint8_t*)&data[0], size_);
|
||||||
return true;
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -308,24 +300,23 @@ public:
|
||||||
|
|
||||||
class test6 : public benchmark::test_case
|
class test6 : public benchmark::test_case
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
uint32_t size_;
|
uint32_t size_;
|
||||||
std::vector<uint8_t> array_;
|
std::vector<uint8_t> array_;
|
||||||
test6(mapnik::parameters const& params)
|
test6(mapnik::parameters const& params)
|
||||||
: test_case(params),
|
: test_case(params)
|
||||||
size_(*params.get<mapnik::value_integer>("size",256*256)),
|
, size_(*params.get<mapnik::value_integer>("size", 256 * 256))
|
||||||
array_(size_,0) { }
|
, array_(size_, 0)
|
||||||
bool validate() const
|
{}
|
||||||
{
|
bool validate() const { return true; }
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
for (std::size_t i=0;i<iterations_;++i) {
|
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_);
|
std::valarray<uint8_t> data(static_cast<uint8_t>(0), static_cast<size_t>(size_));
|
||||||
}
|
ensure_zero(&data[0], size_);
|
||||||
return true;
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -335,24 +326,23 @@ public:
|
||||||
|
|
||||||
class test7 : public benchmark::test_case
|
class test7 : public benchmark::test_case
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
uint32_t size_;
|
uint32_t size_;
|
||||||
std::vector<uint8_t> array_;
|
std::vector<uint8_t> array_;
|
||||||
test7(mapnik::parameters const& params)
|
test7(mapnik::parameters const& params)
|
||||||
: test_case(params),
|
: test_case(params)
|
||||||
size_(*params.get<mapnik::value_integer>("size",256*256)),
|
, size_(*params.get<mapnik::value_integer>("size", 256 * 256))
|
||||||
array_(size_,0) { }
|
, array_(size_, 0)
|
||||||
bool validate() const
|
{}
|
||||||
{
|
bool validate() const { return true; }
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
for (std::size_t i=0;i<iterations_;++i) {
|
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_);
|
boost::container::static_vector<uint8_t, 256 * 256> data(size_, 0);
|
||||||
}
|
ensure_zero(&data[0], size_);
|
||||||
return true;
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -360,20 +350,20 @@ public:
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
return benchmark::sequencer(argc, argv)
|
return benchmark::sequencer(argc, argv)
|
||||||
.run<test4>("calloc")
|
.run<test4>("calloc")
|
||||||
.run<test1>("malloc/memcpy")
|
.run<test1>("malloc/memcpy")
|
||||||
.run<test1b>("malloc/memset")
|
.run<test1b>("malloc/memset")
|
||||||
.run<test1c>("operator new/std::fill")
|
.run<test1c>("operator new/std::fill")
|
||||||
.run<test2>("operator new/memcpy")
|
.run<test2>("operator new/memcpy")
|
||||||
.run<test3>("vector(N)")
|
.run<test3>("vector(N)")
|
||||||
.run<test3b>("vector/resize")
|
.run<test3b>("vector/resize")
|
||||||
.run<test3c>("vector/assign")
|
.run<test3c>("vector/assign")
|
||||||
.run<test3d>("deque(N)")
|
.run<test3d>("deque(N)")
|
||||||
.run<test5>("std::string range")
|
.run<test5>("std::string range")
|
||||||
.run<test5b>("std::string &[0]")
|
.run<test5b>("std::string &[0]")
|
||||||
.run<test6>("valarray")
|
.run<test6>("valarray")
|
||||||
#if BOOST_VERSION >= 105400
|
#if BOOST_VERSION >= 105400
|
||||||
.run<test7>("static_vector")
|
.run<test7>("static_vector")
|
||||||
#endif
|
#endif
|
||||||
.done();
|
.done();
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,12 @@
|
||||||
class test : public benchmark::test_case
|
class test : public benchmark::test_case
|
||||||
{
|
{
|
||||||
std::string expr_;
|
std::string expr_;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
test(mapnik::parameters const& params)
|
test(mapnik::parameters const& params)
|
||||||
: test_case(params),
|
: test_case(params)
|
||||||
expr_("((([mapnik::geometry_type]=2) and ([oneway]=1)) and ([class]='path'))") {}
|
, expr_("((([mapnik::geometry_type]=2) and ([oneway]=1)) and ([class]='path'))")
|
||||||
|
{}
|
||||||
bool validate() const
|
bool validate() const
|
||||||
{
|
{
|
||||||
mapnik::expression_ptr expr = mapnik::parse_expression(expr_);
|
mapnik::expression_ptr expr = mapnik::parse_expression(expr_);
|
||||||
|
@ -18,24 +20,24 @@ public:
|
||||||
bool ret = (result == expr_);
|
bool ret = (result == expr_);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
{
|
{
|
||||||
std::clog << result << " != " << expr_ << "\n";
|
std::clog << result << " != " << expr_ << "\n";
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
for (std::size_t i=0;i<iterations_;++i) {
|
for (std::size_t i = 0; i < iterations_; ++i)
|
||||||
mapnik::expression_ptr expr = mapnik::parse_expression(expr_);
|
{
|
||||||
}
|
mapnik::expression_ptr expr = mapnik::parse_expression(expr_);
|
||||||
return true;
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
mapnik::parameters params;
|
mapnik::parameters params;
|
||||||
benchmark::handle_args(argc,argv,params);
|
benchmark::handle_args(argc, argv, params);
|
||||||
test test_runner(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
|
class test : public benchmark::test_case
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
test(mapnik::parameters const& params)
|
test(mapnik::parameters const& params)
|
||||||
: test_case(params) {}
|
: test_case(params)
|
||||||
|
{}
|
||||||
bool validate() const
|
bool validate() const
|
||||||
{
|
{
|
||||||
std::size_t count = 0;
|
std::size_t count = 0;
|
||||||
|
@ -22,14 +23,15 @@ public:
|
||||||
font_cache,
|
font_cache,
|
||||||
mapnik::freetype_engine::get_mapping(),
|
mapnik::freetype_engine::get_mapping(),
|
||||||
mapnik::freetype_engine::get_cache());
|
mapnik::freetype_engine::get_cache());
|
||||||
if (f) ++count;
|
if (f)
|
||||||
|
++count;
|
||||||
}
|
}
|
||||||
return count == expected_count;
|
return count == expected_count;
|
||||||
}
|
}
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
std::size_t expected_count = mapnik::freetype_engine::face_names().size();
|
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;
|
std::size_t count = 0;
|
||||||
mapnik::freetype_engine::font_file_mapping_type font_file_mapping;
|
mapnik::freetype_engine::font_file_mapping_type font_file_mapping;
|
||||||
|
@ -43,9 +45,11 @@ public:
|
||||||
font_cache,
|
font_cache,
|
||||||
mapnik::freetype_engine::get_mapping(),
|
mapnik::freetype_engine::get_mapping(),
|
||||||
mapnik::freetype_engine::get_cache());
|
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";
|
std::clog << "warning: face creation not working as expected\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,14 +60,14 @@ public:
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
mapnik::parameters params;
|
mapnik::parameters params;
|
||||||
benchmark::handle_args(argc,argv,params);
|
benchmark::handle_args(argc, argv, params);
|
||||||
bool success = mapnik::freetype_engine::register_fonts("./fonts", true);
|
bool success = mapnik::freetype_engine::register_fonts("./fonts", true);
|
||||||
if (!success) {
|
if (!success)
|
||||||
std::clog << "warning, did not register any new fonts!\n";
|
{
|
||||||
return -1;
|
std::clog << "warning, did not register any new fonts!\n";
|
||||||
}
|
return -1;
|
||||||
|
}
|
||||||
std::size_t face_count = mapnik::freetype_engine::face_names().size();
|
std::size_t face_count = mapnik::freetype_engine::face_names().size();
|
||||||
test test_runner(params);
|
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
|
class test : public benchmark::test_case
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
test(mapnik::parameters const& params)
|
test(mapnik::parameters const& params)
|
||||||
: test_case(params) {}
|
: test_case(params)
|
||||||
bool validate() const
|
{}
|
||||||
{
|
bool validate() const { return mapnik::freetype_engine::register_fonts("./fonts", true); }
|
||||||
return mapnik::freetype_engine::register_fonts("./fonts", true);
|
|
||||||
}
|
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
unsigned long count = 0;
|
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);
|
mapnik::freetype_engine::register_fonts("./fonts", true);
|
||||||
count++;
|
count++;
|
||||||
|
@ -24,4 +22,4 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BENCHMARK(test,"font registration")
|
BENCHMARK(test, "font registration")
|
||||||
|
|
|
@ -1,22 +1,20 @@
|
||||||
#include "bench_framework.hpp"
|
#include "bench_framework.hpp"
|
||||||
#include "../plugins/input/csv/csv_getline.hpp"
|
#include "../plugins/input/csv/csv_getline.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class test : public benchmark::test_case
|
class test : public benchmark::test_case
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string line_data_;
|
std::string line_data_;
|
||||||
test(mapnik::parameters const& params)
|
test(mapnik::parameters const& params)
|
||||||
: test_case(params),
|
: test_case(params)
|
||||||
line_data_("this is one line\nand this is a second line\nand a third line")
|
, 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");
|
boost::optional<std::string> line_data = params.get<std::string>("line");
|
||||||
if (line_data)
|
if (line_data)
|
||||||
{
|
{
|
||||||
line_data_ = *line_data;
|
line_data_ = *line_data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool validate() const
|
bool validate() const
|
||||||
{
|
{
|
||||||
|
@ -25,14 +23,15 @@ public:
|
||||||
std::string csv_line;
|
std::string csv_line;
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
s << line_data_;
|
s << line_data_;
|
||||||
std::getline(s,csv_line,newline);
|
std::getline(s, csv_line, newline);
|
||||||
if (csv_line != first)
|
if (csv_line != first)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -42,29 +41,28 @@ public:
|
||||||
std::string csv_line;
|
std::string csv_line;
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
s << line_data_;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class test2 : public benchmark::test_case
|
class test2 : public benchmark::test_case
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string line_data_;
|
std::string line_data_;
|
||||||
test2(mapnik::parameters const& params)
|
test2(mapnik::parameters const& params)
|
||||||
: test_case(params),
|
: test_case(params)
|
||||||
line_data_("this is one line\nand this is a second line\nand a third line")
|
, 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");
|
boost::optional<std::string> line_data = params.get<std::string>("line");
|
||||||
if (line_data)
|
if (line_data)
|
||||||
{
|
{
|
||||||
line_data_ = *line_data;
|
line_data_ = *line_data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool validate() const
|
bool validate() const
|
||||||
{
|
{
|
||||||
|
@ -74,14 +72,15 @@ public:
|
||||||
std::string csv_line;
|
std::string csv_line;
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
s << line_data_;
|
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)
|
if (csv_line != first)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -92,9 +91,9 @@ public:
|
||||||
std::string csv_line;
|
std::string csv_line;
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
s << line_data_;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -106,17 +105,16 @@ int main(int argc, char** argv)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
mapnik::parameters params;
|
mapnik::parameters params;
|
||||||
benchmark::handle_args(argc,argv,params);
|
benchmark::handle_args(argc, argv, params);
|
||||||
{
|
{
|
||||||
test test_runner(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);
|
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";
|
std::clog << ex.what() << "\n";
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -4,34 +4,32 @@
|
||||||
class test : public benchmark::test_case
|
class test : public benchmark::test_case
|
||||||
{
|
{
|
||||||
std::vector<std::string> images_;
|
std::vector<std::string> images_;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
test(mapnik::parameters const& params)
|
test(mapnik::parameters const& params)
|
||||||
: test_case(params),
|
: test_case(params)
|
||||||
images_{
|
, images_{"./test/data/images/dummy.jpg",
|
||||||
"./test/data/images/dummy.jpg",
|
"./test/data/images/dummy.jpeg",
|
||||||
"./test/data/images/dummy.jpeg",
|
"./test/data/images/dummy.png",
|
||||||
"./test/data/images/dummy.png",
|
"./test/data/images/dummy.tif",
|
||||||
"./test/data/images/dummy.tif",
|
"./test/data/images/dummy.tiff",
|
||||||
"./test/data/images/dummy.tiff",
|
//"./test/data/images/landusepattern.jpeg", // will fail since it is a png
|
||||||
//"./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/images/xcode-CgBI.png", // will fail since its an invalid png
|
"./test/data/svg/octocat.svg",
|
||||||
"./test/data/svg/octocat.svg",
|
"./test/data/svg/place-of-worship-24.svg",
|
||||||
"./test/data/svg/place-of-worship-24.svg",
|
"./test/data/svg/point_sm.svg",
|
||||||
"./test/data/svg/point_sm.svg",
|
"./test/data/svg/point.svg",
|
||||||
"./test/data/svg/point.svg",
|
"./test/data/svg/airfield-12.svg"}
|
||||||
"./test/data/svg/airfield-12.svg"
|
{}
|
||||||
} {}
|
bool validate() const { return true; }
|
||||||
bool validate() const
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
unsigned count = 0;
|
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_)
|
for (auto filename : images_)
|
||||||
{
|
{
|
||||||
auto marker = mapnik::marker_cache::instance().find(filename,true);
|
auto marker = mapnik::marker_cache::instance().find(filename, true);
|
||||||
}
|
}
|
||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
|
@ -39,4 +37,4 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BENCHMARK(test,"marker cache")
|
BENCHMARK(test, "marker cache")
|
|
@ -14,40 +14,38 @@
|
||||||
|
|
||||||
class test : public benchmark::test_case
|
class test : public benchmark::test_case
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
test(mapnik::parameters const& params)
|
test(mapnik::parameters const& params)
|
||||||
: test_case(params) {}
|
: test_case(params)
|
||||||
|
{}
|
||||||
|
|
||||||
bool validate() const
|
bool validate() const { return true; }
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
mapnik::Map m(256,256,"epsg:3857");
|
mapnik::Map m(256, 256, "epsg:3857");
|
||||||
|
|
||||||
mapnik::parameters params;
|
mapnik::parameters params;
|
||||||
params["type"]="memory";
|
params["type"] = "memory";
|
||||||
auto ds = std::make_shared<mapnik::memory_datasource>(params);
|
auto ds = std::make_shared<mapnik::memory_datasource>(params);
|
||||||
// add whitespace to trigger phony "reprojection"
|
// add whitespace to trigger phony "reprojection"
|
||||||
mapnik::layer lay("layer",m.srs() + " ");
|
mapnik::layer lay("layer", m.srs() + " ");
|
||||||
lay.set_datasource(ds);
|
lay.set_datasource(ds);
|
||||||
lay.add_style("style");
|
lay.add_style("style");
|
||||||
m.add_layer(lay);
|
m.add_layer(lay);
|
||||||
// dummy style to ensure that layer is processed
|
// 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
|
// dummy bbox, but "valid" because minx and miny are less
|
||||||
// with an invalid bbox then layer.visible() returns false
|
// with an invalid bbox then layer.visible() returns false
|
||||||
// and the initial rendering setup is not run
|
// and the initial rendering setup is not run
|
||||||
m.zoom_to_box(mapnik::box2d<double>(-1,-1,0,0));
|
m.zoom_to_box(mapnik::box2d<double>(-1, -1, 0, 0));
|
||||||
for (unsigned i=0;i<iterations_;++i)
|
for (unsigned i = 0; i < iterations_; ++i)
|
||||||
{
|
{
|
||||||
mapnik::image_rgba8 im(256,256);
|
mapnik::image_rgba8 im(256, 256);
|
||||||
mapnik::agg_renderer<mapnik::image_rgba8> ren(m,im);
|
mapnik::agg_renderer<mapnik::image_rgba8> ren(m, im);
|
||||||
ren.apply();
|
ren.apply();
|
||||||
}
|
}
|
||||||
return true;
|
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_;
|
double step_;
|
||||||
std::uint8_t start_;
|
std::uint8_t start_;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
test_static(mapnik::parameters const& params)
|
test_static(mapnik::parameters const& params)
|
||||||
: test_case(params),
|
: test_case(params)
|
||||||
step_(STEP_NUM),
|
, step_(STEP_NUM)
|
||||||
start_(START_NUM) {}
|
, start_(START_NUM)
|
||||||
bool validate() const
|
{}
|
||||||
{
|
bool validate() const { return true; }
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
double value_ = 0.0;
|
double value_ = 0.0;
|
||||||
std::uint8_t x;
|
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_;
|
double c = static_cast<double>(start_) * value_;
|
||||||
if (c >= 256.0) c = 255.0;
|
if (c >= 256.0)
|
||||||
if (c < 0.0) c = 0.0;
|
c = 255.0;
|
||||||
|
if (c < 0.0)
|
||||||
|
c = 0.0;
|
||||||
x = static_cast<std::uint8_t>(c);
|
x = static_cast<std::uint8_t>(c);
|
||||||
value_ += step_;
|
value_ += step_;
|
||||||
}
|
}
|
||||||
|
@ -33,35 +35,34 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
using boost::numeric::positive_overflow;
|
|
||||||
using boost::numeric::negative_overflow;
|
using boost::numeric::negative_overflow;
|
||||||
|
using boost::numeric::positive_overflow;
|
||||||
|
|
||||||
class test_numeric : public benchmark::test_case
|
class test_numeric : public benchmark::test_case
|
||||||
{
|
{
|
||||||
double step_;
|
double step_;
|
||||||
std::uint8_t start_;
|
std::uint8_t start_;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
test_numeric(mapnik::parameters const& params)
|
test_numeric(mapnik::parameters const& params)
|
||||||
: test_case(params),
|
: test_case(params)
|
||||||
step_(STEP_NUM),
|
, step_(STEP_NUM)
|
||||||
start_(START_NUM) {}
|
, start_(START_NUM)
|
||||||
bool validate() const
|
{}
|
||||||
{
|
bool validate() const { return true; }
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
double value_ = 0.0;
|
double value_ = 0.0;
|
||||||
std::uint8_t x;
|
std::uint8_t x;
|
||||||
for (std::size_t i=0;i<iterations_;++i) {
|
for (std::size_t i = 0; i < iterations_; ++i)
|
||||||
try {
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
x = boost::numeric_cast<std::uint8_t>(start_ * value_);
|
x = boost::numeric_cast<std::uint8_t>(start_ * value_);
|
||||||
}
|
} catch (negative_overflow&)
|
||||||
catch(negative_overflow&)
|
|
||||||
{
|
{
|
||||||
x = std::numeric_limits<std::uint8_t>::min();
|
x = std::numeric_limits<std::uint8_t>::min();
|
||||||
}
|
} catch (positive_overflow&)
|
||||||
catch(positive_overflow&)
|
|
||||||
{
|
{
|
||||||
x = std::numeric_limits<std::uint8_t>::max();
|
x = std::numeric_limits<std::uint8_t>::max();
|
||||||
}
|
}
|
||||||
|
@ -73,8 +74,5 @@ public:
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
return benchmark::sequencer(argc, argv)
|
return benchmark::sequencer(argc, argv).run<test_static>("static_cast").run<test_numeric>("numeric_cast").done();
|
||||||
.run<test_static>("static_cast")
|
|
||||||
.run<test_numeric>("numeric_cast")
|
|
||||||
.done();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,31 +14,36 @@ struct fake_path
|
||||||
cont_type::iterator itr_;
|
cont_type::iterator itr_;
|
||||||
|
|
||||||
fake_path(std::initializer_list<double> l)
|
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(std::vector<double> const& v)
|
||||||
: fake_path(v.begin(), v.size()) {
|
: fake_path(v.begin(), v.size())
|
||||||
}
|
{}
|
||||||
|
|
||||||
template <typename Itr>
|
template<typename Itr>
|
||||||
fake_path(Itr itr, size_t sz) {
|
fake_path(Itr itr, size_t sz)
|
||||||
|
{
|
||||||
size_t num_coords = sz >> 1;
|
size_t num_coords = sz >> 1;
|
||||||
vertices_.reserve(num_coords);
|
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 x = *itr++;
|
||||||
double y = *itr++;
|
double y = *itr++;
|
||||||
unsigned cmd = (i == 0) ? mapnik::SEG_MOVETO : mapnik::SEG_LINETO;
|
unsigned cmd = (i == 0) ? mapnik::SEG_MOVETO : mapnik::SEG_LINETO;
|
||||||
vertices_.push_back(std::make_tuple(x, y, cmd));
|
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));
|
vertices_.push_back(std::make_tuple(x, y, cmd));
|
||||||
}
|
}
|
||||||
itr_ = vertices_.begin();
|
itr_ = vertices_.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned vertex(double *x, double *y) {
|
unsigned vertex(double* x, double* y)
|
||||||
if (itr_ == vertices_.end()) {
|
{
|
||||||
|
if (itr_ == vertices_.end())
|
||||||
|
{
|
||||||
return mapnik::SEG_END;
|
return mapnik::SEG_END;
|
||||||
}
|
}
|
||||||
*x = std::get<0>(*itr_);
|
*x = std::get<0>(*itr_);
|
||||||
|
@ -48,33 +53,30 @@ struct fake_path
|
||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rewind(unsigned) {
|
void rewind(unsigned) { itr_ = vertices_.begin(); }
|
||||||
itr_ = vertices_.begin();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class test_offset : public benchmark::test_case
|
class test_offset : public benchmark::test_case
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
test_offset(mapnik::parameters const& params)
|
test_offset(mapnik::parameters const& params)
|
||||||
: test_case(params) {}
|
: test_case(params)
|
||||||
bool validate() const
|
{}
|
||||||
{
|
bool validate() const { return true; }
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
std::vector<double> path;
|
std::vector<double> path;
|
||||||
int mysize = 2500;
|
int mysize = 2500;
|
||||||
int x1 = 0;
|
int x1 = 0;
|
||||||
path.reserve(mysize*2);
|
path.reserve(mysize * 2);
|
||||||
for( int i = 0; i < mysize; i++ )
|
for (int i = 0; i < mysize; i++)
|
||||||
{
|
{
|
||||||
path.push_back( i );
|
path.push_back(i);
|
||||||
path.push_back( 0 );
|
path.push_back(0);
|
||||||
}
|
}
|
||||||
fake_path fpath(path);
|
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);
|
mapnik::offset_converter<fake_path> off_path(fpath);
|
||||||
off_path.set_offset(10);
|
off_path.set_offset(10);
|
||||||
unsigned cmd;
|
unsigned cmd;
|
||||||
|
@ -88,15 +90,14 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
mapnik::parameters params;
|
mapnik::parameters params;
|
||||||
benchmark::handle_args(argc,argv,params);
|
benchmark::handle_args(argc, argv, params);
|
||||||
int return_value = 0;
|
int return_value = 0;
|
||||||
{
|
{
|
||||||
test_offset test_runner(params);
|
test_offset test_runner(params);
|
||||||
return_value = run(test_runner,"offset_test");
|
return_value = run(test_runner, "offset_test");
|
||||||
}
|
}
|
||||||
return return_value;
|
return return_value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,23 +4,23 @@
|
||||||
class test : public benchmark::test_case
|
class test : public benchmark::test_case
|
||||||
{
|
{
|
||||||
mapnik::image_rgba8 im_;
|
mapnik::image_rgba8 im_;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
test(mapnik::parameters const& params)
|
test(mapnik::parameters const& params)
|
||||||
: test_case(params),
|
: test_case(params)
|
||||||
im_(256,256) {}
|
, im_(256, 256)
|
||||||
bool validate() const
|
{}
|
||||||
{
|
bool validate() const { return true; }
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
std::string out;
|
std::string out;
|
||||||
for (std::size_t i=0;i<iterations_;++i) {
|
for (std::size_t i = 0; i < iterations_; ++i)
|
||||||
|
{
|
||||||
out.clear();
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BENCHMARK(test,"encoding blank png")
|
BENCHMARK(test, "encoding blank png")
|
||||||
|
|
|
@ -4,34 +4,37 @@
|
||||||
class test : public benchmark::test_case
|
class test : public benchmark::test_case
|
||||||
{
|
{
|
||||||
std::shared_ptr<mapnik::image_rgba8> im_;
|
std::shared_ptr<mapnik::image_rgba8> im_;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
test(mapnik::parameters const& params)
|
test(mapnik::parameters const& params)
|
||||||
: test_case(params) {
|
: test_case(params)
|
||||||
|
{
|
||||||
std::string filename("./benchmark/data/multicolor.png");
|
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())
|
if (!reader.get())
|
||||||
{
|
{
|
||||||
throw mapnik::image_reader_exception("Failed to load: " + filename);
|
throw mapnik::image_reader_exception("Failed to load: " + filename);
|
||||||
}
|
}
|
||||||
im_ = std::make_shared<mapnik::image_rgba8>(reader->width(),reader->height());
|
im_ = std::make_shared<mapnik::image_rgba8>(reader->width(), reader->height());
|
||||||
reader->read(0,0,*im_);
|
reader->read(0, 0, *im_);
|
||||||
}
|
}
|
||||||
bool validate() const
|
bool validate() const
|
||||||
{
|
{
|
||||||
std::string expected("./benchmark/data/multicolor-hextree-expected.png");
|
std::string expected("./benchmark/data/multicolor-hextree-expected.png");
|
||||||
std::string actual("./benchmark/data/multicolor-hextree-actual.png");
|
std::string actual("./benchmark/data/multicolor-hextree-actual.png");
|
||||||
mapnik::save_to_file(*im_,actual, "png8:m=h:z=1");
|
mapnik::save_to_file(*im_, actual, "png8:m=h:z=1");
|
||||||
return benchmark::compare_images(actual,expected);
|
return benchmark::compare_images(actual, expected);
|
||||||
}
|
}
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
std::string out;
|
std::string out;
|
||||||
for (std::size_t i=0;i<iterations_;++i) {
|
for (std::size_t i = 0; i < iterations_; ++i)
|
||||||
|
{
|
||||||
out.clear();
|
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;
|
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,
|
mapnik::box2d<double> const& extent,
|
||||||
std::string const& name)
|
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 ren_base = agg::renderer_base<agg::pixfmt_rgba32_plain>;
|
||||||
using renderer = agg::renderer_scanline_aa_solid<ren_base>;
|
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::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);
|
padded_extent.pad(10);
|
||||||
mapnik::view_transform tr(im.width(),im.height(),padded_extent,0,0);
|
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::rendering_buffer buf(im.bytes(), im.width(), im.height(), im.row_size());
|
||||||
agg::pixfmt_rgba32_plain pixf(buf);
|
agg::pixfmt_rgba32_plain pixf(buf);
|
||||||
ren_base renb(pixf);
|
ren_base renb(pixf);
|
||||||
renderer ren(renb);
|
renderer ren(renb);
|
||||||
mapnik::proj_transform prj_trans(mapnik::projection("epsg:4326"),mapnik::projection("epsg:4326"));
|
mapnik::proj_transform prj_trans(mapnik::projection("epsg:4326"), mapnik::projection("epsg:4326"));
|
||||||
ren.color(agg::rgba8(127,127,127,255));
|
ren.color(agg::rgba8(127, 127, 127, 255));
|
||||||
agg::rasterizer_scanline_aa<> ras;
|
agg::rasterizer_scanline_aa<> ras;
|
||||||
for (auto const& poly : geom)
|
for (auto const& poly : geom)
|
||||||
{
|
{
|
||||||
mapnik::geometry::polygon_vertex_adapter<double> va(poly);
|
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);
|
ras.add_path(path);
|
||||||
}
|
}
|
||||||
agg::scanline_u8 sl;
|
agg::scanline_u8 sl;
|
||||||
agg::render_scanlines(ras, sl, ren);
|
agg::render_scanlines(ras, sl, ren);
|
||||||
mapnik::save_to_file(im,name);
|
mapnik::save_to_file(im, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
class test1 : public benchmark::test_case
|
class test1 : public benchmark::test_case
|
||||||
|
@ -70,15 +71,15 @@ class test1 : public benchmark::test_case
|
||||||
std::string wkt_in_;
|
std::string wkt_in_;
|
||||||
mapnik::box2d<double> extent_;
|
mapnik::box2d<double> extent_;
|
||||||
std::string expected_;
|
std::string expected_;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
using conv_clip = agg::conv_clip_polygon<mapnik::geometry::polygon_vertex_adapter<double>>;
|
using conv_clip = agg::conv_clip_polygon<mapnik::geometry::polygon_vertex_adapter<double>>;
|
||||||
test1(mapnik::parameters const& params,
|
test1(mapnik::parameters const& params, std::string const& wkt_in, mapnik::box2d<double> const& extent)
|
||||||
std::string const& wkt_in,
|
: test_case(params)
|
||||||
mapnik::box2d<double> const& extent)
|
, wkt_in_(wkt_in)
|
||||||
: test_case(params),
|
, extent_(extent)
|
||||||
wkt_in_(wkt_in),
|
, expected_("./benchmark/data/polygon_clipping_agg")
|
||||||
extent_(extent),
|
{}
|
||||||
expected_("./benchmark/data/polygon_clipping_agg") {}
|
|
||||||
bool validate() const
|
bool validate() const
|
||||||
{
|
{
|
||||||
mapnik::geometry::geometry<double> geom;
|
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<double> const& poly = mapnik::util::get<mapnik::geometry::polygon<double>>(geom);
|
||||||
mapnik::geometry::polygon_vertex_adapter<double> va(poly);
|
mapnik::geometry::polygon_vertex_adapter<double> va(poly);
|
||||||
|
|
||||||
|
|
||||||
conv_clip clipped(va);
|
conv_clip clipped(va);
|
||||||
clipped.clip_box(
|
clipped.clip_box(extent_.minx(), extent_.miny(), extent_.maxx(), extent_.maxy());
|
||||||
extent_.minx(),
|
|
||||||
extent_.miny(),
|
|
||||||
extent_.maxx(),
|
|
||||||
extent_.maxy());
|
|
||||||
|
|
||||||
|
|
||||||
clipped.rewind(0);
|
clipped.rewind(0);
|
||||||
mapnik::geometry::polygon<double> poly2;
|
mapnik::geometry::polygon<double> poly2;
|
||||||
|
@ -118,7 +113,8 @@ public:
|
||||||
{
|
{
|
||||||
if (cmd == mapnik::SEG_MOVETO)
|
if (cmd == mapnik::SEG_MOVETO)
|
||||||
{
|
{
|
||||||
x0 = x; y0 = y;
|
x0 = x;
|
||||||
|
y0 = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd == mapnik::SEG_CLOSE)
|
if (cmd == mapnik::SEG_CLOSE)
|
||||||
|
@ -126,7 +122,7 @@ public:
|
||||||
ring.emplace_back(x0, y0);
|
ring.emplace_back(x0, y0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ring.emplace_back(x,y);
|
ring.emplace_back(x, y);
|
||||||
}
|
}
|
||||||
poly2.push_back(std::move(ring));
|
poly2.push_back(std::move(ring));
|
||||||
// interior rings
|
// interior rings
|
||||||
|
@ -135,30 +131,31 @@ public:
|
||||||
{
|
{
|
||||||
if (cmd == mapnik::SEG_MOVETO)
|
if (cmd == mapnik::SEG_MOVETO)
|
||||||
{
|
{
|
||||||
x0 = x; y0 = y;
|
x0 = x;
|
||||||
|
y0 = y;
|
||||||
}
|
}
|
||||||
else if (cmd == mapnik::SEG_CLOSE)
|
else if (cmd == mapnik::SEG_CLOSE)
|
||||||
{
|
{
|
||||||
ring.emplace_back(x0,y0);
|
ring.emplace_back(x0, y0);
|
||||||
poly2.push_back(std::move(ring));
|
poly2.push_back(std::move(ring));
|
||||||
ring.clear();
|
ring.clear();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ring.emplace_back(x,y);
|
ring.emplace_back(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string expect = expected_+".png";
|
std::string expect = expected_ + ".png";
|
||||||
std::string actual = expected_+"_actual.png";
|
std::string actual = expected_ + "_actual.png";
|
||||||
mapnik::geometry::multi_polygon<double> mp;
|
mapnik::geometry::multi_polygon<double> mp;
|
||||||
mp.emplace_back(poly2);
|
mp.emplace_back(poly2);
|
||||||
auto env = mapnik::geometry::envelope(mp);
|
auto env = mapnik::geometry::envelope(mp);
|
||||||
if (!mapnik::util::exists(expect) || (std::getenv("UPDATE") != nullptr))
|
if (!mapnik::util::exists(expect) || (std::getenv("UPDATE") != nullptr))
|
||||||
{
|
{
|
||||||
std::clog << "generating expected image: " << expect << "\n";
|
std::clog << "generating expected image: " << expect << "\n";
|
||||||
render(mp,env,expect);
|
render(mp, env, expect);
|
||||||
}
|
}
|
||||||
render(mp,env,actual);
|
render(mp, env, actual);
|
||||||
return benchmark::compare_images(actual,expect);
|
return benchmark::compare_images(actual, expect);
|
||||||
}
|
}
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
|
@ -178,29 +175,28 @@ public:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool valid = true;
|
bool valid = true;
|
||||||
for (unsigned i=0;i<iterations_;++i)
|
for (unsigned i = 0; i < iterations_; ++i)
|
||||||
{
|
{
|
||||||
unsigned count = 0;
|
unsigned count = 0;
|
||||||
mapnik::geometry::polygon<double> const& poly = mapnik::util::get<mapnik::geometry::polygon<double>>(geom);
|
mapnik::geometry::polygon<double> const& poly = mapnik::util::get<mapnik::geometry::polygon<double>>(geom);
|
||||||
mapnik::geometry::polygon_vertex_adapter<double> va(poly);
|
mapnik::geometry::polygon_vertex_adapter<double> va(poly);
|
||||||
conv_clip clipped(va);
|
conv_clip clipped(va);
|
||||||
clipped.clip_box(
|
clipped.clip_box(extent_.minx(), extent_.miny(), extent_.maxx(), extent_.maxy());
|
||||||
extent_.minx(),
|
|
||||||
extent_.miny(),
|
|
||||||
extent_.maxx(),
|
|
||||||
extent_.maxy());
|
|
||||||
unsigned cmd;
|
unsigned cmd;
|
||||||
double x,y;
|
double x, y;
|
||||||
// NOTE: this rewind is critical otherwise
|
// NOTE: this rewind is critical otherwise
|
||||||
// agg_conv_adapter_vpgen will give garbage
|
// agg_conv_adapter_vpgen will give garbage
|
||||||
// values for the first vertex
|
// values for the first vertex
|
||||||
clipped.rewind(0);
|
clipped.rewind(0);
|
||||||
while ((cmd = clipped.vertex(&x, &y)) != mapnik::SEG_END) {
|
while ((cmd = clipped.vertex(&x, &y)) != mapnik::SEG_END)
|
||||||
|
{
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
unsigned expected_count = 30;
|
unsigned expected_count = 30;
|
||||||
if (count != expected_count) {
|
if (count != expected_count)
|
||||||
std::clog << "test1: clipping failed: processed " << count << " verticies but expected " << expected_count << "\n";
|
{
|
||||||
|
std::clog << "test1: clipping failed: processed " << count << " verticies but expected "
|
||||||
|
<< expected_count << "\n";
|
||||||
valid = false;
|
valid = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -208,20 +204,19 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class test3 : public benchmark::test_case
|
class test3 : public benchmark::test_case
|
||||||
{
|
{
|
||||||
std::string wkt_in_;
|
std::string wkt_in_;
|
||||||
mapnik::box2d<double> extent_;
|
mapnik::box2d<double> extent_;
|
||||||
std::string expected_;
|
std::string expected_;
|
||||||
public:
|
|
||||||
test3(mapnik::parameters const& params,
|
public:
|
||||||
std::string const& wkt_in,
|
test3(mapnik::parameters const& params, std::string const& wkt_in, mapnik::box2d<double> const& extent)
|
||||||
mapnik::box2d<double> const& extent)
|
: test_case(params)
|
||||||
: test_case(params),
|
, wkt_in_(wkt_in)
|
||||||
wkt_in_(wkt_in),
|
, extent_(extent)
|
||||||
extent_(extent),
|
, expected_("./benchmark/data/polygon_clipping_boost")
|
||||||
expected_("./benchmark/data/polygon_clipping_boost") {}
|
{}
|
||||||
bool validate() const
|
bool validate() const
|
||||||
{
|
{
|
||||||
mapnik::geometry::geometry<double> geom;
|
mapnik::geometry::geometry<double> geom;
|
||||||
|
@ -234,12 +229,12 @@ public:
|
||||||
std::clog << "empty geom!\n";
|
std::clog << "empty geom!\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!geom.is<mapnik::geometry::polygon<double> >())
|
if (!geom.is<mapnik::geometry::polygon<double>>())
|
||||||
{
|
{
|
||||||
std::clog << "not a polygon!\n";
|
std::clog << "not a polygon!\n";
|
||||||
return false;
|
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::correct(poly);
|
||||||
|
|
||||||
mapnik::geometry::linear_ring<double> bbox;
|
mapnik::geometry::linear_ring<double> bbox;
|
||||||
|
@ -249,15 +244,15 @@ public:
|
||||||
bbox.emplace_back(extent_.maxx(), extent_.miny());
|
bbox.emplace_back(extent_.maxx(), extent_.miny());
|
||||||
bbox.emplace_back(extent_.minx(), 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);
|
boost::geometry::intersection(bbox, poly, result);
|
||||||
|
|
||||||
std::string expect = expected_+".png";
|
std::string expect = expected_ + ".png";
|
||||||
std::string actual = expected_+"_actual.png";
|
std::string actual = expected_ + "_actual.png";
|
||||||
mapnik::geometry::multi_polygon<double> mp;
|
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);
|
mp.emplace_back(_geom);
|
||||||
}
|
}
|
||||||
mapnik::geometry::geometry<double> geom2(mp);
|
mapnik::geometry::geometry<double> geom2(mp);
|
||||||
|
@ -265,10 +260,10 @@ public:
|
||||||
if (!mapnik::util::exists(expect) || (std::getenv("UPDATE") != nullptr))
|
if (!mapnik::util::exists(expect) || (std::getenv("UPDATE") != nullptr))
|
||||||
{
|
{
|
||||||
std::clog << "generating expected image: " << expect << "\n";
|
std::clog << "generating expected image: " << expect << "\n";
|
||||||
render(mp,env,expect);
|
render(mp, env, expect);
|
||||||
}
|
}
|
||||||
render(mp,env,actual);
|
render(mp, env, actual);
|
||||||
return benchmark::compare_images(actual,expect);
|
return benchmark::compare_images(actual, expect);
|
||||||
}
|
}
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
|
@ -282,12 +277,12 @@ public:
|
||||||
std::clog << "empty geom!\n";
|
std::clog << "empty geom!\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!geom.is<mapnik::geometry::polygon<double> >())
|
if (!geom.is<mapnik::geometry::polygon<double>>())
|
||||||
{
|
{
|
||||||
std::clog << "not a polygon!\n";
|
std::clog << "not a polygon!\n";
|
||||||
return false;
|
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::correct(poly);
|
||||||
|
|
||||||
mapnik::geometry::linear_ring<double> bbox;
|
mapnik::geometry::linear_ring<double> bbox;
|
||||||
|
@ -298,22 +293,25 @@ public:
|
||||||
bbox.emplace_back(extent_.minx(), extent_.miny());
|
bbox.emplace_back(extent_.minx(), extent_.miny());
|
||||||
|
|
||||||
bool valid = true;
|
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);
|
boost::geometry::intersection(bbox, poly, result);
|
||||||
unsigned count = 0;
|
unsigned count = 0;
|
||||||
for (auto const& _geom : result)
|
for (auto const& _geom : result)
|
||||||
{
|
{
|
||||||
mapnik::geometry::polygon_vertex_adapter<double> va(_geom);
|
mapnik::geometry::polygon_vertex_adapter<double> va(_geom);
|
||||||
unsigned cmd;
|
unsigned cmd;
|
||||||
double x,y;
|
double x, y;
|
||||||
while ((cmd = va.vertex(&x, &y)) != mapnik::SEG_END) {
|
while ((cmd = va.vertex(&x, &y)) != mapnik::SEG_END)
|
||||||
|
{
|
||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
unsigned expected_count = 29;
|
unsigned expected_count = 29;
|
||||||
if (count != expected_count) {
|
if (count != expected_count)
|
||||||
std::clog << "test3: clipping failed: processed " << count << " verticies but expected " << expected_count << "\n";
|
{
|
||||||
|
std::clog << "test3: clipping failed: processed " << count << " verticies but expected "
|
||||||
|
<< expected_count << "\n";
|
||||||
valid = false;
|
valid = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -500,8 +498,8 @@ public:
|
||||||
}
|
}
|
||||||
unsigned expected_count = 29;
|
unsigned expected_count = 29;
|
||||||
if (count != expected_count) {
|
if (count != expected_count) {
|
||||||
std::clog << "test3: clipping failed: processed " << count << " verticies but expected " << expected_count << "\n";
|
std::clog << "test3: clipping failed: processed " << count << " verticies but expected " <<
|
||||||
valid = false;
|
expected_count << "\n"; valid = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -513,13 +511,16 @@ public:
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
mapnik::parameters params;
|
mapnik::parameters params;
|
||||||
benchmark::handle_args(argc,argv,params);
|
benchmark::handle_args(argc, argv, params);
|
||||||
|
|
||||||
// polygon/rect clipping
|
// 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))
|
// IN : POLYGON ((155 203, 233 454, 315 340, 421 446, 463 324, 559 466, 665 253, 528 178, 394 229, 329 138, 212 134,
|
||||||
// RECT : POLYGON ((181 106, 181 470, 631 470, 631 106, 181 106))
|
// 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
|
||||||
// OUT (expected)
|
// 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))
|
// 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
|
#if 0
|
||||||
mapnik::box2d<double> clipping_box(181,106,631,470);
|
mapnik::box2d<double> clipping_box(181,106,631,470);
|
||||||
std::string filename_("./benchmark/data/polygon.wkt");
|
std::string filename_("./benchmark/data/polygon.wkt");
|
||||||
|
@ -544,5 +545,5 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
#endif
|
#endif
|
||||||
return 0;// return_value;
|
return 0; // return_value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,53 +8,51 @@ class test : public benchmark::test_case
|
||||||
{
|
{
|
||||||
std::string xml_;
|
std::string xml_;
|
||||||
mapnik::box2d<double> extent_;
|
mapnik::box2d<double> extent_;
|
||||||
public:
|
|
||||||
test(mapnik::parameters const& params,
|
public:
|
||||||
std::string const& xml,
|
test(mapnik::parameters const& params, std::string const& xml, mapnik::box2d<double> const& extent)
|
||||||
mapnik::box2d<double> const& extent)
|
: test_case(params)
|
||||||
: test_case(params),
|
, xml_(xml)
|
||||||
xml_(xml),
|
, extent_(extent)
|
||||||
extent_(extent)
|
{}
|
||||||
{}
|
|
||||||
bool validate() const
|
bool validate() const
|
||||||
{
|
{
|
||||||
mapnik::Map m(256,256);
|
mapnik::Map m(256, 256);
|
||||||
mapnik::load_map(m,xml_);
|
mapnik::load_map(m, xml_);
|
||||||
m.zoom_to_box(extent_);
|
m.zoom_to_box(extent_);
|
||||||
mapnik::image_rgba8 im(m.width(),m.height());
|
mapnik::image_rgba8 im(m.width(), m.height());
|
||||||
mapnik::agg_renderer<mapnik::image_rgba8> ren(m,im);
|
mapnik::agg_renderer<mapnik::image_rgba8> ren(m, im);
|
||||||
ren.apply();
|
ren.apply();
|
||||||
//mapnik::save_to_file(im.data(),"test.png");
|
// mapnik::save_to_file(im.data(),"test.png");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
mapnik::Map m(256,256);
|
mapnik::Map m(256, 256);
|
||||||
mapnik::load_map(m,xml_);
|
mapnik::load_map(m, xml_);
|
||||||
m.zoom_to_box(extent_);
|
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::image_rgba8 im(m.width(), m.height());
|
||||||
mapnik::agg_renderer<mapnik::image_rgba8> ren(m,im);
|
mapnik::agg_renderer<mapnik::image_rgba8> ren(m, im);
|
||||||
ren.apply();
|
ren.apply();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
mapnik::parameters params;
|
mapnik::parameters params;
|
||||||
benchmark::handle_args(argc,argv,params);
|
benchmark::handle_args(argc, argv, params);
|
||||||
mapnik::datasource_cache::instance().register_datasources("./plugins/input/");
|
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
|
// 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)
|
return benchmark::sequencer(argc, argv)
|
||||||
.run<test>("polygon clip render z1", "benchmark/data/polygon_rendering_clip.xml", z1)
|
.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 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 clip render z16", "benchmark/data/polygon_rendering_clip.xml", z16)
|
||||||
.run<test>("polygon noclip render z16", "benchmark/data/polygon_rendering_no_clip.xml", z16)
|
.run<test>("polygon noclip render z16", "benchmark/data/polygon_rendering_no_clip.xml", z16)
|
||||||
.done();
|
.done();
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,45 +10,46 @@ class test : public benchmark::test_case
|
||||||
mapnik::box2d<double> from_;
|
mapnik::box2d<double> from_;
|
||||||
mapnik::box2d<double> to_;
|
mapnik::box2d<double> to_;
|
||||||
bool defer_proj_init_;
|
bool defer_proj_init_;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
test(mapnik::parameters const& params,
|
test(mapnik::parameters const& params,
|
||||||
std::string const& src,
|
std::string const& src,
|
||||||
std::string const& dest,
|
std::string const& dest,
|
||||||
mapnik::box2d<double> const& from,
|
mapnik::box2d<double> const& from,
|
||||||
mapnik::box2d<double> const& to,
|
mapnik::box2d<double> const& to,
|
||||||
bool defer_proj)
|
bool defer_proj)
|
||||||
: test_case(params),
|
: test_case(params)
|
||||||
src_(src),
|
, src_(src)
|
||||||
dest_(dest),
|
, dest_(dest)
|
||||||
from_(from),
|
, from_(from)
|
||||||
to_(to),
|
, to_(to)
|
||||||
defer_proj_init_(defer_proj) {}
|
, defer_proj_init_(defer_proj)
|
||||||
|
{}
|
||||||
bool validate() const
|
bool validate() const
|
||||||
{
|
{
|
||||||
mapnik::projection src(src_,defer_proj_init_);
|
mapnik::projection src(src_, defer_proj_init_);
|
||||||
mapnik::projection dest(dest_,defer_proj_init_);
|
mapnik::projection dest(dest_, defer_proj_init_);
|
||||||
mapnik::proj_transform tr(src,dest);
|
mapnik::proj_transform tr(src, dest);
|
||||||
mapnik::box2d<double> bbox = from_;
|
mapnik::box2d<double> bbox = from_;
|
||||||
if (!tr.forward(bbox)) return false;
|
if (!tr.forward(bbox))
|
||||||
return ((std::fabs(bbox.minx() - to_.minx()) < .5) &&
|
return false;
|
||||||
(std::fabs(bbox.maxx() - to_.maxx()) < .5) &&
|
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.miny() - to_.miny()) < .5) && (std::fabs(bbox.maxy() - to_.maxy()) < .5));
|
||||||
(std::fabs(bbox.maxy() - to_.maxy()) < .5)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
mapnik::projection src(src_,defer_proj_init_);
|
mapnik::projection src(src_, defer_proj_init_);
|
||||||
mapnik::projection dest(dest_,defer_proj_init_);
|
mapnik::projection dest(dest_, defer_proj_init_);
|
||||||
mapnik::proj_transform tr(src,dest);
|
mapnik::proj_transform tr(src, dest);
|
||||||
for (std::size_t i=0;i<iterations_;++i)
|
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);
|
mapnik::box2d<double> box(j, k, j, k);
|
||||||
if (!tr.forward(box)) throw std::runtime_error("could not transform coords");
|
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
|
// echo -180 -60 | cs2cs -f "%.10f" epsg:4326 +to epsg:3857
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
mapnik::box2d<double> from(-180,-80,180,80);
|
mapnik::box2d<double> from(-180, -80, 180, 80);
|
||||||
mapnik::box2d<double> to(-20037508.3427892476,-15538711.0963092316,20037508.3427892476,15538711.0963092316);
|
mapnik::box2d<double> to(-20037508.3427892476, -15538711.0963092316, 20037508.3427892476, 15538711.0963092316);
|
||||||
std::string from_str("epsg:4326");
|
std::string from_str("epsg:4326");
|
||||||
std::string to_str("epsg:3857");
|
std::string to_str("epsg:3857");
|
||||||
std::string from_str2("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs");
|
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)
|
return benchmark::sequencer(argc, argv)
|
||||||
.run<test>("lonlat->merc epsg (internal)", from_str, to_str, from, to, true)
|
.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>("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 epsg (internal)", to_str, from_str, to, from, true)
|
||||||
.run<test>("merc->lonlat literal (libproj)", to_str2, from_str2, to, from, true)
|
.run<test>("merc->lonlat literal (libproj)", to_str2, from_str2, to, from, true)
|
||||||
.done();
|
.done();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,43 +6,41 @@ using quad_tree_type = mapnik::quad_tree<std::size_t>;
|
||||||
|
|
||||||
class test : public benchmark::test_case
|
class test : public benchmark::test_case
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
test(mapnik::parameters const& params)
|
test(mapnik::parameters const& params)
|
||||||
: test_case(params) {}
|
: test_case(params)
|
||||||
|
{}
|
||||||
|
|
||||||
bool validate() const
|
bool validate() const { return true; }
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
std::random_device rd;
|
std::random_device rd;
|
||||||
std::default_random_engine engine(rd());
|
std::default_random_engine engine(rd());
|
||||||
std::uniform_int_distribution<int> uniform_dist(0, 2048);
|
std::uniform_int_distribution<int> uniform_dist(0, 2048);
|
||||||
quad_tree_type tree(mapnik::box2d<double>(0,0,2048,2048));
|
quad_tree_type tree(mapnik::box2d<double>(0, 0, 2048, 2048));
|
||||||
//populate
|
// populate
|
||||||
for (size_t i = 0; i < iterations_; ++i)
|
for (size_t i = 0; i < iterations_; ++i)
|
||||||
{
|
{
|
||||||
int cx = uniform_dist(engine);
|
int cx = uniform_dist(engine);
|
||||||
int cy = uniform_dist(engine);
|
int cy = uniform_dist(engine);
|
||||||
int sx = 0.2 * uniform_dist(engine);
|
int sx = 0.2 * uniform_dist(engine);
|
||||||
int sy = 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);
|
tree.insert(i, box);
|
||||||
}
|
}
|
||||||
// bounding box query
|
// bounding box query
|
||||||
std::size_t count=0;
|
std::size_t count = 0;
|
||||||
for (size_t i = 0; i < iterations_; ++i)
|
for (size_t i = 0; i < iterations_; ++i)
|
||||||
{
|
{
|
||||||
int cx = uniform_dist(engine);
|
int cx = uniform_dist(engine);
|
||||||
int cy = uniform_dist(engine);
|
int cy = uniform_dist(engine);
|
||||||
int sx = 0.4 * uniform_dist(engine);
|
int sx = 0.4 * uniform_dist(engine);
|
||||||
int sy = 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 itr = tree.query_in_box(box);
|
||||||
auto end = tree.query_end();
|
auto end = tree.query_end();
|
||||||
for ( ;itr != end; ++itr)
|
for (; itr != end; ++itr)
|
||||||
{
|
{
|
||||||
++count;
|
++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_;
|
mapnik::value_integer height_;
|
||||||
double scale_factor_;
|
double scale_factor_;
|
||||||
std::string preview_;
|
std::string preview_;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
test(mapnik::parameters const& params)
|
test(mapnik::parameters const& params)
|
||||||
: test_case(params),
|
: test_case(params)
|
||||||
xml_(),
|
, xml_()
|
||||||
extent_(),
|
, extent_()
|
||||||
width_(*params.get<mapnik::value_integer>("width",256)),
|
, width_(*params.get<mapnik::value_integer>("width", 256))
|
||||||
height_(*params.get<mapnik::value_integer>("height",256)),
|
, height_(*params.get<mapnik::value_integer>("height", 256))
|
||||||
scale_factor_(*params.get<mapnik::value_double>("scale_factor",1.0)),
|
, scale_factor_(*params.get<mapnik::value_double>("scale_factor", 1.0))
|
||||||
preview_(*params.get<std::string>("preview",""))
|
, preview_(*params.get<std::string>("preview", ""))
|
||||||
{
|
{
|
||||||
boost::optional<std::string> map = params.get<std::string>("map");
|
boost::optional<std::string> map = params.get<std::string>("map");
|
||||||
if (!map)
|
if (!map)
|
||||||
{
|
{
|
||||||
|
@ -43,70 +44,75 @@ public:
|
||||||
{
|
{
|
||||||
throw std::runtime_error("please provide a --extent=<minx,miny,maxx,maxy> arg");
|
throw std::runtime_error("please provide a --extent=<minx,miny,maxx,maxy> arg");
|
||||||
}*/
|
}*/
|
||||||
|
}
|
||||||
}
|
|
||||||
bool validate() const
|
bool validate() const
|
||||||
{
|
{
|
||||||
mapnik::Map m(width_,height_);
|
mapnik::Map m(width_, height_);
|
||||||
mapnik::load_map(m,xml_,true);
|
mapnik::load_map(m, xml_, true);
|
||||||
if (extent_.valid()) {
|
if (extent_.valid())
|
||||||
|
{
|
||||||
m.zoom_to_box(extent_);
|
m.zoom_to_box(extent_);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
m.zoom_all();
|
m.zoom_all();
|
||||||
}
|
}
|
||||||
mapnik::image_rgba8 im(m.width(),m.height());
|
mapnik::image_rgba8 im(m.width(), m.height());
|
||||||
mapnik::agg_renderer<mapnik::image_rgba8> ren(m,im,scale_factor_);
|
mapnik::agg_renderer<mapnik::image_rgba8> ren(m, im, scale_factor_);
|
||||||
ren.apply();
|
ren.apply();
|
||||||
if (!preview_.empty()) {
|
if (!preview_.empty())
|
||||||
|
{
|
||||||
std::clog << "preview available at " << preview_ << "\n";
|
std::clog << "preview available at " << preview_ << "\n";
|
||||||
mapnik::save_to_file(im,preview_);
|
mapnik::save_to_file(im, preview_);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
if (!preview_.empty()) {
|
if (!preview_.empty())
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
mapnik::Map m(width_,height_);
|
mapnik::Map m(width_, height_);
|
||||||
mapnik::load_map(m,xml_);
|
mapnik::load_map(m, xml_);
|
||||||
if (extent_.valid()) {
|
if (extent_.valid())
|
||||||
|
{
|
||||||
m.zoom_to_box(extent_);
|
m.zoom_to_box(extent_);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
m.zoom_all();
|
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::image_rgba8 im(m.width(), m.height());
|
||||||
mapnik::agg_renderer<mapnik::image_rgba8> ren(m,im,scale_factor_);
|
mapnik::agg_renderer<mapnik::image_rgba8> ren(m, im, scale_factor_);
|
||||||
ren.apply();
|
ren.apply();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
int return_value = 0;
|
int return_value = 0;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
mapnik::parameters params;
|
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");
|
boost::optional<std::string> name = params.get<std::string>("name");
|
||||||
if (!name)
|
if (!name)
|
||||||
{
|
{
|
||||||
std::clog << "please provide a name for this test\n";
|
std::clog << "please provide a name for this test\n";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
mapnik::freetype_engine::register_fonts("./fonts/",true);
|
mapnik::freetype_engine::register_fonts("./fonts/", true);
|
||||||
mapnik::datasource_cache::instance().register_datasources("./plugins/input/");
|
mapnik::datasource_cache::instance().register_datasources("./plugins/input/");
|
||||||
{
|
{
|
||||||
test test_runner(params);
|
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";
|
std::clog << ex.what() << "\n";
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -12,14 +12,15 @@
|
||||||
#include <mapnik/datasource_cache.hpp>
|
#include <mapnik/datasource_cache.hpp>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
template <typename Renderer> void process_layers(Renderer & ren,
|
template<typename Renderer>
|
||||||
mapnik::request const& m_req,
|
void process_layers(Renderer& ren,
|
||||||
mapnik::projection const& map_proj,
|
mapnik::request const& m_req,
|
||||||
std::vector<mapnik::layer> const& layers,
|
mapnik::projection const& map_proj,
|
||||||
double scale_denom)
|
std::vector<mapnik::layer> const& layers,
|
||||||
|
double scale_denom)
|
||||||
{
|
{
|
||||||
unsigned layers_size = layers.size();
|
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];
|
mapnik::layer const& lyr = layers[i];
|
||||||
if (lyr.visible(scale_denom))
|
if (lyr.visible(scale_denom))
|
||||||
|
@ -50,17 +51,18 @@ class test : public benchmark::test_case
|
||||||
double scale_factor_;
|
double scale_factor_;
|
||||||
std::string preview_;
|
std::string preview_;
|
||||||
mutable mapnik::image_rgba8 im_;
|
mutable mapnik::image_rgba8 im_;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
test(mapnik::parameters const& params)
|
test(mapnik::parameters const& params)
|
||||||
: test_case(params),
|
: test_case(params)
|
||||||
xml_(),
|
, xml_()
|
||||||
extent_(),
|
, extent_()
|
||||||
width_(*params.get<mapnik::value_integer>("width",256)),
|
, width_(*params.get<mapnik::value_integer>("width", 256))
|
||||||
height_(*params.get<mapnik::value_integer>("height",256)),
|
, height_(*params.get<mapnik::value_integer>("height", 256))
|
||||||
m_(new mapnik::Map(width_,height_)),
|
, m_(new mapnik::Map(width_, height_))
|
||||||
scale_factor_(*params.get<mapnik::value_double>("scale_factor",2.0)),
|
, scale_factor_(*params.get<mapnik::value_double>("scale_factor", 2.0))
|
||||||
preview_(*params.get<std::string>("preview","")),
|
, preview_(*params.get<std::string>("preview", ""))
|
||||||
im_(m_->width(),m_->height())
|
, im_(m_->width(), m_->height())
|
||||||
{
|
{
|
||||||
boost::optional<std::string> map = params.get<std::string>("map");
|
boost::optional<std::string> map = params.get<std::string>("map");
|
||||||
if (!map)
|
if (!map)
|
||||||
|
@ -70,7 +72,7 @@ public:
|
||||||
xml_ = *map;
|
xml_ = *map;
|
||||||
|
|
||||||
boost::optional<std::string> ext = params.get<std::string>("extent");
|
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 (ext && !ext->empty())
|
||||||
{
|
{
|
||||||
if (!extent_.from_string(*ext))
|
if (!extent_.from_string(*ext))
|
||||||
|
@ -87,42 +89,44 @@ public:
|
||||||
|
|
||||||
bool validate() const
|
bool validate() const
|
||||||
{
|
{
|
||||||
mapnik::request m_req(width_,height_,extent_);
|
mapnik::request m_req(width_, height_, extent_);
|
||||||
mapnik::attributes variables;
|
mapnik::attributes variables;
|
||||||
m_req.set_buffer_size(m_->buffer_size());
|
m_req.set_buffer_size(m_->buffer_size());
|
||||||
mapnik::projection map_proj(m_->srs(),true);
|
mapnik::projection map_proj(m_->srs(), true);
|
||||||
double scale_denom = mapnik::scale_denominator(m_req.scale(),map_proj.is_geographic());
|
double scale_denom = mapnik::scale_denominator(m_req.scale(), map_proj.is_geographic());
|
||||||
scale_denom *= scale_factor_;
|
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_);
|
ren.start_map_processing(*m_);
|
||||||
std::vector<mapnik::layer> const& layers = m_->layers();
|
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_);
|
ren.end_map_processing(*m_);
|
||||||
if (!preview_.empty()) {
|
if (!preview_.empty())
|
||||||
|
{
|
||||||
std::clog << "preview available at " << preview_ << "\n";
|
std::clog << "preview available at " << preview_ << "\n";
|
||||||
mapnik::save_to_file(im_,preview_);
|
mapnik::save_to_file(im_, preview_);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
if (!preview_.empty()) {
|
if (!preview_.empty())
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (unsigned i=0;i<iterations_;++i)
|
for (unsigned i = 0; i < iterations_; ++i)
|
||||||
{
|
{
|
||||||
mapnik::request m_req(width_,height_,extent_);
|
mapnik::request m_req(width_, height_, extent_);
|
||||||
mapnik::image_rgba8 im(m_->width(),m_->height());
|
mapnik::image_rgba8 im(m_->width(), m_->height());
|
||||||
mapnik::attributes variables;
|
mapnik::attributes variables;
|
||||||
m_req.set_buffer_size(m_->buffer_size());
|
m_req.set_buffer_size(m_->buffer_size());
|
||||||
mapnik::projection map_proj(m_->srs(),true);
|
mapnik::projection map_proj(m_->srs(), true);
|
||||||
double scale_denom = mapnik::scale_denominator(m_req.scale(),map_proj.is_geographic());
|
double scale_denom = mapnik::scale_denominator(m_req.scale(), map_proj.is_geographic());
|
||||||
scale_denom *= scale_factor_;
|
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_);
|
ren.start_map_processing(*m_);
|
||||||
std::vector<mapnik::layer> const& layers = m_->layers();
|
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_);
|
ren.end_map_processing(*m_);
|
||||||
bool diff = false;
|
bool diff = false;
|
||||||
mapnik::image_rgba8 const& dest = im;
|
mapnik::image_rgba8 const& dest = im;
|
||||||
|
@ -133,37 +137,37 @@ public:
|
||||||
const unsigned int* row_to = dest.get_row(y);
|
const unsigned int* row_to = dest.get_row(y);
|
||||||
for (unsigned int x = 0; x < width_; ++x)
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
int return_value = 0;
|
int return_value = 0;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
mapnik::parameters params;
|
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");
|
boost::optional<std::string> name = params.get<std::string>("name");
|
||||||
if (!name)
|
if (!name)
|
||||||
{
|
{
|
||||||
std::clog << "please provide a name for this test\n";
|
std::clog << "please provide a name for this test\n";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
mapnik::freetype_engine::register_fonts("./fonts/",true);
|
mapnik::freetype_engine::register_fonts("./fonts/", true);
|
||||||
mapnik::datasource_cache::instance().register_datasources("./plugins/input/");
|
mapnik::datasource_cache::instance().register_datasources("./plugins/input/");
|
||||||
{
|
{
|
||||||
test test_runner(params);
|
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";
|
std::clog << ex.what() << "\n";
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -4,27 +4,31 @@
|
||||||
class test : public benchmark::test_case
|
class test : public benchmark::test_case
|
||||||
{
|
{
|
||||||
std::string value_;
|
std::string value_;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
test(mapnik::parameters const& params)
|
test(mapnik::parameters const& params)
|
||||||
: test_case(params),
|
: test_case(params)
|
||||||
value_("true") {}
|
, value_("true")
|
||||||
|
{}
|
||||||
bool validate() const
|
bool validate() const
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
mapnik::util::string2bool(value_.data(),value_.data()+value_.size(),result);
|
mapnik::util::string2bool(value_.data(), value_.data() + value_.size(), result);
|
||||||
if (!result) return result;
|
if (!result)
|
||||||
mapnik::util::string2bool(value_,result);
|
return result;
|
||||||
|
mapnik::util::string2bool(value_, result);
|
||||||
return (result == true);
|
return (result == true);
|
||||||
}
|
}
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
for (std::size_t i=0;i<iterations_;++i) {
|
for (std::size_t i = 0; i < iterations_; ++i)
|
||||||
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
mapnik::util::string2bool(value_,result);
|
mapnik::util::string2bool(value_, result);
|
||||||
mapnik::util::string2bool(value_.data(),value_.data()+value_.size(),result);
|
mapnik::util::string2bool(value_.data(), value_.data() + value_.size(), result);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BENCHMARK(test,"string->bool")
|
BENCHMARK(test, "string->bool")
|
||||||
|
|
|
@ -4,29 +4,36 @@
|
||||||
class test : public benchmark::test_case
|
class test : public benchmark::test_case
|
||||||
{
|
{
|
||||||
std::string value_;
|
std::string value_;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
test(mapnik::parameters const& params)
|
test(mapnik::parameters const& params)
|
||||||
: test_case(params),
|
: test_case(params)
|
||||||
value_("1.23456789") {}
|
, value_("1.23456789")
|
||||||
|
{}
|
||||||
bool validate() const
|
bool validate() const
|
||||||
{
|
{
|
||||||
double result = 0;
|
double result = 0;
|
||||||
if (!mapnik::util::string2double(value_.data(),value_.data()+value_.size(),result)) return false;
|
if (!mapnik::util::string2double(value_.data(), value_.data() + value_.size(), result))
|
||||||
if (result != 1.23456789) return false;
|
return false;
|
||||||
|
if (result != 1.23456789)
|
||||||
|
return false;
|
||||||
result = 0;
|
result = 0;
|
||||||
if (!mapnik::util::string2double(value_,result)) return false;
|
if (!mapnik::util::string2double(value_, result))
|
||||||
if (result != 1.23456789) return false;
|
return false;
|
||||||
|
if (result != 1.23456789)
|
||||||
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
for (std::size_t i=0;i<iterations_;++i) {
|
for (std::size_t i = 0; i < iterations_; ++i)
|
||||||
|
{
|
||||||
double result = 0;
|
double result = 0;
|
||||||
mapnik::util::string2double(value_,result);
|
mapnik::util::string2double(value_, result);
|
||||||
mapnik::util::string2double(value_.data(),value_.data()+value_.size(),result);
|
mapnik::util::string2double(value_.data(), value_.data() + value_.size(), result);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BENCHMARK(test,"string->double")
|
BENCHMARK(test, "string->double")
|
||||||
|
|
|
@ -4,29 +4,36 @@
|
||||||
class test : public benchmark::test_case
|
class test : public benchmark::test_case
|
||||||
{
|
{
|
||||||
std::string value_;
|
std::string value_;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
test(mapnik::parameters const& params)
|
test(mapnik::parameters const& params)
|
||||||
: test_case(params),
|
: test_case(params)
|
||||||
value_("123456789") {}
|
, value_("123456789")
|
||||||
|
{}
|
||||||
bool validate() const
|
bool validate() const
|
||||||
{
|
{
|
||||||
mapnik::value_integer result = 0;
|
mapnik::value_integer result = 0;
|
||||||
if (!mapnik::util::string2int(value_.data(),value_.data()+value_.size(),result)) return false;
|
if (!mapnik::util::string2int(value_.data(), value_.data() + value_.size(), result))
|
||||||
if (result != 123456789) return false;
|
return false;
|
||||||
|
if (result != 123456789)
|
||||||
|
return false;
|
||||||
result = 0;
|
result = 0;
|
||||||
if (!mapnik::util::string2int(value_,result)) return false;
|
if (!mapnik::util::string2int(value_, result))
|
||||||
if (result != 123456789) return false;
|
return false;
|
||||||
|
if (result != 123456789)
|
||||||
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool operator()() const
|
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::value_integer result = 0;
|
||||||
mapnik::util::string2int(value_,result);
|
mapnik::util::string2int(value_, result);
|
||||||
mapnik::util::string2int(value_.data(),value_.data()+value_.size(),result);
|
mapnik::util::string2int(value_.data(), value_.data() + value_.size(), result);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BENCHMARK(test,"string->int")
|
BENCHMARK(test, "string->int")
|
||||||
|
|
|
@ -4,25 +4,28 @@
|
||||||
class test : public benchmark::test_case
|
class test : public benchmark::test_case
|
||||||
{
|
{
|
||||||
double value_;
|
double value_;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
test(mapnik::parameters const& params)
|
test(mapnik::parameters const& params)
|
||||||
: test_case(params),
|
: test_case(params)
|
||||||
value_(-0.1234) {}
|
, value_(-0.1234)
|
||||||
|
{}
|
||||||
bool validate() const
|
bool validate() const
|
||||||
{
|
{
|
||||||
std::string s;
|
std::string s;
|
||||||
mapnik::util::to_string(s,value_);
|
mapnik::util::to_string(s, value_);
|
||||||
return (s == "-0.1234");
|
return (s == "-0.1234");
|
||||||
}
|
}
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
std::string out;
|
std::string out;
|
||||||
for (std::size_t i=0;i<iterations_;++i) {
|
for (std::size_t i = 0; i < iterations_; ++i)
|
||||||
|
{
|
||||||
out.clear();
|
out.clear();
|
||||||
mapnik::util::to_string(out,value_);
|
mapnik::util::to_string(out, value_);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BENCHMARK(test,"to_string double->string")
|
BENCHMARK(test, "to_string double->string")
|
||||||
|
|
|
@ -4,10 +4,12 @@
|
||||||
class test : public benchmark::test_case
|
class test : public benchmark::test_case
|
||||||
{
|
{
|
||||||
double value_;
|
double value_;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
test(mapnik::parameters const& params)
|
test(mapnik::parameters const& params)
|
||||||
: test_case(params),
|
: test_case(params)
|
||||||
value_(-0.1234) {}
|
, value_(-0.1234)
|
||||||
|
{}
|
||||||
bool validate() const
|
bool validate() const
|
||||||
{
|
{
|
||||||
std::ostringstream s;
|
std::ostringstream s;
|
||||||
|
@ -17,7 +19,8 @@ public:
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
std::string out;
|
std::string out;
|
||||||
for (std::size_t i=0;i<iterations_;++i) {
|
for (std::size_t i = 0; i < iterations_; ++i)
|
||||||
|
{
|
||||||
std::ostringstream s;
|
std::ostringstream s;
|
||||||
s << value_;
|
s << value_;
|
||||||
out = s.str();
|
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
|
class test : public benchmark::test_case
|
||||||
{
|
{
|
||||||
std::string utf8_;
|
std::string utf8_;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
test(mapnik::parameters const& params)
|
test(mapnik::parameters const& params)
|
||||||
: test_case(params),
|
: test_case(params)
|
||||||
utf8_(from_u8string(u8"שלום")) {}
|
, utf8_(from_u8string(u8"שלום"))
|
||||||
|
{}
|
||||||
bool validate() const
|
bool validate() const
|
||||||
{
|
{
|
||||||
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> utf32conv;
|
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> utf32conv;
|
||||||
std::u32string utf32 = utf32conv.from_bytes(utf8_);
|
std::u32string utf32 = utf32conv.from_bytes(utf8_);
|
||||||
if (utf32.size() != 4) return false;
|
if (utf32.size() != 4)
|
||||||
if (utf32[0] != 0x5e9 &&
|
return false;
|
||||||
utf32[1] != 0x5dc &&
|
if (utf32[0] != 0x5e9 && utf32[1] != 0x5dc && utf32[2] != 0x5d5 && utf32[3] != 0x5dd)
|
||||||
utf32[2] != 0x5d5 &&
|
return false;
|
||||||
utf32[3] != 0x5dd) return false;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
std::u32string utf32;
|
std::u32string utf32;
|
||||||
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> utf32conv;
|
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> utf32conv;
|
||||||
for (std::size_t i=0;i<iterations_;++i) {
|
for (std::size_t i = 0; i < iterations_; ++i)
|
||||||
utf32 = utf32conv.from_bytes(utf8_);
|
{
|
||||||
|
utf32 = utf32conv.from_bytes(utf8_);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -44,26 +46,28 @@ public:
|
||||||
class test2 : public benchmark::test_case
|
class test2 : public benchmark::test_case
|
||||||
{
|
{
|
||||||
std::string utf8_;
|
std::string utf8_;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
test2(mapnik::parameters const& params)
|
test2(mapnik::parameters const& params)
|
||||||
: test_case(params),
|
: test_case(params)
|
||||||
utf8_(from_u8string(u8"שלום")) {}
|
, utf8_(from_u8string(u8"שלום"))
|
||||||
|
{}
|
||||||
bool validate() const
|
bool validate() const
|
||||||
{
|
{
|
||||||
std::u32string utf32 = boost::locale::conv::utf_to_utf<char32_t>(utf8_);
|
std::u32string utf32 = boost::locale::conv::utf_to_utf<char32_t>(utf8_);
|
||||||
if (utf32.size() != 4) return false;
|
if (utf32.size() != 4)
|
||||||
if (utf32[0] != 0x5e9 &&
|
return false;
|
||||||
utf32[1] != 0x5dc &&
|
if (utf32[0] != 0x5e9 && utf32[1] != 0x5dc && utf32[2] != 0x5d5 && utf32[3] != 0x5dd)
|
||||||
utf32[2] != 0x5d5 &&
|
return false;
|
||||||
utf32[3] != 0x5dd) return false;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
std::u32string utf32;
|
std::u32string utf32;
|
||||||
for (std::size_t i=0;i<iterations_;++i) {
|
for (std::size_t i = 0; i < iterations_; ++i)
|
||||||
utf32 = boost::locale::conv::utf_to_utf<char32_t>(utf8_);
|
{
|
||||||
}
|
utf32 = boost::locale::conv::utf_to_utf<char32_t>(utf8_);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -71,28 +75,30 @@ public:
|
||||||
class test3 : public benchmark::test_case
|
class test3 : public benchmark::test_case
|
||||||
{
|
{
|
||||||
std::string utf8_;
|
std::string utf8_;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
test3(mapnik::parameters const& params)
|
test3(mapnik::parameters const& params)
|
||||||
: test_case(params),
|
: test_case(params)
|
||||||
utf8_(from_u8string(u8"שלום")) {}
|
, utf8_(from_u8string(u8"שלום"))
|
||||||
|
{}
|
||||||
bool validate() const
|
bool validate() const
|
||||||
{
|
{
|
||||||
mapnik::transcoder tr_("utf-8");
|
mapnik::transcoder tr_("utf-8");
|
||||||
mapnik::value_unicode_string utf32 = tr_.transcode(utf8_.data(),utf8_.size());
|
mapnik::value_unicode_string utf32 = tr_.transcode(utf8_.data(), utf8_.size());
|
||||||
//std::u32string utf32 = boost::locale::conv::utf_to_utf<char32_t>(utf8_);
|
// std::u32string utf32 = boost::locale::conv::utf_to_utf<char32_t>(utf8_);
|
||||||
if (utf32.length() != 4) return false;
|
if (utf32.length() != 4)
|
||||||
if (utf32[0] != 0x5e9 &&
|
return false;
|
||||||
utf32[1] != 0x5dc &&
|
if (utf32[0] != 0x5e9 && utf32[1] != 0x5dc && utf32[2] != 0x5d5 && utf32[3] != 0x5dd)
|
||||||
utf32[2] != 0x5d5 &&
|
return false;
|
||||||
utf32[3] != 0x5dd) return false;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool operator()() const
|
bool operator()() const
|
||||||
{
|
{
|
||||||
mapnik::transcoder tr_("utf-8");
|
mapnik::transcoder tr_("utf-8");
|
||||||
mapnik::value_unicode_string utf32;
|
mapnik::value_unicode_string utf32;
|
||||||
for (std::size_t i=0;i<iterations_;++i) {
|
for (std::size_t i = 0; i < iterations_; ++i)
|
||||||
utf32 = tr_.transcode(utf8_.data(),utf8_.size());
|
{
|
||||||
|
utf32 = tr_.transcode(utf8_.data(), utf8_.size());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -101,17 +107,17 @@ public:
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
mapnik::parameters params;
|
mapnik::parameters params;
|
||||||
benchmark::handle_args(argc,argv,params);
|
benchmark::handle_args(argc, argv, params);
|
||||||
int return_value = 0;
|
int return_value = 0;
|
||||||
#ifndef __linux__
|
#ifndef __linux__
|
||||||
test test_runner(params);
|
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
|
#else
|
||||||
std::clog << "skipping 'utf encode std::codecvt' test since <codecvt> is not supported on __linux__\n";
|
std::clog << "skipping 'utf encode std::codecvt' test since <codecvt> is not supported on __linux__\n";
|
||||||
#endif
|
#endif
|
||||||
test2 test_runner2(params);
|
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);
|
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;
|
return return_value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,16 +2,12 @@
|
||||||
|
|
||||||
class test : public benchmark::test_case
|
class test : public benchmark::test_case
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
test(mapnik::parameters const& params)
|
test(mapnik::parameters const& params)
|
||||||
: test_case(params) {}
|
: test_case(params)
|
||||||
bool validate() const
|
{}
|
||||||
{
|
bool validate() const { return true; }
|
||||||
return true;
|
void operator()() const {}
|
||||||
}
|
|
||||||
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>
|
#include <iostream>
|
||||||
|
|
||||||
|
int main(int, char**)
|
||||||
int main ( int, char** )
|
|
||||||
{
|
{
|
||||||
using namespace mapnik;
|
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_lcc =
|
||||||
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";
|
"+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";
|
std::cout << " running demo ... \n";
|
||||||
datasource_cache::instance().register_datasources("plugins/input/");
|
datasource_cache::instance().register_datasources("plugins/input/");
|
||||||
freetype_engine::register_font("fonts/dejavu-fonts-ttf-2.37/ttf/DejaVuSans.ttf");
|
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_background(parse_color("white"));
|
||||||
m.set_srs(srs_merc);
|
m.set_srs(srs_merc);
|
||||||
// create styles
|
// create styles
|
||||||
|
@ -93,13 +95,13 @@ int main ( int, char** )
|
||||||
rule r;
|
rule r;
|
||||||
{
|
{
|
||||||
line_symbolizer line_sym;
|
line_symbolizer line_sym;
|
||||||
put(line_sym,keys::stroke,color(0,0,0));
|
put(line_sym, keys::stroke, color(0, 0, 0));
|
||||||
put(line_sym,keys::stroke_width,1.0);
|
put(line_sym, keys::stroke_width, 1.0);
|
||||||
dash_array dash;
|
dash_array dash;
|
||||||
dash.emplace_back(8,4);
|
dash.emplace_back(8, 4);
|
||||||
dash.emplace_back(2,2);
|
dash.emplace_back(2, 2);
|
||||||
dash.emplace_back(2,2);
|
dash.emplace_back(2, 2);
|
||||||
put(line_sym,keys::stroke_dasharray,dash);
|
put(line_sym, keys::stroke_dasharray, dash);
|
||||||
r.append(std::move(line_sym));
|
r.append(std::move(line_sym));
|
||||||
}
|
}
|
||||||
provlines_style.add_rule(std::move(r));
|
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"));
|
r.set_filter(parse_expression("[CLASS] = 3 or [CLASS] = 4"));
|
||||||
{
|
{
|
||||||
line_symbolizer line_sym;
|
line_symbolizer line_sym;
|
||||||
put(line_sym,keys::stroke,color(171,158,137));
|
put(line_sym, keys::stroke, color(171, 158, 137));
|
||||||
put(line_sym,keys::stroke_width,2.0);
|
put(line_sym, keys::stroke_width, 2.0);
|
||||||
put(line_sym,keys::stroke_linecap,ROUND_CAP);
|
put(line_sym, keys::stroke_linecap, ROUND_CAP);
|
||||||
put(line_sym,keys::stroke_linejoin,ROUND_JOIN);
|
put(line_sym, keys::stroke_linejoin, ROUND_JOIN);
|
||||||
r.append(std::move(line_sym));
|
r.append(std::move(line_sym));
|
||||||
}
|
}
|
||||||
roads34_style.add_rule(std::move(r));
|
roads34_style.add_rule(std::move(r));
|
||||||
|
@ -144,10 +146,10 @@ int main ( int, char** )
|
||||||
r.set_filter(parse_expression("[CLASS] = 2"));
|
r.set_filter(parse_expression("[CLASS] = 2"));
|
||||||
{
|
{
|
||||||
line_symbolizer line_sym;
|
line_symbolizer line_sym;
|
||||||
put(line_sym,keys::stroke,color(171,158,137));
|
put(line_sym, keys::stroke, color(171, 158, 137));
|
||||||
put(line_sym,keys::stroke_width,4.0);
|
put(line_sym, keys::stroke_width, 4.0);
|
||||||
put(line_sym,keys::stroke_linecap,ROUND_CAP);
|
put(line_sym, keys::stroke_linecap, ROUND_CAP);
|
||||||
put(line_sym,keys::stroke_linejoin,ROUND_JOIN);
|
put(line_sym, keys::stroke_linejoin, ROUND_JOIN);
|
||||||
r.append(std::move(line_sym));
|
r.append(std::move(line_sym));
|
||||||
}
|
}
|
||||||
roads2_style_1.add_rule(std::move(r));
|
roads2_style_1.add_rule(std::move(r));
|
||||||
|
@ -160,10 +162,10 @@ int main ( int, char** )
|
||||||
r.set_filter(parse_expression("[CLASS] = 2"));
|
r.set_filter(parse_expression("[CLASS] = 2"));
|
||||||
{
|
{
|
||||||
line_symbolizer line_sym;
|
line_symbolizer line_sym;
|
||||||
put(line_sym,keys::stroke,color(255,250,115));
|
put(line_sym, keys::stroke, color(255, 250, 115));
|
||||||
put(line_sym,keys::stroke_width,2.0);
|
put(line_sym, keys::stroke_width, 2.0);
|
||||||
put(line_sym,keys::stroke_linecap,ROUND_CAP);
|
put(line_sym, keys::stroke_linecap, ROUND_CAP);
|
||||||
put(line_sym,keys::stroke_linejoin,ROUND_JOIN);
|
put(line_sym, keys::stroke_linejoin, ROUND_JOIN);
|
||||||
r.append(std::move(line_sym));
|
r.append(std::move(line_sym));
|
||||||
}
|
}
|
||||||
roads2_style_2.add_rule(std::move(r));
|
roads2_style_2.add_rule(std::move(r));
|
||||||
|
@ -177,10 +179,10 @@ int main ( int, char** )
|
||||||
r.set_filter(parse_expression("[CLASS] = 1"));
|
r.set_filter(parse_expression("[CLASS] = 1"));
|
||||||
{
|
{
|
||||||
line_symbolizer line_sym;
|
line_symbolizer line_sym;
|
||||||
put(line_sym,keys::stroke,color(188,149,28));
|
put(line_sym, keys::stroke, color(188, 149, 28));
|
||||||
put(line_sym,keys::stroke_width,7.0);
|
put(line_sym, keys::stroke_width, 7.0);
|
||||||
put(line_sym,keys::stroke_linecap,ROUND_CAP);
|
put(line_sym, keys::stroke_linecap, ROUND_CAP);
|
||||||
put(line_sym,keys::stroke_linejoin,ROUND_JOIN);
|
put(line_sym, keys::stroke_linejoin, ROUND_JOIN);
|
||||||
r.append(std::move(line_sym));
|
r.append(std::move(line_sym));
|
||||||
}
|
}
|
||||||
roads1_style_1.add_rule(std::move(r));
|
roads1_style_1.add_rule(std::move(r));
|
||||||
|
@ -193,10 +195,10 @@ int main ( int, char** )
|
||||||
r.set_filter(parse_expression("[CLASS] = 1"));
|
r.set_filter(parse_expression("[CLASS] = 1"));
|
||||||
{
|
{
|
||||||
line_symbolizer line_sym;
|
line_symbolizer line_sym;
|
||||||
put(line_sym,keys::stroke,color(242,191,36));
|
put(line_sym, keys::stroke, color(242, 191, 36));
|
||||||
put(line_sym,keys::stroke_width,5.0);
|
put(line_sym, keys::stroke_width, 5.0);
|
||||||
put(line_sym,keys::stroke_linecap,ROUND_CAP);
|
put(line_sym, keys::stroke_linecap, ROUND_CAP);
|
||||||
put(line_sym,keys::stroke_linejoin,ROUND_JOIN);
|
put(line_sym, keys::stroke_linejoin, ROUND_JOIN);
|
||||||
r.append(std::move(line_sym));
|
r.append(std::move(line_sym));
|
||||||
}
|
}
|
||||||
roads1_style_2.add_rule(std::move(r));
|
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>();
|
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.face_name = "DejaVu Sans Book";
|
||||||
placement_finder->defaults.format_defaults.text_size = 10.0;
|
placement_finder->defaults.format_defaults.text_size = 10.0;
|
||||||
placement_finder->defaults.format_defaults.fill = color(0,0,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.halo_fill = color(255, 255, 200);
|
||||||
placement_finder->defaults.format_defaults.halo_radius = 1.0;
|
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);
|
put<text_placements_ptr>(text_sym, keys::text_placements_, placement_finder);
|
||||||
r.append(std::move(text_sym));
|
r.append(std::move(text_sym));
|
||||||
}
|
}
|
||||||
|
@ -228,9 +231,9 @@ int main ( int, char** )
|
||||||
// Provincial polygons
|
// Provincial polygons
|
||||||
{
|
{
|
||||||
parameters p;
|
parameters p;
|
||||||
p["type"]="shape";
|
p["type"] = "shape";
|
||||||
p["file"]="demo/data/boundaries";
|
p["file"] = "demo/data/boundaries";
|
||||||
p["encoding"]="utf8";
|
p["encoding"] = "utf8";
|
||||||
|
|
||||||
layer lyr("Provinces");
|
layer lyr("Provinces");
|
||||||
lyr.set_datasource(datasource_cache::instance().create(p));
|
lyr.set_datasource(datasource_cache::instance().create(p));
|
||||||
|
@ -242,8 +245,8 @@ int main ( int, char** )
|
||||||
// Drainage
|
// Drainage
|
||||||
{
|
{
|
||||||
parameters p;
|
parameters p;
|
||||||
p["type"]="shape";
|
p["type"] = "shape";
|
||||||
p["file"]="demo/data/qcdrainage";
|
p["file"] = "demo/data/qcdrainage";
|
||||||
layer lyr("Quebec Hydrography");
|
layer lyr("Quebec Hydrography");
|
||||||
lyr.set_datasource(datasource_cache::instance().create(p));
|
lyr.set_datasource(datasource_cache::instance().create(p));
|
||||||
lyr.set_srs(srs_lcc);
|
lyr.set_srs(srs_lcc);
|
||||||
|
@ -253,8 +256,8 @@ int main ( int, char** )
|
||||||
|
|
||||||
{
|
{
|
||||||
parameters p;
|
parameters p;
|
||||||
p["type"]="shape";
|
p["type"] = "shape";
|
||||||
p["file"]="demo/data/ontdrainage";
|
p["file"] = "demo/data/ontdrainage";
|
||||||
layer lyr("Ontario Hydrography");
|
layer lyr("Ontario Hydrography");
|
||||||
lyr.set_datasource(datasource_cache::instance().create(p));
|
lyr.set_datasource(datasource_cache::instance().create(p));
|
||||||
lyr.set_srs(srs_lcc);
|
lyr.set_srs(srs_lcc);
|
||||||
|
@ -265,8 +268,8 @@ int main ( int, char** )
|
||||||
// Provincial boundaries
|
// Provincial boundaries
|
||||||
{
|
{
|
||||||
parameters p;
|
parameters p;
|
||||||
p["type"]="shape";
|
p["type"] = "shape";
|
||||||
p["file"]="demo/data/boundaries_l";
|
p["file"] = "demo/data/boundaries_l";
|
||||||
layer lyr("Provincial borders");
|
layer lyr("Provincial borders");
|
||||||
lyr.set_srs(srs_lcc);
|
lyr.set_srs(srs_lcc);
|
||||||
lyr.set_datasource(datasource_cache::instance().create(p));
|
lyr.set_datasource(datasource_cache::instance().create(p));
|
||||||
|
@ -277,8 +280,8 @@ int main ( int, char** )
|
||||||
// Roads
|
// Roads
|
||||||
{
|
{
|
||||||
parameters p;
|
parameters p;
|
||||||
p["type"]="shape";
|
p["type"] = "shape";
|
||||||
p["file"]="demo/data/roads";
|
p["file"] = "demo/data/roads";
|
||||||
layer lyr("Roads");
|
layer lyr("Roads");
|
||||||
lyr.set_srs(srs_lcc);
|
lyr.set_srs(srs_lcc);
|
||||||
lyr.set_datasource(datasource_cache::instance().create(p));
|
lyr.set_datasource(datasource_cache::instance().create(p));
|
||||||
|
@ -293,8 +296,8 @@ int main ( int, char** )
|
||||||
// popplaces
|
// popplaces
|
||||||
{
|
{
|
||||||
parameters p;
|
parameters p;
|
||||||
p["type"]="shape";
|
p["type"] = "shape";
|
||||||
p["file"]="demo/data/popplaces";
|
p["file"] = "demo/data/popplaces";
|
||||||
p["encoding"] = "utf8";
|
p["encoding"] = "utf8";
|
||||||
layer lyr("Populated Places");
|
layer lyr("Populated Places");
|
||||||
lyr.set_srs(srs_lcc);
|
lyr.set_srs(srs_lcc);
|
||||||
|
@ -303,28 +306,28 @@ int main ( int, char** )
|
||||||
m.add_layer(lyr);
|
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());
|
image_rgba8 buf(m.width(), m.height());
|
||||||
agg_renderer<image_rgba8> ren(m,buf);
|
agg_renderer<image_rgba8> ren(m, buf);
|
||||||
ren.apply();
|
ren.apply();
|
||||||
std::string msg("These maps have been rendered using AGG in the current directory:\n");
|
std::string msg("These maps have been rendered using AGG in the current directory:\n");
|
||||||
#ifdef HAVE_JPEG
|
#ifdef HAVE_JPEG
|
||||||
save_to_file(buf,"demo.jpg","jpeg");
|
save_to_file(buf, "demo.jpg", "jpeg");
|
||||||
msg += "- demo.jpg\n";
|
msg += "- demo.jpg\n";
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_PNG
|
#ifdef HAVE_PNG
|
||||||
save_to_file(buf,"demo.png","png");
|
save_to_file(buf, "demo.png", "png");
|
||||||
save_to_file(buf,"demo256.png","png8");
|
save_to_file(buf, "demo256.png", "png8");
|
||||||
msg += "- demo.png\n";
|
msg += "- demo.png\n";
|
||||||
msg += "- demo256.png\n";
|
msg += "- demo256.png\n";
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_TIFF
|
#ifdef HAVE_TIFF
|
||||||
save_to_file(buf,"demo.tif","tiff");
|
save_to_file(buf, "demo.tif", "tiff");
|
||||||
msg += "- demo.tif\n";
|
msg += "- demo.tif\n";
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_WEBP
|
#ifdef HAVE_WEBP
|
||||||
save_to_file(buf,"demo.webp","webp");
|
save_to_file(buf, "demo.webp", "webp");
|
||||||
msg += "- demo.webp\n";
|
msg += "- demo.webp\n";
|
||||||
#endif
|
#endif
|
||||||
msg += "Have a look!\n";
|
msg += "Have a look!\n";
|
||||||
|
@ -332,8 +335,8 @@ int main ( int, char** )
|
||||||
|
|
||||||
#if defined(HAVE_CAIRO)
|
#if defined(HAVE_CAIRO)
|
||||||
// save to pdf/svg files
|
// save to pdf/svg files
|
||||||
save_to_cairo_file(m,"cairo-demo.pdf");
|
save_to_cairo_file(m, "cairo-demo.pdf");
|
||||||
save_to_cairo_file(m,"cairo-demo.svg");
|
save_to_cairo_file(m, "cairo-demo.svg");
|
||||||
|
|
||||||
/* we could also do:
|
/* we could also do:
|
||||||
|
|
||||||
|
@ -342,38 +345,36 @@ int main ( int, char** )
|
||||||
but instead let's build up a surface for more flexibility
|
but instead let's build up a surface for more flexibility
|
||||||
*/
|
*/
|
||||||
|
|
||||||
cairo_surface_ptr image_surface(
|
cairo_surface_ptr image_surface(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, m.width(), m.height()),
|
||||||
cairo_image_surface_create(CAIRO_FORMAT_ARGB32,m.width(),m.height()),
|
cairo_surface_closer());
|
||||||
cairo_surface_closer());
|
|
||||||
double scale_factor = 1.0;
|
double scale_factor = 1.0;
|
||||||
cairo_ptr image_context(create_context(image_surface));
|
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();
|
png_render.apply();
|
||||||
// we can now write to png with cairo functionality
|
// we can now write to png with cairo functionality
|
||||||
cairo_surface_write_to_png(&*image_surface, "cairo-demo.png");
|
cairo_surface_write_to_png(&*image_surface, "cairo-demo.png");
|
||||||
// but we can also benefit from quantization by converting
|
// but we can also benefit from quantization by converting
|
||||||
// to a mapnik image object and then saving that
|
// 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);
|
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);
|
cairo_surface_finish(&*image_surface);
|
||||||
|
|
||||||
std::cout << "Three maps have been rendered using Cairo in the current directory:\n"
|
std::cout << "Three maps have been rendered using Cairo in the current directory:\n"
|
||||||
"- cairo-demo.png\n"
|
"- cairo-demo.png\n"
|
||||||
"- cairo-demo256.png\n"
|
"- cairo-demo256.png\n"
|
||||||
"- cairo-demo.pdf\n"
|
"- cairo-demo.pdf\n"
|
||||||
"- cairo-demo.svg\n"
|
"- cairo-demo.svg\n"
|
||||||
"Have a look!\n";
|
"Have a look!\n";
|
||||||
#endif
|
#endif
|
||||||
// save map definition (data + style)
|
// save map definition (data + style)
|
||||||
save_map(m, "map.xml");
|
save_map(m, "map.xml");
|
||||||
}
|
} catch (std::exception const& ex)
|
||||||
catch ( std::exception const& ex )
|
|
||||||
{
|
{
|
||||||
std::cerr << "### std::exception: " << ex.what() << std::endl;
|
std::cerr << "### std::exception: " << ex.what() << std::endl;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
} catch (...)
|
||||||
catch ( ... )
|
|
||||||
{
|
{
|
||||||
std::cerr << "### Unknown exception." << std::endl;
|
std::cerr << "### Unknown exception." << std::endl;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
|
@ -17,12 +17,10 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "about_dialog.hpp"
|
#include "about_dialog.hpp"
|
||||||
|
|
||||||
|
about_dialog::about_dialog(QWidget* parent)
|
||||||
about_dialog::about_dialog(QWidget *parent)
|
: QDialog(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.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if !defined ABOUT_DIALOG_HPP
|
#if !defined ABOUT_DIALOG_HPP
|
||||||
#define ABOUT_DIALOG_HPP
|
#define ABOUT_DIALOG_HPP
|
||||||
|
|
||||||
|
@ -27,12 +25,12 @@
|
||||||
|
|
||||||
class about_dialog : public QDialog
|
class about_dialog : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
about_dialog(QWidget * parent = 0);
|
about_dialog(QWidget* parent = 0);
|
||||||
private:
|
|
||||||
Ui::Dialog ui;
|
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.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "info_dialog.hpp"
|
#include "info_dialog.hpp"
|
||||||
|
|
||||||
|
info_dialog::info_dialog(QVector<QPair<QString, QString>> const& info, QWidget* parent)
|
||||||
info_dialog::info_dialog(QVector<QPair<QString,QString> > const& info, QWidget *parent)
|
: QDialog(parent)
|
||||||
: QDialog(parent)
|
|
||||||
{
|
{
|
||||||
ui.setupUi(this);
|
ui.setupUi(this);
|
||||||
ui.tableWidget->setHorizontalHeaderItem(0,new QTableWidgetItem("Name"));
|
ui.tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem("Name"));
|
||||||
ui.tableWidget->setHorizontalHeaderItem(1,new QTableWidgetItem("Value"));
|
ui.tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem("Value"));
|
||||||
|
|
||||||
ui.tableWidget->setRowCount(info.size());
|
ui.tableWidget->setRowCount(info.size());
|
||||||
ui.tableWidget->setColumnCount(2);
|
ui.tableWidget->setColumnCount(2);
|
||||||
for (int i=0;i<info.size();++i)
|
for (int i = 0; i < info.size(); ++i)
|
||||||
{
|
{
|
||||||
QTableWidgetItem *keyItem = new QTableWidgetItem(info[i].first);
|
QTableWidgetItem* keyItem = new QTableWidgetItem(info[i].first);
|
||||||
QTableWidgetItem *valueItem = new QTableWidgetItem(info[i].second);
|
QTableWidgetItem* valueItem = new QTableWidgetItem(info[i].second);
|
||||||
ui.tableWidget->setItem(i,0,keyItem);
|
ui.tableWidget->setItem(i, 0, keyItem);
|
||||||
ui.tableWidget->setItem(i,1,valueItem);
|
ui.tableWidget->setItem(i, 1, valueItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,6 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef INFO_DIALOG_HPP
|
#ifndef INFO_DIALOG_HPP
|
||||||
#define INFO_DIALOG_HPP
|
#define INFO_DIALOG_HPP
|
||||||
|
|
||||||
|
@ -27,12 +25,12 @@
|
||||||
|
|
||||||
class info_dialog : public QDialog
|
class info_dialog : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
info_dialog(QVector<QPair<QString,QString> > const& info,QWidget * parent = 0);
|
info_dialog(QVector<QPair<QString, QString>> const& info, QWidget* parent = 0);
|
||||||
private:
|
|
||||||
Ui::InfoDialog ui;
|
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.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "layer_info_dialog.hpp"
|
#include "layer_info_dialog.hpp"
|
||||||
|
|
||||||
// mapnik
|
// mapnik
|
||||||
|
@ -26,14 +25,13 @@
|
||||||
#include <mapnik/params_impl.hpp>
|
#include <mapnik/params_impl.hpp>
|
||||||
#include <mapnik/layer.hpp>
|
#include <mapnik/layer.hpp>
|
||||||
|
|
||||||
|
layer_info_dialog::layer_info_dialog(mapnik::layer& lay, QWidget* parent)
|
||||||
layer_info_dialog::layer_info_dialog(mapnik::layer& lay, QWidget *parent)
|
: QDialog(parent)
|
||||||
: QDialog(parent)
|
|
||||||
{
|
{
|
||||||
ui.setupUi(this);
|
ui.setupUi(this);
|
||||||
|
|
||||||
ui.tableWidget->setHorizontalHeaderItem(0,new QTableWidgetItem("Name"));
|
ui.tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem("Name"));
|
||||||
ui.tableWidget->setHorizontalHeaderItem(1,new QTableWidgetItem("Value"));
|
ui.tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem("Value"));
|
||||||
|
|
||||||
// Layer name
|
// Layer name
|
||||||
ui.layerNameEdit->setText(QString(lay.name().c_str()));
|
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);
|
ui.tableWidget->setColumnCount(2);
|
||||||
|
|
||||||
mapnik::parameters::const_iterator pos;
|
mapnik::parameters::const_iterator pos;
|
||||||
int index=0;
|
int index = 0;
|
||||||
for (pos = ps.begin();pos != ps.end();++pos)
|
for (pos = ps.begin(); pos != ps.end(); ++pos)
|
||||||
{
|
{
|
||||||
boost::optional<std::string> result;
|
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)
|
if (result)
|
||||||
{
|
{
|
||||||
QTableWidgetItem *keyItem = new QTableWidgetItem(QString(pos->first.c_str()));
|
QTableWidgetItem* keyItem = new QTableWidgetItem(QString(pos->first.c_str()));
|
||||||
QTableWidgetItem *valueItem = new QTableWidgetItem(QString((*result).c_str()));
|
QTableWidgetItem* valueItem = new QTableWidgetItem(QString((*result).c_str()));
|
||||||
ui.tableWidget->setItem(index,0,keyItem);
|
ui.tableWidget->setItem(index, 0, keyItem);
|
||||||
ui.tableWidget->setItem(index,1,valueItem);
|
ui.tableWidget->setItem(index, 1, valueItem);
|
||||||
++index;
|
++index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,5 +67,5 @@ layer_info_dialog::layer_info_dialog(mapnik::layer& lay, QWidget *parent)
|
||||||
|
|
||||||
Ui::LayerInfoDialog& layer_info_dialog::getUI()
|
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.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef LAYER_INFO_DIALOG_HPP
|
#ifndef LAYER_INFO_DIALOG_HPP
|
||||||
#define LAYER_INFO_DIALOG_HPP
|
#define LAYER_INFO_DIALOG_HPP
|
||||||
|
|
||||||
#include "ui_layer_info.h"
|
#include "ui_layer_info.h"
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
class layer;
|
class layer;
|
||||||
}
|
}
|
||||||
|
|
||||||
class layer_info_dialog : public QDialog
|
class layer_info_dialog : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
layer_info_dialog(mapnik::layer& l, QWidget * parent = 0);
|
layer_info_dialog(mapnik::layer& l, QWidget* parent = 0);
|
||||||
Ui::LayerInfoDialog& getUI();
|
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.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
#include "layerdelegate.hpp"
|
#include "layerdelegate.hpp"
|
||||||
|
|
||||||
LayerDelegate::LayerDelegate(QObject *parent)
|
LayerDelegate::LayerDelegate(QObject* parent)
|
||||||
: QAbstractItemDelegate(parent)
|
: QAbstractItemDelegate(parent)
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
void LayerDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
void LayerDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||||
const QModelIndex &index) const
|
|
||||||
{
|
{
|
||||||
painter->setRenderHint(QPainter::Antialiasing);
|
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)
|
if (option.state & QStyle::State_Selected)
|
||||||
painter->setBrush(QBrush(QColor(0, 0, 255, 64)));
|
painter->setBrush(QBrush(QColor(0, 0, 255, 64)));
|
||||||
else
|
else
|
||||||
painter->setBrush(QBrush(QColor(255, 0, 0, 64)));
|
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)
|
if (option.state & QStyle::State_Selected)
|
||||||
painter->setBrush(option.palette.highlightedText());
|
painter->setBrush(option.palette.highlightedText());
|
||||||
else
|
else
|
||||||
painter->setBrush(QBrush(QColor(255, 120, 0, 127)));
|
painter->setBrush(QBrush(QColor(255, 120, 0, 127)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize LayerDelegate::sizeHint(const QStyleOptionViewItem & /* option */,
|
QSize LayerDelegate::sizeHint(const QStyleOptionViewItem& /* option */, const QModelIndex& /* index */) const
|
||||||
const QModelIndex & /* index */) const
|
|
||||||
{
|
{
|
||||||
return QSize(120,24);
|
return QSize(120, 24);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,12 +33,10 @@ class LayerDelegate : public QAbstractItemDelegate
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LayerDelegate(QObject *parent = 0);
|
LayerDelegate(QObject* parent = 0);
|
||||||
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
||||||
const QModelIndex &index) const;
|
QSize sizeHint(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.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "layerlistmodel.hpp"
|
#include "layerlistmodel.hpp"
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QBrush>
|
#include <QBrush>
|
||||||
|
@ -26,14 +24,16 @@
|
||||||
|
|
||||||
using mapnik::Map;
|
using mapnik::Map;
|
||||||
|
|
||||||
LayerListModel::LayerListModel(std::shared_ptr<Map> map, QObject *parent)
|
LayerListModel::LayerListModel(std::shared_ptr<Map> map, QObject* parent)
|
||||||
: QAbstractListModel(parent),
|
: QAbstractListModel(parent)
|
||||||
map_(map) {}
|
, map_(map)
|
||||||
|
{}
|
||||||
|
|
||||||
int LayerListModel::rowCount(QModelIndex const&) const
|
int LayerListModel::rowCount(QModelIndex const&) const
|
||||||
{
|
{
|
||||||
if (map_) return map_->layers().size();
|
if (map_)
|
||||||
return 0;
|
return map_->layers().size();
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant LayerListModel::data(QModelIndex const& index, int role) const
|
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)
|
else if (role == Qt::CheckStateRole)
|
||||||
{
|
{
|
||||||
if (map_->layers().at(index.row()).active())
|
if (map_->layers().at(index.row()).active())
|
||||||
return QVariant(Qt::Checked);
|
return QVariant(Qt::Checked);
|
||||||
else
|
else
|
||||||
return QVariant(Qt::Unchecked);
|
return QVariant(Qt::Unchecked);
|
||||||
}
|
}
|
||||||
else if (role == Qt::ForegroundRole)
|
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,
|
QVariant LayerListModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
int role) const
|
|
||||||
{
|
{
|
||||||
if (role != Qt::DisplayRole)
|
if (role != Qt::DisplayRole)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
@ -88,37 +87,37 @@ QVariant LayerListModel::headerData(int section, Qt::Orientation orientation,
|
||||||
return QString("TODO Row %1").arg(section);
|
return QString("TODO Row %1").arg(section);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LayerListModel::setData(const QModelIndex &index,
|
bool LayerListModel::setData(const QModelIndex& index, const QVariant& value, int role)
|
||||||
const QVariant &value, int role)
|
|
||||||
{
|
{
|
||||||
if (!map_) return false;
|
if (!map_)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (index.isValid() && role == Qt::CheckStateRole)
|
if (index.isValid() && role == Qt::CheckStateRole)
|
||||||
{
|
{
|
||||||
int status = value.toInt();
|
int status = value.toInt();
|
||||||
std::vector<mapnik::layer> & layers = const_cast<std::vector<mapnik::layer>& >(map_->layers());
|
std::vector<mapnik::layer>& layers = const_cast<std::vector<mapnik::layer>&>(map_->layers());
|
||||||
layers.at(index.row()).set_active(status);
|
layers.at(index.row()).set_active(status);
|
||||||
emit dataChanged(index, index);
|
emit dataChanged(index, index);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt::ItemFlags LayerListModel::flags(QModelIndex const& index) const
|
Qt::ItemFlags LayerListModel::flags(QModelIndex const& index) const
|
||||||
{
|
{
|
||||||
Qt::ItemFlags flags = QAbstractItemModel::flags(index);
|
Qt::ItemFlags flags = QAbstractItemModel::flags(index);
|
||||||
if (index.isValid())
|
if (index.isValid())
|
||||||
flags |= Qt::ItemIsUserCheckable;
|
flags |= Qt::ItemIsUserCheckable;
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::optional<mapnik::layer&> LayerListModel::map_layer(int i)
|
boost::optional<mapnik::layer&> LayerListModel::map_layer(int i)
|
||||||
{
|
{
|
||||||
if (map_)
|
if (map_)
|
||||||
{
|
{
|
||||||
std::vector<mapnik::layer> & layers = const_cast<std::vector<mapnik::layer>& >(map_->layers());
|
std::vector<mapnik::layer>& layers = const_cast<std::vector<mapnik::layer>&>(map_->layers());
|
||||||
if (i < int(layers.size()))
|
if (i < int(layers.size()))
|
||||||
return boost::optional<mapnik::layer&>(layers[i]);
|
return boost::optional<mapnik::layer&>(layers[i]);
|
||||||
}
|
}
|
||||||
return boost::optional<mapnik::layer&>();
|
return boost::optional<mapnik::layer&>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,6 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef LAYER_LIST_MODEL_HPP
|
#ifndef LAYER_LIST_MODEL_HPP
|
||||||
#define LAYER_LIST_MODEL_HPP
|
#define LAYER_LIST_MODEL_HPP
|
||||||
|
|
||||||
|
@ -32,20 +30,18 @@
|
||||||
|
|
||||||
class LayerListModel : public QAbstractListModel
|
class LayerListModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
LayerListModel(std::shared_ptr<mapnik::Map> map, QObject * parent = 0);
|
LayerListModel(std::shared_ptr<mapnik::Map> map, QObject* parent = 0);
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
||||||
QVariant data(const QModelIndex &index, int role) const;
|
QVariant data(const QModelIndex& index, int role) const;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation,
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||||
int role = Qt::DisplayRole) const;
|
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
||||||
bool setData(const QModelIndex &index, const QVariant &value,
|
Qt::ItemFlags flags(QModelIndex const& index) const;
|
||||||
int role = Qt::EditRole);
|
boost::optional<mapnik::layer&> map_layer(int i);
|
||||||
Qt::ItemFlags flags(QModelIndex const& index) const;
|
|
||||||
boost::optional<mapnik::layer&> map_layer(int i);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<mapnik::Map> map_;
|
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.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "layerwidget.hpp"
|
#include "layerwidget.hpp"
|
||||||
#include <qabstractitemdelegate.h>
|
#include <qabstractitemdelegate.h>
|
||||||
#include <qapplication.h>
|
#include <qapplication.h>
|
||||||
|
@ -33,65 +32,59 @@
|
||||||
#include "layer_info_dialog.hpp"
|
#include "layer_info_dialog.hpp"
|
||||||
|
|
||||||
LayerTab::LayerTab(QWidget* parent)
|
LayerTab::LayerTab(QWidget* parent)
|
||||||
: QListView(parent) {}
|
: QListView(parent)
|
||||||
|
{}
|
||||||
|
|
||||||
|
void LayerTab::paintEvent(QPaintEvent* e)
|
||||||
void LayerTab::paintEvent(QPaintEvent *e)
|
|
||||||
{
|
{
|
||||||
QListView::paintEvent(e);
|
QListView::paintEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayerTab::dataChanged(const QModelIndex &topLeft,
|
void LayerTab::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles)
|
||||||
const QModelIndex &bottomRight,
|
|
||||||
const QVector<int> &roles)
|
|
||||||
{
|
{
|
||||||
emit update_mapwidget();
|
emit update_mapwidget();
|
||||||
QListView::dataChanged(topLeft, bottomRight, roles);
|
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();
|
QModelIndexList list = selected.indexes();
|
||||||
if (list.size() != 0)
|
if (list.size() != 0)
|
||||||
{
|
{
|
||||||
qDebug("SELECTED LAYER -> %d",list[0].row());
|
qDebug("SELECTED LAYER -> %d", list[0].row());
|
||||||
emit layerSelected(list[0].row());
|
emit layerSelected(list[0].row());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayerTab::layerInfo()
|
void LayerTab::layerInfo()
|
||||||
{
|
{
|
||||||
qDebug("Layer info");
|
qDebug("Layer info");
|
||||||
QModelIndexList indexes = selectedIndexes();
|
QModelIndexList indexes = selectedIndexes();
|
||||||
if (indexes.size() > 0)
|
if (indexes.size() > 0)
|
||||||
{
|
{
|
||||||
qDebug("id = %d",indexes[0].row());
|
qDebug("id = %d", indexes[0].row());
|
||||||
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayerTab::layerInfo2(QModelIndex const& index)
|
void LayerTab::layerInfo2(QModelIndex const& index)
|
||||||
{
|
{
|
||||||
qDebug("LayerInfo id = %d",index.row());
|
qDebug("LayerInfo id = %d", index.row());
|
||||||
QVector<QPair<QString,QString> > params;
|
QVector<QPair<QString, QString>> params;
|
||||||
QVector<QString> style_names;
|
QVector<QString> style_names;
|
||||||
unsigned i = index.row();
|
unsigned i = index.row();
|
||||||
LayerListModel * model = static_cast<LayerListModel*>(this->model());
|
LayerListModel* model = static_cast<LayerListModel*>(this->model());
|
||||||
boost::optional<mapnik::layer&> layer = model->map_layer(i);
|
boost::optional<mapnik::layer&> layer = model->map_layer(i);
|
||||||
|
|
||||||
if (layer)
|
if (layer)
|
||||||
{
|
{
|
||||||
layer_info_dialog dlg(*layer,this);
|
layer_info_dialog dlg(*layer, this);
|
||||||
dlg.exec();
|
dlg.exec();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StyleTab::StyleTab(QWidget*)
|
StyleTab::StyleTab(QWidget*) {}
|
||||||
|
|
||||||
|
void StyleTab::contextMenuEvent(QContextMenuEvent* event)
|
||||||
{
|
{
|
||||||
|
qDebug("test");
|
||||||
}
|
|
||||||
|
|
||||||
void StyleTab::contextMenuEvent(QContextMenuEvent * event )
|
|
||||||
{
|
|
||||||
qDebug("test");
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef LAYERWIDGET_HPP
|
#ifndef LAYERWIDGET_HPP
|
||||||
#define LAYERWIDGET_HPP
|
#define LAYERWIDGET_HPP
|
||||||
|
|
||||||
|
@ -28,27 +27,28 @@
|
||||||
class LayerTab : public QListView
|
class LayerTab : public QListView
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
LayerTab(QWidget* parent=0);
|
LayerTab(QWidget* parent = 0);
|
||||||
void paintEvent(QPaintEvent *e);
|
void paintEvent(QPaintEvent* e);
|
||||||
signals:
|
signals:
|
||||||
void update_mapwidget();
|
void update_mapwidget();
|
||||||
void layerSelected(int) const;
|
void layerSelected(int) const;
|
||||||
public slots:
|
public slots:
|
||||||
void layerInfo();
|
void layerInfo();
|
||||||
void layerInfo2(QModelIndex const&);
|
void layerInfo2(QModelIndex const&);
|
||||||
protected slots:
|
protected slots:
|
||||||
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
|
void dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles);
|
||||||
void selectionChanged(const QItemSelection & selected, const QItemSelection &);
|
void selectionChanged(const QItemSelection& selected, const QItemSelection&);
|
||||||
};
|
};
|
||||||
|
|
||||||
class StyleTab : public QTreeView
|
class StyleTab : public QTreeView
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
StyleTab(QWidget* parent=0);
|
StyleTab(QWidget* parent = 0);
|
||||||
protected:
|
|
||||||
void contextMenuEvent(QContextMenuEvent * event );
|
protected:
|
||||||
|
void contextMenuEvent(QContextMenuEvent* event);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// qt
|
// qt
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
@ -26,27 +25,26 @@
|
||||||
#include <mapnik/font_engine_freetype.hpp>
|
#include <mapnik/font_engine_freetype.hpp>
|
||||||
#include "mainwindow.hpp"
|
#include "mainwindow.hpp"
|
||||||
|
|
||||||
int main( int argc, char **argv )
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
using mapnik::datasource_cache;
|
using mapnik::datasource_cache;
|
||||||
using mapnik::freetype_engine;
|
using mapnik::freetype_engine;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
|
||||||
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||||
#endif
|
#endif
|
||||||
QCoreApplication::setOrganizationName("Mapnik");
|
QCoreApplication::setOrganizationName("Mapnik");
|
||||||
QCoreApplication::setOrganizationDomain("mapnik.org");
|
QCoreApplication::setOrganizationDomain("mapnik.org");
|
||||||
QCoreApplication::setApplicationName("Viewer");
|
QCoreApplication::setApplicationName("Viewer");
|
||||||
QSettings settings("viewer.ini",QSettings::IniFormat);
|
QSettings settings("viewer.ini", QSettings::IniFormat);
|
||||||
|
|
||||||
// register input plug-ins
|
// register input plug-ins
|
||||||
QString plugins_dir = settings.value("mapnik/plugins_dir",
|
QString plugins_dir = settings.value("mapnik/plugins_dir", QVariant("/usr/local/lib/mapnik/input/")).toString();
|
||||||
QVariant("/usr/local/lib/mapnik/input/")).toString();
|
|
||||||
datasource_cache::instance().register_datasources(plugins_dir.toStdString());
|
datasource_cache::instance().register_datasources(plugins_dir.toStdString());
|
||||||
// register fonts
|
// register fonts
|
||||||
int count = settings.beginReadArray("mapnik/fonts");
|
int count = settings.beginReadArray("mapnik/fonts");
|
||||||
for (int index=0; index < count; ++index)
|
for (int index = 0; index < count; ++index)
|
||||||
{
|
{
|
||||||
settings.setArrayIndex(index);
|
settings.setArrayIndex(index);
|
||||||
QString font_dir = settings.value("dir").toString();
|
QString font_dir = settings.value("dir").toString();
|
||||||
|
@ -54,37 +52,40 @@ int main( int argc, char **argv )
|
||||||
}
|
}
|
||||||
settings.endArray();
|
settings.endArray();
|
||||||
|
|
||||||
QApplication app( argc, argv );
|
QApplication app(argc, argv);
|
||||||
MainWindow window;
|
MainWindow window;
|
||||||
window.show();
|
window.show();
|
||||||
if (argc > 1) window.open(argv[1]);
|
if (argc > 1)
|
||||||
|
window.open(argv[1]);
|
||||||
if (argc >= 3)
|
if (argc >= 3)
|
||||||
{
|
{
|
||||||
QStringList list = QString(argv[2]).split(",");
|
QStringList list = QString(argv[2]).split(",");
|
||||||
if (list.size()==4)
|
if (list.size() == 4)
|
||||||
{
|
{
|
||||||
bool ok;
|
bool ok;
|
||||||
double x0 = list[0].toDouble(&ok);
|
double x0 = list[0].toDouble(&ok);
|
||||||
double y0 = list[1].toDouble(&ok);
|
double y0 = list[1].toDouble(&ok);
|
||||||
double x1 = list[2].toDouble(&ok);
|
double x1 = list[2].toDouble(&ok);
|
||||||
double y1 = list[3].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
|
else
|
||||||
{
|
{
|
||||||
std::shared_ptr<mapnik::Map> map = window.get_map();
|
std::shared_ptr<mapnik::Map> map = window.get_map();
|
||||||
if (map) map->zoom_all();
|
if (map)
|
||||||
|
map->zoom_all();
|
||||||
}
|
}
|
||||||
if (argc == 4)
|
if (argc == 4)
|
||||||
{
|
{
|
||||||
bool ok;
|
bool ok;
|
||||||
double scaling_factor = QString(argv[3]).toDouble(&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();
|
return app.exec();
|
||||||
}
|
} catch (std::exception const& ex)
|
||||||
catch (std::exception const& ex)
|
|
||||||
{
|
{
|
||||||
std::cerr << "Could not start viewer: '" << ex.what() << "'\n";
|
std::cerr << "Could not start viewer: '" << ex.what() << "'\n";
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// stl
|
// stl
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
@ -58,27 +57,27 @@
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
|
|
||||||
MainWindow::MainWindow()
|
MainWindow::MainWindow()
|
||||||
: filename_(),
|
: filename_()
|
||||||
default_extent_(-20037508.3428,-20037508.3428,20037508.3428,20037508.3428)
|
, default_extent_(-20037508.3428, -20037508.3428, 20037508.3428, 20037508.3428)
|
||||||
{
|
{
|
||||||
mapWidget_ = new MapWidget(this);
|
mapWidget_ = new MapWidget(this);
|
||||||
QSplitter *splitter = new QSplitter(this);
|
QSplitter* splitter = new QSplitter(this);
|
||||||
QTabWidget *tabWidget=new QTabWidget;
|
QTabWidget* tabWidget = new QTabWidget;
|
||||||
layerTab_ = new LayerTab;
|
layerTab_ = new LayerTab;
|
||||||
layerTab_->setFocusPolicy(Qt::NoFocus);
|
layerTab_->setFocusPolicy(Qt::NoFocus);
|
||||||
layerTab_->setIconSize(QSize(16,16));
|
layerTab_->setIconSize(QSize(16, 16));
|
||||||
|
|
||||||
//LayerDelegate *delegate = new LayerDelegate(this);
|
// LayerDelegate *delegate = new LayerDelegate(this);
|
||||||
//layerTab_->setItemDelegate(delegate);
|
// layerTab_->setItemDelegate(delegate);
|
||||||
//layerTab_->setItemDelegate(new QItemDelegate(this));
|
// layerTab_->setItemDelegate(new QItemDelegate(this));
|
||||||
//layerTab_->setViewMode(QListView::IconMode);
|
// layerTab_->setViewMode(QListView::IconMode);
|
||||||
|
|
||||||
layerTab_->setFlow(QListView::TopToBottom);
|
layerTab_->setFlow(QListView::TopToBottom);
|
||||||
tabWidget->addTab(layerTab_,tr("Layers"));
|
tabWidget->addTab(layerTab_, tr("Layers"));
|
||||||
|
|
||||||
// Styles tab
|
// Styles tab
|
||||||
styleTab_ = new StyleTab;
|
styleTab_ = new StyleTab;
|
||||||
tabWidget->addTab(styleTab_,tr("Styles"));
|
tabWidget->addTab(styleTab_, tr("Styles"));
|
||||||
splitter->addWidget(tabWidget);
|
splitter->addWidget(tabWidget);
|
||||||
splitter->addWidget(mapWidget_);
|
splitter->addWidget(mapWidget_);
|
||||||
QList<int> list;
|
QList<int> list;
|
||||||
|
@ -89,7 +88,7 @@ MainWindow::MainWindow()
|
||||||
mapWidget_->setFocusPolicy(Qt::StrongFocus);
|
mapWidget_->setFocusPolicy(Qt::StrongFocus);
|
||||||
mapWidget_->setFocus();
|
mapWidget_->setFocus();
|
||||||
|
|
||||||
//setCentralWidget(mapWidget_);
|
// setCentralWidget(mapWidget_);
|
||||||
setCentralWidget(splitter);
|
setCentralWidget(splitter);
|
||||||
createActions();
|
createActions();
|
||||||
createMenus();
|
createMenus();
|
||||||
|
@ -97,29 +96,28 @@ MainWindow::MainWindow()
|
||||||
createContextMenu();
|
createContextMenu();
|
||||||
|
|
||||||
setWindowTitle(tr("Mapnik Viewer"));
|
setWindowTitle(tr("Mapnik Viewer"));
|
||||||
status=new QStatusBar(this);
|
status = new QStatusBar(this);
|
||||||
status->showMessage(tr(""));
|
status->showMessage(tr(""));
|
||||||
setStatusBar(status);
|
setStatusBar(status);
|
||||||
resize(800,600);
|
resize(800, 600);
|
||||||
|
|
||||||
//connect mapview to layerlist
|
// connect mapview to layerlist
|
||||||
connect(mapWidget_, SIGNAL(mapViewChanged()),layerTab_, SLOT(update()));
|
connect(mapWidget_, SIGNAL(mapViewChanged()), layerTab_, SLOT(update()));
|
||||||
// slider
|
// slider
|
||||||
connect(slider_,SIGNAL(valueChanged(int)),mapWidget_,SLOT(zoomToLevel(int)));
|
connect(slider_, SIGNAL(valueChanged(int)), mapWidget_, SLOT(zoomToLevel(int)));
|
||||||
// renderer selector
|
// renderer selector
|
||||||
connect(renderer_selector_,SIGNAL(currentIndexChanged(QString const&)),
|
connect(renderer_selector_,
|
||||||
mapWidget_, SLOT(updateRenderer(QString const&)));
|
SIGNAL(currentIndexChanged(QString const&)),
|
||||||
|
mapWidget_,
|
||||||
|
SLOT(updateRenderer(QString const&)));
|
||||||
|
|
||||||
// scale factor
|
// scale factor
|
||||||
connect(scale_factor_,SIGNAL(valueChanged(double)),
|
connect(scale_factor_, SIGNAL(valueChanged(double)), mapWidget_, SLOT(updateScaleFactor(double)));
|
||||||
mapWidget_, SLOT(updateScaleFactor(double)));
|
|
||||||
//
|
//
|
||||||
connect(layerTab_,SIGNAL(update_mapwidget()),mapWidget_,SLOT(updateMap()));
|
connect(layerTab_, SIGNAL(update_mapwidget()), mapWidget_, SLOT(updateMap()));
|
||||||
connect(layerTab_,SIGNAL(layerSelected(int)),
|
connect(layerTab_, SIGNAL(layerSelected(int)), mapWidget_, SLOT(layerSelected(int)));
|
||||||
mapWidget_,SLOT(layerSelected(int)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
{
|
{
|
||||||
delete mapWidget_;
|
delete mapWidget_;
|
||||||
|
@ -141,8 +139,7 @@ void MainWindow::open(QString const& path)
|
||||||
{
|
{
|
||||||
if (path.isNull())
|
if (path.isNull())
|
||||||
{
|
{
|
||||||
filename_ = QFileDialog::getOpenFileName(this,tr("Open Mapnik file"),
|
filename_ = QFileDialog::getOpenFileName(this, tr("Open Mapnik file"), currentPath, "*.xml");
|
||||||
currentPath,"*.xml");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -151,18 +148,15 @@ void MainWindow::open(QString const& path)
|
||||||
|
|
||||||
if (!filename_.isEmpty())
|
if (!filename_.isEmpty())
|
||||||
{
|
{
|
||||||
|
|
||||||
load_map_file(filename_);
|
load_map_file(filename_);
|
||||||
setWindowTitle(tr("%1 - Mapnik Viewer").arg(filename_));
|
setWindowTitle(tr("%1 - Mapnik Viewer").arg(filename_));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::reload()
|
void MainWindow::reload()
|
||||||
{
|
{
|
||||||
if (!filename_.isEmpty())
|
if (!filename_.isEmpty())
|
||||||
{
|
{
|
||||||
|
|
||||||
mapnik::box2d<double> bbox = mapWidget_->getMap()->get_current_extent();
|
mapnik::box2d<double> bbox = mapWidget_->getMap()->get_current_extent();
|
||||||
load_map_file(filename_);
|
load_map_file(filename_);
|
||||||
mapWidget_->zoomToBox(bbox);
|
mapWidget_->zoomToBox(bbox);
|
||||||
|
@ -173,39 +167,37 @@ void MainWindow::reload()
|
||||||
void MainWindow::save()
|
void MainWindow::save()
|
||||||
{
|
{
|
||||||
QString initialPath = QDir::currentPath() + "/untitled.xml";
|
QString initialPath = QDir::currentPath() + "/untitled.xml";
|
||||||
QString filename = QFileDialog::getSaveFileName(this, tr("Save"),
|
QString filename = QFileDialog::getSaveFileName(this,
|
||||||
|
tr("Save"),
|
||||||
initialPath,
|
initialPath,
|
||||||
tr("%1 Files (*.xml)")
|
tr("%1 Files (*.xml)").arg(QString("Mapnik definition")));
|
||||||
.arg(QString("Mapnik definition")));
|
|
||||||
if (!filename.isEmpty())
|
if (!filename.isEmpty())
|
||||||
{
|
{
|
||||||
std::cout<<"saving "<< filename.toStdString() << std::endl;
|
std::cout << "saving " << filename.toStdString() << std::endl;
|
||||||
mapnik::save_map(*mapWidget_->getMap(),filename.toStdString());
|
mapnik::save_map(*mapWidget_->getMap(), filename.toStdString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::load_map_file(QString const& filename)
|
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 width = mapWidget_->width();
|
||||||
unsigned height = mapWidget_->height();
|
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);
|
mapWidget_->setMap(map);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
mapnik::auto_cpu_timer t(std::clog, "loading map took: ");
|
mapnik::auto_cpu_timer t(std::clog, "loading map took: ");
|
||||||
mapnik::load_map(*map,filename.toStdString());
|
mapnik::load_map(*map, filename.toStdString());
|
||||||
}
|
} catch (std::exception const& ex)
|
||||||
catch (std::exception const& ex)
|
|
||||||
{
|
{
|
||||||
std::cout << ex.what() << "\n";
|
std::cout << ex.what() << "\n";
|
||||||
}
|
} catch (...)
|
||||||
catch (...)
|
|
||||||
{
|
{
|
||||||
std::cerr << "Exception caught in load_map\n";
|
std::cerr << "Exception caught in load_map\n";
|
||||||
}
|
}
|
||||||
layerTab_->setModel(new LayerListModel(map,this));
|
layerTab_->setModel(new LayerListModel(map, this));
|
||||||
styleTab_->setModel(new StyleModel(map,this));
|
styleTab_->setModel(new StyleModel(map, this));
|
||||||
zoom_all();
|
zoom_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,15 +244,15 @@ void MainWindow::about()
|
||||||
|
|
||||||
void MainWindow::export_as()
|
void MainWindow::export_as()
|
||||||
{
|
{
|
||||||
QAction *action = qobject_cast<QAction *>(sender());
|
QAction* action = qobject_cast<QAction*>(sender());
|
||||||
QByteArray fileFormat = action->data().toByteArray();
|
QByteArray fileFormat = action->data().toByteArray();
|
||||||
QString initialPath = QDir::currentPath() + "/map." + fileFormat;
|
QString initialPath = QDir::currentPath() + "/map." + fileFormat;
|
||||||
|
|
||||||
QString fileName = QFileDialog::getSaveFileName(this, tr("Export As"),
|
QString fileName = QFileDialog::getSaveFileName(
|
||||||
initialPath,
|
this,
|
||||||
tr("%1 Files (*.%2);;All Files (*)")
|
tr("Export As"),
|
||||||
.arg(QString(fileFormat.toUpper()))
|
initialPath,
|
||||||
.arg(QString(fileFormat)));
|
tr("%1 Files (*.%2);;All Files (*)").arg(QString(fileFormat.toUpper())).arg(QString(fileFormat)));
|
||||||
if (!fileName.isEmpty())
|
if (!fileName.isEmpty())
|
||||||
{
|
{
|
||||||
QPixmap const& pix = mapWidget_->pixmap();
|
QPixmap const& pix = mapWidget_->pixmap();
|
||||||
|
@ -270,77 +262,76 @@ void MainWindow::export_as()
|
||||||
|
|
||||||
void MainWindow::print()
|
void MainWindow::print()
|
||||||
{
|
{
|
||||||
|
// Q_ASSERT(mapWidget_->pixmap());
|
||||||
//Q_ASSERT(mapWidget_->pixmap());
|
// QPrintDialog dialog(&printer, this);
|
||||||
//QPrintDialog dialog(&printer, this);
|
// if (dialog.exec()) {
|
||||||
//if (dialog.exec()) {
|
// QPainter painter(&printer);
|
||||||
// QPainter painter(&printer);
|
// QRect rect = painter.viewport();
|
||||||
// QRect rect = painter.viewport();
|
// QSize size = mapWidget_->pixmap()->size();
|
||||||
// QSize size = mapWidget_->pixmap()->size();
|
// size.scale(rect.size(), Qt::KeepAspectRatio);
|
||||||
// size.scale(rect.size(), Qt::KeepAspectRatio);
|
// painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
|
||||||
// painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
|
// painter.setWindow(mapWidget_->pixmap()->rect());
|
||||||
// painter.setWindow(mapWidget_->pixmap()->rect());
|
// painter.drawPixmap(0, 0, *mapWidget_->pixmap());
|
||||||
// painter.drawPixmap(0, 0, *mapWidget_->pixmap());
|
// }
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::createActions()
|
void MainWindow::createActions()
|
||||||
{
|
{
|
||||||
//exportAct = new QAction(tr("&Export as ..."),this);
|
// exportAct = new QAction(tr("&Export as ..."),this);
|
||||||
//exportAct->setShortcut(tr("Ctrl+E"));
|
// exportAct->setShortcut(tr("Ctrl+E"));
|
||||||
//connect(exportAct, SIGNAL(triggered()), this, SLOT(export_as()));
|
// connect(exportAct, SIGNAL(triggered()), this, SLOT(export_as()));
|
||||||
zoomAllAct = new QAction(QIcon(":/images/home.png"),tr("Zoom All"),this);
|
zoomAllAct = new QAction(QIcon(":/images/home.png"), tr("Zoom All"), this);
|
||||||
connect(zoomAllAct, SIGNAL(triggered()), this, SLOT(zoom_all()));
|
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);
|
zoomBoxAct->setCheckable(true);
|
||||||
connect(zoomBoxAct, SIGNAL(triggered()), this, SLOT(zoom_to_box()));
|
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);
|
panAct->setCheckable(true);
|
||||||
connect(panAct, SIGNAL(triggered()), this, SLOT(pan()));
|
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);
|
infoAct->setCheckable(true);
|
||||||
connect(infoAct, SIGNAL(triggered()), this, SLOT(info()));
|
connect(infoAct, SIGNAL(triggered()), this, SLOT(info()));
|
||||||
|
|
||||||
toolsGroup=new QActionGroup(this);
|
toolsGroup = new QActionGroup(this);
|
||||||
toolsGroup->addAction(zoomBoxAct);
|
toolsGroup->addAction(zoomBoxAct);
|
||||||
toolsGroup->addAction(panAct);
|
toolsGroup->addAction(panAct);
|
||||||
toolsGroup->addAction(infoAct);
|
toolsGroup->addAction(infoAct);
|
||||||
zoomBoxAct->setChecked(true);
|
zoomBoxAct->setChecked(true);
|
||||||
|
|
||||||
openAct=new QAction(tr("Open Map definition"),this);
|
openAct = new QAction(tr("Open Map definition"), this);
|
||||||
connect(openAct,SIGNAL(triggered()),this,SLOT(open()));
|
connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
|
||||||
saveAct=new QAction(tr("Save Map definition"),this);
|
saveAct = new QAction(tr("Save Map definition"), this);
|
||||||
connect(saveAct,SIGNAL(triggered()),this,SLOT(save()));
|
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()));
|
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()));
|
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()));
|
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()));
|
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()));
|
connect(reloadAct, SIGNAL(triggered()), this, SLOT(reload()));
|
||||||
|
|
||||||
layerInfo = new QAction(QIcon(":/images/info.png"),tr("&Layer info"),layerTab_);
|
layerInfo = new QAction(QIcon(":/images/info.png"), tr("&Layer info"), layerTab_);
|
||||||
connect(layerInfo, SIGNAL(triggered()), layerTab_,SLOT(layerInfo()));
|
connect(layerInfo, SIGNAL(triggered()), layerTab_, SLOT(layerInfo()));
|
||||||
connect(layerTab_, SIGNAL(doubleClicked(QModelIndex const&)), layerTab_,SLOT(layerInfo2(QModelIndex const&)));
|
connect(layerTab_, SIGNAL(doubleClicked(QModelIndex const&)), layerTab_, SLOT(layerInfo2(QModelIndex const&)));
|
||||||
foreach (QByteArray format, QImageWriter::supportedImageFormats())
|
foreach (QByteArray format, QImageWriter::supportedImageFormats())
|
||||||
{
|
{
|
||||||
QString text = tr("%1...").arg(QString(format).toUpper());
|
QString text = tr("%1...").arg(QString(format).toUpper());
|
||||||
|
|
||||||
QAction *action = new QAction(text, this);
|
QAction* action = new QAction(text, this);
|
||||||
action->setData(format);
|
action->setData(format);
|
||||||
connect(action, SIGNAL(triggered()), this, SLOT(export_as()));
|
connect(action, SIGNAL(triggered()), this, SLOT(export_as()));
|
||||||
exportAsActs.append(action);
|
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"));
|
printAct->setShortcut(tr("Ctrl+E"));
|
||||||
connect(printAct, SIGNAL(triggered()), this, SLOT(print()));
|
connect(printAct, SIGNAL(triggered()), this, SLOT(print()));
|
||||||
|
|
||||||
|
@ -348,17 +339,17 @@ void MainWindow::createActions()
|
||||||
exitAct->setShortcut(tr("Ctrl+Q"));
|
exitAct->setShortcut(tr("Ctrl+Q"));
|
||||||
connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
|
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()));
|
connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::createMenus()
|
void MainWindow::createMenus()
|
||||||
{
|
{
|
||||||
exportMenu = new QMenu(tr("&Export As"), this);
|
exportMenu = new QMenu(tr("&Export As"), this);
|
||||||
foreach (QAction *action, exportAsActs)
|
foreach (QAction* action, exportAsActs)
|
||||||
exportMenu->addAction(action);
|
exportMenu->addAction(action);
|
||||||
|
|
||||||
fileMenu = new QMenu(tr("&File"),this);
|
fileMenu = new QMenu(tr("&File"), this);
|
||||||
fileMenu->addAction(openAct);
|
fileMenu->addAction(openAct);
|
||||||
fileMenu->addAction(saveAct);
|
fileMenu->addAction(saveAct);
|
||||||
fileMenu->addMenu(exportMenu);
|
fileMenu->addMenu(exportMenu);
|
||||||
|
@ -402,8 +393,8 @@ void MainWindow::createToolBars()
|
||||||
scale_factor_->setValue(1.0);
|
scale_factor_->setValue(1.0);
|
||||||
|
|
||||||
fileToolBar->addWidget(scale_factor_);
|
fileToolBar->addWidget(scale_factor_);
|
||||||
slider_ = new QSlider(Qt::Horizontal,fileToolBar);
|
slider_ = new QSlider(Qt::Horizontal, fileToolBar);
|
||||||
slider_->setRange(1,18);
|
slider_->setRange(1, 18);
|
||||||
slider_->setTickPosition(QSlider::TicksBelow);
|
slider_->setTickPosition(QSlider::TicksBelow);
|
||||||
slider_->setTickInterval(1);
|
slider_->setTickInterval(1);
|
||||||
slider_->setTracking(false);
|
slider_->setTracking(false);
|
||||||
|
@ -411,9 +402,7 @@ void MainWindow::createToolBars()
|
||||||
fileToolBar->addAction(aboutAct);
|
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
|
try
|
||||||
{
|
{
|
||||||
|
@ -423,12 +412,12 @@ void MainWindow::set_default_extent(double x0,double y0, double x1, double y1)
|
||||||
mapnik::projection prj(map_ptr->srs());
|
mapnik::projection prj(map_ptr->srs());
|
||||||
prj.forward(x0, y0);
|
prj.forward(x0, y0);
|
||||||
prj.forward(x1, y1);
|
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_);
|
mapWidget_->zoomToBox(default_extent_);
|
||||||
std::cout << "SET DEFAULT EXT:" << default_extent_ << std::endl;
|
std::cout << "SET DEFAULT EXT:" << default_extent_ << std::endl;
|
||||||
}
|
}
|
||||||
}
|
} catch (...)
|
||||||
catch (...) {}
|
{}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::set_scaling_factor(double scaling_factor)
|
void MainWindow::set_scaling_factor(double scaling_factor)
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef MAINWINDOW_HPP
|
#ifndef MAINWINDOW_HPP
|
||||||
#define MAINWINDOW_HPP
|
#define MAINWINDOW_HPP
|
||||||
|
|
||||||
|
@ -30,7 +29,7 @@
|
||||||
|
|
||||||
#include "mapwidget.hpp"
|
#include "mapwidget.hpp"
|
||||||
|
|
||||||
//using namespace mapnik;
|
// using namespace mapnik;
|
||||||
|
|
||||||
class LayerTab;
|
class LayerTab;
|
||||||
class StyleTab;
|
class StyleTab;
|
||||||
|
@ -41,22 +40,24 @@ class QDoubleSpinBox;
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
MainWindow();
|
MainWindow();
|
||||||
virtual ~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);
|
void set_scaling_factor(double scaling_factor);
|
||||||
public :
|
|
||||||
|
public:
|
||||||
std::shared_ptr<mapnik::Map> get_map();
|
std::shared_ptr<mapnik::Map> get_map();
|
||||||
protected:
|
|
||||||
|
protected:
|
||||||
void closeEvent(QCloseEvent* event);
|
void closeEvent(QCloseEvent* event);
|
||||||
public slots:
|
public slots:
|
||||||
void zoom_all();
|
void zoom_all();
|
||||||
void zoom_to_box();
|
void zoom_to_box();
|
||||||
void pan();
|
void pan();
|
||||||
void info();
|
void info();
|
||||||
void export_as();
|
void export_as();
|
||||||
void open(QString const& path = QString());
|
void open(QString const& path = QString());
|
||||||
void reload();
|
void reload();
|
||||||
void save();
|
void save();
|
||||||
void print();
|
void print();
|
||||||
|
@ -65,7 +66,8 @@ public slots:
|
||||||
void pan_right();
|
void pan_right();
|
||||||
void pan_up();
|
void pan_up();
|
||||||
void pan_down();
|
void pan_down();
|
||||||
private:
|
|
||||||
|
private:
|
||||||
void createActions();
|
void createActions();
|
||||||
void createMenus();
|
void createMenus();
|
||||||
void createToolBars();
|
void createToolBars();
|
||||||
|
@ -74,43 +76,42 @@ private:
|
||||||
|
|
||||||
QString currentPath;
|
QString currentPath;
|
||||||
QString filename_;
|
QString filename_;
|
||||||
QAbstractItemModel *model;
|
QAbstractItemModel* model;
|
||||||
LayerTab *layerTab_;
|
LayerTab* layerTab_;
|
||||||
StyleTab * styleTab_;
|
StyleTab* styleTab_;
|
||||||
MapWidget * mapWidget_;
|
MapWidget* mapWidget_;
|
||||||
//actions
|
// actions
|
||||||
QList<QAction *> exportAsActs;
|
QList<QAction*> exportAsActs;
|
||||||
QActionGroup *toolsGroup;
|
QActionGroup* toolsGroup;
|
||||||
|
|
||||||
QAction *zoomAllAct;
|
QAction* zoomAllAct;
|
||||||
QAction *zoomBoxAct;
|
QAction* zoomBoxAct;
|
||||||
QAction *panAct;
|
QAction* panAct;
|
||||||
QAction *infoAct;
|
QAction* infoAct;
|
||||||
QAction *openAct;
|
QAction* openAct;
|
||||||
QAction *saveAct;
|
QAction* saveAct;
|
||||||
QAction *printAct;
|
QAction* printAct;
|
||||||
QAction *exitAct;
|
QAction* exitAct;
|
||||||
QAction *aboutAct;
|
QAction* aboutAct;
|
||||||
QAction *panLeftAct;
|
QAction* panLeftAct;
|
||||||
QAction *panRightAct;
|
QAction* panRightAct;
|
||||||
QAction *panUpAct;
|
QAction* panUpAct;
|
||||||
QAction *panDownAct;
|
QAction* panDownAct;
|
||||||
QAction *reloadAct;
|
QAction* reloadAct;
|
||||||
QAction *layerInfo;
|
QAction* layerInfo;
|
||||||
//toolbars
|
// toolbars
|
||||||
QToolBar *fileToolBar;
|
QToolBar* fileToolBar;
|
||||||
QToolBar *editToolBar;
|
QToolBar* editToolBar;
|
||||||
//menus
|
// menus
|
||||||
QMenu *exportMenu;
|
QMenu* exportMenu;
|
||||||
QMenu *fileMenu;
|
QMenu* fileMenu;
|
||||||
QMenu *helpMenu;
|
QMenu* helpMenu;
|
||||||
//status bar
|
// status bar
|
||||||
QStatusBar *status;
|
QStatusBar* status;
|
||||||
QSlider * slider_;
|
QSlider* slider_;
|
||||||
QComboBox * renderer_selector_;
|
QComboBox* renderer_selector_;
|
||||||
QDoubleSpinBox * scale_factor_;
|
QDoubleSpinBox* scale_factor_;
|
||||||
mapnik::box2d<double> default_extent_;
|
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.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
|
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
|
@ -41,153 +40,139 @@
|
||||||
#include "mapwidget.hpp"
|
#include "mapwidget.hpp"
|
||||||
#include "info_dialog.hpp"
|
#include "info_dialog.hpp"
|
||||||
|
|
||||||
using mapnik::image_rgba8;
|
|
||||||
using mapnik::Map;
|
|
||||||
using mapnik::layer;
|
|
||||||
using mapnik::box2d;
|
using mapnik::box2d;
|
||||||
using mapnik::coord2d;
|
using mapnik::coord2d;
|
||||||
|
using mapnik::feature_kv_iterator;
|
||||||
using mapnik::feature_ptr;
|
using mapnik::feature_ptr;
|
||||||
using mapnik::view_transform;
|
using mapnik::image_rgba8;
|
||||||
|
using mapnik::layer;
|
||||||
|
using mapnik::Map;
|
||||||
using mapnik::projection;
|
using mapnik::projection;
|
||||||
using mapnik::scale_denominator;
|
using mapnik::scale_denominator;
|
||||||
using mapnik::feature_kv_iterator;
|
using mapnik::view_transform;
|
||||||
|
|
||||||
double scales [] = {279541132.014,
|
double scales[] = {279541132.014, 139770566.007, 69885283.0036, 34942641.5018, 17471320.7509,
|
||||||
139770566.007,
|
8735660.37545, 4367830.18772, 2183915.09386, 1091957.54693, 545978.773466,
|
||||||
69885283.0036,
|
272989.386733, 136494.693366, 68247.3466832, 34123.6733416, 17061.8366708,
|
||||||
34942641.5018,
|
8530.9183354, 4265.4591677, 2132.72958385, 1066.36479192, 533.182395962};
|
||||||
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)
|
MapWidget::MapWidget(QWidget* parent)
|
||||||
: QWidget(parent),
|
: QWidget(parent)
|
||||||
map_(),
|
, map_()
|
||||||
selected_(1),
|
, selected_(1)
|
||||||
extent_(),
|
, extent_()
|
||||||
cur_tool_(ZoomToBox),
|
, cur_tool_(ZoomToBox)
|
||||||
start_x_(0),
|
, start_x_(0)
|
||||||
start_y_(0),
|
, start_y_(0)
|
||||||
end_x_(0),
|
, end_x_(0)
|
||||||
end_y_(0),
|
, end_y_(0)
|
||||||
drag_(false),
|
, drag_(false)
|
||||||
first_(true),
|
, first_(true)
|
||||||
pen_(QColor(0,0,255,96)),
|
, pen_(QColor(0, 0, 255, 96))
|
||||||
selectedLayer_(-1),
|
, selectedLayer_(-1)
|
||||||
scaling_factor_(1.0),
|
, scaling_factor_(1.0)
|
||||||
cur_renderer_(AGG)
|
, cur_renderer_(AGG)
|
||||||
{
|
{
|
||||||
pen_.setWidth(3);
|
pen_.setWidth(3);
|
||||||
pen_.setCapStyle(Qt::RoundCap);
|
pen_.setCapStyle(Qt::RoundCap);
|
||||||
pen_.setJoinStyle(Qt::RoundJoin);
|
pen_.setJoinStyle(Qt::RoundJoin);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidget::setTool(eTool tool)
|
void MapWidget::setTool(eTool tool)
|
||||||
{
|
{
|
||||||
cur_tool_=tool;
|
cur_tool_ = tool;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidget::paintEvent(QPaintEvent*)
|
void MapWidget::paintEvent(QPaintEvent*)
|
||||||
{
|
{
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
|
|
||||||
if (drag_)
|
if (drag_)
|
||||||
{
|
{
|
||||||
if (cur_tool_ == ZoomToBox)
|
if (cur_tool_ == ZoomToBox)
|
||||||
{
|
{
|
||||||
unsigned width = end_x_-start_x_;
|
unsigned width = end_x_ - start_x_;
|
||||||
unsigned height = end_y_-start_y_;
|
unsigned height = end_y_ - start_y_;
|
||||||
painter.drawPixmap(QPoint(0, 0),pix_);
|
painter.drawPixmap(QPoint(0, 0), pix_);
|
||||||
painter.setPen(pen_);
|
painter.setPen(pen_);
|
||||||
painter.setBrush(QColor(200,200,255,128));
|
painter.setBrush(QColor(200, 200, 255, 128));
|
||||||
painter.drawRect(start_x_,start_y_,width,height);
|
painter.drawRect(start_x_, start_y_, width, height);
|
||||||
}
|
}
|
||||||
else if (cur_tool_ == Pan)
|
else if (cur_tool_ == Pan)
|
||||||
{
|
{
|
||||||
int dx = end_x_-start_x_;
|
int dx = end_x_ - start_x_;
|
||||||
int dy = end_y_-start_y_;
|
int dy = end_y_ - start_y_;
|
||||||
painter.setBrush(QColor(200,200,200,128));
|
painter.setBrush(QColor(200, 200, 200, 128));
|
||||||
painter.drawRect(0,0,width(),height());
|
painter.drawRect(0, 0, width(), height());
|
||||||
painter.drawPixmap(QPoint(dx,dy),pix_);
|
painter.drawPixmap(QPoint(dx, dy), pix_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
painter.drawPixmap(QPoint(0, 0),pix_);
|
painter.drawPixmap(QPoint(0, 0), pix_);
|
||||||
}
|
}
|
||||||
painter.end();
|
painter.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidget::resizeEvent(QResizeEvent * ev)
|
void MapWidget::resizeEvent(QResizeEvent* ev)
|
||||||
{
|
{
|
||||||
if (map_)
|
if (map_)
|
||||||
{
|
{
|
||||||
map_->resize(ev->size().width(),ev->size().height());
|
map_->resize(ev->size().width(), ev->size().height());
|
||||||
updateMap();
|
updateMap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidget::mousePressEvent(QMouseEvent* e)
|
void MapWidget::mousePressEvent(QMouseEvent* e)
|
||||||
{
|
{
|
||||||
if (e->button()==Qt::LeftButton)
|
if (e->button() == Qt::LeftButton)
|
||||||
{
|
{
|
||||||
if (cur_tool_ == ZoomToBox || cur_tool_==Pan)
|
if (cur_tool_ == ZoomToBox || cur_tool_ == Pan)
|
||||||
{
|
{
|
||||||
start_x_ = e->x();
|
start_x_ = e->x();
|
||||||
start_y_ = e->y();
|
start_y_ = e->y();
|
||||||
drag_=true;
|
drag_ = true;
|
||||||
}
|
}
|
||||||
else if (cur_tool_==Info)
|
else if (cur_tool_ == Info)
|
||||||
{
|
{
|
||||||
if (map_)
|
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 (int(index) != selectedLayer_) continue;
|
QVector<QPair<QString, QString>> info;
|
||||||
|
|
||||||
layer & layer = map_->layers()[index];
|
projection map_proj(map_->srs(), true); // map projection
|
||||||
if (!layer.visible(scale_denom)) continue;
|
double scale_denom = scale_denominator(map_->scale(), map_proj.is_geographic());
|
||||||
std::string name = layer.name();
|
view_transform t(map_->width(), map_->height(), map_->get_current_extent());
|
||||||
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)
|
for (unsigned index = 0; index < map_->layer_count(); ++index)
|
||||||
{
|
{
|
||||||
feature_ptr feat = fs->next();
|
if (int(index) != selectedLayer_)
|
||||||
if (feat)
|
continue;
|
||||||
{
|
|
||||||
feature_kv_iterator itr(*feat,true);
|
|
||||||
feature_kv_iterator end(*feat);
|
|
||||||
|
|
||||||
for ( ;itr!=end; ++itr)
|
layer& layer = map_->layers()[index];
|
||||||
{
|
if (!layer.visible(scale_denom))
|
||||||
info.push_back(QPair<QString,QString>(QString(std::get<0>(*itr).c_str()),
|
continue;
|
||||||
std::get<1>(*itr).to_string().c_str()));
|
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 //
|
#if 0 //
|
||||||
using path_type = mapnik::transform_path_adapter<mapnik::view_transform,mapnik::vertex_adapter>;
|
using path_type = mapnik::transform_path_adapter<mapnik::view_transform,mapnik::vertex_adapter>;
|
||||||
|
@ -219,288 +204,285 @@ void MapWidget::mousePressEvent(QMouseEvent* e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info.size() > 0)
|
if (info.size() > 0)
|
||||||
{
|
{
|
||||||
info_dialog info_dlg(info,this);
|
info_dialog info_dlg(info, this);
|
||||||
info_dlg.exec();
|
info_dlg.exec();
|
||||||
break;
|
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(),
|
else if (e->button() == Qt::RightButton)
|
||||||
map_->layers().end(),
|
{
|
||||||
bind(&layer::name,_1) == "*annotations*")
|
// updateMap();
|
||||||
, map_->layers().end());
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (e->button()==Qt::RightButton)
|
|
||||||
{
|
|
||||||
//updateMap();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidget::mouseMoveEvent(QMouseEvent* e)
|
void MapWidget::mouseMoveEvent(QMouseEvent* e)
|
||||||
{
|
{
|
||||||
if (cur_tool_ == ZoomToBox || cur_tool_==Pan)
|
if (cur_tool_ == ZoomToBox || cur_tool_ == Pan)
|
||||||
{
|
{
|
||||||
end_x_ = e->x();
|
end_x_ = e->x();
|
||||||
end_y_ = e->y();
|
end_y_ = e->y();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidget::mouseReleaseEvent(QMouseEvent* e)
|
void MapWidget::mouseReleaseEvent(QMouseEvent* e)
|
||||||
{
|
{
|
||||||
if (e->button()==Qt::LeftButton)
|
if (e->button() == Qt::LeftButton)
|
||||||
{
|
{
|
||||||
end_x_ = e->x();
|
end_x_ = e->x();
|
||||||
end_y_ = e->y();
|
end_y_ = e->y();
|
||||||
if (cur_tool_ == ZoomToBox)
|
if (cur_tool_ == ZoomToBox)
|
||||||
{
|
{
|
||||||
drag_=false;
|
drag_ = false;
|
||||||
if (map_)
|
if (map_)
|
||||||
{
|
{
|
||||||
view_transform t(map_->width(),map_->height(),map_->get_current_extent());
|
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_));
|
box2d<double> box = t.backward(box2d<double>(start_x_, start_y_, end_x_, end_y_));
|
||||||
map_->zoom_to_box(box);
|
map_->zoom_to_box(box);
|
||||||
updateMap();
|
updateMap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (cur_tool_==Pan)
|
else if (cur_tool_ == Pan)
|
||||||
{
|
{
|
||||||
drag_=false;
|
drag_ = false;
|
||||||
if (map_)
|
if (map_)
|
||||||
{
|
{
|
||||||
int cx = int(0.5 * map_->width());
|
int cx = int(0.5 * map_->width());
|
||||||
int cy = int(0.5 * map_->height());
|
int cy = int(0.5 * map_->height());
|
||||||
int dx = end_x_ - start_x_;
|
int dx = end_x_ - start_x_;
|
||||||
int dy = end_y_ - start_y_;
|
int dy = end_y_ - start_y_;
|
||||||
map_->pan(cx - dx ,cy - dy);
|
map_->pan(cx - dx, cy - dy);
|
||||||
updateMap();
|
updateMap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidget::wheelEvent(QWheelEvent* e)
|
void MapWidget::wheelEvent(QWheelEvent* e)
|
||||||
{
|
{
|
||||||
if (!map_)
|
if (!map_)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||||
QPointF corner(map_->width(), map_->height());
|
QPointF corner(map_->width(), map_->height());
|
||||||
QPointF zoomCoords;
|
QPointF zoomCoords;
|
||||||
double zoom;
|
double zoom;
|
||||||
if (e->angleDelta().y() > 0)
|
if (e->angleDelta().y() > 0)
|
||||||
{
|
{
|
||||||
zoom = 0.5;
|
zoom = 0.5;
|
||||||
QPointF center = corner / 2;
|
QPointF center = corner / 2;
|
||||||
QPointF delta = e->position() - center;
|
QPointF delta = e->position() - center;
|
||||||
zoomCoords = zoom * delta + center;
|
zoomCoords = zoom * delta + center;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
zoom = 2.0;
|
zoom = 2.0;
|
||||||
zoomCoords = corner - e->position();
|
zoomCoords = corner - e->position();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
QPoint corner(map_->width(), map_->height());
|
QPoint corner(map_->width(), map_->height());
|
||||||
QPoint zoomCoords;
|
QPoint zoomCoords;
|
||||||
double zoom;
|
double zoom;
|
||||||
if (e->delta() > 0)
|
if (e->delta() > 0)
|
||||||
{
|
{
|
||||||
zoom = 0.5;
|
zoom = 0.5;
|
||||||
QPoint center = corner / 2;
|
QPoint center = corner / 2;
|
||||||
QPoint delta = e->pos() - center;
|
QPoint delta = e->pos() - center;
|
||||||
zoomCoords = zoom * delta + center;
|
zoomCoords = zoom * delta + center;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
zoom = 2.0;
|
zoom = 2.0;
|
||||||
zoomCoords = corner - e->pos();
|
zoomCoords = corner - e->pos();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
map_->pan_and_zoom(zoomCoords.x(), zoomCoords.y(), zoom);
|
map_->pan_and_zoom(zoomCoords.x(), zoomCoords.y(), zoom);
|
||||||
updateMap();
|
updateMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidget::keyPressEvent(QKeyEvent *e)
|
void MapWidget::keyPressEvent(QKeyEvent* e)
|
||||||
{
|
{
|
||||||
std::cout << "key pressed:"<< e->key()<<"\n";
|
std::cout << "key pressed:" << e->key() << "\n";
|
||||||
switch (e->key()) {
|
switch (e->key())
|
||||||
case Qt::Key_Minus:
|
{
|
||||||
zoomOut();
|
case Qt::Key_Minus:
|
||||||
break;
|
zoomOut();
|
||||||
case Qt::Key_Plus:
|
break;
|
||||||
case 61:
|
case Qt::Key_Plus:
|
||||||
zoomIn();
|
case 61:
|
||||||
break;
|
zoomIn();
|
||||||
case 65:
|
break;
|
||||||
defaultView();
|
case 65:
|
||||||
break;
|
defaultView();
|
||||||
case Qt::Key_Up:
|
break;
|
||||||
panUp();
|
case Qt::Key_Up:
|
||||||
break;
|
panUp();
|
||||||
case Qt::Key_Down:
|
break;
|
||||||
panDown();
|
case Qt::Key_Down:
|
||||||
break;
|
panDown();
|
||||||
case Qt::Key_Left:
|
break;
|
||||||
panLeft();
|
case Qt::Key_Left:
|
||||||
break;
|
panLeft();
|
||||||
case Qt::Key_Right:
|
break;
|
||||||
panRight();
|
case Qt::Key_Right:
|
||||||
break;
|
panRight();
|
||||||
case 49:
|
break;
|
||||||
zoomToLevel(10);
|
case 49:
|
||||||
break;
|
zoomToLevel(10);
|
||||||
case 50:
|
break;
|
||||||
zoomToLevel(11);
|
case 50:
|
||||||
break;
|
zoomToLevel(11);
|
||||||
case 51:
|
break;
|
||||||
zoomToLevel(12);
|
case 51:
|
||||||
break;
|
zoomToLevel(12);
|
||||||
case 52:
|
break;
|
||||||
zoomToLevel(13);
|
case 52:
|
||||||
break;
|
zoomToLevel(13);
|
||||||
case 53:
|
break;
|
||||||
zoomToLevel(14);
|
case 53:
|
||||||
break;
|
zoomToLevel(14);
|
||||||
case 54:
|
break;
|
||||||
zoomToLevel(15);
|
case 54:
|
||||||
break;
|
zoomToLevel(15);
|
||||||
case 55:
|
break;
|
||||||
zoomToLevel(16);
|
case 55:
|
||||||
break;
|
zoomToLevel(16);
|
||||||
case 56:
|
break;
|
||||||
zoomToLevel(17);
|
case 56:
|
||||||
break;
|
zoomToLevel(17);
|
||||||
case 57:
|
break;
|
||||||
zoomToLevel(18);
|
case 57:
|
||||||
break;
|
zoomToLevel(18);
|
||||||
default:
|
break;
|
||||||
QWidget::keyPressEvent(e);
|
default:
|
||||||
}
|
QWidget::keyPressEvent(e);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidget::zoomToBox(mapnik::box2d<double> const& bbox)
|
void MapWidget::zoomToBox(mapnik::box2d<double> const& bbox)
|
||||||
{
|
{
|
||||||
if (map_)
|
if (map_)
|
||||||
{
|
{
|
||||||
map_->zoom_to_box(bbox);
|
map_->zoom_to_box(bbox);
|
||||||
updateMap();
|
updateMap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidget::defaultView()
|
void MapWidget::defaultView()
|
||||||
{
|
{
|
||||||
if (map_)
|
if (map_)
|
||||||
{
|
{
|
||||||
map_->resize(width(),height());
|
map_->resize(width(), height());
|
||||||
map_->zoom_all();
|
map_->zoom_all();
|
||||||
updateMap();
|
updateMap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidget::zoomIn()
|
void MapWidget::zoomIn()
|
||||||
{
|
{
|
||||||
if (map_)
|
if (map_)
|
||||||
{
|
{
|
||||||
map_->zoom(0.5);
|
map_->zoom(0.5);
|
||||||
updateMap();
|
updateMap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidget::zoomOut()
|
void MapWidget::zoomOut()
|
||||||
{
|
{
|
||||||
if (map_)
|
if (map_)
|
||||||
{
|
{
|
||||||
map_->zoom(2.0);
|
map_->zoom(2.0);
|
||||||
updateMap();
|
updateMap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidget::panUp()
|
void MapWidget::panUp()
|
||||||
{
|
{
|
||||||
if (map_)
|
if (map_)
|
||||||
{
|
{
|
||||||
double cx = 0.5*map_->width();
|
double cx = 0.5 * map_->width();
|
||||||
double cy = 0.5*map_->height();
|
double cy = 0.5 * map_->height();
|
||||||
map_->pan(int(cx),int(cy - cy*0.25));
|
map_->pan(int(cx), int(cy - cy * 0.25));
|
||||||
updateMap();
|
updateMap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidget::panDown()
|
void MapWidget::panDown()
|
||||||
{
|
{
|
||||||
if (map_)
|
if (map_)
|
||||||
{
|
{
|
||||||
double cx = 0.5*map_->width();
|
double cx = 0.5 * map_->width();
|
||||||
double cy = 0.5*map_->height();
|
double cy = 0.5 * map_->height();
|
||||||
map_->pan(int(cx),int(cy + cy*0.25));
|
map_->pan(int(cx), int(cy + cy * 0.25));
|
||||||
updateMap();
|
updateMap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidget::panLeft()
|
void MapWidget::panLeft()
|
||||||
{
|
{
|
||||||
if (map_)
|
if (map_)
|
||||||
{
|
{
|
||||||
double cx = 0.5*map_->width();
|
double cx = 0.5 * map_->width();
|
||||||
double cy = 0.5*map_->height();
|
double cy = 0.5 * map_->height();
|
||||||
map_->pan(int(cx - cx * 0.25),int(cy));
|
map_->pan(int(cx - cx * 0.25), int(cy));
|
||||||
updateMap();
|
updateMap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidget::panRight()
|
void MapWidget::panRight()
|
||||||
{
|
{
|
||||||
if (map_)
|
if (map_)
|
||||||
{
|
{
|
||||||
double cx = 0.5*map_->width();
|
double cx = 0.5 * map_->width();
|
||||||
double cy = 0.5*map_->height();
|
double cy = 0.5 * map_->height();
|
||||||
map_->pan(int(cx + cx * 0.25),int(cy));
|
map_->pan(int(cx + cx * 0.25), int(cy));
|
||||||
updateMap();
|
updateMap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MapWidget::zoomToLevel(int level)
|
void MapWidget::zoomToLevel(int level)
|
||||||
{
|
{
|
||||||
if ( map_ && level >= 0 && level < 19 )
|
if (map_ && level >= 0 && level < 19)
|
||||||
{
|
{
|
||||||
double scale_denom = scales[level];
|
double scale_denom = scales[level];
|
||||||
std::cerr << "scale denominator = " << scale_denom << "\n";
|
std::cerr << "scale denominator = " << scale_denom << "\n";
|
||||||
mapnik::box2d<double> ext = map_->get_current_extent();
|
mapnik::box2d<double> ext = map_->get_current_extent();
|
||||||
double width = static_cast<double>(map_->width());
|
double width = static_cast<double>(map_->width());
|
||||||
double height= static_cast<double>(map_->height());
|
double height = static_cast<double>(map_->height());
|
||||||
mapnik::coord2d pt = ext.center();
|
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,
|
mapnik::box2d<double> box(pt.x - 0.5 * width * res,
|
||||||
pt.y - 0.5 * height*res,
|
pt.y - 0.5 * height * res,
|
||||||
pt.x + 0.5 * width * res,
|
pt.x + 0.5 * width * res,
|
||||||
pt.y + 0.5 * height*res);
|
pt.y + 0.5 * height * res);
|
||||||
map_->zoom_to_box(box);
|
map_->zoom_to_box(box);
|
||||||
updateMap();
|
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);
|
// image_rgba8 image(width,height);
|
||||||
//agg_renderer renderer(map,image);
|
// agg_renderer renderer(map,image);
|
||||||
//renderer.apply();
|
// renderer.apply();
|
||||||
//image.saveToFile(filename,type);
|
// image.saveToFile(filename,type);
|
||||||
std::cout << "Export to file .." << std::endl;
|
std::cout << "Export to file .." << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -509,47 +491,44 @@ void MapWidget::set_scaling_factor(double scaling_factor)
|
||||||
scaling_factor_ = 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 width = map.width();
|
||||||
unsigned height=map.height();
|
unsigned height = map.height();
|
||||||
|
|
||||||
image_rgba8 buf(width,height);
|
image_rgba8 buf(width, height);
|
||||||
mapnik::agg_renderer<image_rgba8> ren(map,buf,scaling_factor);
|
mapnik::agg_renderer<image_rgba8> ren(map, buf, scaling_factor);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
mapnik::auto_cpu_timer t(std::clog, "rendering took: ");
|
mapnik::auto_cpu_timer t(std::clog, "rendering took: ");
|
||||||
ren.apply();
|
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());
|
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)
|
catch (std::exception const& ex)
|
||||||
{
|
{
|
||||||
std::cerr << "exception: " << ex.what() << std::endl;
|
std::cerr << "exception: " << ex.what() << std::endl;
|
||||||
}
|
} catch (...)
|
||||||
catch (...)
|
|
||||||
{
|
{
|
||||||
std::cerr << "Unknown exception caught!\n";
|
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;
|
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
|
// FIXME
|
||||||
#ifdef HAVE_CAIRO
|
#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_surface_closer());
|
||||||
mapnik::cairo_ptr cairo = mapnik::create_context(image_surface);
|
mapnik::cairo_ptr cairo = mapnik::create_context(image_surface);
|
||||||
if (cairo)
|
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::image_rgba8 data(map.width(), map.height());
|
||||||
mapnik::cairo_image_to_rgba8(data, image_surface);
|
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());
|
pix = QPixmap::fromImage(image.rgbSwapped());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidget::updateRenderer(QString const& txt)
|
void MapWidget::updateRenderer(QString const& txt)
|
||||||
{
|
{
|
||||||
if (txt == "AGG") cur_renderer_ = AGG;
|
if (txt == "AGG")
|
||||||
else if (txt == "Cairo") cur_renderer_ = Cairo;
|
cur_renderer_ = AGG;
|
||||||
else if (txt == "Grid") cur_renderer_ = Grid;
|
else if (txt == "Cairo")
|
||||||
|
cur_renderer_ = Cairo;
|
||||||
|
else if (txt == "Grid")
|
||||||
|
cur_renderer_ = Grid;
|
||||||
std::cerr << "Update renderer called" << std::endl;
|
std::cerr << "Update renderer called" << std::endl;
|
||||||
updateMap();
|
updateMap();
|
||||||
}
|
}
|
||||||
|
@ -582,50 +564,49 @@ void MapWidget::updateScaleFactor(double scale_factor)
|
||||||
|
|
||||||
void MapWidget::updateMap()
|
void MapWidget::updateMap()
|
||||||
{
|
{
|
||||||
if (map_)
|
if (map_)
|
||||||
{
|
{
|
||||||
if (cur_renderer_== AGG)
|
if (cur_renderer_ == AGG)
|
||||||
{
|
{
|
||||||
render_agg(*map_, scaling_factor_, pix_);
|
render_agg(*map_, scaling_factor_, pix_);
|
||||||
}
|
}
|
||||||
else if (cur_renderer_ == Cairo)
|
else if (cur_renderer_ == Cairo)
|
||||||
{
|
{
|
||||||
render_cairo(*map_, scaling_factor_, pix_);
|
render_cairo(*map_, scaling_factor_, pix_);
|
||||||
}
|
}
|
||||||
else if (cur_renderer_ == Grid)
|
else if (cur_renderer_ == Grid)
|
||||||
{
|
{
|
||||||
render_grid(*map_, scaling_factor_, pix_);
|
render_grid(*map_, scaling_factor_, pix_);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cerr << "Unknown renderer..." << std::endl;
|
std::cerr << "Unknown renderer..." << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
projection prj(map_->srs(), true); // map projection
|
projection prj(map_->srs(), true); // map projection
|
||||||
box2d<double> ext = map_->get_current_extent();
|
box2d<double> ext = map_->get_current_extent();
|
||||||
double x0 = ext.minx();
|
double x0 = ext.minx();
|
||||||
double y0 = ext.miny();
|
double y0 = ext.miny();
|
||||||
double x1 = ext.maxx();
|
double x1 = ext.maxx();
|
||||||
double y1 = ext.maxy();
|
double y1 = ext.maxy();
|
||||||
double z = 0;
|
double z = 0;
|
||||||
std::string dest_srs = {"epsg:4326"};
|
std::string dest_srs = {"epsg:4326"};
|
||||||
mapnik::proj_transform proj_tr(map_->srs(), dest_srs);
|
mapnik::proj_transform proj_tr(map_->srs(), dest_srs);
|
||||||
|
|
||||||
proj_tr.forward(x0, y0, z);
|
proj_tr.forward(x0, y0, z);
|
||||||
proj_tr.forward(x1, y1, z);
|
proj_tr.forward(x1, y1, z);
|
||||||
std::cout << "MAP SIZE:" << map_->width() << "," << map_->height() << std::endl;
|
std::cout << "MAP SIZE:" << map_->width() << "," << map_->height() << std::endl;
|
||||||
std::cout << "BBOX (WGS84): " << x0 << "," << y0 << "," << x1 << "," << y1 << "\n";
|
std::cout << "BBOX (WGS84): " << x0 << "," << y0 << "," << x1 << "," << y1 << "\n";
|
||||||
update();
|
update();
|
||||||
// emit signal to interested widgets
|
// emit signal to interested widgets
|
||||||
emit mapViewChanged();
|
emit mapViewChanged();
|
||||||
}
|
} catch (...)
|
||||||
catch (...)
|
{
|
||||||
{
|
std::cerr << "Unknown exception caught!\n";
|
||||||
std::cerr << "Unknown exception caught!\n";
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Map> MapWidget::getMap()
|
std::shared_ptr<Map> MapWidget::getMap()
|
||||||
|
@ -638,7 +619,6 @@ void MapWidget::setMap(std::shared_ptr<Map> map)
|
||||||
map_ = map;
|
map_ = map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MapWidget::layerSelected(int index)
|
void MapWidget::layerSelected(int index)
|
||||||
{
|
{
|
||||||
selectedLayer_ = index;
|
selectedLayer_ = index;
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef MAP_WIDGET_HPP
|
#ifndef MAP_WIDGET_HPP
|
||||||
#define MAP_WIDGET_HPP
|
#define MAP_WIDGET_HPP
|
||||||
|
|
||||||
|
@ -30,7 +29,6 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
|
||||||
#ifndef Q_MOC_RUN
|
#ifndef Q_MOC_RUN
|
||||||
#include <mapnik/map.hpp>
|
#include <mapnik/map.hpp>
|
||||||
#endif
|
#endif
|
||||||
|
@ -39,22 +37,16 @@ class MapWidget : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum eTool
|
enum eTool {
|
||||||
{
|
|
||||||
ZoomToBox = 1,
|
ZoomToBox = 1,
|
||||||
Pan,
|
Pan,
|
||||||
Info,
|
Info,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum eRenderer
|
enum eRenderer { AGG, Cairo, Grid };
|
||||||
{
|
|
||||||
AGG,
|
|
||||||
Cairo,
|
|
||||||
Grid
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<mapnik::Map> map_;
|
std::shared_ptr<mapnik::Map> map_;
|
||||||
int selected_;
|
int selected_;
|
||||||
QPixmap pix_;
|
QPixmap pix_;
|
||||||
|
@ -70,11 +62,12 @@ private:
|
||||||
int selectedLayer_;
|
int selectedLayer_;
|
||||||
double scaling_factor_;
|
double scaling_factor_;
|
||||||
eRenderer cur_renderer_;
|
eRenderer cur_renderer_;
|
||||||
public:
|
|
||||||
MapWidget(QWidget *parent=0);
|
public:
|
||||||
|
MapWidget(QWidget* parent = 0);
|
||||||
void setTool(eTool tool);
|
void setTool(eTool tool);
|
||||||
std::shared_ptr<mapnik::Map> getMap();
|
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 setMap(std::shared_ptr<mapnik::Map> map);
|
||||||
void defaultView();
|
void defaultView();
|
||||||
void zoomToBox(mapnik::box2d<double> const& box);
|
void zoomToBox(mapnik::box2d<double> const& box);
|
||||||
|
@ -85,26 +78,24 @@ public:
|
||||||
void panUp();
|
void panUp();
|
||||||
void panDown();
|
void panDown();
|
||||||
void set_scaling_factor(double);
|
void set_scaling_factor(double);
|
||||||
public slots:
|
public slots:
|
||||||
void zoomToLevel(int level);
|
void zoomToLevel(int level);
|
||||||
void updateMap();
|
void updateMap();
|
||||||
void layerSelected(int);
|
void layerSelected(int);
|
||||||
void updateRenderer(QString const& txt);
|
void updateRenderer(QString const& txt);
|
||||||
void updateScaleFactor(double scale_factor);
|
void updateScaleFactor(double scale_factor);
|
||||||
signals:
|
signals:
|
||||||
void mapViewChanged();
|
void mapViewChanged();
|
||||||
protected:
|
|
||||||
|
protected:
|
||||||
void paintEvent(QPaintEvent* ev);
|
void paintEvent(QPaintEvent* ev);
|
||||||
void resizeEvent(QResizeEvent* ev);
|
void resizeEvent(QResizeEvent* ev);
|
||||||
void mousePressEvent(QMouseEvent* e);
|
void mousePressEvent(QMouseEvent* e);
|
||||||
void mouseMoveEvent(QMouseEvent* e);
|
void mouseMoveEvent(QMouseEvent* e);
|
||||||
void mouseReleaseEvent(QMouseEvent* e);
|
void mouseReleaseEvent(QMouseEvent* e);
|
||||||
void wheelEvent(QWheelEvent* e);
|
void wheelEvent(QWheelEvent* e);
|
||||||
void keyPressEvent(QKeyEvent *e);
|
void keyPressEvent(QKeyEvent* e);
|
||||||
void export_to_file(unsigned width,
|
void export_to_file(unsigned width, unsigned height, std::string const& filename, std::string const& type);
|
||||||
unsigned height,
|
|
||||||
std::string const& filename,
|
|
||||||
std::string const& type);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAP_WIDGET_HPP
|
#endif // MAP_WIDGET_HPP
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "styles_model.hpp"
|
#include "styles_model.hpp"
|
||||||
#include <mapnik/config.hpp>
|
#include <mapnik/config.hpp>
|
||||||
#include <mapnik/util/variant.hpp>
|
#include <mapnik/util/variant.hpp>
|
||||||
|
@ -39,70 +38,50 @@ class node : private mapnik::util::noncopyable
|
||||||
{
|
{
|
||||||
struct node_base
|
struct node_base
|
||||||
{
|
{
|
||||||
virtual QString name() const=0;
|
virtual QString name() const = 0;
|
||||||
virtual QIcon icon() const=0;
|
virtual QIcon icon() const = 0;
|
||||||
virtual ~node_base() {}
|
virtual ~node_base() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
struct wrap : public node_base
|
struct wrap : public node_base
|
||||||
{
|
{
|
||||||
wrap(T const& obj)
|
wrap(T const& obj)
|
||||||
: obj_(obj) {}
|
: obj_(obj)
|
||||||
|
{}
|
||||||
|
|
||||||
~wrap() {}
|
~wrap() {}
|
||||||
|
|
||||||
QString name () const
|
QString name() const { return obj_.name(); }
|
||||||
{
|
|
||||||
return obj_.name();
|
|
||||||
}
|
|
||||||
|
|
||||||
QIcon icon() const
|
QIcon icon() const { return obj_.icon(); }
|
||||||
{
|
|
||||||
return obj_.icon();
|
|
||||||
}
|
|
||||||
|
|
||||||
T obj_;
|
T obj_;
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
template <typename T>
|
template<typename T>
|
||||||
node ( T const& obj, node * parent=0)
|
node(T const& obj, node* parent = 0)
|
||||||
: impl_(new wrap<T>(obj)),
|
: impl_(new wrap<T>(obj))
|
||||||
parent_(parent)
|
, parent_(parent)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
QString name() const
|
QString name() const { return impl_->name(); }
|
||||||
{
|
|
||||||
return impl_->name();
|
|
||||||
}
|
|
||||||
|
|
||||||
QIcon icon() const
|
QIcon icon() const { return impl_->icon(); }
|
||||||
{
|
|
||||||
return impl_->icon();
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned num_children() const
|
unsigned num_children() const { return children_.count(); }
|
||||||
{
|
|
||||||
return children_.count();
|
|
||||||
}
|
|
||||||
|
|
||||||
node * child(unsigned row) const
|
node* child(unsigned row) const { return children_.value(row); }
|
||||||
{
|
|
||||||
return children_.value(row);
|
|
||||||
}
|
|
||||||
|
|
||||||
node * parent() const
|
node* parent() const { return parent_; }
|
||||||
{
|
|
||||||
return parent_;
|
|
||||||
}
|
|
||||||
|
|
||||||
node * add_child(node * child)
|
node* add_child(node* child)
|
||||||
{
|
{
|
||||||
children_.push_back(child);
|
children_.push_back(child);
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
int row () const
|
int row() const
|
||||||
{
|
{
|
||||||
if (parent_)
|
if (parent_)
|
||||||
return parent_->children_.indexOf(const_cast<node*>(this));
|
return parent_->children_.indexOf(const_cast<node*>(this));
|
||||||
|
@ -110,94 +89,90 @@ public:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
~node()
|
~node() { qDeleteAll(children_); }
|
||||||
{
|
|
||||||
qDeleteAll(children_);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::unique_ptr<node_base> impl_;
|
const std::unique_ptr<node_base> impl_;
|
||||||
QList<node*> children_;
|
QList<node*> children_;
|
||||||
node * parent_;
|
node* parent_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct symbolizer_info
|
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);
|
boost::ignore_unused_variable_warning(sym);
|
||||||
return QString("PointSymbolizer");
|
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);
|
boost::ignore_unused_variable_warning(sym);
|
||||||
return QString("LineSymbolizer");
|
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);
|
boost::ignore_unused_variable_warning(sym);
|
||||||
return QString("LinePatternSymbolizer");
|
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);
|
boost::ignore_unused_variable_warning(sym);
|
||||||
return QString("PolygonSymbolizer");
|
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);
|
boost::ignore_unused_variable_warning(sym);
|
||||||
return QString("PolygonSymbolizer");
|
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);
|
boost::ignore_unused_variable_warning(sym);
|
||||||
return QString("TextSymbolizer");
|
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);
|
boost::ignore_unused_variable_warning(sym);
|
||||||
return QString("ShieldSymbolizer");
|
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);
|
boost::ignore_unused_variable_warning(sym);
|
||||||
return QString("MarkersSymbolizer");
|
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);
|
boost::ignore_unused_variable_warning(sym);
|
||||||
return QString("BuildingSymbolizer");
|
return QString("BuildingSymbolizer");
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
QString operator() (T const& ) const
|
QString operator()(T const&) const
|
||||||
{
|
{
|
||||||
return QString ("FIXME");
|
return QString("FIXME");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct symbolizer_icon
|
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);
|
QPainter painter(&pix);
|
||||||
mapnik::color const& fill = mapnik::get<mapnik::color>(sym, mapnik::keys::fill);
|
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);
|
painter.fillRect(0, 0, 16, 16, brush);
|
||||||
return QIcon(pix);
|
return QIcon(pix);
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon operator() (mapnik::point_symbolizer const& sym) const
|
QIcon operator()(mapnik::point_symbolizer const& sym) const
|
||||||
{
|
{
|
||||||
// FIXME!
|
// FIXME!
|
||||||
/*
|
/*
|
||||||
|
@ -212,55 +187,57 @@ struct symbolizer_icon
|
||||||
*/
|
*/
|
||||||
return QIcon();
|
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();
|
pix.fill();
|
||||||
QPainter painter(&pix);
|
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);
|
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));
|
pen.setWidth(mapnik::get<double>(sym, mapnik::keys::width));
|
||||||
painter.setPen(pen);
|
painter.setPen(pen);
|
||||||
painter.drawLine(0,7,47,7);
|
painter.drawLine(0, 7, 47, 7);
|
||||||
//painter.drawLine(7,15,12,0);
|
// painter.drawLine(7,15,12,0);
|
||||||
//painter.drawLine(12,0,8,15);
|
// painter.drawLine(12,0,8,15);
|
||||||
return QIcon(pix);
|
return QIcon(pix);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
QIcon operator() (T const& ) const
|
QIcon operator()(T const&) const
|
||||||
{
|
{
|
||||||
return QIcon (":/images/filter.png");
|
return QIcon(":/images/filter.png");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class symbolizer_node
|
class symbolizer_node
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
symbolizer_node(mapnik::symbolizer const & sym)
|
symbolizer_node(mapnik::symbolizer const& sym)
|
||||||
: sym_(sym) {}
|
: sym_(sym)
|
||||||
~symbolizer_node(){}
|
{}
|
||||||
|
~symbolizer_node() {}
|
||||||
|
|
||||||
QString name() const
|
QString name() const
|
||||||
{
|
{
|
||||||
//return QString("Symbolizer:fixme");
|
// return QString("Symbolizer:fixme");
|
||||||
return mapnik::util::apply_visitor(symbolizer_info(),sym_);
|
return mapnik::util::apply_visitor(symbolizer_info(), sym_);
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon icon() const
|
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_;
|
mapnik::symbolizer const& sym_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class rule_node
|
class rule_node
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
rule_node(QString name,mapnik::rule const & r)
|
rule_node(QString name, mapnik::rule const& r)
|
||||||
: name_(name),
|
: name_(name)
|
||||||
rule_(r) {}
|
, rule_(r)
|
||||||
|
{}
|
||||||
~rule_node() {}
|
~rule_node() {}
|
||||||
QString name() const
|
QString name() const
|
||||||
{
|
{
|
||||||
|
@ -268,81 +245,68 @@ public:
|
||||||
return QString(mapnik::to_expression_string(*filter).c_str());
|
return QString(mapnik::to_expression_string(*filter).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon icon() const
|
QIcon icon() const { return QIcon(":/images/filter.png"); }
|
||||||
{
|
|
||||||
return QIcon(":/images/filter.png");
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString name_;
|
QString name_;
|
||||||
mapnik::rule const& rule_;
|
mapnik::rule const& rule_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class style_node
|
class style_node
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
style_node(QString name, mapnik::feature_type_style const& style)
|
style_node(QString name, mapnik::feature_type_style const& style)
|
||||||
: name_(name),
|
: name_(name)
|
||||||
style_(style) {}
|
, style_(style)
|
||||||
|
{}
|
||||||
|
|
||||||
~style_node() {}
|
~style_node() {}
|
||||||
|
|
||||||
QString name() const
|
QString name() const { return name_; }
|
||||||
{
|
|
||||||
return name_;
|
|
||||||
}
|
|
||||||
|
|
||||||
QIcon icon() const
|
QIcon icon() const { return QIcon(":/images/style.png"); }
|
||||||
{
|
|
||||||
return QIcon(":/images/style.png");
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString name_;
|
QString name_;
|
||||||
mapnik::feature_type_style const& style_;
|
mapnik::feature_type_style const& style_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class map_node
|
class map_node
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit map_node(std::shared_ptr<mapnik::Map> map)
|
explicit map_node(std::shared_ptr<mapnik::Map> map)
|
||||||
: map_(map) {}
|
: map_(map)
|
||||||
|
{}
|
||||||
~map_node() {}
|
~map_node() {}
|
||||||
|
|
||||||
QString name() const
|
QString name() const { return QString("Map"); }
|
||||||
{
|
|
||||||
return QString("Map");
|
|
||||||
}
|
|
||||||
|
|
||||||
QIcon icon() const
|
QIcon icon() const { return QIcon(":/images/map.png"); }
|
||||||
{
|
|
||||||
return QIcon(":/images/map.png");
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<mapnik::Map> map_;
|
std::shared_ptr<mapnik::Map> map_;
|
||||||
};
|
};
|
||||||
|
|
||||||
StyleModel::StyleModel(std::shared_ptr<mapnik::Map> map, QObject * parent)
|
StyleModel::StyleModel(std::shared_ptr<mapnik::Map> map, QObject* parent)
|
||||||
: QAbstractItemModel(parent),
|
: QAbstractItemModel(parent)
|
||||||
root_(new node(map_node(map)))
|
, root_(new node(map_node(map)))
|
||||||
{
|
{
|
||||||
using style_type = std::map<std::string,mapnik::feature_type_style>;
|
using style_type = std::map<std::string, mapnik::feature_type_style>;
|
||||||
style_type const & styles = map->styles();
|
style_type const& styles = map->styles();
|
||||||
style_type::const_iterator itr = styles.begin();
|
style_type::const_iterator itr = styles.begin();
|
||||||
style_type::const_iterator end = styles.end();
|
style_type::const_iterator end = styles.end();
|
||||||
for (; itr != end; ++itr)
|
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& rules = itr->second.get_rules();
|
||||||
mapnik::rules::const_iterator itr2 = rules.begin();
|
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();
|
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() {}
|
StyleModel::~StyleModel() {}
|
||||||
|
|
||||||
// interface
|
// 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());
|
// qDebug("index() row=%d col=%d parent::internalId() = %lld", row,col,parent.internalId());
|
||||||
node * parent_node;
|
node* parent_node;
|
||||||
|
|
||||||
if (!parent.isValid())
|
if (!parent.isValid())
|
||||||
parent_node = root_.get();
|
parent_node = root_.get();
|
||||||
else
|
else
|
||||||
parent_node = static_cast<node*>(parent.internalPointer());
|
parent_node = static_cast<node*>(parent.internalPointer());
|
||||||
|
|
||||||
node * child_node = parent_node->child(row);
|
node* child_node = parent_node->child(row);
|
||||||
if (child_node)
|
if (child_node)
|
||||||
return createIndex(row,col,child_node);
|
return createIndex(row, col, child_node);
|
||||||
else
|
else
|
||||||
return QModelIndex();
|
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* child_node = static_cast<node*>(index.internalPointer());
|
||||||
node * parent_node = child_node->parent();
|
node* parent_node = child_node->parent();
|
||||||
if (parent_node == root_.get())
|
if (parent_node == root_.get())
|
||||||
return QModelIndex();
|
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
|
int StyleModel::rowCount(QModelIndex const& parent) const
|
||||||
{
|
{
|
||||||
//qDebug("rowCount");
|
// qDebug("rowCount");
|
||||||
node * parent_node;
|
node* parent_node;
|
||||||
if (parent.column() > 0) return 0;
|
if (parent.column() > 0)
|
||||||
|
return 0;
|
||||||
if (!parent.isValid())
|
if (!parent.isValid())
|
||||||
parent_node = root_.get();
|
parent_node = root_.get();
|
||||||
else
|
else
|
||||||
|
@ -390,25 +355,24 @@ int StyleModel::rowCount(QModelIndex const& parent) const
|
||||||
return parent_node->num_children();
|
return parent_node->num_children();
|
||||||
}
|
}
|
||||||
|
|
||||||
int StyleModel::columnCount( QModelIndex const&) const
|
int StyleModel::columnCount(QModelIndex const&) const
|
||||||
{
|
{
|
||||||
return 1;
|
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())
|
if (!index.isValid())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
node * cur_node = static_cast<node*>(index.internalPointer());
|
node* cur_node = static_cast<node*>(index.internalPointer());
|
||||||
if (cur_node)
|
if (cur_node)
|
||||||
{
|
{
|
||||||
if (role == Qt::DisplayRole)
|
if (role == Qt::DisplayRole)
|
||||||
{
|
{
|
||||||
|
|
||||||
return QVariant(cur_node->name());
|
return QVariant(cur_node->name());
|
||||||
}
|
}
|
||||||
else if ( role == Qt::DecorationRole)
|
else if (role == Qt::DecorationRole)
|
||||||
{
|
{
|
||||||
return cur_node->icon();
|
return cur_node->icon();
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef STYLE_MODEL_HPP
|
#ifndef STYLE_MODEL_HPP
|
||||||
#define STYLE_MODEL_HPP
|
#define STYLE_MODEL_HPP
|
||||||
|
|
||||||
|
@ -27,24 +26,23 @@
|
||||||
#include <mapnik/map.hpp>
|
#include <mapnik/map.hpp>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class node;
|
class node;
|
||||||
class StyleModel : public QAbstractItemModel
|
class StyleModel : public QAbstractItemModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
StyleModel(std::shared_ptr<mapnik::Map> map, QObject * parent=0);
|
StyleModel(std::shared_ptr<mapnik::Map> map, QObject* parent = 0);
|
||||||
~StyleModel();
|
~StyleModel();
|
||||||
// interface
|
// interface
|
||||||
QModelIndex index (int row, int col, QModelIndex const& parent = QModelIndex()) const;
|
QModelIndex index(int row, int col, QModelIndex const& parent = QModelIndex()) const;
|
||||||
QModelIndex parent (QModelIndex const& child) const;
|
QModelIndex parent(QModelIndex const& child) const;
|
||||||
int rowCount( QModelIndex const& parent = QModelIndex()) const;
|
int rowCount(QModelIndex const& parent = QModelIndex()) const;
|
||||||
int columnCount( QModelIndex const& parent = QModelIndex()) const;
|
int columnCount(QModelIndex const& parent = QModelIndex()) const;
|
||||||
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
|
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
||||||
private:
|
|
||||||
//std::shared_ptr<mapnik::Map> map_;
|
private:
|
||||||
const std::unique_ptr<node> root_;
|
// std::shared_ptr<mapnik::Map> map_;
|
||||||
|
const std::unique_ptr<node> root_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // STYLE_MODEL_HPP
|
#endif // STYLE_MODEL_HPP
|
||||||
|
|
|
@ -9,8 +9,7 @@ MAPNIK_DISABLE_WARNING_PUSH
|
||||||
#include "agg_conv_smooth_poly1.h"
|
#include "agg_conv_smooth_poly1.h"
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
|
|
||||||
struct vcgen_smooth_calucate_adaptive
|
struct vcgen_smooth_calucate_adaptive
|
||||||
{
|
{
|
||||||
|
@ -57,12 +56,8 @@ struct vcgen_smooth_calucate_adaptive
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {{v1.x + s1 * smooth_value * (v2.x - xm1), v1.y + s1 * smooth_value * (v2.y - ym1)},
|
||||||
{v1.x + s1 * smooth_value * (v2.x - xm1),
|
{v2.x + s2 * smooth_value * (v1.x - xm2), v2.y + s2 * smooth_value * (v1.y - ym2)}};
|
||||||
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>
|
template<class VertexSource>
|
||||||
using conv_smooth_adaptive = agg::conv_smooth_curve<VertexSource, vcgen_smooth_adaptive>;
|
using conv_smooth_adaptive = agg::conv_smooth_curve<VertexSource, vcgen_smooth_adaptive>;
|
||||||
|
|
||||||
template <typename Geometry>
|
template<typename Geometry>
|
||||||
class smooth_converter
|
class smooth_converter
|
||||||
{
|
{
|
||||||
Geometry geom_;
|
Geometry geom_;
|
||||||
|
@ -81,9 +76,9 @@ class smooth_converter
|
||||||
using impl_type = util::variant<basic_impl_type, adaptive_impl_type>;
|
using impl_type = util::variant<basic_impl_type, adaptive_impl_type>;
|
||||||
impl_type impl_;
|
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:
|
case SMOOTH_ALGORITHM_ADAPTIVE:
|
||||||
return adaptive_impl_type(geom);
|
return adaptive_impl_type(geom);
|
||||||
|
@ -94,46 +89,35 @@ class smooth_converter
|
||||||
return basic_impl_type(geom);
|
return basic_impl_type(geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
smooth_converter(Geometry & geom) :
|
smooth_converter(Geometry& geom)
|
||||||
geom_(geom),
|
: geom_(geom)
|
||||||
impl_(std::move(init_impl(SMOOTH_ALGORITHM_BASIC, geom)))
|
, impl_(std::move(init_impl(SMOOTH_ALGORITHM_BASIC, geom)))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void algorithm(smooth_algorithm_enum algo)
|
void algorithm(smooth_algorithm_enum algo) { impl_ = init_impl(algo, geom_); }
|
||||||
{
|
|
||||||
impl_ = init_impl(algo, geom_);
|
|
||||||
}
|
|
||||||
|
|
||||||
void smooth_value(double v)
|
void smooth_value(double v)
|
||||||
{
|
{
|
||||||
return util::apply_visitor([=](auto & impl) {
|
return util::apply_visitor([=](auto& impl) { impl.smooth_value(v); }, impl_);
|
||||||
impl.smooth_value(v);
|
|
||||||
}, impl_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void rewind(unsigned path_id)
|
void rewind(unsigned path_id)
|
||||||
{
|
{
|
||||||
return util::apply_visitor([=](auto & impl) {
|
return util::apply_visitor([=](auto& impl) { return impl.rewind(path_id); }, impl_);
|
||||||
return impl.rewind(path_id);
|
|
||||||
}, impl_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned vertex(double* x, double* y)
|
unsigned vertex(double* x, double* y)
|
||||||
{
|
{
|
||||||
return util::apply_visitor([=](auto & impl) {
|
return util::apply_visitor([=](auto& impl) { return impl.vertex(x, y); }, impl_);
|
||||||
return impl.vertex(x, y);
|
|
||||||
}, impl_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned type() const
|
unsigned type() const
|
||||||
{
|
{
|
||||||
return util::apply_visitor([](auto const& impl) {
|
return util::apply_visitor([](auto const& impl) { return impl.type(); }, impl_);
|
||||||
return impl.type();
|
|
||||||
}, impl_);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_ADAPTIVE_SMOOTH_HPP
|
#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
|
struct agg_polygon_pattern : agg_pattern_base
|
||||||
{
|
{
|
||||||
using color_type = agg::rgba8;
|
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 pixfmt_type = agg::pixfmt_custom_blend_rgba<blender_type, agg::rendering_buffer>;
|
||||||
using wrap_x_type = agg::wrap_mode_repeat;
|
using wrap_x_type = agg::wrap_mode_repeat;
|
||||||
using wrap_y_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,
|
using img_source_type = agg::image_accessor_wrap<agg::pixfmt_rgba32_pre, wrap_x_type, wrap_y_type>;
|
||||||
wrap_x_type,
|
|
||||||
wrap_y_type>;
|
|
||||||
using span_gen_type = agg::span_pattern_rgba<img_source_type>;
|
using span_gen_type = agg::span_pattern_rgba<img_source_type>;
|
||||||
using renderer_base = agg::renderer_base<pixfmt_type>;
|
using renderer_base = agg::renderer_base<pixfmt_type>;
|
||||||
using renderer_type = agg::renderer_scanline_aa_alpha<renderer_base,
|
using renderer_type =
|
||||||
agg::span_allocator<agg::rgba8>,
|
agg::renderer_scanline_aa_alpha<renderer_base, agg::span_allocator<agg::rgba8>, span_gen_type>;
|
||||||
span_gen_type>;
|
|
||||||
|
|
||||||
agg_polygon_pattern(image_rgba8 const& pattern_img,
|
agg_polygon_pattern(image_rgba8 const& pattern_img,
|
||||||
renderer_common const& common,
|
renderer_common const& common,
|
||||||
symbolizer_base const& sym,
|
symbolizer_base const& sym,
|
||||||
mapnik::feature_impl const& feature,
|
mapnik::feature_impl const& feature,
|
||||||
proj_transform const& prj_trans)
|
proj_transform const& prj_trans)
|
||||||
: agg_pattern_base{pattern_img, common, sym, feature, prj_trans},
|
: agg_pattern_base{pattern_img, common, sym, feature, prj_trans}
|
||||||
clip_(get<value_bool, keys::clip>(sym_, feature_, common_.vars_)),
|
, clip_(get<value_bool, keys::clip>(sym_, feature_, common_.vars_))
|
||||||
clip_box_(clipping_extent(common)),
|
, clip_box_(clipping_extent(common))
|
||||||
tr_(geom_transform()),
|
, tr_(geom_transform())
|
||||||
converter_(clip_box_, sym, common.t_, prj_trans, tr_,
|
, converter_(clip_box_, sym, common.t_, prj_trans, tr_, feature, common.vars_, common.scale_factor_)
|
||||||
feature, common.vars_, common.scale_factor_)
|
|
||||||
{
|
{
|
||||||
value_double simplify_tolerance = get<value_double, keys::simplify_tolerance>(sym_, feature_, common_.vars_);
|
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_);
|
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>();
|
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_,
|
coord<double, 2> offset(
|
||||||
pattern_img_.width(), pattern_img_.height()));
|
pattern_offset(sym_, feature_, prj_trans_, common_, pattern_img_.width(), pattern_img_.height()));
|
||||||
agg::rendering_buffer pattern_rbuf((agg::int8u*)pattern_img_.bytes(),
|
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);
|
pattern_img_.width() * 4);
|
||||||
agg::pixfmt_rgba32_pre pixf_pattern(pattern_rbuf);
|
agg::pixfmt_rgba32_pre pixf_pattern(pattern_rbuf);
|
||||||
img_source_type img_src(pixf_pattern);
|
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_);
|
value_double opacity = get<double, keys::opacity>(sym_, feature_, common_.vars_);
|
||||||
renderer_type rp(ren_base, sa, sg, unsigned(opacity * 255));
|
renderer_type rp(ren_base, sa, sg, unsigned(opacity * 255));
|
||||||
|
|
||||||
using apply_vertex_converter_type = detail::apply_vertex_converter<
|
using apply_vertex_converter_type = detail::apply_vertex_converter<VertexConverter, rasterizer>;
|
||||||
VertexConverter, rasterizer>;
|
|
||||||
using vertex_processor_type = geometry::vertex_processor<apply_vertex_converter_type>;
|
using vertex_processor_type = geometry::vertex_processor<apply_vertex_converter_type>;
|
||||||
apply_vertex_converter_type apply(converter_, ras);
|
apply_vertex_converter_type apply(converter_, ras);
|
||||||
mapnik::util::apply_visitor(vertex_processor_type(apply), feature_.get_geometry());
|
mapnik::util::apply_visitor(vertex_processor_type(apply), feature_.get_geometry());
|
||||||
|
@ -139,5 +137,4 @@ struct agg_polygon_pattern : agg_pattern_base
|
||||||
|
|
||||||
} // namespace mapnik
|
} // namespace mapnik
|
||||||
|
|
||||||
|
|
||||||
#endif // MAPNIK_RENDER_POLYGON_PATTERN_HPP
|
#endif // MAPNIK_RENDER_POLYGON_PATTERN_HPP
|
||||||
|
|
|
@ -34,31 +34,31 @@ MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
void set_gamma_method(T & ras_ptr, double gamma, gamma_method_enum method)
|
void set_gamma_method(T& ras_ptr, double gamma, gamma_method_enum method)
|
||||||
{
|
{
|
||||||
switch (method)
|
switch (method)
|
||||||
{
|
{
|
||||||
case GAMMA_POWER:
|
case GAMMA_POWER:
|
||||||
ras_ptr->gamma(agg::gamma_power(gamma));
|
ras_ptr->gamma(agg::gamma_power(gamma));
|
||||||
break;
|
break;
|
||||||
case GAMMA_LINEAR:
|
case GAMMA_LINEAR:
|
||||||
ras_ptr->gamma(agg::gamma_linear(0.0, gamma));
|
ras_ptr->gamma(agg::gamma_linear(0.0, gamma));
|
||||||
break;
|
break;
|
||||||
case GAMMA_NONE:
|
case GAMMA_NONE:
|
||||||
ras_ptr->gamma(agg::gamma_none());
|
ras_ptr->gamma(agg::gamma_none());
|
||||||
break;
|
break;
|
||||||
case GAMMA_THRESHOLD:
|
case GAMMA_THRESHOLD:
|
||||||
ras_ptr->gamma(agg::gamma_threshold(gamma));
|
ras_ptr->gamma(agg::gamma_threshold(gamma));
|
||||||
break;
|
break;
|
||||||
case GAMMA_MULTIPLY:
|
case GAMMA_MULTIPLY:
|
||||||
ras_ptr->gamma(agg::gamma_multiply(gamma));
|
ras_ptr->gamma(agg::gamma_multiply(gamma));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ras_ptr->gamma(agg::gamma_power(gamma));
|
ras_ptr->gamma(agg::gamma_power(gamma));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_AGG_HELPERS_HPP
|
#endif // MAPNIK_AGG_HELPERS_HPP
|
||||||
|
|
|
@ -33,36 +33,31 @@ MAPNIK_DISABLE_WARNING_PUSH
|
||||||
#include "agg_color_rgba.h"
|
#include "agg_color_rgba.h"
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
|
|
||||||
class pattern_source : private util::noncopyable
|
class pattern_source : private util::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
pattern_source(image_rgba8 const& pattern, double opacity = 1.0)
|
pattern_source(image_rgba8 const& pattern, double opacity = 1.0)
|
||||||
: pattern_(pattern),
|
: pattern_(pattern)
|
||||||
opacity_(opacity) {}
|
, opacity_(opacity)
|
||||||
|
{}
|
||||||
|
|
||||||
unsigned int width() const
|
unsigned int width() const { return pattern_.width(); }
|
||||||
{
|
unsigned int height() const { return pattern_.height(); }
|
||||||
return pattern_.width();
|
|
||||||
}
|
|
||||||
unsigned int height() const
|
|
||||||
{
|
|
||||||
return pattern_.height();
|
|
||||||
}
|
|
||||||
agg::rgba8 pixel(int x, int y) const
|
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_),
|
return agg::rgba8(static_cast<unsigned>((c & 0xff) * opacity_),
|
||||||
static_cast<unsigned>(((c >> 8) & 0xff) * opacity_),
|
static_cast<unsigned>(((c >> 8) & 0xff) * opacity_),
|
||||||
static_cast<unsigned>(((c >> 16) & 0xff) * opacity_),
|
static_cast<unsigned>(((c >> 16) & 0xff) * opacity_),
|
||||||
static_cast<unsigned>(((c >> 24) & 0xff) * opacity_));
|
static_cast<unsigned>(((c >> 24) & 0xff) * opacity_));
|
||||||
}
|
}
|
||||||
private:
|
|
||||||
|
private:
|
||||||
image_rgba8 const& pattern_;
|
image_rgba8 const& pattern_;
|
||||||
double opacity_;
|
double opacity_;
|
||||||
};
|
};
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_AGG_PATTERN_SOURCE_HPP
|
#endif // MAPNIK_AGG_PATTERN_SOURCE_HPP
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
// mapnik
|
// mapnik
|
||||||
#include <mapnik/util/noncopyable.hpp>
|
#include <mapnik/util/noncopyable.hpp>
|
||||||
|
|
||||||
|
|
||||||
#include <mapnik/warning.hpp>
|
#include <mapnik/warning.hpp>
|
||||||
MAPNIK_DISABLE_WARNING_PUSH
|
MAPNIK_DISABLE_WARNING_PUSH
|
||||||
#include <mapnik/warning_ignore_agg.hpp>
|
#include <mapnik/warning_ignore_agg.hpp>
|
||||||
|
@ -35,8 +34,10 @@ MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
namespace mapnik {
|
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
|
#endif // MAPNIK_AGG_RASTERIZER_HPP
|
||||||
|
|
|
@ -52,10 +52,14 @@ MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
template <typename SvgRenderer, typename RasterizerType, typename RendererBaseType>
|
template<typename SvgRenderer, typename RasterizerType, typename RendererBaseType>
|
||||||
void render_vector_marker(SvgRenderer & svg_renderer, RasterizerType & ras, RendererBaseType & renb,
|
void render_vector_marker(SvgRenderer& svg_renderer,
|
||||||
box2d<double> const& bbox, agg::trans_affine const& tr,
|
RasterizerType& ras,
|
||||||
double opacity, bool snap_to_pixels)
|
RendererBaseType& renb,
|
||||||
|
box2d<double> const& bbox,
|
||||||
|
agg::trans_affine const& tr,
|
||||||
|
double opacity,
|
||||||
|
bool snap_to_pixels)
|
||||||
{
|
{
|
||||||
agg::scanline_u8 sl;
|
agg::scanline_u8 sl;
|
||||||
if (snap_to_pixels)
|
if (snap_to_pixels)
|
||||||
|
@ -72,23 +76,25 @@ void render_vector_marker(SvgRenderer & svg_renderer, RasterizerType & ras, Rend
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename RendererType, typename RasterizerType>
|
template<typename RendererType, typename RasterizerType>
|
||||||
void render_raster_marker(RendererType renb, RasterizerType & ras, image_rgba8 const& src,
|
void render_raster_marker(RendererType renb,
|
||||||
agg::trans_affine const& tr, double opacity,
|
RasterizerType& ras,
|
||||||
float scale_factor, bool snap_to_pixels)
|
image_rgba8 const& src,
|
||||||
|
agg::trans_affine const& tr,
|
||||||
|
double opacity,
|
||||||
|
float scale_factor,
|
||||||
|
bool snap_to_pixels)
|
||||||
{
|
{
|
||||||
using color_type = agg::rgba8;
|
using color_type = agg::rgba8;
|
||||||
using const_rendering_buffer = util::rendering_buffer<image_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>;
|
using pixfmt_pre = agg::pixfmt_alpha_blend_rgba<agg::blender_rgba32_pre, const_rendering_buffer, agg::pixel32_type>;
|
||||||
|
|
||||||
agg::scanline_u8 sl;
|
agg::scanline_u8 sl;
|
||||||
double width = src.width();
|
double width = src.width();
|
||||||
double height = src.height();
|
double height = src.height();
|
||||||
if (std::fabs(1.0 - scale_factor) < 0.001
|
if (std::fabs(1.0 - scale_factor) < 0.001 && (std::fabs(1.0 - tr.sx) < agg::affine_epsilon) &&
|
||||||
&& (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(0.0 - tr.shy) < agg::affine_epsilon)
|
(std::fabs(1.0 - tr.sy) < 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);
|
const_rendering_buffer src_buffer(src);
|
||||||
pixfmt_pre pixf_mask(src_buffer);
|
pixfmt_pre pixf_mask(src_buffer);
|
||||||
|
@ -98,32 +104,31 @@ void render_raster_marker(RendererType renb, RasterizerType & ras, image_rgba8 c
|
||||||
0,
|
0,
|
||||||
static_cast<int>(std::floor(tr.tx + .5)),
|
static_cast<int>(std::floor(tr.tx + .5)),
|
||||||
static_cast<int>(std::floor(tr.ty + .5)),
|
static_cast<int>(std::floor(tr.ty + .5)),
|
||||||
unsigned(255*opacity));
|
unsigned(255 * opacity));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
renb.blend_from(pixf_mask,
|
renb.blend_from(pixf_mask, 0, static_cast<int>(tr.tx), static_cast<int>(tr.ty), unsigned(255 * opacity));
|
||||||
0,
|
|
||||||
static_cast<int>(tr.tx),
|
|
||||||
static_cast<int>(tr.ty),
|
|
||||||
unsigned(255*opacity));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
using img_accessor_type = agg::image_accessor_clone<pixfmt_pre>;
|
using img_accessor_type = agg::image_accessor_clone<pixfmt_pre>;
|
||||||
using interpolator_type = agg::span_interpolator_linear<>;
|
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 span_gen_type = agg::span_image_resample_rgba_affine<img_accessor_type>;
|
||||||
using renderer_type = agg::renderer_scanline_aa_alpha<RendererType,
|
using renderer_type =
|
||||||
agg::span_allocator<color_type>,
|
agg::renderer_scanline_aa_alpha<RendererType, agg::span_allocator<color_type>, span_gen_type>;
|
||||||
span_gen_type>;
|
|
||||||
|
|
||||||
double p[8];
|
double p[8];
|
||||||
p[0] = 0; p[1] = 0;
|
p[0] = 0;
|
||||||
p[2] = width; p[3] = 0;
|
p[1] = 0;
|
||||||
p[4] = width; p[5] = height;
|
p[2] = width;
|
||||||
p[6] = 0; p[7] = height;
|
p[3] = 0;
|
||||||
|
p[4] = width;
|
||||||
|
p[5] = height;
|
||||||
|
p[6] = 0;
|
||||||
|
p[7] = height;
|
||||||
tr.transform(&p[0], &p[1]);
|
tr.transform(&p[0], &p[1]);
|
||||||
tr.transform(&p[2], &p[3]);
|
tr.transform(&p[2], &p[3]);
|
||||||
tr.transform(&p[4], &p[5]);
|
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);
|
agg::trans_affine final_tr(p, 0, 0, width, height);
|
||||||
if (snap_to_pixels)
|
if (snap_to_pixels)
|
||||||
{
|
{
|
||||||
final_tr.tx = std::floor(final_tr.tx+.5);
|
final_tr.tx = std::floor(final_tr.tx + .5);
|
||||||
final_tr.ty = std::floor(final_tr.ty+.5);
|
final_tr.ty = std::floor(final_tr.ty + .5);
|
||||||
}
|
}
|
||||||
interpolator_type interpolator(final_tr);
|
interpolator_type interpolator(final_tr);
|
||||||
span_gen_type sg(ia, interpolator, filter);
|
span_gen_type sg(ia, interpolator, filter);
|
||||||
renderer_type rp(renb, sa, sg, unsigned(opacity*255));
|
renderer_type rp(renb, sa, sg, unsigned(opacity * 255));
|
||||||
ras.move_to_d(p[0],p[1]);
|
ras.move_to_d(p[0], p[1]);
|
||||||
ras.line_to_d(p[2],p[3]);
|
ras.line_to_d(p[2], p[3]);
|
||||||
ras.line_to_d(p[4],p[5]);
|
ras.line_to_d(p[4], p[5]);
|
||||||
ras.line_to_d(p[6],p[7]);
|
ras.line_to_d(p[6], p[7]);
|
||||||
agg::render_scanlines(ras, sl, rp);
|
agg::render_scanlines(ras, sl, rp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_AGG_RENDER_MARKER_HPP
|
#endif // MAPNIK_AGG_RENDER_MARKER_HPP
|
||||||
|
|
|
@ -24,13 +24,13 @@
|
||||||
#define MAPNIK_AGG_RENDERER_HPP
|
#define MAPNIK_AGG_RENDERER_HPP
|
||||||
|
|
||||||
// mapnik
|
// mapnik
|
||||||
#include <mapnik/config.hpp> // for MAPNIK_DECL
|
#include <mapnik/config.hpp> // for MAPNIK_DECL
|
||||||
#include <mapnik/feature_style_processor.hpp>
|
#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/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/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/pixel_position.hpp>
|
||||||
#include <mapnik/request.hpp>
|
#include <mapnik/request.hpp>
|
||||||
#include <mapnik/symbolizer_enumerations.hpp>
|
#include <mapnik/symbolizer_enumerations.hpp>
|
||||||
|
@ -41,38 +41,40 @@
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
|
||||||
// fwd declaration to avoid dependence on agg headers
|
// fwd declaration to avoid dependence on agg headers
|
||||||
namespace agg { struct trans_affine; }
|
namespace agg {
|
||||||
|
struct trans_affine;
|
||||||
|
}
|
||||||
|
|
||||||
// fwd declarations to speed up compile
|
// fwd declarations to speed up compile
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
class Map;
|
class Map;
|
||||||
class feature_impl;
|
class feature_impl;
|
||||||
class feature_type_style;
|
class feature_type_style;
|
||||||
class label_collision_detector4;
|
class label_collision_detector4;
|
||||||
class layer;
|
class layer;
|
||||||
class color;
|
class color;
|
||||||
struct marker;
|
struct marker;
|
||||||
class proj_transform;
|
class proj_transform;
|
||||||
struct rasterizer;
|
struct rasterizer;
|
||||||
struct rgba8_t;
|
struct rgba8_t;
|
||||||
template<typename T> class image;
|
template<typename T>
|
||||||
}
|
class image;
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
class buffer_stack
|
class buffer_stack
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
buffer_stack(std::size_t width, std::size_t height)
|
buffer_stack(std::size_t width, std::size_t height)
|
||||||
: width_(width),
|
: width_(width)
|
||||||
height_(height),
|
, height_(height)
|
||||||
buffers_(),
|
, buffers_()
|
||||||
position_(buffers_.begin())
|
, position_(buffers_.begin())
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
T & push()
|
T& push()
|
||||||
{
|
{
|
||||||
if (position_ == buffers_.begin())
|
if (position_ == buffers_.begin())
|
||||||
{
|
{
|
||||||
|
@ -86,10 +88,7 @@ public:
|
||||||
}
|
}
|
||||||
return *position_;
|
return *position_;
|
||||||
}
|
}
|
||||||
bool in_range() const
|
bool in_range() const { return (position_ != buffers_.end()); }
|
||||||
{
|
|
||||||
return (position_ != buffers_.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
void pop()
|
void pop()
|
||||||
{
|
{
|
||||||
|
@ -98,34 +97,44 @@ public:
|
||||||
++position_;
|
++position_;
|
||||||
}
|
}
|
||||||
|
|
||||||
T & top() const
|
T& top() const { return *position_; }
|
||||||
{
|
|
||||||
return *position_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::size_t width_;
|
const std::size_t width_;
|
||||||
const std::size_t height_;
|
const std::size_t height_;
|
||||||
std::deque<T> buffers_;
|
std::deque<T> buffers_;
|
||||||
typename std::deque<T>::iterator position_;
|
typename std::deque<T>::iterator position_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T0, typename T1=label_collision_detector4>
|
template<typename T0, typename T1 = label_collision_detector4>
|
||||||
class MAPNIK_DECL agg_renderer : public feature_style_processor<agg_renderer<T0> >,
|
class MAPNIK_DECL agg_renderer : public feature_style_processor<agg_renderer<T0>>,
|
||||||
private util::noncopyable
|
private util::noncopyable
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
public:
|
|
||||||
using buffer_type = T0;
|
using buffer_type = T0;
|
||||||
using processor_impl_type = agg_renderer<T0>;
|
using processor_impl_type = agg_renderer<T0>;
|
||||||
using detector_type = T1;
|
using detector_type = T1;
|
||||||
// create with default, empty placement detector
|
// 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
|
// create with external placement detector, possibly non-empty
|
||||||
agg_renderer(Map const &m, buffer_type & pixmap, std::shared_ptr<detector_type> detector,
|
agg_renderer(Map const& m,
|
||||||
double scale_factor=1.0, unsigned offset_x=0, unsigned offset_y=0);
|
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
|
// 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();
|
~agg_renderer();
|
||||||
void start_map_processing(Map const& map);
|
void start_map_processing(Map const& map);
|
||||||
void end_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 start_style_processing(feature_type_style const& st);
|
||||||
void end_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,
|
void render_marker(pixel_position const& pos,
|
||||||
double opacity, composite_mode_e comp_op);
|
marker const& marker,
|
||||||
|
agg::trans_affine const& tr,
|
||||||
|
double opacity,
|
||||||
|
composite_mode_e comp_op);
|
||||||
|
|
||||||
void process(point_symbolizer const& sym,
|
void process(point_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
mapnik::feature_impl & feature,
|
void process(line_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
proj_transform const& prj_trans);
|
void process(line_pattern_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
void process(line_symbolizer const& sym,
|
void process(polygon_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
mapnik::feature_impl & feature,
|
void process(polygon_pattern_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
proj_transform const& prj_trans);
|
void process(raster_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
void process(line_pattern_symbolizer const& sym,
|
void process(shield_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
mapnik::feature_impl & feature,
|
void process(text_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
proj_transform const& prj_trans);
|
void process(building_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
void process(polygon_symbolizer const& sym,
|
void process(markers_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
mapnik::feature_impl & feature,
|
void process(group_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
proj_transform const& prj_trans);
|
void process(debug_symbolizer const& sym, feature_impl& feature, proj_transform const& prj_trans);
|
||||||
void process(polygon_pattern_symbolizer const& sym,
|
void process(dot_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
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&,
|
inline bool process(rule::symbolizers const&, mapnik::feature_impl&, proj_transform const&)
|
||||||
mapnik::feature_impl&,
|
|
||||||
proj_transform const& )
|
|
||||||
{
|
{
|
||||||
// agg renderer doesn't support processing of multiple symbolizers.
|
// agg renderer doesn't support processing of multiple symbolizers.
|
||||||
return false;
|
return false;
|
||||||
|
@ -189,29 +173,19 @@ public:
|
||||||
void painted(bool painted);
|
void painted(bool painted);
|
||||||
bool painted();
|
bool painted();
|
||||||
|
|
||||||
inline eAttributeCollectionPolicy attribute_collection_policy() const
|
inline eAttributeCollectionPolicy attribute_collection_policy() const { return DEFAULT; }
|
||||||
{
|
|
||||||
return DEFAULT;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline double scale_factor() const
|
inline double scale_factor() const { return common_.scale_factor_; }
|
||||||
{
|
|
||||||
return common_.scale_factor_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline attributes const& variables() const
|
inline attributes const& variables() const { return common_.vars_; }
|
||||||
{
|
|
||||||
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);
|
|
||||||
|
|
||||||
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_;
|
std::stack<std::reference_wrapper<buffer_type>> buffers_;
|
||||||
buffer_stack<buffer_type> internal_buffers_;
|
buffer_stack<buffer_type> internal_buffers_;
|
||||||
std::unique_ptr<buffer_type> inflated_buffer_;
|
std::unique_ptr<buffer_type> inflated_buffer_;
|
||||||
|
@ -219,7 +193,7 @@ private:
|
||||||
gamma_method_enum gamma_method_;
|
gamma_method_enum gamma_method_;
|
||||||
double gamma_;
|
double gamma_;
|
||||||
renderer_common common_;
|
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>>;
|
extern template class MAPNIK_DECL agg_renderer<image<rgba8_t>>;
|
||||||
|
|
|
@ -37,20 +37,21 @@ struct attribute
|
||||||
{
|
{
|
||||||
std::string name_;
|
std::string name_;
|
||||||
explicit attribute(std::string const& _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
|
V const& value(F const& f) const
|
||||||
{
|
{
|
||||||
return f.get(name_);
|
return f.get(name_);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string const& name() const { return name_;}
|
std::string const& name() const { return name_; }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct geometry_type_attribute
|
struct geometry_type_attribute
|
||||||
{
|
{
|
||||||
template <typename V, typename F>
|
template<typename V, typename F>
|
||||||
V value(F const& f) const
|
V value(F const& f) const
|
||||||
{
|
{
|
||||||
return static_cast<mapnik::value_integer>(util::to_ds_type(f.get_geometry()));
|
return static_cast<mapnik::value_integer>(util::to_ds_type(f.get_geometry()));
|
||||||
|
@ -61,10 +62,11 @@ struct global_attribute
|
||||||
{
|
{
|
||||||
std::string name;
|
std::string name;
|
||||||
explicit global_attribute(std::string const& name_)
|
explicit global_attribute(std::string const& name_)
|
||||||
: name(name_) {}
|
: name(name_)
|
||||||
|
{}
|
||||||
|
|
||||||
template <typename V, typename C>
|
template<typename V, typename C>
|
||||||
V const& operator() (C const& ctx)
|
V const& operator()(C const& ctx)
|
||||||
{
|
{
|
||||||
return ctx.get(name);
|
return ctx.get(name);
|
||||||
}
|
}
|
||||||
|
@ -72,6 +74,6 @@ struct global_attribute
|
||||||
|
|
||||||
using attributes = std::unordered_map<std::string, value>;
|
using attributes = std::unordered_map<std::string, value>;
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_ATTRIBUTE_HPP
|
#endif // MAPNIK_ATTRIBUTE_HPP
|
||||||
|
|
|
@ -28,11 +28,11 @@
|
||||||
#include <mapnik/util/noncopyable.hpp>
|
#include <mapnik/util/noncopyable.hpp>
|
||||||
#include <mapnik/attribute.hpp>
|
#include <mapnik/attribute.hpp>
|
||||||
#include <mapnik/symbolizer.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/expression_node.hpp>
|
||||||
#include <mapnik/parse_path.hpp> // for path_processor_type
|
#include <mapnik/parse_path.hpp> // for path_processor_type
|
||||||
#include <mapnik/path_expression.hpp> // for path_expression_ptr
|
#include <mapnik/path_expression.hpp> // for path_expression_ptr
|
||||||
#include <mapnik/text/placements/base.hpp> // for text_placements
|
#include <mapnik/text/placements/base.hpp> // for text_placements
|
||||||
#include <mapnik/image_scaling.hpp>
|
#include <mapnik/image_scaling.hpp>
|
||||||
#include <mapnik/group/group_symbolizer_properties.hpp>
|
#include <mapnik/group/group_symbolizer_properties.hpp>
|
||||||
#include <mapnik/group/group_rule.hpp>
|
#include <mapnik/group/group_rule.hpp>
|
||||||
|
@ -51,76 +51,71 @@ MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
template <typename Container>
|
template<typename Container>
|
||||||
struct expression_attributes
|
struct expression_attributes
|
||||||
{
|
{
|
||||||
explicit expression_attributes(Container& names)
|
explicit expression_attributes(Container& names)
|
||||||
: names_(names) {}
|
: names_(names)
|
||||||
|
{}
|
||||||
|
|
||||||
void operator() (attribute const& attr) const
|
void operator()(attribute const& attr) const { names_.emplace(attr.name()); }
|
||||||
{
|
|
||||||
names_.emplace(attr.name());
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Tag>
|
template<typename Tag>
|
||||||
void operator() (binary_node<Tag> const& x) const
|
void operator()(binary_node<Tag> const& x) const
|
||||||
{
|
{
|
||||||
util::apply_visitor(*this, x.left);
|
util::apply_visitor(*this, x.left);
|
||||||
util::apply_visitor(*this, x.right);
|
util::apply_visitor(*this, x.right);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Tag>
|
template<typename Tag>
|
||||||
void operator() (unary_node<Tag> const& x) const
|
void operator()(unary_node<Tag> const& x) const
|
||||||
{
|
{
|
||||||
util::apply_visitor(*this, x.expr);
|
util::apply_visitor(*this, x.expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator() (regex_match_node const& x) const
|
void operator()(regex_match_node const& x) const { util::apply_visitor(*this, x.expr); }
|
||||||
{
|
|
||||||
util::apply_visitor(*this, x.expr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void operator() (regex_replace_node const& x) const
|
void operator()(regex_replace_node const& x) const { util::apply_visitor(*this, x.expr); }
|
||||||
{
|
|
||||||
util::apply_visitor(*this, x.expr);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
void operator() (T const&) const {}
|
void operator()(T const&) const
|
||||||
|
{}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Container& names_;
|
Container& names_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class group_attribute_collector : public util::noncopyable
|
class group_attribute_collector : public util::noncopyable
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::set<std::string>& names_;
|
std::set<std::string>& names_;
|
||||||
bool expand_index_columns_;
|
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
|
struct extract_attribute_names
|
||||||
{
|
{
|
||||||
explicit extract_attribute_names(Container& names)
|
explicit extract_attribute_names(Container& names)
|
||||||
: names_(names),
|
: names_(names)
|
||||||
f_attr_(names) {}
|
, f_attr_(names)
|
||||||
|
{}
|
||||||
|
|
||||||
void operator() (mapnik::expression_ptr const& expr) const
|
void operator()(mapnik::expression_ptr const& expr) const
|
||||||
{
|
{
|
||||||
if (expr)
|
if (expr)
|
||||||
{
|
{
|
||||||
util::apply_visitor(f_attr_, *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)
|
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)
|
if (expr)
|
||||||
{
|
{
|
||||||
|
@ -136,39 +131,41 @@ struct extract_attribute_names
|
||||||
expression_set expressions;
|
expression_set expressions;
|
||||||
// TODO - optimize (dane)
|
// TODO - optimize (dane)
|
||||||
expr->add_expressions(expressions);
|
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)
|
if (expr)
|
||||||
{
|
{
|
||||||
path_processor_type::collect_attributes(*expr,names_);
|
path_processor_type::collect_attributes(*expr, names_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
void operator() (T const&) const {}
|
void operator()(T const&) const
|
||||||
|
{}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Container& names_;
|
Container& names_;
|
||||||
expression_attributes<std::set<std::string> > f_attr_;
|
expression_attributes<std::set<std::string>> f_attr_;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct symbolizer_attributes
|
struct symbolizer_attributes
|
||||||
{
|
{
|
||||||
symbolizer_attributes(std::set<std::string>& names,
|
symbolizer_attributes(std::set<std::string>& names, double& filter_factor)
|
||||||
double & filter_factor)
|
: filter_factor_(filter_factor)
|
||||||
: filter_factor_(filter_factor),
|
, f_attrs_(names)
|
||||||
f_attrs_(names),
|
, g_attrs_(names, true)
|
||||||
g_attrs_(names, true) {}
|
{}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
void operator () (T const& sym)
|
void operator()(T const& sym)
|
||||||
{
|
{
|
||||||
for (auto const& prop : sym.properties)
|
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);
|
boost::optional<double> filter_factor = get_optional<double>(sym, keys::filter_factor);
|
||||||
if (filter_factor)
|
if (filter_factor)
|
||||||
|
@ -197,57 +194,51 @@ struct symbolizer_attributes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator () (group_symbolizer const& sym)
|
void operator()(group_symbolizer const& sym) { g_attrs_(sym); }
|
||||||
{
|
|
||||||
g_attrs_(sym);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double & filter_factor_;
|
double& filter_factor_;
|
||||||
extract_attribute_names<std::set<std::string> > f_attrs_;
|
extract_attribute_names<std::set<std::string>> f_attrs_;
|
||||||
group_attribute_collector g_attrs_;
|
group_attribute_collector g_attrs_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class attribute_collector : public util::noncopyable
|
class attribute_collector : public util::noncopyable
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::set<std::string> & names_;
|
std::set<std::string>& names_;
|
||||||
double filter_factor_;
|
double filter_factor_;
|
||||||
expression_attributes<std::set<std::string> > f_attr;
|
expression_attributes<std::set<std::string>> f_attr;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
|
|
||||||
attribute_collector(std::set<std::string>& names)
|
attribute_collector(std::set<std::string>& names)
|
||||||
: names_(names),
|
: names_(names)
|
||||||
filter_factor_(1.0),
|
, filter_factor_(1.0)
|
||||||
f_attr(names) {}
|
, f_attr(names)
|
||||||
template <typename RuleType>
|
{}
|
||||||
void operator() (RuleType const& r)
|
template<typename RuleType>
|
||||||
|
void operator()(RuleType const& r)
|
||||||
{
|
{
|
||||||
typename RuleType::symbolizers const& symbols = r.get_symbolizers();
|
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)
|
for (auto const& sym : symbols)
|
||||||
{
|
{
|
||||||
util::apply_visitor(std::ref(s_attr), sym);
|
util::apply_visitor(std::ref(s_attr), sym);
|
||||||
}
|
}
|
||||||
|
|
||||||
expression_ptr const& expr = r.get_filter();
|
expression_ptr const& expr = r.get_filter();
|
||||||
util::apply_visitor(f_attr,*expr);
|
util::apply_visitor(f_attr, *expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
double get_filter_factor() const
|
double get_filter_factor() const { return filter_factor_; }
|
||||||
{
|
|
||||||
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
|
// find all column names referenced in the group symbolizer
|
||||||
std::set<std::string> group_columns;
|
std::set<std::string> group_columns;
|
||||||
attribute_collector column_collector(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
|
// get columns from symbolizer repeat key
|
||||||
expression_ptr repeat_key = get<mapnik::expression_ptr>(sym, keys::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)
|
for (value_integer col_idx = start; col_idx < end; ++col_idx)
|
||||||
{
|
{
|
||||||
std::string col_idx_str;
|
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;
|
std::string col_idx_name = col_name;
|
||||||
boost::replace_all(col_idx_name, "%", col_idx_str);
|
boost::replace_all(col_idx_name, "%", col_idx_str);
|
||||||
|
|
|
@ -27,35 +27,30 @@
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
enum eAttributeType {
|
enum eAttributeType { Integer = 1, Float = 2, Double = 3, String = 4, Boolean = 5, Geometry = 6, Object = 7 };
|
||||||
Integer=1,
|
|
||||||
Float =2,
|
|
||||||
Double =3,
|
|
||||||
String =4,
|
|
||||||
Boolean =5,
|
|
||||||
Geometry=6,
|
|
||||||
Object=7
|
|
||||||
};
|
|
||||||
|
|
||||||
class attribute_descriptor
|
class attribute_descriptor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
attribute_descriptor(std::string const& name,unsigned type,
|
attribute_descriptor(std::string const& name,
|
||||||
bool primary_key=false,
|
unsigned type,
|
||||||
int size=-1,
|
bool primary_key = false,
|
||||||
int precision=-1)
|
int size = -1,
|
||||||
: name_(name),
|
int precision = -1)
|
||||||
type_(type),
|
: name_(name)
|
||||||
size_(size),
|
, type_(type)
|
||||||
precision_(precision),
|
, size_(size)
|
||||||
primary_key_(primary_key) {}
|
, precision_(precision)
|
||||||
|
, primary_key_(primary_key)
|
||||||
|
{}
|
||||||
|
|
||||||
attribute_descriptor(attribute_descriptor const& other)
|
attribute_descriptor(attribute_descriptor const& other)
|
||||||
: name_(other.name_),
|
: name_(other.name_)
|
||||||
type_(other.type_),
|
, type_(other.type_)
|
||||||
size_(other.size_),
|
, size_(other.size_)
|
||||||
precision_(other.precision_),
|
, precision_(other.precision_)
|
||||||
primary_key_(other.primary_key_) {}
|
, primary_key_(other.primary_key_)
|
||||||
|
{}
|
||||||
|
|
||||||
attribute_descriptor& operator=(attribute_descriptor rhs)
|
attribute_descriptor& operator=(attribute_descriptor rhs)
|
||||||
{
|
{
|
||||||
|
@ -68,32 +63,17 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string const& get_name() const
|
std::string const& get_name() const { return name_; }
|
||||||
{
|
|
||||||
return name_;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int get_type() const
|
unsigned int get_type() const { return type_; }
|
||||||
{
|
|
||||||
return type_;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool is_primary_key() const
|
bool is_primary_key() const { return primary_key_; }
|
||||||
{
|
|
||||||
return primary_key_;
|
|
||||||
}
|
|
||||||
|
|
||||||
int get_size() const
|
int get_size() const { return size_; }
|
||||||
{
|
|
||||||
return size_;
|
|
||||||
}
|
|
||||||
|
|
||||||
int get_precision() const
|
int get_precision() const { return precision_; }
|
||||||
{
|
|
||||||
return precision_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string name_;
|
std::string name_;
|
||||||
unsigned int type_;
|
unsigned int type_;
|
||||||
int size_;
|
int size_;
|
||||||
|
@ -101,6 +81,6 @@ private:
|
||||||
bool primary_key_;
|
bool primary_key_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_ATTRIBUTE_DESCRIPTOR_HPP
|
#endif // MAPNIK_ATTRIBUTE_DESCRIPTOR_HPP
|
||||||
|
|
|
@ -30,25 +30,24 @@
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
|
|
||||||
class MAPNIK_DECL boolean_type
|
class MAPNIK_DECL boolean_type
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
boolean_type()
|
boolean_type()
|
||||||
: b_(false) {}
|
: b_(false)
|
||||||
|
{}
|
||||||
boolean_type(bool b)
|
boolean_type(bool b)
|
||||||
: b_(b) {}
|
: b_(b)
|
||||||
|
{}
|
||||||
boolean_type(boolean_type const& b)
|
boolean_type(boolean_type const& b)
|
||||||
: b_(b.b_) {}
|
: b_(b.b_)
|
||||||
|
{}
|
||||||
|
|
||||||
operator bool() const
|
operator bool() const { return b_; }
|
||||||
{
|
|
||||||
return b_;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean_type & operator =(boolean_type const& other)
|
boolean_type& operator=(boolean_type const& other)
|
||||||
{
|
{
|
||||||
if (this == &other)
|
if (this == &other)
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -56,33 +55,32 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool b_;
|
bool b_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Special stream input operator for boolean_type values
|
// Special stream input operator for boolean_type values
|
||||||
template <typename charT, typename traits>
|
template<typename charT, typename traits>
|
||||||
std::basic_istream<charT, traits> &
|
std::basic_istream<charT, traits>& operator>>(std::basic_istream<charT, traits>& s, boolean_type& b)
|
||||||
operator >> ( std::basic_istream<charT, traits> & s, boolean_type & b )
|
|
||||||
{
|
{
|
||||||
if ( s )
|
if (s)
|
||||||
{
|
{
|
||||||
std::string word;
|
std::string word;
|
||||||
s >> word;
|
s >> word;
|
||||||
bool result;
|
bool result;
|
||||||
if (util::string2bool(word,result)) b = result;
|
if (util::string2bool(word, result))
|
||||||
|
b = result;
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename charT, typename traits>
|
template<typename charT, typename traits>
|
||||||
std::basic_ostream<charT, traits> &
|
std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& s, boolean_type const& b)
|
||||||
operator << ( std::basic_ostream<charT, traits> & s, boolean_type const& b )
|
|
||||||
{
|
{
|
||||||
s << ( b ? "true" : "false" );
|
s << (b ? "true" : "false");
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_BOOLEAN_HPP
|
#endif // MAPNIK_BOOLEAN_HPP
|
||||||
|
|
|
@ -23,17 +23,21 @@
|
||||||
#ifndef MAPNIK_BOOST_SPIRIT_INSTANTIATE_HPP
|
#ifndef MAPNIK_BOOST_SPIRIT_INSTANTIATE_HPP
|
||||||
#define 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
|
// helper macro
|
||||||
#define BOOST_SPIRIT_INSTANTIATE_UNUSED(rule_type, Iterator, Context) \
|
#define BOOST_SPIRIT_INSTANTIATE_UNUSED(rule_type, Iterator, Context) \
|
||||||
template bool parse_rule<Iterator, Context, boost::spirit::x3::unused_type const>( \
|
template bool parse_rule<Iterator, Context, boost::spirit::x3::unused_type const>( \
|
||||||
rule_type rule_ \
|
rule_type rule_, \
|
||||||
, Iterator& first, Iterator const& last \
|
Iterator & first, \
|
||||||
, Context const& context, boost::spirit::x3::unused_type const& ); \
|
Iterator const& last, \
|
||||||
|
Context const& context, \
|
||||||
|
boost::spirit::x3::unused_type const&); \
|
||||||
/***/
|
/***/
|
||||||
|
|
||||||
}}}
|
} // namespace x3
|
||||||
|
} // namespace spirit
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
#endif // MAPNIK_BOOST_SPIRIT_INSTANTIATE_HPP
|
#endif // MAPNIK_BOOST_SPIRIT_INSTANTIATE_HPP
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
*
|
*
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#ifndef MAPNIK_CAIRO_CONTEXT_HPP
|
#ifndef MAPNIK_CAIRO_CONTEXT_HPP
|
||||||
#define MAPNIK_CAIRO_CONTEXT_HPP
|
#define MAPNIK_CAIRO_CONTEXT_HPP
|
||||||
|
|
||||||
|
@ -57,7 +56,8 @@ MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
template <typename T> class box2d;
|
template<typename T>
|
||||||
|
class box2d;
|
||||||
|
|
||||||
using ErrorStatus = cairo_status_t;
|
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));
|
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)
|
inline void check_status_and_throw_exception(ErrorStatus status)
|
||||||
{
|
{
|
||||||
if(status != CAIRO_STATUS_SUCCESS)
|
if (status != CAIRO_STATUS_SUCCESS)
|
||||||
throw_exception(status);
|
throw_exception(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,60 +82,65 @@ void check_object_status_and_throw_exception(T const& object)
|
||||||
|
|
||||||
class cairo_face : private util::noncopyable
|
class cairo_face : private util::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
cairo_face(std::shared_ptr<font_library> const& library, face_ptr const& face);
|
cairo_face(std::shared_ptr<font_library> const& library, face_ptr const& face);
|
||||||
~cairo_face();
|
~cairo_face();
|
||||||
cairo_font_face_t * face() const;
|
cairo_font_face_t* face() const;
|
||||||
private:
|
|
||||||
|
private:
|
||||||
class handle
|
class handle
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
handle(std::shared_ptr<font_library> const& library, face_ptr const& face)
|
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_;
|
std::shared_ptr<font_library> library_;
|
||||||
face_ptr face_;
|
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;
|
delete h;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
face_ptr face_;
|
face_ptr face_;
|
||||||
cairo_font_face_t *c_face_;
|
cairo_font_face_t* c_face_;
|
||||||
};
|
};
|
||||||
|
|
||||||
using cairo_face_ptr = std::shared_ptr<cairo_face>;
|
using cairo_face_ptr = std::shared_ptr<cairo_face>;
|
||||||
|
|
||||||
class cairo_face_manager : private util::noncopyable
|
class cairo_face_manager : private util::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
cairo_face_manager(std::shared_ptr<font_library> library);
|
cairo_face_manager(std::shared_ptr<font_library> library);
|
||||||
cairo_face_ptr get_face(face_ptr face);
|
cairo_face_ptr get_face(face_ptr face);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using cairo_face_cache = std::map<face_ptr,cairo_face_ptr>;
|
using cairo_face_cache = std::map<face_ptr, cairo_face_ptr>;
|
||||||
std::shared_ptr<font_library> font_library_;
|
std::shared_ptr<font_library> font_library_;
|
||||||
cairo_face_cache cache_;
|
cairo_face_cache cache_;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cairo_closer
|
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
|
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)
|
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
|
class cairo_pattern : private util::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit cairo_pattern(image_rgba8 const& data, double opacity = 1.0)
|
explicit cairo_pattern(image_rgba8 const& data, double opacity = 1.0)
|
||||||
{
|
{
|
||||||
std::size_t pixels = data.width() * data.height();
|
std::size_t pixels = data.width() * data.height();
|
||||||
const unsigned int *in_ptr = data.data();
|
const unsigned int* in_ptr = data.data();
|
||||||
const unsigned int *in_end = in_ptr + pixels;
|
const unsigned int* in_end = in_ptr + pixels;
|
||||||
unsigned int *out_ptr;
|
unsigned int* out_ptr;
|
||||||
|
|
||||||
surface_ = cairo_surface_ptr(
|
surface_ = cairo_surface_ptr(cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
|
||||||
cairo_image_surface_create(
|
static_cast<int>(data.width()),
|
||||||
CAIRO_FORMAT_ARGB32,
|
static_cast<int>(data.height())),
|
||||||
static_cast<int>(data.width()),
|
cairo_surface_closer());
|
||||||
static_cast<int>(data.height())),
|
|
||||||
cairo_surface_closer());
|
|
||||||
|
|
||||||
out_ptr = reinterpret_cast<unsigned int *>(
|
out_ptr = reinterpret_cast<unsigned int*>(cairo_image_surface_get_data(surface_.get()));
|
||||||
cairo_image_surface_get_data(surface_.get()));
|
|
||||||
|
|
||||||
while (in_ptr < in_end)
|
while (in_ptr < in_end)
|
||||||
{
|
{
|
||||||
|
@ -175,9 +177,9 @@ public:
|
||||||
unsigned int b = static_cast<unsigned>(((in >> 16) & 0xff) * opacity);
|
unsigned int b = static_cast<unsigned>(((in >> 16) & 0xff) * opacity);
|
||||||
unsigned int a = static_cast<unsigned>(((in >> 24) & 0xff) * opacity);
|
unsigned int a = static_cast<unsigned>(((in >> 24) & 0xff) * opacity);
|
||||||
|
|
||||||
//r = r * a / 255;
|
// r = r * a / 255;
|
||||||
//g = g * a / 255;
|
// g = g * a / 255;
|
||||||
//b = b * a / 255;
|
// b = b * a / 255;
|
||||||
|
|
||||||
*out_ptr++ = (a << 24) | (r << 16) | (g << 8) | b;
|
*out_ptr++ = (a << 24) | (r << 16) | (g << 8) | b;
|
||||||
}
|
}
|
||||||
|
@ -186,78 +188,65 @@ public:
|
||||||
pattern_ = cairo_pattern_create_for_surface(surface_.get());
|
pattern_ = cairo_pattern_create_for_surface(surface_.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
cairo_pattern(cairo_surface_ptr const& surface) :
|
cairo_pattern(cairo_surface_ptr const& surface)
|
||||||
surface_(surface),
|
: surface_(surface)
|
||||||
pattern_(cairo_pattern_create_for_surface(surface_.get()))
|
, pattern_(cairo_pattern_create_for_surface(surface_.get()))
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
~cairo_pattern()
|
~cairo_pattern()
|
||||||
{
|
{
|
||||||
if (pattern_) cairo_pattern_destroy(pattern_);
|
if (pattern_)
|
||||||
|
cairo_pattern_destroy(pattern_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_matrix(cairo_matrix_t const& matrix)
|
void set_matrix(cairo_matrix_t const& matrix) { cairo_pattern_set_matrix(pattern_, &matrix); }
|
||||||
{
|
|
||||||
cairo_pattern_set_matrix(pattern_, &matrix);
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_origin(double x, double y)
|
void set_origin(double x, double y)
|
||||||
{
|
{
|
||||||
cairo_matrix_t matrix;
|
cairo_matrix_t matrix;
|
||||||
cairo_pattern_get_matrix(pattern_,&matrix);
|
cairo_pattern_get_matrix(pattern_, &matrix);
|
||||||
matrix.x0 = -x;
|
matrix.x0 = -x;
|
||||||
matrix.y0 = -y;
|
matrix.y0 = -y;
|
||||||
cairo_pattern_set_matrix(pattern_,&matrix);
|
cairo_pattern_set_matrix(pattern_, &matrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_extend(cairo_extend_t extend)
|
void set_extend(cairo_extend_t extend) { cairo_pattern_set_extend(pattern_, extend); }
|
||||||
{
|
|
||||||
cairo_pattern_set_extend(pattern_, extend);
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_filter(cairo_filter_t filter)
|
void set_filter(cairo_filter_t filter) { cairo_pattern_set_filter(pattern_, filter); }
|
||||||
{
|
|
||||||
cairo_pattern_set_filter(pattern_, filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
cairo_pattern_t * pattern() const
|
cairo_pattern_t* pattern() const { return pattern_; }
|
||||||
{
|
|
||||||
return pattern_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
cairo_surface_ptr surface_;
|
cairo_surface_ptr surface_;
|
||||||
cairo_pattern_t * pattern_;
|
cairo_pattern_t* pattern_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class cairo_gradient : private util::noncopyable
|
class cairo_gradient : private util::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
cairo_gradient(mapnik::gradient const& grad, double opacity=1.0)
|
cairo_gradient(mapnik::gradient const& grad, double opacity = 1.0)
|
||||||
{
|
{
|
||||||
double x1,x2,y1,y2,rad;
|
double x1, x2, y1, y2, rad;
|
||||||
grad.get_control_points(x1,y1,x2,y2,rad);
|
grad.get_control_points(x1, y1, x2, y2, rad);
|
||||||
if (grad.get_gradient_type() == LINEAR)
|
if (grad.get_gradient_type() == LINEAR)
|
||||||
{
|
{
|
||||||
pattern_ = cairo_pattern_create_linear(x1, y1, x2, y2);
|
pattern_ = cairo_pattern_create_linear(x1, y1, x2, y2);
|
||||||
}
|
}
|
||||||
else
|
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();
|
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;
|
mapnik::color const& stop_color = st.second;
|
||||||
double r= static_cast<double> (stop_color.red())/255.0;
|
double r = static_cast<double>(stop_color.red()) / 255.0;
|
||||||
double g= static_cast<double> (stop_color.green())/255.0;
|
double g = static_cast<double>(stop_color.green()) / 255.0;
|
||||||
double b= static_cast<double> (stop_color.blue())/255.0;
|
double b = static_cast<double>(stop_color.blue()) / 255.0;
|
||||||
double a= static_cast<double> (stop_color.alpha())/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);
|
cairo_pattern_add_color_stop_rgba(pattern_, st.first, r, g, b, a * opacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
double m[6];
|
double m[6];
|
||||||
|
@ -265,7 +254,7 @@ public:
|
||||||
tr.invert();
|
tr.invert();
|
||||||
tr.store_to(m);
|
tr.store_to(m);
|
||||||
cairo_matrix_t matrix;
|
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);
|
cairo_pattern_set_matrix(pattern_, &matrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,43 +264,32 @@ public:
|
||||||
cairo_pattern_destroy(pattern_);
|
cairo_pattern_destroy(pattern_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cairo_pattern_t* gradient() const { return pattern_; }
|
||||||
|
|
||||||
cairo_pattern_t * gradient() const
|
gradient_unit_e units() const { return units_; }
|
||||||
{
|
|
||||||
return pattern_;
|
|
||||||
}
|
|
||||||
|
|
||||||
gradient_unit_e units() const
|
private:
|
||||||
{
|
cairo_pattern_t* pattern_;
|
||||||
return units_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
cairo_pattern_t * pattern_;
|
|
||||||
gradient_unit_e units_;
|
gradient_unit_e units_;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class cairo_context : private util::noncopyable
|
class cairo_context : private util::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
cairo_context(cairo_ptr const& cairo);
|
cairo_context(cairo_ptr const& cairo);
|
||||||
|
|
||||||
inline ErrorStatus get_status() const
|
inline ErrorStatus get_status() const { return cairo_status(cairo_.get()); }
|
||||||
{
|
|
||||||
return cairo_status(cairo_.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
void clip();
|
void clip();
|
||||||
void show_page();
|
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_color(double r, double g, double b, double opacity = 1.0);
|
||||||
void set_operator(composite_mode_e comp_op);
|
void set_operator(composite_mode_e comp_op);
|
||||||
void set_line_join(line_join_e join);
|
void set_line_join(line_join_e join);
|
||||||
void set_line_cap(line_cap_e cap);
|
void set_line_cap(line_cap_e cap);
|
||||||
void set_miter_limit(double limit);
|
void set_miter_limit(double limit);
|
||||||
void set_line_width(double width);
|
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 set_fill_rule(cairo_fill_rule_t fill_rule);
|
||||||
void move_to(double x, double y);
|
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);
|
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 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(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 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_font_matrix(cairo_matrix_t const& matrix);
|
||||||
void set_matrix(cairo_matrix_t const& matrix);
|
void set_matrix(cairo_matrix_t const& matrix);
|
||||||
void transform(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 show_glyph(unsigned long index, pixel_position const& pos);
|
||||||
void glyph_path(unsigned long index, pixel_position const& pos);
|
void glyph_path(unsigned long index, pixel_position const& pos);
|
||||||
void add_text(glyph_positions 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 comp_op = src_over,
|
||||||
composite_mode_e halo_comp_op = src_over,
|
composite_mode_e halo_comp_op = src_over,
|
||||||
double scale_factor = 1.0);
|
double scale_factor = 1.0);
|
||||||
|
@ -344,7 +322,7 @@ public:
|
||||||
void push_group();
|
void push_group();
|
||||||
void pop_group();
|
void pop_group();
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
void add_path(T& path, unsigned start_index = 0)
|
void add_path(T& path, unsigned start_index = 0)
|
||||||
{
|
{
|
||||||
double x, y;
|
double x, y;
|
||||||
|
@ -366,11 +344,11 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
void add_agg_path(T& path, unsigned start_index = 0)
|
void add_agg_path(T& path, unsigned start_index = 0)
|
||||||
{
|
{
|
||||||
double x=0;
|
double x = 0;
|
||||||
double y=0;
|
double y = 0;
|
||||||
|
|
||||||
path.rewind(start_index);
|
path.rewind(start_index);
|
||||||
|
|
||||||
|
@ -384,26 +362,26 @@ public:
|
||||||
{
|
{
|
||||||
if (agg::is_curve3(cm))
|
if (agg::is_curve3(cm))
|
||||||
{
|
{
|
||||||
double end_x=0;
|
double end_x = 0;
|
||||||
double end_y=0;
|
double end_y = 0;
|
||||||
|
|
||||||
MAPNIK_LOG_WARN(cairo_renderer) << "Curve 3 not implemented";
|
MAPNIK_LOG_WARN(cairo_renderer) << "Curve 3 not implemented";
|
||||||
|
|
||||||
path.vertex(&end_x, &end_y);
|
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))
|
else if (agg::is_curve4(cm))
|
||||||
{
|
{
|
||||||
double ct2_x=0;
|
double ct2_x = 0;
|
||||||
double ct2_y=0;
|
double ct2_y = 0;
|
||||||
double end_x=0;
|
double end_x = 0;
|
||||||
double end_y=0;
|
double end_y = 0;
|
||||||
|
|
||||||
path.vertex(&ct2_x, &ct2_y);
|
path.vertex(&ct2_x, &ct2_y);
|
||||||
path.vertex(&end_x, &end_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))
|
else if (agg::is_line_to(cm))
|
||||||
{
|
{
|
||||||
|
@ -426,21 +404,22 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
cairo_ptr cairo_;
|
cairo_ptr cairo_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context>
|
template<typename Context>
|
||||||
struct line_pattern_rasterizer
|
struct line_pattern_rasterizer
|
||||||
{
|
{
|
||||||
line_pattern_rasterizer(Context & context, cairo_pattern & pattern, unsigned width, unsigned height)
|
line_pattern_rasterizer(Context& context, cairo_pattern& pattern, unsigned width, unsigned height)
|
||||||
: context_(context),
|
: context_(context)
|
||||||
pattern_(pattern),
|
, pattern_(pattern)
|
||||||
width_(width),
|
, width_(width)
|
||||||
height_(height) {}
|
, height_(height)
|
||||||
|
{}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
void add_path(T & path, unsigned start_index = 0)
|
void add_path(T& path, unsigned start_index = 0)
|
||||||
{
|
{
|
||||||
double length = 0.0;
|
double length = 0.0;
|
||||||
double x0 = 0.0;
|
double x0 = 0.0;
|
||||||
|
@ -479,13 +458,12 @@ struct line_pattern_rasterizer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Context & context_;
|
Context& context_;
|
||||||
cairo_pattern & pattern_;
|
cairo_pattern& pattern_;
|
||||||
unsigned width_;
|
unsigned width_;
|
||||||
unsigned height_;
|
unsigned height_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
|
|
||||||
#endif // MAPNIK_CAIRO_CONTEXT_HPP
|
#endif // MAPNIK_CAIRO_CONTEXT_HPP
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
*
|
*
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#ifndef MAPNIK_CAIRO_IMAGE_UTIL_HPP
|
#ifndef MAPNIK_CAIRO_IMAGE_UTIL_HPP
|
||||||
#define MAPNIK_CAIRO_IMAGE_UTIL_HPP
|
#define MAPNIK_CAIRO_IMAGE_UTIL_HPP
|
||||||
|
|
||||||
|
@ -33,8 +32,7 @@
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
static inline void cairo_image_to_rgba8(mapnik::image_rgba8 & data,
|
static inline void cairo_image_to_rgba8(mapnik::image_rgba8& data, cairo_surface_ptr const& surface)
|
||||||
cairo_surface_ptr const& surface)
|
|
||||||
{
|
{
|
||||||
if (cairo_image_surface_get_format(&*surface) != CAIRO_FORMAT_ARGB32)
|
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;
|
int stride = cairo_image_surface_get_stride(&*surface) / 4;
|
||||||
|
|
||||||
const std::unique_ptr<unsigned int[]> out_row(new unsigned int[data.width()]);
|
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)
|
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 g = (in >> 8) & 0xff;
|
||||||
unsigned int b = (in >> 0) & 0xff;
|
unsigned int b = (in >> 0) & 0xff;
|
||||||
|
|
||||||
#define DE_ALPHA(x) do { \
|
#define DE_ALPHA(x) \
|
||||||
if (a == 0) x = 0; \
|
do \
|
||||||
else x = x * 255 / a; \
|
{ \
|
||||||
if (x > 255) x = 255; \
|
if (a == 0) \
|
||||||
} while(0)
|
x = 0; \
|
||||||
|
else \
|
||||||
|
x = x * 255 / a; \
|
||||||
|
if (x > 255) \
|
||||||
|
x = 255; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
DE_ALPHA(r);
|
DE_ALPHA(r);
|
||||||
DE_ALPHA(g);
|
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
|
#endif // MAPNIK_CAIRO_IMAGE_UTIL_HPP
|
||||||
|
|
|
@ -32,12 +32,14 @@ namespace mapnik {
|
||||||
|
|
||||||
class cairo_context;
|
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,
|
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);
|
double opacity);
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_CAIRO_RENDER_VECTOR_HPP
|
#endif // MAPNIK_CAIRO_RENDER_VECTOR_HPP
|
||||||
|
|
||||||
|
|
|
@ -53,42 +53,35 @@ class request;
|
||||||
struct pixel_position;
|
struct pixel_position;
|
||||||
struct cairo_save_restore
|
struct cairo_save_restore
|
||||||
{
|
{
|
||||||
cairo_save_restore(cairo_context & context)
|
cairo_save_restore(cairo_context& context)
|
||||||
: context_(context)
|
: context_(context)
|
||||||
{
|
{
|
||||||
context_.save();
|
context_.save();
|
||||||
}
|
}
|
||||||
~cairo_save_restore()
|
~cairo_save_restore() { context_.restore(); }
|
||||||
{
|
cairo_context& context_;
|
||||||
context_.restore();
|
|
||||||
}
|
|
||||||
cairo_context & context_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
class MAPNIK_DECL cairo_renderer : public feature_style_processor<cairo_renderer<T> >,
|
class MAPNIK_DECL cairo_renderer : public feature_style_processor<cairo_renderer<T>>,
|
||||||
private util::noncopyable
|
private util::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using processor_impl_type = cairo_renderer<T>;
|
using processor_impl_type = cairo_renderer<T>;
|
||||||
cairo_renderer(Map const& m,
|
cairo_renderer(Map const& m, T const& obj, double scale_factor = 1.0, unsigned offset_x = 0, unsigned offset_y = 0);
|
||||||
T const& obj,
|
|
||||||
double scale_factor=1.0,
|
|
||||||
unsigned offset_x=0,
|
|
||||||
unsigned offset_y=0);
|
|
||||||
cairo_renderer(Map const& m,
|
cairo_renderer(Map const& m,
|
||||||
request const& req,
|
request const& req,
|
||||||
attributes const& vars,
|
attributes const& vars,
|
||||||
T const& obj,
|
T const& obj,
|
||||||
double scale_factor=1.0,
|
double scale_factor = 1.0,
|
||||||
unsigned offset_x=0,
|
unsigned offset_x = 0,
|
||||||
unsigned offset_y=0);
|
unsigned offset_y = 0);
|
||||||
cairo_renderer(Map const& m,
|
cairo_renderer(Map const& m,
|
||||||
T const& obj,
|
T const& obj,
|
||||||
std::shared_ptr<label_collision_detector4> detector,
|
std::shared_ptr<label_collision_detector4> detector,
|
||||||
double scale_factor=1.0,
|
double scale_factor = 1.0,
|
||||||
unsigned offset_x=0,
|
unsigned offset_x = 0,
|
||||||
unsigned offset_y=0);
|
unsigned offset_y = 0);
|
||||||
|
|
||||||
~cairo_renderer();
|
~cairo_renderer();
|
||||||
void start_map_processing(Map const& map);
|
void start_map_processing(Map const& map);
|
||||||
|
@ -97,93 +90,56 @@ public:
|
||||||
void end_layer_processing(layer const& lay);
|
void end_layer_processing(layer const& lay);
|
||||||
void start_style_processing(feature_type_style const& st);
|
void start_style_processing(feature_type_style const& st);
|
||||||
void end_style_processing(feature_type_style const& st);
|
void end_style_processing(feature_type_style const& st);
|
||||||
void process(point_symbolizer const& sym,
|
void process(point_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
mapnik::feature_impl & feature,
|
void process(line_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
proj_transform const& prj_trans);
|
void process(line_pattern_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
void process(line_symbolizer const& sym,
|
void process(polygon_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
mapnik::feature_impl & feature,
|
void process(polygon_pattern_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
proj_transform const& prj_trans);
|
void process(raster_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
void process(line_pattern_symbolizer const& sym,
|
void process(shield_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
mapnik::feature_impl & feature,
|
void process(text_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
proj_transform const& prj_trans);
|
void process(building_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
void process(polygon_symbolizer const& sym,
|
void process(markers_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
mapnik::feature_impl & feature,
|
void process(group_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
proj_transform const& prj_trans);
|
void process(debug_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
|
||||||
void process(polygon_pattern_symbolizer const& sym,
|
inline bool
|
||||||
mapnik::feature_impl & feature,
|
process(rule::symbolizers const& /*syms*/, mapnik::feature_impl& /*feature*/, proj_transform const& /*prj_trans*/)
|
||||||
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.
|
// cairo renderer doesn't support processing of multiple symbolizers.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool painted()
|
bool painted() { return true; }
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void painted(bool /*painted*/)
|
void painted(bool /*painted*/)
|
||||||
{
|
{
|
||||||
// nothing to do
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
inline eAttributeCollectionPolicy attribute_collection_policy() const
|
inline eAttributeCollectionPolicy attribute_collection_policy() const { return DEFAULT; }
|
||||||
{
|
|
||||||
return DEFAULT;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline double scale_factor() const
|
inline double scale_factor() const { return common_.scale_factor_; }
|
||||||
{
|
|
||||||
return common_.scale_factor_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline attributes const& variables() const
|
inline attributes const& variables() const { return common_.vars_; }
|
||||||
{
|
|
||||||
return common_.vars_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void render_marker(pixel_position const& pos,
|
void render_marker(pixel_position const& pos,
|
||||||
marker const& marker,
|
marker const& marker,
|
||||||
agg::trans_affine const& mtx,
|
agg::trans_affine const& mtx,
|
||||||
double opacity=1.0,
|
double opacity = 1.0,
|
||||||
bool recenter=true);
|
bool recenter = true);
|
||||||
protected:
|
|
||||||
|
protected:
|
||||||
Map const& m_;
|
Map const& m_;
|
||||||
cairo_context context_;
|
cairo_context context_;
|
||||||
renderer_common common_;
|
renderer_common common_;
|
||||||
cairo_face_manager face_manager_;
|
cairo_face_manager face_manager_;
|
||||||
bool style_level_compositing_;
|
bool style_level_compositing_;
|
||||||
void setup(Map const& m);
|
void setup(Map const& m);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern template class MAPNIK_DECL cairo_renderer<cairo_ptr>;
|
extern template class MAPNIK_DECL cairo_renderer<cairo_ptr>;
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_CAIRO_RENDERER_HPP
|
#endif // MAPNIK_CAIRO_RENDERER_HPP
|
||||||
|
|
||||||
|
|
|
@ -36,36 +36,31 @@ namespace mapnik {
|
||||||
|
|
||||||
struct cairo_renderer_process_visitor_p
|
struct cairo_renderer_process_visitor_p
|
||||||
{
|
{
|
||||||
cairo_renderer_process_visitor_p(agg::trans_affine const& image_tr,
|
cairo_renderer_process_visitor_p(agg::trans_affine const& image_tr, double opacity)
|
||||||
double opacity)
|
: image_tr_(image_tr)
|
||||||
: image_tr_(image_tr),
|
, opacity_(opacity)
|
||||||
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());
|
box2d<double> bbox(marker.bounding_box());
|
||||||
agg::trans_affine tr(transform(bbox));
|
agg::trans_affine tr(transform(bbox));
|
||||||
|
|
||||||
double width = std::max(1.0, std::round(bbox.width()));
|
double width = std::max(1.0, std::round(bbox.width()));
|
||||||
double height = std::max(1.0, std::round(bbox.height()));
|
double height = std::max(1.0, std::round(bbox.height()));
|
||||||
cairo_rectangle_t extent { 0, 0, width, height };
|
cairo_rectangle_t extent{0, 0, width, height};
|
||||||
cairo_surface_ptr surface(
|
cairo_surface_ptr surface(cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, &extent),
|
||||||
cairo_recording_surface_create(
|
cairo_surface_closer());
|
||||||
CAIRO_CONTENT_COLOR_ALPHA, &extent),
|
|
||||||
cairo_surface_closer());
|
|
||||||
|
|
||||||
cairo_ptr cairo = create_context(surface);
|
cairo_ptr cairo = create_context(surface);
|
||||||
cairo_context context(cairo);
|
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_attribute_type const& svg_attributes = svg.attributes();
|
||||||
svg::vertex_stl_adapter<svg::svg_path_storage> stl_storage(
|
svg::vertex_stl_adapter<svg::svg_path_storage> stl_storage(svg.source());
|
||||||
svg.source());
|
|
||||||
svg::svg_path_adapter svg_path(stl_storage);
|
svg::svg_path_adapter svg_path(stl_storage);
|
||||||
|
|
||||||
render_vector_marker(context, svg_path, svg_attributes,
|
render_vector_marker(context, svg_path, svg_attributes, bbox, tr, opacity_);
|
||||||
bbox, tr, opacity_);
|
|
||||||
|
|
||||||
return surface;
|
return surface;
|
||||||
}
|
}
|
||||||
|
@ -75,11 +70,9 @@ struct cairo_renderer_process_visitor_p
|
||||||
box2d<double> bbox(marker.bounding_box());
|
box2d<double> bbox(marker.bounding_box());
|
||||||
agg::trans_affine tr(transform(bbox));
|
agg::trans_affine tr(transform(bbox));
|
||||||
|
|
||||||
cairo_rectangle_t extent { 0, 0, bbox.width(), bbox.height() };
|
cairo_rectangle_t extent{0, 0, bbox.width(), bbox.height()};
|
||||||
cairo_surface_ptr surface(
|
cairo_surface_ptr surface(cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, &extent),
|
||||||
cairo_recording_surface_create(
|
cairo_surface_closer());
|
||||||
CAIRO_CONTENT_COLOR_ALPHA, &extent),
|
|
||||||
cairo_surface_closer());
|
|
||||||
|
|
||||||
cairo_ptr cairo = create_context(surface);
|
cairo_ptr cairo = create_context(surface);
|
||||||
cairo_context context(cairo);
|
cairo_context context(cairo);
|
||||||
|
@ -89,25 +82,21 @@ struct cairo_renderer_process_visitor_p
|
||||||
return surface;
|
return surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
cairo_surface_ptr operator() (marker_null const&) const
|
cairo_surface_ptr operator()(marker_null const&) const
|
||||||
{
|
{
|
||||||
cairo_surface_ptr surface(
|
cairo_surface_ptr surface(cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, nullptr),
|
||||||
cairo_recording_surface_create(
|
cairo_surface_closer());
|
||||||
CAIRO_CONTENT_COLOR_ALPHA, nullptr),
|
|
||||||
cairo_surface_closer());
|
|
||||||
cairo_ptr cairo = create_context(surface);
|
cairo_ptr cairo = create_context(surface);
|
||||||
cairo_context context(cairo);
|
cairo_context context(cairo);
|
||||||
return surface;
|
return surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
agg::trans_affine transform(box2d<double> & bbox) const
|
agg::trans_affine transform(box2d<double>& bbox) const
|
||||||
{
|
{
|
||||||
bbox *= image_tr_;
|
bbox *= image_tr_;
|
||||||
coord<double, 2> c = bbox.center();
|
coord<double, 2> c = bbox.center();
|
||||||
agg::trans_affine mtx = agg::trans_affine_translation(
|
agg::trans_affine mtx = agg::trans_affine_translation(0.5 * bbox.width() - c.x, 0.5 * bbox.height() - c.y);
|
||||||
0.5 * bbox.width() - c.x,
|
|
||||||
0.5 * bbox.height() - c.y);
|
|
||||||
return image_tr_ * mtx;
|
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
|
struct cairo_polygon_pattern : cairo_pattern_base
|
||||||
{
|
{
|
||||||
cairo_polygon_pattern(mapnik::marker const& marker,
|
cairo_polygon_pattern(mapnik::marker const& marker,
|
||||||
|
@ -143,22 +132,23 @@ struct cairo_polygon_pattern : cairo_pattern_base
|
||||||
symbolizer_base const& sym,
|
symbolizer_base const& sym,
|
||||||
mapnik::feature_impl const& feature,
|
mapnik::feature_impl const& feature,
|
||||||
proj_transform const& prj_trans)
|
proj_transform const& prj_trans)
|
||||||
: cairo_pattern_base{marker, common, sym, feature, prj_trans},
|
: cairo_pattern_base{marker, common, sym, feature, prj_trans}
|
||||||
clip_(get<value_bool, keys::clip>(sym_, feature_, common_.vars_)),
|
, clip_(get<value_bool, keys::clip>(sym_, feature_, common_.vars_))
|
||||||
clip_box_(clipping_extent(common)),
|
, clip_box_(clipping_extent(common))
|
||||||
tr_(geom_transform()),
|
, tr_(geom_transform())
|
||||||
converter_(clip_box_, sym, common.t_, prj_trans, tr_,
|
, converter_(clip_box_, sym, common.t_, prj_trans, tr_, feature, common.vars_, common.scale_factor_)
|
||||||
feature, common.vars_, common.scale_factor_)
|
|
||||||
{
|
{
|
||||||
value_double simplify_tolerance = get<value_double, keys::simplify_tolerance>(sym, feature, common_.vars_);
|
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_);
|
value_double smooth = get<value_double, keys::smooth>(sym, feature, common_.vars_);
|
||||||
|
|
||||||
converter_.template set<affine_transform_tag>();
|
converter_.template set<affine_transform_tag>();
|
||||||
if (simplify_tolerance > 0.0) converter_.template set<simplify_tag>();
|
if (simplify_tolerance > 0.0)
|
||||||
if (smooth > 0.0) converter_.template set<smooth_tag>();
|
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_);
|
value_double opacity = get<value_double, keys::opacity>(sym_, feature_, common_.vars_);
|
||||||
agg::trans_affine image_tr = agg::trans_affine_scaling(common_.scale_factor_);
|
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;
|
cairo_rectangle_t pattern_surface_extent;
|
||||||
if (cairo_recording_surface_get_extents(surface.get(), &pattern_surface_extent))
|
if (cairo_recording_surface_get_extents(surface.get(), &pattern_surface_extent))
|
||||||
{
|
{
|
||||||
offset = pattern_offset(sym_, feature_, prj_trans_, common_,
|
offset = pattern_offset(sym_,
|
||||||
pattern_surface_extent.width, pattern_surface_extent.height);
|
feature_,
|
||||||
|
prj_trans_,
|
||||||
|
common_,
|
||||||
|
pattern_surface_extent.width,
|
||||||
|
pattern_surface_extent.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
cairo_pattern pattern(surface);
|
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 apply_vertex_converter_type = detail::apply_vertex_converter<VertexConverter, cairo_context>;
|
||||||
using vertex_processor_type = geometry::vertex_processor<apply_vertex_converter_type>;
|
using vertex_processor_type = geometry::vertex_processor<apply_vertex_converter_type>;
|
||||||
apply_vertex_converter_type apply(converter_, context);
|
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
|
// fill polygon
|
||||||
context.set_fill_rule(fill_rule);
|
context.set_fill_rule(fill_rule);
|
||||||
context.fill();
|
context.fill();
|
||||||
|
@ -207,5 +201,4 @@ struct cairo_polygon_pattern : cairo_pattern_base
|
||||||
|
|
||||||
} // namespace mapnik
|
} // namespace mapnik
|
||||||
|
|
||||||
|
|
||||||
#endif // MAPNIK_CAIRO_RENDER_POLYGON_PATTERN_HPP
|
#endif // MAPNIK_CAIRO_RENDER_POLYGON_PATTERN_HPP
|
||||||
|
|
|
@ -35,15 +35,15 @@ namespace mapnik {
|
||||||
#if defined(HAVE_CAIRO)
|
#if defined(HAVE_CAIRO)
|
||||||
MAPNIK_DECL void save_to_cairo_file(mapnik::Map const& map,
|
MAPNIK_DECL void save_to_cairo_file(mapnik::Map const& map,
|
||||||
std::string const& filename,
|
std::string const& filename,
|
||||||
double scale_factor=1.0,
|
double scale_factor = 1.0,
|
||||||
double scale_denominator=0.0);
|
double scale_denominator = 0.0);
|
||||||
MAPNIK_DECL void save_to_cairo_file(mapnik::Map const& map,
|
MAPNIK_DECL void save_to_cairo_file(mapnik::Map const& map,
|
||||||
std::string const& filename,
|
std::string const& filename,
|
||||||
std::string const& type,
|
std::string const& type,
|
||||||
double scale_factor=1.0,
|
double scale_factor = 1.0,
|
||||||
double scale_denominator=0.0);
|
double scale_denominator = 0.0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // end ns
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_CAIRO_IO_HPP
|
#endif // MAPNIK_CAIRO_IO_HPP
|
||||||
|
|
|
@ -41,7 +41,7 @@ namespace mapnik {
|
||||||
|
|
||||||
class MAPNIK_DECL color : boost::equality_comparable<color>
|
class MAPNIK_DECL color : boost::equality_comparable<color>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::uint8_t red_;
|
std::uint8_t red_;
|
||||||
std::uint8_t green_;
|
std::uint8_t green_;
|
||||||
std::uint8_t blue_;
|
std::uint8_t blue_;
|
||||||
|
@ -50,46 +50,52 @@ public:
|
||||||
|
|
||||||
// default ctor
|
// default ctor
|
||||||
color()
|
color()
|
||||||
: red_(0xff),
|
: red_(0xff)
|
||||||
green_(0xff),
|
, green_(0xff)
|
||||||
blue_(0xff),
|
, blue_(0xff)
|
||||||
alpha_(0xff),
|
, alpha_(0xff)
|
||||||
premultiplied_(false)
|
, premultiplied_(false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
color(std::uint8_t _red, std::uint8_t _green, std::uint8_t _blue, std::uint8_t _alpha = 0xff, bool premultiplied = false)
|
color(std::uint8_t _red,
|
||||||
: red_(_red),
|
std::uint8_t _green,
|
||||||
green_(_green),
|
std::uint8_t _blue,
|
||||||
blue_(_blue),
|
std::uint8_t _alpha = 0xff,
|
||||||
alpha_(_alpha),
|
bool premultiplied = false)
|
||||||
premultiplied_(premultiplied)
|
: red_(_red)
|
||||||
{}
|
, green_(_green)
|
||||||
|
, blue_(_blue)
|
||||||
|
, alpha_(_alpha)
|
||||||
|
, premultiplied_(premultiplied)
|
||||||
|
{}
|
||||||
|
|
||||||
color(std::uint32_t _rgba, bool premultiplied = false)
|
color(std::uint32_t _rgba, bool premultiplied = false)
|
||||||
: red_(_rgba & 0xff),
|
: red_(_rgba & 0xff)
|
||||||
green_((_rgba >> 8) & 0xff),
|
, green_((_rgba >> 8) & 0xff)
|
||||||
blue_((_rgba >> 16) & 0xff),
|
, blue_((_rgba >> 16) & 0xff)
|
||||||
alpha_((_rgba >> 24) & 0xff),
|
, alpha_((_rgba >> 24) & 0xff)
|
||||||
premultiplied_(premultiplied) {}
|
, premultiplied_(premultiplied)
|
||||||
|
{}
|
||||||
|
|
||||||
// copy ctor
|
// copy ctor
|
||||||
color(const color& rhs)
|
color(const color& rhs)
|
||||||
: red_(rhs.red_),
|
: red_(rhs.red_)
|
||||||
green_(rhs.green_),
|
, green_(rhs.green_)
|
||||||
blue_(rhs.blue_),
|
, blue_(rhs.blue_)
|
||||||
alpha_(rhs.alpha_),
|
, alpha_(rhs.alpha_)
|
||||||
premultiplied_(rhs.premultiplied_)
|
, premultiplied_(rhs.premultiplied_)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
// move ctor
|
// move ctor
|
||||||
color(color && rhs)
|
color(color&& rhs)
|
||||||
: red_(std::move(rhs.red_)),
|
: red_(std::move(rhs.red_))
|
||||||
green_(std::move(rhs.green_)),
|
, green_(std::move(rhs.green_))
|
||||||
blue_(std::move(rhs.blue_)),
|
, blue_(std::move(rhs.blue_))
|
||||||
alpha_(std::move(rhs.alpha_)),
|
, alpha_(std::move(rhs.alpha_))
|
||||||
premultiplied_(std::move(rhs.premultiplied_)) {}
|
, 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_string() const;
|
||||||
std::string to_hex_string() const;
|
std::string to_hex_string() const;
|
||||||
|
@ -104,78 +110,45 @@ public:
|
||||||
|
|
||||||
inline bool operator==(color const& rhs) const
|
inline bool operator==(color const& rhs) const
|
||||||
{
|
{
|
||||||
return (red_== rhs.red_) &&
|
return (red_ == rhs.red_) && (green_ == rhs.green_) && (blue_ == rhs.blue_) && (alpha_ == rhs.alpha_) &&
|
||||||
(green_ == rhs.green_) &&
|
(premultiplied_ == rhs.premultiplied_);
|
||||||
(blue_ == rhs.blue_) &&
|
|
||||||
(alpha_ == rhs.alpha_) &&
|
|
||||||
(premultiplied_ == rhs.premultiplied_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::uint8_t red() const
|
inline std::uint8_t red() const { return red_; }
|
||||||
{
|
|
||||||
return red_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::uint8_t green() const
|
inline std::uint8_t green() const { return green_; }
|
||||||
{
|
|
||||||
return green_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::uint8_t blue() const
|
inline std::uint8_t blue() const { return blue_; }
|
||||||
{
|
|
||||||
return blue_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::uint8_t alpha() const
|
inline std::uint8_t alpha() const { return alpha_; }
|
||||||
{
|
|
||||||
return alpha_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void set_red(std::uint8_t _red)
|
inline void set_red(std::uint8_t _red) { red_ = _red; }
|
||||||
{
|
|
||||||
red_ = _red;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void set_green(std::uint8_t _green)
|
inline void set_green(std::uint8_t _green) { green_ = _green; }
|
||||||
{
|
|
||||||
green_ = _green;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void set_blue(std::uint8_t _blue)
|
inline void set_blue(std::uint8_t _blue) { blue_ = _blue; }
|
||||||
{
|
inline void set_alpha(std::uint8_t _alpha) { alpha_ = _alpha; }
|
||||||
blue_ = _blue;
|
inline bool get_premultiplied() const { return premultiplied_; }
|
||||||
}
|
inline void set_premultiplied(bool val) { premultiplied_ = val; }
|
||||||
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
|
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(red_, rhs.red_);
|
||||||
std::swap(green_,rhs.green_);
|
std::swap(green_, rhs.green_);
|
||||||
std::swap(blue_,rhs.blue_);
|
std::swap(blue_, rhs.blue_);
|
||||||
std::swap(alpha_,rhs.alpha_);
|
std::swap(alpha_, rhs.alpha_);
|
||||||
std::swap(premultiplied_, rhs.premultiplied_);
|
std::swap(premultiplied_, rhs.premultiplied_);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename charT, typename traits>
|
template<typename charT, typename traits>
|
||||||
std::basic_ostream<charT, traits> &
|
std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& s, mapnik::color const& c)
|
||||||
operator << ( std::basic_ostream<charT, traits> & s, mapnik::color const& c )
|
|
||||||
{
|
{
|
||||||
s << c.to_string();
|
s << c.to_string();
|
||||||
return s;
|
return s;
|
||||||
|
@ -187,6 +160,6 @@ inline std::size_t hash_value(color const& c)
|
||||||
return c.rgba();
|
return c.rgba();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_COLOR_HPP
|
#endif // MAPNIK_COLOR_HPP
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
// mapnik
|
// mapnik
|
||||||
#include <mapnik/color.hpp>
|
#include <mapnik/color.hpp>
|
||||||
|
|
||||||
//stl
|
// stl
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
|
@ -26,28 +26,28 @@
|
||||||
// Windows DLL support
|
// Windows DLL support
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
# define MAPNIK_EXP __declspec (dllexport)
|
#define MAPNIK_EXP __declspec(dllexport)
|
||||||
# define MAPNIK_IMP __declspec (dllimport)
|
#define MAPNIK_IMP __declspec(dllimport)
|
||||||
# ifdef MAPNIK_EXPORTS
|
#ifdef MAPNIK_EXPORTS
|
||||||
# define MAPNIK_DECL __declspec (dllexport)
|
#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
|
|
||||||
#else
|
#else
|
||||||
# if __GNUC__ >= 4
|
#define MAPNIK_DECL __declspec(dllimport)
|
||||||
# define MAPNIK_EXP __attribute__ ((visibility ("default")))
|
#endif
|
||||||
# define MAPNIK_DECL __attribute__ ((visibility ("default")))
|
#pragma warning(disable: 4251)
|
||||||
# define MAPNIK_IMP __attribute__ ((visibility ("default")))
|
#pragma warning(disable: 4275)
|
||||||
# else
|
#if (_MSC_VER >= 1400) // vc8
|
||||||
# define MAPNIK_EXP
|
#pragma warning(disable: 4996) //_CRT_SECURE_NO_DEPRECATE
|
||||||
# define MAPNIK_DECL
|
#endif
|
||||||
# define MAPNIK_IMP
|
#else
|
||||||
# endif
|
#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
|
#endif
|
||||||
|
|
||||||
#define PROJ_ENVELOPE_POINTS 20
|
#define PROJ_ENVELOPE_POINTS 20
|
||||||
|
|
|
@ -34,19 +34,17 @@ class xml_node;
|
||||||
|
|
||||||
class config_error : public std::exception
|
class config_error : public std::exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
config_error(std::string const& what);
|
config_error(std::string const& what);
|
||||||
config_error(std::string const& what,
|
config_error(std::string const& what, xml_node const& node);
|
||||||
xml_node const& node);
|
config_error(std::string const& what, unsigned line_number, std::string const& filename);
|
||||||
config_error(std::string const& what,
|
|
||||||
unsigned line_number,
|
|
||||||
std::string const& filename);
|
|
||||||
virtual ~config_error() {}
|
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) const;
|
||||||
void append_context(std::string const& ctx, xml_node const& node) const;
|
void append_context(std::string const& ctx, xml_node const& node) const;
|
||||||
void append_context(xml_node const& node) const;
|
void append_context(xml_node const& node) const;
|
||||||
protected:
|
|
||||||
|
protected:
|
||||||
mutable std::string what_;
|
mutable std::string what_;
|
||||||
mutable unsigned line_number_;
|
mutable unsigned line_number_;
|
||||||
mutable std::string file_;
|
mutable std::string file_;
|
||||||
|
@ -54,6 +52,6 @@ protected:
|
||||||
mutable std::string msg_;
|
mutable std::string msg_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_CONFIG_ERROR_HPP
|
#endif // MAPNIK_CONFIG_ERROR_HPP
|
||||||
|
|
|
@ -30,150 +30,173 @@ MAPNIK_DISABLE_WARNING_PUSH
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
template <typename T,int dim>
|
template<typename T, int dim>
|
||||||
struct coord {
|
struct coord
|
||||||
|
{
|
||||||
using type = T;
|
using type = T;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
struct coord<T,2>
|
struct coord<T, 2>
|
||||||
: boost::addable<coord<T,2>,
|
: boost::addable<
|
||||||
boost::addable2<coord<T,2>,T,
|
coord<T, 2>,
|
||||||
boost::subtractable<coord<T,2>,
|
boost::addable2<
|
||||||
boost::subtractable2<coord<T,2>,T,
|
coord<T, 2>,
|
||||||
boost::dividable2<coord<T,2>, T,
|
T,
|
||||||
boost::multipliable2<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;
|
using type = T;
|
||||||
T x;
|
T x;
|
||||||
T y;
|
T y;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
coord()
|
coord()
|
||||||
: x(),y() {}
|
: x()
|
||||||
coord(T x_,T y_)
|
, y()
|
||||||
: x(x_),y(y_) {}
|
{}
|
||||||
|
coord(T x_, T y_)
|
||||||
|
: x(x_)
|
||||||
|
, y(y_)
|
||||||
|
{}
|
||||||
|
|
||||||
coord(coord<T,2> const& rhs)
|
coord(coord<T, 2> const& rhs)
|
||||||
: x(rhs.x),
|
: x(rhs.x)
|
||||||
y(rhs.y) {}
|
, y(rhs.y)
|
||||||
|
{}
|
||||||
|
|
||||||
template <typename T2>
|
template<typename T2>
|
||||||
coord (coord<T2,2> const& rhs)
|
coord(coord<T2, 2> const& rhs)
|
||||||
: x(type(rhs.x)),
|
: x(type(rhs.x))
|
||||||
y(type(rhs.y)) {}
|
, y(type(rhs.y))
|
||||||
|
{}
|
||||||
|
|
||||||
coord(coord<T,2> && rhs) noexcept
|
coord(coord<T, 2>&& rhs) noexcept
|
||||||
: x(std::move(rhs.x)),
|
: x(std::move(rhs.x))
|
||||||
y(std::move(rhs.y)) {}
|
, y(std::move(rhs.y))
|
||||||
|
{}
|
||||||
|
|
||||||
coord<T,2>& operator=(coord<T,2> rhs)
|
coord<T, 2>& operator=(coord<T, 2> rhs)
|
||||||
{
|
{
|
||||||
swap(rhs);
|
swap(rhs);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T2>
|
template<typename T2>
|
||||||
coord<T,2>& operator=(const coord<T2,2>& rhs)
|
coord<T, 2>& operator=(const coord<T2, 2>& rhs)
|
||||||
{
|
{
|
||||||
coord<T,2> tmp(rhs);
|
coord<T, 2> tmp(rhs);
|
||||||
swap(rhs);
|
swap(rhs);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T2>
|
template<typename T2>
|
||||||
bool operator==(coord<T2,2> const& rhs)
|
bool operator==(coord<T2, 2> const& rhs)
|
||||||
{
|
{
|
||||||
return x == rhs.x && y == rhs.y;
|
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;
|
x += rhs.x;
|
||||||
y+=rhs.y;
|
y += rhs.y;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
coord<T,2>& operator+=(T rhs)
|
coord<T, 2>& operator+=(T rhs)
|
||||||
{
|
{
|
||||||
x+=rhs;
|
x += rhs;
|
||||||
y+=rhs;
|
y += rhs;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
coord<T,2>& operator-=(coord<T,2> const& rhs)
|
coord<T, 2>& operator-=(coord<T, 2> const& rhs)
|
||||||
{
|
{
|
||||||
x-=rhs.x;
|
x -= rhs.x;
|
||||||
y-=rhs.y;
|
y -= rhs.y;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
coord<T,2>& operator-=(T rhs)
|
coord<T, 2>& operator-=(T rhs)
|
||||||
{
|
{
|
||||||
x-=rhs;
|
x -= rhs;
|
||||||
y-=rhs;
|
y -= rhs;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
coord<T,2>& operator*=(T t)
|
coord<T, 2>& operator*=(T t)
|
||||||
{
|
{
|
||||||
x*=t;
|
x *= t;
|
||||||
y*=t;
|
y *= t;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
coord<T,2>& operator/=(T t)
|
coord<T, 2>& operator/=(T t)
|
||||||
{
|
{
|
||||||
x/=t;
|
x /= t;
|
||||||
y/=t;
|
y /= t;
|
||||||
return *this;
|
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->x, rhs.x);
|
||||||
std::swap(this->y, rhs.y);
|
std::swap(this->y, rhs.y);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
struct coord<T,3>
|
struct coord<T, 3>
|
||||||
{
|
{
|
||||||
using type = T;
|
using type = T;
|
||||||
T x;
|
T x;
|
||||||
T y;
|
T y;
|
||||||
T z;
|
T z;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
coord()
|
coord()
|
||||||
: x(),y(),z() {}
|
: x()
|
||||||
coord(T x_,T y_,T z_)
|
, y()
|
||||||
: x(x_),y(y_),z(z_) {}
|
, z()
|
||||||
|
{}
|
||||||
|
coord(T x_, T y_, T z_)
|
||||||
|
: x(x_)
|
||||||
|
, y(y_)
|
||||||
|
, z(z_)
|
||||||
|
{}
|
||||||
|
|
||||||
template <typename T2>
|
template<typename T2>
|
||||||
coord (coord<T2,3> const& rhs)
|
coord(coord<T2, 3> const& rhs)
|
||||||
: x(type(rhs.x)),
|
: x(type(rhs.x))
|
||||||
y(type(rhs.y)),
|
, y(type(rhs.y))
|
||||||
z(type(rhs.z)) {}
|
, z(type(rhs.z))
|
||||||
|
{}
|
||||||
|
|
||||||
coord(coord<T,3> && rhs) noexcept
|
coord(coord<T, 3>&& rhs) noexcept
|
||||||
: x(std::move(rhs.x)),
|
: x(std::move(rhs.x))
|
||||||
y(std::move(rhs.y)),
|
, y(std::move(rhs.y))
|
||||||
z(std::move(rhs.z)) {}
|
, z(std::move(rhs.z))
|
||||||
|
{}
|
||||||
|
|
||||||
coord<T,3> operator=(coord<T,3> rhs)
|
coord<T, 3> operator=(coord<T, 3> rhs)
|
||||||
{
|
{
|
||||||
swap(rhs);
|
swap(rhs);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T2>
|
template<typename T2>
|
||||||
coord<T,3>& operator=(coord<T2,3> const& rhs)
|
coord<T, 3>& operator=(coord<T2, 3> const& rhs)
|
||||||
{
|
{
|
||||||
coord<T,3> tmp(rhs);
|
coord<T, 3> tmp(rhs);
|
||||||
swap(tmp);
|
swap(tmp);
|
||||||
return *this;
|
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->x, rhs.x);
|
||||||
std::swap(this->y, rhs.y);
|
std::swap(this->y, rhs.y);
|
||||||
|
@ -181,10 +204,10 @@ private:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
using coord2d = coord<double,2>;
|
using coord2d = coord<double, 2>;
|
||||||
using coord2f = coord<float,2>;
|
using coord2f = coord<float, 2>;
|
||||||
using coord2i = coord<int,2>;
|
using coord2i = coord<int, 2>;
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_COORD_HPP
|
#endif // MAPNIK_COORD_HPP
|
||||||
|
|
|
@ -31,13 +31,11 @@ MAPNIK_DISABLE_WARNING_PUSH
|
||||||
#include <boost/spirit/home/x3.hpp>
|
#include <boost/spirit/home/x3.hpp>
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
|
|
||||||
namespace x3 = boost::spirit::x3;
|
namespace x3 = boost::spirit::x3;
|
||||||
|
|
||||||
namespace css_color_grammar
|
namespace css_color_grammar {
|
||||||
{
|
|
||||||
|
|
||||||
struct css_color_class;
|
struct css_color_class;
|
||||||
using css_color_grammar_type = x3::rule<css_color_class, mapnik::color>;
|
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);
|
BOOST_SPIRIT_DECLARE(css_color_grammar_type);
|
||||||
|
|
||||||
}}
|
} // namespace css_color_grammar
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_CSS_COLOR_GRAMMAR_X3_HPP
|
#endif // MAPNIK_CSS_COLOR_GRAMMAR_X3_HPP
|
||||||
|
|
|
@ -37,13 +37,8 @@ MAPNIK_DISABLE_WARNING_PUSH
|
||||||
#include <boost/fusion/adapted/std_tuple.hpp>
|
#include <boost/fusion/adapted/std_tuple.hpp>
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
BOOST_FUSION_ADAPT_STRUCT (
|
BOOST_FUSION_ADAPT_STRUCT(mapnik::color,
|
||||||
mapnik::color,
|
(std::uint8_t, red_)(std::uint8_t, green_)(std::uint8_t, blue_)(std::uint8_t, alpha_))
|
||||||
(std::uint8_t, red_)
|
|
||||||
(std::uint8_t, green_)
|
|
||||||
(std::uint8_t, blue_)
|
|
||||||
(std::uint8_t, alpha_)
|
|
||||||
)
|
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
|
@ -51,20 +46,21 @@ namespace x3 = boost::spirit::x3;
|
||||||
|
|
||||||
namespace css_color_grammar {
|
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::attr;
|
||||||
using x3::double_;
|
using x3::double_;
|
||||||
|
using x3::hex;
|
||||||
|
using x3::lit;
|
||||||
using x3::no_case;
|
using x3::no_case;
|
||||||
using x3::no_skip;
|
using x3::no_skip;
|
||||||
|
using x3::omit;
|
||||||
|
using x3::symbols;
|
||||||
|
using x3::uint_parser;
|
||||||
|
|
||||||
struct named_colors_ : x3::symbols<color>
|
struct named_colors_ : x3::symbols<color>
|
||||||
{
|
{
|
||||||
named_colors_()
|
named_colors_()
|
||||||
{
|
{
|
||||||
|
// clang-format off
|
||||||
add
|
add
|
||||||
("aliceblue", color(240, 248, 255))
|
("aliceblue", color(240, 248, 255))
|
||||||
("antiquewhite", color(250, 235, 215))
|
("antiquewhite", color(250, 235, 215))
|
||||||
|
@ -216,6 +212,7 @@ struct named_colors_ : x3::symbols<color>
|
||||||
("yellowgreen", color(154, 205, 50))
|
("yellowgreen", color(154, 205, 50))
|
||||||
("transparent", color(0, 0, 0, 0))
|
("transparent", color(0, 0, 0, 0))
|
||||||
;
|
;
|
||||||
|
// clang-format on
|
||||||
}
|
}
|
||||||
} named_colors;
|
} named_colors;
|
||||||
|
|
||||||
|
@ -226,7 +223,7 @@ x3::uint_parser<std::uint16_t, 10, 1, 3> dec3;
|
||||||
// rules
|
// rules
|
||||||
x3::rule<class hex2_color, color> const hex2_color("hex2_color");
|
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 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 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 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");
|
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)
|
static double call(double val)
|
||||||
{
|
{
|
||||||
if (val > 1.0) return 1.0;
|
if (val > 1.0)
|
||||||
if (val < 0.0) return 0.0;
|
return 1.0;
|
||||||
|
if (val < 0.0)
|
||||||
|
return 0.0;
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct percent_converter
|
struct percent_converter
|
||||||
{
|
{
|
||||||
static std::uint8_t call(double val)
|
static std::uint8_t call(double val) { return safe_cast<std::uint8_t>(std::lround((255.0 * val) / 100.0)); }
|
||||||
{
|
|
||||||
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);
|
_val(ctx).red_ = _attr(ctx);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto dec_green = [](auto& ctx)
|
auto dec_green = [](auto& ctx) {
|
||||||
{
|
|
||||||
_val(ctx).green_ = _attr(ctx);
|
_val(ctx).green_ = _attr(ctx);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto dec_blue = [](auto& ctx)
|
auto dec_blue = [](auto& ctx) {
|
||||||
{
|
|
||||||
_val(ctx).blue_ = _attr(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);
|
_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));
|
_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));
|
_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));
|
_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;
|
_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;
|
_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;
|
_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;
|
_val(ctx).alpha_ = _attr(ctx) | _attr(ctx) << 4;
|
||||||
};
|
};
|
||||||
|
|
||||||
auto hex2_red = [](auto& ctx)
|
auto hex2_red = [](auto& ctx) {
|
||||||
{
|
|
||||||
_val(ctx).red_ = _attr(ctx);
|
_val(ctx).red_ = _attr(ctx);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto hex2_green = [](auto& ctx)
|
auto hex2_green = [](auto& ctx) {
|
||||||
{
|
|
||||||
_val(ctx).green_ = _attr(ctx);
|
_val(ctx).green_ = _attr(ctx);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto hex2_blue = [](auto& ctx)
|
auto hex2_blue = [](auto& ctx) {
|
||||||
{
|
|
||||||
_val(ctx).blue_ = _attr(ctx);
|
_val(ctx).blue_ = _attr(ctx);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto hex2_opacity = [](auto& ctx)
|
auto hex2_opacity = [](auto& ctx) {
|
||||||
{
|
|
||||||
_val(ctx).alpha_ = _attr(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 h = std::get<0>(_attr(ctx));
|
||||||
double s = std::get<1>(_attr(ctx));
|
double s = std::get<1>(_attr(ctx));
|
||||||
double l = std::get<2>(_attr(ctx));
|
double l = std::get<2>(_attr(ctx));
|
||||||
|
@ -341,20 +321,20 @@ auto hsl_to_rgba = [] (auto& ctx)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m2 = l + s - l*s;
|
m2 = l + s - l * s;
|
||||||
}
|
}
|
||||||
m1 = l * 2 - m2;
|
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 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);
|
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)),
|
_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 * g)),
|
||||||
safe_cast<uint8_t>(std::lround(255.0 * b)),
|
safe_cast<uint8_t>(std::lround(255.0 * b)),
|
||||||
alpha);
|
alpha);
|
||||||
};
|
};
|
||||||
|
// clang-format off
|
||||||
auto const hex2_color_def = no_skip[lit('#')
|
auto const hex2_color_def = no_skip[lit('#')
|
||||||
>> hex2[hex2_red]
|
>> hex2[hex2_red]
|
||||||
>> hex2[hex2_green]
|
>> hex2[hex2_green]
|
||||||
|
@ -429,21 +409,13 @@ auto const css_color_def =
|
||||||
|
|
|
|
||||||
hsla_color
|
hsla_color
|
||||||
;
|
;
|
||||||
|
// clang-format on
|
||||||
MAPNIK_DISABLE_WARNING_PUSH
|
MAPNIK_DISABLE_WARNING_PUSH
|
||||||
#include <mapnik/warning_ignore.hpp>
|
#include <mapnik/warning_ignore.hpp>
|
||||||
BOOST_SPIRIT_DEFINE(
|
BOOST_SPIRIT_DEFINE(css_color, hex2_color, hex1_color, rgb_color, rgba_color, rgb_color_percent, rgba_color_percent);
|
||||||
css_color,
|
|
||||||
hex2_color,
|
|
||||||
hex1_color,
|
|
||||||
rgb_color,
|
|
||||||
rgba_color,
|
|
||||||
rgb_color_percent,
|
|
||||||
rgba_color_percent
|
|
||||||
);
|
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
} // ns
|
} // namespace css_color_grammar
|
||||||
} //ns mapnik
|
} // 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)
|
* This file is part of Mapnik (c++ mapping toolkit)
|
||||||
*
|
*
|
||||||
|
@ -31,8 +31,7 @@ MAPNIK_DISABLE_WARNING_PUSH
|
||||||
#include <boost/spirit/home/x3.hpp>
|
#include <boost/spirit/home/x3.hpp>
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
using property_value_type = boost::iterator_range<char const*>;
|
using property_value_type = boost::iterator_range<char const*>;
|
||||||
using css_key_value = std::pair<std::string, property_value_type>;
|
using css_key_value = std::pair<std::string, property_value_type>;
|
||||||
using definition_type = std::vector<css_key_value>;
|
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 x3 = boost::spirit::x3;
|
||||||
|
|
||||||
namespace css_grammar
|
namespace css_grammar {
|
||||||
{
|
|
||||||
|
|
||||||
class css_tag;
|
class css_tag;
|
||||||
class ident_tag;
|
class ident_tag;
|
||||||
|
@ -58,17 +56,14 @@ css_grammar_type const css_grammar{"css"};
|
||||||
css_skipper_type const css_skipper{"css skipper"};
|
css_skipper_type const css_skipper{"css skipper"};
|
||||||
css_classes_type const css_classes{"css classes"};
|
css_classes_type const css_classes{"css classes"};
|
||||||
|
|
||||||
BOOST_SPIRIT_DECLARE(ident_grammar_type,
|
BOOST_SPIRIT_DECLARE(ident_grammar_type, css_classes_type, css_grammar_type, css_skipper_type);
|
||||||
css_classes_type,
|
|
||||||
css_grammar_type,
|
|
||||||
css_skipper_type);
|
|
||||||
|
|
||||||
}
|
} // namespace css_grammar
|
||||||
|
|
||||||
css_grammar::ident_grammar_type const ident_grammar();
|
css_grammar::ident_grammar_type const ident_grammar();
|
||||||
css_grammar::css_classes_type const classes();
|
css_grammar::css_classes_type const classes();
|
||||||
css_grammar::css_grammar_type const grammar();
|
css_grammar::css_grammar_type const grammar();
|
||||||
css_grammar::css_skipper_type const skipper();
|
css_grammar::css_skipper_type const skipper();
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_CSS_GRAMMAR_X3_HPP
|
#endif // MAPNIK_CSS_GRAMMAR_X3_HPP
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
*
|
*
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#ifndef MAPNIK_CSS_GRAMMAR_X3_DEF_HPP
|
#ifndef MAPNIK_CSS_GRAMMAR_X3_DEF_HPP
|
||||||
#define 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>
|
#include <boost/fusion/adapted/std_pair.hpp>
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
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
|
* : 0 or more
|
||||||
+ : 1 or more
|
+ : 1 or more
|
||||||
|
@ -148,46 +148,48 @@ namespace x3 = boost::spirit::x3;
|
||||||
|
|
||||||
namespace css_grammar {
|
namespace css_grammar {
|
||||||
|
|
||||||
using x3::lit;
|
using x3::alnum;
|
||||||
|
using x3::alpha;
|
||||||
using x3::attr;
|
using x3::attr;
|
||||||
|
using x3::char_;
|
||||||
|
using x3::lexeme;
|
||||||
|
using x3::lit;
|
||||||
using x3::no_case;
|
using x3::no_case;
|
||||||
using x3::no_skip;
|
using x3::no_skip;
|
||||||
using x3::lexeme;
|
|
||||||
using x3::alpha;
|
|
||||||
using x3::alnum;
|
|
||||||
using x3::char_;
|
|
||||||
using x3::raw;
|
using x3::raw;
|
||||||
using x3::standard::space;
|
using x3::standard::space;
|
||||||
|
|
||||||
// import unicode string rule
|
// 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)))
|
for (auto const& k : std::get<0>(_attr(ctx)))
|
||||||
{
|
{
|
||||||
_val(ctx).emplace(k, std::get<1>(_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));
|
_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
|
// rules
|
||||||
x3::rule<class simple_selector_tag, std::string> const simple_selector {"Simple selector"};
|
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 selector_tag, std::vector<std::string>> const selector{"Selector"};
|
||||||
x3::rule<class value_tag, property_value_type> const value {"Value"};
|
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 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 definition_tag, std::pair<std::vector<std::string>, definition_type>> const definition{"CSS Definition"};
|
||||||
|
|
||||||
auto const ident_def = alpha >> *(alnum | char_('-'));
|
auto const ident_def = alpha >> *(alnum | char_('-'));
|
||||||
auto const simple_selector_def = lexeme[ident >> -((char_('.') | char_('#') | char_(':')) >> ident)]
|
auto const simple_selector_def = lexeme[ident >> -((char_('.') | char_('#') | char_(':')) >> ident)] |
|
||||||
| lexeme[char_('#') >> ident >> -((char_('.') | char_(':')) >> ident)]
|
lexeme[char_('#') >> ident >> -((char_('.') | char_(':')) >> ident)] |
|
||||||
| lexeme[char_('.') >> ident >> -(char_(':') >> ident)];
|
lexeme[char_('.') >> ident >> -(char_(':') >> ident)];
|
||||||
|
|
||||||
auto const selector_def = simple_selector % lit(',');
|
auto const selector_def = simple_selector % lit(',');
|
||||||
auto const value_def = raw[lexeme[+~char_(";}")]];
|
auto const value_def = raw[lexeme[+~char_(";}")]];
|
||||||
|
@ -202,21 +204,19 @@ auto const css_classes_def = +lexeme[ident];
|
||||||
#include <mapnik/warning.hpp>
|
#include <mapnik/warning.hpp>
|
||||||
MAPNIK_DISABLE_WARNING_PUSH
|
MAPNIK_DISABLE_WARNING_PUSH
|
||||||
#include <mapnik/warning_ignore.hpp>
|
#include <mapnik/warning_ignore.hpp>
|
||||||
BOOST_SPIRIT_DEFINE(
|
BOOST_SPIRIT_DEFINE(ident,
|
||||||
ident,
|
css_classes,
|
||||||
css_classes,
|
simple_selector,
|
||||||
simple_selector,
|
selector,
|
||||||
selector,
|
value,
|
||||||
value,
|
key_value,
|
||||||
key_value,
|
definition,
|
||||||
definition,
|
css_grammar,
|
||||||
css_grammar,
|
css_skipper);
|
||||||
css_skipper
|
|
||||||
);
|
|
||||||
|
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
} //css_grammar
|
} // namespace css_grammar
|
||||||
} //mapnik
|
} // 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
|
#ifndef MAPNIK_CSS_UNIT_VALUE_HPP
|
||||||
#define 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;
|
constexpr static double DPI = 96;
|
||||||
css_unit_value()
|
css_unit_value()
|
||||||
{
|
{
|
||||||
add
|
add //
|
||||||
("px", 1.0) // pixels
|
("px", 1.0) // pixels
|
||||||
("pt", DPI/72.0) // points
|
("pt", DPI / 72.0) // points
|
||||||
("pc", DPI/6.0) // picas
|
("pc", DPI / 6.0) // picas
|
||||||
("mm", DPI/25.4) // milimeters
|
("mm", DPI / 25.4) // milimeters
|
||||||
("Q" , DPI/101.6)// quarter-milimeters
|
("Q", DPI / 101.6) // quarter-milimeters
|
||||||
("cm", DPI/2.54) // centimeters
|
("cm", DPI / 2.54) // centimeters
|
||||||
("in", static_cast<double>(DPI)) // inches
|
("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
|
constexpr static double EM = 10.0; // 1em == 10px
|
||||||
css_absolute_size()
|
css_absolute_size()
|
||||||
{
|
{
|
||||||
add
|
add //
|
||||||
("xx-small", 0.6 * EM)
|
("xx-small", 0.6 * EM) //
|
||||||
("x-small", 0.75 * EM)
|
("x-small", 0.75 * EM) //
|
||||||
("small", 0.88 * EM)
|
("small", 0.88 * EM) //
|
||||||
("medium", 1.0 * EM)
|
("medium", 1.0 * EM) //
|
||||||
("large", 1.2 * EM)
|
("large", 1.2 * EM) //
|
||||||
("x-large", 1.5 * EM)
|
("x-large", 1.5 * EM) //
|
||||||
("xx-large", 2.0 * EM)
|
("xx-large", 2.0 * EM) //
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -69,13 +68,12 @@ struct css_relative_size : x3::symbols<double>
|
||||||
{
|
{
|
||||||
css_relative_size()
|
css_relative_size()
|
||||||
{
|
{
|
||||||
add
|
add //
|
||||||
("larger", 1.2)
|
("larger", 1.2) //
|
||||||
("smaller", 0.8)
|
("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;
|
using attribute_type = x3::unused_type;
|
||||||
static bool const has_attribute = false;
|
static bool const has_attribute = false;
|
||||||
|
|
||||||
template <typename Iterator, typename Context, typename Attribute>
|
template<typename Iterator, typename Context, typename Attribute>
|
||||||
bool parse(Iterator& first, Iterator const& last,
|
bool parse(Iterator& first, Iterator const& last, Context const& context, x3::unused_type, Attribute&) const
|
||||||
Context const& context, x3::unused_type, Attribute& ) const
|
|
||||||
{
|
{
|
||||||
x3::skip_over(first, last, context);
|
x3::skip_over(first, last, context);
|
||||||
if (first != last && *first == ' ')
|
if (first != last && *first == ' ')
|
||||||
|
@ -64,6 +63,7 @@ csv_line_grammar_type const line = "csv-line";
|
||||||
|
|
||||||
BOOST_SPIRIT_DECLARE(csv_line_grammar_type);
|
BOOST_SPIRIT_DECLARE(csv_line_grammar_type);
|
||||||
|
|
||||||
}}
|
} // namespace grammar
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_CSV_GRAMMAR_X3_HPP
|
#endif // MAPNIK_CSV_GRAMMAR_X3_HPP
|
||||||
|
|
|
@ -29,45 +29,44 @@ MAPNIK_DISABLE_WARNING_PUSH
|
||||||
#include <mapnik/csv/csv_grammar_x3.hpp>
|
#include <mapnik/csv/csv_grammar_x3.hpp>
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
|
namespace mapnik {
|
||||||
namespace mapnik { namespace grammar {
|
namespace grammar {
|
||||||
|
|
||||||
namespace x3 = boost::spirit::x3;
|
namespace x3 = boost::spirit::x3;
|
||||||
namespace standard = boost::spirit::x3::standard;
|
namespace standard = boost::spirit::x3::standard;
|
||||||
|
|
||||||
using x3::lit;
|
|
||||||
using x3::lexeme;
|
|
||||||
using standard::char_;
|
using standard::char_;
|
||||||
|
using x3::lexeme;
|
||||||
|
using x3::lit;
|
||||||
|
|
||||||
struct unesc_char_ : x3::symbols<char>
|
struct unesc_char_ : x3::symbols<char>
|
||||||
{
|
{
|
||||||
unesc_char_()
|
unesc_char_()
|
||||||
{
|
{
|
||||||
add("\\a", '\a')
|
add("\\a", '\a') //
|
||||||
("\\b", '\b')
|
("\\b", '\b') //
|
||||||
("\\f", '\f')
|
("\\f", '\f') //
|
||||||
("\\n", '\n')
|
("\\n", '\n') //
|
||||||
("\\r", '\r')
|
("\\r", '\r') //
|
||||||
("\\t", '\t')
|
("\\t", '\t') //
|
||||||
("\\v", '\v')
|
("\\v", '\v') //
|
||||||
("\\\\",'\\')
|
("\\\\", '\\') //
|
||||||
("\\\'", '\'')
|
("\\\'", '\'') //
|
||||||
("\\\"", '\"')
|
("\\\"", '\"') //
|
||||||
("\"\"", '\"') // double quote
|
("\"\"", '\"') // double quote
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
} unesc_char;
|
} unesc_char;
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
struct literal : x3::parser<literal<T>>
|
struct literal : x3::parser<literal<T>>
|
||||||
{
|
{
|
||||||
using attribute_type = x3::unused_type;
|
using attribute_type = x3::unused_type;
|
||||||
using context_tag = T;
|
using context_tag = T;
|
||||||
static bool const has_attribute = false;
|
static bool const has_attribute = false;
|
||||||
|
|
||||||
template <typename Iterator, typename Context, typename Attribute>
|
template<typename Iterator, typename Context, typename Attribute>
|
||||||
bool parse(Iterator& first, Iterator const& last,
|
bool parse(Iterator& first, Iterator const& last, Context const& context, x3::unused_type, Attribute&) const
|
||||||
Context const& context, x3::unused_type, Attribute& ) const
|
|
||||||
{
|
{
|
||||||
x3::skip_over(first, last, context);
|
x3::skip_over(first, last, context);
|
||||||
if (first != last && *first == x3::get<context_tag>(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 csv_text, csv_value> const text("csv-text");
|
||||||
x3::rule<class csc_quoted_text, csv_value> const quoted_text("csv-quoted-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 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 (
|
BOOST_SPIRIT_DEFINE(line, column, quoted_text, text);
|
||||||
line,
|
|
||||||
column,
|
|
||||||
quoted_text,
|
|
||||||
text
|
|
||||||
);
|
|
||||||
|
|
||||||
} // grammar
|
} // namespace grammar
|
||||||
} // namespace mapnik
|
} // namespace mapnik
|
||||||
|
|
||||||
|
|
||||||
#endif // MAPNIK_CSV_GRAMMAR_X3_DEF_HPP
|
#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_line = std::vector<csv_value>;
|
||||||
using csv_data = std::vector<csv_line>;
|
using csv_data = std::vector<csv_line>;
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_CSV_TYPES_HPP
|
#endif // MAPNIK_CSV_TYPES_HPP
|
||||||
|
|
|
@ -43,31 +43,27 @@ namespace mapnik {
|
||||||
|
|
||||||
class MAPNIK_DECL datasource_exception : public std::exception
|
class MAPNIK_DECL datasource_exception : public std::exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
datasource_exception(std::string const& message)
|
datasource_exception(std::string const& message)
|
||||||
: message_(message)
|
: message_(message)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
~datasource_exception() {}
|
~datasource_exception() {}
|
||||||
|
|
||||||
virtual const char* what() const noexcept
|
virtual const char* what() const noexcept { return message_.c_str(); }
|
||||||
{
|
|
||||||
return message_.c_str();
|
private:
|
||||||
}
|
|
||||||
private:
|
|
||||||
std::string message_;
|
std::string message_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MAPNIK_DECL datasource : private util::noncopyable
|
class MAPNIK_DECL datasource : private util::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum datasource_t : std::uint8_t {
|
enum datasource_t : std::uint8_t { Vector, Raster };
|
||||||
Vector,
|
|
||||||
Raster
|
|
||||||
};
|
|
||||||
|
|
||||||
datasource (parameters const& _params)
|
datasource(parameters const& _params)
|
||||||
: params_(_params) {}
|
: params_(_params)
|
||||||
|
{}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Get the configuration parameters of the data source.
|
* @brief Get the configuration parameters of the data source.
|
||||||
|
@ -76,25 +72,13 @@ public:
|
||||||
*
|
*
|
||||||
* @return The configuration parameters of the data source.
|
* @return The configuration parameters of the data source.
|
||||||
*/
|
*/
|
||||||
parameters const& params() const
|
parameters const& params() const { return params_; }
|
||||||
{
|
|
||||||
return params_;
|
|
||||||
}
|
|
||||||
|
|
||||||
parameters & params()
|
parameters& params() { return params_; }
|
||||||
{
|
|
||||||
return params_;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator==(datasource const& rhs) const
|
bool operator==(datasource const& rhs) const { return params_ == rhs.params(); }
|
||||||
{
|
|
||||||
return params_ == rhs.params();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator!=(datasource const& rhs) const
|
bool operator!=(datasource const& rhs) const { return !(*this == rhs); }
|
||||||
{
|
|
||||||
return !(*this == rhs);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Get the type of the datasource
|
* @brief Get the type of the datasource
|
||||||
|
@ -113,43 +97,32 @@ public:
|
||||||
virtual box2d<double> envelope() const = 0;
|
virtual box2d<double> envelope() const = 0;
|
||||||
virtual layer_descriptor get_descriptor() const = 0;
|
virtual layer_descriptor get_descriptor() const = 0;
|
||||||
virtual ~datasource() {}
|
virtual ~datasource() {}
|
||||||
protected:
|
|
||||||
|
protected:
|
||||||
parameters params_;
|
parameters params_;
|
||||||
};
|
};
|
||||||
|
|
||||||
using datasource_name = const char* (*)();
|
using datasource_name = const char* (*)();
|
||||||
using create_ds = datasource* (*) (parameters const&);
|
using create_ds = datasource* (*)(parameters const&);
|
||||||
using destroy_ds = void (*) (datasource *);
|
using destroy_ds = void (*)(datasource*);
|
||||||
|
|
||||||
class datasource_deleter
|
class datasource_deleter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void operator() (datasource* ds)
|
void operator()(datasource* ds) { delete ds; }
|
||||||
{
|
|
||||||
delete ds;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
using datasource_ptr = std::shared_ptr<datasource>;
|
using datasource_ptr = std::shared_ptr<datasource>;
|
||||||
|
|
||||||
#ifdef MAPNIK_STATIC_PLUGINS
|
#ifdef MAPNIK_STATIC_PLUGINS
|
||||||
#define DATASOURCE_PLUGIN(classname)
|
#define DATASOURCE_PLUGIN(classname)
|
||||||
#else
|
#else
|
||||||
#define DATASOURCE_PLUGIN(classname) \
|
#define DATASOURCE_PLUGIN(classname) \
|
||||||
extern "C" MAPNIK_EXP const char * datasource_name() \
|
extern "C" MAPNIK_EXP const char* datasource_name() { return classname::name(); } \
|
||||||
{ \
|
extern "C" MAPNIK_EXP datasource* create(parameters const& params) { return new classname(params); } \
|
||||||
return classname::name(); \
|
extern "C" MAPNIK_EXP void destroy(datasource* ds) { delete ds; }
|
||||||
} \
|
|
||||||
extern "C" MAPNIK_EXP datasource* create(parameters const& params) \
|
|
||||||
{ \
|
|
||||||
return new classname(params); \
|
|
||||||
} \
|
|
||||||
extern "C" MAPNIK_EXP void destroy(datasource *ds) \
|
|
||||||
{ \
|
|
||||||
delete ds; \
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_DATASOURCE_HPP
|
#endif // MAPNIK_DATASOURCE_HPP
|
||||||
|
|
|
@ -41,21 +41,22 @@ class datasource;
|
||||||
class parameters;
|
class parameters;
|
||||||
class PluginInfo;
|
class PluginInfo;
|
||||||
|
|
||||||
class MAPNIK_DECL datasource_cache
|
class MAPNIK_DECL datasource_cache : public singleton<datasource_cache, CreateStatic>,
|
||||||
: public singleton<datasource_cache, CreateStatic>,
|
private util::noncopyable
|
||||||
private util::noncopyable
|
|
||||||
{
|
{
|
||||||
friend class CreateStatic<datasource_cache>;
|
friend class CreateStatic<datasource_cache>;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
std::vector<std::string> plugin_names();
|
std::vector<std::string> plugin_names();
|
||||||
std::string plugin_directories();
|
std::string plugin_directories();
|
||||||
bool register_datasources(std::string const& path, bool recurse = false);
|
bool register_datasources(std::string const& path, bool recurse = false);
|
||||||
bool register_datasource(std::string const& path);
|
bool register_datasource(std::string const& path);
|
||||||
std::shared_ptr<datasource> create(parameters const& params);
|
std::shared_ptr<datasource> create(parameters const& params);
|
||||||
private:
|
|
||||||
|
private:
|
||||||
datasource_cache();
|
datasource_cache();
|
||||||
~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_;
|
std::set<std::string> plugin_directories_;
|
||||||
// the singleton has a mutex protecting the instance pointer,
|
// the singleton has a mutex protecting the instance pointer,
|
||||||
// but the instance also needs its own mutex to protect the
|
// 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>;
|
extern template class MAPNIK_DECL singleton<datasource_cache, CreateStatic>;
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_DATASOURCE_CACHE_HPP
|
#endif // MAPNIK_DATASOURCE_CACHE_HPP
|
||||||
|
|
|
@ -27,15 +27,8 @@
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
enum datasource_geometry_t : std::uint8_t {
|
enum datasource_geometry_t : std::uint8_t { Unknown = 0, Point = 1, LineString = 2, Polygon = 3, Collection = 4 };
|
||||||
Unknown = 0,
|
|
||||||
Point = 1,
|
|
||||||
LineString = 2,
|
|
||||||
Polygon = 3,
|
|
||||||
Collection = 4
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // MAPNIK_DATASOURCE_GEOMETRY_TYPE_HPP
|
#endif // MAPNIK_DATASOURCE_GEOMETRY_TYPE_HPP
|
||||||
|
|
|
@ -42,35 +42,21 @@
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
|
|
||||||
// Global logger class that holds the configuration of severity, format
|
// Global logger class that holds the configuration of severity, format
|
||||||
// and file/console redirection.
|
// and file/console redirection.
|
||||||
|
|
||||||
class MAPNIK_DECL logger :
|
class MAPNIK_DECL logger : public singleton<logger, CreateStatic>,
|
||||||
public singleton<logger,CreateStatic>,
|
private util::noncopyable
|
||||||
private util::noncopyable
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum severity_type
|
enum severity_type { debug = 0, warn = 1, error = 2, none = 3 };
|
||||||
{
|
|
||||||
debug = 0,
|
|
||||||
warn = 1,
|
|
||||||
error = 2,
|
|
||||||
none = 3
|
|
||||||
};
|
|
||||||
|
|
||||||
using severity_map = std::unordered_map<std::string, severity_type>;
|
using severity_map = std::unordered_map<std::string, severity_type>;
|
||||||
|
|
||||||
// global security level
|
// global security level
|
||||||
static severity_type get_severity()
|
static severity_type get_severity() { return severity_level_; }
|
||||||
{
|
|
||||||
return severity_level_;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void set_severity(severity_type severity_level)
|
static void set_severity(severity_type severity_level) { severity_level_ = severity_level; }
|
||||||
{
|
|
||||||
severity_level_ = severity_level;
|
|
||||||
}
|
|
||||||
|
|
||||||
// per object security levels
|
// per object security levels
|
||||||
static severity_type get_object_severity(std::string const& object_name)
|
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,
|
static void set_object_severity(std::string const& object_name, severity_type const& security_level)
|
||||||
severity_type const& security_level)
|
|
||||||
{
|
{
|
||||||
if (!object_name.empty())
|
if (!object_name.empty())
|
||||||
{
|
{
|
||||||
|
@ -111,10 +96,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// format
|
// format
|
||||||
static std::string const& get_format()
|
static std::string const& get_format() { return format_; }
|
||||||
{
|
|
||||||
return format_;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void set_format(std::string const& 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_file(std::string const& filepath);
|
||||||
static void use_console();
|
static void use_console();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static severity_map object_severity_level_;
|
static severity_map object_severity_level_;
|
||||||
static std::string format_;
|
static std::string format_;
|
||||||
static std::ofstream file_output_;
|
static std::ofstream file_output_;
|
||||||
|
@ -151,7 +133,6 @@ private:
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
// Default sink, it regulates access to clog
|
// Default sink, it regulates access to clog
|
||||||
|
@ -159,7 +140,7 @@ namespace detail {
|
||||||
template<class Ch, class Tr, class A>
|
template<class Ch, class Tr, class A>
|
||||||
class clog_sink
|
class clog_sink
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using stream_buffer = std::basic_ostringstream<Ch, Tr, A>;
|
using stream_buffer = std::basic_ostringstream<Ch, Tr, A>;
|
||||||
|
|
||||||
void operator()(logger::severity_type const& /*severity*/, stream_buffer const& s)
|
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
|
// This is used for debug/warn reporting that should not output
|
||||||
// anything when not compiling for speed.
|
// 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,
|
logger::severity_type Severity,
|
||||||
class Ch = char,
|
class Ch = char,
|
||||||
class Tr = std::char_traits<Ch>,
|
class Tr = std::char_traits<Ch>,
|
||||||
class A = std::allocator<Ch> >
|
class A = std::allocator<Ch>>
|
||||||
class base_log : public util::noncopyable
|
class base_log : public util::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using output_policy = OutputPolicy<Ch, Tr, A>;
|
using output_policy = OutputPolicy<Ch, Tr, A>;
|
||||||
|
|
||||||
base_log() {}
|
base_log() {}
|
||||||
|
@ -198,9 +179,7 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
base_log(const char* /*object_name*/)
|
base_log(const char* /*object_name*/) {}
|
||||||
{
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
~base_log()
|
~base_log()
|
||||||
|
@ -215,45 +194,38 @@ public:
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
#ifdef MAPNIK_LOG
|
#ifdef MAPNIK_LOG
|
||||||
base_log &operator<<(T const& x)
|
base_log& operator<<(T const& x)
|
||||||
{
|
{
|
||||||
|
|
||||||
streambuf_ << x;
|
streambuf_ << x;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
base_log &operator<<(T const& /*x*/)
|
base_log& operator<<(T const& /*x*/)
|
||||||
{
|
{
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#ifdef MAPNIK_LOG
|
#ifdef MAPNIK_LOG
|
||||||
inline bool check_severity()
|
inline bool check_severity() { return Severity >= logger::get_object_severity(object_name_); }
|
||||||
{
|
|
||||||
return Severity >= logger::get_object_severity(object_name_);
|
|
||||||
}
|
|
||||||
|
|
||||||
typename output_policy::stream_buffer streambuf_;
|
typename output_policy::stream_buffer streambuf_;
|
||||||
std::string object_name_;
|
std::string object_name_;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 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,
|
||||||
//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,
|
|
||||||
logger::severity_type Severity,
|
logger::severity_type Severity,
|
||||||
class Ch = char,
|
class Ch = char,
|
||||||
class Tr = std::char_traits<Ch>,
|
class Tr = std::char_traits<Ch>,
|
||||||
class A = std::allocator<Ch> >
|
class A = std::allocator<Ch>>
|
||||||
class base_log_always : public util::noncopyable
|
class base_log_always : public util::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using output_policy = OutputPolicy<Ch, Tr, A>;
|
using output_policy = OutputPolicy<Ch, Tr, A>;
|
||||||
|
|
||||||
base_log_always() {}
|
base_log_always() {}
|
||||||
|
@ -275,56 +247,63 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
base_log_always &operator<<(T const& x)
|
base_log_always& operator<<(T const& x)
|
||||||
{
|
{
|
||||||
streambuf_ << x;
|
streambuf_ << x;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline bool check_severity()
|
inline bool check_severity() { return Severity >= logger::get_object_severity(object_name_); }
|
||||||
{
|
|
||||||
return Severity >= logger::get_object_severity(object_name_);
|
|
||||||
}
|
|
||||||
|
|
||||||
typename output_policy::stream_buffer streambuf_;
|
typename output_policy::stream_buffer streambuf_;
|
||||||
std::string object_name_;
|
std::string object_name_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
using base_log_debug = base_log<clog_sink, logger::debug>;
|
using base_log_debug = base_log<clog_sink, logger::debug>;
|
||||||
using base_log_warn = base_log<clog_sink, logger::warn>;
|
using base_log_warn = base_log<clog_sink, logger::warn>;
|
||||||
using base_log_error = base_log_always<clog_sink, logger::error>;
|
using base_log_error = base_log_always<clog_sink, logger::error>;
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
|
|
||||||
// real interfaces
|
// real interfaces
|
||||||
class MAPNIK_DECL warn : public detail::base_log_warn
|
class MAPNIK_DECL warn : public detail::base_log_warn
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
warn() : detail::base_log_warn() {}
|
warn()
|
||||||
warn(const char* object_name) : detail::base_log_warn(object_name) {}
|
: detail::base_log_warn()
|
||||||
|
{}
|
||||||
|
warn(const char* object_name)
|
||||||
|
: detail::base_log_warn(object_name)
|
||||||
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
class MAPNIK_DECL debug : public detail::base_log_debug
|
class MAPNIK_DECL debug : public detail::base_log_debug
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
debug() : detail::base_log_debug() {}
|
debug()
|
||||||
debug(const char* object_name) : detail::base_log_debug(object_name) {}
|
: detail::base_log_debug()
|
||||||
|
{}
|
||||||
|
debug(const char* object_name)
|
||||||
|
: detail::base_log_debug(object_name)
|
||||||
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
class MAPNIK_DECL error : public detail::base_log_error
|
class MAPNIK_DECL error : public detail::base_log_error
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
error() : detail::base_log_error() {}
|
error()
|
||||||
error(const char* object_name) : detail::base_log_error(object_name) {}
|
: detail::base_log_error()
|
||||||
|
{}
|
||||||
|
error(const char* object_name)
|
||||||
|
: detail::base_log_error(object_name)
|
||||||
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
// logging helpers
|
// logging helpers
|
||||||
#define MAPNIK_LOG_DEBUG(s) mapnik::debug(#s)
|
#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)
|
#define MAPNIK_LOG_ERROR(s) mapnik::error(#s)
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_DEBUG_HPP
|
#endif // MAPNIK_DEBUG_HPP
|
||||||
|
|
|
@ -38,26 +38,22 @@ namespace mapnik {
|
||||||
|
|
||||||
class illegal_enum_value : public std::exception
|
class illegal_enum_value : public std::exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
illegal_enum_value():
|
illegal_enum_value()
|
||||||
what_() {}
|
: what_()
|
||||||
|
{}
|
||||||
|
|
||||||
illegal_enum_value( std::string const& _what ) :
|
illegal_enum_value(std::string const& _what)
|
||||||
what_( _what )
|
: what_(_what)
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
virtual ~illegal_enum_value() {}
|
virtual ~illegal_enum_value() {}
|
||||||
|
|
||||||
virtual const char * what() const noexcept
|
virtual const char* what() const noexcept { return what_.c_str(); }
|
||||||
{
|
|
||||||
return what_.c_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string what_;
|
std::string what_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/** Slim wrapper for enumerations. It creates a new type from a native enum and
|
/** 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
|
* a char pointer array. It almost exactly behaves like a native enumeration
|
||||||
* type. It supports string conversion through stream operators. This is useful
|
* type. It supports string conversion through stream operators. This is useful
|
||||||
|
@ -137,42 +133,34 @@ protected:
|
||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template <typename ENUM, int THE_MAX>
|
template<typename ENUM, int THE_MAX>
|
||||||
class MAPNIK_DECL enumeration {
|
class MAPNIK_DECL enumeration
|
||||||
public:
|
{
|
||||||
|
public:
|
||||||
using native_type = ENUM;
|
using native_type = ENUM;
|
||||||
|
|
||||||
enumeration()
|
enumeration()
|
||||||
: value_() {}
|
: value_()
|
||||||
|
{}
|
||||||
|
|
||||||
enumeration( ENUM v )
|
enumeration(ENUM v)
|
||||||
: value_(v) {}
|
: value_(v)
|
||||||
|
{}
|
||||||
|
|
||||||
enumeration( enumeration const& other )
|
enumeration(enumeration const& other)
|
||||||
: value_(other.value_) {}
|
: value_(other.value_)
|
||||||
|
{}
|
||||||
|
|
||||||
/** Assignment operator for native enum values. */
|
/** Assignment operator for native enum values. */
|
||||||
void operator=(ENUM v)
|
void operator=(ENUM v) { value_ = v; }
|
||||||
{
|
|
||||||
value_ = v;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Assignment operator. */
|
/** Assignment operator. */
|
||||||
void operator=(enumeration const& other)
|
void operator=(enumeration const& other) { value_ = other.value_; }
|
||||||
{
|
|
||||||
value_ = other.value_;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Conversion operator for native enum values. */
|
/** Conversion operator for native enum values. */
|
||||||
operator ENUM() const
|
operator ENUM() const { return value_; }
|
||||||
{
|
|
||||||
return value_;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum Max
|
enum Max { MAX = THE_MAX };
|
||||||
{
|
|
||||||
MAX = THE_MAX
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Converts @p str to an enum.
|
/** Converts @p str to an enum.
|
||||||
* @throw illegal_enum_value @p str is not a legal identifier.
|
* @throw illegal_enum_value @p str is not a legal identifier.
|
||||||
|
@ -190,113 +178,114 @@ public:
|
||||||
}
|
}
|
||||||
for (unsigned i = 0; i < THE_MAX; ++i)
|
for (unsigned i = 0; i < THE_MAX; ++i)
|
||||||
{
|
{
|
||||||
|
MAPNIK_DISABLE_WARNING_PUSH
|
||||||
MAPNIK_DISABLE_WARNING_PUSH
|
MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS
|
||||||
MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS
|
MAPNIK_DISABLE_WARNING_PRAGMAS
|
||||||
MAPNIK_DISABLE_WARNING_PRAGMAS
|
MAPNIK_DISABLE_LONG_LONG
|
||||||
MAPNIK_DISABLE_LONG_LONG
|
|
||||||
if (str_copy == our_strings_[i])
|
if (str_copy == our_strings_[i])
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
MAPNIK_DISABLE_WARNING_POP
|
||||||
{
|
|
||||||
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";
|
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_PUSH
|
||||||
MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS
|
MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS
|
||||||
MAPNIK_DISABLE_WARNING_PRAGMAS
|
MAPNIK_DISABLE_WARNING_PRAGMAS
|
||||||
MAPNIK_DISABLE_LONG_LONG
|
MAPNIK_DISABLE_LONG_LONG
|
||||||
throw illegal_enum_value(std::string("Illegal enumeration value '") +
|
throw illegal_enum_value(std::string("Illegal enumeration value '") + str + "' for enum " + our_name_);
|
||||||
str + "' for enum " + our_name_);
|
MAPNIK_DISABLE_WARNING_POP
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the current value as a string identifier. */
|
/** Returns the current value as a string identifier. */
|
||||||
std::string as_string() const
|
std::string as_string() const
|
||||||
{
|
{
|
||||||
MAPNIK_DISABLE_WARNING_PUSH
|
MAPNIK_DISABLE_WARNING_PUSH
|
||||||
MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS
|
MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS
|
||||||
MAPNIK_DISABLE_WARNING_PRAGMAS
|
MAPNIK_DISABLE_WARNING_PRAGMAS
|
||||||
MAPNIK_DISABLE_LONG_LONG
|
MAPNIK_DISABLE_LONG_LONG
|
||||||
return our_strings_[value_];
|
return our_strings_[value_];
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
MAPNIK_DISABLE_WARNING_POP
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Static helper function to iterate over valid identifiers. */
|
/** Static helper function to iterate over valid identifiers. */
|
||||||
static const char * get_string(unsigned i)
|
static const char* get_string(unsigned i) { return our_strings_[i]; }
|
||||||
{
|
|
||||||
return our_strings_[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Performs some simple checks and quits the application if
|
/** Performs some simple checks and quits the application if
|
||||||
* any error is detected. Tries to print helpful error messages.
|
* 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)
|
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 "
|
std::cerr << "### FATAL: Not enough strings for enum " << our_name_ << " defined in file '" << filename
|
||||||
<< our_name_ << " defined in file '" << filename
|
|
||||||
<< "' at line " << line_no;
|
<< "' 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_
|
std::cerr << "### FATAL: The string array for enum " << our_name_ << " defined in file '" << filename
|
||||||
<< " defined in file '" << filename << "' at line " << line_no
|
<< "' at line " << line_no << " has too many items or is not terminated with an "
|
||||||
<< " has too many items or is not terminated with an "
|
|
||||||
<< "empty string";
|
<< "empty string";
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ENUM value_;
|
ENUM value_;
|
||||||
static const char ** our_strings_ ;
|
static const char** our_strings_;
|
||||||
static std::string our_name_ ;
|
static std::string our_name_;
|
||||||
static bool our_verified_flag_;
|
static bool our_verified_flag_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** ostream operator for enumeration
|
/** ostream operator for enumeration
|
||||||
* @relates mapnik::enumeration
|
* @relates mapnik::enumeration
|
||||||
*/
|
*/
|
||||||
template <class ENUM, int THE_MAX>
|
template<class ENUM, int THE_MAX>
|
||||||
std::ostream &
|
std::ostream& operator<<(std::ostream& os, const mapnik::enumeration<ENUM, THE_MAX>& e)
|
||||||
operator<<(std::ostream & os, const mapnik::enumeration<ENUM, THE_MAX> & e)
|
|
||||||
{
|
{
|
||||||
return os << e.as_string();
|
return os << e.as_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end of namespace
|
} // namespace mapnik
|
||||||
|
|
||||||
/** Helper macro.
|
/** Helper macro.
|
||||||
* @relates mapnik::enumeration
|
* @relates mapnik::enumeration
|
||||||
*/
|
*/
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#define DEFINE_ENUM( name, e) \
|
#define DEFINE_ENUM(name, e) \
|
||||||
template enumeration<e, e ## _MAX>; \
|
template enumeration<e, e##_MAX>; \
|
||||||
using name = enumeration<e, e ## _MAX>;
|
using name = enumeration<e, e##_MAX>;
|
||||||
#else
|
#else
|
||||||
#define DEFINE_ENUM( name, e) \
|
#define DEFINE_ENUM(name, e) \
|
||||||
using name = enumeration<e, e ## _MAX>; \
|
using name = enumeration<e, e##_MAX>; \
|
||||||
template <> MAPNIK_DECL const char ** name ::our_strings_; \
|
template<> \
|
||||||
template <> MAPNIK_DECL std::string name ::our_name_; \
|
MAPNIK_DECL const char** name ::our_strings_; \
|
||||||
template <> MAPNIK_DECL bool name ::our_verified_flag_;
|
template<> \
|
||||||
|
MAPNIK_DECL std::string name ::our_name_; \
|
||||||
|
template<> \
|
||||||
|
MAPNIK_DECL bool name ::our_verified_flag_;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** Helper macro. Runs the verify_mapnik_enum() method during static initialization.
|
/** Helper macro. Runs the verify_mapnik_enum() method during static initialization.
|
||||||
* @relates mapnik::enumeration
|
* @relates mapnik::enumeration
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define IMPLEMENT_ENUM( name, strings ) \
|
#define IMPLEMENT_ENUM(name, strings) \
|
||||||
template <> MAPNIK_DECL const char ** name ::our_strings_ = strings; \
|
template<> \
|
||||||
template <> MAPNIK_DECL std::string name ::our_name_ = #name; \
|
MAPNIK_DECL const char** name ::our_strings_ = strings; \
|
||||||
template <> MAPNIK_DECL bool name ::our_verified_flag_( name ::verify_mapnik_enum(__FILE__, __LINE__));
|
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
|
#endif // MAPNIK_ENUMERATION_HPP
|
||||||
|
|
|
@ -38,93 +38,91 @@ namespace mapnik {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
template <typename T, typename Attributes>
|
template<typename T, typename Attributes>
|
||||||
struct evaluate_expression
|
struct evaluate_expression
|
||||||
{
|
{
|
||||||
using value_type = T;
|
using value_type = T;
|
||||||
|
|
||||||
explicit evaluate_expression(Attributes const& attrs)
|
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");
|
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);
|
auto itr = attrs_.find(attr.name);
|
||||||
if (itr != attrs_.end())
|
if (itr != attrs_.end())
|
||||||
{
|
{
|
||||||
return itr->second;
|
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");
|
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())
|
return (util::apply_visitor(*this, x.left).to_bool()) && (util::apply_visitor(*this, x.right).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())
|
return (util::apply_visitor(*this, x.left).to_bool()) || (util::apply_visitor(*this, x.right).to_bool());
|
||||||
|| (util::apply_visitor(*this,x.right).to_bool());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Tag>
|
template<typename Tag>
|
||||||
value_type operator() (binary_node<Tag> const& x) const
|
value_type operator()(binary_node<Tag> const& x) const
|
||||||
{
|
{
|
||||||
typename make_op<Tag>::type operation;
|
typename make_op<Tag>::type operation;
|
||||||
return operation(util::apply_visitor(*this, x.left),
|
return operation(util::apply_visitor(*this, x.left), util::apply_visitor(*this, x.right));
|
||||||
util::apply_visitor(*this, x.right));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Tag>
|
template<typename Tag>
|
||||||
value_type operator() (unary_node<Tag> const& x) const
|
value_type operator()(unary_node<Tag> const& x) const
|
||||||
{
|
{
|
||||||
typename make_op<Tag>::type func;
|
typename make_op<Tag>::type func;
|
||||||
return func(util::apply_visitor(*this, x.expr));
|
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);
|
value_type v = util::apply_visitor(*this, x.expr);
|
||||||
return x.apply(v);
|
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);
|
value_type v = util::apply_visitor(*this, x.expr);
|
||||||
return x.apply(v);
|
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);
|
value_type arg = util::apply_visitor(*this, call.arg);
|
||||||
return call.fun(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 arg1 = util::apply_visitor(*this, call.arg1);
|
||||||
value_type arg2 = util::apply_visitor(*this, call.arg2);
|
value_type arg2 = util::apply_visitor(*this, call.arg2);
|
||||||
return call.fun(arg1, arg2);
|
return call.fun(arg1, arg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ValueType>
|
template<typename ValueType>
|
||||||
value_type operator() (ValueType const& val) const
|
value_type operator()(ValueType const& val) const
|
||||||
{
|
{
|
||||||
return value_type(val);
|
return value_type(val);
|
||||||
}
|
}
|
||||||
|
@ -132,87 +130,84 @@ struct evaluate_expression
|
||||||
Attributes const& attrs_;
|
Attributes const& attrs_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
struct evaluate_expression<T, boost::none_t>
|
struct evaluate_expression<T, boost::none_t>
|
||||||
{
|
{
|
||||||
using value_type = T;
|
using value_type = T;
|
||||||
|
|
||||||
evaluate_expression(boost::none_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");
|
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");
|
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");
|
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())
|
return (util::apply_visitor(*this, x.left).to_bool()) && (util::apply_visitor(*this, x.right).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())
|
return (util::apply_visitor(*this, x.left).to_bool()) || (util::apply_visitor(*this, x.right).to_bool());
|
||||||
|| (util::apply_visitor(*this,x.right).to_bool());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Tag>
|
template<typename Tag>
|
||||||
value_type operator() (binary_node<Tag> const& x) const
|
value_type operator()(binary_node<Tag> const& x) const
|
||||||
{
|
{
|
||||||
typename make_op<Tag>::type operation;
|
typename make_op<Tag>::type operation;
|
||||||
return operation(util::apply_visitor(*this, x.left),
|
return operation(util::apply_visitor(*this, x.left), util::apply_visitor(*this, x.right));
|
||||||
util::apply_visitor(*this, x.right));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Tag>
|
template<typename Tag>
|
||||||
value_type operator() (unary_node<Tag> const& x) const
|
value_type operator()(unary_node<Tag> const& x) const
|
||||||
{
|
{
|
||||||
typename make_op<Tag>::type func;
|
typename make_op<Tag>::type func;
|
||||||
return func(util::apply_visitor(*this, x.expr));
|
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);
|
value_type v = util::apply_visitor(*this, x.expr);
|
||||||
return x.apply(v);
|
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);
|
value_type v = util::apply_visitor(*this, x.expr);
|
||||||
return x.apply(v);
|
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);
|
value_type arg = util::apply_visitor(*this, call.arg);
|
||||||
return call.fun(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 arg1 = util::apply_visitor(*this, call.arg1);
|
||||||
value_type arg2 = util::apply_visitor(*this, call.arg2);
|
value_type arg2 = util::apply_visitor(*this, call.arg2);
|
||||||
return call.fun(arg1, arg2);
|
return call.fun(arg1, arg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ValueType>
|
template<typename ValueType>
|
||||||
value_type operator() (ValueType const& val) const
|
value_type operator()(ValueType const& val) const
|
||||||
{
|
{
|
||||||
return value_type(val);
|
return value_type(val);
|
||||||
}
|
}
|
||||||
|
@ -221,90 +216,98 @@ struct evaluate_expression<T, boost::none_t>
|
||||||
struct assign_value
|
struct assign_value
|
||||||
{
|
{
|
||||||
template<typename Attributes>
|
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)
|
switch (target)
|
||||||
{
|
{
|
||||||
case property_types::target_color:
|
case property_types::target_color: {
|
||||||
{
|
// evaluate expression as a string then parse as css color
|
||||||
// evaluate expression as a string then parse as css color
|
std::string str =
|
||||||
std::string str = util::apply_visitor(mapnik::evaluate_expression<mapnik::value,
|
util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs), *expr).to_string();
|
||||||
Attributes>(attrs),*expr).to_string();
|
try
|
||||||
try { val = parse_color(str); }
|
{
|
||||||
catch (...) { val = color(0,0,0);}
|
val = parse_color(str);
|
||||||
break;
|
} catch (...)
|
||||||
}
|
{
|
||||||
case property_types::target_double:
|
val = color(0, 0, 0);
|
||||||
{
|
}
|
||||||
val = util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs),*expr).to_double();
|
break;
|
||||||
break;
|
}
|
||||||
}
|
case property_types::target_double: {
|
||||||
case property_types::target_integer:
|
val =
|
||||||
{
|
util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs), *expr).to_double();
|
||||||
val = util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs),*expr).to_int();
|
break;
|
||||||
break;
|
}
|
||||||
}
|
case property_types::target_integer: {
|
||||||
case property_types::target_bool:
|
val =
|
||||||
{
|
util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs), *expr).to_int();
|
||||||
val = util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs),*expr).to_bool();
|
break;
|
||||||
break;
|
}
|
||||||
}
|
case property_types::target_bool: {
|
||||||
default: // no-op
|
val =
|
||||||
break;
|
util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs), *expr).to_bool();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: // no-op
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
std::tuple<T,bool> pre_evaluate_expression (expression_ptr const& expr)
|
std::tuple<T, bool> pre_evaluate_expression(expression_ptr const& expr)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return std::make_tuple(util::apply_visitor(mapnik::evaluate_expression<T, boost::none_t>(boost::none),*expr), true);
|
return std::make_tuple(util::apply_visitor(mapnik::evaluate_expression<T, boost::none_t>(boost::none), *expr),
|
||||||
}
|
true);
|
||||||
catch (...)
|
} catch (...)
|
||||||
{
|
{
|
||||||
return std::make_tuple(T(),false);
|
return std::make_tuple(T(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct evaluate_global_attributes : util::noncopyable
|
struct evaluate_global_attributes : util::noncopyable
|
||||||
{
|
{
|
||||||
template <typename Attributes>
|
template<typename Attributes>
|
||||||
struct evaluator
|
struct evaluator
|
||||||
{
|
{
|
||||||
evaluator(symbolizer_base::cont_type::value_type & prop, Attributes const& attrs)
|
evaluator(symbolizer_base::cont_type::value_type& prop, Attributes const& attrs)
|
||||||
: prop_(prop),
|
: prop_(prop)
|
||||||
attrs_(attrs) {}
|
, attrs_(attrs)
|
||||||
|
{}
|
||||||
|
|
||||||
void operator() (expression_ptr const& expr) const
|
void operator()(expression_ptr const& expr) const
|
||||||
{
|
{
|
||||||
auto const& meta = get_meta(prop_.first);
|
auto const& meta = get_meta(prop_.first);
|
||||||
assign_value::apply(prop_.second, expr, attrs_, std::get<2>(meta));
|
assign_value::apply(prop_.second, expr, attrs_, std::get<2>(meta));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
void operator() (T const&) const
|
void operator()(T const&) const
|
||||||
{
|
{
|
||||||
// no-op
|
// no-op
|
||||||
}
|
}
|
||||||
symbolizer_base::cont_type::value_type & prop_;
|
symbolizer_base::cont_type::value_type& prop_;
|
||||||
Attributes const& attrs_;
|
Attributes const& attrs_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Attributes>
|
template<typename Attributes>
|
||||||
struct extract_symbolizer
|
struct extract_symbolizer
|
||||||
{
|
{
|
||||||
extract_symbolizer(Attributes const& attrs)
|
extract_symbolizer(Attributes const& attrs)
|
||||||
: attrs_(attrs) {}
|
: attrs_(attrs)
|
||||||
|
{}
|
||||||
|
|
||||||
template <typename Symbolizer>
|
template<typename Symbolizer>
|
||||||
void operator() (Symbolizer & sym) const
|
void operator()(Symbolizer& sym) const
|
||||||
{
|
{
|
||||||
for (auto & prop : sym.properties)
|
for (auto& prop : sym.properties)
|
||||||
{
|
{
|
||||||
util::apply_visitor(evaluator<Attributes>(prop, attrs_), prop.second);
|
util::apply_visitor(evaluator<Attributes>(prop, attrs_), prop.second);
|
||||||
}
|
}
|
||||||
|
@ -312,14 +315,14 @@ struct evaluate_global_attributes : util::noncopyable
|
||||||
Attributes const& attrs_;
|
Attributes const& attrs_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Attributes>
|
template<typename Attributes>
|
||||||
static void apply(Map & m, Attributes const& attrs)
|
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);
|
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
|
#endif // MAPNIK_EVALUATE_GLOBAL_ATTRIBUTES_HPP
|
||||||
|
|
|
@ -34,14 +34,13 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
|
|
||||||
// fwd declare to reduce compile time
|
// fwd declare to reduce compile time
|
||||||
using expression_ptr = std::shared_ptr<expr_node>;
|
using expression_ptr = std::shared_ptr<expr_node>;
|
||||||
using expression_set = std::set<expression_ptr>;
|
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
|
#endif // MAPNIK_EXPRESSION_HPP
|
||||||
|
|
|
@ -31,10 +31,9 @@
|
||||||
#include <mapnik/util/variant.hpp>
|
#include <mapnik/util/variant.hpp>
|
||||||
#include <mapnik/feature.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
|
struct evaluate
|
||||||
{
|
{
|
||||||
using feature_type = T0;
|
using feature_type = T0;
|
||||||
|
@ -42,105 +41,85 @@ struct evaluate
|
||||||
using variable_type = T2;
|
using variable_type = T2;
|
||||||
using result_type = T1; // we need this because automatic result_type deduction fails
|
using result_type = T1; // we need this because automatic result_type deduction fails
|
||||||
explicit evaluate(feature_type const& f, variable_type const& v)
|
explicit evaluate(feature_type const& f, variable_type const& v)
|
||||||
: feature_(f),
|
: feature_(f)
|
||||||
vars_(v) {}
|
, vars_(v)
|
||||||
|
{}
|
||||||
|
|
||||||
value_type operator() (value_integer val) const
|
value_type operator()(value_integer val) const { return val; }
|
||||||
{
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
value_type operator() (value_double val) const
|
value_type operator()(value_double val) const { return val; }
|
||||||
{
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
value_type operator() (value_bool val) const
|
value_type operator()(value_bool val) const { return val; }
|
||||||
{
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
value_type operator() (value_null val) const
|
value_type operator()(value_null val) const { return val; }
|
||||||
{
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
value_type operator() (value_unicode_string const& str) const
|
value_type operator()(value_unicode_string const& str) const { return str; }
|
||||||
{
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
value_type operator() (attribute const& attr) const
|
value_type operator()(attribute const& attr) const { return attr.value<value_type, feature_type>(feature_); }
|
||||||
{
|
|
||||||
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);
|
auto itr = vars_.find(attr.name);
|
||||||
if (itr != vars_.end())
|
if (itr != vars_.end())
|
||||||
{
|
{
|
||||||
return itr->second;
|
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())
|
return (util::apply_visitor(*this, x.left).to_bool()) && (util::apply_visitor(*this, x.right).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())
|
return (util::apply_visitor(*this, x.left).to_bool()) || (util::apply_visitor(*this, x.right).to_bool());
|
||||||
|| (util::apply_visitor(*this, x.right).to_bool());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Tag>
|
template<typename Tag>
|
||||||
value_type operator() (binary_node<Tag> const& x) const
|
value_type operator()(binary_node<Tag> const& x) const
|
||||||
{
|
{
|
||||||
typename make_op<Tag>::type operation;
|
typename make_op<Tag>::type operation;
|
||||||
return operation(util::apply_visitor(*this, x.left),
|
return operation(util::apply_visitor(*this, x.left), util::apply_visitor(*this, x.right));
|
||||||
util::apply_visitor(*this, x.right));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Tag>
|
template<typename Tag>
|
||||||
value_type operator() (unary_node<Tag> const& x) const
|
value_type operator()(unary_node<Tag> const& x) const
|
||||||
{
|
{
|
||||||
typename make_op<Tag>::type func;
|
typename make_op<Tag>::type func;
|
||||||
return func(util::apply_visitor(*this, x.expr));
|
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);
|
value_type v = util::apply_visitor(*this, x.expr);
|
||||||
return x.apply(v);
|
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);
|
value_type v = util::apply_visitor(*this, x.expr);
|
||||||
return x.apply(v);
|
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);
|
value_type arg = util::apply_visitor(*this, call.arg);
|
||||||
return call.fun(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 arg1 = util::apply_visitor(*this, call.arg1);
|
||||||
value_type arg2 = util::apply_visitor(*this, call.arg2);
|
value_type arg2 = util::apply_visitor(*this, call.arg2);
|
||||||
|
@ -151,6 +130,6 @@ struct evaluate
|
||||||
variable_type const& vars_;
|
variable_type const& vars_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_EXPRESSION_EVALUATOR_HPP
|
#endif // MAPNIK_EXPRESSION_EVALUATOR_HPP
|
||||||
|
|
|
@ -31,7 +31,8 @@ MAPNIK_DISABLE_WARNING_PUSH
|
||||||
#include <boost/spirit/home/x3.hpp>
|
#include <boost/spirit/home/x3.hpp>
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
namespace mapnik { namespace grammar {
|
namespace mapnik {
|
||||||
|
namespace grammar {
|
||||||
|
|
||||||
#if BOOST_VERSION >= 106700
|
#if BOOST_VERSION >= 106700
|
||||||
using transcoder_type = mapnik::transcoder;
|
using transcoder_type = mapnik::transcoder;
|
||||||
|
@ -39,7 +40,6 @@ using transcoder_type = mapnik::transcoder;
|
||||||
using transcoder_type = std::reference_wrapper<mapnik::transcoder const>;
|
using transcoder_type = std::reference_wrapper<mapnik::transcoder const>;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace x3 = boost::spirit::x3;
|
namespace x3 = boost::spirit::x3;
|
||||||
struct transcoder_tag;
|
struct transcoder_tag;
|
||||||
struct expression_class; // top-most ID
|
struct expression_class; // top-most ID
|
||||||
|
@ -49,6 +49,7 @@ expression_grammar_type const expression("expression");
|
||||||
|
|
||||||
BOOST_SPIRIT_DECLARE(expression_grammar_type);
|
BOOST_SPIRIT_DECLARE(expression_grammar_type);
|
||||||
|
|
||||||
}}
|
} // namespace grammar
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_EXPRESSIONS_GRAMMAR_X3_HPP
|
#endif // MAPNIK_EXPRESSIONS_GRAMMAR_X3_HPP
|
||||||
|
|
|
@ -26,16 +26,16 @@
|
||||||
#include <mapnik/expression_grammar_x3.hpp>
|
#include <mapnik/expression_grammar_x3.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace mapnik { namespace grammar {
|
namespace mapnik {
|
||||||
|
namespace grammar {
|
||||||
|
|
||||||
namespace x3 = boost::spirit::x3;
|
namespace x3 = boost::spirit::x3;
|
||||||
using iterator_type = std::string::const_iterator;
|
using iterator_type = std::string::const_iterator;
|
||||||
using phrase_context_type = x3::phrase_parse_context<x3::ascii::space_type>::type;
|
using phrase_context_type = x3::phrase_parse_context<x3::ascii::space_type>::type;
|
||||||
// define combined context
|
// define combined context
|
||||||
using context_type = x3::context<transcoder_tag,
|
using context_type = x3::context<transcoder_tag, transcoder_type const, phrase_context_type>;
|
||||||
transcoder_type const,
|
|
||||||
phrase_context_type>;
|
|
||||||
|
|
||||||
}}
|
} // namespace grammar
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_EXPRESSIONS_GRAMMAR_X3_CONFIG_HPP
|
#endif // MAPNIK_EXPRESSIONS_GRAMMAR_X3_CONFIG_HPP
|
||||||
|
|
|
@ -24,299 +24,272 @@
|
||||||
#define MAPNIK_EXPRESSIONS_GRAMMAR_X3_DEF_HPP
|
#define MAPNIK_EXPRESSIONS_GRAMMAR_X3_DEF_HPP
|
||||||
|
|
||||||
#include <mapnik/expression_grammar_x3.hpp>
|
#include <mapnik/expression_grammar_x3.hpp>
|
||||||
#include <mapnik/json/unicode_string_grammar_x3_def.hpp>
|
|
||||||
#include <mapnik/expression_node.hpp>
|
#include <mapnik/expression_node.hpp>
|
||||||
#include <mapnik/function_call.hpp>
|
#include <mapnik/function_call.hpp>
|
||||||
|
#include <mapnik/json/unicode_string_grammar_x3_def.hpp>
|
||||||
#include <mapnik/unicode.hpp>
|
#include <mapnik/unicode.hpp>
|
||||||
|
|
||||||
#include <mapnik/warning.hpp>
|
#include <mapnik/warning.hpp>
|
||||||
MAPNIK_DISABLE_WARNING_PUSH
|
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/adapt_struct.hpp>
|
||||||
#include <boost/fusion/include/std_pair.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
|
MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
BOOST_FUSION_ADAPT_STRUCT(mapnik::unary_function_call,
|
BOOST_FUSION_ADAPT_STRUCT(mapnik::unary_function_call,
|
||||||
(mapnik::unary_function_impl, fun)
|
(mapnik::unary_function_impl, fun)(mapnik::unary_function_call::argument_type, arg))
|
||||||
(mapnik::unary_function_call::argument_type, arg))
|
|
||||||
|
|
||||||
BOOST_FUSION_ADAPT_STRUCT(mapnik::binary_function_call,
|
BOOST_FUSION_ADAPT_STRUCT(mapnik::binary_function_call,
|
||||||
(mapnik::binary_function_impl, fun)
|
(mapnik::binary_function_impl, fun)(mapnik::binary_function_call::argument_type,
|
||||||
(mapnik::binary_function_call::argument_type, arg1)
|
arg1)(mapnik::binary_function_call::argument_type, arg2))
|
||||||
(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 {
|
||||||
namespace ascii = boost::spirit::x3::ascii;
|
auto const& escaped_unicode = json::grammar::escaped_unicode;
|
||||||
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 {
|
template<typename Context>
|
||||||
auto const& escaped_unicode = json::grammar::escaped_unicode;
|
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());
|
||||||
}
|
}
|
||||||
|
else
|
||||||
template <typename Context>
|
|
||||||
inline mapnik::transcoder const& extract_transcoder(Context const& ctx)
|
|
||||||
{
|
{
|
||||||
return x3::get<transcoder_tag>(ctx);
|
_val(ctx) = std::move(attribute(attr));
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
auto append = [](auto const& ctx)
|
auto do_global_attribute = [](auto const& ctx) {
|
||||||
{
|
_val(ctx) = std::move(global_attribute(_attr(ctx)));
|
||||||
_val(ctx) += _attr(ctx);
|
};
|
||||||
};
|
|
||||||
|
|
||||||
auto do_assign = [] (auto const& 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))));
|
||||||
_val(ctx) = std::move(_attr(ctx));
|
};
|
||||||
};
|
|
||||||
|
|
||||||
auto do_negate = [] (auto const& 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))));
|
||||||
_val(ctx) = std::move(unary_node<mapnik::tags::negate>(_attr(ctx)));
|
};
|
||||||
};
|
|
||||||
|
|
||||||
auto do_attribute = [] (auto const& ctx)
|
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 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_global_attribute = [] (auto const& 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))));
|
||||||
_val(ctx) = std::move(global_attribute(_attr(ctx)));
|
};
|
||||||
};
|
|
||||||
|
|
||||||
auto do_add = [] (auto const& 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))));
|
||||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::plus>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
};
|
||||||
};
|
|
||||||
|
|
||||||
auto do_subt = [] (auto const& ctx)
|
auto do_unicode = [](auto const& ctx) {
|
||||||
{
|
auto const& tr = extract_transcoder(ctx);
|
||||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::minus>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
_val(ctx) = std::move(tr.transcode(_attr(ctx).c_str()));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto do_mult = [] (auto const& ctx)
|
auto do_null = [](auto const& ctx) {
|
||||||
{
|
_val(ctx) = std::move(mapnik::value_null());
|
||||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::mult>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
};
|
||||||
};
|
|
||||||
|
|
||||||
auto do_div = [] (auto const& ctx)
|
auto do_not = [](auto const& ctx) {
|
||||||
{
|
mapnik::unary_node<mapnik::tags::logical_not> node(_attr(ctx));
|
||||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::div>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
_val(ctx) = std::move(node);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto do_mod = [] (auto const& 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))));
|
||||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::mod>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
};
|
||||||
};
|
|
||||||
|
|
||||||
auto do_unicode = [] (auto const& 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 const& tr = extract_transcoder(ctx);
|
};
|
||||||
_val(ctx) = std::move(tr.transcode(_attr(ctx).c_str()));
|
|
||||||
};
|
|
||||||
|
|
||||||
auto do_null = [] (auto const& 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))));
|
||||||
_val(ctx) = std::move(mapnik::value_null());
|
};
|
||||||
};
|
|
||||||
|
|
||||||
auto do_not = [] (auto const& 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))));
|
||||||
mapnik::unary_node<mapnik::tags::logical_not> node(_attr(ctx));
|
};
|
||||||
_val(ctx) = std::move(node);
|
|
||||||
};
|
|
||||||
|
|
||||||
auto do_and = [] (auto const& 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))));
|
||||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::logical_and>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
};
|
||||||
};
|
|
||||||
|
|
||||||
auto do_or = [] (auto const& 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))));
|
||||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::logical_or>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
};
|
||||||
};
|
|
||||||
|
|
||||||
auto do_equal = [] (auto const& 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))));
|
||||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::equal_to>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
};
|
||||||
};
|
|
||||||
|
|
||||||
auto do_not_equal = [] (auto const& ctx)
|
auto do_greater_equal = [](auto const& ctx) {
|
||||||
{
|
_val(ctx) =
|
||||||
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::not_equal_to>(std::move(_val(ctx)), std::move(_attr(ctx))));
|
std::move(mapnik::binary_node<mapnik::tags::greater_equal>(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))));
|
|
||||||
};
|
|
||||||
|
|
||||||
// regex
|
// regex
|
||||||
auto do_regex_match = [] (auto const& ctx)
|
auto do_regex_match = [](auto const& ctx) {
|
||||||
{
|
auto const& tr = extract_transcoder(ctx);
|
||||||
auto const& tr = extract_transcoder(ctx);
|
_val(ctx) = std::move(mapnik::regex_match_node(tr, std::move(_val(ctx)), std::move(_attr(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 do_regex_replace = [](auto const& ctx) {
|
||||||
{
|
auto const& tr = extract_transcoder(ctx);
|
||||||
auto const& tr = extract_transcoder(ctx);
|
auto const& pair = _attr(ctx);
|
||||||
auto const& pair = _attr(ctx);
|
auto const& pattern = std::get<0>(pair);
|
||||||
auto const& pattern = std::get<0>(pair);
|
auto const& format = std::get<1>(pair);
|
||||||
auto const& format = std::get<1>(pair);
|
_val(ctx) = mapnik::regex_replace_node(tr, _val(ctx), pattern, format);
|
||||||
_val(ctx) = mapnik::regex_replace_node(tr, _val(ctx) , pattern, format);
|
};
|
||||||
};
|
|
||||||
|
|
||||||
// mapnik::value_integer
|
// 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
|
// 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
|
// mapnik::value_bool
|
||||||
struct boolean_ : x3::symbols<mapnik::value_bool>
|
struct boolean_ : x3::symbols<mapnik::value_bool>
|
||||||
|
{
|
||||||
|
boolean_()
|
||||||
{
|
{
|
||||||
boolean_()
|
add("true", true) //
|
||||||
{
|
("false", false) //
|
||||||
add
|
;
|
||||||
("true", true)
|
}
|
||||||
("false", false)
|
} boolean;
|
||||||
;
|
|
||||||
}
|
|
||||||
} 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) //
|
||||||
add
|
("rad_to_deg", 57.295779513082320876798154814105) //
|
||||||
("pi", 3.1415926535897932384626433832795)
|
;
|
||||||
("deg_to_rad",0.017453292519943295769236907684886)
|
}
|
||||||
("rad_to_deg",57.295779513082320876798154814105)
|
} float_const;
|
||||||
;
|
|
||||||
}
|
|
||||||
} float_const;
|
|
||||||
|
|
||||||
// unary functions
|
// 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()) //
|
||||||
add
|
("tan", tan_impl()) //
|
||||||
("sin", sin_impl())
|
("atan", atan_impl()) //
|
||||||
("cos", cos_impl())
|
("exp", exp_impl()) //
|
||||||
("tan", tan_impl())
|
("log", log_impl()) //
|
||||||
("atan", atan_impl())
|
("abs", abs_impl()) //
|
||||||
("exp", exp_impl())
|
("length", length_impl()) //
|
||||||
("log", log_impl())
|
;
|
||||||
("abs", abs_impl())
|
}
|
||||||
("length",length_impl())
|
} unary_func_types;
|
||||||
;
|
|
||||||
}
|
|
||||||
} unary_func_types ;
|
|
||||||
|
|
||||||
|
|
||||||
// binary functions
|
// 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)) //
|
||||||
add
|
("pow", binary_function_impl(pow_impl)) //
|
||||||
("min", binary_function_impl(min_impl))
|
;
|
||||||
("max", binary_function_impl(max_impl))
|
}
|
||||||
("pow", binary_function_impl(pow_impl))
|
} binary_func_types;
|
||||||
;
|
|
||||||
}
|
|
||||||
} binary_func_types;
|
|
||||||
|
|
||||||
// geometry 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) //
|
||||||
add
|
("polygon", 3) //
|
||||||
("point", 1)
|
("collection", 4) //
|
||||||
("linestring", 2)
|
;
|
||||||
("polygon",3)
|
}
|
||||||
("collection",4)
|
} geometry_type;
|
||||||
;
|
|
||||||
}
|
|
||||||
} geometry_type;
|
|
||||||
|
|
||||||
struct unesc_chars_ : x3::symbols<char>
|
struct unesc_chars_ : x3::symbols<char>
|
||||||
|
{
|
||||||
|
unesc_chars_()
|
||||||
{
|
{
|
||||||
unesc_chars_()
|
add("\\a", '\a') //
|
||||||
{
|
("\\b", '\b') //
|
||||||
add
|
("\\f", '\f') //
|
||||||
("\\a", '\a')
|
("\\n", '\n') //
|
||||||
("\\b", '\b')
|
("\\r", '\r') //
|
||||||
("\\f", '\f')
|
("\\t", '\t') //
|
||||||
("\\n", '\n')
|
("\\v", '\v') //
|
||||||
("\\r", '\r')
|
("\\\\", '\\') //
|
||||||
("\\t", '\t')
|
("\\\'", '\'') //
|
||||||
("\\v", '\v')
|
("\\\"", '\"') //
|
||||||
("\\\\", '\\')
|
;
|
||||||
("\\\'", '\'')
|
}
|
||||||
("\\\"", '\"')
|
} unesc_char;
|
||||||
;
|
|
||||||
}
|
|
||||||
} 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");
|
|
||||||
|
|
||||||
|
// 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
|
// strings
|
||||||
auto const single_quoted_string = x3::rule<class single_quoted_string, std::string> {} = lit('\'')
|
auto const single_quoted_string = x3::rule<class single_quoted_string, std::string> {} = lit('\'')
|
||||||
>> no_skip[*(unesc_char[append]
|
>> no_skip[*(unesc_char[append]
|
||||||
|
@ -431,24 +404,23 @@ namespace mapnik { namespace grammar {
|
||||||
unquoted_ustring[do_unicode]
|
unquoted_ustring[do_unicode]
|
||||||
// ^ https://github.com/mapnik/mapnik/pull/3389
|
// ^ 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 (
|
} // namespace grammar
|
||||||
expression,
|
} // namespace mapnik
|
||||||
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
|
|
||||||
);
|
|
||||||
|
|
||||||
}}
|
#endif // MAPNIK_EXPRESSIONS_GRAMMAR_X3_DEF_HPP
|
||||||
|
|
||||||
#endif // MAPNIK_EXPRESSIONS_GRAMMAR_X3_DEF_HPP
|
|
||||||
|
|
|
@ -34,61 +34,119 @@
|
||||||
// stl
|
// stl
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
|
|
||||||
using value_type = mapnik::value;
|
using value_type = mapnik::value;
|
||||||
|
|
||||||
template <typename Tag> struct make_op;
|
template<typename Tag>
|
||||||
template <> struct make_op<mapnik::tags::negate> { using type = std::negate<value_type>;};
|
struct make_op;
|
||||||
template <> struct make_op<mapnik::tags::plus> { using type = std::plus<value_type>;};
|
template<>
|
||||||
template <> struct make_op<mapnik::tags::minus> { using type = std::minus<value_type>;};
|
struct make_op<mapnik::tags::negate>
|
||||||
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>;};
|
using type = std::negate<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<>
|
||||||
template <> struct make_op<mapnik::tags::less_equal> { using type = std::less_equal<value_type>;};
|
struct make_op<mapnik::tags::plus>
|
||||||
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>;};
|
using type = std::plus<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<>
|
||||||
template <> struct make_op<mapnik::tags::logical_not> { using type = std::logical_not<value_type>;};
|
struct make_op<mapnik::tags::minus>
|
||||||
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>;};
|
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
|
struct unary_node
|
||||||
{
|
{
|
||||||
unary_node (expr_node && a)
|
unary_node(expr_node&& a)
|
||||||
: expr(std::move(a)) {}
|
: expr(std::move(a))
|
||||||
|
{}
|
||||||
|
|
||||||
unary_node (expr_node const& a)
|
unary_node(expr_node const& a)
|
||||||
: expr(a) {}
|
: expr(a)
|
||||||
|
{}
|
||||||
|
|
||||||
static const char* type()
|
static const char* type() { return Tag::str(); }
|
||||||
{
|
|
||||||
return Tag::str();
|
|
||||||
}
|
|
||||||
|
|
||||||
expr_node expr;
|
expr_node expr;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Tag>
|
template<typename Tag>
|
||||||
struct binary_node
|
struct binary_node
|
||||||
{
|
{
|
||||||
binary_node(expr_node && a, expr_node && b)
|
binary_node(expr_node&& a, expr_node&& b)
|
||||||
: left(std::move(a)),
|
: left(std::move(a))
|
||||||
right(std::move(b)) {}
|
, right(std::move(b))
|
||||||
|
{}
|
||||||
|
|
||||||
binary_node(expr_node const& a, expr_node const& b)
|
binary_node(expr_node const& a, expr_node const& b)
|
||||||
: left(a),
|
: left(a)
|
||||||
right(b) {}
|
, right(b)
|
||||||
|
{}
|
||||||
|
|
||||||
static const char* type()
|
static const char* type() { return Tag::str(); }
|
||||||
{
|
expr_node left, right;
|
||||||
return Tag::str();
|
|
||||||
}
|
|
||||||
expr_node left,right;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct unary_function_call
|
struct unary_function_call
|
||||||
|
@ -96,7 +154,9 @@ struct unary_function_call
|
||||||
using argument_type = expr_node;
|
using argument_type = expr_node;
|
||||||
unary_function_call() = default;
|
unary_function_call() = default;
|
||||||
unary_function_call(unary_function_impl _fun, argument_type const& _arg)
|
unary_function_call(unary_function_impl _fun, argument_type const& _arg)
|
||||||
: fun(_fun), arg(_arg) {}
|
: fun(_fun)
|
||||||
|
, arg(_arg)
|
||||||
|
{}
|
||||||
|
|
||||||
unary_function_impl fun;
|
unary_function_impl fun;
|
||||||
argument_type arg;
|
argument_type arg;
|
||||||
|
@ -107,7 +167,10 @@ struct binary_function_call
|
||||||
using argument_type = expr_node;
|
using argument_type = expr_node;
|
||||||
binary_function_call() = default;
|
binary_function_call() = default;
|
||||||
binary_function_call(binary_function_impl _fun, argument_type const& _arg1, argument_type const& _arg2)
|
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;
|
binary_function_impl fun;
|
||||||
argument_type arg1;
|
argument_type arg1;
|
||||||
argument_type arg2;
|
argument_type arg2;
|
||||||
|
@ -137,7 +200,6 @@ struct MAPNIK_DECL regex_replace_node
|
||||||
std::shared_ptr<_regex_replace_impl> impl_;
|
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/value/types.hpp>
|
||||||
#include <mapnik/util/variant.hpp>
|
#include <mapnik/util/variant.hpp>
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
|
|
||||||
namespace tags {
|
namespace tags {
|
||||||
struct negate
|
struct negate
|
||||||
{
|
{
|
||||||
static const char* str()
|
static const char* str() { return "-"; }
|
||||||
{
|
|
||||||
return "-";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct plus
|
struct plus
|
||||||
{
|
{
|
||||||
static const char* str()
|
static const char* str() { return "+"; }
|
||||||
{
|
|
||||||
return "+";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct minus
|
struct minus
|
||||||
{
|
{
|
||||||
static const char* str()
|
static const char* str() { return "-"; }
|
||||||
{
|
|
||||||
return "-";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mult
|
struct mult
|
||||||
{
|
{
|
||||||
static const char* str()
|
static const char* str() { return "*"; }
|
||||||
{
|
|
||||||
return "*";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct div
|
struct div
|
||||||
{
|
{
|
||||||
static const char* str()
|
static const char* str() { return "/"; }
|
||||||
{
|
|
||||||
return "/";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct mod
|
||||||
struct mod
|
|
||||||
{
|
{
|
||||||
static const char* str()
|
static const char* str() { return "%"; }
|
||||||
{
|
|
||||||
return "%";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct less
|
struct less
|
||||||
{
|
{
|
||||||
static const char* str()
|
static const char* str() { return "<"; }
|
||||||
{
|
|
||||||
return "<";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct less_equal
|
struct less_equal
|
||||||
{
|
{
|
||||||
static const char* str()
|
static const char* str() { return "<="; }
|
||||||
{
|
|
||||||
return "<=";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct greater
|
struct greater
|
||||||
{
|
{
|
||||||
static const char* str()
|
static const char* str() { return ">"; }
|
||||||
{
|
|
||||||
return ">";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct greater_equal
|
struct greater_equal
|
||||||
{
|
{
|
||||||
static const char* str()
|
static const char* str() { return ">="; }
|
||||||
{
|
|
||||||
return ">=";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct equal_to
|
struct equal_to
|
||||||
{
|
{
|
||||||
static const char* str()
|
static const char* str() { return "="; }
|
||||||
{
|
|
||||||
return "=";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct not_equal_to
|
struct not_equal_to
|
||||||
{
|
{
|
||||||
static const char* str()
|
static const char* str() { return "!="; }
|
||||||
{
|
|
||||||
return "!=";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct logical_not
|
struct logical_not
|
||||||
{
|
{
|
||||||
static const char* str()
|
static const char* str() { return "not "; }
|
||||||
{
|
|
||||||
return "not ";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct logical_and
|
struct logical_and
|
||||||
{
|
{
|
||||||
static const char* str()
|
static const char* str() { return " and "; }
|
||||||
{
|
|
||||||
return " and ";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct logical_or
|
struct logical_or
|
||||||
{
|
{
|
||||||
static const char* str()
|
static const char* str() { return " or "; }
|
||||||
{
|
|
||||||
return " or ";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end operation tags
|
} // namespace tags
|
||||||
|
|
||||||
|
template<typename Tag>
|
||||||
template <typename Tag> struct binary_node;
|
struct binary_node;
|
||||||
template <typename Tag> struct unary_node;
|
template<typename Tag>
|
||||||
|
struct unary_node;
|
||||||
struct regex_match_node;
|
struct regex_match_node;
|
||||||
struct regex_replace_node;
|
struct regex_replace_node;
|
||||||
struct attribute;
|
struct attribute;
|
||||||
|
@ -166,37 +120,34 @@ struct geometry_type_attribute;
|
||||||
struct unary_function_call;
|
struct unary_function_call;
|
||||||
struct binary_function_call;
|
struct binary_function_call;
|
||||||
|
|
||||||
using expr_node = util::variant<
|
using expr_node = util::variant<value_null,
|
||||||
value_null,
|
value_bool,
|
||||||
value_bool,
|
value_integer,
|
||||||
value_integer,
|
value_double,
|
||||||
value_double,
|
value_unicode_string,
|
||||||
value_unicode_string,
|
attribute,
|
||||||
attribute,
|
global_attribute,
|
||||||
global_attribute,
|
geometry_type_attribute,
|
||||||
geometry_type_attribute,
|
util::recursive_wrapper<unary_node<mapnik::tags::negate>>,
|
||||||
util::recursive_wrapper<unary_node<mapnik::tags::negate> >,
|
util::recursive_wrapper<binary_node<mapnik::tags::plus>>,
|
||||||
util::recursive_wrapper<binary_node<mapnik::tags::plus> >,
|
util::recursive_wrapper<binary_node<mapnik::tags::minus>>,
|
||||||
util::recursive_wrapper<binary_node<mapnik::tags::minus> >,
|
util::recursive_wrapper<binary_node<mapnik::tags::mult>>,
|
||||||
util::recursive_wrapper<binary_node<mapnik::tags::mult> >,
|
util::recursive_wrapper<binary_node<mapnik::tags::div>>,
|
||||||
util::recursive_wrapper<binary_node<mapnik::tags::div> >,
|
util::recursive_wrapper<binary_node<mapnik::tags::mod>>,
|
||||||
util::recursive_wrapper<binary_node<mapnik::tags::mod> >,
|
util::recursive_wrapper<binary_node<mapnik::tags::less>>,
|
||||||
util::recursive_wrapper<binary_node<mapnik::tags::less> >,
|
util::recursive_wrapper<binary_node<mapnik::tags::less_equal>>,
|
||||||
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> >,
|
util::recursive_wrapper<binary_node<mapnik::tags::greater_equal>>,
|
||||||
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::equal_to> >,
|
util::recursive_wrapper<binary_node<mapnik::tags::not_equal_to>>,
|
||||||
util::recursive_wrapper<binary_node<mapnik::tags::not_equal_to> >,
|
util::recursive_wrapper<unary_node<mapnik::tags::logical_not>>,
|
||||||
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_and> >,
|
util::recursive_wrapper<binary_node<mapnik::tags::logical_or>>,
|
||||||
util::recursive_wrapper<binary_node<mapnik::tags::logical_or> >,
|
util::recursive_wrapper<regex_match_node>,
|
||||||
util::recursive_wrapper<regex_match_node>,
|
util::recursive_wrapper<regex_replace_node>,
|
||||||
util::recursive_wrapper<regex_replace_node>,
|
util::recursive_wrapper<unary_function_call>,
|
||||||
util::recursive_wrapper<unary_function_call>,
|
util::recursive_wrapper<binary_function_call>>;
|
||||||
util::recursive_wrapper<binary_function_call>
|
|
||||||
>;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_EXPRESSION_NODE_HPP
|
#endif // MAPNIK_EXPRESSION_NODE_HPP
|
||||||
|
|
|
@ -35,8 +35,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
MAPNIK_DECL std::string to_expression_string(expr_node const& node);
|
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".
|
would yield "true".
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
std::string to_expression_string(T const* expr_node_ptr)
|
std::string to_expression_string(T const* expr_node_ptr)
|
||||||
{
|
{
|
||||||
throw std::logic_error("to_expression_string() called with pointer argument");
|
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
|
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)
|
std::string to_expression_string(std::shared_ptr<T> const& expr_node_ptr)
|
||||||
{
|
{
|
||||||
throw std::logic_error("to_expression_string() called with pointer argument");
|
throw std::logic_error("to_expression_string() called with pointer argument");
|
||||||
// compile error intended here; comment on the next line shows in clang output
|
// compile error intended here; comment on the next line shows in clang output
|
||||||
return expr_node_ptr; // to_expression_string() called with pointer argument
|
return expr_node_ptr; // to_expression_string() called with pointer argument
|
||||||
}
|
}
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_EXPRESSION_STRING_HPP
|
#endif // MAPNIK_EXPRESSION_STRING_HPP
|
||||||
|
|
|
@ -38,108 +38,122 @@ MAPNIK_DISABLE_WARNING_POP
|
||||||
// stl
|
// stl
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
|
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
|
|
||||||
namespace msm = boost::msm;
|
namespace msm = boost::msm;
|
||||||
namespace mpl = boost::mpl;
|
namespace mpl = boost::mpl;
|
||||||
using namespace msm::front;
|
using namespace msm::front;
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
T extend(T const & v1, T const & v2, double length)
|
T extend(T const& v1, T const& v2, double length)
|
||||||
{
|
{
|
||||||
double dx = v2.x - v1.x;
|
double dx = v2.x - v1.x;
|
||||||
double dy = v2.y - v1.y;
|
double dy = v2.y - v1.y;
|
||||||
double l12 = std::sqrt(dx * dx + dy * dy);
|
double l12 = std::sqrt(dx * dx + dy * dy);
|
||||||
double coef = 1.0 + length / l12;
|
double coef = 1.0 + length / l12;
|
||||||
return vertex2d(v1.x + dx * coef,
|
return vertex2d(v1.x + dx * coef, v1.y + dy * coef, v2.cmd);
|
||||||
v1.y + dy * coef, v2.cmd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace events
|
namespace events {
|
||||||
|
struct vertex_event
|
||||||
{
|
{
|
||||||
struct vertex_event
|
vertex_event(vertex2d const& vertex)
|
||||||
{
|
: vertex(vertex)
|
||||||
vertex_event(vertex2d const & vertex) : vertex(vertex) { }
|
{}
|
||||||
vertex2d const & vertex;
|
vertex2d const& vertex;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct move_to : vertex_event { using vertex_event::vertex_event; };
|
struct move_to : 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 store
|
using vertex_event::vertex_event;
|
||||||
{
|
};
|
||||||
template <class FSM, class EVT, class SourceState, class TargetState>
|
struct line_to : vertex_event
|
||||||
void operator()(EVT const & e, FSM & m, SourceState&, TargetState&)
|
{
|
||||||
{
|
using vertex_event::vertex_event;
|
||||||
m.v2 = m.v1;
|
};
|
||||||
m.v1 = e.vertex;
|
struct close : vertex_event
|
||||||
m.output = boost::none;
|
{
|
||||||
}
|
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>
|
m.v2 = m.v1;
|
||||||
void operator()(EVT const & e, FSM & m, SourceState&, TargetState&)
|
m.v1 = e.vertex;
|
||||||
{
|
m.output = boost::none;
|
||||||
m.output = e.vertex;
|
}
|
||||||
}
|
};
|
||||||
};
|
|
||||||
|
|
||||||
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>
|
m.output = e.vertex;
|
||||||
void operator()(EVT const & e, FSM & m, SourceState&, TargetState&)
|
}
|
||||||
{
|
};
|
||||||
m.v2 = m.v1;
|
|
||||||
m.v1 = e.vertex;
|
|
||||||
m.output = m.v2;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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>
|
m.v2 = m.v1;
|
||||||
void operator()(EVT const & e, FSM & m, SourceState&, TargetState&)
|
m.v1 = e.vertex;
|
||||||
{
|
m.output = m.v2;
|
||||||
m.v2 = m.v1;
|
}
|
||||||
m.v1 = e.vertex;
|
};
|
||||||
m.output = extend(m.v1, m.v2, m.extend_length);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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>
|
m.v2 = m.v1;
|
||||||
void operator()(EVT const & e, FSM & m, SourceState&, TargetState&)
|
m.v1 = e.vertex;
|
||||||
{
|
m.output = extend(m.v1, m.v2, m.extend_length);
|
||||||
m.output = extend(m.v2, m.v1, m.extend_length);
|
}
|
||||||
m.v1 = e.vertex;
|
};
|
||||||
}
|
|
||||||
};
|
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>
|
struct extender_def : public msm::front::state_machine_def<extender_def>
|
||||||
{
|
{
|
||||||
using no_exception_thrown = int;
|
using no_exception_thrown = int;
|
||||||
using no_message_queue = int;
|
using no_message_queue = int;
|
||||||
|
|
||||||
struct initial : 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 vertex_one : public msm::front::state<>
|
||||||
struct end : public msm::front::state<> { };
|
{};
|
||||||
|
struct vertex_two : public msm::front::state<>
|
||||||
|
{};
|
||||||
|
struct end : public msm::front::state<>
|
||||||
|
{};
|
||||||
|
|
||||||
using initial_state = initial;
|
using initial_state = initial;
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
struct transition_table : mpl::vector<
|
struct transition_table : mpl::vector<
|
||||||
// Start Event Next Action Guard
|
// 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 < vertex_two , events::end , end , actions::output_end >,
|
||||||
Row < end , events::end , end , actions::output >
|
Row < end , events::end , end , actions::output >
|
||||||
> {};
|
> {};
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
extender_def(double extend_length)
|
extender_def(double extend_length)
|
||||||
: extend_length(extend_length)
|
: extend_length(extend_length)
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
boost::optional<vertex2d> output;
|
boost::optional<vertex2d> output;
|
||||||
vertex2d v1, v2;
|
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>;
|
using extender = msm::back::state_machine<extender_def>;
|
||||||
|
|
||||||
}
|
} // namespace detail
|
||||||
|
|
||||||
template <typename Geometry>
|
template<typename Geometry>
|
||||||
struct extend_converter
|
struct extend_converter
|
||||||
{
|
{
|
||||||
extend_converter(Geometry & geom)
|
extend_converter(Geometry& geom)
|
||||||
: extend_converter(geom, 0)
|
: extend_converter(geom, 0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
extend_converter(Geometry & geom, double extend)
|
extend_converter(Geometry& geom, double extend)
|
||||||
: geom_(geom), extender_(extend)
|
: geom_(geom)
|
||||||
|
, extender_(extend)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void set_extend(double extend)
|
void set_extend(double extend) { extender_.extend_length = extend; }
|
||||||
{
|
|
||||||
extender_.extend_length = extend;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned vertex(double * x, double * y)
|
unsigned vertex(double* x, double* y)
|
||||||
{
|
{
|
||||||
using namespace detail;
|
using namespace detail;
|
||||||
vertex2d v;
|
vertex2d v;
|
||||||
|
@ -210,9 +222,9 @@ struct extend_converter
|
||||||
extender_.process_event(events::end(v));
|
extender_.process_event(events::end(v));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while(!extender_.output);
|
} while (!extender_.output);
|
||||||
|
|
||||||
vertex2d const & output = *extender_.output;
|
vertex2d const& output = *extender_.output;
|
||||||
*x = output.x;
|
*x = output.x;
|
||||||
*y = output.y;
|
*y = output.y;
|
||||||
return output.cmd;
|
return output.cmd;
|
||||||
|
@ -224,11 +236,11 @@ struct extend_converter
|
||||||
extender_.start();
|
extender_.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Geometry & geom_;
|
Geometry& geom_;
|
||||||
detail::extender extender_;
|
detail::extender extender_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_EXTEND_CONVERTER_HPP
|
#endif // MAPNIK_EXTEND_CONVERTER_HPP
|
||||||
|
|
|
@ -32,41 +32,33 @@
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
template
|
template<typename product_type, typename key_type, typename... Args>
|
||||||
<
|
class factory : public singleton<factory<product_type, key_type, Args...>>
|
||||||
typename product_type,
|
|
||||||
typename key_type,
|
|
||||||
typename ...Args >
|
|
||||||
class factory : public singleton<factory <product_type,
|
|
||||||
key_type,
|
|
||||||
Args...> >
|
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
using product_creator = product_type* (*) (Args...);
|
using product_creator = product_type* (*)(Args...);
|
||||||
using product_map = std::map<key_type,product_creator>;
|
using product_map = std::map<key_type, product_creator>;
|
||||||
product_map map_;
|
product_map map_;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
|
|
||||||
bool register_product(key_type const& key, product_creator creator)
|
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)
|
bool unregister_product(const key_type& key) { return map_.erase(key) == 1; }
|
||||||
{
|
|
||||||
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);
|
typename product_map::const_iterator pos = map_.find(key);
|
||||||
if (pos!=map_.end())
|
if (pos != map_.end())
|
||||||
{
|
{
|
||||||
return (pos->second)(args...);
|
return (pos->second)(args...);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_FACTORY_HPP
|
#endif // MAPNIK_FACTORY_HPP
|
||||||
|
|
|
@ -38,9 +38,9 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <ostream> // for basic_ostream, operator<<, etc
|
#include <ostream> // for basic_ostream, operator<<, etc
|
||||||
#include <sstream> // for basic_stringstream
|
#include <sstream> // for basic_stringstream
|
||||||
#include <stdexcept> // for out_of_range
|
#include <stdexcept> // for out_of_range
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
@ -50,12 +50,13 @@ class feature_impl;
|
||||||
|
|
||||||
using raster_ptr = std::shared_ptr<raster>;
|
using raster_ptr = std::shared_ptr<raster>;
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
class context : private util::noncopyable
|
class context : private util::noncopyable
|
||||||
|
|
||||||
{
|
{
|
||||||
friend class feature_impl;
|
friend class feature_impl;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
using map_type = T;
|
using map_type = T;
|
||||||
using value_type = typename map_type::value_type;
|
using value_type = typename map_type::value_type;
|
||||||
using key_type = typename map_type::key_type;
|
using key_type = typename map_type::key_type;
|
||||||
|
@ -65,7 +66,8 @@ public:
|
||||||
using const_iterator = typename map_type::const_iterator;
|
using const_iterator = typename map_type::const_iterator;
|
||||||
|
|
||||||
context()
|
context()
|
||||||
: mapping_() {}
|
: mapping_()
|
||||||
|
{}
|
||||||
|
|
||||||
inline size_type push(key_type const& name)
|
inline size_type push(key_type const& name)
|
||||||
{
|
{
|
||||||
|
@ -74,20 +76,17 @@ public:
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void add(key_type const& name, size_type index)
|
inline void add(key_type const& name, size_type index) { mapping_.emplace(name, index); }
|
||||||
{
|
|
||||||
mapping_.emplace(name, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline size_type size() const { return mapping_.size(); }
|
inline size_type size() const { return mapping_.size(); }
|
||||||
inline const_iterator begin() const { return mapping_.begin();}
|
inline const_iterator begin() const { return mapping_.begin(); }
|
||||||
inline const_iterator end() const { return mapping_.end();}
|
inline const_iterator end() const { return mapping_.end(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
map_type mapping_;
|
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>;
|
using context_ptr = std::shared_ptr<context_type>;
|
||||||
|
|
||||||
static const value default_feature_value{};
|
static const value default_feature_value{};
|
||||||
|
@ -95,38 +94,39 @@ static const value default_feature_value{};
|
||||||
class MAPNIK_DECL feature_impl : private util::noncopyable
|
class MAPNIK_DECL feature_impl : private util::noncopyable
|
||||||
{
|
{
|
||||||
friend class feature_kv_iterator;
|
friend class feature_kv_iterator;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
|
|
||||||
using value_type = mapnik::value;
|
using value_type = mapnik::value;
|
||||||
using cont_type = std::vector<value_type>;
|
using cont_type = std::vector<value_type>;
|
||||||
using iterator = feature_kv_iterator;
|
using iterator = feature_kv_iterator;
|
||||||
|
|
||||||
feature_impl(context_ptr const& ctx, mapnik::value_integer _id)
|
feature_impl(context_ptr const& ctx, mapnik::value_integer _id)
|
||||||
: id_(_id),
|
: id_(_id)
|
||||||
ctx_(ctx),
|
, ctx_(ctx)
|
||||||
data_(ctx_->mapping_.size()),
|
, data_(ctx_->mapping_.size())
|
||||||
geom_(geometry::geometry_empty()),
|
, geom_(geometry::geometry_empty())
|
||||||
raster_() {}
|
, raster_()
|
||||||
|
{}
|
||||||
|
|
||||||
inline mapnik::value_integer id() const { return id_;}
|
inline mapnik::value_integer id() const { return id_; }
|
||||||
inline void set_id(mapnik::value_integer _id) { id_ = _id;}
|
inline void set_id(mapnik::value_integer _id) { id_ = _id; }
|
||||||
template <typename T>
|
template<typename T>
|
||||||
inline void put(context_type::key_type const& key, T const& val)
|
inline void put(context_type::key_type const& key, T const& val)
|
||||||
{
|
{
|
||||||
put(key, value(val));
|
put(key, value(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
inline void put_new(context_type::key_type const& key, T const& val)
|
inline void put_new(context_type::key_type const& key, T const& val)
|
||||||
{
|
{
|
||||||
put_new(key, value(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);
|
context_type::map_type::const_iterator itr = ctx_->mapping_.find(key);
|
||||||
if (itr != ctx_->mapping_.end()
|
if (itr != ctx_->mapping_.end() && itr->second < data_.size())
|
||||||
&& itr->second < data_.size())
|
|
||||||
{
|
{
|
||||||
data_[itr->second] = std::move(val);
|
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);
|
context_type::map_type::const_iterator itr = ctx_->mapping_.find(key);
|
||||||
if (itr != ctx_->mapping_.end()
|
if (itr != ctx_->mapping_.end() && itr->second < data_.size())
|
||||||
&& itr->second < data_.size())
|
|
||||||
{
|
{
|
||||||
data_[itr->second] = std::move(val);
|
data_[itr->second] = std::move(val);
|
||||||
}
|
}
|
||||||
|
@ -152,10 +151,7 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool has_key(context_type::key_type const& key) const
|
inline bool has_key(context_type::key_type const& key) const { return (ctx_->mapping_.count(key) == 1); }
|
||||||
{
|
|
||||||
return (ctx_->mapping_.count(key) == 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline value_type const& get(context_type::key_type const& key) const
|
inline value_type const& get(context_type::key_type const& key) const
|
||||||
{
|
{
|
||||||
|
@ -173,70 +169,31 @@ public:
|
||||||
return default_feature_value;
|
return default_feature_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::size_t size() const
|
inline std::size_t size() const { return data_.size(); }
|
||||||
{
|
|
||||||
return data_.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline cont_type const& get_data() const
|
inline cont_type const& get_data() const { return data_; }
|
||||||
{
|
|
||||||
return data_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void set_data(cont_type const& data)
|
inline void set_data(cont_type const& data) { data_ = data; }
|
||||||
{
|
|
||||||
data_ = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline context_ptr context() const
|
inline context_ptr context() const { return ctx_; }
|
||||||
{
|
|
||||||
return ctx_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void set_geometry(geometry::geometry<double> && geom)
|
inline void set_geometry(geometry::geometry<double>&& geom) { geom_ = std::move(geom); }
|
||||||
{
|
|
||||||
geom_ = std::move(geom);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void set_geometry_copy(geometry::geometry<double> const& geom)
|
inline void set_geometry_copy(geometry::geometry<double> const& geom) { geom_ = geom; }
|
||||||
{
|
|
||||||
geom_ = geom;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline geometry::geometry<double> const& get_geometry() const
|
inline geometry::geometry<double> const& get_geometry() const { return geom_; }
|
||||||
{
|
|
||||||
return geom_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline geometry::geometry<double> & get_geometry()
|
inline geometry::geometry<double>& get_geometry() { return geom_; }
|
||||||
{
|
|
||||||
return geom_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline box2d<double> envelope() const
|
inline box2d<double> envelope() const { return mapnik::geometry::envelope(geom_); }
|
||||||
{
|
|
||||||
return mapnik::geometry::envelope(geom_);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline raster_ptr const& get_raster() const
|
inline raster_ptr const& get_raster() const { return raster_; }
|
||||||
{
|
|
||||||
return raster_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void set_raster(raster_ptr const& raster)
|
inline void set_raster(raster_ptr const& raster) { raster_ = raster; }
|
||||||
{
|
|
||||||
raster_ = raster;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline feature_kv_iterator begin() const
|
inline feature_kv_iterator begin() const { return feature_kv_iterator(*this, true); }
|
||||||
{
|
|
||||||
return feature_kv_iterator(*this,true);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline feature_kv_iterator end() const
|
inline feature_kv_iterator end() const { return feature_kv_iterator(*this); }
|
||||||
{
|
|
||||||
return feature_kv_iterator(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string to_string() const
|
std::string to_string() const
|
||||||
{
|
{
|
||||||
|
@ -249,11 +206,11 @@ public:
|
||||||
{
|
{
|
||||||
if (data_[kv.second] == mapnik::value_null())
|
if (data_[kv.second] == mapnik::value_null())
|
||||||
{
|
{
|
||||||
ss << " " << kv.first << ":null" << std::endl;
|
ss << " " << kv.first << ":null" << std::endl;
|
||||||
}
|
}
|
||||||
else
|
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();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mapnik::value_integer id_;
|
mapnik::value_integer id_;
|
||||||
context_ptr ctx_;
|
context_ptr ctx_;
|
||||||
cont_type data_;
|
cont_type data_;
|
||||||
|
@ -269,8 +226,7 @@ private:
|
||||||
raster_ptr raster_;
|
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();
|
out << f.to_string();
|
||||||
return out;
|
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>;
|
using feature_ptr = std::shared_ptr<feature_impl>;
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_FEATURE_HPP
|
#endif // MAPNIK_FEATURE_HPP
|
||||||
|
|
|
@ -30,17 +30,16 @@
|
||||||
// boost
|
// boost
|
||||||
//#include <boost/pool/pool_alloc.hpp>
|
//#include <boost/pool/pool_alloc.hpp>
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
struct feature_factory
|
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::pool_allocator<feature_impl>(),fid);
|
||||||
//return boost::allocate_shared<feature_impl>(boost::fast_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 std::make_shared<feature_impl>(ctx, fid);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_FEATURE_FACTORY_HPP
|
#endif // MAPNIK_FEATURE_FACTORY_HPP
|
||||||
|
|
|
@ -45,32 +45,31 @@ namespace mapnik {
|
||||||
|
|
||||||
class feature_impl;
|
class feature_impl;
|
||||||
|
|
||||||
class MAPNIK_DECL feature_kv_iterator :
|
class MAPNIK_DECL feature_kv_iterator : public boost::iterator_facade<feature_kv_iterator,
|
||||||
public boost::iterator_facade<feature_kv_iterator,
|
std::tuple<std::string, value> const,
|
||||||
std::tuple<std::string, value> const,
|
boost::forward_traversal_tag>
|
||||||
boost::forward_traversal_tag>
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using value_type = std::tuple<std::string,value>;
|
using value_type = std::tuple<std::string, value>;
|
||||||
feature_kv_iterator (feature_impl const& f, bool begin = false);
|
feature_kv_iterator(feature_impl const& f, bool begin = false);
|
||||||
private:
|
|
||||||
|
private:
|
||||||
friend class boost::iterator_core_access;
|
friend class boost::iterator_core_access;
|
||||||
void increment();
|
void increment();
|
||||||
void decrement();
|
void decrement();
|
||||||
void advance(boost::iterator_difference<feature_kv_iterator>::type);
|
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;
|
value_type const& dereference() const;
|
||||||
|
|
||||||
feature_impl const& f_;
|
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_;
|
mutable value_type kv_;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct value_not_null
|
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));
|
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>;
|
using feature_kv_iterator2 = boost::filter_iterator<value_not_null, feature_kv_iterator>;
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_FEATURE_KV_ITERATOR_HPP
|
#endif // MAPNIK_FEATURE_KV_ITERATOR_HPP
|
||||||
|
|
|
@ -32,90 +32,65 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
|
|
||||||
class layer_descriptor
|
class layer_descriptor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
layer_descriptor(std::string const& name, std::string const& encoding)
|
layer_descriptor(std::string const& name, std::string const& encoding)
|
||||||
: name_(name),
|
: name_(name)
|
||||||
encoding_(encoding),
|
, encoding_(encoding)
|
||||||
descriptors_(),
|
, descriptors_()
|
||||||
extra_params_() {}
|
, extra_params_()
|
||||||
|
{}
|
||||||
|
|
||||||
layer_descriptor(layer_descriptor const& other)
|
layer_descriptor(layer_descriptor const& other)
|
||||||
: name_(other.name_),
|
: name_(other.name_)
|
||||||
encoding_(other.encoding_),
|
, encoding_(other.encoding_)
|
||||||
descriptors_(other.descriptors_),
|
, descriptors_(other.descriptors_)
|
||||||
extra_params_(other.extra_params_) {}
|
, extra_params_(other.extra_params_)
|
||||||
|
{}
|
||||||
|
|
||||||
void set_name(std::string const& name)
|
void set_name(std::string const& name) { name_ = name; }
|
||||||
{
|
|
||||||
name_ = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string const& get_name() const
|
std::string const& get_name() const { return name_; }
|
||||||
{
|
|
||||||
return name_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_encoding(std::string const& encoding)
|
void set_encoding(std::string const& encoding) { encoding_ = encoding; }
|
||||||
{
|
|
||||||
encoding_ = encoding;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string const& get_encoding() const
|
std::string const& get_encoding() const { return encoding_; }
|
||||||
{
|
|
||||||
return encoding_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void add_descriptor(attribute_descriptor const& desc)
|
void add_descriptor(attribute_descriptor const& desc) { descriptors_.push_back(desc); }
|
||||||
{
|
|
||||||
descriptors_.push_back(desc);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<attribute_descriptor> const& get_descriptors() const
|
std::vector<attribute_descriptor> const& get_descriptors() const { return descriptors_; }
|
||||||
{
|
|
||||||
return descriptors_;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<attribute_descriptor>& get_descriptors()
|
std::vector<attribute_descriptor>& get_descriptors() { return descriptors_; }
|
||||||
{
|
|
||||||
return descriptors_;
|
|
||||||
}
|
|
||||||
|
|
||||||
parameters const& get_extra_parameters() const
|
parameters const& get_extra_parameters() const { return extra_params_; }
|
||||||
{
|
|
||||||
return extra_params_;
|
|
||||||
}
|
|
||||||
|
|
||||||
parameters& get_extra_parameters()
|
parameters& get_extra_parameters() { return extra_params_; }
|
||||||
{
|
|
||||||
return extra_params_;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool has_name(std::string const& name) const
|
bool has_name(std::string const& name) const
|
||||||
{
|
{
|
||||||
auto result = std::find_if(std::begin(descriptors_), std::end(descriptors_),
|
auto result = std::find_if(std::begin(descriptors_),
|
||||||
[&name](attribute_descriptor const& desc) { return name == desc.get_name();});
|
std::end(descriptors_),
|
||||||
|
[&name](attribute_descriptor const& desc) { return name == desc.get_name(); });
|
||||||
return result != std::end(descriptors_);
|
return result != std::end(descriptors_);
|
||||||
}
|
}
|
||||||
void order_by_name()
|
void order_by_name()
|
||||||
{
|
{
|
||||||
std::sort(std::begin(descriptors_), std::end(descriptors_),
|
std::sort(
|
||||||
[](attribute_descriptor const& d0, attribute_descriptor const& d1)
|
std::begin(descriptors_),
|
||||||
{
|
std::end(descriptors_),
|
||||||
return d0.get_name() < d1.get_name();
|
[](attribute_descriptor const& d0, attribute_descriptor const& d1) { return d0.get_name() < d1.get_name(); });
|
||||||
});
|
|
||||||
}
|
}
|
||||||
private:
|
|
||||||
|
private:
|
||||||
std::string name_;
|
std::string name_;
|
||||||
std::string encoding_;
|
std::string encoding_;
|
||||||
std::vector<attribute_descriptor> descriptors_;
|
std::vector<attribute_descriptor> descriptors_;
|
||||||
parameters extra_params_;
|
parameters extra_params_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace mapnik
|
||||||
|
|
||||||
#endif // MAPNIK_FEATURE_LAYER_DESC_HPP
|
#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