本文整理汇总了C++中Samples类的典型用法代码示例。如果您正苦于以下问题:C++ Samples类的具体用法?C++ Samples怎么用?C++ Samples使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Samples类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: clear
void clear() {
SamplesIterator i, end = samples.end();
for (i = samples.begin(); i != end; ++i) {
// delete object pointed to by Sample* pointer
delete (*i);
}
samples.clear();
byNames.clear();
marker::manager.unref(markers);
}
示例2: evaluateRange
BSplineInterpolation::Samples BSplineInterpolation::evaluateRange(
const float start, const float stop, const float stepsize)
{
Samples samples;
for (float x=start; x<stop; x+=stepsize) {
float y = evaluate(x);
samples.push_back(std::make_pair(x, y));
}
return samples;
}
示例3: samples
OfflineKMeans::OfflineKMeans(const Samples<float>& data, const int k): samples(data),
featureNum(data.getFeatureNum()), sampleNum(data.getSampleNum()), clusterNum(k) {
initClusters();
#ifdef OKM_DBG
print();
while(reCluster() == true) {
print();
}
#else
while(reCluster() == true);
#endif
}
示例4: Sample
void TransformStack::motionBegin( const std::vector<float> × )
{
// resample the current stack top at the specified times
Samples newSamples;
for( std::vector<float>::const_iterator it = times.begin(), eIt = times.end(); it != eIt; ++it )
{
newSamples.push_back( Sample( *it, get( *it ) ) );
}
m_stack.top() = newSamples;
m_motionIndex = 0;
}
示例5: TEST_F
TEST_F(HannWindowFilterTest, exampleData) {
//given
Samples samples;
cx test[] = { cx(0, 0), cx(1, 0)};
samples.setSampleListData(2, test);
double result []= { 0, 0.5 * (1 - cos(M_PI)) };
filter.applyOn(samples);
ASSERT_EQ(samples.getSample(0), result[0]);
ASSERT_EQ(samples.getSample(1), result[1]);
}
示例6: createDataFile
void DocumentExporter::createDataFile(const Samples& samples, std::ostream& os, Image* textureImage)
{
os << "{ \"frames\": {\n";
for (Samples::const_iterator
it = samples.begin(),
end = samples.end(); it != end; ) {
gfx::Size srcSize = it->originalSize();
gfx::Rect spriteSourceBounds = it->trimmedBounds();
gfx::Rect frameBounds = it->inTextureBounds();
os << " \"" << it->filename() << "\": {\n"
<< " \"frame\": { "
<< "\"x\": " << frameBounds.x << ", "
<< "\"y\": " << frameBounds.y << ", "
<< "\"w\": " << frameBounds.w << ", "
<< "\"h\": " << frameBounds.h << " },\n"
<< " \"rotated\": false,\n"
<< " \"trimmed\": " << (it->trimmed() ? "true": "false") << ",\n"
<< " \"spriteSourceSize\": { "
<< "\"x\": " << spriteSourceBounds.x << ", "
<< "\"y\": " << spriteSourceBounds.y << ", "
<< "\"w\": " << spriteSourceBounds.w << ", "
<< "\"h\": " << spriteSourceBounds.h << " },\n"
<< " \"sourceSize\": { "
<< "\"w\": " << srcSize.w << ", "
<< "\"h\": " << srcSize.h << " },\n"
<< " \"duration\": " << it->sprite()->getFrameDuration(it->frame()) << "\n"
<< " }";
if (++it != samples.end())
os << ",\n";
else
os << "\n";
}
os << " },\n"
<< " \"meta\": {\n"
<< " \"app\": \"" << WEBSITE << "\",\n"
<< " \"version\": \"" << VERSION << "\",\n";
if (!m_textureFilename.empty())
os << " \"image\": \"" << m_textureFilename.c_str() << "\",\n";
os << " \"format\": \"" << (textureImage->getPixelFormat() == IMAGE_RGB ? "RGBA8888": "I8") << "\",\n"
<< " \"size\": { "
<< "\"w\": " << textureImage->getWidth() << ", "
<< "\"h\": " << textureImage->getHeight() << " },\n"
<< " \"scale\": \"" << m_scale << "\"\n"
<< " }\n"
<< "}\n";
}
示例7: add_samples
void
diy::detail::KDTreeSamplingPartition<Block,Point>::
add_samples(Block* b, const diy::ReduceProxy& srp, Samples& samples) const
{
// dequeue and combine the samples
for (int i = 0; i < srp.in_link().size(); ++i)
{
int nbr_gid = srp.in_link().target(i).gid;
Samples smpls;
srp.dequeue(nbr_gid, smpls);
for (size_t i = 0; i < smpls.size(); ++i)
samples.push_back(smpls[i]);
}
}
示例8: drawSpectogram
void drawSpectogram(Samples& samples, const char * file) {
uint16_t samplesInFrame = static_cast<uint16_t>(std::ceil(samples.getNumberOfSamples() / MfccProperty::MAX_FRAME));
Aquila::FramesCollection frames = Aquila::FramesCollection(samples, samplesInFrame,
static_cast<unsigned int>(std::round(0.2 * samplesInFrame)));
std::cout << "samples per frame "<< frames.getSamplesPerFrame();
Aquila::Spectrogram spectrogram{frames};
size_t w = 800;
size_t h = 600;
std::cout << " w = " << w << " h = " << h << std::endl;
cimg_library::CImg<unsigned char> simg{static_cast<unsigned int>(800), static_cast<unsigned int>(600), 1, 2, 0};
for (std::size_t x = 0; x < spectrogram.getFrameCount(); ++x) {
// output only half of the spectrogram, below Nyquist frequency
for (std::size_t y = h/2; y < h ; ++y) {
Aquila::ComplexType point = spectrogram.getPoint(x, y);
unsigned char color[] = {0, 0, 0};
double value = point.real() * point.real() + point.imag() * point.imag();
value = 0.5 * std::log10(value + 1);
std::cout << "value = " << value << std::endl;
getColor(value, color);
// color[0] = (unsigned char) (125 + sDb);
// color[1] = (unsigned char) (125 + sDb);
// color[2] = (unsigned char) (125 + sDb);
simg.draw_point(x, y, 0, color);
}
}
simg.save_jpeg(file);
}
示例9: captureSamples
void DocumentExporter::captureSamples(Samples& samples)
{
std::vector<char> buf(32);
for (std::vector<Document*>::iterator
it = m_documents.begin(),
end = m_documents.end(); it != end; ++it) {
Document* document = *it;
Sprite* sprite = document->getSprite();
for (FrameNumber frame=FrameNumber(0);
frame<sprite->getTotalFrames(); ++frame) {
base::string filename = document->getFilename();
if (sprite->getTotalFrames() > FrameNumber(1)) {
int frameNumWidth =
(sprite->getTotalFrames() < 10)? 1:
(sprite->getTotalFrames() < 100)? 2:
(sprite->getTotalFrames() < 1000)? 3: 4;
std::sprintf(&buf[0], "%0*d", frameNumWidth, frame);
base::string path = base::get_file_path(filename);
base::string title = base::get_file_title(filename);
base::string ext = base::get_file_extension(filename);
filename = base::join_path(path, title + &buf[0] + "." + ext);
}
samples.addSample(Sample(document, sprite, frame, filename));
}
}
}
示例10: compute_local_samples
void
diy::detail::KDTreeSamplingPartition<Block,Point>::
compute_local_samples(Block* b, const diy::ReduceProxy& srp, int dim) const
{
// compute and enqueue local samples
Samples samples;
size_t points_size = (b->*points_).size();
size_t n = std::min(points_size, samples_);
samples.reserve(n);
for (size_t i = 0; i < n; ++i)
{
float x = (b->*points_)[rand() % points_size][dim];
samples.push_back(x);
}
srp.enqueue(srp.out_link().target(0), samples);
}
示例11: operator
void
diy::detail::KDTreeSamplingPartition<Block,Point>::
operator()(Block* b, const diy::ReduceProxy& srp, const KDTreePartners& partners) const
{
int dim;
if (srp.round() < partners.rounds())
dim = partners.dim(srp.round());
else
dim = partners.dim(srp.round() - 1);
if (srp.round() == partners.rounds())
update_links(b, srp, dim, partners.sub_round(srp.round() - 2), partners.swap_rounds(), partners.wrap, partners.domain); // -1 would be the "uninformative" link round
else if (partners.swap_round(srp.round()) && partners.sub_round(srp.round()) < 0) // link round
{
dequeue_exchange(b, srp, dim); // from the swap round
split_to_neighbors(b, srp, dim);
}
else if (partners.swap_round(srp.round()))
{
Samples samples;
receive_samples(b, srp, samples);
enqueue_exchange(b, srp, dim, samples);
} else if (partners.sub_round(srp.round()) == 0)
{
if (srp.round() > 0)
{
int prev_dim = dim - 1;
if (prev_dim < 0)
prev_dim += dim_;
update_links(b, srp, prev_dim, partners.sub_round(srp.round() - 2), partners.swap_rounds(), partners.wrap, partners.domain); // -1 would be the "uninformative" link round
}
compute_local_samples(b, srp, dim);
} else if (partners.sub_round(srp.round()) < (int) partners.histogram.rounds()/2) // we are reusing partners class, so really we are talking about the samples rounds here
{
Samples samples;
add_samples(b, srp, samples);
srp.enqueue(srp.out_link().target(0), samples);
} else
{
Samples samples;
add_samples(b, srp, samples);
if (samples.size() != 1)
{
// pick the median
std::nth_element(samples.begin(), samples.begin() + samples.size()/2, samples.end());
std::swap(samples[0], samples[samples.size()/2]);
//std::sort(samples.begin(), samples.end());
//samples[0] = (samples[samples.size()/2] + samples[samples.size()/2 + 1])/2;
samples.resize(1);
}
forward_samples(b, srp, samples);
}
}
示例12: renderTexture
void DocumentExporter::renderTexture(const Samples& samples, Image* textureImage)
{
textureImage->clear(0);
for (Samples::const_iterator
it = samples.begin(),
end = samples.end(); it != end; ++it) {
// Make the sprite compatible with the texture so the render()
// works correctly.
if (it->sprite()->getPixelFormat() != textureImage->getPixelFormat()) {
DocumentApi docApi(it->document(), NULL); // DocumentApi without undo
docApi.setPixelFormat(it->sprite(), textureImage->getPixelFormat(),
DITHERING_NONE);
}
it->sprite()->render(textureImage,
it->inTextureBounds().x - it->trimmedBounds().x,
it->inTextureBounds().y - it->trimmedBounds().y,
it->frame());
}
}
示例13: gsl_vector_alloc
void BSplineInterpolation::fitFromData(const Samples &samples) {
/* preprocess samples and extract some info */
Samples ssamples = samples;
std::sort(ssamples.begin(), ssamples.end());
const int numSamples = ssamples.size();
const float minSampleX = ssamples[0].first;
const float maxSampleX = ssamples.back().first;
/* prepare fitting data */
gsl_vector *x = gsl_vector_alloc(ssamples.size());
gsl_vector *y = gsl_vector_alloc(ssamples.size());
for (int i=0; i<ssamples.size(); i++) {
gsl_vector_set(x, i, ssamples[i].first);
gsl_vector_set(y, i, ssamples[i].second);
}
/* uniform knots distributed in sample range */
gsl_bspline_knots_uniform(minSampleX, maxSampleX, bSplineWorkspace);
/* construct a fit matrix */
gsl_matrix *fitMatrix = gsl_matrix_alloc(numSamples, nCoeffs);
for (int i=0; i<numSamples; i++) {
/* compute B_j(xi) for all j */
double xi = gsl_vector_get(x, i);
gsl_bspline_eval(xi, bSpline, bSplineWorkspace);
/* fill in row i */
for (int j=0; j<nCoeffs; j++) {
double Bj = gsl_vector_get(bSpline, j);
gsl_matrix_set(fitMatrix, i, j, Bj);
}
}
/* fit spline to data */
gsl_multifit_linear_workspace *mws =
gsl_multifit_linear_alloc(numSamples, nCoeffs);
double chisq;
size_t rank;
double tol = 0.1;
gsl_multifit_linear(fitMatrix, y, cParameters, covMatrix, &chisq, mws);
//gsl_multifit_linear_svd(fitMatrix, y, tol,
// &rank, cParameters, covMatrix, &chisq, mws);
splineMinX = minSampleX;
splineMaxX = maxSampleX;
/* clean up */
gsl_vector_free(x);
gsl_vector_free(y);
gsl_matrix_free(fitMatrix);
gsl_multifit_linear_free(mws);
}
示例14: TEST_F
TEST_F(SpectrumPropertyTest, testCalulate) {
//given
Samples samples;
double * samplesValue = new double[6];
samplesValue[0] = 10;
samplesValue[1] = 0;
samplesValue[2] = 0;
samplesValue[3] = 0;
samplesValue[4] = 0;
samplesValue[5] = 100;
samples.setSamplesData(samplesValue, 6, 6);
SpectrumProperty property;
//when
double result = property.getValue(samples);
//then
ASSERT_DOUBLE_EQ(result, 1.);
}
示例15: record
void NonCalls::record(const string& seqName, long pos, const Samples& samples) {
map<string, NonCall>& site = (*this)[seqName][pos];
for (Samples::const_iterator s = samples.begin(); s != samples.end(); ++s) {
// tally ref and non-ref alleles
const string& name = s->first;
const Sample& sample = s->second;
NonCall& noncall = site[name];
for (Sample::const_iterator a = sample.begin(); a != sample.end(); ++a) {
const vector<Allele*>& alleles = a->second;
for (vector<Allele*>::const_iterator o = alleles.begin(); o != alleles.end(); ++o) {
Allele& allele = **o;
if (allele.isReference()) {
++noncall.refCount;
noncall.reflnQ += allele.lnquality;
} else {
++noncall.altCount;
noncall.altlnQ += allele.lnquality;
}
}
}
}
}