Commit e9cf0f5b authored by Christopher Tenter's avatar Christopher Tenter

Merge branch 'master' into CameraNode

parents 60968437 1beb6152
......@@ -229,6 +229,25 @@ void GLPrimitive::draw_primitive()
//------------------------------------------------------------------------
void GLPrimitive::draw_primitive(GLSL::Program* _program)
{
if (checkVBO())
{
glBindBuffer(GL_ARRAY_BUFFER, vbo_);
vertexDecl_.activateShaderPipeline(_program);
if (numTris_)
glDrawArrays(GL_TRIANGLES, 0, numTris_ * 3);
else
glDrawArrays(GL_LINES, 0, numLines_ * 2);
vertexDecl_.deactivateShaderPipeline(_program);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
}
//------------------------------------------------------------------------
void GLPrimitive::addToRenderer_primitive( class IRenderer* _renderer, RenderObject* _ro )
{
if (checkVBO())
......
......@@ -80,9 +80,17 @@ public:
GLPrimitive();
virtual ~GLPrimitive();
// bind vbo + gl draw call
// bind vbo + gl draw call (fixed function mode)
// use this function in compatibility profile
void draw_primitive();
// activate vertex declaration + gl draw call (shader mode)
// _program may be nullptr, in that case the attribute locations are as follows.
// 0 : float3 position
// 1 : float3 normal
// 2 : float2 texcoord
void draw_primitive(GLSL::Program* _program);
// add to deferred draw call to renderer
void addToRenderer_primitive(class IRenderer* _renderer, struct RenderObject* _ro);
......
......@@ -59,6 +59,7 @@
#include <ACG/GL/acg_glew.hh>
#include "GLState.hh"
#include <OpenMesh/Core/Utils/vector_cast.hh>
#include <cstring>
......@@ -1070,6 +1071,19 @@ Vec4uc GLState::pick_get_name_color (size_t _idx)
//-----------------------------------------------------------------------------
Vec4f GLState::pick_get_name_color_norm (unsigned int _idx)
{
Vec4f rv(0.0f, 0.0f, 0.0f, 0.0f);
if (colorPicking_)
{
Vec4uc color_abs = colorStack_.getIndexColor(_idx);
rv = OpenMesh::vector_cast<Vec4f, Vec4uc>(color_abs) / 255.0f;
}
return rv;
}
//-----------------------------------------------------------------------------
void GLState::pick_push_name (size_t _idx)
{
colorStack_.pushIndex (_idx);
......
......@@ -1114,6 +1114,9 @@ public:
/// for each primitive
Vec4uc pick_get_name_color (size_t _idx);
/// same as pick_get_name_color, but the resulting color channels are normalized in [0.0, 1.0] range
Vec4f pick_get_name_color_norm (unsigned int _idx);
/// creates a new name the stack (like glPushName())
void pick_push_name (size_t _idx);
......
/*===========================================================================*\
* *
* OpenFlipper *
* *
* OpenFlipper *
* Copyright (c) 2001-2015, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
......@@ -36,26 +36,36 @@
* 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. *
* *
* *
\*===========================================================================*/
/*
* ValenceHistogramWidget.cc
*
* Created on: Jan 27, 2016
* Author: hc
*/
// Based on QtHistogram by hc
#include "ValenceHistogramWidget.hh"
#include "QtHistogramWidget.hh"
#include <QPainter>
ValenceHistogramWidget::ValenceHistogramWidget(QWidget *parent) :
histogram_(0) {
namespace ACG {
namespace QtWidgets {
QtHistogramWidget::QtHistogramWidget(QWidget *parent)
: QWidget(parent),
color_(QColor::fromRgbF(0.518, 0.573, 0.643, 1.0))
{}
QtHistogramWidget::~QtHistogramWidget() = default;
void QtHistogramWidget::setHistogram(std::unique_ptr<Histogram> histogram) {
histogram_ = std::move(histogram);
this->update();
}
void ValenceHistogramWidget::paintEvent(QPaintEvent *event) {
void QtHistogramWidget::setColorCoder(std::unique_ptr<IColorCoder> color_coder) {
color_coder_ = std::move(color_coder);
this->update();
}
void QtHistogramWidget::paintEvent(QPaintEvent *event) {
if (!histogram_) {
QWidget::paintEvent(event);
return;
......@@ -64,25 +74,19 @@ void ValenceHistogramWidget::paintEvent(QPaintEvent *event) {
/*
* Analyze histogram/
*/
std::vector<size_t>::iterator nonzero_begin = histogram_->begin();
for (; nonzero_begin != histogram_->end() && *nonzero_begin == 0;
++nonzero_begin);
if (nonzero_begin == histogram_->end()) return;
std::vector<size_t>::iterator nonzero_end = histogram_->end();
for (; (nonzero_end-1) != nonzero_begin && *(nonzero_end-1) == 0;
--nonzero_end);
const std::vector<size_t> &bins = histogram_->getBins();
const std::vector<double> &bin_widths = histogram_->getBinWidths();
const double total_width = histogram_->getTotalWidth();
const size_t hist_size = std::distance(nonzero_begin, nonzero_end);
const size_t hist_max = *std::max_element(nonzero_begin, nonzero_end);
const size_t ofs = std::distance(histogram_->begin(), nonzero_begin);
const size_t hist_max = *std::max_element(bins.begin(), bins.end());
/*
* Establish regions
*/
const qreal labelHeight = 16;
QRectF paint_rect = this->contentsRect();
QRectF bargraph_rect = paint_rect;
bargraph_rect.setBottom(bargraph_rect.bottom() - 16);
bargraph_rect.setBottom(bargraph_rect.bottom() - labelHeight);
QRectF label_rect = paint_rect;
label_rect.setTop(bargraph_rect.bottom());
QPainter painter(this);
......@@ -91,28 +95,39 @@ void ValenceHistogramWidget::paintEvent(QPaintEvent *event) {
* Painter attributes.
*/
painter.setRenderHint(QPainter::Antialiasing);
painter.setBrush(QColor::fromRgbF(0.518, 0.573, 0.643, 1.0));
painter.setFont(this->font());
const qreal stride =
static_cast<qreal>(bargraph_rect.width()) / hist_size;
const qreal gap = (stride > 8) ? 1.0 : 0.0;
const qreal avg_width = bargraph_rect.width() / bins.size();
const qreal gap = (avg_width > 8) ? 1.0 : 0.0;
const qreal label_gap = 4;
QRectF barRect(0, 0, stride - gap, 0);
const qreal scale = static_cast<qreal>(bargraph_rect.height()) / hist_max;
const qreal y_scale = bargraph_rect.height() / hist_max;
const qreal total_gap = (bins.size() - 1) * gap;
const qreal total_barwidth = bargraph_rect.width() - total_gap;
QRectF barRect;
/*
* Draw.
*/
int cnt = 0;
double cumulative_width = 0.0;
qreal xpos = 0;
qreal lastLabelX = label_rect.left();
for (std::vector<size_t>::iterator it = nonzero_begin;
it != nonzero_end; ++it, ++cnt) {
const size_t n_bins = bins.size();
for (size_t idx = 0; idx < n_bins; ++idx) {
const double bin_width = bin_widths[idx];
const qreal bar_width = total_barwidth * (bin_width / total_width);
// Bar
painter.setPen(Qt::NoPen);
barRect.setHeight(scale * (*it));
barRect.moveBottomLeft(
bargraph_rect.bottomLeft() + QPoint(stride * cnt, 0));
// relative position t in [0..1] for the middle of the current bin
const double t = (cumulative_width + bin_width/2) / total_width;
cumulative_width += bin_width;
painter.setBrush(getColor(t));
barRect.setWidth(bar_width - gap);
barRect.setHeight(y_scale * bins[idx]);
barRect.moveBottomLeft(bargraph_rect.bottomLeft() + QPoint(xpos, 0));
if (gap > 0.0)
painter.drawRoundedRect(barRect, 3, 3, Qt::AbsoluteSize);
else
......@@ -120,21 +135,43 @@ void ValenceHistogramWidget::paintEvent(QPaintEvent *event) {
// Label
painter.setPen(Qt::black);
QString labelText = QString::number(cnt + ofs);
QRectF labelBB =
painter.boundingRect(
QRectF(barRect.center().x()-50, label_rect.y(),
100.0, label_rect.height()),
Qt::AlignHCenter | Qt::AlignBottom, labelText);
qreal labelX = 0;
QString labelText;
switch (histogram_->getLabelType()) {
case Histogram::LabelType::PerBin:
labelX = barRect.center().x();
labelText = histogram_->getBinLabel(idx);
break;
case Histogram::LabelType::PerBoundary:
labelX = barRect.x();
labelText = histogram_->getBoundaryLabel(idx);
break;
}
QRectF labelBB = painter.boundingRect(
QRectF(labelX - (label_distance_/2), label_rect.y(),
label_distance_, label_rect.height()),
Qt::AlignHCenter | Qt::AlignBottom, labelText);
if (labelBB.left() >= lastLabelX + label_gap) {
painter.drawText(labelBB, Qt::AlignHCenter | Qt::AlignBottom,
labelText);
lastLabelX = labelBB.right();
}
xpos += bar_width;
}
// TODO: draw last perBoundary label?
}
void ValenceHistogramWidget::setHistogram(std::vector<size_t> *histogram) {
histogram_ = histogram;
this->update();
QColor QtHistogramWidget::getColor(double val)
{
if (color_coder_) {
return color_coder_->color_qcolor(val);
} else {
return color_;
}
}
}
}
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (c) 2001-2015, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
*---------------------------------------------------------------------------*
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. Neither the name of the copyright holder 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 THE COPYRIGHT HOLDER *
* 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. *
* *
\*===========================================================================*/
#ifndef QTHISTOGRAM_HH
#define QTHISTOGRAM_HH
// Based on ValenceHistogramWidget by hc
#include <memory>
#include <QWidget>
#include "../Config/ACGDefines.hh"
#include "../Utils/Histogram.hh"
#include "../Utils/ColorCoder.hh"
namespace ACG {
namespace QtWidgets {
class ACGDLLEXPORT QtHistogramWidget : public QWidget {
Q_OBJECT
public:
explicit QtHistogramWidget(QWidget *parent);
~QtHistogramWidget();
QtHistogramWidget(const QtHistogramWidget &other) = delete;
QtHistogramWidget& operator=(const QtHistogramWidget &other) = delete;
void setHistogram(std::unique_ptr<Histogram> histogram);
void setColorCoder(std::unique_ptr<IColorCoder> color_coder);
protected:
void paintEvent(QPaintEvent *event);
QColor getColor(double val); // val in [0..1]
std::unique_ptr<Histogram> histogram_ = nullptr;
double label_distance_ = 100;
QColor color_; // ignored if we have a color coder
std::unique_ptr<IColorCoder> color_coder_ = nullptr;
};
} // namespace QtWidgets
} // namespace ACG
#endif // QTHISTOGRAM_HH
......@@ -863,7 +863,7 @@ void CoordsysNode::boundingCircle(std::vector<Vec2f> &_in, Vec2f &_center, float
for (unsigned int i = 0; i < _in.size () - 1; i++)
for (unsigned int j = i + 1; j < _in.size (); j++)
{
Vec2f cen = (_in[i] + _in[j]) * 0.5;
Vec2f cen = (_in[i] + _in[j]) * 0.5f;
float rad = (_in[i] - cen).length ();
bool allin = true;
......
......@@ -301,9 +301,9 @@ add_primitive(GlutPrimitiveType _type, Vec3d _pos, Vec3d _axis, ACG::Vec4f _colo
//----------------------------------------------------------------------------
void
GlutPrimitiveNode::draw_obj(int _idx) const
GlutPrimitiveNode::draw_obj(size_t _idx) const
{
if (_idx < 0 || _idx >= (int)primitives_.size()) // range check
if ( _idx >= primitives_.size()) // range check
return;
Vec3d axis = primitives_[_idx].axis;
......@@ -390,7 +390,7 @@ pick(GLState& _state , PickTarget _target)
case PICK_ANYTHING:
case PICK_FACE:
{
for (int i = 0; i < (int)primitives_.size(); ++i)
for (size_t i = 0; i < primitives_.size(); ++i)
{
_state.pick_set_name(i);
glPushMatrix();
......
......@@ -217,7 +217,7 @@ public:
/// drawing the primitive
void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
void draw_obj(int _idx) const;
void draw_obj(size_t _idx) const;
/// picking
void pick(GLState& _state, PickTarget _target);
......
......@@ -372,7 +372,7 @@ void LineNode::pick(GLState& _state , PickTarget _target)
ACG::GLState::vertexPointer( &(points_)[0] );
ACG::GLState::enableClientState(GL_VERTEX_ARRAY);
const unsigned int n_edges = n_points() - 1;
const size_t n_edges = n_points() - 1;
switch (_target)
{
......@@ -414,25 +414,25 @@ void LineNode::pick_edges(GLState& _state, unsigned int _offset)
if (line_mode_ == PolygonMode)
{
const unsigned int n_edges = n_points() - 1;
for (unsigned int i = 0; i < n_edges; ++i)
const size_t n_edges = n_points() - 1;
for (size_t i = 0; i < n_edges; ++i)
{
_state.pick_set_name(i + _offset);
glBegin(GL_LINES);
glArrayElement(i);
glArrayElement(i + 1);
glArrayElement(static_cast<GLint>(i));
glArrayElement(static_cast<GLint>(i + 1));
glEnd();
}
}
else if (line_mode_ == LineSegmentsMode)
{
const unsigned int n_edges = n_points() / 2;
for (unsigned int i = 0; i < n_edges; ++i)
const size_t n_edges = n_points() / 2;
for (size_t i = 0; i < n_edges; ++i)
{
_state.pick_set_name(i + _offset);
glBegin(GL_LINES);
glArrayElement(2*i);
glArrayElement(2*i + 1);
glArrayElement(static_cast<GLint>(2*i));
glArrayElement(static_cast<GLint>(2*i + 1));
glEnd();
}
}
......
......@@ -266,7 +266,7 @@ enter(GLState& _state, const DrawModes::DrawMode& /*_drawmode*/) {
ACG::GLState::enable(GL_TEXTURE_2D);
ACG::GLState::enable(GL_BLEND);
ACG::GLState::enable(GL_ALPHA_TEST);
ACG::GLState::alphaFunc(GL_GREATER, 0.2);
ACG::GLState::alphaFunc(GL_GREATER, 0.2f);
ACG::GLState::blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
if (alwaysOnTop_)
ACG::GLState::disable(GL_DEPTH_TEST);
......
......@@ -818,6 +818,8 @@ void TranslationManipulatorNode::getRenderObjects(IRenderer* _renderer,
ro.blending = false;
ro.depthFunc = GL_LEQUAL;
ro.depthWrite = true;
ro.alpha = 1.0f;
addManipulatorToRenderer(_renderer, &ro, true);
}
}
......@@ -871,12 +873,14 @@ void TranslationManipulatorNode::addManipulatorToRenderer (IRenderer* _renderer,
//================================================================================================
// gluCylinder draws into z direction so z-Axis first
_baseRO->debugName = "TranslationManipulatorNode.z";
addAxisToRenderer(_renderer, _baseRO, _active, ZAxis);
//================================================================================================
// Y-Axis
//================================================================================================
_baseRO->debugName = "TranslationManipulatorNode.y";
_baseRO->modelview.rotate(-90, 1.0, 0.0, 0.0);
addAxisToRenderer(_renderer, _baseRO, _active, YAxis);
......@@ -884,6 +888,7 @@ void TranslationManipulatorNode::addManipulatorToRenderer (IRenderer* _renderer,
// X-Axis
//================================================================================================
_baseRO->debugName = "TranslationManipulatorNode.x";
_baseRO->modelview.rotate(90, 0.0, 1.0, 0.0);
addAxisToRenderer(_renderer, _baseRO, _active, XAxis);
......@@ -891,6 +896,8 @@ void TranslationManipulatorNode::addManipulatorToRenderer (IRenderer* _renderer,
// Sphere
//=================================================================================================
_baseRO->debugName = "TranslationManipulatorNode.sphere";
for (int i = 0; i < 3; ++i)
_baseRO->emissive[i] = _active ? (element_[Origin].active_current_color_[i]) : (element_[Origin].inactive_current_color_[i]);
......@@ -908,6 +915,8 @@ void TranslationManipulatorNode::addManipulatorToRenderer (IRenderer* _renderer,
if ( activeRotations_ & X_AXIS)
{
_baseRO->name = "TranslationManipulatorNode.x_ring";
for (int i = 0; i < 3; ++i)
_baseRO->emissive[i] = _active ? (element_[XRing].active_current_color_[i]) : (element_[XRing].inactive_current_color_[i]);
......@@ -918,6 +927,8 @@ void TranslationManipulatorNode::addManipulatorToRenderer (IRenderer* _renderer,
_baseRO->modelview.rotate(90, 0.0, 1.0, 0.0);
if ( activeRotations_ & Y_AXIS)
{
_baseRO->debugName = "TranslationManipulatorNode.y_ring";
for (int i = 0; i < 3; ++i)
_baseRO->emissive[i] = _active ? (element_[YRing].active_current_color_[i]) : (element_[YRing].inactive_current_color_[i]);
circle_->addToRenderer_primitive(_renderer, _baseRO);
......@@ -926,6 +937,8 @@ void TranslationManipulatorNode::addManipulatorToRenderer (IRenderer* _renderer,
_baseRO->modelview.rotate(90, 1.0, 0.0, 0.0);
if ( activeRotations_ & Z_AXIS)
{
_baseRO->debugName = "TranslationManipulatorNode.z_ring";
for (int i = 0; i < 3; ++i)
_baseRO->emissive[i] = _active ? (element_[ZRing].active_current_color_[i]) : (element_[ZRing].inactive_current_color_[i]);
circle_->addToRenderer_primitive(_renderer, _baseRO);
......
......@@ -93,51 +93,13 @@ ACG::Vec4uc ColorCoder::color4(float _v) const
return signed_mode_ ? color_signed(_v) : color_unsigned(_v);
}
/// color coding
ACG::Vec3uc ColorCoder::color(float _v) const
{
ACG::Vec4uc c;
if (signed_mode_)
c = color_signed(_v);
else
c = color_unsigned(_v);
return ( ACG::Vec3uc(c[0], c[1], c[2]) );
}
/// color coding
ACG::Vec3f ColorCoder::color_float(float _v) const
{
ACG::Vec4uc c;
if (signed_mode_)
c = color_signed(_v);
else
c = color_unsigned(_v);
return (ACG::Vec3f(c[0], c[1], c[2]) / 255.f);
}
/// color coding
ACG::Vec4f ColorCoder::color_float4(float _v) const
{
ACG::Vec4uc c;
if (signed_mode_)
c = color_signed(_v);
else
c = color_unsigned(_v);
ACG::Vec4uc c = color4(_v);
return (ACG::Vec4f(c[0], c[1], c[2], c[3]) / 255.f);
}
/// color coding
QColor ColorCoder::color_qcolor(float _v) const
{
ACG::Vec4uc c;
if (signed_mode_)
c = color_signed(_v);
else
c = color_unsigned(_v);
return(QColor(c[0], c[1], c[2], c[3]));
}
/// min scalar value
float ColorCoder::min() const
{
......
......@@ -61,6 +61,7 @@
#include <ACG/Math/VectorT.hh>
#include <ACG/Config/ACGDefines.hh>
#include <QColor>
#include "IColorCoder.hh"
//== NAMESPACES ===============================================================
......@@ -72,7 +73,7 @@ namespace ACG {
*
*
*/
class ACGDLLEXPORT ColorCoder {
class ACGDLLEXPORT ColorCoder : public IColorCoder {
public:
/// Default constructor.
......@@ -82,30 +83,16 @@ public:
void set_range(float _min, float _max, bool _signed);
/// color coding
ACG::Vec4uc color4(float _v) const;
ACG::Vec4uc color4(float _v) const override;
/// color coding
ACG::Vec3uc color(float _v) const;
/// color coding
ACG::Vec3f color_float(float _v) const;
/// color coding
ACG::Vec4f color_float4(float _v) const;