3
// Copyright (C) 2005-2024, the Celestia Development Team
6
// Author: Toti <root@totibox>, (C) 2005
8
// This program is free software; you can redistribute it and/or
9
// modify it under the terms of the GNU General Public License
10
// as published by the Free Software Foundation; either version 2
11
// of the License, or (at your option) any later version.
19
#include <celutil/gettext.h>
20
#include <celutil/logger.h>
23
namespace engine = celestia::engine;
25
using celestia::util::GetLogger;
27
DSODatabase::~DSODatabase() = default;
29
DSODatabase::DSODatabase(std::unique_ptr<engine::DSOOctree>&& octreeRoot,
30
std::unique_ptr<NameDatabase>&& namesDB,
31
std::vector<std::uint32_t>&& catalogNumberIndex,
33
m_octreeRoot(std::move(octreeRoot)),
34
m_namesDB(std::move(namesDB)),
35
m_catalogNumberIndex(std::move(catalogNumberIndex)),
36
m_avgAbsMag(avgAbsMag)
41
DSODatabase::find(const AstroCatalog::IndexNumber catalogNumber) const
43
auto it = std::lower_bound(m_catalogNumberIndex.begin(),
44
m_catalogNumberIndex.end(),
46
[this](std::uint32_t idx, AstroCatalog::IndexNumber catNum)
48
return (*m_octreeRoot)[idx]->getIndex() < catNum;
51
if (it == m_catalogNumberIndex.end())
54
DeepSkyObject* dso = (*m_octreeRoot)[*it].get();
55
return dso->getIndex() == catalogNumber ? dso : nullptr;
59
DSODatabase::find(std::string_view name, bool i18n) const
64
AstroCatalog::IndexNumber catalogNumber = m_namesDB->getCatalogNumberByName(name, i18n);
65
return catalogNumber == AstroCatalog::InvalidIndex
67
: find(catalogNumber);
71
DSODatabase::getCompletion(std::vector<std::string>& completion, std::string_view name) const
73
// only named DSOs are supported by completion.
75
m_namesDB->getCompletion(completion, name);
79
DSODatabase::getDSOName(const DeepSkyObject* dso, [[maybe_unused]] bool i18n) const
81
AstroCatalog::IndexNumber catalogNumber = dso->getIndex();
83
auto iter = m_namesDB->getFirstNameIter(catalogNumber);
84
if (iter == m_namesDB->getFinalNameIter())
90
const char* local = D_(iter->second.c_str());
91
if (iter->second != local)
100
DSODatabase::getDSONameList(const DeepSkyObject* dso, const unsigned int maxNames) const
102
std::string dsoNames;
104
auto catalogNumber = dso->getIndex();
105
auto iter = m_namesDB->getFirstNameIter(catalogNumber);
107
unsigned int count = 0;
108
while (iter != m_namesDB->getFinalNameIter() && iter->first == catalogNumber && count < maxNames)
111
dsoNames.append(" / ");
113
dsoNames.append(D_(iter->second.c_str()));
122
DSODatabase::findVisibleDSOs(engine::DSOHandler& dsoHandler,
123
const Eigen::Vector3d& obsPos,
124
const Eigen::Quaternionf& obsOrient,
127
float limitingMag) const
129
// Compute the bounding planes of an infinite view frustum
130
std::array<Eigen::Hyperplane<double, 3>, 5> frustumPlanes;
132
Eigen::Quaterniond obsOrientd = obsOrient.cast<double>();
133
Eigen::Matrix3d rot = obsOrientd.toRotationMatrix().transpose();
134
double h = std::tan(fovY / 2);
135
double w = h * aspectRatio;
137
std::array<Eigen::Vector3d, 5> planeNormals
139
Eigen::Vector3d( 0, 1, -h),
140
Eigen::Vector3d( 0, -1, -h),
141
Eigen::Vector3d( 1, 0, -w),
142
Eigen::Vector3d(-1, 0, -w),
143
Eigen::Vector3d( 0, 0, -1),
146
for (int i = 0; i < 5; ++i)
148
planeNormals[i] = rot * planeNormals[i].normalized();
149
frustumPlanes[i] = Eigen::Hyperplane<double, 3>(planeNormals[i], obsPos);
152
engine::DSOOctreeVisibleObjectsProcessor processor(&dsoHandler,
157
m_octreeRoot->processDepthFirst(processor);
161
DSODatabase::findCloseDSOs(engine::DSOHandler& dsoHandler,
162
const Eigen::Vector3d& obsPos,
165
engine::DSOOctreeCloseObjectsProcessor processor(&dsoHandler,
169
m_octreeRoot->processDepthFirst(processor);