bool EpicNavigationNodeHarmonic::srvSetCells(epic::SetCells::Request &req, epic::SetCells::Response &res)
{
    if (!init_alg) {
        ROS_WARN("Warning[EpicNavigationNodeHarmonic::srvSetCells]: Algorithm was not initialized.");
        res.success = false;
        return false;
    }

    std::vector<unsigned int> v;
    std::vector<unsigned int> types;

    for (unsigned int i = 0; i < req.types.size(); i++) {
        // Note: For the SetCells service, these are assigning the raw cells, not picking world coordinates.
        // Thus, no worldToMap translation is required.
        unsigned int x = req.v[2 * i + 0];
        unsigned int y = req.v[2 * i + 1];

        if (x >= width || y >= height) {
            continue;
        }

        v.push_back((unsigned int)req.v[2 * i + 0]);
        v.push_back((unsigned int)req.v[2 * i + 1]);
        types.push_back((unsigned int)req.types[i]);
    }

    setCells(v, types);

    v.clear();
    types.clear();

    res.success = true;

    return true;
}
bool EpicNavigationNodeHarmonic::srvResetFreeCells(epic::ResetFreeCells::Request &req, epic::ResetFreeCells::Response &res)
{
    if (!init_alg) {
        ROS_WARN("Warning[EpicNavigationNodeHarmonic::srvResetFreeCells]: Algorithm was not initialized.");
        res.success = false;
        return false;
    }

    std::vector<unsigned int> v;
    std::vector<unsigned int> types;

    for (unsigned int y = 1; y < height - 1; y++) {
        for (unsigned int x = 1; x < width - 1; x++) {
            if (harmonic.locked[y * width + x] == 0) {
                v.push_back(x);
                v.push_back(y);
                types.push_back(EPIC_CELL_TYPE_FREE);
            }
        }
    }

    setCells(v, types);

    v.clear();
    types.clear();

    res.success = true;

    return true;
}
Exemplo n.º 3
0
/**
 * Initialize SDL
 *
 * @param int rows the number of rows that will be displayed
 * @param int cols the number of columns that will be displayed
 * @param int i the time interval in milliseconds after which the next
 * generation is drawn
 * @param ConwaysGameOfLife *cgol pointer to the object that encapsulates the
 * game's actual logic
 * @param positions_t positions the first generation of cells to be displayed
 *
 * @throws SDLException if SDL coudn't be initialized
 *
 * @see{
 *  game::getWindowSize
 * }
 *
 * TODO: allow the user to draw his own pattern using the mouse at the start
 * A nice feature for this would be to highlight the cell under the and only
 * set it if the user clicks on it
 */
