Commit 102ab42c authored by Sabrina Templeton's avatar Sabrina Templeton
Browse files

diagram with hardcoded nn info, working to fix nn info

parent 1f2e13b9
......@@ -13,7 +13,7 @@ uniform float u_umin;
uniform float u_umax;
uniform samplerBuffer colormap;
uniform samplerBuffer nn;
//uniform samplerBuffer nn;
#define DEBUG 0
......
......@@ -43,6 +43,7 @@ layout (triangle_strip, max_vertices = 80) out; // this was 40, upped it for deb
//uniform usamplerBuffer connectivity;
uniform samplerBuffer seeds;
uniform samplerBuffer nn;
// render full polygon
void render_poly(vec3[MAX_VERTS] poly, vec3 center, int space){
......@@ -244,7 +245,7 @@ main() {
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
//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
vec3 curr_poly1 = vec3(0, 0, 0);
......@@ -276,30 +277,54 @@ main() {
// render_square(test_pt, .05);
//************************************************************************************************
//nearest neighbor hardcoding
int neighbor_hardcoded[49] = int[49]( 0, 1, 2, 3, 4, 5, 6,
1, 0, 4, 3, 2, 5, 6,
2, 0, 1, 3, 4, 5, 6,
3, 0, 1, 2, 4, 5, 6,
4, 1, 0, 2, 3, 5, 6,
5, 6, 3, 2, 0, 1, 4,
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);
}
}
// this will obviously change once we are actually fetching from the nearest neighbor instead of the seed
for (int i = 1; i < 5; i ++){//super hardcoded for now
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);
//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
vec3 nearest_neighbor = vec3(texelFetch( seeds, nn0).xy, 0);
calc_poly(p0, nn0, curr_poly, space);
if (i == 3){
render_square(nearest_neighbor, .04);
}
calc_poly(p0, nearest_neighbor, curr_poly, space);
}
render_square(curr_poly[0], .02);
render_square(curr_poly[1], .02);
render_square(curr_poly[2], .02);
render_square(curr_poly[3], .02);
render_square(curr_poly[4], .02);
// render_square(curr_poly[0], .02);
// render_square(curr_poly[1], .02);
// render_square(curr_poly[2], .02);
// render_square(curr_poly[3], .02);
// render_square(curr_poly[4], .02);
//if (space == 5){
render_poly(curr_poly, p0, space);
//}
render_square(p0, .03);
//render_square(p0, .03);
}
//}
......
......@@ -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 = 7; // since there are only seven points right now, this number will probably be more like 50 later
index_t nb_neighbors = 0; // 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,8 +140,9 @@ 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[k*3] , neighbors.data() , neighbors_sq_dist.data() , GEO::NearestNeighborSearch::KeepInitialValues() );
UT_ASSERT_EQUALS( neighbors[0] , k );
//UT_ASSERT_EQUALS( neighbors[0] , k );
//print_inline(neighbors);
}
......@@ -154,20 +155,28 @@ UT_TEST_CASE( test1 )
// 1.0, 1.0 , 0.0,
// 0.0, -1.0, 0.0,
// };
*/
std::vector<index_t> neighbors = {
0, 1, 2, 3, 4, 5, 6,
1, 0, 4, 3, 2, 5, 6,
2, 0, 1, 3, 4, 5, 6,
3, 0, 1, 2, 4, 5, 6,
4, 1, 0, 2, 3, 5, 6,
5, 6, 3, 2, 0, 1, 4,
6, 5, 3, 2, 0, 1, 4
};
graphics::gl_index points_buffer;
GL_CALL( glGenBuffers( 1 , &points_buffer) );
GL_CALL( glBindBuffer( GL_ARRAY_BUFFER , points_buffer ) );
GL_CALL( glBufferData( GL_ARRAY_BUFFER , sizeof(graphics::gl_float) * seeds.size() , seeds.data() , GL_STATIC_DRAW ) );
GL_CALL( glBindBuffer( GL_ARRAY_BUFFER , 0 ) );
//bind the nearest neighbor information to the buffer
graphics::gl_index nn_buffer;
GL_CALL( glGenBuffers( 1 , &nn_buffer) );
GL_CALL( glBindBuffer( GL_ARRAY_BUFFER , nn_buffer ) );
GL_CALL( glBufferData( GL_ARRAY_BUFFER , sizeof(graphics::gl_float) * neighbors.size() , neighbors.data() , GL_STATIC_DRAW ) );
GL_CALL( glBindBuffer( GL_ARRAY_BUFFER , 0 ) );
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( glBindBuffer( GL_ARRAY_BUFFER , 0 ) );
shader.setUniform("u_ModelViewProjectionMatrix",mvp);
......@@ -190,6 +199,8 @@ UT_TEST_CASE( test1 )
GL_CALL( glTexBuffer( GL_TEXTURE_BUFFER , GL_RGB32F , points_buffer ) );
// generate a texture to hold the colormap
GLuint colormap_texture;
GL_CALL( glGenTextures( 1 , &colormap_texture) );
......@@ -199,7 +210,7 @@ UT_TEST_CASE( test1 )
// generate a texture to hold the nearest neighbor information
graphics::gl_index nn_texture;
graphics::gl_index nn_texture; // does this need to be a different type
GL_CALL( glGenTextures( 1, &nn_texture) );
GL_CALL( glActiveTexture( GL_TEXTURE0 + 2) );
GL_CALL( glBindTexture( GL_TEXTURE_BUFFER, nn_texture) );
......@@ -250,10 +261,12 @@ UT_TEST_CASE( test1 )
// draw
GL_CALL( glBindBuffer(GL_ARRAY_BUFFER, points_buffer ) ); // it doesn't really matter which buffer we bind here since it isn't used
GL_CALL( glDrawArrays(GL_POINTS, 0 , 7 ) );
// swap buffers and wait for user input
......
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