PyQt4 Schema Script

January 30, 2010 Matteo Bertozzi | Filed Under Qt4, Tools | 1 Comment

I’ve received a couple of emails asking me what I use to draw various graphs and schema that I post on this blog. And the obviously answer is QPainter! I’ve a small PyQt script that does the easy things but the more difficult one is coded every time…


The script is really simple, it take an xml input and just draw the few items that can recognize. You can use RGBA colors and you can draw linee-paths, like in the image above. The XML looks like this one:

<!-- Green Rect -->
<item type='rectangle'
      x='130' y='140' width='140' height='60'
      border='1/0x98b954'
      color='0xf4ffe4/0xdbfdab' />

<text x='130' y='140' width='140' height='60'
      color='0x000000' font='Arial'
      size='12' bold='false' italic='true'>
    I'm just a Test!
</text>        

<!-- Links Line -->
<line path='70,120;70,170;130,170' />

I know that it’s a stupid thing and making xml seems to be a long job, but this is what I need at the moment, maybe in the future this script will get a WYSIWYG ui but at this time is just a simple script that generate an image :)

The source code with the above example is available here: PyQt4 Schema Script.

Directories and File-System, RaleighFS Way!

January 30, 2010 Matteo Bertozzi | Filed Under Algorithms, Data Structures | No Comments

When you talk about a new file-system to someone, one of the first question that you will hear is “It will suffer from directory unbalancing” or “How performs with larger directories“.

Ext3 seems to have spread the fear of large directory, but What is a directory? and what large directories mean?

When you design a File-System you’ve to decide what is your target/end-user. Don’t try to design your file-system for everyone, but just for one.

So, what’s your focus? Be the fastest file-system for continuous ‘ls’ (Directory traversing)?

My idea and RaleighFS idea, is that File-System is just a “Big Hashtable” with some useful information, where you ask for an item ‘x’ and you’ll receive it’s data, and metadata. Following this idea, what is a directory? It’s just a name-container that allows user to keep track of his items. At this point, what is the best way to represent Directory?

Directory is just another item in the FS, like your mp3, c source file, and all the other stuff.


When you’re a high-level developer, sometimes you forget how the low-level works, in this case the File-System. The FS has blocks when you remove something from the begin/mid of a file you shift back all the rest and you rewrite the entire file to avoid this you can intelligently pack your data based on the “block-data size” of the file system. (Block data size is not the block size, maybe the file-system add its own block header to your data).

The above picture shows the RaleighFS Directory Block data structure. There’s a small block header that say how much of space are free in this block and there’re directory items that are simply 2-field struct, 1 byte name size and N chars for the name.

block_size = 8192 byte
block_head = 12 byte
dir_head = 2 byte
avg_dir_item_size = 1byte + 15 byte (avg name size)
(block_size - block_head - dir_head) / avg_dir_item_size = 511 entries in one block

In a few blocks you can handle large amount of files, and the remove operation are really quick. Just find your item, move back just your “block” friends and decrease the Directory Header free space. In this way you don’t have to rewrite all the item but just one or few blocks of it.

Remember, in RaleighFS, directory is just a name-container that allows user to keep track of his items (ls /home/) and on disk directory is just a file there’s no unbalance. Every item is looked-up in a  O(1) Time, like traditional Hashtables.

Apple iPad a Revolutionary Device!

January 30, 2010 Matteo Bertozzi | Filed Under iPad | No Comments

It’s finally here, my long waited mobile device is landed on January 27 2010. Finally we’ve a device that fit us, something that you can handle easily lying on the couch.

Ok, something is missing at the moment… iChat for example.. but just because we don’t have a nice way to display two window on the same screen… And as a developer it miss a terminal with a compiler… but it’s a mobile device, not our development machine. Mail, Safari, Notes are just what I need during my break.

1024-by-768-pixel resolution for just one app is a full revolution, we can really change the traditional User Interface experience. iPad isn’t just the best device of its kind. It’s a whole new kind of device. Prepare your self to think different, and to think in the cloud!

I like it not for what is it but for what I know that it will be.

Qt4 Image Crop Item

January 16, 2010 Matteo Bertozzi | Filed Under Qt4 | 1 Comment

Just a quick break from Math, File-System and Data Structure (I’m overly busy). The example below is a simple QGraphicsItem, that allow the user to select an area on the screen, like the “crop tool” that you can see in every Image Editor. The source code is very simple, just paint() and moveEvent() handlers.


The source code is available here: Qt4 Image Crop Item Source Code.

Base Raleigh Library is out

January 9, 2010 Matteo Bertozzi | Filed Under Algorithms, Data Structures | No Comments

In these days I’ve rewritten parts of my Raleigh Library, that I use for my work-in-progress file-system (RaleighFS). The Library provides the basic Abstraction mechanism for read/write data from devices, client-server communication, threading and various data structures like Hashtable, Sets, In-Memory Stream (Chunk), Red-Black Tree, B*Tree and other things.

I’ve published the base source code, with BSD license, at google code (http://code.google.com/p/raleigh). You can download it using Mercurial.

hg clone https://raleigh.googlecode.com/hg/ raleigh

The usage is very simple, and the source code contains Test Cases and Examples that shows how to use all the “classes”. For more information feel free to send me a mail.

Qt4/OpenGL: Pose Editor

December 13, 2009 Matteo Bertozzi | Filed Under OpenGL, Qt4 | 4 Comments

Last week I’ve published an automated “Puppet Animation” to show how Skeletal Animation and OpenGL works. Today, I’ve made something more to help you in the Animation Design Process.

The Qt code is really simple, it was just an UI with some slider connected to the Model Bones Matrix to performs Rotations and Translations and a QGLWidget that displays the OpenGL that you’ve already seen in the last post. I’ve also added a Useful ListWidget to display textures that are loaded by the model.

GDEngine-Qt4-Pose-Editor

To get some cool models you can start by checking Blender’s Open Projects that allows you to download models from Elephants Dream (see the screenshot above), Big Buck Bunny or Yo Frankie!. I’m still working on a better way to export Bones from Blender, If you’ve already tried and want to share some information, give me a mail! (thanks).

For this example, I’ve made a Big Package that contains the OpenGL engine that allows you to load and drows models and the Qt4 Pose Editor Tool that you can easily find in tools/ folder. The Source code is available here: Qt4/OpenGL Pose Editor Source Code.

Backups and Files Deduplication

December 12, 2009 Matteo Bertozzi | Filed Under Tips | No Comments

Yesterday, I’ve heard about a “No Space Left” on Backup Machine, obviously the first solutions arrived was like “Buy a new disk, they don’t cost so much” or “Try this ultra branded backup product”… and then there’s my custom and easy solution that was rejected. :)

So, If you’re a little bit brave and you’re able to write a couple of lines in Python you can have a very flexible backup system with files deduplication.

The main idea is…

  • Foreach home directory that you’ve to backup, store a key/value list with file_path/shasum (or an hash function that you trust).
  • Foreach file in the home directory check if the file is already on the backup server (Store files on Backup Server with shasum as name). If the file was not present upload it.

In this way on the Backup server there’re “two folders” one that contains all the backed-up files (storing by shasum, means that one file was on server just once), and one that contains home-th30z-10-Nov-2009.list, home-th30z-11-Nov-2009.list, and so on.

In this way you can say… Hei, fully restore my home at “specified date” or just peek a file that you’ve in another specified date.. and maybe all the features that you want.

This is a easy and flexible way to store your backup, without wasting space and have a great granularity level of restore…

If you’ve really groked the idea, you can start your start-up company focused on backups. :D

OpenGL: Skeletal Animation

December 6, 2009 Matteo Bertozzi | Filed Under OpenGL | No Comments

Drawing meshes with OpenGL is really nice, but animating it’s even funnier!

I’ve published the source code at gitHub git://github.com/matteobertozzi/GDEngine.git it’s incomplete and buggy but it works for this kind of experiments.

Next Page »