コード例 #1
0
void	EuclideanDisplacementTest::testConvolve() {
	debug(LOG_DEBUG, DEBUG_LOG, 0, "testConvolve() begin");

	// read testimages/sun.fits
	std::string	name("testimages/orion1.fits");
	FITSinfile<unsigned short>	infile(name);
        Image<unsigned short>	*i = infile.read();
	ImagePtr	image(i);

	// create an adapter so that we see double values
	adapter::TypeConversionAdapter<unsigned short>	tconv(*i);

	// apply the convolution
	simpleconvolution	f;

	// create an image from the transform
	transform::EuclideanDisplacementConvolve<double>	ta(f, 1000);
	Image<double>	*result = ta(tconv);
	ImagePtr	r(result);

	// write the transformed image back to tmp/sun-displace.fits
	std::string	outname("tmp/orion-convolve.fits");
	FITSoutfile<double>       *outfile = new FITSoutfile<double>(outname);
        outfile->setPrecious(false);
        outfile->write(*result);
        delete outfile;
	debug(LOG_DEBUG, DEBUG_LOG, 0, "testConvolve() end");
}
Foam::tmp<Foam::volScalarField>
Foam::radiation::cloudAbsorptionEmission::aDisp(const label) const
{
    tmp<volScalarField> ta
    (
        new volScalarField
        (
            IOobject
            (
                "a",
                mesh_.time().timeName(),
                mesh_,
                IOobject::NO_READ,
                IOobject::NO_WRITE,
                false
            ),
            mesh_,
            dimensionedScalar("a", dimless/dimLength, 0.0)
        )
    );

    forAll(cloudNames_, i)
    {
        const thermoCloud& tc
        (
            mesh_.objectRegistry::lookupObject<thermoCloud>(cloudNames_[i])
        );

        ta() += tc.ap();
    }

    return ta;
}
コード例 #3
0
ファイル: main.cpp プロジェクト: smetzlaff/isptap
void isptap_main(Configuration *conf)
{
	if(!conf->getBool(CONF_DISP_INSTRUMENTATION))
	{
		if(conf->getInt(CONF_NUMBER_OF_CORES) == 1)
		{
			TimingAnalysis ta(conf, 0);

			if(ta.start())
			{
				LOG_INFO(logger, "Calculated estimate is " << ta.getEstimate() <<  " solution type: " << ta.getSolutionType());
			}
			else
			{
				LOG_ERROR(logger, "Could not calculate estimate. Something went wrong.");
			}

		}
		else
		{
			// tbd.
		}
	}
	else
	{
		// Instrumentator ins(conf);
		// ins.start();
		assert(false);
	}
}
コード例 #4
0
ファイル: triangle.cpp プロジェクト: nadult/Snail
void Triangle::Collide(SecondaryContext &ctx, int idx, int first, int last) const {
	Vec3q tnrm(plane.x, plane.y, plane.z);
	Vec3q ta(a), tca(ca), tba(ba);
	floatq zero(0.0f), one(1.0f), tit0(it0);

	int count = last - first + 1;
	for(int q = 0; q < count; q++) {
		int tq = q + first;

		const Vec3q dir = ctx.rayDir[tq];
		floatq idet = Inv(dir | tnrm);

		Vec3q tvec = ctx.rayOrigin[tq] - ta;
		floatq dist = -(tvec | tnrm) * idet;
		Vec3q tvec0 = tba ^ tvec;
		Vec3q tvec1 = tvec ^ tca;

		idet *= tit0;
		floatq v = (dir | tvec0) * idet;
		floatq u = (dir | tvec1) * idet;

		f32x4b test = Min(u, v) >= zero && u + v <= one;
		test = test && /*idet > zero &&*/ dist >= zero && dist < ctx.distance[tq];

		ctx.distance[tq] = Condition(test, dist, ctx.distance[tq]);
		ctx.normals[tq] = Condition(test, tnrm, ctx.normals[tq]);
		ctx.triIds[tq] = Condition(i32x4b(test), idx, ctx.triIds[tq]);
		ctx.barycentric[tq] = Condition(test, Vec2q(u, v), ctx.barycentric[tq]);
	}
}
コード例 #5
0
ファイル: TestCondGaussian.cpp プロジェクト: JacobCWard/PyPNL
void TestsPnlHigh::TestGetDiscreteParentValuesIndexes()
{
    printf("TestGetDiscreteParentValuesIndexes\n");

    BayesNet *net = SimpleCGM1();
    
    net->SetPGaussian("Cont1", "0.0", "2.5", "1.0 3.0", "Tab0^State0");
    net->SetPGaussian("Cont1", "-1.5", "0.75", "0.5 2.5", "Tab0^State1");
    
    WCondGaussianDistribFun *pCGDF = dynamic_cast<WCondGaussianDistribFun *>(net->m_pNet->m_paDistribution->Distribution(1));
    
    TokArr ta("Tab0^State0");
    Vector<int> dpInd = pCGDF->GetDiscreteParentValuesIndexes(ta);
    
    if (dpInd.size()!=1)
    {
	PNL_THROW(pnl::CAlgorithmicException, "Size of dpInd is wrong");
    };
    
    if (dpInd[0] != 0)
    {
	PNL_THROW(pnl::CAlgorithmicException, "GetDiscreteParentValuesIndexes works incorrectly");
    };
    
    TokArr ta2("Tab0^State1");
    dpInd = pCGDF->GetDiscreteParentValuesIndexes(ta2);
    
    if (dpInd[0] != 1)
    {
	PNL_THROW(pnl::CAlgorithmicException, "GetDiscreteParentValuesIndexes works incorrectly");
    };
    
    delete net;
};
コード例 #6
0
//
// Traverses the collection of Std Time Alignments for the current zone, looking for the one that 
// matches the given time.
// Returns a CTzDbStdTimeAlignment object.
//
CTzDbStdTimeAlignment* CTzDbZone::FindStdTimeAlignmentL(TInt aYear, TInt aMonth, TInt aDay, TInt aHour, TInt aMinute, const TTzTimeReference aTimeRef)
	{
	TTzStdTimeAlignment* ta(NULL);
	TTzStdTimeAlignment* prevTa(NULL);
	TInt taCount = iPersistedEntity.iNumberOfStdTimeAlignments;
	TBool found = EFalse;
	TInt tmpOffset = 0;
	for (TInt i = 0; (i < taCount) && (!found); i++)
		{
		prevTa = ta;
		tmpOffset = iPersistedEntity.iOffsetsToTimeAlignments[i];
		ta = const_cast<TTzStdTimeAlignment*>(&iReadOnlyTzDb.GetTStdTimeAlignment(tmpOffset));
		
		found = IsTimeInStdTimeAlignment(*ta,aYear,aMonth,aDay,aHour,aMinute,aTimeRef);
		}
		
	if (found)
		{
		return CTzDbStdTimeAlignment::NewL(iReadOnlyTzDb, *ta, prevTa);
		}
	else
		{
		return NULL;
		}
	}
コード例 #7
0
void FilterTurbulence::render_cairo(FilterSlot &slot)
{
    cairo_surface_t *input = slot.getcairo(_input);
    cairo_surface_t *out = ink_cairo_surface_create_same_size(input, CAIRO_CONTENT_COLOR_ALPHA);

    if (!gen->ready()) {
        Geom::Point ta(fTileX, fTileY);
        Geom::Point tb(fTileX + fTileWidth, fTileY + fTileHeight);
        gen->init(seed, Geom::Rect(ta, tb),
            Geom::Point(XbaseFrequency, YbaseFrequency), stitchTiles,
            type == TURBULENCE_FRACTALNOISE, numOctaves);
    }

    Geom::Affine unit_trans = slot.get_units().get_matrix_primitiveunits2pb().inverse();
    Geom::Rect slot_area = slot.get_slot_area();
    double x0 = slot_area.min()[Geom::X];
    double y0 = slot_area.min()[Geom::Y];

    ink_cairo_surface_synthesize(out, Turbulence(*gen, unit_trans, x0, y0));

    cairo_surface_mark_dirty(out);

    slot.set(_output, out);
    cairo_surface_destroy(out);
}
コード例 #8
0
void	EuclideanDisplacementTest::testInterpolate() {
	debug(LOG_DEBUG, DEBUG_LOG, 0, "testInterpolate() begin");

	// read testimages/sun.fits
	std::string	name("testimages/sun.fits");
	FITSinfile<RGB<unsigned char> >	infile(name);
        Image<RGB<unsigned char> >    *i = infile.read();
	ImagePtr	image(i);

	// apply the transformation
	Point	translation(1024 * (1 - sqrt(2)) / 2, 1024 / 2);
	transform::EuclideanDisplacement	d(M_PI / 4, translation);

	// create an image from the transform
	transform::InterpolatingEuclideanDisplacementAdapter<RGB<unsigned char> >	ta(*i, d);
	Image<RGB<unsigned char> >	*t = new Image<RGB<unsigned char> >(ta);
	ImagePtr	transformed(t);

	// write the transformed image back to tmp/sun-displace.fits
	std::string	outname("tmp/sun-interpolate.fits");
	FITSoutfile<RGB<unsigned char> >       *outfile
                = new FITSoutfile<RGB<unsigned char> >(outname);
        outfile->setPrecious(false);
        outfile->write(*t);
        delete outfile;
	debug(LOG_DEBUG, DEBUG_LOG, 0, "testInterpolate() end");
}
コード例 #9
0
ファイル: basic_spaceship.cpp プロジェクト: kamrann/workbase
	void basic_spaceship::activate_effectors(std::vector< double > const& activations)
	{
		agent_body::activate_effectors(activations);

		thruster_base::thruster_activation ta(activations.size());
		std::transform(begin(activations), end(activations), begin(ta), [](double d_act) {
			return d_act > 0.0;
		});

		for(size_t i = 0; i < m_t_cfg->num_thrusters(); ++i)
		{
			if(ta[i])
			{
				b2Vec2 pos = m_half_width * b2Vec2((*m_t_cfg)[i].pos[0], (*m_t_cfg)[i].pos[1]);
				b2Vec2 dir((*m_t_cfg)[i].dir[0], (*m_t_cfg)[i].dir[1]);
				apply_force_local(m_thruster_strength * dir, pos);

				m_t_system[i].t.engage();
			}
			else
			{
				m_t_system[i].t.cool_down(1.0f / 60.0f);	// TODO: Need to know internal system update frequency
			}
		}
	}
コード例 #10
0
ファイル: mlp.cpp プロジェクト: kamrann/workbase
	void mlp_spaceship_controller::update(phys_system::state& st, phys_system::scenario_data sdata)
	{
		std::vector< double > nn_inputs = map_nn_inputs(st);
		double* nn_outputs = nn.run((double*)&nn_inputs[0]);
		thruster_base::thruster_activation ta(num_nn_outputs, false);
		std::transform(nn_outputs, nn_outputs + num_nn_outputs, ta.begin(), [](double d_act) {
			return d_act > 0.0;
		});

		basic_spaceship* ss = static_cast< basic_spaceship* >(st.body.get());
		float const ThrusterForce = 100.0f;	// TODO: Property of the ship/thrusters

		for(size_t i = 0; i < ss->m_t_cfg->num_thrusters(); ++i)
		{
			if(ta[i])
			{
				b2Vec2 pos = ss->m_half_width * b2Vec2((*ss->m_t_cfg)[i].pos[0], (*ss->m_t_cfg)[i].pos[1]);
				b2Vec2 dir((*ss->m_t_cfg)[i].dir[0], (*ss->m_t_cfg)[i].dir[1]);
				ss->apply_force_local(ThrusterForce * dir, pos);

				ss->m_t_system[i].t.engage();
			}
			else
			{
				ss->m_t_system[i].t.cool_down(1.0f / 60.0f);	// TODO: Hard copied from phys_system::update()
			}
		}
	}
コード例 #11
0
ファイル: MultiColvarBase.cpp プロジェクト: whitead/plumed2
vesselbase::StoreDataVessel* MultiColvarBase::buildDataStashes( const bool& allow_wcutoff, const double& wtol ){
  // Check if vessels have already been setup
  for(unsigned i=0;i<getNumberOfVessels();++i){
     StoreColvarVessel* ssc=dynamic_cast<StoreColvarVessel*>( getPntrToVessel(i) );
     if(ssc){
        if( allow_wcutoff && !ssc->weightCutoffIsOn() ) error("Cannot have more than one data stash with different properties");
        if( !allow_wcutoff && ssc->weightCutoffIsOn() ) error("Cannot have more than one data stash with different properties");
        return ssc;
     }
  }
 
  // Setup central atoms
  vesselbase::VesselOptions da("","",0,"",this);
  mycatoms=new StoreCentralAtomsVessel(da);
  if( allow_wcutoff ) mycatoms->setHardCutoffOnWeight( wtol );
  addVessel(mycatoms); 

  // Setup store values vessel
  vesselbase::VesselOptions ta("","",0,"",this);
  myvalues=new StoreColvarVessel(ta);   
  if( allow_wcutoff ) myvalues->setHardCutoffOnWeight( wtol );
  addVessel(myvalues);

  // Make sure resizing of vessels is done
  resizeFunctions();
  return myvalues;
}
コード例 #12
0
ファイル: normest.hpp プロジェクト: timblechmann/nt2
 static S trans(const S& a)
 {
   S ta = zeros(width(a), height(a), meta::as_<value_type>());
   for (size_t i = 1; i <= height(a); ++i)
     for (size_t j = 1; j <= width(a); ++j)
       ta(j, i) = a(i, j);
   return ta;
 }
