<!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"><<a moz-do-not-send="true"
href="mailto:mrapsouthern@gmail.com">mrapsouthern@gmail.com</a>></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;">
Hi,<br>
<br>
Im trying to view a regular 3D grid of points using
vtkImageData. 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, 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>
for(int z = 1; z < H-1;z++)<br>
{<br>
for(int y = 1; y < W-1;y++)<br>
{<br>
for(int x = 1; x < L-1;x++)<br>
{<br>
p[offset1+(z*L*W)+(y*W)+x] = (1.0/6.0)*<br>
(p[offset2+((z+1)*L*W)+(y*W)+x] +<br>
p[offset2+((z-1)*L*W)+(y*W)+x] +<br>
p[offset2+(z*L*W)+((y+1)*W)+x]
+<br>
p[offset2+(z*L*W)+((y-1)*W)+x] +<br>
p[offset2+(z*L*W)+(y*W)+x+1] +<br>
p[offset2+(z*L*W)+(y*W)+x-1]) -<br>
p[offset1+(z*L*W)+(y*W)+x];<br>
}<br>
}<br>
}<br>
<br>
return 0;<br>
}<br>
<br>
int main (int argc, char *argv[])<br>
{<br>
<br>
// Setup Scalar Data Memory<br>
int L = 100; // Set Length/Width/Height of Pressure grid<br>
int W = 50;<br>
int H = 100;<br>
int numPoints = L*W*H;<br>
float* pressure;<br>
pressure = new float [2*numPoints]; // There are two
pressure grids; we only want to view the first one though...<br>
float** viewPressure;<br>
viewPressure = new float* [numPoints];<br>
<br>
//Create any required VTK objects<br>
vtkSmartPointer<vtkFloatArray> vtkPressure =
vtkSmartPointer<vtkFloatArray>::New();<br>
vtkSmartPointer<vtkImageData> imageData =
vtkSmartPointer<vtkImageData>::New();<br>
vtkSmartPointer<vtkLookupTable> table =
vtkSmartPointer<vtkLookupTable>::New();<br>
vtkSmartPointer<vtkImageMapToColors> color =
vtkSmartPointer<vtkImageMapToColors>::New();<br>
vtkSmartPointer<vtkImageActor> imActor =
vtkSmartPointer<vtkImageActor>::New();<br>
vtkSmartPointer<vtkRenderer> ren =
vtkSmartPointer<vtkRenderer>::New();<br>
vtkSmartPointer<vtkRenderWindow> renWin =
vtkSmartPointer<vtkRenderWindow>::New();<br>
vtkSmartPointer<vtkRenderWindowInteractor> iren =
vtkSmartPointer<vtkRenderWindowInteractor>::New();<br>
<br>
// Specify the size of the image data<br>
imageData->SetDimensions(W,L,H);<br>
imageData->SetOrigin(0,0,0);<br>
imageData->SetSpacing(1.0,1.0,1.0);<br>
imageData->SetNumberOfScalarComponents(1);<br>
imageData->SetScalarTypeToFloat();<br>
imageData->AllocateScalars();<br>
<br>
<br>
int* dims = imageData->GetDimensions();<br>
std::cout << "ImageData Dimensions: " << "x: "
<< dims[0] << " y: " << dims[1] << "
z: " << dims[2] << std::endl;<br>
<br>
//Initialize pressure across grid to zero<br>
for(int z = 0; z < H;z++)<br>
{<br>
for(int y = 0; y < W;y++)<br>
{<br>
for(int x = 0; x < L;x++)<br>
{<br>
pressure[(z*L*W)+(y*W)+x] = 0.0;<br>
pressure[numPoints+(z*L*W)+(y*W)+x] = 0.0;<br>
viewPressure[(y*W)+x] =
&pressure[(z*L*W)+(y*W)+x];<br>
}<br>
}<br>
}<br>
<br>
// Now point imageData to the pressure vector points<br>
vtkPressure->SetArray(*viewPressure,L*W,1);<br>
imageData->GetPointData()->SetScalars(vtkPressure);<br>
vtkPressure->Modified();<br>
<br>
// Create a scale lookup table<br>
double r = 0;<br>
double g = 0;<br>
double b = 1.0;<br>
table->SetRange(-0.02, 0.02); // image intensity range<br>
table->SetNumberOfTableValues(64);<br>
for (int x = 0; x < 64 ; x++)<br>
{<br>
if (x > 32) { r = 1.0; g = g - 0.0312; b = b -
0.0312; }<br>
if (x == 32){ r = 1.0; g = 1.0; b = 1.0; }<br>
if (x < 32) { r = r + 0.0312; g = g +
0.0312; b = 1.0; }<br>
table->SetTableValue(x,r,g,b,1.0);<br>
}<br>
table->SetTableValue(32,1,1,1,1.0); // make sure middle
value is total black<br>
table->SetRampToLinear();<br>
table->Build();<br>
<br>
// Map the image through the lookup table<br>
color->SetLookupTable(table);<br>
color->SetInput(imageData);<br>
imActor->SetInput(color->GetOutput());<br>
<br>
// Setup Interactor Renderer, RenderWindow etc...<br>
ren->AddActor(imActor);<br>
ren->SetBackground(0.0,0.0,0.0);<br>
renWin->SetInteractor(iren);<br>
renWin->AddRenderer(ren);<br>
renWin->Render();<br>
<br>
//Initial Condition - Set a pressure point to non-zero<br>
int xi = 20; int yi = 40; int zi = 36;<br>
pressure[(zi*L*W)+(yi*W)+xi] = 100.0;<br>
<br>
int T = 50; //Set number of time steps<br>
int offset1 = numPoints;<br>
int offset2 = 0;<br>
int tmp = 0;<br>
<br>
for (int t = 0; t < T; t++)<br>
{<br>
<br>
cout << t << endl;<br>
RunMockSimulationStep(L,W,H,offset1,offset2,pressure,numPoints);<br>
<br>
//Update Pressure Field View Here<br>
// How?<br>
vtkPressure->Modified();<br>
renWin->Render();<br>
<br>
// cycle offset<br>
tmp = offset1;<br>
offset1 = offset2;<br>
offset2 = tmp;<br>
}<br>
<br>
system("pause");<br>
delete []pressure;<br>
delete []viewPressure;<br>
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>