00001
00027 #ifndef CLUSTERNODE_H_
00028 #define CLUSTERNODE_H_
00029 #include"LeafNode.h"
00030 #include"NodeWrapper.h"
00031 #include<assert.h>
00032 class ClusterNode : public AbstractNode{
00033 private :
00034 AbstractNode *leftChild;
00035 AbstractNode *rightChild;
00036 vector<LeafNode*> reps;
00037 Point3 boxRadius;
00038 Point3 coneDirection;
00039 double coneCos;
00040
00041 public:
00042 ClusterNode():boxRadius(0),coneDirection(0){
00043 }
00044 ~ClusterNode(){
00045
00046 reps.clear();
00047 }
00048 void setBox(double minX, double maxX, double minY, double maxY, double minZ, double maxZ) {
00049 myLoc.set(0.5f * (minX + maxX),0.5f * (minY + maxY),0.5f * (minZ + maxZ));
00050 boxRadius.set(0.5f * (maxX - minX),0.5f * (maxY - minY),0.5f * (maxZ - minZ));
00051 }
00052 void setBox(Point3 & min, Point3 & max) {
00053 myLoc.set(min);
00054 myLoc.add(max);
00055 myLoc.scale(0.5);
00056 boxRadius.set(max);
00057 boxRadius.sub(min);
00058 boxRadius.scale(0.5);
00059 }
00060
00061 void setChildren(AbstractNode *inLeft, AbstractNode *inRight, double repRandomNum) {
00062 leftChild = inLeft;
00063 rightChild = inRight;
00064 setSummedIntensity(*leftChild, *rightChild);
00065
00066
00067 vector<double> *ranVec = repRandomNums[(int) (repRandomNum * numRepRandomNums)];
00068 if (globalMultitime) {
00069 assert(false&&"Should not have time true!");
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 } else
00094 {
00095 if (reps.size() == 0 || reps.size()!= (unsigned int)globalNumReps) {
00096 reps.clear();
00097 reps.resize(globalNumReps);
00098 }
00099 if (leftChild->isLeaf()) {
00100 LeafNode *leftLeaf = (LeafNode*) leftChild;
00101 if (rightChild->isLeaf()) {
00102 chooseRepsNoTime(reps, *this, ranVec, *leftLeaf, (LeafNode&) *rightChild);
00103 } else {
00104 chooseRepsNoTime(reps, *this, ranVec, (ClusterNode&) *rightChild, *leftLeaf);
00105 }
00106 } else {
00107 ClusterNode *leftClus = (ClusterNode*) leftChild;
00108 if (rightChild->isLeaf()) {
00109 chooseRepsNoTime(reps, *this, ranVec, *leftClus, (LeafNode&) *rightChild);
00110 } else {
00111 chooseRepsNoTime(reps, *this, ranVec, *leftClus, (ClusterNode&) *rightChild);
00112 }
00113 }
00114 }
00115 }
00116
00117 static void chooseRepsNoTime(vector<LeafNode*> & repArr, AbstractNode & parent, vector<double> * ranVec, LeafNode &left,LeafNode & right) {
00118 double totalInten = parent.getScalarTotalIntensity();
00119 double leftInten = left.getScalarTotalIntensity();
00120 double nextTest = (*ranVec)[0] * totalInten;
00121 for (unsigned int i = 0; i < repArr.size() - 1; i++) {
00122 double test = nextTest;
00123 nextTest = (*ranVec)[i + 1] * totalInten;
00124 repArr[i] = (test < leftInten) ? &left : &right;
00125 }
00126 repArr[repArr.size() - 1] = (nextTest < leftInten) ? &left : &right;
00127 }
00128
00129
00130 static void chooseRepsNoTime(vector<LeafNode*>& repArr, AbstractNode &parent, vector<double> *ranVec, ClusterNode &left, LeafNode &right) {
00131 double totalInten = parent.getScalarTotalIntensity();
00132 double leftInten = left.getScalarTotalIntensity();
00133 double nextTest = (*ranVec)[0] * totalInten;
00134 for (unsigned int i = 0; i < repArr.size() - 1; i++) {
00135 double test = nextTest;
00136 nextTest = (*ranVec)[i + 1] * totalInten;
00137 repArr[i] = (test < leftInten) ? (left.reps[i]) : &right;
00138 }
00139 repArr[repArr.size() - 1] = (nextTest < leftInten) ? (left.reps[repArr.size() - 1]) : &right;
00140 }
00141
00142 static void chooseRepsNoTime(vector<LeafNode*> &repArr, AbstractNode &parent, vector<double> *ranVec,
00143 ClusterNode &left, ClusterNode &right) {
00144 double totalInten = parent.getScalarTotalIntensity();
00145 double leftInten = left.getScalarTotalIntensity();
00146 double nextTest = (*ranVec)[0] * totalInten;
00147 for (unsigned int i = 0; i < repArr.size() - 1; i++) {
00148 double test = nextTest;
00149 nextTest = (*ranVec)[i + 1] * totalInten;
00150 repArr[i] = (test < leftInten) ? (left.reps[i]) : (right.reps[i]);
00151 }
00152 repArr[repArr.size() - 1] = (nextTest < leftInten) ? (left.reps[repArr.size() - 1])
00153 : (right.reps[repArr.size() - 1]);
00154 }
00155
00156 void setDirectionCone(double dirX, double dirY, double dirZ, double inConeCos) {
00157 coneDirection.set(dirX,dirY,dirZ);
00158 coneCos = inConeCos;
00159 }
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173 float getConeCos() {
00174 return coneCos;
00175 }
00179 void findConeDirsRecursive(vector<double> * coordArr, vector<ClusterNode*> & tempClusterArr){
00180
00181 findConeDirsRecursive(*leftChild, coordArr, 0, tempClusterArr, 3);
00182 findConeDirsRecursive(*rightChild, coordArr, 0, tempClusterArr, 3);
00183
00184 }
00185
00186 static int findConeDirsRecursive(AbstractNode & node, vector<double> *fArr, int numDirs, vector<ClusterNode*> & cArr,int recurseDepth) {
00187 if (!node.isLeaf()) {
00188 ClusterNode & clus = (ClusterNode&) node;
00189 if (clus.coneCos == 1.0) {
00190 numDirs = addConeDir(fArr, numDirs, clus.coneDirection.getX(), clus.coneDirection.getY(), clus.coneDirection.getZ());
00191 } else if (recurseDepth <= 0) {
00192
00193 for (int i = 0; ; i++) {
00194 if (cArr[i] == NULL) {
00195 cArr[i] = &clus;
00196 if (cArr[i + 1] != NULL) {
00197 assert(false);
00198 }
00199 break;
00200 }
00201 }
00202 } else {
00203 numDirs = findConeDirsRecursive(*(clus.leftChild), fArr, numDirs, cArr, recurseDepth - 1);
00204 numDirs = findConeDirsRecursive(*(clus.rightChild), fArr, numDirs, cArr, recurseDepth - 1);
00205 }
00206 } else {
00207 LeafNode &light = (LeafNode&) node;
00208 numDirs = addConeDir(fArr, numDirs, light.getDirX(), light.getDirY(), light.getDirZ());
00209 }
00210 return numDirs;
00211 }
00212
00213 static int addConeDir(vector<double> *fArr, int numDirs, double x, double y, double z) {
00214
00215 for (int i = 0; i < 3 * numDirs; i++) {
00216 if (((*fArr)[i] == x) && ((*fArr)[i + 1] == y) && ((*fArr)[i + 2] == z)) {
00217 return numDirs;
00218 }
00219 }
00220 int index = 3 * numDirs;
00221 (*fArr)[index] = x;
00222 (*fArr)[index + 1] = y;
00223 (*fArr)[index + 2] = z;
00224 return numDirs + 1;
00225 }
00226
00227 bool isLeaf() {
00228 return false;
00229 }
00230
00231 int size() {
00232
00233 return leftChild->size() + rightChild->size();
00234 }
00235 };
00236
00237 #endif