Game::Game(int rows, int cols, unsigned int i, SDL_Color acolor,
           SDL_Color dcolor, ConwaysGameOfLife *cgol, positions_t pos)
        : no_rows(rows), no_columns(cols), interval(i), life(cgol){

    if(SDL_Init(SDL_INIT_VIDEO) < 0){
        throw SDLException("Couldn't initialize SDL!");
    }

    const SDL_VideoInfo* vinfo = SDL_GetVideoInfo();

    unsigned int length = std::min(vinfo->current_w, vinfo->current_h) - 50;
    setCellSideLength(length);

    SDL_Rect size = getWindowSize(length);

    screen = SDL_SetVideoMode(size.w, size.h, vinfo->vfmt->BitsPerPixel, flags);

    if(screen == nullptr){
        throw SDLException("Couldn't set SDL video mode!");
    }

    alive_color = SDL_MapRGB(vinfo->vfmt, acolor.r, acolor.g, acolor.b);
    dead_color = SDL_MapRGB(vinfo->vfmt, dcolor.r, dcolor.g, dcolor.b);

    std::vector<SDL_Rect> rects = setCells(pos, alive_color);

    SDL_UpdateRects(screen, rects.size(), rects.data());

    running = true;
}
bool EpicNavigationNodeHarmonic::srvRemoveGoals(epic::ModifyGoals::Request &req, epic::ModifyGoals::Response &res)
{
    if (!init_alg) {
        ROS_WARN("Warning[EpicNavigationNodeHarmonic::srvRemoveGoals]: Algorithm was not initialized.");
        res.success = false;
        return false;
    }

    std::vector<unsigned int> v;
    std::vector<unsigned int> types;

    // Note: Removing goals turns them into free space. Recall, however, that goals can
    // only be added on free space (above).
    for (unsigned int i = 0; i < req.goals.size(); i++) {
        float x = 0.0f;
        float y = 0.0f;

        if (!worldToMap(req.goals[i].pose.position.x, req.goals[i].pose.position.y, x, y)) {
            continue;
        }

        v.push_back((unsigned int) x);
        v.push_back((unsigned int) y);
        types.push_back(EPIC_CELL_TYPE_FREE);
    }

    setCells(v, types);

    v.clear();
    types.clear();

    res.success = true;

    return true;
}
Exemplo n.º 5
0
void MeshPartition::setRemainder(const MeshPartition& part)
{
  setGrid(part.getGrid());
  QVector<vtkIdType> rcells;
  getRestCells(m_Grid, part.m_Cells, rcells);
  setCells(rcells);
}
Exemplo n.º 6
0
void MeshPartition::setVolume(QString volume_name)
{
  m_Grid = GuiMainWindow::pointer()->getGrid();
  resetOrientation(m_Grid);
  VolumeDefinition V = GuiMainWindow::pointer()->getVol(volume_name);
  QList<vtkIdType> cls;
  EG_VTKDCC(vtkIntArray, cell_code,   m_Grid, "cell_code");
  EG_VTKDCC(vtkIntArray, cell_orgdir, m_Grid, "cell_orgdir");
  EG_VTKDCC(vtkIntArray, cell_curdir, m_Grid, "cell_curdir");
  EG_VTKDCC(vtkIntArray, cell_voldir, m_Grid, "cell_voldir");
  for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
    if (isSurface(id_cell, m_Grid)) {
      int bc = cell_code->GetValue(id_cell);
      cell_voldir->SetValue(id_cell, 0);
      if (V.getSign(bc) != 0) {
        cls.append(id_cell);
        if (V.getSign(bc) == -1) {
          cell_voldir->SetValue(id_cell, 1);
        }
      }
    } else {
      if (cell_code->GetValue(id_cell) == V.getVC()) {
        cls.append(id_cell);
      }
    }
  }
  setCells(cls);
}
Exemplo n.º 7
0
void HTMLTable::addCell( HTMLTableCell *cell )
{
    while ( col < totalCols && cells[row][col] != 0L )
	col++;
    setCells( row, col, cell );

    col++;
}
Exemplo n.º 8
0
    SpriteSheet::SpriteSheet(const std::string& filename, unsigned int rows, unsigned int columns) :
        Picture{filename}
    {
        m_callback.widgetType = "SpriteSheet";

        setCells(rows, columns);
        if ((rows > 1) || (columns > 1))
            setSize(m_texture.getImageSize().x / columns, m_texture.getImageSize().y / rows);
    }
