Nerdworks logo "The nerd shall inherit the earth."

Nerdworks Blogorama

Nerdspeak

What's wrong with India?
Philosophical Crud
8/24/2006 11:11:51 PM  

There was a small article writing contest in the company that I work for to commemorate the 59th anniversary of Indian independence. Two entries were selected as winners; one by yours truly and another by a colleague. We were asked to write what in our opinion was the single most critical issue facing democratic India and what must be done to resolve it. Here are the two winning entries for your reading pleasure! I've hosted both of these articles on Google's Writely service, which is a free online web word processor. Just incase you didn't know Google has free online spreadsheet and calendar applications too!

What's wrong with India and how to fix it - (My colleague Parthiban's version)
Read this for a fun, humorous, tragic perspective!
 
What's wrong with India and how to fix it - (My version)
Read this for a boring, serious, heavy, preachy perspective!
Link Comment
 
Forced software updates?
Irrelevant Stuff
8/18/2006 11:08:46 PM  

Vendors of "free" software programs have started getting into this annoying habit of forcing updates down users throats these days! The sad thing is that these updates aren't updates in the traditional sense of the word; they just make you re-download the entire software again!

The funny thing is that the software seems to just give up the ghost after a preset period of time has expired! There are no discreet checks with an internet server to see whether a new version is in fact available! I wonder what would happen if the time expires and the vendor doesn't manage to release a newer version! So far I've found Google SketchUp and the VMWare virtualization server behaving this way. When they say its free, it should be free forever! It is pretty silly making people download updates when the user is not looking for one especially when these updates are king size files (around 19MB for Google Sketchup and around 150MB for VMWare server)!

Now don't get me wrong. I think it is really cool that these corporations are letting people use their software for free and it is even cooler that they want them to always use the latest and the greatest version. Its just that I don't want them deciding when I need the software updated (security updates are an entirely different issue altogether though; they're like medicine, you just hold your breath and swallow!).

Link Comment
 
Python rocks!
Technobabble
8/18/2006 9:14:20 AM  

I have been dabbling with a bit of 3D graphics programming for the last couple of days; trying my hand at exporting models designed using the free 3D modelling software Blender and getting them rendered using OpenGL. Blender supports a Python based scripting system where pretty much everything in Blender can be accessed via Python scripts. So, along the way I happened to see what Python was all about.

Exporting co-ordinates and normal vectors from Blender turned out to be fairly straightforward. The following script does a quick and dirty job of producing a file with all the numbers.

 import Blender;
 from Blender import *;

 import Blender.Scene;
 from Blender.Scene import *;

 f = open( "co.csv", "w" )

 scenes = Scene.Get(); # iterate thru all ze scenes
 for sc in scenes:
   objects = sc.getChildren(); # run thru all ze objects in this scene
   for obj in objects:
     if( obj.getType() != "Mesh" ): # we are interested only in meshes
       continue;
     print "exporting ", obj.name;
     f.write( "# " + obj.name + "\n" ); # write the name of the object into
                                        # the file; our renderer ignores
                                        # lines starting with the '#' character

     data = obj.getData(0, 1); # get co-ord data
     for face in data.faces: # blender gives us the co-ords face-wise
       #
       # first we write out the normal vector for this polygon
       #
       f.write( "--" +
                ( '%f' % face.no.x ) + "," +
                ( '%f' % face.no.y ) + "," +
                ( '%f' % face.no.z ) + "\n" );

       #
       # now, write out all the vertices
       #
       for v in face.verts:
           f.write( ( '%f' % v.co.x ) + "," +
                    ( '%f' % v.co.y ) + "," +
                    ( '%f' % v.co.z ) + "\n" )
    
 f.close();

Nothing spectacular about the script really. Here's a screenshot of how Blender's default suzanne monkey model looks like in my OpenGL program.

suzanne monkey

But one problem I quickly ran into was with regard to the scale of the co-ordinates output by Blender. Sometimes Blender's data would cause the model to be rendered in gigantic proportions and I'd have to render it far into the screen to make it fit inside the window. What I really needed was a script that could post-process the co-ordinates from Blender (basically, scale them down). I figured I'll write it in Python (I could have done the scaling while exporting them from Blender of course, but where's the fun in that!) and boy was it cool, or was it cool!

Python supports this super-cool feature called "List comprehension" that allows you to succintly express operations that you want performed on elements in a collection. In my case the file containing the list of co-ordinates looked like this:

-3.448783,-1.912737,-0.861946
-3.281278,-2.116843,-0.861946
-2.328871,-1.164436,-3.555760
-2.328871,-1.164436,-3.555760
-3.573251,-1.679874,-0.861946
-3.448783,-1.912737,-0.861946

And I wanted each of those numbers scaled down by a factor. The script turned out to be remarkably short and it has elegance written all over it!

 import string;

 #
 # open the source, dest files
 #
 src = open( "co.csv", "r" );
 dst = open( "cos.csv", "w" );

 #
 # process each line
 #
 line = src.readline();
 while( len( line ) > 0 ):
  #
  # process it only if it is a non-comment and non
  # normal line
  #
  if( line[0] != "#" and line[0:2] != "--" ):
   line = string.join( [ str( float( x ) * 0.25 )
           for x in string.split( line, "," ) ], "," ) + "\n";
   dst.write( line );
   line = src.readline();

 src.close();
 dst.close();

Take special note of the highlighted line. Believe it or not, but that single line of code splits a line of comma delimited text, converts each resulting token into a float, multiplies it with 0.25, converts the value back into a string and then concatenates the list of converted values into a comma delimited string again! Now I know that some of you're thinking that we have traded off clarity of code for expressive power and that is true to an extent here. But it isn't anymore obtuse than, say a regular expression! I guess it boils down to personal preference at the end of the day.

I could have written 20 lines to do the same thing but I sure wouldn't be feeling as pleased as I am feeling right now! Python rocks!

Link Comment (2)
 
blogorama home
about this blog
email the author
where on earth am i?
subscribe to mailing list
feeds Use these links for feed syndication
rss  |  atom
by category
technobabble (33)
philosophical crud (3)
irrelevant stuff (7)
archive
march, 2009 (2)
august, 2008 (2)
march, 2008 (1)
january, 2008 (1)
september, 2007 (2)
april, 2007 (1)
february, 2007 (2)
december, 2006 (1)
october, 2006 (1)
september, 2006 (4)
august, 2006 (3)
july, 2006 (4)
june, 2006 (3)
may, 2006 (6)
april, 2006 (2)
recent entries
Writing a sensor dr...
Enabling JSONP call...
The Conman
Memoization - Optim...
Random Lisp thought...
Learning Common Lis...
JavaScript closures...
Calling a JavaScrip...
92040 hits