Archive

Archive for the ‘Useful Apps’ Category

Converting xfig (.fig) to vector formats using dktools

March 28th, 2012 No comments

Recently I needed to convert old xfig files to inkscape while preparing figures for my dissertation. Luckily I found out about dktools. However, there wasn’t a convenient package in an ubuntu repository. Fortunately, it’s fairly easy to compile. Just in case someone finds this useful, I’ll leave installation instructions here for Ubuntu users:


sudo apt-get install libpng-dev libdb5.1-dev libbz2-dev libjpeg-dev libtiff-dev libsnmp-dev
./configure
make
make install

To convert a .fig to .svg:

fig2vect -lsvg fig.fig fig.svg

Categories: Education, Useful Apps Tags: ,

Using paraview as a post-processor.

October 19th, 2011 No comments

I reviewed paraview about two years ago, and I more or less lambasted it for not being very well documented and that the mailing list was not as responsive to “beginners” questions as one might imagine. Some of the examples on the wiki also did not work back then. I have been quietly monitoring and occasionally evaluating paraview to see how it has been improving. In one of the recent versions this year, they actually released the user guide/handbook, which contains some useful information. The file reader formats have greatly improved and a lot of the features rival that of tecplot, which is not free.

While my research lab recently acquired Abaqus, all of my dissertation code is in the Finite Element Analysis Program (FEAP) from Berkeley. It was written mainly by Robert Taylor (one of the Godfathers of finite elements) and by Sanjay Govindjee. It is a pretty good code, and is written mainly in Fortran/C. Unfortunately, while it includes some sophisticated numerical schemes and efficient solvers, it does not provide much in terms of pre- and post-processing for finite elements. In the past we used Ansys to generate meshes, and manipulated the boundary conditions by hand. However, we have since then, obtained patient-specific heart meshes, and the number of nodes is much larger and the geometry/numbering is not so obvious.

Fortunately, paraview has some powerful selection filters and tools available. Unfortunately, after each selection the number of elements and nodes is renumbered. Paraview actually keeps track of the global id’s but for some reason it is filtered out from the spreadsheet view by default. However this can be changed easily. To use paraview as a pre-processor, the idea is to use successive “Extract Selection” filters after using the “Fustrum” or “Surface” selection tool for nodes/elements in the Selection Toolbar. One should think of it as taking the original mesh, and then slicing or cutting away the parts that are not of interest until you are left with only what you want. Lastly, in the selection explorer, you can also select “Invert Selection”, which effectively allows you to select the portion you want to “cut-away” from the mesh.

The following are instructions to perform this pre-processing selection using paraview.

  1. If not already done, go to Preferences > Charts. Then delete the line that says “vtkOriginalIds” that is in the “hidden” list. This will show the “vtkOriginalIds” value in the spreadsheet view and allow you to “Save Data” on each “Extract Selection”, such that one will get a mapping from vtkOriginalIds to the renumbered fields.
  2. Use the provided selection tools, and “Extract Selection” successively until you arrive at the selection you want.
  3. Click on each “Extract Selection” filter and click on File > Save Data. Select a filename, and make sure to specify either Point/Cell/Field data so you save the proper mapping.
  4. Next you can use the following python script to get the proper mapping using 0-index numbering (paraview indexing). The script takes in a list of “Extraction Selection” csv files and an outputfilename for the global id mapping.
Script source is below:
import os,sys
 
def parse(args):
    extractions, outputfile = map(open,args[:-1]),open(args[-1],"w")
 
    ids = []
    newids = []
 
    for extraction in extractions:
        origids = []
        for line in (extraction.readlines())[1:]:
            orig= line.split(",")[0]
            origids.append(int(orig))
 
        # if ids is filled map rewrite ids accor
        if len(ids) > 0:
           for id in range(len(origids)):
               origids[id] = ids[origids[id]]
 
        ids = origids
 
    for id in ids:
        outputfile.write("%d\n" % (id))
 
    outputfile.close()      
 
if __name__=="__main__":
    parse(sys.argv[1:])

VLC GOMTV SQLive URL extractor

October 25th, 2010 13 comments

Update 03/11 As far as I know GOMTV has started checking for VLC specific information, so the script probably won’t produce anything that works in VLC anymore. I don’t have time to write a Lua plugin for VLC, but that would be ideal to spoof as GOMPlayer.

Update 01/11/11: Updated user script to reflect Foo’s comment below. Code updated below.

Update 10/28/10: Fixed include of which webpages the greasemonkey script runs on. Before sometimes if the url did not match the one in the instructions it would not show the link.

I’ve have a lot of WIPs so I haven’t updated any of the content on this blog frequently. However, the hassle of watching GSL streams in P.S.T. have gotten to me, and at this point I’d rather sleep than watch Idra, Check, SlayersBoxer, Nada, Fruitdealer play Starcraft 2 live. The issue is that VODs are not free from GOMTV, and the pirated Youtube streams are a bit of a hassle to find. The massive viewers on restreamed livestreams easily reduces any computer and it’s network connection to dust.

One easy work around is to just watch the live streams from GomTV, since they are free even though the VODs are not. 720p HQ quality is offered at a premium, but SQLive is free and acceptable. However, since the hours are ridiculously harsh for people living on the West Coast of North America (3 a.m. to 6 a.m.) the best solution is to just record the live stream.

