Embedding Quartz Compositions in Cocoa Applications.

Written by  on January 28, 2009

Yesterday I asked Greg Borenstein what he was using to do his really cool Arduino presentations to show the hardware alongside the code being used to program it. His answer suprised me. It was a simple Quartz Composition run using Composer. He used it to flip the views put out by his web cam so that they made sense from the users viewpoint. I have been seeing a lot of people using quartz composer to do testing and other cool graphic things.

An example I have been working with takes a camera that I had on a pole with a motor that moved it around like a periscope. The camera is sideways so the view has to be rotated. I did this by hand using Core Image this summer using filters and transforms but wanted to do it in Quartz Composer. The composition looks like this.

And the resulting image like this.

On the way down to UCSF last month I experimented with some code that embeds a quartz composition into an application.

You can download it from our svn repository ( https://ssl.tempusdictum.com/pubsvn/trunks/QuartzSnap/ add this url to your x-code scm repositories) and play with it. It builds into a standalone application.

Most all of the work is done by adding your composition to the xcode project and then placing a Quartz Composer View (QCView) from the objects library in your window using Interface builder. The only code I needed to make my application usable (to take pictures) was the action to save the view to a file.

——————————– CameraViewController.h —————————-


#import <Cocoa/Cocoa.h>
#import <Quartz/Quartz.h>

@interface CameraViewController : NSObject {

IBOutlet NSButton *SnapButton;
IBOutlet QCView *CameraView;
NSImage    *TheSnapShot;
NSData *theSnapData;

}
- (IBAction)DoSnapShot:(id)sender;
@end

——————————– CameraViewController.m —————————-


#import "CameraViewController.h"

@implementation CameraViewController

- (IBAction)DoSnapShot:(id)sender {
   theSnapData = [[CameraView snapshotImage] TIFFRepresentation];
   int runResult;
   NSSavePanel *sp = [NSSavePanel savePanel];
   [sp setCanSelectHiddenExtension:YES];
   [sp setRequiredFileType:@"tif"];
   runResult = [sp runModalForDirectory:nil file:nil];
   if (runResult == NSOKButton) {
     if (![theSnapData writeToFile:[sp filename] atomically:YES])
       NSLog(@"Well that didn't work!");
   }
}

@end

And that is pretty much it.

Compared to the several pages of code it took to get the same results using Core Image this was a snap.

Lost passwords on Mac OS X

Written by  on January 22, 2009

So, I inherited TDI’s MacBook from Cosmo who acquired a new one. He was nice enough to set up my user account with no password. Well, of course, that was untenable. So, I immediately set my password. … Time passed because I was occupied with other things. And, of course, I forgot the password. (As usual, this episode allowed the Mac vs. PC argument to bubble to the surface again. I rejoice in such arguments because diversity is the key to agility and dissent is the primary marker for diversity.)

Most websites claim you need an OS X install CD to reset the password. But, the helpful “Dr. Michael” showed us the unix way to do it, with which I’m so much more comfortable. In case that post disappears, here is a modified version of what he said that worked for me:

  1. boot into single user mode (holding command s)
  2. execute the two recommended commands

    /sbin/fsck -fy <return>

    and

    /sbin/mount -wu / <return>
  3. type

    passwd <username>
  4. type the new password <return>
  5. confirm the new password <return>
  6. restart with

    reboot <return>

3 ways to 3 volts

Written by  on January 21, 2009

I have a few devices that I need to interface to either the benito or another avr board that run at 3.3v. one is an ethernet interface, one is a bluetooth modem and then there are the x-bees.

One Way: Simple Voltage Divider.

When looking for interface examples for the xbee I found a site that started out with a circuit from maxstream and then once everything was working tried a resistor based voltage divider. This is how I got my first set of x-bees running via the ftdi chips.

One thing that this circuit didn’t do for me was to provide a decent pull-down for the reset. The 2 transistors on the right of this circuit are an attempt to do just that.

Another Way: Run everything at 3.3v

If you look at the datasheet for the atmega168 you will find the following diagram.

Looking at this you can see that 16mhz may or may not be in the operating range at 3.3v. But if you drop the crystal down to 8mhz you are good for sure. You may have to change a few things but it is doable.

The Ever Illusive Third: Buffers.

The idea of adding another layer at each interface between boards can have you asking for some Tzatziki and falafel to go with the PITA. There are buffers which are designed specifically for this. Many of the odd, many of them expensive. But there are also many families of buffer which are “tolerant” of a range of voltages outside of their supply. One of the buffers I checked out was the 74abt126 which is a tri state buffer. (I was looking at that because with the tristate buffers you can actually do a two way buffer by selecting the direction). I am not entirely certain that the 5v receive side is kosher with these.

The other buffers I am looking at with 5v tolerant i/o are the 74lvc125 and 74lvc126. These are 3.6v native parts with 5v “tolerant” io.

Since I ordered the wrong series of parts last group order I will have to wait a week to check this out.

See Also.

Swarm’s configure script: Can’t find threads

Written by  on January 9, 2009

We recently settled on Ubuntu as a common operating system for the machines on which we run biological models. That meant I have to reinstall Swarm and we encountered the same error Jim cites here.  Our failure is because the configure script doesn’t test for the amd64 platform.  I added the following lines to the configure (after line 19,539):

elif test -d ${jdkdir}/jre/lib/amd64/native_threads; then
threads=native
JAVACMD="\${jdkdir}/jre/bin/java"

That seems to have fixed our problem, perhaps it will help others who encounter the same error.

Cellular Automata Video Synthesizer

Written by  on January 8, 2009

Finished assembling my CAVS from Critter and Guitari.

Here it is in action:
CA Video Synthesizer in action

It’s more difficult than I expected to find a stable, interesting CA. But, although at first annoying, the audio helps find stable and interesting CAs.