LevelGen::LevelGen(int w, int h, int featureSize) { this->w = w; this->h = h; widthMinusOne = w - 1; heightMinusOne = h - 1; values = new float[w * h]; for (int y = 0; y < w; y += featureSize) { for (int x = 0; x < w; x += featureSize) { setSample(x, y, random->nextFloat() * 2 - 1); } } int stepSize = featureSize; float scale = 1.0 / w; float scaleMod = 1; do { int halfStep = stepSize / 2; float stepSizeByScale = stepSize * scale; for (int y = 0; y < w; y += stepSize) { for (int x = 0; x < w; x += stepSize) { float a = sample(x, y); float b = sample(x + stepSize, y); float c = sample(x, y + stepSize); float d = sample(x + stepSize, y + stepSize); float e = (a + b + c + d) / 4.0 + (random->nextFloat() * 2 - 1) * stepSizeByScale; setSample(x + halfStep, y + halfStep, e); } } stepSizeByScale /= 2; //same as multiply by 0.5 needed for next steps for (int y = 0; y < w; y += stepSize) { for (int x = 0; x < w; x += stepSize) { float a = sample(x, y); float b = sample(x + stepSize, y); float c = sample(x, y + stepSize); float d = sample(x + halfStep, y + halfStep); float e = sample(x + halfStep, y - halfStep); float f = sample(x - halfStep, y + halfStep); float H = (a + b + d + e) / 4.0 + (random->nextFloat() * 2 - 1) * stepSizeByScale; float g = (a + c + d + f) / 4.0 + (random->nextFloat() * 2 - 1) * stepSizeByScale; setSample(x + halfStep, y, H); setSample(x, y + halfStep, g); } } stepSize /= 2; scale *= (scaleMod + 0.8); scaleMod *= 0.3; } while (stepSize > 1); }
int generateMonitorRead() { range *prange = (range*) malloc(sizeof(range)); sParameter *parameter=(sParameter*) malloc(sizeof(sParameter)); if ((prange == NULL)) { printf("In main(), cannot malloc pParameter. Error!\n"); return 0; } else{ setParameters(prange); if(setSample(parameter,prange)!=1) { printf("set sampleParameter error!!!\n"); return 0; } if(createDirectory(prange)==0)//this function must rely on setSample() { printf("create directory error!!!\n"); return 0; } if(monitorSample(parameter,prange)!=1 ) { printf("monitor sample error!!!\n"); return 0; } } freeMemory(prange); free(prange); return 1; }
CursorTheme::CursorTheme(const QString &title, const QString &description) { setTitle(title); setDescription(description); setSample(QStringLiteral("left_ptr")); setIsHidden(false); setIsWritable(false); }
void SingleSource::parseXML(const TiXmlElement *element) { //=* attribute: file="(string)" std::string filename; if (XMLParser::parseStringAttribute(filename, element, "file")) setSample(Sample::get(filename)); Source::parseXML(element); }
void DiamondSquare::run(int seed,double * array,int width,int height) { this->height=height; this->width=width; values=array; int featuresize=512; //values = new float[width * height]; srand (seed); for( int y = 0; y < height; y += featuresize) for (int x = 0; x < width; x += featuresize) { setSample(x, y, random()); //setSample(x,y,0); } int samplesize = featuresize; double scale = 1.0; while (samplesize > 1) { diamondSquare(samplesize, scale); samplesize /= 2; scale /= 2.0; } double val; for( int y = 0; y < height; y ++) for (int x = 0; x < width; x ++) { val=sample(x,y); if(val>1.0) setSample(x, y, 1.0); else if(val<-1.0) setSample(x,y,-1.0); //setSample(x,y,0); } }
void BinarizePopup::fetchSample() { TApp *app = TApp::instance(); TImageP img; if (app->getCurrentFrame()->isEditingLevel()) { TXshLevel *xshLevel = app->getCurrentLevel()->getLevel(); if (xshLevel && xshLevel->getSimpleLevel()) { TXshSimpleLevel *sl = xshLevel->getSimpleLevel(); img = sl->getFrame(app->getCurrentFrame()->getFid(), false); } } else { TXsheet *xsh = app->getCurrentScene()->getScene()->getXsheet(); TXshCell cell = xsh->getCell(app->getCurrentFrame()->getFrame(), app->getCurrentColumn()->getColumnIndex()); img = cell.getImage(false); } TRasterImageP ri = img; if (ri) { setSample(ri->getRaster()); } else { setSample(TRasterP()); } }
/** * Called when the mouse moves over this widget * * @param event */ void VisualDisplay::mouseMoveEvent(QMouseEvent *event) { double startX = width() / 2 - (p_boxWidth * (int)floor(p_boxSamps / 2) + (p_boxWidth / 2)); double startY = height() / 2 - (p_boxHeight * (int)floor(p_boxLines / 2) + (p_boxHeight / 2)); int x = (int)ceil((event->x() - startX) / p_boxWidth); int y = (int)ceil((event->y() - startY) / p_boxHeight); if(!p_set || x < 1 || y < 1 || x > p_boxSamps || y > p_boxLines) { emit setSample("Sample: n/a"); emit setLine("Line: n/a"); emit setDn("DN: n/a"); } else { emit setSample(QString("Sample: %1").arg(p_ulSamp + x - 1)); emit setLine(QString("Line: %1").arg(p_ulLine + y - 1)); double dn = p_pixelData[y-1][x-1]; if(IsSpecial(dn)) emit setDn(QString("DN: %1").arg(PixelToString(dn))); else emit setDn(QString("DN: %1").arg(dn)); } }
// set sample by frame and channel void AudioData::setSample(unsigned int frame, unsigned int channel, float value){ if(frame >= getFrameCount()){ std::ostringstream ss; ss << "Cannot set out-of-bounds frame (" << frame << "/" << getFrameCount() << ")"; throw Exception(ss.str().c_str()); } if(channel >= channels){ std::ostringstream ss; ss << "Cannot set out-of-bounds channel (" << channel << "/" << channels << ")"; throw Exception(ss.str().c_str()); } setSample(frame * channels + channel, value); }
void DiamondSquare::sampleDiamond(int x, int y, int size, double value) { int hs = size / 2; // c // //a x b // // d double a = sample(x - hs, y); double b = sample(x + hs, y); double c = sample(x, y - hs); double d = sample(x, y + hs); setSample(x, y, ((a + b + c + d) / 4.0) + value); }
int main(void){ int numVariablePattern[NUM_NODE]={4,4}; int *sample=Malloc(int,NUM_SAMPLE*NUM_NODE); setSample(sample,NUM_SAMPLE,NUM_NODE); bayesianNetwork *model=bayesianNetTrain(sample,NUM_SAMPLE,NUM_NODE,numVariablePattern); bayesianNetPrintSquereMatrix(model->edge,NUM_NODE*NUM_NODE); int predictValue=bayesianNetPredict(model,&sample[0],0); printf("predict:%d\n",predictValue); bayesianNetFree(model); free(sample); free(model); return 0; }
TextField::TextField(Application *application, BMFontBase* font, const char* text, const char* sample, FontBase::TextLayoutParameters *params) : TextFieldBase(application) { if (text) { text_ = text; } font_ = font; if (font_ != 0) font_->ref(); sminx = 0, sminy = 0, smaxx = 0, smaxy = 0; if (sample) setSample(sample); if (params) layout_=*params; setTextColor(0xFF000000); }
void DrumEvent::updateSample() { std::string smp; switch ( _type ) { case PercussionTypes::KICK_808: if ( _timbre == DrumTimbres::GRAVEL ) smp = "kdg"; else smp = "kd"; break; case PercussionTypes::STICK: if ( _timbre == DrumTimbres::GRAVEL ) smp = "stg"; else smp = "st"; break; case PercussionTypes::SNARE: if ( _timbre == DrumTimbres::GRAVEL ) smp = "sng"; else smp = "sn"; break; case PercussionTypes::HI_HAT: if ( _timbre == DrumTimbres::GRAVEL ) smp = "hhg"; else smp = "hh"; break; } setSample( SampleManager::getSample( smp )); }
SingleSource::SingleSource(const std::string& filename) : Source(), failed(false) { if (filename.length() > 0) setSample(Sample::get(filename)); }
/** * Mouse left widget, update labels * * @param event */ void VisualDisplay::leaveEvent(QEvent *event) { emit setSample("Sample: n/a"); emit setLine("Line: n/a"); emit setDn("DN: n/a"); }
/** * Constructor, creates and sets up widgets for this tool. * * @param parent */ StatisticsTool::StatisticsTool(QWidget *parent) : Tool(parent) { p_boxSamps = 3; p_boxLines = 3; p_ulSamp = -1; p_ulLine = -1; p_set = false; p_dialog = new QDialog(parent); p_dialog->setWindowTitle("Statistics"); p_visualBox = new QGroupBox("Visual Display"); p_visualScroll = new QScrollArea; p_visualScroll->setBackgroundRole(QPalette::Dark); p_visualDisplay = new VisualDisplay(p_visualScroll); p_visualDisplay->setObjectName("dnDisplay"); QCheckBox *checkBox = new QCheckBox("Hide Display"); connect(checkBox, SIGNAL(toggled(bool)), this, SLOT(hideDisplay(bool))); QLabel *boxLabel = new QLabel("Box Size:"); p_boxLabel = new QLabel; QString samps, lines; samps.setNum(p_boxSamps); lines.setNum(p_boxLines); p_boxLabel->setText(samps + "x" + lines); QHBoxLayout *boxLabelLayout = new QHBoxLayout; boxLabelLayout->addWidget(checkBox); boxLabelLayout->addStretch(1); boxLabelLayout->addWidget(boxLabel); boxLabelLayout->addWidget(p_boxLabel); QSlider *slider = new QSlider(Qt::Vertical); slider->setRange(2, 18); slider->setSliderPosition(10); slider->setSingleStep(1); slider->setTickInterval(1); slider->setTickPosition(QSlider::TicksBelow); connect(slider, SIGNAL(valueChanged(int)), p_visualDisplay, SLOT(setBoxSize(int))); connect(slider, SIGNAL(valueChanged(int)), this, SLOT(resizeScrollbars())); p_visualScroll->setWidget(p_visualDisplay); QGroupBox *displayMode = new QGroupBox("Display Mode"); QRadioButton *displayText = new QRadioButton("Show Text"); displayText->setToolTip("Display the pixels of a region as text"); QRadioButton *displayPixels = new QRadioButton("Show Pixel Values"); displayPixels->setToolTip("Display the pixels of a region"); QRadioButton *displayDeviation = new QRadioButton("Show Deviation"); displayDeviation->setToolTip("Display standard deviation over a region,\n where red denotes a larger deviation"); QHBoxLayout *displayModeLayout = new QHBoxLayout; displayModeLayout->addWidget(displayText); displayModeLayout->addWidget(displayPixels); displayModeLayout->addWidget(displayDeviation); displayMode->setLayout(displayModeLayout); connect(displayText, SIGNAL(toggled(bool)), p_visualDisplay, SLOT(showText(bool))); connect(displayText, SIGNAL(toggled(bool)), slider, SLOT(setDisabled(bool))); connect(displayPixels, SIGNAL(toggled(bool)), p_visualDisplay, SLOT(showPixels(bool))); connect(displayDeviation, SIGNAL(toggled(bool)), p_visualDisplay, SLOT(showDeviation(bool))); displayText->setChecked(true); QHBoxLayout *visualHBoxLayout = new QHBoxLayout; visualHBoxLayout->addWidget(p_visualScroll); visualHBoxLayout->addWidget(slider); QVBoxLayout *visualVBoxLayout = new QVBoxLayout; visualVBoxLayout->addLayout(visualHBoxLayout); visualVBoxLayout->addWidget(displayMode); p_visualBox->setLayout(visualVBoxLayout); QGroupBox *statsBox = new QGroupBox("Statistics"); p_minLabel = new QLabel("Minimum: n/a"); p_minLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken); p_minLabel->setLineWidth(1); p_minLabel->setMargin(10); p_minLabel->setAlignment(Qt::AlignLeft); p_maxLabel = new QLabel("Maximum: n/a"); p_maxLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken); p_maxLabel->setLineWidth(1); p_maxLabel->setMargin(10); p_maxLabel->setAlignment(Qt::AlignLeft); p_avgLabel = new QLabel("Average: n/a"); p_avgLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken); p_avgLabel->setLineWidth(1); p_avgLabel->setMargin(10); p_avgLabel->setAlignment(Qt::AlignLeft); p_stdevLabel = new QLabel("Standard Dev: n/a"); p_stdevLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken); p_stdevLabel->setLineWidth(1); p_stdevLabel->setMargin(10); p_stdevLabel->setAlignment(Qt::AlignLeft); p_dnLabel = new QLabel("DN: n/a"); QFont labelFont = p_dnLabel->font(); labelFont.setPointSize(8); p_dnLabel->setFont(labelFont); p_dnLabel->setAlignment(Qt::AlignRight); connect(p_visualDisplay, SIGNAL(setDn(QString)), p_dnLabel, SLOT(setText(QString))); p_sampLabel = new QLabel("Sample: n/a"); p_sampLabel->setFont(labelFont); p_sampLabel->setAlignment(Qt::AlignLeft); connect(p_visualDisplay, SIGNAL(setSample(QString)), p_sampLabel, SLOT(setText(QString))); p_lineLabel = new QLabel("Line: n/a"); p_lineLabel->setFont(labelFont); p_lineLabel->setAlignment(Qt::AlignCenter); connect(p_visualDisplay, SIGNAL(setLine(QString)), p_lineLabel, SLOT(setText(QString))); QGridLayout *statsLayout = new QGridLayout; statsLayout->addWidget(p_minLabel, 0, 0, 1, 2); statsLayout->addWidget(p_maxLabel, 1, 0, 1, 2); statsLayout->addWidget(p_avgLabel, 0, 2, 1, 2); statsLayout->addWidget(p_stdevLabel, 1, 2, 1, 2); statsLayout->addWidget(p_sampLabel, 2, 0); statsLayout->addWidget(p_lineLabel, 2, 1, 1, 2); statsLayout->addWidget(p_dnLabel, 2, 3); statsBox->setLayout(statsLayout); QVBoxLayout *dialogLayout = new QVBoxLayout; dialogLayout->addLayout(boxLabelLayout); dialogLayout->addWidget(p_visualBox); dialogLayout->addWidget(statsBox); p_dialog->setLayout(dialogLayout); checkBox->setChecked(true); }
void MainWindow::initializeQMLComponent() { QDeclarativeContext *context = m_view->rootContext(); #if defined(Q_WS_MAEMO_5) || defined(QT_NO_OPENGL) // Set UI to low performance mode for Maemo5 and Symbian^1. This mainly // disables antialiasing on some performance costly elements. context->setContextProperty("lowPerf", true); #else context->setContextProperty("lowPerf", false); #endif #ifdef Q_OS_SYMBIAN context->setContextProperty("sampleFolder", "file:"); #else context->setContextProperty("sampleFolder", QString("file:/") + QDir::currentPath()); #endif #ifdef Q_WS_MAEMO_6 // Hide the exit button in Harmattan context->setContextProperty("exitButtonVisible", false); #else context->setContextProperty("exitButtonVisible", true); #endif m_view->setSource(QUrl("qrc:/qml/Main.qml")); // Create Qt settings object to load / store app settings m_settings = new QSettings("Nokia", "DJTurntable"); // Create Qt objects to handle Turntable and Drum machine m_turntable = new Turntable(m_settings, this); m_drumMachine = new DrumMachine(m_settings, this); m_turntable->addAudioSource(m_drumMachine); // Find out the interesting Qt objects of the QML elements QObject *turntableQML = dynamic_cast<QObject*>(m_view->rootObject()); QObject *sampleSelectorQML = m_view->rootObject()->findChild<QObject*>("sampleSelector"); QObject *drumMachineQML = m_view->rootObject()->findChild<QObject*>("drumMachine"); // If there are errors in QML code and the elements does not exist, // they won't be found Qt side either, check existance of the elements. if (!turntableQML || !sampleSelectorQML || !drumMachineQML) { QMessageBox::warning(NULL, "Warning", "Failed to resolve QML elements in main.cpp"); return; } // Turntable connections connect(turntableQML, SIGNAL(start()), m_turntable, SLOT(start())); connect(turntableQML, SIGNAL(stop()), m_turntable, SLOT(stop())); connect(turntableQML, SIGNAL(diskAimSpeed(QVariant)), m_turntable, SLOT(setDiscAimSpeed(QVariant))); connect(turntableQML, SIGNAL(diskSpeed(QVariant)), m_turntable, SLOT(setDiscSpeed(QVariant))); connect(turntableQML, SIGNAL(cutOff(QVariant)), m_turntable, SLOT(setCutOff(QVariant))); connect(turntableQML, SIGNAL(resonance(QVariant)), m_turntable, SLOT(setResonance(QVariant))); connect(turntableQML, SIGNAL(seekToPosition(QVariant)), m_turntable, SLOT(seekToPosition(QVariant))); connect(m_turntable, SIGNAL(audioPosition(QVariant)), turntableQML, SLOT(audioPosition(QVariant))); connect(m_turntable, SIGNAL(powerOff()), turntableQML, SLOT(powerOff())); // SampleSelector connections connect(sampleSelectorQML, SIGNAL(sampleSelected(QVariant)), m_turntable, SLOT(setSample(QVariant))); connect(sampleSelectorQML, SIGNAL(defaultSample()), m_turntable, SLOT(openDefaultSample())); connect(m_turntable, SIGNAL(sampleOpened(QVariant)), sampleSelectorQML, SLOT(setCurrentSample(QVariant))); connect(m_turntable, SIGNAL(error(QVariant, QVariant)), sampleSelectorQML, SLOT(showError(QVariant, QVariant))); // DrumMachine connections connect(drumMachineQML, SIGNAL(startBeat()), m_drumMachine, SLOT(startBeat())); connect(drumMachineQML, SIGNAL(stopBeat()), m_drumMachine, SLOT(stopBeat())); connect(drumMachineQML, SIGNAL(setBeat(QVariant)), m_drumMachine, SLOT(setBeat(QVariant))); connect(drumMachineQML, SIGNAL(drumButtonToggled(QVariant, QVariant, QVariant)), m_drumMachine, SLOT(drumButtonToggled(QVariant, QVariant, QVariant))); connect(drumMachineQML, SIGNAL(drumMachineSpeed(QVariant)), m_drumMachine, SLOT(setBeatSpeed(QVariant))); connect(m_drumMachine, SIGNAL(drumButtonState(QVariant, QVariant, QVariant)), drumMachineQML, SLOT(setDrumButton(QVariant, QVariant, QVariant))); connect(m_drumMachine, SIGNAL(tickChanged(QVariant)), drumMachineQML, SLOT(highlightTick(QVariant))); // Framework connections connect((QObject*)m_view->engine(), SIGNAL(quit()), qApp, SLOT(quit())); #if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6) #ifndef QT_NO_OPENGL // Create Qt accelerometer objects m_accelerometer = new QAccelerometer(this); m_accelerometerFilter = new AccelerometerFilter; // Does not take the ownership of the filter m_accelerometer->addFilter(m_accelerometerFilter); m_accelerometer->setDataRate(50); // Create Qt objects for accessing profile information m_deviceInfo = new QSystemDeviceInfo(this); m_turntable->profile(m_deviceInfo->currentProfile()); connect(m_accelerometerFilter, SIGNAL(rotationChanged(QVariant)), turntableQML, SLOT(inclination(QVariant))); connect(m_deviceInfo, SIGNAL(currentProfileChanged(QSystemDeviceInfo::Profile)), m_turntable, SLOT(profile(QSystemDeviceInfo::Profile))); // Begin the measuring of the accelerometer sensor m_accelerometer->start(); #endif #endif m_turntable->openLastSample(); m_drumMachine->setBeat(0); }
SingleSource::SingleSource(const SingleSource& other, const osg::CopyOp& copyop) : Source(other, copyop), failed(false) { setSample(other.sample.get()); }
int main(int argc, char **argv) { /* Initial number of changepoints */ int nK0=1; #ifdef FIXED FILE *pfp, *kfp, *Lfp; char *pfn="Probs.dat", *kfn="K.dat", *Lfn="Likelihood.dat"; prefix=NULL; #endif #ifndef FIXED getArgs(argc, argv); #else getFixedArgs(argc, argv); #endif processData(dataFn); initialise(); #ifdef FIXED if(prefix) { pfn=addPrefix(pfn, prefix); kfn=addPrefix(kfn, prefix); Lfn=addPrefix(Lfn, prefix); } pfp=fopen(pfn,"w"); kfp=fopen(kfn,"w"); Lfp=fopen(Lfn,"w"); setData(CDFdata, getNdata()); setSample(sampleMixed); iterate(pfp, kfp, Lfp, /* dPriorNew */dPriorFixedChangepoints, dFixedLikelihood,p0,nProb, ip0, nK, seed, nIter); #endif #ifdef DEFAULT if(!restart) { iterateRJ(prefix, prefix, prefix, prefix, sampleBirthDeath, dPriorChangepoints,dLikelihood, p0, nK0+1,1, nProb, ip0, nK0,1, nK, seed, nIter); } else { /* int k0[]={50000, 100000}; */ /* nK0=2; */ /* initialiseLocations(ip0, k0, CDFdata,getNdata()-1, */ /* p0, 2); */ FILE *re_fp=fopen(re_K, "rb"); char *buf=malloc(MAX_LEN+1); char *ll; int nReK=0, nReP=0; int i; int nums[NCHANGE+1]; double dNums[NCHANGE+2]; ll=lastLine(re_fp, buf, MAX_LEN); fclose(re_fp); nReK=str2ints(ll, nums); /* for(i=0; i<nReK; i++) { */ /* fprintf(OUT, "%d\t", nums[i]); */ /* } */ /* fprintf(OUT, "\nSuccessfully converted %d integers\n", nReK); */ re_fp=fopen(re_P, "rb"); ll=lastLine(re_fp, buf, MAX_LEN); free(buf); fclose(re_fp); nReP=str2doubles(ll, dNums); /* for(i=0; i<nReP; i++) { */ /* fprintf(OUT, "%f\t", dNums[i]); */ /* } */ /* fprintf(OUT, "\nSuccessfully converted %d doubles\n", nReP); */ initialiseLocationsAndProbs(ip0, p0, nums+1, dNums+1, nReK-1); /* printIntParameters(OUT, ip0, nReK-1); */ /* printParameters(OUT, p0, nReP-1); */ /* exit(1); */ iterateRJ(prefix, prefix, prefix, prefix, sampleBirthDeath, dPriorChangepoints,dLikelihood, p0, nReP-1,1, nProb, ip0, nReK-1,1, nK, seed, nIter); } #endif #ifdef GEO iterateRJ(prefix, prefix, prefix, prefix, sampleBirthDeath, dPriorChangepointsGeo,dLikelihood, p0, nK0+1,1, nProb, ip0, nK0,1, nK, seed, nIter); #endif #ifdef NEGATIVEBINK1 iterateRJ(prefix, prefix, prefix, prefix, sampleBirthDeath, dPriorChangepointsNegativeBinK1,dLikelihood, p0, nK0+1,1, nProb, ip0, nK0,1, nK, seed, nIter); #endif #ifdef NEGATIVEBINK2 iterateRJ(prefix, prefix, prefix, prefix, sampleBirthDeath, dPriorChangepointsNegativeBinK2,dLikelihood, p0, nK0+1,1, nProb, ip0, nK0,1, nK, seed, nIter); #endif #ifdef NJGEONEGATIVEBINK1 iterateRJ(prefix, prefix, prefix, prefix, sampleBirthDeath, dPriorChangepoints_nJGeoNegativeBinK1,dLikelihood, p0, nK0+1,1, nProb, ip0, nK0,1, nK, seed, nIter); #endif #ifdef NJGEONEGATIVEBINK2 iterateRJ(prefix, prefix, prefix, prefix, sampleBirthDeath, dPriorChangepoints_nJGeoNegativeBinK2,dLikelihood, p0, nK0+1,1, nProb, ip0, nK0,1, nK, seed, nIter); #endif return 0; }