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