CGI/exercise4/include/Viewer.h

92 lines
2 KiB
C
Raw Normal View History

2019-01-24 14:38:18 +00:00
// This source code is property of the Computer Graphics and Visualization
// chair of the TU Dresden. Do not distribute!
2018-09-06 12:35:43 +00:00
// Copyright (C) CGV TU Dresden - All Rights Reserved
#pragma once
#include <gui/AbstractViewer.h>
#include <gui/SliderHelper.h>
#include <util/OpenMeshUtils.h>
#include "AABBTree.h"
#include "HashGrid.h"
#include "Point.h"
#include "LineSegment.h"
#include "Triangle.h"
#include <gui/ShaderPool.h>
class Viewer : public nse::gui::AbstractViewer
{
2019-01-24 14:38:18 +00:00
public:
2018-09-06 12:35:43 +00:00
Viewer();
void drawContents();
2019-01-24 14:38:18 +00:00
private:
2018-09-06 12:35:43 +00:00
enum PrimitiveType
{
2019-01-24 14:38:18 +00:00
Vertex,
Edge,
Tri
2018-09-06 12:35:43 +00:00
};
void SetupGUI();
void MeshUpdated();
2019-01-24 14:38:18 +00:00
void FindClosestPoint(const Eigen::Vector3f &p);
2018-09-06 12:35:43 +00:00
void BuildGridVBO();
void BuildRayVBOs();
template <typename Grid>
2019-01-24 14:38:18 +00:00
void BuildGridVBO(const Grid &grid)
2018-09-06 12:35:43 +00:00
{
std::vector<Eigen::Vector4f> positions;
for (auto it = grid.NonEmptyCellsBegin(); it != grid.NonEmptyCellsEnd(); ++it)
{
auto box = grid.CellBounds(it->first);
AddBoxVertices(box, positions);
}
ShaderPool::Instance()->simpleShader.bind();
gridVAO.bind();
gridPositions.uploadData(positions).bindToAttribute("position");
gridVAO.unbind();
gridIndices = (GLuint)positions.size();
}
2019-01-24 14:38:18 +00:00
void AddBoxVertices(const Box &box, std::vector<Eigen::Vector4f> &positions);
2018-09-06 12:35:43 +00:00
2019-01-24 14:38:18 +00:00
nanogui::ComboBox *shadingBtn;
nanogui::CheckBox *chkRenderMesh;
nanogui::CheckBox *chkRenderGrid;
nanogui::CheckBox *chkRenderRay;
2018-09-06 12:35:43 +00:00
int raySteps;
2019-01-24 14:38:18 +00:00
nse::gui::VectorInput *sldQuery, *sldRayOrigin, *sldRayDir;
nanogui::ComboBox *cmbPrimitiveType;
2018-09-06 12:35:43 +00:00
HEMesh polymesh;
float bboxMaxLength;
MeshRenderer renderer;
2019-01-24 14:38:18 +00:00
2018-09-06 12:35:43 +00:00
AABBTree<Point> vertexTree;
AABBTree<LineSegment> edgeTree;
AABBTree<Triangle> triangleTree;
2019-01-24 14:38:18 +00:00
2018-09-06 12:35:43 +00:00
HashGrid<Point> vertexGrid;
HashGrid<LineSegment> edgeGrid;
HashGrid<Triangle> triangleGrid;
nse::gui::GLBuffer closestPositions;
nse::gui::GLVertexArray closestVAO;
nse::gui::GLBuffer gridPositions;
nse::gui::GLVertexArray gridVAO;
GLuint gridIndices;
nse::gui::GLBuffer rayPositions, rayCellsPositions;
nse::gui::GLVertexArray rayVAO, rayCellsVAO;
GLuint rayCellsIndices;
};