Integrated lost modifications...
This commit is contained in:
parent
dedf484388
commit
0cceae697e
apps/shadevis
|
@ -24,6 +24,9 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.3 2004/09/09 14:35:54 ponchio
|
||||||
|
Various changes for gcc compatibility
|
||||||
|
|
||||||
Revision 1.2 2004/07/11 22:13:30 cignoni
|
Revision 1.2 2004/07/11 22:13:30 cignoni
|
||||||
Added GPL comments
|
Added GPL comments
|
||||||
|
|
||||||
|
@ -31,6 +34,7 @@ Added GPL comments
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <GL/glut.h>
|
#include <GL/glut.h>
|
||||||
|
@ -48,6 +52,7 @@ Added GPL comments
|
||||||
#include<wrap/io_trimesh/import_ply.h>
|
#include<wrap/io_trimesh/import_ply.h>
|
||||||
#include<vcg/complex/trimesh/update/normal.h>
|
#include<vcg/complex/trimesh/update/normal.h>
|
||||||
#include<vcg/complex/trimesh/update/bounding.h>
|
#include<vcg/complex/trimesh/update/bounding.h>
|
||||||
|
#include<vcg/complex/trimesh/update/color.h>
|
||||||
|
|
||||||
#include "visshader.h"
|
#include "visshader.h"
|
||||||
using namespace vcg;
|
using namespace vcg;
|
||||||
|
@ -65,43 +70,30 @@ class AMesh : public tri::TriMesh< vector<AVertex>, vector<AFace> > {};
|
||||||
|
|
||||||
///////// Global ////////
|
///////// Global ////////
|
||||||
|
|
||||||
int SampleNum=32;
|
int SampleNum=64;
|
||||||
int WindowRes=800;
|
int WindowRes=800;
|
||||||
|
unsigned int TexInd=0;
|
||||||
bool SwapFlag=false;
|
bool SwapFlag=false;
|
||||||
|
bool CullFlag=false;
|
||||||
|
bool ClosedFlag=false;
|
||||||
|
|
||||||
|
float lopass=0,hipass=1,gamma=1;
|
||||||
|
float diff=.8;
|
||||||
|
float ambi=.2;
|
||||||
|
|
||||||
float lopass=0,hipass=1,Gamma=1;
|
|
||||||
bool LightFlag=true;
|
bool LightFlag=true;
|
||||||
bool ColorFlag=true;
|
bool ColorFlag=true;
|
||||||
|
bool ShowDirFlag=false;
|
||||||
|
int imgcnt=0;
|
||||||
|
|
||||||
Trackball Q;
|
Color4b BaseColor=Color4b::White;
|
||||||
|
Trackball QV;
|
||||||
|
Trackball QL;
|
||||||
|
Trackball *Q=&QV;
|
||||||
|
|
||||||
int ScreenH,ScreenW;
|
int ScreenH,ScreenW;
|
||||||
float ViewAngle=45;
|
float ViewAngle=33;
|
||||||
|
vector<Point3f> ViewVector;
|
||||||
class TimeOracle
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
time_t start;
|
|
||||||
time_t cur;
|
|
||||||
|
|
||||||
char buf[128];
|
|
||||||
|
|
||||||
char const *TimeToEndStr(double perc)
|
|
||||||
{
|
|
||||||
time(&cur);
|
|
||||||
double diff=difftime(cur,start);
|
|
||||||
diff= diff/perc - diff;
|
|
||||||
|
|
||||||
int hh=diff/3600;
|
|
||||||
int mm=(diff-hh*3600)/60;
|
|
||||||
int ss=diff-hh*3600-mm*60;
|
|
||||||
sprintf(buf,"%02i:%02i:%02i",hh,mm,ss);
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Start(){time(&start);};
|
|
||||||
};
|
|
||||||
|
|
||||||
bool cb(const char *buf)
|
bool cb(const char *buf)
|
||||||
{
|
{
|
||||||
|
@ -109,19 +101,88 @@ bool cb(const char *buf)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BuildOnePixelTexture(Color4b c, unsigned int &TexInd)
|
||||||
|
{
|
||||||
|
if(TexInd==0) glGenTextures(1,&TexInd);
|
||||||
|
|
||||||
|
glBindTexture(GL_TEXTURE_1D,TexInd);
|
||||||
|
glTexImage1D(GL_TEXTURE_1D,0,GL_RGBA,1,0,GL_RGBA,GL_UNSIGNED_BYTE,&c);
|
||||||
|
glEnable(GL_TEXTURE_1D);
|
||||||
|
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
|
||||||
|
}
|
||||||
|
void glutPrintf(int x, int y, const char * f, ... )
|
||||||
|
{
|
||||||
|
glMatrixMode (GL_PROJECTION);
|
||||||
|
glPushMatrix();
|
||||||
|
glLoadIdentity ();
|
||||||
|
glOrtho(0,ScreenW,0,ScreenH,-1,1);
|
||||||
|
glMatrixMode (GL_MODELVIEW);
|
||||||
|
glPushMatrix();
|
||||||
|
glLoadIdentity ();
|
||||||
|
|
||||||
|
int len, i;
|
||||||
|
char buf[4096];
|
||||||
|
va_list marker;
|
||||||
|
va_start( marker, f );
|
||||||
|
|
||||||
|
int n = vsprintf(buf,f,marker);
|
||||||
|
va_end( marker );
|
||||||
|
|
||||||
|
glColor3f(0,0,0);
|
||||||
|
glRasterPos2f(x, y);
|
||||||
|
len = (int) strlen(buf);
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
|
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, buf[i]);
|
||||||
|
}
|
||||||
|
glMatrixMode (GL_PROJECTION);
|
||||||
|
glPopMatrix();
|
||||||
|
glMatrixMode (GL_MODELVIEW);
|
||||||
|
glPopMatrix();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// prototypes
|
// prototypes
|
||||||
void SaveTexturedGround();
|
void SaveTexturedGround();
|
||||||
|
|
||||||
|
void DrawViewVector()
|
||||||
|
{
|
||||||
|
glDisable(GL_LIGHTING);
|
||||||
|
glColor3f(0,0,1);
|
||||||
|
glBegin(GL_LINES);
|
||||||
|
for(unsigned int i=0;i<ViewVector.size();++i)
|
||||||
|
{
|
||||||
|
glVertex3f(0,0,0);glVertex(ViewVector[i]);
|
||||||
|
}
|
||||||
|
glEnd();
|
||||||
|
}
|
||||||
|
void DrawLightVector()
|
||||||
|
{
|
||||||
|
const int sz=5;
|
||||||
|
glPushMatrix();
|
||||||
|
QL.Apply();
|
||||||
|
glDisable(GL_LIGHTING);
|
||||||
|
glBegin(GL_LINES);
|
||||||
|
glColor3f(1,1,0);
|
||||||
|
for(unsigned int i=0;i<=sz;++i)
|
||||||
|
for(unsigned int j=0;j<=sz;++j)
|
||||||
|
{
|
||||||
|
glColor3f(1,1,0);
|
||||||
|
glVertex3f(-1.0f+i*2.0/sz,-1.0f+j*2.0/sz,-1);
|
||||||
|
glVertex3f(-1.0f+i*2.0/sz,-1.0f+j*2.0/sz, 1);
|
||||||
|
}
|
||||||
|
glEnd();
|
||||||
|
glPopMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
void Draw(AMesh &mm)
|
void Draw(AMesh &mm)
|
||||||
{
|
{
|
||||||
AMesh::FaceIterator fi;
|
AMesh::FaceIterator fi;
|
||||||
glBegin(GL_TRIANGLES);
|
glBegin(GL_TRIANGLES);
|
||||||
for(fi=mm.face.begin();fi!=mm.face.end();++fi)
|
for(fi=mm.face.begin();fi!=mm.face.end();++fi)
|
||||||
{
|
{
|
||||||
|
glNormal((*fi).V(0)->N()); if(ColorFlag) glColor((*fi).V(0)->C()); glVertex((*fi).V(0)->P());
|
||||||
glNormal((*fi).V(0)->N()); glColor((*fi).V(0)->C()); glVertex((*fi).V(0)->P());
|
glNormal((*fi).V(1)->N()); if(ColorFlag) glColor((*fi).V(1)->C()); glVertex((*fi).V(1)->P());
|
||||||
glNormal((*fi).V(1)->N()); glColor((*fi).V(1)->C()); glVertex((*fi).V(1)->P());
|
glNormal((*fi).V(2)->N()); if(ColorFlag) glColor((*fi).V(2)->C()); glVertex((*fi).V(2)->P());
|
||||||
glNormal((*fi).V(2)->N()); glColor((*fi).V(2)->C()); glVertex((*fi).V(2)->P());
|
|
||||||
}
|
}
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
|
@ -138,31 +199,52 @@ string OutNameMsh;
|
||||||
void ViewReshape(GLsizei w, GLsizei h)
|
void ViewReshape(GLsizei w, GLsizei h)
|
||||||
{
|
{
|
||||||
ScreenW=w; ScreenH=h;
|
ScreenW=w; ScreenH=h;
|
||||||
glMatrixMode (GL_PROJECTION);
|
glViewport(0,0,w,h);
|
||||||
glLoadIdentity ();
|
|
||||||
gluPerspective(ViewAngle,(float)w/(float)h,.1,10000);
|
|
||||||
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewDisplay (void)
|
void ViewDisplay (void)
|
||||||
{
|
{
|
||||||
|
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glMatrixMode (GL_PROJECTION);
|
glMatrixMode (GL_PROJECTION);
|
||||||
glLoadIdentity ();
|
glLoadIdentity ();
|
||||||
gluPerspective(ViewAngle,1,.1,10);
|
gluPerspective(ViewAngle,(float)ScreenW/ScreenH,1,7);
|
||||||
glMatrixMode (GL_MODELVIEW);
|
glMatrixMode (GL_MODELVIEW);
|
||||||
glLoadIdentity ();
|
glLoadIdentity ();
|
||||||
|
glPushMatrix();
|
||||||
|
QL.Apply();
|
||||||
|
glutPrintf(5,5,"Diffuse %04.2f Ambient %04.2f LowPass %04.2f HiPass %04.2f Gamma %04.2f ",diff,ambi,lopass,hipass,gamma);
|
||||||
|
GLfloat light_position0[] = {0.0, 10.0, 300.0, 0.0};
|
||||||
|
glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
|
||||||
|
glPopMatrix();
|
||||||
glTranslatef(0,0,-4);
|
glTranslatef(0,0,-4);
|
||||||
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
if(Q==&QL) DrawLightVector();
|
||||||
Q.GetView();
|
QL.GetView();
|
||||||
Q.Apply();
|
QV.GetView();
|
||||||
Q.Draw();
|
QV.Apply();
|
||||||
|
if(ShowDirFlag) DrawViewVector();
|
||||||
|
|
||||||
float d = 2.0/m.bbox.Diag();
|
float d = 2.0/m.bbox.Diag();
|
||||||
glScalef(d, d, d);
|
glScalef(d, d, d);
|
||||||
|
glColor3f(diff,diff,diff);
|
||||||
glTranslate(-m.bbox.Center());
|
glTranslate(-m.bbox.Center());
|
||||||
if(LightFlag) glEnable(GL_LIGHTING);
|
if(LightFlag) glEnable(GL_LIGHTING);
|
||||||
else glDisable(GL_LIGHTING);
|
else glDisable(GL_LIGHTING);
|
||||||
if(ColorFlag) glEnable(GL_COLOR_MATERIAL);
|
if(ColorFlag) glEnable(GL_COLOR_MATERIAL);
|
||||||
else glDisable(GL_COLOR_MATERIAL);
|
else glDisable(GL_COLOR_MATERIAL);
|
||||||
|
glColorMaterial(GL_FRONT,GL_AMBIENT);
|
||||||
|
glMateriali(GL_FRONT,GL_SHININESS,0);
|
||||||
|
float spec[4]={0,0,0,1};
|
||||||
|
float ambientV[4]={ambi,ambi,ambi,1};
|
||||||
|
float diffuseV[4]={diff,diff,diff,1};
|
||||||
|
glMaterialfv(GL_FRONT,GL_SPECULAR,spec);
|
||||||
|
glMaterialfv(GL_FRONT,GL_AMBIENT, ambientV);
|
||||||
|
glMaterialfv(GL_FRONT,GL_DIFFUSE, diffuseV);
|
||||||
|
glCullFace(GL_BACK);
|
||||||
|
|
||||||
|
if(CullFlag) glEnable(GL_CULL_FACE);
|
||||||
|
else glDisable(GL_CULL_FACE);
|
||||||
|
|
||||||
|
BuildOnePixelTexture(BaseColor,TexInd);
|
||||||
Draw(m);
|
Draw(m);
|
||||||
glutSwapBuffers();
|
glutSwapBuffers();
|
||||||
}
|
}
|
||||||
|
@ -172,6 +254,11 @@ void ViewSpecialKey(int , int , int )
|
||||||
glutPostRedisplay();
|
glutPostRedisplay();
|
||||||
}
|
}
|
||||||
void Toggle(bool &flag) {flag = !flag;}
|
void Toggle(bool &flag) {flag = !flag;}
|
||||||
|
void UpdateVis()
|
||||||
|
{
|
||||||
|
if(LightFlag) Vis.MapVisibility(gamma,lopass,hipass,ambi);
|
||||||
|
if(!LightFlag) Vis.MapVisibility(gamma,lopass,hipass,1.0);
|
||||||
|
}
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
|
@ -180,48 +267,66 @@ void ViewKey(unsigned char key, int , int )
|
||||||
Point3f dir;
|
Point3f dir;
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 27: exit(0); break;
|
case 27: exit(0); break;
|
||||||
|
case 9: if(Q==&QV) Q=&QL;else Q=&QV; break;
|
||||||
case 'l' :
|
case 'l' :
|
||||||
lopass=lopass+.05; printf("Lo %f, Hi %f Gamma %f\n",lopass,hipass,Gamma);
|
lopass=lopass+.05; printf("Lo %f, Hi %f Gamma %f\n",lopass,hipass,gamma);
|
||||||
Vis.MapVisibility(Gamma,lopass,hipass);
|
UpdateVis();
|
||||||
break;
|
break;
|
||||||
case 'L' :
|
case 'L' :
|
||||||
lopass=lopass-.05; printf("Lo %f, Hi %f Gamma %f\n",lopass,hipass,Gamma);
|
lopass=lopass-.05; printf("Lo %f, Hi %f Gamma %f\n",lopass,hipass,gamma);
|
||||||
Vis.MapVisibility(Gamma,lopass,hipass);
|
UpdateVis(); break;
|
||||||
break;
|
|
||||||
case 'h' :
|
case 'h' :
|
||||||
hipass=hipass-.05; printf("Lo %f, Hi %f Gamma %f\n",lopass,hipass,Gamma);
|
hipass=hipass-.05; printf("Lo %f, Hi %f Gamma %f\n",lopass,hipass,gamma);
|
||||||
Vis.MapVisibility(Gamma,lopass,hipass);
|
UpdateVis(); break;
|
||||||
break;
|
|
||||||
case 'H' :
|
case 'H' :
|
||||||
hipass=hipass+.05; printf("Lo %f, Hi %f Gamma %f\n",lopass,hipass,Gamma);
|
hipass=hipass+.05; printf("Lo %f, Hi %f Gamma %f\n",lopass,hipass,gamma);
|
||||||
Vis.MapVisibility(Gamma,lopass,hipass);
|
UpdateVis(); break;
|
||||||
break;
|
case 'd' : diff+=.05; printf("Ambient %f Diffuse %f, \n",ambi,diff); UpdateVis(); break;
|
||||||
case 'g' :
|
case 'D' : diff-=.05; printf("Ambient %f Diffuse %f, \n",ambi,diff); UpdateVis(); break;
|
||||||
Gamma=Gamma-.05; printf("Lo %f, Hi %f Gamma %f\n",lopass,hipass,Gamma);
|
case 'a' : ambi+=.05; printf("Ambient %f Diffuse %f, \n",ambi,diff); UpdateVis(); break;
|
||||||
Vis.MapVisibility(Gamma,lopass,hipass);
|
case 'A' : ambi-=.05; printf("Ambient %f Diffuse %f, \n",ambi,diff); UpdateVis(); break;
|
||||||
break;
|
|
||||||
case 'G' :
|
case 'e' : ambi+=.05; diff-=.05; printf("Ambient %f Diffuse %f, \n",ambi,diff); UpdateVis(); break;
|
||||||
Gamma=Gamma+.05; printf("Lo %f, Hi %f Gamma %f\n",lopass,hipass,Gamma);
|
case 'E' : ambi-=.05; diff+=.05; printf("Ambient %f Diffuse %f, \n",ambi,diff); UpdateVis(); break;
|
||||||
Vis.MapVisibility(Gamma,lopass,hipass);
|
|
||||||
break;
|
case 'p' :
|
||||||
case 'c' :
|
gamma=gamma-.05; printf("Lo %f, Hi %f Gamma %f\n",lopass,hipass,gamma);
|
||||||
Vis.ComputeUniform(SampleNum,cb);
|
UpdateVis(); break;
|
||||||
Vis.MapVisibility(Gamma,lopass,hipass);
|
case 'P' :
|
||||||
break;
|
gamma=gamma+.05; printf("Lo %f, Hi %f Gamma %f\n",lopass,hipass,gamma);
|
||||||
|
UpdateVis(); break;
|
||||||
|
case 13 :
|
||||||
|
Vis.ComputeUniform(SampleNum,ViewVector,cb);
|
||||||
|
UpdateVis(); break;
|
||||||
case ' ' : {
|
case ' ' : {
|
||||||
Point3f dir = Q.camera.ViewPoint();
|
Point3f dir = Q->camera.ViewPoint();
|
||||||
printf("ViewPoint %f %f %f\n",dir[0],dir[1],dir[2]);
|
printf("ViewPoint %f %f %f\n",dir[0],dir[1],dir[2]);
|
||||||
dir.Normalize();
|
dir.Normalize();
|
||||||
dir=Inverse(Q.track.Matrix())*dir;
|
dir=Inverse(Q->track.Matrix())*dir;
|
||||||
printf("ViewPoint %f %f %f\n",dir[0],dir[1],dir[2]);
|
printf("ViewPoint %f %f %f\n",dir[0],dir[1],dir[2]);
|
||||||
dir.Normalize();
|
dir.Normalize();
|
||||||
Vis.ComputeSingle(dir,cb);
|
Vis.ComputeSingle(dir,ViewVector,cb);
|
||||||
Vis.MapVisibility(Gamma,lopass,hipass); }
|
UpdateVis();
|
||||||
break;
|
} break;
|
||||||
|
case 'r' : BaseColor[0]=min(255,BaseColor[0]+2); printf("BaseColor %3i %3i %3i \n",BaseColor[0],BaseColor[1],BaseColor[2]); break;
|
||||||
|
case 'R' : BaseColor[0]=max( 0,BaseColor[0]-2); printf("BaseColor %3i %3i %3i \n",BaseColor[0],BaseColor[1],BaseColor[2]); break;
|
||||||
|
case 'g' : BaseColor[1]=min(255,BaseColor[1]+2); printf("BaseColor %3i %3i %3i \n",BaseColor[0],BaseColor[1],BaseColor[2]); break;
|
||||||
|
case 'G' : BaseColor[1]=max( 0,BaseColor[1]-2); printf("BaseColor %3i %3i %3i \n",BaseColor[0],BaseColor[1],BaseColor[2]); break;
|
||||||
|
case 'b' : BaseColor[2]=min(255,BaseColor[2]+2); printf("BaseColor %3i %3i %3i \n",BaseColor[0],BaseColor[1],BaseColor[2]); break;
|
||||||
|
case 'B' : BaseColor[2]=max( 0,BaseColor[2]-2); printf("BaseColor %3i %3i %3i \n",BaseColor[0],BaseColor[1],BaseColor[2]); break;
|
||||||
|
|
||||||
|
case 'v' : Toggle(ShowDirFlag); break;
|
||||||
|
case 'V' :
|
||||||
|
{
|
||||||
|
SimplePic<Color4b> snapC;
|
||||||
|
snapC.OpenGLSnap();
|
||||||
|
char buf[128];
|
||||||
|
sprintf(buf,"Snap%03i.ppm",imgcnt++);
|
||||||
|
snapC.SavePPM(buf);
|
||||||
|
}
|
||||||
case 's' :
|
case 's' :
|
||||||
Vis.SmoothVisibility();
|
Vis.SmoothVisibility();
|
||||||
Vis.MapVisibility(Gamma,lopass,hipass);
|
UpdateVis(); break;
|
||||||
break;
|
|
||||||
case 'S' :
|
case 'S' :
|
||||||
{
|
{
|
||||||
vcg::tri::io::PlyInfo p;
|
vcg::tri::io::PlyInfo p;
|
||||||
|
@ -229,8 +334,12 @@ void ViewKey(unsigned char key, int , int )
|
||||||
tri::io::ExporterPLY<AMesh>::Save(m,OutNameMsh.c_str(),false,p);
|
tri::io::ExporterPLY<AMesh>::Save(m,OutNameMsh.c_str(),false,p);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'a' : LightFlag = !LightFlag; printf("Toggled Light\n"); break;
|
case 'C' : LightFlag = !LightFlag; printf("Toggled Light %s\n",LightFlag?"on":"off"); UpdateVis(); break;
|
||||||
case 'A' : ColorFlag = !ColorFlag; printf("Toggled Color\n"); break;
|
case 'c' : ColorFlag = !ColorFlag; printf("Toggled Color %s\n",ColorFlag?"on":"off"); break;
|
||||||
|
case '1' : diff=0.80f; ambi=0.10f; gamma=1.0; lopass=0.00f; hipass=1.00f; ColorFlag=false; UpdateVis(); break;
|
||||||
|
case '2' : diff=0.65f; ambi=0.30f; gamma=1.0; lopass=0.15f; hipass=0.80f; ColorFlag=true; UpdateVis(); break;
|
||||||
|
case '3' : diff=0.45f; ambi=0.50f; gamma=1.0; lopass=0.20f; hipass=0.75f; ColorFlag=true; UpdateVis(); break;
|
||||||
|
case '4' : diff=0.35f; ambi=0.60f; gamma=1.0; lopass=0.25f; hipass=0.70f; ColorFlag=true; UpdateVis(); break;
|
||||||
}
|
}
|
||||||
glutPostRedisplay(); ;
|
glutPostRedisplay(); ;
|
||||||
}
|
}
|
||||||
|
@ -242,36 +351,34 @@ void ViewMenu(int val)
|
||||||
// TrackBall Functions
|
// TrackBall Functions
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
|
|
||||||
int PressedButton; // What is the button actually pressed?
|
|
||||||
int KeyMod;
|
|
||||||
int GW,GH; // Grandezza della finestra
|
int GW,GH; // Grandezza della finestra
|
||||||
int B[3]={0,0,0}; // Variabile globale che tiene lo stato dei tre bottoni;
|
|
||||||
|
|
||||||
|
|
||||||
void ViewMouse(int button, int state, int x, int y)
|
void ViewMouse(int button, int state, int x, int y)
|
||||||
{
|
{
|
||||||
|
static int KeyMod=0;
|
||||||
static int glut_buttons=0;
|
static int glut_buttons=0;
|
||||||
|
//printf("ViewMouse %i %i %i %i\n",x,y,button,state);
|
||||||
int m_mask = 0;
|
int m_mask = 0;
|
||||||
|
if(state == GLUT_DOWN) {
|
||||||
KeyMod=glutGetModifiers();
|
KeyMod=glutGetModifiers();
|
||||||
if(GLUT_ACTIVE_SHIFT & KeyMod) m_mask |= Trackball::KEY_SHIFT;
|
if(GLUT_ACTIVE_SHIFT & KeyMod) m_mask |= Trackball::KEY_SHIFT;
|
||||||
if(GLUT_ACTIVE_ALT & KeyMod) m_mask |= Trackball::KEY_ALT;
|
if(GLUT_ACTIVE_ALT & KeyMod) m_mask |= Trackball::KEY_ALT;
|
||||||
if(GLUT_ACTIVE_CTRL & KeyMod) m_mask |= Trackball::KEY_CTRL;
|
if(GLUT_ACTIVE_CTRL & KeyMod) m_mask |= Trackball::KEY_CTRL;
|
||||||
|
|
||||||
if(state == GLUT_DOWN) {
|
|
||||||
glut_buttons |= (1<<button);
|
glut_buttons |= (1<<button);
|
||||||
Q.MouseDown(x, ScreenH-y, glut_buttons | m_mask);
|
Q->MouseDown(x, ScreenH-y, glut_buttons | m_mask);
|
||||||
} else {
|
} else {
|
||||||
//glut_buttons &= ~(1<<button);
|
if(GLUT_ACTIVE_SHIFT & KeyMod) m_mask |= Trackball::KEY_SHIFT;
|
||||||
glut_buttons = 0;
|
if(GLUT_ACTIVE_ALT & KeyMod) m_mask |= Trackball::KEY_ALT;
|
||||||
m_mask = 0;
|
if(GLUT_ACTIVE_CTRL & KeyMod) m_mask |= Trackball::KEY_CTRL;
|
||||||
Q.MouseUp(x, ScreenH-y, glut_buttons);
|
glut_buttons |= (1<<button);
|
||||||
|
Q->MouseUp(x, ScreenH-y, glut_buttons | m_mask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewMouseMotion(int x, int y)
|
void ViewMouseMotion(int x, int y)
|
||||||
{
|
{
|
||||||
Q.MouseMove(x,ScreenH-y);
|
Q->MouseMove(x,ScreenH-y);
|
||||||
glutPostRedisplay();
|
glutPostRedisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,16 +387,18 @@ void SetLight()
|
||||||
GLfloat light_ambient0[] = {0.0, 0.0, 0.0, 1.0};
|
GLfloat light_ambient0[] = {0.0, 0.0, 0.0, 1.0};
|
||||||
GLfloat light_diffuse0[] = {1.0, 1.0, 1.0, 1.0};
|
GLfloat light_diffuse0[] = {1.0, 1.0, 1.0, 1.0};
|
||||||
GLfloat light_position0[] = {0.0, 10.0, 300.0, 0.0};
|
GLfloat light_position0[] = {0.0, 10.0, 300.0, 0.0};
|
||||||
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient0);
|
|
||||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse0);
|
|
||||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
|
glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
|
||||||
|
glLightfv(GL_LIGHT0, GL_AMBIENT, light_diffuse0);
|
||||||
|
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse0);
|
||||||
glEnable(GL_LIGHT0);
|
glEnable(GL_LIGHT0);
|
||||||
|
glLightModelfv(GL_LIGHT_MODEL_AMBIENT,light_ambient0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewInit (void) {
|
void ViewInit (void) {
|
||||||
SetLight();
|
SetLight();
|
||||||
Q.Reset();
|
Q->Reset();
|
||||||
Q.radius= 1;
|
Q->radius= 1;
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glDepthFunc(GL_LEQUAL);
|
glDepthFunc(GL_LEQUAL);
|
||||||
glClearColor (0.8, 0.8, 0.8, 0.0);
|
glClearColor (0.8, 0.8, 0.8, 0.0);
|
||||||
|
@ -300,16 +409,8 @@ void ViewInit (void) {
|
||||||
glShadeModel(GL_SMOOTH);
|
glShadeModel(GL_SMOOTH);
|
||||||
// glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
// glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||||
glEnable(GL_COLOR_MATERIAL);
|
|
||||||
glColorMaterial(GL_FRONT,GL_DIFFUSE);
|
|
||||||
//glColorMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE);
|
|
||||||
//glColorMaterial(GL_FRONT,GL_AMBIENT);
|
|
||||||
glMateriali(GL_FRONT,GL_SHININESS,0);
|
|
||||||
float spec[4]={0,0,0,1};
|
|
||||||
glMaterialfv(GL_FRONT,GL_SPECULAR,spec);
|
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
glCullFace(GL_BACK);
|
glCullFace(GL_BACK);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -324,18 +425,18 @@ int main(int argc, char** argv)
|
||||||
"Usage: shadevis file.ply [options]\n"
|
"Usage: shadevis file.ply [options]\n"
|
||||||
"Options:\n"
|
"Options:\n"
|
||||||
" -w# WindowResolution (default 600)\n"
|
" -w# WindowResolution (default 600)\n"
|
||||||
" -n# Sample Directions (default 32)\n"
|
" -n# Sample Directions (default 64)\n"
|
||||||
" -z# z offset (default 1e-4)\n"
|
" -z# z offset (default 1e-3)\n"
|
||||||
" -da # Cone Direction Angle in degree (default 45)\n"
|
" -c assume that the mesh is closed (slightly faster, default false)\n"
|
||||||
" -dv # # # Cone Direction vector (default 0 0 1)\n"
|
|
||||||
" -c Set IsClosed Flag\n"
|
|
||||||
" -f Flip normal of the model\n"
|
" -f Flip normal of the model\n"
|
||||||
|
//" -da # Cone Direction Angle in degree (default 45)\n"
|
||||||
|
//" -dv # # # Cone Direction vector (default 0 0 1)\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
srand(time(0));
|
||||||
int i=1;
|
int i=1;
|
||||||
while(i<argc && (argv[i][0]=='-'))
|
while(i<argc && (argv[i][0]=='-'))
|
||||||
{
|
{
|
||||||
|
@ -343,6 +444,7 @@ int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
case 'n' : SampleNum = atoi(argv[i]+2); break;
|
case 'n' : SampleNum = atoi(argv[i]+2); break;
|
||||||
case 'f' : SwapFlag=false; break;
|
case 'f' : SwapFlag=false; break;
|
||||||
|
case 'c' : ClosedFlag=true; break;
|
||||||
case 'w' : WindowRes= atoi(argv[i]+2); printf("Set WindowRes to %i\n",WindowRes ); break;
|
case 'w' : WindowRes= atoi(argv[i]+2); printf("Set WindowRes to %i\n",WindowRes ); break;
|
||||||
case 's' : Vis.SplitNum= atoi(argv[i]+2); printf("Set SplitNum to %i\n",Vis.SplitNum ); break;
|
case 's' : Vis.SplitNum= atoi(argv[i]+2); printf("Set SplitNum to %i\n",Vis.SplitNum ); break;
|
||||||
case 'z' : Vis.ZTWIST = atof(argv[i]+2); printf("Set ZTWIST to %f\n",Vis.ZTWIST ); break;
|
case 'z' : Vis.ZTWIST = atof(argv[i]+2); printf("Set ZTWIST to %f\n",Vis.ZTWIST ); break;
|
||||||
|
@ -364,6 +466,10 @@ int main(int argc, char** argv)
|
||||||
if(ret) {printf("Error unable to open mesh %s\n",argv[i]);exit(-1);}
|
if(ret) {printf("Error unable to open mesh %s\n",argv[i]);exit(-1);}
|
||||||
tri::UpdateNormals<AMesh>::PerVertexNormalized(m);
|
tri::UpdateNormals<AMesh>::PerVertexNormalized(m);
|
||||||
tri::UpdateBounding<AMesh>::Box(m);
|
tri::UpdateBounding<AMesh>::Box(m);
|
||||||
|
tri::UpdateColor<AMesh>::VertexConstant(m,Color4b::White);
|
||||||
|
Vis.IsClosedFlag=ClosedFlag;
|
||||||
|
Vis.Init();
|
||||||
|
UpdateVis();
|
||||||
|
|
||||||
printf("Mesh bbox (%f %f %f)-(%f %f %f)\n\n",m.bbox.min[0],m.bbox.min[1],m.bbox.min[2],m.bbox.max[0],m.bbox.max[1],m.bbox.max[2]);
|
printf("Mesh bbox (%f %f %f)-(%f %f %f)\n\n",m.bbox.min[0],m.bbox.min[1],m.bbox.min[2],m.bbox.max[0],m.bbox.max[1],m.bbox.max[2]);
|
||||||
OutNameMsh=(string(argv[i]).substr(0,strlen(argv[i])-4));
|
OutNameMsh=(string(argv[i]).substr(0,strlen(argv[i])-4));
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.3 2004/09/09 14:35:54 ponchio
|
||||||
|
Various changes for gcc compatibility
|
||||||
|
|
||||||
Revision 1.2 2004/07/11 22:13:30 cignoni
|
Revision 1.2 2004/07/11 22:13:30 cignoni
|
||||||
Added GPL comments
|
Added GPL comments
|
||||||
|
|
||||||
|
@ -37,7 +40,10 @@ Added GPL comments
|
||||||
|
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
#include <vcg/math/matrix44.h>
|
#include <vcg/math/matrix44.h>
|
||||||
|
#include <wrap/gl/math.h>
|
||||||
#include "simplepic.h"
|
#include "simplepic.h"
|
||||||
|
#include "gen_normal.h"
|
||||||
|
|
||||||
namespace vcg {
|
namespace vcg {
|
||||||
|
|
||||||
template <class ScalarType>
|
template <class ScalarType>
|
||||||
|
@ -66,7 +72,7 @@ template <class MESH_TYPE, int MAXVIS=2048> class VisShader
|
||||||
VisShader(MESH_TYPE &me):m(me)
|
VisShader(MESH_TYPE &me):m(me)
|
||||||
{
|
{
|
||||||
CullFlag= false;
|
CullFlag= false;
|
||||||
IsClosed = false;
|
IsClosedFlag = false;
|
||||||
ZTWIST=1e-3;
|
ZTWIST=1e-3;
|
||||||
SplitNum=1;
|
SplitNum=1;
|
||||||
|
|
||||||
|
@ -97,7 +103,7 @@ template <class MESH_TYPE, int MAXVIS=2048> class VisShader
|
||||||
std::vector< Point3x > VN; // Vettore delle normali che ho usato per calcolare la mask e i float in W;
|
std::vector< Point3x > VN; // Vettore delle normali che ho usato per calcolare la mask e i float in W;
|
||||||
|
|
||||||
// User defined parameters and flags
|
// User defined parameters and flags
|
||||||
bool IsClosed;
|
bool IsClosedFlag;
|
||||||
float ZTWIST;
|
float ZTWIST;
|
||||||
bool CullFlag; // Enable the frustum culling. Useful when the splitting value is larger than 2
|
bool CullFlag; // Enable the frustum culling. Useful when the splitting value is larger than 2
|
||||||
int SplitNum;
|
int SplitNum;
|
||||||
|
@ -108,7 +114,7 @@ template <class MESH_TYPE, int MAXVIS=2048> class VisShader
|
||||||
|
|
||||||
/********************************************************/
|
/********************************************************/
|
||||||
// Generic functions with Specialized code for every subclass
|
// Generic functions with Specialized code for every subclass
|
||||||
virtual void MapVisibility(float Gamma=1, float LowPass=0, float HighPass=1,bool FalseColor=false)=0;
|
virtual void MapVisibility(float Gamma=1, float LowPass=0, float HighPass=1,float Scale=1.0)=0;
|
||||||
//virtual void ApplyLightingEnvironment(std::vector<float> &W, float Gamma);
|
//virtual void ApplyLightingEnvironment(std::vector<float> &W, float Gamma);
|
||||||
|
|
||||||
virtual int GLAccumPixel( std::vector<int> &PixSeen)=0;
|
virtual int GLAccumPixel( std::vector<int> &PixSeen)=0;
|
||||||
|
@ -119,7 +125,8 @@ template <class MESH_TYPE, int MAXVIS=2048> class VisShader
|
||||||
/********************************************************/
|
/********************************************************/
|
||||||
// Generic functions with same code for every subclass
|
// Generic functions with same code for every subclass
|
||||||
|
|
||||||
void Clear() { fill(VV.begin(),VV.end(),0); }
|
void Clear() {
|
||||||
|
fill(VV.begin(),VV.end(),0); }
|
||||||
|
|
||||||
void InitGL()
|
void InitGL()
|
||||||
{
|
{
|
||||||
|
@ -176,9 +183,10 @@ void Compute( CallBack *cb)
|
||||||
{
|
{
|
||||||
//cb(buf.format("Start to compute %i dir\n",VN.size()));
|
//cb(buf.format("Start to compute %i dir\n",VN.size()));
|
||||||
InitGL();
|
InitGL();
|
||||||
|
int t00=clock();
|
||||||
VV.resize(m.vert.size());
|
VV.resize(m.vert.size());
|
||||||
std::vector<int> PixSeen(VV.size(),0);
|
std::vector<int> PixSeen(VV.size(),0);
|
||||||
|
int TotRay=0,HitRay=0;
|
||||||
for(int i=0;i<VN.size();++i)
|
for(int i=0;i<VN.size();++i)
|
||||||
{
|
{
|
||||||
int t0=clock();
|
int t0=clock();
|
||||||
|
@ -186,7 +194,9 @@ void Compute( CallBack *cb)
|
||||||
int added=SplittedRendering(VN[i], PixSeen,cb);
|
int added=SplittedRendering(VN[i], PixSeen,cb);
|
||||||
AddPixelCount(VV,PixSeen);
|
AddPixelCount(VV,PixSeen);
|
||||||
int t1=clock();
|
int t1=clock();
|
||||||
printf("ComputeSingleDir %i on %i : %i msec\n",i,VN.size(),t1-t0);
|
HitRay+=added;
|
||||||
|
TotRay+=VV.size();
|
||||||
|
printf("%3i/%i : %i msec -- TotRays %i, HitRays %i, ray/sec %3.1fk \n ",i,VN.size(),t1-t0,TotRay,HitRay,float(TotRay)/(clock()-t00));
|
||||||
}
|
}
|
||||||
|
|
||||||
RestoreGL();
|
RestoreGL();
|
||||||
|
@ -226,20 +236,24 @@ void ComputeHalf(int nn, Point3x &dir, CallBack *cb)
|
||||||
Compute(cb);
|
Compute(cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComputeUniform(int nn, CallBack *cb)
|
void ComputeUniform(int nn, std::vector<Point3x> &vv, CallBack *cb)
|
||||||
{
|
{
|
||||||
VN.clear();
|
VN.clear();
|
||||||
GenNormal(nn,VN);
|
GenNormal<ScalarType>::Uniform(nn,VN);
|
||||||
|
for(vector<Point3x>::iterator vi=VN.begin();vi!=VN.end();++vi)
|
||||||
|
vv.push_back(*vi);
|
||||||
|
|
||||||
char buf[256];
|
char buf[256];
|
||||||
sprintf(buf,"Asked %i normal, got %i normals\n",nn,VN.size());
|
sprintf(buf,"Asked %i normal, got %i normals\n",nn,VN.size());
|
||||||
cb(buf);
|
cb(buf);
|
||||||
Compute(cb);
|
Compute(cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComputeSingle(Point3x &dir, CallBack *cb)
|
void ComputeSingle(Point3x &dir, std::vector<Point3x> &vv,CallBack *cb)
|
||||||
{
|
{
|
||||||
VN.clear();
|
VN.clear();
|
||||||
VN.push_back(dir);
|
VN.push_back(dir);
|
||||||
|
vv.push_back(dir);
|
||||||
printf("Computing one direction (%f %f %f)\n",dir[0],dir[1],dir[2]);
|
printf("Computing one direction (%f %f %f)\n",dir[0],dir[1],dir[2]);
|
||||||
Compute(cb);
|
Compute(cb);
|
||||||
}
|
}
|
||||||
|
@ -261,16 +275,18 @@ int SplittedRendering(Point3x &ViewDir, std::vector<int> &PixSeen, CallBack *cb=
|
||||||
// Compute a rotation matrix that bring Axis parallel to Z.
|
// Compute a rotation matrix that bring Axis parallel to Z.
|
||||||
void GenMatrix(Matrix44d &a, Point3d Axis, double angle)
|
void GenMatrix(Matrix44d &a, Point3d Axis, double angle)
|
||||||
{
|
{
|
||||||
const double eps=1e-5;
|
const double eps=1e-3;
|
||||||
Point3d RotAx = Axis ^ Point3d(0,0,1);
|
Point3d RotAx = Axis ^ Point3d(0,0,1);
|
||||||
double RotAngle = Angle(Axis,Point3d(0,0,1));
|
double RotAngle = Angle(Axis,Point3d(0,0,1));
|
||||||
|
|
||||||
if(math::Abs(RotAx.Norm())<eps) { // in questo caso Axis e' collineare con l'asse z
|
if(math::Abs(RotAx.Norm())<eps) { // in questo caso Axis e' collineare con l'asse z
|
||||||
RotAx=Point3d(0,1,0);
|
RotAx=Axis ^ Point3d(0,1,0);
|
||||||
double RotAngle = Angle(Axis,Point3d(0,1,0));
|
double RotAngle = Angle(Axis,Point3d(0,1,0));
|
||||||
}
|
}
|
||||||
|
|
||||||
//printf("Rotating around (%5.3f %5.3f %5.3f) %5.3f\n",RotAx[0],RotAx[1],RotAx[2],RotAngle);
|
//printf("Rotating around (%5.3f %5.3f %5.3f) %5.3f\n",RotAx[0],RotAx[1],RotAx[2],RotAngle);
|
||||||
a.SetRotate(-RotAngle,RotAx);
|
RotAx.Normalize();
|
||||||
|
a.SetRotate(RotAngle,RotAx);
|
||||||
//Matrix44d rr;
|
//Matrix44d rr;
|
||||||
//rr.SetRotate(-angle, Point3d(0,0,1));
|
//rr.SetRotate(-angle, Point3d(0,0,1));
|
||||||
//a=rr*a;
|
//a=rr*a;
|
||||||
|
@ -291,7 +307,7 @@ void SetupOrthoViewMatrix(Point3x &ViewDir, int subx, int suby,int LocSplit)
|
||||||
Matrix44d rot;
|
Matrix44d rot;
|
||||||
Point3d qq; qq.Import(ViewDir);
|
Point3d qq; qq.Import(ViewDir);
|
||||||
GenMatrix(rot,qq,0);
|
GenMatrix(rot,qq,0);
|
||||||
glMultMatrixd((const double *)&rot);
|
glMultMatrix(rot);
|
||||||
double d=2.0/m.bbox.Diag();
|
double d=2.0/m.bbox.Diag();
|
||||||
glScalef(d,d,d);
|
glScalef(d,d,d);
|
||||||
glTranslate(-m.bbox.Center());
|
glTranslate(-m.bbox.Center());
|
||||||
|
@ -367,7 +383,7 @@ template <class MESH_TYPE> class VertexVisShader : public VisShader<MESH_TYPE>
|
||||||
if(! m.HasPerVertexColor()) assert(0);
|
if(! m.HasPerVertexColor()) assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Init() { VV.resize(m.vert.size()); AssignColorId(); }
|
void Init() { VV.resize(m.vert.size()); }
|
||||||
// Vis::VisMode Id() {return Vis::VMPerVert;};
|
// Vis::VisMode Id() {return Vis::VMPerVert;};
|
||||||
void Compute(int nn);
|
void Compute(int nn);
|
||||||
|
|
||||||
|
@ -399,7 +415,7 @@ int GLAccumPixel( std::vector<int> &PixSeen)
|
||||||
SimplePic<float> snapZ;
|
SimplePic<float> snapZ;
|
||||||
SimplePic<Color4b> snapC;
|
SimplePic<Color4b> snapC;
|
||||||
|
|
||||||
glClearColor(Color4b::White);
|
glClearColor(Color4b::Black);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT | GL_POLYGON_BIT );
|
glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT | GL_POLYGON_BIT );
|
||||||
glDisable(GL_LIGHTING);
|
glDisable(GL_LIGHTING);
|
||||||
|
@ -411,37 +427,23 @@ int GLAccumPixel( std::vector<int> &PixSeen)
|
||||||
|
|
||||||
/////** Si disegnano le front face **/////
|
/////** Si disegnano le front face **/////
|
||||||
glDepthRange(2.0*ZTWIST,1.0f);
|
glDepthRange(2.0*ZTWIST,1.0f);
|
||||||
// glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
|
if(IsClosedFlag) glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
glCullFace(GL_BACK);
|
glCullFace(GL_BACK);
|
||||||
glColor(Color4b::Red);
|
glColor(Color4b::Red);
|
||||||
DrawFill(m);
|
DrawFill(m);
|
||||||
snapC.OpenGLSnap();
|
|
||||||
|
|
||||||
// if(!IsClosed) // sono necessarie due passate in piu!
|
if(!IsClosedFlag) {
|
||||||
//{
|
glCullFace(GL_FRONT);
|
||||||
// /////** Si disegnano le back face shiftate in avanti di 2 epsilon **/////
|
glColor(Color4b::Black);
|
||||||
// glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
|
DrawFill(m);
|
||||||
// glColor(Color4b::Black);
|
snapC.OpenGLSnap();
|
||||||
// glCullFace(GL_FRONT);
|
}
|
||||||
// glDepthRange(0.0f,1.0f-2.0*ZTWIST);
|
|
||||||
// DrawFill(m);
|
|
||||||
// //glw.DrawFill<GLW::NMNone, GLW::CMNone,GLW::TMNone>();
|
|
||||||
//}
|
|
||||||
//if(OMV.size()>0)
|
|
||||||
//{
|
|
||||||
// /////** Si disegnano le back face shiftate in avanti di 2 epsilon **/////
|
|
||||||
// glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
|
|
||||||
// glColor(Color4b::Black);
|
|
||||||
// glDisable(GL_CULL_FACE);
|
|
||||||
// glDepthRange(0.0f,1.0f-2.0*ZTWIST);
|
|
||||||
// for(unsigned int i=0;i<OMV.size();++i)
|
|
||||||
// DrawFill(*(OMV[i]));
|
|
||||||
// //OGV[i]->DrawFill<GLW::NMNone, GLW::CMNone,GLW::TMNone>();
|
|
||||||
//}
|
|
||||||
int cnt=0;
|
int cnt=0;
|
||||||
snapZ.OpenGLSnap(GL_DEPTH_COMPONENT);
|
snapZ.OpenGLSnap(GL_DEPTH_COMPONENT);
|
||||||
snapC.OpenGLSnap();
|
|
||||||
|
glDepthRange(0,1.0f-2.0*ZTWIST);
|
||||||
double MM[16];
|
double MM[16];
|
||||||
glGetDoublev(GL_MODELVIEW_MATRIX,MM);
|
glGetDoublev(GL_MODELVIEW_MATRIX,MM);
|
||||||
double MP[16];
|
double MP[16];
|
||||||
|
@ -449,27 +451,32 @@ int GLAccumPixel( std::vector<int> &PixSeen)
|
||||||
int VP[4];
|
int VP[4];
|
||||||
glGetIntegerv(GL_VIEWPORT,VP);
|
glGetIntegerv(GL_VIEWPORT,VP);
|
||||||
double tx,ty,tz;
|
double tx,ty,tz;
|
||||||
|
|
||||||
for(int i=0;i<m.vert.size();++i)
|
for(int i=0;i<m.vert.size();++i)
|
||||||
{
|
{
|
||||||
gluProject(m.vert[i].P()[0],m.vert[i].P()[1],m.vert[i].P()[2],
|
gluProject(m.vert[i].P()[0],m.vert[i].P()[1],m.vert[i].P()[2],
|
||||||
MM,MP,VP,
|
MM,MP,VP,
|
||||||
&tx,&ty,&tz);
|
&tx,&ty,&tz);
|
||||||
|
int col=1;
|
||||||
|
|
||||||
if(tx>=0 && tx<snapZ.sx && ty>=0 && ty<snapZ.sy)
|
if(tx>=0 && tx<snapZ.sx && ty>=0 && ty<snapZ.sy)
|
||||||
{
|
{
|
||||||
int txi=floor(tx),tyi=floor(ty);
|
int txi=floor(tx),tyi=floor(ty);
|
||||||
float sd=snapZ.Pix(tx,ty);
|
float sd=snapZ.Pix(tx,ty);
|
||||||
|
if(!IsClosedFlag) {
|
||||||
|
col = max( max(snapC.Pix(txi+0,tyi+0)[0],snapC.Pix(txi+1,tyi+0)[0]),
|
||||||
|
max(snapC.Pix(txi+0,tyi+1)[0],snapC.Pix(txi+1,tyi+1)[0]));
|
||||||
|
|
||||||
int col = min( min(snapC.Pix(txi+0,tyi+0)[0],snapC.Pix(txi+1,tyi+0)[0]),
|
// col=snapC.Pix(txi+0,tyi+0)[0];
|
||||||
min(snapC.Pix(txi+0,tyi+1)[0],snapC.Pix(txi+1,tyi+1)[0]));
|
}
|
||||||
if(col!=0)
|
if(col!=0 && tz<sd) {
|
||||||
if(tz<sd+ZTWIST) {
|
|
||||||
PixSeen[i]++;
|
PixSeen[i]++;
|
||||||
cnt++;
|
cnt++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
glPopAttrib();
|
glPopAttrib();
|
||||||
printf("Seen %i vertexes on %i\n",cnt,m.vert.size());
|
//printf("Seen %i vertexes on %i\n",cnt,m.vert.size());
|
||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -489,8 +496,14 @@ void SmoothVisibility()
|
||||||
for(unsigned int i=0;i<VV2.size();++i)
|
for(unsigned int i=0;i<VV2.size();++i)
|
||||||
VV[i]=VV2[i]/VC[i];
|
VV[i]=VV2[i]/VC[i];
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
The visibility is mapped in [0..1]
|
||||||
|
then clamped to [low,high]
|
||||||
|
this value is mapped again in [0.1] and gamma corrected;
|
||||||
|
and at the end is scaled for 'Scale'
|
||||||
|
|
||||||
void MapVisibility(float Gamma=1, float LowPass=0, float HighPass=1, bool FalseColor = false)
|
*/
|
||||||
|
void MapVisibility(float Gamma=1, float LowPass=0, float HighPass=1, float Scale= 1.0)
|
||||||
{
|
{
|
||||||
float minv=*min_element(VV.begin(),VV.end());
|
float minv=*min_element(VV.begin(),VV.end());
|
||||||
float maxv=*max_element(VV.begin(),VV.end());
|
float maxv=*max_element(VV.begin(),VV.end());
|
||||||
|
@ -501,7 +514,7 @@ void MapVisibility(float Gamma=1, float LowPass=0, float HighPass=1, bool FalseC
|
||||||
float gval=(VV[vi-m.vert.begin()]-minv)/(maxv-minv);
|
float gval=(VV[vi-m.vert.begin()]-minv)/(maxv-minv);
|
||||||
if(gval<LowPass) gval=LowPass;
|
if(gval<LowPass) gval=LowPass;
|
||||||
if(gval>HighPass) gval=HighPass;
|
if(gval>HighPass) gval=HighPass;
|
||||||
(*vi).C().SetGrayShade(pow((gval-LowPass)/(HighPass-LowPass),Gamma));
|
(*vi).C().SetGrayShade(Scale*pow((gval-LowPass)/(HighPass-LowPass),Gamma));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue