Friday, 27 February 2009

System.Shell.CommandLine (storm in a teacup)

Miguel's post caught my eye because it seemed to contain thoughtful analysis of a .NET 4.0 'feature' that had appeared in the latest beta (Miguel later added the pre-script to his post - which sorta spoils the end of the story). I like Miguel's perspective on the framework (particularly the core) given his work on Mono and Moonlight.

I was a big fan of Mono.GetOptions when I first saw it, having included in in Searcharoo.net back in 2007. Now I discover that Miguel is

not a fan of using attributes for command line options. Attributes are just a poor language for expressing complicated semantics, they can only do well for setting simple flags, but once that is over, they become just as bad as the System.Shell.CommandLine interface...We tried that before, that was called "Mono.GetOptions" and we obsoleted it a few years ago, it was a cute idea, but did not map well for real world use.
I guess I better check out Mono.Options. Here's my GetOptions implementation for posterity (I thought the attributes were kinda cool, and more readable/maintainable than any other alternative at the time...)


Elsewhere on my reading list, Bart simultaneously posted an alternative opinion - some detailed examples of the .NET 4.0 code to help people understand it (not sure if he was aware it might not make RTM).

I enjoyed both perspectives, although tended to agree with Miguel's position - that it belonged on CodePlex rather than in the Framework. Was interesting to see his later update indicating that is exactly what would actually happen.

Bit OT for a blog post... but interesting to see the next release growing & changing

Monday, 23 February 2009

Photosynth point cloud in c# (beta...)

Further to this post, I've done a bit more work on the C# version of this Python script to process multiple bin files, format the result for MeshLab and save it as a file with .ply extension (thanks to comments on this post).

View the code Program.cs
and the sample output points_0_0.bin.ply

Here's how the example Sydney Harbour synth looks on Photosynth.net


And this is the Meshlab .ply



Obviously I still haven't got the color parsing quite right (and I'm not 100% sure the point-count is correct...) but it's clearly the same set of points, so the C# code must be doing something right :)

Thursday, 19 February 2009

Photosynth point cloud in c# (alpha...)

Recent posts concerned with Photosynth and its availability on Silverlight 2.0 (and Moonlight) lead me to thinking about how to utilize the data generated by Photosynth (in Deep Zoom Viewer for example).

The first post - Exporting point clouds from Photosynth - was linked directly from Blaise Aguera y Arcas himself; it linked to another with some more detailed instructions - Photosynth Export Tutorial. Unfortunately all the code is in Python.

It seemed obvious to try and convert the Python script bin_to_csv.py to C#. At the risk of embarrassing myself with a poor translation, I'm posting the "work in progress" here in case it's of interest.

You can view the code for the .NET Console application (excerpt below) or download the Visual Studio project and test data ZIPped (238Kb)
code excerpt
NOTE: that I couldn't get the offset calculation to work - I ended up manually cycling through even numbers to get decent output for each .bin file - obviously this suggests perhaps I've screwed something up; but until I get time to test/work on it further, I'm not sure what...

I was testing data from this synth of Sydney



which seems to be just two files: points_0_0.bin and points_0_1.bin.
The output from the C# is points_0_0.txt (216Kb) and points_0_1.txt (109Kb).

Here's the first few lines
-6.723576, -1.410307 ,0.5756224, 4, 60, 8
-4.927393, -0.02451534 ,0.8836676, 21, 41, 21
-1.982108, 3.687859 ,0.03735788, 22, 45, 22
-1.845265, 3.327285 ,0.2232598, 6, 13, 6
-1.977082, 3.292458 ,0.3644025, 2, 8, 6
-1.478826, 3.45144 ,0.3358887, 9, 17, 9


I'm pretty sure at least some of the data is good - I could plot the first 56 points on Vladimir Bodurov's Silverlight 3D project, but I haven't had a chance to validate them any further.

Wednesday, 18 February 2009

EvoLisa "Animated Viewer" (in Silverlight)

In a previous post I added SVG output to the EvoLisa viewer. There is a 'cool' effect when loading the SVG in Firefox - it renders the polygons progressively which looks like it's animated (although unintentionally, when your connection is slow).

I decided to create the same effect with the Xaml output using Silverlight with Javascript.

