PCDLoader incorrect colors from ascii PCD files

Description of the problem

The decoding of RGB colors in incorrect in PCDLoader when decoding ascii files..

three.js/examples/js/loaders/PCDLoader.js

I am basing this fact on PCD files that display correctly using Debian version of pcl_viewer.

We need to treat the data as a 32 bit integer and the color byte order is reversed.

Here is a code fix for the problem:

  //var c = new Float32Array( [ parseFloat( line[ offset.rgb ] ) ] );
  //var dataview = new DataView( c.buffer, 0 );
  //color.push( dataview.getUint8( 0 ) / 255.0 );
  //color.push( dataview.getUint8( 1 ) / 255.0 );
  //color.push( dataview.getUint8( 2 ) / 255.0 );

   var c = new Int32Array( [ parseInt( line[ offset.rgb ] ) ] );
   var dataview = new DataView( c.buffer, 0 );
   color.push( dataview.getUint8( 2 ) / 255.0 );
   color.push( dataview.getUint8( 1 ) / 255.0 );
   color.push( dataview.getUint8( 0 ) / 255.0 );
Three.js version

Latest as of 2017 – 09 -15

Browser
  • All of them
  • Chrome
  • Firefox
  • Internet Explorer
OS
  • [] All of them
  • Windows
  • macOS
  • [x ] Linux
  • Android
  • iOS
Hardware Requirements (graphics card, VR Device, …)

N/A

Author: Fantashit

1 thought on “PCDLoader incorrect colors from ascii PCD files

  1. The loader is not decoding the colors correctly. This appears to work:

    var rgb = parseFloat( line[ offset.rgb ] );
    var r = ( rgb >> 16 ) & 0x0000ff;
    var g = ( rgb >> 8 ) & 0x0000ff;
    var b = ( rgb >> 0 ) & 0x0000ff;
    color.push( r / 255, g / 255, b / 255 );

    There may be a more-elegant solution.

    Plus, it should be:

    material.vertexColors = THREE.VertexColors;

Comments are closed.