Saturday, December 4, 2010

Tips to obfuscate your code.

I often realize people make their code hard to maintain. It's a very good idea to raise your value in the company since nobody else can maintain it. Let's learn from their code. Often you can even get more efficient code since you don't need to write extra lines to make your code nicer. It doesn't cover basic skills like using magic numbers, not making a method name readable, give an object more than one name, delete all comments, etc (Do all of them!). Ideas are listed in order of importance.

(1) Store the same value in more than one places.

If you store the same parameter in more than one places, you need to synchronize them. When a maintainer write a code that changes the value, he will have a change to miss the fact and change only one of them. Every code that uses the other variable which wasn't changed will behave mistakenly. Hopefully the program will be in an inconsistent state.

(2) Store lots of data in an object and every method depends on them

If lots of methods are dependent on the state of the object, the user of the class will need to set all of them properly before using the method and he will be confused. A nice side effect is that it makes the program hard to debug and test cause the behavior of a method can have lots of right and wrong cases. Try packing lots of unnecessary parameters, make the state of objects complicated, and make it hard to maintain.

(3) Reference an object from lots of other objects.

People who look at it will be puzzled, "Is the object I can get from A is the same as what I can get through B?". This strategy is good with (1) above. Unnecessary references are good!

Dec. 24:
Just tried to tell what will happen if you do them. Don't do them of course :)

Thursday, November 25, 2010


A friend of mine wrote a very interesting function that makes arbitrary methods good for currying when used as a decorator. This is an example he wrote,

import pycurry

def test(aa, bb, cc):
    print aa, bb, cc

f = test(10) # => currying
test(10, 20, 30) # => execute the func

f(40, 50) # => execute the func since sufficient arguments are given
f(200, cc=400) # => You can execute the func like this as well

g = f('aaa') # => curring again
g([10]) # => execute

One example use case is making similar functions that takes some of arguments in common, and some of arguments given previously, like
import pycurry

def myShotMessageSlot(buttonName, toggled):
    print 'Button ' + buttonName + "'s current state is " + str(toggled)


I usually do the same thing using a closure (you can also use partial),
def slotFactory(buttonName):
    def myShotMessageSlot(toggled):
        print 'Button ' + buttonName + "'s current state is " + str(toggled)
    return myShotMessageSlot

but using his pycurry makes it nicer.

By the way I just noticed syntaxhighlighter doesn't work anymore. The JavaScript files were on a free hosting site that has ended its service, I need to put it somewhere else, ahhhh...

Sunday, November 21, 2010

First result

First result of my Sunday programming.

Spheres in the grids are pressures (positive or negative), lines are velocities in the staggered grid.
Took a bit of time to show Karman vortex.
I will take several source codes before making it 3D.

Sunday, November 7, 2010

40 days passed since I started weight control

Yellow: body fat
Green: lean body weight
Blue spot: workout
Red spot: went for a drink

Coq Proof Assistant

From the homepage.

Coq is a formal proof management system. It provides a formal language to write mathematical definitions, executable algorithms and theorems together with an environment for semi-interactive development of machine-checked proofs.
I studied basic symbolic logic to learn Coq, but its still very difficult. I still have no idea about correspondence between "A's type is B" and "A is a proof of B" (Curry–Howard correspondence).

From my note (Fluid)

Please let me know if something is wrong.

* [001]Simulating Ocean Water
- Jerry Tessendorf
* [002]Deep-Water Animation and Rendering
- Lasse Staff Jensen and Robert Golias
* [003]A Novel Algorithm for Incompressible Flow Using Only A Coarse Grid Projection
- Michael Lentine, Wen Zheng, Ronald Fedkiw
- Read.
* [004]Filament based smoke with vortex shedding and variational reconnection
- Steffen Weißmann and Ulrich Pinkall
- That filament based stuff.
* [005]Animating Sand as a Fluid
- Yongning Zhu and Robert Bridson
- Bridson's page
- First paper of Flip in CG.
* [006]Basic knowledge to learn weather dynamics(Japanese)
- for [005] (strain rate tensor, etc.)
* [007]A Controllable, Fast and Stable Basis for Vortex Based Smoke Simulation
- Alexis Angelidis, Fabrice Neyret, Karan Singh, Derek Nowrouzezahrai
- one of original paper of [004].
* [008]Computation of Vortex Ring Dynamics
- For [004] tutorial.

