Giter Site home page Giter Site logo

kylebarron / quantized-mesh-encoder Goto Github PK

View Code? Open in Web Editor NEW
80.0 4.0 6.0 6.5 MB

A fast Python Quantized Mesh encoder

Home Page: https://kylebarron.dev/quantized-mesh-encoder

License: MIT License

Python 63.32% HTML 3.64% CSS 1.61% JavaScript 27.24% Cython 4.18%
terrain-mesh-generator cesium deck-gl terrain quantized-mesh mesh mesh-processing

quantized-mesh-encoder's Issues

Example demo is not working properly

Hi @kylebarron,
I can't visualize proper your example demo: https://kylebarron.dev/quantized-mesh-encoder/

This is what I see:
image

Looks like it's related to CORS

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at 
https://us-east-1-lambda.kylebarron.dev/dem/mesh/13/1507/2820.terrain?url=terrarium&mesh_max_error=9.41&mesh_algorithm=pydelatin&flip_y=true. 
(Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 530.

Check winding order of input triangles

It looks like (py)martini creates a mesh with vertices (at least sometimes) in clockwise order, while the Quantized Mesh spec requires counter-clockwise winding order.

e.g. here are the first three 2D vertices, and it looks like they define a clockwise triangle

image

So I should add an option, probably True by default, that checks the input geometries and flips the order of indices if the triangle is in clockwise winding order.

It looks like it shouldn't actually be too slow to check, though it might be best in Cython... not sure if I can vectorize it easily

This might solve #9 , #11

Finish ritter method for bounding sphere

Currently I only have the "naive" method of finding an axis-aligned bounding box, then finding the sphere from that box.

It would be good to finish the ritter method, then to take the minimum of the two of them.

References:

Vertex normals

Optionally compute vertex normals extension. There's two parts:

Normal Generation

Based on the quantized-mesh-tile implementation, essentially for every vertex you look at all the triangles that touch it. For each triangle, compute its normal, and then average the normals of the touching triangles to find each per-vertex normal.

I think that to make it performant, you'd want to first compute all the normals of the triangles. And then you can use that array of normals somehow as a lookup table, so that you can find all the triangles per vertex at once, and then average within the axis...

Normal Encoding

Quantizing and encoding each x, y, z 96-bit floating point unit vector into an x,y 16-bit representation.

References

Comparing deck.gl rendering vs maptiler

image

url:
https://api.maptiler.com/tiles/terrain-quantized-mesh/13/3090/5737.terrain?key=...

bounds:
-112.08251953125,
36.0791015625,
-112.1044921875,
36.057128906249986

x, y, level = 3090, 5737, 13

import numpy as np
self =GeographicTilingScheme()
class GeographicTilingScheme:
    def __init__(self):
        self._numberOfLevelZeroTilesX = 2
        self._numberOfLevelZeroTilesY = 1
        self._rectangle = (-np.pi, -np.pi/2, np.pi, np.pi/2)

    def getNumberOfXTilesAtLevel(self, level):
        """
        Gets the total number of tiles in the X direction at a specified level-of-detail

         @param {Number} level The level-of-detail.
         @returns {Number} The number of tiles in the X direction at the given level.

        """
        return self._numberOfLevelZeroTilesX << level

    def getNumberOfYTilesAtLevel(self, level):
        """
        Gets the total number of tiles in the Y direction at a specified level-of-detail.

         @param {Number} level The level-of-detail.
         @returns {Number} The number of tiles in the Y direction at the given level.

        """
        return self._numberOfLevelZeroTilesY << level

    def tileXYToRectangle(self, x, y, level):
        rectangle = self._rectangle

        xTiles = self.getNumberOfXTilesAtLevel(level)
        yTiles = self.getNumberOfYTilesAtLevel(level)

        width = rectangle[2] - rectangle[0]
        xTileWidth = width / xTiles
        west = x * xTileWidth + rectangle[0]
        east = (x + 1) * xTileWidth + rectangle[0]

        height = rectangle[3] - rectangle[1]
        yTileHeight = height / yTiles
        north = rectangle[3] - y * yTileHeight
        south = rectangle[3] - (y + 1) * yTileHeight

        return np.array([east, south, west, north])

    def tileXYToNativeRectangle(self, x, y, level):
        """
        Converts tile x, y coordinates and level to a rectangle expressed in the native coordinates
        of the tiling scheme.

        Args:
            - x: The integer x coordinate of the tile.
            - y: The integer y coordinate of the tile.
            - level: level The tile level-of-detail.  Zero is the least detailed.
        """
        return np.degrees(self.tileXYToRectangle(x, y, level))

from shapely.geometry import box
bounds = list(np.degrees(self.tileXYToRectangle(x, y, level)))
bounds[1] = np.abs(bounds[1])
bounds[3] = np.abs(bounds[3])

print(bounds)
g = box(bounds[0], bounds[3], bounds[2], bounds[1])
from keplergl_cli import Visualize
g.exterior.coords
Visualize(g)
type(g)
g.exterior.coords
box(*np.degrees(self.tileXYToRectangle(x, y, level)))

Allow indices to be a 2d array

e.g. pydelatin currently returns a 2d array of shape (-1, 3) (which is sensible) but encode_indices expects a 1d array.

You should also cast to np.uint32, the data type expected by the cython encode_indices implementation.

You should also use .astype(np.uint32, casting='safe') so that an error would be produced if the data can't be transformed effectively.

- change to onViewportLoad to align with Tile3DLayer

// TODO - change to onViewportLoad to align with Tile3DLayer
onViewportLoad: {type: 'function', optional: true, value: null, compare: false},
onTileLoad: {type: 'function', value: tile => {}, compare: false},
// eslint-disable-next-line
onTileError: {type: 'function', value: err => console.error(err), compare: false},
extent: {type: 'array', optional: true, value: null, compare: true},


This issue was generated by todo based on a TODO comment in 204bcfc. It's been assigned to @kylebarron because they committed the code.

Water mask encoding (not generation)

I don't want to add code to generate a water mask, since you can't assume elevations < 0 are ocean. But you could add an argument to encode to allow a user to pass a pregenerated water mask.

Check triangleIndices

This is decoded with quantized-mesh-decoder in js:
image

The triangleIndices looks a little suspect. Especially since there are two zeros in a row.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.