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