* Vorticity Structure and Evolution in a Transverse Jet with New Algorithms for Scalable Particle Simulation
- Fro [004] Looks good explanation for rosenhead-moore.
- Flip.
* [010]A new doubly discrete analogue of smoke ring flow and the real time simulation of fluid flow.
- Written by Pinkall, author of Philament based ...
* [011]Fluid Simulation For Computer Graphics: A Tutorial in Grid Based and Particle Based Methods
- Found when googled "MAC grid" while reading Animating Sand as a Fluid
* [012]strain and rotation(Japanese)
- Written by a prof. of Okayama univ. For Animating Sand as a Fluid. Good.
* [013]Strain and stress
- Written by a prof. of Kyusyu univ. For Animating Sand as a Fluid. Good.
* [014]FLUID SIMULATION SIGGRAPH 2007 Course Notes
- Famous one by Bridson, authoer of Animating Sand as a Fluid. SUPER GOOD.
* [015]A forward-trajectory global semi-Lagrangian transport scheme
- Detailed documents about semi-Lagrangian method.
* [016](Japanese)
* [017]Wavelet Turbulence for Fluid Simulation
- That Wavelet Trubulence one.
* [018]Real-time Fluid Simulations with Wavelet Turbulence
- Student's paper. His professor is the author of Wavelet Trubulence.
* [019]Real-Time Simulation and Rendering of 3D Fluids
- GPU Gems 3 chapter30. Haven't read.
* [020]Animation and Rendering of Complex Water Surfaces
- Origin of particle level set. Haven't read.
* [021]A Hybrid Particle Level Set Method for Improved Interface Capturing
- Origin of Particle level set. Havne't read.
* [022]Meshless Approximation Methods and Applications in Physics Based Modeling and Animation Bart Adams, Martin Wicke Eurographics 2009 Tutorial(未)
- Like a course note about Meshles. Haven't read.
* [023]FlowFixer?: Using BFECC for Fluid Simulation
- Haven't read.
* [024]Fluid Simulation for Computer Animation
- PPT slide when googled "Mark Carlson bfecc". Haven't read.

From my note (PRT)

Please let me know if something is wrong.

* [001]PRT (Japanese)
- explanation of :

* [002]Spherical Harmonic Lighting: The Gritty Details
- [001] says read this for docs about SH Rotation.

* [003]All-frequency precomputed radiance transfer using spherical radial basis functions and clustered tensor approximation
- Tsai, Yu-Ting and Shih, Zen-Chung.
- Proceedings of ACM SIGGRAPH 2006, pp. 967-976, 2006.
- SRBF for PRT. Half read.

* [004]All-Frequency Precomputed Radiance Transfer for Glossy Objects
- Read for [003]. Uses PRT for glossy materials by high compression with a combination of wavelet, CPCA, BRDF factorization

* [005]All Frequency Shadows Using Non linear Wavelet Lighting Approximation
- Read for [003] [004]Uses wavelet for PRT.

* [006]Matrix Radiance Transfer
- Read for [003] [004]. Uses CPCA.

* [007]Interactive Rendering with Arbitrary BRDFs using Separable Approximations
- Read for [004]. BRDF factorization。

* [008]Nonstationary Wavelets on them-Sphere for Scattered Data
- [003] says detailed explanation for SRBF convolution, i.e. spherical sigular integral. Haven't read.

* [009]Triple Product Wavelet Integrals for. All-Frequency Relighting
- [003]Referenced. Came after[005]. Haven't read.

* [010]Is There Anything Comparable to Spherical Harmonics But Simpler?
- srbf.pps
- Good document of SRBF for PRT.
- Probabably the base of this is "An RBF-based Image Compression Method for Image-based Rendering" written by the same author. Couldn't find on the web.

* [011]
- Stupid Spherical Harmonics (SH) Tricks
- SH (and PRT?) document by Sloan. Notes on Zonal harmonics.
- Haven't read

* [012]
- Nonstationary Wavelets on the m-Sphere for Scattered Data
- Francis J. Narcowich, Joseph D.Ward
- [003] referenced for spherical functionのconvolution

* [013]
- An Efficient Representation for Irradiance Environment Maps
- For test implementation in Nuke

* [014]
- On the Relationship between Radiance and Irradiance: Determining the illumination from images of a convex Lambertian object
- [013] referenced.

* [100]Hierarchical RBF
- Looks model generation from a point cloud, haven't read.

* [101]Cinematic Wavelet Lighting
- Pyramid published at CEDEC2004

* [102]Wavelet Lighting(Japanese)
- Comes with [101]

* [200]
- All-Frequency Relighting of Non-Diffuse Objects
- Haven't red, looks famous.
- Simpler than [004], fast

Tuesday, November 2, 2010

Re-opened hohehohe2's OpenMaya tutorial

It's moved here!

Thank you Maki for hosting it.

Saturday, September 25, 2010

hohehohe2's OpenMaya tutorial is closing

My OpenMaya(Maya API) tutorial site and its main page are closing due to the end of the free hosting service they are using.

In the meantime I may reopen it somewhere else but at the moment there's no plan for it since the contents are getting old, I've moved my main blog here, and I have less interest in maintaining these kind of informations.

It'll be closed at the end of October. I think the role of the site has finished but if you happen to need it and cannot read it anymore, please email me.

Friday, September 24, 2010

Qt Designer bad knowhows (*)

"bad knowhow" is a Japangrish meaning it is something you have to use knowing it is not a nice way.

Qt designer is a good tool but there are several things you need to know until you get familiar with it.

1) Making widgets expand within a window
It is the first thing most people takes a few hours googling to get the answer. The answer is tricky.

- Drag and drop arbitrary widget (button or spacer is enough)
- Right click the background of the window (not the widget you have dropped)
- Select Layout - Layout Horizontally (or Layout Vertically) in the pop-up menu

You cannot select Layout- Layout Horizontally (Vertically) until you create a widget on the window.

2) Moving a layout from its parent to another.
When the UI gets complicated, it is often difficult to move the right layout to the right place.

To move the right layout:
- Select the layout in the Object Inspector.
- Click the layout
Qt Designer will pick the selected layout.

To the right place:
- When clicking the layout, click near the top left corner of the layout
- Drag and drop it to the new parent in the Object Inspector
Unless you click new the top left corner, you'll be puzzled when dragging it to the Object Inspector

3) Try to copy and paste a widget and get error "Cannot paste widgets. Designer could not find a container without a layout to paste into."

My solution is to create a new dummy window (with ctrl-N) and copy&paste to it. then drag and drop it to wherever you wish to. There may be other ways.

I will add a screen shot on request.
When using the qt-designer generated file (*.ui), never modify automatically generated file. For example, I use Python and I convert *.ui to *.py with pyuic4 tool. I never modify the .py file by hand, which would halve the qt designer's strength. You will quite often want to update the GUI design and once you have modified the generated file, your modification to the source code would be lost. Insted, use the file from another. Same applies to C++ users to.

By the way qt designer is in qt-devel yum package (e.g. qt-devel-4.6.3-8.fc13.i686). It tool a while for me to find it.

Saturday, September 4, 2010


