Skip to content

Commit 6c28418

Browse files
committed
cpp test for 15776 / 493 data
1 parent 8d3cf53 commit 6c28418

File tree

1 file changed

+192
-0
lines changed

1 file changed

+192
-0
lines changed

test/testdata/pcl_pc2_15776.cpp

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
/*
2+
* Software License Agreement (BSD License)
3+
*
4+
* Point Cloud Library (PCL) - www.pointclouds.org
5+
* Copyright (c) 2009-2011, Willow Garage, Inc.
6+
*
7+
* All rights reserved.
8+
*
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, are permitted provided that the following conditions
11+
* are met:
12+
*
13+
* * Redistributions of source code must retain the above copyright
14+
* notice, this list of conditions and the following disclaimer.
15+
* * Redistributions in binary form must reproduce the above
16+
* copyright notice, this list of conditions and the following
17+
* disclaimer in the documentation and/or other materials provided
18+
* with the distribution.
19+
* * Neither the name of Willow Garage, Inc. nor the names of its
20+
* contributors may be used to endorse or promote products derived
21+
* from this software without specific prior written permission.
22+
*
23+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33+
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34+
* POSSIBILITY OF SUCH DAMAGE.
35+
*
36+
* $Id: example_OrganizedPointCloud.cpp 4258 2012-02-05 15:06:20Z daviddoria $
37+
*
38+
*/
39+
40+
// STL
41+
#include <iostream>
42+
#include <fstream>
43+
#include <assert.h>
44+
45+
// PCL
46+
#include <pcl/point_cloud.h>
47+
#include <pcl/point_types.h>
48+
49+
#include <pcl/conversions.h>
50+
51+
52+
char* readdata (int* length) {
53+
54+
std::ifstream is ("_PCLPointCloud2_15776.dat", std::ifstream::binary);
55+
// int length = 0
56+
if (is) {
57+
// get length of file:
58+
is.seekg (0, is.end);
59+
*length = is.tellg();
60+
is.seekg (0, is.beg);
61+
62+
char * buffer = new char [*length];
63+
64+
std::cout << "Reading " << *length << " characters... ";
65+
// read data as a block:
66+
is.read (buffer,*length);
67+
68+
if (is)
69+
std::cout << "all characters read successfully." << std::endl;
70+
else
71+
std::cout << "error: only " << is.gcount() << " could be read" << std::endl;
72+
is.close();
73+
74+
// ...buffer contains the entire file...
75+
76+
// delete[] buffer;
77+
return buffer;
78+
}
79+
char* dummy;
80+
return dummy;
81+
}
82+
83+
int
84+
main ()
85+
{
86+
// load binary data
87+
int length = 0;
88+
89+
// load test data from file, and check its length
90+
char* buffer = readdata(&length);
91+
std::cout << std::endl << "length is " << length << std::endl;
92+
assert(length == 15776);
93+
94+
// hand generate PCLPointCloud2
95+
pcl::PCLPointCloud2 pc2;
96+
97+
// load data first
98+
for (int i = 0; i < length; i++) {
99+
pc2.data.push_back(buffer[i]);
100+
}
101+
102+
unsigned char* buffer_ = reinterpret_cast<unsigned char*>(buffer);
103+
// sizeof arr
104+
for (int i = 0; i < 5; i++) {
105+
printf(" %02x", buffer_[i]);
106+
printf("&%02x", pc2.data[i]);
107+
}
108+
std::cout << " ... ";
109+
for (int i = length-6; i < length ; i++) {
110+
printf(" %02x", buffer_[i]);
111+
printf("&%02x", pc2.data[i]);
112+
}
113+
114+
std::cout << std::endl << "pc2.data size is " << pc2.data.size() << std::endl;
115+
116+
117+
pcl::PCLHeader header;
118+
header.seq = 92147;
119+
header.frame_id = "velodyne";
120+
header.stamp = 1603389805080336;
121+
122+
pcl::PCLPointField pf_x;
123+
pf_x.name = "x";
124+
pf_x.offset = 0x00000000;
125+
pf_x.datatype = pcl::PCLPointField::FLOAT32;
126+
pf_x.count = 1;
127+
pc2.fields.push_back(pf_x);
128+
129+
pcl::PCLPointField pf_y;
130+
pf_y.name = "y";
131+
pf_y.offset = 0x00000004;
132+
pf_y.datatype = pcl::PCLPointField::FLOAT32;
133+
pf_y.count = 1;
134+
pc2.fields.push_back(pf_y);
135+
136+
pcl::PCLPointField pf_z;
137+
pf_z.name = "z";
138+
pf_z.offset = 0x00000008;
139+
pf_z.datatype = pcl::PCLPointField::FLOAT32;
140+
pf_z.count = 1;
141+
pc2.fields.push_back(pf_z);
142+
143+
pcl::PCLPointField pf_i;
144+
pf_i.name = "intensity";
145+
pf_i.offset = 0x00000010;
146+
pf_i.datatype = pcl::PCLPointField::FLOAT32;
147+
pf_i.count = 1;
148+
pc2.fields.push_back(pf_i);
149+
150+
pc2.header = header;
151+
pc2.height = 1;
152+
pc2.width = 493;
153+
pc2.point_step = 32;
154+
pc2.row_step = 15776;
155+
pc2.is_bigendian = false;
156+
pc2.is_dense = 1;
157+
158+
std::cout << "pc2 with header" << std::endl;
159+
160+
// =============================================================================
161+
// Setup the cloud
162+
using PointType = pcl::PointXYZ;
163+
using CloudType = pcl::PointCloud<PointType>;
164+
CloudType::Ptr cloud (new CloudType);
165+
166+
// do the conversion
167+
pcl::fromPCLPointCloud2(pc2, *cloud);
168+
169+
std::cout << "sizeof(PointT) = " << sizeof(PointType) << std::endl;
170+
171+
// // Make the cloud a 10x10 grid
172+
// cloud->height = 10;
173+
// cloud->width = 10;
174+
// cloud->is_dense = true;
175+
// cloud->resize(cloud->height * cloud->width);
176+
177+
// Output the (0,0) point
178+
std::cout << (*cloud)(0,0) << std::endl;
179+
std::cout << cloud->isOrganized() << std::endl;
180+
for (int i=0; i< 10; i++)
181+
std::cout << cloud->points[i] << std::endl;
182+
// // Set the (0,0) point
183+
// PointType p; p.x = 1; p.y = 2; p.z = 3;
184+
// (*cloud)(0,0) = p;
185+
186+
// // Confirm that the point was set
187+
// std::cout << (*cloud)(0,0) << std::endl;
188+
189+
delete[] buffer;
190+
191+
return (0);
192+
}

0 commit comments

Comments
 (0)