Debian Codegraph @

src/HardSettings.cpp

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 #include <stdio.h>
2
3 #if defined(_WIN32)
4 #include <strings.h>
5 #else
6 #include <string.h> // for strcmp
7 #endif
8 #include "HardSettings.h"
9
10 void HardSettings::SetDefaults(){
11 TSIZE=1024; // total texture size
12 MAX_TSIZE=2048; /// MAX texture size
13
14
15 N_VIEW_DIR=128;
16
17 SHADOWMAP_SIZE=1024; // texture size for shadowmap
18 AOSM_SIZE=256; // texture size for shadowmmaps for AO comp[utation
19
20 // if true, use double ShadomMap optimization
21 doubleSM=1;
22
23 NVIDIA_PATCH = 0;
24
25 MOVING_QUALITY=100;
26 STILL_QUALITY=200;
27
28 SNAP_SIZE=1024; // snapshots size
29 SNAP_ANTIALIAS=1;
30 PNG_TRANSPARENT=0;
31
32
33 // GIF animation settings
34 GIF_SNAP_SIZE=256;
35 GIF_INITIAL_PAUSE=0;
36 GIF_ANIMATION_MODE=0;
37
38 GIF_ROT_N_FRAMES=60;
39 GIF_ROT_MSEC=3000;
40 GIF_ROT_SIDEVIEW_ANGLE=10;
41
42 GIF_INSP_N_FRAMES=60;
43 GIF_INSP_MSEC=3000;
44 GIF_INSP_ANGLE=10;
45
46 GIF_6SIDES_N_FRAMES=10;
47 GIF_6SIDES_MSEC=400;
48 GIF_6SIDES_PAUSE=1000;
49
50 };
51
52
•53 static const char* names[NNAMES]={
54 "TSIZE",
55 "MAX_TSIZE",
56 "N_VIEW_DIR",
57 "SHADOWMAP_SIZE",
58 "AOSM_SIZE",
59 "MOVING_QUALITY",
60 "STILL_QUALITY",
61 "doubleSM",
62 "NVIDIA_PATCH",
63
64 "SNAP_SIZE",
65 "SNAP_ANTIALIAS",
66
67 "PNG_TRANSPARENT",
68
69 "GIF_SNAP_SIZE",
70 "GIF_INITIAL_PAUSE",
71 "GIF_ANIMATION_MODE",
72
73 "GIF_ROT_N_FRAMES",
74 "GIF_GIF_ROT_MSEC",
75 "GIF_GIF_ROT_SIDEVIEW_ANGLE",
76
77 "GIF_INSP_N_FRAMES",
78 "GIF_INSP_MSEC",
79 "GIF_INSP_ANGLE",
80
81 "GIF_6SIDES_N_FRAMES",
82 "GIF_6SIDES_MSEC",
83 "GIF_6SIDES_PAUSE",
84 };
85
86
87 HardSettings::HardSettings(){
88 int i=0;
89 data[i++]=&TSIZE;
90 data[i++]=&MAX_TSIZE;
91 data[i++]=&N_VIEW_DIR;
92 data[i++]=&SHADOWMAP_SIZE;
93 data[i++]=&AOSM_SIZE;
94 data[i++]=&MOVING_QUALITY;
95 data[i++]=&STILL_QUALITY;
96 data[i++]=&doubleSM;
97 data[i++]=&NVIDIA_PATCH;
98
99 data[i++]=&SNAP_SIZE;
100 data[i++]=&SNAP_ANTIALIAS;
101
102 data[i++]=&PNG_TRANSPARENT;
103
104 data[i++]=&GIF_SNAP_SIZE;
105 data[i++]=&GIF_INITIAL_PAUSE;
106 data[i++]=&GIF_ANIMATION_MODE;
107
108 data[i++]=&GIF_ROT_N_FRAMES;
109 data[i++]=&GIF_ROT_MSEC;
110 data[i++]=&GIF_ROT_SIDEVIEW_ANGLE;
111
112 data[i++]=&GIF_INSP_N_FRAMES;
113 data[i++]=&GIF_INSP_MSEC;
114 data[i++]=&GIF_INSP_ANGLE;
115
116 data[i++]=&GIF_6SIDES_N_FRAMES;
117 data[i++]=&GIF_6SIDES_MSEC;
118 data[i++]=&GIF_6SIDES_PAUSE;
119
120
121 }
122
123
•124 static const char* comments[NNAMES]={
125 "favoured texture size for molecule",
126 "maximal texture size (used when molecule too large for TSIZE)",
127 "number of view directions ussed in AO computation",
128 "texture size for shadowmap",
129 "texture size for shadowmmaps for AO computation",
130 "Quality of image on screen when molecole moves (between 50..200)",
131 "Quality of image on screen when molecole is still (between 50..200)",
132 "if 1, use double ShadomMap optimization (two way lights)",
133 "use 1 - *AND* disable doubleSM - to patch a bug reported on some Nvidia cards (warning: lowers visual quality!)",
134
135 "snapshots resolution (per side)",
136 "if 1, antialias exported snapshots",
•137 "if 1, save PNG images with transparent background",
138
139
140 "resolution of exported GIF animations",
141 "initial pause in msec before each animation loop",
142 "if 0: full rotation. If 1: inspection mode (rotation around current viewpoint). If 2: six-views show.",
143
144 "number of frames of exported GIF animations (for full rotation)",
145 "total duration in msec of GIF animations loop (for full rotation)",
146 "angle (in -45 +45). If 0, perfect side rotation; if >0, look from above; if <0, look from below (for full rotation)",
147
148 "number of frames of exported GIF animations (for inspections)",
149 "total duration in msec of GIF animations loop (for inspections)",
150 "in (10..45). Animation is an inspection around current view point (for inspections)",
151
152 "number of frames of exported GIF animations (for six-views show)",
153 "duration in msec of each face shift (for six-views show)",
154 "pause in msec after each face shift (for six-views show)",
155 };
156
157
158
159
•160 bool HardSettings::Load(const char *fn){
161 char buf[512];
162 strcpy(buf, PKGDATADIR);
163 if (buf[strlen(buf)-1] != '/') {
164 strcat(buf,"/");
165 }
166 FILE *f=fopen(strcat(buf,fn),"rt");
167
168 bool present[NNAMES];
169 for (int i=0; i<NNAMES; i++) present[i]=false;
170 bool duplicated=false;
171 bool errors=false;
172
173 if (!f) return false;
174 char token[255];
175 char last[255];
•176 last[0]=0;
177 while (1){
178 if (fscanf(f,"%s",token)!=1) break;
179 if (token[0]=='=') {
180 int val;
181 if (fscanf(f,"%d",&val)==1) {
182 bool ok=false;
183 for (int i=0; i<NNAMES; i++) {
184 if (strcmp(names[i],last)==0) {
185 ok=true;
186 *(data[i])=val;
187 if (present[i]) duplicated=true;
188 present[i]=true;
189 }
190 }
191 if (!ok) errors=true;
192 } else errors=true;
193 }
194 sprintf(last,"%s",token);
195 }
196 fclose(f);
197 for (int i=0; i<NNAMES; i++) if (!present[i]) return false;
198
199 if (duplicated) return false;
200 if (errors) return false;
201 return true;
202 }
203
•204 bool HardSettings::Save(const char *fn){
205 FILE *f=fopen(fn,"wt");
206
207 static HardSettings defaults;
208 defaults.SetDefaults();
209
210 if (!f) return false;
211
212 for (int i=0; i<NNAMES; i++) {
213 if (i==13) // quick hack
214 fprintf(f," \\\\ PARAMETERS FOR GIF ANIMATION \n \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n\n");
215
216 fprintf(f,"%s = %d\n \\\\ %s\n \\\\ (default: %d ) \n\n",
217 names[i], *(data[i]), comments[i] , *(defaults.data[i]) );
218 }
219 fclose(f);
220 return true;
221 }
222
•223 void HardSettings::OnStart(){
224 SetDefaults();
225 if (!Load("qutemol.cfg")) {
226 Save("qutemol.cfg");
227 }
228 }
229
230
231
232
233
234 HardSettings hardSettings; // SINGLETON