ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/bsdftrans.cpp
Revision: 2.4
Committed: Sat Mar 5 19:21:12 2016 UTC (8 years, 1 month ago) by schorsch
Branch: MAIN
CVS Tags: rad5R4, rad5R2, rad5R1, rad5R3, HEAD
Changes since 2.3: +13 -4 lines
Log Message:
Magical allocation of dynamic length arrays works in gcc, but wasn't accepted into the standard.

File Contents

# User Rev Content
1 greg 2.1 #ifndef lint
2 schorsch 2.4 static const char RCSid[] = "$Id: bsdftrans.cpp,v 2.3 2014/03/29 21:51:59 greg Exp $";
3 greg 2.1 #endif
4     /*
5     * Compute mass transport plan for RBF lobes
6     */
7    
8     #define _USE_MATH_DEFINES
9     #include <stdio.h>
10     #include <string.h>
11     #include "transportSimplex.h"
12     #include "bsdfrep.h"
13    
14     using namespace t_simplex;
15     using namespace std;
16    
17     /* Compute mass transport plan (internal call) */
18     extern "C" void
19     plan_transport(MIGRATION *mig)
20     {
21 schorsch 2.4 double *src;
22     double *dst;
23     TsFlow *flow;
24    
25     src = new double[mtx_nrows(mig)];
26     dst = new double[mtx_ncols(mig)];
27    
28 greg 2.1 TsSignature<RBFVAL> srcSig(mtx_nrows(mig), mig->rbfv[0]->rbfa, src);
29     TsSignature<RBFVAL> dstSig(mtx_ncols(mig), mig->rbfv[1]->rbfa, dst);
30 schorsch 2.4 flow = new TsFlow[mtx_nrows(mig)+mtx_ncols(mig)-1];
31 greg 2.1 int n;
32     /* clear flow matrix */
33     memset(mig->mtx, 0, sizeof(float)*mtx_nrows(mig)*mtx_ncols(mig));
34     /* set supplies & demands */
35     for (n = mtx_nrows(mig); n--; )
36     src[n] = rbf_volume(&mig->rbfv[0]->rbfa[n]) /
37     mig->rbfv[0]->vtotal;
38     for (n = mtx_ncols(mig); n--; )
39     dst[n] = rbf_volume(&mig->rbfv[1]->rbfa[n]) /
40     mig->rbfv[1]->vtotal;
41    
42     n = 0; /* minimize EMD */
43 greg 2.2 try {
44     transportSimplex(&srcSig, &dstSig, &lobe_distance, flow, &n);
45     } catch (...) {
46     fprintf(stderr, "%s: caught exception from transportSimplex()!\n",
47     progname);
48     exit(1);
49     }
50 greg 2.3 if (n > mtx_nrows(mig)+mtx_ncols(mig)-1) {
51     fprintf(stderr, "%s: signature overflow in plan_transport()!\n",
52     progname);
53     exit(1);
54     }
55 greg 2.1 while (n-- > 0) /* assign sparse matrix */
56     mtx_coef(mig, flow[n].from, flow[n].to) = flow[n].amount;
57 schorsch 2.4
58     delete[] src;
59     delete[] dst;
60     delete[] flow;
61 greg 2.1 }