Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CAMP
campvis-public
Commits
9436df53
Commit
9436df53
authored
Nov 28, 2014
by
Declara Denis
Committed by
Christian Schulte zu Berge
Feb 18, 2015
Browse files
Initial effort to support 2D and 3D textures in GlImageResampler
parent
063265f4
Changes
3
Hide whitespace changes
Inline
Side-by-side
modules/preprocessing/glsl/glimageresampler.frag
View file @
9436df53
...
...
@@ -25,14 +25,27 @@
in
vec3
ex_TexCoord
;
out
vec4
out_Color
;
#i
nclude
"tools/gradient.frag"
#i
fdef GLRESAMPLER_3D
#include
"tools/texture3d.frag"
uniform
sampler3D
_texture
;
uniform
TextureParameters3D
_textureParams
;
uniform
float
_zTexCoord
;
#endif
#ifdef GLRESAMPLER_2D
#include
"tools/texture2d.frag"
uniform
sampler2D
_texture
;
uniform
TextureParameters2D
_textureParams
;
#endif
void
main
()
{
out_Color
=
texture
(
_texture
,
vec3
(
ex_TexCoord
.
xy
,
_zTexCoord
));
#ifdef GLRESAMPLER_3D
vec4
sample
=
texture
(
_texture
,
vec3
(
ex_TexCoord
.
xy
,
_zTexCoord
));
#endif
#ifdef GLRESAMPLER_2D
vec4
sample
=
texture
(
_texture
,
ex_TexCoord
.
xy
);
#endif
out_Color
=
sample
;
}
modules/preprocessing/processors/glimageresampler.cpp
View file @
9436df53
...
...
@@ -45,7 +45,8 @@ namespace campvis {
,
p_outputImage
(
"OutputImage"
,
"Output Image"
,
"GlImageResampler.out"
,
DataNameProperty
::
WRITE
)
,
p_resampleScale
(
"ResampleScale"
,
"Resampling Scale"
,
.5
f
,
.01
f
,
10.
f
)
,
p_targetSize
(
"TargetSize"
,
"Size of Resampled Image"
,
cgt
::
ivec3
(
128
),
cgt
::
ivec3
(
1
),
cgt
::
ivec3
(
1024
))
,
_shader
(
0
)
,
_shader2D
(
0
)
,
_shader3D
(
0
)
{
addProperty
(
p_inputImage
,
INVALID_RESULT
|
INVALID_PROPERTIES
);
addProperty
(
p_outputImage
);
...
...
@@ -60,13 +61,18 @@ namespace campvis {
void
GlImageResampler
::
init
()
{
VisualizationProcessor
::
init
();
_shader
=
ShdrMgr
.
load
(
"core/glsl/passthrough.vert"
,
"modules/preprocessing/glsl/glimageresampler.frag"
,
""
);
_shader
->
setAttributeLocation
(
0
,
"in_Position"
);
_shader
->
setAttributeLocation
(
1
,
"in_TexCoord"
);
_shader2D
=
ShdrMgr
.
load
(
"core/glsl/passthrough.vert"
,
"modules/preprocessing/glsl/glimageresampler.frag"
,
"#define GLRESAMPLER_3D
\n
"
);
_shader2D
->
setAttributeLocation
(
0
,
"in_Position"
);
_shader2D
->
setAttributeLocation
(
1
,
"in_TexCoord"
);
_shader3D
=
ShdrMgr
.
load
(
"core/glsl/passthrough.vert"
,
"modules/preprocessing/glsl/glimageresampler.frag"
,
"#define GLRESAMPLER_2D
\n
"
);
_shader3D
->
setAttributeLocation
(
0
,
"in_Position"
);
_shader3D
->
setAttributeLocation
(
1
,
"in_TexCoord"
);
}
void
GlImageResampler
::
deinit
()
{
ShdrMgr
.
dispose
(
_shader
);
ShdrMgr
.
dispose
(
_shader2D
);
ShdrMgr
.
dispose
(
_shader3D
);
VisualizationProcessor
::
deinit
();
}
...
...
@@ -76,34 +82,46 @@ namespace campvis {
if
(
img
!=
0
)
{
cgt
::
vec3
originalSize
(
img
->
getSize
());
const
cgt
::
ivec3
&
resampledSize
=
p_targetSize
.
getValue
();
bool
isTexture2D
=
img
->
getParent
()
->
getDimensionality
()
==
2
;
// 2D textures should not be scaled along the z axis
if
(
isTexture2D
)
{
resampledSize
.
z
=
1
;
}
cgt
::
TextureUnit
inputUnit
;
inputUnit
.
activate
();
// create texture for result
cgt
::
Texture
*
resultTexture
=
new
cgt
::
Texture
(
GL_TEXTURE_3D
,
resampledSize
,
img
->
getTexture
()
->
getInternalFormat
(),
cgt
::
Texture
::
LINEAR
);
cgt
::
Texture
*
resultTexture
=
new
cgt
::
Texture
(
isTexture2D
?
GL_TEXTURE_2D
:
GL_TEXTURE_3D
,
resampledSize
,
img
->
getTexture
()
->
getInternalFormat
(),
cgt
::
Texture
::
LINEAR
);
// activate shader and bind textures
_shader
->
activate
();
img
->
bind
(
_shader
,
inputUnit
);
// Select the right shader for the 2D and 3D case
cgt
::
Shader
*
shader
=
isTexture2D
?
_shader2D
:
_shader3D
;
// activate shader and bind textures
shader
->
activate
();
img
->
bind
(
shader
,
inputUnit
);
// activate FBO and attach texture
_fbo
->
activate
();
glViewport
(
0
,
0
,
static_cast
<
GLsizei
>
(
resampledSize
.
x
),
static_cast
<
GLsizei
>
(
resampledSize
.
y
));
// render quad to compute difference measure by shader
for
(
int
z
=
0
;
z
<
resampledSize
.
z
;
++
z
)
{
float
zTexCoord
=
static_cast
<
float
>
(
z
)
/
static_cast
<
float
>
(
resampledSize
.
z
)
+
.5
f
/
static_cast
<
float
>
(
resampledSize
.
z
);
_shader
->
setUniform
(
"_zTexCoord"
,
zTexCoord
);
if
(
!
isTexture2D
)
{
float
zTexCoord
=
static_cast
<
float
>
(
z
)
/
static_cast
<
float
>
(
resampledSize
.
z
)
+
.5
f
/
static_cast
<
float
>
(
resampledSize
.
z
);
shader
->
setUniform
(
"_zTexCoord"
,
zTexCoord
);
}
_fbo
->
attachTexture
(
resultTexture
,
GL_COLOR_ATTACHMENT0
,
0
,
z
);
LGL_ERROR
;
QuadRdr
.
renderQuad
();
}
_fbo
->
detachAll
();
_fbo
->
deactivate
();
_
shader
->
deactivate
();
shader
->
deactivate
();
// put resulting image into DataContainer
ImageData
*
id
=
new
ImageData
(
3
,
resampledSize
,
1
);
ImageData
*
id
=
new
ImageData
(
img
->
getParent
()
->
getDimensionality
(),
resampledSize
,
img
->
getParent
()
->
getNumChannels
()
);
ImageRepresentationGL
::
create
(
id
,
resultTexture
);
const
ImageMappingInformation
&
imi
=
img
->
getParent
()
->
getMappingInformation
();
id
->
setMappingInformation
(
ImageMappingInformation
(
img
->
getSize
(),
imi
.
getOffset
(),
imi
.
getVoxelSize
()
/
p_resampleScale
.
getValue
(),
imi
.
getCustomTransformation
()));
...
...
modules/preprocessing/processors/glimageresampler.h
View file @
9436df53
...
...
@@ -84,7 +84,8 @@ namespace campvis {
virtual
void
updateResult
(
DataContainer
&
dataContainer
);
virtual
void
updateProperties
(
DataContainer
&
dataContainer
);
cgt
::
Shader
*
_shader
;
///< Shader for resampling
cgt
::
Shader
*
_shader2D
;
///< Shader for resampling 2D textures
cgt
::
Shader
*
_shader3D
;
///< Shader for resampling 3D textures
static
const
std
::
string
loggerCat_
;
};
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment