示例#1
0
void HalfEllipsoid::draw( Geovalue &gval, GsTLGridProperty *propTi )
{
	grid_->select_property( propTi->name() ); 
	
	double p = gen_();
	rmax_ = get_max_radius( p );
	rmed_ = get_med_radius( p );
	rmin_ = get_min_radius( p );
	
	//Convert angles to radian
	float strike = get_orientation( p );
	float deg_to_rad = -3.14159265/180; 
	if ( strike > 180 ) strike -= 360; 
	if ( strike < -180 ) strike += 360; 
    strike *= deg_to_rad;

	int node_id = gval.node_id();
	std::vector<float> facies_props;
	std::vector<Geovalue> gbRaster = rasterize( node_id, propTi, strike, facies_props );
	
	rasterizedVol_ = 0;
	if ( accept_location( facies_props ) ) {
		std::vector<Geovalue>::iterator gv_itr;	
		for ( gv_itr = gbRaster.begin(); gv_itr != gbRaster.end(); ++gv_itr ) {
			int cur_index = propTi->get_value( gv_itr->node_id() );
			gstl_assert( ( cur_index >= 0 ) && ( cur_index < erosion_rules_.size() ) );
			if ( cur_index != geobody_index_ ) {
				if ( erosion_rules_[cur_index] == 1 ) { //decrease proportion of eroded geobodies?
					propTi->set_value( geobody_index_, gv_itr->node_id() );
					rasterizedVol_++;
				}
			}
		}
	}
}
示例#2
0
//Computes rotated channel raster
std::vector < std::vector<Geovalue> > Sinusoid::rasterize( int node_id, 
	GsTLGridProperty *propTi, float angle, Matrix_2D Rz ) 
{
	const double PI = 3.1415926538;
	int i,j,k;
	cursor_->coords( node_id, i, j, k );

	double p = gen_();
	hellip_->set_dimensions( p );

	std::vector < std::vector<Geovalue> > chRaster;
	std::vector<Geovalue> hellipRaster;
	std::pair<int, int> points;
	int prev_nodeID = -1;
	for ( float jj = -half_length_; jj < half_length_; jj+=0.002 ) {
		float ii = amp_*sin( 2 * PI * jj / wvlength_ );
		int ii_rot = GsTL::round( Rz(1,1)*((i+ii)-i) + Rz(1,2)*((j+jj)-j) + i );
		int jj_rot = GsTL::round( Rz(2,1)*((i+ii)-i) + Rz(2,2)*((j+jj)-j) + j );
		points.first = i + ii_rot;
		points.second = j + jj_rot;
		int nodeID_points = cursor_->node_id( points.first, points.second, k );
		if ( ( nodeID_points >-1 ) && ( nodeID_points < grid_->nxyz() ) ) {
			if ( nodeID_points != prev_nodeID ) {
				float ellip_angle = -angle+(PI/2);
				hellipRaster = hellip_->rasterize( nodeID_points, propTi, ellip_angle );
				if ( !hellipRaster.empty() ) {
					chRaster.push_back( hellipRaster );
					prev_nodeID = nodeID_points;
				}
			}
		}
	}
	return chRaster;
}
示例#3
0
local_tag::local_tag(ns_service * ns_service,
                     const std::string name) :
  ns_service_(ns_service),
  gen_(ID::null()),
  id_(gen_(name)),
  name_(name)
{
}
示例#4
0
void Sinusoid::draw( Geovalue &gval, GsTLGridProperty *propTi )
{
	grid_->select_property( propTi->name() ); 

	double p = gen_();
	get_length( p );
	get_width( p );
	depth_ = cdf_depth_->inverse( p );

	//Convert angle to radian & do checks
	float strike = get_orientation( p );
	float deg_to_rad = 3.14159265/180;
	if ( strike > 180 ) strike -= 360;  
	if ( strike < -180 ) strike += 360; 
    strike *= deg_to_rad;

	amp_ = get_amplitude( p );
	wvlength_ = get_wavelength( p );

	// Channel cross-section is defined by a lower half ellipsoid
	// whose max radius equals channel width, med_radius = 1,
	// and min radius equals channel depth
	cdfType* cdf_hellipRot = new Dirac_cdf( 0.0 );
	cdfType* cdf_hellipMaxr = new Dirac_cdf( half_width_ ); 
	cdfType* cdf_hellipMedr = new Dirac_cdf( 1 );
	cdfType* cdf_hellipMinr = new Dirac_cdf( depth_ );

	int lower_half = 1;
	hellip_ = new HalfEllipsoid(
		grid_, geobody_index_, lower_half,
		cdf_hellipRot, cdf_hellipMaxr, cdf_hellipMedr, 
		cdf_hellipMinr, objErosion_, objOverlap_
	);

	int node_id = gval.node_id();
	Matrix_2D rot = get_rot_matrix( strike );
	std::vector<std::vector<Geovalue> > gbRaster = rasterize( node_id, propTi, strike, rot );

	rasterizedVol_ = 0;
	if ( accept_location( gbRaster, propTi ) ) {
		std::vector< std::vector<Geovalue> >::iterator sup_itr;
		std::vector<Geovalue>::iterator gv_itr;
		for ( sup_itr = gbRaster.begin(); sup_itr != gbRaster.end(); ++sup_itr ) {
			gv_itr = sup_itr->begin();
			for ( ; gv_itr != sup_itr->end(); ++gv_itr ) {
				int cur_index = propTi->get_value( gv_itr->node_id() );
				gstl_assert( ( cur_index >= 0 ) && ( cur_index < erosion_rules_.size() ) );
				if ( cur_index != geobody_index_ ) {
					if ( erosion_rules_[cur_index] == 1 ) { // Decrease proportion of eroded index?
						propTi->set_value( geobody_index_, gv_itr->node_id() );
						rasterizedVol_++;
					}
				}
			}
		}
	} 
	delete hellip_;
}
      void
      fill_random (const Ordinal nrows, 
		   const Ordinal ncols, 
		   Scalar A[], 
		   const Ordinal lda)
      {
	for (Ordinal j = 0; j < ncols; ++j)
	  {
	    Scalar* const A_j = &A[j*lda];
	    for (Ordinal i = 0; i < nrows; ++i)
	      A_j[i] = gen_();
	  }
      }
int Layer_servo_system_sampler< RandNumberGenerator, ComputeLayerIndex >::
operator () ( GeoValue& gval, const CategNonParamCdf& ccdf ) 
{
	typedef typename CategNonParamCdf::value_type value_type;
	typedef typename CategNonParamCdf::p_iterator p_iterator;

	int z = getLayerIndex_( gval );

	const double tolerance = 0.01;
	Categ_non_param_cdf<int> corrected_ccdf( ccdf  );

	// Don't try to correct the ccdf if nb_of_data_ = 0
	if( nb_of_data_[z] != 0 ) 
	{
		// Correct each probability value of the cpdf
		int i=0;
		for( p_iterator p_it=corrected_ccdf.p_begin() ; 
				p_it != corrected_ccdf.p_end(); ++p_it, ++i) 
		{
			// If the probability is extreme (ie close to 0 or 1), don't touch it
			if(*p_it < tolerance || *p_it > 1-tolerance) continue; 

			// Correct each probability 
			*p_it += mu_ * ( target_pdf_[z][i] - current_histogram_[z][i]/nb_of_data_[z] );

			// reset the probability between 0 and 1 if needed.
			*p_it = std::max(*p_it, 0.0);
			*p_it = std::min(*p_it, 1.0);
		}

		// corrected_ccdf now contains a pdf which may not be valid, i.e. it is not 
		// garanteed that the probabilities add-up to 1.
		corrected_ccdf.make_valid();
	}


	// Draw a realization from ccdf and update the servo system
	// A comment about types: "realization" should be of integral type (eg int)
	// but GeoValue::property_type could be different (eg float).
	typedef typename CategNonParamCdf::value_type value_type;
	typedef typename GeoValue::property_type property_type;
	value_type realization = corrected_ccdf.inverse( gen_() );

	gval.set_property_value( static_cast<property_type>(realization) );
	nb_of_data_[z] ++;
	gstl_assert( realization>=0  &&  
		realization < static_cast<int>(current_histogram_[z].size()) );
	current_histogram_[z][ realization ] ++;

	return 0;
}
示例#7
0
    result_type operator()( float x, float y = 0, float z = 0) const
	{
		float freq = 1.0f;
		float scale = 1.0f;

		result_type result = gen_( x, y, z);
		scale *= gain_;
		freq *= lacunarity_;
		
		for( int i = 1; i < octaves_; ++i)
		{
			result_type v = gen_( x * freq, y * freq, z * freq) * scale;
	
			if( turbulent_)
				v = abs( v);
	
			result += v;
			scale *= gain_;
			freq *= lacunarity_;
		}
	
		return result / norm_;
	}
