Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

DCVertex.h

Go to the documentation of this file.
00001 #ifndef DCVERTEX_H
00002 #define DCVERTEX_H
00003 
00004 #include <iostream>
00005 #include <vector>
00006 #include "TObject.h"
00007 #include "NueAna/NueAnaTools/DCEdge.h"
00008 
00009 using std::vector;
00010 using std::cout;
00011 using std::endl;
00012 
00013 template<class T> class DCGraph;
00014 
00015 //for a class T to work in this template it must:
00016 //have a < operater
00017 //have a == operator
00018 //have a - operator that returns a T
00019 //have an abs() operator
00020 //have a Print() method
00021 //have a Draw() method
00022 //have a SetData() method
00023 //have a GetData() method
00024 
00025 template <class T> class DCVertex : public TObject 
00026 {
00027 public:
00028 
00029    DCVertex(){data=0; edges=0; next=0;}
00030    DCVertex(T *idata, DCVertex<T> *nextVert) { data=new T(*idata); next=nextVert; edges=0;}
00031    
00032    virtual ~DCVertex(){ 
00033       if(data!=0){delete data; data=0;}
00034       if(next!=0){delete next; next=0;}
00035       if(edges!=0){delete edges; edges=0;}
00036    }
00037 
00038    T *GetData(){return data;}
00039    DCVertex<T> *GetNextVertex() {return next;}
00040    DCEdge<T> *GetFirstEdge() {return edges;}
00041    void ResetNextVertex(DCVertex<T> *newvert) { next=newvert;}
00042    void ResetFirstEdge(DCEdge<T> *newedge) { edges=newedge;}
00043 
00044    virtual void Print(Option_t *t="") const;
00045    void PrintEdges();
00046    void PrintGraph();
00047    float ConnectTo(DCVertex<T> *);
00048    virtual void Draw(Option_t* t="");
00049    void DrawEdges(Option_t *t="");
00050    void DrawGraph(Option_t *t="");
00051    void ClearConnections();
00052 
00053 private:
00054    T *data;
00055    DCEdge<T> *edges;
00056    DCVertex<T> *next;
00057    ClassDef(DCVertex<T>,1)
00058 
00059 };
00060 
00061 
00062 ClassImpT(DCVertex,T)
00063 
00064 template<class T> void DCVertex<T>::PrintEdges() 
00065 {
00066    if (edges == 0){
00067       cout << "vertex ";
00068       GetData()->Print();
00069       cout<< " has no edges" << endl;
00070    }
00071   else {
00072     cout << "vertex ";
00073     GetData()->Print();
00074     cout << " has edges to: " << endl;
00075     edges->Print();
00076   }
00077 }  
00078 
00079 // prints the edges of the vertex, calls the printGraph method for 
00080 // the next vertex
00081 template<class T>void DCVertex<T>::PrintGraph()
00082 {
00083    PrintEdges();
00084    if (next != 0){
00085       next->PrintGraph();
00086    }
00087 }
00088 
00089 template<class T>void DCVertex<T>::Draw(Option_t *t)
00090 {
00091 //   cout<<"in DCVertex::Draw on ";
00092 //   data->Print();
00093 //   cout<<endl;
00094    data->Draw(t);
00095 }
00096 
00097 template<class T>void DCVertex<T>::DrawEdges(Option_t *t)
00098 {
00099 //   cout<<"In DCVertex::DrawEdges "<<endl;
00100    data->Draw(t);
00101    if(edges!=0){
00102       edges->DrawThisEdge(this,t);
00103    }
00104 }
00105   
00106 template<class T> void DCVertex<T>::DrawGraph(Option_t *t)
00107 {
00108 //   cout<<"In DCVertex::DrawGraph"<<endl;
00109    DrawEdges(t);
00110    if (next != 0){
00111 //      cout<<"Drawing next vertex"<<endl;
00112       next->DrawGraph(t);
00113    }  
00114 }
00115 
00116 
00117 template<class T> void DCVertex<T>::Print(Option_t *t) const
00118 {
00119    data->Print(t);
00120 }
00121 
00122 // adds an edge to connect the vertex to the vertex pointed to by Vert
00123 template<class T> float DCVertex<T>::ConnectTo(DCVertex<T> *Vert) 
00124 {
00125 //   cout<<"In DCVertex::ConnectTo"<<endl;
00126   // allocate memory for a new Edge, set its Vertex pointer to point 
00127   // to Vert, and its Edge pointer to point to the rest of edges 
00128    T minus = (*(Vert->GetData()))-(*data);
00129    float m=(*data-*(Vert->GetData())).abs();
00130    float xm=0.;
00131    float ym=0.; 
00132    float zm=0.;
00133    minus.GetData(xm,ym,zm);
00134    float wm = m*zm;
00135    float xwm=xm*zm;
00136    float ywm=ym*zm;
00137    DCEdge<T> *newEdge = new DCEdge<T>(Vert, edges, m, xm, ym, wm, xwm, ywm);
00138    
00139    // make the new edge the first edge of the vertex
00140    edges = newEdge; 
00141    return newEdge->GetMetric();
00142 }
00143 
00144 template<class T> void DCVertex<T>::ClearConnections()
00145 {
00146    edges=0;
00147 }
00148 
00149 
00150 #endif //VERTEX_H

Generated on Mon Feb 15 11:06:36 2010 for loon by  doxygen 1.3.9.1