Esempio n. 1
0
static void calculate_bounds_data(struct obs_scene_item *item,
		struct vec2 *origin, struct vec2 *scale,
		uint32_t *cx, uint32_t *cy)
{
	float    width         = (float)(*cx) * fabsf(scale->x);
	float    height        = (float)(*cy) * fabsf(scale->y);
	float    item_aspect   = width / height;
	float    bounds_aspect = item->bounds.x / item->bounds.y;
	uint32_t bounds_type   = item->bounds_type;
	float    width_diff, height_diff;

	if (item->bounds_type == OBS_BOUNDS_MAX_ONLY)
		if (width > item->bounds.x || height > item->bounds.y)
			bounds_type = OBS_BOUNDS_SCALE_INNER;

	if (bounds_type == OBS_BOUNDS_SCALE_INNER ||
	    bounds_type == OBS_BOUNDS_SCALE_OUTER) {
		bool  use_width = (bounds_aspect < item_aspect);
		float mul;

		if (item->bounds_type == OBS_BOUNDS_SCALE_OUTER)
			use_width = !use_width;

		mul = use_width ?
			item->bounds.x / width :
			item->bounds.y / height;

		vec2_mulf(scale, scale, mul);

	} else if (bounds_type == OBS_BOUNDS_SCALE_TO_WIDTH) {
		vec2_mulf(scale, scale, item->bounds.x / width);

	} else if (bounds_type == OBS_BOUNDS_SCALE_TO_HEIGHT) {
		vec2_mulf(scale, scale, item->bounds.y / height);

	} else if (bounds_type == OBS_BOUNDS_STRETCH) {
		scale->x = item->bounds.x / (float)(*cx);
		scale->y = item->bounds.y / (float)(*cy);
	}

	width       = (float)(*cx) * scale->x;
	height      = (float)(*cy) * scale->y;
	width_diff  = item->bounds.x - width;
	height_diff = item->bounds.y - height;
	*cx         = (uint32_t)item->bounds.x;
	*cy         = (uint32_t)item->bounds.y;

	add_alignment(origin, item->bounds_align,
			(int)-width_diff, (int)-height_diff);
}
Esempio n. 2
0
void add_alignment_patterns ( char **pattern, int version ) //add
{
	int i;
	int j;
	int x = 4; //begin of dark array

	for ( i = 0; i < alignment_patterns[version][0]; i++ )
	{
		for ( j = 0; j < alignment_patterns[version][0]; j++ )
		{
			if ( test_alignment ( pattern, alignment_patterns[version][i + 1], alignment_patterns[version][j + 1] ) == 0 )
				add_alignment( pattern, alignment_patterns[version][i + 1], alignment_patterns[version][j + 1] );
		}
	}

}
Esempio n. 3
0
static void update_item_transform(struct obs_scene_item *item)
{
	uint32_t        width         = obs_source_get_width(item->source);
	uint32_t        height        = obs_source_get_height(item->source);
	uint32_t        cx            = calc_cx(item, width);
	uint32_t        cy            = calc_cy(item, height);
	struct vec2     base_origin;
	struct vec2     origin;
	struct vec2     scale         = item->scale;
	struct calldata params;
	uint8_t         stack[128];

	if (os_atomic_load_long(&item->defer_update) > 0)
		return;

	width = cx;
	height = cy;

	vec2_zero(&base_origin);
	vec2_zero(&origin);

	/* ----------------------- */

	if (item->bounds_type != OBS_BOUNDS_NONE) {
		calculate_bounds_data(item, &origin, &scale, &cx, &cy);
	} else {
		cx = (uint32_t)((float)cx * scale.x);
		cy = (uint32_t)((float)cy * scale.y);
	}

	add_alignment(&origin, item->align, (int)cx, (int)cy);

	matrix4_identity(&item->draw_transform);
	matrix4_scale3f(&item->draw_transform, &item->draw_transform,
			scale.x, scale.y, 1.0f);
	matrix4_translate3f(&item->draw_transform, &item->draw_transform,
			-origin.x, -origin.y, 0.0f);
	matrix4_rotate_aa4f(&item->draw_transform, &item->draw_transform,
			0.0f, 0.0f, 1.0f, RAD(item->rot));
	matrix4_translate3f(&item->draw_transform, &item->draw_transform,
			item->pos.x, item->pos.y, 0.0f);

	item->output_scale = scale;

	/* ----------------------- */

	if (item->bounds_type != OBS_BOUNDS_NONE) {
		vec2_copy(&scale, &item->bounds);
	} else {
		scale.x = (float)width  * item->scale.x;
		scale.y = (float)height * item->scale.y;
	}

	add_alignment(&base_origin, item->align, (int)scale.x, (int)scale.y);

	matrix4_identity(&item->box_transform);
	matrix4_scale3f(&item->box_transform, &item->box_transform,
			scale.x, scale.y, 1.0f);
	matrix4_translate3f(&item->box_transform, &item->box_transform,
			-base_origin.x, -base_origin.y, 0.0f);
	matrix4_rotate_aa4f(&item->box_transform, &item->box_transform,
			0.0f, 0.0f, 1.0f, RAD(item->rot));
	matrix4_translate3f(&item->box_transform, &item->box_transform,
			item->pos.x, item->pos.y, 0.0f);

	/* ----------------------- */

	item->last_width  = width;
	item->last_height = height;

	calldata_init_fixed(&params, stack, sizeof(stack));
	calldata_set_ptr(&params, "scene", item->parent);
	calldata_set_ptr(&params, "item", item);
	signal_handler_signal(item->parent->source->context.signals,
			"item_transform", &params);
}
Esempio n. 4
0
static void recalculate_transition_matrix(obs_source_t *tr, size_t idx)
{
    obs_source_t *child;
    struct matrix4 mat;
    struct vec2 pos;
    struct vec2 scale;
    float tr_cx = (float)tr->transition_actual_cx;
    float tr_cy = (float)tr->transition_actual_cy;
    float source_cx;
    float source_cy;
    float tr_aspect = tr_cx / tr_cy;
    float source_aspect;
    enum obs_transition_scale_type scale_type = tr->transition_scale_type;

    lock_transition(tr);

    child = tr->transition_sources[idx];
    if (!child) {
        unlock_transition(tr);
        return;
    }

    source_cx = (float)obs_source_get_width(child);
    source_cy = (float)obs_source_get_height(child);
    unlock_transition(tr);

    if (source_cx == 0.0f || source_cy == 0.0f)
        return;

    source_aspect = source_cx / source_cy;

    if (scale_type == OBS_TRANSITION_SCALE_MAX_ONLY) {
        if (source_cx > tr_cx || source_cy > tr_cy) {
            scale_type = OBS_TRANSITION_SCALE_ASPECT;
        } else {
            scale.x = 1.0f;
            scale.y = 1.0f;
        }
    }

    if (scale_type == OBS_TRANSITION_SCALE_ASPECT) {
        bool use_width = tr_aspect < source_aspect;
        scale.x = scale.y = use_width ?
                            tr_cx / source_cx :
                            tr_cy / source_cy;

    } else if (scale_type == OBS_TRANSITION_SCALE_STRETCH) {
        scale.x = tr_cx / source_cx;
        scale.y = tr_cy / source_cy;
    }

    source_cx *= scale.x;
    source_cy *= scale.y;

    vec2_zero(&pos);
    add_alignment(&pos, tr->transition_alignment,
                  (int)(tr_cx - source_cx),
                  (int)(tr_cy - source_cy));

    matrix4_identity(&mat);
    matrix4_scale3f(&mat, &mat, scale.x, scale.y, 1.0f);
    matrix4_translate3f(&mat, &mat, pos.x, pos.y, 0.0f);
    matrix4_copy(&tr->transition_matrices[idx], &mat);
}
Esempio n. 5
0
File: main.cpp Progetto: rvaser/spoa
int main(int argc, char** argv) {

    std::int8_t m = 5;
    std::int8_t n = -4;
    std::int8_t g = -8;
    std::int8_t e = -6;
    std::int8_t q = -10;
    std::int8_t c = -4;

    std::uint8_t algorithm = 0;
    std::uint8_t result = 0;

    std::string dot_path = "";

    char opt;
    while ((opt = getopt_long(argc, argv, "m:n:g:e:q:c:l:r:d:h", options, nullptr)) != -1) {
        switch (opt) {
            case 'm': m = atoi(optarg); break;
            case 'n': n = atoi(optarg); break;
            case 'g': g = atoi(optarg); break;
            case 'e': e = atoi(optarg); break;
            case 'q': q = atoi(optarg); break;
            case 'c': c = atoi(optarg); break;
            case 'l': algorithm = atoi(optarg); break;
            case 'r': result = atoi(optarg); break;
            case 'd': dot_path = optarg; break;
            case 'v': std::cout << version << std::endl; return 0;
            case 'h': help(); return 0;
            default: return 1;
        }
    }

    if (optind >= argc) {
        std::cerr << "[spoa::] error: missing input file!" << std::endl;
        help();
        return 1;
    }

    std::string sequences_path = argv[optind];

    auto is_suffix = [](const std::string& src, const std::string& suffix) -> bool {
        if (src.size() < suffix.size()) {
            return false;
        }
        return src.compare(src.size() - suffix.size(), suffix.size(), suffix) == 0;
    };

    std::unique_ptr<bioparser::Parser<spoa::Sequence>> sparser = nullptr;

    if (is_suffix(sequences_path, ".fasta") || is_suffix(sequences_path, ".fa") ||
        is_suffix(sequences_path, ".fasta.gz") || is_suffix(sequences_path, ".fa.gz")) {
        sparser = bioparser::createParser<bioparser::FastaParser, spoa::Sequence>(
            sequences_path);
    } else if (is_suffix(sequences_path, ".fastq") || is_suffix(sequences_path, ".fq") ||
        is_suffix(sequences_path, ".fastq.gz") || is_suffix(sequences_path, ".fq.gz")) {
        sparser = bioparser::createParser<bioparser::FastqParser, spoa::Sequence>(
            sequences_path);
    } else {
        std::cerr << "[spoa::] error: file " << sequences_path <<
            " has unsupported format extension (valid extensions: .fasta, "
            ".fasta.gz, .fa, .fa.gz, .fastq, .fastq.gz, .fq, .fq.gz)!" <<
            std::endl;
        return 1;
    }

    std::unique_ptr<spoa::AlignmentEngine> alignment_engine;
    try {
        alignment_engine = spoa::createAlignmentEngine(
            static_cast<spoa::AlignmentType>(algorithm), m, n, g, e, q, c);
    } catch(std::invalid_argument& exception) {
        std::cerr << exception.what() << std::endl;
        return 1;
    }

    auto graph = spoa::createGraph();

    std::vector<std::unique_ptr<spoa::Sequence>> sequences;
    sparser->parse(sequences, -1);

    std::size_t max_sequence_size = 0;
    for (const auto& it: sequences) {
        max_sequence_size = std::max(max_sequence_size, it->data().size());
    }
    alignment_engine->prealloc(max_sequence_size, 4);

    for (const auto& it: sequences) {
        auto alignment = alignment_engine->align(it->data(), graph);
        try {
            graph->add_alignment(alignment, it->data(), it->quality());
        } catch(std::invalid_argument& exception) {
            std::cerr << exception.what() << std::endl;
            return 1;
        }
    }

    if (result == 0 || result == 2) {
        std::string consensus = graph->generate_consensus();
        std::cout << "Consensus (" << consensus.size() << ")" << std::endl;
        std::cout << consensus << std::endl;
    }

    if (result == 1 || result == 2) {
        std::vector<std::string> msa;
        graph->generate_multiple_sequence_alignment(msa);
        std::cout << "Multiple sequence alignment" << std::endl;
        for (const auto& it: msa) {
            std::cout << it << std::endl;
        }
    }

    graph->print_dot(dot_path);

    return 0;
}