id/whycon_id_gen.cpp
// Draw the encded ID into WhyCon marker
Draw the encded ID into WhyCon marker
Draw the encded ID into WhyCon marker
void draw_whycode_markers(int id, int idx, const int teethCount)
{
    list<Drawable> drawList;
    list<Coordinate> coordsList;
    if(verbose) printf("Generating WhyCode Canvas for Id %d (encoding %d)\n", idx, id);
    Image image = whycode_sceleton;
    if(verbose) printf("Converting ID to binary\n");
    string s = bitset<32>(id).to_string();
    drawList.push_back(DrawableStrokeWidth(0));
    drawList.push_back(DrawableFillColor("black"));
    double x1, y1, x2, y2;
    for(int i = 0; i < teethCount; i++)
    {
        x1 = xc + 650 * cos(-w * (2 * i + (s.at(i + 32 - teethCount) - '0') * 2.0) / 180.0 * M_PI);
        y1 = yc + 650 * sin(-w * (2 * i + (s.at(i + 32 - teethCount) - '0') * 2.0) / 180.0 * M_PI);
        x2 = xc + 650 * cos(-w * (2 * i + 1) / 180.0 * M_PI);
        y2 = yc + 650 * sin(-w * (2 * i + 1) / 180.0 * M_PI);
        list<Coordinate> coordsList;
        coordsList.push_back(Coordinate(xc, yc));
        coordsList.push_back(Coordinate(x1, y1));
        coordsList.push_back(Coordinate(x2, y2));
        if(verbose) printf("Drawing Segment Size: %f %f %f %f\n", x1 ,y1 ,x2, y2);
        drawList.push_back(DrawablePolygon(coordsList));
        coordsList.clear();
    }
    image.draw(drawList);
    drawList.clear();
    printf("Rendering final image: %d (encoding %d)  =>  %08d.png\n", idx, id, idx);
    drawList.push_back(DrawableStrokeWidth(0));
    drawList.push_back(DrawableFillColor("white"));
    drawList.push_back(DrawableEllipse(xc, yc, 240, 240, 0, 360));
    image.draw(drawList);
    drawList.clear();
    char infoText[13];
    sprintf(infoText, "ID: %d", idx);
    drawList.push_back(DrawableText(1550, 130, infoText));
    drawList.push_back(DrawablePointSize(14));
    image.draw(drawList);
    drawList.clear();
    char fname[13];
    sprintf(fname, "%08d.png", idx);
    image.magick("PNG");
    image.write(fname);
}
void draw_whycode_markers ( int id , int idx , const int teethCount ) { list < Drawable > drawList ; list < Coordinate > coordsList ; if ( verbose ) printf ( " \n " , idx , id ) ; Image image = whycode_sceleton ; if ( verbose ) printf ( " \n " ) ; string s = bitset < 32 > ( id ) . to_string ( ) ; drawList . push_back ( DrawableStrokeWidth ( 0 ) ) ; drawList . push_back ( DrawableFillColor ( " " ) ) ; double x1 , y1 , x2 , y2 ; for ( int i = 0 ; i < teethCount ; i ++ ) { x1 = xc + 650 * cos ( - w * ( 2 * i + ( s . at ( i + 32 - teethCount ) - ' ' ) * 2.0 ) / 180.0 * M_PI ) ; y1 = yc + 650 * sin ( - w * ( 2 * i + ( s . at ( i + 32 - teethCount ) - ' ' ) * 2.0 ) / 180.0 * M_PI ) ; x2 = xc + 650 * cos ( - w * ( 2 * i + 1 ) / 180.0 * M_PI ) ; y2 = yc + 650 * sin ( - w * ( 2 * i + 1 ) / 180.0 * M_PI ) ; list < Coordinate > coordsList ; coordsList . push_back ( Coordinate ( xc , yc ) ) ; coordsList . push_back ( Coordinate ( x1 , y1 ) ) ; coordsList . push_back ( Coordinate ( x2 , y2 ) ) ; if ( verbose ) printf ( " \n " , x1 , y1 , x2 , y2 ) ; drawList . push_back ( DrawablePolygon ( coordsList ) ) ; coordsList . clear ( ) ; } image . draw ( drawList ) ; drawList . clear ( ) ; printf ( " \n " , idx , id , idx ) ; drawList . push_back ( DrawableStrokeWidth ( 0 ) ) ; drawList . push_back ( DrawableFillColor ( " " ) ) ; drawList . push_back ( DrawableEllipse ( xc , yc , 240 , 240 , 0 , 360 ) ) ; image . draw ( drawList ) ; drawList . clear ( ) ; char infoText [ 13 ] ; sprintf ( infoText , " " , idx ) ; drawList . push_back ( DrawableText ( 1550 , 130 , infoText ) ) ; drawList . push_back ( DrawablePointSize ( 14 ) ) ; image . draw ( drawList ) ; drawList . clear ( ) ; char fname [ 13 ] ; sprintf ( fname , " " , idx ) ; image . magick ( " " ) ; image . write ( fname ) ; }
Draw the encded ID into WhyCon marker
Draw the encded ID into WhyCon marker
// Convert lowest bit shift to binary // For each encoding bit // Calculate the pixel positions of each segment // Draw each of the segments onto the original WhyCon marker // Draw a final white circle in the centre to complete the marker