ConstellationMgr.cpp   ConstellationMgr.cpp 
skipping to change at line 24 skipping to change at line 24
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#include <vector> #include <vector>
#include <QDebug> #include <QDebug>
#include <QFile> #include <QFile>
#include <QImageReader>
#include <QSettings> #include <QSettings>
#include <QRegExp> #include <QRegExp>
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
#include "ConstellationMgr.hpp" #include "ConstellationMgr.hpp"
#include "Constellation.hpp" #include "Constellation.hpp"
#include "StarMgr.hpp" #include "StarMgr.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelTextureMgr.hpp" #include "renderer/StelRenderer.hpp"
#include "StelProjector.hpp" #include "StelProjector.hpp"
#include "StelObjectMgr.hpp" #include "StelObjectMgr.hpp"
#include "StelLocaleMgr.hpp" #include "StelLocaleMgr.hpp"
#include "StelSkyCultureMgr.hpp" #include "StelSkyCultureMgr.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelPainter.hpp"
#include "StelSkyDrawer.hpp" #include "StelSkyDrawer.hpp"
using namespace std; using namespace std;
// constructor which loads all data from appropriate files // constructor which loads all data from appropriate files
ConstellationMgr::ConstellationMgr(StarMgr *_hip_stars) ConstellationMgr::ConstellationMgr(StarMgr *_hip_stars)
: hipStarMgr(_hip_stars), : hipStarMgr(_hip_stars),
artFadeDuration(2.0f),
artIntensity(0.5f),
artDisplayed(0), artDisplayed(0),
boundariesDisplayed(0), boundariesDisplayed(0),
linesDisplayed(0), linesDisplayed(0),
namesDisplayed(0) namesDisplayed(0)
{ {
setObjectName("ConstellationMgr"); setObjectName("ConstellationMgr");
Q_ASSERT(hipStarMgr); Q_ASSERT(hipStarMgr);
isolateSelected = false; isolateSelected = false;
asterFont.setPixelSize(15); asterFont.setPixelSize(15);
} }
skipping to change at line 152 skipping to change at line 154
// Translate constellation names for the new sky culture // Translate constellation names for the new sky culture
updateI18n(); updateI18n();
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
qWarning() << "ERROR: while loading new constellation data f or sky culture " qWarning() << "ERROR: while loading new constellation data f or sky culture "
<< skyCultureDir << ", reason: " << e.what() << endl ; << skyCultureDir << ", reason: " << e.what() << endl ;
} }
// TODO: do we need to have an else { clearBoundaries(); } ? // TODO: do we need to have an else { clearBoundaries(); } ?
if (skyCultureDir.startsWith("western")) // load constellation boundaries
try
{ {
try loadBoundaries(StelFileMgr::findFile("skycultures/" + skyCul
{ tureDir + "/constellations_boundaries.dat"));
loadBoundaries(StelFileMgr::findFile("data/constella }
tions_boundaries.dat")); catch (std::runtime_error& e)
} {
catch (std::runtime_error& e) qWarning() << "ERROR loading constellation boundaries file:
{ " << e.what();
qWarning() << "ERROR loading constellation boundarie
s file: " << e.what();
}
} }
lastLoadedSkyCulture = skyCultureDir; lastLoadedSkyCulture = skyCultureDir;
} }
void ConstellationMgr::setStelStyle(const QString& section) void ConstellationMgr::setStelStyle(const QString& section)
{ {
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
// Load colors from config file // Load colors from config file
skipping to change at line 425 skipping to change at line 425
// Draw loading bar // Draw loading bar
// lb.SetMessage(q_("Loading Constellation Art: %1/%2").arg(cur rentLineNumber).arg(totalRecords)); // lb.SetMessage(q_("Loading Constellation Art: %1/%2").arg(cur rentLineNumber).arg(totalRecords));
// lb.Draw((float)(currentLineNumber)/totalRecords); // lb.Draw((float)(currentLineNumber)/totalRecords);
cons = NULL; cons = NULL;
cons = findFromAbbreviation(shortname); cons = findFromAbbreviation(shortname);
if (!cons) if (!cons)
{ {
qWarning() << "ERROR in constellation art file at li ne" << currentLineNumber << "for culture" << cultureName qWarning() << "ERROR in constellation art file at li ne" << currentLineNumber << "for culture" << cultureName
<< "constellation" << shortname < < "unknown"; << "constellation" << shortname << "unkno wn";
} }
else else
{ {
QString texturePath(texfile); QString texturePath(texfile);
try try
{ {
texturePath = StelFileMgr::findFile("skycult ures/"+cultureName+"/"+texfile); texturePath = StelFileMgr::findFile("skycult ures/"+cultureName+"/"+texfile);
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
skipping to change at line 451 skipping to change at line 451
try try
{ {
texturePath = StelFileMgr::findFile( QString("textures/")+texfile); texturePath = StelFileMgr::findFile( QString("textures/")+texfile);
} }
catch(std::exception& e2) catch(std::exception& e2)
{ {
qWarning() << "ERROR: could not find texture, " << texfile << ": " << e2.what(); qWarning() << "ERROR: could not find texture, " << texfile << ": " << e2.what();
} }
} }
cons->artTexture = StelApp::getInstance().getTexture Manager().createTextureThread(texturePath); cons->artTexturePath = texturePath;
int texSizeX, texSizeY; // This is one part that is less convenient than bef
if (cons->artTexture==NULL || !cons->artTexture->get ore the GL refactor
Dimensions(texSizeX, texSizeY)) // (due to the StelRenderer not being globally (Stel
Core) available.
// We need to determine texture size manually here.
// Try to get the size from the file without loading
data
QImageReader im(texturePath);
if (!im.canRead())
{ {
qWarning() << "Texture dimension not availab le"; qWarning() << "Texture dimensions not availa ble";
} }
const QSize size = im.canRead() ? im.size() : QSize(
64, 64);
const int texSizeX = size.width();
const int texSizeY = size.height();
StelCore* core = StelApp::getInstance().getCore(); StelCore* core = StelApp::getInstance().getCore();
Vec3d s1 = hipStarMgr->searchHP(hp1)->getJ2000Equato rialPos(core); Vec3d s1 = hipStarMgr->searchHP(hp1)->getJ2000Equato rialPos(core);
Vec3d s2 = hipStarMgr->searchHP(hp2)->getJ2000Equato rialPos(core); Vec3d s2 = hipStarMgr->searchHP(hp2)->getJ2000Equato rialPos(core);
Vec3d s3 = hipStarMgr->searchHP(hp3)->getJ2000Equato rialPos(core); Vec3d s3 = hipStarMgr->searchHP(hp3)->getJ2000Equato rialPos(core);
// To transform from texture coordinate to 2d coordi nate we need to find X with XA = B // To transform from texture coordinate to 2d coordi nate we need to find X with XA = B
// A formed of 4 points in texture coordinate, B for med with 4 points in 3d coordinate // A formed of 4 points in texture coordinate, B for med with 4 points in 3d coordinate
// We need 3 stars and the 4th point is deduced from the other to get an normal base // We need 3 stars and the 4th point is deduced from the other to get an normal base
// X = B inv(A) // X = B inv(A)
Vec3d s4 = s1 + ((s2 - s1) ^ (s3 - s1)); Vec3d s4 = s1 + ((s2 - s1) ^ (s3 - s1));
Mat4d B(s1[0], s1[1], s1[2], 1, s2[0], s2[1], s2[2], Mat4d B(s1[0], s1[1], s1[2], 1,
1, s3[0], s3[1], s3[2], 1, s4[0], s4[1], s4[2], 1); s2[0], s2[1], s2[2], 1,
Mat4d A(x1, texSizeY - y1, 0.f, 1.f, x2, texSizeY - s3[0], s3[1], s3[2], 1,
y2, 0.f, 1.f, x3, texSizeY - y3, 0.f, 1.f, x1, texSizeY - y1, texSizeX, 1.f s4[0], s4[1], s4[2], 1);
); Mat4d A(x1, texSizeY - y1, 0.f, 1.f,
x2, texSizeY - y2, 0.f, 1.f,
x3, texSizeY - y3, 0.f, 1.f,
x1, texSizeY - y1, texSizeX, 1.f);
Mat4d X = B * A.inverse(); Mat4d X = B * A.inverse();
// Tesselate on the plan assuming a tangential proje cons->texCoordTo3D = Mat4f(X[0] , X[1] , X[2] , X
ction for the image [3],
static const int nbPoints=5; X[4] , X[5] , X[6] , X
QVector<Vec2f> texCoords; [7],
texCoords.reserve(nbPoints*nbPoints*6); X[8] , X[9] , X[10] , X
for (int j=0;j<nbPoints;++j) [11],
{ X[12] , X[13] , X[14] , X
for (int i=0;i<nbPoints;++i) [15]);
{
texCoords << Vec2f(((float)i)/nbPoin
ts, ((float)j)/nbPoints);
texCoords << Vec2f(((float)i+1.f)/nb
Points, ((float)j)/nbPoints);
texCoords << Vec2f(((float)i)/nbPoin
ts, ((float)j+1.f)/nbPoints);
texCoords << Vec2f(((float)i+1.f)/nb
Points, ((float)j)/nbPoints);
texCoords << Vec2f(((float)i+1.f)/nb
Points, ((float)j+1.f)/nbPoints);
texCoords << Vec2f(((float)i)/nbPoin
ts, ((float)j+1.f)/nbPoints);
}
}
QVector<Vec3d> contour;
contour.reserve(texCoords.size());
foreach (const Vec2f& v, texCoords)
contour << X * Vec3d(v[0]*texSizeX, v[1]*tex
SizeY, 0.);
cons->artPolygon.vertex=contour;
cons->artPolygon.texCoords=texCoords;
cons->artPolygon.primitiveType=StelVertexArray::Tria
ngles;
Vec3d tmp(X * Vec3d(0.5*texSizeX, 0.5*texSizeY, 0.)) ; Vec3d tmp(X * Vec3d(0.5 * texSizeX, 0.5 * texSizeY, 0.));
tmp.normalize(); tmp.normalize();
Vec3d tmp2(X * Vec3d(0., 0., 0.)); Vec3d tmp2(X * Vec3d(0., 0., 0.));
tmp2.normalize(); tmp2.normalize();
cons->boundingCap.n=tmp; cons->boundingCap.n=tmp;
cons->boundingCap.d=tmp*tmp2; cons->boundingCap.d=tmp*tmp2;
++readOk; ++readOk;
} }
} }
qDebug() << "Loaded" << readOk << "/" << totalRecords << "constellat ion art records successfully for culture" << cultureName; qDebug() << "Loaded" << readOk << "/" << totalRecords << "constellat ion art records successfully for culture" << cultureName;
fic.close(); fic.close();
} }
void ConstellationMgr::draw(StelCore* core) void ConstellationMgr::draw(StelCore* core, class StelRenderer* renderer)
{ {
const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000) const StelProjectorP projector = core->getProjection(StelCore::Frame
; J2000);
StelPainter sPainter(prj); drawLines(renderer, projector, core);
sPainter.setFont(asterFont); drawNames(renderer, projector, asterFont);
drawLines(sPainter, core); drawArt(renderer, projector);
drawNames(sPainter); drawBoundaries(renderer, projector);
drawArt(sPainter);
drawBoundaries(sPainter);
} }
// Draw constellations art textures // Draw constellations art textures
void ConstellationMgr::drawArt(StelPainter& sPainter) const void ConstellationMgr::drawArt(StelRenderer* renderer, StelProjectorP proje ctor) const
{ {
glBlendFunc(GL_ONE, GL_ONE); renderer->setBlendMode(BlendMode_Add);
sPainter.enableTexture2d(true);
glEnable(GL_BLEND);
glEnable(GL_CULL_FACE);
vector < Constellation * >::const_iterator iter; vector < Constellation * >::const_iterator iter;
SphericalRegionP region = sPainter.getProjector()->getViewportConvex Polygon(); SphericalRegionP region = projector->getViewportConvexPolygon();
for (iter = asterisms.begin(); iter != asterisms.end(); ++iter) for (iter = asterisms.begin(); iter != asterisms.end(); ++iter)
{ {
(*iter)->drawArtOptim(sPainter, *region); Constellation* cons = *iter;
}
if(NULL == cons->artTexture && !cons->artTexturePath.isEmpty
())
{
cons->artTexture = renderer->createTexture(cons->art
TexturePath);
}
if(NULL == cons->artVertices)
{
// Tesselate on the plane assuming a tangential proj
ection for the image
const int resolution = 5;
cons->generateArtVertices(renderer, resolution);
}
glDisable(GL_CULL_FACE); cons->drawArtOptim(renderer, projector, *region);
}
} }
// Draw constellations lines // Draw constellations lines
void ConstellationMgr::drawLines(StelPainter& sPainter, const StelCore* cor e) const void ConstellationMgr::drawLines(StelRenderer* renderer, StelProjectorP pro jector, const StelCore* core) const
{ {
sPainter.enableTexture2d(false); renderer->setBlendMode(BlendMode_Alpha);
glEnable(GL_BLEND); const SphericalCap& viewportHalfspace = projector->getBoundingCap();
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
const SphericalCap& viewportHalfspace = sPainter.getProjector()->get
BoundingCap();
vector < Constellation * >::const_iterator iter; vector < Constellation * >::const_iterator iter;
for (iter = asterisms.begin(); iter != asterisms.end(); ++iter) for (iter = asterisms.begin(); iter != asterisms.end(); ++iter)
{ {
(*iter)->drawOptim(sPainter, core, viewportHalfspace); (*iter)->drawOptim(renderer, projector, core, viewportHalfsp ace);
} }
} }
// Draw the names of all the constellations // Draw the names of all the constellations
void ConstellationMgr::drawNames(StelPainter& sPainter) const void ConstellationMgr::drawNames(StelRenderer* renderer, StelProjectorP pro jector, QFont& font) const
{ {
glEnable(GL_BLEND); renderer->setBlendMode(BlendMode_Alpha);
sPainter.enableTexture2d(true);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
vector < Constellation * >::const_iterator iter; vector < Constellation * >::const_iterator iter;
for (iter = asterisms.begin(); iter != asterisms.end(); iter++) for (iter = asterisms.begin(); iter != asterisms.end(); iter++)
{ {
// Check if in the field of view // Check if in the field of view
if (sPainter.getProjector()->projectCheck((*iter)->XYZname, if (projector->projectCheck((*iter)->XYZname, (*iter)->XYnam
(*iter)->XYname)) e))
(*iter)->drawName(sPainter); {
(*iter)->drawName(renderer, font);\
}
} }
} }
Constellation *ConstellationMgr::isStarIn(const StelObject* s) const Constellation *ConstellationMgr::isStarIn(const StelObject* s) const
{ {
vector < Constellation * >::const_iterator iter; vector < Constellation * >::const_iterator iter;
for (iter = asterisms.begin(); iter != asterisms.end(); ++iter) for (iter = asterisms.begin(); iter != asterisms.end(); ++iter)
{ {
// Check if the star is in one of the constellation // Check if the star is in one of the constellation
if ((*iter)->isStarIn(s)) if ((*iter)->isStarIn(s))
skipping to change at line 1094 skipping to change at line 1091
i++; i++;
} }
dataFile.close(); dataFile.close();
qDebug() << "Loaded" << i << "constellation boundary segments"; qDebug() << "Loaded" << i << "constellation boundary segments";
delete points; delete points;
return true; return true;
} }
void ConstellationMgr::drawBoundaries(StelPainter& sPainter) const void ConstellationMgr::drawBoundaries(StelRenderer* renderer, StelProjector P projector) const
{ {
sPainter.enableTexture2d(false); renderer->setBlendMode(BlendMode_None);
glDisable(GL_BLEND);
#ifndef USE_OPENGL_ES2
glLineStipple(2, 0x3333);
glEnable(GL_LINE_STIPPLE);
#endif
vector < Constellation * >::const_iterator iter; vector < Constellation * >::const_iterator iter;
for (iter = asterisms.begin(); iter != asterisms.end(); ++iter) for (iter = asterisms.begin(); iter != asterisms.end(); ++iter)
{ {
(*iter)->drawBoundaryOptim(sPainter); (*iter)->drawBoundaryOptim(renderer, projector);
} }
#ifndef USE_OPENGL_ES2
glDisable(GL_LINE_STIPPLE);
#endif
} }
StelObjectP ConstellationMgr::searchByNameI18n(const QString& nameI18n) con st StelObjectP ConstellationMgr::searchByNameI18n(const QString& nameI18n) con st
{ {
QString objw = nameI18n.toUpper(); QString objw = nameI18n.toUpper();
vector <Constellation*>::const_iterator iter; vector <Constellation*>::const_iterator iter;
for (iter = asterisms.begin(); iter != asterisms.end(); ++iter) for (iter = asterisms.begin(); iter != asterisms.end(); ++iter)
{ {
QString objwcap = (*iter)->nameI18.toUpper(); QString objwcap = (*iter)->nameI18.toUpper();
skipping to change at line 1160 skipping to change at line 1150
QString constw = (*iter)->getNameI18n().mid(0, objw.size()). toUpper(); QString constw = (*iter)->getNameI18n().mid(0, objw.size()). toUpper();
if (constw==objw) if (constw==objw)
{ {
result << (*iter)->getNameI18n(); result << (*iter)->getNameI18n();
if (result.size()==maxNbItem) if (result.size()==maxNbItem)
return result; return result;
} }
} }
return result; return result;
} }
QStringList ConstellationMgr::listAllObjects(bool inEnglish) const
{
QStringList result;
if (inEnglish)
{
foreach(Constellation* constellation, asterisms)
{
result << constellation->getEnglishName();
}
}
else
{
foreach(Constellation* constellation, asterisms)
{
result << constellation->getNameI18n();
}
}
return result;
}
 End of changes. 32 change blocks. 
102 lines changed or deleted 89 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/