GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/echo/objmethods.c Lines: 0 30 0.0 %
Date: 2017-05-26 Branches: 0 14 0.0 %

Line Branch Exec Source
1
/*
2
  Teem: Tools to process and visualize scientific data and images             .
3
  Copyright (C) 2013, 2012, 2011, 2010, 2009  University of Chicago
4
  Copyright (C) 2008, 2007, 2006, 2005  Gordon Kindlmann
5
  Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998  University of Utah
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
  (LGPL) as published by the Free Software Foundation; either
10
  version 2.1 of the License, or (at your option) any later version.
11
  The terms of redistributing and/or modifying this software also
12
  include exceptions to the LGPL that facilitate static linking.
13
14
  This library is distributed in the hope that it will be useful,
15
  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
  Lesser General Public License for more details.
18
19
  You should have received a copy of the GNU Lesser General Public License
20
  along with this library; if not, write to Free Software Foundation, Inc.,
21
  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22
*/
23
24
#include "echo.h"
25
#include "privateEcho.h"
26
27
#define NEW_TMPL(TYPE, BODY)                         \
28
echo##TYPE *                                         \
29
_echo##TYPE##_new(void) {                            \
30
  echo##TYPE *obj;                                   \
31
                                                     \
32
  obj = (echo##TYPE *)calloc(1, sizeof(echo##TYPE)); \
33
  obj->type = echoType##TYPE;                        \
34
  do { BODY } while (0);                             \
35
  return obj;                                        \
36
}
37
38
#define NIX_TMPL(TYPE, BODY)                         \
39
echo##TYPE *                                         \
40
_echo##TYPE##_nix(echo##TYPE *obj) {                 \
41
  int dummy=0;                                       \
42
                                                     \
43
  if (obj) {                                         \
44
    do { BODY dummy=dummy;} while (0);               \
45
    airFree(obj);                                    \
46
  }                                                  \
47
  return NULL;                                       \
48
}
49
50
void
51
_echoMatterInit(echoObject *obj) {
52
53
  obj->matter = echoMatterUnknown;
54
  ELL_4V_SET(obj->rgba, 0, 0, 0, 0);
55
  memset(obj->mat, 0,ECHO_MATTER_PARM_NUM*sizeof(echoCol_t));
56
  obj->ntext = NULL;
57
}
58
59
NEW_TMPL(Sphere,
60
         _echoMatterInit(OBJECT(obj));
61
         ELL_3V_SET(obj->pos, 0, 0, 0);
62
         obj->rad = 1.0;
63
         )
64
65
NEW_TMPL(Cylinder,
66
         _echoMatterInit(OBJECT(obj));
67
         obj->axis = 2;
68
         )
69
70
NEW_TMPL(Superquad,
71
         _echoMatterInit(OBJECT(obj));
72
         obj->axis = 2;
73
         obj->A = obj->B = 1;
74
         )
75
76
NEW_TMPL(Cube,
77
         _echoMatterInit(OBJECT(obj));
78
         )
79
80
NEW_TMPL(Triangle,
81
         _echoMatterInit(OBJECT(obj));
82
         ELL_3V_SET(obj->vert[0], 0, 0, 0);
83
         ELL_3V_SET(obj->vert[1], 0, 0, 0);
84
         ELL_3V_SET(obj->vert[2], 0, 0, 0);
85
         )
86
87
NEW_TMPL(Rectangle,
88
         _echoMatterInit(OBJECT(obj));
89
         ELL_3V_SET(obj->origin, 0, 0, 0);
90
         ELL_3V_SET(obj->edge0, 0, 0, 0);
91
         ELL_3V_SET(obj->edge1, 0, 0, 0);
92
         )
93
94
NEW_TMPL(TriMesh,
95
         _echoMatterInit(OBJECT(obj));
96
         ELL_3V_SET(obj->meanvert, 0, 0, 0);
97
         ELL_3V_SET(obj->min, ECHO_POS_MAX, ECHO_POS_MAX, ECHO_POS_MAX);
98
         ELL_3V_SET(obj->max, ECHO_POS_MIN, ECHO_POS_MIN, ECHO_POS_MIN);
99
         obj->numV = obj->numF = 0;
100
         obj->pos = NULL;
101
         obj->vert = NULL;
102
         )
103
NIX_TMPL(TriMesh,
104
         obj->pos = (echoPos_t *)airFree(obj->pos);
105
         obj->vert = (int *)airFree(obj->vert);
106
         )
107
108
NEW_TMPL(Isosurface,
109
         _echoMatterInit(OBJECT(obj));
110
         obj->volume = NULL;
111
         obj->value = 0.0;
112
         /* ??? */
113
         )
114
115
NEW_TMPL(AABBox,
116
         obj->obj = NULL;
117
         ELL_3V_SET(obj->min, ECHO_POS_MAX, ECHO_POS_MAX, ECHO_POS_MAX);
118
         ELL_3V_SET(obj->max, ECHO_POS_MIN, ECHO_POS_MIN, ECHO_POS_MIN);
119
         )
120
121
NEW_TMPL(Split,
122
         obj->axis = -1;
123
         ELL_3V_SET(obj->min0, ECHO_POS_MAX, ECHO_POS_MAX, ECHO_POS_MAX);
124
         ELL_3V_SET(obj->max0, ECHO_POS_MIN, ECHO_POS_MIN, ECHO_POS_MIN);
125
         ELL_3V_SET(obj->min1, ECHO_POS_MAX, ECHO_POS_MAX, ECHO_POS_MAX);
126
         ELL_3V_SET(obj->max1, ECHO_POS_MIN, ECHO_POS_MIN, ECHO_POS_MIN);
127
         obj->obj0 = obj->obj1 = NULL;
128
         )
129
130
NEW_TMPL(List,
131
         echoPtrPtrUnion eppu;
132
         obj->obj = NULL;
133
         obj->objArr = airArrayNew((eppu.obj = &(obj->obj),eppu.v), NULL,
134
                                   sizeof(echoObject *),
135
                                   ECHO_LIST_OBJECT_INCR);
136
         )
137
NIX_TMPL(List,
138
         airArrayNuke(obj->objArr);
139
         )
140
141
NEW_TMPL(Instance,
142
         ELL_4M_IDENTITY_SET(obj->M);
143
         ELL_4M_IDENTITY_SET(obj->Mi);
144
         obj->obj = NULL;
145
         )
146
147
echoObject *(*
148
_echoObjectNew[ECHO_TYPE_NUM])(void) = {
149
  (echoObject *(*)(void))_echoSphere_new,
150
  (echoObject *(*)(void))_echoCylinder_new,
151
  (echoObject *(*)(void))_echoSuperquad_new,
152
  (echoObject *(*)(void))_echoCube_new,
153
  (echoObject *(*)(void))_echoTriangle_new,
154
  (echoObject *(*)(void))_echoRectangle_new,
155
  (echoObject *(*)(void))_echoTriMesh_new,
156
  (echoObject *(*)(void))_echoIsosurface_new,
157
  (echoObject *(*)(void))_echoAABBox_new,
158
  (echoObject *(*)(void))_echoSplit_new,
159
  (echoObject *(*)(void))_echoList_new,
160
  (echoObject *(*)(void))_echoInstance_new
161
};
162
163
echoObject *
164
echoObjectNew(echoScene *scene, signed char type) {
165
  echoObject *ret=NULL;
166
  int idx;
167
168
  if (scene && AIR_IN_OP(echoTypeUnknown, type, echoTypeLast)) {
169
    ret = _echoObjectNew[type]();
170
    idx = airArrayLenIncr(scene->catArr, 1);
171
    scene->cat[idx] = ret;
172
  }
173
  return ret;
174
}
175
176
int
177
echoObjectAdd(echoScene *scene, echoObject *obj) {
178
  int idx;
179
180
  if (scene && obj) {
181
    idx = airArrayLenIncr(scene->rendArr, 1);
182
    scene->rend[idx] = obj;
183
  }
184
  return 0;
185
}
186
187
echoObject *(*
188
_echoObjectNix[ECHO_TYPE_NUM])(echoObject *) = {
189
  (echoObject *(*)(echoObject *))airFree,          /* echoTypeSphere */
190
  (echoObject *(*)(echoObject *))airFree,          /* echoTypeCylinder */
191
  (echoObject *(*)(echoObject *))airFree,          /* echoTypeSuperquad */
192
  (echoObject *(*)(echoObject *))airFree,          /* echoTypeCube */
193
  (echoObject *(*)(echoObject *))airFree,          /* echoTypeTriangle */
194
  (echoObject *(*)(echoObject *))airFree,          /* echoTypeRectangle */
195
  (echoObject *(*)(echoObject *))_echoTriMesh_nix, /* echoTypeTriMesh */
196
  (echoObject *(*)(echoObject *))airFree,          /* echoTypeIsosurface */
197
  (echoObject *(*)(echoObject *))airFree,          /* echoTypeAABBox */
198
  (echoObject *(*)(echoObject *))airFree,          /* echoTypeSplit */
199
  (echoObject *(*)(echoObject *))_echoList_nix,    /* echoTypeList */
200
  (echoObject *(*)(echoObject *))airFree           /* echoTypeInstance */
201
};
202
203
echoObject *
204
echoObjectNix(echoObject *obj) {
205
206
  if (obj) {
207
    _echoObjectNix[obj->type](obj);
208
  }
209
  return NULL;
210
}