2016-10-04 6 views
-1

センサから行データを取得しています(距離は&です)。これをC++のベクトルコンテナに保存しています。 OpenGLを使用し
が、私はそれを視覚化しています
Sensor in the middle and get distance of any obstacle within 100 meter range around 360° は、今私は(クラスタリング目的のために)いくつかの要因に基づいてデータを分割し、新しい個々のベクター(複数可)にそれらを保存したいしたい(下の写真をご覧ください)。 問題は、私はいくつのクラスターが得られるのか分からないので、必要なベクトルの数について考えません。
誰もがこの方法を知っています。共有してください。C++のベクトルのランタイムメモリ

+5

したがって、ベクトルのベクトルを使用しますか? –

+0

いいえ、しないでください。ベクトルを使用し、上に2Dインデックスをビューとしてマップします。 –

答えて

1

これは、ベクトルのベクトルのように聞こえる。

// Vector of vector that will contain all your clusters 
std::vector<std::vector<DATA>> clusters; 

// everytime you have a new cluster you can then do something like : 
std::vector<DATA> currentCluster; 

// You add the data to the cluster 
currentCluster.emplace_back(/* The data */) 

// You then add the currentCluster to the group of clusters. 
clusters.emplace_back(currentCluster); 
+0

'clusters.emplace_back'を検討しますか? – Bathsheba

+0

いいえ、この回答を入力している間、私はjoachimのコメントが表示されませんでした^^ – Scriptodude

+0

http://stackoverflow.com/questions/4303513/push-back-vs-emplace-back 私は彼がC++ 0xノルムなので、C++ 98標準では完全に同等です。 – Scriptodude