|
SAGA API
v9.6
|
Go to the documentation of this file.
61 #define PC_FILE_VERSION "SGPC01"
63 #define PC_STR_NBYTES 32
64 #define PC_DAT_NBYTES 32
66 #define PC_GET_NBYTES(type) (type == SG_DATATYPE_String ? PC_STR_NBYTES : type == SG_DATATYPE_Date ? PC_DAT_NBYTES : (int)SG_Data_Type_Get_Size(type))
151 return( _Load(File) );
165 if( pTemplate && pTemplate->
m_nFields > 0 )
167 for(
int iField=0; iField<pTemplate->
m_nFields; iField++)
188 m_Field_Offset = NULL;
195 m_bXYZPrecDbl =
true;
205 m_Shapes[i].m_Index = -1;
208 m_Array_Points.
Create(
sizeof(
char *), 0, TSG_Array_Growth::SG_ARRAY_GROWTH_3);
223 for(
int iField=0; iField<
m_nFields; iField++)
250 bool CSG_PointCloud::_Load(
const CSG_String &File)
254 bool bResult =
false;
262 if( (bResult = Stream.Get_File(_File +
"sg-pts")) ==
false )
264 for(
size_t i=0; i<Stream.Get_File_Count(); i++)
274 bResult = Stream.Get_File(_File +
"sg-pts");
277 if( bResult && _Load(Stream) )
279 if( Stream.Get_File(_File +
"sg-info") )
284 if( Stream.Get_File(_File +
"sg-prj") )
294 if( (bResult = _Load(Stream)) ==
true )
331 bool bResult =
false;
348 if( Stream.
Add_File(Name +
"sg-pts") && _Save(Stream) )
350 if( Stream.
Add_File(Name +
"sg-pts-hdr") )
355 if( Stream.
Add_File(Name +
"sg-info") )
418 bool bResult =
false;
426 if( Stream.
Get_File(_File +
"sg-pts-hdr") )
428 bResult = Header.
Load(Stream);
433 bResult = Header.
Load(File,
SG_T(
"sg-pts-hdr"));
444 bool CSG_PointCloud::_Load(
CSG_File &Stream)
461 if( !Stream.
Read(&nPointBytes,
sizeof(
int)) || nPointBytes < (
int)(3 *
sizeof(
float)) )
468 if( !Stream.
Read(&nFields,
sizeof(
int)) || nFields < 3 )
476 for(
int iField=0; iField<nFields; iField++)
481 || !Stream.
Read(&iBuffer,
sizeof(
int)) || !(iBuffer > 0 && iBuffer < 1024)
482 || !Stream.
Read(Name , iBuffer) )
501 Name[iBuffer] =
'\0';
503 if( !_Add_Field(
CSG_String((
const char *)Name), Type) )
523 bool CSG_PointCloud::_Save(
CSG_File &Stream)
531 int iBuffer, nPointBytes = m_nPointBytes - 1;
534 Stream.
Write(&nPointBytes,
sizeof(
int));
537 for(
int iField=0; iField<
m_nFields; iField++)
541 iBuffer = (int)
m_Field_Name[iField]->Length();
if( iBuffer >= 1024 - 1 ) iBuffer = 1024 - 1;
542 Stream.
Write(&iBuffer,
sizeof(
int));
550 Stream.
Write(m_Points[i] + 1, nPointBytes);
561 Header.
Set_Name(
"PointCloudHeaderFile");
579 for(
int iField=0; iField<
m_nFields; iField++)
606 for(
int iField=0; iField<pPoints->
m_nFields; iField++)
615 memcpy(m_Points[i] + 1, pPoints->m_Points[i] + 1, m_nPointBytes - 1l);
637 for(
int iField=0; iField<
m_nFields; iField++)
665 return(
m_nFields >= 3 && _Add_Field(Name, Type, iField) );
671 #define m_Field_Size(FIELD) PC_GET_NBYTES(m_Field_Type[FIELD])
684 if( Field < 3 && m_nFields >= 3 )
697 m_nFields++; m_nPointBytes += nFieldBytes;
705 for(
int iField=
m_nFields-1; iField>Field; iField--)
716 for(
int iField=0, Offset=1; iField<
m_nFields; iField++)
718 m_Field_Offset[iField] = Offset; Offset+=
m_Field_Size(iField);
722 int Offset = m_Field_Offset[Field], nMoveBytes = Field <
m_nFields - 1 ? m_nPointBytes - m_Field_Offset[Field + 1] : 0;
724 #pragma omp parallel for
727 m_Points[i] = (
char *)
SG_Realloc(m_Points[i], m_nPointBytes *
sizeof(
char));
731 memmove(m_Points[i] + Offset + nFieldBytes, m_Points[i] + Offset, nMoveBytes);
734 memset(m_Points[i] + Offset, 0, nFieldBytes);
748 #define m_Field_Size(FIELD) PC_GET_NBYTES(m_Field_Type[FIELD])
759 m_nFields--; m_nPointBytes -= nFieldBytes;
762 int Offset = m_Field_Offset[Index], nMoveBytes = Index <
m_nFields ? (m_nPointBytes + nFieldBytes) - m_Field_Offset[Index + 1] : 0;
764 #pragma omp parallel for
769 memmove(m_Points[i] + Offset, m_Points[i] + Offset + nFieldBytes, nMoveBytes);
772 m_Points[i] = (
char *)
SG_Realloc(m_Points[i], m_nPointBytes *
sizeof(
char));
779 for(
int iField=Index, Offset=m_Field_Offset[Index]; iField<
m_nFields; iField++)
784 m_Field_Offset[iField] = Offset; Offset +=
m_Field_Size(iField);
812 if( Index < 3 || Index >=
m_nFields || Index == Position )
818 if( Position > Index )
828 if( Position < Index )
835 #pragma omp parallel for
838 memcpy(m_Points[i] + m_Field_Offset[Position], m_Points[i] + m_Field_Offset[Index], Size);
871 #pragma omp parallel for
888 bool CSG_PointCloud::_Set_Field_Value(
char *pPoint,
int iField,
double Value)
890 if( pPoint && iField >= 0 && iField <
m_nFields )
892 pPoint = ((
char *)pPoint) + m_Field_Offset[iField];
927 double CSG_PointCloud::_Get_Field_Value(
char *pPoint,
int iField)
const
929 if( pPoint && iField >= 0 && iField <
m_nFields )
931 pPoint += m_Field_Offset[iField];
955 bool CSG_PointCloud::_Set_Field_Value(
char *pPoint,
int iField,
const SG_Char *Value)
957 if( pPoint && iField >= 0 && iField <
m_nFields && Value )
963 default: {
double d;
return( s.asDouble(d) && _Set_Field_Value(pPoint, iField, d) ); }
967 pPoint += m_Field_Offset[iField];
980 bool CSG_PointCloud::_Get_Field_Value(
char *pPoint,
int iField,
CSG_String &Value)
const
982 if( pPoint && iField >= 0 && iField <
m_nFields )
987 Value.
Printf(
"%f", _Get_Field_Value(pPoint, iField));
1024 p.
x = _Get_Field_Value(m_Cursor, 0);
1025 p.
y = _Get_Field_Value(m_Cursor, 1);
1026 p.
z = _Get_Field_Value(m_Cursor, 2);
1030 p.
x = p.
y = p.
z = 0.;
1043 char *pPoint = m_Points[Index];
1045 p.
x = _Get_Field_Value(pPoint, 0);
1046 p.
y = _Get_Field_Value(pPoint, 1);
1047 p.
z = _Get_Field_Value(pPoint, 2);
1051 p.
x = p.
y = p.
z = 0.;
1060 return( _Set_Field_Value(m_Cursor, 0, Point.
x)
1061 && _Set_Field_Value(m_Cursor, 1, Point.
y)
1062 && _Set_Field_Value(m_Cursor, 2, Point.
z)
1071 return( _Set_Field_Value(m_Points[Index], 0, Point.
x)
1072 && _Set_Field_Value(m_Points[Index], 1, Point.
y)
1073 && _Set_Field_Value(m_Points[Index], 2, Point.
z)
1092 _Set_Field_Value(m_Cursor, 0, x);
1093 _Set_Field_Value(m_Cursor, 1, y);
1094 _Set_Field_Value(m_Cursor, 2, z);
1122 m_Cursor = m_Points[Index];
1126 m_Points[i] = m_Points[j];
1176 bool CSG_PointCloud::_Inc_Array(
void)
1189 bool CSG_PointCloud::_Dec_Array(
void)
1231 for(
int iField=3; iField<
m_nFields; iField++)
1265 Statistics += Value;
1275 char **pPoint = m_Points;
1279 double Value = _Get_Field_Value(*pPoint, Field);
1283 Statistics += Value;
1326 char *Point = m_Points[pShape->
m_Index];
1328 for(
int iField=0; iField<
m_nFields; iField++)
1332 default : _Set_Field_Value(Point, iField, pShape->
asDouble(iField));
break;
1345 char *Point = m_Points[Index];
1347 for(
int iField=0; iField<
m_nFields; iField++)
1351 default: pShape->
Set_Value(iField, _Get_Field_Value(Point, iField));
break;
1373 return( pShape->
m_Index >= 0 ? pShape : NULL );
1377 void CSG_PointCloud::_Shape_Flush(
void)
1381 _Shape_Get(m_Shapes[i].m_Index); m_Shapes[i].m_Index = -1;
1401 CSG_Rect r(Point.
x - Epsilon, Point.
y - Epsilon, Point.
x + Epsilon, Point.
y + Epsilon);
1405 sLong Index = -1;
double Distance = -1.;
1626 m_Points[n] = m_Points[i];
1648 char **pPoint = m_Points;
virtual CSG_Table_Record * Add_Record(CSG_Table_Record *pCopy=NULL)
double asDouble(int Field) const
bool Set_Array(sLong nValues, bool bShrink=true)
virtual bool Assign(CSG_Data_Object *pObject)
CSG_Rect & Assign(double xMin, double yMin, double xMax, double yMax)
CSG_Rect m_Extent_Selected
virtual bool Destroy(void)
bool Get_File(const CSG_String &Name)
sLong Get_Max_Samples(void) const
bool Save(const CSG_String &File, ESG_CRS_Format Format=ESG_CRS_Format::WKT) const
int Printf(const char *Format,...)
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)
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)
@ SG_UI_MSG_STYLE_SUCCESS
virtual bool Del_Field(int iField)
SAGA_API_DLL_EXPORT bool SG_File_Cmp_Extension(const CSG_String &FileName, const CSG_String &Extension)
bool Create(const CSG_Shapes &Shapes)
#define m_Field_Size(FIELD)
#define SG_TABLE_REC_FLAG_Selected
CSG_String ** m_Field_Name
bool Save_MetaData(const CSG_String &FileName)
bool is_NoData_Value(double Value) const
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)
virtual bool Assign(CSG_Data_Object *pSource)
class CSG_Table * Get_Table(void)
virtual bool Add_Field(const CSG_String &Name, TSG_Data_Type Type, int Field=-1)
#define PC_GET_NBYTES(type)
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
TSG_Data_Type * m_Field_Type
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)
CSG_Simple_Statistics ** m_Field_Stats
const SG_Char * asString(int Field, int Decimals=-99) const
const SG_Char * Get_Field_Name(int iField) const
bool Del_Point(sLong Index)
sLong Get_Count(void) const
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
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)
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)
double Get_Maximum(int iField) const
const SG_Char * Get_File_Name(bool bNative=true) const
static bool Get_Header_Content(const CSG_String &FileName, CSG_MetaData &Header)
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_Count(sLong Count)
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]
SAGA_API_DLL_EXPORT bool SG_File_Set_Extension(CSG_String &FileName, const CSG_String &Extension)
bool _Add_Selection(sLong Index)
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
double Get_Minimum(int iField) const
bool SG_UI_Process_Set_Progress(int Position, int Range)
TSG_Point_3D Get_Point(void) const
bool Set_Value(int Field, const CSG_String &Value)
@ POINTCLOUD_FILE_FORMAT_Undefined
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)
virtual CSG_Shape * Get_Selection(sLong Index=0)
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
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)
bool Add_File(const CSG_String &Name, bool bBinary=true)
TSG_Data_Type Get_Field_Type(int iField) const
bool Create(const CSG_Projection &Projection)
virtual bool On_Delete(void)
bool Add_Point(double x, double y, double z)
virtual bool Set_Field_Type(int iField, TSG_Data_Type Type)
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)