34 namespace RestFrames {
41 const std::string& stitle,
42 int Ninvisible,
int Nvisible) :
43 Jigsaw(sname, stitle, Ninvisible, 2*Nvisible),
44 m_Ninv(Ninvisible), m_Nvis(Nvisible)
46 m_Type = kInvisibleJigsaw;
47 m_InvMassDependancy =
false;
48 for(
int i = 0; i < m_Ninv; i++){
49 m_ChildStates += GetNewChildState();
54 :
Jigsaw(), m_Ninv(0), m_Nvis(0) {}
56 InvisibleJigsaw::~InvisibleJigsaw() {}
79 void InvisibleJigsaw::SetParentState(
State& state){
82 Jigsaw::SetParentState(state);
85 InvisibleState
const& InvisibleJigsaw::GetParentState()
const {
86 if(!Jigsaw::GetParentState())
87 return InvisibleState::Empty();
89 return static_cast<const InvisibleState&
>(Jigsaw::GetParentState());
92 InvisibleState& InvisibleJigsaw::GetChildState(
int i)
const{
93 if(!Jigsaw::GetChildState(i))
94 return InvisibleState::Empty();
96 return static_cast<InvisibleState&
>(Jigsaw::GetChildState(i));
101 if(i < 0 || i >= m_Nvis)
return;
104 int N = frames.GetN();
105 for(
int f = 0; f < N; f++)
106 AddDependancyFrame(frames[f], i);
110 int N = frames.GetN();
111 for(
int f = 0; f < N; f++)
117 if(i < 0 || i >= m_Nvis)
return;
120 int N = frames.GetN();
121 for(
int f = 0; f < N; f++)
122 AddDependancyFrame(frames[f], m_Nvis + i);
126 int N = frames.GetN();
127 for(
int f = 0; f < N; f++)
133 if(i < 0 || i >= m_Ninv)
return;
136 int N = frames.GetN();
137 for(
int f = 0; f < N; f++)
138 AddChildFrame(frames[f], i);
142 int N = frames.GetN();
143 for(
int f = 0; f < N; f++)
149 sprintf(strn,
"%d",GetNChildren());
150 std::string name =
GetName()+
"_"+std::string(strn);
157 if(!IsSoundMind())
return 0.;
159 int N = GetNChildren();
161 for(
int i = 0; i < N; i++)
166 bool InvisibleJigsaw::InitializeAnalysis(){
168 return SetMind(
false);
170 for(
int v = 0; v < m_Nvis; v++)
175 return Jigsaw::InitializeAnalysis();
178 void InvisibleJigsaw::FillInvisibleMassJigsawDependancies(JigsawList& jigsaws)
const {
179 if(m_InvMassDependancy){
180 for(
int i = m_Nvis; i < 2*m_Nvis; i++){
181 int M = GetDependancyStates(i).GetN();
182 for(
int j = 0; j < M; j++){
183 GetDependancyStates(i)[j].GetParentJigsaw().
184 FillJigsawDependancies(jigsaws);
188 for(
int i = 0; i < m_Ninv; i++)
189 static_cast<const InvisibleJigsaw&
>(GetChildState(i).GetChildJigsaw()).
190 FillInvisibleMassJigsawDependancies(jigsaws);
193 bool InvisibleJigsaw::InitializeDependancyJigsaws(){
194 if(!IsSoundMind())
return false;
196 m_DependancyJigsaws.Clear();
199 FillJigsawDependancies(jigsaws);
201 m_DependancyJigsaws += jigsaws;
204 FillInvisibleMassJigsawDependancies(jigsaws);
206 m_DependancyJigsaws += jigsaws;
209 JigsawList group_jigsaws;
210 FillGroupJigsawDependants(group_jigsaws);
211 group_jigsaws -= *
this;
212 m_DependancyJigsaws -= group_jigsaws;
217 bool InvisibleJigsaw::InitializeJigsawExecutionList(JigsawList& exec_jigsaws, JigsawList& todo_jigsaws){
218 if(!IsSoundMind())
return false;
219 if(exec_jigsaws.Contains(*
this))
return true;
221 JigsawList group_jigsaws;
222 group_jigsaws.Clear();
223 FillGroupJigsawDependancies(group_jigsaws);
224 group_jigsaws -= *
this;
226 int Ngroup = group_jigsaws.GetN();
227 for(
int i = Ngroup-1; i >= 0; i--){
228 Jigsaw& jigsaw = group_jigsaws[i];
229 if(!exec_jigsaws.Contains(jigsaw))
230 if(!jigsaw.InitializeJigsawExecutionList(exec_jigsaws, todo_jigsaws))
231 return SetMind(
false);
232 m_DependancyJigsaws -= jigsaw;
235 while(m_DependancyJigsaws.GetN() > 0){
236 Jigsaw& jigsaw = m_DependancyJigsaws[m_DependancyJigsaws.GetN()-1];
237 if(exec_jigsaws.Contains(jigsaw)){
238 m_DependancyJigsaws -= jigsaw;
241 if(!jigsaw.InitializeJigsawExecutionList(exec_jigsaws, todo_jigsaws))
242 return SetMind(
false);
243 m_DependancyJigsaws -= jigsaw;
246 if(!exec_jigsaws.Contains(*
this)){
247 exec_jigsaws += *
this;
248 todo_jigsaws += *
this;
253 bool InvisibleJigsaw::IsSoundBody()
const {
254 if(RFBase::IsSoundBody())
257 if(!Jigsaw::IsSoundBody())
258 return SetBody(
false);
260 for(
int i = 0; i < m_Nvis; i++){
263 m_Log <<
"Empty collection of visible frames: " << i;
265 return SetBody(
false);
269 return SetBody(
true);