コード例 #1
0
ファイル: comb.cpp プロジェクト: Amusesmile/Gamma
void audioCB(AudioIOData& io){

	while(io()){
		
		if(tmr()){
			switch(feedType){
			case 0:	printf("Low-pass feedforward\n");
				comb.feeds( 1,0); break;
			case 1:	printf("High-pass feedforward\n");
				comb.feeds(-1,0); break;
			case 2:	printf("Low-pass feedback\n");
				comb.feeds(0,0.7); break;
			case 3:	printf("High-pass feedback\n");
				comb.feeds(0,-0.7); break;
			case 4:	printf("Low-pass dual-feed\n");
				comb.feeds(0.7,0.7); break;
			case 5:	printf("High-pass dual-feed\n");
				comb.feeds(-0.7,-0.7); break;
			case 6:	printf("All-pass 1\n");
				comb.feeds(0.9,-0.9); break;
			case 7:	printf("All-pass 2\n");
				comb.feeds(-0.9,0.9); break;
			}
			(++feedType) %= 8;
		}
		
		float s = src()*0.4;
		
		comb.ipolType(ipl::ROUND);
		comb.delay(mod.triU() * 1./400 + 1./10000);
		s = comb(s);

		io.out(0) = io.out(1) = s;
	}
}
コード例 #2
0
ファイル: test_actor.hpp プロジェクト: BianJian/mmo
  static void my_actor(stackful_actor self, aid_t base_id)
  {
    std::size_t size = 50;
    std::vector<resp_t> res_list(size);
    for (std::size_t i=0; i<size; ++i)
    {
      aid_t aid =
        spawn(
          self,
          boost::bind(&actor_ut::my_child, _arg1)
          );
      res_list[i] = self->request(aid);
    }

    timer_t tmr(self.get_context().get_io_service());
    yield_t yield = self.get_yield();
    tmr.expires_from_now(boost::chrono::milliseconds(1));
    tmr.async_wait(yield);

    for (std::size_t i=0; i<size; ++i)
    {
      aid_t aid;
      message msg;
      do
      {
        aid = self.respond(res_list[i], msg, seconds(1));
      }
      while (aid == aid_nil);
    }

    tmr.expires_from_now(boost::chrono::milliseconds(1));
    tmr.async_wait(yield);

    self->send(base_id);
  }
コード例 #3
0
ファイル: Timer.cpp プロジェクト: GDXN/CoActionOS-Public
bool Timer::isexpired(void){
	Tmr tmr(port);
	if( tmr.get() > timeout_stop_ ){
		return true;
	}
	return false;
}
コード例 #4
0
ファイル: Timer.cpp プロジェクト: GDXN/CoActionOS-Public
uint32_t Timer::value(void){
	Tmr tmr(port);
	if( (int)stop_ != -1 ){
		return start_ - stop_;
	} else {
		return tmr.get() - start_;
	}
}
コード例 #5
0
ファイル: main.cpp プロジェクト: avakar/gh
int main(int argc, char * argv[])
{
	try
	{
		cmdline args(cmdline_entries, std::end(cmdline_entries), argc - 1, argv + 1);

		bool profile = args.pop_switch(gh_opts::time);
		std::string cmd = args.pop_string(gh_opts::cmd);

		int profile_repeat = atoi(args.pop_string(gh_opts::profile).c_str());

		int r = 1;
		for (int i = 0; i < profile_repeat; ++i)
		{
			timer tmr(profile);
			cmdline subargs = args;

			if (cmd == "init")
			{
				r = gh_init(subargs);
			}
			else if (cmd == "test-checkout")
			{
				subargs.set_subparser(gh_subparser::test_checkout);

				gitdb db0;
				db0.open(subargs.pop_string(gh_opts::repo, "."));

				object_id head_oid = db0.get_ref(subargs.pop_string(gh_opts::ref));
				gitdb::commit_t cc = db0.get_commit(head_oid);
				checkout_tree(db0, subargs.pop_string(gh_opts::wd_dir), db0.get_tree(cc.tree_oid));
				r = 0;
			}
			else if (cmd == "st" || cmd == "status")
			{
				r = gh_status(subargs);
			}
		}

		return r;
	}
	catch (std::exception const & e)
	{
		std::cerr << "error: " << e.what() << "\n";
		return 1;
	}

	return 0;
}
コード例 #6
0
ファイル: test_coro.hpp プロジェクト: BianJian/mmo
  static void my_actor(stackful_actor self, aid_t base)
  {
    std::size_t loop_num = 10;
    yield_t yield = self.get_yield();
    timer_t tmr(self.get_context().get_io_service());

    for (std::size_t i=0; i<loop_num; ++i)
    {
      self->send(base, "echo");
      self->recv("echo");

      tmr.expires_from_now(boost::chrono::milliseconds(1));
      tmr.async_wait(yield);
    }
  }
