Ejemplo n.º 1
0
int main() {
    {   // pack, unpack
        my_class my("John Smith", 42);
        my.a = 123;
        my.set_b("ABC");
        my.set_c("DEF");
        std::stringstream ss;
        msgpack::pack(ss, my);

        print(ss.str());

        msgpack::unpacked unp;
        msgpack::unpack(unp, ss.str().data(), ss.str().size());
        msgpack::object obj = unp.get();
        std::cout << obj << std::endl;
        assert(obj.as<my_class>() == my);
    }
    {   // create object with zone
        my_class my("John Smith", 42);
        my.set_b("ABC");
        my.set_c("DEF");
        msgpack::zone z;
        msgpack::object obj(my, z);
        std::cout << obj << std::endl;
        assert(obj.as<my_class>() == my);
    }
}
Ejemplo n.º 2
0
void message_parse(struct message *m, unsigned char *packet)
{
    unsigned char *buf;
    int i;
    
    if(packet == 0 || m == 0) return;

    // keep all our mem in one (aligned) block for easy freeing    
    #define my(x,y) while(m->_len&7) m->_len++; x = (void*)(m->_packet + m->_len); m->_len += y;

    // header stuff bit crap
    m->_buf = buf = packet;
    m->id = net2short(&buf);
    if(buf[0] & 0x80) m->header.qr = 1;
    m->header.opcode = (buf[0] & 0x78) >> 3;
    if(buf[0] & 0x04) m->header.aa = 1;
    if(buf[0] & 0x02) m->header.tc = 1;
    if(buf[0] & 0x01) m->header.rd = 1;
    if(buf[1] & 0x80) m->header.ra = 1;
    m->header.z = (buf[1] & 0x70) >> 4;
    m->header.rcode = buf[1] & 0x0F;
    buf += 2;
    m->qdcount = net2short(&buf);
    if(m->_len + (sizeof(struct question) * m->qdcount) > MAX_PACKET_LEN - 8) { m->qdcount = 0; return; }
    m->ancount = net2short(&buf);
    if(m->_len + (sizeof(struct resource) * m->ancount) > MAX_PACKET_LEN - 8) { m->ancount = 0; return; }
    m->nscount = net2short(&buf);
    if(m->_len + (sizeof(struct resource) * m->nscount) > MAX_PACKET_LEN - 8) { m->nscount = 0; return; }
    m->arcount = net2short(&buf);
    if(m->_len + (sizeof(struct resource) * m->arcount) > MAX_PACKET_LEN - 8) { m->arcount = 0; return; }

    // process questions
    my(m->qd, sizeof(struct question) * m->qdcount);
    
    for(i=0; i < m->qdcount; i++)
    {
        _label(m, &buf, &(m->qd[i].name));
        m->qd[i].type = net2short(&buf);
        m->qd[i].rr_class = net2short(&buf);
    }

    // process rrs
    my(m->an, sizeof(struct resource) * m->ancount);
    my(m->ns, sizeof(struct resource) * m->nscount);
    my(m->ar, sizeof(struct resource) * m->arcount);
    if(! _rrparse(m,m->an,m->ancount,&buf))
      m->ancount = 0; // some error in parsing, set those counts to 0
    if(! _rrparse(m,m->ns,m->nscount,&buf)) 
      m->nscount = 0;
    if(! _rrparse(m,m->ar,m->arcount,&buf)) 
      m->arcount = 0;
}
Ejemplo n.º 3
0
 void my(vector<int> now,TreeNode * node,int sum){
     if(!node->left && !node->right && node->val==sum){
         now.push_back(node->val);
         result.push_back(now);
     }
     else{
         now.push_back(node->val);
         if(node->left)
             my(now,node->left,sum-node->val);
         if(node->right)
             my(now,node->right,sum-node->val);
     }
         
 }
