// File: /workspace/github_cpp_makefile_star2_O2/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 0x7f78(%rip), %rsi      # 0xa862
pushq $0x4
popq %rdx
movq %r15, %rdi
callq 0x20d0
testl %eax, %eax
je 0x2991
leaq 0x78a1(%rip), %rsi      # 0xa1a5
pushq $0x4
popq %rdx
movq %r15, %rdi
callq 0x20d0
testl %eax, %eax
je 0x29ac
leaq 0x788c(%rip), %rsi      # 0xa1aa
pushq $0x4
popq %rdx
movq %r15, %rdi
callq 0x20d0
testl %eax, %eax
je 0x29b9
leaq 0x78dc(%rip), %rsi      # 0xa214
pushq $0x4
popq %rdx
movq %r15, %rdi
callq 0x20d0
movq %r14, %rdi
testl %eax, %eax
je 0x2b5c
callq 0x22e0
movq %rax, %rdi
callq 0x2360
movq %rbx, %rdi
callq 0x20c0
cltq
leaq (%rbx,%rax), %rdi
addq $-0xe, %rdi
leaq 0x78a5(%rip), %rsi      # 0xa219
pushq $0xe
popq %rdx
callq 0x20d0
testl %eax, %eax
je 0x2c2a
movq %r14, %rdi
callq 0x523c
jmp 0x2b61
pushq $0x78
popq %rdi
callq 0x2200
movq %rax, %r15
movq %rax, %rdi
movq %r14, %rsi
callq 0x30f6
jmp 0x2b64
movq %r14, %rdi
callq 0x408c
jmp 0x2b61
movq %r14, %rdi
xorl %esi, %esi
callq 0x4a4a
movq %rax, %r15
cmpl $0x0, 0x68(%rax)
leaq 0x7ae9(%rip), %rax      # 0xa4ba
leaq 0x77f2(%rip), %rdx      # 0xa1ca
cmoveq %rax, %rdx
movl 0x60(%r15), %ecx
leaq 0x77c8(%rip), %rdi      # 0xa1af
movq %r14, %rsi
xorl %eax, %eax
callq 0x2050
movss 0x762f(%rip), %xmm0     # 0xa028
movss 0x762b(%rip), %xmm1     # 0xa02c
movq %r15, %rdi
movl $0x2710, %esi           # imm = 0x2710
callq 0x5f20
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]
cvtss2sd %xmm2, %xmm1
cvtss2sd %xmm3, %xmm2
shufps $0x55, %xmm3, %xmm3     # xmm3 = xmm3[1,1,1,1]
cvtss2sd %xmm3, %xmm3
leaq 0x7794(%rip), %rdi      # 0xa1d1
movb $0x4, %al
callq 0x2050
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rsi
movaps %xmm0, (%rsi)
andq $0x0, 0x10(%rsi)
movq %r15, %rdi
movaps 0x50(%rsp), %xmm0
movaps 0x40(%rsp), %xmm1
movss 0x75bf(%rip), %xmm2     # 0xa028
xorl %edx, %edx
callq 0x6176
leaq 0x20(%rsp), %rsi
movq %r15, %rdi
callq 0x3bc8
movq %rax, %r14
leaq 0x776b(%rip), %rdx      # 0xa1f2
leaq 0x60(%rsp), %r12
movl $0xff, %esi
movq %r12, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2350
movq %r14, %rdi
movq %r12, %rsi
callq 0x38d8
pushq $0x40
popq %rdi
callq 0x2200
movq %rax, %r12
movq %rax, %rdi
movq %r14, %rsi
callq 0x75d8
movq %r12, 0x70(%r14)
movl 0x28(%r12), %esi
leaq 0x7733(%rip), %rdi      # 0xa202
xorl %eax, %eax
callq 0x2050
xorps %xmm0, %xmm0
movq %rsp, %rsi
movaps %xmm0, (%rsi)
andq $0x0, 0x10(%rsi)
movss 0x7544(%rip), %xmm0     # 0xa030
movl $0xc8, %edx
movl $0xf4240, %ecx          # imm = 0xF4240
movl $0xc8, %r8d
movq %r14, %rdi
callq 0x632c
movq %rsp, %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x3acc
movq %r15, %rdi
callq 0x339e
pushq $0x78
popq %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2210
movq %r14, %rdi
callq 0x339e
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2210
movq %rsp, %rdi
callq 0x2cd4
leaq 0x20(%rsp), %rdi
callq 0x2d00
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r14
popq %r15
retq
callq 0x5070
movq %rax, %r15
cmpl $0x0, 0x68(%r15)
leaq 0x794a(%rip), %rax      # 0xa4ba
leaq 0x7653(%rip), %rdx      # 0xa1ca
cmoveq %rax, %rdx
movl 0x60(%r15), %ecx
leaq 0x7629(%rip), %rdi      # 0xa1af
movq %r14, %rsi
xorl %eax, %eax
callq 0x2050
movq %rbx, %rdi
callq 0x20c0
cltq
leaq (%rbx,%rax), %r14
addq $-0x4, %r14
leaq 0x7cb9(%rip), %rsi      # 0xa862
pushq $0x4
popq %rdx
movq %r14, %rdi
callq 0x20d0
testl %eax, %eax
je 0x2bf1
leaq 0x75e6(%rip), %rsi      # 0xa1a5
pushq $0x4
popq %rdx
movq %r14, %rdi
callq 0x20d0
testl %eax, %eax
je 0x2bfe
leaq 0x7653(%rip), %rsi      # 0xa228
pushq $0x4
popq %rdx
movq %r14, %rdi
callq 0x20d0
testl %eax, %eax
jne 0x2c09
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3eee
jmp 0x2c09
movq %r15, %rdi
movq %rbx, %rsi
callq 0x38d8
jmp 0x2c09
movq %r15, %rdi
movq %rbx, %rsi
callq 0x39c4
movq %r15, %rdi
callq 0x339e
pushq $0x78
popq %rsi
movq %r15, %rdi
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x2210
movq %r14, %rdi
callq 0x8074
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x8588
movq %r14, %rdi
callq 0x8066
movl $0x90, %esi
movq %r14, %rdi
jmp 0x2c17
movq %rax, %rbx
pushq $0x40
popq %rsi
movq %r12, %rdi
callq 0x2210
jmp 0x2c74
movq %rax, %rbx
movq %rsp, %rdi
callq 0x2cd4
jmp 0x2c74
jmp 0x2c71
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x2d00
jmp 0x2c8e
movq %rax, %rbx
pushq $0x78
popq %rsi
movq %r15, %rdi
callq 0x2210
movq %rbx, %rdi
callq 0x23b0