Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
imagej-elphel
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Elphel
imagej-elphel
Commits
1ca1c6d0
Commit
1ca1c6d0
authored
May 18, 2017
by
Andrey Filippov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
increasing range to 2 supertiles when calculating connection costs
parent
ada2ac85
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
842 additions
and
147 deletions
+842
-147
Conflicts.java
src/main/java/Conflicts.java
+15
-3
ConnectionCosts.java
src/main/java/ConnectionCosts.java
+444
-0
EyesisCorrectionParameters.java
src/main/java/EyesisCorrectionParameters.java
+11
-0
SuperTiles.java
src/main/java/SuperTiles.java
+343
-50
TilePlanes.java
src/main/java/TilePlanes.java
+10
-0
TileProcessor.java
src/main/java/TileProcessor.java
+19
-94
No files found.
src/main/java/Conflicts.java
View file @
1ca1c6d0
...
...
@@ -32,7 +32,7 @@ public class Conflicts {
private
int
[]
num_all_conflicts
=
new
int
[
24
];
private
int
num_ortho_incompat
=
0
;
private
int
num_ortho_dual
=
0
;
private
int
num_conflicts
;
private
int
num_conflicts
=
0
;
private
SuperTiles
st
=
null
;
public
Conflicts
(
...
...
@@ -89,6 +89,18 @@ public class Conflicts {
num_conflicts
+=
s
*
conflicts
.
num_conflicts
;
}
public
void
resetConflicts
()
{
num_ortho_diag_ortho
=
new
int
[
8
];
num_ortho_ortho_diag
=
new
int
[
16
];
num_all_conflicts
=
new
int
[
24
];
num_ortho_incompat
=
0
;
num_ortho_dual
=
0
;
num_conflicts
=
0
;
}
public
int
addConflicts
(
int
[][][]
conflicts
,
...
...
@@ -104,7 +116,7 @@ public class Conflicts {
num_ortho_dual
+=
conf
.
getDualTriOrthoDiagOrthoConflicts
();
num_conflicts
+=
conf
.
getNumConflicts
();
if
(
debugLevel
>
0
){
printConflict
(
"addConflicts() nsTile = "
+
nsTile
,
conf
);
printConflict
(
"addConflicts() nsTile = "
+
nsTile
+
" "
,
conf
);
}
}
}
...
...
@@ -125,7 +137,7 @@ public class Conflicts {
num_ortho_dual
+=
conf
.
getDualTriOrthoDiagOrthoConflicts
();
num_conflicts
+=
conf
.
getNumConflicts
();
if
(
debugLevel
>
0
){
printConflict
(
"addConflicts() nsTile = "
+
nsTile
,
conf
);
printConflict
(
"addConflicts() nsTile = "
+
nsTile
+
" "
,
conf
);
}
}
}
...
...
src/main/java/ConnectionCosts.java
0 → 100644
View file @
1ca1c6d0
import
java.awt.Point
;
import
java.util.HashMap
;
import
java.util.HashSet
;
/**
**
** ConnectionCosts - calculate and incrementally update cost of supertile connections
**
** Copyright (C) 2017 Elphel, Inc.
**
** -----------------------------------------------------------------------------**
**
** ConnectionCosts.java is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
** -----------------------------------------------------------------------------**
**
*/
public
class
ConnectionCosts
{
TilePlanes
.
PlaneData
[][]
planes
=
null
;
boolean
preferDisparity
=
false
;
TileSurface
.
TileNeibs
tnSurface
;
double
orthoWeight
;
double
diagonalWeight
;
double
starPwr
;
// Divide cost by number of connections to this power
int
steps
;
int
[][][]
neibs_init
;
int
[]
mod_tiles
;
int
[]
all_tiles
;
double
[][][]
val_weights
;
double
init_val
;
double
init_weight
;
HashMap
<
Integer
,
Integer
>
tile_map
;
// map from tile full index to index in neibs[] and
public
ConnectionCosts
(
double
orthoWeight
,
double
diagonalWeight
,
double
starPwr
,
// Divide cost by number of connections to this power
int
steps
,
TilePlanes
.
PlaneData
[][]
planes
,
TileSurface
.
TileNeibs
tnSurface
,
boolean
preferDisparity
)
{
this
.
planes
=
planes
;
this
.
preferDisparity
=
preferDisparity
;
this
.
tnSurface
=
tnSurface
;
this
.
orthoWeight
=
orthoWeight
;
this
.
diagonalWeight
=
diagonalWeight
;
this
.
starPwr
=
starPwr
;
// Divide cost by number of connections to this power
this
.
steps
=
steps
;
}
public
int
[][][]
initConnectionCosts
(
int
[]
nsTiles
)
{
int
[]
exp_tiles
=
nsTiles
;
for
(
int
i
=
1
;
i
<
steps
;
i
++)
exp_tiles
=
getInvolvedSupertiles
(
exp_tiles
);
mod_tiles
=
nsTiles
;
all_tiles
=
exp_tiles
;
val_weights
=
new
double
[
all_tiles
.
length
][][];
neibs_init
=
new
int
[
mod_tiles
.
length
][][];
for
(
int
isTile
=
0
;
isTile
<
mod_tiles
.
length
;
isTile
++){
int
nsTile
=
mod_tiles
[
isTile
];
if
(
planes
[
nsTile
]
!=
null
){
neibs_init
[
isTile
]
=
new
int
[
planes
[
nsTile
].
length
][];
for
(
int
nl
=
0
;
nl
<
planes
[
nsTile
].
length
;
nl
++)
if
(
planes
[
nsTile
][
nl
]
!=
null
){
neibs_init
[
isTile
][
nl
]
=
planes
[
nsTile
][
nl
].
getNeibBest
();
}
}
}
for
(
int
isTile
=
0
;
isTile
<
all_tiles
.
length
;
isTile
++){
int
nsTile
=
all_tiles
[
isTile
];
if
(
planes
[
nsTile
]
!=
null
){
val_weights
[
isTile
]
=
new
double
[
planes
[
nsTile
].
length
][];
for
(
int
nl
=
0
;
nl
<
planes
[
nsTile
].
length
;
nl
++)
if
(
planes
[
nsTile
][
nl
]
!=
null
){
val_weights
[
isTile
][
nl
]
=
new
double
[
2
];
}
}
}
tile_map
=
new
HashMap
<
Integer
,
Integer
>();
for
(
int
i
=
0
;
i
<
mod_tiles
.
length
;
i
++){
tile_map
.
put
(
mod_tiles
[
i
],
i
);
}
switch
(
steps
){
case
1
:
val_weights
=
getConnectionsCostSingleStep
(
null
,
-
1
);
// int debugLevel)
break
;
case
2
:
val_weights
=
getConnectionsCostDualStep
(
null
,
-
1
);
// int debugLevel)
break
;
default
:
val_weights
=
getConnectionsCostSingleStep
(
null
,
-
1
);
// int debugLevel)
}
init_val
=
0.0
;
init_weight
=
0.0
;
// should not change during update
for
(
int
isTile
=
0
;
isTile
<
all_tiles
.
length
;
isTile
++){
if
(
val_weights
[
isTile
]
!=
null
){
for
(
int
nl
=
0
;
nl
<
val_weights
[
isTile
].
length
;
nl
++)
if
(
val_weights
[
isTile
][
nl
]
!=
null
){
init_val
+=
val_weights
[
isTile
][
nl
][
0
]
*
val_weights
[
isTile
][
nl
][
1
];
init_weight
+=
val_weights
[
isTile
][
nl
][
1
];
}
}
}
// Likely weight will never change except first run, but we will still normalize by weight
if
(
init_weight
!=
0.0
)
init_val
/=
init_weight
;
return
neibs_init
;
// neighbors to clone
}
public
double
[][][]
getConnectionsCostSingleStep
(
int
[][][]
neibs
,
int
debugLevel
)
{
boolean
force
=
(
neibs
==
null
);
if
(
force
)
neibs
=
neibs_init
;
double
[][][]
vw
=
new
double
[
all_tiles
.
length
][][];
// now re-calculate val_weights where neibs are different from neibs_prev
for
(
int
isTile
=
0
;
isTile
<
all_tiles
.
length
;
isTile
++){
int
nsTile
=
all_tiles
[
isTile
];
if
(
planes
[
nsTile
]
!=
null
)
{
int
ineib
=
(
tile_map
.
containsKey
(
nsTile
))?
tile_map
.
get
(
nsTile
)
:
-
1
;
if
(
neibs
[
isTile
]
!=
null
){
vw
[
isTile
]
=
new
double
[
planes
[
nsTile
].
length
][];
for
(
int
nl
=
0
;
nl
<
planes
[
nsTile
].
length
;
nl
++)
if
(
planes
[
nsTile
][
nl
]
!=
null
){
if
((
ineib
>=
0
)
&&
(
neibs
[
ineib
][
nl
]
!=
null
))
{
// here just ignoring all tiles outside core ones (should be none)
boolean
neibs_changed
=
false
;
if
(
force
){
neibs_changed
=
true
;
}
else
{
for
(
int
dir
=
0
;
dir
<
8
;
dir
++)
if
(
neibs
[
isTile
][
nl
][
dir
]
!=
neibs_init
[
isTile
][
nl
][
dir
]){
neibs_changed
=
true
;
break
;
}
}
if
(
neibs_changed
){
vw
[
isTile
][
nl
]
=
getStarValueWeight
(
nsTile
,
nl
,
neibs
[
isTile
][
nl
],
orthoWeight
,
diagonalWeight
,
starPwr
,
// double starPwr, // Divide cost by number of connections to this power
tnSurface
,
preferDisparity
,
-
1
);
// debugLevel);
}
else
{
vw
[
isTile
][
nl
]
=
val_weights
[
isTile
][
nl
];
}
}
else
{
vw
[
isTile
][
nl
]
=
null
;
}
}
}
else
{
vw
[
isTile
]
=
null
;
}
}
}
return
vw
;
// negative - improvement
}
public
double
[][][]
getConnectionsCostDualStep
(
int
[][][]
neibs
,
int
debugLevel
)
{
boolean
force
=
(
neibs
==
null
);
if
(
force
)
neibs
=
neibs_init
;
double
[][][]
vw
=
new
double
[
all_tiles
.
length
][][];
// now re-calculate val_weights where neibs are different from neibs_prev
for
(
int
isTile
=
0
;
isTile
<
all_tiles
.
length
;
isTile
++){
int
nsTile
=
all_tiles
[
isTile
];
if
(
planes
[
nsTile
]
!=
null
)
{
int
ineib
=
(
tile_map
.
containsKey
(
nsTile
))?
tile_map
.
get
(
nsTile
)
:
-
1
;
if
((
planes
[
nsTile
]
!=
null
)
&&
((
ineib
<
0
)
||
(
neibs
[
ineib
]
!=
null
))){
vw
[
isTile
]
=
new
double
[
planes
[
nsTile
].
length
][];
for
(
int
nl
=
0
;
nl
<
planes
[
nsTile
].
length
;
nl
++)
if
(
planes
[
nsTile
][
nl
]
!=
null
){
int
[]
neibs0
=
(
ineib
>=
0
)
?
neibs
[
ineib
][
nl
]
:
planes
[
nsTile
][
nl
].
getNeibBest
();
if
(
neibs0
!=
null
)
{
boolean
neibs_changed
=
false
;
if
(
force
){
neibs_changed
=
true
;
}
int
[][]
neibs2
=
new
int
[
8
][];
for
(
int
dir
=
0
;
dir
<
8
;
dir
++
){
if
(!
neibs_changed
&&
(
ineib
>=
0
)
&&
((
neibs_init
[
ineib
]
==
null
)
||
(
neibs_init
[
ineib
][
nl
]
==
null
)
||
(
neibs0
[
dir
]
!=
neibs_init
[
ineib
][
nl
][
dir
])))
{
neibs_changed
=
true
;
}
if
(
neibs0
[
dir
]
>=
0
)
{
int
nl1
=
neibs0
[
dir
];
int
nsTile1
=
tnSurface
.
getNeibIndex
(
nsTile
,
dir
);
int
ineib1
=
(
tile_map
.
containsKey
(
nsTile1
))?
tile_map
.
get
(
nsTile1
)
:
-
1
;
neibs2
[
dir
]
=
(
ineib1
>=
0
)
?
neibs
[
tile_map
.
get
(
nsTile1
)][
nl1
]
:
planes
[
nsTile1
][
nl1
].
getNeibBest
();
if
(!
neibs_changed
&&
(
ineib1
>=
0
))
{
if
((
neibs_init
[
ineib1
]
==
null
)
||
(
neibs_init
[
ineib1
][
nl1
]
==
null
))
{
neibs_changed
=
true
;
}
else
{
for
(
int
dir1
=
0
;
dir1
<
8
;
dir1
++)
if
(
neibs
[
ineib1
][
nl1
][
dir1
]
!=
neibs_init
[
ineib1
][
nl1
][
dir1
]){
neibs_changed
=
true
;
break
;
}
}
}
}
}
if
(
neibs_changed
){
vw
[
isTile
][
nl
]
=
getStarValueWeight
(
nsTile
,
nl
,
neibs0
,
neibs2
,
orthoWeight
,
diagonalWeight
,
starPwr
,
// double starPwr, // Divide cost by number of connections to this power
tnSurface
,
preferDisparity
,
-
1
);
// debugLevel);
}
else
{
vw
[
isTile
][
nl
]
=
val_weights
[
isTile
][
nl
];
}
}
else
{
vw
[
isTile
][
nl
]
=
null
;
}
}
}
else
{
vw
[
isTile
]
=
null
;
}
}
}
return
vw
;
// negative - improvement
}
public
double
getConnectionsCostDiff
(
int
[][][]
neibs
,
// should be initialized at top dimension if neibs_prev==null
int
debugLevel
)
{
double
[][][]
vw
;
switch
(
steps
){
case
1
:
vw
=
getConnectionsCostSingleStep
(
neibs
,
-
1
);
// int debugLevel)
break
;
case
2
:
vw
=
getConnectionsCostDualStep
(
neibs
,
-
1
);
// int debugLevel)
break
;
default
:
vw
=
getConnectionsCostSingleStep
(
neibs
,
-
1
);
// int debugLevel)
}
// calculate new cost
double
new_value
=
0.0
;
double
new_weight
=
0.0
;
// should not change during update
for
(
int
isTile
=
0
;
isTile
<
all_tiles
.
length
;
isTile
++){
if
(
vw
[
isTile
]
!=
null
){
for
(
int
nl
=
0
;
nl
<
vw
[
isTile
].
length
;
nl
++)
if
(
vw
[
isTile
][
nl
]
!=
null
){
new_value
+=
vw
[
isTile
][
nl
][
0
]
*
vw
[
isTile
][
nl
][
1
];
new_weight
+=
vw
[
isTile
][
nl
][
1
];
}
}
}
if
(
new_weight
!=
0.0
)
new_value
/=
new_weight
;
return
new_value
-
init_val
;
// negative - improvement
}
/**
* Calculate main eigenvalue of the current plane and all connected ones - used to estimate advantage of connection swap
* @param nsTile supertile index
* @param nl surface layer
* @param neibs array of 8 neighbors layers (N,NE,...NW), -1 - not connected
* @param orthoWeight multiply contribution of ortho neighbors
* @param diagonalWeight multiply contribution of diagonal neighbors
* @param diagonalWeight divide value by number of connections to this power (if !=0)
* @param tnSurface TileNeibs instance to navigate tile index and control array borders
* @param preferDisparity - the first eigenvalue/vector is the most disparity-like
* (false - smallest eigenvalue)
* @param debugLevel
* @return a pair of eigenvalue of the combine plane and its weight
*/
public
double
[]
getStarValueWeight
(
int
nsTile
,
int
nl
,
int
[]
neibs
,
double
orthoWeight
,
double
diagonalWeight
,
double
starPwr
,
// Divide cost by number of connections to this power
TileSurface
.
TileNeibs
tnSurface
,
boolean
preferDisparity
,
int
debugLevel
)
{
TilePlanes
.
PlaneData
merged_plane
=
planes
[
nsTile
][
nl
];
for
(
int
dir
=
0
;
dir
<
8
;
dir
++){
if
(
neibs
[
dir
]
>=
0
){
double
other_weight
=
((
dir
&
1
)
!=
0
)
?
diagonalWeight
:
orthoWeight
;
TilePlanes
.
PlaneData
other_plane
=
merged_plane
.
getPlaneToThis
(
// layer here does not matter
planes
[
tnSurface
.
getNeibIndex
(
nsTile
,
dir
)][
neibs
[
dir
]],
debugLevel
-
1
);
// debugLevel);
merged_plane
=
merged_plane
.
mergePlaneToThis
(
other_plane
,
// PlaneData otherPd,
other_weight
,
// double scale_other,
false
,
// boolean ignore_weights,
true
,
// boolean sum_weights,
preferDisparity
,
debugLevel
-
1
);
// int debugLevel)
}
}
double
[]
value_weight
=
{
merged_plane
.
getValue
(),
merged_plane
.
getWeight
()};
if
(
starPwr
!=
0
){
value_weight
[
0
]
/=
(
Math
.
pow
((
planes
[
nsTile
][
nl
].
getNumNeibBest
()
+
1.0
),
starPwr
));
}
return
value_weight
;
}
/**
* Calculate main eigenvalue of the current plane and all connected ones - used to estimate advantage of connection swap
* This version uses two steps - not only directly connected, but neighbors' neighbors also, multiple paths to the same
* tile add together.
* @param nsTile supertile index
* @param nl surface layer
* @param neibs array of 8 neighbors layers (N,NE,...NW), -1 - not connected
* @param neibs2 2-d array of 8 neighbors' neighbors layers (N,NE,...NW), -1 - not connected
* @param orthoWeight multiply contribution of ortho neighbors
* @param diagonalWeight multiply contribution of diagonal neighbors
* @param diagonalWeight divide value by number of connections to this power (if !=0)
* @param tnSurface TileNeibs instance to navigate tile index and control array borders
* @param preferDisparity - the first eigenvalue/vector is the most disparity-like
* (false - smallest eigenvalue)
* @param debugLevel
* @return a pair of eigenvalue of the combine plane and its weight
*/
public
double
[]
getStarValueWeight
(
int
nsTile
,
int
nl
,
int
[]
neibs
,
int
[][]
neibs2
,
// neighbors' neighbors
double
orthoWeight
,
double
diagonalWeight
,
double
starPwr
,
// Divide cost by number of connections to this power
TileSurface
.
TileNeibs
tnSurface
,
boolean
preferDisparity
,
int
debugLevel
)
{
double
[]
dir_weight
=
{
orthoWeight
,
diagonalWeight
,
orthoWeight
,
diagonalWeight
,
orthoWeight
,
diagonalWeight
,
orthoWeight
,
diagonalWeight
};
HashMap
<
Point
,
Double
>
tile_weights
=
new
HashMap
<
Point
,
Double
>();
for
(
int
dir
=
0
;
dir
<
8
;
dir
++){
int
nl1
=
neibs
[
dir
];
if
(
nl1
>=
0
){
int
nsTile1
=
tnSurface
.
getNeibIndex
(
nsTile
,
dir
);
double
weight1
=
dir_weight
[
dir
];
tile_weights
.
put
(
new
Point
(
nsTile1
,
nl1
),
new
Double
(
weight1
));
// no need to check for existence here
for
(
int
dir1
=
0
;
dir1
<
8
;
dir1
++){
if
((
dir1
!=
dir
)
&&
(
neibs2
[
dir
]!=
null
)){
int
nl2
=
neibs2
[
dir
][
dir1
];
if
(
nl2
>=
0
){
Point
p
=
new
Point
(
tnSurface
.
getNeibIndex
(
nsTile1
,
dir1
),
nl2
);
Double
w0
=
tile_weights
.
get
(
p
);
double
weight2
=
dir_weight
[
dir1
]*
weight1
;
if
(
w0
!=
null
)
weight2
+=
w0
;
tile_weights
.
put
(
p
,
new
Double
(
weight2
));
}
}
}
}
}
TilePlanes
.
PlaneData
merged_plane
=
planes
[
nsTile
][
nl
];
// center point
for
(
HashMap
.
Entry
<
Point
,
Double
>
entry
:
tile_weights
.
entrySet
()){
TilePlanes
.
PlaneData
other_plane
=
merged_plane
.
getPlaneToThis
(
// layer here does not matter
planes
[
entry
.
getKey
().
x
][
entry
.
getKey
().
y
],
debugLevel
-
1
);
// debugLevel);
merged_plane
=
merged_plane
.
mergePlaneToThis
(
other_plane
,
// PlaneData otherPd,
entry
.
getValue
(),
// double scale_other,
false
,
// boolean ignore_weights,
true
,
// boolean sum_weights,
preferDisparity
,
debugLevel
-
1
);
// int debugLevel)
}
double
[]
value_weight
=
{
merged_plane
.
getValue
(),
merged_plane
.
getWeight
()};
if
(
starPwr
!=
0
){
value_weight
[
0
]
/=
(
Math
.
pow
(
tile_weights
.
size
()
+
1.0
,
starPwr
));
}
return
value_weight
;
}
/**
* Calculate array of supertile indices that need to have connection cost recalculated when they are updated
* first entries of the result will be the same in input array
* @param mod_supertiles array of supertile indices that will be modified
* @param tnSurface TileNeibs instance to navigate tile index and control array borders
* @return array of supertile indices to watch connection cost
*/
public
int
[]
getInvolvedSupertiles
(
int
[]
mod_supertiles
)
{
HashSet
<
Integer
>
stiles_set
=
new
HashSet
<
Integer
>();
for
(
int
i
=
0
;
i
<
mod_supertiles
.
length
;
i
++){
stiles_set
.
add
(
new
Integer
(
mod_supertiles
[
i
]));
for
(
int
dir
=
0
;
dir
<
8
;
dir
++){
Integer
nsTile
=
tnSurface
.
getNeibIndex
(
mod_supertiles
[
i
],
dir
);
if
(
nsTile
>=
0
)
stiles_set
.
add
(
nsTile
);
}
}
int
[]
stiles
=
new
int
[
stiles_set
.
size
()];
int
indx
=
0
;
for
(;
indx
<
mod_supertiles
.
length
;
indx
++){
stiles_set
.
remove
(
new
Integer
(
mod_supertiles
[
indx
]));
stiles
[
indx
]
=
mod_supertiles
[
indx
];
}
for
(
Integer
nsTile:
stiles_set
){
stiles
[
indx
++]
=
nsTile
;
}
return
stiles
;
}
}
src/main/java/EyesisCorrectionParameters.java
View file @
1ca1c6d0
...
...
@@ -2174,8 +2174,11 @@ public class EyesisCorrectionParameters {
public
double
plOKMergeEigen
=
0.03
;
// If result of the merged planes is below, OK to bypass worst worsening
public
double
plMaxWorldSin2
=
0.1
;
// Maximal sine squared of the world angle between planes to merge. Set to >= 1.0 to disable
public
double
plWeakWorsening
=
1.0
;
// Relax merge requirements for weaker planes
public
int
plStarSteps
=
1
;
// How far to look around when calculationg connection cost
public
double
plStarOrtho
=
0.5
;
// When calculating cost for the connections scale 4 ortho neighbors
public
double
plStarDiag
=
0.25
;
// When calculating cost for the connections scale 4 diagonal neighbors
public
double
plStarPwr
=
0.5
;
// Divide cost by number of connections to this power
public
double
plDblTriLoss
=
0.0001
;
// When resolving double triangles allow minor degradation (0.0 - strict)
public
boolean
plMutualOnly
=
true
;
// keep only mutual links, remove weakest if conflict
...
...
@@ -2526,8 +2529,10 @@ public class EyesisCorrectionParameters {
properties
.
setProperty
(
prefix
+
"plMaxWorldSin2"
,
this
.
plMaxWorldSin2
+
""
);
properties
.
setProperty
(
prefix
+
"plWeakWorsening"
,
this
.
plWeakWorsening
+
""
);
properties
.
setProperty
(
prefix
+
"plStarSteps"
,
this
.
plStarSteps
+
""
);
properties
.
setProperty
(
prefix
+
"plStarOrtho"
,
this
.
plStarOrtho
+
""
);
properties
.
setProperty
(
prefix
+
"plStarDiag"
,
this
.
plStarDiag
+
""
);
properties
.
setProperty
(
prefix
+
"plStarPwr"
,
this
.
plStarPwr
+
""
);
properties
.
setProperty
(
prefix
+
"plDblTriLoss"
,
this
.
plDblTriLoss
+
""
);
properties
.
setProperty
(
prefix
+
"plMutualOnly"
,
this
.
plMutualOnly
+
""
);
...
...
@@ -2858,8 +2863,10 @@ public class EyesisCorrectionParameters {
if
(
properties
.
getProperty
(
prefix
+
"plMaxWorldSin2"
)!=
null
)
this
.
plMaxWorldSin2
=
Double
.
parseDouble
(
properties
.
getProperty
(
prefix
+
"plMaxWorldSin2"
));
if
(
properties
.
getProperty
(
prefix
+
"plWeakWorsening"
)!=
null
)
this
.
plWeakWorsening
=
Double
.
parseDouble
(
properties
.
getProperty
(
prefix
+
"plWeakWorsening"
));
if
(
properties
.
getProperty
(
prefix
+
"plStarSteps"
)!=
null
)
this
.
plStarSteps
=
Integer
.
parseInt
(
properties
.
getProperty
(
prefix
+
"plStarSteps"
));
if
(
properties
.
getProperty
(
prefix
+
"plStarOrtho"
)!=
null
)
this
.
plStarOrtho
=
Double
.
parseDouble
(
properties
.
getProperty
(
prefix
+
"plStarOrtho"
));
if
(
properties
.
getProperty
(
prefix
+
"plStarDiag"
)!=
null
)
this
.
plStarDiag
=
Double
.
parseDouble
(
properties
.
getProperty
(
prefix
+
"plStarDiag"
));
if
(
properties
.
getProperty
(
prefix
+
"plStarPwr"
)!=
null
)
this
.
plStarPwr
=
Double
.
parseDouble
(
properties
.
getProperty
(
prefix
+
"plStarPwr"
));
if
(
properties
.
getProperty
(
prefix
+
"plDblTriLoss"
)!=
null
)
this
.
plDblTriLoss
=
Double
.
parseDouble
(
properties
.
getProperty
(
prefix
+
"plDblTriLoss"
));
if
(
properties
.
getProperty
(
prefix
+
"plMutualOnly"
)!=
null
)
this
.
plMutualOnly
=
Boolean
.
parseBoolean
(
properties
.
getProperty
(
prefix
+
"plMutualOnly"
));
...
...
@@ -3218,8 +3225,10 @@ public class EyesisCorrectionParameters {
gd
.
addNumericField
(
"Maximal sine squared of the world angle between planes to merge. Set to >= 1.0 to disable"
,
this
.
plMaxWorldSin2
,
6
);
gd
.
addNumericField
(
"Relax merge requirements for weaker planes"
,
this
.
plWeakWorsening
,
6
);
gd
.
addNumericField
(
"How far to look around when calculationg connection cost"
,
this
.
plStarSteps
,
0
);
gd
.
addNumericField
(
"When calculating cost for the connections scale 4 ortho neighbors"
,
this
.
plStarOrtho
,
6
);
gd
.
addNumericField
(
"When calculating cost for the connections scale 4 diagonal neighbors"
,
this
.
plStarDiag
,
6
);
gd
.
addNumericField
(
"Divide cost by number of connections to this power"
,
this
.
plStarPwr
,
6
);
gd
.
addNumericField
(
"When resolving double triangles allow minor degradation (0.0 - strict)"
,
this
.
plDblTriLoss
,
6
);
gd
.
addCheckbox
(
"Keep only mutual links, remove weakest if conflict"
,
this
.
plMutualOnly
);
...
...
@@ -3563,8 +3572,10 @@ public class EyesisCorrectionParameters {
this
.
plMaxWorldSin2
=
gd
.
getNextNumber
();
this
.
plWeakWorsening
=
gd
.
getNextNumber
();
this
.
plStarSteps
=
(
int
)
gd
.
getNextNumber
();
this
.
plStarOrtho
=
gd
.
getNextNumber
();
this
.
plStarDiag
=
gd
.
getNextNumber
();
this
.
plStarPwr
=
gd
.
getNextNumber
();
this
.
plDblTriLoss
=
gd
.
getNextNumber
();
this
.
plMutualOnly
=
gd
.
getNextBoolean
();
...
...
src/main/java/SuperTiles.java
View file @
1ca1c6d0
...
...
@@ -3750,8 +3750,10 @@ public class SuperTiles{
public
int
[]
resolveDiagonalTriangularConflicts
(
int
[][][]
conflicts
,
Conflicts
conflict_stats
,
// to be updated after applying resolution
int
starSteps
,
// How far to look around when calculationg connection cost
double
orthoWeight
,
double
diagonalWeight
,
double
starPwr
,
// Divide cost by number of connections to this power
double
dblTriLoss
,
// When resolving double triangles allow minor degradation (0.0 - strict)
boolean
preferDisparity
,
int
debugLevel
,
...
...
@@ -3769,7 +3771,7 @@ public class SuperTiles{
for
(
int
nsTile
=
0
;
nsTile
<
conflicts
.
length
;
nsTile
++)
if
(
conflicts
[
nsTile
]
!=
null
)
{
// conflicts may disappear after being fixed, recheck for null
for
(
int
nConfl
=
0
;
(
conflicts
[
nsTile
]
!=
null
)
&&
(
nConfl
<
conflicts
[
nsTile
].
length
);
nConfl
++){
int
dl
=
((
debugLevel
>
0
)
&&
(
nsTile
==
dbgTile
))
?
3
:
0
;
int
dl
=
((
debugLevel
>
-
1
)
&&
(
nsTile
==
dbgTile
))
?
3
:
0
;
Conflict
confl
=
new
Conflict
(
nsTile
,
conflicts
[
nsTile
][
nConfl
]);
for
(
int
dir_orient
=
0
;
dir_orient
<
16
;
dir_orient
++){
boolean
right
=
(
dir_orient
&
8
)
!=
0
;
...
...
@@ -3787,8 +3789,10 @@ public class SuperTiles{
tnSurface
,
// TileSurface.TileNeibs tnSurface,
conflicts
,
// int [][][] conflicts,
conflict_stats
,
// Conflicts conflict_stats, // to be updated after applying resolution
starSteps
,
// How far to look around when calculationg connection cost
orthoWeight
,
// double orthoWeight,
diagonalWeight
,
// double diagonalWeight,
starPwr
,
// double starPwr, // Divide cost by number of connections to this power
dblTriLoss
,
// double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict)
preferDisparity
,
// boolean preferDisparity,
dl
);
// int debugLevel)
...
...
@@ -3809,18 +3813,19 @@ public class SuperTiles{
int
start_dir4
,
boolean
right
,
boolean
reverse
,
TileSurface
.
TileNeibs
tnSurface
,
int
[][][]
conflicts
,
Conflicts
conflict_stats
,
// to be updated after applying resolution
int
starSteps
,
// How far to look around when calculationg connection cost
double
orthoWeight
,
double
diagonalWeight
,
double
starPwr
,
// Divide cost by number of connections to this power
double
dblTriLoss
,
// When resolving double triangles allow minor degradation (0.0 - strict)
boolean
preferDisparity
,
int
debugLevel
)
{
if
(
debugLevel
>
1
)
{
System
.
out
.
println
(
"
*******
resolveDiagonalTriangularConflict(): "
+
conflict
.
toString
()+
": start_dir4 = "
+
start_dir4
+
", right = "
+
right
+
", reverse = "
+
reverse
);
System
.
out
.
println
(
"resolveDiagonalTriangularConflict(): "
+
conflict
.
toString
()+
": start_dir4 = "
+
start_dir4
+
", right = "
+
right
+
", reverse = "
+
reverse
);
}
if
(!
conflict
.
conflictExists
(
...
...
@@ -3848,6 +3853,12 @@ public class SuperTiles{
return
false
;
}
if
(
debugLevel
>
1
)
{
if
(
debugLevel
>
1
)
{
System
.
out
.
println
(
"resolveDiagonalTriangularConflict(): nsTile = "
+
nsTile
+
" nsTile1 = "
+
nsTile1
+
" nsTile2="
+
nsTile2
);
}
}
int
nl2
=
planes
[
nsTile1
][
nl1
].
getNeibBest
(
dir12
);
// now nsTile2:nl2 is supposed to be connected to nsTile:nl_end != nl
...
...
@@ -3865,19 +3876,33 @@ public class SuperTiles{
for
(
int
i
=
0
;
i
<
mod_supertiles
.
length
;
i
++){
replacement_tiles
.
put
(
mod_supertiles
[
i
],
new
Integer
(
i
));
}
int
[][][]
neibs_prev
=
new
int
[
mod_supertiles
.
length
][][];
ConnectionCosts
connectionCosts
=
new
ConnectionCosts
(
orthoWeight
,
diagonalWeight
,
starPwr
,
// Divide cost by number of connections to this power
starSteps
,
this
.
planes
,
tnSurface
,
preferDisparity
);
int
[][][]
neibs_prev
=
connectionCosts
.
initConnectionCosts
(
mod_supertiles
);
int
[][][]
neibs_prev_old
=
new
int
[
mod_supertiles
.
length
][][];
double
[][][]
val_weights
=
new
double
[
mod_supertiles
.
length
][][];
// Calculate original costs and neighhbors
updateConnectionsCost
(
mod_supertiles
,
// int [] nsTiles,
null
,
// int [][][] neibs_prev,
neibs_prev
,
// int [][][] neibs, // should be initialized at top dimension if neibs_prev==null
neibs_prev
_old
,
// int [][][] neibs, // should be initialized at top dimension if neibs_prev==null
val_weights
,
// double [][][] val_weights, // should be initialized at top dimension if neibs_prev==null
orthoWeight
,
diagonalWeight
,
starPwr
,
// double starPwr, // Divide cost by number of connections to this power
tnSurface
,
preferDisparity
,
debugLevel
);
if
((
neibs_prev
==
null
)
||
(
neibs_prev
[
0
]
==
null
)
||
(
neibs_prev
[
1
]
==
null
)){
System
.
out
.
println
(
"resolveDiagonalTriangularConflict(): BUG"
);
System
.
out
.
println
(
"neibs_prev="
+
neibs_prev
);
...
...
@@ -3891,6 +3916,12 @@ public class SuperTiles{
neibs
[
nt
][
l
]
=
neibs_prev
[
nt
][
l
].
clone
();
}
}
int
[][][]
neibs_old
=
{
neibs_prev
[
0
].
clone
(),
neibs_prev
[
1
].
clone
()};
// both non-null
for
(
int
nt
=
0
;
nt
<
neibs
.
length
;
nt
++){
for
(
int
l
=
0
;
l
<
neibs_prev
[
nt
].
length
;
l
++)
if
(
neibs_prev
[
nt
][
l
]!=
null
){
neibs_old
[
nt
][
l
]
=
neibs_prev_old
[
nt
][
l
].
clone
();
}
}
int
[][][]
conflicts_old
=
new
int
[
nsTiles
.
length
][][];
for
(
int
isTile
=
0
;
isTile
<
nsTiles
.
length
;
isTile
++){
conflicts_old
[
isTile
]
=
iconflicts
.
detectTriangularTileConflicts
(
...
...
@@ -3917,18 +3948,41 @@ public class SuperTiles{
if
(
neibs_prev
[
0
][
nl
][
dir02
]
>=
0
)
{
neibs
[
1
][
neibs_prev
[
0
][
nl
][
dir02
]][
dir20
]
=
nl_end
;
}
neibs_old
[
0
][
nl
][
dir02
]
=
nl2
;
neibs_old
[
1
][
nl2
][
dir20
]
=
nl
;
neibs_old
[
0
][
nl_end
][
dir02
]
=
neibs_prev_old
[
0
][
nl
][
dir02
];
if
(
neibs_prev_old
[
0
][
nl
][
dir02
]
>=
0
)
{
neibs_old
[
1
][
neibs_prev_old
[
0
][
nl
][
dir02
]][
dir20
]
=
nl_end
;
}
int
[][][]
new_conflicts
=
new
int
[
nsTiles
.
length
][][];
double
new_costs_diff
=
updateConnectionsCost
(
double
new_costs_diff
=
connectionCosts
.
getConnectionsCostDiff
(
neibs
,
debugLevel
);
if
(
debugLevel
>
-
1
)
{
System
.
out
.
println
(
"resolveDiagonalTriangularConflict(): resolving conflict "
+
conflict
.
toString
()+
", start dir4 = "
+
start_dir4
+
", orientation = "
+(
right
?
"right"
:
"left"
)
+
", improvement (negative diff) = "
+
new_costs_diff
);
}
double
new_costs_diff_old
=
updateConnectionsCost
(
mod_supertiles
,
// int [] nsTiles,
neibs_prev
,
// int [][][] neibs_prev,
neibs
,
// int [][][] neibs, // should be initialized at top dimension if neibs_prev==null
neibs_prev
_old
,
// int [][][] neibs_prev,
neibs
_old
,
// int [][][] neibs, // should be initialized at top dimension if neibs_prev==null
val_weights
,
// double [][][] val_weights, // should be initialized at top dimension if neibs_prev==null
orthoWeight
,
diagonalWeight
,
starPwr
,
// double starPwr, // Divide cost by number of connections to this power
tnSurface
,
preferDisparity
,
debugLevel
);
for
(
int
isTile
=
0
;
isTile
<
nsTiles
.
length
;
isTile
++){
new_conflicts
[
isTile
]
=
iconflicts
.
detectTriangularTileConflicts
(
nsTiles
[
isTile
],
// int nsTile0,
...
...
@@ -3943,10 +3997,10 @@ public class SuperTiles{
new_conflicts_stats
.
subConflicts
(
iconflicts
);
// subtract old number of different types of conflicts
if
(
debugLevel
>
-
1
)
{
System
.
out
.
println
(
"resolveDiagonalTriangularConflict(): resolving conflict "
+
conflict
.
toString
()+
System
.
out
.
println
(
"resolveDiagonalTriangularConflict()
OLD
: resolving conflict "
+
conflict
.
toString
()+
", start dir4 = "
+
start_dir4
+
", orientation = "
+(
right
?
"right"
:
"left"
)
+
", improvement (negative diff) = "
+
new_costs_diff
);
", improvement (negative diff) = "
+
new_costs_diff
_old
);
}
if
(
debugLevel
>
-
1
)
{
...
...
@@ -4011,8 +4065,10 @@ public class SuperTiles{
public
int
[]
resolveMultiTriangularConflicts
(
int
[][][]
conflicts
,
Conflicts
conflict_stats
,
// to be updated after applying resolution
int
starSteps
,
// How far to look around when calculationg connection cost
double
orthoWeight
,
double
diagonalWeight
,
double
starPwr
,
// Divide cost by number of connections to this power
double
dblTriLoss
,
// When resolving double triangles allow minor degradation (0.0 - strict)
boolean
preferDisparity
,
int
debugLevel
,
...
...
@@ -4041,8 +4097,10 @@ public class SuperTiles{
conflicts
,
conflict_stats
,
// to be updated after applying resolution
// maxEigen, // maximal eigenvalue of planes to consider
starSteps
,
// How far to look around when calculationg connection cost
orthoWeight
,
diagonalWeight
,
starPwr
,
// double starPwr, // Divide cost by number of connections to this power
dblTriLoss
,
// When resolving double triangles allow minor degradation (0.0 - strict)
preferDisparity
,
dl
);
// debugLevel,
...
...
@@ -4063,8 +4121,10 @@ public class SuperTiles{
TileSurface
.
TileNeibs
tnSurface
,
int
[][][]
conflicts
,
Conflicts
conflict_stats
,
// to be updated after applying resolution
int
starSteps
,
// How far to look around when calculationg connection cost
double
orthoWeight
,
double
diagonalWeight
,
double
starPwr
,
// Divide cost by number of connections to this power
double
dblTriLoss
,
// When resolving double triangles allow minor degradation (0.0 - strict)
boolean
preferDisparity
,
int
debugLevel
)
...
...
@@ -4108,6 +4168,8 @@ public class SuperTiles{
neibs_vars
[
ivar
][
i
]
=
neibs_raw
[
ivar
][
indices
[
i
]];
}
}
// See how this application will influence number of conflicts
// All supertiles that may have different conflicts
...
...
@@ -4118,19 +4180,33 @@ public class SuperTiles{
for
(
int
i
=
0
;
i
<
mod_supertiles
.
length
;
i
++){
replacement_tiles
.
put
(
mod_supertiles
[
i
],
new
Integer
(
i
));
}
int
[][][]
neibs_prev
=
new
int
[
mod_supertiles
.
length
][][];
ConnectionCosts
connectionCosts
=
new
ConnectionCosts
(
orthoWeight
,
diagonalWeight
,
starPwr
,
// Divide cost by number of connections to this power
starSteps
,
this
.
planes
,
tnSurface
,
preferDisparity
);
int
[][][]
neibs_prev
=
connectionCosts
.
initConnectionCosts
(
mod_supertiles
);
/** */
int
[][][]
neibs_prev_old
=
new
int
[
mod_supertiles
.
length
][][];
double
[][][]
val_weights_original
=
new
double
[
mod_supertiles
.
length
][][];
updateConnectionsCost
(
mod_supertiles
,
// int [] nsTiles,
null
,
// int [][][] neibs_prev,
neibs_prev
,
// int [][][] neibs, // should be initialized at top dimension if neibs_prev==null
neibs_prev
_old
,
// int [][][] neibs, // should be initialized at top dimension if neibs_prev==null
val_weights_original
,
// double [][][] val_weights, // should be initialized at top dimension if neibs_prev==null
orthoWeight
,
diagonalWeight
,
starPwr
,
// double starPwr, // Divide cost by number of connections to this power
tnSurface
,
preferDisparity
,
debugLevel
);
/** */
int
[][][]
conflicts_old
=
new
int
[
nsTiles
.
length
][][];
for
(
int
isTile
=
0
;
isTile
<
nsTiles
.
length
;
isTile
++){
conflicts_old
[
isTile
]
=
iconflicts
.
detectTriangularTileConflicts
(
...
...
@@ -4162,6 +4238,19 @@ public class SuperTiles{
double
[]
variant_costs_diff
=
new
double
[
neibs_vars
.
length
];
for
(
int
variant
=
0
;
variant
<
neibs_vars
.
length
;
variant
++){
variant_costs_diff
[
variant
]
=
connectionCosts
.
getConnectionsCostDiff
(
neibs_vars
[
variant
],
debugLevel
);
if
(
debugLevel
>
-
1
)
{
System
.
out
.
println
(
"resolveMultiTriangularConflict(): resolving conflict for tile "
+
nsTile
+
", nl1 = "
+
nl1
+
", nl2 = "
+
nl2
+
", dir_mask = "
+
dir_mask
+
" variant = "
+
variant
+
" improvement (negative diff) = "
+
variant_costs_diff
[
variant
]);
}
double
[]
variant_costs_diff_old
=
new
double
[
neibs_vars
.
length
];
double
[][][]
val_weights
=
val_weights_original
.
clone
();
for
(
int
nt
=
0
;
nt
<
val_weights_original
.
length
;
nt
++)
if
(
val_weights_original
[
nt
]
!=
null
){
val_weights
[
nt
]
=
val_weights_original
[
nt
].
clone
();
...
...
@@ -4169,16 +4258,19 @@ public class SuperTiles{
val_weights
[
nt
][
nl
]
=
val_weights_original
[
nt
][
nl
].
clone
();
}
}
variant_costs_diff
[
variant
]
=
updateConnectionsCost
(
variant_costs_diff
_old
[
variant
]
=
updateConnectionsCost
(
mod_supertiles
,
// int [] nsTiles,
neibs_prev
,
// int [][][] neibs_prev,
neibs_prev
_old
,
// int [][][] neibs_prev,
neibs_vars
[
variant
],
// int [][][] neibs, // should be initialized at top dimension if neibs_prev==null
val_weights
,
// double [][][] val_weights, // should be initialized at top dimension if neibs_prev==null
orthoWeight
,
diagonalWeight
,
starPwr
,
// double starPwr, // Divide cost by number of connections to this power
tnSurface
,
preferDisparity
,
debugLevel
);
for
(
int
isTile
=
0
;
isTile
<
nsTiles
.
length
;
isTile
++){
variant_conflicts
[
variant
][
isTile
]
=
iconflicts
.
detectTriangularTileConflicts
(
...
...
@@ -4194,7 +4286,7 @@ public class SuperTiles{
variant_conflicts_stats
[
variant
].
subConflicts
(
iconflicts
);
// subtract old number of different types of conflicts
if
(
debugLevel
>
-
1
)
{
System
.
out
.
println
(
"resolveMultiTriangularConflict(): resolving conflict for tile "
+
nsTile
+
System
.
out
.
println
(
"resolveMultiTriangularConflict()
OLD
: resolving conflict for tile "
+
nsTile
+
", nl1 = "
+
nl1
+
", nl2 = "
+
nl2
+
", dir_mask = "
+
dir_mask
+
" variant = "
+
variant
+
" improvement (negative diff) = "
+
variant_costs_diff
[
variant
]);
...
...
@@ -4531,14 +4623,128 @@ public class SuperTiles{
return
neib_vars_trimmed
;
}
public
void
resolveConflicts
(
double
maxEigen
,
// maximal eigenvalue of planes to consider
int
starSteps
,
// How far to look around when calculationg connection cost
double
orthoWeight
,
double
diagonalWeight
,
double
starPwr
,
// Divide cost by number of connections to this power
double
dblTriLoss
,
// When resolving double triangles allow minor degradation (0.0 - strict)
boolean
preferDisparity
,
int
debugLevel
,
int
dbg_X
,
int
dbg_Y
)
{
Conflicts
iconflicts0
=
new
Conflicts
(
this
);
int
[][][]
conflicts0
=
iconflicts0
.
detectTriangularConflicts
(
1
);
// final int debugLevel)
Conflicts
conflicts0_stats
=
new
Conflicts
(
conflicts0
,
this
,
-
1
);
// debugLevel);
for
(
int
pass
=
0
;
pass
<
10
;
pass
++)
{
int
[]
dual_tri_results
=
resolveDualTriangularConflicts
(
conflicts0
,
// int [][][] conflicts,
conflicts0_stats
,
maxEigen
,
starSteps
,
// How far to look around when calculationg connection cost
orthoWeight
,
// double orthoWeight,
diagonalWeight
,
// double diagonalWeight,
starPwr
,
// double starPwr, // Divide cost by number of connections to this power
dblTriLoss
,
// double diagonalWeight,
preferDisparity
,
debugLevel
,
// 1, // final int debugLevel)
dbg_X
,
dbg_Y
);
System
.
out
.
println
(
"Pass "
+(
pass
+
1
)+
": dual_tri_results (success/failures) = "
+
dual_tri_results
[
0
]+
" / "
+
dual_tri_results
[
1
]);
int
[]
conflict_resoultion_results
=
resolveMultiTriangularConflicts
(
conflicts0
,
// int [][][] conflicts,
conflicts0_stats
,
starSteps
,
// How far to look around when calculationg connection cost
orthoWeight
,
// double orthoWeight,
diagonalWeight
,
// double diagonalWeight,
starPwr
,
// double starPwr, // Divide cost by number of connections to this power
dblTriLoss
,
// double diagonalWeight,
preferDisparity
,
debugLevel
,
// 1, // final int debugLevel)
dbg_X
,
dbg_Y
);
System
.
out
.
println
(
"Pass "
+(
pass
+
1
)+
": multi_tri_results (success/failures) = "
+
conflict_resoultion_results
[
0
]+
" / "
+
conflict_resoultion_results
[
1
]);
int
[]
diagonal_resoultion_results
=
resolveDiagonalTriangularConflicts
(
conflicts0
,
// int [][][] conflicts,
conflicts0_stats
,
starSteps
,
// How far to look around when calculationg connection cost
orthoWeight
,
// double orthoWeight,
diagonalWeight
,
// double diagonalWeight,
starPwr
,
// double starPwr, // Divide cost by number of connections to this power
dblTriLoss
,
// double diagonalWeight,
preferDisparity
,
((
pass
==
3
)?
1
:
0
),
// debugLevel, // 1, // final int debugLevel)
dbg_X
,
dbg_Y
);
System
.
out
.
println
(
"Pass "
+(
pass
+
1
)+
": resolveDiagonalTriangularConflicts (success/failures) = "
+
diagonal_resoultion_results
[
0
]+
" / "
+
diagonal_resoultion_results
[
1
]);
if
(
(
dual_tri_results
[
0
]
==
0
)
&&
(
conflict_resoultion_results
[
0
]
==
0
)
&&
(
diagonal_resoultion_results
[
0
]
==
0
))
{
System
.
out
.
println
(
"No more improvements"
);
break
;
}
}
Conflicts
conflicts1_stats
=
new
Conflicts
(
conflicts0
,
this
,
1
);
// -1); // debugLevel);
conflicts1_stats
.
printConflictSummary
(
"Detected conflicts (all):"
,
true
,
false
,
false
);
conflicts1_stats
.
printConflictSummary
(
"Detected conflicts (ortho-diag-ortho):"
,
false
,
true
,
false
);
conflicts1_stats
.
printConflictSummary
(
"Detected conflicts(ortho-ortho-diag):"
,
false
,
false
,
true
);
iconflicts0
.
resetConflicts
();
conflicts0
=
iconflicts0
.
detectTriangularConflicts
(
1
);
// final int debugLevel)
conflicts1_stats
.
printConflictSummary
(
"Recounted conflicts (all):"
,
true
,
false
,
false
);
conflicts1_stats
.
printConflictSummary
(
"Recounted conflicts (ortho-diag-ortho):"
,
false
,
true
,
false
);
conflicts1_stats
.
printConflictSummary
(
"Recounted conflicts(ortho-ortho-diag):"
,
false
,
false
,
true
);
/*
testResoveTriangle(
clt_parameters.plWorstWorsening, // final double worst_worsening,
clt_parameters.plWeakWorsening, // final double worst_worsening,
maxEigen, // final double okMergeEigen,
clt_parameters.plMaxWorldSin2, // final double maxWorldSin2,
clt_parameters.plDispNorm,
clt_parameters.plMaxEigen,
clt_parameters.plPreferDisparity,
conflicts0, // int [][][] conflicts,
1, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
*/
}
public
int
[]
resolveDualTriangularConflicts
(
int
[][][]
conflicts
,
// int [] conflict_stats, // to be updated after applying resolution
Conflicts
conflict_stats
,
// to be updated after applying resolution
double
maxEigen
,
// maximal eigenvalue of planes to consider
int
starSteps
,
// How far to look around when calculationg connection cost
double
orthoWeight
,
double
diagonalWeight
,
double
starPwr
,
// Divide cost by number of connections to this power
double
dblTriLoss
,
// When resolving double triangles allow minor degradation (0.0 - strict)
boolean
preferDisparity
,
int
debugLevel
,
...
...
@@ -4609,19 +4815,30 @@ public class SuperTiles{
int
nl1
=
conflicts
[
nsTile
][
nConfl
][
0
];
int
nl2
=
conflicts
[
nsTile
][
nConfl
][
1
];
// int [] nsTiles = mod_supertiles;
int
[][][]
neibs_prev
=
new
int
[
mod_supertiles
.
length
][][];
ConnectionCosts
connectionCosts
=
new
ConnectionCosts
(
orthoWeight
,
diagonalWeight
,
starPwr
,
// Divide cost by number of connections to this power
starSteps
,
this
.
planes
,
tnSurface
,
preferDisparity
);
int
[][][]
neibs_prev
=
connectionCosts
.
initConnectionCosts
(
mod_supertiles
);
int
[][][]
neibs_prev_old
=
new
int
[
mod_supertiles
.
length
][][];
double
[][][]
val_weights
=
new
double
[
mod_supertiles
.
length
][][];
updateConnectionsCost
(
mod_supertiles
,
// int [] nsTiles,
null
,
// int [][][] neibs_prev,
neibs_prev
,
// int [][][] neibs, // should be initialized at top dimension if neibs_prev==null
neibs_prev
_old
,
// int [][][] neibs, // should be initialized at top dimension if neibs_prev==null
val_weights
,
// double [][][] val_weights, // should be initialized at top dimension if neibs_prev==null
orthoWeight
,
diagonalWeight
,
starPwr
,
// double starPwr, // Divide cost by number of connections to this power
tnSurface
,
preferDisparity
,
debugLevel
);
int
[][][]
neibs
=
neibs_prev
.
clone
();
for
(
int
i
=
0
;
i
<
neibs
.
length
;
i
++)
if
(
neibs_prev
[
i
]
!=
null
){
neibs
[
i
]
=
neibs_prev
[
i
].
clone
();
...
...
@@ -4666,21 +4883,35 @@ public class SuperTiles{
neibs
[
2
][
nl1_2
][
dir2r
]
=
neibs_prev
[
2
][
nl2_2
][
dir2r
];
neibs
[
2
][
nl2_2
][
dir2r
]
=
neibs_prev
[
2
][
nl1_2
][
dir2r
];
}
double
cost_diff
=
updateConnectionsCost
(
double
cost_diff
=
connectionCosts
.
getConnectionsCostDiff
(
neibs
,
debugLevel
);
if
(
debugLevel
>
0
)
{
System
.
out
.
println
(
"resolveDualTriangularConflicts(): resolving dual triangular conflict for tile "
+
nsTile
+
", nl1 = "
+
conflicts
[
nsTile
][
nConfl
][
0
]+
", nl2 = "
+
conflicts
[
nsTile
][
nConfl
][
1
]+
", dir4 = "
+
dir4
+
" improvement (negative diff) = "
+
cost_diff
);
}
double
cost_diff_old
=
updateConnectionsCost
(
mod_supertiles
,
// int [] nsTiles,
neibs_prev
,
// int [][][] neibs_prev,
neibs
,
// int [][][] neibs, // should be initialized at top dimension if neibs_prev==null
val_weights
,
// double [][][] val_weights, // should be initialized at top dimension if neibs_prev==null
orthoWeight
,
diagonalWeight
,
starPwr
,
// double starPwr, // Divide cost by number of connections to this power
tnSurface
,
preferDisparity
,
debugLevel
);
if
(
debugLevel
>
0
)
{
System
.
out
.
println
(
"resolveDualTriangularConflicts(): resolving dual triangular conflict for tile "
+
nsTile
+
System
.
out
.
println
(
"resolveDualTriangularConflicts()
_OLD
: resolving dual triangular conflict for tile "
+
nsTile
+
", nl1 = "
+
conflicts
[
nsTile
][
nConfl
][
0
]+
", nl2 = "
+
conflicts
[
nsTile
][
nConfl
][
1
]+
", dir4 = "
+
dir4
+
" improvement (negative diff) = "
+
cost_diff
);
", dir4 = "
+
dir4
+
" improvement (negative diff) = "
+
cost_diff
_old
);
}
if
(
cost_diff
<
dblTriLoss
)
{
if
(
debugLevel
>
1
)
{
...
...
@@ -4727,30 +4958,13 @@ public class SuperTiles{
iconflicts
.
addConflicts
(
conflicts_old
,
debugLevel
-
1
);
// debugLevel);
/*
int [] conflict_stats_old = getNumConflicts(
conflicts_old,
debugLevel - 1); // debugLevel);
*/
if
(
debugLevel
>
1
)
{
System
.
out
.
println
(
"Calculating resolved conflicts"
);
}
/*
int [] conflict_stats_new = getNumConflicts(
conflicts_new,
debugLevel - 1); // debugLevel);
*/
Conflicts
conflict_stats_new
=
new
Conflicts
(
conflicts_new
,
this
,
debugLevel
-
1
);
// debugLevel);
/*
int [] conflict_stats_diff = new int [conflict_stats_new.length];
for (int i = 0; i < conflict_stats_new.length; i++){
conflict_stats_diff[i] = conflict_stats_new[i]- conflict_stats_old[i];
}
*/
conflict_stats_new
.
subConflicts
(
iconflicts
);
if
(
debugLevel
>
0
)
{
...
...
@@ -4762,7 +4976,6 @@ public class SuperTiles{
"Conflicts difference after resolution:"
,
true
,
true
,
false
);
}
// if ((conflict_stats_diff[9] >= 0) && (cost_diff > -dblTriLoss)){
if
((
conflict_stats_new
.
getNumOrthoIncompat
()
>=
0
)
&&
(
cost_diff
>
-
dblTriLoss
)){
//getNumOrthoIncompat
if
(
debugLevel
>
1
)
{
...
...
@@ -4771,7 +4984,6 @@ public class SuperTiles{
rslt
[
1
]++;
}
else
{
if
(
debugLevel
>
0
)
{
// if (conflict_stats_diff[9] < 0) {
if
(
conflict_stats_new
.
getNumOrthoIncompat
()
<
0
)
{
System
.
out
.
println
(
"Number of incompatible triangles is reduced, resolution WILL BE APPLIED"
);
}
else
{
...
...
@@ -4779,11 +4991,6 @@ public class SuperTiles{
}
}
// update statistics
/*
for (int i = 0; i < conflict_stats.length; i++){
conflict_stats[i] += conflict_stats_diff[i];
}
*/
conflict_stats
.
addConflicts
(
conflict_stats_new
);
// update conflict
...
...
@@ -4910,18 +5117,21 @@ public class SuperTiles{
* @param neibs array of 8 neighbors layers (N,NE,...NW), -1 - not connected
* @param orthoWeight multiply contribution of ortho neighbors
* @param diagonalWeight multiply contribution of diagonal neighbors
* @param diagonalWeight divide value by number of connections to this power (if !=0)
* @param tnSurface TileNeibs instance to navigate tile index and control array borders
* @param preferDisparity - the first eigenvalue/vector is the most disparity-like
* (false - smallest eigenvalue)
* @param debugLevel
* @return a pair of eigenvalue of the combine plane and its weight
*/
public
double
[]
getStarValueWeight
(
int
nsTile
,
int
nl
,
int
[]
neibs
,
double
orthoWeight
,
double
diagonalWeight
,
double
starPwr
,
// Divide cost by number of connections to this power
TileSurface
.
TileNeibs
tnSurface
,
boolean
preferDisparity
,
int
debugLevel
)
...
...
@@ -4943,9 +5153,86 @@ public class SuperTiles{
}
}
double
[]
value_weight
=
{
merged_plane
.
getValue
(),
merged_plane
.
getWeight
()};
if
(
starPwr
!=
0
){
value_weight
[
0
]
/=
(
Math
.
pow
((
planes
[
nsTile
][
nl
].
getNumNeibBest
()
+
1.0
),
starPwr
));
}
return
value_weight
;
}
/**
* Calculate main eigenvalue of the current plane and all connected ones - used to estimate advantage of connection swap
* This version uses two steps - not only directly connected, but neighbors' neighbors also, multiple paths to the same
* tile add together.
* @param nsTile supertile index
* @param nl surface layer
* @param neibs array of 8 neighbors layers (N,NE,...NW), -1 - not connected
* @param neibs2 2-d array of 8 neighbors' neighbors layers (N,NE,...NW), -1 - not connected
* @param orthoWeight multiply contribution of ortho neighbors
* @param diagonalWeight multiply contribution of diagonal neighbors
* @param diagonalWeight divide value by number of connections to this power (if !=0)
* @param tnSurface TileNeibs instance to navigate tile index and control array borders
* @param preferDisparity - the first eigenvalue/vector is the most disparity-like
* (false - smallest eigenvalue)
* @param debugLevel
* @return a pair of eigenvalue of the combine plane and its weight
*/
/*
public double [] getStarValueWeight(
int nsTile,
int nl,
int [] neibs,
int [][] neibs2, // neighbors' neighbors
double orthoWeight,
double diagonalWeight,
double starPwr, // Divide cost by number of connections to this power
TileSurface.TileNeibs tnSurface,
boolean preferDisparity,
int debugLevel)
{
double [] dir_weight = {orthoWeight, diagonalWeight, orthoWeight, diagonalWeight, orthoWeight, diagonalWeight, orthoWeight, diagonalWeight};
HashMap<Point, Double> tile_weights = new HashMap<Point, Double>();
for (int dir = 0; dir < 8; dir++){
int nl1 = neibs[dir];
if (nl1 >= 0){
int nsTile1 = tnSurface.getNeibIndex(nsTile, dir);
double weight1 = dir_weight[dir];
tile_weights.put(new Point(nsTile1, nl1), new Double(weight1)); // no need to check for existence here
for (int dir1 = 0; dir1 < 8; dir1++){
if ((dir1 != dir) && (neibs2[dir]!= null)){
int nl2 =neibs2[dir][dir1];
if (nl2 >= 0){
Point p = new Point (tnSurface.getNeibIndex(nsTile1, dir1), nl2);
Double w0 = tile_weights.get(p);
double weight2 = dir_weight[dir1]*weight1;
if (w0 != null) weight2 += w0;
tile_weights.put(p, new Double(weight2));
}
}
}
}
}
TilePlanes.PlaneData merged_plane = planes[nsTile][nl]; // center point
for (HashMap.Entry<Point, Double> entry : tile_weights.entrySet()){
TilePlanes.PlaneData other_plane = merged_plane.getPlaneToThis( // layer here does not matter
planes[entry.getKey().x][entry.getKey().y],
debugLevel - 1); // debugLevel);
merged_plane = merged_plane.mergePlaneToThis(
other_plane, // PlaneData otherPd,
entry.getValue(), // double scale_other,
false, // boolean ignore_weights,
true, // boolean sum_weights,
preferDisparity,
debugLevel - 1); // int debugLevel)
}
double [] value_weight = {merged_plane.getValue(),merged_plane.getWeight()};
if (starPwr != 0){
value_weight[0] /= (Math.pow(tile_weights.size() + 1.0, starPwr));
}
return value_weight;
}
*/
/**
* Calculate array of supertile indices that need to have connection cost recalculated when they are updated
* first entries of the result will be the same in input array
...
...
@@ -4953,6 +5240,8 @@ public class SuperTiles{
* @param tnSurface TileNeibs instance to navigate tile index and control array borders
* @return array of supertile indices to watch connection cost
*/
public
int
[]
getInvolvedSupertiles
(
int
[]
mod_supertiles
,
TileSurface
.
TileNeibs
tnSurface
)
...
...
@@ -4981,7 +5270,7 @@ public class SuperTiles{
* Update cost of involved connections after swapping some of them. Total number of links should probably stay
* the same.
* @param nsTiles array of indices of the supertiles to watch
* @param neibs_prev 3-d array [per supertile index][per layer][per direction] of previ
uo
s connections for which
* @param neibs_prev 3-d array [per supertile index][per layer][per direction] of previ
ou
s connections for which
* the cost was already calculated. Or null - in that case established connections will be used and returned in
* neibs array
* @param neibs new connections to calculate cost for. If neibs_prev == null, this array should be initialized
...
...
@@ -5002,8 +5291,9 @@ public class SuperTiles{
int
[][][]
neibs_prev
,
int
[][][]
neibs
,
// should be initialized at top dimension if neibs_prev==null
double
[][][]
val_weights
,
// should be initialized at top dimension if neibs_prev==null
double
orthoWeight
,
double
diagonalWeight
,
double
orthoWeight
,
double
diagonalWeight
,
double
starPwr
,
// Divide cost by number of connections to this power
TileSurface
.
TileNeibs
tnSurface
,
boolean
preferDisparity
,
int
debugLevel
)
...
...
@@ -5017,6 +5307,7 @@ public class SuperTiles{
val_weights
[
isTile
]
=
new
double
[
planes
[
nsTile
].
length
][];
for
(
int
nl
=
0
;
nl
<
planes
[
nsTile
].
length
;
nl
++)
if
(
planes
[
nsTile
][
nl
]
!=
null
){
neibs
[
isTile
][
nl
]
=
planes
[
nsTile
][
nl
].
getNeibBest
();
//getNumNeibBest()
val_weights
[
isTile
][
nl
]
=
new
double
[
2
];
}
}
...
...
@@ -5056,6 +5347,7 @@ public class SuperTiles{
neibs
[
isTile
][
nl
],
orthoWeight
,
diagonalWeight
,
starPwr
,
// double starPwr, // Divide cost by number of connections to this power
tnSurface
,
preferDisparity
,
-
1
);
// debugLevel);
...
...
@@ -5087,6 +5379,7 @@ public class SuperTiles{
}
/**
* Find out which of the layers to use to resolve the conflict. Multiple conflict may need to
* be pre-filtered or split to prevent using simultaneously different neighbors for the same
...
...
src/main/java/TilePlanes.java
View file @
1ca1c6d0
...
...
@@ -1154,6 +1154,16 @@ public class TilePlanes {
return
this
.
neib_best
;
}
public
int
getNumNeibBest
()
{
if
(
this
.
neib_best
==
null
)
{
return
0
;
}
int
num
=
0
;
for
(
int
i
=
0
;
i
<
this
.
neib_best
.
length
;
i
++)
if
(
this
.
neib_best
[
i
]
>=
0
)
num
++;
return
num
;
}
public
int
getNeibBest
(
int
dir
)
{
if
(
this
.
neib_best
==
null
)
{
...
...
src/main/java/TileProcessor.java
View file @
1ca1c6d0
...
...
@@ -2959,8 +2959,8 @@ public class TileProcessor {
}
tileSurface
.
testSimpleConnected
(
clt_parameters
.
tileX
,
clt_parameters
.
tileY
);
230
,
//
clt_parameters.tileX,
131
);
//
clt_parameters.tileY);
double
[][][]
dispStrength
=
st
.
getDisparityStrengths
(
clt_parameters
.
stMeasSel
);
// int stMeasSel) // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert)
...
...
@@ -3428,97 +3428,15 @@ public class TileProcessor {
0
,
// final int debugLevel)
clt_parameters
.
tileX
,
clt_parameters
.
tileY
);
Conflicts
iconflicts0
=
new
Conflicts
(
st
);
/*
int [][][] conflicts0 = st.detectTriangularConflicts(
1); // final int debugLevel)
int [] conflicts0_stats = st.getNumConflicts(
conflicts0,
*/
int
[][][]
conflicts0
=
iconflicts0
.
detectTriangularConflicts
(
1
);
// final int debugLevel)
Conflicts
conflicts0_stats
=
new
Conflicts
(
conflicts0
,
st
,
-
1
);
// debugLevel);
// just testing
/*
for (int pass = 0; pass < 10; pass ++) {
int [] dual_tri_results = st. resolveDualTriangularConflicts(
conflicts0, // int [][][] conflicts,
conflicts0_stats,
clt_parameters.plMaxEigen,
clt_parameters.plStarOrtho, // double orthoWeight,
clt_parameters.plStarDiag, // double diagonalWeight,
clt_parameters.plDblTriLoss, // double diagonalWeight,
clt_parameters.plPreferDisparity,
1, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
System.out.println("Pass "+(pass+1)+": dual_tri_results (success/failures) = "+dual_tri_results[0]+" / "+dual_tri_results[1]);
if (dual_tri_results[0] == 0) break;
}
*/
for
(
int
pass
=
0
;
pass
<
10
;
pass
++)
{
int
[]
dual_tri_results
=
st
.
resolveDualTriangularConflicts
(
conflicts0
,
// int [][][] conflicts,
conflicts0_stats
,
clt_parameters
.
plMaxEigen
,
clt_parameters
.
plStarOrtho
,
// double orthoWeight,
clt_parameters
.
plStarDiag
,
// double diagonalWeight,
clt_parameters
.
plDblTriLoss
,
// double diagonalWeight,
clt_parameters
.
plPreferDisparity
,
1
,
// final int debugLevel)
clt_parameters
.
tileX
,
clt_parameters
.
tileY
);
System
.
out
.
println
(
"Pass "
+(
pass
+
1
)+
": dual_tri_results (success/failures) = "
+
dual_tri_results
[
0
]+
" / "
+
dual_tri_results
[
1
]);
int
[]
conflict_resoultion_results
=
st
.
resolveMultiTriangularConflicts
(
conflicts0
,
// int [][][] conflicts,
conflicts0_stats
,
clt_parameters
.
plStarOrtho
,
// double orthoWeight,
clt_parameters
.
plStarDiag
,
// double diagonalWeight,
clt_parameters
.
plDblTriLoss
,
// double diagonalWeight,
clt_parameters
.
plPreferDisparity
,
1
,
// final int debugLevel)
clt_parameters
.
tileX
,
clt_parameters
.
tileY
);
System
.
out
.
println
(
"Pass "
+(
pass
+
1
)+
": multi_tri_results (success/failures) = "
+
conflict_resoultion_results
[
0
]+
" / "
+
conflict_resoultion_results
[
1
]);
int
[]
diagonal_resoultion_results
=
st
.
resolveDiagonalTriangularConflicts
(
conflicts0
,
// int [][][] conflicts,
conflicts0_stats
,
clt_parameters
.
plStarOrtho
,
// double orthoWeight,
clt_parameters
.
plStarDiag
,
// double diagonalWeight,
clt_parameters
.
plDblTriLoss
,
// double diagonalWeight,
clt_parameters
.
plPreferDisparity
,
1
,
// final int debugLevel)
clt_parameters
.
tileX
,
clt_parameters
.
tileY
);
System
.
out
.
println
(
"Pass "
+(
pass
+
1
)+
": resolveDiagonalTriangularConflicts (success/failures) = "
+
diagonal_resoultion_results
[
0
]+
" / "
+
diagonal_resoultion_results
[
1
]);
if
(
(
dual_tri_results
[
0
]
==
0
)
&&
(
conflict_resoultion_results
[
0
]
==
0
)
&&
(
diagonal_resoultion_results
[
0
]
==
0
))
break
;
}
Conflicts
conflicts1_stats
=
new
Conflicts
(
conflicts0
,
st
,
1
);
// -1); // debugLevel);
conflicts1_stats
.
printConflictSummary
(
"Detected conflicts (all):"
,
true
,
false
,
false
);
conflicts1_stats
.
printConflictSummary
(
"Detected conflicts (ortho-diag-ortho):"
,
false
,
true
,
false
);
conflicts1_stats
.
printConflictSummary
(
"Detected conflicts(ortho-ortho-diag):"
,
false
,
false
,
true
);
st
.
testResoveTriangle
(
clt_parameters
.
plWorstWorsening
,
// final double worst_worsening,
clt_parameters
.
plWeakWorsening
,
// final double worst_worsening,
clt_parameters
.
plOKMergeEigen
,
// final double okMergeEigen,
clt_parameters
.
plMaxWorldSin2
,
// final double maxWorldSin2,
clt_parameters
.
plDispNorm
,
st
.
resolveConflicts
(
clt_parameters
.
plMaxEigen
,
clt_parameters
.
plStarSteps
,
// int starSteps, // How far to look around when calculationg connection cost
clt_parameters
.
plStarOrtho
,
// double orthoWeight,
clt_parameters
.
plStarDiag
,
// double diagonalWeight,
clt_parameters
.
plStarPwr
,
// double starPwr, // Divide cost by number of connections to this power
clt_parameters
.
plDblTriLoss
,
// double diagonalWeight,
clt_parameters
.
plPreferDisparity
,
conflicts0
,
// int [][][] conflicts,
1
,
// final int debugLevel)
clt_parameters
.
tileX
,
clt_parameters
.
tileY
);
...
...
@@ -3613,10 +3531,17 @@ public class TileProcessor {
clt_parameters
.
tileX
,
clt_parameters
.
tileY
);
System
.
out
.
println
(
"********* Put here conflict resolution again ! *********"
);
// st.detectTriangularConflicts(
// 1); // final int debugLevel)
st
.
resolveConflicts
(
clt_parameters
.
plMaxEigen
,
clt_parameters
.
plStarSteps
,
// int starSteps, // How far to look around when calculationg connection cost
clt_parameters
.
plStarOrtho
,
// double orthoWeight,
clt_parameters
.
plStarDiag
,
// double diagonalWeight,
clt_parameters
.
plStarPwr
,
// double starPwr, // Divide cost by number of connections to this power
clt_parameters
.
plDblTriLoss
,
// double diagonalWeight,
clt_parameters
.
plPreferDisparity
,
1
,
// final int debugLevel)
clt_parameters
.
tileX
,
clt_parameters
.
tileY
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment