/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2016 Raytrix GmbH. All rights reserved.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/************************************************************************/
/* This example demonstrates: */
/* - Loading of an image with the MGPU runtime */
/* - Loading and applying of a parameter set */
/* - Calculating and displaying Total Focus image */
/* - Loading and applying of another parameter set */
/* - Calculating and displaying color depth map */
/************************************************************************/
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// namespace: Example.LFR.CS.BasicD
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
namespace Example.LFR.CS.BasicD
{
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///
/// Multiple Cameras one GPU synchronous.
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class Example
{
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///
/// Runs this example.
///
///
/// The return code.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public int Run()
{
System.Console.WriteLine("Initializing visualization...");
// Create the visualization
CLUViz.Net.Tool.Init();
int iHandle1 = CLUViz.Net.Tool.CreateViewImage(0, 0, 1000, 800, "");
int iHandle2 = CLUViz.Net.Tool.CreateViewImage(1000, 0, 1000, 800, "");
System.Console.WriteLine("Initializing Runtime and Cuda...");
/************************************************************************/
/* Authenticate LFR */
/************************************************************************/
Rx.LFR.Net.LightFieldRuntime.Authenticate();
// Initialize the calibration manager.
Rx.LFR.Net.CalibrationManager.Initialize();
// Enumerate all CUDA devices at the beginning
Rx.LFR.Net.Cuda.EnumerateCudaDevices();
// Initialize the Cuda compute instance
Rx.LFR.Net.CudaCompute xCudaCompute = new Rx.LFR.Net.CudaCompute();
xCudaCompute.SetCudaDevice(Rx.LFR.Net.Cuda.GetDevice(0));
xCudaCompute.GetParams().SetValue(Rx.LFR.Net.Params.ECudaCompute.PreProc_DataType, (uint) Rx.InteropNet.Runtime28.EDataType.UByte);
// Read all paths
System.Console.WriteLine("Please enter image path: ");
System.String xImagePath = System.Console.ReadLine();
if (!System.IO.File.Exists(xImagePath))
{
System.Console.WriteLine("File does not exist!");
return -1;
}
System.Console.WriteLine("Please enter total focus image settings path: ");
System.String xTotalFocusSettingsPath = System.Console.ReadLine();
if (!System.IO.File.Exists(xTotalFocusSettingsPath))
{
System.Console.WriteLine("File does not exist!");
return -1;
}
System.Console.WriteLine("Please enter depth settings path: ");
System.String xDepthSettingsPath = System.Console.ReadLine();
if (!System.IO.File.Exists(xDepthSettingsPath))
{
System.Console.WriteLine("File does not exist!");
return -1;
}
System.Console.WriteLine("Processing Image...");
/************************************************************************/
/* Process Image */
/************************************************************************/
System.Console.WriteLine(" - Reading image source...");
Rx.LFR.Net.RayImage xImage = new Rx.LFR.Net.RayImage();
Rx.LFR.Net.RayFileReader.Read(xImagePath, xImage);
xCudaCompute.ApplyCalibration(xImage.GetCalibration(), true);
System.Console.WriteLine(" - Uploading raw image to cuda device...");
xCudaCompute.UploadRawImage(xImage);
System.Console.WriteLine(" - Loading and applying total focus parameter settings...");
xCudaCompute.GetParams().ImportFromFile(xTotalFocusSettingsPath);
System.Console.WriteLine(" - Computing total focus...");
// Calculate total focus image
xCudaCompute.Compute_PreProcess();
xCudaCompute.Compute_RefocusBasic();
xCudaCompute.Compute_DepthRay();
xCudaCompute.Compute_DepthMap(Rx.LFR.Net.ESpace.View_Object_Pinhole);
xCudaCompute.Compute_TotalFocus(Rx.LFR.Net.ESpace.View_Object_Pinhole);
// Get the image access interface. This interface allows:
// * Download CUDA image into host memory
// * Upload a host image to CUDA to overwrite a certain CUDA image
// * Access to CUDA device pointer to do own CUDA image processing
Rx.LFR.Net.ICudaDataImages xImages = (xCudaCompute.GetInterface(Rx.LFR.Net.Interfaces.ECudaCompute.Images)) as Rx.LFR.Net.ICudaDataImages;
System.Console.WriteLine(" - Downloading total focus image...");
Rx.Net.Image xTotalFocusImage = new Rx.Net.Image();
xImages.Download(Rx.LFR.Net.EImage.TotalFocus_View_Object_Pinhole, xTotalFocusImage);
CLUViz.Net.Tool.ViewSetImage(iHandle1, xTotalFocusImage);
System.Console.WriteLine(" - Loading and applying depth parameter settings...");
xCudaCompute.GetParams().ImportFromFile(xDepthSettingsPath);
System.Console.WriteLine(" - Computing depth...");
// Calculate colored depth map image
xCudaCompute.Compute_PreProcess();
xCudaCompute.Compute_RefocusBasic();
xCudaCompute.Compute_DepthRay();
xCudaCompute.Compute_DepthMap(Rx.LFR.Net.ESpace.View_Object_Pinhole);
xCudaCompute.Compute_Depth3D();
xCudaCompute.Compute_DepthColorCode(Rx.LFR.Net.ESpace.View_Object_Pinhole);
System.Console.WriteLine(" - Downloading depth image...");
Rx.Net.Image xColoredDepthMapImage = new Rx.Net.Image();
xImages.Download(Rx.LFR.Net.EImage.DepthMapColored_View_Object_Pinhole, xColoredDepthMapImage);
CLUViz.Net.Tool.ViewSetImage(iHandle2, xColoredDepthMapImage);
//Write PLY
/************************************************************************/
/* Wait */
/************************************************************************/
// Press any key to stop the capturing
System.Console.WriteLine("Press any key to exit.");
Console.ReadKey();
return 0;
}
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///
/// A program.
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static class Program
{
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///
/// The main entry point for the application.
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static void Main()
{
new Example().Run();
}
}
}