Skip to content

Commit 2e1e2b7

Browse files
Jonathan LurieJonathan Lurie
authored andcommitted
ADD constant management and volume toggle
1 parent 7c0b6ae commit 2e1e2b7

File tree

9 files changed

+163152
-163081
lines changed

9 files changed

+163152
-163081
lines changed

dist/quickvoxelcore.js

Lines changed: 163080 additions & 163046 deletions
Large diffs are not rendered by default.

dist/quickvoxelcore.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/colormaps.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<html>
22
<head>
3-
<title>Test</title>
3+
<title>Colormap</title>
44

55
<style>
66
html, body {
@@ -64,7 +64,7 @@
6464
// adjusting contrast and brightness for better rendering with colormap
6565
renderEngine.setContrastSlotN(0, 1.5)
6666
renderEngine.setBrightnessSlotN(0, 0.3)
67-
67+
6868

6969
// display colormaps to allow selection
7070
let allColormaps = renderEngine.getListOfColormaps()

examples/double.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<html>
22
<head>
3-
<title>Test</title>
3+
<title>Double</title>
44

55
<style>
66
html, body {
@@ -44,6 +44,13 @@
4444
// for future access the render engine
4545
let renderEngine = qvc.getRenderEngine();
4646

47+
// color and constrast settings
48+
renderEngine.setColormapSlotN(1, 'jet')
49+
renderEngine.setBlendMethod("multiply")
50+
renderEngine.setBrightnessSlotN(1, 0.15)
51+
renderEngine.setBrightnessSlotN(0, 0.25)
52+
renderEngine.setContrastSlotN(0, 1.2)
53+
4754
let dataFolder = "../data/"
4855
let structural = "structural.nii.gz"
4956
let functional = "functional.nii.gz"
@@ -61,7 +68,6 @@
6168
renderEngine.mountVolumeN( 0, volume )
6269
}else{
6370
renderEngine.mountVolumeN( 1, volume )
64-
renderEngine.setColormapSlotN(1, 'jet')
6571
}
6672
})
6773

examples/simple.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<html>
22
<head>
3-
<title>Test</title>
3+
<title>Simple</title>
44

55
<style>
66
html, body {

src/RenderEngine.js

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import * as BABYLON from 'babylonjs/es6.js'
22
import worldcoordtexture3dFrag from './shaders/worldcoordtexture3d.frag.glsl'
33
import worldcoordtexture3dVert from './shaders/worldcoordtexture3d.vert.glsl'
44
import { ColormapManager } from './ColormapManager.js'
5-
6-
const DEFAULT_PLANE_SIZE = 1000;
5+
import { CONSTANTS } from './constants.js'
76

87
/**
98
* [RenderEngine description]
@@ -81,8 +80,8 @@ class RenderEngine {
8180
{
8281
attributes: ["position", "normal", "uv"],
8382
uniforms: ["world", "worldView", "worldViewProjection", "blendMethod", "vol_0_vol_1_blendRatio",
84-
"vol_0_texture3D", "vol_0_transfoMat", "vol_0_timeVal", "vol_0_timeSize", "vol_0_textureReady",
85-
"vol_1_texture3D", "vol_1_transfoMat", "vol_1_timeVal", "vol_1_timeSize", "vol_1_textureReady"
83+
"vol_0_texture3D", "vol_0_transfoMat", "vol_0_timeVal", "vol_0_timeSize", "vol_0_textureReady", "vol_0_display",
84+
"vol_1_texture3D", "vol_1_transfoMat", "vol_1_timeVal", "vol_1_timeSize", "vol_1_textureReady", "vol_1_display"
8685
]
8786
});
8887

@@ -102,15 +101,28 @@ class RenderEngine {
102101

103102

104103
/**
105-
* Change the blending method. Note that this matters only when 2 textures are displayed
106-
* 0: mix using the blendRatio
107-
* 1: average of both volume on each channel
108-
* @param {Number} m - method of blending
104+
* Change the blending method. Note that this matters only when 2 textures are displayed.
105+
*
106+
* @param {String} m - method of blending
107+
*/
108+
setBlendMethod (method) {
109+
if (method in CONSTANTS.BLENDING_METHODS) {
110+
this._shaderMaterial.setInt( 'blendMethod', CONSTANTS.BLENDING_METHODS[method] )
111+
} else {
112+
console.warn('The blending method ' + method + ' does not exist.');
113+
}
114+
}
115+
116+
117+
/**
118+
* Get the list of blending methods
119+
* @return {Array} the list of strings, names of the blending methods
109120
*/
110-
setBlendMethod (m) {
111-
this._shaderMaterial.setInt( "blendMethod", m )
121+
getBlendMethodList () {
122+
return Object.keys( CONSTANTS.BLENDING_METHODS )
112123
}
113124

125+
114126
/**
115127
* Initialize the texture data relative to a single texture
116128
* @param {Number} n - 0 for primary, 1 for secondary
@@ -122,6 +134,7 @@ class RenderEngine {
122134
shaderMaterial.setInt( "vol_" + n + "_timeVal", 0 )
123135
shaderMaterial.setInt( "vol_" + n + "_timeSize", 0 )
124136
shaderMaterial.setInt( "vol_" + n + "_textureReady", 0 )
137+
shaderMaterial.setInt( "vol_" + n + "_display", 1 )
125138

126139
let defaultColormapTexture = this._colormapManager.getColormap()
127140
shaderMaterial.setTexture( "vol_" + n + "_colormap", defaultColormapTexture )
@@ -143,8 +156,8 @@ class RenderEngine {
143156
let xyPlane = BABYLON.MeshBuilder.CreatePlane(
144157
"xyOrthoPlane",
145158
{
146-
height:DEFAULT_PLANE_SIZE,
147-
width: DEFAULT_PLANE_SIZE,
159+
height:CONSTANTS.GEOMETRY.DEFAULT_PLANE_SIZE,
160+
width: CONSTANTS.GEOMETRY.DEFAULT_PLANE_SIZE,
148161
sideOrientation: BABYLON.Mesh.DOUBLESIDE
149162
}, this._scene);
150163
xyPlane.parent = orthoPlaneSystem;
@@ -153,8 +166,8 @@ class RenderEngine {
153166
let xzPlane = BABYLON.MeshBuilder.CreatePlane(
154167
"xzOrthoPlane",
155168
{
156-
height:DEFAULT_PLANE_SIZE,
157-
width: DEFAULT_PLANE_SIZE,
169+
height:CONSTANTS.GEOMETRY.DEFAULT_PLANE_SIZE,
170+
width: CONSTANTS.GEOMETRY.DEFAULT_PLANE_SIZE,
158171
sideOrientation: BABYLON.Mesh.DOUBLESIDE
159172
}, this._scene);
160173
xzPlane.rotation.x = Math.PI/2;
@@ -164,8 +177,8 @@ class RenderEngine {
164177
let yzPlane = BABYLON.MeshBuilder.CreatePlane(
165178
"yzOrthoPlane",
166179
{
167-
height:DEFAULT_PLANE_SIZE,
168-
width: DEFAULT_PLANE_SIZE,
180+
height:CONSTANTS.GEOMETRY.DEFAULT_PLANE_SIZE,
181+
width: CONSTANTS.GEOMETRY.DEFAULT_PLANE_SIZE,
169182
sideOrientation: BABYLON.Mesh.DOUBLESIDE
170183
}, this._scene);
171184
yzPlane.rotation.y = Math.PI/2;
@@ -419,6 +432,14 @@ class RenderEngine {
419432
}
420433

421434

435+
/**
436+
* Display of hide the volume hosted on the Nth slot
437+
* @param {Boolean} [d=true] - display is true, hide if false
438+
*/
439+
displayVolumeSlotN (n, d=true) {
440+
this._shaderMaterial.setInt( "vol_" + n + "_display", +d )
441+
}
442+
422443
/**
423444
* must be in [0, 1].
424445
* if closer to 0, the primary volume is more visible
@@ -429,6 +450,8 @@ class RenderEngine {
429450
this._shaderMaterial.setFloat( "vol_0_vol_1_blendRatio", r )
430451
}
431452

453+
454+
432455
/*
433456
move along the normal of a plane:
434457
let xyPlane = scene.getMeshByName('xyPlane')

src/constants.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export const CONSTANTS = {
2+
BLENDING_METHODS: {
3+
'ratio': 0,
4+
'added-weighted': 1,
5+
'multiply': 2
6+
},
7+
GEOMETRY: {
8+
DEFAULT_PLANE_SIZE: 1000
9+
}
10+
}

src/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
export { CONSTANTS } from './constants.js'
12
export { QuickvoxelCore } from './QuickvoxelCore.js'

src/shaders/worldcoordtexture3d.frag.glsl

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ uniform sampler3D vol_0_texture3D;
1616
uniform mat4 vol_0_transfoMat;
1717
// says if the primary 3D texture is ready
1818
uniform int vol_0_textureReady;
19+
// once it's ready, do we wish to display the primary volume?
20+
uniform int vol_0_display;
1921
// the current time position within the primary 3D texture
2022
uniform int vol_0_timeVal;
2123
// the number of time position available in the primary 3D texture
@@ -36,6 +38,8 @@ uniform sampler3D vol_1_texture3D;
3638
uniform mat4 vol_1_transfoMat;
3739
// says if the secondary 3D texture is ready
3840
uniform int vol_1_textureReady;
41+
// once it's ready, do we wish to display the secondary volume?
42+
uniform int vol_1_display;
3943
// the current time position within the secondary 3D texture
4044
uniform int vol_1_timeVal;
4145
// the number of time position available in the secondary 3D texture
@@ -56,7 +60,7 @@ uniform float vol_1_contrast;
5660
// the volume range and 1 if inside. To be used to know wether of not to use the
5761
// returned color.
5862
vec4 getColorVol_0( out int shouldDisplay, out float intensity){
59-
if( vol_0_textureReady == 0 ){
63+
if( vol_0_textureReady == 0 || vol_0_display == 0){
6064
shouldDisplay = 0;
6165
return vec4(0., 0., 0., 0.);
6266
}
@@ -90,7 +94,7 @@ vec4 getColorVol_0( out int shouldDisplay, out float intensity){
9094
// the volume range and 1 if inside. To be used to know wether of not to use the
9195
// returned color.
9296
vec4 getColorVol_1( out int shouldDisplay, out float intensity ){
93-
if( vol_1_textureReady == 0 ){
97+
if( vol_1_textureReady == 0 || vol_1_display == 0){
9498
shouldDisplay = 0;
9599
return vec4(0., 0., 0., 0.);
96100
}
@@ -125,27 +129,20 @@ vec4 blend( vec4 color0, vec4 color1, float intensity0, float intensity1, int me
125129

126130
switch( method ){
127131

128-
// blending
132+
// ratio
129133
case 0:
130134
color = color0 * (1. - vol_0_vol_1_blendRatio) + (color1 * vol_0_vol_1_blendRatio);
131135
break;
132136

133-
// avg
134-
case 1:
135-
color.r = (color0.r + color1.r) / 2.;
136-
color.g = (color0.g + color1.g) / 2.;
137-
color.b = (color0.b + color1.b) / 2.;
138-
color.a = (color0.a + color1.a) / 2.;
139-
break;
140137

141-
// adding
142-
case 3:
138+
// adding weighted
139+
case 1:
143140
color = color0 + color1*vol_0_vol_1_blendRatio;
144141
break;
145142

146143

147144
// multiply
148-
case 4:
145+
case 2:
149146
color = color0 * color1;
150147

151148
default:

0 commit comments

Comments
 (0)