Example #1
0
void TextManager::drawInput(bool onOff){
  if(!onOff)
    Robot.setTextColor(WHITE);

  Robot.setCursor(getCol(inputCol),getLin(inputLin)+1);
  Robot.print('_');
  
  Robot.setTextColor(BLACK);

}
Example #2
0
static int freeway2(const Data* data, int xdir, int ydir, int c) {
  if(xdir == 0 && ydir == 0) {
    fprintf(stderr, "bug: xdir == ydir == 0\n");
    return 0;
  }

  while(getCol(data->iposx + xdir * c, 
							 data->iposy + ydir * c) == 0) c++;
  return c;
}
Example #3
0
double Matrix::getColSum(int n) const
{
   Matrix column(getCol(n));
   double sum = 0;
   
   for (int i=0; i<column.height; i++)
   {
      sum += column.get(i,0);
   }
   return sum;
}
Example #4
0
void Sudoku::rotate(int n){
	int turnTime=(n%4);
	int copy[81];
	int i,j;

	for(i=0;i<81;i++){
		copy[i]=sudokuIn[i];
	}

	switch(turnTime){
		case 0:
			break;

		case 1:
			for(i=0;i<9;i++){
				getCol(i,copy);
				for(j=0;j<9;j++){
					sudokuIn[i*9+j] = arr_check[8-j];
				}
			}
			break;

		case 2:
			for(i=8;i>=0;i--){
				getRow(i*9,copy);
				for(j=0;j<9;j++){
					sudokuIn[(8-i)*9+j] = arr_check[8-j];
				}
			}
			break;

		case 3:
			for(i=8;i>=0;i--){
				getCol(i,copy);
				for(j=0;j<9;j++){
					sudokuIn[(8-i)*9+j] = arr_check[j];
				}
			}
			break;
	}
};
CvMat* estimateNtd(const CvMat* K1, const CvMat* K2, const CvMat* R, const CvMat* t, const CvMat* H) {

	CvMat* NH = matMul(inv(K2), H, K1);
	CvMat* RmNH = sub(R, NH);

	CvMat* NNH = scale(NH, 1/cvmGet(NH, 2, 2));
	CvMat* NR = scale(R, 1/cvmGet(R, 2, 2));
	CvMat* NRmNNH = sub(NR, NNH);

	cout<<"R: "<<R<<endl;
	cout<<"NH: "<<NH<<endl;
	cout<<"RmNH: "<<RmNH<<endl;

	cout<<"NR: "<<NR<<endl;
	cout<<"NNH: "<<NNH<<endl;
	cout<<"NRmNNH: "<<NRmNNH<<endl;

	CvMat* Ntd = cvCreateMat(1, 3, CV_64FC1);

	CvMat* c0 = getCol(NRmNNH, 0);
	CvMat* c1 = getCol(NRmNNH, 1);
	CvMat* c2 = getCol(NRmNNH, 2);

	cvmSet(Ntd, 0, 0, estimateScale(t, c0));
	cvmSet(Ntd, 0, 1, estimateScale(t, c1));
	cvmSet(Ntd, 0, 2, estimateScale(t, c2));

	cout<<"H: "<<H<<endl;
	cout<<"recovered H: "<<matMul(K2, sub(R, matMul(t, Ntd)), inv(K1))<<endl;

	cvReleaseMat(&NH);
	cvReleaseMat(&RmNH);

	cvReleaseMat(&c0);
	cvReleaseMat(&c1);
	cvReleaseMat(&c2);

	return Ntd;
}
Example #6
0
		bool backtrack(int solve[MAX][MAX]){
			int row=0, col=0;		
			int r = getRow();
			int c = getCol();
			
			//keep going through board to begin with empty tile
			while(board[r][c]!= 0){
				r = getRow();
				c = getCol();
			}

			row = r;
			col = c;	
			//may need more temp
					
 
    // check if the board is filled then it is a win
    	//if(std::find(grid[0], grid[row-1]+col,0))
        if (!isFilled(solve, row, col))
       return true; 
                 
    // go through the numbers 1-9 that will insist on what can be inserted
    for (int num = 1; num <= 9; num++){
    // checks valid input, then puts in num
    if (canPlace(solve, row, col, num)){
    	   solve[row][col] = num;
                                                               
    //when true recurse 
    if (backtrack(solve))
    return true;
                                                                                               
    else //otherwise take away the value 
    solve[row][col] = 0;
    				}
    }
    return false; // this triggers backtracking

		}
Example #7
0
int Astar::getG(int col, int row, int id)
{
    auto item = (AstarItem*)_close->getObjectAtIndex(id);

    int fx = item->getCol();
    int fy = item->getRow();
    int fg = item->getG();
    if(fx - col != 0 && fy - row != 0) {
        return fg + 14;
    } else {
        return fg + 10;
    }

}
Example #8
0
Grid<double>* graphToGrid(BasicGraph* graph) {
    int maxRow = -1;
    int maxCol = -1;
    for (Vertex* v : graph->getVertexSet()) {
        maxRow = max(maxRow, getRow(v));
        maxCol = max(maxCol, getCol(v));
    }
    if (maxRow < 0 || maxCol < 0) {
        return NULL;
    }

    // initially set all to be walls
    Grid<double>* grid = new Grid<double>(maxRow + 1, maxCol + 1);
    for (int r = 0; r <= maxRow; r++) {
        for (int c = 0; c <= maxCol; c++) {
            grid->set(r, c, kMazeWall);
        }
    }
    for (Vertex* v : graph->getVertexSet()) {
        grid->set(getRow(v), getCol(v), getGridValue(v));
    }

    return grid;
}
Example #9
0
Colour BSDF::rho(const RenderContext *rc, const HitContext *hc, const Vec3 &wo, const BxDFtype flags) const
{
	Colour ret(0.0f);
	
	for (int i = 0; i < numBxDFs; ++i)
	{
		if (bxdfs[i]->hasFlags(flags))
		{
			const Colour C = getCol(rc, hc, i);
			ret += bxdfs[i]->rho(wo, C);
		}
	}

	return ret;

}
Example #10
0
bool Sudoku::check_answer(int n){

	getRow(n,answerBoard);
	if(checkUnity(arr_check) == false)
		return false;

	getCol(n,answerBoard);
	if(checkUnity(arr_check) == false)
		return false;

	getCell(n,answerBoard);
	if(checkUnity(arr_check) == false)
		return false;

	return true;
};
Example #11
0
void GameScene::createPlayerItem(cocos2d::Ref *pSender)
{
    auto mapObj = static_cast<MapObject*>(pSender);
    auto row = mapObj->getRow(),col = mapObj->getCol();
    //mapObj->release();
    auto itemId = rand()%5;
    if(itemId<5)
    {
        auto playerItemType = GameManager::getInstance()->getPlayerItems().at(itemId);
        auto item = PlayerItem::create();
        item->setItemType(playerItemType);
        item->setZOrder(row*10);
        item->setIdx(itemId);
        item->setPosition(mapObj->convertCoordinate2Point(Point(col,row)));
        GameManager::getInstance()->getMapTileLayer()->addChild(item);
    }
}
Example #12
0
void Astar::starSearch(int fid)
{
    auto item = (AstarItem*)_close->getObjectAtIndex(fid);
    int col = item->getCol();
    int row = item->getRow();

    // 搜索目前的点的上,下,左,右四个方向

    // 下
    int mycol = col;
    int myrow = row - 1;
    if(myrow >= 0 && checkMap(mycol, myrow)) {
        if(checkOpen(mycol, myrow, fid) && checkClose(mycol, myrow)) {
            addToOpen(mycol, myrow, fid);
        }
    }

    // 左
    mycol = col - 1;
    myrow = row;
    if(mycol >= 0 && checkMap(mycol, myrow)) {
        if(checkOpen(mycol, myrow, fid) && checkClose(mycol, myrow)) {
            addToOpen(mycol, myrow, fid);
        }
    }

    // 上
    mycol = col;
    myrow = row + 1;
    if(myrow < _map->getMapSize().height && checkMap(mycol, myrow)) {
        if(checkOpen(mycol, myrow, fid) &&checkClose(myrow, myrow)) {
            addToOpen(mycol, myrow, fid);
        }
    }

    // 右
    mycol = col + 1;
    myrow = row;
    if(mycol < _map->getMapSize().height && checkMap(mycol, myrow)) {
        if(checkOpen(mycol, myrow, fid) &&checkClose(myrow, myrow)) {
            addToOpen(mycol, myrow, fid);
        }
    }

}
Example #13
0
void GridButton::initBorders()
{
    int r = getRow();
    int c = getCol();
    QColor darkGray("#3D3D3D");

    if ((c + 1) % 5 == 0)
        borderRight = darkGray;

    if (c % 5 == 0)
        borderLeft = darkGray;

    if ((r + 1) % 5 == 0)
        borderBottom = darkGray;

    if (r % 5 == 0)
        borderTop = darkGray;
}
Example #14
0
// draw calls to all controls draw
void Panel::draw(Graphics &g, int left, int top, int layer)
{
	if (!visibility)
		return;
	
	if (layer == getLayer()) {
		iControl::draw(g, left, top, layer);
		/*for (int i = 0; i < getWidth(); i++) {
			for (int j = 0; j < getHeight(); j++) {
				g.write(i + left + getCol(),j + top + getLine()," ");
			}
		}*/
	}
	
	for (auto c : controls) {
		c->draw(g, left + getCol(), top + getLine(), layer);
	}
}
Example #15
0
/**
 * @brief Overrides *= operator for IntMatrix to multiply a matrix with current matrix.
 * @param IntMatrix we wish to multiply the current matrix.
 * @return IntMatrix& reference to the IntMatrix we updated
 */
