Saturday, June 14, 2008

Understanding Deep Zoom - Part 3

My previous post was on Collection and Composition. Let's try and understand the tool that generates a collection or a composition.

Deep Zoom Composer has a tool named SparseImageTool.exe that is used to produce the final composition or collection. It can be accessed from command prompt as

C:\Program Files\Microsoft\Deep Zoom Composer\SparseImageTool.exe

Giving the above command generates the usage pattern for the tool

deepzoomcmd

The basic usage pattern is SparseImageTool.exe <command> <SceneGraphFileName> [parameters]

where command could be CreateCollection  or CreateDeepZoomImage

SceneGraphFileName is path for the SceneGraphFile.xml file

[parameters] refers to a list of other parameters that this application can take.

The SceneGraphFile.xml file has information about the images (width, height, position as x,y co-ordinates), aspect ratio and ZOrder for all images. This is generated by Deep Zoom Composer prior to calling SparseImageTool.exe.

Is it possible to access this tool programmatically? Well, let's try doing so. First, we need to create an XML file that looks similar to SceneGraphFile.xml that is generated by the Deep Zoom Composer.

The XML file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<SceneGraph Version="1">
   <AspectRatio>1</AspectRatio>
   <SceneNode>
     <FileName>C:\Folder\Pic1.JPG</FileName>
     <x>0</x>
     <y>0</y>
     <Width>1</Width>
     <Height>1</Height>
     <ZOrder>0</ZOrder>
   </SceneNode>
   <SceneNode>
     <FileName>C:\Folder\Pic2.JPG</FileName>
     <x>0</x>
     <y>0</y>
     <Width>1</Width>
     <Height>1</Height>
     <ZOrder>1</ZOrder>
   </SceneNode>
</SceneGraph>

Now, let's create a C# Console Application (I think you can try doing the same using VB as well...but am not sure).

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Resources;

namespace deepzoomscenario1
{
    class Program
    {
        static void Main(string[] args)
        {
            Process p = new Process();
            p.StartInfo.FileName = "C:\\Program Files\\Microsoft\\Deep Zoom Composer\\SparseImageTool.exe";
            p.StartInfo.Arguments = @"CreateCollection ""C:\\Users\\S.Preethi\\Desktop\\Folder\\test source.xml"" ""C:\\Users\\S.Preethi\\Desktop\\Folder\\result.sdc"" /XML";
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            p.EnableRaisingEvents = true;
            p.Start();
            p.WaitForExit();
        }
    }
}

The folder contents before running the program is

dz31

Running the Console Application

dz32

Final output

dz33

Notice that the result folder has an XML file items.xml. The updated version allows generation of an XML file as against a Binary file in the previous version. We can now work with this XML file with ease. We can use this XML file to randomly position the images and do a lot of other things (Translation: More ideas coming soon).

The above operation can be done from Command Prompt as well.

SparseImageTool.exe CreateCollection "C:\Users\S.Preethi\Desktop\Folder\test source.xml" "C:\Users\S.Preethi\Desktop\Folder\result.sdc" /XML

Note: The extension .sdc has to be given correctly. Otherwise, the tool doesn't generate a collection.

No comments: