mirror of
https://github.com/eddyem/apogee_control.git
synced 2026-03-20 00:31:09 +03:00
simple relative coordinates when point by mouse (if ROT0, CRPIX1 and CRPIX2 given)
This commit is contained in:
@@ -37,6 +37,8 @@ void processKeybrd(unsigned char key, int mod, int win_GL_ID, _U_ int x, _U_ int
|
||||
case 27:
|
||||
destroyWindow_async(win_GL_ID);
|
||||
break;
|
||||
/* case 'x':
|
||||
break;*/
|
||||
case 'Z':
|
||||
win->zoom *= 1.1;
|
||||
calc_win_props(win, NULL, NULL);
|
||||
@@ -67,6 +69,11 @@ void keySpPressed(_U_ int key, _U_ int x, _U_ int y){
|
||||
DBG("Sp. key pressed. mod=%d, keycode=%d, point=(%d,%d)\n", glutGetModifiers(), key, x,y);
|
||||
}
|
||||
|
||||
// in defhdrs.c
|
||||
extern void calc_coords(float x, float y, double *alpha, double *delta);
|
||||
extern char *time_asc(double t);
|
||||
extern char *angle_asc(double a);
|
||||
|
||||
int oldx, oldy; // coordinates when mouse was pressed
|
||||
int movingwin = 0; // ==1 when user moves image by middle button
|
||||
void mousePressed(_U_ int key, _U_ int state, _U_ int x, _U_ int y){
|
||||
@@ -78,8 +85,16 @@ void mousePressed(_U_ int key, _U_ int state, _U_ int x, _U_ int y){
|
||||
if(state == GLUT_DOWN){
|
||||
oldx = x; oldy = y;
|
||||
float X,Y;
|
||||
double RA, D;
|
||||
conv_mouse_to_image_coords(x,y,&X,&Y,win);
|
||||
DBG("press in (%d, %d) == (%f, %f) on image; mod == %d", x,y,X,Y, mod);
|
||||
calc_coords(X, Y, &RA, &D);
|
||||
printf("x = %f, y= %f", X, Y);
|
||||
/// "úÁÄÁÊÔÅ WCS ÐÁÒÁÍÅÔÒÙ, ÐÏ ËÒÁÊÎÅÊ ÍÅÒÅ ROT0, CRPIX1 É CRPIX2"
|
||||
if(RA > 4e6){
|
||||
printf("\n");
|
||||
WARNX(_("Give WCS parameters, at least ROT0, CRPIX1 and CRPIX2"));
|
||||
}else printf(", ra = %s, dec=%s\n", angle_asc(RA), time_asc(D));
|
||||
if(key == GLUT_MIDDLE_BUTTON) movingwin = 1;
|
||||
if(key == 3){ // wheel UP
|
||||
if(mod == 0) win->y += 10.*win->zoom; // nothing pressed - scroll up
|
||||
@@ -94,47 +109,20 @@ void mousePressed(_U_ int key, _U_ int state, _U_ int x, _U_ int y){
|
||||
}else{
|
||||
movingwin = 0;
|
||||
}
|
||||
/* DBG("Mouse button %s. point=(%d, %d); mod=%d, button=%d\n",
|
||||
(state == GLUT_DOWN)? "pressed":"released", x, y, glutGetModifiers(), key);*/
|
||||
}
|
||||
|
||||
/* int window = glutGetWindow();
|
||||
if(window == WaveWindow){ // ÝÅÌËÎÕÌÉ × ÏËÎÅ Ó ×ÅÊ×ÌÅÔÏÍ
|
||||
_U_ int w = glutGet(GLUT_WINDOW_WIDTH) / 2;
|
||||
_U_ int h = glutGet(GLUT_WINDOW_HEIGHT) / 2;
|
||||
if(state == GLUT_DOWN && key == GLUT_LEFT_BUTTON){
|
||||
//HistCoord[0] = (x > w);
|
||||
//HistCoord[1] = (y > h);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
/* this doesn't work
|
||||
void mouseWheel(int button, int dir, int x, int y){
|
||||
int window = glutGetWindow();
|
||||
windowData *win = searchWindow_byGLID(window);
|
||||
if(!win) return;
|
||||
DBG("Mouse wheel, dir: %d. point=(%d, %d); mod=%d, button=%d\n",
|
||||
dir, x, y, glutGetModifiers(), button);
|
||||
}
|
||||
*/
|
||||
void mouseMove(_U_ int x, _U_ int y){
|
||||
int window = glutGetWindow();
|
||||
windowData *win = searchWindow_byGLID(window);
|
||||
if(!win) return;
|
||||
//DBG("Mouse moved to (%d, %d)\n", x, y);
|
||||
if(movingwin){
|
||||
float X, Y, nx, ny;//, w2, h2;
|
||||
float X, Y, nx, ny;
|
||||
float a = win->Daspect;
|
||||
X = (x - oldx) * a; Y = (y - oldy) * a;
|
||||
nx = win->x + X;
|
||||
ny = win->y - Y;
|
||||
// w2 = win->image->w / 2. * win->zoom;
|
||||
// h2 = win->image->h / 2. * win->zoom;
|
||||
|
||||
// if(nx < w2 && nx > -w2)
|
||||
win->x = nx;
|
||||
// if(ny < h2 && ny > -h2)
|
||||
win->y = ny;
|
||||
win->x = nx;
|
||||
win->y = ny;
|
||||
oldx = x;
|
||||
oldy = y;
|
||||
calc_win_props(win, NULL, NULL);
|
||||
@@ -162,6 +150,7 @@ void createMenu(int GL_ID){
|
||||
glutAddMenuEntry("Quit (ctrl+q)", 'q');
|
||||
glutAddMenuEntry("Close this window (ESC)", 27);
|
||||
glutAddMenuEntry("Restore zoom (1)", '1');
|
||||
// glutAddMenuEntry("Make exposition (x)", 'x');
|
||||
glutAttachMenu(GLUT_RIGHT_BUTTON);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,5 @@ void mousePressed(int key, int state, int x, int y);
|
||||
void mouseMove(int x, int y);
|
||||
void createMenu(int window);
|
||||
void menuEvents(int opt);
|
||||
//void mouseWheel(int button, int dir, int x, int y);
|
||||
|
||||
#endif // __EVENTS_H__
|
||||
|
||||
@@ -80,28 +80,20 @@ void createWindow(windowData *win){
|
||||
glutDisplayFunc(RedrawWindow);
|
||||
glutKeyboardFunc(keyPressed);
|
||||
glutSpecialFunc(keySpPressed);
|
||||
//glutMouseWheelFunc(mouseWheel);
|
||||
glutMouseFunc(mousePressed);
|
||||
glutMotionFunc(mouseMove);
|
||||
//glutIdleFunc(glutPostRedisplay);
|
||||
glutIdleFunc(NULL);
|
||||
DBG("init textures");
|
||||
glGenTextures(1, &(win->Tex));
|
||||
win->zoom = 1.;
|
||||
// calc_win_props(win, NULL, NULL);
|
||||
// win->zoom = 1. / win->Daspect;
|
||||
// DBG("Daspect: %g, zoom: %g", win->Daspect, win->zoom);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, win->Tex);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
// glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
// glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
|
||||
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, win->image->w, win->image->h, 0,
|
||||
GL_RGB, GL_UNSIGNED_BYTE, win->image->rawdata);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
@@ -194,19 +186,6 @@ void redisplay(int GL_ID){
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
||||
/*
|
||||
if(redraw)
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h,
|
||||
GL_LUMINANCE, GL_FLOAT, ptro); // s/image->data/tex/
|
||||
else
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_INTENSITY, w, h,
|
||||
0, GL_LUMINANCE, GL_FLOAT, ptro);
|
||||
//glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
|
||||
//glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
|
||||
*/
|
||||
|
||||
void RedrawWindow(){
|
||||
if(!initialized) return;
|
||||
int window;
|
||||
@@ -218,7 +197,6 @@ void RedrawWindow(){
|
||||
glClearColor(0.0, 0.0, 0.0, 1.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glLoadIdentity();
|
||||
//glTranslatef(win->x-w/2., win->y-h/2., win->z);
|
||||
glTranslatef(win->x, win->y, 0.);
|
||||
glScalef(-win->zoom, -win->zoom, 1.);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
@@ -229,14 +207,6 @@ void RedrawWindow(){
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, win->image->rawdata);
|
||||
win->image->changed = 0;
|
||||
}
|
||||
/*
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0., 1.); glVertex3f(0., 0., 0.);
|
||||
glTexCoord2f(0., 0.); glVertex3f(0.,h, 0.);
|
||||
glTexCoord2f(1., 0.); glVertex3f(w, h, 0.);
|
||||
glTexCoord2f(1., 1.); glVertex3f(w, 0., 0.);
|
||||
glEnd();
|
||||
*/
|
||||
w /= 2.; h /= 2.;
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0.0f, 0.0f); glVertex2f(-w, -h );
|
||||
@@ -255,10 +225,6 @@ void RedrawWindow(){
|
||||
* waits for global signals to create windows & make other actions
|
||||
*/
|
||||
void *Redraw(_U_ void *arg){
|
||||
// pthread_cond_t fakeCond = PTHREAD_COND_INITIALIZER;
|
||||
// struct timeval tv;
|
||||
// struct timespec timeToWait;
|
||||
// struct timeval now;
|
||||
while(1){
|
||||
pthread_mutex_lock(&winini_mutex);
|
||||
if(!initialized){
|
||||
@@ -279,22 +245,8 @@ void *Redraw(_U_ void *arg){
|
||||
wannakill_GL_ID = 0;
|
||||
}
|
||||
forEachWindow(redisplay);
|
||||
/* gettimeofday(&now,NULL);
|
||||
timeToWait.tv_sec = now.tv_sec;
|
||||
timeToWait.tv_nsec = now.tv_usec * 1000UL + 10000000UL;
|
||||
pthread_cond_timedwait(&fakeCond, &winini_mutex, &timeToWait);*/
|
||||
pthread_mutex_unlock(&winini_mutex);
|
||||
//pthread_testcancel();
|
||||
if(totWindows) glutMainLoopEvent(); // process actions if there are windows
|
||||
/* gettimeofday(&now,NULL);
|
||||
timeToWait.tv_sec = now.tv_sec;
|
||||
timeToWait.tv_nsec = now.tv_usec * 1000UL + 10000000UL;
|
||||
pthread_mutex_lock(&fakeMutex);
|
||||
pthread_cond_timedwait(&fakeCond, &fakeMutex, &timeToWait);
|
||||
pthread_mutex_unlock(&fakeMutex);*/
|
||||
/* tv.tv_sec = 0;
|
||||
tv.tv_usec = 10000;
|
||||
select(0, NULL, NULL, NULL, &tv);*/
|
||||
usleep(10000);
|
||||
}
|
||||
return NULL;
|
||||
@@ -305,22 +257,15 @@ void Resize(int width, int height){
|
||||
int window = glutGetWindow();
|
||||
windowData *win = searchWindow_byGLID(window);
|
||||
if(!win) return;
|
||||
/* int GRAB_WIDTH = win->w, GRAB_HEIGHT = win->h;
|
||||
float _U_ tmp, wd = (float) width/GRAB_WIDTH, ht = (float)height/GRAB_HEIGHT;
|
||||
tmp = (wd + ht) / 2.;
|
||||
width = (int)(tmp * GRAB_WIDTH); height = (int)(tmp * GRAB_HEIGHT);*/
|
||||
glutReshapeWindow(width, height);
|
||||
win->w = width;
|
||||
win->h = height;
|
||||
glViewport(0, 0, width, height);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
//GLfloat W = (GLfloat)GRAB_WIDTH; GLfloat H = (GLfloat)GRAB_HEIGHT;
|
||||
GLfloat W, H;
|
||||
calc_win_props(win, &W, &H);
|
||||
glOrtho(-W,W, -H,H, -1., 1.);
|
||||
// gluPerspective(90., W/H, 0., 100.0);
|
||||
// gluLookAt(0., 0., H/2., 0., 0., 0., 0., 1., 0.);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
}
|
||||
@@ -389,11 +334,12 @@ void imageview_init(){
|
||||
int c = 1;
|
||||
static int glutnotinited = 1;
|
||||
if(initialized){
|
||||
// "Уже инициализировано!"
|
||||
// "õÖÅ ÉÎÉÃÉÁÌÉÚÉÒÏ×ÁÎÏ!"
|
||||
WARNX(_("Already initialized!"));
|
||||
return;
|
||||
}
|
||||
if(glutnotinited){
|
||||
DBG("init");
|
||||
XInitThreads(); // we need it for threaded windows
|
||||
glutInit(&c, v);
|
||||
glutnotinited = 0;
|
||||
@@ -419,12 +365,10 @@ void clear_GL_context(){
|
||||
initialized = 0;
|
||||
DBG("locked");
|
||||
// kill main GLUT thread
|
||||
// pthread_cancel(GLUTthread);
|
||||
pthread_mutex_unlock(&winini_mutex);
|
||||
forEachWindow(killwindow_v);
|
||||
DBG("join");
|
||||
pthread_join(GLUTthread, NULL); // wait while main thread exits
|
||||
// pthread_mutex_unlock(&winini_mutex);
|
||||
DBG("main GL thread cancelled");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user