protected void PrepareData() { if (m_Data == null) { return; } // Convolve precise array of data with color matching functions RefractionData D = new RefractionData(); double nX = 0.0; double nY = 0.0; double nZ = 0.0; double kX = 0.0; double kY = 0.0; double kZ = 0.0; int Count = m_Chromas.Length / 4; for (int i = 0; i < Count; i++) { double wl = 1e-3 * m_Chromas[4 * i + 0]; // In µm double x = m_Chromas[4 * i + 1]; double y = m_Chromas[4 * i + 2]; double z = m_Chromas[4 * i + 3]; SampleData((float)wl, D); nX += x * D.n; nY += y * D.n; nZ += z * D.n; kX += x * D.k; kY += y * D.k; kZ += z * D.k; } double dl = 1e-3 * (m_Chromas[4] - m_Chromas[0]); // Integration step float Result_nX = (float)(dl * nX); float Result_nY = (float)(dl * nY); float Result_nZ = (float)(dl * nZ); float Result_kX = (float)(dl * kX); float Result_kY = (float)(dl * kY); float Result_kZ = (float)(dl * kZ); // Transform into sRGB XYZ2sRGB(Result_nX, Result_nY, Result_nZ, out m_IndicesR.n, out m_IndicesG.n, out m_IndicesB.n); XYZ2sRGB(Result_kX, Result_kY, Result_kZ, out m_IndicesR.k, out m_IndicesG.k, out m_IndicesB.k); }
protected void SampleData(float _Wavelength, RefractionData D) { for (int i = 0; i < m_Data.Length - 1; i++) { // if ( m_Data[i].Wavelength <= _Wavelength && m_Data[i+1].Wavelength >= _Wavelength ) if (m_Data[i + 1].Wavelength >= _Wavelength) { // Found the proper interval! float t = (_Wavelength - m_Data[i].Wavelength) / (m_Data[i + 1].Wavelength - m_Data[i].Wavelength); D.Wavelength = _Wavelength; D.n = (1 - t) * m_Data[i].n + t * m_Data[i + 1].n; D.k = (1 - t) * m_Data[i].k + t * m_Data[i + 1].k; return; } } throw new Exception("Wavelength out of range!"); }
protected void SampleData( float _Wavelength, RefractionData D ) { for ( int i=0; i < m_Data.Length-1; i++ ) // if ( m_Data[i].Wavelength <= _Wavelength && m_Data[i+1].Wavelength >= _Wavelength ) if ( m_Data[i+1].Wavelength >= _Wavelength ) { // Found the proper interval! float t = (_Wavelength - m_Data[i].Wavelength) / (m_Data[i+1].Wavelength - m_Data[i].Wavelength); D.Wavelength = _Wavelength; D.n = (1-t) * m_Data[i].n + t * m_Data[i+1].n; D.k = (1-t) * m_Data[i].k + t * m_Data[i+1].k; return; } throw new Exception( "Wavelength out of range!" ); }
protected void PrepareData() { if ( m_Data == null ) return; // Convolve precise array of data with color matching functions RefractionData D = new RefractionData(); double nX = 0.0; double nY = 0.0; double nZ = 0.0; double kX = 0.0; double kY = 0.0; double kZ = 0.0; int Count = m_Chromas.Length / 4; for ( int i=0; i < Count; i++ ) { double wl = 1e-3 * m_Chromas[4*i+0]; // In µm double x = m_Chromas[4*i+1]; double y = m_Chromas[4*i+2]; double z = m_Chromas[4*i+3]; SampleData( (float) wl, D ); nX += x * D.n; nY += y * D.n; nZ += z * D.n; kX += x * D.k; kY += y * D.k; kZ += z * D.k; } double dl = 1e-3 * (m_Chromas[4] - m_Chromas[0]); // Integration step float Result_nX = (float) (dl * nX); float Result_nY = (float) (dl * nY); float Result_nZ = (float) (dl * nZ); float Result_kX = (float) (dl * kX); float Result_kY = (float) (dl * kY); float Result_kZ = (float) (dl * kZ); // Transform into sRGB XYZ2sRGB( Result_nX, Result_nY, Result_nZ, out m_IndicesR.n, out m_IndicesG.n, out m_IndicesB.n ); XYZ2sRGB( Result_kX, Result_kY, Result_kZ, out m_IndicesR.k, out m_IndicesG.k, out m_IndicesB.k ); }