Watch the "EvoLisa" Opera House images reveal by day and by night (using silverlight html host page).



NOTE: this animation is NOT the same thing as the image evolving as part of the EvoLisa program - it is merely gradually revealing a particular set of polygons that have been saved by the program.

NOTE2: it uses Silverlight 1.0, so it should be fine under the recently released Moonlight 1.0.

Monday, 16 February 2009

EvoLisa "Viewer"

This post is related to Roger Alsing's EvoLisa (or GenArt, if you prefer) genetic algorithm. If you aren't familiar with it, read the FAQ and check out the Image Gallery.

Here's how it looks "in action": the image on the left is the 'source', on the right is the evolving polygon 'dna' (it gets gradually better as the dna evolves):

Actually that image is probably too complex to be a great example, sorry.

Anyway, that's old news. This post is because I've added a little piece of code to the 'ecosystem': a viewer for the .DNA files that also lets you save a high-resolution JPG copy. It was inspired by a couple of comments asking about exporting the images.

This is what the DNA Viewer looks like - on the left is a Xaml rendering, on the right is an Image. They both look the same - the interesting bit is comparing the code that generates each of them

The Image is generated by the existing Renderer class in Roger's source (which is also the logic used to save the JPG); the Canvas version uses a new (although very similar) WpfRenderer class. From that it was trivial to create the XamlRenderer which outputs a .xaml file which can be used to view the GenArt creation in Silverlight!


You can download a GeneticDNAViewer_1.0.zip (16Kb) ZIPped exe to play with, or the WpfApplication itself can be reconstructed with the original source and these c# files:
Window1.xaml, Window1.xaml.cs, WpfRenderer.cs and XamlRenderer.

You can test it by unZIPping operahouse6.dna.zip and opening the .dna file inside. I've uploaded a 3200x2032 copy of the image on Flickr to demonstrate the high-resolution output.

FYI, the relative file sizes are:
- operahouse6.dna 51.4Kb
- scene.xaml 17Kb
- operahouse6.jpg 371Kb

p.s. Roger has posted subsequent performance-related posts on EvoLisa, but I'm not sure he's released the source for them yet.

UPDATE [17-Feb-09] another example:
Opera House by day .DNA 49Kb (ZIPped 17Kb)
Opera House by day (Silverlight 17Kb)
Opera House by day (Flickr 1920x1440 162Kb)



While I was testing the new 'DNA', I added SvgRenderer as well (needs updated Window1.xaml.cs). At first it didn't seem to work (left image) because I couldn't figure out how to make the background black. Decided to draw a big black rectangle behind the rest (bit of a hack, but it works). You can view operahouse_day.svg.xml (21Kb) in Firefox.

Friday, 13 February 2009

Photosynth for Mac (as well as Linux)

Yesterday's post talked about Photosynth becoming available on Moonlight, via a new Silverlight-based Photosynth viewer.

Since Silverlight 2.0 is already available for Mac, it makes sense that the 'test' Sydney synth also works on the Mac - which it does (in Safari, even!):


However, while it isn't very obvious, Microsoft has already started enabling the Photosynth website itself for Mac users! The javascript-driven homepage always worked...


But now if you attempt to access a synth you should see this message (since, like, mid-December)


and assuming you have Silverlight 2.0 installed, away you go!




Unfortunately you still need a Windows PC to create synths, but there are quite a few available to browse, including Barack Obama's inauguration.

Thursday, 12 February 2009

Photosynth in (Moon|Silver)light

Scott, Scott and Tim were among the first to blog about today's big news - Miguel de Icaza's announcement that Moonlight 1.0 is live! It's a pretty impressive achievement, which I hope to write more about once I have installed and played with it myself.

However, hidden in Miguel's post was something else I thought was just as cool -- Barack Obama's inauguration Photosynth The Moment was shown in Moonlight (not just on Photosynth)... wha!?

I thought this was a massive 'discovery'. Photosynth previously had a custom viewer install that only ran on Windows... and now it's on Linux?!

