41 float minRange = 0.000001;
43 double resolution = 0.2;
53 vector<vector<int> > preRenderList;
57 vector<vector<int> >** sceneLines;
58 vector<vector2i>** sceneLocations;
61 vector<int> getUniqueValues(vector<int> &v)
65 for(
int i=0; i<(int)v.size(); i++){
69 for(
int j=0; !found && j<(int)ret.size(); j++){
70 found = (v[i]==ret[j]);
78 void* PreRenderThread(
void* arg)
80 static const bool BlankTest =
false;
84 if(debugLevel>2) printf(
"Thread %d sub-task: %d - %d\n",subTask.taskIndex, subTask.taskStart,subTask.taskEnd);
86 int w = ceil((vectorMap->maxX-vectorMap->
minX)/resolution);
88 vector<vector<int> > * mySceneLines =
new vector<vector<int> >();
89 mySceneLines->clear();
90 sceneLines[subTask.taskIndex] = mySceneLines;
91 vector<vector2i> * mylocations =
new vector<vector2i>();
93 sceneLocations[subTask.taskIndex] = mylocations;
95 threadProgress[subTask.taskIndex] = subTask.taskStart;
96 for(
int i=subTask.taskStart; i<=subTask.taskEnd; i++){
97 double y = double(i)*resolution + vectorMap->minY;
98 for(
int j=0; j<w; j++){
99 double x = double(j)*resolution + vectorMap->
minX;
101 mylocations->push_back(
vector2i(j,i));
106 mySceneLines->push_back(list);
109 mySceneLines->push_back(vectorMap->
getSceneLines(loc,maxRange));
112 threadProgress[subTask.taskIndex] = i+1;
118 void PreRenderMultiThread()
120 threads = (pthread_t*) malloc(numThreads*
sizeof(pthread_t));
122 int w = ceil((vectorMap->maxX-vectorMap->
minX)/resolution);
123 int h = ceil((vectorMap->maxY-vectorMap->minY)/resolution);
126 preRenderList.clear();
128 printf(
"\nPre-Render Using %d threads.\n",numThreads);
129 printf(
"Size: %d x %d\nResolution:%.3f\n",w, h, resolution);
130 task_t subTasks[numThreads];
132 int taskIncrement = h/numThreads;
133 for(
int i=0; i<numThreads; i++){
134 subTasks[i].taskIndex = i;
135 subTasks[i].taskStart = start;
136 start += taskIncrement;
137 subTasks[i].taskEnd = start-1;
139 subTasks[numThreads-1].taskEnd = h-1;
142 sceneLines = (vector<vector<int> > **) malloc(numThreads*
sizeof(vector<vector<int> > *));
143 sceneLocations = (vector<vector2i> **) malloc(numThreads*
sizeof(vector<vector2i> *));
144 threadProgress = (
int*) malloc(numThreads*
sizeof(
int));
147 double tStart = GetTimeSec();
148 for(
int i=0; i<numThreads; i++){
149 pthread_create( &threads[i], NULL, PreRenderThread, (
void*) &subTasks[i]);
157 double totalProgress = 0.0;
158 printf(
"\rThread Progress: ");
159 for(
int i=0;i<numThreads; i++){
160 printf(
"%6.2f%% ",
double(threadProgress[i]-subTasks[i].taskStart)/
double(subTasks[i].taskEnd-subTasks[i].taskStart+1)*100.0);
162 done = done && (threadProgress[i]>subTasks[i].taskEnd);
163 totalProgress += double(threadProgress[i]-subTasks[i].taskStart)/double(subTasks[i].taskEnd-subTasks[i].taskStart+1)*100.0;
165 printf(
"Total: %6.2f%% ",totalProgress/
double(numThreads));
170 for(
int i=0; i<numThreads; i++){
171 pthread_join(threads[i],NULL);
174 double tDuration = GetTimeSec()-tStart;
175 printf(
"\nDone Rendering in %.3fs, Saving to file...\n", tDuration);
176 FILE* fidstats = fopen(
"pre_render_stats.txt",
"a");
177 fprintf(fidstats,
"%d, %d, %f\n",h*w,numThreads,tDuration);
181 static const bool debugLines =
false;
182 char renderFile[4096];
183 snprintf(renderFile, 4095,
"./maps/%s/%s_render.dat",vectorMap->mapName.c_str(),vectorMap->mapName.c_str());
184 FILE* fid = fopen(renderFile,
"w+");
185 printf(
"Saving to %s\n",renderFile);
187 fwrite(&w,
sizeof(
int),1,fid);
188 fwrite(&h,
sizeof(
int),1,fid);
189 fwrite(&resolution,
sizeof(
double),1,fid);
190 for(
int i=0; i<numThreads;i++){
191 const vector<vector<int> > &partScene = *sceneLines[i];
192 int numLocs = partScene.size();
193 for(
int j=0; j<numLocs; j++){
194 int x = sceneLocations[i]->at(j).x;
195 int y = sceneLocations[i]->at(j).y;
197 printf(
"loc:%5d,%5d, lines:",x,y);
198 for(
unsigned int k=0; k<partScene[j].size(); k++){
199 printf(
" %3d", partScene[j][k]);
203 fwrite(&x,
sizeof(
int),1,fid);
204 fwrite(&y,
sizeof(
int),1,fid);
205 int size = partScene[j].size();
206 fwrite(&size,
sizeof(
int),1,fid);
207 fwrite(partScene[j].data(),
sizeof(
int),size,fid);
212 int main(
int argc,
char** argv)
215 char *map_name = (
char*) malloc(4096);
216 snprintf(map_name, 4095,
"GHC7");
218 static struct poptOption options[] = {
219 {
"map-name",
'm', POPT_ARG_STRING , &map_name, 0,
"Map name",
"STRING"},
220 {
"debug",
'd', POPT_ARG_INT, &debugLevel, 0,
"Debug Level",
"NUM"},
221 {
"num-threads",
'n', POPT_ARG_INT, &numThreads, 0,
"Num Threads",
"NUM"},
222 {
"render-resolution",
'r', POPT_ARG_DOUBLE, &resolution, 0,
"Render Resolution",
"NUM"},
225 { NULL, 0, 0, NULL, 0, NULL, NULL }
228 POpt popt(NULL,argc,(
const char**)argv,options,0);
230 while((c = popt.getNextOpt()) >= 0){
234 ColourTerminal(TerminalUtils::TERMINAL_COL_GREEN,TerminalUtils::TERMINAL_COL_BLACK,TerminalUtils::TERMINAL_ATTR_BRIGHT);
235 printf(
"\nVector Localization Pre-Render Optimization\n\n");
238 printf(
"Map: %s\n",map_name);
239 printf(
"Num Threads: %d\n",numThreads);
241 vectorMap =
new VectorMap(map_name,
"./maps",
false);
243 InitHandleStop(&run);
244 PreRenderMultiThread();
246 printf(
"closing.\n");
Subroutines to spice up stdout.
void set(num nx, num ny)
set the components of the vector
C++ Interfaces: VectorMap, LineSection.
vector< int > getSceneLines(vector2f loc, float maxRange)
Get a set of lines which are visible from loc.