1 #define _SCL_SECURE_NO_WARNINGS 2 #define _CRT_SECURE_NO_WARNINGS 3 4 #include <iostream> 5 //#include <atlsafe.h> 6 //#include <windows.h> 7 //#include <cassert> 8 #include <pcl/point_cloud.h> 9 #include <pcl/io/pcd_io.h> 10 #include <pcl/visualization/pcl_visualizer.h> 11 12 using namespace std; 13 typedef pcl::PointXYZRGBA PointT; 14 typedef pcl::PointCloud<PointT> PointCloudT; 15 16 #ifdef _WIN64 17 // Yes - type is 'win32' even on WIN64! 18 #pragma comment(linker, ""/manifestdependency:type='win32' name='FARO.LS' version='1.1.701.2' processorArchitecture='amd64' publicKeyToken='1d23f5635ba800ab'"") 19 #else 20 #pragma comment(linker, ""/manifestdependency:type='win32' name='FARO.LS' version='1.1.701.2' processorArchitecture='amd64' publicKeyToken='1d23f5635ba800ab'"") 21 #endif 22 23 // These imports just defines the types - they don't determine which DLLs are actually loaded! 24 // You can choose whatever version you have installed on your system - as long as the interface is compatible 25 #import "C:WindowsWinSxSamd64_faro.ls_1d23f5635ba800ab_1.1.701.2_none_3592adf9356a0308iQopen.dll" no_namespace 26 27 //... 28 29 int main() 30 { 31 CoInitialize(NULL); //应用程序调用com库函数(除CoGetMalloc和内存分配函数)之前必须初始化com库 32 // FARO LS Licensing 33 // Please note: The cryptic key is only a part of the complete license 34 // string you need to unlock the interface. Please 35 // follow the instructions in the 2nd line below 36 37 BSTR licenseCode = L"FARO Open Runtime License " 38 //#include "../FAROOpenLicense" // Delete this line, uncomment the following line, and enter your own license key here: 39 L"Key:39CELNPKTCTXXJ7TN3ZYSPVPL " 40 L" " 41 L"The software is the registered property of FARO Scanner Production GmbH, Stuttgart, Germany. " 42 L"All rights reserved. " 43 L"This software may only be used with written permission of FARO Scanner Production GmbH, Stuttgart, Germany."; 44 45 IiQLicensedInterfaceIfPtr liPtr(__uuidof(iQLibIf)); 46 liPtr->License = licenseCode; 47 IiQLibIfPtr libRef = static_cast<IiQLibIfPtr>(liPtr); 48 if (libRef->load("C:\Users\18148\Desktop\Scan_az001.fls\Scan_az001.fls") != 0) //读取文件的全路径 切记 49 { 50 std::cout << "load ScanData errer !!!" << std::endl; 51 libRef = NULL; 52 liPtr = NULL; 53 return -1; 54 } 55 56 libRef->scanReflectionMode = 2; //黑白灰度展示图像 57 cout << libRef->scanReflectionMode << endl; 58 //libRef->scanReflectionMode = 1; //默认为1 可以为0 1 2三个模式。 59 60 int ret = libRef->setAttribute("#app/ScanLoadColor", "2"); //设置为彩色 Load grey information instead of color 61 cout << "setAttribute" << ret << endl; 62 63 //if (int ret = libRef->saveAs("C:\Users\18148\Desktop\img\ddb123.fws") != 0) //可以存储为 fls,fws 64 //{ 65 // std::cout << "saveAs ScanData errer !!!" << std::endl; 66 // return -1; 67 //} 68 //ret = libRef->extractStream("C:\Users\18148\Desktop\Scan_az001.fls\Scan_az001.fls", "ScanDataStream0", "C:\Users\18148\Desktop\img.fls"); 69 70 double x, y, z; 71 double rx, ry, rz, angle; 72 libRef->getScanPosition(0, &x, &y, &z); 73 libRef->getScanOrientation(0, &rx, &ry, &rz, &angle); 74 int numRows = libRef->getScanNumRows(0); 75 int numCOls = libRef->getScanNumCols(0); 76 77 std::cout << "numRows::" << numRows << std::endl; 78 std::cout << "numCOls::" << numCOls << std::endl; 79 std::cout << x << "," << y << "," << z << std::endl; 80 std::cout << rx << "," << ry << "," << rz << "," << angle << std::endl; 81 82 PointCloudT::Ptr cloud_pointsPtr(new PointCloudT()); 83 // Access all points points by point 84 for (int col = 0; col < numCOls; col++) 85 { 86 for (int row = 0; row<numRows; row++) 87 { 88 double x, y, z; 89 int refl; 90 int result = libRef->getScanPoint(0, row, col, &x, &y, &z, &refl); 91 92 //Use getXYZScanPoints or getXYZScanPoints2 instead to read multiple scan points in a single call. For example, you can read the scan points column by column with these two methods. 93 PointT points; 94 points.x = x; 95 points.y = y; 96 points.z = z; 97 //int rgb = ((int)r) << 16 | ((int)g) << 8 | ((int)b); 98 points.a = 255; 99 points.r = (refl >> 16) & 0x0000ff; //uint8_t r = (rgb >> 16) & 0x0000ff; 100 points.g = (refl >> 8) & 0x0000ff; 101 points.b = (refl)& 0x0000ff; 102 points.rgba = points.a << 24 | points.r << 16 | points.g << 8 | points.b; 103 cloud_pointsPtr->points.push_back(points); 104 105 /* double **array2D = new double *[numRows]; //二维数组分配内存 106 for (int i = 0; i<numRows; ++i) 107 { 108 array2D[i] = new double[3]; 109 } 110 double *pos = *array2D; 111 */ 112 //double *pos = new double[3 * numRows]; //利用一维数组 113 //int *refl = new int[numRows]; 114 //int result = libRef->getXYZScanPoints(0, row, col, numRows, pos, refl); 115 116 ////std::cout << x<<","<<y<<","<<z<< std::endl; 117 118 //delete[] pos; 119 //delete[] refl; 120 //pos = NULL; refl = NULL; 121 } 122 } 123 124 // -------------------------------------------- 125 // -----Open 3D viewer and add point cloud----- 126 // -------------------------------------------- 127 boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("3D Viewer")); 128 viewer->setBackgroundColor(0, 0, 0); 129 pcl::visualization::PointCloudColorHandlerRGBField<PointT> rgb(cloud_pointsPtr); 130 //pcl::visualization::PointCloudColorHandlerCustom<PointT> red(cloud_pointsPtr, 0, 0, 255); 131 viewer->addPointCloud<PointT>(cloud_pointsPtr, "sample cloud"); 132 viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "sample cloud"); 133 viewer->addCoordinateSystem(1.0); 134 viewer->initCameraParameters(); 135 136 // Access all points column per column in polar coordinates 137 //double* positions = new double[numRows*3]; 138 //int* reflections = new int[numRows]; 139 //for (int col = 0; col<numCOls; col++) 140 //{ 141 // int result = libRef->getPolarScanPoints(0, 0, col, numRows, positions, reflections); 142 // for (int row=0 ; row<numRows ; row++) 143 // { 144 // double r, phi, theta; 145 // int refl; 146 // r = positions[3*row+0]; 147 // phi = positions[3*row + 1]; 148 // theta = positions[3*row+2]; 149 // refl = reflections[row]; // ... 150 // } 151 //} 152 //delete[] positions; delete[] reflections; 153 154 libRef = NULL; liPtr = NULL; 155 CoUninitialize(); 156 //-------------------- 157 // -----Main loop----- 158 //-------------------- 159 160 while (!viewer->wasStopped()) 161 { 162 viewer->spinOnce(100); 163 boost::this_thread::sleep(boost::posix_time::microseconds(100000)); 164 } 165 system("pause"); 166 return 0; 167 }