Geometrize  1.0
An application for geometrizing images into geometric primitives
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
geometrize::task::ImageTask::ImageTaskImpl Class Reference
Collaboration diagram for geometrize::task::ImageTask::ImageTaskImpl:
Collaboration graph
[legend]

Public Member Functions

 ImageTaskImpl (ImageTask *pQ, const std::string &displayName, Bitmap &bitmap, Qt::ConnectionType workerConnectionType)
 
 ImageTaskImpl (ImageTask *pQ, const std::string &displayName, Bitmap &bitmap, const Bitmap &initial, Qt::ConnectionType workerConnectionType)
 
 ~ImageTaskImpl ()
 
ImageTaskImploperator= (const ImageTaskImpl &)=delete
 
 ImageTaskImpl (const ImageTaskImpl &)=delete
 
geometrize::script::GeometrizerEnginegetGeometrizer ()
 
Bitmap & getTarget ()
 
Bitmap & getCurrent ()
 
const Bitmap & getTarget () const
 
const Bitmap & getCurrent () const
 
std::uint32_t getWidth () const
 
std::uint32_t getHeight () const
 
std::string getDisplayName () const
 
std::size_t getTaskId () const
 
bool isStepping () const
 
void stepModel ()
 
void drawShape (const std::shared_ptr< geometrize::Shape > shape, const geometrize::rgba color)
 
void drawBackgroundRectangle (const geometrize::rgba color)
 
void modelWillStep ()
 
void modelDidStep (const std::vector< geometrize::ShapeResult > shapes)
 
preferences::ImageTaskPreferencesgetPreferences ()
 
void setPreferences (const preferences::ImageTaskPreferences preferences)
 

Private Member Functions

void init (const Qt::ConnectionType connectionType)
 
void connectSignals (const Qt::ConnectionType connectionType)
 
void disconnectAll ()
 

Static Private Member Functions

static std::size_t getId ()
 

Private Attributes

ImageTaskq
 
preferences::ImageTaskPreferences m_preferences
 
const std::string m_displayName
 

Runtime configuration parameters for the runner.

More...
 
const std::size_t m_id
 

The display name of the image task.

More...
 
QThread m_workerThread
 

A unique id for the image task.

More...
 
ImageTaskWorker m_worker
 

Thread that the image task worker runs on.

More...
 
geometrize::script::GeometrizerEngine m_geometrizer
 

The image task worker.

More...
 

Constructor & Destructor Documentation

geometrize::task::ImageTask::ImageTaskImpl::ImageTaskImpl ( ImageTask pQ,
const std::string &  displayName,
Bitmap &  bitmap,
Qt::ConnectionType  workerConnectionType 
)
inline
36  :
37  q{pQ}, m_preferences{}, m_displayName{displayName}, m_id{getId()}, m_worker{bitmap}
38  {
39  init(workerConnectionType);
40  }
ImageTaskWorker m_worker
Thread that the image task worker runs on.
Definition: imagetask.cpp:232
ImageTask * q
Definition: imagetask.cpp:227
void init(const Qt::ConnectionType connectionType)
Definition: imagetask.cpp:196
preferences::ImageTaskPreferences m_preferences
Definition: imagetask.cpp:228
const std::string m_displayName
Runtime configuration parameters for the runner.
Definition: imagetask.cpp:229
static std::size_t getId()
Definition: imagetask.cpp:190
const std::size_t m_id
The display name of the image task.
Definition: imagetask.cpp:230
geometrize::task::ImageTask::ImageTaskImpl::ImageTaskImpl ( ImageTask pQ,
const std::string &  displayName,
Bitmap &  bitmap,
const Bitmap &  initial,
Qt::ConnectionType  workerConnectionType 
)
inline
42  :
43  q{pQ}, m_preferences{}, m_displayName{displayName}, m_id{getId()}, m_worker{bitmap, initial}
44  {
45  init(workerConnectionType);
46  }
ImageTaskWorker m_worker
Thread that the image task worker runs on.
Definition: imagetask.cpp:232
ImageTask * q
Definition: imagetask.cpp:227
void init(const Qt::ConnectionType connectionType)
Definition: imagetask.cpp:196
preferences::ImageTaskPreferences m_preferences
Definition: imagetask.cpp:228
const std::string m_displayName
Runtime configuration parameters for the runner.
Definition: imagetask.cpp:229
static std::size_t getId()
Definition: imagetask.cpp:190
const std::size_t m_id
The display name of the image task.
Definition: imagetask.cpp:230
geometrize::task::ImageTask::ImageTaskImpl::~ImageTaskImpl ( )
inline
49  {
50  disconnectAll();
51 
52  m_workerThread.quit();
53  if(!m_workerThread.wait(1000)) {
54  m_workerThread.terminate();
55  m_workerThread.wait();
56  }
57  }
QThread m_workerThread
A unique id for the image task.
Definition: imagetask.cpp:231
void disconnectAll()
Definition: imagetask.cpp:219

Here is the call graph for this function:

geometrize::task::ImageTask::ImageTaskImpl::ImageTaskImpl ( const ImageTaskImpl )
delete

Member Function Documentation

void geometrize::task::ImageTask::ImageTaskImpl::connectSignals ( const Qt::ConnectionType  connectionType)
inlineprivate
212  {
213  q->connect(q, &ImageTask::signal_step, &m_worker, &ImageTaskWorker::step, connectionType);
214  q->connect(q, &ImageTask::signal_drawShape, &m_worker, &ImageTaskWorker::drawShape, connectionType);
215  q->connect(&m_worker, &ImageTaskWorker::signal_willStep, q, &ImageTask::modelWillStep, Qt::BlockingQueuedConnection);
216  q->connect(&m_worker, &ImageTaskWorker::signal_didStep, q, &ImageTask::modelDidStep, Qt::BlockingQueuedConnection);
217  }
ImageTaskWorker m_worker
Thread that the image task worker runs on.
Definition: imagetask.cpp:232
ImageTask * q
Definition: imagetask.cpp:227
void modelWillStep()
Definition: imagetask.cpp:320
void signal_step(geometrize::ImageRunnerOptions options, std::function< std::shared_ptr< geometrize::Shape >()> shapeCreator, geometrize::core::EnergyFunction energyFunction)
signal_step Signal that the image task emits to make the internal model step.
void signal_didStep(std::vector< geometrize::ShapeResult > shapes)
void signal_drawShape(std::shared_ptr< geometrize::Shape > shape, geometrize::rgba color)
signal_drawShape Signal that the image task emits to draw a shape to the internal model...
void step(geometrize::ImageRunnerOptions options, std::function< std::shared_ptr< geometrize::Shape >()> shapeCreator, geometrize::core::EnergyFunction energyFunction=nullptr)
step Steps the image task worker. Emits the willStep signal when called, and didStep signal on comple...
Definition: imagetaskworker.cpp:28
void modelDidStep(std::vector< geometrize::ShapeResult > shapes)
Definition: imagetask.cpp:325
void drawShape(std::shared_ptr< geometrize::Shape > shape, geometrize::rgba color)
drawShape Draws a shape with the given color to the image task. Emits the willStep signal when called...
Definition: imagetaskworker.cpp:37

Here is the call graph for this function:

Here is the caller graph for this function:

void geometrize::task::ImageTask::ImageTaskImpl::disconnectAll ( )
inlineprivate
220  {
225  }
ImageTaskWorker m_worker
Thread that the image task worker runs on.
Definition: imagetask.cpp:232
ImageTask * q
Definition: imagetask.cpp:227
void modelWillStep()
Definition: imagetask.cpp:320
void signal_step(geometrize::ImageRunnerOptions options, std::function< std::shared_ptr< geometrize::Shape >()> shapeCreator, geometrize::core::EnergyFunction energyFunction)
signal_step Signal that the image task emits to make the internal model step.
void signal_didStep(std::vector< geometrize::ShapeResult > shapes)
void signal_drawShape(std::shared_ptr< geometrize::Shape > shape, geometrize::rgba color)
signal_drawShape Signal that the image task emits to draw a shape to the internal model...
void step(geometrize::ImageRunnerOptions options, std::function< std::shared_ptr< geometrize::Shape >()> shapeCreator, geometrize::core::EnergyFunction energyFunction=nullptr)
step Steps the image task worker. Emits the willStep signal when called, and didStep signal on comple...
Definition: imagetaskworker.cpp:28
void modelDidStep(std::vector< geometrize::ShapeResult > shapes)
Definition: imagetask.cpp:325
void drawShape(std::shared_ptr< geometrize::Shape > shape, geometrize::rgba color)
drawShape Draws a shape with the given color to the image task. Emits the willStep signal when called...
Definition: imagetaskworker.cpp:37

