// File: /workspace/github_cpp_makefile_star2_O1/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 0x55550
movq %r15, %rdi
movq %r14, %rsi
callq 0x63f4c
testl %eax, %eax
je 0x2f519
movl 0x44(%rsp), %eax
movl %eax, 0x8(%rbx)
movl $0x1, %ebp
testl %eax, %eax
je 0x2f51b
movq %rsp, %rdi
leaq 0x30(%rsp), %rsi
callq 0x55adc
leaq 0x10(%rbx), %rdi
movq %rsp, %rsi
callq 0x850ec
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 0x2f315
shlq $0x4, %r12
leaq (%r12,%r12,2), %r12
xorl %r13d, %r13d
leaq (%r15,%r13), %rdi
callq 0x2b548
addq $0x30, %r13
cmpq %r13, %r12
jne 0x2f303
movq %r15, (%rbx)
cmpl $0x0, 0x44(%rsp)
jle 0x2f51b
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 0x2f354
movq 0x30(%rsp), %rax
movq %r14, %rdi
movq %r13, %rsi
callq *0x2b0(%rax)
leaq 0x30(%r13), %rsi
movq %r15, %rdi
callq 0x85826
movq %r15, %rdi
callq 0x8591c
ucomisd 0xaf018(%rip), %xmm0    # 0xde388
jne 0x2f383
jp 0x2f383
movq %r15, %rdi
leaq 0xb6eb2(%rip), %rsi     # 0xe6230
callq 0x85fc2
movq %r14, %rdi
movq %r13, %rsi
callq 0x56cbe
movapd %xmm0, 0x20(%rsp)
movq %r14, %rdi
movq %r13, %rsi
callq 0x5775c
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 0xaf9e3(%rip), %xmm2    # 0xdedd0
addsd 0xaed4b(%rip), %xmm2    # 0xde140
cvttsd2si %xmm2, %edx
cvtps2pd %xmm1, %xmm2
mulpd 0xaf98c(%rip), %xmm2    # 0xded90
addpd 0xaf994(%rip), %xmm2    # 0xdeda0
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 0x2f43d
jp 0x2f43d
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
ucomiss %xmm2, %xmm1
jne 0x2f43d
jp 0x2f43d
ucomiss %xmm2, %xmm0
jne 0x2f43d
jnp 0x2f441
orb $0x40, (%rcx,%rbp)
movapd 0x20(%rsp), %xmm3
movapd %xmm3, %xmm0
cmpeqsd 0xaef34(%rip), %xmm0    # 0xde388
movapd %xmm0, %xmm1
movsd 0xaf680(%rip), %xmm2    # 0xdeae0
andpd %xmm2, %xmm1
andnpd %xmm3, %xmm0
orpd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
mulsd 0xaf95c(%rip), %xmm0    # 0xdedd8
addsd 0xaecbc(%rip), %xmm0    # 0xde140
cvtsd2ss %xmm0, %xmm0
movss 0xaf958(%rip), %xmm1    # 0xdede8
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 0xaf940(%rip), %xmm1    # 0xdedf8
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 0x2f333
movl $0x1, %ebp
jmp 0x2f51b
xorl %ebp, %ebp
leaq 0x30(%rsp), %rdi
callq 0x55a7e
movl %ebp, %eax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2f551
jmp 0x2f551
jmp 0x2f551
jmp 0x2f551
movq %rax, %rbx
movq %r15, %rdi
movq %r14, %rsi
callq 0x139b0
jmp 0x2f554
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x55a7e
movq %rbx, %rdi
callq 0x138b0