// File: jingdao[P]PointCloudApp/pcd.cpp
// Function: PCD::euclideanClusteringKDTree(std::vector<std::vector<int, std::allocator<int>>, std::allocator<std::vector<int, std::allocator<int>>>>*, float, unsigned long, unsigned long, unsigned long)
void PCD::euclideanClusteringKDTree(std::vector<std::vector<int>> *indices,float distance,size_t minSize,size_t maxSize,size_t maxClusters) {
	if (!kdtree) kdtree = new KdTree(this);
	bool* visited = new bool[numPoints]();
	for (int i=0;i<numPoints;i++) {
		if (visited[i]) continue;
//		printf("%d %lu\n",i,indices->size());
		std::vector<int> P,Q,neighbors;
		Q.push_back(i);
		visited[i] = true;
		while (Q.size() > 0) {
			int p = Q[Q.size()-1];
			Q.pop_back();
			P.push_back(p);
			kdtree->search(&neighbors,float_data[p*4],float_data[p*4+1],float_data[p*4+2],distance);
			for (size_t j=0;j<neighbors.size();j++) {
				if (!visited[neighbors[j]]) {
					Q.push_back(neighbors[j]);
					visited[neighbors[j]] = true;
				}
			}
			neighbors.clear();
		}
		if (P.size() >= minSize && P.size() <= maxSize)
			indices->push_back(P);
		if (indices->size() >= maxClusters)
			break;
	}
	delete[] visited;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movss %xmm0, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xb8(%rbp)
cmpq $0x0, 0x70(%rax)
jne 0x9b11
movl $0x40, %edi
callq 0x2200
movq -0xb8(%rbp), %rsi
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xc0(%rbp)
callq 0xde90
jmp 0x9adb
movq -0xb8(%rbp), %rax
movq -0xc0(%rbp), %rcx
movq %rcx, 0x70(%rax)
jmp 0x9b11
movq -0xc0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
movl $0x40, %esi
callq 0x2210
jmp 0x9e23
movq -0xb8(%rbp), %rax
movslq 0x60(%rax), %rdi
movq %rdi, -0xd0(%rbp)
callq 0x2040
movq -0xd0(%rbp), %rdx
movq %rax, %rdi
movq %rdi, -0xc8(%rbp)
xorl %esi, %esi
callq 0x2100
movq -0xc8(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movq -0xb8(%rbp), %rcx
movl -0x4c(%rbp), %eax
cmpl 0x60(%rcx), %eax
jge 0x9dfd
movq -0x48(%rbp), %rax
movslq -0x4c(%rbp), %rcx
testb $0x1, (%rax,%rcx)
je 0x9b78
jmp 0x9def
leaq -0x68(%rbp), %rdi
callq 0x3130
leaq -0x80(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0x3130
leaq -0x98(%rbp), %rdi
callq 0x3130
movq -0xd8(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
callq 0xae30
jmp 0x9baf
movq -0x48(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movb $0x1, (%rax,%rcx)
leaq -0x80(%rbp), %rdi
callq 0xaca0
cmpq $0x0, %rax
jbe 0x9d6d
leaq -0x80(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0xaca0
movq -0xe0(%rbp), %rdi
movq %rax, %rsi
decq %rsi
callq 0xacc0
movq -0xe0(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x9c(%rbp)
callq 0xaea0
leaq -0x68(%rbp), %rdi
leaq -0x9c(%rbp), %rsi
callq 0xae30
jmp 0x9c16
movq -0xb8(%rbp), %rcx
movq 0x58(%rcx), %rax
movq 0x70(%rcx), %rdi
movl -0x9c(%rbp), %ecx
shll $0x2, %ecx
movslq %ecx, %rcx
movss (%rax,%rcx,4), %xmm0
movss 0x4(%rax,%rcx,4), %xmm1
movss 0x8(%rax,%rcx,4), %xmm2
movss -0x14(%rbp), %xmm3
leaq -0x98(%rbp), %rsi
callq 0xe3e0
jmp 0x9c55
movq $0x0, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0xe8(%rbp)
leaq -0x98(%rbp), %rdi
callq 0xaca0
movq %rax, %rcx
movq -0xe8(%rbp), %rax
cmpq %rcx, %rax
jae 0x9d5c
movq -0x48(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0xa8(%rbp), %rsi
leaq -0x98(%rbp), %rdi
callq 0xacc0
movq %rax, %rcx
movq -0xf0(%rbp), %rax
movslq (%rcx), %rcx
testb $0x1, (%rax,%rcx)
jne 0x9d43
movq -0xa8(%rbp), %rsi
leaq -0x98(%rbp), %rdi
callq 0xacc0
movq %rax, %rsi
leaq -0x80(%rbp), %rdi
callq 0xae30
jmp 0x9ce3
movq -0x48(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0xa8(%rbp), %rsi
leaq -0x98(%rbp), %rdi
callq 0xacc0
movq %rax, %rcx
movq -0xf8(%rbp), %rax
movslq (%rcx), %rcx
movb $0x1, (%rax,%rcx)
jmp 0x9d43
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x31d0
leaq -0x80(%rbp), %rdi
callq 0x31d0
leaq -0x68(%rbp), %rdi
callq 0x31d0
jmp 0x9e23
jmp 0x9d45
movq -0xa8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa8(%rbp)
jmp 0x9c60
leaq -0x98(%rbp), %rdi
callq 0xaed0
jmp 0x9bbb
leaq -0x68(%rbp), %rdi
callq 0xaca0
cmpq -0x20(%rbp), %rax
jb 0x9d9c
leaq -0x68(%rbp), %rdi
callq 0xaca0
cmpq -0x28(%rbp), %rax
ja 0x9d9c
movq -0x10(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0xaef0
jmp 0x9d9a
jmp 0x9d9c
movq -0x10(%rbp), %rdi
callq 0xa9d0
cmpq -0x30(%rbp), %rax
jb 0x9db7
movl $0x2, -0xac(%rbp)
jmp 0x9dc1
movl $0x0, -0xac(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x31d0
leaq -0x80(%rbp), %rdi
callq 0x31d0
leaq -0x68(%rbp), %rdi
callq 0x31d0
movl -0xac(%rbp), %eax
testl %eax, %eax
je 0x9ded
jmp 0x9deb
jmp 0x9dfd
jmp 0x9def
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x9b52
movq -0x48(%rbp), %rax
movq %rax, -0x100(%rbp)
cmpq $0x0, %rax
je 0x9e1a
movq -0x100(%rbp), %rdi
callq 0x2250
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x2380
nopl (%rax)