Main Page Namespace List Class Hierarchy Compound List File List Namespace Members Compound Members File Members Related Pages

# SGNode.h

Go to the documentation of this file.

    00001
    00042 #ifndef __SG_NODE_H__
    00043 #define __SG_NODE_H__
    00044
    00045 #include "DAGNode.h"
    00046 #include "String.h"
    00047 #include "ApproxPoly.h"
    00048
    00049 #define  SHOCK_base 100
    00050 #define  SHOCK_2or3 100
    00051 #define  SHOCK_1        101
    00052 #define  SHOCK_2        102
    00053 #define  SHOCK_3        103
    00054 #define  SHOCK_4        104
    00055 #define  ROOT           105
    00056 #define  TEST_NODE      106
    00057
    00058 enum NODE_ROLE {UNK_ROLE = 0, BIRTH, PROTRUSION, UNION, DEATH, DUMMY};
    00059 enum ENDPT_TYPE {NOTSET_POINT, TERMINAL_POINT, JOINT_POINT, SPLIT_POINT};
    00060
    00062 struct ShockInfo
    00063 {
    00064         double xcoord;
    00065         double ycoord;
    00066         double radius;
    00067         double speed;
    00068         double dr_ds;
    00069         char color;
    00070         double dr;
    00071         int type;
    00072         int dir;
    00073
    00074         ShockInfo() { memset(this, 0, sizeof(ShockInfo)); }
    00075
    00076         virtual istream& Read(istream& is);
    00077         virtual ostream& Write(ostream& os) const;
    00078         void Print(ostream &os) const;
    00079
    00080         friend ostream& operator<<(ostream& os, const ShockInfo& shock) { return shock.Write(os); }
    00081         friend istream& operator>>(istream& is, ShockInfo& shock)               { return shock.Read(is); }
    00082
    00083         bool operator==(const ShockInfo& rhs) const
    00084         {
    00085                 return xcoord == rhs.xcoord && ycoord == rhs.ycoord;
    00086         }
    00087 };
    00088
    00089 class ShockBranch : public SmartArray<ShockInfo>
    00090 {
    00091         SEGMENTS segments;
    00092         int dir;
    00093
    00094         bool bValuesComputed;
    00095         double area;
    00096         double length;
    00097         double avgRadius;
    00098         double avgVelocity;
    00099
    00100 public:
    00101         enum BRANCH_DIR {FORWARD, BACKWARD};
    00102
    00103         ShockBranch()
    00104         {
    00105                 dir = 2; //diff than 0, 1, -1
    00106
    00107                 bValuesComputed = false;
    00108                 area = length = avgRadius = avgVelocity = 0;
    00109         }
    00110
    00111         void Clear()
    00112         {
    00113                 SmartArray<ShockInfo>::Clear();
    00114
    00115                 segments.Clear();
    00116                 dir = 2; //diff than 0, 1, -1
    00117
    00118                 bValuesComputed = false;
    00119                 area = length = avgRadius = avgVelocity = 0;
    00120         }
    00121
    00122         ShockBranch(const ShockBranch& rhs)
    00123         {
    00124                 operator=(rhs);
    00125         }
    00126
    00127         ShockBranch& operator=(const ShockBranch& rhs)
    00128         {
    00129                 SmartArray<ShockInfo>::operator=(rhs);
    00130
    00131                 segments                = rhs.segments;
    00132                 dir                             = rhs.dir;
    00133
    00134                 bValuesComputed = rhs.bValuesComputed;
    00135                 area                    = rhs.area;
    00136                 length                  = rhs.length;
    00137                 avgRadius               = rhs.avgRadius;
    00138                 avgVelocity     = rhs.avgVelocity;
    00139
    00140                 return *this;
    00141         }
    00142
    00143         ShockBranch& operator=(const SmartArray<ShockInfo>& rhs)
    00144         {
    00145                 SmartArray<ShockInfo>::operator=(rhs);
    00146                 return *this;
    00147         }
    00148
    00149         bool operator==(const ShockBranch& rhs) const;
    00150         bool operator!=(const ShockBranch& rhs) const { return !operator==(rhs); }
    00151
    00152         bool operator>(const ShockBranch& rhs) const;
    00153         bool operator<=(const ShockBranch& rhs) const { return !operator>(rhs); }
    00154
    00155         bool operator<(const ShockBranch& rhs) const { return operator<=(rhs) && operator!=(rhs); }
    00156         bool operator>=(const ShockBranch& rhs) const { return !operator<(rhs); }
    00157
    00158         void GetEndPtRadius(double& r0, double& rN) const
    00159         {
    00160                 if (segments.GetSize() > 0) // Use segment' end pt, because the don't have outliers
    00161                 {
    00162                         r0 = segments.GetHead().Y0();
    00163                         rN = segments.GetTail().Y1();
    00164                 }
    00165                 else
    00166                 {
    00167                         r0 = GetHead().radius;
    00168                 rN = GetTail().radius;
    00169                 }
    00170         }
    00171
    00172         const double& MinR() const
    00173         {
    00174                 double r0, rN;
    00175                 GetEndPtRadius(r0, rN);
    00176             return r0 < rN ? r0:rN;
    00177         }
    00178
    00179         const double& MaxR() const
    00180         {
    00181                 double r0, rN;
    00182                 GetEndPtRadius(r0, rN);
    00183             return r0 > rN ? r0:rN;
    00184         }
    00185
    00186         void SetDir(int d) { dir = d; }
    00187         void SetSegments(const SEGMENTS& segs, const double& d);
    00188         SEGMENTS GetSegments() const { return segments; }
    00189
    00190         int GetDir(BRANCH_DIR d) const
    00191         {
    00192                 ASSERT(dir == 0 || dir == 1 || dir == -1);
    00193                 return (d == FORWARD || dir == 0) ? dir:-dir;
    00194         }
    00195
    00196         istream& Read(istream& is);
    00197         ostream& Write(ostream& os) const;
    00198         void Print(ostream &os = cout) const;
    00199
    00200         void ComputeDerivedValues();
    00201
    00202         double CompareAreas(const ShockBranch& rhs, const double& scale) const;
    00203         double CompareRadii(const ShockBranch& rhs, const double& scale) const;
    00204         double CompareVelocities(const ShockBranch& rhs, const double& scale) const;
    00205
    00206         double Area() const             { ASSERT(bValuesComputed); return area; }
    00207         double Length() const           { ASSERT(bValuesComputed); return length; }
    00208         double AvgRadius() const        { ASSERT(bValuesComputed); return avgRadius; }
    00209         double AvgVelocity() const      { ASSERT(bValuesComputed); return avgVelocity; }
    00210 };
    00211
    00222 class SGNode : public DAGNode
    00223 {
    00224 public:
    00225         int m_nType;
    00226         char m_cEndPt;
    00227         double m_seg1, m_seg2;
    00228         String m_strBranchId;
    00229         ShockBranch m_shocks;
    00230         NODE_ROLE m_nRole;
    00231         ENDPT_TYPE m_nEndPt0, m_nEndPtN;
    00232
    00233         virtual DAGNode* CreateObject() const;
    00234
    00235         // Operations
    00236 public:
    00237
    00238         SGNode() { }
    00239         SGNode(const SGNode &sb)                { SGNode::operator=(sb); }
    00240         SGNode(String szId, int nType);
    00241
    00242         void GetContourLength(double& seg1, double& seg2) const { seg1 = m_seg1; seg2 = m_seg2; }
    00243         void SetContourLength(double& seg1, double& seg2) { m_seg1 = seg1; m_seg2 = seg2; }
    00244
    00245         virtual void ComputeDerivedValues();
    00246
    00247         void ComputeSpeeds();
    00248         int GetShockCount() const { return m_shocks.GetSize(); }
    00249
    00250         int GetType() const { return m_nType; }
    00251         char GetEndPt() const { return m_cEndPt; }
    00252         String GetBranchId() const { return m_strBranchId; }
    00253         int GetBranchDir(ShockBranch::BRANCH_DIR d) const { return m_shocks.GetDir(d); }
    00254         SEGMENTS GetSegments() const { return m_shocks.GetSegments(); }
    00255
    00256         const ShockInfo& operator[](int i) const { return m_shocks[i]; }
    00257         int GetSize() const { return m_shocks.GetSize(); }
    00258
    00259         POINTS GetVelocityRadiusArray(int& d0, int& dn, bool bReverseOrder = false) const;
    00260
    00261         void SetNodeType(int nType) { m_nType = nType; }
    00262
    00263         NODE_ROLE GetNodeRole() const { return m_nRole; }
    00264         void SetNodeRole(NODE_ROLE nRole) { m_nRole = nRole; }
    00265
    00266         virtual void Clear();
    00267         virtual DAGNode& operator=(const DAGNode& rhs);
    00268         virtual void Print(ostream& os = cout) const;
    00269         virtual istream& Read(istream& is);
    00270         virtual ostream& Write(ostream& os) const;
    00271
    00272         virtual NODE_LABEL GetLblForGraph() const;
    00273         virtual leda_color GetColorForGraph() const;
    00274         virtual int GetShapeForGraph() const;
    00275 };
    00276
    00277 #endif //__SG_NODE_H__