IntMatrix& IntMatrix :: operator*= (const IntMatrix &other)
{
	assert (getCol() == other.getRow());
    // initialize and empty matrix of the proper size
    IntMatrix tempMatrix(getRow(), other.getCol());
    // initialize each index in that matrix to be the dot product between a row and column
    for (int i = 0; i < tempMatrix.getRow(); i++)
    {
        for (int j = 0; j < tempMatrix.getCol(); j++)
        {
            tempMatrix.getArr()[(i * tempMatrix.getCol()) + j] = dotProduct(&getArr()[i * _colNum],
                                                      &other.getArr()[j], _colNum, other.getCol());
        }
    }
    // set our matrix to equal this matrix and return its reference
    *this = tempMatrix;
    return *this;
}
void SpecificWorker::newAprilTag(const tagsList &l)
{
	// Initial checks
	if (l.size()==0 or innerModel==NULL) return;
	// Tag selection
	static int lastID = -1;
	int indexToUse = 0;
	for (uint i=0; i<l.size(); i++)
	{
		if (l[i].id == lastID)
		{
			indexToUse = i;
		}
	}
	lastID = l[indexToUse].id;
	const RoboCompAprilTags::tag  &tag = l[indexToUse];

	// Localization-related node identifiers
	const QString robot_name("robot");
	const QString tagSeenPose("aprilOdometryReference_seen_pose");
	const QString tagReference = QString("aprilOdometryReference%1_pose").arg(tag.id);

	// Update seen tag in InnerModel
	try { innerModel->updateTransformValues(tagSeenPose, tag.tx, tag.ty, tag.tz, tag.rx, tag.ry, tag.rz); }
	catch (...) { printf("Can't update node %s (%s:%d)\n", tagSeenPose.toStdString().c_str(), __FILE__, __LINE__); }

	// Compute the two ways to get to the tag, the difference-based error and the corrected odometry matrix
	const auto M_T2C = innerModel->getTransformationMatrix("root", tagReference);
	const auto M_t2C = innerModel->getTransformationMatrix("root", tagSeenPose);
	const auto err = M_T2C * M_t2C.invert();
	const auto M_W2R = innerModel->getTransformationMatrix(robot_name, innerModel->getParentIdentifier(robot_name));
	const auto correctOdometry = err * M_W2R;

	// Extract the scalar values from the pose matrix and send the correction
	const auto new_T = correctOdometry.getCol(3).fromHomogeneousCoordinates();
	const auto new_R = correctOdometry.extractAnglesR_min();
	

	try { aprilbasedlocalization_proxy->newPose(new_T(0), new_T(2), new_R(1)); }
	catch( Ice::Exception e) { fprintf(stderr, "Can't connect to aprilbasedlocalization proxy\n"); }
	
	printf("%f %f   @ %f\n", new_T(0), new_T(2), new_R(1));
}
Example #17
0
bool Astar::checkOpen(int col, int row, int id)
{
    // 检查open列表中是否有更小的步长,并排序
    for(int i = _open->count() - 1; i > 0; i--) {
        auto item = (AstarItem*)_open->getObjectAtIndex(i);
        if(item->getCol() == col && item->getRow() == row) {
            int tempG = getG(col, row, id);
            if(tempG < item->getG()) {
                item->setG(tempG);
                item->setFid(id);
                item->setF(tempG + item->getH());
                resetSort(i);
            }
            return false;
        }
    }

    return true;
}
Example #18
0
void Sudoku::solve(){
	int i,j;
	ansCount=0;

	for(i=0;i<81;i=i+9){//test if the sudoku can be solved
		getRow(i,sudokuIn);
		if(checkUnity(arr_check)==false){
			cout << "0"
				 << endl;
	 		return;
	 	}
	 	getCol(i,sudokuIn);
	 	if(checkUnity(arr_check)==false){
			cout << "0"
				 << endl;
	 		return;
	 	}
	 	getCell(i,sudokuIn);
	 	if(checkUnity(arr_check)==false){
			cout << "0"
				 << endl;
	 		return;
	 	}
	}

	for(i=0;i<81;i++){
		answerBoard[i]=sudokuIn[i];
	}

	fillBlank();

	if(ansCount==1){
		cout << "1" << endl;
		printOut(keepAns);
	}
	else if(ansCount==0)
		cout << "0";
	else if(ansCount==2){
		cout << "2";
	}
};
Example #19
0
void thread_runner(void* _arg) {
  struct thread_runner_args *arg = (struct thread_runner_args*)_arg;
  int row, col, attr;
  
  while(1) {
    irql_t saved_irql = hal_irql_set(IRQL_DISPATCH);
   
    row = getRow();
    col = getCol();
    attr = getAttr();
    
    setPos(arg->row, arg->col);
    setAttr(arg->attr[arg->state++ % 2]);
    printf("%s", arg->string);
    
    setAttr(attr);
    setPos(row, col);
    
    hal_irql_restore(saved_irql);

    delay(1000/arg->freq);
  }
}
Example #20
0
void multiboot_print() {
  int row = getRow();
  int col = getCol();
  
  printf("multiboot options\n");
  if(mb_magic == MULTIBOOT_BOOTLOADER_MAGIC) {
    if(mb_info->flags & MULTIBOOT_HAS_LOADER_NAME)
      printf(PAD "loader: %s\n", mb_info->loader_name);
    
    if(mb_info->flags & MULTIBOOT_HAS_CMDLINE)
      printf(PAD "cmdline: %s\n", mb_info->cmdline);
    
    if(mb_info->flags & MULTIBOOT_HAS_VBE)
      printf(PAD "vbe installed\n" );
    
    if(mb_info->flags & MULTIBOOT_HAS_MODS ) {
      int i;
      printf(PAD "%d module(s) present\n", mb_info->mods_count);
      for(i=0; i< mb_info->mods_count; i++) {
	printf(PAD " %d %x\n",i, (mb_info->mods_addr[i].mod_start));
/*	printf(PAD " contents:");
	s= (char*)mb_info->mods_addr[i].mod_start;
	while(s <(char*)mb_info->mods_addr[i].mod_end || s)
	  putchar(*s++); 
	putchar('\n');*/
      }
    }
    
    if(mb_info->flags & MULTIBOOT_HAS_MEMORY)
      printf(PAD "memory info: low %d, high %d kb\n",
	     mb_info->mem_lower, mb_info->mem_upper);
    
    if(mb_info->flags & MULTIBOOT_HAS_MEM_MAP) {
      struct multiboot_address_range* buffer= mb_info->mmap_addr;
      printf(PAD "memory map present \n");

      while(((char*)buffer - (char*)mb_info->mmap_addr) < mb_info->mmap_length) {
	printf(PAD " %x %x type %s\n",
	       buffer->base_addr_low,
	       buffer->length_low,
	       buffer->type  == 1 ? "ram" : "hw" );
	buffer = (struct multiboot_address_range*)
	  (((char*)buffer)+buffer->size+4);
      }
    }

    if(mb_info->flags & MULTIBOOT_HAS_ELF_SHDR) {
      printf(PAD "ELF symbols found\n");
    }

    if(mb_info->flags & MULTIBOOT_HAS_MODS) {
      printf(PAD "Found %d modules\n", mb_info->mods_count);
    }
    
    if(mb_info->flags & MULTIBOOT_HAS_BIOS_CONFIG) {
      u_int8_t* table = mb_info->config_table;
      printf(PAD "bios config table: \n");
      printf(PAD " model %x submodel %x\n", table[1], table[2]);
      printf(PAD " extended BIOS allocated %d\n", (table[5] & (1<<2)) != 0);
      printf(PAD " RTS present %d\n", (table[5] & (1<<5)) != 0);
      printf(PAD " has 2nd 8259 %d\n", (table[5] & (1<<6)) != 0);
    }
  } else
    printf(": notfrom multiboot!\n");

  setPos(row, col); //restore position
}
Example #21
0
void ETF::Smooth(int half_w, int M)
{
	int	i, j, k;
	int MAX_GRADIENT = -1;
	double weight;
	int s, t;
	int x, y;
	double mag_diff;

	int image_x = getRow();
	int image_y = getCol();
    
	ETF e2; 

	e2.init(image_x, image_y); 
	e2.copy(*this); 

	double v[2], w[2], g[2];
	double angle;
	double factor;

	for (k = 0; k < M; k++) {
		////////////////////////
		// horizontal
		for (j = 0; j < image_y; j++) {
			for (i = 0; i < image_x; i++) {
				g[0] = g[1] = 0.0;
				v[0] = p[i][j].tx;
				v[1] = p[i][j].ty;
				for (s = -half_w; s <= half_w; s++) {
					////////////////////////////////////////
					x = i+s; y = j;
					if (x > image_x-1) x = image_x-1;
					else if (x < 0) x = 0;
					if (y > image_y-1) y = image_y-1;
					else if (y < 0) y = 0;
					////////////////////////////////////////
					mag_diff = p[x][y].mag - p[i][j].mag; 
					//////////////////////////////////////////////////////
					w[0] = p[x][y].tx;
					w[1] = p[x][y].ty;
					////////////////////////////////
					factor = 1.0;
					angle = v[0] * w[0] + v[1] * w[1];
					if (angle < 0.0) {
						factor = -1.0; 
					}
					weight = mag_diff + 1;  
					//////////////////////////////////////////////////////
					g[0] += weight * p[x][y].tx * factor;
					g[1] += weight * p[x][y].ty * factor;
				}
				make_unit(g[0], g[1]);
				e2[i][j].tx = g[0];
				e2[i][j].ty = g[1];
			}
		}
		this->copy(e2);
		/////////////////////////////////
		// vertical
		for (j = 0; j < image_y; j++) {
			for (i = 0; i < image_x; i++) {
				g[0] = g[1] = 0.0;
				v[0] = p[i][j].tx;
				v[1] = p[i][j].ty;
				for (t = -half_w; t <= half_w; t++) {
					////////////////////////////////////////
					x = i; y = j+t;
					if (x > image_x-1) x = image_x-1;
					else if (x < 0) x = 0;
					if (y > image_y-1) y = image_y-1;
					else if (y < 0) y = 0;
					////////////////////////////////////////
					mag_diff = p[x][y].mag - p[i][j].mag; 
					//////////////////////////////////////////////////////
					w[0] = p[x][y].tx;
					w[1] = p[x][y].ty;
					////////////////////////////////
					factor = 1.0;
					///////////////////////////////
					angle = v[0] * w[0] + v[1] * w[1];
					if (angle < 0.0) factor = -1.0; 
					/////////////////////////////////////////////////////////
					weight = mag_diff + 1; 
					//////////////////////////////////////////////////////
					g[0] += weight * p[x][y].tx * factor;
					g[1] += weight * p[x][y].ty * factor;
				}
				make_unit(g[0], g[1]);
				e2[i][j].tx = g[0];
				e2[i][j].ty = g[1];
			}
		}
		this->copy(e2);
	}
	////////////////////////////////////////////
}
Example #22
0
void get_log_line_Time (Time *t, char *log_line)
{
	getCol(t->string, log_line, 2);
	strtoTime(t);
	countTotalMs(t);
}
Example #23
0
// sample the bsdf
Colour BSDF::sample(RenderContext *rc,
					const HitContext *hc, 
	 				const Vec3 &woW, 
					Vec3 &wiW, 
					float &pdf, 
					const float r1, 
					const float r2, 
					const float r3, 
					BxDFtype flags,
					BxDFtype *sampled) const
{
	// Grab the number of appropriate BxDF
	int matchingComps = numComponents(flags);

	if (matchingComps == 0) 
	{
		pdf = 0.f;
		return Colours::black;
	}

	// Pick the bxdf
	int which = (int)(r3 * matchingComps);//rc->rnd.randInt(matchingComps - 1);
	which = which == matchingComps ? matchingComps - 1 : which;
	
	BxDF *bxdf = NULL;
	int count = which;
	int bxdfNum = 0;

	for (int i = 0; i < numBxDFs; ++i)
	{
		if (bxdfs[i]->hasFlags(flags))
		{
			if (count-- == 0) 
			{
				bxdf = bxdfs[i];
				bxdfNum = i;
				break;
			}
		}
	}

	// Sample the appropriate BxDF
	pdf = 0.0f;
	Vec3 wi;
	const Vec3 wo = hc->onb.untransform(woW);
	const Colour C = getCol(rc, hc, bxdfNum);	

	Colour f = bxdf->sample(rc, wo, wi, pdf, r1, r2, C);
	f = adjust(hc, f, bxdfNum, wo, wi); // custom adjustment for each BSDF
	
	if (pdf == 0.0f) return 0.0f;
	if (sampled != NULL) *sampled = bxdf->type;
	wiW = hc->onb.transform(wi);

	// Compute overall PDF with all matching BxDFs
	if (matchingComps > 1)
	{
		if (!(bxdf->type & BSDF_SPECULAR)) 
		{
			for (int i = 0; i < numBxDFs; ++i) 
			{
				if (bxdfs[i] != bxdf && bxdfs[i]->hasFlags(flags))
					pdf += bxdfs[i]->pdf(wo, wi);
			}
		}
		
		pdf /= matchingComps;
	}

	// Compute value of BSDF for sampled direction
	if (!(bxdf->type & BSDF_SPECULAR)) 
	{
		f = 0.0;
		
		if (Dot(wiW, hc->gNormal) * Dot(woW, hc->gNormal) > 0)
			flags = BxDFtype(flags & ~BSDF_TRANSMISSION); // ignore BTDFs
		else
			flags = BxDFtype(flags & ~BSDF_REFLECTION); // ignore BRDFs
		
		for (int i = 0; i < numBxDFs; ++i)
		{
			if (bxdfs[i]->hasFlags(flags))
			{
				// Tweak eval output to suit each BSDF
				f += adjust(hc, bxdfs[i]->eval(wo, wi, getCol(rc, hc, bxdfNum)), i, wo, wi);
			}
		}
	}

	return f;
}
Example #24
0
//-------------------------------------------------------
// MESSAGE HANDLER
//-------------------------------------------------------
static int8_t
matrix_arithmetic_msg_handler (void *state, Message * msg)
{
//  matrix_arithmetic_t *s = (matrix_arithmetic_t*)state;

  switch (msg->type)
    {
    case MSG_INIT:
      {
	break;
      }

    case MSG_FINAL:
      {
	break;
      }
      // int8_t add (const CYCLOPS_Matrix * A, const CYCLOPS_Matrix * B, CYCLOPS_Matrix * C) 
    case ADD:
      {
	matrix_math_t *m = (matrix_math_t *) (msg->data);
	CYCLOPS_Matrix *A = (CYCLOPS_Matrix *) (m->ImgPtrA);
	CYCLOPS_Matrix *B = (CYCLOPS_Matrix *) (m->ImgPtrB);
	CYCLOPS_Matrix *C =
	  (CYCLOPS_Matrix *) ker_malloc (sizeof (CYCLOPS_Matrix),
					 MATRIX_ARITHMETICS_PID);
	if (NULL == C)
	  {
	    return -ENOMEM;
	  }
	if (add (A, B, C) != SOS_OK)
	  {
	    return -EINVAL;
	  }
	//PUT_PORT();
	//post_long                     
	break;
      }
      // int8_t Sub (const CYCLOPS_Matrix * A, const CYCLOPS_Matrix * B, CYCLOPS_Matrix * C) 
    case SUB:
      {
	matrix_math_t *m = (matrix_math_t *) (msg->data);
	CYCLOPS_Matrix *A = (CYCLOPS_Matrix *) (m->ImgPtrA);
	CYCLOPS_Matrix *B = (CYCLOPS_Matrix *) (m->ImgPtrB);
	CYCLOPS_Matrix *C =
	  (CYCLOPS_Matrix *) ker_malloc (sizeof (CYCLOPS_Matrix),
					 MATRIX_ARITHMETICS_PID);
	if (NULL == C)
	  {
	    return -ENOMEM;
	  }
	if (Sub (A, B, C) != SOS_OK)
	  {
	    return -EINVAL;
	  }
	//PUT_PORT();
	//post_long     
	break;
      }
      // int8_t abssub (const CYCLOPS_Matrix * A, const CYCLOPS_Matrix * B, CYCLOPS_Matrix * C
    case ABS_SUB:
      {
	matrix_math_t *m = (matrix_math_t *) (msg->data);
	CYCLOPS_Matrix *A = (CYCLOPS_Matrix *) (m->ImgPtrA);
	CYCLOPS_Matrix *B = (CYCLOPS_Matrix *) (m->ImgPtrB);
	CYCLOPS_Matrix *C =
	  (CYCLOPS_Matrix *) ker_malloc (sizeof (CYCLOPS_Matrix),
					 MATRIX_ARITHMETICS_PID);
	if (NULL == C)
	  {
	    return -ENOMEM;
	  }
	if (abssub (A, B, C) != SOS_OK)
	  {
	    return -EINVAL;
	  }

	// Kevin - resulting Matrix will be put unto updateBackground, and abssub   => 2 ports
	//PUT_PORT();   
	//PUT_PORT();   
	//  Kevin -  if these are all sos modules, shouldnt is use self state s->M ???
//              post_long(MATRIX_ARITHMETICS_PID, MATRIX_IMAGE_PID, ABS_SUB, sizeof(CYCLOPS_Matrix), M, SOS_MSG_RELEASE);
//              post_long(MATRIX_ARITHMETICS_PID, MATRIX_IMAGE_PID, ABS_SUB, sizeof(CYCLOPS_Matrix), M, SOS_MSG_RELEASE);

	break;
      }

      // int8_t getRow (const CYCLOPS_Matrix * A, CYCLOPS_Matrix * res, uint16_t row) 
    case GET_ROW:
      {
	matrix_location_t *m = (matrix_location_t *) (msg->data);
	CYCLOPS_Matrix *A = (CYCLOPS_Matrix *) (m->matPtr);
	uint16_t row = (m->row);
	CYCLOPS_Matrix *res =
	  (CYCLOPS_Matrix *) ker_malloc (sizeof (CYCLOPS_Matrix),
					 MATRIX_ARITHMETICS_PID);
	if (NULL == res)
	  {
	    return -ENOMEM;
	  }
	if (getRow (A, res, row) != SOS_OK)
	  {
	    return -EINVAL;
	  }
	//PUT_PORT();
	//post_long                             
	break;
      }

      // int8_t getCol (const CYCLOPS_Matrix * A, CYCLOPS_Matrix * res, uint16_t col) 
    case GET_COLUMN:
      {
	matrix_location_t *m = (matrix_location_t *) (msg->data);
	CYCLOPS_Matrix *A = (CYCLOPS_Matrix *) (m->matPtr);
	uint16_t col = (m->col);
	CYCLOPS_Matrix *res =
	  (CYCLOPS_Matrix *) ker_malloc (sizeof (CYCLOPS_Matrix),
					 MATRIX_ARITHMETICS_PID);
	if (NULL == res)
	  {
	    return -ENOMEM;
	  }
	if (getCol (A, res, col) != SOS_OK)
	  {
	    return -EINVAL;
	  }
	//PUT_PORT();
	//post_long     
	break;
      }

      // int8_t getBit (const CYCLOPS_Matrix * A, uint16_t row, uint16_t col) 
    case GET_BIT:
      {
	matrix_location_t *m = (matrix_location_t *) (msg->data);
	CYCLOPS_Matrix *A = (CYCLOPS_Matrix *) (m->matPtr);
	uint16_t row = (m->row);
	uint16_t col = (m->col);
	CYCLOPS_Matrix *res =
	  (CYCLOPS_Matrix *) ker_malloc (sizeof (CYCLOPS_Matrix),
					 MATRIX_ARITHMETICS_PID);
	if (NULL == res)
	  {
	    return -ENOMEM;
	  }
	if (getBit (A, row, col) != SOS_OK)
	  {
	    return -EINVAL;
	  }
	//PUT_PORT();
	//post_long
	break;
      }

      // int8_t scale (const CYCLOPS_Matrix * A, CYCLOPS_Matrix * C, const uint32_t s) 
    case SCALE:
      {
	matrix_scale_t *m = (matrix_scale_t *) (msg->data);
	CYCLOPS_Matrix *A = (CYCLOPS_Matrix *) (m->matPtrA);
	CYCLOPS_Matrix *C = (CYCLOPS_Matrix *) (m->matPtrC);
	uint32_t s = (m->scale_value);
	if (scale (A, C, s) != SOS_OK)
	  {
	    return -EINVAL;
	  }
	//PUT_PORT();
	//post_long
	break;
      }
      // int8_t threshold (const CYCLOPS_Matrix * A, CYCLOPS_Matrix * B, uint32_t t) 
    case THRESHOLD:
      {
	matrix_thresh_t *m = (matrix_thresh_t *) (msg->data);
	CYCLOPS_Matrix *A = (CYCLOPS_Matrix *) (m->matPtr);
	uint32_t t = (m->threshhold_value);
	CYCLOPS_Matrix *B =
	  (CYCLOPS_Matrix *) ker_malloc (sizeof (CYCLOPS_Matrix),
					 MATRIX_ARITHMETICS_PID);
	if (NULL == B)
	  {
	    return -ENOMEM;
	  }
	if (threshold (A, B, t) != SOS_OK)
	  {
	    return -EINVAL;
	  }
	//PUT_PORT();
	//post_long             
	break;
      }
    default:
      return -EINVAL;
    }

  return SOS_OK;
}
Example #25
0
Vector<TBLoc>
shortestPath(TBLoc start,
             TBLoc end,
             const Grid<double>& world,
             double costFn(const TBLoc& from, const TBLoc& to, const Grid<double>& world),
             double heuristicFn(const TBLoc& from, const TBLoc& to, const Grid<double>& world),
             AlgorithmType algorithm) {
    // modified by Marty to use an actual Graph object
    ensureWorldCache(world, costFn);
    cout << endl;

    Grid<double>* const pWorld = const_cast<Grid<double>*>(&world);
    BasicGraph* graph = WORLD_CACHE[pWorld];
    // graph->resetData();   // make the student worry about this

    s_world = pWorld;
    s_heuristicFunction = heuristicFn;

    // convert start/end from Loc to Vertex
    Vertex* startVertex = graph->getVertex(vertexName(start.row, start.col, world));
    Vertex* endVertex   = graph->getVertex(vertexName(end.row, end.col, world));
    if (startVertex == NULL) {
        error(string("Graph can not find start vertex with name \"") + vertexName(start.row, start.col, world) + "\"");
        for (Vertex* v : graph->getVertexSet()) {
            cout << v->name << " ";
        }
        cout << endl;
    }
    if (endVertex == NULL) {
        error(string("Graph can not find end vertex with name \"") + vertexName(start.row, start.col, world) + "\"");
        for (Vertex* v : graph->getVertexSet()) {
            cout << v->name << " ";
        }
        cout << endl;
    }

    cout << "Looking for a path from " << startVertex->name
         << " to " << endVertex->name << "." << endl;

    Vector<Vertex*> result;
    switch (algorithm) {
    case BFS:
        cout << "Executing breadth-first search algorithm ..." << endl;
        result = breadthFirstSearch(*graph, startVertex, endVertex);
        break;
    case DIJKSTRA:
        cout << "Executing Dijkstra's algorithm ..." << endl;
        result = dijkstrasAlgorithm(*graph, startVertex, endVertex);
        break;
    case A_STAR:
        cout << "Executing A* algorithm ..." << endl;
        result = aStar(*graph, startVertex, endVertex);
        break;
#ifdef BIDIRECTIONAL_SEARCH_ALGORITHM_ENABLED
    case BIDIRECTIONAL:
        cout << "Executing Bidirectional Search algorithm ..." << endl;
        extern Vector<Vertex*> bidirectionalSearch(BasicGraph& graph, Vertex* start, Vertex* end);
        result = bidirectionalSearch(*graph, startVertex, endVertex);
        break;
#endif // BIDIRECTIONAL_SEARCH_ALGORITHM_ENABLED
    case DFS:
    default:
        cout << "Executing depth-first search algorithm ..." << endl;
        result = depthFirstSearch(*graph, startVertex, endVertex);
        break;
    }

    cout << "Algorithm complete." << endl;

    // convert Vector<Vertex*> to Vector<Loc>
    Vector<TBLoc> locResult;
    for (Vertex* v : result) {
        locResult.add(TBLoc(getRow(v), getCol(v)));
    }
    return locResult;
}
Example #26
0
list* doMovement(int mode, int dt) {
  int i;
  float fs;
  Data *data;
  list *l = NULL;
  GameEvent *e;

  for(i = 0; i < game->players; i++) {
    data = game->player[i].data;
    if(data->speed > 0) { /* still alive */

#define FREQ 1200
#define FACTOR 0.09
      fs = 1.0 - FACTOR + FACTOR * 
	cos(i * M_PI / 4.0 + 
	    (float)(game2->time.current % FREQ) * 2.0 * M_PI / (float)FREQ);
#undef FREQ
#undef FACTOR

      data->t += dt / 100.0 * data->speed * fs;
      while(data->t >= 1) {
	moveStep(data);
	data->t--;
	if(getCol(data->iposx, data->iposy) && mode) {
	  e = (GameEvent*) malloc(sizeof(GameEvent));
	  e->type = EVENT_CRASH;
	  e->player = i;
	  e->x = data->iposx;
	  e->y = data->iposy;
	  e->timestamp = game2->time.current;
	  addList(&l, e);
	  break;
	} else {
	  writePosition(i);
	}
      }
      data->posx = data->iposx + data->t * dirsX[data->dir];
      data->posy = data->iposy + data->t * dirsY[data->dir];
    } else { /* already crashed */
      if(game2->rules.eraseCrashed == 1 && data->trail_height > 0)
	data->trail_height -= (float)(dt * TRAIL_HEIGHT) / 1000;
      if(data->exp_radius < EXP_RADIUS_MAX)
	data->exp_radius += (float)dt * EXP_RADIUS_DELTA;
      else if (data->speed == SPEED_CRASHED) {
	int winner = -1;

	data->speed = SPEED_GONE;
	game->running--;
	if(game->running <= 1) { /* all dead, find survivor */
	  int i, maxSpeed = SPEED_GONE;
	  /* create winner event */
	  for(i = 0; i < game->players; i++) {
	    if(game->player[i].data->speed >= maxSpeed) {
	      winner = i;
	      maxSpeed = game->player[i].data->speed;
	    }
	  }
	  if(mode) {
	    e = (GameEvent*) malloc(sizeof(GameEvent));
	    e->type = EVENT_STOP;
	    e->player = winner;
	    e->timestamp = game2->time.current;
	    e->x = 0; e->y = 0;
	    addList(&l, e);
	    /* a stop event is the last event that happens */
	    return l;
	  }
	}
      }
    }      
  }
  return l;
}
Example #27
0
/**
 * Style needed
 */
