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

Linux Cross Reference
Tina6/tina-libs/tina/geometry/geomLine_poly_trans.c

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

  1 /**********
  2  * 
  3  * This file is part of the TINA Open Source Image Analysis Environment
  4  * henceforth known as TINA
  5  *
  6  * TINA is free software; you can redistribute it and/or modify
  7  * it under the terms of the GNU General Public License as 
  8  * published by the Free Software Foundation.
  9  *
 10  * TINA is distributed in the hope that it will be useful,
 11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  * GNU General Public License for more details.
 14  *
 15  * You should have received a copy of the GNU General Public License
 16  * along with TINA; if not, write to the Free Software Foundation, Inc., 
 17  * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 18  *
 19  * ANY users of TINA who require exemption from the existing licence must
 20  * negotiate a new licence with Dr. Neil.A.Thacker, the sole agent for
 21  * the University of Manchester.
 22  *
 23  **********
 24  * 
 25  * Program :    TINA
 26  * File    :  $Source: /home/tina/cvs/tina-libs/tina/geometry/geomLine_poly_trans.c,v $
 27  * Date    :  $Date: 2008/12/04 15:28:02 $
 28  * Version :  $Revision: 1.5 $
 29  * CVS Id  :  $Id: geomLine_poly_trans.c,v 1.5 2008/12/04 15:28:02 paul Exp $
 30  *
 31  * Notes : Anthony Ashbrook. 30th June 1993.
 32  *
 33  *********
 34 */
 35 
 36 
 37 #include "geomLine_poly_trans.h"
 38 
 39 #if HAVE_CONFIG_H
 40   #include <config.h>
 41 #endif
 42 
 43 #include <tina/sys/sysDef.h>
 44 #include <tina/sys/sysPro.h>
 45 #include <tina/math/mathDef.h>
 46 #include <tina/math/mathPro.h>
 47 #include <tina/geometry/geom_GenPro.h>
 48 #include <tina/geometry/geomDef.h>
 49 #include <tina/geometry/geomLine_2line.h>
 50 #include <tina/geometry/geomLine_2trans.h>
 51 
 52 /*--------------------------------------------*/
 53 
 54 
 55 
 56 Vec2 centre_poly_axis(List *geom)
 57 {
 58     double      sum=0.0;
 59     double      weight;
 60     Vec2        shift;
 61 /*     Mat2        rotation_matrix; */
 62     List       *ptr;
 63     Line2      *lptr;
 64     double      sum_x, sum_y;
 65 /*     Transform2  poly_trans; */
 66  
 67         /* (1) Average all of the line midpoints.
 68            (2) Shift all of the lines by this average. */
 69 
 70     sum_x = sum_y = 0.0;    
 71 
 72     for(ptr=geom;ptr!=NULL;ptr=ptr->next)
 73     {
 74         lptr=ptr->to;
 75         weight = (double)lptr->length; /* Added apa 11/1/96 */
 76         sum += weight;
 77         sum_x+=vec2_x(lptr->p)*weight;
 78         sum_y+=vec2_y(lptr->p)*weight;
 79     }
 80 
 81     vec2_x(shift)=(float)-(sum_x/sum);
 82     vec2_y(shift)=(float)-(sum_y/sum);
 83 
 84 /*
 85     rotation_matrix = rot2(0.0);
 86     poly_trans.R = rotation_matrix;
 87     poly_trans.t = shift;
 88 
 89     for(ptr=geom;ptr!=NULL;ptr=ptr->next)
 90         line2_transform(ptr->to, poly_trans);
 91 */
 92     /* Added to prevent compiler warning PAB 04/12/2008 */
 93     shift.ts_id = Vec2_id;
 94 
 95     return(shift);
 96 }
 97 
 98 /* ---------- */
 99 
100 List *poly_copy(List *geom)
101 {
102     List  *copy=NULL;
103     List  *ptr;
104     Line2 *lptr;
105 
106     for(ptr=geom;ptr!=NULL;ptr=ptr->next)
107     {
108         lptr = line2_copy(ptr->to);
109         copy = ref_addtostart(copy, lptr, LINE2);
110     }
111 
112     return (copy);
113 
114 }
115 
116 /* ---------- */
117 
118 void poly_rotate(List *geom, double angle, Vec2 origin)
119 {
120     Vec2        translation; 
121     Mat2        rotation_matrix;
122     List       *ptr;
123     Transform2  model_trans;
124 
125     rotation_matrix = rot2(angle);
126 
127     translation = vec2_diff(origin,mat2_vprod(rotation_matrix, origin));
128 
129     model_trans.R = rotation_matrix;
130     model_trans.t = translation;
131 
132 /* Now transform the model data */
133 
134     for(ptr=geom;ptr!=NULL;ptr=ptr->next)
135         line2_transform(ptr->to, model_trans);      
136 
137 }
138 
139 /* ---------- */
140 
141 void poly_rotate_and_scale(List *geom, double angle, double scale_factor, Vec2 origin)
142 {
143     Vec2        translation; 
144     Mat2        rotation_matrix;
145     List       *ptr;
146     Transform2  model_trans;
147 
148     rotation_matrix = rot2_with_scale(angle, scale_factor);
149 
150     translation = vec2_diff(origin,mat2_vprod(rotation_matrix, origin));
151 
152     model_trans.R = rotation_matrix;
153     model_trans.t = translation;
154 
155 /* Now transform the model data */
156 
157     for(ptr=geom;ptr!=NULL;ptr=ptr->next)
158         line2_transform(ptr->to, model_trans);      
159 
160 }
161 
162 /* ---------- */
163 
164 void poly_translate(List *geom, Vec2 translation)
165 {
166     Mat2        rotation_matrix;
167     List       *ptr;
168     Transform2  model_trans;
169 
170     rotation_matrix = rot2(0.0);
171 
172     model_trans.R = rotation_matrix;
173     model_trans.t = translation;
174 
175     for(ptr=geom;ptr!=NULL;ptr=ptr->next)
176         line2_transform(ptr->to, model_trans);    
177 
178 }
179 
180 /* ---------- */
181 
182 void poly_scale(List *geom, double scale_factor)
183 {
184         List            *ptr;
185         Transform2      trans;
186         Line2           *lptr;
187 
188         trans.R = rot2_with_scale(0.0, scale_factor);
189         trans.t = vec2_zero();
190 
191         for(ptr=geom;ptr!=NULL;ptr=ptr->next)
192         {
193                 lptr = ptr->to;
194                 line2_transform(lptr, trans);
195         }
196 }
197 
198 /* ---------- */
199 
200 double poly_len(List *geom)
201 {
202 List   *ptr;
203 Line2  *lptr;
204 double  len=0.0;
205 
206     for(ptr=geom;ptr!=NULL;ptr=ptr->next)
207     {
208         lptr=ptr->to;
209         len+=lptr->length;
210     }
211 
212     return (len);
213    
214 }
215 
216 /* ---------- */
217 

~ [ 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.