bool nonParamCdfInput_accessor::set_value( const std::string& str ) { // str is just an element of an xml file, hence can not be parsed // by QDomDocument. We need to add a root element. QString qstr( str.c_str() ); qstr = "<root>" + qstr + "</root>"; QDomDocument doc; bool parsed = doc.setContent( qstr ); appli_assert( parsed ); QDomElement root_element = doc.documentElement(); QDomElement elem = root_element.firstChild().toElement(); QString val = elem.attribute( "ref_on_file" ); input_->setRefOnFile(val == "1" ); val = elem.attribute( "ref_on_grid" ); input_->setRefOnGrid(val == "1" ); val = elem.attribute( "break_ties" ); input_->setTieBreaking(val == "1" ); val = elem.attribute( "filename" ); input_->setRefFileName(val); val = elem.attribute( "grid" ); input_->setRefGridName(val); val = elem.attribute( "property" ); input_->setRefPropName(val); QDomNodeList nodes = elem.elementsByTagName( "LTI_type" ); if( nodes.count() == 0 ) { appli_warning( "No element called \"LTI_type\"" << std::endl << "Aborting" ); return false; } QDomNode elemLower_node = nodes.item(0); appli_assert( elemLower_node.isElement() ); QDomElement elemLower = elemLower_node.toElement(); input_->LTI->setFunctionType( elemLower.attribute("function") ); input_->LTI->setExtremeValue( elemLower.attribute("extreme") ); input_->LTI->setOmega( elemLower.attribute("omega") ); nodes = elem.elementsByTagName( "UTI_type" ); if( nodes.count() == 0 ) { appli_warning( "No element called \"UTI_type\"" << std::endl << "Aborting" ); return false; } QDomNode elemUpper_node = nodes.item(0);; appli_assert( elemUpper_node.isElement() ); QDomElement elemUpper = elemUpper_node.toElement(); input_->UTI->setFunctionType( elemUpper.attribute("function") ); input_->UTI->setExtremeValue( elemUpper.attribute("extreme") ); input_->UTI->setOmega( elemUpper.attribute("omega") ); return true; }
void Const_geovalue::set_property_array( const Grid_continuous_property* prop ) { appli_assert( prop ); property_array_ = prop; values_array_ = prop->data(); if( !values_array_ ) { prop->swap_to_memory(); values_array_ = prop->data() ; } appli_assert( values_array_ ); }
Geovalue::Geovalue( Geostat_grid* grid, Grid_continuous_property* prop, int node_id ) : grid_(grid), property_array_(prop), node_id_(node_id), loc_( invalid_coord_, invalid_coord_, invalid_coord_ ), xyz_loc_( invalid_coord_, invalid_coord_, invalid_coord_ ){ appli_assert( prop ); values_array_ = prop->data() ; if( !values_array_ ) { prop->swap_to_memory(); values_array_ = prop->data() ; } appli_assert( values_array_ ); }
void Const_geovalue::init( const Geostat_grid* grid, const Grid_continuous_property* prop, int node_id) { appli_assert( prop ); grid_ = grid; property_array_ = prop; values_array_ = prop->data(); if( !values_array_ ) { prop->swap_to_memory(); values_array_ = prop->data() ; } appli_assert( values_array_ ); node_id_ = node_id; //loc_ = grid->location( node_id ); }
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++; } }
bool EllipsoidInput_accessor::set_value( const std::string& str ) { QString qstr( str.c_str() ); // str is just an element of an xml file, hence can not be parsed // by QDomDocument. We need to add a root element. qstr = "<root>" + qstr + "</root>"; QDomDocument doc; bool parsed = doc.setContent( qstr ); appli_assert( parsed ); QDomElement root_element = doc.documentElement(); QDomElement elem = root_element.firstChild().toElement(); QString val = elem.attribute( "value" ); String_Op::string_pair rows = String_Op::split_string( val.ascii(), "\n", false ); std::vector<double> ranges = String_Op::to_numbers<double>( rows.first ); std::vector<double> angles = String_Op::to_numbers<double>( rows.second ); for( int i=ranges.size(); i < 3; i++ ) ranges.push_back( 0 ); for( int i=angles.size(); i < 3; i++ ) angles.push_back( 0 ); input_->set_ranges( ranges[0], ranges[1], ranges[2] ); input_->set_angles( angles[0], angles[1], angles[2] ); return true; }
bool GridSelector_accessor::set_value( const std::string& str ) { QString qstr( str.c_str() ); // str is just an element of an xml file, hence can not be parsed // by QDomDocument. We need to add a root element. qstr = "<root>" + qstr + "</root>"; QDomDocument doc; bool parsed = doc.setContent( qstr ); appli_assert( parsed ); QDomElement root_element = doc.documentElement(); QDomElement elem = root_element.firstChild().toElement(); QString value = elem.attribute( "value" ); // search if "value" is in the list of possible grids. If yes, select it int id = 0; for( ; id < selector_->count() ; id++ ) { if( selector_->text( id ) == value ) { selector_->setCurrentText( selector_->text(id) ); break; } } return true; }
std::string VariogramInput_accessor::value() const { std::string widget_name = varg_input_->name() ; std::ostringstream result; // Write the nugget effect and the number of structures result << "<" << widget_name << " " << "nugget=\"" << varg_input_->nugget() << "\" " << "structures_count=\"" << varg_input_->structures_count() << "\" >" << std::endl; // Write the info about each structure for( int i=0; i < varg_input_->structures_count() ; i++ ) { const Variogram_structure_input* structure = varg_input_->structure( i ); appli_assert( structure ); result << " <structure_" << i+1 << " " << "contribution=\"" << structure->contribution() << "\" " << "type=\"" << structure->variogram_type() << "\" >" << std::endl << " <ranges max=\"" << structure->max_range() << "\" " << "medium=\"" << structure->medium_range() << "\" " << "min=\"" << structure->min_range() << "\" />" << std::endl << " <angles x=\"" << structure->x_angle() << "\" " << "y=\"" << structure->y_angle() << "\" " << "z=\"" << structure->z_angle() << "\" />" << std::endl << " </structure_" << i+1 << ">" << std::endl; } result << "</" << widget_name << ">" << std::endl; return result.str(); }
bool MultiPropertySelector_accessor::set_value( const std::string& str ) { QString qstr( str.c_str() ); // str is just an element of an xml file, hence can not be parsed // by QDomDocument. We need to add a root element. qstr = "<root>" + qstr + "</root>"; QDomDocument doc; bool parsed = doc.setContent( qstr ); appli_assert( parsed ); QDomElement root_element = doc.documentElement(); QDomElement elem = root_element.firstChild().toElement(); QString count_str = elem.attribute( "count" ); int count = count_str.toInt(); QString prop_string = elem.attribute( "value" ); QStringList prop_list = QStringList::split( ";", prop_string ); for( int i = 0 ; i < prop_list.size() ; i++ ) { QString name = prop_list[i]; int id = 0; for( ; id < selector_->count() ; id++ ) { if( selector_->text( id ) == name ) { selector_->setCurrentItem( id ); break; } } } return true; }
void Oinv_cgrid::set_transparency() { for( int i = 0; i < 256; i++ ) { volrend_colormap_->colorMap.set1Value( 4*i+3, 1.0f ); } if( !cmap_ ) return; float min = cmap_->lower_bound(); float max = cmap_->upper_bound(); if( min == max ) return; const float alpha = 0.01f; std::map< std::string, QString >::iterator found = transparency_map_.find( current_property_name_ ); if( found == transparency_map_.end() ) return; if( found->second.isEmpty() ) return; QStringList intervals_str = QStringList::split( ";", found->second); QStringList::Iterator it = intervals_str.begin(); for ( ; it != intervals_str.end(); ++it ) { QStringList interval_str = QStringList::split( ",", *it ); if( interval_str.size() != 2 ) continue; float low = std::max( interval_str[0].stripWhiteSpace().toFloat(), min ); float high= std::min( interval_str[1].stripWhiteSpace().toFloat(), max ); int a= (low - min) / ( max - min ) * 255; int b= (high - min) / ( max - min ) * 255; appli_assert( a >=0 && b < 256 ); for( int i = a; i <= b; i++ ) { volrend_colormap_->colorMap.set1Value( 4*i+3, alpha ); } } }
std::vector< Ellipsoid_rasterizer::EuclideanVector >& Ellipsoid_rasterizer::rasterize() { GsTLInt center_id = cursor_.node_id( center_[0], center_[1], center_[2] ); appli_assert( center_id >= 0 && center_id < int(already_visited_.size()) ); already_visited_[ center_id ] = true; s_.push( center_id ); EuclideanVector west(-1,0,0); EuclideanVector east(1,0,0); EuclideanVector south(0,-1,0); EuclideanVector north(0,1,0); EuclideanVector down(0,0,-1); EuclideanVector up(0,0,1); // move away from center, until we reach the border of the ellipsoid while( ! s_.empty() ) { GsTLInt id = s_.top(); s_.pop(); GsTLGridNode loc; cursor_.coords( id, loc[0], loc[1], loc[2] ); check_node( loc+west ); check_node( loc+east ); check_node( loc+north ); check_node( loc+south ); check_node( loc+up ); check_node( loc+down ); } return ellipsoid_nodes_; }
Csv_infilter_dialog::Csv_infilter_dialog( QWidget* parent, const char* name ) : QDialog(parent), filter_( 0 ), file_stream_( 0 ) { setupUi(this); SmartPtr<Named_interface> ni = Root::instance()->interface( gslibInputFilters_manager ); Manager* mng = dynamic_cast<Manager*>( ni.raw_ptr() ); appli_assert( mng ); Manager::type_iterator begin = mng->begin(); Manager::type_iterator end = mng->end(); for( ; begin != end ; ++begin ) { ObjectType->addItem( QString( begin->c_str() ) ); } create_specialized_filter( ObjectType->currentText() ); _back->setEnabled(false); ObjectType->setFocus(); QObject::connect( ObjectType, SIGNAL(activated( const QString& )), this, SLOT( create_specialized_filter( const QString& ) ) ); QObject::connect( _next, SIGNAL(clicked()), this, SLOT(nextClicked())); QObject::connect( _back, SIGNAL(clicked()), this, SLOT(backClicked())); QObject::connect( _cancel, SIGNAL(clicked()), this, SLOT(reject())); }
Geostat_grid* Csv_mgrid_infilter::read( std::ifstream& infile ) { // QByteArray tmp =dialog_->name().simplified().toLatin1(); //std::string name( tmp.constData() ); std::string name = dialog_->name().toStdString(); // 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; } ni = Root::instance()->new_interface( "reduced_grid", gridModels_manager + "/" + name ); Reduced_grid* grid = dynamic_cast<Reduced_grid*>( ni.raw_ptr() ); appli_assert( grid != 0 ); if (dialog_->is_xyz_file()) return readPointsetFormat(infile, grid); else return readRegularGridFormat(infile, grid); }
std::string QTable_accessor::value() const { appli_assert( table_ ); /* Scan the table line by line. Stop scanning a line * as soon as an empty cell is encountered. */ std::string widget_name = table_->name() ; std::string val; for( int row = 0 ; row < table_->numRows(); row++) { int col=0; while( col < table_->numCols() && !table_->text( row, col ).isEmpty() ) { QString text( table_->text( row, col ) ); std::string std_text; std_text = text.latin1() ; val += std_text + col_sep ; col++; } if( row != table_->numRows() - 1 ) val += row_sep; } return "<" + widget_name + " value=\"" + val + "\" /> \n"; }
bool Identical_grid_copier::copy( const Geostat_grid* server, const Grid_continuous_property* server_prop, Geostat_grid* client, Grid_continuous_property* client_prop ) { if( server != client ) return false; grid_ = server; copy_categorical_definition(server_prop,client_prop); appli_assert( server_prop->size() == client_prop->size() ); for(int nodeid=0; nodeid<server->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; }
bool Simulacre_output_filter::write( std::string outfile, const Geostat_grid* grid, std::string* errors ) { Reduced_grid rg; QFile file( outfile.c_str() ); if( !file.open( IO_WriteOnly ) ) { if( errors ) errors->append( "can't write to file: " + outfile ); return false; } QDataStream stream( &file ); // Write a header with a "magic number" and the grid type stream << (Q_UINT32)0xB211175D; stream << grid->classname().c_str(); // write the name of the object SmartPtr<Named_interface> ni = Root::instance()->interface( gridModels_manager ); Manager* grid_manager = dynamic_cast<Manager*>( ni.raw_ptr() ); appli_assert( grid_manager ); std::string name = grid_manager->name( (Named_interface*) grid ).c_str(); stream << name.c_str(); // TL modified if (grid->classname() == rg.classname()) return write_reduced_grid(stream, grid); if( dynamic_cast< const Point_set* >( grid ) ) return write_pointset( stream, grid ); if( dynamic_cast< const Cartesian_grid* >( grid ) ) return write_cartesian_grid( stream, grid ); return false; }
void MgridWindowNeighborhood::set_grid( RGrid* grid ) { appli_assert(dynamic_cast<Reduced_grid*>(grid)); grid_ = grid; if( grid ) { cursor_ = *( grid->cursor() ); _mcursor = dynamic_cast<EGridCursor*>(grid->cursor()); } }
void Colormap_categorical::upper_bound( float max ) { double* range; range = discrete_color_table_->GetRange(); appli_assert( range[0] <= max ); // discrete_color_table_->SetRange(range[0],max); }
void Colormap_continuous::upper_bound( float max ) { double* range; range = color_table_->GetRange(); appli_assert( range[0] <= max ); color_table_->SetRange(range[0],max); }
// This is very much the same as saving a point set, except for the bounding box // information. bool Simulacre_output_filter::write_reduced_grid( QDataStream& stream, const Geostat_grid* gstat_grid ) { const Reduced_grid * grid = dynamic_cast< const Reduced_grid* >( gstat_grid ); // write a version number stream << (Q_INT32)100; // write the number of active cells in the point-set stream << (Q_UINT32) grid->size(); // write the grid dimensions stream << (Q_UINT32) grid->nx() << (Q_UINT32) grid->ny() << (Q_UINT32) grid->nz(); // write the cell dimensions GsTLCoordVector cell_dims = grid->cell_dimensions(); stream << (float) cell_dims[0] << (float) cell_dims[1] << (float) cell_dims[2]; // write the grid origin GsTLPoint origin = grid->origin(); stream << (float) origin[0] << (float) origin[1] << (float) origin[2]; // Write the number of properties and the property names std::list<std::string> & prop_list = _list_to_write; stream << (Q_UINT32) prop_list.size(); std::list<std::string>::iterator it = prop_list.begin(); for( ; it != prop_list.end(); ++it ) { stream << it->c_str() ; } // retrieve cell coordinates const std::vector<GsTLGridNode>& locs = grid->psIJK(); std::vector<GsTLGridNode>::const_iterator vec_it = locs.begin(); for( ; vec_it != locs.end(); ++vec_it ) { stream << vec_it->x() << vec_it->y() << vec_it->z(); } // write the property values, one property at a time it = prop_list.begin(); for( ; it != prop_list.end(); ++it ) { const GsTLGridProperty* prop = grid->property( *it ); appli_assert( prop ); for( unsigned int i = 0; i < prop->size(); i++ ) { if( prop->is_informed( i ) ) stream << (float) prop->get_value( i ); else stream << (float) GsTLGridProperty::no_data_value; } } return true; }
void Colormap_categorical::lower_bound( float min ) { double* range; range = discrete_color_table_->GetRange(); appli_assert( min <= range[1] ); // discrete_color_table_->SetRange(min,range[1]); }
void Colormap_continuous::lower_bound( float min ) { double* range; range = color_table_->GetRange(); appli_assert( min <= range[1] ); color_table_->SetRange(min,range[1]); }
Named_interface* Log_data_grid::create_new_interface( std::string& name_and_size_str){ if( name_and_size_str.empty() ) return 0; String_Op::string_pair params = String_Op::split_string(name_and_size_str, "::",true); int size = String_Op::to_number<int>( params.second ); appli_assert( size >= 0 ); return new Log_data_grid( params.first,size ); }
GsTLGridProperty* Histogram_control_panel::get_property( const PropertySelector* object_selector ) { if( object_selector->selectedGrid().isEmpty() || object_selector->selectedProperty().isEmpty() ) return 0; std::string grid_name( object_selector->selectedGrid().latin1() ); Geostat_grid* grid = dynamic_cast<Geostat_grid*>( Root::instance()->interface( gridModels_manager + "/" + grid_name ).raw_ptr() ); appli_assert( grid ); std::string prop_name( object_selector->selectedProperty().latin1() ); GsTLGridProperty* prop = grid->property( prop_name ); appli_assert( prop ); return prop; }
Geostat_grid::location_type Structured_grid::xyz_location( int node_id ) const { appli_assert( node_id >= 0 && node_id <(signed int)( sgrid_geom_->GetNumberOfCells()) ); double loc[3]; cell_centers_filter_->GetOutput()->GetPoint(node_id,loc); return Geostat_grid::location_type(loc[0],loc[1],loc[2]); }
void Colormap_continuous_controller::create_colormap(){ std::string colorscale_name = colormap_selector_->currentText().toStdString(); SmartPtr<Named_interface> ni = Root::instance()->interface( colorscale_manager + "/" + colorscale_name ); Color_scale* colors = dynamic_cast<Color_scale*>( ni.raw_ptr() ); appli_assert( colors ); cmap_ = new Colormap_continuous( colors ); this->reset_min_max(); }
bool DiskAccessor::get_flag( int , GsTLInt id ) { appli_assert( id >= 0 && id < size_ ); if( id >= flags_bound_indexes_.first && id < flags_bound_indexes_.second ) { return flags_buffer_[id - flags_bound_indexes_.first]; } else { // flush the buffer, read the requested part of the file, // store it in the flags buffer and return the flag value. bufferize_flags( id ); return flags_buffer_[0]; } }
float DiskAccessor::get_property_value( GsTLInt id ) { appli_assert( id >= 0 && id < size_ ); if( id >= val_bound_indexes_.first && id < val_bound_indexes_.second ) { return val_buffer_[id - val_bound_indexes_.first]; } else { // flush the buffer, read the requested part of the file, // store it in the value buffer and return the property value bufferize_values( id ); return val_buffer_[0]; } }
bool QComboBox_accessor::set_value( const std::string& str ) { QString qstr( str.c_str() ); // str is just an element of an xml file, hence can not be parsed // by QDomDocument. We need to add a root element. qstr = "<root>" + qstr + "</root>"; QDomDocument doc; bool parsed = doc.setContent( qstr ); appli_assert( parsed ); QDomElement root_element = doc.documentElement(); QDomElement elem = root_element.firstChild().toElement(); QString value = elem.attribute( "value" ); // select entry "value" in the combobox. If there is no such entry, // either add it if the combobox is editable or return false int id = combo_box_->findText(value); if(id >= 0) { combo_box_->setCurrentIndex(id); helper_->activateComboBox(combo_box_,value); return true; } else if( combo_box_->isEditable() ){ combo_box_->addItem( elem.attribute( "value" ) ); helper_->activateComboBox(combo_box_,value); return true; } else return false; /* int entry_id = 0; while( combo_box_->itemText(entry_id) != value ) { entry_id++; if( entry_id >= combo_box_->count() ) break; } if( entry_id >= combo_box_->count() ) { // the entry wasn't found if( combo_box_->isEditable() ) { combo_box_->addItem( elem.attribute( "value" ) ); return true; } else return false; } // combo_box_->setCurrentItem( entry_id ); helper_->activateComboBox( combo_box_, entry_id ); */ return true; }
void Histogram::compute_log_bin_sizes( double* result, int size ) { // ignore all data lesser than 0 const_iterator actual_start = std::upper_bound( start_, end_, 0.0 ); appli_assert( *actual_start > 0 ); float logmin = std::log10( *actual_start ); float logmax = std::log10( *(end_-1) ); float step = (logmax-logmin) / float( size ); for( int i=0; i < size; i++ ) { result[i] = std::pow( float(10.0), logmin + float(i)*step ); } }