void RobotDemo::spinnerRight(float speed) {
	float sec = 0.0;
	float currentMotorPower = 0.0;
	
	if(speed<0.05 && speed>-0.05){
		stopSpinnersRight();
	}
	else if(speed>0){
		while(currentMotorPower<speed){
			spinnerR1->Set(currentMotorPower);
			spinnerR2->Set(currentMotorPower);
			sec += 0.1;
			currentMotorPower = ramp(sec);
		}
		spinnerR1->Set(speed); //may need to
		spinnerR2->Set(speed); //reverse these
	}
	else{
		while(currentMotorPower<abs(speed)){
			spinnerR1->Set(-currentMotorPower);
			spinnerR2->Set(-currentMotorPower);
			sec += 0.3;
			currentMotorPower = ramp(sec);
		}
		spinnerR1->Set(speed); //may need to
		spinnerR2->Set(speed); //reverse these
	}
	
}
// setFire
//---------------------------------------------------------------------------
void Palette::setFire()
{
	ramp(color,   0,   0,   0,   0,  95, 255, 255, 255); // Black  2 White
	ramp(color,  96, 255, 255, 255, 130, 255, 255,   0); // White  2 Yellow
	ramp(color, 131, 255, 255,   0, 247, 255,   3,   3); // Yellow 2 Red

} // end Palette::setFire
void QgsPalettedRendererWidget::setFromRenderer( const QgsRasterRenderer *r )
{
  const QgsPalettedRasterRenderer *pr = dynamic_cast<const QgsPalettedRasterRenderer *>( r );
  if ( pr )
  {
    mBand = pr->band();
    whileBlocking( mBandComboBox )->setBand( mBand );

    //read values and colors and fill into tree widget
    mModel->setClassData( pr->classes() );

    if ( pr->sourceColorRamp() )
    {
      whileBlocking( btnColorRamp )->setColorRamp( pr->sourceColorRamp() );
    }
    else
    {
      std::unique_ptr< QgsColorRamp > ramp( new QgsRandomColorRamp() );
      whileBlocking( btnColorRamp )->setColorRamp( ramp.get() );
    }
  }
  else
  {
    loadFromLayer();
    std::unique_ptr< QgsColorRamp > ramp( new QgsRandomColorRamp() );
    whileBlocking( btnColorRamp )->setColorRamp( ramp.get() );
  }
}
示例#4
0
float Example2DWake::
potential(float x, float y) const
{
   // begin with background laminary flow (adjusted so zero level goes through centre of disc)
   float p=-background_flow_speed*(y-disc_centre[1]);
   // modify for disc
   float d=solid_distance(x,y);
   if(d<disc_influence){
      p*=ramp(d/disc_influence);
   }
   // add turbulent wake that respects disc
   float wake_x=smooth_step(1-(x-disc_centre[0])/disc_radius);
   if(wake_x>0){
      float wake_y=smooth_step(1-std::fabs(y-disc_centre[1])/(1.5f*disc_radius+wake_expansion*(disc_centre[0]-x)));
      if(wake_y>0){
         float wake=wake_x*wake_y;
         float s=0;
         for(unsigned int i=0; i<noise_lengthscale.size(); ++i){
            s+=ramp(d/noise_lengthscale[i])*noise_gain[i]*noise((x-background_flow_speed*t)/noise_lengthscale[i], y/noise_lengthscale[i]);
         }
         p+=wake*s;
      }
   }
   return p;
}
示例#5
0
文件: swritestr.c 项目: csound/csound
static char *pfout(CSOUND *csound, SRTBLK *bp, char *p,
                   int lincnt, int pcnt, CORFIL *sco)
{
    switch (*p) {
    case 'n':
      p = nextp(csound, bp,p, lincnt, pcnt, sco);
      break;
    case 'p':
      p = prevp(csound, bp,p, lincnt, pcnt, sco);
      break;
    case '<':
    case '>':
      p = ramp(csound, bp,p, lincnt, pcnt, sco);
      break;
    case '(':
    case ')':
      p = expramp(csound, bp, p, lincnt, pcnt, sco);
      break;
    case '~':
      p = randramp(csound, bp, p, lincnt, pcnt, sco);
      break;
    case '"':
      p = pfStr(csound, p, lincnt, pcnt, sco);
      break;
    default:
      p = fpnum(csound, p, lincnt, pcnt, sco);
      break;
    }
    return(p);
}
示例#6
0
static double kmol_per_sec_outflow(double n, double TK, double x_m, double refvol, 
				   double flowwidth)
     /* gives Tray outflow in 
             kmol / sec
	from 
             n molar tray holdup
             Temp in Kelvin, 
	     x_m the Methanol concentration
	     refvol reference volume in litre
     */

