<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'>
Thanks for the email.<br>You were right about stroke the same line over itself. Therefore, I made a simple<br>random coordinate generator that should more closely describe the problem I'm<br>working on.<br>Note that all the lines need to be shown in the pdf file (therefore I use translate<br>which depends on min/max coordinate). The number of lines is from<br>20million-350million. This is the main reason I'm striving for speed (in processing<br>and in displaying).<br>Therefore, displaying a PNG file would be appropriate. Please consider the code below.<br>The first translate option cairo_translate (cr, -229770, 26573); leads to execution time<br>of around 7min, while the second one cairo_translate (cr, -429000, 35000); leads to<br>execution time of around 1min. Is it because the invisible parts are not processed?<br><br>For my application, everything within the bounding box (determined by the min/max<br>coordinate) should be displayed.<br>I noted that the output is different when stroke() every 1000th or 100000th line.<br>I thought this was because of the random number generator, but I tested it several times.<br>Please consider the attached PNG files. Note that with the increase of the stroke() stride,<br>the picture's edge becomes more precise. What is the reason for this?<br>What option should I consider for my application?<br><br>The code that should demonstrate the problem is shown below:<br>#include <cairo.h><br>#include <cairo-pdf.h><br>#include <sstream><br>#include <cmath> <br>#include <vector> <br>#include <limits.h><br>#include <queue><br>#include <algorithm><br>#include <numeric><br>#include <iostream><br>int main() {<br> cairo_surface_t *surface;<br> cairo_t *cr;<br><br> std::stringstream myOut; int k=1;<br> myOut<<"pics/forGallery"<<k<< ".pdf";<br> unsigned int resolutionNo=4;<br> //surface = cairo_pdf_surface_create(myOut.str().c_str(), 1432, 1606);<br> //surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1432, 1606);<br> //surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, 1432, 1606);<br> surface = cairo_image_surface_create(CAIRO_FORMAT_A8, 1432, 1606);<br> //surface = cairo_image_surface_create(CAIRO_FORMAT_A1, 1432, 1606);<br> cr = cairo_create(surface);<br> cairo_set_line_width (cr, .5);<br> //cairo_translate (cr, -229770, 26573);<br> cairo_translate (cr, -429000, 35000);<br> srand((unsigned)time(0));<br> double xCoordinate, yCoordinate;<br> unsigned int t=0; unsigned int ITER_NO=2000000; <br> while(t<ITER_NO) {<br> xCoordinate=(rand()%230000)+200000.6;<br> yCoordinate=(rand()%26000)+20000.2;<br> cairo_move_to (cr, xCoordinate, -yCoordinate);<br> xCoordinate=(rand()%230000)+200000.3;<br> yCoordinate=(rand()%26000)+20000.7;<br> cairo_line_to (cr, xCoordinate, -yCoordinate);<br> if(t%100000==0 || t==ITER_NO-1) {<br> //if(t==ITER_NO-1) {<br> cairo_stroke(cr);<br> }<br> std::cout<<"Drawn so far:"<<((double)t/(double)ITER_NO)*100<<"%"<<std::endl;<br> ++t;<br> } <br> <br> //cairo_stroke(cr);<br> //cairo_show_page(cr); // for PDF<br> cairo_surface_write_to_png(surface, "pics/image.png"); // for PNG<br> cairo_surface_finish(surface);<br> cairo_surface_destroy(surface);<br> cairo_destroy(cr);<br><br> return 0;<br><br>}<br>.........................................<br>In addition, any other suggestions what option to chose for displaying large number of lines<br>(ITER_NO>20million in the code above) are welcome.<br><br>Thanks.<br><br><br>> Date: Mon, 30 Aug 2010 20:31:49 +0200<br>> Subject: Re: [cairo] Very large number of lines<br>> From: ranma42@gmail.com<br>> To: opustenom@hotmail.com<br>> CC: cairo@cairographics.org<br>> <br>> On Mon, Aug 30, 2010 at 8:20 PM, necko necko <opustenom@hotmail.com> wrote:<br>> > Thank you for your email. The code I provided is just a sample. I need to<br>> > show<br>> > connections between a number of coordinates; so, in the real scenario the<br>> > output file<br>> > should display various lines.<br>> <br>> How many lines do you expect to pass through the visible area?<br>> Maybe a preprocessing your data to discard the invisible lines would allow<br>> you to get an usable pdf and/or improve the performance of rasterization.<br>> <br>> ><br>> > The stroke() invoked on every 1000000th line produces the pdf file<br>> > (otherwise, only one<br>> > stroke at the end will not produce the pdf file). I know this because the<br>> > size of the output<br>> > file is around 100MB (otherwise, around 400kb). Clearly, I have problems<br>> > displaying this<br>> > file.<br>> ><br>> > As the way to get around this problem was to output PNG file, with the same<br>> > strategy of<br>> > invoking stroke() on every 1000000th line. The code I sent (for PNG files)<br>> > spends *very*<br>> > long time on each stroke() invoked.<br>> ><br>> > Therefore, I wonder whether there is a way to get the png output with this<br>> > large number of connections.<br>> > I tried to use similar strategy as with pdf files, but it is very time<br>> > consuming.<br>> > Perhaps you could try to invoke the code;<br>> <br>> I did try your code. I found that (on my laptop) stroking every ~128<br>> lines is much faster<br>> for the image backend.<br>> Anyway you should *NOT* keep stroking the same line over itself, it is<br>> not a good<br>> benchmark (it can easily be ten times slower than what you would get<br>> using the real<br>> data).<br>> <br>> Profiling your code (when running on actual data) might give you some<br>> more insight<br>> about the real hot spot.<br>> <br>> Andrea<br>                                            </body>
</html>