 |
SAGA API
v9.9
|
Go to the documentation of this file.
61 #define PC_FILE_VERSION "SGPC01"
63 #define PC_SIZE_STRING 32
64 #define PC_SIZE_DATE 32
65 #define PC_SIZE_TYPE(type) (type == SG_DATATYPE_String ? PC_SIZE_STRING : type == SG_DATATYPE_Date ? PC_SIZE_DATE : (int)SG_Data_Type_Get_Size(type))
66 #define PC_SIZE_FIELD(field) PC_SIZE_TYPE(m_Field_Info[field]->m_Type)
94 if( pPoints->
Create(File) )
99 delete(pPoints);
return( NULL );
156 return( _Load(File) );
170 if( pTemplate && pTemplate->
m_nFields > 0 )
172 for(
int i=0; i<pTemplate->
m_nFields; i++)
197 m_Shapes[i].m_Index = -1;
200 m_Array_Points.
Create(
sizeof(
char *), 0, TSG_Array_Growth::SG_ARRAY_GROWTH_3);
221 SG_Free(m_Field_Offset); m_Field_Offset = NULL;
241 bool CSG_PointCloud::_Load(
const CSG_String &File)
245 bool bResult =
false;
253 if( (bResult = Stream.Get_File(_File +
"sg-pts")) ==
false )
255 for(
size_t i=0; i<Stream.Get_File_Count(); i++)
265 bResult = Stream.Get_File(_File +
"sg-pts");
268 if( bResult && _Load(Stream) )
270 if( Stream.Get_File(_File +
"sg-info") )
275 if( Stream.Get_File(_File +
"sg-prj") )
285 if( (bResult = _Load(Stream)) ==
true )
327 bool bResult =
false;
344 if( Stream.
Add_File(Name +
"sg-pts") && _Save(Stream) )
346 if( Stream.
Add_File(Name +
"sg-pts-hdr") )
351 if( Stream.
Add_File(Name +
"sg-info") )
414 bool bResult =
false;
422 if( Stream.
Get_File(_File +
"sg-pts-hdr") )
424 bResult = Header.
Load(Stream);
429 bResult = Header.
Load(File,
SG_T(
"sg-pts-hdr"));
440 bool CSG_PointCloud::_Load(
CSG_File &Stream)
457 if( !Stream.
Read(&nPointBytes,
sizeof(
int)) || nPointBytes < (
int)(3 *
sizeof(
float)) )
464 if( !Stream.
Read(&nFields,
sizeof(
int)) || nFields < 3 )
472 for(
int iField=0; iField<nFields; iField++)
477 || !Stream.
Read(&iBuffer,
sizeof(
int)) || !(iBuffer > 0 && iBuffer < 1024)
478 || !Stream.
Read(Name , iBuffer) )
497 Name[iBuffer] =
'\0';
499 if( !_Add_Field(
CSG_String((
const char *)Name), Type) )
519 bool CSG_PointCloud::_Save(
CSG_File &Stream)
527 int iBuffer, nPointBytes = m_nPointBytes - 1;
530 Stream.
Write(&nPointBytes,
sizeof(
int));
533 for(
int iField=0; iField<
m_nFields; iField++)
537 iBuffer = (int)
m_Field_Info[iField]->m_Name.Length();
if( iBuffer >= 1024 - 1 ) iBuffer = 1024 - 1;
538 Stream.
Write(&iBuffer,
sizeof(
int));
546 Stream.
Write(m_Points[i] + 1, nPointBytes);
557 Header.
Set_Name(
"PointCloudHeaderFile");
575 for(
int iField=0; iField<
m_nFields; iField++)
608 memcpy(m_Points[i] + 1, pPoints->m_Points[i] + 1, m_nPointBytes - 1l);
630 for(
int iField=0; iField<
m_nFields; iField++)
658 return(
m_nFields >= 3 && _Add_Field(Name, Type, Field) );
674 if( Field < 3 && m_nFields >= 3 )
687 m_nFields++; m_nPointBytes += nFieldBytes;
706 int Offset = m_Field_Offset[Field], nMoveBytes = Field <
m_nFields - 1 ? m_nPointBytes - m_Field_Offset[Field + 1] : 0;
708 #pragma omp parallel for
711 m_Points[i] = (
char *)
SG_Realloc(m_Points[i], m_nPointBytes *
sizeof(
char));
715 memmove(m_Points[i] + Offset + nFieldBytes, m_Points[i] + Offset, nMoveBytes);
718 memset(m_Points[i] + Offset, 0, nFieldBytes);
740 m_nFields--; m_nPointBytes -= nFieldBytes;
743 int Offset = m_Field_Offset[Field], nMoveBytes = Field <
m_nFields ? (m_nPointBytes + nFieldBytes) - m_Field_Offset[Field + 1] : 0;
745 #pragma omp parallel for
750 memmove(m_Points[i] + Offset, m_Points[i] + Offset + nFieldBytes, nMoveBytes);
753 m_Points[i] = (
char *)
SG_Realloc(m_Points[i], m_nPointBytes *
sizeof(
char));
759 for(
int i=Field, Offset=m_Field_Offset[Field]; i<
m_nFields; i++)
788 if( Field < 3 || Field >=
m_nFields || Field == Position )
794 if( Position > Field )
804 if( Position < Field )
811 #pragma omp parallel for
814 memcpy(m_Points[i] + m_Field_Offset[Position], m_Points[i] + m_Field_Offset[Field], Size);
843 Length = (Field + 1 >=
m_nFields ? m_nPointBytes : m_Field_Offset[Field + 1]) - m_Field_Offset[Field];
846 return( (
int)Length );
865 #pragma omp parallel for
882 bool CSG_PointCloud::_Set_Field_Value(
char *pPoint,
int Field,
double Value)
884 if( pPoint && Field >= 0 && Field <
m_nFields )
886 pPoint = ((
char *)pPoint) + m_Field_Offset[Field];
921 double CSG_PointCloud::_Get_Field_Value(
char *pPoint,
int Field)
const
923 if( pPoint && Field >= 0 && Field <
m_nFields )
925 pPoint += m_Field_Offset[Field];
949 bool CSG_PointCloud::_Set_Field_Value(
char *pPoint,
int Field,
const SG_Char *Value)
951 if( pPoint && Field >= 0 && Field <
m_nFields && Value )
957 default: {
double d;
return( s.asDouble(d) && _Set_Field_Value(pPoint, Field, d) ); }
961 pPoint += m_Field_Offset[Field];
974 bool CSG_PointCloud::_Get_Field_Value(
char *pPoint,
int Field,
CSG_String &Value)
const
976 if( pPoint && Field >= 0 && Field <
m_nFields )
980 default: Value.
Printf(
"%f", _Get_Field_Value(pPoint, Field));
break;
1016 p.
x = _Get_Field_Value(m_Cursor, 0);
1017 p.
y = _Get_Field_Value(m_Cursor, 1);
1018 p.
z = _Get_Field_Value(m_Cursor, 2);
1022 p.
x = p.
y = p.
z = 0.;
1035 char *pPoint = m_Points[Index];
1037 p.
x = _Get_Field_Value(pPoint, 0);
1038 p.
y = _Get_Field_Value(pPoint, 1);
1039 p.
z = _Get_Field_Value(pPoint, 2);
1043 p.
x = p.
y = p.
z = 0.;
1052 return( _Set_Field_Value(m_Cursor, 0, Point.
x)
1053 && _Set_Field_Value(m_Cursor, 1, Point.
y)
1054 && _Set_Field_Value(m_Cursor, 2, Point.
z)
1063 return( _Set_Field_Value(m_Points[Index], 0, Point.
x)
1064 && _Set_Field_Value(m_Points[Index], 1, Point.
y)
1065 && _Set_Field_Value(m_Points[Index], 2, Point.
z)
1084 _Set_Field_Value(m_Cursor, 0, x);
1085 _Set_Field_Value(m_Cursor, 1, y);
1086 _Set_Field_Value(m_Cursor, 2, z);
1114 m_Cursor = m_Points[Index];
1118 m_Points[i] = m_Points[j];
1168 bool CSG_PointCloud::_Inc_Array(
void)
1181 bool CSG_PointCloud::_Dec_Array(
void)
1211 for(
int iField=0; iField<
m_nFields; iField++)
1245 char **pPoint = m_Points;
1249 Statistics += _Get_Field_Value(*pPoint, Field);
1290 char *Point = m_Points[pShape->
m_Index];
1292 for(
int iField=0; iField<
m_nFields; iField++)
1296 default : _Set_Field_Value(Point, iField, pShape->
asDouble(iField));
break;
1309 char *Point = m_Points[Index];
1311 for(
int iField=0; iField<
m_nFields; iField++)
1315 default: pShape->
Set_Value(iField, _Get_Field_Value(Point, iField));
break;
1337 return( pShape->
m_Index >= 0 ? pShape : NULL );
1341 void CSG_PointCloud::_Shape_Flush(
void)
1345 _Shape_Get(m_Shapes[i].m_Index); m_Shapes[i].m_Index = -1;
1370 sLong Index = -1;
CSG_Rect r(Point.
x - Epsilon, Point.
y - Epsilon, Point.
x + Epsilon, Point.
y + Epsilon);
1374 double Distance = -1.;
1598 m_Points[n] = m_Points[i];
1620 char **pPoint = m_Points;
1658 m_Points[i] = Points[Index[i]];
virtual CSG_Table_Record * Add_Record(CSG_Table_Record *pCopy=NULL)
virtual bool Assign(CSG_Data_Object *pObject, bool bProgress=false)
double asDouble(int Field) const
bool Set_Array(sLong nValues, bool bShrink=true)
CSG_Rect & Assign(double xMin, double yMin, double xMax, double yMax)
CSG_Rect m_Extent_Selected
virtual bool Destroy(void)
bool Save(const CSG_String &File, ESG_CRS_Format Format=ESG_CRS_Format::WKT) const
int Printf(const char *Format,...)
TSG_Data_Type Get_Field_Type(int Field) const
virtual bool Set_Count(sLong nRecords)
void Set_File_Name(const CSG_String &FileName)
@ POINTCLOUD_FILE_FORMAT_Normal
virtual CSG_Shape * Get_Shape(const CSG_Point &Point, double Epsilon=0.)
const char * b_str(void) const
virtual bool Set_Point(const TSG_Point_3D &Point)
virtual bool Set_Field_Type(int Field, TSG_Data_Type Type)
SAGA_API_DLL_EXPORT bool SG_File_Set_Extension(CSG_String &File, const CSG_String &Extension)
virtual double Get_Z(int iPoint=0, int iPart=0, bool bAscending=true) const
void Set_Selected(bool bOn=true)
double Get_NoData_Value(bool bUpper=false) const
CSG_PointCloud * SG_Create_PointCloud(void)
SAGA_API_DLL_EXPORT bool SG_File_Cmp_Extension(const CSG_String &File, const CSG_String &Extension)
@ SG_UI_MSG_STYLE_SUCCESS
virtual CSG_Table_Record * Get_Selection(sLong Index=0) const
virtual bool Set_Field_Type(int Field, TSG_Data_Type Type)
double Get_Maximum(int Field) const
bool Create(const CSG_Shapes &Shapes)
SAGA_API_DLL_EXPORT void * SG_Malloc(size_t size)
#define SG_TABLE_REC_FLAG_Selected
bool Save_MetaData(const CSG_String &FileName)
virtual bool _Stats_Update(int Field) const
bool Reset_Statistics(void)
TSG_Intersection Intersects(const CSG_Rect &Rect) const
virtual const CSG_Rect & Get_Selection_Extent(void)
virtual bool Select(sLong Index, bool bInvert=false)
virtual bool On_Reload(void)
int Get_Field_Count(void) const
SAGA_API_DLL_EXPORT bool SG_File_Delete(const CSG_String &FileName)
SAGA_API_DLL_EXPORT void SG_Free(void *memblock)
CSG_Field_Info ** m_Field_Info
class CSG_Table * Get_Table(void)
virtual bool Add_Field(const CSG_String &Name, TSG_Data_Type Type, int Field=-1)
size_t Read(void *Buffer, size_t Size, size_t Count=1) const
void Set_Update_Flag(bool bOn=true)
SAGA_API_DLL_EXPORT void * SG_Calloc(size_t num, size_t size)
bool _Stats_Invalidate(void) const
bool Contains(double x, double y) const
virtual TSG_Point Get_Point(int iPoint=0) const =0
virtual bool Set_Value(int Field, double Value)
bool is_Compatible(CSG_PointCloud *pPointCloud) const
virtual sLong Del_Selection(void)
@ SG_UI_MSG_STYLE_FAILURE
virtual ~CSG_PointCloud(void)
SAGA_API_DLL_EXPORT CSG_String SG_File_Get_Name(const CSG_String &full_Path, bool bExtension)
virtual int Get_Field_Length(int Field, int Encoding=SG_FILE_ENCODING_UNDEFINED) const
virtual bool Sort(const CSG_Index &Index)
const SG_Char * asString(int Field, int Decimals=-99) const
bool Del_Point(sLong Index)
sLong Get_Selection_Count(void) const
virtual CSG_Table_Record * Get_Record(sLong Index) const
bool _Set_Selection(sLong Index, sLong Selected)
virtual double Get_Value(int Field) const
#define PC_SIZE_TYPE(type)
bool is_Writing(void) const
virtual bool _Stats_Update(int Field) const
double SG_Get_Distance(double ax, double ay, double bx, double by, bool bPolar)
const SG_Char * Get_Field_Name(int Field) const
bool SG_Data_Type_is_Numeric(TSG_Data_Type Type)
sLong Get_Count(void) const
int SG_OMP_Get_Max_Num_Procs(void)
virtual CSG_Shape * Get_Shape(const CSG_Point &Point, double Epsilon=0.)
virtual bool Del_Field(int Field)
int is_Evaluated(void) const
int SG_UI_Progress_Lock(bool bOn)
const SG_Char * Get_File_Name(bool bNative=true) const
static bool Get_Header_Content(const CSG_String &FileName, CSG_MetaData &Header)
bool Get_File(const SG_Char *Name)
virtual sLong Inv_Selection(void)
void * Create(const CSG_Array &Array)
virtual void Set_Modified(bool bModified=true)
bool Load(const CSG_String &File)
virtual const CSG_Rect & Get_Extent(void)
TSG_Vertex_Type m_Vertex_Type
void Set_Modified(bool bOn=true)
bool Set_Cursor(sLong Index)
virtual bool is_Selected(sLong Index) const
static CSG_String Format(const char *Format,...)
bool _Del_Selection(sLong Index)
virtual bool Add_Field(const CSG_String &Name, TSG_Data_Type Type, int Position=-1)
const char gSG_Data_Type_Identifier[][32]
bool Add_File(const SG_Char *Name, bool bBinary=true)
bool _Add_Selection(sLong Index)
CSG_Simple_Statistics m_Statistics
virtual bool Mov_Field(int Field, int Position)
virtual bool On_Update(void)
virtual int Set_Point(double x, double y, int iPoint=0, int iPart=0)=0
@ POINTCLOUD_FILE_FORMAT_Compressed
bool is_Empty(void) const
bool SG_UI_Process_Set_Progress(int Position, int Range)
TSG_Point_3D Get_Point(void) const
bool Create(double xMin, double yMin, double xMax, double yMax)
bool Set_Value(int Field, const CSG_String &Value)
@ POINTCLOUD_FILE_FORMAT_Undefined
virtual bool Del_Field(int Field)
double Get_Minimum(int Field) const
int SG_OMP_Get_Thread_Num(void)
bool Load_MetaData(const CSG_String &FileName)
sLong Get_Selection_Index(sLong Index=0) const
class CSG_PointCloud * asPointCloud(bool bPolymorph=false) const
CSG_Data_Collection & PointCloud(void) const
virtual bool Set_NoData_Value(double Value)
virtual void _On_Construction(void)
SAGA_API_DLL_EXPORT CSG_String SG_File_Make_Path(const CSG_String &Directory, const CSG_String &Name)
const SG_Char * c_str(void) const
size_t Write(void *Buffer, size_t Size, size_t Count=1) const
#define PC_SIZE_FIELD(field)
bool SG_UI_Process_Set_Ready(void)
virtual bool Select(sLong Index, bool bInvert=false)
SAGA_API_DLL_EXPORT void * SG_Realloc(void *memblock, size_t size)
sLong Get_Count(void) const
bool Create(const CSG_Projection &Projection)
virtual bool On_Delete(void)
bool Add_Point(double x, double y, double z)
virtual bool Assign(CSG_Data_Object *pSource, bool bProgress=false)
bool is_Modified(void) const
CSG_Projection & Get_Projection(void)
virtual CSG_Table_Record * Ins_Record(sLong Index, CSG_Table_Record *pCopy=NULL)
virtual bool Destroy(void)
bool is_Reading(void) const
virtual bool Save(const CSG_String &File, int Format=0)
void SG_UI_Msg_Add(const char *Message, bool bNewLine, TSG_UI_MSG_STYLE Style)
virtual CSG_Shape * Add_Shape(CSG_Table_Record *pCopy=NULL, TSG_ADD_Shape_Copy_Mode mCopy=SHAPE_COPY)