Luckily someone had figured out how to extract the SQLive stream link from the GOMTV pages with detailed instructions on reddit. However, the instructions are not particularly clear, and it seems GOMTV decided to change some of the URLs slightly. Last night I managed to verify that these instructions work with some modification and it seemed fairly reasonable to right a greasemonkey script, since most likely I will be extracting these links several times per day. Since this is tedious, and partially because I’m lazy, I decided to write a greasemonkey script to do extract the link while suffering from minor insomnia last night.

Usage:

  1. For GSL2, login and go to http://www.gomtv.net/2010gslopens2/live/.
  2. Link will show up in red next to “View Live” at the top of the page.

Greasyscript below: (or download vlcgomgreaser.user)

// ==UserScript==
// @name           VLCGOMGreaser
// @namespace      hawflakes.unoc.net
// @description    Get VLC link from GOMTV SQLive
// @include        http://www.gomtv.net/*/live/*
// ==/UserScript==
 
//
 
var script = findXPathNode("//div[@id=\"league_mainBody\"]/script");
var scriptcontent = script.innerHTML;
var start = scriptcontent.indexOf("goxUrl");
var start = scriptcontent.indexOf("http", start);
var url = scriptcontent.substring(start, scriptcontent.indexOf(";", start+1));
var url = url.replace(/strLevel=[^&]+/, "strLevel=SQTest");
var url = url.replace(/&title=[^;]+/, "");
 
var linkpage = get(url,"",showlink);
 
function showlink(client,info) {
	var contents = client.responseText;
	var start = contents.indexOf("LiveAddr=") + "LiveAddr=".length;
	var end = contents.indexOf(";\"/");
	var url = unescape(contents.substring(start,end));
 
	var insertion = findXPathNode("//*[@id=\"chmenu_title_container\"]");
	insertion.innerHTML += "<a href="\">"+url+"</a>";
}
 
function get(url, data, cb,info) {
	var client = new XMLHttpRequest();
	client.open("GET",url,true);
 
	client.onreadystatechange = function () {
		if(client.readyState==4) {
 
			cb(client,info);
 
		}
	}
	client.send(null);
}
 
function findXPathNode(xpath, start,doc)
{
	var result = (doc == null ? document : doc).evaluate(xpath,(start == null ? document : start), null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE ,null);
	return (result.snapshotLength &gt; 0 ? result.snapshotItem(0) : null);
}

Tecplot’s avi use broken windows codecs

April 29th, 2010 No comments

For those of you that use tecplot, you know that while the interface is fairly straightforward and the resulting visuals look pretty good, tecplot has one major flaw. The animations are generated in with essentially the MSRLE codec from a decade ago. The codec’s color palette generally cannot handle continuous color flooding  in tecplot; if you try to open it up on other machines or convert them to say flash video or mp4, you will find that the the colors are all messed up. Sometimes the frame size in tecplot causes the video to not display correctly.

So to fix this issue, I found out that the swf output actually works correctly. Modifying the previous pbox2avi script, I created a tecplot specific script to generate mpeg’s or whatever else ffmpeg can spit out. The script is pretty much a more rudimentary version of pbox2avi.py.

Requirements: swftools, ffmpeg

Download tecplot2mpeg.py.

As usual the code for the script is below:

# Copyright 2010 Jonathan Wong
# python script to convert SWF files generated from tecplot to mpeg
 
#requires swfextract
 
import commands,sys,re,math
 
def parse(filename):
#check filename for .swf extension
if not filename.find('.swf'): # not a comprehensive check
return
 
fileprefix = filename[0:filename.find('.swf')]
commands.getstatusoutput("rm %s.mpeg" % (fileprefix,))
 
#open file
status, output = commands.getstatusoutput("swfextract %s" % (filename,))
 
print output
 
#find "JPEGs: ID(s)"
slide_identifier = "PNGs: ID(s)"
start=output.find(slide_identifier)
slide_extract=[]
if start:
start += len(slide_identifier)+1
slide_end = output.find("[-f]",start)
print start,slide_end
slide_extract=output[start:slide_end-2].replace(" ","")
 
# now extract all the data
print "swfextract %s -P -p %s" % (filename,slide_extract)
 
slides = slide_extract.split(",")
digits = 1 + int(math.log10(int(slides[-1])))
 
for slide in slides:
print "Processing frame: %d" % (int(int(slide)/2)+1,)
print ("swfextract %%s -p %%s &amp; mv output.png %s%%0%dd.png" % (fileprefix,digits,)) % (filename,slide,int(int(slide)/2)+1)
status, output = commands.getstatusoutput(("swfextract %%s -p %%s &amp;&amp; mv output.png %s%%0%dd.png" % (fileprefix,digits,)) % (filename,slide,int(int(slide)/2)+1))
 
status, output = commands.getstatusoutput("ffmpeg -f image2 -i %s%%04d.png -b 600k %s.mpeg &amp;&amp; rm %s*.png" % (fileprefix,fileprefix,fileprefix))
return slide_extract
 
if __name__=="__main__":
slides=parse(sys.argv[1])
Categories: Useful Apps Tags: , , , , ,