int main() { unsigned long long n; while(scanf("%lld", &n) == 1){ if(n==0) return 0; std::cout << isTriangular(n) << std::endl; } }
int main() { long n = 144, hexNum = 0; do { hexNum = n * (2 * n - 1); if(isTriangular(hexNum) && isPentagonal(hexNum)) { std::cout << hexNum << std::endl; break; } n++; } while(true); return 0; }
void AbstractMesh::createVAO() noexcept { // if we have already created a VBO just return. if(m_vao == true) { std::cout<<"VAO exist so returning\n"; return; } // else allocate space as build our VAO m_dataPackType=0; if(isTriangular()) { m_dataPackType=GL_TRIANGLES; std::cout <<"Doing Tri Data"<<std::endl; } // data is mixed of > quad so exit error if(m_dataPackType == 0) { std::cerr<<"Can only create VBO from all Triangle or ALL Quad data at present"<<std::endl; exit(EXIT_FAILURE); } // now we are going to process and pack the mesh into an ngl::VertexArrayObject std::vector <VertData> vboMesh; VertData d; int loopFaceCount=3; // loop for each of the faces for(unsigned int i=0; i<m_nFaces; ++i) { // now for each triangle in the face (remember we ensured tri above) for(int j=0; j<loopFaceCount; ++j) { // pack in the vertex data first d.x=m_verts[m_face[i].m_vert[j]].m_x; d.y=m_verts[m_face[i].m_vert[j]].m_y; d.z=m_verts[m_face[i].m_vert[j]].m_z; // now if we have norms of tex (possibly could not) pack them as well if(m_nNorm >0 && m_nTex > 0) { d.nx=m_norm[m_face[i].m_norm[j]].m_x; d.ny=m_norm[m_face[i].m_norm[j]].m_y; d.nz=m_norm[m_face[i].m_norm[j]].m_z; d.u=m_tex[m_face[i].m_tex[j]].m_x; d.v=m_tex[m_face[i].m_tex[j]].m_y; } // now if neither are present (only verts like Zbrush models) else if(m_nNorm ==0 && m_nTex==0) { d.nx=0; d.ny=0; d.nz=0; d.u=0; d.v=0; } // here we've got norms but not tex else if(m_nNorm >0 && m_nTex==0) { d.nx=m_norm[m_face[i].m_norm[j]].m_x; d.ny=m_norm[m_face[i].m_norm[j]].m_y; d.nz=m_norm[m_face[i].m_norm[j]].m_z; d.u=0; d.v=0; } // here we've got tex but not norm least common else if(m_nNorm ==0 && m_nTex>0) { d.nx=0; d.ny=0; d.nz=0; d.u=m_tex[m_face[i].m_tex[j]].m_x; d.v=m_tex[m_face[i].m_tex[j]].m_y; } vboMesh.push_back(d); } } // first we grab an instance of our VOA m_vaoMesh = VertexArrayObject::createVOA(m_dataPackType); // next we bind it so it's active for setting data m_vaoMesh->bind(); m_meshSize=vboMesh.size(); // now we have our data add it to the VAO, we need to tell the VAO the following // how much (in bytes) data we are copying // a pointer to the first element of data (in this case the address of the first element of the // std::vector m_vaoMesh->setData(m_meshSize*sizeof(VertData),vboMesh[0].u); // in this case we have packed our data in interleaved format as follows // u,v,nx,ny,nz,x,y,z // If you look at the shader we have the following attributes being used // attribute vec3 inVert; attribute 0 // attribute vec2 inUV; attribute 1 // attribute vec3 inNormal; attribure 2 // so we need to set the vertexAttributePointer so the correct size and type as follows // vertex is attribute 0 with x,y,z(3) parts of type GL_FLOAT, our complete packed data is // sizeof(vertData) and the offset into the data structure for the first x component is 5 (u,v,nx,ny,nz)..x m_vaoMesh->setVertexAttributePointer(0,3,GL_FLOAT,sizeof(VertData),5); // uv same as above but starts at 0 and is attrib 1 and only u,v so 2 m_vaoMesh->setVertexAttributePointer(1,2,GL_FLOAT,sizeof(VertData),0); // normal same as vertex only starts at position 2 (u,v)-> nx m_vaoMesh->setVertexAttributePointer(2,3,GL_FLOAT,sizeof(VertData),2); // now we have set the vertex attributes we tell the VAO class how many indices to draw when // glDrawArrays is called, in this case we use buffSize (but if we wished less of the sphere to be drawn we could // specify less (in steps of 3)) m_vaoMesh->setNumIndices(m_meshSize); // finally we have finished for now so time to unbind the VAO m_vaoMesh->unbind(); // indicate we have a vao now m_vao=true; }
void mat_dh_read_triples_private(HYPRE_Int ignore, HYPRE_Int *mOUT, HYPRE_Int **rpOUT, HYPRE_Int **cvalOUT, double **avalOUT, FILE* fp) { START_FUNC_DH HYPRE_Int m, n, nz, items, i, j; HYPRE_Int idx = 0; HYPRE_Int *cval, *rp, *I, *J; double *aval, *A, v; char junk[MAX_JUNK]; fpos_t fpos; /* skip over header */ if (ignore && myid_dh == 0) { hypre_printf("mat_dh_read_triples_private:: ignoring following header lines:\n"); hypre_printf("--------------------------------------------------------------\n"); for (i=0; i<ignore; ++i) { fgets(junk, MAX_JUNK, fp); hypre_printf("%s", junk); } hypre_printf("--------------------------------------------------------------\n"); if (fgetpos(fp, &fpos)) SET_V_ERROR("fgetpos failed!"); hypre_printf("\nmat_dh_read_triples_private::1st two non-ignored lines:\n"); hypre_printf("--------------------------------------------------------------\n"); for (i=0; i<2; ++i) { fgets(junk, MAX_JUNK, fp); hypre_printf("%s", junk); } hypre_printf("--------------------------------------------------------------\n"); if (fsetpos(fp, &fpos)) SET_V_ERROR("fsetpos failed!"); } if (feof(fp)) hypre_printf("trouble!"); /* determine matrix dimensions */ m=n=nz=0; while (!feof(fp)) { items = hypre_fscanf(fp,"%d %d %lg",&i,&j,&v); if (items != 3) { break; } ++nz; if (i > m) m = i; if (j > n) n = j; } if (myid_dh == 0) { hypre_printf("mat_dh_read_triples_private: m= %i nz= %i\n", m, nz); } /* reset file, and skip over header again */ rewind(fp); for (i=0; i<ignore; ++i) { fgets(junk, MAX_JUNK, fp); } /* error check for squareness */ if (m != n) { hypre_sprintf(msgBuf_dh, "matrix is not square; row= %i, cols= %i", m, n); SET_V_ERROR(msgBuf_dh); } *mOUT = m; /* allocate storage */ rp = *rpOUT = (HYPRE_Int*)MALLOC_DH((m+1)*sizeof(HYPRE_Int)); CHECK_V_ERROR; cval = *cvalOUT = (HYPRE_Int*)MALLOC_DH(nz*sizeof(HYPRE_Int)); CHECK_V_ERROR; aval = *avalOUT = (double*)MALLOC_DH(nz*sizeof(double)); CHECK_V_ERROR; I = (HYPRE_Int*)MALLOC_DH(nz*sizeof(HYPRE_Int)); CHECK_V_ERROR; J = (HYPRE_Int*)MALLOC_DH(nz*sizeof(HYPRE_Int)); CHECK_V_ERROR; A = (double*)MALLOC_DH(nz*sizeof(double)); CHECK_V_ERROR; /* read <row, col, value> triples into arrays */ while (!feof(fp)) { items = hypre_fscanf(fp,"%d %d %lg",&i,&j,&v); if (items < 3) break; j--; i--; I[idx] = i; J[idx] = j; A[idx] = v; ++idx; } /* convert from triples to sparse-compressed-row storage */ convert_triples_to_scr_private(m, nz, I, J, A, rp, cval, aval); CHECK_V_ERROR; /* if matrix is triangular */ { HYPRE_Int type; type = isTriangular(m, rp, cval); CHECK_V_ERROR; if (type == IS_UPPER_TRI) { hypre_printf("CAUTION: matrix is upper triangular; converting to full\n"); } else if (type == IS_LOWER_TRI) { hypre_printf("CAUTION: matrix is lower triangular; converting to full\n"); } if (type == IS_UPPER_TRI || type == IS_LOWER_TRI) { make_full_private(m, &rp, &cval, &aval); CHECK_V_ERROR; } } *rpOUT = rp; *cvalOUT = cval; *avalOUT = aval; FREE_DH(I); CHECK_V_ERROR; FREE_DH(J); CHECK_V_ERROR; FREE_DH(A); CHECK_V_ERROR; END_FUNC_DH }