コード例 #13
0
ファイル: xAlgebra.cpp プロジェクト: wolftype/versor
int main(){


  static_assert(std::is_same<ega::types::vector::basis, typename vsr::blade<3,1>::type >::value, "ega3d vector basis");
  static_assert(std::is_same<ega::types::bivector::basis, typename vsr::blade<3,2>::type >::value, "ega3d bivector basis");


  printf("some euclidean 3D types\n");

  printf("vector\n");
  ega::types::vector::basis::print();
  printf("bivector\n");
  ega::types::bivector::basis::print();
  printf("trivector\n");
  ega::types::trivector::basis::print();
  printf("rotor\n");
  ega::types::rotor::basis::print();

  printf("some spacetime 4D types\n");

  printf("vector\n");
  sta::make_grade<1>::basis::print();

  printf("some combinatorics: product of rotors a and b in euclidean algebra: \n");
  ega::impl::gp_arrow_t< ega::types::rotor::basis, ega::types::rotor::basis >::Arrow::print();
  printf("some combinatorics: product of vectors a and b in space time algebra: \n");
  sta::impl::gp_arrow_t< sta::make_grade<1>::basis, sta::make_grade<1>::basis >::Arrow::print();
  printf("some combinatorics: product of vectors a and b in euclidean 4d algebra: \n");
  vsr::euclidean<4>::impl::gp_arrow_t< sta::make_grade<1>::basis, sta::make_grade<1>::basis >::Arrow::print();
  printf("some combinatorics: product of bivectors a and b in twistor algebra: \n");
  twistor::impl::gp_arrow_t< sta::make_grade<2>::basis, sta::make_grade<2>::basis >::Arrow::print();

  printf("some conformal 3D types\n");
  
  printf("point\n");
  cga::types::point::basis::print();
  printf("pair\n");
  cga::types::pair::basis::print();
  printf("circle\n");
  cga::types::circle::basis::print();
  printf("sphere\n");
  cga::types::sphere::basis::print();

  
  complex_t<double> ta( 1.0, 2.5 );
  complex_t<double> tb( 2.0, 3.0 );

  c2 a(ta,tb);
  //c2 b( ta, tb );//1.2, 3.2 );

//  std::cout << ega::types::vector(1,2,3) << std::endl;
  a.print();

  (a*a).print();

  return 0;

}
コード例 #14
0
ファイル: station.cpp プロジェクト: koreapyj/openttd-yacd
/**
 * Check whether station tiles of the given station id exist in the given rectangle
 * @param st_id    Station ID to look for in the rectangle
 * @param left_a   Minimal tile X edge of the rectangle
 * @param top_a    Minimal tile Y edge of the rectangle
 * @param right_a  Maximal tile X edge of the rectangle (inclusive)
 * @param bottom_a Maximal tile Y edge of the rectangle (inclusive)
 * @return \c true if a station tile with the given \a st_id exists in the rectangle, \c false otherwise
 */
/* static */ bool StationRect::ScanForStationTiles(StationID st_id, int left_a, int top_a, int right_a, int bottom_a)
{
	TileArea ta(TileXY(left_a, top_a), TileXY(right_a, bottom_a));
	TILE_AREA_LOOP(tile, ta) {
		if (IsTileType(tile, MP_STATION) && GetStationIndex(tile) == st_id) return true;
	}

	return false;
}
コード例 #15
0
int main(int argc, char** argv)
{
    ros::init(argc, argv, "simple_task_planner");
    ros::NodeHandle nodeHandler("simple_task_planner");

    TaskAdvertiser ta(nodeHandler);

    ros::spin();
}
コード例 #16
0
void
DemoReplayGlue::Start()
{
  ProtectedTaskManager::ExclusiveLease task_manager(*m_task_manager);
  ProtectedTaskAccessor ta(task_manager, fixed_zero);
  parms.realistic();
  parms.start_alt = device_blackboard->Basic().nav_altitude;
  DemoReplay::Start(ta, device_blackboard->Basic().location);

  // get wind from aircraft
  aircraft.GetState().wind = device_blackboard->Calculated().GetWindOrZero();
}
コード例 #17
0
ファイル: entity.cpp プロジェクト: Kentzo/mazecompositor
void Entity::render(const Map &map, const Camera &camera) const
{
    m_program->bind();

    m_program->setUniformValue(m_matrixUniform, camera.viewProjectionMatrix());

    QVector3D up(0, 0.65 * m_scale, 0);

    QVector3D va = m_a;
    QVector3D vb = m_a + up;
    QVector3D vc = m_b + up;
    QVector3D vd = m_b;

    qreal dx = 1. / m_textureSize.width();
    qreal dy = 1. / m_textureSize.height();

    int index = m_angleIndex;
    if (m_walking)
        index += 8 + 8 * (m_animationIndex % 4);

    qreal tx1 = (m_tileWidth * (index % m_tileMod) + 1) * dx;
    qreal tx2 = tx1 + (m_tileWidth - 2) * dx;
    qreal ty1 = (m_tileHeight * (index / m_tileMod) + 1) * dy;
    qreal ty2 = ty1 + (m_tileHeight - 2) * dy;

    QVector2D ta(tx2, ty2);
    QVector2D tb(tx2, ty1);
    QVector2D tc(tx1, ty1);
    QVector2D td(tx1, ty2);

    QVector<QVector3D> vertexBuffer;
    vertexBuffer << va << vb << vd << vd << vb << vc;
    QVector<QVector3D> texBuffer;
    texBuffer << ta << tb << td << td << tb << tc;

    m_program->enableAttributeArray(m_vertexAttr);
    m_program->setAttributeArray(m_vertexAttr, vertexBuffer.constData());
    m_program->enableAttributeArray(m_texAttr);
    m_program->setAttributeArray(m_texAttr, texBuffer.constData());

    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, m_texture);

    glDrawArrays(GL_TRIANGLES, 0, 6);

    glDisable(GL_BLEND);

    m_program->disableAttributeArray(m_texAttr);
    m_program->disableAttributeArray(m_vertexAttr);
}
コード例 #18
0
ファイル: get_TrieArray.C プロジェクト: FRED-2/ImmunoNodes
int main(int argc, char** argv)
{
	if (argc < 4)
	{
		std::cout << "Usage: get_TrieArray <fastafile> <matrix> <peptideLength> <outfile> " << std::endl;
		return -1;
	}

	string fastafile(argv[1]);
	string matrix(argv[2]);
	cout << "test" << endl;
	int peptideLength(atoi(argv[3]));
	string outname(argv[4]);

	
	//std::cout << fastafile << "\t" << outname << std::endl;
		
//----------------------------------------------------------------------------------------
	cout << "Reading FASTA file..." << endl;

	Sequences s(fastafile);
	cout << "Read " << s.size() << " sequences." << endl;

	cout << "Generating peptides..." << endl;
	Sequences ninemers;
	generateAllSubstrings(ninemers, s, peptideLength);
	cout << "Generated " << ninemers.size() << " peptides." << endl;

	s.clear();


  	//Matrix m("/abi-projects/dist2self/matrices/BLOSUM45_distance_normal.dat"); cout << "Initializing trie. " << endl; Trie t; 
  	Matrix m(matrix); cout << "Initializing trie. " << endl; Trie t;
	Matrix::IndexSequence indices; 
  	for (size_t i = 0; i < ninemers.size(); ++i) {
 
  	 m.translate(ninemers[i], indices); t.add(indices);
  	} 
    t.dump();


	cout << "Converting to trie array." << endl;
  	TrieArray ta(t, peptideLength);

	cout << "Done." << endl;

//	std::ofstream ofs("test.trie");
	std::ofstream ofs(outname.c_str());
	boost::archive::text_oarchive oa(ofs);
	ta.save(oa,1);


}
コード例 #19
0
/** Scenario editor command that generates desert areas */
static void GenerateDesertArea(TileIndex end, TileIndex start)
{
	if (_game_mode != GM_EDITOR) return;

	_generating_world = true;

	TileArea ta(start, end);
	TILE_AREA_LOOP(tile, ta) {
		SetTropicZone(tile, (_ctrl_pressed) ? TROPICZONE_NORMAL : TROPICZONE_DESERT);
		DoCommandP(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
		MarkTileDirtyByTile(tile);
	}
コード例 #20
0
/**
 * Build a piece of canal.
 * @param tile end tile of stretch-dragging
 * @param flags type of operation
 * @param p1 start tile of stretch-dragging
 * @param p2 waterclass to build. sea and river can only be built in scenario editor
 * @param text unused
 * @return the cost of this operation or an error
 */
CommandCost CmdBuildCanal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
	WaterClass wc = Extract<WaterClass, 0, 2>(p2);
	if (p1 >= MapSize() || wc == WATER_CLASS_INVALID) return CMD_ERROR;

	/* Outside of the editor you can only build canals, not oceans */
	if (wc != WATER_CLASS_CANAL && _game_mode != GM_EDITOR) return CMD_ERROR;

	TileArea ta(tile, p1);

	/* Outside the editor you can only drag canals, and not areas */
	if (_game_mode != GM_EDITOR && ta.w != 1 && ta.h != 1) return CMD_ERROR;

	CommandCost cost(EXPENSES_CONSTRUCTION);
	TILE_AREA_LOOP(tile, ta) {
		CommandCost ret;

		Slope slope = GetTileSlope(tile, NULL);
		if (slope != SLOPE_FLAT && (wc != WATER_CLASS_RIVER || !IsInclinedSlope(slope))) {
			return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
		}

		/* can't make water of water! */
		if (IsTileType(tile, MP_WATER) && (!IsTileOwner(tile, OWNER_WATER) || wc == WATER_CLASS_SEA)) continue;

		ret = DoCommand(tile, 0, 0, flags | DC_FORCE_CLEAR_TILE, CMD_LANDSCAPE_CLEAR);
		if (ret.Failed()) return ret;
		cost.AddCost(ret);

		if (flags & DC_EXEC) {
			switch (wc) {
				case WATER_CLASS_RIVER:
					MakeRiver(tile, Random());
					break;

				case WATER_CLASS_SEA:
					if (TileHeight(tile) == 0) {
						MakeSea(tile);
						break;
					}
					/* FALL THROUGH */

				default:
					MakeCanal(tile, _current_company, Random());
					break;
			}
			MarkTileDirtyByTile(tile);
			MarkCanalsAndRiversAroundDirty(tile);
		}

		cost.AddCost(_price[PR_BUILD_CANAL]);
	}
コード例 #21
0
ファイル: node.cpp プロジェクト: a-pavlov/libed2k
void node_impl::search_keywords(node_id const& info_hash, int listen_port
  , boost::function<void(kad_id const&)> f)
{
#ifdef LIBED2K_DHT_VERBOSE_LOGGING
    LIBED2K_LOG(node) << "search keywords [ ih: " << info_hash << " p: " << listen_port << " ]";
#endif
    // search for nodes with ids close to id or with peers
    // for info-hash id. then send announce_peer to them.
    boost::intrusive_ptr<find_data> ta(new find_data(*this, info_hash, f
    , boost::bind(&search_keywords_fun, _1, boost::ref(*this)
        , listen_port, info_hash), KADEMLIA_FIND_VALUE));
    ta->start();
}
コード例 #22
0
ファイル: x_pigpiod_if2.c プロジェクト: SlySven/pigpio
int main(int argc, char *argv[])
{
   int i, t, c, pi;

   char test[64];

   if (argc > 1)
   {
      t = 0;

      for (i=0; i<strlen(argv[1]); i++)
      {
         c = tolower(argv[1][i]);

         if (!strchr(test, c))
         {
            test[t++] = c;
            test[t] = 0;
         }
      }
   }
   else strcat(test, "0123456789");

   pi = pigpio_start(0, 0);

   if (pi < 0)
   {
      fprintf(stderr, "pigpio initialisation failed (%d).\n", pi);
      return 1;
   }

   printf("Connected to pigpio daemon (%d).\n", pi);

   if (strchr(test, '0')) t0(pi);
   if (strchr(test, '1')) t1(pi);
   if (strchr(test, '2')) t2(pi);
   if (strchr(test, '3')) t3(pi);
   if (strchr(test, '4')) t4(pi);
   if (strchr(test, '5')) t5(pi);
   if (strchr(test, '6')) t6(pi);
   if (strchr(test, '7')) t7(pi);
   if (strchr(test, '8')) t8(pi);
   if (strchr(test, '9')) t9(pi);
   if (strchr(test, 'a')) ta(pi);
   if (strchr(test, 'b')) tb(pi);
   if (strchr(test, 'c')) tc(pi);

   pigpio_stop(pi);

   return 0;
}
コード例 #23
0
ファイル: random_model.cpp プロジェクト: gabrielwu/v2v
void RandomModel::antennasProduce() {
    Direction tad(0,0,1);
	Direction tarp(0,0,0);
	Direction taPolar(sqrt(double(2))/2, 0, sqrt(double(2))/2);
	Antenna ta(tad, tarp, taPolar, 10);
	this->tAntennas.push_back(ta);

	Direction rad(0,0,1);
	Direction rarp(0,0,0);
	Direction raVPolar(1, 0, 0);
	Direction raHPolar(0, 0, 1);
	Antenna ra(rad, rarp, raVPolar, raHPolar);
	this->rAntennas.push_back(ra);
}
コード例 #24
0
TEST_F(TaskAssignmentTest, Constructor) {
	fs::TaskAssignment ta(*original);

	const std::unordered_set<uint32_t> &tasks = ta.getTasks();
	std::unordered_set<uint32_t> expected_tasks = {2,3,4,5,6,7};
	EXPECT_EQ(expected_tasks, tasks);

	const std::unordered_set<uint32_t> &leaves = ta.getLeaves();
	std::unordered_set<uint32_t> expected_leaves = {
			8, // unscheduled aggregator
			16,17,18,19,20,21,22,23 // cores
	};
	EXPECT_EQ(expected_leaves, leaves);
}
コード例 #25
0
void test_create() {
  char * cwd0 = util_alloc_cwd();
  char * cwd1;
  {
    ERT::TestArea ta("test/area");
    cwd1 = util_alloc_cwd();
    test_assert_string_not_equal( cwd0 , cwd1 );
    test_assert_string_equal( cwd1 , ta.getCwd().c_str());
    test_assert_string_equal( cwd0 , ta.getOriginalCwd( ).c_str() );
  }
  test_assert_false( util_is_directory(cwd1) );
  free( cwd1 );
  free( cwd0 );
}
コード例 #26
0
TEST_F(TaskAssignmentTest, Assignments) {
	fs::TaskAssignment ta(*original);

	std::unordered_map<uint32_t, uint32_t> *assignments;
	assignments = ta.getAssignments(*augmented);

	std::unordered_map<uint32_t, uint32_t> expected_assignments = {
			{ 2, 16 },
			{ 3, 18 },
			{ 4, 20 },
			{ 5, 23 },
			{ 6, 22 },
			{ 7, 17 }
	};

	EXPECT_EQ(expected_assignments, *assignments);
	delete assignments;
}
コード例 #27
0
bool HAvTransportAdapterPrivate::getCurrentTransportActions(
    HClientAction*, const HClientActionOp& op)
{
    H_Q(HAvTransportAdapter);

    QSet<HTransportAction> actions;
    if (op.returnValue() == UpnpSuccess)
    {
        QStringList slist = op.outputArguments().value("Actions").toString().split(",");

        foreach(const QString& action, slist)
        {
            HTransportAction ta(action);
            if (ta.isValid())
            {
                actions.insert(ta);
            }
        }
コード例 #28
0
ファイル: inRange.cpp プロジェクト: CESNET/libfastbit
/// Generate some records.  Use ibis::tablex interface and
/// ibis::table::row.  The integer records go from 1 to 16, with the value
/// J repeated J times.
void tester::builtindata(const char *datadir) {
    ibis::table::row irow;
    std::auto_ptr<ibis::tablex> ta(ibis::tablex::create());

    ta->addColumn("l", ibis::LONG);

    irow.longsnames.push_back("l");
    irow.longsvalues.resize(1);
    for (int j = 1; j < 16; ++ j) {
	irow.longsvalues.back() = j;
	for (int i = 0; i < j; ++ i)
	    ta->appendRow(irow);
    }

    ta->write(datadir);
    LOGGER(ibis::gVerbose > 0)
	<< "generated " << ta->mRows() << " rows in directory " << datadir;
}
コード例 #29
0
/**
 * Actually build the object.
 * @param type  The type of object to build.
 * @param tile  The tile to build the northern tile of the object on.
 * @param owner The owner of the object.
 * @param town  Town the tile is related with.
 * @param view  The view for the object.
 * @pre All preconditions for building the object at that location
 *      are met, e.g. slope and clearness of tiles are checked.
 */
void BuildObject(ObjectType type, TileIndex tile, CompanyID owner, Town *town, uint8 view)
{
	const ObjectSpec *spec = ObjectSpec::Get(type);

	TileArea ta(tile, GB(spec->size, HasBit(view, 0) ? 4 : 0, 4), GB(spec->size, HasBit(view, 0) ? 0 : 4, 4));
	Object *o = new Object();
	o->type          = type;
	o->location      = ta;
	o->town          = town == NULL ? CalcClosestTownFromTile(tile) : town;
	o->build_date    = _date;
	o->view          = view;

	/* If nothing owns the object, the colour will be random. Otherwise
	 * get the colour from the company's livery settings. */
	if (owner == OWNER_NONE) {
		o->colour = Random();
	} else {
		const Livery *l = Company::Get(owner)->livery;
		o->colour = l->colour1 + l->colour2 * 16;
	}

	/* If the object wants only one colour, then give it that colour. */
	if ((spec->flags & OBJECT_FLAG_2CC_COLOUR) == 0) o->colour &= 0xF;

	if (HasBit(spec->callback_mask, CBM_OBJ_COLOUR)) {
		uint16 res = GetObjectCallback(CBID_OBJECT_COLOUR, o->colour, 0, spec, o, tile);
		if (res != CALLBACK_FAILED) {
			if (res >= 0x100) ErrorUnknownCallbackResult(spec->grf_prop.grffile->grfid, CBID_OBJECT_COLOUR, res);
			o->colour = GB(res, 0, 8);
		}
	}

	assert(o->town != NULL);

	TILE_AREA_LOOP(t, ta) {
		WaterClass wc = (IsWaterTile(t) ? GetWaterClass(t) : WATER_CLASS_INVALID);
		/* Update company infrastructure counts for objects build on canals owned by nobody. */
		if (wc == WATER_CLASS_CANAL && owner != OWNER_NONE && (IsTileOwner(tile, OWNER_NONE) || IsTileOwner(tile, OWNER_WATER))) {
			Company::Get(owner)->infrastructure.water++;
			DirtyCompanyInfrastructureWindows(owner);
		}
		MakeObject(t, owner, o->index, wc, Random());
		MarkTileDirtyByTile(t);
	}
コード例 #30
0
ファイル: water_cmd.cpp プロジェクト: Voxar/OpenTTD
/** Build a piece of canal.
 * @param tile end tile of stretch-dragging
 * @param flags type of operation
 * @param p1 start tile of stretch-dragging
 * @param p2 specifies canal (0), water (1) or river (2); last two can only be built in scenario editor
 * @param text unused
 * @return the cost of this operation or an error
 */
CommandCost CmdBuildCanal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
	CommandCost cost(EXPENSES_CONSTRUCTION);

	if (p1 >= MapSize()) return CMD_ERROR;

	/* Outside of the editor you can only build canals, not oceans */
	if (p2 != 0 && _game_mode != GM_EDITOR) return CMD_ERROR;

	TileArea ta(tile, p1);

	/* Outside the editor you can only drag canals, and not areas */
	if (_game_mode != GM_EDITOR && ta.w != 1 && ta.h != 1) return CMD_ERROR;

	TILE_AREA_LOOP(tile, ta) {
		CommandCost ret;

		Slope slope = GetTileSlope(tile, NULL);
		if (slope != SLOPE_FLAT && (p2 != 2 || !IsInclinedSlope(slope))) {
			return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
		}

		/* can't make water of water! */
		if (IsTileType(tile, MP_WATER) && (!IsTileOwner(tile, OWNER_WATER) || p2 == 1)) continue;

		ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
		if (CmdFailed(ret)) return ret;
		cost.AddCost(ret);

		if (flags & DC_EXEC) {
			if (TileHeight(tile) == 0 && p2 == 1) {
				MakeSea(tile);
			} else if (p2 == 2) {
				MakeRiver(tile, Random());
			} else {
				MakeCanal(tile, _current_company, Random());
			}
			MarkTileDirtyByTile(tile);
			MarkCanalsAndRiversAroundDirty(tile);
		}

		cost.AddCost(_price[PR_CLEAR_WATER]);
	}