BRL-CAD
brnode.h
Go to the documentation of this file.
1 /* B R N O D E . H
2  * BRL-CAD
3  *
4  * Copyright (c) 2004-2024 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @{ */
21 /** @file brep/brnode.h */
22 /** @addtogroup brep_brnode
23  *
24  * @brief
25  * Bounding Rectangle Hierarchy Node.
26  *
27  */
28 #ifndef BREP_BRNODE_H
29 #define BREP_BRNODE_H
30 
31 #include "common.h"
32 
33 #ifdef __cplusplus
34 extern "C++" {
35 /* @cond */
36 # include <vector>
37 # include <list>
38 /* @endcond */
39 }
40 #endif
41 
42 #include "brep/defines.h"
43 #include "brep/util.h"
44 
45 __BEGIN_DECLS
46 
47 #ifdef __cplusplus
48 extern "C++" {
49 namespace brlcad {
50 
51  /**
52  * Bounding Rectangle Hierarchy
53  */
54  class BREP_EXPORT BRNode : public PooledObject<BRNode> {
55  public:
56  explicit BRNode(const ON_BoundingBox &node);
57  BRNode(const ON_Curve *curve,
58  int trim_index,
59  int adj_face_index,
60  const ON_BoundingBox &node,
61  const ON_BrepFace *face,
62  const ON_Interval &t,
63  bool innerTrim,
64  bool checkTrim,
65  bool trimmed);
67 
68  BRNode(Deserializer &deserializer, const ON_Brep &brep);
69  void serialize(Serializer &serializer) const;
70 
71  /** Node management functions */
72  void addChild(BRNode *child);
73 
74  /** Return a list of all nodes below this node that are leaf nodes */
75  void getLeaves(std::list<const BRNode *> &out_leaves) const;
76 
77  /** Report the depth of this node in the hierarchy */
78  int depth() const;
79 
80  /**
81  * Get 2 points defining bounding box:
82  *
83  * @verbatim
84  * *----------------max
85  * | |
86  * v | |
87  * | |
88  * min----------------*
89  * u
90  * @endverbatim
91  */
92  void GetBBox(fastf_t *min, fastf_t *max) const;
93 
94  bool isTrimmed(const ON_2dPoint &uv, double &trimdist) const;
95 
96  ON_2dPoint getClosestPointEstimate(const ON_3dPoint &pt) const;
97  ON_2dPoint getClosestPointEstimate(const ON_3dPoint &pt, ON_Interval &u, ON_Interval &v) const;
100 
101  /** Bounding Box */
102  ON_BoundingBox m_node;
103 
104  /** Surface Information */
105  ON_Interval m_v;
106 
107  /** Trim Curve Information */
109 
110  /** Trimming Flags */
115 
116  private:
117  BRNode(const BRNode &source);
118  BRNode &operator=(const BRNode &source);
119 
120  void removeChild(BRNode *child);
121 
122  /** Test if this node is a leaf node (i.e. m_children is empty) */
123  bool isLeaf() const;
124 
125  fastf_t getLinearEstimateOfV(fastf_t u) const;
126  const BRNode *closer(const ON_3dPoint &pt, const BRNode *left, const BRNode *right) const;
127 
128  struct Stl : public PooledObject<Stl> {
129  Stl() : m_children() {}
130 
131  std::vector<const BRNode *> m_children;
132  } * const m_stl;
133 
134  const ON_BrepFace *m_face;
135  ON_Interval m_u;
136  const ON_Curve *m_trim;
137  int m_trim_index;
138  ON_Interval m_t;
139  bool m_checkTrim;
140  bool m_trimmed;
141  ON_3dPoint m_estimate;
142  fastf_t m_slope;
143  fastf_t m_bb_diag;
144  ON_3dPoint m_start;
145  ON_3dPoint m_end;
146  };
147 
148  inline void
150  {
151  if (LIKELY(child != NULL)) {
152  m_stl->m_children.push_back(child);
153  }
154  }
155 
156  inline void
157  BRNode::removeChild(BRNode *child)
158  {
159  std::vector<const BRNode *>::iterator i;
160  for (i = m_stl->m_children.begin(); i != m_stl->m_children.end();) {
161  if (*i == child) {
162  delete *i;
163  i = m_stl->m_children.erase(i);
164  } else {
165  ++i;
166  }
167  }
168  }
169 
170  inline bool
171  BRNode::isLeaf() const
172  {
173  if (m_stl->m_children.empty()) {
174  return true;
175  }
176  return false;
177  }
178 
179  inline void
181  {
182  VSETALL(min, INFINITY);
183  VSETALL(max, -INFINITY);
184  if (m_start != ON_3dPoint::UnsetPoint) {
185  VMINMAX(min, max, m_start);
186  }
187  if (m_end != ON_3dPoint::UnsetPoint) {
188  VMINMAX(min, max, m_end);
189  }
190  }
191 
192  extern bool sortX(const BRNode *first, const BRNode *second);
193  extern bool sortY(const BRNode *first, const BRNode *second);
194 
195 
196 } /* namespace brlcad */
197 } /* extern C++ */
198 
199 __END_DECLS
200 
201 #endif
202 
203 /** @} */
204 
205 #endif /* BREP_BRNODE_H */
206 
207 /*
208  * Local Variables:
209  * mode: C
210  * tab-width: 8
211  * indent-tabs-mode: t
212  * c-file-style: "stroustrup"
213  * End:
214  * ex: shiftwidth=4 tabstop=8
215  */
bool isTrimmed(const ON_2dPoint &uv, double &trimdist) const
fastf_t getCurveEstimateOfV(fastf_t u, fastf_t tol) const
bool m_XIncreasing
Definition: brnode.h:111
void addChild(BRNode *child)
Definition: brnode.h:149
void getLeaves(std::list< const BRNode * > &out_leaves) const
bool m_innerTrim
Definition: brnode.h:114
void serialize(Serializer &serializer) const
fastf_t getCurveEstimateOfU(fastf_t v, fastf_t tol) const
ON_2dPoint getClosestPointEstimate(const ON_3dPoint &pt, ON_Interval &u, ON_Interval &v) const
ON_BoundingBox m_node
Definition: brnode.h:102
int depth() const
BRNode(const ON_Curve *curve, int trim_index, int adj_face_index, const ON_BoundingBox &node, const ON_BrepFace *face, const ON_Interval &t, bool innerTrim, bool checkTrim, bool trimmed)
bool m_Horizontal
Definition: brnode.h:112
ON_Interval m_v
Definition: brnode.h:105
void GetBBox(fastf_t *min, fastf_t *max) const
Definition: brnode.h:180
bool m_Vertical
Definition: brnode.h:113
int m_adj_face_index
Definition: brnode.h:108
BRNode(Deserializer &deserializer, const ON_Brep &brep)
ON_2dPoint getClosestPointEstimate(const ON_3dPoint &pt) const
BRNode(const ON_BoundingBox &node)
Header file for the BRL-CAD common definitions.
void int char int int double * min
Definition: tig.h:182
#define LIKELY(expression)
Definition: common.h:359
#define VSETALL(v, s)
Set all elements of 3D vector to same scalar value.
Definition: vmath.h:842
#define VMINMAX(min, max, pt)
Definition: vmath.h:1780
double fastf_t
fastest 64-bit (or larger) floating point type
Definition: vmath.h:334
#define INFINITY
Definition: vmath.h:281
Definition: bbnode.h:42
bool sortX(const BRNode *first, const BRNode *second)
bool sortY(const BRNode *first, const BRNode *second)
NMG topological face.
Definition: topology.h:210