From 218864d6a37253fd44608ddf107fc48e4c865cc5 Mon Sep 17 00:00:00 2001 From: Hugo Van Ruyskensvelde Date: Thu, 2 Dec 2021 13:22:36 +0100 Subject: [PATCH] Oblique Mercator projection for VIIRS DNB images. --- core/dialogpreferences.ui | 110 ++++++- core/equirectangular.cpp | 3 +- core/formephem.ui | 1 + core/formimage.cpp | 1 + core/formtoolbox.cpp | 23 +- core/formtoolbox.ui | 10 +- core/generalverticalperspective.cpp | 1 - core/globe.cpp | 86 ++++- core/globe.h | 3 + core/main.cpp | 11 +- core/mainwindow.cpp | 2 +- core/obliquemercator.cpp | 56 +++- core/pixgeoconversion.cpp | 11 +- core/segmentlistviirsdnb.cpp | 48 +++ core/segmentlistviirsdnb.h | 2 + core/segmentlistviirsm.cpp | 6 +- core/segmentviirsdnb.cpp | 471 +++++++++++++++++----------- core/segmentviirsdnb.h | 2 + core/segmentviirsm.cpp | 6 +- core/segmentviirsm.h | 6 +- 20 files changed, 628 insertions(+), 231 deletions(-) diff --git a/core/dialogpreferences.ui b/core/dialogpreferences.ui index 960f7bc..8d7c759 100644 --- a/core/dialogpreferences.ui +++ b/core/dialogpreferences.ui @@ -167,7 +167,7 @@ - 0 + 4 @@ -317,6 +317,12 @@ + + + 100 + 0 + + 50 @@ -344,6 +350,12 @@ + + + 100 + 0 + + 50 @@ -357,6 +369,12 @@ + + + 100 + 0 + + 50 @@ -370,6 +388,12 @@ + + + 100 + 0 + + 50 @@ -383,6 +407,12 @@ + + + 100 + 0 + + 50 @@ -417,6 +447,12 @@ + + + 100 + 0 + + 50 @@ -430,6 +466,12 @@ + + + 100 + 0 + + 50 @@ -457,6 +499,12 @@ + + + 100 + 0 + + 50 @@ -625,6 +673,12 @@ + + + 100 + 0 + + 50 @@ -638,6 +692,12 @@ + + + 100 + 0 + + 50 @@ -651,6 +711,12 @@ + + + 100 + 0 + + 50 @@ -668,6 +734,12 @@ + + + 100 + 0 + + 80 @@ -681,6 +753,12 @@ + + + 100 + 0 + + 80 @@ -694,6 +772,12 @@ + + + 100 + 0 + + 80 @@ -721,6 +805,12 @@ + + + 100 + 0 + + 80 @@ -734,6 +824,12 @@ + + + 100 + 0 + + 80 @@ -768,6 +864,12 @@ + + + 100 + 0 + + 80 @@ -781,6 +883,12 @@ + + + 100 + 0 + + 80 diff --git a/core/equirectangular.cpp b/core/equirectangular.cpp index ed65600..2f2c118 100644 --- a/core/equirectangular.cpp +++ b/core/equirectangular.cpp @@ -36,7 +36,8 @@ void Equirectangular::Initialize(int imwidth, int imheight) lat_array[i] = 90.0 - (i + 0.5) * lat_del; - initializeProjectionCoord(); + + //initializeProjectionCoord(); } diff --git a/core/formephem.ui b/core/formephem.ui index 52dea41..118c2af 100644 --- a/core/formephem.ui +++ b/core/formephem.ui @@ -230,6 +230,7 @@ 10 + false diff --git a/core/formimage.cpp b/core/formimage.cpp index 6b1b48f..9b9fc87 100644 --- a/core/formimage.cpp +++ b/core/formimage.cpp @@ -204,6 +204,7 @@ void FormImage::setPixmapToLabel(bool settoolboxbuttons) case IMAGE_VIIRSDNB: displayVIIRSImageInfo(segmenttype); imageLabel->setPixmap(QPixmap::fromImage( *(imageptrs->ptrimageViirsDNB))); + formtoolbox->setOMimagesize(imageptrs->ptrimageViirsDNB->width(), imageptrs->ptrimageViirsDNB->height()); break; case IMAGE_OLCI: displaySentinelImageInfo(SEG_OLCIEFR); diff --git a/core/formtoolbox.cpp b/core/formtoolbox.cpp index 1dcae9e..2827672 100644 --- a/core/formtoolbox.cpp +++ b/core/formtoolbox.cpp @@ -3524,13 +3524,6 @@ void FormToolbox::on_btnCreateStereo_clicked() void FormToolbox::on_btnCreateOM_clicked() { - // if(!opts.buttonVIIRSM) - // { - // QMessageBox msgBox; - // msgBox.setText("Only possible for VIIRS images."); - // msgBox.exec(); - // return; - // } ui->pbProgress->reset(); @@ -3542,6 +3535,14 @@ void FormToolbox::on_btnCreateOM_clicked() return; } } + else if(ui->rdbVIIRSDNBin->isChecked()) + { + if(!(opts.buttonVIIRSDNB || opts.buttonVIIRSDNBNOAA20) || !segs->SelectedVIIRSDNBSegments()) + { + QMessageBox::information( this, "VIIRS DNB", "No selected VIIRS DNB segments !" ); + return; + } + } else if(ui->rdbMERSIin->isChecked()) { if(!opts.buttonMERSI || !segs->SelectedMERSISegments()) @@ -3570,6 +3571,14 @@ void FormToolbox::on_btnCreateOM_clicked() else if(opts.buttonVIIRSMNOAA20) imageptrs->om->CreateMapFromVIIRS(eSegmentType::SEG_VIIRSMNOAA20, false); } + else if(ui->rdbVIIRSDNBin->isChecked()) + { + currentProjectionType = PROJ_VIIRSDNB; + if(opts.buttonVIIRSDNB) + imageptrs->om->CreateMapFromVIIRS(eSegmentType::SEG_VIIRSDNB, false); + else if(opts.buttonVIIRSDNBNOAA20) + imageptrs->om->CreateMapFromVIIRS(eSegmentType::SEG_VIIRSDNBNOAA20, false); + } else if(ui->rdbMERSIin->isChecked()) { currentProjectionType = PROJ_MERSI; diff --git a/core/formtoolbox.ui b/core/formtoolbox.ui index 8da8bf4..9c1ed09 100644 --- a/core/formtoolbox.ui +++ b/core/formtoolbox.ui @@ -7308,14 +7308,14 @@ - 0 + 3 0 0 - 591 + 419 670 @@ -8869,8 +8869,8 @@ 0 0 - 540 - 255 + 610 + 470 @@ -8880,7 +8880,7 @@ - Only possible for AVHRR(Metop), VIIRS M and MERSI images + Only possible for AVHRR(Metop), VIIRS M/DNB and MERSI images diff --git a/core/generalverticalperspective.cpp b/core/generalverticalperspective.cpp index b4f7caf..b898729 100644 --- a/core/generalverticalperspective.cpp +++ b/core/generalverticalperspective.cpp @@ -3,7 +3,6 @@ #include "options.h" #include "pixgeoconversion.h" #include -#include "equirectangular.h" #include diff --git a/core/globe.cpp b/core/globe.cpp index 4f7af20..7f79637 100644 --- a/core/globe.cpp +++ b/core/globe.cpp @@ -19,7 +19,7 @@ extern gshhsData *gshhsdata; void Render3DColorTexture(Globe *gl, int geoindex) { - gl->Render3DGeoSegment( geoindex ); + gl->Render3DGeoSegmentNew( geoindex ); } void Render3DColorFBO(Globe *gl, eGeoSatellite sat) @@ -1558,6 +1558,23 @@ void Globe::Render3DGeoSegment(int geoindex) emit renderingglobefinished(true); } +void Globe::Render3DGeoSegmentNew(int geoindex) +{ + Equirectangular equirect; + + equirect.Initialize(imageptrs->pmOut->width(), imageptrs->pmOut->height()); + + + for (int i = 0; i < imageptrs->pmOut->height(); i=i+1) + { + Render3DGeoSegmentLineNew( i, geoindex, &equirect); + } + + opts.texture_changed = true; + emit renderingglobefinished(true); + + +} void Globe::Render3DGeoSegmentLine(int heightinimage, int geoindex) { @@ -1566,7 +1583,7 @@ void Globe::Render3DGeoSegmentLine(int heightinimage, int geoindex) QRgb rgbval; double lon_deg, lat_deg; int x, y; - + double lon_low, lon_high; pixgeoConversion pixconv; QPainter fb_painter(imageptrs->pmOut); @@ -1584,7 +1601,24 @@ void Globe::Render3DGeoSegmentLine(int heightinimage, int geoindex) { if(pixconv.pixcoord2geocoord(segs->seglgeo[geoindex]->geosatlon, pix, heightinimage, segs->seglgeo[geoindex]->COFF, segs->seglgeo[geoindex]->LOFF, segs->seglgeo[geoindex]->CFAC, segs->seglgeo[geoindex]->LFAC, &lat_deg, &lon_deg) == 0) { - if(lon_deg > -65.0 && lon_deg < 65.0 && lat_deg > -65.0 && lat_deg < 65.0) + // if(lon_deg > -65.0 && lon_deg < 65.0 && lat_deg > -65.0 && lat_deg < 65.0) + if(segs->seglgeo[geoindex]->geosatlon == 0.0) + { + lon_low = -90.0; + lon_high = 20.75; + } + else if(segs->seglgeo[geoindex]->geosatlon == 104.5) + { + lon_low = 52.25; + lon_high = 194.5; + } + else if(segs->seglgeo[geoindex]->geosatlon == 41.5) + { + lon_low = 20.75; + lon_high = 131.5; + } + + if(lon_deg < lon_high && lon_deg > lon_low) { sphericalToPixel(lon_deg*PI/180.0, lat_deg*PI/180.0, x, y, imageptrs->pmOriginal->width(), imageptrs->pmOriginal->height()); fb_painter.setPen(rgbval); @@ -1615,6 +1649,52 @@ void Globe::Render3DGeoSegmentLine(int heightinimage, int geoindex) } +void Globe::Render3DGeoSegmentLineNew(int heightinimage, int geoindex, Equirectangular *equirect) +{ + float lon_deg, lat_deg; + pixgeoConversion pixconv; + int ximage, yimage; + QRgb *scanl; + QRgb rgbval; + double lon_low, lon_high; + + + QPainter fb_painter(imageptrs->pmOut); + + for (int pix = 0 ; pix < imageptrs->pmOut->width(); pix+=1) + { + equirect->map_inverse(pix, heightinimage, lon_deg, lat_deg); + if(segs->seglgeo[geoindex]->geosatlon == 0.0) + { + lon_low = -90.0; + lon_high = 20.75; + } + else if(segs->seglgeo[geoindex]->geosatlon == 104.5) + { + lon_low = 52.25; + lon_high = 194.5; + } + else if(segs->seglgeo[geoindex]->geosatlon == 41.5) + { + lon_low = 20.75; + lon_high = 131.5; + } + + //if(lon_deg < lon_high && lon_deg > lon_low) + { + if(pixconv.geocoord2pixcoord(segs->seglgeo[geoindex]->geosatlon, lat_deg, lon_deg, segs->seglgeo[geoindex]->COFF, segs->seglgeo[geoindex]->LOFF, segs->seglgeo[geoindex]->CFAC, segs->seglgeo[geoindex]->LFAC, &ximage, &yimage) == 0) + { + scanl = (QRgb*)imageptrs->ptrimageGeostationary->scanLine(yimage); + rgbval = scanl[ximage]; + fb_painter.setPen(rgbval); + fb_painter.drawPoint(pix, heightinimage); + } + } + } + + fb_painter.end(); +} + void Globe::Render3DGeoSegmentFBO(eGeoSatellite sat) { diff --git a/core/globe.h b/core/globe.h index 95d9c31..4c78c08 100644 --- a/core/globe.h +++ b/core/globe.h @@ -34,6 +34,7 @@ #include "octahedron.h" #include "projextentsgl.h" #include "texturewriter.h" +#include "equirectangular.h" #ifdef OPENGL30 class Globe : public QOpenGLWidget, protected QOpenGLFunctions_3_0 @@ -54,6 +55,7 @@ class Globe : public QOpenGLWidget, protected QOpenGLFunctions public: Globe(QWidget *parent = NULL, SatelliteList *satlist=0, AVHRRSatellite *seglist=0 ); void Render3DGeoSegment(int geoindex); + void Render3DGeoSegmentNew(int geoindex); void Render3DGeoSegmentFBO(eGeoSatellite sat); void drawSatelliteNames(QPainter *painter, QMatrix4x4 modelview); void drawStationNames(QPainter *painter, QMatrix4x4 modelview); @@ -109,6 +111,7 @@ private slots: //void RenderAllScanAreaGL(); void TestForSegmentGL( int x, int realy, float distance, const QMatrix4x4 &m); void Render3DGeoSegmentLine(int heightinimage, int geoindex); + void Render3DGeoSegmentLineNew(int heightinimage, int geoindex, Equirectangular *equirect); void Render3DGeoSegmentLineFBO(int heightinimage, eGeoSatellite geo); diff --git a/core/main.cpp b/core/main.cpp index 002fdb9..b8c5ed7 100644 --- a/core/main.cpp +++ b/core/main.cpp @@ -12,7 +12,7 @@ #include -#define APPVERSION "1.5.2" +#define APPVERSION "1.5.3" using namespace std; @@ -122,7 +122,12 @@ int main(int argc, char *argv[]) for (int i = 0; i < styles.size(); ++i) qInfo() << styles.at(i); - app.setStyle(QStyleFactory::create("Fusion")); + //app.setStyle(QStyleFactory::create("Fusion")); + //QFile file("Adaptic.qss"); //("Combinear.qss"); //file("HackBook.qss"); + //file.open(QFile::ReadOnly); + //QString styleSheet { QLatin1String(file.readAll()) }; + //setup stylesheet + //app.setStyleSheet(styleSheet); if (QCoreApplication::arguments().contains(QStringLiteral("--logging")) || QCoreApplication::arguments().contains(QStringLiteral("-l")) ) @@ -153,7 +158,7 @@ int main(int argc, char *argv[]) app.setApplicationName("EUMETCastView"); app.setApplicationVersion(APPVERSION); -// "QTabWidget::tab:disabled { width: 0; height: 0; margin: 0; padding: 0; border: none; }" + //"QTabWidget::tab:disabled { width: 0; height: 0; margin: 0; padding: 0; border: none; }" app.setStyleSheet( "QTabWidget::tab:default {border-color: navy;}" diff --git a/core/mainwindow.cpp b/core/mainwindow.cpp index e1795a0..f4ab388 100644 --- a/core/mainwindow.cpp +++ b/core/mainwindow.cpp @@ -392,7 +392,7 @@ void MainWindow::on_actionAbout_triggered() "
Version " + QApplication::applicationVersion() + "
" "

supports the following satellites

" "
Polar satellites :" - "
AVHHR images from Metop-A/-B/-C and NOAA-19" + "
AVHRR images from Metop-A/-B/-C and NOAA-19" "
VIIRS images from SUOMI NPP and NOAA-20 (M-Band and Day/Night Band)" "
OLCI EFR/ERR and SLSTR from Sentinel-3A/-3B" "
MERSI from FengYun 3D" diff --git a/core/obliquemercator.cpp b/core/obliquemercator.cpp index a7a97c4..5031c55 100644 --- a/core/obliquemercator.cpp +++ b/core/obliquemercator.cpp @@ -31,6 +31,8 @@ ObliqueMercator::~ObliqueMercator() void ObliqueMercator::Initialize(double r_maj, double r_min, eProjectionType projtype, int imgwidth, int imgheight) { + qDebug() << "ObliqueMercator::Initialize"; + if(opts.bellipsoid) { this->ellipsoid = true; @@ -70,14 +72,6 @@ void ObliqueMercator::InitializeEllipsoid(double r_maj, double r_min, eProjectio qDebug() << "ObliqueMercator::Initialize input image = " << projtype; - if(projtype != PROJ_AVHRR && projtype != PROJ_MERSI && projtype != PROJ_VIIRSM ) - { - QMessageBox msgBox; - msgBox.setText("Only possible for MERSI and VIIRS M projections ! (Ellipsoid)"); - msgBox.exec(); - return; - } - if(projtype == PROJ_VIIRSM) { if(opts.buttonVIIRSM) @@ -85,6 +79,13 @@ void ObliqueMercator::InitializeEllipsoid(double r_maj, double r_min, eProjectio else if(opts.buttonVIIRSMNOAA20) segs->seglviirsmnoaa20->GetCentralCoords(&lon1_d, &lat1_d, &lon2_d, &lat2_d); } + else if(projtype == PROJ_VIIRSDNB) + { + if(opts.buttonVIIRSDNB) + segs->seglviirsdnb->GetCentralCoords(&lon1_d, &lat1_d, &lon2_d, &lat2_d); + else if(opts.buttonVIIRSDNBNOAA20) + segs->seglviirsdnbnoaa20->GetCentralCoords(&lon1_d, &lat1_d, &lon2_d, &lat2_d); + } else if(projtype == PROJ_MERSI) { segs->seglmersi->GetCentralCoords(&lon1_d, &lat1_d, &lon2_d, &lat2_d); @@ -94,6 +95,8 @@ void ObliqueMercator::InitializeEllipsoid(double r_maj, double r_min, eProjectio if(opts.buttonMetop) segs->seglmetop->GetCentralCoords(&lon1_d, &lat1_d, &lon2_d, &lat2_d); } + else + return; qDebug() << "lon1_d = " << lon1_d << " lat1_d = " << lat1_d << " lon2_d = " << lon2_d << " lat2_d = " << lat2_d; lon1_r = deg2rad(lon1_d); @@ -133,6 +136,12 @@ void ObliqueMercator::InitializeEllipsoid(double r_maj, double r_min, eProjectio image_width = imgwidth; //imageptrs->ptrimageViirsM->width(); image_height = imgheight; //imageptrs->ptrimageViirsM->height(); + } + else if(projtype == PROJ_VIIRSDNB) + { + image_width = imgwidth; //imageptrs->ptrimageViirsDNB->width(); + image_height = imgheight; //imageptrs->ptrimageViirsDNB->height(); + } else if(projtype == PROJ_MERSI) { @@ -283,7 +292,15 @@ void ObliqueMercator::InitializeEllipsoid(double r_maj, double r_min, eProjectio GetMinMaxXBoundingBox(SEG_VIIRSM, &boundingbox_min_x, &boundingbox_max_x, &boundingbox_min_y, &boundingbox_max_y); else if(opts.buttonVIIRSMNOAA20) GetMinMaxXBoundingBox(SEG_VIIRSMNOAA20, &boundingbox_min_x, &boundingbox_max_x, &boundingbox_min_y, &boundingbox_max_y); - } else if(projtype == PROJ_MERSI) + } + else if(projtype == PROJ_VIIRSDNB) + { + if(opts.buttonVIIRSDNB) + GetMinMaxXBoundingBox(SEG_VIIRSDNB, &boundingbox_min_x, &boundingbox_max_x, &boundingbox_min_y, &boundingbox_max_y); + else if(opts.buttonVIIRSDNBNOAA20) + GetMinMaxXBoundingBox(SEG_VIIRSDNBNOAA20, &boundingbox_min_x, &boundingbox_max_x, &boundingbox_min_y, &boundingbox_max_y); + } + else if(projtype == PROJ_MERSI) { GetMinMaxXBoundingBox(SEG_MERSI, &boundingbox_min_x, &boundingbox_max_x, &boundingbox_min_y, &boundingbox_max_y); } @@ -493,10 +510,18 @@ void ObliqueMercator::GetMinMaxXBoundingBox(eSegmentType type, double *boundingb { seglist = (SegmentList *)segs->seglviirsm; } + else if(type == SEG_VIIRSDNB) + { + seglist = (SegmentList *)segs->seglviirsdnb; + } else if( type == SEG_VIIRSMNOAA20) { seglist = (SegmentList *)segs->seglviirsmnoaa20; } + else if( type == SEG_VIIRSDNBNOAA20) + { + seglist = (SegmentList *)segs->seglviirsdnbnoaa20; + } else if( type == SEG_MERSI) { seglist = (SegmentList *)segs->seglmersi; @@ -504,6 +529,7 @@ void ObliqueMercator::GetMinMaxXBoundingBox(eSegmentType type, double *boundingb else seglist = NULL; + QList::iterator segsel; segsel = seglist->GetSegsSelectedptr()->begin(); while ( segsel != seglist->GetSegsSelectedptr()->end() ) @@ -783,6 +809,10 @@ void ObliqueMercator::CreateMapFromVIIRS(eSegmentType type, bool combine) segs->seglviirsm->ComposeOMProjection(0); else if( type == SEG_VIIRSMNOAA20) segs->seglviirsmnoaa20->ComposeOMProjection(0); + else if (type == SEG_VIIRSDNB) + segs->seglviirsdnb->ComposeOMProjection(0); + else if( type == SEG_VIIRSDNBNOAA20) + segs->seglviirsdnbnoaa20->ComposeOMProjection(0); if(opts.smoothprojectiontype == 1) imageptrs->SmoothProjectionImage(); @@ -796,6 +826,14 @@ void ObliqueMercator::CreateMapFromVIIRS(eSegmentType type, bool combine) { segs->seglviirsmnoaa20->SmoothVIIRSImage(combine); } + else if (type == SEG_VIIRSDNB) + { + segs->seglviirsdnb->SmoothVIIRSImage(combine); + } + else if (type == SEG_VIIRSDNBNOAA20) + { + segs->seglviirsdnbnoaa20->SmoothVIIRSImage(combine); + } } } diff --git a/core/pixgeoconversion.cpp b/core/pixgeoconversion.cpp index 29c696a..b9188ec 100644 --- a/core/pixgeoconversion.cpp +++ b/core/pixgeoconversion.cpp @@ -488,8 +488,11 @@ int pixgeoConversion::pixcoord2geocoord(double sub_lon_deg, int column, int row, sa = pow(SAT_HEIGHT * cos(x) * cos(y),2 ) - (cos(y)*cos(y) + (double)1.006803 * sin(y)*sin(y)) * (double)1737121856. ; +// if(row == 1856) +// qDebug() << "column = " << column << " sa = " << sa; + /* produce error values */ - if ( sa <= 0.0 ) { + if ( sa <= 1000000.0 ) { *latitude = -999.999; *longitude = -999.999; return (-1); @@ -636,7 +639,8 @@ int pixgeoConversion::geocoord2pixcoord(double sub_lon_deg, double latitude, dou dotprod = r1*(rl * cos(c_lat) * cos(lon - sub_lon)) - r2*r2 - r3*r3*(pow((R_EQ/R_POL),2)); - if (dotprod <= 0 ){ + + if (dotprod <= 30000000 ){ *column = -999; *row = -999; return (-1); @@ -663,6 +667,9 @@ int pixgeoConversion::geocoord2pixcoord(double sub_lon_deg, double latitude, dou *column = ccc; *row = lll; +// if(*row == 1850) +// qDebug() << "column = " << *column << " dotprod = " << dotprod; + return (0); diff --git a/core/segmentlistviirsdnb.cpp b/core/segmentlistviirsdnb.cpp index a904916..e55fd2a 100644 --- a/core/segmentlistviirsdnb.cpp +++ b/core/segmentlistviirsdnb.cpp @@ -569,3 +569,51 @@ void SegmentListVIIRSDNB::spbWindowValueChanged(int spbwindowval, int slcentreba emit segmentlistfinished(true); } + +void SegmentListVIIRSDNB::GetCentralCoords(double *startcentrallon, double *startcentrallat, double *endcentrallon, double *endcentrallat) +{ + double slon, slat, elon, elat; + double save_slon, save_slat, save_elon, save_elat; + int startindex, endindex; + + save_slon = 65535.0; + save_slat = 65535.0; + save_elon = 65535.0; + save_elat = 65535.0; + + bool first = true; + + QList::iterator segsel = segsselected.begin(); + + while ( segsel != segsselected.end() ) + { + SegmentVIIRSDNB *segm = (SegmentVIIRSDNB *)(*segsel); + segm->getCentralCoords(&slon, &slat, &elon, &elat, &startindex, &endindex); + + if(abs(slon) <= 180.0 && abs(slat) <= 90.0 && abs(elon) <= 180.0 && abs(elat) <= 90.0) + { + if(first == true) + { + first = false; + save_slon = slon; + save_slat = slat; + save_elon = elon; + save_elat = elat; + } + else + { + save_elon = elon; + save_elat = elat; + } + } + + QApplication::processEvents(); + ++segsel; + } + + *startcentrallon = save_slon; + *startcentrallat = save_slat; + *endcentrallon = save_elon; + *endcentrallat = save_elat; + +} diff --git a/core/segmentlistviirsdnb.h b/core/segmentlistviirsdnb.h index f4a9f1a..8234da8 100644 --- a/core/segmentlistviirsdnb.h +++ b/core/segmentlistviirsdnb.h @@ -20,6 +20,8 @@ class SegmentListVIIRSDNB : public SegmentList void sliderCentreBandChanged(int val); void spbWindowValueChanged(int spbwindowval, int slcentreband); float getMoonIllumination() { return moonillumination; } + void GetCentralCoords(double *startcentrallon, double *startcentrallat, double *endcentrallon, double *endcentrallat); + static void doComposeVIIRSDNBImageInThread(SegmentListVIIRSDNB *t); QScopedArrayPointer graphvalues; QVector xDNBcurve; diff --git a/core/segmentlistviirsm.cpp b/core/segmentlistviirsm.cpp index 8d52722..45e6146 100644 --- a/core/segmentlistviirsm.cpp +++ b/core/segmentlistviirsm.cpp @@ -1394,7 +1394,7 @@ void SegmentListVIIRSM::GetCentralCoords(double *startcentrallon, double *startc while ( segsel != segsselected.end() ) { SegmentVIIRSM *segm = (SegmentVIIRSM *)(*segsel); - segm->GetCentralCoords(&slon, &slat, &elon, &elat, &startindex, &endindex); + segm->getCentralCoords(&slon, &slat, &elon, &elat, &startindex, &endindex); if(abs(slon) <= 180.0 && abs(slat) <= 90.0 && abs(elon) <= 180.0 && abs(elat) <= 90.0) { @@ -1452,7 +1452,7 @@ void SegmentListVIIRSM::GetCornerCoords(double *cornerlon1, double *cornerlat1, count++; if(count == 1) { - segm->GetStartCornerCoords(&save_cornerlon1, &save_cornerlat1, &save_cornerlon2, &save_cornerlat2, &Xcornerindex1, &Xcornerindex2, &Ycornerindex12 ); + segm->getStartCornerCoords(&save_cornerlon1, &save_cornerlat1, &save_cornerlon2, &save_cornerlat2, &Xcornerindex1, &Xcornerindex2, &Ycornerindex12 ); if(abs(save_cornerlon1) <= 180.0 && abs(save_cornerlat1) <= 90.0 && abs(save_cornerlon2) <= 180.0 && abs(save_cornerlat2) <= 90.0) break; } @@ -1469,7 +1469,7 @@ void SegmentListVIIRSM::GetCornerCoords(double *cornerlon1, double *cornerlat1, if(count == segsselected.size()) { - segm->GetEndCornerCoords(&save_cornerlon3, &save_cornerlat3, &save_cornerlon4, &save_cornerlat4, &Xcornerindex3, &Xcornerindex4, &Ycornerindex34 ); + segm->getEndCornerCoords(&save_cornerlon3, &save_cornerlat3, &save_cornerlon4, &save_cornerlat4, &Xcornerindex3, &Xcornerindex4, &Ycornerindex34 ); if(abs(save_cornerlon3) <= 180.0 && abs(save_cornerlat3) <= 90.0 && abs(save_cornerlon4) <= 180.0 && abs(save_cornerlat4) <= 90.0) break; } diff --git a/core/segmentviirsdnb.cpp b/core/segmentviirsdnb.cpp index 132a1ad..d628d3b 100644 --- a/core/segmentviirsdnb.cpp +++ b/core/segmentviirsdnb.cpp @@ -213,8 +213,8 @@ void SegmentVIIRSDNB::ComposeSegmentImageWindow(float lowerlimit, float upperlim int r; -// upperlimit = 0.8E-2; -// lowerlimit = 2.0E-4; + // upperlimit = 0.8E-2; + // lowerlimit = 2.0E-4; qDebug() << QString("lowerlimit = %1").arg(lowerlimit, 0, 'E', 2); qDebug() << QString("upperlimit = %1").arg(upperlimit, 0, 'E', 2); @@ -227,23 +227,23 @@ void SegmentVIIRSDNB::ComposeSegmentImageWindow(float lowerlimit, float upperlim { float zenith = solar_zenith[line * earth_views_per_scanline + pixelx]; pixval = *(this->ptrbaVIIRSDNB.data() + line * earth_views_per_scanline + pixelx); -// if(pixval > 0) -// { - indexout = (long)(255 * ( pixval - lowerlimit ) / (upperlimit - lowerlimit)); - indexout = indexout > 255 ? 255 : indexout; - indexout = indexout < 0 ? 0 : indexout; - r = indexout; -// if((zenith >= 95.0 && zenith < 95.01) || (zenith >= 100.0 && zenith < 100.01)) -// row[pixelx] = qRgb(0, 255, 0); -// else if(zenith >= 90.0 && zenith < 90.01) -// row[pixelx] = qRgb(0, 255, 255); -// else if((zenith >= 80.0 && zenith < 80.01) || (zenith >= 85.0 && zenith < 85.01) ) -// row[pixelx] = qRgb(255, 0, 0); -// else - row[pixelx] = qRgb(r, r, r ); -// } -// else -// row[pixelx] = qRgb(255, 0, 0 ); + // if(pixval > 0) + // { + indexout = (long)(255 * ( pixval - lowerlimit ) / (upperlimit - lowerlimit)); + indexout = indexout > 255 ? 255 : indexout; + indexout = indexout < 0 ? 0 : indexout; + r = indexout; + // if((zenith >= 95.0 && zenith < 95.01) || (zenith >= 100.0 && zenith < 100.01)) + // row[pixelx] = qRgb(0, 255, 0); + // else if(zenith >= 90.0 && zenith < 90.01) + // row[pixelx] = qRgb(0, 255, 255); + // else if((zenith >= 80.0 && zenith < 80.01) || (zenith >= 85.0 && zenith < 85.01) ) + // row[pixelx] = qRgb(255, 0, 0); + // else + row[pixelx] = qRgb(r, r, r ); + // } + // else + // row[pixelx] = qRgb(255, 0, 0 ); } if(opts.imageontextureOnVIIRS) // && ((line + 5 ) % 16 == 0 || (line + 10) % 16 == 0) ) { @@ -286,23 +286,23 @@ void SegmentVIIRSDNB::ComposeSegmentImageWindowFromCurve(QVector *x, QVe pixval = *(this->ptrbaVIIRSDNB.data() + line * earth_views_per_scanline + pixelx); -// if(pixval > 0) -// { - indexout = (long)(255 * ( pixval - lowerlimit ) / (upperlimit - lowerlimit)); - indexout = indexout > 255 ? 255 : indexout; - indexout = indexout < 0 ? 0 : indexout; - r = indexout; - if((zenith >= 95.0 && zenith < 95.01) || (zenith >= 100.0 && zenith < 100.01)) - row[pixelx] = qRgb(0, 255, 0); - else if(zenith >= 90.0 && zenith < 90.01) - row[pixelx] = qRgb(0, 255, 255); - else if((zenith >= 80.0 && zenith < 80.01) || (zenith >= 85.0 && zenith < 85.01) ) - row[pixelx] = qRgb(255, 0, 0); - else - row[pixelx] = qRgb(r, r, r ); -// } -// else -// row[pixelx] = qRgb(255, 0, 0 ); + // if(pixval > 0) + // { + indexout = (long)(255 * ( pixval - lowerlimit ) / (upperlimit - lowerlimit)); + indexout = indexout > 255 ? 255 : indexout; + indexout = indexout < 0 ? 0 : indexout; + r = indexout; + if((zenith >= 95.0 && zenith < 95.01) || (zenith >= 100.0 && zenith < 100.01)) + row[pixelx] = qRgb(0, 255, 0); + else if(zenith >= 90.0 && zenith < 90.01) + row[pixelx] = qRgb(0, 255, 255); + else if((zenith >= 80.0 && zenith < 80.01) || (zenith >= 85.0 && zenith < 85.01) ) + row[pixelx] = qRgb(255, 0, 0); + else + row[pixelx] = qRgb(r, r, r ); + // } + // else + // row[pixelx] = qRgb(255, 0, 0 ); } } @@ -387,6 +387,11 @@ void SegmentVIIRSDNB::ComposeSegmentSGProjection(int inputchannel, int histogram ComposeProjection(SG, histogrammethod, normalized); } +void SegmentVIIRSDNB::ComposeSegmentOMProjection(int inputchannel, int histogrammethod, bool normalized) +{ + ComposeProjection(OM, histogrammethod, normalized); +} + void SegmentVIIRSDNB::ComposeProjection(eProjections proj, int histogrammethod, bool normalized) { @@ -419,8 +424,11 @@ void SegmentVIIRSDNB::ComposeProjection(eProjections proj, int histogrammethod, { pixval = ptrbaVIIRSDNB[i * earth_views_per_scanline + j]; - latpos1 = geolatitude[i * earth_views_per_scanline + j]; - lonpos1 = geolongitude[i * earth_views_per_scanline + j]; + latpos1 = geolatitude[i * earth_views_per_scanline + j]; + lonpos1 = geolongitude[i * earth_views_per_scanline + j]; + + if(!(pixval >= -99.0 && pixval <= -92.0 )) + { if(proj == LCC) //Lambert { @@ -444,6 +452,15 @@ void SegmentVIIRSDNB::ComposeProjection(eProjections proj, int histogrammethod, MapPixel( i, j, map_x, map_y); } } + else if(proj == OM) // Oblique Mercator + { + if(imageptrs->om->map_forward(lonpos1 * PI / 180.0, latpos1 * PI / 180.0, map_x, map_y)) + { + MapPixel( i, j, map_x, map_y); + } + } + } + } } @@ -462,16 +479,22 @@ void SegmentVIIRSDNB::LonLatMax() { for (int i = 0; i < earth_views_per_scanline; i+=1) { - if(geolatitude[j * earth_views_per_scanline + i] > latMax) - latMax = geolatitude[j * earth_views_per_scanline + i]; - if(geolatitude[j * earth_views_per_scanline + i] <= latMin) - latMin = geolatitude[j * earth_views_per_scanline + i]; - if(geolongitude[j * earth_views_per_scanline + i] > lonMax) - lonMax = geolongitude[j * earth_views_per_scanline + i]; - if(geolongitude[j * earth_views_per_scanline + i] <= lonMin) - lonMin = geolongitude[j * earth_views_per_scanline + i]; + if(geolatitude[j * earth_views_per_scanline + i] != -999.0) + { + if(geolatitude[j * earth_views_per_scanline + i] > latMax) + latMax = geolatitude[j * earth_views_per_scanline + i]; + if(geolatitude[j * earth_views_per_scanline + i] <= latMin) + latMin = geolatitude[j * earth_views_per_scanline + i]; + } + if(geolongitude[j * earth_views_per_scanline + i] != -999.0) + { + if(geolongitude[j * earth_views_per_scanline + i] > lonMax) + lonMax = geolongitude[j * earth_views_per_scanline + i]; + if(geolongitude[j * earth_views_per_scanline + i] <= lonMin) + lonMin = geolongitude[j * earth_views_per_scanline + i]; + } } - } + } qDebug() << QString("Minimum Latitude = %1 ; Maximum Latitude = %2").arg(latMin).arg(latMax); qDebug() << QString("Minimum Longitude = %1 ; Maximum Longitude = %2").arg(lonMin).arg(lonMax); @@ -658,6 +681,18 @@ Segment *SegmentVIIRSDNB::ReadSegmentInMemory() solar_azimuth.reset(new float[totdim]); solar_zenith.reset(new float[totdim]); + for(int i = 0; i < totdim; i++) + { + geolongitude[i] = -999.0; + geolatitude[i] = -999.0; + lunar_azimuth[i] = -999.0; + lunar_zenith[i] = -999.0; + + solar_azimuth[i] = -999.0; + solar_zenith[i] = -999.0; + + } + if((h5_status = H5Dread (radiance_id, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, ptrbaVIIRSDNB.data())) < 0) qDebug() << "Unable to read radiance dataset"; @@ -690,80 +725,80 @@ Segment *SegmentVIIRSDNB::ReadSegmentInMemory() expanscoef.reset(new float[totdim]); Ptpzscan.reset(new int[totdim]); -// M-bands -// NumberOfTiePointZoneGroupsTrack = 1; -// NumberOfTiePointZoneGroupsScan = 1; -// TiePointZoneGroupLocationTrackCompact = 0; -// TiePointZoneGroupLocationScanCompact = 0; -// TiePointZoneGroupLocationTrack = 0; -// TiePointZoneGroupLocationScan = 0; - - NumberOfTiePointZonesScan_id = H5Dopen2(h5_file_id, "/All_Data/VIIRS-DNB-GEO_All/NumberOfTiePointZonesScan", H5P_DEFAULT); - NumberOfTiePointZonesTrack_id = H5Dopen2(h5_file_id, "/All_Data/VIIRS-DNB-GEO_All/NumberOfTiePointZonesTrack", H5P_DEFAULT); - NumberOfTiePointZoneGroupsScan_id = H5Dopen2(h5_file_id, "/All_Data/VIIRS-DNB-GEO_All/NumberOfTiePointZoneGroupsScan", H5P_DEFAULT); - NumberOfTiePointZoneGroupsTrack_id = H5Dopen2(h5_file_id, "/All_Data/VIIRS-DNB-GEO_All/NumberOfTiePointZoneGroupsTrack", H5P_DEFAULT); - TiePointZoneGroupLocationScanCompact_id = H5Dopen2(h5_file_id, "/All_Data/VIIRS-DNB-GEO_All/TiePointZoneGroupLocationScanCompact", H5P_DEFAULT); - TiePointZoneGroupLocationTrackCompact_id = H5Dopen2(h5_file_id, "/All_Data/VIIRS-DNB-GEO_All/TiePointZoneGroupLocationTrackCompact", H5P_DEFAULT); - // TiePointZoneGroupLocationScan_id = H5Dopen2(h5_file_id, "/All_Data/VIIRS-DNB-GEO_All/TiePointZoneGroupLocationScan", H5P_DEFAULT); - // TiePointZoneGroupLocationTrack_id = H5Dopen2(h5_file_id, "/All_Data/VIIRS-DNB-GEO_All/TiePointZoneGroupLocationTrack", H5P_DEFAULT); - - NumberOfTiePointZonesScan.reset(new int[GetTotalDimensionspace(NumberOfTiePointZonesScan_id)]); - NumberOfTiePointZonesTrack.reset(new int[GetTotalDimensionspace(NumberOfTiePointZonesTrack_id)]); - NumberOfTiePointZoneGroupsScan.reset(new int[GetTotalDimensionspace(NumberOfTiePointZoneGroupsScan_id)]); - NumberOfTiePointZoneGroupsTrack.reset(new int[GetTotalDimensionspace(NumberOfTiePointZoneGroupsTrack_id)]); - TiePointZoneGroupLocationScanCompact.reset(new int[GetTotalDimensionspace(TiePointZoneGroupLocationScanCompact_id)]); - TiePointZoneGroupLocationTrackCompact.reset(new int[GetTotalDimensionspace(TiePointZoneGroupLocationTrackCompact_id)]); - //TiePointZoneGroupLocationScan.reset(new int[GetTotalDimensionspace(TiePointZoneGroupLocationScan_id)]); - //TiePointZoneGroupLocationTrack.reset(new int[GetTotalDimensionspace(TiePointZoneGroupLocationTrack_id)]); - - - MoonIllumFraction_id = H5Dopen2(h5_file_id, "/All_Data/VIIRS-DNB-GEO_All/MoonIllumFraction", H5P_DEFAULT); - if((h5_status = H5Dread (MoonIllumFraction_id, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, - H5P_DEFAULT, &MoonIllumFraction)) < 0) - fprintf(stderr, "unable to read MoonIllumFraction dataset"); - - if((h5_status = H5Dread (NumberOfTiePointZonesScan_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, - H5P_DEFAULT, NumberOfTiePointZonesScan.data())) < 0) - fprintf(stderr, "unable to read NumberOfTiePointZonesScan dataset"); - if((h5_status = H5Dread (NumberOfTiePointZonesTrack_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, - H5P_DEFAULT, NumberOfTiePointZonesTrack.data())) < 0) - fprintf(stderr, "unable to read NumberOfTiePointZonesTrack dataset"); - if((h5_status = H5Dread (NumberOfTiePointZoneGroupsScan_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, - H5P_DEFAULT, NumberOfTiePointZoneGroupsScan.data())) < 0) - fprintf(stderr, "unable to read NumberOfTiePointZoneGroupsScan dataset"); - if((h5_status = H5Dread (NumberOfTiePointZoneGroupsTrack_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, - H5P_DEFAULT, NumberOfTiePointZoneGroupsTrack.data())) < 0) - fprintf(stderr, "unable to read NumberOfTiePointZoneGroupsTrack dataset"); - - if((h5_status = H5Dread (TiePointZoneGroupLocationScanCompact_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, - H5P_DEFAULT, TiePointZoneGroupLocationScanCompact.data())) < 0) - fprintf(stderr, "unable to read TiePointZoneGroupLocationScanCompact dataset"); - if((h5_status = H5Dread (TiePointZoneGroupLocationTrackCompact_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, - H5P_DEFAULT, TiePointZoneGroupLocationTrackCompact.data())) < 0) - fprintf(stderr, "unable to read TiePointZoneGroupLocationTrackCompact dataset"); - // if((h5_status = H5Dread (TiePointZoneGroupLocationScan_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, - // H5P_DEFAULT, TiePointZoneGroupLocationScan.data())) < 0) - // fprintf(stderr, "unable to read TiePointZoneGroupLocationScan dataset"); - // if((h5_status = H5Dread (TiePointZoneGroupLocationTrack_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, - // H5P_DEFAULT, TiePointZoneGroupLocationTrack.data())) < 0) - // fprintf(stderr, "unable to read TiePointZoneGroupLocationTrack dataset"); - - TiePointZoneSizeScan.reset(new int[NumberOfTiePointZoneGroupsScan[0]]); - TiePointZoneGroupLocationScan.reset(new int[NumberOfTiePointZoneGroupsScan[0]]); - - - TiePointZoneSizeScan_id = H5Aopen_by_name(h5_file_id, "/All_Data/VIIRS-DNB-SDR_All", "TiePointZoneSizeScan", - H5P_DEFAULT, H5P_DEFAULT); - if((h5_status = H5Aread(TiePointZoneSizeScan_id, H5T_NATIVE_INT, TiePointZoneSizeScan.data())) < 0) - fprintf(stderr, "unable to read TiePointZoneSizeScan attribute"); - - h5_status= H5Aclose(TiePointZoneSizeScan_id); - TiePointZoneGroupLocationScan_id = H5Aopen_by_name(h5_file_id, "/All_Data/VIIRS-DNB-SDR_All", "TiePointZoneGroupLocationScan", - H5P_DEFAULT, H5P_DEFAULT); - if((h5_status = H5Aread(TiePointZoneGroupLocationScan_id, H5T_NATIVE_INT, TiePointZoneGroupLocationScan.data())) < 0) - fprintf(stderr, "unable to read TiePointZoneGroupLocationScan attribute"); - - h5_status= H5Aclose(TiePointZoneGroupLocationScan_id); + // M-bands + // NumberOfTiePointZoneGroupsTrack = 1; + // NumberOfTiePointZoneGroupsScan = 1; + // TiePointZoneGroupLocationTrackCompact = 0; + // TiePointZoneGroupLocationScanCompact = 0; + // TiePointZoneGroupLocationTrack = 0; + // TiePointZoneGroupLocationScan = 0; + + NumberOfTiePointZonesScan_id = H5Dopen2(h5_file_id, "/All_Data/VIIRS-DNB-GEO_All/NumberOfTiePointZonesScan", H5P_DEFAULT); + NumberOfTiePointZonesTrack_id = H5Dopen2(h5_file_id, "/All_Data/VIIRS-DNB-GEO_All/NumberOfTiePointZonesTrack", H5P_DEFAULT); + NumberOfTiePointZoneGroupsScan_id = H5Dopen2(h5_file_id, "/All_Data/VIIRS-DNB-GEO_All/NumberOfTiePointZoneGroupsScan", H5P_DEFAULT); + NumberOfTiePointZoneGroupsTrack_id = H5Dopen2(h5_file_id, "/All_Data/VIIRS-DNB-GEO_All/NumberOfTiePointZoneGroupsTrack", H5P_DEFAULT); + TiePointZoneGroupLocationScanCompact_id = H5Dopen2(h5_file_id, "/All_Data/VIIRS-DNB-GEO_All/TiePointZoneGroupLocationScanCompact", H5P_DEFAULT); + TiePointZoneGroupLocationTrackCompact_id = H5Dopen2(h5_file_id, "/All_Data/VIIRS-DNB-GEO_All/TiePointZoneGroupLocationTrackCompact", H5P_DEFAULT); + // TiePointZoneGroupLocationScan_id = H5Dopen2(h5_file_id, "/All_Data/VIIRS-DNB-GEO_All/TiePointZoneGroupLocationScan", H5P_DEFAULT); + // TiePointZoneGroupLocationTrack_id = H5Dopen2(h5_file_id, "/All_Data/VIIRS-DNB-GEO_All/TiePointZoneGroupLocationTrack", H5P_DEFAULT); + + NumberOfTiePointZonesScan.reset(new int[GetTotalDimensionspace(NumberOfTiePointZonesScan_id)]); + NumberOfTiePointZonesTrack.reset(new int[GetTotalDimensionspace(NumberOfTiePointZonesTrack_id)]); + NumberOfTiePointZoneGroupsScan.reset(new int[GetTotalDimensionspace(NumberOfTiePointZoneGroupsScan_id)]); + NumberOfTiePointZoneGroupsTrack.reset(new int[GetTotalDimensionspace(NumberOfTiePointZoneGroupsTrack_id)]); + TiePointZoneGroupLocationScanCompact.reset(new int[GetTotalDimensionspace(TiePointZoneGroupLocationScanCompact_id)]); + TiePointZoneGroupLocationTrackCompact.reset(new int[GetTotalDimensionspace(TiePointZoneGroupLocationTrackCompact_id)]); + //TiePointZoneGroupLocationScan.reset(new int[GetTotalDimensionspace(TiePointZoneGroupLocationScan_id)]); + //TiePointZoneGroupLocationTrack.reset(new int[GetTotalDimensionspace(TiePointZoneGroupLocationTrack_id)]); + + + MoonIllumFraction_id = H5Dopen2(h5_file_id, "/All_Data/VIIRS-DNB-GEO_All/MoonIllumFraction", H5P_DEFAULT); + if((h5_status = H5Dread (MoonIllumFraction_id, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, + H5P_DEFAULT, &MoonIllumFraction)) < 0) + fprintf(stderr, "unable to read MoonIllumFraction dataset"); + + if((h5_status = H5Dread (NumberOfTiePointZonesScan_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, + H5P_DEFAULT, NumberOfTiePointZonesScan.data())) < 0) + fprintf(stderr, "unable to read NumberOfTiePointZonesScan dataset"); + if((h5_status = H5Dread (NumberOfTiePointZonesTrack_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, + H5P_DEFAULT, NumberOfTiePointZonesTrack.data())) < 0) + fprintf(stderr, "unable to read NumberOfTiePointZonesTrack dataset"); + if((h5_status = H5Dread (NumberOfTiePointZoneGroupsScan_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, + H5P_DEFAULT, NumberOfTiePointZoneGroupsScan.data())) < 0) + fprintf(stderr, "unable to read NumberOfTiePointZoneGroupsScan dataset"); + if((h5_status = H5Dread (NumberOfTiePointZoneGroupsTrack_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, + H5P_DEFAULT, NumberOfTiePointZoneGroupsTrack.data())) < 0) + fprintf(stderr, "unable to read NumberOfTiePointZoneGroupsTrack dataset"); + + if((h5_status = H5Dread (TiePointZoneGroupLocationScanCompact_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, + H5P_DEFAULT, TiePointZoneGroupLocationScanCompact.data())) < 0) + fprintf(stderr, "unable to read TiePointZoneGroupLocationScanCompact dataset"); + if((h5_status = H5Dread (TiePointZoneGroupLocationTrackCompact_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, + H5P_DEFAULT, TiePointZoneGroupLocationTrackCompact.data())) < 0) + fprintf(stderr, "unable to read TiePointZoneGroupLocationTrackCompact dataset"); + // if((h5_status = H5Dread (TiePointZoneGroupLocationScan_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, + // H5P_DEFAULT, TiePointZoneGroupLocationScan.data())) < 0) + // fprintf(stderr, "unable to read TiePointZoneGroupLocationScan dataset"); + // if((h5_status = H5Dread (TiePointZoneGroupLocationTrack_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, + // H5P_DEFAULT, TiePointZoneGroupLocationTrack.data())) < 0) + // fprintf(stderr, "unable to read TiePointZoneGroupLocationTrack dataset"); + + TiePointZoneSizeScan.reset(new int[NumberOfTiePointZoneGroupsScan[0]]); + TiePointZoneGroupLocationScan.reset(new int[NumberOfTiePointZoneGroupsScan[0]]); + + + TiePointZoneSizeScan_id = H5Aopen_by_name(h5_file_id, "/All_Data/VIIRS-DNB-SDR_All", "TiePointZoneSizeScan", + H5P_DEFAULT, H5P_DEFAULT); + if((h5_status = H5Aread(TiePointZoneSizeScan_id, H5T_NATIVE_INT, TiePointZoneSizeScan.data())) < 0) + fprintf(stderr, "unable to read TiePointZoneSizeScan attribute"); + + h5_status= H5Aclose(TiePointZoneSizeScan_id); + TiePointZoneGroupLocationScan_id = H5Aopen_by_name(h5_file_id, "/All_Data/VIIRS-DNB-SDR_All", "TiePointZoneGroupLocationScan", + H5P_DEFAULT, H5P_DEFAULT); + if((h5_status = H5Aread(TiePointZoneGroupLocationScan_id, H5T_NATIVE_INT, TiePointZoneGroupLocationScan.data())) < 0) + fprintf(stderr, "unable to read TiePointZoneGroupLocationScan attribute"); + + h5_status= H5Aclose(TiePointZoneGroupLocationScan_id); @@ -842,7 +877,7 @@ Segment *SegmentVIIRSDNB::ReadSegmentInMemory() s24[j] = (float)((j + 0.5)/24.0); -/* + /* for (j = 0; j < 4; j++) { for (i = 0; i < 6; i++) cout << " " << ptrbaVIIRSDNB[j * earth_views_per_scanline + i]; @@ -999,8 +1034,8 @@ void SegmentVIIRSDNB::CalcInterpolationInTPZ(int itrack, int iscan, int indexfro float lat_A, lat_B, lat_C, lat_D; float lon_A, lon_B, lon_C, lon_D; // float val_A, val_B, val_C, val_D; - float lunar_azimuth_A, lunar_azimuth_B, lunar_azimuth_C, lunar_azimuth_D; - float lunar_zenith_A, lunar_zenith_B, lunar_zenith_C, lunar_zenith_D; + //float lunar_azimuth_A, lunar_azimuth_B, lunar_azimuth_C, lunar_azimuth_D; + //float lunar_zenith_A, lunar_zenith_B, lunar_zenith_C, lunar_zenith_D; float solar_azimuth_A, solar_azimuth_B, solar_azimuth_C, solar_azimuth_D; float solar_zenith_A, solar_zenith_B, solar_zenith_C, solar_zenith_D; @@ -1014,6 +1049,7 @@ void SegmentVIIRSDNB::CalcInterpolationInTPZ(int itrack, int iscan, int indexfro jD = iscan; + lat_A = tiepoints_lat[iA * tiepointxdim + jA]; lat_B = tiepoints_lat[iB * tiepointxdim + jB]; lat_C = tiepoints_lat[iC * tiepointxdim + jC]; @@ -1024,20 +1060,30 @@ void SegmentVIIRSDNB::CalcInterpolationInTPZ(int itrack, int iscan, int indexfro lon_C = tiepoints_lon[iC * tiepointxdim + jC]; lon_D = tiepoints_lon[iD * tiepointxdim + jD]; + if((lat_A >= -999.9 && lat_A <= -999.2) || + (lat_B >= -999.9 && lat_A <= -999.2) || + (lat_C >= -999.9 && lat_A <= -999.2) || + (lat_D >= -999.9 && lat_A <= -999.2) || + (lon_A >= -999.9 && lon_A <= -999.2) || + (lon_B >= -999.9 && lon_B <= -999.2) || + (lon_C >= -999.9 && lon_C <= -999.2) || + (lon_D >= -999.9 && lon_D <= -999.2)) + return; + if(itrack == 0 && igroupscan == 0) qDebug() << QString("--- itrack = %1 iscan = %2 A(%3, %4) B(%5, %6) C(%7, %8) D(%9, %10) Lat tiepoint A = %11 B = %12 C = %13 D = %14").arg(itrack).arg(iscan).arg(jA).arg(iA).arg(jB).arg(iB) .arg(jC).arg(iC).arg(jD).arg(iD).arg(lat_A).arg(lat_B).arg(lat_C).arg(lat_D); -// lunar_azimuth_A = tiepoints_lunar_azimuth[iA * tiepointxdim + jA]; -// lunar_azimuth_B = tiepoints_lunar_azimuth[iB * tiepointxdim + jB]; -// lunar_azimuth_C = tiepoints_lunar_azimuth[iC * tiepointxdim + jC]; -// lunar_azimuth_D = tiepoints_lunar_azimuth[iD * tiepointxdim + jD]; + // lunar_azimuth_A = tiepoints_lunar_azimuth[iA * tiepointxdim + jA]; + // lunar_azimuth_B = tiepoints_lunar_azimuth[iB * tiepointxdim + jB]; + // lunar_azimuth_C = tiepoints_lunar_azimuth[iC * tiepointxdim + jC]; + // lunar_azimuth_D = tiepoints_lunar_azimuth[iD * tiepointxdim + jD]; -// lunar_zenith_A = tiepoints_lunar_zenith[iA * tiepointxdim + jA]; -// lunar_zenith_B = tiepoints_lunar_zenith[iB * tiepointxdim + jB]; -// lunar_zenith_C = tiepoints_lunar_zenith[iC * tiepointxdim + jC]; -// lunar_zenith_D = tiepoints_lunar_zenith[iD * tiepointxdim + jD]; + // lunar_zenith_A = tiepoints_lunar_zenith[iA * tiepointxdim + jA]; + // lunar_zenith_B = tiepoints_lunar_zenith[iB * tiepointxdim + jB]; + // lunar_zenith_C = tiepoints_lunar_zenith[iC * tiepointxdim + jC]; + // lunar_zenith_D = tiepoints_lunar_zenith[iD * tiepointxdim + jD]; solar_azimuth_A = tiepoints_solar_azimuth[iA * tiepointxdim + jA]; solar_azimuth_B = tiepoints_solar_azimuth[iB * tiepointxdim + jB]; @@ -1049,27 +1095,27 @@ void SegmentVIIRSDNB::CalcInterpolationInTPZ(int itrack, int iscan, int indexfro solar_zenith_C = tiepoints_solar_zenith[iC * tiepointxdim + jC]; solar_zenith_D = tiepoints_solar_zenith[iD * tiepointxdim + jD]; -// val_A = ptrbaVIIRSDNB[((itrack * 16)) * earth_views_per_scanline + (iscan * zscan)]; -// val_B = ptrbaVIIRSDNB[((itrack * 16)) * earth_views_per_scanline + (iscan * zscan) + zscan - 1]; -// val_C = ptrbaVIIRSDNB[((itrack * 16) + 15) * earth_views_per_scanline + (iscan * zscan) + zscan - 1]; -// val_D = ptrbaVIIRSDNB[((itrack * 16) + 15) * earth_views_per_scanline + (iscan * zscan)]; + // val_A = ptrbaVIIRSDNB[((itrack * 16)) * earth_views_per_scanline + (iscan * zscan)]; + // val_B = ptrbaVIIRSDNB[((itrack * 16)) * earth_views_per_scanline + (iscan * zscan) + zscan - 1]; + // val_C = ptrbaVIIRSDNB[((itrack * 16) + 15) * earth_views_per_scanline + (iscan * zscan) + zscan - 1]; + // val_D = ptrbaVIIRSDNB[((itrack * 16) + 15) * earth_views_per_scanline + (iscan * zscan)]; -// float minval = Minf(val_A, val_B, val_C, val_D); + // float minval = Minf(val_A, val_B, val_C, val_D); -// for(int relt = 0; relt < 16; relt++) -// { -// for(int rels = 0; rels < zscan; rels++) -// { -// if(ptrbaVIIRSDNB[((itrack * 16) + relt) * earth_views_per_scanline + (iscan * zscan) + rels] == 0 || ptrbaVIIRSDNB[((itrack * 16) + relt) * earth_views_per_scanline + (iscan * zscan) + rels] >= 65528) -// { -// geolatitude[((itrack * 16) + relt) * earth_views_per_scanline + (iscan * 16) + rels] = 65535; -// geolongitude[((itrack * 16) + relt) * earth_views_per_scanline + (iscan * 16) + rels] = 65535; -// } -// } -// } + // for(int relt = 0; relt < 16; relt++) + // { + // for(int rels = 0; rels < zscan; rels++) + // { + // if(ptrbaVIIRSDNB[((itrack * 16) + relt) * earth_views_per_scanline + (iscan * zscan) + rels] == 0 || ptrbaVIIRSDNB[((itrack * 16) + relt) * earth_views_per_scanline + (iscan * zscan) + rels] >= 65528) + // { + // geolatitude[((itrack * 16) + relt) * earth_views_per_scanline + (iscan * 16) + rels] = 65535; + // geolongitude[((itrack * 16) + relt) * earth_views_per_scanline + (iscan * 16) + rels] = 65535; + // } + // } + // } -//// if(itrack == 0) -//// qDebug() << QString("itrack = %1 iscan = %2 Lon tiepoint A = %3 B = %4 C = %5 D = %6").arg(itrack).arg(iscan).arg(lon_A).arg(lon_B).arg(lon_C).arg(lon_D); + //// if(itrack == 0) + //// qDebug() << QString("itrack = %1 iscan = %2 Lon tiepoint A = %3 B = %4 C = %5 D = %6").arg(itrack).arg(iscan).arg(lon_A).arg(lon_B).arg(lon_C).arg(lon_D); float min_lon = Minf(lon_A, lon_B, lon_C, lon_D); float max_lon = Maxf(lon_A, lon_B, lon_C, lon_D); @@ -1080,8 +1126,8 @@ void SegmentVIIRSDNB::CalcInterpolationInTPZ(int itrack, int iscan, int indexfro else interpolateLonLatDirect(itrack, indexfrom, igroupscan, lon_A, lon_B, lon_C, lon_D, lat_A, lat_B, lat_C, lat_D); -// if(itrack == 0) -// qDebug() << QString("itrack = %1 iscan = %2 indexfrom = %3 igroupscan = 4").arg(itrack).arg(iscan).arg(indexfrom).arg(igroupscan); + // if(itrack == 0) + // qDebug() << QString("itrack = %1 iscan = %2 indexfrom = %3 igroupscan = 4").arg(itrack).arg(iscan).arg(indexfrom).arg(igroupscan); float min_solar_azimuth = Minf(solar_azimuth_A, solar_azimuth_B, solar_azimuth_C, solar_azimuth_D); float max_solar_azimuth = Maxf(solar_azimuth_A, solar_azimuth_B, solar_azimuth_C, solar_azimuth_D); @@ -1090,7 +1136,7 @@ void SegmentVIIRSDNB::CalcInterpolationInTPZ(int itrack, int iscan, int indexfro Maxf(abs(lat_A), abs(lat_B), abs(lat_C), abs(lat_D)) > 80.0 ) interpolateSolarViaVector(itrack, indexfrom, igroupscan, lon_A, lon_B, lon_C, lon_D, lat_A, lat_B, lat_C, lat_D, solar_zenith_A, solar_zenith_B, solar_zenith_C, solar_zenith_D, solar_azimuth_A, solar_azimuth_B, solar_azimuth_C, solar_azimuth_D); else - interpolateSolarDirect(itrack, indexfrom, igroupscan, solar_zenith_A, solar_zenith_B, solar_zenith_C, solar_zenith_D, solar_azimuth_A, solar_azimuth_B, solar_azimuth_C, solar_azimuth_D); + interpolateSolarDirect(itrack, indexfrom, igroupscan, solar_zenith_A, solar_zenith_B, solar_zenith_C, solar_zenith_D, solar_azimuth_A, solar_azimuth_B, solar_azimuth_C, solar_azimuth_D); } @@ -1124,8 +1170,8 @@ void SegmentVIIRSDNB::interpolateLonLatDirect(int itrack, int indexfrom, int igr lon_2 = (1 - ascan) * lon_D + ascan * lon_C; lon = (1 - atrack) * lon_1 + atrack * lon_2; -// if(itrack == 0 && igroupscan < 5 && relt == 0) -// qDebug() << QString("---- ptpzscan + rels = %1 rels = %2 lon = %3 zscan = %4").arg(ptpzscan + rels).arg(rels).arg(lon).arg(zscan); + // if(itrack == 0 && igroupscan < 5 && relt == 0) + // qDebug() << QString("---- ptpzscan + rels = %1 rels = %2 lon = %3 zscan = %4").arg(ptpzscan + rels).arg(rels).arg(lon).arg(zscan); geolatitude[((itrack * 16) + relt) * earth_views_per_scanline + ptpzscan + rels] = lat; geolongitude[((itrack * 16) + relt) * earth_views_per_scanline + ptpzscan + rels] = lon; @@ -1140,7 +1186,7 @@ void SegmentVIIRSDNB::interpolateLonLatDirect(int itrack, int indexfrom, int igr { QString str = ""; for (int rels = 0; rels < zscan; rels++) - str.append(QString("%1 ").arg(geolatitude[((itrack * 16) + relt) * earth_views_per_scanline + ptpzscan + rels])); + str.append(QString("%1 ").arg(geolatitude[((itrack * 16) + relt) * earth_views_per_scanline + ptpzscan + rels])); qDebug() << str; } } @@ -1249,28 +1295,28 @@ void SegmentVIIRSDNB::interpolateLonLatViaVector(int itrack, int indexfrom, int } } -// if( itrack == 0 && igroupscan == 0) -// { -// cout << "geolatitude" << endl; -// for (int relt = 0; relt < 16; relt++) { -// for (int rels = 0; rels < zscan; rels++) -// cout << " " << geolatitude[((itrack * 16) + relt) * earth_views_per_scanline + (iscan * zscan) + rels]; -// cout << endl; -// } -// cout << "geolongitude" << endl; -// for (int relt = 0; relt < 16; relt++) { -// for (int rels = 0; rels < zscan; rels++) -// cout << " " << geolongitude[((itrack * 16) + relt) * earth_views_per_scanline + (iscan * zscan) + rels]; -// cout << endl; -// } -// } + // if( itrack == 0 && igroupscan == 0) + // { + // cout << "geolatitude" << endl; + // for (int relt = 0; relt < 16; relt++) { + // for (int rels = 0; rels < zscan; rels++) + // cout << " " << geolatitude[((itrack * 16) + relt) * earth_views_per_scanline + (iscan * zscan) + rels]; + // cout << endl; + // } + // cout << "geolongitude" << endl; + // for (int relt = 0; relt < 16; relt++) { + // for (int rels = 0; rels < zscan; rels++) + // cout << " " << geolongitude[((itrack * 16) + relt) * earth_views_per_scanline + (iscan * zscan) + rels]; + // cout << endl; + // } + // } } void SegmentVIIRSDNB::interpolateSolarViaVector(int itrack, int indexfrom, int igroupscan, - float lon_A, float lon_B, float lon_C, float lon_D, float lat_A, float lat_B, float lat_C, float lat_D, - float solar_zenith_A, float solar_zenith_B, float solar_zenith_C, float solar_zenith_D, - float solar_azimuth_A, float solar_azimuth_B, float solar_azimuth_C, float solar_azimuth_D) + float lon_A, float lon_B, float lon_C, float lon_D, float lat_A, float lat_B, float lat_C, float lat_D, + float solar_zenith_A, float solar_zenith_B, float solar_zenith_C, float solar_zenith_D, + float solar_azimuth_A, float solar_azimuth_B, float solar_azimuth_C, float solar_azimuth_D) { float ascan, atrack; @@ -1413,21 +1459,21 @@ void SegmentVIIRSDNB::interpolateSolarViaVector(int itrack, int indexfrom, int i } } -// if( itrack == 0) -// { -// cout << "solar_azimuth" << endl; -// for (int relt = 0; relt < 16; relt++) { -// for (int rels = 0; rels < zscan; rels++) -// cout << " " << solar_azimuth[((itrack * 16) + relt) * earth_views_per_scanline + rels]; // + (iscan * zscan)]; -// cout << endl; -// } -// cout << "solar_zenith" << endl; -// for (int relt = 0; relt < 16; relt++) { -// for (int rels = 0; rels < zscan; rels++) -// cout << " " << solar_zenith[((itrack * 16) + relt) * earth_views_per_scanline + rels]; // + (iscan * zscan)]; -// cout << endl; -// } -// } + // if( itrack == 0) + // { + // cout << "solar_azimuth" << endl; + // for (int relt = 0; relt < 16; relt++) { + // for (int rels = 0; rels < zscan; rels++) + // cout << " " << solar_azimuth[((itrack * 16) + relt) * earth_views_per_scanline + rels]; // + (iscan * zscan)]; + // cout << endl; + // } + // cout << "solar_zenith" << endl; + // for (int relt = 0; relt < 16; relt++) { + // for (int rels = 0; rels < zscan; rels++) + // cout << " " << solar_zenith[((itrack * 16) + relt) * earth_views_per_scanline + rels]; // + (iscan * zscan)]; + // cout << endl; + // } + // } } void SegmentVIIRSDNB::GetAlpha( float &ascan, float &atrack, int rels, int relt, int index, int zscan) @@ -1449,3 +1495,50 @@ void SegmentVIIRSDNB::GetAlpha( float &ascan, float &atrack, int rels, int relt, atrack = s16[relt]; } +void SegmentVIIRSDNB::getCentralCoords(double *startlon, double *startlat, double *endlon, double *endlat, int *startindex, int *endindex) +{ + if(geolatitude.isNull()) + { + *startlon = 0.0; + *startlat = 0.0; + *endlon = 0.0; + *endlat = 0.0; + return; + } + + for(int i = 0; i < this->NbrOfLines; i++) + { + *startindex = i; + *startlon = geolongitude[i * earth_views_per_scanline + (earth_views_per_scanline/2)]; + *startlat = geolatitude[i * earth_views_per_scanline + (earth_views_per_scanline/2)]; + if(abs(*startlon) <= 180.0 && abs(*startlat) <= 90.0) + break; + } + + for(int i = this->NbrOfLines - 1; i >= 0; i--) + { + *endindex = i; + *endlon = geolongitude[i * earth_views_per_scanline + (earth_views_per_scanline/2)]; + *endlat = geolatitude[i * earth_views_per_scanline + (earth_views_per_scanline/2)]; + if(abs(*endlon) <= 180.0 && abs(*endlat) <= 90.0) + break; + } + + cout << "=================LONGITUDE===========================" << endl; + for(int i = 0; i < this->NbrOfLines;i++) + { + cout << geolongitude[i * earth_views_per_scanline + (int)(earth_views_per_scanline/2)] << " "; + } + cout << endl; + + cout << "=================LATITUDE===========================" << endl; + for(int i = 0; i < this->NbrOfLines;i++) + { + cout << geolatitude[i * earth_views_per_scanline + (int)(earth_views_per_scanline/2)] << " "; + } + cout << endl; + + qDebug() << "SegmentVIIRSDNB::GetCentralCoords startindex = " << *startindex << " endindex = " << *endindex << " slon = " << *startlon << + " slat = " << *startlat << " elon = " << *endlon << " elat = " << *endlat; + +} diff --git a/core/segmentviirsdnb.h b/core/segmentviirsdnb.h index 5f1c6c1..b6570e5 100644 --- a/core/segmentviirsdnb.h +++ b/core/segmentviirsdnb.h @@ -23,11 +23,13 @@ class SegmentVIIRSDNB : public Segment void ComposeSegmentLCCProjection(int inputchannel, int histogrammethod, bool normalized); void ComposeSegmentGVProjection(int inputchannel, int histogrammethod, bool normalized); void ComposeSegmentSGProjection(int inputchannel, int histogrammethod, bool normalized); + void ComposeSegmentOMProjection(int inputchannel, int histogrammethod, bool normalized); void ComposeProjection(eProjections proj, int histogrammethod, bool normalized); void ComposeSegmentImageWindow(float lowerlimit, float upperlimit); void ComposeSegmentImageWindowFromCurve(QVector *x, QVector *y); void CalcGraph(QScopedArrayPointer *graph); + void getCentralCoords(double *startlon, double *startlat, double *endlon, double *endlat, int *startindex, int *endindex); int threshold[3]; float stat_max; diff --git a/core/segmentviirsm.cpp b/core/segmentviirsm.cpp index b5a607f..154a4f6 100644 --- a/core/segmentviirsm.cpp +++ b/core/segmentviirsm.cpp @@ -1796,7 +1796,7 @@ qint32 SegmentVIIRSM::Max(const qint32 v11, const qint32 v12, const qint32 v21, return Maximum; } -void SegmentVIIRSM::GetCentralCoords(double *startlon, double *startlat, double *endlon, double *endlat, int *startindex, int *endindex) +void SegmentVIIRSM::getCentralCoords(double *startlon, double *startlat, double *endlon, double *endlat, int *startindex, int *endindex) { if(geolatitude.isNull()) { @@ -1836,7 +1836,7 @@ void SegmentVIIRSM::GetCentralCoords(double *startlon, double *startlat, double } -void SegmentVIIRSM::GetStartCornerCoords(double *cornerlon1, double *cornerlat1, double *cornerlon2, double *cornerlat2, +void SegmentVIIRSM::getStartCornerCoords(double *cornerlon1, double *cornerlat1, double *cornerlon2, double *cornerlat2, int *Xstartindex1, int *Xstartindex2, int *Ystartindex12) { if(geolatitude.isNull()) @@ -1881,7 +1881,7 @@ void SegmentVIIRSM::GetStartCornerCoords(double *cornerlon1, double *cornerlat1, " Xstartindex1 = " << *Xstartindex1 << " Xstartindex2 = " << *Xstartindex2 << " Ystartindex12 = " << *Ystartindex12; } -void SegmentVIIRSM::GetEndCornerCoords(double *cornerlon3, double *cornerlat3, double *cornerlon4, double *cornerlat4, +void SegmentVIIRSM::getEndCornerCoords(double *cornerlon3, double *cornerlat3, double *cornerlon4, double *cornerlat4, int *Xstartindex3, int *Xstartindex4, int *Ystartindex34) { if(geolatitude.isNull()) diff --git a/core/segmentviirsm.h b/core/segmentviirsm.h index eb57632..dd8f9a6 100644 --- a/core/segmentviirsm.h +++ b/core/segmentviirsm.h @@ -42,10 +42,10 @@ class SegmentVIIRSM : public Segment float getBrightnessTemp(int radiance); float getRadiance(int lines, int views); float getRadiance(int radiance); - void GetCentralCoords(double *startlon, double *startlat, double *endlon, double *endlat, int *startindex, int *endindex); - void GetStartCornerCoords(double *cornerlon1, double *cornerlat1, double *cornerlon2, double *cornerlat2, + void getCentralCoords(double *startlon, double *startlat, double *endlon, double *endlat, int *startindex, int *endindex); + void getStartCornerCoords(double *cornerlon1, double *cornerlat1, double *cornerlon2, double *cornerlat2, int *Xstartindex1, int *Xstartindex2, int *Ystartindex12); - void GetEndCornerCoords(double *cornerlon3, double *cornerlat3, double *cornerlon4, double *cornerlat4, + void getEndCornerCoords(double *cornerlon3, double *cornerlat3, double *cornerlon4, double *cornerlat4, int *Xstartindex3, int *Xstartindex4, int *Ystartindex34); int stat_max_projection[3];