Advertisement
gavinwheeler99

VTK Scenelight vs Headlight, CPU vs GPU

Aug 5th, 2019
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 19.07 KB | None | 0 0
  1. /*=========================================================================
  2.  
  3.   Program:   Visualization Toolkit
  4.   Module:    GPURenderDemo.cxx
  5.  
  6.   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  7.   All rights reserved.
  8.   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
  9.  
  10.      This software is distributed WITHOUT ANY WARRANTY; without even
  11.      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12.      PURPOSE.  See the above copyright notice for more information.
  13.  
  14. =========================================================================*/
  15. // VTK includes
  16. #include "vtkBoxWidget.h"
  17. #include "vtkCamera.h"
  18. #include "vtkCommand.h"
  19. #include "vtkColorTransferFunction.h"
  20. #include "vtkDICOMImageReader.h"
  21. #include "vtkImageData.h"
  22. #include "vtkImageResample.h"
  23. #include "vtkMetaImageReader.h"
  24. #include "vtkPiecewiseFunction.h"
  25. #include "vtkPlanes.h"
  26. #include "vtkProperty.h"
  27. #include "vtkRenderer.h"
  28. #include "vtkRenderWindow.h"
  29. #include "vtkRenderWindowInteractor.h"
  30. #include "vtkVolume.h"
  31. #include "vtkVolumeProperty.h"
  32. #include "vtkXMLImageDataReader.h"
  33. #include "vtkSmartVolumeMapper.h"
  34.  
  35. #include "vtkLight.h"
  36. #include "vtkLightCollection.h"
  37.  
  38. #include <array>
  39.  
  40. #define VTI_FILETYPE 1
  41. #define MHA_FILETYPE 2
  42.  
  43. // Callback for moving the planes from the box widget to the mapper
  44. class vtkBoxWidgetCallback : public vtkCommand
  45. {
  46. public:
  47.   static vtkBoxWidgetCallback *New()
  48.     { return new vtkBoxWidgetCallback; }
  49.   void Execute(vtkObject *caller, unsigned long, void*) override
  50.   {
  51.       vtkBoxWidget *widget = reinterpret_cast<vtkBoxWidget*>(caller);
  52.       if (this->Mapper)
  53.       {
  54.         vtkPlanes *planes = vtkPlanes::New();
  55.         widget->GetPlanes(planes);
  56.         this->Mapper->SetClippingPlanes(planes);
  57.         planes->Delete();
  58.       }
  59.   }
  60.   void SetMapper(vtkSmartVolumeMapper* m)
  61.     { this->Mapper = m; }
  62.  
  63. protected:
  64.   vtkBoxWidgetCallback()
  65.     { this->Mapper = nullptr; }
  66.  
  67.   vtkSmartVolumeMapper *Mapper;
  68. };
  69.  
  70. void PrintUsage()
  71. {
  72.   cout << "Usage: " << endl;
  73.   cout << endl;
  74.   cout << "  GPURenderDemo <options>" << endl;
  75.   cout << endl;
  76.   cout << "where options may include: " << endl;
  77.   cout << endl;
  78.   cout << "  -DICOM <directory>" << endl;
  79.   cout << "  -VTI <filename>" << endl;
  80.   cout << "  -MHA <filename>" << endl;
  81.   cout << "  -DependentComponents" << endl;
  82.   cout << "  -Clip" << endl;
  83.   cout << "  -MIP <window> <level>" << endl;
  84.   cout << "  -CompositeRamp <window> <level>" << endl;
  85.   cout << "  -CompositeShadeRamp <window> <level>" << endl;
  86.   cout << "  -CT_Skin" << endl;
  87.   cout << "  -CT_Bone" << endl;
  88.   cout << "  -CT_Muscle" << endl;
  89.   cout << "  -FrameRate <rate>" << endl;
  90.   cout << "  -DataReduction <factor>" << endl;
  91.   cout << endl;
  92.   cout << "You must use either the -DICOM option to specify the directory where" << endl;
  93.   cout << "the data is located or the -VTI or -MHA option to specify the path of a .vti file." << endl;
  94.   cout << endl;
  95.   cout << "By default, the program assumes that the file has independent components," << endl;
  96.   cout << "use -DependentComponents to specify that the file has dependent components." << endl;
  97.   cout << endl;
  98.   cout << "Use the -Clip option to display a cube widget for clipping the volume." << endl;
  99.   cout << "Use the -FrameRate option with a desired frame rate (in frames per second)" << endl;
  100.   cout << "which will control the interactive rendering rate." << endl;
  101.   cout << "Use the -DataReduction option with a reduction factor (greater than zero and" << endl;
  102.   cout << "less than one) to reduce the data before rendering." << endl;
  103.   cout << "Use one of the remaining options to specify the blend function" << endl;
  104.   cout << "and transfer functions. The -MIP option utilizes a maximum intensity" << endl;
  105.   cout << "projection method, while the others utilize compositing. The" << endl;
  106.   cout << "-CompositeRamp option is unshaded compositing, while the other" << endl;
  107.   cout << "compositing options employ shading." << endl;
  108.   cout << endl;
  109.   cout << "Note: MIP, CompositeRamp, CompositeShadeRamp, CT_Skin, CT_Bone," << endl;
  110.   cout << "and CT_Muscle are appropriate for DICOM data. MIP, CompositeRamp," << endl;
  111.   cout << "and RGB_Composite are appropriate for RGB data." << endl;
  112.   cout << endl;
  113.   cout << "Example: GPURenderDemo -DICOM CTNeck -MIP 4096 1024" << endl;
  114.   cout << endl;
  115. }
  116.  
  117. int main(int argc, char *argv[])
  118. {
  119.   // Parse the parameters
  120.  
  121.   int count = 1;
  122.   char *dirname = nullptr;
  123.   double opacityWindow = 4096;
  124.   double opacityLevel = 2048;
  125.   int blendType = 0;
  126.   int clip = 0;
  127.   double reductionFactor = 1.0;
  128.   double frameRate = 10.0;
  129.   char *fileName=nullptr;
  130.   int fileType=0;
  131.  
  132.   bool independentComponents=true;
  133.  
  134.   while ( count < argc )
  135.   {
  136.     if ( !strcmp( argv[count], "?" ) )
  137.     {
  138.       PrintUsage();
  139.       exit(EXIT_SUCCESS);
  140.     }
  141.     else if ( !strcmp( argv[count], "-DICOM" ) )
  142.     {
  143.       size_t size = strlen(argv[count+1])+1;
  144.       dirname = new char[size];
  145.       snprintf( dirname, size, "%s", argv[count+1] );
  146.       count += 2;
  147.     }
  148.     else if ( !strcmp( argv[count], "-VTI" ) )
  149.     {
  150.       size_t size = strlen(argv[count+1])+1;
  151.       fileName = new char[size];
  152.       fileType = VTI_FILETYPE;
  153.       snprintf( fileName, size, "%s", argv[count+1] );
  154.       count += 2;
  155.     }
  156.     else if ( !strcmp( argv[count], "-MHA" ) )
  157.     {
  158.       size_t size = strlen(argv[count+1])+1;
  159.       fileName = new char[size];
  160.       fileType = MHA_FILETYPE;
  161.       snprintf( fileName, size, "%s", argv[count+1] );
  162.       count += 2;
  163.     }
  164.     else if ( !strcmp( argv[count], "-Clip") )
  165.     {
  166.       clip = 1;
  167.       count++;
  168.     }
  169.     else if ( !strcmp( argv[count], "-MIP" ) )
  170.     {
  171.       opacityWindow = atof( argv[count+1] );
  172.       opacityLevel  = atof( argv[count+2] );
  173.       blendType = 0;
  174.       count += 3;
  175.     }
  176.     else if ( !strcmp( argv[count], "-CompositeRamp" ) )
  177.     {
  178.       opacityWindow = atof( argv[count+1] );
  179.       opacityLevel  = atof( argv[count+2] );
  180.       blendType = 1;
  181.       count += 3;
  182.     }
  183.     else if ( !strcmp( argv[count], "-CompositeShadeRamp" ) )
  184.     {
  185.       opacityWindow = atof( argv[count+1] );
  186.       opacityLevel  = atof( argv[count+2] );
  187.       blendType = 2;
  188.       count += 3;
  189.     }
  190.     else if ( !strcmp( argv[count], "-CT_Skin" ) )
  191.     {
  192.       blendType = 3;
  193.       count += 1;
  194.     }
  195.     else if ( !strcmp( argv[count], "-CT_Bone" ) )
  196.     {
  197.       blendType = 4;
  198.       count += 1;
  199.     }
  200.     else if ( !strcmp( argv[count], "-CT_Muscle" ) )
  201.     {
  202.       blendType = 5;
  203.       count += 1;
  204.     }
  205.     else if ( !strcmp( argv[count], "-RGB_Composite" ) )
  206.     {
  207.       blendType = 6;
  208.       count += 1;
  209.     }
  210.     else if ( !strcmp( argv[count], "-FrameRate") )
  211.     {
  212.       frameRate = atof( argv[count+1] );
  213.       if ( frameRate < 0.01 || frameRate > 60.0 )
  214.       {
  215.         cout << "Invalid frame rate - use a number between 0.01 and 60.0" << endl;
  216.         cout << "Using default frame rate of 10 frames per second." << endl;
  217.         frameRate = 10.0;
  218.       }
  219.       count += 2;
  220.     }
  221.     else if ( !strcmp( argv[count], "-ReductionFactor") )
  222.     {
  223.       reductionFactor = atof( argv[count+1] );
  224.       if ( reductionFactor <= 0.0 || reductionFactor >= 1.0 )
  225.       {
  226.         cout << "Invalid reduction factor - use a number between 0 and 1 (exclusive)" << endl;
  227.         cout << "Using the default of no reduction." << endl;
  228.         reductionFactor = 1.0;
  229.       }
  230.       count += 2;
  231.     }
  232.      else if ( !strcmp( argv[count], "-DependentComponents") )
  233.      {
  234.       independentComponents=false;
  235.       count += 1;
  236.      }
  237.     else
  238.     {
  239.       cout << "Unrecognized option: " << argv[count] << endl;
  240.       cout << endl;
  241.       PrintUsage();
  242.       exit(EXIT_FAILURE);
  243.     }
  244.   }
  245.  
  246.   if ( !dirname && !fileName)
  247.   {
  248.     cout << "Error: you must specify a directory of DICOM data or a .vti file or a .mha!" << endl;
  249.     cout << endl;
  250.     PrintUsage();
  251.     exit(EXIT_FAILURE);
  252.   }
  253.  
  254.   // Create the renderer, render window and interactor
  255.   vtkRenderer *renderer = vtkRenderer::New();
  256.   vtkRenderWindow *renWin = vtkRenderWindow::New();
  257.   renWin->AddRenderer(renderer);
  258.  
  259.   // Connect it all. Note that funny arithematic on the
  260.   // SetDesiredUpdateRate - the vtkRenderWindow divides it
  261.   // allocated time across all renderers, and the renderer
  262.   // divides it time across all props. If clip is
  263.   // true then there are two props
  264.   vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
  265.   iren->SetRenderWindow(renWin);
  266.   iren->SetDesiredUpdateRate(frameRate / (1+clip) );
  267.  
  268.   iren->GetInteractorStyle()->SetDefaultRenderer(renderer);
  269.  
  270.   // Read the data
  271.   vtkAlgorithm *reader=nullptr;
  272.   vtkImageData *input=nullptr;
  273.   if(dirname)
  274.   {
  275.     vtkDICOMImageReader *dicomReader = vtkDICOMImageReader::New();
  276.     dicomReader->SetDirectoryName(dirname);
  277.     dicomReader->Update();
  278.     input=dicomReader->GetOutput();
  279.     reader=dicomReader;
  280.   }
  281.   else if ( fileType == VTI_FILETYPE )
  282.   {
  283.     vtkXMLImageDataReader *xmlReader = vtkXMLImageDataReader::New();
  284.     xmlReader->SetFileName(fileName);
  285.     xmlReader->Update();
  286.     input=xmlReader->GetOutput();
  287.     reader=xmlReader;
  288.   }
  289.   else if ( fileType == MHA_FILETYPE )
  290.   {
  291.     vtkMetaImageReader *metaReader = vtkMetaImageReader::New();
  292.     metaReader->SetFileName(fileName);
  293.     metaReader->Update();
  294.     input=metaReader->GetOutput();
  295.     reader=metaReader;
  296.   }
  297.   else
  298.   {
  299.     cout << "Error! Not VTI or MHA!" << endl;
  300.     exit(EXIT_FAILURE);
  301.   }
  302.  
  303.   // Verify that we actually have a volume
  304.   int dim[3];
  305.   input->GetDimensions(dim);
  306.   if ( dim[0] < 2 ||
  307.        dim[1] < 2 ||
  308.        dim[2] < 2 )
  309.   {
  310.     cout << "Error loading data!" << endl;
  311.     exit(EXIT_FAILURE);
  312.   }
  313.  
  314.   vtkImageResample *resample = vtkImageResample::New();
  315.   if ( reductionFactor < 1.0 )
  316.   {
  317.     resample->SetInputConnection( reader->GetOutputPort() );
  318.     resample->SetAxisMagnificationFactor(0, reductionFactor);
  319.     resample->SetAxisMagnificationFactor(1, reductionFactor);
  320.     resample->SetAxisMagnificationFactor(2, reductionFactor);
  321.   }
  322.  
  323.  
  324.   // reset the volume's origin to be in the centre of the data =====
  325.   // (makes it easier to manually set up the camera, below)
  326.   std::array<int, 6> extent;
  327.   input->GetExtent(extent.data());
  328.  
  329.   std::array<double, 3> spacingArray;
  330.   input->GetSpacing(spacingArray.data());
  331.  
  332.   std::array<double, 3> volumeCentre;
  333.  
  334.   for (auto &volumeCentreElem : volumeCentre)
  335.   {
  336.       auto i = &volumeCentreElem - &volumeCentre[0];
  337.       volumeCentreElem = spacingArray[i] * -0.5 * (extent[i*2] + extent[(i*2)+1]);
  338.   }
  339.  
  340.   input->SetOrigin(volumeCentre.data());
  341.   // end of centring the volume ==========
  342.  
  343.   // Create our volume and mapper
  344.   vtkVolume *volume = vtkVolume::New();
  345.   vtkSmartVolumeMapper *mapper = vtkSmartVolumeMapper::New();
  346.  
  347.   // Add a box widget if the clip option was selected
  348.   vtkBoxWidget *box = vtkBoxWidget::New();
  349.   if (clip)
  350.   {
  351.     box->SetInteractor(iren);
  352.     box->SetPlaceFactor(1.01);
  353.     if ( reductionFactor < 1.0 )
  354.     {
  355.       box->SetInputConnection(resample->GetOutputPort());
  356.     }
  357.     else
  358.     {
  359.       box->SetInputData(input);
  360.     }
  361.  
  362.     box->SetDefaultRenderer(renderer);
  363.     box->InsideOutOn();
  364.     box->PlaceWidget();
  365.     vtkBoxWidgetCallback *callback = vtkBoxWidgetCallback::New();
  366.     callback->SetMapper(mapper);
  367.     box->AddObserver(vtkCommand::InteractionEvent, callback);
  368.     callback->Delete();
  369.     box->EnabledOn();
  370.     box->GetSelectedFaceProperty()->SetOpacity(0.0);
  371.   }
  372.  
  373.   if ( reductionFactor < 1.0 )
  374.   {
  375.     mapper->SetInputConnection( resample->GetOutputPort() );
  376.   }
  377.   else
  378.   {
  379.     mapper->SetInputConnection( reader->GetOutputPort() );
  380.   }
  381.  
  382.  
  383.   // Set the sample distance on the ray to be 1/2 the average spacing
  384.   double spacing[3];
  385.   if ( reductionFactor < 1.0 )
  386.   {
  387.     resample->GetOutput()->GetSpacing(spacing);
  388.   }
  389.   else
  390.   {
  391.     input->GetSpacing(spacing);
  392.   }
  393.  
  394. //  mapper->SetSampleDistance( (spacing[0]+spacing[1]+spacing[2])/6.0 );
  395. //  mapper->SetMaximumImageSampleDistance(10.0);
  396.  
  397.  
  398.   // Create our transfer function
  399.   vtkColorTransferFunction *colorFun = vtkColorTransferFunction::New();
  400.   vtkPiecewiseFunction *opacityFun = vtkPiecewiseFunction::New();
  401.  
  402.   // Create the property and attach the transfer functions
  403.   vtkVolumeProperty *property = vtkVolumeProperty::New();
  404.   property->SetIndependentComponents(independentComponents);
  405.   property->SetColor( colorFun );
  406.   property->SetScalarOpacity( opacityFun );
  407.   property->SetInterpolationTypeToLinear();
  408.  
  409.   // connect up the volume to the property and the mapper
  410.   volume->SetProperty( property );
  411.   volume->SetMapper( mapper );
  412.  
  413.   // Depending on the blend type selected as a command line option,
  414.   // adjust the transfer function
  415.   switch ( blendType )
  416.   {
  417.     // MIP
  418.     // Create an opacity ramp from the window and level values.
  419.     // Color is white. Blending is MIP.
  420.     case 0:
  421.       colorFun->AddRGBSegment(0.0, 1.0, 1.0, 1.0, 255.0, 1.0, 1.0, 1.0 );
  422.       opacityFun->AddSegment( opacityLevel - 0.5*opacityWindow, 0.0,
  423.                               opacityLevel + 0.5*opacityWindow, 1.0 );
  424.       mapper->SetBlendModeToMaximumIntensity();
  425.       break;
  426.  
  427.     // CompositeRamp
  428.     // Create a ramp from the window and level values. Use compositing
  429.     // without shading. Color is a ramp from black to white.
  430.     case 1:
  431.       colorFun->AddRGBSegment(opacityLevel - 0.5*opacityWindow, 0.0, 0.0, 0.0,
  432.                               opacityLevel + 0.5*opacityWindow, 1.0, 1.0, 1.0 );
  433.       opacityFun->AddSegment( opacityLevel - 0.5*opacityWindow, 0.0,
  434.                               opacityLevel + 0.5*opacityWindow, 1.0 );
  435.       mapper->SetBlendModeToComposite();
  436.       property->ShadeOff();
  437.       break;
  438.  
  439.     // CompositeShadeRamp
  440.     // Create a ramp from the window and level values. Use compositing
  441.     // with shading. Color is white.
  442.     case 2:
  443.       colorFun->AddRGBSegment(0.0, 1.0, 1.0, 1.0, 255.0, 1.0, 1.0, 1.0 );
  444.       opacityFun->AddSegment( opacityLevel - 0.5*opacityWindow, 0.0,
  445.                               opacityLevel + 0.5*opacityWindow, 1.0 );
  446.       mapper->SetBlendModeToComposite();
  447.       property->ShadeOn();
  448.       break;
  449.  
  450.     // CT_Skin
  451.     // Use compositing and functions set to highlight skin in CT data
  452.     // Not for use on RGB data
  453.     case 3:
  454.       colorFun->AddRGBPoint( -3024, 0, 0, 0, 0.5, 0.0 );
  455.       colorFun->AddRGBPoint( -1000, .62, .36, .18, 0.5, 0.0 );
  456.       colorFun->AddRGBPoint( -500, .88, .60, .29, 0.33, 0.45 );
  457.       colorFun->AddRGBPoint( 3071, .83, .66, 1, 0.5, 0.0 );
  458.  
  459.       opacityFun->AddPoint(-3024, 0, 0.5, 0.0 );
  460.       opacityFun->AddPoint(-1000, 0, 0.5, 0.0 );
  461.       opacityFun->AddPoint(-500, 1.0, 0.33, 0.45 );
  462.       opacityFun->AddPoint(3071, 1.0, 0.5, 0.0);
  463.  
  464.       mapper->SetBlendModeToComposite();
  465.       property->ShadeOn();
  466.       property->SetAmbient(0.1);
  467.       property->SetDiffuse(0.9);
  468.       property->SetSpecular(0.2);
  469.       property->SetSpecularPower(10.0);
  470.       property->SetScalarOpacityUnitDistance(0.8919);
  471.       break;
  472.  
  473.     // CT_Bone
  474.     // Use compositing and functions set to highlight bone in CT data
  475.     // Not for use on RGB data
  476.     case 4:
  477.       colorFun->AddRGBPoint( -3024, 0, 0, 0, 0.5, 0.0 );
  478.       colorFun->AddRGBPoint( -16, 0.73, 0.25, 0.30, 0.49, .61 );
  479.       colorFun->AddRGBPoint( 641, .90, .82, .56, .5, 0.0 );
  480.       colorFun->AddRGBPoint( 3071, 1, 1, 1, .5, 0.0 );
  481.  
  482.       opacityFun->AddPoint(-3024, 0, 0.5, 0.0 );
  483.       opacityFun->AddPoint(-16, 0, .49, .61 );
  484.       opacityFun->AddPoint(641, .72, .5, 0.0 );
  485.       opacityFun->AddPoint(3071, .71, 0.5, 0.0);
  486.  
  487.       mapper->SetBlendModeToComposite();
  488.       property->ShadeOn();
  489.       property->SetAmbient(0.1);
  490.       property->SetDiffuse(0.9);
  491.       property->SetSpecular(0.2);
  492.       property->SetSpecularPower(10.0);
  493.       property->SetScalarOpacityUnitDistance(0.8919);
  494.       break;
  495.  
  496.     // CT_Muscle
  497.     // Use compositing and functions set to highlight muscle in CT data
  498.     // Not for use on RGB data
  499.     case 5:
  500.       colorFun->AddRGBPoint( -3024, 0, 0, 0, 0.5, 0.0 );
  501.       colorFun->AddRGBPoint( -155, .55, .25, .15, 0.5, .92 );
  502.       colorFun->AddRGBPoint( 217, .88, .60, .29, 0.33, 0.45 );
  503.       colorFun->AddRGBPoint( 420, 1, .94, .95, 0.5, 0.0 );
  504.       colorFun->AddRGBPoint( 3071, .83, .66, 1, 0.5, 0.0 );
  505.  
  506.       opacityFun->AddPoint(-3024, 0, 0.5, 0.0 );
  507.       opacityFun->AddPoint(-155, 0, 0.5, 0.92 );
  508.       opacityFun->AddPoint(217, .68, 0.33, 0.45 );
  509.       opacityFun->AddPoint(420,.83, 0.5, 0.0);
  510.       opacityFun->AddPoint(3071, .80, 0.5, 0.0);
  511.  
  512.       mapper->SetBlendModeToComposite();
  513.       property->ShadeOn();
  514.       property->SetAmbient(0.1);
  515.       property->SetDiffuse(0.9);
  516.       property->SetSpecular(0.2);
  517.       property->SetSpecularPower(10.0);
  518.       property->SetScalarOpacityUnitDistance(0.8919);
  519.       break;
  520.  
  521.     // RGB_Composite
  522.     // Use compositing and functions set to highlight red/green/blue regions
  523.     // in RGB data. Not for use on single component data
  524.     case 6:
  525.       opacityFun->AddPoint(0, 0.0);
  526.       opacityFun->AddPoint(5.0, 0.0);
  527.       opacityFun->AddPoint(30.0, 0.05);
  528.       opacityFun->AddPoint(31.0, 0.0);
  529.       opacityFun->AddPoint(90.0, 0.0);
  530.       opacityFun->AddPoint(100.0, 0.3);
  531.       opacityFun->AddPoint(110.0, 0.0);
  532.       opacityFun->AddPoint(190.0, 0.0);
  533.       opacityFun->AddPoint(200.0, 0.4);
  534.       opacityFun->AddPoint(210.0, 0.0);
  535.       opacityFun->AddPoint(245.0, 0.0);
  536.       opacityFun->AddPoint(255.0, 0.5);
  537.  
  538.       mapper->SetBlendModeToComposite();
  539.       property->ShadeOff();
  540.       property->SetScalarOpacityUnitDistance(1.0);
  541.       break;
  542.     default:
  543.        vtkGenericWarningMacro("Unknown blend type.");
  544.        break;
  545.   }
  546.  
  547.   // orient the volume
  548.   volume->SetOrientation(0.0, 90.0, -90.0);
  549.  
  550.   // pick GPU or CPU rendering in the volume mapper
  551.   mapper->SetRequestedRenderModeToGPU();
  552.   //mapper->SetRequestedRenderModeToRayCast();
  553.  
  554.   // These are the setting for the head data
  555.   auto light = vtkLight::New();
  556.   light->SetLightTypeToSceneLight();
  557.   //light->SetLightTypeToHeadlight();
  558.   light->SetPosition(0.0, 0.0, -400.0);
  559.   light->SetFocalPoint(0.0, 0.0, 0.0);
  560.  
  561.   // These are the common lighting settings
  562.   renderer->SetLightFollowCamera(false);
  563.   renderer->AddLight(light);
  564.  
  565.   // Set the default window size
  566.   renWin->SetSize(600,600);
  567.   renWin->Render();
  568.  
  569.   // Add the volume to the scene
  570.   renderer->AddVolume( volume );
  571.  
  572.   renderer->ResetCamera();
  573.  
  574.   auto camera = renderer->GetActiveCamera();
  575.  
  576.   // These are the settings for the head data
  577.   camera->SetPosition(200.0, 200.0, -400.0);
  578.   camera->SetFocalPoint(0.0, 0.0, 0.0);
  579.   camera->SetViewUp(0.0, 1.0, 0.0);
  580.   camera->SetClippingRange(0.1, 1000.0);
  581.  
  582.   // interact with data
  583.   renWin->Render();
  584.  
  585.   iren->Start();
  586.  
  587.   auto lightCollection = renderer->GetLights();
  588.   lightCollection->InitTraversal();
  589.   auto lightFromCollection = lightCollection->GetNextItem();
  590.  
  591.   opacityFun->Delete();
  592.   colorFun->Delete();
  593.   property->Delete();
  594.  
  595.   box->Delete();
  596.   volume->Delete();
  597.   mapper->Delete();
  598.   reader->Delete();
  599.   resample->Delete();
  600.   renderer->Delete();
  601.   renWin->Delete();
  602.   iren->Delete();
  603.  
  604.   return 0;
  605. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement