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

# MGShockGraph.cpp

Go to the documentation of this file.

    00001
    00037 #include <iostream.h>
    00038 #include <stdio.h>
    00039 #include "Debug.h"
    00040 #include "MGShockGraph.h"
    00041
    00042 extern "C" {
    00043 #define BOOL_DEFINED
    00044 #include <shockgraph-interface.h>
    00045 }
    00046
    00047 #ifdef XML_READING
    00048 #ifndef WIN32
    00049         extern "C" {
    00050         #include <read-xml-skeleton.h>
    00051         #include <read-xml-shockgraph.h>
    00052         }
    00053 #else
    00054         typedef void* xmlDocPtr;
    00055         xmlDocPtr read_xml_file(FILE*);
    00056         Graph* get_xml_shockgraph(xmlDocPtr, FILE*);
    00057 #endif //_MY_DEBUG
    00058 #endif //XML_READING
    00059
    00060
    00061 const MGShockGraph::SGPoint& MGShockGraph::SGSegment::operator[](int i) const
    00062 {
    00063         return *((SGPoint*)getDLCellAt(m_pShock->points, i)->data);
    00064 }
    00065
    00066 MGShockGraph::SGSegment MGShockGraph::operator[](int i) const
    00067 {
    00068         return (Shock*)((Vertex*)getDLCellAt(m_pGraph->vertices, i)->data)->data;
    00069 }
    00070
    00071 const Vertex* MGShockGraph::GetNode(int i) const
    00072 {
    00073         return (Vertex*)getDLCellAt(m_pGraph->vertices, i)->data;
    00074 }
    00075
    00076 MGShockGraph::SGSegment MGShockGraph::GetSegment(const Vertex* pNode) const
    00077 {
    00078         return (Shock*)pNode->data;
    00079 }
    00080
    00081 const Edge* MGShockGraph::GetEdge(int i) const
    00082 {
    00083         return (Edge*)getDLCellAt(m_pGraph->edges, i)->data;
    00084 }
    00085
    00086 #ifdef XML_READING
    00087 bool MGShockGraph::ReadFromXMLFile(const char* szFileName)
    00088 {
    00089         Empty();
    00090
    00091         FILE* file = fopen(szFileName, "r");
    00092
    00093         if (file == NULL)
    00094                 return false;
    00095
    00096         xmlDocPtr doc = (xmlDocPtr) read_xml_file(file);
    00097
    00098         fclose(file);
    00099
    00100         if (doc == NULL)
    00101                 return false;
    00102
    00103         m_pGraph = get_xml_shockgraph(doc, stderr);
    00104
    00105         return m_pGraph != NULL;
    00106 }
    00107 #endif //XML_READING
    00108
    00109 bool MGShockGraph::ComputeFromPPMFile(const char* szFileName, double cutoff, double sigma, double range)
    00110 {
    00111         Empty();
    00112
    00113         /* Initialize the parameters to the default values
    00114            One can initialize the parameters oneself, but it is preferable to
    00115            initialize them and then modify only the relevant ones. */
    00116         ShockParam sp;
    00117
    00118         init_shock_param(&sp);
    00119
    00120         sp.deriv_cutoff = cutoff;
    00121         sp.deriv_smooth_sigma = sigma;
    00122         sp.deriv_smooth_range = range;
    00123
    00124         FILE* file = fopen(szFileName, "r");
    00125
    00126         if (file == NULL)
    00127                 return false;
    00128
    00129         m_pGraph = get_shockgraph_ppm(file, &sp);
    00130
    00131         fclose(file);
    00132
    00133         return m_pGraph != NULL;
    00134 }
    00135
    00140 bool MGShockGraph::ComputeFromMemory(Pixmap& image, double cutoff, double sigma, double range)
    00141 {
    00142         Empty();
    00143
    00144         /* Initialize the parameters to the default values
    00145            One can initialize the parameters oneself, but it is preferable to
    00146            initialize them and then modify only the relevant ones. */
    00147         ShockParam sp;
    00148
    00149         init_shock_param(&sp);
    00150
    00151         sp.deriv_cutoff = cutoff;
    00152         sp.deriv_smooth_sigma = sigma;
    00153         sp.deriv_smooth_range = range;
    00154
    00155         Mat2d matrix;
    00156
    00157         matrix.rows = image.rows;
    00158         matrix.cols = image.cols;
    00159         matrix.buf = image.data;
    00160
    00161         m_pGraph = get_shockgraph(&matrix, &sp);
    00162
    00163         return m_pGraph != NULL;
    00164 }
    00165
    00166 ostream& operator<<(ostream& os, const MGShockGraph::SGPoint& p)
    00167 {
    00168     os << endl        << "   ";
    00169     os << "x:"        << p.x            << ", ";
    00170     os << "y:"        << p.y            << ", ";
    00171     os << "segments:" << p.segments     << ", ";
    00172     os << "color:"    << (short)p.color << ", ";
    00173     os << "r:"        << p.r            << ", ";
    00174     os << "s:"        << p.s            << ", ";
    00175     os << "dr_ds:"    << p.dr_ds;
    00176     os << endl << endl;
    00177
    00178         return os;
    00179 }
    00180
    00181 ostream& operator<<(ostream& os, const MGShockGraph::SGSegment& s)
    00182 {
    00183     os << endl;
    00184     os << "shock_type:"   << s.m_pShock->shock_type   << ", ";
    00185     os << "points:";
    00186
    00187     for (int i = 0; i < s.GetPointCount(); i++)
    00188       os << s[i];
    00189
    00190     os << "id:"           << s.m_pShock->id           << ", ";
    00191     os << "cseg1:"        << s.m_pShock->cseg1        << ", ";
    00192     os << "cseg1_length:" << s.m_pShock->cseg1_length << ", ";
    00193     os << "cseg2:"        << s.m_pShock->cseg2        << ", ";
    00194     os << "cseg2_length:" << s.m_pShock->cseg2_length;
    00195     os << endl;
    00196
    00197         return os;
    00198 }
    00199
    00200
    00201 /*main(int argc, char* argv[])
    00202 {
    00203   MGShockGraph sg;
    00204
    00205   if (!sg.ReadFromXMLFile(argv[1])) {
    00206     cout << "Cannot open %s file." << argv[1];
    00207     return 0;
    00208   }
    00209
    00210   for (int i = 0; i < sg.GetNodeCount(); i++)
    00211      cout << i << '/' << sg.GetNodeCount() << ": " << sg[i];
    00212
    00213   cout << "\n\nFINISHED!!!!\n\n";
    00214
    00215   return 0;
    00216 } */