Exemplo n.º 9
0
void CellsMover::undoMoveCells(const TPoint &pos) const {
  TXsheet *xsh = getXsheet();
  int r        = pos.y;
  int c        = pos.x;
  if (m_qualifiers & eInsertCells) {
    for (int i = 0; i < m_colCount; i++) xsh->removeCells(r, c + i, m_rowCount);
  } else {
    for (int i = 0; i < m_colCount; i++) xsh->clearCells(r, c + i, m_rowCount);
    if (m_qualifiers & eOverwriteCells) setCells(m_oldCells, r, c);
  }
}
/******************************************************************************
* Class AccountPage :: AccountPage - Constructor for the account page         *
*                                                                             *
* Define yourself as an IMultiCellCanvas                                      *
* Create generic page buttons                                                 *
* Create generic page container buttons                                       *
* Create static text for the user ID                                          *
* Create static text for the node                                             *
* Create entryfield for the user ID                                           *
* Create entryfield for the node                                              *
* Define a null container pointer                                             *
* Define a null container object pointer                                      *
* Define a null container column pointer                                      *
* Define a null container column pointer                                      *
* Create an account data object given the key                                 *
* Create a empty account data object                                          *
* Set the key in your private data                                            *
* Set the isQuery in your private data                                        *
* Create the notebook page settings                                           *
* Create a select handler and later attach to the container                   *
******************************************************************************/
AccountPage::AccountPage(  IWindow* pParent,
                           const IString& aKey )
     :IMultiCellCanvas     ( ID_ACCOUNT_PAGE, pParent, pParent ),
      pageButtons          ( ID_ACCOUNT_PAGE_BUTTONS, this, this, false ),
      pageCnrButtons       ( ID_ACCOUNT_PAGE_CNRBUTTONS,
                             this, this, false ),
      userIdText           ( ID_NO_ITEM, this, this ),
      nodeSysText          ( ID_NO_ITEM, this, this ),
      userId               ( ID_ACC_USERID_EF, this, this,
                             IRectangle(),
                             IEntryField::classDefaultStyle
                             | IControl::tabStop),
      nodeSys              ( ID_ACC_NODESYS_EF, this, this,
                             IRectangle(),
                             IEntryField::classDefaultStyle
                             | IControl::tabStop ),
      pCnr                 ( (IContainerControl*) NULL ),
      pAcctCnrObj          ( (AcctCnrObj*) NULL ),
      pColUserID           ( (IContainerColumn*) NULL ),
      pColNodeSys          ( (IContainerColumn*) NULL ),
      acctData             ( aKey ),
      origAcctData         (),
      Key                  ( aKey ),
      isAquery             ( false ),
      thePageSettings      ( IApplication::current().userResourceLibrary().
                             loadString( STR_ACC_ACCOUNT_TAB ), NULL,
                             INotebook::PageSettings::autoPageSize
                             | INotebook::PageSettings::majorTab ),
      cnrSelHandler        ( this )

{
/*-----------------------------------------------------------------------------
| Save the account data to another object in case the user wishes to          |
|  undo any changes.                                                          |
| Label the static text objects.                                              |
| Set the limit for the entryfields.                                          |
-----------------------------------------------------------------------------*/
   origAcctData = acctData;
   userIdText.setText( STR_ACC_USERID );
   nodeSysText.setText( STR_ACC_NODESYS );
   userId.setLimit(  DISPLAY_LARGE );
   nodeSys.setLimit( DISPLAY_LARGE );

/*-----------------------------------------------------------------------------
| Fill the container from the database.                                       |
| Set the objects on yourself (IMultiCellCanvas).                             |
| Start handling the events.                                                  |
-----------------------------------------------------------------------------*/
   fillCnr();
   setCells();
   handleIt();
};
Exemplo n.º 11
0
void MeshPartition::setGrid(vtkUnstructuredGrid *grid, bool use_all_cells)
{
  m_TrackGrid = false;
  resetTimeStamps();
  m_Grid = grid;
  if (use_all_cells) {
    QVector<vtkIdType> cls(grid->GetNumberOfCells());
    for (vtkIdType id_cell = 0; id_cell < cls.size(); ++id_cell) {
      cls[id_cell] = id_cell;
    }
    setCells(cls);
  }
}
Exemplo n.º 12
0
/**
 * Actually run the game:
 * process events, advance through generations and draw the cells
 *
 * @see{
 *  Game::setCell
 *  Game::setCells
 *  Game::processEvent
 * }
 */
