Exemple #1
0
int test() {
  {
    int& (*fpi)(int*) = [](auto* a) -> auto& { return *a; }; // OK
    int (*fp2)(int) = [](auto b) -> int {  return b; };
    int (*fp3)(char) = [](auto c) -> int { return c; };
    char (*fp4)(int) = [](auto d) { return d; }; //expected-error{{no viable conversion}}\
                                                 //expected-note{{candidate template ignored}}
    char (*fp5)(char) = [](auto e) -> int { return e; }; //expected-error{{no viable conversion}}\
                                                 //expected-note{{candidate template ignored}}

    fp2(3);
    fp3('\n');
    fp3('a');
    return 0;
  }
} // end test()
void KisFixedPointMathsTest::testOperatorsNegative()
{
    KisFixedPoint fp1(qreal(-2.5));
    KisFixedPoint fp2(2);
    KisFixedPoint fp3(-3);

    QCOMPARE(fp1 + fp2, KisFixedPoint(qreal(-0.5)));
    QCOMPARE(fp1 - fp2, KisFixedPoint(qreal(-4.5)));
    QCOMPARE(fp1 * fp2, KisFixedPoint(-5));
    QCOMPARE(fp1 * fp3, KisFixedPoint(qreal(7.5)));

    QCOMPARE(fp2 / fp1, KisFixedPoint(qreal(-0.8)));
    QCOMPARE(fp1 / fp2, KisFixedPoint(qreal(-1.25)));
    QCOMPARE(fp3 / fp1, KisFixedPoint(qreal(1.2)));
}
Exemple #3
0
template<class ... Ts> int fooV(Ts ... ts) {
  auto L = [](auto ... a) { 
    auto M = [](decltype(a) ... b) -> void {  
      auto N = [](auto c) -> void {
        int x = 0;
        x = sizeof...(a);        
        x = sizeof...(b);
        x = sizeof(c);
      };  
      N('a');
      N(N);
      N(FirstType<Ts...>{});
    };
    M(a...);
    return M;
  };
  auto M = L(L, ts...);
  decltype(L(L, ts...)) (*fp)(decltype(L), decltype(ts) ...) = L;
  void (*fp2)(decltype(L), decltype(ts) ...) = L(L, ts...);
  
  {
    auto L = [](auto ... a) { 
      auto M = [](decltype(a) ... b) {  
        auto N = [](auto c) -> void {
          int x = 0;
          x = sizeof...(a);        
          x = sizeof...(b);
          x = sizeof(c);
        };  
        N('a');
        N(N);
        N(FirstType<Ts...>{});
        return N;
      };
      M(a...);
      return M;
    };
    auto M = L(L, ts...);
    decltype(L(L, ts...)) (*fp)(decltype(L), decltype(ts) ...) = L;
    fp(L, ts...);
    decltype(L(L, ts...)(L, ts...)) (*fp2)(decltype(L), decltype(ts) ...) = L(L, ts...);
    fp2 = fp(L, ts...);
    void (*fp3)(char) = fp2(L, ts...);
    fp3('a');
  }
  return 0;
}
Exemple #4
0
static void test_standalone_funcs() {
    printf("\r\n********** Starting test_standalone_funcs **********\r\n");
    const char *testmsg1 = "Test message 1";
    const char *testmsg2 = "Test message 2";
    const int testint1 = 13;
    const double testdouble = 100.0;

    // First call function pointers directly
    FunctionPointer1<void, const char*> fp1(sa_func_1);
    FunctionPointer1<void, int> fp2(sa_func_2);
    FunctionPointer0<void> fp3(sa_func_3);
    FunctionPointer3<void, int, const char*, double> fp4(sa_func_4);
    call_fp1("ptr to standalone func(char*)", fp1, testmsg1);
    call_fp1("ptr to standalone func(char*)", fp1, testmsg2);
    call_fp1("ptr to standalone func(int)", fp2, testint1);
    call_fp0("ptr to standalone func(void)", fp3);
    call_fp3("ptr to standalong func(int, const char*, double)", fp4, testint1, testmsg1, testdouble);
}
Exemple #5
0
    void TestConstructor(void)
    {
        SCXCoreLib::SCXFilePath fp1;
        SCXCoreLib::SCXFilePath fp2(L"/some/path");
        std::wstring sp = L"C:\\some/other\\path/";
        SCXCoreLib::SCXFilePath fp3(sp);
        SCXCoreLib::SCXFilePath fp4(fp2);
        // Check that constructors create a path as expected.
        CPPUNIT_ASSERT(fp1.Get().compare(L"") == 0);
#if defined(WIN32)
        CPPUNIT_ASSERT(fp2.Get() == L"\\some\\path");
        CPPUNIT_ASSERT(fp3.Get() == L"C:\\some\\other\\path\\");
#else
        CPPUNIT_ASSERT(fp2.Get() == L"/some/path");
        CPPUNIT_ASSERT(fp3.Get() == L"C:/some/other/path/");
#endif
        // Check that copy constructor creates identical content.
        CPPUNIT_ASSERT(fp2.Get() == fp4.Get());
    }
