Multi-dimensional vector of arrays

I'm trying to store the inforamtions of a point in a vector. So I got three coordinates for each point. To store the information I would like to use two vectors of arrays of doubles. So my code looks like this

1
2
  std::vector<std::array<double, 3>> matrix;
  std::vector<std::array<double, 3>> hull;


But in this line I get the error message:
1
2
3
4
error C2039: 'array' : is not a member of 'std'
error C2065: 'array' : undeclared identifier
error C2062: type 'double' unexpected
error C2143: syntax error : missing ';' before '>'


Can someone tell me, what I'm doing wrong?
Did you include the <array> header?
Are you using a C++11 compiler with C++11 enabled?
Thanks for the tip. I forgot the array header. But now I have a second question. For this code segment I also got an error message
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
for(auto it = matrix.begin(); it != matrix.end(); ++it)
{
       auto bestIt = matrix.end();

	double bestSquareDistance = 0.0;
			
	for(auto nextIt = it + 1; nextIt != matrix.end(); ++nextIt)
	{
		const auto squareDistance = squareDistancePoints(*it, *nextIt);
		if( squareDistance < bestSquareDistance)
		{
			bestSquareDistance = squareDistance;
			bestIt = nextIt;
		}
	}
	if(bestIt != matrix.end())
	{
		std::swap(*(it+1), *bestIt);
	}

}


The error message shows:
 
error C2664: 'squareDistancePoints' : cannot convert parameter 1 from 'std::array<_Ty,_Size>' to 'const std::vector<_Ty> &'


I marked the line bold.

For the squareDistancePoints function I use this code
1
2
3
4
5
6
7
8
double squareDistancePoints(const std::vector<double>& a, const std::vector<double>& b)
{
    assert(a.size() == b.size());
    double sum = 0;
    for(size_t i = 0; i < a.size(); ++i)
        sum += pow(a[i]-b[i], 2);
    return sum;
}
Your function is expecting a reference to a std::vector<double> as its first parameter. However, your iterator is pointing to a std::array - because that's the type of item held in your matrix vector.

Is there any reason your function needs to take a std::vector, when your point is actually represented by a std::array?
Last edited on
Hi BeKinect,

http://www.cplusplus.com/forum/beginner/191546/#msg924362

Did you see my reply to your other post? You may not need to do any of what you are doing now. Admittedly what I proposed there could be fairly involved, but at least it might be better than the current design.

I mentioned inefficiency last time, this function seems to have O(N*(N!)) - that is factorial, efficiency which is rather bad. So with only 10 points (M) the algorithm is executed 36,288,000 times to find the shortest distances for all of them. The squareDistancePoints function goes through all of a vector as well making it quadratic factorial efficiency.

What happens after you have the shortest distances? A contouring algorithm needs to find all adjacent points in the triangular mesh, not just the nearest one. So this is why Delaunay is seen as being one of the best ways of producing a contour-able TIN (Triangular Irregular Network)

Also coder777 suggestion of using a struct for a point.

Rather than use iterators like you do, if you want to go through the whole container, consider using a range based for loop:

1
2
3
4
for (const auto Elem& : matrix) {
   // your code here
   // Elem is an item in matrix
}


http://en.cppreference.com/w/cpp/language/range-for

Good Luck !!
Hi TheIdeasMan

Thanks. Yeah I saw your post and my colleague is working on this. But till we get a working function for the Delaunay Triangulation, I want to continue working on this idea. But we are working also on your approach.
Thanks man.
Ok, so you can do whatever you want - but I would seriously suggest you reconsider. Why bother with something that will be horribly inefficient? It's going to take an inordinate amount of time to do even 100 50 20 points, making it almost useless.

So you have colleagues: Is this for commercial software, or open source? Either way, you really need to consider your design: get it sorted out on paper - make sure it is going to conceptually work before doing any coding. Otherwise you will all waste lots of time by inevitably having to redo things

I am amazed you don't have a class for a Point.
Topic archived. No new replies allowed.