Ejemplo n.º 1
0
void
Scene_c3t3_item::c3t3_changed()
{
  // Update colors
  // Fill indices map and get max subdomain value
  indices_.clear();

  int max = 0;
  for (C3t3::Cells_in_complex_iterator cit = this->c3t3().cells_in_complex_begin(),
    end = this->c3t3().cells_in_complex_end(); cit != end; ++cit)
  {
    max = (std::max)(max, cit->subdomain_index());
    indices_.insert(cit->subdomain_index());
  }
  for (C3t3::Facets_in_complex_iterator fit = this->c3t3().facets_in_complex_begin(),
    end = this->c3t3().facets_in_complex_end(); fit != end; ++fit)
  {
    max = (std::max)(max, fit->first->surface_patch_index(fit->second));
    indices_.insert(fit->first->surface_patch_index(fit->second));
  }

  d->colors.resize(max + 1);
  compute_color_map(color_);

  // Rebuild histogram
  build_histogram();
  
}
Ejemplo n.º 2
0
Histogram*
convert_ppm_to_histogram ( char * const ppm )
{
  /*
   * Check for P2 tag at top of file. If the P2 tag is not present,
   * return NULL.
   */
  if ( strncmp ( "P2" , strtok ( ppm , "\n" ) , 2 ) )
    return NULL;

  /*
   * Parse x_span and y_span.
   */
  unsigned int x_span = 0;
  unsigned int y_span = 0;

  sscanf ( strtok ( NULL , "\n" ) , "%u %u" , &x_span , &y_span);

  /*
   * Parse scale.
   */
  unsigned short scale = 0;

  sscanf ( strtok ( NULL , "\n" ) , "%hu" , &scale );

  /*
   * Create histogram.
   */
  Histogram* histogram = build_histogram ( x_span , y_span , scale );

  /*
   * Parse the actual histogram data.
   */

  for ( unsigned int j = 0 ; j < histogram->y_span ; ++j )
    {
      for ( unsigned int i = 0 ; i < histogram->x_span ; ++i )
        {
          unsigned short tmp = 0;
          /*
           * sscanf may be inefficeint, look into strtol
           */
          sscanf ( strtok ( NULL , " \n" ) , "%hu" , &tmp );
          histogram->data[i + j * histogram->x_span] = tmp;
        }
    }

  /*
   * Return histogram.
   */
  return histogram;
};
Ejemplo n.º 3
0
  std::vector<T>
  mode(I first, I last) {
    assert(first != last);
    assert(std::is_sorted(first, last));

    using Count = std::pair<int, T>;

    // Accumulate counts of all equivalent observations. If all
    // elements are unique, there is no mode.
    int n = count_equivalent(first, last);
    if (n == 1)
      return std::vector<T>{};

    std::vector<Count> v(n);
    build_histogram(first, last, v.begin());

    // Sort the accumulation by their counts and find the 
    // position of the first of the greatest counts.
    std::sort(v.begin(), v.end(), [](Count const& a, Count const& b) {
      return a.first < b.first;
    });
    auto bound = std::lower_bound(v.begin(), v.end(), v.back());

    // If all elements have the same count, then this
    // is an amodal distribution.
    if (bound == v.end())
      return std::vector<T>{};
    
    // Otherwise, copy out the elements with the greatest counts.
    std::vector<T> result(std::distance(bound, v.end()));
    auto iter = result.begin();
    while (bound != v.end()) {
      *iter = (*bound).second;
      ++iter;
      ++bound;
    }
    return result;
  }
Ejemplo n.º 4
0
void
Scene_c3t3_item::c3t3_changed()
{
  // Update colors
  // Fill indices map and get max subdomain value
  indices_.clear();

  int max = 0;
  for (C3t3::Cells_in_complex_iterator cit = this->c3t3().cells_in_complex_begin(),
    end = this->c3t3().cells_in_complex_end(); cit != end; ++cit)
  {
    max = (std::max)(max, cit->subdomain_index());
    indices_.insert(cit->subdomain_index());
  }

  d->colors.resize(max + 1);
  compute_color_map(color_);

  // Rebuild histogram
  build_histogram();
  //compute_elements();
  this->invalidate_buffers();
  need_changed = false;
}
Ejemplo n.º 5
0
void
Scene_c3t3_item::update_histogram()
{
  build_histogram();
}