This is my log of start using SCons, you don't need to read this if you are familiar with SCons already. Most of my knowledge comes from SCons User Guide, and many of examples shown here were taken from the guide.

I looked for a build tool (like make) for my project. Like everybody else in the world, I'm sick of traditional make and needed a more elegant one.OMake's concurrent build (-P switch) attracted me a lot but it seemed to need some time to use Omake with emacs. Scons is a build tool (like make) fully utilizes Python, and there is no need to code in OCaml (omake) (*).

Once you have installed scons (if you use macport to install, you also need py25-hashlib to be installed), the first step of using Scons is to write a SConstruct file (Makefile equivalent), which is actually a Python script (so you can write a Makefile equivalent in Python).
If you just have two files hello.cpp which uses hello.h, a simple SConstruct file is


to build, you just type

Scons automatically looks at the source code hello.cpp and it is dependent on hello.h, so whenever hello.h changes, scons knows it needs to rebuild hello.

SCons User Guide is very well written and easy to read document but it is targeted for non-Python programmers and a little bit verbose, so I'll just write down the most important parts (for me) of the guide here. It doesn't cover throughout hte guide, I only read the first several chapters, up to 7.2.1 and I felt I can already use Scons to some extent.

-Program(['foo.cpp', 'bar.cpp']) if there are two sources.

-You can write Program('program', Glob('*.c')).

-SharedLibrary('foo', ['f1.c', 'f2.c']) and StaticLibrary('foo', ['f1.c', 'f2.c']) for shared and static library.

-Program('prog.c', LIBS=['foo', 'bar'], LIBPATH='.')

-Program('hello.c', CPPPATH = ['include', '/home/project/inc']) for -Iinclude -I/home/project/inc

-Program('prog.c', LIBS = 'm', LIBPATH = ['/usr/lib', '/usr/local/lib']) for -L/usr/lib -L/usr/local/lib -lm

-You can write SConstruct script like,
     hello_list = Object('hello.c', CCFLAGS='-DHELLO')
    goodbye_list = Object('goodbye.c', CCFLAGS='-DGOODBYE')
    Program(hello_list + goodbye_list)
Object means "Object file" (i.e. *.o file). Not Python object, nor any other object.

-Explict dependency.
      hello = Program('hello.c')
     Depends(hello, 'other_file')
The following scripts are also accepted.
Depends('hello', 'ho.cpp')

-Construction Environment
env = Environment(CC = 'gcc', CCFLAGS = '-O2')
To make it default settings (so that you can write Program('foo.c') instead of env.Program('foo.c')),
DefaultEnvironment(CC = 'gcc')

- SConscript(['subdirectory/SConscript']) for hierarchical build,

- Program(['foo.cpp', 'bar.cpp']) makes build target foo (looks scons gets the name from the first item in the list, not where the main function exists). Default(Program(['foo.cpp', 'bar.cpp'])) to set it as the default target.

(*) OMake official site says "There is no need to code in Perl (cons), or Python (scons)." ;)

Thursday, September 2, 2010

So what am I doing now (again)

Now I work for Polygon Pictures as a freelancer and working for some big project. It is O.K, I wish if my work could be a little bit more challenging since it's one of the easiest works I've ever done, but working with artists is always fun.

Apart from my work, I'm trying to make something interesting (interesting for CG guys), but I'm not going to tell you what it is since nothing is worth mentioning until you show an image is an unwritten rule all over the CG industry.

Wednesday, August 11, 2010

Any good module for saving settings file?

I'm thinking about the file format for various settings.
Using XML is like going to a super market by jet plane. YAML is good but not in the standard module.
So far the best choice is using JSON but json module in the standard module is not suitable for my needs since it has no __getstate__/__setstate__ equivalent.

I wonder if there's a nice module that has both pickle and json features. It would

- be able to serialize arbitrary object
- have __getstate__, __setstate__ equivalent
- be able to convert to/from standard Python objects (NOT Tag/Node/Element object ! )
- create json formatted file
- preferably customize the behavior on error
- be a light weight module (not dependent on thousands of other modules)

There's no need to maintain object references, dump() can raise an exception just like json.
I can make one by myself but I don't want to reinvent the wheel. Anybody knows if it exists already?

Saturday, July 17, 2010

Mighty Optical Illusions

If you haven't seen it, take a look at this site!
Some of them I'm fascinated.

Stereo Dino Optical Illusion (must visit)

This Isn't a Painting (must visit)

Shadow and Reflection Sculptures

Illusion Billboards Again

Sunday, July 4, 2010

Makin your Python code fast

Check out a presentatiton by Andrew Bennetts at Pycon Australia 2010.
He introduced various ways of Python code profiling.

Material from PyCon AU are licensed under the Creative Commons CC-BY-NC-SA license.

And you may also be interested in "Python Goes to the Movies" by Mark J Streatfield at Dr. D Studios, which is kind of introductory stuffs though because the conference is for Python and not for vfx.

Friday, May 28, 2010

Ohhh iPad !

I didn't know we can do such thinkgs with iPad!

Friday, May 21, 2010

Recipe 577237: Prevent star imports (Python)

Recipe 577237
Use this code in your module to prevent people using the "from foo import *" syntax with your module.

class __all__(object):
    def __getitem__(self, _):
        raise ImportError("Star imports not supported")

Saturday, April 24, 2010

Path class

I hope one of these stuffs is in the standard library.

>>> p = Path('/path/to/some/text.txt')
>>> p.parent()
>>> p.parent().parent()
>>> p.parent().parent().parent()
>>> p.parent().parent().parent().parent()
>>> p.parent().parent().parent().parent().parent()
>>> p.parent().child('other').child('text.txt')
>>> p[:-1]
>>> p[1:-1]
>>> p[2:-1]

You cannot write e.g. p[2:3] = p('aaa') since conceptually the Path class is immutable.

import os

class Path(object):
    def __init__(self, path):
        if isinstance(path, Path):
            path = path.path
        self.path = path

    def parent(self):
        return Path(os.path.dirname(self.path))

    def child(self, name):
        if isinstance(name, Path):
            name = name.path
        childPath = os.path.join(self.path, name)
        return Path(childPath)

    def base(self):
        return Path(os.path.basename(self.path))

    def abspath(self):
        return Path(os.path.abspath(self.path))

    def __str__(self):
        return self.path

    def __repr__(self):
        return self.__class__.__name__ + '(' + repr(self.path) + ')'

    def __add__(self, rhs):
        if isinstance(rhs, Path):
            return self.child(rhs.path)
            return Path(self.path + rhs)

    def __eq__(self, rhs):
        if isinstance(rhs, Path):
            rpath = rhs.path
        elif isinstance(rhs, unicode):
            rpath = rhs
            return False
        return os.path.abspath(self.path) == os.path.abspath(rpath)

    def __ne__(self, rhs):
        return not self.__eq__(rhs)

    def __getitem__(self, key):
        this, parent = self, self.parent()
        bases = [this.base()]
        while this != parent:
            bases[:0] = [parent.base()]
            this, parent = parent, parent.parent()
        bases[0] = this
        bases = bases[key]
        retPath = bases[0]
        for base in bases[1:]:
            retPath = retPath.child(base)
        return retPath

    def getCurrent():
        return Path(os.getcwd())

To extract the Python string a Path object has, you can pass the object to str() or unicode(). A friend of mine gave me an idea to make the class to be a subclass of str/unicode so that a Path object can be used as a Python string. But the meaning of __eq__, __ne__, and __getitem__ is quite different between str/unicode and my class.

Wednesday, April 14, 2010

MRV multi-platform python development environment

MRV v1.0.0-preview documentation

Looks like a high abstract level Maya API Python wrapper (and more?). Anybody tested it?

