Problems with outline rasterizer

View: New views
6 Messages — Rating Filter:   Alert me  

Problems with outline rasterizer

by Jim Barry-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Folks,

I noticed that the outline rasterizer fails to draw empty (or nearly-empty) rectangles. For example, consider a rectangle with vertices ABCD and zero height. The sequence of events goes like this:

1) Add vertex A to path. Vertex list is now "A".

2) Add vertex B to path. Vertex list is now "AB".

3) Add vertex C to path - A and B are coincident so vertex B is removed. Vertex list is now "AC".

4) Add vertex D to path. Vertex list is now "ACD".

5) Process path_cmd_end_poly:
 - rasterizer_outline_aa<>::render closes the path
 - vertex_sequence<>::close sees that C and D are coincident and removes vertex C
 - Vertex list is now "AD"
 - rasterizer_outline_aa<>::render no-ops because vertex count < 3

I propose changing the logic in rasterizer_outline_aa<>::render from this:

  if(close_polygon)
  {
    if(m_src_vertices.size() >= 3)
    {
       // ...
    }
  }
  else
  // ...

to this:

  if(close_polygon && (m_src_vertices.size() >= 3))
  {
    // ...
  }
  else
  // ...

Now the zero-height rectangle will be drawn as a line. Does this seem like a reasonable fix, or might it cause other problems?

Also, the outline rasterizer will "optimize" away rectangles with single-pixel width/height, because it considers points at a distance of 1.5 times the subpixel scale or closer to be coincident. Presumably Maxim had a reason for choosing this threshold, but I propose changing line_aa_vertex::operator() from this:

  bool operator () (const line_aa_vertex& val)
  {
    float_type dx = val.x - x;
    float_type dy = val.y - y;
    return (len = uround(sqrt(dx * dx + dy * dy))) >
      (line_subpixel_scale + line_subpixel_scale / 2);
  }

to this:

  bool operator () (const line_aa_vertex& val)
  {
    float_type dx = val.x - x;
    float_type dy = val.y - y;
    return (len = uround(sqrt(dx * dx + dy * dy))) >= line_subpixel_scale;
  }

Comments?

- Jim

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Vector-agg-general mailing list
Vector-agg-general@...
https://lists.sourceforge.net/lists/listinfo/vector-agg-general

Re: Problems with outline rasterizer

by Stephan Assmus :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

On 2009-06-10 at 15:29:56 [+0200], Jim Barry <jim@...> wrote:

> I noticed that the outline rasterizer fails to draw empty (or
> nearly-empty) rectangles. For example, consider a rectangle with vertices
> ABCD and zero height. The sequence of events goes like this:
>
> 1) Add vertex A to path. Vertex list is now "A".
>
> 2) Add vertex B to path. Vertex list is now "AB".
>
> 3) Add vertex C to path - A and B are coincident so vertex B is removed.
> Vertex list is now "AC".
>
> 4) Add vertex D to path. Vertex list is now "ACD".
>
> 5) Process path_cmd_end_poly:
>  - rasterizer_outline_aa<>::render closes the path
>  - vertex_sequence<>::close sees that C and D are coincident and removes
>  vertex C
>  - Vertex list is now "AD"
>  - rasterizer_outline_aa<>::render no-ops because vertex count < 3
>
> I propose changing the logic in rasterizer_outline_aa<>::render from this:
>
>   if(close_polygon)
>   {
>     if(m_src_vertices.size() >= 3)
>     {
>        // ...
>     }
>   }
>   else
>   // ...
>
> to this:
>
>   if(close_polygon && (m_src_vertices.size() >= 3))
>   {
>     // ...
>   }
>   else
>   // ...
>
> Now the zero-height rectangle will be drawn as a line. Does this seem
> like a reasonable fix, or might it cause other problems?
>
> Also, the outline rasterizer will "optimize" away rectangles with
> single-pixel width/height, because it considers points at a distance of
> 1.5 times the subpixel scale or closer to be coincident. Presumably Maxim
> had a reason for choosing this threshold, but I propose changing
> line_aa_vertex::operator() from this:
>
>   bool operator () (const line_aa_vertex& val)
>   {
>     float_type dx = val.x - x;
>     float_type dy = val.y - y;
>     return (len = uround(sqrt(dx * dx + dy * dy))) >
>       (line_subpixel_scale + line_subpixel_scale / 2);
>   }
>
> to this:
>
>   bool operator () (const line_aa_vertex& val)
>   {
>     float_type dx = val.x - x;
>     float_type dy = val.y - y;
>     return (len = uround(sqrt(dx * dx + dy * dy))) >= line_subpixel_scale;
>   }
>
> Comments?

Both changes sound fine to me, although you have obviously spend more time
researching this than me. ;-)

Best regards,
-Stephan

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Vector-agg-general mailing list
Vector-agg-general@...
https://lists.sourceforge.net/lists/listinfo/vector-agg-general

Re: Problems with outline rasterizer

by Pierre Arnaud :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Your changes seem reasonable. A zero height or zero width rectangle should
indeed have an outline, even if it has no surface and filling it should not
draw anything...

I've no idea why Maxim chose the "1.5 times the subpixel scale"; I'd advise
to be cautious. Does anybody have a large set of tests based on the outline
rasterizer, so that we could check if applying your changes breaks anything?


> -----Original Message-----
> From: Jim Barry [mailto:jim@...]
> Sent: Wednesday, June 10, 2009 3:30 PM
> To: Anti-Grain Geometry
> Subject: [AGG] Problems with outline rasterizer
>
> Hi Folks,
>
> I noticed that the outline rasterizer fails to draw empty (or nearly-
> empty) rectangles. For example, consider a rectangle with vertices ABCD
> and zero height. The sequence of events goes like this:
>
[...]

>
> Now the zero-height rectangle will be drawn as a line. Does this seem
> like a reasonable fix, or might it cause other problems?
>
> Also, the outline rasterizer will "optimize" away rectangles with
> single-pixel width/height, because it considers points at a distance of
> 1.5 times the subpixel scale or closer to be coincident. Presumably
> Maxim had a reason for choosing this threshold, but I propose changing
> line_aa_vertex::operator() from this:
>
>   bool operator () (const line_aa_vertex& val)
>   {
>     float_type dx = val.x - x;
>     float_type dy = val.y - y;
>     return (len = uround(sqrt(dx * dx + dy * dy))) >
>       (line_subpixel_scale + line_subpixel_scale / 2);
>   }
>
> to this:
>
>   bool operator () (const line_aa_vertex& val)
>   {
>     float_type dx = val.x - x;
>     float_type dy = val.y - y;
>     return (len = uround(sqrt(dx * dx + dy * dy))) >=
> line_subpixel_scale;
>   }
>
> Comments?
>
> - Jim


------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Vector-agg-general mailing list
Vector-agg-general@...
https://lists.sourceforge.net/lists/listinfo/vector-agg-general

Re: Problems with outline rasterizer

by Jim Barry-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Stephan Assmus wrote:
> Both changes sound fine to me, although you have obviously spend more
> time researching this than me. ;-)

Thanks Stephan. In the end, I decided not to use the outline rasterizer because of its various limitations, specifically its inaccurate joins and poor handling of acute angles. Do you think the changes are worth checking in, or is it best just to leave things alone?

- Jim

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Vector-agg-general mailing list
Vector-agg-general@...
https://lists.sourceforge.net/lists/listinfo/vector-agg-general

Parent Message unknown Re: Problems with outline rasterizer

by Jim Barry-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Pierre Arnaud wrote:
> I've no idea why Maxim chose the "1.5 times the subpixel scale"; I'd
> advise to be cautious. Does anybody have a large set of tests based
> on the outline rasterizer, so that we could check if applying your
> changes breaks anything?

As I understand it, the outline rasterizer is mainly intended for drawing contour lines on maps and that kind of thing. I think the idea of the 1.5x threshold is to Maxim-ize the number of vertices that can be skipped, without the result becoming too noticeable. Perhaps the threshold should be configurable...

- Jim

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Vector-agg-general mailing list
Vector-agg-general@...
https://lists.sourceforge.net/lists/listinfo/vector-agg-general

Re: Problems with outline rasterizer

by jbarbara :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks!

This fix just fixed an outline text issue I was having where all lowercase i's and l's outline didn't not appear.  Must have been optimized away!

I had only just started digging into the code when I saw this post thought I would give it a try!

Joe

Jim Barry-2 wrote:
Hi Folks,

I noticed that the outline rasterizer fails to draw empty (or nearly-empty) rectangles. For example, consider a rectangle with vertices ABCD and zero height. The sequence of events goes like this:

1) Add vertex A to path. Vertex list is now "A".

2) Add vertex B to path. Vertex list is now "AB".

3) Add vertex C to path - A and B are coincident so vertex B is removed. Vertex list is now "AC".

4) Add vertex D to path. Vertex list is now "ACD".

5) Process path_cmd_end_poly:
 - rasterizer_outline_aa<>::render closes the path
 - vertex_sequence<>::close sees that C and D are coincident and removes vertex C
 - Vertex list is now "AD"
 - rasterizer_outline_aa<>::render no-ops because vertex count < 3

I propose changing the logic in rasterizer_outline_aa<>::render from this:

  if(close_polygon)
  {
    if(m_src_vertices.size() >= 3)
    {
       // ...
    }
  }
  else
  // ...

to this:

  if(close_polygon && (m_src_vertices.size() >= 3))
  {
    // ...
  }
  else
  // ...

Now the zero-height rectangle will be drawn as a line. Does this seem like a reasonable fix, or might it cause other problems?

Also, the outline rasterizer will "optimize" away rectangles with single-pixel width/height, because it considers points at a distance of 1.5 times the subpixel scale or closer to be coincident. Presumably Maxim had a reason for choosing this threshold, but I propose changing line_aa_vertex::operator() from this:

  bool operator () (const line_aa_vertex& val)
  {
    float_type dx = val.x - x;
    float_type dy = val.y - y;
    return (len = uround(sqrt(dx * dx + dy * dy))) >
      (line_subpixel_scale + line_subpixel_scale / 2);
  }

to this:

  bool operator () (const line_aa_vertex& val)
  {
    float_type dx = val.x - x;
    float_type dy = val.y - y;
    return (len = uround(sqrt(dx * dx + dy * dy))) >= line_subpixel_scale;
  }

Comments?

- Jim

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Vector-agg-general mailing list
Vector-agg-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vector-agg-general