Here is the call graph for this function:

Here is the caller graph for this function:

void geometrize::task::ImageTask::ImageTaskImpl::drawBackgroundRectangle ( const geometrize::rgba  color)
inline
159  {
160  const std::int32_t w = m_worker.getTarget().getWidth();
161  const std::int32_t h = m_worker.getTarget().getHeight();
162  const std::shared_ptr<geometrize::Rectangle> rectangle = std::make_shared<geometrize::Rectangle>(0, 0, w, h);
163  rectangle->rasterize = [w, h](const geometrize::Shape& s) { return geometrize::rasterize(static_cast<const geometrize::Rectangle&>(s), w, h); };
164 
165  emit q->signal_drawShape(rectangle, color);
166  }
ImageTaskWorker m_worker
Thread that the image task worker runs on.
Definition: imagetask.cpp:232
ImageTask * q
Definition: imagetask.cpp:227
geometrize::Bitmap & getTarget()
getTarget Gets the current target bitmap.
Definition: imagetaskworker.cpp:51
void signal_drawShape(std::shared_ptr< geometrize::Shape > shape, geometrize::rgba color)
signal_drawShape Signal that the image task emits to draw a shape to the internal model...

Here is the call graph for this function:

void geometrize::task::ImageTask::ImageTaskImpl::drawShape ( const std::shared_ptr< geometrize::Shape >  shape,
const geometrize::rgba  color 
)
inline
154  {
155  emit q->signal_drawShape(shape, color);
156  }
ImageTask * q
Definition: imagetask.cpp:227
void signal_drawShape(std::shared_ptr< geometrize::Shape > shape, geometrize::rgba color)
signal_drawShape Signal that the image task emits to draw a shape to the internal model...
Bitmap& geometrize::task::ImageTask::ImageTaskImpl::getCurrent ( )
inline
73  {
74  return m_worker.getCurrent();
75  }
ImageTaskWorker m_worker
Thread that the image task worker runs on.
Definition: imagetask.cpp:232
geometrize::Bitmap & getCurrent()
getCurrent Gets the current working bitmap.
Definition: imagetaskworker.cpp:46

Here is the call graph for this function:

const Bitmap& geometrize::task::ImageTask::ImageTaskImpl::getCurrent ( ) const
inline
83  {
84  return m_worker.getCurrent();
85  }
ImageTaskWorker m_worker
Thread that the image task worker runs on.
Definition: imagetask.cpp:232
geometrize::Bitmap & getCurrent()
getCurrent Gets the current working bitmap.
Definition: imagetaskworker.cpp:46

Here is the call graph for this function:

std::string geometrize::task::ImageTask::ImageTaskImpl::getDisplayName ( ) const
inline
98  {
99  return m_displayName;
100  }
const std::string m_displayName
Runtime configuration parameters for the runner.
Definition: imagetask.cpp:229
geometrize::script::GeometrizerEngine& geometrize::task::ImageTask::ImageTaskImpl::getGeometrizer ( )
inline
63  {
64  return m_geometrizer;
65  }
geometrize::script::GeometrizerEngine m_geometrizer
The image task worker.
Definition: imagetask.cpp:233
std::uint32_t geometrize::task::ImageTask::ImageTaskImpl::getHeight ( ) const
inline
93  {
94  return m_worker.getCurrent().getHeight();
95  }
ImageTaskWorker m_worker
Thread that the image task worker runs on.
Definition: imagetask.cpp:232
geometrize::Bitmap & getCurrent()
getCurrent Gets the current working bitmap.
Definition: imagetaskworker.cpp:46

Here is the call graph for this function:

static std::size_t geometrize::task::ImageTask::ImageTaskImpl::getId ( )
inlinestaticprivate
191  {
192  static std::atomic<std::size_t> id{0U};
193  return id++;
194  }
preferences::ImageTaskPreferences& geometrize::task::ImageTask::ImageTaskImpl::getPreferences ( )
inline
179  {
180  return m_preferences;
181  }
preferences::ImageTaskPreferences m_preferences
Definition: imagetask.cpp:228
Bitmap& geometrize::task::ImageTask::ImageTaskImpl::getTarget ( )
inline
68  {
69  return m_worker.getTarget();
70  }
ImageTaskWorker m_worker
Thread that the image task worker runs on.
Definition: imagetask.cpp:232
geometrize::Bitmap & getTarget()
getTarget Gets the current target bitmap.
Definition: imagetaskworker.cpp:51

Here is the call graph for this function:

const Bitmap& geometrize::task::ImageTask::ImageTaskImpl::getTarget ( ) const
inline
78  {
79  return m_worker.getTarget();
80  }
ImageTaskWorker m_worker
Thread that the image task worker runs on.
Definition: imagetask.cpp:232
geometrize::Bitmap & getTarget()
getTarget Gets the current target bitmap.
Definition: imagetaskworker.cpp:51

Here is the call graph for this function:

std::size_t geometrize::task::ImageTask::ImageTaskImpl::getTaskId ( ) const
inline
103  {
104  return m_id;
105  }
const std::size_t m_id
The display name of the image task.
Definition: imagetask.cpp:230
std::uint32_t geometrize::task::ImageTask::ImageTaskImpl::getWidth ( ) const
inline
88  {
89  return m_worker.getCurrent().getWidth();
90  }
ImageTaskWorker m_worker
Thread that the image task worker runs on.
Definition: imagetask.cpp:232
geometrize::Bitmap & getCurrent()
getCurrent Gets the current working bitmap.
Definition: imagetaskworker.cpp:46

Here is the call graph for this function:

void geometrize::task::ImageTask::ImageTaskImpl::init ( const Qt::ConnectionType  connectionType)
inlineprivate
197  {
198  qRegisterMetaType<std::vector<geometrize::ShapeResult>>();
199  qRegisterMetaType<geometrize::ImageRunnerOptions>();
200  qRegisterMetaType<std::function<std::shared_ptr<geometrize::Shape>()>>();
201  qRegisterMetaType<std::shared_ptr<geometrize::Shape>>();
202  qRegisterMetaType<geometrize::rgba>();
203  qRegisterMetaType<geometrize::core::EnergyFunction>();
204 
205  m_worker.moveToThread(&m_workerThread);
206  m_workerThread.start();
207 
208  connectSignals(connectionType);
209  }
ImageTaskWorker m_worker
Thread that the image task worker runs on.
Definition: imagetask.cpp:232
QThread m_workerThread
A unique id for the image task.
Definition: imagetask.cpp:231
void connectSignals(const Qt::ConnectionType connectionType)
Definition: imagetask.cpp:211

Here is the call graph for this function:

bool geometrize::task::ImageTask::ImageTaskImpl::isStepping ( ) const
inline
108  {
109  return m_worker.isStepping();
110  }
ImageTaskWorker m_worker
Thread that the image task worker runs on.
Definition: imagetask.cpp:232
bool isStepping() const
isStepping Returns true if the internal model is currently stepping.
Definition: imagetaskworker.cpp:71

Here is the call graph for this function:

void geometrize::task::ImageTask::ImageTaskImpl::modelDidStep ( const std::vector< geometrize::ShapeResult >  shapes)
inline
174  {
175  emit q->signal_modelDidStep(shapes);
176  }
ImageTask * q
Definition: imagetask.cpp:227
void signal_modelDidStep(std::vector< geometrize::ShapeResult > shapes)
signal_modelDidStep Signal that is emitted immediately after the underlying image task model is stepp...
void geometrize::task::ImageTask::ImageTaskImpl::modelWillStep ( )
inline
169  {
170  emit q->signal_modelWillStep();
171  }
ImageTask * q
Definition: imagetask.cpp:227
void signal_modelWillStep()
signal_modelWillStep Signal that is emitted immediately before the underlying image task model is ste...
ImageTaskImpl& geometrize::task::ImageTask::ImageTaskImpl::operator= ( const ImageTaskImpl )
delete
void geometrize::task::ImageTask::ImageTaskImpl::setPreferences ( const preferences::ImageTaskPreferences  preferences)
inline
184  {
185  m_preferences = preferences;
186  emit q->signal_preferencesSet();
187  }
ImageTask * q
Definition: imagetask.cpp:227
void signal_preferencesSet()
signal_preferencesSet Signal that is emitted immediately after the image task preferences are set...
preferences::ImageTaskPreferences m_preferences
Definition: imagetask.cpp:228
void geometrize::task::ImageTask::ImageTaskImpl::stepModel ( )
inline
113  {
114  const bool isScriptModeEnabled = m_preferences.isScriptModeEnabled();
115  const auto imageRunnerOptions = m_preferences.getImageRunnerOptions();
116 
117  // Early out if the script engine is disabled (use the default/C++ implementations)
118  if(!isScriptModeEnabled) {
119  emit q->signal_step(imageRunnerOptions, nullptr, nullptr);
120  return;
121  }
122 
123  const auto scripts = m_preferences.getScripts();
124  const std::int32_t targetWidth = m_worker.getTarget().getWidth();
125  const std::int32_t targetHeight = m_worker.getTarget().getHeight();
126 
127  // Scripting is enabled - clone the entire geometrizer engine
128  // This is important because many threads will be working with it when geometrizing shapes
129  // and we don't want to mess with the state of the engine on the main thread while these threads are working with
130  const auto geometrizerEngineClone = [this, scripts]() {
131  auto engine = std::make_shared<geometrize::script::GeometrizerEngine>(m_geometrizer.getEngine()->get_state());
132 
133  // Install the scripts that are required for the geometrization process
134  engine->installScripts(scripts);
135  return engine;
136  }();
137 
138  // Pick the shape creation function
139  const auto shapeCreator = [geometrizerEngineClone, imageRunnerOptions, targetWidth, targetHeight]() {
140  // NOTE - this method uses shared_from_this to keep the engine alive
141  return geometrizerEngineClone->makeShapeCreator(imageRunnerOptions.shapeTypes, targetWidth, targetHeight);
142  }();
143 
144  // Pick the energy calculation function
145  const geometrize::core::EnergyFunction energyFunction = [geometrizerEngineClone]() {
146  // NOTE - this method uses shared_from_this to keep the engine alive
147  return geometrizerEngineClone->makeEnergyFunction();
148  }();
149 
150  emit q->signal_step(imageRunnerOptions, shapeCreator, energyFunction);
151  }
ImageTaskWorker m_worker
Thread that the image task worker runs on.
Definition: imagetask.cpp:232
ImageTask * q
Definition: imagetask.cpp:227
geometrize::script::GeometrizerEngine m_geometrizer
The image task worker.
Definition: imagetask.cpp:233
chaiscript::ChaiScript * getEngine()
getEngine Gets a pointer to the script engine used by the shape mutation engine.
Definition: geometrizerengine.cpp:52
geometrize::Bitmap & getTarget()
getTarget Gets the current target bitmap.
Definition: imagetaskworker.cpp:51
void signal_step(geometrize::ImageRunnerOptions options, std::function< std::shared_ptr< geometrize::Shape >()> shapeCreator, geometrize::core::EnergyFunction energyFunction)
signal_step Signal that the image task emits to make the internal model step.
preferences::ImageTaskPreferences m_preferences
Definition: imagetask.cpp:228
bool isScriptModeEnabled() const
Definition: imagetaskpreferences.cpp:247
geometrize::ImageRunnerOptions getImageRunnerOptions() const
getImageRunnerOptions Gets a copy of the image runner options.
Definition: imagetaskpreferences.cpp:197
std::map< std::string, std::string > getScripts() const
Definition: imagetaskpreferences.cpp:262

Here is the call graph for this function:

Member Data Documentation

const std::string geometrize::task::ImageTask::ImageTaskImpl::m_displayName
private

Runtime configuration parameters for the runner.

geometrize::script::GeometrizerEngine geometrize::task::ImageTask::ImageTaskImpl::m_geometrizer
private

The image task worker.

const std::size_t geometrize::task::ImageTask::ImageTaskImpl::m_id
private

The display name of the image task.

preferences::ImageTaskPreferences geometrize::task::ImageTask::ImageTaskImpl::m_preferences
private
ImageTaskWorker geometrize::task::ImageTask::ImageTaskImpl::m_worker
private

Thread that the image task worker runs on.

QThread geometrize::task::ImageTask::ImageTaskImpl::m_workerThread
private

A unique id for the image task.

ImageTask* geometrize::task::ImageTask::ImageTaskImpl::q
private

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