コード例 #7
0
ファイル: test_coro.hpp プロジェクト: BianJian/gce1.0
  static void my_actor(self_t self, aid_t base)
  {
    std::size_t loop_num = 10;
    yield_t yield = self.get_yield();
    timer_t tmr(self.get_cache_pool()->get_context().get_io_service());

    for (std::size_t i=0; i<loop_num; ++i)
    {
      send(self, base, atom("echo"));
      recv(self, atom("echo"));

      tmr.expires_from_now(boost::chrono::milliseconds(1));
      tmr.async_wait(yield);
    }
  }
コード例 #8
0
ファイル: Timer.cpp プロジェクト: GDXN/CoActionOS-Public
void Timer::wait_usec(uint32_t timeout){
	Tmr tmr(port);
	tmr_reqattr_t chan_req;

	//enable the interrupt
	hwpl_tmr_off(port, 0);
	chan_req.channel =  TMR_ACTION_CHANNEL_OC0;
	chan_req.value = hwpl_tmr_get(port, 0) + timeout;
	hwpl_tmr_setoc(port, &chan_req);

	tmr_is_expired = false;
	hwpl_tmr_on(port, 0);
	while( !tmr_is_expired ){
		_hwpl_core_sleep(CORE_SLEEP);
	}
}
コード例 #9
0
ファイル: Timer.cpp プロジェクト: GDXN/CoActionOS-Public
int Timer::init(Tmr::port_t port){
	Timer::port = port;
	tmr_action_t action;
	Tmr tmr(port);
	if(  tmr.init(1000000) < 0 ){
		return -1;
	}
	tmr.on();

	//initialize the interrupts
	action.channel = TMR_ACTION_CHANNEL_OC0;
	action.context = 0;
	action.callback = tmr_priv_expired;
	action.event = TMR_ACTION_EVENT_INTERRUPT;
	hwpl_tmr_setaction(port, &action);

	return 0;
}
コード例 #10
0
ファイル: Wasabi.cpp プロジェクト: ngopee/Wasabi
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR cmdLine, int cmdShow) {
	WInitializeTimers();

	Wasabi* app = WInitialize();
	app->maxFPS = 60.0f;

	app->SoundComponent = new WSoundComponent();

#ifdef _WIN32
	app->WindowComponent = new WWC_Win32(app);
	app->InputComponent = new WIC_Win32(app);
#elif defined(__linux__)
	app->WindowComponent = new WWC_Linux(app);
	app->InputComponent = new WIC_Linux(app);
#endif

	if (app->Setup()) {
		WTimer tmr(W_TIMER_SECONDS);
		WTimer fpsChangeTmr(W_TIMER_SECONDS);
		fpsChangeTmr.Start();
		UINT numFrames = 0;
		float deltaTime = 0.0f;
		while (!app->__EXIT) {
			tmr.Reset();
			tmr.Start();

			if (!app->WindowComponent->Loop())
				continue;

			if (deltaTime) {
				if (!app->Loop(deltaTime))
					break;
				if (app->curState)
					app->curState->Update(deltaTime);
			}

			// TODO: render
			//while (app->core->Update(deltaTime) == HX_WINDOWMINIMIZED)
			//	hx->core->Loop();

			numFrames++;

			deltaTime = app->FPS < 0.0001 ? 1.0f / 60.0f : 1.0f / app->FPS;

			if (app->maxFPS > 0.001) {
				float maxDeltaTime = 1.0f / app->maxFPS; // delta time at max FPS
				if (deltaTime < maxDeltaTime) {
					WTimer sleepTimer(W_TIMER_SECONDS);
					sleepTimer.Start();
					while (sleepTimer.GetElapsedTime() < (maxDeltaTime - deltaTime));
					deltaTime = maxDeltaTime;
				}
			}

			if (fpsChangeTmr.GetElapsedTime() >= 0.5f) //0.5 second passed -> update FPS
			{
				app->FPS = (float)numFrames * 2.0f;
				numFrames = 0;
				fpsChangeTmr.Reset();
			}
		}

		app->Cleanup();
	}

	W_SAFE_DELETE(app);

	WUnInitializeTimers();

	return 0;
}
コード例 #11
0
//TODO: code here should be abstracted outside the app, modify tests accordingly
int main(int argc, char *argv[]) {

    // Chec the number of arguments
    if (argc != 2) {
        std::cout << "********************************" << std::endl;
        std::cout << "Usage of the code: ./traffic-sign-detection imageFileName.extension" << std::endl;
        std::cout << "********************************" << std::endl;

        return -1;
    }

    // Clock for measuring the elapsed time
    std::chrono::time_point<std::chrono::system_clock> start, end;
    start = std::chrono::system_clock::now();

    // Read the input image - convert char* to string
    std::string input_filename(argv[1]);

    // Read the input image
    cv::Mat input_image = cv::imread(input_filename);

    // Check that the image has been opened
    if (!input_image.data) {
        std::cout << "Error to read the image. Check ''cv::imread'' function of OpenCV" << std::endl;
        return -1;
    }
    // Check that the image read is a 3 channels image
    CV_Assert(input_image.channels() == 3);


    /*
   * Conversion of the image in some specific color space
   */

    // Conversion of the rgb image in ihls color space
    cv::Mat ihls_image;
    colorconversion::convert_rgb_to_ihls(input_image, ihls_image);
    // Conversion from RGB to logarithmic chromatic red and blue
    std::vector< cv::Mat > log_image;
    colorconversion::rgb_to_log_rb(input_image, log_image);

    /*
   * Segmentation of the image using the previous transformation
   */

    // Segmentation of the IHLS and more precisely of the normalised hue channel
    // ONE PARAMETER TO CONSIDER - COLOR OF THE TRAFFIC SIGN TO DETECT - RED VS BLUE
    int nhs_mode = 0; // nhs_mode == 0 -> red segmentation / nhs_mode == 1 -> blue segmentation
    cv::Mat nhs_image_seg_red;

    segmentation::seg_norm_hue(ihls_image, nhs_image_seg_red, nhs_mode);
    //nhs_mode = 1; // nhs_mode == 0 -> red segmentation / nhs_mode == 1 -> blue segmentation
    //cv::Mat nhs_image_seg_blue;
    cv::Mat nhs_image_seg_blue = nhs_image_seg_red.clone();
    //segmentation::seg_norm_hue(ihls_image, nhs_image_seg_blue, nhs_mode);
    // Segmentation of the log chromatic image
    // TODO - DEFINE THE THRESHOLD FOR THE BLUE TRAFFIC SIGN. FOR NOW WE AVOID THE PROCESSING FOR BLUE SIGN AND LET ONLY THE OTHER METHOD TO TAKE CARE OF IT.
    cv::Mat log_image_seg;
    segmentation::seg_log_chromatic(log_image, log_image_seg);

    /*
   * Merging and filtering of the previous segmentation
   */

    // Merge the results of previous segmentation using an OR operator
    // Pre-allocation of an image by cloning a previous image
    cv::Mat merge_image_seg_with_red = nhs_image_seg_red.clone();
    cv::Mat merge_image_seg = nhs_image_seg_blue.clone();
    cv::bitwise_or(nhs_image_seg_red, log_image_seg, merge_image_seg_with_red);
    cv::bitwise_or(nhs_image_seg_blue, merge_image_seg_with_red, merge_image_seg);

    // Filter the image using median filtering and morpho math
    cv::Mat bin_image;
    imageprocessing::filter_image(merge_image_seg, bin_image);


    cv::imwrite("seg.jpg", bin_image);

    /*
   * Extract candidates (i.e., contours) and remove inconsistent candidates
   */

    std::vector< std::vector< cv::Point > > distorted_contours;
    imageprocessing::contours_extraction(bin_image, distorted_contours);

    /*
   * Correct the distortion for each contour
   */

    // Initialisation of the variables which will be returned after the distortion. These variables are linked with the transformation applied to correct the distortion
    std::vector< cv::Mat > rotation_matrix(distorted_contours.size());
    std::vector< cv::Mat > scaling_matrix(distorted_contours.size());
    std::vector< cv::Mat > translation_matrix(distorted_contours.size());
    for (unsigned int contour_idx = 0; contour_idx < distorted_contours.size(); contour_idx++) {
        rotation_matrix[contour_idx] = cv::Mat::eye(3, 3, CV_32F);
        scaling_matrix[contour_idx] = cv::Mat::eye(3, 3, CV_32F);
        translation_matrix[contour_idx] = cv::Mat::eye(3, 3, CV_32F);
    }

    // Correct the distortion
    std::vector< std::vector< cv::Point2f > > undistorted_contours;
    imageprocessing::correction_distortion(distorted_contours, undistorted_contours, translation_matrix, rotation_matrix, scaling_matrix);

    // Normalise the contours to be inside a unit circle
    std::vector<double> factor_vector(undistorted_contours.size());
    std::vector< std::vector< cv::Point2f > > normalised_contours;
    initopt::normalise_all_contours(undistorted_contours, normalised_contours, factor_vector);

    std::vector< std::vector< cv::Point2f > > detected_signs_2f(normalised_contours.size());
    std::vector< std::vector< cv::Point > > detected_signs(normalised_contours.size());

    // For each contours
    for (unsigned int contour_idx = 0; contour_idx < normalised_contours.size(); contour_idx++) {

        Timer tmr("for each contours");
        // For each type of traffic sign
        /*
     * sign_type = 0 -> nb_edges = 3;  gielis_sym = 6; radius
     * sign_type = 1 -> nb_edges = 4;  gielis_sym = 4; radius
     * sign_type = 2 -> nb_edges = 12; gielis_sym = 4; radius
     * sign_type = 3 -> nb_edges = 8;  gielis_sym = 8; radius
     * sign_type = 4 -> nb_edges = 3;  gielis_sym = 6; radius / 2
     */

        Timer tmrSgnType("For signType");
        optimisation::ConfigStruct_<double> final_config;
        double best_fit = std::numeric_limits<double>::infinity();
        //int type_sign_to_keep = 0;
        for (int sign_type = 0; sign_type < 5; sign_type++) {
            Timer tmrIteration(" for_signType_iter");

            // Check the center mass for a contour
            cv::Point2f mass_center = initopt::mass_center_discovery(input_image, translation_matrix[contour_idx],
                                                                     rotation_matrix[contour_idx], scaling_matrix[contour_idx],
                                                                     normalised_contours[contour_idx], factor_vector[contour_idx],
                                                                     sign_type);

            // Find the rotation offset
            double rot_offset = initopt::rotation_offset(normalised_contours[contour_idx]);

            // Declaration of the parameters of the gielis with the default parameters
            optimisation::ConfigStruct_<double> contour_config;
            // Set the number of symmetry
            int gielis_symmetry = 0;
            switch (sign_type) {
            case 0:
                gielis_symmetry = 6;
                break;
            case 1:
                gielis_symmetry = 4;
                break;
            case 2:
                gielis_symmetry = 4;
                break;
            case 3:
                gielis_symmetry = 8;
                break;
            case 4:
                gielis_symmetry = 6;
                break;
            }
            contour_config.p = gielis_symmetry;
            // Set the rotation matrix
            contour_config.theta_offset = rot_offset;
            // Set the mass center
            contour_config.x_offset = mass_center.x;
            contour_config.y_offset = mass_center.y;

            Timer tmrOpt("\t for_signType_gielisOptimization");
            // Go for the optimisation
            Eigen::Vector4d mean_err(0,0,0,0), std_err(0,0,0,0);
            optimisation::gielis_optimisation(normalised_contours[contour_idx], contour_config, mean_err, std_err);

            mean_err = mean_err.cwiseAbs();
            double err_fit = mean_err.sum();

            if (err_fit < best_fit) {
                best_fit = err_fit;
                final_config = contour_config;
                //type_sign_to_keep = sign_type;
            }
        }

        Timer tmr2("Reconstruct contour");

        // Reconstruct the contour
        std::cout << "Contour #" << contour_idx << ":\n" << final_config << std::endl;
        std::vector< cv::Point2f > gielis_contour;
        int nb_points = 1000;
        optimisation::gielis_reconstruction(final_config, gielis_contour, nb_points);
        std::vector< cv::Point2f > denormalised_gielis_contour;
        initopt::denormalise_contour(gielis_contour, denormalised_gielis_contour, factor_vector[contour_idx]);
        std::vector< cv::Point2f > distorted_gielis_contour;
        imageprocessing::inverse_transformation_contour(denormalised_gielis_contour, distorted_gielis_contour,
                                                        translation_matrix[contour_idx], rotation_matrix[contour_idx],
                                                        scaling_matrix[contour_idx]);

        // Transform to cv::Point to show the results
        std::vector< cv::Point > distorted_gielis_contour_int(distorted_gielis_contour.size());
        for (unsigned int i = 0; i < distorted_gielis_contour.size(); i++) {
            distorted_gielis_contour_int[i].x = (int) std::round(distorted_gielis_contour[i].x);
            distorted_gielis_contour_int[i].y = (int) std::round(distorted_gielis_contour[i].y);
        }

        detected_signs_2f[contour_idx] = distorted_gielis_contour;
        detected_signs[contour_idx] = distorted_gielis_contour_int;

    }

    end = std::chrono::system_clock::now();
    std::chrono::duration<double> elapsed_seconds = end-start;
    std::time_t end_time = std::chrono::system_clock::to_time_t(end);

    std::cout << "Finished computation at " << std::ctime(&end_time)
              << "Elapsed time: " << elapsed_seconds.count()*1000 << " ms\n";


    cv::Mat output_image = input_image.clone();
    cv::Scalar color(0,255,0);
    cv::drawContours(output_image, detected_signs, -1, color, 2, 8);

    cv::namedWindow("Window", CV_WINDOW_AUTOSIZE);
    cv::imshow("Window", output_image);
    cv::waitKey(0);

    return 0;
}
コード例 #12
0
ファイル: test_actor.hpp プロジェクト: BianJian/mmo
 static void echo(yield_t yld, io_service_t& ios)
 {
   timer_t tmr(ios);
   tmr.expires_from_now(boost::chrono::seconds(30));
   tmr.async_wait(yld);
 }
コード例 #13
0
int _tmain(int argc, _TCHAR* argv[])
{

	GLFWwindow* window = 0;
	glfwSetErrorCallback(glfw_error_callback_func);


	// Initialise GLFW
	if (!glfwInit())
	{
		fprintf(stderr, "Failed to initialize GLFW\n");
		getchar();
		return -1;
	}

	//-----------------------------------------------------------------------------
	glfwWindowHint(GLFW_SAMPLES, 4);

	// GL3.3 Core profile
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
	//	glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

	glfwWindowHint(GLFW_VISIBLE, 0);	//オフスクリーン

	// Open a window and create its OpenGL context
	window = glfwCreateWindow(1, 1, "GPGPU Test", NULL, NULL);
	if (window == NULL){
		fprintf(stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n");
		getchar();
		glfwTerminate();
		return -1;
	}
	glfwMakeContextCurrent(window);

#if defined _WIN32
	// Initialize GLEW
	glewExperimental = GL_TRUE;			///!!!! important for core profile // コアプロファイルで必要となります
	if (glewInit() != GLEW_OK) {
		fprintf(stderr, "Failed to initialize GLEW\n");
		getchar();
		glfwTerminate();
		return -1;
	}
#endif


	{
		cout << "GL_VENDOR:" << glGetString(GL_VENDOR) << endl;
		cout << "GL_RENDERER:" << glGetString(GL_RENDERER) << endl;
		cout << "GL_VERSION:" << glGetString(GL_VERSION) << endl;
		cout << "GL_SHADING_LANGUAGE_VERSION:" << glGetString(GL_SHADING_LANGUAGE_VERSION) << endl;

	}

#ifdef _DEBUG
	Mat imgSrc = Mat(Size(8, 4), CV_32FC1);
#else
	Mat imgSrc = Mat(Size(1024, 1024), CV_32FC1);
#endif
	Mat imgDst = Mat::zeros(imgSrc.size(), imgSrc.type());
	Mat imgRef = Mat::zeros(imgSrc.size(), imgSrc.type());

	//世代
#ifdef _DEBUG
	const int generations = 1;
//	const int generations = 3;
#else
	const int generations = 1000;
#endif
	{
		cout << "Cell Size:" << imgSrc.size() << endl;
		cout << "generations:" << generations << endl;
	}

	//---------------------------------
	//init Src image
	initCellLife(imgSrc);



	//---------------------------------
	//Execute GPGPU
	{
		cout << "Execute GPGPU" << endl;

		const int width = imgSrc.cols;
		const int height = imgSrc.rows;


		// Create and compile our GLSL program from the shaders
		GLuint programID = LoadShaders("LifeGame.vertexshader", "LifeGameUpdate.fragmentshader");

		// texture

		enum E_TextureID{
			SRC,
			DST,
			SIZEOF,
		};

		unsigned int textureID[E_TextureID::SIZEOF];	//src dst
		//---------------------------------
		// CreateTexture
		{
			GLenum format = GL_RED;				//single channel
			GLenum type = GL_FLOAT;				//float
			GLenum internalFormat = GL_R32F;	//single channel float

			glGenTextures(sizeof(textureID) / sizeof(textureID[0]), textureID); // create (reference to) a new texture

			for (int i = 0; i < sizeof(textureID) / sizeof(textureID[0]); i++){
				glBindTexture(GL_TEXTURE_2D, textureID[i]);
				// (set texture parameters here)
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
//				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
//				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
#ifdef LIFE_BOUND_REPEAT					
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
#else
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
#endif
				
				//create the texture
				glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height, 0, format, type, 0);

				glBindTexture(GL_TEXTURE_2D, 0);
			}

		}

		//upload imgSrc to texture
		{
			//Timer tmr("upload:");

			GLenum format = GL_RED;				//single channel
			GLenum type = GL_FLOAT;				//float
			void* data = imgSrc.data;

			glBindTexture(GL_TEXTURE_2D, textureID[E_TextureID::SRC]);
			glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, type, data);
			glBindTexture(GL_TEXTURE_2D, 0);
		}

		// FBO identifier
		GLuint fbo = 0;

		//---------------------------------
		// FBO
		// create FBO (off-screen framebuffer)
		glGenFramebuffers(1, &fbo);

		// bind offscreen framebuffer (that is, skip the window-specific render target)
		//		glBindFramebuffer(GL_FRAMEBUFFER, fbo);


		//Execute
		{
			Timer tmr("LifeGame@gpu:");
			for (int i = 0; i < generations; i++){
				GLuint texSrc = textureID[(i % 2)];
				GLuint texDst = textureID[(i % 2) ^ 1];
				executeGpGpuProcess(programID, fbo, texSrc, texDst);
			}
		}

		{	//download from framebuffer
			//Timer tmr("download:");


			GLenum format = GL_RED;				//single channel
			GLenum type = GL_FLOAT;				//float
			void* data = imgDst.data;
			int width = imgDst.cols;
			int height = imgDst.rows;


			//wait for Rendering
			glFinish();


			// ReadBuffer
			glReadBuffer(GL_COLOR_ATTACHMENT0);

			// ReadPixels
			glReadPixels(0, 0, width, height, format, type, data);


		}

		//clean up
		glDeleteTextures(sizeof(textureID) / sizeof(textureID[0]), textureID);
		glDeleteFramebuffers(1, &fbo);

		glDeleteProgram(programID);
	}

	//---------------------------------
	//Execute CPU
	{
		cout << "Execute CPU" << endl;

		Mat imgBank[2] = { Mat::zeros(imgSrc.size(), imgSrc.type()), Mat::zeros(imgSrc.size(), imgSrc.type()) };
		int bank = 0;
		imgBank[bank] = imgSrc.clone();
		{
			Timer tmr("LifeGame@cpu:");
			for (int i = 0; i < generations; i++){
				updateCellLife(imgBank[bank], imgBank[bank ^ 1]);
				bank = bank ^ 1;
			}
		}
		imgRef = imgBank[bank].clone();

	}


