// File: /workspace/github_cpp_makefile_star2_O3/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 0x2db8d
movq (%rbx), %rax
movq %rbx, %rdi
callq *0xc0(%rax)
leaq 0x1060d1(%rip), %rax    # 0x133c08
movsd (%rax), %xmm1
movsd 0xaf61d(%rip), %xmm2    # 0xdd160
addsd %xmm0, %xmm2
movapd 0xaf851(%rip), %xmm4    # 0xdd3a0
xorpd %xmm1, %xmm4
cmpnlesd %xmm2, %xmm4
movapd %xmm4, %xmm3
andpd %xmm0, %xmm3
cmpnlesd %xmm1, %xmm2
andpd %xmm2, %xmm0
movsd 0xaf5d7(%rip), %xmm1    # 0xdd148
andnpd %xmm1, %xmm2
orpd %xmm0, %xmm2
andnpd %xmm2, %xmm4
orpd %xmm3, %xmm4
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm4
jne 0x2db9f
jp 0x2db9f
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsd 0x80(%r14), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x2dbc3
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 0x83dd2
movq %r15, %rdi
movq %rbx, %rsi
callq 0x846d8
movq 0x98(%r14), %rdi
testq %rdi, %rdi
je 0x2dc22
movl 0xb4(%r14), %eax
testl %eax, %eax
jne 0x2dc19
movq (%rdi), %rax
movq 0x8(%rdi), %rdx
movl 0x28(%rdi), %ecx
movq %r14, %rsi
callq *0x88(%rax)
testl %eax, %eax
je 0x2dc22
movl 0xb4(%r14), %eax
incl %eax
movl %eax, 0xb4(%r14)
leaq 0x30(%r14), %rdi
leaq 0x106d9b(%rip), %r15    # 0x1349c8
leaq 0x8(%r15), %rsi
callq 0x8412a
leaq 0x48(%r14), %rdi
addq $0x20, %r15
movq %r15, %rsi
callq 0x8412a
cmpl $0x0, 0x8(%r14)
jle 0x2df2b
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 %r13, 0x18(%rsp)
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 0x83dc2
movswl -0x1f(%rbp,%r15), %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss 0xaf735(%rip), %xmm3    # 0xdd400
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 %rbx, %r13
movq %r14, %rbx
movq %r12, %r14
leaq 0x20(%rsp), %rdi
callq 0x84856
movswl -0x19(%rbp,%r15), %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss 0xaf6db(%rip), %xmm3    # 0xdd400
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 0x84856
movq %r14, %rdi
movq %rbx, %r14
movq %r13, %rbx
movq %r13, %rsi
callq 0x846d8
leaq 0x20(%rsp), %rdi
movq %r13, %rsi
callq 0x853d6
movq %r12, %rdi
movq %r13, %rsi
callq 0x853d6
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 0xaffe3(%rip), %xmm2    # 0xdddc0
addsd 0xaf353(%rip), %xmm2    # 0xdd138
cvttsd2si %xmm2, %eax
cvtps2pd %xmm1, %xmm2
mulpd 0xaff8c(%rip), %xmm2    # 0xddd80
movapd 0xaff94(%rip), %xmm3    # 0xddd90
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 0x2de33
jp 0x2de33
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
ucomiss %xmm4, %xmm1
jne 0x2de33
jp 0x2de33
ucomiss %xmm4, %xmm0
jne 0x2de33
jnp 0x2de39
orb $0x40, (%rbp,%r15)
xorps %xmm0, %xmm0
cvtsd2ss 0x80(%rsp), %xmm0
cvtpd2ps 0x70(%rsp), %xmm1
xorps %xmm2, %xmm2
cvtss2sd %xmm0, %xmm2
mulsd 0xaff66(%rip), %xmm2    # 0xdddc0
addsd 0xaf2d6(%rip), %xmm2    # 0xdd138
cvttsd2si %xmm2, %eax
cvtps2pd %xmm1, %xmm2
mulpd 0xaff0f(%rip), %xmm2    # 0xddd80
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
movq 0x18(%rsp), %r13
jne 0x2deae
jp 0x2deae
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
ucomiss %xmm4, %xmm1
jne 0x2deae
jp 0x2deae
ucomiss %xmm4, %xmm0
jne 0x2deae
jnp 0x2deb4
orb $0x1, (%rbp,%r15)
movd -0x13(%rbp,%r15), %xmm0
punpcklwd 0xaff4d(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1],xmm0[2],mem[2],xmm0[3],mem[3]
cvtdq2ps %xmm0, %xmm0
mulps 0xaf523(%rip), %xmm0    # 0xdd3f0
cvtps2pd %xmm0, %xmm0
mulpd %xmm2, %xmm0
cvtpd2ps %xmm0, %xmm0
cvtps2pd %xmm0, %xmm0
mulpd 0xafebd(%rip), %xmm0    # 0xddda0
addpd %xmm3, %xmm0
cvtpd2ps %xmm0, %xmm0
movaps 0xafebe(%rip), %xmm1    # 0xdddb0
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 0x6dd46
incq %r13
movslq 0x8(%r14), %rax
addq $0x30, %r15
cmpq %rax, %r13
jl 0x2dc76
orb $0x1, 0x89(%r14)
movq %r14, %rbx
movq 0x98(%r14), %r14
testq %r14, %r14
je 0x2db8d
movl 0xb4(%rbx), %eax
cmpl $0x1, %eax
jne 0x2df76
movq (%r14), %rax
movq 0x8(%r14), %rdx
movl 0x28(%r14), %ecx
movq %r14, %rdi
movq %rbx, %rsi
callq *0x90(%rax)
testl %eax, %eax
je 0x2db8d
movl 0xb4(%rbx), %eax
decl %eax
movl %eax, 0xb4(%rbx)
jne 0x2db8d
testb $0x2, 0x89(%rbx)
je 0x2db8d
movq (%r14), %rax
movq %r14, %rdi
movq %rbx, %rsi
callq *0x18(%rax)
movq %rbx, %rdi
callq 0x2ca06
movl $0xc8, %esi
movq %rbx, %rdi
callq 0x134f0
jmp 0x2db8d
nop