Exemple #6
0
static void test_array_of_events() {
    printf("\r\n********** Starting test_array_of_events **********\r\n");
    const char* testmsg1 = "Test message 1";
    const char* testmsg2 = "Test message 2";
    const int testint = 13;
    VDerived derived(20, 100);
    MyArg arg("array", 5, 10);

    FunctionPointer1<void, const char*> fp1((VBase*)&derived, &VBase::print_virtual_str);
    FunctionPointer0<void> fp2(sa_func_3);
    FunctionPointer1<void, int> fp3(sa_func_2);
    FunctionPointer0<void> fp4(&derived, &VDerived::print_virtual_noargs);
    FunctionPointer1<void, MyArg> fp5(sa_ntc);
    Event events[] = {fp1.bind(testmsg1), fp1.bind(testmsg2), fp2.bind(), fp3.bind(testint),
                      fp4.bind(), fp5.bind(arg)};

    for (unsigned i = 0; i < sizeof(events)/sizeof(events[0]); i ++) {
        events[i].call();
    }
}
Exemple #7
0
static void test_funcs_nontca() {
    printf("\r\n********** Starting test_funcs_nontca **********\r\n");

    FunctionPointer1<void, MyArg> fp1(sa_ntc);
    Event e1, e2, e3;
    {
        // Test binding argument that gets out of scope at the end of this block
        MyArg arg("test", 10, 20);
        call_fp1("ptr to standalong func taking non-trivial arg", fp1, arg);
        e1 = e2 = e3 = fp1.bind(arg);
    }
    e1.call(); // This should work, since it has a copy of 'arg' above
    // Test functions taking non-trivial arguments inside classes
    ADerived d(10, 100);
    ABase *pDerived = &d;
    FunctionPointer1<void, MyArg> fp2(&d, &ADerived::print_virtual_arg);
    FunctionPointer1<void, MyArg> fp3(pDerived, &ABase::print_virtual_arg);
    call_fp1("ptr to virtual method taking non-tc argument", fp2, MyArg("notest", 5, 8));
    call_fp1("ptr to virtual method taking non-tc argument (via base class pointer)", fp2, MyArg("notest", 5, 8));
}
void KisFixedPointMathsTest::testConversionsNegative()
{
    KisFixedPoint fp1(qreal(-2.5));
    KisFixedPoint fp2(qreal(-2.73));
    KisFixedPoint fp3(qreal(-2.34));

    QCOMPARE(fp1.toInt(), -2);
    QCOMPARE(fp1.toIntRound(), -3);
    QCOMPARE(fp1.toIntFloor(), -3);
    QCOMPARE(fp1.toIntCeil(), -2);

    QCOMPARE(fp2.toInt(), -2);
    QCOMPARE(fp2.toIntRound(), -3);
    QCOMPARE(fp2.toIntFloor(), -3);
    QCOMPARE(fp2.toIntCeil(), -2);

    QCOMPARE(fp3.toInt(), -2);
    QCOMPARE(fp3.toIntRound(), -2);
    QCOMPARE(fp3.toIntFloor(), -3);
    QCOMPARE(fp3.toIntCeil(), -2);
}
Exemple #9
0
PyObject *_PY_fp3(PyObject *self, PyObject *args, PyObject *kwds)
   {int ok;
    PyObject *_lo;
    int _la1;
    short *_rv;
    char *kw_list[] = {"a1", NULL};

/* local variable initializations */
    _la1       = 0;

    ok = PyArg_ParseTupleAndKeywords(args, kwds,
                                     "i:fp3_p",
                                     kw_list,
                                     &_la1);
    if (ok == FALSE)
       return(NULL);

    _rv = fp3(_la1);
    _lo = PY_build_object("fp3",
                          G_SHORT_I, 0, &_rv,
                          0);

    return(_lo);}
void KisFixedPointMathsTest::testConversions()
{
    KisFixedPoint fp1(qreal(2.5));
    KisFixedPoint fp2(qreal(2.73));
    KisFixedPoint fp3(qreal(2.34));

    QCOMPARE(fp1.toInt(), 2);
    QCOMPARE(fp1.toIntRound(), 3);
    QCOMPARE(fp1.toIntFloor(), 2);
    QCOMPARE(fp1.toIntCeil(), 3);
    QCOMPARE(fp1.toFloat(), qreal(2.5));

    QCOMPARE(fp2.toInt(), 2);
    QCOMPARE(fp2.toIntRound(), 3);
    QCOMPARE(fp2.toIntFloor(), 2);
    QCOMPARE(fp2.toIntCeil(), 3);
    QCOMPARE(fp2.toFloat(), qreal(698.0/256.0));

    QCOMPARE(fp3.toInt(), 2);
    QCOMPARE(fp3.toIntRound(), 2);
    QCOMPARE(fp3.toIntFloor(), 2);
    QCOMPARE(fp3.toIntCeil(), 3);
    QCOMPARE(fp3.toFloat(), qreal(599.0/256.0));
}
void KisFixedPointMathsTest::testOperators()
{
    KisFixedPoint fp1(1);
    KisFixedPoint fp2(2);
    KisFixedPoint fp3(qreal(2.5));
    KisFixedPoint fp4(qreal(2.0));

    QVERIFY(fp1 < fp2);
    QVERIFY(fp2 < fp3);

    QVERIFY(fp2 > fp1);
    QVERIFY(fp3 > fp2);

    QVERIFY(fp1 != fp2);
    QVERIFY(fp2 == fp4);

    QCOMPARE(fp1 + fp2, KisFixedPoint(3));
    QCOMPARE(fp1 - fp2, KisFixedPoint(-1));
    QCOMPARE(fp1 * fp2, KisFixedPoint(2));
    QCOMPARE(fp2 * fp3, KisFixedPoint(5));
    QCOMPARE(fp1 / fp2, KisFixedPoint(qreal(0.5)));
    QCOMPARE(fp1 / fp3, KisFixedPoint(qreal(0.4)));
    QCOMPARE(fp2 / fp3, KisFixedPoint(qreal(0.8)));
}
bool Frustum::bakeProjectionOffset()
{
   // Nothing to bake if ortho
   if( mIsOrtho )
      return false;

   // Nothing to bake if no offset
   if( mProjectionOffset.isZero() )
      return false;

   // Near plane points in camera space
   Point3F np[4];
   np[0].set( mNearLeft, mNearDist, mNearTop );       // NearTopLeft
   np[1].set( mNearRight, mNearDist, mNearTop );      // NearTopRight
   np[2].set( mNearLeft, mNearDist, mNearBottom );    // NearBottomLeft
   np[3].set( mNearRight, mNearDist, mNearBottom );   // NearBottomRight

   // Generate the near plane
   PlaneF nearPlane( np[0], np[1], np[3] );

   // Far plane points in camera space
   const F32 farOverNear = mFarDist / mNearDist;
   Point3F fp0( mNearLeft * farOverNear, mFarDist, mNearTop * farOverNear );     // FarTopLeft
   Point3F fp1( mNearRight * farOverNear, mFarDist, mNearTop * farOverNear );    // FarTopRight
   Point3F fp2( mNearLeft * farOverNear, mFarDist, mNearBottom * farOverNear );  // FarBottomLeft
   Point3F fp3( mNearRight * farOverNear, mFarDist, mNearBottom * farOverNear ); // FarBottomRight

   // Generate the far plane
   PlaneF farPlane( fp0, fp1, fp3 );

   // The offset camera point
   Point3F offsetCamera( mProjectionOffset.x, 0.0f, mProjectionOffset.y );

   // The near plane point we'll be using for our calculations below
   U32 nIndex = 0;
   if( mProjectionOffset.x < 0.0 )
   {
      // Offset to the left so we'll need to use the near plane point on the right
      nIndex = 1;
   }
   if( mProjectionOffset.y > 0.0 )
   {
      // Offset to the top so we'll need to use the near plane point at the bottom
      nIndex += 2;
   }

   // Begin by calculating the offset point on the far plane as it goes
   // from the offset camera to the edge of the near plane.
   Point3F farPoint;
   Point3F fdir = np[nIndex] - offsetCamera;
   fdir.normalize();
   if( farPlane.intersect(offsetCamera, fdir, &farPoint) )
   {
      // Calculate the new near plane edge from the non-offset camera position
      // to the far plane point from above.
      Point3F nearPoint;
      Point3F ndir = farPoint;
      ndir.normalize();
      if( nearPlane.intersect( Point3F::Zero, ndir, &nearPoint) )
      {
         // Handle a x offset
         if( mProjectionOffset.x < 0.0 )
         {
            // The new near plane right side
            mNearRight = nearPoint.x;
         }
         else if( mProjectionOffset.x > 0.0 )
         {
            // The new near plane left side
            mNearLeft = nearPoint.x;
         }

         // Handle a y offset
         if( mProjectionOffset.y < 0.0 )
         {
            // The new near plane top side
            mNearTop = nearPoint.y;
         }
         else if( mProjectionOffset.y > 0.0 )
         {
            // The new near plane bottom side
            mNearBottom = nearPoint.y;
         }
      }
   }

   mDirty = true;

   // Indicate that we've modified the frustum
   return true;
}
Exemple #13
0
//一定要素用のBEM関数
void BEM_main_for_CONSTANT(mpsconfig *CON,vector<point2D> &NODE,vector<element2D> &ELEM,vector<mpsparticle> &PART,int fluid_number,double **F,vector<REGION> &region)
{
	int node_num=int (NODE.size());		//節点数
	int elemnum=int (ELEM.size());		//要素数
	int region_num=(int)(region.size());//領域の数
	int uk=0;								//未知数
	int count;

	cout<<"領域数="<<region_num<<endl;
	
	//未知数計算
	for(int i=0;i<node_num;i++)
	{
		if(NODE[i].boundary_condition==BOTH) uk+=2;	//BOTHは多媒質境界上の節点であり、ポテンシャル、法線微分の両方が未知であることを示す
		else uk++;									//こちらは通常。DiricだろうとNeumnだろうと、片方は未知なので++;
	}
	cout<<"未知数="<<uk<<endl;

	int *Nid=new int [uk];							//i番目の未知数はi番目の計算点であることを示す
	int *bd_type=new int [uk];
	int *BOTH_column=new int [node_num];
	count=0;
	
	for(int i=0;i<elemnum;i++)
	{
		if(ELEM[i].boundary_condition==BOTH)
		{
			Nid[i]=i;		//i番目の未知数はi番目の計算点であることを示す
			bd_type[i]=Neumn;//BOTHの場合、未知数はポテンシャル、法線微分の順に定義する。よってbd_typeはこのようにしておく
			Nid[elemnum+count]=i;
			bd_type[elemnum+count]=Diric;
			BOTH_column[i]=elemnum+count;//i番目の計算点がBOTHのとき、法線微分を表す未知数はBOTH_column[i]番目の未知数である。
			count++;
		}
		else
		{
			Nid[i]=i;				//i番目の未知数はi番目の計算点であることを示す
			bd_type[i]=ELEM[i].boundary_condition;
			BOTH_column[i]=-1;		//BOTHでないならダミーとして−1を格納
		}
	}
	
	
	int gauss_N=4;				//ガウス積分における評価点数 //3,4,8
	int NGS[32];				//たとえばGauss積分点が4のときはfor(int i=NGS[4];i<NGS[4]+4;i++) ep1[i]=~~~~という使いかたをする
	double ep1[32];				//ガウス積分における局所座標格納
	double ep_ln[32];			//自然対数に関するガウス積分における局所座標格納
	double w1[32];				//ガウス積分における重み格納
	double w_ln[32];			//自然対数に関するガウス積分における重み格納

	//ガウス積分の準備
	set_gauss_parameter(NGS, ep1,w1,ep_ln,w_ln);

	//matrix作成
	double **matrixC=new double*[uk];
	for(int n=0;n<uk;n++) matrixC[n]=new double[uk];
	double **matrixC2=new double*[uk];
	for(int n=0;n<uk;n++) matrixC2[n]=new double[uk];
	double **H=new double*[uk];
	for(int n=0;n<uk;n++) H[n]=new double[uk];
	double **G=new double*[uk];
	for(int n=0;n<uk;n++) G[n]=new double[uk];
	double *Bmatrix=new double[uk];//解行列
	
	for(int n=0;n<uk;n++)
	{
		for(int m=0;m<uk;m++)
		{
			matrixC[n][m]=0;				//初期化
			matrixC2[n][m]=0;
			H[n][m]=0;
			G[n][m]=0;
		}
		Bmatrix[n]=0;
	}
	
	for(int ID=0;ID<1;ID++)				//まずは第1領域のみ計算
	{
		for(int n1=region[ID].start;n1<region[ID].end;n1++)
		{	
			int n=n1;
			int n2=BOTH_column[n1];
				
			double SR=0.5*ELEM[n1].L;//要素長さの半分
					
			for(int m1=region[ID].start;m1<region[ID].end;m1++)
			{
				int m=m1;
				int m2=BOTH_column[m1];
					
				int type=0;//type=0なら通常 1なら、その要素は節点nを含む特異積分
				if(n1==m1) type=1;
					
				if(type==0)
				{
					double w;
					double ep;		//評価点の局所座標
					for(int i=NGS[gauss_N];i<NGS[gauss_N]+gauss_N;i++)
					{
						ep=ep1[i];
						w=w1[i];
							
						set_GHmatrix_for_constant(ELEM, ep,  H, G, w, type,n, m,n1,m1);
					}
					if(m2!=-1)
					{
						G[n][m2]=G[n][m];
						G[n][m]=0;
					}
				}
			}
			H[n][n]=PI;
			G[n][n]=2*SR*(1-log(SR));
				

			if(n2!=-1)
			{
				G[n][n2]=G[n][n];
				G[n][n]=0;
			}
		}
	}
	//法線ベクトルを反転
	if(region_num>1) for(int i=0;i<elemnum;i++) for(int D=0;D<2;D++) ELEM[i].direct[D]*=-1.0;
	
	for(int ID=1;ID<region_num;ID++)				//第2領域以降を計算
	{
		for(int n1=region[ID].start;n1<region[ID].end;n1++)
		{	
			int n=BOTH_column[n1];					//計算点n1の、法線微分の未知変数はBOTH_column[n1]番目の未知数
			
			double SR=0.5*ELEM[n1].L;//要素長さの半分
			for(int m1=region[ID].start;m1<region[ID].end;m1++)
			{
				int m=m1;
				int m2=BOTH_column[m1];
				int type=0;//type=0なら通常 1なら、その要素は節点nを含む特異積分
				if(n1==m1) type=1;
					
				if(type==0)
				{
					double w;
					double ep;		//評価点の局所座標
						
					for(int i=NGS[gauss_N];i<NGS[gauss_N]+gauss_N;i++)
					{
						ep=ep1[i];
						w=w1[i];
							
						set_GHmatrix_for_constant(ELEM, ep,  H, G, w, type,n, m,n1,m1);
					}	
					G[n][m2]=-G[n][m]/80;
					//G[n][m2]=-G[n][m]/1;
					G[n][m]=0;
				}
			}
			H[n][n1]=PI;
			G[n][n]=-2*SR*(1-log(SR));
		}
	}
	//法線ベクトルを反転
	if(region_num>1) for(int i=0;i<elemnum;i++) for(int D=0;D<2;D++) ELEM[i].direct[D]*=-1.0;

	//実際に解く係数行列作成
	for(int n=0;n<elemnum;n++)	
	{
		if(ELEM[n].boundary_condition==Diric)
		{
			for(int m=0;m<uk;m++)
			{
				matrixC[m][n]=-G[m][n];
				matrixC2[m][n]=-H[m][n];
			}
		}
		else if(ELEM[n].boundary_condition==Neumn)
		{
			for(int m=0;m<uk;m++)
			{
				matrixC[m][n]=H[m][n];
				matrixC2[m][n]=G[m][n];
			}
		}
		else if(ELEM[n].boundary_condition==BOTH)
		{
			int n2=BOTH_column[n];
			
			for(int m=0;m<uk;m++)
			{
				matrixC[m][n2]=-G[m][n2];
				if(H[m][n2]!=0) cout<<"H "<<m<<" "<<n2<<" "<<H[m][n2]<<endl;
			}
				
			for(int m=0;m<uk;m++)
			{
				matrixC[m][n]=H[m][n];
				if(G[m][n]!=0) cout<<"G "<<m<<" "<<n<<" "<<G[m][n]<<endl;
			}
		}
	}

	//解行列作成
	for(int n=0;n<uk;n++)
	{
		double val=0;//解行列の値
		for(int m=0;m<uk;m++)
		{
			int elem=Nid[m];			//未知数nに対応する要素番号
			int node=ELEM[elem].node[0];	//要素elemに対応するのはELEM[elem].node[0]に格納している
			if(bd_type[m]==Diric) val+=matrixC2[n][m]*NODE[node].potential;
			else if(bd_type[m]==Neumn) val+=matrixC2[n][m]*NODE[node].slop1;
		}
		Bmatrix[n]=val;
	}
	/////matrix作成完了

	cout<<"行列作成完了 ガウスの消去法---";


	gauss(matrixC,Bmatrix,uk);//答えはBmatrixに格納



	cout<<"ok"<<endl;

	//答え格納
	for(int n=0;n<uk;n++)
	{
		int elem=Nid[n];		//未知数nに対応する要素番号
		int node=ELEM[elem].node[0];
		if(bd_type[n]==Neumn) NODE[node].potential=Bmatrix[n];
		else if(bd_type[n]==Diric) NODE[node].slop1=Bmatrix[n]; 
	}

	//答え確認
	ofstream fp3("V.dat");
	ofstream fp4("slop.dat");
	for(int n=0;n<elemnum;n++)
	{
		int node=ELEM[n].node[0];
		fp3<<ELEM[n].r[A_X]<<" "<<ELEM[n].r[A_Y]<<" "<<NODE[node].potential<<endl;
		fp4<<ELEM[n].r[A_X]<<" "<<ELEM[n].r[A_Y]<<" "<<NODE[node].slop1<<endl;
	}
	fp3.close();
	fp4.close();

	

	ofstream fp5("F.dat");
	double ep0=8.854e-12;
	double times=1e-3;
	double le=CON->get_distancebp();
	for(int n=0;n<elemnum;n++)
	{
		if(ELEM[n].material==FLUID)
		{
			int node=ELEM[n].node[0];//対応する節点番号
			int i=NODE[node].particle;//対応する粒子番号
			double E=NODE[node].slop1;
			double Fs=0.5*ep0*E*E;	//応力
			double Fn=Fs*ELEM[n].L;	//力[N]
			for(int D=0;D<2;D++) F[D][i]=-Fn*ELEM[n].direct[D];
			fp5<<PART[i].r[A_X]<<" "<<PART[i].r[A_Y]<<" "<<F[A_X][i]*times/le<<" "<<F[A_Y][i]*times/le<<endl;
			//fp5<<NODE[node].r[A_X]<<" "<<NODE[node].r[A_Y]<<" "<<F[A_X][i]*times/le<<" "<<F[A_Y][i]*times/le<<endl;
		//	fp5<<ELEM[n].r[A_X]<<" "<<ELEM[n].r[A_Y]<<" "<<Fs<<endl;
		}
	}
	fp5.close();

	////スムージング
	//smoothingF3D(CON,PART,fluid_number,F,t);

	if(CON->get_dir_for_P()==2 ||CON->get_dir_for_P()==3 )
    {
		ofstream bb("electromagnetic_P.dat");
		for(int i=0;i<fluid_number;i++)
		{
			double fs=0;//表面力
			if(PART[i].surface==ON)//内部流体の場合はfs=0とする
			{
				double Fn=sqrt(F[A_X][i]*F[A_X][i]+F[A_Y][i]*F[A_Y][i]);
				fs=Fn/le;
				for(int D=0;D<3;D++) F[D][i]=0;//圧力デ゙ィリクレとして電磁力を使用するのでここでは初期化
			}
			bb<<-fs<<endl;
        }
		bb.close();
	}


	for(int n=0;n<node_num;n++) delete[] matrixC[n];
	delete [] matrixC;
	for(int n=0;n<node_num;n++) delete[] matrixC2[n];
	delete [] matrixC2;
	for(int n=0;n<node_num;n++) delete[] H[n];
	delete [] H;
	for(int n=0;n<node_num;n++) delete[] G[n];
	delete [] G;
	delete [] Bmatrix;

	delete [] Nid;
	delete [] bd_type;
	delete [] BOTH_column;
}
Exemple #14
0
  DescriptorReader(const String& zernike_filename, const String& texture_filename, const String& dc_filename) {
    std::ifstream fp(zernike_filename.c_str());

    String line;
    while (fp) {
      std::getline(fp, line);

      if (line.length() <= 0) continue;

      size_t idx = line.find(" ");

      if (idx != String::npos) {
        String meshname = line.substr(0,idx);
        String descriptorStr = line.substr(idx+1);

        meshname = meshname.substr(meshname.find_last_of('/')+1);
        String meshnamefull = "meerkat:///tahirazim/apiupload/" + meshname + "/optimized/0/" + meshname;

        mZernikeDescriptorMap[meshnamefull] = ZernikeDescriptor(descriptorStr);
 
        meshnamefull = "meerkat:///tahirazim/apiupload/" + meshname + "/original/0/" + meshname;
        mZernikeDescriptorMap[meshnamefull] = ZernikeDescriptor(descriptorStr);


      }
    }

    fp.close();

    std::ifstream fp2(texture_filename.c_str());
    while (fp2) {
      std::getline(fp2, line);

      if (line.length() <= 0) continue;

      size_t idx = line.find(" ");

      if (idx != String::npos) {
        String meshname = line.substr(0,idx);
        String descriptorStr = line.substr(idx+1);

        if (meshname.find("meerkat:///") != 0) {
          //meshname = meshname.substr(meshname.find_last_of('/')+1); //this is no longer needed with ~/all_csds.txt
          String meshnamefull = "meerkat:///tahirazim/apiupload/" + meshname + "/optimized/0/" + meshname;
          mTextureDescriptorMap[meshnamefull] = ZernikeDescriptor(descriptorStr);
          meshnamefull = "meerkat:///tahirazim/apiupload/" + meshname + "/original/0/" + meshname;
          mTextureDescriptorMap[meshnamefull] = ZernikeDescriptor(descriptorStr);
        }
        else {
          mTextureDescriptorMap[meshname] = ZernikeDescriptor(descriptorStr);
        }
      }
    }

    fp2.close();

    std::ifstream fp3(dc_filename.c_str());
    std::getline(fp3, line);
    while (fp3) {
      String meshname=line;
      std::getline(fp3, line);  //texname
      String texname = line;
      String fullname = meshname + ":" + texname;
      std::getline(fp3, line);  //texname again
      std::getline(fp3, line);  //size info
      std::getline(fp3, line);  // sc (spatial coherence info)
      std::getline(fp3, line);  //percentage, color value, color variance table head.

      String value="abcde";
      int r = 0, g = 0, b = 0;
      std::getline(fp3, value);

      int maxPercentage = 0;
      //parse next "value: " line.
      while (value.substr(0,6) == "value:") {

        bool currentIsMax = false;

        char valueline[1024];
        strncpy(valueline, value.c_str(), value.length()+1);
        const char* delim = " :|";
        char* p;
        char*save;
        int count = 0;

        //tokenize the line
#if LIBPROX_PLATFORM == PLATFORM_WINDOWS
#define strtok_threadsafe strtok_s
#else
#define strtok_threadsafe strtok_r
#endif
        for (p=strtok_threadsafe(valueline, delim, &save); p; p = strtok_threadsafe(NULL, delim, &save) ) {
          if (count == 1) {
            int percentValue = atoi(p);
            if (percentValue > maxPercentage && percentValue > 90) {
              maxPercentage = percentValue;
              currentIsMax = true;
            }
          } //end if

          if (currentIsMax) {
            if (count == 2) r = atoi(p);
            if (count == 3) g = atoi(p);
            if (count == 4) b = atoi(p);
          } //end if

          count++;
        } //end for

        std::getline(fp3, value);
      } //end while

      line = value;

      //quantize the r,g,b's
      r = ((r/32)*32) + 16;
      g = ((g/32)*32) + 16;
      b = ((b/32)*32) + 16;

      //add to map.
      std::vector<float> rgb;
      rgb.push_back(r);
      rgb.push_back(g);
      rgb.push_back(b);

      //std::cout << fullname << " : " << r << " " << g << " " << b << "\n";
      if (maxPercentage != 0)
        mDominantColorMap[fullname] = ZernikeDescriptor(rgb);

      //std::cout << fullname << " : " << mDominantColorMap[fullname].toString() << "\n";
    }
    fp3.close();
  }
Exemple #15
0
int main() {
   constants_wrapper cfg;
   cfg.show();
   InitRNG RNG;
   RNG.seed(cfg.SEED);
   int a(0);
   if (!a) std::cout << "TRUEEEEE!!!" << std::endl;
   std::cout << std::endl << std::endl;
   std::cout << "X_MIN = " << cfg.X_MIN << std::endl;
   std::cout << "X_MAX = " << cfg.X_MAX << std::endl;
   std::cout << "Y_MIN = " << cfg.Y_MIN << std::endl;
   std::cout << "Y_MAX = " << cfg.Y_MAX << std::endl;

   std::cout << "READ_FOOD_FROM_FILE = " << cfg.READ_FOOD_FROM_FILE << std::endl;
   std::cout << "FOOD_POINT_DISTRIBUTION = " << cfg.FOOD_POINT_DISTRIBUTION << std::endl;


   chromo beauty_d(beauty_default);
   chromo dim_d(dim_default);
   chromo athlet_d(athlet_default);
   chromo karma_d(karma_default);
   chromo attracted_d(attracted_default);
   chromo charm_d(charm_default);

   DNA dna1(charm_d, beauty_d, dim_d, athlet_d, karma_d, attracted_d);
   DNA dna2(attracted_d, beauty_d, dim_d, athlet_d, karma_d, attracted_d);
   //dna2.set_chromo(c1,5);
   if (dna1 == dna2)  {
      std::cout << "TRUE1" << std::endl;
   } else { std::cout << "qualche problema" << std::endl;
     };
   
   being conf_being(dna1, 0, cfg.starting_energy, true, 1.0, 2.0, 0, 0);
   conf_being.configure(cfg);
   being b1(dna1, 0, cfg.starting_energy, true, 1.0, 2.0, 0, 0);
   //b1.show();
   being b2(dna2, 0, 100, true, 2.0, 2.0, 0, 0);

   food_point fp2(4.1, 4.2, cfg.default_nutrival);
   food_point fp3(1.1, 2.2, cfg.default_nutrival);

   point_2d p1(1,1);
   point_2d p2(2,2);

   // create and open a character archive for output
   std::ofstream ofs("./points.txt");
   // save data to archive
    {
        boost::archive::text_oarchive oa(ofs);
        // write class instance to archive
        oa << p1;
        oa << p2;
        oa << beauty_d;
        oa << dna1;
        oa << b1;
    	// archive and stream closed when destructors are called
    }


    // ... some time later restore the class instance to its orginal state
    point_2d p1new;
    point_2d p2new;
    chromo new_beauty;
    DNA dna1new;
    being b1new;

    {
        // create and open an archive for input
        std::ifstream ifs("./points.txt");
        boost::archive::text_iarchive ia(ifs);
        // read class state from archive
        ia >> p1new;
        ia >> p2new;
        ia >> new_beauty;
        ia >> dna1new;
        ia >> b1new;
        // archive and stream closed when destructors are called
    }

   std::cout << "P1new = ";
   p1new.show_point();
   std::cout << std::endl;

   std::cout << "P2new = ";
   p2new.show_point();
   std::cout << std::endl;

   std::cout << "new beauty = " << new_beauty << std::endl;
   std::cout << "newdna1 = " << dna1new << std::endl;

   if (dna1 == dna1new) std::cout << "TRUE!" << std::endl;

   std::cout << "B1NEW = " << std::endl << b1new << std::endl;

   world myworld(cfg.N_BEINGS,cfg.N_FOOD_POINT_AT_START);
   myworld.name("MyWorld");
   std::cout << "World name = " << myworld.name() << std::endl;
   
   //myworld.add(b1);
   //myworld.add(b2);
   //myworld.add(fp2);
   //myworld.add(fp3);
   //myworld.stats();
   //myworld.advance_one_generation();
   //myworld.stats();

//   myworld.load("DATA/200.txt");
//   myworld.stats();
//   myworld.evolve(1);
//   myworld.stats();

   std::vector<int> iv;
   iv.reserve(10);
   for (int i=0; i<10; ++i) iv.push_back(i);

   std::vector<int>::iterator iv_end = iv.end();
   for (std::vector<int>::iterator it = iv.begin(); it!=iv_end; ++it) {
      std::cout << *it << std::endl;
      iv.push_back(11);
   }

   if (cfg.BEINGS_START_DISTRIBUTION == "UNIFORM") {
      std::uniform_real_distribution<float> beings_distribution_x(cfg.X_MIN , cfg.X_MAX);
      std::uniform_real_distribution<float> beings_distribution_y(cfg.Y_MIN , cfg.Y_MAX);
      for (int i = 0; i < cfg.N_BEINGS; ++i) {
         b1.set_x(beings_distribution_x(RNG.generator));
         b1.set_y(beings_distribution_y(RNG.generator));
         myworld.add(b1) ;
      };
   };

   std::cout << "READ_FOOD_FROM_FILE = " << cfg.READ_FOOD_FROM_FILE << std::endl;
   if (!cfg.READ_FOOD_FROM_FILE) 
   {
      std::cout << "Creating food point from scratch" << std::endl;
      if (cfg.FOOD_POINT_DISTRIBUTION == "UNIFORM") {
         std::uniform_real_distribution<float> food_distribution_x(cfg.X_MIN , cfg.X_MAX);
         std::uniform_real_distribution<float> food_distribution_y(cfg.Y_MIN , cfg.Y_MAX);
         for (int i = 0; i < cfg.N_FOOD_POINT_AT_START; ++i) {
            food_point fpx( food_distribution_x(RNG.generator) , food_distribution_y(RNG.generator) , cfg.default_nutrival );
            myworld.add(fpx) ;
         }
      }
   }
   else 
   {
      std::cout << "Reading food points from file = " << cfg.food_file << std::endl;
      // create and open an archive for input
      std::ifstream ifs2(cfg.food_file);
      boost::archive::text_iarchive ia(ifs2);
      food_point newfp;
      // read class state from archive
      for (int i=0; i<cfg.N_FOOD_POINT_AT_START; ++i) {
         ia >> newfp;
         myworld.add(newfp);
      }
   };
  

   myworld.stats();

   //return 0;
   std::chrono::time_point<std::chrono::high_resolution_clock> start, end;
   start = std::chrono::high_resolution_clock::now();
   myworld.evolve(cfg.ITER_NUMBER);
   end = std::chrono::high_resolution_clock::now();
   cfg.save("myworld.cfg");
   std::cout << "World evolved in = " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms." << std::endl;
/*
   // create and open a character archive for output
   std::ofstream ofs2("./world.txt");
   // save data to archive
    {
        boost::archive::text_oarchive oa(ofs2);
        // write class instance to archive
        oa << myworld;
        // archive and stream closed when destructors are called
    }



    world newworld(1000,1000);


    {
        // create and open an archive for input
        std::ifstream ifs2("./world.txt");
        boost::archive::text_iarchive ia(ifs2);
        // read class state from archive
        ia >> newworld;
        // archive and stream closed when destructors are called
    }


   newworld.stats();
*/
   return 0;
};