void calc_bbox(const BezierPatch& patch, BBox& box) { for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { box.add_point(patch.P[i][j]); } } }
void read_patches(const char* filename, vector<BezierPatch>& patches, bool flip_surface) { vector<int> indices; vector<vec3> points; FILE* file = fopen(filename, "r"); if (!file) { cerr << "Can't open " << filename << endl; exit(1); } int np, nv; int r = fscanf(file, "%i\n", &np); indices.resize(np * 16); for (int i = 0; i < np; ++i) { int *p = &(indices[i*16]); if (!flip_surface) { r = fscanf(file, "%i, %i, %i, %i,", p+ 0, p+ 1, p+ 2, p+ 3); r = fscanf(file, "%i, %i, %i, %i,", p+ 4, p+ 5, p+ 6, p+ 7); r = fscanf(file, "%i, %i, %i, %i,", p+ 8, p+ 9, p+10, p+11); r = fscanf(file, "%i, %i, %i, %i\n", p+12, p+13, p+14, p+15); } else { r = fscanf(file, "%i, %i, %i, %i,", p+ 0, p+ 4, p+ 8, p+12); r = fscanf(file, "%i, %i, %i, %i,", p+ 1, p+ 5, p+ 9, p+13); r = fscanf(file, "%i, %i, %i, %i,", p+ 2, p+ 6, p+10, p+14); r = fscanf(file, "%i, %i, %i, %i\n", p+ 3, p+ 7, p+11, p+15); } } BBox bbox; r= fscanf(file, "%i\n", &nv); points.resize(nv); for (int i = 0; i < nv; ++i) { float x,y,z; r= fscanf(file, "%f, %f, %f\n", &x, &y, &z); points[i] = vec3(x,y,z); bbox.add_point(vec3(x,y,z)); } vec3 center = bbox.center(); for (int i = 0; i < nv; ++i) { points[i] -= center; } patches.resize(np); int k = 0; for (int i = 0; i < np; ++i) { vec3* ps = patches[i].P[0]; for (int j = 0; j < 16; ++j) { ps[j] = points[indices[k]-1]; ++k; } } }
void Reyes::BoundNSplitGLCPU::bound_patch_range (const PatchRange& r, const BezierPatch& p, const mat4& mv, const mat4& mvp, BBox& box, float& vlen, float& hlen) { const size_t RES = 3; //vec2 pp[RES][RES]; vec3 ps[RES][RES]; vec3 pos; box.clear(); for (size_t iu = 0; iu < RES; ++iu) { for (size_t iv = 0; iv < RES; ++iv) { float v = r.range.min.x + (r.range.max.x - r.range.min.x) * iu * (1.0f / (RES-1)); float u = r.range.min.y + (r.range.max.y - r.range.min.y) * iv * (1.0f / (RES-1)); eval_patch(p, u, v, pos); vec3 pt = vec3(mv * vec4(pos,1)); box.add_point(pt); // pp[iu][iv] = project(mvp * vec4(pos,1)); ps[iu][iv] = pt; } } vlen = 0; hlen = 0; for (size_t i = 0; i < RES; ++i) { float h = 0, v = 0; for (size_t j = 0; j < RES-1; ++j) { // v += glm::distance(pp[j][i], pp[j+1][i]); // h += glm::distance(pp[i][j], pp[i][j+1]); v += glm::distance(ps[j][i], ps[j+1][i]); h += glm::distance(ps[i][j], ps[i][j+1]); } vlen = maximum(v, vlen); hlen = maximum(h, hlen); } }