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/refactor ts classes #30

Merged
merged 2 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pybabylonjs/babylonjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def set_defaults(validator, properties, instance, schema):
"img_width": {"type": "number"},
"img_height": {"type": "number"},
},
"required": ["xy_bbox", "img_width"],
"required": ["xy_bbox"],
}


Expand Down
27 changes: 23 additions & 4 deletions pybabylonjs/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ def numpy_to_binary(arr):
img = ((img - np.min(img)) / (np.max(img) - np.min(img))) * 255
binary_image = numpy_to_binary(img)

[img_height, img_width] = np.shape(img)

return dict(data=binary_image, img_width=img_width, img_height=img_height)
return dict(data=binary_image)


def create_mapbox_image(data: dict, **kwargs):
Expand All @@ -107,8 +105,25 @@ def create_mapbox_image(data: dict, **kwargs):
bbox = BoundingBox(
data["X"].min(), data["Y"].min(), data["X"].max(), data["Y"].max()
)

dst_bbox = transform_bounds(data_crs, dst_crs, *bbox)

print(bbox)
print(dst_bbox)

w = bbox[2] - bbox[0]
h = bbox[3] - bbox[1]

if w > h:
ww = 1280
hh = int(h / w * 1280)
elif h > w:
hh = 1280
ww = int(w / h * 1280)

print(ww)
print(hh)

f = requests.get(
(
"https://api.mapbox.com/styles/v1/mapbox/"
Expand All @@ -121,7 +136,11 @@ def create_mapbox_image(data: dict, **kwargs):
+ str(dst_bbox[2])
+ ","
+ str(dst_bbox[3])
+ "]/1280x1280?access_token="
+ "]/"
+ str(ww)
+ "x"
+ str(hh)
+ "?access_token="
+ mbtoken
)
)
Expand Down
11 changes: 7 additions & 4 deletions src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ export class BabylonPointCloudView extends BabylonBaseView {
const ymin = data.Y.reduce((accum: number, currentNumber: number) => Math.min(accum, currentNumber));
const ymax = data.Y.reduce((accum: number, currentNumber: number) => Math.max(accum, currentNumber));


if (isClass) {
var pcs = new PointsCloudSystem('pcs', pointSize, scene, {
updatable: isClass
Expand Down Expand Up @@ -405,8 +404,7 @@ export class BabylonImageView extends BabylonBaseView {
protected async createScene(): Promise<Scene> {
return super.createScene().then( ( scene ) => {
const data = this.values.data;
const img_height = this.values.img_height;
const img_width = this.values.img_width;
const bbox = this.values.xy_bbox;

scene.createDefaultCameraOrLight(true, true, true);
scene.clearColor = new Color4(0.95, 0.94, 0.92, 1);
Expand All @@ -422,7 +420,12 @@ export class BabylonImageView extends BabylonBaseView {
groundMaterial.specularColor = new Color3(0.5, 0.5, 0.5);
groundMaterial.specularPower = 32;

const ground = MeshBuilder.CreateGround("ground", {height: img_height*0.005, width: img_width*0.005, subdivisions: 16}, scene);
const xmin = bbox[0];
const xmax = bbox[1];
const ymin = bbox[2];
const ymax = bbox[3];

const ground = MeshBuilder.CreateGround("ground", {height: (xmax-xmin)*0.005, width: (ymax-ymin)*0.005, subdivisions: 36}, scene);
ground.material = groundMaterial;

let camera = scene.activeCamera as ArcRotateCamera;
Expand Down