// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/apps/confview/confview.cpp
// Function: GLUTKeyboard(unsigned char, int, int)
void GLUTKeyboard(unsigned char key, int x, int y)
{
  // Invert y coordinate
  y = GLUTwindow_height - y;

  // Process keyboard button event
  switch (key) {
  case '~': {
    // Dump screen shot to file iX.jpg
    static char buffer[64];
    static int image_count = 1;
    sprintf(buffer, "i%d.jpg", image_count++);
    screenshot_image_name = buffer;
    break; }

  case 1: // ctrl-A
    for (int i = 0; i < configuration.NImages(); i++) {
      RGBDImage *image = configuration.Image(i);
      if (!image->DepthChannel()) image->ReadChannels();
    }
    break;

  case 26: // ctrl-Z
    for (int i = 0; i < configuration.NImages(); i++) {
      RGBDImage *image = configuration.Image(i);
      if (image->DepthChannel()) image->ReleaseChannels();
    }
    break;

  case 4: // ctrl-D
    DeleteSelectedSurface();
    break;

  case 18: // ctrl-R
    ResetViewer();
    break;

  case 'A':
  case 'a':
    show_axes = !show_axes;
    break;

  case 'B':
  case 'b':
    show_bboxes = !show_bboxes;
    break;

  case 'C':
  case 'c':
    show_cameras = !show_cameras;
    break;

  case 'D':
  case 'd':
    if (color_scheme == RGBD_PHOTO_COLOR_SCHEME) color_scheme = RGBD_RENDER_COLOR_SCHEME;
    else if (color_scheme == RGBD_RENDER_COLOR_SCHEME) color_scheme = RGBD_INDEX_COLOR_SCHEME;
    else color_scheme = RGBD_PHOTO_COLOR_SCHEME;
    break;

  case 'E':
  case 'e':
    show_edges = !show_edges;
    break;

  case 'F':
  case 'f':
    show_faces = !show_faces;
    break;

  case 'I':
  case 'i':
    show_images = !show_images;
    break;

  case 'O':
  case 'o':
    show_overlaps = !show_overlaps;
    break;

  case 'P':
  case 'p':
    show_points = !show_points;
    break;

  case 'q':
  case 'Q':
    show_quads = !show_quads;
    break;

  case 's':
  case 'S':
    show_surfels = !show_surfels;
    break;

  case 'T':
  case 't':
    show_textures = !show_textures;
    break;

  case 'V':
  case 'v':
    show_vertices = !show_vertices;
    break;
      
  case 'W':
  case 'w':
    if (snap_image_index >= 0) {
      RGBDImage *snap_image = configuration.Image(snap_image_index);
      viewer.RepositionCamera(snap_image->WorldViewpoint());
      viewer.ReorientCamera(snap_image->WorldTowards(), snap_image->WorldUp());
      center = snap_image->WorldViewpoint() + 3 * snap_image->WorldTowards();
    }
    break;
      
  case 'Y':
  case 'y':
    show_selected_position = !show_selected_position;
    break;

  case 'Z':
  case 'z':
    show_patches = !show_patches;
    break;

  case ' ': {
    RGBDImage *selected_image = NULL;
    if (Pick(x, y, NULL, &selected_image)) {
      printf("Picked %s\n", selected_image->Name());
      if (!selected_image->DepthChannel()) selected_image->ReadChannels();
      else selected_image->ReleaseChannels();
      selected_image_index = selected_image->ConfigurationIndex();
      snap_image_index = selected_image_index;
    }
    break; }

  case '!': {
    // Print camera
    const R3Camera& camera = viewer.Camera();
    printf("%g %g %g  %g %g %g  %g %g %g  %g %g  1\n",
           camera.Origin().X(), camera.Origin().Y(), camera.Origin().Z(),
           camera.Towards().X(), camera.Towards().Y(), camera.Towards().Z(),
           camera.Up().X(), camera.Up().Y(), camera.Up().Z(),
           camera.XFOV(), camera.YFOV());
    break; }

  case 27: // ESCAPE
    GLUTStop();
    break;
  }

  // Remember mouse position 
  GLUTmouse[0] = x;
  GLUTmouse[1] = GLUTwindow_height - y;

  // Remember modifiers 
  GLUTmodifiers = glutGetModifiers();

  // Redraw
  glutPostRedisplay();  
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %esi, %ebp
movl 0x12d1a1(%rip), %ebx    # 0x155a00
subl %edx, %ebx
leal -0x41(%rdi), %eax
cmpl $0x3d, %eax
ja 0x28890
leaq 0xb9880(%rip), %rcx     # 0xe20f0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
xorl %eax, %eax
cmpl $0x0, 0x13222e(%rip)    # 0x15aab0
sete %al
movl %eax, 0x132225(%rip)    # 0x15aab0
jmp 0x28d90
leal -0x1a(%rdi), %eax
cmpl $0x7, %eax
ja 0x288ed
leaq 0xb9831(%rip), %rcx     # 0xe20d0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x132036(%rip), %eax    # 0x15a8e4
xorl %r14d, %r14d
movslq %eax, %rcx
cmpq %rcx, %r14
jge 0x28d90
movq 0x132014(%rip), %rcx    # 0x15a8d8
movq (%rcx,%r14,8), %rdi
cmpl $0x4, 0x24(%rdi)
jl 0x288e8
movq 0x18(%rdi), %rcx
cmpq $0x0, 0x18(%rcx)
je 0x288e8
movq (%rdi), %rax
callq *0x148(%rax)
movl 0x131ffc(%rip), %eax    # 0x15a8e4
incq %r14
jmp 0x288b1
cmpl $0x1, %edi
je 0x28ccb
cmpl $0x4, %edi
je 0x28d10
cmpl $0x12, %edi
jne 0x28d90
callq 0x28695
jmp 0x28d90
xorl %eax, %eax
cmpl $0x0, 0x132181(%rip)    # 0x15aa9c
sete %al
movl %eax, 0x132178(%rip)    # 0x15aa9c
jmp 0x28d90
xorl %eax, %eax
cmpl $0x0, 0x12d0c6(%rip)    # 0x1559f8
sete %al
movl %eax, 0x12d0bd(%rip)    # 0x1559f8
jmp 0x28d90
xorl %eax, %eax
cmpl $0x0, 0x13215b(%rip)    # 0x15aaa4
sete %al
movl %eax, 0x132152(%rip)    # 0x15aaa4
jmp 0x28d90
xorl %eax, %eax
cmpl $0x0, 0x132148(%rip)    # 0x15aaa8
sete %al
movl %eax, 0x13213f(%rip)    # 0x15aaa8
jmp 0x28d90
xorl %eax, %eax
cmpl $0x0, 0x132119(%rip)    # 0x15aa90
sete %al
movl %eax, 0x132110(%rip)    # 0x15aa90
jmp 0x28d90
movslq 0x12d080(%rip), %rax    # 0x155a0c
testq %rax, %rax
js 0x28d90
movq 0x131f3c(%rip), %rcx    # 0x15a8d8
movq (%rcx,%rax,8), %r14
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x29e3e
leaq 0x132021(%rip), %r12    # 0x15a9d8
movq %r12, %rdi
movq %r15, %rsi
callq 0x38c18
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x29e58
leaq 0x60(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0x29e72
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x38c1e
leaq 0x60(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x29e3e
leaq 0x90(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x29e58
leaq 0x78(%rsp), %r14
movsd 0xb9668(%rip), %xmm0    # 0xe2088
movq %r14, %rdi
movq %r12, %rsi
callq 0x7d76a
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x7cb7b
leaq 0x131f73(%rip), %rdi    # 0x15a9b8
movq %r12, %rsi
callq 0x7cb9e
jmp 0x28d90
xorl %eax, %eax
cmpl $0x0, 0x132051(%rip)    # 0x15aaac
sete %al
movl %eax, 0x132048(%rip)    # 0x15aaac
jmp 0x28d90
xorl %eax, %eax
cmpl $0x0, 0x12cf7e(%rip)    # 0x1559f0
sete %al
movl %eax, 0x12cf75(%rip)    # 0x1559f0
jmp 0x28d90
xorl %eax, %eax
cmpl $0x0, 0x132017(%rip)    # 0x15aaa0
sete %al
movl %eax, 0x13200e(%rip)    # 0x15aaa0
jmp 0x28d90
movl 0x12cf57(%rip), %eax    # 0x1559f4
cmpl $0x2, %eax
je 0x28d5d
cmpl $0x1, %eax
jne 0x28d69
movl $0x2, 0x12cf3b(%rip)    # 0x1559f4
jmp 0x28d90
xorl %eax, %eax
cmpl $0x0, 0x131fcd(%rip)    # 0x15aa94
sete %al
movl %eax, 0x131fc4(%rip)    # 0x15aa94
jmp 0x28d90
xorl %eax, %eax
cmpl $0x0, 0x131faa(%rip)    # 0x15aa88
sete %al
movl %eax, 0x131fa1(%rip)    # 0x15aa88
jmp 0x28d90
xorl %eax, %eax
cmpl $0x0, 0x131f8f(%rip)    # 0x15aa84
sete %al
movl %eax, 0x131f86(%rip)    # 0x15aa84
jmp 0x28d90
xorl %eax, %eax
cmpl $0x0, 0x131f8c(%rip)    # 0x15aa98
sete %al
movl %eax, 0x131f83(%rip)    # 0x15aa98
jmp 0x28d90
xorl %eax, %eax
cmpl $0x0, 0x131f69(%rip)    # 0x15aa8c
sete %al
movl %eax, 0x131f60(%rip)    # 0x15aa8c
jmp 0x28d90
movsd 0x131e9f(%rip), %xmm0   # 0x15a9d8
movsd %xmm0, 0x58(%rsp)
movsd 0x131e99(%rip), %xmm0   # 0x15a9e0
movsd %xmm0, 0x50(%rsp)
movsd 0x131e93(%rip), %xmm0   # 0x15a9e8
movsd %xmm0, 0x48(%rsp)
leaq 0x131ebe(%rip), %r14    # 0x15aa20
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x7d9da
movsd (%r15), %xmm0
movsd %xmm0, 0x40(%rsp)
leaq 0x60(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x7d9da
movsd 0x8(%r15), %xmm0
movsd %xmm0, 0x38(%rsp)
leaq 0x78(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x7d9da
movsd 0x10(%r15), %xmm5
movsd 0x131e51(%rip), %xmm6   # 0x15aa08
movsd 0x131e51(%rip), %xmm7   # 0x15aa10
movsd 0x131e51(%rip), %xmm0   # 0x15aa18
movsd 0x131e69(%rip), %xmm1   # 0x15aa38
movsd 0x131e69(%rip), %xmm2   # 0x15aa40
movsd %xmm2, 0x10(%rsp)
movsd %xmm1, 0x8(%rsp)
movsd %xmm0, (%rsp)
leaq 0xb9663(%rip), %rdi     # 0xe2252
movsd 0x58(%rsp), %xmm0
movsd 0x50(%rsp), %xmm1
movsd 0x48(%rsp), %xmm2
movsd 0x40(%rsp), %xmm3
movsd 0x38(%rsp), %xmm4
movb $0x8, %al
callq 0x23080
jmp 0x28d90
leaq 0x20(%rsp), %rcx
andq $0x0, (%rcx)
movl %ebp, %edi
movl %ebx, %esi
xorl %edx, %edx
xorl %r8d, %r8d
callq 0x28011
testl %eax, %eax
je 0x28d90
movq 0x20(%rsp), %rax
movq 0x1d0(%rax), %rsi
leaq 0xb95fc(%rip), %rdi     # 0xe2247
xorl %eax, %eax
callq 0x23080
movq 0x20(%rsp), %rdi
movl $0xf8, %eax
cmpl $0x4, 0x24(%rdi)
jl 0x28c79
movq 0x18(%rdi), %rax
cmpq $0x0, 0x18(%rax)
movl $0xf8, %ecx
movl $0x148, %eax            # imm = 0x148
cmoveq %rcx, %rax
movq (%rdi), %rcx
callq *(%rcx,%rax)
movq 0x20(%rsp), %rax
movl 0x10(%rax), %eax
movl %eax, 0x12cd7b(%rip)    # 0x155a08
movl %eax, 0x12cd79(%rip)    # 0x155a0c
jmp 0x28d90
movl 0x12cd72(%rip), %edx    # 0x155a10
leal 0x1(%rdx), %eax
movl %eax, 0x12cd69(%rip)    # 0x155a10
leaq 0x131e52(%rip), %r14    # 0x15ab00
leaq 0xb958a(%rip), %rsi     # 0xe223f
movq %r14, %rdi
xorl %eax, %eax
callq 0x23140
movq %r14, 0x131df2(%rip)    # 0x15aab8
jmp 0x28d90
movl 0x131c13(%rip), %eax    # 0x15a8e4
xorl %r14d, %r14d
movslq %eax, %rcx
cmpq %rcx, %r14
jge 0x28d90
movq 0x131bf1(%rip), %rcx    # 0x15a8d8
movq (%rcx,%r14,8), %rdi
cmpl $0x4, 0x24(%rdi)
jl 0x28cfc
movq 0x18(%rdi), %rcx
cmpq $0x0, 0x18(%rcx)
jne 0x28d0b
movq (%rdi), %rax
callq *0xf8(%rax)
movl 0x131bd9(%rip), %eax    # 0x15a8e4
incq %r14
jmp 0x28cd4
movl 0x12ccee(%rip), %esi    # 0x155a04
testl %esi, %esi
js 0x28d75
leaq 0xb9627(%rip), %rdi     # 0xe2348
xorl %eax, %eax
callq 0x23080
movq 0x12c211(%rip), %rax    # 0x154f40
movq (%rax), %rdi
callq 0x23ac0
movslq 0x12ccc6(%rip), %rax    # 0x155a04
movq 0x131ba3(%rip), %rcx    # 0x15a8e8
movq (%rcx,%rax,8), %rdi
testq %rdi, %rdi
je 0x28d54
movq (%rdi), %rax
callq *0x8(%rax)
orl $-0x1, 0x12cca9(%rip)   # 0x155a04
jmp 0x28d90
movl $0x3, 0x12cc8d(%rip)    # 0x1559f4
jmp 0x28d90
movl $0x1, 0x12cc81(%rip)    # 0x1559f4
jmp 0x28d90
leaq 0xb9a93(%rip), %rdi     # 0xe280f
callq 0x23f00
movq 0x12c1b8(%rip), %rax    # 0x154f40
movq (%rax), %rdi
callq 0x23ac0
movl %ebp, 0x131d2e(%rip)    # 0x15aac4
movl 0x12cc64(%rip), %eax    # 0x155a00
subl %ebx, %eax
movl %eax, 0x131d24(%rip)    # 0x15aac8
callq 0xda0ca
movl %eax, 0x131d21(%rip)    # 0x15aad0
callq 0xd562c
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x26a0c