Raytrix Light Field SDK  4.0
Logo
Using the Raytrix Light Field API

Contents

Initialize the Raytrix Light Field API

Independent of the programming language you are using you have to reference the Raytrix Light Field API in your project.

To start working with the Raytrix Light Field API, you have to include the Raytrix API header or reference the Raytrix API assembly.

// The Raytrix Light Field API
#include "Rx.ApiLF\Rx.ApiLF.h"
using namespace Rx::ApiLF;
using namespace Rx;
// The Raytrix Light Field API
#include "Rx.ApiLF\Rx.ApiLF.h"
using namespace Rx::Net::ApiLF;
using namespace Rx;
// The Raytrix Light Field API is included as an assambly into the project
using Rx.Net.ApiLF;
using Rx;

The namespaces allow you to use all API related code without writing the whole namespace each time. After the API header is included you must start with initializing the Raytrix Light Field API.

The function Rx::ApiLF::RxInit initializes the Raytrix Light Field API.

This function has to be called before any other API function, with the exception of

If you do not specify any parameters the CUDA device is initialized implicitly. All the computational functions are implemented on the CUDA device.

The function Rx::ApiLF::RxCudaSelectDevice allows you to select a CUDA device.

If several CUDA devices are present, you have the possibility to select the CUDA device width the highest graphical processing power. In the most cases it is sufficient to use the function without any parameter settings, which will select the first device that has enough computational power.

// Initialize Raytrix Library
// Automatic CUDA device selection if no device ID or a negative device ID is given.
// Initialize Raytrix Library
// Automatic CUDA device selection if no device ID or a negative device ID is given.
// Initialize Raytrix Library
// Automatic CUDA device selection if no device ID or a negative device ID is given.
See also
Full Example

Binding the Source

The Raytrix Light Field SDK allows you to work with three different image sources (Programming with the Raytrix Light Field API). In this example we will demonstrate the usage of a ray image source.

CRxString sxFile = "..\\ExampleImages\\Demo_01.ray";
// Load a ray image and
unsigned uImgID = RxRayLoad(sxFile);
// Bind the loaded ray image. This copies the ray image to the CUDA device.
RxRayBind(uImgID);
String^ sFile = gcnew String("..\\ExampleImages\\Demo_01.ray");
// Load a ray image and
unsigned uImgID = RxRayLoad(sFile);
// Bind the loaded ray image. This copies the ray image to the CUDA device.
RxRayBind(uImgID);
string sFile = "..\\ExampleImages\\Demo_01.ray";
// Load a ray image and
uint uImgID = RxRayLoad(sFile);
// Bind the loaded ray image. This copies the ray image to the CUDA device.
RxRayBind(uImgID);
Attention
After a ray image is bound to the Raytrix Light Field API you have to preprocess the image for all further image processing.
See also
Preprocess the Bound Image
Full Example

Preprocess the Bound Image

The ray image that is bound is a raw Light Field image. Before this ray image can be used by the actual image processing algorithms, it has to be preprocessed.

The function Rx::ApiLF::RxPreProcess prepares the raw image for further image processing

The number of preprocessing tasks that are performed depends on the corresponding API parameters. You can activate or deactivate:

Attention
if the image has a bayer pattern the debayer algorithm is performed by the preprocess step.

Each preprocessing task can be adjusted by further API paramters:

// Pre-process raw Light Field image before calling any processing functions
// Pre-process raw Light Field image before calling any processing functions
// Pre-process raw Light Field image before calling any processing functions

After the preprocessing step is executed the image Rx::ApiLF::EImg::Processed_Normalized is created on the CUDA device and further image processing is possible.

See also
Image Processing with the Raytrix Light Field API
Raytrix Light Field API Computation - Detailed
Full Example

Image Processing with the Raytrix Light Field API

Attention
After you have preprocessed the raw image you can start your actual image processing.

The Raytrix Light Field API offers a lot of image processing algorithms that are implemented on the CUDA device. Each processing function creates an image on the device. The image that is created can depend on the parameter Rx::ApiLF::EPar::Proj_CurrentTargetView that can be set to one of the values in Rx::Projection::ESpace. The following image and the corresponding table illustrate the relation between the computational functions and the created images:

RaytrixIO_medium.png
Ratrix Light Field API - Images
Function Requirement Rx::ApiLF::EImg
Rx::ApiLF::RxRefocusBasic Rx::ApiLF::EImgID::RefocusBasic
Rx::ApiLF::RxTotalFocus Rx::LF::ESpace::Virtual Rx::ApiLF::EImgID::TotalFocus_View_Virtual
Rx::ApiLF::RxTotalFocus Rx::LF::ESpace::ViewCamera Rx::ApiLF::EImgID::TotalFocus_View_Object_Pinhole
Rx::ApiLF::RxMultiview Rx::ApiLF::EImgID::Multiview
Rx::ApiLF::RxDepthRay Rx::ApiLF::EImgID::DepthRay
Rx::ApiLF::RxDepthMap Rx::LF::ESpace::Virtual Rx::ApiLF::EImgID::DepthMap_View_Virtual
Rx::ApiLF::RxDepthMap Rx::LF::ESpace::ViewCamera Rx::ApiLF::EImgID::DepthMap_View_Object_Pinhole
Rx::ApiLF::RxDepth3D Rx::ApiLF::EImgID::DepthMap_View_Object_Pinhole must existRx::ApiLF::EImgID::Depth3D
Rx::ApiLF::RxDepthColorCode Rx::LF::ESpace::Virtual Rx::ApiLF::EImgID::DepthMapColored_View_Virtual
Rx::ApiLF::RxDepthColorCode Rx::LF::ESpace::ViewCamera Rx::ApiLF::EImgID::DepthMapColored_View_Object_Pinhole

Further computational functions are:

Every processing function can be adjusted with a wide range of parameters Light Field Parameter .

The following simple example demonstrates how you can refocus your image in the middle of the near and far plane.

// Focus ray image to plane at depth 0.5
// Get focused image from CUDA device
CRxImage xImage;
// Now work with the image.
// ...
// Focus ray image to plane at depth 0.5
// Get focused image from CUDA device
Rx::Net::Image^ xImage = gcnew Rx::Net::Image();
// Now work with the image.
// ...
// Focus ray image to plane at depth 0.5
RxSetPar(EPar.Focus_RelativeFocusPlane, 0.5);
// Get focused image from CUDA device
public Image Image;
RxGetImage(EImgID.RefocusBasic, ref Image);
// Now work with the image.
// ...

The last section of this page will show you how to finalize the Raytrix Light Field API

See also
Finalize the Raytrix Light Field API
Full Example

Finalize the Raytrix Light Field API

After you have finished your work with the Raytrix Light Field API you want to make sure that all memory is freed on host and on CUDA device. Furthermore you want to close all cameras properly:

// Close Raytrix API, free all memory on host and CUDA device
// and close all open cameras.
// Close Raytrix API, free all memory on host and CUDA device
// and close all open cameras.
// Close Raytrix API, free all memory on host and CUDA device
// and close all open cameras.
See also
Full Example

Full Example

// The Raytrix exception class base type
#include "Rx.Interop.Runtime30/CIException.h"
// The Raytrix Light Field API
#include "Rx.ApiLF\Rx.ApiLF.h"
using namespace Rx::ApiLF;
using namespace Rx;
int main(int argc, char* argv[])
{
unsigned uImgID = 0;
CRxImage xImage;
CRxString sxFile;
try
{
// Initialize Raytrix Library
RxInit(true, 0);
// Automatic CUDA device selection if no device ID or a negative device ID is given.
// Construct path to ray image
sxFile = "..\\ExampleImages\\Demo_01.ray";
// Load a ray image
RxRayLoad(uImgID, sxFile);
// Bind the loaded ray image. This copies the ray image to the CUDA device.
RxRayBind(uImgID);
// Pre-process raw Light Field image before calling any processing functions
// Focus ray image to plane at depth 0.5
// Get focused image from CUDA device
// Now work with the image.
// ...
}
{
return -1;
}
// Close Raytrix API, free all memory on host and CUDA device
// and close all open cameras.
return 0;
}
// The Raytrix exception class base type
#include "Rx.Interop.Runtime30/CIException.h"
// The Raytrix Light Field API
#include "Rx.ApiLF\Rx.ApiLF.h"
using namespace Rx::Net::ApiLF;
using namespace Rx;
int main(int argc, char* argv[])
{
unsigned uImgID = 0;
Rx::Net::Image^ xImage = gcnew Rx::Net::Image();
String^ sFile = gcnew String();
try
{
// Initialize Raytrix Library
RxInit(true, 0);
// Automatic CUDA device selection if no device ID or a negative device ID is given.
// Construct path to ray image
sxFile = "..\\ExampleImages\\Demo_01.ray";
// Load a ray image
RxRayLoad(uImgID, sxFile);
// Bind the loaded ray image. This copies the ray image to the CUDA device.
RxRayBind(uImgID);
// Pre-process raw Light Field image before calling any processing functions
// Focus ray image to plane at depth 0.5
// Get focused image from CUDA device
// Now work with the image.
// ...
}
{
return -1;
}
// Close Raytrix API, free all memory on host and CUDA device
// and close all open cameras.
return 0;
}
using Rx.Net.ApiLF;
using Rx;
static void Main(string[] args)
{
uint uImgID = 0;
public Image Image;
string sFile;
try
{
// Initialize Raytrix Library
RxInit(true, 0);
// Automatic CUDA device selection if no device ID or a negative device ID is given.
// Construct path to ray image
sFile = "..\\ExampleImages\\Demo_01.ray";
// Load a ray image
RxRayLoad(uImgID, sxFile);
// Bind the loaded ray image. This copies the ray image to the CUDA device.
RxRayBind(uImgID);
// Pre-process raw Light Field image before calling any processing functions
// Focus ray image to plane at depth 0.5
RxSetPar(EPar.Focus_RelativeFocusPlane, 0.5);
// Get focused image from CUDA device
RxGetImage(EImgID.RefocusBasic, ref Image);
// Now work with the image.
// ...
}
{
// Handle Exception
}
// Close Raytrix API, free all memory on host and CUDA device
// and close all open cameras.
}