Example #1
0
// Set libplot's filling-and-edging style.  May set the line width to zero
// to turn off edging.  In libplot, a 0-width line is as narrow a line as
// can be drawn.
void drvplot::set_filling_and_edging_style()
{
	switch (currentShowType()) {
	case drvbase::stroke:
		(void)plotter->flinewidth(currentLineWidth());
		(void)plotter->pencolor(plotcolor(currentR()), plotcolor(currentG()), plotcolor(currentB()));
		(void)plotter->filltype(0);	// no filling
		break;

	case drvbase::fill:
		if (pathWasMerged()) {
			(void)plotter->flinewidth(currentLineWidth());
			(void)plotter->pencolor(plotcolor(edgeR()), plotcolor(edgeG()), plotcolor(edgeB()));
			(void)plotter->fillcolor(plotcolor(fillR()), plotcolor(fillG()), plotcolor(fillB()));
		} else {
			(void)plotter->flinewidth(0.0);	// little or no edging
			(void)plotter->pencolor(plotcolor(currentR()), plotcolor(currentG()), plotcolor(currentB()));
			(void)plotter->fillcolor(plotcolor(currentR()), plotcolor(currentG()), plotcolor(currentB()));
		}
		(void)plotter->filltype(1);
		(void)plotter->fillmod("winding");
		break;

	case drvbase::eofill:
		if (pathWasMerged()) {
			(void)plotter->flinewidth(currentLineWidth());
			(void)plotter->pencolor(plotcolor(edgeR()), plotcolor(edgeG()), plotcolor(edgeB()));
			(void)plotter->fillcolor(plotcolor(fillR()), plotcolor(fillG()), plotcolor(fillB()));
		} else {
			(void)plotter->flinewidth(0.0);	// little or no edging
			(void)plotter->pencolor(plotcolor(currentR()), plotcolor(currentG()), plotcolor(currentB()));
			(void)plotter->fillcolor(plotcolor(currentR()), plotcolor(currentG()), plotcolor(currentB()));
		}
		(void)plotter->filltype(1);
		(void)plotter->fillmod("even-odd");
		break;

	default:
		// cannot happen
		errf << "unexpected ShowType " << (int) currentShowType();
		break;
	}
}
Example #2
0
// Version with multi-segment lines
void drvVTK::print_coords()
{
	int bp = 0;
	colorStream << fillR() << " " << fillG() << " " << fillB() << " 0.5" << endl;

	polyStream << numberOfElementsInPath() << " " ;
	linepoints += numberOfElementsInPath();
	lineCount++;
	for (unsigned int n = 0; n < numberOfElementsInPath(); n++) {
		const basedrawingelement & elem = pathElement(n);
		switch (elem.getType()) {
		case moveto:{
				const Point & p = elem.getPoint(0);
				const int m = add_point(p);
				polyStream << m-1 << " ";
				bp = m; 
			}
			break;
		case lineto:{
				const Point & p = elem.getPoint(0);
				const int l = add_point(p);
				polyStream << l-1 << " ";
			}
			break;
		case closepath:
			polyStream << bp-1 << " ";
			break;
		case curveto:{
			errf << "\t\tFatal: unexpected case in drvVTK - curveto " << endl;
			}
			break;
		default:
			errf << "\t\tFatal: unexpected case in drvVTK : default" << endl;
			abort();
			break;
		}
	}
	polyStream << endl;
}
Example #3
0
void drvSAMPL::show_path()
{
	outf << "Path # " << currentNr();
	if (isPolygon())
		outf << " (polygon): " << endl;
	else
		outf << " (polyline): " << endl;
	outf << "\tcurrentShowType: ";
	switch (currentShowType()) {
	case drvbase::stroke:
		outf << "stroked";
		break;
	case drvbase::fill:
		outf << "filled";
		break;
	case drvbase::eofill:
		outf << "eofilled";
		break;
	default:
		// cannot happen
		outf << "unexpected ShowType " << (int) currentShowType();
		break;
	}
	outf << endl;
	outf << "\tcurrentLineWidth: " << currentLineWidth() << endl;
	outf << "\tcurrentR: " << currentR() << endl;
	outf << "\tcurrentG: " << currentG() << endl;
	outf << "\tcurrentB: " << currentB() << endl;
	outf << "\tedgeR:    " << edgeR() << endl;
	outf << "\tedgeG:    " << edgeG() << endl;
	outf << "\tedgeB:    " << edgeB() << endl;
	outf << "\tfillR:    " << fillR() << endl;
	outf << "\tfillG:    " << fillG() << endl;
	outf << "\tfillB:    " << fillB() << endl;
	outf << "\tcurrentLineCap: " << currentLineCap() << endl;
	outf << "\tdashPattern: " << dashPattern() << endl;
	outf << "\tPath Elements 0 to " << numberOfElementsInPath() - 1 << endl;
	print_coords();
}
Example #4
0
void drvCAIRO::show_path()
{
  DashPattern dp(dashPattern());

  outf << endl;
  outf << "  /*" << endl;
  outf << "   * Path # " << currentNr() ;
  if (isPolygon())
    outf << " (polygon):" << endl;
  else
    outf << " (polyline):" << endl;
  outf << "   */" << endl;
  outf << endl;
  
  outf << "  cairo_save (cr);" << endl;
  outf << "  cairo_set_line_width (cr, " << currentLineWidth() << ");" << endl;

  // CAIRO_LINE_CAP_BUTT   - start(stop) the line exactly at the start(end) point
  // CAIRO_LINE_CAP_ROUND  - use a round ending, the center of the circle is the end point
  // CAIRO_LINE_CAP_SQUARE - use squared ending, the center of the square is the end point
  outf << "  cairo_set_line_cap (cr, ";
  switch( currentLineCap() ) {
  case 0:
    outf << "CAIRO_LINE_CAP_BUTT);" << endl;
    break;

  case 1:
    outf << "CAIRO_LINE_CAP_ROUND);" << endl;
    break;

  case 2:
    outf << "CAIRO_LINE_CAP_SQUARE);" << endl;
    break;

  default:
    errf << "Unexpected currentLineCap() in cairo driver:  " << currentLineCap() << endl;
    outf << "CAIRO_LINE_CAP_ROUND);" << endl;
    break;
  }
  // cairo_set_dash (cairo_t *cr, const double *dashes, int num_dashes, double offset);
  // dashes :
  //     an array specifying alternate lengths of on and off stroke portions
  //
  // num_dashes :
  //     the length of the dashes array
  //
  // offset :
  //     an offset into the dash pattern at which the stroke should start
  //
  // dashPattern:  has nrOfEntries, float *numbers, float offset

  if (dp.nrOfEntries > 0) {
    outf << "  {" << endl;
    outf << "    double pat[" << dp.nrOfEntries << "] = {" << endl;
    for (int i = 0; i < dp.nrOfEntries; i++) {
      outf << "                      " << dp.numbers[i] << ", " << endl;
    }
    outf << "                   };" << endl;
    outf << endl;
    outf << "    cairo_set_dash (cr, pat, " << dp.nrOfEntries << ", " << dp.offset << ");" << endl;
    outf << "   }" << endl;
  } else {
    outf << "  cairo_set_dash (cr, NULL, 0, 0.0);" << endl;
  }

  // cairo_move_to (cr, 0.25, 0.25);
  // cairo_line_to (cr, 0.5, 0.375);
  outf << "  /* Path Elements 0 to " << numberOfElementsInPath() - 1 << " */" << endl;
  print_coords();



  switch (currentShowType()) {
  case drvbase::stroke:
    outf << "  cairo_set_source_rgb (cr, " << edgeR() << "," << edgeG() << "," << edgeB() << ");" << endl;
    outf << "  cairo_stroke (cr);" << endl;
    break;
	  
  case drvbase::eofill:
    outf << "  cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);" << endl;
    evenoddmode = true;

  case drvbase::fill:
	  
    outf << "  cairo_set_source_rgb (cr, " << fillR() << "," << fillG() << "," << fillB() << ");" << endl;
    outf << "  cairo_fill_preserve (cr);" << endl;
    if (evenoddmode) {
      outf << "  cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);" << endl;
      evenoddmode = false;
    }
    outf << "  cairo_set_source_rgb (cr, " << edgeR() << "," << edgeG() << "," << edgeB() << ");" << endl;
    outf << "  cairo_stroke (cr);" << endl;
    break;
	  
  default:
    // cannot happen
    outf << "  // unexpected ShowType " << (int) currentShowType();
    break;
  }
  outf << "  cairo_restore (cr);" << endl;

}
Example #5
0
int main()
{
	int target_rate;

	dctTrans();
	getherStats();
	fillR();
	fillD();

	for (int i = 0; i < 64; i++)
	{
		least_D[i] = new double[max_rate * 64];
		choice[i] = new int[max_rate * 64];
		for (int j = 0; j < max_rate * 64; j++)
		{
			choice[i][j] = 150;
		}
	}
	for (int n = 0; n < 64; n++)//³õʼ»¯least_D
	{
		for (int s = 0; s <= max_rate; s++)
		{
			least_D[n][s] = INFINITY;
		}
	}

	for (int q = 1; q < QMAX; q++)
	{
		if (D[0][q] < least_D[0][R[0][q]])
		{
			least_D[0][R[0][q]] = D[0][q];
			choice[0][R[0][q]] = q;
		}
	}
	for (int n = 1; n < 64; n++)
	{
		for (int q = 1; q < QMAX; q++)
		{
			for (int s = 0; s <= max_rate; s++)
			{
				if (D[n][q] + least_D[n - 1][s] < least_D[n][s + R[n][q]])
				{
					least_D[n][s + R[n][q]] = D[n][q] + least_D[n - 1][s];
					choice[n][s + R[n][q]] = q;
				}
			}
		}
	}

	for (int i = 0; i < 64; i++)
	{
		for (int j = 1; j < 64 * max_rate; j++)
		{
			if (choice[i][j] > choice[i][j - 1])
				choice[i][j] = choice[i][j - 1];
			//  cout << choice[i][j] << " ";
		}
		//  cout << endl;
	}

	target_rate = 110;
	for (int n = 63; n >= 0; n--)
	{
		cout << choice[n][target_rate] << "  ";
		target_rate -= R[n][choice[n][target_rate]];
	}

	for (int i = 0; i < 64; i++)
	{
		delete[] least_D[i];
		delete[] choice[i];
	}
	return 0;
}
int main(int argc, char**) {
  {
    long long t1=0;
    float s1=0;
    long long t2=0;
    float s2=0;
    long long t3=0;
    float s3=0;
    
    
    fillR();
    computeV();
    
    
    for (int i=0; i!=10000; ++i) {
      fillO();

      t1 -= rdtsc();
      computeV();
      t1 += rdtsc();
      s1+=sum();
      
      t2 -= rdtsc();
      computeA();
      t2 += rdtsc();
      s2+=sum();
      
      t3 -= rdtsc();
      computeB();
      t3 += rdtsc();
      s3+=sum();
      
    }
    std::cout << "native vector " << s1 << " " << double(t1)/10000 << std::endl;
    std::cout << "vector by elements " << s2 << " " << double(t2)/10000 << std::endl;
    std::cout << "scalar " << s3 << " " << double(t3)/10000 << std::endl << std::endl;

  }
  {
    long long t1=0;
    float s1=0;
    long long t2=0;
    float s2=0;
    long long t3=0;
    float s3=0;
    
    
    fillO();
    computeV();
    
    
    for (int i=0; i!=10000; ++i) {
      fillR();
      t1 -= rdtsc();
      computeV();
      t1 += rdtsc();
      s1+=sum();
      
      t2 -= rdtsc();
      computeA();
      t2 += rdtsc();
      s2+=sum();
      
      memcpy(a,va,sizeof(float)*1024*vfl);
      t3 -= rdtsc();
      computeL();
      t3 += rdtsc();
      memcpy(vb,b,sizeof(float)*1024*vfl);
      s3+=sum();
      
    }
    std::cout << "native vector " << s1 << " " << double(t1)/10000 << std::endl;
    std::cout << "vector by elements " << s2 << " " << double(t2)/10000 << std::endl;
    std::cout << "scalar " << s3 << " " << double(t3)/10000 << std::endl << std::endl;
  }
  {
    long long t1=0;
    float s1=0;
    long long t2=0;
    float s2=0;
    long long t3=0;
    float s3=0;
    
    
    fillO();
    computeV();
    
    
    for (int i=0; i!=10000; ++i) {
      fillW();
      t1 -= rdtsc();
      computeV();
      t1 += rdtsc();
      s1+=sum();
      
      t2 -= rdtsc();
      computeA();
      t2 += rdtsc();
      s2+=sum();
      
      t3 -= rdtsc();
      computeB();
      t3 += rdtsc();
      s3+=sum();
      
    }
    std::cout << "native vector " << s1 << " " << double(t1)/10000 << std::endl;
    std::cout << "vector by elements " << s2 << " " << double(t2)/10000 << std::endl;
    std::cout << "scalar " << s3 << " " << double(t3)/10000 << std::endl << std::endl;
  }
  return 0;
    
}