// just use ADFun<double> constructor void release_adfun_ctor(void) { CppAD::vector< CppAD::AD<double> > ax(1), ay(1); ax[0] = 0.; CppAD::Independent(ax); ay[0] = fabs(ax[0]); CppAD::ADFun<double> f(ax, ay); return; }
Vec3q SATSampler::operator()(const Vec2q &uv,const Vec2q &diff) const { f32x4b fullMask=diff.x>=0.5f||diff.x>= 0.5f; if(ForAll(fullMask)) return Vec3q(avg.x,avg.y,avg.z); Vec2q tDiff=diff*floatq(0.5f); Vec2q a=(uv-tDiff),b=(uv+tDiff); a*=Vec2q(floatq(w),floatq(h)); b*=Vec2q(floatq(w),floatq(h)); i32x4 ax(a.x),ay(a.y); i32x4 bx(b.x),by(b.y); ax&=wMask; ay&=hMask; bx&=wMask; by&=hMask; union { __m128 count; float countf[4]; }; TSample sum[4]; i32x4 one(1); if(ForAll(ax<=bx&&ay<=by)) { count = (f32x4(by-ay+one)*f32x4(bx-ax+one)).m; ComputeRect(ax,ay,bx,by,sum); } else for(int k=0;k<4;k++) { if(ax[k]>bx[k]) { if(ay[k]>by[k]) { countf[k]=(bx[k]+1)*(by[k]+1)+(w-ax[k])*(h-ay[k]); sum[k]=ComputeRect(0,0,bx[k],by[k])+ComputeRect(ax[k],ay[k],w-1,h-1); } else { countf[k]=(bx[k]+1+w-ax[k])*(by[k]-ay[k]+1); sum[k]=ComputeRect(0,ay[k],bx[k],by[k])+ComputeRect(ax[k],ay[k],w-1,by[k]); } } else { if(ay[k]>by[k]) { countf[k]=(bx[k]-ax[k]+1)*(by[k]+h+1-ay[k]); sum[k]=ComputeRect(ax[k],0,bx[k],by[k])+ComputeRect(ax[k],ay[k],bx[k],h-1); } else { countf[k]=(by[k]-ay[k]+1)*(bx[k]-ax[k]+1); sum[k]=ComputeRect(ax[k],ay[k],bx[k],by[k]); } } } union { __m128 out[3]; struct { float ox[4]; float oy[4]; float oz[4]; } o; }; o.ox[0]=sum[0].R(); o.oy[0]=sum[0].G(); o.oz[0]=sum[0].B(); o.ox[1]=sum[1].R(); o.oy[1]=sum[1].G(); o.oz[1]=sum[1].B(); o.ox[2]=sum[2].R(); o.oy[2]=sum[2].G(); o.oz[2]=sum[2].B(); o.ox[3]=sum[3].R(); o.oy[3]=sum[3].G(); o.oz[3]=sum[3].B(); return Condition(fullMask,Vec3q(avg.x,avg.y,avg.z), Vec3q(out[0], out[1], out[2]) * Inv(floatq(count) * 255.0f)); }
// multi_thread_checkpoint bool multi_atomic(void) { bool ok = true; // OpenMP setup size_t num_threads = 4; // number of threads omp_set_dynamic(0); // turn off dynamic thread adjustment omp_set_num_threads( int(num_threads) ); // set number of OMP threads // check that multi-threading is possible on this machine if( omp_get_max_threads() < 2 ) { std::cout << "This machine does not support multi-threading: "; } // create checkpoint version of algorithm size_t n(1), m(1); ad_vector ax(n), ay(m); ax[0] = 2.0; size_t length_of_sum = 5000; long_sum_atomic atom_fun("long_sum", length_of_sum); // setup for using CppAD in paralle mode CppAD::thread_alloc::parallel_setup(num_threads, in_parallel, thread_num); CppAD::thread_alloc::hold_memory(true); CppAD::parallel_ad<double>(); // place to hold result for each thread d_vector y(num_threads); for(size_t thread = 0; thread < num_threads; thread++) y[thread] = 0.0; # pragma omp parallel for for(int thread = 0; thread < int(num_threads); thread++) { ad_vector au(n), av(m); au[0] = 1.0; CppAD::Independent(au); atom_fun(au, av); CppAD::ADFun<double> f(au, av); // d_vector x(n), v(m); x[0] = double( thread + 1 ); v = f.Forward(0, x); // // this assigment has false sharing; i.e., will case cache resets // (conversion avoids boost vector conversion warning) y[size_t(thread)] = v[0]; } // check the results for(size_t thread = 0; thread < num_threads; thread++) { double check = double( length_of_sum * (thread + 1) ); ok &= check == y[thread]; } return ok; }
int store_a() { Pid_t i; char *fname = tagged_output_name("acc"); FILE *fp = fopen(fname, "wt"); log("IO", "Storing accelerations in %s\n", fname); myassert(fp != NULL, "Can't open file to write accelerations."); fprintf(fp, "%ld\n", (long int)env.n_particles); forall_particles(i) fprintf(fp, "%.8g %.8g %.8g\n", (double)ax(i), (double)ay(i), (double)az(i)); //fprintf(fp, "%.8g %.8g %.8g %.8g\n", ax(i), ay(i), az(i), DIST(ax(i), ay(i), az(i))); fclose(fp); return 0; }
void saatarih(void) { putchar('\n'); putchar('\n'); saat(); putchar(' '); bugun(); putchar(' '); ayinkaci(); putchar(' '); ay(); putchar(' '); yil(); putchar('\n'); putchar('\n'); }
void DynamicGeometry::AddLineArrowHead(const glm::vec3 &p0, const glm::vec3 &p1, float size, const glm::vec3 &color) { const float eps = 0.001f; if (glm::dot(p0, p1) < eps * eps) return; glm::vec3 ax; glm::vec3 ay(0.0, 1.0, 0.0); glm::vec3 az; az = p0 - p1; az = glm::normalize(az); ax = glm::cross(ay, az); ay = glm::cross(az, ax); ay = glm::normalize(ay); AddLine(p0, glm::vec3(p0[0] + az[0] * size + ax[0] * size / 3, p0[1] + az[1] * size + ax[1] * size / 3, p0[2] + az[2] * size + ax[2] * size / 3), color); AddLine(p0, glm::vec3(p0[0] + az[0] * size - ax[0] * size / 3, p0[1] + az[1] * size - ax[1] * size / 3, p0[2] + az[2] * size - ax[2] * size / 3), color); }
void XYView_helper::print(Printer* c, const Allocation&) const { current_draw_view_ = v_; c->push_clipping(); c->clip_rect(v_->left(), v_->bottom(), v_->right(), v_->top()); char buf[100]; float x, b; v_->s2o().matrix(x, b, b, b, b, b); sprintf(buf, "\n%g setlinewidth", x); c->comment(buf); // when printfile started printing at the level of the xyview // the allocation was incorrect and was used by the background // that was ok when the background was white... // set the allocation the same as the clipping Allocation a1; Allotment ax(v_->left(), v_->width(), 0); Allotment ay(v_->bottom(), v_->height(), 0); a1.allot_x(ax); a1.allot_y(ay); body()->print(c, a1); c->pop_clipping(); }
Box::Box(Wm5::Box3d& box) { Vector3d c(box.Center[0],box.Center[1],box.Center[2]); Vector3d ax(box.Axis[0][0],box.Axis[0][1],box.Axis[0][2]); Vector3d ay(box.Axis[1][0],box.Axis[1][1],box.Axis[1][2]); Vector3d az(box.Axis[2][0],box.Axis[2][1],box.Axis[2][2]); double ex=box.Extent[0]; double ey=box.Extent[1]; double ez=box.Extent[2]; Vertex[0]=c-ex*ax-ey*ay+ez*az; Vertex[1]=c+ex*ax-ey*ay+ez*az; Vertex[2]=c+ex*ax-ey*ay-ez*az; Vertex[3]=c-ex*ax-ey*ay-ez*az; Vertex[4]=c-ex*ax+ey*ay+ez*az; Vertex[5]=c+ex*ax+ey*ay+ez*az; Vertex[6]=c+ex*ax+ey*ay-ez*az; Vertex[7]=c-ex*ax+ey*ay-ez*az; for (int i=0;i<6;i++) { Extendable[i]=true; } type=0; }
void cnbint( int i, const double pos[][3], const double vel[][3], const double mass[], int nnb, int list[], double f[3], double fdot[3]){ const int NBMAX = 512; assert(nnb <= NBMAX); float xbuf[NBMAX] __attribute__ ((aligned(16))); float ybuf[NBMAX] __attribute__ ((aligned(16))); float zbuf[NBMAX] __attribute__ ((aligned(16))); float vxbuf[NBMAX] __attribute__ ((aligned(16))); float vybuf[NBMAX] __attribute__ ((aligned(16))); float vzbuf[NBMAX] __attribute__ ((aligned(16))); float mbuf[NBMAX] __attribute__ ((aligned(16))); assert((unsigned long)xbuf % 16 == 0); double xi = pos[i][0]; double yi = pos[i][1]; double zi = pos[i][2]; float vxi = vel[i][0]; float vyi = vel[i][1]; float vzi = vel[i][2]; for(int k=0; k<nnb; k++){ int j = list[k]; #if 1 int jj = list[k+4]; __builtin_prefetch(pos[jj]); __builtin_prefetch(pos[jj]+2); __builtin_prefetch(vel[jj]); __builtin_prefetch(vel[jj]+2); __builtin_prefetch(&mass[jj]); #endif #if 0 xbuf[k] = pos[j][0] - xi; ybuf[k] = pos[j][1] - yi; zbuf[k] = pos[j][2] - zi; vxbuf[k] = vel[j][0] - vxi; vybuf[k] = vel[j][1] - vyi; vzbuf[k] = vel[j][2] - vzi; mbuf[k] = mass[j]; #else double xj = pos[j][0]; double yj = pos[j][1]; double zj = pos[j][2]; float vxj = vel[j][0]; float vyj = vel[j][1]; float vzj = vel[j][2]; float mj = mass[j]; xj -= xi; yj -= yi; zj -= zi; vxj -= vxi; vyj -= vyi; vzj -= vzi; xbuf[k] = xj; ybuf[k] = yj; zbuf[k] = zj; vxbuf[k] = vxj; vybuf[k] = vyj; vzbuf[k] = vzj; mbuf[k] = mj; #endif } for(int k=nnb; k%4; k++){ xbuf[k] = 16.0f; ybuf[k] = 16.0f; zbuf[k] = 16.0f; vxbuf[k] = 0.0f; vybuf[k] = 0.0f; vzbuf[k] = 0.0f; mbuf[k] = 0.0f; } v4df ax(0.0), ay(0.0), az(0.0); v4sf jx(0.0), jy(0.0), jz(0.0); for(int k=0; k<nnb; k+=4){ v4sf dx(xbuf + k); v4sf dy(ybuf + k); v4sf dz(zbuf + k); v4sf dvx(vxbuf + k); v4sf dvy(vybuf + k); v4sf dvz(vzbuf + k); v4sf mj(mbuf + k); v4sf r2 = dx*dx + dy*dy + dz*dz; v4sf rv = dx*dvx + dy*dvy + dz*dvz; rv *= v4sf(-3.0f); // v4sf rinv1 = r2.rsqrt() & v4sf(mask); #if 1 v4sf rinv1 = r2.rsqrt(); #else v4sf rinv1 = v4sf(v4df(1.0) / v4df(r2).sqrt()); #endif v4sf rinv2 = rinv1 * rinv1; rv *= rinv2; v4sf rinv3 = mj * rinv1 * rinv2; dx *= rinv3; ax += v4df(dx); dy *= rinv3; ay += v4df(dy); dz *= rinv3; az += v4df(dz); dvx *= rinv3; jx += dvx; dvy *= rinv3; jy += dvy; dvz *= rinv3; jz += dvz; dx *= rv; jx += dx; dy *= rv; jy += dy; dz *= rv; jz += dz; } f[0] = ax.sum(); f[1] = ay.sum(); f[2] = az.sum(); fdot[0] = (v4df(jx)).sum(); fdot[1] = (v4df(jy)).sum(); fdot[2] = (v4df(jz)).sum(); assert(f[0] == f[0]); assert(f[1] == f[1]); assert(f[2] == f[2]); assert(fdot[0] == fdot[0]); assert(fdot[1] == fdot[1]); assert(fdot[2] == fdot[2]); }
void cnbint( int i, const double pos[][3], const double vel[][3], const double mass[], int nnb, int list[], double f[3], double fdot[3]){ const int NBMAX = 512; assert(nnb <= NBMAX); double xbuf[NBMAX] __attribute__ ((aligned(16))); double ybuf[NBMAX] __attribute__ ((aligned(16))); double zbuf[NBMAX] __attribute__ ((aligned(16))); float vxbuf[NBMAX] __attribute__ ((aligned(16))); float vybuf[NBMAX] __attribute__ ((aligned(16))); float vzbuf[NBMAX] __attribute__ ((aligned(16))); float mbuf[NBMAX] __attribute__ ((aligned(16))); for(int k=0; k<nnb; k++){ int j = list[k]; xbuf[k] = pos[j][0]; ybuf[k] = pos[j][1]; zbuf[k] = pos[j][2]; vxbuf[k] = vel[j][0]; vybuf[k] = vel[j][1]; vzbuf[k] = vel[j][2]; mbuf[k] = mass[j]; } for(int k=nnb; k%4; k++){ xbuf[k] = 16.0; ybuf[k] = 16.0; zbuf[k] = 16.0; vxbuf[k] = 0.0f; vybuf[k] = 0.0f; vzbuf[k] = 0.0f; mbuf[k] = 0.0f; } v4df xi(pos[i][0]); v4df yi(pos[i][1]); v4df zi(pos[i][2]); v4sf vxi(vel[i][0]); v4sf vyi(vel[i][1]); v4sf vzi(vel[i][2]); v4df ax(0.0), ay(0.0), az(0.0); v4sf jx(0.0), jy(0.0), jz(0.0); for(int k=0; k<nnb; k+=4){ v4df xj(xbuf + k); v4df yj(ybuf + k); v4df zj(zbuf + k); v4sf vxj(vxbuf + k); v4sf vyj(vybuf + k); v4sf vzj(vzbuf + k); v4sf mj(mbuf + k); v4sf dx = v4sf::_v4sf(xj - xi); v4sf dy = v4sf::_v4sf(yj - yi); v4sf dz = v4sf::_v4sf(zj - zi); v4sf dvx = vxj - vxi; v4sf dvy = vyj - vyi; v4sf dvz = vzj - vzi; v4sf r2 = dx*dx + dy*dy + dz*dz; v4sf rv = dx*dvx + dy*dvy + dz*dvz; rv *= v4sf(-3.0f); // v4sf rinv1 = r2.rsqrt() & v4sf(mask); v4sf rinv1 = r2.rsqrt(); v4sf rinv2 = rinv1 * rinv1; rv *= rinv2; v4sf rinv3 = mj * rinv1 * rinv2; dx *= rinv3; ax += v4df(dx); dy *= rinv3; ay += v4df(dy); dz *= rinv3; az += v4df(dz); dvx *= rinv3; jx += dvx; dvy *= rinv3; jy += dvy; dvz *= rinv3; jz += dvz; dx *= rv; jx += dx; dy *= rv; jy += dy; dz *= rv; jz += dz; } f[0] = ax.sum(); f[1] = ay.sum(); f[2] = az.sum(); fdot[0] = (v4df(jx)).sum(); fdot[1] = (v4df(jy)).sum(); fdot[2] = (v4df(jz)).sum(); assert(f[0] == f[0]); assert(f[1] == f[1]); assert(f[2] == f[2]); assert(fdot[0] == fdot[0]); assert(fdot[1] == fdot[1]); assert(fdot[2] == fdot[2]); }
//-----------------------------------------------------------------------------------------// //--------------------------------DRAW NEW POINT TO THE GRAPHS-----------------------------// //-----------------------------------------------------------------------------------------// void RealTimePlotWindow::dataAvaible(QByteArray ext) { double przelicznik = 6103515625;//prescaler value double memory = 2; QVector<measurementData> data = ExtractData(ext);//extract data from dialogwinndow quint16 newDataSize = data.size(); QVector<double> key(newDataSize); QVector<double> ax(newDataSize); QVector<double> ay(newDataSize); QVector<double> az(newDataSize); QVector<double> gx(newDataSize); QVector<double> gy(newDataSize); QVector<double> gz(newDataSize); double keyPrescaler =0; keyPrescaler = keyCounter / 200; // qDebug()<<"znacznik"; for(double i = 0; i<newDataSize; i++) { key[i] = (double)keyPrescaler + (i/200); // key[i] = (double)keyCounter; ax[i] = ((double)data.at(i).ax.as_word)*przelicznik/100000000000; ay[i] = ((double)data.at(i).ay.as_word)*(-1)*przelicznik/100000000000; az[i] = ((double)data.at(i).az.as_word)*(-1)*przelicznik/100000000000; gx[i] = ((double)data.at(i).gx.as_word)*przelicznik/100000000000; gy[i] = ((double)data.at(i).gy.as_word)*(-1)*przelicznik/100000000000; gz[i] = ((double)data.at(i).gz.as_word)*(-1)*przelicznik/100000000000; } if((newDataSize>0)&(triger == true))//get instValues 5 times per secound(depend of timmer interval) { (*instValues)[0] = ax[0]; (*instValues)[1] = ay[0]; (*instValues)[2] = az[0]; (*instValues)[3] = gx[0]; (*instValues)[4] = gy[0]; (*instValues)[5] = gz[0]; triger = false; instValWindow->setInstValues(instValues); } // add new data to graphs ui->accPlot->graph(0)->addData(key, ax); ui->accPlot->graph(1)->addData(key, ay); ui->accPlot->graph(2)->addData(key, az); ui->gyroPlot->graph(0)->addData(key, gx); ui->gyroPlot->graph(1)->addData(key, gy); ui->gyroPlot->graph(2)->addData(key, gz); // remove data of lines that's outside visible range: ui->accPlot->graph(0)->removeDataBefore(keyPrescaler-memory); ui->accPlot->graph(1)->removeDataBefore(keyPrescaler-memory); ui->accPlot->graph(2)->removeDataBefore(keyPrescaler-memory); // qDebug()<<"znacznik 4\n"; // rescale value (vertical) axis to fit the current data: ui->accPlot->graph(0)->rescaleValueAxis(); ui->accPlot->graph(1)->rescaleValueAxis(true); ui->accPlot->graph(2)->rescaleValueAxis(true); // make key axis range scroll with the data (at a constant range size of 8): ui->accPlot->xAxis->setRange(keyPrescaler, memory, Qt::AlignRight); ui->accPlot->replot(); // remove data of lines that's outside visible range: ui->gyroPlot->graph(0)->removeDataBefore(keyPrescaler-memory); ui->gyroPlot->graph(1)->removeDataBefore(keyPrescaler-memory); ui->gyroPlot->graph(2)->removeDataBefore(keyPrescaler-memory); // rescale value (vertical) axis to fit the current data: ui->gyroPlot->graph(0)->rescaleValueAxis(); ui->gyroPlot->graph(1)->rescaleValueAxis(true); ui->gyroPlot->graph(2)->rescaleValueAxis(true); // make key axis range scroll with the data (at a constant range size of 8): ui->gyroPlot->xAxis->setRange(keyPrescaler, memory, Qt::AlignRight); ui->gyroPlot->replot(); keyCounter += newDataSize; MPS += newDataSize; qDebug()<<"keyCounter:"<<keyCounter; }
int main(int argc, char *argv[]) { unsigned int repeat=0; char **tags; int i; int a; int b; float gdivide_a; float gdivide_b; char are_you_sure[100]; #ifdef NAJI_DEBUG fprintf(stderr, "\n\n"); fprintf(stderr, "NAJI_DEBUG - check if two commands are displayed as one joined string,\n"); fprintf(stderr, " you might have missed a , in najitool_valid_commands[]\n\n"); for (i=0; i<NAJITOOL_MAX_COMMANDS; i++) fprintf(stderr, "%s ", najitool_valid_commands[i]); fgetc(stdin); #endif /* NAJI_DEBUG */ #ifdef NAJI_DEBUG fprintf(stderr, "\n\nNAJI_DEBUG - YOUR PARAMETERS/ARGUMENTS:\n\n"); for (i=0; i<argc; i++) fprintf(stderr, "%s ", argv[i]); fprintf(stderr, "\n\n"); fgetc(stdin); #endif /* NAJI_DEBUG */ if (argc >= 2) { tolowers(argv[1]); najitool_check_command(argv[1]); } if (argc == 1) { printf("\n\n"); /* printf(" __ | \n"); printf(" / \\ | \n"); printf(" / _____| | o \\ \n"); printf(" | \\ o |___| \n"); printf(" \\____\\ \n"); printf(" o o T O O L \n"); */ printf(" __ | ********************************************\n"); printf(" / \\ | najitool 0.8.4 using libnaji 0.6.4 \n"); printf(" / _____| | o \\ both written by NECDET COKYAZICI \n"); printf(" | \\ o |___| and contributors \n"); printf(" \\____\\ ********************************************\n"); printf(" o o T O O L No warranty, to view the license type: \n"); printf(" najitool license \n"); printf(" http://najitool.sf.net/ ********************************************\n"); printf(" To view the credits type: najitool credits \n"); printf(" Public Domain, 2003-2011 ********************************************\n"); printf("\n"); forhelp(); return 0; } if (argc >= 2) { if (!strcmp(argv[1], "mp3taged")) { if ((argc % 2 != 1) | (argc == 3)) { printf("mp3taged: too few arguments '%s'\n", argv[1]); return 1; } /* * we save the tags' options: * tags[i] = <tag name> * tags[i+1] = <user content> * .. */ tags = (char**) malloc (sizeof(char*)*(argc-3)*2); for (i=0; i<(argc-3)*2; i+=2) tags[i] = (char*) malloc(7*sizeof(char)); for (i=1; i<(argc-3)*2; i+=2) tags[i] = argv[i+2]; for (i=0; i<(argc-3)*2; i+=2) memcpy (tags[i], argv[i+2], 7); mp3editag (argv[argc-1], tags, argc-3); for (i=0; i<(argc-3)*2; i+=2) free(tags[i]); free(tags); return 0; } if (!strcmp(argv[1], "credits")) { if (argc > 2) tooparam("credits"); naji_credits(); return 0; } if (!strcmp(argv[1], "asctable")) { if (argc > 2) tooparam("asctable"); asctable(); return 0; } if (!strcmp(argv[1], "engnum")) { if (argc > 2) tooparam("engnum"); engnum(); return 0; } if (!strcmp(argv[1], "turnum")) { if (argc > 2) tooparam("turnum"); turnum(); return 0; } if (!strcmp(argv[1], "najcrypt")) { if (argc > 2) tooparam("najcrypt"); najcrypt(); return 0; } if (!strcmp(argv[1], "database")) { if (argc > 2) tooparam("database"); naji_database(); return 0; } if (!strcmp(argv[1], "html_db")) { if (argc > 2) tooparam("html_db"); naji_html_database(); return 0; } if (!strcmp(argv[1], "calc")) { if (argc > 2) tooparam("calc"); naji_calc(); return 0; } if (!strcmp(argv[1], "length")) { if (argc > 2) tooparam("length"); length(); return 0; } if (!strcmp(argv[1], "mathgame")) { if (argc > 2) tooparam("mathgame"); mathgame(); return 0; } if (!strcmp(argv[1], "license")) { if (argc > 2) tooparam("license"); naji_license(); return 0; } if (!strcmp(argv[1], "ttt")) { if (argc > 2) tooparam("ttt"); ttt(); return 0; } if (!strcmp(argv[1], "naji_bmp")) { if (argc > 2) tooparam("naji_bmp"); naji_bmp(); return 0; } if (!strcmp(argv[1], "unihtml")) { if (argc > 2) tooparam("unihtml"); naji_gen_unicode_html_pages(); return 0; } if (!strcmp(argv[1], "rmunihtm")) { if (argc > 2) tooparam("rmunihtm"); naji_del_gen_unicode_html_pages(); return 0; } if (!strcmp(argv[1], "cat_text")) { if (argc == 2) { naji_stdin_msg(); cat_text_stdin(); return 0; } if (argc == 3) { cat_text(argv[2]); return 0; } if (argc > 3) tooparam("cat_text"); return 0; } if (!strcmp(argv[1], "kitten")) { if (argc == 2) { naji_stdin_msg(); kitten_stdin(); return 0; } if (argc == 3) { kitten(argv[2]); return 0; } if (argc > 3) tooparam("kitten"); return 0; } if (!strcmp(argv[1], "genlic")) { if (argc > 2) tooparam("genlic"); naji_genlic(); return 0; } if (!strcmp(argv[1], "genhelp")) { if (argc > 2) tooparam("genhelp"); najitool_generate_help(); return 0; } if (!strcmp(argv[1], "htmlhelp")) { if (argc > 2) tooparam("htmlhelp"); najitool_generate_help_html(); return 0; } if (!strcmp(argv[1], "systemdt")) { if (argc > 2) tooparam("systemdt"); systemdt(); return 0; } if (!strcmp(argv[1], "datetime")) { if (argc > 2) tooparam("datetime"); datetime(); return 0; } if (!strcmp(argv[1], "telltime")) { if (argc > 2) tooparam("telltime"); printf("\n\n"); telltime(); printf("\n\n"); return 0; } if (!strcmp(argv[1], "today")) { if (argc > 2) tooparam("today"); printf("\n\n"); today(); printf("\n\n"); return 0; } if (!strcmp(argv[1], "dayofmon")) { if (argc > 2) tooparam("dayofmon"); printf("\n\n"); dayofmon(); printf("\n\n"); return 0; } if (!strcmp(argv[1], "month")) { if (argc > 2) tooparam("month"); printf("\n\n"); month(); printf("\n\n"); return 0; } if (!strcmp(argv[1], "year")) { if (argc > 2) tooparam("year"); printf("\n\n"); year(); printf("\n\n"); return 0; } if (!strcmp(argv[1], "saatarih")) { if (argc > 2) tooparam("saatarih"); saatarih(); return 0; } if (!strcmp(argv[1], "saat")) { if (argc > 2) tooparam("saat"); printf("\n\n"); saat(); printf("\n\n"); return 0; } if (!strcmp(argv[1], "bugun")) { if (argc > 2) tooparam("bugun"); printf("\n\n"); bugun(); printf("\n\n"); return 0; } if (!strcmp(argv[1], "ayinkaci")) { if (argc > 2) tooparam("ayinkaci"); printf("\n\n"); ayinkaci(); printf("\n\n"); return 0; } if (!strcmp(argv[1], "ay")) { if (argc > 2) tooparam("ay"); printf("\n\n"); ay(); printf("\n\n"); return 0; } if (!strcmp(argv[1], "yil")) { if (argc > 2) tooparam("yil"); printf("\n\n"); yil(); printf("\n\n"); return 0; } if (!strcmp(argv[1], "allbmp16")) { if (argc > 2) tooparam("allbmp16"); printf("\n\n"); allbmp16(); printf("\n\n"); return 0; } if (!strcmp(argv[1], "help")) { if (argc == 2) { printf("\n\nAvailable help catagories:\n\n"); printf("commands\n"); printf("\n\n"); forhelp(); return 0; } if (argc == 3) { if (!strcmp(argv[2], "commands")) najitool_help_commands(); else najitool_command_help(argv[2]); return 0; } if (argc > 3) tooparam("help"); return 0; } begin_cmd("mergline", 7) mergline(argv[2], argv[3], argv[4], argv[5], argv[6]); end_cmd() begin_cmd("mp3split", 6) mp3split(argv[4], argv[5], atoi(argv[2]), atoi(argv[3])); end_cmd() begin_cmd("rrrchars", 6) rrrchars(argv[2], argv[3], atoi(argv[4]), atoi(argv[5])); end_cmd() begin_cmd("chstr", 6) chstr(argv[2], argv[3], argv[4], argv[5]); end_cmd() begin_cmd("chchars", 6) chchars(argv[2], argv[3], argv[4], argv[5]); end_cmd() begin_cmd("chchar", 6) chchar(argv[2], argv[3], argv[4][0], argv[5][0]); end_cmd() begin_cmd("filechop", 6) filechop( (strtol(argv[2], NULL, 0)), argv[3], argv[4], argv[5]); end_cmd() begin_cmd("putlines", 6) putlines(argv[2], argv[3], argv[4], argv[5]); end_cmd() begin_cmd("copyoffs", 6) copyoffs(argv[2], strtoul(argv[3], NULL, 0), strtoul(argv[4], NULL, 0), argv[5]); end_cmd() begin_cmd("istrael", 6) istrael(argv[2], atoi(argv[3]), argv[4], argv[5]); end_cmd() begin_cmd("addline", 6) addline(argv[2], argv[3], argv[4], strtoul(argv[5], NULL, 0)); end_cmd() begin_cmd("replacel", 6) replacel(argv[2], argv[3], argv[4], strtoul(argv[5], NULL, 0)); end_cmd() begin_cmd("bremline", 5) bremline(argv[2], argv[3], argv[4]); end_cmd() begin_cmd("eremline", 5) eremline(argv[2], argv[3], argv[4]); end_cmd() begin_cmd("remline", 5) remline(argv[2], argv[3], argv[4]); end_cmd() begin_cmd("skipstr", 5) skipstr(argv[2], argv[3], argv[4]); end_cmd() begin_cmd("makarray", 5) makarray(argv[2], argv[3], argv[4]); end_cmd() begin_cmd("streline", 5) streline(argv[2], argv[3], argv[4]); end_cmd() begin_cmd("strbline", 5) strbline(argv[2], argv[3], argv[4]); end_cmd() begin_cmd("swapfeb", 5) swapfeb(argv[2], argv[3], argv[4]); end_cmd() begin_cmd("filbreed", 5) filbreed(argv[2], argv[3], argv[4]); end_cmd() begin_cmd("skipchar", 5) skipchar(argv[2], argv[3], argv[4]); end_cmd() begin_cmd("onlychar", 5) onlychar(argv[2], argv[3], argv[4]); end_cmd() begin_cmd("repchar", 5) repeat = (unsigned int) atoi(argv[4]); repchar(argv[2], argv[3], repeat); end_cmd() begin_cmd("linesnip", 5) repeat = (unsigned int) atoi(argv[2]); linesnip(repeat, argv[3], argv[4]); end_cmd() begin_cmd("charwarp", 5) repeat = (unsigned int) atoi(argv[4]); charwrap(repeat, argv[2], argv[3]); end_cmd() begin_cmd("repcharp", 5) repeat = (unsigned int) atoi(argv[4]); repcharp(argv[2], argv[3], repeat); end_cmd() begin_cmd("coffset", 5) coffset(argv[2], strtoul(argv[3], NULL, 0), strtoul(argv[4], NULL, 0)); end_cmd() begin_cmd("dumpoffs", 5) dumpoffs(argv[2], strtoul(argv[3], NULL, 0), strtoul(argv[4], NULL, 0)); end_cmd() begin_cmd("bin2c", 5) bin2c(argv[2], argv[3], argv[4]); end_cmd() begin_cmd("filejoin", 5) filejoin(argv[2], argv[3], argv[4]); end_cmd() begin_cmd("mkpatch", 5) mkpatch(argv[2], argv[3], argv[4]); end_cmd() begin_cmd("charfile", 5) repeat = (unsigned int) atoi(argv[3]); charfile(argv[2], repeat, argv[4][0]); end_cmd() begin_cmd("strfile", 5) repeat = (unsigned int) atoi(argv[3]); strfile(argv[2], repeat, argv[4]); end_cmd() begin_cmd("tabspace", 5) repeat = atoi(argv[2]); tabspace(repeat, argv[3], argv[4]); end_cmd() begin_cmd("charaftr", 5) charaftr(argv[2], argv[3], argv[4][0]); end_cmd() begin_cmd("charbefr", 5) charbefr(argv[2], argv[3], argv[4][0]); end_cmd() begin_cmd("strachar", 5) strachar(argv[2], argv[3], argv[4]); end_cmd() begin_cmd("strbchar", 5) strbchar(argv[2], argv[3], argv[4]); end_cmd() begin_cmd("rstrach", 5) rstrach(atoi(argv[2]), argv[3], argv[4]); end_cmd() begin_cmd("rstrbch", 5) rstrbch(atoi(argv[2]), argv[3], argv[4]); end_cmd() begin_cmd("cpfroml", 5) cpfroml(atoi(argv[2]), argv[3], argv[4]); end_cmd() begin_cmd("cptiline", 5) cptiline(atoi(argv[2]), argv[3], argv[4]); end_cmd() begin_cmd("n2ch", 5) n2ch(argv[2][0], argv[3], argv[4]); end_cmd() begin_cmd("n2str", 5) n2str(argv[2], argv[3], argv[4]); end_cmd() begin_cmd("weakrypt", 5) weakrypt(argv[2], argv[3], argv[4]); end_cmd() begin_cmd("sp2ce2sp", 5) sp2ce2sp(argv[2][0], argv[3], argv[4]); end_cmd() begin_cmd("istreml", 5) istreml(argv[2], argv[3], argv[4]); end_cmd() begin_cmd("removel", 5) removel(argv[2], argv[3], strtoul(argv[4], NULL, 0)); end_cmd() begin_cmd("printftx", 4) printftx(argv[2], argv[3]); end_cmd() begin_cmd("lensorts", 4) lensorts(argv[2], argv[3]); end_cmd() begin_cmd("lensortl", 4) lensortl(argv[2], argv[3]); end_cmd() begin_cmd("find", 4) find(argv[2], argv[3]); end_cmd() begin_cmd("findi", 4) findi(argv[2], argv[3]); end_cmd() begin_cmd("cfind", 4) cfind(argv[2], argv[3]); end_cmd() begin_cmd("cfindi", 4) cfindi(argv[2], argv[3]); end_cmd() begin_cmd("showline", 4) showline(argv[2], atoi(argv[3])); end_cmd() begin_cmd("cat_tail", 4) cat_tail(argv[2], atoi(argv[3])); end_cmd() begin_cmd("cat_head", 4) cat_head(argv[2], atoi(argv[3])); end_cmd() begin_cmd("getlinks", 4) getlinks(argv[2], argv[3]); end_cmd() begin_cmd("f2upper", 4) f2upper(argv[2], argv[3]); end_cmd() begin_cmd("f2lower", 4) f2lower(argv[2], argv[3]); end_cmd() begin_cmd("fswpcase", 4) fswpcase(argv[2], argv[3]); end_cmd() begin_cmd("downlist", 4) downlist(argv[2], argv[3]); end_cmd() begin_cmd("hilist", 4) hilist(argv[2], argv[3]); end_cmd() begin_cmd("rtcafter", 4) rtcafter(argv[2], argv[3]); end_cmd() begin_cmd("rtcbefor", 4) rtcbefor(argv[2], argv[3]); end_cmd() begin_cmd("rbcafter", 4) rbcafter(argv[2], argv[3]); end_cmd() begin_cmd("rbcbefor", 4) rbcbefor(argv[2], argv[3]); end_cmd() begin_cmd("numlines", 4) numlines(argv[2], argv[3]); end_cmd() begin_cmd("file2dec", 4) file2dec(argv[2], argv[3]); end_cmd() begin_cmd("file2hex", 4) file2hex(argv[2], argv[3]); end_cmd() begin_cmd("file2bin", 4) file2bin(argv[2], argv[3]); end_cmd() begin_cmd("wordline", 4) wordline(argv[2], argv[3]); end_cmd() begin_cmd("8bit256", 4) repeat = (unsigned int) atoi(argv[3]); _8bit256(argv[2], repeat); end_cmd() begin_cmd("eng2arab", 4) eng2arab(argv[2], argv[3]); end_cmd() begin_cmd("arab2eng", 4) arab2eng(argv[2], argv[3]); end_cmd() begin_cmd("e2ahtml", 4) e2ahtml(argv[2], argv[3]); end_cmd() begin_cmd("freverse", 4) freverse(argv[2], argv[3]); end_cmd() begin_cmd("repcat", 4) repeat = (unsigned int) atoi(argv[3]); repcat(argv[2], repeat); end_cmd() begin_cmd("repcatpp", 4) repeat = (unsigned int) atoi(argv[3]); repcatpp(argv[2], repeat); end_cmd() begin_cmd("copyfile", 4) copyfile(argv[2], argv[3]); end_cmd() begin_cmd("qpatch", 4) qpatch(argv[2], argv[3]); end_cmd() begin_cmd("flipcopy", 4) flipcopy(argv[2], argv[3]); end_cmd() begin_cmd("fillfile", 4) fillfile(argv[2], argv[3][0]); end_cmd() begin_cmd("bin2text", 4) bin2text(argv[2], argv[3]); end_cmd() begin_cmd("bin2hexi", 4) bin2hexi(argv[2], argv[3]); end_cmd() begin_cmd("rndbfile", 4) rndbfile(argv[2], strtoul(argv[3], NULL, 0)); end_cmd() begin_cmd("rndtfile", 4) rndtfile(argv[2], strtoul(argv[3], NULL, 0)); end_cmd() begin_cmd("skipcat", 4) skipcat(argv[2], argv[3]); end_cmd() begin_cmd("onlycat", 4) onlycat(argv[2], argv[3]); end_cmd() begin_cmd("bigascif", 4) bigascif(argv[2], argv[3]); end_cmd() begin_cmd("leetfile", 4) leetfile(argv[2], argv[3]); end_cmd() begin_cmd("asc2ebc", 4) asc2ebc(argv[2], argv[3]); end_cmd() begin_cmd("ebc2asc", 4) ebc2asc(argv[2], argv[3]); end_cmd() begin_cmd("unix2dos", 4) unix2dos(argv[2], argv[3]); end_cmd() begin_cmd("dos2unix", 4) dos2unix(argv[2], argv[3]); end_cmd() begin_cmd("uuencode", 4) uuencode(argv[2], argv[3]); end_cmd() begin_cmd("uudecode", 4) uudecode(argv[2], argv[3]); end_cmd() begin_cmd("wordwrap", 4) wordwrap(argv[2], argv[3]); end_cmd() begin_cmd("compare", 4) compare(argv[2], argv[3]); end_cmd() begin_cmd("ccompare", 4) ccompare(argv[2], argv[3]); end_cmd() begin_cmd("hmakerf", 4) hmakerf(argv[2], argv[3]); end_cmd() begin_cmd("qcrypt", 4) qcrypt(argv[2], argv[3]); end_cmd() begin_cmd("revlines", 4) revlines(argv[2], argv[3]); end_cmd() begin_cmd("html2txt", 4) html2txt(argv[2], argv[3]); end_cmd() begin_cmd("txt2html", 4) txt2html(argv[2], argv[3]); end_cmd() begin_cmd("htmlfast", 4) htmlfast(argv[2], argv[3]); end_cmd() begin_cmd("onlalnum", 4) onlalnum(argv[2], argv[3]); end_cmd() begin_cmd("onlalpha", 4) onlalpha(argv[2], argv[3]); end_cmd() begin_cmd("onlcntrl", 4) onlcntrl(argv[2], argv[3]); end_cmd() begin_cmd("onldigit", 4) onldigit(argv[2], argv[3]); end_cmd() begin_cmd("onlgraph", 4) onlgraph(argv[2], argv[3]); end_cmd() begin_cmd("onllower", 4) onllower(argv[2], argv[3]); end_cmd() begin_cmd("onlprint", 4) onlprint(argv[2], argv[3]); end_cmd() begin_cmd("onlpunct", 4) onlpunct(argv[2], argv[3]); end_cmd() begin_cmd("onlspace", 4) onlspace(argv[2], argv[3]); end_cmd() begin_cmd("onlupper", 4) onlupper(argv[2], argv[3]); end_cmd() begin_cmd("onlxdigt", 4) onlxdigt(argv[2], argv[3]); end_cmd() begin_cmd("skpalnum", 4) skpalnum(argv[2], argv[3]); end_cmd() begin_cmd("skpalpha", 4) skpalpha(argv[2], argv[3]); end_cmd() begin_cmd("skpcntrl", 4) skpcntrl(argv[2], argv[3]); end_cmd() begin_cmd("skpdigit", 4) skpdigit(argv[2], argv[3]); end_cmd() begin_cmd("skpgraph", 4) skpgraph(argv[2], argv[3]); end_cmd() begin_cmd("skplower", 4) skplower(argv[2], argv[3]); end_cmd() begin_cmd("skpprint", 4) skpprint(argv[2], argv[3]); end_cmd() begin_cmd("skppunct", 4) skppunct(argv[2], argv[3]); end_cmd() begin_cmd("skpspace", 4) skpspace(argv[2], argv[3]); end_cmd() begin_cmd("skpupper", 4) skpupper(argv[2], argv[3]); end_cmd() begin_cmd("skpxdigt", 4) skpxdigt(argv[2], argv[3]); end_cmd() begin_cmd("ftothe", 4) ftothe(argv[2], argv[3]); end_cmd() begin_cmd("blanka", 4) blanka(argv[2], argv[3]); end_cmd() begin_cmd("unblanka", 4) unblanka(argv[2], argv[3]); end_cmd() begin_cmd("najirle", 4) najirle(argv[2], argv[3]); end_cmd() begin_cmd("unajirle", 4) unajirle(argv[2], argv[3]); end_cmd() begin_cmd("gplus", 4) a = atoi(argv[2]); b = atoi(argv[3]); gplus(a, b); end_cmd() begin_cmd("gminus", 4) a = atoi(argv[2]); b = atoi(argv[3]); gminus(a, b); end_cmd() begin_cmd("gtimes", 4) a = atoi(argv[2]); b = atoi(argv[3]); gtimes(a, b); end_cmd() begin_cmd("gdivide", 4) gdivide_a = atof(argv[2]); gdivide_b = atof(argv[3]); gdivide(gdivide_a, gdivide_b); end_cmd() begin_cmd("bytsplit", 4) bytsplit(argv[2], atol(argv[3])); end_cmd() begin_cmd("kbsplit", 4) kbsplit(argv[2], atol(argv[3])); end_cmd() begin_cmd("mbsplit", 4) mbsplit(argv[2], atol(argv[3])); end_cmd() begin_cmd("gbsplit", 4) gbsplit(argv[2], atol(argv[3])); end_cmd() begin_cmd("mjoin", 4) mjoin(argv[2], argv[3]); end_cmd() begin_cmd("listdigt", 4) listdigt(atoi(argv[2]), argv[3]); end_cmd() begin_cmd("listlowr", 4) listlowr(atoi(argv[2]), argv[3]); end_cmd() begin_cmd("listprnt", 4) listprnt(atoi(argv[2]), argv[3]); end_cmd() begin_cmd("listuppr", 4) listuppr(atoi(argv[2]), argv[3]); end_cmd() begin_cmd("charsort", 4) charsort(argv[2], argv[3]); end_cmd() begin_cmd("sp2re2sp", 4) sp2re2sp(argv[2], argv[3]); end_cmd() begin_cmd("lcvfiles", 3) lcvfiles(argv[2]); end_cmd() begin_cmd("rcvfiles", 3) rcvfiles(argv[2]); end_cmd() begin_cmd("mp3tagnf", 3) mp3info(argv[2]); end_cmd() begin_cmd("catrandl", 3) catrandl(argv[2]); end_cmd() begin_cmd("leetstr", 3) printf("\n\n"); leetstr(argv[2]); printf("\n\n"); end_cmd() begin_cmd("lcharvar", 3) lcharvar(argv[2]); end_cmd() begin_cmd("rcharvar", 3) rcharvar(argv[2]); end_cmd() begin_cmd("hexicat", 3) hexicat(argv[2]); end_cmd() begin_cmd("rndffill", 3) rndffill(argv[2]); end_cmd() begin_cmd("zerokill", 3) zerokill(argv[2]); end_cmd() begin_cmd("randkill", 3) randkill(argv[2]); end_cmd() begin_cmd("najisum", 3) najisum(argv[2]); end_cmd() begin_cmd("rndbsout", 3) rndbsout(strtoul(argv[2], NULL, 0)); end_cmd() begin_cmd("rndtsout", 3) rndtsout(strtoul(argv[2], NULL, 0)); end_cmd() begin_cmd("patch", 3) patch(argv[2]); end_cmd() begin_cmd("revcat", 3) revcat(argv[2]); end_cmd() begin_cmd("copyself", 3) copyfile(argv[0], argv[2]); end_cmd() begin_cmd("bigascii", 3) bigascii(argv[2]); end_cmd() begin_cmd("hmaker", 3) hmaker(argv[2]); end_cmd() begin_cmd("wrdcount", 3) printf("\n\n%i\n\n", wrdcount(argv[2])); end_cmd() begin_cmd("addim", 3) addim(atoi(argv[2])); end_cmd() begin_cmd("allfiles", 3) fprintf(stderr, "\n" "NOTE: On most systems you can stop with Ctrl+C\n" "WARNING: This will make a lot of files.\n" "Are you sure? type YES to continue\n" "or anything else to quit.\n" ); safegets(are_you_sure, 80); if (!strcmp(are_you_sure, "YES")) allfiles(atol(argv[2])); end_cmd(); begin_cmd("tothe", 3) tothe(argv[2]); end_cmd() begin_cmd("vowelwrd", 3) vowelwrd(argv[2]); end_cmd() begin_cmd("gigabyte", 3) gigabyte(strtoul(argv[2], NULL, 0)); end_cmd() begin_cmd("sort", 3) sort(argv[2]); end_cmd() begin_cmd("sortlast", 3) sortlast(argv[2]); end_cmd() begin_cmd("lineback", 3) lineback(argv[2]); end_cmd() begin_cmd("longline", 3) longline(argv[2]); end_cmd() begin_cmd("howline", 3) howline(argv[2]); end_cmd() begin_cmd("rndlines", 3) rndlines(argv[2]); end_cmd() begin_cmd("spyramid", 3) spyramid(argv[2]); end_cmd() } /* if (argc >= 2) */ return 0; }
void DrawCoordinateSystem::projectPoints(){ cv::Mat_<double> rvec(3,1); cv::Mat_<double> tvec(3,1); Types::HomogMatrix homogMatrix; cv::Mat_<double> rotMatrix; rotMatrix.create(3,3); // Try to read rotation and translation from rvec and tvec or homogenous matrix. if(!in_rvec.empty()&&!in_tvec.empty()){ rvec = in_rvec.read(); tvec = in_tvec.read(); } else if(!in_homogMatrix.empty()){ homogMatrix = in_homogMatrix.read(); for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { rotMatrix(i,j)=homogMatrix(i, j); } tvec(i, 0) = homogMatrix(i, 3); } Rodrigues(rotMatrix, rvec); } else return; // Get camera info properties. Types::CameraInfo camera_matrix = in_camera_matrix.read(); vector<cv::Point3f> object_points; vector<cv::Point2f> image_points; // Create four points constituting ends of three lines. object_points.push_back(cv::Point3f(0,0,0)); object_points.push_back(cv::Point3f(0.1,0,0)); object_points.push_back(cv::Point3f(0,0.1,0)); object_points.push_back(cv::Point3f(0,0,0.1)); // Project points taking into account the camera properties. if (rectified) { cv::Mat K, _r, _t; cv::decomposeProjectionMatrix(camera_matrix.projectionMatrix(), K, _r, _t); cv::projectPoints(object_points, rvec, tvec, K, cv::Mat(), image_points); } else { cv::projectPoints(object_points, rvec, tvec, camera_matrix.cameraMatrix(), camera_matrix.distCoeffs(), image_points); } // Draw lines between projected points. Types::Line ax(image_points[0], image_points[1]); ax.setCol(cv::Scalar(255, 0, 0)); Types::Line ay(image_points[0], image_points[2]); ay.setCol(cv::Scalar(0, 255, 0)); Types::Line az(image_points[0], image_points[3]); az.setCol(cv::Scalar(0, 0, 255)); // Add lines to container. Types::DrawableContainer ctr; ctr.add(ax.clone()); ctr.add(ay.clone()); ctr.add(az.clone()); CLOG(LINFO)<<"Image Points: "<<image_points; // Write output to dataports. out_csystem.write(ctr); out_impoints.write(image_points); }
virtual void SetUp() { // use a special object for source code generation using Base = double; using CGD = CG<Base>; using ADCG = AD<CGD>; using ADD = AD<Base>; std::vector<ADD> ax(n); std::vector<ADD> ay(m); for (size_t j = 0; j < n; j++) { x[j] = j + 2; ax[j] = x[j]; } // independent variables std::vector<ADCG> u(n); for (size_t j = 0; j < n; j++) { u[j] = x[j]; } CppAD::Independent(u); // dependent variable vector std::vector<ADCG> Z(m); _atomicFun = new checkpoint<double>("func", testModel, ax, ay); // the normal atomic function _cgAtomicFun = new CGAtomicFun<double>(*_atomicFun, x, true); // a wrapper used to tape with CG<Base> (*_cgAtomicFun)(u, Z); // create f: U -> Z and vectors used for derivative calculations _fun = new ADFun<CGD>(u, Z); /** * Create the dynamic library * (generate and compile source code) */ ModelCSourceGen<double> compHelp(*_fun, MODEL_NAME); compHelp.setCreateForwardZero(true); compHelp.setCreateForwardOne(true); compHelp.setCreateReverseOne(true); compHelp.setCreateReverseTwo(true); compHelp.setCreateJacobian(true); compHelp.setCreateHessian(true); compHelp.setCreateSparseJacobian(true); compHelp.setCreateSparseHessian(true); ModelLibraryCSourceGen<double> compDynHelp(compHelp); SaveFilesModelLibraryProcessor<double>::saveLibrarySourcesTo(compDynHelp, MODEL_NAME); DynamicModelLibraryProcessor<double> p(compDynHelp); GccCompiler<double> compiler; prepareTestCompilerFlags(compiler); _dynamicLib = p.createDynamicLibrary(compiler); _model = _dynamicLib->model(MODEL_NAME); _model->addAtomicFunction(*_atomicFun); }
void showbox(player& pl) { setcolor(pl.color); setfillstyle(SOLID_FILL,pl.color); bar(ax(pl), ay(pl), dx(pl), dy(pl)); }
int main( int argc, char ** argv ) { char * in_file = NULL; char * out_file = NULL; unsigned int max_it = 2000; // Max nr. of iterations bool print_input = false; bool verbose = false; int mode = MODE_PT; // 1: PocketTopo Optimize // 2: Optimize2 // 3: OptimizeBest // 4: PocketTopo Optimize with optimize_axis // 5: OptimizeBest with optimize_axis // 6: Optimize M at fixed G // 7: Optimize iterative double delta = 0.5; // required delta for OptimizeBest double error; unsigned int iter = 0; int ac = 1; while ( ac < argc ) { if ( strncmp(argv[ac],"-i",2) == 0 ) { max_it = atoi( argv[ac+1]); if ( max_it < 200 ) max_it = 200; ac += 2; #ifdef EXPERIMENTAL } else if ( strncmp(argv[ac],"-m", 2) == 0 ) { mode = atoi( argv[ac+1] ); if ( mode < MODE_PT || mode >= MODE_MAX ) mode = MODE_PT; ac += 2; } else if ( strncmp(argv[ac],"-d", 2) == 0 ) { delta = atof( argv[ac+1] ); if ( delta < 0.001 ) delta = 0.5; ac += 2; #endif } else if ( strncmp(argv[ac],"-p", 2) == 0 ) { print_input = true; ac ++; } else if ( strncmp(argv[ac],"-v", 2) == 0 ) { verbose = true; ac ++; } else if ( strncmp(argv[ac],"-h", 2) == 0 ) { usage(); ac ++; } else { break; } } if ( ac >= argc ) { usage(); return 0; } in_file = argv[ac]; ac ++; if ( argc > ac ) { out_file = argv[ac]; } if ( verbose ) { fprintf(stderr, "Calibration data file \"%s\"\n", in_file ); if ( out_file ) { fprintf(stderr, "Calibration coeff file \"%s\"\n", out_file ); } fprintf(stderr, "Max nr. iterations %d \n", max_it ); #ifdef EXPERIMENTAL fprintf(stderr, "Optimization mode: nr. %d\n", mode ); #endif } FILE * fp = fopen( in_file, "r" ); if ( fp == NULL ) { fprintf(stderr, "ERROR: cannot open input file \"%s\"\n", in_file); return 0; } Calibration calib; int16_t gx, gy, gz, mx, my, mz; int grp; int ignore; int cnt = 0; char line[256]; if ( fgets(line, 256, fp) == NULL ) { // empty file fclose( fp ); return false; } if ( line[0] == '0' && line[1] == 'x' ) { // calib-coeff format if ( verbose ) { fprintf(stderr, "Input file format: calib-coeff\n"); } int gx0, gy0, gz0, mx0, my0, mz0; // skip coeffs; for (int k=1; k<6; ++k ) fgets(line, 256, fp); // skip one more line fgets(line, 256, fp); // printf("reading after: %s\n", line); while ( fgets(line, 255, fp ) ) { // fprintf(stderr, line ); char rem[32]; if ( line[0] == '#' ) continue; sscanf( line, "G: %d %d %d M: %d %d %d %s %d %d", &gx0, &gy0, &gz0, &mx0, &my0, &mz0, rem, &grp, &ignore); gx = (int16_t)( gx0 ); gy = (int16_t)( gy0 ); gz = (int16_t)( gz0 ); mx = (int16_t)( mx0 ); my = (int16_t)( my0 ); mz = (int16_t)( mz0 ); calib.AddValues( gx, gy, gz, mx, my, mz, cnt, grp, ignore ); ++cnt; if ( verbose ) { fprintf(stderr, "%d G: %d %d %d M: %d %d %d [%d]\n", cnt, gx, gy, gz, mx, my, mz, grp ); } } } else { if ( verbose ) { fprintf(stderr, "Input file format: calib-data\n"); } rewind( fp ); unsigned int gx0, gy0, gz0, mx0, my0, mz0; while ( fgets(line, 255, fp ) ) { // fprintf(stderr, line ); if ( line[0] == '#' ) continue; sscanf( line, "%x %x %x %x %x %x %d %d", &gx0, &gy0, &gz0, &mx0, &my0, &mz0, &grp, &ignore); gx = (int16_t)( gx0 & 0xffff ); gy = (int16_t)( gy0 & 0xffff ); gz = (int16_t)( gz0 & 0xffff ); mx = (int16_t)( mx0 & 0xffff ); my = (int16_t)( my0 & 0xffff ); mz = (int16_t)( mz0 & 0xffff ); calib.AddValues( gx, gy, gz, mx, my, mz, cnt, grp, ignore ); ++cnt; if ( verbose ) { fprintf(stderr, "%d G: %d %d %d M: %d %d %d [%d]\n", cnt, gx, gy, gz, mx, my, mz, grp ); } } } fclose( fp ); if ( print_input ) { calib.PrintValues(); // { int i; scanf("%d", &i); } // calib.CheckInput(); // { int i; scanf("%d", &i); } calib.PrintGroups(); } calib.PrepareOptimize(); switch ( mode ) { case MODE_PT: iter = calib.Optimize( delta, error, max_it ); break; #ifdef EXPERIMENTAL case MODE_GRAD: iter = calib.Optimize2( delta, error, max_it ); break; case MODE_DELTA: iter = calib.OptimizeBest( delta, error, max_it ); break; case MODE_FIX_G: { // TODO set the G coeffs Vector b( 0.0037, -0.0725, -0.0300); Vector ax( 1.7678, -0.0013, 0.0119); Vector ay( -0.0023, 1.7657, -0.0016); Vector az(-0.0112, -0.0016, 1.7660); Matrix a( ax, ay, az ); iter = calib.Optimize( delta, error, max_it ); fprintf(stdout, "Iterations %d\n", iter); fprintf(stdout, "Delta %.4f\n", delta ); fprintf(stdout, "Max error %.4f\n", error ); calib.PrintCoeffs(); delta = 0.5; iter = 0; error = 0.0; calib.SetGCoeffs( a, b ); iter = calib.OptimizeM( delta, error, max_it ); } break; case MODE_ITER: /* Vector b( 0.0037, -0.0725, -0.0300); Vector ax( 1.7678, -0.0013, 0.0119); Vector ay( -0.0023, 1.7657, -0.0016); Vector az(-0.0112, -0.0016, 1.7660); Matrix a( ax, ay, az ); calib.SetGCoeffs( a, b ); */ iter = calib.OptimizeIterative( delta, error, max_it ); break; #ifdef USE_GUI case MODE_PT_DISPLAY: calib.SetShowGui( true ); iter = calib.Optimize( delta, error, max_it ); // OptimizeExp( delta, error, max_it, true ); break; case MODE_DELTA_DISPLAY: calib.SetShowGui( true ); iter = calib.OptimizeBest( delta, error, max_it, true ); break; #endif #endif // EXPERIMENTAL default: fprintf(stderr, "Unexpected calibration mode %d\n", mode ); break; } fprintf(stdout, "Iterations %d\n", iter); fprintf(stdout, "Delta %.4f\n", delta ); fprintf(stdout, "Max error %.4f\n", error ); fprintf(stderr, "M dip angle %.2f\n", calib.GetDipAngle() ); if ( verbose ) { calib.PrintCoeffs(); // calib.CheckInput(); } #if 0 unsigned char data[48]; calib.GetCoeff( data ); for (int k=0; k<48; ++k) { printf("0x%02x ", data[k] ); if ( ( k % 4 ) == 3 ) printf("\n"); } #endif if ( out_file != NULL ) { calib.PrintCalibrationFile( out_file ); } return 0; }