// File: /workspace/github_cpp_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
testq %rsi, %rsi
je 0x4042
movq %rsi, %r15
movq %rdi, %r14
leaq 0x65ec(%rip), %rsi      # 0xa501
movq %r15, %rdi
callq 0x2240
testq %rax, %rax
je 0x4054
movq %rax, %rbx
leaq 0x67d5(%rip), %rdi      # 0xa705
pushq $0xb
popq %rsi
pushq $0x1
popq %rdx
movq %rax, %rcx
callq 0x23e0
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x8056
movq %rsp, %rsi
leaq 0xb0(%rsp), %rdx
movq %r15, %rdi
callq 0x8258
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
leaq 0xb0(%rsp), %rdx
callq 0x833c
xorl %r15d, %r15d
pushq $0xa
popq %rbp
leaq 0x6214(%rip), %r14      # 0xa197
cmpl $0x8, %r15d
je 0x401b
pushq $0x30
popq %r13
xorl %r12d, %r12d
cmpq $0x3, %r12
je 0x4009
movsd 0x98(%rsp,%r12,8), %xmm1
movq %r13, %rax
xorl %ecx, %ecx
movsd 0x632f(%rip), %xmm2     # 0xa2e0
cvtsd2ss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
cmpq $0x3, %rcx
je 0x3ff3
btl %ecx, %r15d
movl $0x0, %edx
adcl $-0x1, %edx
orl $0x1, %edx
cvtsi2ss %edx, %xmm1
cvtss2sd %xmm1, %xmm1
mulsd 0x38(%rsp,%rcx,8), %xmm1
mulsd %xmm2, %xmm1
mulsd 0x20(%rsp,%rax), %xmm1
addsd %xmm0, %xmm1
incq %rcx
addq $0x18, %rax
jmp 0x3fb1
movq %rbx, %rdi
movq %r14, %rsi
movb $0x1, %al
callq 0x22b0
incq %r12
addq $0x8, %r13
jmp 0x3f94
movl %ebp, %edi
movq %rbx, %rsi
callq 0x2260
incl %r15d
jmp 0x3f83
leaq 0x66ef(%rip), %rdi      # 0xa711
pushq $0x6c
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x23e0
movq %rbx, %rdi
callq 0x21f0
leaq 0x20(%rsp), %rdi
callq 0x8066
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x64a8(%rip), %rdi      # 0xa503
movq %r15, %rsi
xorl %eax, %eax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2050
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x8066
movq %rbx, %rdi
callq 0x23b0
nop