Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpenBoard
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lifo
Nicolas Ollinger
OpenBoard
Commits
5bf52b8b
Commit
5bf52b8b
authored
Nov 05, 2016
by
Craig Watson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Take into account stroke thickness when simplifying it
parent
b6f41165
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
9 deletions
+22
-9
UBSettings.cpp
src/core/UBSettings.cpp
+1
-0
UBSettings.h
src/core/UBSettings.h
+1
-0
UBGraphicsStroke.cpp
src/domain/UBGraphicsStroke.cpp
+20
-9
No files found.
src/core/UBSettings.cpp
View file @
5bf52b8b
...
@@ -272,6 +272,7 @@ void UBSettings::init()
...
@@ -272,6 +272,7 @@ void UBSettings::init()
boardInterpolatePenStrokes
=
new
UBSetting
(
this
,
"Board"
,
"InterpolatePenStrokes"
,
true
);
boardInterpolatePenStrokes
=
new
UBSetting
(
this
,
"Board"
,
"InterpolatePenStrokes"
,
true
);
boardSimplifyPenStrokes
=
new
UBSetting
(
this
,
"Board"
,
"SimplifyPenStrokes"
,
true
);
boardSimplifyPenStrokes
=
new
UBSetting
(
this
,
"Board"
,
"SimplifyPenStrokes"
,
true
);
boardSimplifyPenStrokesThresholdAngle
=
new
UBSetting
(
this
,
"Board"
,
"SimplifyPenStrokesThresholdAngle"
,
2
);
boardSimplifyPenStrokesThresholdAngle
=
new
UBSetting
(
this
,
"Board"
,
"SimplifyPenStrokesThresholdAngle"
,
2
);
boardSimplifyPenStrokesThresholdWidthDifference
=
new
UBSetting
(
this
,
"Board"
,
"SimplifyPenStrokesThresholdWidthDifference"
,
2.0
);
boardInterpolateMarkerStrokes
=
new
UBSetting
(
this
,
"Board"
,
"InterpolateMarkerStrokes"
,
true
);
boardInterpolateMarkerStrokes
=
new
UBSetting
(
this
,
"Board"
,
"InterpolateMarkerStrokes"
,
true
);
boardSimplifyMarkerStrokes
=
new
UBSetting
(
this
,
"Board"
,
"SimplifyMarkerStrokes"
,
true
);
boardSimplifyMarkerStrokes
=
new
UBSetting
(
this
,
"Board"
,
"SimplifyMarkerStrokes"
,
true
);
...
...
src/core/UBSettings.h
View file @
5bf52b8b
...
@@ -276,6 +276,7 @@ class UBSettings : public QObject
...
@@ -276,6 +276,7 @@ class UBSettings : public QObject
UBSetting
*
boardInterpolatePenStrokes
;
UBSetting
*
boardInterpolatePenStrokes
;
UBSetting
*
boardSimplifyPenStrokes
;
UBSetting
*
boardSimplifyPenStrokes
;
UBSetting
*
boardSimplifyPenStrokesThresholdAngle
;
UBSetting
*
boardSimplifyPenStrokesThresholdAngle
;
UBSetting
*
boardSimplifyPenStrokesThresholdWidthDifference
;
UBSetting
*
boardInterpolateMarkerStrokes
;
UBSetting
*
boardInterpolateMarkerStrokes
;
UBSetting
*
boardSimplifyMarkerStrokes
;
UBSetting
*
boardSimplifyMarkerStrokes
;
...
...
src/domain/UBGraphicsStroke.cpp
View file @
5bf52b8b
...
@@ -223,23 +223,32 @@ UBGraphicsStroke* UBGraphicsStroke::simplify()
...
@@ -223,23 +223,32 @@ UBGraphicsStroke* UBGraphicsStroke::simplify()
* test these three points. As long as they are aligned, B is erased and we start over.
* test these three points. As long as they are aligned, B is erased and we start over.
* If not, the current B becomes the new A, and so on.
* If not, the current B becomes the new A, and so on.
*
*
* In case the stroke thickness varies a lot between A and B, then B is not removed even if it
* should be according to the previous criteria.
*
*
* TODO: more advanced algorithm that could also simplify curved sections of the stroke
* TODO: more advanced algorithm that could also simplify curved sections of the stroke
*/
*/
// angle difference in degrees between AB and BC below which the segments are considered colinear
// angle difference in degrees between AB and BC below which the segments are considered colinear
qreal
threshold
=
UBSettings
::
settings
()
->
boardSimplifyPenStrokesThresholdAngle
->
get
().
toReal
();
qreal
thresholdAngle
=
UBSettings
::
settings
()
->
boardSimplifyPenStrokesThresholdAngle
->
get
().
toReal
();
// Relative difference in thickness between two consecutive points (A and B) below which they are considered equal
qreal
thresholdWidthDifference
=
UBSettings
::
settings
()
->
boardSimplifyPenStrokesThresholdWidthDifference
->
get
().
toReal
();
QList
<
strokePoint
>::
iterator
it
=
points
.
begin
();
QList
<
strokePoint
>::
iterator
it
=
points
.
begin
();
QList
<
QList
<
strokePoint
>::
iterator
>
toDelete
;
QList
<
QList
<
strokePoint
>::
iterator
>
toDelete
;
while
(
it
+
2
!=
points
.
end
())
{
while
(
it
+
2
!=
points
.
end
())
{
// it, b_it and (b_it+1) correspond to A, B and C respectively
QList
<
strokePoint
>::
iterator
b_it
(
it
+
1
);
QList
<
strokePoint
>::
iterator
b_it
(
it
+
1
);
while
(
b_it
+
1
!=
points
.
end
())
{
while
(
b_it
+
1
!=
points
.
end
())
{
qreal
angle
=
qFabs
(
QLineF
(
it
->
first
,
b_it
->
first
).
angle
()
-
QLineF
(
b_it
->
first
,
(
b_it
+
1
)
->
first
).
angle
());
qreal
angle
=
qFabs
(
QLineF
(
it
->
first
,
b_it
->
first
).
angle
()
-
QLineF
(
b_it
->
first
,
(
b_it
+
1
)
->
first
).
angle
());
qreal
widthRatio
=
qMax
(
it
->
second
,
b_it
->
second
)
/
qMin
(
it
->
second
,
b_it
->
second
);
if
(
widthRatio
>
thresholdWidthDifference
)
qDebug
()
<<
"Width ratio: "
<<
widthRatio
;
if
(
angle
<
threshold
)
if
(
angle
<
threshold
Angle
&&
widthRatio
<
thresholdWidthDifference
)
b_it
=
points
.
erase
(
b_it
);
b_it
=
points
.
erase
(
b_it
);
else
else
break
;
break
;
...
@@ -267,16 +276,18 @@ UBGraphicsStroke* UBGraphicsStroke::simplify()
...
@@ -267,16 +276,18 @@ UBGraphicsStroke* UBGraphicsStroke::simplify()
// certain threshold helps mitigate this issue.
// certain threshold helps mitigate this issue.
// TODO: fix fill issue
// TODO: fix fill issue
if
(
newStrokePoints
.
size
()
>
1
&&
i
<
points
.
size
()
-
1
)
{
if
(
hasAlpha
())
{
qreal
angle
=
qFabs
(
UBGeometryUtils
::
angle
(
points
[
i
-
1
].
first
,
points
[
i
].
first
,
points
[
i
+
1
].
first
));
if
(
newStrokePoints
.
size
()
>
1
&&
i
<
points
.
size
()
-
1
)
{
qDebug
()
<<
"Angle: "
<<
angle
;
qreal
angle
=
qFabs
(
UBGeometryUtils
::
angle
(
points
[
i
-
1
].
first
,
points
[
i
].
first
,
points
[
i
+
1
].
first
));
if
(
angle
>
40
&&
angle
<
320
)
qDebug
()
<<
"Angle: "
<<
angle
;
if
(
angle
>
40
&&
angle
<
320
)
drawCurve
=
true
;
}
if
(
newStrokePoints
.
size
()
%
20
==
0
)
drawCurve
=
true
;
drawCurve
=
true
;
}
}
if
(
newStrokePoints
.
size
()
%
20
==
0
)
drawCurve
=
true
;
if
(
drawCurve
)
{
if
(
drawCurve
)
{
UBGraphicsPolygonItem
*
poly
=
mScene
->
polygonToPolygonItem
(
UBGeometryUtils
::
curveToPolygon
(
newStrokePoints
,
true
,
true
));
UBGraphicsPolygonItem
*
poly
=
mScene
->
polygonToPolygonItem
(
UBGeometryUtils
::
curveToPolygon
(
newStrokePoints
,
true
,
true
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment