SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
AppDemoSceneVolumeRayCast.cpp
Go to the documentation of this file.
1 /**
2  * \file AppDemoSceneVolumeRayCast.cpp
3  * \brief Implementation for an SLScene inherited class
4  * \details For more info about App framework and the scene assembly see:
5  * https://cpvrlab.github.io/SLProject4/app-framework.html
6  * \date May 2024
7  * \authors Marino von Wattenwyl
8  * \copyright http://opensource.org/licenses/GPL-3.0
9  * \remarks Please use clangformat to format the code. See more code style on
10  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
11 */
12 
14 #include <SLAssetLoader.h>
15 #include <SLLightSpot.h>
16 #include <SLBox.h>
17 #include <AppCommon.h>
18 
19 //-----------------------------------------------------------------------------
21  : SLScene("Volume Ray Cast Test")
22 {
23  info("Volume Rendering of an angiographic MRI scan");
24 }
25 //-----------------------------------------------------------------------------
26 //! All assets the should be loaded in parallel must be registered in here.
28 {
29  // Load volume data into 3D texture
30  SLVstring mriImages;
31  for (SLint i = 0; i < 207; ++i)
32  mriImages.push_back(Utils::formatString(al.texturePath() + "i%04u_0000b.png", i));
33 
34  SLint clamping3D = GL_CLAMP_TO_EDGE;
35  if (SLGLState::instance()->getSLVersionNO() > "320")
36  clamping3D = 0x812D; // GL_CLAMP_TO_BORDER
37 
39  mriImages,
40  GL_LINEAR,
41  GL_LINEAR,
42  clamping3D,
43  clamping3D,
44  "mri_head_front_to_back",
45  false);
47  AppCommon::shaderPath + "VolumeRenderingRayCast.vert",
48  AppCommon::shaderPath + "VolumeRenderingRayCast.frag");
49 }
50 //-----------------------------------------------------------------------------
51 //! After parallel loading of the assets the scene gets assembled in here.
53 {
54  // Create transfer LUT 1D texture
55  SLVAlphaLUTPoint tfAlphas = {SLAlphaLUTPoint(0.00f, 0.00f),
56  SLAlphaLUTPoint(0.01f, 0.75f),
57  SLAlphaLUTPoint(1.00f, 1.00f)};
58  SLTexColorLUT* tf = new SLTexColorLUT(am,
59  tfAlphas,
60  CLUT_BCGYR);
61 
62  // Load shader and uniforms for volume size
64  "u_volumeX",
65  (SLfloat)_mriTex3D->images()[0]->width());
67  "u_volumeY",
68  (SLfloat)_mriTex3D->images()[0]->height());
70  "u_volumeZ",
71  (SLfloat)_mriTex3D->images().size());
72  _sp->addUniform1f(volX);
73  _sp->addUniform1f(volY);
74  _sp->addUniform1f(volZ);
75 
76  // Create volume rendering material
77  SLMaterial* matVR = new SLMaterial(am,
78  "matVR",
79  _mriTex3D,
80  tf,
81  nullptr,
82  nullptr,
83  _sp);
84 
85  // Create camera
86  SLCamera* cam1 = new SLCamera("Camera 1");
87  cam1->translation(0, 0, 3);
88  cam1->lookAt(0, 0, 0);
89  cam1->focalDist(3);
90  cam1->background().colors(SLCol4f(0, 0, 0));
91  cam1->setInitialState();
93 
94  // Set light
95  SLLightSpot* light1 = new SLLightSpot(am, this, 0.3f);
96  light1->powers(0.1f, 1.0f, 1.0f);
97  light1->attenuation(1, 0, 0);
98  light1->translation(5, 5, 5);
99 
100  // Assemble scene with box node
101  SLNode* scene = new SLNode("Scene");
102  root3D(scene);
103  scene->addChild(light1);
104  scene->addChild(new SLNode(new SLBox(am,
105  -1,
106  -1,
107  -1,
108  1,
109  1,
110  1,
111  "Box",
112  matVR)));
113  scene->addChild(cam1);
114 
115  sv->camera(cam1);
116 }
117 //-----------------------------------------------------------------------------
The AppCommon class holds the top-level instances of the app-demo.
Class declaration for an SLScene inherited class.
float SLfloat
Definition: SL.h:173
vector< SLstring > SLVstring
Definition: SL.h:201
int SLint
Definition: SL.h:170
@ UT_const
constant value
Definition: SLEnums.h:233
SLGLUniform< SLfloat > SLGLUniform1f
Definition: SLGLUniform.h:149
@ CLUT_BCGYR
blue to cyan to green to yellow to red
Definition: SLTexColorLUT.h:30
vector< SLAlphaLUTPoint > SLVAlphaLUTPoint
Definition: SLTexColorLUT.h:57
SLVec4< SLfloat > SLCol4f
Definition: SLVec4.h:237
static SLDeviceRotation devRot
Mobile device rotation from IMU.
Definition: AppCommon.h:64
static SLDeviceLocation devLoc
Mobile device location from GPS.
Definition: AppCommon.h:65
static SLstring shaderPath
Path to GLSL shader programs.
Definition: AppCommon.h:84
void assemble(SLAssetManager *am, SLSceneView *sv) override
After parallel loading of the assets the scene gets assembled in here.
void registerAssetsToLoad(SLAssetLoader &al) override
All scene specific assets have to be registered for async loading in here.
void addProgramToLoad(SLGLProgram *&program, const SLstring &vertShaderFile, const SLstring &fragShaderFile)
Add generic GLSL program with shader files to load.
SLstring texturePath() const
Definition: SLAssetLoader.h:71
void addTextureToLoad(SLGLTexture *&texture, const SLstring &path, SLint min_filter=GL_LINEAR_MIPMAP_LINEAR, SLint mag_filter=GL_LINEAR, SLTextureType type=TT_unknown, SLint wrapS=GL_REPEAT, SLint wrapT=GL_REPEAT)
Add 2D textures with internal image allocation.
Toplevel holder of the assets meshes, materials, textures and shaders.
void colors(const SLCol4f &uniformColor)
Sets a uniform background color.
Axis aligned box mesh.
Definition: SLBox.h:31
Active or visible camera node class.
Definition: SLCamera.h:54
void devRotLoc(SLDeviceRotation *devRot, SLDeviceLocation *devLoc)
Definition: SLCamera.h:120
void focalDist(const SLfloat f)
Definition: SLCamera.h:116
SLBackground & background()
Definition: SLCamera.h:165
void addUniform1f(SLGLUniform1f *u)
add float uniform
static SLGLState * instance()
Public static instance getter for singleton pattern.
Definition: SLGLState.h:74
CVVImage & images()
Definition: SLGLTexture.h:225
Template for a single GLSL uniform variable.
Definition: SLGLUniform.h:24
void attenuation(const SLfloat kConstant, const SLfloat kLinear, const SLfloat kQuadratic)
Definition: SLLight.h:116
void powers(SLfloat ambiPow, SLfloat diffPow, SLfloat specPow, const SLCol4f &ambiDiffSpecCol=SLCol4f::WHITE)
Sets the ambient, diffuse and specular powers all with the same color.
Definition: SLLight.h:74
SLLightSpot class for a spot light source.
Definition: SLLightSpot.h:36
Defines a standard CG material with textures and a shader program.
Definition: SLMaterial.h:56
SLNode represents a node in a hierarchical scene graph.
Definition: SLNode.h:147
void addChild(SLNode *child)
Definition: SLNode.cpp:207
void translation(const SLVec3f &pos, SLTransformSpace relativeTo=TS_parent)
Definition: SLNode.cpp:828
void setInitialState()
Definition: SLNode.cpp:1084
void lookAt(SLfloat targetX, SLfloat targetY, SLfloat targetZ, SLfloat upX=0, SLfloat upY=1, SLfloat upZ=0, SLTransformSpace relativeTo=TS_world)
Definition: SLNode.h:652
The SLScene class represents the top level instance holding the scene structure.
Definition: SLScene.h:47
SLNode * root3D()
Definition: SLScene.h:99
friend class SLNode
Definition: SLScene.h:48
SLstring & info()
Definition: SLScene.h:102
SceneView class represents a dynamic real time 3D view onto the scene.
Definition: SLSceneView.h:69
void camera(SLCamera *camera)
Definition: SLSceneView.h:145
SLTexColorLUT defines a lookup table as an 1D texture of (256) RGBA values.
Definition: SLTexColorLUT.h:70
string formatString(string fmt_str,...)
Returns a formatted string as sprintf.
Definition: Utils.cpp:320
Alpha point with alpha value and position value between 0-1.
Definition: SLTexColorLUT.h:51