# | Line 48 | Line 48 | RadialDistrFunc:: RadialDistrFunc(SimInfo* info | |
---|---|---|
48 | ||
49 | RadialDistrFunc:: RadialDistrFunc(SimInfo* info, const std::string& filename, const std::string& sele1, const std::string& sele2) | |
50 | : info_(info), currentSnapshot_(NULL), dumpFilename_(filename), step_(1), | |
51 | < | selectionScript1_(sele1), selectionScript2_(sele2), evaluator1_(info), evaluator2_(info), seleMan1_(info), seleMan2_(info){ |
51 | > | selectionScript1_(sele1), selectionScript2_(sele2), evaluator1_(info), evaluator2_(info), |
52 | > | seleMan1_(info), seleMan2_(info), common_(info), sele1_minus_common_(info), sele2_minus_common_(info){ |
53 | ||
54 | evaluator1_.loadScriptString(sele1); | |
55 | evaluator2_.loadScriptString(sele2); | |
# | Line 60 | Line 61 | RadialDistrFunc:: RadialDistrFunc(SimInfo* info | |
61 | seleMan2_.setSelectionSet(evaluator2_.evaluate()); | |
62 | } | |
63 | ||
64 | + | if (!evaluator1_.isDynamic() && !evaluator2_.isDynamic()) { |
65 | + | //if all selections are static, we can precompute the number of real pairs |
66 | + | common_ = seleMan1_ & seleMan2_; |
67 | + | sele1_minus_common_ = seleMan1_ - common_; |
68 | + | sele2_minus_common_ = seleMan2_ - common_; |
69 | + | |
70 | + | int nSelected1 = seleMan1_.getSelectionCount(); |
71 | + | int nSelected2 = seleMan2_.getSelectionCount(); |
72 | + | int nIntersect = common_.getSelectionCount(); |
73 | + | |
74 | + | nPairs_ = nSelected1 * nSelected2 - (nIntersect +1) * nIntersect/2; |
75 | + | } |
76 | + | |
77 | } | |
78 | ||
79 | void RadialDistrFunc::process() { | |
# | Line 72 | Line 86 | void RadialDistrFunc::process() { | |
86 | ||
87 | DumpReader reader(info_, dumpFilename_); | |
88 | int nFrames = reader.getNFrames(); | |
89 | < | nProcessed_ = nFrames / step_ + 1; |
89 | > | nProcessed_ = nFrames / step_; |
90 | > | |
91 | for (int i = 0; i < nFrames; i += step_) { | |
92 | reader.readFrame(i); | |
93 | currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot(); | |
# | Line 94 | Line 109 | void RadialDistrFunc::process() { | |
109 | ||
110 | initalizeHistogram(); | |
111 | ||
97 | – | StuntDouble* sd1; |
98 | – | int j; |
99 | – | for (sd1 = seleMan1_.beginSelected(j); sd1 != NULL; sd1 = seleMan1_.nextSelected(j)) { |
112 | ||
113 | < | StuntDouble* sd2; |
114 | < | int k; |
115 | < | for (sd2 = seleMan2_.beginSelected(k); sd2 != NULL; sd2 = seleMan2_.nextSelected(k)) { |
116 | < | collectHistogram(sd1, sd2); |
117 | < | } |
113 | > | |
114 | > | //selections may overlap. |
115 | > | // |
116 | > | // |s1 -c | c | |
117 | > | // | c |s2 - c| |
118 | > | // |
119 | > | // s1 : number of selected stuntdoubles in selection1 |
120 | > | // s2 : number of selected stuntdoubles in selection2 |
121 | > | // c : number of intersect stuntdouble between selection1 and selection2 |
122 | > | //when loop over the pairs, we can divide the looping into 3 stages |
123 | > | //stage 1 : [s1-c] [s2] |
124 | > | //stage 2 : [c] [s2 - c] |
125 | > | //stage 3 : [c] [c] |
126 | > | //stage 1 and stage 2 are completly non-overlapping |
127 | > | //stage 3 are completely overlapping |
128 | > | |
129 | > | if (evaluator1_.isDynamic() || evaluator2_.isDynamic()) { |
130 | > | |
131 | > | common_ = seleMan1_ & seleMan2_; |
132 | > | sele1_minus_common_ = seleMan1_ - common_; |
133 | > | sele2_minus_common_ = seleMan2_ - common_; |
134 | > | int nSelected1 = seleMan1_.getSelectionCount(); |
135 | > | int nSelected2 = seleMan2_.getSelectionCount(); |
136 | > | int nIntersect = common_.getSelectionCount(); |
137 | > | |
138 | > | nPairs_ = nSelected1 * nSelected2 - (nIntersect +1) * nIntersect/2; |
139 | } | |
140 | ||
141 | + | processNonOverlapping(sele1_minus_common_, seleMan2_); |
142 | + | processNonOverlapping(common_, sele2_minus_common_); |
143 | + | processOverlapping(common_); |
144 | + | |
145 | + | |
146 | processHistogram(); | |
147 | ||
148 | } | |
# | Line 114 | Line 152 | void RadialDistrFunc::process() { | |
152 | writeRdf(); | |
153 | } | |
154 | ||
155 | + | void RadialDistrFunc::processNonOverlapping( SelectionManager& sman1, SelectionManager& sman2) { |
156 | + | StuntDouble* sd1; |
157 | + | StuntDouble* sd2; |
158 | + | int i; |
159 | + | int j; |
160 | + | |
161 | + | for (sd1 = sman1.beginSelected(i); sd1 != NULL; sd1 = sman1.nextSelected(i)) { |
162 | + | |
163 | + | for (sd2 = sman2.beginSelected(j); sd2 != NULL; sd2 = sman2.nextSelected(j)) { |
164 | + | collectHistogram(sd1, sd2); |
165 | + | } |
166 | + | } |
167 | + | |
168 | } | |
169 | + | |
170 | + | void RadialDistrFunc::processOverlapping( SelectionManager& sman) { |
171 | + | StuntDouble* sd1; |
172 | + | StuntDouble* sd2; |
173 | + | int i; |
174 | + | int j; |
175 | + | |
176 | + | //basically, it is the same as below loop |
177 | + | //for (int i = 0; i < n; ++i ) |
178 | + | // for (int j = i + 1; j < n; ++j) {} |
179 | + | |
180 | + | for (sd1 = sman.beginSelected(i); sd1 != NULL; sd1 = sman.nextSelected(i)) { |
181 | + | for (j = i, sd2 = sman.nextSelected(j); sd2 != NULL; sd2 = sman.nextSelected(j)) { |
182 | + | collectHistogram(sd1, sd2); |
183 | + | } |
184 | + | } |
185 | + | |
186 | + | } |
187 | + | |
188 | + | } |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |