<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <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 class="moz-txt-link-freetext" href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/Lighting/Light">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 class="moz-cite-prefix">On 08/05/16 14:10, David E DeMarle
      wrote:<br>
    </div>
    <blockquote
cite="mid:CANjZAi-YCfuwQTo-w0XKMXrZP4Ox=DTS+xShOOcqu37Y+hxAEg@mail.gmail.com"
      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">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/Ex<wbr>amples/Cxx/VolumeRendering/Sma<wbr>rtVolumeMapper</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>::Ne<wbr>w();<br>
                sphere->SetRadius(0.1);<br>
                sphere->SetCenter(0.0, 0.0, 0.0);<br>
            <br>
                vtkSmartPointer<vtkSampleFunct<wbr>ion>
            sampleFunction = vtkSmartPointer<vtkSampleFunct<wbr>ion>::New();<br>
                sampleFunction->SetImplicitFun<wbr>ction(sphere);<br>
                sampleFunction->SetOutputScala<wbr>rTypeToFloat();<br>
                sampleFunction->SetSampleDimen<wbr>sions(64, 64, 20);<br>
                sampleFunction->SetModelBounds<wbr>(-1.0, 1.0, -1.0,
            1.0, -1.0, 1.0);<br>
                sampleFunction->SetCapping(fal<wbr>se);<br>
                sampleFunction->SetComputeNorm<wbr>als(false);<br>
                sampleFunction->SetScalarArray<wbr>Name("values");<br>
                sampleFunction->Update();<br>
            <br>
                vtkDataArray* a = sampleFunction->GetOutput()->G<wbr>etPointData()->GetScalars("val<wbr>ues");<br>
                double range[2];<br>
                a->GetRange(range);<br>
            <br>
                vtkSmartPointer<vtkImageShiftS<wbr>cale> t =
            vtkSmartPointer<vtkImageShiftS<wbr>cale>::New();<br>
                t->SetInputConnection(sampleFu<wbr>nction->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->SetOutputScalarTypeToUnsign<wbr>edChar();<br>
                t->Update();<br>
            <br>
                vtkSmartPointer<vtkImageData> imageData =
            vtkSmartPointer<vtkImageData>:<wbr>:New();<br>
                imageData->ShallowCopy(t->GetO<wbr>utput());<br>
            <br>
                vtkSmartPointer<vtkSmartVolume<wbr>Mapper>
            volumeMapper = vtkSmartPointer<vtkSmartVolume<wbr>Mapper>::New();<br>
                volumeMapper->SetBlendModeToCo<wbr>mposite(); //
            composite first<br>
                volumeMapper->SetInputData(ima<wbr>geData);<br>
            <br>
                vtkSmartPointer<vtkVolumePrope<wbr>rty>
            volumeProperty = vtkSmartPointer<vtkVolumePrope<wbr>rty>::New();<br>
                volumeProperty->ShadeOff();<br>
            volumeProperty->SetInterpolati<wbr>onType(VTK_LINEAR_<wbr>INTERPOLATION);<br>
            <br>
                vtkSmartPointer<vtkPiecewiseFu<wbr>nction>
            compositeOpacity = vtkSmartPointer<vtkPiecewiseFu<wbr>nction>::New();<br>
                compositeOpacity->AddPoint(0.0<wbr>, 0.0);<br>
                compositeOpacity->AddPoint(80.<wbr>0, 1.0);<br>
                compositeOpacity->AddPoint(80.<wbr>1, 0.0);<br>
                compositeOpacity->AddPoint(255<wbr>.0, 0.0);<br>
                volumeProperty->SetScalarOpaci<wbr>ty(compositeOpacity);
            // composite first.<br>
            <br>
                vtkSmartPointer<vtkColorTransf<wbr>erFunction>
            color = vtkSmartPointer<vtkColorTransf<wbr>erFunction>::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<wbr>);<br>
            <br>
                vtkSmartPointer<vtkVolume> volume =
            vtkSmartPointer<vtkVolume>::Ne<wbr>w();<br>
                volume->SetMapper(volumeMapper<wbr>);<br>
                volume->SetProperty(volumeProp<wbr>erty);<br>
            <br>
                vtkSmartPointer<vtkMatrix4x4> volumeScaleTransform
            = vtkSmartPointer<vtkMatrix4x4>:<wbr>:New();<br>
                volumeScaleTransform->Identity<wbr>();<br>
                volumeScaleTransform->SetEleme<wbr>nt(0, 0, 512);<br>
                volumeScaleTransform->SetEleme<wbr>nt(1, 1, 512);<br>
                volumeScaleTransform->SetEleme<wbr>nt(2, 2, 160);<br>
                volume->SetUserMatrix(volumeSc<wbr>aleTransform);<br>
                return volume;<br>
            }<br>
            <br>
            int main()<br>
            {<br>
                // camera1<br>
                vtkSmartPointer<vtkCamera> camera1 =
            vtkSmartPointer<vtkCamera>::Ne<wbr>w();<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>::Ne<wbr>w();<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->SetModelTransformMatr<wbr>ix(modelViewTransform);<br>
            <br>
                // renderer1 using camera1<br>
                vtkSmartPointer<vtkRenderer> renderer1 =
            vtkSmartPointer<vtkRenderer>::<wbr>New();<br>
                renderer1->SetViewport(0, 0, 0.5, 1);<br>
                renderer1->AddVolume(generateV<wbr>olume());<br>
                renderer1->SetActiveCamera(cam<wbr>era1);<br>
            <br>
                // renderer2 using camera2<br>
                vtkSmartPointer<vtkRenderer> renderer2 =
            vtkSmartPointer<vtkRenderer>::<wbr>New();<br>
                renderer2->SetViewport(0.5, 0, 1, 1);<br>
                renderer2->AddVolume(generateV<wbr>olume());<br>
                renderer2->SetActiveCamera(cam<wbr>era2);<br>
            <br>
                // assert model view matrices are the same<br>
                vtkSmartPointer<vtkMatrix4x4> vtkModelViewMatrix1
            = renderer1->GetActiveCamera()-><wbr>GetModelViewTransformMatrix();<br>
                vtkSmartPointer<vtkMatrix4x4> vtkModelViewMatrix2
            = renderer2->GetActiveCamera()-><wbr>GetModelViewTransformMatrix();<br>
                for (int i = 0; i < 4; ++i)<br>
                    for (int j = 0; j < 4; ++j)<br>
                        assert(vtkModelViewMatrix1->Ge<wbr>tElement(i,
            j) == vtkModelViewMatrix2->GetElemen<wbr>t(i, j));<br>
            <br>
                // window and interactor<br>
                vtkSmartPointer<vtkRenderWindo<wbr>w> renderWindow
            = vtkSmartPointer<vtkRenderWindo<wbr>w>::New();<br>
                renderWindow->SetSize(1024, 512);<br>
                renderWindow->AddRenderer(rend<wbr>erer1);<br>
                renderWindow->AddRenderer(rend<wbr>erer2);<br>
                vtkSmartPointer<vtkRenderWindo<wbr>wInteractor>
            renderWindowInteractor = vtkSmartPointer<vtkRenderWindo<wbr>wInteractor>::New();<br>
                renderWindowInteractor->SetRen<wbr>derWindow(renderWindow);<br>
            <br>
                renderWindow->Render();<br>
                renderWindowInteractor->Start(<wbr>);<br>
            <br>
                return EXIT_SUCCESS;<br>
            }<br>
            <br>
            <br>
            Thank you very much.<br>
            <br>
            <br>
            ______________________________<wbr>_________________<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/<wbr>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_<wbr>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=<wbr>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/<wbr>mailman/listinfo/vtkusers</a><br>
            <br>
          </blockquote>
        </div>
      </div>
    </blockquote>
    <br>
  </body>
</html>