// File: /workspace/github_cpp_makefile_star2_O3/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 0x4258
movq %rsi, %r15
movq %rdi, %r14
leaq 0x7449(%rip), %rsi      # 0xb559
movq %r15, %rdi
callq 0x2230
testq %rax, %rax
je 0x4269
movq %rax, %rbx
leaq 0x7632(%rip), %rdi      # 0xb75d
movl $0xb, %esi
movl $0x1, %edx
movq %rax, %rcx
callq 0x23d0
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x8ee0
movq %rsp, %rsi
leaq 0xb0(%rsp), %rdx
movq %r15, %rdi
callq 0x9180
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
leaq 0xb0(%rsp), %rdx
callq 0x9270
xorl %r15d, %r15d
leaq 0x7018(%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 0x713b(%rip), %xmm2     # 0xb2e0
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 0x41a5
cvtss2sd %xmm0, %xmm0
movq %rbx, %rdi
movq %r14, %rsi
movb $0x1, %al
callq 0x22a0
incq %r13
addq $0x8, %r12
cmpq $0x3, %r13
jne 0x4188
movl $0xa, %edi
movq %rbx, %rsi
callq 0x2250
incl %r15d
cmpl $0x8, %r15d
jne 0x417f
leaq 0x7535(%rip), %rdi      # 0xb769
movl $0x6c, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x23d0
movq %rbx, %rdi
callq 0x21f0
leaq 0x20(%rsp), %rdi
callq 0x8ef4
addq $0x100, %rsp            # imm = 0x100
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0x72eb(%rip), %rdi      # 0xb55b
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 0x8ef4
movq %rbx, %rdi
callq 0x23a0
nop