#include #include #include #include #include #include #include #include #include #include #include #include #include #include "TCabsHough.h" #include "TCfast2Dhough.h" #include "Hyperplane2D.h" #include "Hough2DNode.h" bool compareNodes (Hough2DNode* n1, Hough2DNode* n2) { return (n1->getVote() > n2->getVote()); } using std::cout; using std::endl; TCfast2DHough::TCfast2DHough(const TVector3 firstAxis, const TVector3 secondAxis) :TCabsHough(firstAxis,secondAxis){ dynamicParSpace=false; canv=NULL; houghSpace=NULL; clear(); m_Max =0.2f; m_Min =-0.2f; t_Max = 1.5f; t_Min =-1.5f; TREE_DEPTH = 5; //number of space divisions THRESHOLD = 4; } TCfast2DHough::TCfast2DHough(const TVector3 firstAxis, const TVector3 secondAxis,bool dynamicParSpace_) :TCabsHough(firstAxis,secondAxis){ debug=false; canv=NULL; houghSpace=NULL; clear(); m_Max =0.2; m_Min =-0.2f; t_Max = 1.5f; t_Min =-1.5f; dynamicParSpace=dynamicParSpace_; TREE_DEPTH = 5; //number of space divisions THRESHOLD = 4; } void TCfast2DHough::make(std::vector& _c){ nClusters=0; convert(_c); float mins[2] = {m_Min, t_Min}; float maxs[2] = {m_Max, t_Max}; for(unsigned int i=0;isetParamSpace(mins, maxs); nClusters++; } int BIN_m=500; int BIN_t=500; char buf[50]; char bufName[50]; if(yp.x()==-1&&zp.z()==1){ sprintf(buf,"houghspaceXZ"); sprintf(bufName,"Hough Space XZ"); }else if(yp.y()==1&&zp.z()==1){ sprintf(buf,"houghspaceYZ"); sprintf(bufName,"Hough Space YZ"); }else{ static TRandom r(0); sprintf(buf,"houghspace%f",r.Uniform()); sprintf(bufName,"Hough Space%f",r.Uniform()); } if(houghSpace==NULL){ if(debug){ cout<<"houghSpace created"<SetLineColor(kBlue); houghLines.back()->SetLineStyle(1); houghLines.back()->SetLineWidth(1); /* for(int t=0; tFill(M,T); if(t%250==0&&debug){ cout<<"t "< parent_list; float* corners = root->getCorners(); if(debug){ for(int i=0; i<8; i++) { if(i%2==0) std::cout<testIntersect(*root); } if(debug){ std::cout << "\nThere have been "<getVote() <<" of "<getVote() < THRESHOLD){ cout<<"top node not enough votes"<0) { Hough2DNode* the_node = (*parent_list.begin()); if(the_node->getLevel() >= TREE_DEPTH) { node_list.push_back(the_node); parent_list.pop_front(); continue; } float* sons = the_node->getSonArray(); bool* hitList = the_node->getHitList(); for(int s=0; s<4; s++) { parent_list.push_back(new Hough2DNode(sons+2*s, the_node->getLevel()+1, nClusters)); Hough2DNode* the_son = parent_list.back(); //now loop over points for this son and do hit check for(int i=0; itestIntersect(*the_son); } if(the_son->getLevel() < 6) { if(the_son->getVote() < THRESHOLD) { delete parent_list.back(); parent_list.pop_back(); } } else{ if(the_son->getVote() < the_node->getVote()*0.92) { delete parent_list.back(); parent_list.pop_back(); } } } //end loop over sons delete parent_list.front(); parent_list.pop_front(); } if(debug){ std::cout<<"There have been "< temp_sons; for(int l=0; l new_nodes; if(debug){ std::cout<<"level: "<getSonArray(); //hitlist of the mother bool* hitList = the_node->getHitList(); //create sons for(int s=0; s<4; ++s) { temp_sons.push_back(new Hough2DNode(sons+2*s, the_node->getLevel()+1, nClusters)); Hough2DNode* the_son = temp_sons.at(temp_sons.size()-1); //now loop over points for this son and do hit check for(int i=0; itestIntersect(the_son); } if(the_son->getLevel() < 6) { if(the_son->getVote() < THRESHOLD) { //TODO: optimize delete temp_sons.at(temp_sons.size()-1); temp_sons.at(temp_sons.size()-1) = NULL; } } //dynamic thresholding else{ if(the_son->getVote() < the_node->getVote()*0.95) { delete temp_sons.at(temp_sons.size()-1); temp_sons.at(temp_sons.size()-1) = NULL; } } } //end loop over sons free(sons);//should find alternative measure //keep sons that passed the test for(int s=0; s<4; s++) { if(temp_sons.at(s)!=NULL) new_nodes.push_back(temp_sons.at(s)); } temp_sons.clear(); //erase parent (no longer needed) if(l!=TREE_DEPTH-1) delete parent_list.at(n); } //end loop over parent_list if(l!=TREE_DEPTH-1) parent_list = new_nodes; } maxVote=-1; Hough2DNode* maxNode=NULL; for(std::vector::iterator it=parent_list.begin();it!=parent_list.end();++it){ if((*it)->getVote()>maxVote){ maxVote=(*it)->getVote(); maxNode=(*it); } } if(debug){ cout<<"maxVote "<0){ bool cont=true; int counter =0; // debug=true; while(cont) { counter++; //sort nodes by final votes bool* bestHitList = parent_list.front()->getHitList(); if(debug){ std::cout<getVote()<getHitList(); if(debug){ std::cout<getVote()<getNplanes()<<" n clusters "<checkHit(p)){ if(debug){ cout<<"hit "<removeHit(p); } } } solution_node_list.push_back(parent_list.front()); } if(debug){ std::cout<<"amount of maxima: "<getCorners(); if(debug){ cout<<"solution "<SetSelectedPad(canv->cd(1)); for(unsigned int s=0; sgetCenter(); std::cout<<"maxima "<<(center[0]+0.5)*(m_Max-m_Min) <<" "<<(center[1]+0.5)*(t_Max-t_Min)<getSideLength(); float x1 = (center[0] - 0.5*length+0.5)*(m_Max-m_Min)+m_Min; float x2 = (center[0] + 0.5*length+0.5)*(m_Max-m_Min)+m_Min; float y1 = (center[1] - 0.5*length+0.5)*(t_Max-t_Min)+t_Min; float y2 = (center[1] + 0.5*length+0.5)*(t_Max-t_Min)+t_Min; boxlist.push_back(new TBox(x1,y1,x2,y2)); } gStyle->SetPalette(1); houghSpace->SetStats(kFALSE); houghSpace->Draw(); for(unsigned int h=0;hDraw("same"); } for(unsigned int b=0; bSetLineColor(kPink+10); (boxlist[b])->SetFillStyle(0); (boxlist[b])->SetLineWidth(2); (boxlist[b])->Draw("l"); } houghSpace->GetXaxis()->SetTitle("m"); houghSpace->GetYaxis()->SetTitle("t (cm)"); canv->Modified(); canv->Update(); if(stop){ gApplication->SetReturnFromRun(true); gSystem->Run(); } } TCfast2DHough::~TCfast2DHough(){ delete houghSpace; for(unsigned int i =0; i& _c){ TVector3 xp=yp.Cross(zp); TMatrixT S(3,3); S[0][0]=xp.X(); S[1][0]=xp.Y(); S[2][0]=xp.Z(); S[0][1]=yp.X(); S[1][1]=yp.Y(); S[2][1]=yp.Z(); S[0][2]=zp.X(); S[1][2]=zp.Y(); S[2][2]=zp.Z(); //TMatrixT Stransp = S; //Stransp.T(); clear(); float yMax=-999999; float yMin=999999; float zMax=-999999; float zMin=999999; for(unsigned int i=0;i<_c.size();++i){ TVector3 hitPrime = S * _c.at(i).posXYZ(); //xprime isnt needed float y=hitPrime.Y(); float z=hitPrime.Z(); if(debug){ std::cout<<"hough y "<yMax){ yMax=y; } if(z>zMax){ zMax=z; } if(yClear(); } if(houghSpace!=NULL){ delete houghSpace; houghSpace=NULL; } ypHit.clear(); zpHit.clear(); for(unsigned int i=0;i