Commit f9e75258 authored by Lukas Vollmer's avatar Lukas Vollmer
Browse files

Moved Triangulation from VBAPFreeFieldRenderer to Triangulation

parent 728289fb
......@@ -16,6 +16,9 @@
*
*/
#ifndef IW_ITA_BASE_TRIANGULATION
#define IW_ITA_BASE_TRIANGULATION
#include <vector>
#include <VistaBase/VistaVector3D.h>
......@@ -29,41 +32,67 @@ namespace ITABase
{
class ITA_BASE_API CTriangulation
{
class VAVec;
class CLoudspeaker;
public:
// Legacy Constructor
CTriangulation(const std::vector< VistaVector3D >& vv3Loudspeaker, const std::vector <std::string>& vsID, const std::vector <int>& viID, const std::vector <int>& viChannel, const VistaVector3D& vReproductionCenterPos = VistaVector3D(0, 0, 0));
CTriangulation(const std::vector< VistaVector3D >& vvLoudspeakerPos, const VistaVector3D& vReproductionCenterPos);
CTriangulation(const std::vector< VistaVector3D >& vvLoudspeakerPos, const std::vector< VistaVector3D >& vvTriangulationIndices, const VistaVector3D& vReproductionCenterPos = VistaVector3D(0, 0, 0));
~CTriangulation();
VistaTriangle* GetTriangleIntersectedBySourceDirection(const VistaVector3D& vSourceDir);
bool IsDelaunayTriangulation(float epsilon = 1.0e-4);
int NumPoints() const;
bool GetPointIndicesFromTriangle(const VistaTriangle& vtTriangle, VistaVector3D& v3PointIndices) const;
bool IsDelaunayTriangulation(const float epsilon = 1.0e-4) const;
const VistaTriangle* GetTriangleIntersectedByPointDirection(const VistaVector3D& vPoint, VistaVector3D& vBarycentricCoords, int& iTriangleIndex, const bool bIsReferenced = false, const float epsilon = 1.0e-4) const;
const VistaTriangle* GetTriangleIntersectedByPointDirection(const VistaVector3D& vPoint, VistaVector3D& vBarycentricCoords, const bool bIsReferenced = false, const float epsilon = 1.0e-4) const;
const VistaTriangle* GetTriangleIntersectedByPointDirection(const VistaVector3D& vPoint, const bool bIsReferenced = false, const float epsilon = 1.0e-4) const;
// Operators
inline VistaTriangle operator[] (int i) const
{
return m_vtTriangulation[i];
}
inline VistaVector3D operator() (int i) const
{
return m_vv3TriangulationIndices[i];
}
private:
/* new Implementation @LVO */
std::vector< VistaVector3D > m_vvLoudspeakerPos;
std::vector< VistaVector3D > m_vv3LoudspeakerPos;
VistaVector3D m_v3CenterPosition;
std::vector< VistaVector3D > m_vv3TriangulationIndices;
std::vector< VistaTriangle > m_vtTriangulation;
/* Implementation from VBAP Renderer*/
struct sLoudspeaker
/* Implementation from VBAPFreeFieldRenderer */
class VAVec3
{
std::string sIdentifier;
int iIdentifier;
int iChannel;
VistaVector3D pos;
public:
double x, y, z;
};
struct sSection
// Loudspeaker
class CLoudspeaker
{
public:
std::string sIdentifier;
int iIdentifier;
std::vector <int> iLSIdentifier;
VistaPolygon Polygon;
int iChannel;
VAVec3 pos;
};
VistaVector3D m_vCenterPosition;
std::vector< sLoudspeaker > m_vLoudspeaker;
std::vector< sSection > m_vSection;
std::vector< VistaVector3D > m_vvTriangulationIndices;
std::vector< VistaTriangle > m_vTriangulation; //!< Triangulation all loudspeaker for the VBAP setup; Entries are the pos of the speaker safed in a VistaTriangle struct
std::vector< std::vector< sLoudspeaker > > m_vvTriangulationLoudspeaker; //!< Triangulation all loudspeaker for the VBAP setup; Entries are the actual loudspeaker according to m_voLoudspeaker
std::vector< CLoudspeaker > m_voLoudspeaker; //!< List of all loudspeaker for the VBAP setup
//The triangulation safed as a VistaVector with each entry in the vector corresponding to the index of a speaker
std::vector< std::vector< CLoudspeaker > > m_voTriangulationLoudspeaker; //!< Triangulation all loudspeaker for the VBAP setup; Entries are the actual loudspeaker according to m_voLoudspeaker
void Triangulate();
};
// ---------- Helper functions ----------
float calculateCircumcenter3D(const VistaTriangle& tTriangle, VistaVector3D& vCenter);
float sphereEquation(const VistaVector3D& vCenter, const VistaVector3D& vPoint);
}
}
#endif // IW_ITA_BASE_TRIANGULATION
\ No newline at end of file
This diff is collapsed.
#include <ITAStringUtils.h>
#include <stdio.h>
#include <vector>
#include <math.h>
#include <iostream>
#include <VistaBase/VistaVector3D.h>
#include <ITAConstants.h>
#include <ITABase/Math/Triangulation.h>
using namespace std;
using namespace ITABase;
using namespace ITABase::Math;
bool TestDelaunayCondition(const CTriangulation* triangulation)
{
if (!triangulation->IsDelaunayTriangulation())
{
cout << "Error: Predefined Triangulation satisfies Delaunay condition, however \"IsDelaunayTriangulation\" indicates it doesn't." << endl;
return false;
}
else
{
cout << "\"IsDelaunayTriangulation\" -- OK" << endl;
return true;
}
}
bool TestIntersectedTriangleDetection(const CTriangulation* triangulation)
{
bool passed = true;
// define test points
const vector< VistaVector3D> vv3TestPos{
VistaVector3D(0, 0, -1), // case node match
VistaVector3D(-0.088826996301291, 0.392029462242860, -0.797359488602036), // case on triangle edge
VistaVector3D( 0.193729508443099, 0.453823535457991, -0.631990887330380), // case inside triangle
VistaVector3D(2*0.193729508443099, 2*0.453823535457991, 2*-0.631990887330380) // not on radius inside triangle
};
float ab, ac;
VistaVector3D v3BarycentricCoords(0, 0, 0),
v3ReconstructedFromBary(0, 0, 0);
for (size_t i = 0; i < vv3TestPos.size(); i++)
{
// function under test
const VistaTriangle* pTriangle = triangulation->GetTriangleIntersectedByPointDirection(vv3TestPos[i], v3BarycentricCoords);
bool bInside = v3BarycentricCoords[0] > -1.0e-5 && v3BarycentricCoords[1] > -1.0e-5 && v3BarycentricCoords[2] > -1.0e-5;
if (i == 0 && bInside)
{
cout << "Test case 1: Node match -- OK" << endl;
passed = passed && true;
}
else if (i == 1 && bInside)
{
cout << "Test case 2: Triangle edge -- OK" << endl;
passed = passed && true;
}
else if (i == 2 && bInside)
{
cout << "Test case 3: Inside triangle -- OK" << endl;
passed = passed && true;
}
else if (i == 3 && bInside)
{
cout << "Test case 4: Inside triangle, at radius 2 -- OK" << endl;
passed = passed && true;
}
else
{
cout << "Error in test case " << i+1 << ": Found triangle is not intersected by point direction" << endl;
passed = passed && false;
}
}
if (passed)
cout << "\"GetTriangleIntersectedByPointDirection\" -- OK" << endl;
return passed;
}
int main( int, char** )
{
std::vector< int > v = StringToIntVec( "1,2,3,4" );
int nTests = 0, nErrors = 0;
// define points to be triangulated
const vector< VistaVector3D> vv3LsPos{ // 4-Design, 14 points
VistaVector3D(0, 0, -1),
VistaVector3D(-0.17765, 0.78406, -0.59472),
VistaVector3D(0.76784, -0.23818, -0.59472),
VistaVector3D(-0.59019, -0.54588, -0.59472),
VistaVector3D(-0.17765, -0.78406, 0.59472),
VistaVector3D(-0.59019, 0.54588, 0.59472),
VistaVector3D(0.76784, 0.23818, 0.59472),
VistaVector3D(-0.87947, 0.36847, -0.30125),
VistaVector3D(0.75884, 0.57741, -0.30125),
VistaVector3D(0.12063, -0.94588, -0.30125),
VistaVector3D(-0.87947, -0.36847, 0.30125),
VistaVector3D(0.12063, 0.94588, 0.30125),
VistaVector3D(0.75884, -0.57741, 0.30125),
VistaVector3D(-1.2246e-16, 0, 1)
};
// define center
const VistaVector3D v3CenterPos = VistaVector3D(0, 0, 0);
// define reference delaunay triangulation
const vector < VistaVector3D > vv3TriangulationIndices{
VistaVector3D(0, 1, 8),
VistaVector3D(0, 2, 9),
VistaVector3D(0, 3, 7),
VistaVector3D(0, 7, 1),
VistaVector3D(0, 8, 2),
VistaVector3D(0, 9, 3),
VistaVector3D(1, 5, 11),
VistaVector3D(1, 7, 5),
VistaVector3D(1, 11, 8),
VistaVector3D(2, 6, 12),
VistaVector3D(2, 8, 6),
VistaVector3D(2, 12, 9),
VistaVector3D(3, 4, 10),
VistaVector3D(3, 9, 4),
VistaVector3D(3, 10, 7),
VistaVector3D(4, 9, 12),
VistaVector3D(4, 12, 13),
VistaVector3D(4, 13, 10),
VistaVector3D(5, 7, 10),
VistaVector3D(5, 10, 13),
VistaVector3D(5, 13, 11),
VistaVector3D(6, 8, 11),
VistaVector3D(6, 11, 13),
VistaVector3D(6, 13, 12)
};
const CTriangulation* triangulation = new CTriangulation(vv3LsPos, vv3TriangulationIndices, v3CenterPos);
// ---------- Start Tests ----------
cout << setprecision(2);
cout << "\tStarting Tests for Triangulation\t" << endl;
cout << "------------------------------------------------" << endl << endl;
cout << "------------ Test 1 ------------" << endl;
cout << "Check Delaunay condition function with predefined triangulation from matlab" <<endl;
nErrors += TestDelaunayCondition(triangulation) ? 0 : 1;
nTests += 1;
cout << endl;
cout << "------------ Test 2 ------------" << endl;
cout << "Check calculation of intersected triangles for different cases" << endl;
nErrors += TestIntersectedTriangleDetection(triangulation) ? 0: 1;
nTests += 1;
cout << endl;
for( int n : v )
cout << n << endl;
// --------- All Tests finished ----------
cout << "------------------------------------------------" << endl;
cout << "All tests finished -- Passed " << nTests - nErrors << " of " << nTests << " tests" << endl;
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment