template <bool align> void BgrToYuv422p(const uint8_t * bgr, size_t width, size_t height, size_t bgrStride, uint8_t * y, size_t yStride,
            uint8_t * u, size_t uStride, uint8_t * v, size_t vStride)
        {
            assert((width % 2 == 0) && (width >= DA));
            if (align)
            {
                assert(Aligned(y) && Aligned(yStride) && Aligned(u) && Aligned(uStride));
                assert(Aligned(v) && Aligned(vStride) && Aligned(bgr) && Aligned(bgrStride));
            }

            size_t alignedWidth = AlignLo(width, DA);
            const size_t A6 = A * 6;
            for (size_t row = 0; row < height; ++row)
            {
                Storer<align> _y(y), _u(u), _v(v);
                BgrToYuv422p<align, true>(bgr, _y, _u, _v);
                for (size_t col = DA, colBgr = A6; col < alignedWidth; col += DA, colBgr += A6)
                    BgrToYuv422p<align, false>(bgr + colBgr, _y, _u, _v);
                Flush(_y, _u, _v);
                if (width != alignedWidth)
                {
                    size_t offset = width - DA;
                    Storer<false> _y(y + offset), _u(u + offset / 2), _v(v + offset / 2);
                    BgrToYuv422p<false, true>(bgr + offset * 3, _y, _u, _v);
                    Flush(_y, _u, _v);
                }
                y += yStride;
                u += uStride;
                v += vStride;
                bgr += bgrStride;
            }
        }
        template <bool align> void BgrToYuv444p(const uint8_t * bgr, size_t width, size_t height, size_t bgrStride, uint8_t * y, size_t yStride,
            uint8_t * u, size_t uStride, uint8_t * v, size_t vStride)
        {
            assert(width >= A);
            if (align)
            {
                assert(Aligned(y) && Aligned(yStride) && Aligned(u) && Aligned(uStride));
                assert(Aligned(v) && Aligned(vStride) && Aligned(bgr) && Aligned(bgrStride));
            }

            size_t alignedWidth = AlignLo(width, A);
            const size_t A3 = A * 3;
            for (size_t row = 0; row < height; ++row)
            {
                Storer<align> _y(y), _u(u), _v(v);
                BgrToYuv444p<align, true>(bgr, _y, _u, _v);
                for (size_t col = A, colBgr = A3; col < alignedWidth; col += A, colBgr += A3)
                    BgrToYuv444p<align, false>(bgr + colBgr, _y, _u, _v);
                Flush(_y, _u, _v);
                if (width != alignedWidth)
                {
                    size_t col = width - A;
                    Storer<false> _y(y + col), _u(u + col), _v(v + col);
                    BgrToYuv444p<false, true>(bgr + col * 3, _y, _u, _v);
                    Flush(_y, _u, _v);
                }
                y += yStride;
                u += uStride;
                v += vStride;
                bgr += bgrStride;
            }
        }
