Skip to content

Commit

Permalink
Merge pull request #360 from zeyuyun1/master
Browse files Browse the repository at this point in the history
Fixing the error that arise when using uneven width and height
  • Loading branch information
vidartf committed Dec 6, 2021
2 parents 010f272 + 7eea4c0 commit a78cb57
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
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
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
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
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
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

0 comments on commit a78cb57

Please sign in to comment.