// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelBlock.cpp
// Function: gaps::R3SurfelBlock::Transform(gaps::R3Affine const&)
void R3SurfelBlock::
Transform(const R3Affine& transformation) 
{
  // Check if transformation is identity
  if (transformation.IsIdentity()) return;

  // Get scale factor
  RNScalar scale = transformation.ScaleFactor();
  if (RNIsEqual(scale, 1.0)) scale = 1.0;
  if (scale == 0) return;

  // Update resolution
  if (resolution > 0) resolution /= scale * scale;

  // Transform position_origin
  R3Point old_position_origin = position_origin;
  position_origin.Transform(transformation);

  // Read block
  if (database) database->ReadBlock(this);

  // Transform surfels 
  bbox = R3null_box;
  for (int i = 0; i < NSurfels(); i++) {
    R3Surfel *surfel = &surfels[i];
    R3Point position(surfel->X() + old_position_origin[0], surfel->Y() + old_position_origin[1], surfel->Z() + old_position_origin[2]);
    R3Vector normal(surfel->NX(), surfel->NY(), surfel->NZ());
    R3Vector tangent(surfel->TX(), surfel->TY(), surfel->TZ());
    position.Transform(transformation);
    normal.Transform(transformation);
    tangent.Transform(transformation);
    surfel->SetPosition(position.X() - position_origin.X(), position.Y() - position_origin.Y(), position.Z() - position_origin.Z());
    surfel->SetNormal(normal.X(), normal.Y(), normal.Z());
    surfel->SetTangent(tangent.X(), tangent.Y(), tangent.Z());
    surfel->SetRadius(0, scale * surfel->Radius(0));
    surfel->SetRadius(1, scale * surfel->Radius(1));
    bbox.Union(position);
  }

  // Remember that block is dirty
  SetDirty();

  // Release block
  if (database) database->ReleaseBlock(this);

  // Update database
  // ???
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq (%rsi), %rax
movq %rsi, %rdi
callq *0x10(%rax)
testl %eax, %eax
jne 0x2df53
movq (%rbx), %rax
movq %rbx, %rdi
callq *0xc0(%rax)
leaq 0x106d0b(%rip), %rax    # 0x134c08
movsd (%rax), %xmm1
movsd 0xb025f(%rip), %xmm2    # 0xde168
addsd %xmm0, %xmm2
movapd 0xb048b(%rip), %xmm4    # 0xde3a0
xorpd %xmm1, %xmm4
cmpnlesd %xmm2, %xmm4
movapd %xmm4, %xmm3
andpd %xmm0, %xmm3
cmpnlesd %xmm1, %xmm2
andpd %xmm2, %xmm0
movsd 0xb0219(%rip), %xmm1    # 0xde150
andnpd %xmm1, %xmm2
orpd %xmm0, %xmm2
andnpd %xmm2, %xmm4
orpd %xmm3, %xmm4
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm4
jne 0x2df65
jp 0x2df65
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsd 0x80(%r14), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x2df89
movapd %xmm4, %xmm1
mulsd %xmm4, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x80(%r14)
movapd %xmm4, (%rsp)
leaq 0x10(%r14), %r15
leaq 0x58(%rsp), %rdi
movq %r15, %rsi
callq 0x84d8e
movq %r15, %rdi
movq %rbx, 0x18(%rsp)
movq %rbx, %rsi
callq 0x8569a
movq 0x98(%r14), %rdi
testq %rdi, %rdi
je 0x2dfe3
cmpl $0x0, 0xb4(%r14)
jne 0x2dfdc
movq (%rdi), %rax
movq 0x8(%rdi), %rdx
movl 0x28(%rdi), %ecx
movq %r14, %rsi
callq *0x88(%rax)
testl %eax, %eax
je 0x2dfe3
incl 0xb4(%r14)
leaq 0x30(%r14), %rdi
leaq 0x1079da(%rip), %r15    # 0x1359c8
leaq 0x8(%r15), %rsi
callq 0x850ec
leaq 0x48(%r14), %rdi
addq $0x20, %r15
movq %r15, %rsi
callq 0x850ec
cmpl $0x0, 0x8(%r14)
jle 0x2e2e1
leaq 0x28(%r14), %rax
movq %rax, 0x10(%rsp)
movdqa (%rsp), %xmm0
punpcklqdq %xmm0, %xmm0    # xmm0 = xmm0[0,0]
movdqa %xmm0, (%rsp)
movl $0x2f, %r15d
xorl %r13d, %r13d
leaq 0x40(%rsp), %r12
movq (%r14), %rbp
xorps %xmm0, %xmm0
cvtss2sd -0x2f(%rbp,%r15), %xmm0
addsd 0x58(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtss2sd -0x2b(%rbp,%r15), %xmm1
addsd 0x60(%rsp), %xmm1
xorps %xmm2, %xmm2
cvtss2sd -0x27(%rbp,%r15), %xmm2
addsd 0x68(%rsp), %xmm2
movq %r12, %rdi
callq 0x84d7e
movswl -0x1f(%rbp,%r15), %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss 0xb0379(%rip), %xmm3    # 0xde400
mulss %xmm3, %xmm0
cvtss2sd %xmm0, %xmm0
movswl -0x1d(%rbp,%r15), %eax
xorps %xmm1, %xmm1
cvtsi2ss %eax, %xmm1
movswl -0x1b(%rbp,%r15), %eax
xorps %xmm2, %xmm2
cvtsi2ss %eax, %xmm2
mulss %xmm3, %xmm1
cvtss2sd %xmm1, %xmm1
mulss %xmm3, %xmm2
cvtss2sd %xmm2, %xmm2
movq %r14, %rbx
movq %r12, %r14
leaq 0x20(%rsp), %rdi
callq 0x85816
movswl -0x19(%rbp,%r15), %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss 0xb0322(%rip), %xmm3    # 0xde400
mulss %xmm3, %xmm0
cvtss2sd %xmm0, %xmm0
movswl -0x17(%rbp,%r15), %eax
xorps %xmm1, %xmm1
cvtsi2ss %eax, %xmm1
movswl -0x15(%rbp,%r15), %eax
xorps %xmm2, %xmm2
cvtsi2ss %eax, %xmm2
mulss %xmm3, %xmm1
cvtss2sd %xmm1, %xmm1
mulss %xmm3, %xmm2
cvtss2sd %xmm2, %xmm2
leaq 0x70(%rsp), %r12
movq %r12, %rdi
callq 0x85816
movq %r14, %rdi
movq %rbx, %r14
movq 0x18(%rsp), %rbx
movq %rbx, %rsi
callq 0x8569a
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x863f2
movq %r12, %rdi
movq %rbx, %rsi
callq 0x863f2
movsd 0x50(%rsp), %xmm0
subsd 0x20(%r14), %xmm0
cvtsd2ss %xmm0, %xmm0
movapd 0x40(%rsp), %xmm1
movupd 0x10(%r14), %xmm2
subpd %xmm2, %xmm1
cvtpd2ps %xmm1, %xmm1
movlpd %xmm1, -0x2f(%rbp,%r15)
movss %xmm0, -0x27(%rbp,%r15)
xorps %xmm0, %xmm0
cvtsd2ss 0x30(%rsp), %xmm0
cvtpd2ps 0x20(%rsp), %xmm1
xorps %xmm2, %xmm2
cvtss2sd %xmm0, %xmm2
mulsd 0xb0c38(%rip), %xmm2    # 0xdedd0
addsd 0xaffa0(%rip), %xmm2    # 0xde140
cvttsd2si %xmm2, %eax
cvtps2pd %xmm1, %xmm2
mulpd 0xb0be1(%rip), %xmm2    # 0xded90
movapd 0xb0be9(%rip), %xmm3    # 0xdeda0
addpd %xmm3, %xmm2
cvttpd2dq %xmm2, %xmm2
pshuflw $0xe8, %xmm2, %xmm2     # xmm2 = xmm2[0,2,2,3,4,5,6,7]
movd %xmm2, -0x1f(%rbp,%r15)
movw %ax, -0x1b(%rbp,%r15)
xorpd %xmm4, %xmm4
ucomiss %xmm4, %xmm1
jne 0x2e1ee
jp 0x2e1ee
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
ucomiss %xmm4, %xmm1
jne 0x2e1ee
jp 0x2e1ee
ucomiss %xmm4, %xmm0
jne 0x2e1ee
jnp 0x2e1f4
orb $0x40, (%rbp,%r15)
xorps %xmm0, %xmm0
cvtsd2ss 0x80(%rsp), %xmm0
cvtpd2ps 0x70(%rsp), %xmm1
xorps %xmm2, %xmm2
cvtss2sd %xmm0, %xmm2
mulsd 0xb0bbb(%rip), %xmm2    # 0xdedd0
addsd 0xaff23(%rip), %xmm2    # 0xde140
cvttsd2si %xmm2, %eax
cvtps2pd %xmm1, %xmm2
mulpd 0xb0b64(%rip), %xmm2    # 0xded90
addpd %xmm3, %xmm2
cvttpd2dq %xmm2, %xmm2
pshuflw $0xe8, %xmm2, %xmm2     # xmm2 = xmm2[0,2,2,3,4,5,6,7]
movd %xmm2, -0x19(%rbp,%r15)
movw %ax, -0x15(%rbp,%r15)
ucomiss %xmm4, %xmm1
movapd (%rsp), %xmm2
jne 0x2e264
jp 0x2e264
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
ucomiss %xmm4, %xmm1
jne 0x2e264
jp 0x2e264
ucomiss %xmm4, %xmm0
jne 0x2e264
jnp 0x2e26a
orb $0x1, (%rbp,%r15)
movd -0x13(%rbp,%r15), %xmm0
punpcklwd 0xb08c7(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1],xmm0[2],mem[2],xmm0[3],mem[3]
cvtdq2ps %xmm0, %xmm0
mulps 0xb016d(%rip), %xmm0    # 0xde3f0
cvtps2pd %xmm0, %xmm0
mulpd %xmm2, %xmm0
cvtpd2ps %xmm0, %xmm0
cvtps2pd %xmm0, %xmm0
mulpd 0xb0b17(%rip), %xmm0    # 0xdedb0
addpd %xmm3, %xmm0
cvtpd2ps %xmm0, %xmm0
movaps 0xb0b18(%rip), %xmm1    # 0xdedc0
minps %xmm0, %xmm1
cvttps2dq %xmm1, %xmm0
pshuflw $0xe8, %xmm0, %xmm0     # xmm0 = xmm0[0,2,2,3,4,5,6,7]
movd %xmm0, -0x13(%rbp,%r15)
movq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %r12
movq %r12, %rsi
callq 0x6e9a6
incq %r13
movslq 0x8(%r14), %rax
addq $0x30, %r15
cmpq %rax, %r13
jl 0x2e037
orb $0x1, 0x89(%r14)
movq %r14, %rbx
movq 0x98(%r14), %r14
testq %r14, %r14
je 0x2df53
cmpl $0x1, 0xb4(%rbx)
jne 0x2e324
movq (%r14), %rax
movq 0x8(%r14), %rdx
movl 0x28(%r14), %ecx
movq %r14, %rdi
movq %rbx, %rsi
callq *0x90(%rax)
testl %eax, %eax
je 0x2df53
decl 0xb4(%rbx)
jne 0x2df53
testb $0x2, 0x89(%rbx)
je 0x2df53
movq (%r14), %rax
movq %r14, %rdi
movq %rbx, %rsi
callq *0x18(%rax)
movq %rbx, %rdi
callq 0x2ce2e
movl $0xc8, %esi
movq %rbx, %rdi
callq 0x134f0
jmp 0x2df53
nop