示例#3
0
Real SphericalBesselGenerator::y(const UnsignedInteger n, const Real z) const
{
    if(n <= 2)
    {
        return _y_smalln(n, z);
    }

    if(n > getMaxNY())
    {
        return _y(n, z);
    }
    
    const sb_table::Table* table(getSYTable(n));
    assert(table != 0);
    
    const Real minz(table->x_start + table->delta_x * 3);
    const Real maxz(table->x_start + table->delta_x * (table->N-3));
    
    if(z >= minz && z < maxz)
    {
        return _y_table(n, z);
    }
    else
    {
        return _y(n, z);
    }
}
示例#4
0
文件: sasio.cpp 项目: dww100/sasmol
///
/// @par Detailed description
/// ...
/// @param [in, out] (param1) ...
/// @return ...
/// @note ...
void
sasio::Files::
resize_array()
{

    int nf = _number_of_frames() ;

    Eigen::Array<float,Eigen::Dynamic,Eigen::Dynamic> temp_x(_natoms(),nf) ;
    Eigen::Array<float,Eigen::Dynamic,Eigen::Dynamic> temp_y(_natoms(),nf) ;
    Eigen::Array<float,Eigen::Dynamic,Eigen::Dynamic> temp_z(_natoms(),nf) ;

    temp_x = _x() ;
    temp_y = _y() ;
    temp_z = _z() ;

    _x().resize(_natoms(),_number_of_frames()+1) ;
    _y().resize(_natoms(),_number_of_frames()+1) ;
    _z().resize(_natoms(),_number_of_frames()+1) ;

    // see: slice.cpp in retired_ideas/play_with_eigen/
    //    mat1.block(i,j,rows,cols)
    //       a.block(0, 0, 3, 1) = b.block(0,0,3,1) ;

    _x().block(0, 0, _natoms(), nf) = temp_x.block(0,0,_natoms(),nf) ;
    _y().block(0, 0, _natoms(), nf) = temp_y.block(0,0,_natoms(),nf) ;
    _z().block(0, 0, _natoms(), nf) = temp_z.block(0,0,_natoms(),nf) ;

    return ;
}
示例#5
0
wkt_generator<OutputIterator, Geometry>::wkt_generator(bool single)
    : wkt_generator::base_type(wkt)
{
    boost::spirit::karma::uint_type uint_;
    boost::spirit::karma::_val_type _val;
    boost::spirit::karma::_1_type _1;
    boost::spirit::karma::lit_type lit;
    boost::spirit::karma::_a_type _a;
    boost::spirit::karma::_b_type _b;
    boost::spirit::karma::_c_type _c;
    boost::spirit::karma::_r1_type _r1;
    boost::spirit::karma::eps_type eps;
    boost::spirit::karma::string_type kstring;

    wkt = point | linestring | polygon
        ;

    point = &uint_(mapnik::geometry_type::types::Point)[_1 = _type(_val)]
        << kstring[ phoenix::if_ (single) [_1 = "Point("]
                   .else_[_1 = "("]]
        << point_coord [_1 = _first(_val)] << lit(')')
        ;

    linestring = &uint_(mapnik::geometry_type::types::LineString)[_1 = _type(_val)]
        << kstring[ phoenix::if_ (single) [_1 = "LineString("]
                   .else_[_1 = "("]]
        << coords
        << lit(')')
        ;

    polygon = &uint_(mapnik::geometry_type::types::Polygon)[_1 = _type(_val)]
        << kstring[ phoenix::if_ (single) [_1 = "Polygon("]
                   .else_[_1 = "("]]
        << coords2
        << lit("))")
        ;

    point_coord = &uint_ << coordinate << lit(' ') << coordinate
        ;

    polygon_coord %= ( &uint_(mapnik::SEG_MOVETO)
                       << eps[_r1 += 1][_a  = _x(_val)][ _b = _y(_val)]
                       << kstring[ if_ (_r1 > 1) [_1 = "),("]
                                  .else_[_1 = "("]]
                       |
                       &uint_(mapnik::SEG_LINETO)
                       << lit(',') << eps[_a = _x(_val)][_b = _y(_val)]
        )
        << coordinate[_1 = _a]
        << lit(' ')
        << coordinate[_1 = _b]
        ;

    coords2 %= *polygon_coord(_a,_b,_c)
        ;

    coords = point_coord % lit(',')
        ;
}
示例#6
0
文件: sascalc.cpp 项目: dww100/sasmol
///
/// @par Detailed description 
/// ... 
/// @param [in, out] (param1) ...
/// @return ...
/// @note ...
int
sascalc::Prop::
self_overlap(float &cutoff, int &frame){

    int check = 0 ;     // overlapped == 1
                  // default == no overlap will return == 0 

    float dist ; 
    float this_x , that_x ;
    float this_y , that_y ;
    float this_z , that_z ;
    float dx2, dy2, dz2 ;
    int count = 1 ;

    for(int i = 0 ; i != _natoms()-1 ; ++i)
    {
        this_x = _x()(i,frame) ;
        this_y = _y()(i,frame) ;
        this_z = _z()(i,frame) ;

        for(int j = i+1 ; j != _natoms() ; ++j)
        {
            that_x = _x()(j,frame) ;
            that_y = _y()(j,frame) ;
            that_z = _z()(j,frame) ;

            dx2 = (this_x - that_x)*(this_x - that_x) ;
            dy2 = (this_y - that_y)*(this_y - that_y) ;
            dz2 = (this_z - that_z)*(this_z - that_z) ;

            dist = sqrt(dx2+dy2+dz2) ;

            if(dist < cutoff) 
            {
                std::cout << "count = " << count << std::endl ;
                std::cout << "this_atom = " << _atom_name()[count-1] << std::endl ;
                std::cout << "that_atom = " << _atom_name()[count] << std::endl ;
                std::cout << "dist = " << dist << std::endl ;
                std::cout << "this_x = " << this_x << std::endl ;
                std::cout << "this_y = " << this_y << std::endl ;
                std::cout << "this_z = " << this_z << std::endl ;
                std::cout << "that_x = " << that_x << std::endl ;
                std::cout << "that_y = " << that_y << std::endl ;
                std::cout << "that_z = " << that_z << std::endl ;
                check = 1 ; 
                return check ;
            }
        }    
//        std::cout << count << " " ;
        count++ ;

    }
    std::cout << std::endl ;
    
    return check ;

}
示例#7
0
文件: sascalc.cpp 项目: dww100/sasmol
///
/// @par Detailed description 
/// ... 
/// @param [in, out] (param1) ...
/// @return ...
/// @note ...
void
sascalc::Prop::
calc_pmi(int &frame)
{
    std::vector<float> com = calc_com(frame) ;

    _x().col(frame) -= com[0] ;
    _y().col(frame) -= com[1] ;
    _z().col(frame) -= com[2] ;

    float Ixx = (_atom_mass()*(_y().col(frame)*_y().col(frame) + _z().col(frame)*_z().col(frame))).sum() ;
    float Iyy = (_atom_mass()*(_x().col(frame)*_x().col(frame) + _z().col(frame)*_z().col(frame))).sum() ;
    float Izz = (_atom_mass()*(_x().col(frame)*_x().col(frame) + _y().col(frame)*_y().col(frame))).sum() ;

    float Ixy = (-_atom_mass()*(_x().col(frame)*_y().col(frame))).sum() ;
    float Ixz = (-_atom_mass()*(_x().col(frame)*_z().col(frame))).sum() ;
    float Iyz = (-_atom_mass()*(_y().col(frame)*_z().col(frame))).sum() ;
    float Iyx = (-_atom_mass()*(_y().col(frame)*_x().col(frame))).sum() ;
    float Izx = (-_atom_mass()*(_z().col(frame)*_x().col(frame))).sum() ;
    float Izy = (-_atom_mass()*(_z().col(frame)*_y().col(frame))).sum() ;
    
    Eigen::Matrix3f I ;

    I << Ixx, Ixy, Ixz,
         Iyx, Iyy, Iyz,
         Izx, Izy, Izz;

    Eigen::SelfAdjointEigenSolver<Eigen::Matrix3f> eigensolver(I);

    if (eigensolver.info() != Eigen::Success) 
    {
        std::cout << "PMI calculation failed" << std::endl ;
        return ;
    }

    _uk() = eigensolver.eigenvalues() ; // .col(0) ;
    _ak() = eigensolver.eigenvectors() ;

//    std::cout << "The eigenvalues of I are:\n" << eigensolver.eigenvalues() << std::endl;
//    std::cout << "Here's a matrix whose columns are eigenvectors of I \n"
//    << "corresponding to these eigenvalues:\n"
//    << eigensolver.eigenvectors() << std::endl;

    _x().col(frame) += com[0] ;
    _y().col(frame) += com[1] ;
    _z().col(frame) += com[2] ;

    return ;
}
示例#8
0
文件: sascalc.cpp 项目: dww100/sasmol
///
/// @par Detailed description 
/// ... 
/// @param [in, out] (param1) ...
/// @return ...
/// @note ...
std::vector<float>
sascalc::Prop::
calc_com(int &frame)
{

    if(_total_mass() <= 0.0) {
        calc_mass() ;
        std::cout << "com tot mass = " << _total_mass() << std::endl ;
    }

    float comx = 0.0, comy = 0.0, comz = 0.0 ;

    try
    {
        comx = (_atom_mass()*_x().col(frame)).sum() / _total_mass() ;    
        comy = (_atom_mass()*_y().col(frame)).sum() / _total_mass() ;    
        comz = (_atom_mass()*_z().col(frame)).sum() / _total_mass() ;    
    }
    catch(std::overflow_error e) {
        std::cout << "failed in calc_com" << std::endl ;
        std::cout << "total_mass = " << _total_mass() << std::endl ;
        std::cout << e.what() << " -> ";
        std::vector<float> com = {comx, comy, comz} ;
        return com ;
    }

    std::vector<float> com = {comx, comy, comz} ;

    return com ;
}
示例#9
0
文件: tracy.c 项目: HetGroteBos/tracy
/* Find and execute hook. */
int tracy_execute_hook(struct tracy *t, char *syscall, struct tracy_event *e) {
    struct tracy_ll_item *item;
    int hash;
    union {
            void *pvoid;
            tracy_hook_func pfunc;
        } _hax;


    if (TRACY_PRINT_SYSCALLS(t))
        printf(_y("%04d System call: %s (%ld) Pre: %d")"\n",
                e->child->pid, get_syscall_name_abi(e->syscall_num, e->abi),
                e->syscall_num, e->child->pre_syscall);

    hash = hash_syscall(syscall, e->abi);

    item = ll_find(t->hooks, hash);

    if (item) {
        /* printf("Executing hook for: %s\n", syscall); */

        /* ANSI C has some disadvantages too ... */
        _hax.pvoid = item->data;
        return _hax.pfunc(e);
    }

    if (t->defhook)
        return t->defhook(e);

    return TRACY_HOOK_NOHOOK;
}
示例#10
0
文件: sasio.cpp 项目: dww100/sasmol
///
/// @par Detailed description
/// ...
/// @param [in, out] (param1) ...
/// @return ...
/// @note ...
void
sasio::Files::
read_dcd(std::string &dcd_input_file_name)
{

    int input_natoms, input_nset, input_reverseEndian ;
    FILE *dcd_file_pointer ;

    dcd_file_pointer = sasio::open_dcd_read(dcd_input_file_name, input_natoms, input_nset, input_reverseEndian) ;

    int input_frame = 0 ;

    _number_of_frames() = 0 ;

    _x().setZero(_natoms(), input_nset);
    _y().setZero(_natoms(), input_nset);
    _z().setZero(_natoms(), input_nset);

    std::cout << "_x().cols() = " << _x().cols() << std::endl ;
    std::cout << "input_nset = " << input_nset << std::endl ;

    for(int i = 0 ; i < input_nset ; ++i)
    {
        std::cout << "." ;
        read_dcd_step(dcd_file_pointer, i, input_natoms, input_reverseEndian) ;
    }

    int result = close_dcd_read(dcd_file_pointer) ;

    std::cout << std::endl ;

    return ;
}
示例#11
0
文件: sasio.cpp 项目: dww100/sasmol
///
/// @par Detailed description
/// ...
/// @param [in, out] (param1) ...
/// @return ...
/// @note ...
void
sasio::Files::
read_dcd_step(FILE *dcd_infile, int &frame, int &natoms, int &reverseEndian)
{

    int charmm = 0 ;
    int num_fixed = 0 ;
    int result ;

    std::vector<float> vector_x(natoms) ;
    std::vector<float> vector_y(natoms) ;
    std::vector<float> vector_z(natoms) ;

    result = read_dcdstep(dcd_infile,natoms,&vector_x[0],&vector_y[0],&vector_z[0],num_fixed,frame,reverseEndian,charmm) ;

    if(_x().cols() < frame)
    {
        std::cout << "resizing array: cols() =  " << _x().cols() << " frame = " << frame  << std::endl ;
        resize_array() ;
    }

    for(int i = 0 ; i < _natoms() ; ++i)
    {
        _x()(i,frame) = vector_x[i] ;
        _y()(i,frame) = vector_y[i] ;
        _z()(i,frame) = vector_z[i] ;
    }

    _number_of_frames()++ ;

    return ;
}
示例#12
0
文件: sasio.cpp 项目: dww100/sasmol
///
/// @par Detailed description
/// ...
/// @param [in, out] (param1) ...
/// @return ...
/// @note ...
void
sasio::Files::
write_dcd_step(FILE *outfile, int &frame, int &step)
{
    int step_result = 0 ;

    step_result = write_dcdstep(outfile,_natoms(),&_x()(0,frame),&_y()(0,frame),&_z()(0,frame),step+1) ;

    return ;
}
示例#13
0
文件: sascalc.cpp 项目: dww100/sasmol
///
/// @par Detailed description 
/// ... 
/// @param [in, out] (param1) ...
/// @return ...
/// @note ...
std::vector<std::vector<float >>
sascalc::Prop::
calc_minmax(int &frame){

    float min_x = _x().col(frame).minCoeff() ; float max_x = _x().col(frame).maxCoeff() ;
    float min_y = _y().col(frame).minCoeff() ; float max_y = _y().col(frame).maxCoeff() ;
    float min_z = _z().col(frame).minCoeff() ; float max_z = _z().col(frame).maxCoeff() ;

    std::vector<float> min_vector ;
    std::vector<float> max_vector ;

    min_vector.push_back(min_x) ; min_vector.push_back(min_y) ; min_vector.push_back(min_z) ;
    max_vector.push_back(max_x) ; max_vector.push_back(max_y) ; max_vector.push_back(max_z) ;

    std::vector<std::vector<float >> minmax ;
    minmax.push_back(min_vector) ; minmax.push_back(max_vector) ;

    return minmax ;
}
示例#14
0
文件: tracy.c 项目: HetGroteBos/tracy
/* Handle SIGINT in tracy_main and shutdown smoothly */
static void _main_interrupt_handler(int sig)
{
    if (kill(global_fpid, SIGINT) < 0) {
        if (errno == ESRCH)
            fprintf(stderr, _y("\ntracy: Received %s, foreground PID "
                "does not exists, killing all."), get_signal_name(sig));
        else
            fprintf(stderr, _y("\ntracy: Received %s, kill(%i, SIGINT) failed: %s"),
                get_signal_name(sig), global_fpid, strerror(errno));

        /* Reset to default so tracy can be killed */
        signal(sig, SIG_DFL);

        /* Cancel main loop */
        main_loop_go_on = 0;
    }

    return;
}
示例#15
0
static void _tracer_fork_signal_handler(int sig, siginfo_t *info, void *uctx)
{
    /* Context useable by setcontext, not of any use for us */
    (void)uctx;

    fprintf(stderr, _y("tracy: Received %s would attach to child %d")"\n",
        get_signal_name(sig),
        info->si_pid);

    /*PTRACE_CHECK_NORETURN(PTRACE_ATTACH, info->si_pid, 0, 0); */
}
示例#16
0
BlockLowPass::BlockLowPass(AP_Var_group * group, uint8_t groupStart, float fCut,
             const prog_char_t * fCutLabel) :
    AP_ControllerBlock(group, groupStart, 1),
    _fCut(group, groupStart, fCut, fCutLabel ? : PSTR("fCut")),
    _y(0) {
}
float BlockLowPass::update(const float & input, const float & dt) {
    float RC = 1 / (2 * M_PI * _fCut); // low pass filter
    _y = _y + (input - _y) * (dt / (dt + RC));
    return _y;
}
示例#17
0
文件: sascalc.cpp 项目: dww100/sasmol
///
/// @par Detailed description 
/// ... 
/// @param [in, out] (param1) ...
/// @return ...
/// @note ...
float
sascalc::Prop::
calc_rmsd(sasmol::SasMol &mol, int &frame){

    float dx = (_x().col(frame)-mol._x().col(frame)).pow(2.0).sum() ;
    float dy = (_y().col(frame)-mol._y().col(frame)).pow(2.0).sum() ;
    float dz = (_z().col(frame)-mol._z().col(frame)).pow(2.0).sum() ;

    float rmsd = sqrt((dx + dy + dz)/_natoms()) ;

    return rmsd ;
}
示例#18
0
文件: sascalc.cpp 项目: dww100/sasmol
///
/// @par Detailed description 
/// ... 
/// @param [in, out] (param1) ...
/// @return ...
/// @note ...
float
sascalc::Prop::
calc_rg(int &frame){

    std::vector<float> com = calc_com(frame) ;

    float rgx = ((_x().col(frame) - com[0]).pow(2.0)).sum() ;
    float rgy = ((_y().col(frame) - com[1]).pow(2.0)).sum() ;
    float rgz = ((_z().col(frame) - com[2]).pow(2.0)).sum() ;
    
    float rg = sqrt((rgx + rgy + rgz) / _natoms()) ;    

    return rg ;
}
示例#19
0
bool gcta::check_case_control(double &ncase)
{
    double case_num=0.0;
	vector<double> value(_n);
	for(int i=0; i<_n; i++) value[i]=_y(i);
	stable_sort(value.begin(), value.end());
	value.erase(unique(value.begin(), value.end()), value.end());
	if(value.size()==2){
	    if(CommFunc::FloatEqual(value[0],0.0) && CommFunc::FloatEqual(value[1],1.0)) case_num=_y.sum();
	    else if(CommFunc::FloatEqual(value[0],1.0) && CommFunc::FloatEqual(value[1],2.0)) case_num=(_y.sum()-_n);
        cout<<"Assuming a disease phenotype for a case-control study ";
        cout<<"("<<(int)case_num<<" cases and "<<(int)(_n-case_num)<<" controls)."<<endl;
        ncase=case_num/_n;
        return true;
    }
	else if(value.size()<2) throw("Error: invalid phenotype. Please check the phenotype file.");
	return false;
}
示例#20
0
  int usermult(Mat A, Vec x, Vec y)
  {
    // Wrap PETSc Vec as dolfin::PETScVector
    boost::shared_ptr<Vec> _x(&x, NoDeleter());
    boost::shared_ptr<Vec> _y(&y, NoDeleter());
    PETScVector __x(_x);
    PETScVector __y(_y);

    // Extract pointer to PETScLinearOperator
    void* ctx = 0;
    MatShellGetContext(A, &ctx);
    PETScLinearOperator* _A = ((PETScLinearOperator*) ctx);

    // Call user-defined mult function through wrapper
    dolfin_assert(_A);
    GenericLinearOperator* wrapper = _A->wrapper();
    dolfin_assert(wrapper);
    wrapper->mult(__x, __y);

    return 0;
  }
示例#21
0
文件: sasio.cpp 项目: dww100/sasmol
///
/// @par Detailed description
/// ...
/// @param [in, out] (param1) ...
/// @return ...
/// @note ...
void
sasio::Files::
read_xyz(const std::string &filename)
{

    /* NOT CHECKED FOR MULTIPLE FRAMES */

    std::string line, word ;

    std::ifstream infile(filename) ;

    std::string local_natoms ;
    infile >> local_natoms ;

    _natoms() = stoi(local_natoms) ;
    _number_of_frames() = 1 ;    // HARDWIRED

    // #### need to cleanly read the end of the first line
    // ####     and the next line

    getline(infile,line) ;
    std::istringstream record(line) ;
    while(record >> word) ;
    getline(infile,line) ;
    while(record >> word) ;

    std::vector<float> vector_x;
    std::vector<float> vector_y;
    std::vector<float> vector_z;

    std::vector<float> coor;

    while(getline(infile,line))
    {
        std::istringstream record(line) ;
        record >> word ;
        _atom_name().push_back(word) ;
        while(record >> word)
        {
            coor.push_back(stod(word));
        }
    }

    auto begin = coor.begin() ;
    auto end = coor.end() ;
    std::vector<float>::iterator ii ;

    for(ii = begin ; ii != end ; ii+=3)
    {
        vector_x.push_back(*ii) ;
        vector_y.push_back(*(ii+1)) ;
        vector_z.push_back(*(ii+2));
    }

    infile.close() ;

    if(_number_of_frames() == 0)
    {
        _x().setZero(_natoms(), 1);
        _y().setZero(_natoms(), 1);
        _z().setZero(_natoms(), 1);
    }
    else
    {
        resize_array() ;
    }

    for(int i = 0 ; i < _natoms() ; ++i)
    {
        _x()(i,_number_of_frames()) = vector_x[i] ;
        _y()(i,_number_of_frames()) = vector_y[i] ;
        _z()(i,_number_of_frames()) = vector_z[i] ;
    }

    _number_of_frames()++ ;

    return ;

    /*
    5
      test
      N         -3.259000       -5.011000      -14.360000
    */

} // end of read_xyz
示例#22
0
文件: sasmath.cpp 项目: dww100/sasmol
///
/// @par Detailed description 
/// ... 
/// @param [in, out] (param1) ...
/// @return ...
/// @note ...
Eigen::Matrix3f
sasmath::Math::
find_u(sasmol::SasMol &mol, int &frame)
{

    Eigen::Matrix3f r ;

    float rxx = (mol._x().col(frame)*_x().col(frame)).sum() ; 
    float rxy = (mol._x().col(frame)*_y().col(frame)).sum() ;
    float rxz = (mol._x().col(frame)*_z().col(frame)).sum() ;
    
    float ryx = (mol._y().col(frame)*_x().col(frame)).sum() ;
    float ryy = (mol._y().col(frame)*_y().col(frame)).sum() ;
    float ryz = (mol._y().col(frame)*_z().col(frame)).sum() ;

    float rzx = (mol._z().col(frame)*_x().col(frame)).sum() ;
    float rzy = (mol._z().col(frame)*_y().col(frame)).sum() ;
    float rzz = (mol._z().col(frame)*_z().col(frame)).sum() ;

    r << rxx,rxy,rxz,
         ryx,ryy,ryz,
         rzx,rzy,rzz;

    Eigen::Matrix3f rtr = r.transpose() * r ;
    
    Eigen::SelfAdjointEigenSolver<Eigen::Matrix3f> eigensolver(rtr);

    if (eigensolver.info() != Eigen::Success)
    {
          std::cout << "find_u calculation failed" << std::endl ;
    }

    Eigen::Matrix<float,3,1> uk ;  // eigenvalues
    Eigen::Matrix3f ak ;          // eigenvectors

    uk = eigensolver.eigenvalues() ; 
    ak = eigensolver.eigenvectors() ;

    Eigen::Matrix3f akt = ak.transpose() ;
    Eigen::Matrix3f new_ak  ;

    new_ak.row(0) = akt.row(2) ; //sort eigenvectors
    new_ak.row(1) = akt.row(1) ;
    new_ak.row(2) = akt.row(0) ;

    // python ak0 --> ak[2] ; ak1 --> ak[1] ; ak2 --> ak[0]

    //Eigen::Matrix<float,3,1> ak2 = akt.row(2).cross(akt.row(1)) ;

    Eigen::MatrixXf rak0 = (r * (akt.row(2).transpose())) ;
    Eigen::MatrixXf rak1 = (r * (akt.row(1).transpose())) ;

    Eigen::Matrix<float,3,1> urak0 ; 
    if(uk[2] == 0.0)
    { 
        urak0 = 1E15 * rak0 ;
    } 
    else
    {    
        urak0 = (1.0/sqrt(fabs(uk[2])))*rak0 ;
    }
    
    Eigen::Matrix<float,3,1> urak1 ; 
    if(uk[1] == 0.0)
    { 
        urak1 = 1E15 * rak1 ;
    } 
    else
    {    
        urak1 = (1.0/sqrt(fabs(uk[1])))*rak1 ;
    }

    Eigen::Matrix<float,3,1> urak2 = urak0.col(0).cross(urak1.col(0)) ;
    Eigen::Matrix3f bk ;

    bk << urak0,urak1,urak2;

    Eigen::Matrix3f u ;

    u =  (bk * new_ak).transpose() ;

    return u ;
/*
u = array([[-0.94513198,  0.31068658,  0.100992  ],
       [-0.3006246 , -0.70612572, -0.64110165],
       [-0.12786863, -0.63628635,  0.76078203]])
check:

u = 
-0.945133  0.310686  0.100992
-0.300624 -0.706126 -0.641102
-0.127869 -0.636287  0.760782 
*/
}
示例#23
0
static void
HoughLinesSDiv( const Mat& img,
                float rho, float theta, int threshold,
                int srn, int stn,
                std::vector<Vec2f>& lines, int linesMax,
                double min_theta, double max_theta )
{
    #define _POINT(row, column)\
        (image_src[(row)*step+(column)])

    int index, i;
    int ri, ti, ti1, ti0;
    int row, col;
    float r, t;                 /* Current rho and theta */
    float rv;                   /* Some temporary rho value */

    int fn = 0;
    float xc, yc;

    const float d2r = (float)(CV_PI / 180);
    int sfn = srn * stn;
    int fi;
    int count;
    int cmax = 0;

    std::vector<hough_index> lst;

    CV_Assert( img.type() == CV_8UC1 );
    CV_Assert( linesMax > 0 );

    threshold = MIN( threshold, 255 );

    const uchar* image_src = img.ptr();
    int step = (int)img.step;
    int w = img.cols;
    int h = img.rows;

    float irho = 1 / rho;
    float itheta = 1 / theta;
    float srho = rho / srn;
    float stheta = theta / stn;
    float isrho = 1 / srho;
    float istheta = 1 / stheta;

    int rn = cvFloor( std::sqrt( (double)w * w + (double)h * h ) * irho );
    int tn = cvFloor( 2 * CV_PI * itheta );

    lst.push_back(hough_index(threshold, -1.f, 0.f));

    // Precalculate sin table
    std::vector<float> _sinTable( 5 * tn * stn );
    float* sinTable = &_sinTable[0];

    for( index = 0; index < 5 * tn * stn; index++ )
        sinTable[index] = (float)cos( stheta * index * 0.2f );

    std::vector<uchar> _caccum(rn * tn, (uchar)0);
    uchar* caccum = &_caccum[0];

    // Counting all feature pixels
    for( row = 0; row < h; row++ )
        for( col = 0; col < w; col++ )
            fn += _POINT( row, col ) != 0;

    std::vector<int> _x(fn), _y(fn);
    int* x = &_x[0], *y = &_y[0];

    // Full Hough Transform (it's accumulator update part)
    fi = 0;
    for( row = 0; row < h; row++ )
    {
        for( col = 0; col < w; col++ )
        {
            if( _POINT( row, col ))
            {
                int halftn;
                float r0;
                float scale_factor;
                int iprev = -1;
                float phi, phi1;
                float theta_it;     // Value of theta for iterating

                // Remember the feature point
                x[fi] = col;
                y[fi] = row;
                fi++;

                yc = (float) row + 0.5f;
                xc = (float) col + 0.5f;

                /* Update the accumulator */
                t = (float) fabs( cvFastArctan( yc, xc ) * d2r );
                r = (float) std::sqrt( (double)xc * xc + (double)yc * yc );
                r0 = r * irho;
                ti0 = cvFloor( (t + CV_PI*0.5) * itheta );

                caccum[ti0]++;

                theta_it = rho / r;
                theta_it = theta_it < theta ? theta_it : theta;
                scale_factor = theta_it * itheta;
                halftn = cvFloor( CV_PI / theta_it );
                for( ti1 = 1, phi = theta_it - (float)(CV_PI*0.5), phi1 = (theta_it + t) * itheta;
                     ti1 < halftn; ti1++, phi += theta_it, phi1 += scale_factor )
                {
                    rv = r0 * std::cos( phi );
                    i = (int)rv * tn;
                    i += cvFloor( phi1 );
                    assert( i >= 0 );
                    assert( i < rn * tn );
                    caccum[i] = (uchar) (caccum[i] + ((i ^ iprev) != 0));
                    iprev = i;
                    if( cmax < caccum[i] )
                        cmax = caccum[i];
                }
            }
        }
    }

    // Starting additional analysis
    count = 0;
    for( ri = 0; ri < rn; ri++ )
    {
        for( ti = 0; ti < tn; ti++ )
        {
            if( caccum[ri * tn + ti] > threshold )
                count++;
        }
    }

    if( count * 100 > rn * tn )
    {
        HoughLinesStandard( img, rho, theta, threshold, lines, linesMax, min_theta, max_theta );
        return;
    }

    std::vector<uchar> _buffer(srn * stn + 2);
    uchar* buffer = &_buffer[0];
    uchar* mcaccum = buffer + 1;

    count = 0;
    for( ri = 0; ri < rn; ri++ )
    {
        for( ti = 0; ti < tn; ti++ )
        {
            if( caccum[ri * tn + ti] > threshold )
            {
                count++;
                memset( mcaccum, 0, sfn * sizeof( uchar ));

                for( index = 0; index < fn; index++ )
                {
                    int ti2;
                    float r0;

                    yc = (float) y[index] + 0.5f;
                    xc = (float) x[index] + 0.5f;

                    // Update the accumulator
                    t = (float) fabs( cvFastArctan( yc, xc ) * d2r );
                    r = (float) std::sqrt( (double)xc * xc + (double)yc * yc ) * isrho;
                    ti0 = cvFloor( (t + CV_PI * 0.5) * istheta );
                    ti2 = (ti * stn - ti0) * 5;
                    r0 = (float) ri *srn;

                    for( ti1 = 0; ti1 < stn; ti1++, ti2 += 5 )
                    {
                        rv = r * sinTable[(int) (std::abs( ti2 ))] - r0;
                        i = cvFloor( rv ) * stn + ti1;

                        i = CV_IMAX( i, -1 );
                        i = CV_IMIN( i, sfn );
                        mcaccum[i]++;
                        assert( i >= -1 );
                        assert( i <= sfn );
                    }
                }

                // Find peaks in maccum...
                for( index = 0; index < sfn; index++ )
                {
                    i = 0;
                    int pos = (int)(lst.size() - 1);
                    if( pos < 0 || lst[pos].value < mcaccum[index] )
                    {
                        hough_index vi(mcaccum[index],
                                       index / stn * srho + ri * rho,
                                       index % stn * stheta + ti * theta - (float)(CV_PI*0.5));
                        lst.push_back(vi);
                        for( ; pos >= 0; pos-- )
                        {
                            if( lst[pos].value > vi.value )
                                break;
                            lst[pos+1] = lst[pos];
                        }
                        lst[pos+1] = vi;
                        if( (int)lst.size() > linesMax )
                            lst.pop_back();
                    }
                }
            }
        }
    }

    for( size_t idx = 0; idx < lst.size(); idx++ )
    {
        if( lst[idx].rho < 0 )
            continue;
        lines.push_back(Vec2f(lst[idx].rho, lst[idx].theta));
    }
}
示例#24
0
文件: sasio.cpp 项目: dww100/sasmol
void
sasio::Files::
write_pdb(const std::string &filename, int &frame)
{
    std::ofstream outfile(filename) ;

    std::string time_and_user_string ;
    time_and_user_string = util::time_and_user();
    std::string temp_remark = "REMARK PDB FILE WRITTEN ";
    temp_remark += time_and_user_string ;
    std::string remark(temp_remark,0,80) ;
    std::cout << remark << std::endl ;

    outfile << remark << std::endl;
    //std::string dum1 ="         1         2         3         4         5         6         7         8";
    //std::string dum2 ="12345678901234567890123456789012345678901234567890123456789012345678901234567890";
    //outfile << dum1 << std::endl;
    //outfile << dum2 << std::endl;

    std::stringstream line ;
    std::stringstream my_stringstream;

    for(int i = 0 ; i < _natoms() ; ++i)
    {
        line.str( std::string() );
        line.clear() ;
        std::string tmp(_atom_record()[i],0,6) ;
        line << std::setfill(' ') << std::setw(6) << tmp ;

        if(_atom_index()[i] > 99999)
        {
            std::string tmp2(std::to_string(99999),0,5) ;
            line << std::setfill(' ') << std::setw(5) << std::right << tmp2 ;
        }
        else if(_atom_index()[i] < -9999)
        {
            std::string tmp2(std::to_string(-9999),0,5) ;
            line << std::setfill(' ') << std::setw(5) << std::right << tmp2 ;
        }
        else
        {
            std::string tmp2(std::to_string(_atom_index()[i]),0,5) ;
            line << std::setfill(' ') << std::setw(5) << std::right << tmp2 ;
        }

        std::string tmp0 = " ";
        line << tmp0 ;

        std::string tmp3(_atom_name()[i],0,4) ;
        line << std::setfill(' ') << std::setw(4) << std::left << tmp3 ;

        std::string tmp4(_atom_altloc()[i],0,1) ;
        line << std::setw(1) << tmp4 ;

        std::string tmp5(_atom_resname()[i],0,3) ;
        line << std::setfill(' ') << std::setw(4) << std::left << tmp5 ;

        std::string tmp6(_atom_chain()[i],0,1) ;
        line << std::setfill(' ') << std::setw(1) << std::left << tmp6 ;

        if(_atom_resid()[i] > 9999)
        {
            std::string tmp7(std::to_string(9999),0,4) ;
            line << std::setfill(' ') << std::setw(4) << std::right << tmp7 ;
        }
        else if(_atom_resid()[i] < -999)
        {
            std::string tmp7(std::to_string(-999),0,4) ;
            line << std::setfill(' ') << std::setw(4) << std::right << tmp7 ;
        }
        else
        {
            std::string tmp7(std::to_string(_atom_resid()[i]),0,4) ;
            line << std::setfill(' ') << std::setw(4) << std::right << tmp7 ;
        }

        std::string tmp8(_atom_icode()[i],0,1) ;
        line << std::setw(4) << std::left << tmp8 ;

        //std::string f_str = std::to_string(f);

        //here
        //
        my_stringstream << _x()(i,frame) ;
        //my_stringstream << std::to_string(_x()(i,frame)) ;
        //line << std::setfill(' ') << std::setw(8) << std::right << my_stringstream.str() ;
        line << std::setfill(' ') << std::setw(8) << std::right << my_stringstream.str() ;

        my_stringstream << _y()(i,frame) ;
        line << my_stringstream.str() ;

        my_stringstream << _z()(i,frame) ;
        line << my_stringstream.str() ;

        std::string tmp12(_atom_occupancy()[i],0,6) ;
        line << std::setfill(' ') << std::setw(6) << std::right << tmp12 ;

        std::string tmp13(_atom_beta()[i],0,6) ;
        line << std::setfill(' ') << std::setw(6) << std::right << tmp13 ;

        std::string tmp14(_atom_segname()[i],0,4) ;
        line << std::setfill(' ') << std::setw(10) << std::right << tmp14 ;

        std::string tmp15(_atom_element()[i],0,2) ;
        line << std::setfill(' ') << std::setw(2) << std::right << tmp15 ;

        std::string tmp16(_atom_charge()[i],0,2) ;
        line << std::setfill(' ') << std::setw(2) << std::right << tmp16 ;

        outfile << line.str() << std::endl ;
    }

    outfile << "END" << std::endl;
    outfile.close() ;
}
示例#25
0
文件: sasio.cpp 项目: dww100/sasmol
///
/// @par Detailed description
/// ...
/// @param [in, out] (param1) ...
/// @return ...
/// @note ...
void
sasio::Files::
read_pdb(const std::string &filename)
{
    std::string line, word ;

    std::string element_string ;

    std::ifstream infile(filename) ;

    int count = 0 ;
    int frame = 0 ;

    //string s(line, index, number_characters) ;

    std::vector<float> vector_x;
    std::vector<float> vector_y;
    std::vector<float> vector_z;

    while(getline(infile,line))
    {
        std::istringstream record(line) ;
        record >> word ;

        std::string temp1(word,0,5) ;

        if(temp1 != "ATOM" && temp1 != "HETAT")
        {
            std::cout << "excluding: " << word << std::endl ;
        }
        else
        {
            std::string tmp(line,0,6) ;
            _atom_record().push_back(tmp) ;

            std::string tmp2(line,6,5) ;
            _atom_index().push_back(stoi(tmp2)) ;

            std::string tmp3(line,12,4) ;
            _atom_name().push_back(tmp3) ;

            std::string tmp4(line,16,1) ;
            _atom_altloc().push_back(tmp4) ;

            std::string tmp5(line,17,3) ;
            _atom_resname().push_back(tmp5) ;

            std::string tmp6(line,21,1) ;
            _atom_chain().push_back(tmp6) ;

            std::string tmp7(line,22,4) ;
            _atom_resid().push_back(stoi(tmp7)) ;

            std::string tmp8(line,26,1) ;
            _atom_icode().push_back(tmp8) ;

            std::string tmp9(line,30,8) ;
            vector_x.push_back(stof(tmp9)) ;

            std::string tmp10(line,38,8) ;
            vector_y.push_back(stof(tmp10)) ;

            std::string tmp11(line,46,8) ;
            vector_z.push_back(stof(tmp11)) ;

            try
            {
                std::string tmp12(line,54,6) ;
                if(util::has_only_spaces(tmp12))
                {
                    _atom_occupancy().push_back("0.00") ;
                }
                else
                {
                    _atom_occupancy().push_back(tmp12) ;
                }
            }
            catch(const std::out_of_range& oor)
            {
                _atom_occupancy().push_back("0.00") ;
                std::cerr<<"Occupancy: Out of range error: "<< oor.what() <<std::endl ;
            }

            try
            {
                std::string tmp13(line,60,6) ;
                if(util::has_only_spaces(tmp13))
                {
                    _atom_beta().push_back("0.00") ;
                }
                else
                {
                    _atom_beta().push_back(tmp13) ;
                }
            }
            catch(const std::out_of_range& oor)
            {
                _atom_beta().push_back("0.00") ;
                std::cerr<<"Beta: Out of range error: "<< oor.what() <<std::endl ;
            }

            try
            {
                std::string tmp14(line,72,4) ;
                if(util::has_only_spaces(tmp14))
                {
                    _atom_segname().push_back("SEGN") ;
                }
                else
                {
                    _atom_segname().push_back(tmp14) ;
                }
            }
            catch(const std::out_of_range& oor)
            {
                _atom_segname().push_back("SEGN") ;
                std::cerr<<"Segname: Out of range error: "<< oor.what() <<std::endl ;
            }

            try
            {
                std::string tmp15(line,76,2) ;
                if(util::has_only_spaces(tmp15))
                {
                    std::cout << "Element not found" << std::endl;
                    element_string = element_from_name(tmp3) ;
                    _atom_element().push_back(element_string) ;
                }
                else
                {
                    _atom_element().push_back(tmp15) ;
                }
            }
            catch(const std::out_of_range& oor)
            {
                element_string = element_from_name(tmp3) ;
                _atom_element().push_back(element_string) ;
                std::cerr<<"Element: Out of range error: "<< oor.what() <<std::endl ;
            }

            try
            {
                std::string tmp16(line,78,2) ;
                if(util::has_only_spaces(tmp16))
                {
                    _atom_charge().push_back(" ") ;
                }
                else
                {
                    _atom_charge().push_back(tmp16) ;
                }
            }
            catch(const std::out_of_range& oor)
            {
                _atom_charge().push_back(" ") ;
                std::cerr<<"Charge: Out of range error: "<< oor.what() <<std::endl ;
            }

            count++ ;
        }
    }

    _natoms() = count ;
    infile.close() ;

    int nf = _number_of_frames() ;

    if(_number_of_frames() == 0)
    {
        _x().setZero(_natoms(), 1);
        _y().setZero(_natoms(), 1);
        _z().setZero(_natoms(), 1);
    }
    else
    {
        resize_array() ;
    }

    for(int i = 0 ; i < _natoms() ; ++i)
    {
        _x()(i,_number_of_frames()) = vector_x[i] ;
        _y()(i,_number_of_frames()) = vector_y[i] ;
        _z()(i,_number_of_frames()) = vector_z[i] ;
    }

    std::vector<std::string> s_element ;
    s_element = util::strip_white_space(_atom_element()) ;
    _atom_selement() = s_element ;

    dynamic_cast<sasmol::SasMol*>(this)->calc_mass() ;
    _atom_com() = dynamic_cast<sasmol::SasMol*>(this)->calc_com(frame) ;

    _number_of_frames() += 1 ;

    _set_unique_attributes();

    /*
              1         2         3         4         5         6         7         8
    012345678901234567890123456789012345678901234567890123456789012345678901234567890
             1         2         3         4         5         6         7         8
    12345678901234567890123456789012345678901234567890123456789012345678901234567890
    0    6    1 2   7
    ATOM      1  N   GLY X   1     -21.525 -67.562  86.759  1.00  0.00      GAG  N
    ATOM      2  HT1 GLY X   1     -22.003 -68.460  86.892  1.00  0.00      GAG  H
    ATOM      3  HT2 GLY X   1     -21.905 -66.929  87.525  1.00  0.00      GAG  H

    */
}
示例#26
0
文件: tracy.c 项目: HetGroteBos/tracy
/* Main function for simple tracy based applications */
int tracy_main(struct tracy *tracy) {
    struct tracy_event *e;

    /* Setup interrupt handler */
    main_loop_go_on = 1;
    signal(SIGINT, _main_interrupt_handler);

    while (main_loop_go_on) {
        e = tracy_wait_event(tracy, -1);
        if (!e) {
            fprintf(stderr, "tracy_main: tracy_wait_Event returned NULL\n");
            continue;
        }

        if (e->type == TRACY_EVENT_NONE) {
            break;
        } else if (e->type == TRACY_EVENT_INTERNAL) {
            /*
            printf("Internal event for syscall: %s\n",
                    get_syscall_name(e->syscall_num));
            */
        }
        if (e->type == TRACY_EVENT_SIGNAL) {
            if (TRACY_PRINT_SIGNALS(tracy)) {
                fprintf(stderr, _y("Signal %s (%ld) for child %d")"\n",
                    get_signal_name(e->signal_num), e->signal_num, e->child->pid);
            }
        } else

        if (e->type == TRACY_EVENT_SYSCALL) {
            /*
            if (TRACY_PRINT_SYSCALLS(tracy)) {
                printf(_y("%04d System call: %s (%ld) Pre: %d")"\n",
                        e->child->pid, get_syscall_name(e->syscall_num),
                        e->syscall_num, e->child->pre_syscall);
            }
            */
        } else

        if (e->type == TRACY_EVENT_QUIT) {
            if (tracy->opt & TRACY_VERBOSE)
                printf(_b("EVENT_QUIT from %d with signal %s (%ld)\n"),
                        e->child->pid, get_signal_name(e->signal_num),
                        e->signal_num);
            if (e->child->pid == tracy->fpid) {
                if (tracy->opt & TRACY_VERBOSE)
                    printf(_g("Our first child died.\n"));
            }

            tracy_remove_child(e->child);
            continue;
        }

        if (!tracy_children_count(tracy)) {
            break;
        }

        tracy_continue(e, 0);
    }

    /* Tear down interrupt handler */
    signal(SIGINT, SIG_DFL);

    return 0;
}