Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Mirrors
SuperElastix
Commits
5f75dab4
Commit
5f75dab4
authored
Aug 30, 2016
by
Floris Berendsen
Browse files
ENH: let Overlord use AddProviding/AcceptingInterfaceCriteria
parent
b107f8b7
Changes
7
Hide whitespace changes
Inline
Side-by-side
Modules/Components/itkImageRegistrationMethodv4/test/selxRegistrationItkv4Test.cxx
View file @
5f75dab4
...
...
@@ -581,7 +581,7 @@ TEST_F( RegistrationItkv4Test, FullyConfigured3dAffine )
connection5Parameters
[
"NameOfInterface"
]
=
{
"itkMetricv4Interface"
};
blueprint
->
AddConnection
(
"Metric"
,
"RegistrationMethod"
,
connection5Parameters
);
blueprint
->
AddConnection
(
"FixedImageSource"
,
"Transform"
,
{
{}
}
);
//
blueprint->AddConnection( "FixedImageSource", "Transform", { {} } );
blueprint
->
AddConnection
(
"Transform"
,
"RegistrationMethod"
,
{
{}
}
);
blueprint
->
AddConnection
(
"Optimizer"
,
"RegistrationMethod"
,
{
{}
}
);
...
...
Modules/Core/ComponentInterface/include/selxComponentBase.h
View file @
5f75dab4
...
...
@@ -62,25 +62,22 @@ public:
virtual
int
AcceptConnectionFrom
(
ComponentBase
*
)
=
0
;
/** if there is any failed criterion, return false (like a short - circuit AND) */
//TODO deprecate:
bool
MeetsCriteria
(
const
CriteriaType
&
criteria
);
bool
MeetsCriterionBase
(
const
CriterionType
&
criterion
);
virtual
bool
MeetsCriterion
(
const
CriterionType
&
criterion
)
=
0
;
virtual
interfaceStatus
CanAcceptConnectionFrom
(
ComponentBase
*
,
const
InterfaceCriteriaType
)
=
0
;
protected:
virtual
bool
HasAcceptingInterface
(
const
char
*
)
=
0
;
virtual
bool
HasProvidingInterface
(
const
char
*
)
=
0
;
//experimental:
virtual
unsigned
int
CountAcceptingInterfaces
(
const
InterfaceCriteriaType
)
=
0
;
virtual
unsigned
int
CountProvidingInterfaces
(
const
InterfaceCriteriaType
)
=
0
;
protected:
virtual
bool
HasAcceptingInterface
(
const
char
*
)
=
0
;
virtual
bool
HasProvidingInterface
(
const
char
*
)
=
0
;
ComponentBase
()
{}
virtual
~
ComponentBase
()
{}
};
...
...
Modules/Core/ComponentInterface/include/selxComponentSelector.h
View file @
5f75dab4
...
...
@@ -68,7 +68,7 @@ public:
/** Check for multiple versus 1 or 0 components*/
bool
HasMultipleComponents
(
void
);
unsigned
int
CountCompatible
Interface
s
(
ComponentBasePointer
other
);
unsigned
int
RequireAccept
Interface
From
(
ComponentBasePointer
other
,
const
InterfaceCriteriaType
&
interfaceCriteria
);
/** Return Component or Nullptr*/
ComponentBasePointer
GetComponent
(
void
);
...
...
Modules/Core/ComponentInterface/include/selxInterfaceTraits.h
View file @
5f75dab4
...
...
@@ -269,7 +269,7 @@ struct Properties
//static_assert(StaticErrorMessageRevealT<T>::False, "Please Implement InterfaceProperties<InterfaceType> for this InterfaceType");
static
const
std
::
map
<
std
::
string
,
std
::
string
>
Get
()
{
return
{
{
"Name"
,
InterfaceName
<
T
>::
Get
()
}
};
return
{
{
"Name
OfInterface
"
,
InterfaceName
<
T
>::
Get
()
}
};
}
};
...
...
@@ -280,7 +280,7 @@ struct Properties< itkImageFixedInterface< D, TPixel >>
{
static
const
std
::
map
<
std
::
string
,
std
::
string
>
Get
()
{
return
{
{
"Name"
,
InterfaceName
<
itkImageFixedInterface
<
D
,
TPixel
>
>::
Get
()
},
{
"Dimensionality"
,
"3"
},
{
"PixelType"
,
"float"
}
};
return
{
{
"Name
OfInterface
"
,
InterfaceName
<
itkImageFixedInterface
<
D
,
TPixel
>
>::
Get
()
},
{
"Dimensionality"
,
"3"
},
{
"PixelType"
,
"float"
}
};
}
};
...
...
@@ -289,7 +289,7 @@ struct Properties< MetricValueInterface >
{
static
const
std
::
map
<
std
::
string
,
std
::
string
>
Get
()
{
return
{
{
"Name"
,
"MetricValueInterface"
}
};
return
{
{
"Name
OfInterface
"
,
"MetricValueInterface"
}
};
}
};
}
// end namespace selx
...
...
Modules/Core/ComponentInterface/include/selxSuperElastixComponent.hxx
View file @
5f75dab4
...
...
@@ -147,12 +147,12 @@ Accepting< FirstInterface, RestInterfaces ... >::CanAcceptConnectionFrom(Compone
{
ComponentBase
::
interfaceStatus
restInterfacesStatus
=
Accepting
<
RestInterfaces
...
>::
CanAcceptConnectionFrom
(
other
,
interfaceCriteria
);
// if multiple interfaces were a succes we do not have to check any further interfaces.
// if multiple interfaces were a succes
s
we do not have to check any further interfaces.
if
(
restInterfacesStatus
==
ComponentBase
::
interfaceStatus
::
multiple
)
{
return
ComponentBase
::
interfaceStatus
::
multiple
;
}
// if a previous interface was a success, we can have either succes or multiple (successes)
// if a previous interface was a success, we can have either succes
s
or multiple (successes)
else
if
(
restInterfacesStatus
==
ComponentBase
::
interfaceStatus
::
success
)
{
unsigned
int
interfaceMeetsCriteria
=
Count
<
FirstInterface
>::
MeetsCriteria
(
interfaceCriteria
);
...
...
@@ -173,7 +173,7 @@ Accepting< FirstInterface, RestInterfaces ... >::CanAcceptConnectionFrom(Compone
}
}
}
// if a previous interface was noprovider, we can have either succes or noprovider (we know that there was at least 1 acceptor)
// if a previous interface was noprovider, we can have either succes
s
or noprovider (we know that there was at least 1 acceptor)
else
if
(
restInterfacesStatus
==
ComponentBase
::
interfaceStatus
::
noprovider
)
{
unsigned
int
interfaceMeetsCriteria
=
Count
<
FirstInterface
>::
MeetsCriteria
(
interfaceCriteria
);
...
...
@@ -194,7 +194,7 @@ Accepting< FirstInterface, RestInterfaces ... >::CanAcceptConnectionFrom(Compone
}
}
}
// if a previous interface was noaccept
o
r, we can have noaccepter, succes or noprovider
// if a previous interface was noaccept
e
r, we can have noaccepter, succes
s
or noprovider
else
if
(
restInterfacesStatus
==
ComponentBase
::
interfaceStatus
::
noaccepter
)
{
unsigned
int
interfaceMeetsCriteria
=
Count
<
FirstInterface
>::
MeetsCriteria
(
interfaceCriteria
);
...
...
@@ -215,6 +215,8 @@ Accepting< FirstInterface, RestInterfaces ... >::CanAcceptConnectionFrom(Compone
}
}
}
// never reached
return
ComponentBase
::
interfaceStatus
::
noaccepter
;
}
...
...
Modules/Core/ComponentInterface/src/selxComponentSelector.cxx
View file @
5f75dab4
...
...
@@ -70,12 +70,13 @@ ComponentSelector::AddProvidingInterfaceCriteria(const InterfaceCriteriaType & i
});
}
//
Require
CompatibleInterfaces
unsigned
int
ComponentSelector
::
CountCompatible
Interface
s
(
ComponentBasePointer
other
)
// CompatibleInterfaces
unsigned
int
ComponentSelector
::
RequireAccept
Interface
From
(
ComponentBasePointer
other
,
const
InterfaceCriteriaType
&
interfaceCriteria
)
{
this
->
m_PossibleComponents
.
remove_if
([
&
](
ComponentBasePointer
component
){
return
!
component
->
CanAcceptConnectionFrom
(
oth
er
)
;
this
->
m_PossibleComponents
.
remove_if
([
&
](
ComponentBasePointer
component
){
auto
status
=
component
->
CanAcceptConnectionFrom
(
other
,
interfaceCriteria
);
return
status
==
ComponentBase
::
interfaceStatus
::
noaccepter
||
status
==
ComponentBase
::
interfaceStatus
::
noprovid
er
;
});
return
0
;
}
ComponentSelector
::
ComponentBasePointer
...
...
Modules/Core/ComponentInterface/src/selxOverlord.cxx
View file @
5f75dab4
...
...
@@ -159,30 +159,26 @@ Overlord::ApplyConnectionConfiguration()
{
for
(
auto
const
&
outgoingName
:
this
->
m_Blueprint
->
GetOutputNames
(
name
)
)
{
//TODO check direction upstream/downstream input/output source/target
Blueprint
::
ParameterMapType
connectionProperties
=
this
->
m_Blueprint
->
GetConnection
(
name
,
outgoingName
);
//TODO
//TODO:
//1: this lambda function converts the blueprint properties: map<string,vector<string>> to interfacecriteria: map<string,string>, consider redesign.
//2: connection blueprint->addConnection("myfirstnode","mysecondnode",{{}}) creates connectionProperties {"",[]} which is not an empty map.
ComponentBase
::
InterfaceCriteriaType
interfaceCriteria
;
std
::
for_each
(
connectionProperties
.
begin
(),
connectionProperties
.
end
(),
[
interfaceCriteria
](
Blueprint
::
ParameterMapType
::
value_type
kv
)
mutable
{
interfaceCriteria
[
kv
.
first
]
=
kv
.
second
[
0
];
});
std
::
for_each
(
connectionProperties
.
begin
(),
connectionProperties
.
end
(),
[
interfaceCriteria
](
Blueprint
::
ParameterMapType
::
value_type
kv
)
mutable
{
if
(
kv
.
second
.
size
()
>
0
)
interfaceCriteria
[
kv
.
first
]
=
kv
.
second
[
0
];
});
this
->
m_ComponentSelectorContainer
[
name
]
->
AddProvidingInterfaceCriteria
(
interfaceCriteria
);
this
->
m_ComponentSelectorContainer
[
outgoingName
]
->
AddAcceptingInterfaceCriteria
(
interfaceCriteria
);
std
::
cout
<<
" Blueprint Connection: "
<<
name
<<
" -> "
<<
outgoingName
<<
std
::
endl
;
std
::
for_each
(
interfaceCriteria
.
begin
(),
interfaceCriteria
.
end
(),
[](
ComponentBase
::
InterfaceCriteriaType
::
value_type
kv
)
mutable
{
std
::
cout
<<
" { "
<<
kv
.
first
<<
": "
<<
kv
.
second
<<
" }
\n
"
;
});
if
(
connectionProperties
.
count
(
"NameOfInterface"
)
>
0
)
{
this
->
m_ComponentSelectorContainer
[
name
]
->
AddCriterion
(
{
keys
::
HasProvidingInterface
,
connectionProperties
[
keys
::
NameOfInterface
]
}
);
this
->
m_ComponentSelectorContainer
[
outgoingName
]
->
AddCriterion
(
{
keys
::
HasAcceptingInterface
,
connectionProperties
[
keys
::
NameOfInterface
]
}
);
std
::
cout
<<
" Blueprint Node: "
<<
name
<<
std
::
endl
<<
" HasProvidingInterface "
<<
connectionProperties
[
keys
::
NameOfInterface
][
0
]
<<
std
::
endl
;
std
::
cout
<<
" Blueprint Node: "
<<
outgoingName
<<
std
::
endl
<<
" HasAcceptingInterface "
<<
connectionProperties
[
keys
::
NameOfInterface
][
0
]
<<
std
::
endl
;
}
if
(
(
this
->
m_ComponentSelectorContainer
[
outgoingName
]
->
HasMultipleComponents
()
==
false
)
&&
(
this
->
m_ComponentSelectorContainer
[
outgoingName
]
->
GetComponent
().
IsNull
()
)
)
{
std
::
stringstream
msg
;
msg
<<
"Too many criteria for Component "
<<
outgoingName
<<
std
::
endl
;
msg
<<
outgoingName
<<
" does not accept a connection of given criteria"
<<
std
::
endl
;
throw
std
::
runtime_error
(
msg
.
str
()
);
}
}
...
...
@@ -190,7 +186,7 @@ Overlord::ApplyConnectionConfiguration()
&&
(
this
->
m_ComponentSelectorContainer
[
name
]
->
GetComponent
().
IsNull
()
)
)
{
std
::
stringstream
msg
;
msg
<<
"Too many criteria for Component "
<<
name
<<
std
::
endl
;
msg
<<
name
<<
" does not provide a connection of given criteria"
<<
std
::
endl
;
throw
std
::
runtime_error
(
msg
.
str
()
);
}
}
...
...
@@ -253,7 +249,8 @@ Overlord::GetSourceInterfaces()
for
(
const
auto
&
componentSelector
:
this
->
m_ComponentSelectorContainer
)
{
ComponentBase
::
Pointer
component
=
componentSelector
.
second
->
GetComponent
();
if
(
component
->
MeetsCriterionBase
(
{
keys
::
HasProvidingInterface
,
{
keys
::
SourceInterface
}
}
)
)
if
(
component
->
CountProvidingInterfaces
({
{
keys
::
NameOfInterface
,
keys
::
SourceInterface
}
})
==
1
)
{
SourceInterface
*
provingSourceInterface
=
dynamic_cast
<
SourceInterface
*
>
(
component
.
GetPointer
()
);
if
(
provingSourceInterface
==
nullptr
)
// is actually a double-check for sanity: based on criterion cast should be successful
...
...
@@ -276,7 +273,7 @@ Overlord::GetSinkInterfaces()
for
(
auto
const
&
componentSelector
:
this
->
m_ComponentSelectorContainer
)
{
ComponentBase
::
Pointer
component
=
componentSelector
.
second
->
GetComponent
();
if
(
component
->
MeetsCriterionBase
(
{
keys
::
HasProviding
Interface
,
{
keys
::
SinkInterface
}
}
)
)
if
(
component
->
CountProvidingInterfaces
({
{
keys
::
NameOf
Interface
,
keys
::
SinkInterface
}
})
==
1
)
{
SinkInterface
*
provingSinkInterface
=
dynamic_cast
<
SinkInterface
*
>
(
component
.
GetPointer
()
);
if
(
provingSinkInterface
==
nullptr
)
// is actually a double-check for sanity: based on criterion cast should be successful
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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