lynda.com

Build an OpenGL GUI application in Mac OSX

April 2nd, 2010 by windmaomao

I had a school project that I need to build a visualization application to plot some scientific dataset in 3D on my snow leopard. While I had some experience in terms of plotting in Windows, building a 3D application in Macintosh environment is fairly new to me. So I kinda spent couple of weeks researching and experimenting couple of components that are needed to proceed .

Canvas

Basically, you need to setup a screen canvas to draw 3D objects, which can be achieved by using OpenGL API . The library takes care of setting up the graphic hardware, creation of objects, and projection them to 2D screen pixel on the canvas, all sorts of basic functionalities in 3D world. Normally this process is fixed, but a shader language (normally comes with OpenGL) can let you adjust how you represent object and how to draw them into pixels at run time through some scripts. This really adds the overall flexibility, and effects can achieved very easily by writing some shader and plug into the pipeline.
To see how apple supports OpenGL and shader, you can check out GLSLShowpiece application from apple reference library ( it comes with a executable file). You can test your shader easily using OpenGL shader builder (in XCode folder) where you can test all sorts of functionality of shader without writing any code.

Engine

To make 3D rendering job a bit easier, I’d also like to have a backbone engine that deals with scene loading, objects/material management, camera handling in a black box, so I can concentrate on the application logic. Here’s a list of engines/libraries that I came across, some are more favoring game, and some are to the visualization (the difference between game and visualization lies in where their interests first originates, IMO). To name a few,
1) NSOpenGLView control in Mac XCode
2) Ogre 3D, game engine, open source
3) Unity 3D, game engine, commercial
4) OpenScenGraph, open source, visualization
5) VTK, open source, scientific visualization

First of all, NSOpenGLView is a native control developed by Apple to have openGL embedded in a native view, which is very nice, and you can find couple of ready to built demos from Online Reference Library, OpenGL section.

While NSOpenGLView is a good place to start, the design is pretty basic at this moment. So I checked some game engine, ex. Ogre 3D. It got very decent resource management, scene construction and utilities that you’ll find handy in 3D space. To be able to use it as a native view in XCode, you need to direct the rendering output to NSView as described in this post and more examples can be found here here, ex. mouse control, etc.
ogre_nsview_color

unity icon
I mentioned Unity 3D here because I’ve used it for another of my project before. It’s a commercial game engine, very robust, cross platformed, and objects can be controlled through script language. Personally I like it a lot except the fact that it lacks the native GUI controls on OSX. And for this project, it could be very time consuming.

OpenSceneGraph and VTK are two visualization packages that are available to the open source community. Though I didn’t get chance to test them, from what I read from introduction, they contains lot of visualization processing libraries that will come handy if your data needs to be manipulated before plotting.

All in all, for this project, I chose Ogre. And this post will be keep updated as the project unfolds.

Fang

Reblog this post [with Zemanta]
VN:F [1.6.4_902]
Rating: 0.0/10 (0 votes cast)
VN:F [1.6.4_902]
Rating: 0 (from 0 votes)

Dropbox, a better plan for internet storage

February 9th, 2010 by windmaomao

dropbox is out

Internet space is becoming more and more important, not only the fun in sharing your photos with your friend, but also in the confidence that you can work anywhere of the world and anytime you choose to.

I used to pay $100 for 20GB using apple MobileMe, no offense of the price, but I have a better plan here. Check out Dropbox where they offer you 2GB for free instantly when you sign up. The software lets it merge with your operation system and be one of the folder. And you get a nice notifier monitoring the usage of this folder as well.

[updates] The sync feature is well implemented, whenever you put file in dropbox folder, it enters an query to be uploaded to the server, and the icon indicates if the file is updating. And when the server gets the updated file, it’ll notify all connected computer to update them into latest version. The drawback you can see from here is that all computers has a copy of all files in your local hard drive. And if you just want to transfer a file from this machine to another one, it’s better to do a direct ssh if available.

As for the charge, they let you to refer to your friends to earn extra free space, after you fills up all referrer program, you can have up to 5.2GB free storage space to play with. And if you really like their service and want to extend it, they offer $100 for 50GB as a start. Very attractive IMHO.

[more updates] Dropbox raised the referrer program to 10.2GB Max free space, which is really nice. And I found out they keep track of the files version, so if you want to go back to old version of any single file you overwrote before, just follow this help tip.

VN:F [1.6.4_902]
Rating: 0.0/10 (0 votes cast)
VN:F [1.6.4_902]
Rating: 0 (from 0 votes)

How to extend your work with others ?

August 11th, 2009 by windmaomao

Last night I was asked for advice about how to combine your work with others’ in coding. Interestingly enough, I think this can be a general question in day-to-day work, how to borrow other people’s work, how do I extend them, how can I include some feature on top of other’s work?

Well, the best way I can think of right now is the following.

1) leave other’s contribution intact. It’s very easy to steal the idea, but trust me, it’s much harder to support the work, especially the work not done by you. So the best way to incorporate other’s work is first to credit them (or pay them) and leave their work for their own goods.

2) leave your work intact. Same thing as above, only this time applying to yourself.

3) build a bridge between them. Same thing as above, only this time applying to the bridge (or interface) or the connection. You need to credit the connections these days, while sometimes over-charged, they can be very useful and efficient.

Ok, essentially three component, each of them serve only one purpose. Actually there’re still one component missing, the final user, who’s gonna use the work through the connection which binds two unique skills.

This is how the work is extended in the modern life, I think. So coding is no exception. The rule of thumb is to make each component as independent as possible. The more you can achieve this, the better it can turn out to be ;)

VN:F [1.6.4_902]
Rating: 0.0/10 (0 votes cast)
VN:F [1.6.4_902]
Rating: 0 (from 0 votes)
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • email
  • LinkedIn

Include png jpeg picture in Texshop on mac latex

July 28th, 2009 by windmaomao

it really took me a while to figure out how to include pictures in the latex, after trial and error and some online helper, it turns out to be very easy.

add the following in the beginning of the document
\usepackage{graphicx}

and whenever you need to include picture, add
\includegraphics[scale=0.5]{myfig}

make sue two things, 1) the myfig file need to be in the same path of the tex file; 2) no extension of the file should be appended, ex. png, jpg. I don’t know why, but if you add the extension, the texshop gave an fatal error. And the documentation of the texshop actually doesn’t have extension included either when it refers to include pdf and eps. If you get a missing bounding box error, please don’t go investigate bounding box, it’s not related as far as I see.

You can adjust the options in the bracket [], a small documentation you can found from here.

hope the above helps :)

VN:F [1.6.4_902]
Rating: 7.0/10 (4 votes cast)
VN:F [1.6.4_902]
Rating: 0 (from 0 votes)
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • email
  • LinkedIn

File management software bundle for Mac

July 24th, 2009 by windmaomao

One of things that I sought is a tool that helps organizing files into where they should be and allow me find them when I need to. Well, not-very-soon I realized that there’s no such thing on earth can organize things automatically. The best I see other people accomplish this is that they just put things in folders manually by themselves. I admire them.

There’s no shortcut, since nobody can make you happy better than yourself.

Ok, then I realized that no one is born to be someone. As people say, take it easy and do things you like a bit everyday. That’s all it takes to organize. Is this the universal rule for everything? Hehe. As I proceed, there’s a list of software emerging which helped me, here they are. Hit the icon to reach their author’s website.

quicksilver Finder, build in OSX, free
Ok, you can do a lot with your finder, hit spacebar and give it a tour.

quicksilverQuicksilver, the comannd launcher, free
It help you launch every application or files by typing.

macfusionMacfusion, the world in your finder, free
Free. It mounts a remote hard drive or folder to your local hard drive.

pathfinderPathfinder, guide your path in finder, shareware
Duel panel explorer, shortcut folder, drop zone copy paste, terminal build-in. It does everything that Finder does and more.

textmateTextmate, the missing text editor in OSX, shareware
Don’t insult textEdit no more. Try textmate, not only does it handle all types of text based file like swiss knife, but also most of important, it can group text files into file structure and bundle project. How can you navigate hundreds of snippets while writing a book, it shines the way.

I found the above a must for starters, and if you have your idea of organizing and moving around folders, let me know as well :)

VN:F [1.6.4_902]
Rating: 0.0/10 (0 votes cast)
VN:F [1.6.4_902]
Rating: 0 (from 0 votes)
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • email
  • LinkedIn

Hack or do extension, I

July 9th, 2009 by windmaomao

If we live in perfect world, nobody want to hack anything, ’cause you can just take it :)

In programming, sometimes you need to borrow other people’s library, either you don’t like the design or you want to add something on top of that, you are facing one million dollar question ?

hack ? or do extension.

well, let me explain what’s hacking here, you open the library, go to line 2375, write your stuff, write your comment if you are nice person. You compile the code, it worked.

it takes maybe 10 seconds to modify it after you read the manual (if any) for hours to days, it solves the problem quick. The only problem here is, next time if you want to do something else, it’s difficult for you to track what’s changed and reuse the change you made. As you can see here, it’s not a formal extension, it’s just a quick hack.

For consistency and extensibility, you probably want to think about writing an extension, especially when you have another library at hand, one good approach is to write something connecting both without hurting any of these two libraries. What we do usually is to write another container class holding both. But in the un-perfect world, what if one of the library isn’t OOPed, or not written independently?

Wow, another million dollar question ?

still, you can make it, the sacrifice here is you have to modify one of the library, but still there’s nice way to deal with it.

the answer is to write an bridge, an interface wrapping most of the functionalities of one library, and this wrapper gets called by another library. Why not just call one library inside another library? Well, for lots of reason, what I can think of right now is, one library might not be bored to be with another library most of time, so the easy way to maintain their relationship is to create a buffer to cool down the tension.

ok, well said, here’s an example in fortran (one of the worst language for OOP), I want to use Steve’s package, how do I extend it with my code, ex. XXX. ok, steve’s code is well organized, since it’s not OOPed, let’s just leave it as a black box.

so your code should look something like this,

module Cell_System
 
	type :: cells
	end type cells
 
contains
 
	subroutine cellsys_create(csys)
               type(cells) :: csys
 
	end subroutine cellsys_create	
 
	subroutine cellsys_destroy(csys)
               type(cells) :: csys
 
	end subroutine cellsys_destroy
 
       !! lots of functionalities about cells here
	subroutine cellsys_do_something_1(csys)
               type(cells) :: csys
 
	end subroutine cellsys_do_something_1
 
	subroutine cellsys_do_something_2(csys)
               type(cells) :: csys
 
	end subroutine cellsys_do_something_2
 
end module Cell_System

let’s make a extension for our problem now, the interface should look something like this

module Problem_Cell
	use Cell_System
	implicit none
 
	type :: cell_app
		type(cells) :: cell_sys
	end type cell_app
 
        !! lots of problem related parameters here
 
contains
 
	subroutine cprob_create(capp)
               type(cell_app) :: capp
 
	end subroutine cprob_create
 
	subroutine cprob_destroy(capp)
               type(cell_app) :: capp
 
	end subroutine cprob_destroy
 
       !! lots of functionalities related to problem here which uses cell system, ex.
	subroutine cprob_do_something_with_problem(capp)
               type(cell_app) :: capp
 
              call  cellsys_do_something_1(capp%cell_sys)
              call  cellsys_do_something_2(capp%cell_sys)
 
	end subroutine cprob_do_something_with_problem
 
 
end module Problem_Cell

It’s pretty similar to the library code, yes, but it’s related to problem and tuned to problem domain. ok, now in the problem.f90, you call write,

MODULE Problem
 
	! define cell system object
	type(cell_app) :: capp
 
