1 /** -*- mode: c++ ; c-basic-offset: 2 -*-
2  * @file   KeypointList.cpp
3  * @author Sebastien Fourey
4  * @date   June 2018
5  * @brief  Definition of the class KeypointList
6  *
7  * This file is part of the ZArt software's source code.
8  *
9  * Copyright Sebastien Fourey / GREYC Ensicaen (2010-...)
10  *
11  *                    https://foureys.users.greyc.fr/
12  *
13  * This software is a computer program whose purpose is to demonstrate
14  * the possibilities of the GMIC image processing language by offering the
15  * choice of several manipulations on a video stream acquired from a webcam. In
16  * other words, ZArt is a GUI for G'MIC real-time manipulations on the output
17  * of a webcam.
18  *
19  * This software is governed by the CeCILL  license under French law and
20  * abiding by the rules of distribution of free software.  You can  use,
21  * modify and/ or redistribute the software under the terms of the CeCILL
22  * license as circulated by CEA, CNRS and INRIA at the following URL
23  * "http://www.cecill.info". See also the directory "Licence" which comes
24  * with this source code for the full text of the CeCILL license.
25  *
26  * As a counterpart to the access to the source code and  rights to copy,
27  * modify and redistribute granted by the license, users are provided only
28  * with a limited warranty  and the software's author,  the holder of the
29  * economic rights,  and the successive licensors  have only  limited
30  * liability.
31  *
32  * In this respect, the user's attention is drawn to the risks associated
33  * with loading,  using,  modifying and/or developing or reproducing the
34  * software by the user in light of its specific status of free software,
35  * that may mean  that it is complicated to manipulate,  and  that  also
36  * therefore means  that it is reserved for developers  and  experienced
37  * professionals having in-depth computer knowledge. Users are therefore
38  * encouraged to load and test the software's suitability as regards their
39  * requirements in conditions enabling the security of their systems and/or
40  * data to be ensured and,  more generally, to use and operate it in the
41  * same conditions as regards security.
42  *
43  * The fact that you are presently reading this means that you have had
44  * knowledge of the CeCILL license and that you accept its terms.
45  */
46 #include "KeypointList.h"
47 #include <cmath>
48 #include <cstring>
49 
KeypointList()50 KeypointList::KeypointList() {}
51 
add(const KeypointList::Keypoint & keypoint)52 void KeypointList::add(const KeypointList::Keypoint & keypoint)
53 {
54   _keypoints.push_back(keypoint);
55 }
56 
isEmpty()57 bool KeypointList::isEmpty()
58 {
59   return _keypoints.empty();
60 }
61 
clear()62 void KeypointList::clear()
63 {
64   _keypoints.clear();
65 }
66 
position(int n) const67 QPointF KeypointList::position(int n) const
68 {
69   const Keypoint & kp = _keypoints[n];
70   return QPointF(kp.x, kp.y);
71 }
72 
color(int n) const73 QColor KeypointList::color(int n) const
74 {
75   return _keypoints[n].color;
76 }
77 
isRemovable(int n) const78 bool KeypointList::isRemovable(int n) const
79 {
80   return _keypoints[n].removable;
81 }
82 
Keypoint(float x,float y,QColor color,bool removable,float radius,bool keepOpacityWhenSelected)83 KeypointList::Keypoint::Keypoint(float x, float y, QColor color, bool removable, float radius, bool keepOpacityWhenSelected)
84     : x(x), y(y), color(color), removable(removable), radius(radius), keepOpacityWhenSelected(keepOpacityWhenSelected)
85 {
86 }
87 
Keypoint(QPointF point,QColor color,bool removable,float radius,bool keepOpacityWhenSelected)88 KeypointList::Keypoint::Keypoint(QPointF point, QColor color, bool removable, float radius, bool keepOpacityWhenSelected)
89     : x((float)point.x()), y((float)point.y()), color(color), removable(removable), radius(radius), keepOpacityWhenSelected(keepOpacityWhenSelected)
90 {
91 }
92 
Keypoint(QColor color,bool removable,float radius,bool keepOpacityWhenSelected)93 KeypointList::Keypoint::Keypoint(QColor color, bool removable, float radius, bool keepOpacityWhenSelected)
94     : color(color), removable(removable), radius(radius), keepOpacityWhenSelected(keepOpacityWhenSelected)
95 {
96   setNaN();
97 }
98 
isNaN() const99 bool KeypointList::Keypoint::isNaN() const
100 {
101   if (sizeof(float) == 4) {
102     unsigned int ix, iy;
103     std::memcpy(&ix, &x, sizeof(float));
104     std::memcpy(&iy, &y, sizeof(float));
105     return ((ix & 0x7fffffff) > 0x7f800000) || ((iy & 0x7fffffff) > 0x7f800000);
106   }
107 #ifdef isnan
108   return (isnan(x) || isnan(y));
109 #else
110   return !(x == x) || !(y == y);
111 #endif
112 }
113 
setNaN()114 KeypointList::Keypoint & KeypointList::Keypoint::setNaN()
115 {
116 #ifdef NAN
117   x = y = (float)NAN;
118 #else
119   const double nanValue = -std::sqrt(-1.0);
120   x = y = (float)nanValue;
121 #endif
122   return *this;
123 }
124