I am working on a unix machine. and I have a list of names in .eps file format. I know I can easily grep show lines to extract my names but they're not in the same order as in the figure. is there a way to extract names from the figure while preserving the order?
example:
/ArialMT-ISOLatin1 findfont
32 scalefont
setfont
0 0 0 setrgbcolor
newpath
0 0 moveto
(King James) show
grestore
grestore
grestore
0 0 0 setrgbcolor
[] 0 setdash
5 setlinewidth
0 setlinejoin
1 setlinecap
newpath
-1013.087 5437.645 moveto
-574.44269 5148.3467 lineto
stroke
0 0 0 setrgbcolor
[] 0 setdash
5 setlinewidth
0 setlinejoin
1 setlinecap
newpath
-801.10602 5042.689 moveto
-683.66547 4973.3872 lineto
stroke
0 0 0 setrgbcolor
[] 0 setdash
5 setlinewidth
0 setlinejoin
0 setlinecap
newpath
-764.50114 5103.5574 moveto
-789.24211 5063.1816 -813.3093 5022.3968 -836.69272 4981.22 curveto
stroke
gsave [0.8480481 -0.52991926 0.52991926 0.8480481 -3204.0386 27.010243]
concat
gsave [1 0 0 -1 -1554.9214 5600.4102] concat
gsave
/ArialMT-ISOLatin1 findfont
32 scalefont
setfont
0 0 0 setrgbcolor
newpath
0 0 moveto
(M. L. King) show
...
M.L.King should go before King James but could I do this by exploiting the coordinate system?
thnx
First, I wanted to suggest to keep track of movements ie where the PostScript interpreter is putting the text, but that can be tricky since postscript is a fully fledged programming language. Another approach is to annotate your .eps files:
open a file with the 'open' command
for every show
a. get the current coordianates by 'currentpoint'. this leaves the coordinates on the stack
b. 'write' those two values into your file (as a .csv perhaps?) and the text which is going to be shown
close the file with 'closefile'
Run your annotated .eps file through a PS interpreter. Sort the generated file on the coordinates with the Unix 'sort' command, don't forget the -n option for both keys (ie y coordinate and x coordinate). And you are done.
Related
I believe that I am doing something very wrong with my image buttons. I want to do something as simple as making them change its image whenever I hover over the button or by pressing it. Stylesheets are a bit ambiguous at the moment for me.
Here is a code snip where I think I am doing wrong with it:
border-image: url(:/Data/buttonNUC_Idle.png) 0 0 0 0 stretch stretch;
hover:{border-image: url(:/Data/buttonNUC_Hover.png) 0 0 0 0 stretch stretch;};
pressed: {border-image: url(:/Data/buttonNUC_Idle.png) 0 0 0 0 stretch stretch;};
Does anyone has any idea on what I can do?
Another thing that I tried, but to no avail.
void MainWindow::on_nucButton_pressed()
{
ui->nucButton->setStyleSheet("QLineEdit {border-image: url(:/Data/buttonNUC_Pressed.png) 0 0 0 0 stretch stretch;}");
// printf("Work?\n");
}
Try this
ui->nucButton->setStyleSheet("QLineEdit {border-image: url(:/Data/buttonNUC_Pressed.png) 0 0 0 0 stretch stretch;}"
"QLineEdit:hover {border-image: url(:/Data/buttonNUC_Idle.png) 0 0 0 0 stretch stretch;}"
"QLineEdit:pressed {border-image: url(:/Data/buttonNUC_Idle.png) 0 0 0 0 stretch stretch;}");
Solved it - just copy pasted the old project code into a new project and everything worked. For some reason my Qt project got bugged and it didn't let me do it.
How can i compute descriptor matches using --pair_list option file (using main_ComputeMatches.cpp).
What is the format of data in the file specified by input --pair_list?
Thanks in advance for any suggestion.
You must list the image view index.
See your sfm_data.json, each image is linked to a view index.
In the pair_list file you just connect the image pair your wanna try to compute like
0 1
0 2
1 2
1 6
...
Expanding #Jack answer, you could also compact it like this:
0 1 2
1 2 6
...
I need to change a value with a specific condition in an output data file. An example of the output file is like below:
#comments
1 0 0.002799 296.404062 2.474652 1.769134
2 0 0.002799 293.540280 2.474652 1.769134
3 0 0.002799 296.404062 0.821247 4.107403
4 0 0.002799 290.676497 2.474652 1.769134
5 0 0.002799 287.812715 2.474652 1.769134
6 0 0.002799 296.404062 2.474652 1.769134
I need to change the second value(which is zero by default) to 1 if the last value in the line is smaller than 8, otherwise leave it zero. Could someone please help me with that?!
Based on your approach a came up with the following code:
with open('data.txt') as fin, open('outfile.txt','w') as fout:
for line in fin:
if line.startswith("#"):
fout.write(line)
continue
fields = line.split()
fields[1] = "0" if float(fields[-1]) < 8 else "1"
fout.write(" ".join(fields) + "\n")
If the line starts with #, it continues.
Then it converts the line into an array of individual fields.
If the last field is smaller than 8 (after conversion to float), the second field is set to "0" - and "1" if not.
Finally, it joins the fields and writes them to the output file.
with open(infile.chkpt) as fin,open('outfile.txt','w') as fout:
for line in fin:
#use line.split('\t'3) if the name of the field can contain spaces
float,float,rest = line.split('\t'3)
#do something to change start and end here.
#Note that `start` and `end` are strings, but they can easily be changed
#using `int` or `float` builtins.
fout.write('\t'.join((name,start,end,rest)))
I was wondering if anyone knew an easier way of doing the following:
I have a dataset of health facility caseload by year, where each observation is one health facility. Facilities were 'brought online' in different years, so some have zeros before they have values for caseload. Also, some 'discontinue', as in they did provide services, but don't any more. I would like to replace the zeros with missing values for the years in which a facility discontinued. In the following example, the 3rd and 4th facilities discontinued, so I'd like missing for y2014 for the 3rd and y2013 & y2014 for the 4th.
y2011 y2012 y2013 y2014
0 0 76 82
0 0 29 13
0 0 25 0
5 10 0 0
0 0 17 24
I tried the following, which worked, but I'm going to have many years worth of data to work on (2000-2014), so was wondering if there was a more efficient way.
replace y2014=. if y2014==0 & (y2013>0 | y2012>0 | y2011>0)
replace y2013=. if y2013==0 & ( y2012>0 | y2011>0)
replace y2012=. if y2012==0 & ( y2011>0)
I messed around with egen rowlast to identify the facilities with a zero in the last year (meaning they discontinued), but then wasn't sure where to go with it.
Your problem would benefit from a loop over the variables.
We'll initialise started to 0, change our mind about started when we see a positive value, and change any subsequent 0s to missings if started is 1.
gen started = 0
forval y = 2000/2014 {
replace started = 1 if y`y' > 0
replace y`y' = . if started == 1 & y`y' == 0
}
Note that this scheme allows re-starts.
A more general comment is that this is not the better data structure for such panel or longitudinal data. This particular problem is not too challenging, but most problems with such data will be easier after reshape long.
See here for a survey of "rowwise" technique in Stata.
Can any one tell me how to write a simple C++ code to export my data(from variable) into PDF file without using any external libraries or utilities?
Use fprintf and write to a file, conforming to the PDF file format.
Specifically look in Appendix G. You might be able to get away with some very simple transformations and produce a readable PDF file.
Without using a PDF library your best way might be to create a simple PDF with sample text using some other application (eg OpenOffice). Then use this as a basis for the boiler plate and have you C++ code insert your own text in place. Note that PDF is line orientated so each new line of text has to be explicitly placed at the correct position.
For anything other than very simple output this is going to be tricky without fully understanding the PDF spec
Can any one tell me how to write a simple C++ code to export my data(from variable) into PDF file without using any external libraries or utilities?
No. PDF files are complicated. To read and write them, your code is going to be complicated. Normally, you could use an external library to hide that complexity, but if you don't want to do that, then your code is going to have to contain the complexity. And then it will not be simple.
You're asking for the impossible. You're asking to perform a complex task without doing anything complex yourself, and without relying on anyone else to do something complex for you.
But someone is going to have to do it.
I'm currently using ZendPDF right now, and I have created a test pdf file that looked like this when viewed as text. When I changed the text "This is a test" to "This is a super test" in the pdf file itself, I was able to change the final pdf file and it opened in foxit. So, copy this and use C++ to replace the string with what you want. I was also able to make new text appear with just a text editor by copying that F1 14 Tf stuff.
The php used to output this text is
<?php
require("inc/function.inc.php");
// start authorization check
require("inc/authcheckhdr.inc.php");
$pdf = new Zend_Pdf();
// Fetch the first page so you can draw on top of it.
$page = $pdf->pages[0] = $pdf->newPage('A4');
// Set font and text color.
$page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 14);
$page->setFillColor(new Zend_Pdf_Color_HTML('black'));
// Draw some text on top of the page at x,y
$page->drawText('This is a test', 72, 720);
// More drawing commands...
// Save the resulting PDF document. OR
$pdf->save('result.pdf');
// Render the resulting PDF and send it to the browser
$pdfDocument = $pdf->render();
header("Content-Type: application/pdf");
header("Content-Disposition: attachment; filename=result.pdf");
echo $pdfDocument;
?>
The pdf file is...
%PDF-1.4
%âãÏÓ
1 0 obj
<</Type /Catalog /Version /1.4 /Pages 2 0 R /Names 7 0 R >>
endobj
2 0 obj
<</Type /Pages /Kids [3 0 R ] /Count 1 >>
endobj
3 0 obj
<</Type /Page /LastModified (D:20091231114504-08'00') /Resources <</ProcSet [/Text /PDF ] /Font <</F1 8 0 R >> >> /MediaBox [0 0 595 842 ]
/Contents [4 0 R ] /Parent 2 0 R >>
endobj
4 0 obj
<</Length 50 >>
stream
/F1 14 Tf
0 g
BT
72 620 Td
(This is a test) Tj
ET
/F1 14 Tf
0 g
BT
72 720 Td
(This is a super test) Tj
ET
endstream
endobj
5 0 obj
[]
endobj
6 0 obj
<</Names 5 0 R >>
endobj
7 0 obj
<</Dests 6 0 R >>
endobj
8 0 obj
<</Type /Font /Encoding /WinAnsiEncoding /Subtype /Type1 /BaseFont /Helvetica >>
endobj
xref
0 9
0000000000 65535 f
0000000015 00000 n
0000000091 00000 n
0000000149 00000 n
0000000341 00000 n
0000000441 00000 n
0000000460 00000 n
0000000494 00000 n
0000000528 00000 n
trailer
<</ID [<65386133343365653231383339346131> <64663632306233616663343536616332> ] /Size 9 /Root 1 0 R >>
startxref
625
%%EOF
...without using any external
libraries or utilities?
that is a bit of a problem... If you are using QT you can do it... What is your setup?