yzt
2023-05-08 24e1c6a1c3d5331b5a4f1111dcbae3ef148eda1a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
import {
  BatchTableHierarchy,
  PropertyTable,
  MetadataSchema,
  MetadataTable,
  JsonMetadataTable,
} from "../../Source/Cesium.js";
import MetadataTester from "../MetadataTester.js";
 
describe("Scene/PropertyTable", function () {
  if (!MetadataTester.isSupported()) {
    return;
  }
 
  var properties = {
    name: {
      componentType: "STRING",
      semantic: "NAME",
    },
    height: {
      componentType: "FLOAT32",
      semantic: "HEIGHT",
    },
  };
 
  var propertyValues = {
    name: ["Building A", "Building B", "Building C"],
    height: [10.0, 20.0, 30.0],
  };
 
  var extras = {
    description: "Extra",
  };
  var extensions = {
    EXT_other_extension: {},
  };
 
  function createPropertyTable() {
    return MetadataTester.createPropertyTable({
      properties: properties,
      propertyValues: propertyValues,
      extras: extras,
      extensions: extensions,
    });
  }
 
  it("creates feature table with default values", function () {
    var propertyTable = new PropertyTable({
      count: 3,
    });
    expect(propertyTable.count).toBe(3);
    expect(propertyTable.class).toBeUndefined();
    expect(propertyTable.extras).toBeUndefined();
    expect(propertyTable.extensions).toBeUndefined();
  });
 
  it("creates feature table", function () {
    var propertyTable = createPropertyTable();
    expect(propertyTable.count).toBe(3);
    expect(propertyTable.class).toBeDefined();
    expect(propertyTable.getPropertyIds().length).toBe(2);
    expect(propertyTable.getProperty(0, "name")).toBe("Building A");
    expect(propertyTable.getProperty(1, "name")).toBe("Building B");
    expect(propertyTable.getProperty(2, "name")).toBe("Building C");
    expect(propertyTable.getProperty(0, "height")).toBe(10.0);
    expect(propertyTable.getProperty(1, "height")).toBe(20.0);
    expect(propertyTable.getProperty(2, "height")).toBe(30.0);
    expect(propertyTable.extras).toBe(extras);
    expect(propertyTable.extensions).toBe(extensions);
  });
 
  it("constructor throws without count", function () {
    expect(function () {
      return new PropertyTable({});
    }).toThrowDeveloperError();
  });
 
  it("hasProperty throws without index", function () {
    var propertyTable = createPropertyTable();
    expect(function () {
      propertyTable.hasProperty(undefined, "name");
    }).toThrowDeveloperError();
  });
 
  it("hasProperty throws without propertyId", function () {
    var propertyTable = createPropertyTable();
    expect(function () {
      propertyTable.hasProperty(0, undefined);
    }).toThrowDeveloperError();
  });
 
  it("hasProperty returns true if the feature has this property", function () {
    var propertyTable = createPropertyTable();
    expect(propertyTable.hasProperty(0, "name")).toBe(true);
  });
 
  it("hasProperty returns false if the feature does not have this property", function () {
    var propertyTable = createPropertyTable();
    expect(propertyTable.hasProperty(0, "numberOfPoints")).toBe(false);
  });
 
  it("hasPropertyBySemantic throws without index", function () {
    var propertyTable = createPropertyTable();
    expect(function () {
      propertyTable.hasPropertyBySemantic(undefined, "NAME");
    }).toThrowDeveloperError();
  });
 
  it("hasPropertyBySemantic throws without semantic", function () {
    var propertyTable = createPropertyTable();
    expect(function () {
      propertyTable.hasPropertyBySemantic(0, undefined);
    }).toThrowDeveloperError();
  });
 
  it("hasPropertyBySemantic returns true if the feature has a property with the given semantic", function () {
    var propertyTable = createPropertyTable();
    expect(propertyTable.hasPropertyBySemantic(0, "NAME")).toBe(true);
  });
 
  it("hasPropertyBySemantic returns false if the feature does not a property with the given semantic", function () {
    var propertyTable = createPropertyTable();
    expect(propertyTable.hasPropertyBySemantic(0, "ID")).toBe(false);
  });
 
  it("propertyExists throws without propertyId", function () {
    var propertyTable = createPropertyTable();
    expect(function () {
      propertyTable.propertyExists(undefined);
    }).toThrowDeveloperError();
  });
 
  it("propertyExists returns true if the property exists", function () {
    var propertyTable = createPropertyTable();
    expect(propertyTable.propertyExists("name")).toBe(true);
  });
 
  it("propertyExists returns false if the property does not exist", function () {
    var propertyTable = createPropertyTable();
    expect(propertyTable.propertyExists("numberOfPoints")).toBe(false);
  });
 
  it("propertyExistsBySemantic throws without semantic", function () {
    var propertyTable = createPropertyTable();
    expect(function () {
      propertyTable.propertyExistsBySemantic(undefined);
    }).toThrowDeveloperError();
  });
 
  it("propertyExistsBySemantic returns true if the property exists", function () {
    var propertyTable = createPropertyTable();
    expect(propertyTable.propertyExistsBySemantic("NAME")).toBe(true);
  });
 
  it("propertyExistsBySemantic returns false if the property does not exist", function () {
    var propertyTable = createPropertyTable();
    expect(propertyTable.propertyExistsBySemantic("ID")).toBe(false);
  });
 
  it("getPropertyIds returns array of property IDs", function () {
    var propertyTable = createPropertyTable();
    var propertyIds = propertyTable.getPropertyIds([]);
    propertyIds.sort();
    expect(propertyIds).toEqual(["height", "name"]);
  });
 
  it("getProperty returns undefined if a property does not exist", function () {
    var propertyTable = createPropertyTable();
    expect(propertyTable.getProperty(0, "numberOfPoints")).not.toBeDefined();
  });
 
  it("getProperty returns the property value", function () {
    var propertyTable = createPropertyTable();
    expect(propertyTable.getProperty(0, "name")).toEqual("Building A");
    expect(propertyTable.getProperty(0, "height")).toEqual(10.0);
  });
 
  it("setProperty does not create property if it doesn't exist", function () {
    var propertyTable = createPropertyTable();
    expect(propertyTable.setProperty(0, "numberOfPoints", 10)).toBe(false);
  });
 
  it("setProperty sets property value", function () {
    var propertyTable = createPropertyTable();
    expect(propertyTable.getProperty(0, "name")).toBe("Building A");
    propertyTable.setProperty(0, "name", "Building New");
    expect(propertyTable.getProperty(0, "name")).toBe("Building New");
  });
 
  it("getPropertyBySemantic returns undefined when there's no property with the given semantic", function () {
    var propertyTable = createPropertyTable();
    expect(propertyTable.getPropertyBySemantic(0, "ID")).not.toBeDefined();
  });
 
  it("getPropertyBySemantic returns the property value", function () {
    var propertyTable = createPropertyTable();
    expect(propertyTable.getPropertyBySemantic(0, "NAME")).toEqual(
      "Building A"
    );
  });
 
  it("getPropertyBySemantic returns undefined if there is no metadataTable", function () {
    var propertyTable = new PropertyTable({
      count: 3,
    });
    expect(propertyTable.getPropertyBySemantic(0, "NAME")).not.toBeDefined();
  });
 
  it("setPropertyBySemantic sets property value", function () {
    var propertyTable = createPropertyTable();
    expect(propertyTable.getPropertyBySemantic(0, "NAME")).toEqual(
      "Building A"
    );
    expect(propertyTable.setPropertyBySemantic(0, "NAME", "Building New")).toBe(
      true
    );
  });
 
  it("setPropertyBySemantic returns false if the semantic does not exist", function () {
    var propertyTable = createPropertyTable();
    expect(propertyTable.setPropertyBySemantic(0, "ID", 10)).toBe(false);
  });
 
  it("setPropertyBySemantic returns false if there is no metadata table", function () {
    var propertyTable = new PropertyTable({
      count: 3,
    });
    expect(propertyTable.setPropertyBySemantic(0, "NAME")).toBe(false);
  });
 
  it("getPropertyTypedArray returns typed array", function () {
    var propertyTable = createPropertyTable();
    var expectedTypedArray = new Float32Array([10.0, 20.0, 30.0]);
 
    expect(propertyTable.getPropertyTypedArray("height")).toEqual(
      expectedTypedArray
    );
  });
 
  it("getPropertyTypedArray returns undefined if property does not exist", function () {
    var propertyTable = createPropertyTable();
 
    expect(propertyTable.getPropertyTypedArray("volume")).toBeUndefined();
  });
 
  it("getPropertyTypedArray throws if propertyId is undefined", function () {
    var propertyTable = createPropertyTable();
 
    expect(function () {
      propertyTable.getPropertyTypedArray(undefined);
    }).toThrowDeveloperError();
  });
 
  it("getPropertyTypedArrayBySemantic returns typed array", function () {
    var propertyTable = createPropertyTable();
    var expectedTypedArray = new Float32Array([10.0, 20.0, 30.0]);
 
    expect(propertyTable.getPropertyTypedArrayBySemantic("HEIGHT")).toEqual(
      expectedTypedArray
    );
  });
 
  it("getPropertyTypedArrayBySemantic returns undefined if semantic does not exist", function () {
    var propertyTable = createPropertyTable();
 
    expect(propertyTable.getPropertyTypedArrayBySemantic("ID")).toBeUndefined();
  });
 
  it("getPropertyTypedArrayBySemantic throws if semantic is undefined", function () {
    var propertyTable = createPropertyTable();
 
    expect(function () {
      propertyTable.getPropertyTypedArrayBySemantic(undefined);
    }).toThrowDeveloperError();
  });
 
  describe("batch table compatibility", function () {
    var schemaJson = {
      classes: {
        box: {
          properties: {
            itemId: {
              componentType: "UINT8",
            },
            itemCount: {
              componentType: "UINT16",
            },
          },
        },
      },
    };
    var schema = new MetadataSchema(schemaJson);
 
    var propertyTableJson = {
      count: 3,
      class: "box",
      properties: {
        itemId: {
          bufferView: 0,
        },
        itemCount: {
          bufferView: 1,
        },
      },
    };
 
    var bufferViews = {
      0: new Uint8Array([25, 32, 57]),
      1: new Uint8Array([25, 0, 5, 1, 50, 0]),
    };
 
    var jsonProperties = {
      priority: [2, 1, 0],
      uri: ["tree.las", "building.gltf", "map.tif"],
    };
    var count = 3;
 
    var hierarchyExtension = {
      classes: [
        {
          name: "Wheels",
          length: 2,
          instances: {
            tireLocation: ["front", "back"],
          },
        },
        {
          name: "Car",
          length: 1,
          instances: {
            color: ["blue"],
            type: ["sedan"],
            year: ["2020"],
          },
        },
      ],
      instancesLength: 3,
      classIds: [0, 0, 1],
      parentIds: [2, 2, 2],
      parentCounts: [1, 1, 0],
    };
 
    var batchTable;
    var batchTableJsonOnly;
 
    beforeEach(function () {
      var jsonTable = new JsonMetadataTable({
        count: count,
        properties: jsonProperties,
      });
 
      var hierarchy = new BatchTableHierarchy({
        extension: hierarchyExtension,
      });
 
      var metadataTable = new MetadataTable({
        count: count,
        properties: propertyTableJson.properties,
        class: schema.classes.box,
        bufferViews: bufferViews,
      });
 
      batchTable = new PropertyTable({
        count: count,
        metadataTable: metadataTable,
        jsonMetadataTable: jsonTable,
        batchTableHierarchy: hierarchy,
      });
 
      batchTableJsonOnly = new PropertyTable({
        count: count,
        jsonMetadataTable: jsonTable,
      });
    });
 
    it("getPropertyIds combines binary, json and hierarchy IDs", function () {
      var results = batchTable.getPropertyIds(0);
      expect(results.sort()).toEqual([
        "color",
        "itemCount",
        "itemId",
        "priority",
        "tireLocation",
        "type",
        "uri",
        "year",
      ]);
    });
 
    it("hasProperty uses feature metadata", function () {
      expect(batchTable.hasProperty(0, "itemId")).toBe(true);
      expect(batchTable.hasProperty(0, "itemCount")).toBe(true);
    });
 
    it("hasProperty uses JSON metadata", function () {
      expect(batchTable.hasProperty(0, "priority")).toBe(true);
      expect(batchTable.hasProperty(0, "uri")).toBe(true);
    });
 
    it("hasProperty uses batch table hierarchy", function () {
      expect(batchTable.hasProperty(0, "tireLocation")).toBe(true);
      expect(batchTable.hasProperty(0, "color")).toBe(true);
      expect(batchTable.hasProperty(0, "type")).toBe(true);
      expect(batchTable.hasProperty(0, "year")).toBe(true);
 
      expect(batchTable.hasProperty(1, "tireLocation")).toBe(true);
      expect(batchTable.hasProperty(1, "color")).toBe(true);
      expect(batchTable.hasProperty(1, "type")).toBe(true);
      expect(batchTable.hasProperty(1, "year")).toBe(true);
 
      expect(batchTable.hasProperty(2, "tireLocation")).toBe(false);
      expect(batchTable.hasProperty(2, "color")).toBe(true);
      expect(batchTable.hasProperty(2, "type")).toBe(true);
      expect(batchTable.hasProperty(2, "year")).toBe(true);
    });
 
    it("hasProperty returns false for unknown property", function () {
      expect(batchTable.hasProperty(0, "widgets")).toBe(false);
    });
 
    it("hasPropertyBySemantic returns false when there is no metadata table", function () {
      expect(batchTableJsonOnly.hasPropertyBySemantic(0, "NAME")).toBe(false);
    });
 
    it("propertyExists uses feature metadata", function () {
      expect(batchTable.propertyExists("itemId")).toBe(true);
      expect(batchTable.propertyExists("itemCount")).toBe(true);
    });
 
    it("propertyExists uses JSON metadata", function () {
      expect(batchTable.propertyExists("priority")).toBe(true);
      expect(batchTable.propertyExists("uri")).toBe(true);
    });
 
    it("propertyExists uses batch table hierarchy", function () {
      expect(batchTable.propertyExists("tireLocation")).toBe(true);
      expect(batchTable.propertyExists("color")).toBe(true);
      expect(batchTable.propertyExists("type")).toBe(true);
      expect(batchTable.propertyExists("year")).toBe(true);
    });
 
    it("propertyExists returns false for unknown property", function () {
      expect(batchTable.propertyExists("widgets")).toBe(false);
    });
 
    it("propertyExistsBySemantic returns false when there is no metadata table", function () {
      expect(batchTableJsonOnly.propertyExistsBySemantic("NAME")).toBe(false);
    });
 
    it("getProperty uses feature metadata", function () {
      expect(batchTable.getProperty(0, "itemId")).toBe(25);
      expect(batchTable.getProperty(0, "itemCount")).toBe(25);
 
      expect(batchTable.getProperty(1, "itemId")).toBe(32);
      expect(batchTable.getProperty(1, "itemCount")).toBe(261);
 
      expect(batchTable.getProperty(2, "itemId")).toBe(57);
      expect(batchTable.getProperty(2, "itemCount")).toBe(50);
    });
 
    it("getProperty uses JSON metadata", function () {
      expect(batchTable.getProperty(0, "priority")).toBe(2);
      expect(batchTable.getProperty(1, "priority")).toBe(1);
      expect(batchTable.getProperty(2, "priority")).toBe(0);
 
      expect(batchTable.getProperty(0, "uri")).toBe("tree.las");
      expect(batchTable.getProperty(1, "uri")).toBe("building.gltf");
      expect(batchTable.getProperty(2, "uri")).toBe("map.tif");
    });
 
    it("getProperty uses batch table hierarchy", function () {
      expect(batchTable.getProperty(0, "tireLocation")).toBe("front");
      expect(batchTable.getProperty(0, "color")).toBe("blue");
      expect(batchTable.getProperty(0, "type")).toBe("sedan");
      expect(batchTable.getProperty(0, "year")).toBe("2020");
 
      expect(batchTable.getProperty(1, "tireLocation")).toBe("back");
      expect(batchTable.getProperty(1, "color")).toBe("blue");
      expect(batchTable.getProperty(1, "type")).toBe("sedan");
      expect(batchTable.getProperty(1, "year")).toBe("2020");
 
      expect(batchTable.getProperty(2, "tireLocation")).not.toBeDefined();
      expect(batchTable.getProperty(2, "color")).toBe("blue");
      expect(batchTable.getProperty(2, "type")).toBe("sedan");
      expect(batchTable.getProperty(2, "year")).toBe("2020");
    });
 
    it("getProperty returns undefined for unknown propertyId", function () {
      expect(batchTable.getProperty(0, "widgets")).not.toBeDefined();
    });
 
    it("setProperty uses feature metadata", function () {
      expect(batchTable.getProperty(0, "itemCount")).toBe(25);
      expect(batchTable.setProperty(0, "itemCount", 24)).toBe(true);
      expect(batchTable.getProperty(0, "itemCount")).toBe(24);
    });
 
    it("setProperty uses JSON metadata", function () {
      expect(batchTable.getProperty(0, "uri")).toBe("tree.las");
      expect(batchTable.setProperty(0, "uri", "tree_final.las")).toBe(true);
      expect(batchTable.getProperty(0, "uri")).toBe("tree_final.las");
    });
 
    it("setProperty uses batch table hierarchy", function () {
      expect(batchTable.getProperty(0, "tireLocation")).toBe("front");
      expect(batchTable.getProperty(0, "color")).toBe("blue");
 
      expect(batchTable.getProperty(2, "tireLocation")).not.toBeDefined();
      expect(batchTable.getProperty(2, "color")).toBe("blue");
 
      expect(batchTable.setProperty(0, "tireLocation", "back")).toBe(true);
      expect(batchTable.setProperty(2, "color", "navy")).toBe(true);
 
      expect(batchTable.getProperty(0, "tireLocation")).toBe("back");
      expect(batchTable.getProperty(0, "color")).toBe("navy");
 
      expect(batchTable.getProperty(2, "tireLocation")).not.toBeDefined();
      expect(batchTable.getProperty(2, "color")).toBe("navy");
    });
 
    it("setProperty returns false for unknown propertyId", function () {
      expect(batchTable.setProperty(0, "widgets", 5)).toBe(false);
    });
 
    it("getPropertyTypedArray returns undefined for JSON and hierarchy properties", function () {
      expect(batchTable.getPropertyTypedArray("itemId")).toBeDefined();
      expect(batchTable.getPropertyTypedArray("priority")).not.toBeDefined();
      expect(
        batchTable.getPropertyTypedArray("tireLocation")
      ).not.toBeDefined();
    });
 
    it("getPropertyTypedArray returns undefined when there is no metadata table", function () {
      expect(
        batchTableJsonOnly.getPropertyTypedArray("priority")
      ).not.toBeDefined();
    });
 
    it("getPropertyTypedArrayBySemantic returns undefined when there is no metadata table", function () {
      expect(
        batchTableJsonOnly.getPropertyTypedArrayBySemantic("PRIORITY")
      ).not.toBeDefined();
    });
  });
});