void MainWindow::setCentroids() { switcher = PaintSwitch::NOTHING; QVector<CPoint> centroids; WORD centroidsCount = QInputDialog::getInt(this,tr("Set number of centroids/neurons"),tr("Number of centroids")); qDebug() << "Setting " << centroidsCount << " centroids."; WORD dimension = QInputDialog::getInt(this,tr("Set number of dimensions"),tr("Dimensions")); qDebug() << "Setting " << dimension << " dimensions."; centroids = Centroids::randomizeCentroids(centroidsCount,dimension,50,this->height()-50); colors.clear(); for(int i=0;i<centroidsCount;i++) colors.push_back(generateColor()); kmeans.setCentroids(centroids); nGas.setCentroids(centroids); kohonen.setCentroids(centroids); if(dimension == 2) { ui->actionSet_Data->setEnabled(true); ui->actionLoad_image->setEnabled(false); ui->graphicsView->setVisible(false); ui->graphicsView_2->setVisible(false); } if(dimension == 3) { ui->actionLoad_image->setEnabled(true); ui->actionSet_Data->setEnabled(false); ui->actionKMeans_Algorithm->setEnabled(false); ui->actionKohonen_s_Algorithm->setEnabled(false); ui->actionNeural_Gas_Algorithm->setEnabled(false); } }
void DialogSpectraTemplates::on_pushNew_clicked() { Qpx::Spectrum::Template new_template; new_template.appearance = generateColor().rgba(); new_template.match_pattern.resize(current_dets_.size()); new_template.add_pattern.resize(current_dets_.size()); DialogSpectrumTemplate* newDialog = new DialogSpectrumTemplate(new_template, current_dets_, false, this); connect(newDialog, SIGNAL(templateReady(Qpx::Spectrum::Template)), this, SLOT(add_template(Qpx::Spectrum::Template))); newDialog->exec(); }
void FormOptimization::do_run() { ui->pushStop->setEnabled(true); my_run_ = true; emit toggleIO(false); bits = ui->spinBits->value(); optimizing_.bits = bits; int optchan = ui->comboTarget->currentData().toInt(); optimizing_.add_pattern.resize(optchan + 1, 0); optimizing_.add_pattern[optchan] = 1; optimizing_.match_pattern.resize(optchan + 1, 0); optimizing_.match_pattern[optchan] = 1; optimizing_.appearance = generateColor().rgba(); XMLableDB<Qpx::Spectrum::Template> db("SpectrumTemplates"); db.add(optimizing_); current_spectra_.clear(); current_spectra_.set_spectra(db); peaks_.push_back(Qpx::Peak()); spectra_.push_back(Qpx::Fitter()); ui->plotSpectrum->update_spectrum(); Qpx::Setting set(current_setting_); set.indices.clear(); set.indices.insert(optchan); set.value_dbl = val_current; Qpx::Engine::getInstance().set_setting(set, Qpx::Match::id | Qpx::Match::indices); QThread::sleep(1); Qpx::Engine::getInstance().get_all_settings(); set = Qpx::Engine::getInstance().pull_settings().get_setting(set, Qpx::Match::id | Qpx::Match::indices); setting_values_.push_back(set.value_dbl); setting_fwhm_.push_back(0); emit settings_changed(); interruptor_.store(false); opt_runner_thread_.do_run(current_spectra_, interruptor_, 0); }
DialogSpectrumTemplate::DialogSpectrumTemplate(Qpx::Spectrum::Template newTemplate, std::vector<Qpx::Detector> current_dets, bool edit, QWidget *parent) : QDialog(parent), current_dets_(current_dets), ui(new Ui::DialogSpectrumTemplate) { ui->setupUi(this); for (auto &q : Qpx::Spectrum::Factory::getInstance().types()) ui->comboType->addItem(QString::fromStdString(q)); ui->colPicker->setStandardColors(); connect(ui->colPicker, SIGNAL(colorChanged(QColor)), this, SLOT(colorChanged(QColor))); QRegExp rx("^\\w*$"); QValidator *validator = new QRegExpValidator(rx, this); ui->lineName->setValidator(validator); if (edit) { myTemplate = newTemplate; ui->lineName->setEnabled(false); ui->comboType->setEnabled(false); Qpx::Spectrum::Template *newtemp = Qpx::Spectrum::Factory::getInstance().create_template(newTemplate.type); if (newtemp != nullptr) { myTemplate.description = newtemp->description; myTemplate.input_types = newtemp->input_types; myTemplate.output_types = newtemp->output_types; } else PL_WARN << "Problem with spectrum type. Factory cannot make template for " << newTemplate.type; } else { Qpx::Spectrum::Template *newtemp = Qpx::Spectrum::Factory::getInstance().create_template(ui->comboType->currentText().toStdString()); if (newtemp != nullptr) { myTemplate = *newtemp; size_t sz = current_dets_.size(); Qpx::Setting pattern; pattern = myTemplate.generic_attributes.get(Qpx::Setting("pattern_coinc")); pattern.value_pattern.resize(sz); myTemplate.generic_attributes.replace(pattern); pattern = myTemplate.generic_attributes.get(Qpx::Setting("pattern_anti")); pattern.value_pattern.resize(sz); myTemplate.generic_attributes.replace(pattern); pattern = myTemplate.generic_attributes.get(Qpx::Setting("pattern_add")); pattern.value_pattern.resize(sz); myTemplate.generic_attributes.replace(pattern); myTemplate.match_pattern.resize(sz); myTemplate.add_pattern.resize(sz); } else PL_WARN << "Problem with spectrum type. Factory cannot make template for " << ui->comboType->currentText().toStdString(); myTemplate.appearance = generateColor().rgba(); } table_model_.eat(&myTemplate.generic_attributes); ui->tableGenericAttrs->setModel(&table_model_); ui->tableGenericAttrs->setItemDelegate(&special_delegate_); ui->tableGenericAttrs->verticalHeader()->hide(); ui->tableGenericAttrs->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); ui->tableGenericAttrs->horizontalHeader()->setStretchLastSection(true); ui->tableGenericAttrs->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); ui->tableGenericAttrs->setSelectionMode(QAbstractItemView::SingleSelection); ui->tableGenericAttrs->show(); updateData(); ui->tableGenericAttrs->resizeColumnsToContents(); }
void DialogSpectrumTemplate::on_pushRandColor_clicked() { myTemplate.appearance = generateColor().rgba(); ui->colPicker->setCurrentColor(QColor::fromRgba(myTemplate.appearance)); }
void ParticleEmitter::emitOnce(unsigned int particleCount) { GP_ASSERT(_node); GP_ASSERT(_particles); // Limit particleCount so as not to go over _particleCountMax. if (particleCount + _particleCount > _particleCountMax) { particleCount = _particleCountMax - _particleCount; } Vector3 translation; Matrix world = _node->getWorldMatrix(); world.getTranslation(&translation); // Take translation out of world matrix so it can be used to rotate orbiting properties. world.m[12] = 0.0f; world.m[13] = 0.0f; world.m[14] = 0.0f; // Emit the new particles. for (unsigned int i = 0; i < particleCount; i++) { Particle* p = &_particles[_particleCount]; p->_visible = true; generateColor(_colorStart, _colorStartVar, &p->_colorStart); generateColor(_colorEnd, _colorEndVar, &p->_colorEnd); p->_color.set(p->_colorStart); p->_energy = p->_energyStart = generateScalar(_energyMin, _energyMax); p->_size = p->_sizeStart = generateScalar(_sizeStartMin, _sizeStartMax); p->_sizeEnd = generateScalar(_sizeEndMin, _sizeEndMax); p->_rotationPerParticleSpeed = generateScalar(_rotationPerParticleSpeedMin, _rotationPerParticleSpeedMax); p->_angle = generateScalar(0.0f, p->_rotationPerParticleSpeed); p->_rotationSpeed = generateScalar(_rotationSpeedMin, _rotationSpeedMax); // Only initial position can be generated within an ellipsoidal domain. generateVector(_position, _positionVar, &p->_position, _ellipsoid); generateVector(_velocity, _velocityVar, &p->_velocity, false); generateVector(_acceleration, _accelerationVar, &p->_acceleration, false); generateVector(_rotationAxis, _rotationAxisVar, &p->_rotationAxis, false); // Initial position, velocity and acceleration can all be relative to the emitter's transform. // Rotate specified properties by the node's rotation. if (_orbitPosition) { world.transformPoint(p->_position, &p->_position); } if (_orbitVelocity) { world.transformPoint(p->_velocity, &p->_velocity); } if (_orbitAcceleration) { world.transformPoint(p->_acceleration, &p->_acceleration); } // The rotation axis always orbits the node. if (p->_rotationSpeed != 0.0f && !p->_rotationAxis.isZero()) { world.transformPoint(p->_rotationAxis, &p->_rotationAxis); } // Translate position relative to the node's world space. p->_position.add(translation); // Initial sprite frame. if (_spriteFrameRandomOffset > 0) { p->_frame = rand() % _spriteFrameRandomOffset; } else { p->_frame = 0; } p->_timeOnCurrentFrame = 0.0f; ++_particleCount; } }
int main(int argc, const char * argv[] ) { // setting up GLFW process glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // initialize the window with GLFW GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "Assignment1", nullptr, nullptr); //make the program listen to the key input glfwSetKeyCallback(window, key_exit); // Handle window not created successfully if(window == nullptr) { cout << "Failed to create a window" << endl; glfwTerminate(); return -1; } glfwMakeContextCurrent(window); // setting up the GLEW glewInit(); glewExperimental = GL_TRUE; if(glewInit() != GLEW_OK) { cout << "Failed to initialize GLEW" << endl; return -1; } //random colors vector vector<glm::vec4> colors = generateColor(); //color iterator auto j = colors.begin(); //randome rectangles vector vector<validRectangle> rectangles; rectangles.push_back(generateRectanle()); for(int i = RECNUM;i>=0;--i) { rectangles.push_back(generateRectanle()); } int width, height; glfwGetFramebufferSize(window, &width, &height); glViewport(0, 0, width, height); // compile the shader GLuint vertexShader; vertexShader = glCreateShader(GL_VERTEX_SHADER); //Next we attach the shader source code to the shader object and compile the shader: glShaderSource(vertexShader, 1, &vertexShaderSource2, NULL); glCompileShader(vertexShader); //check if the complication is sucessful GLint success; GLchar infoLog[512]; glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success); if(!success) { glGetShaderInfoLog(vertexShader, 512, NULL, infoLog); std::cout << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" << infoLog << std::endl; } //compile the fragmentShader GLuint fragmentShader; fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(fragmentShader,1,&fragmentShaderSource2,NULL); glCompileShader(fragmentShader); // Shader Program GLuint shaderProgram; shaderProgram = glCreateProgram(); // attch the shader to program created glAttachShader(shaderProgram,vertexShader); glAttachShader(shaderProgram,fragmentShader); glLinkProgram(shaderProgram); // check if the link is succesfful glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success); if(!success) { glGetProgramInfoLog(shaderProgram, 512, NULL, infoLog); } // glUseProgram(shaderProgram); // we can delete them after the link glDeleteShader(vertexShader); glDeleteShader(fragmentShader); // draw indices GLuint indices[] = { 0, 2, 3, 1, 2, 3 }; // GLuint indices[] = { // 3, 3, 2, // 1, 2, 3 // }; // // setting up buffer and attribute objects GLuint VBOs[RECNUM],VAOs[RECNUM],EBOs[RECNUM]; glGenVertexArrays(RECNUM,VAOs); // Generate multiple VAOs glGenBuffers(RECNUM,VBOs); glGenBuffers(RECNUM,EBOs); //testing more random std::random_device rd2; // obtain a random number from hardware std::mt19937 eng(rd2()); // seed the generator std::uniform_real_distribution<> distr_1(-0.25, 0.25); std::uniform_real_distribution<> distr_2(-0.25, 0.25 );// define the range float xChange = distr_1(eng); float yChange = distr_2(eng); float zChange = distr_1(eng); float wChange = distr_1(eng); //generate rectangles store them into VAOs and VBOs int counter = 0; for(auto i = rectangles.begin();i!=rectangles.end();i++) { //originally z should be 1.0f but now we're making it random // and the x and y is just the point values GLfloat vertices[] { i->firstPoint.x + xChange,i->firstPoint.y + xChange,xChange, i->secondPoint.x + yChange,i->secondPoint.y + yChange,yChange, i->thirdPoint.x + zChange,i->thirdPoint.y + zChange,zChange, i->fouthPoint.x + wChange, i->fouthPoint.y + wChange,wChange, }; glBindVertexArray(VAOs[counter]); glBindBuffer(GL_ARRAY_BUFFER,VBOs[counter]); glBufferData(GL_ARRAY_BUFFER,sizeof(vertices),vertices,GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,EBOs[1]); glBufferData(GL_ELEMENT_ARRAY_BUFFER,sizeof(indices),indices,GL_STATIC_DRAW); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0); glEnableVertexAttribArray(0); glBindVertexArray(0); counter++; } vector<glm::mat4> transforms; // generate random transform matrix for each rectangles and store them into a vector so // that we'd be to change them and acess them for(int j = 0 ; j < RECNUM;j++) { glm::mat4 transform; transforms.push_back(transform); }; //drawing process while(!glfwWindowShouldClose(window)) { // Check if any events have been activiated (key pressed, mouse moved etc.) and call corresponding response functions glfwPollEvents(); //rendering commands here glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); //test random color std::random_device rd; // obtain a random number from hardware std::mt19937 eng(rd()); // seed the generator std::uniform_int_distribution<> distr(1, 2000); std::uniform_int_distribution<> distr2(1, 2000);// define the range GLint vertexColorLocation = glGetUniformLocation(shaderProgram,"ourColor"); // Draw our first rectangle glUseProgram(shaderProgram); // Create transformations // glm::mat4 transform; glm::mat4 reverse; // Get matrix's uniform location and set matrix GLint transformLoc = glGetUniformLocation(shaderProgram, "transform"); GLint reverseLoc = glGetUniformLocation(shaderProgram,"reverse"); //drawing multiples for (int i = 0 ; i < RECNUM ;i ++ ) { if(start) { glm::mat4 transform = transforms[i]; int xscale = distr(eng); int yscale = distr2(eng); if(i%2==0) { transforms[i]= glm::scale(transform,glm::vec3(1.0f - cos((GLfloat)glfwGetTime())/xscale/10,1.0f,1.0f)); transform = transforms[i]; transforms[i] = glm::rotate(transform,xscale*1.0f/50000,glm::vec3(yscale/100.0,yscale/100.0 ,sin(yscale/100.0))); transform = transforms[i]; transforms[i] = glm::translate(transform, glm::vec3(cos(xscale)/50*sin(yscale/100),cos(xscale)/50*sin(yscale/100),cos(xscale)/100*sin(yscale/100))); } else { transforms[i]= glm::scale(transform,glm::vec3(1.0f,1.0f - cos((GLfloat)glfwGetTime())/xscale/10,1.0f)); transform = transforms[i]; transforms[i] = glm::rotate(transform,xscale*1.0f/50000,glm::vec3(-yscale/100.0,-yscale/100.0,-yscale/100.0)); transform = transforms[i]; transforms[i] = glm::translate(transform, glm::vec3(sin(xscale)/30*cos(yscale/40),sin(xscale)/20*cos(yscale/10),0.0f)); } } glUniformMatrix4fv(transformLoc, 1, GL_FALSE, glm::value_ptr(transforms[i])); glUniformMatrix4fv(reverseLoc,1,GL_FALSE,glm::value_ptr(reverse)); glUniform4f(vertexColorLocation,j[i].x,j[i].y,j[i].z,j[i].w); glBindVertexArray(VAOs[i]); glDrawElements(GL_TRIANGLES, 6,GL_UNSIGNED_INT, 0); } glBindVertexArray(0); // Swap the screen buffers glfwSwapBuffers(window); } // Properly de-allocate all resources once they've outlived their purpose glDeleteVertexArrays(RECNUM, VAOs); glDeleteBuffers(RECNUM, VBOs); // Terminate GLFW, clearing any resources allocated by GLFW. glfwTerminate(); return 0; }
TracksItem::TracksItem(QWidget *widget) : QWidget(widget), d(new TracksItemPrivate(this)) { auto em = QRockyStyle::em(this); this->setAutoFillBackground(true); QPalette palette(this->palette()); palette.setColor(QPalette::Window, palette.alternateBase().color()); palette.setColor(QPalette::WindowText, palette.brightText().color()); palette.setColor(QPalette::Button, palette.alternateBase().color()); palette.setColor(QPalette::ButtonText, QColor(0x33, 0x33, 0x33)); palette.setColor(QPalette::Light, QColor(0x33, 0x33, 0x33)); this->setPalette(palette); d->lbl_color = new QWidget; d->lbl_color->setMinimumWidth(qRound(em)); d->lbl_color->setMaximumWidth(qRound(em)); d->lbl_color->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum); d->lbl_artwork = new QLabel; auto pxm_artwork = QIcon(":/Roca.svg").pixmap(qRound(4*em), qRound(4*em)); d->lbl_artwork->setPixmap(pxm_artwork); d->lbl_artwork->setMinimumSize(qRound(4*em), qRound(4*em)); d->lbl_artwork->setMaximumSize(qRound(4*em), qRound(4*em)); d->lbl_trackname = new QLabel("Track 1"); QFont font1_5x(this->font()); if(font1_5x.pointSizeF() > 0) { font1_5x.setPointSizeF(font1_5x.pointSizeF()*3/2); } else { font1_5x.setPixelSize((font1_5x.pixelSize()*3+1)/2); } d->lbl_trackname->setFont(font1_5x); d->lbl_trackname->setPalette(palette); d->lbl_trackname->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); d->lbl_sfname = new QLabel("Roca IcySnowy 0.1.0alpha"); d->lbl_sfname->setPalette(palette); d->lbl_sfname->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); d->btn_mute = new QRockyButton("M"); d->btn_mute->setCheckable(true); d->btn_mute->setCombineBorders(QRockyStyle::Combine_Right); d->btn_mute->setMinMaxSize(qRound(1.5*em), qRound(1.5*em)); d->btn_mute->setPalette(palette); d->btn_solo = new QRockyButton("S"); d->btn_solo->setCheckable(true); d->btn_solo->setCombineBorders(QRockyStyle::Combine_Left); d->btn_solo->setMinMaxSize(qRound(1.5*em), qRound(1.5*em)); d->btn_solo->setPalette(palette); d->sld_volume = new QSlider; d->sld_volume->setMinimum(0); d->sld_volume->setMaximum(65536); d->sld_volume->setValue(65536); d->sld_volume->setMinimumWidth(qRound(7*em)); d->sld_volume->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum); d->sld_volume->setOrientation(Qt::Horizontal); this->connect(d->sld_volume, &QSlider::valueChanged, this, &TracksItem::onVolumeChange); d->lbl_volume = new QLabel("0.0 dB"); d->lbl_volume->setMinimumWidth(qRound(4.5*em)); d->lbl_volume->setPalette(palette); auto layout0 = new QVBoxLayout; layout0->addWidget(d->lbl_trackname); layout0->addWidget(d->lbl_sfname); auto layout1 = new QHBoxLayout; layout1->addWidget(d->lbl_artwork); layout1->addSpacing(qRound(em)); layout1->addLayout(layout0); auto layout2 = new QHBoxLayout; layout2->addSpacing(qRound(em/2)); layout2->addWidget(d->btn_mute); layout2->addWidget(d->btn_solo); layout2->addSpacing(qRound(1.5*em)); layout2->addWidget(d->sld_volume); layout2->addSpacing(qRound(em/2)); layout2->addWidget(d->lbl_volume); auto layout3 = new QVBoxLayout; layout3->addSpacing(qRound(em/16)); layout3->addLayout(layout1); layout3->addSpacing(qRound(em/4)); layout3->addLayout(layout2); layout3->addSpacing(qRound(em/4 + em/16)); auto layout = new QHBoxLayout; layout->setMargin(0); layout->setSpacing(0); layout->addWidget(d->lbl_color); layout->addLayout(layout3); this->setLayout(layout); this->setColor(generateColor()); }
bool SIM_PLOT_PANEL::AddTrace( const wxString& aName, int aPoints, const double* aX, const double* aY, SIM_PLOT_TYPE aFlags ) { TRACE* trace = NULL; // Find previous entry, if there is one auto prev = m_traces.find( aName ); bool addedNewEntry = ( prev == m_traces.end() ); if( addedNewEntry ) { if( m_type == ST_TRANSIENT ) { bool hasVoltageTraces = false; for( auto tr : m_traces ) { if( !( tr.second->GetFlags() & SPT_CURRENT ) ) { hasVoltageTraces = true; break; } } if( !hasVoltageTraces ) m_axis_y2->SetMasterScale( nullptr ); else m_axis_y2->SetMasterScale( m_axis_y1 ); } // New entry trace = new TRACE( aName ); trace->SetTraceColour( generateColor() ); trace->SetPen( wxPen( trace->GetTraceColour(), 2, wxPENSTYLE_SOLID ) ); m_traces[aName] = trace; // It is a trick to keep legend & coords always on the top for( mpLayer* l : m_topLevel ) DelLayer( l ); AddLayer( (mpLayer*) trace ); for( mpLayer* l : m_topLevel ) AddLayer( l ); } else { trace = prev->second; } std::vector<double> tmp( aY, aY + aPoints ); if( m_type == ST_AC ) { if( aFlags & SPT_AC_PHASE ) { for( int i = 0; i < aPoints; i++ ) tmp[i] = tmp[i] * 180.0 / M_PI; // convert to degrees } else { for( int i = 0; i < aPoints; i++ ) tmp[i] = 20 * log( tmp[i] ) / log( 10.0 ); // convert to dB } } trace->SetData( std::vector<double>( aX, aX + aPoints ), tmp ); if( aFlags & SPT_AC_PHASE || aFlags & SPT_CURRENT ) trace->SetScale( m_axis_x, m_axis_y2 ); else trace->SetScale( m_axis_x, m_axis_y1 ); trace->SetFlags( aFlags ); UpdateAll(); return addedNewEntry; }