| 49 | } |
| 50 | |
| 51 | void |
| 52 | Select1DTool::end (int x, int y, BitMask modifiers, BitMask buttons) |
| 53 | { |
| 54 | if (!cloud_ptr_) |
| 55 | return; |
| 56 | if (!(buttons & LEFT)) |
| 57 | return; |
| 58 | |
| 59 | unsigned int index = 0; |
| 60 | union |
| 61 | { |
| 62 | unsigned char pixel[4];// XXX - assume uchar = 1 byte |
| 63 | unsigned int id; |
| 64 | } u; |
| 65 | // XXX - The following assumes sizeof(unsigned int) == 4 bytes |
| 66 | glPushAttrib(GL_COLOR_BUFFER_BIT | GL_PIXEL_MODE_BIT | GL_HINT_BIT | |
| 67 | GL_LINE_BIT | GL_POINT_BIT); |
| 68 | { |
| 69 | glDisable(GL_POINT_SMOOTH); |
| 70 | glDisable(GL_LINE_SMOOTH); |
| 71 | glDisable( GL_BLEND ); |
| 72 | glClearColor(0,0,0,0); |
| 73 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
| 74 | GLint viewport[4]; |
| 75 | glGetIntegerv(GL_VIEWPORT, viewport); |
| 76 | IncIndex inc(1);// start the indexing from 1, since the clear color is 0 |
| 77 | unsigned int *index_arr = new unsigned int[cloud_ptr_->size()]; |
| 78 | std::generate_n(index_arr, cloud_ptr_->size(), inc); |
| 79 | |
| 80 | glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT); |
| 81 | { |
| 82 | glEnableClientState(GL_COLOR_ARRAY); |
| 83 | glColorPointer(4, GL_UNSIGNED_BYTE, 0, index_arr); |
| 84 | cloud_ptr_->draw(true); |
| 85 | glReadPixels(x, viewport[3] - y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, u.pixel); |
| 86 | } |
| 87 | glPopClientAttrib(); |
| 88 | delete [] index_arr; |
| 89 | } |
| 90 | glPopAttrib(); |
| 91 | |
| 92 | if (!u.id) |
| 93 | return; // no selection - they did not hit a point |
| 94 | |
| 95 | // the color buffer used [1,n] to color the points - retrieve the point index |
| 96 | index = u.id-1; |
| 97 | |
| 98 | if (modifiers & SHFT) |
| 99 | { |
| 100 | selection_ptr_->addIndex(index); |
| 101 | } |
| 102 | else if (modifiers & CTRL) |
| 103 | { |
| 104 | selection_ptr_->removeIndex(index); |
| 105 | } |
| 106 | else |
| 107 | { |
| 108 | selection_ptr_->clear(); |
nothing calls this directly
no test coverage detected