Giter Site home page Giter Site logo

Comments (3)

InventorMentor avatar InventorMentor commented on May 24, 2024

Hello, the following code fixes this issue for me under Windows 10 using Python 3.6 [msvc14]. Maybe you could also test this reworked version of SoMarkerSet.i with Linux? Best wishes!

%extend SoMarkerSet {
    static void addMarker(int idx, const SbVec2s & size, PyObject* string, 
                        SbBool isLSBFirst = TRUE, SbBool isUpToDown = TRUE)
    {
        short WIDTH, HEIGHT;
        size.getValue(WIDTH, HEIGHT);
        short BYTEWIDTH = (WIDTH + 7) / 2;
        char* coin_marker;
#ifdef PY_2
        if (PyString_Check(string))
        {
            coin_marker = PyString_AsString(string);
        }
#else
        if (PyUnicode_Check(string))
        {
            coin_marker = PyUnicode_AsUTF8(string);            
        }
        else if (PyBytes_Check(string))
        {
            coin_marker = PyBytes_AsString(string);
        }
#endif
        else
        {
            return;
            // raise an attribute error: PyObject string should be of type bytes!
        }
        // https://grey.colorado.edu/coin3d/classSoMarkerSet.html
        // from addMarker example:

        int byteidx = 0;
        unsigned char* bitmapbytes = NULL;
        bitmapbytes = new unsigned char[BYTEWIDTH * HEIGHT];
        
        for (int h = 0; h < HEIGHT; h++)
        {
            unsigned char bits = 0;
            for (int w = 0; w < WIDTH; w++)
            {
                if (coin_marker[(h * WIDTH) + w] != ' ') { bits |= (0x80 >> (w % 8)); }
                if ((((w + 1) % 8) == 0) || (w == WIDTH - 1)) {
                bitmapbytes[byteidx++] = bits;
                bits = 0;
                }
            }
        }
        SoMarkerSet::addMarker(idx, size, bitmapbytes, isLSBFirst, isUpToDown);
        delete[] bitmapbytes;
        bitmapbytes = NULL;
    }
}

from pivy.

looooo avatar looooo commented on May 24, 2024

wow, thanks! I spend hours on this problem...

from pivy.

looooo avatar looooo commented on May 24, 2024

looooo@4102e36

from pivy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.