libcootapi
 
Loading...
Searching...
No Matches
g_triangle.hh
1/*
2 * coot-utils/g_triangle.hh
3 *
4 * Copyright 2022 by Medical Research Council
5 * Author: Paul Emsley
6 *
7 * This file is part of Coot
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published
11 * by the Free Software Foundation; either version 3 of the License, or (at
12 * your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copies of the GNU General Public License and
20 * the GNU Lesser General Public License along with this program; if not,
21 * write to the Free Software Foundation, Inc., 51 Franklin Street,
22 * Fifth Floor, Boston, MA, 02110-1301, USA.
23 * See http://www.gnu.org/licenses/
24 *
25 */
26
27#ifndef COOT_UTILS_G_TRIANGLE_HH
28#define COOT_UTILS_G_TRIANGLE_HH
29
30#include <ostream>
31
34public:
36 g_triangle(const unsigned int &a0,
37 const unsigned int &a1,
38 const unsigned int &a2) {
39 point_id[0] = a0;
40 point_id[1] = a1;
41 point_id[2] = a2;
42 // colour_index = -1;
43 }
44 g_triangle() {} // for resize
45 unsigned int point_id[3];
47 unsigned int &operator[] (const unsigned int &i) { return point_id[i]; }
48 const unsigned int &operator[] (const unsigned int &i) const { return point_id[i]; }
50 void rebase(const unsigned int &idx_base) {
51 for (unsigned int i=0; i<3; i++) {
52 point_id[i] += idx_base;
53 }
54 }
55
57 std::swap(point_id[0], point_id[1]);
58 }
59 friend std::ostream& operator <<(std::ostream &s, const g_triangle &t);
60};
61
62std::ostream& operator <<(std::ostream &s, const g_triangle &t);
63
64
65// This is the g_triangle class that should be used for blender - and
66// recently used in webassembly.
69class g_triangle_with_colour_index : public g_triangle {
70 public:
71 int colour_index;
72 g_triangle_with_colour_index(const unsigned int &a0,
73 const unsigned int &a1,
74 const unsigned int &a2) : g_triangle(a0, a1, a2) {
75 colour_index = -1;
76 }
77};
78
79#endif // G_TRIANGLE_HH
80
g_triangle is the container for the vertices of a triangles (indexing into the vertices vector).
Definition g_triangle.hh:33
g_triangle(const unsigned int &a0, const unsigned int &a1, const unsigned int &a2)
constructor
Definition g_triangle.hh:36
void reverse_winding()
in-place reverse the winding of this triangle
Definition g_triangle.hh:56
void rebase(const unsigned int &idx_base)
use rebase() when adding more vertices and triangles into a mesh.
Definition g_triangle.hh:50
unsigned int & operator[](const unsigned int &i)
int colour_index;
Definition g_triangle.hh:47