Guest User

Untitled

a guest
Oct 18th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.48 KB | None | 0 0
  1.     int particle_count = 100000;
  2.     float4 * particles = new float4[particle_count];
  3.     random_init(particles,particle_count);
  4.     debug_adaptive(particles,particle_count);
  5.  
  6. void debug_adaptive( float4 * particles, int particle_count )
  7. {
  8.     //construct particle array for sorting
  9.     morton_sort_particle * sort_particles = new morton_sort_particle[particle_count];
  10.     for (unsigned int i = 0; i < particle_count; i++)
  11.         sort_particles[i] = morton_sort_particle(particles[i],-1,i);
  12.  
  13.     //number of boxes
  14.     int box_count = (1-pow(8,(float) TREEDEPTH)) /(1-(float) 8)-1;
  15.     int leaf_count = pow(8,(float) TREEDEPTH-1);
  16.  
  17.     //prepare boxes
  18.     int3 * boxes = new int3[box_count];
  19.     memset(boxes,0,sizeof(int3)*(box_count));  
  20.  
  21.     //sort particles (CPU)
  22.     sort_particles_morton(sort_particles,boxes,particle_count);
  23.  
  24.     //construct particle array
  25.     sort_particle * adaptive_sort_particles = new sort_particle[particle_count];
  26.     for (unsigned int i = 0; i < particle_count; i++)
  27.         adaptive_sort_particles[i] = sort_particle(i,particles[i]);
  28.  
  29.     float side_length = 1.0;
  30.     float3 center = make_float3(0.5,0.5,0.5);
  31.  
  32.     //...and we are ready to initialize the first box...
  33.     Box * oct_tree = new Box(0,particle_count,center,side_length);
  34.     std::vector<Box*> * leafs = new std::vector<Box*>();
  35.  
  36.     //...and split it recursively
  37.     oct_tree->build_tree_adaptive(adaptive_sort_particles,*leafs,TREEDEPTH,0,100); 
  38.  
  39.     //enumerate boxes in bfs fashion
  40.     Box::assign_keys_bfs(oct_tree);
  41.  
  42.     //get all boxes
  43.     std::vector<Box*> * flat_tree = new std::vector<Box*>();
  44.     Box::flatten_tree(oct_tree,flat_tree);
  45.  
  46.     bool sorting_passed = true;
  47.  
  48.     for (int i = 1; i < box_count; i++) {
  49.  
  50.         int box_morton = flat_tree->at(i)->morton_box();
  51.        
  52.         float adaptive_str_sum = 0.0f;
  53.         float regular_str_sum = 0.0f;
  54.  
  55.         int mortoncount = boxes[box_morton-1].y - boxes[box_morton-1].x;
  56.         int adaptivecount = flat_tree->at(i)->recv_end - flat_tree->at(i)->recv_start;
  57.  
  58.         for (int j = flat_tree->at(i)->recv_start; j < flat_tree->at(i)->recv_end; j++) {
  59.             adaptive_str_sum += adaptive_sort_particles[j].particle.w;
  60.         }
  61.  
  62.         for (int j = boxes[box_morton-1].x; j < boxes[box_morton-1].y; j++) {
  63.             regular_str_sum += sort_particles[j].data.w;
  64.         }
  65.  
  66.         if (mortoncount!=adaptivecount) {
  67.             sorting_passed = false;
  68.             break;
  69.         }
  70.  
  71.         if (fabs(adaptive_str_sum-regular_str_sum) > 0.1) {
  72.             sorting_passed = false;
  73.             break;
  74.         }
  75.            
  76.     }
  77.  
  78.     if (sorting_passed) printf("sorting passed, carrying on!\n"); else {printf("sorting failed, shutting down!\n"); exit(0);}
  79.  
  80. }
Add Comment
Please, Sign In to add comment