コード例 #1
0
ファイル: xdoc.C プロジェクト: viatsko/parser3
static void _transform(Request& r, MethodParams& params) {
	VXdoc& vdoc=GET_SELF(r, VXdoc);

	// params
	Array<const xmlChar*> transform_strings;
	const xmlChar** transform_params=0;
	if(params.count()>1)
		if(HashStringValue* hash=params.as_hash(1, "transform options")) {
			transform_params=new(UseGC) const xmlChar*[hash->count()*2+1];
			Add_xslt_param_info info={
				&r, 
				&transform_strings,
				transform_params
			};
			hash->for_each<Add_xslt_param_info*>(add_xslt_param, &info);
			transform_params[hash->count()*2]=0;
		}

	VXdoc* result;
	if(Value *vxdoc=params[0].as(VXDOC_TYPE)) { // stylesheet (xdoc)
		xmlDoc& stylesheetdoc=static_cast<VXdoc *>(vxdoc)->get_xmldoc();
		// compile xdoc stylesheet
		xsltStylesheet_auto_ptr stylesheet_ptr(xsltParseStylesheetDoc(&stylesheetdoc)); 
		if(xmlHaveGenericErrors())
			throw XmlException(0, r);
		if(!stylesheet_ptr.get())
			throw Exception("xml",
				0,
				"stylesheet failed to compile");
		// strange thing - xsltParseStylesheetDoc records document and destroys it in stylesheet destructor
		// we don't need that
		stylesheet_ptr->doc=0;

		// transform!
		result=&_transform(r, 0,
			vdoc, stylesheet_ptr.get(),
			transform_params);
	} else { // stylesheet (file name)
		// extablish stylesheet connection
		const String& stylesheet_filespec=
			r.absolute(params.as_string(0, "stylesheet must be file name (string) or DOM document (xdoc)"));
		Stylesheet_connection_ptr connection=stylesheet_manager->get_connection(stylesheet_filespec);

		// load and compile file to stylesheet [or get cached if any]
		// transform!
		result=&_transform(r, &stylesheet_filespec, vdoc, connection->stylesheet(),
			transform_params);
	}

	// write out result
	r.write_no_lang(*result);
}
コード例 #2
0
ファイル: fht.cpp プロジェクト: amundhov/legendary
void FHT::transform(float *p)
{
    if (m_num == 8)
        transform8(p);
    else
        _transform(p, m_num, 0);
}
コード例 #3
0
ファイル: visual.c プロジェクト: discoloda/SolemnTides
void visual_printf(int x, int y, int v, const char *fmt, ...) {
    char *str;
    const char *s;
    va_list va;
    struct visual *vis = visuals + v;

    va_start(va, fmt);
    vasprintf(&str, fmt, va);
    va_end(va);

    s = str;

    while(*s) {
        uint32_t uni;
        int tx = x, ty = y;
        utf8_take_rune(&s, &uni);

        if(_transform(&tx, &ty)) {
            io->set_cell(io, tx, ty, uni, vis->color_fov, IO_BLACK);
        }
        x++;
    }

    free(str);
}
コード例 #4
0
void FastFourierTransformation::_transform( float *p, int n, int k )
{
    if(n == 8)
    {
        transform8( p + k );
        return;
    }

    int i, j, ndiv2 = n / 2;
    float a, *t1, *t2, *t3, *t4, *ptab, *pp;

    for( i = 0, t1 = m_buf, t2 = m_buf + ndiv2, pp = &p[k]; i < ndiv2; i++ )
    {
        *t1++ = *pp++, *t2++ = *pp++;
    }

    memcpy( p + k, m_buf, sizeof( float ) * n );

    _transform( p, ndiv2, k );
    _transform( p, ndiv2, k + ndiv2 );

    j = m_num / ndiv2 - 1;
    t1 = m_buf;
    t2 = t1 + ndiv2;
    t3 = p + k + ndiv2;
    ptab = m_tab;
    pp = p + k;

    a = *ptab++ * *t3++;
    a += *ptab * *pp;
    ptab += j;

    *t1++ = *pp + a;
    *t2++ = *pp++ - a;

    for ( i = 1, t4 = p + k + n; i < ndiv2; i++, ptab += j )
    {
        a = *ptab++ * *t3++;
        a += *ptab * *--t4;

        *t1++ = *pp + a;
        *t2++ = *pp++ - a;
    }
    
    memcpy( p + k, m_buf, sizeof(float) * n );
}
コード例 #5
0
ファイル: fht.cpp プロジェクト: ConfusedGiant/Clementine
void FHT::power2(float* p) {
  int i;
  float* q;
  _transform(p, num_, 0);

  *p = (*p * *p), *p += *p, p++;

  for (i = 1, q = p + num_ - 2; i < (num_ / 2); i++, --q)
    *p = (*p * *p) + (*q * *q), p++;
}
コード例 #6
0
ファイル: fht.cpp プロジェクト: Gu1/Clementine
void FHT::power2(float* p) {
  int i;
  float* q;
  _transform(p, m_num, 0);

  *p = (*p * *p), *p += *p, p++;

  for (i = 1, q = p + m_num - 2; i < (m_num / 2); i++, --q)
    *p = (*p * *p) + (*q * *q), p++;
}
コード例 #7
0
ファイル: File.cpp プロジェクト: ShockwaveNN/core
    void File::read(const std::wstring& filename)
	{
		m_listContent.clear();

		if (filename.empty())
			return;

        TxtFile file(filename);
		
		//читаем юникод чтобы можно было выкинуть невалидные символы

		if (file.isUtf8())
		{
			m_listContent = _transform(file.readUtf8(), Encoding::utf82unicode);
		}
		else if (file.isUnicode())
		{
			m_listContent = file.readUnicode();
		}
		else if (file.isBigEndian())
		{
			m_listContent = file.readBigEndian();
		}
		//проверка убрана, потому что она работает в редких случаюх: если в первой строке есть английские символы
		//далее не делается проверка BigEndian или LittleEndian
		//notepad++ открывает такие файлы как ansi и мы будем также.
		//else if (file.isUnicodeWithOutBOM())
		//	listContentUnicode = file.readUnicodeWithOutBOM();
		else
		{
            if (-1 == m_nEncoding)
                m_listContent = _transform(file.readAnsiOrCodePage(), Encoding::utf82unicode);
			else if (1000 == m_nEncoding)
                m_listContent = _transform(file.readAnsiOrCodePage(), Encoding::ansi2unicode);
			else
                m_listContent = _transform2(file.readAnsiOrCodePage(), m_nEncoding, Encoding::cp2unicode);
		}
		
		m_listContentSize = file.getLinesCount();
		
		//correctUnicode(listContentUnicode); - ВЫТИРАЕТ ПРОБЕЛЫ  в конце строки (
	}
