Skip to content

Fixing the error that arise when using uneven width and height #360

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

Merged
merged 5 commits into from
Dec 6, 2021
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ jobs:
# explicit file installs don't support extras, skimage brings most along
run: |
set -eux
${{ matrix.py_cmd }} -m pip install -vv nbval scikit-image ipywebrtc pytest-cov codecov
${{ matrix.py_cmd }} -m pip install -vv nbval scikit-image ipywebrtc pytest-cov codecov matplotlib
- name: Run python tests
# remove the source directory to avoid surprises
run: |
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def add_scripts(app):
for fname in ['jupyter-threejs.js']:
if not os.path.exists(os.path.join(here, '_static', fname)):
logger.warn('missing javascript file: %s' % fname)
app.add_javascript(fname)
app.add_js_file(fname)

def add_images(app):
# TODO: Add all images automatically by dir
Expand Down
10 changes: 5 additions & 5 deletions examples/Examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"# Generate surface data:\n",
"view_width = 600\n",
"view_height = 400\n",
"nx, ny = (20, 20)\n",
"nx, ny = (24, 20)\n",
"xmax=1\n",
"x = np.linspace(-xmax, xmax, nx)\n",
"y = np.linspace(-xmax, xmax, ny)\n",
Expand All @@ -91,14 +91,14 @@
"\n",
"\n",
"# Generate scene objects from data:\n",
"surf_g = SurfaceGeometry(z=list(z[::-1].flat), \n",
"surf_g = SurfaceGeometry(z=list(z.flat), \n",
" width=2 * xmax,\n",
" height=2 * xmax,\n",
" width_segments=nx - 1,\n",
" height_segments=ny - 1)\n",
"\n",
"surf = Mesh(geometry=surf_g,\n",
" material=MeshLambertMaterial(map=height_texture(z[::-1], 'YlGnBu_r')))\n",
" material=MeshLambertMaterial(map=height_texture(z, 'YlGnBu_r')))\n",
"\n",
"surfgrid = SurfaceGrid(geometry=surf_g, material=LineBasicMaterial(color='black'),\n",
" position=[0, 0, 1e-2]) # Avoid overlap by lifting grid slightly\n",
Expand Down Expand Up @@ -155,8 +155,8 @@
"metadata": {},
"outputs": [],
"source": [
"surf_g.z = list((-z[::-1]).flat)\n",
"surf.material.map = height_texture(-z[::-1])"
"surf_g.z = list((-z).flat)\n",
"surf.material.map = height_texture(-z)"
]
},
{
Expand Down
74 changes: 29 additions & 45 deletions examples/Textures.ipynb

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions js/src/textures/DataTexture.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ var DataTextureModel = DataTextureBase.extend({
}
var data = this.convertArrayBufferModelToThree(rawData, 'data');

// ipydatawidgets uses row-major storage, so "flip" axes dims here:
return {
data: data,
width: rawData.shape[0],
height: rawData.shape[1],
width: rawData.shape[1],
height: rawData.shape[0],
};
},

Expand Down Expand Up @@ -75,9 +76,10 @@ var DataTextureModel = DataTextureBase.extend({
var rawData = dataserializers.getArray(modelNDArray);
rawData.data.set(imageRecord.data);
} else {
// ipydatawidgets uses row-major storage, so "flip" axes dims here:
this.set('data', ndarray(
imageRecord.data,
[imageRecord.width, imageRecord.height]
[imageRecord.height, imageRecord.width]
));
}
},
Expand Down
4 changes: 2 additions & 2 deletions pythreejs/pythreejs.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def grid_indices_gen(nx, ny):
"""
for x in range(nx - 1):
for y in range(ny - 1):
root = x + y * ny
root = x + y * nx
yield (root, root + 1, root + nx)
yield (root + nx, root + 1, root + nx + 1)

Expand Down Expand Up @@ -78,7 +78,7 @@ def _update_surface(self):
x = np.linspace(-self.width/2, self.width/2, nx)
y = np.linspace(-self.height/2, self.height/2, ny)
xx, yy = np.meshgrid(x, y)
z = np.array(self.z).reshape((nx, ny))
z = np.array(self.z).reshape(xx.shape)

positions = np.dstack((xx, yy, z)).reshape(nx * ny, 3).astype(np.float32)

Expand Down