43 #if __BYTE_ORDER == __BIG_ENDIAN 45 x = (x & 0x00000000FFFFFFFF) << 32 | (x & 0xFFFFFFFF00000000) >> 32;
46 x = (x & 0x0000FFFF0000FFFF) << 16 | (x & 0xFFFF0000FFFF0000) >> 16;
47 x = (x & 0x00FF00FF00FF00FF) << 8 | (x & 0xFF00FF00FF00FF00) >> 8;
51 #define __Swap2Bytes(val) ( (((val) >> 8) & 0x00FF) | (((val) << 8) & 0xFF00) ) 52 #define __Swap2BytesD(val) (val>7490?0:( (((val) >> 8) & 0x00FF) | (((val) << 8) & 0xFF00) )) 53 #define __Swap4Bytes(dword) ( ((dword>>24)&0x000000FF) | ((dword>>8)&0x0000FF00) | ((dword<<8)&0x00FF0000) | ((dword<<24)&0xFF000000) ) 54 #define __Swap8Bytes(val) (swapLong(val)) 56 #define __Swap2Bytes(val) (val) 57 #define __Swap2BytesD(val) (val>7490?0:val) 58 #define __Swap4Bytes(dword) (dword) 59 #define __Swap8Bytes(dword) (dword) 70 double *cam2worldMatrix=NULL,
71 double fx=146.5,
double fy=146.5,
double cx=84.4,
double cy=71.2,
72 double k1=0.326442,
double k2=0.219623,
74 width(width), height(height),
81 memcpy(this->cam2worldMatrix, cam2worldMatrix,
sizeof(this->cam2worldMatrix));
108 const uint32_t pkglength = ntohl( *(uint32_t*)(data+4) );
115 if(size<11)
return false;
117 const uint32_t magicword = ntohl( *(uint32_t*)(data+0) );
120 return magicword != 0x02020202 || size>=actual_size(data, size);
124 bool read(
const char *data,
const size_t size) {
126 const uint32_t magicword = ntohl( *(uint32_t*)(data+0) );
127 const uint32_t pkglength = ntohl( *(uint32_t*)(data+4) );
128 const uint16_t protocolVersion = ntohs( *(uint16_t*)(data+8) );
129 const uint8_t packetType = *(uint8_t*)(data+10);
135 if( magicword != 0x02020202 || protocolVersion != 1 || packetType != 98 )
140 const uint16_t
id = ntohs( *(uint16_t*)(data+11) );
141 const uint16_t numSegments = ntohs( *(uint16_t*)(data+13) );
146 uint32_t offset[numSegments];
147 uint32_t changedCounter[numSegments];
148 for(
size_t i=0; i<(size_t)numSegments; i++) {
149 offset[i] = 11 + ntohl( *(uint32_t*)(data+(i*8+15)) );
150 changedCounter[i] = ntohl( *(uint32_t*)(data+(i*8+19)) );
154 std::string xmlSegment(data+offset[0], offset[1]-offset[0]);
157 parseXML(xmlSegment);
174 distance_ = cv::Mat(cameraParams_.
height, cameraParams_.
width, CV_16UC1);
175 intensity_ = cv::Mat(cameraParams_.
height, cameraParams_.
width, CV_16UC1);
176 confidence_ = cv::Mat(cameraParams_.
height, cameraParams_.
width, CV_16UC1);
178 getData(data+offset[1], size-offset[1]);
186 numBytesPerConfidenceValue_ = numBytesPerIntensityValue_ = numBytesPerConfidenceValue_ = -1;
188 boost::property_tree::ptree pt;
189 std::istringstream ss(xmlString);
191 boost::property_tree::xml_parser::read_xml(ss, pt);
193 ROS_ERROR(
"failed to parse response (XML malformed)\ncontent: %s", xmlString.c_str());
197 boost::property_tree::ptree ds = pt.get_child(
"SickRecord.DataSets.DataSetDepthMap.FormatDescriptionDepthMap.DataStream");
198 cameraParams_.
width = ds.get<uint32_t>(
"Width");
199 cameraParams_.
height = ds.get<uint32_t>(
"Height");
202 BOOST_FOREACH(
const boost::property_tree::ptree::value_type &item, ds.get_child(
"CameraToWorldTransform")) {
209 cameraParams_.
fx = ds.get<
double>(
"CameraMatrix.FX");
210 cameraParams_.
fy = ds.get<
double>(
"CameraMatrix.FY");
211 cameraParams_.
cx = ds.get<
double>(
"CameraMatrix.CX");
212 cameraParams_.
cy = ds.get<
double>(
"CameraMatrix.CY");
214 cameraParams_.
k1 = ds.get<
double>(
"CameraDistortionParams.K1");
215 cameraParams_.
k2 = ds.get<
double>(
"CameraDistortionParams.K2");
217 cameraParams_.
f2rc = ds.get<
double>(
"FocalToRayCross");
220 std::string data_type;
222 data_type=ds.get<std::string>(
"Distance",
"");
223 boost::algorithm::to_lower(data_type);
224 if(data_type !=
"") {
226 numBytesPerDistanceValue_ = 2;
229 data_type=ds.get<std::string>(
"Intensity",
"");
230 boost::algorithm::to_lower(data_type);
231 if(data_type !=
"") {
233 numBytesPerIntensityValue_ = 2;
236 data_type=ds.get<std::string>(
"Confidence",
"");
237 boost::algorithm::to_lower(data_type);
238 if(data_type !=
"") {
240 numBytesPerConfidenceValue_ = 2;
246 void getData(
const char *data,
const size_t size) {
249 ROS_WARN(
"malformed data (1): %d<14", (
int)size);
252 const size_t numBytesDistance = (numBytesPerDistanceValue_ > 0) ? distance_.total()*numBytesPerDistanceValue_ : 0;
253 const size_t numBytesIntensity = (numBytesPerIntensityValue_ > 0) ? intensity_.total()*numBytesPerIntensityValue_ : 0;
254 const size_t numBytesConfidence = (numBytesPerConfidenceValue_ > 0) ? confidence_.total()*numBytesPerConfidenceValue_ : 0;
259 const uint32_t length =
__Swap4Bytes( *(uint32_t*)(data+offset) );
260 const uint64_t timeStamp =
__Swap8Bytes( *(uint64_t*)(data+offset+4) );
261 const uint16_t version =
__Swap2Bytes( *(uint16_t*)(data+offset+12) );
266 ROS_WARN(
"malformed data (2): %d>%d", (
int)length, (
int)size);
272 framenumber_ = ntohl( *(uint32_t*)(data+offset) );
273 const uint8_t dataQuality = *(uint8_t*)(data+offset+4);
274 const uint8_t deviceStatus = *(uint8_t*)(data+offset+5);
280 size_t end = offset + numBytesDistance + numBytesIntensity + numBytesConfidence;
287 if (numBytesDistance > 0) {
288 for(
size_t i=0; i<distance_.total(); i++)
289 distance_.at<uint16_t>(i) =
__Swap2BytesD( *(uint16_t*)(data+offset+i*2) );
290 offset += numBytesDistance;
295 if (numBytesIntensity > 0) {
296 for(
size_t i=0; i<intensity_.total(); i++)
297 intensity_.at<uint16_t>(i) =
__Swap2Bytes( *(uint16_t*)(data+offset+i*2) );
298 offset += numBytesIntensity;
301 intensity_.setTo(std::numeric_limits<uint16_t>::max()/2);
303 if (numBytesConfidence > 0) {
304 for(
size_t i=0; i<confidence_.total(); i++)
305 confidence_.at<uint16_t>(i) =
__Swap2Bytes( *(uint16_t*)(data+offset+i*2) );
306 offset += numBytesConfidence;
309 confidence_.setTo(std::numeric_limits<uint16_t>::max());
313 const uint32_t unusedCrc =
__Swap4Bytes( *(uint32_t*)(data+offset) );
314 const uint32_t lengthCopy =
__Swap4Bytes( *(uint32_t*)(data+offset + 4) );
316 if(length != lengthCopy)
317 ROS_WARN(
"check failed %d!=%d", (
int)length, (
int)lengthCopy);
int numBytesPerIntensityValue_
static bool check_header(const char *data, const size_t size)
#define __Swap4Bytes(dword)
uint32_t get_framenumber() const
bool read(const char *data, const size_t size)
double cam2worldMatrix[4 *4]
const CameraParameters & getCameraParameters() const
#define __Swap2Bytes(val)
CameraParameters(uint32_t width=176, uint32_t height=144, double *cam2worldMatrix=NULL, double fx=146.5, double fy=146.5, double cx=84.4, double cy=71.2, double k1=0.326442, double k2=0.219623, double f2rc=0.0)
void getData(const char *data, const size_t size)
CameraParameters cameraParams_
const cv::Mat & get_distance() const
uint64_t swapLong(uint64_t x)
#define __Swap8Bytes(val)
#define __Swap2BytesD(val)
static size_t actual_size(const char *data, const size_t size)
bool parseXML(const std::string &xmlString)
const cv::Mat & get_intensity() const
const cv::Mat & get_confidence() const