Debian Codegraph @

src/AO.cpp

raw symbols ◀ ▶ SCIP
2 Debian patches touch this file
1
2 typedef unsigned char Byte;
3
4 #include <math.h>
•5 #include <stdio.h>
6
7 #include <vector>
8 #include <vcg/space/point3.h>
9
10 using namespace vcg;
11 using namespace std;
12
13 #include "CubeMapSamp.h"
14 #include "OctaMapSamp.h"
15
16 #include "Mol.h"
17 #include "AO.h"
18
19 const float infty=1000;
20
21 vector<bool> tmpbool(32*32,false);
22
23 void AO::PrintBuffer(){
24 int target=32;
25 int k=0;
26 for (int y=0; y<target; y++){
27 for (int x=0; x<target; x++) {
28 double b=buf[k];
29 if (b==infty)
30 printf("%2s","*");
31 else
32 printf("%2s","-");
33 if (tmpbool[k]) printf("'"); else printf(" ");
34
35 k++;
36 // printf("%7.3f ",buf[k++]);
37 }
38 printf("\n");
39 }
40 }
41
42 void AO::RenderSphere(float cx, float cy, float cz, float rad){
43 printf("Rendering %f %f %f %f...\n",cx,cy,cz,rad);
44 /*cx*=bufscale;
45 cy*=bufscale;
46 rad*=bufscale;*/
47 int cxi=int(cx);
48 int cyi=int(cy);
49
50 for (int y=-(int)rad; y<=(int)rad; y++)
51 for (int x=-(int)rad; x<=(int)rad; x++)
52 {
53 float tmp=(-x*x-y*y+rad*rad);
54 if (tmp>0) {
55 tmp=sqrt(tmp)+cz;
56 int i=index(x+cxi,y+cyi);
57 if (buf[i]>tmp) buf[i]=tmp;
58 //buf[i]=0;
59 }
60 }
61 }
62
63
64 void AO::CheckAtom(QAtom &a){
65
66 int n=a.s.nsamp();
67 for (int i=0; i<n; i++) {
68 Point3f f=a.s.dirrot[i]*a.trr;
69
70 if (f[2]>0) {
71
72
73 int bx=(int) (a.trp[0]+f[0]);
74 int by=(int) (a.trp[1]+f[1]);
75 tmpbool[index(bx,by)]=true;;
76 if (buf[index(bx,by)] == infty ) {
77 a.s.sum[i]+=f[2];
78 };
79 a.s.div[i]+=f[2];
80 }
81 }
82 }
83
84
85 AO::AO( Point3f _dir, Mol &m) {
86
87 dir=_dir.Normalize();
88
89 // orthonormal basis
90 Point3f ax,ay,az=dir;
91 ax=az^Point3f(1,0,0);
92 if (ax.SquaredNorm()<0.1) ax=az^Point3f(0,1,0);
93 ax=ax.Normalize();
94 ay=(az^ax).Normalize();
95
96 // project...
97 m.Transform(ax,ay,az);
98
99
100 int target=32; //
101 bufx=bufy=target;
102 float bufscalex=target/(m.tx1-m.tx0);
103 float bufscaley=target/(m.ty1-m.ty0);
104 bufscale=(bufscalex<bufscaley)?bufscalex:bufscaley;
105
106 m.ScaleTransl(bufscale);
107 CubeMapSamp::Transform(ax,ay,az);
108
109 printf("Scale=%f\n",bufscale);
110
111 buf.resize(target*target,infty);
112
•113 for (int i=0; i < (int)m.atom.size()-1; i++) {
114 QAtom &a=m.atom[i];
115 CheckAtom(a);
116 RenderSphere( a.trp[0], a.trp[1], a.trp[2], a.trr );
117 PrintBuffer();
118 }
119
120
121 }