1 
2 ///////////////////////////////////////////////////////////
3 //                                                       //
4 //                         SAGA                          //
5 //                                                       //
6 //      System for Automated Geoscientific Analyses      //
7 //                                                       //
8 //           Application Programming Interface           //
9 //                                                       //
10 //                  Library: SAGA_API                    //
11 //                                                       //
12 //-------------------------------------------------------//
13 //                                                       //
14 //                     pointcloud.h                      //
15 //                                                       //
16 //          Copyright (C) 2009 by Olaf Conrad            //
17 //                                                       //
18 //-------------------------------------------------------//
19 //                                                       //
20 // This file is part of 'SAGA - System for Automated     //
21 // Geoscientific Analyses'.                              //
22 //                                                       //
23 // This library is free software; you can redistribute   //
24 // it and/or modify it under the terms of the GNU Lesser //
25 // General Public License as published by the Free       //
26 // Software Foundation, either version 2.1 of the        //
27 // License, or (at your option) any later version.       //
28 //                                                       //
29 // This library is distributed in the hope that it will  //
30 // be useful, but WITHOUT ANY WARRANTY; without even the //
31 // implied warranty of MERCHANTABILITY or FITNESS FOR A  //
32 // PARTICULAR PURPOSE. See the GNU Lesser General Public //
33 // License for more details.                             //
34 //                                                       //
35 // You should have received a copy of the GNU Lesser     //
36 // General Public License along with this program; if    //
37 // not, see <http://www.gnu.org/licenses/>.              //
38 //                                                       //
39 //-------------------------------------------------------//
40 //                                                       //
41 //    contact:    Olaf Conrad                            //
42 //                Institute of Geography                 //
43 //                University of Hamburg                  //
44 //                Germany                                //
45 //                                                       //
46 //    e-mail:     oconrad@saga-gis.org                   //
47 //                                                       //
48 ///////////////////////////////////////////////////////////
49 
50 //---------------------------------------------------------
51 #ifndef HEADER_INCLUDED__SAGA_API__pointcloud_H
52 #define HEADER_INCLUDED__SAGA_API__pointcloud_H
53 
54 
55 ///////////////////////////////////////////////////////////
56 //														 //
57 //														 //
58 //														 //
59 ///////////////////////////////////////////////////////////
60 
61 //---------------------------------------------------------
62 /** \file pointcloud.h
63 * The point cloud data container, a specialized CSG_Shapes class.
64 * @see CSG_PointCloud
65 * @see CSG_Shapes
66 * @see CSG_Table
67 * @see CSG_Data_Object
68 */
69 
70 
71 ///////////////////////////////////////////////////////////
72 //														 //
73 //														 //
74 //														 //
75 ///////////////////////////////////////////////////////////
76 
77 //---------------------------------------------------------
78 #include "shapes.h"
79 
80 
81 ///////////////////////////////////////////////////////////
82 //														 //
83 //														 //
84 //														 //
85 ///////////////////////////////////////////////////////////
86 
87 //---------------------------------------------------------
88 typedef enum ESG_PointCloud_FileType
89 {
90 	POINTCLOUD_FILE_FORMAT_Undefined	= 0,
91 	POINTCLOUD_FILE_FORMAT_Normal,
92 	POINTCLOUD_FILE_FORMAT_Compressed
93 }
94 TSG_PointCloud_File_Type;
95 
96 
97 ///////////////////////////////////////////////////////////
98 //														 //
99 //														 //
100 //														 //
101 ///////////////////////////////////////////////////////////
102 
103 //---------------------------------------------------------
104 class SAGA_API_DLL_EXPORT CSG_PointCloud : public CSG_Shapes
105 {
106 public:
107 
108 									CSG_PointCloud		(void);
109 	bool							Create				(void);
110 
111 									CSG_PointCloud		(const CSG_PointCloud &PointCloud);
112 	bool							Create				(const CSG_PointCloud &PointCloud);
113 
114 									CSG_PointCloud		(const CSG_String &File_Name);
115 	bool							Create				(const CSG_String &File_Name);
116 
117 									CSG_PointCloud		(CSG_PointCloud *pStructure);
118 	bool							Create				(CSG_PointCloud *pStructure);
119 
120 	virtual ~CSG_PointCloud(void);
121 
122 	virtual bool					Destroy				(void);
123 
Get_ObjectType(void)124 	virtual TSG_Data_Object_Type	Get_ObjectType		(void)	const			{	return( SG_DATAOBJECT_TYPE_PointCloud );	}
125 
126 	virtual bool					Assign				(CSG_Data_Object *pSource);
127 
128 	virtual bool					Save				(const CSG_String &File, int Format = 0);
129 	virtual bool					Save				(const char       *File, int Format = 0)	{	return( Save(CSG_String(File), Format) );	}
130 	virtual bool					Save				(const wchar_t    *File, int Format = 0)	{	return( Save(CSG_String(File), Format) );	}
131 
Set_XYZ_Precision(bool bDouble)132 	void							Set_XYZ_Precision	(bool bDouble)			{	m_bXYZPrecDbl	= bDouble;	}
133 
134 	static bool						Get_Header_Content	(const CSG_String &FileName, CSG_MetaData &Header);
135 
136 	//-----------------------------------------------------
is_Valid(void)137 	virtual bool					is_Valid			(void)	const			{	return( m_nFields > 0 );	}
138 	bool							is_Compatible		(CSG_PointCloud *pPointCloud)	const;
139 
140 	//-----------------------------------------------------
141 	virtual bool					Add_Field			(const CSG_String &Name, TSG_Data_Type Type, int iField = -1);
142 	virtual bool					Del_Field			(int iField);
143 	virtual bool					Mov_Field			(int iField, int Position);
144 
145 	virtual bool					Set_Field_Type		(int iField, TSG_Data_Type Type);
146 
147 	//-----------------------------------------------------
Get_Attribute_Count(void)148 	int								Get_Attribute_Count	(void)			const	{	return( m_nFields - 3 );	}
Get_Attribute_Name(int iField)149 	const SG_Char *					Get_Attribute_Name	(int iField)	const	{	iField += 3; return( iField >= 3 && iField < m_nFields ? m_Field_Name[iField]->c_str() : NULL );			}
Get_Attribute_Type(int iField)150 	TSG_Data_Type					Get_Attribute_Type	(int iField)	const	{	iField += 3; return( iField >= 3 && iField < m_nFields ? m_Field_Type[iField] : SG_DATATYPE_Undefined );	}
151 
152 	//-----------------------------------------------------
153 	bool							Add_Point			(double x, double y, double z);
154 	bool							Del_Point			(int iPoint);
155 	bool							Del_Points			(void);
156 
Get_Point_Count(void)157 	int								Get_Point_Count		(void)			const	{	return( m_nRecords );	}
158 
159 	//-----------------------------------------------------
Set_Cursor(int iPoint)160 	bool							Set_Cursor			(int iPoint)							{	return( (m_Cursor = iPoint >= 0 && iPoint < m_nRecords ? m_Points[iPoint] : NULL) != NULL );	}
Set_Value(int iField,double Value)161 	virtual bool					Set_Value			(            int iField, double Value)	{	return( _Set_Field_Value(m_Cursor, iField, Value) );	}
Get_Value(int iField)162 	virtual double					Get_Value			(            int iField)	const		{	return( _Get_Field_Value(m_Cursor, iField) );			}
Get_X(void)163 	double							Get_X				(void)						const		{	return( _Get_Field_Value(m_Cursor, 0) );				}
Get_Y(void)164 	double							Get_Y				(void)						const		{	return( _Get_Field_Value(m_Cursor, 1) );				}
Get_Z(void)165 	double							Get_Z				(void)						const		{	return( _Get_Field_Value(m_Cursor, 2) );				}
Set_Attribute(int iField,double Value)166 	bool							Set_Attribute		(            int iField, double Value)	{	return( Set_Value(iField + 3, Value) );					}
Get_Attribute(int iField)167 	double							Get_Attribute		(            int iField)	const		{	return( Get_Value(iField + 3) );						}
Set_NoData(int iField)168 	bool							Set_NoData			(            int iField)				{	return( Set_Value(iField, Get_NoData_Value()) );	}
is_NoData(int iField)169 	bool							is_NoData			(            int iField)	const		{	return( is_NoData_Value(Get_Value(iField)) );		}
170 
Set_Value(int iPoint,int iField,double Value)171 	virtual bool					Set_Value			(int iPoint, int iField, double Value)	{	return( _Set_Field_Value(iPoint >= 0 && iPoint < m_nRecords ? m_Points[iPoint] : NULL, iField, Value) );	}
Get_Value(int iPoint,int iField)172 	virtual double					Get_Value			(int iPoint, int iField)	const		{	return( _Get_Field_Value(iPoint >= 0 && iPoint < m_nRecords ? m_Points[iPoint] : NULL, iField) );		}
Get_X(int iPoint)173 	double							Get_X				(int iPoint)				const		{	return( _Get_Field_Value(iPoint >= 0 && iPoint < m_nRecords ? m_Points[iPoint] : NULL, 0) );				}
Get_Y(int iPoint)174 	double							Get_Y				(int iPoint)				const		{	return( _Get_Field_Value(iPoint >= 0 && iPoint < m_nRecords ? m_Points[iPoint] : NULL, 1) );				}
Get_Z(int iPoint)175 	double							Get_Z				(int iPoint)				const		{	return( _Get_Field_Value(iPoint >= 0 && iPoint < m_nRecords ? m_Points[iPoint] : NULL, 2) );				}
Set_Attribute(int iPoint,int iField,double Value)176 	bool							Set_Attribute		(int iPoint, int iField, double Value)	{	return( Set_Value(iPoint, iField + 3, Value) );				}
Get_Attribute(int iPoint,int iField)177 	double							Get_Attribute		(int iPoint, int iField)	const		{	return( Get_Value(iPoint, iField + 3) );					}
Set_NoData(int iPoint,int iField)178 	bool							Set_NoData			(int iPoint, int iField)				{	return( Set_Value(iPoint, iField, Get_NoData_Value()) );}
is_NoData(int iPoint,int iField)179 	bool							is_NoData			(int iPoint, int iField)	const		{	return( is_NoData_Value(Get_Value(iPoint, iField)) );	}
180 
Set_Value(int iField,const SG_Char * Value)181 	virtual bool					Set_Value			(            int iField, const SG_Char *Value)			{	return( _Set_Field_Value(m_Cursor, iField, Value) );	}
Get_Value(int iField,CSG_String & Value)182 	virtual bool					Get_Value			(            int iField, CSG_String    &Value)	const	{	return( _Get_Field_Value(m_Cursor, iField, Value) );	}
Set_Value(int iPoint,int iField,const SG_Char * Value)183 	virtual bool					Set_Value			(int iPoint, int iField, const SG_Char *Value)			{	return( _Set_Field_Value(iPoint >= 0 && iPoint < m_nRecords ? m_Points[iPoint] : NULL, iField, Value) );	}
Get_Value(int iPoint,int iField,CSG_String & Value)184 	virtual bool					Get_Value			(int iPoint, int iField, CSG_String    &Value)	const	{	return( _Get_Field_Value(iPoint >= 0 && iPoint < m_nRecords ? m_Points[iPoint] : NULL, iField, Value) );	}
Set_Attribute(int iField,const SG_Char * Value)185 	virtual bool					Set_Attribute		(            int iField, const SG_Char *Value)			{	return( Set_Value(iField + 3, Value) );			}
Get_Attribute(int iField,CSG_String & Value)186 	virtual bool					Get_Attribute		(            int iField, CSG_String    &Value)	const	{	return( Get_Value(iField + 3, Value) );			}
Set_Attribute(int iPoint,int iField,const SG_Char * Value)187 	virtual bool					Set_Attribute		(int iPoint, int iField, const SG_Char *Value)			{	return( Set_Value(iPoint, iField + 3, Value) );	}
Get_Attribute(int iPoint,int iField,CSG_String & Value)188 	virtual bool					Get_Attribute		(int iPoint, int iField, CSG_String    &Value)	const	{	return( Get_Value(iPoint, iField + 3, Value) );	}
189 
190 	TSG_Point_Z						Get_Point			(void)			const;
191 	TSG_Point_Z						Get_Point			(int iPoint)	const;
192 	virtual bool					Set_Point			(            const TSG_Point_Z &Point);
193 	virtual bool					Set_Point			(int iPoint, const TSG_Point_Z &Point);
194 
195 	virtual void					Set_Modified		(bool bModified = true)		{	CSG_Data_Object::Set_Modified(bModified);	}
196 
197 
198 	//-----------------------------------------------------
199 	// Overrides: CSG_Table, CSG_Shapes
200 
201 	virtual CSG_Table_Record *		Get_Record			(int iRecord)	const;
202 
203 	virtual CSG_Shape *				Get_Shape			(TSG_Point Point, double Epsilon = 0.0);
204 
Del_Record(int iRecord)205 	virtual bool					Del_Record			(int iRecord)	{	return( Del_Point(iRecord) );	}
Del_Shape(int iShape)206 	virtual bool					Del_Shape			(int iShape)	{	return( Del_Point(iShape) );	}
Del_Records(void)207 	virtual bool					Del_Records			(void)			{	return( Del_Points() );			}
Del_Shapes(void)208 	virtual bool					Del_Shapes			(void)			{	return( Del_Points() );			}
209 
210 	virtual CSG_Table_Record *		Ins_Record			(int iRecord, CSG_Table_Record *pCopy = NULL);
211 	virtual CSG_Table_Record *		Add_Record			(             CSG_Table_Record *pCopy = NULL);
212 	virtual CSG_Shape *				Add_Shape			(             CSG_Table_Record *pCopy = NULL, TSG_ADD_Shape_Copy_Mode mCopy = SHAPE_COPY);
Del_Shape(CSG_Shape * pShape)213 	virtual bool					Del_Shape			(CSG_Shape *pShape)	{	return( false );	}
214 
215 	virtual bool					Select				(int iRecord             , bool bInvert = false);
216 	virtual bool					Select				(CSG_Shape *pShape = NULL, bool bInvert = false);
217 	virtual bool					Select				(TSG_Rect Extent         , bool bInvert = false);
218 	virtual bool					Select				(TSG_Point Point         , bool bInvert = false);
219 
220 	virtual bool					is_Selected			(int iRecord)	const;
221 
222 	virtual int						Del_Selection		(void);
223 	virtual int						Inv_Selection		(void);
224 	virtual CSG_Shape *				Get_Selection		(size_t Index = 0);
225 	virtual const CSG_Rect &		Get_Selection_Extent(void);
226 
227 
228 protected:
229 
230 	virtual bool					On_Update			(void);
231 	virtual bool					On_Reload			(void);
232 	virtual bool					On_Delete			(void);
233 
234 	virtual void					_On_Construction	(void);
235 
236 	virtual bool					_Stats_Update		(int iField)	const;
237 
238 
239 private:
240 
241 	bool							m_bXYZPrecDbl;
242 
243 	char							**m_Points, *m_Cursor;
244 
245 	int								m_nPointBytes, *m_Field_Offset, m_Shapes_Index;
246 
247 	CSG_Array						m_Array_Points;
248 
249 	CSG_Shapes						m_Shapes;
250 
251 
252 	bool							_Load				(const CSG_String &File_Name);
253 	bool							_Load				(CSG_File &Stream);
254 	bool							_Save				(CSG_File &Stream);
255 	CSG_MetaData					_Create_Header		(void)	const;
256 
257 	bool							_Add_Field			(const SG_Char *Name, TSG_Data_Type Type, int iField = -1);
258 	bool							_Set_Field_Value	(char *pPoint, int iField, double         Value);
259 	double							_Get_Field_Value	(char *pPoint, int iField                      )	const;
260 	bool							_Set_Field_Value	(char *pPoint, int iField, const SG_Char *Value);
261 	bool							_Get_Field_Value	(char *pPoint, int iField, CSG_String    &Value)	const;
262 	int								_Get_Field_Bytes	(TSG_Data_Type Type);
263 
264 	bool							_Inc_Array			(void);
265 	bool							_Dec_Array			(void);
266 
267 	CSG_Shape *						_Set_Shape			(int iPoint);
268 
269 };
270 
271 
272 ///////////////////////////////////////////////////////////
273 //														 //
274 //														 //
275 //														 //
276 ///////////////////////////////////////////////////////////
277 
278 //---------------------------------------------------------
279 /** Safe Point Cloud construction */
280 SAGA_API_DLL_EXPORT CSG_PointCloud *	SG_Create_PointCloud	(void);
281 
282 /** Safe Point Cloud construction */
283 SAGA_API_DLL_EXPORT CSG_PointCloud *	SG_Create_PointCloud	(const CSG_PointCloud &PointCloud);
284 
285 /** Safe Point Cloud construction */
286 SAGA_API_DLL_EXPORT CSG_PointCloud *	SG_Create_PointCloud	(const CSG_String &File_Name);
287 
288 /** Safe Point Cloud construction */
289 SAGA_API_DLL_EXPORT CSG_PointCloud *	SG_Create_PointCloud	(CSG_PointCloud *pStructure);
290 
291 ///////////////////////////////////////////////////////////
292 //														 //
293 //														 //
294 //														 //
295 ///////////////////////////////////////////////////////////
296 
297 //---------------------------------------------------------
298 #endif // #ifndef HEADER_INCLUDED__SAGA_API__pointcloud_H
299