File indexing completed on 2025-01-12 09:34:22
0001 /* HiPS : Hierarchical Progressive Surveys 0002 HiPS is the hierarchical tiling mechanism which allows one to access, visualize and browse seamlessly image, catalogue and cube data. 0003 0004 The KStars HiPS compoenent is used to load and overlay progress surveys from various online catalogs. 0005 0006 SPDX-FileCopyrightText: 2017 Jasem Mutlaq <mutlaqja@ikarustech.com> 0007 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 #include "hipscomponent.h" 0012 0013 #include "Options.h" 0014 #include "skypainter.h" 0015 #include "skymap.h" 0016 0017 HIPSComponent::HIPSComponent(SkyComposite *parent) : SkyComponent(parent) 0018 { 0019 m_ElapsedTimer.start(); 0020 m_RefreshTimer.start(); 0021 } 0022 0023 bool HIPSComponent::selected() 0024 { 0025 return Options::showHIPS(); 0026 } 0027 0028 void HIPSComponent::draw(SkyPainter *skyp) 0029 { 0030 0031 #if !defined(KSTARS_LITE) 0032 if ( (SkyMap::IsSlewing() && !Options::hIPSPanning()) || !selected()) 0033 return; 0034 0035 // If we are tracking and we currently have a focus object or point 0036 // Then no need for re-render every update cycle since that is CPU intensive 0037 // Draw the cached HiPS image for 5000ms. When this expires, render the image again and 0038 // restart the timer. 0039 0040 // Keep track of zoom level and redraw if changes. 0041 ViewParams view = SkyMap::Instance()->projector()->viewParams(); 0042 bool sameView = ( 0043 view.width == m_previousViewParams.width && 0044 view.height == m_previousViewParams.height && 0045 view.zoomFactor == m_previousViewParams.zoomFactor && 0046 view.rotationAngle == m_previousViewParams.rotationAngle && 0047 view.useAltAz == m_previousViewParams.useAltAz 0048 ); 0049 if (sameView && Options::isTracking() && SkyMap::IsFocused()) 0050 { 0051 // We can draw the cache when two conditions are met. 0052 // 1. It is not yet time to re-draw 0053 // 2. Refresh time expired. 0054 if (m_ElapsedTimer.elapsed() < HIPS_REDRAW_PERIOD && m_RefreshTimer.elapsed() > HIPS_REFRESH_PERIOD) 0055 { 0056 skyp->drawHips(true); 0057 } 0058 else 0059 { 0060 skyp->drawHips(false); 0061 m_ElapsedTimer.restart(); 0062 } 0063 0064 // If focus object changes, we reset fresh timer to force drawing of uncached image. 0065 if (SkyMap::Instance()->focusObject() && SkyMap::Instance()->focusObject()->name() != m_LastFocusedObjectName) 0066 { 0067 m_LastFocusedObjectName = SkyMap::Instance()->focusObject()->name(); 0068 m_RefreshTimer.restart(); 0069 } 0070 } 0071 // When slewing or not tracking, render and draw immediately. 0072 else 0073 skyp->drawHips(false); 0074 0075 m_previousViewParams = view; 0076 #else 0077 Q_UNUSED(skyp); 0078 #endif 0079 }