40 InvisibleJigsaw::InvisibleJigsaw(
const std::string& sname,
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();
53 InvisibleJigsaw::InvisibleJigsaw()
54 : Jigsaw(), m_Ninv(0), m_Nvis(0) {}
56 InvisibleJigsaw::~InvisibleJigsaw() {}
63 return SetMassInvJigsaw::Empty();
66 void InvisibleJigsaw::SetGroup(Group& group){
68 if(!group.IsInvisibleGroup())
return;
69 Jigsaw::SetGroup(group);
72 InvisibleGroup& InvisibleJigsaw::GetGroup()
const {
73 if(!Jigsaw::GetGroup())
74 return InvisibleGroup::Empty();
76 return static_cast<InvisibleGroup&
>(Jigsaw::GetGroup());
79 void InvisibleJigsaw::SetParentState(State& state){
81 if(!state.IsInvisibleState())
return;
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));
99 void InvisibleJigsaw::AddVisibleFrame(
const RestFrame& frame,
int i){
101 if(i < 0 || i >= m_Nvis)
return;
103 ConstRestFrameList frames = frame.GetListVisibleFrames();
104 int N = frames.GetN();
105 for(
int f = 0; f < N; f++)
106 AddDependancyFrame(frames[f], i);
109 void InvisibleJigsaw::AddVisibleFrames(
const ConstRestFrameList& frames,
int i){
110 int N = frames.GetN();
111 for(
int f = 0; f < N; f++)
112 AddVisibleFrame(frames[f], i);
115 void InvisibleJigsaw::AddMassFrame(
const RestFrame& frame,
int i){
117 if(i < 0 || i >= m_Nvis)
return;
119 ConstRestFrameList frames = frame.GetListVisibleFrames();
120 int N = frames.GetN();
121 for(
int f = 0; f < N; f++)
122 AddDependancyFrame(frames[f], m_Nvis + i);
125 void InvisibleJigsaw::AddMassFrames(
const ConstRestFrameList& frames,
int i){
126 int N = frames.GetN();
127 for(
int f = 0; f < N; f++)
128 AddMassFrame(frames[f], i);
131 void InvisibleJigsaw::AddInvisibleFrame(
const RestFrame& frame,
int i){
133 if(i < 0 || i >= m_Ninv)
return;
135 ConstRestFrameList frames = frame.GetListInvisibleFrames();
136 int N = frames.GetN();
137 for(
int f = 0; f < N; f++)
138 AddChildFrame(frames[f], i);
141 void InvisibleJigsaw::AddInvisibleFrames(
const ConstRestFrameList& frames,
int i){
142 int N = frames.GetN();
143 for(
int f = 0; f < N; f++)
144 AddInvisibleFrame(frames[f], i);
147 InvisibleState& InvisibleJigsaw::GetNewChildState(){
149 sprintf(strn,
"%d",GetNChildren());
150 std::string name =
GetName()+
"_"+std::string(strn);
151 InvisibleState* statePtr =
new InvisibleState(name, name);
156 double InvisibleJigsaw::GetMinimumMass()
const {
157 if(!IsSoundMind())
return 0.;
159 int N = GetNChildren();
161 for(
int i = 0; i < N; i++)
162 M += std::max(0., GetChildState(i).GetMinimumMass());
166 bool InvisibleJigsaw::InitializeAnalysis(){
168 return SetMind(
false);
170 for(
int v = 0; v < m_Nvis; v++)
171 if(GetDependancyFrames(m_Nvis + v).GetN() == 0)
172 AddMassFrames(GetDependancyFrames(v), 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 FillGroupJigsawDependancies(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 FillStateJigsawDependancies(jigsaws);
201 m_DependancyJigsaws += jigsaws;
204 FillInvisibleMassJigsawDependancies(jigsaws);
206 m_DependancyJigsaws += jigsaws;
209 FillGroupJigsawDependancies(jigsaws);
211 m_DependancyJigsaws += jigsaws;
216 bool InvisibleJigsaw::InitializeJigsawExecutionList(JigsawList& exec_jigsaws){
217 if(!IsSoundMind())
return false;
218 if(exec_jigsaws.Contains(*
this))
return true;
221 JigsawList group_jigsaws;
222 FillGroupJigsawDependancies(group_jigsaws);
223 group_jigsaws -= *
this;
225 int Ngroup = group_jigsaws.GetN();
226 for(
int i = Ngroup-1; i >= 0; i--){
227 Jigsaw& jigsaw = group_jigsaws[i];
228 if(!exec_jigsaws.Contains(jigsaw))
229 if(!jigsaw.InitializeJigsawExecutionList(exec_jigsaws))
230 return SetMind(
false);
231 m_DependancyJigsaws -= jigsaw;
234 while(m_DependancyJigsaws.GetN() > 0){
235 Jigsaw& jigsaw = m_DependancyJigsaws[m_DependancyJigsaws.GetN()-1];
236 if(exec_jigsaws.Contains(jigsaw)){
237 m_DependancyJigsaws -= jigsaw;
240 if(jigsaw.DependsOnJigsaw(*
this))
241 m_DependancyJigsaws -= jigsaw;
242 if(!jigsaw.InitializeJigsawExecutionList(exec_jigsaws))
243 return SetMind(
false);
244 m_DependancyJigsaws -= jigsaw;
247 exec_jigsaws += *
this;
251 bool InvisibleJigsaw::IsSoundBody()
const {
252 if(RFBase::IsSoundBody())
255 if(!Jigsaw::IsSoundBody())
256 return SetBody(
false);
258 for(
int i = 0; i < m_Nvis; i++){
259 if(GetDependancyFrames(i).GetN() <= 0){
261 m_Log <<
"Empty collection of visible frames: " << i;
263 return SetBody(
false);
267 return SetBody(
true);
std::string GetName() const
Returns object name.
virtual void Clear()
Clears Jigsaw of all connections to other objects.
void AddDependent(RFBase *dep)
pointer to RFBase object owned by this one
virtual void Clear()
Clears Jigsaw of all connections to other objects.