|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
DanRRight
Joined: 10 Mar 2008 Posts: 2834 Location: South Pole, Antarctica
|
Posted: Wed May 05, 2021 4:56 am Post subject: Adjustable curve spline |
|
|
Would be good to add to the newnew %pl continuously adjustable smoothing of graph lines same way as very nicely in newnew %pl the antialiasing smoothing is done - you just click and see the effect. Something which with the slider you can adjust between link=lines and link=curves. I have no specific method in mind may be someone has an idea. The current default link=curves is too harshly smoothing everything very often causing severe distortions of lines compared to just linear interpolation between the points. In most my cases i can not use this option, specifically with the LOG plots, so i'm forced to use only simplest linear interpolation link=lines |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7938 Location: Salford, UK
|
Posted: Wed May 05, 2021 8:11 am Post subject: |
|
|
Dan
I am not clear about what you are asking for. At the moment there are 5 possible values for [smoothing=v] and these are v=0 to v=5.
There are 5 possible settngs for [line=s] and these are s="none", s="lines", s="curves", s="columns", s="bars" and s="user".
"lines" are straight lines.
"curves" are cardinal splines.
In theory you could set [lines=user] and then call draw_beziersD@ from a %pl callback function. But bezier splines are quite specialized and the control points and their number must be carefully chosen. The GDI+ function used in ClearWin+ for beziers is described here...
https://docs.microsoft.com/en-us/previous-versions//ms536147(v=vs.85).
p.s. I can't get the link to display correctly so a manual copy is required. |
|
Back to top |
|
|
jlb
Joined: 21 Oct 2020 Posts: 48
|
Posted: Wed May 05, 2021 9:36 am Post subject: |
|
|
Dan
May be you could have a look to the Akima method of interpolation and smooth, which is quite "soft", see Akima, H. (1970). A New Method of Interpolation and Smooth Curve Fitting Based on Local Procedures. Journal of the ACM, 17(4), pp. 589�602.
The link to the B�zier function used in GDI+ might be the following
https://docs.microsoft.com/en-us/previous-versions/ms536147(v=vs.85)
(v=vs.85) belongs to the URL, so use copy and paste. |
|
Back to top |
|
|
Kenneth_Smith
Joined: 18 May 2012 Posts: 697 Location: Hamilton, Lanarkshire, Scotland.
|
Posted: Wed May 05, 2021 10:27 am Post subject: |
|
|
Paul,
If the "curves" are cardinal splines, is there any possibility of providing a setting for the �tension� parameter? I think that may be what Dan is looking for. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7938 Location: Salford, UK
|
Posted: Wed May 05, 2021 11:08 am Post subject: |
|
|
Ken and Dan
It would be possible to add a cardinal spline tension parameter.
Please let me know if that would be useful. |
|
Back to top |
|
|
Kenneth_Smith
Joined: 18 May 2012 Posts: 697 Location: Hamilton, Lanarkshire, Scotland.
|
Posted: Wed May 05, 2021 1:51 pm Post subject: |
|
|
Paul,
This would certainly provide control over the path taken by [link=curves] and as such would be a valuable general addition to the %pl[native] functionality.
I have seen cases where the curve has �bowed out� and an increase in �tension� would have reduced that. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7938 Location: Salford, UK
|
Posted: Wed May 05, 2021 2:15 pm Post subject: |
|
|
Ken
OK. It should be fairly easy to implement.
I think that the tension parameter is 1.0 by default and 0.0 gives maximum tension - a straight line. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7938 Location: Salford, UK
|
Posted: Wed May 05, 2021 3:56 pm Post subject: |
|
|
Ken and Dan
I have added this feature and you can get new DLLs via the sticky post.
You can set the tension for each curve using...
Code: | CALL winop@("%pl[tension=1.0]") |
The setting for [link=v] becomes redundant when tension is added.
tension=0.0 is the same as [link=lines].
I had assumed the tension=1.0 would be the same as [link=curves] but my tests do not confirm this. |
|
Back to top |
|
|
Kenneth_Smith
Joined: 18 May 2012 Posts: 697 Location: Hamilton, Lanarkshire, Scotland.
|
Posted: Wed May 05, 2021 7:42 pm Post subject: |
|
|
Paul,
Thanks for this addition. A few quick tests confirm the expected responses (tests 2 and 3 below).
With n_graphs > 1 mixing the different approaches [link=lines/curves] and [tension=X] runs into problems (tests 4 and 5). Is this to be expected (and so mixing approaches avoided)?
For Dan�s �continuously adjustable smoothing of graph lines�, I wonder if the value of tension could be added to the parameters that can be changed by CHANGE_PLOT_DBL@ ?
Code: | !Tension test 05/05/2021
winapp
module test
use clrwin
implicit none
integer, parameter :: dp = kind(1.d0), n = 10
real(kind=dp) x_array(1:n), y_array(1:n)
integer :: npl(3) = n
contains
integer function plot()
integer iw
do iw = 1, n, 1 ; x_array(iw) = iw - 1 ; y_array(iw) = random@() ; end do
iw = winio@('Test 1&')
iw = winio@('%nl2 graphs %nlRED link=lines, BLUE link = curves&')
iw = winio@('%nlThis is the previous behaviour&')
call winop@('%pl[native,frame,etched,width=3,x_array,independent,n_graphs=2]')
call winop@('%pl[colour=red,link=lines,symbol=6]')
call winop@('%pl[colour=blue,link=curves]')
iw = winio@('%ff%pl&',800,600,npl,x_array,y_array,x_array,y_array)
iw = winio@('')
iw = winio@('Test 2&')
iw = winio@('%nl2 graphs, both have specified tension. %nlRED tension=0.0, BLUE tension=0.5&')
iw = winio@('%nlTension = 0 is equivalent to link=lines, and tension=0.5 is equivalent to link=curves&')
call winop@('%pl[native,frame,etched,width=3,x_array,independent,n_graphs=2]')
call winop@('%pl[colour=red,tension=0.0,symbol=6]')
call winop@('%pl[colour=blue,tension=0.5]')
iw = winio@('%ff%pl&',800,600,npl,x_array,y_array,x_array,y_array)
iw = winio@('')
iw = winio@('Test 3&')
iw = winio@('%nl3 graphs, all have specified tension&')
iw = winio@('%nlRED tension=0.0, BLUE tension=0.25, GREEN tension = 0.5&')
iw = winio@('%nlBlue curve has an intermediate tension between link=lines and link=curves&')
call winop@('%pl[native,frame,etched,width=3,x_array,independent,n_graphs=3]')
call winop@('%pl[colour=red,tension=0.0,symbol=6]')
call winop@('%pl[colour=blue,tension=0.25]')
call winop@('%pl[colour=green,tension=0.5]')
iw = winio@('%ff%pl&',800,600,npl,x_array,y_array,x_array,y_array,x_array,y_array)
iw = winio@('')
iw = winio@('Test 4&')
iw = winio@('%nl2 graphs, mixing link=lines and tension %nlRED link = lines, BLUE tension=0.0&')
iw = winio@('%nlRED line is correct, BLUE line is the same as previous link=curves, but should be like link=lines&')
call winop@('%pl[native,frame,etched,width=3,x_array,independent,n_graphs=2]')
call winop@('%pl[colour=red,link=lines,symbol=6]')
call winop@('%pl[colour=blue,tension=0.0]')
iw = winio@('%ff%pl&',800,600,npl,x_array,y_array,x_array,y_array)
iw = winio@('')
iw = winio@('Test 5&')
iw = winio@('%nl2 graphs, mixing link=curves and tension %nlRED link = curves, BLUE tension=0.0&')
iw = winio@('%nlRed is linked with lines instead of curves.&')
iw = winio@('Blue curve looks like tension=0.5 rather than tension=0&')
call winop@('%pl[native,frame,etched,width=3,x_array,independent,n_graphs=2]')
call winop@('%pl[colour=red,link=curves,symbol=6]')
call winop@('%pl[colour=blue,tension=0.0]')
iw = winio@('%ff%pl&',800,600,npl,x_array,y_array,x_array,y_array)
iw = winio@('')
plot = 1
end function plot
end module test |
|
|
Back to top |
|
|
DanRRight
Joined: 10 Mar 2008 Posts: 2834 Location: South Pole, Antarctica
|
Posted: Wed May 05, 2021 11:55 pm Post subject: |
|
|
Thanks all for help, discussion and solutions,
Paul, this tension adjustment works exactly how i wanted it, you've done great job. Would be nice to add it to newest %pl (the Designer %pl how you call it?). Adjusting the smoothing with the slider for anyone liking would be great
The only major thing i'd change in the designer is how it is made to adjust the plot: the visual way where user clicks on picture (be it line or axis or title etc) and change parameters in the supplied popup box would be much better and faster and more pleasant to do! Here is a "reference plot" what should pop first when user clicks on "Adjust" icon
We users can make nicer example picture for it.
Other minor suggestions: after some testing i'd also add to Designer some switch of Linear to LOG plots, title and axis names change, font change and saving the plot into png and jpg formats - that would be almost all essential things which are now missing. And ESC has to be added to quit Designer mode. This new PL will be then a bomb !
UPDATE
BTW, here is the text for snapshot i use with %PL. Filenames are automatically updated each time. Ideally this name has to be the same as in %pl[file=zDesignerPL.set... the "DDrates.date.time.png" as in my case below so they will be easier to find among 1000s of others
Code: | use clrwin
integer, external :: SnapshotPL
parameter (N=6)
real*8 X(N), Y(N)
Data X/1., 1e1, 1e2, 1e3, 1e4, 1e5/
Data Y/0.01, 10.2, 1266, 8333, 2111, 77/
i=winio@('%ww%pv%pl[file=DDrates.set,title="D-D fusion",x_axis="Energy (keV)", &
& y_axis="Fusion crs",x_array,scale=log_log,n_graphs=1,y_min=1.e-2,y_max=1.e4]&', &
480,360, n, X, Y)
i=winio@('%ff%cn%^tt[Snapshot]%es', SnapshotPL)
end
!......................................................
! ____ __ _ __ ____ ____ _ _ __ ____
! / ___)( ( \ / _\ ( _ \/ ___)/ )( \ / \ (_ _)
! \___ \/ // \ ) __/\___ \) __ (( O ) )(
! (____/\_)__)\_/\_/(__) (____/\_)(_/ \__/ (__)
!......................................................
integer function SnapshotPL ()
use clrwin
character PNGfilename*256, chdate*8, chtime*10, chzone*5
integer ivalues(8)
call DATE_AND_TIME(chdate, chtime, chzone, ivalues ) ! chdate format 20210504
PNGfilename = 'zDesignerPL_'//chdate(1:8)//'_'//chtime(1:6)//'.png'
i = export_image@(trim(PNGfilename))
call sound@(3000,1)
call sound@(1000,1)
call sound@(2000,1)
SnapshotPL = 2
end function |
Last edited by DanRRight on Thu May 06, 2021 9:19 pm; edited 1 time in total |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7938 Location: Salford, UK
|
Posted: Thu May 06, 2021 7:38 am Post subject: |
|
|
Ken and Dan
Thank you for the feedback. I will see what can be done.
The idea of interacting with the graph when in design mode would "take it to another level" as they say on Youtube. But I will give this some thought. |
|
Back to top |
|
|
Kenneth_Smith
Joined: 18 May 2012 Posts: 697 Location: Hamilton, Lanarkshire, Scotland.
|
Posted: Thu May 06, 2021 11:02 am Post subject: |
|
|
This example illustrates (by a different more complex route), what was behind my thoughts for requesting changing the tension value via CHANGE_PLOT_DBL@
Code: | !Tension + slider 06/05/2021
winapp
module test
use clrwin
implicit none
integer, parameter :: dp = kind(1.d0), n = 11
real(kind=dp) x_array(1:n), y_array(1:n)
real(kind=dp) :: tension = 0.d0
integer :: uid1=1000, uid2=1001
contains
integer function plot()
integer iw
do iw = 1, n, 1 ; x_array(iw) = iw - 1 ; y_array(iw) = random@() ; end do
iw = winio@('%mn[Exit]&','exit')
iw = winio@('%2.1ob[invisible]&')
iw = winio@('%`gr&',800,600,uid2)
iw = winio@('%cb&')
iw = winio@('Tension%nl%`5rf&',tension)
iw = winio@('%nl%^24sl[vertical]&',tension,0.d0,1.d0, create_pl)
iw = winio@('%sc&',create_pl)
iw = winio@('%cb&')
iw = winio@('')
plot = 1
end function plot
integer function create_pl()
integer i, iw, control
character(len=28) ten_string
write(ten_string,'("%pl[tension=",F5.3,"]")') tension
i = create_graphics_region@(uid1,800,600)
call winop@('%pl[native,frame,etched,gridlines,width=3,x_array,independent,n_graphs=1]')
call winop@(ten_string)
call winop@('%pl[colour=blue,symbol=6]')
call winop@('%pl[x_min=0,x_max=10,dx=2,y_min=0,y_max=1]')
iw = winio@('%ff%pl[external]&',n,x_array,y_array)
iw = winio@('%lw&', control)
iw = winio@('')
i = COPY_GRAPHICS_REGION@(uid2, 1, 1, 800, 600, &
uid1, 1, 1, 800, 600, &
13369376 )
i = DELETE_GRAPHICS_REGION@(uid1)
create_pl = 1
end function create_pl
end module test
program main
use test
i = plot()
end program main |
|
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7938 Location: Salford, UK
|
Posted: Thu May 06, 2021 1:47 pm Post subject: |
|
|
Ken
I have fixed the issue illustrated in your first sample. The line index for the tension was not in sync. I have also added the option "tension" to CHANGE_PLOT_DBL@. I will provide new DLLs shortly so that you can see if it does what you want. I have also added draw_curves2D@ which is like draw_curvesD@ but with an extra double precision argument for the tension. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7938 Location: Salford, UK
|
Posted: Thu May 06, 2021 2:42 pm Post subject: |
|
|
Dan
I have considered your suggestions for improvement. Unfortunately even your simplest request (to add tension to the designer) would take more that half a day's work. Extending the designer to interact with the graph would take a week or more. So, as is often the case, there would be a vast amount of work for very little gain. |
|
Back to top |
|
|
DanRRight
Joined: 10 Mar 2008 Posts: 2834 Location: South Pole, Antarctica
|
Posted: Thu May 06, 2021 11:38 pm Post subject: |
|
|
Ken,
That functionality with the slider in Designer mode like in your last example is what i was talking about. Hopefully with the new addition Paul added this will be much easier to implement in regular Programming mode too
Paul,
Of course all beautifications and perfections take a lot of time to implement. It might take weeks, months and years till you'll say that it's completely done.
Meantime can you please look at this my demo example above because it exposes some defect of %pl ? It works initially but if you change something like position of X or Y axis in Designer mode, it fails. There exist a problem with LOG plotting in %pl, it often claims negative values where there actually are none even without smoothing like in my example. Smoothing often can generate some part of plot being below zero and plot fails in LOG mode and offers to switch to linear mode. Solution for that is to check the plotting data limits after smoothing plus the user has to set externally y_min=positive_value (ideally such message has to appear as a warning). Currently even setting y_min does not help
Similar visually but different by nature effect also exists in "linear" plotting for both x and y too when due to smoothing the curve may get way out of frame or axis limits. I suspect that PL has some defect while checking plotting limits. To demonstrate that effect it is necessary to take the function with sharp peak. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|