Skip to content

Commit 854ca59

Browse files
authored
Merge pull request #37 from felenitaribeiro/tests-flr
tests for surface and surface overlay loading
2 parents 67e623b + d55aebb commit 854ca59

File tree

6 files changed

+103
-6
lines changed

6 files changed

+103
-6
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,25 @@ If niivue-vscode fails to open any of these files, please create an issue.
4545

4646
## Developing this extension in VSCode
4747

48+
- Fork this repository;
4849
- Clone [this repository](https://github.com/korbinian90/niivue-vscode) and open in VSCode
4950
- Run inside the `niivue-vscode` folder
5051

5152
### Installing
5253

5354
```bash
54-
yarn install
55+
npm install --global yarn
56+
yarn install:all
5557
```
5658

59+
It might be required to update *node* first before running 'yarn install'. This can be done with the following:
60+
61+
```bash
62+
npm install --global n
63+
n latest
64+
```
65+
66+
5767
### Hot Reload Development in browser
5868

5969
```bash

niivue/src/components/Menu.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { addImagesEvent, addOverlayEvent, openImageFromURL } from '../events'
55
import { SLICE_TYPE } from '@niivue/niivue'
66
import { ScalingBox } from './ScalingBox'
77
import { getMetadataString } from '../utility'
8+
import { getNumberOfPoints } from '../utility'
89
import {
910
HeaderDialog,
1011
ImageSelect,
@@ -163,7 +164,7 @@ export const Menu = (props: AppProps) => {
163164
selectedOverlayNumber.value = nOverlays.value - (isMesh.value ? 1 : 0)
164165
overlayMenu.value = true
165166
}
166-
167+
167168
return html`
168169
<div class="flex flex-wrap items-baseline gap-2">
169170
${!isVscode && html`<${MenuButton} label="Home" onClick=${homeEvent} />`}
@@ -221,6 +222,7 @@ export const Menu = (props: AppProps) => {
221222
<${MenuEntry} label="Select All" onClick=${selectAll} />
222223
</${ImageSelect}>
223224
</div>
225+
<p class="pl-2">${isMesh.value? getNumberOfPoints(nvArraySelected.value[0]): 'No mesh'}</p>
224226
${isVolume.value && html`<p class="pl-2">${getMetadataString(nvArraySelected.value[0])}</p>`}
225227
<${ScalingBox}
226228
selectedOverlayNumber=${selectedOverlayNumber}

niivue/src/events.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,22 @@ function addMeshOverlay(nv: Niivue, item: any, type: string) {
130130
if (type === 'replaceMeshOverlay') {
131131
mesh.layers.pop()
132132
}
133-
NVMesh.readLayer(
133+
if (!item.data) {
134+
console.log('Running loadFromURL');
135+
NVMesh.loadLayer(
136+
{url: item.uri,
137+
opacity:a.opacity,
138+
colormap:a.colormap,
139+
colormapNegative:a.colormapNegative,
140+
useNegativeCmap:a.useNegativeCmap,
141+
cal_min:a.calMin,
142+
cal_max:a.calMax,
143+
},
144+
mesh,
145+
)
146+
} else {
147+
console.log('Running readLayer');
148+
NVMesh.readLayer(
134149
item.uri,
135150
item.data,
136151
mesh,
@@ -140,7 +155,8 @@ function addMeshOverlay(nv: Niivue, item: any, type: string) {
140155
a.useNegativeCmap,
141156
a.calMin,
142157
a.calMax,
143-
)
158+
)
159+
}
144160
mesh.updateMesh(nv.gl)
145161
nv.opts.isColorbar = true
146162
nv.updateGLVolume()

niivue/src/utility.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,9 @@ export function getMetadataString(nv: Niivue) {
113113
const timeString = meta.nt > 1 ? ', timepoints: ' + meta.nt : ''
114114
return matrixString + ', ' + voxelString + timeString
115115
}
116+
117+
export function getNumberOfPoints(nv: Niivue) {
118+
const mesh = nv?.meshes?.[0]
119+
const matrixString = 'Number of Points: ' + mesh.pts.length / 3
120+
return matrixString
121+
}

niivue/tests/example.spec.ts

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,36 @@ test.describe('app', () => {
8585
expect(await page.$$('canvas')).toHaveLength(2)
8686
})
8787

88+
test('loads a test surface', async ({ page }) => {
89+
await page.goto(BASE_URL);
90+
91+
await loadTestSurfImage(page);
92+
await page.waitForTimeout(1000); // wait time to work around a bug
93+
94+
expect(await page.waitForSelector('canvas')).toBeTruthy();
95+
expect(await page.$$('canvas')).toHaveLength(1);
96+
97+
await loadTestSurfImage(page);
98+
expect(await page.$$('canvas')).toHaveLength(2);
99+
100+
expect(await page.textContent('text=/Number of Points: 40962/i')).toBeTruthy();
101+
});
102+
103+
test('loads a test image and overlay', async ({ page }) => {
104+
await page.goto(BASE_URL);
105+
106+
await loadTestSurfImage(page);
107+
108+
await page.waitForTimeout(1000); // duplicated code to work around a bug
109+
await loadTestSurfImage(page); // duplicated code to work around a bug
110+
111+
await loadTestSurfOverlay(page, 'curv');
112+
113+
await page.waitForTimeout(1000); // duplicated code to work around a bug
114+
await loadTestSurfOverlay(page, 'curv'); // duplicated code to work around a bug
115+
116+
});
117+
88118
test('loads an image and checks the menu bar', async ({ page }) => {
89119
await page.goto(BASE_URL)
90120

@@ -125,5 +155,38 @@ async function loadTestImage(page) {
125155
uri: testLink,
126156
},
127157
}
128-
await page.evaluate((m) => window.postMessage(m, '*'), message)
158+
await page.evaluate((m) => window.postMessage(m, '*'), message);
159+
}
160+
161+
async function loadTestSurfImage(page) {
162+
const testLink = 'https://niivue.github.io/niivue/images/BrainMesh_ICBM152.lh.mz3';
163+
// send a message to the app to load the test image
164+
const message = {
165+
type: 'addImage',
166+
body: {
167+
data: '',
168+
uri: testLink,
169+
},
170+
}
171+
await page.evaluate((m) => window.postMessage(m, '*'), message);
172+
}
173+
174+
async function loadTestSurfOverlay(page, file_type) {
175+
let testLink;
176+
177+
if (file_type === 'curv') {
178+
testLink = 'https://niivue.github.io/niivue/images/BrainMesh_ICBM152.lh.curv';
179+
} else if (file_type === 'other') {
180+
testLink = 'https://niivue.github.io/niivue/images/BrainMesh_ICBM152.lh.motor.mz3';
181+
}
182+
// send a message to the app to load the test image
183+
const message = {
184+
type: 'addMeshOverlay',
185+
body: {
186+
index: 0,
187+
data: '',
188+
uri: String(testLink),
189+
},
190+
}
191+
await page.evaluate((m) => window.postMessage(m, '*'), message);
129192
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
"*"
139139
],
140140
"scripts": {
141-
"install": "yarn install && cd niivue && yarn install",
141+
"install:all": "yarn install && cd niivue && yarn install",
142142
"start:webview": "cd niivue && yarn run start",
143143
"build:webview": "cd niivue && yarn run build",
144144
"test:webview": "cd niivue && yarn run test",

0 commit comments

Comments
 (0)