IccMAX 2.1.27
Color Profile Tools
Loading...
Searching...
No Matches
CIccMatrixMath Class Reference

#include <IccMatrixMath.h>

Public Member Functions

 CIccMatrixMath (const CIccMatrixMath &mat)
 
 CIccMatrixMath (icUInt16Number nRows, icUInt16Number nCols, bool bInitIdentity=false)
 
virtual ~CIccMatrixMath ()
 
virtual void dumpMtx (std::string &str) const
 
icFloatNumberentry (icUInt16Number nRow, icUInt16Number nCol=0)
 
const icFloatNumberentry (icUInt16Number nRow, icUInt16Number nCol=0) const
 
virtual icUInt16Number GetCols () const
 
virtual icUInt16Number GetRows () const
 
bool Invert ()
 
virtual bool isIdentityMtx () const
 
CIccMatrixMathMult (const CIccMatrixMath *matrix) const
 
icFloatNumber RowSum (icUInt16Number nRow) const
 
void Scale (icFloatNumber v)
 
bool SetRange (const icSpectralRange &from, const icSpectralRange &to)
 
virtual void VectorMult (icFloatNumber *pDst, const icFloatNumber *pSrc) const
 
void VectorScale (const icFloatNumber *vec)
 

Static Public Member Functions

static CIccMatrixMathrangeMap (const icSpectralRange &from, const icSpectralRange &to)
 

Protected Attributes

icUInt16Number m_nCols
 
icUInt16Number m_nRows
 
icFloatNumberm_vals
 

Detailed Description

Type: Class

Purpose: Object for performing matrix/vector math

Constructor & Destructor Documentation

◆ CIccMatrixMath() [1/2]

CIccMatrixMath::CIccMatrixMath ( icUInt16Number  nRows,
icUInt16Number  nCols,
bool  bInitIdentity = false 
)

Name: CIccMatrixMath::CIccMatrixMath

Purpose: Constructor

95{
96 int nTotal = nRows * nCols;
97 int nMin = nRows<nCols ? nRows : nCols;
98
99 m_nRows = nRows;
100 m_nCols = nCols;
101 m_vals = new icFloatNumber[nTotal];
102 if (bInitIdentity) {
103 memset(m_vals, 0, nTotal * sizeof(icFloatNumber));
104 int i;
105 for (i=0; i<nMin; i++) {
106 icFloatNumber *row = entry(nRows-1-i);
107 row[nCols-1-i] = 1.0;
108 }
109 }
110}
float icFloatNumber
Definition IccDefs.h:101
icFloatNumber * entry(icUInt16Number nRow, icUInt16Number nCol=0)
Definition IccMatrixMath.h:111
icFloatNumber * m_vals
Definition IccMatrixMath.h:126
icUInt16Number m_nCols
Definition IccMatrixMath.h:125
icUInt16Number m_nRows
Definition IccMatrixMath.h:125

References entry(), m_nCols, m_nRows, and m_vals.

Referenced by CIccMpeEmissionMatrix::Begin(), CIccMpeInvEmissionMatrix::Begin(), CIccMpeEmissionCLUT::Begin(), CIccMpeReflectanceCLUT::Begin(), CIccMpeEmissionObserver::Begin(), CIccMpeReflectanceObserver::Begin(), IIccProfileConnectionConditions::getEmissiveObserver(), CIccTagSpectralViewingConditions::getObserverMatrix(), Mult(), and rangeMap().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CIccMatrixMath() [2/2]

CIccMatrixMath::CIccMatrixMath ( const CIccMatrixMath matrix)

Name: CIccMatrixMath::CIccMatrixMath

Purpose: Copy Constructor

122{
123 int nTotal = matrix.m_nRows * matrix.m_nCols;
124 m_nRows = matrix.m_nRows;
125 m_nCols = matrix.m_nCols;
126 m_vals = new icFloatNumber[nTotal];
127 memcpy(m_vals, matrix.m_vals, nTotal*sizeof(icFloatNumber));
128}

References m_nCols, m_nRows, and m_vals.

Referenced by CIccMpeReflectanceObserver::Begin().

