pcl::PointCloud<pcl::PointXYZRGB>::Ptr
convertBytesToPointCloud(char* buffer,int buffer_point_size){

pcl::PointCloud<pcl::PointXYZRGB>::Ptr point_cloud_ptr (new pcl::PointCloud<pcl::PointXYZRGB>);

uint8_t r(255), g(15), b(15);

for(int k=0;k<buffer_point_size;k+=12) {

pcl::PointXYZRGB point;
point.x = bytesToFloat(buffer[k], buffer[k+1], buffer[k+2], buffer[k+3]);
point.y = bytesToFloat(buffer[k+4], buffer[k+5], buffer[k+6], buffer[k+7]);
point.z = bytesToFloat(buffer[k+8], buffer[k+9], buffer[k+10], buffer[k+11]);
printf("%f,%f,%f\n ", point.x,point.y,point.z);

uint32_t rgb = (static_cast<uint32_t>(r) << 16 |
                static_cast<uint32_t>(g) << 8  |
                static_cast<uint32_t>(b)        );
point.rgb = *reinterpret_cast<float*>(&rgb);
point_cloud_ptr->points.push_back (point);
r -= 5;
g += 5;

}

  point_cloud_ptr->width = (int) point_cloud_ptr->points.size ();
  point_cloud_ptr->height = 1;

return point_cloud_ptr;
}
Пример #2
0
void compute_segment_precisions_float_2D(float *oriData, float* pwrErrBound, 
int r1, int r2, int R2, int edgeSize, unsigned char* pwrErrBoundBytes, float Min, float Max)
{
	int i = 0, j = 0, k = 0, p = 0, index = 0, J; //I=-1,J=-1 if they are needed
	float realPrecision; 
	float approxPrecision;
	unsigned char realPrecBytes[4];
	float curValue, curAbsValue;
	float* minAbsValues = (float*)malloc(R2*sizeof(float));
	
	float max = fabs(Min)<fabs(Max)?fabs(Max):fabs(Min); //get the max abs value.
	for(i=0;i<R2;i++)
		minAbsValues[i] = max;
	for(i=0;i<r1;i++)
	{
		for(j=0;j<r2;j++)
		{
			index = i*r2+j;
			curValue = oriData[index];				
			if(((i%edgeSize==edgeSize-1 || i==r1-1) &&j%edgeSize==0&&j>0) || (i%edgeSize==0&&j==0&&i>0))
			{
				realPrecision = pw_relBoundRatio*minAbsValues[J];
				floatToBytes(realPrecBytes, realPrecision);
				realPrecBytes[2] = realPrecBytes[3] = 0;
				approxPrecision = bytesToFloat(realPrecBytes);
				//put the realPrecision in float* pwrErBound		
				pwrErrBound[p++] = approxPrecision;
				//put the two bytes in pwrErrBoundBytes
				pwrErrBoundBytes[k++] = realPrecBytes[0];
				pwrErrBoundBytes[k++] = realPrecBytes[1];	
				minAbsValues[J] = max;		
			}	
			if(j==0)
				J = 0;
			else if(j%edgeSize==0)
				J++;			
			if(curValue!=0)
			{
				curAbsValue = fabs(curValue);
				if(minAbsValues[J]>curAbsValue)
					minAbsValues[J] = curAbsValue;
			}
		}
	}
	realPrecision = pw_relBoundRatio*minAbsValues[J];
	floatToBytes(realPrecBytes, realPrecision);
	realPrecBytes[2] = realPrecBytes[3] = 0;
	approxPrecision = bytesToFloat(realPrecBytes);
	//put the realPrecision in float* pwrErBound
	pwrErrBound[p++] = approxPrecision;
	//put the two bytes in pwrErrBoundBytes
	pwrErrBoundBytes[k++] = realPrecBytes[0];
	pwrErrBoundBytes[k++] = realPrecBytes[1];	
	
	free(minAbsValues);
}
Пример #3
0
void compute_segment_precisions_float_1D(float *oriData, int dataLength, float* pwrErrBound, unsigned char* pwrErrBoundBytes)
{
	int i = 0, j = 0, k = 0;
	float realPrecision = oriData[0]!=0?fabs(pw_relBoundRatio*oriData[0]):pw_relBoundRatio; 
	float approxPrecision;
	unsigned char realPrecBytes[4];
	float curPrecision;
	float curValue;
	for(i=0;i<dataLength;i++)
	{
		curValue = oriData[i];
		if(i%segment_size==0&&i>0)
		{
			//get two first bytes of the realPrecision
			floatToBytes(realPrecBytes, realPrecision);
			realPrecBytes[2] = realPrecBytes[3] = 0;
			approxPrecision = bytesToFloat(realPrecBytes);
			//put the realPrecision in float* pwrErBound
			pwrErrBound[j++] = approxPrecision;
			//put the two bytes in pwrErrBoundBytes
			pwrErrBoundBytes[k++] = realPrecBytes[0];
			pwrErrBoundBytes[k++] = realPrecBytes[1];
			realPrecision = curValue!=0?fabs(pw_relBoundRatio*curValue):pw_relBoundRatio;
		}
		else if(curValue!=0)
		{
			curPrecision = fabs(pw_relBoundRatio*curValue);
			if(realPrecision>curPrecision)
				realPrecision = curPrecision;
		}
	}
	floatToBytes(realPrecBytes, realPrecision);
	realPrecBytes[2] = realPrecBytes[3] = 0;
	approxPrecision = bytesToFloat(realPrecBytes);
	//put the realPrecision in float* pwrErBound
	pwrErrBound[j++] = approxPrecision;
	//put the two bytes in pwrErrBoundBytes
	pwrErrBoundBytes[k++] = realPrecBytes[0];
	pwrErrBoundBytes[k++] = realPrecBytes[1];
}
void dostuff (int sock)
{

//printf("---------------------%f\n", cloud->points[0].x );

   int n;

   char* buffer=new char [4];

   if (read(sock,buffer,4) < 0) error("ERROR reading from socket");

   int points_no =(int)bytesToFloat(buffer[0], buffer[1], buffer[2], buffer[3]) - 1;
   delete [] buffer;

   int buffer_point_size=points_no*(int)sizeof(float);
   buffer=new char[buffer_point_size];
   if (read(sock,buffer,buffer_point_size) < 0) error("ERROR reading from socket");

printf("%d\n", buffer_point_size );
printf("Message from client:\n");



//convertBytesToPointCloud(buffer,buffer_point_size);
 *shared_buffer_size=points_no;

int j;
for(int k=0;k<buffer_point_size;k+=4) {
 sharedbuffer[j]=bytesToFloat(buffer[k], buffer[k+1], buffer[k+2], buffer[k+3]);
std::cout<<" "<<sharedbuffer[j]<<std::endl;
j++;
}
printf("\n");




   n = write(sock,"I got your message",18);
   if (n < 0) error("ERROR writing to socket");
}
template<class Type> Type readbuffer4(int *newsockfd,const char* chars){

    char* buffer=new char [4];
    bzero(buffer,4);
    int n=read(*newsockfd,buffer,4);
    if ( n< 0) error("ERROR reading from socket");

    //point no
    Type res =(Type)bytesToFloat(buffer[0], buffer[1], buffer[2], buffer[3]);

    std::cout << chars<<res << std::endl;


    delete [] buffer;
    return res;

}
Пример #6
0
void compute_segment_precisions_float_3D(float *oriData, float* pwrErrBound, 
int r1, int r2, int r3, int R2, int R3, int edgeSize, unsigned char* pwrErrBoundBytes, float Min, float Max)
{
	int i = 0, j = 0, k = 0, p = 0, q = 0, index = 0, J = 0, K = 0; //I=-1,J=-1 if they are needed
	int r23 = r2*r3, ir, jr;
	float realPrecision; 
	float approxPrecision;
	unsigned char realPrecBytes[4];
	float curValue, curAbsValue;
	
	float** minAbsValues = create2DArray_float(R2, R3);
	float max = fabs(Min)<fabs(Max)?fabs(Max):fabs(Min); //get the max abs value.	
	for(i=0;i<R2;i++)
		for(j=0;j<R3;j++)
			minAbsValues[i][j] = max;			
			
	for(i=0;i<r1;i++)
	{
		ir = i*r23;		
		if(i%edgeSize==0&&i>0)
		{
			realPrecision = pw_relBoundRatio*minAbsValues[J][K];
			floatToBytes(realPrecBytes, realPrecision);
			memset(&realPrecBytes[2], 0, 2);
			approxPrecision = bytesToFloat(realPrecBytes);
			//put the realPrecision in float* pwrErBound
			pwrErrBound[p++] = approxPrecision;
			//put the two bytes in pwrErrBoundBytes
			//printf("q=%d, i=%d, j=%d, k=%d\n",q,i,j,k);
			pwrErrBoundBytes[q++] = realPrecBytes[0];
			pwrErrBoundBytes[q++] = realPrecBytes[1];
			minAbsValues[J][K] = max;			
		}		
		for(j=0;j<r2;j++)
		{
			jr = j*r3;
			if((i%edgeSize==edgeSize-1 || i == r1-1)&&j%edgeSize==0&&j>0)
			{
				realPrecision = pw_relBoundRatio*minAbsValues[J][K];
				floatToBytes(realPrecBytes, realPrecision);
				memset(&realPrecBytes[2], 0, 2);
				approxPrecision = bytesToFloat(realPrecBytes);
				//put the realPrecision in float* pwrErBound
				pwrErrBound[p++] = approxPrecision;
				//put the two bytes in pwrErrBoundBytes
				//printf("q=%d, i=%d, j=%d, k=%d\n",q,i,j,k);
				pwrErrBoundBytes[q++] = realPrecBytes[0];
				pwrErrBoundBytes[q++] = realPrecBytes[1];
				minAbsValues[J][K] = max;				
			}
			
			if(j==0)
				J = 0;
			else if(j%edgeSize==0)
				J++;					
			
			for(k=0;k<r3;k++)
			{
				index = ir+jr+k;				
				curValue = oriData[index];				
				if((i%edgeSize==edgeSize-1 || i == r1-1)&&(j%edgeSize==edgeSize-1||j==r2-1)&&k%edgeSize==0&&k>0)
				{
					realPrecision = pw_relBoundRatio*minAbsValues[J][K];
					floatToBytes(realPrecBytes, realPrecision);
					memset(&realPrecBytes[2], 0, 2);
					approxPrecision = bytesToFloat(realPrecBytes);
					//put the realPrecision in float* pwrErBound
					pwrErrBound[p++] = approxPrecision;
					//put the two bytes in pwrErrBoundBytes
					//printf("q=%d, i=%d, j=%d, k=%d\n",q,i,j,k);
					pwrErrBoundBytes[q++] = realPrecBytes[0];
					pwrErrBoundBytes[q++] = realPrecBytes[1];
					minAbsValues[J][K] = max;
				}	

				if(k==0)
					K = 0;
				else if(k%edgeSize==0)
					K++;
					
				if(curValue!=0)
				{
					curAbsValue = fabs(curValue);
					if(minAbsValues[J][K]>curAbsValue)
						minAbsValues[J][K] = curAbsValue;
				}
			}			
		}
	}	
	
	realPrecision = pw_relBoundRatio*minAbsValues[J][K];
	floatToBytes(realPrecBytes, realPrecision);
	realPrecBytes[2] = realPrecBytes[3] = 0;
	approxPrecision = bytesToFloat(realPrecBytes);
	//put the realPrecision in float* pwrErBound
	pwrErrBound[p++] = approxPrecision;
	//put the two bytes in pwrErrBoundBytes
	pwrErrBoundBytes[q++] = realPrecBytes[0];
	pwrErrBoundBytes[q++] = realPrecBytes[1];
	
	free2DArray_float(minAbsValues, R2);
}
Пример #7
0
/**
 * 
 * 
 * @return status SUCCESSFUL (SZ_SCES) or not (other error codes) 
 * */
int SZ_decompress_args_float(float** newData, int r5, int r4, int r3, int r2, int r1, unsigned char* cmpBytes, int cmpSize)
{
	int status = SZ_SCES;
	int dataLength = computeDataLength(r5,r4,r3,r2,r1);
	
	//unsigned char* tmpBytes;
	int targetUncompressSize = dataLength <<2; //i.e., *4
	//tmpSize must be "much" smaller than dataLength
	int tmpSize = 12, i;
	unsigned char* szTmpBytes;	
	
	if(cmpSize!=12)
	{
		int isZlib = isZlibFormat(cmpBytes[0], cmpBytes[1]);
		if(isZlib)
			szMode = SZ_BEST_COMPRESSION;
		else
			szMode = SZ_BEST_SPEED;		
		if(szMode==SZ_BEST_SPEED)
		{
			tmpSize = cmpSize;
			szTmpBytes = cmpBytes;	
		}
		else if(szMode==SZ_BEST_COMPRESSION || szMode==SZ_DEFAULT_COMPRESSION)
		{
			if(targetUncompressSize<MIN_ZLIB_DEC_ALLOMEM_BYTES) //Considering the minimum size
				targetUncompressSize = MIN_ZLIB_DEC_ALLOMEM_BYTES; 
			tmpSize = zlib_uncompress2(cmpBytes, (unsigned long)cmpSize, &szTmpBytes, (unsigned long)targetUncompressSize);			
			//szTmpBytes = (unsigned char*)malloc(sizeof(unsigned char)*tmpSize);
			//memcpy(szTmpBytes, tmpBytes, tmpSize);
			//free(tmpBytes); //release useless memory		
		}
		else
		{
			printf("Wrong value of szMode in the double compressed bytes.\n");
			status = SZ_MERR;
			return status;
		}	
	}
	else
		szTmpBytes = cmpBytes;
	
	//TODO: convert szTmpBytes to data array.
	TightDataPointStorageF* tdps;
	int errBoundMode = new_TightDataPointStorageF_fromFlatBytes(&tdps, szTmpBytes, tmpSize);
	
	//writeByteData(tdps->typeArray, tdps->typeArray_size, "decompress-typebytes.tbt");
	
	int dim = computeDimension(r5,r4,r3,r2,r1);	
	int floatSize = sizeof(float);
	if(tdps->isLossless)
	{
		*newData = (float*)malloc(floatSize*dataLength);
		if(sysEndianType==BIG_ENDIAN_SYSTEM)
		{
			memcpy(*newData, szTmpBytes+8, dataLength*floatSize);
		}
		else
		{
			unsigned char* p = szTmpBytes+8;
			for(i=0;i<dataLength;i++,p+=floatSize)
				(*newData)[i] = bytesToFloat(p);
		}		
	}
	else if (dim == 1)
		getSnapshotData_float_1D(newData,r1,tdps, errBoundMode);
	else
	if (dim == 2)
		getSnapshotData_float_2D(newData,r2,r1,tdps, errBoundMode);
	else
	if (dim == 3)
		getSnapshotData_float_3D(newData,r3,r2,r1,tdps, errBoundMode);
	else
	if (dim == 4)
		getSnapshotData_float_3D(newData,r4*r3,r2,r1,tdps, errBoundMode);
	else
	{
		printf("Error: currently support only at most 4 dimensions!\n");
		status = SZ_DERR;
	}
	free_TightDataPointStorageF(tdps);
	if(szMode!=SZ_BEST_SPEED && cmpSize!=12)
		free(szTmpBytes);
	SZ_ReleaseHuffman();	
	return status;
}