Skip to content
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

[Bug] Stack viewport broken when switch from volume viewport if set config useNorm16Texture = true #4167

Open
tunglt1810 opened this issue May 24, 2024 · 6 comments
Assignees
Labels
Awaiting Reproduction Can we reproduce the reported bug?

Comments

@tunglt1810
Copy link

Describe the Bug

Hi guys,
I am working with a fork version which forked since 4 months ago.
I faced with an issue when trying switch hanging protocol from mpr to default.
The first time loaded and render is ok.
I switch to protocol primaryAxial is ok. But when switch back to protocol default, it looks like image is crashed.
But one more time when I switch to protocol primaryAxial, the viewports look fine.
first load ok
primaryAxial ok
errors

Maybe I was wrong in wording, so I raise this issue to ask about some hints to debug this issue

Steps to Reproduce

  1. Run app
  2. Open the first study CTA Head and Neck
image 3. Switch to hanging protocol `primaryAxial` 4. Switch back to handing protocol `default`

The current behavior

After switch hanging protocol from primaryAxial to default, viewport image looks like broken

The expected behavior

I expect that viewport image will be not broken

OS

macOS 14.5

Node version

v18.16.1

Browser

Chrome 125.0.6422.61

@tunglt1810 tunglt1810 added the Awaiting Reproduction Can we reproduce the reported bug? label May 24, 2024
@tunglt1810 tunglt1810 changed the title [Bug] [Bug] After switch hanging protocol from primaryAxial to default, viewport image looks like broken May 24, 2024
@ahlaughland
Copy link

ahlaughland commented May 28, 2024

Not sure if this is related but it sounds similar to what I'm seeing.

I'm also on a forked branch of OHIF. We're at 3.9.0-beta.0 and usng the new layout selector.

When I switch protocols using the new layout switcher the viewports don't seem to update, like above. For example, if I swtich from a view of with 3 viewports like: [axial][saggital][coronal] and switch to just an [axial] and back to [axial][saggital][coronal] the [saggital][coronal] viewports don't update. I have to re-select the [axial][saggital][coronal] option then the viewports update and look correct.

We are calling a function to update to viewports' opacity threshold from the protocol callbacks.onProtocolEnter.

We use some VTK code directly and it looks like the VTK Actor entry is not ready and is missing the getProperty() from volumeActor.getProperty()...

If I wrap our function calling the actor using a setTimeout(() => ,500); the actor is then available and the viewports are updated.

Again, not sure if this is related to the original post but thought I would pass it along.

@tunglt1810
Copy link
Author

Hi @ahlaughland ,
Thank for your sharing.
I also call a command to enable crosshairs tool when onProtocolEnter.
And the calling setHangingProtocol with id is default after that.
Do you think I need to call something before calling command to active crosshairs tool?

Screen.Recording.2024-05-28.at.22.23.52.mov

@ahlaughland
Copy link

Hi @ahlaughland , Thank for your sharing. I also call a command to enable crosshairs tool when onProtocolEnter. And the calling setHangingProtocol with id is default after that. Do you think I need to call something before calling command to active crosshairs tool?

Screen.Recording.2024-05-28.at.22.23.52.mov

I would think activating the tool for the correct toolGroupId would be enough.

@tunglt1810
Copy link
Author

tunglt1810 commented May 29, 2024

Now I can reproduce the error.
I made a command that toggle between volume and stack viewport.
Now the stack viewport will be crashed after switch from volume viewport. Do I miss something or some function to call when setting up volume viewport ?
I also add log debug from renderingEngine. It looks like the pixel data has decreased by 4 times

toggleSwitchMPR: async ({ orientation }) => {
	const activeViewportID = viewportGridService.getActiveViewportId();
	const viewportInfo = cornerstoneViewportService.getViewportInfo(activeViewportID);
	const currentViewportData = viewportInfo.viewportData;
	const displaySetInstanceUID = currentViewportData.data.length
		? currentViewportData.data[0].displaySetInstanceUID
		: currentViewportData.data.displaySetInstanceUID;
	const displaySet = displaySetService.getDisplaySetByUID(displaySetInstanceUID);
	const dataSource = extensionManager.getActiveDataSource()[0];
	const renderingEngine = cornerstoneViewportService.getRenderingEngine();
	if (currentViewportData.viewportType === 'stack') {
		const offScreen = renderingEngine._debugRender();
		console.log(`debug render1`, offScreen);
		const viewportOptions = {
			viewportType: 'volume',
			orientation: orientation
		};
		const viewportData = await cornerstoneCacheService.createViewportData([displaySet], viewportOptions, dataSource);
		const publicViewportOptions: PublicViewportOptions = {
			id: orientation,
			viewportType: 'volume',
			toolGroupId: 'mpr',
			orientation: orientation
		};
		cornerstoneViewportService.setViewportData(
			activeViewportID,
			viewportData,
			publicViewportOptions,
			viewportInfo.displaySetOptions
		);
	} else {
		const viewportOptions = {
			viewportType: 'stack'
		};
		const viewportData = await cornerstoneCacheService.createViewportData([displaySet], viewportOptions, dataSource);
		const publicViewportOptions: PublicViewportOptions = {
			viewportType: 'stack',
			toolGroupId: 'default',
			initialImageOptions: {
				preset: 'middle'
			}
		};
		cornerstoneViewportService.setViewportData(
			activeViewportID,
			viewportData,
			publicViewportOptions,
			viewportInfo.displaySetOptions
		);
		window.setTimeout(() => {
			const offScreen = renderingEngine._debugRender();
			console.log(`debug render2`, offScreen);
		}, 500);
	}
}

Before switch from stack viewport to volume viewport
image

After switch from volume viewport to stack viewport
image

@tunglt1810
Copy link
Author

@ahlaughland
I reallied that I am using this config to reduce memory sizing

useNorm16Texture: true,
preferSizeOverAccuracy: true

Also found a config about rendering engine
image

If I config cornerstone like this, the issue is solved

cornerstone.setConfiguration({
	...cornerstone.getConfiguration(),
	rendering: {
		...cornerstone.getConfiguration().rendering,
		strictZSpacingForVolumeViewport: appConfig.strictZSpacingForVolumeViewport
	},
	enableCacheOptimization: false
});

@tunglt1810 tunglt1810 changed the title [Bug] After switch hanging protocol from primaryAxial to default, viewport image looks like broken [Bug] Stack viewport broken when switch from volume viewport if set config useNorm16Texture = true May 29, 2024
@sedghi sedghi self-assigned this May 29, 2024
@ahlaughland
Copy link

@ahlaughland I reallied that I am using this config to reduce memory sizing

useNorm16Texture: true,
preferSizeOverAccuracy: true

Also found a config about rendering engine image

If I config cornerstone like this, the issue is solved

cornerstone.setConfiguration({
	...cornerstone.getConfiguration(),
	rendering: {
		...cornerstone.getConfiguration().rendering,
		strictZSpacingForVolumeViewport: appConfig.strictZSpacingForVolumeViewport
	},
	enableCacheOptimization: false
});

Thanks, I will research this enableCacheOptimization option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Reproduction Can we reproduce the reported bug?
Projects
None yet
Development

No branches or pull requests

3 participants