ViSP
 All Classes Functions Variables Enumerations Enumerator Friends Groups Pages
testMatrixException.cpp
1 /****************************************************************************
2  *
3  * $Id: testMatrixException.cpp 4056 2013-01-05 13:04:42Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Test matrix exceptions.
36  *
37  * Authors:
38  * Eric Marchand
39  * Fabien Spindler
40  *
41  *****************************************************************************/
42 
48 #include <visp/vpMath.h>
49 #include <visp/vpMatrix.h>
50 #include <visp/vpMatrixException.h>
51 #include <visp/vpDebug.h>
52 
53 #include <visp/vpParseArgv.h>
54 
55 #include <stdlib.h>
56 #include <stdio.h>
57 
58 // List of allowed command line options
59 #define GETOPTARGS "h"
60 
66 void usage(const char *name, const char *badparam)
67 {
68  fprintf(stdout, "\n\
69 Test some vpMatrix functionalities.\n\
70 \n\
71 SYNOPSIS\n\
72  %s [-h]\n", name);
73 
74  fprintf(stdout, "\n\
75 OPTIONS: Default\n\
76  -h\n\
77  Print the help.\n");
78 
79  if (badparam)
80  fprintf(stdout, "\nERROR: Bad parameter [%s]\n", badparam);
81 }
89 bool getOptions(int argc, const char **argv)
90 {
91  const char *optarg;
92  int c;
93  while ((c = vpParseArgv::parse(argc, argv, GETOPTARGS, &optarg)) > 1) {
94 
95  switch (c) {
96  case 'h': usage(argv[0], NULL); return false; break;
97 
98  default:
99  usage(argv[0], optarg);
100  return false; break;
101  }
102  }
103 
104  if ((c == 1) || (c == -1)) {
105  // standalone param or error
106  usage(argv[0], NULL);
107  std::cerr << "ERROR: " << std::endl;
108  std::cerr << " Bad argument " << optarg << std::endl << std::endl;
109  return false;
110  }
111 
112  return true;
113 }
114 
115 
116 int
117 main(int argc, const char ** argv)
118 {
119  // Read the command line options
120  if (getOptions(argc, argv) == false) {
121  exit (-1);
122  }
123 
124  vpMatrix M ;
125  vpMatrix M1(2,3) ;
126  vpMatrix M2(3,3) ;
127  vpMatrix M3(2,2) ;
128 
129  vpTRACE("test matrix size in multiply") ;
130 
131  try
132  {
133  M = M1*M3 ;
134  }
135  catch (vpMatrixException me)
136  {
137  vpCTRACE ;
138  std::cout << me << std::endl ;
139  }
140 
141 
142  vpTRACE("test matrix size in addition") ;
143 
144  try
145  {
146  M = M1+M3 ;
147  }
148  catch (vpMatrixException me)
149  {
150  vpCTRACE ;
151  std::cout << me << std::endl ;
152  }
153 
154 }