Commit ecd78b58 authored by Sabrina Templeton's avatar Sabrina Templeton
Browse files

found the bug in passing over the nearest neighbors so now it works if...

found the bug in passing over the nearest neighbors so now it works if hardcoded on c++ side. also comitting the changes which allow parallel and serial tests to be run for late
parent 102ab42c
......@@ -39,11 +39,12 @@ const int MAX_VERTS = 30;
// out vec3 v_Normal;
// out vec3 v_Parameter;
layout (triangle_strip, max_vertices = 80) out; // this was 40, upped it for debugging purposes
layout (triangle_strip, max_vertices = 100) out; // this was 40, upped it for debugging purposes
//uniform usamplerBuffer connectivity;
uniform samplerBuffer seeds;
uniform samplerBuffer nn;
uniform usamplerBuffer nn; //ask about why this has to be u I don't really understand the difference here but this is what made it work!
// render full polygon
void render_poly(vec3[MAX_VERTS] poly, vec3 center, int space){
......@@ -244,7 +245,7 @@ main() {
// lookup the seed points, taking in glPrimitiveIDIn
vec3 p0 = vec3(texelFetch( seeds , gl_PrimitiveIDIn ).xy, 0);
//vec3 p1 = vec3(texelFetch( seeds , 0 ).xy, 0);
render_square(p0, .03);
//if (gl_PrimitiveIDIn == 0){ // this is for debugging purposes: REMOVE ONCE WE WANT TO EXPAND TO ACTUALLY COMPUTE FOR MORE THAN ONE SEED
// but also when we do that we will need to fix the nearest neighbors which right now are hardcoded in
//this is the initial poly
......@@ -287,25 +288,31 @@ main() {
6, 5, 3, 2, 0, 1, 4 );
//nearest neighbor test
for (int i = 1; i < 49; i ++){
int nn_test = int(texelFetch( nn, i).x);
if (nn_test == 3) {
render_square(vec3(-.5, -.5, 0), .05);
}
}
//nearest neighbor test
// for (int i = 1; i < 49; i ++){
// int nn_test = int(texelFetch( nn, i).x);
// // if (nn_test == neighbor_hardcoded[i]) {
// // render_square(vec3(-.5, -.5, 0), .05);
// // }
// if (nn_test > 1) {
// render_square(vec3(-.8, -.8, 0), .05);
// }
// }
// this will obviously change once we are actually fetching from the nearest neighbor instead of the seed
for (int i = 1; i < 7; i ++){//super hardcoded for now
//works when i < 2 but not otherwise
//vec3 nn0 = vec3(texelFetch( seeds, i).xy, 0);
int nn0 = neighbor_hardcoded[i + (gl_PrimitiveIDIn * 7)];//int(texelFetch( nn, i + (gl_PrimitiveIDIn * 7)).x); // i + (gl_PrimitiveIDIn * 7) // remember that this is just the index, we have to use this to lookup in seeds
int nn0 = int(texelFetch( nn, i + (gl_PrimitiveIDIn * 7)).x); // i + (gl_PrimitiveIDIn * 7)
//int nn0 = neighbor_hardcoded[i + (gl_PrimitiveIDIn * 7)];//int(texelFetch( nn, i + (gl_PrimitiveIDIn * 7)).x); // i + (gl_PrimitiveIDIn * 7) // remember that this is just the index, we have to use this to lookup in seeds
vec3 nearest_neighbor = vec3(texelFetch( seeds, nn0).xy, 0);
if (i == 3){
render_square(nearest_neighbor, .04);
}
calc_poly(p0, nearest_neighbor, curr_poly, space);
......@@ -323,7 +330,7 @@ main() {
//}
//render_square(p0, .03);
render_square(p0, .03);
//}
......
......@@ -93,11 +93,13 @@ PowerDiagram::compute() {
// compute the power diagram
//printf("computing the power diagram in %ud\n",sites_.dim());
clock_t t0 = clock();
index_t nb_thread = 1;
#if PARALLEL
typedef PowerDiagram thisclass;
ProcessCPU::parallel_for(
parallel_for_member_callback( this , &thisclass::compute ), 0,cell_.size()
);
nb_thread = ProcessCPU::maximum_concurrent_threads();
#else
for (index_t k = 0; k < cell_.size(); k++) {
compute(k);
......@@ -105,7 +107,7 @@ PowerDiagram::compute() {
#endif
// record the time it took to compute the voronoi diagram
time_voronoi_ = real_t(clock()-t0)/real_t(CLOCKS_PER_SEC)/ProcessCPU::maximum_concurrent_threads();
time_voronoi_ = real_t(clock()-t0)/real_t(CLOCKS_PER_SEC)/nb_thread;
}
......
......@@ -18,10 +18,10 @@ UT_TEST_CASE( test_2d )
GEO::PCK::initialize();
static coord_t number = 2;
static coord_t dim = number+1;
index_t nb_points = 1e2;
static coord_t dim = number;
index_t nb_points = 1e4;
index_t N = 50;
index_t N = 2;
std::vector<index_t> dims(number,N);
CKF_Triangulation ckf(dims);
......
......@@ -98,8 +98,8 @@ UT_TEST_CASE( test1 )
0.15, 0.7 , 0.0,
0.55, 0.5 , 0.0,
0.01, 0.25 , 0.0,
1.0, 1.0 , 0.0,
1.0, 1.0 , 0.0,
0.8, 0.8 , 0.0,
0.9, 0.9 , 0.0,
};
// std::vector<graphics::gl_float> seeds = { // test case 2
......@@ -113,7 +113,7 @@ UT_TEST_CASE( test1 )
// };
std::vector<real_t> seeds_d( seeds.begin() , seeds.end() ); //convert the seeds to double
/*
//compute the nearest neighbors here
GEO::NearestNeighborSearch* nns = GEO::NearestNeighborSearch::create(3,"BNN"); // number of dimensions is really 2, but we have been using three
......@@ -126,11 +126,11 @@ UT_TEST_CASE( test1 )
// x[k] = random_within(0.,1.); //we will substitute seeds for this code chunk
// //x[k] = random_within(0.,1.);
/*
nns->set_points( num_points , seeds_d.data() );
index_t nb_neighbors = 0; // since there are only seven points right now, this number will probably be more like 50 later
index_t nb_neighbors = 7; // since there are only seven points right now, this number will probably be more like 50 later
std::vector<index_t> neighbors(nb_neighbors);
std::vector<double> neighbors_sq_dist(nb_neighbors);
......@@ -140,10 +140,12 @@ UT_TEST_CASE( test1 )
for (index_t k=0;k<num_points;k++)
{
nns->get_nearest_neighbors( nb_neighbors , k , neighbors.data() , neighbors_sq_dist.data() );
nns->get_nearest_neighbors( nb_neighbors , &seeds_d[k*3] , neighbors.data() , neighbors_sq_dist.data() , GEO::NearestNeighborSearch::KeepInitialValues() );
//nns->get_nearest_neighbors( nb_neighbors , &seeds_d[k*3] , neighbors.data() , neighbors_sq_dist.data() , GEO::NearestNeighborSearch::KeepInitialValues() );
//nns->get_nearest_neighbors( nb_neighbors , &seeds[k*3] , neighbors.data() , neighbors_sq_dist.data() , GEO::NearestNeighborSearch::KeepInitialValues() );
//UT_ASSERT_EQUALS( neighbors[0] , k );
//print_inline(neighbors);
//here we need to resave the neighbors in a new full neighbors array before moving on
}
......@@ -155,8 +157,10 @@ UT_TEST_CASE( test1 )
// 1.0, 1.0 , 0.0,
// 0.0, -1.0, 0.0,
// };
*/
std::vector<index_t> neighbors = {
*/
std::vector<int> neighbors_x = {
0, 1, 2, 3, 4, 5, 6,
1, 0, 4, 3, 2, 5, 6,
2, 0, 1, 3, 4, 5, 6,
......@@ -175,7 +179,7 @@ UT_TEST_CASE( test1 )
graphics::gl_index nn_buffer;
GL_CALL( glGenBuffers( 1 , &nn_buffer) );
GL_CALL( glBindBuffer( GL_TEXTURE_BUFFER , nn_buffer ) );
GL_CALL( glBufferData( GL_TEXTURE_BUFFER , sizeof(float) * neighbors.size() , neighbors.data() , GL_STATIC_DRAW ) );
GL_CALL( glBufferData( GL_TEXTURE_BUFFER , sizeof(int) * neighbors_x.size() , neighbors_x.data() , GL_STATIC_DRAW ) );
//GL_CALL( glBindBuffer( GL_ARRAY_BUFFER , 0 ) );
......@@ -214,7 +218,7 @@ UT_TEST_CASE( test1 )
GL_CALL( glGenTextures( 1, &nn_texture) );
GL_CALL( glActiveTexture( GL_TEXTURE0 + 2) );
GL_CALL( glBindTexture( GL_TEXTURE_BUFFER, nn_texture) );
GL_CALL( glTexBuffer( GL_TEXTURE_BUFFER, GL_R32I, nn_texture) );
GL_CALL( glTexBuffer( GL_TEXTURE_BUFFER, GL_R32I, nn_buffer) );
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment