Example #1
0
/*The Main Program*/
int main(int argc, char** argv) {
    /* defines the tray_icon, as well as init gtk*/
    g_set_application_name(PACKAGE_NAME);
    parse_command_line_options(argc,argv);
    register_thread("Main Thread");
    if (!queue_init())
        print("queue_init FAILED",NULL,ERROR);
    print("Glade File",glade_file,DEBUG);
    g_thread_init(NULL);
    gtk_init(NULL,NULL);
    gtk_init(&argc, &argv);
    Hosts_lock = g_mutex_new();
    Userpath_lock = g_mutex_new();
    g_mutex_lock(Userpath_lock);
    Userpath = g_strdup(getenv("HOME"));
    g_mutex_unlock(Userpath_lock);

    settings_init();
    rest_init();
    if (!xml_init())
        print("xml_init FAILED",NULL,ERROR);
    init_hostname();
    /*sets the tray icon from the create_tray_icon*/
    create_tray_icon();
    playing_info_music pInfo = {"Artist","Album","Song",0,0,0};
    /* declares the playing info struct, and print if, if _DEBUG is definded at the top of msdaemon.c*/
    /*inits the dbus and get the first set of info*/
    dbus_init();
    pInfo = dbus_get_playing_info_music();
    print_playing_info_music(pInfo);
    get_active_devices(NULL);
    update_song_info();
    GError *error;
    if ( (network_thread = g_thread_create((GThreadFunc)rest_thread_handler, NULL, FALSE, &error)) == NULL){
        print("Error Creating Network Thread",error->message,ERROR);
        g_error_free(error);
    }

    if ( (file_thread = g_thread_create((GThreadFunc)file_thread_handler, NULL, FALSE, &error)) == NULL){
        print("Error Creating Network Thread",error->message,ERROR);
        g_error_free(error);
    }
    if ( (gui_thread = g_thread_create((GThreadFunc)gui_thread_handler, NULL, FALSE, &error)) == NULL){
        print("Error Creating Network Thread",error->message,ERROR);
        g_error_free(error);
    }

    g_timeout_add (1000,(GSourceFunc) get_next_command,NULL);
    g_timeout_add (300000,(GSourceFunc) update_active_devices,NULL);
    init_status_window(FALSE,glade_file);
    start_tray();
    g_free(Userpath);

    deauthenticate();
    return 0;
}
Example #2
0
/* The parser calls this callback after it finishes parsing all
 * --foo=bar options inside the script. At this point we know all
 * command line and in-script options, and can finalize our
 * configuration. Notably, this allows us to know when we parse a TCP
 * packet line in the script whether we should create an IPv4 or IPv6
 * packet.
 */
void parse_and_finalize_config(struct invocation *invocation)
{
	DEBUGP("parse_and_finalize_config\n");

	/* Parse options in script */
	parse_script_options(invocation->config,
			     invocation->script->option_list);

	/* Command line options overwrite options in script */
	parse_command_line_options(invocation->argc, invocation->argv,
					   invocation->config);

	/* Now take care of the last details */
	finalize_config(invocation->config);
}
Example #3
0
void
parse_command_line(int argc, char **argv, rtapp_options_t *opts)
{
#ifdef JSON
	if (argc < 2)
		usage(NULL, EXIT_SUCCESS);
	struct stat config_file_stat;
	if (stat(argv[1], &config_file_stat) == 0) {
		parse_config(argv[1], opts);
		return;
	}
	else if (strcmp(argv[1], "-") == 0) {
		parse_config_stdin(opts);
		return;
	} 
#endif
	parse_command_line_options(argc, argv, opts);
	opts->resources = NULL;
	opts->nresources = 0;
}
Example #4
0
int main(int argc, char *argv[])
{
    opt::options_description desc("Usage: ");
    opt::positional_options_description po;
    opt::variables_map vm;
    std::shared_ptr<cnote> cn;
    set_options(desc, po);
    if (!parse_command_line_options(desc, po, argc, argv, vm)) {
        std::cout << "See -h for usage." << std::endl;
        return -1;
    }
    parse_cnote_options(vm);
    cnote_parser parser;
    if (!parse_note_database(parser, opts.notes_db_.c_str()))
        return -1;
    
    if (vm.count("help")) {
        std::cout << desc << std::endl;
        return 0;
    } else if (vm.count("search")) {
        if (opts.debug_)
            std::cout << "Searching for: " << vm["search"].as<std::string>()
                    << std::endl;
        print_note(parser, vm["search"].as<std::string>());
        return 0;
    } else if (vm.count("list")) {
        list_notes(parser);
        return 0;
    }

    cnote_creator cc;
    cn = cc.create_note();

    if (cn) {
        parser.save_note(cn);
        write_note_database(parser, opts.notes_db_.c_str());
    }
    return 0;
}
Example #5
0
int main(int argc, char* argv[]) {
  gtk_init(&argc, &argv);

  if(!parse_command_line_options(argc, argv)) {
    return 1;
  }

  if (show_version) {
    printf(VERSION);
    return 0;
  }

  if (config_file == NULL) {
    config_file = DEFAULT_CONFIG_FILE;
  }
  parse_config_file(config_file);

  new_window();

  gtk_main();
  return 0;
}
int main (int argc, char** argv)
{
	boost::program_options::variables_map variablesMap;

	// Parse parameters, exit if help is requested
	if (parse_command_line_options(variablesMap, argc, argv))
		return 1;

	// General parameters
	std::string sessionName			= variablesMap[PARAM_NAME].as<std::string>();
	bool enabledViewer				= variablesMap[PARAM_VIEWER].as<bool>();
	int rotationModifier			= variablesMap[PARAM_ROTATION].as<int>();
	std::string cloudsDirectory		= variablesMap[PARAM_CLOUDSDIR].as<std::string>();
	int numClouds					= variablesMap[PARAM_NUMCLOUDS].as<int>();
	double stepRotationAngle		= variablesMap[PARAM_STEP_ANGLE].as<double>();
	bool saveBinaryFormat			= variablesMap[PARAM_SAVE_BINARY].as<bool>();

	// Ground truth parameters
	double groundCenterX = variablesMap[PARAM_GROUND_CENTER_X].as<double>();
	double groundCenterY = variablesMap[PARAM_GROUND_CENTER_Y].as<double>();
	double groundCenterZ = variablesMap[PARAM_GROUND_CENTER_Z].as<double>();
	double groundNormalX = variablesMap[PARAM_GROUND_NORMAL_X].as<double>();
	double groundNormalY = variablesMap[PARAM_GROUND_NORMAL_Y].as<double>();
	double groundNormalZ = variablesMap[PARAM_GROUND_NORMAL_Z].as<double>();

	// Bilateral Filtering parameters
	bool applyBilateralFilter = variablesMap[PARAM_BILATERAL_FILTER].as<bool>();
	float bilateralFilterSigmaR = variablesMap[PARAM_BILATERAL_FILTER_SIGMA_R].as<float>();
	float bilateralFilterSigmaS = variablesMap[PARAM_BILATERAL_FILTER_SIGMA_S].as<float>();

	// Normal estimation parameters
	int normalEstimationK				= variablesMap[PARAM_NORMAL_ESTIMATION_K].as<int>();
	int downsampledNormalEstimationK	= variablesMap[PARAM_NORMAL_ESTIMATION_DOWN_K].as<int>();

	// SOR parameters
	bool sorEnabled		= variablesMap[PARAM_SOR].as<bool>();
	int sorMeanK		= variablesMap[PARAM_SOR_MEANK].as<int>();
	float sorStdDev		= variablesMap[PARAM_SOR_STDDEV].as<float>();

	// ROR parameters
	bool rorEnabled		= variablesMap[PARAM_ROR].as<bool>();
	int rorNeighbors	= variablesMap[PARAM_ROR_NEIGHBORS].as<int>();
	float rorRadius		= variablesMap[PARAM_ROR_RADIUS].as<float>();

	// Cut parameters
	bool cutEnabled		= variablesMap[PARAM_CUT].as<bool>();
	int cutAmount		= variablesMap[PARAM_CUT_AMOUNT].as<int>();

	// ECE parameters
	bool eceEnabled		= variablesMap[PARAM_ECE].as<bool>();
	int eceClusters		= variablesMap[PARAM_ECE_CLUSTERS].as<int>();
	int eceMaxSize		= variablesMap[PARAM_ECE_MAXSIZE].as<int>();
	int eceMinSize		= variablesMap[PARAM_ECE_MINSIZE].as<int>();
	float eceTolerance	= variablesMap[PARAM_ECE_TOLERANCE].as<float>();

	// ICP parameters
	bool icpEnabled		= variablesMap[PARAM_ICP].as<bool>();
	int icpIterations	= variablesMap[PARAM_ICP_MAXITERATIONS].as<int>();
	double icpEpsilon	= variablesMap[PARAM_ICP_EPSILON].as<double>();

	// VG parameters
	bool vgEnabled		= variablesMap[PARAM_VG].as<bool>();
	float vgLeafSize	= variablesMap[PARAM_VG_LEAFSIZE].as<float>();

	// PMR parameters
	bool pmrEnabled		= variablesMap[PARAM_PMR].as<bool>();
	float pmrSrchRadM	= variablesMap[PARAM_PMR_MLS_SEARCHRADIUS].as<float>();
	bool pmrPolyFit		= variablesMap[PARAM_PMR_MLS_POLYNOMIALFIT].as<bool>();
	int pmrPolyOrder	= variablesMap[PARAM_PMR_MLS_POLYNOMIALORDER].as<int>();
	float pmrUpSmpRad	= variablesMap[PARAM_PMR_MLS_UPSAMPLINGRADIUS].as<float>();
	float pmrUpSmpStp	= variablesMap[PARAM_PMR_MLS_UPSAMPLINGSTEP].as<float>();
	float pmrSrchRadN	= variablesMap[PARAM_PMR_NE_RADIUSSEARCH].as<float>();
	int pmrDepth		= variablesMap[PARAM_PMR_P_DEPTH].as<int>();


	// Get PCD filenames from the specified directory
	std::vector<std::string> filenames;
	Utils::get_pcd_filenames(cloudsDirectory, filenames);

	// Ground truth center and normal
	Eigen::Vector3f groundCenter(groundCenterX, groundCenterY, groundCenterZ);
	Eigen::Vector3f groundNormal(groundNormalX, groundNormalY, groundNormalZ);

	pcl::visualization::PCLVisualizer viewer(sessionName.c_str());
	std::vector<pcl::PointCloud<pcl::PointXYZRGB>::Ptr> clouds;
	Eigen::Matrix4f icpAccumulatedTransformation = Eigen::Matrix4f::Identity();

	int rotationMultiplier = 0;
	for (auto it = filenames.begin(); it != filenames.end() && rotationMultiplier < numClouds; ++it)
	{
		pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGB>());

		// Load PCD file
		if (pcl::io::loadPCDFile (*it, *cloud) < 0)  
		{
			std::cerr << "Error loading point cloud " << *it << "\n";
			return -1;
		}

		std::cout << "Loaded point cloud: " << *it << "\n";

		// Apply bilateral filter to cloud
		if (applyBilateralFilter)
			PointCloudOperations::filter_bilateral(
			cloud,
			bilateralFilterSigmaR,
			bilateralFilterSigmaS,
			cloud);

		// Remove NaNs from the point cloud
		std::vector<int> mapping;
		pcl::removeNaNFromPointCloud(*cloud, *cloud, mapping);
		std::cout << "NaNs removed..." << "\n";

		// Statistical Outlier Removal filtering
		if (sorEnabled)
			PointCloudOperations::sor_cloud	
				(
					cloud, 
					cloud, 
					sorMeanK, 
					sorStdDev
				);

		// Radial Outlier Removal filtering
		if (rorEnabled)
			PointCloudOperations::ror_cloud
				(
					cloud,
					cloud,
					rorNeighbors,
					rorRadius
				);

		// Cloud cutting threshold
		if (cutEnabled)
			PointCloudOperations::cut_cloud
				(
					cloud,
					cloud,
					cutAmount
				);

		// Euclidean Cluster Extraction filter
		if (eceEnabled)
			PointCloudOperations::ece_cloud
				(
					cloud, 
					cloud, 
					eceTolerance,
					eceMinSize,
					eceMaxSize,
					eceClusters
				);

		// Translation to origin
		PointCloudOperations::translate_cloud
			(
				cloud, 
				cloud, 
				groundCenter
			);

		// Step rotation
		PointCloudOperations::rotate_cloud
			(
				cloud, 
				cloud, 
				(rotationModifier * stepRotationAngle * rotationMultiplier), 
				groundNormal
			);

		// Cloud ICP alignment
		if (icpEnabled && rotationMultiplier > 0)
			PointCloudOperations::icp_align_cloud
				(
					cloud,
					clouds.at(rotationMultiplier - 1),
					cloud,
					icpIterations,
					icpEpsilon
				);

		clouds.push_back(cloud);
		++rotationMultiplier;
	}

	// Concatenate all the processed clouds
	pcl::PointCloud<pcl::PointXYZRGB>::Ptr concatenatedClouds(new pcl::PointCloud<pcl::PointXYZRGB>());
	PointCloudOperations::concatenate_clouds(clouds, concatenatedClouds);

	//PointCloudOperations::translate_cloud(concatenatedClouds, concatenatedClouds, Eigen::Vector3f(-groundCenter.x(), -groundCenter.y(), -groundCenter.z()));

	// Save 360-registered clouds
	pcl::io::savePCDFile(sessionName + "_cloud.pcd", *concatenatedClouds, saveBinaryFormat);
	pcl::io::savePLYFile(sessionName + "_cloud.ply", *concatenatedClouds, saveBinaryFormat);

	// Save cloud normals
	pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>());
	PointCloudOperations::compute_normals(concatenatedClouds, normalEstimationK, normals);
	for (size_t i = 0; i < normals->size(); ++i)
	{
		normals->points[i].normal_x *= -1.0;
		normals->points[i].normal_y *= -1.0;
		normals->points[i].normal_z *= -1.0;
	}
	pcl::io::savePCDFile(sessionName + "_cloud_normals.pcd", *normals, saveBinaryFormat);
	pcl::io::savePLYFile(sessionName + "_cloud_normals.ply", *normals, saveBinaryFormat);

	// Save cloud with normals
	pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr cloudWithNormals(new pcl::PointCloud<pcl::PointXYZRGBNormal>());
	pcl::concatenateFields(*concatenatedClouds, *normals, *cloudWithNormals);
	pcl::io::savePCDFile(sessionName + "_cloud_with_normals.pcd", *cloudWithNormals, saveBinaryFormat);
	pcl::io::savePLYFile(sessionName + "_cloud_with_normals.ply", *cloudWithNormals, saveBinaryFormat);

	pcl::PointCloud<pcl::PointXYZRGB>::Ptr downsampledCloud(new pcl::PointCloud<pcl::PointXYZRGB>());
	pcl::PointCloud<pcl::Normal>::Ptr downsampledNormals(new pcl::PointCloud<pcl::Normal>());
	pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr downsampledCloudWithNormals(new pcl::PointCloud<pcl::PointXYZRGBNormal>());

	// Voxel Grid filter
	if (vgEnabled)
	{
		PointCloudOperations::vg_cloud
			(
				concatenatedClouds,
				downsampledCloud,
				vgLeafSize
			);

		// Save downsampled clouds
		pcl::io::savePCDFile(sessionName + "_cloud_downsampled.pcd", *downsampledCloud, saveBinaryFormat);
		pcl::io::savePLYFile(sessionName + "_cloud_downsampled.ply", *downsampledCloud, saveBinaryFormat);

		// Save downsampled clouds normals
		PointCloudOperations::compute_normals(downsampledCloud, downsampledNormalEstimationK, downsampledNormals);
		for (size_t i = 0; i < downsampledNormals->size(); ++i)
		{
			downsampledNormals->points[i].normal_x *= -1.0;
			downsampledNormals->points[i].normal_y *= -1.0;
			downsampledNormals->points[i].normal_z *= -1.0;
		}
		pcl::io::savePCDFile(sessionName + "_cloud_downsampled_normals.pcd", *downsampledNormals, saveBinaryFormat);
		pcl::io::savePLYFile(sessionName + "_cloud_downsampled_normals.ply", *downsampledNormals, saveBinaryFormat);

		// Save downsampled clouds with normals
		pcl::concatenateFields(*downsampledCloud, *downsampledNormals, *downsampledCloudWithNormals);
		pcl::io::savePCDFile(sessionName + "_cloud_downsampled_with_normals.pcd", *downsampledCloudWithNormals, saveBinaryFormat);
		pcl::io::savePLYFile(sessionName + "_cloud_downsampled_with_normals.ply", *downsampledCloudWithNormals, saveBinaryFormat);
	}
	else
	{
		//pcl::copyPointCloud(*concatenatedClouds, *downsampledCloud);
		downsampledCloud = concatenatedClouds;
		downsampledNormals = normals;
		downsampledCloudWithNormals = downsampledCloudWithNormals;
	}

	// Poisson Mesh reconstruction
	if (pmrEnabled)
	{
		pcl::PolygonMesh mesh;

		PointCloudOperations::pmr_cloud
			(
				downsampledCloud,
				mesh,
				pmrSrchRadM,
				pmrPolyFit,
				pmrPolyOrder,
				pmrUpSmpRad,
				pmrUpSmpStp,
				pmrSrchRadN,
				pmrDepth
			);

		// Save reconstructed mesh
		pcl::io::savePLYFile(sessionName + "_mesh.ply", mesh, 5);

		viewer.addPolygonMesh(mesh);
	}

	// Set up the viewer
	if (enabledViewer)
	{
		std::cout << "Adding clouds to viewer...\n";

		pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB> cloudColorHandler(downsampledCloud);
		viewer.addPointCloud(downsampledCloud, cloudColorHandler, "cloud");
		viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 2, "cloud");
		viewer.addPointCloudNormals<pcl::PointXYZRGB, pcl::Normal>(downsampledCloud, downsampledNormals, 100, 0.05, "cloudNormals");

		viewer.addCoordinateSystem(0.75, 0);
		viewer.setBackgroundColor(0.8, 0.8, 0.8, 0);

		while (!viewer.wasStopped())
		{
			viewer.spinOnce();
		}
	}

	return 0;
}
Example #7
0
File: ns.cpp Project: arashb/tbslas
int main(int argc, char** argv) {
  MPI_Init(&argc, &argv);
  MPI_Comm comm = MPI_COMM_WORLD;
  int myrank;
  MPI_Comm_rank(comm, &myrank);

  parse_command_line_options(argc, argv);

  bool unif =
      (commandline_option(
           argc, argv, "-unif", NULL, false,
           "-unif                : Uniform point distribution.") != NULL);
  int m =
      strtoul(commandline_option(
                  argc, argv, "-m", "10", false,
                  "-m    <int> = (10)   : Multipole order (+ve even integer)."),
              NULL, 10);
  int test = strtoul(commandline_option(argc, argv, "-test", "1", false,
                                        "-test <int> = (1)    : 1) Laplace, "
                                        "Smooth Gaussian, Periodic Boundary"),
                     NULL, 10);
  int merge = strtoul(commandline_option(argc, argv, "-merge", "1", false,
                                         "-merge <int> = (1)    : 1) no merge "
                                         "2) complete merge 3) Semi-Merge"),
                      NULL, 10);
  double exp_alpha =
      strtod(commandline_option(argc, argv, "-ea", "10", false,
                                "-ea <real> = (10) : diffusivity"),
             NULL);

  // =========================================================================
  // SIMULATION PARAMETERS
  // =========================================================================
  tbslas::SimConfig* sim_config = tbslas::SimConfigSingleton::Instance();

  pvfmm::Profile::Enable(sim_config->profile);
  sim_config->vtk_filename_variable = "vel";
  sim_config->mult_order = m;
  sim_config->merge = merge;
  sim_config->test = test;

  EXP_ALPHA = exp_alpha;

  // =========================================================================
  // PRINT METADATA
  // =========================================================================
  if (!myrank) {
    MetaData_t::Print();
  }

  // SetupFMMPrecomp<double>();

  // =========================================================================
  // RUN
  // =========================================================================
  // pvfmm::Profile::Tic("NS",&comm,true);
  // RunNSFirstOrder<double>(test,
  // 			  sim_config->tree_num_point_sources,
  // 			  sim_config->tree_num_points_per_octanct,
  // 			  unif,
  // 			  m,
  // 			  sim_config->tree_chebyshev_order,
  // 			  sim_config->tree_max_depth,
  // 			  sim_config->tree_adap,
  // 			  sim_config->tree_tolerance,
  // 			  merge,
  // 			  comm);
  // pvfmm::Profile::Toc();

  // =========================================================================
  // RUN
  // =========================================================================
  pvfmm::Profile::Tic("NS", &comm, true);
  RunNS<double>();
  // sim_config->test,
  // 		sim_config->tree_num_point_sources,
  // 		sim_config->tree_num_points_per_octanct,
  // 		unif,
  // 		sim_config->mult_order,
  // 		sim_config->tree_chebyshev_order,
  // 		sim_config->tree_max_depth,
  // 		sim_config->tree_adap,
  // 		sim_config->tree_tolerance,
  // 		sim_config->merge,
  // 		comm);
  pvfmm::Profile::Toc();
  // Output Profiling results.
  // pvfmm::Profile::print(&comm);

  // Shut down MPI
  MPI_Finalize();
  return 0;
}
Example #8
0
int main(int argc, char** argv) {
  MPI_Init(&argc, &argv);
  MPI_Comm comm = MPI_COMM_WORLD;
  int np;
  MPI_Comm_size(comm, &np);
  int myrank;
  MPI_Comm_rank(comm, &myrank);

  parse_command_line_options(argc, argv);

  int test =
      strtoul(commandline_option(
                  argc, argv, "-test", "1", false,
                  "-test <int> = (1)    : 1) Gaussian profile 2) Zalesak disk"),
              NULL, 10);

  {
    tbslas::SimConfig* sim_config = tbslas::SimConfigSingleton::Instance();
    tbslas::new_nodes<Tree_t::Real_t>(sim_config->tree_chebyshev_order, 3);

    pvfmm::Profile::Enable(sim_config->profile);
    // =========================================================================
    // PRINT METADATA
    // =========================================================================
    if (!myrank) {
      MetaData_t::Print();
    }

    // =========================================================================
    // TEST CASE
    // =========================================================================
    double data_dof = 0;
    pvfmm::BoundaryType bc;
    switch (test) {
      case 1:

        // fn_2 = tbslas::get_linear_field_y<double,3>;
        // data_dof = 1;

        // fn_2 = get_gaussian_field_atT<double,3>;
        // data_dof = 1;

        // fn_2 = get_vorticity_field_tv_wrapper<double>;
        // data_dof = 3;

        fn_2 = get_taylor_green_field_tv_ns_wrapper<double>;
        data_dof = 3;

        // fn_2 = tbslas::get_vorticity_field<double,3>;
        // data_dof = 3;

        // fn_2 = get_hopf_field_wrapper<double>;
        // data_dof = 3;

        // fn_2 = get_taylor_green_field_tv_wrapper<double>;
        // data_dof = 3;

        bc = pvfmm::Periodic;
        // bc = pvfmm::FreeSpace;

        break;
    }

    // =========================================================================
    // SIMULATION PARAMETERS
    // =========================================================================
    sim_config->vtk_filename_variable = "conc";
    sim_config->bc = bc;

    double DT = sim_config->dt;
    // double DT = 0.3925;
    // double DT = 1;

    double cheb_deg = sim_config->tree_chebyshev_order;

    std::vector<double> tree_set_times;
    std::vector<Tree_t*> tree_set_elems;

    // =========================================================================
    // INIT THE TREE 1
    // =========================================================================
    tcurr = 0;
    Tree_t tree1(comm);
    tbslas::ConstructTree<Tree_t>(
        sim_config->tree_num_point_sources,
        sim_config->tree_num_points_per_octanct,
        sim_config->tree_chebyshev_order, sim_config->tree_max_depth,
        sim_config->tree_adap, sim_config->tree_tolerance, comm, fn_2, data_dof,
        tree1);
    if (sim_config->vtk_save_rate) {
      tree1.Write2File(tbslas::GetVTKFileName(1, "tree").c_str(),
                       sim_config->vtk_order);
    }
    tree_set_times.push_back(tcurr);
    tree_set_elems.push_back(&tree1);

    // =========================================================================
    // INIT THE TREE 2
    // =========================================================================
    tcurr += DT;
    Tree_t tree2(comm);
    tbslas::ConstructTree<Tree_t>(
        sim_config->tree_num_point_sources,
        sim_config->tree_num_points_per_octanct,
        sim_config->tree_chebyshev_order, sim_config->tree_max_depth,
        sim_config->tree_adap, sim_config->tree_tolerance, comm, fn_2, data_dof,
        tree2);

    if (sim_config->vtk_save_rate) {
      tree2.Write2File(tbslas::GetVTKFileName(2, "tree").c_str(),
                       sim_config->vtk_order);
    }

    tree_set_times.push_back(tcurr);
    tree_set_elems.push_back(&tree2);

    // =========================================================================
    // INIT THE TREE 3
    // =========================================================================
    tcurr += DT;
    Tree_t tree3(comm);
    tbslas::ConstructTree<Tree_t>(
        sim_config->tree_num_point_sources,
        sim_config->tree_num_points_per_octanct,
        sim_config->tree_chebyshev_order, sim_config->tree_max_depth,
        sim_config->tree_adap, sim_config->tree_tolerance, comm, fn_2, data_dof,
        tree3);

    if (sim_config->vtk_save_rate) {
      tree3.Write2File(tbslas::GetVTKFileName(3, "tree").c_str(),
                       sim_config->vtk_order);
    }

    tree_set_times.push_back(tcurr);
    tree_set_elems.push_back(&tree3);

    // =========================================================================
    // INIT THE TREE 4
    // =========================================================================
    tcurr += DT;
    Tree_t tree4(comm);
    tbslas::ConstructTree<Tree_t>(
        sim_config->tree_num_point_sources,
        sim_config->tree_num_points_per_octanct,
        sim_config->tree_chebyshev_order, sim_config->tree_max_depth,
        sim_config->tree_adap, sim_config->tree_tolerance, comm, fn_2, data_dof,
        tree4);
    if (sim_config->vtk_save_rate) {
      tree4.Write2File(tbslas::GetVTKFileName(4, "tree").c_str(),
                       sim_config->vtk_order);
    }

    tree_set_times.push_back(tcurr);
    tree_set_elems.push_back(&tree4);

    // =========================================================================
    // MERGE
    // =========================================================================
    tcurr = 1.5 * DT;
    Tree_t merged_tree(comm);
    tbslas::ConstructTree<Tree_t>(
        sim_config->tree_num_point_sources,
        sim_config->tree_num_points_per_octanct,
        sim_config->tree_chebyshev_order, sim_config->tree_max_depth,
        sim_config->tree_adap, sim_config->tree_tolerance, comm, fn_2, data_dof,
        merged_tree);

    double in_al2, in_rl2, in_ali, in_rli;
    CheckChebOutput<Tree_t>(&merged_tree, fn_2, data_dof, in_al2, in_rl2,
                            in_ali, in_rli, std::string("Input"));

    // =========================================================================
    // COLLECT THE MERGED TREE POINTS
    // =========================================================================
    std::vector<double> merged_tree_points_pos;
    int num_leaf =
        tbslas::CollectChebTreeGridPoints(merged_tree, merged_tree_points_pos);

    // =========================================================================
    // CONSTRUCT THE FUNCTOR
    // =========================================================================
    tbslas::FieldSetFunctor<double, Tree_t> tree_set_functor(tree_set_elems,
                                                             tree_set_times);
    // tbslas::NodeFieldFunctor<double,Tree_t> tree_functor(&merged_tree);

    // int num_points = 1;
    // std::vector<double> xtmp(num_points*3);
    // std::vector<double> vtmp(num_points*data_dof);

    // xtmp[0] = 0.8;
    // xtmp[1] = 1.0;
    // xtmp[2] = 0.3;

    // tree_functor(xtmp.data(),
    //              num_points,
    //              1.5*DT,
    //              vtmp.data());
    // std::cout << "MYRANK: " << myrank << " vals: " << vtmp[0] << " " <<
    // vtmp[1] << " " << vtmp[2] << std::endl;

    // =========================================================================
    // INTERPOLATE IN TIME
    // =========================================================================
    int merged_tree_num_points = merged_tree_points_pos.size() / 3;
    std::vector<double> merged_tree_points_val(merged_tree_num_points *
                                               data_dof);

    pvfmm::Profile::Tic("EvalSet", &sim_config->comm, false, 5);
    tree_set_functor(merged_tree_points_pos.data(), merged_tree_num_points,
                     1.5 * DT, merged_tree_points_val.data());

    // tree_functor(merged_tree_points_pos.data(),
    //              merged_tree_num_points,
    //              merged_tree_points_val.data());
    pvfmm::Profile::Toc();

    // =========================================================================
    // FIX THE VALUES MEMORY LAYOUT
    // =========================================================================
    int d = cheb_deg + 1;
    int num_pnts_per_node = d * d * d;
    std::vector<double> mt_pnts_val_ml(merged_tree_num_points * data_dof);
    for (int nindx = 0; nindx < num_leaf; nindx++) {
      int input_shift = nindx * num_pnts_per_node * data_dof;
      for (int j = 0; j < num_pnts_per_node; j++) {
        for (int i = 0; i < data_dof; i++) {
          mt_pnts_val_ml[input_shift + j + i * num_pnts_per_node] =
              merged_tree_points_val[input_shift + j * data_dof + i];
        }
      }
    }

    // =========================================================================
    // SET INTERPOLATED VALUES
    // =========================================================================
    pvfmm::Profile::Tic("SetValues", &sim_config->comm, false, 5);
    tbslas::SetTreeGridValues(merged_tree, cheb_deg, data_dof, mt_pnts_val_ml);
    pvfmm::Profile::Toc();

    if (sim_config->vtk_save_rate) {
      merged_tree.Write2File(tbslas::GetVTKFileName(0, "tree_interp").c_str(),
                             sim_config->vtk_order);
    }

    double al2, rl2, ali, rli;
    CheckChebOutput<Tree_t>(&merged_tree, fn_2, data_dof, al2, rl2, ali, rli,
                            std::string("Output"));

    // =========================================================================
    // TEST
    // =========================================================================
    // tree_set_functor(xtmp.data(),
    //                  num_points,
    //                  1.5*DT,
    //                  vtmp.data());
    // std::cout << "vals: " << vtmp[0] << " " << vtmp[1] << " " << vtmp[2] <<
    // std::endl;

    // tbslas::NodeFieldFunctor<double,Tree_t> tf(&merged_tree);
    // tf(xtmp.data(),
    //    num_points,
    //    1.5*DT,
    //    vtmp.data());
    // std::cout << "vals: " << vtmp[0] << " " << vtmp[1] << " " << vtmp[2] <<
    // std::endl;

    // =========================================================================
    // REPORT RESULTS
    // =========================================================================
    int tcon_max_depth = 0;
    int tvel_max_depth = 0;
    tbslas::GetTreeMaxDepth(merged_tree, tcon_max_depth);
    // tbslas::GetTreeMaxDepth(tvel, tvel_max_depth);

    typedef tbslas::Reporter<double> Rep;
    if (!myrank) {
      Rep::AddData("NP", np, tbslas::REP_INT);
      Rep::AddData("OMP", sim_config->num_omp_threads, tbslas::REP_INT);

      Rep::AddData("TOL", sim_config->tree_tolerance);
      Rep::AddData("Q", sim_config->tree_chebyshev_order, tbslas::REP_INT);

      Rep::AddData("MaxD", sim_config->tree_max_depth, tbslas::REP_INT);
      Rep::AddData("CMaxD", tcon_max_depth, tbslas::REP_INT);
      // Rep::AddData("VMaxD", tvel_max_depth, tbslas::REP_INT);

      // Rep::AddData("CBC", sim_config->use_cubic?1:0, tbslas::REP_INT);
      // Rep::AddData("CUF", sim_config->cubic_upsampling_factor,
      // tbslas::REP_INT);

      Rep::AddData("DT", sim_config->dt);
      // Rep::AddData("TN", sim_config->total_num_timestep, tbslas::REP_INT);
      // Rep::AddData("TEST", test, tbslas::REP_INT);
      // Rep::AddData("MERGE", merge, tbslas::REP_INT);

      Rep::AddData("InAL2", in_al2);
      Rep::AddData("OutAL2", al2);

      Rep::AddData("InRL2", in_rl2);
      Rep::AddData("OutRL2", rl2);

      Rep::AddData("InALINF", in_ali);
      Rep::AddData("OutALINF", ali);

      Rep::AddData("InRLINF", in_rli);
      Rep::AddData("OutRLINF", rli);

      Rep::Report();
    }

    // Output Profiling results.
    // pvfmm::Profile::print(&comm);
  }

  // Shut down MPI
  MPI_Finalize();
  return 0;
}
Example #9
0
int main(int argc, char *argv[]) {
    std::string ip_address = "";
    int parse_ret = parse_command_line_options(argc, argv, ip_address);
    if(parse_ret != 1)
        return parse_ret;

    if(ip_address.empty()) {
        ip_address = DEFAULT_IP_ADDR;
    }

    print_intro();

    modbus_t *mb;

    mb = modbus_new_tcp(DEFAULT_IP_ADDR, 502);
    if (mb == NULL) {
        fprintf(stderr, "Unable to allocate libmodbus context\n");
        return -1;
    }
    if (modbus_connect(mb) == -1) {
        fprintf(stderr, "Connection failed: %s\n", modbus_strerror(errno));
        modbus_free(mb);
        return -1;
    }

    setup_interupt();

    bool write_bool = true;
    int  write_num  = 0;
    unsigned int count = 0;
    uint8_t outputs[16] = {0};

    //variables for calculations
    bool button_pressed = false;

    try {
        while (true) {
            uint16_t input = 0;
            if(read_inputs(mb, &input) == -1)
                break;
            button_pressed = get_input_bit(input, 9);

            //solenoid = button xor photoeyen
            bool sol_out = button_pressed ^ get_input_bit(input, 2);

            outputs[0] = sol_out;

            if(write_outputs(mb, outputs) == -1)
                break;


            print_io(input, outputs);

            /* code for incrmenting IO
            count++;
            if(count%50==0){
                outputs[write_num] = write_bool;
                write_num++;
            }
            if(write_num==16){
                write_bool = !write_bool;
                write_num = 0;
            }*/
            usleep(1*1000); //Sleep 1ms
        }
    } catch(InterruptException& e) {
        modbus_close(mb);
        modbus_free(mb);
    }
}
Example #10
0
int main(int argc, char *argv[])
{
   int p=0, w=0, h=0, x=-1000000, y=-1000000;
   //GdkGeometry geom;

   channels = NULL;
   current_channel = -1;
   previous_channel = -1;
   lirc_dev = NULL;
   channelcombo = NULL;

   gtk_init(&argc, &argv);
   if (!parse_command_line_options(&argc, &argv, &p, &w, &h, &x, &y)) return 1;
   load_options(w?NULL:&w, h?NULL:&h, x!=-1000000?NULL:&x, y!=-1000000?NULL:&y);
   if (p) port = p;

   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_signal_connect (GTK_OBJECT (window), "delete_event",
      GTK_SIGNAL_FUNC (delete_event), NULL);
   gtk_signal_connect (GTK_OBJECT (window), "destroy",
      GTK_SIGNAL_FUNC (destroy), NULL);
   gtk_window_set_policy(GTK_WINDOW(window), 1, 1, 0);

   gtk_window_set_title (GTK_WINDOW (window), "Linux Video Studio TV");
   gtk_container_set_border_width (GTK_CONTAINER (window), 0);

   tv = gtk_tvplug_new(port);
   if (!tv)
   {
      g_print("ERROR: no suitable video4linux device found\n");
      g_print("Please supply a video4linux Xv-port manually (\'stv -p <num>\')\n");
      return 1;
   }
   if (channels)
   {
      int i;
      for(i=0;channels[i];i++)
         if (channels[i]->frequency == (int)GTK_TVPLUG(tv)->frequency_adj->value)
         {
            current_channel = i;
            break;
         }
   }
   if (!port) port = GTK_TVPLUG(tv)->port;
   GTK_WIDGET_SET_FLAGS(tv, GTK_CAN_FOCUS); /* key press events */
   gtk_container_add (GTK_CONTAINER (window), tv);
   gtk_widget_show(tv);
   set_background_color(tv, 0, 0, 0);

   gtk_signal_connect(GTK_OBJECT(tv), "button_press_event",
      GTK_SIGNAL_FUNC(tv_clicked), NULL);
   gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
      GTK_SIGNAL_FUNC(tv_typed), NULL);
   gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
      GTK_SIGNAL_FUNC(focus_in_event), NULL);
   gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
      GTK_SIGNAL_FUNC(focus_out_event), NULL);
   set_background_color(window, 0, 0, 0);

   input_init();
#if 0
   geom.min_width = GTK_TVPLUG(tv)->width_best/16;
   geom.min_height = GTK_TVPLUG(tv)->height_best/16;
   geom.max_width = GTK_TVPLUG(tv)->width_best;
   geom.max_height = GTK_TVPLUG(tv)->height_best;
   geom.width_inc = GTK_TVPLUG(tv)->width_best/16;
   geom.height_inc = GTK_TVPLUG(tv)->height_best/16;
   geom.min_aspect = GTK_TVPLUG(tv)->height_best / GTK_TVPLUG(tv)->width_best - 0.05;
   geom.max_aspect = GTK_TVPLUG(tv)->height_best / GTK_TVPLUG(tv)->width_best + 0.05;
   gtk_window_set_geometry_hints(GTK_WINDOW(window), window, &geom,
      GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE | GDK_HINT_ASPECT | GDK_HINT_RESIZE_INC);
   if (w>0 && h>0) gtk_widget_set_usize(window, w, h);
   if (x!=-1000000 && y!=-1000000) gtk_widget_set_uposition(window, x, y);
#endif
#ifdef HAVE_LIRC
   lirc_init();
#endif
#ifdef OSS
   sound_init();
#endif

   gtk_widget_show(window);

   gtk_main();

   return 0;
}