コード例 #1
0
ファイル: NodeDropped.cpp プロジェクト: fnavarrov/SGeMS
void NodeDropped::setDNProp( RGrid* grid, GsTLGridProperty* prop )
{
    SGrid_cursor  cursor = SGrid_cursor( *(grid->cursor()) );
    int node_id;

    for (int i=0; i<path_size; i++)
    {
        node_id = cursor.node_id( nodes[i].first );
        prop->set_value( nodes[i].second, node_id );
    }
}
コード例 #2
0
void Layer_servo_system_sampler< RandNumberGenerator, ComputeLayerIndex >::
removeSimulatedNode( RGrid* grid, Grid_continuous_property* prop, vector<int>& grid_path )
{
    SGrid_cursor  cursor = SGrid_cursor( *(grid->cursor()) );
    int current_value; 
    int node_id;
    int z; // layer index

    for (int i=0; i<grid_path.size(); i++)
    {
        node_id = cursor.node_id( grid_path[i] );
        current_value = prop->get_value( node_id );
        prop->set_not_informed( node_id );

        z = getLayerIndex_( node_id );
		current_histogram_[z][ current_value ] --;
		nb_of_data_[z] --;
    }
}
コード例 #3
0
bool Cgrid_to_cgrid_copier::copy( const Geostat_grid* server, 
                                  const Grid_continuous_property* server_prop,
                                  Geostat_grid* client, 
                                  Grid_continuous_property* client_prop ) {
  Cartesian_grid* to_grid = dynamic_cast< Cartesian_grid* >( client );
  const Cartesian_grid* from_grid = dynamic_cast< const Cartesian_grid* >( server );

  if( !from_grid || !to_grid ) return false;

  copy_categorical_definition(server_prop,client_prop);

  // if the 2 grids are identical, just copy the property
  if( are_identical_grids( from_grid, to_grid ) ) {
    
    appli_assert( server_prop->size() == client_prop->size() );
    for(int nodeid=0; nodeid<from_grid->size();++nodeid) {
      if( server_prop->is_informed(nodeid) ) {
      
		    //client_prop->set_value( server_prop->get_value( i ), i );
        client_prop->set_value( server_prop->get_value(nodeid), nodeid );
		    if( mark_as_hard_ )   //added by Yongshe
                client_prop->set_harddata( true, nodeid); //added by Yongshe
		  }
	    else if(overwrite_)
		    client_prop->set_not_informed( nodeid );
    }
    return true;
  }
  

  typedef Grid_continuous_property::property_type Property_type;

  // check if we already worked with "source" and "property_name" 
  // If that's the case and we're not required to do the assignement
  // from scratch, use what we did last time.
  if( !from_scratch_ && server == server_ &&
      server_prop == server_prop_ && client == client_ ) {
    
    for( unsigned int i = 0 ; i < last_assignement_.size() ; i++ ) {
      Property_type val = server_prop->get_value( last_assignement_[i].first );
      client_prop->set_value( val, last_assignement_[i].second );
      if( mark_as_hard_ )
      	client_prop->set_harddata( true, last_assignement_[i].second );
    } 
    return true;
  }
  
  last_assignement_.clear();
  backup_.clear();
  server_ = server;
  server_prop_ = server_prop;
  client_ = client;
  client_property_ = client_prop;

 
  // We will need to obtain the coordinates of a grid node from its
  // node id. Hence we need a grid-cursor, set to multigrid level 1.
  SGrid_cursor cursor = *( to_grid->cursor() );
  cursor.set_multigrid_level( 1 );

  GsTL_cube bbox = to_grid->bounding_box();

  // Use a map to record what point was assigned to which grid node
  // This map is used in case multiple points could be assigned to the
  // same grid node: in that case the new point is assigned if it is closer
  // to the grid node than the previously assigned node was.
  typedef Cartesian_grid::location_type location_type;
  typedef std::map<GsTLInt,location_type>::iterator map_iterator;
  std::map<GsTLInt,location_type> already_assigned;

  for(int server_id = 0 ; server_id < from_grid->size(); ++server_id ) {

    if( !server_prop->is_informed(server_id) ) continue;

    // only consider the points inside the target's bounding box
    location_type current_loc = from_grid->location(server_id);
    if( !bbox.contains( current_loc) ) continue;


    GsTLInt node_id = to_grid->closest_node( current_loc );
    appli_assert( node_id >=0 && node_id < client_prop->size() );
    appli_assert( server_id < server_prop->size() );
    if(  !to_grid->is_inside_selected_region(node_id) ) continue;
            
    // If there is already a property value (not assigned by the
    // grid initializer), and we don't want to overwrite, leave it alone
    if( !overwrite_ && client_prop->is_informed( node_id ) ) continue;


//    bool perform_assignment = true;

    // check if a point was already assigned to that node
    map_iterator it = already_assigned.find( node_id );
    if( it != already_assigned.end() ) {
    	int i,j,k;
    	GsTLCoordVector sizes = to_grid->cell_dimensions();
     	cursor.coords( node_id, i,j,k );
     	location_type node_loc( float(i)*sizes.x(),
			                        float(j)*sizes.y(),
			                        float(k)*sizes.z() );

     	// if the new point is further away to the grid node than
     	// the already assigned node, don't assign the new point
     	if( square_euclidean_distance( node_loc, current_loc ) > 
          square_euclidean_distance( node_loc, it->second ) ) 
        continue; //perform_assignment = false;
    }
	
//    if( perform_assignment ) {
  	// store the node id of the source and of the target and make a backup of the
    // property value of the client property
   	last_assignement_.push_back( std::make_pair( server_id, node_id ) );

    if( undo_enabled_ ) {
      Property_type backup_val = Grid_continuous_property::no_data_value;
      if( client_prop->is_informed( node_id ) )
        backup_val = client_prop->get_value( node_id );
      backup_.push_back( std::make_pair( node_id, backup_val ) );
    }

    Property_type val = server_prop->get_value(server_id);
    client_prop->set_value( val, node_id );
    already_assigned[node_id] = current_loc;
    if( mark_as_hard_ )
      client_prop->set_harddata( true, node_id );
    
  }
  
  unset_harddata_flag_ = mark_as_hard_;
  return true;
}