コード例 #1
0
ファイル: main.cpp プロジェクト: gitcrtn/render_crtn
void write_bmp(const char* imagename, ImageBuffer& buffer, const Setting& setting)
{
	unsigned int scan_line_bytes = setting.reso_w * 3;
	int file_size = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+scan_line_bytes * setting.reso_h;
	BITMAPFILEHEADER header;
	header.bfType = 'B' | ('M' << 8);
	header.bfSize = file_size;
	header.bfReserved1 = 0;
	header.bfReserved2 = 0;
	header.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
	BITMAPINFOHEADER infoHeader;
	infoHeader.biSize = sizeof(BITMAPINFOHEADER);
	infoHeader.biWidth = setting.reso_w;
	infoHeader.biHeight = setting.reso_h;
	infoHeader.biPlanes = 1;
	infoHeader.biBitCount = 24;
	infoHeader.biCompression = 0;
	infoHeader.biSizeImage = setting.reso_w * setting.reso_h * 3;
	infoHeader.biXPixPerMeter = 3780;
	infoHeader.biYPixPerMeter = 3780;
	infoHeader.biClrUsed = 0;
	infoHeader.biClrImporant = 0;
	
	FILE *fp = fopen(imagename, "wb");
	int i, j, k, index;
	unsigned char buf;

	fwrite(&header.bfType, sizeof(header.bfType), 1, fp);
	fwrite(&header.bfSize, sizeof(header.bfSize), 1, fp);
	fwrite(&header.bfReserved1, sizeof(header.bfReserved1), 1, fp);
	fwrite(&header.bfReserved2, sizeof(header.bfReserved2), 1, fp);
	fwrite(&header.bfOffBits, sizeof(header.bfOffBits), 1, fp);

	fwrite(&infoHeader.biSize, sizeof(infoHeader.biSize), 1, fp);
	fwrite(&infoHeader.biWidth, sizeof(infoHeader.biWidth), 1, fp);
	fwrite(&infoHeader.biHeight, sizeof(infoHeader.biHeight), 1, fp);
	fwrite(&infoHeader.biPlanes, sizeof(infoHeader.biPlanes), 1, fp);
	fwrite(&infoHeader.biBitCount, sizeof(infoHeader.biBitCount), 1, fp);
	fwrite(&infoHeader.biCompression, sizeof(infoHeader.biCompression), 1, fp);
	fwrite(&infoHeader.biSizeImage, sizeof(infoHeader.biSizeImage), 1, fp);
	fwrite(&infoHeader.biXPixPerMeter, sizeof(infoHeader.biXPixPerMeter), 1, fp);
	fwrite(&infoHeader.biYPixPerMeter, sizeof(infoHeader.biYPixPerMeter), 1, fp);
	fwrite(&infoHeader.biClrUsed, sizeof(infoHeader.biClrUsed), 1, fp);
	fwrite(&infoHeader.biClrImporant, sizeof(infoHeader.biClrImporant), 1, fp);

	for (i = 0; i < (int)setting.reso_h; i++)
	{

		for (j = 0; j < (int)setting.reso_w; j++) {
			index = (setting.reso_h - i - 1) * setting.reso_w + j;
			buf = f2c(buffer[index].y);
			fwrite(&buf, 1, 1, fp);
			buf = f2c(buffer[index].x);
			fwrite(&buf, 1, 1, fp);
			buf = f2c(buffer[index].z);
			fwrite(&buf, 1, 1, fp);
		}
	}
	fclose(fp);	
}
コード例 #2
0
ファイル: f2c.c プロジェクト: superizer/AUNP2015
int main(int argc, char **argv){
  double cel, fah;

  fah = 32; cel = f2c(fah);
  assert(cel == 0);

  fah = 212; cel = f2c(fah);
  assert(cel == 100);

  return 0;
}
コード例 #3
0
ファイル: main.cpp プロジェクト: gitcrtn/render_crtn
void write_ppm(const char* imagename, ImageBuffer& buffer, const Setting& setting)
{
	FILE *f;
	f = fopen(imagename, "wb");
	Imath::PackedColor packedBuf;
	fprintf(f, "P3\n%d %d\n%d\n", setting.reso_w, setting.reso_h, 255);
	for (int i = 0; i < setting.reso_w * setting.reso_h; i++){
		packedBuf = Imath::rgb2packed(buffer[i]);
		//fprintf(f, "%d %d %d ", packedBuf & 0x000000FF, (packedBuf >> 8) & 0x000000FF, (packedBuf >> 16) & 0x000000FF);
		fprintf(f, "%d %d %d ", f2c(buffer[i].x), f2c(buffer[i].y), f2c(buffer[i].z));
	}

	fclose(f);
}
コード例 #4
0
int main(int argc, char *argv[])
{
  char *flag = argv[1];
  char *tempString = argv[2];
  float celcius, farenheit;

  progname = argv[0];
  if (argc < 3) {
    usage();
  }

  if (flag[0] == 'c') {
    if (sscanf(tempString, "%f", &farenheit) != 1) {
      usage();
    }
    printf("%.2f\n", f2c(farenheit));
  } else if (flag[0] == 'f') {
    if (sscanf(tempString, "%f", &celcius) != 1) {
      usage();
    }
    printf("%.2f\n", c2f(celcius));
  } else {
    usage();
  }
  
  return 0;
}
コード例 #5
0
ファイル: rpn.c プロジェクト: 8l/bomberjacket
int main(int argc, char *argv[])
{
  jit_node_t *nc, *nf;
  pifi c2f, f2c;
  int i;

  init_jit(argv[0]);
  _jit = jit_new_state();

  nc = compile_rpn("32x9*5/+");
  nf = compile_rpn("x32-5*9/");
  (void)jit_emit();
  c2f = (pifi)jit_address(nc);
  f2c = (pifi)jit_address(nf);
  jit_clear_state();

  printf("\nC:");
  for (i = 0; i <= 100; i += 10) printf("%3d ", i);
  printf("\nF:");
  for (i = 0; i <= 100; i += 10) printf("%3d ", c2f(i));
  printf("\n");

  printf("\nF:");
  for (i = 32; i <= 212; i += 18) printf("%3d ", i);
  printf("\nC:");
  for (i = 32; i <= 212; i += 18) printf("%3d ", f2c(i));
  printf("\n");

  jit_destroy_state();
  finish_jit();
  return 0;
}
コード例 #6
0
ファイル: code5.c プロジェクト: rwttr/AUNP2015
int     main(int argc, char **argv){
        double in_tmp;
        char unit;
        if(argc ==2){ // argc begin from program name; default =1
                sscanf(argv[1], "%lf%c", &in_tmp, &unit);
                printf("%lf     %c\n",in_tmp,unit);
                
                if( unit == 'c'){
                        printf("%2.2lf c= %2.2lf f\n",in_tmp, c2f(in_tmp) );
                }
                else if( unit == 'f'){
                        printf("%2.2lf f= %2.2lf c\n",in_tmp, f2c(in_tmp) );
                }
                else{
                        printf("Wrong input format\n");
                }
        }
        else if(argc ==3){
                in_tmp = atof(argv[1]);
                if( *argv[2] == 'c'){
                        printf("%2.2lf c= %2.2lf f\n",in_tmp, c2f(in_tmp) );
                }
                else if( *argv[2] == 'f'){
                        printf("%2.2lf f= %2.2lf c\n",in_tmp, f2c(in_tmp) );
                }
                else{
                        printf("Wrong input format : second argument");
                }
        }
        else{
                printf("Wrong input format\n");
        }

        
        /*
        char input_unit, output_unit;
        double inut_temp, output_temp;
        
        printf("input unit (f/c): ");   scanf("%c", &input_unit);
        printf("output unit (f/c): ");  scanf("%c", &output_unit);
        printf("input temp: ");         scanf("%c". &input_temp);
        
        printf("Convert %lf %c to %c\n", input_temp, input_unit, output_temp);
        */
        
        return 0;
}
コード例 #7
0
void test_function() {
  function<int(int, int)> f2a;
  function<int(int, int)> f2b = add<int>();
  function<int(int, int)> f2c = add<float>();
  function<int(int, int)> f2d(f2b);
  function<int(int, int)> f2e = &add_ints;
  f2c = f2d;
  f2d = &add_ints;
  f2c(1.0, 3);
}
コード例 #8
0
ファイル: frame.cpp プロジェクト: Buanderie/rpg_svo
bool Frame::isVisible(const Vector3d& xyz_w) const
{
    Vector3d xyz_f = T_f_w_*xyz_w;
    if(xyz_f.z() < 0.0)
        return false; // point is behind the camera
    Vector2d px = f2c(xyz_f);
    if(px[0] >= 0.0 && px[1] >= 0.0 && px[0] < cam_->width() && px[1] < cam_->height())
        return true;
    return false;
}
コード例 #9
0
ファイル: f2c.c プロジェクト: dlindelof/cintro
main()
{
    int fahr, celsius;

    fahr = LOWER;
    while (fahr <= UPPER) {
        celsius = f2c(fahr);
        printf("%d\t%d\n", fahr, celsius);
        fahr = fahr + STEP;
    }
}
コード例 #10
0
ファイル: tempscacov.c プロジェクト: liangfengchen/tempscacov
int main(int argc, char* argv[])	{
	if(argc ==  2 && IsDec(argv[1]))	{
		printf("The temperature is %.2f℃\n", f2c(atof(argv[1])));		
	}
	else if(argc == 3 && IsDec(argv[2]))	{
		if( strcmp(argv[1], "f2c")==0 )
			printf("The temperature is %.2f℃\n", f2c(atof(argv[2])));
		else if( strcmp(argv[1], "c2f") ==0 )
			printf("The temperature is %.2f°F\n", c2f(atof(argv[2])));
	}
	else	{
		printf("Usage:\n");
		printf("The second argument is \"c2f\" or \"f2c\"\n");
		printf("And the third argument is a positive real number.\n");
		printf("For example:\n");
		printf("    tempscacov c2f 22\n");
		printf("    tempscacov f2c 72\n");
	}
	return 0;
}
コード例 #11
0
ファイル: temp.c プロジェクト: mildronize/my-AUNP2015
int temp(double temp_in, char temp_in_unit, double *temp_out, char temp_out_unit){
  double tmp_var;
  if(temp_in_unit == 'c'){
    tmp_var = c2f(temp_in);
  }else if( temp_in_unit == 'f'){
    tmp_var = f2c(temp_in);
  }else {
    fprintf(stderr, "Temp unit '%c' is not supported yest\n", temp_in_unit);
    return -1;
  }
  printf("input = %.2lf %c, output = %.2lf %c\n", temp_in, temp_in_unit, tmp_var, temp_out_unit);
  *temp_out = tmp_var; 
  return 0; 
}
コード例 #12
0
ファイル: a.c プロジェクト: christoffer/k-r
int main()
{
  float fahr;

  /* Table heading */
  printf("Fahrenheit  Celsius\n");

  /* Table body */
  for (fahr = 300; fahr >= 0; fahr -= 20) {
    printf("%10.2f  %7.2f\n", fahr, f2c(fahr));
  }

  return 0;
}
コード例 #13
0
ファイル: spgw.hpp プロジェクト: ZloyBabai/qpp
  void spgw_get_symmetry(generated_group<rotrans<REAL,true> > & G,
       geometry<REAL,CELL> & geom,
       REAL R = geometry<REAL,CELL>::tol_geom_default) {
    int nat = geom.size();
    auto lattice = new double[3][3]();
    auto position = new double[nat][3]();
    auto types = new int[nat]();

    get_spgdata_from_geom(geom,lattice,position,types);

    int max_size = nat*48, nsymm;
    double translation[max_size][3];
    int rotation[max_size][3][3];

    //std::cout << "before get symmetry\n";

    nsymm = spg_get_symmetry(rotation, translation, max_size, lattice, position, types, nat, R);
    matrix3<REAL> f2c,c2f;

    //std::cout << "after get symmetry\n";

    G.group.clear();

    for (int i=0; i<3; i++)
      for (int j=0; j<3; j++)
        f2c(i,j) = geom.cell(i)(j);

    c2f = f2c.inverse();

    for (int i=0; i<nsymm; i++)
      {
  //std::cout << "i= " << i << "\n";

      matrix3<REAL> rot;
      vector3<REAL> transl = {translation[i][0],translation[i][1],translation[i][2]};
      for (int j=0; j<3; j++)
  for (int k=0; k<3; k++)
    rot(j,k) = rotation[i][j][k];
      rot = f2c*rot*c2f;
      G.group.push_back(rotrans<REAL,true>(f2c*transl,rot,&geom.cell));
      }

    /*
  std::cout << "Leaving get_symmetry\n";
  for (int i=0; i<G.group.size(); i++)
  std:: cout << G.group[i] << "\n";
    */

  }
コード例 #14
0
ファイル: E1-15.c プロジェクト: DaveCprog/KandR
main()
{
	int fahr; 
	int lower, upper, step; 

	lower = 0; // lower limit of temperatur table
	upper = 300; // upper limit
	step = 20; // step size

	fahr = lower; 
	while (fahr <= upper)
	{
		printf("%d\t%d\n",fahr,f2c(fahr));
		fahr = fahr + step; 	
	}
}
コード例 #15
0
ファイル: tempc.c プロジェクト: superizer/AUNP2015
int tempc(double temp_in, char temp_in_unit, double *temp_out, char temp_out_unit){
	double t_out;

	if(temp_in_unit == 'c'){
		t_out = c2f(temp_in);
	}else if(temp_in_unit == 'f'){
		t_out = f2c(temp_in);
	}else{
		fprintf(stderr, "Temperature unit '%c' is not supported yet\n", temp_in_unit);
	}

	printf("input = %lf %c, output = %lf %c\n", temp_in, temp_in_unit, t_out, temp_out_unit);
	
	*temp_out = t_out;

	return 0;

}
コード例 #16
0
ファイル: rpnfp.c プロジェクト: pcpa/lightning
int
main ()
{
  pdfd c2f, f2c;
  double i;

  codeBuffer = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE | PROT_EXEC,
                    MAP_PRIVATE | MAP_ANON, -1, 0);
  if (codeBuffer == MAP_FAILED) {
    perror("mmap");
    exit(0);
  }

  regs[0] = JIT_FPR0;
  regs[1] = JIT_FPR1;
  regs[2] = JIT_FPR2;
  regs[3] = JIT_FPR3;
  regs[4] = JIT_FPR4;
  regs[5] = JIT_FPR5;

  jit_set_ip (codeBuffer);
  c2f = compile_rpn ("9*5/32+");
  f2c = compile_rpn ("32-5*9/");

#ifndef LIGHTNING_CROSS
  printf ("\nC:");
  for (i = 0; i <= 100; i += 10)
    printf ("%6.1f", i);
  printf ("\nF:");
  for (i = 0; i <= 100; i += 10)
    printf ("%6.1f", c2f (i));
  printf ("\n");

  printf ("\nF:");
  for (i = 32; i <= 212; i += 10)
    printf ("%6.1f", i);
  printf ("\nC:");
  for (i = 32; i <= 212; i += 10)
    printf ("%6.1f", f2c (i));
  printf ("\n");
#endif
  return 0;
}
コード例 #17
0
ファイル: rpn.c プロジェクト: pcpa/lightning
int
main ()
{
  pifi c2f, f2c;
  int i;

  codeBuffer = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE | PROT_EXEC,
                    MAP_PRIVATE | MAP_ANON, -1, 0);
  if (codeBuffer == MAP_FAILED) {
    perror("mmap");
    exit(0);
  }

  jit_set_ip (codeBuffer);
  c2f = compile_rpn ("32 x 9 * 5 / +");
  f2c = compile_rpn ("5 x 32_ + * 9 /");

#ifndef LIGHTNING_CROSS
  printf ("\nC:");
  for (i = 0; i <= 100; i += 10)
    printf ("%3d ", i);
  printf ("\nF:");
  for (i = 0; i <= 100; i += 10)
    printf ("%3d ", c2f (i));
  printf ("\n");

  printf ("\nF:");
  for (i = 32; i <= 212; i += 10)
    printf ("%3d ", i);
  printf ("\nC:");
  for (i = 32; i <= 212; i += 10)
    printf ("%3d ", f2c (i));
  printf ("\n");
#endif
  return 0;
}