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

add viewer size #151

Merged
merged 2 commits into from
May 21, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions docs/Rotation.html

Large diffs are not rendered by default.

35 changes: 21 additions & 14 deletions docs/Transform.html

Large diffs are not rendered by default.

136 changes: 92 additions & 44 deletions docs/Vector.html

Large diffs are not rendered by default.

83 changes: 49 additions & 34 deletions docs/Vector3.html

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions docs/index.html

Large diffs are not rendered by default.

24 changes: 21 additions & 3 deletions notebooks/Vector.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@
"outputs": [],
"source": [
"import py3d\n",
"py3d.Vector([[1,2,3],[4,5,6]], columns=[\"t\",\"x\",\"y\"]).to_csv(\"tmp.csv\")"
"py3d.Vector([[1,2,3],[4,5,6]], columns=[\"t\",\"x\",\"y\"]).to_csv(\"with_cols.csv\")\n",
"py3d.Vector([[7,8.4,9],[-1,-2,-3]]).to_csv(\"no_cols.csv\")"
]
},
{
Expand All @@ -360,8 +361,18 @@
"outputs": [],
"source": [
"import py3d\n",
"a=py3d.read_csv(\"tmp.csv\")\n",
"a[[\"t\",\"x\"]]"
"a=py3d.read_csv(\"with_cols.csv\", header=1)\n",
"a[\"t\",\"x\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import py3d\n",
"py3d.read_csv(\"no_cols.csv\")"
]
},
{
Expand Down Expand Up @@ -491,6 +502,13 @@
"print(vertices)\n",
"mesh"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
12 changes: 8 additions & 4 deletions py3d/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def __init__(self) -> None:
self.viewpoint = None
self.lookat = None
self.up = None
self.size = None

def __render_args__(self, t, **args):
t = round(t, 3)
Expand All @@ -54,15 +55,17 @@ def _repr_html_(self):
self.viewpoint = None
self.lookat = None
self.up = None
self.size = None
return html

def show(self, viewpoint=None, lookat=None, up=None, inplace=True, in_jupyter=True, name="py3d", port=9871):
def show(self, viewpoint=None, lookat=None, up=None, inplace=True, size=[], in_jupyter=True, name="py3d", port=9871):
'''
same as py3d.show
'''
self.viewpoint = viewpoint
self.lookat = lookat
self.up = up
self.size = size
if in_jupyter:
if inplace:
clear_output(True)
Expand Down Expand Up @@ -113,18 +116,19 @@ def label(text, position: list = [0, 0, 0], color="grey", t=0):
return default_view.label(text, position, color, t)


def show(viewpoint=None, lookat=None, up=None, inplace=True, in_jupyter=True, name="py3d", port=9871):
def show(viewpoint=None, lookat=None, up=None, inplace=True, size=[], in_jupyter=True, name="py3d", port=9871):
'''
display all rendered objects in one scene
viewpoint: the position from where to view the scene
lookat: the position to look at
up: up direction to view the scene
inplace: update the output when displayed in jupyter
size: size of the viewer
in_jupyter: display in jupyter, as a output, otherwise in a web browser
name: name of the page when displayed in a web browser
port: port to visit the page when displayed in a web browser
'''
return default_view.show(viewpoint, lookat, up, inplace, in_jupyter, name, port)
return default_view.show(viewpoint, lookat, up, inplace, size, in_jupyter, name, port)


def read_pcd(path) -> Vector:
Expand Down Expand Up @@ -230,7 +234,7 @@ def read_ply(path) -> tuple[Vector3, Triangle]:
return vertices, mesh


def read_csv(path, header=1) -> Vector:
def read_csv(path, header=0) -> Vector:
'''
Load data from a csv file.
header: line number of header, 0 if there is no header
Expand Down
3 changes: 2 additions & 1 deletion py3d/viewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@
this.labeldiv = document.createElement("div")
this.labeldiv.style.position = "absolute"
this.canvasdiv = document.createElement("div")
this.canvasdiv.style.height = "300px"
this.canvasdiv.style.height = data.size[0] + "px"
this.canvasdiv.style.width = data.size[1] + "px"
this.canvasdiv.style.overflow = "hidden"
this.canvasdiv.style.resize = "vertical"
this.canvasdiv.append(this.labeldiv, this.canvas)
Expand Down