Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • shlomist/unionized-triangles
  • blaicheo/unionized-triangles-2
2 results
Show changes
Commits on Source (23)
Showing with 179 additions and 53 deletions
build
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/settings.json
\ No newline at end of file
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(ctest) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${cmake.testProgram}",
"args": ["${cmake.testArgs}"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}
\ No newline at end of file
......@@ -25,10 +25,18 @@ add_executable(
tests/unit_tests/split_triangle_tests.cpp
tests/unit_tests/simple_triangle_tests.cpp
tests/unit_tests/point_in_triangle_tests.cpp
tests/unit_tests/triangulation_tests.cpp
tests/unit_tests/ear_removal_tests.cpp
src/utilities/intersections.cpp
tests/union_tests.cpp
tests/unit_tests/orientation_tests.cpp
tests/unit_tests/contourize_tests.cpp
tests/unit_tests/intersection_tests/intersections_tests.cpp
tests/edge_union_cases.cpp
tests/unit_tests/orientation_tests.cpp
tests/union_neighbours_tests.cpp
tests/quad_tree_tests.cpp
tests/unit_tests/interpolate_z_tests.cpp
tests/unit_tests/convex_triangulation_tests.cpp
src/debug_utilities/mostly_equal.cpp
src/utilities/intersections.cpp
src/shapes/triangle.cpp
src/shapes/triangle_edges.cpp
src/utilities/contourize.cpp
......@@ -36,21 +44,15 @@ add_executable(
src/utilities/orientation.cpp
src/shapes/point.cpp
src/union.cpp
src/utilities/triangulation.cpp
src/utilities/pointList.cpp
tests/unit_tests/orientation_tests.cpp
tests/unit_tests/intersections_tests.cpp
src/data_structures/box.cpp
src/data_structures/quad_tree.cpp
tests/quad_tree_tests.cpp
tests/edge_union_cases.cpp
tests/unit_tests/convex_triangulation_tests.cpp
src/utilities/convex_triangulation.cpp
tests/unit_tests/edge_direction_intr_tests.cpp
tests/unit_tests/contourize_tests.cpp
src/debug_utilities/print_triangles.cpp
src/utilities/split_triangle.cpp
tests/unit_tests/orientation_tests.cpp
src/debug_utilities/shift_triangle.cpp
src/utilities/interpolate_z.cpp
src/data_structures/quad_tree.cpp
src/data_structures/box_edges.cpp
)
include_directories(include)
......
Provides a datastructure for storing triangles based on how far they are from a light source.
Provides a function to perform a union on 2 triangles. Intended for use with cone-tracing algorithms.
Provides a datastructure for storing triangles based on how far they are from a light source. (Not Implemented Yet)
The datastructure is capable of performing the following queries:
1. for a point, get the closest triangle
2. get the visible surface area
## Building
Create a build directory and setup cmake
```
mkdir build
cd build
cmake ..
```
Build code
```
make
```
Run tests
```
./tests
```
\ No newline at end of file
#pragma once
#include <point.h>
#include "box_edges.h"
struct Triangle;
struct Point;
#define BOX_NB_POINTS 4
// left -> +x
// up -> +y
struct Box {
float minX, maxX, minY, maxY;
bool isIn(const Triangle &t) const;
bool isIn(const Point &p) const;
Point topLeft;
Point bottomRight;
Point points [BOX_NB_POINTS];
BoxEdges edges;
Box(Point topLeft, Point bottomRight);
bool intersects(const Triangle &t) const;
bool intersects(const Point &p) const;
Box firstQuadrant() const;
Box secondQuadrant() const;
Box thirdQuadrant() const;
Box fourthQuadrant() const;
};
\ No newline at end of file
#pragma once
#include <edge.h>
struct Box;
struct BoxEdges {
static const int size = 4;
Edge e [4];
BoxEdges(const Point p[size]);
};
\ No newline at end of file
......@@ -4,6 +4,7 @@
#define NB_TRIANGLE_SIDES 3
#define EPSILON 0.00001
// all points must have values between these 2 values
#define MAX_POINT 10
......
#pragma once
#include <vector>
#include <string>
#include <exception>
struct Triangle;
struct Point;
class ContourizeException : public std::exception {
virtual const char *what() const throw();
};
// creates a contour from a list of points
std::vector<Point> contourize(const std::vector<Point> &points);
\ No newline at end of file
......@@ -5,4 +5,4 @@
#include <vector>
// Requires a convex shape
std::vector<Triangle> convexTriangulation(const std::vector<Point> &points, int depth, int triangleId);
std::vector<Triangle> convexTriangulation(const std::vector<Point> &points, int triangleId, std::shared_ptr<std::vector<int>> neighbours);
#pragma once
#include "point.h"
#include <vector>
struct Edge {
Point p1, p2;
bool positiveSide(const Point &p) const;
};
\ No newline at end of file
};
std::vector<Edge> makeEdges(const std::vector<Point> &points);
\ No newline at end of file
#pragma once
#include <vector>
struct Point;
struct Edge;
float interpolateZ(const Edge &e, const Point &p);
......@@ -11,6 +11,7 @@ struct TrigTrigInterResults {
std::vector<Point> results;
};
std::optional<Point> intersectionFirstSide(const Edge &e1, const Edge &e2);
std::optional<Point> intersectionWithinEdge(const Edge &e1, const Edge &e2);
std::optional<Point> intersection(const Edge &e1, const Edge &e2);
......@@ -20,4 +21,4 @@ bool intersect(const Triangle &t1, const Triangle &t2);
std::optional<Point> intersectionWithinEdgeDirection(const Edge &e1, const Edge &e2);
std::vector<Point> intersections(const Triangle t, const Edge &line);
\ No newline at end of file
std::vector<Point> intersections(const std::vector<Point> &points, const Edge &line);
\ No newline at end of file
#pragma once
struct Triangle;
struct Point;
enum Orientation {
Clockwise, Collinear, Counterclockwise
};
Orientation orientation(const Point &p1, const Point &p2, const Point &p3);
\ No newline at end of file
Orientation orientation(const Point &p1, const Point &p2, const Point &p3);
Orientation orientation(const Triangle &t);
\ No newline at end of file
......@@ -2,8 +2,11 @@
#include <ostream>
struct Point {
float x, y;
float x, y, z;
bool operator==(const Point &other) const;
Point operator-(const Point &other) const;
Point operator+(const Point &other) const;
Point operator-() const;
};
std::ostream &operator<<(std::ostream &os, Point const &p);
......@@ -3,22 +3,30 @@
#include <memory>
#include <vector>
#include "box.h"
#include <set>
const int POINT_NOT_IN_QUADTREE = -1;
const int QUADTREE_MAX_DEPTH = 5;
#define QUADTREE_NODE_MAX_SHAPE 4
class QuadTree {
class QuadTree
{
Box b;
std::vector<Triangle> triangles;
int level;
std::vector<Triangle> triangles;
std::vector<QuadTree> children;
QuadTree(Box b, int level);
void collectUniqueTriangleFragments(const Triangle &t, std::set<int> &seen, std::vector<Triangle> &result) const;
void split();
void addNonIntersectingTriangle(const Triangle &t);
public:
QuadTree(Box b);
void addTriangle(Triangle triangle);
std::vector<Triangle> visibleSurface() const;
// returns triangle id
int pointIntersection(Point p) const;
std::vector<Triangle> visibleSurface(std::set<int> &seen) const;
public:
QuadTree(Box b);
void addTriangle(const Triangle &triangle);
std::vector<Triangle> visibleSurface() const;
// returns triangle id
int pointIntersection(const Point &p) const;
};
\ No newline at end of file
#pragma once
struct Triangle;
void shiftZ(Triangle &t, float z) ;
\ No newline at end of file
......@@ -5,4 +5,4 @@
struct Triangle;
struct Edge;
std::vector<std::vector<Point>> splitTriangle(const Triangle &t, const Edge &line);
\ No newline at end of file
std::vector<std::vector<Point>> splitShape(const std::vector<Point> &points, const Edge &line);
\ No newline at end of file
#pragma once
#include "point.h"
#include "print_triangle.h"
#include <vector>
#include <memory>
// points specified counterclockwise
// note : Triangle equality is only specified for tests
// points specified in counterclockwise or collinear (line / point) order
struct Triangle
{
Point points[3];
int depth;
int id;
bool neighbours(const Triangle &other) const;
Triangle(const Point &p1, const Point &p2, const Point &p3, int depth, int id = 0);
int mainTriangleId;
int fragmentId;
std::shared_ptr<std::vector<int>> neighbours;
Triangle(const Point &p1, const Point &p2, const Point &p3, int mainTriangleId = 0, const std::vector<int> neighbours = {});
Triangle(const Point &p1, const Point &p2, const Point &p3, int mainTriangleId, std::shared_ptr<std::vector<int>> neighbours);
bool pointInTriangle(const Point &p) const;
Point nextPoint(int pointIndex) const;
bool operator==(const Triangle &other) const;
......
#pragma once
class TriangleFragmentIdAssigner {
public:
static TriangleFragmentIdAssigner& getInstance()
{
static TriangleFragmentIdAssigner instance;
return instance;
}
int generateUniqueId() {
currentInd++;
return currentInd;
};
private:
int currentInd = 0;
TriangleFragmentIdAssigner() {}
public:
TriangleFragmentIdAssigner(TriangleFragmentIdAssigner const&) = delete;
void operator=(TriangleFragmentIdAssigner const&) = delete;
};
\ No newline at end of file
#pragma once
#include <vector>
#include <optional>
#include <triangle.h>
class PointList;
struct Point;
std::optional<Triangle> removeEar(int &index, PointList &pointList, const std::vector<Point> &allPoints);
std::vector<Triangle> triangulate(std::vector<Point> points);
std::vector<Triangle> triangulate(Triangle t1, Triangle t2);
\ No newline at end of file