void make_mesh(std::vector<vertex> &vrts, std::vector<vec3u> &faces, bool scale=true) const { for(int j = 0; j < dim[1]; ++j) { for(int i = 0; i < dim[0]; ++i) { const vec3f pos(i, j, pix[i + j * dim[0]]); const vec2f uv(i/static_cast<float>(dim[0]-1), j/static_cast<float>(dim[1]-1)); vrts.push_back(vertex(pos, vec3f(0), uv)); } } if(scale) for(int j = 0; j < dim[1]; ++j) { for(int i = 0; i < dim[0]; ++i) { vec2f &v2d = sub<0,2>::vector(vrts[i + j * dim[0]].position); v2d = v2d*spacing + origin; vrts[i + j * dim[0]].position[2] = zbase + zscale*vrts[i + j * dim[0]].position[2]; } } for(int j = 0; j < dim[1]; ++j) { for(int i = 0; i < dim[0]; ++i) { const vec3f ¤t(vrts[i+j*dim[0]].position); vec3f xback(0), yback(0), xnext(0), ynext(0); if(i > 0) xback = vec3f(vrts[i-1+ j *dim[0]].position - current); if(j > 0) yback = vec3f(vrts[i +(j-1)*dim[0]].position - current); if(i < dim[0]-1) xnext = vec3f(vrts[i+1+ j *dim[0]].position - current); if(j < dim[1]-1) ynext = vec3f(vrts[i +(j+1)*dim[0]].position - current); vrts[i+j*dim[1]].normal = tvmet::cross(0.5*(ynext-yback), 0.5*(xnext-xback)); vrts[i+j*dim[1]].normal /= length(vrts[i+j*dim[0]].normal); } } for(int j = 1; j < dim[1]; ++j) { for(int i = 1; i < dim[0]; ++i) { faces.push_back(vec3u(i-1 + j*dim[0], i + j*dim[0], i-1 + (j-1)*dim[0])); faces.push_back(vec3u(i + j *dim[0], i + (j-1)*dim[0], i-1 + (j-1)*dim[0])); } } }
void CTexture3D::Upload(void const * const Data, vec3u const & Size, EFormatComponents const Components, EScalarType const Type) { if (Size != TextureSize) { cerr << "GL::Texture3D upload size does not match storage size." << endl; cerr << "Handle is " << Handle << endl; } UploadSubRegion(Data, vec3u(0, 0, 0), Size, Components, Type); }