[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2. Example programs

Before anything else, let's look at some VXL example programs.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.0.1 Hello world

Here's one to print "Hello world":

 
// Include standard C++ input/output library
#include <vcl_iostream.h>

// main is the first function to be called
int main()
{
  // send string "hello world" to the standard
  // output stream cout.
  vcl_cout << "Hello world\n";

  // Must return something from main
  return 0;
}

This is the same example that one might see in any C++ book, but for the include line at the start. C++ books assume that your C++ compiler works, which is not true of any C++ compiler in the year 2000. Chapter 3 goes into more detail, but for the moment, include standard headers such as <cstdio> using <vcl_cstdio.h>.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.0.2 Loading an image

Because most vxl programs use images in some form, here's an example of loading an image, and printing the pixel value at (100,100). It assumes the image is greyscale, and does no error checking.

 
#include <vcl_iostream.h>
#include <vxl_config.h>
#include <vil/vil_rgb.h>
#include <vil/vil_load.h>
#include <vil/vil_image_view.h>

int main()
{
  // Load image into memory.
  vil_image_view<vil_rgb<vxl_byte> > img = vil_load("foo.ppm");

  // Access pixel (100,100) and print its value as an int.
  vcl_cerr << "Pixel 100,100 = " << img(100,100) << vcl_endl;

  return 0;
}

[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated on May, 1 2013 using texi2html 1.76.