示例#1
0
void MainWindow::processImage()
{
    resetImageStack(true);
    if(!currentImageSteps->first())
        return;
    int whiteTol, blackTol;
    whiteTol = ui->whiteLumEdit->text().toInt();
    blackTol = ui->blackLumEdit->text().toInt();

    //Step 1 : Noise Reduction using Gaussian Blur
    //    advanceStep();

    //Step 2 : Edge Detection
    //NOTE: Loses a two-pixel border.
    advanceStep();
    EdgeDetector edge(currentImageSteps->at(*currentStep),this);
    edge.setThreshold(blackTol,whiteTol);
    edge.processImage();

    //Fill 2px border with black
    for(int i = 0; i < currentImageSteps->at(*currentStep)->width(); i++) {
        currentImageSteps->at(*currentStep)->setPixel(i,0,0);
        currentImageSteps->at(*currentStep)->setPixel(i,1,0);
        currentImageSteps->at(*currentStep)->setPixel(i,currentImageSteps->at(*currentStep)->height()-2,0);
        currentImageSteps->at(*currentStep)->setPixel(i,currentImageSteps->at(*currentStep)->height()-1,0);
    }
    for(int i = 0; i < currentImageSteps->at(*currentStep)->height(); i++) {
        currentImageSteps->at(*currentStep)->setPixel(0,i,0);
        currentImageSteps->at(*currentStep)->setPixel(1,i,0);
        currentImageSteps->at(*currentStep)->setPixel(currentImageSteps->at(*currentStep)->width()-2,i,0);
        currentImageSteps->at(*currentStep)->setPixel(currentImageSteps->at(*currentStep)->width()-1,i,0);
    }

    //Step 3 : Circle Detection
    advanceStep();
    GenePool gp(currentImageSteps->at(*currentStep));
    while((gp.averageFitness() / gp.fittest().fitness()) < 0.6 && gp.currentGeneration() < 50) {
        gp.advanceGeneration();
    }
    dbg(QString("On generation %1 best chromosome is: %2=%3. Ratio: %4")
        .arg(gp.currentGeneration())
        .arg(gp.fittest().toString())
        .arg(gp.fittest().fitness())
        .arg(gp.averageFitness() / gp.fittest().fitness()));
    gp.fittest().paintSelf();
    //Return
    currentImageLabel->setPixmap(QPixmap::fromImage(*currentImageSteps->at(*currentStep)));
    updatePageNumbers();
    ui->fitnessButton->setEnabled(true);
}
示例#2
0
static void
JoyCalAutomaton(void)
{
	static int axis;
	const int BUFSIZE = 1024;
	char buf[BUFSIZE];
	
    switch (CalState) {
		case 0:
			memcpy(axCenter, ax, sizeof(axCenter));
			advanceStep();
			break;
		case 1:
			axis = Cmd[CalState + OFFSET_CMD].ref.index;
			Cmd[CalState + OFFSET_CMD].min = ax[axis];
			Cmd[CalState + OFFSET_CMD].max = axCenter[axis];
			Cmd[CalState + OFFSET_CMD].pow = 1.0;
			snprintf(buf, BUFSIZE, "%.2g", ax[axis]);
			GfuiLabelSetText(scrHandle2, LabMinId[0], buf);
			advanceStep();
			break;
		case 2:
			axis = Cmd[CalState + OFFSET_CMD].ref.index;
			Cmd[CalState + OFFSET_CMD].min = axCenter[axis];
			Cmd[CalState + OFFSET_CMD].max = ax[axis];
			Cmd[CalState + OFFSET_CMD].pow = 1.0;
			snprintf(buf, BUFSIZE, "%.2g", ax[axis]);
			GfuiLabelSetText(scrHandle2, LabMaxId[0], buf);
			advanceStep();
			break;
		case 3:
		case 4:
		case 5:
			axis = Cmd[CalState + OFFSET_CMD].ref.index;
			Cmd[CalState + OFFSET_CMD].min = axCenter[axis];
			Cmd[CalState + OFFSET_CMD].max = ax[axis]*1.1;
			Cmd[CalState + OFFSET_CMD].pow = 1.2;
			snprintf(buf, BUFSIZE, "%.2g", axCenter[axis]);
			GfuiLabelSetText(scrHandle2, LabMinId[CalState - 2], buf);
			snprintf(buf, BUFSIZE, "%.2g", ax[axis]*1.1);
			GfuiLabelSetText(scrHandle2, LabMaxId[CalState - 2], buf);
			advanceStep();
			break;
    }
    GfuiLabelSetText(scrHandle2, InstId, Instructions[CalState]);
}
/*---------------------------------------------------------------------*//**
	フレーム処理実装
**//*---------------------------------------------------------------------*/
void MapEmp_10243_1002_HandoverItemToCollector::execImplement(ExecRes* res, const ExecCtx* ec, f32 frameBegun)
{
    enum Step
    {
        STEP_NULL,
        STEP_WAIT_BEGIN,
        STEP_SHOW_ITEM_LIST,
        STEP_WAIT_ITEM_SELECT,
    };

    switch(getStep())
    {
    case STEP_WAIT_BEGIN:		// 継続監視
        if(!getOwner()->checkBegunOtherMatter(this, true))
        {
            // 自身以外のイベントが起動していないならば次のステップへ
            advanceStep();
        }
        break;
    case STEP_SHOW_ITEM_LIST:
    {
        // 背景を消す
        SorSgm* sgm = Game::getGame()->getSceneGraph();
        sgm->showBg(false);

        // アイテムリストウインドウを開く
        ItemListWindow* wndItemList = Game::getGame()->getGui()->getItemListWindow();
        ASSERT(wndItemList != 0L);
        wndItemList->setCase(ItemListWindow::ILWCASE_SELECT, ItemListWindow::AF_STONE_ONLY);
        wndItemList->showWindow(true);
        wndItemList->setSelfClose();

        advanceStep();
    }
    break;
    case STEP_WAIT_ITEM_SELECT:
    {
        ItemListWindow* wndItemList = Game::getGame()->getGui()->getItemListWindow();
        ASSERT(wndItemList != 0L);
        if(wndItemList->isDone())	// 完了検知
        {
            // アイテムを選択した
            if(wndItemList->getResult()->getSelectedIndex() != -1)
            {
                // アイテムを渡す
                const Item* item = wndItemList->getSelectedItem();
                handoverItem(item);
            }
            // キャンセル
            else
            {
                // アイテムを渡す
                handoverItem(0L);
            }

            // アイテムリストウインドウを閉じる
            if(wndItemList->isShowWindow())
            {
                wndItemList->showWindow(false);
            }

            // 背景表示を戻す
            SorSgm* sgm = Game::getGame()->getSceneGraph();
            sgm->showBg(true);

            end();	// イベント終了
        }
    }
    break;
    }
}
示例#4
0
static void
JoyCalAutomaton(void)
{
    linked_item_t * item_in_list;
    linked_item_t * new_in_list;
    float last_max;

    switch (CalState) {
    case 0:
	/* Grab snapshot of 'NULL' position */
	memcpy(JoyAxisCenter, JoyAxis, sizeof(JoyAxisCenter));

	advanceStep();
	break;

    case 1:
	/* Start linked list with Null Position */
	AtobList = (linked_item_t*)malloc(sizeof(linked_item_t));
	AtobList->next = NULL;
	AtobList->command = -1;
	AtobList->value = JoyAxisCenter[AtobAxis];

	CalState = 2;

	/* fall through */
    case 2:
	/* Insert each ATOB into list */
	item_in_list = AtobList;

	new_in_list = (linked_item_t*)malloc(sizeof(linked_item_t));
	new_in_list->command = AtobCount;
	new_in_list->value = JoyAxis[AtobAxis];
		
	if (new_in_list->value < item_in_list->value) {
	    /* insert first position*/
	    new_in_list->next = item_in_list;
	    AtobList = new_in_list;
	} else {
	    /* walk list */
	    while (item_in_list->next != NULL) {
		if (new_in_list->value < item_in_list->next->value) {
		    /* insert after current */
		    new_in_list->next = item_in_list->next;
		    item_in_list->next = new_in_list;
		    break;
		}

		/* step to next item */
		item_in_list = item_in_list->next; 
	    }

	    if (item_in_list->next == NULL) {
		/* insert at end */
		new_in_list->next = NULL;
		item_in_list->next = new_in_list;
	    }
	}

	advanceStep();

	if (CalState == 3) {
	   /* Walk list to compute min/max thresholds */
	   last_max=-1.0;

	   while (AtobList != NULL) {
		item_in_list = AtobList;
		if (item_in_list->command != -1)
		   Cmd[item_in_list->command].min = last_max;

		/* Split difference between current and next */
		if (item_in_list->next != NULL)
		   last_max = (item_in_list->value + item_in_list->next->value)/2;
		else
		   last_max = 1.0;

		if (item_in_list->command != -1)
		    Cmd[item_in_list->command].max = last_max;

		AtobList = item_in_list->next; 
		free(item_in_list);
	    }

	    advanceStep();
	}

	break;
    }
    GfuiLabelSetText(ScrHandle, InstId, Instructions[CalState]);

    /* Change button appearance when done */
    if (CalState == 3) {
	GfuiEnable(ScrHandle, CancelBut, GFUI_DISABLE);
	if (DoneBut)
	   GfuiEnable(ScrHandle, DoneBut, GFUI_ENABLE);
	else
	   GfuiEnable(ScrHandle, NextBut, GFUI_ENABLE);
    }
}
示例#5
0
void DriverBase<Scalar>::advanceFrame(unsigned int frame)
{
    std::cout<<"Begin Frame "<<frame<<"\n";
    //plugin onBeginFrame()
    unsigned int plugin_num = static_cast<unsigned int>(plugins_.size());
    DriverPluginBase<Scalar>* plugin;
    for(unsigned int i = 0; i < plugin_num; ++i)
    {
        plugin = plugins_[i];
        if(plugin != NULL)
            plugin->onBeginFrame(frame);
    }
    //timer start frame
    if(enable_timer_) timer_.startTimer();
    //frame content
    Scalar frame_dt=1.0/frame_rate_;
    Scalar finish_time=time_+frame_dt;
    bool frame_done=false;
    while(!frame_done)
    {
        //compute time step
        dt_=computeTimeStep();
        dt_=(dt_>max_dt_)?max_dt_:dt_;
        //adjust time step if it's the last step of frame
        if(finish_time-time_<=dt_)
        {
            dt_=finish_time-time_;
            frame_done=true;
        }
        //advance step
        advanceStep(dt_);
    }
    std::cout<<"End Frame "<<frame<<" ";
    //timer end frame
    if(enable_timer_)
    {
        timer_.stopTimer();
        Scalar time_cur_frame = timer_.getElapsedTime();
        total_simulation_time_ += time_cur_frame;
        std::cout<<time_cur_frame<<" s";
    }
    std::cout<<"\n";
    //end simulation
    if(frame == end_frame_)
    {
        std::cout<<"Simulation Ended.\n";
        if(enable_timer_)
            std::cout<<"Total simulation time: "<<total_simulation_time_<<" s; Average: "<<total_simulation_time_/(end_frame_-start_frame_)<<" s/frame.\n";
    }
    //write to file
    if(write_to_file_)
    {
        std::stringstream adaptor;
        adaptor<<frame;
        std::string frame_str;
        adaptor>>frame_str;
        std::string file_name=std::string("Frame ")+frame_str;
        write(file_name.c_str());
    }
    //plugin
    for(unsigned int i = 0; i < plugin_num; ++i)
    {
        plugin = plugins_[i];
        if(plugin != NULL)
            plugin->onEndFrame(frame);
    }
}
示例#6
0
static void
JoyCalAutomaton(void)
{
    static char buf[64];

    int axis;

    switch (CalState) {
    case 0:
#if SDL_JOYSTICK
   memcpy(&joyCenter, &joyInfo, sizeof(joyCenter));
#else
	memcpy(JoyAxisCenter, JoyAxis, sizeof(JoyAxisCenter));
#endif
	advanceStep();
	break;
    case 1:
	axis = Cmd[CalState + CmdOffset].ref.index;
#if SDL_JOYSTICK
   Cmd[CalState + CmdOffset].min = joyCenter.ax[axis];
   Cmd[CalState + CmdOffset].max = joyInfo.ax[axis];
#else
   Cmd[CalState + CmdOffset].min = JoyAxisCenter[axis];
   Cmd[CalState + CmdOffset].max = JoyAxis[axis];
#endif

	// record the polarity of the turn action
	if (Cmd[CalState + CmdOffset].max >= Cmd[CalState + CmdOffset].min)
		Cmd[CalState + CmdOffset].pow = 1.0;
	else
		Cmd[CalState + CmdOffset].pow = -1.0;

#if SDL_JOYSTICK
   sprintf(buf, "%.2f", joyInfo.ax[axis]);
#else
	sprintf(buf, "%.2f", JoyAxis[axis]);
#endif
	GfuiLabelSetText(ScrHandle, LabMinId[0], buf);
	advanceStep();
	break;
    case 2:
	axis = Cmd[CalState + CmdOffset].ref.index;
#if SDL_JOYSTICK
   Cmd[CalState + CmdOffset].min = joyCenter.ax[axis];
   Cmd[CalState + CmdOffset].max = joyInfo.ax[axis];
#else
	Cmd[CalState + CmdOffset].min = JoyAxisCenter[axis];
	Cmd[CalState + CmdOffset].max = JoyAxis[axis];
#endif

	// record the polarity of the turn action
	if (Cmd[CalState + CmdOffset].max >= Cmd[CalState + CmdOffset].min)
		Cmd[CalState + CmdOffset].pow = 1.0;
	else
		Cmd[CalState + CmdOffset].pow = -1.0;
#if SDL_JOYSTICK
   sprintf(buf, "%.2f", joyInfo.ax[axis]);
#else
	sprintf(buf, "%.2f", JoyAxis[axis]);
#endif
	GfuiLabelSetText(ScrHandle, LabMaxId[0], buf);
	advanceStep();
	break;
    case 3:
    case 4:
    case 5:
	axis = Cmd[CalState + CmdOffset].ref.index;
#if SDL_JOYSTICK
   Cmd[CalState + CmdOffset].min = joyCenter.ax[axis];
   Cmd[CalState + CmdOffset].max = joyInfo.ax[axis];
#else
	Cmd[CalState + CmdOffset].min = JoyAxisCenter[axis];
	Cmd[CalState + CmdOffset].max = JoyAxis[axis];
#endif
	Cmd[CalState + CmdOffset].pow = 1.0;
#if SDL_JOYSTICK
   sprintf(buf, "%.2f", joyCenter.ax[axis]);
#else
	sprintf(buf, "%.2f", JoyAxisCenter[axis]);
#endif
	GfuiLabelSetText(ScrHandle, LabMinId[CalState - 2], buf);
#if SDL_JOYSTICK
   sprintf(buf, "%.2f", joyInfo.ax[axis]);
#else
	sprintf(buf, "%.2f", JoyAxis[axis]);
#endif
	GfuiLabelSetText(ScrHandle, LabMaxId[CalState - 2], buf);
	advanceStep();

	break;
    }
    GfuiLabelSetText(ScrHandle, InstId, Instructions[CalState]);

    /* Change button appearance when done */
    if (CalState == NbCalSteps) {
	GfuiEnable(ScrHandle, CancelBut, GFUI_DISABLE);
	if (DoneBut)
	   GfuiEnable(ScrHandle, DoneBut, GFUI_ENABLE);
	else
	   GfuiEnable(ScrHandle, NextBut, GFUI_ENABLE);
    }
}
/*---------------------------------------------------------------------*//**
	フレーム処理実装
**//*---------------------------------------------------------------------*/
void MapEmp_10242_1701_RestAtHome::execImplement(ExecRes* res, const ExecCtx* ec, f32 frameBegun)
{
    enum Step
    {
        STEP_NULL,
        STEP_WAIT_BEGIN,
        STEP_CHECK_MOTEHR,
        STEP_TALK,
        STEP_WAIT_TALK,
        STEP_WAIT_YESNO,
        STEP_WAIT_FOUT,
        STEP_WAIT_FIN,
    };

    GameGui* gui = Game::getGame()->getGui();
    ASSERT(gui != 0L);
    SubtitlesWindow* wndSbt = gui->getSubtitlesWindow();
    ASSERT(wndSbt != 0L);
    GameSysMsgWindow* wndSysMsg = (GameSysMsgWindow*)gui->getSysMsgWindow();
    ASSERT(wndSysMsg != 0L);
    ScreenEffect* screff = Game::getGame()->getSceneScreenEffect();
    ASSERT(screff != 0L);

    switch(getStep())
    {
    case STEP_WAIT_BEGIN:		// 継続監視
        ///STRACE("!!! WAIT...\n");
        if(!getOwner()->checkBegunOtherMatter(this, true))
        {
            // 自身以外のイベントが起動していないならば次のステップへ
            advanceStep();
        }
        break;
    case STEP_CHECK_MOTEHR:
    {
        UnitManager* unitmng = Game::getGame()->getUnitManager();
        ASSERT(unitmng != 0L);
        // アサの母親在宅チェック
        Unit* unitYu = unitmng->findCharUnitFromCharId(CharIdDef::CHARID_NPC_MOTHER);
        _isShowMotherMsg = (unitYu != 0L);

        // 次のステップへ
        advanceStep();
    }
    break;
    case STEP_TALK:
    {
        if(_isShowMotherMsg)
        {
            // メッセージを得る
            EventData* evdat = getOwner()->getEventData();
            ASSERT(evdat != 0L);
            const MsgDataSet* msgdatset = evdat->getMsgDataSet();
            ASSERT(msgdatset != 0L);
            const MsgData::Msg* msg = msgdatset->findMessageFromMsgid(MSGID_TALK_MSG);
            const VcString strMsg = (msg != 0L) ? msgdatset->getString(msg) : "";
            // 会話メッセージウインドウを表示する
            wndSbt->setKind(SubtitlesWindow::KIND_TALK);
            wndSbt->showMessage(&strMsg, MSGWND_CTRL_HINT);

            // 次のステップへ
            advanceStep();
        }
        else
        {
            if(frameBegun > (1.0f * FRAMERATE))	// ちょっと待って
            {
                // 次のステップへ
                advanceStep();
            }
        }
    }
    break;
    case STEP_WAIT_TALK:
        if(wndSbt->isDone() || (!_isShowMotherMsg))
        {
            // ウインドウを閉じる
            wndSbt->showWindow(false);

            // メッセージを得る
            EventData* evdat = getOwner()->getEventData();
            ASSERT(evdat != 0L);
            const MsgDataSet* msgdatset = evdat->getMsgDataSet();
            ASSERT(msgdatset != 0L);
            const MsgData::Msg* msg = msgdatset->findMessageFromMsgid(MSGID_INQURE);
            const VcString strMsg = (msg != 0L) ? msgdatset->getString(msg) : "";
            // YES / NO メッセージウインドウを表示する
            wndSysMsg->setKind(MessageWindow::KIND_YESNO);
            wndSysMsg->showMessage(&strMsg, MSGWND_CTRL_HINT);

            // 次のステップへ
            advanceStep();
        }
        break;
    case STEP_WAIT_YESNO:
    {
        const GameSysMsgWindow::Result* res = wndSysMsg->getResult();
        if(res->isClickYesButton())
        {
            // ウインドウを閉じる
            wndSysMsg->showWindow(false);
            // フェードアウト
            ColorU8 col1(0, 0, 0, 255);
            screff->setColor1(&col1);
            screff->setMaxFrame(120);
            screff->start(ScreenEffect::MODE_FADE_OUT);
            // 次のステップへ
            advanceStep();
        }
        else if(res->isClickNoButton())
        {
            // ウインドウを閉じる
            wndSysMsg->showWindow(false);
            // 終了
            end();
        }
    }
    break;
    case STEP_WAIT_FOUT:
        if(!screff->isWorking())
        {
            // 家での休息処理
            restAtHome();
            StoryManager* strymng = Game::getGame()->getStoryManager();
            ASSERT(strymng != 0L);
            strymng->notifyRestAtHome();

            // PSNS にスコア送信
            ScoreBase* score = Game::getGame()->getScore();
            ASSERT(score != 0L);
            score->updatePsnsScore();

            // 休息時イベント起動(たいていは何も起動しない)
            EventSys* evsys = Game::getGame()->getEventSys();
            ASSERT(evsys != 0L);
            EvCause evcause(EventCause::CID_EVENT);
            ///evsys->beginCase(StDepEvDef::ECID_V01_MAP_REST_AT_HOME, 0, &evcause);
            evsys->begin(StDepEvDef::EVID_EP01_MAP_AFTER_REST_AT_HOME, 0, &evcause);

            // フェードインへ
            ColorU8 col1(0, 0, 0, 255);
            screff->setColor1(&col1);
            screff->setMaxFrame(60);
            screff->start(ScreenEffect::MODE_FADE_IN);
            // 次のステップへ
            advanceStep();
        }
        break;
    case STEP_WAIT_FIN:
        if(!screff->isWorking())
        {
            screff->end(0);
            end();
        }
        break;
    }
}
/*---------------------------------------------------------------------*//**
	フレーム処理実装
**//*---------------------------------------------------------------------*/
void QsEmp_ConfirmContract::execImplement(ExecRes* res, const ExecCtx* ec, f32 frameBegun)
{
	GameGui* gui = Game::getGame()->getGui(); ASSERT(gui != 0L);
	GameSysMsgWindow* wndSysMsg = (GameSysMsgWindow*)gui->getSysMsgWindow(); ASSERT(wndSysMsg != 0L);
	ScreenEffect* screff = Game::getGame()->getSceneScreenEffect(); ASSERT(screff != 0L);

	switch(getStep())
	{
	case STEP_WAIT_BEGIN:		// 継続監視
		///STRACE("!!! WAIT...\n");
		if(!getOwner()->checkBegunOtherMatter(this, true))	// 自身以外のイベントが起動していない
		{
			// メッセージを得る
			EventData* evdat = getOwner()->getEventData(); ASSERT(evdat != 0L);
			const MsgDataSet* msgdatset = evdat->getMsgDataSet(); ASSERT(msgdatset != 0L);
			// YES / NO メッセージウインドウを表示する
			wndSysMsg->setKind(MessageWindow::KIND_YESNO);
			wndSysMsg->showMessage(GameFixedStrTbl::getString(GameFixedStrTbl::SID_QUEST_CONFIRM_CONTRACT), MSGWND_CTRL_HINT);

			// 次のステップへ
			advanceStep();
		}
		break;
	case STEP_WAIT_YESNO:
		{
			const GameSysMsgWindow::Result* res = wndSysMsg->getResult();
			if(res->isClickYesButton())
			{
				// ウインドウを閉じる
				wndSysMsg->showWindow(false);

				// スプライトを読み込む
				_sprite->create(FILEID_CONV_LANG(QUESTEVENT_SPRITE_QUESTACCEPT_EN_PNG), 0, true, 0x000000ff, true);

				// SE 再生
				Game::getGame()->getSoundManager()->playUiSe(GameSoundDef::SE_QUEST_ADV, false);

				// 次のステップへ
				advanceStep();
			}
			else if(res->isClickNoButton())
			{
				// ウインドウを閉じる
				wndSysMsg->showWindow(false);

				// 終了
				end();

				// 親マターも終了してイベントを閉じる
				EventData* evdat = getOwner()->getEventData(); ASSERT(evdat != 0L);
				EvMatter* matter = evdat->getMatterFromEvid(getParentEvId());
				if(matter != 0L) { matter->end(); }
			}
		}
		break;
	case STEP_WAIT_EFFECT:
		if(_sprite->isEnd())
		{
			// フェードアウト
			ColorU8 colBlack(0, 0, 0, 255);
			screff->setColor1(&colBlack);
			screff->setMaxFrame(60);
			screff->start(ScreenEffect::MODE_FADE_OUT);

			// 次のステップへ
			advanceStep();
		}
		_sprite->exec(ec);
		break;
	case STEP_WAIT_FOUT:
		if(!screff->isWorking())
		{
			// クエスト受託
			contractQuest();

			// フェードインへ
			ColorU8 colBlack(0, 0, 0, 255);
			screff->setColor1(&colBlack);
			screff->setMaxFrame(30);
			screff->start(ScreenEffect::MODE_FADE_IN);
			// 次のステップへ
			advanceStep();
		}
		break;
	case STEP_WAIT_FIN:
		if(!screff->isWorking())
		{
			screff->end(0);
			end();
		}
		break;
	}
}