typename intrusive_lockfree_stack<T, E>::pop_result
intrusive_lockfree_stack<T, E>::try_pop(pointer& out)
{
    typename top_ptr::tag_type old_tag;
    out = m_top.get(old_tag);
    if(NULL == out)
        return EMPTY;
    pointer new_top(mpm_lfs_get_next(*out));
    return m_top.compare_and_swap(
            out, new_top, old_tag, old_tag + 1) ? SUCCESS : CAS_FAILED;
}
예제 #2
0
void ltPushTint(LTfloat r, LTfloat g, LTfloat b, LTfloat a) {
    LTColor new_top(r, g, b, a);
    if (!tint_stack.empty()) {
        LTColor *top = &tint_stack.front();
        new_top.red *= top->red;
        new_top.green *= top->green;
        new_top.blue *= top->blue;
        new_top.alpha *= top->alpha;
    }
    tint_stack.push_front(new_top);
    ltColor(new_top.red, new_top.green, new_top.blue, new_top.alpha);
}
예제 #3
0
파일: simbox.cpp 프로젝트: CRAVA/crava
// Constructor with two correlation surfaces -------------------------
Simbox::Simbox(const Simbox         * simbox,
               const std::string    & interval_name,
               int                    n_layers,
               double                 ext_dz,
               double                 lz_limit,
               const Surface        & top_surface,
               const Surface        & base_surface,
               const Surface        * top_corr_surface,
               const Surface        * base_corr_surface,
               int                    other_output,
               int                    output_domain,
               int                    output_format,
               std::string          & err_text,
               bool                 & failed)
