forked from mrrtf/pigiron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsegmentation3.go
169 lines (144 loc) · 4.46 KB
/
segmentation3.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package mapping
import (
"errors"
"fmt"
"log"
)
var ErrInvalidPadUID = errors.New("invalid pad uid")
const InvalidPadUID int = -1
type segmentation3 struct {
segType int
isBendingPlane bool
padGroups []padGroup
padGroupTypes []padGroupType
padSizes []padSize
dualSampaIDs []int
padGroupIndex2PadUIDIndex []int
padUID2PadGroupTypeFastIndex []int
padUID2PadGroupIndex []int
}
func (seg *segmentation3) NofDualSampas() int {
return len(seg.dualSampaIDs)
}
// NewSegmentation creates a segmentation object for the given detection element plane
func NewSegmentation(detElemID int, isBendingPlane bool) Segmentation {
segType, err := detElemID2SegType(detElemID)
if err != nil {
return nil
}
builder := getSegmentationBuilder(segType)
if builder == nil {
return nil
}
return builder.Build(isBendingPlane)
}
func print(seg *segmentation3) {
fmt.Println("segmentation3 has ", len(seg.dualSampaIDs), " dual sampa ids")
}
func newSegmentation(segType int, isBendingPlane bool, padGroups []padGroup,
padGroupTypes []padGroupType, padSizes []padSize) *segmentation3 {
seg := &segmentation3{segType, isBendingPlane, padGroups, padGroupTypes, padSizes, []int{}, []int{}, []int{}, []int{}}
uniq := make(map[int]struct{})
var empty struct{}
for i := range padGroups {
uniq[padGroups[i].fecID] = empty
}
for key := range uniq {
seg.dualSampaIDs = append(seg.dualSampaIDs, key)
}
seg.init()
return seg
}
func (seg *segmentation3) init() {
paduid := 0
for padGroupIndex := range seg.padGroups {
seg.padGroupIndex2PadUIDIndex = append(seg.padGroupIndex2PadUIDIndex, paduid)
pg := seg.padGroups[padGroupIndex]
pgt := seg.padGroupTypes[pg.padGroupTypeID]
for ix := 0; ix < pgt.nofPads; ix++ {
for iy := 0; iy < pgt.nofPadsY; iy++ {
if pgt.idByIndices(ix, iy) >= 0 {
seg.padUID2PadGroupIndex = append(seg.padUID2PadGroupIndex, padGroupIndex)
seg.padUID2PadGroupTypeFastIndex = append(seg.padUID2PadGroupTypeFastIndex, pgt.fastIndex(ix, iy))
paduid++
}
}
}
}
}
func (seg *segmentation3) getPadUIDs(dualSampaID int) []int {
pi := []int{}
for pgi := range seg.padGroups {
pg := seg.padGroups[pgi]
if pg.fecID == dualSampaID {
pgt := seg.padGroupTypes[pg.padGroupTypeID]
i1 := seg.padGroupIndex2PadUIDIndex[pgi]
for i := i1; i < i1+pgt.nofPads; i++ {
pi = append(pi, i)
}
}
}
return pi
}
func (seg *segmentation3) DualSampaID(dualSampaIndex int) (int, error) {
if dualSampaIndex >= len(seg.dualSampaIDs) {
return -1, fmt.Errorf("Incorrect dualSampaIndex %d (should be within 0-%d range", dualSampaIndex,
len(seg.dualSampaIDs))
}
return seg.dualSampaIDs[dualSampaIndex], nil
}
func (seg *segmentation3) NofPads() int {
n := 0
for i := 0; i < seg.NofDualSampas(); i++ {
dsid, err := seg.DualSampaID(i)
if err != nil {
log.Fatalf("Could not get DualSampaID for i=%d", i)
}
n += len(seg.getPadUIDs(dsid))
}
return n
}
func (seg *segmentation3) ForEachPadInDualSampa(dualSampaID int, padHandler func(paduid int)) {
for _, paduid := range seg.getPadUIDs(dualSampaID) {
padHandler(paduid)
}
}
func (seg *segmentation3) PadDualSampaChannel(paduid int) int {
return seg.padGroupType(paduid).idByFastIndex(seg.padUID2PadGroupTypeFastIndex[paduid])
}
func (seg *segmentation3) PadDualSampaID(paduid int) int {
return seg.padGroup(paduid).fecID
}
func (seg *segmentation3) padGroup(paduid int) padGroup {
return seg.padGroups[seg.padUID2PadGroupIndex[paduid]]
}
func (seg *segmentation3) padGroupType(paduid int) padGroupType {
return seg.padGroupTypes[seg.padGroup(paduid).padGroupTypeID]
}
func (seg *segmentation3) IsValid(paduid int) bool {
return paduid != InvalidPadUID
}
func (seg *segmentation3) FindPadByFEE(dualSampaID, dualSampaChannel int) (int, error) {
for _, paduid := range seg.getPadUIDs(dualSampaID) {
if seg.padGroupType(paduid).idByFastIndex(seg.padUID2PadGroupTypeFastIndex[paduid]) == dualSampaChannel {
return paduid, nil
}
}
return InvalidPadUID, ErrInvalidPadUID
}
/// FIXME : to be implemented...
func (seg *segmentation3) FindPadByPosition(x, y float64) (int, error) {
return 0, fmt.Errorf("invalid pad")
}
func (seg *segmentation3) PadPositionX(paduid int) float64 {
return 0
}
func (seg *segmentation3) PadPositionY(paduid int) float64 {
return 0
}
func (seg *segmentation3) PadSizeX(paduid int) float64 {
return 0
}
func (seg *segmentation3) PadSizeY(paduid int) float64 {
return 0
}