Skip to content

Commit

Permalink
Merge pull request #6 from Azzinoth/dev
Browse files Browse the repository at this point in the history
Merging from the development branch.
  • Loading branch information
Azzinoth authored May 15, 2024
2 parents df65e79 + 4ef3eb3 commit c848c28
Show file tree
Hide file tree
Showing 25 changed files with 720 additions and 206 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ContinuousIntegration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
Write-Host "Executable started."
Write-Host "Waiting for the process to exit..."
$process.WaitForExit(300000) # 300 seconds
$process.WaitForExit(500000) # 500 seconds
$substring = "All evaluations passed"
$found = $false
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ project(HabiCAT3D LANGUAGES CXX)

set(CMAKE_CXX_FLAGS_DEBUG "/MP /Zi /MDd /INCREMENTAL:NO /DEBUG /OPT:REF /OPT:ICF /Od")
set(CMAKE_CXX_FLAGS_RELEASE "/MP")
# Set the stack reserve size to 10 MB
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:10485760")

# Because of we are catching CGAL exceptions in the loop, we need to enable this flag
if(MSVC)
Expand Down
73 changes: 25 additions & 48 deletions SubSystems/ComplexityCore/ComplexityMetricInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ using namespace FocalEngine;

ComplexityMetricInfo::ComplexityMetricInfo() {}

float ComplexityMetricInfo::GetTotalArea()
double ComplexityMetricInfo::GetTotalArea()
{
return TotalArea;
}

void ComplexityMetricInfo::FillTrianglesData(std::vector<float>& Vertices, std::vector<float>& Colors, std::vector<float>& UVs, std::vector<float>& Tangents, std::vector<int>& Indices, std::vector<float>& Normals)
void ComplexityMetricInfo::FillTrianglesData(std::vector<double>& Vertices, std::vector<float>& Colors, std::vector<float>& UVs, std::vector<float>& Tangents, std::vector<int>& Indices, std::vector<float>& Normals)
{
MeshData.Vertices = Vertices;
MeshData.Colors = Colors;
Expand All @@ -21,40 +21,42 @@ void ComplexityMetricInfo::FillTrianglesData(std::vector<float>& Vertices, std::
TrianglesNormals.clear();
TrianglesArea.clear();
TrianglesCentroids.clear();
TotalArea = 0;
TotalArea = 0.0;

std::vector<glm::vec3> Triangle;
std::vector<glm::dvec3> Triangle;
Triangle.resize(3);
std::vector<glm::vec3> TriangleNormal;
TriangleNormal.resize(3);

for (size_t i = 0; i < Indices.size(); i += 3)
{
int VertexPosition = Indices[i] * 3;
Triangle[0] = glm::vec3(Vertices[VertexPosition], Vertices[VertexPosition + 1], Vertices[VertexPosition + 2]);
Triangle[0] = glm::dvec3(Vertices[VertexPosition], Vertices[VertexPosition + 1], Vertices[VertexPosition + 2]);

VertexPosition = Indices[i + 1] * 3;
Triangle[1] = glm::vec3(Vertices[VertexPosition], Vertices[VertexPosition + 1], Vertices[VertexPosition + 2]);
Triangle[1] = glm::dvec3(Vertices[VertexPosition], Vertices[VertexPosition + 1], Vertices[VertexPosition + 2]);

VertexPosition = Indices[i + 2] * 3;
Triangle[2] = glm::vec3(Vertices[VertexPosition], Vertices[VertexPosition + 1], Vertices[VertexPosition + 2]);
Triangle[2] = glm::dvec3(Vertices[VertexPosition], Vertices[VertexPosition + 1], Vertices[VertexPosition + 2]);

Triangles.push_back(Triangle);
TrianglesArea.push_back(TriangleArea(Triangle[0], Triangle[1], Triangle[2]));
TotalArea += static_cast<float>(TrianglesArea.back());
TrianglesArea.push_back(GEOMETRY.CalculateTriangleArea(Triangle[0], Triangle[1], Triangle[2]));
TotalArea += TrianglesArea.back();

TrianglesCentroids.push_back((Triangle[0] + Triangle[1] + Triangle[2]) / 3.0f);
TrianglesCentroids.push_back((Triangle[0] + Triangle[1] + Triangle[2]) / 3.0);

if (!Normals.empty())
{
VertexPosition = Indices[i] * 3;
Triangle[0] = glm::vec3(Normals[VertexPosition], Normals[VertexPosition + 1], Normals[VertexPosition + 2]);
TriangleNormal[0] = glm::vec3(Normals[VertexPosition], Normals[VertexPosition + 1], Normals[VertexPosition + 2]);

VertexPosition = Indices[i + 1] * 3;
Triangle[1] = glm::vec3(Normals[VertexPosition], Normals[VertexPosition + 1], Normals[VertexPosition + 2]);
TriangleNormal[1] = glm::vec3(Normals[VertexPosition], Normals[VertexPosition + 1], Normals[VertexPosition + 2]);

VertexPosition = Indices[i + 2] * 3;
Triangle[2] = glm::vec3(Normals[VertexPosition], Normals[VertexPosition + 1], Normals[VertexPosition + 2]);
TriangleNormal[2] = glm::vec3(Normals[VertexPosition], Normals[VertexPosition + 1], Normals[VertexPosition + 2]);

TrianglesNormals.push_back(Triangle);
TrianglesNormals.push_back(TriangleNormal);
}
}

Expand All @@ -65,23 +67,23 @@ void ComplexityMetricInfo::UpdateAverageNormal()
{
AverageNormal = glm::vec3();

std::vector<float> OriginalAreas;
float TotalArea = 0.0f;
std::vector<double> OriginalAreas;
double TotalArea = 0.0;
for (size_t i = 0; i < Triangles.size(); i++)
{
const double originalArea = TriangleArea(Triangles[i][0], Triangles[i][1], Triangles[i][2]);
OriginalAreas.push_back(static_cast<float>(originalArea));
TotalArea += static_cast<float>(originalArea);
const double OriginalArea = GEOMETRY.CalculateTriangleArea(Triangles[i][0], Triangles[i][1], Triangles[i][2]);
OriginalAreas.push_back(OriginalArea);
TotalArea += OriginalArea;
}

// ******* Geting average normal *******
for (size_t i = 0; i < Triangles.size(); i++)
{
const float currentTriangleCoef = OriginalAreas[i] / TotalArea;
double CurrentTriangleCoef = OriginalAreas[i] / TotalArea;

AverageNormal += TrianglesNormals[i][0] * currentTriangleCoef;
AverageNormal += TrianglesNormals[i][1] * currentTriangleCoef;
AverageNormal += TrianglesNormals[i][2] * currentTriangleCoef;
AverageNormal += TrianglesNormals[i][0] * static_cast<float>(CurrentTriangleCoef);
AverageNormal += TrianglesNormals[i][1] * static_cast<float>(CurrentTriangleCoef);
AverageNormal += TrianglesNormals[i][2] * static_cast<float>(CurrentTriangleCoef);
}

AverageNormal = glm::normalize(AverageNormal);
Expand All @@ -92,25 +94,6 @@ glm::vec3 ComplexityMetricInfo::GetAverageNormal()
return AverageNormal;
}

double ComplexityMetricInfo::TriangleArea(glm::dvec3 PointA, glm::dvec3 PointB, glm::dvec3 PointC)
{
const double x1 = PointA.x;
const double x2 = PointB.x;
const double x3 = PointC.x;

const double y1 = PointA.y;
const double y2 = PointB.y;
const double y3 = PointC.y;

const double z1 = PointA.z;
const double z2 = PointB.z;
const double z3 = PointC.z;

return 0.5 * sqrt(pow(x2 * y1 - x3 * y1 - x1 * y2 + x3 * y2 + x1 * y3 - x2 * y3, 2.0) +
pow((x2 * z1) - (x3 * z1) - (x1 * z2) + (x3 * z2) + (x1 * z3) - (x2 * z3), 2.0) +
pow((y2 * z1) - (y3 * z1) - (y1 * z2) + (y3 * z2) + (y1 * z3) - (y2 * z3), 2.0));
}

void ComplexityMetricInfo::AddLayer(std::vector<float> TrianglesToData)
{
if (TrianglesToData.size() == Triangles.size())
Expand Down Expand Up @@ -218,12 +201,6 @@ void MeshLayer::FillRawData()
if (ParentComplexityMetricData == nullptr || TrianglesToData.empty())
return;

std::vector<float> PositionsVector;
for (size_t i = 0; i < ParentComplexityMetricData->MeshData.Vertices.size(); i++)
{
PositionsVector.push_back(ParentComplexityMetricData->MeshData.Vertices[i]);
}

std::vector<int> IndexVector;
for (size_t i = 0; i < ParentComplexityMetricData->MeshData.Indices.size(); i++)
{
Expand Down
16 changes: 6 additions & 10 deletions SubSystems/ComplexityCore/ComplexityMetricInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class MeshLayer
// For purposes of complexity metric storing of all of raw data is redundant,but it is needed for saving RUG file.
struct RawMeshData
{
std::vector<float> Vertices;
std::vector<double> Vertices;
std::vector<float> Colors;
std::vector<float> UVs;
std::vector<float> Tangents;
Expand All @@ -138,31 +138,27 @@ class ComplexityMetricInfo

int CurrentLayerIndex = -1;

float TotalArea = 0.0f;
double TotalArea = 0.0;
glm::vec3 AverageNormal = glm::vec3();
public:
ComplexityMetricInfo();

float GetTotalArea();
double GetTotalArea();

std::vector<int> TriangleSelected;

RawMeshData MeshData;

std::vector<std::vector<glm::vec3>> Triangles;
std::vector<std::vector<glm::dvec3>> Triangles;
std::vector<double> TrianglesArea;

std::vector<std::vector<glm::vec3>> TrianglesNormals;
std::vector<glm::vec3> TrianglesCentroids;

void FillTrianglesData(std::vector<float>& Vertices, std::vector<float>& Colors, std::vector<float>& UVs, std::vector<float>& Tangents, std::vector<int>& Indices, std::vector<float>& Normals);
std::vector<glm::dvec3> TrianglesCentroids;

void FillTrianglesData(std::vector<double>& Vertices, std::vector<float>& Colors, std::vector<float>& UVs, std::vector<float>& Tangents, std::vector<int>& Indices, std::vector<float>& Normals);

glm::vec3 GetAverageNormal();
void UpdateAverageNormal();

static double TriangleArea(glm::dvec3 PointA, glm::dvec3 PointB, glm::dvec3 PointC);

std::vector<MeshLayer> Layers;

void AddLayer(std::vector<float> TrianglesToData);
Expand Down
6 changes: 3 additions & 3 deletions SubSystems/ComplexityCore/ComplexityMetricManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ComplexityMetricManager* ComplexityMetricManager::Instance = nullptr;
ComplexityMetricManager::ComplexityMetricManager() {}
ComplexityMetricManager::~ComplexityMetricManager() {}

void ComplexityMetricManager::Init(std::vector<float>& Vertices, std::vector<float>& Colors, std::vector<float>& UVs, std::vector<float>& Tangents, std::vector<int>& Indices, std::vector<float>& Normals)
void ComplexityMetricManager::Init(std::vector<double>& Vertices, std::vector<float>& Colors, std::vector<float>& UVs, std::vector<float>& Tangents, std::vector<int>& Indices, std::vector<float>& Normals)
{
if (ActiveComplexityMetricInfo != nullptr)
delete ActiveComplexityMetricInfo;
Expand Down Expand Up @@ -34,7 +34,7 @@ void ComplexityMetricManager::ImportOBJ(const char* FileName, bool bForceOneMesh

if (FirstObject != nullptr)
{
COMPLEXITY_METRIC_MANAGER.Init(FirstObject->FVerC, FirstObject->fColorsC, FirstObject->FTexC, FirstObject->FTanC, FirstObject->FInd, FirstObject->FNorC);
COMPLEXITY_METRIC_MANAGER.Init(FirstObject->DVerC, FirstObject->FColorsC, FirstObject->FTexC, FirstObject->FTanC, FirstObject->FInd, FirstObject->FNorC);
}

for (size_t i = 0; i < ClientLoadCallbacks.size(); i++)
Expand Down Expand Up @@ -71,7 +71,7 @@ void ComplexityMetricManager::SaveToRUGFile(std::string FilePath)

int Count = static_cast<int>(ActiveComplexityMetricInfo->MeshData.Vertices.size());
File.write((char*)&Count, sizeof(int));
File.write((char*)ActiveComplexityMetricInfo->MeshData.Vertices.data(), sizeof(float) * Count);
File.write((char*)ActiveComplexityMetricInfo->MeshData.Vertices.data(), sizeof(double) * Count);

Count = static_cast<int>(ActiveComplexityMetricInfo->MeshData.Colors.size());
File.write((char*)&Count, sizeof(int));
Expand Down
4 changes: 2 additions & 2 deletions SubSystems/ComplexityCore/ComplexityMetricManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using namespace FocalEngine;

#include "../EngineInclude.h"

#define APP_VERSION 0.62f
#define APP_VERSION 0.87f

const COMDLG_FILTERSPEC RUGOSITY_LOAD_FILE_FILTER[] =
{
Expand All @@ -23,7 +23,7 @@ class ComplexityMetricManager

ComplexityMetricInfo* ActiveComplexityMetricInfo = nullptr;

void Init(std::vector<float>& Vertices, std::vector<float>& Colors, std::vector<float>& UVs, std::vector<float>& Tangents, std::vector<int>& Indices, std::vector<float>& Normals);
void Init(std::vector<double>& Vertices, std::vector<float>& Colors, std::vector<float>& UVs, std::vector<float>& Tangents, std::vector<int>& Indices, std::vector<float>& Normals);
void ImportOBJ(const char* FileName, bool bForceOneMesh);

void AddLoadCallback(std::function<void()> Func);
Expand Down
Loading

0 comments on commit c848c28

Please sign in to comment.