Managing Presets

<< Click to Display Table of Contents >>

Navigation:  XStream® HDVR® SDK > Implementation Concepts >

Managing Presets

Previous pageReturn to chapter overviewNext page

C++ C++ Java Java .NET .NET

Summary

 

When rendering an image using the XStream® HDVR® SDK, the render engine state is set with the RENDER_PARAMS structure. This structure contains all the data fields that control how an image is rendered. The data fields in the RENDER_PARAMS structure may be set directly in code, or they may be set in an end user application with user interface controls. Once a RENDER_PARAMS structure is configured, it may be saved to disk as an XML preset file for later reuse. The XStream HDVR SDK provides utility methods for saving and loading these preset files. Preset files may be saved to either the client or server machine. For more information on configuring the RENDER_PARAMS structure, see the Render Parameters page.

 

Saving an XML Preset: Server Side Methods

 

The IServerContext::SavePreset() method can be used to save a RENDER_PARAMS structure to an XML preset file for reuse at a later time. The function takes as input parameters a path and file name to save the file to, and a RENDER_PARAMS structure to be saved. The file path is relative to the server machine and the server application's working directory.

 

// Get render params from the desired render engine.

RENDER_PARAMS rp;

pRenderEngine->GetRenderParams(&rp);

 

// Save render params to an XML file.

pServerContext->SavePreset("/data/presets/new_preset.xml", &rp);

 

The hdrcServerContext::savePreset() method can be used to save a RENDER_PARAMS structure to an XML preset file for reuse at a later time. The function takes as input parameters a path and file name to save the file to, and a RENDER_PARAMS structure to be saved. The file path is relative to the server machine and the server application's working directory.

 

// Get render params from the desired render engine.

RENDER_PARAMS rp = new RENDER_PARAMS();

rp = renderEngine.getRenderParams();

 

// Save render params to an XML file.

serverContext.savePreset("/data/presets/new_preset.xml", rp);

 

Loading an XML Preset: Server Side Methods

 

The IServerContext::LoadPreset() function can be used to load a previously saved XML preset file into a RENDER_PARAMS structure. The method takes as input parameters a path and file name from which the file is to be loaded, and a RENDER_PARAMS structure to contain the loaded data. The file path is relative to the server machine and the server application’s working directory.

 

RENDER_PARAMS rp;

 

// Load a new preset into a RENDER_PARAMS structure.

pServerContext->LoadPreset("/data/presets/saved_preset.xml", &rp);

 

// Apply the RENDER_PARAMS structure.

pRenderEngine->SetRenderParams(&rp);

 

The hdrcServerContext::loadPreset() function can be used to load a previously saved XML preset file into a RENDER_PARAMS structure. The method takes as input parameters a path and file name from which the file is to be loaded, and a RENDER_PARAMS structure to contain the loaded data. The file path is relative to the server machine and the server application’s working directory.

 

RENDER_PARAMS rp = new RENDER_PARAMS();

 

// Load a new preset into a RENDER_PARAMS structure.

serverContext.loadPreset("/data/presets/saved_preset.xml", rp);

 

// Apply the RENDER_PARAMS structure.

renderEngine.setRenderParams(rp);

 

Saving an XML Preset: Client Side Method

 

The IPresetUtils::WriteParamsToXml() method can be used to save a RENDER_PARAMS structure to an XML preset file for reuse at a later time. The method takes as input parameters a path and file name to save the file to, and a RENDER_PARAMS structure to be saved. The file path is relative to the client machine and the client application’s working directory.

 

// Create an IPresetUtils object

IPresetUtils *pPresetUtils;

pLibrary->CreateObject(&CLSID_PresetUtils, &pPresetUtils);

 

// Get render params from the desired render engine.

RENDER_PARAMS rp;

pRenderEngine->GetRenderParams(&rp);

 

// Save render params to a XML file.

pPresetUtils->WriteParamsToXml("/data/presets/new_preset.xml", &rp);

 

The RENDER_PARAMS.saveToXML() method can be used to save a RENDER_PARAMS structure to an XML preset file for reuse at a later time. The method takes as an input parameter the path and file name to save the file to. The data is saved from the calling RENDER_PARAMS structure. The file path is relative to the client machine and the client application's working directory.

 

// Get render params from the desired render engine.

RENDER_PARAMS rp = new RENDER_PARAMS();

rp = renderEngine.getRenderParams();

 

// Save render params to an XML file.

rp.saveToXML("/data/presets/new_preset.xml");

 

Loading an XML Preset: Client Side Method

 

The IPresetUtils::ReadParamsFromXml() method can be used to load a previously saved XML preset file into a RENDER_PARAMS structure. The method takes as an input parameter the path and file name to load the file from and a RENDER_PARAMS structure to hold the loaded data. The file path is relative to the client machine and the client application's working directory.

 

// Create an IPresetUtils object

IPresetUtils *pPresetUtils;

pLibrary->CreateObject(&CLSID_PresetUtils, &pPresetUtils);

 

// Get render params from the desired render engine.

RENDER_PARAMS rp;

 

// Load a new preset into a RENDER_PARAMS structure.

pPresetUtils->ReadParamsFromXml("/data/presets/saved_preset.xml", &rp);

 

// Apply the RENDER_PARAMS structure.

pRenderEngine->SetRenderParams(&rp);

 

The RENDER_PARAMS.loadFromXML() method can be used to load a previously saved XML preset file into a RENDER_PARAMS structure. The method takes as an input parameter the path and file name to load the file from. The data is loaded into the calling RENDER_PARAMS structure. The file path is relative to the client machine and the client application's working directory.

 

