BlosSOM
Interactive dimensionality reduction on large datasets (EmbedSOM and FLOWER combined)
landmark_model.h
Go to the documentation of this file.
1/* This file is part of BlosSOM.
2 *
3 * Copyright (C) 2021 Mirek Kratochvil
4 * Sona Molnarova
5 *
6 * BlosSOM is free software: you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 3 of the License, or (at your option)
9 * any later version.
10 *
11 * BlosSOM is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 * details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * BlosSOM. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef GRAPH_MODEL_H
21#define GRAPH_MODEL_H
22
23#include <glm/glm.hpp>
24
25#include <vector>
26
27#include "dirty.h"
28
29/**
30 * @brief Model of the high- and low-dimensional landmarks.
31 *
32 */
33struct LandmarkModel : public Dirt
34{
35 /** Dimension size. */
36 size_t d;
37 /** One-dimensional array storing d-dimensional landmark coordinates in
38 * row-major order. */
39 std::vector<float> hidim_vertices;
40 /** Array storing two-dimensional landmark coordinates. */
41 std::vector<glm::vec2> lodim_vertices;
42
43 /** Lengths of all edges.
44 *
45 * The ID of the edge is the index of the array and corresponds to @ref
46 * edges indices. */
47 std::vector<float> edge_lengths;
48 /** Array of vertex ID pairs.
49 *
50 * The ID of the edge is the index of the array and corresponds to @ref
51 * edge_lengths indices.
52 *
53 * \warning constraint: first vertex ID < second vertex ID
54 */
55 std::vector<std::pair<size_t, size_t>> edges; // constraint: first<second
56
57 /**
58 * @brief Creates empty landmarks with dimension 0.
59 *
60 */
62 /**
63 * @brief Updates current dimension and calls @ref init_grid().
64 *
65 * @param dim
66 */
67 void update_dim(size_t dim);
68 /**
69 * @brief Creates squared landmarks layout, without edges.
70 *
71 * It will create \p side * \p side two-dimensional landmarks and
72 * \p side * \p side * @ref LandmarkModel::d high-dimensional landmarks.
73 *
74 * @param side Side of the square.
75 */
76 void init_grid(size_t side);
77
78 /**
79 * @brief Sets two-dimensional position of the pressed landmark to mouse
80 * position.
81 *
82 * @param ind Index of the pressed landmark.
83 * @param mouse_pos Mouse screen position.
84 */
85 void move(size_t ind, const glm::vec2 &mouse_pos);
86 /**
87 * @brief Creates new landmark with the same two- and high-dimensional
88 * coordinates as the given landmark.
89 *
90 * @param ind Index of the landmark which will be duplicated.
91 */
92 void duplicate(size_t ind);
93 /**
94 * @brief Creates new landmark with the two- and high-dimensional
95 * coordinates as the closeset landmark.
96 *
97 * @param mouse_pos Mouse screen position.
98 */
99 void add(const glm::vec2 &mouse_pos);
100 /**
101 * @brief Removes landmark and corresponding edges.
102 *
103 * @param ind Index of the removed landmark.
104 */
105 void remove(size_t ind);
106
107 /**
108 * @brief Counts closest landmark to the given position.
109 *
110 * @param mouse_pos Mouse screen position.
111 * @return size_t Index of the closest landmark.
112 */
113 size_t closest_landmark(const glm::vec2 &mouse_pos) const;
114
115 /**
116 * @brief Reurns number of the 2D landmarks.
117 *
118 * @return size_t Number of the 2D landmarks.
119 */
120 size_t n_landmarks() const { return lodim_vertices.size(); }
121};
122
123#endif
A piece of dirt for dirtying the caches.
Definition: dirty.h:32
Model of the high- and low-dimensional landmarks.
size_t n_landmarks() const
Reurns number of the 2D landmarks.
void duplicate(size_t ind)
Creates new landmark with the same two- and high-dimensional coordinates as the given landmark.
void move(size_t ind, const glm::vec2 &mouse_pos)
Sets two-dimensional position of the pressed landmark to mouse position.
void add(const glm::vec2 &mouse_pos)
Creates new landmark with the two- and high-dimensional coordinates as the closeset landmark.
std::vector< glm::vec2 > lodim_vertices
Array storing two-dimensional landmark coordinates.
std::vector< float > hidim_vertices
One-dimensional array storing d-dimensional landmark coordinates in row-major order.
std::vector< float > edge_lengths
Lengths of all edges.
size_t d
Dimension size.
size_t closest_landmark(const glm::vec2 &mouse_pos) const
Counts closest landmark to the given position.
LandmarkModel()
Creates empty landmarks with dimension 0.
void update_dim(size_t dim)
Updates current dimension and calls init_grid().
void remove(size_t ind)
Removes landmark and corresponding edges.
void init_grid(size_t side)
Creates squared landmarks layout, without edges.
std::vector< std::pair< size_t, size_t > > edges
Array of vertex ID pairs.