Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drawing over specific classifications (+ adding more colours to a shader) #179

Open
wants to merge 5 commits into
base: selection
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -171,22 +171,6 @@ Both the LASlib and IlmBase libraries may be built using the separate third
party build system in ``thirdparty/external/CMakeLists.txt``.


Build options
~~~~~~~~~~~~~
To read the .las and .laz file formats, you'll need one of the following:

* LASlib >= something-recent (known to work with 150406). This is the default
because it's reasonably fast and has no additional library dependencies.
* PDAL >= something-recent (known to work with 0.1.0-3668-gff73c08). You may
select PDAL by setting the build option ``DISPLAZ_USE_PDAL=TRUE``. Note that
building PDAL also requires several libraries including boost, laszip and
GDAL.

If you only want to read ply files (for example, to use the scripting language
bindings), and don't care about las you may set the build option
``DISPLAZ_USE_LAS=FALSE``.


Supported Systems
-----------------

Expand Down
3 changes: 2 additions & 1 deletion shaders/las_points_selection.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ void main()
else if (classification == 2) classColor = vec3(0.33, 0.18, 0.0);
else if (classification == 3) classColor = vec3(1.0, 0.0, 0.0);
else if (classification == 4) classColor = vec3(0.0, 1.0, 1.0);
else if (classification == 5) classColor = vec3(0.295, 0.0, 0.5);
else if (classification == 6) classColor = vec3(1.0, 0.63, 0.5);
pointColor = classColor +
vec3(0,0,float(rr<selectionRadius)) +
tonemap(intensity/400.0, exposure, contrast) * vec3(1);
Expand Down Expand Up @@ -227,4 +229,3 @@ void main()
}

#endif

96 changes: 96 additions & 0 deletions shaders/point_normals.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#version 130
// Copyright 2015, Christopher J. Foster and the other displaz contributors.
// Use of this code is governed by the BSD-style license found in LICENSE.txt

// This shader allows normals to be supplied with each point, and draws a small
// line segment in the direction of the normal, centred on the point.

uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
uniform mat4 modelViewProjectionMatrix;

//------------------------------------------------------------------------------
#if defined(VERTEX_SHADER)

uniform float pointSize = 10.0; //# uiname=Point Size; min=1; max=200
uniform float minPointSize = 0;
uniform float maxPointSize = 200.0;
// Point size multiplier to keep coverage constant when doing stochastic
// simplification
uniform float pointSizeLodMultiplier = 1;
in vec3 position;
in vec3 normal;
in vec3 color;

flat out float pointScreenSize;
flat out vec3 pointColor;
flat out vec2 lineNormal;
flat out float lineNormalLen;

void main()
{
vec4 p = modelViewProjectionMatrix * vec4(position,1.0);
gl_Position = p;
float wInv = 1.0/p.w;
// Compute differential of the projection Proj(v) = (A*v).xy / (A*v).w
// restricted to the xy plane. dProj given here has a factor of wInv
// removed so that the resulting lineNormalLen is correct for the point
// coordinate system (pointScreenSize is effectively absorbing the factor
// of wInv).
mat3x2 dProj = mat3x2(modelViewProjectionMatrix) -
outerProduct(wInv*p.xy, transpose(modelViewProjectionMatrix)[3].xyz);
// Remove aspect ratio - fragment coord system will be square.
float aspect = projectionMatrix[1][1]/projectionMatrix[0][0];
dProj = mat2x2(aspect, 0, 0, 1) * dProj;
vec2 dirProj = dProj*normalize(normal);
lineNormalLen = length(dirProj);
lineNormal = vec2(-dirProj.y, dirProj.x) / lineNormalLen;
pointScreenSize = clamp(20.0*pointSize * wInv * pointSizeLodMultiplier,
minPointSize, maxPointSize);
gl_PointSize = pointScreenSize;
pointColor = color;
}


//------------------------------------------------------------------------------
#elif defined(FRAGMENT_SHADER)

uniform float markerWidth = 0.3; // # uiname=Marker Width; min=0.01; max=1

flat in float pointScreenSize;
flat in vec3 pointColor;
flat in vec2 lineNormal;
flat in float lineNormalLen;

out vec4 fragColor;

// Limit at which the point is rendered as a small square for antialiasing
// rather than using a specific marker shape
const float pointScreenSizeLimit = 2;

void main()
{
if (pointScreenSize <= 0)
discard;
if (pointScreenSize > pointScreenSizeLimit)
{
float w = markerWidth;
if (pointScreenSize < 2*pointScreenSizeLimit)
{
// smoothly turn on the markers as we get close enough to see them
w = mix(1, w, pointScreenSize/pointScreenSizeLimit - 1);
}
vec2 p = 2*(gl_PointCoord - 0.5);
p.y = -p.y;
float r = length(p);
const float lineRad = 1.0;
bool inLine = r*(1-w) < max(0.5*lineNormalLen, 2/pointScreenSize) &&
abs(dot(lineNormal,p))*(1-w)*pointScreenSize < lineRad;
if (!inLine)
discard;
}
fragColor = vec4(pointColor, 1);
}

#endif

2 changes: 1 addition & 1 deletion src/gui/PointViewerMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ PointViewerMainWindow::PointViewerMainWindow(const QGLFormat& format)
viewMenu->addSeparator();
QAction* drawBoundingBoxes = viewMenu->addAction(tr("Draw Bounding bo&xes"));
drawBoundingBoxes->setCheckable(true);
drawBoundingBoxes->setChecked(true);
drawBoundingBoxes->setChecked(false);
QAction* drawCursor = viewMenu->addAction(tr("Draw 3D &Cursor"));
drawCursor->setCheckable(true);
drawCursor->setChecked(true);
Expand Down
136 changes: 97 additions & 39 deletions src/render/View3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ View3D::View3D(GeometryCollection* geometries, const QGLFormat& format, QWidget
m_selectionClassFrom(-1),
m_selectionClassTo(1),
m_backgroundColor(60, 50, 50),
m_drawBoundingBoxes(true),
m_drawBoundingBoxes(false),
m_drawCursor(true),
m_drawAxes(true),
m_drawGrid(false),
Expand Down Expand Up @@ -645,50 +645,58 @@ void View3D::wheelEvent(QWheelEvent* event)

void View3D::keyPressEvent(QKeyEvent *event)
{
#include <string>
// Centre camera on current cursor location
if(event->key() == Qt::Key_C)
{
m_camera.setCenter(m_cursorPos);
}
else if(event->key() == Qt::Key_0)
else if(!(event->modifiers()& Qt::AltModifier))
{
m_selectionClassTo = 0;
}
else if(event->key() == Qt::Key_1)
{
m_selectionClassTo = 1;
}
else if(event->key() == Qt::Key_2)
{
m_selectionClassTo = 2;
}
else if(event->key() == Qt::Key_3)
{
m_selectionClassTo = 3;
}
else if(event->key() == Qt::Key_4)
{
m_selectionClassTo = 4;
}
else if(event->key() == Qt::Key_5)
{
m_selectionClassTo = 5;
}
else if(event->key() == Qt::Key_6)
{
m_selectionClassTo = 6;
}
else if(event->key() == Qt::Key_7)
{
m_selectionClassTo = 7;
}
else if(event->key() == Qt::Key_8)
{
m_selectionClassTo = 8;
}
else if(event->key() == Qt::Key_9)
{
m_selectionClassTo = 9;
if(event->key() == Qt::Key_0)
{
m_selectionClassTo = 0;
}
else if(event->key() == Qt::Key_1)
{
m_selectionClassTo = 1;
}
else if(event->key() == Qt::Key_2)
{
m_selectionClassTo = 2;
}
else if(event->key() == Qt::Key_3)
{
m_selectionClassTo = 3;
}
else if(event->key() == Qt::Key_4)
{
m_selectionClassTo = 4;
}
else if(event->key() == Qt::Key_5)
{
m_selectionClassTo = 5;
}
else if(event->key() == Qt::Key_6)
{
m_selectionClassTo = 6;
}
else if(event->key() == Qt::Key_7)
{
m_selectionClassTo = 7;
}
else if(event->key() == Qt::Key_8)
{
m_selectionClassTo = 8;
}
else if(event->key() == Qt::Key_9)
{
m_selectionClassTo = 9;
}
else if(event->modifiers() == 0)
{
event->ignore();
}
}
else if(event->key() == Qt::Key_S && (event->modifiers() & Qt::ControlModifier))
{
Expand All @@ -700,6 +708,56 @@ void View3D::keyPressEvent(QKeyEvent *event)
m_geometries->get()[sel[i].row()]->saveFile(fileName);
}
}
else if(event->modifiers() & Qt::AltModifier){
if(event->key() == Qt::Key_0)
{
m_selectionClassFrom = 0;
}
else if(event->key() == Qt::Key_1)
{
m_selectionClassFrom = 1;
}
else if(event->key() == Qt::Key_2)
{
m_selectionClassFrom = 2;
}
else if(event->key() == Qt::Key_3)
{
m_selectionClassFrom = 3;
}
else if(event->key() == Qt::Key_4)
{
m_selectionClassFrom = 4;
}
else if(event->key() == Qt::Key_5)
{
m_selectionClassFrom = 5;
}
else if(event->key() == Qt::Key_6)
{
m_selectionClassFrom = 6;
}
else if(event->key() == Qt::Key_7)
{
m_selectionClassFrom = 7;
}
else if(event->key() == Qt::Key_8)
{
m_selectionClassFrom = 8;
}
else if(event->key() == Qt::Key_9)
{
m_selectionClassFrom = 9;
}
else if(event->key() == Qt::Key_R)
{
m_selectionClassFrom = 1;
}
else
{
event->ignore();
}
}
else
{
event->ignore();
Expand Down