ViSP  2.9.0
testColvector.cpp
1 /****************************************************************************
2  *
3  * $Id: testColvector.cpp 4658 2014-02-09 09:50:14Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 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 some vpColVector functionalities.
36  *
37  * Authors:
38  * Eric Marchand
39  *
40  *****************************************************************************/
41 
48 #include <visp/vpColVector.h>
49 #include <visp/vpDebug.h>
50 #include <visp/vpParseArgv.h>
51 
52 #include <stdlib.h>
53 #include <stdio.h>
54 
55 // List of allowed command line options
56 #define GETOPTARGS "h"
57 
58 void usage(const char *name, const char *badparam);
59 bool getOptions(int argc, const char **argv);
60 
66 void usage(const char *name, const char *badparam)
67 {
68  fprintf(stdout, "\n\
69 Test some vpColVector 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  try {
120  // Read the command line options
121  if (getOptions(argc, argv) == false) {
122  exit (-1);
123  }
124 
125  vpColVector V(4) ;
126  V = 1.0;
127 
128  vpTRACE("------------------------");
129  vpTRACE("call std::cout << V;");
130  std::cout << V << std::endl;
131 
132  vpTRACE("------------------------");
133  vpTRACE("call V.normalize();");
134  V.normalize();
135 
136  vpTRACE("------------------------");
137  vpTRACE("call std::cout << V;");
138  std::cout << V << std::endl;
139  return (0);
140  }
141  catch(vpException e) {
142  std::cout << "Catch an exception: " << e << std::endl;
143  return (1);
144  }
145 }
#define vpTRACE
Definition: vpDebug.h:418
error that can be emited by ViSP classes.
Definition: vpException.h:76
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Definition: vpParseArgv.cpp:79
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72