@@ -896,13 +896,37 @@ void Crystal::XMLInput(istream &is,const XMLCrystTag &tagg)
896
896
this ->RemoveSubRefObj (mScatteringPowerRegistry .GetObj (i));
897
897
mScatteringPowerRegistry .GetObj (i).DeRegisterClient (*this );
898
898
}
899
- mScatteringPowerRegistry .DeleteAll ();
899
+
900
+ std::list<ScatteringPowerAtom*> vold_scattpow;
901
+ if (mDeleteSubObjInDestructor )
902
+ {
903
+ mScatteringPowerRegistry .DeleteAll ();
904
+ }
905
+ else
906
+ {
907
+ // Keep track of the old atomic scattering powers to see if they can be re-used
908
+ for (std::vector<ScatteringPower*>::const_iterator pos=mScatteringPowerRegistry .begin () ;
909
+ pos!=mScatteringPowerRegistry .end (); ++pos)
910
+ {
911
+ if ((*pos)->GetClassName ().compare (" ScatteringPowerAtom" )!=0 ) continue ;
912
+ vold_scattpow.push_back (dynamic_cast <ScatteringPowerAtom*>(*pos));
913
+ }
914
+ mScatteringPowerRegistry .DeRegisterAll ();
915
+ }
916
+
900
917
for (long i=0 ;i<mScattererRegistry .GetNb ();i++)
901
918
{
902
919
this ->RemoveSubRefObj (mScattererRegistry .GetObj (i));
903
920
mScattererRegistry .GetObj (i).DeRegisterClient (*this );
904
921
}
905
- mScattererRegistry .DeleteAll ();
922
+ if (mDeleteSubObjInDestructor )
923
+ {
924
+ mScattererRegistry .DeleteAll ();
925
+ }
926
+ else
927
+ {
928
+ mScattererRegistry .DeRegisterAll ();
929
+ }
906
930
907
931
for (unsigned int i=0 ;i<tagg.GetNbAttribute ();i++)
908
932
{
@@ -1011,6 +1035,33 @@ void Crystal::XMLInput(istream &is,const XMLCrystTag &tagg)
1011
1035
VFN_DEBUG_MESSAGE (" Crystal::XMLInput():reading a ScatteringPowerAtom" ,5 )
1012
1036
ScatteringPowerAtom *sc=new ScatteringPowerAtom;
1013
1037
sc->XMLInput (is,tag);
1038
+ if (!mDeleteSubObjInDestructor )
1039
+ {
1040
+ // Can we re-use a previous scattering power since we did not delete them ?
1041
+ for (std::list<ScatteringPowerAtom*>::iterator pos= vold_scattpow.begin ();
1042
+ pos!=vold_scattpow.end ();++pos)
1043
+ {
1044
+ if ((*pos)->GetSymbol () != sc->GetSymbol ()) continue ;
1045
+ if ((*pos)->GetName () != sc->GetName ()) continue ;
1046
+ if ((*pos)->GetFormalCharge () != sc->GetFormalCharge ()) continue ;
1047
+ if ((*pos)->GetMaximumLikelihoodNbGhostAtom () != sc->GetMaximumLikelihoodNbGhostAtom ()) continue ;
1048
+ if ((*pos)->GetMaximumLikelihoodPositionError () != sc->GetMaximumLikelihoodPositionError ()) continue ;
1049
+ if ((*pos)->IsIsotropic () != sc->IsIsotropic ()) continue ;
1050
+ if (fabs ((*pos)->GetBiso () - sc->GetBiso ()) > 1e-4f ) continue ;
1051
+ if (!(*pos)->IsIsotropic ())
1052
+ {
1053
+ if (fabs ((*pos)->GetBij (0 ) - sc->GetBij (0 )) > 1e-4f ) continue ;
1054
+ if (fabs ((*pos)->GetBij (1 ) - sc->GetBij (1 )) > 1e-4f ) continue ;
1055
+ if (fabs ((*pos)->GetBij (2 ) - sc->GetBij (2 )) > 1e-4f ) continue ;
1056
+ if (fabs ((*pos)->GetBij (3 ) - sc->GetBij (3 )) > 1e-4f ) continue ;
1057
+ if (fabs ((*pos)->GetBij (4 ) - sc->GetBij (4 )) > 1e-4f ) continue ;
1058
+ if (fabs ((*pos)->GetBij (5 ) - sc->GetBij (5 )) > 1e-4f ) continue ;
1059
+ }
1060
+ VFN_DEBUG_MESSAGE (" Crystal::XMLInput(): reusing scattering power: " <<sc->GetName (),5 );
1061
+ delete sc;
1062
+ sc = *pos;
1063
+ }
1064
+ }
1014
1065
this ->AddScatteringPower (sc);
1015
1066
VFN_DEBUG_EXIT (" Crystal::XMLInput():reading a ScatteringPowerAtom" ,5 )
1016
1067
continue ;
0 commit comments