~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/covira/spline_pick.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #include <tina/all_tina.h>
  2 #include <tina/brain.h>
  3 #include <tina/brainfuncs.h>
  4 
  5 static List *points = NULL;
  6 static Bool newspline = true;
  7 
  8 /* setting up spline interpolation points */
  9 
 10 static void spline_mark_point(Tv * tv, Ipos pos)
 11 {
 12     Vec2 v;
 13     if (newspline)
 14     {
 15         dd_list_rm(points, rfree);
 16         points = NULL;
 17         newspline = false;
 18     }
 19     v = tv_backproj2(tv, pos);
 20     points = dd_ref_addtostart(points, vec2_make(v), VEC2);
 21     tv_save_draw(tv);
 22     tv_set_color(tv, magenta);
 23     tv_bigdot2(tv, v, 2);
 24     tv_reset_draw(tv);
 25 }
 26 
 27 static double area(List * points)
 28 {
 29     List *ptr;
 30     double a = 0.0;
 31     for (ptr = points; ptr != NULL; ptr = ptr->next)
 32     {
 33         Vec2 v1, v2;
 34         v1 = *((Vec2 *) ptr->to);
 35         if (ptr->next != NULL)
 36             v2 = *((Vec2 *) ptr->next->to);
 37         else
 38             v2 = *((Vec2 *) points->to);
 39         a += vec2_cross(v1, v2);
 40     }
 41     a *= 0.5;
 42     return (a);
 43 }
 44 
 45 /* constructing interpolating spline */
 46 void spline_save_periodic(Tv * tv, Ipos pos)
 47 {
 48     Spline2 *spline;
 49 
 50     if(dd_list_length(points) < 3)
 51     {
 52         error("spline_save_periodic: < 3 points", warning);
 53         return;
 54     }
 55     if (area(points) < 0.0)
 56         points = dd_list_reverse(points);
 57     spline = spline2_interpolate_ddlist(SPLINE_PERIODIC, points);
 58     newspline = true;
 59     ims_spline_set(spline);
 60     tv_repaint(tv);
 61 }
 62 
 63 /* constructing interpolating spline */
 64 void spline_save_tube(Tv * tv, Ipos pos)
 65 {
 66     static Spline2 *spline1 = NULL, *spline2 = NULL;
 67 
 68     if(dd_list_length(points) < 3)
 69     {
 70         error("spline_save_tube: < 3 points", warning);
 71         return;
 72     }
 73     if(spline1 == NULL)
 74     {
 75         spline1 = spline2_interpolate_ddlist(SPLINE_NATURAL, points);
 76         newspline = true;
 77         tv_save_draw(tv);
 78         tv_color_set(tv, magenta);
 79         spline2_draw(tv, spline1);
 80         tv_reset_draw(tv);
 81         return;
 82     }
 83     spline2 = spline2_interpolate_ddlist(SPLINE_NATURAL, points);
 84     newspline = true;
 85 
 86     ims_sagit_tube_set(spline1, spline2, (double) ims_x_get());
 87     spline2_free(spline1); spline1 = NULL;
 88     spline2_free(spline2); spline2 = NULL;
 89     tv_repaint(tv);
 90 }
 91 
 92 /* replacing spline interpolation points */
 93 
 94 static int iclose;
 95 static void spline_replace_down(Tv * tv, Ipos pos)
 96 {
 97     Spline2 *spline;
 98     Vec2 p;
 99 
100     if ((spline = ims_spline_get()) == NULL)
101         return;
102     p = tv_backproj2(tv, pos);
103     iclose = ROUND(spline2_param(spline, p));
104     if (iclose == spline->n)
105         iclose = 0;
106     spline2_replace_point(spline, iclose, p);
107     tv_set_overlay(tv);
108     spline2_draw(tv, spline);
109 }
110 
111 static void spline_replace_drag(Tv * tv, Ipos pos)
112 {
113     Spline2 *spline;
114     Vec2 p;
115 
116     if ((spline = ims_spline_get()) == NULL)
117         return;
118     spline2_draw(tv, spline);
119     p = tv_backproj2(tv, pos);
120     spline2_replace_point(spline, iclose, p);
121     spline2_draw(tv, spline);
122 }
123 
124 static void spline_replace_up(Tv * tv, Ipos pos)
125 {
126     Spline2 *spline;
127     Vec2 p;
128 
129     if ((spline = ims_spline_get()) == NULL)
130         return;
131     p = tv_backproj2(tv, pos);
132     spline2_replace_point(spline, iclose, p);
133     ims_spline_changed();
134 
135     tv_reset_draw(tv);
136     tv_repaint(tv);
137 }
138 
139 static void spline_insert_point(Tv * tv, Ipos pos)
140 {
141     Spline2 *spline;
142     int ibelow;
143     Vec2 p;
144 
145     if ((spline = ims_spline_get()) == NULL)
146         return;
147 
148     p = tv_backproj2(tv, pos);
149     ibelow = spline2_param(spline, p);
150     spline2_add_point(spline, ibelow, p);
151     ims_spline_changed();
152 
153     tv_repaint(tv);
154 }
155 
156 static void spline_remove_point(Tv * tv, Ipos pos)
157 {
158     Spline2 *spline;
159     Vec2 p;
160     int iclose;
161 
162     if ((spline = ims_spline_get()) == NULL || spline->n <= 3 /** 5 **/ )
163         return;
164 
165     p = tv_backproj2(tv, pos);
166     iclose = ROUND(spline2_param(spline, p));
167     if (iclose == spline->n)
168         iclose = 0;
169     spline2_delete_point(spline, iclose);
170     ims_spline_changed();
171 
172     tv_repaint(tv);
173 }
174 
175 Tv_mouse spline_periodic_draw_mouse(void)
176 {
177     return (mouse_define(MOUSE_NAME, "spline draw",
178                          LEFT_NAME, "mark",
179                          LEFT_DOWN, spline_mark_point,
180                          MIDDLE_NAME, "save",
181                          MIDDLE_DOWN, spline_save_periodic,
182                          NULL));
183 }
184 
185 Tv_mouse spline_tube_draw_mouse(void)
186 {
187     return (mouse_define(MOUSE_NAME, "spline draw",
188                          LEFT_NAME, "mark",
189                          LEFT_DOWN, spline_mark_point,
190                          MIDDLE_NAME, "save",
191                          MIDDLE_DOWN, spline_save_tube,
192                          NULL));
193 }
194 
195 Tv_mouse spline_edit_mouse(void)
196 {
197     return (mouse_define(MOUSE_NAME, "spline edit",
198                          LEFT_NAME, "replace",
199                          LEFT_DOWN, spline_replace_down,
200                          LEFT_DRAG, spline_replace_drag,
201                          LEFT_UP, spline_replace_up,
202                          MIDDLE_NAME, "add",
203                          MIDDLE_DOWN, spline_insert_point,
204                          RIGHT_NAME, "delete",
205                          RIGHT_DOWN, spline_remove_point,
206                          NULL));
207 }
208 
209 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.