Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

DasherNode.cpp

Go to the documentation of this file.
00001 // DasherNode.cpp
00002 //
00004 //
00005 // Copyright (c) 2001-2002 David Ward
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         /* TODO sort out
00019         dchar out[256];
00020         if (m_Symbol)
00021                 wsprintf(out,TEXT("%7x %3c %7x %5d %7x  %5d %8x %8x      \n"),this,m_Symbol,m_iGroup,m_context,m_Children,m_Cscheme,m_iLbnd,m_iHbnd);
00022         else
00023                 wsprintf(out,TEXT("%7x     %7x %5d %7x  %5d %8x %8x      \n"),this,m_iGroup,m_context,m_Children,m_Cscheme,m_iLbnd,m_iHbnd);
00024         
00025         OutputDebugString(out);
00026         
00027         if (m_Children) {
00028                 unsigned int i; 
00029                 for (i=1;i<m_iChars;i++)
00030                         m_Children[i]->Dump_node();
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)   // make sure it's a valid symbol and don't enter if already done
00040                 m_languagemodel->EnterNodeSymbol(m_context,m_Symbol);
00041 
00042         
00043         vector<symbol> newchars;   // place to put this list of characters
00044         vector<unsigned int> cum,groups;   // for the probability list
00045         m_languagemodel->GetNodeProbs(m_context,newchars,groups,cum,0.003);
00046         m_iChars=newchars.size();
00047         // work out cumulative probs
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         // create the children
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 // push a node copying the specified context
00078 {
00079 
00080         if (m_Children) {
00081                 // if there are children just give them a poke
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         // if we haven't got a context then try to get a new one
00091         m_context=m_languagemodel->CloneNodeContext(context);
00092         // if it fails, be patient
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                 // if there are children just give them a poke
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         // if we haven't got a context then try to get a new one
00114         if (m_parent) 
00115                 m_context=m_languagemodel->CloneNodeContext(m_parent->m_context);
00116         else
00117                 m_context=m_languagemodel->GetRootNodeContext();
00118         
00119         // if it fails, be patient
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         // we are over (*this) node so add it to the string 
00130         vString.push_back(m_Symbol);
00131         
00132         // look for children who might also be under the coords
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 

Generated on Sat Nov 5 16:16:00 2005 for OPIE by  doxygen 1.4.2