00001
00002
00004
00005
00006
00008
00009 #include "DasherNode.h"
00010 using namespace Dasher;
00011 using namespace Opts;
00012 using namespace std;
00013
00015
00016 void CDasherNode::Dump_node () const
00017 {
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 }
00034
00035 void CDasherNode::Generic_Push_Node(CLanguageModel::CNodeContext *) {
00036
00037 m_iAge=0;
00038 m_bAlive=true;
00039 if (m_Symbol && !m_iChars)
00040 m_languagemodel->EnterNodeSymbol(m_context,m_Symbol);
00041
00042
00043 vector<symbol> newchars;
00044 vector<unsigned int> cum,groups;
00045 m_languagemodel->GetNodeProbs(m_context,newchars,groups,cum,0.003);
00046 m_iChars=newchars.size();
00047
00048 unsigned int i;
00049 for (i=1;i<m_iChars;i++)
00050 cum[i]+=cum[i-1];
00051
00052 m_Children =new CDasherNode *[m_iChars];
00053
00054
00055 ColorSchemes NormalScheme, SpecialScheme;
00056 if ((m_ColorScheme==Nodes1) || (m_ColorScheme==Special1)) {
00057 NormalScheme = Nodes2;
00058 SpecialScheme = Special2;
00059 } else {
00060 NormalScheme = Nodes1;
00061 SpecialScheme = Special1;
00062 }
00063
00064 ColorSchemes ChildScheme;
00065 for (i=1;i<m_iChars;i++) {
00066 if (newchars[i]==this->m_languagemodel->GetSpaceSymbol())
00067 ChildScheme = SpecialScheme;
00068 else
00069 ChildScheme = NormalScheme;
00070 m_Children[i]=new CDasherNode(this,newchars[i],groups[i],i,ChildScheme,cum[i-1],cum[i],m_languagemodel,m_languagemodel->GetColour(i));
00071 }
00072 }
00073
00075
00076 void CDasherNode::Push_Node(CLanguageModel::CNodeContext *context)
00077
00078 {
00079
00080 if (m_Children) {
00081
00082 unsigned int i;
00083 for (i=1;i<m_iChars;i++) {
00084 m_Children[i]->m_iAge=0;
00085 m_Children[i]->m_bAlive=1;
00086 }
00087 return;
00088 }
00089
00090
00091 m_context=m_languagemodel->CloneNodeContext(context);
00092
00093 if (!m_context)
00094 return;
00095 Generic_Push_Node(m_context);
00096 }
00097
00099
00100 void CDasherNode::Push_Node()
00101 {
00102
00103 if (m_Children) {
00104
00105 unsigned int i;
00106 for (i=1;i<m_iChars;i++) {
00107 m_Children[i]->m_iAge=0;
00108 m_Children[i]->m_bAlive=1;
00109 }
00110 return;
00111 }
00112
00113
00114 if (m_parent)
00115 m_context=m_languagemodel->CloneNodeContext(m_parent->m_context);
00116 else
00117 m_context=m_languagemodel->GetRootNodeContext();
00118
00119
00120 if (!m_context)
00121 return;
00122 Generic_Push_Node(m_context);
00123 }
00124
00126
00127 void CDasherNode::Get_string_under(const int iNormalization,const myint miY1,const myint miY2,const myint miMousex,const myint miMousey, vector<symbol> &vString) const
00128 {
00129
00130 vString.push_back(m_Symbol);
00131
00132
00133 if (m_Children) {
00134 myint miRange=miY2-miY1;
00135 unsigned int i;
00136 for (i=1;i<m_iChars;i++) {
00137 myint miNewy1=miY1+(miRange*m_Children[i]->m_iLbnd)/iNormalization;
00138 myint miNewy2=miY1+(miRange*m_Children[i]->m_iHbnd)/iNormalization;
00139 if (miMousey<miNewy2 && miMousey>miNewy1 && miMousex<miNewy2-miNewy1) {
00140 m_Children[i]->Get_string_under(iNormalization,miNewy1,miNewy2,miMousex,miMousey,vString);
00141 return;
00142 }
00143 }
00144 }
00145 return;
00146 }
00147
00149
00150 CDasherNode * const CDasherNode::Get_node_under(int iNormalization,myint miY1,myint miY2,myint miMousex,myint miMousey)
00151 {
00152 if (m_Children) {
00153 myint miRange=miY2-miY1;
00154 m_iAge=0;
00155 m_bAlive=true;
00156 unsigned int i;
00157 for (i=1;i<m_iChars;i++) {
00158 myint miNewy1=miY1+(miRange*m_Children[i]->m_iLbnd)/iNormalization;
00159 myint miNewy2=miY1+(miRange*m_Children[i]->m_iHbnd)/iNormalization;
00160 if (miMousey<miNewy2 && miMousey>miNewy1 && miMousex<miNewy2-miNewy1)
00161 return m_Children[i]->Get_node_under(iNormalization,miNewy1,miNewy2,miMousex,miMousey);
00162 }
00163 }
00164 return this;
00165 }
00166