Last active
August 29, 2015 14:17
-
-
Save Logrus/d92596529a1263f6e1f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct point{ | |
unsigned int x, y; | |
point() {}; | |
point (int a, int b) { | |
x = a; y = b; | |
} | |
bool point::operator ==(const point &a){ | |
return (x == a.x && y == a.y); | |
} | |
}; | |
point ClusterTree::sampleRand(node* n){ | |
unsigned int minx = 0; | |
unsigned int maxx = n->coordinates.size()-1; | |
unsigned int index = rand() % (maxx - minx) + minx; // random value in [min, max] | |
point p; | |
p.x = n->coordinates[index].x; | |
p.y = n->coordinates[index].y; | |
return p; | |
} | |
__global__ void _getTheHeck(int2* list, unsigned int* d_indicator, int x_size, int y_size, int index){ | |
int xId = blockDim.x * blockIdx.x + threadIdx.x; | |
int yId = blockDim.y * blockIdx.y + threadIdx.y; | |
// Check global image boundaries | |
if (xId >= x_size || yId >= y_size) | |
return; | |
if (d_indicator[yId*x_size + xId] != index){ | |
int2 p; | |
p.x = -1; | |
p.y = -1; | |
list[yId*x_size + xId] = p; | |
} | |
else{ | |
int2 p; | |
p.x = xId; | |
p.y = yId; | |
list[yId*x_size + xId] = p; | |
} | |
} | |
void ClusterTree::updateCoordinateList(node* n, int level){ | |
int2* d_list; | |
checkCudaErrors(cudaMalloc(&d_list, sizeof(int2) * image_size)); | |
checkCudaErrors(cudaMemset(d_list, 0, sizeof(int2) * image_size)); | |
_getTheHeck << <grid, block >> >(d_list, d_indicatorMat, x_size, y_size, n->index); | |
//int divisor = level; | |
//divisor <<= 1; | |
thrust::device_ptr<int2> d_list_(d_list); | |
int size = image_size; //DIV_UP(image_size, divisor); | |
int2* result = new int2[size]; | |
thrust::device_vector<int2> d_vec(size); | |
thrust::host_vector<int2> h_vec(size); | |
thrust::copy_if(d_list_, d_list_ + size, d_vec.begin(), nonneg()); | |
h_vec = d_vec; | |
thrust::copy(h_vec.begin(), h_vec.end(), result); | |
n->coordinates.clear(); | |
for (int i = 0; ; ++i){ // ! BUG HERE | |
if (i == 0 && !result[i].x && !result[i].y) { // The first point could be 0 0 for some nodes | |
point p; p.x = result[i].x; p.y = result[i].y; | |
n->coordinates.push_back(p); | |
continue; | |
} | |
if (!result[i].x && !result[i].y) break; | |
point p; | |
p.x = result[i].x; p.y = result[i].y; | |
n->coordinates.push_back(p); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment