//#include <windows.h>

#include "vtkImageImport.h"
#include "vtkPiecewiseFunction.h"
#include "vtkColorTransferFunction.h"
#include "vtkVolumeProperty.h"
#include "vtkVolumeRayCastCompositeFunction.h"
#include "vtkVolumeRayCastMapper.h"
#include "vtkVolume.h"
#include "vtkLODProp3D.h"
#include "vtkSphereSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkProperty.h"
#include "vtkCamera.h"

void main ()
{
    // Create volume data
    unsigned char vol[100][50][50];
//    memset(vol, 120, 100*50*50);
    memset(vol, 0, 100*50*50);
    memset(vol, 200, 100*50*25);
    // Create an importer to read the data
    vtkImageImport* importer = vtkImageImport::New();
    importer->SetWholeExtent(0, 49, 0, 49, 0, 99);
    importer->SetDataExtentToWholeExtent();
    importer->SetDataScalarTypeToUnsignedChar();
    importer->SetImportVoidPointer((void*)vol);

    // Create transfer mapping scalar value to opacity
    vtkPiecewiseFunction* opacityTransferFunction = vtkPiecewiseFunction::New();
    opacityTransferFunction->AddPoint(0, 0.0);
    opacityTransferFunction->AddPoint(100, 0.0);
    opacityTransferFunction->AddPoint(129, 1.0);
    opacityTransferFunction->AddPoint(255, 1.0);
    // Create transfer mapping scalar value to color
    vtkColorTransferFunction* colorTransferFunction = vtkColorTransferFunction::New();
    colorTransferFunction->AddRGBPoint(0, 0.0, 0.0, 0.0);
    colorTransferFunction->AddRGBPoint(100, 0.0, 0.0, 0.0);
    colorTransferFunction->AddRGBPoint(129, 1.0, 0.0, 0.0);
    colorTransferFunction->AddRGBPoint(255, 1.0, 0.0, 0.0);

    // Property describes how the data will look
    vtkVolumeProperty *volumeProperty = vtkVolumeProperty::New();
    volumeProperty->SetColor(colorTransferFunction);
    volumeProperty->SetScalarOpacity(opacityTransferFunction);
    volumeProperty->SetInterpolationTypeToLinear();
    volumeProperty->ShadeOn();

    // Mapper/ray cast function for rendering the data
    vtkVolumeRayCastCompositeFunction *compositeFunction = vtkVolumeRayCastCompositeFunction::New();
    vtkVolumeRayCastMapper *volumeMapper = vtkVolumeRayCastMapper::New();
    volumeMapper->SetVolumeRayCastFunction(compositeFunction);
    volumeMapper->SetInput(importer->GetOutput());

    vtkVolume *volume = vtkVolume::New();
    volume->SetMapper(volumeMapper);
    volume->SetProperty(volumeProperty);

    // a renderer and render window
    vtkRenderer *ren1 = vtkRenderer::New();
    vtkRenderWindow *renWin = vtkRenderWindow::New();
    renWin->AddRenderer(ren1);

    // an interactor
    vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
    iren->SetRenderWindow(renWin);

    // add the actor to the scene
    ren1->AddViewProp(volume);
    ren1->SetBackground(1,1,1); // Background color white

    // render an image (lights and cameras are created automatically)
    renWin->Render();

//    Sleep(5000);
    memset(vol, 0, 100*50*50);
    memset(vol, 200, 100*50*20);
    renWin->Render();

    // begin mouse interaction
    iren->Start();
}

