Beispiel #1
0
int main()
{
    std_setup();
    
    
    int N = 300;
    
    grid2D<> u( N, 0, 1, N, 0, 1 );
    
    
    
    
    plot2D plt( 0,1,0,1, N, N);
    plt = ml_white;
    ml_random rng;
    
    int count = 0;
    
    
    for (int k=0; k<100000; k++)
    {
        cout << k << endl;
        
        plt = ml_white;
        
        double x1 = rng.gen_double();
        double x2 = rng.gen_double();
        double x3 = rng.gen_double();
        double x4 = rng.gen_double();
        double y1 = rng.gen_double();
        double y2 = rng.gen_double();
        double y3 = rng.gen_double();
        double y4 = rng.gen_double();
        
        double x,y;
        
        int res = intersection( x,y, x1, y1, x2, y2, x3, y3, x4, y4 );
        bool straddle = straddle_test( x1,x2,x3,x4,y1,y2,y3,y4 );
        
        plt.ptDot( x,y, 5, ml_green );
        
        if ( ( straddle and res == 1 ) or ( !straddle and res == 0 ) )
        {
            plt.ptLine( x1,y1,x2,y2, ml_black );
            plt.ptLine( x3,y3,x4,y4, ml_black );
            
          // sprintf(fname, "/workspace/output/SDE/project1/test/%04d.png", k );
          // plt.png(fname);
            
            count ++;
        }
        
        
    }
    
    cout << count << endl;
    
    
    std_exit();
}
void QSoftKeyDesignToolWidget::on_EditHeight_editingFinished()
{
    QPalette plt( ui->EditHeight->palette() );
    plt.setColor( QPalette::Text, Qt::black );
    ui->EditPosX->setPalette( plt );

    EditModified();
}
Beispiel #3
0
int main()
{
    // input signal parameters
    const std::size_t SIZE = 64;
    const Aquila::FrequencyType sampleFreq = 2000;
    const Aquila::FrequencyType f1 = 96, f2 = 813;
    const Aquila::FrequencyType f_lp = 500;

    Aquila::SineGenerator sineGenerator1 = Aquila::SineGenerator(sampleFreq);
    sineGenerator1.setAmplitude(32).setFrequency(f1).generate(SIZE);
    Aquila::SineGenerator sineGenerator2 = Aquila::SineGenerator(sampleFreq);
    sineGenerator2.setAmplitude(8).setFrequency(f2).setPhase(0.75).generate(SIZE);
    Aquila::Sum sum(sineGenerator1, sineGenerator2);

    Aquila::TextPlot plt("Signal waveform before filtration");
    plt.plot(sum);

    // calculate the FFT
    auto fft = Aquila::FftFactory::getFft(SIZE);
    Aquila::ComplexType spectrum[SIZE];
    fft->fft(sum.toArray(), spectrum);
    plt.setTitle("Signal spectrum before filtration");
    plt.plotSpectrum(spectrum, SIZE);

    // generate a low-pass filter spectrum
    Aquila::ComplexType filterSpectrum[SIZE];
    for (std::size_t i = 0; i < SIZE; ++i)
    {
        if (i < (SIZE * f_lp / sampleFreq))
        {
            // passband
            filterSpectrum[i] = 1.0;
        }
        else
        {
            // stopband
            filterSpectrum[i] = 0.0;
        }
    }
    plt.setTitle("Filter spectrum");
    plt.plotSpectrum(filterSpectrum, SIZE);

    // the following line does the multiplication of two spectra
    // (which is complementary to convolution in time domain)
    typedef Aquila::ComplexType cplx;
    std::transform(spectrum, spectrum + SIZE, filterSpectrum, spectrum,
                   [] (cplx x, cplx y) { return x * y; });
    plt.setTitle("Signal spectrum after filtration");
    plt.plotSpectrum(spectrum, SIZE);

    // Inverse FFT moves us back to time domain
    double x1[SIZE];
    fft->ifft(spectrum, x1);
    plt.setTitle("Signal waveform after filtration");
    plt.plot(x1, SIZE);

    return 0;
}
Beispiel #4
0
int main(int argc, const char * argv[]) {
    // insert code here...
    int n=1;
    int num_rows=1;
    int spots_per_row=11;
    ParkingLot plt(n,num_rows,spots_per_row);
    std::cout<<plt.parkVehicle("motor1");
    return 0;
}
Beispiel #5
0
//	TEST(NumOptNew, BestSetSimple) {
//		float data[1] = {8};
//		NumOptAlgoBestSet<float, 1> opt(200);
//		Plot plt(Opt::fSimple);
//		opt.setCallback(plt.get());
//		opt.findMinimum(Opt::fSimple, NumOptAlgoBestSet<float,1>::ModifyAll(4,0), data);
//		ASSERT_NEAR(0, data[0], 0.1);
//	}
//	TEST(NumOptNew, BestSetNoise0) {
//		float data[1] = {8};
//		NumOptAlgoBestSet<float, 1> opt(200);
//		Plot plt(Opt::fNoise0);
//		opt.setCallback(plt.get());
//		opt.findMinimum(Opt::fNoise0, NumOptAlgoBestSet<float,1>::ModifyAll(4,0), data);
//		ASSERT_NEAR(0, data[0], 0.1);
//	}
//	TEST(NumOptNew, BestSetNoise1) {
//		float data[1] = {8};
//		NumOptAlgoBestSet<float, 1> opt(200);
//		Plot plt(Opt::fNoise1);
//		opt.setCallback(plt.get());
//		opt.findMinimum(Opt::fNoise1, NumOptAlgoBestSet<float,1>::ModifyAll(4,0), data);
//		ASSERT_NEAR(0, data[0], 0.1);
//	}
//	TEST(NumOptNew, BestSetNoise2) {
//		float data[1] = {8};
//		NumOptAlgoBestSet<float, 1> opt(200);
//		Plot plt(Opt::fNoise2);
//		opt.setCallback(plt.get());
//		opt.findMinimum(Opt::fNoise2, NumOptAlgoBestSet<float,1>::ModifyAll(4,0), data);
//		ASSERT_NEAR(0, data[0], 0.1);
//	}
//	TEST(NumOptNew, BestSetRosenbrock) {
//		float data[2] = {-1};
//		NumOptAlgoBestSet<float, 2> opt(200);
//		Plot2 plt(Opt::fRosenbrock, -2, 2, 50);
//		opt.setCallback(plt.get());
//		opt.findMinimum(Opt::fRosenbrock, NumOptAlgoBestSet<float,2>::ModifyAll(1,0), data);
//		ASSERT_NEAR(1, data[0], 0.1);
//		ASSERT_NEAR(1, data[1], 0.1);
//	}
	TEST(NumOptNew, BestSetRosenbrock) {
		float data[2] = {-1};
		NumOptAlgoBestSet<float, 2> opt(200);
		Plot2 plt(Opt::fHimmelblau, -4, 4, 50);
		opt.setCallback(plt.get());
		opt.findMinimum(Opt::fHimmelblau, NumOptAlgoBestSet<float,2>::ModifyAll(1,0), data);
//		ASSERT_NEAR(1, data[0], 0.1);
//		ASSERT_NEAR(1, data[1], 0.1);
	}
