Skip to content

Commit

Permalink
Draw wireframe in Gl1_QMGeometry for MarchingCube, and add note about…
Browse files Browse the repository at this point in the history
… marginal distributions in (non-existing yet) QMGeometryDisplayConfig
  • Loading branch information
cosurgi committed May 19, 2015
1 parent f3ba079 commit 444af23
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
32 changes: 23 additions & 9 deletions pkg/qm/Gl1_QMGeometry.cpp
Expand Up @@ -153,7 +153,7 @@ void Gl1_QMGeometry::go(
if(drawStyle[draw]()=="nodes") glBegin(GL_POINTS); else glBegin(GL_LINE_STRIP);
glColor3v( colorToDraw[draw](col) );
for(struct{size_t i;Real x;}_={0,start.x()} ; _.i<pd->gridSize[0] ; _.i++ , _.x+=g->step.x() ) {
glVertex3d(_.x,0,valueToDraw[draw] ((pd->tableValuesPosition.at(_.i))) *scalingFactor);
glVertex3d(_.x,0,valueToDraw[draw] ((pd->psiMarginalDistribution.at(_.i))) *scalingFactor);
}
glEnd();
} // else "points"
Expand All @@ -169,15 +169,15 @@ void Gl1_QMGeometry::go(
for(struct{size_t i;Real x;}_={0,start.x()} ; _.i<pd->gridSize[0] ; _.i++, _.x+=g->step.x() ) {
glBegin(GL_LINE_STRIP);
for(struct{size_t j;Real y;}__={0,start.y()} ; __.j<pd->gridSize[1] ; __.j++, __.y+=g->step.y() ) {
glVertex3d(_.x,__.y,valueToDraw[draw] ((pd->tableValuesPosition.at(_.i,__.j))) *scalingFactor);
glVertex3d(_.x,__.y,valueToDraw[draw] ((pd->psiMarginalDistribution.at(_.i,__.j))) *scalingFactor);
}
glEnd();
if(timeLimit.tooLong(g->renderMaxTime)) break;
}
for(struct{size_t j;Real y;}__={0,start.y()} ; __.j<pd->gridSize[1] ; __.j++, __.y+=g->step.y() ) {
glBegin(GL_LINE_STRIP);
for(struct{size_t i;Real x;}_={0,start.x()} ; _.i<pd->gridSize[0] ; _.i++, _.x+=g->step.x() ) {
glVertex3d(_.x,__.y,valueToDraw[draw] ((pd->tableValuesPosition.at(_.i,__.j))) *scalingFactor);
glVertex3d(_.x,__.y,valueToDraw[draw] ((pd->psiMarginalDistribution.at(_.i,__.j))) *scalingFactor);
}
glEnd();
if(timeLimit.tooLong(g->renderMaxTime)) break;
Expand All @@ -189,7 +189,7 @@ void Gl1_QMGeometry::go(
FOREACH(std::vector<Real>& xx, waveValues2D) {xx.resize(pd->gridSize[1]);};
for(size_t i=0 ; i<pd->gridSize[0] ; i++ ) {
for(size_t j=0 ; j<pd->gridSize[1] ; j++ ) {
waveValues2D[i][j]=valueToDraw[draw] ((pd->tableValuesPosition.at(i,j))) *scalingFactor;
waveValues2D[i][j]=valueToDraw[draw] ((pd->psiMarginalDistribution.at(i,j))) *scalingFactor;
}
if(timeLimit.tooLong(g->renderMaxTime)) break;
}
Expand All @@ -202,6 +202,8 @@ void Gl1_QMGeometry::go(
// if(points == true) ... else ...
// 3D lines
// 3D surface
// FIXME - draw transparent MarchingCube for each layer?
// http://www.videotutorialsrock.com/opengl_tutorial/reference.php
if(true /* points == false */) {
// FIXME!! ↓ is it possible to skip this copying of data to calculate valueToDraw[draw](...) ?
Vector3r minMC(start.x()+g->step.x()*0.5,start.y()+g->step.y()*0.5,start.z()+g->step.z()*0.5);
Expand All @@ -215,14 +217,14 @@ void Gl1_QMGeometry::go(
//// FIXME(1) - is it possible to skip this copying of data to calculate valueToDraw[draw](...) ?
//// (potrzebne mi też będą kontrakcje na życzenie - tylko gdy rysuję)
//// FIXME - here's crash sometimes when step is changed "live" in inspect window
waveValues3D[i][j][k]=valueToDraw[draw] (pd->tableValuesPosition.at(i,j,k));
waveValues3D[i][j][k]=valueToDraw[draw] (pd->psiMarginalDistribution.at(i,j,k));
}
}
if(timeLimit.tooLong(g->renderMaxTime)) break;
}
mc.computeTriangulation(waveValues3D,g->threshold3D);
// FIXME(2) - drawSurface or drawWires
glDrawMarchingCube(mc,colorToDraw[draw](col));
glDrawMarchingCube(mc,colorToDraw[draw](col),drawStyle[draw](),wire);
}
break;
default:
Expand Down Expand Up @@ -309,27 +311,39 @@ void Gl1_QMGeometry::go(
// std::cerr << "Gl1_QMGeometry: Drawing of grid steps is not ready yet.\n";
};

void Gl1_QMGeometry::glDrawMarchingCube(MarchingCube& mc,Vector3r col)
void Gl1_QMGeometry::glDrawMarchingCube(MarchingCube& mc,Vector3r col,std::string drawStyle,bool wire)
{
prepareGlSurfaceMaterial();
glColor3v(col);

bool WIRE(wire == true or drawStyle == "wire");

const vector<Vector3r>& triangles = mc.getTriangles();
int nbTriangles = mc.getNbTriangles();
const vector<Vector3r>& normals = mc.getNormals();
if(g->renderSmoothing){ glShadeModel(GL_SMOOTH);};
glEnable(GL_NORMALIZE);
glBegin(GL_TRIANGLES);
if(WIRE) {
glDisable(GL_LIGHTING);
} else {
glBegin(GL_TRIANGLES);
}
for(int i=0;i<3*nbTriangles;++i)
{
if(WIRE) glBegin(GL_LINE_STRIP);
glNormal3v(normals[ i]);
glVertex3v(triangles[i]);
glNormal3v(normals[++i]);
glVertex3v(triangles[i]);
glNormal3v(normals[++i]);
glVertex3v(triangles[i]);
if(WIRE) glEnd();
}
if(WIRE) {
glEnable(GL_LIGHTING);
} else {
glEnd();
}
glEnd();

// FIXME(2) - maybe draw using this approach instead? http://webhome.csc.uvic.ca/~pouryash/depot/HPC_Course/OpenGLDrawingMethods.pdf
//glColorPointer(3, GL_FLOAT,0,mesh.vColor);
Expand Down
2 changes: 1 addition & 1 deletion pkg/qm/Gl1_QMGeometry.hpp
Expand Up @@ -23,7 +23,7 @@ class Gl1_QMGeometry: public GlShapeFunctor
void drawSurface(const std::vector<std::vector<Real> >& waveVals,Vector3r col);
void calcNormalVectors(const std::vector<std::vector<Real> >& waveVals,std::vector<std::vector<Vector3r> >& wavNormV);
void prepareGlSurfaceMaterial();
void glDrawMarchingCube(MarchingCube& mc,Vector3r col);
void glDrawMarchingCube(MarchingCube& mc,Vector3r col,std::string drawStyle,bool wire);
void glDrawSurface(const std::vector<std::vector<Real> >& waveVals,const std::vector<std::vector<Vector3r> >& wavNormV,Vector3r col);
void glDrawSurfaceInterpolated(const std::vector<std::vector<Real> >&,const std::vector<std::vector<Vector3r> >&,const std::vector<std::vector<Real> >&,const std::vector<std::vector<Vector3r> >&,Vector3r col);
void interpolateExtraWaveValues(const std::vector<std::vector<Real> >& waveVals,std::vector<std::vector<Real> >& extraWaveVals);
Expand Down
7 changes: 6 additions & 1 deletion pkg/qm/QMGeometry.hpp
Expand Up @@ -42,7 +42,12 @@ class QMGeometry: public Box
If the wavefunctions were really infinite, then it would work nicely, but due to computer limitations this \
halfSize also covers the range of interactions between particles. Later it should work in 4D space-time.")) */
((Menu,partAbsolute ,Menu({"default wire" ,"hidden","nodes","big nodes","points","wire","surface"}),,"Show absolute value of the wavefunction"))
((Menu,partImaginary ,Menu({"default surface","hidden","nodes","big nodes","points","wire","surface"}),,"Show imaginary component"))
((Menu,partImaginary ,Menu({
"default surface","hidden","nodes","big nodes","points","wire","surface"
//"default draw: ∬ψ(x₁,y₁,x₂,y₂)dx₂dy₂ end_x₂"
// ,"draw: ∫ψ(x₁,y₁,x₂,y₂)dy₂" , "draw: ∬ψ(x₁,y₁,x₂,y₂)dx₂dy₂ start_x₂"
// ,"draw: ∬ψ(x₁,y₁,x₂,y₂)dx₂dy₂ end_x₂", "draw: ∬ψ(x₁,y₁,x₂,y₂)dx₂dy₂ start_x₂,end_x₂"
}),,"Show imaginary component"))
((Menu,partReal ,Menu({"default surface","hidden","nodes","big nodes","points","wire","surface"}),,"Show real component"))
((int ,partsScale ,1.0,,"Scaling of the wavefunction or potential. Positive number multiplies, negative divides by absolute value."))
((bool,partsSquared ,false,,"Show squares of selected parts to draw (eg. squared partAbsolute is probability)"))
Expand Down

0 comments on commit 444af23

Please sign in to comment.