void Game::run(){
    SDL_Event event;

    while(running){
        while(SDL_PollEvent(&event)){
            processEvent(&event);
        }

        std::pair<positions_t, positions_t> positions = life->evolve();

        std::vector<SDL_Rect> cell_rects(setCells(positions.first, alive_color));
        std::vector<SDL_Rect> dead_cell_rects(
            setCells(positions.second, dead_color));

        cell_rects.insert(cell_rects.end(), dead_cell_rects.begin(),
            dead_cell_rects.end());

        SDL_UpdateRects(screen, cell_rects.size(), cell_rects.data());

        SDL_Delay(interval);
    }
}
Exemplo n.º 13
0
//
// xsheet <- m_cells; insert cells if qualifiers contain eInsertCells
//
void CellsMover::moveCells(const TPoint &pos) const {
  int r        = pos.y;
  int c        = pos.x;
  TXsheet *xsh = getXsheet();
  if (m_qualifiers & eInsertCells) {
    for (int i = 0; i < m_colCount; i++) {
      TXshColumn *column = xsh->getColumn(c + i);
      if (column) {
        if (column->getCellColumn() == 0 || column->isLocked()) continue;
        xsh->insertCells(r, c + i, m_rowCount);
      }
    }
  }
  setCells(m_cells, r, c);
}
Exemplo n.º 14
0
void EpicNavigationNodeHarmonic::subOccupancyGrid(const nav_msgs::OccupancyGrid::ConstPtr &msg)
{
    // If the size changed, then free everything and start over.
    // Note we don't care if the resolution or offsets change.
    if (msg->info.width != width || msg->info.height != height) {
        uninitAlg();
        initAlg(msg->info.width, msg->info.height);
    }

    if (!init_alg) {
        ROS_WARN("Warning[EpicNavigationNodeHarmonic::subOccupancyGrid]: Algorithm was not initialized.");
        return;
    }

    // These only affect the final path, not the path computation.
    x_origin = msg->info.origin.position.x;
    y_origin = msg->info.origin.position.y;
    resolution = msg->info.resolution;

    // Copy the data to the Harmonic object.
    std::vector<unsigned int> v;
    std::vector<unsigned int> types;

    for (unsigned int y = 1; y < height - 1; y++) {
        for (unsigned int x = 1; x < width - 1; x++) {
            if (msg->data[y * width + x] == EPIC_OCCUPANCY_GRID_NO_CHANGE || isCellGoal(x, y)) {
                // Do nothing.
            } else if (msg->data[y * width + x] >= EPIC_OCCUPANCY_GRID_OBSTACLE_THRESHOLD) {
                v.push_back(x);
                v.push_back(y);
                types.push_back(EPIC_CELL_TYPE_OBSTACLE);
            } else {
                v.push_back(x);
                v.push_back(y);
                types.push_back(EPIC_CELL_TYPE_FREE);
            }
        }
    }

    setCells(v, types);

    v.clear();
    types.clear();
}
Exemplo n.º 15
0
bool EpicNavigationNodeHarmonic::srvAddGoals(epic::ModifyGoals::Request &req, epic::ModifyGoals::Response &res)
{
    if (!init_alg) {
        ROS_WARN("Warning[EpicNavigationNodeHarmonic::srvAddGoals]: Algorithm was not initialized.");
        res.success = false;
        return false;
    }

    std::vector<unsigned int> v;
    std::vector<unsigned int> types;

    for (unsigned int i = 0; i < req.goals.size(); i++) {
        float x = 0.0f;
        float y = 0.0f;

        worldToMap(req.goals[i].pose.position.x, req.goals[i].pose.position.y, x, y);

        // If the goal location is an obstacle, then do not let it add a goal here.
        if (isCellObstacle((unsigned int)(x + 0.5f), (unsigned int)(y + 0.5f))) {
            continue;
        }

        v.push_back((unsigned int) x);
        v.push_back((unsigned int) y);
        types.push_back(EPIC_CELL_TYPE_GOAL);
    }

    if (v.size() == 0) {
        ROS_WARN("Warning[EpicNavigationNodeHarmonic::srvAddGoals]: Attempted to add goal(s) inside obstacles. No goals added.");
        res.success = false;
        return false;
    }

    setCells(v, types);

    v.clear();
    types.clear();

    res.success = true;

    return true;
}
//*****************************************************************************
// CLASS GeneralPage - Contructor
//*****************************************************************************
GeneralPage :: GeneralPage(IWindow* pParent,
                           const IString empNum)
             : IMultiCellCanvas(ID_GENERAL_PAGE, pParent, pParent),
               employeeData(empNum ),
               pageButtons(ID_GENERAL_PAGE_BUTTONS,
                          this,this, false),
               employeeIdText  (ID_NO_ITEM, this, this ),
               lastNameText    (ID_NO_ITEM, this, this ),
               firstNameText   (ID_NO_ITEM, this, this ),
               middleNameText  (ID_NO_ITEM, this, this ),
               intPhoneText    (ID_NO_ITEM, this, this ),
               extPhoneText    (ID_NO_ITEM, this, this ),
               roomText        (ID_NO_ITEM, this, this ),
               deptText        (ID_NO_ITEM, this, this ),
               bldgText        (ID_NO_ITEM, this, this ),
               divText         (ID_NO_ITEM, this, this ),
               mgrEmpNumText   (ID_NO_ITEM, this, this ),
               mgrEmpNameText  (ID_NO_ITEM, this, this ),
               employeeId     (ID_GEN_EMPLOYEE_ID_EF   , this, this,
                              IRectangle(),
                              IEntryField::classDefaultStyle |
                              IControl::tabStop),
               lastName       (ID_GEN_LAST_NAME_EF     , this, this,
                               IRectangle(),
                               IEntryField::classDefaultStyle |
                               IControl::tabStop),
               firstName      (ID_GEN_FIRST_NAME_EF    , this, this,
                               IRectangle(),
                               IEntryField::classDefaultStyle |
                               IControl::tabStop),
               middleInitial  (ID_GEN_MIDDLE_INITIAL_EF, this, this,
                               IRectangle(),
                               IEntryField::classDefaultStyle |
                               IControl::tabStop),
               intPhone       (ID_GEN_INT_PHONE_EF, this, this,
                               IRectangle(),
                               IEntryField::classDefaultStyle |
                               IControl::tabStop),
               extPhone       (ID_GEN_EXT_PHONE_EF, this, this,
                               IRectangle(),
                               IEntryField::classDefaultStyle |
                               IControl::tabStop),
               room           (ID_GEN_ROOM_EF     , this, this,
                               IRectangle(),
                               IEntryField::classDefaultStyle |
                               IControl::tabStop),
               building       (ID_GEN_BUILDING_EF , this, this,
                               IRectangle(),
                               IEntryField::classDefaultStyle |
                               IControl::tabStop),
               deptName       (ID_GEN_DEPT_EF     , this, this,
                               IRectangle(),
                               IEntryField::classDefaultStyle |
                               IControl::tabStop),
               division       (ID_GEN_DIVISION_EF , this, this,
                               IRectangle(),
                               IEntryField::classDefaultStyle |
                               IControl::tabStop),
               employeeType   (this),
               mgrEmpId       (ID_GEN_MGR_EMP_ID_EF, this, this,
                               IRectangle(),
                               IEntryField::classDefaultStyle |
                               IControl::tabStop),
               mgrName        (ID_GEN_MGR_NAME_EF  , this, this,
                               IRectangle(),
                               IEntryField::classDefaultStyle |
                               IControl::tabStop),
               Key(empNum),
               thePageSettings( IApplication::current().userResourceLibrary().loadString(
                                STR_GEN_GENERAL_TAB), NULL,
                                INotebook::PageSettings::autoPageSize
                                | INotebook::PageSettings::majorTab ),
              isAquery(false)
{
   // set up the fields
   setUp();
   if ( employeeId.text().length() )
      employeeId.disableDataUpdate();

   // set up the page
   setCells();

   // populate the page from any database info
   displayData();
   handleIt();
}
Exemplo n.º 17
0
 void SpriteSheet::setColumns(unsigned int columns)
 {
     setCells(m_Rows, columns);
 }
Exemplo n.º 18
0
AbstractGrid::AbstractGrid(int nbCells) {
    setNbCells(nbCells);
    setCells();
}
Exemplo n.º 19
0
 void SpriteSheet::setRows(unsigned int rows)
 {
     setCells(rows, m_Columns);
 }