copy data from Armadillo matrix to vtkFloatArray


I use armadillo as math library and I would like to use VTK library to plot data.
Is there a way to prepare data for plotting like:

fvec(100) DATA; // armadillo vector of type float
DATA.ones(100); // sets all 100 elements equal to 1
vtkNew !!!TRIANGULAR BRACKETS AREN’t SHOWN HERE!!! vtkFloatArray arrC;
arrC->SetArray(DATA, DATA.size(), 1);

I’m beginner in programming so any help I would appreciate,

Best regards,

Hello, here’s how I populate vtk*Arrays:

    //create a VTK array to store the values
    vtkSmartPointer<vtkFloatArray> values = vtkSmartPointer<vtkFloatArray>::New();

    for( uint i = 0; i < DATA.size(); ++i ){
        float value = .... ; //insert your object's element getter here
        values->InsertNextValue( value );

Enclose your code block between two ``` one before the 1st line and the other after the last line. :wink:

kind regards,


1 Like

Thank for reply
Actually there is also another solution with Armadillo matrix tha looks like:
arrC->SetArray(DATA.memptr(), DATA.size(), 1);
But anyway, thank for help :slight_smile:

So, what’s the issue?

When I found the solution arrC->SetArray(DATA.memptr(), DATA.size(), 1); the issue was solved :slight_smile: