1 /*
2 Teem: Tools to process and visualize scientific data and images .
3 Copyright (C) 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
25 #include "push.h"
26 #include "privatePush.h"
27
28 /*
29 ** the reason to take the pushContext *pctx argument is to allow
30 ** doling out the ttaagg ID
31 */
32 pushPoint *
pushPointNew(pushContext * pctx)33 pushPointNew(pushContext *pctx) {
34 pushPoint *pnt;
35 pushPtrPtrUnion pppu;
36
37 if (pctx) {
38 pnt = AIR_CAST(pushPoint *, calloc(1, sizeof(pushPoint)));
39 if (pnt) {
40 pnt->ttaagg = pctx->ttaagg++;
41 ELL_3V_SET(pnt->pos, AIR_NAN, AIR_NAN, AIR_NAN);
42 ELL_3V_SET(pnt->frc, AIR_NAN, AIR_NAN, AIR_NAN);
43 TEN_T_SET(pnt->ten, AIR_NAN, AIR_NAN, AIR_NAN,
44 AIR_NAN, AIR_NAN, AIR_NAN, AIR_NAN);
45 TEN_T_SET(pnt->inv, AIR_NAN, AIR_NAN, AIR_NAN,
46 AIR_NAN, AIR_NAN, AIR_NAN, AIR_NAN);
47 ELL_3V_SET(pnt->cnt, AIR_NAN, AIR_NAN, AIR_NAN);
48 pnt->grav = AIR_NAN;
49 ELL_3V_SET(pnt->gravGrad, AIR_NAN, AIR_NAN, AIR_NAN);
50 pnt->seedThresh = AIR_NAN;
51 pnt->enr = DBL_MAX; /* any finite quantity will be less than this */
52
53 pnt->neighArr = airArrayNew((pppu.point = &(pnt->neigh), pppu.v),
54 &(pnt->neighNum),
55 sizeof(pushPoint *), 10);
56 }
57 } else {
58 pnt = NULL;
59 }
60 return pnt;
61 }
62
63 pushPoint *
pushPointNix(pushPoint * pnt)64 pushPointNix(pushPoint *pnt) {
65
66 airFree(pnt);
67 return NULL;
68 }
69
70
71 pushContext *
pushContextNew(void)72 pushContextNew(void) {
73 pushContext *pctx;
74
75 pctx = (pushContext *)calloc(1, sizeof(pushContext));
76 if (pctx) {
77 pctx->pointNum = 0;
78
79 pctx->nin = NULL;
80 pctx->npos = NULL;
81
82 pctx->stepInitial = 1;
83 pctx->scale = 0.2;
84 pctx->wall = 0.1;
85 pctx->cntScl = 0.0;
86 pctx->deltaLimit = 0.3;
87 pctx->deltaFracMin = 0.2;
88 pctx->energyStepFrac = 0.9;
89 pctx->deltaFracStepFrac = 0.5;
90 pctx->neighborTrueProb = 0.3;
91 pctx->probeProb = 0.5;
92 pctx->energyImprovMin = 0.01;
93
94 pctx->detReject = AIR_FALSE;
95 pctx->midPntSmp = AIR_FALSE;
96 pctx->verbose = 0;
97
98 pctx->seedRNG = 42;
99 pctx->threadNum = 1;
100 pctx->maxIter = 0;
101 pctx->snap = 0;
102
103 pctx->gravItem = tenGageUnknown;
104 pctx->gravGradItem = tenGageUnknown;
105 pctx->gravScl = AIR_NAN;
106 pctx->gravZero = AIR_NAN;
107
108 pctx->seedThreshItem = tenGageUnknown;
109 pctx->seedThreshSign = +1;
110 pctx->seedThresh = 0.0;
111
112 pctx->ensp = pushEnergySpecNew();
113
114 pctx->binSingle = AIR_FALSE;
115 pctx->binIncr = 512;
116
117 pctx->ksp00 = nrrdKernelSpecNew();
118 pctx->ksp11 = nrrdKernelSpecNew();
119 pctx->ksp22 = nrrdKernelSpecNew();
120
121 pctx->ttaagg = 0;
122 pctx->nten = NULL;
123 pctx->ninv = NULL;
124 pctx->nmask = NULL;
125 pctx->gctx = NULL;
126 pctx->tpvl = NULL;
127 pctx->ipvl = NULL;
128 pctx->finished = AIR_FALSE;
129 pctx->dimIn = 0;
130 pctx->sliceAxis = 42; /* an invalid value */
131
132 pctx->bin = NULL;
133 ELL_3V_SET(pctx->binsEdge, 0, 0, 0);
134 pctx->binNum = 0;
135 pctx->binIdx = 0;
136 pctx->binMutex = NULL;
137
138 pctx->step = AIR_NAN;
139 pctx->maxDist = AIR_NAN;
140 pctx->maxEval = AIR_NAN;
141 pctx->meanEval = AIR_NAN;
142 pctx->maxDet = AIR_NAN;
143 pctx->energySum = 0;
144
145 pctx->task = NULL;
146
147 pctx->iterBarrierA = NULL;
148 pctx->iterBarrierB = NULL;
149
150 pctx->deltaFrac = AIR_NAN;
151
152 pctx->timeIteration = 0;
153 pctx->timeRun = 0;
154 pctx->iter = 0;
155 pctx->noutPos = nrrdNew();
156 pctx->noutTen = nrrdNew();
157 }
158 return pctx;
159 }
160
161 /*
162 ** this should only nix things created by pushContextNew
163 */
164 pushContext *
pushContextNix(pushContext * pctx)165 pushContextNix(pushContext *pctx) {
166
167 if (pctx) {
168 pctx->ensp = pushEnergySpecNix(pctx->ensp);
169 pctx->ksp00 = nrrdKernelSpecNix(pctx->ksp00);
170 pctx->ksp11 = nrrdKernelSpecNix(pctx->ksp11);
171 pctx->ksp22 = nrrdKernelSpecNix(pctx->ksp22);
172 pctx->noutPos = nrrdNuke(pctx->noutPos);
173 pctx->noutTen = nrrdNuke(pctx->noutTen);
174 airFree(pctx);
175 }
176 return NULL;
177 }
178