void update(QOpenGLShaderProgram *prog, const HighQualityTextureItem::ShaderData *data) { auto d = static_cast<const HighQualityTextureData*>(data); auto f = HighQualityTextureItem::func(); int textureIndex = 0; auto bind = [&] (const OpenGLTextureBase *tex, int loc) { tex->bind(prog, loc, textureIndex++); }; const float w = d->texture->width(), h = d->texture->height(); QVector2D dxy(1.0, 1.0), overlay_factor(1.0, 1.0); if (!m_rectangle) dxy = { 1.0f/w, 1.0f/h }; else overlay_factor = { 1.0f/w, 1.0f/h }; prog->setUniformValue(loc_dxy, dxy); prog->setUniformValue(loc_tex_size, QVector2D(w, h)); prog->setUniformValue(loc_overlay_factor, overlay_factor); bind(d->texture, loc_tex); bind(d->overlay, loc_overlay); for (int i=0; i<m_lutIntCount; ++i) bind(d->lutInt[i], loc_lut_int[i]); if (m_dithering) { auto &dithering = *d->lutDither; Q_ASSERT(dithering.width() == dithering.height()); const int size = dithering.width(); const auto q = static_cast<float>(1 << d->depth) - 1.f; prog->setUniformValue(loc_dith_quant, q); prog->setUniformValue(loc_dith_center, 0.5f / size * size); prog->setUniformValue(loc_dith_size, QSize(size, size)); bind(d->lutDither, loc_dithering); } f->glActiveTexture(GL_TEXTURE0); }
returnValue Power::AD_symmetric( int dim , /**< number of directions */ VariableType *varType , /**< the variable types */ int *component , /**< and their components */ Operator *l , /**< the backward seed */ Operator **S , /**< forward seed matrix */ int dimS , /**< dimension of forward seed */ Operator **dfS , /**< first order foward result */ Operator **ldf , /**< first order backward result */ Operator **H , /**< upper trianglular part of the Hessian */ int &nNewLIS , /**< the number of newLIS */ TreeProjection ***newLIS , /**< the new LIS-pointer */ int &nNewSIS , /**< the number of newSIS */ TreeProjection ***newSIS , /**< the new SIS-pointer */ int &nNewHIS , /**< the number of newHIS */ TreeProjection ***newHIS /**< the new HIS-pointer */ ){ TreeProjection dyy, dy; TreeProjection dx( *derivative12 ); dy = Product( clone(), derivative02->clone()); TreeProjection dxx( *derivative22 ); TreeProjection dxy( *derivative23 ); dyy = Product( dy.clone(), derivative02->clone() ); return ADsymCommon2( argument1,argument2,dx,dy,dxx,dxy,dyy, dim, varType, component, l, S, dimS, dfS, ldf, H, nNewLIS, newLIS, nNewSIS, newSIS, nNewHIS, newHIS ); }
void NPC::postMove() { Entity::postMove(); // Normal exit. if (destTile) { Exit* exit = destTile->exits[EXIT_NORMAL]; if (exit) takeExit(exit); } // Side exit. ivec2 dxy(deltaCoord.x, deltaCoord.y); Exit* exit = fromTile->exitAt(dxy); if (exit) takeExit(exit); }
void computeCorners(CTensor<float>& aImage, CMatrix<float>& aCorners, float aRho) { aCorners.setSize(aImage.xSize(),aImage.ySize()); int aXSize = aImage.xSize(); int aYSize = aImage.ySize(); int aSize = aXSize*aYSize; // Compute gradient CTensor<float> dx(aXSize,aYSize,aImage.zSize()); CTensor<float> dy(aXSize,aYSize,aImage.zSize()); CDerivative<float> aDerivative(3); NFilter::filter(aImage,dx,aDerivative,1,1); NFilter::filter(aImage,dy,1,aDerivative,1); // Compute second moment matrix CMatrix<float> dxx(aXSize,aYSize,0); CMatrix<float> dyy(aXSize,aYSize,0); CMatrix<float> dxy(aXSize,aYSize,0); int i2 = 0; for (int k = 0; k < aImage.zSize(); k++) for (int i = 0; i < aSize; i++,i2++) { dxx.data()[i] += dx.data()[i2]*dx.data()[i2]; dyy.data()[i] += dy.data()[i2]*dy.data()[i2]; dxy.data()[i] += dx.data()[i2]*dy.data()[i2]; } // Smooth second moment matrix NFilter::recursiveSmoothX(dxx,aRho); NFilter::recursiveSmoothY(dxx,aRho); NFilter::recursiveSmoothX(dyy,aRho); NFilter::recursiveSmoothY(dyy,aRho); NFilter::recursiveSmoothX(dxy,aRho); NFilter::recursiveSmoothY(dxy,aRho); // Compute smallest eigenvalue for (int i = 0; i < aSize; i++) { float a = dxx.data()[i]; float b = dxy.data()[i]; float c = dyy.data()[i]; float temp = 0.5*(a+c); float temp2 = temp*temp+b*b-a*c; if (temp2 < 0.0f) aCorners.data()[i] = 0.0f; else aCorners.data()[i] = temp-sqrt(temp2); } }
/** * \brief Updates this entity. */ void Arrow::update() { MapEntity::update(); if (is_suspended()) { return; } uint32_t now = System::now(); // stop the movement if necessary (i.e. stop() was called) if (stop_now) { clear_movement(); stop_now = false; if (entity_reached != NULL) { // the arrow just hit an entity (typically an enemy) and this entity may have a movement Rectangle dxy(get_x() - entity_reached->get_x(), get_y() - entity_reached->get_y()); set_movement(new FollowMovement(entity_reached, dxy.get_x(), dxy.get_y(), true)); } } if (entity_reached != NULL) { // see if the entity reached is still valid if (is_stopped()) { // the arrow is stopped because the entity that was reached just disappeared disappear_date = now; } else if (entity_reached->get_type() == ENTITY_DESTRUCTIBLE && !entity_reached->is_obstacle_for(*this)) { disappear_date = now; } else if (entity_reached->get_type() == ENTITY_ENEMY && ((Enemy*) entity_reached)->is_dying()) { // the enemy is dying disappear_date = now; } } // see if the arrow just hit a wall or an entity bool reached_obstacle = false; if (get_sprite().get_current_animation() != "reached_obstacle") { if (entity_reached != NULL) { // the arrow was just attached to an entity reached_obstacle = true; } else if (is_stopped()) { if (has_reached_map_border()) { // the map border was reached: destroy the arrow disappear_date = now; } else { // the arrow has just hit another obstacle reached_obstacle = true; } } } if (reached_obstacle) { // an obstacle or an entity was just reached disappear_date = now + 1500; get_sprite().set_current_animation("reached_obstacle"); Sound::play("arrow_hit"); if (entity_reached == NULL) { clear_movement(); } check_collision_with_detectors(false); } // destroy the arrow when disappear_date is reached if (now >= disappear_date) { remove_from_map(); } }
//---------------------------------------------------------------------------- int ExtractRidges::Main (int, char**) { std::string imageName = Environment::GetPathR("Head.im"); ImageDouble2D image(imageName.c_str()); // Normalize the image values to be in [0,1]. int quantity = image.GetQuantity(); double minValue = image[0], maxValue = minValue; int i; for (i = 1; i < quantity; ++i) { if (image[i] < minValue) { minValue = image[i]; } else if (image[i] > maxValue) { maxValue = image[i]; } } double invRange = 1.0/(maxValue - minValue); for (i = 0; i < quantity; ++i) { image[i] = (image[i] - minValue)*invRange; } // Use first-order centered finite differences to estimate the image // derivatives. The gradient is DF = (df/dx, df/dy) and the Hessian // is D^2F = {{d^2f/dx^2, d^2f/dxdy}, {d^2f/dydx, d^2f/dy^2}}. int xBound = image.GetBound(0); int yBound = image.GetBound(1); int xBoundM1 = xBound - 1; int yBoundM1 = yBound - 1; ImageDouble2D dx(xBound, yBound); ImageDouble2D dy(xBound, yBound); ImageDouble2D dxx(xBound, yBound); ImageDouble2D dxy(xBound, yBound); ImageDouble2D dyy(xBound, yBound); int x, y; for (y = 1; y < yBoundM1; ++y) { for (x = 1; x < xBoundM1; ++x) { dx(x, y) = 0.5*(image(x+1, y) - image(x-1, y)); dy(x, y) = 0.5*(image(x, y+1) - image(x, y-1)); dxx(x, y) = image(x+1, y) - 2.0*image(x, y) + image(x-1, y); dxy(x, y) = 0.25*(image(x+1, y+1) + image(x-1, y-1) - image(x+1, y-1) - image(x-1, y+1)); dyy(x, y) = image(x, y+1) - 2.0*image(x, y) + image(x, y+1); } } dx.Save("dx.im"); dy.Save("dy.im"); dxx.Save("dxx.im"); dxy.Save("dxy.im"); dyy.Save("dyy.im"); // The eigensolver produces eigenvalues a and b and corresponding // eigenvectors U and V: D^2F*U = a*U, D^2F*V = b*V. Define // P = Dot(U,DF) and Q = Dot(V,DF). The classification is as follows. // ridge: P = 0 with a < 0 // valley: Q = 0 with b > 0 ImageDouble2D aImage(xBound, yBound); ImageDouble2D bImage(xBound, yBound); ImageDouble2D pImage(xBound, yBound); ImageDouble2D qImage(xBound, yBound); for (y = 1; y < yBoundM1; ++y) { for (x = 1; x < xBoundM1; ++x) { Vector2d gradient(dx(x, y), dy(x, y)); Matrix2d hessian(dxx(x, y), dxy(x, y), dxy(x, y), dyy(x, y)); EigenDecompositiond decomposer(hessian); decomposer.Solve(true); aImage(x,y) = decomposer.GetEigenvalue(0); bImage(x,y) = decomposer.GetEigenvalue(1); Vector2d u = decomposer.GetEigenvector2(0); Vector2d v = decomposer.GetEigenvector2(1); pImage(x,y) = u.Dot(gradient); qImage(x,y) = v.Dot(gradient); } } aImage.Save("a.im"); bImage.Save("b.im"); pImage.Save("p.im"); qImage.Save("q.im"); // Use a cheap classification of the pixels by testing for sign changes // between neighboring pixels. ImageRGB82D result(xBound, yBound); for (y = 1; y < yBoundM1; ++y) { for (x = 1; x < xBoundM1; ++x) { unsigned char gray = (unsigned char)(255.0f*image(x, y)); double pValue = pImage(x, y); bool isRidge = false; if (pValue*pImage(x-1 ,y) < 0.0 || pValue*pImage(x+1, y) < 0.0 || pValue*pImage(x, y-1) < 0.0 || pValue*pImage(x, y+1) < 0.0) { if (aImage(x, y) < 0.0) { isRidge = true; } } double qValue = qImage(x,y); bool isValley = false; if (qValue*qImage(x-1, y) < 0.0 || qValue*qImage(x+1, y) < 0.0 || qValue*qImage(x, y-1) < 0.0 || qValue*qImage(x, y+1) < 0.0) { if (bImage(x,y) > 0.0) { isValley = true; } } if (isRidge) { if (isValley) { result(x, y) = GetColor24(gray, 0, gray); } else { result(x, y) = GetColor24(gray, 0, 0); } } else if (isValley) { result(x, y) = GetColor24(0, 0, gray); } else { result(x, y) = GetColor24(gray, gray, gray); } } } result.Save("result.im"); return 0; }
/*********************************************************************** ** PostScript mainline processor. ** ***********************************************************************/ static void psmain(void) { int color_done; /* done doing colors */ int i; ini_JOB(); /* init job stuff */ ini_PAGE(); /* init %%Page: comment state */ Fofd = 0; GraphicsPresentFlag = 0; NoFont = 0; width_open(); /* Open WIDTH for H&Js char-width round-off errors*/ FontBase = 1000; #ifdef TRACE if(debugger_trace) p_info(PI_TRACE, "Starting job:%s\n",JobName); #endif cc_hit = 0; cc_mask = (1 & Plates); /* hit nothing, set all black */ if ( !cc_mask) m_fopen(tpname, "w+", 1); /* delete prev version of .tp */ spot_pass = 1; /* 1st pass */ color_done = 0; /* not done yet */ PageRotationAngle = 0; frame_fg_attribute = 0; /* default is opaque */ prologue_output_flag = 0; PageNo1 = 1; underscore_min = 10; overflow_page_buff_count = 0; memset ( (char *)overflow_page_buff, 0, sizeof (overflow_page_buff) ); ExitError = 0; HNJ_LockFailureFlag = 0; while(color_done != 1 ) /* until we get all colors */ { FootnoteFrameFlag = 0; BlackPaint_cc_mask = cc_mask; PaintOnPage = 0; blend_flag = 0; BlendAngle = 0; BlendEndColor = 0; in_overflow = 0; was_overflow = 0; Linesub = -1; /* clear text/escapement buffer */ flagGlyph = 0; *GlyphName = 0; for(i=0; i<1999; i++) { Line[i] = 0; Kspace[i] = 0; } for(i=0; i<40; i++) bf_kmd80[i].active_flag = 0; fowrd = 256; Xmark = 0; y_max = 0; Oldfont = -1; Holdfont = 0; usw = 0; StrikeThruRuleStartFlag = 0; FlashOn = 1; CurrentFrame = 0; CurrentEle = 0; memset( (char *)&fo_line_def.FoStatusLength, 0, sizeof(LDEF) ); DontPaintFlag = fo_line_def.MiscLineFlags & 0x10; not_lnum = 1; /* Default: Put text font, not line-num font*/ last_lnum = 0; jbl = 0; repeatno = 0; Obdegree = 0; Old_ob = 0; Hold_ob = 0; Holdss = 0; Holdps = 0; Oldss = 0; Oldps = 0; Ktabmode = 0; psend = 0; WidthOfNumeric = 0; memset ( page_number, 0, sizeof(page_number) ); CurrentLineBcEc = 0; PrevLineBcEc = 0; BcEcExtraLeadNeeded = 0; BcEcExtraLead = 0; LastLinemaxErr = 0; cc_hit &= (Plates & ~1); /* only use plates to be output */ #ifdef TRACE if(debugger_trace) { p_info(PI_TRACE, "spot color pass %d, cc_mask: %lo , cc_hit: %lo\n", spot_pass, cc_mask, cc_hit); p_info(PI_TRACE, "processing Tree: '%s', Dir: '%s',file: '%s', type= %d\n", TreeName, SubDirName, JobName, FileType); } #endif switch(FileType) { case 0: /* Galley output */ if (spot_pass != 2) cc_hit = 0; if((err = dtext()) ) error("processing FO file, err = ",JobName,err); if( (cc_hit < 2) || /* picked up no color(s) */ (spot_pass != 1) || /* or on second pass thru file */ ( !KeyOutputType) ) /* or composite */ color_done = 1; /* we are done */ else { spot_pass = 2; /* mark as 2nd pass thru file */ cc_hit &= (Plates & ~1); /* mask off black */ cc_mask = 0; /* not the black we start with */ galley_count = 0; MasterOutputSwitch = 1; if(Fofd) /* if still open */ foread(1); /* rewind open FO file */ } break; case 1: /* DesignMaster */ if((err = dxy()) ) p_info(PI_ELOG, "ERROR --processing Tree: '%s', Dir: '%s', Unit: %s\n", TreeName,SubDirName,JobName); color_done = 1; /* color loop inside dxy */ break; } /* end switch(FileType) */ m_close(-1); /* close all output */ } /* end while(color_done!=1) */ if (wdfd) { p_close (wdfd); wdfd = 0; } if (Fofd) { p_close(Fofd); Fofd = 0; FoName[0] = 0; } if (TrailerName) { fclose(TrailerName); TrailerName = NULL; } if (PrologName) { fclose(PrologName); PrologName = NULL; if (EpsFlag) strcpy (logname, p_path(TreeName, EPS_FILE, SubDirName, tpname)); else if (BookPrint) strcpy (logname, p_path(TreeName, OUTPUT_FILE, ParentDirName, tpname)); else strcpy (logname, p_path(TreeName, OUTPUT_FILE, SubDirName, tpname)); sprintf(shell_msg,"cat %s >> %s \n mv %s %s \n cat %s >> %s \n mv %s %s", prologname, trailername, trailername, prologname, logname, prologname, prologname, logname); system(shell_msg); } #ifdef TRACE if(debugger_trace) p_info(PI_TRACE, "Finished job, Tree: '%s', Dir: '%s', Name: '%s'.\n", TreeName,SubDirName,JobName); #endif }