/***************************************************************************** * * Copyright (c) 2000 - 2014, Lawrence Livermore National Security, LLC * Produced at the Lawrence Livermore National Laboratory * LLNL-CODE-442911 * All rights reserved. * * This file is part of VisIt. For details, see https://visit.llnl.gov/. The * full copyright notice is contained in the file COPYRIGHT located at the root * of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, * this list of conditions and the disclaimer below. * - Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the disclaimer (as noted below) in the * documentation and/or other materials provided with the distribution. * - Neither the name of the LLNS/LLNL nor the names of its contributors may * be used to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, * LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. * *****************************************************************************/ #include "QvisScribbleOpacityBar.h" #include #include #include #include #include #include #include #include #include // **************************************************************************** // Method: QvisScribbleOpacityBar::QvisScribbleOpacityBar // // Purpose: // // // Programmer: Jeremy Meredith // Creation: January 31, 2001 // // Modifications: // Brad Whitlock, Thu Feb 14 12:57:49 PDT 2002 // Added deletion of values array and the internal pixmap. // // Brad Whitlock, Wed Jun 4 09:20:11 PDT 2008 // Qt 4. // // **************************************************************************** QvisScribbleOpacityBar::QvisScribbleOpacityBar(QWidget *parent) : QvisAbstractOpacityBar(parent) { setFrameStyle( QFrame::Panel | QFrame::Sunken ); setLineWidth( 2 ); setMinimumHeight(50); setMinimumWidth(128); nvalues = 256; values = new float[nvalues]; for (int i=0; ix(); int y = e->y(); setValue(x2val(x), y2val(y)); lastx = x; lasty = y; mousedown = true; imageDirty(); update(); } // **************************************************************************** // Method: QvisScribbleOpacityBar::mouseMoveEvent // // Purpose: // // // Programmer: Jeremy Meredith // Creation: January 31, 2001 // // Modifications: // Brad Whitlock, Wed Jun 4 09:58:43 PDT 2008 // Use update(). // // **************************************************************************** void QvisScribbleOpacityBar::mouseMoveEvent(QMouseEvent *e) { if (!mousedown) return; int x = e->x(); int y = e->y(); setValues(lastx, lasty, x, y); lastx = x; lasty = y; imageDirty(); update(); } // **************************************************************************** // Method: QvisScribbleOpacityBar::mouseReleaseEvent // // Purpose: // // // Programmer: Jeremy Meredith // Creation: January 31, 2001 // // Modifications: // Brad Whitlock, Wed Jun 4 09:58:43 PDT 2008 // Use update(). // // **************************************************************************** void QvisScribbleOpacityBar::mouseReleaseEvent(QMouseEvent *e) { int x = e->x(); int y = e->y(); setValues(lastx, lasty, x, y); mousedown = false; imageDirty(); update(); emit mouseReleased(); } // **************************************************************************** // Method: QvisScribbleOpacityBar::setValues // // Purpose: // // // Programmer: Jeremy Meredith // Creation: January 31, 2001 // // **************************************************************************** void QvisScribbleOpacityBar::setValues(int x1, int y1, int x2, int y2) { if (x1==x2) { setValue(x2val(x2), y2val(y2)); return; } int xdiff = abs(x2 - x1) + 1; int step = (x1 < x2) ? 1 : -1; float slope = float(y2 - y1) / float (x2 - x1); for (int i=0; i nvalues) { for (int i=0; i= nvalues) break; sumUp = sumUp + up; values[i] = sumUp; i++; } for (int j=0; j= nvalues) break; sumUp = sumUp - up; values[i] = (sumUp>=0)?sumUp:0.0; i++; } } imageDirty(); update(); // Emit a signal indicating that the values changed. emit opacitiesChanged(); } // **************************************************************************** // Method: QvisScribbleOpacityBar::smoothCurve // // Purpose: // This is a Qt slot function that applies a simple filter to the alphas // in order to smooth them out. // // Programmer: Brad Whitlock // Creation: Mon Feb 5 13:43:15 PST 2001 // // Modifications: // Brad Whitlock, Thu Feb 14 13:07:26 PST 2002 // Fixed an ABR. // // Brad Whitlock, Thu Dec 18 14:09:40 PST 2008 // I changed how the image gets invalidated. // // **************************************************************************** void QvisScribbleOpacityBar::smoothCurve() { // Smooth the curve for(int i = 1; i < nvalues - 1; ++i) { // 1 3 1 filter. float smooth = (0.2 * values[i - 1]) + (0.6 * values[i]) + (0.2 * values[i + 1]); values[i] = (smooth > 1.) ? 1. : smooth; } imageDirty(); update(); // Emit a signal indicating that the values changed. emit opacitiesChanged(); }