Ejemplo n.º 4
0
    void SBShapelet::SBShapeletImpl::fillXImage(ImageView<double> im,
                                                double x0, double dx, int izero,
                                                double y0, double dy, int jzero) const
    {
        dbg<<"SBShapelet fillXImage\n";
        dbg<<"x = "<<x0<<" + i * "<<dx<<", izero = "<<izero<<std::endl;
        dbg<<"y = "<<y0<<" + j * "<<dy<<", jzero = "<<jzero<<std::endl;
        const int m = im.getNCol();
        const int n = im.getNRow();
        double* ptr = im.getData();
        const int skip = im.getNSkip();
        assert(im.getStep() == 1);

        x0 /= _sigma;
        dx /= _sigma;
        y0 /= _sigma;
        dy /= _sigma;

        tmv::Matrix<double> mx(m,n);
        for (int i=0; i<m; ++i,x0+=dx) mx.row(i).setAllTo(x0);
        tmv::Matrix<double> my(m,n);
        for (int j=0; j<n; ++j,y0+=dy) my.col(j).setAllTo(y0);

        tmv::Matrix<double> val(m,n);
        fillXValue(val.view(),mx,my);

        typedef tmv::VIt<double,1,tmv::NonConj> It;
        It valit = val.linearView().begin();
        for (int j=0; j<n; ++j,ptr+=skip) {
            for (int i=0; i<m; ++i)
                *ptr++ = *valit++;
        }
    }
Ejemplo n.º 5
0
 vector<vector<int> > pathSum(TreeNode *root, int sum) {
     if(!root)
         return result;
     vector<int> now;
     my(now,root,sum);
     return result;
 }
