void Combined_neighborhood::find_neighbors( const Geovalue& center ) { neighbors_.clear(); center_ = center; /* this version was not good first_->find_neighbors( center ); if( first_->size() < max_size_ ) { second_->max_size( max_size_ - first_->size() ); second_->find_neighbors( center ); } neighbors_.resize( first_->size() + second_->size() ); iterator end = std::copy( first_->begin(), first_->end(), neighbors_.begin() ); std::copy( second_->begin(), second_->end(), end ); */ // ask both neighborhoods to search neighbors first_->find_neighbors( center ); second_->find_neighbors( center ); neighbors_.resize( first_->size() + second_->size() ); // select those that are closest to "center" from both neighborhoods if( cov_ ) std::merge( first_->begin(), first_->end(), second_->begin(), second_->end(), neighbors_.begin(), Geovalue_covariance_comparator(center.location(), *cov_) ); else std::merge( first_->begin(), first_->end(), second_->begin(), second_->end(), neighbors_.begin(), Geovalue_comparator(center.location() ) ); if( neighbors_.size() > max_size_ ) neighbors_.erase( neighbors_.begin() + max_size_, neighbors_.end() ); }
// g1 < g2 if the covariance between g1 and the center is higher bool operator() (const Geovalue& g1, const Geovalue& g2 ) const { location_type g1_loc = g1.location(); location_type g2_loc = g2.location(); bool is_same_loc = GsTL::equals( g1_loc.x(),g2_loc.x() ) && GsTL::equals( g1_loc.y(),g2_loc.y() ) && GsTL::equals( g1_loc.z(),g2_loc.z() ); return is_same_loc; }
void Cosisim::code_into_indicators( Geovalue& g ) { float val = g.property_value(); int node_id = g.node_id(); for( unsigned int i= 0 ; i < indicators_.size(); i++ ) { if( !indicators_[i]->is_harddata( node_id ) ) { float thresh = *(marginal_->z_begin() + i); indicators_[i]->set_value( indicator_coder_( val, thresh ), node_id ); } } }
void Combined_neighborhood::find_neighbors( const Geovalue& center ) { neighbors_.clear(); center_ = center; neigh_filter_->clear(); /* this version was not good first_->find_neighbors( center ); if( first_->size() < max_size_ ) { second_->max_size( max_size_ - first_->size() ); second_->find_neighbors( center ); } neighbors_.resize( first_->size() + second_->size() ); iterator end = std::copy( first_->begin(), first_->end(), neighbors_.begin() ); std::copy( second_->begin(), second_->end(), end ); */ // ask both neighborhoods to search neighbors first_->find_neighbors( center ); second_->find_neighbors( center ); std::sort(second_->begin(), second_->end(),Geovalue_covariance_comparator(center.location(), *cov_)); std::vector<Geovalue> neighbors_temp; neighbors_temp.resize( first_->size() + second_->size() ); neighbors_.reserve( first_->size() + second_->size() ); // select those that are closest to "center" from both neighborhoods if( cov_ ) std::merge( first_->begin(), first_->end(), second_->begin(), second_->end(), neighbors_temp.begin(), Geovalue_covariance_comparator(center.location(), *cov_) ); else std::merge( first_->begin(), first_->end(), second_->begin(), second_->end(), neighbors_temp.begin(), Geovalue_comparator(center.location() ) ); Neighborhood::iterator it_unique = std::unique(neighbors_temp.begin(), neighbors_temp.end(),Geovalue_location_comparator() ); // neighbors_temp.erase( it_unique, neighbors_temp.end() ); Neighborhood::iterator it_neigh = neighbors_temp.begin(); for( ; it_neigh != it_unique; ++it_neigh ) { if(neigh_filter_->is_admissible(*it_neigh, center)) { neighbors_.push_back( *it_neigh ); } } if( neighbors_.size() > max_size_ ) neighbors_.erase( neighbors_.begin() + max_size_, neighbors_.end() ); }
void MgridNeighborhood_hd::find_neighbors( const Geovalue& center ) { appli_assert( center.grid() == grid_ ); _mcursor = dynamic_cast<EGridCursor*>(grid_->cursor()); appli_assert(_mcursor); // This is exactly the same function as // Rgrid_ellips_neighborhood::find_neighbors, except that the condition // for a node to be a neighbor is that it contains a hard-data neighbors_.clear(); if( !property_ ) return; center_ = center; center_.set_property_array( property_ ); Grid_template::const_iterator it = geom_.begin(); Grid_template::const_iterator end = geom_.end(); GsTLGridNode loc; _mcursor->coords( center.node_id(), loc[0], loc[1], loc[2] ); // "already_found" is the number of neighbors already found int already_found=0; if( includes_center_ && center_.is_harddata() ) { neighbors_.push_back( center_ ); already_found++; } while( it != end && already_found < max_neighbors_ ) { GsTLGridNode node = loc + (*it); GsTLInt node_id = _mcursor->node_id( node[0], node[1], node[2] ); if( node_id < 0 ) { it++; continue; } if( property_->is_harddata( node_id ) ) { neighbors_.push_back( Geovalue( grid_, property_, node_id ) ); already_found++; } it++; } }
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_++; } } } } }
void Rgrid_window_neighborhood::find_all_neighbors( const Geovalue& center ) { size_ = -1; center_ = center; center_.set_property_array( property_ ); neighbors_.clear(); if( !property_ ) return; SGrid_cursor cursor( *grid_->cursor() ); GsTLInt i,j,k; cursor.coords( center.node_id(), i,j,k ); GsTLGridNode center_location( i,j,k ); if( geom_.size() == 0 ) return; Grid_template::iterator begin = geom_.begin(); Grid_template::iterator bound = geom_.end()-1; for( ; begin != bound+1 ; ++begin ) { GsTLGridNode node = center_location + (*begin); neighbors_.push_back( Geovalue( grid_, property_, cursor_.node_id( node[0], node[1], node[2] ) ) ); } }
void MgridWindowNeighborhood::find_all_neighbors( const Geovalue& center ) { size_ = -1; center_ = center; center_.set_property_array( property_ ); _mcursor = dynamic_cast<EGridCursor*>(grid_->cursor()); neighbors_.clear(); if( !property_ ) return; //SGrid_cursor cursor( *grid_->cursor() ); GsTLInt i,j,k; _mcursor->coords( center.node_id(), i,j,k ); GsTLGridNode center_location( i,j,k ); if( geom_.size() == 0 ) return; Grid_template::iterator begin = geom_.begin(); Grid_template::iterator bound = geom_.end()-1; for( ; begin != bound+1 ; ++begin ) { GsTLGridNode node = center_location + (*begin); if (_mcursor->node_id( node[0], node[1], node[2] ) < 0) continue; neighbors_.push_back( Geovalue( grid_, property_, _mcursor->node_id( node[0], node[1], node[2] ) ) ); } }
// g1 < g2 if the covariance between g1 and the center is higher bool operator() (const Geovalue& g1 ) const { location_type g1_loc = g1.location(); bool is_same_loc = GsTL::equals( center_.x(),g1_loc.x() ) && GsTL::equals( center_.y(),g1_loc.y() ) && GsTL::equals( center_.z(),g1_loc.z() ); return is_same_loc; }
void Combined_neighborhood_dedup::find_neighbors( const Geovalue& center ){ neighbors_.clear(); center_ = center; // ask both neighborhoods to search neighbors first_->find_neighbors( center ); second_->find_neighbors( center ); // remove the colocated neighbors iterator end_1st = first_->end(); iterator end_2nd = second_->end(); if(!first_->is_empty() && !second_->is_empty()) { if(override_first_ ) { for(iterator it= second_->begin(); it!=second_->end(); ++it ){ iterator new_last = std::remove_if(first_->begin(),end_1st, Location_comparator(it->location()) ); end_1st = new_last; } } else { for(iterator it= first_->begin(); it!=first_->end(); ++it ){ iterator new_last = std::remove_if(second_->begin(),end_2nd, Location_comparator(it->location()) ); end_2nd = new_last; } } } //neighbors_.resize( first_->size() + second_->size() ); neighbors_.resize( std::distance(first_->begin(),end_1st) + std::distance(second_->begin(),end_2nd) ); // select those that are closest to "center" from both neighborhoods if( cov_ ) std::merge( first_->begin(), end_1st, second_->begin(), end_2nd, neighbors_.begin(), Geovalue_covariance_comparator(center.location(), *cov_) ); else std::merge( first_->begin(), end_1st, second_->begin(), end_2nd, neighbors_.begin(), Geovalue_comparator(center.location() ) ); if( neighbors_.size() > max_size_ ) neighbors_.erase( neighbors_.begin() + max_size_, neighbors_.end() ); }
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 Rgrid_window_neighborhood::find_neighbors( const Geovalue& center ) { size_ = -1; center_ = center; center_.set_property_array( property_ ); neighbors_.clear(); if( !property_ ) return; SGrid_cursor cursor( *grid_->cursor() ); GsTLInt i,j,k; cursor.coords( center.node_id(), i,j,k ); GsTLGridNode center_location( i,j,k ); if( geom_.size() == 0 ) return; Grid_template::iterator begin = geom_.begin(); Grid_template::iterator bound = geom_.end()-1; /* nico: old code, remove if new works properly while (bound != begin-1) { GsTLGridNode p = center_location + (*bound); if( !grid_->contains( p ) ) { bound--; continue; } if( grid_->is_informed( p ) ) break; else bound--; } */ while (bound != begin) { GsTLGridNode p = center_location + (*bound); GsTLInt node_id = cursor.node_id( p[0], p[1], p[2] ); if( node_id < 0 ) { bound--; continue; } if( property_->is_informed( node_id ) ) break; else bound--; } // Need to place the bound at one pass the actual end point bound++; for( ; begin != bound; ++begin ) { GsTLGridNode node = center_location + (*begin); neighbors_.push_back( Geovalue( grid_, property_, cursor_.node_id( node[0], node[1], node[2] ) ) ); //neighbors_.push_back( grid_->geovalue( center_location + (*begin) ) ); } }
void Cosisim:: get_current_local_cdf( const Geovalue& g, std::vector< unsigned int >& unestimated_indicators ) { unestimated_indicators.clear(); int node_id = g.node_id(); Ccdf_type::p_iterator prob_it = ccdf_->p_begin(); for( unsigned int i = 0 ; i < indicators_.size() ; ++prob_it, ++i ) { if( indicators_[i]->is_harddata( node_id ) && indicators_[i]->is_informed( node_id ) ) *prob_it = indicators_[i]->get_value( node_id ); else unestimated_indicators.push_back( i ); } }
void MgridWindowNeighborhood::find_neighbors( const Geovalue& center ) { size_ = -1; center_ = center; center_.set_property_array( property_ ); _mcursor = dynamic_cast<MaskedGridCursor*>(grid_->cursor()); neighbors_.clear(); if( !property_ ) return; //SGrid_cursor cursor( *grid_->cursor() ); GsTLInt i,j,k; _mcursor->coords( center.node_id(), i,j,k ); GsTLGridNode center_location( i,j,k ); if( geom_.size() == 0 ) return; Grid_template::iterator begin = geom_.begin(); Grid_template::iterator bound = geom_.end()-1; while (bound != begin) { GsTLGridNode p = center_location + (*bound); GsTLInt node_id = _mcursor->node_id( p[0], p[1], p[2] ); if( node_id < 0 ) { bound--; continue; } if( property_->is_informed( node_id ) ) break; else bound--; } bound++; for( ; begin != bound ; ++begin ) { GsTLGridNode node = center_location + (*begin); if (_mcursor->node_id( node[0], node[1], node[2] ) < 0) continue; neighbors_.push_back( Geovalue( grid_, property_, _mcursor->node_id( node[0], node[1], node[2] ) ) ); } }
void Rgrid_ellips_neighborhood_hd::find_neighbors( const Geovalue& center ) { // This is exactly the same function as // Rgrid_ellips_neighborhood::find_neighbors, except that the condition // for a node to be a neighbor is that it contains a hard-data neighbors_.clear(); if( !property_ ) return; center_ = center; // center_.set_property_array( property_ ); // "already_found" is the number of neighbors already found int already_found=0; // loc will store the i,j,k coordinates of the center, node_id is the // center's node-id. They will be computed differently, whether "center" // and *this both refer to the same grid or not. GsTLGridNode loc; GsTLInt node_id = -1; if( center.grid() != grid_ ) { // "center" and "*this" do not refer to the same grid bool ok = grid_->geometry()->grid_coordinates( loc, center.location() ); if( !ok ) return; if( includes_center_ ) //GsTLInt id = cursor_.node_id( loc[0], loc[1], loc[2] ); node_id = cursor_.node_id( loc[0], loc[1], loc[2] ); } else { // "center" and "*this" both refer to the same grid cursor_.coords( center.node_id(), loc[0], loc[1], loc[2] ); node_id = center.node_id(); } if( includes_center_ && property_->is_informed( node_id ) ) { neighbors_.push_back( Geovalue( grid_, property_, node_id ) ); already_found++; } // Visit each node defined by the window ("geom_") // For each node, check if the node is inside the grid. // If it is and it contains a data value, add it to the list of // neighbors Grid_template::const_iterator it = geom_.begin(); Grid_template::const_iterator end = geom_.end(); while( it != end && already_found < max_neighbors_ ) { GsTLGridNode node = loc + (*it); GsTLInt node_id = cursor_.node_id( node[0], node[1], node[2] ); if( node_id < 0 ) { // The node does not belong to the grid: skip it it++; continue; } if( property_->is_harddata( node_id ) ) { // The node is informed: get the corresponding geovalue and add it // to the list of neighbors neighbors_.push_back( Geovalue( grid_, property_, node_id ) ); already_found++; } it++; } }
void MgridNeighborhood::find_neighbors( const Geovalue& center ) { _mcursor = dynamic_cast<EGridCursor*>(grid_->cursor()); appli_assert(_mcursor); neighbors_.clear(); if( !property_ ) return; center_ = center; // center_.set_property_array( property_ ); // "already_found" is the number of neighbors already found int already_found=0; // loc will store the i,j,k coordinates of the center, node_id is the // center's node-id. They will be computed differently, whether "center" // and *this both refer to the same grid or not. GsTLGridNode loc; GsTLInt node_id = -1; if( center.grid() != grid_ ) { // "center" and "*this" do not refer to the same grid bool ok = grid_->geometry()->grid_coordinates( loc, center.location() ); if( !ok ) return; if( includes_center_ ) { GsTLInt id = _mcursor->node_id( loc[0], loc[1], loc[2] ); if (id == -1) return; } } else { // "center" and "*this" both refer to the same grid _mcursor->coords( center.node_id(), loc[0], loc[1], loc[2] ); node_id = center.node_id(); /* appli_message("center node id : " << center.node_id() << ", loc: " << loc[0] << "," << loc[1] << "," << loc[2] << ". Id: " << _mcursor->node_id(loc[0],loc[1],loc[2]) << "\n"); */ } if( includes_center_ && property_->is_informed( node_id ) ) { neighbors_.push_back( Geovalue( grid_, property_, node_id ) ); already_found++; } // Visit each node defined by the window ("geom_") // For each node, check if the node is inside the grid. // If it is and it contains a data value, add it to the list of // neighbors Grid_template::const_iterator it = geom_.begin(); Grid_template::const_iterator end = geom_.end(); while( it != end && already_found < max_neighbors_ ) { GsTLGridNode node = loc + (*it); GsTLInt node_id = _mcursor->node_id( node[0], node[1], node[2] ); if( node_id < 0 ) { // The node does not belong to the grid: skip it it++; continue; } if( property_->is_informed( node_id ) ) { // The node is informed: get the corresponding geovalue and add it // to the list of neighbors neighbors_.push_back( Geovalue( grid_, property_, node_id ) ); already_found++; } it++; } }
int main() { //----------------- // Build a grid RGrid rgrid; RGrid_geometry* geom = new Simple_RGrid_geometry(); geom->set_size( 0, 5 ); geom->set_size( 1, 5 ); geom->set_size( 2, 1 ); rgrid.set_geometry( geom ); rgrid.add_property( "poro" ); Strati_grid* grid = &rgrid; GsTLGridProperty* prop = grid->select_property("poro"); grid->set_level(1); //----------------- //----------------- // Initialize the grid for( int i=0; i< prop->size() ; i++ ) prop->set_value( (float) i, i ); for( int i=0; i< prop->size() ; i++ ) cout << prop->get_value( i ) << endl; cout << endl; //----------------- //----------------- // Create a geovalue and use it to modify the grid cout << "-------------------------------" << endl << "Getting a geovalue (index=2)" << endl << endl; Geovalue gval = rgrid.geovalue( 2 ); cout << "location: " << gval.location() << endl; cout << "is informed? " << gval.is_informed() << endl; gval.set_property_value( 2.3 ); cout << "value changed to : " << gval.property_value() << endl; cout << endl << "this is the new grid" << endl; for( int i=0; i< prop->size() ; i++ ) cout << prop->get_value( i ) << endl; cout << endl; //---------------- //----------------- // Create a geovalue and use it to modify the grid cout << "-------------------------------" << endl << "Iterating on the grid and changing the values" << endl << endl; for( RGrid::iterator it = rgrid.begin() ; it!= rgrid.end(); ++it) { it->set_property_value( 10+ it->property_value() ); cout << "location: " << it->location() << " val= " << it->property_value() << endl; } cout << endl << "this is the new grid" << endl; for( int i=0; i< prop->size() ; i++ ) cout << prop->get_value( i ) << endl; cout << endl; //------------------ //----------------- // Work on a coarser grid cout << "-------------------------------" << endl << "Working on coarse grid 2" << endl << endl; rgrid.set_level( 2 ); RGrid::iterator it = rgrid.begin(); RGrid::iterator end = rgrid.end(); for( ; it!= end; ++it) { it->set_property_value( 100+ it->property_value() ); cout << "location: " << it->location() << " val= " << it->property_value() << endl; } cout << endl << "this is the new grid" << endl; for( int i=0; i< prop->size() ; i++ ) cout << prop->get_value( i ) << endl; cout << endl; cout << "-------------------------------" << endl << "Working on coarse grid 3" << endl << endl; rgrid.set_level( 3 ); it = rgrid.begin(); end = rgrid.end(); for( ; it!= end; ++it) { it->set_property_value( 300+ it->property_value() ); cout << "location: " << it->location() << " val= " << it->property_value() << endl; } cout << endl << "this is the new grid" << endl; for( int i=0; i< prop->size() ; i++ ) cout << prop->get_value( i ) << endl; cout << endl; //------------------ rgrid.add_property( "perm" ); std::list<std::string> names = rgrid.property_list(); cout << endl << "list of properties: " << endl; for( std::list<std::string>::iterator it = names.begin(); it!= names.end(); ++it) cout << *it << endl; }
bool operator() ( const Geovalue& g ) { return g.is_informed(); }
// g1 < g2 if the covariance between g1 and the center is higher bool operator() ( const Geovalue& g1, const Geovalue& g2 ) const { return cov_( g1.location(), center_ ) > cov_(g2.location(), center_ ); }
// g1 < g2 if the covariance between g1 and the center is higher bool operator() ( const Geovalue& g1, const Geovalue& g2 ) const { return square_euclidean_distance( g1.location(), center_ ) < square_euclidean_distance(g2.location(), center_ ); }