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

# DAGNode.cpp

Go to the documentation of this file.

    00001
    00043 #include <iostream.h>
    00044 #include "DAGNode.h"
    00045 #include "memory.h"
    00046 #include "HelperFunctions.h"
    00047 #include <stdio.h>
    00048
    00050 DAGNode::DAGNode(NODE_LABEL lbl)
    00051 {
    00052         Clear();
    00053         nodeLbl = lbl;
    00054 }
    00055
    00057 void DAGNode::Clear()
    00058 {
    00059         nodeLbl  = NODE_LBL_DEFAULT_VAL;
    00060         childrenTSV.Clear();
    00061
    00062         eigenLbl = -1.0;
    00063         tsvNorm = -1;
    00064         nMass = -1;
    00065         nLevel = -1;
    00066         nDFSIndex = -1;
    00067         bVisited = false;
    00068         dAssignedSimilarity = 0;
    00069 }
    00070
    00072 void DAGNode::Print(ostream& os) const
    00073 {
    00074         PRINT_OPEN(os, nodeLbl);
    00075         PRINT(os, eigenLbl);
    00076         PRINT(os, tsvNorm);
    00077         PRINT(os, nMass);
    00078         PRINT(os, nLevel);
    00079         PRINT_CLOSE(os, nDFSIndex);
    00080
    00081         childrenTSV.Print(os);
    00082 }
    00083
    00085 DAGNode& DAGNode::operator=(const DAGNode& rhs)
    00086 {
    00087         nodeLbl         = rhs.nodeLbl;
    00088         childrenTSV = rhs.childrenTSV;
    00089
    00090         eigenLbl        = rhs.eigenLbl;
    00091         tsvNorm         = rhs.tsvNorm;
    00092         nMass           = rhs.nMass;
    00093         nLevel          = rhs.nLevel;
    00094         nDFSIndex       = rhs.nDFSIndex;
    00095         bVisited        = rhs.bVisited;
    00096
    00097         return *this;
    00098 }
    00099
    00105 istream& DAGNode::Read(istream& is)
    00106 {
    00107         nodeLbl.Read(is);
    00108         childrenTSV.Read(is);
    00109
    00110         is.read((char*) &eigenLbl, sizeof(eigenLbl));
    00111         is.read((char*) &tsvNorm, sizeof(tsvNorm));
    00112         is.read((char*) &nMass, sizeof(nMass));
    00113         is.read((char*) &nLevel, sizeof(nLevel));
    00114         is.read((char*) &nDFSIndex, sizeof(nDFSIndex));
    00115
    00116         bVisited = false;
    00117
    00118         return is;
    00119 }
    00120
    00126 ostream& DAGNode::Write(ostream& os) const
    00127 {
    00128         nodeLbl.Write(os);
    00129         childrenTSV.Write(os);
    00130
    00131         os.write((char*) &eigenLbl, sizeof(eigenLbl));
    00132         os.write((char*) &tsvNorm, sizeof(tsvNorm));
    00133         os.write((char*) &nMass, sizeof(nMass));
    00134         os.write((char*) &nLevel, sizeof(nLevel));
    00135         os.write((char*) &nDFSIndex, sizeof(nDFSIndex));
    00136
    00137         return os;
    00138 }
    00139
    00150 TSV DAGNode::GetTSV(int nDim) const
    00151 {
    00152         ASSERT(nDim > 0);
    00153
    00154         TSV tsv(nDim);
    00155         int i;
    00156
    00157         tsv[0] = eigenLbl;
    00158
    00159         for (i = 1; i < nDim && i - 1 < childrenTSV.GetSize(); i++)
    00160                 tsv[i] = childrenTSV[i - 1];
    00161
    00162         for (; i < nDim; i++)
    00163                 tsv[i] = 0;
    00164
    00165         // Do not sort it. I want it in a constant position
    00166         // since it is a distinct value from the others.
    00167         // no -> tsv.Sort();
    00168
    00169         return tsv;
    00170 }
    00171
    00177 void DAGNode::ComputeDerivedValues()
    00178 {
    00179         double n = childrenTSV.Norm2();
    00180
    00181         tsvNorm = sqrt(n * n + eigenLbl * eigenLbl);
    00182
    00183         ASSERT(tsvNorm >= 0);
    00184 }
    00185
    00186 NODE_LABEL DAGNode::GetLblForGraph() const
    00187 {
    00188         return GetNodeLbl();
    00189 }
    00190
    00191 leda_color DAGNode::GetColorForGraph() const
    00192 {
    00193         return leda_color(255, 255, 255);
    00194 }
    00195
    00196 int DAGNode::GetShapeForGraph() const
    00197 {
    00198         return 1 /*ellipse_node*/;
    00199 }