示例#8
0
 /** \brief the method to generate the random variable with given distribution */
 double operator()() {
     return getQuantile( gen_() );
 }
示例#9
0
bool CollisionModel::sampleForR(int seed, const std::string &link_name, const Eigen::Vector2d &r, Eigen::Vector3d &p, Eigen::Vector4d &q) const {
    std::map<std::string, LinkCollisionModel >::const_iterator it = link_models_map_.find( link_name );
    if (it == link_models_map_.end()) {
        return false;
    }
    const std::vector<Feature > &features = it->second.features_;
    std::mt19937 gen_(seed);

    const int n_points = features.size();
    std::vector<double > weights(n_points, 0.0);

    double result_x, result_y, result_z;
    Eigen::Vector4d result_q;

    // sample the x coordinate
    double sum = 0.0;
    for (int pidx = 0; pidx < n_points; pidx++) {
//            if (std::fabs(r(0) - features[pidx].pc1) > r_dist_max_ || std::fabs(r(1) - features[pidx].pc2) > r_dist_max_ || features[pidx].weight < 0.0000001) {
//                weights[pidx] = 0.0;
//            }
//            else {
        weights[pidx] = features[pidx].weight * biVariateIsotropicGaussianKernel(r, Eigen::Vector2d(features[pidx].pc1, features[pidx].pc2), sigma_r_);
//            }
        sum += weights[pidx];
    }

    Feature random_kernel;
    double rr = randomUniform(0.0, sum);
    for (int pidx = 0; pidx < n_points; pidx++) {
        rr -= weights[pidx];
        if (rr <= 0.0) {
            random_kernel = features[pidx];
            break;
        }
    }

    Eigen::Vector4d mean_q;
    result_x = random_kernel.T_C_F.p.x();
    result_y = random_kernel.T_C_F.p.y();
    result_z = random_kernel.T_C_F.p.z();
    random_kernel.T_C_F.M.GetQuaternion(mean_q(0), mean_q(1), mean_q(2), mean_q(3));

    std::normal_distribution<> d = std::normal_distribution<>(result_x, sigma_p_);
    result_x = d(gen_);
    d = std::normal_distribution<>(result_y, sigma_p_);
    result_y = d(gen_);
    d = std::normal_distribution<>(result_z, sigma_p_);
    result_z = d(gen_);

    int iterations = orientationNormalSample(mean_q, sigma_q_, result_q);
    if (iterations < 0) {
        std::cout << "ERROR: orientationNormalSample" << std::endl;
    }

    p(0) = result_x;
    p(1) = result_y;
    p(2) = result_z;
    q = result_q;

    return true;
}
示例#10
0
文件: gui.c 项目: hyz/dotfiles
int gui_main(char const* (*gen_)(int), void (*poll_)(), void(*stop_)()) //(int ac, char* const av[])
{
    GdiFont* font;
    struct nk_context *ctx;

    WNDCLASSW wc;
    ATOM atom;
    RECT rect = { 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT };
    DWORD style = WS_OVERLAPPEDWINDOW;
    DWORD exstyle = WS_EX_APPWINDOW;
    HWND wnd;
    HDC dc;
    int running = 1;
    int needs_refresh = 1;

    /* Win32 */
    memset(&wc, 0, sizeof(wc));
    wc.lpfnWndProc = WindowProc;
    wc.hInstance = GetModuleHandleW(0);
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.lpszClassName = L"NuklearWindowClass";
    atom = RegisterClassW(&wc);

    AdjustWindowRectEx(&rect, style, FALSE, exstyle);

    wnd = CreateWindowExW(exstyle, wc.lpszClassName, L"Lucky",
        style | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT,
        rect.right - rect.left, rect.bottom - rect.top,
        NULL, NULL, wc.hInstance, NULL);
    dc = GetDC(wnd);

    /* GUI */
    font = nk_gdifont_create("Arial", 14);
    ctx = nk_gdi_init(font, dc, WINDOW_WIDTH, WINDOW_HEIGHT);
    while (running) {
        MSG msg;
        poll_();

        /* Input */
        nk_input_begin(ctx);
        if (needs_refresh == 0)
        {
            if (GetMessageW(&msg, NULL, 0, 0) <= 0)
            {
                running = 0;
            }
            else
            {
                TranslateMessage(&msg);
                DispatchMessageW(&msg);
            }
            needs_refresh = 1;
        }
        else
        {
            needs_refresh = 0;
        }
        while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE))
        {
            if (msg.message == WM_QUIT)
                running = 0;
            TranslateMessage(&msg);
            DispatchMessageW(&msg);
            needs_refresh = 1;
        }
        nk_input_end(ctx);

        /* GUI */
        {struct nk_panel layout;
        if (nk_begin(ctx, &layout, "Demo", nk_rect(60, 0, 120, 320), 0))
            //NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE
        {
            enum {EASY, HARD};
            static int op = EASY;
            static int property = 20;

            //nk_layout_row_static(ctx, 30, 80, 1);
            nk_layout_row_dynamic(ctx, 30, 1);
            if (nk_button_label(ctx, "三码", NK_BUTTON_DEFAULT)) {
                notepad_open(gen_(3));
            }
            if (nk_button_label(ctx, "二码", NK_BUTTON_DEFAULT)) {
                notepad_open(gen_(2));
            }
            if (nk_button_label(ctx, "one", NK_BUTTON_DEFAULT)) {
                notepad_open(gen_(1));
            }

#if 0
            if (nk_button_label(ctx, "四码", NK_BUTTON_DEFAULT)) {
                notepad_open(gen_(4));
            }
            if (nk_button_label(ctx, "五码", NK_BUTTON_DEFAULT)) {
                notepad_open(gen_(5));
            }
            if (nk_button_label(ctx, "六码", NK_BUTTON_DEFAULT)) {
                notepad_open(gen_(6));
            }
			if (nk_button_label(ctx, "七码", NK_BUTTON_DEFAULT)) {
				notepad_open(gen_(7));
			}
			if (nk_button_label(ctx, "八码", NK_BUTTON_DEFAULT)) {
				notepad_open(gen_(8));
			}
			if (nk_button_label(ctx, "九码", NK_BUTTON_DEFAULT)) {
				notepad_open(gen_(9));
			}
			if (nk_button_label(ctx, "十码", NK_BUTTON_DEFAULT)) {
				notepad_open(gen_(10));
			}
#endif
            //nk_layout_row_dynamic(ctx, 30, 2);
            //if (nk_option_label(ctx, "easy", op == EASY)) op = EASY;
            //if (nk_option_label(ctx, "hard", op == HARD)) op = HARD;
            //nk_layout_row_dynamic(ctx, 22, 1);
            //nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1);
        }
        nk_end(ctx);}
        if (nk_window_is_closed(ctx, "Demo")) break;

        /* Draw */
        nk_gdi_render(nk_rgb(30,30,30));
    }
    stop_();

    nk_gdifont_del(font);
    ReleaseDC(wnd, dc);
    UnregisterClassW(wc.lpszClassName, wc.hInstance);
    return 0;
}
示例#11
0
int Randomizer::Random(int a, int b) {
        std::random_device rd_;
        std::mt19937 gen_(rd_());
	std::uniform_int_distribution<> dis(a, b);
	return dis(gen_);
}
示例#12
0
        /** \brief the method to generate the random variable in given range, uniform distribution */
        double operator()() {
			boost::mutex::scoped_lock scoped_lock(access_);
			return gen_();
        }
示例#13
0
 bool operator()(idx_t& eo) override {
     auto by = gen_();
     eo = bounds_.add(eo, by);
     return by;
 }
示例#14
0
 bool operator()(idx_t& eo) override {
     auto by = gen_();
     eo += by;
     return by;
 }