Commit 2f5cca39 authored by Jan Möbius's avatar Jan Möbius
Browse files

Code cleanup

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5094 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 9181c9dc
...@@ -12,12 +12,12 @@ ...@@ -12,12 +12,12 @@
// it under the terms of the GNU Lesser General Public License as published by // it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// OpenFlipper is distributed in the hope that it will be useful, // OpenFlipper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details. // GNU Lesser General Public License for more details.
// //
// You should have received a copy of the GNU Lesser General Public License // You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>. // along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
// //
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
namespace ACG { namespace ACG {
//== IMPLEMENTATION ========================================================== //== IMPLEMENTATION ==========================================================
...@@ -116,7 +116,7 @@ slotMouseEvent(QMouseEvent* _event) ...@@ -116,7 +116,7 @@ slotMouseEvent(QMouseEvent* _event)
glPushMatrix(); glPushMatrix();
glLoadIdentity(); glLoadIdentity();
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
glDisable(GL_DITHER); glDisable(GL_DITHER);
glLineWidth(2.0); glLineWidth(2.0);
...@@ -127,7 +127,7 @@ slotMouseEvent(QMouseEvent* _event) ...@@ -127,7 +127,7 @@ slotMouseEvent(QMouseEvent* _event)
// process mouse event // process mouse event
switch(_event->type()) switch(_event->type())
{ {
case QEvent::MouseButtonPress: case QEvent::MouseButtonPress:
{ {
...@@ -135,81 +135,81 @@ slotMouseEvent(QMouseEvent* _event) ...@@ -135,81 +135,81 @@ slotMouseEvent(QMouseEvent* _event)
// initialize // initialize
if (!is_active()) if (!is_active())
{ {
is_active_ = true; is_active_ = true;
first_point_ = last_point_ = p; first_point_ = last_point_ = p;
} }
// draw line // draw line
glBegin(GL_LINES); glBegin(GL_LINES);
glVertex(last_point_); glVertex(last_point_);
glVertex(p); glVertex(p);
glEnd(); glEnd();
last_point_ = rubberband_point_ = p; last_point_ = rubberband_point_ = p;
break; break;
} }
case QEvent::MouseMove: case QEvent::MouseMove:
{ {
if (is_active()) if (is_active())
{ {
Vec2i p(_event->pos().x(), height-_event->pos().y()); Vec2i p(_event->pos().x(), height-_event->pos().y());
// draw freehand // draw freehand
if (_event->modifiers() & Qt::LeftButton) if (_event->modifiers() & Qt::LeftButton)
{ {
glBegin(GL_LINES); glBegin(GL_LINES);
glVertex(last_point_); glVertex(last_point_);
glVertex(p); glVertex(p);
glEnd(); glEnd();
last_point_ = rubberband_point_ = p; last_point_ = rubberband_point_ = p;
} }
// draw rubber band // draw rubber band
else else
{ {
glEnable(GL_COLOR_LOGIC_OP); glEnable(GL_COLOR_LOGIC_OP);
glLogicOp(GL_XOR); glLogicOp(GL_XOR);
glBegin(GL_LINES); glBegin(GL_LINES);
glVertex(last_point_); glVertex(last_point_);
glVertex(rubberband_point_); glVertex(rubberband_point_);
glVertex(last_point_); glVertex(last_point_);
glVertex(p); glVertex(p);
glEnd(); glEnd();
glDisable(GL_COLOR_LOGIC_OP); glDisable(GL_COLOR_LOGIC_OP);
rubberband_point_ = p; rubberband_point_ = p;
} }
} }
break; break;
} }
case QEvent::MouseButtonDblClick: case QEvent::MouseButtonDblClick:
{ {
if (is_active()) if (is_active())
{ {
// close polygon // close polygon
glBegin(GL_LINES); glBegin(GL_LINES);
glVertex(last_point_); glVertex(last_point_);
glVertex(first_point_); glVertex(first_point_);
glEnd(); glEnd();
glFinish(); glFinish();
// mark reference point (0,0) with border color // mark reference point (0,0) with border color
glPointSize(1.0); glPointSize(1.0);
glBegin(GL_POINTS); glBegin(GL_POINTS);
glVertex2i(0, 0); glVertex2i(0, 0);
glEnd(); glEnd();
glPointSize(glstate_.point_size()); glPointSize(glstate_.point_size());
// create mask and precompute matrix // create mask and precompute matrix
create_mask(); create_mask();
is_active_ = false; is_active_ = false;
emit_signal = true; emit_signal = true;
} }
break; break;
} }
...@@ -217,7 +217,7 @@ slotMouseEvent(QMouseEvent* _event) ...@@ -217,7 +217,7 @@ slotMouseEvent(QMouseEvent* _event)
default: // avoid warning default: // avoid warning
break; break;
} }
// restore GL settings // restore GL settings
...@@ -264,7 +264,7 @@ create_mask() ...@@ -264,7 +264,7 @@ create_mask()
GLubyte *fbuffer; GLubyte *fbuffer;
QRgb rgb, borderRgb; QRgb rgb, borderRgb;
// GL context // GL context
w = glstate_.viewport_width(); w = glstate_.viewport_width();
h = glstate_.viewport_height(); h = glstate_.viewport_height();
...@@ -292,27 +292,27 @@ create_mask() ...@@ -292,27 +292,27 @@ create_mask()
// read lasso color // read lasso color
borderRgb = qRgb( fbuffer[0], fbuffer[1], fbuffer[2] ); borderRgb = qRgb( fbuffer[0], fbuffer[1], fbuffer[2] );
fbuffer[0] = fbuffer[1] = fbuffer[2] = 0; fbuffer[0] = fbuffer[1] = fbuffer[2] = 0;
// mark lasso pixels // mark lasso pixels
for (y = 0; y < h; ++y) for (y = 0; y < h; ++y)
{ {
offset = y*w; offset = y*w;
for (x = 0; x < w; ++x) for (x = 0; x < w; ++x)
{ {
i = 3*(offset + x); i = 3*(offset + x);
rgb = qRgb(fbuffer[i], fbuffer[i+1], fbuffer[i+2]); rgb = qRgb(fbuffer[i], fbuffer[i+1], fbuffer[i+2]);
mask_[offset+x] = (rgb == borderRgb) ? 3 : 1; mask_[offset+x] = (rgb == borderRgb) ? 3 : 1;
} }
} }
// seed fill
// seed fill
std::vector<Vec2i> toDo; std::vector<Vec2i> toDo;
toDo.reserve(w*h); toDo.reserve(w*h);
toDo.push_back(Vec2i(0,0)); toDo.push_back(Vec2i(0,0));
while (!toDo.empty()) while (!toDo.empty())
{ {
Vec2i p = toDo.back(); Vec2i p = toDo.back();
toDo.pop_back(); toDo.pop_back();
...@@ -320,39 +320,39 @@ create_mask() ...@@ -320,39 +320,39 @@ create_mask()
x = p[0]; x = p[0];
y = p[1]; y = p[1];
unsigned char &s = MASK(x, y); unsigned char &s = MASK(x, y);
if (s != 3) if (s != 3)
{ {
s = 0; s = 0;
xx = x-1; yy = y; xx = x-1; yy = y;
if ((xx<w) && (MASK(xx,yy)==1)) if ((xx<w) && (MASK(xx,yy)==1))
{ {
toDo.push_back(Vec2i(xx,yy)); toDo.push_back(Vec2i(xx,yy));
MASK(xx,yy) = 2; MASK(xx,yy) = 2;
} }
xx = x+1; yy = y; xx = x+1; yy = y;
if ((xx<w) && (MASK(xx,yy)==1)) if ((xx<w) && (MASK(xx,yy)==1))
{ {
toDo.push_back(Vec2i(xx,yy)); toDo.push_back(Vec2i(xx,yy));
MASK(xx,yy) = 2; MASK(xx,yy) = 2;
} }
xx = x; yy = y-1; xx = x; yy = y-1;
if ((yy<h) && (MASK(xx,yy)==1)) if ((yy<h) && (MASK(xx,yy)==1))
{ {
toDo.push_back(Vec2i(xx,yy)); toDo.push_back(Vec2i(xx,yy));
MASK(xx,yy) = 2; MASK(xx,yy) = 2;
} }
xx = x; yy = y+1; xx = x; yy = y+1;
if ((yy<h) && (MASK(xx,yy)==1)) if ((yy<h) && (MASK(xx,yy)==1))
{ {
toDo.push_back(Vec2i(xx,yy)); toDo.push_back(Vec2i(xx,yy));
MASK(xx,yy) = 2; MASK(xx,yy) = 2;
} }
} }
} }
...@@ -367,10 +367,10 @@ create_mask() ...@@ -367,10 +367,10 @@ create_mask()
void void
QtLasso:: QtLasso::
free_mask() free_mask()
{ {
if (mask_) if (mask_)
{ {
delete[] mask_; delete[] mask_;
mask_ = 0; mask_ = 0;
mask_width_ = mask_height_ = 0; mask_width_ = mask_height_ = 0;
} }
...@@ -390,19 +390,19 @@ is_vertex_selected(const Vec3d& _v) ...@@ -390,19 +390,19 @@ is_vertex_selected(const Vec3d& _v)
// size changed? // size changed?
w = glstate_.viewport_width(); w = glstate_.viewport_width();
h = glstate_.viewport_height(); h = glstate_.viewport_height();
if ((w != mask_width_) || (h != mask_height_)) if ((w != mask_width_) || (h != mask_height_))
{ {
std::cerr << "Lasso: viewport size has changed.\n"; std::cerr << "Lasso: viewport size has changed.\n";
return false; return false;
} }
// project vertex to 2D integer coordinates // project vertex to 2D integer coordinates
Vec3d v = glstate_.project(_v); Vec3d v = glstate_.project(_v);
x = (unsigned int)(v[0] + 0.5); x = (unsigned int)(v[0] + 0.5);
y = (unsigned int)(v[1] + 0.5); y = (unsigned int)(v[1] + 0.5);
// near and far plane clipping // near and far plane clipping
if (v[2] < 0.0 || v[2] > 1.0) if (v[2] < 0.0 || v[2] > 1.0)
return false; return false;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment