Skip to content
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

Merged
merged 19 commits into from
Jul 1, 2017
Merged

validating batch table #41

merged 19 commits into from
Jul 1, 2017

Conversation

JudyWeng
Copy link
Contributor

#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.

@pjcozzi
Copy link
Contributor

pjcozzi commented Jan 5, 2017

@lilleyse will you be able to look at this soon?

@lilleyse
Copy link
Contributor

lilleyse commented Jan 6, 2017

If I remember correctly, the main things to address here were:

  • Move the batch table JSON and batch table binary extraction to the individual validateB3dm, validateI3dm, files. While there will be some duplicate code, I think it is worth it just so each tile type is self-contained.
  • Avoid loading the batch table schema in validateBatchTable, since it would be much nicer to avoid promises entirely here. Rather it could be loaded right from the start in in validateTileset and eventually passed along to each tile in some sort of schemas object.

@pjcozzi
Copy link
Contributor

pjcozzi commented Jan 15, 2017

@JudyWeng any update here as well?

@JudyWeng
Copy link
Contributor Author

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) {
Copy link
Contributor Author

@JudyWeng JudyWeng Feb 13, 2017

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lilleyse any thoughts here?

Copy link
Contributor

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.

@JudyWeng
Copy link
Contributor Author

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.

@lilleyse
Copy link
Contributor

I'll look at both later today.

Copy link
Contributor

@lilleyse lilleyse left a 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.

throw new DeveloperError('b3dm content must be of type buffer');
}

if(content.length < 2) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be 24?

Copy link
Contributor

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.

batchTableJSON: batchTableJSON,
batchTableBinary: batchTableBinary,
message: message
};
Copy link
Contributor

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.

@@ -0,0 +1,29 @@
'use strict';
var Cesium = require('cesium');
var Ajv = require('ajv');
Copy link
Contributor

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.

* 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
Copy link
Contributor

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?

*
* @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
Copy link
Contributor

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() {
Copy link
Contributor

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');
Copy link
Contributor

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]);
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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]
};
Copy link
Contributor

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"
Copy link
Contributor

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.

Copy link
Contributor

@lilleyse lilleyse left a 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.

throw new DeveloperError('b3dm content must be of type buffer');
}

if (content.length < 28) {
Copy link
Contributor

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.

var batchTableJSONByteLength = content.readUInt32LE(20);
var batchTableBinaryByteLength = content.readUInt32LE(24);
if (batchTableJSONByteLength > 0) {
var batchTableJSONHeader = content.slice(offset, offset + batchTableJSONByteLength);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just call this batchTableJSON

offset += batchTableJSONByteLength;
var batchTableBinary = content.slice(offset, offset + batchTableBinaryByteLength);

if((batchTableJSONHeader.length == batchTableJSONByteLength) && (batchTableBinary.length == batchTableBinaryByteLength)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ===.

if((batchTableJSONHeader.length == batchTableJSONByteLength) && (batchTableBinary.length == batchTableBinaryByteLength)) {
var batchTableJSON = JSON.parse(batchTableJSONHeader.toString());
var validBatchTable = validateBatchTable(batchTableSchema, batchTableJSON, batchTableBinary);
if (!validBatchTable.validation) {
Copy link
Contributor

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.

return {
result: false,
message: 'b3dm has invalid batch table lengths'
}
Copy link
Contributor

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'
}
Copy link
Contributor

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'
}

}

var propertyByteLength = batchLength * componentTypeSize[componentType] * typeSize[numberOfComponents];
if (propertyByteLength + byteOffset > binaryBodyLength) {
Copy link
Contributor

@lilleyse lilleyse Apr 14, 2017

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.

*
* @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
Copy link
Contributor

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() {
Copy link
Contributor

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);
Copy link
Contributor

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

@JudyWeng
Copy link
Contributor Author

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...

@lilleyse
Copy link
Contributor

You can ignore that, Travis is broken for this repo right now due to the directory structure.

@lilleyse
Copy link
Contributor

lilleyse commented Jul 1, 2017

I'm late here, but thanks for all the work @JudyWeng!

@lilleyse lilleyse merged commit 2abb1fa into validator-master Jul 1, 2017
@lilleyse lilleyse deleted the validate-batchTable branch July 1, 2017 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants