本文整理汇总了C++中Gradient类的典型用法代码示例。如果您正苦于以下问题:C++ Gradient类的具体用法?C++ Gradient怎么用?C++ Gradient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Gradient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ASSERT
Gradient* CSSGradientValue::createGradient(RenderObject* renderer, const IntSize& size)
{
ASSERT(!size.isEmpty());
float zoomFactor = renderer->style()->effectiveZoom();
FloatPoint firstPoint = resolvePoint(m_firstX.get(), m_firstY.get(), size, zoomFactor);
FloatPoint secondPoint = resolvePoint(m_secondX.get(), m_secondY.get(), size, zoomFactor);
Gradient* gradient = 0;
if (m_type == CSSLinearGradient)
gradient = new Gradient(firstPoint, secondPoint);
else {
float firstRadius = resolveRadius(m_firstRadius.get(), zoomFactor);
float secondRadius = resolveRadius(m_secondRadius.get(), zoomFactor);
gradient = new Gradient(firstPoint, firstRadius, secondPoint, secondRadius);
}
// Now add the stops.
sortStopsIfNeeded();
// We have to resolve colors.
for (unsigned i = 0; i < m_stops.size(); i++) {
Color color = renderer->document()->styleSelector()->getColorFromPrimitiveValue(m_stops[i].m_color.get());
gradient->addColorStop(m_stops[i].m_stop, color);
}
// The back end already sorted the stops.
gradient->setStopsSorted(true);
return gradient;
}
示例2: creationEnsembleConnexe
void Seuillage::creationEnsembleConnexe(const IplImage* _img, const Gradient& _g)
{
cout << "Création ensemble connexe. " << endl;
std::vector<bool> tabPointsEffectues;
tabConnexite.clear();
tabPointsEffectues.assign(_g.getLargeur()*_g.getHauteur(), false);
numEnsembleConvexe = 0;
for(int i=0; i<_img->height; i++)
{
for(int j=0; j<_img->width; j++)
{
if(cvGet2D(_img,i,j).val[0] == 0 && tabPointsEffectues[i*(_img->width-1) + j] == false)
{
QPoint p(i,j);
vector<QPoint> v;
tabConnexite.push_back(v);
ajoutEnsembleConnexe(_img, p, tabPointsEffectues);
numEnsembleConvexe++;
}
}
}
cout << "L'image affinée comporte "<< tabConnexite.size() << " ensembles connexes. " << endl;
}
示例3: Gradient
// MakeGradient
Gradient*
SVGRadialGradient::MakeGradient() const
{
//printf("SVGRadialGradient::MakeGradient()\n");
// TODO: handle userSpaceOnUse/objectBoundingBox
Gradient* gradient = new Gradient(true);
gradient->SetType(GRADIENT_CIRCULAR);
gradient->SetInterpolation(INTERPOLATION_LINEAR);
double cx = 0.0;
double cy = 0.0;
double r = 100.0;
BString value;
if (FindString("cx", &value) >= B_OK)
cx = atof(value.String());
if (FindString("cy", &value) >= B_OK)
cy = atof(value.String());
if (FindString("r", &value) >= B_OK)
r = atof(value.String());
// the transformed parallelogram
double parl[6];
parl[0] = cx - r;
parl[1] = cy - r;
parl[2] = cx + r;
parl[3] = cy - r;
parl[4] = cx + r;
parl[5] = cy + r;
trans_affine transform(-64.0, -64.0, 64.0, 64.0, parl);
gradient->multiply(transform);
return gradient;
}
示例4: syncPlatformContext
static void syncPlatformContext(GraphicsContext* gc)
{
// Stroke and fill sometimes reference each other, so always
// sync them both to make sure our state is consistent.
PlatformGraphicsContext* pgc = gc->platformContext();
Gradient* grad = gc->state().fillGradient.get();
Pattern* pat = gc->state().fillPattern.get();
if (grad)
pgc->setFillShader(grad->platformGradient());
else if (pat)
pgc->setFillShader(pat->platformPattern(AffineTransform()));
else
pgc->setFillColor(gc->state().fillColor);
grad = gc->state().strokeGradient.get();
pat = gc->state().strokePattern.get();
if (grad)
pgc->setStrokeShader(grad->platformGradient());
else if (pat)
pgc->setStrokeShader(pat->platformPattern(AffineTransform()));
else
pgc->setStrokeColor(gc->state().strokeColor);
}
示例5: initilizeWeights
/**
* refer to the method vSGD-l from paper "No More Pesky Learning Rates"
**/
bool BiLogisticRegression::vlSGD(unsigned int rows, unsigned int cols,
const double* data, const int* label,
unsigned int maxIteration)
{
if (0==data || 0==label) return false;
typedef BiLogisticRegGradient Gradient;
typedef Optimization::ExpectedAdapLocalRates<GaussNewtonBbprop> LearningRates;
typedef Optimization::RelativeDiffValue<BiLRStandErrorFunction> StopCriterion;
typedef ForwardSelection Selection;
typedef Optimization::SGD<Gradient, LearningRates, StopCriterion, Selection> vSGD;
initilizeWeights(cols);
vSGD sgd(cols, &(m_Weights[0]));
const double* weights = sgd.getWeighs();
Gradient* gradient = new Gradient(cols, weights, data, label);
LearningRates* lr = new LearningRates(cols, gradient->getGradient());
lr->setDiagonalHessian(new GaussNewtonBbprop(cols, weights, data, label));
BiLRStandErrorFunction error(rows, cols, weights, data, label);
StopCriterion* sc = new StopCriterion(-1.0, 0.0000001, maxIteration, error);
const int window = (rows < 500) ? rows : 500;
Selection* sel = new Selection(window, 0, rows);
sgd.setGradient(gradient);
sgd.setLearningRates(lr);
sgd.setStopCriterion(sc);
sgd.setSelection(sel);
bool isSuccess = sgd.optimize(rows, cols, data, label);
std::copy(weights, weights + cols, m_Weights.begin());
return isSuccess;
}
示例6: new
void
StyleView::ObjectChanged(const Observable* object)
{
if (!fStyle)
return;
Gradient* controlGradient = fGradientControl->Gradient();
// NOTE: it is important to compare the gradients
// before assignment, or we will get into an endless loop
if (object == controlGradient) {
if (!fGradient)
return;
if (fIgnoreControlGradientNotifications)
return;
fIgnoreControlGradientNotifications = true;
if (!fGradient->ColorStepsAreEqual(*controlGradient)) {
// Make sure we never apply the transformation from the control
// gradient to the style gradient. Setting this here would cause to
// re-enter ObjectChanged(), which is prevented to cause harm via
// fIgnoreControlGradientNotifications.
controlGradient->SetTransform(*fGradient);
if (fCommandStack) {
fCommandStack->Perform(
new (nothrow) SetGradientCommand(
fStyle, controlGradient));
} else {
*fGradient = *controlGradient;
}
// transfer the current gradient color to the current color
_TransferGradientStopColor();
}
fIgnoreControlGradientNotifications = false;
} else if (object == fGradient) {
if (!fGradient->ColorStepsAreEqual(*controlGradient)) {
fGradientControl->SetGradient(fGradient);
_MarkType(fGradientType->Menu(), fGradient->Type());
// transfer the current gradient color to the current color
_TransferGradientStopColor();
}
} else if (object == fStyle) {
// maybe the gradient was added or removed
// or the color changed
_SetGradient(fStyle->Gradient(), false, true);
if (fCurrentColor && !fStyle->Gradient())
fCurrentColor->SetColor(fStyle->Color());
} else if (object == fCurrentColor) {
// NOTE: because of imprecisions in converting
// RGB<->HSV, the current color can be different
// even if we just set it to the current
// gradient stop color, that's why we ignore
// notifications caused by this situation
if (!fIgnoreCurrentColorNotifications)
_AdoptCurrentColor(fCurrentColor->Color());
}
}
示例7: Gradient
Gradient *GradientAdjuster::getAdjusted(Gradient *gradient, ElevationModel *em)
{
float min = (em->getAverage()-1.5*em->getDeviation())/HGT_RANGE;
float newRange = (3*em->getDeviation())/HGT_RANGE;
Gradient *output = new Gradient(*gradient);
QVector<Stop*> stops = output->getStops();
for (int i=0; i<stops.size(); i++)
stops.at(i)->setPosition(stops.at(i)->getPosition()*newRange + min*100000);
return output;
}
示例8: drawEdges
void Vision::drawEdges(Gradient& g)
{
#ifdef OFFLINE
if (thresh->debugEdgeDetection){
for (int i=0; g.isPeak(i); ++i) {
drawDot(g.getAnglesXCoord(i) + IMAGE_WIDTH/2,
g.getAnglesYCoord(i) + IMAGE_HEIGHT/2,
PINK);
}
}
#endif
}
示例9: set
void Gradient::set(const Gradient& gradient)
{
// copy the gradient
resize(gradient.size());
copy(gradient.begin(), gradient.end(), begin());
//copy the norm and the valid_ flag
norm = gradient.norm;
inv_norm = gradient.inv_norm;
rms = gradient.rms;
valid_ = gradient.valid_;
}
示例10: printf
synfig::ValueBase
synfig::ValueNode_GradientRotate::operator()(Time t)const
{
if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
printf("%s:%d operator()\n", __FILE__, __LINE__);
Gradient gradient;
gradient=(*ref_gradient)(t).get(gradient);
Real offset((*ref_offset)(t).get(Real()));
Gradient::iterator iter;
for(iter=gradient.begin();iter!=gradient.end();++iter)
iter->pos+=offset;
return gradient;
}
示例11: singlePoint
void singlePoint()
{
double energy = amber.updateEnergy();
amber.updateForces();
Gradient grad;
grad.set(amber.getAtoms());
grad.normalize();
Log.info() << "single point energy: " << energy << " kJ/mol" << endl;
Log.info() << " - stretch :" << amber.getStretchEnergy() << " kJ/mol" << endl;
Log.info() << " - bend :" << amber.getBendEnergy() << " kJ/mol" << endl;
Log.info() << " - torsion :" << amber.getTorsionEnergy() << " kJ/mol" << endl;
Log.info() << " - VdW :" << amber.getVdWEnergy() << " kJ/mol" << endl;
Log.info() << " - electrostatic:" << amber.getESEnergy() << " kJ/mol" << endl;
Log.info() << "grad: " << grad.rms << endl;
}
示例12: TEST_F
TEST_F(HoughSpaceTest, HoughSpace)
{
Gradient g;
// Create gradient map such that it has a known line
g.createLineAtPoint(0, 80);
// Run the gradient through the Hough Space
hs.markEdges(g);
for (int t=0; t < HoughConstants::t_span; ++t){
for (int r=0; r < HoughConstants::r_span; ++r){
EXPECT_GE(hs.getHoughBin(r,t) , 0);
}
}
// Check to make sure there is a point at r = 80 = img_width/4 , theta = 0
// which is where the above gradient has a line, roughly.
EXPECT_GT(hs.getHoughBin(IMAGE_WIDTH * 1/4 + HoughConstants::r_span/2,0) , 0);
// Notice that it is t_span +1. This is the same as in the
// Hough Space.
uint16_t pre[HoughConstants::t_span+10][HoughConstants::r_span];
for (int t=0; t < HoughConstants::t_span+10; ++t){
for(int r=0; r < HoughConstants::r_span; ++r){
pre[t][r] = hs.hs[t][r];
}
}
hs.smooth();
// Test if smoothing worked
for (int t=HoughConstants::first_smoothing_row;
t < HoughConstants::t_span + HoughConstants::first_smoothing_row; ++t){
for (int r=0; r < HoughConstants::r_span-1; ++r){
int preSum = (pre[t][r] + pre[t+1][r] +
pre[t][r+1] + pre[t+1][r+1]) -
hs.getAcceptThreshold()*4; // Smoothing grows mag by 4x
preSum = max(preSum, 0); // Bound it at zero
int smoothed = hs.getHoughBin(r,t);
EXPECT_EQ( smoothed, preSum);
}
}
}
示例13: InvalidRange
// dot product of two gradients
double Gradient::operator * (const Gradient& gradient) const
{
Size max_index = (Size)size();
if (gradient.size() != max_index)
{
throw Exception::InvalidRange(__FILE__, __LINE__, gradient.size());
}
double result = 0.0;
for (Size i = 0; i < max_index; i++)
{
result += operator[](i) * gradient[i];
}
return result;
}
示例14: optimize
void MinfuncLBFGS::optimize(MatrixXd& data, MatrixXd& label, MatrixXd& weight, Gradient& gradfunc)
{
int iters = this->iters;
float alpha = this->alpha;
int keep = this->keep;
MatrixXd grad, descent, old_grad;
vector<MatrixXd> old_directions, old_steps;
double hession;
for(int index = 0; index < iters; index++)
{
cout<<"turn: "<<index<<endl;
grad = gradfunc.compute_grad(data, label, weight);
if(index == 0)
{
descent = -grad;
hession = 1;
}
else
{
lbfgs_update(grad - old_grad, alpha*descent, old_directions, old_steps, keep, hession);
descent = lbfgs_descent(-grad, old_directions, old_steps, hession);
}
old_grad = grad;
weight = weight + alpha*descent;
}
}
示例15: addAction
void ParticleEditor::applyState()
{
StateObject::applyState();
ActionMapper::clearActions();
ActionMapper::clearCreatedEvents();
addAction(MakeFunctionEvent(ParticleEditor, load), KEY_F1, 0);
addAction(MakeFunctionEvent(ParticleEditor, reload), KEY_F5, 0);
//addAction(MakeFunctionEvent(ParticleEditor, start), KEY_F5, 0);
//addAction(MakeFunctionEvent(ParticleEditor, stop), KEY_F6, 0);
addAction(MakeFunctionEvent(ParticleEditor, start), MOUSE_BUTTON_LEFT, 0);
addAction(MakeFunctionEvent(ParticleEditor, stop), MOUSE_BUTTON_RIGHT, 0);
addAction(MakeFunctionEvent(ParticleEditor, goToTitle), KEY_ESCAPE, 0);
addAction(MakeFunctionEvent(ParticleEditor, toggleHair), KEY_F9, 0);
Gradient *grad = new Gradient;
grad->scale = Vector(800, 600);
grad->position = Vector(400,300);
grad->makeVertical(Vector(0.4, 0.4, 0.4), Vector(0.8, 0.8, 0.8));
addRenderObject(grad, LR_BACKDROP);
core->cameraPos = Vector(0,0);
emitter = new ParticleEffect;
//emitter->followCamera = 1;
//emitter->position = Vector(400,300);
addRenderObject(emitter, LR_ENTITIES);
dsq->overlay->alpha.interpolateTo(0, 0.5);
hair = new Hair(20,12,32);
hair->setTexture("eel-0001");
hair->followCamera = 1;
addRenderObject(hair, LR_PARTICLES);
hair->alpha = 0;
test = new Quad;
test->color = 0;
test->scale = Vector(64,64);
test->position = Vector(400,300);
test->offset = Vector(0,-80);
addRenderObject(test, LR_PARTICLES);
test->alpha = 0;
}