コード例 #1
0
ファイル: patterntable.cpp プロジェクト: koukou73gr/seiscomp3
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bool PatternTable::read(const char *filename) {
	ifstream ifs;
	ifs.open(filename);
	if ( !ifs.is_open() ) return false;

	string line;
	while ( getline(ifs, line) ) {
		Core::trim(line);
		if ( line.empty() ) continue;
		if ( line[0] == '#' ) continue;

		vector<string> cols;
		Core::split(cols, line.c_str(), " ");
		if ( cols.size() == 4 )
			_rows.push_back(Row(Key(cols[0], cols[1]), Value(cols[2], cols[3])));
		else if ( cols.size() == 3 )
			_rows.push_back(Row(Key(cols[0], cols[1]), Value(cols[2], "")));
	}

	return true;
}
コード例 #2
0
std::string FldToStr(FLD f)
{
	if (f == NF)
		return "-";

	char buf[3];
	buf[0] = static_cast<char>('a' + Col(f));
	buf[1] = static_cast<char>('8' - Row(f));
	buf[2] = 0;

	return std::string(buf);
}
コード例 #3
0
ファイル: Matrix.cpp プロジェクト: eyeq/Matrix
double Matrix::Trace() const {
	if (!IsSquare()) {
		throw "Exception : Not a square matrixe.\n";
		exit(EXIT_FAILURE);
	}

	double f = 0.0;
	for (int i = 0; i < Row(); i++) {
		f += (*this)(i, i);
	}
	return f;
}
コード例 #4
0
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();

		auto cameraMatrix = CamMatrixf::Orbiting(
			Vec3f(0.0f, 3.0f, 0.0f),
			8.0f,
			FullCircles(time / 12.0),
			Degrees(SineWave(time / 20.0) * 80)
		);

		plane.Bind();
		plane_prog.Use();
		Uniform<Mat4f>(plane_prog, "CameraMatrix").Set(cameraMatrix);

		gl.DrawArrays(PrimitiveType::TriangleStrip, 0, 4);

		gl.Enable(Capability::Blend);

		volume.Bind();
		volume_prog.Use();
		Uniform<Mat4f>(volume_prog, "CameraMatrix").Set(cameraMatrix);
		Uniform<Vec3f>(volume_prog, "ViewX").Set(
			cameraMatrix.Row(0).xyz()
		);
		Uniform<Vec3f>(volume_prog, "ViewY").Set(
			cameraMatrix.Row(1).xyz()
		);
		Uniform<Vec3f>(volume_prog, "ViewZ").Set(
			cameraMatrix.Row(2).xyz()
		);
		gl.DrawArraysInstanced(
			PrimitiveType::Points,
			0, 1,
			samples
		);

		gl.Disable(Capability::Blend);
	}
コード例 #5
0
mtp::u32 MtpObjectsModel::createDirectory(const QString &name, mtp::AssociationType type)
{
	QModelIndex existingDir = findObject(name);
	if (existingDir.isValid())
		return _rows.at(existingDir.row()).ObjectId;

	mtp::u32 storageId = _storageId != mtp::Session::AllStorages? _storageId: mtp::Session::Device;
	mtp::Session::NewObjectInfo noi = _session->CreateDirectory(toUtf8(name), _parentObjectId, storageId, type);
	beginInsertRows(QModelIndex(), _rows.size(), _rows.size());
	_rows.push_back(Row(noi.ObjectId));
	endInsertRows();
	return noi.ObjectId;
}
コード例 #6
0
ファイル: Matrix.cpp プロジェクト: eyeq/Matrix
double Matrix::Abs() const {
	if (!IsSquare()) {
		throw "Exception : Not a square matrixe.\n";
		exit(EXIT_FAILURE);
	}

	Matrix m = UpperTriangular();
	double f = 1.0;
	for (int i = 0; i < Row(); i++) {
		f *= m(i, i);
	}
	return f;
}
コード例 #7
0
ファイル: RowFormWidget.cpp プロジェクト: StefanL74/XCSoar
void
RowFormWidget::Add(Row::Type type, Window *window)
{
  assert(IsDefined());
#ifndef USE_GDI
  assert(window->GetParent() == GetWindow());
#endif
  assert(window->IsVisible());
  /* cannot append rows after a REMAINING row */
  assert(rows.empty() || rows.back().type != Row::Type::REMAINING);

  rows.push_back(Row(type, window));
}
コード例 #8
0
ファイル: 026_clouds.cpp プロジェクト: xdray/oglplus
    void Render(double time)
    {
        gl.Clear().ColorBuffer().DepthBuffer();

        auto lightPos = light_path.Position(time * 0.05);
        auto cameraMatrix = CamMatrixf::Orbiting(
                                Vec3f(),
                                4.5f,
                                Degrees(0),
                                Degrees(SineWave(time / 20.0) * 80)
                            );

        light.Bind();
        light_prog.Use();

        Uniform<Vec3f>(light_prog, "LightPos").Set(lightPos);
        Uniform<Mat4f>(light_prog, "CameraMatrix").Set(cameraMatrix);

        sphere_instr.Draw(sphere_indices);

        clouds.Bind();
        cloud_prog.Use();

        Uniform<Vec3f>(cloud_prog, "LightPos").Set(lightPos);
        Uniform<Mat4f>(cloud_prog, "CameraMatrix").Set(cameraMatrix);
        Uniform<Vec4f>(cloud_prog, "ViewX").Set(cameraMatrix.Row(0));
        Uniform<Vec4f>(cloud_prog, "ViewY").Set(cameraMatrix.Row(1));
        Uniform<Vec4f>(cloud_prog, "ViewZ").Set(cameraMatrix.Row(2));
        for(std::size_t i=0, n=positions.size(); i!=n; ++i)
        {
            cloud_tex[i].Bind(Texture::Target::_3D);
            gl.DrawArraysInstanced(
                PrimitiveType::Points,
                i, 1,
                samples
            );
        }
    }
コード例 #9
0
WgTableHook * WgTableHook::PrevInRow() const
{
	WgTableRow* pRow = Row();
	int col = ColumnNb()-1;

	while( col >= 0 )
	{
		if( pRow->m_pCells[col].Widget() )
			return &pRow->m_pCells[col];
		col--;
	}

	return 0;
}
コード例 #10
0
void EditCoursesMenu::Down()
{
	if( m_bInSongMenu )
	{
		m_SongMenu.Down();
		return;
	}

	if( CanGoDown() )
	{
		ChangeToRow( Row(m_SelectedRow+1) );
		m_soundChangeRow.Play();
	}
}
コード例 #11
0
WgTableHook * WgTableHook::NextInRow() const
{
	WgTableRow* pRow = Row();
	int col = ColumnNb()+1;

	while( col < pRow->m_nCells )
	{
		if( pRow->m_pCells[col].Widget() )
			return &pRow->m_pCells[col];
		col++;
	}

	return 0;
}
コード例 #12
0
ファイル: result.cpp プロジェクト: AndreasWelchlin/tntdb
    Row Result::getRow(size_type tup_num) const
    {
      log_debug("mysql_data_seek(" << tup_num << ')');
      ::mysql_data_seek(result, tup_num);

      log_debug("mysql_fetch_row");
      MYSQL_ROW row = ::mysql_fetch_row(result);
      if (row == 0)
        throw MysqlError("mysql_fetch_row", mysql);

      const IResult* resc = this;
      IResult* res = const_cast<IResult*>(resc);
      return Row(new ResultRow(tntdb::Result(res), result, row));
    }
コード例 #13
0
WgTableHook * WgTableHook::NextInColumn() const
{
	WgTableRow* pRow = Row()->Next();
	int col = ColumnNb();

	while( pRow )
	{
		if( pRow->m_nCells > col && pRow->m_pCells[col].Widget() )
			return &pRow->m_pCells[col];

		pRow = pRow->Next();
	}

	return 0;
}
コード例 #14
0
ファイル: res-f4.cpp プロジェクト: gblanco92/M2
void F4Res::makeMatrix()
{
  auto& myframe = mFrame.level(mThisLevel);
  long r = 0;
  long comp = 0;
  for (auto it = myframe.begin(); it != myframe.end(); ++it)
    {
      if (it->mDegree == mThisDegree)
        {
          mSPairs.push_back(Row());
          mSPairComponents.push_back(comp);
          Row& row = mSPairs[r];
          r++;
          row.mLeadTerm = it->mMonom;
          loadRow(row);
          if (M2_gbTrace >= 4)
            if (r % 5000 == 0)
              std::cout << "makeMatrix  sp: " << r << " #rows = " << mColumns.size() << std::endl;
        }
      comp++;
    }
  // Now we process all monomials in the columns array
  while (mNextReducerToProcess < mColumns.size())
    {
      // Warning: mReducers is being appended to during 'loadRow', and 
      // since we act on the Row directly, it might get moved on us!
      // (actually, it did get moved, which prompted this fix)
      Row thisrow;
      std::swap(mReducers[mNextReducerToProcess], thisrow);
      loadRow(thisrow);
      std::swap(mReducers[mNextReducerToProcess], thisrow);
      mNextReducerToProcess++;
      if (M2_gbTrace >= 4)
        if (mNextReducerToProcess % 5000 == 0)
          std::cout << "makeMatrix red: " << mNextReducerToProcess << " #rows = " << mReducers.size() << std::endl;
    }

#if 0
  std :: cout << "-- reducer matrix --" << std::endl;
  debugOutputMatrix(mReducers);
  debugOutputMatrixSparse(mReducers);

  std :: cout << "-- spair matrix --" << std::endl;
  debugOutputMatrix(mSPairs);
  debugOutputMatrixSparse(mSPairs);
#endif
  reorderColumns();
}
コード例 #15
0
ファイル: SimpleSurface.cpp プロジェクト: madrazo/lime
	void SimpleSurface::BlitTo (const RenderTarget &outDest, const Rect &inSrcRect, int inPosX, int inPosY, BlendMode inBlend, const BitmapCache *inMask, uint32 inTint) const {
		
		if (!mBase)
			return;
		
		// Translate inSrcRect src_rect to dest ...
		Rect src_rect (inPosX, inPosY, inSrcRect.w, inSrcRect.h);
		// clip ...
		src_rect = src_rect.Intersect (outDest.mRect);
		
		if (inMask)
			src_rect = src_rect.Intersect (inMask->GetRect ());
		
		// translate back to source-coordinates ...
		src_rect.Translate (inSrcRect.x-inPosX, inSrcRect.y - inPosY);
		// clip to origial rect...
		src_rect = src_rect.Intersect (inSrcRect);
		
		if (src_rect.HasPixels ()) {
			
			bool src_alpha = (mPixelFormat == pfAlpha);
			bool dest_alpha = (outDest.mPixelFormat == pfAlpha);
			
			int dx = inPosX + src_rect.x - inSrcRect.x;
			int dy = inPosY + src_rect.y - inSrcRect.y;
			
			// Check for overlap....
			if (src_alpha == dest_alpha) {
				
				int size_shift = (!src_alpha ? 2 : 0);   //fix for IDX8
				int d_base = (outDest.mSoftPtr - mBase);
				int y_off = d_base / mStride;
				int x_off = (d_base - y_off * mStride) >> size_shift;
				Rect dr (dx + x_off, dy + y_off, src_rect.w, src_rect.h);
				if (src_rect.Intersect (dr).HasPixels ()) {
					
					SimpleSurface sub (src_rect.w, src_rect.h, mPixelFormat);
					Rect sub_dest (0, 0, src_rect.w, src_rect.h);
					
					for (int y = 0; y < src_rect.h; y++)
						memcpy ((void *)sub.Row (y), Row (src_rect.y + y) + (src_rect.x << size_shift), src_rect.w << size_shift);
					
					sub.BlitTo (outDest, sub_dest, dx, dy, inBlend, 0, inTint);
					return;
					
				}
				
			}
コード例 #16
0
WgTableHook * WgTableHook::NextInTable() const
{
	WgTableHook * p = NextInRow();

	if( !p )
	{
		WgTableRow* pRow = Row()->Next();
		while( pRow && !p )
		{
			p = pRow->FirstHook();
			pRow = pRow->Next();
		}
	}

	return p;
}
コード例 #17
0
ファイル: mnuttt.c プロジェクト: DhruvRelwani/GamesmanClassic
POSITION DoMove (POSITION position, MOVE move)
{
	char board[BOARD_SIZE];
	int current_player = generic_hash_turn(position);
	int move_position = Unhasher_Index(move);
	int row = Row (move_position);
	int col = Column (move_position);
	int direction = Unhasher_Direction(move);
	int new_position = Index(row + dir_increments[direction][0], \
	                         col + dir_increments[direction][1]);

	generic_hash_unhash (position, board);
	board[new_position] = board[move_position];
	board[move_position] = (char) EMPTY_PIECE;
	return generic_hash_hash(board, (current_player == PLAYER1_TURN ? PLAYER2_TURN : PLAYER1_TURN));
}
コード例 #18
0
ファイル: Matrix.cpp プロジェクト: eyeq/Matrix
Matrix::Matrix(int row, int column, double initValue) : row(row), column(column) {
	if (Row() < 1 || Column() < 1) {
		throw "Exception : Invailed matrix size.\n";
		exit(EXIT_FAILURE);
	}

	this->values = new double[Size()];
	if (!Values()) {
		throw "Exception : Can not allocate memory.\n";
		exit(EXIT_FAILURE);
	}

	for (long i = 0; i < Size(); i++) {
		(*this)(i) = initValue;
	}
}
コード例 #19
0
void MtpObjectsModel::setParent(mtp::u32 parentObjectId)
{
	beginResetModel();

	_parentObjectId = parentObjectId;
	mtp::msg::ObjectHandles handles = _session->GetObjectHandles(_storageId, mtp::Session::AllFormats, parentObjectId);
	_rows.clear();
	_rows.reserve(handles.ObjectHandles.size());
	for(size_t i = 0; i < handles.ObjectHandles.size(); ++i)
	{
		mtp::u32 oid = handles.ObjectHandles[i];
		_rows.append(Row(oid));
	}

	endResetModel();
}
コード例 #20
0
ファイル: shapemodel.cpp プロジェクト: MosaicHe/amazingcomic
SHAPE TransformShape (const SHAPE &Shape, const Mat &TransformMat)
{
ASSERT(Shape.ncols() == 2);
ASSERT(TransformMat.ncols() == 3 || TransformMat.nrows() == 2);

SHAPE OutShape(Shape);
int iRow = Shape.nrows();
while (iRow--)
    if (fPointUsed(Shape, iRow))  // points at 0,0 must remain at 0,0
        {
        MatView Row(OutShape.row(iRow));
        Row = TransformMat.mat33TimesVec2(Row);
        }

return OutShape;
}
コード例 #21
0
StoreQueryResult::StoreQueryResult(MYSQL_RES * res_, Connection * conn_, const Query * query_) : ResultBase(res_, conn_, query_)
{
    UInt64 rows = mysql_num_rows(res);
    UInt32 fields = getNumFields();
    reserve(rows);
    lengths.resize(rows * fields);

    for (UInt64 i = 0; MYSQL_ROW row = mysql_fetch_row(res); ++i)
    {
        MYSQL_LENGTHS lengths_for_row = mysql_fetch_lengths(res);
        memcpy(&lengths[i * fields], lengths_for_row, sizeof(lengths[0]) * fields);

        push_back(Row(row, this, &lengths[i * fields]));
    }
    checkError(conn->getDriver());
}
コード例 #22
0
WgTableHook * WgTableHook::PrevInTable() const
{
	WgTableHook * p = PrevInRow();

	if( !p )
	{
		WgTableRow* pRow = Row()->Prev();
		while( pRow && !p )
		{
			p = pRow->LastHook();
			pRow = pRow->Prev();
		}
	}

	return p;
}
コード例 #23
0
bool MtpObjectsModel::uploadFile(const QString &filePath, QString filename)
{
	QFileInfo fileInfo(filePath);
	mtp::ObjectFormat objectFormat = mtp::ObjectFormatFromFilename(toUtf8(filePath));

	if (filename.isEmpty())
		filename = fileInfo.fileName();

	qDebug() << "uploadFile " << fileInfo.fileName() << " as " << filename;

	bool needReset = false;
	QModelIndex existingObject = findObject(filename);
	if (existingObject.isValid())
	{
		if (!emit existingFileOverwrite(filename))
		{
			qDebug() << "skipping, overwrite not confirmed";
			return false;
		}
		_session->DeleteObject(_rows.at(existingObject.row()).ObjectId);
		needReset = true;
	}

	std::shared_ptr<QtObjectInputStream> object(new QtObjectInputStream(filePath));
	if (!object->Valid())
	{
		qWarning() << "file " << filePath << " could not be opened";
		return false;
	}
	qDebug() << "sending " << fileInfo.size() << " bytes";
	connect(object.get(), SIGNAL(positionChanged(qint64,qint64)), this, SIGNAL(filePositionChanged(qint64,qint64)));

	mtp::msg::ObjectInfo oi;
	oi.Filename = toUtf8(filename);
	oi.ObjectFormat = objectFormat;
	oi.SetSize(fileInfo.size());
	mtp::Session::NewObjectInfo noi = _session->SendObjectInfo(oi, _storageId != mtp::Session::AllStorages? _storageId: mtp::Session::Device, _parentObjectId);
	qDebug() << "new object id: " << noi.ObjectId << ", sending...";
	_session->SendObject(object);
	qDebug() << "ok";
	beginInsertRows(QModelIndex(), _rows.size(), _rows.size());
	_rows.push_back(Row(noi.ObjectId));
	endInsertRows();
	if (needReset)
		refresh();
	return true;
}
コード例 #24
0
PrintTable &
PrintTable::at(
    size_t        row,
    size_t        col)
{
    for (Table::size_type i = m_table.size(); i <= row; ++i)
        m_table.push_back(Row());
    for (Row::size_type i = m_table[row].size(); i <= col; ++i)
        m_table[row].push_back(Cell());

    m_currentCell.m_string = std::string(m_currentCell.m_indent*2, ' ') + m_currentString.str();
    m_table[row][col] = m_currentCell;

    m_currentCell = Cell();
    m_currentString.str("");

    return *this;
}
コード例 #25
0
ファイル: lsq.c プロジェクト: HiromuIshikawa/MakePanoExp
void MatrixQRDecompColMajor(Matrix*mtR,Matrix*mt){
  // gram-schmidt orthonormalization (Lt and Q)
  double t, *aT[mt->W];
  int W = mt->W;
  int i,j;
  MatrixClear(mtR); 
  for (i = 0; i < W;i++) {
    aT[i] = Row(mt,i);
    for (j = 0; j < i; j++) {
      Elem(mtR,j,i) = t = VP(aT[j], aT[i], W);
      VSA(aT[i], aT[j], -t, W);
    }
    Elem(mtR,i,i) = t = sqrt(VP(aT[i],aT[i],W));
    VSS(aT[i], 1/t, W); 
  }




  /*

  Elem(mtR,0,0) = t = sqrt(VP(aT[0],aT[0],W));
  VSS(aT[0], 1/t, W);


  Elem(mtR,0,1) = t = VP(aT[0], aT[1], W);
  VSA(aT[1], aT[0], -t, W);

  Elem(mtR,1,1) = t = sqrt(VP(aT[1],aT[1],W));
  VSS(aT[1], 1/t, W);

///////////
  Elem(mtR,0,2) = t = VP(aT[0], aT[2], W);
  VSA(aT[2], aT[0], -t, W);

  Elem(mtR,1,2) = t = VP(aT[1], aT[2], W);
  VSA(aT[2], aT[1], -t, W);

  Elem(mtR,2,2) = t = sqrt(VP(aT[2],aT[2],W));
  VSS(aT[2], 1/t, W);

////// 以下略
*/
}
コード例 #26
0
ファイル: lsq.c プロジェクト: HiromuIshikawa/MakePanoExp
void MatrixSimeqLr(Matrix*mtB,Matrix*mtR){
  // B = B L^{-1}
  double * B = Row(mtB,0);
  int i,j;
  for (i = mtB->W - 1; i >= 0; i--) {
    for (j = i+1; j < mtB->W; j++) {
      B[i] = B[i]-B[j]*Elem(mtR,i,j);
    }
    B[i] = B[i] / Elem(mtR,i,i);
  }

  /*
  B[7] =  B[7] / Elem(mtR,7,7);
  B[6] = (B[6]-B[7]*Elem(mtR,6,7)) / Elem(mtR,6,6);
  B[5] = (B[5]-B[6]*Elem(mtR,5,6)-B[7]*Elem(mtR,5,7)) / Elem(mtR,5,5);
///// 以下略
*/
  
}
コード例 #27
0
ファイル: qhistable.cpp プロジェクト: apmckinlay/csuneido
Row HistoryTable::get(Dir dir) {
	void* p;
	Mmoffset offset;
	do {
		offset = dir == NEXT ? next() : prev();
		if (offset == 0)
			return Eof;
		p = theDB()->mmf->adr(offset - sizeof(int));
	} while (*(int*) p != tblnum);
	Record r1;
	Commit* commit = (Commit*) *iter;
	r1.addval(SuDate::parse(ctime(&commit->t)));
	r1.addval(dir == NEXT
			? 0 <= ic && ic < commit->ncreates ? "create" : "delete"
			: 0 <= id && id < commit->ndeletes ? "delete" : "create");
	Record r2(theDB()->mmf, offset);
	static Record emptyrec;
	return Row(lisp(emptyrec, r1, emptyrec, r2));
}
コード例 #28
0
void CMembersView::OnEdit()
{
	// Ignore if no selection.
	if (!m_lvGrid.IsSelection())
		return;

	// Get the current selection.
	int   iLVItem = m_lvGrid.Selection();
	CRow& oRow    = Row(iLVItem);

	CMemberDlg Dlg(m_oDB, oRow, true);

	if (Dlg.RunModal(*this) == IDOK)
	{
		// Update the list view.
		UpdateRow(iLVItem, true);

		App.m_AppCmds.UpdateUI();
	}
}
コード例 #29
0
ファイル: decoderstack.cpp プロジェクト: zeldin/pulseview
void DecoderStack::annotation_callback(srd_proto_data *pdata, void *decoder)
{
	assert(pdata);
	assert(decoder);

	DecoderStack *const d = (DecoderStack*)decoder;
	assert(d);

	lock_guard<mutex> lock(d->_output_mutex);

	const Annotation a(pdata);

	// Find the row
	assert(pdata->pdo);
	assert(pdata->pdo->di);
	const srd_decoder *const decc = pdata->pdo->di->decoder;
	assert(decc);

	auto row_iter = d->_rows.end();
	
	// Try looking up the sub-row of this class
	const auto r = d->_class_rows.find(make_pair(decc, a.format()));
	if (r != d->_class_rows.end())
		row_iter = d->_rows.find((*r).second);
	else
	{
		// Failing that, use the decoder as a key
		row_iter = d->_rows.find(Row(decc));	
	}

	assert(row_iter != d->_rows.end());
	if (row_iter == d->_rows.end()) {
		qDebug() << "Unexpected annotation: decoder = " << decc <<
			", format = " << a.format();
		assert(0);
		return;
	}

	// Add the annotation
	(*row_iter).second.push_annotation(a);
}
コード例 #30
0
ファイル: Matrix.cpp プロジェクト: eyeq/Matrix
Matrix Matrix::Inverse() const {
	if (!IsSquare()) {
		throw "Exception : Not a square matrixe.\n";
		exit(EXIT_FAILURE);
	}

	Matrix m = Clone();
	const int N = Row();
	Matrix e = IdentityMatrix(N);
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			if (abs(m(i, i)) < abs(m(j, i))) {
				m.SwapRow(i, j);
			}
		}
		double aii = m(i, i);
		if (aii == 0.0) {
			throw "Exception : Can not calculate.\n";
			exit(EXIT_FAILURE);
		}

		for (int j = 0; j < N; j++) {
			m(i, j) /= aii;
			e(i, j) /= aii;
		}
		for (int j = 0; j < N; j++) {
			if (i == j) {
				continue;
			}
			double aji = m(j, i);
			for (int k = 0; k < N; k++) {
				m(j, k) -= m(i, k) * aji;
				e(j, k) -= m(i, k) * aji;
			}
		}
	}
	return e;
}