1 | #include "muscle.h" |
---|
2 | #include "dpreglist.h" |
---|
3 | |
---|
4 | unsigned DPRegionList::GetDPArea() const |
---|
5 | { |
---|
6 | unsigned uArea = 0; |
---|
7 | for (unsigned i = 0; i < m_uCount; ++i) |
---|
8 | { |
---|
9 | const DPRegion &r = m_DPRegions[i]; |
---|
10 | if (DPREGIONTYPE_Rect == r.m_Type) |
---|
11 | uArea += r.m_Rect.m_uLengthA*r.m_Rect.m_uLengthB; |
---|
12 | } |
---|
13 | return uArea; |
---|
14 | } |
---|
15 | |
---|
16 | void DPRegionList::Add(const DPRegion &r) |
---|
17 | { |
---|
18 | if (m_uCount == MAX_DPREGIONS) |
---|
19 | Quit("DPRegionList::Add, overflow %d", m_uCount); |
---|
20 | m_DPRegions[m_uCount] = r; |
---|
21 | ++m_uCount; |
---|
22 | } |
---|
23 | |
---|
24 | void DPRegionList::LogMe() const |
---|
25 | { |
---|
26 | Log("DPRegionList::LogMe, count=%u\n", m_uCount); |
---|
27 | Log("Region Type StartA StartB EndA EndB\n"); |
---|
28 | Log("------ ---- ------ ------ ---- ----\n"); |
---|
29 | for (unsigned i = 0; i < m_uCount; ++i) |
---|
30 | { |
---|
31 | const DPRegion &r = m_DPRegions[i]; |
---|
32 | Log("%6u ", i); |
---|
33 | if (DPREGIONTYPE_Diag == r.m_Type) |
---|
34 | Log("Diag %6u %6u %6u %6u\n", |
---|
35 | r.m_Diag.m_uStartPosA, |
---|
36 | r.m_Diag.m_uStartPosB, |
---|
37 | r.m_Diag.m_uStartPosA + r.m_Diag.m_uLength - 1, |
---|
38 | r.m_Diag.m_uStartPosB + r.m_Diag.m_uLength - 1); |
---|
39 | else if (DPREGIONTYPE_Rect == r.m_Type) |
---|
40 | Log("Rect %6u %6u %6u %6u\n", |
---|
41 | r.m_Rect.m_uStartPosA, |
---|
42 | r.m_Rect.m_uStartPosB, |
---|
43 | r.m_Rect.m_uStartPosA + r.m_Rect.m_uLengthA - 1, |
---|
44 | r.m_Rect.m_uStartPosB + r.m_Rect.m_uLengthB - 1); |
---|
45 | else |
---|
46 | Log(" *** ERROR *** Type=%u\n", r.m_Type); |
---|
47 | } |
---|
48 | } |
---|
49 | |
---|
50 | void DiagListToDPRegionList(const DiagList &DL, DPRegionList &RL, |
---|
51 | unsigned uLengthA, unsigned uLengthB) |
---|
52 | { |
---|
53 | if (g_uDiagMargin > g_uMinDiagLength/2) |
---|
54 | Quit("Invalid parameters, diagmargin=%d must be <= 2*diaglength=%d", |
---|
55 | g_uDiagMargin, g_uMinDiagLength); |
---|
56 | |
---|
57 | unsigned uStartPosA = 0; |
---|
58 | unsigned uStartPosB = 0; |
---|
59 | const unsigned uDiagCount = DL.GetCount(); |
---|
60 | DPRegion r; |
---|
61 | for (unsigned uDiagIndex = 0; uDiagIndex < uDiagCount; ++uDiagIndex) |
---|
62 | { |
---|
63 | const Diag &d = DL.Get(uDiagIndex); |
---|
64 | assert(d.m_uLength >= g_uMinDiagLength); |
---|
65 | const unsigned uStartVertexA = d.m_uStartPosA + g_uDiagMargin - 1; |
---|
66 | const unsigned uStartVertexB = d.m_uStartPosB + g_uDiagMargin - 1; |
---|
67 | const unsigned uEndVertexA = d.m_uStartPosA + d.m_uLength - g_uDiagMargin; |
---|
68 | const unsigned uEndVertexB = d.m_uStartPosB + d.m_uLength - g_uDiagMargin; |
---|
69 | |
---|
70 | r.m_Type = DPREGIONTYPE_Rect; |
---|
71 | r.m_Rect.m_uStartPosA = uStartPosA; |
---|
72 | r.m_Rect.m_uStartPosB = uStartPosB; |
---|
73 | |
---|
74 | assert(uStartVertexA + 1 >= uStartPosA); |
---|
75 | assert(uStartVertexB + 1 >= uStartPosB); |
---|
76 | r.m_Rect.m_uLengthA = uStartVertexA + 1 - uStartPosA; |
---|
77 | r.m_Rect.m_uLengthB = uStartVertexB + 1 - uStartPosB; |
---|
78 | RL.Add(r); |
---|
79 | |
---|
80 | if (uEndVertexA > uStartVertexA + 1) |
---|
81 | { |
---|
82 | const unsigned uDiagLengthMinusCaps = uEndVertexA - uStartVertexA - 1; |
---|
83 | |
---|
84 | r.m_Type = DPREGIONTYPE_Diag; |
---|
85 | r.m_Diag.m_uStartPosA = uStartVertexA + 1; |
---|
86 | r.m_Diag.m_uStartPosB = uStartVertexB + 1; |
---|
87 | assert(uEndVertexA - uStartVertexA == uEndVertexB - uStartVertexB); |
---|
88 | r.m_Diag.m_uLength = uEndVertexA - uStartVertexA - 1; |
---|
89 | RL.Add(r); |
---|
90 | } |
---|
91 | |
---|
92 | uStartPosA = uEndVertexA; |
---|
93 | uStartPosB = uEndVertexB; |
---|
94 | } |
---|
95 | |
---|
96 | assert((int) uLengthA - (int) uStartPosA >= (int) g_uDiagMargin); |
---|
97 | assert((int) uLengthB - (int) uStartPosB >= (int) g_uDiagMargin); |
---|
98 | |
---|
99 | r.m_Type = DPREGIONTYPE_Rect; |
---|
100 | r.m_Rect.m_uStartPosA = uStartPosA; |
---|
101 | r.m_Rect.m_uStartPosB = uStartPosB; |
---|
102 | |
---|
103 | assert(uLengthA >= uStartPosA); |
---|
104 | assert(uLengthB >= uStartPosB); |
---|
105 | r.m_Rect.m_uLengthA = uLengthA - uStartPosA; |
---|
106 | r.m_Rect.m_uLengthB = uLengthB - uStartPosB; |
---|
107 | RL.Add(r); |
---|
108 | } |
---|