select1DTool.cpp
Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00039 
00040 #include <algorithm>
00041 #include <GL/gl.h>
00042 #include <pcl/apps/point_cloud_editor/select1DTool.h>
00043 #include <pcl/apps/point_cloud_editor/cloud.h>
00044 #include <pcl/apps/point_cloud_editor/selection.h>
00045 #include <pcl/apps/point_cloud_editor/localTypes.h>
00046 
00047 Select1DTool::Select1DTool (SelectionPtr selection_ptr, CloudPtr cloud_ptr)
00048   : selection_ptr_(selection_ptr), cloud_ptr_(cloud_ptr)
00049 {
00050 }
00051 
00052 void
00053 Select1DTool::end (int x, int y, BitMask modifiers, BitMask buttons)
00054 {
00055   if (!cloud_ptr_)
00056     return;
00057   if (!(buttons & LEFT))
00058     return;
00059 
00060   unsigned int index = 0;
00061   union
00062   {
00063     unsigned char pixel[4];// XXX - assume uchar = 1 byte
00064     unsigned int id;
00065   } u;
00066   // XXX - The following assumes sizeof(unsigned int) == 4 bytes
00067   glPushAttrib(GL_COLOR_BUFFER_BIT | GL_PIXEL_MODE_BIT | GL_HINT_BIT |
00068                GL_LINE_BIT | GL_POINT_BIT);
00069   {
00070     glDisable(GL_POINT_SMOOTH);
00071     glDisable(GL_LINE_SMOOTH);
00072     glDisable( GL_BLEND );
00073     glClearColor(0,0,0,0);
00074     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00075     GLint viewport[4];
00076     glGetIntegerv(GL_VIEWPORT, viewport);
00077     IncIndex inc(1);// start the indexing from 1, since the clear color is 0
00078     unsigned int *index_arr = new unsigned int[cloud_ptr_->size()];
00079     std::generate_n(index_arr, cloud_ptr_->size(), inc);
00080 
00081     glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
00082     {
00083       glEnableClientState(GL_COLOR_ARRAY);
00084       glColorPointer(4, GL_UNSIGNED_BYTE, 0, index_arr);
00085       cloud_ptr_->draw(true);
00086       glReadPixels(x, viewport[3] - y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, u.pixel);
00087     }
00088     glPopClientAttrib();
00089     delete [] index_arr;
00090   }
00091   glPopAttrib();
00092 
00093   if (!u.id)
00094     return; // no selection - they did not hit a point
00095 
00096   // the color buffer used [1,n] to color the points - retrieve the point index
00097   index = u.id-1;
00098 
00099   if (modifiers & SHFT)
00100   {
00101     selection_ptr_->addIndex(index);
00102   }
00103   else if (modifiers & CTRL)
00104   {
00105     selection_ptr_->removeIndex(index);
00106   }
00107   else
00108   {
00109     selection_ptr_->clear();
00110     selection_ptr_->addIndex(index);
00111   }
00112   cloud_ptr_->setSelection(selection_ptr_);
00113 }


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:33:22