//From http://www.richelbilderbeek.nl/GetDistancesPath.htm
const boost::shared_ptr<const ribi::maziak::IntMaze> ribi::maziak::SolutionMaze::CreateSolution(
  const boost::shared_ptr<const DistancesMaze> distances,
  const int player_x,
  const int player_y
) noexcept
{
  const int size = distances->GetSize();

  std::vector<std::vector<int> > solution(size, std::vector<int>(size,0));
  {
    int x = player_x;
    int y = player_y;
    int distance = distances->Get(x,y) - 1;
    while (distance >= 0)
    {
      //We must be where we are now
      solution[y][x] = 1;
      if ( x!=0      && distances->Get(x-1,y) == distance ) { --x; --distance; continue; }
      if ( x!=size-1 && distances->Get(x+1,y) == distance ) { ++x; --distance; continue; }
      if ( y!=0      && distances->Get(x,y-1) == distance ) { --y; --distance; continue; }
      if ( y!=size-1 && distances->Get(x,y+1) == distance ) { ++y; --distance; continue; }
    }
  }

  const boost::shared_ptr<const IntMaze> maze {
    new IntMaze(solution)
  };
  assert(maze);
  return maze;
}
const boost::shared_ptr<ribi::cmap::Examples> ribi::cmap::ExamplesFactory::Create(
  const boost::shared_ptr<const cmap::Examples>& examples)
{
  assert(examples);
  const boost::shared_ptr<ribi::cmap::Examples> p = Create(examples->Get());
  assert(p);
  return p;
}
void ribi::cmap::QtExamplesItem::SetExamples(const boost::shared_ptr<const cmap::Examples>& examples)
{
  std::vector<std::string> v;
  for (const boost::shared_ptr<const cmap::Example> example: examples->Get())
  {
    const std::string s { example->GetText() };
    const std::size_t wordwrap_length = 40;
    const std::vector<std::string> w { Wordwrap(s,wordwrap_length) };
    std::copy(w.begin(),w.end(),std::back_inserter(v));
  }
  this->SetText(v);
}
void QtPvdbExamplesItem::SetExamples(const boost::shared_ptr<const pvdb::Examples>& examples)
{
  const std::vector<boost::shared_ptr<const pvdb::Example> >& v = examples->Get();
  std::vector<std::string> w;
  std::transform(v.begin(),v.end(),std::back_inserter(w),
    [](const boost::shared_ptr<const pvdb::Example>& p)
    {
      assert(p);
      return p->GetText();
    }
  );
  this->SetText(w);
}
void write_map(fs::path file_path, GDALDataType data_type, boost::shared_ptr<Map_Matrix<DataFormat> > data, std::string WKTprojection, GeoTransform transform, std::string driverName) throw(std::runtime_error)
{
	GDALAllRegister(); //This registers all availble raster file formats for use with this utility. How neat is that. We can input any GDAL supported rater file format.
    
    const char *pszFormat = driverName.c_str();
    GDALDriver * poDriver = GetGDALDriverManager()->GetDriverByName(pszFormat);
    if (poDriver == NULL)
    {
        throw std::runtime_error("No driver for file tyle found");
    }
    
    char ** papszMetadata = poDriver->GetMetadata();
    if (!(CSLFetchBoolean(papszMetadata, GDAL_DCAP_CREATE, FALSE)))
    {
        throw std::runtime_error("Driver does not support raster creation");
    }
    
    char **papszOptions = NULL;
	papszOptions = CSLSetNameValue(papszOptions, "COMPRESS", "LZW");

    GDALDataset *poDstDS = poDriver->Create(file_path.string().c_str(), (int)data->NCols(), (int)data->NRows(), 1, data_type, papszOptions);
    
    double adfGeoTransform[6] = {1, 1, 1, 1, 1, 1};
    adfGeoTransform[0] = transform.x_origin;
    adfGeoTransform[1] = transform.pixel_width;
    adfGeoTransform[2] = transform.x_line_space;
    adfGeoTransform[3] = transform.y_origin;
    adfGeoTransform[4] = transform.pixel_height;
    adfGeoTransform[5] = transform.y_line_space;
    
    const char * psz_WKT = WKTprojection.c_str();
    poDstDS->SetGeoTransform(adfGeoTransform);             
    poDstDS->SetProjection(psz_WKT);
    
    DataFormat * pafScanline = new DataFormat[data->NCols() * data->NRows()];
    int pafIterator = 0;
	for (int i = 0; i < data->NRows(); i++)
    {
		for (int j = 0; j < data->NCols(); j++)
        {
            pafScanline[pafIterator] = data->Get(i, j);
            pafIterator++;
        }
    }
    
    GDALRasterBand * poBand = poDstDS->GetRasterBand(1);
    poBand->SetNoDataValue(data->NoDataValue());
    poBand->RasterIO(GF_Write, 0, 0, (int) data->NCols(), (int) data->NRows(), pafScanline, (int) data->NCols(), (int) data->NRows(), data_type, 0, 0);
    
    GDALClose( (GDALDatasetH) poDstDS);
}
void TBranchCollection::writeDirectory( std::string folder, boost::shared_ptr<TFile> treeFile ) {
    std::string currentPath = "";

        // if (index == 0) {
        if (treeFile->Get(folder.c_str()) == 0)
            treeFile->mkdir(folder.c_str());
        // } else {
        //     TDirectory* currentDir = (TDirectory*) treeFile->Get(currentPath.c_str());
        //     assert(currentDir != 0);
        //     if (currentDir->Get(dir.c_str()) == 0)
        //         currentDir->mkdir(dir.c_str());
        //     currentPath += "/" + dir;
        // }
    }