: Volume(*simbox),
top_eroded_surface_(NULL),
base_eroded_surface_(NULL)
{
  std::string output_name = "";
  if (interval_name != "")
    output_name = " for interval \'" + interval_name + "\'";
  LogKit::LogFormatted(LogKit::Low,"\nCreating a temporary simbox (used for inversion grid) with two correlation surfaces" + output_name + ".\n");

  interval_name_  = interval_name;
  status_         = BOXOK;
  cosrot_         = cos(simbox->GetAngle());
  sinrot_         = sin(simbox->GetAngle());
  dx_             = simbox->getdx();
  dy_             = simbox->getdy();
  dz_             = -1;
  nx_             = simbox->getnx();
  ny_             = simbox->getny();
  nz_             = n_layers;
  nx_pad_         = nx_;
  ny_pad_         = ny_;
  nz_pad_         = nz_;
  x_pad_fac_      = (nx_pad_ / nx_);
  y_pad_fac_      = (ny_pad_ / ny_);
  z_pad_fac_      = (nz_pad_ / nz_);
  lz_eroded_      = 0;
  inLine0_        = simbox->getIL0();
  crossLine0_     = simbox->getXL0();
  ilStepX_        = simbox->getILStepX();
  ilStepY_        = simbox->getILStepY();
  xlStepX_        = simbox->getXLStepX();
  xlStepY_        = simbox->getXLStepY();
  constThick_     = simbox->getIsConstantThick();

  setDepth(top_surface, base_surface, n_layers);
  SetErodedSurfaces(top_surface, base_surface);
  //this->calculateDz(lz_limit, err_text);
  double old_dz = GetLZ() / nz_;

  //
  // Check that the two surfaces do not intersect
  //
  double x,y;
  for (size_t i = 0; i < base_surface.GetNI(); i++){
    for (size_t j = 0; j < base_surface.GetNJ(); j++){

      base_surface.GetXY(i,j,x,y);
      double z_top_corr   = top_corr_surface->GetZ(x,y);
      double z_base_corr  = base_corr_surface->GetZ(x,y);

      if (!top_corr_surface->IsMissing(z_top_corr) && !base_corr_surface->IsMissing(z_base_corr) && z_top_corr > z_base_corr) {
        std::string interval_text = "";
        if (interval_name != "")
          interval_text = " for interval " + interval_name;
        err_text += "Error: The top correlation surface crosses the base correlation surface" + interval_text + ".\n";
        failed = true;
      }
    }
  }

  //
  // Check that the correlation surfaces cover the inversion surfaces
  //
  if (simbox->CheckSurface(*top_corr_surface) == false) {
    err_text += "Error: Top correlation surface "+ top_corr_surface->GetName() +"does not cover volume.\n";
    failed = true;
  }
  if (simbox->CheckSurface(*base_corr_surface) == false){
    err_text += "Error: Base correlation surface "+ base_corr_surface->GetName() +"does not cover volume.\n";
    failed = true;
  }

  //
  // Should the corr surfaces have the same resolution?
  //

  if(!failed){
    Surface * mean_corr_surface;
    //NRLib::Vector corr_plane_parameters_top = FindPlane(top_corr_surface);
    //NRLib::Vector corr_plane_parameters_base = FindPlane(base_corr_surface);

    Surface * mean_surface;
    // Use the finest resolution
    double resolution_top   = top_corr_surface->GetDX()*top_corr_surface->GetDY();
    double resolution_base  = base_corr_surface->GetDX()*base_corr_surface->GetDY();
    if(resolution_top != resolution_base){
      if(resolution_top > resolution_base){ // base corr surface has higher resolution
        mean_surface            = new Surface(*base_corr_surface);
        mean_corr_surface       = new Surface(*base_corr_surface);
      }
      else{                                 // top corr surface has the highest resolution
        mean_surface            = new Surface(*top_corr_surface);
        mean_corr_surface       = new Surface(*top_corr_surface);
      }

    }
    else{
      mean_surface              = new Surface(*top_corr_surface);
      mean_corr_surface         = new Surface(*top_corr_surface);
    }

    // Initialize mean surface to 0
    for(size_t i = 0; i < mean_surface->GetN(); i++){
      (*mean_surface)(i)        = 0;
      (*mean_corr_surface)(i)   = 0;
    }

    // Find mean of top and base surface

    mean_surface->AddNonConform(&top_surface);
    mean_surface->AddNonConform(&base_surface);
    mean_surface->Multiply(0.5);
    NRLib::Vector ref_plane_parameters = FindPlane(mean_surface);

    // Find the mean of the top and base correlation surface
    mean_corr_surface->AddNonConform(top_corr_surface);
    mean_corr_surface->AddNonConform(base_corr_surface);
    mean_corr_surface->Multiply(0.5);
    //NRLib::Vector corr_plane_parameters = FindPlane(mean_corr_surface);


    // tilt the mean plane with the correlation plane

    NRLib::Vector corr_plane_parameters_mean = FindPlane(mean_corr_surface);
    ref_plane_parameters -= corr_plane_parameters_mean;
    grad_x_               = ref_plane_parameters(1);
    grad_y_               = ref_plane_parameters(2);

    // Create plane from parameters and add the original corr surfaces

    //Surface * ref_plane_base    = CreatePlaneSurface(ref_plane_parameters, mean_surface);
    Surface * ref_plane     = CreatePlaneSurface(ref_plane_parameters, mean_surface);

    // Create new top surface
    ref_plane->AddNonConform(top_corr_surface);
    ref_plane->AddNonConform(base_corr_surface);
    ref_plane->Multiply(0.5);
    Surface new_top(*ref_plane);
    new_top.SubtractNonConform(&(top_surface));
    double shift_top = new_top.Max();
    shift_top *= -1.0;
    new_top.Add(shift_top);
    new_top.AddNonConform(&top_surface);//new_top.AddNonConform(&(simbox->GetTopSurface())); //H?

    // Create new base surface
    //ref_plane_base->AddNonConform(base_corr_surface);
    Surface new_base(*ref_plane);
    new_base.SubtractNonConform(&(base_surface));
    double shift_bot = new_base.Min();
    shift_bot *= -1.0;

    double thick    = shift_bot-shift_top;
    double dz       = old_dz;
    if(n_layers < 0)
      dz = ext_dz;
    int    nz       = int(thick/dz);
    double residual = thick - nz*dz;
    if (residual > 0.0) {
      shift_bot += dz-residual;
      nz++;
    }

    if (nz != n_layers && n_layers > 0) {
      std::string interval_text = "";
      if (interval_name != "")
        interval_text += " in interval " + interval_name;

      LogKit::LogFormatted(LogKit::High,"\nNumber of layers" + interval_text + " increased from %d", n_layers);
      LogKit::LogFormatted(LogKit::High," to %d in grid created using the correlation direction.\n",nz);
    }

    new_base.Add(shift_bot);
    new_base.AddNonConform(&(base_surface));

    setDepth(new_top, new_base, nz);
    this->calculateDz(lz_limit, err_text);

  if((other_output & IO::EXTRA_SURFACES) > 0 && (output_domain & IO::TIMEDOMAIN) > 0) {
    std::string top_surf_name  = IO::PrefixSurface() + IO::PrefixTop() + interval_name + "_"  + IO::PrefixTime() + "_Extended";
    std::string base_surf_name = IO::PrefixSurface() + IO::PrefixBase() + interval_name + "_" + IO::PrefixTime() + "_Extended";
    if (interval_name == ""){
      top_surf_name          = IO::PrefixSurface() + IO::PrefixTop()  + IO::PrefixTime() + "_Extended";
      base_surf_name         = IO::PrefixSurface() + IO::PrefixBase() + IO::PrefixTime() + "_Extended";
    }

    WriteTopBaseSurfaceGrids(top_surf_name,
                             base_surf_name,
                             IO::PathToInversionResults(),
                             output_format);
  }

    delete  ref_plane;
    //delete  ref_plane_base;
    delete  mean_surface;
    delete  mean_corr_surface;
  }
}