12#include "../../src/interfaces/AutonomyThread.hpp"
13#include "../../src/util/ExampleChecker.h"
14#include "../opencv/TagGenerator.hpp"
36 int m_nNumTagsToGenerate = 0;
37 std::vector<cv::aruco::PredefinedDictionaryType> m_vDictionaries;
38 std::mutex m_muDictMutex;
73 std::unique_lock<std::mutex> lock(m_muDictMutex);
76 m_vDictionaries.pop_back();
84 bool bUseParallelLoop =
false;
93 [&cvDictType](
const int a,
const int b)
96 for (
int i = a; i < b; ++i)
105 for (
int i = 0; i < m_nNumTagsToGenerate; ++i)
149 int m_nNumTagsToGenerate = 0;
150 std::vector<cv::aruco::PredefinedDictionaryType> m_vDictionaries;
165 while (m_vDictionaries.size() > 0)
169 m_vDictionaries.pop_back();
172 for (
int i = 0; i < m_nNumTagsToGenerate; ++i)
213 std::chrono::time_point tmStartTime = std::chrono::high_resolution_clock::now();
225 LinearTagGenerator.
Start();
234 LinearTagGenerator.
Start();
243 LinearTagGenerator.
Start();
252 LinearTagGenerator.
Start();
255 std::chrono::time_point tmEndTime = std::chrono::high_resolution_clock::now();
257 int nSingledThreadedDuration = std::chrono::duration_cast<std::chrono::milliseconds>(tmEndTime - tmStartTime).count();
259 std::cout <<
"Time taken for single threaded generator: " << nSingledThreadedDuration <<
" milliseconds." << std::endl;
262 for (
const std::filesystem::directory_entry& stdEntry : std::filesystem::directory_iterator(
"."))
265 if (std::filesystem::is_regular_file(stdEntry) && stdEntry.path().extension() ==
".png")
268 std::filesystem::remove(stdEntry.path());
276 tmStartTime = std::chrono::high_resolution_clock::now();
291 ThreadedTagGenerator1.
Start();
300 ThreadedTagGenerator2.
Start();
309 ThreadedTagGenerator3.
Start();
318 ThreadedTagGenerator4.
Start();
321 ThreadedTagGenerator1.
Join();
322 ThreadedTagGenerator2.
Join();
323 ThreadedTagGenerator3.
Join();
324 ThreadedTagGenerator4.
Join();
327 tmEndTime = std::chrono::high_resolution_clock::now();
329 int nMultiThreadedDuration = std::chrono::duration_cast<std::chrono::milliseconds>(tmEndTime - tmStartTime).count();
331 std::cout <<
"Time taken for multithreaded generator: " << nMultiThreadedDuration <<
" milliseconds." << std::endl;
332 std::cout <<
"\n\nCheck your build directory for all aruco tags!" << std::endl;
void GenerateOpenCVArucoMarker(cv::aruco::PredefinedDictionaryType eDictionary, unsigned short sMarker)
Generate an ArUco Tag.
Definition TagGenerator.hpp:25
Interface class used to easily multithread a child class.
Definition AutonomyThread.hpp:38
void Join()
Waits for thread to finish executing and then closes thread. This method will block the calling code ...
Definition AutonomyThread.hpp:180
void ParallelizeLoop(const int nNumThreads, const N tTotalIterations, F &&tLoopFunction)
Given a ref-qualified looping function and an arbitrary number of iterations, this method will divide...
Definition AutonomyThread.hpp:404
void RequestStop()
Signals threads to stop executing user code, terminate. DOES NOT JOIN. This method will not force the...
Definition AutonomyThread.hpp:164
void Start()
When this method is called, it starts a new thread that runs the code within the ThreadedContinuousCo...
Definition AutonomyThread.hpp:117
void RunDetachedPool(const unsigned int nNumTasksToQueue, const unsigned int nNumThreads=2, const bool bForceStopCurrentThreads=false)
When this method is called, it starts a thread pool full of threads that don't return std::futures (l...
Definition AutonomyThread.hpp:336
void JoinPool()
Waits for pool to finish executing tasks. This method will block the calling code until thread is fin...
Definition AutonomyThread.hpp:439