BSD

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • How to trim a bezier path?

    7 answers - 772 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    I have a small app which collects temperature data and graphs it over
    time. As I collect new data, I append it to an existing path. If I
    run this app for many days the bezier path gets large and eats up a
    lot of memory. What I want to do is set a limit of how much data I
    display (maybe a day or two) and once I reach that begin removing
    points from the beginning of the path as I add points to the end of it.
    Is there a simple way to do this?
    Thanks,
    Jim
    Do not post admin requests to the list. They will be ignored.
    Cocoa-dev mailing list (Cocoa-dev (AT) lists (DOT) apple.com)
    Help/Unsubscribe/Update your Subscription:
    %40developershed.com
    This email sent to bsdarchive (AT) developershed (DOT) com
  • No.1 | | 983 bytes | |

    Dec 7, 2005, at 7:26 AM, Jim Marschke wrote:

    I have a small app which collects temperature data and graphs it
    over time. As I collect new data, I append it to an existing
    path. If I run this app for many days the bezier path gets large
    and eats up a lot of memory. What I want to do is set a limit of
    how much data I display (maybe a day or two) and once I reach that
    begin removing points from the beginning of the path as I add
    points to the end of it.

    Is there a simple way to do this?

    Instead of storing your data inside the path, store the data in your
    own storage area and generate the path from the last few points of
    that storage area.

    Scott

    Do not post admin requests to the list. They will be ignored.
    Cocoa-dev mailing list (Cocoa-dev (AT) lists (DOT) apple.com)
    Help/Unsubscribe/Update your Subscription:
    %40developershed.com

    This email sent to bsdarchive (AT) developershed (DOT) com
  • No.2 | | 2204 bytes | |

    Dec 7, 2005, at 8:50 AM, Jim Marschke wrote:

    But that means every time I want to draw the path I have to
    recreate it. That can take a while when I have thousands of points
    -- and multiple paths. The path itself seems to be a great storage
    area, and when I resize I just do a transform rather than
    rebuilding. There are easy ways to append data to a path, I was
    hoping someone knew of a way to remove data.

    Jim

    More likely than not, it is a much better idea to recreate the path
    from the data every time.

    Let's say you have 10,000 data points. It is the case that creating
    a path from those 10,000 points will take some time. However, since
    a wide monitor is only on the order of 1000 pixels wide, it is very
    unlikely that even if you were to display the path of 10,000 points
    that the user would be able to glean 10,000 points worth of useful
    information from seeing it drawn on the screen.

    A much better strategy would be to filter the 10,000 points depending
    on how you plan to display them. In the example above, you could
    choose every 10th point, or average 10 points, or any of a number of
    other strategies to generate a path of only 1000 points.

    For a path of 10,000 points, there are other considerations. When
    you draw a path, the drawing model guarantees that each pixel
    affected by the path will be drawn exactly once. This requires the
    computer to check the path for self intersections and such. In
    drawing a path of 10,000 points in a window that is 1000 pixels wide
    these calculations can yield very poor performance.

    Reasons like these should help you to understand that the bezier path
    classes are not intended to be repositories for model data. In the
    long run, you will probably do yourself a favor by using the bezier
    classes for drawing, and managing your data yourself.

    Scott

    Do not post admin requests to the list. They will be ignored.
    Cocoa-dev mailing list (Cocoa-dev (AT) lists (DOT) apple.com)
    Help/Unsubscribe/Update your Subscription:
    %40developershed.com

    This email sent to bsdarchive (AT) developershed (DOT) com
  • No.3 | | 1477 bytes | |

    But that means every time I want to draw the path I have to recreate
    it. That can take a while when I have thousands of points -- and
    multiple paths. The path itself seems to be a great storage area,
    and when I resize I just do a transform rather than rebuilding.
    There are easy ways to append data to a path, I was hoping someone
    knew of a way to remove data.

    Jim

    Dec 7, 2005, at 7:26 AM, Jim Marschke wrote:
    >
    >I have a small app which collects temperature data and graphs it
    >over time. As I collect new data, I append it to an existing
    >path. If I run this app for many days the bezier path gets large
    >and eats up a lot of memory. What I want to do is set a limit of
    >how much data I display (maybe a day or two) and once I reach that
    >begin removing points from the beginning of the path as I add
    >points to the end of it.
    >>

    >Is there a simple way to do this?
    >

    Instead of storing your data inside the path, store the data in
    your own storage area and generate the path from the last few
    points of that storage area.

    Scott

    Do not post admin requests to the list. They will be ignored.
    Cocoa-dev mailing list (Cocoa-dev (AT) lists (DOT) apple.com)
    Help/Unsubscribe/Update your Subscription:
    %40developershed.com

    This email sent to bsdarchive (AT) developershed (DOT) com
  • No.4 | | 1429 bytes | |

    7 Dec 2005, at 13:26, Jim Marschke wrote:

    I have a small app which collects temperature data and graphs it
    over time. As I collect new data, I append it to an existing
    path. If I run this app for many days the bezier path gets large
    and eats up a lot of memory. What I want to do is set a limit of
    how much data I display (maybe a day or two) and once I reach that
    begin removing points from the beginning of the path as I add
    points to the end of it.

    Is there a simple way to do this?

    The short answer is no. There is no API for removing points from a
    Bezier path. Either you'll need to keep a copy of the raw data and
    periodically recreate the path from the last N data points or you
    will need to walk through the points in the path using -
    and build a new path using that
    information. The former method is almost always going to be a better
    solution. Note that you don't need to do this every time; you can
    continue building the path incrementally but just throw it away and
    rebuild it as needed (e.g. when the path gets too big to draw quickly).

    Cheers,
    Nicko

    Do not post admin requests to the list. They will be ignored.
    Cocoa-dev mailing list (Cocoa-dev (AT) lists (DOT) apple.com)
    Help/Unsubscribe/Update your Subscription:
    %40developershed.com

    This email sent to bsdarchive (AT) developershed (DOT) com
  • No.5 | | 827 bytes | |

    Dec 7, 2005, at 6:50 AM, Jim Marschke wrote:

    But that means every time I want to draw the path I have to
    recreate it.

    No, just when the underlying data that you want to plot changes.

    Also, you don't need to discard an NSBezierPath object. You can clear
    it with a -removeAllPoints: message, and save the cost of
    deallocating and re-creating it.
    -jcr

    John C. Randolph <jcr (AT) mac (DOT) com(408) 914-0013
    Roaming Cocoa Engineer,
    Available for your projects at great Expense and Inconvenience.

    Do not post admin requests to the list. They will be ignored.
    Cocoa-dev mailing list (Cocoa-dev (AT) lists (DOT) apple.com)
    Help/Unsubscribe/Update your Subscription:
    %40developershed.com

    This email sent to bsdarchive (AT) developershed (DOT) com
  • No.6 | | 738 bytes | |

    Dec 7, 2005, at 7:08 AM, Nicko van Someren wrote:

    There is no API for removing points from a Bezier path.

    Not strictly true. There isn't an API for removing *individual*
    points from the path, but -removeAllPoints: will clear the contents
    of an NSBezierPath object.
    -jcr

    John C. Randolph <jcr (AT) mac (DOT) com(408) 914-0013
    Roaming Cocoa Engineer,
    Available for your projects at great Expense and Inconvenience.

    Do not post admin requests to the list. They will be ignored.
    Cocoa-dev mailing list (Cocoa-dev (AT) lists (DOT) apple.com)
    Help/Unsubscribe/Update your Subscription:
    %40developershed.com

    This email sent to bsdarchive (AT) developershed (DOT) com
  • No.7 | | 2535 bytes | |

    7 Dec 2005, at 16:10, Scott Thompson wrote:

    Dec 7, 2005, at 8:50 AM, Jim Marschke wrote:
    >
    >But that means every time I want to draw the path I have to
    >recreate it. That can take a while when I have thousands of
    >points -- and multiple paths. The path itself seems to be a great
    >storage area, and when I resize I just do a transform rather than
    >rebuilding. There are easy ways to append data to a path, I was
    >hoping someone knew of a way to remove data.
    >>

    >Jim
    >

    A much better strategy would be to filter the 10,000 points
    depending on how you plan to display them. In the example above,
    you could choose every 10th point, or average 10 points, or any of
    a number of other strategies to generate a path of only 1000 points.

    I'm going to chip in here because I've seen people screw this up time
    after time. You absolutely cannot just choose every 10th point
    unless you're certain that your data has only small frequency
    components at over one tenth of the collection frequency. If you
    don't pay attention to this, you'll display completely the wrong
    graph (lots of sample editors do this, which is quite inexcusable
    because they are written by people who should know better; you can
    see the effect as you zoom in/out of the sample data).

    You *do* need to process the data a bit; a simple way to do this is
    to "minimax" the points you're amalgamating, by which I mean you find
    the minimum value and the maximum value, and draw a line between
    those two. This means you can skip lots of intermediate points
    whilst keeping the display sensible. Alternatively you could use a
    digital filter (the specification for which depends on your
    application), or even use a combination (e.g. you might draw a light-
    coloured line using the minimax approach, then mark in the 95th
    percentile in a darker colour).

    Also, if you're finding that NSBezierPath is too slow (e.g. because
    your data set is very large), you could try GL. The latter is
    hardware accelerated and because it doesn't give the same image
    quality guarantees that Core Graphics does, it can be a lot faster
    for this type of application.

    (Apologies if you know all this already, but it's an oft-overlooked
    gotcha when drawing graphs with more horizontal points than pixels.)

    Kind regards,

    Alastair.

Re: How to trim a bezier path?


max 4000 letters.
Your nickname that display:
In order to stop the spam: 5 + 4 =
QUESTION ON "BSD"

EMSDN.COM