Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ttnghia committed Jun 27, 2020
1 parent 4aa36fd commit dabc324
Show file tree
Hide file tree
Showing 24 changed files with 341 additions and 487 deletions.
13 changes: 4 additions & 9 deletions Data/points.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@

// Control point of curve #0
-2.87181 1.84298 0.22415
-2.15362 0.72365 -0.290709
-0.781428 1.69175 0.865892
-0.569098 1.70164 1.77287

// Control point of curve #1
0.692288 0.970642 0.904679
0.799703 1.41361 1.88313
2.58704 1.45852 1.0763
0.75 0.25 0
-0.75 0 0
0.75 1.25 -1.70373
-0.75 1.48362 1.10581
19 changes: 13 additions & 6 deletions Source/QuadraticApproximationApp.cpp → Source/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
#include <Magnum/GL/DefaultFramebuffer.h>

#include "DrawableObjects/PickableObject.h"
#include "QuadraticApproximationApp.h"
#include "Application.h"

/****************************************************************************************************/
QuadraticApproximationApp::QuadraticApproximationApp(const Arguments& arguments) :
Application::Application(const Arguments& arguments) :
PickableApplication{"Quadratic Approximation of Cubic Curves", arguments} {
m_DefaultCamPosition = Vector3(0, 1.0, 5);
m_DefaultCamTarget = Vector3(0, 0.75, 0);
Expand All @@ -31,7 +31,7 @@ QuadraticApproximationApp::QuadraticApproximationApp(const Arguments& arguments)
}

/****************************************************************************************************/
void QuadraticApproximationApp::drawEvent() {
void Application::drawEvent() {
GL::defaultFramebuffer.clear(GL::FramebufferClear::Color | GL::FramebufferClear::Depth);
ImGuiApplication::beginFrame();

Expand Down Expand Up @@ -82,10 +82,12 @@ void QuadraticApproximationApp::drawEvent() {

/* Update the corresponding node's point */
Vector3 translation = objMat[3].xyz();
m_Curves->setControlPoint(selectedPoint->idx(), translation);
m_Curves->setDataPoint(selectedPoint->idx(), translation);

/* Update all control points and curves */
m_Curves->convertControlPoints();
m_Curves->saveControlPoints();
m_Curves->computeBezierControlPoints();
m_Curves->updatePolylines();
m_Curves->updateCurveControlPoints();
m_Curves->computeCurves();
}
Expand All @@ -99,12 +101,17 @@ void QuadraticApproximationApp::drawEvent() {
}

/****************************************************************************************************/
void QuadraticApproximationApp::showMenu() {
void Application::showMenu() {
if(ImGui::CollapsingHeader("Tessellation and quadratic approximation", ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::PushID("Subdivision+Approximation");
if(ImGui::SliderInt("Segments", &m_Curves->subdivision(), 1, 128)) {
m_Curves->computeCurves();
}
if(ImGui::Checkbox("Bezier from Catmull-Rom", &m_Curves->BezierFromCatmullRom())) {
m_Curves->computeBezierControlPoints();
m_Curves->generateCurves();
m_Curves->computeCurves();
}
if(ImGui::Checkbox("Render quadratic Bezier", &m_Curves->quadC1BezierConfig.bEnabled)) {
m_Curves->updateCurveConfigs();
}
Expand Down
6 changes: 3 additions & 3 deletions Source/QuadraticApproximationApp.h → Source/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#include "QuadraticCurveApproximation.h"

/****************************************************************************************************/
class QuadraticApproximationApp : public PickableApplication {
class Application : public PickableApplication {
public:
explicit QuadraticApproximationApp(const Arguments& arguments);
explicit Application(const Arguments& arguments);

protected:
void drawEvent() override;
Expand All @@ -33,4 +33,4 @@ class QuadraticApproximationApp : public PickableApplication {
};

/****************************************************************************************************/
MAGNUM_APPLICATION_MAIN(QuadraticApproximationApp)
MAGNUM_APPLICATION_MAIN(Application)
4 changes: 2 additions & 2 deletions Source/Application/GLApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* limitations under the License.
*/

#include "Application/GLApplication.h"

#include <Magnum/GL/DefaultFramebuffer.h>
#include <Magnum/GL/Renderer.h>
#include <Magnum/GL/Context.h>
#include <Magnum/GL/Version.h>

#include "Application/GLApplication.h"

/****************************************************************************************************/
GLApplication::GLApplication(const std::string& title, const Arguments& arguments,
const Vector2i& defaultWindowSize) :
Expand Down
7 changes: 3 additions & 4 deletions Source/Application/GLApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

#pragma once

#include <Corrade/Containers/Pointer.h>
#include "Camera/ArcBallCamera.h"
#include "DrawableObjects/Grid.h"

#include <Corrade/Containers/Pointer.h>
#include <Magnum/Magnum.h>
#include <Magnum/Math/Color.h>
#include <Magnum/Math/Vector3.h>
Expand All @@ -26,9 +28,6 @@
#include <Magnum/SceneGraph/Scene.h>
#include <Magnum/SceneGraph/Drawable.h>

#include "Camera/ArcBallCamera.h"
#include "DrawableObjects/Grid.h"

/****************************************************************************************************/
using namespace Corrade;
using namespace Magnum;
Expand Down
3 changes: 1 addition & 2 deletions Source/Application/ImGuiApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
* limitations under the License.
*/

#include <Magnum/GL/Renderer.h>

#include "Application/ImGuiApplication.h"
#include <Magnum/GL/Renderer.h>

/****************************************************************************************************/
ImGuiApplication::ImGuiApplication(const std::string& title, const Arguments& arguments,
Expand Down
3 changes: 1 addition & 2 deletions Source/Application/ImGuiApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@

#pragma once

#include <Magnum/ImGuiIntegration/Context.hpp>

#include "Application/GLApplication.h"
#include <Magnum/ImGuiIntegration/Context.hpp>

/****************************************************************************************************/
class ImGuiApplication : public GLApplication {
Expand Down
6 changes: 3 additions & 3 deletions Source/Application/PickableApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* limitations under the License.
*/

#include "Application/PickableApplication.h"
#include "DrawableObjects/PickableObject.h"

#include <Magnum/GL/DefaultFramebuffer.h>
#include <Magnum/GL/PixelFormat.h>
#include <Magnum/Image.h>

#include "Application/PickableApplication.h"
#include "DrawableObjects/PickableObject.h"

#include <ImGuizmo.h>

/****************************************************************************************************/
Expand Down
4 changes: 2 additions & 2 deletions Source/Application/PickableApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

#pragma once

#include "Application/ImGuiApplication.h"

#include <Magnum/Magnum.h>
#include <Magnum/PixelFormat.h>
#include <Magnum/GL/Framebuffer.h>
#include <Magnum/GL/Renderbuffer.h>
#include <Magnum/GL/RenderbufferFormat.h>

#include "Application/ImGuiApplication.h"

#include <unordered_map>

/****************************************************************************************************/
Expand Down
61 changes: 61 additions & 0 deletions Source/DrawableObjects/Curves/CubicBezier.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Copyright 2020 Nghia Truong <nghiatruong.vn@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once
#include "DrawableObjects/Curves/Curve.h"

/****************************************************************************************************/
class CubicBezier : public Curve {
public:
explicit CubicBezier(Scene3D* const scene,
int subdivision = 128,
const Color3& color = Color3(1.0f),
float thickness = 1.0f,
bool renderControlPoints = true,
bool editableControlPoints = true,
float controlPointRadius = 0.05f) :
Curve(scene, subdivision, color, thickness, renderControlPoints,
editableControlPoints, controlPointRadius) {}
protected:
virtual void computeLines() override {
if(m_ControlPoints.size() != 4) {
Fatal() << "Cubic Bezier requires 4 control points, currently has"
<< m_ControlPoints.size();
}
const auto B0 = m_ControlPoints[0];
const auto B1 = m_ControlPoints[1];
const auto B2 = m_ControlPoints[2];
const auto B3 = m_ControlPoints[3];

const auto step = 1.0f / static_cast<float>(m_Subdivision);
for(int i = 0; i <= m_Subdivision; ++i) {
const auto t = static_cast<float>(i) * step;
const auto t_sqr = t * t;
const auto one_m_t = 1.0f - t;
const auto one_m_t_sqr = one_m_t * one_m_t;

const auto position = one_m_t * one_m_t_sqr * B0 +
3.0f * one_m_t_sqr * t * B1 +
3.0f * one_m_t * t_sqr * B2 +
t * t_sqr * B3;
m_Points.push_back(position);

if(i == 0 || i == m_Subdivision) {
m_Points.push_back(position);
}
}
}
};
56 changes: 0 additions & 56 deletions Source/DrawableObjects/Curves/CubicBezierCurve.cpp

This file was deleted.

32 changes: 0 additions & 32 deletions Source/DrawableObjects/Curves/CubicBezierCurve.h

This file was deleted.

Loading

0 comments on commit dabc324

Please sign in to comment.