int main(int argc, char** argv) { img.load("img/4.pgm"); //img.filterSobel(); initLines(&linesq); showLines(&linesq); calcRectangles(&linesq, &recsq); calcTriangles(&linesq, &triangles); showRectangles(&recsq); showTriangles(&triangles); glutInit( &argc, argv ); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB); glutInitWindowSize(1000, 700); glutInitWindowPosition(100, 100); glutCreateWindow( "Cam" ); glutDisplayFunc(display); //glutMouseFunc(mouseButton); glutKeyboardFunc(keyboard); //glutReshapeFunc(resize); initialize(); //init OpenGL state glutMainLoop(); return 0; }
GL_LineAO::GL_LineAO( std::shared_ptr< const LineSet > sLines ) : streamlines( sLines ) { GLint value[4]; glGetIntegerv( GL_VIEWPORT, value ); int width = value[2]; int height = value[3]; m_width = width; m_height = height; srand( time( NULL ) ); // create shaders m_lineShader = std::unique_ptr< Shader >( new Shader( "/u/mai11dre/VisPrak/fantom/praktikum/shader/Line-vertex.glsl", "/u/mai11dre/VisPrak/fantom/praktikum/shader/Line-fragment.glsl") ); m_textureShader = std::unique_ptr< Shader >( new Shader ( "/u/mai11dre/VisPrak/fantom/praktikum/shader/Lightning-vertex.glsl", "/u/mai11dre/VisPrak/fantom/praktikum/shader/Lightning-fragment.glsl") ); initLines(); initQuad(); initGBuffer(); genNoiseTexture(); }
WaterParticle::WaterParticle(int amountOfParticles, float volume, float density, float timeStep, Cellist *c) { //mass = (density * total volume) / (total number of particles) //conservation of mass => we can store mass in class and not in each particle //particleMass = (density * volume) / amountOfParticles; particleMass = 0.02f; //particleMass = 3.25e-14f; this->cellList = c; current_time = 0.0; time_step = timeStep; initLines(); }
void TidyLines::quicktidy(std::map<int,Line>& lines, const QtRegion& region) { m_region = region; double avglen = 0.0; for (auto line: lines) { avglen += line.second.length(); } avglen /= lines.size(); double tolerance = avglen * 10e-6; auto iter = lines.begin(), end = lines.end(); for(; iter != end; ) { if (iter->second.length() < tolerance) { iter = lines.erase(iter); } else { ++iter; } } // now load up m_lines... initLines(lines.size(),m_region.bottom_left,m_region.top_right); for (auto line: lines) { addLine(line.second); } sortPixelLines(); // and chop duplicate lines: std::vector<int> removelist; int i = -1; for (auto line: lines) { i++; PixelRef start = pixelate(line.second.start()); auto& pixel_lines = m_pixel_lines(static_cast<size_t>(start.y), static_cast<size_t>(start.x)); for (int k: pixel_lines) { if (k > int(i) && approxeq(m_lines[i].line.start(),m_lines[k].line.start(),tolerance)) { if (approxeq(m_lines[i].line.end(),m_lines[k].line.end(),tolerance)) { removelist.push_back(line.first); break; } } } } for(int remove: removelist) { lines.erase(remove); } removelist.clear(); // always clear this list, it's reused} }
Game(): window(sf::VideoMode(500, 400), "Okno aplikacji"), messages_text("Komunikaty:"), player(nullptr), turn(0), left_button(false) { window.setFramerateLimit(100); loadFont(); initBoard(); initLines(); initAreas(); initMessages(); initButton(); }
void XBScene1::setup(XBBaseGUI *_gui) { XBBaseScene::setup(_gui); wavesMask.allocate(ofGetWidth(), ofGetHeight(), GL_RGB); wavesMask.begin(); ofSetBackgroundAuto(false); ofBackground(0, 0, 0); wavesMask.end(); initWindows(); initParticles(); initWaves(); initStones(); initLines(); blur.setup(getMainFBO().getWidth(), getMainFBO().getHeight(), 0); XBScene1GUI *myGUI = (XBScene1GUI *) gui; myGUI->flashDirector.getParameter().cast<bool>().addListener(this, &XBScene1::flashDirector); }
void KisStrokeBenchmark::initTestCase() { m_dataPath = QString(FILES_DATA_DIR) + QDir::separator(); m_outputPath = QString(FILES_OUTPUT_DIR) + QDir::separator(); m_colorSpace = KoColorSpaceRegistry::instance()->rgb8(); m_color = KoColor(m_colorSpace); int width = TEST_IMAGE_WIDTH; int height = TEST_IMAGE_HEIGHT; m_image = new KisImage(0, width, height, m_colorSpace, "stroke sample image"); m_layer = new KisPaintLayer(m_image, "temporary for stroke sample", OPACITY_OPAQUE_U8, m_colorSpace); m_painter = new KisPainter(m_layer->paintDevice()); m_painter->setPaintColor(KoColor(Qt::black, m_colorSpace)); // for bezier curve test initCurvePoints(width, height); // for the lines test initLines(width,height); }
void TidyLines::tidy(std::vector<Line>& lines, const QtRegion& region) { m_region = region; double maxdim = std::max(m_region.width(),m_region.height()); // simple first pass -- remove very short lines lines.erase( std::remove_if(lines.begin(), lines.end(), [maxdim](const Line& line) {return line.length() < maxdim * TOLERANCE_B;}), lines.end()); // now load up m_lines... initLines(lines.size(),m_region.bottom_left,m_region.top_right); for (auto& line: lines) { addLine(line); } sortPixelLines(); std::vector<int> removelist; for (size_t i = 0; i < lines.size(); i++) { // n.b., as m_lines have just been made, note that what's in m_lines matches whats in lines // we will use this later! m_test++; m_lines[i].test = m_test; PixelRefVector list = pixelateLine( m_lines[i].line ); for (size_t a = 0; a < list.size(); a++) { auto pixel_lines = m_pixel_lines(static_cast<size_t>(list[a].y), static_cast<size_t>(list[a].x)); for (int j: pixel_lines) { if (m_lines[j].test != m_test && j > (int)i && intersect_region(lines[i],lines[j],TOLERANCE_B * maxdim)) { m_lines[j].test = m_test; int axis_i = (lines[i].width() >= lines[i].height()) ? XAXIS : YAXIS; int axis_j = (lines[j].width() >= lines[j].height()) ? XAXIS : YAXIS; int axis_reverse = (axis_i == XAXIS) ? YAXIS : XAXIS; if (axis_i == axis_j && fabs(lines[i].grad(axis_reverse) - lines[j].grad(axis_reverse)) < TOLERANCE_A && fabs(lines[i].constant(axis_reverse) - lines[j].constant(axis_reverse)) < (TOLERANCE_B * maxdim)) { // check for overlap and merge int parity = (axis_i == XAXIS) ? 1 : lines[i].sign(); if ((lines[i].start()[axis_i] * parity + TOLERANCE_B * maxdim) > (lines[j].start()[axis_j] * parity) && (lines[i].start()[axis_i] * parity) < (lines[j].end()[axis_j] * parity + TOLERANCE_B * maxdim)) { int end = ((lines[i].end()[axis_i] * parity) > (lines[j].end()[axis_j] * parity)) ? i : j; lines[j].bx() = lines[end].bx(); lines[j].by() = lines[end].by(); removelist.push_back(i); continue; // <- don't do this any more, we've zapped it and replaced it with the later line } if ((lines[j].start()[axis_j] * parity + TOLERANCE_B * maxdim) > (lines[i].start()[axis_i] * parity) && (lines[j].start()[axis_j] * parity) < (lines[i].end()[axis_i] * parity + TOLERANCE_B * maxdim)) { int end = ((lines[i].end()[axis_i] * parity) > (lines[j].end()[axis_j] * parity)) ? i : j; lines[j].ax() = lines[i].ax(); lines[j].ay() = lines[i].ay(); lines[j].bx() = lines[end].bx(); lines[j].by() = lines[end].by(); removelist.push_back(i); continue; // <- don't do this any more, we've zapped it and replaced it with the later line } } } } } } // comes out sorted, remove duplicates just in case removelist.erase(std::unique(removelist.begin(), removelist.end()), removelist.end()); for(auto iter = removelist.rbegin(); iter != removelist.rend(); ++iter) lines.erase(lines.begin() + *iter); removelist.clear(); // always clear this list, it's reused }
//------------------------------------------------------------------------------ // std::auto_ptr<XxDiffs> XxBuilderDirs2::process( const QString& command, XxBuffer& buffer1, XxBuffer& buffer2 ) { initLines(); QString path1 = buffer1.getName(); QString path2 = buffer2.getName(); QStringList filenames; filenames.append( path1 ); filenames.append( path2 ); QStringList out_args; QString executable; XxUtil::splitArgs( command, filenames, executable, out_args ); QProcess diffProc; diffProc.start( executable, out_args ); if ( ! diffProc.waitForStarted() ) { throw XxIoError( XX_EXC_PARAMS ); } diffProc.waitForReadyRead(); diffProc.setReadChannel( QProcess::StandardOutput ); std::vector<DirDiffType> types1; std::vector<DirDiffType> types2; QTextStream errors( &_errors ); // Note: for now we don't support recursive diffs built against a directory. if ( _buildSolelyFromOutput || _isDiffRecursive ) { buildSolelyFromOutput( diffProc, errors, buffer1, buffer2, types1, types2 ); } else { buildAgainstReadDirectory( diffProc, errors, buffer1, buffer2, types1, types2 ); } #ifdef LOCAL_TRACE XX_TRACE( "------------------------------" ); for ( unsigned int ii = 0; ii < types1.size(); ++ii ) { XX_TRACE( typeString[ types1[ii] ] ); } XX_TRACE( "------------------------------" ); XX_TRACE( "------------------------------" ); for ( unsigned int ii = 0; ii < types2.size(); ++ii ) { XX_TRACE( typeString[ types2[ii] ] ); } XX_TRACE( "------------------------------" ); #endif XxFln fline1 = 1; XxFln fline2 = 1; { // Create regions with it. Hopefully our searches resulted in something // coherent w.r.t. to the quantities and pair matching of entries. Barf if // it doesn't. std::vector<DirDiffType>::const_iterator it1 = types1.begin(); std::vector<DirDiffType>::const_iterator it2 = types2.begin(); while ( it1 != types1.end() || it2 != types2.end() ) { if ( it1 == types1.end() ) { if ( *it2 != ONLY_IN ) { throw XxInternalError( XX_EXC_PARAMS ); } XxLine line( XxLine::INSERT_2, -1, fline2++ ); addLine( line ); ++it2; continue; } if ( it2 == types2.end() ) { if ( *it1 != ONLY_IN ) { throw XxInternalError( XX_EXC_PARAMS ); } XxLine line( XxLine::INSERT_1, fline1++, -1 ); addLine( line ); ++it1; continue; } if ( *it1 == ONLY_IN ) { XxLine line( XxLine::INSERT_1, fline1++, -1 ); addLine( line ); ++it1; } else if ( *it2 == ONLY_IN ) { XxLine line( XxLine::INSERT_2, -1, fline2++ ); addLine( line ); ++it2; } else if ( *it1 == DIFFER ) { if ( *it2 != *it1 ) { throw XxInternalError( XX_EXC_PARAMS ); } XxLine::Type dtype = _ignoreFileChanges == true ? XxLine::SAME : XxLine::DIFF_ALL; XxLine line( dtype, fline1++, fline2++ ); addLine( line ); ++it1; ++it2; } else if ( *it1 == IDENTICAL ) { if ( *it2 != *it1 ) { throw XxInternalError( XX_EXC_PARAMS ); } XxLine line( XxLine::SAME, fline1++, fline2++ ); addLine( line ); ++it1; ++it2; } else if ( *it1 == COMMON_SUBDIR ) { if ( *it2 != *it1 ) { throw XxInternalError( XX_EXC_PARAMS ); } XxLine line( XxLine::DIRECTORIES, fline1++, fline2++ ); addLine( line ); ++it1; ++it2; } else { XX_ASSERT( false ); } } } // Create hunks. if ( _lines.size() > 0 ) { XxHunk curHunk = 0; XxLine::Type prevType = _lines[0].getType(); _lines[0].setHunkId( curHunk ); for ( XxDln ii = 1; ii < XxDln(_lines.size()); ++ii ) { XxLine& cline = _lines[ii]; if ( prevType != cline.getType() ) { ++curHunk; prevType = cline.getType(); } cline.setHunkId( curHunk ); } } diffProc.waitForFinished(); // Collect stderr. QString errstr = diffProc.readAllStandardError(); if ( ! errstr.isEmpty() ) { errors << errstr << endl; } _status = ( diffProc.exitStatus() == QProcess::NormalExit ) ? diffProc.exitCode() : 2; // Saved error text. errors << flush; XX_LOCAL_TRACE( "Errors: " << _errors ); // If we've read no lines and there are diff errors then blow off if ( ( fline1 == 1 ) && ( fline2 == 1 ) && hasErrors() ) { throw XxIoError( XX_EXC_PARAMS ); } std::auto_ptr<XxDiffs> ap( new XxDiffs( _lines, true ) ); return ap; }
void LinkStatusWidget::paintEvent(QPaintEvent *event){ initLines(); QPainter painter(this); QPixmap pic(QString::fromUtf8(":/computer_white.png")); QRectF dest(0,0,pic.width(),pic.height()); QPixmap pic2(QString::fromUtf8(":/honeywell.png")); QRectF dest2(0,0,pic2.width(),pic2.height()); //220*180 QRectF target_0(this->left_left,this->left_top,this->left_width,this->left_height); QRectF target_1(this->width()-this->right_right-this->right_width,this->right_top,this->right_width,this->right_height); QRectF target_2(this->width()-this->right_right-this->right_width,this->right_top+this->right_height+this->right_space,this->right_width,this->right_height); painter.setPen(Qt::white); painter.drawPixmap(target_0,pic2,dest2); painter.drawText(this->left_left+this->left_width+this->left_space,this->left_top+painter.fontMetrics().height(),Config::LINKSTATUS_LABEL.split("#").at(2)); painter.drawPixmap(target_1,pic,dest); QString text=Config::LINKSTATUS_LABEL.split("#").at(0); int f_w=painter.fontMetrics().width(text); painter.drawText(this->width()-this->right_right-this->right_width-this->right_space*2-f_w,this->right_top+painter.fontMetrics().height()+this->right_space,text); painter.drawPixmap(target_2,pic,dest); text=Config::LINKSTATUS_LABEL.split("#").at(1); f_w=painter.fontMetrics().width(text); painter.drawText(this->width()-this->right_right-this->right_width-this->right_space*2-f_w,this->right_top+this->right_height+this->right_space*2+painter.fontMetrics().height(),text); //draw base line painter.save(); //#353942 QPen pen1(Qt::white,8,Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); pen1.setColor(QColor(53, 57, 66)); painter.setPen(pen1); painter.drawLines(lines); painter.restore(); if(!this->isConn){ return; } int centerHeight=this->right_top+this->right_height+this->right_space/2; QColor co1 =QColor(146, 196, 15) ; QColor co2 =QColor(0, 255, 0, 0); QColor co3 =QColor( 255,0, 0,200); QColor co4 =QColor( 255,0,0, 0); int mleft=this->width()-this->right_right-this->right_width-this->right_space-this->countMain; int mright=mleft+this->line_width_main; if(this->isBroken_1){ QLinearGradient linearGradient = QLinearGradient(mleft,centerHeight,mright,centerHeight); linearGradient.setColorAt(0,co3); linearGradient.setColorAt(1,co4); QPen pen2(linearGradient,5); pen2.setCapStyle(Qt::RoundCap); painter.setPen(pen2); }else{ QLinearGradient linearGradient = QLinearGradient(mleft,centerHeight,mright,centerHeight); linearGradient.setColorAt(0,co1); linearGradient.setColorAt(1,co2); QPen pen2(linearGradient,5); pen2.setCapStyle(Qt::RoundCap); painter.setPen(pen2); } painter.drawLine(mleft,centerHeight,mright,centerHeight); int sbottom= this->right_top+this->right_height/2+this->countSub; int stop= sbottom-this->line_width_sub; int sright=this->width()-this->right_right+this->right_space; //message 2 if(this->isBroken_2){ QLinearGradient linearGradient2 = QLinearGradient(sright,stop,sright,sbottom); linearGradient2.setColorAt(0,co4); linearGradient2.setColorAt(1,co3); QPen pen3(linearGradient2,4); pen3.setCapStyle(Qt::RoundCap); painter.setPen(pen3); }else{ QLinearGradient linearGradient2 = QLinearGradient(sright,stop,sright,sbottom); linearGradient2.setColorAt(0,co2); linearGradient2.setColorAt(1,co1); QPen pen3(linearGradient2,4); pen3.setCapStyle(Qt::RoundCap); painter.setPen(pen3); } painter.drawLine(sright,stop,sright,sbottom); }