void ribi::pvdb::QtPvdbClusterDialog::on_button_next_clicked()
{
  assert(m_file);
  if (GetWidget() && GetWidget()->isEnabled()) //Save concept map, when user is all
  {

    const boost::shared_ptr<pvdb::Cluster> cluster = GetWidget()->GetCluster();
    TRACE(cluster->Get().size());
    m_file->SetCluster(cluster);


    //File's cluster and widget's cluster should be the same
    assert(m_file->GetCluster() == GetWidget()->GetCluster());

    //The concept map is either (1) not yet created (2) already present
    assert(!m_file->GetConceptMap() || m_file->GetConceptMap());
  }

  QtPvdbConceptMapDialog d(m_file);
  this->ShowChild(&d);

  //By now, the concept map must have been (1) created (2) already present
  assert(m_file->GetConceptMap());

  if (d.GoBackToMenu())
  {
    m_back_to_menu = true;
    close();
  }

  //Same test as in constructor
  if (m_file->GetConceptMap()->GetNodes().size() > 1) //1, as node[0] is focal question
  {
    if (m_widget)
    {
      m_widget->setEnabled(false);
      assert(!this->GetWidget()->isEnabled());
    }
    ui->button_add->setEnabled(false);
    ui->edit->setEnabled(false);
  }
}
void
ControllerPOMDP::
normalizeBelief ( boost::shared_ptr<JointBeliefInterface> b )
{
    vector<double> one_vec ( getNumberOfStates(), 1.0 );
    float sum = b->InnerProduct ( one_vec );
    if ( sum > 0 )
    {
        for ( size_t s = 0; s < getNumberOfStates(); s++ )
        {
            float p = b->Get ( s ) / sum; ///normalizing belief to 1
            b->Set ( s, p );
        }
    }
    else
    {
        ROS_WARN ( "ControllerPOMDP:: Failed to normalize. Setting belief to default ISD." );
        b->Set ( * ( loader_->GetDecPOMDP()->GetISD() ) );
    }
}
const std::string ribi::pvdb::Cluster::ToXml(const boost::shared_ptr<const pvdb::Cluster>& cluster)
{
  std::stringstream s;
  s << "<cluster>";
  {
    const std::vector<boost::shared_ptr<const ribi::cmap::Concept> >& v = cluster->Get();
    std::for_each(v.begin(), v.end(),
      [&s](const boost::shared_ptr<const ribi::cmap::Concept>& concept)
      {
        s << concept->ToXml();
      }
    );
  }
  s << "</cluster>";

  const std::string r = s.str();
  assert(r.size() >= 19);
  assert(r.substr(0,9) == std::string("<cluster>"));
  assert(r.substr(r.size() - 10,10) == std::string("</cluster>"));

  return r;
}
VALUE
getObject(VALUE /*self*/, VALUE path)
{
    boost::shared_ptr<Leaf> leaf = gMyPrivateContext->Get(STR2CSTR(path));
    return ScriptServer::GetZeitgeistObject(leaf).Get();
}
Exemple #11
0
Tile::Tile( Vec2D p, boost::shared_ptr<SpriteLoader> spr_loader ) : pos( p )
{
	flow = spr_loader->Get( "flow" );
	flow->spr->SetHotSpot( 16, 16 );
	flow_power = 0;
}
Exemple #12
0
Script::Script(boost::shared_ptr<const Buffer> script) :
        m_script(script)
{
    m_binding.DoString(static_cast<const char*>(script->Get()));
}