<div dir="ltr">Hi Elvis,<div><br></div><div>Here is something you can do as a check: set the sample distance for the ray casting to a very small value, so that it takes around 1000 steps for the ray to traverse the volume from front to back.  The thickness of your volume is 29*0.006 = 0.174, so you can try a sample spacing of 1.74e-04:</div><div><br></div><div>mapper->AutoAdjustSampleDistancesOff();</div><div>mapper->SetSampleDistance(1.74e-04);</div><div><br></div><div>If the two volumes look the same when you use a small sample distance, then the difference you were seeing was probably just due to discretization.</div><div><br></div><div> - David</div><div><br></div><div><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Feb 9, 2017 at 6:45 AM, Elvis Stansvik <span dir="ltr"><<a href="mailto:elvis.stansvik@orexplore.com" target="_blank">elvis.stansvik@orexplore.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div>Hi all,<br><br>The following example shows a 30x30x30 volume rendered, and next to it a downscaled version of it (but using an identical opacity/transfer function). Notice how in the result (attached), the downscaled version is less opaque. This is despite me using<br><br>    SetScalarOpacityUnitDistance(<wbr>image->GetSpacing()[0])<br><br></div>to set the scalar opacity unit distance to the spacing of the respective image. I would thought calling SetScalarOpacityUnitDistance like this would ensure both volumes look the same (apart from resolution).<br><br></div>How can I make both volumes look the same opacity-wise when using the same transfer functions?<br><br></div>Thanks in advance,<br></div>Elvis<br><br></div>main.cpp:<br><br><br>#include <algorithm><br><br>#include <vtkCamera.h><br>#include <vtkColorTransferFunction.h><br>#include <vtkGPUVolumeRayCastMapper.h><br>#include <vtkImageData.h><br>#include <vtkImageResize.h><br>#include <vtkPiecewiseFunction.h><br>#include <vtkRenderer.h><br>#include <vtkRenderWindow.h><br>#include <vtkRenderWindowInteractor.h><br>#include <vtkSmartPointer.h><br>#include <vtkVolume.h><br>#include <vtkVolumeProperty.h><br><br>// Create a volume from the given image<br>vtkSmartPointer<vtkVolume> createVolume(vtkSmartPointer<<wbr>vtkImageData> image) {<br>    auto color = vtkSmartPointer<<wbr>vtkColorTransferFunction>::<wbr>New();<br>    color->AddRGBPoint(0.0, 1.0, 0.0, 0.0);<br>    color->AddRGBPoint(1.0, 1.0, 0.0, 0.0);<br><br>    auto opacity = vtkSmartPointer<<wbr>vtkPiecewiseFunction>::New();<br>    opacity->AddPoint(0.0, 0.1);<br>    opacity->AddPoint(1.0, 0.1);<br><br>    auto property = vtkSmartPointer<<wbr>vtkVolumeProperty>::New();<br>    property->SetColor(color);<br>    property->SetScalarOpacity(<wbr>opacity);<br>    property-><wbr>SetInterpolationTypeToLinear()<wbr>;<br>    property->ShadeOff();<br>    property-><wbr>SetScalarOpacityUnitDistance(<wbr>image->GetSpacing()[0]);<br><br>    auto mapper = vtkSmartPointer<<wbr>vtkGPUVolumeRayCastMapper>::<wbr>New();<br>    mapper->SetInputData(image);<br><br>    auto volume = vtkSmartPointer<vtkVolume>::<wbr>New();<br>    volume->SetMapper(mapper);<br>    volume->SetProperty(property);<br><br>    return volume;<br>}<br><br>int main(int argc, char *argv[]) {<br><br>    // Create a 30x30x30 volume<br>    auto image = vtkSmartPointer<vtkImageData>:<wbr>:New();<br>    image->SetDimensions(30, 30, 30);<br>    image->SetSpacing(0.006, 0.006, 0.006);<br>    image->AllocateScalars(VTK_<wbr>FLOAT, 1);<br><br>    auto imagePtr = static_cast<float *>(image->GetScalarPointer());<br>    std::fill_n(imagePtr, 30 * 30 * 30, 1.0);<br><br>    auto volume = createVolume(image);<br><br>    // Create a smaller (10x10x10) version<br>    auto resize = vtkSmartPointer<<wbr>vtkImageResize>::New();<br>    resize->SetInputData(image);<br>    resize->SetOutputDimensions(<wbr>10, 10, 10);<br>    resize->Update();<br><br>    auto smallVolume = createVolume(resize-><wbr>GetOutput());<br>    smallVolume->SetPosition(0.2, 0, 0);<br><br>    // Render the two volumes<br>    auto renderer = vtkSmartPointer<vtkRenderer>::<wbr>New();<br>    renderer->SetBackground(1.0, 1.0, 1.0);<br>    renderer->AddVolume(volume);<br>    renderer->AddVolume(<wbr>smallVolume);<br>    renderer->ResetCamera();<br><br>    auto camera = renderer->GetActiveCamera();<br>    camera->SetParallelProjection(<wbr>1);<br><br>    auto window = vtkSmartPointer<<wbr>vtkRenderWindow>::New();<br>    window->AddRenderer(renderer);<br>    window->SetSize(800, 400);<br><br>    auto interactor = vtkSmartPointer<<wbr>vtkRenderWindowInteractor>::<wbr>New();<br>    interactor->SetRenderWindow(<wbr>window);<br>    interactor->Start();<br><br>    return 0;<br>}<br><br><br></div>CMakeLists.txt:<br><br><br>cmake_minimum_required(VERSION 3.1)<br> <br>project(TestCase)<br> <br>set(CMAKE_CXX_STANDARD 11)<br>set(CMAKE_CXX_STANDARD_<wbr>REQUIRED ON)<br><br>find_package(VTK COMPONENTS<br>    vtkCommonCore<br>    vtkCommonDataModel<br>    vtkCommonExecutionModel<br>    vtkInteractionStyle<br>    vtkImagingCore<br>    vtkRenderingCore<br>    vtkRenderingOpenGL2<br>    vtkRenderingVolume<br>    vtkRenderingVolumeOpenGL2<br>)<br><br>add_executable(TestCase main.cpp)<br> <br>target_link_libraries(TestCase PUBLIC<br>    vtkCommonCore<br>    vtkCommonDataModel<br>    vtkCommonExecutionModel<br>    vtkImagingCore<br>    vtkInteractionStyle<br>    vtkRenderingCore<br>    vtkRenderingOpenGL2<br>    vtkRenderingVolume<br>    vtkRenderingVolumeOpenGL2<br>)<br><br>target_include_directories(<wbr>TestCase PUBLIC<br>    ${VTK_INCLUDE_DIRS}<br>)<br><br><br>target_compile_definitions(<wbr>TestCase PUBLIC<br>    ${VTK_DEFINITIONS}<br>)</div></blockquote></div><br></div></div></div>