174 lines
5.3 KiB
Go
174 lines
5.3 KiB
Go
package producer
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
"time"
|
|
|
|
"github.com/duke-git/lancet/v2/mathutil"
|
|
"github.com/paulmach/orb"
|
|
"github.com/paulmach/orb/geo"
|
|
"github.com/paulmach/orb/planar"
|
|
"starwiz.cn/sjy01/image-proc/pkg/auxilary"
|
|
"starwiz.cn/sjy01/image-proc/pkg/calculator"
|
|
)
|
|
|
|
func (r *Registrator) LoadAuxData() error {
|
|
var err error
|
|
r.auxHeads, r.auxBoxes, r.AuxPlatforms, err = auxilary.ExtractAux(r.Params.AuxRawFile)
|
|
return err
|
|
}
|
|
|
|
func (r *Registrator) SceneImageTime(scene *Scene) (start, center, end time.Time) {
|
|
startPosInAux, endPosInAux := r.SceneInAuxIndex(scene)
|
|
centerPosInAux := (startPosInAux + endPosInAux) / 2
|
|
|
|
start = time.Unix(int64(auxilary.ReferenceTime2000)+int64(r.AuxPlatforms[startPosInAux].UTCTimeSec),
|
|
int64(r.AuxPlatforms[startPosInAux].Microsecond)*1000)
|
|
center = time.Unix(int64(auxilary.ReferenceTime2000)+int64(r.AuxPlatforms[centerPosInAux].UTCTimeSec),
|
|
int64(r.AuxPlatforms[centerPosInAux].Microsecond)*1000)
|
|
end = time.Unix(int64(auxilary.ReferenceTime2000)+int64(r.AuxPlatforms[endPosInAux].UTCTimeSec),
|
|
int64(r.AuxPlatforms[endPosInAux].Microsecond)*1000)
|
|
|
|
return
|
|
}
|
|
|
|
// FIXME: 位置像元经纬度计算方法,暂时使用星下点替代
|
|
func (r *Registrator) ScenePosition(scene *Scene) (topLeft, bottomRight orb.Point) {
|
|
// // startPosInAux, endPosInAux := r.SceneInAuxIndex(scene)
|
|
// ap := r.AuxPlatforms[0]
|
|
// // ap1 := r.AuxPlatforms[endPosInAux]
|
|
// lat0, lng0, _ := calculator.WGS84XYZtoLatLngH(ap.WGS84PosX, ap.WGS84PosY, ap.WGS84PosZ)
|
|
|
|
// lat, lng := calculator.CalculateDestination(lat0, lng0,
|
|
// float64(scene.Width)*scene.Meta.Gsd, float64(-scene.Y)*scene.Meta.Gsd)
|
|
// lat1, lng1 := calculator.CalculateDestination(lat, lng,
|
|
// float64(scene.Width)*scene.Meta.Gsd, float64(-scene.Height)*scene.Meta.Gsd)
|
|
|
|
// poly := orb.Polygon{
|
|
// {
|
|
// {lng, lat},
|
|
// {lng1, lat},
|
|
// {lng1, lat1},
|
|
// {lng, lat1},
|
|
// {lng, lat},
|
|
// },
|
|
// }
|
|
|
|
startPosInAux, endPosInAux := r.SceneInAuxIndex(scene)
|
|
|
|
as := r.AuxPlatforms[startPosInAux]
|
|
startPos := []float64{as.W84PosX, as.W84PosY, as.W84PosZ}
|
|
startTime := time.Unix(int64(auxilary.ReferenceTime2000)+int64(as.UTCTimeSec),
|
|
int64(as.Microsecond)*1000).UTC()
|
|
lat0, lng0 := calculator.Intersection(
|
|
calculator.Quaternion{W: as.QuatAttstarQ0, X: as.QuatAttstarQ1, Y: as.QuatAttstarQ2, Z: as.QuatAttstarQ3},
|
|
startPos,
|
|
startTime,
|
|
0,
|
|
)
|
|
lat01, lng01 := calculator.Intersection(
|
|
calculator.Quaternion{W: as.QuatAttstarQ0, X: as.QuatAttstarQ1, Y: as.QuatAttstarQ2, Z: as.QuatAttstarQ3},
|
|
startPos,
|
|
startTime,
|
|
9344,
|
|
)
|
|
|
|
fmt.Println("distance 0: ", geo.Distance(orb.Point{lng0, lat0}, orb.Point{lng01, lat01}))
|
|
|
|
ae := r.AuxPlatforms[endPosInAux]
|
|
endPos := []float64{ae.W84PosX, ae.W84PosY, ae.W84PosZ}
|
|
endTime := time.Unix(int64(auxilary.ReferenceTime2000)+int64(ae.UTCTimeSec),
|
|
int64(ae.Microsecond)*1000).UTC()
|
|
lat2, lng2 := calculator.Intersection(
|
|
calculator.Quaternion{W: ae.QuatAttstarQ0, X: ae.QuatAttstarQ1, Y: ae.QuatAttstarQ2, Z: ae.QuatAttstarQ3},
|
|
endPos,
|
|
endTime,
|
|
0,
|
|
)
|
|
lat3, lng3 := calculator.Intersection(
|
|
calculator.Quaternion{W: ae.QuatAttstarQ0, X: ae.QuatAttstarQ1, Y: ae.QuatAttstarQ2, Z: ae.QuatAttstarQ3},
|
|
endPos,
|
|
endTime,
|
|
9344,
|
|
)
|
|
|
|
fmt.Println("distance 1: ", geo.Distance(orb.Point{lng2, lat2}, orb.Point{lng3, lat3}))
|
|
|
|
// 求外接矩形
|
|
lat := mathutil.Min(lat0, lat01, lat2, lat3)
|
|
lng := mathutil.Min(lng0, lng01, lng2, lng3)
|
|
lat1 := mathutil.Max(lat0, lat01, lat2, lat3)
|
|
lng1 := mathutil.Max(lng0, lng01, lng2, lng3)
|
|
|
|
poly := orb.Polygon{
|
|
{
|
|
{lng, lat},
|
|
{lng1, lat},
|
|
{lng1, lat1},
|
|
{lng, lat1},
|
|
{lng, lat},
|
|
},
|
|
}
|
|
|
|
centroid, _ := planar.CentroidArea(poly)
|
|
scene.Meta.CentreLocation.Latitude = centroid.Y()
|
|
scene.Meta.CentreLocation.Longitude = centroid.X()
|
|
scene.Meta.Corners.UpperLeft.Latitude = lat
|
|
scene.Meta.Corners.UpperLeft.Longitude = lng
|
|
scene.Meta.Corners.UpperRight.Latitude = lat
|
|
scene.Meta.Corners.UpperRight.Longitude = lng1
|
|
scene.Meta.Corners.LowerLeft.Latitude = lat1
|
|
scene.Meta.Corners.LowerLeft.Longitude = lng
|
|
scene.Meta.Corners.LowerRight.Latitude = lat1
|
|
scene.Meta.Corners.LowerRight.Longitude = lng1
|
|
|
|
scene.Meta.Corners.UpperLeft.Latitude = lat0
|
|
scene.Meta.Corners.UpperLeft.Longitude = lng0
|
|
scene.Meta.Corners.UpperRight.Latitude = lat01
|
|
scene.Meta.Corners.UpperRight.Longitude = lng01
|
|
scene.Meta.Corners.LowerLeft.Latitude = lat2
|
|
scene.Meta.Corners.LowerLeft.Longitude = lng2
|
|
scene.Meta.Corners.LowerRight.Latitude = lat3
|
|
scene.Meta.Corners.LowerRight.Longitude = lng3
|
|
|
|
scene.Meta.SatPosX = ae.WGS84PosX
|
|
scene.Meta.SatPosY = ae.WGS84PosY
|
|
scene.Meta.SatPosZ = ae.WGS84PosZ
|
|
scene.Meta.Yaw = ae.Eular3 * 180 / math.Pi
|
|
scene.Meta.Pitch = ae.Eular2 * 180 / math.Pi
|
|
scene.Meta.Roll = ae.Eular1 * 180 / math.Pi
|
|
|
|
// feature := geojson.NewFeature(poly)
|
|
// fcs.Features = append(fcs.Features, feature)
|
|
|
|
// fd, _ := fcs.MarshalJSON()
|
|
// fmt.Println(string(fd))
|
|
|
|
return
|
|
}
|
|
|
|
func (r *Registrator) SceneInAuxIndex(scene *Scene) (int, int) {
|
|
var auxForImageRow int
|
|
switch scene.Type {
|
|
case "MSS":
|
|
auxForImageRow = 4
|
|
case "PAN":
|
|
auxForImageRow = 16
|
|
case "FUS":
|
|
auxForImageRow = 16
|
|
}
|
|
|
|
startPosInAux := scene.Y / auxForImageRow
|
|
if startPosInAux >= len(r.AuxPlatforms) {
|
|
startPosInAux = len(r.AuxPlatforms) - 1
|
|
}
|
|
|
|
endPosInAux := (scene.Y + scene.Height) / auxForImageRow
|
|
if endPosInAux >= len(r.AuxPlatforms) {
|
|
endPosInAux = len(r.AuxPlatforms) - 1
|
|
}
|
|
|
|
return startPosInAux, endPosInAux
|
|
}
|