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

# ShockGraph.h

Go to the documentation of this file.

    00001
    00043 #ifndef __SHOCK_GRAPH_H__
    00044 #define __SHOCK_GRAPH_H__
    00045
    00046 #include "DAG.h"
    00047 #include "SGNode.h"
    00048 #include <LEDA/tuple.h>
    00049 #include "BlumSkeleton.h"
    00050
    00051 #ifdef COMPILE_OLD_SG_CODE
    00052 #include "MGShockGraph.h"
    00053 #endif //COMPILE_OLD_SG_CODE
    00054
    00055 #include <sg.h>
    00056 extern "C"
    00057 {
    00058 #include <ppm.h>
    00059 }
    00060
    00061 class ShockGraph;
    00062
    00064 typedef SmartPtr<ShockGraph> SGPtr;
    00065
    00066 // SG computation params
    00067 struct SGCP
    00068 {
    00069     int nSlipt3s;
    00070     double dMinSlope, dMinError, dSkTreshold;
    00071     double dMaxAccelChg;
    00072
    00073     SGCP() { memset(this, 0, sizeof(SGCP)); }
    00074 };
    00075
    00082 class ShockGraph: public DAG
    00083 {
    00084      int nLastIndexUsed;
    00085      const char* GetNextIdx();
    00086      BlumSkeleton* m_pSkeleton;
    00087      SGCP compParams;
    00088
    00089 public:
    00090
    00091         enum BRANCH_DIR {IN_DIR, OUT_DIR};
    00092
    00095         double area;
    00096
    00099         double perimeter;
    00100
    00101         double xmin, xmax, ymin, ymax;
    00102
    00103         double Width() const { return xmax - xmin; }
    00104         double Height() const { return ymax - ymin; }
    00105
    00106         int NodeType(leda_node v) const { return GetSGNode(v)->m_nType; }
    00107         NODE_ROLE NodeRole(leda_node v) const { return GetSGNode(v)->GetNodeRole(); }
    00108         int NodeLength(leda_node v) const {     return GetSGNode(v)->m_shocks.GetSize(); }
    00109
    00110         int GetBranchDir(leda_node u, leda_node wrtV) const;
    00111         const ShockInfo& GetJointPoint(leda_node u, leda_node v) const;
    00112
    00113         ShockGraph();
    00114         ~ShockGraph();
    00115
    00116 #ifdef COMPILE_OLD_SG_CODE
    00117         bool Translate(const MGShockGraph& sg);
    00118
    00119         bool ComputeFromMemory(Pixmap& image,
    00120                 double cutoff = .15, double sigma = 2, double range = 3);
    00121 #endif //COMPILE_OLD_SG_CODE
    00122         bool ComputeFromPPMFile(const char* szFileName,
    00123                 double cutoff = .15, double sigma = 2, double range = 3);
    00124
    00125         bool ComputeFromPPMFile2(const char* szFileName, const SGCP& sgparams);
    00126
    00127         bool RecomputeFromSkeleton(const SGCP& sgparams);
    00128
    00129         sg::DDSkeleton* ComputeDDSkeleton(const char* szPPMFileName);
    00130         bool ComputeSGFromDDSkeleton(sg::DDSkeleton* sk);
    00131
    00132         SGNode* CopyNodeInfo(sg::DDSEdge* ddsEdge, leda_node u, SGNode* pNode);
    00133         void LabelEndPoints(SGNode* pNode, sg::FluxPointList& fpl, sg::DDSNode* n1, sg::DDSNode* n2);
    00134         SGNode* GroupShockPoints(leda_node u, SGNode* pNode);
    00135         SGNode* SplitNode(leda_node v, SGNode* pNode, int nEnd, SEGMENT& leftSeg, SEGMENT& rightSeg);
    00136         void ConnectNodes(leda_node u, SGNode* pNode, sg::DDSEdge* e, sg::DDSNode* n);
    00137
    00138         void RevertEdge(leda_edge pxEdge);
    00139
    00140         void DetectLigatureNodes(sg::DDSkeleton* sk);
    00141         void Insert4sAnd2s();
    00142         void Relabel3As2or4(leda_node v);
    00143
    00144         void ComputeObjectViewName();
    00145         void ComputeNodeRole(leda_node v);
    00146
    00147         sg::DiscreteDivergenceSkeletonEdge* GetGreatestUntouched (leda_d_array<long, leda_node>& map,
    00148                 std::vector<sg::DiscreteDivergenceSkeletonEdge*> edges);
    00149
    00150         SGNode* SplitSGNode(SGNode* pNode, leda_d_array<long, leda_node>& map);
    00151
    00152         void DrawEdges(sg::DiscreteDivergenceSkeletonEdge* SKparent,
    00153                 sg::DiscreteDivergenceSkeletonNode* node, leda_d_array<long, leda_node>& map, SGNode* SGparent);
    00154         int ComputeNodeLabel(const SGNode *node) const;
    00155
    00156         NODE_LABEL GetNodeLbl(leda_node v) const;
    00157
    00158         // DAG virtual functions
    00159         virtual DAG& operator=(const DAG& rhs);
    00160         virtual void Clear();
    00161         virtual void ComputeDerivedValues();
    00162
    00163         // DAG pure virtual functions
    00164         virtual double NodeDistance(leda_node g1Node, const DAG& g2, leda_node g2Node) const;
    00165         virtual bool AreNodesRelated(leda_node g1Node, const DAG& g2, leda_node g2Node) const;
    00166         virtual DAG* CreateObject() const;
    00167         virtual DAGNodePtr CreateNodeObject(NODE_LABEL lbl) const;
    00168         virtual DAGNodePtr ReadNode(istream& is) const;
    00169         virtual String ClassName() const;
    00170
    00171         virtual istream& Read(istream& is, bool bOnlyDataForMatching = false);
    00172         virtual ostream& Write(ostream& os) const;
    00173         virtual void Print(ostream& os = cout) const;
    00174
    00175         const BlumSkeleton* GetSkeleton() const { return m_pSkeleton; }
    00176         const SGNode* GetSGNode(leda_node v) const { return (const SGNode*)(const DAGNode*)GetNode(v); }
    00177         SGNode* UnsafeGetSGNode(leda_node v) { return (SGNode*)GetSGNode(v); }
    00178 };
    00179
    00180 #endif //__SHOCK_GRAPH_H__