#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "IDelaunay2D.hxx" #include "IMeshPoint.hxx" class IQuitPanel : public TGMainFrame { private: TGTextButton *fButton1; TGLayoutHints *fLayout1; void QuitProgram(void); enum {QuitButton}; public: IQuitPanel(const TGWindow *p, UInt_t w, UInt_t h); ~IQuitPanel(); Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2); }; IQuitPanel::IQuitPanel(const TGWindow *p, UInt_t w, UInt_t h) : TGMainFrame(p,w,h) { // Create a main frame with a number of different buttons. fButton1 = new TGTextButton(this, "&Quit", QuitButton); fLayout1 = new TGLayoutHints(kLHintsCenterX | kLHintsCenterY | kLHintsExpandX | kLHintsExpandY); AddFrame(fButton1, fLayout1); MapSubwindows(); Layout(); SetWindowName("Button Control"); SetIconName("Button Control "); MapWindow(); } IQuitPanel::~IQuitPanel(void) { delete fButton1; delete fLayout1; } Bool_t IQuitPanel::ProcessMessage(Long_t msg, Long_t parm1, Long_t) { // Process events generated by the buttons in the frame. switch (GET_MSG(msg)) { case kC_COMMAND: switch (GET_SUBMSG(msg)) { case kCM_BUTTON: printf("text button id %ld pressed\n", parm1); if( parm1 == QuitButton ) QuitProgram(); default: break; } } gROOT->Reset(); return kTRUE; } COMET::IDelaunay2D* gDelaunay = NULL; void IQuitPanel::QuitProgram(void) { delete gDelaunay; exit(0); } int main(int argc, char **argv) { int points = 2; double cut = 100; if (argc>1) { std::istringstream arg(argv[1]); arg >> points; } if (argc>2) { std::istringstream arg(argv[2]); arg >> cut; } //Initialize GUI TApplication theApp("App",&argc,argv); TCanvas* mainCanvas = new TCanvas ("gMainCanvas","Tracks",200,10,1000,1200); new IQuitPanel(gClient->GetRoot(), 100, 150); mainCanvas = new TCanvas ("gMainCanvas","Tracks",200,10,1000,1200); TH2F *drawRegion = new TH2F("drawRegion","Triangulation", 800,-10,+10, 800,-10,+10); drawRegion->SetStats(false); gDelaunay = new COMET::IDelaunay2D; TRandom ran; std::cout << "Triangulation started " << std::endl; for (int i=0; iAddPoint(new COMET::IMeshXYPoint(x,y)); } gDelaunay->Close(); std::cout << "Triangulation finished " << std::endl; for (COMET::TMeshEdgeSet::iterator e = gDelaunay->BeginEdges(); e != gDelaunay->EndEdges();) { if (cut < (*e)->GetLength()) gDelaunay->RemoveEdge(*(e++)); else ++e; } std::cout << "All long edges removed" << std::endl; gDelaunay->SetMarkerStyle(8); gDelaunay->SetMarkerColor(2); gDelaunay->SetLineColor(4); drawRegion->Draw(); gDelaunay->Draw(); COMET::TMeshPointSet allPoints; std::copy(gDelaunay->BeginPoints(), gDelaunay->EndPoints(), std::inserter(allPoints,allPoints.begin())); while (!allPoints.empty()) { std::cout << "There are " << allPoints.size() << " points in the mesh." << std::endl; COMET::IMeshPoint* seed = *allPoints.begin(); COMET::TMeshPointSet somePoints; // Copy all points that are connected to seed into somePoints. std::copy(seed->BeginPoints(),seed->EndPoints(), std::inserter(somePoints,somePoints.begin())); std::cout << "Point " << seed << " connected to " << somePoints.size() << std::endl; // Remove points copied to somePoints from allPoints. for (COMET::TMeshPointSet::iterator t = somePoints.begin(); t!=somePoints.end(); ++t) allPoints.erase(*t); } // Mark a point. COMET::TMeshEdgeSet::iterator edge = gDelaunay->BeginEdges(); COMET::IMeshPoint* startPoint = (*edge)->GetHead(); TMarker startMarker(startPoint->X(), startPoint->Y(),8); startMarker.SetMarkerColor(3); startMarker.SetMarkerSize(1.5); startMarker.Draw(); COMET::IMeshPoint* endPoint = (*edge)->GetTail(); TMarker endMarker(endPoint->X(), endPoint->Y(),8); endMarker.SetMarkerColor(5); endMarker.SetMarkerSize(1.5); endMarker.Draw(); COMET::IMeshPoint::PathVector pointPaths = startPoint->GetPaths(endPoint, 10, 10); std::cout << "Paths found: " << pointPaths.size() << std::endl; for (COMET::IMeshPoint::PathVector::iterator path = pointPaths.begin(); path != pointPaths.end(); ++path) { std::cout << " Path " << std::endl; TPolyLine *thePath = new TPolyLine; for (COMET::IMeshPoint::PointVector::iterator p = path->begin(); p != path->end(); ++p) { std::cout << " " << *p << " " << (*p)->X() << " " << (*p)->Y() << std::endl; thePath->SetNextPoint((*p)->X(),(*p)->Y()); } thePath->SetLineColor(1); thePath->SetLineWidth(2); thePath->Draw(); } theApp.Run(); }