写一个gocator的c++程序,能够获取点云图片
时间: 2023-04-04 14:02:30 浏览: 90
你好,我可以回答这个问题。以下是一个获取点云图片的gocator的c程序示例:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <GoSdk/GoSdk.h>
void onData(void* ctx, const GoDataSet* dataSet)
{
unsigned int i;
for (i = 0; i < GoDataSet_Count(dataSet); ++i)
{
GoDataMsg dataObj = GoDataSet_At(dataSet, i);
switch (GoDataMsg_Type(dataObj))
{
case GO_DATA_MESSAGE_TYPE_STAMP:
{
GoStampMsg stampMsg = dataObj;
printf("Frame Index: %llu\n", stampMsg->frameIndex);
printf("Time Stamp: %llu\n", stampMsg->timestamp);
}
break;
case GO_DATA_MESSAGE_TYPE_SURFACE:
{
GoSurfaceMsg surfaceMsg = dataObj;
printf("Surface data received:\n");
printf(" Width: %lu\n", GoSurfaceMsg_Width(surfaceMsg));
printf(" Height: %lu\n", GoSurfaceMsg_Height(surfaceMsg));
printf(" X resolution: %.3f um\n", (float) GoSurfaceMsg_XResolution(surfaceMsg) / 1000.0);
printf(" Y resolution: %.3f um\n", (float) GoSurfaceMsg_YResolution(surfaceMsg) / 1000.0);
printf(" Z resolution: %.3f nm\n", (float) GoSurfaceMsg_ZResolution(surfaceMsg));
printf(" X offset: %.3f mm\n", (float) GoSurfaceMsg_XOffset(surfaceMsg) / 1000.0);
printf(" Y offset: %.3f mm\n", (float) GoSurfaceMsg_YOffset(surfaceMsg) / 1000.0);
printf(" Z offset: %.3f mm\n", (float) GoSurfaceMsg_ZOffset(surfaceMsg) / 1000.0);
printf(" Data type: %u\n", GoSurfaceMsg_Type(surfaceMsg));
printf(" Data size: %lu\n", GoSurfaceMsg_BufferSize(surfaceMsg));
}
break;
default:
{
printf("Unhandled data message received.\n");
}
break;
}
}
}
int main(int argc, char** argv)
{
kStatus status;
GoSystem system;
GoSensor sensor;
GoDataSet dataSet;
unsigned int i;
GoSetup setup;
GoOutput output;
GoEthernet ethernet;
char ipAddress[256];
// Initialize the GoSdk library.
status = GoSdk_Initialize();
if (status != kOK)
{
printf("Error: GoSdk_Initialize:%d\n", status);
return EXIT_FAILURE;
}
// Create a GoSystem object.
status = GoSystem_Construct(&system, kNULL);
if (status != kOK)
{
printf("Error: GoSystem_Construct:%d\n", status);
GoSdk_Uninitialize();
return EXIT_FAILURE;
}
// Find the first sensor.
status = GoSystem_FindSensorByIpAddress(system, "192.168.1.10", &sensor);
if (status != kOK)
{
printf("Error: GoSystem_FindSensorByIpAddress:%d\n", status);
GoSystem_Destroy(system);
GoSdk_Uninitialize();
return EXIT_FAILURE;
}
// Create a setup object.
status = GoSetup_Construct(&setup, kNULL);
if (status != kOK)
{
printf("Error: GoSetup_Construct:%d\n", status);
GoSensor_Destroy(sensor);
GoSystem_Destroy(system);
GoSdk_Uninitialize();
return EXIT_FAILURE;
}
// Load the setup from the sensor.
status = GoSensor_LoadConfig(sensor, setup);
if (status != kOK)
{
printf("Error: GoSensor_LoadConfig:%d\n", status);
GoSetup_Destroy(setup);
GoSensor_Destroy(sensor);
GoSystem_Destroy(system);
GoSdk_Uninitialize();
return EXIT_FAILURE;
}
// Enable the output.
output = GoSetup_Output(setup);
ethernet = GoOutput_Ethernet(output);
GoEthernet_Address(ethernet, ipAddress, sizeof(ipAddress));
printf("Output enabled on %s\n", ipAddress);
// Start the sensor.
status = GoSystem_Start(system);
if (status != kOK)
{
printf("Error: GoSystem_Start:%d\n", status);
GoSetup_Destroy(setup);
GoSensor_Destroy(sensor);
GoSystem_Destroy(system);
GoSdk_Uninitialize();
return EXIT_FAILURE;
}
// Grab a frame of data.
status = GoSystem_ReadData(system, &dataSet);
if (status != kOK)
{
printf("Error: GoSystem_ReadData:%d\n", status);
GoSystem_Stop(system);
GoSetup_Destroy(setup);
GoSensor_Destroy(sensor);
GoSystem_Destroy(system);
GoSdk_Uninitialize();
return EXIT_FAILURE;
}
// Process the data.
onData(kNULL, &dataSet);
// Destroy the data set.
GoDestroy(dataSet);
// Stop the sensor.
status = GoSystem_Stop(system);
if (status != kOK)
{
printf("Error: GoSystem_Stop:%d\n", status);
GoSetup_Destroy(setup);
GoSensor_Destroy(sensor);
GoSystem_Destroy(system);
GoSdk_Uninitialize();
return EXIT_FAILURE;
}
// Destroy the setup object.
GoDestroy(setup);
// Destroy the sensor object.
GoDestroy(sensor);
// Destroy the system object.
GoDestroy(system);
// Uninitialize the GoSdk library.
GoSdk_Uninitialize();
return EXIT_SUCCESS;
}