Exemplo n.º 1
0
void lookat_rotate(Matrix  T, double  x, double  y, double  z, Matrix Matrix0)
{
    static Vector N, V, U;
    static Vector ep, lp;

    lp.x = x;
    lp.y = y;
    lp.z = z;
    ep.x = T[12];
    ep.y = T[13];
    ep.z = T[14];
    points_to_array(&N, &lp, &ep);
    normalize_array(&N);

    U.x = T[0];
    U.y = T[4];
    U.z = T[8];
    cross_product(&V, &N, &U);
    normalize_array(&V);

    cross_product(&U, &V, &N);
    normalize_array(&U);

    M[0] = U.x;
    M[1] = V.x;
    M[2] = N.x;
    M[3] = 0.;
    M[4] = U.y;
    M[5] = V.y;
    M[6] = N.y;
    M[7] = 0.;
    M[8] = U.z;
    M[9] = V.z;
    M[10] = N.z;
    M[11] = 0.;
#if 0
    M[12] = ep.x;
    M[13] = ep.y;
    M[14] = ep.z;
    M[15] = 1.;
#endif
#if 0
    M[12] = -U.x * ep.x - U.y * ep.y - U.z * ep.z;
    M[13] = -V.x * ep.x - V.y * ep.y - V.z * ep.z;
    M[14] = -N.x * ep.x - N.y * ep.y - N.z * ep.z;
#endif
    M[12] = ((U.x * ep.x) + (U.y * ep.y) + (U.z * ep.z));
    M[13] = ((V.x * ep.x) + (V.y * ep.y) + (V.z * ep.z));
    M[14] = ((N.x * ep.x) + (N.y * ep.y) + (N.z * ep.z));
    M[15] = 1.;

#ifdef DEBUG
    print_array(&lp, "look point");
    print_array(&ep, "eye point");
    print_array(&N, "normal array");
    print_array(&V, "V = N x U");
    print_array(&U, "U = V x N");
    print_matrix(M, "final matrix");
#endif				/* DEBUG */
}
Exemplo n.º 2
0
void lookat_rotate2(double, ex, double  ey, double  ez, double  lx, double  ly, double double, ex, double0,double, ex, double1 double, ex, double2,double, ex, double3 double, ex, double4)
{
    static Vector N, V, U;
    static Vector ep, lp;

    ep.x = ex;
    ep.y = ey;
    ep.z = ez;
    lp.x = lx;
    lp.y = ly;
    lp.z = lz;
    points_to_array(&N, &lp, &ep);
    normalize_array(&N);

    U.x = 0.;
    U.y = 1.;
    U.z = 0.;
    cross_product(&V, &N, &U);
    normalize_array(&V);

    cross_product(&U, &V, &N);
    normalize_array(&U);

    M[0] = U.x;
    M[1] = V.x;
    M[2] = N.x;
    M[3] = 0.;
    M[4] = U.y;
    M[5] = V.y;
    M[6] = N.y;
    M[7] = 0.;
    M[8] = U.z;
    M[9] = V.z;
    M[10] = N.z;
    M[11] = 0.;
#if 0
    M[12] = ep.x;
    M[13] = ep.y;
    M[14] = ep.z;
    M[15] = 1.;
#endif
#if 0
    M[12] = -U.x * ep.x - U.y * ep.y - U.z * ep.z;
    M[13] = -V.x * ep.x - V.y * ep.y - V.z * ep.z;
    M[14] = -N.x * ep.x - N.y * ep.y - N.z * ep.z;
#endif
    M[12] = ((U.x * ep.x) + (U.y * ep.y) + (U.z * ep.z));
    M[13] = ((V.x * ep.x) + (V.y * ep.y) + (V.z * ep.z));
    M[14] = ((N.x * ep.x) + (N.y * ep.y) + (N.z * ep.z));
    M[15] = 1.;

#ifdef DEBUG
    print_array(&lp, "look point");
    print_array(&ep, "eye point");
    print_array(&N, "normal array");
    print_array(&V, "V = N x U");
    print_array(&U, "U = V x N");
    print_matrix(M, "final matrix");
#endif				/* DEBUG */
}
Exemplo n.º 3
0
void optimize_picture(network *net, image orig, int max_layer, float scale, float rate, float thresh, int norm)
{
    //scale_image(orig, 2);
    //translate_image(orig, -1);
    net->n = max_layer + 1;

    int dx = rand()%16 - 8;
    int dy = rand()%16 - 8;
    int flip = rand()%2;

    image crop = crop_image(orig, dx, dy, orig.w, orig.h);
    image im = resize_image(crop, (int)(orig.w * scale), (int)(orig.h * scale));
    if(flip) flip_image(im);

    resize_network(net, im.w, im.h);
    layer_t last = net->layers[net->n-1];
    //net->layers[net->n - 1].activation = LINEAR;

    image delta = make_image(im.w, im.h, im.c);

    NETWORK_STATE(state);

#ifdef GPU
    state.input = cuda_make_array(im.data, im.w*im.h*im.c);
    state.delta = cuda_make_array(im.data, im.w*im.h*im.c);

    forward_network_gpu(*net, state);
    copy_ongpu(last.outputs, last.output_gpu, 1, last.delta_gpu, 1);

    cuda_pull_array(last.delta_gpu, last.delta, last.outputs);
    calculate_loss(last.delta, last.delta, last.outputs, thresh);
    cuda_push_array(last.delta_gpu, last.delta, last.outputs);

    backward_network_gpu(*net, state);

    cuda_pull_array(state.delta, delta.data, im.w*im.h*im.c);
    cuda_free(state.input);
    cuda_free(state.delta);
#else
    state.input = im.data;
    state.delta = delta.data;
    forward_network(*net, state);
    fltcpy(last.delta, last.output, last.outputs);
    calculate_loss(last.output, last.delta, last.outputs, thresh);
    backward_network(*net, state);
#endif

    if(flip) flip_image(delta);
    //normalize_array(delta.data, delta.w*delta.h*delta.c);
    image resized = resize_image(delta, orig.w, orig.h);
    image out = crop_image(resized, -dx, -dy, orig.w, orig.h);

    /*
       image g = grayscale_image(out);
       free_image(out);
       out = g;
     */

    //rate = rate / abs_mean(out.data, out.w*out.h*out.c);

    if(norm) normalize_array(out.data, out.w*out.h*out.c);
    fltaddmul(orig.data, out.data, orig.w * orig.h * orig.c, rate);

    /*
       normalize_array(orig.data, orig.w*orig.h*orig.c);
       scale_image(orig, sqrt(var));
       translate_image(orig, mean);
     */

    //translate_image(orig, 1);
    //scale_image(orig, .5);
    //normalize_image(orig);

    constrain_image(orig);

    free_image(crop);
    free_image(im);
    free_image(delta);
    free_image(resized);
    free_image(out);

}
Exemplo n.º 4
0
int main() {
  int i;

  for (i=0; i<20; i++) {
    a[i].var = i;
    a[i].exp = 1;
  }
  normalize_array(20);

  for (i=0; i<20; i++) {
    a[i].var = 20 - i;
    a[i].exp = 2;
  }
  normalize_array(20);

  for (i=0; i<10; i++) {
    a[i].var = 20 - i;
    a[i].exp = -i;
  }
  for (i=10; i<20; i++) {
    a[i].var = i + 1;
    a[i].exp = 19 - i;
  }
  normalize_array(20);

  normalize_array(0);
  normalize_array(1);

  a[0].var = 0;
  a[1].var = 10;
  normalize_array(2);

  a[0].var = 10;
  a[1].var = 0;
  normalize_array(2);

  for (i=0; i<40; i++) {
    a[i].var = random() % 100;
    a[i].exp = i;
  }
  normalize_array(40);

  for (i=0; i<100; i++) {
    a[i].var = random() % 100;
    a[i].exp = i;
  }
  normalize_array(100);

  for (i=0; i<100; i++) {
    a[i].var = random() % 100;
    a[i].exp = i;
  }
  normalize_array(100);

  for (i=0; i<100; i++) {
    a[i].var = random() % 100;
    a[i].exp = i;
  }
  normalize_array(100);

  for (i=0; i<100; i++) {
    a[i].var = random() % 100;
    a[i].exp = i;
  }
  normalize_array(100);

  for (i=0; i<100; i++) {
    a[i].var = random() % 100;
    a[i].exp = i;
  }
  normalize_array(100);

  for (i=0; i<100; i++) {
    a[i].var = random() % 100;
    a[i].exp = i;
  }
  normalize_array(100);

  return 0;
}