コード例 #1
0
ファイル: GlNode.cpp プロジェクト: kdbanman/browseRDF
BoundingBox GlNode::getBoundingBox(GlGraphInputData* data) {
  node n=node(id);

  if(data->getElementRotation()->getNodeValue(n)==0) {
    BoundingBox box;
    box.expand(data->getElementLayout()->getNodeValue(n)-data->getElementSize()->getNodeValue(n)/2.f);
    box.expand(data->getElementLayout()->getNodeValue(n)+data->getElementSize()->getNodeValue(n)/2.f);
    assert(box.isValid());
    return box;
  }
  else {
    float cosAngle=static_cast<float>(cos(data->getElementRotation()->getNodeValue(n)/180.*M_PI));
    float sinAngle=static_cast<float>(sin(data->getElementRotation()->getNodeValue(n)/180.*M_PI));
    Coord tmp1(data->getElementSize()->getNodeValue(n)/2.f);
    Coord tmp2(tmp1[0] ,-tmp1[1], tmp1[2]);
    Coord tmp3(-tmp1[0],-tmp1[1],-tmp1[2]);
    Coord tmp4(-tmp1[0], tmp1[1],-tmp1[2]);
    tmp1=Coord(tmp1[0]*cosAngle-tmp1[1]*sinAngle,tmp1[0]*sinAngle+tmp1[1]*cosAngle,tmp1[2]);
    tmp2=Coord(tmp2[0]*cosAngle-tmp2[1]*sinAngle,tmp2[0]*sinAngle+tmp2[1]*cosAngle,tmp2[2]);
    tmp3=Coord(tmp3[0]*cosAngle-tmp3[1]*sinAngle,tmp3[0]*sinAngle+tmp3[1]*cosAngle,tmp3[2]);
    tmp4=Coord(tmp4[0]*cosAngle-tmp4[1]*sinAngle,tmp4[0]*sinAngle+tmp4[1]*cosAngle,tmp4[2]);
    BoundingBox bb;
    bb.expand(data->getElementLayout()->getNodeValue(n)+tmp1);
    bb.expand(data->getElementLayout()->getNodeValue(n)+tmp2);
    bb.expand(data->getElementLayout()->getNodeValue(n)+tmp3);
    bb.expand(data->getElementLayout()->getNodeValue(n)+tmp4);
    return bb;
  }
}
コード例 #2
0
ファイル: test.cpp プロジェクト: NEXUS1000/class
//复数类的四则运算
int main()
{
	Fushu a(10);
	Fushu b(20);
	Fushu tmp1(a+b);
	tmp1.Show();
	Fushu tmp2(a-b);
	tmp2.Show();
	Fushu tmp3(a*b);
	tmp3.Show();
	Fushu tmp4(a/b);
	tmp4.Show();
	return 0;
}
コード例 #3
0
int test_rotate90()
{
#ifdef _MSC_VER
	cv::Mat matSrc = cv::imread("E:/GitCode/OpenCV_Test/test_images/1.jpg", 1);
#else	
	cv::Mat matSrc = cv::imread("test_images/1.jpg", 1);
#endif
	if (!matSrc.data) {
		std::cout << "read image fail" << std::endl;
		return -1;
	}

	int width = matSrc.cols;
	int height = matSrc.rows;

	fbc::Mat_<uchar, 3> mat1(height, width, matSrc.data);
	fbc::Mat_<uchar, 3> matTranspose(width, height);
	fbc::transpose(mat1, matTranspose);

	// clockwise rotation  90
	fbc::Mat_<uchar, 3> matRotate90(width, height);
	fbc::flip(matTranspose, matRotate90, 1);
	cv::Mat tmp2(width, height, CV_8UC3, matRotate90.data);
#ifdef _MSC_VER
	cv::imwrite("E:/GitCode/OpenCV_Test/test_images/rotate_90.jpg", tmp2);
#else	
	cv::imwrite("test_images/rotate_90.jpg", tmp2);
#endif

	// clockwise rotation 180
	fbc::Mat_<uchar, 3> matRotate180(height, width);
	fbc::flip(mat1, matRotate180, -1);
	cv::Mat tmp3(height, width, CV_8UC3, matRotate180.data);
#ifdef _MSC_VER
	cv::imwrite("E:/GitCode/OpenCV_Test/test_images/rotate_180.jpg", tmp3);
#else
	cv::imwrite("test_images/rotate_180.jpg", tmp3);
#endif
	// clockwise rotation 270
	fbc::Mat_<uchar, 3> matRotate270(width, height);
	fbc::flip(matTranspose, matRotate270, 0);
	cv::Mat tmp4(matTranspose.rows, matTranspose.cols, CV_8UC3, matRotate270.data);
#ifdef _MSC_VER
	cv::imwrite("E:/GitCode/OpenCV_Test/test_images/rotate_270.jpg", tmp4);
#else
	cv::imwrite("test_images/rotate_270.jpg", tmp4);
#endif
	return 0;
}
コード例 #4
0
ファイル: leetcode.cpp プロジェクト: zzhan133/leetcode
int _tmain(int argc, _TCHAR* argv[])
{
	unordered_set<string> dict;

	string tmp1("hot");
	string tmp2("dot");
	string tmp3("dog");
	string tmp4("lot");
	string tmp5("log");

	dict.insert(tmp1);
	dict.insert(tmp2);
	dict.insert(tmp3);
	dict.insert(tmp4);
	dict.insert(tmp5);

	string start("hit");
	string end("cog");
	Solution instance;
	vector<vector<string> > vvs = instance.findLadders(start, end, dict);

	return 0;
}
コード例 #5
0
ファイル: emgm.cpp プロジェクト: ivcl/SplitVectors
gaussian_model EMclustering::maximization(MatrixXf x, MatrixXf r)
{
	int d = x.rows();
	int n = x.cols();
	int k = r.cols();
	//cerr<<x<<endl;
	VectorXf nk(r.rows());
	nk = r.colwise().sum();
	VectorXf w(nk.size());
	w = nk/n;
	MatrixXf tmp1(x.rows(),r.cols());
	tmp1 = x * r;
	VectorXf tmp2(nk.size());
	tmp2 = nk.array().inverse();
	//cerr<<tmp2<<endl<<endl;
	MatrixXf mu(x.rows(),r.cols());
	mu = tmp1 * tmp2.asDiagonal() ;
	MatrixXf *sigma = new MatrixXf[k];
	for(int i=0;i<k;i++)
		sigma[i].setZero(d,d);
	MatrixXf sqrtr(r.rows(),r.cols());
	sqrtr = r.cwiseSqrt();
	MatrixXf xo(d,n);
	MatrixXf tmp3(d,d);
	tmp3.setIdentity(d,d);
	
	for(int i=0;i<k;i++)
	{
		xo = x.colwise() - mu.col(i);
		VectorXf tmp4(sqrtr.rows());
		tmp4 = sqrtr.col(i);
		tmp4 = tmp4.adjoint();
		xo = xo* tmp4.asDiagonal();
		sigma[i] = xo*xo.adjoint()/nk(i);
		sigma[i] = sigma[i] + tmp3*1e-6; 
		//cerr<<sigma[i]<<endl<<endl;
	}

	gaussian_model model;
	model.mu = mu;
	model.sigma = new MatrixXf[k];
	for(int i=0;i<k;i++)
		model.sigma[i] = sigma[i];
	
	model.weight = w;
	
	nk.resize(0);
	w.resize(0);
	tmp1.resize(0,0);
	tmp2.resize(0);
	tmp3.resize(0,0);
	mu.resize(0,0);
	for(int i=0;i<k;i++)
		sigma[i].resize(0,0);
	delete [] sigma;
	sqrtr.resize(0,0);
	xo.resize(0,0);
	tmp3.resize(0,0);

	//cerr<<"---"<<endl;
	model.weight = model.weight.adjoint();
	//cerr<<model.weight<<endl<<endl;
	//cerr<<model.mu<<endl<<endl;
	//for(int i=0;i<k;i++)
	//{
	//	cerr<<model.sigma[i]<<endl<<endl;
	//}
	return model;
}
コード例 #6
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

    */
}
コード例 #7
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() ;
}