2006年05月29日

是一个开源的、高效的2D图形库,它的网站:http://www.antigrain.com/

AGG的功能与GDI+的功能非常类似,但提供了比GDI+更灵活的编程接口,其产生的图形的质量也非常高,而且它是跨平台的,其宣传可以在非常多的操作系统上运行。

功能:

  • Rendering of arbitrary polygons with Anti-Aliasing and Subpixel Accuracy.
  • Gradients and Gouraud Shading.
  • Fast filtered image affine transformations, including many interpolation filters (bilinear, bicubic, spline16, spline36, sinc, Blackman).
  • Strokes with different types of line joins and line caps.
  • Dashed line generator.
  • Markers, such as arrowheads/arrowtails.
  • Fast vectorial polygon clipping to a rectangle.
  • Low-level clipping to multiple rectangular regions.
  • Alpha-Masking.
  • A new, fast Anti-Alias line algorithm.
  • Using arbitrary images as line patterns.
  • Rendering in separate color channels.
  • Perspective and bilinear transformations of vector and image data.
  • Boolean polygon operations (and, or, xor, sub) based on Alan Murta’s
    General Polygon Clipper.
  • 2006年05月15日

    基于fox1.6.4,按照fox的邮件列表一位日本朋友的方法(http://sourceforge.net/mailarchive/message.php?msg_id=15420326)修改源码编译后就能输入中文了,他上面讲得很清楚。

    不过他只修改了FXText类,我自己又修改了FXTextField类,只需在FXMAPFUNC(SEL_QUERY_HELP,0,FXTextField::onQueryHelp),这行后面添加FXMAPFUNC(SEL_IME_TEXT,0,FXTextField::onCmdInsertString),这行就行。

    一共修改了五个文件,可以到下面地址下载修改过的文件。

    http://www.flmnware.com/community/viewtopic.php?t=227

    2006年05月12日

    很早就听说你,试了一下感觉也不错,轻量级适合我的口味,可是,可是,你怎么不支持输入法啊?

    看你开发进度这么快,什么时候才能添加输入法支持啊?

    http://www.fox-toolkit.org/

    2005年11月24日

    Problem Statement
        
    When editing a single line of text, there are four keys that can be used to move the cursor: end, home, left-arrow and right-arrow. As you would expect, left-arrow and right-arrow move the cursor one character left or one character right, unless the cursor is at the beginning of the line or the end of the line, respectively, in which case the keystrokes do nothing (the cursor does not wrap to the previous or next line). The home key moves the cursor to the beginning of the line, and the end key moves the cursor to the end of the line.  You will be given a int, N, representing the number of character in a line of text. The cursor is always between two adjacent characters, at the beginning of the line, or at the end of the line. It starts before the first character, at position 0. The position after the last character on the line is position N. You should simulate a series of keystrokes and return the final position of the cursor. You will be given a string where characters of the string represent the keystrokes made, in order. ‘L’ and ‘R’ represent left and right, while ‘H’ and ‘E’ represent home and end.
    Definition
        
    Class:
    CursorPosition
    Method:
    getPosition
    Parameters:
    string, int
    Returns:
    int
    Method signature:
    int getPosition(string keystrokes, int N)
    (be sure your method is public)
        

    Constraints
    -
    keystrokes will be contain between 1 and 50 ‘L’, ‘R’, ‘H’, and ‘E’ characters, inclusive.
    -
    N will be between 1 and 100, inclusive.
    Examples
    0)

        
    "ERLLL"
    10
    Returns: 7
    First, we go to the end of the line at position 10. Then, the right-arrow does nothing because we are already at the end of the line. Finally, three left-arrows brings us to position 7.
    1)

        
    "EHHEEHLLLLRRRRRR"
    2
    Returns: 2
    All the right-arrows at the end ensure that we end up at the end of the line.
    2)

        
    "ELLLELLRRRRLRLRLLLRLLLRLLLLRLLRRRL"
    10
    Returns: 3

    3)

        
    "RRLEERLLLLRLLRLRRRLRLRLRLRLLLLL"
    19
    Returns: 12

    This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.

    我的程序:

    #include <string>
    #include <iostream>

    using namespace std;

    class CursorPosition
    {
    public:
     int getPosition(string keystrokes, int N)
     {
      int result = 0;
      size_t len = keystrokes.length();
      if (len>50 || N<1 || N>100)
      {
       return result;
      }
      for (unsigned int i=0; i<len; ++i)
      {
       switch(keystrokes.at(i))
       {
       case ‘L’:
        result = result==0 ? 0 : result-1;
        break;
       case ‘R’:
        result = result==N ? N : result+1;
        break;
       case ‘H’:
        result = 0;
        break;
       case ‘E’:
        result = N;
        break;
       }
      }
      return result;
     }
    };

    Problem Statement
        
    A square matrix is a grid of NxN numbers. For example, the following is a 3×3 matrix:
     4 3 5
     2 4 5
     0 1 9
    One way to represent a matrix of numbers, each of which is between 0 and 9 inclusive, is as a row-major string. To generate the string, simply concatenate all of the elements from the first row followed by the second row and so on, without any spaces. For example, the above matrix would be represented as "435245019".  You will be given a square matrix as a row-major string. Your task is to convert it into a vector <string>, where each element represents one row of the original matrix. Element i of the vector <string> represents row i of the matrix. You should not include any spaces in your return. Hence, for the above string, you would return {"435","245","019"}. If the input does not represent a square matrix because the number of characters is not a perfect square, return an empty vector <string>, {}.
    Definition
        
    Class:
    MatrixTool
    Method:
    convert
    Parameters:
    string
    Returns:
    vector <string>
    Method signature:
    vector <string> convert(string s)
    (be sure your method is public)
        

    Constraints
    -
    s will contain between 1 and 50 digits, inclusive.
    Examples
    0)

        
    "435245019"
    Returns: {"435", "245", "019" }
    The example above.
    1)

        
    "9"
    Returns: {"9" }

    2)

        
    "0123456789"
    Returns: { }
    This input has 10 digits, and 10 is not a perfect square.
    3)

        
    "3357002966366183191503444273807479559869883303524"
    Returns: {"3357002", "9663661", "8319150", "3444273", "8074795", "5986988", "3303524" }

    This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.

    我的程序:

    #include <algorithm>
    #include <string>
    #include <vector>
    #include <iostream>

    using namespace std;

    class MatrixTool
    {
    public:
     vector<string > convert(string s)
     {
      int sqt[7] = {1, 4, 9, 16, 25, 36, 49};
      vector<string > result;
      int* p = find(sqt, sqt + 7, s.length());
      if (p != sqt + 7)
      {
       unsigned int n = (unsigned int)(p – sqt) + 1;
       size_t len = s.length();
       for (unsigned int i=0; i<len; i+=n)
       {
        result.push_back(s.substr(i, n));
       }
      }
      return result;
     }
    };

    Problem Statement
        
    A simple line drawing program uses a blank 20 x 20 pixel canvas and a directional cursor that starts at the upper left corner pointing straight down. The upper left corner of the canvas is at (0, 0) and the lower right corner is at (19, 19). You are given a vector <string>, commands, each element of which contains one of two possible commands. A command of the form "FORWARD x" means that the cursor should move forward by x pixels. Each pixel on its path, including the start and end points, is painted black. The only other command is "LEFT", which means that the cursor should change its direction by 90 degrees counterclockwise. So, if the cursor is initially pointing straight down and it receives a single "LEFT" command, it will end up pointing straight to the right. Execute all the commands in order and return the resulting 20 x 20 pixel canvas as a vector <string> where character j of element i represents the pixel at (i, j). Black pixels should be represented as uppercase ‘X’ characters and blank pixels should be represented as ‘.’ characters.
    Definition
        
    Class:
    DrawLines
    Method:
    execute
    Parameters:
    vector <string>
    Returns:
    vector <string>
    Method signature:
    vector <string> execute(vector <string> commands)
    (be sure your method is public)
        

    Notes
    -
    The cursor only paints the canvas if it moves (see example 1).
    Constraints
    -
    commands will contain between 1 and 50 elements, inclusive.
    -
    Each element of commands will be formatted as either "LEFT" or "FORWARD x" (quotes for clarity only), where x is an integer between 1 and 19, inclusive, with no extra leading zeros.
    -
    When executing the commands in order, the cursor will never leave the 20 x 20 pixel canvas.
    Examples
    0)

        
    {"FORWARD 19", "LEFT", "FORWARD 19", "LEFT", "FORWARD 19", "LEFT", "FORWARD 19"}
    Returns:
    {"XXXXXXXXXXXXXXXXXXXX",
     "X………………X",
     "X………………X",
     "X………………X",
     "X………………X",
     "X………………X",
     "X………………X",
     "X………………X",
     "X………………X",
     "X………………X",
     "X………………X",
     "X………………X",
     "X………………X",
     "X………………X",
     "X………………X",
     "X………………X",
     "X………………X",
     "X………………X",
     "X………………X",
     "XXXXXXXXXXXXXXXXXXXX" }
    This sequence of commands draws a 20 x 20 outline of a square. The cursor is initially at (0, 0) pointing straight down. It then travels to (0, 19) after the first FORWARD command, painting each pixel along its path with a ‘*’. It then rotates 90 degrees left, travels to (19, 19), rotates 90 degrees left, travels to (19, 0), rotates 90 degrees left, and finally travels back to (0, 0).
    1)

        
    {"LEFT", "LEFT", "LEFT", "LEFT", "LEFT", "LEFT", "LEFT", "LEFT"}
    Returns:
    {"………………..",
     "………………..",
     "………………..",
     "………………..",
     "………………..",
     "………………..",
     "………………..",
     "………………..",
     "………………..",
     "………………..",
     "………………..",
     "………………..",
     "………………..",
     "………………..",
     "………………..",
     "………………..",
     "………………..",
     "………………..",
     "………………..",
     "……………….." }
    The cursor spins round and round, but never actually paints any pixels. The result is an empty canvas.
    2)

        
    {"FORWARD 1"}
    Returns:
    {"X……………….",
     "X……………….",
     "………………..",
     "………………..",
     "………………..",
     "………………..",
     "………………..",
     "………………..",
     "………………..",
     "………………..",
     "………………..",
     "………………..",
     "………………..",
     "………………..",
     "………………..",
     "………………..",
     "………………..",
     "………………..",
     "………………..",
     "……………….." }
    Going forward by one pixel creates a line that is 2 pixels long because both the start and end points are painted.
    3)

        
    {"LEFT", "FORWARD 19", "LEFT", "LEFT", "LEFT",
     "FORWARD 18", "LEFT", "LEFT", "LEFT", "FORWARD 17",
     "LEFT", "LEFT", "LEFT", "FORWARD 16", "LEFT",
     "LEFT", "LEFT", "FORWARD 15", "LEFT", "LEFT", "LEFT",
     "FORWARD 14", "LEFT", "LEFT", "LEFT", "FORWARD 13",
     "LEFT", "LEFT", "LEFT", "FORWARD 12", "LEFT", "LEFT",
     "LEFT", "FORWARD 11", "LEFT", "LEFT", "LEFT", "FORWARD 10",
     "LEFT", "LEFT", "LEFT", "FORWARD 9", "LEFT", "LEFT",
     "LEFT", "FORWARD 8", "LEFT", "LEFT", "LEFT", "FORWARD 7"}
    Returns:
    {"XXXXXXXXXXXXXXXXXXXX",
     "……………….X",
     "..XXXXXXXXXXXXXXXX.X",
     "..X…………..X.X",
     "..X.XXXXXXXXXXXX.X.X",
     "..X.X……….X.X.X",
     "..X.X.XXXXXXXX.X.X.X",
     "..X.X.X……..X.X.X",
     "..X.X.X……..X.X.X",
     "..X.X.X……..X.X.X",
     "..X.X.X……..X.X.X",
     "..X.X.X……..X.X.X",
     "..X.X.X……..X.X.X",
     "..X.X.X……..X.X.X",
     "..X.X.XXXXXXXXXX.X.X",
     "..X.X…………X.X",
     "..X.XXXXXXXXXXXXXX.X",
     "..X…………….X",
     "..XXXXXXXXXXXXXXXXXX",
     "……………….." }

     
    This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.

    我的程序:

    #include <string>
    #include <vector>
    #include <iostream>

    using namespace std;

    class DrawLines
    {
    public:
     vector<string > execute(vector<string > commands)
     {
      vector<string > result;
      _init();
      vector<string >::iterator it = commands.begin();
      while (it != commands.end())
      {
       if (‘L’ == it->at(0))
       {
        ++_dir;
        if (_dir > LEFT)
        {
         _dir = DOWN;
        }
       }
       else if (‘F’ == it->at(0))
       {
        size_t p = it->find(‘ ‘, 0);
        unsigned int step = atoi(it->substr(p, it->size()-p).c_str());
        _line(step);
       }
       ++it;
      }
      for (unsigned int i=0; i<SIZE; ++i)
      {
       result.push_back(string(&_buff[i*SIZE], &_buff[(i+1)*SIZE]));
      }
      return result;
     }
    private:
     enum
     {
      DOWN,
      RIGHT,
      UP,
      LEFT
     };

     enum
     {
      SIZE = 20
     };

     void _init(void)
     {
      _x = 0;
      _y = 0;
      _dir = DOWN;
      for (unsigned int i=0; i<SIZE*SIZE; ++i)
      {
       _buff[i] = ‘.’;
      }
     }

     void _line(unsigned int step)
     {
      switch(_dir)
      {
      case DOWN:
       for (unsigned int i=0; i<step; ++i)
       {
        _buff[_x+_y*SIZE] = ‘X’;
        ++_y;
       }
       break;
      case RIGHT:
       for (unsigned int i=0; i<step; ++i)
       {
        _buff[_x+_y*SIZE] = ‘X’;
        ++_x;
       }
       break;
      case UP:
       for (unsigned int i=0; i<step; ++i)
       {
        _buff[_x+_y*SIZE] = ‘X’;
        –_y;
       }
       break;
      case LEFT:
       for (unsigned int i=0; i<step; ++i)
       {
        _buff[_x+_y*SIZE] = ‘X’;
        –_x;
       }
       break;
      }
      _buff[_x+_y*SIZE] = ‘X’;
     }

     unsigned int _x;
     unsigned int _y;
     unsigned int _dir;
     char   _buff[SIZE*SIZE];
    };

    2005年07月25日

    不一定。

    看这个程序
    .h
    class C
    {
    public:
         void setNumber(int num);
    private:
         static int s_Number;
    };

    .cpp
    int C::s_Number;
    void C::setNumber(int num)
    {
        s_Number = num;
    }

    main.cpp
    C* pC;
    pC->setNumber(100);

    上面这句会执行正常,完全没错。

    这个未初始化的指针为什么不会出错呢?是因为类C的成员函数setNumber中只访问了类C的静态变量,也就是说,他没有用到this这个隐含参数,所以虽然pC是一个不知道什么值的值,但是他被传进setNumber并没有被利用,所以不会出错。出错是由于访问非静态变量,是通过this->变量名访问的,一个未初始化的指针必然引起访问冲突。

    写这个不是说可以那样用,是强调this这个指针变量。

    2005年06月03日

    今天从OSG库里继承了一个Drawable,需要覆盖它的drawImplementation,但是drawImplementation是个const方法,我要在里面更新我的模型,上网查了以下资料,发现两个方法可以实现我的要求:
    1。使用关键字mutable修饰要在const方法里修改的变量,相关理论网上很多;
    2。将要改变的变量声明成指针,在构造函数里new一下,然后记得delete就行了,指针变量本身不能修改,但它指向的内容还是可以修改的。

    因为我需要的是一个巨大数组,所以第二种方法正好符合我的需要。