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
MultiPointCloud.hpp
lvr2::floatArr
boost::shared_array< float > floatArr
Definition: DataStruct.hpp:133
lvr2::PointCloudAttribute
Definition: MultiPointCloud.hpp:51
lvr2::indexPair
std::pair< size_t, size_t > indexPair
Definition: DataStruct.hpp:162
lvr2::MultiPointCloud::model
virtual ModelPtr model()
Definition: MultiPointCloud.cpp:120
lvr2::MultiPointCloud::MultiPointCloud
MultiPointCloud(ModelPtr model, string name="<unnamed point cloud>")
Definition: MultiPointCloud.cpp:40
lvr2::Renderable::isActive
bool isActive()
Definition: Renderable.hpp:89
lvr2::indexArray
boost::shared_array< unsigned int > indexArray
Definition: DataStruct.hpp:128
lvr2::Renderable::m_model
ModelPtr m_model
Definition: Renderable.hpp:167
lvr2::MultiPointCloud::removeCloud
void removeCloud(PointCloud *pc)
Definition: MultiPointCloud.cpp:115
lvr2::PointBufferPtr
std::shared_ptr< PointBuffer > PointBufferPtr
Definition: PointBuffer.hpp:130
p
SharedPointer p
Definition: ConvertShared.hpp:42
lvr2::PointBuffer
A class to handle point information with an arbitrarily large number of attribute channels....
Definition: PointBuffer.hpp:51
lvr2::PointCloud::updateDisplayLists
void updateDisplayLists()
Definition: PointCloud.cpp:134
lvr2::BaseVector::x
CoordT x
Definition: BaseVector.hpp:65
lvr2::Model
Definition: Model.hpp:51
lvr2::ColorVertex::r
ColorT r
Definition: ColorVertex.hpp:158
lvr2::pc_attr_it
map< PointCloud *, PointCloudAttribute * >::iterator pc_attr_it
Definition: MultiPointCloud.hpp:60
lvr2::MultiPointCloud::m_clouds
map< PointCloud *, PointCloudAttribute * > m_clouds
Definition: MultiPointCloud.hpp:94
lvr2::Renderable::setName
virtual void setName(string s)
Definition: Renderable.hpp:82
lvr2::Renderable::m_boundingBox
BoundingBox< Vec > * m_boundingBox
Definition: Renderable.hpp:165
lvr2::Renderable::boundingBox
BoundingBox< Vec > * boundingBox()
Definition: Renderable.hpp:124
lvr2::BaseVector::y
CoordT y
Definition: BaseVector.hpp:66
lvr2::PointCloud
Definition: PointCloud.hpp:59
scripts.create_png.colors
colors
Definition: create_png.py:41
lvr2::BoundingBox
A dynamic bounding box class.
Definition: BoundingBox.hpp:49
lvr2::ColorVertex::b
ColorT b
Definition: ColorVertex.hpp:158
lvr2::BaseVector::z
CoordT z
Definition: BaseVector.hpp:67
lvr2::MultiPointCloud::init
void init(PointBufferPtr buffer)
Definition: MultiPointCloud.cpp:54
lvr2::MultiPointCloud::addCloud
void addCloud(PointCloud *pc)
Definition: MultiPointCloud.cpp:107
lvr2::ucharArr
boost::shared_array< unsigned char > ucharArr
Definition: DataStruct.hpp:137
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::ColorVertex::g
ColorT g
Definition: ColorVertex.hpp:158
lvr2::ModelPtr
std::shared_ptr< Model > ModelPtr
Definition: Model.hpp:80
lvr2::PointCloud::m_points
vector< uColorVertex > m_points
Definition: PointCloud.hpp:94
lvr2::ColorVertex
A color vertex.
Definition: ColorVertex.hpp:50
lvr2::PointCloudAttribute::cloud
PointCloud * cloud
Definition: MultiPointCloud.hpp:54
lvr2::PointCloud::addPoint
void addPoint(float x, float y, float z, unsigned char r, unsigned char g, unsigned char b)
Definition: PointCloud.hpp:72


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 Wed Mar 2 2022 00:37:24