Skip to content

Commit

Permalink
Semantic change: rename Tile to TileContent
Browse files Browse the repository at this point in the history
In 3dtiles semantic, the *Tile* is the json containing the
geometricError, boundingVolume, content etc... And the *content* is the
tile binary content: b3dm, i3dm and such.
  • Loading branch information
autra committed Dec 2, 2019
1 parent ec12cdf commit 4648202
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 66 deletions.
34 changes: 17 additions & 17 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ Generic Tile
The py3dtiles module provides some classes to fit into the
specification:

- *Tile* with a header *TileHeader* and a body *TileBody*
- *TileContent* with a header *TileHeader* and a body *TileBody*
- *TileHeader* represents the metadata of the tile (magic value, version, ...)
- *TileBody* contains varying semantic and geometric data depending on the the tile's type

Moreover, a utility class *TileReader* is available to read a tile
Moreover, a utility class *TileContentReader* is available to read a tile
file as well as a simple command line tool to retrieve basic information
about a tile: **py3dtiles\_info**. We also provide a utility to generate a
tileset from a list of 3D models in WKB format or stored in a postGIS table.
Expand All @@ -32,20 +32,20 @@ In the current implementation, the *Pnts* class only contains a *FeatureTable*

.. code-block:: python
>>> from py3dtiles import TileReader
>>> from py3dtiles import TileContentReader
>>> from py3dtiles import Pnts
>>>
>>> filename = 'tests/pointCloudRGB.pnts'
>>>
>>> # read the file
>>> tile = TileReader().read_file(filename)
>>> tile_content = TileContentReader.read_file(filename)
>>>
>>> # tile is an instance of the Tile class
>>> tile
<py3dtiles.tile.Tile>
>>> # tile_content is an instance of the TileContent class
>>> tile_content
<py3dtiles.tile.TileContent>
>>>
>>> # extract information about the tile header
>>> th = tile.header
>>> # extract information about the tile_content header
>>> th = tile_content.header
>>> th
<py3dtiles.tile.TileHeader>
>>> th.magic_value
Expand All @@ -54,7 +54,7 @@ In the current implementation, the *Pnts* class only contains a *FeatureTable*
15176
>>>
>>> # extract the feature table
>>> ft = tile.body.feature_table
>>> ft = tile_content.body.feature_table
>>> ft
<py3dtiles.feature_table.FeatureTable
>>>
Expand Down Expand Up @@ -116,17 +116,17 @@ https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/TileFormats/Batche

.. code-block:: python
>>> from py3dtiles import TileReader
>>> from py3dtiles import TileContentReader
>>> from py3dtiles import B3dm
>>>
>>> filename = 'tests/dragon_low.b3dm'
>>>
>>> # read the file
>>> tile = TileReader().read_file(filename)
>>> tile_content = TileContentReader.read_file(filename)
>>>
>>> # tile is an instance of the Tile class
>>> tile
<py3dtiles.tile.Tile>
>>> # tile_content is an instance of the TileContent class
>>> tile_content
<py3dtiles.tile.TileContent>
>>>
>>> # extract information about the tile header
>>> th = tile.header
Expand All @@ -138,7 +138,7 @@ https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/TileFormats/Batche
47246
>>>
>>> # extract the glTF
>>> gltf = tile.body.glTF
>>> gltf = tile_content.body.glTF
>>> gltf
<py3dtiles.gltf.GlTF>
>>>
Expand Down Expand Up @@ -181,7 +181,7 @@ file containing polyhedralsurfaces or multipolygons.
>>> geometry = { 'position': positions, 'normal': normals, 'bbox': box }
>>> gltf = GlTF.from_binary_arrays([geometry], transform)
>>>
>>> # create a b3dm tile directly from the glTF.
>>> # create a b3dm tile_content directly from the glTF.
>>> t = B3dm.from_glTF(glTF)
>>>
>>> # to save our tile as a .b3dm file
Expand Down
2 changes: 1 addition & 1 deletion docs/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Command line usage
info
~~~~

Here is an example on how to retrieve basic information about a tile, in this
Here is an example on how to retrieve basic information about a tile binary content, in this
case *pointCloudRGB.pnts*:

.. code-block:: shell
Expand Down
6 changes: 3 additions & 3 deletions py3dtiles/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

