Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "mitkBaseData.h"
00020 #include <itkObjectFactoryBase.h>
00021 #include <itkSmartPointerForwardReference.txx>
00022
00023
00024
00025 #define MITK_WEAKPOINTER_PROBLEM_WORKAROUND_ENABLED
00026
00027 mitk::BaseData::BaseData() :
00028 m_RequestedRegionInitialized(false), m_SmartSourcePointer(NULL),
00029 m_SourceOutputIndexDuplicate(0), m_Initialized(true),
00030 m_Unregistering(false), m_CalculatingExternalReferenceCount(false),
00031 m_ExternalReferenceCount(-1)
00032 {
00033 m_TimeSlicedGeometry = TimeSlicedGeometry::New();
00034 m_PropertyList = PropertyList::New();
00035 }
00036
00037 mitk::BaseData::~BaseData()
00038 {
00039 m_SmartSourcePointer = NULL;
00040 }
00041
00042 void mitk::BaseData::InitializeTimeSlicedGeometry(unsigned int timeSteps)
00043 {
00044 mitk::TimeSlicedGeometry::Pointer timeGeometry = this->GetTimeSlicedGeometry();
00045
00046 mitk::Geometry3D::Pointer g3d = mitk::Geometry3D::New();
00047 g3d->Initialize();
00048
00049 if ( timeSteps > 1 )
00050 {
00051 mitk::ScalarType timeBounds[] = {0.0, 1.0};
00052 g3d->SetTimeBounds( timeBounds );
00053 }
00054
00055
00056
00057 timeGeometry->InitializeEvenlyTimed( g3d.GetPointer(), timeSteps );
00058 }
00059
00060 void mitk::BaseData::UpdateOutputInformation()
00061 {
00062 if ( this->GetSource() )
00063 {
00064 this->GetSource()->UpdateOutputInformation();
00065 }
00066 if(m_TimeSlicedGeometry.IsNotNull())
00067 m_TimeSlicedGeometry->UpdateInformation();
00068 }
00069
00070 const mitk::TimeSlicedGeometry* mitk::BaseData::GetUpdatedTimeSlicedGeometry()
00071 {
00072 SetRequestedRegionToLargestPossibleRegion();
00073
00074 UpdateOutputInformation();
00075
00076 return GetTimeSlicedGeometry();
00077 }
00078
00079 void mitk::BaseData::Expand( unsigned int timeSteps )
00080 {
00081 if( m_TimeSlicedGeometry.IsNotNull() )
00082 m_TimeSlicedGeometry->ExpandToNumberOfTimeSteps( timeSteps );
00083 }
00084
00085 const mitk::Geometry3D* mitk::BaseData::GetUpdatedGeometry(int t)
00086 {
00087 SetRequestedRegionToLargestPossibleRegion();
00088
00089 UpdateOutputInformation();
00090
00091 return GetGeometry(t);
00092 }
00093
00094 void mitk::BaseData::SetGeometry(Geometry3D* aGeometry3D)
00095 {
00096 if(aGeometry3D!=NULL)
00097 {
00098 TimeSlicedGeometry::Pointer timeSlicedGeometry = dynamic_cast<TimeSlicedGeometry*>(aGeometry3D);
00099 if ( timeSlicedGeometry.IsNotNull() )
00100 m_TimeSlicedGeometry = timeSlicedGeometry;
00101 else
00102 {
00103 timeSlicedGeometry = TimeSlicedGeometry::New();
00104 m_TimeSlicedGeometry = timeSlicedGeometry;
00105 timeSlicedGeometry->InitializeEvenlyTimed(aGeometry3D, 1);
00106 }
00107 Modified();
00108 }
00109 else if( m_TimeSlicedGeometry.IsNotNull() )
00110 {
00111 m_TimeSlicedGeometry = NULL;
00112 Modified();
00113 }
00114 return;
00115 }
00116
00117 void mitk::BaseData::SetGeometry(Geometry3D* aGeometry3D, unsigned int time)
00118 {
00119 if ( m_TimeSlicedGeometry )
00120 m_TimeSlicedGeometry->SetGeometry3D(aGeometry3D, time);
00121 }
00122
00123 void mitk::BaseData::SetClonedGeometry(const Geometry3D* aGeometry3D)
00124 {
00125 SetGeometry(static_cast<mitk::Geometry3D*>(aGeometry3D->Clone().GetPointer()));
00126 }
00127
00128 void mitk::BaseData::SetClonedGeometry(const Geometry3D* aGeometry3D, unsigned int time)
00129 {
00130 SetGeometry(static_cast<mitk::Geometry3D*>(aGeometry3D->Clone().GetPointer()), time);
00131 }
00132
00133 bool mitk::BaseData::IsEmpty(unsigned int) const
00134 {
00135 return IsInitialized() == false;
00136 }
00137
00138 bool mitk::BaseData::IsEmpty() const
00139 {
00140 if(IsInitialized() == false)
00141 return true;
00142 const TimeSlicedGeometry* timeGeometry = const_cast<BaseData*>(this)->GetUpdatedTimeSlicedGeometry();
00143 if(timeGeometry == NULL)
00144 return true;
00145 unsigned int timeSteps = timeGeometry->GetTimeSteps();
00146 for ( unsigned int t = 0 ; t < timeSteps ; ++t )
00147 {
00148 if(IsEmpty(t) == false)
00149 return false;
00150 }
00151 return true;
00152 }
00153
00154 itk::SmartPointerForwardReference<mitk::BaseProcess> mitk::BaseData::GetSource() const
00155 {
00156 return static_cast<mitk::BaseProcess*>(Superclass::GetSource().GetPointer());
00157 }
00158
00159 int mitk::BaseData::GetExternalReferenceCount() const
00160 {
00161 if(m_CalculatingExternalReferenceCount==false)
00162 {
00163 m_CalculatingExternalReferenceCount = true;
00164
00165 m_ExternalReferenceCount = -1;
00166
00167 int realReferenceCount = GetReferenceCount();
00168
00169 if(GetSource()==NULL)
00170 {
00171 m_ExternalReferenceCount = realReferenceCount;
00172 m_CalculatingExternalReferenceCount = false;
00173 return m_ExternalReferenceCount;
00174 }
00175
00176 mitk::BaseProcess::DataObjectPointerArray outputs = m_SmartSourcePointer->GetOutputs();
00177
00178 unsigned int idx;
00179 for (idx = 0; idx < outputs.size(); ++idx)
00180 {
00181
00182 if(outputs[idx]==this)
00183 --realReferenceCount;
00184 }
00185 m_ExternalReferenceCount = realReferenceCount;
00186 if(m_ExternalReferenceCount<0)
00187 m_ExternalReferenceCount=0;
00188 m_CalculatingExternalReferenceCount = false;
00189 }
00190 else
00191 return -1;
00192 return m_ExternalReferenceCount;
00193 }
00194
00195 void mitk::BaseData::UnRegister() const
00196 {
00197 #ifdef MITK_WEAKPOINTER_PROBLEM_WORKAROUND_ENABLED
00198 if(GetReferenceCount()>1)
00199 {
00200 Superclass::UnRegister();
00201 if((m_Unregistering==false) && (m_SmartSourcePointer.IsNotNull()))
00202 {
00203 m_Unregistering=true;
00204
00205
00206
00207
00208
00209
00210 if((this->m_SmartSourcePointer->GetExternalReferenceCount()==0) || (this->GetSource()==NULL))
00211 m_SmartSourcePointer=NULL;
00212 else
00213 m_Unregistering=false;
00214 }
00215 }
00216 else
00217 #endif
00218 Superclass::UnRegister();
00219 }
00220
00221 void mitk::BaseData::ConnectSource(itk::ProcessObject *arg, unsigned int idx) const
00222 {
00223 #ifdef MITK_WEAKPOINTER_PROBLEM_WORKAROUND_ENABLED
00224 itkDebugMacro( "connecting source " << arg
00225 << ", source output index " << idx);
00226
00227 if ( GetSource() != arg || m_SourceOutputIndexDuplicate != idx)
00228 {
00229 m_SmartSourcePointer = dynamic_cast<mitk::BaseProcess*>(arg);
00230 m_SourceOutputIndexDuplicate = idx;
00231 Modified();
00232 }
00233 #endif
00234 }
00235
00236 mitk::PropertyList::Pointer mitk::BaseData::GetPropertyList() const
00237 {
00238 return m_PropertyList;
00239 }
00240
00241
00242 mitk::BaseProperty::Pointer mitk::BaseData::GetProperty(const char *propertyKey) const
00243 {
00244 return m_PropertyList->GetProperty(propertyKey);
00245 }
00246
00247 void mitk::BaseData::SetProperty(const char *propertyKey,
00248 BaseProperty* propertyValue)
00249 {
00250 m_PropertyList->SetProperty(propertyKey, propertyValue);
00251 }
00252
00253 void mitk::BaseData::SetPropertyList(PropertyList *pList)
00254 {
00255 m_PropertyList = pList;
00256 }
00257
00258 void mitk::BaseData::SetOrigin(const mitk::Point3D& origin)
00259 {
00260 mitk::TimeSlicedGeometry* timeSlicedGeometry = GetTimeSlicedGeometry();
00261
00262 assert(timeSlicedGeometry!=NULL);
00263
00264 mitk::Geometry3D* geometry;
00265
00266 unsigned int steps = timeSlicedGeometry->GetTimeSteps();
00267
00268 for(unsigned int timestep = 0; timestep < steps; ++timestep)
00269 {
00270 geometry = GetGeometry(timestep);
00271 if(geometry != NULL)
00272 {
00273 geometry->SetOrigin(origin);
00274 }
00275 if(GetTimeSlicedGeometry()->GetEvenlyTimed())
00276 {
00277 GetTimeSlicedGeometry()->InitializeEvenlyTimed(geometry, steps);
00278 break;
00279 }
00280 }
00281 }
00282
00283 unsigned long mitk::BaseData::GetMTime() const
00284 {
00285 unsigned long time = Superclass::GetMTime();
00286 if(m_TimeSlicedGeometry.IsNotNull())
00287 {
00288 if((time < m_TimeSlicedGeometry->GetMTime()))
00289 {
00290 Modified();
00291 return Superclass::GetMTime();
00292 }
00293
00294
00295
00296
00297
00298 }
00299 return time;
00300 }
00301
00302 void mitk::BaseData::CopyInformation( const itk::DataObject* data )
00303 {
00304 const Self* bd = dynamic_cast<const Self*>(data);
00305 if (bd != NULL)
00306 {
00307 m_TimeSlicedGeometry = dynamic_cast<TimeSlicedGeometry*>(bd->GetTimeSlicedGeometry()->Clone().GetPointer());
00308 m_PropertyList = bd->GetPropertyList()->Clone();
00309 }
00310 else
00311 {
00312
00313
00314 itkExceptionMacro(<< "mitk::BaseData::CopyInformation() cannot cast "
00315 << typeid(data).name() << " to "
00316 << typeid(Self*).name() );
00317 }
00318
00319 }
00320
00321 bool mitk::BaseData::IsInitialized() const
00322 {
00323 return m_Initialized;
00324 }
00325
00326 void mitk::BaseData::Clear()
00327 {
00328 this->ClearData();
00329 this->InitializeEmpty();
00330 }
00331
00332 void mitk::BaseData::ClearData()
00333 {
00334 if(m_Initialized)
00335 {
00336 ReleaseData();
00337 m_Initialized = false;
00338 }
00339 }
00340
00341 void mitk::BaseData::ExecuteOperation(mitk::Operation* )
00342 {
00343
00344 }
00345
00346 void mitk::BaseData::PrintSelf(std::ostream& os, itk::Indent indent) const
00347 {
00348 os << std::endl;
00349 os << indent << " TimeSlicedGeometry: ";
00350 if(GetTimeSlicedGeometry() == NULL)
00351 os << "NULL" << std::endl;
00352 else
00353 GetTimeSlicedGeometry()->Print(os, indent);
00354 }
00355