Turns out ScottGu did 'announce' this, back in January (don't know how I missed it)

CNN and MSNBC are both launching Photosynth viewers that will ... combine pictures ... to create an interactive Photosynth experience of the event using Silverlight’s built-in DeepZoom feature to deliver an amazing 3D viewing of it.
Check out the difference between the plug-in version (view synth):


and the Silverlight version (view synth and object tag):

Very similar - all the Silverlight version is missing is the 'control point cloud' that you see holding down Ctrl in the embedded viewer.

Turns out the CNN version hosts Photosynth.xap with the following assemblies -- including Kit3D!

Here's how the HTML looks to host it. It's fairly trivial to extract the .DZC filename from a Photosynth.net page and embed it in Silverlight.

In Photosynth.net HTML source
Find the var _collectionInfo JSON object and extract the
"Url":"http://mslabs-328.vo.llnwd.net/d6/photosynth/M6/collections/89/49/43/894943c7-0a67-477f-9607-1eb1ee62eab1.dzc"

In a new Silverlight host page paste the DZC in the initParams
<param name="initParams" value="autoplay=true,dzcPath=http://mslabs-328.vo.llnwd.net/d6/photosynth/M6/collections/89/49/43/894943c7-0a67-477f-9607-1eb1ee62eab1.dzc"/>

So if you are playing around with Moonlight 1.0 it's fairly trivial to access the thousands of existing Photosynths (unfortunately I think you'll still need Windows to create one).


Finally, unless Microsoft releases something 'official' I doubt it's allowed to redistribute Photosynth.xap to display your own synths (especially for commercial purposes). Interestingly, the Photosynth site still says Like the viewing experience, the "synther" only runs on PCs (XP and Vista) :-).


P.S. I expected a Silverlight synth viewer sooner; writing back in August 2008
given the shared heritage with the Silverlight 2.0 MultiScaleImage control I wouldn't be surprised to see a Photosynth 'viewer' in RTM version of Silverlight 2.0 (or certainly a future version after that).

EDIT: I had previously wondered how the Photosynth data was stored, since each Photosynth is opened via a .DZC file (see above). I guess Fiddler would have answered the question - a JSON file is downloaded based on the DZC location: dzcUrl.Replace(".dzc", ".synth_files/0.json"). A summary of the JSON for that synth is shown here (thanks to JSON Viewer).

I guess it's all this data that was harvested for the pointcloud explorer built by these guys, in Python!

Silverlight + Model-View-ViewModel (MVVM)

I've been collecting links & info about Model-View-ViewModel in Silverlight (and WPF) for a while - these are my favourites:

StackOverflow question Should I use the Model-View-ViewModel (MVVM) pattern in Silverlight projects? Links to a couple of good posts including
MSDN Magazine's WPF Apps With The Model-View-ViewModel Design Pattern
Why WPF Developers Love MVVM

Once a developer becomes comfortable with WPF and MVVM, it can be difficult to differentiate the two. MVVM is the lingua franca of WPF developers because it is well suited to the WPF platform, and WPF was designed to make it easy to build applications using the MVVM pattern (amongst others). In fact, Microsoft was using MVVM internally to develop WPF applications, such as Microsoft Expression Blend, while the core WPF platform was under construction. Many aspects of WPF, such as the look-less control model and data templates, utilize the strong separation of display from state and behavior promoted by MVVM.
Dan Crevier's DataModel-View-ViewModel pattern series 8-part series including sample DataModel and ViewModel (WPF-focused).
David Wynn's Silverlight and the View-ViewModel Pattern Example using NInject, Silverlight Extensions (Command) and Unit Testing.
Josh Smith discusses MVVM eliminates 99% of the need for ValueConverters Paul Stovell, Laurent Bugnion, Jaime Rodriguez (among others) weigh in on the proposition that:
The only place I can see a use for value converters in an MVVM architecture is cross-element bindings. If I'm binding the Visibility of a panel to the IsChecked of a CheckBox, then I will need to use the BooleanToVisibilityConverter.
Mark Heath's Model View View-Model (MVVM) in Silverlight Basic 'scoreboard' example demonstrating MVVM in Silverlight 2.0
John Gossman's Introduction to Model/View/ViewModel pattern for building WPF apps Whoa - John talks about MVVM back in October 2005, talking about the "Sparkle UI". The MSDN article (above) quote "In fact, Microsoft was using MVVM internally to develop WPF applications, such as Microsoft Expression Blend, while the core WPF platform was under construction" must be true!

I've kept a copy on conceptdevelopment.net too.

