• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
  • fitsviewer
fitsoverlay.cpp
Go to the documentation of this file.
1 /* FITS Overlay
2  Copyright (C) 2012 Jasem Mutlaq (mutlaqja@ikarustech.com)
3 
4  This application is free software; you can redistribute it and/or
5  modify it under the terms of the GNU General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  */
10 
11 #include <KTemporaryFile>
12 #include <KIO/CopyJob>
13 #include <KIO/JobUiDelegate>
14 
15 #include "fitsoverlay.h"
16 #include "fitsimage.h"
17 
18 FITSOverlay::FITSOverlay() : downloadJob(0)
19 {
20 }
21 
22 void FITSOverlay::addFITSOverlay(const dms &ra, const dms &dec, const KUrl &imageURL)
23 {
24  m_ImageUrl = imageURL;
25  this->ra = ra;
26  this->dec = dec;
27 
28  // check URL
29  if (!m_ImageUrl.isValid())
30  kDebug() << "URL is malformed: " << m_ImageUrl;
31 
32  // FIXME: check the logic with temporary files. Races are possible
33  {
34  KTemporaryFile tempfile;
35  tempfile.open();
36  file.setFileName( tempfile.fileName() );
37  }// we just need the name and delete the tempfile from disc; if we don't do it, a dialog will be show
38 
39  loadImageFromURL();
40 
41 }
42 
43 FITSOverlay::~FITSOverlay()
44 {
45  if ( downloadJob )
46  {
47  // close job quietly, without emitting a result
48  downloadJob->kill( KJob::Quietly );
49  delete downloadJob;
50  }
51 
52  qDeleteAll(fList);
53 }
54 
55 void FITSOverlay::loadImageFromURL()
56 {
57  KUrl saveURL = KUrl::fromPath( file.fileName() );
58  if (!saveURL.isValid())
59  kDebug()<<"tempfile-URL is malformed\n";
60 
61  qDebug() << "Starting download job for URL " << m_ImageUrl << endl;
62 
63  downloadJob = KIO::copy (m_ImageUrl, saveURL); // starts the download asynchron
64  connect (downloadJob, SIGNAL (result (KJob *)), SLOT (downloadReady (KJob *)));
65 }
66 
67 void FITSOverlay::downloadReady (KJob *job)
68 {
69  // set downloadJob to 0, but don't delete it - the job will be deleted automatically !!!
70  downloadJob = 0;
71 
72  if ( job->error() )
73  {
74  static_cast<KIO::Job*>(job)->ui()->showErrorMessage();
75  return;
76  }
77 
78  file.close(); // to get the newest information from the file and not any information from opening of the file
79 
80  qDebug() << "Download OK , opening image now ..." << endl;
81  if ( file.exists() )
82  {
83  openImage();
84  return;
85  }
86 }
87 
88 void FITSOverlay::openImage()
89 {
90  FOverlay * newFO = new FOverlay;
91 
92  newFO->image_data = new FITSImage(FITS_NORMAL);
93 
94  qDebug() << "Reading FITS file ..." << endl;
95  bool result = newFO->image_data->loadFITS(file.fileName());
96 
97  if (result == false)
98  {
99  delete (newFO->image_data);
100  return;
101  }
102 
103  qDebug() << "Read succesfull, creating fits overlay now ..." << endl;
104 
105  int image_width, image_height;
106  double min,max, bzero, bscale, val;
107  float *image_buffer;
108 
109  image_width = newFO->image_data->getWidth();
110  image_height = newFO->image_data->getHeight();
111  min = newFO->image_data->getMin();
112  max = newFO->image_data->getMax();
113 
114  QImage image(image_width, image_height, QImage::Format_Indexed8);
115 
116  image_buffer = newFO->image_data->getImageBuffer();
117 
118  bscale = 255. / (max - min);
119  bzero = (-min) * (255. / (max - min));
120 
121  image.setNumColors(256);
122  for (int i=0; i < 256; i++)
123  image.setColor(i, qRgb(i,i,i));
124 
125  /* Fill in pixel values using indexed map, linear scale */
126  for (int j = 0; j < image_height; j++)
127  for (int i = 0; i < image_width; i++)
128  {
129  val = image_buffer[j * image_width + i];
130  image.setPixel(i, j, ((int) (val * bscale + bzero)));
131  }
132 
133 
134  newFO->pix.convertFromImage(image);
135  newFO->ra = ra;
136  newFO->dec = dec;
137  newFO->pix_width = image_width;
138  newFO->pix_height = image_height;
139 
140  qDebug() << "Added a new pixmap FITS!" << endl;
141 
142  fList.append(newFO);
143 }
144 
145 bool FITSOverlay::contains(const dms &ra, const dms &dec)
146 {
147  return false;
148 }
149 
150 #include "fitsoverlay.moc"
FOverlay::pix
QPixmap pix
Definition: fitsoverlay.h:29
fitsimage.h
FITSImage
Definition: fitsimage.h:73
FOverlay::ra
dms ra
Definition: fitsoverlay.h:27
fitsoverlay.h
FITS_NORMAL
Definition: fitscommon.h:20
FOverlay::image_data
FITSImage * image_data
Definition: fitsoverlay.h:26
FITSImage::getHeight
long getHeight()
Definition: fitsimage.h:99
FITSImage::getMin
double getMin()
Definition: fitsimage.h:94
FOverlay::pix_width
int pix_width
Definition: fitsoverlay.h:28
dms
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:42
FOverlay
Definition: fitsoverlay.h:24
FITSImage::getImageBuffer
float * getImageBuffer()
Definition: fitsimage.h:91
FITSImage::getWidth
long getWidth()
Definition: fitsimage.h:98
FITSOverlay::FITSOverlay
FITSOverlay()
Definition: fitsoverlay.cpp:18
FITSOverlay::contains
bool contains(const dms &ra, const dms &dec)
Definition: fitsoverlay.cpp:145
FITSOverlay::~FITSOverlay
~FITSOverlay()
Definition: fitsoverlay.cpp:43
FITSOverlay::addFITSOverlay
void addFITSOverlay(const dms &ra, const dms &dec, const KUrl &imageURL)
Definition: fitsoverlay.cpp:22
FITSImage::getMax
double getMax()
Definition: fitsimage.h:95
FOverlay::pix_height
int pix_height
Definition: fitsoverlay.h:28
FITSImage::loadFITS
bool loadFITS(const QString &filename, QProgressDialog *progress=NULL)
Definition: fitsimage.cpp:96
FOverlay::dec
dms dec
Definition: fitsoverlay.h:27
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal