示例#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
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_;
}
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;
}
示例#4
0
//Helper function for rasterize with built-in rotation
void HalfEllipsoid::do_rotation( location_3d<int> loc, location_3d<int> cen,
	float angle, std::vector<Geovalue> &gbRaster, GsTLGridProperty *propTi,
	std::vector<float> &facies_props, int &total_nodes )
{
	location_3d<int> loc_new = rotate_loc( loc, cen, angle );
	if ( cursor_->check_triplet( loc_new[0], loc_new[1], loc_new[2] ) ) {
		euclidean_vector_3d<int> res = loc_new-cen;
		//Check if point is outside the ellipse
		if ( !outside( res ) ) {
			if ( cursor_->check_triplet( loc[0], loc[1], loc[2] ) ) {
				int cur_node_id = cursor_->node_id( loc[0], loc[1], loc[2] );
				gbRaster.push_back( Geovalue( grid_, propTi, cur_node_id ) );
				//Update proportion of the different facies in the rotated raster
				int cur_index = propTi->get_value( cur_node_id );
				gstl_assert( ( cur_index >= 0 ) && ( cur_index < facies_props.size() ) );
				facies_props[ cur_index ]++;
				total_nodes++;
			}
		}
	}
}
示例#5
0
bool Sinusoid::accept_location( 
	const std::vector< std::vector<Geovalue> > &gbRaster,
	GsTLGridProperty *propTi )
{
	if ( all_random( min_overlap_, max_overlap_ ) ) {
		return true;
	}
	std::vector<float> facies_props;
	facies_props.insert( facies_props.begin(), min_overlap_.size(), 0.0 );
	int total_nodes = 0;

	std::vector< std::vector<Geovalue> >::const_iterator sup_itr;
	std::vector<Geovalue>::const_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 < facies_props.size() ) );
			facies_props[ cur_index ]++;
			total_nodes++;	
		}
	}
	// Compute geobody volume fractions and check geobody overlap rules 
	std::vector<float>::iterator it = facies_props.begin();
	std::vector<float>::iterator it_min = min_overlap_.begin();
	std::vector<float>::iterator it_max = max_overlap_.begin();
	for ( ; it != facies_props.end(); ++it, ++it_min, ++it_max ) { 
		 *it = *it / (float) total_nodes;  
		 if ( GsTL::equals( *it_min, *it_max ) ) {
			 if ( !GsTL::equals( *it, *it_min ) ) {
				return false;
			}
		 }
		 else if ( ( *it < *it_min ) || ( *it > *it_max ) ) { 
			return false; 
		 }
	}
	return true;
}