#include #include #include #include "IMesh.hxx" COMET::IMesh::IMesh() : fUnitXLength(1), fUnitYLength(1) { } // This routine is a little weird since COMET::IMeshPoint and COMET::IMeshEdge objects have // cross pointers and will try to delete each other. COMET::IMesh is going to delete // all of the pointers and we don't want this complicated inter-delete stuff. // For that reason, it does some internal clearing and NULL pointer setting // before actually deleting stuff. COMET::IMesh::~IMesh() { // Delete the each COMET::IMeshPoint by first clearing the edges that connect it // to other points, and then doing the delete. After this loop is // finished, the end point pointers in fEdges are invalid and so must be // reset before deleting the edges. for (TMeshPointSet::iterator p = fPoints.begin(); p!=fPoints.end(); ++p) { (*p)->fEdges.clear(); // invalidate the edge set... delete *p; } // Now delete the edges by first clearing the head and tail pointers so // that the COMET::IMeshEdge destructor won't try to remove the edge from the end // point edge sets. for (TMeshEdgeSet::iterator e = fEdges.begin(); e!=fEdges.end(); ++e) { (*e)->fHead = NULL; (*e)->fTail = NULL; delete *e; } } COMET::IMeshPoint* COMET::IMesh::AddPoint(COMET::IMeshPoint* point) { TMeshPointSet::iterator p = fPoints.find(point); if (p != fPoints.end()) { if (*p != point) delete point; return *p; } fPoints.insert(point); return point; } COMET::IMeshEdge* COMET::IMesh::AddEdge(COMET::IMeshEdge* edge) { TMeshEdgeSet::iterator e = fEdges.find(edge); if (e != fEdges.end()) { if (*e != edge) delete edge; edge = *e; } COMET::IMeshPoint* h = COMET::IMesh::AddPoint(edge->GetHead()); h->AddEdge(edge); COMET::IMeshPoint* t = COMET::IMesh::AddPoint(edge->GetTail()); t->AddEdge(edge); fEdges.insert(edge); return edge; } void COMET::IMesh::RemoveEdge(COMET::IMeshEdge* edge) { TMeshEdgeSet::iterator e = fEdges.find(edge); fEdges.erase(e); delete edge; } void COMET::IMesh::Paint(Option_t* opt) { TAttMarker::Modify(); TAttLine::Modify(); for (TMeshPointSet::iterator p = BeginPoints(); p!=EndPoints(); ++p) { double x1 = gPad->XtoPad((*p)->X()/fUnitXLength); double y1 = gPad->YtoPad((*p)->Y()/fUnitYLength); gPad->PaintPolyMarker(-1,&x1,&y1,""); } for (TMeshEdgeSet::iterator e = BeginEdges(); e != EndEdges(); ++e) { double x1 = gPad->XtoPad((*e)->GetHead()->X()/fUnitXLength); double y1 = gPad->YtoPad((*e)->GetHead()->Y()/fUnitYLength); double x2 = gPad->XtoPad((*e)->GetTail()->X()/fUnitXLength); double y2 = gPad->YtoPad((*e)->GetTail()->Y()/fUnitYLength); gPad->PaintLine(x1,y1,x2,y2); } }