| 1 | <h2>Stylus state modeler</h2> |
| 2 | <p>Up till now we have only used the raw input stream to create a new |
| 3 | smoothed stream of positions, leaving behind the pressure attribute. |
| 4 | This is what’s done here, to model the state of the stylus for these new |
| 5 | position based on the pressure data of the raw input strokes.<br /> |
| 6 | <strong>Algorithm</strong> Stylus state modeler<br /> |
| 7 | <strong>Input</strong> : |
| 8 | </p> |
| 9 | <ul> |
| 10 | <li> |
| 11 | <p>input stream with pressure information |
| 12 | <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"> |
| 13 | <semantics> |
| 14 | <mrow> |
| 15 | <mo stretchy="true" form="prefix">{</mo> |
| 16 | <mrow> |
| 17 | <mo stretchy="true" form="prefix">(</mo> |
| 18 | <mi>p</mi> |
| 19 | <mo stretchy="false" form="prefix">[</mo> |
| 20 | <mi>k</mi> |
| 21 | <mo stretchy="false" form="postfix">]</mo> |
| 22 | <mo>=</mo> |
| 23 | <mrow> |
| 24 | <mo stretchy="true" form="prefix">(</mo> |
| 25 | <mi>x</mi> |
| 26 | <mo stretchy="false" form="prefix">[</mo> |
| 27 | <mi>k</mi> |
| 28 | <mo stretchy="false" form="postfix">]</mo> |
| 29 | <mo>,</mo> |
| 30 | <mi>y</mi> |
| 31 | <mo stretchy="false" form="prefix">[</mo> |
| 32 | <mi>k</mi> |
| 33 | <mo stretchy="false" form="postfix">]</mo> |
| 34 | <mo stretchy="true" form="postfix">)</mo> |
| 35 | </mrow> |
| 36 | <mo>,</mo> |
| 37 | <mi>ν</mi> |
| 38 | <mo stretchy="false" form="prefix">[</mo> |
| 39 | <mi>k</mi> |
| 40 | <mo stretchy="false" form="postfix">]</mo> |
| 41 | <mo stretchy="true" form="postfix">)</mo> |
| 42 | </mrow> |
| 43 | <mo>,</mo> |
| 44 | <mn>0</mn> |
| 45 | <mo>≤</mo> |
| 46 | <mi>k</mi> |
| 47 | <mo>≤</mo> |
| 48 | <mi>n</mi> |
| 49 | <mo stretchy="true" form="postfix">}</mo> |
| 50 | </mrow> |
| 51 | <annotation encoding="application/x-tex">\left\{ \left( p\lbrack k\rbrack = \left( x\lbrack |
| 52 | k\rbrack,y\lbrack k\rbrack \right),\nu\lbrack k\rbrack \right),0 \leq k \leq n \right\} |
| 53 | </annotation> |
| 54 | </semantics> |
| 55 | </math> |
| 56 | </p> |
| 57 | </li> |
| 58 | <li> |
| 59 | <p>query position |
| 60 | <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"> |
| 61 | <semantics> |
| 62 | <mrow> |
| 63 | <mi>q</mi> |
| 64 | <mo>=</mo> |
| 65 | <mrow> |
| 66 | <mo stretchy="true" form="prefix">(</mo> |
| 67 | <mi>x</mi> |
| 68 | <mo>,</mo> |
| 69 | <mi>y</mi> |
| 70 | <mo stretchy="true" form="postfix">)</mo> |
| 71 | </mrow> |
| 72 | </mrow> |
| 73 | <annotation encoding="application/x-tex">q = (x,y)</annotation> |
| 74 | </semantics> |
| 75 | </math> |
| 76 | </p> |
| 77 | </li> |
| 78 | <li> |
| 79 | <p>search window |
| 80 | <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"> |
| 81 | <semantics> |
| 82 | <msub> |
| 83 | <mi>n</mi> |
| 84 | <mtext mathvariant="normal">search</mtext> |
| 85 | </msub> |
| 86 | <annotation encoding="application/x-tex">n_{\text{search}}</annotation> |
| 87 | </semantics> |
| 88 | </math> |
| 89 | (From <code>stylus_state_modeler_max_input_samples</code>), |
| 90 | </p> |
| 91 | </li> |
| 92 | </ul> |
| 93 | <p><br /> |
| 94 | <strong>initialize</strong> |
| 95 | <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"> |
| 96 | <semantics> |
| 97 | <mrow> |
| 98 | <mi>d</mi> |
| 99 | <mo>=</mo> |
| 100 | <mi>∞</mi> |
| 101 | </mrow> |
| 102 | <annotation encoding="application/x-tex">d = \infty</annotation> |
| 103 | </semantics> |
| 104 | </math>, |
| 105 | <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"> |
| 106 | <semantics> |
| 107 | <mrow> |
| 108 | <mtext mathvariant="normal">index</mtext> |
| 109 | <mo>=</mo> |
| 110 | <mtext mathvariant="normal">None</mtext> |
| 111 | </mrow> |
| 112 | <annotation encoding="application/x-tex">\text{index} = \text{None}</annotation> |
| 113 | </semantics> |
| 114 | </math>, |
| 115 | <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"> |
| 116 | <semantics> |
| 117 | <mrow> |
| 118 | <mrow> |
| 119 | <mtext mathvariant="normal">interp </mtext> |
| 120 | <mspace width="0.333em"></mspace> |
| 121 | </mrow> |
| 122 | <mo>=</mo> |
| 123 | <mrow> |
| 124 | <mspace width="0.333em"></mspace> |
| 125 | <mtext mathvariant="normal"> None</mtext> |
| 126 | </mrow> |
| 127 | </mrow> |
| 128 | <annotation encoding="application/x-tex">\text{interp } = \text{ None}</annotation> |
| 129 | </semantics> |
| 130 | </math><br /> |
| 131 | <strong>for</strong> |
| 132 | <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"> |
| 133 | <semantics> |
| 134 | <mrow> |
| 135 | <mi>i</mi> |
| 136 | <mo>=</mo> |
| 137 | <mi>n</mi> |
| 138 | <mo>−</mo> |
| 139 | <msub> |
| 140 | <mi>n</mi> |
| 141 | <mtext mathvariant="normal">search</mtext> |
| 142 | </msub> |
| 143 | </mrow> |
| 144 | <annotation encoding="application/x-tex">i = n - n_{\text{search}}</annotation> |
| 145 | </semantics> |
| 146 | </math> |
| 147 | to |
| 148 | <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"> |
| 149 | <semantics> |
| 150 | <mrow> |
| 151 | <mi>n</mi> |
| 152 | <mo>−</mo> |
| 153 | <mn>1</mn> |
| 154 | </mrow> |
| 155 | <annotation encoding="application/x-tex">n - 1</annotation> |
| 156 | </semantics> |
| 157 | </math> |
| 158 | <strong>do</strong><br /> |
| 159 | - <strong>Find</strong> |
| 160 | <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"> |
| 161 | <semantics> |
| 162 | <msub> |
| 163 | <mi>q</mi> |
| 164 | <mi>i</mi> |
| 165 | </msub> |
| 166 | <annotation encoding="application/x-tex">q_{i}</annotation> |
| 167 | </semantics> |
| 168 | </math> |
| 169 | the position that’s closest to |
| 170 | <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"> |
| 171 | <semantics> |
| 172 | <mi>q</mi> |
| 173 | <annotation encoding="application/x-tex">q</annotation> |
| 174 | </semantics> |
| 175 | </math> |
| 176 | on the segment |
| 177 | <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"> |
| 178 | <semantics> |
| 179 | <mrow> |
| 180 | <mo stretchy="true" form="prefix">[</mo> |
| 181 | <mi>p</mi> |
| 182 | <mo stretchy="false" form="prefix">[</mo> |
| 183 | <mi>i</mi> |
| 184 | <mo stretchy="false" form="postfix">]</mo> |
| 185 | <mo>,</mo> |
| 186 | <mi>p</mi> |
| 187 | <mo stretchy="false" form="prefix">[</mo> |
| 188 | <mi>i</mi> |
| 189 | <mo>+</mo> |
| 190 | <mn>1</mn> |
| 191 | <mo stretchy="false" form="postfix">]</mo> |
| 192 | <mo stretchy="true" form="postfix">]</mo> |
| 193 | </mrow> |
| 194 | <annotation encoding="application/x-tex">\left\lbrack p\lbrack i\rbrack,p\lbrack i + 1\rbrack \right\rbrack |
| 195 | </annotation> |
| 196 | </semantics> |
| 197 | </math> |
| 198 | and denote |
| 199 | <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"> |
| 200 | <semantics> |
| 201 | <mrow> |
| 202 | <mi>r</mi> |
| 203 | <mo>∈</mo> |
| 204 | <mo stretchy="false" form="prefix">[</mo> |
| 205 | <mn>0</mn> |
| 206 | <mo>,</mo> |
| 207 | <mn>1</mn> |
| 208 | <mo stretchy="false" form="postfix">]</mo> |
| 209 | </mrow> |
| 210 | <annotation encoding="application/x-tex">r \in \lbrack 0,1\rbrack</annotation> |
| 211 | </semantics> |
| 212 | </math> |
| 213 | the value such that |
| 214 | <math display="block" xmlns="http://www.w3.org/1998/Math/MathML"> |
| 215 | <semantics> |
| 216 | <mrow> |
| 217 | <msub> |
| 218 | <mi>q</mi> |
| 219 | <mi>i</mi> |
| 220 | </msub> |
| 221 | <mo>=</mo> |
| 222 | <mrow> |
| 223 | <mo stretchy="true" form="prefix">(</mo> |
| 224 | <mn>1</mn> |
| 225 | <mo>−</mo> |
| 226 | <mi>r</mi> |
| 227 | <mo stretchy="true" form="postfix">)</mo> |
| 228 | </mrow> |
| 229 | <mi>p</mi> |
| 230 | <mo stretchy="false" form="prefix">[</mo> |
| 231 | <mi>i</mi> |
| 232 | <mo stretchy="false" form="postfix">]</mo> |
| 233 | <mo>+</mo> |
| 234 | <mi>r</mi> |
| 235 | <mi>p</mi> |
| 236 | <mo stretchy="false" form="prefix">[</mo> |
| 237 | <mi>i</mi> |
| 238 | <mo>+</mo> |
| 239 | <mn>1</mn> |
| 240 | <mo stretchy="false" form="postfix">]</mo> |
| 241 | </mrow> |
| 242 | <annotation encoding="application/x-tex">q_{i} = (1 - r)p\lbrack i\rbrack + rp\lbrack i + 1\rbrack |
| 243 | </annotation> |
| 244 | </semantics> |
| 245 | </math><br /> |
| 246 | - <strong>if</strong> |
| 247 | <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"> |
| 248 | <semantics> |
| 249 | <mrow> |
| 250 | <mrow> |
| 251 | <mo>∥</mo> |
| 252 | <mrow> |
| 253 | <mi>q</mi> |
| 254 | <mo>−</mo> |
| 255 | <msub> |
| 256 | <mi>q</mi> |
| 257 | <mi>i</mi> |
| 258 | </msub> |
| 259 | </mrow> |
| 260 | </mrow> |
| 261 | <mo>∥</mo> |
| 262 | <mo><</mo> |
| 263 | <mi>d</mi> |
| 264 | </mrow> |
| 265 | <annotation encoding="application/x-tex">\left. \parallel{q - q_{i}} \right.\parallel < d</annotation> |
| 266 | </semantics> |
| 267 | </math><br /> |
| 268 | - |
| 269 | <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"> |
| 270 | <semantics> |
| 271 | <mtable> |
| 272 | <mtr> |
| 273 | <mtd columnalign="right" style="text-align: right"> |
| 274 | <mi>d</mi> |
| 275 | <mo>←</mo> |
| 276 | <mrow> |
| 277 | <mo>∥</mo> |
| 278 | <mrow> |
| 279 | <mi>q</mi> |
| 280 | <mo>−</mo> |
| 281 | <msub> |
| 282 | <mi>q</mi> |
| 283 | <mi>i</mi> |
| 284 | </msub> |
| 285 | </mrow> |
| 286 | </mrow> |
| 287 | <mo>∥</mo> |
| 288 | <mo><</mo> |
| 289 | <mi>d</mi> |
| 290 | </mtd> |
| 291 | </mtr> |
| 292 | <mtr> |
| 293 | <mtd columnalign="right" style="text-align: right"> |
| 294 | <mrow> |
| 295 | <mtext mathvariant="normal">index </mtext> |
| 296 | <mspace width="0.333em"></mspace> |
| 297 | </mrow> |
| 298 | <mo>=</mo> |
| 299 | <mi>i</mi> |
| 300 | </mtd> |
| 301 | </mtr> |
| 302 | <mtr> |
| 303 | <mtd columnalign="right" style="text-align: right"> |
| 304 | <mrow> |
| 305 | <mtext mathvariant="normal">interp </mtext> |
| 306 | <mspace width="0.333em"></mspace> |
| 307 | </mrow> |
| 308 | <mo>=</mo> |
| 309 | <mi>r</mi> |
| 310 | </mtd> |
| 311 | </mtr> |
| 312 | </mtable> |
| 313 | <annotation encoding="application/x-tex">\begin{array}{r} |
| 314 | d \leftarrow \left. \parallel{q - q_{i}} \right.\parallel < d \\ |
| 315 | \text{index } = i \\ |
| 316 | \text{interp } = r |
| 317 | \end{array}</annotation> |
| 318 | </semantics> |
| 319 | </math><br /> |
| 320 | - <strong>endif</strong><br /> |
| 321 | <strong>endfor</strong><br /> |
| 322 | <strong>calculate</strong> |
| 323 | <math display="block" xmlns="http://www.w3.org/1998/Math/MathML"> |
| 324 | <semantics> |
| 325 | <mrow> |
| 326 | <mi>ν</mi> |
| 327 | <mo>=</mo> |
| 328 | <mrow> |
| 329 | <mo stretchy="true" form="prefix">(</mo> |
| 330 | <mn>1</mn> |
| 331 | <mo>−</mo> |
| 332 | <mi>r</mi> |
| 333 | <mo stretchy="true" form="postfix">)</mo> |
| 334 | </mrow> |
| 335 | <mi>ν</mi> |
| 336 | <mrow> |
| 337 | <mo stretchy="true" form="prefix">[</mo> |
| 338 | <mtext mathvariant="normal">index</mtext> |
| 339 | <mo stretchy="true" form="postfix">]</mo> |
| 340 | </mrow> |
| 341 | <mo>+</mo> |
| 342 | <mi>r</mi> |
| 343 | <mi>ν</mi> |
| 344 | <mrow> |
| 345 | <mo stretchy="true" form="prefix">[</mo> |
| 346 | <mrow> |
| 347 | <mtext mathvariant="normal">index </mtext> |
| 348 | <mspace width="0.333em"></mspace> |
| 349 | </mrow> |
| 350 | <mo>+</mo> |
| 351 | <mn>1</mn> |
| 352 | <mo stretchy="true" form="postfix">]</mo> |
| 353 | </mrow> |
| 354 | </mrow> |
| 355 | <annotation encoding="application/x-tex">\nu = (1 - r)\nu\left\lbrack \text{index} \right\rbrack + |
| 356 | r\nu\left\lbrack \text{index } + 1 \right\rbrack</annotation> |
| 357 | </semantics> |
| 358 | </math><br /> |
| 359 | <strong>Output</strong> : interpolated pressure |
| 360 | <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"> |
| 361 | <semantics> |
| 362 | <mi>ν</mi> |
| 363 | <annotation encoding="application/x-tex">\nu</annotation> |
| 364 | </semantics> |
| 365 | </math> |
| 366 | </p> |