void QgsMapToPixel::updateMatrix() { double rotation = mapRotation(); #if 0 // debugging QgsDebugMsg( QString( "XXX %7 -- xCent:%1 yCent:%2 mWidth:%3 mHeight:%4 uPP:%5 rot:%6" ) .arg( xCenter ).arg( yCenter ).arg( mWidth ).arg( mHeight ) .arg( mMapUnitsPerPixel ).arg( rotation ).arg(( quintptr )this, QT_POINTER_SIZE *2, 15, QChar( '0' ) ) ); #endif // NOTE: operations are done in the reverse order in which // they are configured, so translation to geographical // center happens first, then scaling, then rotation // and finally translation to output viewport center if ( qgsDoubleNear( rotation, 0.0 ) ) { //no rotation, return a simplified matrix mMatrix = QTransform::fromScale( 1.0 / mMapUnitsPerPixel, -1.0 / mMapUnitsPerPixel ) .translate( -xMin, - ( yMin + mHeight * mMapUnitsPerPixel ) ); return; } double cy = mapHeight() / 2.0; double cx = mapWidth() / 2.0; mMatrix = QTransform::fromTranslate( cx, cy ) .rotate( rotation ) .scale( 1 / mMapUnitsPerPixel, -1 / mMapUnitsPerPixel ) .translate( -xCenter, -yCenter ) ; }
QTransform QgsMapToPixel::transform() const { // NOTE: operations are done in the reverse order in which // they are configured, so translation to geographical // center happens first, then scaling, then rotation // and finally translation to output viewport center double rotation = mapRotation(); if ( qgsDoubleNear( rotation, 0.0 ) ) { //no rotation, return a simplified matrix return QTransform::fromScale( 1.0 / mMapUnitsPerPixel, -1.0 / mMapUnitsPerPixel ) .translate( -xMin, - ( yMin + mHeight * mMapUnitsPerPixel ) ); } else { double cy = mapHeight() / 2.0; double cx = mapWidth() / 2.0; return QTransform::fromTranslate( cx, cy ) .rotate( rotation ) .scale( 1 / mMapUnitsPerPixel, -1 / mMapUnitsPerPixel ) .translate( -xCenter, -yCenter ); } }
ToolsMenu::ToolsMenu(ImageViewer* iv, QWidget* parent) : QWidget(parent), ui(new Ui::ToolsMenu) { ui->setupUi(this); setLayout(ui->verticalLayoutWidget->layout()); m_viewer = (ImageViewer*) iv; m_tools = new Tools(m_viewer, this); // locking tools menu when performing transformation connect(m_viewer, SIGNAL(lockTools()), this, SLOT(disableAllTools())); connect(m_viewer, SIGNAL(unlockTools()), this, SLOT(enableAllTools())); /* ------------------------------------------------------- * ROTATION * ------------------------------------------------------- */ connect(ui->rotate90Button, SIGNAL(clicked()), m_tools, SLOT(rotate90())); connect(ui->rotate180Button, SIGNAL(clicked()), m_tools, SLOT(rotate180())); connect(ui->rotate270Button, SIGNAL(clicked()), m_tools, SLOT(rotate270())); /* ------------------------------------------------------- * HISTOGRAM * ------------------------------------------------------- */ QMenu* hMenu = new QMenu(ui->histogramButton); hMenu->addAction( QIcon(":/icons/icons/chart_curve_error.png"), QString("Equalize histograms"), m_tools, SLOT(histogramEqualize()) ); hMenu->addAction( QIcon(":/icons/icons/chart_curve_go.png"), QString("Stretch histograms"), m_tools, SLOT(histogramStretch()) ); ui->histogramButton->setMenu(hMenu); /* ------------------------------------------------------- * FILTERS (convolution, blur) * ------------------------------------------------------- */ QMenu* bMenu = new QMenu(ui->blurButton); bMenu->addAction( QIcon(":/icons/icons/draw_convolve.png"), QString("Gaussian blur"), m_tools, SLOT(blurGauss()) ); bMenu->addAction( QIcon(":/icons/icons/draw_convolve.png"), QString("Uniform blur"), m_tools, SLOT(blurUniform()) ); bMenu->addAction( QIcon(":/icons/icons/flag_airfield_vehicle_safety.png"), QString("Custom linear filter"), m_tools, SLOT(blurLinear()) ); ui->blurButton->setMenu(bMenu); /* ------------------------------------------------------- * BINARIZATION * ------------------------------------------------------- */ QMenu* binMenu = new QMenu(ui->binarizationButton); binMenu->addAction( QIcon(":/icons/icons/universal_binary.png"), QString("Manual"), m_tools, SLOT(binManual()) ); binMenu->addAction( QIcon(":/icons/icons/universal_binary.png"), QString("Gradient"), m_tools, SLOT(binGradient()) ); binMenu->addAction( QIcon(":/icons/icons/universal_binary.png"), QString("Iterative bimodal"), m_tools, SLOT(binIterBimodal()) ); binMenu->addAction( QIcon(":/icons/icons/universal_binary.png"), QString("Niblack"), m_tools, SLOT(binNiblack()) ); binMenu->addAction( QIcon(":/icons/icons/universal_binary.png"), QString("Otsu"), m_tools, SLOT(binOtsu()) ); ui->binarizationButton->setMenu(binMenu); /* ------------------------------------------------------- * NOISE REDUCTION * ------------------------------------------------------- */ QMenu* nMenu = new QMenu(ui->noiseButton); nMenu->addAction( QIcon(":/icons/icons/checkerboard.png"), QString("Median"), m_tools, SLOT(noiseMedian()) ); nMenu->addAction( QIcon(":/icons/icons/checkerboard.png"), QString("Bilateral"), m_tools, SLOT(noiseBilateral()) ); ui->noiseButton->setMenu(nMenu); /* ------------------------------------------------------- * MORPHOLOGICAL * ------------------------------------------------------- */ QMenu* morphMenu = new QMenu(ui->morphButton); morphMenu->addAction( QIcon(":/icons/icons/arrow_out.png"), QString("Dilate"), m_tools, SLOT(morphDilate()) ); morphMenu->addAction( QIcon(":/icons/icons/arrow_in.png"), QString("Erode"), m_tools, SLOT(morphErode()) ); morphMenu->addAction( QIcon(":/icons/icons/arrow_divide.png"), QString("Open"), m_tools, SLOT(morphOpen()) ); morphMenu->addAction( QIcon(":/icons/icons/arrow_join.png"), QString("Close"), m_tools, SLOT(morphClose()) ); ui->morphButton->setMenu(morphMenu); /* ------------------------------------------------------- * EDGE DETECTION * ------------------------------------------------------- */ QMenu* eMenu = new QMenu(ui->edgeButton); eMenu->addAction( QIcon(":/icons/icons/key_s.png"), QString("Sobel"), m_tools, SLOT(edgeSobel()) ); eMenu->addAction( QIcon(":/icons/icons/key_p.png"), QString("Prewitt"), m_tools, SLOT(edgePrewitt()) ); eMenu->addAction( QIcon(":/icons/icons/key_r.png"), QString("Roberts"), m_tools, SLOT(edgeRoberts()) ); eMenu->addAction( QIcon(":/icons/icons/edge_detection.png"), QString("Laplacian"), m_tools, SLOT(edgeLaplacian()) ); eMenu->addAction( QIcon(":/icons/icons/edge_detection.png"), QString("Zero-crossing (LoG)"), m_tools, SLOT(edgeZero()) ); eMenu->addAction( QIcon(":/icons/icons/edge_detection.png"), QString("Canny"), m_tools, SLOT(edgeCanny()) ); ui->edgeButton->setMenu(eMenu); /* ------------------------------------------------------- * TEXTURES * ------------------------------------------------------- */ QMenu* texMenu = new QMenu(ui->textureButton); texMenu->addAction( QIcon(":/icons/icons/flag_airfield_vehicle_safety.png"), QString("Height map"), m_tools, SLOT(mapHeight()) ); texMenu->addAction( QIcon(":/icons/icons/flag_airfield_vehicle_safety.png"), QString("Normal map"), m_tools, SLOT(mapNormal()) ); texMenu->addAction( QIcon(":/icons/icons/flag_airfield_vehicle_safety.png"), QString("Horizon map"), m_tools, SLOT(mapHorizon()) ); ui->textureButton->setMenu(texMenu); /* ------------------------------------------------------- * TRANSFORMATIONS * ------------------------------------------------------- */ QMenu* transMenu = new QMenu(ui->transformationsButton); transMenu->addAction( QIcon(":/icons/icons/videodisplay.png"), QString("Hough"), m_tools, SLOT(houghTransform()) ); transMenu->addAction( QIcon(":/icons/icons/videodisplay.png"), QString("Hough - lines"), m_tools, SLOT(houghLines()) ); transMenu->addAction( QIcon(":/icons/icons/videodisplay.png"), QString("Hough - rectangles"), m_tools, SLOT(houghRectangles()) ); transMenu->addAction( QIcon(":/icons/icons/videodisplay.png"), QString("Segmentation"), m_tools, SLOT(segmentation()) ); ui->transformationsButton->setMenu(transMenu); /* ------------------------------------------------------- * CORNER DETECTION * ------------------------------------------------------- */ QMenu* cornerMenu = new QMenu(ui->cornerButton); cornerMenu->addAction( QIcon(":/icons/icons/things_digital.png"), QString("Harris"), m_tools, SLOT(cornerHarris()) ); ui->cornerButton->setMenu(cornerMenu); }
//This function is called each time it is your turn. //Return true to end your turn, return false to ask the server for updated information. bool AI::run() { Fish* coolFish = getFish(0, 0, fishes); if(coolFish != NULL) { coolFish->carryingWeight(); } for(int i = 0;i < tiles.size();i++) { if(tiles[i].owner() == playerID() && getFish(tiles[i].x(), tiles[i].y(), fishes) == NULL) { for(int p = 0;p<species.size(); p++) { if(species[p].season() == currentSeason()) { if(players[playerID()].spawnFood() >= species[p].cost() && tiles[i].hasEgg() == false) { species[p].spawn(tiles[i].x(), tiles[i].y()); } } } } } for(int i = 0;i < fishes.size();i++) { if(fishes[i].owner() == playerID()) { int x = fishes[i].x(); int y = fishes[i].y(); if(fishes[i].x() >= 1) { if(getTile(x - 1, y, mapHeight(), tiles).trashAmount() > 0 && fishes[i].carryingWeight() + 1 <= fishes[i].carryCap()) { fishes[i].pickUp(x - 1, y, 1); } } if(fishes[i].carryingWeight() > 0) { if(fishes[i].x() < mapWidth()/2 - boundLength() - 1) { if(fishes[i].y() != 0) { if(getTile(x,y - 1,mapHeight(),tiles).owner() == 2 && getFish(x,y + 1,fishes) == NULL) { fishes[i].drop(x, y - 1, fishes[i].carryingWeight()); } } else { if(getTile(x,y + 1,mapHeight(),tiles).owner() == 2 && getFish(x,y + 1,fishes) == NULL) { fishes[i].drop(x, y + 1, fishes[i].carryingWeight()); } } } } if(fishes[i].x() >= 1) { if(getTile(x - 1,y,mapHeight(),tiles).owner() != enemyAI_ID && getTile(x - 1,y,mapHeight(),tiles).trashAmount() == 0) { if(getFish(x - 1, y, fishes) == NULL && getTile(x - 1, y, mapHeight(), tiles).hasEgg() == false) { fishes[i].move(x - 1,y); } } } } } return true; }
//This function is called each time it is your turn. //Return true to end your turn, return false to ask the server for updated information. bool AI::run() { //loop through all of the tiles for(int i = 0;i < tiles.size();i++) { //if this tile is one of my coves and does not have a fish on it if(tiles[i].owner() == playerID() && getFishIndex(tiles[i].x(), tiles[i].y()) == -1) { if(getSpecies(SEA_STAR).spawn(tiles[i].x(),tiles[i].y())) std::cout<<"I am fish"<<std::endl; /* //loop through all of the species for(int p = 0;p<species.size(); p++) { //if the current species is in season if(species[p].season() == currentSeason()) { //if I have enough food to spawn the fish in and there is not //an egg on that tile already if(players[playerID()].spawnFood() >= species[p].cost() && tiles[i].hasEgg() == false) { //spawn the fish on that tile species[p].spawn(tiles[i].x(), tiles[i].y()); } } }*/ } } //loop through all of the fish for(int i = 0;i < fishes.size();i++) { //if this is my fish if(fishes[i].owner() == playerID()) { int x = fishes[i].x(); int y = fishes[i].y(); if(fishes[i].x() >= 1) { //if the tile to the left has trash and the current fish can //carry at least one more trash if(getTile(x - 1, y).trashAmount() > 0 && fishes[i].carryingWeight() + 1 <= fishes[i].carryCap()) { //if the fish has enought health to pick up trash if(1 * trashDamage() < fishes[i].currentHealth()) { //pick up trash to the left of the fish fishes[i].pickUp(x - 1, y, 1); } } } //if the fish carrying any trash if(fishes[i].carryingWeight() > 0) { //if the fish in the enemy's side if((fishes[i].x() < mapWidth()/2 - boundLength() - 1 && enemyAI_ID == 0) || (fishes[i].x() > mapWidth()/2 + boundLength() + 1 && enemyAI_ID == 1)) { if(fishes[i].y() != 0) { //if the tile above the fish is not a cove and has no fish if(getTile(x, y - 1).owner() == 2 && getFishIndex(x, y + 1) == -1) { //drop all of the trash the fish is carrying fishes[i].drop(x, y - 1, fishes[i].carryingWeight()); } } else if(fishes[i].y() != mapHeight() - 1) { //if the tile below the fish is not a cove and has no fish if(getTile(x,y + 1).owner() == 2 && getFishIndex(x,y + 1) == -1) { //drop all of the trash the fish is carrying fishes[i].drop(x, y + 1, fishes[i].carryingWeight()); } } } } if(fishes[i].x() >= 1) { //if the tile to the left is not an enemy cove and there is no trash if(getTile(x - 1,y).owner() != enemyAI_ID && getTile(x - 1,y).trashAmount() == 0) { //if the tile to the left does not have a fish and does not have an //egg if(getFishIndex(x - 1, y) == -1 && getTile(x - 1, y).hasEgg() == false) { //move to the left fishes[i].move(x - 1, y); } } //get the fish to the left int target = getFishIndex(x - 1, y); //if there is a fish to the left and the fish has attacks left if(target != -1 && fishes[i].attacksLeft() > 0) { //if the fish is not a cleaner shrimp if(fishes[i].species() != CLEANER_SHRIMP) { //if the fish to the left is an enemy fish if(fishes[target].owner() == enemyAI_ID) { //attack the fish fishes[i].attack(fishes[target]); } } else { //this is if the fish is a cleaner shrimp //if the fish to the left is a friendly fish if(fishes[target].owner() != enemyAI_ID) { //heal the fish fishes[i].attack(fishes[target]); } } } } } } return true; }