Commit af4a639d authored by Ruben Jesus Garcia Hernandez's avatar Ruben Jesus Garcia Hernandez
Browse files

Allow choosing atom glyph in GearVR

parent d2ee02e6
......@@ -3,6 +3,7 @@
#include "ConfigFile.h"
#include "atoms.hpp"
#include "eprintf.h"
#include "polyhedron.h"
const char * PATH;
const char * SCREENSHOT;
......@@ -29,7 +30,7 @@ float abc[3][3]; //basis vectors
bool has_abc = false;
int repetitions[3];
Solid *solid;
const char * loadConfigFileErrors[] =
{
......@@ -48,6 +49,7 @@ const char * loadConfigFileErrors[] =
"Non-periodic, but repetitions requested", //-12
"No basis vectors, but repetitions requested", //-13
"Error loading config file",// -14
"Error reading atomglyph", //-15
"Error loading xyz file, add 100 to see the error",//<-100
"Error loading cube file, add 100 to see the error",//<-200
"Error loading json file, add 200 to see the error",//<-300
......@@ -129,6 +131,7 @@ int loadConfigFile(const char * f)
repetitions[i]=1;
for (int i=0;i<3;i++)
userpos[i] = 0;
solid=0;
//
FILE *F = fopen(f, "r");
if (F == 0)
......@@ -328,6 +331,18 @@ int loadConfigFile(const char * f)
if (r!=1)
return -11;
}
} else if (!strcmp(s, "atomglyph")) {
r=fscanf (F, "%s", s);
if (r==0)
return -15;
if (!strcmp(s, "icosahedron"))
solid=new Solid(Solid::Type::Icosahedron);
else if(!strcmp(s, "octahedron"))
solid=new Solid(Solid::Type::Octahedron);
else if(!strcmp(s, "tetrahedron"))
solid=new Solid(Solid::Type::Tetrahedron);
else
return -15;
}
else {
eprintf( "Unrecognized parameter %s\n", s);
......
#ifndef __CONFIGFILE_H
#define __CONFIGFILE_H
#include <vector>
#include "polyhedron.h"
extern const char * PATH;
extern const char * SCREENSHOT;
......@@ -28,6 +29,8 @@ extern bool has_abc;
extern int repetitions[3];
extern Solid *solid;
extern const char * loadConfigFileErrors[];
int loadConfigFile(const char * f);
......
......@@ -12,7 +12,7 @@
#include "atoms.hpp"
#include "rapidjson/document.h"
#include "rapidjson/filereadstream.h"
#include "happyhttp.h"
#include "happyhttp/happyhttp.h"
//FIXME, support more platforms
#ifdef WIN32
......
......@@ -20,10 +20,10 @@ int readAtomsJsonURL (const char *const f, int **numatoms, int *timesteps, float
#if defined(WIN32)
int readAtomsJsonURLwget (const char *const f, int **numatoms, int *timesteps, float ***pos, float abc[3][3], std::vector<float>** clonedAtoms);
#endif
const float MISSINGRADIUS=0.2;
const float MISSINGR=1;
const float MISSINGG=1;
const float MISSINGB=1;
const float MISSINGRADIUS=0.2f;
const float MISSINGR=1.f;
const float MISSINGG=1.f;
const float MISSINGB=1.f;
extern const char * readAtomsXYZErrors[];
extern const char * readAtomsCubeErrors[];
......
......@@ -64,15 +64,15 @@ if (!numAtoms)
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glDisableVertexAttribArray(3);
//eprintf ("SetupAtomsNoTess 5, totalatoms=%d, nVerts=%d", totalatoms, SOLID::nVerts);
float *tmp = new float[SOLID::nVerts * 7 * totalatoms];
//eprintf ("SetupAtomsNoTess 5, totalatoms=%d, nVerts=%d", totalatoms, solid->nVerts);
float *tmp = new float[solid->nVerts * 7 * totalatoms];
//eprintf ("SetupAtomsNoTess 6");
#ifdef INDICESGL32
int *tmpi = new int[SOLID::nFaces*3 * totalatoms];
int *tmpi = new int[solid->nFaces*3 * totalatoms];
//eprintf ("SetupAtomsNoTess 7");
int *currenti=tmpi;
#else
unsigned short *tmpi = new unsigned short[SOLID::nFaces*3 * totalatoms];
unsigned short *tmpi = new unsigned short[solid->nFaces*3 * totalatoms];
//eprintf ("SetupAtomsNoTess 7B");
unsigned short *currenti=tmpi;
#endif
......@@ -83,20 +83,20 @@ if (!numAtoms)
for (int a = 0; a < numAtoms[p]-(p==0?0:numAtoms[p-1]); a++) {
const int atomNumber = static_cast<int>(atoms[p][4 * a + 3]);
const float radius = atomColours[atomNumber][3]/**atomScaling*/;
for (int i = 0; i < SOLID::nVerts; i++) { //verts
for (int i = 0; i < solid->nVerts; i++) { //verts
for (int k = 0; k < 3; k++) {
*current++ = SOLID::Verts[3 * i + k]* radius +atoms[p][4 * a + k]; //pos
*current++ = solid->Verts[3 * i + k]* radius +atoms[p][4 * a + k]; //pos
}
for (int k = 0; k < 3; k++) {
*current++ = SOLID::Verts[3 * i + k]; //normal
*current++ = solid->Verts[3 * i + k]; //normal
}
*current++ = atomNumber;
*current++ = static_cast<float>(atomNumber);
} //i
for (int i = 0; i < SOLID::nFaces * 3; i++)
*currenti++ = SOLID::Faces[i] + (a+(p==0?0:numAtoms[p-1]))*SOLID::nVerts;
for (int i = 0; i < solid->nFaces * 3; i++)
*currenti++ = solid->Faces[i] + (a+(p==0?0:numAtoms[p-1]))*solid->nVerts;
} //a
} //p
glBufferData(GL_ARRAY_BUFFER, sizeof(float) *totalatoms* 7 * SOLID::nVerts, tmp,
glBufferData(GL_ARRAY_BUFFER, sizeof(float) *totalatoms* 7 * solid->nVerts, tmp,
GL_STATIC_DRAW);
if ((e = glGetError()) != GL_NO_ERROR)
eprintf("opengl error %d, glBufferData, l %d\n", e, __LINE__);
......@@ -107,7 +107,7 @@ if (!numAtoms)
#else
sizeof(unsigned int)
#endif
* totalatoms * 3 * SOLID::nFaces, tmpi, GL_STATIC_DRAW);
* totalatoms * 3 * solid->nFaces, tmpi, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 7*sizeof(float), (const void *)0);
......@@ -125,15 +125,15 @@ if (!numAtoms)
eprintf("opengl error %d, end of SetupAtoms, l %d\n", e, __LINE__);
//FIXME TODO: cloned atoms
tmp = new float[SOLID::nVerts * 7 * numClonedAtoms];
tmp = new float[solid->nVerts * 7 * numClonedAtoms];
current=tmp;
//eprintf ("SetupAtomsNoTess 6");
#ifdef INDICESGL32
tmpi = new int[SOLID::nFaces*3 * numClonedAtoms];
tmpi = new int[solid->nFaces*3 * numClonedAtoms];
//eprintf ("SetupAtomsNoTess 7");
currenti=tmpi;
#else
tmpi = new unsigned short[SOLID::nFaces*3 * numClonedAtoms];
tmpi = new unsigned short[solid->nFaces*3 * numClonedAtoms];
//eprintf ("SetupAtomsNoTess 7B");
currenti=tmpi;
#endif
......@@ -142,17 +142,17 @@ if (!numAtoms)
for (int a = 0; a < numClonedAtoms; a++) {
const int atomNumber = static_cast<int>(clonedAtoms[0][4 * a + 3]);
const float radius = atomColours[atomNumber][3]/**atomScaling*/;
for (int i = 0; i < SOLID::nVerts; i++) { //verts
for (int i = 0; i < solid->nVerts; i++) { //verts
for (int k = 0; k < 3; k++) {
*current++ = SOLID::Verts[3 * i + k]* radius +clonedAtoms[0][4 * a + k]; //pos
*current++ = solid->Verts[3 * i + k]* radius +clonedAtoms[0][4 * a + k]; //pos
}
for (int k = 0; k < 3; k++) {
*current++ = SOLID::Verts[3 * i + k]; //normal
*current++ = solid->Verts[3 * i + k]; //normal
}
*current++ = atomNumber;
*current++ = static_cast<float>(atomNumber);
} //i
for (int i = 0; i < SOLID::nFaces * 3; i++)
*currenti++ = SOLID::Faces[i] + a*SOLID::nVerts;
for (int i = 0; i < solid->nFaces * 3; i++)
*currenti++ = solid->Faces[i] + a*solid->nVerts;
} //a
//eprintf ("After For 2");
......@@ -167,7 +167,7 @@ if (!numAtoms)
glEnableVertexAttribArray(2);
glDisableVertexAttribArray(3);
glBufferData(GL_ARRAY_BUFFER, sizeof(float) *numClonedAtoms* 7 * SOLID::nVerts, tmp,
glBufferData(GL_ARRAY_BUFFER, sizeof(float) *numClonedAtoms* 7 * solid->nVerts, tmp,
GL_STATIC_DRAW);
if ((e = glGetError()) != GL_NO_ERROR)
eprintf("opengl error %d, glBufferData, l %d\n", e, __LINE__);
......@@ -178,7 +178,7 @@ if (!numAtoms)
#else
sizeof(unsigned int)
#endif
* numClonedAtoms * 3 * SOLID::nFaces, tmpi, GL_STATIC_DRAW);
* numClonedAtoms * 3 * solid->nFaces, tmpi, GL_STATIC_DRAW);
//eprintf ("After bufferdata, element array buffer");
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 7*sizeof(float), (const void *)0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 7 * sizeof(float), (const void *)(3*sizeof(float)));
......
......@@ -3,8 +3,6 @@
#include "MyGL.h"
#define SOLID Icosahedron
GLenum atomTexture(GLuint t);
GLenum SetupAtoms(GLuint **AtomVAO, GLuint **AtomVertBuffer);
GLenum SetupAtomsNoTess (GLuint **AtomVAO, GLuint **AtomVertBuffer, GLuint **AtomIndexBuffer);
......
#ifndef __POLYHEDRON_H
#define __POLYHEDRON_H
class Icosahedron {
public:
static const int nFaces;
......@@ -21,3 +24,38 @@ public:
static const int nVerts;
static const float Verts[];
};
class Solid {
public:
enum Type {
Icosahedron,
Octahedron,
Tetrahedron
};
Solid(Type t) {
switch (t) {
case Icosahedron:
nFaces=Icosahedron::nFaces;
Faces=Icosahedron::Faces;
nVerts=Icosahedron::nVerts;
Verts=Icosahedron::Verts;
break;
case Octahedron:
nFaces=Octahedron::nFaces;
Faces=Octahedron::Faces;
nVerts=Octahedron::nVerts;
Verts=Octahedron::Verts;
case Tetrahedron:
nFaces=Tetrahedron::nFaces;
Faces=Tetrahedron::Faces;
nVerts=Tetrahedron::nVerts;
Verts=Tetrahedron::Verts;
}
}
int nFaces;
const int *Faces;
int nVerts;
const float *Verts;
};
#endif // __POLYHEDRON_H
\ No newline at end of file
......@@ -15,12 +15,12 @@ Copyright : Copyright 2014 Oculus VR, LLC. All Rights reserved.
#include "GuiSys.h"
#include "OVR_Locale.h"
#include "atoms.hpp"
#include "ConfigFile.h"
#include "atomsGL.h"
#include "UnitCellShaders.h"
#include "TessShaders.h"
#include "polyhedron.h"
#include "NOMADVRLib/atoms.hpp"
#include "NOMADVRLib/ConfigFile.h"
#include "NOMADVRLib/atomsGL.h"
#include "NOMADVRLib/UnitCellShaders.h"
#include "NOMADVRLib/TessShaders.h"
#include "NOMADVRLib/polyhedron.h"
using namespace OVR;
......@@ -59,7 +59,7 @@ jlong Java_oculus_MainActivity_nativeSetAppInterface( JNIEnv * jni, jclass clazz
#define GL( func ) func;
#endif
#include "rply.h"
#include "rply/rply.h"
//static int vertex_cb(p_ply_argument argument);
//static int face_cb(p_ply_argument argument);
......@@ -148,8 +148,10 @@ void OvrApp::OneTimeInit( const char * fromPackage, const char * launchIntentJSO
}
}
if (!solid) {
LOG("No atom glyph specified, using Icosahedron");
solid=new Solid(Solid::Type::Icosahedron);
}
LOG("OneTimeInit, 2");
const ovrJava * java = app->GetJava();
SoundEffectContext = new ovrSoundEffectContext( *java->Env, java->ActivityObject );
......@@ -312,7 +314,7 @@ void OvrApp::RenderAtoms(const float *m) //m[16]
glUseProgram(AtomsP);
glUniformMatrix4fv(AtomMatrixLoc, 1, GL_FALSE, m);
if (currentSet==0) {
glDrawElements(GL_TRIANGLES, numAtoms[currentSet]* 3 * SOLID::nFaces,
glDrawElements(GL_TRIANGLES, numAtoms[currentSet]* 3 * solid->nFaces,
#ifndef INDICESGL32
GL_UNSIGNED_SHORT,
#else
......@@ -322,12 +324,12 @@ void OvrApp::RenderAtoms(const float *m) //m[16]
} else {
//eprintf("draw elements triangles, %d, unsigned_int, %d", numAtoms[currentSet]-numAtoms[currentSet-1],
// numAtoms[currentSet-1]);
//eprintf ("solid::nfaces=%d", SOLID::nFaces);
glDrawElements(GL_TRIANGLES, (numAtoms[currentSet]-numAtoms[currentSet-1]) * 3 * SOLID::nFaces,
//eprintf ("solid->nfaces=%d", solid->nFaces);
glDrawElements(GL_TRIANGLES, (numAtoms[currentSet]-numAtoms[currentSet-1]) * 3 * solid->nFaces,
#ifndef INDICESGL32
GL_UNSIGNED_SHORT, (void*)(numAtoms[currentSet-1]*sizeof(unsigned short)*3*SOLID::nFaces)
GL_UNSIGNED_SHORT, (void*)(numAtoms[currentSet-1]*sizeof(unsigned short)*3*solid->nFaces)
#else
GL_UNSIGNED_INT, (void*)(numAtoms[currentSet-1]*sizeof(unsigned int)*3*SOLID::nFaces)
GL_UNSIGNED_INT, (void*)(numAtoms[currentSet-1]*sizeof(unsigned int)*3*solid->nFaces)
#endif
);
}
......@@ -337,7 +339,7 @@ void OvrApp::RenderAtoms(const float *m) //m[16]
//eprintf("numClonedAtoms %d, painting", numClonedAtoms);
if (numClonedAtoms!=0 && currentSet==0) {
glBindVertexArray(AtomVAO[1]);
glDrawElements(GL_TRIANGLES, numClonedAtoms* 3 * SOLID::nFaces,
glDrawElements(GL_TRIANGLES, numClonedAtoms* 3 * solid->nFaces,
#ifndef INDICESGL32
GL_UNSIGNED_SHORT,
#else
......
......@@ -152,7 +152,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;_CRT_NONSTDC_NO_DEPRECATE;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<AdditionalIncludeDirectories>..;../../headers;../thirdparty/glew/glew-1.11.0/include;..\thirdparty\sdl2-2.0.3\include;Y:\v2t\software\rapidjson\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..;../../headers;../thirdparty/glew/glew-1.11.0/include;..\thirdparty\sdl2-2.0.3\include;Y:\v2t\software\rapidjson\include;Y:\v2t\software\openvr\openvr-0.9.19\samples\TimestepData</AdditionalIncludeDirectories>
<EnablePREfast>false</EnablePREfast>
</ClCompile>
<Link>
......@@ -169,8 +169,17 @@
<ClCompile Include="..\shared\lodepng.cpp" />
<ClCompile Include="..\shared\Matrices.cpp" />
<ClCompile Include="..\shared\pathtools.cpp" />
<ClCompile Include="happyhttp\happyhttp.cpp" />
<ClCompile Include="hellovr_opengl_main.cpp" />
<ClCompile Include="hsv.c" />
<ClCompile Include="NOMADVRLib\atoms.cpp" />
<ClCompile Include="NOMADVRLib\atomsGL.cpp" />
<ClCompile Include="NOMADVRLib\CompileGLShader.cpp" />
<ClCompile Include="NOMADVRLib\ConfigFile.cpp" />
<ClCompile Include="NOMADVRLib\polyhedron.cpp" />
<ClCompile Include="NOMADVRLib\TessShaders.cpp" />
<ClCompile Include="NOMADVRLib\UnitCellShaders.cpp" />
<ClCompile Include="rply\rply.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\shared\lodepng.h" />
......@@ -179,6 +188,15 @@
<ClInclude Include="..\shared\Vectors.h" />
<ClInclude Include="hsv.h" />
<ClInclude Include="NOMADViveT.h" />
<ClInclude Include="NOMADVRLib\atoms.hpp" />
<ClInclude Include="NOMADVRLib\atomsGL.h" />
<ClInclude Include="NOMADVRLib\CompileGLShader.h" />
<ClInclude Include="NOMADVRLib\ConfigFile.h" />
<ClInclude Include="NOMADVRLib\eprintf.h" />
<ClInclude Include="NOMADVRLib\MyGL.h" />
<ClInclude Include="NOMADVRLib\polyhedron.h" />
<ClInclude Include="NOMADVRLib\TessShaders.h" />
<ClInclude Include="NOMADVRLib\UnitCellShaders.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="NOMADViveT.rc" />
......
......@@ -36,6 +36,33 @@
<ClCompile Include="hsv.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="NOMADVRLib\atoms.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="NOMADVRLib\ConfigFile.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="NOMADVRLib\atomsGL.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="NOMADVRLib\TessShaders.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="NOMADVRLib\UnitCellShaders.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="NOMADVRLib\CompileGLShader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="NOMADVRLib\polyhedron.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="happyhttp\happyhttp.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="rply\rply.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\shared\lodepng.h">
......@@ -56,6 +83,33 @@
<ClInclude Include="NOMADViveT.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="NOMADVRLib\atoms.hpp">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="NOMADVRLib\atomsGL.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="NOMADVRLib\TessShaders.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="NOMADVRLib\eprintf.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="NOMADVRLib\MyGL.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="NOMADVRLib\CompileGLShader.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="NOMADVRLib\ConfigFile.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="NOMADVRLib\UnitCellShaders.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="NOMADVRLib\polyhedron.h">
<Filter>Source Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="NOMADViveT.rc">
......
......@@ -38,6 +38,8 @@
#include "NOMADVRLib/CompileGLShader.h"
#include "NOMADVRLib/polyhedron.h"
static int vertex_cb(p_ply_argument argument);
static int face_cb(p_ply_argument argument);
......@@ -2997,6 +2999,9 @@ int main(int argc, char *argv[])
return -100+r;
}
if (solid)
MessageBoxA(0, "Only spheres implemented as atom glyphs in HTC Vive", "Atom Glyph", 0);
CMainApplication *pMainApplication = new CMainApplication( argc, argv );
if (pMainApplication == nullptr) {
......
......@@ -29,6 +29,16 @@ installer.
<!--Wget.exe should be in the PATH to enable https and ftp support.
Download it <a href="https://eternallybored.org/misc/wget/">here</a>.-->
</p>
<h2>
NOMAD Virtual Reality demo for <a href="http://www.samsung.com/de/wearables/gear-vr-r323/">
Samsung GearVR</a></h2>
<h3>Software</h3>
<p>
<a href="NOMADGearvrT-release.apk">NOMAD Gear VR for time-dependant data,
APK installer</a>, 2 MB<br/>
Contact garcia at lrz dot de for instructions related to requesting apk signing.
</p>
<h2>Datasets for HTC Vive demo</h2>
<h3>
Dataset corresponding to the reaction of gaseous CO<sub>2</sub> to CaO(001) surface.
Corresponding material:
......@@ -56,6 +66,7 @@ NOMAD Usecase 1</a><br/>
<img src="AgAll_bands.png" width=10% /><br/>
<a href="AgFermi.rar">Ag Fermi surface</a>, 374 KB
</p>
<h2>Datasets for both Vive and GearVR</h2>
<h3>Dataset for molecular dynamics using extended xyz file</h3>
<p>
Atomistic viewer: Glucose (from <a href="http://wetche.cmbi.ru.nl/organic/methods/xyzf.html">this example</a>)<br/>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment