Пример #1
0
void
MPEGCodec::decompress(const DataChunk &data)
{
	const int channels = 3;
	const size_t bytes_per_channel = sizeof(unsigned char);
	
	const UInt32 width = _descriptor.getStoredWidth();
	const UInt32 height = _descriptor.getStoredHeight();
	
	const ptrdiff_t stride = bytes_per_channel * channels;
	const size_t rowbytes = width * stride;
	const size_t data_size = rowbytes * height;
	
	DataChunkPtr buf_data = new DataChunk(data_size);
	
	char *data_origin = (char *)buf_data->Data;
	
	
	
	FrameBufferPtr buf = new FrameBuffer(width, height);
	
	buf->insert("R", Slice(MoxFiles::UINT8, data_origin + (bytes_per_channel * 0), stride, rowbytes));
	buf->insert("G", Slice(MoxFiles::UINT8, data_origin + (bytes_per_channel * 1), stride, rowbytes));
	buf->insert("B", Slice(MoxFiles::UINT8, data_origin + (bytes_per_channel * 2), stride, rowbytes));
	
	memset(data_origin, 0, data_size);
	
	buf->attachData(buf_data);
	
	
	storeFrame(buf);
}
Пример #2
0
Slice MemTable::get(int(*compare)(unsigned char* key, int key_size, unsigned char* value, int value_size), unsigned char* key, int key_size)
{
	Slice slice;
	if (this->current_table)
	{
		slice = this->mem_table1->searchNode(compare, key, key_size);
		if (slice.getKeySize() == 0 && (!slice.isDeleted()))
		{
			Slice s = this->mem_table2->searchNode(compare, key, key_size);

			return Slice(s.getKey(),s.getKeySize(),s.getValue(),s.getValueSize(), s.isDeleted());
		}
		else
		{
			return Slice(slice.getKey(), slice.getKeySize(), slice.getValue(), slice.getValueSize(), slice.isDeleted());
		}
	}
	else {
		slice = this->mem_table2->searchNode(compare, key, key_size);
		if (slice.getKeySize() == 0 && (!slice.isDeleted()))
		{
			Slice s = this->mem_table1->searchNode(compare, key, key_size);

			return Slice(s.getKey(), s.getKeySize(), s.getValue(), s.getValueSize(), s.isDeleted());
		}
		else {
			return Slice(slice.getKey(), slice.getKeySize(), slice.getValue(), slice.getValueSize(), slice.isDeleted());
		}
	}
}
Пример #3
0
/*** KDF ***/
void KDF(const string &auth_key, const UInt128 &msg_key, int X, UInt256 *aes_key, UInt256 *aes_iv) {
  CHECK(auth_key.size() == 2048 / 8);
  const char *auth_key_raw = auth_key.c_str();
  uint8 buf[48];
  as<UInt128>(buf) = msg_key;
  as<UInt256>(buf + 16) = as<UInt256>(auth_key_raw + X);
  uint8 sha1_a[20];
  sha1(Slice(buf, 48), sha1_a);

  as<UInt128>(buf) = as<UInt128>(auth_key_raw + X + 32);
  as<UInt128>(buf + 16) = msg_key;
  as<UInt128>(buf + 32) = as<UInt128>(auth_key_raw + X + 48);
  uint8 sha1_b[20];
  sha1(Slice(buf, 48), sha1_b);

  as<UInt256>(buf) = as<UInt256>(auth_key_raw + 64 + X);
  as<UInt128>(buf + 32) = msg_key;
  uint8 sha1_c[20];
  sha1(Slice(buf, 48), sha1_c);

  as<UInt128>(buf) = msg_key;
  as<UInt256>(buf + 16) = as<UInt256>(auth_key_raw + 96 + X);
  uint8 sha1_d[20];
  sha1(Slice(buf, 48), sha1_d);

  as<uint64>(aes_key->raw) = as<uint64>(sha1_a);
  as<UInt<96>>(aes_key->raw + 8) = as<UInt<96>>(sha1_b + 8);
  as<UInt<96>>(aes_key->raw + 20) = as<UInt<96>>(sha1_c + 4);

  as<UInt<96>>(aes_iv->raw) = as<UInt<96>>(sha1_a + 8);
  as<uint64>(aes_iv->raw + 12) = as<uint64>(sha1_b);
  as<uint32>(aes_iv->raw + 20) = as<uint32>(sha1_c + 16);
  as<uint64>(aes_iv->raw + 24) = as<uint64>(sha1_d);
}
Пример #4
0
				void Run()
				{
					db->VisitAllDB(this);
					db->GetEngine()->CommitBatchWrite();
					db->GetEngine()->CompactRange(Slice(), Slice());
					delete this;
				}
Пример #5
0
 Slice WiredTigerIterator::Value() const
 {
     if (0 == m_iter->get_value(m_iter, &m_value_item))
     {
         return Slice((const char*) m_value_item.data, m_value_item.size);
     }
     return Slice();
 }
Пример #6
0
/**
 * @brief Left hand side operator (i.e. inverse transform) 
 *
 * @param  in      K-space
 * @param  sm      Sensitivities 
 * @param  nx      Sizes & co.
 * @param  fts     FT operators
 * @return         Image
 */
template <class T> inline static Matrix< std::complex<T> >
EH (const Matrix< std::complex<T> >& in, const Matrix< std::complex<T> >& sm,
    const std::vector<size_t>& nx, const std::vector<NFFT<T> >& fts) {
	Matrix< std::complex<T> > out = zeros< std::complex<T> > (size(sm));
#pragma omp parallel for default (shared)
	for (int j = 0; j < nx[1]; j++)
        Slice (out, j, fts[omp_get_thread_num()] ->* Column (in,j) * conj(Slice (sm, j)));
 	return sum (out, nx[0]);
}
Пример #7
0
void saveEXRRGBA(const char* filename, int width, int height, float* data)
{
	half *idr_r = new half[ width * height];
	half *idr_g = new half[ width * height];
	half *idr_b = new half[ width * height];
	half *idr_a = new half[ width * height];
	
	for(int j=0; j< height; j++) {
		int invj = height - 1 -j;
		for(int i=0; i< width; i++) {
			idr_r[j* width + i] = (half)data[(invj* width + i)*4];
			idr_g[j* width + i] = (half)data[(invj* width + i)*4+1];
			idr_b[j* width + i] = (half)data[(invj* width + i)*4+2];
			idr_a[j* width + i] = (half)data[(invj* width + i)*4+3];
		}
	}
// write exr
	Header idrheader ( width,  height); 

		idrheader.channels().insert ("R", Channel (HALF));
		idrheader.channels().insert ("G", Channel (HALF));                                   // 1 
        idrheader.channels().insert ("B", Channel (HALF));
		idrheader.channels().insert ("A", Channel (HALF));                   // 2  
    
        OutputFile idrfile (filename, idrheader);                               // 4 
        FrameBuffer idrframeBuffer;
		 idrframeBuffer.insert ("R",                                // name   // 6 
                            Slice (HALF,                        // type   // 7 
                                   (char *) idr_r,            // base   // 8 
                                   sizeof (*idr_r) * 1,       // xStride// 9 
                                   sizeof (*idr_r) *  width));
        idrframeBuffer.insert ("G",                                // name   // 6 
                            Slice (HALF,                        // type   // 7 
                                   (char *) idr_g,            // base   // 8 
                                   sizeof (*idr_g) * 1,       // xStride// 9 
                                   sizeof (*idr_g) *  width));
		 idrframeBuffer.insert ("B",                                // name   // 6 
                            Slice (HALF,                        // type   // 7 
                                   (char *) idr_b,            // base   // 8 
                                   sizeof (*idr_b) * 1,       // xStride// 9 
                                   sizeof (*idr_b) *  width));
		 idrframeBuffer.insert ("A",                                // name   // 6 
                            Slice (HALF,                        // type   // 7 
                                   (char *) idr_a,            // base   // 8 
                                   sizeof (*idr_a) * 1,       // xStride// 9 
                                   sizeof (*idr_a) *  width));
       
        idrfile.setFrameBuffer (idrframeBuffer);                                // 16 
        idrfile.writePixels ( height); 
        
// cleanup
	delete[] idr_r;
	delete[] idr_g;
	delete[] idr_b;
	delete[] idr_a;
}
Пример #8
0
				void Run()
				{
					KeyObject start(Slice(), KV, dbid);
					KeyObject end(Slice(), KV, dbid + 1);
					Buffer sbuf, ebuf;
					encode_key(sbuf, start);
					encode_key(ebuf, end);
					adb->GetEngine()->CompactRange(sbuf.AsString(), ebuf.AsString());
					delete this;
				}
Пример #9
0
  Function Map
  ::get_reverse(const std::string& name, int nadj,
                const std::vector<std::string>& i_names,
                const std::vector<std::string>& o_names,
                const Dict& opts) const {
    // Shorthands
    int n_in = this->n_in(), n_out = this->n_out();

    // Generate map of derivative
    Function df = f_.reverse(nadj);
    Function dm = df.map(n_, parallelization());

    // Input expressions
    vector<MX> arg = dm.mx_in();

    // Need to reorder sensitivity inputs
    vector<MX> res = arg;
    vector<MX>::iterator it=res.begin()+n_in+n_out;
    vector<int> ind;
    for (int i=0; i<n_out; ++i, ++it) {
      int sz = f_.size2_out(i);
      ind.clear();
      for (int k=0; k<n_; ++k) {
        for (int d=0; d<nadj; ++d) {
          for (int j=0; j<sz; ++j) {
            ind.push_back((d*n_ + k)*sz + j);
          }
        }
      }
      *it = (*it)(Slice(), ind);
    }

    // Get output expressions
    res = dm(res);

    // Reorder sensitivity outputs
    it = res.begin();
    for (int i=0; i<n_in; ++i, ++it) {
      int sz = f_.size2_in(i);
      ind.clear();
      for (int d=0; d<nadj; ++d) {
        for (int k=0; k<n_; ++k) {
          for (int j=0; j<sz; ++j) {
            ind.push_back((k*nadj + d)*sz + j);
          }
        }
      }
      *it = (*it)(Slice(), ind);
    }

    // Construct return function
    return Function(name, arg, res, i_names, o_names, opts);
  }
Пример #10
0
				void Run()
				{
					adb->GetEngine()->BeginBatchWrite();
					adb->VisitDB(dbid, this);
					adb->GetEngine()->CommitBatchWrite();
					KeyObject start(Slice(), KV, dbid);
					KeyObject end(Slice(), KV, dbid + 1);
					Buffer sbuf, ebuf;
					encode_key(sbuf, start);
					encode_key(ebuf, end);
					adb->GetEngine()->CompactRange(sbuf.AsString(), ebuf.AsString());
					delete this;
				}
Пример #11
0
void readEXRRGB(const char* filename, int width, int height, float* data)
{
	InputFile file(filename); 
	Box2i dw = file.header().dataWindow();
	
	int size = (width)*(height);
	
	half *rPixels = new half[size];
	half *gPixels = new half[size];
	half *bPixels = new half[size];
	
	FrameBuffer frameBuffer; 
	frameBuffer.insert ("R",                                  // name 
						Slice (HALF,                          // type 
							   (char *) rPixels, 
							   sizeof (*rPixels) * 1,    // xStride 
							   sizeof (*rPixels) * (width),// yStride 
							   1, 1,                          // x/y sampling 
							   0.0));                         // fillValue 
							   
	frameBuffer.insert ("G",                                  // name 
						Slice (HALF,                          // type 
							   (char *) gPixels, 
							   sizeof (*gPixels) * 1,    // xStride 
							   sizeof (*gPixels) * (width),// yStride 
							   1, 1,                          // x/y sampling 
							   0.0));
							   
	frameBuffer.insert ("B",                                  // name 
						Slice (HALF,                          // type 
							   (char *) bPixels, 
							   sizeof (*bPixels) * 1,    // xStride 
							   sizeof (*bPixels) * (width),// yStride 
							   1, 1,                          // x/y sampling 
							   0.0));
							   
	file.setFrameBuffer (frameBuffer); 
	file.readPixels (dw.min.y, dw.max.y); 
	
	for(int j=0; j<height; j++)
	for(int i=0; i<width; i++) {
		
		data[(j*width+i)*3 ] = rPixels[(height-1-j)*width+i];
		data[(j*width+i)*3+1] = gPixels[(height-1-j)*width+i];
		data[(j*width+i)*3+2] = bPixels[(height-1-j)*width+i];
	}
	
	delete[] rPixels;
	delete[] gPixels;
	delete[] bPixels;
}
Пример #12
0
void writeEXRHalf(OStream *ost, const float *pixels,
	      int width, int height, int components) 
{
	//assert(components==3 || components==4);
	// TODO: throw std::exception if invalid number of components

	Header header (width, height);
	header.channels().insert ("R", Channel (HALF));
	header.channels().insert ("G", Channel (HALF));
	header.channels().insert ("B", Channel (HALF));
	if(components==4)
		header.channels().insert ("A", Channel (HALF));

	// Convert data to half
	half *data = new half [width*height*components];
	
	std::copy(pixels, pixels+(width*height*components), data);
	
	// And save it
	OutputFile file (*ost, header);
	FrameBuffer frameBuffer;

	frameBuffer.insert("R",				// name
			    Slice (HALF,		// type
				   ((char *) data)+0,	// base
				   2 * components,		// xStride
				   2 * components * width));	// yStride
	frameBuffer.insert("G",				// name
			    Slice (HALF,		// type
				   ((char *) data)+2,	// base
				   2 * components,		// xStride
				   2 * components * width));	// yStride
	frameBuffer.insert("B",				// name
			    Slice (HALF,		// type
				   ((char *) data)+4,	// base
				   2 * components,		// xStride
				   2 * components * width));	// yStride
	if(components==4) {
		frameBuffer.insert("A",					// name
				    Slice (HALF,			// type
					   ((char *) data)+6,		// base
					   2 * components,		// xStride
					   2 * components * width));	// yStride
	}

	file.setFrameBuffer(frameBuffer);
	file.writePixels(height);
	delete data;
}
Пример #13
0
void Model::SliceToSVG(Glib::RefPtr<Gio::File> file, bool single_layer)
{
  if (is_calculating) return;
  is_calculating=true;

  lastlayer = NULL;
  Slice();
  m_progress->stop (_("Done"));
  if (!single_layer) {
    Glib::file_set_contents (file->get_path(), getSVG());
  }
  else {
    uint n_layers = layers.size();
    m_progress->start (_("Saving Files"),n_layers);
    uint digits = log10(n_layers)+1;
    string base = file->get_path();
    ostringstream ostr;
    for (uint i = 0; i < n_layers; i++) {
      ostr.str("");
      ostr << base;
      uint nzero = (uint)(digits - log10(i+1));
      if (i==0) nzero = digits-1;
      for (uint d = 0; d < nzero; d++)
	ostr << "0";
      ostr << i
	   << ".svg";
      if (!m_progress->update(i)) break;
      Glib::file_set_contents (ostr.str(), getSVG(i));
    }
    m_progress->stop (_("Done"));
  }
  string directory_path = file->get_parent()->get_path();
  settings.STLPath = directory_path;
  is_calculating = false;
}
Пример #14
0
 void Seek(const Slice &target)
 {
     char buf[prefix.size() + target.size()];
     (void) memcpy(buf, prefix.data(), prefix.size());
     (void) memcpy(buf + sizeof(prefix), target.data(), target.size());
     impl.Seek(Slice(buf, sizeof(buf)));
 }
