// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelBlock.cpp
// Function: gaps::R3SurfelBlock::ReadPly(_IO_FILE*)
int R3SurfelBlock::
ReadPly(FILE *fp)
{
  // Read into mesh
  R3Mesh mesh;
  if (!mesh.ReadPlyStream(fp)) return 0;

  // Determine the number of surfels
  nsurfels = mesh.NVertices();
  if (nsurfels == 0) return 1;

  // Determine position origin
  position_origin = mesh.Centroid();

  // Allocate array of surfels
  surfels = new R3Surfel [ nsurfels ];
  if (!surfels) {
    RNFail("Unable to allocate surfels\n");
    return 0;
  }

  // Fill array of surfels
  for (int i = 0; i < mesh.NVertices(); i++) {
    R3MeshVertex *vertex = mesh.Vertex(i);
    const R3Point& position = mesh.VertexPosition(vertex);
    R3Vector normal = mesh.VertexNormal(vertex);
    if (normal.Length() == 0) normal = R3posz_vector;
    const RNRgb& color = mesh.VertexColor(vertex);
    RNLength radius = mesh.VertexAverageEdgeLength(vertex);
    if (radius == 0) radius = 0.01;
    RNBoolean boundary = mesh.IsVertexOnBoundary(vertex);
    float x = (float) (position.X() - position_origin.X());
    float y = (float) (position.Y() - position_origin.Y());
    float z = (float) (position.Z() - position_origin.Z());
    surfels[i].SetPosition(x, y, z);
    surfels[i].SetNormal(normal.X(), normal.Y(), normal.Z());
    surfels[i].SetRadius(radius);
    surfels[i].SetIdentifier(i+1);
    surfels[i].SetColor(color);
    surfels[i].SetBorderBoundary(boundary);
    surfels[i].SetAerial(FALSE);
  }

  // Return success
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x30(%rsp), %r15
movq %r15, %rdi
callq 0x54af4
movq %r15, %rdi
movq %r14, %rsi
callq 0x6335e
testl %eax, %eax
je 0x2f1a7
movl 0x44(%rsp), %eax
movl %eax, 0x8(%rbx)
movl $0x1, %ebp
testl %eax, %eax
je 0x2f1a9
movq %rsp, %rdi
leaq 0x30(%rsp), %rsi
callq 0x55090
leaq 0x10(%rbx), %rdi
movq %rsp, %rsi
callq 0x8412a
movslq 0x8(%rbx), %r12
movl $0x30, %ecx
movq %r12, %rax
mulq %rcx
movq $-0x1, %r14
cmovnoq %rax, %r14
movq %r14, %rdi
callq 0x13030
movq %rax, %r15
testl %r12d, %r12d
je 0x2efa3
shlq $0x4, %r12
leaq (%r12,%r12,2), %r12
xorl %r13d, %r13d
leaq (%r15,%r13), %rdi
callq 0x2b118
addq $0x30, %r13
cmpq %r13, %r12
jne 0x2ef91
movq %r15, (%rbx)
cmpl $0x0, 0x44(%rsp)
jle 0x2f1a9
movl $0x2f, %ebp
xorl %r12d, %r12d
leaq 0x30(%rsp), %r14
movq %rsp, %r15
movq 0x38(%rsp), %rax
movq (%rax,%r12,8), %r13
testb $0x2, 0x78(%r13)
jne 0x2efe2
movq 0x30(%rsp), %rax
movq %r14, %rdi
movq %r13, %rsi
callq *0x2b0(%rax)
leaq 0x30(%r13), %rsi
movq %r15, %rdi
callq 0x84866
movq %r15, %rdi
callq 0x8495c
ucomisd 0xae38a(%rip), %xmm0    # 0xdd388
jne 0x2f011
jp 0x2f011
movq %r15, %rdi
leaq 0xb620c(%rip), %rsi     # 0xe5218
callq 0x84fe2
movq %r14, %rdi
movq %r13, %rsi
callq 0x5631a
movapd %xmm0, 0x20(%rsp)
movq %r14, %rdi
movq %r13, %rsi
callq 0x56d98
movsd 0x28(%r13), %xmm0
subsd 0x20(%rbx), %xmm0
cvtsd2ss %xmm0, %xmm0
movq (%rbx), %rcx
movupd 0x18(%r13), %xmm1
movupd 0x10(%rbx), %xmm2
subpd %xmm2, %xmm1
cvtpd2ps %xmm1, %xmm1
movlpd %xmm1, -0x2f(%rcx,%rbp)
movss %xmm0, -0x27(%rcx,%rbp)
xorps %xmm0, %xmm0
cvtsd2ss 0x10(%rsp), %xmm0
cvtpd2ps (%rsp), %xmm1
xorps %xmm2, %xmm2
cvtss2sd %xmm0, %xmm2
mulsd 0xaed45(%rip), %xmm2    # 0xdddc0
addsd 0xae0b5(%rip), %xmm2    # 0xdd138
cvttsd2si %xmm2, %edx
cvtps2pd %xmm1, %xmm2
mulpd 0xaecee(%rip), %xmm2    # 0xddd80
addpd 0xaecf6(%rip), %xmm2    # 0xddd90
cvttpd2dq %xmm2, %xmm2
pshuflw $0xe8, %xmm2, %xmm2     # xmm2 = xmm2[0,2,2,3,4,5,6,7]
movd %xmm2, -0x1f(%rcx,%rbp)
movw %dx, -0x1b(%rcx,%rbp)
pxor %xmm2, %xmm2
ucomiss %xmm2, %xmm1
jne 0x2f0cb
jp 0x2f0cb
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
ucomiss %xmm2, %xmm1
jne 0x2f0cb
jp 0x2f0cb
ucomiss %xmm2, %xmm0
jne 0x2f0cb
jnp 0x2f0cf
orb $0x40, (%rcx,%rbp)
movapd 0x20(%rsp), %xmm3
movapd %xmm3, %xmm0
cmpeqsd 0xae2a6(%rip), %xmm0    # 0xdd388
movapd %xmm0, %xmm1
movsd 0xae9f2(%rip), %xmm2    # 0xddae0
andpd %xmm2, %xmm1
andnpd %xmm3, %xmm0
orpd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
mulsd 0xaecbe(%rip), %xmm0    # 0xdddc8
addsd 0xae026(%rip), %xmm0    # 0xdd138
cvtsd2ss %xmm0, %xmm0
movss 0xaecba(%rip), %xmm1    # 0xdddd8
minss %xmm0, %xmm1
cvttss2si %xmm1, %edx
movw %dx, -0x13(%rcx,%rbp)
movw %dx, -0x11(%rcx,%rbp)
incq %r12
movl %r12d, -0xf(%rcx,%rbp)
movsd 0x58(%r13), %xmm0
movsd 0xaeca2(%rip), %xmm1    # 0xddde8
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %edx
movb %dl, -0x3(%rcx,%rbp)
movsd 0x60(%r13), %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %edx
movb %dl, -0x2(%rcx,%rbp)
movsd 0x68(%r13), %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %edx
movb %dl, -0x1(%rcx,%rbp)
movq (%rbx), %rcx
movb (%rcx,%rbp), %dl
andb $-0x33, %dl
testl %eax, %eax
movl $0x30, %esi
cmovnel %esi, %eax
orb %dl, %al
movb %al, (%rcx,%rbp)
movslq 0x44(%rsp), %rax
addq $0x30, %rbp
cmpq %rax, %r12
jl 0x2efc1
movl $0x1, %ebp
jmp 0x2f1a9
xorl %ebp, %ebp
leaq 0x30(%rsp), %rdi
callq 0x55032
movl %ebp, %eax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2f1df
jmp 0x2f1df
jmp 0x2f1df
jmp 0x2f1df
movq %rax, %rbx
movq %r15, %rdi
movq %r14, %rsi
callq 0x139b0
jmp 0x2f1e2
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x55032
movq %rbx, %rdi
callq 0x138b0