diff options
Diffstat (limited to 'Software/Visual_Studio/Native')
4 files changed, 45 insertions, 75 deletions
diff --git a/Software/Visual_Studio/Native/Tango.ColorLib/ColorConverter.cpp b/Software/Visual_Studio/Native/Tango.ColorLib/ColorConverter.cpp index d398453f8..2b8131657 100644 --- a/Software/Visual_Studio/Native/Tango.ColorLib/ColorConverter.cpp +++ b/Software/Visual_Studio/Native/Tango.ColorLib/ColorConverter.cpp @@ -1267,7 +1267,7 @@ bool Tango::ColorLib::ColorConverter::IsInGamut(double *InLab, SURROUND sur) VectorXd V1(3); VectorXd V2(3); V1 << JLab[0], JLab[1], JLab[2]; - V1 << xCoord[0], xCoord[1], xCoord[2]; + V2 << xCoord[0], xCoord[1], xCoord[2]; double dECMC; m_Conv02->SymmetricaldECMC(V1, V2, dECMC); if (dECMC < dETol) diff --git a/Software/Visual_Studio/Native/Tango.ColorLib/Tango.ColorLib.vcxproj b/Software/Visual_Studio/Native/Tango.ColorLib/Tango.ColorLib.vcxproj index bed1cc7bb..506745a12 100644 --- a/Software/Visual_Studio/Native/Tango.ColorLib/Tango.ColorLib.vcxproj +++ b/Software/Visual_Studio/Native/Tango.ColorLib/Tango.ColorLib.vcxproj @@ -23,7 +23,7 @@ <ProjectGuid>{625B2A26-97A9-45C9-8BCF-6BD30F593E17}</ProjectGuid> <Keyword>Win32Proj</Keyword> <RootNamespace>TangoColorLib</RootNamespace> - <WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion> + <WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion> </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> diff --git a/Software/Visual_Studio/Native/Tango.ColorLib/Utils/GBD.cpp b/Software/Visual_Studio/Native/Tango.ColorLib/Utils/GBD.cpp index 0a21d5f25..43132ab20 100644 --- a/Software/Visual_Studio/Native/Tango.ColorLib/Utils/GBD.cpp +++ b/Software/Visual_Studio/Native/Tango.ColorLib/Utils/GBD.cpp @@ -36,7 +36,7 @@ GBD::~GBD() { } -void GBD::TriangleRayIntersection(double *origin, double *direction, bool intersect, double *xCoor) +void GBD::TriangleRayIntersection(double *origin, double *direction, bool &intersect, double *xCoor) { int i, j; @@ -47,23 +47,36 @@ void GBD::TriangleRayIntersection(double *origin, double *direction, bool inters double t = LargeNumber; double u = t; double v = t; - double *edge1 = new double[3]; - double *edge2 = new double[3]; - double *tvec = new double[3]; // vector from vert0 to ray origin - double *pvec = new double[3]; - double *qvec = new double[3]; + //double *edge1 = new double[3]; + //double *edge2 = new double[3]; + VectorXd tvec(3); + VectorXd qvec(3); + VectorXd pvec(3); + VectorXd edge1(3); + VectorXd edge2(3); + VectorXd VDirection(3); + VDirection << direction[0], direction[1], direction[2]; + //double *tvec = new double[3]; // vector from vert0 to ray origin + //double *pvec = new double[3]; + //double *qvec = new double[3]; double det = 0; bool angleOK = false; for (i = 0; i < m_nTriangles; ++i) { for (j = 0; j < 3; ++j) { - edge1[j] = m_vert1[i][j] - m_vert0[i][j]; - edge2[j] = m_vert2[i][j] - m_vert0[i][j]; - tvec[j] = origin[j] - m_vert0[i][j]; + edge1(j)= m_vert1[i][j] - m_vert0[i][j]; + edge2(j) = m_vert2[i][j] - m_vert0[i][j]; + tvec(j) = origin[j] - m_vert0[i][j]; } - crossProduct(direction, edge2, pvec); + crossProduct(VDirection, edge2, pvec); det = dotProduct(edge1, pvec); + //std::cout << "edge1 " << edge1(0) <<" "<< edge1(1) <<" "<< edge1(2) << "\n"; + //std::cout << "edge2 " << edge2(0) << " " << edge2(1) << " " << edge2(2)<< "\n"; + //std::cout << "tvec " << tvec(0) << " " << tvec(1) << " " << tvec(2) << "\n"; + //std::cout << "crossProduct " << pvec(0) << " " << pvec(1) << " " << pvec(2)<< "\n"; + //std::cout << "Det " << det << "\n"; + switch (rtri) { case TwoSided: @@ -81,9 +94,14 @@ void GBD::TriangleRayIntersection(double *origin, double *direction, bool inters { u = dotProduct(tvec, pvec) / det; crossProduct(tvec, edge1, qvec); - v = dotProduct(direction, qvec) / det; + v = dotProduct(VDirection, qvec) / det; t = dotProduct(edge2, qvec) / det; ok = (angleOK && (u >= -eps) && (v >= -eps) && ((u + v) <= 1 + eps)); + //std::cout << "u " << u << "\n"; + //std::cout << "v " << v << "\n"; + //std::cout << "Qvec " << qvec(0) << " " << qvec(1) << " " << qvec(2) << "\n"; + //std::cout << "t " << t << "\n"; + //std::cout << "OK " << ok << "\n"; } else ok = false; @@ -106,60 +124,11 @@ void GBD::TriangleRayIntersection(double *origin, double *direction, bool inters if (intersect) { for (j = 0; j < 3; ++j) - xCoor[j] = m_vert0[i][j] + edge1[j] * u + edge2[j] * v; - if (edge1 != NULL) - { - delete[]edge1; - edge1 = NULL; - } - if (edge2 != NULL) - { - delete[]edge2; - edge2 = NULL; - } - if (tvec != NULL) - { - delete[]tvec; - tvec = NULL; - } - if (qvec != NULL) - { - delete[]qvec; - qvec = NULL; - } - if (pvec != NULL) - { - delete[]pvec; - pvec = NULL; - } + xCoor[j] = m_vert0[i][j] + edge1(j) * u + edge2(j) * v; return; } } - if (edge1 != NULL) - { - delete[]edge1; - edge1 = NULL; - } - if (edge2 != NULL) - { - delete[]edge2; - edge2 = NULL; - } - if (tvec != NULL) - { - delete[]tvec; - tvec = NULL; - } - if (qvec != NULL) - { - delete[]qvec; - qvec = NULL; - } - if (pvec != NULL) - { - delete[]pvec; - pvec = NULL; - } + return; } @@ -289,23 +258,24 @@ void GBD::InitData(unsigned char* colorTransformBuffer, long colorTransformFileS // dot product of two vectors. -double GBD::dotProduct(double *vect_A, double*vect_B) +double GBD::dotProduct(VectorXd vect_A, VectorXd vect_B) { - int product = 0; + double product = 0.0; // Loop for calculate dot product - int n = sizeof(vect_A); + + int n = vect_A.size(); for (int i = 0; i < n; i++) - product = product + vect_A[i] * vect_B[i]; + product = product + vect_A(i) * vect_B(i); return (product); } // cross product of two vectors -void GBD::crossProduct(double *vect_A, double* vect_B,double *cross_P) +void GBD::crossProduct(VectorXd vect_A, VectorXd vect_B, VectorXd &cross_P) { - cross_P[0] = vect_A[1] * vect_B[2] - vect_A[2] * vect_B[1]; - cross_P[1] = vect_A[0] * vect_B[2] - vect_A[2] * vect_B[0]; - cross_P[2] = vect_A[0] * vect_B[1] - vect_A[1] * vect_B[0]; + cross_P(0) = vect_A(1) * vect_B(2) - vect_A(2) * vect_B(1); + cross_P(1) = -vect_A(0) * vect_B(2) + vect_A(2) * vect_B(0); + cross_P(2) = vect_A(0) * vect_B(1) - vect_A(1) * vect_B(0); return; } diff --git a/Software/Visual_Studio/Native/Tango.ColorLib/Utils/GBD.h b/Software/Visual_Studio/Native/Tango.ColorLib/Utils/GBD.h index 6ef4d3a51..61aadf37a 100644 --- a/Software/Visual_Studio/Native/Tango.ColorLib/Utils/GBD.h +++ b/Software/Visual_Studio/Native/Tango.ColorLib/Utils/GBD.h @@ -14,7 +14,7 @@ public: int GetNTriangles() { return(m_nTriangles); }; C_RGB_XYZ_Lab getCenter(){ return(m_CenterLab);}; void InitData(unsigned char* colorTransformBuffer, long colorTransformFileSize); - void TriangleRayIntersection(double *origin, double *direction, bool intersect, double *xCoor); + void TriangleRayIntersection(double *origin, double *direction, bool &intersect, double *xCoor); private: int m_prec; int m_nDevChan; @@ -31,8 +31,8 @@ private: void SetNDev_Channels(int nDevChan) { m_nDevChan = nDevChan; }; void SetNTriangles(int nTriangles) { m_nTriangles = nTriangles; }; //void SetCenter( C_RGB_XYZ_Lab CenterLab); - double dotProduct(double *vect_A, double*vect_B); - void crossProduct(double *vect_A, double* vect_B, double *cross_P); + double dotProduct(VectorXd vect_A, VectorXd vect_B); + void crossProduct(VectorXd vect_A, VectorXd vect_B, VectorXd &cross_P); }; #endif |
