xc
TriangleMap.h
1 // -*-c++-*-
2 //----------------------------------------------------------------------------
3 // xc utils library; general purpose classes and functions.
4 //
5 // Copyright (C) Luis C. Pérez Tato
6 //
7 // XC utils is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This software is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program.
19 // If not, see <http://www.gnu.org/licenses/>.
20 //----------------------------------------------------------------------------
21 //TriangleMap.h
22 
23 #ifndef TRIANGLE_MAP_H
24 #define TRIANGLE_MAP_H
25 
26 
27 #include <cstdlib>
28 #include <cstring>
29 #include <getopt.h>
30 #include <unistd.h>
31 #include "gts.h"
32 #include "utility/gnu_gts/GTSVertex.h"
33 #include "utility/gnu_gts/GTSFace.h"
34 #include "utility/gnu_gts/GTSSurface.h"
35 #include "utility/geom/pos_vec/Pos3d.h"
36 #include "utility/geom/pos_vec/KDTreePos.h"
38 #include <iostream>
39 #include <map>
40 
41 Pos3d Vertex2Pos3d(const GtsVertex &v);
42 
44 //
46 class VertexPos: public KDTreePos
47  {
48  private:
49  int index;
50  public:
51  VertexPos(const int &i, const Pos3d &);
52  explicit VertexPos(const Pos3d &p);
53  inline const int &getIndex(void) const
54  { return index; }
55  static inline double tac( VertexPos p, size_t k ) { return p[k]; }
56  };
57 
58 inline bool operator==(const VertexPos &A,const VertexPos &B)
59  { return ((A.getIndex()== B.getIndex()) && (A[0] == B[0]) && (A[1] == B[1]) && (A[2] == B[2])); }
60 
61 class VerticesKDTree: protected kd_tree::KDTree<3, VertexPos, std::pointer_to_binary_function<VertexPos,size_t,double> >
62  {
63  size_t pend_optimizar;
64  public:
66  VerticesKDTree(void);
67 
68  void insert(const int &,const Pos3d &);
69  //void erase(const VertexPos &);
70  void clear(void);
71 
72  int getNearest(const Pos3d &pos) const;
73  int getNearestBallPoint(const Pos3d &pos, const double &r) const;
74  };
75 
76 class VerticesMap: public std::map<size_t,Pos3d>
77  {
78 
79  static bool chequea_vertice(GtsVertex *v);
80 
81  friend class TriangleMap;
82 
83  public:
84  void insert(GtsVertex *v);
85  void insert(const size_t &i,const Pos3d &p);
86  void Print(std::ostream &os) const;
87  void Borra(void);
88  };
89 
90 std::ostream &operator<<(std::ostream &os, const VerticesMap &mv);
91 
93 //Almacena tres indices que resultan de convertir
94 //los punteros a los vértices en enteros
95  {
96  size_t v1,v2,v3;
97 
98  bool chequea_edges(GtsTriangle *t);
99 
100  public:
102  TriangleVerticesIndexes(const size_t &,const size_t &,const size_t &);
103  TriangleVerticesIndexes(GtsTriangle *t);
104  inline const size_t &V1(void) const
105  { return v1; }
106  inline const size_t &V2(void) const
107  { return v2; }
108  inline const size_t &V3(void) const
109  { return v3; }
110  inline size_t &V1(void)
111  { return v1; }
112  inline size_t &V2(void)
113  { return v2; }
114  inline size_t &V3(void)
115  { return v3; }
116  inline bool operator==(const TriangleVerticesIndexes &other) const
117  { return (v1==other.v1) && (v2==other.v2) && (v3==other.v3); }
118  void Print(std::ostream &os) const;
119  };
120 
121 
122 std::ostream &operator<<(std::ostream &os, const TriangleVerticesIndexes &ivc);
123 
124 class TriangleFaces: public std::deque<TriangleVerticesIndexes>
125  {
126  public:
127  void Append(const size_t &,const size_t &,const size_t &);
128  void Print(std::ostream &os) const;
129  };
130 
132  {
133  VerticesMap mv;
134  TriangleFaces faces;
135  public:
136  inline const VerticesMap &getVertices(void) const
137  { return mv; }
138  inline VerticesMap &getVertices(void)
139  { return mv; }
140  inline const TriangleFaces &getFaces(void) const
141  { return faces; }
142  inline TriangleFaces &getFaces(void)
143  { return faces; }
144 
145  void insertVertex(GtsVertex *v);
146  void AppendFace(GtsTriangle *t);
147  void Renumera(void);
148  void Print(std::ostream &os) const;
149  };
150 
151 
152 std::ostream &operator<<(std::ostream &os, const TriangleMap &mt);
153 
154 TriangleMap getTriangleMap(const GTSSurface &sf);
155 
156 #endif
Vertex position wrapper for KDTree.
Definition: TriangleMap.h:46
Definition: TriangleMap.h:124
VertexPos(const int &i, const Pos3d &)
Constructor.
Definition: TriangleMap.cc:29
Defines the interface for the KDTree class.
Definition: TriangleMap.h:76
Definition: kdtree.hpp:99
Definition: TriangleMap.h:131
Definition: GTSSurface.h:38
Posición en tres dimensiones.
Definition: Pos3d.h:44
Definition: TriangleMap.h:92
Definition: TriangleMap.h:61
Base class for KDTree positions.
Definition: KDTreePos.h:31