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 (44)
Showing with 230 additions and 20 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
......@@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.12)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
include(FetchContent)
FetchContent_Declare(
googletest
......@@ -20,13 +22,21 @@ project(intersection)
add_executable(
tests
tests/unit_tests/split_triangle_tests.cpp
tests/unit_tests/simple_triangle_tests.cpp
tests/unit_tests/contourize_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
......@@ -34,9 +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
src/data_structures/box.cpp
src/utilities/convex_triangulation.cpp
src/debug_utilities/print_triangles.cpp
src/utilities/split_triangle.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 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;
#define BOX_NB_POINTS 4
// left -> +x
// up -> +y
struct Box {
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
#pragma once
#define MAX_TRIANGLE_INTERSECTION_POINTS 12
\ No newline at end of file
#define MAX_TRIANGLE_INTERSECTION_POINTS 12
#define NB_TRIANGLE_SIDES 3
#define EPSILON 0.00001
// all points must have values between these 2 values
#define MAX_POINT 10
#define MIN_POINT -10
\ No newline at end of file
#pragma once
#include <vector>
#include <string>
#include <exception>
struct Triangle;
struct Point;
class ContourizeException : public std::exception {
virtual const char *what() const throw();
};
std::vector<Point> contourize(const Triangle &leftmostTriangle, const Triangle &otherTriangle, int leftmostInd);
std::vector<Point> sortPoints(std::vector<Point> &points);
\ No newline at end of file
// creates a contour from a list of points
std::vector<Point> contourize(const std::vector<Point> &points);
\ No newline at end of file
#pragma once
#include <triangle.h>
#include <point.h>
#include <vector>
// Requires a convex shape
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,14 @@ 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);
std::vector<Point> intersections(const Triangle &t1, const Triangle &t2);
\ No newline at end of file
std::vector<Point> intersections(const Triangle &t1, const Triangle &t2);
bool intersect(const Triangle &t1, const Triangle &t2);
std::optional<Point> intersectionWithinEdgeDirection(const Edge &e1, const Edge &e2);
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
#pragma once
#include <ostream>
struct Point {
float x, y;
float x, y, z;
bool operator==(const Point &other) const;
};
\ No newline at end of file
Point operator-(const Point &other) const;
Point operator+(const Point &other) const;
Point operator-() const;
};
std::ostream &operator<<(std::ostream &os, Point const &p);
......@@ -8,6 +8,7 @@ struct PointNode {
int nextIndex;
Point p;
int next() const;
int prev() const;
};
class PointList {
......@@ -16,7 +17,7 @@ class PointList {
PointNode points[MAX_TRIANGLE_INTERSECTION_POINTS];
PointList(const std::vector<Point> &points);
bool empty() const;
int prev(const PointNode &p) const;
int next(const PointNode &p) const;
int getSize() const;
void remove(int index);
};
\ No newline at end of file
#pragma once
#include <ostream>
#include <vector>
struct Triangle;
std::ostream &operator<<(std::ostream &os, const Triangle &t);
#pragma once
#include "triangle.h"
#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
{
Box b;
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);
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
#pragma once
#include <vector>
#include <point.h>
struct Triangle;
struct Edge;
std::vector<std::vector<Point>> splitShape(const std::vector<Point> &points, const Edge &line);
\ No newline at end of file
......@@ -3,11 +3,12 @@
template<typename T>
class StaticVector{
int size;
int size = 0;
public:
T items [2];
int getSize() const;
void clear();
void push_back(T item);
void push_back(std::optional<T> item);
};
......@@ -25,4 +26,8 @@ template<typename T> void StaticVector<T>::push_back(std::optional<T> item) {
template<typename T> int StaticVector<T>::getSize() const {
return size;
}
template<typename T> void StaticVector<T>::clear() {
size = 0;
}
\ No newline at end of file