contains
 
	subroutine SetProb()
 
		call cprob_create(capp,domain)
 
	end subroutine SetProb
 
	subroutine AfterRun()
 
		call cprob_destroy(capp)
 
	end subroutine AfterRun
 
	!! lots of functionalities referred to cell system calls
	subroutine Step()
 
		call cprob_do_something_with_problem(capp)
 
	end subroutine Step
 
 
end module Problem

I hope you get the idea, take a look at all three codes, they’re quite similar, you build two houses, instead of drilling holes on both houses to connect them, you build a small house in-between to keep the integrity of both. Well in this case, we have to arrange the furniture of one of the house.

FYI, one of the house (cell system)) can be built multiple times while one of the house (steve’s library) can only have one copy. If both are designed to be multiple times allowed, we could do another approach that builds a bigger house containing both while keeping integrity of both so that each can be maintained and improved separately. If you interested, the fundamental idea behind this is information hiding and isolation, one of the topic in OOP (object oriented programming), here I used it in fortran.

Hope the above isn’t too overwhelming for non-computer science major people ;)

VN:F [1.6.4_902]
Rating: 0.0/10 (0 votes cast)
VN:F [1.6.4_902]
Rating: 0 (from 0 votes)
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • email
  • LinkedIn

C#, a new scripting language ?

June 13th, 2009 by windmaomao

Honestly I ain’t a fan for C#, it’s a new language, and can do a lot of fun things. But anyway at work I have to stick with Fortran and matlab, and at home I use c++ and python sometimes. Besides, I am a mac person now, thought there’s no way in the world I’ll be in using C#.

But, I guess I’m wrong :)

It seems C sharp is pretty popular among some game and web design or wherever these two meets. In writing a small game project, I’m extremely happy to use an internal scripting language extendable and powerful and easy to use as C#.

So I went ahead, download the simple C# bundle for my favorite text editor Textmate, and start programming on it. As for a standalone C sharp on mac, you can check out mono on OSX.

And here you go, life is good, isn’t it? :)

VN:F [1.6.4_902]
Rating: 0.0/10 (0 votes cast)
VN:F [1.6.4_902]
Rating: 0 (from 0 votes)
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • email
  • LinkedIn

OOP comes to Matlab, wow

February 14th, 2009 by windmaomao

[SinglePic not found]

I never actually thought in my dream one day OOP will ever come to Matlab, though I am aware of python, and matlab is not much different from python. Narrow minded as I am, I got very excited to read the documentation online.

In short, it’s very nicely designed, pretty much got all latest object-oriented features, I also like the event callback which C++ never had natively. Since 2008b is a bit new, as far as I can see, only one container object is available, which is container.map, which maps value to key. I eagerly  expect that in the furture they can have a complete set of structure object, ex. expandable vector, linked list (they got a demo code for this one), trees, or even graph (a nice component which borrows boost, MatlabBGL).

Script language with compiled version on the back probably will be the future anyway. I was very proud to be a C++ programmer, due to the work reason, I program a lot in Fortran these days, but Matlab starts to get me excited everyday how much work I can accomplish everyday.

OOP in matlab will have a bright and kicking-a** future. Cheers.

VN:F [1.6.4_902]
Rating: 9.0/10 (1 vote cast)
VN:F [1.6.4_902]
Rating: 0 (from 0 votes)
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • email
  • LinkedIn

QPlot, memory in my old school

February 14th, 2009 by windmaomao

[SinglePic not found]
 well, i wrote a app in windows back when I was in grad school. Need a quick tool to examine my simulation data quickly. Took couple of weeks using Borland C++ builder, and there you go, my qplot :)

if there’s any regret, that’ll be, though I setup a website, I never got chance to support it as most of the programmer treat their babies. Part of it is that I switched to Mac, and never looked back :) Part of it is that I finally graduated and never want to look back either. Life moved on. Maybe someday I will come back revisit my baby if I get bored with matlab, hehe.

VN:F [1.6.4_902]
Rating: 0.0/10 (0 votes cast)
VN:F [1.6.4_902]
Rating: 0 (from 0 votes)
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • email
  • LinkedIn