void IPDWRITELATEX(Word r, Word A, Word V) { Word Ap,E,Ep,Vp,a,e,l,s,t,v; Step1: /* r=0 or A=0. */ Ap = DIPFP(r,A); if (r == 0 || Ap == 0) { IWRITE(Ap); goto Return; } l = 1; Step2: /* General case. */ do { ADV2(Ap,&a,&E,&Ap); s = ISIGNF(a); a = IABSF(a); if (s > 0 && l == 0) CWRITE('+'); if (s < 0) CWRITE('-'); if (a != 1) { if (l == 0) CWRITE(' '); IWRITE(a); t = 1; } else t = 0; Ep = CINV(E); Vp = V; do { ADV(Ep,&e,&Ep); ADV(Vp,&v,&Vp); if (e > 0) { if (l == 0 || t == 1) CWRITE(' '); VWRITE(v); t = 1; } if (e > 1) { CWRITE('^'); CWRITE('{'); AWRITE(e); } CWRITE('}'); } while (Ep != NIL); if (t == 0) { if (l == 0) CWRITE(' '); CWRITE('1'); } if (Ap == NIL) goto Return; CWRITE(' '); l = 0; } while (1); Return: /* Prepare for return. */ return; }
void stop() { ADJ_D_Time = ACLOCK() - ADJ_D_Time; SWRITE("\nADJ_2D took "); IWRITE(ADJ_D_Time); SWRITE(" millseconds.\n"); }
void SIPWRITE(Word *P, BDigit p, BDigit k) { BDigit wii, i; wii = 2*(p + 3); // words in interval for(i = P[0]; i >= 0; i--) { SIDWRITE(P + 1 + i*wii,k); SWRITE(" x^"); IWRITE(i); if (i > 0) SWRITE(" + "); } }
/* * sac_to_gmp() assumes that the incoming integer really is a bignum and is * not representable as a machine precision integer. If the argument sac is * machine precision, the while loop becomes infinite (this is bad). * * On entry I also assume that the caller has initialized gmp_int. */ static void sac_to_gmp(mpz_ptr gmp_int, Word sac) { short set_neg_flag = -1; /* when set, this will be 0 or 1 */ MP_INT pwr, temp; Word lsac, d; #ifdef MP_DEBUG fprintf(stderr, "sac_to_gmp: entering, the bignum here is "); IWRITE(sac);printf("\n"); fflush(stderr); #endif if (ISATOM(sac)) { if (sac < 0) { set_neg_flag = 1; sac = -sac; } else set_neg_flag = 0; mpz_set_si(gmp_int, (int) sac); if (set_neg_flag) mpz_neg(gmp_int, gmp_int); return; } ADV(sac, &d, &lsac); mpz_init(&pwr); mpz_set_si(&pwr, 1); if (d != 0) { set_neg_flag = (d < 0) ? 1 : 0; if (set_neg_flag) d = -d; } mpz_set_si(gmp_int, d); mpz_init(&temp); while (!ISNIL(lsac)) { mpz_mul_ui(&pwr, &pwr, BETA); ADV(lsac, &d, &lsac); if (d != 0) { mpz_clear(&temp); /* Argh!! We need to keep checking because we may have had all leading zeroes to this point! */ if (set_neg_flag == -1) set_neg_flag = (d < 0) ? 1 : 0; if (set_neg_flag) d = -d; mpz_mul_ui(&temp, &pwr, d); mpz_add(gmp_int, gmp_int, &temp); } } if (set_neg_flag) mpz_neg(gmp_int, gmp_int); #ifdef MP_DEBUG fprintf(stderr,"sac_to_gmp: exiting\n");fflush(stderr); #endif return; }
int sacMain() { Word V,B,t,Vx,M,L,Lp,i,k = 20; Word wii, p, J, *I , *Bp; /* Read bivariate polynomial */ V = LIST2(LFS("x"),LFS("y")); SWRITE("Enter B, a polynomial in x and y : "); IPEXPREADR(2,V,&B,&t); if (!t) { SWRITE("Polynomial read unsuccessfull!\n"); return 1; } else { SWRITE("Polynomial read in is: "); IPDWRITE(2,B,V); SWRITE("\n"); } /* Get precision */ SWRITE("Enter precision: "); p = IREAD(); SWRITE("Precision read is: "); IWRITE(p); SWRITE("\n"); /* Read Interval */ SWRITE("Enter binary rational interval: "); J = LBRIREAD(); /* Sub! */ Bp = GETARRAY(1 + (PDEG(B) + 1)*2*(p + 3)); IBPELBRISIPR(B,J,p,Bp); SWRITE("Evaluation result is : "); SIPWRITE(Bp,p,k); SWRITE("\n"); return 0; }
Word NECCONDS(Word L_T, Word L_F, Word L_A, Word P) { Word SF,Lp,N,a,t,Fp,SFp,A,n,S,f,S_f,T,I,i,Ap,L; Word t1,t2,t3; t1 = ACLOCK(); Step1: /* Construct N, the list of necessary conditions. */ for(Lp = CINV(L_A), N = NIL; Lp != NIL; Lp = RED(Lp)) { a = FIRST(Lp); for(t = TRUE,T = L_T; t == TRUE && T != NIL; T = RED(T)) t = FMACELLEVAL(a,FIRST(T),P); if (t == TRUE) N = COMP(a,N); } Step2: /* Construct Fp, the list of false cells satisfying N. */ for(Lp = CINV(L_F), Fp = NIL; Lp != NIL; Lp = RED(Lp)) if (FMACELLEVAL(COMP(ANDOP,N),FIRST(Lp),P) != FALSE) Fp = COMP(FIRST(Lp),Fp); t1 = ACLOCK() - t1; t2 = ACLOCK(); Step3: /* Construct formula for simplified problem. */ SFp = NAIVESF(L_T,Fp,L_A,P); t2 = ACLOCK() - t2; t3 = ACLOCK(); Step4: /* Construct Fp, the list of false cells satisfying SFp. */ for(Lp = CINV(L_F), Fp = NIL; Lp != NIL; Lp = RED(Lp)) if (FMACELLEVAL(SFp,FIRST(Lp),P) != FALSE) Fp = COMP(FIRST(Lp),Fp); if (Fp == NIL) { SF = SFp; goto Return; } Step5: /* Construct the minimum hitting set problem. */ A = CINV(N); n = LENGTH(A); for(S = NIL; Fp != NIL; Fp = RED(Fp)) { f = FIRST(Fp); S_f = NIL; for(i = n, Ap = A; Ap != NIL; i--,Ap = RED(Ap)) if (FMACELLEVAL(FIRST(Ap),f,P) == FALSE) S_f = COMP(i,S_f); S = COMP(S_f,S); } Step6: /* Get the hitting set. */ T = MINHITSETSR(S,-1); Step7: /* Convert hitting set to a formula. */ T = LBIBMS(T); for(I = NIL, L = N, i = 1; T != NIL; i++, L = RED(L)) if (i == FIRST(T)) { T = RED(T); I = COMP(FIRST(L),I); } if (LENGTH(I) == 1) I = FIRST(I); else I = COMP(ANDOP,INV(I)); Step8: /* Join I and SFp. */ SF = LIST3(ANDOP,I,SFp); Return: /* Prepare to return. */ t3 = ACLOCK() - t3; if (PCVERBOSE) { SWRITE("\nNECCONDS: t1 = ");IWRITE(t1);SWRITE(" t2 = "); IWRITE(t2);SWRITE(" t3 = ");IWRITE(t3);SWRITE("\n\n"); } return SF; }
void GeometryBuilder::BuildSphere( int _PhiSubdivisions, int _ThetaSubdivisions, IGeometryWriter& _Writer, const MapperBase* _pMapper, TweakVertexDelegate _TweakVertex, void* _pUserData ) { int BandLength = _PhiSubdivisions; int VerticesCount = (BandLength+1) * (1 + _ThetaSubdivisions + 1); // 1 band at the top and bottom of the sphere + as many subdivisions as required int BandsCount = 1 + _ThetaSubdivisions; int IndicesCount = (2*(BandLength+1+1)) * BandsCount - 2; // Create the buffers void* pVerticesArray = NULL; void* pIndicesArray = NULL; _Writer.CreateBuffers( VerticesCount, IndicesCount, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, pVerticesArray, pIndicesArray ); ASSERT( pVerticesArray != NULL, "Invalid vertex buffer !" ); ASSERT( pIndicesArray != NULL, "Invalid index buffer !" ); void* pVertex = pVerticesArray; void* pIndex = pIndicesArray; ////////////////////////////////////////////////////////////////////////// // Build vertices float3 Position, Normal, Tangent, BiTangent; float2 UV; // Top band { for ( int i=0; i <= BandLength; i++ ) { float Phi = TWOPI * i / BandLength; Tangent.x = cosf( Phi ); Tangent.y = 0.0f; Tangent.z = -sinf( Phi ); // Create a dummy position that is slightly offseted from the top of the sphere so UVs are not all identical Position.y = 1.0f; Position.x = -0.001f * Tangent.z; Position.z = 0.001f * Tangent.x; // Position.Normalize(); Normal = Position; Normal.Normalize(); BiTangent = Normal.Cross( Tangent ); // Ask for UVs if ( _pMapper ) _pMapper->Map( Position, Normal, Tangent, UV, i == BandLength ); else UV.Set( 2.0f * float(i) / BandLength, 0.0f ); Position.x = Position.z = 0.0f; // Write vertex VWRITE( pVertex, float3::UnitY, float3::UnitY, Tangent, BiTangent, UV ); } } // Generic bands for ( int j=0; j < _ThetaSubdivisions; j++ ) { float Theta = PI * (1+j) / (1 + _ThetaSubdivisions); for ( int i=0; i <= BandLength; i++ ) { float Phi = TWOPI * i / BandLength; Position.x = sinf( Phi ) * sinf( Theta ); Position.y = cosf( Theta ); Position.z = cosf( Phi ) * sinf( Theta ); Normal = Position; Tangent.x = cosf( Phi ); Tangent.y = 0.0f; Tangent.z = -sinf( Phi ); BiTangent = Normal.Cross( Tangent ); // Ask for UVs if (_pMapper ) _pMapper->Map( Position, Normal, Tangent, UV, i == BandLength ); else UV.Set( 2.0f * float(i) / BandLength, float(j) / _ThetaSubdivisions ); // Write vertex VWRITE( pVertex, Position, Normal, Tangent, BiTangent, UV ); } } // Bottom band { for ( int i=0; i <= BandLength; i++ ) { float Phi = TWOPI * i / BandLength; Tangent.x = cosf( Phi ); Tangent.y = 0.0f; Tangent.z = -sinf( Phi ); // Create a dummy position that is slightly offseted from the bottom of the sphere so UVs are not all identical Position.y = -1.0f; Position.x = -0.001f * Tangent.z; Position.z = 0.001f * Tangent.x; // Position.Normalize(); Normal = Position; Normal.Normalize(); BiTangent = Normal.Cross( Tangent ); // Ask for UVs if ( _pMapper ) _pMapper->Map( Position, Normal, Tangent, UV, i == BandLength ); else UV.Set( 2.0f * float(i) / BandLength, 1.0f ); Position.x = Position.z = 0.0f; // Write vertex VWRITE( pVertex, -float3::UnitY, -float3::UnitY, Tangent, BiTangent, UV ); } } ASSERT( VerticesCount == 0, "Wrong contruction!" ); ////////////////////////////////////////////////////////////////////////// // Build indices for ( int j=0; j < BandsCount; j++ ) { int CurrentBandOffset = j * (BandLength+1); int NextBandOffset = (j+1) * (BandLength+1); for ( int i=0; i <= BandLength; i++ ) { IWRITE( pIndex, CurrentBandOffset + i ); IWRITE( pIndex, NextBandOffset + i ); } if ( j == BandsCount-1 ) continue; // Not for the last band... // Write 2 last degenerate indices so we smoothly transition to next band IWRITE( pIndex, NextBandOffset + BandLength ); IWRITE( pIndex, NextBandOffset + BandLength+1 ); } ASSERT( IndicesCount == 0, "Wrong contruction!" ); ////////////////////////////////////////////////////////////////////////// // Finalize _Writer.Finalize( pVerticesArray, pIndicesArray ); }
void GeometryBuilder::BuildCube( int _SubdivisionsX, int _SubdivisionsY, int _SubdivisionsZ, IGeometryWriter& _Writer, const MapperBase* _pMapper, TweakVertexDelegate _TweakVertex, void* _pUserData ) { ASSERT( _SubdivisionsX > 0 && _SubdivisionsY > 0 && _SubdivisionsZ > 0, "Can't create a cube with 0 subdivision!" ); int SizeX = _SubdivisionsX+1; int SizeY = _SubdivisionsY+1; int SizeZ = _SubdivisionsZ+1; int VerticesCount = 2*(SizeX*SizeY + SizeX*SizeZ + SizeY*SizeZ); int IndicesCount = 2*( (2*(SizeZ+1) * _SubdivisionsY - 2) + (2*(SizeX+1) * _SubdivisionsZ - 2) + (2*(SizeX+1) * _SubdivisionsZ - 2) ) + 2*5; // Create the buffers void* pVerticesArray = NULL; void* pIndicesArray = NULL; _Writer.CreateBuffers( VerticesCount, IndicesCount, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, pVerticesArray, pIndicesArray ); ASSERT( pVerticesArray != NULL, "Invalid vertex buffer !" ); ASSERT( pIndicesArray != NULL, "Invalid index buffer !" ); void* pVertex = pVerticesArray; void* pIndex = pIndicesArray; ////////////////////////////////////////////////////////////////////////// // Build vertices float3 pNormals[6] = { -float3::UnitX, float3::UnitX, -float3::UnitY, float3::UnitY, -float3::UnitZ, float3::UnitZ, }; float3 pTangents[6] = { float3::UnitZ, -float3::UnitZ, float3::UnitX, float3::UnitX, -float3::UnitX, float3::UnitX, }; int pSizesX[6] = { SizeZ, SizeZ, SizeX, SizeX, SizeX, SizeX }; int pSizesY[6] = { SizeY, SizeY, SizeZ, SizeZ, SizeZ, SizeZ }; float3 Position, Normal, X, Y; float2 UV; for ( int FaceIndex=0; FaceIndex < 6; FaceIndex++ ) { int Sx = pSizesX[FaceIndex]; int Sy = pSizesY[FaceIndex]; Normal = pNormals[FaceIndex]; X = pTangents[FaceIndex]; Y = Normal.Cross( X ); for ( int j=0; j < Sy; j++ ) { float y = 1.0f - 2.0f * float(j) / (Sy-1); for ( int i=0; i < Sx; i++ ) { float x = 2.0f * float(i) / (Sx-1) - 1.0f; Position = Normal + x * X + y * Y; if ( _pMapper ) _pMapper->Map( Position, Normal, X, UV, false ); else UV.Set( 0.5f * (1.0f + x), 0.5f * (1.0f + y) ); VWRITE( pVertex, Position, Normal, X, Y, UV ); } } } ASSERT( VerticesCount == 0, "Wrong contruction!" ); ////////////////////////////////////////////////////////////////////////// // Build indices int FaceOffset = 0; for ( int FaceIndex=0; FaceIndex < 6; FaceIndex++ ) { int Sx = pSizesX[FaceIndex]; int Sy = pSizesY[FaceIndex]; if ( FaceIndex > 0 ) { // Write a first degenerate vertex for that face to make a clean junction with previous face... IWRITE( pIndex, FaceOffset+0 ); } for ( int j=0; j < Sy-1; j++ ) { int CurrentBandOffset = FaceOffset + j * Sx; int NextBandOffset = FaceOffset + (j+1) * Sx; for ( int i=0; i < Sx; i++ ) { IWRITE( pIndex, CurrentBandOffset + i ); IWRITE( pIndex, NextBandOffset + i ); } if ( j == _SubdivisionsY-1 ) continue; // Not for the last band... // Write 2 last degenerate indices so we smoothly transition to next band IWRITE( pIndex, NextBandOffset+Sx-1 ); IWRITE( pIndex, NextBandOffset ); } FaceOffset += Sx*Sy; if ( FaceIndex < 5 ) { // Write one last degenerate vertex for that face to make a clean junction with next face... IWRITE( pIndex, FaceOffset-1 ); } } ASSERT( IndicesCount == 0, "Wrong contruction!" ); ////////////////////////////////////////////////////////////////////////// // Finalize _Writer.Finalize( pVerticesArray, pIndicesArray ); }
void GeometryBuilder::BuildPlane( int _SubdivisionsX, int _SubdivisionsY, const float3& _X, const float3& _Y, IGeometryWriter& _Writer, const MapperBase* _pMapper, TweakVertexDelegate _TweakVertex, void* _pUserData ) { ASSERT( _SubdivisionsX > 0 && _SubdivisionsY > 0, "Can't create a plane with 0 subdivision!" ); int VerticesCount = (_SubdivisionsX+1) * (_SubdivisionsY+1); int IndicesCount = 2*(_SubdivisionsX+1+1) * _SubdivisionsY - 2; // Create the buffers void* pVerticesArray = NULL; void* pIndicesArray = NULL; _Writer.CreateBuffers( VerticesCount, IndicesCount, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, pVerticesArray, pIndicesArray ); ASSERT( pVerticesArray != NULL, "Invalid vertex buffer !" ); ASSERT( pIndicesArray != NULL, "Invalid index buffer !" ); void* pVertex = pVerticesArray; void* pIndex = pIndicesArray; ////////////////////////////////////////////////////////////////////////// // Build vertices float3 Tangent = _X; Tangent.Normalize(); float3 BiTangent = _Y; BiTangent.Normalize(); float3 Normal = Tangent.Cross( BiTangent ); Normal.Normalize(); float3 Position; float2 UV; for ( int j=0; j <= _SubdivisionsY; j++ ) { float Y = 1.0f - 2.0f * j / _SubdivisionsY; for ( int i=0; i <= _SubdivisionsX; i++ ) { float X = 2.0f * i / _SubdivisionsX - 1.0f; Position = X * _X + Y * _Y; if ( _pMapper ) _pMapper->Map( Position, Normal, Tangent, UV, false ); else UV.Set( float(i) / _SubdivisionsX, float(j) / _SubdivisionsY ); VWRITE( pVertex, Position, Normal, Tangent, BiTangent, UV ); } } ASSERT( VerticesCount == 0, "Wrong contruction!" ); ////////////////////////////////////////////////////////////////////////// // Build indices for ( int j=0; j < _SubdivisionsY; j++ ) { int CurrentBandOffset = j * (_SubdivisionsX+1); int NextBandOffset = (j+1) * (_SubdivisionsX+1); for ( int i=0; i <= _SubdivisionsX; i++ ) { IWRITE( pIndex, CurrentBandOffset + i ); IWRITE( pIndex, NextBandOffset + i ); } if ( j == _SubdivisionsY-1 ) continue; // Not for the last band... // Write 2 last degenerate indices so we smoothly transition to next band IWRITE( pIndex, NextBandOffset+_SubdivisionsX ); IWRITE( pIndex, NextBandOffset ); } ASSERT( IndicesCount == 0, "Wrong contruction!" ); ////////////////////////////////////////////////////////////////////////// // Finalize _Writer.Finalize( pVerticesArray, pIndicesArray ); }
void GeometryBuilder::BuildTorus( int _PhiSubdivisions, int _ThetaSubdivisions, float _LargeRadius, float _SmallRadius, IGeometryWriter& _Writer, const MapperBase* _pMapper, TweakVertexDelegate _TweakVertex, void* _pUserData ) { int BandLength = _ThetaSubdivisions; int BandsCount = _PhiSubdivisions; int VerticesCount = BandsCount * (BandLength+1); int IndicesCount = 2*(BandLength+1+1) * BandsCount - 2; // Create the buffers void* pVerticesArray = NULL; void* pIndicesArray = NULL; _Writer.CreateBuffers( VerticesCount, IndicesCount, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, pVerticesArray, pIndicesArray ); ASSERT( pVerticesArray != NULL, "Invalid vertex buffer !" ); ASSERT( pIndicesArray != NULL, "Invalid index buffer !" ); void* pVertex = pVerticesArray; void* pIndex = pIndicesArray; ////////////////////////////////////////////////////////////////////////// // Build vertices float3 Position, Normal, Tangent, BiTangent; float2 UV; for ( int j=0; j < BandsCount; j++ ) { float Phi = TWOPI * j / BandsCount; float3 X( cosf(Phi), sinf(Phi), 0.0f ); // Radial branch in X^Y plane at this angle float3 Center = _LargeRadius * X; // Center of the small ring Tangent.x = -sinf(Phi); Tangent.y = cosf(Phi); Tangent.z = 0.0f; for ( int i=0; i <= BandLength; i++ ) { float Theta = TWOPI * i / BandLength; Normal = cosf(Theta) * X + sinf(Theta) * float3::UnitZ; Position = Center + _SmallRadius * Normal; BiTangent = Normal.Cross( Tangent ); if ( _pMapper ) _pMapper->Map( Position, Normal, Tangent, UV, i == BandLength ); else UV.Set( 4.0f * float(j) / BandsCount, float(j) / BandLength ); VWRITE( pVertex, Position, Normal, Tangent, BiTangent, UV ); } } ASSERT( VerticesCount == 0, "Wrong contruction!" ); ////////////////////////////////////////////////////////////////////////// // Build indices for ( int j=0; j < BandsCount; j++ ) { int CurrentBandOffset = j * (BandLength+1); int NextBandOffset = ((j+1) % _PhiSubdivisions) * (BandLength+1); int NextNextBandOffset = ((j+2) % _PhiSubdivisions) * (BandLength+1); for ( int i=0; i <= BandLength; i++ ) { IWRITE( pIndex, CurrentBandOffset + i ); IWRITE( pIndex, NextBandOffset + i ); } if ( j == BandsCount-1 ) continue; // Not for the last band... // Write 2 last degenerate indices so we smoothly transition to next band IWRITE( pIndex, NextBandOffset + BandLength ); IWRITE( pIndex, NextNextBandOffset ); } ASSERT( IndicesCount == 0, "Wrong contruction!" ); ////////////////////////////////////////////////////////////////////////// // Finalize _Writer.Finalize( pVerticesArray, pIndicesArray ); }
void GeometryBuilder::BuildCylinder( int _RadialSubdivisions, int _VerticalSubdivisions, bool _bIncludeCaps, IGeometryWriter& _Writer, const MapperBase* _pMapper, TweakVertexDelegate _TweakVertex, void* _pUserData ) { ASSERT( _RadialSubdivisions > 1, "Can't create a cylinder with less than 2 radial subdivisions!" ); ASSERT( _VerticalSubdivisions > 0, "Can't create a cylinder with 0 vertical subdivisions!" ); int BandLength = 1+_RadialSubdivisions; int BandsCount = _bIncludeCaps ? 1 + (1+_VerticalSubdivisions) + 1 : 1+_VerticalSubdivisions; // 1 band at the top and bottom for the optional caps + as many subdivisions as required int VerticesCount = BandLength * BandsCount; int IndicesCount = 2 * (BandLength+1) * (BandsCount-1) - 2; // Create the buffers void* pVerticesArray = NULL; void* pIndicesArray = NULL; _Writer.CreateBuffers( VerticesCount, IndicesCount, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, pVerticesArray, pIndicesArray ); ASSERT( pVerticesArray != NULL, "Invalid vertex buffer !" ); ASSERT( pIndicesArray != NULL, "Invalid index buffer !" ); void* pVertex = pVerticesArray; void* pIndex = pIndicesArray; ////////////////////////////////////////////////////////////////////////// // Build vertices float3 Position, Normal, Tangent, BiTangent; float2 UV; // Top vertices if ( _bIncludeCaps ) { for ( int i=0; i <= _RadialSubdivisions; i++ ) { float Phi = TWOPI * i / _RadialSubdivisions; Tangent.x = cosf( Phi ); Tangent.y = 0.0f; Tangent.z = -sinf( Phi ); // Create a dummy position that is slightly offseted from the top of the sphere so UVs are not all identical Position.y = 1.0f; Position.x = -0.001f * Tangent.z; Position.z = 0.001f * Tangent.x; Normal = float3::UnitY; BiTangent = Normal.Cross( Tangent ); // Ask for UVs if ( _pMapper ) _pMapper->Map( Position, Normal, Tangent, UV, i == _RadialSubdivisions ); else UV.Set( 2.0f * float(i) / _RadialSubdivisions, 0.0f ); Position.x = Position.z = 0.0f; // Write vertex VWRITE( pVertex, float3::UnitY, float3::UnitY, Tangent, BiTangent, UV ); } } // Generic bands for ( int j=0; j <= _VerticalSubdivisions; j++ ) { float Y = 1.0f - 2.0f * j / _VerticalSubdivisions; for ( int i=0; i <= _RadialSubdivisions; i++ ) { float Phi = TWOPI * i / _RadialSubdivisions; Position.x = sinf( Phi ); Position.y = Y; Position.z = cosf( Phi ); Normal.x = sinf( Phi ); Normal.y = 0; Normal.z = cosf( Phi ); Tangent.x = cosf( Phi ); Tangent.y = 0.0f; Tangent.z = -sinf( Phi ); BiTangent = Normal.Cross( Tangent ); // Ask for UVs if ( _pMapper ) _pMapper->Map( Position, Normal, Tangent, UV, i == _RadialSubdivisions ); else UV.Set( 2.0f * float(i) / _RadialSubdivisions, float(j) / _VerticalSubdivisions ); // Write vertex VWRITE( pVertex, Position, Normal, Tangent, BiTangent, UV ); } } // Bottom band if ( _bIncludeCaps ) { for ( int i=0; i <= _RadialSubdivisions; i++ ) { float Phi = TWOPI * i / _RadialSubdivisions; Tangent.x = cosf( Phi ); Tangent.y = 0.0f; Tangent.z = -sinf( Phi ); // Create a dummy position that is slightly offseted from the bottom of the sphere so UVs are not all identical Position.y = -1.0f; Position.x = -0.001f * Tangent.z; Position.z = 0.001f * Tangent.x; Normal = -float3::UnitY; BiTangent = Normal.Cross( Tangent ); // Ask for UVs if ( _pMapper ) _pMapper->Map( Position, Normal, Tangent, UV, i == _RadialSubdivisions ); else UV.Set( 2.0f * float(i) / _RadialSubdivisions, 1.0f ); Position.x = Position.z = 0.0f; // Write vertex VWRITE( pVertex, -float3::UnitY, -float3::UnitY, Tangent, BiTangent, UV ); } } ASSERT( VerticesCount == 0, "Wrong contruction!" ); ////////////////////////////////////////////////////////////////////////// // Build indices for ( int j=0; j < BandsCount-1; j++ ) { int CurrentBandOffset = j * BandLength; int NextBandOffset = (j+1) * BandLength; for ( int i=0; i < BandLength; i++ ) { IWRITE( pIndex, CurrentBandOffset + i ); IWRITE( pIndex, NextBandOffset + i ); } if ( j == BandsCount-2 ) continue; // Not for the last band... // Write 2 last degenerate indices so we smoothly transition to next band IWRITE( pIndex, NextBandOffset + BandLength-1 ); IWRITE( pIndex, NextBandOffset + BandLength ); } ASSERT( IndicesCount == 0, "Wrong contruction!" ); ////////////////////////////////////////////////////////////////////////// // Finalize _Writer.Finalize( pVerticesArray, pIndicesArray ); }
static void print() { SWRITE("\n\nk = "); IWRITE(k); SWRITE("\n\n"); }
Word QepcadCls::PROJMCmod(Word r, Word A) { Word A1,A2,Ap,Ap1,Ap2,App,D,L,Lh,P,R,W,i,t,Q,j,S,Sp; Step1: /* Obtain coefficients. */ P = NIL; Ap = A; while (Ap != NIL) { ADV(Ap,&A1,&Ap); Ap1 = LELTI(A1,PO_POLY); /* Deal with projection points! */ if (LELTI(A1,PO_TYPE) == PO_POINT) { W = MPOLY(RED(Ap1),NIL,LIST1(LIST2(PT_PRJ,A1)),PO_POINT,PO_KEEP); P = COMP(W,P); continue; } /* Handle the leading coefficient! */ L = PLDCF(Ap1); Lh = NIL; t = 0; /* if (!PCONST(r - 1,L)) {*/ if (!VERIFYCONSTSIGN(r-1,IPIP(r-1,ISIGNF(PLBCF(r-1,L)),L),1,GVNA.W)) { W = MPOLY(L,NIL,LIST1(LIST3(PO_LCO,0,A1)),PO_OTHER,PO_KEEP); P = COMP(W,P); Lh = COMP(L,Lh); t = 1; } /* If r = 2 then we know the leading coefficient is always enough! */ if (r == 2) t = 0; /* If x_{r-1} is a bound variable, and the quantifier is either F or G, then we know we'll only be lifting over full dimensional cells so we don't have to add more coefficients! */ if (t) { j = r - GVNFV - 1; if (j > 0) { Q = LELTI(GVQ,j); /* Quantifier for x_{r-1} */ if (Q == FULLDE || Q == FULLDA) t = 0; } } /* If PCMZERROR is set to true, then we only need leading coefficients when projecting polynomials of level k+1 or lower. */ if (t && PCMZERROR && r <= GVNFV + 1) t = 0; /* If it can be determined that the system of coefficients is inconsistent ... we can stop with just the leading coeff! */ if (t) { j = CLOCK(); S = COEFSYS(r,Ap1); if (S == 1 || (Sp = SIMPLIFYSYSLIST(r-1,S,GVNA == NIL ? TRUE : GVNA.W)) == 1) t = 0; else { QepcadCls Q; Word G; for(t = 0; t == 0 && Sp != NIL; Sp = RED(Sp)) if ((G = SYSSOLVECAD(r-1,FIRST(Sp),GVNA == NIL ? TRUE : GVNA.W,GVVL,Q)) != NIL) { /* If there are finitely many solutions, add those points as projection points. */ if (ISLIST(G)) { for(Word Lp = G; Lp != NIL; Lp = RED(Lp)) { /* ADD POINTS to PROJECTION POLS! */ Word X = NIL; /* List of all sample points up to and inluding FIRST(G) */ Word c = Q.GVPC; for(Word I = LELTI(FIRST(Lp),INDX); I != NIL; I = RED(I)) { c = LELTI(LELTI(c,CHILD),FIRST(I)); Word s = LELTI(c,SAMPLE); X = COMP(ISPRIMIT(s) ? (LENGTH(s) > 3 ? FOURTH(s) : s) : s,X); } W = MPOLY(X,NIL,LIST1(LIST2(PT_NUL,A1)),PO_POINT,PO_KEEP); P = COMP(W,P); } } else t = 1; /* Instead of adding all the other coeffs, better to add system! */ } } j = CLOCK() - j; if (PCVERBOSE) { SWRITE("Coef consistency check took "); IWRITE(j); SWRITE("ms\n"); if (!t) SWRITE("Found system inconsistent for "); else SWRITE("Unable to determine consistency for "); IPDWRITE(r,Ap1,GVVL); SWRITE("\n"); } } /* Handle the rest of the coefficients as needed. */ i = 0; while (t) { Ap1 = PRED(Ap1); i++; L = PLDCF(Ap1); t = 0; if (Ap1 != 0) if (!PCONST(r - 1,L)) if (!IPFZT(r - 1,Lh)) { W = MPOLY(L,NIL,LIST1(LIST3(PO_LCO,i,A1)),PO_OTHER,PO_KEEP); P = COMP(W,P); Lh = COMP(L,Lh); t = 1; } } } Step2: /* Obtain discriminants. */ Ap = A; while (Ap != NIL) { ADV(Ap,&A1,&Ap); if (LELTI(A1,PO_TYPE) == PO_POINT) continue; if (PCEQC && LELTI(A1,PO_TYPE) != PO_ECON) continue; Ap1 = LELTI(A1,PO_POLY); if (PDEG(Ap1) >= 2) { D = IPDSCRQE(r,Ap1); W = MPOLY(D,NIL,LIST1(LIST4(PO_DIS,0,0,A1)),PO_OTHER,PO_KEEP); P = COMP(W,P); } } Step3: /* Obtain resultants. */ Ap = A; while (Ap != NIL) { ADV(Ap,&A1,&Ap); if (LELTI(A1,PO_TYPE) == PO_POINT) continue; Ap1 = LELTI(A1,PO_POLY); App = Ap; while (App != NIL) { ADV(App,&A2,&App); if (LELTI(A2,PO_TYPE) == PO_POINT) continue; if (PCEQC && LELTI(A1,PO_TYPE) != PO_ECON && LELTI(A2,PO_TYPE) != PO_ECON) continue; Ap2 = LELTI(A2,PO_POLY); R = IPRESQE(r,Ap1,Ap2); W = MPOLY(R,NIL,LIST1(LIST6(PO_RES,0,0,A1,0,A2)),PO_OTHER,PO_KEEP); P = COMP(W,P); } } Step4: /* Finish. */ P = INV(P); goto Return; Return: /* Prepare for return. */ return(P); }