Commit 589b59d1 authored by Graham Inggs's avatar Graham Inggs

Updated version 0.4.1~cvs20081111 from 'upstream/0.4.1_cvs20081111'

with Debian dir 16a41a217811252120499a3c3d27585d4f93771c
parents a51664b9 c4063ba1
INCDIRS = -Ivcg -Isrc -I.
OPTFLAGS = -Os -Wall -g
CXXFLAGS = $(INCDIRS) $(OPTFLAGS) `wx-config --cppflags`
LIBS = $(CXXFLAGS) `wx-config --libs core,base --gl-libs` -lGLEW -lGLU -lGL
OBJS = \
src/AO.o \
src/AOgpu.o \
src/AtomColor.o \
src/CgUtil.o \
src/Common.o \
src/HardSettings.o \
src/Mol.o \
src/MyTab.o \
src/Sampling.o \
src/ShadowMap.o \
src/main.o \
src/wx_trackball.o \
vcg/wrap/gui/trackball.o \
vcg/wrap/gui/trackmode.o
all: qutemol
clean:
find . -name "*.o" | xargs rm
qutemol: $(OBJS)
$(CXX) -o qutemol $(CFLAGS) $(OBJS) $(LIBS)
QuteMol depends on the following libraries
vcglib
available on cvs access from http://vcg.sourceforge.net
wxWidgets
http://www.wxwidgets.org/
The standard building environment of QuteMol is DevCpp.
and it assume that the cvs root of QuteMol is at the same level of the cvs root of vcglib
\ No newline at end of file
typedef unsigned char Byte;
#include <math.h>
#include <vector>
#include <vcg/space/point3.h>
using namespace vcg;
using namespace std;
#include "CubeMapSamp.h"
#include "OctaMapSamp.h"
#include "Mol.h"
#include "AO.h"
const float infty=1000;
vector<bool> tmpbool(32*32,false);
void AO::PrintBuffer(){
int target=32;
int k=0;
for (int y=0; y<target; y++){
for (int x=0; x<target; x++) {
double b=buf[k];
if (b==infty)
printf("%2s","*");
else
printf("%2s","-");
if (tmpbool[k]) printf("'"); else printf(" ");
k++;
// printf("%7.3f ",buf[k++]);
}
printf("\n");
}
}
void AO::RenderSphere(float cx, float cy, float cz, float rad){
printf("Rendering %f %f %f %f...\n",cx,cy,cz,rad);
/*cx*=bufscale;
cy*=bufscale;
rad*=bufscale;*/
int cxi=int(cx);
int cyi=int(cy);
for (int y=-(int)rad; y<=(int)rad; y++)
for (int x=-(int)rad; x<=(int)rad; x++)
{
float tmp=(-x*x-y*y+rad*rad);
if (tmp>0) {
tmp=sqrt(tmp)+cz;
int i=index(x+cxi,y+cyi);
if (buf[i]>tmp) buf[i]=tmp;
//buf[i]=0;
}
}
}
void AO::CheckAtom(QAtom &a){
int n=a.s.nsamp();
for (int i=0; i<n; i++) {
Point3f f=a.s.dirrot[i]*a.trr;
if (f[2]>0) {
int bx=(int) (a.trp[0]+f[0]);
int by=(int) (a.trp[1]+f[1]);
tmpbool[index(bx,by)]=true;;
if (buf[index(bx,by)] == infty ) {
a.s.sum[i]+=f[2];
};
a.s.div[i]+=f[2];
}
}
}
AO::AO( Point3f _dir, Mol &m) {
dir=_dir.Normalize();
// orthonormal basis
Point3f ax,ay,az=dir;
ax=az^Point3f(1,0,0);
if (ax.SquaredNorm()<0.1) ax=az^Point3f(0,1,0);
ax=ax.Normalize();
ay=(az^ax).Normalize();
// project...
m.Transform(ax,ay,az);
int target=32; //
bufx=bufy=target;
float bufscalex=target/(m.tx1-m.tx0);
float bufscaley=target/(m.ty1-m.ty0);
bufscale=(bufscalex<bufscaley)?bufscalex:bufscaley;
m.ScaleTransl(bufscale);
CubeMapSamp::Transform(ax,ay,az);
printf("Scale=%f\n",bufscale);
buf.resize(target*target,infty);
for (int i=0; i<m.atom.size()-1; i++) {
QAtom &a=m.atom[i];
CheckAtom(a);
RenderSphere( a.trp[0], a.trp[1], a.trp[2], a.trr );
PrintBuffer();
}
}
// class to compute ambient occlusion
class AO{
//private:
Point3f dir; // direction
vector<float> buf;
int bufx, bufy;
float bufscale;
inline int index(int x, int y){
int res=x+bufx*y;
if (res<0) res=0;
if (res>=buf.size()) res=buf.size()-1;
return res;
//return x+bufx*y;
}
void PrintBuffer();
void RenderSphere(float cx, float cy, float cz, float rad);
void CheckAtom(QAtom &a);
public:
AO( Point3f _dir, Mol &m);
};
typedef unsigned char Byte;
#include <GL/glew.h>
#include "CgUtil.h"
//#include <GL/gl.h>
#include <math.h>
//#include <GL/glu.h>
#include <vector>
#include <vcg/space/point3.h>
#include <vcg/space/color4.h>
using namespace vcg;
using namespace std;
#include "CubeMapSamp.h"
#include "OctaMapSamp.h"
#include "Mol.h"
#include "AOgpu.h"
#include "HardSettings.h"
extern int CSIZE;
extern int used_mapping;
bool SaveImagePPM( const char * filename , const Byte *im, int sizex, int sizey);
void ReloadTexture(vector<Byte> t, bool bilinear);
float extractCurrentScaleFactor();
CgUtil mySettings;
vector<Byte> AOgpu::fakeTexture;
vector<unsigned int> AOgpu::snap;
vector<int> AOgpu::sum;
unsigned int AOgpu::div;
float AOgpu::areas;
unsigned int AOgpu::mask=0;
void swapbuffers();
void AOgpu::OpenGLSnap()
{
GLint vp[4];
glGetIntegerv( GL_VIEWPORT,vp ); // Lettura viewport
glPixelStorei( GL_PACK_ROW_LENGTH, 0);
glPixelStorei( GL_PACK_ALIGNMENT, 1);
snapx = vp[2];
snapy = vp[3];
//Create(tx,ty);
if (snap.size()!=snapx*snapy+1) snap.resize(snapx*snapy+1);
GLenum mtype = 0;
int format=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 *)&snap[0]);
//SaveImagePPM("test.ppm" ,(Byte*)(&snap[0]), vp[2],vp[3]);
//swapbuffers();
}
AOgpu::AOgpu( Point3f _dir, Mol &m) {
int out=hardSettings.TSIZE*hardSettings.TSIZE;
glClearColor((out&&255)/255.0 , ((out>>8)&&255)/255.0, (out>>16)/255.0, 0 );
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
dir=_dir.Normalize();
// orthonormal basis
Point3f ax,ay,az=dir;
ax=az^Point3f(1,0,0);
if (ax.SquaredNorm()<0.1) ax=az^Point3f(0,1,0);
ax=ax.Normalize();
ay=(az^ax).Normalize();
//CubeMapSamp::Transform(ax,ay,az);
// make a snapshot!
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
GLfloat nearPlane = 0.1;
GLfloat farPlane = 200;
glOrtho(-1,+1,-1,+1, nearPlane, farPlane);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
gluLookAt( az[0],az[1],az[2], 0,0,0, ay[0], ay[1], ay[2] );
if (areas<0) {
// only once: compute areas
GLint vp[4];
glGetIntegerv( GL_VIEWPORT,vp );
float sc=extractCurrentScaleFactor()*(1/m.r);
areas=vp[2]*vp[3]*sc*sc;
}
mySettings.BindShaders();
m.Draw();
OpenGLSnap();
// interpret spanshot
int k=0,h=0;
//int* snapi=(int*)(&snap[0]);
int max=snapy*snapx;
int maxt=sum.size();
/*static*/
// vector<int> found(sum.size(), false );
for (int i=0; i<max; i++){
//if (snap[i]==0) printf(" ");
//sum[snap[i]&0x00ffffff]++;
//if (sum[snap[i]&0x00ffffff] ) |=mask;
/*
int dec=snap[i]&0x00ffffff;
if (!found[dec]) {
found[dec]=true;
sum[ dec ] += snap[i]>>24;
printf("[%d]",snap[i]>>24);
}*/
if (sum[ snap[i]&0x00ffffff ]>>24 !=div) {
sum[ snap[i]&0x00ffffff ] =
(sum[ snap[i]&0x00ffffff ]+(snap[i]>>24))&0x00ffffff | (div<<24);
//printf("[%d]",snap[i]>>24);
}
/*
sum[ snap[i]&0x00ffffff ] =
(
(
(sum[ snap[i]&0x00ffffff ] +
((sum[ snap[i]&0x00ffffff ]>>24)!=div)*(snap[i]>>24)
)&0x00ffffff
)
| (div<<24)
); */
}
/*
static Point3f sumv=Point3f(0,0,0);
sumv+=az;
printf("%d (%f %f %f) (%f %f %f)\n", div, az[0],az[1],az[2], sumv[0],sumv[1],sumv[2]);
*/
mask<<=1;
div++;
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
}
void AOgpu::Reset(Mol &m){
mySettings.SetForOffLine();
if (fakeTexture.size()==0) {
// Prepare And Load fake texture
fakeTexture.resize(hardSettings.TSIZE*hardSettings.TSIZE*3);
int k=0, i=0;
for (int x=0; x<hardSettings.TSIZE; x++)
for (int y=0; y<hardSettings.TSIZE; y++) {
fakeTexture[i++]=k&255;
fakeTexture[i++]=(k>>8)&255;
fakeTexture[i++]=(k>>16)&255;
k++;
}
m.DuplicateTexels(fakeTexture, hardSettings.TSIZE);
}
glActiveTextureARB(GL_TEXTURE0_ARB);
//glBindTexture(GL_TEXTURE_2D, molTexture);
//ReloadTexture(fakeTexture, false);
div=0;
if (sum.size()!=hardSettings.TSIZE*hardSettings.TSIZE) {
sum.resize(hardSettings.TSIZE*hardSettings.TSIZE,0);
} else {
sum.clear();
sum.resize(hardSettings.TSIZE*hardSettings.TSIZE,0);
}
mask=1;
areas=-1;
mySettings.BindShaders();
}
inline unsigned int BitCount(unsigned int x){
x=(((x>>1)&x)&(0x88888888)) + ((x<<1)^x)&(0xAAAAAAAA) ;
x = ((x>>2)&(0x33333333)) + ( x &(0x33333333));
x = ((x>>4)&(0x0F0F0F0F)) + ( x &(0x0F0F0F0F));
x = ((x>>8)&(0x00FF00FF)) + ( x &(0x00FF00FF));
return (x&0x0000FFFF)+(x>>16);
}
void AOgpu::GetFinalTexture(vector<Byte> &text,Mol &m){
int k=0,i=0;
//m.SmoothTexture( sum, hardSettings.TSIZE );
int maxt=sum.size();
/*for (int i=0; i<maxt; i++){
sum[i]=BitCount(sum[i]);
}*/
for (int i=0; i<maxt; i++){
sum[i]&=0x00ffffff;
}
m.FillTexture( text, sum, hardSettings.TSIZE, 4.0/float(div) /*8*2*255 / (div * areas )*/ );
m.DuplicateTexels(text, hardSettings.TSIZE);
}
class AOgpu{
//private:
Point3f dir; // direction
void CheckAtom(QAtom &a);
static vector<Byte> fakeTexture;
static vector<unsigned int> snap;
static vector<int> sum;
static unsigned int div;
static float areas; // expected area coverage of a 1 radius sphere
int snapx, snapy;
void OpenGLSnap();
bool SavePPM( const char * filename );
static unsigned int mask;
public:
static void Reset(Mol &m);
AOgpu( Point3f _dir, Mol &m);
static void GetFinalTexture(vector<Byte> &text, Mol &m);
};
This diff is collapsed.
int getAtomColor(const char* atomicElement);
float getAtomRadius(const char* atomicElement);
float getAtomCovalentRadius(const char* atomicElement);
int getChainColor(int chianIndex);
#define MAX_COVALENT_RADIUS 1.688f
bool readArtFile(const char* filename);
This diff is collapsed.
class GeoSettings {
public:
typedef enum{ SPACE_FILL, BALL_N_STICKS, LICORICE } GeoMode;
GeoMode mode;
float stickRadius;
float licoRadius;
bool stick_smooth_color;
bool use_stick_const_color;
float stick_const_color_R,stick_const_color_G,stick_const_color_B;
bool showHetatm;
void SetDefaults(){
mode=SPACE_FILL;
//stickRadius=0.2;
SetLicoRadiusPercentage(50);
SetStickRadiusPercentage(100);
//licoRadius=0.6;
stick_smooth_color = false;
use_stick_const_color = false;
stick_const_color_R=0.75;
stick_const_color_G=0.50;
stick_const_color_B=0.50;
showHetatm = false;
}
void Rotate(){
mode=(GeoMode)((((int)mode)+1)%3);
}
GeoSettings() {
SetDefaults();
}
void Apply();
void ApplyColor();
void SetLicoRadiusPercentage(int percentage){
licoRadius = 0.3 + percentage/100.0*0.65;
}
int GetLicoRadiusPercentage(){
return int(100.0*((licoRadius - 0.3)/0.65));
}
void SetStickRadiusPercentage(int percentage){
const float tmp=0.32 * 0.85-0.16;
stickRadius = 0.16 + percentage/100.0*tmp;
}
int GetStickRadiusPercentage(){
const float tmp=0.32 * 0.85-0.16;
return int(100.0*((stickRadius - 0.16)/tmp));
}
};
// drawing settings
class CgUtil {
public:
// RENDERING PARAMETERS:
// Settarli a piacere e poi chiamare setShaders...
/////////////////////////////////////////////
/* SERIALIZE_BEGIN */
float P_light_base; // from 0 (dark) to 1 (bright)
float P_lighting; // from 0 (no lighting) to 1 (full lighting)
float P_phong; // from 0 (no phong lighting) to 1 (full lighting)
float P_phong_size; // from 0 (POW=100) to 1 (POW=1)