I want to write a standard interpretation of distance. To do this, I create a voxelgrid 100 * 100 * 100, for example (the size will increase if it works). Now my plans are to load a point cloud into a 1d texture:
glEnable(GL_TEXTURE_1D);
glGenTextures(1, &_texture);
glBindTexture(GL_TEXTURE_1D, _texture);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, pc->pc.size(), 0, GL_RGBA, GL_FLOAT, &pc->pc.front());
glBindTexture(GL_TEXTURE_1D, 0);
'pc' is just a class that contains a Point structure vector that only floats x, y, z, w.
Than I want to display a grid of holes 100x100x100, so every voxel and iteration over all points of this texture calculates the distance to my current voxel and saves this distance in a new texture (1000x1000). At the moment, this texture that I create contains only color values ββthat preserve the distance in the red and green components, and blue - 1.0. Therefore, I see the result on the screen.
, 500 000 , , ( 50 000). , , , .
, , , -, , -, , /.
, - 1D Texture. ? .
, , , , , :
:
for(int i = 0; i < points; ++i){
vec4 texInfo = texture(textureImg, getTextCoord(i));
vec4 pos = position;
pos.z /= rows*rows;
vec4 distVector = texInfo-pos;
float dist = sqrt(distVector.x*distVector.x + distVector.y*distVector.y + distVector.z*distVector.z);
if(dist < minDist){
minDist = dist;
}
}
getTexCoord:
float getTextCoord(float a)
{
return (a * 2.0f + 1.0f) / (2.0f * points);
}
* :
vec4 newPos = vec4(makeCoord(position.x+Col())-1,
makeCoord(position.y+Row())-1,
0,
1.0);
float makeCoord(float a){
return (a/rows)*2;
}
int Col(){
float a = mod(position.z,rows);
return int(a);
}
int Row()
{
float a = position.z/rows;
return int(a);
}