RENDER_PARAMS rp = new RENDER_PARAMS();

 

// Load a new preset into a RENDER_PARAMS structure.

rp.loadFromXML("/data/presets/saved_preset.xml");

 

// Apply the RENDER_PARAMS structure.

renderEngine.setRenderParams(rp);

 

Using a Subset of RENDER_PARAM Settings

 

Typically, not every field of the RENDER_PARAMS structure will be in use. A given RENDER_PARAMS structure may contain only a camera transform or transfer function, with the other fields unused. Although subsets of the RENDER_PARAMS structure cannot be saved, you can determine which fields are valid from the RENDER_PARAMS::Mask and RENDER_PARAMS::FlagsMask fields. These fields are bitmasks comprised of ENUM_RENDER_PARAMS_MASK and ENUM_RENDER_FLAGS bit flags. The developer can set/clear these flags to ensure that only the desired fields are in use. If a given bit is set, that field of the RENDER_PARAMS structure is valid; otherwise the XStream HDVR engine ignores it. For more information on use of the RENDER_PARAMS structure, see the Render Parameters section.

 

Generating Thumbnails

 

Thumbnail images presented as a collection of saved presets are commonly featured in end-user applications, so that the user can see a visual representation of the preset file settings. To generate the thumbnail images, a small image of the dataset in question is rendered using the preset file settings. These thumbnail images are then added to a user interface image collection object. The display of this thumbnail collection is done in an application-specific manner. Some sample code that demonstrates how this might be done is provided below.

 

QT - C++

 

Microsoft Windows - .NET Framework (C# / .NET)

 

Java

 

// Generates an IconImage thumbnail and adds it to the designated container. 

public void addPresetFile(String filepath) {

   try {

      // create a render engine and octree context

      hdrcRenderEngineContext rec = m_3DrenderControl.getServerContext().createRenderEngine(0);

      rec.setVolumeData(m_3DrenderControl.getVolumeDataContext(), m_3DrenderControl.getOctreeContext());

 

      // now load the rendering parameters from a valid XML file

      RENDER_PARAMS rp = new RENDER_PARAMS();

      if (rp.loadFromXML(filepath)) {

         // change the size since we are generating a thumbnail, and set them

         rp.adjustZoomForNewSize(rp.RenderImageSize.cx, rp.RenderImageSize.cy, kThumbnailWidth, kThumbnailHeight);

         rp.RenderImageSize.cx = kThumbnailWidth;

         rp.RenderImageSize.cy = kThumbnailHeight;

         rec.setRenderParams(rp);

 

         VOLVISIMAGE imRes = new VOLVISIMAGE();

         VOLVISIMAGE imReq = new VOLVISIMAGE();

         imReq.Stage = VOLVISIMAGE.RENDER_STAGE_PROGR0;

 

         // now render into our memory buffer

         rec.render(imReq, imRes);

         rec.renderStreamed(imReq, rp, null, new long[] { 0, 0, 0, 0 }, null, imReq, true);

 

         // generate the icon

         ImageIcon imageIcon = generateThumbnail(imRes);

 

         // do a clean reload of the original preset that is then stored in our thumbnail preset model

         rp.loadFromXML(filepath);

 

         // save the model

         ThumbnailLabel thumbnailRenderer = new ThumbnailLabel(new ThumbnailContext(filepath, rp, imageIcon));

         m_thumbnailContainer.add(thumbnailRenderer);

 

         // increment the thumbnail count and determine if we need to increment the scroll bars

         m_numThumbnails++;

         if (m_numThumbnails > 6) {

            m_thumbnailContainer.setPreferredSize(new Dimension(280, (m_numThumbnails + 2) / 3 * 100));

         }

 

            m_thumbnailContainer.revalidate();

         } else {

            if (m_displayPresetWarning) {

               JOptionPane.showMessageDialog(null, "Preset file not found:  \n\n " + filepath);

               System.out.println("addPresetFile:  file not found -- " + filepath);

            }

         }

 

         rec.releaseSessionResources();

      } catch (IOException ex) {

         System.out.println("addPresetFile:  exception generating thumbnail");

         ex.printStackTrace();

      }

   }

}

 

// Generate the ImageIcon resource.

private ImageIcon generateThumbnail(VOLVISIMAGE vvi) {

 

   int btype = 0;

   switch (vvi.Type) {

   case VOLVISIMAGE.IMAGE_TYPE_LUMINANCE8:

      btype = BufferedImage.TYPE_BYTE_GRAY;

      break;

   case VOLVISIMAGE.IMAGE_TYPE_LUMINANCE12:

      btype = BufferedImage.TYPE_USHORT_GRAY;

      break;

   case VOLVISIMAGE.IMAGE_TYPE_RGB:

      btype = BufferedImage.TYPE_3BYTE_BGR;

      break;

   default:

      System.out.println("generateThumbnail:  invalid image type");

      return null;

   }

 

   BufferedImage img = new BufferedImage(kThumbnailWidth, kThumbnailHeight, btype);

   WritableRaster rasD = img.getRaster();

   DataBuffer dbD = rasD.getDataBuffer();

   DataBufferByte dbbD = (DataBufferByte) dbD;

   byte dst[] = dbbD.getData();

 

   System.arraycopy(vvi.Data, 0, dst, 0, dst.length);

 

   return new ImageIcon(img);

}