void DrawCube() { //Listing 3.2. OpenGL code for selecting the slice direction. //Real Time Volume Graphics page 52 GLfloat pModelViewMatrix[16]; GLfloat pModelViewMatrixInv[16]; //GLfloat pMatrixIdentity[16]; // get the current modelview matrix glGetFloatv(GL_MODELVIEW_MATRIX, pModelViewMatrix); // invert the modelview matrix InvertMatrix(pModelViewMatrix, pModelViewMatrixInv); // rotate the initial viewing direction GLfloat pViewVector[4] = { 0.0f, 0.0f, -1.0f, 0.0f }; //GLfloat pViewVector1[4]; MatVecMultiply(pModelViewMatrixInv, pViewVector); // find the maximal vector component int nMax = FindAbsMaximum(pViewVector); //printf("%d %f %f %f %f \n", nMax, pViewVector[0],pViewVector[1],pViewVector[2],pViewVector[3]); switch (nMax) { case X: if (pViewVector[X] > 0.0f) { DrawSliceStack(1); } else { DrawSliceStack(0); } break; case Y: if (pViewVector[Y] > 0.0f) { DrawSliceStack(3); } else { DrawSliceStack(2); } break; case Z: if (pViewVector[Z] > 0.0f) { DrawSliceStack(5); } else { DrawSliceStack(4); } break; } }
int main(int argc, char * argv[]) { if (argc > 1){ parse_args(argc, argv); } const int size = n * n; float *mat = malloc(size * sizeof(float)); float *vec = malloc(n * sizeof(float)); float *output = malloc(n * sizeof(float)); float *expected = malloc(n * sizeof(float)); float *mat_transposed = malloc(n * n * sizeof(float)); generate_matrix(n, mat, range); generate_vector(n, vec, range); timing_t timer1; timer_start(&timer1); transpose(n, mat, mat_transposed); MatVecMultiply(size, n, mat_transposed, vec, output); timer_stop(&timer1); float sum = sum_vec(n, output); printf("%d %f %ld %ld\n", n, sum, timer1.realtime, timer1.cputime); if (trace == 1) { printf("\nInput matrix\n"); for (int i=0; i<n; i++){ for (int j=0; j<n; j++){ printf("%f " , mat[i*n+j]); } printf("\n"); } printf("\nInput vector \n"); for (int i=0; i<n; i++){ printf("%f " , vec[i]); } printf("\n\nResult\n"); for (int i=0; i<n; i++){ printf("%f " , output[i]); } printf("\n"); } else if (trace == 2) { multiply_CPU(n, mat, vec, expected); int status = check(n, output, expected); if (status) printf("Test failed.\n"); else printf("Test passed OK!\n"); return status; } free(mat); free(vec); free(output); free(expected); free(mat_transposed); return 0; }