Jump to content
Paint.NET 5.1 is now available! ×

Recommended Posts

Posted

'Bentley' - beta for 'Bezncurve' update

I am starting a thread to discuss possible improvements to the 'Bezncurve' plugin I recently published here:

http://forums.getpaint.net/index.php?/topic/26457-bezncurve-6-control-points-new-21st-may-2013/
To avoid confusion with the published version I have called this 'Bentley'.
I have attached the VS CS file and the new .dll file (with grey construction lines as suggested by Midora).

I would like to stress that I am new to Visual studio so there will be horrible mistakes in the code.
All are welcome to change and 'play' with the code to suit their own needs (maybe adding more control points) - it is only setting the start/end control point of Bezier in the middle of the points either side (just the simplest way to ensure all 3 are in a straight line).

Questions:
1. Is it correct to dispose of the pens and graphics surface g, or is that automatically done when PDN stops using the effect?
2. Is there an easy way to make the 'grayPen' construction lines dotted?
3. Any other glaring mistakes?
4. If anyone would like the challenge of creating a full size interactive U.I. I'm sure users would appreciate it and the example code would be invaluable. (I haven't got a clue about WPF, forms, eventargs etc. and would make a complete hash of it!).
 

Bentley.zip

BentleyC#code.zip

 

Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings

 

PdnForumSig2.jpg

Posted

(I haven't looked at the code so I'm responding in a general sense)

 

1. If you created the object then you should dispose it. This does not affect "correctness" but it is a good optimization. (Also, key word is "should" ... this isn't required)

1a. If you didn't create an object, and there's no clear indication that "ownership" has been transferred to you, then you should not dispose it.

1b. When in doubt, don't call Dispose() on objects you didn't create or that you've handed out to other components. Probably doesn't apply here.

 

2. If you want to make a Pen that draws with dashes, use the Pen.DashStyle property. You can also do further customization with other properties. http://msdn.microsoft.com/en-us/library/system.drawing.pen.dashstyle.aspx

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Posted

I've always intended to create separate VS templates for a Windows Form UI vs IndirectUI.  Unfortunately, I'm a great procrastinator and always find something else to do.

 

Would you like to collaborate on a Bentley port?  You would get to figure out some Forms stuff, and I'll get a kick into starting the Forms template.

 

 

The "Mercedes Benz" port :lol:

Posted (edited)

If you are creating temporary object like pens of file handles you may use the 'using' directive

            using (var pen = (Pen)Pens.Red.Clone()) { ... }

because its scope controls the lifetime of these objects. Means they are disposed at the end of the block.

 

Nice to see the construction lines. But now there are too many ;-) The tangents are the important ones because they are defining the black control points. In a typical UI you would activate a black control point which then shows the tangent of this point including the two end points of the tangent.

 

Rick stalked in his blog about the new shape tool. There ou can see a curve shape. But I do not expect that 4.0 allows to control the amount of control points and tangents.

 

One additional remark: I would allow to control the points on the curve and just one end of the tangents. This way the user already knows that half of the points are on the curve (see attachment). And you avoid the difference between the open and the closed curve. Moving one control point of the line should move the associated control point by the same amount. Moving the associated point relativ to it curve point changes curvature and flatness.

 

post-79572-0-43306900-1369292085_thumb.j

Edited by midora

midoras signature.gif

Posted

Converted it to a Visual Studio 2010 solution for you. 

BentleySrc.zip

 

The Pens have been moved into the effect class and are disposed when the effect closes, and the surface copying has been moved to OnSetRenderInfo so it can be done all at once.

Also the Graphics object now uses the built-in DstArgs field that Paint.NET disposes, along with some minor cleanup / renaming of the generated CodeLab code. :)

PdnSig.png

Plugin Pack | PSFilterPdn | Content Aware Fill | G'MICPaint Shop Pro Filetype | RAW Filetype | WebP Filetype

The small increase in performance you get coding in C++ over C# is hardly enough to offset the headache of coding in the C++ language. ~BoltBait

 

Posted

 the surface copying has been moved to OnSetRenderInfo so it can be done all at once.

 

This raises a general question, which may be of interest for the developers.

 

What's the proposed method to copy the source:

- doing one call in OnSetRenderInfo() to copy the whole surface

- doing dst.CopySurface(src, renderRect.Location, renderRect); in OnRender() for each rectangle in the list.

 

The first one may be a little bit faster on a single core but the second one on multi core plus it is faster to abort (I guess Paint.NET aborts current rendering if the UI forces a new FinishTokenUpdate()).

midoras signature.gif

Posted (edited)

One additional tip: Use a GraphicsPath for the closed curves to avoid the caps at the end of the line (you mentioned this issue in the description of the original plugin).

 

using (GraphicsPath gp = new GraphicsPath())
{
    gp.StartFigure();
    gp.AddBeziers(closedBezPoints);
    gp.CloseFigure();
    g.DrawPath(priPen, gp);
}
Edited by midora

midoras signature.gif

Posted

Rick -     Many thanks for the general advice as to when and what to dispose. I will experiment with the Pen.DashStyle properties too.

EER -     Re Templates - If I can help in anyway, I will.

Midora - I like the 'using' block idea to ensure things are correctly disposed and may try using it in future.

             I'm afraid you lost me a bit regarding the control points and tangents. As I understand, the black control points could be anywhere along the line between the control points on either side but I opted to put them halfway purely for simplicity and to reduce the number of controls required on the U.I.  I also like the idea of the 'GraphicsPath', and many thanks for the example code.

Null54 -  Thank you! - I have only just had a chance to download this and have a quick look through the changes. The  comments seem to answer most of my questions. I used your 'clipwarp' VS files as a template for both this and 'BevelObject' (without the extra surfaces), so having this example in the same 'style' of layout should make things more understandable.

Thank you all again.
 

 

Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings

 

PdnForumSig2.jpg

Posted



I have built the version of 'Bentley' from the source files very kindly provided by Null54.
The problem is that when running the effect it works as intended until I try to render (by clicking on the OK button).
It doesn't render anything and I can't work out why?

Null54 - did the compiled .dll do this on your system or have I changed something or set it up incorrectly?
(I didn't notice on the first few test of the .dll as it looked o.k. and I didn't render.)

I have tried it both with and without the changes I have made - both behave the same way.
I added an 'else if' to get the antialiasing to turn off and used Midora's graphics path code for the closed Bezier.
These work well until I try to render.

I am, of course, still very grateful for the work you have put in.
Perhaps something is being disposed of before the dst surface is rendered?
Bentley.zip


I also included Midora's graphic path idea in my source code for Bezncurve - I had to use 'pdnGraphicsPath' as intellisense wouldn't recognize 'GraphicsPath' in this version. I have disposed of the pens but not the PdnGraphicsPath or 'g' - thinking that will be handled by PDN itself - is that correct?
I thought the 'g.Clip = new Region(rect);' would mean GDI+ is effectively being used single threadedly?
This works as expected and renders normally.
Bezncurve.zip


The 'bug' I referred to when I originally published Bezncurve may be the correct behaviour - it just looks wrong as it so different depending on line width. It happens when the control points are very close together and using a very large line width. Example:
nkaht2G.jpg

 

The other'bug' where the closed Bezier didn't close properly is fixed by Midora's suggestion of using a graphics path.

Thanks again

 

 

Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings

 

PdnForumSig2.jpg

Posted

I have built the version of 'Bentley' from the source files very kindly provided by Null54.

The problem is that when running the effect it works as intended until I try to render (by clicking on the OK button).

It doesn't render anything and I can't work out why?

 

That's an interesting problem. OnRender() will be called the expected number of times after Ok but the length parameter is always zero which means that Render() will never be called. (I tested the Null54 original project).

 

 

 I had to use 'pdnGraphicsPath' as intellisense wouldn't recognize 'GraphicsPath' in this version. I have disposed of the pens but not the PdnGraphicsPath or 'g' - thinking that will be handled by PDN itself - is that correct?

 

GraphicsPath should be there if you are adding "using "System.Drawing.Drawing2D".

If you are creating a new  object than you should dispose it.

 

 

I thought the 'g.Clip = new Region(rect);' would mean GDI+ is effectively being used single threadedly?

 

I guess you are mixing something here. Clip() just defines the area of output not the gdi problem that two threads may share the same object like a pen. BTW g.SetClip( rect) does the same, there is no need to create a new region.

 

I never used GDI+ single threaded. But this means that each OnRender has to use its own set of objects.

 

There are bugs and flaws in GDI+ but at the end it is easy to use.

  • Upvote 1

midoras signature.gif

Posted

I have built the version of 'Bentley' from the source files very kindly provided by Null54.

The problem is that when running the effect it works as intended until I try to render (by clicking on the OK button).

It doesn't render anything and I can't work out why?

 

It turns out that the source surface was being copied when Paint.NET skips rendering after the dialog closes.

I have updated the code in my first post to fix this problem.

 

  • Upvote 1

PdnSig.png

Plugin Pack | PSFilterPdn | Content Aware Fill | G'MICPaint Shop Pro Filetype | RAW Filetype | WebP Filetype

The small increase in performance you get coding in C++ over C# is hardly enough to offset the headache of coding in the C++ language. ~BoltBait

 

Posted

Many, many thanks both of you - I will download the new version, Null54.

 

I'm still a little unsure as to what to dispose (and what is handled by pdn) - however if I am using  Null54's code, I can use the straight forward GraphicsPath and dispose of it in the OnDispose block along with the pens. - but not Graphics 'g'.

 

 

Haven't looked at the new code yet, but many thanks in advance!

 

Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings

 

PdnForumSig2.jpg

Posted

Many, many thanks both of you - I will download the new version, Null54.

 

I'm still a little unsure as to what to dispose (and what is handled by pdn) - however if I am using  Null54's code, I can use the straight forward GraphicsPath and dispose of it in the OnDispose block along with the pens. - but not Graphics 'g'.

 

 

Haven't looked at the new code yet, but many thanks in advance!

 

The Graphics 'g' variable is an alias for DstArgs.Graphics which will be disposed by Paint.NET.

PdnSig.png

Plugin Pack | PSFilterPdn | Content Aware Fill | G'MICPaint Shop Pro Filetype | RAW Filetype | WebP Filetype

The small increase in performance you get coding in C++ over C# is hardly enough to offset the headache of coding in the C++ language. ~BoltBait

 

Posted

I have updated the 'Bezncurve' .dll in the publishing thread - it is very similar to the recent versions here.
I was going to upload the full VS project file here but it seems to be too big?

I intend to explore a custom U.I for this (hopefully working with EER) and will post any developements back here.

Many thanks to all that have helped particularly Null54 and Midora - much appreciated.

 

Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings

 

PdnForumSig2.jpg

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...