Visual Servoing Platform  version 3.6.1 under development (2024-07-27)
testImagePoint.cpp
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See https://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Test for vpImagePoint class.
32  */
40 #include <iostream>
41 
42 #include <visp3/core/vpConfig.h>
43 #include <visp3/core/vpImagePoint.h>
44 
45 #if defined(VISP_HAVE_CATCH2)
46 #define CATCH_CONFIG_RUNNER
47 #include <catch.hpp>
48 
49 #ifdef ENABLE_VISP_NAMESPACE
50 using namespace VISP_NAMESPACE_NAME;
51 #endif
52 TEST_CASE("Test comparison operator", "[operator]")
53 {
54  vpImagePoint ip1, ip2, ip3;
55 
56  ip1.set_u(-11.1);
57  ip1.set_v(10);
58 
59  ip2.set_j(-11.1);
60  ip2.set_i(10);
61 
62  ip3.set_j(11.10001);
63  ip3.set_i(10.1);
64  CHECK(ip1 == ip2);
65  CHECK_FALSE(ip1 != ip2);
66  CHECK_FALSE(ip1 == ip3);
67  CHECK(ip1 != ip3);
68 }
69 
70 TEST_CASE("Test pixel belongs to segment", "[operator]")
71 {
72  vpImagePoint start_pixel(10, 10);
73  SECTION("Segment horizontal right")
74  {
75  vpImagePoint end_pixel = start_pixel + vpImagePoint(0, 5);
76  auto j = start_pixel.get_j();
77  for (auto curr_pixel = start_pixel; curr_pixel.inSegment(start_pixel, end_pixel);
78  curr_pixel = curr_pixel.nextInSegment(start_pixel, end_pixel), j++) {
79  CHECK(curr_pixel == vpImagePoint(start_pixel.get_i(), j));
80  if (curr_pixel == end_pixel)
81  break;
82  }
83  }
84  SECTION("Segment horizontal left")
85  {
86  vpImagePoint end_pixel = start_pixel - vpImagePoint(0, 5);
87  auto j = start_pixel.get_j();
88  for (auto curr_pixel = start_pixel; curr_pixel.inSegment(start_pixel, end_pixel);
89  curr_pixel = curr_pixel.nextInSegment(start_pixel, end_pixel), j--) {
90  CHECK(curr_pixel == vpImagePoint(start_pixel.get_i(), j));
91  if (curr_pixel == end_pixel)
92  break;
93  }
94  }
95  SECTION("Segment vertical bottom")
96  {
97  vpImagePoint end_pixel = start_pixel + vpImagePoint(5, 0);
98  auto i = start_pixel.get_i();
99  for (auto curr_pixel = start_pixel; curr_pixel.inSegment(start_pixel, end_pixel);
100  curr_pixel = curr_pixel.nextInSegment(start_pixel, end_pixel), i++) {
101  CHECK(curr_pixel == vpImagePoint(i, start_pixel.get_j()));
102  if (curr_pixel == end_pixel)
103  break;
104  }
105  }
106  SECTION("Segment vertical top")
107  {
108  vpImagePoint end_pixel = start_pixel - vpImagePoint(5, 0);
109  auto i = start_pixel.get_i();
110  for (auto curr_pixel = start_pixel; curr_pixel.inSegment(start_pixel, end_pixel);
111  curr_pixel = curr_pixel.nextInSegment(start_pixel, end_pixel), i--) {
112  CHECK(curr_pixel == vpImagePoint(i, start_pixel.get_j()));
113  if (curr_pixel == end_pixel)
114  break;
115  }
116  }
117 }
118 
119 int main(int argc, char *argv[])
120 {
121  Catch::Session session; // There must be exactly one instance
122 
123  // Let Catch (using Clara) parse the command line
124  session.applyCommandLine(argc, argv);
125 
126  int numFailed = session.run();
127 
128  // numFailed is clamped to 255 as some unices only use the lower 8 bits.
129  // This clamping has already been applied, so just return it here
130  // You can also do any post run clean-up here
131  return numFailed;
132 }
133 
134 #else
135 int main()
136 {
137  vpImagePoint ip1, ip2, ip3;
138 
139  ip1.set_u(-11.1);
140  ip1.set_v(10);
141 
142  ip2.set_j(-11.1);
143  ip2.set_i(10);
144 
145  ip3.set_j(11.10001);
146  ip3.set_i(10.1);
147 
148  std::cout << "We define ip1 with coordinates: " << ip1 << std::endl;
149 
150  std::cout << "We define ip2 with coordinates: " << ip2 << std::endl;
151 
152  std::cout << "We define ip3 with coordinates: " << ip3 << std::endl;
153 
154  if (ip1 == ip2) {
155  std::cout << "ip1 == ip2" << std::endl;
156  }
157  else {
158  std::cout << "ip1 != ip2 (bad result)" << std::endl;
159  return EXIT_FAILURE;
160  }
161 
162  if (ip1 != ip2) {
163  std::cout << "ip1 != ip2 (bad result)" << std::endl;
164  return EXIT_FAILURE;
165  }
166  else {
167  std::cout << "ip1 == ip2" << std::endl;
168  }
169 
170  if (ip1 == ip3) {
171  std::cout << "ip1 == ip3 (bad result)" << std::endl;
172  return EXIT_FAILURE;
173  }
174  else {
175  std::cout << "ip1 != ip3" << std::endl;
176  }
177 
178  if (ip1 != ip3) {
179  std::cout << "ip1 != ip3" << std::endl;
180  }
181  else {
182  std::cout << "ip1 == ip3 (bad result)" << std::endl;
183  return EXIT_FAILURE;
184  }
185 
186  return EXIT_SUCCESS;
187 }
188 #endif
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:82
void set_j(double jj)
Definition: vpImagePoint.h:309
void set_i(double ii)
Definition: vpImagePoint.h:298
void set_u(double u)
Definition: vpImagePoint.h:335
void set_v(double v)
Definition: vpImagePoint.h:346