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

Linux Cross Reference
Tina5/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 Lesser 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 Lesser General Public License for more details.
 14  *
 15  * You should have received a copy of the GNU Lesser 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  **********
 20  * 
 21  * Program :    TINA
 22  * File    :  $Source: /home/tina/cvs/tina-libs/tina/geometry/geomLine_poly_trans.c,v $
 23  * Date    :  $Date: 2008/12/04 15:28:02 $
 24  * Version :  $Revision: 1.5 $
 25  * CVS Id  :  $Id: geomLine_poly_trans.c,v 1.5 2008/12/04 15:28:02 paul Exp $
 26  *
 27  * Notes : Anthony Ashbrook. 30th June 1993.
 28  *
 29  *********
 30 */
 31 
 32 
 33 #include "geomLine_poly_trans.h"
 34 
 35 #if HAVE_CONFIG_H
 36   #include <config.h>
 37 #endif
 38 
 39 #include <tina/sys/sysDef.h>
 40 #include <tina/sys/sysPro.h>
 41 #include <tina/math/mathDef.h>
 42 #include <tina/math/mathPro.h>
 43 #include <tina/geometry/geom_GenPro.h>
 44 #include <tina/geometry/geomDef.h>
 45 #include <tina/geometry/geomLine_2line.h>
 46 #include <tina/geometry/geomLine_2trans.h>
 47 
 48 /*--------------------------------------------*/
 49 
 50 
 51 
 52 Vec2 centre_poly_axis(List *geom)
 53 {
 54     double      sum=0.0;
 55     double      weight;
 56     Vec2        shift;
 57 /*     Mat2        rotation_matrix; */
 58     List       *ptr;
 59     Line2      *lptr;
 60     double      sum_x, sum_y;
 61 /*     Transform2  poly_trans; */
 62  
 63         /* (1) Average all of the line midpoints.
 64            (2) Shift all of the lines by this average. */
 65 
 66     sum_x = sum_y = 0.0;    
 67 
 68     for(ptr=geom;ptr!=NULL;ptr=ptr->next)
 69     {
 70         lptr=ptr->to;
 71         weight = (double)lptr->length; /* Added apa 11/1/96 */
 72         sum += weight;
 73         sum_x+=vec2_x(lptr->p)*weight;
 74         sum_y+=vec2_y(lptr->p)*weight;
 75     }
 76 
 77     vec2_x(shift)=(float)-(sum_x/sum);
 78     vec2_y(shift)=(float)-(sum_y/sum);
 79 
 80 /*
 81     rotation_matrix = rot2(0.0);
 82     poly_trans.R = rotation_matrix;
 83     poly_trans.t = shift;
 84 
 85     for(ptr=geom;ptr!=NULL;ptr=ptr->next)
 86         line2_transform(ptr->to, poly_trans);
 87 */
 88     /* Added to prevent compiler warning PAB 04/12/2008 */
 89     shift.ts_id = Vec2_id;
 90 
 91     return(shift);
 92 }
 93 
 94 /* ---------- */
 95 
 96 List *poly_copy(List *geom)
 97 {
 98     List  *copy=NULL;
 99     List  *ptr;
100     Line2 *lptr;
101 
102     for(ptr=geom;ptr!=NULL;ptr=ptr->next)
103     {
104         lptr = line2_copy(ptr->to);
105         copy = ref_addtostart(copy, lptr, LINE2);
106     }
107 
108     return (copy);
109 
110 }
111 
112 /* ---------- */
113 
114 void poly_rotate(List *geom, double angle, Vec2 origin)
115 {
116     Vec2        translation; 
117     Mat2        rotation_matrix;
118     List       *ptr;
119     Transform2  model_trans;
120 
121     rotation_matrix = rot2(angle);
122 
123     translation = vec2_diff(origin,mat2_vprod(rotation_matrix, origin));
124 
125     model_trans.R = rotation_matrix;
126     model_trans.t = translation;
127 
128 /* Now transform the model data */
129 
130     for(ptr=geom;ptr!=NULL;ptr=ptr->next)
131         line2_transform(ptr->to, model_trans);      
132 
133 }
134 
135 /* ---------- */
136 
137 void poly_rotate_and_scale(List *geom, double angle, double scale_factor, Vec2 origin)
138 {
139     Vec2        translation; 
140     Mat2        rotation_matrix;
141     List       *ptr;
142     Transform2  model_trans;
143 
144     rotation_matrix = rot2_with_scale(angle, scale_factor);
145 
146     translation = vec2_diff(origin,mat2_vprod(rotation_matrix, origin));
147 
148     model_trans.R = rotation_matrix;
149     model_trans.t = translation;
150 
151 /* Now transform the model data */
152 
153     for(ptr=geom;ptr!=NULL;ptr=ptr->next)
154         line2_transform(ptr->to, model_trans);      
155 
156 }
157 
158 /* ---------- */
159 
160 void poly_translate(List *geom, Vec2 translation)
161 {
162     Mat2        rotation_matrix;
163     List       *ptr;
164     Transform2  model_trans;
165 
166     rotation_matrix = rot2(0.0);
167 
168     model_trans.R = rotation_matrix;
169     model_trans.t = translation;
170 
171     for(ptr=geom;ptr!=NULL;ptr=ptr->next)
172         line2_transform(ptr->to, model_trans);    
173 
174 }
175 
176 /* ---------- */
177 
178 void poly_scale(List *geom, double scale_factor)
179 {
180         List            *ptr;
181         Transform2      trans;
182         Line2           *lptr;
183 
184         trans.R = rot2_with_scale(0.0, scale_factor);
185         trans.t = vec2_zero();
186 
187         for(ptr=geom;ptr!=NULL;ptr=ptr->next)
188         {
189                 lptr = ptr->to;
190                 line2_transform(lptr, trans);
191         }
192 }
193 
194 /* ---------- */
195 
196 double poly_len(List *geom)
197 {
198 List   *ptr;
199 Line2  *lptr;
200 double  len=0.0;
201 
202     for(ptr=geom;ptr!=NULL;ptr=ptr->next)
203     {
204         lptr=ptr->to;
205         len+=lptr->length;
206     }
207 
208     return (len);
209    
210 }
211 
212 /* ---------- */
213 

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