ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/applications/staticProps/RadialDistrFunc.cpp
(Generate patch)

Comparing trunk/OOPSE-4/src/applications/staticProps/RadialDistrFunc.cpp (file contents):
Revision 2035 by tim, Tue Feb 15 19:36:07 2005 UTC vs.
Revision 2037 by tim, Wed Feb 16 19:36:30 2005 UTC

# 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 62 | Line 63 | RadialDistrFunc::        RadialDistrFunc(SimInfo* info
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 <
73 <        BitSet bs = seleMan1_.getSelectionSet();
74 <        bs &= seleMan2_.getSelectionSet();
71 <        int nIntersect = bs.countBits();
72 <
73 <        nRealPairs_ = nSelected1 * nSelected2 - (nIntersect +1) * nIntersect/2;
72 >        int nIntersect = common_.getSelectionCount();
73 >        
74 >        nPairs_ = nSelected1 * nSelected2 - (nIntersect +1) * nIntersect/2;            
75      }
76      
77   }
# Line 108 | Line 109 | void RadialDistrFunc::process() {
109          
110          initalizeHistogram();
111  
111        StuntDouble* sd1;
112        int j;
113        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 <                if (sd1 != sd2) {
117 <                    collectHistogram(sd1, sd2);
118 <                }
119 <            }            
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 130 | Line 152 | int RadialDistrFunc::getNRealPairs() {
152      writeRdf();
153   }
154  
155 < int RadialDistrFunc::getNRealPairs() {
156 <    if (evaluator1_.isDynamic() || evaluator2_.isDynamic()) {
157 <        //if one of the selection is dynamic,  need to recompute it    
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 <        int nSelected1 = seleMan1_.getSelectionCount();
164 <        int nSelected2 = seleMan2_.getSelectionCount();
163 >        for (sd2 = sman2.beginSelected(j); sd2 != NULL; sd2 = sman2.nextSelected(j)) {
164 >            collectHistogram(sd1, sd2);
165 >        }            
166 >    }
167  
168 <        BitSet bs = seleMan1_.getSelectionSet();
141 <        bs &= seleMan2_.getSelectionSet();
142 <        int nIntersect = bs.countBits();
168 > }
169  
170 <        nRealPairs_ = nSelected1 * nSelected2 - (nIntersect +1) * nIntersect/2;
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  
147    return nRealPairs_;
186   }
187  
188   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines