/** \brief Find a curve with the input name as its input_filename. \return A pointer to the curve with the name, or NULL if it is not found. \param findme The name you want to appear as the input_filename of the curve. */ const Curve * curve_with_name(const std::string & findme) const { if (findme.compare(crit_curve_.input_filename().filename().string())==0) { return &crit_curve_; } if (findme.compare(sphere_curve_.input_filename().filename().string())==0) { return &sphere_curve_; } for (auto iter = singular_curves_.begin(); iter!=singular_curves_.end(); ++iter) { if (findme.compare(iter->second.input_filename().filename().string())==0) { return &(iter->second); } } for (auto iter = mid_slices_.begin(); iter!=mid_slices_.end(); ++iter) { if (findme.compare(iter->input_filename().filename().string())==0) { return &(*iter); } } for (auto iter = crit_slices_.begin(); iter!=crit_slices_.end(); ++iter) { if (findme.compare(iter->input_filename().filename().string())==0) { return &(*iter); } } std::cout << "failed to find curve with name " << findme << std::endl; return NULL; }
void lex_error(sub_context_ty *scp, char *s) { string_ty *buffer; int len; int need_to_delete; if (scp) need_to_delete = 0; else { scp = sub_context_new(); need_to_delete = 1; } buffer = subst_intl(scp, s); len = buffer->str_length; while (len > 0 && isspace(buffer->str_text[len - 1])) --len; /* re-use substitution context */ sub_var_set_string(scp, "File_Name", input_filename(input)); sub_var_set_long(scp, "Number", line_number); sub_var_set(scp, "MeSsaGe", "%.*s", len, buffer->str_text); str_free(buffer); error_intl(scp, i18n("$filename: $number: $message")); notify(); if (need_to_delete) sub_context_delete(scp); }
void gram_trace2(void *garbage, char *s, ...) { va_list ap; string_ty *buffer; char *cp; static char line[1024]; va_start(ap, s); buffer = str_vformat(s, ap); va_end(ap); cp = line + strlen(line); cp = strendcpy(cp, buffer->str_text, line + sizeof(line)); str_free(buffer); if (cp > line && cp[-1] == '\n') { --cp; *cp = 0; trace_printf ( "%s: %ld: %s\n", input_filename(input)->str_text, line_number, line ); line[0] = 0; } }
int main(int argc, char* argv[]) { if (argc < 2 || argc > 3) { std::cerr << "Usage: " << argv[0] << " INFILE [OUTFILE]" << std::endl; exit(1); } std::string input_filename(argv[1]); std::string output_filename; if (argc != 3) { output_filename = std::string("out.sqlite"); } else { output_filename = std::string(argv[2]); } { // from http://stackoverflow.com/questions/1647557/ifstream-how-to-tell-if-specified-file-doesnt-exist/3071528#3071528 struct stat file_info; if (stat(output_filename.c_str(), &file_info) == 0) { std::cerr << "ERROR: Output file '" << output_filename << "' exists. Aborting..." << std::endl; exit(1); } } std::set<osmium::unsigned_object_id_type> addr_interpolation_node_set; name2highways_type name2highway; index_pos_type index_pos; index_neg_type index_neg; location_handler_type location_handler(index_pos, index_neg); //location_handler.ignore_errors(); MemHelper mem_helper; //mem_helper.start(); { osmium::io::Reader reader(input_filename); FirstHandler first_handler(addr_interpolation_node_set, name2highway); osmium::apply(reader, location_handler, first_handler); reader.close(); } //mem_helper.stop(); osmium::io::Reader reader2(input_filename); SecondHandler second_handler(output_filename, addr_interpolation_node_set, name2highway); osmium::apply(reader2, location_handler, second_handler); reader2.close(); google::protobuf::ShutdownProtobufLibrary(); std::cout << std::endl; mem_helper.print_max(); std::cout << "\nsoftware finished properly\n" << std::endl; return 0; }
static void notify(void) { if (!input) return; if (++error_count >= 20) { sub_context_ty *scp; scp = sub_context_new(); sub_var_set_string(scp, "File_Name", input_filename(input)); fatal_intl(scp, i18n("$filename: too many fatal errors")); } }
int main(int argc, char* argv[]){ /* Arguments: 1:input (2:output) */ if (argc <= 1) { std::cout << "Error: Filename must be specified." << std::endl; std::cout << "Usage: " << argv[0] << " input [output]" << std::endl; return -1; } if (argc > 3) { std::cout << "Error: Extra arguments." << std::endl; std::cout << "Usage: " << argv[0] << " input [output]" << std::endl; return -1; } std::string output_filename; std::ofstream output_file; if (argc == 3) { std::cout << "Saving to " << argv[2] << std::endl; output_filename = argv[2]; output_file.open(argv[2], std::ifstream::out); if (!output_file.is_open()) { std::cout << "Error: Creating output file." << std::endl; return -1; } } // Opening input: std::string input_filename(argv[1]); if (!std::ifstream(input_filename).good()){ std::cerr << "Error: Input file." << std::endl; return -1; } // Translating... try { Assembler a(input_filename); if (!output_filename.empty()) { a.translate(output_file); output_file.close(); } else { a.translate(std::cout); } } catch(std::runtime_error& e) { std::cerr << "Exiting... (" << e.what() << ")" << std::endl; return -1; } return 0; }
void getSokolovOfChainsBulk(string path, string input_name) { string input_filename(path); input_filename.append(input_name); std::ifstream input_file; input_file.open(input_filename); string line; getline (input_file, line); istringstream linestream(line); int L, l, m; long double eps; string output_name; linestream >> L >> l >> m >> eps >> output_name; string output_filename(path); output_filename.append(output_name); std::ofstream output_file; output_file.open(output_filename); output_file.close(); int max_probs_count = 20; vector<long double> probs; probs.reserve(max_probs_count); int probs_count = 0; do { getline (input_file, line); if (!line.empty()) { vector<int> errors(readChainErrors(line)); long double prob = GetSokolovBound(L, l, m, eps, errors); probs.push_back(prob); ++probs_count; } if ((probs_count == max_probs_count) or (input_file.eof())) { output_file.open(output_filename, std::ios::app); copy(probs.begin(), probs.end(), std::ostream_iterator<long double>(output_file, "\n")); output_file.close(); probs.clear(); probs.reserve(max_probs_count); probs_count = 0; } std::cout << probs.size() << "\n"; } while (!input_file.eof()); input_file.close(); }
void Transcoder::run() { position_ = eta_ = audio_b_ = video_b_ = -1; stopping_ = false; pass_ = extra_args_.contains("--two-pass") ? 0 : -1; proc_.start(ffmpeg2theora(), QStringList() << "--frontend" << extra_args_ << "--output" << output_filename() << input_filename()); if (proc_.waitForStarted()) exec(); else emit statusUpdate("Encoding failed to start"); }
int main(int argc, char **argv) { try { TCLAP::CmdLine cmd("Centers a mesh", ' ', "1.0"); TCLAP::ValueArg<std::string> log_filename("l","logfile", "Log file name (default is convert.log)", false, "convert.log", "string"); cmd.add( log_filename ); TCLAP::UnlabeledValueArg<std::string> input_filename( "input-filename", "Input file name", true, "", "InputFile" ); cmd.add( input_filename ); TCLAP::UnlabeledValueArg<std::string> output_filename( "output-filename", "Output file name", true, "", "OutputFile" ); cmd.add( output_filename ); cmd.parse( argc, argv ); if ( !log_filename.getValue().empty() ) viennamesh_log_add_logging_file(log_filename.getValue().c_str(), NULL); viennamesh::context_handle context; viennamesh::algorithm_handle mesh_reader = context.make_algorithm("mesh_reader"); mesh_reader.set_input( "filename", input_filename.getValue() ); mesh_reader.run(); viennamesh::algorithm_handle center_mesh = context.make_algorithm("center_mesh"); center_mesh.set_default_source(mesh_reader); center_mesh.run(); viennamesh::algorithm_handle mesh_writer = context.make_algorithm("mesh_writer"); mesh_writer.set_default_source(center_mesh); mesh_writer.set_input( "filename", output_filename.getValue() ); mesh_writer.run(); } catch (TCLAP::ArgException &e) // catch any exceptions { std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; } return 0; }
int main(int argc, char* argv[]) { if (argc != 2) { std::cerr << "Usage: " << argv[0] << " INFILE\n"; exit(1); } std::string output_format("SQLite"); std::string input_filename(argv[1]); std::string output_filename("multipolygon.db"); OGRDataSource* data_source = initialize_database(output_format, output_filename); osmium::area::ProblemReporterOGR problem_reporter(data_source); osmium::area::Assembler::config_type assembler_config(&problem_reporter); assembler_config.enable_debug_output(); osmium::area::MultipolygonCollector<osmium::area::Assembler> collector(assembler_config); std::cerr << "Pass 1...\n"; osmium::io::Reader reader1(input_filename); collector.read_relations(reader1); reader1.close(); std::cerr << "Pass 1 done\n"; index_type index_pos; index_type index_neg; location_handler_type location_handler(index_pos, index_neg); location_handler.ignore_errors(); TestHandler test_handler(data_source); std::cerr << "Pass 2...\n"; osmium::io::Reader reader2(input_filename); osmium::apply(reader2, location_handler, test_handler, collector.handler([&test_handler](const osmium::memory::Buffer& area_buffer) { osmium::apply(area_buffer, test_handler); })); reader2.close(); std::cerr << "Pass 2 done\n"; OGRDataSource::DestroyDataSource(data_source); OGRCleanupAll(); }
int main(int argc, char** argv) { if (argc != 3) { std::cerr << "Usage: urdf_to_collada input.urdf output.dae" << std::endl; return -1; } ros::init(argc, argv, "urdf_to_collada"); std::string input_filename(argv[1]); std::string output_filename(argv[2]); urdf::Model robot_model; if( !robot_model.initFile(input_filename) ) { ROS_ERROR("failed to open urdf file %s",input_filename.c_str()); } collada_urdf::WriteUrdfModelToColladaFile(robot_model, output_filename); std::cout << std::endl << "Document successfully written to " << output_filename << std::endl; return 0; }
void lex_close(void) { trace(("lex_close()\n{\n")); assert(input); if (error_count) { sub_context_ty *scp; scp = sub_context_new(); sub_var_set_string(scp, "File_Name", input_filename(input)); sub_var_set_long(scp, "Number", error_count); sub_var_optional(scp, "Number"); fatal_intl(scp, i18n("$filename: found $number fatal errors")); } input_delete(input); input = 0; line_number = 0; bol = 0; first = 0; trace(("}\n")); }
int main(int argc, char* argv[]) { if (argc != 2) { std::cerr << "Usage: " << argv[0] << " INFILE\n"; exit(1); } std::string output_format("SQLite"); std::string input_filename(argv[1]); std::string output_filename("testdata-overview.db"); ::unlink(output_filename.c_str()); osmium::io::Reader reader(input_filename); index_type index; location_handler_type location_handler(index); location_handler.ignore_errors(); TestOverviewHandler handler(output_format, output_filename); osmium::apply(reader, location_handler, handler); reader.close(); }
//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++) { // 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; }
gchar *bossao_filename (void) { return input_filename (); }
int main(int argc, char **argv) { try { TCLAP::CmdLine cmd("Maps/Renames segments", ' ', "1.0"); TCLAP::ValueArg<std::string> log_filename("l","logfile", "Log file name (default is convert.log)", false, "convert.log", "string"); cmd.add( log_filename ); TCLAP::ValueArg<std::string> input_filetype("","inputtype", "Input file type. Can be\nauto - ViennaMesh automatically detects the file format (default)\nvtk - for VTK files\nmesh - for Netgen .mesh files\npoly - for Tetgen .poly files\ndeva - for GTS deva files", false, "auto", "string"); cmd.add( input_filetype ); TCLAP::ValueArg<std::string> output_filetype("","outputtype", "Output file type. Can be\nauto - ViennaMesh automatically detects the file format (default)\nvtk - for VTK files\nvmesh - for Vienna vmesh files", false, "auto", "string"); cmd.add( output_filetype ); TCLAP::ValueArg<std::string> segment_mapping_string("m","segment-mapping", "Segment mapping. Syntax: \"src_id,dst_id;src_id,dst_id\"", true, "", "string"); cmd.add( segment_mapping_string ); TCLAP::UnlabeledValueArg<std::string> input_filename( "input-filename", "Input file name", true, "", "InputFile" ); cmd.add( input_filename ); TCLAP::UnlabeledValueArg<std::string> output_filename( "output-filename", "Output file name", true, "", "OutputFile" ); cmd.add( output_filename ); cmd.parse( argc, argv ); viennamesh::logger().register_callback( new viennamesh::FileStreamCallback<viennamesh::FileStreamFormater>( log_filename.getValue() ) ); viennamesh::algorithm_handle reader( new viennamesh::io::mesh_reader() ); reader->set_input( "filename", input_filename.getValue() ); if (input_filetype.isSet() && (input_filetype.getValue() != "auto")) reader->set_input( "file_type", input_filetype.getValue() ); reader->run(); std::map<int, int> segment_mapping; std::list<std::string> split_mappings = stringtools::split_string( segment_mapping_string.getValue(), ";" ); for (std::list<std::string>::const_iterator mit = split_mappings.begin(); mit != split_mappings.end(); ++mit) { std::list<std::string> from_to = stringtools::split_string( *mit, "," ); std::list<std::string>::const_iterator it = from_to.begin(); if (it == from_to.end()) continue; int src_segment_id = lexical_cast<int>(*it); ++it; if (it == from_to.end()) continue; int dst_segment_id = lexical_cast<int>(*it); segment_mapping[src_segment_id] = dst_segment_id; } viennamesh::algorithm_handle map_segments( new viennamesh::map_segments() ); map_segments->set_input( "mesh", reader->get_output("mesh") ); map_segments->set_input( "segment_mapping", segment_mapping ); map_segments->run(); viennamesh::algorithm_handle writer( new viennamesh::io::mesh_writer() ); writer->set_input( "mesh", map_segments->get_output("mesh") ); writer->set_input( "quantities", reader->get_output("quantities") ); writer->set_input( "filename", output_filename.getValue() ); if (output_filetype.isSet() && (output_filetype.getValue() != "auto")) writer->set_input( "file_type", output_filetype.getValue() ); writer->run(); } catch (TCLAP::ArgException &e) // catch any exceptions { std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; } return 0; }
int main(int argc, char **argv) { try { TCLAP::CmdLine cmd("Geometrically transforms a mesh", ' ', "1.0"); TCLAP::ValueArg<std::string> log_filename("l","logfile", "Log file name (default is convert.log)", false, "convert.log", "string"); cmd.add( log_filename ); TCLAP::ValueArg<std::string> input_filetype("","inputtype", "Input file type. Can be\nauto - ViennaMesh automatically detects the file format (default)\nvtk - for VTK files\nmesh - for Netgen .mesh files\npoly - for Tetgen .poly files\ndeva - for GTS deva files", false, "auto", "string"); cmd.add( input_filetype ); TCLAP::ValueArg<std::string> output_filetype("","outputtype", "Output file type. Can be\nauto - ViennaMesh automatically detects the file format (default)\nvtk - for VTK files\nvmesh - for Vienna vmesh files", false, "auto", "string"); cmd.add( output_filetype ); TCLAP::ValueArg<std::string> matrix_string("m","matrix", "Translate matrix", false, "", "string"); cmd.add( matrix_string ); TCLAP::ValueArg<double> scale("s","scale", "Scale the mesh", false, 0.0, "double"); cmd.add( scale ); TCLAP::ValueArg<std::string> translate_string("t","translate", "Translate the mesh", false, "", "string"); cmd.add( translate_string ); TCLAP::UnlabeledValueArg<std::string> input_filename( "input-filename", "Input file name", true, "", "InputFile" ); cmd.add( input_filename ); TCLAP::UnlabeledValueArg<std::string> output_filename( "output-filename", "Output file name", true, "", "OutputFile" ); cmd.add( output_filename ); cmd.parse( argc, argv ); viennamesh::logger().register_callback( new viennamesh::FileStreamCallback<viennamesh::FileStreamFormater>( log_filename.getValue() ) ); viennamesh::algorithm_handle reader( new viennamesh::io::mesh_reader() ); reader->set_input( "filename", input_filename.getValue() ); if (input_filetype.isSet() && (input_filetype.getValue() != "auto")) reader->set_input( "file_type", input_filetype.getValue() ); reader->run(); int dimension = lexical_cast<int>(reader->get_output("mesh")->get_property("geometric_dimension").first); viennamesh::algorithm_handle transform( new viennamesh::affine_transform() ); viennamesh::dynamic_point matrix(dimension*dimension, 0.0); for (int i = 0; i < dimension; ++i) matrix[dimension*i+i] = 1.0; if ( matrix_string.isSet() ) { matrix = stringtools::vector_from_string<double>( matrix_string.getValue() ); } else if (scale.isSet()) { for (int i = 0; i < dimension*dimension; ++i) matrix[i] *= scale.getValue(); } viennamesh::dynamic_point translate( dimension, 0.0 ); if ( translate_string.isSet() ) { translate = stringtools::vector_from_string<double>( translate_string.getValue() ); } transform->set_input( "mesh", reader->get_output("mesh") ); transform->set_output( "mesh", reader->get_output("mesh") ); transform->set_input( "matrix", matrix ); transform->set_input( "translate", translate ); transform->run(); viennamesh::algorithm_handle writer( new viennamesh::io::mesh_writer() ); writer->set_input( "mesh", transform->get_output("mesh") ); writer->set_input( "quantities", reader->get_output("quantities") ); writer->set_input( "filename", output_filename.getValue() ); if (output_filetype.isSet() && (output_filetype.getValue() != "auto")) writer->set_input( "file_type", output_filetype.getValue() ); writer->run(); } catch (TCLAP::ArgException &e) // catch any exceptions { std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; } return 0; }
blob_ty * lex_blob(string_ty *s) { return blob_alloc(s, input_filename(input), line_number - first); }
int gram_lex(void) { static char *paren; static long paren_max; long paren_depth; int c; long linum; int bol_was; int first_was; string_ty *s; int token; int start_of_line = 0; trace(("gram_lex()\n{\n")); for (;;) { linum = line_number; bol_was = bol; first_was = first; c = byte(); switch (c) { case INPUT_EOF: token = 0; goto done; case '\t': if (!bol_was || within_define) continue; sa_open(); for (;;) { c = byte(); switch (c) { case INPUT_EOF: case '\n': break; case ' ': case '\t': case '\f': #if __STDC__ >= 1 case '\v': #endif if (sa_data_length) sa_char(c); continue; default: sa_char(c); continue; } break; } gram_lval.lv_line = blob_alloc(sa_close(), input_filename(input), linum); token = COMMAND; goto done; case '#': sa_open(); more_comment: start_of_line = 1; for (;;) { c = byte(); switch (c) { case INPUT_EOF: case '\n': break; case '#': if (!start_of_line) sa_char(c); continue; case ' ': case '\t': case '\f': #if __STDC__ >= 1 case '\v': #endif if (!start_of_line) sa_char(' '); continue; default: sa_char(c); start_of_line = 0; continue; } break; } if (!first_was) { /* * If the comment did not start at the * beginning of the line, throw it away. */ byte_undo('\n'); continue; } token = COMMENT; if (c == '\n') { /* * Take a peek at the next character. * If it is '#', we have more comment. * If it is '\t', we have a code comment. */ c = byte(); if (c == '#') { sa_char('\n'); goto more_comment; } if (c == '\t') token = COMMAND_COMMENT; byte_undo(c); /* need to restore this state, too */ bol = 1; first = 1; colon_special = 1; } gram_lval.lv_line = blob_alloc(sa_close(), input_filename(input), linum); goto done; case ' ': case '\f': #if __STDC__ >= 1 case '\v': #endif break; case '\n': token = EOLN; goto done; case ';': if (!colon_special) goto normal; byte_undo('\t'); bol = 1; first = 1; colon_special = 1; token = EOLN; goto done; case ':': if (!colon_special) goto normal; c = byte(); if (c == ':') { token = COLON_COLON; goto done; } if (c == '=') { token = COLON_EQUALS; colon_special = 0; goto done; } byte_undo(c); token = COLON; goto done; case '=': token = EQUALS; colon_special = 0; goto done; case '+': c = byte(); if (c == '=') { token = PLUS_EQUALS; colon_special = 0; goto done; } byte_undo(c); c = '+'; /* fall through... */ default: normal: sa_open(); paren_depth = 0; for (;;) { switch (c) { case INPUT_EOF: case '\n': break; case ' ': case '\t': case '\f': #if __STDC__ >= 1 case '\v': #endif if (!within_define && !paren_depth) break; sa_char(c); c = byte(); continue; case ';': case ':': case '=': if (colon_special && !within_define && !paren_depth) break; sa_char(c); c = byte(); continue; default: sa_char(c); c = byte(); continue; case '(': sa_char(c); if (paren_depth >= paren_max) { paren_max = paren_max * 2 + 16; paren = mem_change_size(paren, paren_max); } paren[paren_depth++] = ')'; c = byte(); continue; case ')': case '}': sa_char(c); if (paren_depth && c == paren[paren_depth - 1]) --paren_depth; c = byte(); continue; case '{': sa_char(c); if (paren_depth >= paren_max) { paren_max = paren_max * 2 + 16; paren = mem_change_size(paren, paren_max); } paren[paren_depth++] = '}'; c = byte(); continue; } break; } byte_undo(c); s = sa_close(); if (first_was && (token = reserved(s)) != 0) { switch (token) { case DEFINE: str_free(s); ++within_define; break; case ENDDEF: str_free(s); --within_define; break; case IF: gram_lval.lv_line = blob_alloc(s, input_filename(input), linum); break; case VPATH: colon_special = 0; break; default: str_free(s); break; } goto done; } gram_lval.lv_line = blob_alloc(s, input_filename(input), linum); token = WORD; goto done; } } /* * here for all exits */ done: #ifdef DEBUG if (token == WORD || token == COMMENT || token == COMMAND) trace(("text = \"%s\";\n", gram_lval.lv_line->text->str_text)); #endif trace(("return %d;\n", token)); trace(("}\n")); return token; }
int main(int argc, char **argv) { try { TCLAP::CmdLine cmd("Clips elements based on a hyperplane", ' ', "1.0"); TCLAP::ValueArg<std::string> log_filename("l","logfile", "Log file name (default is convert.log)", false, "convert.log", "string"); cmd.add( log_filename ); TCLAP::ValueArg<std::string> input_filetype("","inputtype", "Input file type. Can be\nauto - ViennaMesh automatically detects the file format (default)\nvtk - for VTK files\nmesh - for Netgen .mesh files\npoly - for Tetgen .poly files\ndeva - for GTS deva files", false, "auto", "string"); cmd.add( input_filetype ); TCLAP::ValueArg<std::string> output_filetype("","outputtype", "Output file type. Can be\nauto - ViennaMesh automatically detects the file format (default)\nvtk - for VTK files\nvmesh - for Vienna vmesh files", false, "auto", "string"); cmd.add( output_filetype ); TCLAP::ValueArg<std::string> hyperplane_point_string("p","hyperplane_point", "Point of the clip hyperplane", true, "", "string"); cmd.add( hyperplane_point_string ); TCLAP::ValueArg<std::string> hyperplane_normal_string("n","hyperplane_normal", "Normal vector of the clip hyperplane", true, "", "string"); cmd.add( hyperplane_normal_string ); TCLAP::UnlabeledValueArg<std::string> input_filename( "input-filename", "Input file name", true, "", "InputFile" ); cmd.add( input_filename ); TCLAP::UnlabeledValueArg<std::string> output_filename( "output-filename", "Output file name", true, "", "OutputFile" ); cmd.add( output_filename ); cmd.parse( argc, argv ); viennamesh::logger().register_callback( new viennamesh::FileStreamCallback<viennamesh::FileStreamFormater>( log_filename.getValue() ) ); viennamesh::algorithm_handle reader( new viennamesh::io::mesh_reader() ); reader->set_input( "filename", input_filename.getValue() ); if (input_filetype.isSet() && (input_filetype.getValue() != "auto")) reader->set_input( "file_type", input_filetype.getValue() ); reader->run(); viennamesh::dynamic_point hyperplane_point = viennamesh::dynamic_point_from_string( hyperplane_point_string.getValue() ); viennamesh::dynamic_point hyperplane_normal = viennamesh::dynamic_point_from_string( hyperplane_normal_string.getValue() ); viennamesh::algorithm_handle clip( new viennamesh::hyperplane_clip() ); clip->set_input( "mesh", reader->get_output("mesh") ); clip->set_input( "hyperplane_point", hyperplane_point ); clip->set_input( "hyperplane_normal", hyperplane_normal ); clip->run(); viennamesh::algorithm_handle writer( new viennamesh::io::mesh_writer() ); writer->set_input( "mesh", clip->get_output("mesh") ); writer->set_input( "filename", output_filename.getValue() ); if (output_filetype.isSet() && (output_filetype.getValue() != "auto")) writer->set_input( "file_type", output_filetype.getValue() ); writer->run(); } catch (TCLAP::ArgException &e) // catch any exceptions { std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; } return 0; }
int main(int argc, char *argv[]) { int iOS = 0; char *pInputFile = NULL; char *pOutputFile = NULL; /* Figure out arguments. * [REQUIRED] First argument is input file. * [OPTIONAL] Second argument is output file. */ if(argc > 1) { FILE *pInputStream = NULL; FILE *pOutputStream = NULL; /* Form respective filenames. */ pInputFile = input_filename(argv[1]); pOutputFile = output_filename(pInputFile, argc > 2 ? argv[2] : NULL); if(pInputFile == NULL) { fprintf(stderr, "MANTOMAK: Unable to form input filename\n"); iOS = 1; } else { pInputStream = fopen(pInputFile, "rb"); if(pInputStream == NULL) { fprintf(stderr, "MANTOMAK: Unable to open input file %s\n", pInputFile); iOS = 1; } } if(pOutputFile == NULL) { fprintf(stderr, "MANTOMAK: Unable to form output filename\n"); iOS = 1; } else if(pInputStream != NULL) { pOutputStream = fopen(pOutputFile, "wt"); if(pOutputStream == NULL) { fprintf(stderr, "MANTOMAK: Unable to open output file %s\n", pOutputFile); iOS = 1; } } /* Only do the real processing if our error code is not * already set. */ if(iOS == 0) { iOS = input_to_output(pInputStream, pOutputStream); } if(pInputStream != NULL) { fclose(pInputStream); pInputStream = NULL; } if(pOutputStream != NULL) { fclose(pOutputStream); pOutputStream = NULL; } } else { help(); iOS = 1; } if(pInputFile) { free(pInputFile); pInputFile = NULL; } if(pOutputFile) { free(pOutputFile); pOutputFile = NULL; } return(iOS); }