Sunday, April 4, 2010

Detexify2 - LaTeX symbol classifier

Detexify2 - LaTeX symbol classifier

What is this?

Anyone who works with LaTeX knows how time-consuming it can be to find a symbol in symbols-a4.pdf that you just can't memorize. Detexify is an attempt to simplify this search.
How does it work?

Just draw the symbol you are looking for into the square area above and look what happens!

Wrong usage.

Saturday, March 27, 2010

google translate

google translate
-> English:I do not have to surgery. No way, thank you.
-> Japanese:*****
-> English:I do not need the surgery. So no thank you.
-> Japanese:*****
-> English:I do not need the surgery. Well, thank you.
-> Japanese:*****
-> English:I do not need the surgery. Well, thank you.

It's interesting the final translation of the second sentence is closer to the right meaning, though the first translation is completely opposite. Google translate needs convergence ;)
The meaning of the first sentence remained opposite. It means "You need to have an operation".

Sunday, March 21, 2010

So what am I doing now?

I haven't updated "on topic" issues for quite a long time. Now I'm working as a freelancer at a company which is making a GI renderer and mainly working with 3ds Max (especially with material part of its SDK, that explains why I am NOT a big fan of Max). At home I'm reading siggraph papers, papers, papers. Siggraph papers are like treasure boxes but they are often hard to open, the key of a box is often inside another, and it needs yet another to open ...

Saturday, March 20, 2010

particle breakout

Particle breakout
Nice idea and beautiful.

Sunday, February 14, 2010

Sikuli on my visual programming app

I made a Sikuli node on my application for a test of conbining two visual programming software. When the user starts his application by clicking the small red circle, the downstream Sikuli node(s) gets activated, it starts a Sikuli ide ("hello popup" and "open my blog") and another Sikuli command line application to control the Sikuli ide, press play button and terminate the Sikuli ide. Sikuli uses HTML so I could easily show a Sikuli script on my Sikuli node. When opening my blog, I ran it on debug mode. You'll see what node is currently evaluated.

Feb, 15 added:
I just think it'll be conceptually fun if it could handle objects in a screen movie capture. The user plays the movie forward/backward and defines objects with a mouse, and the rest is the same as Sikuli. It'll be fun if it can generate a script from the movie capture automatically after the user defines objects in the movie.

Practically Sikuli might need a robust way to identify objects in the screen. I wanted to do File - close but many applications has the same visual interface. Currently region and inside() can specify only screen coordinates but people will want to make his script work after a window has been moved (I think they may change the behavior to get the region(s) dinamically from the screen image). Other methods like similar(), near(), etc. could be a help, or it can have some method to restrict click() actions if the region belongs to some application. Since Sikuli can already start and end an application with its name it will probably be possible to implement it.

And I think it'll be useful to be able to click a certain point in an image. It'll be good to click an "empty space" (think of clicking F4 cell in an excel sheet). And "do something until image appears" loop (think of dragging a scroll bar in a panel to show a scrolled out button).

Saturday, February 13, 2010

SIKULI is fun.

This is my first SIKULI script which makes a sphere, duplicate it, and move it.

I like its "what you see is how it works" style scripting :)

Tuesday, January 5, 2010

The Third & The Seventh


A FULL-CG animated piece that tries to illustrate architecture art across a photographic point of view where main subjects
are already-built spaces. Sometimes in an abstract way. Sometimes surreal.
.Fullscreen it, please. (comment by the Author)

The Third & The Seventh from Alex Roman on Vimeo.

Monday, January 4, 2010

Early preview(2)

My new visual programming environment.

- Macro (under developing)
- Node definition in Python (callback based)
- Code editor
- Node template
- Visual debugger (It's fun to see how node networks are working. I'll soon add a video on this entry)

See some brief descriptions here about the demo.

(Please wait if an error occurs and couldn't see the movie until youtube finishes processing)