Wednesday, 11 February 2009

Cooliris on iPhone

It wasn't that long ago I was impressed by Microsoft's SeaDragon (DeepZoom) on iPhone... but I just discovered that Cooliris has also released an iPhone viewer and it's just as cool!



Although you can't see it in a static screenshot, it also includes the same '3D floating wall effect' as the Windows version. Download from iTunes or just search in the AppStore.

Sunday, 1 February 2009

Microsoft Tag: CMYK or bust?

As I mentioned previously, the Microsoft Tag HCCB format - which is CMYK by default - has been tested in various monochrome formats. Since then, however, I read about the 'palette symbols' - the final four triangles which are the same in every Tag and therefore enable the decoder to handle many color reproductions (once it figures out the bounds and orientation of the tag).

Microsoft Tag: ConceptDevelopment.net
To test out the palette's influence on the decoder, the tag shown to the left has been recolored and then "read" with the Tag Reader application for iPhone.

Each of these versions: Red, White & Blue; Purple, Yellow & White; Blue, Lime & White was decoded successfully. Admittedly the conditions were 'perfect' (represented on screen, photo taken square-on and filling the viewfinder, etc) but it does suggest the format is less sensitive to specific colors than it seems.



I'm sure Microsoft put a lot of thought into standardizing on CMYK though - probably not a great idea to put one of these 'custom color' tags into the wild...

[EDIT] Interestingly, there is some sort of error correction or extraneous symbols in the current implementation too - a couple of my Tags (including the one shown above) work with the bottom row 'blacked out' (but not the 'palette' symbols) like this:

Weird.

Microsoft Tag: how does the High Capacity Color Barcode work?


Microsoft Tag was recently announced at CES 2009. It is a new mobile-camera-reading-barcoding scheme that uses
Microsoft Research's High Capacity Color Barcode (which has been around since at least April 2007).

First interesting point
it works in monochrome, not just CMYK. One of the commenters on that thread seems to have missed the point by 'complaining' about Microsoft's "choice" of colors... If the product is aimed at print media, using the base components of four color process printing seems kinda logical?

Second interesting point
Microsoft Tag itself is not a data-storage format. It's like tinyURL but on paper, in color. The HCCB (barcode) standard allows 'storage' any amount of data, but for the fixed size image that Microsoft Tag uses, it makes more sense to store a 'pointer' or lookup to data - held on Microsoft's servers (of course). So Microsoft Tag is really just a 'brand' for an implementation of Research's HCCB idea.

Third interesting point
Microsoft released the reader software across a wide variety of phone platforms almost simultaneously - from iPhone, Android and Blackberry to J2ME, Symbian, PalmOS and Windows Mobile.

BUT how does it actually work?

As per point #2 above - all Tag barcodes must be created on the Microsoft Tag website (Live ID required) since the barcode itself will only contain a 'pointer' to the actual content it references (either a Url, Vcard or just plain text). The input form for a URL barcode looks like this:

(which produced the tag at the top of this post)

Having generated a barcode, you may then wonder how much data is actually stored? (ie. how big is the pointer? how many tags can we make before we run out? are there enough GUIDs in the world :), etc). The HCCB page has a brief description of how four colors compares to two:


So where Black & White limits us to either 0 or 1 for each symbol, using four colors allows 00, 01, 10 or 11 to be represented by a single symbol. The public documentation doesn't seem to discuss much about the use of triangular symbols as opposed to squares - but it "just looking at it" seems more space efficient (and it possibly has advantages when visual-processing too).

Now assuming each symbol/triangle represents two bits, and a tag has 5 rows of 10 symbols (50 symbols = 100 bits), we might assume 12.5 bytes can be stored. The Wikipedia HCCB page says

Microsoft Tag is an implementation of HCCB using 4 colors in a 5 x 10 grid. This yields 105 bits, or 13 bytes, of raw data
however elsewhere in the description of HCCB it notes that the final four symbols/triangles are always the same - the 'palette' which ensures that even in poor color/lighting/contrast/etc conditions the decoder can still differentiate between Yellow, Magenta, Black and Cyan - so we lose 4 symbols/8 bits/1 byte.

That leaves us with 92 bits, or 2 ^ 92 possible combinations. Windows Calc tells me that's 4951760157141521099596496896 Tags (without using some of the bits for error detection/correction or some other purpose). GUIDs are 128-bit by comparison.

That isn't to say that the bits represented by the symbols are simply encoded and resolved to a URL on Microsoft's server... consider the example below:

Microsoft Tag: ConceptDevelopment.netHere is an existing Tag created on the Microsoft Tag website to redirect to a URL. Using Fiddler after scanning the tag on an iPhone it's easy to see how the Microsoft Tag application "works" over the Internet...

After photographing and decoding the HCCB, it requests two URLs (shown below), both containing a string like this - L25RKKEP6HTXXCZYBP2X2TIMRBCBDW4V - which appears to be a Base 36 encoded string (but representing much more data than the 92 bits theoretically "in" the barcode). It may be encrypted or signed or something - but given it's the common element between the two, it seems likely to represent the barcode contents somehow.

The first request sends User-Agent: TagReader/2.1.68 CFNetwork/342.1 Darwin/9.4.1 - it's sent by the Tag application itself to retrieve the actual contents of the barcode.
http://rs.tag.microsoft.com/L25RKKEP6HTXXCZYBP2X2TIMRBCBDW4V.aspx?Level=1&VID=5+0&RequestType=1

<PAYLOAD><NAME>ConceptDevelopment</NAME></PAYLOAD>

This NAME is then used in the application History. The response (perhaps by the lack of other <DATA>) then causes the application to 'generate' a second request... which sends User-Agent: Mozilla/5.0 (iPhone; U; CPU iPhone OS 2_2 like Mac OS X; en-us) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.1.1 Mobile/5G77 Safari/525.20 indicating it's actually Safari calling...

http://rs.tag.microsoft.com/L25RKKEP6HTXXCZYBP2X2TIMRBCBDW4V.aspx?Level=1&VID=5%2B0&TH=_%2Bxrkqa8CU1GhOgWheA%24&PL=r9gT2kA6Wnk7_odMCmtkGJCExSXvsSjMERpFBSHlqAw6JDB47PPYcevPGKZOOl5NUuuvfXMMUiye6J9Dl4QUhCE5fVsroOcMe14zeZ%2BXrlTJvAzSMT5bFCb4o29PTzQD%2BJraRt3YY6orTVl2JZTMaDUiM2rn5txFv8Y%24

<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="http://conceptdev.blogspot.com/">here</a>.</h2>
</body></html>

and getting redirected to http://conceptdev.blogspot.com/!

The other barcode types (Text, vCard, Dialler) only send a single request

http://rs.tag.microsoft.com/I3WC77ROEQOP5AL46TPRSU23BZHWZSG2.aspx?Level=1&VID=5%2B0&TH=_%2Bxokry8Ck1AhMMWheA%24&PL=t6IX2kQ5Jwg79vYxdQkAGoa4py78uwSrEBZcH0eNqnIiXjR46PClAOvHacYxWyJPROnNcGAEVEuf5IZZ8ewW%2BjlDeVsvo5p9e1ZCGeD20lbfvm7fIjZdcyf0unUpJzZ94OHeRtnbHtsrRSgWWvO6aiMgUWf07toivso%24

and get a single (more detailed) response to be decoded by the Tag application.

<PAYLOAD><NAME>ConceptDevelopment services</NAME>
<PIN>0</PIN>
<DATA>
r6QEsUVaVGZOm9MVWDszHo_0vTzeonHOUytWESKQ3gVLLjl5kfK5IsvFGaJYLDsEEK3mM2ESIlGlqJp465U4mm1Za1AEgvYhFgwVEr21nnnhijDNAXsjHRWt9k5pGhpIqryJAvr9IYFRHWZWbNi7GmcbG1KivZ4C_Zwo9XgMcU0K8_InYRJ0FouulAj4nCn6bAZ+BQO+6U0QU0E+pL+ECPaALYhoJn9QatmXbD0dDy2juowX6YFjj2IaA08Ru+l1awZKX6remxSQ2S6IbhtgNwun4CB0CglEvqiYY7WWOIA5WCVWH8zmLRIdAlei9Z95+4kmh2MFJ14JqaYXWC0udfM$
</DATA></PAYLOAD>

which in this case displays the following: