// File: jingdao[P]PointCloudApp/pcd.cpp
// Function: PCD::LoadFromCluster(char const*)
PCD* PCD::LoadFromCluster(const char* dir) {
	char buffer[1024];
	int ndir = strlen(dir);
	strncpy(buffer,dir,ndir);
	char* buffer_c = buffer + ndir;
	*buffer_c++ = '/';

	strcpy(buffer_c,"prediction.txt");
	FILE* labelFile = fopen(buffer,"r");
	std::vector<int> labels;
	char line[256];
	while (fgets(line,256,labelFile)) {
		labels.push_back(atoi(line));
	}
	fclose(labelFile);

	PCD* combined = new PCD(0);
	float colorChoice[] = {16777215, 255<<16, 255<<8, 255, (255<<16)|(255<<8), (255<<16)|255, (255<<8)|255};
	for (size_t i=0;i<labels.size();i++) {
		snprintf(buffer_c,64,"%lu-cloud.pcd",i);
		PCD cloud(buffer);
		int offset = combined->numPoints;
		combined->expand(offset + cloud.numPoints);
		for (int j = 0;j<cloud.numPoints;j++) {
			combined->float_data[(offset+j) * 4] = cloud.float_data[j * 4];
			combined->float_data[(offset+j) * 4 + 1] = cloud.float_data[j * 4 + 1];
			combined->float_data[(offset+j) * 4 + 2] = cloud.float_data[j * 4 + 2];
			combined->float_data[(offset+j) * 4 + 3] = colorChoice[labels[i]];
		}
	}

	return combined;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x630, %rsp            # imm = 0x630
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x20c0
movl %eax, -0x414(%rbp)
leaq -0x410(%rbp), %rdi
movq -0x8(%rbp), %rsi
movslq -0x414(%rbp), %rdx
callq 0x20e0
leaq -0x410(%rbp), %rax
movslq -0x414(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x420(%rbp)
movq -0x420(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x420(%rbp)
movb $0x2f, (%rax)
movq -0x420(%rbp), %rdi
leaq 0xbc2a(%rip), %rsi      # 0x1384d
callq 0x21c0
leaq -0x410(%rbp), %rdi
leaq 0xbb56(%rip), %rsi      # 0x1378c
callq 0x2230
movq %rax, -0x428(%rbp)
leaq -0x440(%rbp), %rdi
callq 0x3130
movq -0x428(%rbp), %rdx
leaq -0x540(%rbp), %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x2300
movq %rax, -0x610(%rbp)
jmp 0x7c6f
movq -0x610(%rbp), %rax
cmpq $0x0, %rax
je 0x7cbc
leaq -0x540(%rbp), %rdi
callq 0x22f0
movl %eax, -0x550(%rbp)
leaq -0x440(%rbp), %rdi
leaq -0x550(%rbp), %rsi
callq 0xac70
jmp 0x7ca3
jmp 0x7c4e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x548(%rbp)
movl %eax, -0x54c(%rbp)
jmp 0x7f8b
movq -0x428(%rbp), %rdi
callq 0x21f0
jmp 0x7cca
movl $0x78, %edi
callq 0x2200
movq %rax, -0x618(%rbp)
jmp 0x7cdd
movq -0x618(%rbp), %rdi
xorl %esi, %esi
callq 0x41e0
jmp 0x7ced
movq -0x618(%rbp), %rax
movq %rax, -0x558(%rbp)
movq 0xbbbe(%rip), %rax      # 0x138c0
movq %rax, -0x580(%rbp)
movq 0xbbb8(%rip), %rax      # 0x138c8
movq %rax, -0x578(%rbp)
movq 0xbbb2(%rip), %rax      # 0x138d0
movq %rax, -0x570(%rbp)
movl 0xbbad(%rip), %eax      # 0x138d8
movl %eax, -0x568(%rbp)
movq $0x0, -0x588(%rbp)
movq -0x588(%rbp), %rax
movq %rax, -0x620(%rbp)
leaq -0x440(%rbp), %rdi
callq 0xaca0
movq %rax, %rcx
movq -0x620(%rbp), %rax
cmpq %rcx, %rax
jae 0x7f61
movq -0x420(%rbp), %rdi
movq -0x588(%rbp), %rcx
leaq 0xb8e9(%rip), %rdx      # 0x13667
xorl %eax, %eax
movl $0x40, %esi
callq 0x2310
leaq -0x600(%rbp), %rdi
leaq -0x410(%rbp), %rsi
callq 0x3ed0
jmp 0x7d9f
movq -0x558(%rbp), %rax
movl 0x60(%rax), %eax
movl %eax, -0x604(%rbp)
movq -0x558(%rbp), %rdi
movl -0x604(%rbp), %esi
movl -0x5a0(%rbp), %eax
addl %eax, %esi
callq 0x4330
jmp 0x7dcb
movl $0x0, -0x608(%rbp)
movl -0x608(%rbp), %eax
cmpl -0x5a0(%rbp), %eax
jge 0x7f3e
movq -0x5a8(%rbp), %rax
movl -0x608(%rbp), %ecx
shll $0x2, %ecx
movslq %ecx, %rcx
movss (%rax,%rcx,4), %xmm0
movq -0x558(%rbp), %rax
movq 0x58(%rax), %rax
movl -0x604(%rbp), %ecx
addl -0x608(%rbp), %ecx
shll $0x2, %ecx
movslq %ecx, %rcx
movss %xmm0, (%rax,%rcx,4)
movq -0x5a8(%rbp), %rax
movl -0x608(%rbp), %ecx
shll $0x2, %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movss (%rax,%rcx,4), %xmm0
movq -0x558(%rbp), %rax
movq 0x58(%rax), %rax
movl -0x604(%rbp), %ecx
addl -0x608(%rbp), %ecx
shll $0x2, %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movss %xmm0, (%rax,%rcx,4)
movq -0x5a8(%rbp), %rax
movl -0x608(%rbp), %ecx
shll $0x2, %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movss (%rax,%rcx,4), %xmm0
movq -0x558(%rbp), %rax
movq 0x58(%rax), %rax
movl -0x604(%rbp), %ecx
addl -0x608(%rbp), %ecx
shll $0x2, %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movss %xmm0, (%rax,%rcx,4)
movq -0x588(%rbp), %rsi
leaq -0x440(%rbp), %rdi
callq 0xacc0
movslq (%rax), %rax
movss -0x580(%rbp,%rax,4), %xmm0
movq -0x558(%rbp), %rax
movq 0x58(%rax), %rax
movl -0x604(%rbp), %ecx
addl -0x608(%rbp), %ecx
shll $0x2, %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0x608(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x608(%rbp)
jmp 0x7dd5
movq -0x618(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x548(%rbp)
movl %eax, -0x54c(%rbp)
movl $0x78, %esi
callq 0x2210
jmp 0x7f8b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x548(%rbp)
movl %eax, -0x54c(%rbp)
leaq -0x600(%rbp), %rdi
callq 0x4290
jmp 0x7f8b
leaq -0x600(%rbp), %rdi
callq 0x4290
movq -0x588(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x588(%rbp)
jmp 0x7d3c
movq -0x558(%rbp), %rax
movq %rax, -0x628(%rbp)
leaq -0x440(%rbp), %rdi
callq 0x31d0
movq -0x628(%rbp), %rax
addq $0x630, %rsp            # imm = 0x630
popq %rbp
retq
leaq -0x440(%rbp), %rdi
callq 0x31d0
movq -0x548(%rbp), %rdi
callq 0x2380
nopw %cs:(%rax,%rax)