mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-23 16:15:36 +08:00
Serializing JSON code for drawable objects (and some documentation) (#222)
* some comments and starting serializing comments. on plane w/o formatter * fixing pylint and black * removed changes in file * revert file * addressing comments * remove abstract Co-authored-by: Ethan Weber <ethanweber@Ethans-MacBook-Pro.local>
This commit is contained in:
1 parent
44a7fa288c
commit
d13a766b9e
13 files changed
+240
-106
No files matched your search
+39
-11
@@ -17,7 +17,7 @@ Dataset input structures.
|
||||
"""
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import List, Optional
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
import torch
|
||||
from torchtyping import TensorType
|
||||
@@ -27,7 +27,7 @@ from nerfactory.cameras.rays import RayBundle
|
||||
|
||||
@dataclass
|
||||
class PointCloud:
|
||||
"""_summary_"""
|
||||
"""Dataclass for a point cloud."""
|
||||
|
||||
xyz: TensorType["num_points", 3] = None
|
||||
rgb: TensorType["num_points", 3] = None
|
||||
@@ -35,22 +35,24 @@ class PointCloud:
|
||||
|
||||
@dataclass
|
||||
class Semantics:
|
||||
"""_summary_"""
|
||||
"""Dataclass for semantic labels."""
|
||||
|
||||
stuff_classes: List[str] = None
|
||||
stuff_colors: List[List[int]] = None
|
||||
stuff_filenames: List[str] = None
|
||||
thing_classes: List[str] = None
|
||||
thing_colors: List[List[int]] = None
|
||||
thing_filenames: List[str] = None
|
||||
stuff_classes: Optional[List[str]] = None
|
||||
stuff_colors: Optional[List[str]] = None
|
||||
stuff_filenames: Optional[List[str]] = None
|
||||
thing_classes: Optional[List[str]] = None
|
||||
thing_colors: Optional[List[str]] = None
|
||||
thing_filenames: Optional[List[str]] = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class SceneBounds:
|
||||
"""Data to represent the scene bounds.
|
||||
|
||||
aabb: axis-aligned bounding box
|
||||
aabb[0] is the minimum (x,y,z) point. aabb[1] is the maximum (x,y,z) point.
|
||||
Attributes:
|
||||
aabb: axis-aligned bounding box.
|
||||
aabb[0] is the minimum (x,y,z) point.
|
||||
aabb[1] is the maximum (x,y,z) point.
|
||||
"""
|
||||
|
||||
aabb: TensorType[2, 3] = None
|
||||
@@ -71,6 +73,32 @@ class SceneBounds:
|
||||
about the origin."""
|
||||
return SceneBounds(aabb=(self.aabb - self.get_center()) * scale_factor)
|
||||
|
||||
@staticmethod
|
||||
def get_normalized_positions(positions: TensorType[..., 3], aabb: TensorType[2, 3]):
|
||||
"""Return normalized positions in range [0, 1] based on the aabb axis-aligned bounding box.
|
||||
|
||||
Args:
|
||||
positions: the xyz positions
|
||||
aabb: the axis-aligned bounding box
|
||||
|
||||
Returns:
|
||||
positions that are normalized into the range [0, 1].
|
||||
"""
|
||||
aabb_lengths = aabb[1] - aabb[0]
|
||||
normalized_positions = (positions - aabb[0]) / aabb_lengths
|
||||
return normalized_positions
|
||||
|
||||
def to_json(self) -> Dict:
|
||||
"""Returns a json object from the Python object."""
|
||||
return {"type": "aabb", "min_point": self.aabb[0].tolist(), "max_point": self.aabb[1].tolist()}
|
||||
|
||||
@staticmethod
|
||||
def from_json(json_: Dict) -> "SceneBounds":
|
||||
"""Returns the an instance of SceneBounds from a json dictionary."""
|
||||
assert json_["type"] == "aabb"
|
||||
aabb = torch.tensor([json_[0], json_[1]])
|
||||
return SceneBounds(aabb=aabb)
|
||||
|
||||
|
||||
@dataclass
|
||||
class DatasetInputs:
|
||||
|
||||
Reference in new issue
Block a user