BRL-CAD
nurb_reverse.c
Go to the documentation of this file.
1 /* N U R B _ R E V E R S E . C
2  * BRL-CAD
3  *
4  * Copyright (c) 1991-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @addtogroup nurb */
21 /** @{ */
22 /** @file primitives/bspline/nurb_reverse.c
23  *
24  * Reverse the direction of a nurb surface by transposing the control
25  * points
26  *
27  */
28 /** @} */
29 
30 #include "common.h"
31 
32 #include "bio.h"
33 
34 #include "vmath.h"
35 #include "nmg.h"
36 #include "raytrace.h"
37 #include "nurb.h"
38 
39 void
40 rt_nurb_reverse_srf(struct face_g_snurb *srf)
41 {
42 
43  int i, j, k;
44  int coords;
45  int row, col;
46  fastf_t * p_ptr;
47  fastf_t * tmp;
48  fastf_t * ptr2;
49 
50  p_ptr = srf->ctl_points;
51  coords = RT_NURB_EXTRACT_COORDS(srf->pt_type);
52 
53  row = srf->s_size[0];
54  col = srf->s_size[1];
55 
56  tmp = (fastf_t *) bu_malloc(sizeof(fastf_t) * coords *
57  row * col, "nurb_reverse:temp");
58 
59  ptr2 = tmp;
60 
61  for (i = 0; i < row; i++)
62  for (j = 0; j < col; j++) {
63  for (k = 0; k < coords; k++)
64  *ptr2++ = srf->ctl_points[ (j * col + i) * coords + k];
65  }
66 
67  for (i = 0; i < row * col * coords; i++)
68  p_ptr[i] = tmp[i];
69 
70  srf->s_size[0] = col;
71  srf->s_size[1] = row;
72 
73  i = srf->u.k_size;
74  srf->u.k_size = srf->v.k_size;
75  srf->v.k_size = i;
76 
77  p_ptr = srf->u.knots;
78  srf->u.knots = srf->v.knots;
79  srf->v.knots = p_ptr;
80 
81  bu_free((char *) tmp, "temporary storage for transpose");
82 }
83 
84 
85 /*
86  * Local Variables:
87  * mode: C
88  * tab-width: 8
89  * indent-tabs-mode: t
90  * c-file-style: "stroustrup"
91  * End:
92  * ex: shiftwidth=4 tabstop=8
93  */
Header file for the BRL-CAD common definitions.
void * bu_malloc(size_t siz, const char *str)
Definition: malloc.c:314
void rt_nurb_reverse_srf(struct face_g_snurb *srf)
Definition: nurb_reverse.c:40
void bu_free(void *ptr, const char *str)
Definition: malloc.c:328
double fastf_t
Definition: defines.h:300