// File: jingdao[P]PointCloudApp/descriptor.cpp
// Function: Descriptor::LoadFromDir(char const*)
Descriptor* Descriptor::LoadFromDir(const char* dir) {
	Descriptor* res = new Descriptor();

	char buffer[1024];
	int ndir = strlen(dir);
	strncpy(buffer,dir,ndir);
	char* buffer_c = buffer + ndir;
	*buffer_c++ = '/';

	std::vector<double> measurements;
	int j;
	for (j=0;;j++) {
		snprintf(buffer_c,64,"%d-cloud.pcd",j);
		PCD cloud(buffer);
		if (cloud.numPoints==0)
			break;
		Descriptor desc(&cloud);
		double lambda[3],v[9];
		desc.getPCA_XY(lambda,v);
		desc.setPCA(lambda,v);
		measurements.push_back(desc.principalLengths[0]); //length;
		measurements.push_back(desc.principalLengths[1]); //width;
		measurements.push_back(desc.principalLengths[2]); //height;
	}

	//set data
	res->numPoints = j;
	res->dimension = 3;
	res->data = new float[res->numPoints * res->dimension];
	for (size_t i=0;i<measurements.size();i++) {
		res->data[i] = measurements[i];
	}

	return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x600, %rsp            # imm = 0x600
movq %rdi, -0x8(%rbp)
movl $0x90, %edi
callq 0x2200
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x5e0(%rbp)
callq 0xf620
jmp 0xf8dd
movq -0x5e0(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rdi
callq 0x20c0
movl %eax, -0x424(%rbp)
leaq -0x420(%rbp), %rdi
movq -0x8(%rbp), %rsi
movslq -0x424(%rbp), %rdx
callq 0x20e0
leaq -0x420(%rbp), %rax
movslq -0x424(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x430(%rbp)
movq -0x430(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x430(%rbp)
movb $0x2f, (%rax)
leaq -0x448(%rbp), %rdi
callq 0x10b20
movl $0x0, -0x44c(%rbp)
movq -0x430(%rbp), %rdi
movl -0x44c(%rbp), %ecx
leaq 0x3f80(%rip), %rdx      # 0x138e8
xorl %eax, %eax
movl $0x40, %esi
callq 0x2310
leaq -0x4c8(%rbp), %rdi
leaq -0x420(%rbp), %rsi
callq 0x3ed0
jmp 0xf989
cmpl $0x0, -0x468(%rbp)
jne 0xf9d4
movl $0x2, -0x4cc(%rbp)
jmp 0xfa76
movq -0x5e0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl $0x90, %esi
callq 0x2210
jmp 0xfbe9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0xfbdd
leaq -0x560(%rbp), %rdi
leaq -0x4c8(%rbp), %rsi
callq 0xf840
jmp 0xf9e9
leaq -0x560(%rbp), %rdi
leaq -0x580(%rbp), %rsi
leaq -0x5d0(%rbp), %rdx
callq 0xfc00
jmp 0xfa05
leaq -0x560(%rbp), %rdi
leaq -0x580(%rbp), %rsi
leaq -0x5d0(%rbp), %rdx
callq 0xfdb0
jmp 0xfa21
leaq -0x548(%rbp), %rsi
leaq -0x448(%rbp), %rdi
callq 0x10b40
jmp 0xfa36
leaq -0x540(%rbp), %rsi
leaq -0x448(%rbp), %rdi
callq 0x10b40
jmp 0xfa4b
leaq -0x538(%rbp), %rsi
leaq -0x448(%rbp), %rdi
callq 0x10b40
jmp 0xfa60
leaq -0x560(%rbp), %rdi
callq 0xf870
movl $0x0, -0x4cc(%rbp)
leaq -0x4c8(%rbp), %rdi
callq 0x4290
movl -0x4cc(%rbp), %eax
testl %eax, %eax
je 0xfa90
jmp 0xfa8e
jmp 0xfadd
jmp 0xfa92
movl -0x44c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44c(%rbp)
jmp 0xf954
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0xfacc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x560(%rbp), %rdi
callq 0xf870
leaq -0x4c8(%rbp), %rdi
callq 0x4290
jmp 0xfbdd
movl -0x44c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movl $0x3, 0x4(%rax)
movq -0x10(%rbp), %rcx
movl (%rcx), %eax
movl 0x4(%rcx), %ecx
imull %ecx, %eax
cltq
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0x2040
movq %rax, -0x5e8(%rbp)
jmp 0xfb26
movq -0x5e8(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq $0x0, -0x5d8(%rbp)
movq -0x5d8(%rbp), %rax
movq %rax, -0x5f0(%rbp)
leaq -0x448(%rbp), %rdi
callq 0x10bb0
movq %rax, %rcx
movq -0x5f0(%rbp), %rax
cmpq %rcx, %rax
jae 0xfbac
movq -0x5d8(%rbp), %rsi
leaq -0x448(%rbp), %rdi
callq 0x10bd0
movsd (%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x5d8(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movq -0x5d8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x5d8(%rbp)
jmp 0xfb40
movq -0x10(%rbp), %rax
movq %rax, -0x5f8(%rbp)
movl $0x1, -0x4cc(%rbp)
leaq -0x448(%rbp), %rdi
callq 0x10bf0
movq -0x5f8(%rbp), %rax
addq $0x600, %rsp            # imm = 0x600
popq %rbp
retq
leaq -0x448(%rbp), %rdi
callq 0x10bf0
movq -0x18(%rbp), %rdi
callq 0x2380
nopw %cs:(%rax,%rax)