<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#ffffff" text="#000000">
    Hi,<br>
    <br>
    Thanks for the reply, unfortunately I'm properly stumped,
    vtkSmartVolumeMapper sounds promising but its not installed (not a
    clue where to start), can't find anything useful on
    vtkGPURayCastMapper and the only example I found using
    vtkFixedPointVolumeRayCastMapper at<br>
    <br>
    <a
href="http://www.paraview.org/Wiki/VTK/Examples/Cxx/VolumeRendering/MinIntensityRendering">http://www.paraview.org/Wiki/VTK/Examples/Cxx/VolumeRendering/MinIntensityRendering</a><br>
    <br>
    which is a bad example of volume rendering (IMHO), has almost put me
    off using VTK for this portion of the project if that is the best on
    offer.<br>
    <br>
    Can anyone show me an example or at least a screenshot of some
    volume rendered data that will at least show that VTK can do this
    well and give me some incentive to carry on with it?<br>
    <br>
    Thanks<br>
    Alex<br>
    <br>
    On 23.9.2010 13:41, Shashwath T.R. wrote:
    <blockquote
      cite="mid:AANLkTim+XwEZOr9XwLhGGYKScOGSfU2T-uu2FgojXhY7@mail.gmail.com"
      type="cite">Hi Alex,<br>
      <br>
      You'll need to view it as a volume, not a vtkImageActor.
      vtkImageActor is purely 2D.<br>
      <br>
      Take a look at this example (if you don't have
      vtkSmartVolumeMapper, you can use vtkFixedPointVolumeRayCastMapper
      or vtkGPURayCastMapper): <a moz-do-not-send="true"
href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/VolumeRendering/SmartVolumeMapper">http://www.vtk.org/Wiki/VTK/Examples/Cxx/VolumeRendering/SmartVolumeMapper</a><br>
      <br>
      Regards,<br>
      Shash<br>
      <br>
      <div class="gmail_quote">On Thu, Sep 23, 2010 at 2:50 PM, Alex
        Southern <span dir="ltr">&lt;<a moz-do-not-send="true"
            href="mailto:mrapsouthern@gmail.com">mrapsouthern@gmail.com</a>&gt;</span>
        wrote:<br>
        <blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
          0.8ex; border-left: 1px solid rgb(204, 204, 204);
          padding-left: 1ex;">
          &nbsp;Hi,<br>
          <br>
          Im trying to view a regular 3D grid of points using
          vtkImageData. &nbsp; Each point is a single scalar that is mapped
          to a color.<br>
          I've included the complete source code and cmakelists.txt file
          of a simplified problem scenario.<br>
          <br>
          Basically, can someone confirm that they also do not see a
          cuboid but instead a 2D plane, why is this?<br>
          <br>
          In addition, &nbsp;the render window is not updated after each
          iteration as I intended. What am I doing wrong?<br>
          <br>
          (Note the source is called ImageSlicing.cpp, but I am not at
          the stage of the slicing yet, I want to view the whole 3D
          pressure field first)<br>
          <br>
          Thanks<br>
          Alex<br>
          <br>
          // ----------- CmakeLists.txt ------------------<br>
          <br>
          cmake_minimum_required(VERSION 2.6)<br>
          <br>
          PROJECT(ImageSlicing)<br>
          <br>
          FIND_PACKAGE(VTK REQUIRED)<br>
          INCLUDE(${VTK_USE_FILE})<br>
          <br>
          ADD_EXECUTABLE(ImageSlicing ImageSlicing.cpp)<br>
          TARGET_LINK_LIBRARIES(ImageSlicing vtkHybrid vtkWidgets)<br>
          <br>
          //------------------------------ End Cmakelists.txt<br>
          <br>
          // --------------------------Start ImageSlicing.cpp
          ----------------------------------------<br>
          #include "vtkSmartPointer.h"<br>
          #include "vtkImageReslice.h"<br>
          #include "vtkLookupTable.h"<br>
          #include "vtkImageMapToColors.h"<br>
          #include "vtkImageActor.h"<br>
          #include "vtkRenderer.h"<br>
          #include "vtkRenderWindow.h"<br>
          #include "vtkRenderWindowInteractor.h"<br>
          #include "vtkInteractorStyleImage.h"<br>
          #include "vtkCommand.h"<br>
          #include "vtkImageData.h"<br>
          #include "vtkPointData.h"<br>
          #include "vtkProperty.h"<br>
          #include "vtkFloatArray.h";<br>
          #include "vtkLookupTable.h";<br>
          #include "vtkScalarBarActor.h";<br>
          #include "vtkImageMapToColors.h";<br>
          <br>
          int RunMockSimulationStep(int L, int W, int H, int offset1,
          int offset2, float* p, int numPoints)<br>
          {<br>
          <br>
          &nbsp; &nbsp; &nbsp; &nbsp;for(int z = 1; z &lt; H-1;z++)<br>
          &nbsp; &nbsp; &nbsp; &nbsp;{<br>
          &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for(int y = 1; y &lt; W-1;y++)<br>
          &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br>
          &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for(int x = 1; x &lt; L-1;x++)<br>
          &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br>
          &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;p[offset1+(z*L*W)+(y*W)+x] = (1.0/6.0)*<br>
          &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(p[offset2+((z+1)*L*W)+(y*W)+x] +<br>
          &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;p[offset2+((z-1)*L*W)+(y*W)+x] +<br>
          &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;p[offset2+(z*L*W)+((y+1)*W)+x]
          +<br>
          &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
          &nbsp;p[offset2+(z*L*W)+((y-1)*W)+x] +<br>
          &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
          &nbsp;p[offset2+(z*L*W)+(y*W)+x+1] +<br>
          &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
          &nbsp;p[offset2+(z*L*W)+(y*W)+x-1]) -<br>
          &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
          &nbsp;p[offset1+(z*L*W)+(y*W)+x];<br>
          &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
          &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
          &nbsp; &nbsp; &nbsp; &nbsp;}<br>
          <br>
          &nbsp; &nbsp;return 0;<br>
          }<br>
          <br>
          int main (int argc, char *argv[])<br>
          {<br>
          <br>
          &nbsp; &nbsp;// Setup Scalar Data Memory<br>
          &nbsp; &nbsp;int L = 100; // Set Length/Width/Height of Pressure grid<br>
          &nbsp; &nbsp;int W = 50;<br>
          &nbsp; &nbsp;int H = 100;<br>
          &nbsp; &nbsp;int numPoints = L*W*H;<br>
          &nbsp; &nbsp;float* pressure;<br>
          &nbsp; &nbsp;pressure = new float [2*numPoints]; // There are two
          pressure grids; we only want to view the first one though...<br>
          &nbsp; &nbsp;float** viewPressure;<br>
          &nbsp; &nbsp;viewPressure = new float* [numPoints];<br>
          <br>
          &nbsp; &nbsp;//Create any required VTK objects<br>
          &nbsp; &nbsp;vtkSmartPointer&lt;vtkFloatArray&gt; vtkPressure =
          vtkSmartPointer&lt;vtkFloatArray&gt;::New();<br>
          &nbsp; &nbsp;vtkSmartPointer&lt;vtkImageData&gt; imageData =
          vtkSmartPointer&lt;vtkImageData&gt;::New();<br>
          &nbsp; &nbsp;vtkSmartPointer&lt;vtkLookupTable&gt; table =
          vtkSmartPointer&lt;vtkLookupTable&gt;::New();<br>
          &nbsp; &nbsp;vtkSmartPointer&lt;vtkImageMapToColors&gt; color =
          vtkSmartPointer&lt;vtkImageMapToColors&gt;::New();<br>
          &nbsp; &nbsp;vtkSmartPointer&lt;vtkImageActor&gt; imActor =
          vtkSmartPointer&lt;vtkImageActor&gt;::New();<br>
          &nbsp; &nbsp;vtkSmartPointer&lt;vtkRenderer&gt; ren =
          vtkSmartPointer&lt;vtkRenderer&gt;::New();<br>
          &nbsp; &nbsp;vtkSmartPointer&lt;vtkRenderWindow&gt; renWin =
          vtkSmartPointer&lt;vtkRenderWindow&gt;::New();<br>
          &nbsp; &nbsp;vtkSmartPointer&lt;vtkRenderWindowInteractor&gt; iren =
          vtkSmartPointer&lt;vtkRenderWindowInteractor&gt;::New();<br>
          <br>
          &nbsp; &nbsp;// Specify the size of the image data<br>
          &nbsp; &nbsp;imageData-&gt;SetDimensions(W,L,H);<br>
          &nbsp; &nbsp;imageData-&gt;SetOrigin(0,0,0);<br>
          &nbsp; &nbsp;imageData-&gt;SetSpacing(1.0,1.0,1.0);<br>
          &nbsp; &nbsp;imageData-&gt;SetNumberOfScalarComponents(1);<br>
          &nbsp; &nbsp;imageData-&gt;SetScalarTypeToFloat();<br>
          &nbsp; &nbsp;imageData-&gt;AllocateScalars();<br>
          <br>
          <br>
          &nbsp; &nbsp;int* dims = imageData-&gt;GetDimensions();<br>
          &nbsp; &nbsp;std::cout &lt;&lt; "ImageData Dimensions: " &lt;&lt; "x: "
          &lt;&lt; dims[0] &lt;&lt; " y: " &lt;&lt; dims[1] &lt;&lt; "
          z: " &lt;&lt; dims[2] &lt;&lt; std::endl;<br>
          <br>
          &nbsp; &nbsp;//Initialize pressure across grid to zero<br>
          &nbsp; &nbsp;for(int z = 0; z &lt; H;z++)<br>
          &nbsp; &nbsp;{<br>
          &nbsp; &nbsp; &nbsp; &nbsp;for(int y = 0; y &lt; W;y++)<br>
          &nbsp; &nbsp; &nbsp; &nbsp;{<br>
          &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for(int x = 0; x &lt; L;x++)<br>
          &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br>
          &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pressure[(z*L*W)+(y*W)+x] = 0.0;<br>
          &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pressure[numPoints+(z*L*W)+(y*W)+x] = 0.0;<br>
          &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;viewPressure[(y*W)+x] =
          &amp;pressure[(z*L*W)+(y*W)+x];<br>
          &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
          &nbsp; &nbsp; &nbsp; &nbsp;}<br>
          &nbsp; &nbsp;}<br>
          <br>
          &nbsp; &nbsp;// Now point imageData to the pressure vector points<br>
          &nbsp; &nbsp;vtkPressure-&gt;SetArray(*viewPressure,L*W,1);<br>
          &nbsp; &nbsp;imageData-&gt;GetPointData()-&gt;SetScalars(vtkPressure);<br>
          &nbsp; &nbsp;vtkPressure-&gt;Modified();<br>
          <br>
          &nbsp; &nbsp;// Create a scale lookup table<br>
          &nbsp; &nbsp;double r = 0;<br>
          &nbsp; &nbsp;double g = 0;<br>
          &nbsp; &nbsp;double b = 1.0;<br>
          &nbsp; &nbsp;table-&gt;SetRange(-0.02, 0.02); // image intensity range<br>
          &nbsp; &nbsp;table-&gt;SetNumberOfTableValues(64);<br>
          &nbsp; &nbsp;for (int x = 0; x &lt; 64 ; x++)<br>
          &nbsp; &nbsp; &nbsp; &nbsp;{<br>
          &nbsp; &nbsp; &nbsp; &nbsp;if (x &gt; 32) { &nbsp; &nbsp;r = 1.0; g = g - 0.0312; b = b -
          0.0312; &nbsp; &nbsp;}<br>
          &nbsp; &nbsp; &nbsp; &nbsp;if (x == 32){ &nbsp; &nbsp;r = 1.0; g = 1.0; b = 1.0; &nbsp; &nbsp;}<br>
          &nbsp; &nbsp; &nbsp; &nbsp;if (x &lt; 32) &nbsp; &nbsp;{ &nbsp; &nbsp;r = r + 0.0312; &nbsp; &nbsp;g = g +
          0.0312; &nbsp; &nbsp;b = 1.0; &nbsp; &nbsp;}<br>
          &nbsp; &nbsp; &nbsp; &nbsp;table-&gt;SetTableValue(x,r,g,b,1.0);<br>
          &nbsp; &nbsp;}<br>
          &nbsp; &nbsp;table-&gt;SetTableValue(32,1,1,1,1.0); // make sure middle
          value is total black<br>
          &nbsp; &nbsp;table-&gt;SetRampToLinear();<br>
          &nbsp; &nbsp;table-&gt;Build();<br>
          <br>
          &nbsp; &nbsp;// Map the image through the lookup table<br>
          &nbsp; &nbsp;color-&gt;SetLookupTable(table);<br>
          &nbsp; &nbsp;color-&gt;SetInput(imageData);<br>
          &nbsp; &nbsp;imActor-&gt;SetInput(color-&gt;GetOutput());<br>
          <br>
          &nbsp; &nbsp;// Setup Interactor Renderer, RenderWindow etc...<br>
          &nbsp; &nbsp;ren-&gt;AddActor(imActor);<br>
          &nbsp; &nbsp;ren-&gt;SetBackground(0.0,0.0,0.0);<br>
          &nbsp; &nbsp;renWin-&gt;SetInteractor(iren);<br>
          &nbsp; &nbsp;renWin-&gt;AddRenderer(ren);<br>
          &nbsp; &nbsp;renWin-&gt;Render();<br>
          <br>
          &nbsp; &nbsp;//Initial Condition - Set a pressure point to non-zero<br>
          &nbsp; &nbsp;int xi = 20; int yi = 40; int zi = 36;<br>
          &nbsp; &nbsp;pressure[(zi*L*W)+(yi*W)+xi] = 100.0;<br>
          <br>
          &nbsp; &nbsp;int T = 50; //Set number of time steps<br>
          &nbsp; &nbsp;int offset1 = numPoints;<br>
          &nbsp; &nbsp;int offset2 = 0;<br>
          &nbsp; &nbsp;int tmp = 0;<br>
          <br>
          &nbsp; &nbsp;for (int t = 0; t &lt; T; t++)<br>
          &nbsp; &nbsp;{<br>
          <br>
          &nbsp; &nbsp; &nbsp; &nbsp;cout &lt;&lt; t &lt;&lt; endl;<br>
          &nbsp; &nbsp; &nbsp;
          &nbsp;RunMockSimulationStep(L,W,H,offset1,offset2,pressure,numPoints);<br>
          <br>
          &nbsp; &nbsp; &nbsp; &nbsp;//Update Pressure Field View Here<br>
          &nbsp; &nbsp; &nbsp; &nbsp;// How?<br>
          &nbsp; &nbsp; &nbsp; &nbsp;vtkPressure-&gt;Modified();<br>
          &nbsp; &nbsp; &nbsp; &nbsp;renWin-&gt;Render();<br>
          <br>
          &nbsp; &nbsp; &nbsp; &nbsp;// cycle offset<br>
          &nbsp; &nbsp; &nbsp; &nbsp;tmp = offset1;<br>
          &nbsp; &nbsp; &nbsp; &nbsp;offset1 = offset2;<br>
          &nbsp; &nbsp; &nbsp; &nbsp;offset2 = tmp;<br>
          &nbsp; &nbsp;}<br>
          <br>
          &nbsp; &nbsp;system("pause");<br>
          &nbsp; &nbsp;delete []pressure;<br>
          &nbsp; &nbsp;delete []viewPressure;<br>
          &nbsp; &nbsp;return EXIT_SUCCESS;<br>
          }<br>
          <br>
          // --------------- END CPP<br>
          _______________________________________________<br>
          Powered by <a moz-do-not-send="true"
            href="http://www.kitware.com" 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"
            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" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
          <br>
          Follow this link to subscribe/unsubscribe:<br>
          <a moz-do-not-send="true"
            href="http://www.vtk.org/mailman/listinfo/vtkusers"
            target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
        </blockquote>
      </div>
      <br>
    </blockquote>
    <br>
  </body>
</html>