Question

I am creating a gridcell class which is basically a multi array of cells. I want this gridcell to have any number of dimensions. This means that in the declaration of the boost::multiarray variable I cannot specify the second argument of the template. Concretely, my code looks as follows:

#include "cell.h"
#include <iostream>
#include <vector>
#include <boost/multi_array.hpp>

class GridCell {
public: 
    GridCell(); // Default constructor not used.
    GridCell(const std::vector<int> dims, const float leafsize);
    virtual ~GridCell();

    friend std::ostream& operator << (std::ostream & os, const GridCell & c);

private:
    std::vector<int> dims_; // Vector containing the size of each dimension.
    float leafsize_; // It is assumed that the cells in the grid are cubic.
    boost::multi_array<Cell,ndims> * grid;
};

Concretely, boost::multi_array * grid; The number of dimensions I want it to be specified in the Gridcell class constructor.

Any advice or alternative?

Thank you very much!

Was it helpful?

Solution

In order to close the question, I add this answer:

Finally I solved the problem by creating a self-made container based on arrays. Initially it was based on vectors, but I preferred to go to arrays by determining the number of dimensions and the maximum size. In this case, I think tis approach is better than using boost multi_array since my container is actually a flat array and the element indexing is generalized by mathematical operations.

Thank you for your replies.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top