<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'>
Thank you for your email. I applied your approach of stoke() every Nth line (but I take N=1000000 instead of 1000;<br>if you think it would be better to use smaller stride (N=1000), please let me know). <br>This approach outputs the pdf file of size 1.5 MB, but the machine is still trying to display it. I hope it will display<br>that single line. Did Evince display the pdf file properly at your machine?<br><br>As for the PNG file, take a look at the following:<br>#include &lt;cairo.h&gt;<br>#include &lt;cairo-pdf.h&gt;<br>#include &lt;sstream&gt;<br>#include &lt;cmath&gt;&nbsp; <br>#include &lt;vector&gt;&nbsp;&nbsp; <br>#include &lt;limits.h&gt;<br>#include &lt;queue&gt;<br>#include &lt;algorithm&gt;<br>#include &lt;numeric&gt;<br>#include &lt;iostream&gt;<br>int main() {<br>&nbsp; cairo_surface_t *surface;<br>&nbsp; cairo_t *cr;<br><br>&nbsp; std::stringstream myOut; int k=1;<br>&nbsp; myOut&lt;&lt;"pics/forGallery"&lt;&lt;k&lt;&lt; ".pdf";<br>&nbsp; //surface = cairo_pdf_surface_create(myOut.str().c_str(), 1432, 1606);<br>&nbsp; surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1432, 1606);<br>&nbsp; //surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, 1432, 1606);<br>&nbsp; //surface = cairo_image_surface_create(CAIRO_FORMAT_A8, 1432, 1606);<br>&nbsp; //surface = cairo_image_surface_create(CAIRO_FORMAT_A1, 1432, 1606);<br>&nbsp; cr = cairo_create(surface);<br>&nbsp; <br>&nbsp; //cairo_set_source_rgb(cr, 1, 1, 1);<br>&nbsp; //cairo_paint(cr);<br>&nbsp; //cairo_set_source_rgb(cr, 0, 0, 0);<br>&nbsp; <br>&nbsp; cairo_translate (cr, -229770, 26573.7); // -40, 50: for margin -37, 53<br><br>&nbsp; unsigned int t=0; unsigned int ITER_NO=20000000;<br>&nbsp; while(t&lt;ITER_NO) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cairo_move_to (cr, 229770, -26573.7);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cairo_line_to (cr, 231202, -24967.3);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(t%1000000==0 || t==ITER_NO-1) {<br>&nbsp;&nbsp;&nbsp; cairo_stroke(cr);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; std::cout&lt;&lt;"Drawn so far:"&lt;&lt;((double)t/(double)ITER_NO)*100&lt;&lt;"%"&lt;&lt;std::endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ++t;<br>&nbsp; }<br>&nbsp; <br>&nbsp; //cairo_show_page(cr); // for PDF<br>&nbsp; cairo_surface_write_to_png(surface, "image.png");&nbsp; // for PNG<br>&nbsp; cairo_surface_destroy(surface);<br>&nbsp; cairo_destroy(cr);<br><br>&nbsp; return 0;<br><br>}<br>...............................<br>The above code is much slower than the PDF version, as it practically stops every 1000000th line (t%1000000==0), even though<br>it is related to PNG files. Do you know what might be the reason for this?<br>My intention is to produce PNG files (if it is faster to view then than pdf files), but the above introduces problem.<br><br>I appreciate your help. <br><br><br><hr id="stopSpelling">Date: Mon, 30 Aug 2010 12:04:53 +0200<br>Subject: Re: [cairo] Very large number of lines<br>From: a.g.nienhuis@gmail.com<br>To: opustenom@hotmail.com<br>CC: cairo@cairographics.org<br><br><div>Hi,</div><div><br></div><div>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.</div><div>
<br></div><div>If you try to create a path with 20 milion subpaths, cairo will fail silently(!!!) which I think is a bug.</div><div><br></div><div>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.</div>
<div><br></div><div>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.</div>
<div><br></div><div>Groeten, Arjen</div><div><br></div><div><div><font class="ecxApple-style-span" face="'courier new', monospace">&nbsp;&nbsp;while(t&lt;ITER_NO) {</font></div><div><font class="ecxApple-style-span" face="'courier new', monospace">&nbsp;&nbsp; &nbsp; &nbsp;cairo_move_to (cr, 229770, -26573.7);</font></div>
<div><font class="ecxApple-style-span" face="'courier new', monospace">&nbsp;&nbsp; &nbsp; &nbsp;cairo_line_to (cr, 231202, -24967.3);</font></div><div><font class="ecxApple-style-span" face="'courier new', monospace">&nbsp;&nbsp; &nbsp; &nbsp;++t;</font></div>
<div><font class="ecxApple-style-span" face="'courier new', monospace">&nbsp;&nbsp; &nbsp; &nbsp;if (t % 1000 == 0)</font></div><div><font class="ecxApple-style-span" face="'courier new', monospace">&nbsp;&nbsp; &nbsp; &nbsp;{</font></div><div><font class="ecxApple-style-span" face="'courier new', monospace">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cairo_stroke(cr);</font></div>
<div><font class="ecxApple-style-span" face="'courier new', monospace">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::cout&lt;&lt;"Drawn so far:"&lt;&lt;((double)t/(double)ITER_NO)*100&lt;&lt;"%"&lt;&lt;std::endl;</font></div><div>
<font class="ecxApple-style-span" face="'courier new', monospace">&nbsp;&nbsp; &nbsp; &nbsp;}</font></div><div><font class="ecxApple-style-span" face="'courier new', monospace">&nbsp;&nbsp;}</font></div></div><div><br></div><div><br></div><div class="ecxgmail_quote">
On Mon, Aug 30, 2010 at 10:39 AM, necko necko <span dir="ltr">&lt;<a href="mailto:opustenom@hotmail.com">opustenom@hotmail.com</a>&gt;</span> wrote:<br><blockquote class="ecxgmail_quote" style="border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">




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