nmwsharp / polyscope-py Goto Github PK
View Code? Open in Web Editor NEWPython bindings for Polyscope
License: MIT License
Python bindings for Polyscope
License: MIT License
After pip-installing the latest and running this code, the selection UI doesn't show up when clicking on the mesh. Everything works fine with the C++ library when I build that from source.
import polyscope as pscope
pscope.set_program_name("Demo")
pscope.init()
# create mesh
ps_mesh = pscope.register_surface_mesh("ps-mesh", mesh.vertices, mesh.faces)
if mesh.normals is not None:
ps_mesh.add_vector_quantity("normals", mesh.normals, enabled=False)
if mesh.uvs is not None:
ps_mesh.add_parameterization_quantity("uv", mesh.uvs, checker_size=3e-4, viz_style="checker", enabled=True)
if mesh.face_ids is not None:
ps_mesh.add_scalar_quantity("face_ids", mesh.face_ids, defined_on="faces", enabled=True)
pscope.show()
Right now, failing to call ps.init()
manifests as a segfault. Add nice sanity checks at least on the register()
functions so we give better errors.
First of all thank you @nmwsharp so much for this super beautiful visualization library cpp+python!
I wanted to ask how a few things which I fail to find the documentation for and I think might be implemented already -
I'm currently trying to assign vector constraints on specific faces through UI and these will be very helpful:)
Thank you so much again!
Hi @nmwsharp !
Thanks for this amazing package!
ps.init()
fn = 'data/our_faces/face_lod0_with_uv.obj'
mesh : Trimesh = trimesh.load(fn, process=False)
verts = mesh.vertices
faces = mesh.faces
uv = mesh.visual.uv
print("verts shape:", verts.shape, ',uv shape:', uv.shape)
ps_mesh = ps.register_surface_mesh("my_mesh", verts, faces, color=(0.8, 0.8, 0.8), edge_width=0.8)
ps_mesh.add_parameterization_quantity("my_uv", uv, defined_on='vertices', enabled=True)
dims = (200, 200, 3)
color_vals = np.random.randint(0, 255, size=dims) # dummy placeholder image data
color_vals = color_vals / 255.
ps_mesh.add_color_quantity("my_img", color_vals,
defined_on='texture', param_name="my_uv",
enabled=True)
ps.add_color_image_quantity("color_img", color_vals, enabled=True,
show_fullscreen=False, show_in_camera_billboard=False, transparency=0.5)
ps.show()
the texture not working, the noise texture is expected on the surface of mesh, but it does NOT.
then I checked the uv by enable the my_uv(vertex parameterization), it looks ok. so the problem is not on UV.
Thanks.
(and docs too)
This is a common request from folks using Polyscope for research figures.
Make sure we have all combinations of get/set view matrix and get/set projection matrix & the respective params.
Maybe give better controls over window size too?
Also expose the get/set JSON string.
Also also make these nice and visible in the docs!
I'm using PolyScope through its Python bindings in pygraphite. It would be interesting to be able to save PolyScope rendering parameters in the .graphite
files that serialize the whole scene graph (they have a generic attribute mechanism to do that). Would it be possible to add a function to serialize / deserialize all structure parameters in a string in JSON format ?
seems to be taking screenshot, but not sure where they are getting written to
Hi @nmwsharp !
Thanks for this amazing package! I'm currently designing a tool that is using Polyscope and makes heavy use of keyboard controls. For that, it would be invaluable to have access to modifier keys as well as the full set of keys from the keyboard. However, currently in the Polyscope Python interface only a few keys are mapped (see
polyscope-py/src/cpp/imgui.cpp
Line 1704 in 11362b1
io.KeyMods
, if I'm not mistaken).
Is there currently a way to read modifier keys in Polyscope in Python that I'm missing? Would it be possible to expose access to the io module or another access function? Could we extend the list of mapped keys to cover the entire keyboard instead of the current selection?
Thanks a lot in advance!
Christoph
I'm creating custom UI elements since the default callback seems to only support a single additional window and also has a hardcoded name of "Command UI". In the C++ source, I noticed the windows are being docked by continually updating the current window heights of the parent window and adjusting the positions accordingly.
I'm trying to do this in the Python implementation with the imgui bindings, but the functions GetWindowHeight() and GetWindowWidth() seem to return completely static values when I call them within my callback, and do not change if I move/resize the parent window or the actual callback GUI element. It's unclear what it's doing. I'm seeing the same trouble with GetWindowContentRegionMax() and GetContentRegionMax().
Not sure if this is a ImGui specific question but it seems related to PolyScope. For that matter, it would be nice if the main polyscope instance could return the window sizing params for this purpose if the above bindings don't actually have the parent window context. Otherwise, I'm not sure how to get GUI elements to dock to different sides of the window, etc. It would also be nice if we could rename the default callback GUI, as well as enable/disable the Structure, Picker, and Polyscope GUI elements from Python like that can be done in C++. Additionally, further customization of those default elements would be highly appreciated since without it, users who want to customize the UI will have to turn off the boilerplate and re-write it which defeats the purpose in my opinion.
conda install -c conda-forge polyscope
produces
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
PackagesNotFoundError: The following packages are not available from current channels:
- polyscope
Current channels:
- https://conda.anaconda.org/conda-forge/osx-arm64
- https://conda.anaconda.org/conda-forge/noarch
- https://repo.anaconda.com/pkgs/main/osx-arm64
- https://repo.anaconda.com/pkgs/main/noarch
- https://repo.anaconda.com/pkgs/r/osx-arm64
- https://repo.anaconda.com/pkgs/r/noarch
To search for alternate channels that may provide the conda package you're
looking for, navigate to
https://anaconda.org
and use the search bar at the top of the page.
I'm curious if it's related to being on an m1 mac.
FWIW, cloning this repo and building local worked fine.
Fix this nmwsharp/neural-implicit-queries#2
get_camera_world_position()
, get_camera_frame()
, get_field_of_view()
It would be interesting to have a function to show/hide the gizmo associated with a structure programatically, from a Python script (did not find it but maybe I looked in the wrong place)
Right now the following code results in segfault:
import polyscope as ps
import numpy as np
ps.init()
cloud = ps.register_point_cloud("my cloud", np.random.rand(100,3))
ps.remove_point_cloud("my cloud")
cloud.add_scalar_quantity("my scalar", np.random.rand(100)) # boom!
(the same applies for all structures/quantities)
The solution is that add_scalar_quantity()
should first check if the underlying point cloud still exists, and if not throw an informative Python error. There are a couple possible ways to implement this; we could check by name, or just set some flag in the python point cloud handle object.
When using polyscope for a quick visualization I don't always have or care about a meaningful "name" for my mesh. Could there be a default?
If I understand correctly calling register_surface_mesh
twice with the same name
will overwrite the first call's data. So I guess there's a question whether a default would be default1
, default2
, etc. or just keep overwriting default
. I kind of like overwriting default
because avoiding that clearly gives the non-default name a sense of purpose.
Hey there,
I seem to have difficulties putting 2 dropdown menues in the same row:
`import numpy as np
import pymeshlab
import polyscope as ps
import polyscope.imgui as psim
class PolyscopeGUI:
def __init__(self):
self.ui_options = ["Laplacian smoothing operation", "option B", "option C"]
self.ui_options_selected = self.ui_options[1]
self.reconstruction_options = ["Screened Poisson Reconstruction", "APSS Marching cubes"]
self.reconstruction_options_selected = self.reconstruction_options[0]
ps.init()
#ps.register_point_cloud('my point cloud', points)
ps.set_user_callback(self.__callback)
ps.show()
def __callback(self):
'''This function is responsible for defining the actual GUI'''
psim.PushItemWidth(250)
smoothing_options = psim.BeginCombo("", self.ui_options_selected)
if smoothing_options:
for val in self.ui_options:
_, selected = psim.Selectable(val, self.ui_options_selected==val)
if selected:
self.ui_options_selected = val
psim.EndCombo()
psim.PopItemWidth()
psim.SameLine()
psim.PushItemWidth(150)
reconstruction_options = psim.BeginCombo("", self.reconstruction_options_selected)
if reconstruction_options:
for val in self.reconstruction_options:
_, selected = psim.Selectable(val, self.reconstruction_options_selected==val)
if selected:
self.reconstruction_options_selected = val
psim.EndCombo()
psim.PopItemWidth()
def callback():
pass
def main():
poly = PolyscopeGUI()
if name == 'main':
main() `
I have no idea how to include the last few lines of code into the code block. But what happens is that the right drop down menu does not work at all unfortunately. Any Idea what could be wrong?
Here's my WIP on adding ImGui https://github.com/subscale/polyscope-py/blob/add-gui-features/src/cpp/imgui.cpp
I took the following approach:
ImGui::TreeNodeEx
becomes tree_node_ex
float v[2]
-> std::array<float, 2>
m.def(
"drag_float2",
[](const char* label,
const std::array<float, 2>& v,
float v_speed,
float v_min,
float v_max,
const char* format,
float power) {
auto v_ = v;
auto clicked =
ImGui::DragFloat2(label, v_.data(), v_speed, v_min, v_max, format, power);
return std::make_tuple(clicked, v_);
},
py::arg("label"),
py::arg("v"),
py::arg("v_speed") = 1.0f,
py::arg("v_min") = 0.0f,
py::arg("v_max") = 0.0f,
py::arg("format") = "%.3f",
py::arg("power") = 1.0f);
ImVecN
types are translated into std::tuple
Vec2T from_vec2(const ImVec2& v) { return std::make_tuple(v.x, v.y); }
Vec4T from_vec4(const ImVec4& v) { return std::make_tuple(v.x, v.y, v.z, v.w); }
m.def(
"progress_bar",
[](float fraction, const Vec2T& size_arg) {
ImGui::ProgressBar(fraction, to_vec2(size_arg));
},
py::arg("fraction"),
py::arg("size_arg") = std::make_tuple(-1.f, 0.f));
m.def("get_cursor_pos", []() { return from_vec2(ImGui::GetCursorPos()); });
py::enum_
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.