コード例 #8
0
VRPNTrackerAxis::VRPNTrackerAxis(const std::string& axis) :
    _transform( Matrix4f::IDENTITY )
{
    _transform(2,2) = -1.f; // TODO: remove old default; specify explicitly

    if (!axis.empty())
    {
        if (!parseTransform(axis, _transform))
            LBWARN << "VRPN tracker couldn't process axis option: " << axis;
    }
}
コード例 #9
0
ファイル: fht.cpp プロジェクト: Atrament666/Clementine
void FHT::_transform(float* p, int n, int k) {
  if (n == 8) {
    transform8(p + k);
    return;
  }

  int i, j, ndiv2 = n / 2;
  float a, *t1, *t2, *t3, *t4, *ptab, *pp;

  for (i = 0, t1 = buf_(), t2 = buf_() + ndiv2, pp = &p[k]; i < ndiv2; i++)
    *t1++ = *pp++, *t2++ = *pp++;

  std::copy(buf_(), buf_() + n, p + k);

  _transform(p, ndiv2, k);
  _transform(p, ndiv2, k + ndiv2);

  j = num_ / ndiv2 - 1;
  t1 = buf_();
  t2 = t1 + ndiv2;
  t3 = p + k + ndiv2;
  ptab = tab_();
  pp = p + k;

  a = *ptab++ * *t3++;
  a += *ptab * *pp;
  ptab += j;

  *t1++ = *pp + a;
  *t2++ = *pp++ - a;

  for (i = 1, t4 = p + k + n; i < ndiv2; i++, ptab += j) {
    a = *ptab++ * *t3++;
    a += *ptab * *--t4;

    *t1++ = *pp + a;
    *t2++ = *pp++ - a;
  }

  std::copy(buf_(), buf_() + n, p + k);
}
コード例 #10
0
ファイル: fht.cpp プロジェクト: Atrament666/Clementine
void FHT::power2(float* p) {
  _transform(p, num_, 0);

  *p = static_cast<float>(2 * pow(*p, 2));
  p++;

  float* q = p + num_ - 2;
  for (int i = 1; i < (num_ / 2); i++) {
    *p = static_cast<float>(pow(*p, 2) + pow(*q, 2));
    p++;
    q--;
  }
}
コード例 #11
0
void FastFourierTransformation::power2( float *p )
{
    int i;
    float *q;
    _transform( p, m_num, 0 );

    *p = (*p * *p), *p += *p, p++;

    for( i = 1, q = p + m_num - 2; i < (m_num / 2); i++, --q )
    {
        *p = (*p * *p) + (*q * *q), p++;
    }
}
コード例 #12
0
ファイル: visual.c プロジェクト: discoloda/SolemnTides
void visual_draw(int x, int y, int v) {
    struct visual *vis = visuals + v;

    int tx = x, ty = y;

    if(!_transform(&tx, &ty)) {
        return;
    }

    if(map_fov(x, y)) {
        io->set_cell(io, tx, ty, vis->uni, vis->color_fov, IO_BLACK);
    } else if(vis->color_seen && map_seen(x, y)) {
        io->set_cell(io, tx, ty, vis->uni, vis->color_seen, IO_BLACK);
    }
}
コード例 #13
0
ファイル: ukf.cpp プロジェクト: Achierius/siganal
//Actual Kalman Filter equations
void ukf::stepUKF(std::chrono::milliseconds dT, Eigen::VectorXd measurement, Eigen::VectorXd control){
  for(auto j = std::chrono::milliseconds(0); j < (dT>_dT ? dT : _dT); j+=_dT){
   
    _prevState= _state;
    _prevCovar= _covar; 

    _statistic = 1/(2*(_states+_lambda));
    _sqrtP = _covar.sqrt();
    double coeff = std::sqrt(_states+_lambda);
    
    _sigmaPoints.col(0) = _prevState;
    _sigmaPoints.block(0, 1, _states, _states) = coeff*_sqrtP;
    _sigmaPoints.block(0, 1+_states, _states, _states) = -1*coeff*_sqrtP;
    for(auto i = 1; i < 2*_states+1; i++){
      _sigmaPoints.col(i) += _prevState;
    }
    
    for(auto i = 0; i < 2*_states+1; i++){
      _sigmaPoints.col(i) = _transform(_sigmaPoints.col(i), static_cast<double>(std::min(_dT, dT).count()));
    } 
    
    _state = _sigmaPoints.col(0);
    for(auto i = 1; i < 2*_states+1; i++){
      _state+= _sigmaPoints.col(i);
    }
    _state *= _statistic;
 
    _covar = _Q;
    for(auto i = 0; i < 2*_states+1; i++){
      _covar += (_sigmaPoints.col(i) - _prevState)*(static_cast<Eigen::MatrixXd>(_sigmaPoints.col(i) - _prevState)).transpose();
    }
    _state *= _statistic;
    
    for(auto i = 0; i < 2*_states+1; i++){
      _measureSigmaPoints.col(i) = _measure(_sigmaPoints.col(i), static_cast<double>(std::min(_dT, dT).count()));
    } 
  }
}
コード例 #14
0
ファイル: Application.cpp プロジェクト: rdelillo/FumiGen
// Animates an objets
void Application::animate()
{
	++_cntMove;
	// Remove un-needed figures 
	if(_cntMove%FREE_REFRESH_LOOP == 0)
		_removeEmptyFigures();
	// If in PLAY mode (no FPS)
	if(m_camera->getMode() == "PLAY")
	{
		++_playMove;
		// Animate the camera if needed
		m_camera->move();
		// Transform the figures if needed
		_transform();
		// Animate the figures
		for(unsigned int i=0; i<m_figures.size(); ++i)
		{
			m_figures[i]->move();
			if(m_renderFlag)
			{
				m_figures[i]->setRenderCamera(m_camera->getRendermanTransform());
				m_figures[i]->render();
			}
		}
		// Test if play sequence is finished
		// Optimization, better to reconstruct
		// the data, at the end of the play sequence
		if(m_camera->getMode() == "FPS")
		{
			_reset();
			m_renderFlag = false;
			for(unsigned int i=0; i<m_figures.size(); ++i)
				m_figures[i]->reset();	
		}
	}
}
コード例 #15
0
ファイル: File.cpp プロジェクト: ShockwaveNN/core
    void File::writeAnsi(const std::wstring& filename) const
	{
        TxtFile file(filename);
		file.writeAnsiOrCodePage(_transform(m_listContent, Encoding::unicode2ansi));
	}
