Create openMVS.build
This commit is contained in:
commit
365aa390ba
1856 files changed
+839085
No files matched your search
@@ -0,0 +1,14 @@
|
||||
|
||||
VCGLib http://vcg.sf.net o o
|
||||
Visual and Computer Graphics Library o o
|
||||
_ O _
|
||||
Copyright(C) 2005-2006 \/)\/
|
||||
Visual Computing Lab http://vcg.isti.cnr.it /\/|
|
||||
ISTI - Italian National Research Council |
|
||||
\
|
||||
ShadeVis 1.00 2005/11/11
|
||||
All rights reserved.
|
||||
|
||||
|
||||
2005/11/11 Release 1.00
|
||||
Initial Release
|
||||
@@ -0,0 +1,598 @@
|
||||
/****************************************************************************
|
||||
* VCGLib o o *
|
||||
* Visual and Computer Graphics Library o o *
|
||||
* _ O _ *
|
||||
* Copyright(C) 2004-2016 \/)\/ *
|
||||
* Visual Computing Lab /\/| *
|
||||
* ISTI - Italian National Research Council | *
|
||||
* \ *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
||||
* for more details. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
/****************************************************************************
|
||||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.10 2005/11/12 06:48:47 cignoni
|
||||
Version 1.0
|
||||
Added management of point set, correct bug in printing on the screen,
|
||||
|
||||
Revision 1.9 2005/01/03 13:59:54 cignoni
|
||||
Resolved min/max macro conflict
|
||||
|
||||
Revision 1.8 2004/09/30 00:57:42 ponchio
|
||||
Reference to temporary fixed and indented.
|
||||
|
||||
Revision 1.7 2004/09/28 09:46:51 cignoni
|
||||
Added MapFalseColor
|
||||
|
||||
Revision 1.6 2004/09/16 14:08:35 ponchio
|
||||
gamma is a math function.
|
||||
|
||||
Revision 1.5 2004/09/10 14:02:20 cignoni
|
||||
Added Cone directions
|
||||
|
||||
Revision 1.4 2004/09/09 22:34:38 cignoni
|
||||
Integrated lost modifications...
|
||||
|
||||
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
|
||||
Added GPL comments
|
||||
|
||||
|
||||
****************************************************************************/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <time.h>
|
||||
// this define is mandatory to avoid the conflicts due to the silly definition of
|
||||
// min and max macros in windows.h (included by glut...)
|
||||
#define NOMINMAX
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <GL/glut.h>
|
||||
#include <wrap/gl/space.h>
|
||||
|
||||
|
||||
#include <wrap/callback.h>
|
||||
#include <vcg/math/base.h>
|
||||
#include <wrap/gui/trackball.h>
|
||||
#include <vcg/simplex/vertex/with/vcvn.h>
|
||||
#include <vcg/simplex/vertex/with/vcvn.h>
|
||||
#include <vcg/simplex/face/with/fn.h>
|
||||
#include <vcg/space/index/grid_static_ptr.h>
|
||||
#include <vcg/complex/complex.h>
|
||||
#include<wrap/io_trimesh/export_ply.h>
|
||||
#include<wrap/io_trimesh/import_ply.h>
|
||||
#include<vcg/complex/algorithms/update/normal.h>
|
||||
#include<vcg/complex/algorithms/update/bounding.h>
|
||||
#include<vcg/complex/algorithms/update/color.h>
|
||||
|
||||
#include "visshader.h"
|
||||
using namespace vcg;
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
|
||||
// Vertex, Face, Mesh and Grid definitions.
|
||||
class MyEdge;
|
||||
class AFace;
|
||||
class AVertex : public VertexVCVN< float ,MyEdge,AFace > {};
|
||||
class AFace : public FaceFN< AVertex,MyEdge,AFace > {};
|
||||
class AMesh : public tri::TriMesh< vector<AVertex>, vector<AFace> > {};
|
||||
|
||||
///////// Global ////////
|
||||
|
||||
int SampleNum=64;
|
||||
int WindowRes=800;
|
||||
unsigned int TexInd=0;
|
||||
bool SwapFlag=false;
|
||||
bool CullFlag=false;
|
||||
bool ClosedFlag=false;
|
||||
Point3f ConeDir(0,1,0);
|
||||
float ConeAngleRad = math::ToRad(180.0f);
|
||||
|
||||
float lopass=0,hipass=1,gamma_correction=1;
|
||||
float diff=.8;
|
||||
float ambi=.2;
|
||||
|
||||
bool LightFlag=true;
|
||||
bool ColorFlag=true;
|
||||
bool FalseColorFlag=false;
|
||||
bool ShowDirFlag=false;
|
||||
int imgcnt=0;
|
||||
|
||||
Color4b BaseColor=Color4b::White;
|
||||
Trackball QV;
|
||||
Trackball QL;
|
||||
Trackball *Q=&QV;
|
||||
|
||||
int ScreenH,ScreenW;
|
||||
float ViewAngle=33;
|
||||
vector<Point3f> ViewVector;
|
||||
|
||||
bool cb(const char *buf)
|
||||
{
|
||||
printf(buf);
|
||||
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 );
|
||||
glPushAttrib(GL_ENABLE_BIT);
|
||||
glDisable(GL_LIGHTING);
|
||||
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();
|
||||
glPopAttrib();
|
||||
}
|
||||
|
||||
// prototypes
|
||||
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)
|
||||
{
|
||||
if(mm.face.empty())
|
||||
{
|
||||
glPushAttrib(GL_ENABLE_BIT);
|
||||
glDisable(GL_LIGHTING);
|
||||
AMesh::VertexIterator vi;
|
||||
glBegin(GL_POINTS);
|
||||
for(vi=mm.vert.begin();vi!=mm.vert.end();++vi)
|
||||
{
|
||||
if(ColorFlag) glColor((*vi).C());
|
||||
glVertex((*vi).P());
|
||||
}
|
||||
glEnd();
|
||||
glPopAttrib();
|
||||
}
|
||||
else
|
||||
{
|
||||
AMesh::FaceIterator fi;
|
||||
glBegin(GL_TRIANGLES);
|
||||
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(1)->N()); if(ColorFlag) 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());
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
|
||||
AMesh m;
|
||||
VertexVisShader<AMesh> Vis(m);
|
||||
|
||||
string OutNameMsh;
|
||||
|
||||
|
||||
/* Called when the window is first opened and whenever
|
||||
* the window is reconfigured (moved or resized).
|
||||
*/
|
||||
void ViewReshape(GLsizei w, GLsizei h)
|
||||
{
|
||||
ScreenW=w; ScreenH=h;
|
||||
glViewport(0,0,w,h);
|
||||
}
|
||||
|
||||
void ViewDisplay (void)
|
||||
{
|
||||
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glLoadIdentity ();
|
||||
gluPerspective(ViewAngle,(float)ScreenW/ScreenH,1,7);
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
glLoadIdentity ();
|
||||
glPushMatrix();
|
||||
QL.Apply();
|
||||
glutPrintf(5,5,"Diffuse %04.2f Ambient %04.2f "
|
||||
" LowPass %04.2f HiPass %04.2f Gamma %04.2f rgb = %03i:%03i:%03i",
|
||||
diff,ambi,lopass,hipass,gamma_correction,BaseColor[0],BaseColor[1],BaseColor[2]);
|
||||
|
||||
GLfloat light_position0[] = {0.0, 10.0, 300.0, 0.0};
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
|
||||
glPopMatrix();
|
||||
glTranslatef(0,0,-4);
|
||||
if(Q==&QL) DrawLightVector();
|
||||
QL.GetView();
|
||||
QV.GetView();
|
||||
QV.Apply();
|
||||
if(ShowDirFlag) DrawViewVector();
|
||||
|
||||
float d = 2.0/m.bbox.Diag();
|
||||
glScalef(d, d, d);
|
||||
glColor3f(diff,diff,diff);
|
||||
glTranslate(-m.bbox.Center());
|
||||
if(LightFlag) glEnable(GL_LIGHTING);
|
||||
else glDisable(GL_LIGHTING);
|
||||
if(ColorFlag) glEnable(GL_COLOR_MATERIAL);
|
||||
else glDisable(GL_COLOR_MATERIAL);
|
||||
if(FalseColorFlag) glColorMaterial(GL_FRONT,GL_DIFFUSE);
|
||||
else 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);
|
||||
glutSwapBuffers();
|
||||
}
|
||||
|
||||
void ViewSpecialKey(int , int , int )
|
||||
{
|
||||
glutPostRedisplay();
|
||||
}
|
||||
void Toggle(bool &flag) {flag = !flag;}
|
||||
void UpdateVis()
|
||||
{
|
||||
if( LightFlag && !FalseColorFlag)
|
||||
Vis.MapVisibility(gamma_correction,lopass,hipass,ambi);
|
||||
if(!LightFlag && !FalseColorFlag)
|
||||
Vis.MapVisibility(gamma_correction,lopass,hipass,1.0);
|
||||
if(FalseColorFlag)
|
||||
Vis.MapFalseColor();
|
||||
}
|
||||
/*********************************************************************/
|
||||
/*********************************************************************/
|
||||
/*********************************************************************/
|
||||
|
||||
void ViewKey(unsigned char key, int , int )
|
||||
{
|
||||
Point3f dir;
|
||||
switch (key) {
|
||||
case 27: exit(0); break;
|
||||
case 9: if(Q==&QV) Q=&QL;else Q=&QV; break;
|
||||
case 'l' :
|
||||
lopass=lopass+.05;
|
||||
printf("Lo %f, Hi %f Gamma %f\n",lopass,hipass,gamma_correction);
|
||||
UpdateVis(); break;
|
||||
case 'L' :
|
||||
lopass=lopass-.05;
|
||||
printf("Lo %f, Hi %f Gamma %f\n",lopass,hipass,gamma_correction);
|
||||
UpdateVis(); break;
|
||||
case 'h' :
|
||||
hipass=hipass-.05;
|
||||
printf("Lo %f, Hi %f Gamma %f\n",lopass,hipass,gamma_correction);
|
||||
UpdateVis(); break;
|
||||
case 'H' :
|
||||
hipass=hipass+.05;
|
||||
printf("Lo %f, Hi %f Gamma %f\n",lopass,hipass,gamma_correction);
|
||||
UpdateVis(); break;
|
||||
case 'd' : diff+=.05; printf("Ambient %f Diffuse %f, \n",ambi,diff); UpdateVis(); break;
|
||||
case 'D' : diff-=.05; printf("Ambient %f Diffuse %f, \n",ambi,diff); UpdateVis(); break;
|
||||
case 'a' : ambi+=.05; printf("Ambient %f Diffuse %f, \n",ambi,diff); UpdateVis(); break;
|
||||
case 'A' : ambi-=.05; printf("Ambient %f Diffuse %f, \n",ambi,diff); UpdateVis(); break;
|
||||
|
||||
case 'e' : ambi+=.05; diff-=.05;
|
||||
printf("Ambient %f Diffuse %f, \n",ambi,diff);
|
||||
UpdateVis(); break;
|
||||
case 'E' : ambi-=.05; diff+=.05;
|
||||
printf("Ambient %f Diffuse %f, \n",ambi,diff);
|
||||
UpdateVis(); break;
|
||||
case 'p' :
|
||||
gamma_correction=gamma_correction-.05;
|
||||
printf("Lo %f, Hi %f Gamma %f\n",lopass,hipass,gamma_correction);
|
||||
UpdateVis(); break;
|
||||
case 'P' :
|
||||
gamma_correction=gamma_correction+.05;
|
||||
printf("Lo %f, Hi %f Gamma %f\n",lopass,hipass,gamma_correction);
|
||||
UpdateVis(); break;
|
||||
case 13 :
|
||||
//Vis.ComputeUniform(SampleNum,ViewVector,cb);
|
||||
Vis.ComputeUniformCone(SampleNum,ViewVector, ConeAngleRad,ConeDir,cb);
|
||||
UpdateVis(); break;
|
||||
case ' ' : {
|
||||
Point3f dir = Q->camera.ViewPoint();
|
||||
printf("ViewPoint %f %f %f\n",dir[0],dir[1],dir[2]);
|
||||
dir.Normalize();
|
||||
dir=Inverse(Q->track.Matrix())*dir;
|
||||
printf("ViewPoint %f %f %f\n",dir[0],dir[1],dir[2]);
|
||||
dir.Normalize();
|
||||
Vis.ComputeSingle(dir,ViewVector,cb);
|
||||
UpdateVis();
|
||||
} break;
|
||||
case 'r' : BaseColor[0]=min(255,BaseColor[0]+2); break;
|
||||
case 'R' : BaseColor[0]=max( 0,BaseColor[0]-2); break;
|
||||
case 'g' : BaseColor[1]=min(255,BaseColor[1]+2); break;
|
||||
case 'G' : BaseColor[1]=max( 0,BaseColor[1]-2); break;
|
||||
case 'b' : BaseColor[2]=min(255,BaseColor[2]+2); break;
|
||||
case 'B' : BaseColor[2]=max( 0,BaseColor[2]-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' :
|
||||
Vis.SmoothVisibility();
|
||||
UpdateVis(); break;
|
||||
case 't' :
|
||||
Vis.SmoothVisibility(true);
|
||||
UpdateVis(); break;
|
||||
case 'S' :
|
||||
{
|
||||
vcg::tri::io::PlyInfo p;
|
||||
p.mask|=vcg::tri::io::Mask::IOM_VERTCOLOR /* | vcg::ply::PLYMask::PM_VERTQUALITY*/ ;
|
||||
tri::io::ExporterPLY<AMesh>::Save(m,OutNameMsh.c_str(),false,p);
|
||||
}
|
||||
break;
|
||||
case 'C' : LightFlag = !LightFlag;
|
||||
printf("Toggled Light %s\n",LightFlag?"on":"off");
|
||||
UpdateVis(); break;
|
||||
case 'c' : ColorFlag = !ColorFlag;
|
||||
printf("Toggled Color %s\n",ColorFlag?"on":"off"); break;
|
||||
case 'f' : FalseColorFlag = !FalseColorFlag;
|
||||
printf("Toggled FalseColor %s\n",ColorFlag?"on":"off");
|
||||
UpdateVis(); break;
|
||||
|
||||
case '1' : diff=0.80f; ambi=0.10f; gamma_correction=1.0; lopass=0.00f; hipass=1.00f; ColorFlag=false; UpdateVis(); break;
|
||||
case '2' : diff=0.65f; ambi=0.30f; gamma_correction=1.0; lopass=0.15f; hipass=0.80f; ColorFlag=true; UpdateVis(); break;
|
||||
case '3' : diff=0.45f; ambi=0.50f; gamma_correction=1.0; lopass=0.20f; hipass=0.75f; ColorFlag=true; UpdateVis(); break;
|
||||
case '4' : diff=0.35f; ambi=0.60f; gamma_correction=1.0; lopass=0.25f; hipass=0.70f; ColorFlag=true; UpdateVis(); break;
|
||||
}
|
||||
glutPostRedisplay(); ;
|
||||
}
|
||||
void ViewMenu(int val)
|
||||
{
|
||||
ViewKey(val, 0, 0);
|
||||
}
|
||||
/*********************************************************************/
|
||||
// TrackBall Functions
|
||||
/*********************************************************************/
|
||||
|
||||
int GW,GH; // Grandezza della finestra
|
||||
|
||||
void ViewMouse(int button, int state, int x, int y)
|
||||
{
|
||||
static int KeyMod=0;
|
||||
static int glut_buttons=0;
|
||||
//printf("ViewMouse %i %i %i %i\n",x,y,button,state);
|
||||
int m_mask = 0;
|
||||
if(state == GLUT_DOWN) {
|
||||
KeyMod=glutGetModifiers();
|
||||
if(GLUT_ACTIVE_SHIFT & KeyMod) m_mask |= Trackball::KEY_SHIFT;
|
||||
if(GLUT_ACTIVE_ALT & KeyMod) m_mask |= Trackball::KEY_ALT;
|
||||
if(GLUT_ACTIVE_CTRL & KeyMod) m_mask |= Trackball::KEY_CTRL;
|
||||
|
||||
glut_buttons |= (1<<button);
|
||||
Q->MouseDown(x, ScreenH-y, glut_buttons | m_mask);
|
||||
} else {
|
||||
if(GLUT_ACTIVE_SHIFT & KeyMod) m_mask |= Trackball::KEY_SHIFT;
|
||||
if(GLUT_ACTIVE_ALT & KeyMod) m_mask |= Trackball::KEY_ALT;
|
||||
if(GLUT_ACTIVE_CTRL & KeyMod) m_mask |= Trackball::KEY_CTRL;
|
||||
glut_buttons |= (1<<button);
|
||||
Q->MouseUp(x, ScreenH-y, glut_buttons | m_mask);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewMouseMotion(int x, int y)
|
||||
{
|
||||
Q->MouseMove(x,ScreenH-y);
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
||||
void SetLight()
|
||||
{
|
||||
GLfloat light_ambient0[] = {0.0, 0.0, 0.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};
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT, light_diffuse0);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse0);
|
||||
glEnable(GL_LIGHT0);
|
||||
glLightModelfv(GL_LIGHT_MODEL_AMBIENT,light_ambient0);
|
||||
|
||||
}
|
||||
|
||||
void ViewInit (void) {
|
||||
SetLight();
|
||||
Q->Reset();
|
||||
Q->radius= 1;
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
glClearColor (0.8, 0.8, 0.8, 0.0);
|
||||
glEnable(GL_NORMALIZE);
|
||||
glEnable(GL_LIGHTING);
|
||||
|
||||
// glEnable(GL_BLEND);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
// glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if(argc<2) {
|
||||
printf(
|
||||
"shadevis 1.0 \n"__DATE__"\n"
|
||||
"Copyright 2003-2004 Visual Computing Lab I.S.T.I. C.N.R.\n"
|
||||
"Paolo Cignoni (cignoni@isti.cnr.it)\n\n"
|
||||
"Usage: shadevis file.ply [options]\n"
|
||||
"Options:\n"
|
||||
" -w# WindowResolution (default 600)\n"
|
||||
" -n# Sample Directions (default 64)\n"
|
||||
" -z# z offset (default 1e-3)\n"
|
||||
" -c assume that the mesh is closed (slightly faster, default false)\n"
|
||||
" -f Flip normal of the model\n"
|
||||
" -da # Cone Direction Angle in degree (default 180)\n"
|
||||
" -dv # # # Cone Direction vector (default 0 0 1)\n"
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
srand(time(0));
|
||||
int i=1;
|
||||
while(i<argc && (argv[i][0]=='-'))
|
||||
{
|
||||
switch(argv[i][1])
|
||||
{
|
||||
case 'd' :
|
||||
if(argv[i][2] == 'a') {
|
||||
ConeAngleRad = math::ToRad(atof(argv[i+1])); ++i; break;
|
||||
}
|
||||
if(argv[i][2] == 'v') {
|
||||
Point3f p(atof(argv[i+1]),atof(argv[i+2]),atof(argv[i+3]));
|
||||
ConeDir = Normalize(p);
|
||||
i+=3; break;
|
||||
}
|
||||
printf("Error unable to parse option '%s'\n",argv[i]);
|
||||
exit(0);
|
||||
break;
|
||||
case 'n' : SampleNum = atoi(argv[i]+2); 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 '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;
|
||||
default: {
|
||||
printf("Error unable to parse option '%s'\n",argv[i]);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
|
||||
|
||||
string basename = argv[i];
|
||||
if(!(basename.substr(basename.length()-4)==".ply")) {
|
||||
printf("Error: Unknown file extension %s\n",basename.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
// loading original mesh
|
||||
int ret=tri::io::ImporterPLY<AMesh>::Open(m,argv[i]);
|
||||
if(ret) {printf("Error unable to open mesh %s : '%s' \n",argv[i],tri::io::ImporterPLY<AMesh>::ErrorMsg(ret));exit(-1);}
|
||||
tri::UpdateNormals<AMesh>::PerVertexNormalized(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]);
|
||||
|
||||
OutNameMsh=(string(argv[i]).substr(0,strlen(argv[i])-4));
|
||||
OutNameMsh+="_vis.ply";
|
||||
|
||||
printf("Mesh Output filename %s\n",OutNameMsh.c_str());
|
||||
|
||||
printf("Mesh %iv %if bbox Diag %g\n",m.vn,m.fn,m.bbox.Diag());
|
||||
|
||||
glutInit(&argc, argv);
|
||||
|
||||
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
|
||||
glutInitWindowSize(WindowRes, WindowRes);
|
||||
glutInitWindowPosition (10,10);
|
||||
glutCreateWindow ("shadevis - Visual Computing Lab - vcg.isti.cnr.it ");
|
||||
glutDisplayFunc(ViewDisplay);
|
||||
glutReshapeFunc(ViewReshape);
|
||||
glutKeyboardFunc(ViewKey);
|
||||
glutSpecialFunc(ViewSpecialKey);
|
||||
glutMouseFunc(ViewMouse);
|
||||
glutMotionFunc(ViewMouseMotion);
|
||||
|
||||
ViewInit();
|
||||
glewInit();
|
||||
glutMainLoop();
|
||||
|
||||
return(0);
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
|
||||
VCGLib http://vcg.sf.net o o
|
||||
Visual and Computer Graphics Library o o
|
||||
_ O _
|
||||
Copyright(C) 2004 \/)\/
|
||||
Visual Computing Lab http://vcg.isti.cnr.it /\/|
|
||||
ISTI - Italian National Research Council |
|
||||
\
|
||||
ShadeVis, All rights reserved.
|
||||
|
||||
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
|
||||
for more details.
|
||||
|
||||
--- Synopsis ---
|
||||
|
||||
'shadevis' is a tool designed to compute a per vertex, ambient occlusion term;
|
||||
This term can be used for a shading effect, commonly known as ambient occlusion
|
||||
shading, that is aimed to provide more faithful simple realtime rendering of rather complex meshes.
|
||||
|
||||
In practice rather than considering the ambient lighting to exist uniformally throughout a scene,
|
||||
this approach determines the ambient brightness of each part of a surface to be proportional to the extent
|
||||
to which the surface has "its outward view of its environment" free i.e. occluded, by other surfaces of the object. For example, the upper part of the David forehead is less exposed to its local environment than the nose and as a consequence it will be proportionally darker.
|
||||
|
||||
The most common techniques to compute ambient occlusion is based on shooting rays from each surface element to evaluate the quantity of light that reach it. Shadevis tools use OpenGL to accellerate this process by simply rendering the scene ortographically from a set of uniformely distributed directions and checking against the zbuffer if each vertex is occluded or not. Usually the result is stored in a texture map.
|
||||
|
||||
The Shadevis tool is oriented to handle rather large meshes, we have successfully used on a 8M triangle mesh of the David on a 512Mb machine.
|
||||
|
||||
|
||||
We have used this tool also for computing the exposition of falling agents over the Michelangelo's David.
|
||||
|
||||
Please, when using this tool cite the following references:
|
||||
|
||||
R. Borgo, P. Cignoni, R. Scopigno
|
||||
An easy to use visualization system for huge cultural heritage meshes
|
||||
VAST’01 Conference, Greece, Nov. 28-30, 2001.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
For any question about this software please contact:
|
||||
Paolo Cignoni ( p.cignoni@isti.cnr.it )
|
||||
|
||||
|
||||
---- Notes on the Color mapping ----
|
||||
|
||||
This value is mapped into a gray shade according to this formula
|
||||
|
||||
v=clamp(v,LowPass,HighPass)
|
||||
v=(v-LowPass)/(HighPass-LowPass) /// Normalized 0..1
|
||||
graylevel=GammaCorrection(v,GammaLev)
|
||||
|
||||
This graylevel is used in the Opengl lighting equation as follow.
|
||||
Let assume that there is just a single directional light and no emissive and no specular component in the material, the OpenGL lighting equation is:
|
||||
|
||||
C = Acm *Acs + Acm*Acli + (n*L)*Dcm*Dcli
|
||||
|
||||
where
|
||||
Acm ambient color of the material (glMaterial or glColor if glColorMaterial is enabled)
|
||||
Acs ambient color of the scene (glLightModel)
|
||||
Acli ambient intensity of the light (glLight)
|
||||
Dcm diffuse color of the material (we assume constant over the object).
|
||||
|
||||
We simply substitute the constant ambient that is usually constant, with a per vertex color, using a constant diffuse color.
|
||||
|
||||
|
||||
|
||||
Simple one line tutorial:
|
||||
-- load a ply mesh, press 'enter', wait, press preset keys from 1 to 4.
|
||||
|
||||
Another tutorial:
|
||||
-- load a ply mesh,
|
||||
-- press 'enter', wait taking care to not overlap existing window with other ones, ambient occlusion will be computed and stored per vertex
|
||||
|
||||
Press preset keys from 1 to 4.
|
||||
Now you can play with diffuse and ambient percentages, pressing d/D and a/A you increase/decrease
|
||||
the percentage of the diffuse/ambient component of OpenGL lighting,
|
||||
these percentages are shown at the bottom of the screen; when ambient==0 you have pure diffuse lighting.
|
||||
when diffuse==0 and ambient=100 you have a pure ambient occlusion lighting.
|
||||
To simultaneously increase ambient and decrease diffuse use e/E keys.
|
||||
Note that neither these values nor their sum are clamped to 100%.
|
||||
The above keys do not change stored visibility values but just their mapping to opengl ambient.
|
||||
Smoothing and Enhancing on the other hand really changes these values.
|
||||
|
||||
|
||||
---- Reference ----
|
||||
Keys
|
||||
'esc' quit
|
||||
'enter' compute the sampling (sample are added so pressing the key twice is the same of using 2n sampling directions)
|
||||
' ' add the current view to the sampling direction
|
||||
'S' save a ply with the currently computed color.
|
||||
's' smooth (average) the computed visibility among adjacent vertices
|
||||
't' enhance the computed visibility among adjacent vertices (enhancement is done by (val + (val-avg)) )
|
||||
'v' toggle the rendering of directions used for the sampling.
|
||||
'V' Save a Snapshot of the current View.
|
||||
|
||||
'tab' switch between object trackball light trackball
|
||||
|
||||
'l'-'L' Increase/Decrease LowPass
|
||||
'h'-'H' Increase/Decrease HighPass
|
||||
'p'-'p' Increase/Decrease GammaLev
|
||||
|
||||
'r'-'R' Increase/Decrease red component of diffuse color
|
||||
'g'-'G' Increase/Decrease green component of diffuse color
|
||||
'b'-'B' Increase/Decrease blue component of diffuse color
|
||||
|
||||
'C' Toggle Lighting
|
||||
'c' Toggle per vertex coloring
|
||||
'f' Toggle false color visualization
|
||||
|
||||
'a'-'A' Increase/Decrease Ambient Coefficient
|
||||
'd'-'D' Increase/Decrease Diffuse Coefficient
|
||||
'e'-'E' Increase/Decrease Balance between Diffuse and Ambient coefficient
|
||||
'1'..'4' Some preset values for the ambient/diffuse terms ranging from standard constant ambient to a strongly shaded coloring;
|
||||
|
||||
---- Command Line Options ----
|
||||
|
||||
-n <number> set the number of sampling direction (default 64, but 100~500 should be better)
|
||||
-f flip normal of the surface
|
||||
-z <float> specify the z tolerance used to decide if a vertex is visible against the zbuffer or not (default 1e-3, useful range 1e-3 .. 1e-6)
|
||||
@@ -0,0 +1,90 @@
|
||||
/****************************************************************************
|
||||
* VCGLib o o *
|
||||
* Visual and Computer Graphics Library o o *
|
||||
* _ O _ *
|
||||
* Copyright(C) 2004-2016 \/)\/ *
|
||||
* Visual Computing Lab /\/| *
|
||||
* ISTI - Italian National Research Council | *
|
||||
* \ *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
||||
* for more details. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
/****************************************************************************
|
||||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __VCG_SIMPLE_PIC
|
||||
#define __VCG_SIMPLE_PIC
|
||||
#include <vcg/math/matrix44.h>
|
||||
|
||||
namespace vcg {
|
||||
template <class PixType>
|
||||
class SimplePic
|
||||
{public:
|
||||
std::vector<PixType> img;
|
||||
int sx,sy;
|
||||
void Create(int tx,int ty)
|
||||
{
|
||||
sx=tx;sy=ty;
|
||||
img.resize(sx*sy);
|
||||
}
|
||||
PixType &Pix(int x, int y) {return img[sx*y+x];}
|
||||
|
||||
void OpenGLSnap(GLenum format=0)
|
||||
{
|
||||
int vp[4];
|
||||
glGetIntegerv( GL_VIEWPORT,vp ); // Lettura viewport
|
||||
glPixelStorei( GL_PACK_ROW_LENGTH, 0);
|
||||
glPixelStorei( GL_PACK_ALIGNMENT, 1);
|
||||
int tx = vp[2];
|
||||
int ty = vp[3];
|
||||
|
||||
Create(tx,ty);
|
||||
|
||||
GLenum mtype = 0;
|
||||
|
||||
if(format==0) {
|
||||
format = GL_RGBA;
|
||||
mtype = GL_UNSIGNED_BYTE;
|
||||
}
|
||||
if(format==GL_DEPTH_COMPONENT) {
|
||||
format = GL_DEPTH_COMPONENT;
|
||||
mtype = GL_FLOAT;
|
||||
}
|
||||
glReadPixels(vp[0],vp[1],vp[2],vp[3],format,mtype,(GLvoid *)&img[0]);
|
||||
}
|
||||
bool SavePPM( const char * filename )
|
||||
{
|
||||
FILE * fp = fopen(filename,"wb");
|
||||
if(fp==0) return false;
|
||||
|
||||
|
||||
fprintf(fp,"P6\n%d %d\n255\n",sx,sy);
|
||||
|
||||
for(int i=0;i<sx*sy;++i)
|
||||
{
|
||||
fwrite(&(img[i]),3,1,fp);
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif // __VCG_MESH_VISIBILITY
|
||||
@@ -0,0 +1,573 @@
|
||||
/****************************************************************************
|
||||
* VCGLib o o *
|
||||
* Visual and Computer Graphics Library o o *
|
||||
* _ O _ *
|
||||
* Copyright(C) 2004-2016 \/)\/ *
|
||||
* Visual Computing Lab /\/| *
|
||||
* ISTI - Italian National Research Council | *
|
||||
* \ *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
||||
* for more details. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
/****************************************************************************
|
||||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.9 2005/11/12 06:47:18 cignoni
|
||||
Added Enhancement, removed type warnings,
|
||||
started to refactor code in order to remove the unnecessary generality of the class.
|
||||
|
||||
Revision 1.8 2004/09/28 09:45:17 cignoni
|
||||
Added MapFalseColor
|
||||
|
||||
Revision 1.7 2004/09/16 14:23:57 ponchio
|
||||
fixed gcc template compatibility issues.
|
||||
|
||||
Revision 1.6 2004/09/10 14:02:20 cignoni
|
||||
Added Cone directions
|
||||
|
||||
Revision 1.5 2004/09/09 22:59:21 cignoni
|
||||
Removed many small warnings
|
||||
|
||||
Revision 1.4 2004/09/09 22:37:48 cignoni
|
||||
Integrated lost modifications...
|
||||
|
||||
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
|
||||
Added GPL comments
|
||||
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __VCG_MESH_VISIBILITY
|
||||
#define __VCG_MESH_VISIBILITY
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <bitset>
|
||||
#include <vcg/math/matrix44.h>
|
||||
#include <wrap/gl/math.h>
|
||||
#include "simplepic.h"
|
||||
#include <vcg/math/gen_normal.h>
|
||||
|
||||
namespace vcg {
|
||||
// Base Class che definisce le varie interfaccie;
|
||||
template <class MESH_TYPE, int MAXVIS=2048> class VisShader
|
||||
{
|
||||
public :
|
||||
enum {VisMax=MAXVIS};
|
||||
VisShader(MESH_TYPE &me):m(me)
|
||||
{
|
||||
CullFlag= false;
|
||||
IsClosedFlag = false;
|
||||
ZTWIST=1e-3;
|
||||
SplitNum=1;
|
||||
|
||||
CameraViewing=false;
|
||||
}
|
||||
|
||||
typedef Point3<typename MESH_TYPE::ScalarType> Point3x;
|
||||
|
||||
typedef typename MESH_TYPE::CoordType CoordType;
|
||||
typedef typename MESH_TYPE::ScalarType ScalarType;
|
||||
typedef typename MESH_TYPE::VertexType VertexType;
|
||||
typedef typename MESH_TYPE::VertexPointer VertexPointer;
|
||||
typedef typename MESH_TYPE::VertexIterator VertexIterator;
|
||||
typedef typename MESH_TYPE::FaceIterator FaceIterator;
|
||||
typedef typename MESH_TYPE::FaceType FaceType;
|
||||
typedef Matrix44<ScalarType> Matrix44x;
|
||||
typedef Box3<ScalarType> Box3x;
|
||||
|
||||
// The Basic Data the mesh and its wrapper;
|
||||
MESH_TYPE &m;
|
||||
|
||||
std::vector<MESH_TYPE *> OMV; // Occluder Mesh Vector;
|
||||
|
||||
// la visibilita' e' in float, per ogni entita'
|
||||
// 1 significa che e' totalmente visibile per una data direzione.
|
||||
|
||||
std::vector<float> VV;
|
||||
std::vector< Point3x > VN; // Vettore delle normali che ho usato per calcolare la mask e i float in W;
|
||||
|
||||
// User defined parameters and flags
|
||||
bool IsClosedFlag;
|
||||
float ZTWIST;
|
||||
bool CullFlag; // Enable the frustum culling. Useful when the splitting value is larger than 2
|
||||
int SplitNum;
|
||||
protected:
|
||||
bool CameraViewing;
|
||||
//Camera<ScalarType> Cam;
|
||||
public:
|
||||
|
||||
/********************************************************/
|
||||
// Generic functions with Specialized code for every subclass
|
||||
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 int GLAccumPixel( std::vector<int> &PixSeen)=0;
|
||||
|
||||
virtual bool ReadVisibility(const char * /*filename*/){assert( 0); return false;}
|
||||
virtual bool WriteVisibility(const char * /*filename*/){assert( 0); return false;}
|
||||
|
||||
/********************************************************/
|
||||
// Generic functions with same code for every subclass
|
||||
|
||||
void Clear() {
|
||||
fill(VV.begin(),VV.end(),0); }
|
||||
|
||||
void InitGL()
|
||||
{
|
||||
glPushAttrib(GL_COLOR_BUFFER_BIT );
|
||||
::glClearColor (1.0, 1.0, 1.0, 0.0);
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
}
|
||||
|
||||
void RestoreGL()
|
||||
{
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
glPopAttrib();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Funzione principale di conversione in visibilita'
|
||||
Dati i due vettori PixSeen e PixNotSeen che indicano per ogni entita' (vertice o faccia)
|
||||
quanti sono, rispettivamente, i pixel visibili e occlusi,
|
||||
questa funzione calcola un valore float per ogni entita' che indica quanto e' visibile lungo una data direzione camera
|
||||
== 1 significa completamente visibile
|
||||
== 0 significa completamente occluso.
|
||||
|
||||
*/
|
||||
void AddPixelCount(std::vector<float> &_VV, const std::vector<int> &PixSeen)
|
||||
{
|
||||
assert(_VV.size()==PixSeen.size());
|
||||
for(unsigned int i=0;i<PixSeen.size();++i)
|
||||
if(PixSeen[i]>0) _VV[i]+= 1;
|
||||
}
|
||||
|
||||
|
||||
//void SetVisibilityMask(std::vector< std::bitset<MAXVIS> > &_VM, const std::vector<int> &PixSeen, const int dir)
|
||||
// {
|
||||
// assert(_VM.size()==PixSeen.size());
|
||||
// for(int i=0;i<PixSeen.size();++i)
|
||||
// if(PixSeen[i]>0) _VM[i][dir]=true;
|
||||
// }
|
||||
|
||||
/*******************************
|
||||
Funzioni ad alto livello che computano le Visibility Mask per varie distribuzioni di direzioni
|
||||
|
||||
|
||||
*******************************/
|
||||
|
||||
// Funzione Generica
|
||||
// Calcola l'occlusion in base all'insieme VN di direzioni.
|
||||
|
||||
void Compute( CallBack *cb)
|
||||
{
|
||||
//cb(buf.format("Start to compute %i dir\n",VN.size()));
|
||||
InitGL();
|
||||
int t00=clock();
|
||||
VV.resize(m.vert.size());
|
||||
std::vector<int> PixSeen(VV.size(),0);
|
||||
int TotRay=0,HitRay=0;
|
||||
for(unsigned int i=0;i<VN.size();++i)
|
||||
{
|
||||
int t0=clock();
|
||||
fill(PixSeen.begin(),PixSeen.end(),0);
|
||||
int added=SplittedRendering(VN[i], PixSeen,cb);
|
||||
AddPixelCount(VV,PixSeen);
|
||||
int t1=clock();
|
||||
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));
|
||||
}
|
||||
|
||||
printf("Tot Time %i msec TotRays %i, HitRays %i, ray/sec %3.1fk \n ",clock()-t00,TotRay,HitRay,float(TotRay)/(clock()-t00));
|
||||
RestoreGL();
|
||||
}
|
||||
|
||||
void ComputeHalf(int nn, Point3x &dir, CallBack *cb)
|
||||
{
|
||||
std::string buf;
|
||||
|
||||
VN.clear();
|
||||
std::vector<Point3x> nvt;
|
||||
assert(0 && "This is only my guess (to compile). (Ponchio)");
|
||||
assert(0 && "Was: GenNormal(nn*2, nvt);");
|
||||
GenNormal<ScalarType>::Uniform(nn*2,nvt);
|
||||
for(int i=0;i<nvt.size();++i)
|
||||
if(dir*nvt[i]>0) VN.push_back(nvt[i]);
|
||||
|
||||
printf("Asked %i normal, got %i normals\n",nn,VN.size());
|
||||
Compute(cb);
|
||||
}
|
||||
|
||||
void ComputeUniformCone(int nn, std::vector<Point3x> &vv, ScalarType AngleRad, Point3x &ConeDir, CallBack *cb)
|
||||
{
|
||||
VN.clear();
|
||||
GenNormal<ScalarType>::UniformCone(nn,VN,AngleRad,ConeDir);
|
||||
typename std::vector<Point3x>::iterator vi;
|
||||
for(vi=VN.begin();vi!=VN.end();++vi)
|
||||
vv.push_back(*vi);
|
||||
|
||||
char buf[256];
|
||||
sprintf(buf,"Asked %i normal, got %i normals\n",nn,VN.size());
|
||||
cb(buf);
|
||||
Compute(cb);
|
||||
}
|
||||
void ComputeUniform(int nn, std::vector<Point3x> &vv, CallBack *cb)
|
||||
{
|
||||
VN.clear();
|
||||
GenNormal<ScalarType>::Uniform(nn,VN);
|
||||
typename std::vector<Point3x>::iterator vi;
|
||||
for(vi=VN.begin();vi!=VN.end();++vi)
|
||||
vv.push_back(*vi);
|
||||
|
||||
char buf[256];
|
||||
sprintf(buf,"Asked %i normal, got %i normals\n",nn,VN.size());
|
||||
cb(buf);
|
||||
Compute(cb);
|
||||
}
|
||||
|
||||
void ComputeSingle(Point3x &dir, std::vector<Point3x> &vv,CallBack *cb)
|
||||
{
|
||||
VN.clear();
|
||||
VN.push_back(dir);
|
||||
vv.push_back(dir);
|
||||
printf("Computing one direction (%f %f %f)\n",dir[0],dir[1],dir[2]);
|
||||
Compute(cb);
|
||||
}
|
||||
|
||||
/**********************************************************/
|
||||
|
||||
int SplittedRendering(Point3x &ViewDir, std::vector<int> &PixSeen, CallBack *cb=DummyCallBack)
|
||||
{
|
||||
int tt=0;
|
||||
int i,j;
|
||||
for(i=0;i<SplitNum;++i)
|
||||
for(j=0;j<SplitNum;++j){
|
||||
SetupOrthoViewMatrix(ViewDir, i,j,SplitNum);
|
||||
tt+=GLAccumPixel(PixSeen);
|
||||
}
|
||||
return tt;
|
||||
}
|
||||
|
||||
// Compute a rotation matrix that bring Axis parallel to Z.
|
||||
void GenMatrix(Matrix44d &a, Point3d Axis, double angle)
|
||||
{
|
||||
const double eps=1e-3;
|
||||
Point3d RotAx = 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
|
||||
RotAx=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);
|
||||
RotAx.Normalize();
|
||||
a.SetRotate(RotAngle,RotAx);
|
||||
//Matrix44d rr;
|
||||
//rr.SetRotate(-angle, Point3d(0,0,1));
|
||||
//a=rr*a;
|
||||
}
|
||||
|
||||
|
||||
// Genera la matrice di proj e model nel caso di un rendering ortogonale.
|
||||
// subx e suby indicano la sottoparte che si vuole
|
||||
void SetupOrthoViewMatrix(Point3x &ViewDir, int subx, int suby,int LocSplit)
|
||||
{
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glLoadIdentity ();
|
||||
float dlt=2.0f/LocSplit;
|
||||
|
||||
glOrtho(-1+subx*dlt, -1+(subx+1)*dlt, -1+suby*dlt, -1+(suby+1)*dlt,-2,2);
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
glLoadIdentity ();
|
||||
Matrix44d rot;
|
||||
Point3d qq; qq.Import(ViewDir);
|
||||
GenMatrix(rot,qq,0);
|
||||
glMultMatrix(rot);
|
||||
double d=2.0/m.bbox.Diag();
|
||||
glScalef(d,d,d);
|
||||
glTranslate(-m.bbox.Center());
|
||||
}
|
||||
|
||||
void ComputeSingleDirection(Point3x BaseDir, std::vector<int> &PixSeen, CallBack *cb=DummyCallBack)
|
||||
{
|
||||
int t0=clock();
|
||||
std::string buf;
|
||||
|
||||
int added=SplittedRendering(BaseDir, PixSeen,cb);
|
||||
int t1=clock();
|
||||
printf("ComputeSingleDir %i msec\n",t1-t0);
|
||||
}
|
||||
|
||||
void ComputeAverageVisibilityDirection()
|
||||
{
|
||||
int i,j;
|
||||
VD.resize(VM.size());
|
||||
for(j=0;j<VM.size();++j)
|
||||
{
|
||||
Point3x &nn=VD[j];
|
||||
nn=Point3x(0,0,0);
|
||||
bitset<VisMax> &msk=VM[j];
|
||||
for(i=0;i<VN.size();++i)
|
||||
if(msk[i]) nn+=VN[i];
|
||||
}
|
||||
for(j=0;j<VM.size();++j)
|
||||
VD[j].Normalize();
|
||||
|
||||
}
|
||||
|
||||
// calcola un LightingEnvironment direzionale, cioe'un vettore di pesi per l'insieme di normali
|
||||
// corrente tale che
|
||||
// mette a 1 tutti i vettori che sono entro un angolo DegAngle1
|
||||
// a 0 tutti quelli oltre DegAngle2 e
|
||||
// sfuma linearmente nel mezzo.
|
||||
void DirectionalLightingEnvironment(std::vector<float> &LE, Point3x dir, ScalarType DegAngle1, ScalarType DegAngle2)
|
||||
{
|
||||
LE.clear();
|
||||
LE.resize(VN.size(),0);
|
||||
int i;
|
||||
for(i=0;i<VN.size();++i)
|
||||
{
|
||||
ScalarType a=ToDeg(Angle(dir,VN[i]));
|
||||
if(a<DegAngle1) { LE[i]=1; continue; }
|
||||
if(a>DegAngle2) { LE[i]=0; continue; }
|
||||
LE[i] = 1.0-(a-DegAngle1)/(DegAngle2-DegAngle1);
|
||||
|
||||
}
|
||||
// last step normalize the weights;
|
||||
ScalarType sum=0;
|
||||
for(i=0;i<VN.size();++i)
|
||||
sum+=LE[i];
|
||||
for(i=0;i<VN.size();++i)
|
||||
LE[i]/=sum;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
|
||||
template <class MESH_TYPE> class VertexVisShader : public VisShader<MESH_TYPE>
|
||||
{
|
||||
public :
|
||||
|
||||
// Function Members
|
||||
VertexVisShader(MESH_TYPE &me):VisShader<MESH_TYPE>(me)
|
||||
{
|
||||
// la mesh DEVE avere colore per vertice
|
||||
if(! HasPerVertexColor(m)) assert(0);
|
||||
}
|
||||
|
||||
void Init() { VV.resize(m.vert.size()); }
|
||||
void Compute(int nn);
|
||||
|
||||
void DrawFill (MESH_TYPE &mm)
|
||||
{
|
||||
static GLuint dl=0;
|
||||
if(mm.face.empty())
|
||||
{ AMesh::VertexIterator vi;
|
||||
glBegin(GL_POINTS);
|
||||
for(vi=mm.vert.begin();vi!=mm.vert.end();++vi)
|
||||
{
|
||||
if(ColorFlag) glColor((*vi).C());
|
||||
glVertex((*vi).P());
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
else
|
||||
{
|
||||
glBegin(GL_TRIANGLES);
|
||||
FaceIterator fi;
|
||||
for(fi=mm.face.begin();fi!=mm.face.end();++fi)
|
||||
{
|
||||
glVertex((*fi).V(0)->P());
|
||||
glVertex((*fi).V(1)->P());
|
||||
glVertex((*fi).V(2)->P());
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
//VertexVisibility
|
||||
// Funzione Principale restituisce per ogni entita' quanti px si vedono o no.
|
||||
|
||||
int GLAccumPixel( std::vector<int> &PixSeen)
|
||||
{
|
||||
SimplePic<float> snapZ;
|
||||
SimplePic<Color4b> snapC;
|
||||
|
||||
glClearColor(Color4b::Black);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT | GL_POLYGON_BIT );
|
||||
glDisable(GL_LIGHTING);
|
||||
glDepthRange(0.0f,1.0f);
|
||||
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
|
||||
glDepthMask(GL_TRUE);
|
||||
glDrawBuffer(GL_BACK);
|
||||
glReadBuffer(GL_BACK);
|
||||
|
||||
/////** Si disegnano le front face **/////
|
||||
glDepthRange(2.0*ZTWIST,1.0f);
|
||||
if(IsClosedFlag) glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
glColor(Color4b::Red);
|
||||
DrawFill(m);
|
||||
|
||||
if(!IsClosedFlag) {
|
||||
glCullFace(GL_FRONT);
|
||||
glColor(Color4b::Black);
|
||||
DrawFill(m);
|
||||
snapC.OpenGLSnap();
|
||||
}
|
||||
|
||||
int cnt=0;
|
||||
snapZ.OpenGLSnap(GL_DEPTH_COMPONENT);
|
||||
|
||||
glDepthRange(0,1.0f-2.0*ZTWIST);
|
||||
double MM[16];
|
||||
glGetDoublev(GL_MODELVIEW_MATRIX,MM);
|
||||
double MP[16];
|
||||
glGetDoublev(GL_PROJECTION_MATRIX,MP);
|
||||
int VP[4];
|
||||
glGetIntegerv(GL_VIEWPORT,VP);
|
||||
double tx,ty,tz;
|
||||
|
||||
for(unsigned int i=0;i<m.vert.size();++i)
|
||||
{
|
||||
gluProject(m.vert[i].P()[0],m.vert[i].P()[1],m.vert[i].P()[2],
|
||||
MM,MP,VP,
|
||||
&tx,&ty,&tz);
|
||||
int col=1;
|
||||
|
||||
if(tx>=0 && tx<snapZ.sx && ty>=0 && ty<snapZ.sy)
|
||||
{
|
||||
int txi=floor(tx),tyi=floor(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]));
|
||||
|
||||
// col=snapC.Pix(txi+0,tyi+0)[0];
|
||||
}
|
||||
if(col!=0 && tz<sd) {
|
||||
PixSeen[i]++;
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
glPopAttrib();
|
||||
//printf("Seen %i vertexes on %i\n",cnt,m.vert.size());
|
||||
return cnt;
|
||||
}
|
||||
|
||||
void SmoothVisibility(bool Enhance=false)
|
||||
{
|
||||
FaceIterator fi;
|
||||
std::vector<float> VV2;
|
||||
std::vector<int> VC(VV.size(),1);
|
||||
VV2=VV;
|
||||
for(fi=m.face.begin();fi!=m.face.end();++fi)
|
||||
for(int i=0;i<3;++i)
|
||||
{
|
||||
VV2[(*fi).V(i)-&*m.vert.begin()] += VV[(*fi).V1(i)-&*m.vert.begin()];
|
||||
++VC[(*fi).V(i)-&*m.vert.begin()];
|
||||
}
|
||||
|
||||
if(!Enhance)
|
||||
for(unsigned int i=0;i<VV2.size();++i)
|
||||
VV[i]=VV2[i]/VC[i];
|
||||
else
|
||||
for(unsigned int i=0;i<VV2.size();++i)
|
||||
VV[i]=VV[i]+ (VV[i]-VV2[i]/VC[i])*.5;
|
||||
}
|
||||
|
||||
|
||||
void MapFalseColor()
|
||||
{
|
||||
float minv=*min_element(VV.begin(),VV.end());
|
||||
float maxv=*max_element(VV.begin(),VV.end());
|
||||
printf("Visibility Range %f %f\n", minv,maxv);
|
||||
MapFalseColor(minv, maxv);
|
||||
}
|
||||
|
||||
void MapFalseColor(float minv, float maxv)
|
||||
{
|
||||
VertexIterator vi;
|
||||
for(vi=m.vert.begin();vi!=m.vert.end();++vi){
|
||||
float gval=(VV[vi-m.vert.begin()]-minv)/(maxv-minv);
|
||||
math::Clamp(gval,0.0f,1.0f);
|
||||
(*vi).C().ColorRamp(1.0,0.0,gval);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
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, float Scale= 1.0)
|
||||
{
|
||||
float minv=*min_element(VV.begin(),VV.end());
|
||||
float maxv=*max_element(VV.begin(),VV.end());
|
||||
printf("Visibility Range %f %f\n", minv,maxv);
|
||||
|
||||
VertexIterator vi;
|
||||
for(vi=m.vert.begin();vi!=m.vert.end();++vi){
|
||||
float gval=(VV[vi-m.vert.begin()]-minv)/(maxv-minv);
|
||||
if(gval<LowPass) gval=LowPass;
|
||||
if(gval>HighPass) gval=HighPass;
|
||||
(*vi).C().SetGrayShade(Scale*pow((gval-LowPass)/(HighPass-LowPass),Gamma));
|
||||
}
|
||||
}
|
||||
|
||||
//void ApplyLightingEnvironment(std::vector<float> &W, float Gamma=1)
|
||||
// {
|
||||
// assert(W.size()==VN.size());
|
||||
// MESH_TYPE::VertexIterator vi;
|
||||
//
|
||||
// for(vi=m.vert.begin();vi!=m.vert.end();++vi)
|
||||
// {
|
||||
// float gray=0;
|
||||
// bitset<VisMax> &msk=VM[vi-m.vert.begin()];
|
||||
// for(int i=0;i<VN.size();++i)
|
||||
// if(msk[i]) gray+=W[i];
|
||||
//
|
||||
// (*vi).C().SetGrayShade(gray);
|
||||
// }
|
||||
// }
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
#endif // __VCG_MESH_VISIBILITY
|
||||
Reference in new issue
Block a user