void SampleRenderer::render_tile(CtxG&, Recti tile_rect, Recti tile_film_rect, Film& tile_film, Sampler& sampler) const { StatTimer t(TIMER_RENDER_TILE); Vec2 film_res(float(this->film->x_res), float(this->film->y_res)); for(int32_t y = tile_rect.p_min.y; y < tile_rect.p_max.y; ++y) { for(int32_t x = tile_rect.p_min.x; x < tile_rect.p_max.x; ++x) { sampler.start_pixel(); for(uint32_t s = 0; s < sampler.samples_per_pixel; ++s) { sampler.start_pixel_sample(); Vec2 pixel_pos = sampler.get_sample_2d(this->pixel_pos_idx); Vec2 film_pos = Vec2(float(x), float(y)) + pixel_pos; Ray ray(this->scene->camera->cast_ray(film_res, film_pos)); Spectrum radiance = this->get_radiance(*this->scene, ray, 0, sampler); assert(is_finite(radiance)); assert(is_nonnegative(radiance)); if(is_finite(radiance) && is_nonnegative(radiance)) { Vec2 tile_film_pos = film_pos - Vec2(float(tile_film_rect.p_min.x), float(tile_film_rect.p_min.y)); tile_film.add_sample(tile_film_pos, radiance); } } } } }
void b2g_library_init(b2g_library_t *library, const char *name, b2g_cutoff_lminlmax_t *cutoff_lminlmax, int PROPER_LENGTH) { assert(library && name && cutoff_lminlmax && is_nonnegative(PROPER_LENGTH)); b2g_library_stats_t stats = {PROPER_LENGTH, -1}; strcpy(library->name, name); library->cutoff_lminlmax = *cutoff_lminlmax; library->cutoff_data = stats; }
/* process command-line arguments */ int process_arguments (int argc, char **argv) { int c; int option = 0; static struct option longopts[] = { {"hostname", required_argument, 0, 'H'}, {"query_address", required_argument, 0, 'l'}, {"warning", required_argument, 0, 'w'}, {"critical", required_argument, 0, 'c'}, {"timeout", required_argument, 0, 't'}, {"dig-arguments", required_argument, 0, 'A'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {"help", no_argument, 0, 'h'}, {"record_type", required_argument, 0, 'T'}, {"expected_address", required_argument, 0, 'a'}, {"port", required_argument, 0, 'p'}, {"use-ipv4", no_argument, 0, '4'}, {"use-ipv6", no_argument, 0, '6'}, {0, 0, 0, 0} }; if (argc < 2) return ERROR; while (1) { c = getopt_long (argc, argv, "hVvt:l:H:w:c:T:p:a:A:46", longopts, &option); if (c == -1 || c == EOF) break; switch (c) { case 'h': /* help */ print_help (); exit (STATE_UNKNOWN); case 'V': /* version */ print_revision (progname, NP_VERSION); exit (STATE_UNKNOWN); case 'H': /* hostname */ host_or_die(optarg); dns_server = optarg; break; case 'p': /* server port */ if (is_intpos (optarg)) { server_port = atoi (optarg); } else { usage_va(_("Port must be a positive integer - %s"), optarg); } break; case 'l': /* address to lookup */ query_address = optarg; break; case 'w': /* warning */ if (is_nonnegative (optarg)) { warning_interval = strtod (optarg, NULL); } else { usage_va(_("Warning interval must be a positive integer - %s"), optarg); } break; case 'c': /* critical */ if (is_nonnegative (optarg)) { critical_interval = strtod (optarg, NULL); } else { usage_va(_("Critical interval must be a positive integer - %s"), optarg); } break; case 't': /* timeout */ if (is_intnonneg (optarg)) { timeout_interval = atoi (optarg); } else { usage_va(_("Timeout interval must be a positive integer - %s"), optarg); } break; case 'A': /* dig arguments */ dig_args = strdup(optarg); break; case 'v': /* verbose */ verbose = TRUE; break; case 'T': record_type = optarg; break; case 'a': expected_address = optarg; break; case '4': query_transport = "-4"; break; case '6': query_transport = "-6"; break; default: /* usage5 */ usage5(); } } c = optind; if (dns_server == NULL) { if (c < argc) { host_or_die(argv[c]); dns_server = argv[c]; } else { if (strcmp(query_transport,"-6") == 0) dns_server = strdup("::1"); else dns_server = strdup ("127.0.0.1"); } } return validate_arguments (); }
/* process command-line arguments */ int process_arguments (int argc, char **argv) { int c; char* temp; int option = 0; static struct option longopts[] = { {"hostname", required_argument, 0, 'H'}, {"expect", required_argument, 0, 'e'}, {"critical", required_argument, 0, 'c'}, {"warning", required_argument, 0, 'w'}, {"timeout", required_argument, 0, 't'}, {"port", required_argument, 0, 'p'}, {"from", required_argument, 0, 'f'}, {"fqdn", required_argument, 0, 'F'}, {"authtype", required_argument, 0, 'A'}, {"authuser", required_argument, 0, 'U'}, {"authpass", required_argument, 0, 'P'}, {"command", required_argument, 0, 'C'}, {"response", required_argument, 0, 'R'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {"use-ipv4", no_argument, 0, '4'}, {"use-ipv6", no_argument, 0, '6'}, {"help", no_argument, 0, 'h'}, {"starttls",no_argument,0,'S'}, {"certificate",required_argument,0,'D'}, {"ignore-quit-failure",no_argument,0,'q'}, {0, 0, 0, 0} }; if (argc < 2) return ERROR; for (c = 1; c < argc; c++) { if (strcmp ("-to", argv[c]) == 0) strcpy (argv[c], "-t"); else if (strcmp ("-wt", argv[c]) == 0) strcpy (argv[c], "-w"); else if (strcmp ("-ct", argv[c]) == 0) strcpy (argv[c], "-c"); } while (1) { c = getopt_long (argc, argv, "+hVv46t:p:f:e:c:w:H:C:R:SD:F:A:U:P:q", longopts, &option); if (c == -1 || c == EOF) break; switch (c) { case 'H': /* hostname */ if (is_host (optarg)) { server_address = optarg; } else { usage2 (_("Invalid hostname/address"), optarg); } break; case 'p': /* port */ if (is_intpos (optarg)) server_port = atoi (optarg); else usage4 (_("Port must be a positive integer")); break; case 'F': /* localhostname */ localhostname = strdup(optarg); break; case 'f': /* from argument */ from_arg = optarg + strspn(optarg, "<"); from_arg = strndup(from_arg, strcspn(from_arg, ">")); send_mail_from = 1; break; case 'A': authtype = optarg; use_ehlo = TRUE; break; case 'U': authuser = optarg; break; case 'P': authpass = optarg; break; case 'e': /* server expect string on 220 */ server_expect = optarg; break; case 'C': /* commands */ if (ncommands >= command_size) { command_size+=8; commands = realloc (commands, sizeof(char *) * command_size); if (commands == NULL) die (STATE_UNKNOWN, _("Could not realloc() units [%d]\n"), ncommands); } commands[ncommands] = (char *) malloc (sizeof(char) * 255); strncpy (commands[ncommands], optarg, 255); ncommands++; break; case 'R': /* server responses */ if (nresponses >= response_size) { response_size += 8; responses = realloc (responses, sizeof(char *) * response_size); if (responses == NULL) die (STATE_UNKNOWN, _("Could not realloc() units [%d]\n"), nresponses); } responses[nresponses] = (char *) malloc (sizeof(char) * 255); strncpy (responses[nresponses], optarg, 255); nresponses++; break; case 'c': /* critical time threshold */ if (!is_nonnegative (optarg)) usage4 (_("Critical time must be a positive")); else { critical_time = strtod (optarg, NULL); check_critical_time = TRUE; } break; case 'w': /* warning time threshold */ if (!is_nonnegative (optarg)) usage4 (_("Warning time must be a positive")); else { warning_time = strtod (optarg, NULL); check_warning_time = TRUE; } break; case 'v': /* verbose */ verbose++; break; case 'q': ignore_send_quit_failure++; /* ignore problem sending QUIT */ break; case 't': /* timeout */ if (is_intnonneg (optarg)) { socket_timeout = atoi (optarg); } else { usage4 (_("Timeout interval must be a positive integer")); } break; case 'S': /* starttls */ use_ssl = TRUE; use_ehlo = TRUE; break; case 'D': /* Check SSL cert validity */ #ifdef USE_OPENSSL if ((temp=strchr(optarg,','))!=NULL) { *temp='\0'; if (!is_intnonneg (optarg)) usage2 ("Invalid certificate expiration period", optarg); days_till_exp_warn = atoi(optarg); *temp=','; temp++; if (!is_intnonneg (temp)) usage2 (_("Invalid certificate expiration period"), temp); days_till_exp_crit = atoi (temp); } else { days_till_exp_crit=0; if (!is_intnonneg (optarg)) usage2 ("Invalid certificate expiration period", optarg); days_till_exp_warn = atoi (optarg); } check_cert = TRUE; #else usage (_("SSL support not available - install OpenSSL and recompile")); #endif break; case '4': address_family = AF_INET; break; case '6': #ifdef USE_IPV6 address_family = AF_INET6; #else usage4 (_("IPv6 support not available")); #endif break; case 'V': /* version */ print_revision (progname, NP_VERSION); exit (STATE_OK); case 'h': /* help */ print_help (); exit (STATE_OK); case '?': /* help */ usage5 (); } } c = optind; if (server_address == NULL) { if (argv[c]) { if (is_host (argv[c])) server_address = argv[c]; else usage2 (_("Invalid hostname/address"), argv[c]); } else { xasprintf (&server_address, "127.0.0.1"); } } if (server_expect == NULL) server_expect = strdup (SMTP_EXPECT); if (mail_command == NULL) mail_command = strdup("MAIL "); if (from_arg==NULL) from_arg = strdup(" "); return validate_arguments (); }
/* process command-line arguments */ int process_arguments (int argc, char **argv) { int c; int option = 0; static struct option longopts[] = { {"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'V'}, {"timeout", required_argument, 0, 't'}, {"critical", required_argument, 0, 'c'}, {"warning", required_argument, 0, 'w'}, {"hostname", required_argument, 0, 'H'}, {"logname", required_argument, 0, 'l'}, {"password", required_argument, 0, 'p'}, {"authorization", required_argument, 0, 'a'}, {"port", required_argument, 0, 'P'}, {"database", required_argument, 0, 'd'}, {"verbose", no_argument, 0, 'v'}, {0, 0, 0, 0} }; while (1) { c = getopt_long (argc, argv, "hVt:c:w:H:P:d:l:p:a:v", longopts, &option); if (c == EOF) break; switch (c) { case '?': /* usage */ usage5 (); case 'h': /* help */ print_help (); exit (STATE_OK); case 'V': /* version */ print_revision (progname, NP_VERSION); exit (STATE_OK); case 't': /* timeout period */ if (!is_integer (optarg)) usage2 (_("Timeout interval must be a positive integer"), optarg); else timeout_interval = atoi (optarg); break; case 'c': /* critical time threshold */ if (!is_nonnegative (optarg)) usage2 (_("Critical threshold must be a positive integer"), optarg); else tcrit = strtod (optarg, NULL); break; case 'w': /* warning time threshold */ if (!is_nonnegative (optarg)) usage2 (_("Warning threshold must be a positive integer"), optarg); else twarn = strtod (optarg, NULL); break; case 'H': /* host */ if (!is_host (optarg)) usage2 (_("Invalid hostname/address"), optarg); else pghost = optarg; break; case 'P': /* port */ if (!is_integer (optarg)) usage2 (_("Port must be a positive integer"), optarg); else pgport = optarg; break; case 'd': /* database name */ if (!is_pg_dbname (optarg)) /* checks length and valid chars */ usage2 (_("Database name is not valid"), optarg); else /* we know length, and know optarg is terminated, so us strcpy */ strcpy (dbName, optarg); break; case 'l': /* login name */ if (!is_pg_logname (optarg)) usage2 (_("User name is not valid"), optarg); else pguser = optarg; break; case 'p': /* authentication password */ case 'a': pgpasswd = optarg; break; case 'v': verbose++; break; } } return validate_arguments (); }
inline bool is_nonnegative(const RgbSpectrum& s) { return is_nonnegative(s.rgb); }
// num_skipped counts the number of reads that do not show up in output. Used by validate to account for all the input reads. b2g_error_t params2gasv_input(char *BAM_PATH, char *OUTPUT_PREFIX, int MAPPING_QUALITY, int WRITE_CONCORDANT, int WRITE_LOWQ, int LOW_MEMORY, int AMBIGUOUS, int LIB_SEP, int VERBOSE, int CUTOFF_X, int CUTOFF_Y, b2g_cutoff_lminlmax_mode_t CUTOFF_MODE, char *CUTOFF_NAME, int PROPER_LENGTH, int USE_NUMBER_READS, int DEBUG_LEVEL, int WRITE_SPLITREAD, int MIN_ALIGNED_PCT, char *CHROMOSOME_NAMING, b2g_platform_t PLATFORM, int VALIDATION_STRINGENCY, int GASV_PRO, int IGNORE_DUPLICATES, int QNAME_SORTED, int SPLIT_BY_CHROMOSOME, unsigned int *num_skipped) { assert(BAM_PATH && OUTPUT_PREFIX && in_range(MAPPING_QUALITY, 0, 255) && is_bool(WRITE_CONCORDANT) && is_bool(WRITE_LOWQ) && is_bool(LOW_MEMORY) && is_bool(AMBIGUOUS) && is_bool(LIB_SEP) && is_bool(VERBOSE) && CUTOFF_MODE && (FILENAME != CUTOFF_MODE || CUTOFF_NAME) && is_nonnegative(PROPER_LENGTH) && is_positive(USE_NUMBER_READS) && is_bool(WRITE_SPLITREAD) && in_range(MIN_ALIGNED_PCT, 50, 100) && is_bool(GASV_PRO) && is_bool(IGNORE_DUPLICATES) && is_bool(SPLIT_BY_CHROMOSOME)); b2g_error_t ERR = B2GERR_NO_ERROR; hash_t *pairtable = NULL; samfile_t *in = NULL, *lowq_file = NULL, *split_file = NULL; FILE *chromosome_naming_file = NULL, *cutoff_file = NULL, *info_file = NULL, *gasv_file = NULL, *gasvpro_file = NULL; unsigned long GENOME_LENGTH = DEFAULT_GENOME_LENGTH; if (GASV_PRO && !WRITE_CONCORDANT) { if (VERBOSE) printf("-WRITE_CONCORDANT is required for -GASVPRO output. Automatically enabling.\n\n"); WRITE_CONCORDANT = 1; } if (AMBIGUOUS && !QNAME_SORTED) { if (VERBOSE) printf("-QNAME_SORTED is required for -AMBIGUOUS output. Automatically enabling.\n\n"); QNAME_SORTED = 1; } if (FILENAME == CUTOFF_MODE && !LIB_SEP) { if (VERBOSE) printf("-LIB_SEP sep is required for -CUTOFF_LMINLMAX FILE=... output. Automatically enabling.\n\n"); LIB_SEP = 1; } if (AMBIGUOUS && (WRITE_LOWQ || WRITE_SPLITREAD)) { if (VERBOSE) printf("-WRITE_LOWQ and -WRITE_SPLITREAD behavior are undefined for -AMBIGUOUS. Automatically disabling\n\n"); WRITE_LOWQ = WRITE_SPLITREAD = 0; } // Open all external resources and abort if failure. if ((ERR = _open_files(&in, &chromosome_naming_file, &cutoff_file, &lowq_file, &split_file, &info_file, &gasv_file, &gasvpro_file, BAM_PATH, OUTPUT_PREFIX, CHROMOSOME_NAMING, CUTOFF_MODE, CUTOFF_NAME, WRITE_LOWQ, WRITE_SPLITREAD, GASV_PRO))) return _cleanup(in, chromosome_naming_file, cutoff_file, lowq_file, split_file, info_file, gasv_file, gasvpro_file, pairtable, ERR); // Allocate hash table struct stat st; stat(BAM_PATH, &st); if (!(pairtable = hash(!QNAME_SORTED * ((st.st_size / B2G_HASH_SIZE) / (LOW_MEMORY ? MAX_BAM_FILES : 1))))) return _cleanup(in, chromosome_naming_file, cutoff_file, lowq_file, split_file, info_file, gasv_file, gasvpro_file, pairtable, B2GERR_OUT_OF_MEMORY); // Calculate required space for bam_header metadata, int NUM_CHROMOSOMES, NUM_READGROUPS, NUM_LIBRARIES; b2g_bam_header_counts(in->header, &NUM_CHROMOSOMES, &NUM_READGROUPS, &NUM_LIBRARIES, &LIB_SEP, PROPER_LENGTH); // allocate memory for said data, b2g_cutoff_lminlmax_t cutoff_lminlmax = {CUTOFF_MODE, CUTOFF_X , CUTOFF_Y, CUTOFF_NAME}; int chromosome_numbers[NUM_CHROMOSOMES]; b2g_chromosomes_t chromosomes = {NUM_CHROMOSOMES, chromosome_numbers}; b2g_readgroup2library_t rgs2libs[NUM_READGROUPS]; b2g_library_t libs[NUM_LIBRARIES]; b2g_libraries_t libraries = {NUM_READGROUPS, NUM_LIBRARIES, &rgs2libs[0], &libs[0]}; // and read the header into that memory. if ((ERR = b2g_bam_header_read(in->header, &chromosomes, &libraries, &GENOME_LENGTH, cutoff_lminlmax, chromosome_naming_file, cutoff_file, LIB_SEP, USE_NUMBER_READS, PROPER_LENGTH, VERBOSE))) return _cleanup(in, chromosome_naming_file, cutoff_file, lowq_file, split_file, info_file, gasv_file, gasvpro_file, pairtable, ERR); // Do all the main program logic of splitting the bam file, sorting the contents, merging the final output, and dumping the statistics. if ((ERR = _split_sort_merge_dump(BAM_PATH, OUTPUT_PREFIX, MAPPING_QUALITY, WRITE_CONCORDANT, WRITE_LOWQ, LOW_MEMORY, AMBIGUOUS, LIB_SEP, VERBOSE, CUTOFF_X, CUTOFF_Y, CUTOFF_MODE, CUTOFF_NAME, PROPER_LENGTH, USE_NUMBER_READS, DEBUG_LEVEL, WRITE_SPLITREAD, MIN_ALIGNED_PCT, CHROMOSOME_NAMING, PLATFORM, GASV_PRO, IGNORE_DUPLICATES, lowq_file, split_file, &libraries, &chromosomes, pairtable, info_file, gasv_file, gasvpro_file, GENOME_LENGTH, QNAME_SORTED, SPLIT_BY_CHROMOSOME, num_skipped))) return _cleanup(in, chromosome_naming_file, cutoff_file, lowq_file, split_file, info_file, gasv_file, gasvpro_file, pairtable, ERR); return _cleanup(in, chromosome_naming_file, cutoff_file, lowq_file, split_file, info_file, gasv_file, gasvpro_file, pairtable, B2GERR_NO_ERROR); }