0

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

Roko C. Buljan
  • 196,159
  • 39
  • 305
  • 313
Pravin Poudel
  • 1,433
  • 3
  • 16
  • 38
  • Where did you get this data from? You probably should have used `Uint32Array` from the beginning. (Or `Int32Array`? Or `Float32Array`? You haven't told us *how* every 4 bytes represent a coordinate. Also what is the endianness of the data?) – Bergi Jul 01 '23 at 19:51
  • I get this data from another system and in my case i am getting data from ROS and i am trying to visualize this data. – Pravin Poudel Jul 01 '23 at 21:58
  • Then you should use a [`DataView`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView) and call the respective `get(U)Int32` method with the correct endianness for each index – Bergi Jul 02 '23 at 03:39

1 Answers1

-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;
};
antonylgs
  • 1
  • 2
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 03 '23 at 10:49