C++ (Qt) while (src != srcEnd) { // присваиваем временные имена const float& x0 = *(src++); const float& y0 = *(src++); const float& z0 = *(src++); const float& x1 = *(src++); const float& y1 = *(src++); const float& z1 = *(src++); const float& x2 = *(src++); const float& y2 = *(src++); const float& z2 = *(src++); // вычисляем векторы float a[3] = {x1 - x0, y1 - y0, z1 - z0}, b[3] = {x2 - x0, y2 - y0, z2 - z0}; const int x = 0, y = 1, z = 2; // вычисление и запись перпендикуляра *dest = a[y] * b[z] - a[z] * b[y]; dest[1] = a[z] * b[x] - a[x] * b[z]; dest[2] = a[x] * b[y] - a[y] * b[x]; // вычисление длины и нормализация float inv_length = 1.0 / sqrt(*dest * *dest + dest[y] * dest[y] + dest[z] * dest[z]); *dest *= inv_length; dest[y] *= inv_length; dest[z] *= inv_length; // копирование во все вершины memcpy(dest + 3, dest, 3 * sizeof(float)); memcpy(dest + 6, dest, 3 * sizeof(float)); dest += 9; }
C++ (Qt)void CalcNormals( const float * srcF, int numF, float * dstF ){ const QVector3D * src = (QVector3D *) srcF; QVector3D * dst = (QVector3D *) dstF; int N = numF / 3 / 3; // #pragma omp parallel for for (int i = 0; i < N; ++i) { int j = i * 3; dst[j] = dst[j + 1] = dst[j + 2] = QVector3D::crossProduct(src[j + 1] - src[j], src[j + 2] - src[j]).normalize(); }}
C++ (Qt) int times = (srcEnd - src) / sizeof(float) / 9; #pragma omp parallel for for(int i = 0; i < times; i++) { // присваиваем временные имена int j = i * 9; const float& x0 = src[j]; const float& y0 = src[j + 1]; const float& z0 = src[j + 2]; const float& x1 = src[j + 3]; const float& y1 = src[j + 4]; const float& z1 = src[j + 5]; const float& x2 = src[j + 6]; const float& y2 = src[j + 7]; const float& z2 = src[j + 8]; // вычисляем векторы float a[3] = {x1 - x0, y1 - y0, z1 - z0}, b[3] = {x2 - x0, y2 - y0, z2 - z0}; const int x = 0, y = 1, z = 2; // вычисление и запись перпендикуляра float& xNorm = dest[j] = a[y] * b[z] - a[z] * b[y]; float& yNorm = dest[j + 1] = a[z] * b[x] - a[x] * b[z]; float& zNorm = dest[j + 2] = a[x] * b[y] - a[y] * b[x]; // вычисление длины и нормализация float inv_length = 1.0 / sqrt(xNorm * xNorm + yNorm * yNorm + zNorm * zNorm); xNorm *= inv_length; yNorm *= inv_length; zNorm *= inv_length; // копирование во все вершины memcpy(&xNorm + 3, &xNorm, 3 * sizeof(float)); memcpy(&xNorm + 6, &xNorm, 3 * sizeof(float)); }
Normals calculated with 1 thread in 7 msNormals calculated with multithreading in 28 msNormals calculated with 1 thread in 7 msNormals calculated with multithreading in 7 msNormals calculated with 1 thread in 6 msNormals calculated with multithreading in 6 msNormals calculated with 1 thread in 7 msNormals calculated with multithreading in 6 msNormals calculated with 1 thread in 7 msNormals calculated with multithreading in 6 msNormals calculated with 1 thread in 7 msNormals calculated with multithreading in 7 msNormals calculated with 1 thread in 7 msNormals calculated with multithreading in 7 msNormals calculated with 1 thread in 6 msNormals calculated with multithreading in 7 msNormals calculated with 1 thread in 6 msNormals calculated with multithreading in 7 msNormals calculated with 1 thread in 7 msNormals calculated with multithreading in 6 msNormals calculated with 1 thread in 7 msNormals calculated with multithreading in 6 msNormals calculated with 1 thread in 6 msNormals calculated with multithreading in 7 msNormals calculated with 1 thread in 7 msNormals calculated with multithreading in 7 msNormals calculated with 1 thread in 7 msNormals calculated with multithreading in 7 msNormals calculated with 1 thread in 7 msNormals calculated with multithreading in 7 msNormals calculated with 1 thread in 7 msNormals calculated with multithreading in 7 msNormals calculated with 1 thread in 7 msNormals calculated with multithreading in 7 msNormals calculated with 1 thread in 7 msNormals calculated with multithreading in 7 msNormals calculated with 1 thread in 6 msNormals calculated with multithreading in 7 msNormals calculated with 1 thread in 7 msNormals calculated with multithreading in 7 msNormals calculated with 1 thread in 6 msNormals calculated with multithreading in 7 msNormals calculated with 1 thread in 7 msNormals calculated with multithreading in 7 msNormals calculated with 1 thread in 6 msNormals calculated with multithreading in 7 msNormals calculated with 1 thread in 6 msNormals calculated with multithreading in 6 msNormals calculated with 1 thread in 7 msNormals calculated with multithreading in 6 ms
C++ (Qt)int times = (srcEnd - src) / sizeof(float) / 9;