Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Sign In

uber / deck.gl / 13779

18 Sep 2019 - 0:00 coverage decreased (-2.9%) to 79.902%
13779

Pull #3623

travis-ci-com

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
beta.2
Pull Request #3623: Bump dependency versions

3405 of 4619 branches covered (73.72%)

Branch coverage included in aggregate %.

7031 of 8442 relevant lines covered (83.29%)

5687.45 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.21
/modules/layers/src/point-cloud-layer/point-cloud-layer.js
1
// Copyright (c) 2015 - 2017 Uber Technologies, Inc.
9×
2
//
3
// Permission is hereby granted, free of charge, to any person obtaining a copy
4
// of this software and associated documentation files (the "Software"), to deal
5
// in the Software without restriction, including without limitation the rights
6
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
// copies of the Software, and to permit persons to whom the Software is
8
// furnished to do so, subject to the following conditions:
9
//
10
// The above copyright notice and this permission notice shall be included in
11
// all copies or substantial portions of the Software.
12
//
13
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
// THE SOFTWARE.
20

21
import {Layer} from '@deck.gl/core';
22
import GL from '@luma.gl/constants';
23
import {Model, Geometry, PhongMaterial} from '@luma.gl/core';
24

25
import vs from './point-cloud-layer-vertex.glsl';
26
import fs from './point-cloud-layer-fragment.glsl';
27

28
const DEFAULT_COLOR = [0, 0, 0, 255];
1×
29
const DEFAULT_NORMAL = [0, 0, 1];
1×
30
const defaultMaterial = new PhongMaterial();
1×
31

32
const defaultProps = {
1×
33
  sizeUnits: 'pixels',
34
  pointSize: {type: 'number', min: 0, value: 10}, //  point radius in pixels
35

UNCOV
36
  getPosition: {type: 'accessor', value: x => x.position},
!
37
  getNormal: {type: 'accessor', value: DEFAULT_NORMAL},
38
  getColor: {type: 'accessor', value: DEFAULT_COLOR},
39

40
  material: defaultMaterial,
41

42
  // Depreated
43
  radiusPixels: {deprecatedFor: 'pointSize'}
44
};
45

46
// support loaders.gl point cloud format
47
function normalizeData(data) {
48
  const {header, attributes} = data;
8×
49
  if (!header || !attributes) {
8×
50
    return;
7×
51
  }
52

53
  data.length = header.vertexCount;
1×
54

55
  if (attributes.POSITION) {
Branches [[2, 1]] missed. 1×
56
    attributes.instancePositions = attributes.POSITION;
1×
57
  }
58
  if (attributes.NORMAL) {
Branches [[3, 1]] missed. 1×
59
    attributes.instanceNormals = attributes.NORMAL;
1×
60
  }
61
  if (attributes.COLOR_0) {
Branches [[4, 1]] missed. 1×
62
    attributes.instanceColors = attributes.COLOR_0;
1×
63
  }
64
}
65

66
export default class PointCloudLayer extends Layer {
67
  getShaders(id) {
68
    return super.getShaders({vs, fs, modules: ['project32', 'gouraud-lighting', 'picking']});
2×
69
  }
70

71
  initializeState() {
72
    /* eslint-disable max-len */
73
    this.getAttributeManager().addInstanced({
2×
74
      instancePositions: {
75
        size: 3,
76
        type: this.use64bitPositions() ? GL.DOUBLE : GL.FLOAT,
Branches [[5, 1]] missed.
77
        transition: true,
78
        accessor: 'getPosition'
79
      },
80
      instanceNormals: {
81
        size: 3,
82
        transition: true,
83
        accessor: 'getNormal',
84
        defaultValue: DEFAULT_NORMAL
85
      },
86
      instanceColors: {
87
        size: this.props.colorFormat.length,
88
        type: GL.UNSIGNED_BYTE,
89
        normalized: true,
90
        transition: true,
91
        accessor: 'getColor',
92
        defaultValue: DEFAULT_COLOR
93
      }
94
    });
95
    /* eslint-enable max-len */
96
  }
97

98
  updateState({props, oldProps, changeFlags}) {
99
    super.updateState({props, oldProps, changeFlags});
12×
100
    if (changeFlags.extensionsChanged) {
12×
101
      const {gl} = this.context;
2×
102
      if (this.state.model) {
Branches [[7, 0]] missed. 2×
UNCOV
103
        this.state.model.delete();
!
104
      }
105
      this.setState({model: this._getModel(gl)});
2×
106
      this.getAttributeManager().invalidateAll();
2×
107
    }
108
    if (changeFlags.dataChanged) {
12×
109
      normalizeData(props.data);
8×
110
    }
111
  }
112

113
  draw({uniforms}) {
114
    const {viewport} = this.context;
13×
115
    const {pointSize, sizeUnits} = this.props;
13×
116

117
    const sizeMultiplier = sizeUnits === 'meters' ? viewport.distanceScales.pixelsPerMeter[2] : 1;
Branches [[9, 0]] missed. 13×
118

119
    this.state.model
13×
120
      .setUniforms(
121
        Object.assign({}, uniforms, {
122
          radiusPixels: pointSize * sizeMultiplier
123
        })
124
      )
125
      .draw();
126
  }
127

128
  _getModel(gl) {
129
    // a triangle that minimally cover the unit circle
130
    const positions = [];
2×
131
    for (let i = 0; i < 3; i++) {
2×
132
      const angle = (i / 3) * Math.PI * 2;
6×
133
      positions.push(Math.cos(angle) * 2, Math.sin(angle) * 2, 0);
6×
134
    }
135

136
    return new Model(
2×
137
      gl,
138
      Object.assign({}, this.getShaders(), {
139
        id: this.props.id,
140
        geometry: new Geometry({
141
          drawMode: GL.TRIANGLES,
142
          attributes: {
143
            positions: new Float32Array(positions)
144
          }
145
        }),
146
        isInstanced: true
147
      })
148
    );
149
  }
150
}
151

152
PointCloudLayer.layerName = 'PointCloudLayer';
1×
153
PointCloudLayer.defaultProps = defaultProps;
1×
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
BLOG · TWITTER · Legal & Privacy · Supported CI Services · What's a CI service? · Automated Testing

© 2019 Coveralls, LLC