// File: /workspace/github_cpp_makefile_star2_O1/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 0x13f271(%rip), %ebx    # 0x1689e0
subl %edx, %ebx
cmpl $0x40, %edi
jle 0x297a9
addl $-0x41, %edi
cmpl $0x3d, %edi
ja 0x29ce4
leaq 0xd2967(%rip), %rax     # 0xfc0f0
movslq (%rax,%rdi,4), %rcx
addq %rax, %rcx
jmpq *%rcx
xorl %eax, %eax
cmpl $0x0, 0x1442f5(%rip)    # 0x16da90
sete %al
movl %eax, 0x1442ec(%rip)    # 0x16da90
jmp 0x29ce4
cmpl $0x19, %edi
jle 0x29813
addl $-0x1a, %edi
cmpl $0x7, %edi
ja 0x29ce4
leaq 0xd290f(%rip), %rax     # 0xfc0d0
movslq (%rax,%rdi,4), %rcx
addq %rax, %rcx
jmpq *%rcx
cmpl $0x0, 0x1440f3(%rip)    # 0x16d8c4
jle 0x29ce4
xorl %r14d, %r14d
movq 0x1440d7(%rip), %rax    # 0x16d8b8
movq (%rax,%r14,8), %rdi
cmpl $0x4, 0x24(%rdi)
jl 0x297ff
movq 0x18(%rdi), %rax
cmpq $0x0, 0x18(%rax)
je 0x297ff
movq (%rdi), %rax
callq *0x148(%rax)
incq %r14
movslq 0x1440bb(%rip), %rax    # 0x16d8c4
cmpq %rax, %r14
jl 0x297da
jmp 0x29ce4
cmpl $0x1, %edi
je 0x29c6f
cmpl $0x4, %edi
je 0x29c1b
cmpl $0x12, %edi
jne 0x29ce4
callq 0x29502
jmp 0x29ce4
xorl %eax, %eax
cmpl $0x0, 0x14423f(%rip)    # 0x16da80
sete %al
movl %eax, 0x144236(%rip)    # 0x16da80
jmp 0x29ce4
xorl %eax, %eax
cmpl $0x0, 0x13f180(%rip)    # 0x1689d8
sete %al
movl %eax, 0x13f177(%rip)    # 0x1689d8
jmp 0x29ce4
xorl %eax, %eax
cmpl $0x0, 0x144215(%rip)    # 0x16da84
sete %al
movl %eax, 0x14420c(%rip)    # 0x16da84
jmp 0x29ce4
xorl %eax, %eax
cmpl $0x0, 0x1441ee(%rip)    # 0x16da74
sete %al
movl %eax, 0x1441e5(%rip)    # 0x16da74
jmp 0x29ce4
xorl %eax, %eax
cmpl $0x0, 0x1441db(%rip)    # 0x16da78
sete %al
movl %eax, 0x1441d2(%rip)    # 0x16da78
jmp 0x29ce4
xorl %eax, %eax
cmpl $0x0, 0x1441b4(%rip)    # 0x16da68
sete %al
movl %eax, 0x1441ab(%rip)    # 0x16da68
jmp 0x29ce4
xorl %eax, %eax
cmpl $0x0, 0x1441a5(%rip)    # 0x16da70
sete %al
movl %eax, 0x14419c(%rip)    # 0x16da70
jmp 0x29ce4
xorl %eax, %eax
cmpl $0x0, 0x1441aa(%rip)    # 0x16da8c
sete %al
movl %eax, 0x1441a1(%rip)    # 0x16da8c
jmp 0x29ce4
movl 0x13f0de(%rip), %eax    # 0x1689d4
cmpl $0x2, %eax
je 0x29cb1
cmpl $0x1, %eax
jne 0x29cbd
movl $0x2, 0x13f0c2(%rip)    # 0x1689d4
jmp 0x29ce4
xorl %eax, %eax
cmpl $0x0, 0x13f0b0(%rip)    # 0x1689d0
sete %al
movl %eax, 0x13f0a7(%rip)    # 0x1689d0
jmp 0x29ce4
xorl %eax, %eax
cmpl $0x0, 0x14412d(%rip)    # 0x16da64
sete %al
movl %eax, 0x144124(%rip)    # 0x16da64
jmp 0x29ce4
xorl %eax, %eax
cmpl $0x0, 0x14411e(%rip)    # 0x16da6c
sete %al
movl %eax, 0x144115(%rip)    # 0x16da6c
jmp 0x29ce4
xorl %eax, %eax
cmpl $0x0, 0x144117(%rip)    # 0x16da7c
sete %al
movl %eax, 0x14410e(%rip)    # 0x16da7c
jmp 0x29ce4
movslq 0x13f072(%rip), %rax    # 0x1689ec
testq %rax, %rax
js 0x29ce4
movq 0x143f2e(%rip), %rcx    # 0x16d8b8
movq (%rcx,%rax,8), %r14
addq $0x38, %r14
leaq 0x147567(%rip), %rdx    # 0x170f00
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x876e6
leaq 0x144008(%rip), %r13    # 0x16d9b8
movq %r13, %rdi
movq %r12, %rsi
callq 0x3b21c
leaq 0xd6336(%rip), %rdx     # 0xffcf8
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x8766e
leaq 0xd62bf(%rip), %rdx     # 0xffc98
leaq 0x60(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x8766e
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x3b222
leaq 0x60(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
leaq 0x1474f7(%rip), %rdx    # 0x170f00
callq 0x876e6
leaq 0x90(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
leaq 0xd62d5(%rip), %rdx     # 0xffcf8
callq 0x8766e
leaq 0x78(%rsp), %r14
movsd 0xd2653(%rip), %xmm0    # 0xfc088
movq %r14, %rdi
movq %r12, %rsi
callq 0x8a156
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x89039
leaq 0x143f3e(%rip), %rdi    # 0x16d998
movq %r12, %rsi
callq 0x8905c
jmp 0x29ce4
xorl %eax, %eax
cmpl $0x0, 0x144018(%rip)    # 0x16da88
sete %al
movl %eax, 0x14400f(%rip)    # 0x16da88
jmp 0x29ce4
leaq 0x20(%rsp), %rcx
movq $0x0, (%rcx)
movl %ebp, %edi
movl %ebx, %esi
xorl %edx, %edx
xorl %r8d, %r8d
callq 0x28d8e
testl %eax, %eax
je 0x29ce4
movq 0x20(%rsp), %rax
movq 0x1d0(%rax), %rsi
leaq 0xd2794(%rip), %rdi     # 0xfc247
xorl %eax, %eax
callq 0x23080
movq 0x20(%rsp), %rdi
movl $0xf8, %eax
cmpl $0x4, 0x24(%rdi)
jl 0x29ae1
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, 0x13eef3(%rip)    # 0x1689e8
movl %eax, 0x13eef1(%rip)    # 0x1689ec
jmp 0x29ce4
movsd 0x143eb0(%rip), %xmm0   # 0x16d9b8
movsd %xmm0, 0x58(%rsp)
movsd 0x143eaa(%rip), %xmm0   # 0x16d9c0
movsd %xmm0, 0x50(%rsp)
movsd 0x143ea4(%rip), %xmm0   # 0x16d9c8
movsd %xmm0, 0x48(%rsp)
leaq 0x143ecf(%rip), %r14    # 0x16da00
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x8a41c
movsd (%r15), %xmm0
movsd %xmm0, 0x40(%rsp)
leaq 0x60(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x8a41c
movsd 0x8(%r15), %xmm0
movsd %xmm0, 0x38(%rsp)
leaq 0x78(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x8a41c
movsd 0x10(%r15), %xmm5
movsd 0x143e62(%rip), %xmm6   # 0x16d9e8
movsd 0x143e62(%rip), %xmm7   # 0x16d9f0
movsd 0x143e62(%rip), %xmm0   # 0x16d9f8
movsd 0x143e7a(%rip), %xmm1   # 0x16da18
movsd 0x143e7a(%rip), %xmm2   # 0x16da20
movsd %xmm2, 0x10(%rsp)
movsd %xmm1, 0x8(%rsp)
movsd %xmm0, (%rsp)
leaq 0xd2694(%rip), %rdi     # 0xfc252
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 0x29ce4
movl 0x13ee02(%rip), %edx    # 0x1689f0
leal 0x1(%rdx), %eax
movl %eax, 0x13edf9(%rip)    # 0x1689f0
leaq 0x143ee2(%rip), %r14    # 0x16dae0
leaq 0xd263a(%rip), %rsi     # 0xfc23f
movq %r14, %rdi
xorl %eax, %eax
callq 0x23140
movq %r14, 0x143e82(%rip)    # 0x16da98
jmp 0x29ce4
movl 0x13edc3(%rip), %esi    # 0x1689e4
testl %esi, %esi
js 0x29cc9
leaq 0xd2718(%rip), %rdi     # 0xfc348
xorl %eax, %eax
callq 0x23080
movq 0x13e2e2(%rip), %rax    # 0x167f20
movq (%rax), %rdi
callq 0x23ad0
movslq 0x13ed97(%rip), %rax    # 0x1689e4
movq 0x143c74(%rip), %rcx    # 0x16d8c8
movq (%rcx,%rax,8), %rdi
testq %rdi, %rdi
je 0x29c63
movq (%rdi), %rax
callq *0x8(%rax)
movl $0xffffffff, 0x13ed77(%rip) # imm = 0xFFFFFFFF
jmp 0x29ce4
cmpl $0x0, 0x143c4e(%rip)    # 0x16d8c4
jle 0x29ce4
xorl %r14d, %r14d
movq 0x143c36(%rip), %rax    # 0x16d8b8
movq (%rax,%r14,8), %rdi
cmpl $0x4, 0x24(%rdi)
jl 0x29c97
movq 0x18(%rdi), %rax
cmpq $0x0, 0x18(%rax)
jne 0x29ca0
movq (%rdi), %rax
callq *0xf8(%rax)
incq %r14
movslq 0x143c1a(%rip), %rax    # 0x16d8c4
cmpq %rax, %r14
jl 0x29c7b
jmp 0x29ce4
movl $0x3, 0x13ed19(%rip)    # 0x1689d4
jmp 0x29ce4
movl $0x1, 0x13ed0d(%rip)    # 0x1689d4
jmp 0x29ce4
leaq 0xd2b42(%rip), %rdi     # 0xfc812
callq 0x23ef0
movq 0x13e244(%rip), %rax    # 0x167f20
movq (%rax), %rdi
callq 0x23ad0
movl %ebp, 0x143dba(%rip)    # 0x16daa4
movl 0x13ecf0(%rip), %eax    # 0x1689e0
subl %ebx, %eax
movl %eax, 0x143db0(%rip)    # 0x16daa8
callq 0xf3e60
movl %eax, 0x143dad(%rip)    # 0x16dab0
callq 0xeef18
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2765c