void* InitStructEuclidean() { int i,j; unsigned long long int temp = 1; unsigned long long int M = (temp << 32) - 5; confEuclidean *ce = malloc(sizeof(confEuclidean)); ce->v = malloc((euc->k) * sizeof(double*)); ce->w = 4; ce->t = malloc((euc->k)*sizeof(int)); for (i = 0; i < euc->k; i++) { ce->t[i] = (int)GetUniform(0, ce->w); ce->v[i] = malloc((euc->dim) * sizeof(double)); for (j = 0; j < euc->dim; j++) { ce->v[i][j] = GetNormal(0, 1); } } ce->gt = malloc((euc->k) * sizeof(unsigned int)); for (i = 0; i < euc->k; i++) { //ce->gt[i] = malloc((euc->dim) * sizeof(double)); //for (j = 0; j < euc->dim; j++) { ce->gt[i] = (unsigned int)GetUniform(0, M); //printf("%u\n", ce->gt[i]); //printf("%f\n",ce->gt[i][j]); //} } return ce; }
void GetKUniform(int K, int from, int to, int* randomArr){ int i=0; for(i=0;i<K;i++){ randomArr[i]=(int)GetUniform(from, to); } }
void LabelElement::Render() { auto m = GetMetrics(); auto gui = GUI::Get(); auto textProgram = ShaderRegistry::GetProgram("text"); textProgram->Use(); gui->camera->SetUniforms(textProgram.get()); glUniform4f(textProgram->GetUniform("color"), 1,1,1, 1); auto size = m->topRight - m->bottomLeft; auto scalexy = size/textMesh->size; auto scale = std::min(scalexy.x, scalexy.y); auto tmbl = m->bottomLeft + vec2{0, textMesh->size.y * scalexy.y}; Debug::PointUI(m->topRight); Debug::PointUI(m->bottomLeft); Debug::PointUI(m->bottomLeft + vec2{0, textMesh->size.y * scale}, vec3{1,1,0}); Debug::PointUI(tmbl, vec3{1,0,0}); Debug::PointUI(tmbl + textMesh->size * vec2{1,-1} * scale, vec3{0,1,0}); Debug::PointUI(tmbl + textMesh->size * vec2{1,-1} * scale * .5f, vec3{0,0,1}); textMesh->modelMatrix = glm::translate(vec3{tmbl, 0}) * glm::scale(vec3{scale}); textMesh->Render(); }
void TestPam() { int k= GetNoOfCluster(); int q = 100; int flag = 0; int i, j; int l,oldCentr,newCentr; int x, uniSup = q-1; double Jarx = PamAssign(5,4); int ret = 0; for (j = 0; j < q; ++j) { x = (int)GetUniform(0,uniSup); oldCentr = x%k; newCentr = x/k; double dj = ComputeDJ(oldCentr, newCentr); SwapCentroid( newCentr,oldCentr); double Jtel = PamAssign(5,4); double tmp = Jtel - Jarx - dj; ret += (tmp == 0)? 0 : 1; Jarx = Jtel; } CU_ASSERT( ret == 0); }
void OGLSpotLight::Render(double time) { glClear(GL_DEPTH_BUFFER_BIT); glm::vec3 bgColor(0.2f); glClearBufferfv(GL_COLOR, 0, &bgColor[0]); camera.Update(); light.position = camera.GetPosition(); light.direction = camera.GetForwardDirection(); // Render container auto programMesh = programs[0]; programMesh->Use(); SendLightUniform(programMesh.get()); glm::mat4 model = glm::mat4(1); for (size_t i = 0; i < 10; i++) { float sign = (i % 2) * 2 - 1.0f; model = glm::mat4(1); model = glm::rotate(model, i * 0.2f * glm::two_pi<float>(), glm::vec3(0, 1, 0)) * glm::translate(model, glm::vec3(20, 0, 20)); model = glm::scale(glm::rotate(glm::translate(glm::mat4(1), cubePositions[i]), glm::radians(sign * 30.0f), cubePositions[i]), glm::vec3(10)); SendMatricesUniform(programMesh.get(), model); vaos[0]->BindVAO(); vbos[0]->BindVBO(); textures[0]->BindTexture(GL_TEXTURE0); textures[1]->BindTexture(GL_TEXTURE3); glUniform1f(programMesh->GetUniform("material.shininess"), 32.0f); glDrawArrays(GL_TRIANGLES, 0, 36); } }
void* InitStructDistanceMatrix() { int i; //static int currIndex = 0; confDistanceMatrix* ddm = malloc(sizeof(confDistanceMatrix)); ddm->T = malloc(sizeof(double) * dm->k); for (i = 0; i < dm->k; ++i) ddm->T[i] = 0.0 / 0.0; ddm->index = GetUniform(0, dm->dataNum); return ddm; }
void* InitStructFunction() { int i; //static int currIndex = 0; confFunction* cF = malloc(sizeof(confFunction)); cF->T = malloc(sizeof(double) * fun->k); for (i = 0; i < fun->k; ++i) cF->T[i] = 0.0 / 0.0; printf("%d\n", fun->dataNum); cF->index = GetUniform(0, fun->dataNum); return cF; }
void Shader::SetUniform(string name, Texture* val) { val->Bind(); glUniform1i(GetUniform(name), val->GetIndex()); // val->Unbind(); }
void Shader::SetUniform(string name, const mat4& val) { glUniformMatrix4fv(GetUniform(name), 1, GL_FALSE, &val[0][0]); }
void Shader::SetUniform(string name, const vec4& val) { glUniform4f(GetUniform(name), val.x, val.y, val.z, val.w); }
void Shader::SetUniform(string name, const vec3& val) { glUniform3f(GetUniform(name), val.x, val.y, val.z); }
void Shader::SetUniform(string name, const vec2& val) { glUniform2f(GetUniform(name), val.x, val.y); }
void Shader::SetUniform(string name, unsigned int val) { glUniform1ui(GetUniform(name), val); }
void Shader::SetUniform(string name, int val) { glUniform1i(GetUniform(name), val); }
void Shader::SetUniform(string name, float val) { glUniform1f(GetUniform(name), val); }
cxBool RangeShader::InitUniform() { onepixel = GetUniform("onepixel"); range = GetUniform("range"); return true; }
void ReadDataMolecule(value** val, FILE* input ,double r){ size_t lineSize = 0; char* lineBuff = NULL; // for strtok //char* token=NULL; //char delims[4]="\t \n"; getline(&lineBuff, &lineSize, input); if (sscanf(lineBuff, "%d", &dm.noOfMols) < 1) { printf("error???? \n"); } getline(&lineBuff, &lineSize, input); if (sscanf(lineBuff, "%d", &dm.N) < 1) { printf("error???? \n"); } int i, j; //printf("%d\n", dm.noOfMols); //printf("%d\n", dm.N); *val = malloc(sizeof(value) * dm.noOfMols); dm.molecules = malloc(sizeof(double*)* dm.noOfMols); for (i = 0; i < dm.noOfMols; ++i) dm.molecules[i] = malloc(sizeof(double) * dm.N *3); //int flag = 0; int totalCount = 0; for (i = 0; i < dm.noOfMols; ++i) { for (j = 0; j < dm.N*3; j+=3) { totalCount++; //dm.molecules[i][j] = malloc(sizeof(double)*3); getline(&lineBuff, &lineSize, input); float x, y, z; if (sscanf(lineBuff, "%f %f %f", &x, &y, &z) < 1) { printf("error???? \n"); } /* row major */ dm.molecules[i][j + 0] = x; dm.molecules[i][j + 1] = y; dm.molecules[i][j + 2] = z; /**/ /* col major * dm.molecules[i][j + 0 + dm.N*0] = x; dm.molecules[i][j + 1 + dm.N*1] = y; dm.molecules[i][j + 2 + dm.N*2] = z; */ //if (flag == 0) //printf("%g\t%g\t%g\n", x, y, z); } //double r = getFrobNorm( dm.molecules[i], dm.N); //if(flag == 0) //printf("%f\n", r); int *content = malloc(sizeof(int)); *content = i; (*val)[i].content = content; (*val)[i].name = NULL; } printf("%d\n", dm.N * dm.N); dm.rSize = sqrt(r); printf("%d, %d\n", dm.rSize, dm.N); dm.r = malloc(sizeof(int) * dm.rSize); for(i=0;i< dm.rSize;i++) dm.r[i]=(int)GetUniform(i * dm.N/dm.rSize, (i+1) * dm.N/dm.rSize); //for(i=0;i< dm.rSize;i++) //printf("%d\t", dm.r[i]); //printf("\n"); //for(i=0;i< dm.rSize;i++) //dm.r[i] = i; dm.D = malloc(sizeof(double*)*(dm.noOfMols)); for(i=0; i<dm.noOfMols; i++){ SetupDistances(i); } //printf("k = %d\n", dm.k); SetDataSize(dm.noOfMols); free(lineBuff); }
bool OGLSpotLight::Init(int windowWidth, int windowHeight) { bool res = gs::Stage::Init(windowWidth, windowHeight); if (!res) { return false; } cubePositions.resize(10); res &= InitGUI(); // Init Camera camera.SetPosition(glm::vec3(0, 0, 50)); camera.SetSpeed(15.0f); camera.SetupProjection(45.0f, windowWidth / (float)windowHeight); // Init light InitLight(); // Init materials InitCubePosition(); // Init program res &= AddProgram("mesh.vert", "spotLight.frag"); auto program = programs[0]; // Get uniform locations res &= AddLightUniform(program.get()); res &= AddMatricesUniform(program.get()); res &= program->AddUniform("material.shininess"); res &= program->AddUniform("samplerDiffuse1"); program->AddUniform("samplerDiffuse2"); program->AddUniform("samplerDiffuse3"); program->AddUniform("samplerSpecular1"); program->AddUniform("samplerSpecular2"); glUniform1i(program->GetUniform("samplerDiffuse1"), 0); glUniform1i(program->GetUniform("samplerDiffuse2"), 1); glUniform1i(program->GetUniform("samplerDiffuse3"), 2); glUniform1i(program->GetUniform("samplerSpecular1"), 3); glUniform1i(program->GetUniform("samplerSpecular2"), 4); // Init geometry auto vao = std::make_unique<gs::VertexArray>(); vao->BindVAO(); auto vbo = std::make_unique<gs::VertexBuffer>(GL_ARRAY_BUFFER); vbo->BindVBO(); OGLCube cube; auto& vertices = cube.GetVertices(); cube.InitVertices(glm::vec3(0)); glBufferData(vbo->GetTarget(), sizeof(gs::Vertex) * vertices.size(), vertices.data(), GL_STATIC_DRAW); vbos.push_back(std::move(vbo)); vao->AddAttribute(0, 3, GL_FLOAT, GL_FALSE, sizeof(gs::Vertex), 0); vao->AddAttribute(1, 2, GL_FLOAT, GL_FALSE, sizeof(gs::Vertex), (void*)offsetof(gs::Vertex, texCoords)); vao->AddAttribute(2, 3, GL_FLOAT, GL_FALSE, sizeof(gs::Vertex), (void*)offsetof(gs::Vertex, normal)); vaos.push_back(std::move(vao)); auto diffuse = std::make_unique<gs::Texture>(IMAGE_TYPE::GLI); diffuse->SetContribution(LIGHT_CONTRIBUTION::DIFFUSE); res &= diffuse->LoadTexture("containerDiffuse.dds"); diffuse->BindTexture(GL_TEXTURE0); textures.push_back(std::move(diffuse)); auto specular = std::make_unique<gs::Texture>(IMAGE_TYPE::GLI); specular->SetContribution(LIGHT_CONTRIBUTION::DIFFUSE); res &= specular->LoadTexture("containerSpecular.dds"); specular->BindTexture(GL_TEXTURE3); textures.push_back(std::move(specular)); glEnable(GL_DEPTH_TEST); res = true; return res; }