openNURBS SDK Help
opennurbs_pointcloud.h
1 /* $NoKeywords: $ */
2 /*
3 //
4 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
5 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
6 // McNeel & Associates.
7 //
8 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
9 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
10 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
11 //
12 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
13 //
14 ////////////////////////////////////////////////////////////////
15 */
16 
17 #if !defined(OPENNURBS_POINTCLOUD_INC_)
18 #define OPENNURBS_POINTCLOUD_INC_
19 
20 ///////////////////////////////////////////////////////////////////////////////
21 //
22 // Class ON_PointCloud - unordered set of points
23 // ON_PointField - point height field
24 //
25 
26 class ON_CLASS ON_PointCloud : public ON_Geometry
27 {
28  ON_OBJECT_DECLARE(ON_PointCloud);
29 
30 public:
31  ON_PointCloud();
33  int // initial point array capacity
34  );
35  ON_PointCloud( const ON_PointCloud& );
36  ~ON_PointCloud();
38 
39  ON_3dPoint& operator[](int);
40  const ON_3dPoint& operator[](int) const;
41 
42  /*
43  Description:
44  Get a point cloud point from an ON_COMPONENT_INDEX.
45  Parameters:
46  ci - [in] a component index with m_typ set to ON_COMPONENT_INDEX::pointcloud_point
47  and 0 <= m_index and m_index < m_P.Count().
48  Returns:
49  Point at [ci.m_index] or ON_3dPoint::UnsetPoint if ci is not valid.
50  */
51  ON_3dPoint Point( ON_COMPONENT_INDEX ci ) const;
52 
53  void Destroy();
54 
55  /*
56  Description:
57  Call when the memory pool used the point cloud's arrays is
58  no longer in existence.
59  */
60  void EmergencyDestroy();
61 
62  bool IsValid( class ON_TextLog* text_log = nullptr ) const override;
63 
64  // virtual ON_Object override
65  void Dump( ON_TextLog& ) const override; // for debugging
66 
67  // virtual ON_Object override
68  bool Write( ON_BinaryArchive& ) const override;
69 
70  // virtual ON_Object override
71  bool Read( ON_BinaryArchive& ) override;
72 
73  // virtual ON_Object override
74  ON::object_type ObjectType() const override;
75 
76  // virtual ON_Geometry override
77  int Dimension() const override;
78 
79  // virtual ON_Geometry GetBBox override
80  bool GetBBox( double* boxmin, double* boxmax, bool bGrowBox = false ) const override;
81 
82  // virtual ON_Geometry GetTightBoundingBox override
83  bool GetTightBoundingBox( class ON_BoundingBox& tight_bbox, bool bGrowBox = false, const class ON_Xform* xform = nullptr ) const override;
84 
85  // virtual ON_Geometry override
86  bool Transform(
87  const ON_Xform&
88  ) override;
89 
90  // virtual ON_Geometry override
91  bool IsDeformable() const override;
92 
93  // virtual ON_Geometry override
94  bool MakeDeformable() override;
95 
96  // virtual ON_Geometry override
97  bool SwapCoordinates(
98  int, int // indices of coords to swap
99  ) override;
100 
101 
102  /*
103  Description:
104  Get the index of the point in the point cloud that is closest
105  to P.
106  Parameters:
107  P - [in]
108  closest_point_index - [out]
109  maximum_distance - [in] optional distance constraint.
110  If maximum_distance > 0, then only points Q with
111  |P-Q| <= maximum_distance are tested.
112  Returns:
113  True if a point is found; in which case *closest_point_index
114  is the index of the point. False if no point is found
115  or the input is not valid.
116  See Also:
117  ON_GetClosestPointInPointList
118  */
119  bool GetClosestPoint(
120  ON_3dPoint P,
121  int* closest_point_index,
122  double maximum_distance = 0.0
123  ) const;
124 
125 
126  /////////////////////////////////////////////////////////////////
127  // Interface
128  //
129  int PointCount() const;
130  void AppendPoint( const ON_3dPoint& );
131  void InvalidateBoundingBox(); // call if you change values of points
132 
133  // for ordered streams
134  void SetOrdered(bool bOrdered); // true if set is ordered stream
135  bool IsOrdered() const; // true if set is ordered stream
136 
137  // for height fields
138  bool HasPlane() const; // true if set is height field above a plane
139  void SetPlane( const ON_Plane& );
140  const ON_Plane& Plane();
141  double Height(int);
142 
143  /*
144  Returns:
145  True if m_N.Count() == m_P.Count().
146  */
147  bool HasPointNormals() const;
148 
149  /*
150  Returns:
151  True if m_C.Count() == m_P.Count().
152  */
153  bool HasPointColors() const;
154 
155  /*
156  Returns:
157  True if m_V.Count() == m_P.Count().
158  */
159  bool HasPointValues() const;
160 
161  /*
162  Returns:
163  Number of points that are hidden.
164  */
165  int HiddenPointCount() const;
166  unsigned int HiddenPointUnsignedCount() const;
167 
168  /*
169  Description:
170  Destroys the m_H[] array and sets m_hidden_count=0.
171  */
172  void DestroyHiddenPointArray();
173 
174  /*
175  Returns:
176  If the point cloud has some hidden points, then an array
177  of length PointCount() is returned and the i-th
178  element is true if the i-th vertex is hidden.
179  If no ponts are hidden, nullptr is returned.
180  */
181  const bool* HiddenPointArray() const;
182 
183  /*
184  Description:
185  Set the runtime hidden point flag.
186  Parameters:
187  point_index - [in] point vertex index
188  bHidden - [in] true to hide vertex
189  */
190  void SetHiddenPointFlag( int point_index, bool bHidden );
191 
192  /*
193  Description:
194  Returns true if the point is hidden. This is a runtime
195  setting that is not saved in 3dm files.
196  Parameters:
197  point_index - [in]
198  Returns:
199  True if the point is hidden.
200  */
201  bool PointIsHidden( int point_index ) const;
202 
203  /////////////////////////////////////////////////////////////////
204  // Implementation
206 
207  /////////////////////////////////////////////////////////////////
208  // Implementation - OPTIONAL point normal
209  // Either m_N[] has zero count or it has the same
210  // count as m_P[], in which case m_N[j] reports
211  // the color assigned to m_P[j].
213 
214  /////////////////////////////////////////////////////////////////
215  // Implementation - OPTIONAL point color
216  // Either m_C[] has zero count or it has the same
217  // count as m_P[], in which case m_C[j] reports
218  // the color assigned to m_P[j].
220 
221  /////////////////////////////////////////////////////////////////
222  // Implementation - OPTIONAL point value (intensity)
223  // Either m_V[] has zero count or it has the same
224  // count as m_P[], in which case m_V[j] reports
225  // the value assigned to m_P[j].
227 
228  /////////////////////////////////////////////////////////////////
229  // Implementation - RUNTIME point visibility - not saved in 3dm files.
230  // If m_H.Count() = m_P.Count(), then
231  // m_H[j] is true if the point m_P[j]
232  // is hidden. Otherwise, all points are visible.
233  // m_hidden_count = number of true values in the m_H[] array.
235  unsigned int m_hidden_count = 0;
236 
239  unsigned int m_flags = 0; // bit 1 is set if ordered
240  // bit 2 is set if plane is set
241 
242 };
243 
244 #endif
virtual bool Transform(const ON_Xform &xform)
virtual int Dimension() const
virtual bool GetBBox(double *boxmin, double *boxmax, bool bGrowBox=false) const
virtual bool MakeDeformable()
virtual bool SwapCoordinates(int i, int j)
virtual ON::object_type ObjectType() const
Definition: opennurbs_geometry.h:36
ON_SimpleArray< double > m_V
Definition: opennurbs_pointcloud.h:226
virtual bool GetTightBoundingBox(class ON_BoundingBox &tight_bbox, bool bGrowBox=false, const class ON_Xform *xform=nullptr) const
ON_SimpleArray< ON_3dVector > m_N
Definition: opennurbs_pointcloud.h:212
Definition: opennurbs_point.h:2073
Definition: opennurbs_bounding_box.h:25
Definition: opennurbs_xform.h:28
Definition: opennurbs_pointcloud.h:26
ON_Plane m_plane
Definition: opennurbs_pointcloud.h:237
ON_SimpleArray< ON_Color > m_C
Definition: opennurbs_pointcloud.h:219
virtual void Dump(ON_TextLog &) const
void EmergencyDestroy()
virtual bool IsDeformable() const
ON_SimpleArray< bool > m_H
Definition: opennurbs_pointcloud.h:234
ON_BoundingBox m_bbox
Definition: opennurbs_pointcloud.h:238
ON_3dPointArray m_P
Implementation.
Definition: opennurbs_pointcloud.h:205
ON_Geometry & operator=(const ON_Geometry &)=default
Definition: opennurbs_textlog.h:20
< use for generic serialization of binary data
Definition: opennurbs_archive.h:1866
virtual bool Read(ON_BinaryArchive &binary_archive)
Definition: opennurbs_point.h:480
bool IsValid(class ON_TextLog *text_log=nullptr) const override
virtual bool Write(ON_BinaryArchive &binary_archive) const
Definition: opennurbs_plane.h:20