00001
00002
00003
00004
00005
00007
00008
00009 #include <fstream>
00010 #include "TObjArray.h"
00011
00012 #include "BField/TIntList.h"
00013 #include "BField/BFLNode.h"
00014 #include "BField/BFLVtx.h"
00015 #include "BField/BFLEdge.h"
00016 #include "BField/BFLPolyg.h"
00017 #include "BField/BFLWingedEdge.h"
00018
00019 ClassImp(BFLWingedEdge)
00020
00021 BFLWingedEdge::BFLWingedEdge(Long_t ngens):
00022 fNPolygons(0)
00023 {
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 fEdges = new TObjArray(3*ngens + 100);
00037 fVertices = new TObjArray(2*ngens + 100);
00038 fPolygons = new TObjArray(ngens + 100);
00039
00040
00041 fAvailableVtxIDs = new TIntList();
00042 fAvailableEdgeIDs = new TIntList();
00043
00044 fGenerators = 0;
00045
00046 fANSYSTable = 0;
00047 }
00049
00050 BFLWingedEdge::~BFLWingedEdge()
00051 {
00052 fEdges->Delete();
00053 delete fEdges;
00054
00055 fVertices->Delete();
00056 delete fVertices;
00057
00058 fPolygons->Delete();
00059 delete fPolygons;
00060
00061 if(fGenerators) {
00062 fGenerators->Delete();
00063 delete fGenerators;
00064 }
00065
00066 delete fAvailableVtxIDs;
00067 delete fAvailableEdgeIDs;
00068 }
00070
00071 void BFLWingedEdge::AddEdge(Int_t EdgeSlot) {
00072
00073 fEdges->AddAtAndExpand(new BFLEdge(EdgeSlot), EdgeSlot);
00074
00075
00076 Int_t EdgeID = EdgeSlot;
00077 SetEdgeID(EdgeSlot,EdgeID);
00078 }
00080
00081 void BFLWingedEdge::AddPolyg(Int_t PolySlot) {
00082
00083 fPolygons->AddAtAndExpand(new BFLPolyg(PolySlot), PolySlot);
00084
00085
00086 Int_t PolyID = PolySlot;
00087 SetPolygID(PolySlot,PolyID);
00088 }
00090
00091 void BFLWingedEdge::AddVtx(Int_t VtxSlot) {
00092
00093 fVertices->AddAtAndExpand(new BFLVtx(VtxSlot), VtxSlot);
00094
00095
00096 Int_t VtxID = VtxSlot;
00097 SetVtxID(VtxSlot,VtxID);
00098 }
00100
00101 void BFLWingedEdge::AddAvailableVtxID(Int_t id)
00102 {
00103 fAvailableVtxIDs -> Add(id);
00104 fAvailableVtxIDs -> Sort();
00105 }
00107
00108 Int_t BFLWingedEdge::FirstAvailableVtxID(void) const
00109 {
00110
00111
00112
00113
00114
00115
00116 Int_t vtx;
00117
00118 fAvailableVtxIDs->Sort();
00119 vtx = fAvailableVtxIDs->First();
00120
00121 return vtx;
00122 }
00124
00125 Int_t BFLWingedEdge::MaxAvailableVtxID(void) const
00126 {
00127 fAvailableVtxIDs->Sort();
00128 return fAvailableVtxIDs->Last();
00129 }
00131
00132 void BFLWingedEdge::DeleteFirstAvailableVtxID(void)
00133 {
00134
00135
00136 Int_t NextID;
00137
00138 fAvailableVtxIDs->Sort();
00139 if(fAvailableVtxIDs->NumberOfElements() == 1) {
00140 NextID = fAvailableVtxIDs->First() + 1;
00141 fAvailableVtxIDs->AddAt(NextID,1);
00142 }
00143 fAvailableVtxIDs->Remove( fAvailableVtxIDs->First() );
00144 }
00145
00147
00148 void BFLWingedEdge::AddAvailableEdgeID(Int_t id)
00149 {
00150 fAvailableEdgeIDs -> Add(id);
00151 fAvailableEdgeIDs -> Sort();
00152 }
00154
00155 Int_t BFLWingedEdge::FirstAvailableEdgeID(void) const
00156 {
00157
00158
00159
00160
00161 Int_t edge;
00162
00163 fAvailableEdgeIDs->Sort();
00164 edge = fAvailableEdgeIDs->First();
00165
00166
00167 return edge;
00168 }
00170
00171 Int_t BFLWingedEdge::MaxAvailableEdgeID(void) const
00172 {
00173 fAvailableEdgeIDs->Sort();
00174 return fAvailableEdgeIDs->Last();
00175 }
00177
00178 void BFLWingedEdge::DeleteFirstAvailableEdgeID(void)
00179 {
00180
00181
00182 Int_t NextID;
00183
00184 fAvailableEdgeIDs->Sort();
00185 if(fAvailableEdgeIDs->NumberOfElements() == 1) {
00186 NextID = fAvailableEdgeIDs->First() + 1;
00187 fAvailableEdgeIDs->AddAt(NextID,1);
00188 }
00189 fAvailableEdgeIDs->Remove( fAvailableEdgeIDs->First() );
00190 }
00192
00193 void BFLWingedEdge::PrintEdges(void)
00194 {
00195 TIter next(fEdges);
00196 BFLEdge * edge;
00197
00198 cout << "\n************ PRINTING VORONOI EDGES *************" << endl;
00199
00200 while( (edge = (BFLEdge *)next()) ) {
00201
00202 cout << "* -------------- Edge id : "<< edge->GetEdgeID() << endl;
00203 cout << "*Left Polygon......" << edge->GetLeftPolyg() << endl;
00204 cout << "*Right Polygon....." << edge->GetRightPolyg() << endl;
00205 cout << "*Start Vtx........." << edge->GetStartVtx() << endl;
00206 cout << "*End Vtx..........." << edge->GetEndVtx() << endl;
00207 cout << "*CW Successor......" << edge->GetCwSuccessor() << endl;
00208 cout << "*CCW Successor....." << edge->GetCcwSuccessor() << endl;
00209 cout << "*CW Predecessor...." << edge->GetCwPredecessor() << endl;
00210 cout << "*CCW Predecessor..." << edge->GetCcwPredecessor()<< endl;
00211 }
00212 cout << endl;
00213 delete edge;
00214 }
00216
00217 void BFLWingedEdge::PrintVertices(void)
00218 {
00219 TIter next(fVertices);
00220 BFLVtx * vtx;
00221 char wght;
00222
00223 cout << "\n********** PRINTING VORONOI VERTICES ***********" << endl;
00224
00225 while( (vtx = (BFLVtx *)next()) ) {
00226
00227 if(vtx->GetWeight()) wght = 'T';
00228 else wght = 'F';
00229
00230 cout << "* -------------- Vtx id : "<< vtx->GetVtxID() << endl;
00231 cout << "*Incident Edge...." << vtx->GetEdgeAroundVtx() << endl;
00232 cout << "*Vertex Weight...." << wght << endl;
00233 cout << "*Vertex X........." << vtx->GetX() << endl;
00234 cout << "*Vertex Y........." << vtx->GetY() << endl;
00235 }
00236 cout << endl;
00237 delete vtx;
00238 }
00240
00241 void BFLWingedEdge::PrintPolygons(void)
00242 {
00243 TIter next(fPolygons);
00244 BFLPolyg * polyg;
00245
00246 cout << "\n********** PRINTING VORONOI POLYGONS ***********" << endl;
00247
00248 while( (polyg = (BFLPolyg *)next()) ) {
00249
00250 cout << "* ----------- Polyg id : "<< polyg->GetPolygID() << endl;
00251 cout << "*Edge Around...." << polyg->GetEdgeAroundPolyg() << endl;
00252 }
00253 cout << endl;
00254 delete polyg;
00255 }
00257
00258 void BFLWingedEdge::PrintVoronoi(Int_t PrintWhat)
00259 {
00260 switch(PrintWhat){
00261 case(kEDGES):
00262 PrintEdges();
00263 break;
00264 case(kVERTICES):
00265 PrintVertices();
00266 break;
00267 case(kPOLYGONS):
00268 PrintPolygons();
00269 break;
00270 case(kALL):
00271 PrintEdges();
00272 PrintVertices();
00273 PrintPolygons();
00274 break;
00275 }
00276 }
00278
00279 void BFLWingedEdge::Plot(void)
00280 {
00281
00282
00283
00284 ofstream MACRO("VoronPlot.C",std::ios::out);
00285
00286 MACRO << "{" << endl;
00287 MACRO << "gROOT->Reset();" << endl;
00288
00289 MACRO << "TCanvas * c = new TCanvas(\"c\",\"Vor\",20,20,800,600);" << endl;
00290 MACRO << "c->Range(-3000.,-3000.,3000.,3000.);" << endl;
00291
00292 MACRO << "// Plotting Voronoi diagram " << endl;
00293 MACRO << "TLine * line = new TLine();" << endl;
00294 MACRO << "line->SetLineColor(9);" << endl;
00295
00296 TIter next(fEdges);
00297 BFLEdge * edge;
00298 while( (edge = (BFLEdge *)next()) ) {
00299
00300 Int_t svtxID = edge->GetStartVtx();
00301 Int_t evtxID = edge->GetEndVtx();
00302
00303 BFLVtx * Svtx = GetVtxObj(svtxID);
00304 BFLVtx * Evtx = GetVtxObj(evtxID);
00305
00306 Float_t xs = Svtx->GetX();
00307 Float_t ys = Svtx->GetY();
00308 Float_t xe = Evtx->GetX();
00309 Float_t ye = Evtx->GetY();
00310
00311 MACRO << "line->DrawLine(" << xs << "," << ys << ","
00312 << xe << "," << ye << ");" << endl;
00313 }
00314
00315 MACRO << "}" << endl;
00316 }
00318
00319 void BFLWingedEdge::Save(const Char_t * filename)
00320 {
00321 ofstream WEFILE(filename,std::ios::out);
00322
00323
00324 TIter nexte(fEdges);
00325 BFLEdge * edge;
00326
00327 WEFILE << fEdges->GetLast() << endl;
00328 while( (edge = (BFLEdge *)nexte()) ) {
00329
00330 WEFILE << edge->GetEdgeID() << endl;
00331 WEFILE << edge->GetLeftPolyg() << "\t\t"
00332 << edge->GetRightPolyg() << endl;
00333 WEFILE << edge->GetStartVtx() << "\t\t"
00334 << edge->GetEndVtx() << endl;
00335 WEFILE << edge->GetCwSuccessor() << "\t\t"
00336 << edge->GetCcwSuccessor() << endl;
00337 WEFILE << edge->GetCwPredecessor() << "\t\t"
00338 << edge->GetCcwPredecessor() << endl;
00339 }
00340 delete edge;
00341
00342
00343 TIter nextv(fVertices);
00344 BFLVtx * vtx;
00345 Int_t wght;
00346
00347 WEFILE << fVertices->GetLast() << endl;
00348 while( (vtx = (BFLVtx *)nextv()) ) {
00349
00350 if(vtx->GetWeight()) wght = 1;
00351 else wght = 0;
00352
00353 WEFILE << vtx->GetVtxID() << endl;
00354 WEFILE << vtx->GetEdgeAroundVtx() << endl;
00355 WEFILE << wght << endl;
00356 WEFILE << vtx->GetX() << "\t\t" << vtx->GetY() << endl;
00357 }
00358 delete vtx;
00359
00360
00361 TIter nextp(fPolygons);
00362 BFLPolyg * polyg;
00363
00364 WEFILE << fPolygons->GetLast() << endl;
00365 while( (polyg = (BFLPolyg *)nextp()) ) {
00366
00367 WEFILE << polyg->GetPolygID() << endl;
00368 WEFILE << polyg->GetEdgeAroundPolyg() << endl;
00369 }
00370 delete polyg;
00371
00372 }
00374
00375 void BFLWingedEdge::Load(const Char_t * filename)
00376 {
00377 Int_t MaxEdge, MaxVertex, MaxPolygon;
00378 Int_t ID, LeftPolyg, RightPolyg, StartVtx, EndVtx;
00379 Int_t CwSuccessor, CcwSuccessor;
00380 Int_t CwPredecessor, CcwPredecessor;
00381 Int_t EdgeAroundVtx, EdgeAroundPolyg, wght;
00382 Float_t X, Y;
00383 ifstream WEFILE(filename,std::ios::in);
00384
00385
00386 if(fEdges) {
00387 fEdges->Delete();
00388 delete fEdges;
00389 }
00390 if(fVertices) {
00391 fVertices->Delete();
00392 delete fVertices;
00393 }
00394 if(fPolygons) {
00395 fPolygons->Delete();
00396 delete fPolygons;
00397 }
00398 if(fAvailableVtxIDs) delete fAvailableVtxIDs;
00399 if(fAvailableEdgeIDs) delete fAvailableEdgeIDs;
00400
00401
00402 fEdges = new TObjArray(100);
00403 fVertices = new TObjArray(100);
00404 fPolygons = new TObjArray(100);
00405 fAvailableVtxIDs = new TIntList();
00406 fAvailableEdgeIDs = new TIntList();
00407
00408
00409 WEFILE >> MaxEdge;
00410 do {
00411 WEFILE >> ID;
00412 WEFILE >> LeftPolyg >> RightPolyg;
00413 WEFILE >> StartVtx >> EndVtx;
00414 WEFILE >> CwSuccessor >> CcwSuccessor;
00415 WEFILE >> CwPredecessor >> CcwPredecessor;
00416
00417 SetEdge(ID);
00418 SetRightPolyg(ID,RightPolyg);
00419 SetLeftPolyg(ID,LeftPolyg);
00420 SetStartVtx(ID,StartVtx);
00421 SetEndVtx(ID,EndVtx);
00422 SetCwPredecessor(ID,CwPredecessor);
00423 SetCcwPredecessor(ID,CcwPredecessor);
00424 SetCwSuccessor(ID,CwSuccessor);
00425 SetCcwSuccessor(ID,CcwSuccessor);
00426
00427 } while(ID != MaxEdge);
00428
00429
00430 WEFILE >> MaxVertex;
00431 do {
00432 WEFILE >> ID;
00433 WEFILE >> EdgeAroundVtx;
00434 WEFILE >> wght;
00435 WEFILE >> X >> Y;
00436
00437 SetVtx(ID);
00438 SetEdgeAroundVtx(ID,EdgeAroundVtx);
00439 if(wght) SetWeight(ID,kTRUE);
00440 else SetWeight(ID,kFALSE );
00441 SetX(ID,X);
00442 SetY(ID,Y);
00443 } while(ID != MaxVertex);
00444
00445
00446 WEFILE >> MaxPolygon;
00447 do {
00448 WEFILE >> ID;
00449 WEFILE >> EdgeAroundPolyg;
00450
00451 SetPolyg(ID);
00452 SetEdgeAroundPolyg(ID,EdgeAroundPolyg);
00453 } while(ID != MaxPolygon);
00454 }
00456
00457 void BFLWingedEdge::SaveNodalSet(const Char_t * filename)
00458 {
00459 ofstream NSFILE(filename,std::ios::out);
00460
00461 TIter next(fGenerators);
00462 BFLNode * generator;
00463 Int_t GeneratedCell = 1;
00464
00465 NSFILE << GetNofPolygons() << endl;
00466 while( (generator = (BFLNode *) next()) ) {
00467 NSFILE << generator->GetNodeID() << "\t\t"
00468 << GeneratedCell++ << "\t\t"
00469 << generator->GetX() << "\t\t"
00470 << generator->GetY() << endl;
00471 }
00472 delete generator;
00473 }
00475
00476 void BFLWingedEdge::LoadNodalSet(const Char_t * filename)
00477 {
00478 ifstream NSFILE(filename,std::ios::in);
00479 Int_t igenerator, NGens, nID, VorCell;
00480 Float_t x, y;
00481 Int_t VorCellLast = -999;
00482
00483 fGenerators = new TObjArray(100);
00484
00485 NSFILE >> NGens;
00486 for(igenerator = 0; igenerator < NGens; igenerator++) {
00487
00488 NSFILE >> nID >> VorCell >> x >> y;
00489 if (VorCell != VorCellLast)
00490 fGenerators->AddAtAndExpand(new BFLNode(nID,x,y),VorCell-1);
00491 VorCellLast = VorCell;
00492 }
00493 }
00495
00496 Long_t BFLWingedEdge::Size(void)
00497 {
00498 Long_t size = 0;
00499
00500 TIter nextv(fVertices);
00501 BFLVtx * vtx;
00502 while( (vtx = (BFLVtx *)nextv()) ) size += sizeof(*vtx);
00503
00504 TIter nexte(fEdges);
00505 BFLEdge * edge;
00506 while( (edge = (BFLEdge *)nexte()) ) size += sizeof(*edge);
00507
00508 TIter nextp(fPolygons);
00509 BFLPolyg * polyg;
00510 while( (polyg = (BFLPolyg *)nextp()) ) size += sizeof(*polyg);
00511
00512 delete vtx;
00513 delete edge;
00514 delete polyg;
00515
00516 return size;
00517 }
00519
00520 void BFLWingedEdge::LoadANSYSLookupTable(BfldGrid::Grid_t grid)
00521 {
00522 if(fANSYSTable) delete fANSYSTable;
00523 fANSYSTable = new BFLAnsysLookup(grid);
00524 }