Ejemplo n.º 6
0
TEST(BitMap, intersects__unaligned) {
  BitMapMemory mx(aligned_size);
  BitMapMemory my(aligned_size);

  BitMapView x = mx.make_view(unaligned_size, even_bits);
  BitMapView y = my.make_view(unaligned_size, zero_bits);
  EXPECT_FALSE(x.intersects(y));

  // Check that adding a bit beyond the end of y doesn't count.
  {
    BitMapView aligned_x = BitMapView(mx.memory(), aligned_size);
    BitMapView aligned_y = BitMapView(my.memory(), aligned_size);
    const idx_t index = aligned_size - 2;
    STATIC_ASSERT(unaligned_size <= index);
    ASSERT_TRUE(aligned_x.at(index));

    WithBitSet wbs(aligned_y, index);
    EXPECT_FALSE(x.intersects(y));
  }

  // Check that adding a bit in the final partial word does count.
  {
    idx_t index = unaligned_size - 2;
    ASSERT_LE(BitMap::word_align_down(unaligned_size), index);
    ASSERT_TRUE(x.at(index));

    WithBitSet wbs(y, index);
    EXPECT_TRUE(x.intersects(y));
  }
}
Ejemplo n.º 7
0
geometry_msgs::Pose JacoPose::constructPoseMsg()
{
    geometry_msgs::Pose pose;
    tf::Quaternion position_quaternion;

    
    // TODO: QUICK FIX, bake this as a quaternion:
    tf::Matrix3x3 mx(           1,            0,            0, 
                                0,  cos(ThetaX), -sin(ThetaX),
                                0,  sin(ThetaX),  cos(ThetaX));
    tf::Matrix3x3 my( cos(ThetaY),            0,  sin(ThetaY),
                                0,            1,            0,
                     -sin(ThetaY),            0,  cos(ThetaY));
    tf::Matrix3x3 mz( cos(ThetaZ), -sin(ThetaZ),            0,
                      sin(ThetaZ),  cos(ThetaZ),            0,
                                0,            0,            1);

    tf::Matrix3x3  mg = mx * my * mz;
    mg.getRotation(position_quaternion);

    // NOTE: This doesn't work, as angles reported by the API are not fixed.
    // position_quaternion.setRPY(ThetaX, ThetaY, ThetaZ);

    
    tf::quaternionTFToMsg(position_quaternion, pose.orientation);

    pose.position.x = X;
    pose.position.y = Y;
    pose.position.z = Z;

    return pose;
}
Ejemplo n.º 8
0
TEST(BitMap, contains__unaligned) {
  BitMapMemory mx(aligned_size);
  BitMapMemory my(aligned_size);

  BitMapView x = mx.make_view(unaligned_size, even_bits);
  BitMapView y = my.make_view(unaligned_size, even_bits);

  // Check that a missing bit beyond the end of x doesn't count.
  {
    BitMapView aligned = BitMapView(mx.memory(), aligned_size);
    const idx_t index = aligned_size - 2;
    STATIC_ASSERT(unaligned_size <= index);

    WithBitClear wbc(aligned, index);
    EXPECT_TRUE(x.contains(y));
  }

  // Check that a missing bit in the final partial word does count.
  {
    idx_t index = unaligned_size - 2;
    ASSERT_LE(BitMap::word_align_down(unaligned_size), index);

    WithBitClear wbc(x, index);
    EXPECT_FALSE(x.contains(y));
  }
}
Ejemplo n.º 9
0
int main(int argc,char * argv[]) 
{ 
	int buff[1]; 
	my();
//	buff[2] = (int)why_here; 
	printf( "main\n" );
	return 0;
} 
//  Returns the blended SQT transform
wsTransform wsTransform::blend(const wsTransform& other, f32 blendFactor) const {
  WS_PROFILE();
  wsTransform my( wsLerp(scale, other.scale, blendFactor),
                  rotation.blend(other.rotation, blendFactor),
                  wsLerp(translationX, other.translationX, blendFactor),
                  wsLerp(translationY, other.translationY, blendFactor),
                  wsLerp(translationZ, other.translationZ, blendFactor)   );

  return my;
}
Ejemplo n.º 11
0
int main(int argc, char *argv[])
{
	QApplication app(argc, argv);

	MyCallback my(0,Qt::WindowStaysOnTopHint);
	my.setGeometry(200,200,100,500);
	my.show();

	return app.exec();
}
Ejemplo n.º 12
0
//-----------------------------------------------------------------------------
void DatPanel::squize()
{
	QString mx("1"), my("1"), mz("1");
	if(sizesDialog(tr("UDAV - Squeeze data"), tr("Enter step of saved points. For example, '1' save all, '2' save each 2nd point, '3' save each 3d and so on."), tr("X-direction"), tr("Y-direction"), tr("Z-direction"), mx, my, mz))
	{
		mglData *d = dynamic_cast<mglData *>(var);
		if(d)	d->Squeeze(mx.toInt(), my.toInt(), mz.toInt());
		refresh();	updateDataItems();
	}
}
Ejemplo n.º 13
0
TEST(BitMap, contains__aligned) {
  BitMapMemory mx(aligned_size);
  BitMapMemory my(aligned_size);

  BitMapView x = mx.make_view(aligned_size, even_bits);
  BitMapView y = my.make_view(aligned_size, even_bits);
  EXPECT_TRUE(x.contains(y));

  WithBitClear wbc(x, aligned_size / 2);
  EXPECT_FALSE(x.contains(y));
}
Ejemplo n.º 14
0
//-----------------------------------------------------------------------------
void DatPanel::create()
{
	QString mx, my("1"), mz("1");
	if(sizesDialog(tr("UDAV - Clear data"), tr("Enter new data sizes"), tr("X-size"), tr("Y-size"), tr("Z-size"), mx, my, mz))
	{
		mglData *d = dynamic_cast<mglData *>(var);
		if(d)	d->Create(mx.toInt(), my.toInt(), mz.toInt());
		mglDataC *c = dynamic_cast<mglDataC *>(var);
		if(c)	c->Create(mx.toInt(), my.toInt(), mz.toInt());
		refresh();	updateDataItems();
	}
}
Ejemplo n.º 15
0
TEST(BitMap, intersects__aligned) {
  BitMapMemory mx(aligned_size);
  BitMapMemory my(aligned_size);

  BitMapView x = mx.make_view(aligned_size, even_bits);
  BitMapView y = my.make_view(aligned_size, zero_bits);
  EXPECT_FALSE(x.intersects(y));

  ASSERT_TRUE(x.at(aligned_size / 2));
  WithBitSet wbs(y, aligned_size / 2);
  EXPECT_TRUE(x.intersects(y));
}
Ejemplo n.º 16
0
static void rect( int p, mapevalenviron& mapenv, evalcontext* ecntxt )
{
  int i, j, p2, p3;
  realtyp mid;
  realtyp d1, d2;
  real2typ xy;

  p2 = p + p;
  p3 = p2 + p;
  for( i = 0; !ecntxt->cycles->error && i < fracsizx; i += p2 )
    for( j = p; !ecntxt->cycles->error && j < fracsizy; j += p2 )
    {
      xy.r2[0] = (realtyp)i/fracsizx;
      xy.r2[1] = (realtyp)j/fracsizy;
      mid = 0.0;
      mid += *adrarar(    i      , my( j + p) );
      mid += *adrarar(    i      , my( j - p) );
      mid += *adrarar( mx( i + p ),    j      );
      mid += *adrarar( mx( i - p ),    j      );
      mid *= 0.25;
      mid += normrand( 0.0, stdm( i, j, mapenv, ecntxt ), rndvl );
      if ( mid > lmax ) lmax = mid;
      else if ( mid < lmin ) lmin = mid;
      if ( fracbump && p == 1 )
      {
        d1 = *adrarar( mx( i + 1 ), j ) - mid;
        d2 = *adrarar( i ,my( j + 1 ) ) - mid;
        if ( d1 > dmax ) dmax = d1;
        else if ( d1 < dmin ) dmin = d1;
        if ( d2 > dmax ) dmax = d2;
        else if ( d2 < dmin ) dmin = d2;
      }
      *adrarar( i, j ) = (float)mid;
    }
  for( i = p; !ecntxt->cycles->error && i < fracsizx; i += p2 )
    for( j = 0; !ecntxt->cycles->error && j < fracsizy; j += p2 )
    {
      xy.r2[0] = (realtyp)i/fracsizx;
      xy.r2[1] = (realtyp)j/fracsizy;
      mid = 0.0;
      mid += *adrarar(    i      , my( j + p) );
      mid += *adrarar(    i      , my( j - p) );
      mid += *adrarar( mx( i + p ),    j      );
      mid += *adrarar( mx( i - p ),    j      );
      mid *= 0.25;
      mid += normrand( 0.0, stdm( i, j, mapenv, ecntxt ), rndvl );
      if ( mid > lmax ) lmax = mid;
      else if ( mid < lmin ) lmin = mid;
      if ( fracbump && p == 1 )
      {
        d1 = *adrarar( mx( i + 1 ), j ) - mid;
        d2 = *adrarar( i ,my( j + 1 ) ) - mid;
        if ( d1 > dmax ) dmax = d1;
        else if ( d1 < dmin ) dmin = d1;
        if ( d2 > dmax ) dmax = d2;
        else if ( d2 < dmin ) dmin = d2;
      }
      *adrarar( i, j ) = (float)mid;
    }
}
Ejemplo n.º 17
0
int main() {
    {   // pack, unpack
        my_class my("John Smith", 42);
        std::stringstream ss;
        msgpack::pack(ss, my);

        print(ss.str());

        msgpack::object_handle oh =
            msgpack::unpack(ss.str().data(), ss.str().size());
        msgpack::object obj = oh.get();
        std::cout << obj << std::endl;
        assert(obj.as<my_class>() == my);
    }
    {   // create object with zone
        my_class my("John Smith", 42);
        msgpack::zone z;
        msgpack::object obj(my, z);
        std::cout << obj << std::endl;
        assert(obj.as<my_class>() == my);
    }
}
Ejemplo n.º 18
0
static void diag( int p, mapevalenviron& mapenv, evalcontext* ecntxt )
{
  int i, j, p2, p3;
  realtyp mid;

  p2 = p + p;
  p3 = p2 + p;
  for( i = p; !ecntxt->cycles->error && i < fracsizx; i += p2 )
    for( j = p; !ecntxt->cycles->error && j < fracsizy; j += p2 )
    {
      mid = 0.0;
      mid += *adrarar( mx( i + p ), my( j + p) );
      mid += *adrarar( mx( i - p ), my( j + p) );
      mid += *adrarar( mx( i + p ), my( j - p) );
      mid += *adrarar( mx( i - p ), my( j - p) );
      mid *= 0.25;
      mid += normrand( 0.0, stdm( i, j, mapenv, ecntxt ), rndvl );
      if ( mid > lmax ) lmax = mid;
      else if ( mid < lmin ) lmin = mid;
      *adrarar( i, j ) = (float)mid;
    }
}
Ejemplo n.º 19
0
AxisRotate::AxisRotate(const QImage &im, const int newW, const int newH): image(im)
{
mx.fill(0.0);
my.fill(0.0);
mz.fill(0.0);
per.fill(0.0);
minusTran.fill(0.0);
tran.fill(0.0);

minusTran(0,0) = minusTran(1,1) = minusTran(2,2) = minusTran(3,3) =
tran(0,0) = tran(1,1) = tran(2,2) = tran(3,3) = 1.0;

mx(0,0)=mx(1,1)=mx(2,2)=mx(3,3)=1.0;
my(0,0)=my(1,1)=my(2,2)=my(3,3)=1.0;
mz(0,0)=mz(1,1)=mz(2,2)=mz(3,3)=1.0;
move(0,0)=move(1,1)=move(2,2)=move(3,3)=1.0;

move(0,3)=newW/2-im.width()/2;
move(1,3)=newH/2-im.height()/2;

minusTran(0,3) = im.width()/2.0;
minusTran(1,3) = im.height()/2.0;
//minusTran(2,3) = 0;
nw = newW;
nh = newH;

tran(0,3) = -im.width() /2.0;
tran(1,3) = -im.height()/2.0;

//tran(2,3) = 0;

per(0,0) = per(1,1) = per(3,3) = 1.0;
per(3,2) = 1.0/-200.0;

rotatedImage = NULL;
}
Ejemplo n.º 20
0
Vector Camera::rotateAxisAngle( Vector v, Vector n, float a)
{
    float co = cos(a);
    float si = sin(a);
    
    Vector o;
    Vector mx( n.X*n.X*(1.0f-co)+co, n.X*n.Y*(1.0f-co)-n.Z*si,n.X*n.Z*(1.0f-co)+n.Y*si );
    Vector my( n.X*n.Y*(1.0f-co)+n.Z*si, n.Y*n.Y*(1.0f-co)+co, n.Y*n.Z*(1.0f-co)-n.X*si );
    Vector mz( n.X*n.Z*(1.0f-co)-n.Y*si, n.Z*n.Y*(1.0f-co)+n.X*si, n.Z*n.Z*(1.0f-co)+co);
    o.X = mx.dot(v);
    o.Y = my.dot(v);
    o.Z = mz.dot(v);

    return o;
}
Ejemplo n.º 21
0
 QImage *AxisRotate::setY(int y) {

     double ry = static_cast<double>(y)*M_PI/180.0;

     my(1,1) = my(3,3) = 1;
     my(0,0) = my(2,2) = cos(ry);
     my(0,2) = sin(ry);
     my(2,0) = -sin(ry);
return translate();
}
Ejemplo n.º 22
0
void PlanetAtmosphereNode::findVisible( Camera*cam, RenderQueue& display, a_vector<LightNode*>& light )
{
    if(!m_controller->m_use_atmosphere || !cam->isInFrustrum(m_globalBbox))
        return;

    PlanetModel* model = m_controller->m_model;
    m_controller->m_cam_position = cam->getPosition();

    vec4 my(0,0,0,1);
    my = m_transform->modelMatrix()*my;
    m_controller->m_cam_position = m_controller->m_cam_position-vec3(my);
    m_controller->m_cam_dist = length(m_controller->m_cam_position);
    display.push_back(this,RenderQueue::TRenderType::TYPE_BLEND);

    SceneNode::findVisible(cam,display,light);
}
void TestWakeups()
{
    tbb::task_scheduler_init my(tbb::task_scheduler_init::deferred);
    if( tbb::task_scheduler_init::default_num_threads() <= NUM_TASKS )
        my.initialize(NUM_TASKS*2);
    Harness::SpinBarrier barrier(NUM_TASKS);
    REMARK("Missing wake-up: affinity_partitioner\n");
    tbb::affinity_partitioner aff;
    for (size_t i = 0; i < NUM_REPEATS; ++i)
        tbb::parallel_for(tbb::blocked_range<int>(0, NUM_TASKS), Functor(barrier), aff);
    REMARK("Missing wake-up: simple_partitioner\n");
    for (size_t i = 0; i < NUM_REPEATS; ++i)
        tbb::parallel_for(tbb::blocked_range<int>(0, NUM_TASKS), Functor(barrier), tbb::simple_partitioner());
    REMARK("Missing wake-up: auto_partitioner\n");
    for (size_t i = 0; i < NUM_REPEATS; ++i)
        tbb::parallel_for(tbb::blocked_range<int>(0, NUM_TASKS), Functor(barrier)); // auto
}
Ejemplo n.º 24
0
int main(){
    my(1);
    printf("-----------------------\n");
    test();
    //test2();
    printf("-----------------------\n");
    test3();
    printf("-----------------------\n");
    test4();
    printf("-----------------------\n");
    testswap();
    printf("-----------------------\n");
    test5();
    printf("-----------------------\n");
    test6();

    return 0;
}
Ejemplo n.º 25
0
int test_main(int, char *[])
{
	/*
	BOOST_CHECK(Com::traits<Com::object< ::IUnknown> >::variant_type_id==::VT_UNKNOWN);
	BOOST_CHECK(Com::traits<Com::object< ::IDispatch> >::variant_type_id==::VT_DISPATCH);
	BOOST_CHECK(Com::traits<Com::object<IMy> >::variant_type_id==::VT_UNKNOWN);
	BOOST_CHECK(Com::traits<Com::object<IDMy> >::variant_type_id==::VT_DISPATCH);
	BOOST_CHECK(Com::traits<Com::object<IDMy2> >::variant_type_id==::VT_DISPATCH);
	*/

	Com::iunknown P;
	BOOST_CHECK(P.QueryInterface<My_IDMy>()==My::IDMy());

	Com::iunknown P1(new MyBase<Com::iunknown::interface_type>());
	BOOST_CHECK(P1.QueryInterface<IUnknown>()!=Com::iunknown());

	My::IDMy my(new DMy());
	BOOST_CHECK(my.A()==2005);
	return 0;
}
Ejemplo n.º 26
0
    void SBShapelet::SBShapeletImpl::fillXImage(ImageView<double> im,
                                                double x0, double dx, double dxy,
                                                double y0, double dy, double dyx) const
    {
        dbg<<"SBShapelet fillXImage\n";
        dbg<<"x = "<<x0<<" + i * "<<dx<<" + j * "<<dxy<<std::endl;
        dbg<<"y = "<<y0<<" + i * "<<dyx<<" + j * "<<dy<<std::endl;
        const int m = im.getNCol();
        const int n = im.getNRow();
        double* ptr = im.getData();
        const int skip = im.getNSkip();
        assert(im.getStep() == 1);

        x0 /= _sigma;
        dx /= _sigma;
        dxy /= _sigma;
        y0 /= _sigma;
        dy /= _sigma;
        dyx /= _sigma;

        tmv::Matrix<double> mx(m,n);
        tmv::Matrix<double> my(m,n);
        typedef tmv::VIt<double,1,tmv::NonConj> It;
        It xit = mx.linearView().begin();
        It yit = my.linearView().begin();
        for (int j=0; j<n; ++j,x0+=dxy,y0+=dy) {
            double x = x0;
            double y = y0;
            for (int i=0; i<m; ++i,x+=dx,y+=dyx) { *xit++ = x; *yit++ = y; }
        }

        tmv::Matrix<double> val(m,n);
        fillXValue(val.view(),mx,my);

        It valit = val.linearView().begin();
        for (int j=0; j<n; ++j,ptr+=skip) {
            for (int i=0; i<m; ++i)
                *ptr++ = *valit++;
        }
    }
Ejemplo n.º 27
0
Archivo: msd.cpp Proyecto: rforge/rhr
RcppExport SEXP msdcpp(SEXP xx, SEXP yy, SEXP mmx, SEXP mmy) {
BEGIN_RCPP
  Rcpp::NumericVector x(xx);
  Rcpp::NumericVector y(yy);
  Rcpp::NumericVector mx(mmx);
  Rcpp::NumericVector my(mmy);

  int n = x.size();
  double sumx = 0;
  double sumy = 0;
  double tmp_ri = 0;  // What is tmp_ri?
  int i;  // counting variable used within the loop

  for (i = 0; i < n; i++) {
    double tx = x[i] - mx[0];
    double ty = y[i] - my[0];
    tmp_ri += pow(tx, 2) + pow(ty, 2);
  }
  
  return Rcpp::NumericVector::create(1/(double)(n-1) * tmp_ri);
END_RCPP
}
Ejemplo n.º 28
0
void Display::OnAbout()
{
	about my(IDD_DIALOG2);
	my.DoModal();
}
Ejemplo n.º 29
0
void bvh_parser(const char *bvh_dir)
{
    FILE *bvh = fopen(bvh_dir,"r");
    if(bvh == NULL)
    {
        printf("[open file error] %s\n",bvh_dir);
        return;
    }

    //declarition
    char buffer[256];
    myStack my(MAX_JOINT+1);

    //initialization
    joint_num = 0;
    joint_end = 0;
    channels_num = 0;
    memset(parent_of,-1,sizeof(parent_of));
    memset(is_end,0,sizeof(is_end));
    parent_of[1] = 0;

    //hierarchy construct
    while( fscanf(bvh,"%s",buffer) != EOF )
    {
        if( strcmp(buffer,"{") == 0 )
        {
            my.push(joint_num);
        }
        else if( strcmp(buffer,"}") == 0 )
        {
            int c = my.top(); my.pop();

            if(c == 1)
            {
                //back to root
                break;
            }

            parent_of[ c ] = my.top();

        }
        else if( strcmp(buffer,"OFFSET") == 0 )
        {
            fscanf(bvh,"%lf%lf%lf",&joint_hiry[joint_num].offset[0],\
                   &joint_hiry[joint_num].offset[1],\
                   &joint_hiry[joint_num].offset[2]);
        }
        else if( strcmp(buffer,"CHANNELS") == 0)
        {
            fscanf(bvh,"%d",&joint_hiry[joint_num].channel);
            channels_num += joint_hiry[joint_num].channel;
            for(int i = 0;i < joint_hiry[joint_num].channel; i++)
            {
                fscanf(bvh,"%s",buffer);
                //x = 0, y = 1, z = 2
                //position rotation | rotation
                if( buffer[0] == 'X')
                {
                    joint_hiry[joint_num].channels[i] = 0;
                }
                else if( buffer[0] == 'Y' )
                {
                    joint_hiry[joint_num].channels[i] = 1;
                }
                else if( buffer[0] == 'Z')
                {
                    joint_hiry[joint_num].channels[i] = 2;
                }
            }
        }
        else if( strcmp(buffer,"JOINT") == 0 || strcmp(buffer,"ROOT") == 0 || strcmp(buffer,"End") == 0)
        {
            fscanf(bvh,"%s",joint_hiry[++joint_num].joint_name);

            if(buffer[0] == 'E')
            {
                is_end[joint_num] = true;
                joint_end++;
            }
        }
    }
    my.free();
    //end of construction


    fscanf(bvh,"%s",buffer);fscanf(bvh,"%s",buffer);
    fscanf(bvh,"%d",&frame_num);
    fscanf(bvh,"%s",buffer);fscanf(bvh,"%s",buffer);
    fscanf(bvh,"%lf",&frame_time);

    int col = 6 + (joint_num - joint_end - 1)*3;
    assert(col == channels_num);
    assert(frame_num < MAX_FRAME);
    assert(joint_num < MAX_JOINT);
    for(int i = 0;i < frame_num;i++)
    {
        for(int j = 0;j < channels_num;j++)
        {
            fscanf(bvh,"%lf",&mat[i][j]);
        }
    }

    fclose( bvh ); bvh = 0;
}
Ejemplo n.º 30
0
void Graph::readfile(){
	clock_t time=clock();
	//ifstream my("E:/xmark.txt");
	ifstream my("E:/uniprot150m.txt");
	//ifstream my("E:/test.txt");

//方法一
/*
	my>>vexNum;
	int f1,f2;
	while (!my.eof())
	{
		my>>f1>>f2;
		if(my.fail())
		{
			break;
		}
		//cout<<f1<<" "<<f2<<endl;
	}
	time=clock()-time;
	cout<<"success! use time :"<<time<<endl;
	my.close();
*/

//方法二
	/*
	if (my)
	{
		clock_t time=clock();
		string t;
		my.seekg(0,my.end);
		int length=my.tellg();
		my.seekg(0,my.beg);
		char * buffer =new char[length];
		//memset(buffer,0,length*sizeof(char));
		memset(buffer,0,length);
		cout<<"reading "<<length<<endl;
		my.read(buffer,length);
		//sprintf(buffer,buffer+'\n');
		if (my)
		{
			t=buffer;
			//cout<<"success"<<endl;
		}else{
			t=buffer;
		//	cout<<"fail!"<<endl;
		}

		int pos1=0,pos2=0;
	
		pos2=t.find("\n",0);
		istringstream vv(t.substr(pos1,pos2));
		vv>>vexNum;
		cout<<"number of vex "<<vexNum<<endl;
		initArcNode();
		string start,end;
		int s,e;
		while(t.find("\n",pos2)!=-1){
			pos1=t.find(" ",pos2++);
			start=t.substr(pos2,pos1-pos2);
			//cout<<start<<endl;
			pos2=t.find("\n",pos2);
			end=t.substr(++pos1,pos2-pos1);
			//cout<<end<<endl;
			//cout<<start<<" "<<end<<" ";
			istringstream ss(start);
			ss>>s;
			istringstream ee(end);
			ee>>e;
			dirGraph(s,e);
		}
		//cout<<t<<endl;
		//cout<<t.find("\n",0);
		time=clock()-time;
		cout<<" use time "<<time<<endl;
	}
	*/
}