コード例 #16
0
ファイル: fht.cpp プロジェクト: ConfusedGiant/Clementine
void FHT::transform(float* p) {
  if (num_ == 8)
    transform8(p);
  else
    _transform(p, num_, 0);
}
コード例 #17
0
VRPNTrackerAxis::VRPNTrackerAxis() :
    _transform( Matrix4f::IDENTITY )
{
    _transform(2,2) = -1.f; // TODO: remove old default; specify explicitly
}
コード例 #18
0
ファイル: mgshape.cpp プロジェクト: arthur-zhang/touchvg
void MgBaseShape::transform(const Matrix2d& mat) { _transform(mat); }
コード例 #19
0
ファイル: kgramstats.cpp プロジェクト: hatkirby/rawr-ebooks
// runs in O(n log t) time where n is the input number of sentences and t is the number of tokens in the input corpus
std::string rawr::randomSentence(int maxL, std::mt19937& rng) const
{
  if (!_compiled)
  {
    return "";
  }
  
  std::string result;
  kgram cur(1, wildcardQuery);
  int cuts = 0;
  std::stack<parentype> open_delimiters;
  std::set<int> used_corpora;
	
  for (;;)
  {
    if (cur.size() == _maxK)
    {
      cur.pop_front();
    }
    
    while (cur.size() > 2 &&
           cuts > 0 &&
           !std::bernoulli_distribution(1.0 / static_cast<double>(cuts))(rng))
    {
        cur.pop_front();
        cuts--;
    }
    
    // Gotta circumvent the last line of the input corpus
    // https://twitter.com/starla4444/status/684222271339237376
    if (_stats.count(cur) == 0)
    {
      // The end of a corpus should probably be treated like a terminator, so
      // maybe we should just end here.
      if (result.length() > maxL ||
          std::bernoulli_distribution(1.0 / 4.0)(rng))
      {
        break;
      }

      cur = kgram(1, wildcardQuery);
    }

    auto& distribution = _stats.at(cur);
    int max = distribution.rbegin()->first;
    std::uniform_int_distribution<int> randDist(0, max - 1);
    int r = randDist(rng);
    const token_data& next = distribution.upper_bound(r)->second;
    const token& interned = _tokenstore.get(next.tok);
    std::string nextToken = interned.w.forms.next(rng);

    // Apply user-specified transforms
    if (_transform)
    {
      nextToken = _transform(interned.w.canon, nextToken);
    }
  
    // Determine the casing of the next token. We randomly make the token all
    // caps based on the markov chain. Otherwise, we check if the previous
    // token is the end of a sentence (terminating token or a wildcard query).
    std::uniform_int_distribution<int> caseDist(0, next.all - 1);
    int casing = caseDist(rng);
    
    if (casing < next.uppercase)
    {
      std::transform(
        std::begin(nextToken),
        std::end(nextToken),
        std::begin(nextToken),
        ::toupper);
    } else {
      bool capitalize = false;

      if (casing - next.uppercase < next.titlecase)
      {
        capitalize = true;
      } else if (cur.rbegin()->type == querytype::sentence)
      {
        if (std::bernoulli_distribution(1.0 / 2.0)(rng))
        {
          capitalize = true;
        }
      } else {
        const token& lastTok = _tokenstore.get(cur.rbegin()->tok);

        if (lastTok.suffix == suffixtype::terminating &&
            std::bernoulli_distribution(1.0 / 2.0)(rng))
        {
          capitalize = true;
        }
      }

      if (capitalize)
      {
        nextToken[0] = toupper(nextToken[0]);
      }
    }
    
    // Delimiters
    for (auto& dt : interned.delimiters)
    {
      if (dt.first.status == doublestatus::both)
      {
        switch (dt.first.type)
        {
          case parentype::paren: nextToken = std::string("(", dt.second) + nextToken + std::string(")", dt.second); break;
          case parentype::square_bracket: nextToken = std::string("[", dt.second) + nextToken + std::string("]", dt.second); break;
          case parentype::asterisk: nextToken = std::string("*", dt.second) + nextToken + std::string("*", dt.second); break;
          case parentype::quote: nextToken = std::string("\"", dt.second) + nextToken + std::string("\"", dt.second); break;
        }
      } else if (dt.first.status == doublestatus::opening)
      {
        for (int i=0; i<dt.second; i++)
        {
          open_delimiters.push(dt.first.type);
        }
        
        switch (dt.first.type)
        {
          case parentype::paren: nextToken = std::string("(", dt.second) + nextToken; break;
          case parentype::square_bracket: nextToken = std::string("[", dt.second) + nextToken; break;
          case parentype::asterisk: nextToken = std::string("*", dt.second) + nextToken; break;
          case parentype::quote: nextToken = std::string("\"", dt.second) + nextToken; break;
        }
      } else if (dt.first.status == doublestatus::closing)
      {
        for (int i=0; i<dt.second; i++)
        {
          while (!open_delimiters.empty() && (open_delimiters.top() != dt.first.type))
          {
            switch (open_delimiters.top())
            {
              case parentype::paren: nextToken.append(")"); break;
              case parentype::square_bracket: nextToken.append("]"); break;
              case parentype::asterisk: nextToken.append("*"); break;
              case parentype::quote: nextToken.append("\""); break;
            }
            
            open_delimiters.pop();
          }
          
          if (open_delimiters.empty())
          {
            switch (dt.first.type)
            {
              case parentype::paren: result = "(" + result; break;
              case parentype::square_bracket: result = "[" + result; break;
              case parentype::asterisk: result = "*" + result; break;
              case parentype::quote: result = "\"" + result; break;
            }
          } else {
            open_delimiters.pop();
          }
          
          switch (dt.first.type)
          {
            case parentype::paren: nextToken.append(")"); break;
            case parentype::square_bracket: nextToken.append("]"); break;
            case parentype::asterisk: nextToken.append("*"); break;
            case parentype::quote: nextToken.append("\""); break;
          }
        }
      }
    }
    
    // Terminators
    if (interned.suffix == suffixtype::terminating)
    {
      auto term = interned.w.terms.next(rng);
      nextToken.append(term.form);
      
      if (term.newline)
      {
        nextToken.append("\n");
      } else {
        nextToken.append(" ");
      }
    } else if (interned.suffix == suffixtype::comma)
    {
      nextToken.append(", ");
    } else {
      nextToken.append(" ");
    }
    
    if (next.all == max)
    {
      // If this pick was guaranteed, increase cut chance
      cuts++;
    } else if (cuts > 0) {
      // Otherwise, decrease cut chance
      cuts /= 2;
    }
    
    if (next.corpora.size() == 1)
    {
      used_corpora.insert(*next.corpora.begin());
    }
		
    /* DEBUG */
    std::cout << cur << "-> \"" << nextToken << "\" (" << next.all << "/" << max << ")" << " in corp";
    for (auto cor : next.corpora)
    {
      std::cout << " " << cor;
    }
    std::cout << "; l=" << cur.size() << ",cuts=" << cuts << std::endl;

    cur.push_back(next.tok);
    result.append(nextToken);

    if (interned.suffix == suffixtype::terminating &&
          (result.length() > maxL ||
           std::bernoulli_distribution(1.0 / 4.0)(rng)))
    {
      break;
    }
  }
  
  // Ensure that enough corpora are used
  if (used_corpora.size() < _min_corpora)
  {
    return randomSentence(maxL, rng);
  }
  
  // Remove the trailing space
  if (result.back() == ' ' || result.back() == '\n')
  {
    result.pop_back();
  }
  
  // Close any open delimiters
  while (!open_delimiters.empty())
  {
    switch (open_delimiters.top())
    {
      case parentype::paren: result.append(")"); break;
      case parentype::square_bracket: result.append("]"); break;
      case parentype::asterisk: result.append("*"); break;
      case parentype::quote: result.append("\""); break;
    }
    
    open_delimiters.pop();
  }
	
  return result;
}
コード例 #20
0
void CQDlgTranslations::_applyTransformation(int t)
{ // t==0: rotation, t==1: translation, t==2: scaling
	int editMode=App::ct->objCont->getEditModeType();
	int objSelSize=App::ct->objCont->getSelSize();
	int editObjSelSize=App::ct->objCont->editModeBuffer.size();
	if ( (editMode==NO_EDIT_MODE)&&(objSelSize>0) )
	{
		for (int i=0;i<objSelSize;i++)
		{
			C3DObject* object=App::ct->objCont->getObject(App::ct->objCont->getSelID(i));
			bool hasParentPresent=false;
			if ((transfMode==0)&&(t!=2)) // scaling is different!
			{ // We do a transformation relative to the world. If this object has a parent that also is selected, we don't process this object!
				C3DObject* p=object->getParent();
				while (p!=NULL)
				{
					for (int j=0;j<objSelSize;j++)
					{
						if (App::ct->objCont->getSelID(j)==p->getID())
						{
							hasParentPresent=true;
							break;
						}
					}
					if (hasParentPresent)
						break;
					p=p->getParent();
				}
			}
			if (!hasParentPresent)
			{
				C7Vector tr;
				if (transfMode==0)
					tr=object->getCumulativeTransformationPart1();
				else
					tr=object->getLocalTransformationPart1();
				_transform(tr,t,transfMode==2);
				if (transfMode==0)
					tr=object->getParentCumulativeTransformation().getInverse()*tr;
				object->setLocalTransformation(tr);
			}
		}
	}
	if ( (editMode&PATH_EDIT_MODE)&&(editObjSelSize>0)&&(App::ct->objCont->_editionPath!=NULL) )
	{
		CPathCont* pathCont=App::ct->objCont->_editionPath;
		CPath* path=App::ct->objCont->getPath(App::ct->objCont->getEditModeObjectID());
		for (int i=0;i<editObjSelSize;i++)
		{
			CSimplePathPoint* pp=pathCont->getSimplePathPoint(App::ct->objCont->editModeBuffer[i]);
			if ( (pp!=NULL)&&(path!=NULL) )
			{
				C7Vector tr(pp->getTransformation());
				if (transfMode==0)
					tr=path->getCumulativeTransformationPart1()*tr;
				_transform(tr,t,transfMode==2);
				if (transfMode==0)
					tr=path->getCumulativeTransformationPart1().getInverse()*tr;
				pp->setTransformation(tr,pathCont->getAttributes());
			}
		}
		pathCont->actualizePath();
	}
	if ( (editMode&VERTEX_EDIT_MODE)&&(editObjSelSize>0) )
	{
		CShape* shape=App::ct->objCont->getShape(App::ct->objCont->getEditModeObjectID());
		if (shape!=NULL)
		{
			for (int i=0;i<editObjSelSize;i++)
			{
				C7Vector tr;
				tr.setIdentity();
				int ind=App::ct->objCont->editModeBuffer[i];
				tr.X.set(&App::ct->objCont->_editionVertices[3*ind+0]);
				if (transfMode==0)
					tr=shape->getCumulativeTransformationPart1()*tr;
				_transform(tr,t,transfMode==2);
				if (transfMode==0)
					tr=shape->getCumulativeTransformationPart1().getInverse()*tr;
				App::ct->objCont->_editionVertices[3*ind+0]=tr.X(0);
				App::ct->objCont->_editionVertices[3*ind+1]=tr.X(1);
				App::ct->objCont->_editionVertices[3*ind+2]=tr.X(2);
			}
		}
	}
}
コード例 #21
0
ファイル: File.cpp プロジェクト: ShockwaveNN/core
    void File::writeUtf8(const std::wstring& filename) const
	{
        TxtFile file(filename);
		file.writeUtf8(_transform(m_listContent, Encoding::unicode2utf8));
	}