예제 #1
0
/** callback called by Grid::draw_row_names() to draw an individual row name  */
void
Canvas::draw_row_name ( int y, const char *name, int color )
{
    bool draw = m.draw;
    bool clear = false;

    y = ntr( y );

    if ( ! m.row_compact && ! name )
        clear = true;

    y -= m.vp->y;

    int bx = m.origin_x;
    int by = m.origin_y + m.margin_top + y * m.div_h;
    int bw = min( m.margin_left, m.width / 8 );
    int bh = m.div_h;

    if ( y < 0 || y >= m.vp->h )
        draw = false;

    if ( clear && draw )
        gui_clear_area( bx, by, bw, bh );
    else
        m.margin_left = max( m.margin_left, gui_draw_string( bx, by,
                                                             bw, bh,
                                                             color,
                                                             name,
                                                             draw ) );
}
예제 #2
0
void
Canvas::end_cursor ( int x, int y )
{
    if ( ! grid_pos( &x, &y ) )
        return;

    m.ruler_drawn = false;

    m.p2 = x;
    m.p4 = ntr( y );

    _lr();

    signal_draw();
}
예제 #3
0
display::Geometries get_rigid_body_derivative_geometries(
    Model *m, ParticleIndex pi) {
    RigidBody d(m, pi);
    display::Geometries ret;
    Particles ms = get_as<Particles>(d.get_rigid_members());
    algebra::Transformation3D otr =
        d.get_reference_frame().get_transformation_to();
    algebra::VectorD<4> rderiv = d.get_rotational_derivatives();
    algebra::Vector3D tderiv = d.get_derivatives();
    algebra::VectorD<4> rot = otr.get_rotation().get_quaternion();
    IMP_LOG_TERSE("Old rotation was " << rot << std::endl);
    Float scale = .1;
    algebra::VectorD<4> dv = rderiv;
    if (dv.get_squared_magnitude() > 0.00001) {
        dv = scale * dv.get_unit_vector();
    }
    rot += dv;
    rot = rot.get_unit_vector();
    algebra::Rotation3D r(rot[0], rot[1], rot[2], rot[3]);
    IMP_LOG_TERSE("Derivative was " << tderiv << std::endl);
    IMP_LOG_TERSE("New rotation is " << rot << std::endl);
    FloatRange xr =
        d.get_particle()->get_model()->get_range(core::XYZ::get_xyz_keys()[0]);
    Float wid = xr.second - xr.first;
    algebra::Vector3D stderiv = scale * tderiv * wid;
    algebra::Transformation3D ntr(
        algebra::Rotation3D(rot[0], rot[1], rot[2], rot[3]),
        stderiv + otr.get_translation());
    for (unsigned int i = 0; i < ms.size(); ++i) {
        core::RigidMember dm(ms[i]);
        display::SegmentGeometry *tr = new display::SegmentGeometry(
            algebra::Segment3D(dm.get_coordinates(), dm.get_coordinates() + tderiv),
            /*xyzcolor_*/
            display::Color(1, 0, 0));
        ret.push_back(tr);
        algebra::Vector3D ic =
            r.get_rotated(dm.get_internal_coordinates()) + d.get_coordinates();
        display::SegmentGeometry *rtr = new display::SegmentGeometry(
            algebra::Segment3D(dm.get_coordinates(), ic), display::Color(0, 1, 0));
        ret.push_back(rtr);
        display::SegmentGeometry *nrtr = new display::SegmentGeometry(
            algebra::Segment3D(dm.get_coordinates(),
                               ntr.get_transformed(dm.get_internal_coordinates())),
            display::Color(0, 0, 1));
        ret.push_back(nrtr);
    }
    return ret;
}
예제 #4
0
/** "draw" a shape in the backbuffer */
void
Canvas::draw_shape ( int x, int y, int shape, int state, int color, bool selected )
{
    y = ntr( y );

    if ( y < 0 )
        return;

    // adjust for viewport.

    x -= m.vp->x;
    y -= m.vp->y;

    if ( x < 0 || y < 0 || x >= m.vp->w || y >= m.vp->h )
        return;

    m.current[ x ][ y ].shape = shape;
    m.current[ x ][ y ].color = color;
    m.current[ x ][ y ].state = (uint)m.vp->x + x > m.grid->ts_to_x( m.grid->length() ) ? PARTIAL : state;
    if ( selected )
        m.current[ x ][ y ].state = SELECTED;
    m.current[ x ][ y ].flags = 0;
}
예제 #5
0
cv::Mat BoxFilter::perform(std::vector<cv::Mat> in_d){

    assert(in_d.size() > 0);
    assert(in_d[0].type() == CV_64F);

    int R = in_d[0].rows;
    int C = in_d[0].cols;
    int Z = in_d.size();

    cv::Mat out = cv::Mat::zeros(R, C, CV_64F);

    for (int b = 0; b < _boxes.size(); b++){

        int l_start = 0;    // near layer = 0
        int l_end = Z - 1;  // far layer = last

        // Near layers

        cv::Mat ntl(R - _shape[0], C - _shape[1], CV_64F, cv::Scalar::all(0.0));
        cv::Mat ntr(R - _shape[0], C - _shape[1], CV_64F, cv::Scalar::all(0.0));
        cv::Mat nbl(R - _shape[0], C - _shape[1], CV_64F, cv::Scalar::all(0.0));
        cv::Mat nbr(R - _shape[0], C - _shape[1], CV_64F, cv::Scalar::all(0.0));

        cv::Range rs[2];

        if (l_start > 0){

            rs[0] = cv::Range(_boxes[b].tl().y, R - _shape[0] + _boxes[b].tl().y);
            rs[1] = cv::Range(_boxes[b].tl().x, C - _shape[1] + _boxes[b].tl().x);

            ntl = cv::Mat(in_d[l_start-1], rs); // ntl: Near-Top-Left layer, -1 because near layer of box filtering process

            rs[0] = cv::Range(_boxes[b].tl().y, R - _shape[0] + _boxes[b].tl().y);
            rs[1] = cv::Range(_boxes[b].br().x, C - _shape[1] + _boxes[b].br().x);

            ntr = cv::Mat(in_d[l_start-1], rs); // ntr: Near-Top-Right layer

            rs[0] = cv::Range(_boxes[b].br().y, R - _shape[0] + _boxes[b].br().y);
            rs[1] = cv::Range(_boxes[b].tl().x, C - _shape[1] + _boxes[b].tl().x);

            nbl = cv::Mat(in_d[l_start-1], rs); // nbl: Near-Bottom-Left layer

            rs[0] = cv::Range(_boxes[b].br().y, R - _shape[0] + _boxes[b].br().y);
            rs[1] = cv::Range(_boxes[b].br().x, C - _shape[1] + _boxes[b].br().x);

            nbr = cv::Mat(in_d[l_start-1], rs);   // nbr: Near-Bottom-Right layer
        }
        else{
            ntl = cv::Mat(R - _shape[0], C - _shape[1], CV_64F, cv::Scalar::all(0.0));
            ntr = cv::Mat(R - _shape[0], C - _shape[1], CV_64F, cv::Scalar::all(0.0));
            nbl = cv::Mat(R - _shape[0], C - _shape[1], CV_64F, cv::Scalar::all(0.0));
            nbr = cv::Mat(R - _shape[0], C - _shape[1], CV_64F, cv::Scalar::all(0.0));
        }

        // Far layers

        rs[0] = cv::Range(_boxes[b].tl().y, R - _shape[0] + _boxes[b].tl().y);
        rs[1] = cv::Range(_boxes[b].tl().x, C - _shape[1] + _boxes[b].tl().x);

        cv::Mat ftl = cv::Mat(in_d[l_end], rs);   // ftl: Far-Top-Left layer

        rs[0] = cv::Range(_boxes[b].tl().y, R - _shape[0] + _boxes[b].tl().y);
        rs[1] = cv::Range(_boxes[b].br().x, C - _shape[1] + _boxes[b].br().x);

        cv::Mat ftr = cv::Mat(in_d[l_end], rs);   // ftr: Far-Top-Right layer

        rs[0] = cv::Range(_boxes[b].br().y, R - _shape[0] + _boxes[b].br().y);
        rs[1] = cv::Range(_boxes[b].tl().x, C - _shape[1] + _boxes[b].tl().x);
        rs[2] = cv::Range(l_end, l_end + 1);

        cv::Mat fbl = cv::Mat(in_d[l_end], rs);    // fbl: Far-Bottom-Left layer

        rs[0] = cv::Range(_boxes[b].br().y, R - _shape[0] + _boxes[b].br().y);
        rs[1] = cv::Range(_boxes[b].br().x, C - _shape[1] + _boxes[b].br().x);
        rs[2] = cv::Range(l_end, l_end + 1);

        cv::Mat fbr = cv::Mat(in_d[l_end], rs);    // fbr: Far-Bottom-Right layer

        // apply zero padding
        int pad_left = ceil((double) _shape[1] / 2.0);
        int pad_top = ceil((double) _shape[0] / 2.0);
        int pad_right = _shape[1]/2;
        int pad_bottom = _shape[0]/2;

        cv::Mat ntl_p(R, C, CV_64F);    // ntl: Near-Top-Left layer
        cv::copyMakeBorder(ntl, ntl_p, pad_top + 1, pad_bottom - 1,
                       pad_left + 1, pad_right - 1, cv::BORDER_CONSTANT, cv::Scalar::all(0));

        cv::Mat ntr_p(R, C, CV_64F);    // ntr: Near-Top-Right layer
        cv::copyMakeBorder(ntr, ntr_p, pad_top + 1, pad_bottom - 1,
                       pad_left, pad_right, cv::BORDER_CONSTANT, cv::Scalar::all(0));

        cv::Mat nbl_p(R, C, CV_64F);    // nbl: Near-Bottom-Left layer
        cv::copyMakeBorder(nbl, nbl_p, pad_top, pad_bottom,
                       pad_left + 1, pad_right - 1, cv::BORDER_CONSTANT, cv::Scalar::all(0));

        cv::Mat nbr_p(R, C, CV_64F);    // nbr: Near-Bottom-Right layer
        cv::copyMakeBorder(nbr, nbr_p, pad_top, pad_bottom,
                       pad_left, pad_right, cv::BORDER_CONSTANT, cv::Scalar::all(0));

        cv::Mat ftl_p(R, C, CV_64F);    // ftl: Far-Top-Left layer
        cv::copyMakeBorder(ftl, ftl_p, pad_top + 1, pad_bottom - 1,
                       pad_left + 1, pad_right - 1, cv::BORDER_CONSTANT, cv::Scalar::all(0));

        cv::Mat ftr_p(R, C, CV_64F);    // ftr: Far-Top-Right layer
        cv::copyMakeBorder(ftr, ftr_p, pad_top + 1, pad_bottom - 1,
                       pad_left, pad_right, cv::BORDER_CONSTANT, cv::Scalar::all(0));

        cv::Mat fbl_p(R, C, CV_64F);    // fbl: Far-Bottom-Left layer
        cv::copyMakeBorder(fbl, fbl_p, pad_top, pad_bottom,
                       pad_left + 1, pad_right - 1, cv::BORDER_CONSTANT, cv::Scalar::all(0));

        cv::Mat fbr_p(R, C, CV_64F);    // fbr: Far-Bottom-Right layer
        cv::copyMakeBorder(fbr, fbr_p, pad_top, pad_bottom,
                       pad_left, pad_right, cv::BORDER_CONSTANT, cv::Scalar::all(0));


        // obtain filtered image with a weighted sum of layers
        // equation for box filtering
        out += _boxes[b].v() * (fbr_p - nbr_p - ftr_p - fbl_p + ftl_p + nbl_p + ntr_p - ntl_p);

    }

//    cv::Range ran[2];
//    ran[0] = cv::Range(_shape[0], out.rows - shape[0]);
//    ran[1] = cv::Range(_shape[1], out.cols - shape[1]);
    return out(cv::Range(_shape[0]/2 + 1, out.rows - _shape[0]/2 - 1), cv::Range(_shape[1]/2 + 1, out.cols - _shape[1]/2 - 1));
}