Operator Console
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
ImageTest Class Referenceabstract

An abstract class that defines an image test to be performed. More...

#include <ImageTest.h>

Inheritance diagram for ImageTest:
[legend]

Public Member Functions

 ImageTest (void)
 
virtual ~ImageTest (void)
 
virtual void ParseResults (string &results)=0
 This must be implemented by subclass. More...
 
virtual void Run ()
 Runs the test pointed to by m_imatestFunc. More...
 
virtual void Run (void *raw_pixels, int width, int height, const Config *config)
 
void GetLog (CString &dst)
 
void GetFailInfo (CString &dst)
 
void GetJSON (CString &dst)
 
void GetName (CString &name)
 
void GetSummary (CString &dst)
 
void Init (void *raw_pixels, int width, int height, const Config *config)
 
bool Passed ()
 
void SetBuffer (void *buf)
 
 ImageTest (void)
 
virtual ~ImageTest (void)
 
virtual void ParseResults (string &results)=0
 This must be implemented by subclass. More...
 
virtual void Run ()
 
virtual void Run (void *raw_pixels, int width, int height, const Config *config)
 
void GetLog (CString &dst)
 
void GetFailInfo (CString &dst)
 
void GetJSON (CString &dst)
 
void GetName (CString &name)
 
void GetSummary (CString &dst)
 
void Init (void *raw_pixels, int width, int height, const Config *config)
 
bool Passed ()
 
void SetBuffer (void *buf)
 

Static Public Member Functions

static UINT __cdecl ThreadProc (void *param)
 param must be a pointer to a ThreadControl object; param->m_data must point to an ImageTest object More...
 
static UINT __cdecl ThreadProc (void *param)
 param must be a pointer to a ThreadControl object; param->m_data must point to an ImageTest object More...
 

Public Attributes

int m_width
 
int m_height
 
int m_ncolors
 
const char * m_extension
 
const char * m_fileroot
 
const char * m_serialNumber
 
const char * m_partNumber
 
const char * m_iniFilePathName
 
const char * m_programPath
 
const char * m_name
 
long long m_elapsed
 
CString m_elapsedStr
 
Timestamp m_timestamp
 

Protected Member Functions

bool AllocateRGB ()
 
void AppendLog (CString &log)
 
void ClearLog ()
 
void ClearJSON ()
 
void ClearFailInfo ()
 
void ClearSummary ()
 
void DeleteRGB ()
 
bool GetDataNode (string &results, JSONNode &data, bool logErrors=true)
 
bool GetPassFailNode (JSONNode &data, JSONNode &passFail, bool logErrors=true)
 
void PlanesFromRGB ()
 converts from m_rawPixels to m_rgb More...
 
void GetString (JSONNode &node, const char *name, json_string &string, bool logErrors=true)
 
void InitResults ()
 
void ParseFailures (const JSONNode *data)
 
void RGBFromPlanes (UINT *rgb)
 converts from m_rgb to rgb More...
 
void SaveImage (RGBQUAD *buf, const char *filename)
 
void SetJSON (string &src)
 
void SetSummary (CString &src)
 
bool AllocateRGB ()
 
void AppendLog (CString &log)
 
void ClearLog ()
 
void ClearJSON ()
 
void ClearFailInfo ()
 
void ClearSummary ()
 
void DeleteRGB ()
 
bool GetDataNode (string &results, JSONNode &data, bool logErrors=true)
 
bool GetPassFailNode (JSONNode &data, JSONNode &passFail, bool logErrors=true)
 
void PlanesFromRGB ()
 
void GetString (JSONNode &node, const char *name, json_string &string, bool logErrors=true)
 
void InitResults ()
 
void ParseFailures (const JSONNode *data)
 
void RGBFromPlanes (UINT *rgb)
 
void SaveImage (RGBQUAD *buf, const char *filename)
 
void SetJSON (string &src)
 
void SetSummary (CString &src)
 

Protected Attributes

const void * m_rawPixels
 
unsigned char * m_rgb
 
bool m_passed
 
const TestIDm_tests
 
int m_numTests
 
Timer m_time
 
ImatestShellFunc m_imatestFunc
 
CriticalCString m_jsonResults
 the full results of the test in JSON format More...
 
CriticalCString m_summary
 the summary results of the test (these get displayed in the dialog) More...
 
CriticalCString m_failInfo
 reasons that image failed the test More...
 
CriticalCString m_log
 log message(s) More...
 

Detailed Description

An abstract class that defines an image test to be performed.

ImageTest is an abstract class that defines an image test to be performed (e.g. blemish, SFRplus). To use this class, create a subclass and implement the ParseResults() method.

Some member variables are used by more than 1 thread. To prevent these variables from being accessed simultaneously from multiple threads, they are protected by critical sections, which limit access to one thread at a time.

In theory there shouldn't be a case where both threads are trying to access the variable simultaneously, but theory is often different than the real world. The sequence of events in the threads is as follows:

The main thread signals the ImageTest thread to run its test once.

The test runs once It sets the values of the shared member variables It sends a "done" message to the main thread It waits for a signal to run again Repeat

The main thread receives the "done" message It makes copies of the shared member variables It signals the ImageTest thread to run once Repeat

In this scenario, the main thread only accesses the shared data when it has received the "done" message (i.e. after the ImageTest thread is finished using the shared data), and the ImageTest thread only accesses the shared data while the main thread is doing other things.

Constructor & Destructor Documentation

ImageTest::ImageTest ( void  )

References m_extension, m_fileroot, m_height, m_imatestFunc, m_iniFilePathName, m_name, m_partNumber, m_programPath, m_rawPixels, m_rgb, m_serialNumber, and m_width.

32 {
33  m_width = 0;
34  m_height = 0;
35  m_extension = NULL;
36  m_fileroot = NULL;
37  m_serialNumber = NULL;
38  m_partNumber = NULL;
39  m_iniFilePathName = NULL;
40  m_programPath = NULL;
41  m_rawPixels = NULL;
42  m_name = NULL;
43  m_imatestFunc = NULL;
44  m_rgb = NULL;
45 }
const char * m_partNumber
Definition: ImageTest.h:133
const char * m_fileroot
Definition: ImageTest.h:131
const char * m_serialNumber
Definition: ImageTest.h:132
int m_width
Definition: ImageTest.h:127
int m_height
Definition: ImageTest.h:128
const void * m_rawPixels
Definition: ImageTest.h:142
const char * m_programPath
Definition: ImageTest.h:135
const char * m_iniFilePathName
Definition: ImageTest.h:134
unsigned char * m_rgb
Definition: ImageTest.h:143
const char * m_extension
Definition: ImageTest.h:130
const char * m_name
Definition: ImageTest.h:136
ImatestShellFunc m_imatestFunc
Definition: ImageTest.h:148
ImageTest::~ImageTest ( void  )
virtual

References DeleteRGB().

49 {
50  DeleteRGB();
51 }
void DeleteRGB()
Definition: ImageTest.cpp:84

Here is the call graph for this function:

ImageTest::ImageTest ( void  )
virtual ImageTest::~ImageTest ( void  )
virtual

Member Function Documentation

bool ImageTest::AllocateRGB ( )
protected

References DeleteRGB(), m_height, m_ncolors, m_rgb, and m_width.

Referenced by Init().

70 {
71  //
72  // If the source data is 3-channel (i.e. rgb) in rgba format, then
73  // we will need to convert it into a planar format for MATLAB.
74  //
75  if (m_ncolors == 3)
76  {
77  DeleteRGB();
78  m_rgb = new unsigned char[m_width * m_height * 3];
79  }
80 
81  return m_rgb != NULL;
82 }
void DeleteRGB()
Definition: ImageTest.cpp:84
int m_ncolors
Definition: ImageTest.h:129
int m_width
Definition: ImageTest.h:127
int m_height
Definition: ImageTest.h:128
unsigned char * m_rgb
Definition: ImageTest.h:143

Here is the call graph for this function:

Here is the caller graph for this function:

bool ImageTest::AllocateRGB ( )
protected
void ImageTest::AppendLog ( CString &  log)
inlineprotected
109 {m_log.Append(log);}
bool Append(CString &str)
Definition: CriticalCString.cpp:87
CriticalCString m_log
log message(s)
Definition: ImageTest.h:180
void ImageTest::AppendLog ( CString &  log)
inlineprotected

Referenced by Run().

109 {m_log.Append(log);}
bool Append(CString &str)
Definition: CriticalCString.cpp:87
CriticalCString m_log
log message(s)
Definition: ImageTest.h:180

Here is the caller graph for this function:

void ImageTest::ClearFailInfo ( )
inlineprotected
112 {m_failInfo.Clear();}
void Clear()
Definition: CriticalCString.cpp:32
CriticalCString m_failInfo
reasons that image failed the test
Definition: ImageTest.h:179
void ImageTest::ClearFailInfo ( )
inlineprotected
112 {m_failInfo.Clear();}
void Clear()
Definition: CriticalCString.cpp:32
CriticalCString m_failInfo
reasons that image failed the test
Definition: ImageTest.h:179
void ImageTest::ClearJSON ( )
inlineprotected
111 {m_jsonResults.Clear();}
void Clear()
Definition: CriticalCString.cpp:32
CriticalCString m_jsonResults
the full results of the test in JSON format
Definition: ImageTest.h:177
void ImageTest::ClearJSON ( )
inlineprotected
111 {m_jsonResults.Clear();}
void Clear()
Definition: CriticalCString.cpp:32
CriticalCString m_jsonResults
the full results of the test in JSON format
Definition: ImageTest.h:177
void ImageTest::ClearLog ( )
inlineprotected
110 {m_log.Clear();}
void Clear()
Definition: CriticalCString.cpp:32
CriticalCString m_log
log message(s)
Definition: ImageTest.h:180
void ImageTest::ClearLog ( )
inlineprotected
110 {m_log.Clear();}
void Clear()
Definition: CriticalCString.cpp:32
CriticalCString m_log
log message(s)
Definition: ImageTest.h:180
void ImageTest::ClearSummary ( )
inlineprotected
113 {m_summary.Clear();}
void Clear()
Definition: CriticalCString.cpp:32
CriticalCString m_summary
the summary results of the test (these get displayed in the dialog)
Definition: ImageTest.h:178
void ImageTest::ClearSummary ( )
inlineprotected
113 {m_summary.Clear();}
void Clear()
Definition: CriticalCString.cpp:32
CriticalCString m_summary
the summary results of the test (these get displayed in the dialog)
Definition: ImageTest.h:178
void ImageTest::DeleteRGB ( )
protected

References m_rgb.

Referenced by AllocateRGB(), and ~ImageTest().

85 {
86  if (m_rgb != NULL)
87  {
88  delete [] m_rgb;
89  m_rgb = NULL;
90  }
91 }
unsigned char * m_rgb
Definition: ImageTest.h:143

Here is the caller graph for this function:

void ImageTest::DeleteRGB ( )
protected
bool ImageTest::GetDataNode ( string &  results,
JSONNode data,
bool  logErrors = true 
)
protected

References CriticalCString::Append(), Timestamp::Get(), m_log, m_timestamp, and libjson::parse().

275 {
276  bool success = false;
277  JSONNode node;
278  CString log;
279 
280  try
281  {
282  node = libjson::parse(results.c_str());
283  data = node.at(0);
284  success = true;
285  }
286  catch(...)
287  {
288  if (logErrors)
289  {
290  log.AppendFormat("%s Results have invalid format\n", (LPCTSTR)m_timestamp.Get());
291  }
292 
293  success = false;
294  }
295 
296  m_log.Append(log);
297 
298  return success;
299 }
bool Append(CString &str)
Definition: CriticalCString.cpp:87
Timestamp m_timestamp
Definition: ImageTest.h:139
Definition: JSONNode.h:132
const CString & Get()
Definition: Timestamp.cpp:32
CriticalCString m_log
log message(s)
Definition: ImageTest.h:180
static JSONNode parse(const json_string &json) json_throws(std
Definition: libjson.h:242

Here is the call graph for this function:

bool ImageTest::GetDataNode ( string &  results,
JSONNode data,
bool  logErrors = true 
)
protected
void ImageTest::GetFailInfo ( CString &  dst)
inline
97 {m_failInfo.Get(dst);}
void Get(CString &str, bool clear=false)
copy m_string into str, then optionally clear m_string
Definition: CriticalCString.cpp:40
CriticalCString m_failInfo
reasons that image failed the test
Definition: ImageTest.h:179
void ImageTest::GetFailInfo ( CString &  dst)
inline

Referenced by COperatorConsoleApp::GetResults().

97 {m_failInfo.Get(dst);}
void Get(CString &str, bool clear=false)
copy m_string into str, then optionally clear m_string
Definition: CriticalCString.cpp:40
CriticalCString m_failInfo
reasons that image failed the test
Definition: ImageTest.h:179

Here is the caller graph for this function:

void ImageTest::GetJSON ( CString &  dst)
inline
98 {m_jsonResults.Get(dst);}
void Get(CString &str, bool clear=false)
copy m_string into str, then optionally clear m_string
Definition: CriticalCString.cpp:40
CriticalCString m_jsonResults
the full results of the test in JSON format
Definition: ImageTest.h:177
void ImageTest::GetJSON ( CString &  dst)
inline

Referenced by COperatorConsoleApp::GetResults().

98 {m_jsonResults.Get(dst);}
void Get(CString &str, bool clear=false)
copy m_string into str, then optionally clear m_string
Definition: CriticalCString.cpp:40
CriticalCString m_jsonResults
the full results of the test in JSON format
Definition: ImageTest.h:177

Here is the caller graph for this function:

void ImageTest::GetLog ( CString &  dst)
inline
96 {m_log.Get(dst);}
CriticalCString m_log
log message(s)
Definition: ImageTest.h:180
void Get(CString &str, bool clear=false)
copy m_string into str, then optionally clear m_string
Definition: CriticalCString.cpp:40
void ImageTest::GetLog ( CString &  dst)
inline

Referenced by COperatorConsoleApp::GetResults().

96 {m_log.Get(dst);}
CriticalCString m_log
log message(s)
Definition: ImageTest.h:180
void Get(CString &str, bool clear=false)
copy m_string into str, then optionally clear m_string
Definition: CriticalCString.cpp:40

Here is the caller graph for this function:

void ImageTest::GetName ( CString &  name)
inline
99 {name = m_name;}
const char * m_name
Definition: ImageTest.h:136
void ImageTest::GetName ( CString &  name)
inline

Referenced by COperatorConsoleApp::GetResults().

99 {name = m_name;}
const char * m_name
Definition: ImageTest.h:136

Here is the caller graph for this function:

bool ImageTest::GetPassFailNode ( JSONNode data,
JSONNode passFail,
bool  logErrors = true 
)
protected

References CriticalCString::Append(), Timestamp::Get(), m_log, and m_timestamp.

303 {
304  bool validNode;
305  CString log;
306 
307  try
308  {
309  passFail = data.at("passfail");
310  validNode = true;
311  }
312 
313  catch(...)
314  {
315  validNode = false;
316 
317  if (logErrors)
318  {
319  log.AppendFormat("%s Couldn't find pass/fail section in results\n", (LPCTSTR)m_timestamp.Get());
320  }
321  }
322 
323  m_log.Append(log);
324 
325  return validNode;
326 }
bool Append(CString &str)
Definition: CriticalCString.cpp:87
Timestamp m_timestamp
Definition: ImageTest.h:139
const CString & Get()
Definition: Timestamp.cpp:32
CriticalCString m_log
log message(s)
Definition: ImageTest.h:180

Here is the call graph for this function:

bool ImageTest::GetPassFailNode ( JSONNode data,
JSONNode passFail,
bool  logErrors = true 
)
protected
void ImageTest::GetString ( JSONNode node,
const char *  name,
json_string &  string,
bool  logErrors = true 
)
protected

References CriticalCString::Append(), JSONNode::as_array(), JSONNode::as_string(), Timestamp::Get(), m_log, and m_timestamp.

329 {
330  try
331  {
332  string = node.at(name).as_array()[0].as_string();
333  }
334 
335  catch(...)
336  {
337  CString log;
338  log.AppendFormat("%s Couldn't find %s value\n", (LPCTSTR)m_timestamp.Get(), name);
339  m_log.Append(log);
340  }
341 }
bool Append(CString &str)
Definition: CriticalCString.cpp:87
Timestamp m_timestamp
Definition: ImageTest.h:139
const CString & Get()
Definition: Timestamp.cpp:32
JSONNode as_array(void) const json_nothrow json_read_priority
Definition: JSONNode.cpp:84
CriticalCString m_log
log message(s)
Definition: ImageTest.h:180
json_string as_string(void) const json_nothrow json_read_priority
Definition: JSONNode.h:678

Here is the call graph for this function:

void ImageTest::GetString ( JSONNode node,
const char *  name,
json_string &  string,
bool  logErrors = true 
)
protected
void ImageTest::GetSummary ( CString &  dst)
inline

Referenced by COperatorConsoleApp::GetResults().

100 {m_summary.Get(dst);}
CriticalCString m_summary
the summary results of the test (these get displayed in the dialog)
Definition: ImageTest.h:178
void Get(CString &str, bool clear=false)
copy m_string into str, then optionally clear m_string
Definition: CriticalCString.cpp:40

Here is the caller graph for this function:

void ImageTest::GetSummary ( CString &  dst)
inline
100 {m_summary.Get(dst);}
CriticalCString m_summary
the summary results of the test (these get displayed in the dialog)
Definition: ImageTest.h:178
void Get(CString &str, bool clear=false)
copy m_string into str, then optionally clear m_string
Definition: CriticalCString.cpp:40
void ImageTest::Init ( void *  raw_pixels,
int  width,
int  height,
const Config config 
)

References AllocateRGB(), height, Config::m_extension, m_extension, Config::m_fileRoot, m_fileroot, m_height, Config::m_iniFilePathName, m_iniFilePathName, Config::m_ncolors, m_ncolors, Config::m_partNumber, m_partNumber, Config::m_programPath, m_programPath, m_rawPixels, Config::m_serialNumber, m_serialNumber, m_width, and width.

Referenced by COperatorConsoleApp::InitBlemishThread(), COperatorConsoleApp::InitSFRplusThread(), and Run().

54 {
55  m_rawPixels = raw_pixels;
56  m_width = width;
57  m_height = height;
58  m_fileroot = config->m_fileRoot;
60  m_partNumber = config->m_partNumber;
61  m_extension = config->m_extension;
63  m_programPath = config->m_programPath;
64  m_ncolors = config->m_ncolors;
65 
66  AllocateRGB();
67 }
const char * m_partNumber
Definition: ImageTest.h:133
int m_ncolors
Definition: ImageTest.h:129
bool AllocateRGB()
Definition: ImageTest.cpp:69
const char * m_iniFilePathName
Fully-qualified ini file name (including full path)
Definition: Config.h:38
const char * m_programPath
Path to Imatest.
Definition: Config.h:37
const char * m_extension
RAW file extension.
Definition: Config.h:39
const char * m_fileroot
Definition: ImageTest.h:131
const char * m_serialNumber
Definition: ImageTest.h:132
int m_width
Definition: ImageTest.h:127
int m_height
Definition: ImageTest.h:128
const void * m_rawPixels
Definition: ImageTest.h:142
const char * m_programPath
Definition: ImageTest.h:135
const char * m_fileRoot
File root.
Definition: Config.h:40
const char * m_partNumber
Camera part number.
Definition: Config.h:42
const char * m_iniFilePathName
Definition: ImageTest.h:134
int m_ncolors
Definition: Config.h:43
width
Definition: calculation_checks.m:1
const char * m_extension
Definition: ImageTest.h:130
height
Definition: calculation_checks.m:2
const char * m_serialNumber
Camera serial number.
Definition: Config.h:41

Here is the call graph for this function:

Here is the caller graph for this function:

void ImageTest::Init ( void *  raw_pixels,
int  width,
int  height,
const Config config 
)
void ImageTest::InitResults ( )
protected

References CriticalCString::Clear(), m_failInfo, m_jsonResults, m_log, m_passed, and m_summary.

Referenced by Run().

427 {
429  m_summary.Clear();
430  m_failInfo.Clear();
431  m_log.Clear();
432  m_passed = false;
433 }
bool m_passed
Definition: ImageTest.h:144
void Clear()
Definition: CriticalCString.cpp:32
CriticalCString m_log
log message(s)
Definition: ImageTest.h:180
CriticalCString m_summary
the summary results of the test (these get displayed in the dialog)
Definition: ImageTest.h:178
CriticalCString m_jsonResults
the full results of the test in JSON format
Definition: ImageTest.h:177
CriticalCString m_failInfo
reasons that image failed the test
Definition: ImageTest.h:179

Here is the call graph for this function:

Here is the caller graph for this function:

void ImageTest::InitResults ( )
protected
void ImageTest::ParseFailures ( const JSONNode data)
protected

References CriticalCString::Append(), JSONNode::as_array(), JSONNode::as_bool(), FAIL_DELIMITER, m_failInfo, m_log, m_numTests, m_tests, and CriticalCString::Set().

344 {
345  CString fail;
346  CString log;
347  int i;
348  bool first = true;
349  bool passed = false;
350 
351 
352  for (i = 0; i < m_numTests; i++)
353  {
354  try
355  {
356  passed = passfail->at(m_tests[i].key).as_array()[0].as_bool();
357 
358  if (!passed)
359  {
360  if (!first)
361  {
362  fail.Append(FAIL_DELIMITER); // add a separator before adding the next test name
363  }
364 
365  fail.Append(m_tests[i].name); // add the name of the test that failed to the m_failInfo string
366  first = false;
367  }
368  }
369 
370  catch(...)
371  {
372  log.AppendFormat("Couldn't find %s in results\n", m_tests[i].key);
373  }
374  }
375 
376  m_failInfo.Set(fail);
377  m_log.Append(log);
378 }
#define FAIL_DELIMITER
Definition: ImageTest.cpp:29
bool Append(CString &str)
Definition: CriticalCString.cpp:87
int m_numTests
Definition: ImageTest.h:146
const TestID * m_tests
Definition: ImageTest.h:145
CriticalCString m_log
log message(s)
Definition: ImageTest.h:180
void Set(CString &str)
Definition: CriticalCString.cpp:52
CriticalCString m_failInfo
reasons that image failed the test
Definition: ImageTest.h:179

Here is the call graph for this function:

void ImageTest::ParseFailures ( const JSONNode data)
protected
virtual void ImageTest::ParseResults ( string &  results)
pure virtual

This must be implemented by subclass.

Implemented in SFRplusTest, SFRplusTest, BlemishTest, and BlemishTest.

Referenced by Run().

Here is the caller graph for this function:

virtual void ImageTest::ParseResults ( string &  results)
pure virtual

This must be implemented by subclass.

Implemented in SFRplusTest, SFRplusTest, BlemishTest, and BlemishTest.

bool ImageTest::Passed ( )
inline

Referenced by COperatorConsoleApp::UpdateResults().

102 {return m_passed;}
bool m_passed
Definition: ImageTest.h:144

Here is the caller graph for this function:

bool ImageTest::Passed ( )
inline
102 {return m_passed;}
bool m_passed
Definition: ImageTest.h:144
void ImageTest::PlanesFromRGB ( )
protected

converts from m_rawPixels to m_rgb

References m_height, m_rawPixels, m_rgb, and m_width.

Referenced by Run().

95 {
96  int i, numPixels;
97  unsigned char *r, *g, *b; // pointers into m_rgb
98  unsigned char *R, *G, *B; // pointers into m_rawPixels
99 
100 
101  //
102  // m_rawPixels is an array of RGBQUAD structs (32-bit ints), where each byte represents one color component (r, g, b), plus
103  // one unused byte. MATLAB stores an RGB image sequentially, with all of the red values followed by all of the green values,
104  // followed by all of the blue values. This function converts an arry of RGBQUAD values into MATLAB's color plane format.
105  //
106  numPixels = m_width * m_height;
107  r = m_rgb;
108  g = r + numPixels;
109  b = g + numPixels;
110 
111  R = (unsigned char *)m_rawPixels;
112  G = R+1;
113  B = G+1;
114 
115  // TODO, vectorize this loop?
116  for (i = 0; i < numPixels; i++)
117  {
118  *r = *R;
119  *g = *G;
120  *b = *B;
121 
122  r++;
123  g++;
124  b++;
125  R += 4;
126  G += 4;
127  B += 4;
128  }
129 }
int m_width
Definition: ImageTest.h:127
int m_height
Definition: ImageTest.h:128
const void * m_rawPixels
Definition: ImageTest.h:142
unsigned char * m_rgb
Definition: ImageTest.h:143

Here is the caller graph for this function:

void ImageTest::PlanesFromRGB ( )
protected
void ImageTest::RGBFromPlanes ( UINT *  rgb)
protected
void ImageTest::RGBFromPlanes ( UINT *  rgb)
protected

converts from m_rgb to rgb

References m_height, m_rgb, and m_width.

Referenced by Run().

133 {
134  int i, numPixels;
135  unsigned char *r, *g, *b; // pointers into m_rgb
136  unsigned char *R, *G, *B; // pointers into m_rawPixels
137 
138 
139  //
140  // rgb is an array of 32-bit ints, arranged in rgba order.
141  // MATLAB stores an RGB image sequentally, with all of the red values followed
142  // by all of the green values, followed by all of the blue values.
143  //
144  // This function converts from MATLAB's color plane format into rgb format
145  //
146  numPixels = m_width * m_height;
147  r = m_rgb;
148  g = r + numPixels;
149  b = g + numPixels;
150 
151  R = (unsigned char *)rgb;
152  G = R+1;
153  B = G+1;
154 
155  for (i = 0; i < numPixels; i++)
156  {
157  *R = *r;
158  *G = *g;
159  *B = *b;
160 
161  r++;
162  g++;
163  b++;
164  R += 4;
165  G += 4;
166  B += 4;
167  }
168 }
int m_width
Definition: ImageTest.h:127
int m_height
Definition: ImageTest.h:128
unsigned char * m_rgb
Definition: ImageTest.h:143

Here is the caller graph for this function:

void ImageTest::Run ( )
virtual

Runs the test pointed to by m_imatestFunc.

References AppendLog(), Timestamp::Get(), INI_RAW_JSON_MODE, InitResults(), m_extension, m_fileroot, m_height, m_imatestFunc, m_iniFilePathName, m_name, m_ncolors, m_partNumber, m_passed, m_programPath, m_rgb, m_serialNumber, m_timestamp, m_width, ParseResults(), PlanesFromRGB(), prepareTestSettings(), RGBFromPlanes(), SaveImage(), and SetJSON().

Referenced by Run(), and ThreadProc().

180 {
181  json_string test_settings;
182  int crop_borders[4] = {0,0,0,0};
183 
184  InitResults(); // clear out strings, set m_passed to false
185 
186 //#ifdef IMATEST_CAMERA
187 // RGBFromPlanes((UINT *)m_rawPixels);
188 //#else
189  PlanesFromRGB(); // convert m_rawPixels from rgba format to planar format for MATLAB
190 //#endif
191  // RGBFromPlanes((UINT *)m_rawPixels); // convert it back, just for fun
192 
193 #if 0
194  //
195  // Save the data as a png file
196  //
197  UINT *tmp = new UINT[m_width*m_height];
198  RGBFromPlanes(tmp);
199  SaveImage((RGBQUAD *)tmp, "image.png");
200  delete [] tmp;
201 #endif
203 
204  const char *operation_flag[] = {INI_RAW_JSON_MODE};
205  const char *file_name[] = {""};
206  const char *iniFile[] = {m_iniFilePathName};
207  const char *program_path[] = {m_programPath};
208  const char *input_keys[] = {"JSON"};
209  const char *json_options[] = {test_settings.c_str()}; // make sure to call prepareTestSettings() first
210 
211  //
212  // To create mwArrays using the constructor prototype:
213  // mwArray(mwSize num_strings, const char** str)
214  //
215  try
216  {
217  mwArray fileParam(1, file_name); // Argument 1 - File name (Not applicable for raw files)
218  mwArray pathParam(1, program_path); // Argument 2 - Program Path
219  mwArray keysParam(1, input_keys); // Argument 3 - Mode of Control
220  mwArray modeParam(1, operation_flag); // Argument 4 - Operation Flag
221  mwArray iniFileParam(1, iniFile); // Argument 5 INI file
222 // mwArray rawFileParam(m_width * m_height, 1, mxUINT16_CLASS, mxREAL); // Argument 6 - Raw Data
223  mwArray rawFileParam(m_width * m_height * 3, 1, mxUINT8_CLASS, mxREAL); // Argument 6 - RGB Data
224  mwArray json_options_param(1,json_options); // JSON options describing the RAW file;
225  mwArray vararginParam(1,3,mxCELL_CLASS); // The remaining arguments go in this param
226  mwArray out; // this will hold returned data
227 
228 #ifdef IMATEST_CAMERA
229 
230  rawFileParam.SetData(m_rgb, m_width * m_height * 3);
231  //rawFileParam.SetData((unsigned short *)m_rawPixels, m_width * m_height);
232 #else
233  rawFileParam.SetData(m_rgb, m_width * m_height * 3);
234 #endif
235  // Our remaining arguments go into the Varargin parameter
236  vararginParam.Get(1,1).Set(iniFileParam); // Path to INI file
237  vararginParam.Get(1,2).Set(rawFileParam); // data description
238  vararginParam.Get(1,3).Set(json_options_param); // options file
239 
240  //
241  // Call the Imatest IT library function
242  //
243  if (m_imatestFunc == NULL)
244  {
245  }
246  else
247  {
248  m_imatestFunc(1, out, fileParam, pathParam, keysParam, modeParam, vararginParam);
249  }
250 
251  //
252  // Copy the output of the module to a System::String object
253  //
254  stringstream ss (stringstream::in | stringstream::out);
255  ss << out;
256  string jsonResults = ss.str();
257  ParseResults(jsonResults);
258  SetJSON(jsonResults); // copy results into m_jsonResults (m_jsonResults is shared between threads, so we don't want to access it directly)
259  }
260 
261  catch (const mwException &e)
262  {
263  CString log;
264  log.AppendFormat("%s Error running %s test\n%s\n", (LPCTSTR)m_timestamp.Get(), m_name, e.what());
265  log.Replace("\n", "\r\n"); // the exception may have '\n' characters that we need to replace with "\r\n"
266  AppendLog(log);
267  m_passed = false;
268  }
269 }
void prepareTestSettings(int width, int height, int ncolors, const char *extension, const char *fileroot, const char *serial_number, const char *part_number, int crop_borders[4], json_string &test_settings)
Definition: jsonhelpers.cpp:67
const char * m_partNumber
Definition: ImageTest.h:133
void InitResults()
Definition: ImageTest.cpp:426
bool m_passed
Definition: ImageTest.h:144
int m_ncolors
Definition: ImageTest.h:129
Timestamp m_timestamp
Definition: ImageTest.h:139
void RGBFromPlanes(UINT *rgb)
converts from m_rgb to rgb
Definition: ImageTest.cpp:132
const char * m_fileroot
Definition: ImageTest.h:131
const char * m_serialNumber
Definition: ImageTest.h:132
void AppendLog(CString &log)
Definition: ImageTest.h:109
int m_width
Definition: ImageTest.h:127
const CString & Get()
Definition: Timestamp.cpp:32
int m_height
Definition: ImageTest.h:128
void SetJSON(string &src)
Definition: ImageTest.h:123
const char * m_programPath
Definition: ImageTest.h:135
void PlanesFromRGB()
converts from m_rawPixels to m_rgb
Definition: ImageTest.cpp:94
#define INI_RAW_JSON_MODE
Definition: BlemishTest.cpp:33
const char * m_iniFilePathName
Definition: ImageTest.h:134
unsigned char * m_rgb
Definition: ImageTest.h:143
virtual void ParseResults(string &results)=0
This must be implemented by subclass.
const char * m_extension
Definition: ImageTest.h:130
const char * m_name
Definition: ImageTest.h:136
void SaveImage(RGBQUAD *buf, const char *filename)
Definition: ImageTest.cpp:436
ImatestShellFunc m_imatestFunc
Definition: ImageTest.h:148

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void ImageTest::Run ( )
virtual
virtual void ImageTest::Run ( void *  raw_pixels,
int  width,
int  height,
const Config config 
)
virtual
void ImageTest::Run ( void *  raw_pixels,
int  width,
int  height,
const Config config 
)
virtual

References Init(), and Run().

171 {
172  Init(raw_pixels, width, height, config);
173  Run();
174 }
virtual void Run()
Runs the test pointed to by m_imatestFunc.
Definition: ImageTest.cpp:179
void Init(void *raw_pixels, int width, int height, const Config *config)
Definition: ImageTest.cpp:53
width
Definition: calculation_checks.m:1
height
Definition: calculation_checks.m:2

Here is the call graph for this function:

void ImageTest::SaveImage ( RGBQUAD *  buf,
const char *  filename 
)
protected

References m_height, and m_width.

Referenced by Run().

437 {
438  CImage image;
439  HDC hdc;
440  HBITMAP hbitmap;
441  BITMAPINFO info;
442 
443 
444  memset(&info, 0, sizeof(info));
445  info.bmiHeader.biSize = sizeof(info.bmiHeader);
446  info.bmiHeader.biWidth = m_width;
447  info.bmiHeader.biHeight = -m_height; // a negative value means top-down instead of bottom-up
448  info.bmiHeader.biPlanes = 1;
449  info.bmiHeader.biBitCount = 32;
450  info.bmiHeader.biCompression = BI_RGB;
451  info.bmiHeader.biSizeImage = 0;
452  info.bmiHeader.biXPelsPerMeter = 1;
453  info.bmiHeader.biYPelsPerMeter = 1;
454  info.bmiHeader.biClrUsed = 0;
455  info.bmiHeader.biClrImportant = 0;
456 
457  image.Create(m_width, m_height, 32);
458  hdc = image.GetDC();
459  hbitmap = (HBITMAP)image;
460 
461  SetDIBits(hdc, hbitmap, 0, m_height, buf, &info, DIB_RGB_COLORS);
462  image.ReleaseDC();
463  image.Save(filename, Gdiplus::ImageFormatPNG);
464 }
int m_width
Definition: ImageTest.h:127
int m_height
Definition: ImageTest.h:128

Here is the caller graph for this function:

void ImageTest::SaveImage ( RGBQUAD *  buf,
const char *  filename 
)
protected
void ImageTest::SetBuffer ( void *  buf)
inline
103 {m_rawPixels = buf;}
const void * m_rawPixels
Definition: ImageTest.h:142
void ImageTest::SetBuffer ( void *  buf)
inline
103 {m_rawPixels = buf;}
const void * m_rawPixels
Definition: ImageTest.h:142
void ImageTest::SetJSON ( string &  src)
inlineprotected

Referenced by Run().

123 {m_jsonResults.Set(src);}
void Set(CString &str)
Definition: CriticalCString.cpp:52
CriticalCString m_jsonResults
the full results of the test in JSON format
Definition: ImageTest.h:177

Here is the caller graph for this function:

void ImageTest::SetJSON ( string &  src)
inlineprotected
123 {m_jsonResults.Set(src);}
void Set(CString &str)
Definition: CriticalCString.cpp:52
CriticalCString m_jsonResults
the full results of the test in JSON format
Definition: ImageTest.h:177
void ImageTest::SetSummary ( CString &  src)
inlineprotected
124 {m_summary.Set(src);}
CriticalCString m_summary
the summary results of the test (these get displayed in the dialog)
Definition: ImageTest.h:178
void Set(CString &str)
Definition: CriticalCString.cpp:52
void ImageTest::SetSummary ( CString &  src)
inlineprotected
124 {m_summary.Set(src);}
CriticalCString m_summary
the summary results of the test (these get displayed in the dialog)
Definition: ImageTest.h:178
void Set(CString &str)
Definition: CriticalCString.cpp:52
static UINT __cdecl ImageTest::ThreadProc ( void *  param)
static

param must be a pointer to a ThreadControl object; param->m_data must point to an ImageTest object

UINT __cdecl ImageTest::ThreadProc ( void *  param)
static

param must be a pointer to a ThreadControl object; param->m_data must point to an ImageTest object

References DONE_INDEX, Timer::Get(), ThreadControl::m_data, m_elapsed, m_elapsedStr, ThreadControl::m_events, ThreadControl::m_parentID, ThreadControl::m_threadMsg, m_time, NUM_THREAD_EVENTS, Run(), RUN_INDEX, Timer::Start(), and Timer::Stop().

Referenced by COperatorConsoleApp::InitBlemishThread(), and COperatorConsoleApp::InitSFRplusThread().

381 {
382  ThreadControl *info = (ThreadControl *)param;
383  ImageTest *test = (ImageTest *)info->m_data;
384  bool done = false;
385  DWORD eventIndex;
386 
387 
388  while (!done)
389  {
390  //
391  // Wait for an event to be signaled. info->m_events is an array of 2 CEvent structs.
392  // 'eventIndex' tells us which event was signaled. Once we know which event was signaled
393  // we can take the appropriate action.
394  //
395  // While we're waiting for an event, our thread blocks, allowing other threads (like the
396  // GUI handler) to run.
397  //
398  eventIndex = ::WaitForMultipleObjects(NUM_THREAD_EVENTS, info->m_events, FALSE, INFINITE); // wait for an event to be signaled
399 
400  if (eventIndex == DONE_INDEX)
401  {
402  //
403  // We get a DONE event when the program is terminating. We just exit the loop and return.
404  //
405  done = TRUE;
406  }
407  else if (eventIndex == RUN_INDEX)
408  {
409  //
410  // We get a RUN event when it's time to run the test. We send a
411  // message to the main application thread when the test is done.
412  //
413  test->m_time.Start();
414  test->Run();
415  test->m_time.Stop();
416  test->m_time.Get(&test->m_elapsedStr);
417  test->m_time.Get(&test->m_elapsed);
418  ::PostThreadMessage(info->m_parentID, info->m_threadMsg, (WPARAM)0, (LPARAM)0);
419  }
420  }
421 
422  return 0; // this terminates the thread
423 }
Thread synchronization and communication class.
Definition: ThreadControl.h:56
CString m_elapsedStr
Definition: ImageTest.h:138
void * m_data
pointer to whatever is useful
Definition: ThreadControl.h:77
HANDLE m_events[2]
Definition: ThreadControl.h:74
An abstract class that defines an image test to be performed.
Definition: ImageTest.h:86
void Get(long long *ms)
gets the elapsed time in milliseconds
Definition: Timer.cpp:71
Timer m_time
Definition: ImageTest.h:147
#define NUM_THREAD_EVENTS
Definition: ThreadControl.h:51
void Stop()
Definition: Timer.cpp:40
virtual void Run()
Runs the test pointed to by m_imatestFunc.
Definition: ImageTest.cpp:179
#define RUN_INDEX
Definition: ThreadControl.h:49
long long m_elapsed
Definition: ImageTest.h:137
#define DONE_INDEX
Definition: ThreadControl.h:50
void Start()
Definition: Timer.cpp:35
DWORD m_parentID
the thread to send the message to
Definition: ThreadControl.h:76
UINT m_threadMsg
message to send to parent thread
Definition: ThreadControl.h:75

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

long long ImageTest::m_elapsed
CString ImageTest::m_elapsedStr
const char * ImageTest::m_extension

Referenced by ImageTest(), Init(), and Run().

CriticalCString ImageTest::m_failInfo
protected

reasons that image failed the test

Referenced by InitResults(), and ParseFailures().

const char * ImageTest::m_fileroot

Referenced by ImageTest(), Init(), and Run().

int ImageTest::m_height
ImatestShellFunc ImageTest::m_imatestFunc
protected

Referenced by ImageTest(), and Run().

const char * ImageTest::m_iniFilePathName
CriticalCString ImageTest::m_jsonResults
protected

the full results of the test in JSON format

Referenced by InitResults().

CriticalCString ImageTest::m_log
protected
const char * ImageTest::m_name
int ImageTest::m_ncolors

Referenced by AllocateRGB(), Init(), and Run().

int ImageTest::m_numTests
protected

Referenced by ParseFailures().

const char * ImageTest::m_partNumber
bool ImageTest::m_passed
protected

Referenced by InitResults(), and Run().

const char * ImageTest::m_programPath
const void * ImageTest::m_rawPixels
protected

Referenced by ImageTest(), Init(), and PlanesFromRGB().

unsigned char * ImageTest::m_rgb
protected
const char * ImageTest::m_serialNumber
CriticalCString ImageTest::m_summary
protected

the summary results of the test (these get displayed in the dialog)

Referenced by InitResults().

const TestID * ImageTest::m_tests
protected

Referenced by ParseFailures().

Timer ImageTest::m_time
protected

Referenced by ThreadProc().

Timestamp ImageTest::m_timestamp
int ImageTest::m_width

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