Example #1
0
void printCross(BMP &bitmap, int x, int y, int r, int g, int b) {
	const int shiftX[5] = {0, 0, 0, 1, -1};
	const int shiftY[5] = {0, 1, -1, 0, 0};
	for (int i = 0; i < 5; i++) {
		int currX = std::min(512, std::max(x + shiftX[i], 0));
		int currY = std::min(512, std::max(y + shiftY[i], 0));

		setPixelValue(bitmap, currX, currY, r, g, b);
	}
}
Example #2
0
int main(int argc, char *argv[]) {
    Uint32 *screen; //This pointer will reference the backbuffer 
    screen = InitVideo(SCREEN_WIDTH, SCREEN_HEIGH);
    if (screen == nullptr) exit(SCREEN_INIT_ERROR);

    LightRay camera_ray(Position(0, 0, -3), Direction(0, 0, 1));
    World world;

    Sphere* mov = new Sphere(Position(3, 3, 10), 5, Material::glass());
    world.elements.push_back(mov);
    world.elements.push_back(new Sphere(Position(-3, 3, 10), 5, Material::RedPlastic()));
    world.elements.push_back(new Sphere(Position(-3, -3, 10), 4, Material::silver()));
    world.elements.push_back(new Plane());

    while (1) {

        SDL_Event event;
        while (SDL_PollEvent(&event)) {
            if (event.type == SDL_MOUSEMOTION) {
                world.globalLight.direction[0] += 0.01f * (event.motion.xrel);
                world.globalLight.direction[1] += 0.01f * (event.motion.yrel);
            }
            if (event.type == SDL_KEYDOWN) {
                exit(RETURN_OK);
            }
            if (event.type == SDL_QUIT) {
                exit(RETURN_OK);
            }
        }

        Uint32 t1 = SDL_GetTicks();
        mov->translate(Direction(0.f, 0.f, 0.1f * (1 - 2 * (((int) (t1 / 2000.0f)) % 2))));

        for (int x = 0; x < SCREEN_WIDTH; x++) for (int y = 0; y < SCREEN_HEIGH; y++) {
                screenPixelDirection(camera_ray.direction, static_cast<float> (x), static_cast<float> (y));
                Light value = world.rayTracing(camera_ray, nullptr);
                setPixelValue(screen, x, y, lightToPixel(value));
        }

        showImage(screen);
        printf("time: %1ums\n", SDL_GetTicks() - t1);
    }

    freeRenderer(screen);
    return RETURN_OK;
}
Example #3
0
    /**
     * @brief conv2d methods defines a convolution operations
     * @param _input
     * @param _kernel
     * @param dst
     */
    void conv2d(Mat _input,Mat _kernel,Mat &_out)
    {
            _image_height=_input.rows;
            _image_width =_input.cols;
            _kernel_height=_kernel.rows;
            _kernel_width=_kernel.cols;
            _image_channels=_input.channels ();
            _kernel_channels=_kernel.channels ();

            //dst.create (_image_height,_image_width,_input.type ());

            for(int y=0;y<_image_height;y++)
            {

            for(int x=0;x<_image_width;x++)
            {


                //performs computation for pixels in the valid range
                Point p=Point(x,y);

                //local variable used  to store convolution sum
                float value=0;
                //loop over the rows of the pixel neighborhood
                //loop over the columns of the pixels neighborhood
                for(int i=0;i<_kernel_height;i++)
                for(int j=0;j<_kernel_width;j++)
                {
                    Point pixel=Point(y+i-(_kernel_height/2),(x+j-(_kernel_width/2)));
                    //condition defines pixels lying within the image borders
                    bool flag=checkPixel (pixel);
                    if(flag==true)
                    {
                    T val=getPixelValue(_input,pixel);
                    value=value+val;
                    }
                   }

                //setting the result in the destination matrix
                setPixelValue (_out,Point(x,y),value);
            }


            }

            }