Vec2f GridLayout::layoutSize(const MFUnrecChildComponentPtr* Components, const Component* ParentComponent, SizeType TheSizeType) const
{
    if(getRows() == 0 || getColumns() == 0)
    {
        return Vec2f(1.0f,1.0f);
    }

	Real32 maxSizeX = 0.0f;
	Real32 maxSizeY = 0.0f;

    Vec2f ComponentSize;
	//set the size to the perfered sizes for the buttons
	for(UInt16 i = 0; i<Components->size(); i++){
		if ((*Components)[i] != NULL) 
		{
            ComponentSize = getComponentSize((*Components)[i],TheSizeType);
			if(ComponentSize.x()>maxSizeX)
				maxSizeX = ComponentSize.x();
			if(ComponentSize.y()>maxSizeY)
				maxSizeY = ComponentSize.y();
		}
	}

    return Vec2f(maxSizeX * static_cast<Real32>(getColumns()) + getHorizontalGap() * static_cast<Real32>(getColumns()-1),
                 maxSizeY * static_cast<Real32>(getRows()) + getVerticalGap() * static_cast<Real32>(getRows()-1));
}
Example #2
0
double SqMRO_Cofactor::operator()(const unsigned int row, const unsigned int column) const {

	SquareMatrix newSquareMatrix(getRows() - 1);
	double sign;

	if (row >= getRows() || column >= getColumns()) {
		error("SquareMatrixAlias::cofactor : Subscript out of range\n");
		return 0;
	}

	sign = (row + column) % 2 ? -1 : 1;

	// Top left quadrant
	if (row > 0 && column > 0) {
		newSquareMatrix.subMatrix(0, row-1, 0, column-1) = m_thisMatrix->subMatrix(0, row-1, 0, column-1);
	}
	// Top right quadrant
	if (row > 0 && column < (getColumns() - 1)) {
		newSquareMatrix.subMatrix(0, row-1, column, getColumns()-2) = m_thisMatrix->subMatrix(0, row-1, column+1, getColumns()-1);
	}
	// Bottom left quadrant
	if (row < (getRows() - 1) && column > 0) {
		newSquareMatrix.subMatrix(row, getRows()-2, 0, column-1) = m_thisMatrix->subMatrix(row+1, getRows()-1, 0, column-1);
	}
	// Bottom right quadrant
	if (row < (getRows() - 1) && column < (getColumns() - 1)) {
		newSquareMatrix.subMatrix(row, getRows()-2, column, getColumns()-2) = m_thisMatrix->subMatrix(row+1, getRows()-1, column+1, getColumns()-1);
	}

	return sign * newSquareMatrix.determinant();
}
void SqliteTableModel::setTable(const QString& table)
{
    reset();

    m_sTable = table;

    QString sColumnQuery = QString::fromUtf8("SELECT * FROM `%1`;").arg(table);
    if(m_db->getObjectByName(table).gettype() == "table")
    {
        sqlb::Table t = sqlb::Table::parseSQL(m_db->getObjectByName(table).getsql()).first;
        if(t.name() != "") // parsing was OK
        {
            m_headers.push_back(t.rowidColumn());
            m_headers.append(m_db->getTableFields(table));
        }
        else
        {
            m_headers.push_back("rowid");
            m_headers.append(getColumns(sColumnQuery));
        }
    }
    else
    {
        m_headers.push_back("rowid");
        m_headers.append(getColumns(sColumnQuery));
    }

    buildQuery();
}
Example #4
0
void MWO_EqualsElementCopyResize::operator()(const MatrixAliasConstant& copy) const
{
		unsigned int i, j;

		//printf("MWO_EqualsElementCopyResize called\n");

		//printf("copy.getRows():%d\ngetRows():%d\ncopy.getColumns():%d\ncopy.getColumns():%d\n",copy.getRows(),getRows(),copy.getColumns(),copy.getColumns());

		if(copy.getRows() != getRows() || copy.getColumns() != getColumns()) {
			// Resize!!

			// Change values
			setRows(copy.getRows());
			setColumns(copy.getColumns());

			// Delete old memory
			delete[] getDataPointer();

			// Allocate new memory
			setDataPointer(new double[getRows()*getColumns()]);
		}


		for (i = 0; i < getRows(); i++) {
			for (j = 0; j < getColumns(); j++) {
				element(i, j) = copy.element(i, j);
			}
		}

}
Example #5
0
void RVWO_EqualsElementCopyResize::operator()(const MatrixAliasConstant& copy) const
{
		unsigned int i;

		if(copy.isRowVector() == 0)
		{
			error("RVWO_EqualsElementCopyResize: Matrix to copy is not a row vector\n");
			return;
		}


		if(copy.getColumns() != getColumns()) {
			// Resize!!

			// Change values
			setColumns(copy.getColumns());

			// Delete old memory
			delete[] getDataPointer();

			// Allocate new memory
			setDataPointer(new double[getColumns()]);
		}


		for (i = 0; i < getColumns(); i++) {
			element(0, i) = copy.element(0, i);
		}

}
Example #6
0
void SqMWO_EqualsElementCopyResize::operator()(const MatrixAliasConstant& copy) const
{
		unsigned int i, j;

		if(copy.isSquareMatrix() == 0)
		{
			error("SqMWO_EqualsElementCopyResize: Matrix to copy is not a square matrix\n");
			return;
		}


		if(copy.getColumns() != getColumns()) {
			// Resize!!

			// Change values
			setRows(copy.getRows());
			setColumns(copy.getColumns());

			// Delete old memory
			delete[] getDataPointer();

			// Allocate new memory
			setDataPointer(new double[getRows()*getColumns()]);
		}


		for (i = 0; i < getRows(); i++) {
			for (j = 0; j < getColumns(); j++) {
				element(i, j) = copy.element(i, j);
			}
		}
}
Example #7
0
Matrix MRO_Multiply::operator()(const MatrixAliasConstant& operand) const
{
	Matrix result(getRows(), operand.getColumns());
	double thisElement;
	unsigned int i, j, k;


	if (operand.getRows() != getColumns()) {
		error("MatrixAlias::operator* : Dimensions are not consistent\n");
		return result; // Return empty matrix
	}

	for (i = 0; i < getRows(); i++) {

		for (j = 0; j < operand.getColumns(); j++) {

			thisElement = 0;

			for (k = 0; k < getColumns(); k++) {
				thisElement += element(i, k) * operand.element(k, j);
			}

			result.element(i, j) = thisElement;
		}
	}

	return result;
}
Example #8
0
void GridLayout::updateLayout(const MFUnrecComponentPtr* Components, const Component* ParentComponent) const
{
	Pnt2f borderTopLeft, borderBottomRight;
	dynamic_cast<const ComponentContainer*>(ParentComponent)->getInsideInsetsBounds(borderTopLeft, borderBottomRight);
	Vec2f borderSize(borderBottomRight-borderTopLeft);

	Real32 Xpos = 0;
	Real32 Ypos = 0;
	Real32 maxSizeX = 0;
	Real32 maxSizeY = 0;
	Real32 debug = 10;
	Int32 numComp = Components->getSize();
	Real32 buttonXSize, buttonYSize;

	//set the size to the perfered sizes for the buttons
	for(UInt16 i = 0; i<Components->size(); i++){
		if ((*Components)[i] != NULL) 
		{
			if((*Components)[i]->getPreferredSize().x()>maxSizeX)
				maxSizeX = (*Components)[i]->getPreferredSize().x();
			if((*Components)[i]->getPreferredSize().y()>maxSizeY)
				maxSizeY = (*Components)[i]->getPreferredSize().y();
		}
	}
	//set the  size of the button
	for(UInt16 i = 0; i < Components->size(); i++){
		if ((*Components)[i] != NULL) 
		{
			if(maxSizeX < (*Components)[i]->getMaxSize().x())
				buttonXSize = maxSizeX;
			else
				buttonXSize = (*Components)[i]->getMaxSize().x();
			if(maxSizeY<(*Components)[i]->getMaxSize().y())
				buttonYSize = maxSizeY;
			else
				buttonYSize = (*Components)[i]->getMaxSize().y();
			   (*Components)[i]->setSize(Vec2f(buttonXSize, buttonYSize));
		}
	}


	//position each button
	for(UInt16 i = 0; i <= getRows()&& numComp>=0; i++){
		if ((*Components)[i] != NULL) 
		{
			for(UInt16 j = 0; j < getColumns()&& numComp>0; j++){
				debug = i*getColumns()+j;
                   (*Components)[i*getColumns()+j]->setPosition(borderTopLeft + Vec2f(Xpos, Ypos));
				numComp--;
				Xpos = Xpos + (maxSizeX+getHorizontalGap());
			}
			Xpos = 0;
			Ypos += maxSizeY+getVerticalGap();
		}
	}
}
Example #9
0
//-----------------------------------------
//          Element Functions
//-----------------------------------------
double& MatrixWriteAccess::writeElement(const unsigned int row, const unsigned int column)
{
	if (row >= getRows() || column >= getColumns()) {
		error("MatrixAlias::element : Subscript out of range\n");
		return getDataPointer()[0];
	}

	return getDataPointer()[row*(getColumns()) + column];

}
Example #10
0
double& SubMatrixWriteAccess::writeElement(const unsigned int index)
{
	if (index >= (getRows()*getColumns())) {
		error("Matrix::element : Subscript out of range\n");
		return getDataPointer()[0];
	}

	return writeElement(index / getColumns(), index % getColumns());

}
Example #11
0
void MWO_EqualsMemCopy::operator()(const MatrixAliasConstant& copy) const
{
		if(copy.getRows() != getRows() || copy.getColumns() != getColumns()) {
			error("MWO_EqualsMemCopy : Dimensions are not consistent\n");
			return;
		}

		// Perform a direct memory copy
		memcpy(getDataPointer(), copy.getDataPointer(), sizeof(double)*getRows()*getColumns());

}
Example #12
0
Matrix MRO_Multiply::operator()(const double& operand) const
{
	Matrix result(getRows(), getColumns());
	unsigned int i, j;

	for (i = 0; i < getRows(); i++) {
		for (j = 0; j < getColumns(); j++) {
			result.element(i, j) = element(i, j) * operand;
		}
	}

	return result;
}
Example #13
0
Matrix MRO_Absolute::operator()() const {

	Matrix newMatrix(getColumns(), getRows());
	unsigned int i, j;

	for (i = 0; i < getRows(); i++) {
		for (j = 0; j < getColumns(); j++) {
			newMatrix.element(i, j) = fabs(element(i, j));
		}
	}

	return newMatrix;
}
Example #14
0
Matrix MRO_Transpose::operator()() const {

	Matrix newMatrix(getColumns(), getRows());
	unsigned int i, j;

	for (i = 0; i < getRows(); i++) {
		for (j = 0; j < getColumns(); j++) {
			newMatrix.element(j, i) = element(i, j);
		}
	}

	return newMatrix;
}
Example #15
0
Geometry::Geometry(int n_vertex, std::vector<int> attributes, const float* data) :
	n_vertex(n_vertex), attributes(attributes) {

	// save to RAM
	raw_data.reserve(n_vertex * getColumns());
	for(int i = 0; i < n_vertex * getColumns(); i++) {
		raw_data.push_back(data[i]);
	}

	glGenVertexArrays(1, &vertex_array);
	glGenBuffers(1, &vertex_buffer);

	sendToGPU();
}
Example #16
0
void MRO_PrintMatlabFriendly::operator()() const
{

	unsigned int i, j;
	printf("[\n");
	for (i = 0; i < getRows(); i++) {
		for (j = 0; j < (getColumns()-1); j++) {
			printf("%.2lf  ", element(i, j));
		}
		printf("%.2lf;", element(i, getColumns()-1));
		printf("\n");
	}
	printf("]\n");
}
Example #17
0
int Board::findOpenColumn( unsigned int current, int step ) const
{
	unsigned int started = current;
	current += step;
	if ( current == getColumns() ) { current = 0; }
	current = clamp( current, 0U, getColumns()-1 );
	while ( get( current, 0 ) ) {
		if ( current == started ) { return -1; }
		current += step;
		if ( current == getColumns() ) { current = 0; }
		current = clamp( current, 0U, getColumns()-1 );
	}
	return current;
}
Example #18
0
RowVector MRO_ColumnSum::operator()() const {

	RowVector newVector(getColumns());
	unsigned int i, j;

	for (j = 0; j < getColumns(); j++) {
		newVector.element(j) = 0;
		for (i = 0; i < getRows(); i++) {
			newVector.element(j) += element(i, j);
		}
	}

	return newVector;
}
Example #19
0
const double& SimInputVectorReadAccess::readElement(const unsigned int row, const unsigned int column)
{

	// Cast data pointer
	const double * const * dataPointer = (const double * const *)getDataPointer();

	if (row >= getRows() || column >= getColumns()) {
		error("MatrixAlias::element : Subscript out of range\n");
		return *dataPointer[0];
	}



	return *(dataPointer[row*(getColumns()) + column]);
}
CharacteristicValue CharacteristicDefinition::getValue(const cv::Mat& img, bool skip_datacalc) const
{
    CharacteristicValue val;
    val.definition = this;
    val.weight = 0.0;

    //init result grid
    std::vector<std::vector<double> > grid(getRows());
    for (int r=0 ; r<getRows() ; r++)
    {
        grid[r] = std::vector<double>(getColumns());
    }

    //fill result grid
    if (!classify_frame(img, val, grid, skip_datacalc))
        std::cerr << "UNKNOWN ERROR processing frame" << std::endl;

    //process results
    int pos_tally = 0;
    int neg_tally = 0;
    double pos_sum = 0.0;
    double neg_sum = 0.0;

    for (int row=0 ; row<getRows() ; row++)
    {
        for (int col=0 ; col<getColumns() ; col++)
        {
            if (grid[row][col] > 0)
            {
                pos_tally++;
                pos_sum += grid[row][col];
            }
            else
            {
                neg_tally++;
                neg_sum += grid[row][col];
            }
        }
    }

    //save result
    if (pos_tally > 0 && pos_tally >= getRows()*getColumns()*getRequiredRatio())
        val.weight = pos_sum/pos_tally;
    else
        val.weight = neg_sum/neg_tally;

    return val;
}
void ITableDeclaration::check(const NamesAndTypesList & provided_columns, const Names & column_names) const
{
    const NamesAndTypesList & available_columns = getColumns().getAllPhysical();
    const auto available_columns_map = getColumnsMap(available_columns);
    const NamesAndTypesMap & provided_columns_map = getColumnsMap(provided_columns);

    if (column_names.empty())
        throw Exception("Empty list of columns queried. There are columns: " + listOfColumns(available_columns),
            ErrorCodes::EMPTY_LIST_OF_COLUMNS_QUERIED);

    using UniqueStrings = GOOGLE_NAMESPACE::dense_hash_set<StringRef, StringRefHash>;
    UniqueStrings unique_names;
    unique_names.set_empty_key(StringRef());

    for (const String & name : column_names)
    {
        NamesAndTypesMap::const_iterator it = provided_columns_map.find(name);
        if (provided_columns_map.end() == it)
            continue;

        NamesAndTypesMap::const_iterator jt = available_columns_map.find(name);
        if (available_columns_map.end() == jt)
            throw Exception("There is no column with name " + name + ". There are columns: "
                + listOfColumns(available_columns), ErrorCodes::NO_SUCH_COLUMN_IN_TABLE);

        if (!it->second->equals(*jt->second))
            throw Exception("Type mismatch for column " + name + ". Column has type "
                + jt->second->getName() + ", got type " + it->second->getName(), ErrorCodes::TYPE_MISMATCH);

        if (unique_names.end() != unique_names.find(name))
            throw Exception("Column " + name + " queried more than once",
                ErrorCodes::COLUMN_QUERIED_MORE_THAN_ONCE);
        unique_names.insert(name);
    }
}
Example #22
0
int MRO_IsColumnVector::operator()() const
{
	if(getColumns() == 1)
		return 1; // Matrix is column vector

	return 0; //  Matrix is NOT column vector
}
void CompressedDataColumn::convertColumnToDense(int nRows) {
	if (formatType == DENSE) {
		return;
	}

//	real_vector* oldData = data;
    RealVectorPtr oldData = data;
//	data = new real_vector();
    data = make_shared<RealVector>();
	
	data->resize(nRows, static_cast<real>(0));

	int* indicators = getColumns();
	int n = getNumberOfEntries();
//	int nonzero = 0;
	for (int i = 0; i < n; ++i) {
		const int k = indicators[i];
//		cerr << " " << k;
//		nonzero++;

		real value = (formatType == SPARSE) ? oldData->at(i) : 1.0;	

		data->at(k) = value;
	}
	formatType = DENSE;
//	delete columns; 
    columns = NULL;
//	if (oldData) {
//		delete oldData;
//	}
}
void ITableDeclaration::check(const Names & column_names) const
{
    const NamesAndTypesList & available_columns = getColumns().getAllPhysical();

    if (column_names.empty())
        throw Exception("Empty list of columns queried. There are columns: " + listOfColumns(available_columns),
            ErrorCodes::EMPTY_LIST_OF_COLUMNS_QUERIED);

    const auto columns_map = getColumnsMap(available_columns);

    using UniqueStrings = GOOGLE_NAMESPACE::dense_hash_set<StringRef, StringRefHash>;
    UniqueStrings unique_names;
    unique_names.set_empty_key(StringRef());

    for (const auto & name : column_names)
    {
        if (columns_map.end() == columns_map.find(name))
            throw Exception("There is no column with name " + name + " in table. There are columns: " + listOfColumns(available_columns),
                ErrorCodes::NO_SUCH_COLUMN_IN_TABLE);

        if (unique_names.end() != unique_names.find(name))
            throw Exception("Column " + name + " queried more than once",
                ErrorCodes::COLUMN_QUERIED_MORE_THAN_ONCE);
        unique_names.insert(name);
    }
}
Example #25
0
StorageTinyLog::StorageTinyLog(
    const std::string & path_,
    const std::string & name_,
    const ColumnsDescription & columns_,
    bool attach,
    size_t max_compress_block_size_)
    : IStorage{columns_},
    path(path_), name(name_),
    max_compress_block_size(max_compress_block_size_),
    file_checker(path + escapeForFileName(name) + '/' + "sizes.json"),
    log(&Logger::get("StorageTinyLog"))
{
    if (path.empty())
        throw Exception("Storage " + getName() + " requires data path", ErrorCodes::INCORRECT_FILE_NAME);

    String full_path = path + escapeForFileName(name) + '/';
    if (!attach)
    {
        /// create files if they do not exist
        if (0 != mkdir(full_path.c_str(), S_IRWXU | S_IRWXG | S_IRWXO) && errno != EEXIST)
            throwFromErrno("Cannot create directory " + full_path, ErrorCodes::CANNOT_CREATE_DIRECTORY);
    }

    for (const auto & col : getColumns().getAllPhysical())
        addFiles(col.name, *col.type);
}
Block ITableDeclaration::getSampleBlockForColumns(const Names & column_names) const
{
    Block res;

    NamesAndTypesList all_columns = getColumns().getAll();
    std::unordered_map<String, DataTypePtr> columns_map;
    for (const auto & elem : all_columns)
        columns_map.emplace(elem.name, elem.type);

    for (const auto & name : column_names)
    {
        auto it = columns_map.find(name);
        if (it != columns_map.end())
        {
            res.insert({ it->second->createColumn(), it->second, it->first });
        }
        else
        {
            /// Virtual columns.
            NameAndTypePair elem = getColumn(name);
            res.insert({ elem.type->createColumn(), elem.type, elem.name });
        }
    }

    return res;
}
void SqliteTableModel::setTable(const sqlb::ObjectIdentifier& table, int sortColumn, Qt::SortOrder sortOrder, const QMap<int, QString> filterValues, const QVector<QString>& display_format)
{
    // Unset all previous settings. When setting a table all information on the previously browsed data set is removed first.
    reset();

    // Save the other parameters
    m_sTable = table;
    m_vDisplayFormat = display_format;

    for(auto filterIt=filterValues.constBegin(); filterIt!=filterValues.constEnd(); ++filterIt)
        updateFilter(filterIt.key(), filterIt.value(), false);

    // The first column is the rowid column and therefore is always of type integer
    m_vDataTypes.push_back(SQLITE_INTEGER);

    // Get the data types of all other columns as well as the column names
    bool allOk = false;
    if(m_db.getObjectByName(table) && m_db.getObjectByName(table)->type() == sqlb::Object::Types::Table)
    {
        sqlb::TablePtr t = m_db.getObjectByName<sqlb::Table>(table);
        if(t && t->fields.size()) // parsing was OK
        {
            m_sRowidColumn = t->rowidColumn();
            m_headers.push_back(m_sRowidColumn);
            m_headers.append(t->fieldNames());

            // parse columns types
            static QStringList dataTypes = QStringList()
                    << "INTEGER"
                    << "REAL"
                    << "TEXT"
                    << "BLOB";
            for(const sqlb::Field& fld :  t->fields)
            {
                QString name(fld.type().toUpper());
                int colType = dataTypes.indexOf(name);
                colType = (colType == -1) ? SQLITE_TEXT : colType + 1;
                m_vDataTypes.push_back(colType);
            }
            allOk = true;
        }
    }

    // If for one reason or another (either it's a view or we couldn't parse the table statement) we couldn't get the field
    // information we retrieve it from SQLite using an extra query.
    // NOTE: It would be nice to eventually get rid of this piece here. As soon as the grammar parser is good enough...
    if(!allOk)
    {
        QString sColumnQuery = QString::fromUtf8("SELECT * FROM %1;").arg(table.toString());
        m_sRowidColumn = "rowid";
        m_headers.push_back("rowid");
        m_headers.append(getColumns(nullptr, sColumnQuery, m_vDataTypes));
    }

    // Set sort parameters. We're setting the sort column to an invalid value before calling sort() because this way, in sort() the
    // current sort order is always changed and thus buildQuery() is always going to be called.
    // This is also why we don't need to call buildQuery() here again.
    m_iSortColumn = -1;
    sort(sortColumn, sortOrder);
}
void SqliteTableModel::setQuery(const QString& sQuery, bool dontClearHeaders)
{
    // clear
    if(!dontClearHeaders)
        reset();

    if(!m_db->isOpen())
        return;

    m_sQuery = removeComments(sQuery).trimmed();

    // do a count query to get the full row count in a fast manner
    m_rowCount = getQueryRowCount();
    if(m_rowCount == -1)
    {
        m_valid = false;
        return;
    }

    // headers
    if(!dontClearHeaders)
    {
        m_headers.append(getColumns(sQuery));
    }

    // now fetch the first entries
    clearCache();
    fetchData(0, m_chunkSize);
    m_valid = true;

    emit layoutChanged();
}
void SqliteTableModel::setQuery(const QString& sQuery, bool dontClearHeaders)
{
    // clear
    if(!dontClearHeaders)
        reset();
    else
        clearCache();

    if(!m_db.isOpen())
        return;

    m_sQuery = sQuery.trimmed();
    removeCommentsFromQuery(m_sQuery);

    worker->setQuery(m_sQuery);
    worker->triggerRowCountDetermination(m_lifeCounter);

    if(!dontClearHeaders)
        m_headers.append(getColumns(worker->getDb(), sQuery, m_vDataTypes));

    // now fetch the first entries
    triggerCacheLoad(m_chunkSize / 2 - 1);

    emit layoutChanged();
}
Example #30
0
bool Console::printHints(const Common::UString &command) {
	if (_tabCount < 2)
		return false;

	uint32 maxSize;
	uint32 count;
	const std::list<Common::UString> &hints = _readLine->getCompleteHint(maxSize, count);
	if (count == 0)
		return false;

	maxSize = MAX<uint32>(maxSize, 3) + 2;
	uint32 lineSize = getColumns() / maxSize;
	uint32 lines = count / lineSize;

	if (lines >= (kConsoleLines - 3)) {
		if (!_printedCompleteWarning)
			printf("%d completion candidates", count);

		_printedCompleteWarning = true;

		if (_tabCount < 4)
			return true;
	}

	_console->scrollBottom();
	_console->print(Common::UString(kPrompt) + " " + command);
	printList(hints, maxSize);

	_tabCount = 0;
	_printedCompleteWarning = false;

	return true;
}