// File: /workspace/github_cpp_makefile_star2_O3/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 %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movq %rsi, %rbx
movq %rdi, %r14
callq 0x20c0
cltq
leaq (%r14,%rax), %r15
addq $-0x4, %r15
leaq 0x8f0f(%rip), %rsi      # 0xb8ba
movl $0x4, %edx
movq %r15, %rdi
callq 0x20d0
testl %eax, %eax
je 0x2a5c
leaq 0x87de(%rip), %rsi      # 0xb1a5
movl $0x4, %edx
movq %r15, %rdi
callq 0x20d0
testl %eax, %eax
je 0x2a79
leaq 0x87c7(%rip), %rsi      # 0xb1aa
movl $0x4, %edx
movq %r15, %rdi
callq 0x20d0
testl %eax, %eax
je 0x2a86
leaq 0x8815(%rip), %rsi      # 0xb214
movl $0x4, %edx
movq %r15, %rdi
callq 0x20d0
movq %r14, %rdi
testl %eax, %eax
je 0x2c46
callq 0x22d0
movq %rax, %rdi
callq 0x2350
movq %rbx, %rdi
callq 0x20c0
cltq
leaq (%rbx,%rax), %rdi
addq $-0xe, %rdi
leaq 0x87dc(%rip), %rsi      # 0xb219
movl $0xe, %edx
callq 0x20d0
testl %eax, %eax
je 0x2d1c
movq %r14, %rdi
callq 0x5a1e
jmp 0x2c4b
movl $0x78, %edi
callq 0x2200
movq %rax, %r15
movq %rax, %rdi
movq %r14, %rsi
callq 0x3186
jmp 0x2c4e
movq %r14, %rdi
callq 0x42a0
jmp 0x2c4b
movq %r14, %rdi
xorl %esi, %esi
callq 0x4fd8
movq %rax, %r15
cmpl $0x0, 0x68(%rax)
leaq 0x8a74(%rip), %rax      # 0xb512
leaq 0x8725(%rip), %rdx      # 0xb1ca
cmoveq %rax, %rdx
movl 0x60(%r15), %ecx
leaq 0x86fb(%rip), %rdi      # 0xb1af
movq %r14, %rsi
xorl %eax, %eax
callq 0x2050
movss 0x8562(%rip), %xmm0     # 0xb028
movss 0x855e(%rip), %xmm1     # 0xb02c
movq %r15, %rdi
movl $0x2710, %esi           # imm = 0x2710
callq 0x6b2c
movaps %xmm0, %xmm2
movaps %xmm0, 0x50(%rsp)
movaps %xmm1, %xmm3
movaps %xmm1, 0x40(%rsp)
cvtss2sd %xmm0, %xmm0
shufps $0x55, %xmm2, %xmm2     # xmm2 = xmm2[1,1,1,1]
xorps %xmm1, %xmm1
cvtss2sd %xmm2, %xmm1
xorps %xmm2, %xmm2
cvtss2sd %xmm3, %xmm2
shufps $0x55, %xmm3, %xmm3     # xmm3 = xmm3[1,1,1,1]
cvtss2sd %xmm3, %xmm3
leaq 0x86c1(%rip), %rdi      # 0xb1d1
movb $0x4, %al
callq 0x2050
xorps %xmm0, %xmm0
movq %rsp, %rsi
movaps %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
movq %r15, %rdi
movaps 0x50(%rsp), %xmm0
movaps 0x40(%rsp), %xmm1
movss 0x84eb(%rip), %xmm2     # 0xb028
xorl %edx, %edx
callq 0x6d96
movq %rsp, %rsi
movq %r15, %rdi
callq 0x3d42
movq %rax, %r14
leaq 0x8699(%rip), %rdx      # 0xb1f2
leaq 0x60(%rsp), %r12
movl $0xff, %esi
movq %r12, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2340
movq %r14, %rdi
movq %r12, %rsi
callq 0x3a1a
movl $0x40, %edi
callq 0x2200
movq %rax, %r12
movq %rax, %rdi
movq %r14, %rsi
callq 0x83d4
movq %r12, 0x70(%r14)
movl 0x28(%r12), %esi
leaq 0x865f(%rip), %rdi      # 0xb202
xorl %eax, %eax
callq 0x2050
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rsi
movaps %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
movss 0x846b(%rip), %xmm0     # 0xb030
movl $0xc8, %edx
movl $0xf4240, %ecx          # imm = 0xF4240
movl $0xc8, %r8d
movq %r14, %rdi
callq 0x6fa6
leaq 0x20(%rsp), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x3c2e
movq %r15, %rdi
callq 0x3494
movl $0x78, %esi
movq %r15, %rdi
callq 0x2210
movq %r14, %rdi
callq 0x3494
movl $0x78, %esi
movq %r14, %rdi
callq 0x2210
leaq 0x20(%rsp), %rdi
callq 0x2dd4
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x2c37
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r14
popq %r15
retq
callq 0x57f8
movq %rax, %r15
cmpl $0x0, 0x68(%r15)
leaq 0x88b8(%rip), %rax      # 0xb512
leaq 0x8569(%rip), %rdx      # 0xb1ca
cmoveq %rax, %rdx
movl 0x60(%r15), %ecx
leaq 0x853f(%rip), %rdi      # 0xb1af
movq %r14, %rsi
xorl %eax, %eax
callq 0x2050
movq %rbx, %rdi
callq 0x20c0
cltq
leaq (%rbx,%rax), %r14
addq $-0x4, %r14
leaq 0x8c27(%rip), %rsi      # 0xb8ba
movl $0x4, %edx
movq %r14, %rdi
callq 0x20d0
testl %eax, %eax
je 0x2ce1
leaq 0x84fa(%rip), %rsi      # 0xb1a5
movl $0x4, %edx
movq %r14, %rdi
callq 0x20d0
testl %eax, %eax
je 0x2cee
leaq 0x8565(%rip), %rsi      # 0xb228
movl $0x4, %edx
movq %r14, %rdi
callq 0x20d0
testl %eax, %eax
jne 0x2cf9
movq %r15, %rdi
movq %rbx, %rsi
callq 0x40ea
jmp 0x2cf9
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3a1a
jmp 0x2cf9
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3b16
movq %r15, %rdi
callq 0x3494
movl $0x78, %esi
movq %r15, %rdi
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x2210
movq %r14, %rdi
callq 0x8f02
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x94c8
movq %r14, %rdi
callq 0x8ef4
movl $0x90, %esi
movq %r14, %rdi
jmp 0x2d09
movq %rax, %rbx
movl $0x40, %esi
movq %r12, %rdi
callq 0x2210
jmp 0x2d6a
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x2dd4
jmp 0x2d6a
jmp 0x2d67
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x2d8d
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
jmp 0x2d88
movq %rax, %rbx
movl $0x78, %esi
movq %r15, %rdi
callq 0x2210
movq %rbx, %rdi
callq 0x23a0