Пример #1
0
void CJabberProto::GetAvatarFileName(MCONTACT hContact, TCHAR* pszDest, size_t cbLen)
{
	int tPathLen = mir_sntprintf(pszDest, cbLen, _T("%s\\%S"), VARST(_T("%miranda_avatarcache%")), m_szModuleName);

	DWORD dwAttributes = GetFileAttributes(pszDest);
	if (dwAttributes == 0xffffffff || (dwAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
		CreateDirectoryTreeT(pszDest);

	pszDest[ tPathLen++ ] = '\\';

	const TCHAR* szFileType = ProtoGetAvatarExtension( getByte(hContact, "AvatarType", PA_FORMAT_PNG));

	if (hContact != NULL) {
		char str[ 256 ];
		DBVARIANT dbv;
		if (!db_get_utf(hContact, m_szModuleName, "jid", &dbv)) {
			strncpy_s(str, dbv.pszVal, _TRUNCATE);
			str[ sizeof(str)-1 ] = 0;
			db_free(&dbv);
		}
		else _i64toa((LONG_PTR)hContact, str, 10);
		mir_sntprintf(pszDest + tPathLen, MAX_PATH - tPathLen, _T("%S%s"), ptrA(JabberSha1(str)), szFileType);
	}
	else if (m_ThreadInfo != NULL) {
		mir_sntprintf(pszDest + tPathLen, MAX_PATH - tPathLen, _T("%s@%S avatar%s"),
			m_ThreadInfo->conn.username, m_ThreadInfo->conn.server, szFileType);
	}
	else {
		ptrA res1( getStringA("LoginName")), res2( getStringA("LoginServer"));
		mir_sntprintf(pszDest + tPathLen, MAX_PATH - tPathLen, _T("%S@%S avatar%s"),
			(res1) ? (LPSTR)res1 : "noname", (res2) ? (LPSTR)res2 : m_szModuleName, szFileType);
	}
}
TEST( ResourceDependenciesGraph, removingFile )
{
   ResourceDependenciesGraph graph;

   FilePath file( "a.res" );
   FilePath res1( "b.tmat" );
   FilePath res2( "c.tmat" );
   graph.addDependency( file, res1 );
   graph.addDependency( file, res2 );

   CPPUNIT_ASSERT_EQUAL( ( uint ) 2, graph.getAffectedResources( file ).size() );

   graph.onFileRemoved( res1 );
   CPPUNIT_ASSERT_EQUAL( ( uint ) 1, graph.getAffectedResources( file ).size() );

   graph.onFileRemoved( res2 );
   CPPUNIT_ASSERT_EQUAL( ( uint ) 0, graph.getAffectedResources( file ).size() );

   graph.addDependency( file, res1 );
   graph.addDependency( file, res2 );
   CPPUNIT_ASSERT_EQUAL( ( uint ) 2, graph.getAffectedResources( file ).size() );

   graph.onFileRemoved( file );
   CPPUNIT_ASSERT_EQUAL( ( uint ) 0, graph.getAffectedResources( file ).size() );
}
TEST( ResourceDependenciesGraph, removingDir )
{
   ResourceDependenciesGraph graph;

   FilePath file( "/directory1/a.res" );
   FilePath res1( "/directory2/b.tmat" );
   FilePath res2( "/directory3/c.tmat" );
   FilePath dir1( "/directory1" );
   FilePath dir2( "/directory2" );
   FilePath dir3( "/directory3" );
   graph.addDependency( file, res1 );
   graph.addDependency( file, res2 );

   CPPUNIT_ASSERT_EQUAL( ( uint ) 2, graph.getAffectedResources( file ).size() );

   graph.onDirRemoved( dir2 );
   CPPUNIT_ASSERT_EQUAL( ( uint ) 1, graph.getAffectedResources( file ).size() );
   CPPUNIT_ASSERT_EQUAL( res2.getRelativePath(), graph.getAffectedResources( file ).front().getRelativePath() );

   graph.onDirRemoved( dir3 );
   CPPUNIT_ASSERT_EQUAL( ( uint ) 0, graph.getAffectedResources( file ).size() );

   graph.addDependency( file, res1 );
   graph.addDependency( file, res2 );
   CPPUNIT_ASSERT_EQUAL( ( uint ) 2, graph.getAffectedResources( file ).size() );

   graph.onDirRemoved( dir1 );
   CPPUNIT_ASSERT_EQUAL( ( uint ) 0, graph.getAffectedResources( file ).size() );
}
Пример #4
0
int main(int argc, char *argv[])
{
    //embed fonts
    QFile res1(":/fonts/bell-gothic-black.ttf");
    if (res1.open(QIODevice::ReadOnly))
    {
        QFontDatabase::addApplicationFontFromData(res1.readAll());
    }
    QFile res2(":/fonts/bell-gothic-bold.ttf");
    if (res2.open(QIODevice::ReadOnly))
    {
        QFontDatabase::addApplicationFontFromData(res2.readAll());
    }
    QFile res3(":/fonts/bell-gothic-light.ttf");
    if (res3.open(QIODevice::ReadOnly))
    {
        QFontDatabase::addApplicationFontFromData(res3.readAll());
    }

    QApplication a(argc, argv);

    MainWindow w;
    w.show();

    return a.exec();
}
int btPersistentManifold::sortCachedPoints(const btManifoldPoint& pt) 
{

		//calculate 4 possible cases areas, and take biggest area
		//also need to keep 'deepest'
		
		int maxPenetrationIndex = -1;
#define KEEP_DEEPEST_POINT 1
#ifdef KEEP_DEEPEST_POINT
		btScalar maxPenetration = pt.getDistance();
		for (int i=0;i<4;i++)
		{
			if (m_pointCache[i].getDistance() < maxPenetration)
			{
				maxPenetrationIndex = i;
				maxPenetration = m_pointCache[i].getDistance();
			}
		}
#endif //KEEP_DEEPEST_POINT
		
		btScalar res0(btScalar(0.)),res1(btScalar(0.)),res2(btScalar(0.)),res3(btScalar(0.));
		if (maxPenetrationIndex != 0)
		{
			btVector3 a0 = pt.m_localPointA-m_pointCache[1].m_localPointA;
			btVector3 b0 = m_pointCache[3].m_localPointA-m_pointCache[2].m_localPointA;
			btVector3 cross = a0.cross(b0);
			res0 = cross.length2();
		}
		if (maxPenetrationIndex != 1)
		{
			btVector3 a1 = pt.m_localPointA-m_pointCache[0].m_localPointA;
			btVector3 b1 = m_pointCache[3].m_localPointA-m_pointCache[2].m_localPointA;
			btVector3 cross = a1.cross(b1);
			res1 = cross.length2();
		}

		if (maxPenetrationIndex != 2)
		{
			btVector3 a2 = pt.m_localPointA-m_pointCache[0].m_localPointA;
			btVector3 b2 = m_pointCache[3].m_localPointA-m_pointCache[1].m_localPointA;
			btVector3 cross = a2.cross(b2);
			res2 = cross.length2();
		}

		if (maxPenetrationIndex != 3)
		{
			btVector3 a3 = pt.m_localPointA-m_pointCache[0].m_localPointA;
			btVector3 b3 = m_pointCache[2].m_localPointA-m_pointCache[1].m_localPointA;
			btVector3 cross = a3.cross(b3);
			res3 = cross.length2();
		}

		btVector4 maxvec(res0,res1,res2,res3);
		int biggestarea = maxvec.closestAxis4();
		return biggestarea;
}
Пример #6
0
void test_verify_1()
{
  cout << "Verify Test 1" << endl;
  vector<int> res1 (100);
  vector<int> res2 (100);
  cout << "res1 == res2: " << TestEnvironment::verify(res1, res2) << endl;
  vector<int> res3 (50);
  vector<int> res4 (100);
  cout << "res3 == res4: " << TestEnvironment::verify(res3, res4) << endl;
  cout << endl;
}
TEST( ResourceDependenciesGraph, basics )
{
   ResourceDependenciesGraph graph;

   FilePath res1( "a.res" );
   FilePath res2( "b.res" );
   graph.addDependency( res1, res2 );

   CPPUNIT_ASSERT_EQUAL( ( uint ) 1, graph.getAffectedResources( res1 ).size() );
   CPPUNIT_ASSERT_EQUAL( ( uint ) 0, graph.getAffectedResources( res2 ).size() );
}
Пример #8
0
/**
 * \fn Numerique Numerique::operator>(const Numerique& n)
 * \brief Operateur >
 */
Numerique Numerique::operator>(const Numerique& n)
{
    double temp1=(double)numReel/(double)denomReel;
    double temp2=(double)n.numReel/(double)n.denomReel;
    if (temp1 > temp2)
    {
        Numerique res1(1,"entier");
        return res1;
    }
    else
    {
        Numerique res0(0,"entier");
        return res0;
    }
}
Пример #9
0
/**
 * \fn Numerique Numerique::operator==(const Numerique& n)
 * \brief Operateur ==
 */
Numerique Numerique::operator==(const Numerique& n)
{

    if (numReel==n.numReel && denomReel==n.denomReel && numIm==n.numIm && denomIm==n.denomIm)
    {
        Numerique res1(1,"entier");
        return res1;
    }
    else
    {
        Numerique res0(0,"entier");
        return res0;
    }

}
Пример #10
0
/**
 * \fn Numerique Numerique::operator!=(const Numerique& n)
 * \brief Operateur !=
 */
Numerique Numerique::operator!=(const Numerique& n)
{

    if (numReel!=n.numReel || denomReel!=n.denomReel || numIm!=n.numIm || denomIm!=n.denomIm)
    {
        Numerique res1(1,"entier");
        return res1;
    }
    else
    {
        Numerique res0(0,"entier");
        return res0;
    }

}
Пример #11
0
int main(int argc, char *argv[])
{
    //embed fonts
    QFile res1(":/fonts/bell-gothic-black.ttf");
    if (res1.open(QIODevice::ReadOnly))
    {
        QFontDatabase::addApplicationFontFromData(res1.readAll());
    }
    QFile res2(":/fonts/bell-gothic-bold.ttf");
    if (res2.open(QIODevice::ReadOnly))
    {
        QFontDatabase::addApplicationFontFromData(res2.readAll());
    }
    QFile res3(":/fonts/bell-gothic-light.ttf");
    if (res3.open(QIODevice::ReadOnly))
    {
        QFontDatabase::addApplicationFontFromData(res3.readAll());
    }

    bool quiet = false;

    QApplication a(argc, argv);

    #ifdef Q_OS_WIN
        if (argc>1)
        {
            QString arg1 = argv[1];
            qDebug() << arg1;
            if (arg1 == "-q" || arg1 == "-quiet" || arg1 == "-s" || arg1 == "-silent")
            {
                quiet = true;

                QuietInstaller qi = QuietInstaller();
            }
            else
            {
                qWarning() << "Unknown argument";
            }
        }
    #endif

    MainWindow w;
    w.show();

    return a.exec();
}
Пример #12
0
void If::execute(void* result, Tree &tree)
{
	std::vector<bool>& res = *(std::vector<bool>*)result;
		uint size = (uint) res.size();

		std::vector<bool> arg(size), res1(size), res2(size);
		getNextArgument(&arg, tree);
		getNextArgument(&res1, tree);
		getNextArgument(&res2, tree);

		for(uint i = 0; i < size; i++)
			if(arg[i]) {
				res[i] = res1[i];
			} else {
				res[i] = res2[i];
			}
}
Пример #13
0
 double ComposeCoefficientFunction::Evaluate (const BaseMappedIntegrationPoint & ip) const
 {
   IntegrationPoint outip;
   Vector<> res1(c1->Dimension());
   c1->Evaluate(ip, res1);
   if (ma)
   {
     LocalHeap lh(100000);
     int el = ma->FindElementOfPoint(res1, outip, false);
     if (el == -1) return 0;
     ElementTransformation & eltrans = ma->GetTrafo(el, lh);
     BaseMappedIntegrationPoint & mip = eltrans(outip, lh);
     return c2->Evaluate(mip);
   } else {
     LocalHeap lh(1000);
     return c2->Evaluate(DummyMIPFromPoint(res1, lh));
   }
 }
Пример #14
0
/**
 * \fn Numerique Numerique::operatorNOT()
 * \brief Operateur NOT
 */
Numerique Numerique::operatorNOT()
{
    if ( numReel>0)
    {
        Numerique res0(0,"entier");
        return res0;
    }
    if ( numIm>0)
    {
        Numerique res0cmplx(0,"entier");
        return res0cmplx;
    }
    else
    {
        Numerique res1(1,"entier");
        return res1;
    }
}
Пример #15
0
/**
 * \fn Numerique Numerique::operatorOR(const Numerique& n)
 * \brief Operateur OR
 */
Numerique Numerique::operatorOR(const Numerique& n)
{
    if ( numReel>0 || n.numReel>0)
    {
        Numerique res1(1,"entier");
        return res1;
    }
    else if ((typeIm!="null" &&  numIm>0) || (n.typeIm!="null" && n.numIm>0))
    {
        Numerique res1cmplx(1,"entier");
        return res1cmplx;
    }
    else
    {
        Numerique res0(0,"entier");
        return res0;
    }

}
std::vector<std::vector<size_t> > process_clustering(std::vector<imgptr> images) {
    
    std::vector<size_t> set1(images.size());
    
    std::iota (std::begin(set1), std::end(set1), 0);
    
    distance_processor d;
    d.calculate_distances(images);
    
    std::vector<std::vector<size_t> > res1(cluster_set(set1, d));
    std::vector<std::vector<size_t> > res2;
    for (std::vector<size_t>& r: res1) {
        auto rt = cluster_set(r, d);
        res2.insert(res2.end(), std::make_move_iterator(rt.begin()),
                std::make_move_iterator(rt.end()));
    }
    std::cout<<"clusters1 :" <<res1.size()<<" clusters2: "<<res2.size()<<"\n";
    return res2;
}
Пример #17
0
 /*
  * compare: Compare running time of 2 implementations of Nearest Neighbor Search by performing N queries
  *          on N reference points where each point has dimension k
  */
void TestEnvironment::compare(NearestNeighbor<float> *impl1, NearestNeighbor<float> *impl2, int N, int k)
{
  //cout << "N = " << N << endl;
  vector<Point<float>> data (N);
  vector<Point<float>> queries (N);
  vector<int> res1 (N);
  vector<int> res2 (N);
  TestEnvironment::gen_data(data, k);
  TestEnvironment::gen_data(queries, k);
  impl1->nns(data, queries, res1);
  impl2->nns(data, queries, res2);
  if(!verify(res1, res2))
  {
    cout << "Results don't match !!!" << endl;
    exit(-1);
  }

  print_result(N, impl1->get_search_time().count(), impl2->get_search_time().count());

}
Пример #18
0
 void ComposeCoefficientFunction::Evaluate(const BaseMappedIntegrationPoint & ip,
                                           FlatVector<> result) const
 {
   IntegrationPoint outip;
   Vector<> res1(c1->Dimension());
   c1->Evaluate(ip, res1);
   if (ma)
   {
     LocalHeap lh(100000);
     int el = ma->FindElementOfPoint(res1, outip, false);
     if (el == -1)
     {
       result = 0;
       return;
     }
     ElementTransformation & eltrans = ma->GetTrafo(el, lh);
     BaseMappedIntegrationPoint & mip = eltrans(outip, lh);
     c2->Evaluate(mip, result);
   } else {
     // TODO: heap allocation too slow
     LocalHeap lh(1000);
     c2->Evaluate(DummyMIPFromPoint(res1, lh), result);
   }
 }
Пример #19
0
bool authpgsql_connection::getuserinfo(authpgsql_userinfo &uiret,
				       const char *username,
				       const char *service)
{
	std::string querybuf;

	if (!do_connect())
		return false;

	if (config_file.select_clause.empty())
	{
		std::ostringstream o;

		o << "SELECT "
		  << config_file.login_field << ", "
		  << config_file.crypt_field << ", "
		  << config_file.clear_field << ", "
		  << config_file.uid_field << ", "
		  << config_file.gid_field << ", "
		  << config_file.home_field << ", "
		  << (strcmp(service, "courier") == 0 ?
		      config_file.defaultdelivery_field
		      :config_file.maildir_field) << ", "
		  << config_file.quota_field << ", "
		  << config_file.name_field << ", "
		  << config_file.options_field
		  << " FROM " << config_file.user_table
		  << " WHERE " << config_file.login_field
		  << " = '"
		  << escape_username(username)
		  << "' AND (" << config_file.where_clause << ")";

		querybuf=o.str();
	}
	else
	{
		std::map<std::string, std::string> parameters;

		parameters["service"]=service;

		querybuf=config_file
			.parse_custom_query(config_file.select_clause,
					    escape(username),
					    config_file.defdomain,
					    parameters);
	}

	DPRINTF("SQL query: %s", querybuf.c_str());

	result res1(*this, querybuf);

	if (res1)
		return getuserinfo(uiret, res1);

	disconnect();
	if (do_connect())
	{
		result res2(*this, querybuf);

		if (res2)
			return getuserinfo(uiret, res2);
	}
	return false;
}
Пример #20
0
void SIMPLE_Agents::get_IR_reading( vector <double> &_reading){
    double x,z,X,Z,rotation = 0.0;
    this->pos = this->get_pos();
    double y = pos[1] + 0.011;
    btMatrix3x3 m = btMatrix3x3(body->getWorldTransform().getRotation());
    double rfPAngle = btAsin(-m[1][2]);
       if ( rfPAngle < SIMD_HALF_PI )   {
           if ( rfPAngle > -SIMD_HALF_PI ) rotation = btAtan2(m[0][2],m[2][2]);
            else rotation = -btAtan2(-m[0][1],m[0][0]);
        }
        else rotation = btAtan2(-m[0][1],m[0][0]);

 //   IR0 reading
      x = pos[0]+((robot_radius) * cos(-rotation + 0.3));   //calc IR sensor X based on robot radius
      z = pos[2]+((robot_radius) * sin(-rotation + 0.3));
      from1[0] = btVector3(x, y, z);                        //sensor position based on robot rotation vector to hold btVector
      X = x+((IR_range) * cos(-rotation + 0.3 ));           //calc IR ray end position based on IR range and placement of sensor on the robot
      Z = z+((IR_range) * sin(-rotation + 0.3 ));
      to1[0] = btVector3( X, y, Z );                        //Max reading pos of the IR based on rotation and IR range
      btCollisionWorld::ClosestRayResultCallback res0(from1[0], to1[0]); //struct for the closest ray callback
      //uncomment below line if you experience any ray pentration problem to the object this might happened with very slow machine
      //res0.m_flags = 0xFFFFFFFF;
       this->world->rayTest(from1[0], to1[0], res0);        //check for ray collision between the coords sets
    if(res0.hasHit()){
        _reading[0] = IR_range*res0.m_closestHitFraction ;
        to1[0]=res0.m_hitPointWorld;                        //update the vector with the btVector results -> used to render it in openGL
    }

 //   IR7 reading
      x = pos[0]+((robot_radius) * cos(-rotation - 0.3));
      z = pos[2]+((robot_radius) * sin(-rotation - 0.3));
      from1[1] = btVector3(x, y, z);
      X = x+((IR_range) * cos(-rotation - 0.3 ));
      Z = z+((IR_range) * sin(-rotation - 0.3 ));
      to1[1] = btVector3( X, y, Z );
      btCollisionWorld::ClosestRayResultCallback res7(from1[1], to1[1]);
      //uncomment below line if you experience any ray pentration problem to the object this might happened with very slow machine
      //res7.m_flags = 0xFFFFFFFF;
      this->world->rayTest(from1[1], to1[1], res7);
      if(res7.hasHit()){
          _reading[1] = IR_range*res7.m_closestHitFraction;
          to1[1]=res7.m_hitPointWorld;
      }

 //   IR1 reading corrospond to epuck
      x = pos[0]+((robot_radius) * cos(-rotation + 0.8));
      z = pos[2]+((robot_radius) * sin(-rotation + 0.8));
      from1[2] = btVector3(x, y, z);
      X = x+((IR_range) * cos(-rotation + 0.8 ));
      Z = z+((IR_range) * sin(-rotation + 0.8 ));
      to1[2] = btVector3( X, y, Z );
      btCollisionWorld::ClosestRayResultCallback res1(from1[2], to1[2]);
      //uncomment below line if you experience any ray pentration problem to the object this might happened with very slow machine
      //res1.m_flags = 0xFFFFFFFF;
      this->world->rayTest(from1[2], to1[2], res1);
      if(res1.hasHit()){
        _reading[2] = IR_range*res1.m_closestHitFraction;
        to1[2]=res1.m_hitPointWorld;
      }


 //   IR6 reading
      x = pos[0]+((robot_radius) * cos(-rotation - 0.8));
      z = pos[2]+((robot_radius) * sin(-rotation - 0.8));
      from1[3] = btVector3(x, y, z);
      X = x+((IR_range) * cos(-rotation - 0.8 ));
      Z = z+((IR_range) * sin(-rotation - 0.8 ));
      to1[3] = btVector3( X, y, Z );
      btCollisionWorld::ClosestRayResultCallback res6(from1[3], to1[3]);
      //uncomment below line if you experience any ray pentration problem to the object this might happened with very slow machine
      //res6.m_flags = 0xFFFFFFFF;
      this->world->rayTest(from1[3], to1[3], res6);
      if(res6.hasHit()){
          _reading[3] = IR_range*res6.m_closestHitFraction;
          to1[3]=res6.m_hitPointWorld;
     }

 //   IR2 reading
      x = pos[0]+((0.028) * cos(-rotation + 1.57));
      z = pos[2]+((0.028) * sin(-rotation + 1.57));
      from1[4] = btVector3(x, y, z);
      X = x+((0.049) * cos(-rotation + 1.57 ));
      Z = z+((0.049) * sin(-rotation + 1.57));
      to1[4] = btVector3( X, y, Z );
      btCollisionWorld::ClosestRayResultCallback res2(from1[4], to1[4]);
      //uncomment below line if you experience any ray pentration problem to the object this might happened with very slow machine
      //res2.m_flags = 0xFFFFFFFF;
      this->world->rayTest(from1[4], to1[4], res2);
      if(res2.hasHit()){
          _reading[4] = 0.049*(res2.m_closestHitFraction) - 0.009;
          to1[4]=res2.m_hitPointWorld;
      }

 //   IR5 reading
      x = pos[0]+((0.028) * cos(-rotation - 1.57));
      z = pos[2]+((0.028) * sin(-rotation - 1.57));
      from1[5] = btVector3(x, y, z);
      X = x+((0.049) * cos(-rotation - 1.57 ));
      Z = z+((0.049) * sin(-rotation - 1.57 ));
      to1[5] = btVector3( X, y, Z );
      btCollisionWorld::ClosestRayResultCallback res5(from1[5], to1[5]);
      //uncomment below line if you experience any ray pentration problem to the object this might happened with very slow machine
      //res5.m_flags = 0xFFFFFFFF;
      this->world->rayTest(from1[5], to1[5], res5);
      if(res5.hasHit()){
           _reading[5] = 0.049*res5.m_closestHitFraction - 0.009;
           to1[5]=res5.m_hitPointWorld;
      }


 //   IR3 reading
      x = pos[0]+((robot_radius) * cos(-rotation + 2.64));
      z = pos[2]+((robot_radius) * sin(-rotation + 2.64));
      from1[6] = btVector3(x, y, z);
      X = x+((IR_range) * cos(-rotation + 2.64 ));
      Z = z+((IR_range) * sin(-rotation + 2.64 ));
      to1[6] = btVector3( X, y, Z );
      btCollisionWorld::ClosestRayResultCallback res3(from1[6], to1[6]);
      //uncomment below line if you experience any ray pentration problem to the object this might happened with very slow machine
      //res3.m_flags = 0xFFFFFFFF;
      this->world->rayTest(from1[6], to1[6], res3);
      if(res3.hasHit()){
          _reading[6] = IR_range*res3.m_closestHitFraction;
          to1[6]=res3.m_hitPointWorld;
      }

  //   IR4 reading
      x = pos[0]+((robot_radius) * cos(-rotation - 2.64));
      z = pos[2]+((robot_radius) * sin(-rotation - 2.64));
      from1[7] = btVector3(x, y, z);
      X = x+((IR_range) * cos(-rotation - 2.64 ));
      Z = z+((IR_range) * sin(-rotation - 2.64 ));
      to1[7] = btVector3( X, y, Z );
      btCollisionWorld::ClosestRayResultCallback res4(from1[7], to1[7]);
      //uncomment below line if you experience any ray pentration problem to the object this might happened with very slow machine
      //res4.m_flags = 0xFFFFFFFF;
      this->world->rayTest(from1[7], to1[7], res4);
      if(res4.hasHit()){
          _reading[7] = IR_range*res4.m_closestHitFraction;
          to1[7]=res4.m_hitPointWorld;
      }

//        for( int i = 0; i < num_IR_sensors; i++){
//            printf(" \nIR%d distance reading= %f ",i,_reading[i]);
//        }

    //calibrating distance to IR value reading according to a line equations
  for(int i = 0; i < num_IR_sensors; i++){
       if (_reading[i] > 0.03 && _reading[i] <= 0.04)
           _reading[i] = -20600 * _reading[i] + 924;
       else if (_reading[i] > 0.02 && _reading[i] <= 0.03)
           _reading[i] = -37000 * _reading[i] + 1416;
       else if (_reading[i] > 0.01 && _reading[i] <= 0.02)
           _reading[i] = -153500 * _reading[i] + 3746;
       else if (_reading[i] > 0.005 && _reading[i] <= 0.01)
           _reading[i] = -252600 * _reading[i] + 4737;
       else if (_reading[i] >= 0.0 && _reading[i] <= 0.005 )
           _reading[i] = -124200 * _reading[i] + 4095;

  }
//  for( int i = 0; i < num_IR_sensors; i++){
//      printf("\n IR%d distance reading= %f ",i,_reading[i]);
//  }

//    take_occupancy_reading(_reading, get_rotation(), get_pos()[0], get_pos()[2] );


}
Пример #21
0
std::shared_ptr<TextureParameters> processTexture(
    domCommon_color_or_texture_type_complexType::domTexture *tex
)
{
    std::shared_ptr<TextureParameters> parameters(new TextureParameters);
    //parameters.transparent = tuu == TRANSPARENCY_MAP_UNIT;
    //parameters.opaque = opaque;
    //parameters.transparency = transparency;

    //find the newparam for the sampler based on the texture attribute
    domFx_sampler2D_common *sampler = NULL;
    domFx_surface_common *surface = NULL;
    domImage *dImg = NULL;

    std::string target = std::string("./") + std::string(tex->getTexture());
    // OSG_INFO<<"processTexture("<<target<<")"<<std::endl;

    daeSIDResolver res1( /*_currentEffect*/currentEffect(), target.c_str() );
    daeElement *el = res1.getElement();

    if (el == NULL )
    {
        std::cout << "Could not locate newparam for texture sampler2D \"" << tex->getTexture() <<
            "\". Checking if data does incorrect linking straight to the image" << std::endl;
        GetDAE().getDatabase()->getElement( (daeElement**)&dImg, 0, tex->getTexture(), "image" );
        if (dImg != NULL )
        {
            std::cout << "Direct image link found. Data is incorrect but will continue to load texture" << std::endl;
        }
    }
    else
    {
        domCommon_newparam_type *cnp = daeSafeCast< domCommon_newparam_type >( el );
        domFx_newparam_common *npc = daeSafeCast< domFx_newparam_common >( el );

        if (cnp != NULL )
        {
            sampler = cnp->getSampler2D();
        }
        else if (npc != NULL )
        {
            sampler = npc->getFx_basic_type_common()->getSampler2D();
        }

        if (sampler == NULL )
        {
            std::cout << "Wrong newparam type. Expected sampler2D" << std::endl;
            return nullptr;
        }

        if (sampler->getSource() == NULL )
        {
            std::cout << "Could not locate source for sampler2D" << std::endl;
            return nullptr;
        }

        //find the newparam for the surface based on the sampler2D->source value
        target = std::string("./") + std::string( sampler->getSource()->getValue() );
        daeSIDResolver res2( /*_currentEffect*/currentEffect(), target.c_str() );
        el = res2.getElement();
        if (el == NULL )
        {
            std::cout << "Could not locate newparam for source " << sampler->getSource()->getValue() << std::endl;
            return nullptr;
        }
        cnp = daeSafeCast< domCommon_newparam_type >( el );
        npc = daeSafeCast< domFx_newparam_common >( el );

        if (cnp != NULL )
        {
            surface = cnp->getSurface();
        }
        else if (npc != NULL )
        {
            surface = npc->getFx_basic_type_common()->getSurface();
        }

        if (surface == NULL )
        {
            std::cout << "Wrong newparam type. Expected surface" << std::endl;
            return NULL;
        }

        //look for the domImage based on the surface initialization stuff
        daeIDRef &ref = surface->getFx_surface_init_common()->getInit_from_array()[0]->getValue();
        dImg = daeSafeCast< domImage >( getElementFromIDRef( ref ) );
    }

    parameters->filename = processImagePath(dImg);
	std::cout << "ImagePath: " << parameters->filename << std::endl;
    if (parameters->filename.empty())
    {
		
        return NULL;
    }
	

    //set texture parameters
    if (sampler)
    {
        if (sampler->getWrap_s())
        {
            parameters->wrap_s = sampler->getWrap_s()->getValue();//getWrapMode(sampler->getWrap_s()->getValue());
        }
        if (sampler->getWrap_t())
        {
            parameters->wrap_t = sampler->getWrap_t()->getValue();//getWrapMode(sampler->getWrap_s()->getValue());
        }

        if (sampler->getMinfilter() && sampler->getMinfilter()->getValue() != FX_SAMPLER_FILTER_COMMON_NONE)
        {
            parameters->filter_min = sampler->getMinfilter()->getValue();//getFilterMode(sampler->getMinfilter()->getValue(), true);
        }
        if (sampler->getMagfilter() && sampler->getMagfilter()->getValue() != FX_SAMPLER_FILTER_COMMON_NONE)
        {
            parameters->filter_mag = sampler->getMagfilter()->getValue();//getFilterMode(sampler->getMagfilter()->getValue(), false);
        }

        if (sampler->getBorder_color() != NULL )
        {
            const domFloat4& col = sampler->getBorder_color()->getValue();
            parameters->border = col;// parameters.border.set(col[0], col[1], col[2], col[3]);
        }
    }

	   
	//osg::Texture2D* t2D = NULL;
    //TextureParametersMap::const_iterator mapIt = _textureParamMap.find(parameters);
    //if (mapIt != _textureParamMap.end())
    //{
    //    t2D = mapIt->second.get();
    //}
    //else
    //{
    //    osg::ref_ptr<osg::Image> img = osgDB::readRefImageFile(parameters.filename);

    //    if (!img.valid())
    //    {
    //        _textureParamMap[parameters] = NULL;
    //        return NULL;
    //    }

    //    OSG_INFO<<"  processTexture(..) - readImage("<<parameters.filename<<")"<<std::endl;

    //    if (tuu == TRANSPARENCY_MAP_UNIT)
    //    {
    //        img = processImageTransparency(img.get(), opaque, transparency);
    //    }

    //    t2D = new osg::Texture2D(img.get());

    //    t2D->setWrap( osg::Texture::WRAP_S, parameters.wrap_s);
    //    t2D->setWrap( osg::Texture::WRAP_T, parameters.wrap_t);
    //    t2D->setFilter( osg::Texture::MIN_FILTER, parameters.filter_min);
    //    t2D->setFilter( osg::Texture::MAG_FILTER, parameters.filter_mag);
    //    t2D->setBorderColor(parameters.border);

    //    _textureParamMap[parameters] = t2D;
    //}

    //_texCoordSetMap[TextureToCoordSetMap::key_type(ss, tuu)] = tex->getTexcoord();

    return /*t2D*/parameters;
}
Пример #22
0
ibis::table* ibis::jRange::select(const char *sstr) const {
    if (nrows < 0) {
        int64_t ierr = count();
        if (ierr < 0) {
            LOGGER(ibis::gVerbose > 0)
                << "Warning -- jRange::count failed with error code"
                << ierr;
            return 0;
        }
    }
    if (sstr == 0 || *sstr == 0) { // default
        std::string tn = ibis::util::shortName(desc_.c_str());
        return new ibis::tabula(tn.c_str(), desc_.c_str(), nrows);
    }

    ibis::selectClause sel(sstr);
    uint32_t features=0; // 1: arithmetic operation, 2: aggregation
    // use a barrel to collect all unique names
    ibis::math::barrel brl;
    for (uint32_t j = 0; j < sel.aggSize(); ++ j) {
        const ibis::math::term* t = sel.aggExpr(j);
        brl.recordVariable(t);
        if (t->termType() != ibis::math::VARIABLE &&
            t->termType() != ibis::math::NUMBER &&
            t->termType() != ibis::math::STRING) {
            features |= 1; // arithmetic operation
        }
        if (sel.getAggregator(j) != ibis::selectClause::NIL_AGGR) {
            features |= 2; // aggregation
        }
    }
    // convert the barrel into a stringArray for processing
    ibis::table::stringArray sl;
    sl.reserve(brl.size());
    for (unsigned j = 0; j < brl.size(); ++ j) {
        const char* str = brl.name(j);
        if (*str != 0) {
            if (str[0] != '_' || str[1] != '_')
                sl.push_back(str);
        }
    }

    std::unique_ptr<ibis::table> res1(select(sl));
    if (res1.get() == 0 || res1->nRows() == 0 || res1->nColumns() == 0 ||
        features == 0)
        return res1.release();

    if (ibis::gVerbose > 2) {
        ibis::util::logger lg;
        lg() << "jRange::select(" << sstr << ", " << desc_
             << ") produced the first intermediate table:\n";
        res1->describe(lg());
    }

    if ((features & 1) != 0) { // arithmetic computations
        res1.reset(static_cast<const ibis::bord*>(res1.get())->evaluateTerms
                   (sel, desc_.c_str()));
        if (res1.get() != 0) {
            if (ibis::gVerbose > 2) {
                ibis::util::logger lg;
                lg() << "jRange::select(" << sel << ", " << desc_
                     << ") produced the second intermediate table:\n";
                res1->describe(lg());
            }
        }
        else {
            LOGGER(ibis::gVerbose > 0)
                << "Warning -- jRange::select(" << sel
                << ") failed to evaluate the arithmetic expressions";
            return 0;
        }
    }

    if ((features & 2) != 0) { // aggregation operations
        res1.reset(static_cast<const ibis::bord*>(res1.get())->groupby(sel));
        if (res1.get() != 0) {
            if (ibis::gVerbose > 2) {
                ibis::util::logger lg;
                lg() << "jRange::select(" << *sel_ << ", " << desc_
                     << ") produced the third intermediate table:\n";
                res1->describe(lg());
            }
        }
        else {
            LOGGER(ibis::gVerbose > 0)
                << "Warning -- jRange::select(" << *sel_
                << ") failed to evaluate the aggregations";
        }
    }
    return res1.release();
} // ibis::jRange::select