コード例 #1
0
GsTLPoint Structured_grid_coord_mapper::uvw_coords(GsTLPoint xyz)  {
  vtkSmartPointer<vtkStructuredGrid> geom = sgrid_->get_structured_geometry();


  // Need to get the ijk of the cell and add the parametric coordinate once normalized

  vtkSmartPointer<vtkGenericCell> gcell = vtkSmartPointer<vtkGenericCell>::New();
  
  double xyzcoord[3];
  xyzcoord[0] = xyz.x();
  xyzcoord[1] = xyz.y();
  xyzcoord[2] = xyz.z();

  double pcoord[3];
  double weights[8];
  int subid;

  int cellid = geom->FindCell(xyzcoord,0,gcell,-1,1e-4,subid,pcoord,weights);

  //If it outside the grid, ensure that it is so far away that it will get pickup within a neighborhood
  if(cellid <0 ) return GsTLPoint(xyzcoord[0] + 9e9,xyzcoord[1] + 9e9,xyzcoord[2] + 9e9);
  //geom->GetCell(cellid, gcell);  //may not be necessary if gcell is already stored in the FindCell
  int i,j,k;
  sgrid_->cursor()->coords(cellid,i,j,k);

  //Th u,v,w coordinates ranges from 0-1

  double u = (static_cast<double>(i) + pcoord[0])/grid_cell_number_.x();
  double v = (static_cast<double>(j) + pcoord[1])/grid_cell_number_.y();
  double w = (static_cast<double>(k) + pcoord[2])/grid_cell_number_.z();

  return GsTLPoint(u,v,w );

}
コード例 #2
0
ファイル: rgrid_geometry.cpp プロジェクト: ahinoamp/Research
GsTLPoint Simple_RGrid_geometry::coordinates(GsTLInt i, GsTLInt j, GsTLInt k) {
  GsTLCoord x = origin_.x() + GsTLCoord(i)*cell_dims_.x() ; 
  GsTLCoord y = origin_.y() + GsTLCoord(j)*cell_dims_.y() ; 
  GsTLCoord z = origin_.z() + GsTLCoord(k)*cell_dims_.z() ; 

  return GsTLPoint(x, y, z);
}
コード例 #3
0
void Structured_grid::set_structured_points( std::vector<GsTLPoint>& corner_points){

  vtkSmartPointer<vtkPoints> pts = vtkSmartPointer<vtkPoints>::New();
  pts->SetDataTypeToDouble ();
  pts->SetNumberOfPoints( (this->nx()+1) * (this->ny()+1) * (this->nz()+1) );

  std::vector<GsTLPoint>::const_iterator it = corner_points.begin();
  for(int i=0 ; it!= corner_points.end(); ++it,++i) {
    pts->SetPoint(i,it->x(),it->y(),it->z());
  }
  
  sgrid_geom_->SetDimensions(this->nx()+1, this->ny()+1, this->nz()+1);
  sgrid_geom_->SetPoints(pts);

  cell_centers_filter_->Update();

  GsTLCoordVector dims( 1.0/this->nx(), 1.0/this->ny(), 1.0/this->nz());
  geometry_->set_cell_dims( dims );

  // The uvw coordinates should start at (0,0,0) and finish at (1,1,1)
  //double origin_coord[3];
  //sgrid_geom_->GetPoint(0,origin_coord);
  //origin_ = GsTLPoint(origin_coord[0],origin_coord[1],origin_coord[2]); 
  origin_ = GsTLPoint(0,0,0); 
  coord_mapper_ = new Structured_grid_coord_mapper(this);
  
}
コード例 #4
0
GsTLPoint Simple_RGrid_geometry::coordinates(GsTLInt i, GsTLInt j, GsTLInt k) const {
  
  GsTLCoord dx = GsTLCoord(i)*cell_dims_.x() ;
  GsTLCoord dy = GsTLCoord(j)*cell_dims_.y() ;
  
  GsTLCoord x = origin_.x() + dx*z_cos_angle_ - dy*z_sin_angle_; 
  GsTLCoord y = origin_.y() + dx*z_sin_angle_ + dy*z_cos_angle_ ; 
  GsTLCoord z = origin_.z() + GsTLCoord(k)*cell_dims_.z() ; 

  /*
  GsTLCoord x = origin_.x() + GsTLCoord(i)*cell_dims_.x() ; 
  GsTLCoord y = origin_.y() + GsTLCoord(j)*cell_dims_.y() ; 
  GsTLCoord z = origin_.z() + GsTLCoord(k)*cell_dims_.z() ; 
  */
  return GsTLPoint(x, y, z);
}
コード例 #5
0
GsTLPoint Structured_grid_coord_mapper::xyz_coords(GsTLPoint uvw)  {
  vtkSmartPointer<vtkStructuredGrid> geom = sgrid_->get_structured_geometry();

  int i,j,k;
  int node_id = sgrid_->closest_node(uvw);
  sgrid_->cursor()->coords(node_id,i,j,k);

  //The coordinates wihtin the cell
  double pcoords[3];
  pcoords[0] = uvw.x() - static_cast<double>(i)/grid_cell_number_.x();
  pcoords[1] = uvw.y() - static_cast<double>(j)/grid_cell_number_.y();
  pcoords[2] = uvw.z() - static_cast<double>(k)/grid_cell_number_.z();

  double xyz[3];
  double* weights;
  vtkSmartPointer<vtkGenericCell> cell = vtkSmartPointer<vtkGenericCell>::New();
  geom->GetCell(node_id,cell);
  int subid=0;
  cell->EvaluateLocation(subid,pcoords,xyz,weights);
  return GsTLPoint(xyz[0],xyz[1],xyz[2]);


}
コード例 #6
0
int main(int argc, char **argv) {
    // Initialize Inventor and Qt
    QWidget *myWindow = SoQt::init(argv[0]);
    GsTL_SoNode::initClass();
    if (myWindow == NULL) exit(1);

    SmartPtr<Named_interface> ni_cmaps =
        Root::instance()->new_interface("directory://colormaps",
                                        colormap_manager );
    Manager* dir = dynamic_cast<Manager*>( ni_cmaps.raw_ptr() );

    if( !dir ) {
        GsTLlog << "could not create directory "
                << colormap_manager << "\n";
        return 1;
    }
    dir->factory( "colormap", Color_scale::create_new_interface );
    Root::instance()->new_interface( "colormap://rainbow.map",
                                     colormap_manager + "/rainbow" );
    Root::instance()->new_interface( "colormap://cyan_red.map",
                                     colormap_manager + "/cyan_red" );

    Root::instance()->list_all( cout );

    int nx=5;
    int ny=3;
    int nz=6;

    Cartesian_grid grid;
    grid.set_dimensions( nx, ny, nz, 1, 1, 1 );
    grid.origin( GsTLPoint( -0.5, -0.5, -0.5 ) );
    GsTLGridProperty* prop = grid.add_property( "toto", typeid( float ) );
    for( int i=0; i < nx*ny*nz; i ++ )
        prop->set_value( i, i );

    Oinv_cgrid oinv_grid;
    oinv_grid.init( &grid );
    oinv_grid.set_property( "toto" );
    oinv_grid.oinv_node()->visible = true;

    cout << "Setting up oinv scene" << endl;

    SoSelection* root = new SoSelection;

    SoSeparator* line_sep = new SoSeparator;
    SoLightModel* light_model = new SoLightModel;
    light_model->model = SoLightModel::BASE_COLOR;
    line_sep->addChild( light_model );
    SoMaterial* material = new SoMaterial;
    material->diffuseColor.setValue( 1.0, 0.0, 0.0 );
    line_sep->addChild( material );
    SoDrawStyle* draw_style = new SoDrawStyle;
    draw_style->style = SoDrawStyle::LINES;
    draw_style->lineWidth = 2;
    line_sep->addChild( draw_style );
    oinv_grid.property_display_mode( Oinv::NOT_PAINTED );
    line_sep->addChild( oinv_grid.oinv_node() );

    root->addChild( line_sep );

    SoSeparator* filled_sep = new SoSeparator;
    SoDrawStyle* draw_style_filled = new SoDrawStyle;
    draw_style_filled->style = SoDrawStyle::FILLED;
    filled_sep->addChild( draw_style_filled );
    oinv_grid.property_display_mode( Oinv::PAINTED );
    filled_sep->addChild( oinv_grid.oinv_node() );

    root->addChild( filled_sep );



    SoQtGsTLViewer* myViewer = new SoQtGsTLViewer( (QWidget*) myWindow, "camera" );
    //SoQtExaminerViewer *myViewer = new SoQtExaminerViewer(myWindow);
    myViewer->setSceneGraph(root);
    myViewer->show();
    SoQt::show(myWindow);

    SoQt::mainLoop();


}
コード例 #7
0
GsTLPoint Structured_grid::get_corner_point_locations(int id) const {
  double d_coord[3];
  sgrid_geom_->GetPoint(id,d_coord);
  return GsTLPoint(d_coord[0],d_coord[1],d_coord[2]); 

}
コード例 #8
0
int main() {

  const int grid_size = 10;
  // Build grid with locally varying mean
  Cartesian_grid* lvm_grid = new Cartesian_grid( grid_size, grid_size, 1 );
  GsTLGridProperty* prop = lvm_grid->add_property( "trend", typeid( float ) );
  
  for( int i=0; i< grid_size*grid_size/2 ; i++ ) {
    prop->set_value( 0.0, i );
  }
  for( int i=grid_size*grid_size/2; i< grid_size*grid_size ; i++ ) {
    prop->set_value( 10.0, i );
  }
  Colocated_neighborhood* coloc_neigh = 
    dynamic_cast<Colocated_neighborhood*>( 
	  lvm_grid->colocated_neighborhood( "trend" )
       );


  // Build kriging grid 
  Cartesian_grid* krig_grid = new Cartesian_grid( grid_size, grid_size, 1 );
  GsTLGridProperty* krig_prop = 
    krig_grid->add_property( string("krig"), typeid( float )  );
  krig_grid->select_property( "krig");

  // Build harddata grid
  const int pointset_size = 4;
  Point_set* harddata = new Point_set( pointset_size );
  std::vector<GsTLPoint> locations;
  locations.push_back( GsTLPoint( 0,0,0 ) );
  locations.push_back( GsTLPoint( 1,5,0 ) );
  locations.push_back( GsTLPoint( 8,8,0 ) );
  locations.push_back( GsTLPoint( 5,2,0 ) );
  harddata->point_locations( locations );
  GsTLGridProperty* hard_prop = harddata->add_property( "poro" );
  
  for( int i=0; i<pointset_size; i++ ) {
    hard_prop->set_value( i, i );
  }

  harddata->select_property( "poro" );


  // Set up covariance
  Covariance<GsTLPoint> cov;
  cov.nugget(0.1);
  cov.add_structure( "Spherical" );
  cov.sill( 0, 0.9 );
  cov.set_geometry( 0, 10,10,10, 0,0,0 );

  Grid_initializer initializer;
  initializer.assign( krig_grid,
		      krig_prop,
		      harddata,
		      "poro" );
	
  for( int i=0; i< krig_prop->size(); i++ ) {
    if( krig_prop->is_harddata( i ) )
      cout << "value at " << i << ": " 
	   << krig_prop->get_value( i ) << endl;
  }

  krig_grid->select_property( "krig");

  Neighborhood* neighborhood = krig_grid->neighborhood( 20, 20, 1, 0,0,0,
							&cov, true );

  typedef GsTLPoint Location;
  typedef std::vector<double>::const_iterator weight_iterator;
  typedef SKConstraints_impl< Neighborhood, Location > SKConstraints;
  typedef SK_local_mean_combiner<weight_iterator, Neighborhood,
                                 Colocated_neighborhood> LVM_combiner;
  typedef Kriging_constraints< Neighborhood, Location > KrigingConstraints;
  typedef Kriging_combiner< weight_iterator, Neighborhood > KrigingCombiner;


  LVM_combiner combiner( *coloc_neigh );
  SKConstraints constraints;


  // initialize the algo
  Kriging algo;
  algo.simul_grid_ = krig_grid;
  algo.property_name_ = "krig";
  algo.harddata_grid_ = 0;
  algo.neighborhood_ = neighborhood;
  algo.covar_ = cov;
  algo.combiner_ = new KrigingCombiner( &combiner );
  algo.Kconstraints_ = new KrigingConstraints( &constraints );


  // Run and output the results
  algo.execute();

  ofstream ofile( "result.out" );
  if( !ofile ) {
    cerr << "can't create file result.out" << endl;
    return 1;
  }

  GsTLGridProperty* prop1 = krig_grid->select_property( "krig" );
  ofile << "kriging" << endl << "1" << endl << "krig" << endl ;
  for( int i=0; i< prop1->size(); i++ ) {
    if( prop1->is_informed( i ) )
      ofile << prop1->get_value( i ) << endl;
    else
      ofile << "-99" << endl;
  }
}
コード例 #9
0
ファイル: csv_filter.cpp プロジェクト: fnavarrov/SGeMS
Geostat_grid* Csv_mgrid_infilter::readRegularGridFormat(std::ifstream& infile,Reduced_grid * grid)
{

  infile.clear();
  infile.seekg(0, ios::beg);
	std::vector<std::string> nums;

	int nx = dialog_->nx();
	int ny = dialog_->ny();
	int nz = dialog_->nz();
	float x_size = dialog_->x_size();
	float y_size = dialog_->y_size();
	float z_size = dialog_->z_size();
	float Ox = dialog_->Ox();
	float Oy = dialog_->Oy();
	float Oz = dialog_->Oz();

	grid->set_dimensions( nx, ny, nz,
		x_size, y_size, z_size);
	grid->origin( GsTLPoint( Ox,Oy,Oz) );

	std::string buffer;

  int maskColNumber = dialog_->mask_column_index();
  int X_col_id = dialog_->X_column_index();
  int Y_col_id = dialog_->Y_column_index();
  int Z_col_id = dialog_->Z_column_index();

  bool use_no_data_value = dialog_->use_no_data_value();
  float no_data_value = GsTLGridProperty::no_data_value;
  QString no_data_value_str = QString().arg(no_data_value);
  if( dialog_->use_no_data_value() ) {
    no_data_value = dialog_->no_data_value();
    no_data_value_str = QString::number(no_data_value);
  }

	//-------------------------
	//   now, read the file
	std::getline( infile, buffer, '\n');
	std::vector<std::string> property_names = String_Op::decompose_string( buffer, ",", false );


  int beg_data_pos = infile.tellg();
  std::vector<bool> mask;
  mask.reserve(grid->rgrid_size());
  int size_active=0;

// Read Mask
  for( int i=0; i < grid->rgrid_size() ; i++ ) {
		std::getline( infile, buffer, '\n');
		std::vector<std::string> buf = String_Op::decompose_string(buffer, ",", false);
    if(buf.size() < property_names.size()) {
	    GsTLcerr << "Invalid file format\n Line " <<i<<" does not have " <<static_cast<int>(property_names.size())<<" columns"<< gstlIO::end;
		  return NULL;
    }
    mask.push_back( buf[maskColNumber] == "1" );
	}
  grid->mask( mask );


	// reposition the stream
	infile.clear();
	infile.seekg( 0 );
	std::getline( infile, buffer, '\n');

//Read one column at a time
  std::streampos start_data = infile.tellg();
  for(unsigned int j = 0; j< property_names.size(); j++) {
    infile.clear();
    infile.seekg( start_data );
    // Check if property j is categorical
    bool is_categ = false;
    for(unsigned int i=0; i<30 ; i++ ) {
      if( std::getline(infile, buffer) ) break;
      std::vector<std::string> values_str = String_Op::decompose_string(buffer, ",", false);
      is_categ = !String_Op::is_number(values_str[j]);
      if(is_categ) break;
    }
    infile.clear();
    infile.seekg( start_data );

    if(is_categ) {
      GsTLGridCategoricalProperty* prop = 
        grid->add_categorical_property(property_names[j]);

      // Set the category definition
      SmartPtr<Named_interface> ni = 
        Root::instance()->new_interface( categoricalDefinition_manager, 
                                         dialog_->name().toStdString()+"-"+property_names[j]);
      CategoricalPropertyDefinitionName* cat_def = 
            dynamic_cast<CategoricalPropertyDefinitionName*>(ni.raw_ptr());

      while( std::getline(infile, buffer) ) {
        QString qstr(buffer.c_str());
        QStringList values_qstr = qstr.split(",");
        cat_def->add_category(values_qstr[j].toStdString());
      }
      prop->set_category_definition(cat_def->name());
      infile.clear();
      infile.seekg( start_data );

      // Read the data
      int node_id=0;
      int index = 0;
      while( std::getline(infile, buffer) ) {
        if( mask[index] ) {
          QString qstr(buffer.c_str());
          QStringList values_qstr = qstr.split(",");
          QString val = values_qstr[j];
          if(!val.isEmpty() && val != no_data_value_str ) {
            prop->set_value(values_qstr[j].toStdString(),node_id);
          }
          node_id++;
        }
        index++;
      }
    }
    else {
      GsTLGridProperty* prop = 
        grid->add_property(property_names[j]);
      int node_id=0;
      int index = 0;
      while( std::getline(infile, buffer) ) {
        if(mask[index]) {
          QString qstr(buffer.c_str());
          QStringList values_qstr = qstr.split(",");
          if(!values_qstr[j].isEmpty()) {
            bool ok;
            float val = values_qstr[j].toFloat(&ok);
            if(ok && val != no_data_value ) prop->set_value(val,node_id);
          }
          node_id++;
        }
        index++;
      }
      
    }
  }
	return grid;
}
コード例 #10
0
ファイル: csv_filter.cpp プロジェクト: fnavarrov/SGeMS
Geostat_grid* Csv_grid_infilter::read( std::ifstream& infile ) {

  int nx = dialog_->nx();
  int ny = dialog_->ny();
  int nz = dialog_->nz();
  float x_size = dialog_->x_size();
  float y_size = dialog_->y_size();
  float z_size = dialog_->z_size();
  float Ox = dialog_->Ox();
  float Oy = dialog_->Oy();
  float Oz = dialog_->Oz();

  bool use_no_data_value = dialog_->use_no_data_value();
  float no_data_value = GsTLGridProperty::no_data_value;
  QString no_data_value_str = QString().arg(no_data_value);
  if( dialog_->use_no_data_value() ) {
    no_data_value = dialog_->no_data_value();
    no_data_value_str = QString::number(no_data_value);

  }

  QByteArray tmp = dialog_->name().simplified().toLatin1();
  std::string name( tmp.constData() );

  // ask manager to get a new grid and initialize it
  SmartPtr<Named_interface> ni =
    Root::instance()->interface( gridModels_manager + "/" + name );

  if( ni.raw_ptr() != 0 ) {
    GsTLcerr << "object " << name << " already exists\n" << gstlIO::end;
    return 0;
  }

  appli_message( "creating new grid '" << name << "'" 
		             << " of dimensions: " << nx << "x" << ny << "x" << nz);

  ni = Root::instance()->new_interface( "cgrid", 
                                        gridModels_manager + "/" + name );
  Cartesian_grid* grid = dynamic_cast<Cartesian_grid*>( ni.raw_ptr() );
  appli_assert( grid != 0 );

  grid->set_dimensions( nx, ny, nz,
			x_size, y_size, z_size);
  grid->origin( GsTLPoint( Ox,Oy,Oz) );
  appli_message( "grid resized to " << nx << "x" << ny << "x" << nz
		<< "  total=: " << grid->size() );

  std::string buffer;
  
  //-------------------------
  //   now, read the file

  std::getline( infile, buffer, '\n');
  QStringList property_names = QString(buffer.c_str()).split(",");

//Read one column at a time
  std::streampos start_data = infile.tellg();
  for(unsigned int j = 0; j< property_names.size(); j++) {
    infile.clear();
    infile.seekg( start_data );
    // Check if property j is categorical
    bool is_categ = false;
    for(unsigned int i=0; i<30 ; i++ ) {
      bool ok;
      if( std::getline(infile, buffer) ) break;
      QString qstr(buffer.c_str());
      QStringList values_str = qstr.split(",");
      values_str[j].toFloat(&ok);
      if(!ok)  {
        is_categ = true;
        break;
      }
    }
    infile.clear();
    infile.seekg( start_data );

    if(is_categ) {
      GsTLGridCategoricalProperty* prop = 
        grid->add_categorical_property(property_names[j].toStdString());
      
      ni = Root::instance()->new_interface( categoricalDefinition_manager, name+"-"+property_names[j].toStdString());
      CategoricalPropertyDefinitionName* cat_def = 
            dynamic_cast<CategoricalPropertyDefinitionName*>(ni.raw_ptr());

      while( std::getline(infile, buffer) ) {
        QString qstr(buffer.c_str());
        QStringList values_qstr = qstr.split(",");
        cat_def->add_category(values_qstr[j].toStdString());
      }
      prop->set_category_definition(cat_def->name());
      infile.clear();
      infile.seekg( start_data );

      int node_id=0;
      while( std::getline(infile, buffer) ) {
        QString qstr(buffer.c_str());
        QStringList values_qstr = qstr.split(",");
        QString val = values_qstr[j];
        if(use_no_data_value && val == no_data_value_str)  {
          prop->set_value( GsTLGridProperty::no_data_value, node_id );
        }
        else {
          prop->set_value( val.toStdString(), node_id );
        }
        node_id++;
      }
    }
    else {
      GsTLGridProperty* prop = 
        grid->add_property(property_names[j].toStdString());
      int node_id=0;
      while( std::getline(infile, buffer) ) {
        QString qstr(buffer.c_str());
        QStringList values_qstr = qstr.split(",");
        if(!values_qstr[j].isEmpty()) {
          bool ok;
          float val = values_qstr[j].toFloat(&ok);
          if(ok  && val != no_data_value) prop->set_value(val,node_id);
        }
        node_id++;
      }
    }

  }
  return grid;
}
コード例 #11
0
ファイル: gslib_filter.cpp プロジェクト: fnavarrov/SGeMS
Geostat_grid* Gslib_grid_infilter::read( std::ifstream& infile ) {

    int nx = dialog_->nx();
    int ny = dialog_->ny();
    int nz = dialog_->nz();
    float x_size = dialog_->x_size();
    float y_size = dialog_->y_size();
    float z_size = dialog_->z_size();
    float Ox = dialog_->Ox();
    float Oy = dialog_->Oy();
    float Oz = dialog_->Oz();

    QByteArray tmp = dialog_->name().simplified().toLatin1();
    std::string name( tmp.constData() );

    // ask manager to get a new grid and initialize it
    SmartPtr<Named_interface> ni =
        Root::instance()->interface( gridModels_manager + "/" + name );

    if( ni.raw_ptr() != 0 ) {
        GsTLcerr << "object " << name << " already exists\n" << gstlIO::end;
        return 0;
    }

    appli_message( "creating new grid '" << name << "'"
                   << " of dimensions: " << nx << "x" << ny << "x" << nz);

    ni = Root::instance()->new_interface( "cgrid",
                                          gridModels_manager + "/" + name );
    Cartesian_grid* grid = dynamic_cast<Cartesian_grid*>( ni.raw_ptr() );
    appli_assert( grid != 0 );

    grid->set_dimensions( nx, ny, nz,
                          x_size, y_size, z_size);
    grid->origin( GsTLPoint( Ox,Oy,Oz) );
    appli_message( "grid resized to " << nx << "x" << ny << "x" << nz
                   << "  total=: " << grid->size() );

    std::string buffer;

    //-------------------------
    //   now, read the file

    // read title
    std::getline( infile, buffer, '\n');

    // read nb of properties
    int property_count;
    infile >> property_count;
    std::getline( infile, buffer, '\n');


    // check whether the file contains multiple realizations
    bool has_multi_real = false;

    int lines_to_skip = grid->size() + property_count;
    for( int pos=0; pos < lines_to_skip ; pos++ )
        std::getline( infile, buffer, '\n');
    float val;
    if( infile >> val ) has_multi_real = true;

    // reposition the stream
    infile.clear();
    infile.seekg( 0 );
    std::getline( infile, buffer, '\n');
    std::getline( infile, buffer, '\n');

    if( has_multi_real ) {
        std::vector<MultiRealization_property*> properties;
        for( int i=0; i<property_count; i++ ) {
            std::getline( infile, buffer, '\n');
            QString prop_name( buffer.c_str() );
            MultiRealization_property* prop;
            QByteArray tmp = prop_name.simplified().toAscii();
            prop = grid->add_multi_realization_property( tmp.constData() );
            if( !prop ) {
                GsTLcerr << "Several properties share the same name " << gstlIO::end;
                return 0;
            }

            properties.push_back( prop );

        }


        while( infile ) {
            if( !infile ) break;
            char c = infile.peek();
            if( !std::isdigit(c) ) break;

            std::vector<GsTLGridProperty*> props;
            int index = 0;
            for( unsigned int ii=0; ii < property_count; ii++) {

                GsTLGridProperty* prop = properties[index]->new_realization();
                props.push_back( prop );
                ++index;

            }
            read_one_realization( infile, props, grid->size() );
        }
    }

    else {
        std::vector<GsTLGridProperty*> properties;
        for( int i=0; i<property_count; i++ ) {
            std::getline( infile, buffer, '\n');
            QString prop_name( buffer.c_str() );

            QByteArray tmp  =prop_name.simplified().toAscii();
            GsTLGridProperty* prop =
                grid->add_property( tmp.constData() );
            properties.push_back( prop );
        }
        read_one_realization( infile, properties, grid->size() );

    }

    return grid;
}
コード例 #12
0
ファイル: gslib_filter.cpp プロジェクト: fnavarrov/SGeMS
Geostat_grid* Gslib_mgrid_infilter::readRegularGridFormat(std::ifstream& infile,Reduced_grid * grid)
{
    std::vector<std::string> nums;

    int nx = dialog_->nx();
    int ny = dialog_->ny();
    int nz = dialog_->nz();
    float x_size = dialog_->x_size();
    float y_size = dialog_->y_size();
    float z_size = dialog_->z_size();
    float Ox = dialog_->Ox();
    float Oy = dialog_->Oy();
    float Oz = dialog_->Oz();

    grid->set_dimensions( nx, ny, nz,
                          x_size, y_size, z_size);
    grid->origin( GsTLPoint( Ox,Oy,Oz) );

    std::string buffer;

    int maskColNumber = dialog_->mask_column()-1;

    //-------------------------
    //   now, read the file

    // read title
    std::getline( infile, buffer, '\n');

    // read nb of properties
    int total_columns;
    infile >> total_columns;
    std::getline( infile, buffer, '\n');

    if (maskColNumber > total_columns) {
        GsTLcerr << "Invalid mask column" << gstlIO::end;
        return NULL;
    }

    bool has_multi_real = false;
//	std::vector<GsTLGridProperty*> properties;
    for( int i=0; i<total_columns; i++ ) {
        std::getline( infile, buffer, '\n');
        QString prop_name( buffer.c_str() );
//		if( i != maskColNumber ) {
//      GsTLGridProperty* prop = grid->add_property(prop_name.toStdString());
//      properties.push_back( prop );
//		}
    }

    int beg_data_pos = infile.tellg();
    std::vector<bool> mask;
    mask.reserve(grid->rgrid_size());
    int size_active=0;

// Read Mask

    for( int i=0; i < grid->rgrid_size() ; i++ ) {
        std::getline( infile, buffer, '\n');
        QString qbuffer(buffer.c_str());
        QStringList buf = qbuffer.split(" ",QString::SkipEmptyParts);

        //std::vector<std::string> buf = String_Op::decompose_string(buffer, " ", false);
        if(buf.size() < total_columns) {
            GsTLcerr << "Invalid file format\n Line " <<i<<" does not have " <<total_columns<<" columns"<< gstlIO::end;
            return NULL;
        }
        bool is_active = buf[maskColNumber].toFloat() == 1. ;
        mask.push_back( is_active );
    }
    grid->mask( mask );


// We are at the end of the file, if more data are present,
// it is another realizations
    float val;
    if( infile >> val ) has_multi_real = true;

    // reposition the stream
    infile.clear();
    infile.seekg( 0 );
    std::getline( infile, buffer, '\n');
    std::getline( infile, buffer, '\n');

    if( has_multi_real ) {
        std::vector<MultiRealization_property*> properties;
        for( int i=0; i<total_columns; i++ ) {
            std::getline( infile, buffer, '\n');
            QString prop_name( buffer.c_str() );
            MultiRealization_property* prop;

            if (i != maskColNumber ) {
//				QByteArray tmp = prop_name.simplified().toAscii();
                prop = grid->add_multi_realization_property( prop_name.toStdString() );
                if( !prop ) {
                    GsTLcerr << "Several properties share the same name " << gstlIO::end;
                    return 0;
                }
                properties.push_back( prop );
            }
        }

        while( infile ) {
            if( !infile ) break;
            char c = infile.peek();
            if( !std::isdigit(c) ) break;

            std::vector<GsTLGridProperty*> props;
            std::vector<MultiRealization_property*>::iterator multi_prop_it = properties.begin();
            for( unsigned int ii=0; ii < total_columns; ii++) {
                if (ii != maskColNumber) {
                    GsTLGridProperty* prop = (*multi_prop_it)->new_realization();
                    multi_prop_it++;
                    props.push_back( prop );
                }
            }
            if( props.size() > 0 )  // If onyl the mask was present in the file
                read_one_realization( infile, props, grid );
        }
    }

    else {
        std::vector<GsTLGridProperty*> properties;
        for( int i=0; i<total_columns; i++ ) {
            std::getline( infile, buffer, '\n');
            QString prop_name( buffer.c_str() );

            if (i != maskColNumber) {
                GsTLGridProperty* prop =
                    grid->add_property( prop_name.toStdString() );
                properties.push_back( prop );
            }
        }
        if( properties.size() > 0 )  // If onyl the mask was present in the file
            read_one_realization( infile, properties, grid);
    }
    return grid;
}