Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int particle_count = 100000;
- float4 * particles = new float4[particle_count];
- random_init(particles,particle_count);
- debug_adaptive(particles,particle_count);
- void debug_adaptive( float4 * particles, int particle_count )
- {
- //construct particle array for sorting
- morton_sort_particle * sort_particles = new morton_sort_particle[particle_count];
- for (unsigned int i = 0; i < particle_count; i++)
- sort_particles[i] = morton_sort_particle(particles[i],-1,i);
- //number of boxes
- int box_count = (1-pow(8,(float) TREEDEPTH)) /(1-(float) 8)-1;
- int leaf_count = pow(8,(float) TREEDEPTH-1);
- //prepare boxes
- int3 * boxes = new int3[box_count];
- memset(boxes,0,sizeof(int3)*(box_count));
- //sort particles (CPU)
- sort_particles_morton(sort_particles,boxes,particle_count);
- //construct particle array
- sort_particle * adaptive_sort_particles = new sort_particle[particle_count];
- for (unsigned int i = 0; i < particle_count; i++)
- adaptive_sort_particles[i] = sort_particle(i,particles[i]);
- float side_length = 1.0;
- float3 center = make_float3(0.5,0.5,0.5);
- //...and we are ready to initialize the first box...
- Box * oct_tree = new Box(0,particle_count,center,side_length);
- std::vector<Box*> * leafs = new std::vector<Box*>();
- //...and split it recursively
- oct_tree->build_tree_adaptive(adaptive_sort_particles,*leafs,TREEDEPTH,0,100);
- //enumerate boxes in bfs fashion
- Box::assign_keys_bfs(oct_tree);
- //get all boxes
- std::vector<Box*> * flat_tree = new std::vector<Box*>();
- Box::flatten_tree(oct_tree,flat_tree);
- bool sorting_passed = true;
- for (int i = 1; i < box_count; i++) {
- int box_morton = flat_tree->at(i)->morton_box();
- float adaptive_str_sum = 0.0f;
- float regular_str_sum = 0.0f;
- int mortoncount = boxes[box_morton-1].y - boxes[box_morton-1].x;
- int adaptivecount = flat_tree->at(i)->recv_end - flat_tree->at(i)->recv_start;
- for (int j = flat_tree->at(i)->recv_start; j < flat_tree->at(i)->recv_end; j++) {
- adaptive_str_sum += adaptive_sort_particles[j].particle.w;
- }
- for (int j = boxes[box_morton-1].x; j < boxes[box_morton-1].y; j++) {
- regular_str_sum += sort_particles[j].data.w;
- }
- if (mortoncount!=adaptivecount) {
- sorting_passed = false;
- break;
- }
- if (fabs(adaptive_str_sum-regular_str_sum) > 0.1) {
- sorting_passed = false;
- break;
- }
- }
- if (sorting_passed) printf("sorting passed, carrying on!\n"); else {printf("sorting failed, shutting down!\n"); exit(0);}
- }
Add Comment
Please, Sign In to add comment