Hoyt's FORK of DemoIccMAX 2.1.17.hoyt
Documentation for Hoyt's FORK of DemoIccMAX
Loading...
Searching...
No Matches
CIccMatrixMath Class Reference

Type: Class. More...

#include <IccMatrixMath.h>

+ Collaboration diagram for CIccMatrixMath:

Public Member Functions

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

Static Public Member Functions

static CIccMatrixMathrangeMap (const icSpectralRange &from, const icSpectralRange &to)
 Name: CIccMatrixMath::rangeMap.
 

Protected Attributes

icUInt16Number m_nCols
 
icUInt16Number m_nRows
 
icFloatNumberm_vals
 

Detailed Description

Type: Class.

Purpose: Object for performing matrix/vector math

Definition at line 93 of file IccMatrixMath.h.

Constructor & Destructor Documentation

◆ CIccMatrixMath() [1/2]

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

Name: CIccMatrixMath::CIccMatrixMath.

Purpose: Constructor

Definition at line 94 of file IccMatrixMath.cpp.

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
All floating point operations/variables in IccProfLib use the icFloatNumber data type.
Definition IccDefs.h:100
icFloatNumber * entry(icUInt16Number nRow, icUInt16Number nCol=0)
icFloatNumber * m_vals
icUInt16Number m_nCols
icUInt16Number m_nRows

◆ CIccMatrixMath() [2/2]

CIccMatrixMath::CIccMatrixMath ( const CIccMatrixMath & matrix)

Name: CIccMatrixMath::CIccMatrixMath.

Purpose: Copy Constructor

Definition at line 121 of file IccMatrixMath.cpp.

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.

◆ ~CIccMatrixMath()

CIccMatrixMath::~CIccMatrixMath ( )
virtual

Name: CIccMatrixMath::~CIccMatrixMath.

Purpose: Destructor

Definition at line 139 of file IccMatrixMath.cpp.

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

Member Function Documentation

◆ dumpMtx()

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

Name: CIccMatrixMath::dump.

Purpose: dumps the context of the step

Definition at line 177 of file IccMatrixMath.cpp.

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

References ICCMTXSTEPDUMPFMT.

◆ entry() [1/2]

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

Definition at line 111 of file IccMatrixMath.h.

111{ return &m_vals[(int)nRow*m_nCols + nCol]; }

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

+ Here is the caller graph for this function:

◆ entry() [2/2]

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

Definition at line 112 of file IccMatrixMath.h.

112{ return &m_vals[(int)nRow*m_nCols + nCol]; }

◆ GetCols()

virtual icUInt16Number CIccMatrixMath::GetCols ( ) const
inlinevirtual

Definition at line 101 of file IccMatrixMath.h.

101{ return m_nCols; }

◆ GetRows()

virtual icUInt16Number CIccMatrixMath::GetRows ( ) const
inlinevirtual

Definition at line 102 of file IccMatrixMath.h.

102{ return m_nRows; }

◆ Invert()

bool CIccMatrixMath::Invert ( )

Name: CIccMatrixMath::Invert.

Purpose: Inverts the matrix

Definition at line 276 of file IccMatrixMath.cpp.

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

References icMatrixInvert3x3().

+ Here is the call 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

Definition at line 320 of file IccMatrixMath.cpp.

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

References icNearRange.

◆ 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).

Definition at line 202 of file IccMatrixMath.cpp.

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}
Type: Class.
CIccMatrixMath(icUInt16Number nRows, icUInt16Number nCols, bool bInitIdentity=false)
Name: CIccMatrixMath::CIccMatrixMath.
unsigned short icUInt16Number

References 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.

Definition at line 409 of file IccMatrixMath.cpp.

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}
bool SetRange(const icSpectralRange &from, const icSpectralRange &to)
Name: CIccMatrixMath::SetRange.
icUInt16Number steps
icFloat16Number start
icFloat16Number end

References 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.

Definition at line 297 of file IccMatrixMath.cpp.

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}

Referenced by IIccProfileConnectionConditions::getReflectanceObserver().

+ 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

Definition at line 257 of file IccMatrixMath.cpp.

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}

Referenced by IIccProfileConnectionConditions::getReflectanceObserver().

+ 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.

Definition at line 353 of file IccMatrixMath.cpp.

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}
icFloatNumber icF16toF(icFloat16Number num)
Definition IccUtil.cpp:629

References icSpectralRange::end, icF16toF(), 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

Definition at line 154 of file IccMatrixMath.cpp.

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}

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

+ 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

Definition at line 238 of file IccMatrixMath.cpp.

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}

Referenced by IIccProfileConnectionConditions::getReflectanceObserver().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_nCols

icUInt16Number CIccMatrixMath::m_nCols
protected

Definition at line 125 of file IccMatrixMath.h.

Referenced by CIccMatrixMath(), and Mult().

◆ m_nRows

icUInt16Number CIccMatrixMath::m_nRows
protected

Definition at line 125 of file IccMatrixMath.h.

Referenced by CIccMatrixMath(), and Mult().

◆ m_vals

icFloatNumber* CIccMatrixMath::m_vals
protected

Definition at line 126 of file IccMatrixMath.h.

Referenced by CIccMatrixMath().


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