0

I've found the Eigen::Map class for converting a raw array to an Eigen class (and some useful snippets here https://stackoverflow.com/a/12007784/1136458 )

Is there any Eigen or vtk class to convert a vtk array to an Eigen class (and back)? What I am trying right now is:

But I get the following error:

error C2665: 'Eigen::Map::Map' : none of the 4 overloads could convert all the argument types

I don't necessarily need the intermediate cpp_matrix, if there is a direct method that would be fine as well

Community
  • 1
  • 1
lib
  • 2,918
  • 3
  • 27
  • 53
  • You write `curTuple` from `vtk_arr->GetTuple(i, curTuple)` component-wise to `cpp_matrix` [there](http://stackoverflow.com/questions/24650468/how-to-get-the-the-values-of-a-vtkdoublearray-in-a-stdvector#24650468). Why dont you write it directly component-wise into the `Eigen::Matrix`? – Tobias Jul 09 '14 at 10:41
  • I just started this way because I hoped that there existed some method in vtk like GetRawArray, so that I could do: eig_arr = map(vtk_arr->getRawData). But yes, since I have already implemented how to scan the vtkarray I can just adapt that code. – lib Jul 09 '14 at 11:23

2 Answers2

1

The memory layout of a std::vector<std::vector<double> > is not compatible with what Eigen::Map is expecting. All entries must be sequentially stored in memory with an optional constant space between each column. So if the memory layout of vtkDoubleArray is not comptable, then you have no other choice but copy the values using a manual for loop.

ggael
  • 28,425
  • 2
  • 65
  • 71
0

What about converting vtkMappedDataArray to Eigen::matrix?

I stumpled upon "vtkMappedDataArray" and this discussion about "InSituDataStructures" for VTK. Unfortunatly I don't know any details but maybe it helps. Please let us know.

Frank
  • 1
  • Thank you, I didn't know about this! At a first glance it seems the use of vtkmappedarray is opposite to mine: it should map external data in a vtkarray. But I found an interesting reference to the getvoidpointer method , I could try that or getvoidpointer. – lib Jul 09 '14 at 18:04