Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
catchImagePoint.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 
47 #include <catch_amalgamated.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;
122  session.applyCommandLine(argc, argv);
123  int numFailed = session.run();
124  std::cout << (numFailed ? "Test failed" : "Test succeed") << std::endl;
125  return numFailed;
126 }
127 
128 #else
129 int main()
130 {
131  vpImagePoint ip1, ip2, ip3;
132 
133  ip1.set_u(-11.1);
134  ip1.set_v(10);
135 
136  ip2.set_j(-11.1);
137  ip2.set_i(10);
138 
139  ip3.set_j(11.10001);
140  ip3.set_i(10.1);
141 
142  std::cout << "We define ip1 with coordinates: " << ip1 << std::endl;
143 
144  std::cout << "We define ip2 with coordinates: " << ip2 << std::endl;
145 
146  std::cout << "We define ip3 with coordinates: " << ip3 << std::endl;
147 
148  if (ip1 == ip2) {
149  std::cout << "ip1 == ip2" << std::endl;
150  }
151  else {
152  std::cout << "ip1 != ip2 (bad result)" << std::endl;
153  return EXIT_FAILURE;
154  }
155 
156  if (ip1 != ip2) {
157  std::cout << "ip1 != ip2 (bad result)" << std::endl;
158  return EXIT_FAILURE;
159  }
160  else {
161  std::cout << "ip1 == ip2" << std::endl;
162  }
163 
164  if (ip1 == ip3) {
165  std::cout << "ip1 == ip3 (bad result)" << std::endl;
166  return EXIT_FAILURE;
167  }
168  else {
169  std::cout << "ip1 != ip3" << std::endl;
170  }
171 
172  if (ip1 != ip3) {
173  std::cout << "ip1 != ip3" << std::endl;
174  }
175  else {
176  std::cout << "ip1 == ip3 (bad result)" << std::endl;
177  return EXIT_FAILURE;
178  }
179 
180  return EXIT_SUCCESS;
181 }
182 #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