Geometrize 1.0
C++ library for geometrizing images into geometric primitives
model.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <functional>
5#include <memory>
6#include <vector>
7
8#include "core.h"
9#include "shaperesult.h"
10
11namespace geometrize
12{
13class Bitmap;
14class Scanline;
15class Shape;
16}
17
18namespace geometrize
19{
20
33using ShapeAcceptancePreconditionFunction = std::function<bool(
34 double lastScore,
35 double newScore,
36 const geometrize::Shape& shape,
37 const std::vector<geometrize::Scanline>& lines,
38 const geometrize::rgba& color,
39 const geometrize::Bitmap& before,
40 const geometrize::Bitmap& after,
41 const geometrize::Bitmap& target)>;
42
47class Model
48{
49public:
54 Model(const geometrize::Bitmap& target);
55
62 Model(const geometrize::Bitmap& target, const geometrize::Bitmap& initial);
63 ~Model();
64 Model& operator=(const Model&) = delete;
65 Model(const Model&) = delete;
66
71 void reset(geometrize::rgba backgroundColor);
72
77 std::int32_t getWidth() const;
78
83 std::int32_t getHeight() const;
84
96 std::vector<geometrize::ShapeResult> step(
97 const std::function<std::shared_ptr<geometrize::Shape>(void)>& shapeCreator,
98 std::uint8_t alpha,
99 std::uint32_t shapeCount,
100 std::uint32_t maxShapeMutations,
101 std::uint32_t maxThreads,
102 const geometrize::core::EnergyFunction& energyFunction = nullptr,
103 const geometrize::ShapeAcceptancePreconditionFunction& addShapePrecondition = nullptr);
104
112 geometrize::ShapeResult drawShape(std::shared_ptr<geometrize::Shape> shape, geometrize::rgba color);
113
119
125
130 const geometrize::Bitmap& getCurrent() const;
131
136 const geometrize::Bitmap& getTarget() const;
137
142 void setSeed(std::uint32_t seed);
143
144private:
145 class ModelImpl;
146 std::unique_ptr<Model::ModelImpl> d;
147};
148
149}
The Bitmap class is a helper class for working with bitmap data.
Definition: bitmap.h:16
Definition: model.cpp:44
The Model class is the model for the core optimization/fitting algorithm.
Definition: model.h:48
Model(const Model &)=delete
geometrize::Bitmap & getTarget()
getTarget Gets the target bitmap.
Definition: model.cpp:262
~Model()
Definition: model.cpp:227
Model & operator=(const Model &)=delete
geometrize::ShapeResult drawShape(std::shared_ptr< geometrize::Shape > shape, geometrize::rgba color)
drawShape Draws a shape on the model. Typically used when to manually add a shape to the image (e....
Definition: model.cpp:257
void reset(geometrize::rgba backgroundColor)
reset Resets the model back to the state it was in when it was created.
Definition: model.cpp:230
geometrize::Bitmap & getCurrent()
getCurrent Gets the current bitmap.
Definition: model.cpp:267
void setSeed(std::uint32_t seed)
setSeed Sets the seed that the random number generators of this model use. Note that the model also u...
Definition: model.cpp:282
std::int32_t getWidth() const
getWidth Gets the width of the target bitmap.
Definition: model.cpp:235
std::int32_t getHeight() const
getHeight Gets the height of the target bitmap.
Definition: model.cpp:240
Model(const geometrize::Bitmap &target)
Model Creates a model that will aim to replicate the target bitmap with shapes.
Definition: model.cpp:221
std::unique_ptr< Model::ModelImpl > d
Definition: model.h:146
std::vector< geometrize::ShapeResult > step(const std::function< std::shared_ptr< geometrize::Shape >(void)> &shapeCreator, std::uint8_t alpha, std::uint32_t shapeCount, std::uint32_t maxShapeMutations, std::uint32_t maxThreads, const geometrize::core::EnergyFunction &energyFunction=nullptr, const geometrize::ShapeAcceptancePreconditionFunction &addShapePrecondition=nullptr)
step Steps the primitive optimization/fitting algorithm.
Definition: model.cpp:245
Definition: shape.h:18
std::function< double(const std::vector< geometrize::Scanline > &lines, const std::uint32_t alpha, const geometrize::Bitmap &target, const geometrize::Bitmap &current, geometrize::Bitmap &buffer, double score)> EnergyFunction
EnergyFunction Type alias for a function that calculates a measure of the improvement adding the scan...
Definition: core.h:44
Definition: bitmap.cpp:8
std::function< bool(double lastScore, double newScore, const geometrize::Shape &shape, const std::vector< geometrize::Scanline > &lines, const geometrize::rgba &color, const geometrize::Bitmap &before, const geometrize::Bitmap &after, const geometrize::Bitmap &target)> ShapeAcceptancePreconditionFunction
ShapeAcceptancePreconditionFunction Type alias for a function that is used to decide whether or not t...
Definition: model.h:41
The ShapeResult struct is a container for info about a shape added to the model.
Definition: shaperesult.h:20
The rgba struct is a helper for manipulating RGBA8888 color data.
Definition: rgba.h:13