Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
9.2.2023: Due to updates GitLab will be unavailable for some minutes between 9:00 and 11:00.
Open sidebar
CAMP
campvis-public
Commits
307c3da2
Commit
307c3da2
authored
May 06, 2014
by
Christian Schulte zu Berge
Browse files
Added 2D projection mode to MprRenderer.
parent
ce2003de
Changes
3
Hide whitespace changes
Inline
Side-by-side
modules/vis/pipelines/mprdemo.cpp
View file @
307c3da2
...
...
@@ -64,6 +64,7 @@ namespace campvis {
_camera
.
addSharedProperty
(
&
_mprRenderer
.
p_camera
);
_mprRenderer
.
p_targetImageID
.
setValue
(
"MPR"
);
_mprRenderer
.
p_targetImageID
.
addSharedProperty
(
&
_compositor
.
p_firstImageId
);
_mprRenderer
.
p_planeSize
.
setValue
(
250.
f
);
_compositor
.
p_compositingMethod
.
selectByOption
(
RenderTargetCompositor
::
CompositingModeFirst
);
_compositor
.
p_targetImageId
.
setValue
(
"final"
);
...
...
modules/vis/processors/mprrenderer.cpp
View file @
307c3da2
...
...
@@ -51,6 +51,7 @@ namespace campvis {
,
p_planeNormal
(
"PlaneNormal"
,
"Clipping Plane Normal"
,
tgt
::
vec3
(
0.
f
,
0.
f
,
1.
f
),
tgt
::
vec3
(
-
1.
f
),
tgt
::
vec3
(
1.
f
),
tgt
::
vec3
(
.1
f
),
tgt
::
ivec3
(
2
))
,
p_planeDistance
(
"PlaneDistance"
,
"Clipping Plane Distance"
,
0.
f
,
-
1000.
f
,
1000.
f
,
1.
f
,
1
)
,
p_planeSize
(
"PlaneSize"
,
"Clipping Plane Size"
,
100.
f
,
0.
f
,
1000.
f
,
1.
f
,
1
)
,
p_use2DProjection
(
"Use3dRendering"
,
"Use 3D Rendering instead of 2D"
,
true
)
,
p_relativeToImageCenter
(
"RelativeToImageCenter"
,
"Construct Plane Relative to Image Center"
,
true
)
,
p_transferFunction
(
"transferFunction"
,
"Transfer Function"
,
new
SimpleTransferFunction
(
256
))
,
_shader
(
nullptr
)
...
...
@@ -61,6 +62,7 @@ namespace campvis {
addProperty
(
p_planeNormal
);
addProperty
(
p_planeDistance
);
addProperty
(
p_planeSize
);
addProperty
(
p_use2DProjection
,
INVALID_RESULT
|
INVALID_PROPERTIES
);
addProperty
(
p_relativeToImageCenter
);
addProperty
(
p_transferFunction
);
}
...
...
@@ -102,22 +104,38 @@ namespace campvis {
if
(
p_relativeToImageCenter
.
getValue
())
base
+=
img
->
getParent
()
->
getWorldBounds
().
center
();
// construct the four vertices
std
::
vector
<
tgt
::
vec3
>
vertices
;
vertices
.
push_back
(
base
+
inPlaneA
+
inPlaneB
);
vertices
.
push_back
(
base
-
inPlaneA
+
inPlaneB
);
vertices
.
push_back
(
base
-
inPlaneA
-
inPlaneB
);
vertices
.
push_back
(
base
+
inPlaneA
-
inPlaneB
);
FaceGeometry
slice
(
vertices
,
vertices
);
// construct the four texCoords
std
::
vector
<
tgt
::
vec3
>
texCoords
;
texCoords
.
push_back
(
base
+
inPlaneA
+
inPlaneB
);
texCoords
.
push_back
(
base
-
inPlaneA
+
inPlaneB
);
texCoords
.
push_back
(
base
-
inPlaneA
-
inPlaneB
);
texCoords
.
push_back
(
base
+
inPlaneA
-
inPlaneB
);
FaceGeometry
slice
(
texCoords
,
texCoords
);
// perform the rendering
glEnable
(
GL_DEPTH_TEST
);
_shader
->
activate
();
_shader
->
setIgnoreUniformLocationError
(
true
);
_shader
->
setUniform
(
"_projectionMatrix"
,
cam
.
getProjectionMatrix
());
_shader
->
setUniform
(
"_viewMatrix"
,
cam
.
getViewMatrix
());
tgt
::
Shader
::
IgnoreUniformLocationErrorGuard
guard
(
_shader
);
if
(
p_use2DProjection
.
getValue
())
{
// generate a camera position that simulates 2D rendering
// this way it is easier to achieve the correct aspect ratio in all cases
tgt
::
vec3
camPosition
=
base
-
p_planeSize
.
getValue
()
*
n
;
float
ratio
=
static_cast
<
float
>
(
getEffectiveViewportSize
().
x
)
/
getEffectiveViewportSize
().
y
;
// experimentally discovered:
// if the camera distance is half as big as the plane size, a field of view of
// 54 allows to see everything
float
fovy
=
54.
f
;
tgt
::
Camera
c
(
camPosition
,
base
,
inPlaneA
,
fovy
,
ratio
,
0.1
f
,
10000.
f
);
_shader
->
setUniform
(
"_projectionMatrix"
,
c
.
getProjectionMatrix
());
_shader
->
setUniform
(
"_viewMatrix"
,
c
.
getViewMatrix
());
}
else
{
_shader
->
setUniform
(
"_projectionMatrix"
,
cam
.
getProjectionMatrix
());
_shader
->
setUniform
(
"_viewMatrix"
,
cam
.
getViewMatrix
());
}
tgt
::
TextureUnit
inputUnit
,
tfUnit
;
img
->
bind
(
_shader
,
inputUnit
);
...
...
@@ -127,6 +145,7 @@ namespace campvis {
createAndAttachColorTexture
();
createAndAttachDepthTexture
();
glClear
(
GL_COLOR_BUFFER_BIT
|
GL_DEPTH_BUFFER_BIT
);
slice
.
render
(
GL_POLYGON
);
_shader
->
deactivate
();
...
...
@@ -152,7 +171,9 @@ namespace campvis {
if
(
img
!=
0
)
{
p_transferFunction
.
setVisible
(
img
->
getNumChannels
()
==
1
);
}
p_transferFunction
.
setImageHandle
(
img
.
getDataHandle
());
p_camera
.
setVisible
(
!
p_use2DProjection
.
getValue
());
validate
(
AbstractProcessor
::
INVALID_PROPERTIES
);
}
...
...
modules/vis/processors/mprrenderer.h
View file @
307c3da2
...
...
@@ -76,6 +76,7 @@ namespace campvis {
FloatProperty
p_planeDistance
;
///< Clipping plane distance
FloatProperty
p_planeSize
;
///< Size of clipping plane
BoolProperty
p_use2DProjection
;
///< Use 3D Rendering instead of 2D
BoolProperty
p_relativeToImageCenter
;
///< Flag whether to construct image plane relative to image center
TransferFunctionProperty
p_transferFunction
;
///< Transfer function
...
...
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