Esempio n. 1
0
glm::vec4 cross4D(const glm::vec4 &v0, const glm::vec4 &v1,
                  const glm::vec4 &v2)
{
    glm::vec4 crossVec;
    glm::mat3 tempMat;
    std::cout << "Vectors: " << std::endl;
    printVec(v0, 4);
    printVec(v1, 4);
    printVec(v2, 4);
    tempMat[0] = glm::vec3(v0.y, v0.z, v0.w);
    tempMat[1] = glm::vec3(v1.y, v1.z, v1.w);
    tempMat[2] = glm::vec3(v2.y, v2.z, v2.w);
    crossVec.x = glm::determinant(tempMat);
    printMat(tempMat, 3, 3);
    tempMat[0] = glm::vec3(v0.x, v0.z, v0.w);
    tempMat[1] = glm::vec3(v1.x, v1.z, v1.w);
    tempMat[2] = glm::vec3(v2.x, v2.z, v2.w);
    crossVec.y = -glm::determinant(tempMat);
    printMat(tempMat, 3, 3);
    tempMat[0] = glm::vec3(v0.x, v0.y, v0.w);
    tempMat[1] = glm::vec3(v1.x, v1.y, v1.w);
    tempMat[2] = glm::vec3(v2.x, v2.y, v2.w);
    crossVec.z = glm::determinant(tempMat);
    printMat(tempMat, 3, 3);
    tempMat[0] = glm::vec3(v0.x, v0.y, v0.z);
    tempMat[1] = glm::vec3(v1.x, v1.y, v1.z);
    tempMat[2] = glm::vec3(v2.x, v2.y, v2.z);
    crossVec.w = -glm::determinant(tempMat);
    printMat(tempMat, 3, 3);
    printVec(crossVec, 4);
    assert(glm::length(crossVec) >= 0.001);
    return crossVec;
}
int main(int argc, char *argv[]) {
  int NRA = 8;
  int NCA = 8;
  int NCB = 8;
  int NRB = NCA;
  int i,j;

  double *A, *B, *C;
  A = (double *) malloc(NRA * NCA * sizeof(double));
  B = (double *) malloc(NRB * NCB * sizeof(double));
  C = (double *) malloc(NRA * NCB * sizeof(double));
  
  //Initialize the matrices
  for (i = 0; i < NRA; i++) {
    for (j = 0; j < NCA; j++) {
      A[i*NCA+j] = i + j;
    }
  }
  for (i = 0; i < NRB; i++) {
    for (j = 0; j < NCB; j++) {
      B[i*NCB+j] = i - j;
    }
  }

  printf("A=\n"); printMat(NRA, NCA, A);
  printf("B=\n"); printMat(NRB, NCB, B);

  matMult(NRA, NCA, NCB, A, B, C);
  printf("C=\n"); printMat(NRA,NCB, C);
  
  free(C);
  free(B);
  free(A);
}
Esempio n. 3
0
 cv::Mat CameraCalibration::remap(const cv::Mat &image)
 {
     cv::Mat undistorted;
     
     if(mustInitUndistort) { 
         cv::initUndistortRectifyMap(
             cameraMatrix,
             distCoeffs,
             cv::Mat(),
             cv::Mat(),
             image.size(),
             CV_32F,
             mapX,
             mapY           
         );
         
         printMat(cameraMatrix, "Camera Matrix");
         printMat(distCoeffs, "Disortion Coefficients");
         
         mustInitUndistort= false;
     }
     
     cv::remap(image, undistorted, mapX, mapY, cv::INTER_LINEAR);
     
     return undistorted;
 }
