<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
<br>
<blockquote
cite="mid:AANLkTi=Eadi4pGaWstZDMZkOz-_jVVa6-68wzDbDxg7H@mail.gmail.com"
type="cite">
<div dir="ltr"><span class="Apple-style-span"
style="font-family: arial,sans-serif; font-size: 13px; border-collapse: collapse;">
<div><span class="Apple-style-span"
style="font-family: arial,sans-serif; font-size: 13px; border-collapse: collapse;"><br>
</span></div>
<div>I think, the same code should work fine if you use a 1D double
array instead of 2D.</div>
<div><br>
</div>
<div>Prathamesh</div>
<div><span class="Apple-style-span"
style="font-family: arial,sans-serif; font-size: 13px; border-collapse: collapse;"><br>
</span></div>
<br>
</span></div>
</blockquote>
<br>
Prathamesh,<br>
<br>
Thank you very much for your response; this is greatly appreciated! I
tried changing my example code to use a 1D double array, but I still
receive a similar result. The window that is displayed by VTK shows
only "garbage" data. The rendered data appears as a series of white
lines which I believe to be indicative of uninitialized memory.<br>
<br>
What am I doing wrong with my example code? Perhaps I am not utilizing
the SetWholeExtent() and SetDataExtent() functions properly? Might
there be another way to display the matrix?<br>
<br>
Here is the example function that I am now attempting to run. What I
now do is copy the data into a 1D array before passing it into the
SetImportVoidPointer() function:<br>
<br>
void test_VTK()<br>
{<br>
std::string fileName = "M.txt";<br>
double deltax = 1.0e-3;<br>
double deltay = 1.0e-3;<br>
int Nx = 1000;<br>
int Ny = 1000;<br>
int PML_num = 20;<br>
<br>
int Nxp = Nx + 2 * PML_num;<br>
int Nyp = Ny + 2 * PML_num;<br>
<br>
TNT::Array2D<double> M(Nxp, Nyp);<br>
//double **pm;<br>
load_matrix( fileName, &M );<br>
<br>
vtkSmartPointer<vtkImageImport> import =<br>
vtkSmartPointer<vtkImageImport>::New();<br>
<br>
// copy into 1D Array<br>
std::cout << "Copying data " << std::endl;<br>
int num = Nxp * Nyp;<br>
TNT::Array1D<double> pm(num);<br>
std::cout << "Have now created the matrix" << std::endl;<br>
int counter = 0;<br>
for(int i = 0; i < Nxp; i++)<br>
{<br>
for(int j = 0; j < Nyp; j++)<br>
{<br>
pm[counter++] = M[i][j];<br>
<br>
}<br>
}<br>
std::cout << "Finishing copying data" << std::endl;<br>
<br>
import->SetImportVoidPointer((void*)pm);<br>
import->SetWholeExtent(0,Nxp,0,Nyp,0,0);<br>
import->SetDataExtent(0,Nxp,0,Nyp,0,0);<br>
<br>
//vtkSmartPointer<vtkImageData> data =<br>
// vtkSmartPointer<vtkImageData>::New();<br>
//data->setDimensions( 1040, 1040, 0 );<br>
<br>
vtkSmartPointer<vtkLookupTable> lookupTable =<br>
vtkSmartPointer<vtkLookupTable>::New();<br>
<br>
vtkSmartPointer<vtkScalarBarActor> colorbar =<br>
vtkSmartPointer<vtkScalarBarActor>::New();<br>
<br>
// add a colorbar<br>
lookupTable->SetNumberOfColors(9344);<br>
lookupTable->SetTableRange(0,10);<br>
lookupTable->ForceBuild();<br>
<br>
colorbar->SetLookupTable(lookupTable);<br>
colorbar->SetWidth(0.05);<br>
colorbar->SetPosition(0.95, 0.1);<br>
colorbar->SetLabelFormat("%.3g");<br>
colorbar->PickableOff();<br>
colorbar->VisibilityOn();<br>
<br>
//std::string bunny = "633px-Bunny.jpg";<br>
<br>
//read the image<br>
//vtkSmartPointer<vtkJPEGReader> jPEGReader =<br>
// vtkSmartPointer<vtkJPEGReader>::New();<br>
//jPEGReader->SetFileName ( bunny.c_str() );<br>
//jPEGReader->Update();<br>
<br>
vtkSmartPointer<vtkImageViewer2> viewer =<br>
vtkSmartPointer<vtkImageViewer2>::New();<br>
viewer->SetInput(import->GetOutput());<br>
viewer->SetInput( import->GetOutput() );<br>
<br>
//setup renderer<br>
vtkSmartPointer<vtkRenderer> renderer =<br>
vtkSmartPointer<vtkRenderer>::New();<br>
renderer->AddActor ( viewer->GetImageActor() );<br>
renderer->AddActor(colorbar);<br>
renderer->ResetCamera();<br>
<br>
//setup render window<br>
vtkSmartPointer<vtkRenderWindow> renderWindow =<br>
vtkSmartPointer<vtkRenderWindow>::New();<br>
renderWindow->AddRenderer ( renderer );<br>
<br>
//setup render window interactor<br>
vtkSmartPointer<vtkRenderWindowInteractor>
renderWindowInteractor =<br>
vtkSmartPointer<vtkRenderWindowInteractor>::New();<br>
vtkSmartPointer<vtkInteractorStyleImage> style =<br>
vtkSmartPointer<vtkInteractorStyleImage>::New();<br>
<br>
renderWindowInteractor->SetInteractorStyle( style );<br>
<br>
//render and start interaction<br>
renderWindowInteractor->SetRenderWindow ( renderWindow );<br>
renderWindowInteractor->Initialize();<br>
renderWindowInteractor->Start();<br>
<br>
<br>
} // end function<br>
<br>
</body>
</html>