Пример #1
0
float FastCorner::shiTomasiScore_10(const ImageRef<unsigned char>& im, const Point2i& pos)
{
    const unsigned char* p3 = &(im.data())[(pos.y - 3) * im.width()];
    const unsigned char* p2 = &(im.data())[(pos.y - 2) * im.width()];
    const unsigned char* p1 = &(im.data())[(pos.y - 1) * im.width()];
    const unsigned char* s  = &(im.data())[pos.y * im.width()];
    const unsigned char* n1 = &(im.data())[(pos.y + 1) * im.width()];
    const unsigned char* n2 = &(im.data())[(pos.y + 2) * im.width()];
    const unsigned char* n3 = &(im.data())[(pos.y + 3) * im.width()];
    float Dxx = 0.0f;
    float Dxy = 0.0f;
    float Dyy = 0.0f;
    const int endx = pos.x + 3;
    for (int x = pos.x - 3; x<=endx; ++x) {
        float dx = (float)(p2[x+1] - p2[x-1]); float dy = (float)(p1[x] - p3[x]);
        Dxx += dx * dx; Dyy += dy * dy; Dxy += dx * dy;

        dx = (float)(p1[x+1] - p1[x-1]); dy = (float)(s[x] - p2[x]);
        Dxx += dx * dx; Dyy += dy * dy; Dxy += dx * dy;

        dx = (float)(s[x+1] - s[x-1]); dy = (float)(n1[x] - p1[x]);
        Dxx += dx * dx; Dyy += dy * dy; Dxy += dx * dy;

        dx = (float)(n1[x+1] - n1[x-1]); dy = (float)(n2[x] - s[x]);
        Dxx += dx * dx; Dyy += dy * dy; Dxy += dx * dy;

        dx = (float)(n2[x+1] - n2[x-1]); dy = (float)(n3[x] - n1[x]);
        Dxx += dx * dx; Dyy += dy * dy; Dxy += dx * dy;
    }

    const float sum_Dxx_Dyy = Dxx + Dyy;

    float r = 0.04f * 0.5f * (sum_Dxx_Dyy - std::sqrt(sum_Dxx_Dyy * sum_Dxx_Dyy - 4.0f * (Dxx * Dyy - Dxy * Dxy)));
    return r;
}
Пример #2
0
 void Scene::raytrace(CameraRef camera, Rect rect, RenderOption option, ImageRef image)
 {
     ASSERT(image->width() == rect.size.width && image->height() == rect.size.height);
     for (unsigned int y = 0; y < rect.size.height; y++) {
         for (unsigned int x = 0; x < rect.size.width; x++) {
             float xPos = (float)(x + rect.origin.x) / (float) camera->width() - 0.5f;
             float yPos = (float)(y + rect.origin.y) / (float) camera->height() - 0.5f;
             Ray viewRay = camera->viewRay(xPos, yPos);
             HitInfo hitInfo;
             Color color;
             
             if (traceRay(viewRay, option, 1.0f, 0, &color, &hitInfo)) {
                 image->setPixelColor(x, y, color);
             } else {
                 // set Background ccolor
                 //image->setPixelColor(x, y, hitInfo.material->color());
             }
             
         }
     }
 }