+ Here is the caller graph for this function:

◆ ~CIccMatrixMath()

CIccMatrixMath::~CIccMatrixMath ( )
virtual

Name: CIccMatrixMath::~CIccMatrixMath

Purpose: Destructor

140{
141 if (m_vals)
142 delete[] m_vals;
143}

References m_vals.

Member Function Documentation

◆ dumpMtx()

void CIccMatrixMath::dumpMtx ( std::string &  str) const
virtual

Name: CIccMatrixMath::dump

Purpose: dumps the context of the step

178{
179 char buf[80];
180 int i, j;
181 const icFloatNumber *row = entry(0);
182 for (j=0; j<m_nRows; j++) {
183 for (i=0; i<m_nCols; i++) {
184 sprintf(buf, ICCMTXSTEPDUMPFMT, row[i]);
185 str += buf;
186 }
187 str += "\n";
188 row = &row[m_nCols];
189 }
190}
#define ICCMTXSTEPDUMPFMT
Definition IccMatrixMath.h:83

References entry(), m_nCols, and m_nRows.

+ Here is the call graph for this function:

◆ entry() [1/2]

icFloatNumber * CIccMatrixMath::entry ( icUInt16Number  nRow,
icUInt16Number  nCol = 0 
)
inline

◆ entry() [2/2]

const icFloatNumber * CIccMatrixMath::entry ( icUInt16Number  nRow,
icUInt16Number  nCol = 0 
) const
inline
112{ return &m_vals[(int)nRow*m_nCols + nCol]; }

References m_nCols, and m_vals.

Referenced by dumpMtx(), isIdentityMtx(), Mult(), RowSum(), and VectorMult().

+ Here is the caller graph for this function:

◆ GetCols()

virtual icUInt16Number CIccMatrixMath::GetCols ( ) const
inlinevirtual
101{ return m_nCols; }

References m_nCols.

◆ GetRows()

virtual icUInt16Number CIccMatrixMath::GetRows ( ) const
inlinevirtual
102{ return m_nRows; }

References m_nRows.

◆ Invert()

bool CIccMatrixMath::Invert ( )

Name: CIccMatrixMath::Invert

Purpose: Inverts the matrix

277{
278 if (m_nRows==3 && m_nCols==3) {
280 return true;
281 }
282
283 return false;
284}
ICCPROFLIB_API bool icMatrixInvert3x3(icFloatNumber *matrix)
Definition IccUtil.cpp:391

References icMatrixInvert3x3(), m_nCols, m_nRows, and m_vals.

Referenced by CIccMpeInvEmissionMatrix::Begin().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isIdentityMtx()

bool CIccMatrixMath::isIdentityMtx ( ) const
virtual

Name: CIccMatrixMath::isIdentityMtx

Purpose: Determines if applying this step will result in negligible change in data

321{
322 if (m_nCols!=m_nRows)
323 return false;
324
325 int i, j;
326 for (j=0; j<m_nRows; j++) {
327 for (i=0; i<m_nCols; i++) {
328 icFloatNumber v = *(entry(j, i));
329 if (i==j) {
330 if (v<1.0f-icNearRange || v>1.0f+icNearRange)
331 return false;
332 }
333 else {
334 if (v<-icNearRange ||v>icNearRange)
335 return false;
336 }
337 }
338 }
339
340 return true;
341}
#define icNearRange
Definition IccMatrixMath.h:82

References entry(), m_nCols, and m_nRows.

+ Here is the call graph for this function:

◆ Mult()

CIccMatrixMath * CIccMatrixMath::Mult ( const CIccMatrixMath matrix) const

Name: CIccMatrixMath::Mult

Purpose: Creates a new CIccMatrixMath that is the result of concatentating another matrix with this matrix. (IE result = matrix * this).

203{
204 icUInt16Number mCols = matrix->m_nCols;
205 icUInt16Number mRows = matrix->m_nRows;
206
207 if (m_nRows != mCols)
208 return NULL;
209
210 CIccMatrixMath *pNew = new CIccMatrixMath(mRows, m_nCols);
211
212 int i, j, k;
213 for (j=0; j<mRows; j++) {
214 const icFloatNumber *row = matrix->entry(j);
215 for (i=0; i<m_nCols; i++) {
216 icFloatNumber *to = pNew->entry(j, i);
217 const icFloatNumber *from = entry(0, i);
218
219 *to = 0.0f;
220 for (k=0; k<m_nRows; k++) {
221 *to += row[k] * (*from);
222 from += m_nCols;
223 }
224 }
225 }
226
227 return pNew;
228}
unsigned short icUInt16Number
Definition icProfileHeader.h:256
Definition IccMatrixMath.h:94

References CIccMatrixMath(), entry(), entry(), m_nCols, and m_nRows.

Referenced by CIccMpeReflectanceCLUT::Begin(), CIccMpeReflectanceObserver::Begin(), and IIccProfileConnectionConditions::getReflectanceObserver().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rangeMap()

CIccMatrixMath * CIccMatrixMath::rangeMap ( const icSpectralRange srcRange,
const icSpectralRange dstRange 
)
static

Name: CIccMatrixMath::rangeMap

Purpose: This helper function generates a matrix math object that can be used to convert spectral vectors from one spectral range to another using linear interpolation.

410{
411 if (srcRange.steps != dstRange.steps ||
412 srcRange.start != dstRange.start ||
413 srcRange.end != dstRange.end) {
414 CIccMatrixMath *mtx = new CIccMatrixMath(dstRange.steps, srcRange.steps);
415 mtx->SetRange(srcRange, dstRange);
416
417 return mtx;
418 }
419
420 return NULL;
421}
icUInt16Number steps
Definition icProfileHeader.h:1469
icFloat16Number start
Definition icProfileHeader.h:1467
icFloat16Number end
Definition icProfileHeader.h:1468
bool SetRange(const icSpectralRange &from, const icSpectralRange &to)
Definition IccMatrixMath.cpp:353

References CIccMatrixMath(), icSpectralRange::end, SetRange(), icSpectralRange::start, and icSpectralRange::steps.

Referenced by CIccTagSpectralViewingConditions::applyRangeToObserver(), CIccMpeReflectanceCLUT::Begin(), CIccMpeReflectanceObserver::Begin(), IIccProfileConnectionConditions::getEmissiveObserver(), IIccProfileConnectionConditions::getObserverIlluminantScaleFactor(), IIccProfileConnectionConditions::getObserverWhiteScaleFactor(), and IIccProfileConnectionConditions::getReflectanceObserver().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RowSum()

icFloatNumber CIccMatrixMath::RowSum ( icUInt16Number  nRow) const

Name: CIccMatrixMath::RowSum

Purpose: Creates a new CIccMatrixMath step that is the result of multiplying the matrix of this object to the scale of another object.

298{
299 icFloatNumber rv=0;
300 int i;
301 const icFloatNumber *row = entry(nRow);
302
303 for (i=0; i<m_nCols; i++) {
304 rv += row[i];
305 }
306
307 return rv;
308}

References entry(), and m_nCols.

Referenced by IIccProfileConnectionConditions::getReflectanceObserver().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Scale()

void CIccMatrixMath::Scale ( icFloatNumber  v)

Name: CIccMatrixMath::Scale

Purpose: Multiplies all values in matrix by a single scale factor

258{
259 int i, j;
260 for (j=0; j<m_nRows; j++) {
261 icFloatNumber *row = entry(j);
262 for (i=0; i<m_nCols; i++) {
263 row[i] *= v;
264 }
265 }
266}

References entry(), m_nCols, and m_nRows.

Referenced by IIccProfileConnectionConditions::getReflectanceObserver().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetRange()

bool CIccMatrixMath::SetRange ( const icSpectralRange srcRange,
const icSpectralRange dstRange 
)

Name: CIccMatrixMath::SetRange

Purpose: Fills a matrix math object that can be used to convert spectral vectors from one spectral range to another using linear interpolation.

354{
355 if (m_nRows != dstRange.steps || m_nCols != srcRange.steps)
356 return false;
357
359 icFloatNumber srcStart = icF16toF(srcRange.start);
360 icFloatNumber srcEnd = icF16toF(srcRange.end);
361 icFloatNumber dstStart = icF16toF(dstRange.start);
362 icFloatNumber dstEnd = icF16toF(dstRange.end);
363 icFloatNumber srcDiff = srcEnd - srcStart;
364 icFloatNumber dstDiff = dstEnd - dstStart;
365 icFloatNumber srcScale = (srcEnd - srcStart) / (srcRange.steps-1);
366 icFloatNumber dstScale = (dstEnd - dstStart ) / (dstRange.steps - 1);
367
368 icFloatNumber *data=entry(0);
369 memset(data, 0, dstRange.steps*srcRange.steps*sizeof(icFloatNumber));
370
371 for (d=0; d<dstRange.steps; d++) {
372 icFloatNumber *r = entry(d);
373 icFloatNumber w = dstStart + (icFloatNumber)d * dstScale;
374 if (w<srcStart) {
375 r[0] = 1.0;
376 }
377 else if (w>=srcEnd) {
378 r[srcRange.steps-1] = 1.0;
379 }
380 else {
381 icUInt16Number p = (icUInt16Number)((w - srcStart) / srcScale);
382 icFloatNumber p2 = (w - (srcStart + p * srcScale)) / srcScale;
383
384 if (p2<0.00001) {
385 r[p] = 1.0f;
386 }
387 else if (p2>0.99999) {
388 r[p+1] = 1.0f;
389 }
390 else {
391 r[p] = 1.0f - p2;
392 r[p+1] = p2;
393 }
394 }
395 }
396
397 return true;
398}
ICCPROFLIB_API icFloat32Number icF16toF(icFloat16Number num)
Definition IccUtil.cpp:629

References icSpectralRange::end, entry(), icF16toF(), m_nCols, m_nRows, icSpectralRange::start, and icSpectralRange::steps.

Referenced by rangeMap().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ VectorMult()

void CIccMatrixMath::VectorMult ( icFloatNumber pDst,
const icFloatNumber pSrc 
) const
virtual

Name: CIccMatrixMath::VectorMult

Purpose: Multiplies pSrc vector passed by a matrix resulting in a pDst vector

155{
156 int i, j;
157 const icFloatNumber *row = entry(0);
158 for (j=0; j<m_nRows; j++) {
159 pDst[j] = 0.0f;
160 for (i=0; i<m_nCols; i++) {
161 if (row[i]!=0.0)
162 pDst[j] += row[i] * pSrc[i];
163 }
164 row = &row[m_nCols];
165 }
166}

References entry(), m_nCols, and m_nRows.

Referenced by CIccMpeEmissionMatrix::Apply(), CIccMpeInvEmissionMatrix::Apply(), CIccMpeSpectralObserver::Apply(), CIccTagSpectralViewingConditions::applyRangeToObserver(), CIccMpeEmissionMatrix::Begin(), CIccMpeInvEmissionMatrix::Begin(), CIccMpeEmissionCLUT::Begin(), CIccMpeReflectanceCLUT::Begin(), CIccMpeEmissionObserver::Begin(), CIccMpeReflectanceObserver::Begin(), IIccProfileConnectionConditions::getEmissiveObserver(), IIccProfileConnectionConditions::getObserverIlluminantScaleFactor(), CIccTagSpectralViewingConditions::getObserverMatrix(), and IIccProfileConnectionConditions::getObserverWhiteScaleFactor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ VectorScale()

void CIccMatrixMath::VectorScale ( const icFloatNumber vec)

Name: CIccMatrixMath::VectorScale

Purpose: Multiplies each row by values of vector passed in

239{
240 int i, j;
241 for (j=0; j<m_nRows; j++) {
242 icFloatNumber *row = entry(j);
243 for (i=0; i<m_nCols; i++) {
244 row[i] *= vec[i];
245 }
246 }
247}

References entry(), m_nCols, and m_nRows.

Referenced by IIccProfileConnectionConditions::getReflectanceObserver().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ m_nCols

◆ m_nRows

◆ m_vals

icFloatNumber* CIccMatrixMath::m_vals
protected

The documentation for this class was generated from the following files: