Of course. This snippet is from the ImageRegistration module:
ImageWindow StarAlignmentInstance::CreateImageWindow( const View& view, const IsoString& postFix, int bitsPerSample, bool floatSample )
{
IsoString id = ValidFullId( view.FullId() ) + postFix;
ImageWindow window( 1, 1, 1, bitsPerSample, floatSample, false, true, id );
if ( window.IsNull() )
throw Error( "Unable to create image window: " + id );
return window;
}
and the ValidFullId routine, which is useful when you want to use previews, is something like:
static IsoString ValidFullId( const IsoString& id )
{
IsoString validId( id );
validId.ReplaceString( "->", "_" );
return validId;
}
The following functions:
IsoString View::Id() const
IsoString View::FullId() const
provide the identifier and full identifier, respectively, of any view. For a preview, the full identifier is composed of the main view's identifier and the preview's identifier, separated with the "->" sequence. For a main view, FullId() and Id() give the same string. The ValidFullId() routine above transforms a preview full id into a valid view identifier.
The CreateImageWindow() function allows you to create a new image window with the specified bit depth and data type, taking a view's full identifier as the basis to build the id of the newly created window, plus an optional postfix. I use routines like these quite frequently.
Finally, you'll probably wonder what's the trick behind:
ImageWindow window( 1, 1, 1, bitsPerSample, floatSample, false, true, id );
This is a special call to ImageWindow's constructor. When the core receives a request to create a 1x1x1 image, it knows that what is being created is actually a placeholder where an actual image will be built later. You can assign any image to window.MainView().Image(), and the core will keep track of the assignment automatically. This technique is useful when you don't know in advance the dimensions and color space of the final image.
Of course, change the above code as necessary. For example, to create a 1024x768 RGB color image:
ImageWindow window( 1024, 768, 3, bitsPerSample, floatSample, true, true, id );
Hope this helps