Skip to main content

[JAVA2D] Efficient pattern painting and continous stroke patterns

2 replies [Last post]
Anonymous

Hi,

I need to fill regions with simple, two colored patterns, such as
horizontal/vertical/diagonal lines, crosses, diagonal crosses, etc. The
patterns have to be continous among several paint operations, which
means that if I fill an area and then a second area that intersects with
the first, the lines of the pattern should be horizontally and
vertically continous. The shapes that need to be filled will be
rectangular.

Should I paint tiles using a buffered image? Or is drawing all the lines
using g.drawLine() the way to go? Or should I use my very own special
Paint class?

And as a second question: When painting strokes, how can I make sure
that the stroke pattern is continous among several paint operations?
Let's say I first paint a line from x=10 to x=23, then from x=24 to
x=50. How can I make sure the stroke pattern does not restart at 24?
Would translating the Graphics object change anything? Clipping? Setting
a transform? Or more general: What parameters determe the starting point
of a stroke pattern?

Any ideas are welcome

Jan

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mgrev
Offline
Joined: 2003-08-12

Hi Jan,

If you want speed, and I know you do, you should stay away from painting a lot of pixels with a custom Stroke. At least on my setup (FireGL 256t, WindowsXP) doing that is dog slow.

Going with a buffered image, that are managed, as a tile is very fast and I think the preferref way, if you can solve the aligning, which depending on context might not be possible since non |- lines would possibly require a BI with a "float" size wich is not possible.

If you do use lines (solid) do them all after one another without changing anything in the graphics object. If so the lines will be sent to the gfx card in a "bunch" and it will be quite fast.

Best of luck Jan.

Btw, any "custom paint" (such as GradientPaint) will NOT be hardware accelerateable until the OpeGL pipeline is ready, wich is not i quite a while.

Cheers,
Mikael Grev

Jim Graham

Hi Jan,

If you are talking about the "patterns" that are available by installing a
BasicStroke object (basically just dashing), then it always calculates the
dashing pattern based on the start of the path and its "starting offset"
parameter. You can adjust the starting offset and install a new
BasicStroke between rendering calls to make the dashing patterns agree with
each other, but the Stroke interface is not designed to deal with lining up
patterns in device space. A custom Stroke object (i.e. not the built-in
BasicStroke) could attempt to ensure consistency between shapes by assuming
that the same coordinate transform is in effect between calls, but that
would be hard to calculate.

You can also make patterns on lines using the Paint interface. Unlike the
Stroke interface, Paint is designed to be able to support consistency
between operations by giving the Paint object enough information to work in
either user coordinates or device coordinates. Our built-in GradientPaint
and TexturePaint objects should have very good consistency of the patterns
for overlapping renderings and should do so regardless of clip. Both will
interpret the coordinates you construct them with as being coordinates in
"user coordinates" so if you change the transform between rendering
operations then they will change their operation to match the change in the
transform. But for any given transformation, they should remain consistent
between rendering operations with that given transformation.

...jim

--On Monday, November 01, 2004 2:56 PM +0100 "\"Jan Bösenberg (INCORS
GmbH)\"" wrote:

> Hi,
>
> I need to fill regions with simple, two colored patterns, such as
> horizontal/vertical/diagonal lines, crosses, diagonal crosses, etc. The
> patterns have to be continous among several paint operations, which
> means that if I fill an area and then a second area that intersects with
> the first, the lines of the pattern should be horizontally and
> vertically continous. The shapes that need to be filled will be
> rectangular.
>
> Should I paint tiles using a buffered image? Or is drawing all the lines
> using g.drawLine() the way to go? Or should I use my very own special
> Paint class?
>
> And as a second question: When painting strokes, how can I make sure
> that the stroke pattern is continous among several paint operations?
> Let's say I first paint a line from x=10 to x=23, then from x=24 to
> x=50. How can I make sure the stroke pattern does not restart at 24?
> Would translating the Graphics object change anything? Clipping? Setting
> a transform? Or more general: What parameters determe the starting point
> of a stroke pattern?
>
> Any ideas are welcome
>
>
> Jan
>
> =========================================================================
> ==
> To unsubscribe, send email to listserv@java.sun.com and include in the
> body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".