Beispiel #6
0
void GenericCodeEditor::paintLineIndicator( QPaintEvent *e )
{
    QPalette plt( mLineIndicator->palette() );
    QRect r( e->rect() );
    QPainter p( mLineIndicator );

    p.fillRect( r, plt.color( QPalette::Mid ) );
    p.setPen( plt.color(QPalette::Dark) );
    p.drawLine( r.topRight(), r.bottomRight() );

    p.setPen( plt.color(QPalette::ButtonText) );

    QTextDocument *doc = QPlainTextEdit::document();
    QTextCursor cursor(textCursor());
    int selStartBlock, selEndBlock;
    if (cursor.hasSelection()) {
        selStartBlock = doc->findBlock(cursor.selectionStart()).blockNumber();
        selEndBlock = doc->findBlock(cursor.selectionEnd()).blockNumber();
    }
    else
        selStartBlock = selEndBlock = -1;

    QTextBlock block = firstVisibleBlock();
    int blockNumber = block.blockNumber();
    qreal top = blockBoundingGeometry(block).translated(contentOffset()).top();
    qreal bottom = top + blockBoundingRect(block).height();

    while (block.isValid() && top <= e->rect().bottom()) {
        if (block.isVisible() && bottom >= e->rect().top()) {
            p.save();

            QRectF numRect( 0, top, mLineIndicator->width() - 1, bottom - top );

            int num = blockNumber;
            if (num >= selStartBlock && num <= selEndBlock) {
                num -= selStartBlock;
                p.setPen(Qt::NoPen);
                p.setBrush(plt.color(QPalette::Highlight));
                p.drawRect(numRect);
                p.setPen(plt.color(QPalette::HighlightedText));
            }

            QString number = QString::number(num + 1);
            p.drawText(0, top, mLineIndicator->width() - 4, bottom - top,
                       Qt::AlignRight, number);

            p.restore();
        }

        block = block.next();
        top = bottom;
        bottom = top + blockBoundingRect(block).height();
        ++blockNumber;
    }
}
Beispiel #7
0
void
PNGTests::testWriter() {
  static const int width  = 256;
  static const int height = 256;

  // create an image and fill it with random data
  auto_ptr<Image> image(CreateImage(width, height, PF_R8G8B8A8));
  setRandomBytes((byte*)image->getPixels(), width * height * 4);

  // generate filename
  char* filename = tmpnam(0);
  CPPUNIT_ASSERT_MESSAGE("opening temporary file", filename != 0);

  // save image
  CPPUNIT_ASSERT(SaveImage(filename, FF_PNG, image.get()) == true);

  // load it back
  auto_ptr<Image> img2(OpenImage(filename, PF_R8G8B8A8));
  CPPUNIT_ASSERT_MESSAGE("reloading image file", img2.get() != 0);

  AssertImagesEqual(
    "comparing saved with loaded",
    image.get(),
    img2.get());

  // force pixel format conversion (don't destroy the old image)
  auto_ptr<Image> img3(OpenImage(filename, PF_R8G8B8));
  CPPUNIT_ASSERT(SaveImage(filename, FF_PNG, img3.get()) == true);

  remove(filename);


  //== PALETTIZED SAVING TEST ==
  // disabled until loading palettized PNGs with a correct palette format
  // is implemented.
#if 0
  char* plt_filename = tmpnam(0);
  CPPUNIT_ASSERT_MESSAGE("opening temporary file (palette)", plt_filename != 0);
  auto_ptr<Image> plt(CreateImage(256, 256, PF_I8, 256, PF_R8G8B8));
  setRandomBytes((byte*)plt->getPixels(), 256 * 256);
  setRandomBytes((byte*)plt->getPalette(), 256);

  CPPUNIT_ASSERT(SaveImage(plt_filename, FF_PNG, plt.get()) == true);

  auto_ptr<Image> plt2(OpenImage(plt_filename, FF_PNG));
  CPPUNIT_ASSERT_MESSAGE("reloading palettized image", plt2.get() != 0);
  CPPUNIT_ASSERT(plt2->getPaletteSize() == 256);
  CPPUNIT_ASSERT(plt2->getPaletteFormat() == PF_R8G8B8);
  CPPUNIT_ASSERT(plt2->getFormat() == PF_I8);
  AssertImagesEqual("Comparing palettized image", plt.get(), plt2.get());

  remove(plt_filename);
#endif
}
Beispiel #8
0
void Theme::fillDefault()
{
    addToTheme(mFormats, "text", QColor(Qt::black), QColor(Qt::white));

    QPalette appPlt(QApplication::palette());
    QColor bkg = appPlt.color(QPalette::Base);
    int value = bkg.value();
    if (value > 40)
        bkg.setHsv(bkg.hue(), bkg.saturation(), value - 11);
    else
        bkg.setHsv(bkg.hue(), bkg.saturation(), value + 20);
    addToTheme(mFormats, "currentLine", QColor(Qt::black), bkg.toRgb());
    addToTheme(mFormats, "searchResult",
               appPlt.color(QPalette::HighlightedText).darker(200),
               appPlt.color(QPalette::Highlight).darker(200));
    addToTheme(mFormats, "matchingBrackets", QColor("#2bc93d"), Qt::yellow, true);
    addToTheme(mFormats, "mismatchedBrackets", Qt::white, QColor(150,0,0));
    addToTheme(mFormats, "evaluatedCode", Qt::black, QColor("#F8A200"));

    QPalette plt(QApplication::palette());
    QColor base = plt.color(QPalette::Base);
    QColor text = plt.color(QPalette::Text);
    int shade = (base.red() + base.green() + base.blue() < 380) ? 160 : 100;

    QColor whitespace_color((base.red() + text.red()) / 2,
                            (base.green() + text.green()) / 2,
                            (base.blue() + text.blue()) / 2);

    addToTheme(mFormats, "whitespace", whitespace_color);
    addToTheme(mFormats, "keyword", QColor(0,0,230).lighter(shade),
                                    QColor(Qt::transparent), true);
    addToTheme(mFormats, "built-in", QColor(51,51,191).lighter(shade));
    addToTheme(mFormats, "env-var", QColor(140,70,20).lighter(shade));
    addToTheme(mFormats, "class", QColor(0,0,210).lighter(shade));
    addToTheme(mFormats, "number", QColor(152,0,153).lighter(shade));
    addToTheme(mFormats, "symbol", QColor(0,115,0).lighter(shade));
    addToTheme(mFormats, "string", QColor(95,95,95).lighter(shade));
    addToTheme(mFormats, "char", QColor(0,115,0).lighter(shade));
    addToTheme(mFormats, "comment", QColor(191,0,0).lighter(shade));
    addToTheme(mFormats, "primitive", QColor(51,51,191).lighter(shade));
    addToTheme(mFormats, "lineNumbers", plt.color(QPalette::ButtonText), 
                                        plt.color(QPalette::Mid));
    addToTheme(mFormats, "selection", plt.color(QPalette::HighlightedText),
                                      plt.color(QPalette::Highlight));
    addToTheme(mFormats, "postwindowtext", plt.color(QPalette::ButtonText));
    addToTheme(mFormats, "postwindowerror", QColor(209, 28, 36));
    addToTheme(mFormats, "postwindowwarning", QColor(165, 119, 6));
    addToTheme(mFormats, "postwindowsuccess", QColor(115, 138, 5));
    addToTheme(mFormats, "postwindowemphasis", Qt::black, Qt::transparent, true);
}
Beispiel #9
0
int
main(int argc, char **argv)
{
  static xyc *Z; static nde *N;
  static double **A, *u;

  initop(argc, argv);
  fp2mesh(stdfp(),Z,N);

  ary2(A,dim1(Z)+1, dim1(Z)+1); ary1(u,dim1(Z)+1);

  set_A(Z,N,A); set_u(Z,u);

  esolver(A,u);

  plt(NULL,NULL,Z,N,u); sleep(1000);
  return 0;
}
Beispiel #10
0
void test1(){
	PyPlot plt("trig");
	const int N = 400;
	double x[N];
	double y[N];
	for(int i=0; i < N; i++){
		x[i] = 6*PI*i/N;
		y[i] = sin(x[i]);
	}
	plt.plot(x, y, N);
	plt.linestyle("--");
	plt.linewidth("3");
	plt.linecolor("red");


	for(int i=0; i < N/10; i++){
		x[i] = 6*PI*i/(N/10);
		y[i] = sin(x[i]);
	}
	plt.plot(x, y, N/10);
	plt.linestyle("None");
	plt.markertype("o");
	plt.markersize("7");
	plt.markercolor("black");

	plt.axis(0, 15, -2, 2);
	plt.title("sin(x) vs. x");
	double xticks[6] = {0, 1.6, 1.6+3.2, 1.6+6.4, 1.6+9.6, 
			    1.6+4*3.2};
	double yticks[5] = {-0.75, -0.5, 0, 0.5, 0.75};
	plt.xticks(xticks, 6);
	plt.yticks(yticks, 5);
	//plt.ticksize("20");
	const char *cmd = 
		"plt.xlabel('OK')"
		"\n";
	plt.pycmd(cmd);

	plt.show();
	plt.savescript();
}
Beispiel #11
0
QcGraph::QcGraph() :
  QtCollider::Style::Client(this),
  _defaultThumbSize( QSize(18,18) ),
  _style(DotElements),
  _drawLines( true ),
  _drawRects( true ),
  _editable( true ),
  _step( 0.01 ),
  _selectionForm( ElasticSelection ),
  _xOrder( NoOrder ),
  _gridOn( false ),
  _geometryDirty( false ),
  _lastIndex(-1)
{
  QPalette plt( palette() );

  setFocusPolicy( Qt::StrongFocus );
  setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );

  connect( &_model, SIGNAL(removed(QcGraphElement*)), this, SLOT(onElementRemoved(QcGraphElement*)) );
}
Beispiel #12
0
void QcCanvas::paintEvent( QPaintEvent *e )
{
  if( _paint && _repaintNeeded ) {
    if( _resize ) {
      _pixmap = QPixmap( size() );
      _resize = false;
      _clearOnce = true;
    }

    if( _clearOnRefresh || _clearOnce ) {
      _pixmap.fill( QColor(0,0,0,0) );
      _clearOnce = false;
    }

    bool opaque_before = testAttribute(Qt::WA_OpaquePaintEvent);

    QPainter pixPainter( &_pixmap );
    Q_EMIT( painting(&pixPainter) );
    _repaintNeeded = false;

    bool opaque_after = testAttribute(Qt::WA_OpaquePaintEvent);
    if( opaque_before && !opaque_after )
    {
      repaint();
      return;
    }
  }

  QPainter p(this);
  QPalette plt(palette());

  if( _bkg.isValid() )
      p.fillRect( e->rect(), _bkg );

  if( _paint ) p.drawPixmap( e->rect(), _pixmap, e->rect() );
}
Beispiel #13
0
void Plt(void)
{
    int mode;
    double x, y;
#ifndef WIN32
    mode = *getarg(1);
    if (mode >= 0 || ifarg(2))
    {
        if ((x = *getarg(2)) > 2047)
            x = 2047;
        else if (x < 0)
            x = 0;
        if ((y = *getarg(3)) > 2047)
            y = 2047;
        else if (y < 0)
            y = 0;
    } else {
        x=y=0.;
    }
    plt(mode, x, y);
#endif
    ret();
    pushx(1.);
}
Beispiel #14
0
void Manager::initHighlightingDefaults()
{
    QPalette plt( QApplication::palette() );
    QColor base = plt.color(QPalette::Base);
    QColor text = plt.color(QPalette::Text);
    int shade = (base.red() + base.green() + base.blue() < 380) ? 160 : 100;

    QColor whitespace_color(
                (base.red() + text.red()) / 2,
                (base.green() + text.green()) / 2,
                (base.blue() + text.blue()) / 2 );

    setDefault( "whitespace", makeHlFormat( whitespace_color ) );
    setDefault( "keyword", makeHlFormat( QColor(0,0,230).lighter(shade), QFont::Bold ) );
    setDefault( "built-in", makeHlFormat( QColor(51,51,191).lighter(shade) ) );
    setDefault( "env-var", makeHlFormat( QColor(140,70,20).lighter(shade) ) );
    setDefault( "class", makeHlFormat( QColor(0,0,210).lighter(shade) ) );
    setDefault( "number", makeHlFormat( QColor(152,0,153).lighter(shade) ) );
    setDefault( "symbol", makeHlFormat( QColor(0,115,0).lighter(shade) ) );
    setDefault( "string", makeHlFormat( QColor(95,95,95).lighter(shade) ) );
    setDefault( "char", makeHlFormat( QColor(0,115,0).lighter(shade) ) );
    setDefault( "comment", makeHlFormat( QColor(191,0,0).lighter(shade) ) );
    setDefault( "primitive", makeHlFormat( QColor(51,51,191).lighter(shade) ) );
}
Beispiel #15
0
int main(int const argc, char const * const * const argv)
{
  Grammar g;
  /*
  g |= NT("goal") >>= NT("expr");
  g |= NT("expr") >>= NT("term") + T("+") + NT("expr") | NT("term");
  g |= NT("term") >>= NT("factor") + T("*") + NT("term") | NT("factor");
  g |= NT("factor") >>= T("0") | T("1") | T("2") | T("3") | T("4") | T("5") | T("6") | T("7") | T("8") | T("9");
  */

  g |= NT("goal") >>= NT("expr");
  g |= NT("expr") >>= NT("term") + T("+") + NT("expr");
  g |= NT("expr") >>= NT("term");
  g |= NT("term") >>= NT("factor") + T("*") + NT("term");
  g |= NT("term") >>= NT("factor");
  g |= NT("factor") >>= T("id");

  /*
  g |= NT("E") >>= NT("E") + T("*") + NT("B");
  g |= NT("E") >>= NT("E") + T("+") + NT("B");
  g |= NT("E") >>= NT("B");
  g |= NT("B") >>= T("0");
  g |= NT("B") >>= T("1");
  */

  //g |= NT("B") >>= T("hello") + T(" ") + T("world") | T("goodbye") + T(" ") + T("world");

  /*
  g |= NT("start_$") >>= NT("start");
  g |= NT("start") >>= NT("start") + NT("expr");
  g |= NT("start");
  g |= NT("expr") >>= T("NR");
  g |= NT("expr") >>= NT("expr") + T("+") + NT("expr");
  */

  LRParser p(LRTable::Type::LR, 1, g);
  LexText plt(TEST_FILEPATH);
#ifndef NDEBUG
  std::cout << "====================----- Parsing -----====================" << std::endl;
#endif
  if(p.parse(plt))
  {
    std::cout << "Parsing success." << std::endl;
  }
#ifndef NDEBUG
  std::cout << "==================================================" << std::endl;
#endif

#ifndef NDEBUG
  std::cout << "====================----- " << TEST_FILEPATH << " -----====================" << std::endl;
  LexText lt(TEST_FILEPATH);
  Symbol s=END();
  do
  {
    s = lt.pop();
    std::cout << s.toString() << " ";
  }
  while(s != END());
  std::cout << std::endl;
  std::cout << "==================================================" << std::endl;

  
  std::cout << "====================----- Grammar -----====================" << std::endl;
  std::cout << g.toString();
  std::cout << "==================================================" << std::endl;
#endif

  return 0;
}
void QSoftKeyDesignToolWidget::on_EditHeight_textEdited(const QString &/*arg1*/)
{
    QPalette plt( ui->EditHeight->palette() );
    plt.setColor( QPalette::Text, Qt::red );
    ui->EditPosX->setPalette( plt );
}
Beispiel #17
0
void RawImport::setBackgroundColor(const QColor& bg)
{
    QPalette plt(d->previewWidget->palette());
    plt.setColor(d->previewWidget->backgroundRole(), bg);
    d->previewWidget->setPalette(plt);
}
Beispiel #18
0
void plprint(const char* s)
{
#if DOS
	extern int newstyle;
	extern unsigned text_style, text_size, text_orient;
#endif
	char buf[128];

	if (text && s[strlen(s) - 1] == '\n') {
		IGNORE(strcpy(buf, s));
		s = buf;
		buf[strlen(s)-1] = '\0';
	}

	if (console && text) {
#if	DOS
		if (egagrph == 2) {
			if (newstyle) {
				settextstyle(text_style,text_orient,text_size);
				newstyle = 0;
			}
			outtext(s);
		}else{
			IGNORE(fprintf(cdev, "%s", s));
		}
#else
#if SUNCORE
		hoc_pl_sunplot(s);
#else
#if NRNOC_X11
		x11_put_text(s);
#else
#if NeXTstep
		if (graphdev == NX) 
			NeXT_put_text(s);
#else

		IGNORE(fprintf(cdev, "%s", s));
		IGNORE(fflush(cdev));
#endif
#endif
#endif
#endif

	} else if (!text) {
#if GRX
		if (egagrph) {
			hoc_outtext(s);
		}else
#endif
		{
			IGNORE(fprintf(stdout, "%s", s));
		}
	}
	if (hardplot && hpdev && text && strlen(s)) {
		hard_text_preamble();
		IGNORE(fprintf(hpdev, "%s", s));
		IGNORE(fflush(hpdev));
	}
	if (text && s == buf) {
		plt(1, xlast, ylast-20);
		plt(-2, 0.,0.);
	}
}
Beispiel #19
0
void makeplot(double *x, double *y, int n, const char *name){
	PyPlot plt(name, PLTOFF);
	plt.plot(x, y, n);
	plt.show();
}