/* Dongxu Li's Version, 19 Aug 2011 * scale an ellipse * Find the eigen vactors and eigen values by optimization * original ellipse equation, * x= a cos t * y= b sin t * rotated by angle, * * x = a cos t cos (angle) - b sin t sin(angle) * y = a cos t sin (angle) + b sin t cos(angle) * scaled by ( kx, ky), * x *= kx * y *= ky * find the maximum and minimum of x^2 + y^2, */ void RS_Ellipse::scale(RS_Vector center, RS_Vector factor) { data.center.scale(center, factor); RS_Vector vpStart=getStartpoint().scale(getCenter(),factor); RS_Vector vpEnd=getEndpoint().scale(getCenter(),factor);; double ct=cos(getAngle()); double ct2 = ct*ct; // cos^2 angle double st=sin(getAngle()); double st2=1.0 - ct2; // sin^2 angle double kx2= factor.x * factor.x; double ky2= factor.y * factor.y; double a=getMajorRadius(); double b=getMinorRadius(); double cA=0.5*a*a*(kx2*ct2+ky2*st2); double cB=0.5*b*b*(kx2*st2+ky2*ct2); double cC=a*b*ct*st*(ky2-kx2); RS_Vector vp(cA-cB,cC); setMajorP(RS_Vector(a,b).scale(RS_Vector(vp.angle())).rotate(RS_Vector(ct,st)).scale(factor)); a=cA+cB; b=vp.magnitude(); setRatio( sqrt((a - b)/(a + b) )); if( std::isnormal(getAngle1()) || std::isnormal(getAngle2() ) ) { //only reset start/end points for ellipse arcs, i.e., angle1 angle2 are not both zero setAngle1(getEllipseAngle(vpStart)); setAngle2(getEllipseAngle(vpEnd)); } correctAngles();//avoid extra 2.*M_PI in angles //calculateEndpoints(); calculateBorders(); }
void OrbitCamera::applyPerspectiveCamera( const int width, const int height) { if( width != 0 && height != 0 ) setRatio(width/(float)height); Vector3 dir(-Vector3::fromAngles(m_theta+M_PI/2.f, m_phi)); // Vector3 eye( - dir * m_zoom); Vector4 eye4 = getEyePos(); Vector3 eye = Vector3( eye4.x, eye4.y, eye4.z ); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(m_fovy, m_ratio, m_near, m_far); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(eye.x, eye.y, eye.z, eye.x + dir.x, eye.y + dir.y, eye.z + dir.z, m_up.x, m_up.y, m_up.z); /* * An alternative way to setup camera */ /*float matrix[16]; this->getProjectionMatrix().getTranspose().fillArray(matrix); glMatrixMode(GL_PROJECTION); glLoadMatrixf(matrix); glMatrixMode(GL_MODELVIEW); this->getModelviewMatrix().getTranspose().fillArray(matrix); glLoadMatrixf(matrix); */ }
void HealthBar::update() { float ratio = static_cast<float>(summoner_->getLife()) / static_cast<float>(settings::maxLife); setRatio(ratio); }
bool REllipseData::moveReferencePoint(const RVector& referencePoint, const RVector& targetPoint) { RVector startPoint = getStartPoint(); RVector endPoint = getEndPoint(); if (!isFullEllipse()) { if (referencePoint.equalsFuzzy(startPoint)) { moveStartPoint(targetPoint, true); return true; } if (referencePoint.equalsFuzzy(endPoint)) { moveEndPoint(targetPoint, true); return true; } } if (referencePoint.equalsFuzzy(center+majorPoint)) { double minorRadius = getMinorRadius(); majorPoint = targetPoint-center; setRatio(minorRadius / getMajorRadius()); return true; } if (referencePoint.equalsFuzzy(center-majorPoint)) { double minorRadius = getMinorRadius(); majorPoint = -(targetPoint-center); setRatio(minorRadius / getMajorRadius()); return true; } if (referencePoint.equalsFuzzy(center+getMinorPoint())) { setMinorPoint(targetPoint-center); return true; } if (referencePoint.equalsFuzzy(center-getMinorPoint())) { setMinorPoint(-(targetPoint-center)); return true; } if (referencePoint.equalsFuzzy(center)) { center = targetPoint; return true; } return false; }
bool GUISeparator::loadXMLSettings(const TiXmlElement *element) { if(!element || !element->Value() || strcmp(element->Value(), "Separator")) return Logger::writeErrorLog("Need a <Separator> tag"); setRatio(XMLArbiter::fillComponents1f(element, "ratio", ratio)); return true; }
bool Camera::setupCamera(VideoContext const& context) { float ratio; if ((ratio = static_cast<float>(context.getScreenWidth()) / static_cast<float>(context.getScreenHeight())) == 0.0f) return false; setRatio(ratio); return true; }
bool BoxLayout::setRatio(const Widget::Ptr& widget, float ratio) { for (unsigned int i = 0; i < m_layoutWidgets.size(); ++i) { if (m_layoutWidgets[i] == widget) return setRatio(i, ratio); } return false; }
void TimeBar::update() { float ratio = 0; if (summoner_->getTime() != 0) { ratio = 1 - static_cast<float>(summoner_->getTime()) / static_cast<float>(settings::turnTime * 1000); } setRatio(ratio); }
void Compressor::setNValue(int idx, double value) { switch (idx) { case RMS_PEAK: setRmsPeak(value); break; case ATTACK: setAttack(value); break; case RELEASE: setRelease(value); break; case THRESHOLD: setThreshold(value); break; case RATIO: setRatio(value); break; case KNEE: setKnee(value); break; case GAIN: setMakeupGain(value); break; } }
bool REllipse::switchMajorMinor() { if (fabs(ratio) < RS::PointTolerance) { return false; } RVector vp_start=getStartPoint(); RVector vp_end=getStartPoint(); RVector vp=getMajorPoint(); setMajorPoint(RVector(-ratio*vp.y, ratio*vp.x)); setRatio(1.0/ratio); setStartParam(getParamTo(vp_start)); setEndParam(getParamTo(vp_end)); return true; }
bool RS_Ellipse::switchMajorMinor(void) //switch naming of major/minor, return true if success { if (fabs(data.ratio) < RS_TOLERANCE) return false; RS_Vector vp_start=getStartpoint(); RS_Vector vp_end=getStartpoint(); RS_Vector vp=getMajorP(); setMajorP(RS_Vector(- data.ratio*vp.y, data.ratio*vp.x)); //direction pi/2 relative to old MajorP; setRatio(1./data.ratio); if( std::isnormal(getAngle1()) || std::isnormal(getAngle2() ) ) { //only reset start/end points for ellipse arcs, i.e., angle1 angle2 are not both zero setAngle1(getEllipseAngle(vp_start)); setAngle2(getEllipseAngle(vp_end)); } return true; }
//------------------------------------------------------------ void input::updateInput(ofxCvGrayscaleImage grayThres){ int w = grayThres.width; int h = grayThres.height; contours.findContours(grayThres, 1000, w*h , 1, false); //only one blob, no holes. if (contours.nBlobs){ blob = contours.blobs[0]; //we always work with the biggest blob. setPos(); setArea(); setFactor(); setRatio(); empty = false; } else { empty = true; } }
AxisButton::AxisButton(ArCW& arCW, ArRef<Texture> texture, bool textUp) : OSDSprite(arCW, texture), // _text(new_OSDText()) { _text(OSDText::NEW()) { setLocation(OSD::LOC_FREE); resizeWithRenderer(false); setRatio(1.0); addSetupCB(thisRef(), &AxisButton::_onSetupCB); setValue(0.0); _text->setDepth(1.0); _text->setLocation(OSD::LOC_FREE); _text->setFont("9x15bold"); _text->setMouseButtonInteraction(false); _text->setMotionInteraction(false); _text->attachTo(thisRef()); _textUp = textUp; }
void Resampler::setFrequency(float frequency, float resampledFrequency) { settings.frequency = frequency; settings.resampledFrequency = resampledFrequency; setRatio(); }
/** * Sets the minor point relative to the center point. */ void REllipse::setMinorPoint(const RVector& p) { double angle = RMath::getNormalizedAngle(p.getAngle() - M_PI/2.0); majorPoint.setPolar(getMajorRadius(), angle); setRatio(p.getMagnitude() / getMajorRadius()); }
GUISeparator::GUISeparator(int orientation_) : GUIRectangle() { setOrientation(orientation); setRatio(1.0f); widgetType = WT_SEPARATOR; }
bool BoxLayout::insertSpace(std::size_t index, float ratio) { bool success = insert(index, std::make_shared<ClickableWidget>(), ""); setRatio(index, ratio); return success; }
void BoxLayout::addSpace(float ratio) { add(std::make_shared<ClickableWidget>(), ""); setRatio(m_layoutWidgets.size()-1, ratio); }
/* cgraph requires */ void graph_init(graph_t * g, boolean use_rankdir) { char *p; double xf; static char *rankname[] = { "local", "global", "none", NULL }; static int rankcode[] = { LOCAL, GLOBAL, NOCLUST, LOCAL }; static char *fontnamenames[] = {"gd","ps","svg", NULL}; static int fontnamecodes[] = {NATIVEFONTS,PSFONTS,SVGFONTS,-1}; int rankdir; GD_drawing(g) = NEW(layout_t); /* set this up fairly early in case any string sizes are needed */ if ((p = agget(g, "fontpath")) || (p = getenv("DOTFONTPATH"))) { /* overide GDFONTPATH in local environment if dot * wants its own */ #ifdef HAVE_SETENV setenv("GDFONTPATH", p, 1); #else static char *buf = 0; buf = grealloc(buf, strlen("GDFONTPATH=") + strlen(p) + 1); strcpy(buf, "GDFONTPATH="); strcat(buf, p); putenv(buf); #endif } GD_charset(g) = findCharset (g); if (!HTTPServerEnVar) { Gvimagepath = agget (g, "imagepath"); if (!Gvimagepath) Gvimagepath = Gvfilepath; } GD_drawing(g)->quantum = late_double(g, agfindgraphattr(g, "quantum"), 0.0, 0.0); /* setting rankdir=LR is only defined in dot, * but having it set causes shape code and others to use it. * The result is confused output, so we turn it off unless requested. * This effective rankdir is stored in the bottom 2 bits of g->u.rankdir. * Sometimes, the code really needs the graph's rankdir, e.g., neato -n * with record shapes, so we store the real rankdir in the next 2 bits. */ rankdir = RANKDIR_TB; if ((p = agget(g, "rankdir"))) { if (streq(p, "LR")) rankdir = RANKDIR_LR; else if (streq(p, "BT")) rankdir = RANKDIR_BT; else if (streq(p, "RL")) rankdir = RANKDIR_RL; } if (use_rankdir) SET_RANKDIR (g, (rankdir << 2) | rankdir); else SET_RANKDIR (g, (rankdir << 2)); xf = late_double(g, agfindgraphattr(g, "nodesep"), DEFAULT_NODESEP, MIN_NODESEP); GD_nodesep(g) = POINTS(xf); p = late_string(g, agfindgraphattr(g, "ranksep"), NULL); if (p) { if (sscanf(p, "%lf", &xf) == 0) xf = DEFAULT_RANKSEP; else { if (xf < MIN_RANKSEP) xf = MIN_RANKSEP; } if (strstr(p, "equally")) GD_exact_ranksep(g) = TRUE; } else xf = DEFAULT_RANKSEP; GD_ranksep(g) = POINTS(xf); GD_showboxes(g) = late_int(g, agfindgraphattr(g, "showboxes"), 0, 0); p = late_string(g, agfindgraphattr(g, "fontnames"), NULL); GD_fontnames(g) = maptoken(p, fontnamenames, fontnamecodes); setRatio(g); GD_drawing(g)->filled = getdoubles2ptf(g, "size", &(GD_drawing(g)->size)); getdoubles2ptf(g, "page", &(GD_drawing(g)->page)); GD_drawing(g)->centered = mapbool(agget(g, "center")); if ((p = agget(g, "rotate"))) GD_drawing(g)->landscape = (atoi(p) == 90); else if ((p = agget(g, "orientation"))) GD_drawing(g)->landscape = ((p[0] == 'l') || (p[0] == 'L')); else if ((p = agget(g, "landscape"))) GD_drawing(g)->landscape = mapbool(p); p = agget(g, "clusterrank"); CL_type = maptoken(p, rankname, rankcode); p = agget(g, "concentrate"); Concentrate = mapbool(p); State = GVBEGIN; EdgeLabelsDone = 0; GD_drawing(g)->dpi = 0.0; if (((p = agget(g, "dpi")) && p[0]) || ((p = agget(g, "resolution")) && p[0])) GD_drawing(g)->dpi = atof(p); do_graph_label(g); Initial_dist = MYHUGE; G_ordering = agfindgraphattr(g, "ordering"); G_gradientangle = agfindgraphattr(g,"gradientangle"); G_margin = agfindgraphattr(g, "margin"); /* initialize nodes */ N_height = agfindnodeattr(g, "height"); N_width = agfindnodeattr(g, "width"); N_shape = agfindnodeattr(g, "shape"); N_color = agfindnodeattr(g, "color"); N_fillcolor = agfindnodeattr(g, "fillcolor"); N_style = agfindnodeattr(g, "style"); N_fontsize = agfindnodeattr(g, "fontsize"); N_fontname = agfindnodeattr(g, "fontname"); N_fontcolor = agfindnodeattr(g, "fontcolor"); N_label = agfindnodeattr(g, "label"); if (!N_label) N_label = agattr(g, AGNODE, "label", NODENAME_ESC); N_xlabel = agfindnodeattr(g, "xlabel"); N_showboxes = agfindnodeattr(g, "showboxes"); N_penwidth = agfindnodeattr(g, "penwidth"); N_ordering = agfindnodeattr(g, "ordering"); N_margin = agfindnodeattr(g, "margin"); /* attribs for polygon shapes */ N_sides = agfindnodeattr(g, "sides"); N_peripheries = agfindnodeattr(g, "peripheries"); N_skew = agfindnodeattr(g, "skew"); N_orientation = agfindnodeattr(g, "orientation"); N_distortion = agfindnodeattr(g, "distortion"); N_fixed = agfindnodeattr(g, "fixedsize"); N_imagescale = agfindnodeattr(g, "imagescale"); N_nojustify = agfindnodeattr(g, "nojustify"); N_layer = agfindnodeattr(g, "layer"); N_group = agfindnodeattr(g, "group"); N_comment = agfindnodeattr(g, "comment"); N_vertices = agfindnodeattr(g, "vertices"); N_z = agfindnodeattr(g, "z"); N_gradientangle = agfindnodeattr(g,"gradientangle"); /* initialize edges */ E_weight = agfindedgeattr(g, "weight"); E_color = agfindedgeattr(g, "color"); E_fillcolor = agfindedgeattr(g, "fillcolor"); E_fontsize = agfindedgeattr(g, "fontsize"); E_fontname = agfindedgeattr(g, "fontname"); E_fontcolor = agfindedgeattr(g, "fontcolor"); E_label = agfindedgeattr(g, "label"); E_xlabel = agfindedgeattr(g, "xlabel"); E_label_float = agfindedgeattr(g, "labelfloat"); /* vladimir */ E_dir = agfindedgeattr(g, "dir"); E_arrowhead = agfindedgeattr(g, "arrowhead"); E_arrowtail = agfindedgeattr(g, "arrowtail"); E_headlabel = agfindedgeattr(g, "headlabel"); E_taillabel = agfindedgeattr(g, "taillabel"); E_labelfontsize = agfindedgeattr(g, "labelfontsize"); E_labelfontname = agfindedgeattr(g, "labelfontname"); E_labelfontcolor = agfindedgeattr(g, "labelfontcolor"); E_labeldistance = agfindedgeattr(g, "labeldistance"); E_labelangle = agfindedgeattr(g, "labelangle"); /* end vladimir */ E_minlen = agfindedgeattr(g, "minlen"); E_showboxes = agfindedgeattr(g, "showboxes"); E_style = agfindedgeattr(g, "style"); E_decorate = agfindedgeattr(g, "decorate"); E_arrowsz = agfindedgeattr(g, "arrowsize"); E_constr = agfindedgeattr(g, "constraint"); E_layer = agfindedgeattr(g, "layer"); E_comment = agfindedgeattr(g, "comment"); E_tailclip = agfindedgeattr(g, "tailclip"); E_headclip = agfindedgeattr(g, "headclip"); E_penwidth = agfindedgeattr(g, "penwidth"); /* background */ GD_drawing(g)->xdots = init_xdot (g); /* initialize id, if any */ if ((p = agget(g, "id")) && *p) GD_drawing(g)->id = strdup_and_subst_obj(p, g); }
void Camera::resizeGL(int w, int h) { qreal aspect = qreal(w) / qreal(h ? h : 1); setRatio(aspect); }