<div>Hello. I created the matrices in matlab and saved them to a binary file. I then use vnl to manipulate these matrices on the fly in vtk.</div>
<div>I made it work now, by first importing the data into itk, and then connect it to vtk using the provided connectPipelines() function.</div>
<div>I don&#39;t know what the error was, but it had something to do with the importfilter, since this is where the data went wrong.</div>
<div>Thank you for your answers.<br><br>&nbsp;</div>
<div><span class="gmail_quote">2007/1/15, Luis Ibanez &lt;<a href="mailto:luis.ibanez@kitware.com">luis.ibanez@kitware.com</a>&gt;:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><br>Hi Arne,<br><br><br>You may want to check your program in several intermediate locations.<br><br><br>1) Inside the method&nbsp;&nbsp;&quot;importData()&quot; you should check writing
<br>&nbsp;&nbsp; out the vtkImageData in a .vtk file and then open it using<br>&nbsp;&nbsp; ParaView (<a href="http://www.paraview.org">www.paraview.org</a>). This will verify if the import<br>&nbsp;&nbsp; process work well or not.<br><br><br>2) If (1) works fine, then you should try wrting out the vtkImageData
<br>&nbsp;&nbsp; just after returning from the importData() function. This will<br>&nbsp;&nbsp; verify if there is any reference counting issue that may have<br>&nbsp;&nbsp; deleted your image when returning from the function.<br><br><br>3) What exactly are you trying to import ?
<br>&nbsp;&nbsp; Is this an image that you created with ITK ?<br>&nbsp;&nbsp; From your email, it seems that you are importing a matrix<br>&nbsp;&nbsp; that you created with vnl...<br><br>&nbsp;&nbsp; How did you created that file ?<br>&nbsp;&nbsp; Did you created the file in the same machine ?
<br>&nbsp;&nbsp; (e.g. can you discard endianness problems ?)<br><br><br>Please let us know<br><br><br>&nbsp;&nbsp;Thanks<br><br><br>&nbsp;&nbsp;&nbsp;&nbsp; Luis<br><br><br><br>------------------<br>Arne Hansen wrote:<br>&gt; Hello all. I am (still) having problems getting my data correct read
<br>&gt; into vtk. I have a really strange problem which i absolutely dont<br>&gt; understand. I read in the data from binary files...that goes well. Then<br>&gt; i put it into a vnl_matrix(goes also well) and extract a certain part of
<br>&gt; this matrix, import this subpart into a vtkImageData with 3 dimensions<br>&gt; using the itkImageImport class.<br>&gt; When i then try to use this image data, the application crashes because<br>&gt; the data has not been put there correctly is my assumption.
<br>&gt; When i call the print() function for the vtkImageData object it tells me<br>&gt; that there are the 97*110*129 = 1376430 which there should be. The<br>&gt; GetEstimatedMemorySize() and GetActualMemorySize() also returns more or
<br>&gt; less the correct amount in kb. To check that the values of data is<br>&gt; correct I have tried calling GetDataScalarPointer() to get access to the<br>&gt; data kept inside this object.<br>&gt; When i then iterate this data in my unique(...) function(my own, see
<br>&gt; below), and print the values, it seems that at position 344107 it<br>&gt; assumes value -4.2e037, and thereafter -9.1e041and followed by zeros up<br>&gt; until index 345072 where the application crashes.<br>&gt; And it should be able to print out 1376430 elements, since this is the
<br>&gt; size of the image.<br>&gt;<br>&gt; Furthermore, the application crashes if i try to render the image.<br>&gt;<br>&gt; So I was hoping someone with a bit more experience with me could take a<br>&gt; quick look at my code and see if it looks completely wrong. I am really
<br>&gt; stuck here, and I dont understand why the data is not there, when it<br>&gt; should be, and vtk actually tells me that it is there.<br>&gt;<br>&gt; I have copied my program listing below for ease of understanding my
<br>&gt; problem. I really hope for help since i am pretty stuck here.<br>&gt; Thank you very much in advance<br>&gt; - H<br>&gt;<br>&gt; #include&lt;cstdio&gt;<br>&gt; #include &lt;fstream&gt;<br>&gt; #include &lt;vtkImageData.h
&gt;<br>&gt; #include &quot;vtkImageImport.h&quot; //Import images for VTK<br>&gt; #include &quot;vtkActor.h&quot;<br>&gt; #include &quot;vtkOutlineFilter.h &quot;<br>&gt; #include &quot;vtkPolyDataMapper.h&quot;<br>&gt; #include &quot;
vtkRenderWindow.h&quot;<br>&gt; #include &quot;vtkRenderer.h&quot;<br>&gt; #include &quot;vtkRenderWindowInteractor.h&quot;<br>&gt; #include &quot;vtkLight.h&quot;<br>&gt; #include &quot;vtkCamera.h&quot;<br>&gt; #include &quot;
vtkContourFilter.h&quot;<br>&gt; #include &quot;vtkProperty.h&quot;<br>&gt;<br>&gt; #include&lt;map&gt;<br>&gt; #include &lt;vnl/vnl_matrix.h&gt;<br>&gt;<br>&gt; typedef float SDMdatatype;<br>&gt; typedef vnl_matrix&lt;SDMdatatype&gt; mat;
<br>&gt;<br>&gt; int D[]={110,129,97};<br>&gt; unsigned int N=((*D)*(*(D+1))*(*(D+2))); //numel(vol)<br>&gt; unsigned short m=1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Shape count<br>&gt; unsigned short sm=7;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Significant modes chosen<br>&gt; mat meanShape(N*m,1);
<br>&gt;<br>&gt; SDMdatatype* readArrayFromFile(char* fn,long size){<br>&gt;&nbsp;&nbsp;std::ifstream file;<br>&gt;&nbsp;&nbsp;file.open(fn,std::ios::in|std::ios::binary);<br>&gt;&nbsp;&nbsp;if (!file) { printf(&quot;file was not opened, issue error msg&quot;); }
<br>&gt;&nbsp;&nbsp;SDMdatatype* buffer;<br>&gt;&nbsp;&nbsp;buffer = new SDMdatatype[size];<br>&gt;&nbsp;&nbsp;file.read(reinterpret_cast&lt;char*&gt;(buffer), sizeof (SDMdatatype) *<br>&gt; size);//static_cast &lt;char *&gt; buffer<br>&gt;&nbsp;&nbsp;file.close
();<br>&gt;&nbsp;&nbsp;return buffer;<br>&gt; }<br>&gt;<br>&gt; vtkImageData* importData(SDMdatatype *data1,int *dims){<br>&gt;&nbsp;&nbsp;vtkImageImport *importer = vtkImageImport::New();<br>&gt;&nbsp;&nbsp;importer-&gt;SetDataScalarTypeToFloat();<br>
&gt;&nbsp;&nbsp;importer-&gt;SetDataOrigin(0,0,0);<br>&gt;&nbsp;&nbsp;//importer-&gt;SetImportVoidPointer(data1);<br>&gt;&nbsp;&nbsp;importer-&gt;CopyImportVoidPointer(data1,N);<br>&gt;<br>&gt;&nbsp;&nbsp;importer-&gt;SetWholeExtent(0,dims[0]-1,0,dims[1]-1,0,dims[2]-1);//If not
<br>&gt; 3D image set 3D extent = 0.<br>&gt;&nbsp;&nbsp;importer-&gt;SetDataExtentToWholeExtent();<br>&gt;<br>&gt;&nbsp;&nbsp;importer-&gt;Update();<br>&gt;<br>&gt;&nbsp;&nbsp;vtkImageData *img=importer-&gt;GetOutput();<br>&gt;&nbsp;&nbsp;img-&gt;Update();<br>&gt;&nbsp;&nbsp;return img;
<br>&gt; }<br>&gt;<br>&gt; void loadPCAResults(){<br>&gt;&nbsp;&nbsp;SDMdatatype* b1=readArrayFromFile(<br>&gt;&nbsp;&nbsp; &quot;C:\\thesisIntermediate\\meanshape.dat&quot;,<br>&gt;&nbsp;&nbsp;N*m);<br>&gt;<br>&gt;&nbsp;&nbsp;meanShape.copy_in(b1);<br>&gt;&nbsp;&nbsp;delete b1;
<br>&gt; }<br>&gt; void unique(SDMdatatype* data, int size,bool print){<br>&gt;&nbsp;&nbsp;typedef std::map&lt;SDMdatatype,long&gt; pixHistType;<br>&gt;&nbsp;&nbsp;pixHistType hist;<br>&gt;<br>&gt;&nbsp;&nbsp;for(int k=0;k&lt;size;k++){<br>&gt;&nbsp;&nbsp; //printf(&quot;%x\n&quot;,data[k]);
<br>&gt;&nbsp;&nbsp; std::cout&lt;&lt;k&lt;&lt;&quot; : &quot;&lt;&lt;*(data+k)&lt;&lt;std::endl;<br>&gt;&nbsp;&nbsp; SDMdatatype val=data[k];<br>&gt;&nbsp;&nbsp; //mexPrintf(&quot;%4i\n&quot;,val);<br>&gt;&nbsp;&nbsp; hist[val]++;<br>&gt;&nbsp;&nbsp;}<br>&gt;&nbsp;&nbsp;if(print){
<br>&gt;&nbsp;&nbsp; pixHistType::iterator iter;<br>&gt;&nbsp;&nbsp; for(iter = hist.begin(); iter != hist.end(); ++iter)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; std::cout&lt;&lt;&quot;[&quot;&lt;&lt;iter-&gt;first&lt;&lt;&quot;]:[&quot;&lt;&lt;iter-&gt;second&lt;&lt;&quot;]&quot;&lt;&lt;std::endl;
<br>&gt;&nbsp;&nbsp;}<br>&gt; }<br>&gt;<br>&gt; int main(int argc,char* argv[])<br>&gt; {<br>&gt;&nbsp;&nbsp;loadPCAResults();<br>&gt;<br>&gt;&nbsp;&nbsp;//structure actors<br>&gt;&nbsp;&nbsp;vtkActor *Temporopolar_region_left_actor&nbsp;&nbsp;= vtkActor::New();<br>&gt;<br>
&gt;&nbsp;&nbsp;//rendering objects<br>&gt;&nbsp;&nbsp;vtkRenderer *aRenderer = vtkRenderer::New();<br>&gt;&nbsp;&nbsp;vtkRenderWindow *renWin = vtkRenderWindow::New();<br>&gt;&nbsp;&nbsp;vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();<br>&gt;&nbsp;&nbsp;vtkCamera *aCamera = vtkCamera::New();
<br>&gt;<br>&gt;&nbsp;&nbsp;// Get vols from SDM<br>&gt;&nbsp;&nbsp;//extract(height,width,top,left)<br>&gt;&nbsp;&nbsp;mat t=meanShape.extract(N,1, 0,0);<br>&gt;&nbsp;&nbsp;SDMdatatype* b=t.data_block();<br>&gt;&nbsp;&nbsp;vtkImageData *Temporopolar_region_left_data = importData(b,D);
<br>&gt;<br>&gt;&nbsp;&nbsp;Temporopolar_region_left_data-&gt;Update();<br>&gt;&nbsp;&nbsp;Temporopolar_region_left_data-&gt;UpdateInformation();<br>&gt;&nbsp;&nbsp;Temporopolar_region_left_data-&gt;PropagateUpdateExtent();<br>&gt;<br>&gt;&nbsp;&nbsp;SDMdatatype* a =
<br>&gt; (SDMdatatype*)Temporopolar_region_left_data-&gt;GetScalarPointer();<br>&gt;<br>&gt;&nbsp;&nbsp;unique(a,N,1);<br>&gt;<br>&gt;&nbsp;&nbsp;vtkContourFilter *contours = vtkContourFilter::New();<br>&gt;&nbsp;&nbsp;contours-&gt;SetInput(Temporopolar_region_left_data);
<br>&gt;&nbsp;&nbsp;contours-&gt;SetValue(0,0);<br>&gt;<br>&gt;&nbsp;&nbsp;vtkPolyDataMapper *mpr = vtkPolyDataMapper::New();<br>&gt;&nbsp;&nbsp;mpr-&gt;SetInput(contours-&gt;GetOutput());<br>&gt;<br>&gt;&nbsp;&nbsp;Temporopolar_region_left_actor -&gt; SetMapper(mpr);
<br>&gt;&nbsp;&nbsp;Temporopolar_region_left_actor -&gt; GetProperty() -&gt; SetDiffuseColor(1.,<br>&gt; 0., 0.);<br>&gt;&nbsp;&nbsp;Temporopolar_region_left_actor -&gt; GetProperty() -&gt; SetSpecularPower(50);<br>&gt;&nbsp;&nbsp;Temporopolar_region_left_actor -&gt; GetProperty() -&gt; SetSpecular(
0.5);<br>&gt;&nbsp;&nbsp;Temporopolar_region_left_actor -&gt; GetProperty() -&gt; SetDiffuse( 0.8);<br>&gt;<br>&gt;&nbsp;&nbsp;// Actors are added to the renderer.<br>&gt;&nbsp;&nbsp;aRenderer-&gt;AddActor(Temporopolar_region_left_actor);<br>&gt;<br>&gt;&nbsp;&nbsp;iren-&gt;SetRenderWindow(renWin);
<br>&gt;&nbsp;&nbsp;renWin-&gt;AddRenderer(aRenderer);<br>&gt;&nbsp;&nbsp;aRenderer-&gt;SetActiveCamera(aCamera);<br>&gt;<br>&gt;&nbsp;&nbsp;// Setting the color and size of the renderwindow,<br>&gt;&nbsp;&nbsp;// initializing the camera position<br>&gt;<br>&gt;&nbsp;&nbsp;// Here we go!
<br>&gt;&nbsp;&nbsp;iren-&gt;Initialize();<br>&gt;&nbsp;&nbsp;renWin-&gt;Render();<br>&gt;&nbsp;&nbsp;iren-&gt;Start();<br>&gt;&nbsp;&nbsp;//////////////////////////////////////////////////////////////////////////////////<br>&gt;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CLEAN UP&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //
<br>&gt;&nbsp;&nbsp;//////////////////////////////////////////////////////////////////////////////////<br>&gt;<br>&gt;<br>&gt;&nbsp;&nbsp;aCamera-&gt;Delete();<br>&gt;&nbsp;&nbsp;aRenderer-&gt;Delete();<br>&gt;&nbsp;&nbsp;renWin-&gt;Delete();<br>&gt;&nbsp;&nbsp;iren-&gt;Delete();
<br>&gt; }<br>&gt;<br>&gt;<br>&gt; ------------------------------------------------------------------------<br>&gt;<br>&gt; _______________________________________________<br>&gt; This is the private VTK discussion list.<br>
&gt; Please keep messages on-topic. Check the FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ">http://www.vtk.org/Wiki/VTK_FAQ</a><br>&gt; Follow this link to subscribe/unsubscribe:<br>&gt; <a href="http://www.vtk.org/mailman/listinfo/vtkusers">
http://www.vtk.org/mailman/listinfo/vtkusers</a><br></blockquote></div><br>