-
arrays arrays arrays....
Hi there,
i have a Problem with converting one Array into another.
The Starter Array is a vector Template of a struct, the targetarray is a static float array.
The Array is needed so i have a common array to put into vtkData.
Here the piece of Code:
(Red is the "criticalcode")
Code:
#include <stdio.h>
#include <iostream>
#include <vector>
struct SimpVec
{
float coordx;
float coordy;
float coordz;
};
vector<SimpVec> vecs2;
void pcavis2(vector<SimpVec> vecs2)
{
cout << "Starting Visualisation" << endl;
int i;
static float vecs2f[][3];
//ExampleArray
//static float x[3][3]={{0,0.5,0.7}, {0.3,0.9,0.2}, {1,1,1}};
//Checking if the given Vector has elements
cout << vecs2.size() << endl;
//Put Vectordata into a float array
for (int j=0; j < vecs2.size(); j++){
vecs2f[i][0] = vecs2[i].coordx;
vecs2f[i][1] = vecs2[i].coordy;
vecs2f[i][2] = vecs2[i].coordz;
};
//Create testdata and put Scalars and Points into it
vtkPolyData *testdata = vtkPolyData::New();
vtkPoints *testpoints = vtkPoints::New();
vtkFloatArray *testScalars = vtkFloatArray::New();
for (i=0; i < vecs2.size(); i++) testpoints->InsertPoint(i, vecs2f[i]);
.
.
.
The rest is of the code is plain visualisaion and has no meaning in this Problem.
Thanks in Advance!
Jan
-
static float vecs2f[][3];
You are declaring an array with no size. Try this instead:
static float* vecs2f[3];
vecs2f[0]=new float[vecs.size()];
vecs2f[1]=new float[vecs.size()];
vecs2f[2]=new float[vecs.size()];
By doing this, you are going to have to reverse the way you access the elements. vecs2f[0][2] will have to be vecs2f[2][0] in my solution. You could also use a vector if you don't want to have to reverse the way you access the elements.