Ejemplo n.º 1
0
Geostat_grid* Simulacre_input_filter::read( const std::string& filename, 
                                           std::string* errors ) {
  QFile file( filename.c_str() );
  if( !file.open( IO_ReadOnly ) ) {
    if( errors ) 
      errors->append( "can't open file: " + filename);
    return false;
  }

  QDataStream stream( &file );
  Q_UINT32 magic_nb;
  stream >> magic_nb;
  if( magic_nb != 0xB211175D ) {
    if( errors )
      errors->append( "wrong file format" );
    return 0;
  }

  char* type;
  stream >> type;
  std::string object_type( type );
  delete [] type;

  //TL modified
  if (object_type == Reduced_grid().classname())
	  return read_reduced_grid(stream, errors);
  if( object_type == Cartesian_grid().classname() ) 
    return read_cartesian_grid( stream, errors );
  if( object_type == Point_set().classname() ) 
    return read_pointset( stream, errors );

  return 0;
}
Ejemplo n.º 2
0
//------------------------
bool library_grid_init::init_property_copier_factory() {
  Property_copier_factory::add_method( Point_set().classname(), 
                                       Cartesian_grid().classname(), 
                                       Cgrid_to_pset_copier::create_new_interface );
  Property_copier_factory::add_method( Cartesian_grid().classname(), 
                                       Cartesian_grid().classname(), 
                                       Cgrid_to_cgrid_copier::create_new_interface );
  Property_copier_factory::add_method( Point_set().classname(), 
                                       Point_set().classname(), 
                                       Pset_to_pset_copier::create_new_interface );

  //TL modified
  Property_copier_factory::add_method( Reduced_grid().classname(), 
                                       Reduced_grid().classname(), 
                                       Mask_to_mask_copier::create_new_interface );
  Property_copier_factory::add_method( Point_set().classname(), 
                                       Reduced_grid().classname(), 
                                       Pset_to_mask_copier::create_new_interface );


  return true;
}
Ejemplo n.º 3
0
/* Adds a unit cube, axis-aligned and centered on zero to the Module.
 * If solid is zero, add only lines. If solid is non-zero, use
 * polygons. Only lines need to be supported now.
 */
void Module_cube(Module *md, int solid, Texture *tex[6]) {
  Point v[8];
  Point  tv[4];
  Vector normal[4];
  TextureCoord st[4];
  printf("adding cube...\n");
  // corners of a cube, centered at (0, 0, 0)
  Point_set( &v[0], -0.5, -0.5, -0.5 );
  Point_set( &v[1],  0.5, -0.5, -0.5 );
  Point_set( &v[2],  0.5,  0.5, -0.5 );
  Point_set( &v[3], -0.5,  0.5, -0.5 );
  Point_set( &v[4], -0.5, -0.5,  0.5 );
  Point_set( &v[5],  0.5, -0.5,  0.5 );
  Point_set( &v[6],  0.5,  0.5,  0.5 );
  Point_set( &v[7], -0.5,  0.5,  0.5 );
  // add only line
  if (solid == 0) {
    Line temp;
    
    Line_set(&temp,v[0],v[1]);
    Module_line(md,&temp);
    Line_set(&temp,v[0],v[3]);
    Module_line(md,&temp);
    Line_set(&temp,v[0],v[4]);
    Module_line(md,&temp);
    
    Line_set(&temp,v[1],v[2]);
    Module_line(md,&temp);
    Line_set(&temp,v[1],v[5]);
    Module_line(md,&temp);

    Line_set(&temp,v[2],v[3]);
    Module_line(md,&temp);
    Line_set(&temp,v[2],v[6]);
    Module_line(md,&temp);
    
    Line_set(&temp,v[3],v[7]);
    Module_line(md,&temp);
    
    Line_set(&temp,v[4],v[5]);
    Module_line(md,&temp);
    Line_set(&temp,v[4],v[7]);
    Module_line(md,&temp);
    
    Line_set(&temp,v[5],v[6]);
    Module_line(md,&temp);
    
    Line_set(&temp,v[6],v[7]);
    Module_line(md,&temp);
  }
  // use polygons
  else {
    Polygon temp;
    Polygon_setNULL(&temp);
    
    // THIS IS HARD-CODED !!!!!
    if (tex != NULL) {
      st[0].s = 372; st[0].t = 0;
      st[1].s = 0; st[1].t = 0;
      st[2].s = 0; st[2].t = 372;
      st[3].s = 372; st[3].t = 372;
    }
    // front side
    Polygon_set( &temp, 4, &(v[0]) );
    Vector front = {{0.0,0.0,-1.0}};
    normal[0] = normal[1] = normal[2] 
      = normal[3] = front;
    Polygon_setNormals( &temp, 4, normal);    
    if (tex != NULL) 
      Module_texture(md,tex[0]);
      Polygon_setTexture(&temp, 4, st);

    Module_polygon(md,&temp);

    // back side
    Polygon_set( &temp, 4, &(v[4]) );
    Vector back = {{0.0,0.0,1.0}};
    normal[0] = normal[1] = normal[2] 
      = normal[3] = back;
    Polygon_setNormals( &temp, 4, normal);
    if (tex != NULL) 
      Module_texture(md,tex[1]);  
      Polygon_setTexture(&temp, 4, st);
    Module_polygon(md,&temp);
    
    // top side
    Point_copy( &tv[0], &v[2] );
    Point_copy( &tv[1], &v[3] );
    Point_copy( &tv[2], &v[7] );
    Point_copy( &tv[3], &v[6] );

    Polygon_set( &temp, 4, tv );
    Vector top = {{0.0,1.0,0.0}};
    normal[0] = normal[1] = normal[2] 
      = normal[3] = top;
    Polygon_setNormals( &temp, 4, normal);
    if (tex != NULL) 
      Module_texture(md,tex[2]);  
      Polygon_setTexture(&temp, 4, st);
    Module_polygon(md,&temp);

    // bottom side
    Point_copy( &tv[0], &v[0] );
    Point_copy( &tv[1], &v[1] );
    Point_copy( &tv[2], &v[5] );
    Point_copy( &tv[3], &v[4] );

    Polygon_set( &temp, 4, tv );
    Vector bottom = {{0.0,-1.0,0.0}};
    normal[0] = normal[1] = normal[2] 
      = normal[3] = bottom;
    Polygon_setNormals( &temp, 4, normal);    
    if (tex != NULL) 
      Module_texture(md,tex[3]);  
      Polygon_setTexture(&temp, 4, st);

    Module_polygon(md,&temp);

    // left side
    Point_copy( &tv[0], &v[0] );
    Point_copy( &tv[1], &v[3] );
    Point_copy( &tv[2], &v[7] );
    Point_copy( &tv[3], &v[4] );

    Polygon_set( &temp, 4, tv );
    Vector left = {{-1.0,0.0,0.0}};
    normal[0] = normal[1] = normal[2] 
      = normal[3] = left;
    Polygon_setNormals( &temp, 4, normal);       
    if (tex != NULL) 
      Module_texture(md,tex[4]);  
      Polygon_setTexture(&temp, 4, st);
    Module_polygon(md,&temp);

    // right side
    Point_copy( &tv[0], &v[1] );
    Point_copy( &tv[1], &v[2] );
    Point_copy( &tv[2], &v[6] );
    Point_copy( &tv[3], &v[5] );

    Polygon_set( &temp, 4, tv );
    Vector right = {{1.0,0.0,0.0}};
    normal[0] = normal[1] = normal[2] 
      = normal[3] = right;
    Polygon_setNormals( &temp, 4, normal);  
    if (tex != NULL) 
      Module_texture(md,tex[5]);  
      Polygon_setTexture(&temp, 4, st);

    Module_polygon(md,&temp);
  }
  return;
}