-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
validating batch table #41
Conversation
@lilleyse will you be able to look at this soon? |
If I remember correctly, the main things to address here were:
|
@JudyWeng any update here as well? |
I had attempted the method of changing the tiles to promises first, which caused a lot of changes, but I'm going to try loading the batch table schema in validateTileset now instead to avoid having to change every validateB3dm, validateI3dm file. |
|
||
loadJson('https://raw.githubusercontent.com/AnalyticalGraphicsInc/3d-tiles/master/schema/batchTable.schema.json') | ||
.then(function(schema) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to change the validate files to take the batch table schema in as a parameter to avoid having to change everything into an asynchronous process, as suggested previously. However, it seems like loadJson() is returning the "XMLHttpRequest i undefined" error. I have tried both the url above and this url: "https://github.com/AnalyticalGraphicsInc/3d-tiles/blob/master/schema/batchTable.schema.json" to load the Json. Am I not using this function properly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, XMLHttpRequest
must only be supported in browsers and not Node. You could try looking at http.request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I choose to use http.request it would require me to change loadJson() though wouldn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lilleyse any thoughts here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed this offline, that using http.request (or alternatives) is fine to replace loadJson.
I wrote the test cases for the binary table validation for b3dm, i3dm, and pnts, but not cmpt yet because that validation branch has yet to be merged into validator-master. Please let me know if there are more edge cases I have yet to cover. |
I'll look at both later today. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mostly looked at the b3dm code, so there may be areas I missed. I'll do a closer review at a later point.
So far it looks solid - mainly once the batch table extraction code is more condensed I think it will fit in better.
validator/lib/validateB3dm.js
Outdated
throw new DeveloperError('b3dm content must be of type buffer'); | ||
} | ||
|
||
if(content.length < 2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be 24?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: if(
-> if (
.
Fix throughout.
validator/lib/validateB3dm.js
Outdated
batchTableJSON: batchTableJSON, | ||
batchTableBinary: batchTableBinary, | ||
message: message | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section may be able to be condensed by extracting the sections, and then verifying they are correct.
For example - https://github.com/AnalyticalGraphicsInc/3d-tiles-tools/blob/master/tools/lib/extractB3dm.js#L44-L46. You could do something like that and then verify the buffers are the correct size. Ideally the batch table extraction/validation could even go inline with the rest of the b3dm checking.
validator/lib/validateBatchTable.js
Outdated
@@ -0,0 +1,29 @@ | |||
'use strict'; | |||
var Cesium = require('cesium'); | |||
var Ajv = require('ajv'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add requires in alphabetical order.
validator/lib/validateBatchTable.js
Outdated
* Checks if provided buffers follow the batch table schema | ||
* | ||
* @param {Object} schema - A JSON object containing the schema for the batch table. | ||
* @param {Buffer} batchTableJSON - A buffer containing the JSON Header of a batch table |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSON Header of a batch table
-> batch table JSON
. It's not a buffer, right?
validator/lib/validateBatchTable.js
Outdated
* | ||
* @param {Object} schema - A JSON object containing the schema for the batch table. | ||
* @param {Buffer} batchTableJSON - A buffer containing the JSON Header of a batch table | ||
* @param {Buffer} batchTableBinary - A buffer containing the binary body of a batch table |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
binary body of a batch table
-> batch table binary
is simpler.
expect(validateB3dm(createB3dmTile()).result).toBe(true); | ||
}); | ||
|
||
it('validates b3dm tile with batch table JSON header matches spec', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The wording for these tests is awkward.
header.writeUInt32LE(0, 16); // batchTableBinaryByteLength | ||
header.writeUInt32LE(0, 20); // batchLength | ||
|
||
console.log('checking:\n' + header + '\n'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this.
header.writeUInt32LE(header.length + batchJSON.length, 8); // byteLength | ||
header.writeUInt32LE(batchJSON.length, 12); // batchTableJSONByteLength | ||
|
||
return Buffer.concat([header, batchJSON]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to avoid condensing the name, batchTableJSON
while longer is easier to follow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name of the function could also be createB3dmWithBatchTableJson
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also make sure to be consistent with Json
vs JSON
.
"id":[0,1,2], | ||
"longitude":[-1.3196595204101946,-1.3196567190670823,-1.3196687138763508], | ||
"height":[8,14,14] | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to wrap each key in quotes.
"height" : { | ||
"byteOffset" : 12, | ||
"componentType" : "UNSIGNED_INT", | ||
"type" : "SCALAR" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use single quotes for UNSIGNED_INT
and SCALAR
.
…icsInc/3d-tiles-tools into validate-batchTable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes look good overall, the tests are definitely shaping out nicely.
Make sure to double check everywhere that the validator is up to date with the updated b3dm format.
validator/lib/validateB3dm.js
Outdated
throw new DeveloperError('b3dm content must be of type buffer'); | ||
} | ||
|
||
if (content.length < 28) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleaner to save 28 as a headerByteLength
variable used here and below.
validator/lib/validateB3dm.js
Outdated
var batchTableJSONByteLength = content.readUInt32LE(20); | ||
var batchTableBinaryByteLength = content.readUInt32LE(24); | ||
if (batchTableJSONByteLength > 0) { | ||
var batchTableJSONHeader = content.slice(offset, offset + batchTableJSONByteLength); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just call this batchTableJSON
validator/lib/validateB3dm.js
Outdated
offset += batchTableJSONByteLength; | ||
var batchTableBinary = content.slice(offset, offset + batchTableBinaryByteLength); | ||
|
||
if((batchTableJSONHeader.length == batchTableJSONByteLength) && (batchTableBinary.length == batchTableBinaryByteLength)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use ===
.
validator/lib/validateB3dm.js
Outdated
if((batchTableJSONHeader.length == batchTableJSONByteLength) && (batchTableBinary.length == batchTableBinaryByteLength)) { | ||
var batchTableJSON = JSON.parse(batchTableJSONHeader.toString()); | ||
var validBatchTable = validateBatchTable(batchTableSchema, batchTableJSON, batchTableBinary); | ||
if (!validBatchTable.validation) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename validation
to result
to be consistent. Ultimately this way of passing the result will be changed, but still worth addressing.
validator/lib/validateB3dm.js
Outdated
return { | ||
result: false, | ||
message: 'b3dm has invalid batch table lengths' | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs semicolon.
"byteOffset" : 12, | ||
"componentType" : 'UNSIGNED_INT', | ||
"type" : 'SCALAR' | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine to do:
width : {
byteOffset : 12,
componentType : 'UNSIGNED_INT',
type : 'SCALAR'
}
validator/lib/validateBatchTable.js
Outdated
} | ||
|
||
var propertyByteLength = batchLength * componentTypeSize[componentType] * typeSize[numberOfComponents]; | ||
if (propertyByteLength + byteOffset > binaryBodyLength) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also worth validating that componentType
and type
are actually valid strings.
validator/lib/validateBatchTable.js
Outdated
* | ||
* @param {Object} schema - A JSON object containing the schema for the batch table. | ||
* @param {JSON} batchTableJSON - Batch table JSON | ||
* @param {Buffer} batchTableBinary - A buffer containing the batch table binary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since batchTableBinary
is optional, change to [batchTableBinary]
expect(validateBatchTable(batchTableSchema, batchTableJSON, batchTableBinary).validation).toBe(false); | ||
}); | ||
|
||
it('byteoffset out of bounds', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make these two slightly more descriptive - Binary property byteOffset out of bounds
var batchTable = createBatchTableBinary(); | ||
innerB3dmTile.writeUInt32LE(innerB3dmTile.length + batchTable.buffer.length, 8); // byteLength | ||
innerB3dmTile.writeUInt32LE(batchTable.batchTableJSONByteLength, 12); // batchTableJSONByteLength | ||
innerB3dmTile.writeUInt32LE(batchTable.batchTableBinaryByteLength, 16); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
12 and 16 are now offsets for the feature table
I've updated the old tests to the new b3dm specs and they pass when I run them. I'm not sure what else might be causing the checks to fail... |
You can ignore that, Travis is broken for this repo right now due to the directory structure. |
I'm late here, but thanks for all the work @JudyWeng! |
#32
I think I have the helper methods to extract and validate the batch table, but the loadJson method from Cesium returns a promise and I'm still working on learning about promises and how to use it in the individual tile validation files.