scan

package
v4.64.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Example (Scan_GeneratePolygons)
scanId := "189137412"
imgName := "189137412/PCO_0545_0715357896_000RCM_N02651501891374120096075J__.png"
//beamVersion := 3

// db := wstestlib.GetDBWithEnvironment("local-pixlise")
// ctx := context.TODO()
// coll := db.Collection(dbCollections.ScansName)
/*	result := coll.FindOne(ctx, bson.M{"_id": "189137412"})

	if result.Err() != nil {
		panic(result.Err())
	} else {
		scan := protos.ScanItem{}
		err := result.Decode(&scan)
		if err != nil {
			panic(err)
		}
	}
*/
fs := fileaccess.FSAccess{}
fileBytes, err := fs.ReadObject("./test-data/"+scanId+"-dataset.bin", "")
if err != nil {
	panic(err)
}

// Now decode the data & return it
datasetPB := &protos.Experiment{}
err = proto.Unmarshal(fileBytes, datasetPB)
if err != nil {
	panic(err)
}

scanItemData, err := os.ReadFile("./test-data/189137412-scan.json")
if err != nil {
	panic(err)
}

scanItem := &protos.ScanItem{}
err = protojson.Unmarshal(scanItemData, scanItem)
if err != nil {
	panic(err)
}

indexes := []uint32{}
// Use all indexes available in the file
for c := range datasetPB.Locations {
	indexes = append(indexes, uint32(c))
}

scanEntries, err := ReadScanEntries(datasetPB, indexes)
if err != nil {
	panic(err)
}

xyz := ReadXYZ(datasetPB, indexes)
ij := []*protos.Coordinate2D{}

ijData, err := os.ReadFile("./test-data/189137412-ijs.json")
if err != nil {
	panic(err)
}

err = json.Unmarshal(ijData, &ij)
if err != nil {
	panic(err)
}
/*
	coll = db.Collection(dbCollections.ImageBeamLocationsName)

	// Read the image and check that the user has access to all scans associated with it
	imgResult := coll.FindOne(ctx, bson.M{"_id": imgName})

	var dbLocs *protos.ImageLocations
	err = imgResult.Decode(&dbLocs)
	if err != nil {
		panic(err)
	}

	for _, loc := range dbLocs.LocationPerScan {
		if loc.ScanId == scanId && loc.BeamVersion == uint32(beamVersion) {
			ij = loc.Locations
			break
		}
	}
*/

// d, _ := json.Marshal(ij)
// os.WriteFile("./test-data/189137412-ijs.json", d, 777)

if len(ij) <= 0 {
	panic("No ijs loaded")
}

configStr := `{
    "id": "PIXL",
    "minElement": 11,
    "maxElement": 92,
    "xrfeVLowerBound": 800,
    "xrfeVUpperBound": 20000,
    "xrfeVResolution": 230,
    "windowElement": 14,
    "tubeElement": 45,
    "defaultParams": "",
    "mmBeamRadius": 0.05999999865889549,
    "elevAngle": 70
}`
config := &protos.DetectorConfig{}
err = protojson.Unmarshal([]byte(configStr), config)
if err != nil {
	panic(err)
}

resp, err := GeneratePolygons(
	imgName,
	scanItem,
	scanEntries,
	xyz,
	//beamVersion,
	&ij,
	config,
)

//json, err := protojson.Marshal(resp)
fmt.Printf("%v|clusters=%v|footprints=%v|mmconversion=%v|dispradius=%v\n", err, len(resp.PointClusters), len(resp.Footprints), resp.PixelToMMConversion, resp.ScanPointDisplayRadius)

