게하! 개하! (게임도 하고 개발도 하고)

How to change (convert) rgb and xyz number to pcd file format in javascript 본문

Javascript

How to change (convert) rgb and xyz number to pcd file format in javascript

Sorrel 2022. 2. 16. 12:46
//Those arrays are all different according to each code
//Check your html file and find location of position and color arrays
let pcd_position = document.querySelector('#root').components['sync'].envPointSet....;
let pcd_color = document.querySelector('#root').components['sync'].envPointSet....;
let width = document.querySelector('#root').components['sync'].envPointSet....;

//make file format
//This process is likely to take a long time according to your array size
//If it takes too long time to finish, you should use 'web worker' and add a thread to manage this process own
let data = `# .PCD v.7 - Point Cloud Data file format\nVERSION .7\nFIELDS x y z rgb\nSIZE 4 4 4 4\nTYPE F F F F\nCOUNT 1 1 1 1\nWIDTH ${width}\nHEIGHT 1\nVIEWPOINT 0 0 0 1 0 0 0\nPOINTS ${width}\nDATA ascii\n`;
let r = 0, g = 0, b = 0;
for (i = 0; i < width * 3; i++) {
	data = data.concat(String(roundToSix(pcd_position.array[i]))) + " ";
	switch (i % 3) {
		case 0: r = (pcd_color.array[i]) * 255; break;
		case 1: g = (pcd_color.array[i]) * 255; break;
		default:
		b = (pcd_color.array[i]) * 255;
		rgb = Math.floor((r + g / 256 + b / (256 * 256)) * 256 * 256);
		if (i != width * 3 - 1) {
			data = data.concat(String(rgb) + "\n");
		}
		else {
			data = data.concat(String(rgb));
		}
	}
}

You should change only definition of 'pcd_position', 'pcd_color' and 'width'

 

Those arrays are all different according to each code
Check your html file and find location of position and color arrays using developer tool(f12)

And apply your code in document.querySelector('#root').components['sync'].envPointSet....; <-- here

 

This process is likely to take a long time according to your array size.
If it takes too long time to finish, you should use 'web worker' and add a thread to manage this process own

0 Comments
댓글쓰기 폼