Esempio n. 4
0
Mat Camera::computePMatrix() {
    Mat AR = computeCalibrationMatrix() * computeRotationMatrix();
    printMat("A", computeCalibrationMatrix());
    printMat("R", computeRotationMatrix());
    Mat ARC = AR * computeCameraCenterMatrix(false);
    Mat p;
    hconcat(AR, ARC.mul(-1), p);
    printMat("P", p);
    return p;
}
Esempio n. 5
0
// Show the internal face recognition data, to help debugging.
void showTrainingDebugData(const Ptr<FaceRecognizer> model, const int faceWidth, const int faceHeight)
{
    try {   // Surround the OpenCV calls by a try/catch block so we don't crash if some model parameters aren't available.

        // Show the average face (statistical average for each pixel in the collected images).
        Mat averageFaceRow = model->get<Mat>("mean");
        printMatInfo(averageFaceRow, "averageFaceRow");
        // Convert the matrix row (1D float matrix) to a regular 8-bit image.
        Mat averageFace = getImageFrom1DFloatMat(averageFaceRow, faceHeight);
        printMatInfo(averageFace, "averageFace");
        // imshow("averageFace", averageFace);
        saveFloatMat("averageFace.jpg", &averageFace);

        // Get the eigenvectors
        Mat eigenvectors = model->get<Mat>("eigenvectors");
        printMatInfo(eigenvectors, "eigenvectors");

        // Show the best 20 eigenfaces
        for (int i = 0; i < min(20, eigenvectors.cols); i++) {
            // Create a column vector from eigenvector #i.
            // Note that clone() ensures it will be continuous, so we can treat it like an array, otherwise we can't reshape it to a rectangle.
            // Note that the FaceRecognizer class already gives us L2 normalized eigenvectors, so we don't have to normalize them ourselves.
            Mat eigenvectorColumn = eigenvectors.col(i).clone();
            //printMatInfo(eigenvectorColumn, "eigenvector");

            Mat eigenface = getImageFrom1DFloatMat(eigenvectorColumn, faceHeight);
            //printMatInfo(eigenface, "eigenface");
            char eigenName[64];
            sprintf(eigenName,"Eigenface%d.jpg", i);
            saveFloatMat(eigenName, &eigenface);
            // imshow(format("Eigenface%d", i), eigenface);
        }

        // Get the eigenvalues
        Mat eigenvalues = model->get<Mat>("eigenvalues");
        printMat(eigenvalues, "eigenvalues");

        //int ncomponents = model->get<int>("ncomponents");
        //cout << "ncomponents = " << ncomponents << endl;

        vector<Mat> projections = model->get<vector<Mat> >("projections");
        cout << "projections: " << projections.size() << endl;
        for (int i = 0; i < (int)projections.size(); i++) {
            printMat(projections[i], "projections");
        }

        //labels = model->get<Mat>("labels");
        //printMat(labels, "labels");

    } catch (cv::Exception e) {
        //cout << "WARNING: Missing FaceRecognizer properties." << endl;
    }

}
void transposedMat4h(double tr[][VEC_SIZE], double m[][VEC_SIZE]){
	for (int i = 0; i < VEC_SIZE; ++i){
		for (int j = 0; j < VEC_SIZE; ++j){
			tr[j][i] = m[i][j];
		}
	}

	#ifdef DEBUG
	// 結果の出力
	printf("Input ");
	printMat(m);
	printf("Transposed ");
	printMat(tr);
	#endif

}
void translate4hnotInit(double m[][VEC_SIZE], double v[]){
	for (int i = 0; i< VEC_SIZE; ++i) {
		m[i][3] = v[i];
	}
	#ifdef DEBUG
	printMat(m);
	#endif
}
Esempio n. 8
0
int main(int argc, char ** argv) {
    if(argc < 3) {
        printf("Usage:  smahal <nrows> <ncols>\n");
        exit(1);
    }

    char * tail;
    int
      nr = strtol(argv[1], &tail, 0),
      nc = strtol(argv[2], &tail, 0);

    puts(argv[1]);
    puts(argv[2]);

    double * x = Calloc(nr * nc, double);
    int * z = Calloc(nr, int);

    srand(time(0));
    for(int i = 0; i < nr; i++)
      z[i] = ((rand() % 2) == 1);
    for(int i = 0; i < nr * nc; i++)
      x[i] = (double) rand() / (double) RAND_MAX;

    for(int i = 0; i < nc; i++)
      x[i * nr] = x[i * nr + (nc - 1)];

    puts("==== z");
    for(int i = 0; i < nr; i++)
      printf("%d ", z[i]);
    puts("");

    printf("==== x\n");
    printMat(nr, nc, x);

    DMAT * ans = smahal(nr, nc, x, z);

    printf("==== ans\n");
    printMat(ans->nr, ans->nc, ans->data);

    free(ans->data);
    free(ans);

    return 0;
}
// 参考サイト: http://www.mech.tohoku-gakuin.ac.jp/rde/contents/course/robotics/coordtrans.html
void invMat4h(double im[][VEC_SIZE], double m[][VEC_SIZE]){
	double det;
	double u[VEC_SIZE], v[VEC_SIZE];

	det = m[0][0] * m[1][1] * m[2][2] + m[1][0] * m[2][1] * m[0][2] + m[2][0] * m[0][1] * m[1][2]
		- m[0][0] * m[2][1] * m[1][2] - m[2][0] * m[1][1] * m[0][2] - m[1][0] * m[0][1] * m[2][2];
	if (det == 0){
		printf("逆行列は存在しません\n");
	}
	else{
		// 一応初期化
		zeroMat4h(im);

		// 逆行列計算
		// 回転要素の計算
		im[0][0] = m[1][1] * m[2][2] - m[1][2] * m[2][1];
		im[0][1] = m[0][2] * m[2][1] - m[0][1] * m[2][2];
		im[0][2] = m[0][1] * m[1][2] - m[0][2] * m[1][1];

		im[1][0] = m[1][2] * m[2][0] - m[1][0] * m[2][2];
		im[1][1] = m[0][0] * m[2][2] - m[0][2] * m[2][0];
		im[1][2] = m[0][2] * m[1][0] - m[0][0] * m[1][2];

		im[2][0] = m[1][0] * m[2][1] - m[1][1] * m[2][0];
		im[2][1] = m[0][1] * m[2][0] - m[0][0] * m[2][1];
		im[2][2] = m[0][0] * m[1][1] - m[0][1] * m[1][0];

		for (int i = 0; i < VEC_SIZE; ++i){
			for (int j = 0; j < VEC_SIZE; ++j){
				im[i][j] = im[i][j] / det;
			}
		}

		// 平行移動要素初期化
		for (int i = 0; i < VEC_SIZE; ++i){
			u[i] = 0.0;
			v[i] = m[i][VEC_SIZE - 1];
		}
		u[VEC_SIZE - 1] = 1.0;

		// 平行移動要素計算
		for (int i = 0; i< VEC_SIZE - 1; ++i) {
			for (int j = 0; j < VEC_SIZE - 1; ++j) {
				u[i] += im[i][j] * v[j];
			}
			im[i][VEC_SIZE - 1] = -u[i];
		}
		im[VEC_SIZE - 1][VEC_SIZE - 1] = 1;

		#ifdef DEBUG
		// 結果の出力
		printf("Inverse ");
		printMat(im);
		#endif
	}
}
void translate4h(double m[][VEC_SIZE], double v[]){
	zeroMat4h(m);
	for (int i = 0; i< VEC_SIZE; ++i) {
		m[i][3] = v[i];
		m[i][i] = 1;
	}
	#ifdef DEBUG
	printMat(m);
	#endif
}
Esempio n. 11
0
int main(int argc, char* argv[]) {
	float  matA[25] =
	{
		1, 1, 1, 1, 1,//4
		2, 2, 2, 2, 2,//9
		3, 3, 3, 3, 3,//14
		4, 4, 4, 4, 4,
		5, 5, 5, 5, 5
	};
	printf("\ninput Matrix A = \n");
	printMat(matA);
	float matB[25]=
	{
		4, 4, 4, 4, 4,
		3, 3, 3, 3, 3,
		2, 2, 2, 2, 2,
		1, 1, 1, 1, 1,
		0, 0, 0, 0, 0
	};
	printf("\ninput Matrix B = \n");
	printMat(matB);
	float matC[25];/* = {
		0, 0, 0, 0, 0,
		0, 0, 0, 0, 0,
		0, 0, 0, 0, 0,
		0, 0, 0, 0, 0,
		0, 0, 0, 0, 0
	};*/
	//kint a = -1;
	//std::cin >> a;
	MatrixCalc::mat_mul(matA,matB,matC,5);
	printf("\n multiply output Matrix C = A*B = \n");
	printMat(matC);

	MatrixCalc::mat_add(matA, matB, matC, 5);
	printf("\n multiply output Matrix C = A+B =  \n");
	printMat(matC);

	MatrixCalc::mat_sub(matA, matB, matC, 5);
	printf("\n multiply output Matrix C = A-B = \n");
	printMat(matC);
	system("pause");
}
Esempio n. 12
0
void BenchMarkLatex::ProduceTable(CStr dataFileDir, CStr outDir)
{
	CmFile::MkDir(outDir);
	Mat mae1d(_numMethod, _numDb, CV_64F), auc1d(_numMethod, _numDb, CV_64F);
	Mat meanF1d(_numMethod, _numDb, CV_64F), maxF1d(_numMethod, _numDb, CV_64F);
	Mat cutAdp1d(_numMethod, _numDb, CV_64F), cutSC1d(_numMethod, _numDb, CV_64F);

	for (int i = 0; i < _numDb; i++){
		CStr inName = _dbNames[i] + "PrRocAuc.m", outDataF = outDir + inName;
		CmFile::Copy2Dir(dataFileDir + _dbNames[i] + "/" + inName, outDir);
		CV_Assert(CmFile::FilesExist(outDataF));
		
		Mat(readVectorFromMatlabeFile(outDataF, "MAE")).copyTo(mae1d.col(i)); // MAE
		Mat(readVectorFromMatlabeFile(outDataF, "AUC")).copyTo(auc1d.col(i)); // AUC
		Mat(readVectorFromMatlabeFile(outDataF, "MeanFMeasure")).copyTo(meanF1d.col(i)); // MeanFMeasure
		Mat(readVectorFromMatlabeFile(outDataF, "MaxFMeasure")).copyTo(maxF1d.col(i)); // MaxFMeasure
		Mat(readVectorFromMatlabeFile(outDataF, "FMeasureMaskFT")).copyTo(cutAdp1d.col(i)); // Adaptive threshold
		Mat(readVectorFromMatlabeFile(outDataF, "FMeasureMaskSC")).copyTo(cutSC1d.col(i)); // Saliency Cut
	}
	printMat(mae1d, outDir + "MAE.tex", false);
	printMat(auc1d, outDir + "AUC.tex", true);
	printMat(meanF1d, outDir + "MeanF.tex", true);
	printMat(maxF1d, outDir + "MaxF.tex", true);
	printMat(cutAdp1d, outDir + "CutAdp.tex", false);
	printMat(cutSC1d, outDir + "SalCut.tex", true);


		Mat chals[3] = {maxF1d, cutAdp1d, cutSC1d};
	 	Mat mergedTabel3d;
	 	merge(chals, 3, mergedTabel3d);
	 	printMat(mergedTabel3d, outDir + "FixAdpSc.tex", true);
	 	saveData2Csv(mergedTabel3d, outDir + "FixAdpSc.csv", _methodNames);
	 
	 	chals[0] = auc1d; chals[1] = mae1d;
	 	Mat mergedTabel2d;
	 	merge(chals, 2, mergedTabel2d);
	 	saveData2Csv(mergedTabel2d, outDir + "AucMae.csv", _methodNames);//
	 
	 
	 	// Print table for a specific dataset
	 	const int NUM_ROW = 3; // Number of rows in the table
	 	Mat dataArray[NUM_ROW] = { maxF1d, auc1d, mae1d }; //, meanF1d, cutAdp1d, cutSC1d};
	 	const char* rowDes[NUM_ROW] = {"Max", "AUC", "MAE"}; //, "Mean", "AdpT", "SCut"};
	 	bool decentOrder[NUM_ROW] = { true, true, false };
		for (int i = 0; i < _numDb; i++){
			Mat dbTable(_numMethod, NUM_ROW, CV_64F);
			for (int j = 0; j < NUM_ROW; j++)
				dataArray[j].col(i).copyTo(dbTable.col(j));
			printMatTransport(dbTable.t(), outDir + "MaxAdpScT" + _dbNames[i] + ".tex", rowDes, decentOrder);
		}
	 	
	 	printModelRanking(outDir + "MaxFRnk", meanF1d, maxF1d, cutAdp1d, cutSC1d, auc1d, mae1d);


	CmFile::Copy2Dir("xticklabel_rotate.m", outDir);
	CmFile::Copy2Dir("Results.tex", outDir);
}
void scale4h(double m[][VEC_SIZE], double a, double b, double c){
	zeroMat4h(m);
	m[0][0] = a;
	m[1][1] = b;
	m[2][2] = c;
	m[3][3] = 1;

	#ifdef DEBUG
	printMat(m);
	#endif
}
Esempio n. 14
0
int main(){
	pthread_t threads[N];
	int rows[N];

	init(matrix1);
	init(matrix2);
	printf("Matrix 1-------------------------\n");
	printMat(matrix1);
	printf("Matrix 2-------------------------\n");
	printMat(matrix2);
	for(int i =0; i< N; i++){
		rows[i] = i;
		pthread_create (&threads[i], NULL, (void*)&suma, (void*)&rows[i]);
	}
	printf("Result---------------------------\n");
	printMat(result);
	for(int i = 0; i < N; i++){
		t
	}
}
void mirrorO4h(double m[][VEC_SIZE]){
	zeroMat4h(m);
	m[0][0] = -1;
	m[1][1] = -1;
	m[2][2] = -1;
	m[3][3] = 1;

	#ifdef DEBUG
	printMat(m);
	#endif
}
int main()
{
  const int nrOfRows = 6;
  const int nrOfCols = 4;
  int** matrix = new int*[nrOfRows];
  for (int i = 0; i < nrOfRows; ++i) {
    matrix[i] = new int[nrOfCols];
  }
  
  initMat(matrix, nrOfRows, nrOfCols);
  printMat(matrix, nrOfRows, nrOfCols);
  matrix[3][3] = 0;
  printf("\n");
  rowColZero(matrix, nrOfRows, nrOfCols);
  printMat(matrix, nrOfRows, nrOfCols);
  printf("\n");
  


  return 0;
}
void setMatCol4h(double a[][VEC_SIZE], double v0[], double v1[], double v2[], double p[]){
	zeroMat4h(a);
	for (int i = 0; i < VEC_SIZE; ++i){
		a[i][0] = v0[i];
		a[i][1] = v1[i];
		a[i][2] = v2[i];
		a[i][3] = p[i];
	}
	#ifdef DEBUG
	printMat(a);
	#endif
}
Esempio n. 18
0
void test_inverse0()
{
	real * A = makeRandMatrix();
	real * B = makeMatrix();
	real * C = makeMatrix();
	real * X = makeMatrix();

	identity(X, NN);
	printf("test inverse0\n");
	copyMatrix(B, A);
	printMat("A=", A);
	inverse(A,C, NN);
	printMat("inverse=", C);
	multiply0(A, B, C, NN, NN, NN);
	printMat("A*A'=", A);
	printDiffent("A*A'=I", X, A);
	freeMatrix(A);
	freeMatrix(B);
	freeMatrix(C);
	freeMatrix(X);
}
void rotateZ4h(double m[][VEC_SIZE], double a){
	zeroMat4h(m);
	m[0][0] = cos(a);
	m[0][1] = -sin(a);
	m[1][0] = sin(a);
	m[1][1] = cos(a);
	m[2][2] = m[3][3] = 1;

	#ifdef DEBUG
	printMat(m);
	#endif
}
void rotateXSC4h(double m[][VEC_SIZE], double sv, double cv){
	zeroMat4h(m);
	m[1][1] = cv;
	m[1][2] = -sv;
	m[2][1] = sv;
	m[2][2] = cv;
	m[0][0] = m[3][3] = 1;

	#ifdef DEBUG
	printMat(m);
	#endif
}
void mulMM4h(double m01[][VEC_SIZE], double m0[][VEC_SIZE], double m1[][VEC_SIZE]){
	zeroMat4h(m01);
	for (int i = 0; i< VEC_SIZE; ++i) {
		for (int j = 0; j < VEC_SIZE; ++j) {
			for (int k = 0; k < VEC_SIZE; ++k) {
				m01[i][j] += m0[i][k] * m1[k][j];
			}
		}
	}
	#ifdef DEBUG
	printMat(m01);
	#endif
}
Esempio n. 22
0
void test_lup()
{
	real * A = makeRandMatrix();
	real * B = makeMatrix();
	real * L = makeMatrix();
	real * X = makeMatrix();
	real * P = makeMatrix();
	
	identity(X, NN);
	printf("test crout_plu\n");
	copyMatrix(B, A);
	printMat("A=", A);
	crout_plu(A,P,L,NN);
	multiply0(X, P, L, NN, NN, NN);
	multiply0(P, X, A, NN, NN, NN);
	printMat("A*A'=", P);
	printDiffent("A*A'=I", B, P);
	freeMatrix(A);
	freeMatrix(B);
	freeMatrix(L);
	freeMatrix(X);
	freeMatrix(P);
}
//将矩阵拟上三角化
void hessenbergMat(double **a)       
{
    int r, i, j;
    double c, d, h, t, u[10], p[10], q[10], w[10];
    for (r = 0; r<8; r++) {
        zeroMat(a);
        c = 0; d = 0; h = 0;
        for (i = r + 2; i<10; i++)
            d += a[i][r] * a[i][r];
        if (d == 0)
            continue;
        else {
            d += a[r + 1][r] * a[r + 1][r];
            d = pow(d, 0.5);
            if (a[r + 1][r] != 0)
                c = -fabs(a[r + 1][r]) / a[r + 1][r] * d;
            else 
                c = d;
            h = c*c - c*a[r + 1][r];
            for (i = 0; i<r + 1; i++)
                u[i] = 0;
            u[r + 1] = a[r + 1][r] - c;
            for (i = r + 2; i<10; i++) 
                u[i] = a[i][r];
            for (i = 0; i<10; i++) {
                p[i] = 0; q[i] = 0;
                for (j = 0; j<10; j++) {
                    p[i] += a[j][i] * u[j] / h;
                    q[i] += a[i][j] * u[j] / h;
                }
            }
            t = 0;
            for (i = 0; i<10; i++)
                t += p[i] * u[i] / h;
            for (i = 0; i<10; i++)
                w[i] = q[i] - t*u[i];
            for (i = 0; i<10; i++) {
                for (j = 0; j<10; j++)
                    a[i][j] -= (w[i] * u[j] + u[i] * p[j]);
            }
        }
    }
    printf("A(n-1)\n");
    zeroMat(a);
    printMat(a);
}
Esempio n. 24
0
static void test_lemke()
{
	real * A = makeRandMatrix();
	real * b = makeRandVec2();
	real * x = (real *)malloc(2*NN*sizeof(real));
	real * xx = (real *)malloc(2*NN*sizeof(real));
	real * AA = makeMatrix();
	real * bb = makeRandVec2();
	std::vector<real *> vx;
//	copyMatrix(A,exaples_m2);
//	for(int i =0;i<N;i++)
//		b[i] = exaples_q2[i];
	copyMatrix(AA,A);
	memcpy(bb,b,NN*sizeof(real));
	//memset(x,0,sizeof(real)*N);
	memset(x,0,NN*sizeof(real));
	//memcpy(xx,b,N*sizeof(real));
	memset(xx,0,sizeof(real)*NN);	
	
	printf("--------------------------------------------------------\n");
	printMat("solve lcp A=",A);
	printVec("lcp b=",b);
	printf("--------------------------------------------------------\n");
	int result1 = lcp(A,b,vx,NN);	
	int result2 = lcp_lemke(A,b,x,NN);
	
	printf("lcp solve:\n");
	printf("--------------------------------------------------------\n");
	printLCPVx(vx);
	printf("lcp_lemke solve %s (%d)\n",result2?"true":"false",result2);
	printVec("lcp_lemke=",x);
	check_lcp_result(AA,bb,x,NN);
	
	freeMatrix(A);
	freeMatrix(b);
	freeMatrix(x);
	freeMatrix(AA);
	freeMatrix(bb);	
	freeLcpSolve(vx);	
}
Esempio n. 25
0
static void test_pgs()
{
	real * A = makeRandSPDMatrix();
	real * b = makeRandVec2();
	real * x = makeRandVec2();
	real * xx = makeRandVec2();
	real * AA = makeMatrix();
	real * bb = makeRandVec2();
	std::vector<real *> vx;
	copyMatrix(AA,A);
	memcpy(bb,b,NN*sizeof(real));
	//memset(x,0,sizeof(real)*N);
	memset(x,0,NN*sizeof(real));
	//memcpy(xx,b,N*sizeof(real));
	memset(xx,0,sizeof(real)*NN);
	
	printf("--------------------------------------------------------\n");
	printMat("solve lcp A=",A);
	printVec("lcp b=",b);
	printf("--------------------------------------------------------\n");
	int result1 = lcp(A,b,vx,NN);	
	int result2 = lcp_pgs(A,b,x,NN,15,0.001);
	int result3 = Solve_GaussSeidel(AA,bb,xx,NN,15);
	printf("lcp solve:\n");
	printf("--------------------------------------------------------\n");
	printLCPVx(vx);
	printf("lcp_pgs solve %s (%d)\n",result2?"true":"false",result2);
	printVec("lcp_pgs=",x);
	check_lcp_result(AA,bb,x,NN);
	printVec("gs solve :",xx);

	freeMatrix(A);
	freeMatrix(b);
	freeMatrix(x);
	freeMatrix(AA);
	freeMatrix(bb);
	freeLcpSolve(vx);
}
Esempio n. 26
0
int main()
{
    int i, j, count;
    int r=SIZE,c=SIZE;
    int **arr = (int **)malloc(r * sizeof(int *));
    for (i=0; i<r; i++)
        arr[i] = (int *)malloc(c * sizeof(int));

// Note that arr[i][j] is same as *(*(arr+i)+j)
    count = 0;
    for (i = 0; i <r; i++)
        for (j = 0; j < c; j++)
            arr[i][j] = ++count;// OR *(*(arr+i)+j) = ++count

    printMat(arr,SIZE);
 /* Code for further processing and free the 
 dynamically allocated memory */
 int len=0;
 int **sol = diagonal(arr, SIZE, SIZE, &len);
    printSolMat(sol,len);

 return 0;
 }
Esempio n. 27
0
//=========================================================================
// test matrix copy constructor (copy & view)
int matrixCpyCtr(bool verbose, bool debug) {
	const int m1rows = 5;
	const int m1cols = 4;
	const int m2rows = 2;
	const int m2cols = 6;

	int ierr = 0;
	int returnierr = 0;
	if(verbose) printHeading("Testing matrix copy constructors");

	if(verbose) cout << "checking copy constructor (view)" << endl;
	double* m1rand = getRandArray(m1rows * m1cols);
	if(debug) printArray(m1rand, m1rows * m1cols);
	Epetra_SerialDenseMatrix m1(View, m1rand, m1rows, m1rows, m1cols);
	if(debug) {
		cout << "original matrix:" << endl;
		printMat("m1",m1);
	}
	Epetra_SerialDenseMatrix m1clone(m1);
	if(debug) {
		cout << "clone matrix:" << endl;
		printMat("m1clone",m1clone);
	}
	if(verbose) cout << "making sure signatures match" << endl;
	EPETRA_TEST_ERR(!identicalSignatures(m1, m1clone), ierr);
	delete[] m1rand;
	returnierr += ierr;
	if(ierr == 0)
		if(verbose) cout << "Checked OK." << endl;
	ierr = 0;
	
	if(verbose) cout << "\nchecking copy constructor (copy)" << endl;
	double* m2rand = getRandArray(m2rows * m2cols);
	if(debug) printArray(m2rand, m2rows * m2cols);
	Epetra_SerialDenseMatrix m2(Copy, m2rand, m2rows, m2rows, m2cols);
	if(debug) {
		cout << "original matrix:" << endl;
		printMat("m2",m2);
	}
	Epetra_SerialDenseMatrix m2clone(m2);
	if(debug) {
		cout << "clone matrix:" << endl;
		printMat("m2clone",m2clone);
	}
	if(verbose) cout << "checking that signatures match" << endl;
	EPETRA_TEST_ERR(!identicalSignatures(m2, m2clone), ierr);
	returnierr += ierr;
	if(ierr == 0)
		if(verbose) cout << "Checked OK." << endl;
	ierr = 0;

	if(verbose) cout << "\nmodifying entry in m2, m2clone should be unchanged" << endl;
	EPETRA_TEST_ERR(!seperateData(m2, m2clone), ierr);
	if(debug) {
		printArray(m2rand, m2rows * m2cols);
		cout << "orig:" << endl;
		printMat("m2",m2);
		cout << "clone:" << endl;
		printMat("m2clone",m2clone);
	}
	delete[] m2rand;
	returnierr += ierr;
	if(ierr == 0)
		if(verbose) cout << "Checked OK." << endl;
	ierr = 0;
	
	return(returnierr);
}
Esempio n. 28
0
//=========================================================================
// test matrix operator= (copy & view)
int matrixAssignment(bool verbose, bool debug) {
	int ierr = 0;
	int returnierr = 0;
	if(verbose) printHeading("Testing matrix operator=");

	// each section is in its own block so we can reuse variable names
	// lhs = left hand side, rhs = right hand side
	
	{
		// copy->copy (more space needed)
		// orig and dup should have same signature
		// modifying orig or dup should have no effect on the other
		if(verbose) cout << "Checking copy->copy (new alloc)" << endl;
		Epetra_SerialDenseMatrix lhs(2,2);
		double* rand1 = getRandArray(25);
		Epetra_SerialDenseMatrix rhs(Copy, rand1, 5, 5, 5);
		if(debug) {
			cout << "before assignment:" << endl;
			printMat("rhs",rhs);
			printMat("lhs",lhs);
		}
		lhs = rhs;
		if(debug) {
			cout << "after assignment:" << endl;
			printMat("rhs",rhs);
			printMat("lhs",lhs);
		}
		EPETRA_TEST_ERR(!identicalSignatures(rhs,lhs), ierr);
		EPETRA_TEST_ERR(!seperateData(rhs,lhs), ierr);
		delete[] rand1;
	}
	returnierr += ierr;
	if(ierr == 0)
		if(verbose) cout << "Checked OK." << endl;
	ierr = 0;
	{
		// copy->copy (have enough space)
		// orig and dup should have same signature
		// modifying orig or dup should have no effect on the other
		if(verbose) cout << "\nChecking copy->copy (no alloc)" << endl;
		double* rand1 = getRandArray(25);
		double* rand2 = getRandArray(20);
		Epetra_SerialDenseMatrix lhs(Copy, rand1, 5, 5, 5);
		Epetra_SerialDenseMatrix rhs(Copy, rand2, 4, 4, 5);
		double* origA = lhs.A();
		int origLDA = lhs.LDA();
		if(debug) {
			cout << "before assignment:" << endl;
			printMat("rhs",rhs);
			printMat("lhs",lhs);
		}
		lhs = rhs;
		if(debug) {
			cout << "after assignment:" << endl;
			printMat("rhs",rhs);
			printMat("lhs",lhs);
		}
		// in this case, instead of doing a "normal" LDA test in identSig,
		// we do our own. Since we had enough space already, A and LDA should
		// not have been changed by the assignment. (The extra parameter to
		// identicalSignatures tells it not to test LDA).
		EPETRA_TEST_ERR((lhs.A() != origA) || (lhs.LDA() != origLDA), ierr);
		EPETRA_TEST_ERR(!identicalSignatures(rhs,lhs,false), ierr);
		EPETRA_TEST_ERR(!seperateData(rhs,lhs), ierr);
	}
	returnierr += ierr;
	if(ierr == 0)
		if(verbose) cout << "Checked OK." << endl;
	ierr = 0;
	{
		// view->copy
		// orig and dup should have same signature
		// modifying orig or dup should have no effect on the other
		if(verbose) cout << "\nChecking view->copy" << endl;
		double* rand1 = getRandArray(25);
		double* rand2 = getRandArray(64);
		Epetra_SerialDenseMatrix lhs(View, rand1, 5, 5, 5);
		Epetra_SerialDenseMatrix rhs(Copy, rand2, 8, 8, 8);
		if(debug) {
			cout << "before assignment:" << endl;
			printMat("rhs",rhs);
			printMat("lhs",lhs);
		}
		lhs = rhs;
		if(debug) {
			cout << "after assignment:" << endl;
			printMat("rhs",rhs);
			printMat("lhs",lhs);
		}
		EPETRA_TEST_ERR(!identicalSignatures(rhs,lhs), ierr);
		EPETRA_TEST_ERR(!seperateData(rhs,lhs), ierr);
		delete[] rand1;
		delete[] rand2;
	}
	returnierr += ierr;
	if(ierr == 0)
		if(verbose) cout << "Checked OK." << endl;
	ierr = 0;
	{
	  // copy->view
		// orig and dup should have same signature
		// modifying orig or dup should change the other
		if(verbose) cout << "\nChecking copy->view" << endl;
		double* rand1 = getRandArray(10);
		Epetra_SerialDenseMatrix lhs(4,4);
		Epetra_SerialDenseMatrix rhs(View, rand1, 2, 2, 5);
		if(debug) {
			cout << "before assignment:" << endl;
			printMat("rhs",rhs);
			printMat("lhs",lhs);
		}
		lhs = rhs;
		if(debug) {
			cout << "after assignment:" << endl;
			printMat("rhs",rhs);
			printMat("lhs",lhs);
		}
		EPETRA_TEST_ERR(!identicalSignatures(rhs,lhs), ierr);
		EPETRA_TEST_ERR(seperateData(rhs,lhs), ierr);
		delete[] rand1;
	}
	returnierr += ierr;
	if(ierr == 0)
		if(verbose) cout << "Checked OK." << endl;
	ierr = 0;	
	{
		// view->view
		// orig and dup should have same signature
		// modifying orig or dup should change the other
		if(verbose) cout << "\nChecking view->view" << endl;
		double* rand1 = getRandArray(9);
		double* rand2 = getRandArray(18);
		Epetra_SerialDenseMatrix lhs(View, rand1, 3, 3, 3);
		Epetra_SerialDenseMatrix rhs(View, rand2, 3, 3, 6);
		if(debug) {
			cout << "before assignment:" << endl;
			printMat("rhs",rhs);
			printMat("lhs",lhs);
		}
		lhs = rhs;
		if(debug) {
			cout << "after assignment:" << endl;
			printMat("rhs",rhs);
			printMat("lhs",lhs);
		}
		EPETRA_TEST_ERR(!identicalSignatures(rhs,lhs), ierr);
		EPETRA_TEST_ERR(seperateData(rhs,lhs), ierr);
		delete[] rand1;
		delete[] rand2;
	}
	returnierr += ierr;
	if(ierr == 0)
		if(verbose) cout << "Checked OK." << endl;
	ierr = 0;

	return(returnierr);
}
Esempio n. 29
0
// FUNCTION ======	setup
void setup() {
    //---- SDL initialization
    if ( SDL_Init(SDL_INIT_VIDEO) != 0 ) {
        printf("Unable to initialize SDL: %s\n", SDL_GetError());
        getchar() ;
    }
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    //screen = SDL_SetVideoMode( WIDTH, HEIGHT, COLDEPTH, SDL_OPENGL |  SDL_SWSURFACE  );
    screen = SDL_SetVideoMode( WIDTH, HEIGHT, COLDEPTH, SDL_OPENGL );
    if(!screen)  {
        printf("Couldn't set %dx%d GL video mode: %s\n", WIDTH,HEIGHT, SDL_GetError());
        SDL_Quit();
        exit(2);
    }
    SDL_WM_SetCaption(" Prokop's test SDL+ OpenGL", "SDL+ OpenGL");

    //materialy
    float ambient  [] = { 0.25f, 0.25f, 0.25f, 1.0f};
    glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT,   ambient);
    float diffuse  [] = { 0.50f, 0.50f, 0.50f, 1.0f};
    glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE,   diffuse);
    float specular [] = { 0.00f, 0.00f, 0.00f, 1.0f};
    glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR,  specular);
    float shininess[] = { 0.0f                     };
    glMaterialfv (GL_FRONT_AND_BACK, GL_SHININESS, shininess);
    glEnable  (GL_LIGHT0);
    float light0_pos  []   = { 1000.0f, 2000.0f, 3000.0f, 1.00f};
    glLightfv (GL_LIGHT0, GL_POSITION, light0_pos );
    float light0_color[]   = { 0.9f, 0.8f, 0.7f, 1.00f};
    glLightfv (GL_LIGHT0, GL_DIFFUSE,  light0_color  );
    float light0_ambient[] = { 0.5f, 0.6f, 0.7f, 1.00f};
    glLightfv (GL_LIGHT0, GL_AMBIENT,  ambient       );
    glEnable  (GL_LIGHTING);
    glEnable (GL_COLOR_MATERIAL);
    glEnable  (GL_NORMALIZE);
    glEnable  (GL_DEPTH_TEST);
    //glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    //glEnable(GL_BLEND) ;
    //glBlendFunc (GL_SRC_ALPHA, GL_SRC_ALPHA);
    glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
    glShadeModel(GL_SMOOTH);
    glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);

    glClearColor( 0.9, 0.9, 0.9, 0.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    qmouse.setOne();

    srand(1234);

    buildings = makeBuildings( 10, 10, 100, 100, 0.5, 0.5, 50, 100 );

    const int len = 5;
    double masses[len]  = { 4,1,1,0.5f,0.5f };
    Vec3d  poss[len]    = { {0,-0.2,1}, {-2,0,0}, {2,0,0}, {0,0,-3}, {0,0.2,-3} };

    myCraft.from_mass_points( len, masses, poss );
    myCraft.qrot.setOne();
    //myCraft.qrot.set(0,0,-0.5,1); myCraft.qrot.normalize();

    printVec(myCraft.pos);
    printf("pos\n");

    myCraft.wingLeft .craft = &myCraft;
    myCraft.wingRight.craft = &myCraft;
    myCraft.elevator .craft = &myCraft;
    myCraft.rudder   .craft = &myCraft;

    myCraft.wingLeft .lpos.set( poss[1] - myCraft.pos );
    myCraft.wingRight.lpos.set( poss[2] - myCraft.pos );
    myCraft.elevator .lpos.set( poss[3] - myCraft.pos );
    myCraft.rudder   .lpos.set( poss[4] - myCraft.pos );

    /*
    	myCraft.wingLeft .lpos.set( poss[1] );
    	myCraft.wingRight.lpos.set( poss[2] );
    	myCraft.elevator .lpos.set( poss[3] );
    	myCraft.rudder   .lpos.set( poss[4] );
    */

    myCraft.wingLeft .lrot.set( { 1,0,0, 0,1,0,  0,0,1  } );
    myCraft.wingLeft  .lrot.rotate( -0.1, { 0,0,1 } );
    myCraft.wingRight.lrot.set( { 1,0,0, 0,1,0,  0,0,1  } );
    myCraft.wingRight .lrot.rotate( +0.1, { 0,0,1 } );
    myCraft.elevator .lrot.set( { 1,0,0, 0,1,0,  0,0,1  } );
    myCraft.elevator .lrot.rotate( +0.2, { 1,0,0 } );
    printf("elevator lrot\n");
    printMat( myCraft.elevator.lrot );

    myCraft.rudder   .lrot.set( { 0,1,0, 1,0,0,  0,0,1  } );

    myCraft.wingLeft .C.set( 0.05, 1.0, 0.05 );
    myCraft.wingRight.C.set( 0.05, 1.0, 0.05 );
    myCraft.elevator .C.set( 0.05, 1.0, 0.05 );
    myCraft.elevator.C *= 0.1;
    myCraft.rudder   .C.set( 0.05, 1.0, 0.05 );
    myCraft.rudder  .C *= 0.1;

    myCraft.L.set(0,0,0);
    myCraft.init( );

    myCraft.vel.set(0,0,0);
    myCraft.pos.set(0,500,0);

    printf("Ibody\n");
    printMat(myCraft.Ibody);
    printf("invIbody\n");
    printMat(myCraft.invIbody);

}
Esempio n. 30
0
// The MAIN function, from here we start the application and run the 
// game loop
int main()
{
    std::cout << "Starting GLFW context, OpenGL 3.3" << std::endl;
    // Init GLFW
    glfwInit();
    // Set all the required options for GLFW
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    // OS X requests 3.3 differently.
#ifdef __APPLEOS__
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);

    // Create a GLFWwindow object that we can use for GLFW's functions
    GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "LearnOpenGL", 
                                          nullptr, nullptr);    
    if (window == nullptr)
    {
        std::cout << "Failed to create GLFW window" << std::endl;
        glfwTerminate();
        return -1;
    }
    glfwMakeContextCurrent(window);
    // Set the required callback functions
    glfwSetKeyCallback(window, key_callback);

    // Set this to true so GLEW knows to use a modern approach to retrieving
    // function pointers and extensions
    // More hacking for my autocomplete.
#ifndef CLANG_COMPLETE_ONLY
    glewExperimental = GL_TRUE;
    // Initialize GLEW to setup the OpenGL Function pointers
    if (glewInit() != GLEW_OK)
    {
        std::cout << "Failed to initialize GLEW" << std::endl;
        return -1;
    }    
#endif

    // Define the viewport dimensions
    // Corrected from the tutorial, should request framebuffer size instead.
    // Technically should also write a callback when the window is resized
    // with framebuffer_size_callback. See GLFW docs. This will do for now.
    int fbwidth, fbheight;
    glfwGetFramebufferSize(window, &fbwidth, &fbheight);

    // Options
    glViewport(0, 0, WIDTH, HEIGHT);
    glEnable(GL_DEPTH_TEST);

    // ---------- BEGIN OPENGL ----------- //
    
    // Shader creation
    Shader edgeShader("vertex_shader_unsliced.glsl", "fragment_shader_unsliced.glsl");

    // Data
    GLfloat vertices[] = {
        // Positions           
         0.6f,   0.6f,   0.6f,   0.6f,
         0.6f,  -0.6f,   0.6f,   0.6f,  
        -0.6f,  -0.6f,   0.6f,   0.6f,
        -0.6f,   0.6f,   0.6f,   0.6f,

         0.6f,   0.6f,  -0.6f,   0.6f,
         0.6f,  -0.6f,  -0.6f,   0.6f,
        -0.6f,  -0.6f,  -0.6f,   0.6f,
        -0.6f,   0.6f,  -0.6f,   0.6f,

         0.8f,   0.8f,   0.8f,  -0.8f,
         0.8f,  -0.8f,   0.8f,  -0.8f,  
        -0.8f,  -0.8f,   0.8f,  -0.8f,
        -0.8f,   0.8f,   0.8f,  -0.8f,

         0.8f,   0.8f,  -0.8f,  -0.8f,
         0.8f,  -0.8f,  -0.8f,  -0.8f,
        -0.8f,  -0.8f,  -0.8f,  -0.8f,
        -0.8f,   0.8f,  -0.8f,  -0.8f,
    };

    GLuint indices[] = {
        // Near Cube
         0,  2,  1,
         0,  3,  2,
         7,  5,  6,
         7,  4,  5,
         3,  4,  7,
         3,  0,  4,
         6,  1,  2,
         6,  5,  1,
         6,  3,  7,
         6,  2,  3,
         1,  4,  0,
         1,  5,  4,
        // Far Cube
         8, 10,  9,
         8, 11, 10,
        15, 13, 14,
        15, 12, 13,
        11, 12, 15,
        11,  8, 12,
        14,  9, 10,
        14, 13,  9,
        14, 11, 15,
        14, 10, 11,
         9, 12,  8,
         9, 13, 12,
        // Front Cube
         0,  2,  1,
         0,  3,  2,
        11,  9, 10,
        11,  8,  9,
         3,  0,  8,
         3,  8, 11,
        10,  1,  2,
        10,  9,  1,
        10,  3, 11,
        10,  2,  3,
         1,  8,  0,
         1,  9,  8,
        // Back Cube
         5,  7,  4,
         5,  6,  7,
        14, 12, 15,
        14, 13, 12,
         6,  5, 13,
         6, 13, 14,
        15,  4,  7,
        15, 12,  4,
        15,  6, 14,
        15,  7,  6,
         4, 13,  5,
         4, 12, 13,
        // Top Cube
         4,  7,  3,
         4,  3,  0,
        15,  8, 11,
        15, 12,  8,
         7, 12, 15,
         7,  4, 12,
         0, 11,  8,
         0,  3, 11,
         3,  7, 15,
         3, 15, 11,
         4,  0,  8,
         4,  8, 12,
        // Bottom Cube
         1,  2,  6,
         1,  6,  5,
        10, 13, 14,
        10,  9, 13,
         2,  9, 10,
         2,  1,  9,
         5, 14, 13,
         5,  6, 14,
         6,  2, 10,
         6, 10, 14,
         1,  5, 13,
         1, 13,  9,
        // Left Cube
         3,  7,  6,
         3,  6,  2,
        15, 11, 10,
        15, 10, 14,
        11, 15,  7,
        11,  7,  3,
        14,  2,  6,
        14, 10,  2,
         7, 15, 14,
         7, 14,  6,
        11,  3,  2,
        11,  2, 10,
        // Right Cube
         1,  5,  4,
         1,  4,  0,
        13,  9,  8,
        13,  8, 12,
         9, 13,  5,
         9,  5,  1,
        12,  0,  4,
        12,  8,  0,
         5, 13, 12,
         5, 12,  4,
         9,  1,  0,
         9,  0,  8,
    };

    // Textures

    // Set up buffer stuff
    GLuint VAO, VBO, EBO;
    glGenVertexArrays(1, &VAO);
    glGenBuffers(1, &VBO);
    glGenBuffers(1, &EBO);
    
    // Game loop
    while (!glfwWindowShouldClose(window))
    {
        // Check if any events have been activated (key pressed, mouse moved
        // etc.) and call corresponding response functions
        glfwPollEvents();

        // Setup stuff
        glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glEnable(GL_BLEND);
        glLineWidth(3);

        // 4D-3D Transformations
        glm::mat4 model4D(1.0f), view4D;
        GLfloat theta = glm::radians((GLfloat)glfwGetTime() * 50.0f);
        GLfloat cs = cos(theta), sn = sin(theta);
        model4D[0][0] = cs;
        model4D[0][3] = -sn;
        model4D[3][0] = sn;
        model4D[3][3] = cs;
        glm::mat4x3 projection4D;
        glm::vec4 from(0.0f, 0.0f, 0.0f, 4.0f), to(0.0f, 0.0f, 0.0f, 0.0f); 
        glm::vec4 up(0.0f, 1.0f, 0.0f, 0.0f), over(0.0f, 0.0f, 1.0f, 0.0f);
        view4D = lookAt4D(from, to, up, over);

        std::cout << "View Mat: " << std::endl;
        printMat(view4D, 4, 4);

        projection4D = proj4D();

        GLfloat *projVert = new GLfloat[16*7];
        std::cout << "--------------------------------" << std::endl;
        for(int i = 0; i != 16; i++) {
            // Project each vertex to the 3D space
            glm::vec4 vert4(vertices[i*4], vertices[i*4+1],
                            vertices[i*4+2], vertices[i*4+3]);
            glm::vec4 viewVert = view4D * (model4D * vert4 - from); 
            glm::vec3 vert3 = projection4D * view4D * (model4D * vert4 - from);

            printVec(viewVert, 4);

            projVert[i*7] = vert3.x;
            projVert[i*7+1] = vert3.y;
            projVert[i*7+2] = vert3.z;
            if (i < 8) {
                projVert[i*7+3] = 1.0f;
                projVert[i*7+4] = 0.0f;
                projVert[i*7+5] = 0.0f;
            } else {
                projVert[i*7+3] = 0.0f;
                projVert[i*7+4] = 0.0f;
                projVert[i*7+5] = 1.0f;
            }
            projVert[i*7+6] = (viewVert.w + 5.0f)/2.0f;
        }

        // 3D-2D Transformations
        glm::mat4 view3D = glm::lookAt(glm::vec3(3.0f, 1.2f, 2.0f),
                                       glm::vec3(0.0f, 0.0f, 0.0f),
                                       glm::vec3(0.0f, 1.0f, 0.0f));
        glm::mat4 proj3D = glm::perspective(glm::radians(45.0f),
                                            (float)WIDTH/(float)HEIGHT,
                                            0.1f, 100.0f);
        // Shader Uniforms
        edgeShader.Use();

        GLint viewLoc = glGetUniformLocation(edgeShader.Program,
                                             "view3D");
        GLint projectionLoc = glGetUniformLocation(edgeShader.Program,
                                                   "projection3D");
        glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view3D));
        glUniformMatrix4fv(projectionLoc, 1, GL_FALSE, glm::value_ptr(proj3D));

        // Load Vertices
        glBindVertexArray(VAO);
        glBindBuffer(GL_ARRAY_BUFFER, VBO);
        glBufferData(GL_ARRAY_BUFFER, 16*7*sizeof(GL_FLOAT), projVert, GL_DYNAMIC_DRAW);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, 
                     GL_DYNAMIC_DRAW);
        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 7*sizeof(GL_FLOAT), 
                              (GLvoid*)0);
        glEnableVertexAttribArray(0);
        glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 7*sizeof(GL_FLOAT), 
                              (GLvoid*)(3*sizeof(GL_FLOAT)));
        glEnableVertexAttribArray(1);

        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
        glDrawElements(GL_TRIANGLES, 8*12*3, GL_UNSIGNED_INT, 0);
        glBindVertexArray(0);

        // Swap the screen buffers
        glfwSwapBuffers(window);

        delete[] projVert;
    }

    // Terminate GLFW, clearing any resources allocated by GLFW.
    glfwTerminate();
    glDeleteVertexArrays(1, &VAO);
    glDeleteBuffers(1, &VBO);
    glDeleteBuffers(1, &EBO);
    return 0;
}