from .utils import TileReader, convert_to_ecef
from .tile import Tile
from .utils import TileContentReader, convert_to_ecef
from .tile import TileContent
from .feature_table import Feature
from .gltf import GlTF
from .pnts import Pnts
Expand All @@ -10,5 +10,5 @@
from .wkb_utils import TriangleSoup

__version__ = '1.1.0'
__all__ = ['TileReader', 'convert_to_ecef', 'Tile', 'Feature', 'GlTF', 'Pnts',
__all__ = ['TileContentReader', 'convert_to_ecef', 'TileContent', 'Feature', 'GlTF', 'Pnts',
'B3dm', 'BatchTable', 'TriangleSoup']
16 changes: 8 additions & 8 deletions py3dtiles/b3dm.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# -*- coding: utf-8 -*-
# coding: utf-8
import struct
import numpy as np

from .tile import Tile, TileHeader, TileBody, TileType
from .tile import TileContent, TileHeader, TileBody, TileType
from .gltf import GlTF
from .batch_table import BatchTable


class B3dm(Tile):
class B3dm(TileContent):

@staticmethod
def from_glTF(gltf, bt=None):
Expand All @@ -22,7 +22,7 @@ def from_glTF(gltf, bt=None):
Returns
-------
tile : Tile
tile : TileContent
"""

tb = B3dmBody()
Expand All @@ -32,7 +32,7 @@ def from_glTF(gltf, bt=None):
th = B3dmHeader()
th.sync(tb)

t = Tile()
t = TileContent()
t.body = tb
t.header = th

Expand All @@ -47,7 +47,7 @@ def from_array(array):
Returns
-------
t : Tile
t : TileContent
"""

# build tile header
Expand All @@ -62,8 +62,8 @@ def from_array(array):
- B3dmHeader.BYTELENGTH])
b = B3dmBody.from_array(h, b_arr)

# build Tile with header and body
t = Tile()
# build TileContent with header and body
t = TileContent()
t.header = h
t.body = b

Expand Down
10 changes: 5 additions & 5 deletions py3dtiles/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from py3dtiles.points.transformations import rotation_matrix, angle_between_vectors, vector_product, inverse_matrix, scale_matrix, translation_matrix
from py3dtiles.points.utils import compute_spacing, name_to_filename
from py3dtiles.points.node import Node
from py3dtiles import TileReader
from py3dtiles import TileContentReader
from py3dtiles.points.shared_node_store import SharedNodeStore
import py3dtiles.points.task.las_reader as las_reader
import py3dtiles.points.task.xyz_reader as xyz_reader
Expand All @@ -41,11 +41,11 @@ def write_tileset(in_folder, out_folder, octree_metadata, offset, scale, project
for child in ['0', '1', '2', '3', '4', '5', '6', '7']:
ondisk_tile = name_to_filename(out_folder, child.encode('ascii'), '.pnts')
if os.path.exists(ondisk_tile):
tile = TileReader().read_file(ondisk_tile)
fth = tile.body.feature_table.header
xyz = tile.body.feature_table.body.positions_arr.view(np.float32).reshape((fth.points_length, 3))
tile_content = TileContentReader.read_file(ondisk_tile)
fth = tile_content.body.feature_table.header
xyz = tile_content.body.feature_table.body.positions_arr.view(np.float32).reshape((fth.points_length, 3))
if include_rgb:
rgb = tile.body.feature_table.body.colors_arr.reshape((fth.points_length, 3))
rgb = tile_content.body.feature_table.body.colors_arr.reshape((fth.points_length, 3))
else:
rgb = np.zeros(xyz.shape, dtype=np.uint8)

Expand Down
4 changes: 2 additions & 2 deletions py3dtiles/info.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from py3dtiles import TileReader
from py3dtiles import TileContentReader


def print_pnts_info(tile):
Expand Down Expand Up @@ -53,7 +53,7 @@ def print_b3dm_info(tile):


def main(args):
tile = TileReader().read_file(args.filename)
tile = TileContentReader.read_file(args.filename)
magic = tile.header.magic_value

if magic == "pnts":
Expand Down
4 changes: 2 additions & 2 deletions py3dtiles/merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import numpy as np
import json
from py3dtiles import TileReader
from py3dtiles import TileContentReader
from py3dtiles.points.utils import split_aabb
from py3dtiles.points.transformations import inverse_matrix
from py3dtiles.points.task.pnts_writer import points_to_pnts
Expand All @@ -16,7 +16,7 @@ def _get_root_tile(tileset, filename):
folder,
tileset['root']['content']['uri'])

