From 7304df8d56b6c825b6afc7788ef2db9421d64668 Mon Sep 17 00:00:00 2001 From: "Ruben J. Garcia-Hernandez" <garcia@lrz.de> Date: Sun, 27 Sep 2020 12:32:12 +0200 Subject: [PATCH] Add cutplanes support, double-sided normals and explicit iso names (from standard NOMAD VR code). --- FluidDynamics/NOMADVRLib/ConfigFile.cpp | 34 +++++++++++++++++++++++ FluidDynamics/NOMADVRLib/ConfigFile.h | 10 +++++++ FluidDynamics/NOMADVRLib/IsoShaders.cpp | 9 +++--- FluidDynamics/hellovr_opengl_main.cpp | 37 +++++++++++++++++++------ 4 files changed, 77 insertions(+), 13 deletions(-) diff --git a/FluidDynamics/NOMADVRLib/ConfigFile.cpp b/FluidDynamics/NOMADVRLib/ConfigFile.cpp index d273a9f..4e7786d 100644 --- a/FluidDynamics/NOMADVRLib/ConfigFile.cpp +++ b/FluidDynamics/NOMADVRLib/ConfigFile.cpp @@ -30,6 +30,7 @@ int ISOS; int TIMESTEPS; float **isocolours; // [ISOS][4]; const char **plyfiles; +const char *** fullplyfiles; float **translations; float userpos[3]; float scaling; @@ -73,6 +74,7 @@ bool showcontrollers; bool gazenavigation; int transparencyquality; float nearclip, farclip; +float nearcut, farcut; //markers such as hole positions and electron positions float ** markers; @@ -82,6 +84,8 @@ float cubetrans[3]; float animationspeed; float movementspeed; +menubutton_t menubutton; + //added variables for move with Particles int isoBufferSize; float arrowScalingVelocity; @@ -315,6 +319,23 @@ int loadConfigFile(const char * f) } } + else if (!strcmp(s, "fullvalues")) { + if (TIMESTEPS == 0 || ISOS == 0) { + eprintf("full values with no previous correct isos or timesteps parameter\n"); + fclose(F); + return -3; + } + fullplyfiles = new const char **[TIMESTEPS]; + for (int j = 0; j < TIMESTEPS; j++) { + for (int i = 0; i < ISOS; i++) { + r = readString(F, s); + if (r != 0) + return -14; + free((void*)(fullplyfiles[j][i])); + fullplyfiles[j][i] = strdup(s); + } + } + } else if (!strcmp(s, "colours")) { if (ISOS == 0) { eprintf( "colours with no previous correct isos parameter\n"); @@ -622,6 +643,10 @@ int loadConfigFile(const char * f) r=fscanf (F, "%f %f", &nearclip, &farclip); if (r<2) eprintf ("Error reading clippingplanes values"); + } else if (!strcmp(s, "cutplanes")) { + r = fscanf(F, "%f %f", &nearcut, &farcut); + if (r<2) + eprintf("Error reading clippingplanes values"); }else if (!strcmp (s, "bondscolour")) { r=fscanf (F, "%f %f %f", bondscolours, bondscolours+1, bondscolours+2); if (r<3) @@ -642,6 +667,15 @@ int loadConfigFile(const char * f) r=fscanf (F, "%f", &animationspeed); if (r<1) eprintf ("Error reading animationspeed"); + } else if (!strcmp(s, "menubutton")) { + r = fscanf(F, "%99s", s); + if (!strcmp(s, "Record")) + menubutton = Record; + else if (!strcmp(s, "CuttingPlane")) + menubutton = CuttingPlane; + else if (!strcmp (s, "Nothing")) + menubutton = Nothing; + else eprintf ("Unknown menubutton parameter %s\n", s); } else if (!strcmp (s, "movementspeed")) { r=fscanf (F, "%f", &movementspeed); if (r<1) diff --git a/FluidDynamics/NOMADVRLib/ConfigFile.h b/FluidDynamics/NOMADVRLib/ConfigFile.h index b3ade3d..607efe7 100644 --- a/FluidDynamics/NOMADVRLib/ConfigFile.h +++ b/FluidDynamics/NOMADVRLib/ConfigFile.h @@ -25,6 +25,7 @@ extern int ISOS; extern int TIMESTEPS; extern float **isocolours; // [ISOS][4]; extern const char **plyfiles; +extern const char *** fullplyfiles; //explicit plyfiles for all timesteps extern float **translations; extern float userpos[3]; extern float scaling; @@ -69,6 +70,7 @@ extern bool gazenavigation; extern int transparencyquality; extern float nearclip, farclip; +extern float nearcut, farcut; extern float animationspeed; //how fast to change to next timestep extern float movementspeed; //how fast to move the user @@ -89,4 +91,12 @@ extern float arrowScalingVelocity; extern float arrowScalingAcceleration; extern float arrowScalingCross; +typedef enum { + Record, + CuttingPlane, + Nothing +} menubutton_t; + +extern menubutton_t menubutton; + #endif //__CONFIGFILE_H diff --git a/FluidDynamics/NOMADVRLib/IsoShaders.cpp b/FluidDynamics/NOMADVRLib/IsoShaders.cpp index 1b561a8..84ef965 100644 --- a/FluidDynamics/NOMADVRLib/IsoShaders.cpp +++ b/FluidDynamics/NOMADVRLib/IsoShaders.cpp @@ -50,8 +50,9 @@ const char * const IsoShaders [] = {"Iso Renderer", "void main()\n" "{\n" "lowp vec3 nn=normalize(vnormal);" - "lowp float a=max(0.0, dot(nn, vec3(0,sqrt(2.0)/2.0,sqrt(2.0)/2.0)));\n" - "lowp float b=max(0.0, dot(nn, vec3(0,0,1)));\n" + //two faced normal + "lowp float a=abs (dot(nn, vec3(0,sqrt(2.0)/2.0,sqrt(2.0)/2.0)));\n" + "lowp float b=abs (dot(nn, vec3(0,0,1))); "highp vec4 res=vcolor;\n" " outputColor = vec4 ((res.rgb) * (0.2 + 0.2*a + 0.3*b), vcolor.a);\n" "}\n" @@ -111,8 +112,8 @@ const char *const IsoTransparentShaders [] = {"Iso Transparent Renderer", "if ((pos.z/pos.w+1.0)/2.0 <= mytex.r+0.00001 ) discard;\n" "lowp vec3 nn=normalize(n);" - "lowp float a=max(0.0, dot(nn, vec3(0,sqrt(2.0)/2.0,sqrt(2.0)/2.0)));\n" - "lowp float b=max(0.0, dot(nn, vec3(0,0,1)));\n" + "lowp float a=abs(dot(nn, vec3(0,sqrt(2.0)/2.0,sqrt(2.0)/2.0)));\n" + "lowp float b=abs(dot(nn, vec3(0,0,1)));\n" "highp vec4 res=color;\n" //"outputColor = vec4(pos.x/pos.w*0.5+0.5, pos.y/pos.w*0.5+0.5, 0,1);\n" " outputColor = vec4 ((res.rgb) * (0.2 + 0.2*a + 0.3*b), color.a);\n" diff --git a/FluidDynamics/hellovr_opengl_main.cpp b/FluidDynamics/hellovr_opengl_main.cpp index 867150a..fc910e9 100644 --- a/FluidDynamics/hellovr_opengl_main.cpp +++ b/FluidDynamics/hellovr_opengl_main.cpp @@ -1294,10 +1294,22 @@ bool CMainApplication::HandleInput() else if(unDevice !=firstdevice && seconddevice==-1) seconddevice=unDevice; - if (firstdevice==unDevice) - savetodisk = !savetodisk; - else + if (firstdevice==unDevice) { + if (menubutton==Record) + savetodisk = !savetodisk; + else if (menubutton == CuttingPlane) { + if (firstdevice != -1 && seconddevice != -1) { + static float origNearclip = nearclip; + static float t = M_PI * 3.0f / 2.0f; + nearclip = nearcut + (farcut - nearcut) / 2.0f + sinf(t)*(farcut - nearcut) / 2.0f; + SetupCameras(); + t += 0.1f; + } + } + + } else { showAtoms= !showAtoms; + } } else if (buttonPressed[1][unDevice] && 0 == (state.ulButtonPressed&vr::ButtonMaskFromId(vr::k_EButton_ApplicationMenu))) { @@ -2415,8 +2427,10 @@ void CMainApplication::SetupIsosurfaces() SDL_GL_SwapWindow(m_pWindow); //http://stackoverflow.com/questions/9052224/error4error-c3861-snprintf-identifier-not-found - sprintf(tmpname, "%s%s%d-%s.ply", PATH, lods[currentlod], time, plyfiles[p % ISOS]); - + if (!fullplyfiles) + sprintf(tmpname, "%s%s%d-%s.ply", PATH, lods[currentlod], time, plyfiles[p % ISOS]); + else + sprintf(tmpname, "%s%s", PATH, fullplyfiles[time][p%ISOS]); vertdataarray[currentlod][p].clear(); vertindicesarray[currentlod][p].clear(); @@ -2951,8 +2965,10 @@ void CMainApplication::LoadIsosurfacesDyn(int buffer){ //Loading Screen //http://stackoverflow.com/questions/9052224/error4error-c3861-snprintf-identifier-not-found - sprintf(tmpname, "%s%d-%s.ply", PATH, time, plyfiles[p % ISOS]); - + if (!fullplyfiles) + sprintf(tmpname, "%s%d-%s.ply", PATH, time, plyfiles[p % ISOS]); + else + sprintf(tmpname, "%s%s", PATH, fullplyfiles[time][p%ISOS]); vertdataarrayDyn[p].clear(); vertindicesarrayDyn[p].clear(); @@ -3124,7 +3140,10 @@ int CMainApplication::sdl_LoadIsos(){ for (int p = 0; p < myNUMPLY; p++) { //http://stackoverflow.com/questions/9052224/error4error-c3861-snprintf-identifier-not-found - sprintf(tmpname, "%s%d-%s.ply", PATH, time, plyfiles[p % ISOS]); + if (!fullplyfiles) + sprintf(tmpname, "%s%d-%s.ply", PATH, time, plyfiles[p % ISOS]); + else + sprintf(tmpname, "%s%s", PATH, fullplyfiles[time][p%ISOS]); //eprintf("%s",tmpname); vertdataarrayDyn[p].clear(); @@ -5044,4 +5063,4 @@ int main(int argc, char *argv[]) cleanConfig(); _CrtDumpMemoryLeaks(); return 0; -} \ No newline at end of file +} -- GitLab