// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x160, %rsp            # imm = 0x160
movq %rsi, %rbx
movq %rdi, %r14
callq 0x20c0
cltq
leaq (%r14,%rax), %r15
addq $-0x4, %r15
leaq 0x8e5e(%rip), %rsi      # 0xb7ea
movl $0x4, %edx
movq %r15, %rdi
callq 0x20d0
testl %eax, %eax
je 0x2a4c
leaq 0x87fd(%rip), %rsi      # 0xb1a5
movl $0x4, %edx
movq %r15, %rdi
callq 0x20d0
testl %eax, %eax
je 0x2a69
leaq 0x87e6(%rip), %rsi      # 0xb1aa
movl $0x4, %edx
movq %r15, %rdi
callq 0x20d0
testl %eax, %eax
je 0x2a76
leaq 0x8834(%rip), %rsi      # 0xb214
movl $0x4, %edx
movq %r15, %rdi
callq 0x20d0
movq %r14, %rdi
testl %eax, %eax
je 0x2c30
callq 0x22d0
movb $0x1, %bpl
testq %rax, %rax
je 0x2d36
movq %rax, %rdi
callq 0x2350
movq %rbx, %rdi
callq 0x20c0
cltq
leaq (%rbx,%rax), %rdi
addq $-0xe, %rdi
leaq 0x87ef(%rip), %rsi      # 0xb219
movl $0xe, %edx
callq 0x20d0
movq %r14, %rdi
testl %eax, %eax
je 0x2d0c
callq 0x5914
movq %rax, %r15
jmp 0x2d36
movl $0x78, %edi
callq 0x2200
movq %rax, %r15
movq %rax, %rdi
movq %r14, %rsi
callq 0x3182
jmp 0x2c38
movq %r14, %rdi
callq 0x42d0
jmp 0x2c35
movq %r14, %rdi
xorl %esi, %esi
callq 0x4fb8
movq %rax, %r15
cmpl $0x0, 0x68(%rax)
leaq 0x89b4(%rip), %rax      # 0xb442
leaq 0x8735(%rip), %rdx      # 0xb1ca
cmoveq %rax, %rdx
movl 0x60(%r15), %ecx
leaq 0x870b(%rip), %rdi      # 0xb1af
movq %r14, %rsi
xorl %eax, %eax
callq 0x2050
movss 0x8572(%rip), %xmm0     # 0xb028
movss 0x856e(%rip), %xmm1     # 0xb02c
movq %r15, %rdi
movl $0x2710, %esi           # imm = 0x2710
callq 0x6a5e
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 0x86d1(%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 0x84fb(%rip), %xmm2     # 0xb028
xorl %edx, %edx
callq 0x6d3a
movq %rsp, %rsi
movq %r15, %rdi
callq 0x3d72
movq %rax, %r14
leaq 0x86a9(%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 0x3a4a
movl $0x40, %edi
callq 0x2200
movq %rax, %r12
movq %rax, %rdi
movq %r14, %rsi
callq 0x83c0
movq %r12, 0x70(%r14)
movl 0x28(%r12), %esi
leaq 0x866f(%rip), %rdi      # 0xb202
xorl %eax, %eax
callq 0x2050
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rsi
movaps %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
movss 0x847b(%rip), %xmm0     # 0xb030
movl $0xc8, %edx
movl $0xf4240, %ecx          # imm = 0xF4240
movl $0xc8, %r8d
movq %r14, %rdi
callq 0x6f7c
leaq 0x20(%rsp), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x3c5e
movq %r15, %rdi
callq 0x348e
movl $0x78, %esi
movq %r15, %rdi
callq 0x2210
movq %r14, %rdi
callq 0x348e
movl $0x78, %esi
movq %r14, %rdi
callq 0x2210
leaq 0x20(%rsp), %rdi
callq 0x2dde
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x2d3f
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
jmp 0x2d3f
callq 0x5716
movq %rax, %r15
cmpl $0x0, 0x68(%r15)
leaq 0x87fe(%rip), %rax      # 0xb442
leaq 0x857f(%rip), %rdx      # 0xb1ca
cmoveq %rax, %rdx
movl 0x60(%r15), %ecx
leaq 0x8555(%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 0x8b6d(%rip), %rsi      # 0xb7ea
movl $0x4, %edx
movq %r14, %rdi
callq 0x20d0
testl %eax, %eax
je 0x2ccb
leaq 0x8510(%rip), %rsi      # 0xb1a5
movl $0x4, %edx
movq %r14, %rdi
callq 0x20d0
testl %eax, %eax
je 0x2cd8
leaq 0x857b(%rip), %rsi      # 0xb228
movl $0x4, %edx
movq %r14, %rdi
callq 0x20d0
testl %eax, %eax
jne 0x2ce3
movq %r15, %rdi
movq %rbx, %rsi
callq 0x411a
jmp 0x2ce3
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3a4a
jmp 0x2ce3
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3b46
testq %r15, %r15
je 0x2d3f
movq %r15, %rdi
callq 0x348e
movl $0x78, %esi
movq %r15, %rdi
addq $0x160, %rsp            # imm = 0x160
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x2210
callq 0x8f1e
movq %rax, %r15
movq %rax, %rdi
movq %rbx, %rsi
callq 0x9538
movq %r15, %rdi
callq 0x8f10
movl $0x90, %esi
movq %r15, %rdi
callq 0x2210
xorl %ebp, %ebp
testb %bpl, %bpl
jne 0x2c38
addq $0x160, %rsp            # imm = 0x160
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0x40, %esi
movq %r12, %rdi
callq 0x2210
jmp 0x2d75
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x2dde
jmp 0x2d75
jmp 0x2d72
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x2d98
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
jmp 0x2d93
movq %rax, %rbx
movl $0x78, %esi
movq %r15, %rdi
callq 0x2210
movq %rbx, %rdi
callq 0x23a0