<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body>
    Hi Aashish,<br>
    <br>
    I compiled VTK revision dbae27c5ee61cb7507d893001ae8d93a580f9e72 of
    the master branch and still the same problem with volume rendering. 
    Rectangles render fine.<br>
    <br>
    The worldToCamera transform applied through
    SetModelTransformMatrix() seems to deform the volume for volume
    rendering - yet it does not deform the rectangle geometry.  Does
    this behavior seem right or should I file a bug report? I'm a new
    user so it's entirely possible this is intended behavior, but to me
    at a glance and reading API documentaiton it doesn't seem right. 
    Yet another screenshot attached.<br>
    <br>
    Thanks.<br>
    <br>
    <br>
    <div class="moz-cite-prefix">On 08/29/2016 03:43 PM, Aashish
      Chaudhary wrote:<br>
    </div>
    <blockquote
cite="mid:CAEw35Z8SrqmNb546CeRK_F9pop_j0rdhq=qb1O_7mZA-22DvCw@mail.gmail.com"
      type="cite">
      <div dir="ltr">Hi Bud, 
        <div><br>
        </div>
        <div>There was a bug that was fixed recently. Can you try the
          latest master and see if it is fixed? If it is, you can always
          cherry-pick that commit to 6.3 branch. </div>
        <div><br>
        </div>
        <div>- Aashish</div>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr">On Mon, Aug 29, 2016 at 1:46 PM Bud Bundy <<a
            moz-do-not-send="true" href="mailto:budric@gmail.com">budric@gmail.com</a>>
          wrote:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0 0 0
          .8ex;border-left:1px #ccc solid;padding-left:1ex">
          <div bgcolor="#FFFFFF" text="#000000">
            <p>Sorry to bump my own thread but I still can't get this to
              work.  For 2 identical cameras in terms of position and
              projection transform, after adjusting the lights (or not)
              I get 2 different renderings.  <br>
            </p>
            <p>The only difference is I apply worldToCamera transform by
              setting
              camera1->SetModelTransformMatrix(worldToCamera);
              whereas for camera2 I transform the vtkVolume.  In my
              understanding these should be identical in terms of
              positioning something in camera coordinate system.  But
              the rendering is different (sample attached as
              volume_vtk_7.0.0.jpg).<br>
            </p>
            <p>Weirdly enough if I render a cube instead of the volume,
              it works with VTK 7.0.0 (attached actor_vtk_7.0.0.jpg). 
              Same transform, both cameras work.  However, then same
              code rendering the cube doesn't work with 6.3.0 (attached
              actor_vtk_6.3.0.jpg).  Not that I need to use 6.3.0.  But
              I'm just at my wits end on what to try.<br>
            </p>
            <p>Can someone please have a look at my code and tell me how
              to get camera1 to render properly?  Thank you</p>
          </div>
          <div bgcolor="#FFFFFF" text="#000000">
            <p><br>
              #include <vtkActor.h><br>
              #include <vtkSmartPointer.h><br>
              #include <vtkCubeSource.h><br>
              #include <vtkPolyDataMapper.h><br>
              #include <vtkRenderWindow.h><br>
              #include <vtkRenderer.h><br>
              #include <vtkRenderWindowInteractor.h><br>
              #include <vtkCamera.h><br>
              #include <vtkSphere.h><br>
              #include <vtkSampleFunction.h><br>
              #include <vtkImageShiftScale.h><br>
              #include <vtkImageData.h><br>
              #include <vtkPointData.h><br>
              #include <vtkSmartVolumeMapper.h><br>
              #include <vtkPiecewiseFunction.h><br>
              #include <vtkVolumeProperty.h><br>
              #include <vtkColorTransferFunction.h><br>
              #include <vtkCommand.h><br>
              #include <vtkMatrix4x4.h><br>
            </p>
          </div>
          <div bgcolor="#FFFFFF" text="#000000">
            <p> #include <vtkLightCollection.h><br>
              #include <vtkLight.h><br>
              #include <vtkTransform.h><br>
              #include <iostream><br>
              <br>
              const double objectToWorld[16] = {<br>
                  0.976,    0,    0,        -249.511,<br>
                  0, -0.976,    0,        249.224,<br>
                  0,    0, -2,            -1251.5,<br>
                  0,    0,    0,            1 };<br>
              <br>
              const double worldToCamera[16] = {<br>
                  -0.965924, 0.00168586, 0.258819,    372.757,<br>
                  0.258819, -0.000451724, 0.965926,    1382.12,<br>
                  0.00174533, 0.999998, 0,            16.3087,<br>
                  0, 0, 0,                            1};<br>
              <br>
              vtkSmartPointer<vtkActor> generateRectangle()<br>
              {<br>
                  vtkSmartPointer<vtkCubeSource> cubeSource =
              vtkSmartPointer<vtkCubeSource>::New();<br>
              <br>
                  vtkSmartPointer<vtkPolyDataMapper> mapper =
              vtkSmartPointer<vtkPolyDataMapper>::New();<br>
                 
              mapper->SetInputConnection(cubeSource->GetOutputPort());<br>
              <br>
                  vtkSmartPointer<vtkActor> actor =
              vtkSmartPointer<vtkActor>::New();<br>
                  actor->SetMapper(mapper);<br>
                  actor->SetScale(512, 512, 160);<br>
                  actor->SetPosition(256, 256, 80);<br>
                  vtkSmartPointer<vtkTransform> userTransform =
              vtkSmartPointer<vtkTransform>::New();<br>
                  userTransform->SetMatrix(objectToWorld);<br>
                  actor->SetUserTransform(userTransform);<br>
                  return actor;</p>
          </div>
          <div bgcolor="#FFFFFF" text="#000000">
            <p><br>
              }<br>
              <br>
              vtkSmartPointer<vtkVolume> generateVolume()<br>
              {<br>
                  // Create a spherical implicit function.<br>
                  vtkSmartPointer<vtkSphere> sphere =
              vtkSmartPointer<vtkSphere>::New();<br>
            </p>
          </div>
          <div bgcolor="#FFFFFF" text="#000000">
            <p>     sphere->SetRadius(1);</p>
          </div>
          <div bgcolor="#FFFFFF" text="#000000">
            <p><br>
                  sphere->SetCenter(0.0, 0.0, 0.0);<br>
              <br>
                  vtkSmartPointer<vtkSampleFunction>
              sampleFunction =
              vtkSmartPointer<vtkSampleFunction>::New();<br>
                  sampleFunction->SetImplicitFunction(sphere);<br>
                  sampleFunction->SetOutputScalarTypeToFloat();<br>
                  sampleFunction->SetSampleDimensions(64, 64, 20);<br>
                  sampleFunction->SetModelBounds(-1.0, 1.0, -1.0,
              1.0, -1.0, 1.0);<br>
                  sampleFunction->SetCapping(false);<br>
                  sampleFunction->SetComputeNormals(false);<br>
                  sampleFunction->SetScalarArrayName("values");<br>
                  sampleFunction->Update();<br>
              <br>
                  vtkDataArray* a =
sampleFunction->GetOutput()->GetPointData()->GetScalars("values");<br>
                  double range[2];<br>
                  a->GetRange(range);<br>
              <br>
                  vtkSmartPointer<vtkImageShiftScale> t =
              vtkSmartPointer<vtkImageShiftScale>::New();<br>
                 
              t->SetInputConnection(sampleFunction->GetOutputPort());<br>
              <br>
                  t->SetShift(-range[0]);<br>
                  double magnitude = range[1] - range[0];<br>
                  if (magnitude == 0.0)<br>
                  {<br>
                      magnitude = 1.0;<br>
                  }<br>
                  t->SetScale(255.0 / magnitude);<br>
                  t->SetOutputScalarTypeToUnsignedChar();<br>
                  t->Update();<br>
              <br>
                  vtkSmartPointer<vtkImageData> imageData =
              vtkSmartPointer<vtkImageData>::New();<br>
                  imageData->ShallowCopy(t->GetOutput());<br>
              <br>
                  vtkSmartPointer<vtkSmartVolumeMapper>
              volumeMapper =
              vtkSmartPointer<vtkSmartVolumeMapper>::New();<br>
                  volumeMapper->SetBlendModeToComposite(); //
              composite first<br>
                  volumeMapper->SetInputData(imageData);<br>
              <br>
                  vtkSmartPointer<vtkVolumeProperty>
              volumeProperty =
              vtkSmartPointer<vtkVolumeProperty>::New();<br>
                  volumeProperty->ShadeOff();<br>
                 
              volumeProperty->SetInterpolationType(VTK_LINEAR_INTERPOLATION);<br>
              <br>
                  vtkSmartPointer<vtkPiecewiseFunction>
              compositeOpacity =
              vtkSmartPointer<vtkPiecewiseFunction>::New();<br>
                  compositeOpacity->AddPoint(0.0, 0.0);<br>
                  compositeOpacity->AddPoint(80.0, 1.0);<br>
                  compositeOpacity->AddPoint(80.1, 0.0);<br>
                  compositeOpacity->AddPoint(255.0, 0.0);<br>
                  volumeProperty->SetScalarOpacity(compositeOpacity);
              // composite first.<br>
              <br>
                  vtkSmartPointer<vtkColorTransferFunction> color
              = vtkSmartPointer<vtkColorTransferFunction>::New();<br>
                  color->AddRGBPoint(0.0, 0.0, 0.0, 1.0);<br>
                  color->AddRGBPoint(40.0, 1.0, 0.0, 0.0);<br>
                  color->AddRGBPoint(255.0, 1.0, 1.0, 1.0);<br>
                  volumeProperty->SetColor(color);<br>
              <br>
                  vtkSmartPointer<vtkVolume> volume =
              vtkSmartPointer<vtkVolume>::New();<br>
                  volume->SetMapper(volumeMapper);<br>
                  volume->SetProperty(volumeProperty);<br>
              <br>
            </p>
          </div>
          <div bgcolor="#FFFFFF" text="#000000">
            <p>     volume->SetScale(512, 512, 160);<br>
                  volume->SetPosition(256, 256, 80);<br>
              <br>
                  vtkSmartPointer<vtkTransform> userTransform =
              vtkSmartPointer<vtkTransform>::New();<br>
                  userTransform->SetMatrix(objectToWorld);<br>
                  volume->SetUserTransform(userTransform);<br>
                  return volume;</p>
          </div>
          <div bgcolor="#FFFFFF" text="#000000">
            <p><br>
              }<br>
              <br>
              void assertArrayEquals(const double * a, const double * b,
              size_t elements)<br>
              {<br>
                  for (size_t i = 0; i < elements; ++i)<br>
                  {<br>
                      assert(a[i] - b[i] <=
              std::numeric_limits<double>::epsilon());<br>
                  }<br>
              }<br>
              <br>
            </p>
          </div>
          <div bgcolor="#FFFFFF" text="#000000">
            <p> void assertVtkMatrixEquals(const vtkMatrix4x4 * a, const
              vtkMatrix4x4 * b)<br>
              {<br>
                  for (size_t i = 0; i < 4; ++i)<br>
                  {<br>
                      for (size_t j = 0; j < 4; ++j)<br>
                      {<br>
                          assert(fabs(a->GetElement(i, j) -
              b->GetElement(i, j)) <
              std::numeric_limits<double>::epsilon());</p>
          </div>
          <div bgcolor="#FFFFFF" text="#000000">
            <p><br>
                      }<br>
                  }<br>
              }<br>
              <br>
              int main()<br>
              {<br>
                  // camera1<br>
                  vtkSmartPointer<vtkCamera> camera1 =
              vtkSmartPointer<vtkCamera>::New();<br>
                  camera1->SetPosition(0, 0, 1000);<br>
                  camera1->SetFocalPoint(0, 0, 0);<br>
            </p>
          </div>
          <div bgcolor="#FFFFFF" text="#000000">
            <p>     camera1->SetViewUp(0, 1, 0);</p>
          </div>
          <div bgcolor="#FFFFFF" text="#000000">
            <p><br>
                  camera1->SetClippingRange(0.1, 5000);<br>
                  camera1->SetViewAngle(60);<br>
            </p>
          </div>
          <div bgcolor="#FFFFFF" text="#000000">
            <p>     camera1->SetModelTransformMatrix(worldToCamera);</p>
          </div>
          <div bgcolor="#FFFFFF" text="#000000">
            <p><br>
              <br>
                  //camera 2<br>
                  vtkSmartPointer<vtkCamera> camera2 =
              vtkSmartPointer<vtkCamera>::New();<br>
            </p>
          </div>
          <div bgcolor="#FFFFFF" text="#000000">
            <p>     camera2->SetPosition(0, 0, 1000);<br>
                  camera2->SetFocalPoint(0, 0, 0);<br>
                  camera2->SetViewUp(0, 1, 0);<br>
                  camera2->SetClippingRange(0.1, 5000);<br>
                  camera2->SetViewAngle(60);</p>
          </div>
          <div bgcolor="#FFFFFF" text="#000000">
            <p><br>
              <br>
                  // renderer1 using camera1<br>
                  vtkSmartPointer<vtkRenderer> renderer1 =
              vtkSmartPointer<vtkRenderer>::New();<br>
                  renderer1->SetViewport(0, 0, 0.5, 1);<br>
            </p>
          </div>
          <div bgcolor="#FFFFFF" text="#000000">
            <p>     renderer1->SetActiveCamera(camera1);    <br>
                  //renderer1->AddVolume(generateVolume());<br>
                  renderer1->AddActor(generateRectangle());</p>
          </div>
          <div bgcolor="#FFFFFF" text="#000000">
            <p><br>
                  <br>
                  // renderer2 using camera2<br>
                  vtkSmartPointer<vtkRenderer> renderer2 =
              vtkSmartPointer<vtkRenderer>::New();<br>
                  renderer2->SetViewport(0.5, 0, 1, 1);<br>
            </p>
          </div>
          <div bgcolor="#FFFFFF" text="#000000">
            <p>     vtkSmartPointer<vtkVolume> volume2 =
              generateVolume();<br>
                  vtkSmartPointer<vtkActor> rectangle2 =
              generateRectangle();<br>
                  vtkSmartPointer<vtkTransform>
              objectToCameraTransform =
              vtkSmartPointer<vtkTransform>::New();<br>
                  // Generate transform (worldToCamera * objectToWorld)
              and apply it to the model<br>
                  objectToCameraTransform->SetMatrix(objectToWorld);<br>
                  objectToCameraTransform->PostMultiply();<br>
                 
              objectToCameraTransform->Concatenate(worldToCamera);<br>
                  objectToCameraTransform->Update();<br>
                  volume2->SetUserTransform(objectToCameraTransform);<br>
                 
              rectangle2->SetUserTransform(objectToCameraTransform);<br>
                  renderer2->SetActiveCamera(camera2);<br>
                  //renderer2->AddVolume(volume2);<br>
                  renderer2->AddActor(rectangle2);</p>
          </div>
          <div bgcolor="#FFFFFF" text="#000000">
            <p><br>
              <br>
                  // window and interactor<br>
                  vtkSmartPointer<vtkRenderWindow> renderWindow =
              vtkSmartPointer<vtkRenderWindow>::New();<br>
                  renderWindow->SetSize(1024, 512);<br>
                  renderWindow->AddRenderer(renderer1);<br>
                  renderWindow->AddRenderer(renderer2);<br>
                  vtkSmartPointer<vtkRenderWindowInteractor>
              renderWindowInteractor =
              vtkSmartPointer<vtkRenderWindowInteractor>::New();<br>
                 
              renderWindowInteractor->SetRenderWindow(renderWindow);<br>
              <br>
            </p>
          </div>
          <div bgcolor="#FFFFFF" text="#000000">
            <p>     // Attempt to Adjust lights<br>
                  renderWindow->Render();<br>
                  vtkLight * modifiedLight = dynamic_cast<vtkLight
              *>(renderer1->GetLights()->GetItemAsObject(0));<br>
                  modifiedLight->SetLightTypeToHeadlight();<br>
                 
              modifiedLight->SetPosition(camera1->GetPosition());<br>
                 
              modifiedLight->SetFocalPoint(camera1->GetFocalPoint());<br>
                  // Above Doesn't work, Ok let's try this as well<br>
                  renderer1->UpdateLightsGeometryToFollowCamera();<br>
              <br>
                  // Sanity check<br>
                  assertArrayEquals(camera1->GetPosition(),       
                      camera2->GetPosition(), 3);<br>
                  assertArrayEquals(camera1->GetFocalPoint(),       
                      camera2->GetFocalPoint(), 3);<br>
                 
assertVtkMatrixEquals(camera1->GetProjectionTransformMatrix(renderer1),
              camera2->GetProjectionTransformMatrix(renderer2));</p>
          </div>
          <div bgcolor="#FFFFFF" text="#000000">
            <p><br>
                  vtkSmartPointer<vtkLightCollection>
              lightCollection1 = renderer1->GetLights();<br>
                  vtkSmartPointer<vtkLightCollection>
              lightCollection2 = renderer2->GetLights();<br>
                  assert(lightCollection1->GetNumberOfItems() ==
              lightCollection2->GetNumberOfItems());<br>
                  lightCollection1->InitTraversal();<br>
                  lightCollection2->InitTraversal();<br>
                  vtkSmartPointer<vtkLight> light1 =
              lightCollection1->GetNextItem();<br>
                  vtkSmartPointer<vtkLight> light2 =
              lightCollection2->GetNextItem();<br>
                  assertArrayEquals(light1->GetPosition(),           
                  light2->GetPosition(), 3);<br>
                 
              assertArrayEquals(light1->GetTransformedPosition(),   
                  light2->GetTransformedPosition(), 3);<br>
                  assertArrayEquals(light1->GetFocalPoint(),       
                      light2->GetFocalPoint(), 3);<br>
                 
              assertArrayEquals(light1->GetTransformedFocalPoint(),   
              light1->GetTransformedFocalPoint(), 3);<br>
                  assertArrayEquals(light1->GetAmbientColor(),       
                  light2->GetAmbientColor(), 3);<br>
                  assertArrayEquals(light1->GetSpecularColor(),   
                      light2->GetSpecularColor(), 3);<br>
                  assertArrayEquals(light1->GetDiffuseColor(),       
                  light2->GetDiffuseColor(), 3);<br>
              <br>
                  renderWindow->Render();<br>
                  renderWindowInteractor->Start();<br>
              <br>
            </p>
          </div>
          <div bgcolor="#FFFFFF" text="#000000">
            <p>     return EXIT_SUCCESS;<br>
              }<br>
            </p>
          </div>
          <div bgcolor="#FFFFFF" text="#000000"> <br>
            <div>On 08/05/2016 03:10 PM, Bud Bundy wrote:<br>
            </div>
            <blockquote type="cite">
              <p>Thanks,</p>
              <p>The light positions were indeed different, but making
                them the same didn't fix it for me.  Perhaps my fix is
                wrong?</p>
              <p>void assertArrayEquals(const double * a, const double *
                b, size_t elements)<br>
                {<br>
                    for (size_t i = 0; i < elements; ++i)<br>
                    {<br>
                        assert(a[i] - b[i] <=
                std::numeric_limits<double>::epsilon());<br>
                    }<br>
                }<br>
              </p>
              <p>    //previous int main() code ...<br>
              </p>
              <p>    //setting lights before first call to Render()
                crashes program, also describedh <a
                  moz-do-not-send="true"
                  href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/Lighting/Light"
                  target="_blank">http://www.vtk.org/Wiki/VTK/Examples/Cxx/Lighting/Light</a><br>
              </p>
              <p>    renderWindow->Render(); <br>
                <br>
                    renderer2->RemoveAllLights();<br>
                    vtkSmartPointer<vtkLight> newLight =
                vtkSmartPointer<vtkLight>::New();<br>
                    newLight->SetPosition(0, 0, 1000);<br>
                    renderer2->AddLight(newLight);<br>
                    <br>
                    //assert lighting is the same<br>
                    vtkSmartPointer<vtkLightCollection>
                lightCollection1 = renderer1->GetLights();<br>
                    vtkSmartPointer<vtkLightCollection>
                lightCollection2 = renderer2->GetLights();<br>
                    assert(lightCollection1->GetNumberOfItems() ==
                lightCollection2->GetNumberOfItems());<br>
                    lightCollection1->InitTraversal();<br>
                    lightCollection2->InitTraversal();<br>
                    vtkSmartPointer<vtkLight> light1 =
                lightCollection1->GetNextItem();<br>
                    vtkSmartPointer<vtkLight> light2 =
                lightCollection2->GetNextItem();<br>
                    assertArrayEquals(light1->GetPosition(),
                light2->GetPosition(), 3);<br>
                   
                assertArrayEquals(light1->GetTransformedPosition(),
                light2->GetTransformedPosition(), 3);<br>
                    assertArrayEquals(light1->GetFocalPoint(),
                light2->GetFocalPoint(), 3);<br>
                   
                assertArrayEquals(light1->GetTransformedFocalPoint(),
                light1->GetTransformedFocalPoint(), 3);<br>
                    assertArrayEquals(light1->GetAmbientColor(),
                light2->GetAmbientColor(), 3);<br>
                    assertArrayEquals(light1->GetSpecularColor(),
                light2->GetSpecularColor(), 3);<br>
                    assertArrayEquals(light1->GetDiffuseColor(),
                light2->GetDiffuseColor(), 3);<br>
                <br>
                    renderWindow->Render();<br>
                    <br>
                    renderWindowInteractor->Start();</p>
              <p><br>
              </p>
              <div>On 08/05/16 14:10, David E DeMarle wrote:<br>
              </div>
              <blockquote type="cite">
                <p dir="ltr">I was just doing a very similar thing and
                  noticed that light positions are only updated with the
                  set origin, focal point and up. I ended up computing
                  those for my intended matrix and lighting then worked
                  as expected. </p>
                <div class="gmail_extra"><br>
                  <div class="gmail_quote">On Aug 5, 2016 1:12 PM, "Bud
                    Bundy" <<a moz-do-not-send="true"
                      href="mailto:budric@gmail.com" target="_blank">budric@gmail.com</a>>
                    wrote:<br type="attribution">
                    <blockquote class="gmail_quote" style="margin:0 0 0
                      .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
                      <br>
                      I need to setup the camera to an arbitrary
                      modelview matrix I have in memory.  I managed to
                      get some code working such that
                      GetModelViewTransformMatrix() returns the
                      modelview I have/want. However the volume
                      rendering is sometimes blank, and I don't
                      understand why because the volume is in front of
                      the camera.  I managed to boil down the problem to
                      the following code below. camera1 and camera2 have
                      the same modelview transform, however the
                      rendering look very different (I've attached a
                      screen shot) - though not blank it's a lot dimmer.<br>
                      <br>
                      The code is loosely based on: <a
                        moz-do-not-send="true"
