Annotations

<< Click to Display Table of Contents >>

Navigation:  XStream® HDVR® SDK > Advanced Functionality >

Annotations

Previous pageReturn to chapter overviewNext page

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

Summary

Annotations are text, lines, or other graphical labels that are drawn on top of the images rendered by the XStream® HDVR® SDK. Annotations can be used to label structural features, as outlines for region selection operations, as measurement lines, or for other purposes. The XStream HDVR SDK does not supply methods for drawing such annotations on screen. This is accomplished with drawing methods specific to the GUI toolkit and language being used to implement an application. Some examples of platform-specific drawing methods are discussed in the Render Window Overlay section. The XStream HDVR SDK does provide some utility methods that facilitate the conversion between 3D volume coordinates and 2D screen space coordinates. These can be used to calculate the appropriate screen position of annotation drawings and objects. For additional information on the XStream HDVR SDK coordinate system, see the section on Understanding Coordinates.

 

 

AnnotationFig1

Volume rendering with annotation lines and labels.

 

Annotation Utility Methods

 

Several utility methods are provided in the C3DHelpers (or hdrc3DHelpers) class that facilitate the conversion between 3D volume coordinates and 2D screen space coordinates. These methods are discussed below. When developing an HDVR® application, it is recommended that the annotation coordinates be stored in 3D volume coordinates, then converted to 2D screen coordinates when annotation display is desired. This is because the screen coordinates change whenever the view position and orientation are changed.

 

Converting 3D Volume Coordinates to 2D Screen Coordinates

 

Converting 3D volume coordinates to 2D screen coordinates is accomplished with the C3DHelpers::Volume2ProjectionPlane(). This method takes a coordinate in 3D volume space and converts it to a 2D screen space coordinate. The C3DHelpers::Volume2ProjectionPlane() method takes into account the current render mode, zoom, slice spacing, camera transform, and view angle settings. The current render mode, zoom, and camera transform can be accessed in the current RENDER_PARAMS structure, which can be obtained with a call to IRenderEngineContext::GetRenderParams() or IRenderQueue::GetRenderParams(). The volume slice spacing can be obtained from the VOLUME_DATA_PARAMS structure. The VOLUME_DATA_PARAMS structure can be obtained with a call to IVolumeDataContext::GetVolumeDataParams(). The view angle parameter can be calculated with a call to the C3DHelpers::GetConvertedViewAngle() method. This method take as input parameters the size of the image being rendered, and the current field of view. These can both be obtained from the current RENDER_PARAMS structure. The C3DHelpers::GetConvertedViewAngle() method returns as an output parameter the converted view angle value to be used with the C3DHelpers::Volume2ProjectionPlane() method.

 

If the input 3D volume coordinate is outside the current view area, the 2D screen space coordinate may be negative, or larger than the window dimensions. Check the 2D screen space coordinates to ensure that the application does not attempt to draw to an off-screen location.

 

RENDER_PARAMS rp;

BCOM_ZEROMEMORY(rp);

 

C3DHelpers c3DHelpers;

 

// Get render params for input parameters.

rp.Mask = (ENUM_RENDER_PARAMS_MASK)(RPM_RENDER_TYPE | RPM_TRANSFORM | RPM_ZOOM | RPM_RENDER_IMAGE_SIZE | RPM_VIEW_ANGLE);

pRenderEngine->GetRenderParams(&rp);

 

// Get converted view angle. This value can be reused as long as the image size and field of view are constant.

h_float64 convertedViewAngle;

c3DHelpers.GetConvertedViewAngle(&convertedViewAngle, &rp.RenderImageSize, rp.ViewAngle);

 

// Get volume data parameters.

VOLUME_DATA_PARAMS volumeData;

BCOM_ZEROMEMORY(volumeData);

pVolumeDataContext->GetVolumeDataParams(&volumeData);

 

// Convert 3D volume coordinates to 2D screen space coordinates.

VECTOR3D projPlanePos;

c3DHelpers.Volume2ProjectionPlane(&projPlanePos, rp.RenderType, 0, 0, 0, rp.Zoom, volumeData.Spacing, &rp.Transform, &rp.RenderImageSize, convertedViewAngle); 

 

Converting 3D volume coordinates to 2D screen coordinates is accomplished with the hdrc3DHelpers.volume2ProjectionPlane(). This method takes a coordinate in 3D volume space and converts it to a 2D screen space coordinate. The hdrc3DHelpers.volume2ProjectionPlane() method takes into account the current render mode, zoom, slice spacing, camera transform, and view angle settings. The current render mode, zoom, and camera transform can be accessed in the current RENDER_PARAMS structure, which can be obtained with a call to hdrcRenderEngineContext.getRenderParams() or hdrcRenderQueue.getRenderParams(). The volume slice spacing can be obtained from the VOLUME_DATA_PARAMS structure. The VOLUME_DATA_PARAMS structure can be obtained with a call to hdrcVolumeDataContext.getVolumeDataParams(). The view angle parameter can be calculated with a call to the hdrc3DHelpers.getConvertedViewAngle() method. This method take as input parameters the size of the image being rendered, and the current field of view. These can both be obtained from the current RENDER_PARAMS structure. The hdrc3DHelpers.getConvertedViewAngle() method returns the converted view angle value to be used with the hdrc3DHelpers::volume2ProjectionPlane() method.

 

If the input 3D volume coordinate is outside the current view area, the 2D screen space coordinate may be negative, or larger than the window dimensions. Check the 2D screen space coordinates to ensure that the application does not attempt to draw to an off-screen location.

 

RENDER_PARAMS rp = new RENDER_PARAMS();

 

// Get render params for input parameters.

rp = renderEngine.getRenderParams();

 

// Get converted view angle.

double convertedViewAngle;

convertedViewAngle = hdrc3DHelpers.getConvertedViewAngle(rp.RenderImageSize, rp.ViewAngle);

 

// Get volume data parameters.

VOLUME_DATA_PARAMS volumeData = new VOLUME_DATA_PARAMS();

volumeData = volumeDataContext.getVolumeDataParams();

 

// Convert 3D volume coordinates to 2D screen space coordinates.

VECTOR3D projPlanePos;

projPlanePos = hdrc3DHelpers.volume2ProjectionPlane(rp.RenderType, 0, 0, 0, rp.Zoom, volumeData.Spacing, &rp.Transform, &rp.RenderImageSize, convertedViewAngle); 

 

Converting 2D Screen Coordinates to 3D Volume Coordinates

 

Converting 2D screen coordinates to 3D volume coordinates can be accomplished with the C3DHelpers::ShootRayToPointInCenterOfView() or C3DHelpers::ShootRayToPointLocation() methods. These methods take as input parameters the 2D screen space coordinate of a rendered pixel, and the address of an IRenderParamsReciever derived object that rendered the onscreen image (such as an IRenderEngineContext or IRenderQueue object). The C3DHelpers::ShootRayToPointInCenterOfView() and C3DHelpers::ShootRayToPointLocation() methods return as an output parameter the 3D volume coordinates of the first opaque voxel encountered by that ray.

 

The C3DHelpers::ShootRayToPointInCenterOfView() and C3DHelpers::ShootRayToPointLocation() methods make use of the IRenderEngineContext::ShootRayFast() method to shoot a ray of light into the volume. Other ShootRay() methods are available that give more control over how rays are cast into the volume, and return additional data about the voxels they encounter. See the sections on Transfer Functions and The ShootRay() Methods for additional information on these topics.

 

C3DHelpers c3DHelpers;

 

// Shoot ray into volume from center of view window.

VECTOR3D voxelCoordinate;

c3DHelpers.ShootRayToPointInCenterOfView(&voxelCoordinate, pRenderEngine);

 

// Shoot ray into volume from window coordinates 250, 250.

c3DHelpers.ShootRayToPointLocation(&voxelCoordinate, pRenderEngine, 250, 250);

 

Converting 2D screen coordinates to 3D volume coordinates can be accomplished with the hdrc3DHelpers.ShootRayToPointInCenterOfView() or hdrc3DHelpers.ShootRayToPointLocation() methods. These methods take as input parameters the 2D screen space coordinate of a rendered pixel, and the address of an hdrcIRenderParamsReciever derived object that rendered the onscreen image (such as an hdrcRenderEngineContext or hdrcRenderQueue object). The hdrc3DHelpers::ShootRayToPointInCenterOfView() and hdrc3DHelpers::ShootRayToPointLocation() methods return as an output parameter the 3D volume coordinates of the first opaque voxel encountered by that ray.

 

The hdrc3DHelpers::ShootRayToPointInCenterOfView() and hdrc3DHelpers::ShootRayToPointLocation() methods make use of the IRenderEngineContext.shootRayFast() method to  shoot a ray of light into the volume. Other shootRay() methods are available that give more control over how rays are cast into the volume, and return additional data about the voxels they encounter. See the sections on Transfer Functions and The ShootRay() Methods for additional information on these topics.

 

// Shoot ray into volume from center of view window.

VECTOR3D voxelCoordinate;

voxelCoordinate = hdrc3DHelpers.shootRayToPointInCenterOfView(renderEngine);

 

// Shoot ray into volume from window coordinates 250, 250.

voxelCoordinate = hdrc3DHelpers.shootRayToPointLocation(renderEngine, 250, 250);

 

Converting Between DICOM and HDVR Coordinates

 

The origin for a volume defined in a DICOM series is determined by the position data associated with each slice in the series. The origin for a volume loaded into an HDVR® based application is the center of the volume. This can result in different origins for the DICOM series and the HDVR volume. The C3DHelpers::FoviaRefToDICOM() and C3DHelpers::DICOMRefToFovia() methods can be used to convert between the two coordinate systems. DICOM coordinates can be converted to HDVR coordinates, or vice versa. The C3DHelpers::FoviaRefToDICOM() method takes as input parameters the current RENDER_PARAMS structure, the volume slice spacing, and the origin offset (if any). It returns as an output parameter an hdrcDICOMImageDesc structure that contains the DICOM equivalent coordinate, two vectors describing the relative DICOM series orientation, and the size and spacing of the series. The C3DHelpers::DICOMRefToFovia() method takes an hdrcDICOMImageDesc structure which defines the DICOM coordinate system, as described above. The other fields in the hdrcDICOMImageDesc structure must be filled in as well. The C3DHelpers::DICOMRefToFovia() method also takes the volume slice spacing, and an offset coordinate (if any) to be converted to the HDVR coordinate system. It returns in a RENDER_PARAMS output parameter the converted coordinate in the RENDER_PARAMS::Transform field.

 

 

// Get render parameters.

RENDER_PARAMS rp;

BCOM_ZEROMEMORY(rp);

 

// Get volume data parameters.

VOLUME_DATA_PARAMS volumeData;

BCOM_ZEROMEMORY(volumeData);

pVolumeDataContext->GetVolumeDataParams(&volumeData);

 

// Request transformation for an arbitrary offset.

VECTOR3D volumeOffset;

volumeOffset.x = 100;

volumeOffset.y = 150;

volumeOffset.z = 200;

 

C3DHelpers c3DHelpers;

hdrcDICOMImageDesc dicomImageDesc;

 

// Convert HDVR coordinates to DICOM reference frame.

c3DHelpers.FoviaRefToDICOM(&dicomImageDesc, &rp, volumeData.Spacing, &volumeOffset);

 

// Convert DICOM coordinates to HDVR reference frame.

c3DHelpers.DICOMRefToFovia(&rp, &dicomImageDesc, volumeData.Spacing, &volumeOffset);

 

The origin for a volume defined in a DICOM series is determined by the position data associated with each slice in the series. The origin for a volume loaded into an HDVR® based application is the center of the volume. This can result in different origins for the DICOM series and the HDVR volume. The hdrc3DHelpers.FoviaRefToDICOM() and hdrc3DHelpers.DICOMRefToFovia() methods can be used to convert between the two coordinate systems. DICOM coordinates can be converted to HDVR coordinates, or vice versa. The hdrc3DHelpers.FoviaRefToDICOM() method takes as input parameters the current RENDER_PARAMS structure, the volume slice spacing, and the origin offset (if any). It returns as an output parameter an hdrcDICOMImageDesc structure that contains the DICOM equivalent coordinate, two vectors describing the relative DICOM series orientation, and the size and spacing of the series. The hdrc3DHelpers.DICOMRefToFovia() method takes an hdrcDICOMImageDesc structure which defines the DICOM coordinate system, as described above. The other fields in the hdrcDICOMImageDesc structure must be filled in as well. The hdrc3DHelpers.DICOMRefToFovia() method also takes the volume slice spacing, and an offset coordinate (if any) to be converted to the HDVR coordinate system. It returns in a RENDER_PARAMS output parameter the converted coordinate in the RENDER_PARAMS.Transform field.

 

// Get render parameters.

RENDER_PARAMS rp = new RENDER_PARAMS();

 

// Get volume data parameters.

VOLUME_DATA_PARAMS volumeData = new VOLUME_DATA_PARAMS();

volumeData = volumeDataContext.getVolumeDataParams();

 

// Request transformation for an arbitrary offset.

VECTOR3D volumeOffset = new VECTOR3D(100, 150, 200);

 

hdrcDICOMImageDesc dicomImageDesc = new hdrcDICOMImageDesc();

 

// Convert HDVR coordinates to DICOM reference frame.

dicomImageDesc = hdrc3DHelpers.FoviaRefToDICOM(rp, volumeData.Spacing, volumeOffset);

 

// Convert DICOM coordinates to HDVR reference frame.

rp = hdrc3DHelpers.DICOMRefToFovia(dicomImageDesc, volumeData.Spacing, volumeOffset);