void FbEditor::onStyleNeeded(wxStyledTextEvent & event)
{
    // startint position
    auto startPos  = GetEndStyled();
    auto startLine = LineFromPosition(startPos);
    startPos       = PositionFromLine(startLine);
    // end position
    int lastPos    = event.GetPosition();
    int lastLine   = std::max(LineFromPosition(lastPos), std::min(GetLineCount(), GetFirstVisibleLine() + LinesOnScreen()));
    lastPos        = GetLineEndPosition(lastLine);
        
    // get token
    auto token = m_srcCtx->getLine(startLine, lastLine);
    
    // set stylling position
    StartStyling(startPos, INT_MAX);
    
    // clear indicatirs
    SetIndicatorCurrent(ErrorIndicator);
    IndicatorClearRange(startPos, lastPos - startPos);
    
    // no token? just colour to default
    if (!token) {
        style(lastPos - startPos, TokenStyle::Default);
        return;
    }
    
    
    // style the tokens
    int line = startLine;
    int col  = 0;
    while (token && line <= lastLine) {
        // end of the line?
        if (token->getKind() == TokenKind::EndOfLine) {
            token = token->getNext();
            continue;
        }
        
        // token line
        int tline = token->getLine();
        
        // token started before current line
        if (line > tline) {
            int start = PositionFromLine(line);
            int end   = PositionFromLine(token->getEndLine()) + token->getEndCol();
            style(end - start, token);
            
            // end on line and column
            col  = token->getEndCol();
            line = token->getEndLine();
            
            // get next token and continue
            token = token->getNext();
            continue;
        }
        
        // empty lines before next token?
        if (line < tline) {
            int start = PositionFromLine(line) + col;
            int end   = PositionFromLine(tline) + token->getCol();
            style(end - start, TokenStyle::Default);
            
            // end on line and column
            line = token->getLine();
            col = token->getCol();
            continue;
        }
        
        // started on the current line
        if (line == tline) {
            // empty space ?
            if (token->getCol() > col) {
                style(token->getCol() - col, TokenStyle::Default);
            }
            
            // style the token
            style(token->getLength(), token);
            col = token->getEndCol();
            line = token->getEndLine();
            
            // advance to the next one
            token = token->getNext();
            continue;
        }
        
        // some empty space till end of the line
        int length = GetLineLength(line);
        if (col < length) {
            style(length - col, TokenStyle::Default);
        }
        
        // incement line
        line++;
        col = 0;
    }
}
Example #28
0
bool ColMajorCell::operator< (ColMajorCell const& cell) const
{
    return (getCol()*1024 + getRow()) < (cell.getCol()*1024 + cell.getRow());
}
Example #29
0
int MapMatrix::toIndex(int x, int y) const {
	return (y*getCol() + x);
}
Example #30
0
void graphMatching(int size1, float G1[size1][size1], int size2, float G2[size2][size2], float sigma, int numberOfMatches, float X[size1][size2], float Z[size1][size2], float Y[size1][size2]){

/*	Algorithm due to R. Zass and A. Shashua.,
 	'Probabilistic Graph and Hypergraph Matching.',
 	Computer Vision and Pattern Recognition (CVPR) Anchorage, Alaska, June 2008.

 	G1  				An size1 by size1 symmetric matrix, with the weight of the first graph edges.
 	G2  				An size2 by size2 symmetric matrix, with the weight of the second graph edges.
 	sigma 	 			Kernel parameter for edge-to-edge correlations.
 	numberOfMatches  	number of matches required. 

 	X [Output]  	a size1 by size2 matrix with the hard matching results.
             		The i,j entry is one iff the i-th feature of the first object
             		match the j-th feature of the second object. Zero otherwise.
 
	Z [Output]  	a size1 by size2 matrix with the soft matching results.
             		The i,j entry is the probablity that the i-th feature of the
             		first object match the j-th feature of the second object.
 
	Y [Output]  	Debug information.
*/


	//Check to make sure the matrices are symmetric	
	if(isSymmetric(size1, G1) == 0) {
		printf("G1 is not symmetric \n");
	}
	
	if(isSymmetric(size2, G2) == 0) {
		printf("G2 is not symmetric \n");
	}

	// tranpose G2
	float G2t[size2][size2];
	transpose(size2, size2, G2, G2t);
	
	// make Y an all zero matrix
	zeros(size1, size2, Y);
	float d[size1][size2], d1[size1][size2], d2[size1][size2], G1_i[size1][1], G2t_j[1][size2];

	for(int i=0; i < size1; i++) {
		for(int j=0; j < size2; j++) {
			//d = repmat(G1(:,i), 1, n2) - repmat(G2t(j, :), n1, 1);

			//...G1(:,i)...
			getCol(size1, size1, G1, G1_i, i);
			// ...G2t(j,:)...
			getRow(size2, size2, G2t, G2t_j, j);	
			//...repmat(G1(:,i), 1, n2)...
			repmat(size1, 1, G1_i, 1, size2, d1);
			//...repmat(G2t(j, :), n1, 1);
			repmat(1, size2, G2t_j, size1, 1, d2);

			// d = ... - ...
			matSub(size1, size2, d1, d2, d);

			//Y = Y + exp((-d.*d) ./ sigma);

			//exp((-d.*d) ./ sigma)
			for(int k=0; k < size1; k++) {
				for(int l=0; l < size2; l++) {
					d[k][l] = exp((-d[k][l] * d[k][l]) / sigma);
				}
			}

			// Y = Y + ...
			for(int u=0; u < size1; u++) {
				for(int v=0; v < size2; v++) {
					Y[u][v] += d[u][v];
				}
			}
			
		}
	}

	/* do hypergraphMatching over Y */
	hypergraphMatching(size1, size2, Y, numberOfMatches, X, Z);

}