コード例 #1
0
ファイル: embeddedGMap3.cpp プロジェクト: vovythevov/SOFA
Dart EmbeddedGMap3::cutEdge(Dart d)
{
    Dart nd = GMap3::cutEdge(d);

    if(isOrbitEmbedded<EDGE>())
    {
        // embed the new darts created in the cut edge
        unsigned int eEmb = getEmbedding<EDGE>(d) ;
        Dart e = d ;
        do
        {
            setDartEmbedding<EDGE>(beta0(e), eEmb) ;
            e = alpha2(e) ;
        } while(e != d) ;

        // embed a new cell for the new edge and copy the attributes' line (c) Lionel
        setOrbitEmbeddingOnNewCell<EDGE>(phi1(d)) ;
        copyCell<EDGE>(phi1(d), d) ;
    }

    if(isOrbitEmbedded<FACE>())
    {
        Dart f = d;
        do
        {
            unsigned int fEmb = getEmbedding<FACE>(f) ;
            setDartEmbedding<FACE>(beta0(f), fEmb);
            setDartEmbedding<FACE>(phi1(f), fEmb);
            setDartEmbedding<FACE>(phi3(f), fEmb);
            setDartEmbedding<FACE>(beta1(phi3(f)), fEmb);
            f = alpha2(f);
        } while(f != d);
    }

    if(isOrbitEmbedded<VOLUME>())
    {
        Dart f = d;
        do
        {
            unsigned int vEmb = getEmbedding<VOLUME>(f) ;
            setDartEmbedding<VOLUME>(beta0(f), vEmb);
            setDartEmbedding<VOLUME>(phi1(f), vEmb);
            setDartEmbedding<VOLUME>(phi2(f), vEmb);
            setDartEmbedding<VOLUME>(beta1(phi2(f)), vEmb);
            f = alpha2(f);
        } while(f != d);
    }

    return nd ;
}
コード例 #2
0
ファイル: xmap.hpp プロジェクト: Peiffert/CGoGN
bool tXMap<DART>::foreach_dart_of_face(Dart d, FunctorType& f, unsigned int thread)
{
	if (foreach_dart_of_oriented_face(d,f,thread)) return true;

	Dart d3 = phi3(d);
	if (d3 != d) return foreach_dart_of_oriented_face(d3,f,thread);
	return false;
}
コード例 #3
0
ファイル: testprog.cpp プロジェクト: cdesrosiers/libqsd
int main() 
{
// Primary Operators
  AnnihilationOperator A1(0);  // 1st freedom
  NumberOperator N1(0);
  IdentityOperator Id1(0);
  AnnihilationOperator A2(1);  // 2nd freedom
  NumberOperator N2(1);
  IdentityOperator Id2(1);
  SigmaPlus Sp(2);             // 3rd freedom
  IdentityOperator Id3(2);
  Operator Sm = Sp.hc();       // Hermitian conjugate
  Operator Ac1 = A1.hc();
  Operator Ac2 = A2.hc();
// Hamiltonian
  double E = 20.0;           
  double chi = 0.4;      
  double omega = -0.7;       
  double eta = 0.001;
  Complex I(0.0,1.0);
  Operator H = (E*I)*(Ac1-A1)
             + (0.5*chi*I)*(Ac1*Ac1*A2 - A1*A1*Ac2)
             + omega*Sp*Sm + (eta*I)*(A2*Sp-Ac2*Sm);
// Lindblad operators
  double gamma1 = 1.0;       
  double gamma2 = 1.0;       
  double kappa = 0.1;        
  const int nL = 3;
  Operator L[nL]={sqrt(2*gamma1)*A1,sqrt(2*gamma2)*A2,sqrt(2*kappa)*Sm};
// Initial state
  State phi1(50,FIELD);       // see paper Section 4.2
  State phi2(50,FIELD);
  State phi3(2,SPIN);
  State stateList[3] = {phi1,phi2,phi3};
  State psiIni(3,stateList);
// Trajectory
  double dt = 0.01;    // basic time step                            
  int numdts = 100;    // time interval between outputs = numdts*dt  
  int numsteps = 5;    // total integration time = numsteps*numdts*dt
  int nOfMovingFreedoms = 2;
  double epsilon = 0.01;     // cutoff probability
  int nPad = 2;              // pad size
  //ACG gen(38388389);            // random number generator with seed
  //ComplexNormal rndm(&gen);     // Complex Gaussian random numbers
  ComplexNormalTest rndm(899101); // Simple portable random number generator
  AdaptiveStep stepper(psiIni, H, nL, L);       // see paper Section 5
// Output
  const int nOfOut = 3;
  Operator outlist[nOfOut]={ Sp*A2*Sm*Sp, Sm*Sp*A2*Sm, A2 };
  char *flist[nOfOut]={"X1.out","X2.out","A2.out"};
  int pipe[] = {1,5,9,11}; // controls standard output (see `onespin.cc')
// Simulate one trajectory (for several trajectories see `onespin.cc')
  Trajectory traj(psiIni, dt, stepper, &rndm);  // see paper Section 5
  traj.plotExp( nOfOut, outlist, flist, pipe, numdts, numsteps,
                nOfMovingFreedoms, epsilon, nPad );
}
コード例 #4
0
inline Dart Map3::phi(Dart d)
{
	assert( (N >0) || !"negative parameters not allowed in template multi-phi");
	if (N<10)
	{
		switch(N)
		{
		case 1 : return phi1(d) ;
		case 2 : return phi2(d) ;
		case 3 : return phi3(d) ;
		default : assert(!"Wrong multi-phi relation value") ; return d ;
		}
	}
	switch(N%10)
	{
	case 1 : return phi1(phi<N/10>(d)) ;
	case 2 : return phi2(phi<N/10>(d)) ;
	case 3 : return phi3(phi<N/10>(d)) ;
	default : assert(!"Wrong multi-phi relation value") ; return d ;
	}
}
コード例 #5
0
ファイル: xmap.hpp プロジェクト: Peiffert/CGoGN
bool tXMap<DART>::foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int thread)
{
	DartMarkerStore m(*this,thread);
	bool found = false;
	std::list<Dart> darts_list;
	darts_list.push_back(d);
	m.mark(d);

	typename std::list<Dart>::iterator prem = darts_list.begin();

	while (!found && prem != darts_list.end())
	{
		Dart d1 = *prem;

		// add phi21 and phi23 successor of they are not yet marked
		Dart d2 = phi1(d1); // turn in face
		Dart d3 = phi2(d1); // change volume
		Dart d4 = phi3(d1); // change volume

		if (!m.isMarked(d2))
		{
			darts_list.push_back(d2);
			m.mark(d2);
		}
		if (!m.isMarked(d3))
		{
			darts_list.push_back(d2);
			m.mark(d2);
		}
		if (!m.isMarked(d4))
		{
			darts_list.push_back(d4);
			m.mark(d4);
		}
		prem++;

		found =  f(d1);	// functor say finish
	}

	return found;
}
コード例 #6
0
inline bool Map3::foreach_dart_of_face(Dart d, FunctorType& f, unsigned int thread)
{
	return Map2::foreach_dart_of_face(d, f, thread) || Map2::foreach_dart_of_face(phi3(d), f, thread);
}
コード例 #7
0
inline bool Map3::isBoundaryFace(Dart d)
{
	return isBoundaryMarked(d) || isBoundaryMarked(phi3(d));
}
コード例 #8
0
inline bool Map3::sameFace(Dart d, Dart e)
{
	return Map2::sameOrientedFace(d, e) || Map2::sameOrientedFace(phi3(d), e) ;
}
コード例 #9
0
inline Dart Map3::alpha_2(Dart d)
{
	return phi2(phi3(d));
}
コード例 #10
0
inline Dart Map3::alpha1(Dart d)
{
	return phi3(phi_1(d)) ;
}
コード例 #11
0
inline Dart Map3::alpha0(Dart d)
{
	return phi3(d) ;
}
コード例 #12
0
 // Approximates the derivative of phi3.
 double CbPotential::phi3_q (const double &q) const
 {
   const double dq = q*EPS;
   return (phi3(q+dq)-phi3(q)) / dq;
 }
コード例 #13
0
/*
Sensible Values for parameter:
 int gridSize=20; //must be divideable by 2
 int globalMaxThreshold=255;
 int globalMinThreshold=50;  //30;
 
*/
int OtsuThresholdingWithParameter(densityDataType data, ucharDataType target, int globalMinThreshold, int globalMaxThreshold, int gridSize)
{

    
    unsigned char *image= (unsigned char *) malloc (data.sizeX*data.sizeY*sizeof (unsigned char));
    
    int rows=data.sizeY; 
    int cols=data.sizeX; 
    int x0=1; 
    int y0=1; 
    int dx=12;
    int dy=12;
    int vvv=0;// No out put exept of errors
    
    int z;
    for (z=0;z<data.sizeX*data.sizeY;z++) image[z]=(unsigned char)  ( (float) 255.0 * data.data[z]);
    
 /*   
    int gridSize=20; //must be divideable by 2
    int globalMaxThreshold=255;
    int globalMinThreshold=50;  //30;
   */ 
    
    
    
    
    int gridX=data.sizeX/gridSize+1;
    int gridY=data.sizeY/gridSize+1;
    
    unsigned char *thresholdValues= (unsigned char*) malloc (sizeof(unsigned char)*gridX*gridY);
    unsigned char thresholdResult;
    
    
    int gY, gX;
    for(gY=1;gY<(gridY-1);gY++) //starts at 1 befor no full element before, stops 1 before because no full elment out there
	for (gX=1;gX<(gridX-1);gX++)
	{
	    x0=gX*gridSize-gridSize/2;//move mid point 
	    y0=gY*gridSize-gridSize/2;
	    dx=gridSize;
	    dy=gridSize;
	    
	    thresholdResult=(unsigned char) otsu (image, rows, cols, x0, y0, dx, dy, vvv);
	    if (thresholdResult>globalMaxThreshold) thresholdResult=globalMaxThreshold;
	    if (thresholdResult<globalMinThreshold) thresholdResult=globalMinThreshold;
	    thresholdValues[gX+gY*gridX]= thresholdResult;
	};      
    
    
    //The boundary threshold has to be calcultaed different
    
    for(gY=1;gY<(gridY-1);gY++) //Boundary is maxium threshold
    {
	gX=gridX-1;
	x0=gX*gridSize-gridSize;//move mid point 
	    y0=gY*gridSize-gridSize/2;
	    dx=gridSize;
	    dy=gridSize;
	    
	    thresholdResult=(unsigned char) otsu (image, rows, cols, x0, y0, dx, dy, vvv);
	    if (thresholdResult>globalMaxThreshold) thresholdResult=globalMaxThreshold;
	    if (thresholdResult<globalMinThreshold) thresholdResult=globalMinThreshold;
	    thresholdValues[(gridX-1)+gY*gridX]= thresholdResult;
	    
    };  
    
    
    for(gY=1;gY<(gridY-1);gY++) //Boundary is maxium threshold
    {
	gX=0;
	x0=gX*gridSize;//move mid point 
	    y0=gY*gridSize-gridSize/2;
	    dx=gridSize;
	    dy=gridSize;
	    
	    thresholdResult=(unsigned char) otsu (image, rows, cols, x0, y0, dx, dy, vvv);
	    if (thresholdResult>globalMaxThreshold) thresholdResult=globalMaxThreshold;
	    if (thresholdResult<globalMinThreshold) thresholdResult=globalMinThreshold;
	    thresholdValues[0+gY*gridX]= thresholdResult;
    };   
    
    
    for (gX=1;gX<(gridX-1);gX++) //Boundary is maxium threshold
    {
	gY=0;
	x0=gX*gridSize-gridSize/2; /*move mid point*/ 
	y0=gY*gridSize;
	dx=gridSize;
	dy=gridSize;
	
	thresholdResult=(unsigned char) otsu (image, rows, cols, x0, y0, dx, dy, vvv);
	if (thresholdResult>globalMaxThreshold) thresholdResult=globalMaxThreshold;
	if (thresholdResult<globalMinThreshold) thresholdResult=globalMinThreshold;
	thresholdValues[gX+0*gridX]= thresholdResult;
	
    };
    
    for (gX=1;gX<(gridX-1);gX++) //Boundary is maxium threshold
    {
	gY=gridY-1;
	x0=gX*gridSize-gridSize/2; /*move mid point*/ 
	y0=gY*gridSize-gridSize;
	dx=gridSize;
	dy=gridSize;
	
	thresholdResult=(unsigned char) otsu (image, rows, cols, x0, y0, dx, dy, vvv);
	if (thresholdResult>globalMaxThreshold) thresholdResult=globalMaxThreshold;
	if (thresholdResult<globalMinThreshold) thresholdResult=globalMinThreshold;
	thresholdValues[gX+(gridY-1)*gridX]= thresholdResult;
	
    };
    
    //The four corners in a other way
    //Corner1
    gX=0;
    gY=0;
    x0=gX*gridSize; /*move mid point*/ 
    y0=gY*gridSize;
    dx=gridSize;
    dy=gridSize;
    thresholdResult=(unsigned char) otsu (image, rows, cols, x0, y0, dx, dy, vvv);
    if (thresholdResult>globalMaxThreshold) thresholdResult=globalMaxThreshold;
    if (thresholdResult<globalMinThreshold) thresholdResult=globalMinThreshold;
    thresholdValues[gX+gY*gridX]= thresholdResult;
    
    //Corner2
    gX=gridX-1;
    gY=0;
    x0=gX*gridSize-gridSize; /*move mid point*/ 
    y0=gY*gridSize;
    dx=gridSize;
    dy=gridSize;
    thresholdResult=(unsigned char) otsu (image, rows, cols, x0, y0, dx, dy, vvv);
    if (thresholdResult>globalMaxThreshold) thresholdResult=globalMaxThreshold;
    if (thresholdResult<globalMinThreshold) thresholdResult=globalMinThreshold;
    thresholdValues[gX+gY*gridX]= thresholdResult;
    
    //Corner3
    gX=0;
    gY=gridY-1;
    x0=gX*gridSize; /*move mid point*/ 
    y0=gY*gridSize-gridSize;
    dx=gridSize;
    dy=gridSize;
    thresholdResult=(unsigned char) otsu (image, rows, cols, x0, y0, dx, dy, vvv);
    if (thresholdResult>globalMaxThreshold) thresholdResult=globalMaxThreshold;
    if (thresholdResult<globalMinThreshold) thresholdResult=globalMinThreshold;
    thresholdValues[gX+gY*gridX]= thresholdResult;
    
    //Corner4
    gX=gridX-1;
    gY=gridY-1;
    x0=gX*gridSize-gridSize; /*move mid point*/ 
    y0=gY*gridSize-gridSize;
    dx=gridSize;
    dy=gridSize;
    thresholdResult=(unsigned char) otsu (image, rows, cols, x0, y0, dx, dy, vvv);
    if (thresholdResult>globalMaxThreshold) thresholdResult=globalMaxThreshold;
    if (thresholdResult<globalMinThreshold) thresholdResult=globalMinThreshold;
    thresholdValues[gX+gY*gridX]= thresholdResult;
    
    //Elementwise Interpolation 
    for( gY=0;gY<(gridY-1);gY++) 
	for ( gX=0;gX<(gridX-1);gX++)
	{
	    x0=gX*gridSize;
	    y0=gY*gridSize;
	    
	    int Node1=thresholdValues[gX+gY*gridX];
	    int Node2=thresholdValues[(gX+1)+gY*gridX];
	    int Node3=thresholdValues[gX+(gY+1)*gridX];
	    int Node4=thresholdValues[(gX+1)+(gY+1)*gridX];
	    
	    
	    int x,y;
	    for (y=0;y<gridSize;y++) 
		for (x=0;x<gridSize;x++) 
		{	
		    float psi=(float) x/gridSize;
		    float mu=(float) y/gridSize;
		    
		    float thresholdResult=(float) phi1(psi,mu)*Node1+phi2(psi,mu)*Node2+phi3(psi,mu)*Node3+phi4(psi,mu)*Node4;
		    
		    //printf("x:%d y:%d\n",x,y);
		    if (image[(x+x0)+(y+y0)*data.sizeX]>thresholdResult)
		    {
			SetBinaryDataAtPoint(target,(x+x0),(y+y0),1);
		    }
		    else
		    {
			SetBinaryDataAtPoint(target,(x+x0),(y+y0),0);
		    };
		};
	    
	};      
    
    
    return 0;
}