#ifndef TXS_ALGO_GUARD #define TXS_ALGO_GUARD #include "TxsMesh.h" using namespace TXS; // the various algos void synthTexturesNaive(TxsMesh &mesh, TiffImage &img); void synthTexturesSingleRes(TxsMesh &mesh, TiffImage &img); void performMultiResRelaxTextureSynth(TxsMesh &mesh, TxsPyramid &inPy); int rand_range(int a, int b); NormRGB randomRgbFrom(TiffImage &img); double random_pos_unit(); NormRGB randomRgb(); template void knuth_shuffle(vector &items); Point pointForUV(const Point &uvo, const Vector &uvUp, const Vector &uvRight, const UVs &uv); bool getHitRgb(list &faces, const Point &s, const Vector &d, int level, NormRGB &rgbOut); int getFinestLevel(TxsMesh &mesh); void setToClosestUsing2LevPyramid(pixelLocn &p, TxsPyramid &inPy); void fillPixelsWithRandomImageRGBs(vector &pixLocs, TiffImage &img); int accumPixelLocsForAllLevels(vector*> &pixLocLevels, TxsMesh &mesh); void getProgressStats(int done, int total, double startClk, double &remainingSecs, double &elapsedSecs, double &percentageDone); void statProgress(int done, int total, double startClk); extern int g_numNhoodRaysMissed; extern int SR_NHOOD_PIXELS; struct NhoodPatch_s { Point center; Vector up; Vector right; Vector normal; UVs botLeftUV; TXS_REAL unitsPerSquare; TXS_REAL halfUPS; /* * Returns the world coordinates of * the (gx,gy) grid square's center * (0,0) corresponds to the bottom left square. */ Point getSquareCenter(int gx, int gy) { // calculate the UV for this grid pt UVs guv(botLeftUV.u + gx * unitsPerSquare, botLeftUV.v + gy * unitsPerSquare); // now, calculate the point Point gridPt = pointForUV(this->center, this->up, this->right, guv); return gridPt; } Point getSquareCorner(int gx, int gy, int cx, int cy) { if(cx == 0) cx = -1; if(cy == 0) cy = -1; // calculate the UV for this grid pt UVs guv(botLeftUV.u + gx * unitsPerSquare + cx*halfUPS, botLeftUV.v + gy * unitsPerSquare + cy*halfUPS); // now, calculate the point Point gridPt = pointForUV(this->center, this->up, this->right, guv); return gridPt; } void setTo(pixelLocn &p, TXS_REAL unitsPerSquare, int squaresPerEdge) { TxsFace* face = p.face; // center on the pixel location this->center = p.pos; // figure out the phong-shaded normal // flip it for the grid. though that shouldn't really matter this->normal = -1.0 * face->calcPhongNormalAt(p.pos); // figure out nhood grid axis vectors // this is where we determine orientation // for now, we do random Vector orienter(random_unit(), random_unit(), random_unit()); this->up = this->normal * orienter; this->up.Normalize(); this->right = this->up * this->normal; this->right.Normalize(); /* * now figure out the bot left from the size */ this->unitsPerSquare = unitsPerSquare; halfUPS = unitsPerSquare * 0.5; const TXS_REAL UPS = unitsPerSquare; const TXS_REAL unitsPerEdge = squaresPerEdge * UPS; const TXS_REAL unitsPerHalfEdge = unitsPerEdge * 0.5; // the bottom left UV pt should be negative // cuz, or uv origin, p, should be the center of the grid // and, we add halfUPP since UVs should be on the center of the grid square // // make sure both u/v are the same expression: - unitsPerHalfEdge + halfUPP botLeftUV.u = -unitsPerHalfEdge + halfUPS; botLeftUV.v = -unitsPerHalfEdge + halfUPS; } }; NormRGB averageColors(list &clrs); void fillNhoodImage(TiffImage &img, NhoodPatch_s nhood, int level, list &faces); void fillNhoodImageSuperSampled(TiffImage &img, NhoodPatch_s nhood, int level, list &faces); #endif /* TXS_ALGO_GUARD */