Пример #15
0
// Parse a length-prefixed number
//  Format: 0x02 <length-byte> <number>
static
boost::optional<Slice>
sigPart (Slice& buf)
{
    if (buf.size() < 3 || buf[0] != 0x02)
        return boost::none;
    auto const len = buf[1];
    buf += 2;
    if (len > buf.size() || len < 1 || len > 33)
        return boost::none;
    // Can't be negative
    if ((buf[0] & 0x80) != 0)
        return boost::none;
    if (buf[0] == 0)
    {
        // Can't be zero
        if (len == 1)
            return boost::none;
        // Can't be padded
        if ((buf[1] & 0x80) == 0)
            return boost::none;
    }
    boost::optional<Slice> number = Slice(buf.data(), len);
    buf += len;
    return number;
}
Пример #16
0
int main () {
	fwrite(PG_BINARY_HEADER, sizeof(PG_BINARY_HEADER), 1, stdout);
	uint32_t height = 0;

	while (true) {
		uint8_t buffer[32];
		const auto read = fread(buffer, sizeof(buffer), 1, stdin);

		// EOF?
		if (read == 0) break;

		uint8_t pbuffer[46];
		auto pslice = Slice(pbuffer, pbuffer + sizeof(pbuffer));

		std::reverse(&buffer[0], &buffer[32]); // BLOCK_HASH -> BLOCK_ID

		// postgres COPY tuple
		pslice.write<int16_t, true>(2);

		pslice.write<int32_t, true>(32);
		memcpy(pslice.begin, buffer, 32);
		pslice.popFrontN(32);

		pslice.write<int32_t, true>(4);
		pslice.write<int32_t, true>(height);
		fwrite(pbuffer, sizeof(pbuffer), 1, stdout);

		++height;
	}

	fwrite(PG_BINARY_TAIL, sizeof(PG_BINARY_TAIL), 1, stdout);

	return 0;
}
Пример #17
0
Expression *SliceExp::optimize(int result)
{   Expression *e;

    //printf("SliceExp::optimize(result = %d) %s\n", result, toChars());
    e = this;
    e1 = e1->optimize(WANTvalue | (result & (WANTinterpret|WANTexpand)));
    if (!lwr)
    {   if (e1->op == TOKstring)
        {   // Convert slice of string literal into dynamic array
            Type *t = e1->type->toBasetype();
            if (t->nextOf())
                e = e1->castTo(NULL, t->nextOf()->arrayOf());
        }
        return e;
    }
    e1 = fromConstInitializer(result, e1);
    // We might know $ now
    setLengthVarIfKnown(lengthVar, e1);
    lwr = lwr->optimize(WANTvalue | (result & WANTinterpret));
    upr = upr->optimize(WANTvalue | (result & WANTinterpret));
    e = Slice(type, e1, lwr, upr);
    if (e == EXP_CANT_INTERPRET)
        e = this;
    //printf("-SliceExp::optimize() %s\n", e->toChars());
    return e;
}
Пример #18
0
	int Ardb::FlushScripts()
	{
		KeyObject start(Slice(), SCRIPT, ARDB_GLOBAL_DB);
		Iterator* iter = FindValue(start, false);
		BatchWriteGuard guard(GetEngine());
		while (NULL != iter && iter->Valid())
		{
			Slice tmpkey = iter->Key();
			KeyObject* kk = decode_key(tmpkey, NULL);
			if (NULL != kk)
			{
				if (kk->type == SCRIPT)
				{
					DelValue(*kk);
				} else
				{
					break;
				}
			}
			DELETE(kk);
			iter->Next();
		}
		DELETE(iter);
		return 0;
	}
Пример #19
0
	bool Ardb::Init()
	{
		if (NULL == m_engine)
		{
			INFO_LOG("Start init storage engine.");
			m_engine = m_engine_factory->CreateDB(
			        m_engine_factory->GetName().c_str());

			KeyObject verkey(Slice(), KEY_END, 0xFFFFFF);
			ValueObject ver;
			if (0 == GetValue(verkey, &ver, NULL))
			{
				if (ver.v.int_v != ARDB_FORMAT_VERSION)
				{
					ERROR_LOG(
					        "Incompatible data format version:%d in DB", ver.v.int_v);
					return false;
				}
			}
			else
			{
				ver.v.int_v = ARDB_FORMAT_VERSION;
				ver.type = INTEGER;
				SetValue(verkey, ver);
			}
			if (NULL != m_engine)
			{
				INFO_LOG("Init storage engine success.");
			}
		}
		return m_engine != NULL;
	}
Пример #20
0
	bool Ardb::DBExist(const DBID& db, DBID& nextdb)
	{
		KeyObject start(Slice(), KV, db);
		Iterator* iter = FindValue(start, false);
		bool found = false;
		nextdb = db;
		if (NULL != iter && iter->Valid())
		{
			Slice tmpkey = iter->Key();
			KeyObject* kk = decode_key(tmpkey, NULL);
			if (NULL != kk)
			{
				if (kk->db == db)
				{
					found = true;
				} else
				{
					nextdb = kk->db;
				}
			}
			DELETE(kk);
		}
		DELETE(iter);
		return found;
	}
Пример #21
0
	void Ardb::Walk(WalkHandler* handler)
	{
		KeyObject start(Slice(), KV, 0);
		Iterator* iter = FindValue(start);
		uint32 cursor = 0;
		while (NULL != iter && iter->Valid())
		{
			Slice tmpkey = iter->Key();
			KeyObject* kk = decode_key(tmpkey, NULL);
			if (NULL == kk)
			{
				break;
			}
			ValueObject v;
			Buffer readbuf(const_cast<char*>(iter->Value().data()), 0, iter->Value().size());
			decode_value(readbuf, v, false);
			int ret = handler->OnKeyValue(kk, &v, cursor++);
			DELETE(kk);
			if (ret < 0)
			{
				break;
			}
			iter->Next();
		}
		DELETE(iter);
	}
