// File: jingdao[P]PointCloudApp/main.cpp
// Function: fileConversion(char*, char*)
void fileConversion(char* in, char* out) {
	PCD* p,*q;
	int l = strlen(in);
	if (strncmp(in + l - 4,".pcd",4) == 0) {
		p = new PCD(in);
	} else if (strncmp(in + l - 4,".ply",4) == 0) {
		p = PCD::LoadFromPLY(in);
	} else if (strncmp(in + l - 4,".bin",4) == 0) {
		p = PCD::LoadFromKITTI(in,NULL);
		printf("Loaded %s (%s, %d points)\n",in,
			p->data_storage==PCD::ASCII ? "ascii" : "binary",
			p->numPoints);

		float segThreshold = 0.4, filterThreshold = 0.4, clusterThreshold = 0.1;
		
		PCD::Plane  coefficients = p->segmentPlane(10000,segThreshold,0.7);
		printf("Plane Coefficients: %f %f %f %f\n",coefficients.a,coefficients.b,coefficients.c,coefficients.d);
		std::vector<int> ind;
		p->filterPlane(&ind,coefficients,filterThreshold,false);
		q = p->extractIndices(&ind);
		char originalPath[256];
		snprintf(originalPath,255,"%s/original.pcd",out);
		q->writeToPCD(originalPath);

//		q = p;
		q->kdtree = new KdTree(q);
		printf("kdtree depth: %d\n",q->kdtree->kdtreeDepth);
		std::vector<std::vector<int>> clusters;
		q->euclideanClusteringKDTree(&clusters,clusterThreshold,200,1000000,200);
		q->writeClustersToPCD(&clusters,out);

		delete p;
		delete q;
		return;
	} else if (strncmp(in + l - 4,".pts",4) == 0) {
		p = PCD::LoadFromPTS(in);
	} else if (DIR* d = opendir(in)){
		closedir(d);
		l = strlen(out);
		if (strncmp(out + l - 14,"descriptor.pcd",14) == 0) {
			Descriptor* d = Descriptor::LoadFromDir(in);
			d->writeToPCD(out);
			delete d;
			return;
		} else {
			p = PCD::LoadFromCluster(in);
		}
	}


	printf("Loaded %s (%s, %d points)\n",in,
		p->data_storage==PCD::ASCII ? "ascii" : "binary",
		p->numPoints);

	l = strlen(out);
	if (strncmp(out + l - 4,".pcd",4) == 0)
		p->writeToPCD(out);
	else if (strncmp(out + l - 4,".ply",4) == 0)
		p->writeToPLY(out);
	else if (strncmp(out + l - 4,".off",4) == 0)
		p->writeToOFF(out);
	delete p;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x200, %rsp            # imm = 0x200
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
callq 0x20c0
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x24(%rbp), %rax
addq %rax, %rdi
addq $-0x4, %rdi
leaq 0x10cb3(%rip), %rsi     # 0x137e8
movl $0x4, %edx
callq 0x20d0
cmpl $0x0, %eax
jne 0x2b98
movl $0x78, %edi
callq 0x2200
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x1b0(%rbp)
movq -0x8(%rbp), %rsi
callq 0x3ed0
jmp 0x2b66
movq -0x1b0(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0x2fae
movq -0x1b0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
movl $0x78, %esi
callq 0x2210
jmp 0x30c4
movq -0x8(%rbp), %rdi
movslq -0x24(%rbp), %rax
addq %rax, %rdi
addq $-0x4, %rdi
leaq 0x105c7(%rip), %rsi     # 0x13175
movl $0x4, %edx
callq 0x20d0
cmpl $0x0, %eax
jne 0x2bcf
movq -0x8(%rbp), %rdi
callq 0x5970
movq %rax, -0x18(%rbp)
jmp 0x2fac
movq -0x8(%rbp), %rdi
movslq -0x24(%rbp), %rax
addq %rax, %rdi
addq $-0x4, %rdi
leaq 0x10595(%rip), %rsi     # 0x1317a
movl $0x4, %edx
callq 0x20d0
cmpl $0x0, %eax
jne 0x2eaf
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, -0x1b4(%rbp)
movl %eax, %esi
callq 0x6d00
movq %rax, %rcx
movl -0x1b4(%rbp), %eax
movq %rcx, -0x18(%rbp)
movq -0x8(%rbp), %rsi
movq -0x18(%rbp), %rdx
movl 0x60(%rdx), %ecx
movl 0x68(%rdx), %edx
testl %edx, %edx
leaq 0x107c3(%rip), %rdi     # 0x133f2
leaq 0x10564(%rip), %rdx     # 0x1319a
cmoveq %rdi, %rdx
leaq 0x1053e(%rip), %rdi     # 0x1317f
callq 0x2050
movl $0x3ecccccd, -0x38(%rbp) # imm = 0x3ECCCCCD
movl $0x3ecccccd, -0x3c(%rbp) # imm = 0x3ECCCCCD
movl $0x3dcccccd, -0x40(%rbp) # imm = 0x3DCCCCCD
movq -0x18(%rbp), %rdi
movss -0x38(%rbp), %xmm0
movl $0x2710, %esi           # imm = 0x2710
movss 0x10393(%rip), %xmm1    # 0x13004
callq 0x9460
movlpd %xmm0, -0x50(%rbp)
movlpd %xmm1, -0x48(%rbp)
movss -0x50(%rbp), %xmm0
movss -0x4c(%rbp), %xmm1
cvtss2sd %xmm0, %xmm0
cvtss2sd %xmm1, %xmm1
movss -0x48(%rbp), %xmm2
cvtss2sd %xmm2, %xmm2
movss -0x44(%rbp), %xmm3
cvtss2sd %xmm3, %xmm3
leaq 0x104f6(%rip), %rdi     # 0x131a1
movb $0x4, %al
callq 0x2050
leaq -0x68(%rbp), %rdi
movq %rdi, -0x1c0(%rbp)
callq 0x3130
movq -0x1c0(%rbp), %rsi
movl -0x1b4(%rbp), %edx
movq -0x18(%rbp), %rdi
movups -0x50(%rbp), %xmm0
movaps %xmm0, -0x80(%rbp)
movss -0x3c(%rbp), %xmm2
movsd -0x80(%rbp), %xmm0
movsd -0x78(%rbp), %xmm1
callq 0x98a0
jmp 0x2cf1
movq -0x18(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x5120
movq %rax, -0x1c8(%rbp)
jmp 0x2d07
movq -0x1c8(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rcx
leaq 0x104a5(%rip), %rdx     # 0x131c2
xorl %eax, %eax
leaq -0x180(%rbp), %rdi
movq %rdi, -0x1d0(%rbp)
movl $0xff, %esi
callq 0x2310
movq -0x1d0(%rbp), %rsi
movq -0x20(%rbp), %rdi
callq 0x4c90
jmp 0x2d49
movl $0x40, %edi
callq 0x2200
movq %rax, -0x1d8(%rbp)
jmp 0x2d5c
movq -0x1d8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0xde90
jmp 0x2d6e
movq -0x1d8(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x70(%rax)
movq -0x20(%rbp), %rax
movq 0x70(%rax), %rax
movl 0x28(%rax), %esi
leaq 0x10443(%rip), %rdi     # 0x131d2
xorl %eax, %eax
callq 0x2050
jmp 0x2d98
leaq -0x198(%rbp), %rdi
movq %rdi, -0x1e0(%rbp)
callq 0x3150
movq -0x1e0(%rbp), %rsi
movq -0x20(%rbp), %rdi
movss -0x40(%rbp), %xmm0
movl $0xf4240, %ecx          # imm = 0xF4240
movl $0xc8, %r8d
movq %r8, %rdx
callq 0x9a80
jmp 0x2dd0
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq -0x198(%rbp), %rsi
callq 0x4f90
jmp 0x2de6
movq -0x18(%rbp), %rax
movq %rax, -0x1e8(%rbp)
cmpq $0x0, %rax
je 0x2e14
movq -0x1e8(%rbp), %rdi
callq 0x4290
movq -0x1e8(%rbp), %rdi
movl $0x78, %esi
callq 0x2210
movq -0x20(%rbp), %rax
movq %rax, -0x1f0(%rbp)
cmpq $0x0, %rax
je 0x2e42
movq -0x1f0(%rbp), %rdi
callq 0x4290
movq -0x1f0(%rbp), %rdi
movl $0x78, %esi
callq 0x2210
leaq -0x198(%rbp), %rdi
callq 0x3170
leaq -0x68(%rbp), %rdi
callq 0x31d0
jmp 0x30bb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x2ea1
movq -0x1d8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
movl $0x40, %esi
callq 0x2210
jmp 0x2ea1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x198(%rbp), %rdi
callq 0x3170
leaq -0x68(%rbp), %rdi
callq 0x31d0
jmp 0x30c4
movq -0x8(%rbp), %rdi
movslq -0x24(%rbp), %rax
addq %rax, %rdi
addq $-0x4, %rdi
leaq 0x1031f(%rip), %rsi     # 0x131e4
movl $0x4, %edx
callq 0x20d0
cmpl $0x0, %eax
jne 0x2ee6
movq -0x8(%rbp), %rdi
callq 0x7910
movq %rax, -0x18(%rbp)
jmp 0x2fa8
movq -0x8(%rbp), %rdi
callq 0x22b0
movq %rax, -0x1a0(%rbp)
cmpq $0x0, -0x1a0(%rbp)
je 0x2fa6
movq -0x1a0(%rbp), %rdi
callq 0x2320
movq -0x10(%rbp), %rdi
callq 0x20c0
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x24(%rbp), %rax
addq %rax, %rdi
addq $-0xe, %rdi
leaq 0x102b7(%rip), %rsi     # 0x131e9
movl $0xe, %edx
callq 0x20d0
cmpl $0x0, %eax
jne 0x2f97
movq -0x8(%rbp), %rdi
callq 0xf8b0
movq %rax, -0x1a8(%rbp)
movq -0x1a8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x102f0
movq -0x1a8(%rbp), %rax
movq %rax, -0x1f8(%rbp)
cmpq $0x0, %rax
je 0x2f92
movq -0x1f8(%rbp), %rdi
callq 0xf870
movq -0x1f8(%rbp), %rdi
movl $0x90, %esi
callq 0x2210
jmp 0x30bb
movq -0x8(%rbp), %rdi
callq 0x7bb0
movq %rax, -0x18(%rbp)
jmp 0x2fa6
jmp 0x2fa8
jmp 0x2faa
jmp 0x2fac
jmp 0x2fae
movq -0x8(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x68(%rax), %ecx
leaq 0x101da(%rip), %rdx     # 0x1319a
leaq 0x1042b(%rip), %rax     # 0x133f2
cmpl $0x0, %ecx
cmoveq %rax, %rdx
movq -0x18(%rbp), %rax
movl 0x60(%rax), %ecx
leaq 0x101a3(%rip), %rdi     # 0x1317f
movb $0x0, %al
callq 0x2050
movq -0x10(%rbp), %rdi
callq 0x20c0
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x24(%rbp), %rax
addq %rax, %rdi
addq $-0x4, %rdi
leaq 0x107e3(%rip), %rsi     # 0x137e8
movl $0x4, %edx
callq 0x20d0
cmpl $0x0, %eax
jne 0x3023
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x4c90
jmp 0x308d
movq -0x10(%rbp), %rdi
movslq -0x24(%rbp), %rax
addq %rax, %rdi
addq $-0x4, %rdi
leaq 0x1013c(%rip), %rsi     # 0x13175
movl $0x4, %edx
callq 0x20d0
cmpl $0x0, %eax
jne 0x3057
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x4e00
jmp 0x308b
movq -0x10(%rbp), %rdi
movslq -0x24(%rbp), %rax
addq %rax, %rdi
addq $-0x4, %rdi
leaq 0x1018b(%rip), %rsi     # 0x131f8
movl $0x4, %edx
callq 0x20d0
cmpl $0x0, %eax
jne 0x3089
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x56c0
jmp 0x308b
jmp 0x308d
movq -0x18(%rbp), %rax
movq %rax, -0x200(%rbp)
cmpq $0x0, %rax
je 0x30bb
movq -0x200(%rbp), %rdi
callq 0x4290
movq -0x200(%rbp), %rdi
movl $0x78, %esi
callq 0x2210
addq $0x200, %rsp            # imm = 0x200
popq %rbp
retq
movq -0x30(%rbp), %rdi
callq 0x2380
nopl (%rax)