Custom Server Algorithm

<< Click to Display Table of Contents >>

Navigation:  XStream® HDVR® SDK > Implementation Concepts >

Custom Server Algorithm

Previous pageReturn to chapter overviewNext page

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

Summary

 

The XStream® HDVR® SDK can incorporate user-defined functions that execute a custom algorithm on the rendering server. Through this mechanism, custom algorithms  that provides the ability to process the DICOM or the original image data. This is useful for the creation of custom segmentation routines, incorporation of advanced fusion and registration capabilities, and execution of custom image processing filters or image data analysis algorithms such as volumetric analysis.

 

The XStream HDVR Server API provides an interface to easily incorporate this functionality into your application. Although the functions and methods specified in the API have a segmentation name, the user-defined algorithm is more general and does not necessarily imply use of segmentation.

 

Defining the Custom Server Function (Server API)

 

The first step in defining a custom server function is to write the server-side routine itself. The custom server function must conform to the segmentfunc type as shown below. This function must be defined in the XStream HDVR Server API as it runs in the server application process space. The advantage to running on the server is that all image data is already in memory and shared, and more importantly does not need to be downloaded and processed on the client.

 

NOTE:  The XStream HDVR Server API is only available in the C++ language, although the client can invoke it from any client API.

 

typedef h_int32 (segmentfunc)(h_int32 segmenttype, char *psz, IVolumeData *pVolumeData, IVolumeOctree *pVolumeOctree, ITaskProgress *piTask, h_int64 taskID);

 

Since the amount of time the custom server function requires is based on the underlying algorithm, appropriate user interface guidelines should be considered. When the custom server function is executed from the client, the client will block until the function completes. The preferred approach is to launch and run the custom server function in a separate thread. A second custom server function can then report the progress back through the user interface on the client on the status of the primary custom server function.

 

The custom server function takes the following parameters:

h_int32 segmenttype

The custom server function ID value (see Setting the Custom Server Function).

char *psz

A block of data that has been cast to the char* type. This parameter is used to pass user data from the client application to the custom server function.

IVolumeData *pVolumeData

The IVolumeData object associated with this function call.

IVolumeOctree *pVolumeOctree

The IVolumeOctree object associated with this function call.

ITaskProgress *piTask

Reserved for future use.

h_int64 taskID

Reserved for future use.

 

Accessing the IVolumeSegmentation object

 

Accessing the IVolumeSegmentation object associated with the IVolumeOctree input parameter is accomplished with the IVolumeOctree::GetSegmenter() function. In order for an IVolumeSegmentation object to be available to the custom server function, an IVolumeSegmentationContext object must have already been created and initialized from the client application. If an IVolumeSegmentation object is created and initialized within the custom server function, it will not be accessible to the client application.

 

Setting the Custom Server Function (Server API)

 

Once the custom server function has been defined, it is then registered with the server through the XStream HDVR Server API method IHdrcServer::SetSegmentFunc(). This function takes two input parameters. The first parameter that serves as the function ID and is used to reference the custom server function from the client application. It must be cast to the ENUM_SEGMENT_FUNC enumeration and be between the ENUM_SEGMENT_FUNC::LF_CUSTOM_START and ENUM_SEGMENT_FUNC::lF_CUSTOM_END values. The second input parameter is a pointer to the custom server function itself.

 

// Define custom server function.

h_int32 UserAlgorithm(h_int32 segmenttype, char *psz, IVolumeData *pVolumeData, IVolumeOctree *pVolumeOctree, ITaskProgress *piTask, h_int64 taskID) {

   // Execute custom server algorithm.

}

 

// Register the custom server function.

pHdrcServer->SetSegmentFunc(ENUM_SEGMENT_FUNC(1042), UserAlgorithm);

 

Calling the Custom Server Function (Client API)

 

Once the custom server function has been defined and registered with the server application, it can be called from a client application.

 

Using the C++ client API, the custom server function is invoked  using the IVolumeSegmentationContext::CustomSegmentationFunction() method to execute the server side custom function. This method takes four input parameters. The first parameter is an integer representing the function ID as registered in the server application with the IHdrcServer::SetSegmentFunc().The second parameter is a character string that is passed to the custom server function with any user-defined data from the client to the server. The third and fourth parameters are the IVolumeDataContext and IOctreeContext that the server side custom function should operate on. Within the server application, these correspond to server side IVolumeData and IVolumeOctree objects.

 

char *userData = "User data string";

pVolumeSegmentationContext->CustomSegmentationFunction(42, userData, pVolumeData, pOctreeData);

 

NOTE: The IVolumeSegmentationContext::CustomSegmentationFunction() method will block until the custom server function completes. The preferred approach is to launch and run the custom server function in a separate thread. A second custom server function can then report the progress back through the user interface on the client on the status of the primary custom server function.

 

 

Using the Java++/.NET API, the custom server function is invoked using the hdrcIVolumeSegmentation::CustomSegmentationFunction() method to execute the server side custom function. This method takes four input parameters. The first parameter is an integer representing the function ID as registered in the server application with the IHdrcServer::SetSegmentFunc().The second parameter is a character string that is passed to the custom server function with any user-defined data from the client to the server. The third and fourth parameters are the hdrcVolumeDataContext and hdrcOctreeContext that the server side custom function should operate on. Within the server application these correspond to server side IVolumeData and IVolumeOctree objects.

 

String userData = "User data string";

volumeSegmentation.CustomSegmentationFunction(42, userData, volumeData, octreeData);

 

NOTE: The hdrcIVolumeSegmentation::CustomSegmentationFunction() method will block until the custom server function completes. The preferred approach is to launch and run the custom server function in a separate thread. A second custom server function can then report the progress back through the user interface on the client on the status of the primary custom server function.