return TileReader().read_file(pnts_filename)
return TileContentReader.read_file(pnts_filename)


def _get_root_transform(tileset):
Expand Down
14 changes: 7 additions & 7 deletions py3dtiles/pnts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import struct
import numpy as np

from .tile import Tile, TileHeader, TileBody, TileType
from .tile import TileContent, TileHeader, TileBody, TileType
from .feature_table import FeatureTable


class Pnts(Tile):
class Pnts(TileContent):

@staticmethod
def from_features(pdtype, cdtype, features):
Expand All @@ -20,7 +20,7 @@ def from_features(pdtype, cdtype, features):
Returns
-------
tile : Tile
tile : TileContent
"""

ft = FeatureTable.from_features(pdtype, cdtype, features)
Expand All @@ -30,7 +30,7 @@ def from_features(pdtype, cdtype, features):

th = PntsHeader()

t = Tile()
t = TileContent()
t.body = tb
t.header = th

Expand All @@ -45,7 +45,7 @@ def from_array(array):
Returns
-------
t : Tile
t : TileContent
"""

# build tile header
Expand All @@ -60,8 +60,8 @@ def from_array(array):
b_arr = array[PntsHeader.BYTELENGTH:PntsHeader.BYTELENGTH + b_len]
b = PntsBody.from_array(h, b_arr)

# build Tile with header and body
t = Tile()
# build TileContent with header and body
t = TileContent()
t.header = h
t.body = b

Expand Down
6 changes: 3 additions & 3 deletions py3dtiles/points/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import json

from py3dtiles import TileReader
from py3dtiles import TileContentReader
from py3dtiles.feature_table import SemanticPoint
from py3dtiles.points.utils import name_to_filename, node_from_name, SubdivisionType, aabb_size_to_subdivision_type
from py3dtiles.points.points_grid import Grid
Expand Down Expand Up @@ -194,7 +194,7 @@ def to_tileset(executor, name, parent_aabb, parent_spacing, folder, scale):
# - computing the real AABB (instead of the one based on the octree)
# - merging this tile's small (<100 points) children
if os.path.exists(ondisk_tile):
tile = TileReader().read_file(ondisk_tile)
tile = TileContentReader.read_file(ondisk_tile)
fth = tile.body.feature_table.header
xyz = tile.body.feature_table.body.positions_arr
if fth.colors != SemanticPoint.NONE:
Expand Down Expand Up @@ -222,7 +222,7 @@ def to_tileset(executor, name, parent_aabb, parent_spacing, folder, scale):
# See if we should merge this child in tile
if xyz is not None:
# Read pnts content
tile = TileReader().read_file(child_ondisk_tile)
tile = TileContentReader.read_file(child_ondisk_tile)
fth = tile.body.feature_table.header

# If this child is small enough, merge in the current tile
Expand Down
2 changes: 1 addition & 1 deletion py3dtiles/points/task/pnts_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def points_to_pnts(name, points, out_folder, include_rgb):
body = py3dtiles.pnts.PntsBody()
body.feature_table = ft

tile = py3dtiles.tile.Tile()
tile = py3dtiles.tile.TileContent()
tile.body = body
tile.header = py3dtiles.pnts.PntsHeader()
tile.header.sync(body)
Expand Down
2 changes: 1 addition & 1 deletion py3dtiles/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from abc import ABC, abstractmethod


class Tile(ABC):
class TileContent(ABC):

def __init__(self):
self.header = None
Expand Down
10 changes: 6 additions & 4 deletions py3dtiles/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ def convert_to_ecef(x, y, z, epsg_input):
return pyproj.transform(inp, outp, x, y, z)


class TileReader(object):
class TileContentReader(object):

def read_file(self, filename):
@staticmethod
def read_file(filename):
with open(filename, 'rb') as f:
data = f.read()
arr = np.frombuffer(data, dtype=np.uint8)
return self.read_array(arr)
return TileContentReader.read_array(arr)
return None

def read_array(self, array):
@staticmethod
def read_array(array):
magic = ''.join([c.decode('UTF-8') for c in array[0:4].view('c')])
if magic == 'pnts':
return Pnts.from_array(array)
Expand Down

0 comments on commit 4648202

Please sign in to comment.