size_t GenericHeader::readSize(IDataReader &reader) { size_t hhSize = getMinSize(); DataBuffer buf(hhSize, ALIGNMENT); size_t numBytesRead = reader.getData(buf.getFree(), hhSize); buf.moveFreeToData(numBytesRead); if (numBytesRead < hhSize) { throw IllegalHeaderException("Failed to read header info."); } uint32_t magic = buf.readInt32(); if (magic != MAGIC) { throw IllegalHeaderException("Failed to verify magic bits."); } uint32_t numBytesTotal = buf.readInt32(); if (numBytesTotal == 0) { throw IllegalHeaderException("Failed to read header size."); } if (numBytesTotal < getMinSize()) { throw IllegalHeaderException("Failed to verify header size."); } uint32_t version = buf.readInt32(); if (version != VERSION) { throw IllegalHeaderException("Failed to verify header version."); } return numBytesTotal; }
static void complexity(FILE *f, SmiNode *row, SmiNode *col, void *data) { int *cmplx = (int *) data; SmiType *smiType; unsigned long min, max; smiType = smiGetNodeType(col); if (! smiType) { return; } switch (smiType->basetype) { case SMI_BASETYPE_INTEGER32: case SMI_BASETYPE_UNSIGNED32: case SMI_BASETYPE_ENUM: *cmplx += 1; break; case SMI_BASETYPE_OCTETSTRING: case SMI_BASETYPE_OBJECTIDENTIFIER: case SMI_BASETYPE_BITS: *cmplx += 2; min = getMinSize(smiType); max = getMaxSize(smiType); if (min != max) { *cmplx += 1; } break; default: /* ignore everything else */ break; } }
bool PointChunk::operator == (const StateChunk &other) const { PointChunk const *tother = dynamic_cast<PointChunk const*>(&other); if(!tother) return false; if(tother == this) return true; if(getSize() != tother->getSize() || getSmooth() != tother->getSmooth() || getMinSize() != tother->getMinSize() || getMaxSize() != tother->getMaxSize() || getConstantAttenuation() != tother->getConstantAttenuation() || getLinearAttenuation() != tother->getLinearAttenuation() || getQuadraticAttenuation() != tother->getQuadraticAttenuation() || getFadeThreshold() != tother->getFadeThreshold() || getSprite() != tother->getSprite() || getRMode() != tother->getRMode() ) { return false; } return true; }
void AbstractWindow::updateContainerLayout(void) { if(getParentContainer() != NULL) { Inherited::updateContainerLayout(); } else if(getSize() != getPreferredSize()) { Vec2f Size(osgMax(osgMin(getPreferredSize().x(), getMaxSize().x()), getMinSize().x()), osgMax(osgMin(getPreferredSize().y(), getMaxSize().y()), getMinSize().y())); if(getSize() != Size) { setSize(Size); } } }
QSizeF WindowController::getMinSizeAspectRatioCorrect() const { const auto min = getMinSize(); const auto max = getMaxSize(); if (min > max) return _getAspectRatioSize().scaled(max, Qt::KeepAspectRatio); return _getAspectRatioSize().scaled(min, Qt::KeepAspectRatioByExpanding); }
//---------------------------------------------------------------------------- // bool TextureMemoryLayout::isMinBlockSize(int width, int height, int pixMode) { PixelType pType = modeToPixelType(pixMode); const PixelFormatLayout &pf = pixelFormat[pType]; getMinSize(width, height, pixMode); return (width >= pf.blockSize.width) && (height >= pf.blockSize.height); }
Pane MessageWindow::getPane(StrLen title) const { Point size=getMinSize(title,sub_win.getMinSize()); Point s=desktop->getScreenSize(); size=Inf(size,s-s/4); return Pane((s.x-size.x)/2,+cfg.pos_ratio*(s.y-size.y),size); }
size_t GenericHeader::getSize() const { size_t ret = getMinSize(); for (TagMap::const_iterator it = _tags.begin(); it != _tags.end(); ++it) { ret += it->second.getSize(); } return ret; }
int MainWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QMainWindow::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: getBitPlane((*reinterpret_cast< int(*)>(_a[1]))); break; case 1: getDisplayOption((*reinterpret_cast< int(*)>(_a[1]))); break; case 2: getEdgeFilter((*reinterpret_cast< int(*)>(_a[1]))); break; case 3: getImpulseNoise((*reinterpret_cast< int(*)>(_a[1]))); break; case 4: getKLTQuality((*reinterpret_cast< double(*)>(_a[1]))); break; case 5: getKLTMinDist((*reinterpret_cast< int(*)>(_a[1]))); break; case 6: getKLTWindowSize((*reinterpret_cast< int(*)>(_a[1]))); break; case 7: getKLTNumLevels((*reinterpret_cast< int(*)>(_a[1]))); break; case 8: getLogarithmConstant((*reinterpret_cast< double(*)>(_a[1]))); break; case 9: getOFAlgorithm((*reinterpret_cast< int(*)>(_a[1]))); break; case 10: getPowerLawConstant((*reinterpret_cast< double(*)>(_a[1]))); break; case 11: getPowerLawGamma((*reinterpret_cast< double(*)>(_a[1]))); break; case 12: getR1((*reinterpret_cast< int(*)>(_a[1]))); break; case 13: getK((*reinterpret_cast< int(*)>(_a[1]))); break; case 14: getMinSize((*reinterpret_cast< int(*)>(_a[1]))); break; case 15: getSharpeningAlgorithm((*reinterpret_cast< int(*)>(_a[1]))); break; case 16: getSigma((*reinterpret_cast< double(*)>(_a[1]))); break; case 17: getSmoothingFilter((*reinterpret_cast< int(*)>(_a[1]))); break; case 18: getSmoothingMask((*reinterpret_cast< int(*)>(_a[1]))); break; case 19: exitApplication(); break; case 20: openImageDirectory(); break; case 21: toggleAddGaussianNoise(); break; case 22: toggleAddGammaNoise(); break; case 23: toggleAddImpulseNoise(); break; case 24: toggleBitPlaneSlicing(); break; case 25: toggleContrastStretching(); break; case 26: toggleFilter(); break; case 27: toggleFitToWindow(); break; case 28: toggleHistogramEqualization(); break; case 29: toggleLogarithm(); break; case 30: toggleNegative(); break; case 31: toggleOpticalFlow(); break; case 32: togglePowerLaw(); break; case 33: toggleSegmentation(); break; case 34: toggleSharpeningAlgorithm(); break; case 35: toggleSmoothing(); break; case 36: toggleSwapRedBlue(); break; case 37: updateImageNumber((*reinterpret_cast< int(*)>(_a[1]))); break; case 38: timerEvent((*reinterpret_cast< QTimerEvent*(*)>(_a[1]))); break; case 39: on_pushButtonTrack_clicked(); break; default: ; } _id -= 40; } return _id; }
QSize DockPixelStreamer::constrainSize(const QSize& size) const { QSize minSize = getMinSize(); QSize maxSize = getMaxSize(); if (size.width() < minSize.width() || size.height() < minSize.height()) return minSize; if (size.width() > maxSize.width() || size.height() > maxSize.height()) return maxSize; return size; }
ItemButton::ItemButton(QWidget *parent) : QAbstractButton(parent) { description = ""; price = ""; slot = 0; setContentsMargins(9, 9, 9, 9); setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); setMinimumHeight(getMinSize()); connect(this, SIGNAL(clicked()), this, SLOT(handleClick())); }
void ContentWindowController::constrainSize( QSizeF& windowSize ) const { const QSizeF& maxSize = getMaxSize(); if( windowSize > maxSize ) { windowSize.scale( maxSize, Qt::KeepAspectRatio ); return; } const QSizeF& minSize = getMinSize(); if( windowSize < minSize ) windowSize = _contentWindow->getCoordinates().size(); }
ItemButton::ItemButton(QString nTitle, QString nDescription, QString nPrice, QIcon nIcon, int slot, QWidget *parent) : QAbstractButton(parent) { setText(nTitle); description = nDescription; price = nPrice; setIcon(nIcon); this->slot = slot; setContentsMargins(13, 13, 13, 13); setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); setMinimumHeight(getMinSize()); connect(this, SIGNAL(clicked()), this, SLOT(handleClick())); }
size_t GenericHeader::read(IDataReader &reader) { size_t bufLen = 1024 * 32; DataBuffer buf(bufLen, ALIGNMENT); size_t numBytesRead = reader.getData(buf.getFree(), bufLen); buf.moveFreeToData(numBytesRead); if (numBytesRead < 4 /* magic */ + 4 /* size */) { throw IllegalHeaderException("Failed to read header info."); } uint32_t magic = buf.readInt32(); if (magic != MAGIC) { throw IllegalHeaderException("Failed to verify magic bits."); } uint32_t numBytesTotal = buf.readInt32(); if (numBytesTotal == 0) { throw IllegalHeaderException("Failed to read header size."); } if (numBytesTotal < getMinSize()) { throw IllegalHeaderException("Failed to verify header size."); } if (numBytesRead < numBytesTotal) { LOG(debug, "Read %d of %d header bytes, performing backfill.", (uint32_t)numBytesRead, numBytesTotal); uint32_t numBytesRemain = numBytesTotal - numBytesRead; buf.ensureFree(numBytesRemain); LOG(debug, "Reading remaining %d bytes of header.", numBytesRemain); numBytesRead += reader.getData(buf.getFree(), numBytesRemain); if (numBytesRead != numBytesTotal) { throw IllegalHeaderException("Failed to read full header."); } buf.moveFreeToData(numBytesRemain); } else { buf.moveDataToFree(numBytesRead - numBytesTotal); } uint32_t version = buf.readInt32(); if (version != VERSION) { throw IllegalHeaderException("Failed to verify header version."); } uint32_t numTags = buf.readInt32(); TagMap tags; for (uint32_t i = 0; i < numTags; ++i) { Tag tag; tag.read(buf); tags.insert(TagMap::value_type(tag.getName(), tag)); } _tags.swap(tags); return numBytesTotal; }
void Aw::Label::getMetrics(cairo_t *cr, Size& min_size, bool& expandh, bool& expandv) { // We over-ride the switch (m_font_type) { case font_type::normal: cairo_set_font_face(cr, theApp->m_font.m_norm_face); break; case font_type::bold: cairo_set_font_face(cr, theApp->m_font.m_bold_face); break; case font_type::mono: cairo_set_font_face(cr, theApp->m_font.m_mono_face); break; } cairo_text_extents_t te; cairo_set_source_rgb (cr, 0, 0, 0); cairo_set_font_size(cr, m_font_size); cairo_text_extents (cr, m_text.c_str(), &te); // anvil_syslog(0, "TEXT: %s %d %d %d %d %d %d\n", // m_text.c_str(), // (int)te.width, // (int)te.height, // (int)te.x_advance, // (int)te.y_advance, // (int)te.x_bearing, // (int)te.y_bearing // ); min_size = getMinSize(); if (te.width + 10 > min_size.m_width) { min_size.m_width = te.width + 10; } if (te.height + 10 > min_size.m_height) { min_size.m_height = te.height + 10; } expandh = expandH(); expandv = expandV(); }
void WindowController::constrainSize(QSizeF& windowSize, const Window::ResizePolicy policy) const { const auto snapToAspectRatio = policy == Window::KEEP_ASPECT_RATIO && _window.getContent().isZoomed(); const auto tryKeepAspectRatio = policy == Window::KEEP_ASPECT_RATIO && !_window.getContent().isZoomed(); const auto keepAspectRatio = tryKeepAspectRatio || _mustKeepAspectRatio(windowSize); if (keepAspectRatio) _constrainAspectRatio(windowSize); windowSize = geometry::constrain(windowSize, getMinSize(), getMaxSize(), keepAspectRatio); if (snapToAspectRatio && _isCloseToContentAspectRatio(windowSize)) windowSize = geometry::adjustAspectRatio(windowSize, _getContentSize()); }
static unsigned long getMinSize(SmiType *smiType) { SmiRange *smiRange; SmiType *parentType; unsigned int min = 65535, size; switch (smiType->basetype) { case SMI_BASETYPE_BITS: return 0; case SMI_BASETYPE_OCTETSTRING: case SMI_BASETYPE_OBJECTIDENTIFIER: size = 0; break; default: return 0; } for (smiRange = smiGetFirstRange(smiType); smiRange ; smiRange = smiGetNextRange(smiRange)) { if (smiRange->minValue.value.unsigned32 < min) { min = smiRange->minValue.value.unsigned32; } } if (min < 65535 && min > size) { size = min; } parentType = smiGetParentType(smiType); if (parentType) { unsigned int psize = getMinSize(parentType); if (psize > size) { size = psize; } } return size; }
Point TextLineShape::getMinSize() const { return getMinSize(text.str()); }
void PointChunk::changeFrom(DrawEnv *pEnv, StateChunk *old_chunk, UInt32 ) { PointChunk *old = dynamic_cast<PointChunk *>(old_chunk); #ifndef OSG_OGL_ES2 if(getSize() != old->getSize()) glPointSize(getSize()); #endif #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY) if(getSmooth() && !old->getSmooth()) { glEnable(GL_POINT_SMOOTH); } else if(!getSmooth() && old->getSmooth()) { glDisable(GL_POINT_SMOOTH); } #endif Window *pWin = pEnv->getWindow(); osgSinkUnusedWarning(pWin); #if GL_ARB_point_parameters if(getMinSize() >= 0.f) { if(pEnv->getWindow()->hasExtOrVersion(_extPointParameters, 0x0104)) { OSGGETGLFUNCBYID_GL3( glPointParameterf, osgGlPointParameterf, _funcIdPointParameterf, pWin); #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY) OSGGETGLFUNCBYID_GL3( glPointParameterfv, osgGlPointParameterfv, _funcIdPointParameterfv, pWin); osgGlPointParameterf(GL_POINT_SIZE_MIN_ARB, getMinSize()); osgGlPointParameterf(GL_POINT_SIZE_MAX_ARB, getMaxSize()); #endif osgGlPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_ARB, getFadeThreshold()); #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY) GLfloat att[3] = { getConstantAttenuation (), getLinearAttenuation (), getQuadraticAttenuation() }; osgGlPointParameterfv(GL_POINT_DISTANCE_ATTENUATION_ARB, att); #endif } } else if(old->getMinSize() >= 0.f) { if(pEnv->getWindow()->hasExtOrVersion(_extPointParameters, 0x0104)) { OSGGETGLFUNCBYID_GL3( glPointParameterf, osgGlPointParameterf, _funcIdPointParameterf, pWin); #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY) OSGGETGLFUNCBYID_GL3( glPointParameterfv, osgGlPointParameterfv, _funcIdPointParameterfv, pWin); osgGlPointParameterf(GL_POINT_SIZE_MIN_ARB, 0); osgGlPointParameterf(GL_POINT_SIZE_MAX_ARB, 1e10); #endif osgGlPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_ARB, 1); #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY) GLfloat att[3] = { 1, 0, 0 }; osgGlPointParameterfv(GL_POINT_DISTANCE_ATTENUATION_ARB, att); #endif } } #endif #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY) #if GL_ARB_point_sprite if(getSprite() && !old->getSprite()) { if(pEnv->getWindow()->hasExtOrVersion(_extPointSpriteARB, 0x0200)) { #if GL_NV_point_sprite if(pEnv->getWindow()->hasExtension(_extPointSpriteNV)) { OSGGETGLFUNCBYID_GL3( glPointParameterf, osgGlPointParameterf, _funcIdPointParameterf, pWin); osgGlPointParameterf(GL_POINT_SPRITE_R_MODE_NV, Real32(getRMode())); } #endif glEnable(GL_POINT_SPRITE_ARB); } } else if(!getSprite() && old->getSprite()) { if(pEnv->getWindow()->hasExtOrVersion(_extPointSpriteARB, 0x0200)) { glDisable(GL_POINT_SPRITE_ARB); } } #endif #endif #if ! defined(GL_ARB_point_parameters) && ! defined(GL_ARB_point_sprite) pEnv; #endif }
void PointChunk::deactivate(DrawEnv *pEnv, UInt32) { #ifndef OSG_OGL_ES2 if(getSize() != 1.f) glPointSize(1.f); #endif Window *pWin = pEnv->getWindow(); osgSinkUnusedWarning(pWin); #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY) if(getSmooth()) glDisable(GL_POINT_SMOOTH); #endif #if GL_ARB_point_parameters if(getMinSize() >= 0.f) { if(pEnv->getWindow()->hasExtOrVersion(_extPointParameters, 0x0104)) { OSGGETGLFUNCBYID_GL3( glPointParameterf, osgGlPointParameterf, _funcIdPointParameterf, pWin); #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY) OSGGETGLFUNCBYID_GL3( glPointParameterfv, osgGlPointParameterfv, _funcIdPointParameterfv, pWin); osgGlPointParameterf(GL_POINT_SIZE_MIN_ARB, 0); osgGlPointParameterf(GL_POINT_SIZE_MAX_ARB, 1e10); #endif osgGlPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_ARB, 1); #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY) GLfloat att[3] = { 1, 0, 0 }; osgGlPointParameterfv(GL_POINT_DISTANCE_ATTENUATION_ARB, att); #endif } } #endif #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY) #if GL_ARB_point_sprite if(getSprite()) { if(pEnv->getWindow()->hasExtOrVersion(_extPointSpriteARB, 0x0200)) { glDisable(GL_POINT_SPRITE_ARB); } } #endif #endif #if ! defined(GL_ARB_point_parameters) && ! defined(GL_ARB_point_sprite) pEnv; #endif }
bool PointChunk::isTransparent(void) const { return getMinSize() >= 0.f; }
void Grid::updatePositionsOfAllWidgets() { sf::Vector2f position; sf::Vector2f previousPosition; // Calculate m_Size and the available space which will be distributed when widgets will be positionned. sf::Vector2f availableSpace; m_Size = m_IntendedSize; sf::Vector2f minSize = getMinSize(); if (m_IntendedSize.x > minSize.x) availableSpace.x = m_IntendedSize.x - minSize.x; else m_Size.x = minSize.x; if (m_IntendedSize.y > minSize.y) availableSpace.y = m_IntendedSize.y - minSize.y; else m_Size.y = minSize.y; sf::Vector2f availSpaceOffset(0.5f * availableSpace.x / m_ColumnWidth.size(), 0.5f * availableSpace.y / m_RowHeight.size()); // Loop through all rows for (unsigned int row = 0; row < m_GridWidgets.size(); ++row) { // Remember the current position previousPosition = position; // Loop through all widgets in the row for (unsigned int col = 0; col < m_GridWidgets[row].size(); ++col) { if (m_GridWidgets[row][col].get() == nullptr) { position.x += m_ColumnWidth[col] + 2 * availSpaceOffset.x; continue; } sf::Vector2f cellPosition(position); // Place the next widget on the correct position switch (m_ObjLayout[row][col]) { case Layout::UpperLeft: cellPosition.x += static_cast<float>(m_ObjBorders[row][col].left) + availSpaceOffset.x; cellPosition.y += static_cast<float>(m_ObjBorders[row][col].top) + availSpaceOffset.y; break; case Layout::Up: cellPosition.x += m_ObjBorders[row][col].left + (((m_ColumnWidth[col] - m_ObjBorders[row][col].left - m_ObjBorders[row][col].right) - m_GridWidgets[row][col]->getFullSize().x) / 2.f) + availSpaceOffset.x; cellPosition.y += static_cast<float>(m_ObjBorders[row][col].top) + availSpaceOffset.y; break; case Layout::UpperRight: cellPosition.x += m_ColumnWidth[col] - m_ObjBorders[row][col].right - m_GridWidgets[row][col]->getFullSize().x + availSpaceOffset.x; cellPosition.y += static_cast<float>(m_ObjBorders[row][col].top) + availSpaceOffset.y; break; case Layout::Right: cellPosition.x += m_ColumnWidth[col] - m_ObjBorders[row][col].right - m_GridWidgets[row][col]->getFullSize().x + availSpaceOffset.x; cellPosition.y += m_ObjBorders[row][col].top + (((m_RowHeight[row] - m_ObjBorders[row][col].top - m_ObjBorders[row][col].bottom) - m_GridWidgets[row][col]->getFullSize().y) / 2.f) + availSpaceOffset.y; break; case Layout::BottomRight: cellPosition.x += m_ColumnWidth[col] - m_ObjBorders[row][col].right - m_GridWidgets[row][col]->getFullSize().x + availSpaceOffset.x; cellPosition.y += m_RowHeight[row] - m_ObjBorders[row][col].bottom - m_GridWidgets[row][col]->getFullSize().y + availSpaceOffset.y; break; case Layout::Bottom: cellPosition.x += m_ObjBorders[row][col].left + (((m_ColumnWidth[col] - m_ObjBorders[row][col].left - m_ObjBorders[row][col].right) - m_GridWidgets[row][col]->getFullSize().x) / 2.f) + availSpaceOffset.x; cellPosition.y += m_RowHeight[row] - m_ObjBorders[row][col].bottom - m_GridWidgets[row][col]->getFullSize().y + availSpaceOffset.y; break; case Layout::BottomLeft: cellPosition.x += static_cast<float>(m_ObjBorders[row][col].left) + availSpaceOffset.x; cellPosition.y += m_RowHeight[row] - m_ObjBorders[row][col].bottom - m_GridWidgets[row][col]->getFullSize().y + availSpaceOffset.y; break; case Layout::Left: cellPosition.x += static_cast<float>(m_ObjBorders[row][col].left) + availSpaceOffset.x; cellPosition.y += m_ObjBorders[row][col].top + (((m_RowHeight[row] - m_ObjBorders[row][col].top - m_ObjBorders[row][col].bottom) - m_GridWidgets[row][col]->getFullSize().y) / 2.f) + availSpaceOffset.y; break; case Layout::Center: cellPosition.x += m_ObjBorders[row][col].left + (((m_ColumnWidth[col] - m_ObjBorders[row][col].left - m_ObjBorders[row][col].right) - m_GridWidgets[row][col]->getFullSize().x) / 2.f) + availSpaceOffset.x; cellPosition.y += m_ObjBorders[row][col].top + (((m_RowHeight[row] - m_ObjBorders[row][col].top - m_ObjBorders[row][col].bottom) - m_GridWidgets[row][col]->getFullSize().y) / 2.f) + availSpaceOffset.y; break; } m_GridWidgets[row][col]->setPosition(cellPosition); position.x += m_ColumnWidth[col] + 2 * availSpaceOffset.x; } // Go to the next row position = previousPosition; position.y += m_RowHeight[row] + 2 * availSpaceOffset.y; } }
void Grid::changeWidgetLayout(const Widget::Ptr& widget, Layout::Layouts layout) { // Find the widget in the grid for (unsigned int row = 0; row < m_GridWidgets.size(); ++row) { for (unsigned int col = 0; col < m_GridWidgets[row].size(); ++col) { if (m_GridWidgets[row][col] == widget) { // Change the layout of the widget m_ObjLayout[row][col] = layout; // Recalculate the position of the widget { // Calculate the available space which is distributed when widgets are positionned. sf::Vector2f availableSpace; sf::Vector2f minSize = getMinSize(); if (m_Size.x > minSize.x) availableSpace.x = m_Size.x - minSize.x; if (m_Size.y > minSize.y) availableSpace.y = m_Size.y - minSize.y; sf::Vector2f availSpaceOffset(0.5f * availableSpace.x / m_ColumnWidth.size(), 0.5f * availableSpace.y / m_RowHeight.size()); float left = 0; float top = 0; for (unsigned int i=0; i < row; ++i) top += static_cast<float>(m_RowHeight[i]) + 2 * availSpaceOffset.y; for (unsigned int i=0; i < col; ++i) left += static_cast<float>(m_ColumnWidth[i]) + 2 * availSpaceOffset.x; switch (m_ObjLayout[row][col]) { case Layout::UpperLeft: left += static_cast<float>(m_ObjBorders[row][col].left) + availSpaceOffset.x; top += static_cast<float>(m_ObjBorders[row][col].top) + availSpaceOffset.y; break; case Layout::Up: left += m_ObjBorders[row][col].left + (((m_ColumnWidth[col] - m_ObjBorders[row][col].left - m_ObjBorders[row][col].right) - m_GridWidgets[row][col]->getFullSize().x) / 2.f) + availSpaceOffset.x; top += static_cast<float>(m_ObjBorders[row][col].top) + availSpaceOffset.y; break; case Layout::UpperRight: left += m_ColumnWidth[col] - m_ObjBorders[row][col].right - m_GridWidgets[row][col]->getFullSize().x + availSpaceOffset.x; top += static_cast<float>(m_ObjBorders[row][col].top) + availSpaceOffset.y; break; case Layout::Right: left += m_ColumnWidth[col] - m_ObjBorders[row][col].right - m_GridWidgets[row][col]->getFullSize().x + availSpaceOffset.x; top += m_ObjBorders[row][col].top + (((m_RowHeight[row] - m_ObjBorders[row][col].top - m_ObjBorders[row][col].bottom) - m_GridWidgets[row][col]->getFullSize().y) / 2.f) + availSpaceOffset.y; break; case Layout::BottomRight: left += m_ColumnWidth[col] - m_ObjBorders[row][col].right - m_GridWidgets[row][col]->getFullSize().x + availSpaceOffset.x; top += m_RowHeight[row] - m_ObjBorders[row][col].bottom - m_GridWidgets[row][col]->getFullSize().y + availSpaceOffset.y; break; case Layout::Bottom: left += m_ObjBorders[row][col].left + (((m_ColumnWidth[col] - m_ObjBorders[row][col].left - m_ObjBorders[row][col].right) - m_GridWidgets[row][col]->getFullSize().x) / 2.f) + availSpaceOffset.x; top += m_RowHeight[row] - m_ObjBorders[row][col].bottom - m_GridWidgets[row][col]->getFullSize().y + availSpaceOffset.y; break; case Layout::BottomLeft: left += static_cast<float>(m_ObjBorders[row][col].left) + availSpaceOffset.x; top += m_RowHeight[row] - m_ObjBorders[row][col].bottom - m_GridWidgets[row][col]->getFullSize().y + availSpaceOffset.y; break; case Layout::Left: left += static_cast<float>(m_ObjBorders[row][col].left) + availSpaceOffset.x; top += m_ObjBorders[row][col].top + (((m_RowHeight[row] - m_ObjBorders[row][col].top - m_ObjBorders[row][col].bottom) - m_GridWidgets[row][col]->getFullSize().y) / 2.f) + availSpaceOffset.y; break; case Layout::Center: left += m_ObjBorders[row][col].left + (((m_ColumnWidth[col] - m_ObjBorders[row][col].left - m_ObjBorders[row][col].right) - m_GridWidgets[row][col]->getFullSize().x) / 2.f) + availSpaceOffset.x; top += m_ObjBorders[row][col].top + (((m_RowHeight[row] - m_ObjBorders[row][col].top - m_ObjBorders[row][col].bottom) - m_GridWidgets[row][col]->getFullSize().y) / 2.f) + availSpaceOffset.y; break; } m_GridWidgets[row][col]->setPosition(left, top); } } } } }
bool EditRatioWindow::isGoodSize(Point size) const { return size>=getMinSize(); }
void EvolutionOfMorphologyAndBehavior::prepareCreatures() { for (int i = 0; i < getPopulationSize(); ++i) { Creature& creature = getCreature(i); creature.reset(); double* position = getPsoModel().getParticle(i).getPosition(); int particle_index = 0; //Morphology //[index] int morphology_index = (int) Math::scale(0, 100, position[particle_index++], 0, getNumberOfMorphologies()); setCreaturesMorphologyIndex(i, morphology_index); setup(creature, getMorphology(morphology_index)); getMorphology(morphology_index).addFitness(1.0); //BodyPart //[ shape | size-x | size-y | size-z | mass ] * creature.getBodyParts(); for (int j = 0; j < creature.getNumberOfBodyParts(); ++j) { creature.getBodyPart(j).setShape(getShape(position[particle_index++])); creature.getBodyPart(j).setSizeX(Math::scale(0, 100, position[particle_index++], getMinSize(), getMaxSize())); creature.getBodyPart(j).setSizeY(Math::scale(0, 100, position[particle_index++], getMinSize(), getMaxSize())); creature.getBodyPart(j).setSizeZ(Math::scale(0, 100, position[particle_index++], getMinSize(), getMaxSize())); creature.getBodyPart(j).setMass(Math::scale(0, 100, position[particle_index++], getMinMass(), getMaxMass())); } //Constraints //[ parent-connection-point | connection-point | // cone-swing-x | cone-twist-y | cone-swing-z ] * creature.getConstraints(); for (int j = 0; j < creature.getNumberOfConstraints(); ++j) { creature.getConstraint(j).setType(Constraint::CT_CONE_TWIST); creature.getConstraint(j).setConnectionA((int) Math::scale(0, 100, position[particle_index++], 0, Constraint::MAX_CONNECTION_POINTS)); creature.getConstraint(j).setConnectionB((int) Math::scale(0, 100, position[particle_index++], 0, Constraint::MAX_CONNECTION_POINTS)); creature.getConstraint(j).setConeSwingX(Math::scale(0, 100, position[particle_index++], Constraint::CONE_MIN_SWING, Constraint::CONE_MAX_SWING)); creature.getConstraint(j).setConeTwistY(Math::scale(0, 100, position[particle_index++], Constraint::CONE_MIN_TWIST, Constraint::CONE_MAX_TWIST)); creature.getConstraint(j).setConeSwingZ(Math::scale(0, 100, position[particle_index++], Constraint::CONE_MIN_SWING, Constraint::CONE_MAX_SWING)); } //NeuralNetwork //[ weight ] * creature.getNeuralNetwork().getTotalNumberOfWeights(); NeuralNetwork& nn = creature.getNeuralNetwork(); int layers = nn.getNumberOfLayers(); for (int j = 1; j < layers; ++j) { int neurons = nn.getLayer(j).getNumberOfNeurons(); for (int k = 0; k < neurons; ++k) { int inputs = nn.getLayer(j).getNeuron(k).getNumberOfInputs(); for (int l = 0; l < inputs; l++) { nn.getLayer(j).getNeuron(k).setInput(l, Math::scale(0, 100, position[particle_index++], -1.0, 1.0)); } nn.getLayer(j).getNeuron(k).setThreshold( Math::scale(0, 100, position[particle_index++], -1.0, 1.0)); } } creature.set(); } }