【发布时间】:2013-02-05 03:40:02
【问题描述】:
我的算法通过使用二维循环遍历 U 和 V 段来计算 3 维空间中形状的顶点。
for (LONG i=0; i < info.useg + 1; i++) {
// Calculate the u-parameter.
u = info.umin + i * info.udelta;
for (LONG j=0; j < info.vseg + 1; j++) {
// Calculate the v-parameter.
v = info.vmin + j * info.vdelta;
// Compute the point's position.
point = calc_point(op, &info, u, v);
// Set the point to the object and increase the point-index.
points[point_i] = point;
point_i++;
}
}
然而,点数组是一个一维数组,这就是point_i 在每个循环中递增的原因。我知道我可以通过point_i = i * info.vseg + j 计算索引。
我希望这个循环是多线程的。我的目标是创建多个线程来处理特定范围的点。在线程中,我会这样做:
for (LONG x=start; x <= end; x++) {
LONG i = // ...
LONG j = // ...
Real u = info.umin + i * info.udelta;
Real v = info.vmin + j * info.vdelta;
points[i] = calc_point(op, &info, u, v);
}
问题是从线性点索引计算i 和j 指数。我如何计算 i 和 j 时(我认为):
point_i = i * vsegments + j
我无法解决数学问题,在这里..
【问题讨论】:
标签: c++ arrays multithreading 3d uv-mapping