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 "mitkSurface.h"
00020 #include "mitkInteractionConst.h"
00021 #include "mitkSurfaceOperation.h"
00022
00023 #include <vtkPolyData.h>
00024
00025 #include <itkSmartPointerForwardReference.txx>
00026
00027
00028
00029 mitk::Surface::Surface() :
00030 m_CalculateBoundingBox( false )
00031 {
00032 this->InitializeEmpty();
00033 }
00034
00035 mitk::Surface::~Surface()
00036 {
00037 this->ClearData();
00038 }
00039
00040 void mitk::Surface::ClearData()
00041 {
00042 for ( VTKPolyDataSeries::iterator it = m_PolyDataSeries.begin(); it != m_PolyDataSeries.end(); ++it )
00043 {
00044 if ( ( *it ) != NULL )
00045 ( *it )->Delete();
00046 }
00047 m_PolyDataSeries.clear();
00048
00049 Superclass::ClearData();
00050 }
00051
00052 void mitk::Surface::InitializeEmpty()
00053 {
00054 vtkPolyData* pdnull = NULL;
00055 m_PolyDataSeries.resize( 1, pdnull );
00056 Superclass::InitializeTimeSlicedGeometry(1);
00057
00058 m_Initialized = true;
00059 }
00060
00061 void mitk::Surface::SetVtkPolyData( vtkPolyData* polydata, unsigned int t )
00062 {
00063
00064 this->Expand( t+1 );
00065
00066 if(m_PolyDataSeries[ t ] != NULL)
00067 {
00068
00069 m_PolyDataSeries[ t ]->Delete();
00070 }
00071 m_PolyDataSeries[ t ] = polydata;
00072
00073
00074
00075 if(m_PolyDataSeries[ t ] != NULL)
00076 {
00077 m_PolyDataSeries[ t ]->Register( NULL );
00078 }
00079 this->Modified();
00080 m_CalculateBoundingBox = true;
00081 }
00082
00083 bool mitk::Surface::IsEmpty(unsigned int t) const
00084 {
00085 if(!IsInitialized())
00086 return false;
00087 vtkPolyData* polydata = const_cast<Surface*>(this)->GetVtkPolyData(t);
00088 return
00089 (polydata == NULL) ||
00090 (
00091 (polydata->GetNumberOfVerts() <= 0) &&
00092 (polydata->GetNumberOfPolys() <= 0) &&
00093 (polydata->GetNumberOfStrips() <= 0) &&
00094 (polydata->GetNumberOfLines() <= 0)
00095 );
00096 }
00097
00098 vtkPolyData* mitk::Surface::GetVtkPolyData( unsigned int t )
00099 {
00100
00101 if ( t < m_PolyDataSeries.size() )
00102 {
00103 vtkPolyData* polydata = m_PolyDataSeries[ t ];
00104 if((polydata==NULL) && (GetSource().GetPointer()!=NULL))
00105 {
00106 RegionType requestedregion;
00107 requestedregion.SetIndex(3, t);
00108 requestedregion.SetSize(3, 1);
00109 SetRequestedRegion(&requestedregion);
00110 GetSource()->Update();
00111 }
00112 polydata = m_PolyDataSeries[ t ];
00113 return polydata;
00114 }
00115 else
00116 return NULL;
00117 }
00118
00119 void mitk::Surface::UpdateOutputInformation()
00120 {
00121 if ( this->GetSource() )
00122 {
00123 this->GetSource()->UpdateOutputInformation();
00124 }
00125 if ( ( m_CalculateBoundingBox ) && ( m_PolyDataSeries.size() > 0 ) )
00126 CalculateBoundingBox();
00127 else
00128 GetTimeSlicedGeometry()->UpdateInformation();
00129 }
00130
00131 void mitk::Surface::CalculateBoundingBox()
00132 {
00133
00134
00135
00136
00137 mitk::TimeSlicedGeometry* timeGeometry = GetTimeSlicedGeometry();
00138 if ( timeGeometry->GetTimeSteps() != m_PolyDataSeries.size() )
00139 {
00140 itkExceptionMacro(<<"timeGeometry->GetTimeSteps() != m_PolyDataSeries.size() -- use Initialize(timeSteps) with correct number of timeSteps!");
00141 }
00142
00143
00144
00145
00146
00147 for ( unsigned int i = 0 ; i < m_PolyDataSeries.size() ; ++i )
00148 {
00149 vtkPolyData* polyData = m_PolyDataSeries[ i ];
00150 vtkFloatingPointType bounds[ ] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
00151 if ( ( polyData != NULL ) && ( polyData->GetNumberOfPoints() > 0 ) )
00152 {
00153 polyData->Update();
00154 polyData->ComputeBounds();
00155 polyData->GetBounds( bounds );
00156 }
00157 mitk::Geometry3D::Pointer g3d = timeGeometry->GetGeometry3D( i );
00158 assert( g3d.IsNotNull() );
00159 g3d->SetFloatBounds( bounds );
00160 }
00161 timeGeometry->UpdateInformation();
00162
00163 mitk::BoundingBox::Pointer bb = const_cast<mitk::BoundingBox*>( timeGeometry->GetBoundingBox() );
00164 itkDebugMacro( << "boundingbox min: "<< bb->GetMinimum());
00165 itkDebugMacro( << "boundingbox max: "<< bb->GetMaximum());
00166 m_CalculateBoundingBox = false;
00167 }
00168
00169 void mitk::Surface::SetRequestedRegionToLargestPossibleRegion()
00170 {
00171 m_RequestedRegion = GetLargestPossibleRegion();
00172 }
00173
00174 bool mitk::Surface::RequestedRegionIsOutsideOfTheBufferedRegion()
00175 {
00176 RegionType::IndexValueType end = m_RequestedRegion.GetIndex(3)+m_RequestedRegion.GetSize(3);
00177
00178 if(((RegionType::IndexValueType)m_PolyDataSeries.size())<end)
00179 return true;
00180
00181 for( RegionType::IndexValueType t=m_RequestedRegion.GetIndex(3); t<end; ++t )
00182 if(m_PolyDataSeries[t]==NULL)
00183 return true;
00184
00185 return false;
00186 }
00187
00188 bool mitk::Surface::VerifyRequestedRegion()
00189 {
00190 if( (m_RequestedRegion.GetIndex(3)>=0) &&
00191 (m_RequestedRegion.GetIndex(3)+m_RequestedRegion.GetSize(3)<=m_PolyDataSeries.size()) )
00192 return true;
00193
00194 return false;
00195 }
00196
00197 void mitk::Surface::SetRequestedRegion( itk::DataObject *data )
00198 {
00199 mitk::Surface *surfaceData;
00200
00201 surfaceData = dynamic_cast<mitk::Surface*>(data);
00202
00203 if (surfaceData)
00204 {
00205 m_RequestedRegion = surfaceData->GetRequestedRegion();
00206 }
00207 else
00208 {
00209
00210 itkExceptionMacro( << "mitk::Surface::SetRequestedRegion(DataObject*) cannot cast " << typeid(data).name() << " to " << typeid(Surface*).name() );
00211 }
00212 }
00213
00214 void mitk::Surface::SetRequestedRegion(Surface::RegionType *region)
00215 {
00216 if(region!=NULL)
00217 {
00218 m_RequestedRegion = *region;
00219 }
00220 else
00221 {
00222
00223 itkExceptionMacro( << "mitk::Surface::SetRequestedRegion(Surface::RegionType*) cannot cast " << typeid(region).name() << " to " << typeid(Surface*).name() );
00224 }
00225 }
00226
00227 void mitk::Surface::CopyInformation( const itk::DataObject * data)
00228 {
00229 Superclass::CopyInformation( data );
00230
00231 const mitk::Surface* surfaceData;
00232
00233 surfaceData = dynamic_cast<const mitk::Surface*>( data );
00234
00235 if ( surfaceData )
00236 {
00237 m_LargestPossibleRegion = surfaceData->GetLargestPossibleRegion();
00238 }
00239 else
00240 {
00241
00242 itkExceptionMacro( << "mitk::Surface::CopyInformation(const DataObject *data) cannot cast " << typeid(data).name() << " to " << typeid(surfaceData).name() );
00243 }
00244 }
00245
00246 void mitk::Surface::Update()
00247 {
00248 if ( GetSource() == NULL )
00249 {
00250 for ( VTKPolyDataSeries::iterator it = m_PolyDataSeries.begin() ; it != m_PolyDataSeries.end() ; ++it )
00251 {
00252 if ( ( *it ) != NULL )
00253 ( *it )->Update();
00254 }
00255 }
00256 Superclass::Update();
00257 }
00258
00259 void mitk::Surface::Expand( unsigned int timeSteps )
00260 {
00261
00262
00263 if ( timeSteps > m_PolyDataSeries.size() )
00264 {
00265 Superclass::Expand( timeSteps );
00266 vtkPolyData* pdnull = NULL;
00267 m_PolyDataSeries.resize( timeSteps, pdnull );
00268 m_CalculateBoundingBox = true;
00269 }
00270 }
00271
00272 void mitk::Surface::ExecuteOperation(Operation *operation)
00273 {
00274 switch ( operation->GetOperationType() )
00275 {
00276 case OpSURFACECHANGED:
00277
00278 mitk::SurfaceOperation* surfOp = dynamic_cast<mitk::SurfaceOperation*>(operation);
00279 if( ! surfOp ) break;
00280
00281 unsigned int time = surfOp->GetTimeStep();
00282
00283 if(m_PolyDataSeries[ time ] != NULL)
00284 {
00285 vtkPolyData* updatePoly = surfOp->GetVtkPolyData();
00286 if( updatePoly ){
00287 this->SetVtkPolyData( updatePoly, time );
00288 this->CalculateBoundingBox();
00289 }
00290 }
00291 break;
00292 }
00293 this->Modified();
00294 }
00295
00296 unsigned int mitk::Surface::GetSizeOfPolyDataSeries() const
00297 {
00298 return m_PolyDataSeries.size();
00299 }
00300
00301 void mitk::Surface::Graft( const DataObject* data )
00302 {
00303 const Self* surface;
00304 try
00305 {
00306 surface = dynamic_cast<const Self*>( data );
00307 }
00308 catch(...)
00309 {
00310 itkExceptionMacro( << "mitk::Surface::Graft cannot cast "
00311 << typeid(data).name() << " to "
00312 << typeid(const Self *).name() );
00313 return;
00314 }
00315
00316 if(!surface)
00317 {
00318
00319 itkExceptionMacro( << "mitk::Surface::Graft cannot cast "
00320 << typeid(data).name() << " to "
00321 << typeid(const Self *).name() );
00322 return;
00323 }
00324
00325 this->CopyInformation( data );
00326
00327 m_PolyDataSeries.clear();
00328
00329 for (unsigned int i=0; i<surface->GetSizeOfPolyDataSeries(); i++)
00330 {
00331 m_PolyDataSeries.push_back(vtkPolyData::New());
00332 m_PolyDataSeries.back()->DeepCopy( const_cast<mitk::Surface*>(surface)->GetVtkPolyData( i ) );
00333
00334 }
00335 }
00336
00337 void mitk::Surface::PrintSelf( std::ostream& os, itk::Indent indent ) const
00338 {
00339 Superclass::PrintSelf(os, indent);
00340
00341 os << indent << "\nNumber PolyDatas: " << m_PolyDataSeries.size() << "\n";
00342 unsigned int count = 0;
00343 for (VTKPolyDataSeries::const_iterator it = m_PolyDataSeries.begin(); it != m_PolyDataSeries.end(); ++it)
00344 {
00345 vtkPolyData* pd = *it;
00346 if(pd != NULL)
00347 {
00348 os << "\n";
00349 os << indent << "PolyData at time step " << count << ". \n";
00350 os << indent << "Number of cells " << pd->GetNumberOfCells() << ": \n";
00351 os << indent << "Number of points " << pd->GetNumberOfPoints() << ": \n\n";
00352 os << indent << "VTKPolyData : \n";
00353 pd->Print(os);
00354 }
00355 else
00356 os << indent << "\nEmpty PolyData at time step " << count << ".\n";
00357
00358 count++;
00359 }
00360 }