36 namespace RestFrames {
38 int Group::m_class_key = 0;
41 const std::string& stitle)
44 m_Type = kVanillaGroup;
45 m_GroupStatePtr =
nullptr;
50 m_Type = kVanillaGroup;
65 m_GroupStatePtr =
nullptr;
71 m_StatesToResolve.Clear();
72 m_JigsawsToUse.Clear();
76 return m_Type == kInvisibleGroup;
80 return m_Type == kCombinatoricGroup;
94 int N = frames.GetN();
95 for(
int i = 0; i < N; i++)
113 if(m_JigsawsToUse.Add(jigsaw))
118 if(!m_Frames.Contains(frame))
124 m_Frames.Remove(frame);
128 int N = m_Frames.GetN();
129 for(
int i = N-1; i >= 0; i--){
135 if(!m_Jigsaws.Contains(jigsaw) &&
136 !m_JigsawsToUse.Contains(jigsaw))
142 m_Jigsaws.Remove(jigsaw);
143 m_JigsawsToUse.Remove(jigsaw);
147 int N = m_Jigsaws.GetN();
148 for(
int i = N-1; i >= 0; i--){
151 N = m_JigsawsToUse.GetN();
152 for(
int i = N-1; i >= 0; i--){
158 return m_Frames.Contains(frame);
162 return m_Frames.GetN();
173 State& Group::GetParentState()
const {
175 return *m_GroupStatePtr;
180 bool Group::InitializeAnalysis(){
182 m_Log <<
"Initializing Group for analysis...";
185 m_GroupStatePtr = &InitializeParentState();
188 if(!ResolveUnknowns()){
190 m_Log <<
"Unable to resolve unknowns associated with ";
191 m_Log <<
"Frames in this Group with available Jigsaws";
193 return SetBody(
false);
197 m_Log <<
"...Done initializing group for analysis" << LogEnd;
199 return SetMind(
true);
202 bool Group::ResolveUnknowns(){
203 m_JigsawsToUse += m_Jigsaws;
206 int Njigsaw = m_JigsawsToUse.GetN();
207 for(
int i = 0; i < Njigsaw; i++){
208 if(m_JigsawsToUse[i].GetNChildren() == 1){
209 m_JigsawsToUse[i].RemoveFrames(m_Frames);
211 for(
int j = 0; j < N; j++)
212 m_JigsawsToUse[i].AddChildFrame(m_Frames[j]);
217 m_StatesToResolve.Clear();
218 m_States.Add(*m_GroupStatePtr);
219 m_StatesToResolve.Add(*m_GroupStatePtr);
221 while(m_StatesToResolve.GetN() > 0){
222 State& state = m_StatesToResolve.Get(0);
223 if(!ResolveState(state)){
224 if(state.GetNFrames() != 1){
226 m_Log <<
"Cannot find Jigsaw to Resolve State for frames:";
227 m_Log << std::endl <<
" " << Log(state.GetListFrames());
231 m_StatesToResolve.Remove(state);
237 bool Group::ResolveState(
const State& state){
238 Jigsaw* jigsawSolutionPtr =
nullptr;
240 int N = m_JigsawsToUse.GetN();
241 for(
int i = 0; i < N; i++){
242 Jigsaw* jigsawPtr = &m_JigsawsToUse[i];
243 if(jigsawPtr->CanResolve(state)){
244 if(!jigsawSolutionPtr){
245 jigsawSolutionPtr = jigsawPtr;
248 if(jigsawPtr->GetNChildren() <= jigsawSolutionPtr->GetNChildren())
249 if((jigsawPtr->GetNChildren() < jigsawSolutionPtr->GetNChildren()) ||
250 (jigsawPtr->GetNDependancyStates() < jigsawSolutionPtr->GetNDependancyStates()))
251 jigsawSolutionPtr = jigsawPtr;
254 if(!jigsawSolutionPtr)
258 m_Log <<
"Found Jigsaw to resolve State:" << std::endl;
259 m_Log <<
" Frames:" << std::endl <<
" ";
260 m_Log << Log(state.GetListFrames()) << std::endl;
261 m_Log <<
" Jigsaw:" << Log(jigsawSolutionPtr);
264 if(!InitializeJigsaw(*jigsawSolutionPtr))
267 m_JigsawsToUse.Remove(*jigsawSolutionPtr);
271 bool Group::InitializeJigsaw(Jigsaw& jigsaw){
272 State& state = m_StatesToResolve[0];
273 jigsaw.SetParentState(state);
275 if(!jigsaw.InitializeTree()){
277 m_Log <<
"Unable to initialize Jigsaw:";
278 m_Log << Log(jigsaw) << LogEnd;
282 m_States += jigsaw.GetChildStates();
283 m_StatesToResolve -= state;
284 m_StatesToResolve += jigsaw.GetChildStates();
290 int Group::GetNChildStates()
const {
291 return m_States.GetN();
294 State& Group::GetChildState(
int i)
const {
295 if(i < 0 || i > GetNChildStates()-1)
301 State& Group::GetChildState(
const RestFrame& frame)
const {
303 int Ns = GetNChildStates();
304 for(
int i = Ns-1; i >= 0; i--)
305 if(m_States[i].IsFrame(frame))
311 StateList Group::GetChildStates(
const RestFrameList& frames)
const {
315 int Ns = m_States.GetN();
316 for(
int i = 0; i < Ns; i++){
317 RestFrameList iframes = m_States[i].GetListFrames();
318 if(frames.Contains(iframes)){
319 int Nsol = states.GetN();
321 for(
int j = 0; j < Nsol; j++){
323 RestFrameList jframes = states[j].GetListFrames();
324 if(iframes.Contains(jframes)){
325 states.Remove(states[j]);
329 if(jframes.Contains(iframes)){
334 if(isnew) states.Add(m_States[i]);
338 RestFrameList match_frames;
340 for(
int i = 0; i < Ns; i++)
343 if(!(frames == match_frames)){
345 m_Log <<
"Unable to find States corresponding to Frames: " << std::endl;
346 m_Log << Log(frames) << LogEnd;
353 RestFrame
const& Group::GetLabFrame()
const {
354 if(m_Frames.GetN() < 1)
357 return m_Frames[0].GetLabFrame();