// The output text is comparing the chrome debug console output with what happened in Go. Changes
// allowed for:
// - Go outputs: Location data physical size X=0.024586006999015808, Y=0.016534999012947083, Z=5.50001859664917e-05
//   where Z is the same as Z=0.0000550001859664917 so changing the expected value to the Go output
// - The original code randomly sampled 1000 PMCs to find the min distance and work out a display point radius. We
//   don't random sample, we're server side so have time, and we check each point. This might get slow for large
//   scans but we'll deal with that when it happens. For now, the min distance of this scan is 2.543132907103864
Output:
  Location position relative to context image: (x,y)=49,135, (w,h)=530,339
  Location data physical size X=0.024586006999015808, Y=0.016534999012947083, Z=5.50001859664917e-05
  Beam location is in meters
  Conversion factor for image pixels to mm: 0.04709422455222193
  Generated locationDisplayPointRadius: 2.543132907103864
  Point cluster 1 contains 25 PMCs, 12 footprint points, 0.000 degrees rotated
  Point cluster 2 contains 51 PMCs, 12 footprint points, -39.878 degrees rotated
  Point cluster 3 contains 51 PMCs, 14 footprint points, 49.857 degrees rotated
  Point cluster 4 contains 51 PMCs, 14 footprint points, -40.000 degrees rotated
  Point cluster 5 contains 25 PMCs, 12 footprint points, 0.000 degrees rotated
  Point cluster 6 contains 25 PMCs, 14 footprint points, 0.000 degrees rotated
  Point cluster 7 contains 25 PMCs, 11 footprint points, 0.000 degrees rotated
  Point cluster 8 contains 51 PMCs, 14 footprint points, 39.928 degrees rotated
  Point cluster 9 contains 51 PMCs, 15 footprint points, 40.075 degrees rotated
  Point cluster 10 contains 51 PMCs, 13 footprint points, 40.234 degrees rotated
  Point cluster 11 contains 153 PMCs, 16 footprint points, 126.771 degrees rotated
  Point cluster 12 contains 153 PMCs, 15 footprint points, 39.604 degrees rotated
  Point cluster 13 contains 51 PMCs, 15 footprint points, 42.187 degrees rotated
  Point cluster 14 contains 51 PMCs, 14 footprint points, 42.403 degrees rotated
  Point cluster 15 contains 51 PMCs, 14 footprint points, 42.584 degrees rotated
<nil>|clusters=15|footprints=15|mmconversion=0.04709422455222193|dispradius=2.543132907103864

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GeneratePolygons added in v4.63.1

func GeneratePolygons(imageName string,
	scanItem *protos.ScanItem,
	scanEntries []*protos.ScanEntry,
	beamXYZs []*protos.Coordinate3D,
	beamIJs *[]*protos.Coordinate2D,
	detectorConfig *protos.DetectorConfig,
) (*protos.ImageScanEntryDisplayElementsGetResp, error)

func ReadScanEntries added in v4.63.1

func ReadScanEntries(exprPB *protos.Experiment, indexes []uint32) ([]*protos.ScanEntry, error)

func ReadScanItem

func ReadScanItem(scanId string, db *mongo.Database) (*protos.ScanItem, error)

func ReadXYZ added in v4.63.1

func ReadXYZ(exprPB *protos.Experiment, indexes []uint32) []*protos.Coordinate3D

Types

type HullPoint added in v4.63.1

type HullPoint struct {
	Point  Point
	Idx    int
	Normal *Point
}

func QuickHull added in v4.63.1

func QuickHull(points []HullPoint) ([]HullPoint, error)

type MinMax added in v4.63.1

type MinMax struct {
	Min *float64
	Max *float64
}

type Point added in v4.63.1

type Point struct {
	X float64
	Y float64
}

type PointCluster added in v4.63.1

type PointCluster struct {
	LocIdxs                    []int
	PointDistance              float64
	FootprintPoints            []HullPoint
	AngleRadiansToContextImage float64
}

type QuickHullGenerator added in v4.63.1

type QuickHullGenerator struct {
	// contains filtered or unexported fields
}

type Rect added in v4.63.1

type Rect struct {
	X float64
	Y float64
	W float64
	H float64
}

type ScanPoint added in v4.63.1

type ScanPoint struct {
	PMC uint32
	// contains filtered or unexported fields
}

type ScanPointPolygon added in v4.63.1

type ScanPointPolygon struct {
	BBox   Rect
	Points []Point
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL