[cairo] Very large number of lines

Arjen Nienhuis a.g.nienhuis at gmail.com
Mon Aug 30 03:04:53 PDT 2010


Hi,

If you stroke each line you need (on my system) 500 bytes per line. That
would be 10GB RAM. I don't have that. You can use swap (and you need 64
bits), but it will be very slow.

If you try to create a path with 20 milion subpaths, cairo will fail
silently(!!!) which I think is a bug.

What I did, is stroke the path every 1000 lines. That does work. I don't
know if acroread can open it. Evince can, but it takes a long time. Files
like this can break all sorts of software.

Rendering to PNG or JPEG might be the right thing to do. You need to
experiment what resolution works best for you. It will always (as long the
image is not 100s of mega pixels) be faster to view than PDF files.

Groeten, Arjen

  while(t<ITER_NO) {
      cairo_move_to (cr, 229770, -26573.7);
      cairo_line_to (cr, 231202, -24967.3);
      ++t;
      if (t % 1000 == 0)
      {
          cairo_stroke(cr);
          std::cout<<"Drawn so
far:"<<((double)t/(double)ITER_NO)*100<<"%"<<std::endl;
      }
  }


On Mon, Aug 30, 2010 at 10:39 AM, necko necko <opustenom at hotmail.com> wrote:

>  As for the cairo version, I simply followed the steps for Ubuntu, from
> http://www.cairographics.org/download/
> This means I only typed
>
> sudo apt-get install libcairo2-dev
>
> Below is the code that reproduces the problem. Setting ITER_NO to
> 20000, for example, produces regular pdf file. But, setting it to
> 20000000 seems not to be appropriate.
>
> I hope you would have suggestions on how to achieve the goal of
> representing large number of lines.
> Also, I'm interested in whether the png version of the resulting output
> file would be lighter and easier (less time consuming) to view using regular
> viewer. Your suggestions on this might also be helpful.
>
> code:
>
> #include <cairo.h>
> #include <cairo-pdf.h>
> #include <sstream>
> #include <cmath>
> #include <vector>
> #include <limits.h>
> #include <queue>
> #include <algorithm>
> #include <numeric>
> #include <iostream>
> int main() {
>   cairo_surface_t *surface;
>   cairo_t *cr;
>
>   std::stringstream myOut; int k=1;
>   myOut<<"forGallery"<<k<< ".pdf";
>   surface = cairo_pdf_surface_create(myOut.str().c_str(), 1432, 1606);
>   cr = cairo_create(surface);
>   cairo_translate (cr, -229770, 26573.7); // -40, 50: for margin -37, 53
>
>   unsigned int t=0; unsigned int ITER_NO=20000000;
>   while(t<ITER_NO) {
>       cairo_move_to (cr, 229770, -26573.7);
>       cairo_line_to (cr, 231202, -24967.3);
>       std::cout<<"Drawn so
> far:"<<((double)t/(double)ITER_NO)*100<<"%"<<std::endl;
>       ++t;
>   }
>
>   cairo_stroke(cr);
>   cairo_show_page(cr);
>   cairo_surface_destroy(surface);
>   cairo_destroy(cr);
>
>   return 0;
>
> }
>
> > Date: Sun, 29 Aug 2010 21:41:23 +0200
> > Subject: Re: [cairo] Very large number of lines
> > From: a.g.nienhuis at gmail.com
> > To: opustenom at hotmail.com
> > CC: cairo at cairographics.org; cairo-bugs at cairographics.org
>
> >
> > What version of cairo do use?
> > Did you finish() the surface?
> > Can you send a simple program (source code) that reproduces the problem?
> >
> > Groeten, Arjen
> >
> > On Sunday, August 29, 2010, necko necko <opustenom at hotmail.com> wrote:
> > >
> > >
> > >
> > >
> > >
> > > The pdf output file is supposed to display very large number of lines,
> connections
> > > between a number of points. This is the code sample which specifies
> around 8million
> > > lines:
> > > .............
> > > while (myIter!=edges.end()) {
> > >      .......
> > >     cairo_move_to (cr, *firstIter, *(firstIter+1));
> > >     cairo_line_to (cr, *secondIter, *(secondIter+1));
> > >     ..........
> > >     ++myIter;
> > > }
> > > cairo_set_line_width (cr, .05);
> > > cairo_stroke (cr);
> > > .........................
> > > Note that the above code produces pdf files which were viewed with
> Evince, but not
> > > with Adobe Reader (drawing error occurred, shown in the report window).
> > > I used the same code for showing larger number of lines, more than
> 20million. The output
> > > pdf files had names as specified, but their size was around 400 bytes,
> and when I try to
> > > open them, they are simply empty(white, in Evince), while Adobe says
> that the file has no
> > > pages to display.
> > > In order to overcome this problem, I put stroke() within the while()
> loop, but when I tried
> > > to draw files showing more than 20million lines, the process got
> "Killed" (Ubuntu Linux) at
> > > around 33% of the total.
> > > .............................
> > > What would be the way to properly draw the pdf file specifying very
> large number of lines?
> > > What would be the code to try? Note that the variations work properly
> with smaller number
> > > of lines.
> > >
> > > Thanks
> > >
> > >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20100830/ebf9cb95/attachment-0001.htm>


More information about the cairo mailing list