// File: /workspace/github_cpp_makefile_star2_O1/jingdao[P]PointCloudApp/pcd.cpp
// Function: PCD::writeToOFF(char const*)
void PCD::writeToOFF(const char* filename) {
	if (!filename)
		return;
	FILE* f = fopen(filename, "w");
	if (!f) {
		printf("Cannot write to file: %s\n", filename);
		return;
	}

	fprintf(f,"OFF\n8 6 12\n");
#define USE_OBB 1
#if USE_OBB
	Descriptor d(this);
	double lambda[3], v[9];
	d.getPCA_XY(lambda,v);
	d.setPCA(lambda,v);
	for (int i=0;i<8;i++) {
		float coords[3];
		for (int j=0;j<3;j++) {
			coords[j] = d.bbCenter[j];
			for (int axis=0;axis<3;axis++) {
				float sign = (i & 1<<axis) ? 1 : -1;
				coords[j] += sign * d.principalLengths[axis] / 2 * d.principalAxes[axis][j];
			}
			fprintf(f,"%f ",coords[j]);
		}
		fprintf(f,"\n");
	}
#else
	if (!kdtree) kdtree = new KdTree(this);
	KdTree::Cube bb = kdtree->getBoundingBox();
	fprintf(f,"%f %f %f\n",bb.x1,bb.y1,bb.z1);
	fprintf(f,"%f %f %f\n",bb.x2,bb.y1,bb.z1);
	fprintf(f,"%f %f %f\n",bb.x1,bb.y2,bb.z1);
	fprintf(f,"%f %f %f\n",bb.x2,bb.y2,bb.z1);
	fprintf(f,"%f %f %f\n",bb.x1,bb.y1,bb.z2);
	fprintf(f,"%f %f %f\n",bb.x2,bb.y1,bb.z2);
	fprintf(f,"%f %f %f\n",bb.x1,bb.y2,bb.z2);
	fprintf(f,"%f %f %f\n",bb.x2,bb.y2,bb.z2);
#endif
	fprintf(f,"4 0 1 3 2 1 0 0 0\n"
	"4 0 4 5 1 0 1 0 0\n"
	"4 0 2 6 4 1 0 0 0\n"
	"4 1 3 7 5 0 1 0 0\n"
	"4 2 6 7 3 1 0 0 0\n"
	"4 4 5 7 6 0 1 0 0\n");
	fclose(f);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x100, %rsp            # imm = 0x100
testq %rsi, %rsi
je 0x4288
movq %rsi, %r15
movq %rdi, %r14
leaq 0x7349(%rip), %rsi      # 0xb489
movq %r15, %rdi
callq 0x2230
testq %rax, %rax
je 0x4299
movq %rax, %rbx
leaq 0x7532(%rip), %rdi      # 0xb68d
movl $0xb, %esi
movl $0x1, %edx
movq %rax, %rcx
callq 0x23e0
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x8efc
movq %rsp, %rsi
leaq 0xb0(%rsp), %rdx
movq %r15, %rdi
callq 0x919c
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
leaq 0xb0(%rsp), %rdx
callq 0x92b6
xorl %r15d, %r15d
leaq 0x6fe8(%rip), %r14      # 0xb197
movl $0x30, %r12d
xorl %r13d, %r13d
xorps %xmm0, %xmm0
cvtsd2ss 0x98(%rsp,%r13,8), %xmm0
movl $0x3, %eax
movq %r12, %rcx
movsd 0x7113(%rip), %xmm2     # 0xb2e8
leal -0x3(%rax), %edx
movzbl %dl, %edx
btl %edx, %r15d
movl $0x0, %edx
adcl $-0x1, %edx
orl $0x1, %edx
xorps %xmm1, %xmm1
cvtsi2ss %edx, %xmm1
cvtss2sd %xmm1, %xmm1
mulsd 0x20(%rsp,%rax,8), %xmm1
mulsd %xmm2, %xmm1
mulsd 0x20(%rsp,%rcx), %xmm1
cvtss2sd %xmm0, %xmm0
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
incq %rax
addq $0x18, %rcx
cmpq $0x6, %rax
jne 0x41d5
cvtss2sd %xmm0, %xmm0
movq %rbx, %rdi
movq %r14, %rsi
movb $0x1, %al
callq 0x22a0
incq %r13
addq $0x8, %r12
cmpq $0x3, %r13
jne 0x41b8
movl $0xa, %edi
movq %rbx, %rsi
callq 0x2250
incl %r15d
cmpl $0x8, %r15d
jne 0x41af
leaq 0x7435(%rip), %rdi      # 0xb699
movl $0x6c, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x23e0
movq %rbx, %rdi
callq 0x21f0
leaq 0x20(%rsp), %rdi
callq 0x8f10
addq $0x100, %rsp            # imm = 0x100
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0x71eb(%rip), %rdi      # 0xb48b
movq %r15, %rsi
xorl %eax, %eax
addq $0x100, %rsp            # imm = 0x100
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x2050
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x8f10
movq %rbx, %rdi
callq 0x23a0
nop