示例#1
0
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
0
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
0
// 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;
}
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);
}
	/**
	* 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
0
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
0
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
0
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
0
文件: gradient.C 项目: HeyJJ/ball
	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
0
// GetGradient
Gradient*
SVGGradient::GetGradient(BRect objectBounds)
{
	if (fGradient) {
		Gradient* gradient = new Gradient(*fGradient);

		IdentifyGradientUnits();
		if (fGradientUnits == OBJECT_BOUNDING_BOX) {
			gradient->FitToBounds(objectBounds);
		}

		return gradient;
	}
	return NULL;
}
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;
}
示例#12
0
文件: files.C 项目: HeyJJ/ball
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;
}
示例#13
0
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);
        }
    }
}
示例#14
0
文件: gradient.C 项目: HeyJJ/ball
	// 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;
	}
    void init(pointClouds &pointCloud_interest)
    {
        cout<<"n points "<<pointCloud_interest.nPointsC<<endl;
        if(pointCloud_interest.nPointsC<1000)
        {
            for(size_t i=0;i<pointCloud_interest.nPointsC;i++)
            {
                points.push_back(pointCloud_interest.point_cloud[i]);
            }

        }
        else
        {
            int i=0;
            Vector point;
            point.resize(3,0.0);
            while(i<pointCloud_interest.nPointsC)
            {
                points.push_back(pointCloud_interest.point_cloud[i]);
                i=i+30;
            }
        }

        aux_objvalue=0.0;
        first_gof=true;
        first_gogr=true;

       //computeBounds();

        grad.init(points);

    }
示例#16
0
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;
    } 
}
示例#17
0
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;
}
示例#18
0
void test_for_line(uint8_t angle, float radius)
{
    float radAngle = static_cast<float>(angle) * M_PI_FLOAT / 128.f;

    Gradient g;

    g.reset();
    g.clear();
    g.createLineAtPoint(angle, radius);

    HoughSpaceImpl hs;
    hs.reset();
    hs.findHoughLines(g);

    list<HoughLine> lines;
    for (int i=0; i < hs.activeLines.size(); ++i){
        if (hs.activeLines.active(i)){
            lines.push_back(hs.activeLines[i]);
        }
    }

    EXPECT_FALSE(lines.empty());

    float maxRadius = sqrtf(IMAGE_WIDTH * IMAGE_WIDTH +
                            IMAGE_HEIGHT * IMAGE_HEIGHT);

    bool foundFixedLine = false;
    list<HoughLine>::iterator l = lines.begin();

    while (l != lines.end()){
        EXPECT_LE(l->getRadius() , maxRadius); // Line must be in image
        EXPECT_GE(l->getRadius(), -maxRadius); // in either direction
        EXPECT_GE(l->getAngle() , 0);          // 0 <= Angle <= 2 * pi
        EXPECT_LE(l->getAngle() ,
                  2 * M_PI_FLOAT + HoughSpaceTest::ACCEPT_ANGLE);
        EXPECT_GE(l->getScore() , 0);

        // Make sure the system found the one line in the gradient
        if (isDesiredLine(radius, radAngle, *l)){
            foundFixedLine = true;
        }
        l++;
    }
    // We better have found that line
    EXPECT_TRUE(foundFixedLine);
}
示例#19
0
void testPoisson2D(std::string srcImage) {


	// simulating reconstructed features

	cv::Mat src = cv::imread(srcImage);

	uint w = src.size().width, h = src.size().height;
	if (src.channels() > 1) {
		cv::cvtColor(src, src, cv::COLOR_RGB2GRAY);
	}

	auto dst = simulateKeyPoints(src, 1);

	// displaying them

	cv::imshow("image", showKeyPoints(dst, src));

	Cloud cloud{ w, h, dst };

	cv::Mat gradX;
	cv::Sobel(src, gradX, CV_32F, 1, 0);
	cv::Mat gradY;
	cv::Sobel(src, gradY, CV_32F, 0, 1);
	float* gradXp = (float*)gradX.data;
	float* gradYp = (float*)gradY.data;

	Gradient orgGrad(gradX, gradY);

	cv::imshow("original gradient", 0.5 + 0.001*orgGrad.display());

	Gradient grad = cloud.reconstructGradient();
	cv::imshow("reconstructed gradient", grad.display());

	cv::imshow("reconstructed divergence", 0.5 + grad.getDivergence());

	cv::imshow("divergence", 0.5 + 0.0001*orgGrad.getDivergence());

	cv::waitKey(1);

	cv::imshow("integration", 0.5 + grad.poissonIntegration());

	cv::waitKey();
}
示例#20
0
//Compute gradient
void UnconstrainedOptimizer::G()
{
	dVector dgrad(n);
	memcpy(vecGradient.get(),x,n*sizeof(double));
	currentModel->setWeights(vecGradient);
	if(currentModel->getDebugLevel() >= 2)
		std::cout << "Compute gradient..." << std::endl;
	currentGradient->computeGradient(dgrad, currentModel,currentDataset);
	memcpy(g,dgrad.get(),n*sizeof(double));
}
示例#21
0
RefTargetHandle Gradient::Clone(RemapDir &remap) 
	{
	Gradient *mnew = new Gradient();
	*((MtlBase*)mnew) = *((MtlBase*)this);  // copy superclass stuff
	mnew->ReplaceReference(0,remap.CloneRef(uvGen));
	mnew->ReplaceReference(TEXOUT_REF,remap.CloneRef(texout));
	mnew->ReplaceReference(1,remap.CloneRef(pblock));
	mnew->col[0] = col[0];
	mnew->col[1] = col[1];
	mnew->col[2] = col[2];	
	mnew->ivalid.SetEmpty();	
	for (int i = 0; i<NSUBTEX; i++) {
		mnew->subTex[i] = NULL;
		if (subTex[i])
			mnew->ReplaceReference(i+2,remap.CloneRef(subTex[i]));
		mnew->mapOn[i] = mapOn[i];
		}
	BaseClone(this, mnew, remap);
	return (RefTargetHandle)mnew;
	}
void ChromoConditions::setGradient(Gradient newGradient)
    throw(ChromoConditionsException)
{
    if (newGradient.size() < 2)
    {
        throw ChromoConditionsException(
            "The gradient must contain at least two points.");
    }
    mGradient = newGradient;
    recalculateSSConcentrations();
}
示例#23
0
void GraphicsContext::fillRect(const FloatRect& rect, Gradient& gradient)
{
    if (paintingDisabled())
        return;

    if (isRecording()) {
        m_displayListRecorder->fillRect(rect, gradient);
        return;
    }

    gradient.fill(this, rect);
}
synfig::ValueBase
synfig::ValueNode_Repeat_Gradient::operator()(Time t)const
{
	if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
		printf("%s:%d operator()\n", __FILE__, __LINE__);

	const int count((*count_)(t).get(int()));
	int i;
	Gradient ret;

	if(count<=0)
		return ret;

	const Gradient gradient((*gradient_)(t).get(Gradient()));
	const float width(max(0.0,min(1.0,(*width_)(t).get(Real()))));
	const bool specify_start((*specify_start_)(t).get(bool()));
	const bool specify_end((*specify_end_)(t).get(bool()));

	const float gradient_width_a(width/count);
	const float gradient_width_b((1.0-width)/count);

	Gradient::const_iterator iter;
	Gradient::const_reverse_iterator riter;
	if (specify_start)
		ret.push_back(Gradient::CPoint(0,(*start_color_)(t).get(Color())));
	for(i=0;i<count;i++)
	{
		float pos(float(i)/count);
		if (width != 0.0)
			for(iter=gradient.begin();iter!=gradient.end();iter++)
				ret.push_back(Gradient::CPoint(pos+gradient_width_a*iter->pos,iter->color));
		pos+=gradient_width_a;
		if (width != 1.0)
			for(riter=gradient.rbegin();riter!=gradient.rend();riter++)
				ret.push_back(Gradient::CPoint(pos+gradient_width_b*(1-(riter->pos)),riter->color));
	}
	if (specify_end)
		ret.push_back(Gradient::CPoint(1,(*end_color_)(t).get(Color())));
	return ret;
}
// SetColors
void
Gradient::SetColors(const Gradient& other)
{
#ifdef ICON_O_MATIC
	AutoNotificationSuspender _(this);
#endif

	_MakeEmpty();
	for (int32 i = 0; BGradient::ColorStop* step = other.ColorAt(i); i++)
		AddColor(*step, i);

	Notify();
}
// ColorStepsAreEqual
bool
Gradient::ColorStepsAreEqual(const Gradient& other) const
{
	int32 count = CountColors();
	if (count == other.CountColors() &&
		fType == other.fType &&
		fInterpolation == other.fInterpolation &&
		fInheritTransformation == other.fInheritTransformation) {

		bool equal = true;
		for (int32 i = 0; i < count; i++) {
			BGradient::ColorStop* ourStep = ColorAtFast(i);
			BGradient::ColorStop* otherStep = other.ColorAtFast(i);
			if (*ourStep != *otherStep) {
				equal = false;
				break;
			}
		}
		return equal;
	}
	return false;
}
示例#27
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Gradient Application::configGetColorGradient(const std::string& query,
                                             const Gradient& base) const {
	const Seiscomp::Config::Config &config = configuration();
	bool error = false;

	std::vector<std::string> colors = config.getStrings(query, &error);
	if ( error ) return base;

	Gradient grad;
	for ( size_t i = 0; i < colors.size(); ++i ) {
		QColor color;
		qreal value;

		std::vector<std::string> toks;
		size_t size = Core::split(toks, colors[i].c_str(), ":");
		if ( size < 2 || size > 3 ) {
			SEISCOMP_ERROR("Wrong format of color entry %lu in '%s'",
			               (unsigned long)i, query.c_str());
			return base;
		}

		if ( !Core::fromString(value, toks[0]) ) {
			SEISCOMP_ERROR("Wrong value format of color entry %lu in '%s'",
			               (unsigned long)i, query.c_str());
			return base;
		}

		bool ok;
		color = readColor("", toks[1], color, &ok);
		if ( !ok ) return base;

		QString text;
		if ( size == 3 ) text = QString::fromStdString(toks[2]);

		grad.setColorAt(value, color, text);
	}

	return grad;
}
示例#28
0
// Compute the alpha term of Eq. 69
Number EnergySystem :: alpha(Gradient grad_T, Gradient grad_h, Number f){
	
	Real mag_grad_h = grad_h.size();
		
	if (mag_grad_h > 0){
		return (grad_T * grad_h) / (mag_grad_h * mag_grad_h);
	
	} else {
		const Number cf = thermo->get_constant<Number>("specific_heat_fluid");
		const Number cs = thermo->get_constant<Number>("specific_heat_solid");
		return 1 / (cs + cf*f - cs*f);  
		//return - 1 / ((cf - cs) * (f - 1));
	}
} 
示例#29
0
// MakeGradient
Gradient*
SVGLinearGradient::MakeGradient() const
{
//printf("SVGLinearGradient::MakeGradient()\n");
//PrintToStream();

	Gradient* gradient = new Gradient(true);
	gradient->SetType(GRADIENT_LINEAR);
	gradient->SetInterpolation(INTERPOLATION_LINEAR);
	// setup the gradient transform 
	BPoint start(-64.0, -64.0);
	BPoint end(64.0, -64.0);
	BString coordinate;
	if (FindString("x1", &coordinate) >= B_OK)
		start.x = atof(coordinate.String());
	if (FindString("y1", &coordinate) >= B_OK)
		start.y = atof(coordinate.String());
	if (FindString("x2", &coordinate) >= B_OK)
		end.x = atof(coordinate.String());
	if (FindString("y2", &coordinate) >= B_OK)
		end.y = atof(coordinate.String());

	// the transformed parallelogram
	double parl[6];
	parl[0] = start.x;
	parl[1] = start.y;
	parl[2] = end.x;
	parl[3] = end.y;
	parl[4] = end.x - (end.y - start.y);
	parl[5] = end.y + (end.x - start.x);

	trans_affine transform(-64.0, -64.0, 64.0, 64.0, parl);
	gradient->multiply(transform);

	return gradient;
}
// constructor
Gradient::Gradient(const Gradient& other)
#ifdef ICON_O_MATIC
	: BArchivable(other),
	  Observable(),
	  Transformable(other),
#else
	: Transformable(other),
#endif

	  fColors(4),
	  fType(other.fType),
	  fInterpolation(other.fInterpolation),
	  fInheritTransformation(other.fInheritTransformation)
{
	for (int32 i = 0; BGradient::ColorStop* step = other.ColorAt(i); i++) {
		AddColor(*step, i);
	}
}