{
  double volumeholdup, volumeoutflow, outflow, l_per_kmol;
  const double alpha=500;
  l_per_kmol=litre_per_kmol(TK, x_m);
  volumeholdup=l_per_kmol * n;
  volumeoutflow = flowwidth*(
			     pow(1/alpha*ramp(alpha*(volumeholdup-refvol)),1.5)
			     /* -1/pow(alpha,1.5)*ramp(-alpha*(volumeholdup-refvol)) */
			     );
  outflow=volumeoutflow / l_per_kmol;

  /*
  acadoFPrintf(stderr,"%g  ",refvol/volumeholdup);
  */

  return outflow;
}
示例#7
0
void do_geo(DisjointBoxLayout&              a_dbl,
            EBISLayout       &              a_ebisl,
            Box              &              a_domain,
            Real             &              a_dx )
{

  //define grids
  int len = 32;
  int mid = len/2;
  Real xdom = 1.0;
  a_dx = xdom/len;
  const IntVect hi = (len-1)*IntVect::Unit;
  a_domain=  Box(IntVect::Zero, hi);
  Vector<Box> boxes(4);
  Vector<int> procs(4);
  boxes[0] = Box(IntVect(D_DECL(0  ,  0,   0)), IntVect(D_DECL(mid-1, mid-1, len-1)));
  boxes[1] = Box(IntVect(D_DECL(0  ,mid,   0)), IntVect(D_DECL(mid-1, len-1, len-1)));
  boxes[2] = Box(IntVect(D_DECL(mid,  0,   0)), IntVect(D_DECL(len-1, mid-1, len-1)));
  boxes[3] = Box(IntVect(D_DECL(mid,mid,   0)), IntVect(D_DECL(len-1, len-1, len-1)));

  LoadBalance(procs, boxes);
  /**
  int loProc = 0;
  int hiProc = numProc() -1;
  procs[0] = loProc;
  procs[1] = hiProc;
  procs[2] = loProc;
  procs[3] = hiProc;
  **/

  a_dbl = DisjointBoxLayout(boxes, procs);

  //define geometry
  RealVect rampNormal = RealVect::Zero;
  rampNormal[0] = -0.5;
  rampNormal[1] = 0.866025404;

  Real rampAlpha = -0.0625;

  RealVect rampPoint = RealVect::Zero;
  rampPoint[0] = rampAlpha / rampNormal[0];

  bool inside = true;

  PlaneIF ramp(rampNormal,rampPoint,inside);

  RealVect vectDx = RealVect::Unit;
  vectDx *= a_dx;

  GeometryShop mygeom( ramp, 0, vectDx );
  RealVect origin = RealVect::Zero;

  EBIndexSpace *ebisPtr = Chombo_EBIS::instance();
  ebisPtr->define(a_domain, origin, a_dx, mygeom);

  //fill layout
  ebisPtr->fillEBISLayout(a_ebisl, a_dbl, a_domain, 4 );
}
void RobotDemo::move(float distance) { //distance in feet
	/*if(distance>0){  //calls to motors directly
		victorFL->Set(MOTOR_POWER);
		victorFR->Set(MOTOR_POWER);
		victorBL->Set(MOTOR_POWER);
		victorBR->Set(MOTOR_POWER);
		Wait(distance/ROBOT_VELOCITY);
	}
	else{
		victorFL->Set(-1*MOTOR_POWER);
		victorFR->Set(-1*MOTOR_POWER);
		victorBL->Set(-1*MOTOR_POWER);
		victorBR->Set(-1*MOTOR_POWER);
		Wait(-1*distance/ROBOT_VELOCITY);
	}
	stop();*/
	float sec = 0.0;
	float currentMotorPower = ramp(sec);
			
	if(distance>0){ //forward		
		while(currentMotorPower<MOTOR_POWER){
			//myRobot.MecanumDrive_Cartesian(0,currentMotorPower,0.0,0.0);
			MecanumDrive(0,currentMotorPower,0.0,0.0);
			sec += 0.1;
			currentMotorPower = ramp(sec);
		}
		//myRobot.MecanumDrive_Cartesian(0,MOTOR_POWER,0.0,0.0);
		MecanumDrive(0,MOTOR_POWER,0.0,0.0);
		Wait(distance/ROBOT_VELOCITY-3);
	}
	else{ //backward
		while(currentMotorPower<MOTOR_POWER){
			//myRobot.MecanumDrive_Cartesian(0,-currentMotorPower,0.0,0.0);
			MecanumDrive(0,-currentMotorPower,0.0,0.0);
			sec += 0.1;
			currentMotorPower = ramp(sec);
		}
		//myRobot.MecanumDrive_Cartesian(0,-1*MOTOR_POWER,0.0,0.0);
		MecanumDrive(0,-1*MOTOR_POWER,0.0,0.0);
		Wait(-1*distance/ROBOT_VELOCITY-3);
	}
	stop();
}
示例#9
0
文件: song.c 项目: fvdsn/tuned
void song(track_t*t){
	track_t *s = trackNew(8000);
	track_t *b = trackNew(8000);
	fun_t *f;
	fun_t *f2;
	bassloop(t,0,200);
	bassloop(t,8*200,200);
	bassloop(t,16*200,200);
	bassloop(t,24*200,200);
	bassloop(t,32*200,200);
	bassloop(t,46*200,200);
	bassloop(t,54*200,200);
	bassloop(t,62*200,200);
	f = min(c(1.0),max(ramp(4000,8400,0,1),sine(ramp(2000,8400,5,8),0,10)));
	f2 =max(unit(2400,0.2,0),unit(2400,0,1.0));
		
	trackMult(t,f,f);
	f = max(unit(5000,1,0),max(unit(8500,0,1),
		min(c(1.0),max(ramp(5000,8500,1,0),sine(ramp(5000,8000,20,200),0,10)))
		));
	trackMult(t,f,f);
	//trackMult(t,f2,f2);
	//fx_reverb(t);
	fx_disto(t,WAVE_BOTH);

	tshhloop(s,0*200,200);
	tshhloop(s,8*200,200);
	tshhloop(s,16*200,200);
	tshhloop(s,24*200,200);
	tshhloop(s,32*200,200);
	tshhloop(s,40*200,200);
	tshhloop(s,46*200,200);
	tshhloop(s,54*200,200);
	tshhloop(s,56*200,200);
	tshhloop(s,62*200,200);
	f = ramp(0,8000,0.2,0.7);
	trackMult(s,f,f);
	trackMix(t,s,0,1);
		
	//fx_reverb(b);
	//fx_disto(b);
	//trackMix(t,b,0,0.5);	
}
void QgsGraduatedSymbolRendererWidget::reapplyColorRamp()
{
  std::unique_ptr< QgsColorRamp > ramp( btnColorRamp->colorRamp() );
  if ( !ramp )
    return;

  mRenderer->updateColorRamp( ramp.release() );
  mRenderer->updateSymbols( mGraduatedSymbol.get() );
  refreshSymbolView();
}
示例#11
0
static
FRESULT play (
const char *dir,	/* Directory */
const char *fn		/* File */
)
{
	DWORD sz;
	FRESULT res;
	BYTE sw;
	WORD btr;


	wdt_reset();

	res = pf_open((char*)Buff);		/* Open sound file */
	if (res == FR_OK) {
		sz = load_header();			/* Check file format and ready to play */
		if (sz < 1024) return 255;	/* Cannot play this file */

		FifoCt = 0; FifoRi = 0; FifoWi = 0;	/* Reset audio FIFO */

		if (!TCCR1) {				/* Enable audio out if not enabled */
			PLLCSR = 0b00000110;	/* Select PLL clock for TC1.ck */
			GTCCR =  0b01100000;	/* Enable OC1B as PWM */
			TCCR1 = MODE ? 0b01100001 : 0b00000001;	/* Start TC1 and enable OC1A as PWM if needed */
			TCCR0A = 0b00000010;	/* Statr TC0 as interval timer at 2MHz */
			TCCR0B = 0b00000010;
			TIMSK = _BV(OCIE0A);
			ramp(1);
		}

		pf_read(0, 512 - (Fs.fptr % 512), &rb);	/* Snip sector unaligned part */
		sz -= rb;
		sw = 1;	/* Button status flag */
		do {	/* Data transfer loop */
			wdt_reset();

			btr = (sz > 1024) ? 1024 : (WORD)sz;/* A chunk of audio data */
			res = pf_read(0, btr, &rb);	/* Forward the data into audio FIFO */
			if (rb != 1024) break;		/* Break on error or end of data */
			sz -= rb;					/* Decrease data counter */

			sw <<= 1;					/* Break on button down */
		} while ((PINB & 1) || ++sw != 1);
	}
	else{
		sendDiag(PLAY_FAIL);
	}

	while (FifoCt) ;			/* Wait for audio FIFO empty */
	OCR1A = 128; OCR1B = 128;	/* Return output to center level */

	return res;
}
示例#12
0
void QgsColorRampButton::setColorRampFromName( const QString &name )
{
  if ( !name.isEmpty() )
  {
    std::unique_ptr< QgsColorRamp > ramp( mStyle->colorRamp( name ) );
    if ( ramp )
    {
      setColorRamp( ramp.get() );
    }
  }
}
示例#13
0
task main()
{
	while(true)
	{
		getJoystickSettings(joystick);

		Driver();
		arm_tilt();
		arm_extension();
		ramp();
	}
}
示例#14
0
bool QgsStyleExportImportDialog::populateStyles( QgsStyle *style )
{
  // load symbols and color ramps from file
  if ( mDialogMode == Import )
  {
    // NOTE mTempStyle is style here
    if ( !style->importXml( mFileName ) )
    {
      QMessageBox::warning( this, tr( "Import error" ),
                            tr( "An error occurred during import:\n%1" ).arg( style->errorString() ) );
      return false;
    }
  }

  QStandardItemModel *model = qobject_cast<QStandardItemModel *>( listItems->model() );
  model->clear();

  // populate symbols
  QStringList styleNames = style->symbolNames();
  QString name;

  for ( int i = 0; i < styleNames.count(); ++i )
  {
    name = styleNames[i];
    QStringList tags = style->tagsOfSymbol( QgsStyle::SymbolEntity, name );
    QgsSymbol *symbol = style->symbol( name );
    QStandardItem *item = new QStandardItem( name );
    QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( symbol, listItems->iconSize(), 15 );
    item->setIcon( icon );
    item->setToolTip( QString( "<b>%1</b><br><i>%2</i>" ).arg( name, tags.count() > 0 ? tags.join( ", " ) : tr( "Not tagged" ) ) );
    // Set font to 10points to show reasonable text
    QFont itemFont = item->font();
    itemFont.setPointSize( 10 );
    item->setFont( itemFont );
    model->appendRow( item );
    delete symbol;
  }

  // and color ramps
  styleNames = style->colorRampNames();

  for ( int i = 0; i < styleNames.count(); ++i )
  {
    name = styleNames[i];
    std::unique_ptr< QgsColorRamp > ramp( style->colorRamp( name ) );

    QStandardItem *item = new QStandardItem( name );
    QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.get(), listItems->iconSize(), 15 );
    item->setIcon( icon );
    model->appendRow( item );
  }
  return true;
}
示例#15
0
文件: LEDs2.c 项目: kbob/hw-samples
int main()
{
    init_timer();
    init_serial();
    init_SPI();
    init_ATX_power();
    sei();

    enable_ATX_power();
    delay_milliseconds(100);

    next_update_time = millisecond_time() + FRAME_MS;
    SPI_write_byte(0x00);
    while (true) {
        const uint8_t b1 = MAX_BRIGHTNESS / 4;
        const uint8_t b2 = MAX_BRIGHTNESS * 3 / 4; 
        const uint8_t b3 = MAX_BRIGHTNESS;
        ramp(0, b1, set_LEDs_white);
        ramp(b1, 0, set_LEDs_white);
        ramp(0, b2, set_LEDs_CMY);
        ramp(b2, 0, set_LEDs_CMY);
        ramp(0, b3, set_LEDs_RGB);
        ramp(b3, 0, set_LEDs_RGB);
    }
}
示例#16
0
文件: song.c 项目: fvdsn/tuned
void sq_bass(track_t *t, int base, float vol){
	static track_t *n = NULL;
	int l;
	fun_t *f;
	if( n == NULL){
		n = trackRead("samples/basse/sq-basse.raw");
		l = trackMsecLength(n);
		printf("%d\n",l);
		f = ramp(l*0.75,l,1,0);
		trackMult(n,f,f);
	}
	trackMix(t,n,base,vol);
}
示例#17
0
void QgsPalettedRendererWidget::addEntry()
{
  disconnect( mModel, &QgsPalettedRendererModel::classesChanged, this, &QgsPalettedRendererWidget::widgetChanged );

  QColor color( 150, 150, 150 );
  std::unique_ptr< QgsColorRamp > ramp( btnColorRamp->colorRamp() );
  if ( ramp )
  {
    color = ramp->color( 1.0 );
  }
  QModelIndex newEntry = mModel->addEntry( color );
  mTreeView->scrollTo( newEntry );
  mTreeView->selectionModel()->select( newEntry, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows );
  connect( mModel, &QgsPalettedRendererModel::classesChanged, this, &QgsPalettedRendererWidget::widgetChanged );
  emit widgetChanged();
}
示例#18
0
void lsTest()
{

	for(uint16_t i=0; i<8; i++)
	{
		ramp(i);
		delay(300);
	}

	for(uint16_t i=0; i<8; i++)
	{
		tlc.setPWM(i, 0);
		tlc.write();
		delay(300);
	}
}
示例#19
0
TEST(Ramp, verify_with_reference_data) {
  Ramp ramp(1000, 0);
  
  int ind = 0;
  
  EXPECT_EQ(reference[ind], ramp.getDelay());
  while (unsigned(++ind) < sizeof(reference)/sizeof(*reference)) {
    EXPECT_EQ(reference[ind], ramp.nextDelay());  
  }
  
  ramp.reverseAcc();
  EXPECT_EQ(reference[--ind], ramp.getDelay());

  while (--ind >= 0) {
    EXPECT_EQ(reference[ind], ramp.nextDelay());  
  }
}
示例#20
0
static
void delay500 (void)
{
	wdt_reset();

	TCCR0B = 0; TCCR0A = 0;	/* Stop TC0 */

	if (TCCR1) {	/* Stop TC1 if enabled */
		ramp(0);
		TCCR1 = 0; GTCCR = 0;
	}

	WDTCR = _BV(WDE) | _BV(WDIE) | 0b101;	/* Set WDT to interrupt mode in timeout of 0.5s */
	set_sleep_mode(SLEEP_MODE_PWR_DOWN);	/* Enter power down mode */
	sleep_mode();

	wdt_reset();
	WDTCR = _BV(WDE) | 0b110;				/* Set WDT to reset mode in timeout of 1s */
}
示例#21
0
void QgsStyleManagerDialog::populateColorRamps( const QStringList& colorRamps, bool check )
{
  QStandardItemModel* model = qobject_cast<QStandardItemModel*>( listItems->model() );
  model->clear();

  for ( int i = 0; i < colorRamps.count(); ++i )
  {
    QString name = colorRamps[i];
    QScopedPointer< QgsColorRamp > ramp( mStyle->colorRamp( name ) );

    QStandardItem* item = new QStandardItem( name );
    QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.data(), listItems->iconSize() );
    item->setIcon( icon );
    item->setData( name ); // used to find out original name when user edited the name
    item->setCheckable( check );
    item->setToolTip( name );
    model->appendRow( item );
  }
  selectedSymbolsChanged( QItemSelection(), QItemSelection() );
  symbolSelected( listItems->currentIndex() );
}
示例#22
0
int main() {
    float scale     = 400.f;
    float offset_x  = 5.9f;
    float offset_y  = 5.1f;
    float offset_z  = 0.05f;
    float lacunarity    = 1.99f;
    float persistance   = 0.5f;

    Img img;

    while (!img.is_closed()) {
        Measure measure;
        measure.start();
        const SimplexNoise simplex(0.1f/scale, 0.5f, lacunarity, persistance); // Amplitude of 0.5 for the 1st octave : sum ~1.0f
        const int octaves = static_cast<int>(5 + std::log(scale)); // Estimate number of octaves needed for the current scale
        std::ostringstream title;
        title << "2D Simplex Perlin noise (" << octaves << " octaves)";
        img.set_title(title.str().c_str());
        for (int row = 0; row < img.height(); ++row) {
            const float y = static_cast<float>(row - img.height()/2 + offset_y*scale);
            for (int col = 0; col < img.width(); ++col) {
                const float x = static_cast<float>(col - img.width()/2 + offset_x*scale);
                
                // TODO(SRombauts): Add 'erosion' with simple smoothing like exponential, and other 'modifiers' like in libnoise
                // Generate "biomes", ie smooth geographic variation in frequency & amplitude, 
                // and add smaller details, summing the noise values for the coordinate
                const float noise = simplex.fractal(octaves, x, y) + offset_z;
                const color3f color = ramp(noise); // convert to color
                img.draw_point(col, row, (float*)&color);
            }
        }
        img.display();
        const double diff_ms = measure.get();
        std::cout << std::fixed << diff_ms << "ms\n";

        img.user(scale, offset_x, offset_y, offset_z, lacunarity, persistance);
    }

    return 0;
}
示例#23
0
void QgsPalettedRendererWidget::applyColorRamp()
{
  std::unique_ptr< QgsColorRamp > ramp( btnColorRamp->colorRamp() );
  if ( !ramp )
  {
    return;
  }

  disconnect( mModel, &QgsPalettedRendererModel::classesChanged, this, &QgsPalettedRendererWidget::widgetChanged );

  QgsPalettedRasterRenderer::ClassData data = mModel->classData();
  QgsPalettedRasterRenderer::ClassData::iterator cIt = data.begin();

  double numberOfEntries = data.count();
  int i = 0;

  if ( QgsRandomColorRamp *randomRamp = dynamic_cast<QgsRandomColorRamp *>( ramp.get() ) )
  {
    //ramp is a random colors ramp, so inform it of the total number of required colors
    //this allows the ramp to pregenerate a set of visually distinctive colors
    randomRamp->setTotalColorCount( numberOfEntries );
  }

  if ( numberOfEntries > 1 )
    numberOfEntries -= 1; //avoid duplicate first color

  for ( ; cIt != data.end(); ++cIt )
  {
    cIt->color = ramp->color( i / numberOfEntries );
    i++;
  }
  mModel->setClassData( data );

  connect( mModel, &QgsPalettedRendererModel::classesChanged, this, &QgsPalettedRendererWidget::widgetChanged );
  emit widgetChanged();
}
示例#24
0
float Example2DFancy::
potential(float x, float y) const
{
   Vec2f px(x,y);
   float numer=(1/sqr(envelope))*cross(px,wind_velocity);
   float denom=1/sqr(envelope);
   float minphi=1e36;
   for(unsigned int r=0; r<rigid.size(); ++r){
      Vec2f dx=px-rigid[r].centre;
      float psi=cross(px,rigid[r].velocity) + (sqr(envelope)-mag2(dx))/2*rigid[r].angular_velocity;
      float phi=rigid[r].distance(px);
      if(phi<minphi) minphi=phi;
      float m=1/(sqr(phi)+1e-18);
      numer+=m*psi;
      denom+=m;
   }
   float base_psi=numer/denom;

   float d=minphi/noise_lengthscale;
   float g=smooth_step(1.1-x);
   float turb=g*ramp(d)*noise_gain*noise((px-t*wind_velocity)/noise_lengthscale);

   return base_psi+turb;
}
void QgsCptCityColorRampDialog::populateVariants()
{
  QStringList variantList = mRamp.variantList();

  QgsDebugMsg( QStringLiteral( "ramp %1%2 has %3 variants" ).arg( mRamp.schemeName(), mRamp.variantName() ).arg( variantList.count() ) );

  cboVariantName->blockSignals( true );
  cboVariantName->clear();

  if ( variantList.isEmpty() )
  {
    cboVariantName->setEnabled( false );
    cboVariantName->setVisible( false );
    cboVariantName_currentIndexChanged( -1 );
  }
  else
  {
    // populate variant combobox
    QString oldVariant = cboVariantName->currentText();
    QgsCptCityColorRamp ramp( mRamp.schemeName(), mRamp.variantList(), QString() );
    QPixmap blankPixmap( cboVariantName->iconSize() );
    blankPixmap.fill( Qt::white );
    QIcon blankIcon( blankPixmap );
    int index;

    Q_FOREACH ( const QString &variant, variantList )
    {
      QString variantStr = variant;
      if ( variantStr.startsWith( '-' ) || variantStr.startsWith( '_' ) )
        variantStr.remove( 0, 1 );
      cboVariantName->addItem( ' ' + variantStr );
      index = cboVariantName->count() - 1;
      cboVariantName->setItemData( index, variant, Qt::UserRole );

      ramp.setVariantName( variant );
      if ( ramp.loadFile() )
        cboVariantName->setItemIcon( index,
                                     QgsSymbolLayerUtils::colorRampPreviewIcon( &ramp, cboVariantName->iconSize() ) );
      else
        cboVariantName->setItemIcon( index, blankIcon );
      cboVariantName->setItemData( index, Qt::AlignHCenter, Qt::TextAlignmentRole );
    }

    cboVariantName->blockSignals( false );

    // try to set the original variant again (if exists)
    int idx = -1;
    QString newVariant = mRamp.variantName();
    QgsDebugMsg( QStringLiteral( "variant= %1 - %2 variants" ).arg( mRamp.variantName() ).arg( mRamp.variantList().count() ) );
    if ( newVariant != QString() )
    {
      if ( newVariant.startsWith( '-' ) || newVariant.startsWith( '_' ) )
        newVariant.remove( 0, 1 );
      newVariant = ' ' + newVariant;
      idx = cboVariantName->findText( newVariant );
    }
    else
      idx = cboVariantName->findText( oldVariant );

    // if not found use the item in the middle
    if ( idx == -1 )
    {
      idx = cboVariantName->count() / 2;
    }
    cboVariantName->setCurrentIndex( idx );
    // updatePreview();

    cboVariantName->setEnabled( true );
    cboVariantName->setVisible( true );
  }
示例#26
0
int makeGeometry(Box& a_domain)
{
  Real dx;
  RealVect origin;
  int eekflag =  0;
  //parse input file
  ParmParse pp;

  Vector<int> n_cell(SpaceDim);
  pp.getarr("n_cell",n_cell,0,SpaceDim);

  CH_assert(n_cell.size() == SpaceDim);
  IntVect lo = IntVect::Zero;
  IntVect hi;
  for (int ivec = 0; ivec < SpaceDim; ivec++)
    {
      if (n_cell[ivec] <= 0)
        {
          pout() << " bogus number of cells input = " << n_cell[ivec];
          return(-1);
        }
      hi[ivec] = n_cell[ivec] - 1;
    }

  a_domain.setSmall(lo);
  a_domain.setBig(hi);

  Vector<Real> prob_lo(SpaceDim, 1.0);
  Real prob_hi;
  pp.getarr("prob_lo",prob_lo,0,SpaceDim);
  pp.get("prob_hi",prob_hi);
  dx = (prob_hi-prob_lo[0])/n_cell[0];
  RealVect dxVect = dx*RealVect::Unit;
  for (int idir = 0; idir < SpaceDim; idir++)
    {
      origin[idir] = prob_lo[idir];
    }
  int verbosity = 0;
  int whichgeom;
  pp.get("which_geom",whichgeom);
  EBIndexSpace* ebisPtr = Chombo_EBIS::instance();

  if (whichgeom == 0)
    {
      //allregular
      pout() << "all regular geometry" << endl;
      AllRegularService regserv;
      ebisPtr->define(a_domain, origin, dx, regserv);
    }
  else if (whichgeom == 1)
    {
      pout() << "ramp geometry" << endl;
      int upDir;
      int indepVar;
      Real startPt;
      Real slope;
      pp.get("up_dir",upDir);
      pp.get("indep_var",indepVar);
      pp.get("start_pt", startPt);
      pp.get("ramp_slope", slope);

      RealVect normal = RealVect::Zero;
      normal[upDir] = 1.0;
      normal[indepVar] = -slope;

      RealVect point = RealVect::Zero;
      point[upDir] = -slope*startPt;

      bool normalInside = true;

      PlaneIF ramp(normal,point,normalInside);

      GeometryShop workshop(ramp,verbosity,dxVect);
      //this generates the new EBIS
      ebisPtr->define(a_domain, origin, dx, workshop);
    }
  else if (whichgeom == 5)
    {
      pout() << "sphere geometry" << endl;
      vector<Real> sphere_center(SpaceDim);
      pp.getarr("sphere_center",sphere_center, 0, SpaceDim);
      RealVect sphereCenter;
      for (int idir = 0; idir < SpaceDim; idir++)
        {
          sphereCenter[idir] = sphere_center[idir];
        }
      Real sphereRadius;
      pp.get("sphere_radius", sphereRadius);

      bool     insideRegular = false;
      SphereIF implicit(sphereRadius,sphereCenter,insideRegular);
      GeometryShop workshop(implicit,verbosity,dxVect);
      //this generates the new EBIS
      ebisPtr->define(a_domain, origin, dx, workshop);
    }
  else if (whichgeom == 13)
    {
      pout() << "rhodonea geometry" << endl;
      vector<Real> tmp(SpaceDim);
      pp.getarr("rhodonea_center", tmp, 0, SpaceDim);
      RealVect rhodoneaCenter;
      for (int idir = 0; idir < SpaceDim; idir++)
        {
          rhodoneaCenter[idir] = tmp[idir];
        }
      Real innerRadius;
      pp.get("inner_radius", innerRadius);

      Real outerRadius;
      pp.get("outer_radius", outerRadius);

      int frequency;
      pp.get("frequency", frequency);

      bool     insideRegular = false;

      RhodoneaIF implicit(innerRadius, outerRadius, frequency,
                          rhodoneaCenter, insideRegular);

      GeometryShop workshop(implicit,verbosity,dxVect);
      //this generates the new EBIS
      ebisPtr->define(a_domain, origin, dx, workshop);
    }
  else if (whichgeom == 18)
    {
      pout() << "Low swirl burner geometry" << endl;
      //        AttachDebugger();

      Box domain;

      for (int idir = 0; idir < SpaceDim; idir++)
        {
          origin[idir] = prob_lo[idir];
        }

      Real outerRadius;
      pp.get("outer_radius",outerRadius);

      Real outerThick;
      pp.get("outer_thick",outerThick);

      Real outerHeight;
      pp.get("outer_height",outerHeight);

      Real outerOffset = ((prob_hi - prob_lo[0]) - outerHeight) / 2.0 + prob_lo[0];

      Real innerRadius;
      pp.get("inner_radius",innerRadius);

      Real innerThick;
      pp.get("inner_thick",innerThick);

      Real innerOffset = 0.0;
      innerOffset += outerOffset;

      Real innerHeight;
      pp.get("inner_height",innerHeight);

      Real plateHeight;
      pp.get("plate_height",plateHeight);
      plateHeight += outerOffset;

      Real plateThick;
      pp.get("plate_thick",plateThick);

      int doHoles;
      pp.get("do_holes",doHoles);

      Real holeRadius;
      pp.get("hole_radius",holeRadius);

      Real holeSpace;
      pp.get("hole_space",holeSpace);

      int vaneNum;
      pp.get("vane_num",vaneNum);

      Real vaneThick;
      pp.get("vane_thick",vaneThick);

      RealVect vaneNorm;

      Vector<Real> vectVaneNorm;
      pp.getarr("vane_norm",vectVaneNorm,0,SpaceDim);

      for (int idir = 0; idir < SpaceDim; idir++)
        {
          vaneNorm[idir] = vectVaneNorm[idir];
        }

      Real vaneOffset;
      pp.get("vane_offset",vaneOffset);

      Real vaneHeight = innerHeight - 2*vaneOffset;

      vaneOffset += outerOffset;

      // Make the outer chamber
      BaseIF* outerChamber = makeChamber(outerRadius,outerThick,
                                         outerOffset,outerHeight);

      // Make the inner chamber
      BaseIF* innerChamber = makeChamber(innerRadius,innerThick,
                                         innerOffset,innerHeight);

      // Make the inner plate with holes
      BaseIF* holyPlate = makePlate(plateHeight,plateThick,innerRadius,
                                    doHoles,holeRadius,holeSpace);

      // Make the vanes
      BaseIF* vanes = makeVanes(vaneNum,vaneThick,vaneNorm,innerRadius,outerRadius,
                                vaneOffset,vaneHeight);

      // Union all the pieces together
      Vector<BaseIF*> pieces;

      pieces.push_back(outerChamber);
      pieces.push_back(innerChamber);
      pieces.push_back(holyPlate);
      pieces.push_back(vanes);

      UnionIF swirl(pieces);
      ComplementIF outside(swirl,true);

      GeometryShop workshop(outside,verbosity,dxVect);

      // This generates the new EBIS
      EBIndexSpace* ebisPtr = Chombo_EBIS::instance();
      ebisPtr->define(a_domain, origin, dx, workshop);

    }
  else
    {
      //bogus which_geom
      pout() << " bogus which_geom input = " << whichgeom;
      eekflag = 33;
    }

  return eekflag;
}
示例#27
0
bool QgsStyleManagerDialog::editColorRamp()
{
  QString name = currentItemName();
  if ( name.isEmpty() )
    return false;

  QScopedPointer< QgsColorRamp > ramp( mStyle->colorRamp( name ) );

  if ( ramp->type() == QLatin1String( "gradient" ) )
  {
    QgsGradientColorRamp* gradRamp = static_cast<QgsGradientColorRamp*>( ramp.data() );
    QgsGradientColorRampDialog dlg( *gradRamp, this );
    if ( !dlg.exec() )
    {
      return false;
    }
    ramp.reset( dlg.ramp().clone() );
  }
  else if ( ramp->type() == QLatin1String( "random" ) )
  {
    QgsLimitedRandomColorRamp* randRamp = static_cast<QgsLimitedRandomColorRamp*>( ramp.data() );
    QgsLimitedRandomColorRampDialog dlg( *randRamp, this );
    if ( !dlg.exec() )
    {
      return false;
    }
    ramp.reset( dlg.ramp().clone() );
  }
  else if ( ramp->type() == QLatin1String( "colorbrewer" ) )
  {
    QgsColorBrewerColorRamp* brewerRamp = static_cast<QgsColorBrewerColorRamp*>( ramp.data() );
    QgsColorBrewerColorRampDialog dlg( *brewerRamp, this );
    if ( !dlg.exec() )
    {
      return false;
    }
    ramp.reset( dlg.ramp().clone() );
  }
  else if ( ramp->type() == QLatin1String( "preset" ) )
  {
    QgsPresetSchemeColorRamp* presetRamp = static_cast<QgsPresetSchemeColorRamp*>( ramp.data() );
    QgsPresetColorRampDialog dlg( *presetRamp, this );
    if ( !dlg.exec() )
    {
      return false;
    }
    ramp.reset( dlg.ramp().clone() );
  }
  else if ( ramp->type() == QLatin1String( "cpt-city" ) )
  {
    QgsCptCityColorRamp* cptCityRamp = static_cast<QgsCptCityColorRamp*>( ramp.data() );
    QgsCptCityColorRampDialog dlg( *cptCityRamp, this );
    if ( !dlg.exec() )
    {
      return false;
    }
    if ( dlg.saveAsGradientRamp() )
    {
      ramp.reset( dlg.ramp().cloneGradientRamp() );
    }
    else
    {
      ramp.reset( dlg.ramp().clone() );
    }
  }
  else
  {
    Q_ASSERT( 0 && "invalid ramp type" );
  }

  mStyle->addColorRamp( name, ramp.take(), true );
  mModified = true;
  return true;
}
示例#28
0
int makeGeometry(Box& a_domain,
                 Real& a_dx,
                 RealVect& a_origin,
                 int& a_upDir,
                 int& a_indepVar,
                 Real& a_startPt,
                 Real& a_slope)
{
    int eekflag =  0;
    //parse input file
    ParmParse pp;

    Vector<int> n_cell(SpaceDim);
    pp.getarr("n_cell",n_cell,0,SpaceDim);

    CH_assert(n_cell.size() == SpaceDim);
    IntVect lo = IntVect::Zero;
    IntVect hi;
    for (int ivec = 0; ivec < SpaceDim; ivec++)
    {
        if (n_cell[ivec] <= 0)
        {
            pout() << " bogus number of cells input = " << n_cell[ivec];
            return(-1);
        }
        hi[ivec] = n_cell[ivec] - 1;
    }

    a_domain.setSmall(lo);
    a_domain.setBig(hi);

    Vector<Real> prob_lo(SpaceDim, 1.0);
    Real prob_hi;
    pp.getarr("prob_lo",prob_lo,0,SpaceDim);
    pp.get("prob_hi",prob_hi);
    a_dx = (prob_hi-prob_lo[0])/n_cell[0];
    for (int idir = 0; idir < SpaceDim; idir++)
    {
        a_origin[idir] = prob_lo[idir];
    }
    pp.get("up_dir",a_upDir);
    a_upDir = SpaceDim-1;
    pp.get("indep_var",a_indepVar);
    pp.get("start_pt", a_startPt);
    pp.get("ramp_slope", a_slope);

    RealVect normal = RealVect::Zero;
    normal[a_upDir] = 1.0;
    normal[a_indepVar] = -a_slope;

    RealVect point = RealVect::Zero;
    point[a_upDir] = -a_slope*a_startPt;

    bool normalInside = true;

    PlaneIF ramp(normal,point,normalInside);

    RealVect vectDx = RealVect::Unit;
    vectDx *= a_dx;

    GeometryShop workshop(ramp,0,vectDx);
    //this generates the new EBIS
    EBIndexSpace* ebisPtr = Chombo_EBIS::instance();
    ebisPtr->define(a_domain, a_origin, a_dx, workshop);

    return eekflag;
}
示例#29
0
int makeGeometry(Box& a_domain)
{
  int eekflag =  0;
  //parse input file
  ParmParse pp;
  RealVect origin = RealVect::Zero;
  Vector<int> n_cell(SpaceDim);
  pp.getarr("n_cell",n_cell,0,SpaceDim);
  Real probhi;
  pp.get("prob_hi", probhi);
  Real dx = probhi/n_cell[0];

 CH_assert(n_cell.size() == SpaceDim);
  IntVect lo = IntVect::Zero;
  IntVect hi;
  for (int ivec = 0; ivec < SpaceDim; ivec++)
    {
      if (n_cell[ivec] <= 0)
        {
          pout() << " bogus number of cells input = " << n_cell[ivec];
          return(-1);
        }
      hi[ivec] = n_cell[ivec] - 1;
    }

  a_domain.setSmall(lo);
  a_domain.setBig(hi);

  int iverbose;
  pp.get("verbose", iverbose);
  bool verbose = (iverbose==1);

  int whichgeom;
  pp.get("which_geom",whichgeom);
  if (whichgeom == 0)
    {
      //allregular
      if (verbose)
        pout() << "all regular geometry" << endl;
      AllRegularService regserv;
      EBIndexSpace* ebisPtr = Chombo_EBIS::instance();
      ebisPtr->define(a_domain, origin, dx, regserv, 2048);
    }
  else if (whichgeom == 1)
    {
      if (verbose)
        pout() << "ramp geometry" << endl;
      int upDir;
      int indepVar;
      Real startPt;
      Real slope;
      pp.get("up_dir",upDir);
      pp.get("indep_var",indepVar);
      pp.get("start_pt", startPt);
      pp.get("ramp_slope", slope);

      RealVect normal = RealVect::Zero;
      normal[upDir] = 1.0;
      normal[indepVar] = -slope;

      RealVect point = RealVect::Zero;
      point[upDir] = -slope*startPt;

      bool normalInside = true;

      PlaneIF ramp(normal,point,normalInside);

      RealVect vectDx = RealVect::Unit;
      vectDx *= dx;

      GeometryShop workshop(ramp,0,vectDx);
      //this generates the new EBIS
      EBIndexSpace* ebisPtr = Chombo_EBIS::instance();
      ebisPtr->define(a_domain, origin, dx, workshop, 2048);
    }
  else if (whichgeom == 2)
    {
      if (verbose)
        pout() << "slab geometry" << endl;
      vector<int> slab_lo(SpaceDim);
      pp.getarr("slab_lo",slab_lo,0,SpaceDim);
      vector<int> slab_hi(SpaceDim);
      pp.getarr("slab_hi",slab_hi,0,SpaceDim);
      IntVect lo, hi;
      for (int idir = 0; idir < SpaceDim; idir++)
        {
          lo[idir] = slab_lo[idir];
          hi[idir] = slab_hi[idir];
        }
      Box coveredBox(lo,hi);
      SlabService slab(coveredBox);
      //this generates the new EBIS
      EBIndexSpace* ebisPtr = Chombo_EBIS::instance();
      RealVect origin = RealVect::Zero;
      ebisPtr->define(a_domain, origin, dx, slab,2048);
    }
  else
    {
      //bogus which_geom
      pout() << " bogus which_geom input = " << whichgeom;
      eekflag = 33;
    }
  return eekflag;
}
void QgsGraduatedSymbolRendererV2Widget::classifyGraduated()
{
  QString attrName = mExpressionWidget->currentField();

  int nclasses = spinGraduatedClasses->value();

  QSharedPointer<QgsVectorColorRampV2> ramp( cboGraduatedColorRamp->currentColorRamp() );
  if ( !ramp )
  {
    if ( cboGraduatedColorRamp->count() == 0 )
      QMessageBox::critical( this, tr( "Error" ), tr( "There are no available color ramps. You can add them in Style Manager." ) );
    else
      QMessageBox::critical( this, tr( "Error" ), tr( "The selected color ramp is not available." ) );
    return;
  }

  QgsGraduatedSymbolRendererV2::Mode mode;
  if ( cboGraduatedMode->currentIndex() == 0 )
    mode = QgsGraduatedSymbolRendererV2::EqualInterval;
  else if ( cboGraduatedMode->currentIndex() == 2 )
    mode = QgsGraduatedSymbolRendererV2::Jenks;
  else if ( cboGraduatedMode->currentIndex() == 3 )
    mode = QgsGraduatedSymbolRendererV2::StdDev;
  else if ( cboGraduatedMode->currentIndex() == 4 )
    mode = QgsGraduatedSymbolRendererV2::Pretty;
  else // default should be quantile for now
    mode = QgsGraduatedSymbolRendererV2::Quantile;

  // Jenks is n^2 complexity, warn for big dataset (more than 50k records)
  // and give the user the chance to cancel
  if ( QgsGraduatedSymbolRendererV2::Jenks == mode && mLayer->featureCount() > 50000 )
  {
    if ( QMessageBox::Cancel == QMessageBox::question( this, tr( "Warning" ), tr( "Natural break classification (Jenks) is O(n2) complexity, your classification may take a long time.\nPress cancel to abort breaks calculation or OK to continue." ), QMessageBox::Cancel, QMessageBox::Ok ) )
      return;
  }

  // create and set new renderer

  mRenderer->setClassAttribute( attrName );
  mRenderer->setMode( mode );

  if ( methodComboBox->currentIndex() == 0 )
  {
    QgsVectorColorRampV2* ramp = cboGraduatedColorRamp->currentColorRamp();

    if ( !ramp )
    {
      if ( cboGraduatedColorRamp->count() == 0 )
        QMessageBox::critical( this, tr( "Error" ), tr( "There are no available color ramps. You can add them in Style Manager." ) );
      else
        QMessageBox::critical( this, tr( "Error" ), tr( "The selected color ramp is not available." ) );
      return;
    }
    mRenderer->setSourceColorRamp( ramp );
  }
  else
  {
    mRenderer->setSourceColorRamp( nullptr );
  }

  QApplication::setOverrideCursor( Qt::WaitCursor );
  mRenderer->updateClasses( mLayer, mode, nclasses );

  if ( methodComboBox->currentIndex() == 1 )
    mRenderer->setSymbolSizes( minSizeSpinBox->value(), maxSizeSpinBox->value() );

  mRenderer->calculateLabelPrecision();
  QApplication::restoreOverrideCursor();
  // PrettyBreaks and StdDev calculation don't generate exact
  // number of classes - leave user interface unchanged for these
  updateUiFromRenderer( false );
}