MultiPointCloud.cpp
Go to the documentation of this file.
1 
36 
37 namespace lvr2
38 {
39 
41 {
42 
43  PointBufferPtr buffer = model->m_pointCloud;
44  init(buffer);
45  m_model = model;
46 }
47 
49 {
50  m_model = ModelPtr(new Model(buffer));
51  init(buffer);
52 }
53 
55 {
56  if(buffer)
57  {
59  size_t numSubClouds;
60  size_t dummy;
61 
62  indexArray subClouds = buffer->getIndexArray("sub_clouds", numSubClouds, dummy);
63 
64  vector<indexPair> pairs;
65  pairs.reserve(numSubClouds);
66  for (size_t i = 0; i < numSubClouds; i++)
67  {
68  pairs[i].first = subClouds[i*2 + 0];
69  pairs[i].second = subClouds[i*2 + 1];
70  }
71 
72  vector<indexPair>::iterator it;
73 
74  int c(1);
75  size_t n = buffer->numPoints();
76  size_t w_color;
77  floatArr points = buffer->getPointArray();
78  ucharArr colors = buffer->getColorArray(w_color);
79 
80  for(it = pairs.begin(); it != pairs.end(); it ++)
81  {
82  indexPair p = *it;
83 
84  // Create new point cloud from scan
85  PointCloud* pc = new PointCloud;
86  for(size_t a = p.first; a <= p.second; a++)
87  {
88  if(colors)
89  {
90  pc->addPoint(points[a*3 + 0], points[a*3 + 1], points[a*3 + 2], colors[a*3 + 0], colors[a*3 + 1], colors[a*3 + 2]);
91  }
92  else
93  {
94  pc->addPoint(points[a*3 + 0], points[a*3 + 1], points[a*3 + 2], 255, 0, 0);
95  }
96  }
97  stringstream ss;
98 
99  pc->updateDisplayLists();
100  pc->setName(ss.str());
101  addCloud(pc);
102  c++;
103  }
104  }
105 }
106 
108 {
110  a->cloud = pc;
111  m_clouds[pc] = a;
112  m_boundingBox->expand(*(pc->boundingBox()));
113 }
114 
116 {
117  m_clouds.erase(pc);
118 }
119 
121 {
122 
123  // Count all points that need to be exported
124  pc_attr_it it;
125  size_t c = 0;
126  for(it = m_clouds.begin(); it != m_clouds.end(); it++)
127  {
128  PointCloud* pc = it->second->cloud;
129  if(pc->isActive())
130  {
131  vector<uColorVertex>::iterator p_it;
132  for(p_it = pc->m_points.begin(); p_it != pc->m_points.end(); p_it++)
133  {
134  c++;
135  }
136  }
137  }
138 
139 
140  // Create a new model and save points
141  PointBufferPtr pcBuffer(new PointBuffer);
142  floatArr pointBuffer(new float[3 * c]);
143  ucharArr colorBuffer(new unsigned char[3 * c]);
144  c = 0;
145 
146  for(it = m_clouds.begin(); it != m_clouds.end(); it++)
147  {
148  PointCloud* pc = it->second->cloud;
149  if(pc->isActive())
150  {
151  vector<uColorVertex>::iterator p_it;
152  for(p_it = pc->m_points.begin(); p_it != pc->m_points.end(); p_it++)
153  {
154  size_t bufferPos = 3 * c;
155 
156  uColorVertex v = *p_it;
157  pointBuffer[bufferPos ] = v.x;
158  pointBuffer[bufferPos + 1] = v.y;
159  pointBuffer[bufferPos + 2] = v.z;
160 
161  colorBuffer[bufferPos ] = v.r;
162  colorBuffer[bufferPos + 1] = v.g;
163  colorBuffer[bufferPos + 2] = v.b;
164 
165  c++;
166  }
167  }
168 
169  }
170 
171  pcBuffer->setPointArray(pointBuffer, c);
172  pcBuffer->setColorArray(colorBuffer, c);
173 
174  ModelPtr modelPtr(new Model);
175  modelPtr->m_pointCloud = pcBuffer;
176 
177 
178  return modelPtr;
179 }
180 
181 } // namespace lvr2
A class to handle point information with an arbitrarily large number of attribute channels...
Definition: PointBuffer.hpp:51
map< PointCloud *, PointCloudAttribute * >::iterator pc_attr_it
MultiPointCloud(ModelPtr model, string name="<unnamed point cloud>")
boost::shared_array< unsigned char > ucharArr
Definition: DataStruct.hpp:137
map< PointCloud *, PointCloudAttribute * > m_clouds
std::shared_ptr< PointBuffer > PointBufferPtr
A dynamic bounding box class.
Definition: BoundingBox.hpp:49
virtual void setName(string s)
Definition: Renderable.hpp:82
A color vertex.
Definition: ColorVertex.hpp:50
void addCloud(PointCloud *pc)
boost::shared_array< unsigned int > indexArray
Definition: DataStruct.hpp:128
void removeCloud(PointCloud *pc)
boost::shared_array< float > floatArr
Definition: DataStruct.hpp:133
SharedPointer p
void addPoint(float x, float y, float z, unsigned char r, unsigned char g, unsigned char b)
Definition: PointCloud.hpp:72
vector< uColorVertex > m_points
Definition: PointCloud.hpp:94
virtual ModelPtr model()
BoundingBox< Vec > * boundingBox()
Definition: Renderable.hpp:124
std::shared_ptr< Model > ModelPtr
Definition: Model.hpp:80
BoundingBox< Vec > * m_boundingBox
Definition: Renderable.hpp:165
std::pair< size_t, size_t > indexPair
Definition: DataStruct.hpp:162
void updateDisplayLists()
Definition: PointCloud.cpp:134
void init(PointBufferPtr buffer)


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Mon Feb 28 2022 22:46:08