1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
|
/* by A Mennucci, Aug 2000
*
* code based on:
*
* diw_map.c: Digital Image Warping X graphical user interface
//
// Written and Copyright (C) 1994-1999 by Michael J. Gourlay
//
// PROVIDED AS IS. NO WARRANTEES, EXPRESS OR IMPLIED.
//
*/
/* Meshpoint picking and drawing parameters */
/* MP_PICK_DIST: farthest you may be from a Mesh point to pick it
currently ignored
*/
//#define MP_PICK_DIST 15
#define MP_SIZE 8
#define MP_ARC (360*64)
#include <stdio.h>
#include <stdlib.h>
#include "gtk/gtk.h"
//#include "xmorphspline.h"
#include "../libmorph/spl-array.h"
//#include "RgbaImage.h"
//#include "image_cb.h"
//#include "image_diw.h"
#include "../libmorph/mesh.h"
//#include "mjg_dialog.h"
#ifdef USE_IMLIB
#include <gdk_imlib.h>
#else
#include <gdk-pixbuf/gdk-pixbuf.h>
#endif
#include <gdk/gdkx.h>
#include <gdk/gdkrgb.h>
#include <gdk/gdk.h>
#include "main.h"
//#include "diw_map.h"
#include "drawmesh.h"
#define MY_CALLOC(A,B) (g_malloc0((A)*sizeof(B)))
#define FREE(A) (g_free(A))
/* --------------------------------------------------------------- */
/* NAME
// gdk_draw_mesh: Draw mesh lines and points for one mesh
//
//
//
//
// DESCRIPTION
// Draw mesh lines and points.
// Also draw the selected meshpoint.
//
// if subimage !=NULL, rescale the mesh to stay in the subimage
//
// SEE ALSO
// DrawMeshes
*/
typedef struct _GdkArc GdkArc;
struct _GdkArc {
gint filled;
gint x;
gint y;
gint width;
gint height;
gint angle1;
gint angle2;
} ;
//widget->style->black_gc
gboolean
gdk_draw_mesh(GdkDrawable *drawable,
GdkGC *lines_gc, //lines GC
GdkGC *points_gc, //points GC
MeshT *mesh,
GdkRectangle *subimage,
int height, //viewport height
int width //viewport width
)
{
//extern GC mpl_gc; /* mesh line graphics context */
//extern GC mp_gc; /* mesh point graphics context */
//extern GdkGC *mps_gc; /* (selected) mesh point graphics context */
//Display *display = XtDisplay(widget);
//Window window = XtWindow(widget);
GdkPoint *xpoints;
//XPoint *xpoints;
//XArc *xarcs;
int xi, yi;
const double *xsP = mesh->x;
const double *ysP = mesh->y;
//const double *xdP = dmP->mesh_dst.x;
//const double *ydP = dmP->mesh_dst.y;
//const double mpt = dmP->mesh_t;
double *x_tmp; //= mesh->x;
double *y_tmp; //= mesh->y;
double *xrow;
double *yrow;
// this is not defined currently in gdk, so we define it above
GdkArc xarc;
xarc.width = MP_SIZE;
xarc.height = MP_SIZE ;
xarc.angle1=0;
xarc.angle2=MP_ARC;
if(!(x_tmp=MY_CALLOC(MAX(mesh->nx,mesh->ny)+1, double))) {
return(FALSE);
}
if(!(y_tmp=MY_CALLOC(MAX(mesh->nx,mesh->ny)+1, double))) {
return(FALSE);
}
if(!(xrow=MY_CALLOC(MAX(width/4,height/4)+1, double)))
{
return(FALSE);
}
if(!(yrow=MY_CALLOC(MAX(width/4,height/4)+1, double)))
{
return(FALSE);
}
if(!(xpoints=MY_CALLOC(MAX(width/4,height/4)+1, GdkPoint)))
{
return(FALSE);
}
//if(!(xarcs = MY_CALLOC(mesh->ny, GdkArc))) {
// return(FALSE);
//}
/* Draw meshpoints and vertical meshlines */
for(xi=0; xi < mesh->nx; xi++) {
/* Draw vertical mesh lines */
{
/* Create 1D array of mesh points knots */
if(subimage)
for(yi=0; yi<mesh->ny; yi++) {
x_tmp[yi] =
xsP[yi*mesh->nx + xi] * subimage->width /width + subimage->x;
y_tmp[yi] =
ysP[yi*mesh->nx + xi]* subimage->height /height+ subimage->y;
}
else
for(yi=0; yi<mesh->ny; yi++) {
x_tmp[yi] = xsP[yi*mesh->nx + xi];
y_tmp[yi] = ysP[yi*mesh->nx + xi];
}
#ifdef USE_SPLINES
/* Create abcissas of interpolant to make a smoothly drawn mesh line */
for(yi=0; yi<(height/4); yi++)
yrow[yi] = yi*4;
/* Make sure last abcissa is set */
yrow[yi-1] = height-1;
/* Create the interpolated line segments */
hermite3_array(y_tmp, x_tmp, mesh->ny, yrow, xrow, height/4);
/* Create an array of XPoints to draw smoothly interpolated mesh line */
for(yi=0; yi<(height/4); yi++) {
xpoints[yi].x = (int) xrow[yi];
xpoints[yi].y = (int) yrow[yi];
}
/* Draw the smoothly interpolated mesh line */
gdk_draw_lines(drawable,lines_gc , xpoints,height/4);
#else USE_SPLINES
for(yi=0; yi< mesh->ny; yi++) {
xpoints[yi].x = (int) x_tmp[yi];
xpoints[yi].y = (int) y_tmp[yi];
}
/* Draw the mesh lines */
gdk_draw_lines(drawable,lines_gc , xpoints, mesh->ny);
#endif
}
/* Draw mesh points */
{
for(yi=0; yi<mesh->ny; yi++) {
xarc.x = x_tmp[yi] ;
xarc.y = y_tmp[yi] ;
if ( meshGetLabel(mesh,xi,yi))
gdk_draw_arc (drawable, points_gc,
TRUE,
xarc. x - MP_SIZE/2,
xarc. y - MP_SIZE/2,
xarc. width,
xarc. height,
xarc. angle1,
xarc. angle2 );
#ifdef DRAW_UNSELECTED_POINTS
else
gdk_draw_arc (drawable, lines_gc,
TRUE,
xarc. x - MP_SIZE/2,
xarc. y - MP_SIZE/2,
xarc. width/2,
xarc. height/2,
xarc. angle1,
xarc. angle2 );
#endif
}
}
}
/* Draw horizontal meshlines */
{
for(yi=0; yi<mesh->ny; yi++) {
if(subimage)
for(xi=0; xi<mesh->nx; xi++) {
x_tmp[xi] =
xsP[yi*mesh->nx + xi]* subimage->width /width + subimage->x;
y_tmp[xi] =
ysP[yi*mesh->nx + xi]* subimage->height /height+ subimage->y;
}
else
for(xi=0; xi<mesh->nx; xi++) {
x_tmp[xi] = xsP[yi*mesh->nx + xi];
y_tmp[xi] = ysP[yi*mesh->nx + xi];
}
#ifdef USE_SPLINES
for(xi=0; xi<(width/4); xi++)
xrow[xi] = xi*4;
xrow[xi-1] = width-1;
hermite3_array(x_tmp, y_tmp, mesh->nx, xrow, yrow, width/4);
for(xi=0; xi<(width/4); xi++) {
xpoints[xi].x = (int) xrow[xi];
xpoints[xi].y = (int) yrow[xi];
}
gdk_draw_lines (drawable, lines_gc,
xpoints, width/4);
#else
for(xi=0; xi<mesh->nx; xi++) {
xpoints[xi].x = (int) x_tmp[xi];
xpoints[xi].y = (int) y_tmp[xi];
}
gdk_draw_lines (drawable, lines_gc,
xpoints, mesh->nx);
#endif
}
}
for(yi=0; yi<mesh->ny; yi++) {
for(xi=0; xi<mesh->nx; xi++) {
}}
//FREE(x_tmp);
//FREE(y_tmp);
g_free(xrow);
g_free(yrow);
g_free(xpoints);
return(TRUE);
}
|