Programming Page |
[last updated 19th Oct 2006]
Disclaimer : far from being a comprehensive manual, this page contains only the tips and hints that I find useful to be able to look up quickly on my web site
// Define a typedef called pf3 that improves
readability later on. Assume CBase has a public typedef unsigned long (CBase::*pf3)(
int &, unsigned char ); // If you have to explicitly state the calling convention,
you do it thus typedef unsigned long ( __cdecl
CBase::*pf4)( int &, unsigned char ); void func()
} |
when initializing static memory, the C++ standard tells us to do so at file scope like this
EIGENSTRUCT* MyClass::m_eigenstructures = 0;
|
but the order and moment in which these static members are initialized is not standardized and can be down to compiler choice / platform / whats in memory and other hideous unpredictable reasons however the standard is very clear about static initialization at function scope. Instead use the singleton pattern to initialize static variables (particularly where additional memory is allocated) like so;
const EIGENSTRUCT * getEigenValuesTable() {
    static EIGENSTRUCT* MyClass::m_eigenstructures = 0;     if (!MyClass::m_eigenstructures) {            // allocate memory and assign to / initialize m_eigenstructures here     }     return MyClass::m_eigenstructures; |
Disclaimer: if I got any of the syntax wrong, its cause I didn't check it before it got posted. See the C++ FAQ Lite for the correct syntax
To debug Link errors use nm (and ldd)
nm -A -C dof.so | grep globalThreadCount
|
Is useful to track the source of an error message related to a mangled sym table name, eg.
D02001 {WARNING} TgPathDLOpen: Bad DSO found: dof.so (undefined symbol: _ZN3Imf17globalThreadCountEv) |
and this;
man nm |
will give the manual page
You need to link with CPPFLAGS -pthread
before the include paths and LDLIBS -lpthread
in your libs
Include this from the cpp file
#include < pthread.h>
|
The things to look up when searching for docs are;
struct pthread_attr_t |
coming next ... interthread communication using kernel objects.
## TCL comments are denoted by lines starting with '##'
} |
## The 'foreach' keyword syntax is very different for anyone used to
C/C++
|
.slim .sl |
This shader uses an arbitrary image as it's basis. In Maya you'd set up an MTOR
coordinate system and a poly cube to represent the volume in which the effect
will be rendered. The coordsys acts as the origin and orientation of the
effect, so it should be placed flush up against one of the faces of the cube.
The average of the RGB at each pixel is used as an initial length to create a
beam of the same colour eminating into the volume from the corresponding
position on the image plane. The image will appear within the coordsys, so it
can be scaled and positioned to get the effect you want. Bear in mind that only
the beams that intersect the cube will be rendered.
Some quick rules for slim's template syntax:
|
This slim template allows you to hook up nodes which output a colour, to a
vector connection, which is otherwise not possible. It allows scale and bias of
the colour, clamping upper and lower limits and normalization. The template
demonstrates how to use collections amongst other things.
This slim template allows you to make Euler coordinates into Polar coordinates.
I have written a well useful script for Slim that allows you to find rogue nodes that still exist but have dissapeared from every one of the Palette windows. This can be especially useful for finding and deleting rogue custom templates that have errors.
## Author : Dan Evans
|
I have written a useful script for Pixar's Renderman Shader network tool, 'Slim', which batch flattens all shaders. This is run from the slim console window which is under the Renderman > Slim menu in Maya.
|
// x > = 1 : Truncates floats down to x decimal places
} |
// Purpose : String substitution to work around the problem of the attribute
being in the
}; |
// -fl means "flatten", and gives pShape5.f[1] pShape5.f[2] pShape5.f[3]
|
|
#! /usr/bin/perl
|
|
|
|
place this in a file called loop and chmod a+x
example of use is moving subset from a sequence using filters
loop 4 10 cg_myshot_blah_t004_v002 exr /some/dest/path/
ver.pl is a perl script to extract the version number from a file name and compare it with a loop variable. Click the link below to download it.
|
This is a way of batch converting TEX files to TIFF format. In a terminal window
in Linux, copy and paste the following bold text exactly as they appear,
WITHOUT MODIFICATION.
find . -name \*.tex -exec sho -dspy tiff -dspyfile \{\}.tif \{\} \;
For current dir only, you will also need the maxdepth 1 option: find . -name \*.tex -maxdepth 1 -exec sho -dspy tiff -dspyfile \{\}.tif \{\} \;
For finding only recent files, use -amin +/-N where N is in minutes and - means newer than, + older than: find . -name '*shd*tex' -amin -10
find all .mb or .ma files that have velvet in their name find . -name '*.m[ab]' | grep -i 'velvet'
exr's less than 1 day old find . -name '*.exr' -atime -1
exr's more than 1 day old find . -name '*.exr' -atime +1
exr's less than 60 minutes old find . -name '*.exr' -amin -60
|
Click here to download 'Makefile' |
This command will list all the file names in the current directory (.) find . -name c\[0-9\]-\*.pdf
this command would find double digits ( c##- ) find . -name c\[0-9\]\[0-9\]-\*.pdf
|
This command will batch download all pdf's from the specified url. wget -r -l 1 -A pdf http://www.library.cornell.edu/nr/bookcpdf/
The paramaters:
|
type "env" in the shell and it will list all of your environment variables env > somename.txt
will pipe it into a text file so you can search it easily. |
type su machinename
to login to a machine from some other workstation (so substitute
machinename for whatever the workstation name is). Now it's exactly as if you
were sitting there. top
and you get a list of processes currently running on that machine. You can use
the PID to pass to 'kill' to shut down processess that have hanged. mount -l (lowercase 'L') will list all of the devices that can be mounted (such as hard disks). mount -a
will mount all of the devices according to your mount file in wherever it is. |
It wasn't obvious to me at first how to get my usb memory stick reader working on linux 7/9. So here's a couple of helpful links that got me on the right track USB Mass storage HOW-TO: useful link #1USB Mass storage HOW-TO: useful link #2 I created a directory under root called /mspro to mount my device to once i'd
edited the fstab. mount /mspro
to mount it, and then; umount /mspro -l
when you want to unplug it (minus lowercase L for 'lazy'). At work i do this to mount the memory stick into /mnt/mspro/ in /etc/fstab; /dev/sdb1 /mnt/mspro auto defaults,user,noauto 0 0
then in a shell su mount /dev/sdb1
On my home machine, I'd do this mount /dev/sda1
Use; fdisk -l
to figure out what to add to fstab. The number of blocks will be
significantly less than your hard disks, so that's how you tell what one it is. dmesg is a pretty useful thang too, lists hardware messages |
Example - I wanted to extract f-stop info in a batch for a whole load of image
files, but metacam has no command line options to do this...... find . -name \*.THM -exec metacam \{\} \;
> temp.txt 2. grep it to list only the important lines containing filename (they all start with CRW_) and 'aperture' grep -i -e 'CRW_\|Aperture:' temp.txt >
apertures.txt or as one line, stick a semi-colon between them (NOT an escape character) find . -name \*.THM -exec metacam \{\} \;
> temp.txt ; grep -i -e 'CRW_\|Aperture:' temp.txt > apertures.txt
|
Creates a symbolic link to /Acrobat5/bin/acroread in the directory /usr/local/bin. This is useful because /usr/local/bin is in the PATH env variable which means you can type the name of any exe's or scripts in that dir from any directory in a shell window and it will run. This effectively allows you to extent the set of Linux shell commands. Oh mental note I need to add the tiff2vnl++ script to this page, as it's well clever. ln -s /usr/local/Acrobat5/bin/acroread /usr/local/bin
|
chmod a+w acroread |
pwd |
locate wx |
tar -zxvf linux-508.tar.gz |
gunzip -d STL_doc.tar.gz | tar -xvf - |
ls -al |
touch somefile.whatever |
To grab the latest 2.0.x code, run the following commands: export CVSROOT=:pserver:anonymous@cvs.sourceforge.net:/cvsroot/fltk cvs login (press ENTER when asked for a password) cvs -z3 get -d fltk-2.0.x fltk cd fltk-2.0.x autoconf Once you have the code downloaded, run the following commands to keep your local copy up to date: cd fltk-2.0.x cvs -z3 update -dP
autoconf
|
df -h du . -sh |
pf maya |
shader dnGlassBuilding.sl |& head |& pipes the results of shader into head, which in turn only displays the first few lines of output messages.... quite handy if you have billions of errors and only want to see the first couple of them. |
find . -name '*.sl' -exec grep 'mCorrosion' \{\} \; the -print prints the file name to the stdout, this \; ends the -exec part and {} is a placeholder for the results from find |
(gdb) file /u/dde/dev/sw/window_matte/Linux-gcc322-debug/window_matte (gdb) break 59 (gdb) run commandline1 commandline2 [ etc..] (gdb) next [ = step over ] (gdb) frame (gdb) print foobar.size() (gdb) clear (gdb) continue [ like Run,F5 ] (gdb) step [ = step into ] (gdb)
|
Change to the top level directory of your new software project (E.g. /u/me/dev/sw/myApp) and execute: cvs import -m "Initial import" sw/myApp DNEG BASE
The important bit is to be in the correct directory and to specify a correct
repository name ('maya/myPlugin' in the above case). The repository name should
normally match the local directory structure and project name within your dev
area, making it easier to relate the cvs repository structure to you local sub
directories under whatever your $DEV path points to. |
To check out a project from the repository (such as the one you might have imported above) change directory to the top of your local dev area: cd /u/dde/dev
Because cvs checks out files into your current directory you will normally want
to be in /u/dde/dev. cvs checkout sw/myApp
(will create /u/dde/dev/sw/myApp/)
|
After making changes to your software project and building a working version your can do the following to save any changes back to the cvs repository - Change to your project top-level directory (E.g. /u/dde/dev/sw/myApp) and type: cvs commit -m "Your checkin lable goes
here"
The current directory and all subdirectories will be scanned and changes stored. Note that you must explicitly add and remove any files using cvs (see below). |
If you add any files to your checkout project you must use the following command before they can be committed: cvs add filenames...
|
To remove files from your project you must first remove the files from disk using 'rm' then use the following cvs command before a commit: cvs rm filenames...
|
If someone else has committed changes to files you have checkout then you can merge those changes (as long as they're not too significant) into your local project using the following command: cvs update
|
To use this, type make clean ; make
It's an example of how to use a config file - wx-config in this case - inside a make file to get the include paths necessary. PROJNAME = noisetweaker OPENGL_LIBS = -lGL -lGLU CPPFLAGS = `wx-config --cppflags` LDLIBS = `wx-config --libs` -lwx_gtk_gl-2.4 $(OPENGL_LIBS) OBJECTFILES = glCanvas.o perlinNoise.o slider.o $(PROJNAME).o $(PROJNAME): $(OBJECTFILES) nbsp; g++ $(LDLIBS) $(OBJECTFILES) -o $(PROJNAME) slider.o: nbsp; g++ $(CPPFLAGS) -c slider.cpp $(PROJNAME).o: g++ $(CPPFLAGS) -c $(PROJNAME).cpp glCanvas.o: g++ $(CPPFLAGS) -c glCanvas.cpp perlinNoise.o : g++ $(CPPFLAGS) -c perlinNoise.cpp clean:
|
In NEDIT; to regex find / replace color(1,1,1) with { 1 1 1 }
or color(0.5,0.5,0.5) with { 0.5 0.5 0.5 }
or color(.5,.5,.5) with { .5 .5 .5 }
use find : color\(([0]*\.*[0-9]),([0]*\.*[0-9]),([0]*\.*[0-9])\)
replace : { \1 \2 \3 }
and Alt+T to replace again. You have to use () around the regular expressions in 'find' that you want to use access again later on in the substitution otherwise it won't work. To explain a bit what color\(([0]*\.*[0-9]),([0]*\.*[0-9]),([0]*\.*[0-9])\)
does;
|
consider the following sequence mySequence.0001.exr mySequence.0002.exr . . to get just the basename.... "mySequence" foreach f ( *.exr ) foreach? echo $f:r:r foreach? end to get just the extension.... "exr" foreach f ( *.exr ) foreach? echo $f:e foreach? end to get just the frame number...."0001", "0002", etc foreach f ( *.exr ) foreach? echo $f:r:e foreach? end
|
svnlook tree /tools/STAR/subversion/
|
svn log -r 1:HEAD file:///tools/STAR/subversion/prman/shader/srf/starTecto_srf/trunk
This will output to the shell, all of the revision numbers associated with changes to files in this directory and their associated log message. |
svn checkout file:///tools/STAR/subversion/prman/shader/srf/starTecto_srf/trunk
The file checked out will go in whatever your current dir is, so make sure you know if something will be overwritten |
svn checkout -r 40 file:///tools/STAR/subversion/prman/shader/srf/starTecto_srf/trunk
As above, but getting an older version instead of the latest one |
svn diff -r 1:HEAD file:///tools/STAR/subversion/prman/shader/srf/starTecto_srf/trunk
HEAD is an alias for the highest revision number for this file. You can also just put a revision number here |