我试图借助顶点坐标插值三角形 .
a
|\
| \
| \
| \
b|_ _ _ \c
我按此顺序(b,a),(a,c)和(c,b)插入顶点 . 这里a,b和c是具有颜色值的3维坐标 .
a = (x1,y1,z1,c1);
b = (x2,y2,z2,c2);
c = (x3,y3,z3,c3);
Structure used to compute the calculation:
struct pointsInterpolateStruct{
QList<double> x,y,z;
QList<double> r, g, b, clr;
void clear() {
x.clear();
y.clear();
z.clear();
r.clear();
g.clear();
b.clear();
clr.clear();
}
};
Interpolation Code:
QList<double> x,y,z,clrs;
上述列表已用于从包含a,b和c坐标的文件中读取值 .
/**
void interpolate();
@param1 ipts is an object for the point interpolation struct which holds the x,y,z and color
@param2 idx1 is the point A
@param 3idx2 is the point B
@return returns the interpolated values after filling the struct pointsInterpolateStruct
*/
void GLThread::interpolate(pointsInterpolateStruct *ipts,int idx1, int idx2) {
int ipStep = 0;
double delX, imX,iX,delY,imY,iY,delZ,imZ,iZ,delClr,imC,iC;
ipStep = 5; // number of points needed between the 2 points
delX = imX = iX = delY = imY = iY = delZ = imZ = iZ = delClr = imC = iC = 0;
delX = (x.at(idx2) - x.at(idx1));
imX = x.at(idx1);
iX = (delX / (ipStep + 1));
delY = (y.at(idx2) - y.at(idx1));
imY = aParam->y.at(idx1);
iY = (delY / (ipStep + 1));
delZ = (z.at(idx2) - z.at(idx1));
imZ = z.at(idx1);
iZ = (delZ / (ipStep + 1));
delClr = (clrs.at(idx2) - clrs.at(idx1));
imC = clrs.at(idx1);
iC = (delClr / (ipStep + 1));
ipts->clear();
int i = 0;
while(i<= ipStep) {
ipts->x.append((imX+ iX * i));
ipts->y.append((imY+ iY * i));
ipts->z.append((imZ+ iZ * i));
ipts->clr.append((imC + iC * i));
i++;
}
}*
Visualization of this interpolated points using OpenGL :
所有点都填充到顶点和颜色缓冲区,我使用以下格式绘制它 . 即使对于较大的点,可视化也非常快 .
void GLWidget::drawInterpolatedTriangle(void) {
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glColorPointer(3, GL_FLOAT, 0, clr);
glVertexPointer(3, GL_FLOAT, 0, vrt);
glPushMatrix();
glDrawArrays(GL_POLYGON, 0, vrtCnt);
glPopMatrix();
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
}
}
}
现在一切正常 . 我得到了理想的输出 . 但问题是当我试图对'n'个三角形(比如n = 40,000)做同样的事情时,即使我在QThread中调用了这个函数,应用程序也会崩溃,我发现这个方法效率不高方法,因为它需要大量的时间进行计算 .
请建议采用乐观的方式来完成此过程,以便在良好的性能下获得更好的结果 .
Output image :
插值三角形(点视图)
网格视图
多边形视图