#ifdef _DEBUG
	//dump 
	{
		cout << "imgSrc" << endl;
		cout << imgSrc << endl;

		cout << "imgDst" << endl;
		cout << imgDst << endl;

		cout << "imgRef" << endl;
		cout << imgRef << endl;
	}
#endif

	//verify
	int errNum = 0;
	{
		//verify
		int width = imgSrc.cols;
		int height = imgSrc.rows;
		for (int y = 0; y < height; y++){
			for (int x = 0; x < width; x++){
				float ref = imgRef.at<float>(y, x);
				float dst = imgDst.at<float>(y, x);
				if (ref != dst) errNum++;
			}
		}
		cout << "ErrNum:" << errNum << endl;
	}

#if 0
	//visualize
	{
		imshow("src", imgSrc);
		imshow("dst", imgDst);
		imshow("ref", imgRef);

		waitKey();
	}
#endif

	// Close OpenGL window and terminate GLFW
	glfwTerminate();

	cout << "Hit return key" << endl;
	cin.get();


	return errNum;
}
コード例 #14
0
ファイル: Timer.cpp プロジェクト: GDXN/CoActionOS-Public
void Timer::settimeout(uint32_t timeout){
	Tmr tmr(port);
	timeout_stop_ = tmr.get() + timeout;
}
コード例 #15
0
ファイル: Timer.cpp プロジェクト: GDXN/CoActionOS-Public
void Timer::stop(void){
	Tmr tmr(port);
	if( (int)stop_ == -1 ){
		stop_ = tmr.get();
	}
}
コード例 #16
0
ファイル: Timer.cpp プロジェクト: GDXN/CoActionOS-Public
void Timer::start(void){
	Tmr tmr(port);
	start_ = tmr.get();
	stop_ = -1;
}