Skip to content

Commit

Permalink
refactor(parsers): move and rename parsers to a new parser directory
Browse files Browse the repository at this point in the history
Multiple classes are in charge of decoding file chunks. They were scattered into multiple directories and had different names : Loaders, Parsers, IoDrivers...
They are now all moved to a new src/Parser directory
This commit addresses first item of #695
  • Loading branch information
mbredif authored and peppsac committed Mar 27, 2018
1 parent a212dde commit 6324b66
Show file tree
Hide file tree
Showing 22 changed files with 54 additions and 54 deletions.
2 changes: 1 addition & 1 deletion examples/gpx.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
// Listen for globe full initialisation event
globeView.addEventListener(itowns.GLOBE_VIEW_EVENTS.GLOBE_INITIALIZED, function () {
console.info('Globe initialized');
itowns.GpxUtils.load('https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/ULTRA2009.gpx', globeView.referenceCrs).then(function (gpx) {
itowns.GpxParser.load('https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/ULTRA2009.gpx', globeView.referenceCrs).then(function (gpx) {
if (gpx) {
globeView.scene.add(gpx);
globeView.controls.setTilt(45, true);
Expand Down
12 changes: 6 additions & 6 deletions src/Core/Scheduler/Providers/3dTiles_Provider.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as THREE from 'three';
import B3dmLoader from '../../../Renderer/ThreeExtended/B3dmLoader';
import PntsLoader from '../../../Renderer/ThreeExtended/PntsLoader';
import B3dmParser from '../../../Parser/B3dmParser';
import PntsParser from '../../../Parser/PntsParser';
import Fetcher from './Fetcher';
import OBB from '../../../Renderer/ThreeExtended/OBB';
import Extent from '../../Geographic/Extent';
Expand Down Expand Up @@ -142,11 +142,11 @@ export function patchMaterialForLogDepthSupport(material) {
};
}

let b3dmLoader;
let b3dmParser;
let textDecoder;
function b3dmToMesh(data, layer, url) {
b3dmLoader = b3dmLoader || new B3dmLoader();
return b3dmLoader.parse(data, layer.asset.gltfUpAxis, url, textDecoder).then((result) => {
b3dmParser = b3dmParser || new B3dmParser();
return b3dmParser.parse(data, layer.asset.gltfUpAxis, url, textDecoder).then((result) => {
const init = function f_init(mesh) {
mesh.frustumCulled = false;
if (mesh.material) {
Expand Down Expand Up @@ -177,7 +177,7 @@ function b3dmToMesh(data, layer, url) {

function pntsParse(data) {
return new Promise((resolve) => {
resolve({ object3d: PntsLoader.parse(data, textDecoder).point });
resolve({ object3d: PntsParser.parse(data, textDecoder).point });
});
}

Expand Down
8 changes: 4 additions & 4 deletions src/Core/Scheduler/Providers/OGCWebServiceHelper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as THREE from 'three';
import Fetcher from './Fetcher';
import IoDriver_XBIL from './IoDriver_XBIL';
import XbilParser from '../../../Parser/XbilParser';
import Projection from '../../Geographic/Projection';
import Extent from '../../Geographic/Extent';

Expand All @@ -12,7 +12,7 @@ export const SIZE_TEXTURE_TILE = 256;
// Info : THREE.js have cache image https://github.com/mrdoob/three.js/blob/master/src/loaders/ImageLoader.js#L25
const cache = new Map();
const pending = new Map();
const ioDXBIL = new IoDriver_XBIL();
const XBIL = new XbilParser();
const projection = new Projection();

const getTextureFloat = function getTextureFloat(buffer) {
Expand All @@ -24,7 +24,7 @@ const getTextureFloat = function getTextureFloat(buffer) {
const tileCoord = new Extent('WMTS:WGS84G', 0, 0, 0);

export default {
ioDXBIL,
XBIL,
getColorTextureByUrl(url, networkOptions) {
if (cache.has(url)) {
return Promise.resolve(cache.get(url));
Expand Down Expand Up @@ -59,7 +59,7 @@ export default {
return pending.get(url);
}

const promiseXBil = ioDXBIL.read(url, networkOptions).then((result) => {
const promiseXBil = XBIL.read(url, networkOptions).then((result) => {
// TODO RGBA is needed for navigator with no support in texture float
// In RGBA elevation texture LinearFilter give some errors with nodata value.
// need to rewrite sample function in shader
Expand Down
8 changes: 4 additions & 4 deletions src/Core/Scheduler/Providers/PointCloudProvider.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as THREE from 'three';
import Fetcher from './Fetcher';
import PointCloudProcessing from '../../../Process/PointCloudProcessing';
import PotreeBinLoader from './PotreeBinLoader';
import PotreeCinLoader from './PotreeCinLoader';
import PotreeBinParser from '../../../Parser/PotreeBinParser';
import PotreeCinParser from '../../../Parser/PotreeCinParser';
import Picking from '../../Picking';

// Create an A(xis)A(ligned)B(ounding)B(ox) for the child `childIndex` of one aabb.
Expand Down Expand Up @@ -123,9 +123,9 @@ function addPickingAttribute(points) {
function loadPointFile(layer, url) {
return fetch(url, layer.fetchOptions).then(foo => foo.arrayBuffer()).then((ab) => {
if (layer.metadata.customBinFormat) {
return addPickingAttribute(PotreeCinLoader.parse(ab));
return addPickingAttribute(PotreeCinParser.parse(ab));
} else {
return addPickingAttribute(PotreeBinLoader.parse(ab));
return addPickingAttribute(PotreeBinParser.parse(ab));
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Scheduler/Providers/Raster_Provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as THREE from 'three';
import togeojson from 'togeojson';
import Extent from '../../Geographic/Extent';
import Feature2Texture from '../../../Renderer/ThreeExtended/Feature2Texture';
import GeoJSON2Features from '../../../Renderer/ThreeExtended/GeoJSON2Features';
import GeoJsonParser from '../../../Parser/GeoJsonParser';
import Fetcher from './Fetcher';

function getExtentFromGpxFile(file) {
Expand Down Expand Up @@ -104,7 +104,7 @@ export default {
}

if (geojson) {
return GeoJSON2Features.parse(parentCrs, geojson, layer.extent, options);
return GeoJsonParser.parse(parentCrs, geojson, layer.extent, options);
}
}).then((feature) => {
if (feature) {
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Scheduler/Providers/WFS_Provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import Extent from '../../Geographic/Extent';
import URLBuilder from './URLBuilder';
import Fetcher from './Fetcher';
import GeoJSON2Features from '../../../Renderer/ThreeExtended/GeoJSON2Features';
import GeoJsonParser from '../../../Parser/GeoJsonParser';
import Feature2Mesh from '../../../Renderer/ThreeExtended/Feature2Mesh';

const cache = new Map();
Expand Down Expand Up @@ -71,7 +71,7 @@ function getFeatures(crs, tile, layer) {

return Fetcher.json(urld, layer.networkOptions)
.then(
geojson => GeoJSON2Features.parse(crs, geojson, tile.extent, { filter: layer.filter }),
geojson => GeoJsonParser.parse(crs, geojson, tile.extent, { filter: layer.filter }),
(err) => {
// special handling for 400 errors, as it probably means the config is wrong
if (err.response.status == 400) {
Expand Down
2 changes: 1 addition & 1 deletion src/Core/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const VIEW_EVENTS = {
* @constructor
* @example
* // How add gpx object
* itowns.GpxUtils.load(url, viewer.referenceCrs).then((gpx) => {
* itowns.GpxParser.load(url, viewer.referenceCrs).then((gpx) => {
* if (gpx) {
* viewer.scene.add(gpx);
* }
Expand Down
4 changes: 2 additions & 2 deletions src/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ export { default as Extent } from './Core/Geographic/Extent';
export { GeometryLayer, ImageryLayers } from './Core/Layer/Layer';
export { STRATEGY_MIN_NETWORK_TRAFFIC, STRATEGY_GROUP, STRATEGY_PROGRESSIVE, STRATEGY_DICHOTOMY } from './Core/Layer/LayerUpdateStrategy';
export { default as GlobeView, GLOBE_VIEW_EVENTS, createGlobeLayer } from './Core/Prefab/GlobeView';
export { default as GpxUtils } from './Core/Scheduler/Providers/GpxUtils';
export { default as PlanarView, createPlanarLayer } from './Core/Prefab/PlanarView';
export { default as PanoramaView, createPanoramaLayer } from './Core/Prefab/PanoramaView';
export { default as Panorama } from './Core/Prefab/Panorama/Constants';
export { default as Fetcher } from './Core/Scheduler/Providers/Fetcher';
export { MAIN_LOOP_EVENTS } from './Core/MainLoop';
export { default as View } from './Core/View';
export { VIEW_EVENTS } from './Core/View';
export { default as GpxParser } from './Parser/GpxParser';
export { default as GeoJsonParser } from './Parser/GeoJsonParser';
export { process3dTilesNode, init3dTilesLayer, $3dTilesCulling, $3dTilesSubdivisionControl, pre3dTilesUpdate } from './Process/3dTilesProcessing';
export { default as FeatureProcessing } from './Process/FeatureProcessing';
export { updateLayeredMaterialNodeImagery, updateLayeredMaterialNodeElevation } from './Process/LayeredMaterialNodeProcessing';
Expand All @@ -22,7 +23,6 @@ export { default as Feature2Mesh } from './Renderer/ThreeExtended/Feature2Mesh';
export { default as FlyControls } from './Renderer/ThreeExtended/FlyControls';
export { default as FirstPersonControls } from './Renderer/ThreeExtended/FirstPersonControls';
export { default as PlanarControls } from './Renderer/ThreeExtended/PlanarControls';
export { default as GeoJSON2Features } from './Renderer/ThreeExtended/GeoJSON2Features';
export { default as FeaturesUtils } from './Renderer/ThreeExtended/FeaturesUtils';
export { CONTROL_EVENTS } from './Renderer/ThreeExtended/GlobeControls';
export { default as DEMUtils } from './utils/DEMUtils';
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as THREE from 'three';
import GLTFLoader from './GLTFLoader';
import LegacyGLTFLoader from './deprecated/LegacyGLTFLoader';
import LegacyGLTFLoader from './LegacyGLTFLoader';
import BatchTable from './BatchTable';

const matrixChangeUpVectorZtoY = (new THREE.Matrix4()).makeRotationX(Math.PI / 2);
// For gltf rotation
const matrixChangeUpVectorZtoX = (new THREE.Matrix4()).makeRotationZ(-Math.PI / 2);

function B3dmLoader() {
function B3dmParser() {
this.glTFLoader = new GLTFLoader();
this.LegacyGLTFLoader = new LegacyGLTFLoader();
}
Expand Down Expand Up @@ -46,7 +46,7 @@ function applyOptionalCesiumRTC(data, gltf, textDecoder) {
}
}

B3dmLoader.prototype.parse = function parse(buffer, gltfUpAxis, url, textDecoder) {
B3dmParser.prototype.parse = function parse(buffer, gltfUpAxis, url, textDecoder) {
if (!buffer) {
throw new Error('No array buffer provided.');
}
Expand Down Expand Up @@ -124,4 +124,4 @@ B3dmLoader.prototype.parse = function parse(buffer, gltfUpAxis, url, textDecoder
}
};

export default B3dmLoader;
export default B3dmParser;
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Class: FeatureToolBox
* Description:
*/
import Coordinates from '../../Core/Geographic/Coordinates';
import Extent from '../../Core/Geographic/Extent';
import Coordinates from '../Core/Geographic/Coordinates';
import Extent from '../Core/Geographic/Extent';

function readCRS(json) {
if (json.crs) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/**
* Generated On: 2016-07-07
* Class: GpxUtils
* Class: GpxParser
* Description: Parse Gpx file to get [lat, lon, alt]
*/

import * as THREE from 'three';
import Line from 'three.meshline';
import Fetcher from './Fetcher';
import Coordinates from '../../Geographic/Coordinates';
import Capabilities from '../../System/Capabilities';
import { patchMaterialForLogDepthSupport } from './3dTiles_Provider';
import Fetcher from '../Core/Scheduler/Providers/Fetcher';
import Coordinates from '../Core/Geographic/Coordinates';
import Capabilities from '../Core/System/Capabilities';
import { patchMaterialForLogDepthSupport } from '../Core/Scheduler/Providers/3dTiles_Provider';

function _gpxToWayPointsArray(gpxXML) {
return gpxXML.getElementsByTagName('wpt');
Expand Down Expand Up @@ -171,7 +171,7 @@ function _gpxToMesh(gpxXML, options = {}) {
}

export default {
/** @module gpxUtils */
/** @module GpxParser */
/** Load gpx file and convert to THREE.Mesh
* @function load
* @param {string} urlFile The url of gpx file
Expand All @@ -183,7 +183,7 @@ export default {
* @return {THREE.Mesh} Three.js Mesh see {@link https://threejs.org/docs/#api/objects/Mesh}
* @example
* // How add gpx object
* itowns.GpxUtils.load(url, viewer.referenceCrs).then((gpx) => {
* itowns.GpxParser.load(url, viewer.referenceCrs).then((gpx) => {
* if (gpx) {
* viewer.scene.add(gpx);
* viewer.notifyChange(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@

import JSZip from 'jszip';
import * as THREE from 'three';
import Coordinates from '../../Core/Geographic/Coordinates';
import Coordinates from '../Core/Geographic/Coordinates';

function KMZLoader() {
function KmzParser() {
this.colladaLoader = new THREE.ColladaLoader();
this.colladaLoader.options.convertUpAxis = true;
this.cache = [];
}

KMZLoader.prototype = Object.create(KMZLoader.prototype);
KmzParser.prototype = Object.create(KmzParser.prototype);

KMZLoader.prototype.constructor = KMZLoader;
KmzParser.prototype.constructor = KmzParser;

KMZLoader.prototype.parseCollada = function parseCollada(buffer) {
KmzParser.prototype.parseCollada = function parseCollada(buffer) {
var zip = new JSZip(buffer);
var collada;
var coordCarto;
Expand All @@ -40,7 +40,7 @@ KMZLoader.prototype.parseCollada = function parseCollada(buffer) {
return collada;
};

KMZLoader.prototype.load = function load(url) {
KmzParser.prototype.load = function load(url) {
return fetch(url).then((response) => {
if (response.status < 200 || response.status >= 300) {
throw new Error(`Error loading ${url}: status ${response.status}`);
Expand All @@ -49,4 +49,4 @@ KMZLoader.prototype.load = function load(url) {
}).then(buffer => this.parseCollada(buffer));
};

export default KMZLoader;
export default KmzParser;
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as THREE from 'three';
import PointsMaterial from '../../../Renderer/PointsMaterial';
import PointsMaterial from '../Renderer/PointsMaterial';

// Parse .bin PotreeConverter format
export default {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as THREE from 'three';
import PointsMaterial from '../../../Renderer/PointsMaterial';
import PointsMaterial from '../Renderer/PointsMaterial';

// Parse .cin PotreeConverter format (see https://github.com/peppsac/PotreeConverter/tree/custom_bin)
export default {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Fetcher from './Fetcher';
import Fetcher from '../Core/Scheduler/Providers/Fetcher';


var portableXBIL = function portableXBIL(buffer) {
Expand All @@ -9,10 +9,10 @@ var portableXBIL = function portableXBIL(buffer) {
};


function IoDriver_XBIL() {
function XbilParser() {
}

IoDriver_XBIL.prototype.computeMinMaxElevation = function computeMinMaxElevation(buffer, width, height, offsetScale) {
XbilParser.prototype.computeMinMaxElevation = function computeMinMaxElevation(buffer, width, height, offsetScale) {
let min = 1000000;
let max = -1000000;

Expand Down Expand Up @@ -44,7 +44,7 @@ IoDriver_XBIL.prototype.computeMinMaxElevation = function computeMinMaxElevation
return { min, max };
};

IoDriver_XBIL.prototype.parseXBil = function parseXBil(buffer, url) {
XbilParser.prototype.parseXBil = function parseXBil(buffer, url) {
if (!buffer) {
throw new Error('Error processing XBIL');
}
Expand All @@ -62,9 +62,9 @@ IoDriver_XBIL.prototype.parseXBil = function parseXBil(buffer, url) {
};


IoDriver_XBIL.prototype.read = function read(url, networkOptions) {
XbilParser.prototype.read = function read(url, networkOptions) {
return Fetcher.arrayBuffer(url, networkOptions).then(buffer => this.parseXBil(buffer, url));
};


export default IoDriver_XBIL;
export default XbilParser;
2 changes: 1 addition & 1 deletion src/Process/LayeredMaterialNodeProcessing.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function initNodeElevationTextureFromParent(node, parent, layer) {
// to use parent's min-max.
const useMinMaxFromParent = node.level - texture.coords.zoom > 6;
if (!useMinMaxFromParent) {
const { min, max } = OGCWebServiceHelper.ioDXBIL.computeMinMaxElevation(
const { min, max } = OGCWebServiceHelper.XBIL.computeMinMaxElevation(
texture.image.data,
SIZE_TEXTURE_TILE, SIZE_TEXTURE_TILE,
pitch);
Expand Down
4 changes: 2 additions & 2 deletions test/feature2mesh_unit_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as THREE from 'three';
import proj4 from 'proj4';
import GeoJSON2Features from '../src/Renderer/ThreeExtended/GeoJSON2Features';
import GeoJsonParser from '../src/Parser/GeoJsonParser';
import Feature2Mesh from '../src/Renderer/ThreeExtended/Feature2Mesh';
/* global describe, it */

Expand All @@ -11,7 +11,7 @@ proj4.defs('EPSG:3946',
'+proj=lcc +lat_1=45.25 +lat_2=46.75 +lat_0=46 +lon_0=3 +x_0=1700000 +y_0=5200000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs');

function parse() {
return GeoJSON2Features.parse(
return GeoJsonParser.parse(
'EPSG:3946', geojson, undefined,
{ buildExtent: true, crsIn: 'EPSG:3946' });
}
Expand Down
2 changes: 1 addition & 1 deletion test/featureUtils_unit_test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import GeoJSON2Features from '../src/Renderer/ThreeExtended/GeoJSON2Features';
import GeoJSON2Features from '../src/Parser/GeoJsonParser';
import FeaturesUtils from '../src/Renderer/ThreeExtended/FeaturesUtils';
import Coordinates from '../src/Core/Geographic/Coordinates';
/* global describe, it */
Expand Down

0 comments on commit 6324b66

Please sign in to comment.