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

Mg/sort data array #36

Merged
merged 2 commits into from
Jun 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 47 additions & 5 deletions src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ export class BabylonPointCloudView extends BabylonBaseView {
var isTopo = false;
var isGltf = false;

var data!: {
[x: string]: any; X: number[], Y: number[], Z: number[], Red: number[], Green: number[], Blue: number[], GpsTime: number[], Classification: number[]};
var data: any

if (this.values.mode === "time"){
isTime = true;
Expand All @@ -128,12 +127,19 @@ export class BabylonPointCloudView extends BabylonBaseView {
}

if (this.values.source === "cloud"){
data = await loadPointCloud(this.values).then((results) => {return results});
//if (isTime = true){sort data by GpsTime}
var dataUnsorted = await loadPointCloud(this.values).then((results) => {return results});
if (isTime){
data = sortDataArrays(dataUnsorted);
}else{
data = dataUnsorted;
}
}else{
data = this.values.data;
}

console.log("data")
console.log(data)

const numCoords = data.X.length;
const gltfData = this.values.gltf_data;
const pointSize = this.values.point_size;
Expand Down Expand Up @@ -497,4 +503,40 @@ async function loadPointCloud(values: {name_space: string, array_name: string, b
return results
}

};
}

function sortDataArrays(data: any){

const GpsTime = data.GpsTime
const X = data.X
const Y = data.Y
const Z = data.Z
const Red = data.Red
const Green = data.Green
const Blue = data.Blue

const sortedData = sortArrays({GpsTime, X, Y, Z, Red, Green, Blue})

return sortedData;

}

function sortArrays(arrays: any, comparator = (a: number, b: number) => (a < b) ? -1 : (a > b) ? 1 : 0) {

const arrayKeys = Object.keys(arrays);
const [sortableArray] = Object.values(arrays) as any[];
const indexes = Object.keys(sortableArray);
const sortedIndexes = indexes.sort((a, b) => comparator(sortableArray[a], sortableArray[b]));

const sortByIndexes = (array: { [x: string]: any; }, sortedIndexes: any[]) => sortedIndexes.map(sortedIndex => array[sortedIndex]);

if (Array.isArray(arrays)) {
return arrayKeys.map((arrayIndex: string) => sortByIndexes(arrays[arrayIndex as any], sortedIndexes));
} else {
const sortedArrays: any = {};
arrayKeys.forEach((arrayKey) => {
sortedArrays[arrayKey] = sortByIndexes(arrays[arrayKey as any], sortedIndexes) as any;
});
return sortedArrays;
}
}