From 29a37cd9fa1c7a55fd7e09c0b532189789a85fb8 Mon Sep 17 00:00:00 2001 From: David Mayerich Date: Tue, 18 Apr 2017 11:04:25 -0500 Subject: [PATCH] fixed matrix_sym errors, changed the glut_template to a CPP file --- python/structen.py | 4 ++++ stim/math/matrix_sym.h | 4 ++-- stim/math/tensor3.h | 10 +++++----- stim/visualization/glut_template.cpp | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ stim/visualization/glut_template.h | 99 --------------------------------------------------------------------------------------------------- 5 files changed, 114 insertions(+), 106 deletions(-) create mode 100644 stim/visualization/glut_template.cpp delete mode 100644 stim/visualization/glut_template.h diff --git a/python/structen.py b/python/structen.py index 3eb0bea..f284ff6 100644 --- a/python/structen.py +++ b/python/structen.py @@ -127,6 +127,10 @@ def sym2mat(T): def st2vec(S, vector='largest'): #Create a color image from a 2D or 3D structure tensor slice + + if(S.ndim != 3): + print("ERROR: a 2D slice is expected") + return #convert the field to a full rank-2 tensor T = sym2mat(S); diff --git a/stim/math/matrix_sym.h b/stim/math/matrix_sym.h index 4cac755..8761c43 100644 --- a/stim/math/matrix_sym.h +++ b/stim/math/matrix_sym.h @@ -48,8 +48,8 @@ protected: public: //return the symmetric matrix associated with this tensor - stim::matrix mat() { - stim::matrix r; + stim::matrix mat() { + stim::matrix r; r.setsym(M); return r; } diff --git a/stim/math/tensor3.h b/stim/math/tensor3.h index b18a67b..acfacfe 100644 --- a/stim/math/tensor3.h +++ b/stim/math/tensor3.h @@ -73,12 +73,12 @@ namespace stim { return lam; } - CUDA_CALLABLE stim::matrix eig(stim::vec3& lambda = stim::vec3()) { - stim::matrix V; + CUDA_CALLABLE stim::matrix eig(stim::vec3& lambda = stim::vec3()) { + stim::matrix V; - stim::matrix M1 = matrix_sym::mat(); - stim::matrix M2 = matrix_sym::mat(); - stim::matrix M3 = matrix_sym::mat(); // fill a tensor with symmetric values + stim::matrix M1 = matrix_sym::mat(); + stim::matrix M2 = matrix_sym::mat(); + stim::matrix M3 = matrix_sym::mat(); // fill a tensor with symmetric values M1 = M1 - lambda[0]; // M1 = A - lambda[0] * I diff --git a/stim/visualization/glut_template.cpp b/stim/visualization/glut_template.cpp new file mode 100644 index 0000000..40be42e --- /dev/null +++ b/stim/visualization/glut_template.cpp @@ -0,0 +1,103 @@ +/* Don't change this file. Make a copy in your project and change parameters as necessary. + + In order to use this template, specify the following signature in your main.cpp file: + void glut_init(int argc, char* argv[]); + +*/ + +#ifndef GLUT_TEMPLATE_H +#define GLUT_TEMPLATE_H + +#include +#include + +struct glut_template_struct { + float theta_scale = 0.01f; + float phi_scale = 0.01f; + float zoom_scale = 0.1f; + stim::camera cam; //create a camera object + int mx, my; //mouse coordinates in the window space + float d = 1.5; //initial distance between the camera and the sphere + bool rotate_zoom = true; //sets the current camera mode (rotation = true, zoom = false) + + bool axis = false; //render the z-axis (set via a command line flag) +} gt; + +//render the XYZ axes +void render_axes() { + glDisable(GL_TEXTURE_2D); //turn off texture mapping + glBegin(GL_LINES); + glColor3f(1.0f, 0.0f, 0.0f); //set the color to RED and render X + glVertex3f(0.0, 0.0, 0.0); + glVertex3f(100.0, 0.0, 0.0); + + glColor3f(0.0f, 1.0f, 0.0f); //set the color to RED and render X + glVertex3f(0.0, 0.0, 0.0); + glVertex3f(0.0, 100.0, 0.0); + + glColor3f(0.0f, 0.0f, 1.0f); //set the color to RED and render X + glVertex3f(0.0, 0.0, 0.0); + glVertex3f(0.0, 0.0, 100.0); + glEnd(); +} + +//display function executed to update every frame +void glut_display() { + + glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); //clear the screen + + glMatrixMode(GL_PROJECTION); //put the projection matrix on the stack + glLoadIdentity(); //set it to the identity matrix + gluPerspective(gt.cam.getFOV(), 1, 0.001, 1000000); //set up a perspective projection + glMatrixMode(GL_MODELVIEW); //load the model view matrix to the stack + glLoadIdentity(); //set it to the identity matrix + stim::vec3 p = gt.cam.getPosition(); //get the camera parameters + stim::vec3 u = gt.cam.getUp(); + stim::vec3 d = gt.cam.getDirection(); + gluLookAt(p[0], p[1], p[2], d[0], d[1], d[2], u[0], u[1], u[2]); //specify the camera parameters to OpenGL + + render_axes(); //render the axes if the user requests them + glutSwapBuffers(); //swap in the back buffer (double-buffering is used to prevent tearing) +} + +//process mouse press events +void glut_mouse_press(int button, int state, int x, int y) { + if (button == GLUT_LEFT_BUTTON) //set the camera motion mode based on the mouse button pressed + gt.rotate_zoom = true; + else if (button == GLUT_RIGHT_BUTTON) + gt.rotate_zoom = false; + if (state == GLUT_DOWN) { //if the mouse is pressed + gt.mx = x; gt.my = y; //set the current mouse position + } +} + +//process mouse drags to update the camera +void glut_mouse_drag(int x, int y) { + if (gt.rotate_zoom == true) { //if the camera is in rotation mode, rotate + float theta = gt.theta_scale * (gt.mx - x); + float phi = -gt.phi_scale * (gt.my - y); + gt.cam.OrbitFocus(theta, phi); //if the mouse is dragged + } + else { //otherwize zoom + gt.cam.Push(gt.zoom_scale*(gt.my - y)); + } + gt.mx = x; gt.my = y; //update the mouse position + glutPostRedisplay(); +} + +void glut_init(int argc, char* argv[]) { + glutInit(&argc, argv); //initialize GLUT + glutInitWindowSize(500, 500); //set the size of the GLUT window + glutInitDisplayMode(GLUT_DEPTH | GLUT_RGBA | GLUT_DOUBLE); + glutCreateWindow("3D Tensor Visualization"); //create the GLUT window (and an OpenGL context) + glutDisplayFunc(glut_display); //set the display function (which will be called repeatedly by glutMainLoop) + glutMouseFunc(glut_mouse_press); //set the mouse press function (called when a mouse button is pressed) + glutMotionFunc(glut_mouse_drag); //set the mouse motion function (which will be called any time the mouse is dragged) + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); //set the clear color to white + gt.cam.setPosition(gt.d, gt.d, gt.d); //initialize the camera + gt.cam.LookAt(0, 0, 0, 0, 1, 1); + gt.cam.setFOV(40); + glutMainLoop(); //enter the main loop +} + +#endif \ No newline at end of file diff --git a/stim/visualization/glut_template.h b/stim/visualization/glut_template.h deleted file mode 100644 index 15aad96..0000000 --- a/stim/visualization/glut_template.h +++ /dev/null @@ -1,99 +0,0 @@ -/* Don't change this file. Make a copy in your project and change parameters as necessary. */ - -#ifndef GLUT_TEMPLATE_H -#define GLUT_TEMPLATE_H - -#include -#include - -struct glut_template_struct { - float theta_scale = 0.01f; - float phi_scale = 0.01f; - float zoom_scale = 0.1f; - stim::camera cam; //create a camera object - int mx, my; //mouse coordinates in the window space - float d = 1.5; //initial distance between the camera and the sphere - bool rotate_zoom = true; //sets the current camera mode (rotation = true, zoom = false) - - bool axis = false; //render the z-axis (set via a command line flag) -} gt; - -//render the XYZ axes -void render_axes() { - glDisable(GL_TEXTURE_2D); //turn off texture mapping - glBegin(GL_LINES); - glColor3f(1.0f, 0.0f, 0.0f); //set the color to RED and render X - glVertex3f(0.0, 0.0, 0.0); - glVertex3f(100.0, 0.0, 0.0); - - glColor3f(0.0f, 1.0f, 0.0f); //set the color to RED and render X - glVertex3f(0.0, 0.0, 0.0); - glVertex3f(0.0, 100.0, 0.0); - - glColor3f(0.0f, 0.0f, 1.0f); //set the color to RED and render X - glVertex3f(0.0, 0.0, 0.0); - glVertex3f(0.0, 0.0, 100.0); - glEnd(); -} - -//display function executed to update every frame -void glut_display() { - - glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); //clear the screen - - glMatrixMode(GL_PROJECTION); //put the projection matrix on the stack - glLoadIdentity(); //set it to the identity matrix - gluPerspective(gt.cam.getFOV(), 1, 0.001, 1000000); //set up a perspective projection - glMatrixMode(GL_MODELVIEW); //load the model view matrix to the stack - glLoadIdentity(); //set it to the identity matrix - stim::vec3 p = gt.cam.getPosition(); //get the camera parameters - stim::vec3 u = gt.cam.getUp(); - stim::vec3 d = gt.cam.getDirection(); - gluLookAt(p[0], p[1], p[2], d[0], d[1], d[2], u[0], u[1], u[2]); //specify the camera parameters to OpenGL - - - render_axes(); //render the axes if the user requests them - glutSwapBuffers(); //swap in the back buffer (double-buffering is used to prevent tearing) -} - -//process mouse press events -void glut_mouse_press(int button, int state, int x, int y) { - if (button == GLUT_LEFT_BUTTON) //set the camera motion mode based on the mouse button pressed - gt.rotate_zoom = true; - else if (button == GLUT_RIGHT_BUTTON) - gt.rotate_zoom = false; - if (state == GLUT_DOWN) { //if the mouse is pressed - gt.mx = x; gt.my = y; //set the current mouse position - } -} - -//process mouse drags to update the camera -void glut_mouse_drag(int x, int y) { - if (gt.rotate_zoom == true) { //if the camera is in rotation mode, rotate - float theta = gt.theta_scale * (gt.mx - x); - float phi = -gt.phi_scale * (gt.my - y); - gt.cam.OrbitFocus(theta, phi); //if the mouse is dragged - } - else { //otherwize zoom - gt.cam.Push(gt.zoom_scale*(gt.my - y)); - } - gt.mx = x; gt.my = y; //update the mouse position - glutPostRedisplay(); -} - -void glut_init(int argc, char* argv[]) { - glutInit(&argc, argv); //initialize GLUT - glutInitWindowSize(500, 500); //set the size of the GLUT window - glutInitDisplayMode(GLUT_DEPTH | GLUT_RGBA | GLUT_DOUBLE); - glutCreateWindow("3D Tensor Visualization"); //create the GLUT window (and an OpenGL context) - glutDisplayFunc(glut_display); //set the display function (which will be called repeatedly by glutMainLoop) - glutMouseFunc(glut_mouse_press); //set the mouse press function (called when a mouse button is pressed) - glutMotionFunc(glut_mouse_drag); //set the mouse motion function (which will be called any time the mouse is dragged) - glClearColor(1.0f, 1.0f, 1.0f, 1.0f); //set the clear color to white - gt.cam.setPosition(gt.d, gt.d, gt.d); //initialize the camera - gt.cam.LookAt(0, 0, 0, 0, 1, 1); - gt.cam.setFOV(40); - glutMainLoop(); //enter the main loop -} - -#endif \ No newline at end of file -- libgit2 0.21.4