00001 /* $NoKeywords: $ */ 00002 /* 00003 // 00004 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved. 00005 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert 00006 // McNeel & Associates. 00007 // 00008 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. 00009 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF 00010 // MERCHANTABILITY ARE HEREBY DISCLAIMED. 00011 // 00012 // For complete openNURBS copyright information see <http://www.opennurbs.org>. 00013 // 00015 */ 00016 00017 #if !defined(OPENNURBS_POINTCLOUD_INC_) 00018 #define OPENNURBS_POINTCLOUD_INC_ 00019 00021 // 00022 // Class ON_PointCloud - unordered set of points 00023 // ON_PointField - point height field 00024 // 00025 00026 class ON_CLASS ON_PointCloud : public ON_Geometry 00027 { 00028 ON_OBJECT_DECLARE(ON_PointCloud); 00029 00030 public: 00031 ON_PointCloud(); 00032 ON_PointCloud( 00033 int // initial point array capacity 00034 ); 00035 ON_PointCloud( const ON_PointCloud& ); 00036 ~ON_PointCloud(); 00037 ON_PointCloud& operator=( const ON_PointCloud& ); 00038 00039 ON_3dPoint& operator[](int); 00040 const ON_3dPoint& operator[](int) const; 00041 00042 /* 00043 Description: 00044 Get a point cloud point from an ON_COMPONENT_INDEX. 00045 Parameters: 00046 ci - [in] a component index with m_typ set to ON_COMPONENT_INDEX::pointcloud_point 00047 and 0 <= m_index and m_index < m_P.Count(). 00048 Returns: 00049 Point at [ci.m_index] or ON_UNSET_POINT if ci is not valid. 00050 */ 00051 ON_3dPoint Point( ON_COMPONENT_INDEX ci ) const; 00052 00053 void Destroy(); 00054 00055 /* 00056 Description: 00057 Call when the memory pool used the point cloud's arrays is 00058 no longer in existence. 00059 */ 00060 void EmergencyDestroy(); 00061 00062 // virtual ON_Object override 00063 ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const; 00064 00065 // virtual ON_Object override 00066 void Dump( ON_TextLog& ) const; // for debugging 00067 00068 // virtual ON_Object override 00069 ON_BOOL32 Write( ON_BinaryArchive& ) const; 00070 00071 // virtual ON_Object override 00072 ON_BOOL32 Read( ON_BinaryArchive& ); 00073 00074 // virtual ON_Object override 00075 ON::object_type ObjectType() const; 00076 00077 // virtual ON_Geometry override 00078 int Dimension() const; 00079 00080 // virtual ON_Geometry override 00081 ON_BOOL32 GetBBox( // returns true if successful 00082 double*, // minimum 00083 double*, // maximum 00084 ON_BOOL32 = false // true means grow box 00085 ) const; 00086 00087 // virtual ON_Geometry override 00088 bool GetTightBoundingBox( 00089 ON_BoundingBox& tight_bbox, 00090 int bGrowBox = false, 00091 const ON_Xform* xform = 0 00092 ) const; 00093 00094 // virtual ON_Geometry override 00095 ON_BOOL32 Transform( 00096 const ON_Xform& 00097 ); 00098 00099 // virtual ON_Geometry override 00100 bool IsDeformable() const; 00101 00102 // virtual ON_Geometry override 00103 bool MakeDeformable(); 00104 00105 // virtual ON_Geometry override 00106 ON_BOOL32 SwapCoordinates( 00107 int, int // indices of coords to swap 00108 ); 00109 00110 /* 00111 Description: 00112 Get the index of the point in the point cloud that is closest 00113 to P. 00114 Parameters: 00115 P - [in] 00116 closest_point_index - [out] 00117 maximum_distance - [in] optional distance constraint. 00118 If maximum_distance > 0, then only points Q with 00119 |P-Q| <= maximum_distance are tested. 00120 Returns: 00121 True if a point is found; in which case *closest_point_index 00122 is the index of the point. False if no point is found 00123 or the input is not valid. 00124 See Also: 00125 ON_GetClosestPointInPointList 00126 */ 00127 bool GetClosestPoint( 00128 ON_3dPoint P, 00129 int* closest_point_index, 00130 double maximum_distance = 0.0 00131 ) const; 00132 00133 00135 // Interface 00136 // 00137 int PointCount() const; 00138 void AppendPoint( const ON_3dPoint& ); 00139 void InvalidateBoundingBox(); // call if you change values of points 00140 00141 // for ordered streams 00142 void SetOrdered(bool bOrdered); // true if set is ordered stream 00143 bool IsOrdered() const; // true if set is ordered stream 00144 00145 // for height fields 00146 bool HasPlane() const; // true if set is height field above a plane 00147 void SetPlane( const ON_Plane& ); 00148 const ON_Plane& Plane(); 00149 double Height(int); 00150 00151 /* 00152 Returns: 00153 True if m_N.Count() == m_P.Count(). 00154 */ 00155 bool HasPointNormals() const; 00156 00157 /* 00158 Returns: 00159 True if m_C.Count() == m_P.Count(). 00160 */ 00161 bool HasPointColors() const; 00162 00163 00164 /* 00165 Returns: 00166 Number of points that are hidden. 00167 */ 00168 int HiddenPointCount() const; 00169 00170 /* 00171 Description: 00172 Destroys the m_H[] array and sets m_hidden_count=0. 00173 */ 00174 void DestroyHiddenPointArray(); 00175 00176 /* 00177 Returns: 00178 If the point cloud has some hidden points, then an array 00179 of length PointCount() is returned and the i-th 00180 element is true if the i-th vertex is hidden. 00181 If no ponts are hidden, NULL is returned. 00182 */ 00183 const bool* HiddenPointArray() const; 00184 00185 /* 00186 Description: 00187 Set the runtime hidden point flag. 00188 Parameters: 00189 point_index - [in] point vertex index 00190 bHidden - [in] true to hide vertex 00191 */ 00192 void SetHiddenPointFlag( int point_index, bool bHidden ); 00193 00194 /* 00195 Description: 00196 Returns true if the point is hidden. This is a runtime 00197 setting that is not saved in 3dm files. 00198 Parameters: 00199 point_index - [in] 00200 Returns: 00201 True if the point is hidden. 00202 */ 00203 bool PointIsHidden( int point_index ) const; 00204 00206 // Implementation 00207 ON_3dPointArray m_P; 00208 00210 // Implementation - OPTIONAL point normal 00211 // Either m_N[] has zero count or it has the same 00212 // count as m_P[], in which case m_N[j] reports 00213 // the color assigned to m_P[j]. 00214 ON_SimpleArray<ON_3dVector> m_N; 00215 00217 // Implementation - OPTIONAL point color 00218 // Either m_C[] has zero count or it has the same 00219 // count as m_P[], in which case m_P[j] reports 00220 // the color assigned to m_P[j]. 00221 ON_SimpleArray<ON_Color> m_C; 00222 00224 // Implementation - RUNTIME point visibility - not saved in 3dm files. 00225 // If m_H.Count() = m_P.Count(), then 00226 // m_H[j] is true if the point m_P[j] 00227 // is hidden. Otherwise, all points are visible. 00228 // m_hidden_count = number of true values in the m_H[] array. 00229 ON_SimpleArray<bool> m_H; 00230 int m_hidden_count; 00231 00232 ON_Plane m_plane; 00233 ON_BoundingBox m_bbox; 00234 unsigned int m_flags; // bit 1 is set if ordered 00235 // bit 2 is set if plane is set 00236 00237 }; 00238 00239 #endif