ConvexHull(const Polygon &scatteredPoints) { const int numPoints = scatteredPoints.size(); Polygon copy(scatteredPoints); // Sort input by x (lex): std::sort(©[0], ©[numPoints]); // Find left and rightmost points: Point leftMost = copy[0]; Point rightMost = copy[numPoints-1]; //Split points in upper and lower: Polygon upperPoints; Polygon lowerPoints; for(int i = 1; i < numPoints-1; ++i) { Point p = copy[i]; if(colinear(leftMost, rightMost, p)) { continue; } if(leftTurn(leftMost, rightMost, p)) { upperPoints.push_back(p); } else { lowerPoints.push_back(flipY(p)); } } upperPoints = upperHull(leftMost, rightMost, upperPoints); lowerPoints = upperHull(flipY(leftMost), flipY(rightMost), lowerPoints); //Make points of hull: int actualNumPoints = size = upperPoints.size() + lowerPoints.size(); points = new Point[actualNumPoints]; int i = 0; for(Polygon::const_iterator it = upperPoints.begin(); it != upperPoints.end(); ++it) { points[i++] = *it; } points[i] = rightMost; i = actualNumPoints; for(Polygon::const_iterator it = lowerPoints.begin(); it != lowerPoints.end(); ++it) { i--; if(i != actualNumPoints-1) points[i+1] = flipY(*it); } std::cout << actualNumPoints; for(i = 0; i < actualNumPoints; ++i) std::cout << " " << points[i].first << " " << points[i].second; std::cout << std::endl; }
void Sphere::move() { coord += step; gravity(); if(collisionX()) flipX(); if(collisionY()) flipY(); }
float2 DrawBar(const ShaderState &s1, uint fill, uint line, float alpha, float2 p, float2 s, float a) { ShaderState ss = s1; a = clamp(a, 0.f, 1.f); ss.color(fill, alpha); const float2 wp = p + float2(1.f, -1.f); const float2 ws = s - float2(2.f); ShaderUColor::instance().DrawQuad(ss, wp, wp + a * justX(ws), wp - justY(ws), wp + float2(a*ws.x, -ws.y)); ss.color(line, alpha); ShaderUColor::instance().DrawLineQuad(ss, p, p + justX(s), p - justY(s), p + flipY(s)); return s; }
inline void storeFramebuffer(int resultIndex, const FilePath& pngDir, const FilePath& exrDir, const FilePath& baseName, float gamma, const Framebuffer& framebuffer) { // Create output directories in case they don't exist createDirectory(pngDir.str()); createDirectory(exrDir.str()); // Path of primary output image files FilePath pngFile = pngDir + baseName.addExt(".png"); FilePath exrFile = exrDir + baseName.addExt(".exr"); // Make a copy of the image Image copy = framebuffer.getChannel(0); // Store the EXR image "as is" storeEXRImage(exrFile.str(), copy); // Post-process copy of image and store PNG file copy.flipY(); copy.divideByAlpha(); copy.applyGamma(gamma); storeImage(pngFile.str(), copy); // Store complete framebuffer as a single EXR multi layer image auto exrFramebufferFilePath = exrDir + baseName.addExt(".bnzframebuffer.exr"); storeEXRFramebuffer(exrFramebufferFilePath.str(), framebuffer); // Store complete framebuffer as PNG indivual files in a dediacted subdirectory auto pngFramebufferDirPath = pngDir + "framebuffers/"; createDirectory(pngFramebufferDirPath.str()); if(resultIndex >= 0) { pngFramebufferDirPath = pngFramebufferDirPath + toString3(resultIndex); // Split different results of the same batch in different subdirectories } createDirectory(pngFramebufferDirPath.str()); // Store each channel of the framebuffer for(auto i = 0u; i < framebuffer.getChannelCount(); ++i) { auto name = framebuffer.getChannelName(i); // Prefix by the index of the channel FilePath pngFile = pngFramebufferDirPath + FilePath(toString3(i)).addExt("_" + name + ".png"); auto copy = framebuffer.getChannel(i); copy.flipY(); copy.divideByAlpha(); copy.applyGamma(gamma); storeImage(pngFile.str(), copy); } }
bool RGBAImage::loadPNG(const string &fileName, bool doFlipY) { string fullName; getFullFileName(fileName, fullName); unsigned error = lodepng::decode(pixels, width, height, fullName.c_str()); if (error) { ERROR_MSG(lodepng_error_text(error), false); return false; } if (doFlipY) flipY(); // PNGs go top-to-bottom, OpenGL is bottom-to-top name = fileName; return true; }
void AutomationPatternView::constructContextMenu( QMenu * _cm ) { QAction * a = new QAction( embed::getIconPixmap( "automation" ), tr( "Open in Automation editor" ), _cm ); _cm->insertAction( _cm->actions()[0], a ); connect(a, SIGNAL(triggered()), this, SLOT(openInAutomationEditor())); _cm->insertSeparator( _cm->actions()[1] ); _cm->addSeparator(); _cm->addAction( embed::getIconPixmap( "edit_erase" ), tr( "Clear" ), m_pat, SLOT( clear() ) ); _cm->addSeparator(); _cm->addAction( embed::getIconPixmap( "reload" ), tr( "Reset name" ), this, SLOT( resetName() ) ); _cm->addAction( embed::getIconPixmap( "edit_rename" ), tr( "Change name" ), this, SLOT( changeName() ) ); _cm->addAction( embed::getIconPixmap( "record" ), tr( "Set/clear record" ), this, SLOT( toggleRecording() ) ); _cm->addAction( embed::getIconPixmap( "flip_y" ), tr( "Flip Vertically (Visible)" ), this, SLOT( flipY() ) ); _cm->addAction( embed::getIconPixmap( "flip_x" ), tr( "Flip Horizontally (Visible)" ), this, SLOT( flipX() ) ); if( !m_pat->m_objects.isEmpty() ) { _cm->addSeparator(); QMenu * m = new QMenu( tr( "%1 Connections" ). arg( m_pat->m_objects.count() ), _cm ); for( AutomationPattern::objectVector::iterator it = m_pat->m_objects.begin(); it != m_pat->m_objects.end(); ++it ) { if( *it ) { a = new QAction( tr( "Disconnect \"%1\"" ). arg( ( *it )->fullDisplayName() ), m ); a->setData( ( *it )->id() ); m->addAction( a ); } } connect( m, SIGNAL( triggered( QAction * ) ), this, SLOT( disconnectObject( QAction * ) ) ); _cm->addMenu( m ); }
bool raw_img::loadFromFile(const std::string& filename) { if(data){ eraseInternalData(); } int x,y,n; // int x=-1,y=-1,n=-1; unsigned char *newdata = stbi_load(filename.c_str(), &x, &y, &n, 0); if(!newdata){ std::string err(stbi_failure_reason()); omg_warn(err); return false; } data = newdata; pixelSize = {x,y}; channels = n; flipY(); return data!=nullptr; }
void WriteDepthFile(const char *filename, double *imgDepth, int gWidth , int gHeight) { FILE *f; f = fopen(filename, "w"); if (!f) { printf("Couldn't open image file: %s\n", filename); return; } int MAX = 255; fprintf(f, "P5\n"); fprintf(f, "# pgm-file created by %s\n", "renderer"); fprintf(f, "%i %i\n", gWidth, gHeight); fprintf(f, "255\n"); fclose(f); f = fopen(filename, "ab"); /* now append binary data */ if (!f) { printf("Couldn't append to image file: %s\n", filename); return; } GLubyte *newd = (GLubyte *) malloc(gWidth * gHeight * sizeof(GLubyte)); for (int i = 0;i < gHeight*gWidth;i++) { imgDepth[i] *= MAX; } flipY(imgDepth, gWidth, gHeight, newd); printDebugWriteDepthFile(gWidth, gHeight, newd, MAX); fwrite(newd, sizeof(GLubyte), gWidth*gHeight, f); fclose(f); if (DEBUG) { sout << "Wrote " << gWidth << " by " << gHeight << " image file: " << filename << endl; } free(newd); }
void AutomationPattern::flipY() { flipY(getMin(), getMax()); }
DWORD LandScape::execV( LS_OPCODE _opcode, va_list _va ) { // reset the return status - individual functions will alter this if need be mExecStatus = EXEC_SUCCESS; mExecString[0] = '\0'; switch( _opcode ) { case LS_SEED: setSeed( va_arg(_va,DWORD) ); break; case LS_LOAD: return load( va_arg(_va,char*) ); case LS_LOADM: { char * tmpCh = va_arg(_va,char*); double tmpD = va_arg(_va,double); return load(tmpCh, float(tmpD)); } case LS_SAVE: return save( va_arg(_va,char*) ); case LS_CLEAR: clear(); break; case LS_PUSH: push( va_arg(_va,int)); break; case LS_POP: pop(); break; case LS_GET: return (DWORD)get( va_arg(_va,int) ); case LS_SWAP: swap(); break; case LS_DUP: dup(); break; case LS_ADD: add( float(va_arg(_va,double)) ); break; case LS_SUB: sub( float(va_arg(_va,double)) ); break; case LS_MUL: mul( float(va_arg(_va,double)) ); break; case LS_DIV: div( float(va_arg(_va,double)) ); break; case LS_EXP: exp( float(va_arg(_va,double)) ); break; case LS_NEG: neg(); break; case LS_CLR: clr( float(va_arg(_va,double)) ); break; case LS_DIFF: diff(); break; case LS_NORMALIZE: { double i = va_arg(_va,double); double j = va_arg(_va,double); normalize( float(i), float(j) ); } break; case LS_ADDS: addStack(); break; case LS_SUBS: subStack(); break; case LS_FLOOR: { double i = va_arg(_va,double); double j = va_arg(_va,double); double k = va_arg(_va,double); floor( float(i), float(j), float(k) ); } break; case LS_CEIL: { double i = va_arg(_va,double); double j = va_arg(_va,double); double k = va_arg(_va,double); ceil( i, j, k ); } break; case LS_CLIPMIN: clipMin( float(va_arg(_va,double)) ); break; case LS_CLIPMAX: clipMax( float(va_arg(_va,double)) ); break; case LS_ROT: rot(); break; case LS_FLIPX: flipX(); break; case LS_FLIPY: flipY(); break; case LS_TERRAIN: { int i = va_arg(_va,int); double j = va_arg(_va,double); if (i > 256) { terrain( 256, float(j) ); size(i); } else terrain( i, float(j) ); } break; case LS_PLASMA: { int i = va_arg(_va,int); double j = va_arg(_va,double); if (i > 256) { plasma( 256, float(j) ); size(i); } else plasma( i, float(j) ); } break; case LS_SIZE: size( va_arg(_va,int) ); break; case LS_SLOPE: { double i = va_arg(_va,double); int j = va_arg(_va,int); slope( i, float(j) ); } break; case LS_SHAVE: { double i = va_arg(_va,double); double j = va_arg(_va,double); double k = va_arg(_va,double); shaveArea( float(i), float(j), float(k) ); } break; case LS_CURVE: { double i = va_arg(_va,double); int j = va_arg(_va,int); curve( float(i), j ); } break; case LS_FFT: if (stack.size() > 1) fft( va_arg(_va,int) ); break; case LS_FILL_N: if (stack.size() > 1) fillNormal( float(va_arg(_va,double)) ); break; case LS_OVERLAY: { int i = va_arg(_va,int); double j = va_arg(_va,double); overlay( i, float(j) ); } break; case LS_ALPHABLEND: { int x = va_arg(_va, int); int y = va_arg(_va, int); alphablend(x, y); } break; case LS_BLEND: { int i = va_arg(_va,int); int j = va_arg(_va,int); blend( i, j ); } case LS_SMOOTH: { double i = va_arg(_va,double); double j = va_arg(_va,double); smooth( float(i), float(j) ); } break; case LS_TILE: tile(); break; case LS_WRAP: wrap(); break; case LS_CLAMP: { int i = va_arg(_va,int); double j = va_arg(_va,double); clamp(i, float(j)); } break; case LS_MASK: { int i = va_arg(_va,int); double j = va_arg(_va,double); mask(i, float(j)); } break; case LS_CRATER: case LS_PEAK: case LS_RING: case LS_FILLBASIN: case LS_LPFILTER: case LS_HPFILTER: case LS_BPFILTER: case LS_BRFILTER: case LS_FFLP: case LS_FFHP: case LS_FFBP: case LS_FFBR: default: break; } return NULL; }