Geometrize 1.0
C++ library for geometrizing images into geometric primitives
Classes | Public Member Functions | Private Attributes | List of all members
geometrize::Model Class Reference

The Model class is the model for the core optimization/fitting algorithm. More...

#include <model.h>

Classes

class  ModelImpl
 

Public Member Functions

 Model (const geometrize::Bitmap &target)
 Model Creates a model that will aim to replicate the target bitmap with shapes. More...
 
 Model (const geometrize::Bitmap &target, const geometrize::Bitmap &initial)
 Model Creates a model that will optimize for the given target bitmap, starting from the given initial bitmap. The target bitmap and initial bitmap must be the same size (width and height). More...
 
 ~Model ()
 
Modeloperator= (const Model &)=delete
 
 Model (const Model &)=delete
 
void reset (geometrize::rgba backgroundColor)
 reset Resets the model back to the state it was in when it was created. More...
 
std::int32_t getWidth () const
 getWidth Gets the width of the target bitmap. More...
 
std::int32_t getHeight () const
 getHeight Gets the height of the target bitmap. More...
 
std::vector< geometrize::ShapeResultstep (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. More...
 
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.g. when setting an initial background). NOTE this unconditionally draws the shape, even if it increases the difference between the source and target image. More...
 
geometrize::BitmapgetCurrent ()
 getCurrent Gets the current bitmap. More...
 
geometrize::BitmapgetTarget ()
 getTarget Gets the target bitmap. More...
 
const geometrize::BitmapgetCurrent () const
 getCurrent Gets the current bitmap, const-edition. More...
 
const geometrize::BitmapgetTarget () const
 getTarget Gets the target bitmap, const-edition. More...
 
void setSeed (std::uint32_t seed)
 setSeed Sets the seed that the random number generators of this model use. Note that the model also uses an internal seed offset which is incremented when the model is stepped. More...
 

Private Attributes

std::unique_ptr< Model::ModelImpld
 

Detailed Description

The Model class is the model for the core optimization/fitting algorithm.

Author
Sam Twidale (https://samcodes.co.uk/)

Constructor & Destructor Documentation

◆ Model() [1/3]

geometrize::Model::Model ( const geometrize::Bitmap target)

Model Creates a model that will aim to replicate the target bitmap with shapes.

Parameters
targetThe target bitmap to replicate with shapes.
221 : d{std::unique_ptr<Model::ModelImpl>(new Model::ModelImpl(target))}
222{}
std::unique_ptr< Model::ModelImpl > d
Definition: model.h:146

◆ Model() [2/3]

geometrize::Model::Model ( const geometrize::Bitmap target,
const geometrize::Bitmap initial 
)

Model Creates a model that will optimize for the given target bitmap, starting from the given initial bitmap. The target bitmap and initial bitmap must be the same size (width and height).

Parameters
targetThe target bitmap to replicate with shapes.
initialThe starting bitmap.
224 : d{std::unique_ptr<Model::ModelImpl>(new Model::ModelImpl(target, initial))}
225{}

◆ ~Model()

geometrize::Model::~Model ( )
228{}

◆ Model() [3/3]

geometrize::Model::Model ( const Model )
delete

Member Function Documentation

◆ drawShape()

geometrize::ShapeResult geometrize::Model::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.g. when setting an initial background). NOTE this unconditionally draws the shape, even if it increases the difference between the source and target image.

Parameters
shapeThe shape to draw.
colorThe color (including alpha) of the shape.
Returns
Data about the shape drawn on the model.
258{
259 return d->drawShape(shape, color);
260}

◆ getCurrent() [1/2]

geometrize::Bitmap & geometrize::Model::getCurrent ( )

getCurrent Gets the current bitmap.

Returns
The current bitmap.
268{
269 return d->getCurrent();
270}
Here is the caller graph for this function:

◆ getCurrent() [2/2]

const geometrize::Bitmap & geometrize::Model::getCurrent ( ) const

getCurrent Gets the current bitmap, const-edition.

Returns
The current bitmap.
278{
279 return d->getCurrent();
280}

◆ getHeight()

std::int32_t geometrize::Model::getHeight ( ) const

getHeight Gets the height of the target bitmap.

Returns
The height of the target bitmap.
241{
242 return d->getHeight();
243}

◆ getTarget() [1/2]

geometrize::Bitmap & geometrize::Model::getTarget ( )

getTarget Gets the target bitmap.

Returns
The target bitmap.
263{
264 return d->getTarget();
265}
Here is the caller graph for this function:

◆ getTarget() [2/2]

const geometrize::Bitmap & geometrize::Model::getTarget ( ) const

getTarget Gets the target bitmap, const-edition.

Returns
The target bitmap.
273{
274 return d->getTarget();
275}

◆ getWidth()

std::int32_t geometrize::Model::getWidth ( ) const

getWidth Gets the width of the target bitmap.

Returns
The width of the target bitmap.
236{
237 return d->getWidth();
238}

◆ operator=()

Model & geometrize::Model::operator= ( const Model )
delete

◆ reset()

void geometrize::Model::reset ( geometrize::rgba  backgroundColor)

reset Resets the model back to the state it was in when it was created.

Parameters
backgroundColorThe starting background color to use.
231{
232 d->reset(backgroundColor);
233}

◆ setSeed()

void geometrize::Model::setSeed ( std::uint32_t  seed)

setSeed Sets the seed that the random number generators of this model use. Note that the model also uses an internal seed offset which is incremented when the model is stepped.

Parameters
seedThe random number generator seed.
283{
284 d->setSeed(seed);
285}
Here is the caller graph for this function:

◆ step()

std::vector< geometrize::ShapeResult > geometrize::Model::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.

Parameters
shapeCreatorA function that will produce the shapes.
alphaThe alpha of the shape.
shapeCountThe number of random shapes to generate (only 1 is chosen in the end).
maxShapeMutationsThe maximum number of times to mutate each random shape.
maxThreadsThe maximum number of threads to use during this step.
energyFunctionAn optional function to calculate the energy (if unspecified a default implementation is used).
addShapePreconditionAn optional function to determine whether to accept a shape (if unspecified a default implementation is used).
Returns
A vector containing data about the shapes added to the model in this step. This may be empty if no shape that improved the image could be found.
253{
254 return d->step(shapeCreator, alpha, shapeCount, maxShapeMutations, maxThreads, energyFunction, addShapePrecondition);
255}
Here is the caller graph for this function:

Member Data Documentation

◆ d

std::unique_ptr<Model::ModelImpl> geometrize::Model::d
private

The documentation for this class was generated from the following files: