Pravin Poudel
Pravin Poudel

Reputation: 1536

retriving data from Uint8 array

I have a point data in this format

Uint8Array
(1434544) [170, 189, 128, 65, 141, 54, 182, 65, 218, 50, 12, 192, 61, 247, 134, 194, 242, 169, 128, 65, ...]

It is Uint8Array and represent point data of point cloud in format of x, y, z, and i where each is 4 bytes making each point 16 bytes.

The data array is list of point in byte stream or typedarray for points

How can i transformed this data to retrive x, y, z and i of each point?

Any help please

Upvotes: 0

Views: 85

Answers (1)

antonylgs
antonylgs

Reputation: 1

You can use this function:

const sortDataPoints = (array) => {
  let arrayOfPoints = [];
  let i = 0;
  let tempObject = {};

  for (let u = 0; u < array.length; u = u + 4) {
    const coordonate = new TextDecoder().decode(
      Uint8Array.from([array[u], array[u + 1], array[u + 2], array[u + 3]])
    );

    if (i === 0) {
      tempObject.x = coordonate;
      i++;
    } else if (i === 1) {
      tempObject.y = coordonate;
      i++;
    } else if (i === 2) {
      tempObject.z = coordonate;
      i++;
    } else if (i === 3) {
      tempObject.i = coordonate;
      arrayOfPoints.push(tempObject);
      tempObject = {};
      i = 0;
    }
  }

  return arrayOfPoints;
};

Upvotes: -1

Related Questions