<div dir="ltr">Hi Nicholas,<div><br></div><div>At a first glance, it appears that you could try doing the following changes:</div><div><br></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; color: rgb(80, 0, 80); "> import->SetImportVoidPointer(pm);<br>
import->SetWholeExtent(0,Nxp-1,0,Nyp-1,0,0);<br> import->SetDataExtent(0,Nxp-1,0,Nyp-1,0,0);</span></div><div><font class="Apple-style-span" color="#500050" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;"><br>
</span></font></div><div><font class="Apple-style-span" color="#500050" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;"><font class="Apple-style-span" color="#000000">Also, your lookupTable does not appear to be connected to the imageActor.</font></span></font></div>
<div><font class="Apple-style-span" color="#500050" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;"><font class="Apple-style-span" color="#000000"><br></font></span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;"><br></span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">Prathamesh</span></font></div>
<div><br><div class="gmail_quote">On Sat, Aug 14, 2010 at 12:49 PM, Nicholas Kinar <span dir="ltr"><<a href="mailto:n.kinar@usask.ca">n.kinar@usask.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div bgcolor="#ffffff" text="#000000"><div class="im">
<br>
<blockquote type="cite">
<div dir="ltr"><span style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse">
<div><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 style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse"><br>
</span></div>
<br>
</span></div>
</blockquote>
<br></div>
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:<div class="im"><br>
<br>
void test_VTK()<br>
{<br>
std::string fileName = "M.txt";<br></div>
double deltax = 1.0e-3;<br>
double deltay = 1.0e-3;<div class="im"><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></div><div class="im">
vtkSmartPointer<vtkImageImport> import =<br>
vtkSmartPointer<vtkImageImport>::New();<br>
<br></div>
// 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;<div class="im"><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></div>
//vtkSmartPointer<vtkImageData> data =<br>
// vtkSmartPointer<vtkImageData>::New();<br>
//data->setDimensions( 1040, 1040, 0 );<div class="im"><br>
<br>
vtkSmartPointer<vtkLookupTable> lookupTable =<br>
vtkSmartPointer<vtkLookupTable>::New();<br>
<br>
vtkSmartPointer<vtkScalarBarActor> colorbar =<br>
vtkSmartPointer<vtkScalarBarActor>::New();<br>
<br></div>
// add a colorbar<div class="im"><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></div>
//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();<div class="im"><br>
<br>
vtkSmartPointer<vtkImageViewer2> viewer =<br>
vtkSmartPointer<vtkImageViewer2>::New();<br>
viewer->SetInput(import->GetOutput());<br>
viewer->SetInput( import->GetOutput() );<br>
<br></div>
//setup renderer<div class="im"><br>
vtkSmartPointer<vtkRenderer> renderer =<br>
vtkSmartPointer<vtkRenderer>::New();<br>
renderer->AddActor ( viewer->GetImageActor() );<br>
renderer->AddActor(colorbar);<br>
renderer->ResetCamera();<br>
<br></div>
//setup render window<div class="im"><br>
vtkSmartPointer<vtkRenderWindow> renderWindow =<br>
vtkSmartPointer<vtkRenderWindow>::New();<br>
renderWindow->AddRenderer ( renderer );<br>
<br></div>
//setup render window interactor<div class="im"><br>
vtkSmartPointer<vtkRenderWindowInteractor>
renderWindowInteractor =<br>
vtkSmartPointer<vtkRenderWindowInteractor>::New();<br>
vtkSmartPointer<vtkInteractorStyleImage> style =<br>
vtkSmartPointer<vtkInteractorStyleImage>::New();<br>
<br>
renderWindowInteractor->SetInteractorStyle( style );<br>
<br></div>
//render and start interaction<div class="im"><br>
renderWindowInteractor->SetRenderWindow ( renderWindow );<br>
renderWindowInteractor->Initialize();<br>
renderWindowInteractor->Start();<br>
<br>
<br>
} // end function<br>
<br>
</div></div>
</blockquote></div><br></div></div>