// File: /workspace/github_cpp_makefile_star2_O2/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 $0x98, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq (%rsi), %rax
movq %rsi, %rdi
callq *0x10(%rax)
testl %eax, %eax
jne 0x2b52d
movq (%r14), %rax
movq %r14, %rdi
callq *0xc0(%rax)
leaq 0xf99f1(%rip), %rax     # 0x124c28
movsd (%rax), %xmm1
movsd 0x9cf1d(%rip), %xmm2    # 0xc8160
addsd %xmm0, %xmm2
movapd 0x9d151(%rip), %xmm4    # 0xc83a0
xorpd %xmm1, %xmm4
cmpnlesd %xmm2, %xmm4
movapd %xmm4, %xmm3
andpd %xmm0, %xmm3
cmpnlesd %xmm1, %xmm2
andpd %xmm2, %xmm0
movsd 0x9ced7(%rip), %xmm1    # 0xc8148
andnpd %xmm1, %xmm2
orpd %xmm0, %xmm2
andnpd %xmm2, %xmm4
orpd %xmm3, %xmm4
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm4
jne 0x2b291
jnp 0x2b52d
movsd 0x80(%rbx), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x2b2b3
movapd %xmm4, %xmm1
mulsd %xmm4, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x80(%rbx)
movapd %xmm4, (%rsp)
leaq 0x10(%rbx), %r15
leaq 0x80(%rsp), %rdi
movq %r15, %rsi
callq 0x781cc
movq %r15, %rdi
movq %r14, 0x10(%rsp)
movq %r14, %rsi
callq 0x78802
movq 0x98(%rbx), %rdi
testq %rdi, %rdi
je 0x2b2f0
movq %rbx, %rsi
callq 0x20a64
leaq 0x28(%rbx), %rdi
leaq 0xfa6ed(%rip), %rsi     # 0x1259e8
movq %rdi, 0x18(%rsp)
callq 0x177ee
movdqa (%rsp), %xmm0
punpcklqdq %xmm0, %xmm0    # xmm0 = xmm0[0,0]
movdqa %xmm0, (%rsp)
xorl %r13d, %r13d
xorl %ecx, %ecx
movslq 0x8(%rbx), %rax
cmpq %rax, %rcx
jge 0x2b512
movq (%rbx), %r12
leaq (%r12,%r13), %rax
movq %rax, 0x20(%rsp)
cvtss2sd (%r12,%r13), %xmm0
addsd 0x80(%rsp), %xmm0
cvtss2sd 0x4(%r12,%r13), %xmm1
addsd 0x88(%rsp), %xmm1
cvtss2sd 0x8(%r12,%r13), %xmm2
addsd 0x90(%rsp), %xmm2
leaq 0x30(%rsp), %rbp
movq %rbp, %rdi
movq %rcx, 0x28(%rsp)
callq 0x781bc
movswl 0x10(%r12,%r13), %eax
cvtsi2ss %eax, %xmm0
movss 0x9d07c(%rip), %xmm3    # 0xc8400
mulss %xmm3, %xmm0
cvtss2sd %xmm0, %xmm0
movswl 0x12(%r12,%r13), %eax
cvtsi2ss %eax, %xmm1
movswl 0x14(%r12,%r13), %eax
cvtsi2ss %eax, %xmm2
mulss %xmm3, %xmm1
cvtss2sd %xmm1, %xmm1
mulss %xmm3, %xmm2
cvtss2sd %xmm2, %xmm2
leaq 0x68(%rsp), %r14
movq %r14, %rdi
callq 0x7897c
movswl 0x16(%r12,%r13), %eax
cvtsi2ss %eax, %xmm0
movss 0x9d031(%rip), %xmm3    # 0xc8400
mulss %xmm3, %xmm0
cvtss2sd %xmm0, %xmm0
movswl 0x18(%r12,%r13), %eax
cvtsi2ss %eax, %xmm1
movswl 0x1a(%r12,%r13), %eax
cvtsi2ss %eax, %xmm2
mulss %xmm3, %xmm1
cvtss2sd %xmm1, %xmm1
mulss %xmm3, %xmm2
cvtss2sd %xmm2, %xmm2
leaq 0x50(%rsp), %r15
movq %r15, %rdi
callq 0x7897c
movq %rbp, %rdi
movq %rbx, %rbp
movq 0x10(%rsp), %rbx
movq %rbx, %rsi
callq 0x78802
movq %r14, %rdi
movq %rbx, %rsi
callq 0x79228
movq %r15, %rdi
movq %rbx, %rsi
movq %rbp, %rbx
callq 0x79228
movsd 0x40(%rsp), %xmm0
subsd 0x20(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
movapd 0x30(%rsp), %xmm1
movupd 0x10(%rbp), %xmm2
subpd %xmm2, %xmm1
cvtpd2ps %xmm1, %xmm1
movlpd %xmm1, (%r12,%r13)
movss %xmm0, 0x8(%r12,%r13)
cvtsd2ss 0x68(%rsp), %xmm0
cvtsd2ss 0x70(%rsp), %xmm1
cvtsd2ss 0x78(%rsp), %xmm2
movq 0x20(%rsp), %r14
movq %r14, %rdi
callq 0x293b6
cvtsd2ss 0x50(%rsp), %xmm0
cvtsd2ss 0x58(%rsp), %xmm1
cvtsd2ss 0x60(%rsp), %xmm2
movq %r14, %rdi
callq 0x29418
movd 0x1c(%r12,%r13), %xmm0
punpcklwd 0x9d965(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1],xmm0[2],mem[2],xmm0[3],mem[3]
cvtdq2ps %xmm0, %xmm0
mulps 0x9cf3b(%rip), %xmm0    # 0xc83f0
cvtps2pd %xmm0, %xmm0
mulpd (%rsp), %xmm0
cvtpd2ps %xmm0, %xmm0
cvtps2pd %xmm0, %xmm0
mulpd 0x9d8d4(%rip), %xmm0    # 0xc8da0
addpd 0x9d8bc(%rip), %xmm0    # 0xc8d90
cvtpd2ps %xmm0, %xmm0
movaps 0x9d8d1(%rip), %xmm1    # 0xc8db0
minps %xmm0, %xmm1
cvttps2dq %xmm1, %xmm0
pshuflw $0xe8, %xmm0, %xmm0     # xmm0 = xmm0[0,2,2,3,4,5,6,7]
movd %xmm0, 0x1c(%r12,%r13)
movq 0x18(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x6464c
movq 0x28(%rsp), %rcx
incq %rcx
addq $0x30, %r13
jmp 0x2b318
orb $0x1, 0x89(%rbx)
movq 0x98(%rbx), %rdi
testq %rdi, %rdi
je 0x2b52d
movq %rbx, %rsi
callq 0x20aa0
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop