// File: /workspace/github_cpp_makefile_star2_O3/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 0x13d36a(%rip), %ebx    # 0x1669e0
subl %edx, %ebx
cmpl $0x40, %edi
jle 0x296b0
addl $-0x41, %edi
cmpl $0x3d, %edi
ja 0x29bff
leaq 0xd0a60(%rip), %rax     # 0xfa0f0
movslq (%rax,%rdi,4), %rcx
addq %rax, %rcx
jmpq *%rcx
xorl %eax, %eax
cmpl $0x0, 0x1423ee(%rip)    # 0x16ba90
sete %al
movl %eax, 0x1423e5(%rip)    # 0x16ba90
jmp 0x29bff
cmpl $0x19, %edi
jle 0x29724
addl $-0x1a, %edi
cmpl $0x7, %edi
ja 0x29bff
leaq 0xd0a08(%rip), %rax     # 0xfa0d0
movslq (%rax,%rdi,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movl 0x1421ed(%rip), %eax    # 0x16b8c4
testl %eax, %eax
jle 0x29bff
movq 0x1421d2(%rip), %rcx    # 0x16b8b8
xorl %r14d, %r14d
movq (%rcx,%r14,8), %rdi
cmpl $0x4, 0x24(%rdi)
jl 0x29714
movq 0x18(%rdi), %rdx
cmpq $0x0, 0x18(%rdx)
je 0x29714
movq (%rdi), %rax
callq *0x148(%rax)
movq 0x1421aa(%rip), %rcx    # 0x16b8b8
movl 0x1421b0(%rip), %eax    # 0x16b8c4
incq %r14
movslq %eax, %rdx
cmpq %rdx, %r14
jl 0x296e9
jmp 0x29bff
cmpl $0x1, %edi
je 0x29b80
cmpl $0x4, %edi
je 0x29b2c
cmpl $0x12, %edi
jne 0x29bff
callq 0x29409
jmp 0x29bff
xorl %eax, %eax
cmpl $0x0, 0x14232e(%rip)    # 0x16ba80
sete %al
movl %eax, 0x142325(%rip)    # 0x16ba80
jmp 0x29bff
xorl %eax, %eax
cmpl $0x0, 0x13d26f(%rip)    # 0x1669d8
sete %al
movl %eax, 0x13d266(%rip)    # 0x1669d8
jmp 0x29bff
xorl %eax, %eax
cmpl $0x0, 0x142304(%rip)    # 0x16ba84
sete %al
movl %eax, 0x1422fb(%rip)    # 0x16ba84
jmp 0x29bff
xorl %eax, %eax
cmpl $0x0, 0x1422dd(%rip)    # 0x16ba74
sete %al
movl %eax, 0x1422d4(%rip)    # 0x16ba74
jmp 0x29bff
xorl %eax, %eax
cmpl $0x0, 0x1422ca(%rip)    # 0x16ba78
sete %al
movl %eax, 0x1422c1(%rip)    # 0x16ba78
jmp 0x29bff
xorl %eax, %eax
cmpl $0x0, 0x1422a3(%rip)    # 0x16ba68
sete %al
movl %eax, 0x14229a(%rip)    # 0x16ba68
jmp 0x29bff
xorl %eax, %eax
cmpl $0x0, 0x142294(%rip)    # 0x16ba70
sete %al
movl %eax, 0x14228b(%rip)    # 0x16ba70
jmp 0x29bff
xorl %eax, %eax
cmpl $0x0, 0x142299(%rip)    # 0x16ba8c
sete %al
movl %eax, 0x142290(%rip)    # 0x16ba8c
jmp 0x29bff
movl 0x13d1cd(%rip), %eax    # 0x1669d4
cmpl $0x2, %eax
je 0x29bcc
cmpl $0x1, %eax
jne 0x29bd8
movl $0x2, 0x13d1b1(%rip)    # 0x1669d4
jmp 0x29bff
xorl %eax, %eax
cmpl $0x0, 0x13d19f(%rip)    # 0x1669d0
sete %al
movl %eax, 0x13d196(%rip)    # 0x1669d0
jmp 0x29bff
xorl %eax, %eax
cmpl $0x0, 0x14221c(%rip)    # 0x16ba64
sete %al
movl %eax, 0x142213(%rip)    # 0x16ba64
jmp 0x29bff
xorl %eax, %eax
cmpl $0x0, 0x14220d(%rip)    # 0x16ba6c
sete %al
movl %eax, 0x142204(%rip)    # 0x16ba6c
jmp 0x29bff
xorl %eax, %eax
cmpl $0x0, 0x142206(%rip)    # 0x16ba7c
sete %al
movl %eax, 0x1421fd(%rip)    # 0x16ba7c
jmp 0x29bff
movslq 0x13d161(%rip), %rax    # 0x1669ec
testq %rax, %rax
js 0x29bff
movq 0x14201d(%rip), %rcx    # 0x16b8b8
movq (%rcx,%rax,8), %r14
addq $0x38, %r14
leaq 0x145656(%rip), %rdx    # 0x16ef00
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x8630e
leaq 0x1420f7(%rip), %r13    # 0x16b9b8
movq %r13, %rdi
movq %r12, %rsi
callq 0x3ad5c
leaq 0xd4415(%rip), %rdx     # 0xfdce8
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x86296
leaq 0xd439e(%rip), %rdx     # 0xfdc88
leaq 0x60(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x86296
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x3ad62
leaq 0x60(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
leaq 0x1455e6(%rip), %rdx    # 0x16ef00
callq 0x8630e
leaq 0x90(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
leaq 0xd43b4(%rip), %rdx     # 0xfdce8
callq 0x86296
leaq 0x78(%rsp), %r14
movsd 0xd0742(%rip), %xmm0    # 0xfa088
movq %r14, %rdi
movq %r12, %rsi
callq 0x88d46
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x87c5b
leaq 0x14202d(%rip), %rdi    # 0x16b998
movq %r12, %rsi
callq 0x87c7e
jmp 0x29bff
xorl %eax, %eax
cmpl $0x0, 0x142107(%rip)    # 0x16ba88
sete %al
movl %eax, 0x1420fe(%rip)    # 0x16ba88
jmp 0x29bff
leaq 0x20(%rsp), %rcx
movq $0x0, (%rcx)
movl %ebp, %edi
movl %ebx, %esi
xorl %edx, %edx
xorl %r8d, %r8d
callq 0x28cda
testl %eax, %eax
je 0x29bff
movq 0x20(%rsp), %rax
movq 0x1d0(%rax), %rsi
leaq 0xd0883(%rip), %rdi     # 0xfa247
xorl %eax, %eax
callq 0x23080
movq 0x20(%rsp), %rdi
movl $0xf8, %eax
cmpl $0x4, 0x24(%rdi)
jl 0x299f2
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, 0x13cfe2(%rip)    # 0x1669e8
movl %eax, 0x13cfe0(%rip)    # 0x1669ec
jmp 0x29bff
movsd 0x141f9f(%rip), %xmm0   # 0x16b9b8
movsd %xmm0, 0x58(%rsp)
movsd 0x141f99(%rip), %xmm0   # 0x16b9c0
movsd %xmm0, 0x50(%rsp)
movsd 0x141f93(%rip), %xmm0   # 0x16b9c8
movsd %xmm0, 0x48(%rsp)
leaq 0x141fbe(%rip), %r14    # 0x16ba00
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x88fe4
movsd (%r15), %xmm0
movsd %xmm0, 0x40(%rsp)
leaq 0x60(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x88fe4
movsd 0x8(%r15), %xmm0
movsd %xmm0, 0x38(%rsp)
leaq 0x78(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x88fe4
movsd 0x10(%r15), %xmm5
movsd 0x141f51(%rip), %xmm6   # 0x16b9e8
movsd 0x141f51(%rip), %xmm7   # 0x16b9f0
movsd 0x141f51(%rip), %xmm0   # 0x16b9f8
movsd 0x141f69(%rip), %xmm1   # 0x16ba18
movsd 0x141f69(%rip), %xmm2   # 0x16ba20
movsd %xmm2, 0x10(%rsp)
movsd %xmm1, 0x8(%rsp)
movsd %xmm0, (%rsp)
leaq 0xd0783(%rip), %rdi     # 0xfa252
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 0x29bff
movl 0x13cef1(%rip), %edx    # 0x1669f0
leal 0x1(%rdx), %eax
movl %eax, 0x13cee8(%rip)    # 0x1669f0
leaq 0x141fd1(%rip), %r14    # 0x16bae0
leaq 0xd0729(%rip), %rsi     # 0xfa23f
movq %r14, %rdi
xorl %eax, %eax
callq 0x23140
movq %r14, 0x141f71(%rip)    # 0x16ba98
jmp 0x29bff
movl 0x13ceb2(%rip), %esi    # 0x1669e4
testl %esi, %esi
js 0x29be4
leaq 0xd0807(%rip), %rdi     # 0xfa348
xorl %eax, %eax
callq 0x23080
movq 0x13c3d1(%rip), %rax    # 0x165f20
movq (%rax), %rdi
callq 0x23ac0
movslq 0x13ce86(%rip), %rax    # 0x1669e4
movq 0x141d63(%rip), %rcx    # 0x16b8c8
movq (%rcx,%rax,8), %rdi
testq %rdi, %rdi
je 0x29b74
movq (%rdi), %rax
callq *0x8(%rax)
movl $0xffffffff, 0x13ce66(%rip) # imm = 0xFFFFFFFF
jmp 0x29bff
movl 0x141d3e(%rip), %eax    # 0x16b8c4
testl %eax, %eax
jle 0x29bff
movq 0x141d27(%rip), %rcx    # 0x16b8b8
xorl %r14d, %r14d
movq (%rcx,%r14,8), %rdi
cmpl $0x4, 0x24(%rdi)
jl 0x29ba9
movq 0x18(%rdi), %rdx
cmpq $0x0, 0x18(%rdx)
jne 0x29bbf
movq (%rdi), %rax
callq *0xf8(%rax)
movq 0x141cff(%rip), %rcx    # 0x16b8b8
movl 0x141d05(%rip), %eax    # 0x16b8c4
incq %r14
movslq %eax, %rdx
cmpq %rdx, %r14
jl 0x29b94
jmp 0x29bff
movl $0x3, 0x13cdfe(%rip)    # 0x1669d4
jmp 0x29bff
movl $0x1, 0x13cdf2(%rip)    # 0x1669d4
jmp 0x29bff
leaq 0xd0c24(%rip), %rdi     # 0xfa80f
callq 0x23ee0
movq 0x13c329(%rip), %rax    # 0x165f20
movq (%rax), %rdi
callq 0x23ac0
movl %ebp, 0x141e9f(%rip)    # 0x16baa4
movl 0x13cdd5(%rip), %eax    # 0x1669e0
subl %ebx, %eax
movl %eax, 0x141e95(%rip)    # 0x16baa8
callq 0xf1aa9
movl %eax, 0x141e92(%rip)    # 0x16bab0
callq 0xecbf0
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2762c