52 #ifndef __PCL_StarDatabaseFile_h
53 #define __PCL_StarDatabaseFile_h
77 class PCL_CLASS StarDatabaseFile;
141 float medianLeafLength = 0;
156 double centerDec = 0;
158 float magnitudeLow = -1.5;
160 float magnitudeHigh = 26;
175 double timeTotal = 0;
178 double timeUncompress = 0;
179 double timeDecode = 0;
192 template <
class StarData>
203 excessCount = rejectCount = 0u;
204 timeTotal = timeIO = 0;
206 timeUncompress = timeDecode = 0;
228 uint64 blockOffsetAndLeafFlag;
230 uint32 compressedBlockSize;
238 uint32 compressedBlockSize;
254 union { ChildNodeData child;
255 LeafNodeData leaf; } index;
259 static_assert(
sizeof( *
this ) == 48,
"Invalid sizeof( XPSD::IndexNode )" );
260 static_assert(
sizeof( ChildNodeData ) == 16,
"Invalid sizeof( XPSD::ChildNodeData )" );
261 static_assert(
sizeof( LeafNodeData ) == 16,
"Invalid sizeof( XPSD::LeafNodeData )" );
262 static_assert(
sizeof( index ) == 16,
"Invalid sizeof( XPSD::IndexNode::index )" );
264 index.child.nw = index.child.ne = index.child.sw = index.child.se = 0;
270 return (index.leaf.blockOffsetAndLeafFlag & 0x8000000000000000) != 0;
272 return index.leaf.leafFlag;
276 uint64 BlockOffset()
const
279 return index.leaf.blockOffsetAndLeafFlag & 0x7FFFFFFFFFFFFFFF;
281 return index.leaf.blockOffset;
287 return index.leaf.blockSize;
290 uint32 CompressedBlockSize()
const
292 return index.leaf.compressedBlockSize;
296 static double Distance(
double lon1,
double lat1,
double lon2,
double lat2 )
301 static double CrossTrackDistance(
double lon,
double lat,
double lon1,
double lat1,
double lon2,
double lat2 )
309 return c.Angle3D( p ) -
Pi()/2;
312 static bool WithinExtent(
double lon,
double lat,
double lon1,
double lat1,
double lon2,
double lat2 )
316 return lon == lon1 && lat == lat1;
323 Vector d10 = n0 - n1, d12 = n2 - n1;
324 Vector d20 = n0 - n2, d21 = n1 - n2;
327 if ( d10 * d12 >= 0 )
328 if ( d20 * d21 >= 0 )
329 return (n0 * n1) >= 0 && (n0 * n2) >= 0;
334 static bool InRegion(
double lon,
double lat,
335 double lon1,
double lat1,
double lon2,
double lat2,
336 double lon3,
double lat3,
double lon4,
double lat4 )
343 return Abs( v1.Angle3D( v2, p ) + v2.Angle3D( v3, p ) + v3.Angle3D( v4, p ) + v4.Angle3D( v1, p ) ) >
Pi();
346 enum projection_type { Equirectangular, TransverseEquirectangular, AzimuthalEquidistant };
348 static String ProjectionToAttributeValue(
int );
349 static projection_type ProjectionFromAttributeValue(
const String& );
355 IndexTree( StarDatabaseFile* parent,
356 projection_type projection,
double centerRA,
double centerDec,
357 const Array<IndexNode>& nodes )
359 , m_projection( projection )
360 , m_centerRA( centerRA )
361 , m_centerDec( centerDec )
366 IndexTree() =
default;
367 IndexTree(
const IndexTree& ) =
default;
369 void Project(
double& x,
double& y,
double ra,
double dec )
const
371 switch( m_projection )
374 case Equirectangular:
378 case AzimuthalEquidistant:
382 double r = 90 -
Abs( dec );
387 case TransverseEquirectangular:
400 void Unproject(
double& ra,
double& dec,
double x,
double y )
const
402 switch( m_projection )
405 case Equirectangular:
409 case AzimuthalEquidistant:
416 if ( m_centerDec < 0 )
419 case TransverseEquirectangular:
429 if ( m_centerDec < 0 )
436 void Search(
double ra,
double dec,
double r,
void* searchData )
const
438 SearchRecursive( 0, ra, dec, r, searchData );
443 StarDatabaseFile* m_parent =
nullptr;
444 projection_type m_projection = Equirectangular;
445 double m_centerRA = 0;
446 double m_centerDec = 0;
447 Array<IndexNode> m_nodes;
449 void GetNodeBounds(
double& ra1,
double& dec1,
double& ra2,
double& dec2,
450 double& ra3,
double& dec3,
double& ra4,
double& dec4,
const IndexNode& node )
const
452 Unproject( ra1, dec1, node.x0, node.y0 );
453 Unproject( ra2, dec2, node.x1, node.y0 );
454 Unproject( ra3, dec3, node.x1, node.y1 );
455 Unproject( ra4, dec4, node.x0, node.y1 );
458 bool InNodeRegion(
double ra,
double dec,
const IndexNode& node )
const
460 double ra1, dec1, ra2, dec2, ra3, dec3, ra4, dec4;
461 GetNodeBounds( ra1, dec1, ra2, dec2, ra3, dec3, ra4, dec4, node );
462 return InRegion( ra, dec, ra1, dec1, ra2, dec2, ra3, dec3, ra4, dec4 );
465 bool IntersectsNodeRegion(
double ra,
double dec,
double r,
const IndexNode& node )
const
467 double ra1, dec1, ra2, dec2, ra3, dec3, ra4, dec4;
468 GetNodeBounds( ra1, dec1, ra2, dec2, ra3, dec3, ra4, dec4, node );
469 double rr =
Rad( r );
470 return InRegion( ra, dec, ra1, dec1, ra2, dec2, ra3, dec3, ra4, dec4 )
471 ||
Distance( ra, dec, ra1, dec1 ) < rr
472 ||
Distance( ra, dec, ra2, dec2 ) < rr
473 ||
Distance( ra, dec, ra3, dec3 ) < rr
474 ||
Distance( ra, dec, ra4, dec4 ) < rr
475 || WithinExtent( ra, dec, ra1, dec1, ra2, dec2 ) && CrossTrackDistance( ra, dec, ra1, dec1, ra2, dec2 ) < rr
476 || WithinExtent( ra, dec, ra2, dec2, ra3, dec3 ) && CrossTrackDistance( ra, dec, ra2, dec2, ra3, dec3 ) < rr
477 || WithinExtent( ra, dec, ra3, dec3, ra4, dec4 ) && CrossTrackDistance( ra, dec, ra3, dec3, ra4, dec4 ) < rr
478 || WithinExtent( ra, dec, ra4, dec4, ra1, dec1 ) && CrossTrackDistance( ra, dec, ra4, dec4, ra1, dec1 ) < rr;
482 void SearchRecursive(
uint32 nodeIndex,
double ra,
double dec,
double r,
void* searchData )
const;
484 friend class StarDatabaseFile;
591 return m_file.IsOpen();
600 return m_file.FilePath();
610 return m_magnitudeLow;
620 return m_magnitudeHigh;
694 float magnitudeLow,
float magnitudeHigh,
705 float m_magnitudeLow = 0;
706 float m_magnitudeHigh = 0;
708 uint64 m_dataPosition = 0;
712 virtual void LoadData(
void* block,
uint64 offset,
uint32 size,
void* searchData )
const
716 m_file.
Read( block, size );
721 virtual void Uncompress(
ByteArray& block,
uint32 uncompressedSize,
void* searchData )
const
726 block = m_compression->Uncompress( block, uncompressedSize );
727 reinterpret_cast<SearchDataBase*
>( searchData )->timeUncompress += T();
731 virtual void GetEncodedData(
const ByteArray&,
const XPSD::IndexTree&,
const XPSD::IndexNode&,
void* )
const = 0;
733 friend class XPSD::IndexTree;
739 XPSD::IndexTree::SearchRecursive(
uint32 nodeIndex,
double ra,
double dec,
double r,
void* searchData )
const
741 const IndexNode& node = m_nodes[nodeIndex];
742 if ( IntersectsNodeRegion( ra, dec, r, node ) )
747 m_parent->LoadData( block.
Begin(), node.BlockOffset(), node.CompressedBlockSize(), searchData );
748 if ( node.CompressedBlockSize() != node.BlockSize() )
749 m_parent->Uncompress( block, node.BlockSize(), searchData );
750 m_parent->GetEncodedData( block, *
this, node, searchData );
754 if ( node.index.child.nw != 0 )
755 SearchRecursive( node.index.child.nw, ra, dec, r, searchData );
756 if ( node.index.child.ne != 0 )
757 SearchRecursive( node.index.child.ne, ra, dec, r, searchData );
758 if ( node.index.child.sw != 0 )
759 SearchRecursive( node.index.child.sw, ra, dec, r, searchData );
760 if ( node.index.child.se != 0 )
761 SearchRecursive( node.index.child.se, ra, dec, r, searchData );
A smart pointer with exclusive object ownership and optional automatic object destruction.
Dynamic array of 8-bit unsigned integers.
Abstract base class of data compression algorithm implementations.
High-resolution time stamp.
A platform-independent interface to the local file system.
virtual void Read(void *buffer, fsize_type len)
virtual void SetPosition(fpos_type pos)
static GenericVector FromSpherical(double slon, double clon, double slat, double clat)
double Angle3D(const GenericVector &v) const noexcept
GenericVector Cross(const GenericVector &v2) const
Point source and star catalog database files (XPSD format).
virtual ~StarDatabaseFile() noexcept(false)
const XPSD::Metadata & Metadata() const
StarDatabaseFile()=default
static void Serialize(const String &filePath, const XPSD::Metadata &metadata, const XPSD::Statistics &statistics, float magnitudeLow, float magnitudeHigh, const Array< XPSD::IndexTree > &index, const ByteArray &data, const Compression *compression=nullptr, const String ¶meters=String())
StarDatabaseFile(StarDatabaseFile &&)=default
const XPSD::Statistics & Statistics() const
StarDatabaseFile(const StarDatabaseFile &)=delete
void Open(const String &filePath)
float MagnitudeLow() const
const String & FilePath() const
float MagnitudeHigh() const
StarDatabaseFile(const String &filePath)
An instant in any timescale.
64-bit floating point real vector.
Base class of point source database implementations.
Complex< T > Sqrt(const Complex< T > &c) noexcept
T Abs(const Complex< T > &c) noexcept
Complex< T > Cos(const Complex< T > &c) noexcept
void SinCos(T x, T &sx, T &cx) noexcept
constexpr T ArcTan(T x) noexcept
constexpr T ArcSin(T x) noexcept
constexpr T Rad(T x) noexcept
constexpr T Deg(T x) noexcept
constexpr long double Pi() noexcept
unsigned long long uint64
FI1 Search(FI1 i1, FI1 j1, FI2 i2, FI2 j2) noexcept
distance_type Distance(FI i, FI j)
Parameters and output instrumentation data for catalog search operations.
Data items and parameters for catalog search operations.
void ResetSearchResults()
Array< StarData > stars
The list of stars found by the search operation (output data).
Structural and statistical data about an XPSD database file.