Пример #22
0
void Table::ReadMeta(const Footer& footer) {
  if (rep_->options.filter_policy == NULL) {
    return;  // Do not need any metadata
  }

  // TODO(sanjay): Skip this if footer.metaindex_handle() size indicates
  // it is an empty block.
  ReadOptions opt;
  if (rep_->options.paranoid_checks) {
    opt.verify_checksums = true;
  }
  BlockContents contents;
  if (!ReadBlock(rep_->file, opt, footer.metaindex_handle(), &contents).ok()) {
    // Do not propagate errors since meta info is not needed for operation
    return;
  }
  Block* meta = new Block(contents);

  Iterator* iter = meta->NewIterator(BytewiseComparator());
  std::string key = "filter.";
  key.append(rep_->options.filter_policy->Name());
  iter->Seek(key);
  if (iter->Valid() && iter->key() == Slice(key)) {
    ReadFilter(iter->value());
  }
  delete iter;
  delete meta;
}
Пример #23
0
void ZFnEXR::readCameraNZ(const char* filename, int width, int height, float* data, M44f& mat, float& fov)
{
	InputFile file(filename); 
	
	const DoubleAttribute *fovattr = file.header().findTypedAttribute <DoubleAttribute> ("fov");
	fov = fovattr->value();
	
	const M44fAttribute *matattr = file.header().findTypedAttribute <M44fAttribute> ("cameraTransform");
	mat = matattr->value();
	
	Box2i dw = file.header().dataWindow();
	
	//int size = (width)*(height);
	
	FrameBuffer frameBuffer; 
	frameBuffer.insert ("R",                                  
						Slice (FLOAT,                         
							   (char *) data, 
							   sizeof (*data) * 1,    
							   sizeof (*data) * (width),
							   1, 1,                          
							   0.0));                        
							   
	file.setFrameBuffer (frameBuffer); 
	file.readPixels (dw.min.y, dw.max.y); 
}
Пример #24
0
Slice RandomSlice(Random* rnd, size_t len, std::string* dst) {
    dst->resize(len);
    for (size_t i = 0; i < len; i++) {
        (*dst)[i] = static_cast<char>(' ' + rnd->Uniform(95));   // ' ' .. '~'
    }
    return Slice(*dst);
}
Пример #25
0
void ZFnEXR::readR(const char* filename, int width, int height, float* data)
{
	InputFile file(filename); 
	Box2i dw = file.header().dataWindow();
	
	int size = (width)*(height);
	
	half *rPixels = new half[size];
	
	FrameBuffer frameBuffer; 
	frameBuffer.insert ("R",                                  // name 
						Slice (HALF,                          // type 
							   (char *) rPixels, 
							   sizeof (*rPixels) * 1,    // xStride 
							   sizeof (*rPixels) * (width),// yStride 
							   1, 1,                          // x/y sampling 
							   0.0));                         // fillValue 
							   
	file.setFrameBuffer (frameBuffer); 
	file.readPixels (dw.min.y, dw.max.y); 
	
	for(int i=0; i<size; i++) data[i] = rPixels[i];
	
	delete[] rPixels;
}
Пример #26
0
  void SymbolicQr::evaluateSXGen(const SXPtrV& input, SXPtrV& output, bool tr) {
    // Get arguments
    casadi_assert(input.at(0)!=0);
    SX r = *input.at(0);
    casadi_assert(input.at(1)!=0);
    SX A = *input.at(1);

    // Number of right hand sides
    int nrhs = r.size2();

    // Factorize A
    vector<SX> v = fact_fcn_(A);

    // Select solve function
    Function& solv = tr ? solv_fcn_T_ : solv_fcn_N_;

    // Solve for every right hand side
    vector<SX> resv;
    v.resize(3);
    for (int i=0; i<nrhs; ++i) {
      v[2] = r(Slice(), i);
      resv.push_back(solv(v).at(0));
    }

    // Collect the right hand sides
    casadi_assert(output[0]!=0);
    *output.at(0) = horzcat(resv);
  }
Пример #27
0
/**
 * @brief    MATLAB-like meshgrid. x and y vectors must be specified z may be specified optionally.
 *
 * @param x  X-Vector
 * @param y  Y-Vector
 * @param z  Z-Vector (default: unused)
 * @return   Mesh grid O (Ny x Nx x Nz x 3) (if z specified) else O (Ny x Nx x 2)<br/>
 */
template <class T> inline static Matrix<T>
meshgrid (const Vector<T>& x, const Vector<T>& y, const Vector<T>& z = Vector<T>(1)) {

	size_t nx = numel(x);
	size_t ny = numel(y);
	size_t nz = numel(z);

	assert (nx > 1);
	assert (ny > 1);

	// Column vectors
	assert (size(x,0) == nx); 
	assert (size(y,0) == ny);
	assert (size(z,0) == nz);

	Matrix<T> res (ny, nx, (nz > 1) ? nz : 2, (nz > 1) ? 3 : 1);
	
	for (size_t i = 0; i < ny * nz; i++) 
		Row    (res, i          , x);
	for (size_t i = 0; i < nx * nz; i++) 
		Column (res, i + nx * nz, y);
	if (nz > 1)
		for (size_t i = 0; i < nz; i++)
			Slice  (res, i +  2 * nz, z[i]);
	
	return res;	

}
Пример #28
0
static void
UpdateSlotValue(impl_context* Context, input_slot SlotHandle, impl_slot* Slot, float NewValue)
{
  float const AttunedValue = AttuneValue(Slot, NewValue);

  Slot->Frame = Context->Frame;
  Slot->ValueStore = AttunedValue;

  //
  // Apply input mapping
  //
  for(auto& Mapping : Slice(Context->SlotMappings))
  {
    if(Mapping.Source == SlotHandle)
    {
      impl_slot* OtherSlot{};
      DisassembleSlotHandle(Mapping.Target, nullptr, nullptr, nullptr, &OtherSlot);

      Assert(OtherSlot);

      float NewMappedValue = AttunedValue * Mapping.Scale;
      UpdateSlotValue(Context, Mapping.Target, OtherSlot, NewMappedValue);
    }
  }
}
Пример #29
0
//Split (Tokenize) string at specified intervals
	//s == string to split
	//retArray == split up string (out)
	//cpszExp == expression to split at
	//crnStart == start postion to split
	//crnCount == max number of split of strings
	//crbCIComp == true if case insensitive
	void Split( const wxString& s, wxArrayString& retArray,  const wxChar* cpszExp, 
				const size_t& crnStart = 0, const size_t& crnCount = (size_t)-1,
				const bool& crbCIComp = false)
	{
		//sanity checks
		wxASSERT_MSG(cpszExp != NULL, wxT("Invalid value for First Param of wxString::Split (cpszExp)"));
		//wxASSERT_MSG(crnCount >= (size_t)-1, wxT("Invalid value for Third Param of wxString::Split (crnCount)"));

		retArray.Clear();

		size_t  nOldPos = crnStart,	  //Current start position in this string
				nPos = crnStart;	  //Current end position in this string

		wxString szComp,			//this string as-is (if bCIComp is false) or converted to lowercase
				 szExp = cpszExp;   //Expression string, normal or lowercase

		if (crbCIComp)
		{
			szComp = s.Lower();
			szExp.MakeLower();
		}
		else
			szComp = s;

		if(crnCount == (size_t)-1)
		{
		for (; (nPos = szComp.find(szExp, nPos)) != wxString::npos;)//Is there another token in the string
			{
			retArray.Add(Slice(s, nOldPos, nPos)); //Insert the token in the array
			nOldPos = nPos += szExp.Length();//Move up the start slice position
			}
	   
		}
		else
		{
		for (int i = crnCount;
				(nPos = szComp.find(szExp, nPos)) != wxString::npos &&
				i != 0;
					--i)//Is there another token in the string && have we met nCount?
		{
			retArray.Add(Slice(s, nOldPos, nPos)); //Insert the token in the array
			nOldPos = nPos += szExp.Length();//Move up the start slice position
		}
		}
		if (nOldPos != s.Length())
			retArray.Add( Slice(s, nOldPos, s.Length()) ); //Add remaining characters in string
	}
void WrapperDirect3DIndexBuffer9::put_y_mesh(int vb_id, INT BaseVertexIndex, UINT startIndex, YMesh* y_mesh) {
	memset(mesh_arr, 0, sizeof mesh_arr);
	mesh_arr[0] = vb_id;
	mesh_arr[1] = BaseVertexIndex;
	mesh_arr[2] = startIndex;

	mesh_table_.insert( Slice((char*)mesh_arr, 12), y_mesh );
}