iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
test-PointCloudGraphics.C
3 #include <nrt/Graphics/Shapes.H>
4 #include <nrt/Graphics/Camera.H>
6 
7 NRT_DECLARE_PARAMETER(switch_through, bool, "Switch through all point cloud types, or just show cubes?", true);
8 
9 int main(int argc, char const * argv[])
10 {
11 
12  nrt::Manager mgr(argc, argv);
13 
14  auto renderer = mgr.addComponent<nrt::graphics::ShapeRendererBasic>("Renderer");
15 
16  class MyParameters : public nrt::Component, public nrt::Parameter<switch_through>
17  { using nrt::Component::Component; };
18 
19  auto params = mgr.addComponent<MyParameters>("params");
20 
21  mgr.launch();
22 
23  std::default_random_engine g((unsigned int)time(0));
24  std::uniform_real_distribution<float> loc(-10, 10);
25  std::uniform_int_distribution<nrt::byte> col(0, 255);
26 
27  int nPoints = 10000;
28 
29  nrt::PointCloud2 noneCloud = nrt::PointCloud2::create<>(nPoints);
30  nrt::PointCloud2 grayCloud = nrt::PointCloud2::create<nrt::PixGray<nrt::byte>>(nPoints);
31  nrt::PointCloud2 rgbCloud = nrt::PointCloud2::create<nrt::PixRGB<nrt::byte>>(nPoints);
32 
33  for(auto p : noneCloud.range())
34  {
35  p.geometry() = {loc(g)+25, loc(g), loc(g)};
36  }
37  for(auto p : grayCloud.range<nrt::PixGray<nrt::byte>>())
38  {
39  p.geometry() = {loc(g), loc(g), loc(g)};
41  }
42  for(auto p : rgbCloud.range<nrt::PixRGB<nrt::byte>>())
43  {
44  p.geometry() = {loc(g)-25, loc(g), loc(g)};
45  p.get<nrt::PixRGB<nrt::byte>>() = nrt::PixRGB<nrt::byte>(col(g), col(g), col(g));
46  }
47 
48  nrt::graphics::PointCloud noneGraphics(noneCloud, 3);
49  nrt::graphics::PointCloud grayGraphics(grayCloud, 3);
50  nrt::graphics::PointCloud rgbGraphics(rgbCloud, 3);
51 
52  nrt::graphics::Box boxGraphics(Eigen::Affine3f(Eigen::Translation3f(0, 0, 35)), nrt::forev(), nrt::PixRGB<uint8_t>(255, 0, 0));
53 
54  // Create a drawing context:
55  renderer->createContext();
56 
57 
58  auto delay = std::chrono::seconds(2);
59  auto switchTime = std::chrono::steady_clock::now() - delay;
60  int mode = params->switch_through::get() ? 0 : 3;
61  size_t frameCount = 0;
62  float const pointsize2D = 3.0f;
63  float const pointsize3D = 0.1f;
64  while (true)
65  {
66  if(std::chrono::steady_clock::now() > switchTime)
67  {
68  if(frameCount > 0)
69  NRT_INFO(".... Frame Rate: " << frameCount << " fps");
70  switch(mode)
71  {
72  case 0:
73  std::cout << "-----------------------" << std::endl;
74  NRT_INFO("VBO, Point");
75  noneGraphics.setUseVBO(true);
76  grayGraphics.setUseVBO(true);
77  rgbGraphics.setUseVBO(true);
78  noneGraphics.setDisplayType(nrt::graphics::PointCloud::Point);
79  grayGraphics.setDisplayType(nrt::graphics::PointCloud::Point);
80  rgbGraphics.setDisplayType(nrt::graphics::PointCloud::Point);
81  noneGraphics.setPointSize(pointsize2D);
82  grayGraphics.setPointSize(pointsize2D);
83  rgbGraphics.setPointSize(pointsize2D);
84  break;
85  case 1:
86  NRT_INFO("VBO, Sprite");
87  noneGraphics.setUseVBO(true);
88  grayGraphics.setUseVBO(true);
89  rgbGraphics.setUseVBO(true);
90  noneGraphics.setDisplayType(nrt::graphics::PointCloud::Sprite);
91  grayGraphics.setDisplayType(nrt::graphics::PointCloud::Sprite);
92  rgbGraphics.setDisplayType(nrt::graphics::PointCloud::Sprite);
93  noneGraphics.setPointSize(pointsize2D);
94  grayGraphics.setPointSize(pointsize2D);
95  rgbGraphics.setPointSize(pointsize2D);
96  break;
97  case 2:
98  NRT_INFO("VBO, Billboard");
99  noneGraphics.setUseVBO(true);
100  grayGraphics.setUseVBO(true);
101  rgbGraphics.setUseVBO(true);
102  noneGraphics.setDisplayType(nrt::graphics::PointCloud::Billboard);
103  grayGraphics.setDisplayType(nrt::graphics::PointCloud::Billboard);
104  rgbGraphics.setDisplayType(nrt::graphics::PointCloud::Billboard);
105  noneGraphics.setPointSize(pointsize3D);
106  grayGraphics.setPointSize(pointsize3D);
107  rgbGraphics.setPointSize(pointsize3D);
108  break;
109  case 3:
110  NRT_INFO("VBO, Cube");
111  noneGraphics.setUseVBO(true);
112  grayGraphics.setUseVBO(true);
113  rgbGraphics.setUseVBO(true);
114  noneGraphics.setDisplayType(nrt::graphics::PointCloud::Cube);
115  grayGraphics.setDisplayType(nrt::graphics::PointCloud::Cube);
116  rgbGraphics.setDisplayType(nrt::graphics::PointCloud::Cube);
117  noneGraphics.setPointSize(pointsize3D);
118  grayGraphics.setPointSize(pointsize3D);
119  rgbGraphics.setPointSize(pointsize3D);
120  break;
121  case 4:
122  NRT_INFO("Immediate, Point");
123  noneGraphics.setUseVBO(false);
124  grayGraphics.setUseVBO(false);
125  rgbGraphics.setUseVBO(false);
126  noneGraphics.setDisplayType(nrt::graphics::PointCloud::Point);
127  grayGraphics.setDisplayType(nrt::graphics::PointCloud::Point);
128  rgbGraphics.setDisplayType(nrt::graphics::PointCloud::Point);
129  noneGraphics.setPointSize(pointsize2D);
130  grayGraphics.setPointSize(pointsize2D);
131  rgbGraphics.setPointSize(pointsize2D);
132  break;
133  case 5:
134  NRT_INFO("Immediate, Sprite");
135  noneGraphics.setUseVBO(false);
136  grayGraphics.setUseVBO(false);
137  rgbGraphics.setUseVBO(false);
138  noneGraphics.setDisplayType(nrt::graphics::PointCloud::Sprite);
139  grayGraphics.setDisplayType(nrt::graphics::PointCloud::Sprite);
140  rgbGraphics.setDisplayType(nrt::graphics::PointCloud::Sprite);
141  noneGraphics.setPointSize(pointsize2D);
142  grayGraphics.setPointSize(pointsize2D);
143  rgbGraphics.setPointSize(pointsize2D);
144  break;
145  case 6:
146  NRT_INFO("Immediate, Billboard");
147  noneGraphics.setUseVBO(false);
148  grayGraphics.setUseVBO(false);
149  rgbGraphics.setUseVBO(false);
150  noneGraphics.setDisplayType(nrt::graphics::PointCloud::Billboard);
151  grayGraphics.setDisplayType(nrt::graphics::PointCloud::Billboard);
152  rgbGraphics.setDisplayType(nrt::graphics::PointCloud::Billboard);
153  noneGraphics.setPointSize(pointsize3D);
154  grayGraphics.setPointSize(pointsize3D);
155  rgbGraphics.setPointSize(pointsize3D);
156  break;
157  case 7:
158  NRT_INFO("Immediate, Cube");
159  noneGraphics.setUseVBO(false);
160  grayGraphics.setUseVBO(false);
161  rgbGraphics.setUseVBO(false);
162  noneGraphics.setDisplayType(nrt::graphics::PointCloud::Cube);
163  grayGraphics.setDisplayType(nrt::graphics::PointCloud::Cube);
164  rgbGraphics.setDisplayType(nrt::graphics::PointCloud::Cube);
165  noneGraphics.setPointSize(pointsize3D);
166  grayGraphics.setPointSize(pointsize3D);
167  rgbGraphics.setPointSize(pointsize3D);
168  break;
169  }
170 
171  if (params->switch_through::get())
172  mode = (mode+1) % 8;
173  switchTime = std::chrono::steady_clock::now() + delay;
174  frameCount = 0;
175  }
176  ++frameCount;
177 
178  renderer->initFrame();
179 
180  noneGraphics.render(*renderer);
181  grayGraphics.render(*renderer);
182  rgbGraphics.render(*renderer);
183 
184  boxGraphics.render(*renderer);
185 
186  renderer->renderFrame();
187  }
188 
189 }