href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/VolumeRendering/SmartVolumeMapper"
                        rel="noreferrer" target="_blank">http://www.vtk.org/Wiki/VTK/Examples/Cxx/VolumeRendering/SmartVolumeMapper</a><br>
                      <br>
                      I'm using VTK 7.0<br>
                      <br>
                      #include <vtkActor.h><br>
                      #include <vtkSmartPointer.h><br>
                      #include <vtkCubeSource.h><br>
                      #include <vtkPolyDataMapper.h><br>
                      #include <vtkRenderWindow.h><br>
                      #include <vtkRenderer.h><br>
                      #include <vtkRenderWindowInteractor.h><br>
                      #include <vtkCamera.h><br>
                      #include <vtkSphere.h><br>
                      #include <vtkSampleFunction.h><br>
                      #include <vtkImageShiftScale.h><br>
                      #include <vtkImageData.h><br>
                      #include <vtkPointData.h><br>
                      #include <vtkSmartVolumeMapper.h><br>
                      #include <vtkPiecewiseFunction.h><br>
                      #include <vtkVolumeProperty.h><br>
                      #include <vtkColorTransferFunction.h><br>
                      #include <vtkCommand.h><br>
                      #include <vtkMatrix4x4.h><br>
                      <br>
                      vtkSmartPointer<vtkVolume> generateVolume()<br>
                      {<br>
                          // Create a spherical implicit function.<br>
                          vtkSmartPointer<vtkSphere> sphere =
                      vtkSmartPointer<vtkSphere>::New();<br>
                          sphere->SetRadius(0.1);<br>
                          sphere->SetCenter(0.0, 0.0, 0.0);<br>
                      <br>
                          vtkSmartPointer<vtkSampleFunction>
                      sampleFunction =
                      vtkSmartPointer<vtkSampleFunction>::New();<br>
                         
                      sampleFunction->SetImplicitFunction(sphere);<br>
                         
                      sampleFunction->SetOutputScalarTypeToFloat();<br>
                          sampleFunction->SetSampleDimensions(64, 64,
                      20);<br>
                          sampleFunction->SetModelBounds(-1.0, 1.0,
                      -1.0, 1.0, -1.0, 1.0);<br>
                          sampleFunction->SetCapping(false);<br>
                          sampleFunction->SetComputeNormals(false);<br>
                         
                      sampleFunction->SetScalarArrayName("values");<br>
                          sampleFunction->Update();<br>
                      <br>
                          vtkDataArray* a =
sampleFunction->GetOutput()->GetPointData()->GetScalars("values");<br>
                          double range[2];<br>
                          a->GetRange(range);<br>
                      <br>
                          vtkSmartPointer<vtkImageShiftScale> t =
                      vtkSmartPointer<vtkImageShiftScale>::New();<br>
                         
                      t->SetInputConnection(sampleFunction->GetOutputPort());<br>
                      <br>
                          t->SetShift(-range[0]);<br>
                          double magnitude = range[1] - range[0];<br>
                          if (magnitude == 0.0)<br>
                          {<br>
                              magnitude = 1.0;<br>
                          }<br>
                          t->SetScale(255.0 / magnitude);<br>
                          t->SetOutputScalarTypeToUnsignedChar();<br>
                          t->Update();<br>
                      <br>
                          vtkSmartPointer<vtkImageData> imageData
                      = vtkSmartPointer<vtkImageData>::New();<br>
                          imageData->ShallowCopy(t->GetOutput());<br>
                      <br>
                          vtkSmartPointer<vtkSmartVolumeMapper>
                      volumeMapper =
                      vtkSmartPointer<vtkSmartVolumeMapper>::New();<br>
                          volumeMapper->SetBlendModeToComposite(); //
                      composite first<br>
                          volumeMapper->SetInputData(imageData);<br>
                      <br>
                          vtkSmartPointer<vtkVolumeProperty>
                      volumeProperty =
                      vtkSmartPointer<vtkVolumeProperty>::New();<br>
                          volumeProperty->ShadeOff();<br>
volumeProperty->SetInterpolationType(VTK_LINEAR_INTERPOLATION);<br>
                      <br>
                          vtkSmartPointer<vtkPiecewiseFunction>
                      compositeOpacity =
                      vtkSmartPointer<vtkPiecewiseFunction>::New();<br>
                          compositeOpacity->AddPoint(0.0, 0.0);<br>
                          compositeOpacity->AddPoint(80.0, 1.0);<br>
                          compositeOpacity->AddPoint(80.1, 0.0);<br>
                          compositeOpacity->AddPoint(255.0, 0.0);<br>
                         
                      volumeProperty->SetScalarOpacity(compositeOpacity);
                      // composite first.<br>
                      <br>
                         
                      vtkSmartPointer<vtkColorTransferFunction>
                      color =
                      vtkSmartPointer<vtkColorTransferFunction>::New();<br>
                          color->AddRGBPoint(0.0, 0.0, 0.0, 1.0);<br>
                          color->AddRGBPoint(40.0, 1.0, 0.0, 0.0);<br>
                          color->AddRGBPoint(255.0, 1.0, 1.0, 1.0);<br>
                          volumeProperty->SetColor(color);<br>
                      <br>
                          vtkSmartPointer<vtkVolume> volume =
                      vtkSmartPointer<vtkVolume>::New();<br>
                          volume->SetMapper(volumeMapper);<br>
                          volume->SetProperty(volumeProperty);<br>
                      <br>
                          vtkSmartPointer<vtkMatrix4x4>
                      volumeScaleTransform =
                      vtkSmartPointer<vtkMatrix4x4>::New();<br>
                          volumeScaleTransform->Identity();<br>
                          volumeScaleTransform->SetElement(0, 0,
                      512);<br>
                          volumeScaleTransform->SetElement(1, 1,
                      512);<br>
                          volumeScaleTransform->SetElement(2, 2,
                      160);<br>
                         
                      volume->SetUserMatrix(volumeScaleTransform);<br>
                          return volume;<br>
                      }<br>
                      <br>
                      int main()<br>
                      {<br>
                          // camera1<br>
                          vtkSmartPointer<vtkCamera> camera1 =
                      vtkSmartPointer<vtkCamera>::New();<br>
                          camera1->SetPosition(0, 0, 1000);<br>
                          camera1->SetFocalPoint(0, 0, 0);<br>
                          camera1->SetClippingRange(0.1, 5000);<br>
                          camera1->SetViewAngle(60);<br>
                      <br>
                          //camera 2<br>
                          vtkSmartPointer<vtkCamera> camera2 =
                      vtkSmartPointer<vtkCamera>::New();<br>
                          camera2->SetPosition(0, 0, 0);           
                      //I do not want any additional translation that
                      comes with default (0,0,1) setting.<br>
                          camera2->SetFocalPoint(0, 0, -1);     
                       //setting this to (0,0,0) causes whole modelview
                      matrix to be 0, regardless of what
                      SetModelTransformMatrix() sets<br>
                          camera2->SetViewAngle(60);<br>
                          camera2->SetClippingRange(0.1, 5000);<br>
                          double modelViewTransform[16] = { 1, 0, 0, 0,<br>
                              0, 1, 0, 0,<br>
                              0, 0, 1, -1000,<br>
                              0, 0, 0, 1 };<br>
                         
                      camera2->SetModelTransformMatrix(modelViewTransform);<br>
                      <br>
                          // renderer1 using camera1<br>
                          vtkSmartPointer<vtkRenderer> renderer1 =
                      vtkSmartPointer<vtkRenderer>::New();<br>
                          renderer1->SetViewport(0, 0, 0.5, 1);<br>
                          renderer1->AddVolume(generateVolume());<br>
                          renderer1->SetActiveCamera(camera1);<br>
                      <br>
                          // renderer2 using camera2<br>
                          vtkSmartPointer<vtkRenderer> renderer2 =
                      vtkSmartPointer<vtkRenderer>::New();<br>
                          renderer2->SetViewport(0.5, 0, 1, 1);<br>
                          renderer2->AddVolume(generateVolume());<br>
                          renderer2->SetActiveCamera(camera2);<br>
                      <br>
                          // assert model view matrices are the same<br>
                          vtkSmartPointer<vtkMatrix4x4>
                      vtkModelViewMatrix1 =
                      renderer1->GetActiveCamera()->GetModelViewTransformMatrix();<br>
                          vtkSmartPointer<vtkMatrix4x4>
                      vtkModelViewMatrix2 =
                      renderer2->GetActiveCamera()->GetModelViewTransformMatrix();<br>
                          for (int i = 0; i < 4; ++i)<br>
                              for (int j = 0; j < 4; ++j)<br>
                                 
                      assert(vtkModelViewMatrix1->GetElement(i, j) ==
                      vtkModelViewMatrix2->GetElement(i, j));<br>
                      <br>
                          // window and interactor<br>
                          vtkSmartPointer<vtkRenderWindow>
                      renderWindow =
                      vtkSmartPointer<vtkRenderWindow>::New();<br>
                          renderWindow->SetSize(1024, 512);<br>
                          renderWindow->AddRenderer(renderer1);<br>
                          renderWindow->AddRenderer(renderer2);<br>
                         
                      vtkSmartPointer<vtkRenderWindowInteractor>
                      renderWindowInteractor =
                      vtkSmartPointer<vtkRenderWindowInteractor>::New();<br>
                         
                      renderWindowInteractor->SetRenderWindow(renderWindow);<br>
                      <br>
                          renderWindow->Render();<br>
                          renderWindowInteractor->Start();<br>
                      <br>
                          return EXIT_SUCCESS;<br>
                      }<br>
                      <br>
                      <br>
                      Thank you very much.<br>
                      <br>
                      <br>
                      _______________________________________________<br>
                      Powered by <a moz-do-not-send="true"
                        href="http://www.kitware.com" rel="noreferrer"
                        target="_blank">www.kitware.com</a><br>
                      <br>
                      Visit other Kitware open-source projects at <a
                        moz-do-not-send="true"
                        href="http://www.kitware.com/opensource/opensource.html"
                        rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
                      <br>
                      Please keep messages on-topic and check the VTK
                      FAQ at: <a moz-do-not-send="true"
                        href="http://www.vtk.org/Wiki/VTK_FAQ"
                        rel="noreferrer" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
                      <br>
                      Search the list archives at: <a
                        moz-do-not-send="true"
                        href="http://markmail.org/search/?q=vtkusers"
                        rel="noreferrer" target="_blank">http://markmail.org/search/?q=vtkusers</a><br>
                      <br>
                      Follow this link to subscribe/unsubscribe:<br>
                      <a moz-do-not-send="true"
                        href="http://public.kitware.com/mailman/listinfo/vtkusers"
                        rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/vtkusers</a><br>
                      <br>
                    </blockquote>
                  </div>
                </div>
              </blockquote>
              <br>
            </blockquote>
            <br>
          </div>
          _______________________________________________<br>
          Powered by <a moz-do-not-send="true"
            href="http://www.kitware.com" rel="noreferrer"
            target="_blank">www.kitware.com</a><br>
          <br>
          Visit other Kitware open-source projects at <a
            moz-do-not-send="true"
            href="http://www.kitware.com/opensource/opensource.html"
            rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
          <br>
          Please keep messages on-topic and check the VTK FAQ at: <a
            moz-do-not-send="true"
            href="http://www.vtk.org/Wiki/VTK_FAQ" rel="noreferrer"
            target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
          <br>
          Search the list archives at: <a moz-do-not-send="true"
            href="http://markmail.org/search/?q=vtkusers"
            rel="noreferrer" target="_blank">http://markmail.org/search/?q=vtkusers</a><br>
          <br>
          Follow this link to subscribe/unsubscribe:<br>
          <a moz-do-not-send="true"
            href="http://public.kitware.com/mailman/listinfo/vtkusers"
            rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/vtkusers</a><br>
        </blockquote>
      </div>
    </blockquote>
    <br>
  </body>
</html>