Skip to content

Commit a78cb57

Browse files
authored
Merge pull request #360 from zeyuyun1/master
Fixing the error that arise when using uneven width and height
2 parents 010f272 + 7eea4c0 commit a78cb57

File tree

6 files changed

+43
-57
lines changed

6 files changed

+43
-57
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ jobs:
199199
# explicit file installs don't support extras, skimage brings most along
200200
run: |
201201
set -eux
202-
${{ matrix.py_cmd }} -m pip install -vv nbval scikit-image ipywebrtc pytest-cov codecov
202+
${{ matrix.py_cmd }} -m pip install -vv nbval scikit-image ipywebrtc pytest-cov codecov matplotlib
203203
- name: Run python tests
204204
# remove the source directory to avoid surprises
205205
run: |

docs/source/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def add_scripts(app):
213213
for fname in ['jupyter-threejs.js']:
214214
if not os.path.exists(os.path.join(here, '_static', fname)):
215215
logger.warn('missing javascript file: %s' % fname)
216-
app.add_javascript(fname)
216+
app.add_js_file(fname)
217217

218218
def add_images(app):
219219
# TODO: Add all images automatically by dir

examples/Examples.ipynb

+5-5
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"# Generate surface data:\n",
8282
"view_width = 600\n",
8383
"view_height = 400\n",
84-
"nx, ny = (20, 20)\n",
84+
"nx, ny = (24, 20)\n",
8585
"xmax=1\n",
8686
"x = np.linspace(-xmax, xmax, nx)\n",
8787
"y = np.linspace(-xmax, xmax, ny)\n",
@@ -91,14 +91,14 @@
9191
"\n",
9292
"\n",
9393
"# Generate scene objects from data:\n",
94-
"surf_g = SurfaceGeometry(z=list(z[::-1].flat), \n",
94+
"surf_g = SurfaceGeometry(z=list(z.flat), \n",
9595
" width=2 * xmax,\n",
9696
" height=2 * xmax,\n",
9797
" width_segments=nx - 1,\n",
9898
" height_segments=ny - 1)\n",
9999
"\n",
100100
"surf = Mesh(geometry=surf_g,\n",
101-
" material=MeshLambertMaterial(map=height_texture(z[::-1], 'YlGnBu_r')))\n",
101+
" material=MeshLambertMaterial(map=height_texture(z, 'YlGnBu_r')))\n",
102102
"\n",
103103
"surfgrid = SurfaceGrid(geometry=surf_g, material=LineBasicMaterial(color='black'),\n",
104104
" position=[0, 0, 1e-2]) # Avoid overlap by lifting grid slightly\n",
@@ -155,8 +155,8 @@
155155
"metadata": {},
156156
"outputs": [],
157157
"source": [
158-
"surf_g.z = list((-z[::-1]).flat)\n",
159-
"surf.material.map = height_texture(-z[::-1])"
158+
"surf_g.z = list((-z).flat)\n",
159+
"surf.material.map = height_texture(-z)"
160160
]
161161
},
162162
{

examples/Textures.ipynb

+29-45
Large diffs are not rendered by default.

js/src/textures/DataTexture.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ var DataTextureModel = DataTextureBase.extend({
2222
}
2323
var data = this.convertArrayBufferModelToThree(rawData, 'data');
2424

25+
// ipydatawidgets uses row-major storage, so "flip" axes dims here:
2526
return {
2627
data: data,
27-
width: rawData.shape[0],
28-
height: rawData.shape[1],
28+
width: rawData.shape[1],
29+
height: rawData.shape[0],
2930
};
3031
},
3132

@@ -75,9 +76,10 @@ var DataTextureModel = DataTextureBase.extend({
7576
var rawData = dataserializers.getArray(modelNDArray);
7677
rawData.data.set(imageRecord.data);
7778
} else {
79+
// ipydatawidgets uses row-major storage, so "flip" axes dims here:
7880
this.set('data', ndarray(
7981
imageRecord.data,
80-
[imageRecord.width, imageRecord.height]
82+
[imageRecord.height, imageRecord.width]
8183
));
8284
}
8385
},

pythreejs/pythreejs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def grid_indices_gen(nx, ny):
4444
"""
4545
for x in range(nx - 1):
4646
for y in range(ny - 1):
47-
root = x + y * ny
47+
root = x + y * nx
4848
yield (root, root + 1, root + nx)
4949
yield (root + nx, root + 1, root + nx + 1)
5050

@@ -78,7 +78,7 @@ def _update_surface(self):
7878
x = np.linspace(-self.width/2, self.width/2, nx)
7979
y = np.linspace(-self.height/2, self.height/2, ny)
8080
xx, yy = np.meshgrid(x, y)
81-
z = np.array(self.z).reshape((nx, ny))
81+
z = np.array(self.z).reshape(xx.shape)
8282

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

0 commit comments

Comments
 (0)