// File: jingdao[P]PointCloudApp/pcd.cpp
// Function: PCD::loadDescriptor(char const*)
void PCD::loadDescriptor(const char* filename) {
	FILE* f = fopen(filename,"r");
	if (!f) {
		printf("File not found: %s\n", filename);
		return;
	}
	char buf[256];
	int numDescriptors=0,count=0;
	while (fgets(buf, 256, f)) {
		if (sscanf(buf, "POINTS %d", &numDescriptors) == 1) {
			if (numDescriptors!=numPoints) {
				printf("Number of descriptors does not match number of points!\n");
				return;
			}
		} else if (sscanf(buf,"COUNT %d",&count)==1) {
		} else if (strncmp(buf,"DATA ascii",10)==0) 
			break;
	}
	float val,sum,maxSum=0;
	char* c;
	float* values = new float[numDescriptors];
	for (int i=0;i<numDescriptors;i++) {
		fgets(buf,256,f);
		sum=0;
		c = buf;
		for (int j=0;j<count;j++) {
			val = strtod(c,&c);
			sum += val * val;
		}
		values[i] = sum;
		if (sum > maxSum) maxSum = sum;
	}
	for (int i=0;i<numDescriptors;i++) {
		values[i] /= maxSum;
		float_data[i * 4 + 3] = colormap(values[i]);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x160(%rbp)
movq -0x10(%rbp), %rdi
leaq 0xefa3(%rip), %rsi      # 0x1378c
callq 0x2230
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x4810
movq -0x10(%rbp), %rsi
leaq 0xebac(%rip), %rdi      # 0x133b0
movb $0x0, %al
callq 0x2050
jmp 0x4aa0
movl $0x0, -0x124(%rbp)
movl $0x0, -0x128(%rbp)
leaq -0x120(%rbp), %rdi
movq -0x18(%rbp), %rdx
movl $0x100, %esi            # imm = 0x100
callq 0x2300
cmpq $0x0, %rax
je 0x48d6
leaq -0x120(%rbp), %rdi
leaq 0xeb73(%rip), %rsi      # 0x133c4
leaq -0x124(%rbp), %rdx
movb $0x0, %al
callq 0x21e0
cmpl $0x1, %eax
jne 0x488b
movq -0x160(%rbp), %rcx
movl -0x124(%rbp), %eax
cmpl 0x60(%rcx), %eax
je 0x4889
leaq 0xebb3(%rip), %rdi      # 0x13430
movb $0x0, %al
callq 0x2050
jmp 0x4aa0
jmp 0x48d1
leaq -0x120(%rbp), %rdi
leaq 0xebcf(%rip), %rsi      # 0x13468
leaq -0x128(%rbp), %rdx
movb $0x0, %al
callq 0x21e0
cmpl $0x1, %eax
jne 0x48ae
jmp 0x48cf
leaq -0x120(%rbp), %rdi
leaq 0xeb31(%rip), %rsi      # 0x133ed
movl $0xa, %edx
callq 0x20d0
cmpl $0x0, %eax
jne 0x48cd
jmp 0x48d6
jmp 0x48cf
jmp 0x48d1
jmp 0x4824
xorps %xmm0, %xmm0
movss %xmm0, -0x134(%rbp)
movslq -0x124(%rbp), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2040
movq %rax, -0x148(%rbp)
movl $0x0, -0x14c(%rbp)
movl -0x14c(%rbp), %eax
cmpl -0x124(%rbp), %eax
jge 0x4a1c
leaq -0x120(%rbp), %rdi
movq -0x18(%rbp), %rdx
movl $0x100, %esi            # imm = 0x100
callq 0x2300
xorps %xmm0, %xmm0
movss %xmm0, -0x130(%rbp)
leaq -0x120(%rbp), %rax
movq %rax, -0x140(%rbp)
movl $0x0, -0x150(%rbp)
movl -0x150(%rbp), %eax
cmpl -0x128(%rbp), %eax
jge 0x49ca
movq -0x140(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x2150
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x12c(%rbp)
movss -0x12c(%rbp), %xmm0
movss -0x12c(%rbp), %xmm2
movss -0x130(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x130(%rbp)
movl -0x150(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x150(%rbp)
jmp 0x4964
movss -0x130(%rbp), %xmm0
movq -0x148(%rbp), %rax
movslq -0x14c(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movss -0x130(%rbp), %xmm0
ucomiss -0x134(%rbp), %xmm0
jbe 0x4a06
movss -0x130(%rbp), %xmm0
movss %xmm0, -0x134(%rbp)
jmp 0x4a08
movl -0x14c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14c(%rbp)
jmp 0x491a
movl $0x0, -0x154(%rbp)
movl -0x154(%rbp), %eax
cmpl -0x124(%rbp), %eax
jge 0x4aa0
movss -0x134(%rbp), %xmm1
movq -0x148(%rbp), %rax
movslq -0x154(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
divss %xmm1, %xmm0
movss %xmm0, (%rax,%rcx,4)
movq -0x148(%rbp), %rax
movslq -0x154(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
callq 0x4ab0
movq -0x160(%rbp), %rax
movq 0x58(%rax), %rax
movl -0x154(%rbp), %ecx
shll $0x2, %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0x154(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x154(%rbp)
jmp 0x4a26
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
nopl (%rax)