SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
AppDemoSceneVolumeRayCastLighted.cpp
Go to the documentation of this file.
1 /**
2  * \file AppDemoSceneVolumeRayCastLighted.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("Lighted Volume Ray Cast Test")
22 {
23  info("Lighted 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  true);
46 
47  al.addLoadTask([=]() { _mriTex3D->calc3DGradients(1); });
48  //al.addLoadTask([=]()
49  // { _mriTex3D->smooth3DGradients(1); });
50 
52  AppCommon::shaderPath + "VolumeRenderingRayCast.vert",
53  AppCommon::shaderPath + "VolumeRenderingRayCastLighted.frag");
54 }
55 //-----------------------------------------------------------------------------
56 //! After parallel loading of the assets the scene gets assembled in here.
58  SLSceneView* sv)
59 {
60  // Create transfer LUT 1D texture
61  SLVAlphaLUTPoint tfAlphas = {SLAlphaLUTPoint(0.00f, 0.00f),
62  SLAlphaLUTPoint(0.01f, 0.75f),
63  SLAlphaLUTPoint(1.00f, 1.00f)};
64  SLTexColorLUT* tf = new SLTexColorLUT(am,
65  tfAlphas,
66  CLUT_BCGYR);
67 
69  "u_volumeX",
70  (SLfloat)_mriTex3D->images()[0]->width());
72  "u_volumeY",
73  (SLfloat)_mriTex3D->images()[0]->height());
75  "u_volumeZ",
76  (SLfloat)_mriTex3D->images().size());
77  _sp->addUniform1f(volX);
78  _sp->addUniform1f(volY);
79  _sp->addUniform1f(volZ);
80 
81  // Create volume rendering material
82  SLMaterial* matVR = new SLMaterial(am,
83  "matVR",
84  _mriTex3D,
85  tf,
86  nullptr,
87  nullptr,
88  _sp);
89 
90  // Create camera
91  SLCamera* cam1 = new SLCamera("Camera 1");
92  cam1->translation(0, 0, 3);
93  cam1->lookAt(0, 0, 0);
94  cam1->focalDist(3);
95  cam1->background().colors(SLCol4f(0, 0, 0));
96  cam1->setInitialState();
98 
99  // Set light
100  SLLightSpot* light1 = new SLLightSpot(am, this, 0.3f);
101  light1->powers(0.1f, 1.0f, 1.0f);
102  light1->attenuation(1, 0, 0);
103  light1->translation(5, 5, 5);
104 
105  // Assemble scene with box node
106  SLNode* scene = new SLNode("Scene");
107  root3D(scene);
108  scene->addChild(light1);
109  scene->addChild(new SLNode(new SLBox(
110  am,
111  -1,
112  -1,
113  -1,
114  1,
115  1,
116  1,
117  "Box",
118  matVR)));
119  scene->addChild(cam1);
120 
121  sv->camera(cam1);
122 }
123 //-----------------------------------------------------------------------------
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 addLoadTask(SLAssetLoadTask task)
Add generic task.
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
void calc3DGradients(SLint sampleRadius, const function< void(int)> &onUpdateProgress=nullptr)
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