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.