New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alternatives to Bezier #547
Comments
I searched a bit about this issue. Veusz's interpolation is internally treated by C++ code derived from Inkscape (veusz/veusz/helpers/src/qtloops/beziers.cpp). Both algorithms are similar in many points:
As far as I glanced through the both codes, the difference between the two algorithms comes from the way of determining the positions of the remaining two control points. Inkscape's algorithm seems to optimize the positions of bz(1) and bz(2) by moving them on "tangent vectors" (Core functions:
Therefore, I think the issue may be solved by translating Brian's VBA code to beziers.cpp of Veusz. Unfortunately, I have no experience to write C++ code. So, it will be a tough work for me. |
Wow, thanks for that very careful response. It seems to me that the Inkscape formula -- being from a drawing program -- will not necessarily include the constraint that the graph cannot go 'backwards', because a drawing does not have such a concept, whereas a graph does. That would seem to make the Excel-type approach more appropriate for a graphing program. I have not installed Veusz from source, nor coded in C++, so I can have a look but I would struggle to know where to start. I only know Fortran ... but I think this is a great step, knowing what to do. Thank you for a very clear explanation. |
I think I have successfully implemented what we want, though it is still just under testing (and the code is still dirty). Bezier fitting result by current ver. of VeuszBezier interpolation result by newly tested VeuszBezier interpolation by MS Excel |
This seems to work well by a simple code described below. Such fitting-less method might be also beneficial in the aspect of performance. QPolygonF bezier_interpolate_Excel(const QPolygonF& data) {
// Excel-like low-cost Bezier interpolation, translated from
// https://blog.splitwise.com/2012/01/31/mystery-solved-
// the-secret-of-excel-curved-line-interpolation/
double tension=6.0
const int len = data.size();
if (len <= 1) {
return QPolygonF();
}else if (len == 2) {
QPolygonF bezier_ctrls(4);
bezier_ctrls << data[0] << data[1] << data[1] << data[1];
return bezier_ctrls;
}else{
QPolygonF bezier_ctrls(4 * (len - 1));
QPolygonF ctrls(4);
QPointF pt0;
QPointF pt1;
QPointF pt2;
QPointF pt3;
double f1;
double f2;
double d02;
double d12;
double d13;
bool b1;
bool b2;
for (int i = 1; i < len; i++) {
pt1 = data[i-1];
pt2 = data[i];
if (i == 1) {
pt0 = data[i-1];
pt3 = data[i+1];
f1 = 1.0 / tension * 2;
f2 = 1.0 / tension;
}else if (i == len - 1) {
pt0 = data[i-2];
pt3 = data[i];
f1 = 1.0 / tension;
f2 = 1.0 / tension;
}else{
pt0 = data[i-2];
pt3 = data[i+1];
f1 = 1.0 / tension;
f2 = 1.0 / tension * 2;
}
ctrls[0] = pt1;
ctrls[3] = pt2;
d02 = QLineF(pt0, pt2).length();
d12 = QLineF(pt1, pt2).length();
d13 = QLineF(pt1, pt3).length();
b1 = d02 / 6.0 < d12 / 2.0;
b2 = d13 / 6.0 < d12 / 2.0;
if (b1 && b2) {
ctrls[1] = pt1 + (pt2 - pt0) * f1;
ctrls[2] = pt2 + (pt1 - pt3) * f2;
}else if (!b1 && !b2) {
ctrls[1] = pt1 + (pt2 - pt0) * d12 / 2.0 / d02;
ctrls[2] = pt2 + (pt1 - pt3) * d12 / 2.0 / d13;
}else if (!b1) {
ctrls[1] = pt1 + (pt2 - pt0) * d12 / 2.0 / d02;
ctrls[2] = pt2 + (pt1 - pt3) * d12 / 2.0 / d13 * d13 / d02;
}else{
ctrls[1] = pt1 + (pt2 - pt0) * d12 / 2.0 / d02 * d02 / d13;
ctrls[2] = pt2 + (pt1 - pt3) * d12 / 2.0 / d13;
}
bezier_ctrls += ctrls;
}
return bezier_ctrls;
}
} I also added and examined a "Tension parameter" (I'm not sure this naming is appropriate) to control the curvature. |
That is great. I am working on being able to build Veusz but Debian stable which I use provides low versions of Qt and the build commands throw lots of errors to do with pyqt. I don't know how to fix it because the qt version is not something you can back port -- that would break existing things apparently I have to see if I can build it. But your changes really look like they have done a great job. |
Thanks again. I am still trying to get a working development environment. I am not a software developer, and I am finding it very difficult. I am following https://github-wiki-see.page/m/veusz/veusz/wiki/DevStart but without success. If I ever get it to work, I'll report back! |
Can you tell me what error messages you are facing and what your OS? |
Hi I should preface this by saying I am very ignorant of development environments. I find the jungle of dependencies with tools like Python and Qt to be incomprehensible. It is entirely possible that the instructions are fine and that I am just too ignorant. I did get a working development environment, and have compiled the vanilla Veusz successfully. Please note that the computer in question had no development tools to speak of on it before I started. Next I need to see if I can compile your version and text the new algorithm. Veusz development environment on WindowsOK, we start with https://github-wiki-see.page/m/veusz/veusz/wiki/DevStart
Was unclear to me which bits of Qt I needed. Did I only need the MSVC 2017? Or did I need lots of stuff as well as MSVC 2017? In the end I installed the whole 12 GB of stuff. (The downloads needed to get this project running are very large. I guess their fine if you are a developer and work on several projects using Qt and so on, but for me the overhead was a shock. I spent many hours waiting for downloads to happen -- Qt and the MS C++ tools are very big downloads.) In the end, I installed all 12 GB of the Qt stuff; after the 2 GB download I thought I might as well. Added the QMAKE_EXE environment variable for my user. The path was not quite the same as in the docs, but it was easy enough to find Windows button > type 'env' > Edit environment variables for your account > created QMAKE_EXE and made it point to directory and file as C:\Users\username>set QMAKE_EXE=C:\Qt\Qt5.9.9\5.9.9\msvc2017_64\bin\qmake.exe When I typed:
I got redirected to the MS store to install it. OK, something did not work. Maybe I need to add something to my path? No, eventually I worked out that the Python installer above just installs it as python.exe:
So had to just use 'python' for 'python3'.
OK, that seemed to be working. (sandbox)> pip install numpy sip==5.5.0 PyQt5 pyqt5-tools Got a message to update pip: (sandbox)> python.exe -m pip install --upgrade pip Then continued the steps as given: (sandbox)> pip install h5py astropy iminuit Ghostscript Sphinx Watched lots of dependencies install. (sandbox)> cd sandbox Seemed OK. Now, it said we go to: (sandbox) C:\Users\user\veusz> but that does not exist. What step have I missed? Ah, Windows instructions omit this: (sandbox)> cd c:\Users\username I guess we do not issue it ftom within the sandbox folder? I guess not. (sandbox)> cd veusz Threw an error -- but of course this is an error only a complete nondeveloper would make. I did not have C++ installed from Microsoft. I guess you would reasonably assume this. Not me! building 'veusz.helpers.threed' extension error: Microsoft Visual C++ 14.0 or greater is required. Get it with OK, we go to that website. How big is this download? OK, ran the installer from MS and installed the C++ tools. Not sure what was needed, so installed using defaults from this category. Rebooted.
And it worked. Summary: The supplied document gave enough information to get it to work, it just omitted a few steps that were probably seen as too obvious to need listing. (I am not a programmer.) The name of the Python binary in Windows as a small trap, and given the relatively compact size of Veusz when it is all done, the overhead of Python, Qt and MSVC is kind of large. I guess that is inevitable. Getting it to work on Debian stable was more of a problem. In the end, I think it just cannot be done. The show stopper was the version of Qt5, which is too low on Debian stable. Some output from Debian: username@lauequad:~$ cat /etc/debian_version 10.10 $ python setup.py build $ ls -l /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 And of we look at the Debian package database, stable contains: https://packages.debian.org/buster/libqt5core5a And I am not prepared to change my whole distribution just to be able to compile Veusz. I expect Debian will move to the new libraries soon enough anyway. |
Thank you for the detailed report, which must be very useful to improve the wiki. I usually develop on Windows machine using WSL2 (Ubuntu). Setting up the development environment with WSL2 is easier, so I may add some descriptions for WSL2 case. |
Thanks for all your work.
…On Fri, 20 Aug 2021, 8:39 pm Takuro Hosomi, ***@***.***> wrote:
Thank you for the detailed report, which would be useful to improve the
wiki.
"Dev Start" should literally be a start point, but the current version
(which I wrote before) is not very friendly.
I would like to add some explanations, especially the part of developing
in Windows which need a major revision.
I usually develop on Windows machine using WSL2 (Ubuntu). Setting up the
development environment with WSL2 is easier, so I may add some descriptions
for WSL2 case.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#547 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC7UXMBXUV26GJS37OSE2H3T5YWGDANCNFSM5BSLKXWQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email>
.
|
I revised https://github-wiki-see.page/m/veusz/veusz/wiki/DevStart I checked that I can make a devevopment environment on a fresh win 10 by this recipie. |
That looks fantastic. Thanks again. I think Veusz is really great. |
Hi
Just a note that I have recently updated my machine to Debian 11 and the
devstart instructions work very well. Only one thing was different/
$ sudo apt install qt5-qmake qt5-default python3-pyqt5.qtsvg \
build-essential python3-dev python3-venv \
libdbus-1-dev libdbus-glib-1-dev
Package qt5-default is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
Instead I installed
qtbase5-dev qtchooser qtbase5-dev-tools
and it all seemed to work well.
THank you for your trouble. I am now going to start testing the Bezier work
you so kindly did. It has taken me a while to be in a position to do so,
sorry.
…-------------
Brittle Gum Editing
***@***.***
darrengoossens.wordpress.com/brittle-gum-editing/
On Sat, 21 Aug 2021 at 04:35, Takuro Hosomi ***@***.***> wrote:
I revised https://github-wiki-see.page/m/veusz/veusz/wiki/DevStart
, reflecting your informative report.
I checked that I can make a devevopment environment on a fresh win 10 by
this recipie.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#547 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC7UXMAZSNH2S4VDHZOYQ3LT52N7VANCNFSM5BSLKXWQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email>
.
|
Thanks for the report. |
@jeremysanders |
Yes - I forgot |
Great experience with the Veusz community. Many thanks. It is appreciated. |
Hi. I really like Veusz. I am curious about how the smoothing seems to deliver some odd results at times. The attached image shows some lines drawn in Excel (top) and Veusz (bottom). I prefer Veusz over Excel almost always, but I think you can see that the smoothing here is Veusz is delivering some strange results. In particular, the big peak -- the line seems to go backwards, with the x value decreasing near (2015,0.125), which I think would be an arror in most circumstances. I cannot pretend to be able to offer a solution. If there is a sort of 'tension' parameter, that might help? Any advice welcome.
The text was updated successfully, but these errors were encountered: