Code cleanup

presentation
Andreas Butti 7 years ago
parent 4832317827
commit b3f2fded38
  1. 28
      src/control/jobs/Scheduler.cpp
  2. 6
      src/control/shaperecognizer/CircleRecognizer.cpp
  3. 22
      src/control/shaperecognizer/ShapeRecognizer.cpp
  4. 19
      src/control/shaperecognizer/ShapeRecognizerConfig.h
  5. 7
      src/control/shaperecognizer/ShapeRecognizerResult.cpp

@ -1,26 +1,12 @@
#include "Scheduler.h"
#include <config-debug.h>
#ifdef DEBUG_SHEDULER
#include <iostream>
#define SDEBUG(msg) std::cout << bl::format(CONCAT("Scheduler::", msg, "\n"))
#include <inttypes.h>
#ifdef DEBUG_SHEDULER
#define SDEBUG g_message
#else
//kind of workaround
class no_debug_format
{
public:
template<class T>
no_debug_format& operator%(const T& x)
{
return *this;
}
};
#define SDEBUG(msg) no_debug_format()
#define SDEBUG(msg, ...)
#endif
Scheduler::Scheduler()
@ -120,7 +106,7 @@ void Scheduler::addJob(Job* job, JobPriority priority)
g_queue_push_tail(this->jobQueue[priority], job);
g_cond_broadcast(&this->jobQueueCond);
SDEBUG("add job: {1}") % (uint64_t) job;
SDEBUG("add job: %" PRId64, (uint64_t) job);
g_mutex_unlock(&this->jobQueueMutex);
}
@ -297,7 +283,7 @@ gpointer Scheduler::jobThreadCallback(Scheduler* scheduler)
hasOnlyRenderJobs = false;
}
SDEBUG("get job: {1}") % (uint64_t) job;
SDEBUG("get job: %" PRId64, (uint64_t) job);
if (job == NULL)
{
@ -319,7 +305,7 @@ gpointer Scheduler::jobThreadCallback(Scheduler* scheduler)
continue;
}
SDEBUG("do job: {1}") % (uint64_t) job;
SDEBUG("do job: %" PRId64, (uint64_t) job);
g_mutex_unlock(&scheduler->jobQueueMutex);

@ -72,13 +72,13 @@ Stroke* CircleRecognizer::recognize(Stroke* stroke)
{
Inertia s;
s.calc(stroke->getPoints(), 0, stroke->getPointCount());
RDEBUG("Mass={1,p=0}, Center=({2,p=1},{3,p=1}, I=({4,p=0},{5,p=0}, {6,p=0}), Rad={7,p=2}, Det={8,p=4}")
% s.getMass() % s.centerX() % s.centerY() % s.xx() % s.yy() % s.xy() % s.rad() % s.det();
RDEBUG("Mass=%.0f, Center=(%.1f,%.1f), I=(%.0f,%.0f, %.0f), Rad=%.2f, Det=%.4f",
s.getMass(), s.centerX(), s.centerY(), s.xx(), s.yy(), s.xy(), s.rad(), s.det());
if (s.det() > CIRCLE_MIN_DET)
{
double score = CircleRecognizer::scoreCircle(stroke, s);
RDEBUG("Circle score: {1,p=2}") % score;
RDEBUG("Circle score: %.2f", score);
if (score < CIRCLE_MAX_SCORE)
{
return CircleRecognizer::makeCircleShape(stroke, s);

@ -201,7 +201,7 @@ Stroke* ShapeRecognizer::tryArrow()
alpha[i] -= M_PI;
rs[i].reversed = !rs[i].reversed;
}
RDEBUG("arrow: alpha[{1}] = {2,p=1} degrees") % i % (alpha[i] * 180 / M_PI);
RDEBUG("arrow: alpha[%d] = %.1f degrees", i, (alpha[i] * 180 / M_PI));
if (fabs(alpha[i]) < ARROW_ANGLE_MIN || fabs(alpha[i]) > ARROW_ANGLE_MAX)
{
return NULL;
@ -209,8 +209,7 @@ Stroke* ShapeRecognizer::tryArrow()
}
// check arrow head segments are roughly symmetric
if (alpha[1] * alpha[2] > 0 ||
fabs(alpha[1] + alpha[2]) > ARROW_ASYMMETRY_MAX_ANGLE)
if (alpha[1] * alpha[2] > 0 || fabs(alpha[1] + alpha[2]) > ARROW_ASYMMETRY_MAX_ANGLE)
{
return NULL;
}
@ -231,7 +230,7 @@ Stroke* ShapeRecognizer::tryArrow()
{
double dist = hypot(pt.x - (rs[j].reversed ? rs[j].x1 : rs[j].x2),
pt.y - (rs[j].reversed ? rs[j].y1 : rs[j].y2));
RDEBUG("linear tolerance: tip[{1}] = {2,p=2}") % j % (dist / rs[j].radius);
RDEBUG("linear tolerance: tip[%d] = %.2f", j, (dist / rs[j].radius));
if (dist > ARROW_TIP_LINEAR_TOLERANCE * rs[j].radius)
{
return NULL;
@ -241,7 +240,7 @@ Stroke* ShapeRecognizer::tryArrow()
double dist = (pt.x - x2) * sin(angle) - (pt.y - y2) * cos(angle);
dist /= rs[1].radius + rs[2].radius;
RDEBUG("sideways gap tolerance = {1,p=2}") % dist;
RDEBUG("sideways gap tolerance = %.2f", dist);
if (fabs(dist) > ARROW_SIDEWAYS_GAP_TOLERANCE)
{
@ -251,7 +250,7 @@ Stroke* ShapeRecognizer::tryArrow()
dist = (pt.x - x2) * cos(angle) + (pt.y - y2) * sin(angle);
dist /= rs[1].radius + rs[2].radius;
RDEBUG("main linear gap = {1,p=2}") % dist;
RDEBUG("main linear gap = %.2f", dist);
if (dist < ARROW_MAIN_LINEAR_GAP_MIN || dist > ARROW_MAIN_LINEAR_GAP_MAX)
{
@ -561,14 +560,13 @@ ShapeRecognizerResult* ShapeRecognizer::recognizePatterns(Stroke* stroke)
{
optimizePolygonal(stroke->getPoints(), n, brk, ss);
#ifdef DEBUG_RECOGNIZER
cout << endl << boost::format("ShapeReco:: Polygon, %d edges:") % n << endl;
g_message("--");
g_message("ShapeReco:: Polygon, %d edges:", n);
for (int i = 0; i < n; i++)
{
cout << boost::format("ShapeReco:: %d-%d (M=%.0f, det=%.4f)")
% brk[i] % brk[i + 1] % ss[i].getMass() % ss[i].det()
<< endl;
g_message("ShapeReco:: %d-%d (M=%.0f, det=%.4f)", brk[i], brk[i + 1], ss[i].getMass(), ss[i].det());
}
cout << endl;
g_message("--");
#endif
// update recognizer segment queue (most recent at end)
while (n + queueLength > MAX_POLYGON_SIDES)
@ -583,7 +581,7 @@ ShapeRecognizerResult* ShapeRecognizer::recognizePatterns(Stroke* stroke)
g_memmove(queue, queue + i, queueLength * sizeof(RecoSegment));
}
RDEBUG("Queue now has {1} + {2} edges") % this->queueLength % n;
RDEBUG("Queue now has %i + %i edges", this->queueLength, n);
RecoSegment* rs = &this->queue[this->queueLength];
this->queueLength += n;

@ -34,22 +34,7 @@
#ifdef DEBUG_RECOGNIZER
#include <iostream>
using std::cout;
using std::endl;
#define RDEBUG(msg) cout << bl::format(CONCAT("ShapeReco::", msg, "\n"))
#define RDEBUG(msg, ...) g_message("ShapeReco::" msg, ##__VA_ARGS__)
#else
class no_debug_format
{
public:
template<class T>
no_debug_format& operator%(const T& x)
{
return *this;
}
};
#define RDEBUG(msg) no_debug_format()
#define RDEBUG(msg, ...)
#endif

@ -24,7 +24,7 @@ ShapeRecognizerResult::ShapeRecognizerResult(Stroke* result, ShapeRecognizer* re
}
}
RDEBUG("source list length: {1}") % this->source.size();
RDEBUG("source list length: %i", (int)this->source.size());
}
ShapeRecognizerResult::~ShapeRecognizerResult()
@ -44,9 +44,8 @@ void ShapeRecognizerResult::addSourceStroke(Stroke* s)
{
if (s == elem)
{
// TODO LOW PRIO: this is a bug in the ShapreRecognizer!!
// g_warning("ShapeRecognizerResult::addSourceStroke() try to add a stroke twice!");
// Stacktrace::printStracktrace();
// this is a bug in the ShapreRecognizer
// Ignore
return;
}
}

Loading…
Cancel
Save