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 "mitkUnstructuredGrid.h"
00020
00021 #include <vtkUnstructuredGrid.h>
00022
00023 #include <itkSmartPointerForwardReference.txx>
00024
00025 void mitk::UnstructuredGrid::SetVtkUnstructuredGrid( vtkUnstructuredGrid* grid, unsigned int t )
00026 {
00027 this->Expand(t);
00028
00029 if(m_GridSeries[ t ] != NULL)
00030 {
00031 m_GridSeries[ t ]->Delete();
00032 }
00033
00034 m_GridSeries[ t ] = grid;
00035
00036
00037
00038 if (m_GridSeries[t] != 0)
00039 m_GridSeries[t]->Register(grid);
00040
00041 this->Modified();
00042 m_CalculateBoundingBox = true;
00043 }
00044
00045 void mitk::UnstructuredGrid::Expand(unsigned int timeSteps)
00046 {
00047
00048
00049 if(timeSteps > m_GridSeries.size())
00050 {
00051 Superclass::Expand(timeSteps);
00052 vtkUnstructuredGrid* pdnull = 0;
00053 m_GridSeries.resize( timeSteps, pdnull );
00054 m_CalculateBoundingBox = true;
00055 }
00056 }
00057
00058 void mitk::UnstructuredGrid::ClearData()
00059 {
00060 for ( VTKUnstructuredGridSeries::iterator it = m_GridSeries.begin(); it != m_GridSeries.end(); ++it )
00061 {
00062 if ( ( *it ) != 0 )
00063 ( *it )->Delete();
00064 }
00065 m_GridSeries.clear();
00066
00067 Superclass::ClearData();
00068 }
00069
00070 void mitk::UnstructuredGrid::InitializeEmpty()
00071 {
00072 vtkUnstructuredGrid* pdnull = 0;
00073 m_GridSeries.resize( 1, pdnull );
00074 Superclass::InitializeTimeSlicedGeometry(1);
00075
00076 m_Initialized = true;
00077 }
00078
00079 vtkUnstructuredGrid* mitk::UnstructuredGrid::GetVtkUnstructuredGrid(unsigned int t)
00080 {
00081 if ( t < m_GridSeries.size() )
00082 {
00083 vtkUnstructuredGrid* grid = m_GridSeries[ t ];
00084 if((grid == 0) && (GetSource().GetPointer() != 0))
00085 {
00086 RegionType requestedregion;
00087 requestedregion.SetIndex(3, t);
00088 requestedregion.SetSize(3, 1);
00089 SetRequestedRegion(&requestedregion);
00090 GetSource()->Update();
00091 }
00092 grid = m_GridSeries[ t ];
00093 return grid;
00094 }
00095 else
00096 return 0;
00097 }
00098
00099 mitk::UnstructuredGrid::UnstructuredGrid() : m_CalculateBoundingBox( false )
00100 {
00101 this->InitializeEmpty();
00102 }
00103
00104 mitk::UnstructuredGrid::~UnstructuredGrid()
00105 {
00106 this->ClearData();
00107 }
00108
00109 void mitk::UnstructuredGrid::UpdateOutputInformation()
00110 {
00111 if ( this->GetSource() )
00112 {
00113 this->GetSource()->UpdateOutputInformation();
00114 }
00115 if ( ( m_CalculateBoundingBox ) && ( m_GridSeries.size() > 0 ) )
00116 CalculateBoundingBox();
00117 else
00118 GetTimeSlicedGeometry()->UpdateInformation();
00119 }
00120
00121 void mitk::UnstructuredGrid::CalculateBoundingBox()
00122 {
00123
00124
00125
00126
00127 mitk::TimeSlicedGeometry* timeGeometry = GetTimeSlicedGeometry();
00128 if ( timeGeometry->GetTimeSteps() != m_GridSeries.size() )
00129 {
00130 itkExceptionMacro(<<"timeGeometry->GetTimeSteps() != m_GridSeries.size() -- use Initialize(timeSteps) with correct number of timeSteps!");
00131 }
00132
00133
00134
00135
00136
00137 for ( unsigned int i = 0 ; i < m_GridSeries.size() ; ++i )
00138 {
00139 vtkUnstructuredGrid* grid = m_GridSeries[ i ];
00140 vtkFloatingPointType bounds[ ] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
00141 if ( ( grid != 0 ) && ( grid->GetNumberOfCells() > 0 ) )
00142 {
00143 grid->Update();
00144 grid->ComputeBounds();
00145 grid->GetBounds( bounds );
00146 }
00147 mitk::Geometry3D::Pointer g3d = timeGeometry->GetGeometry3D( i );
00148 assert( g3d.IsNotNull() );
00149 g3d->SetFloatBounds( bounds );
00150 }
00151 timeGeometry->UpdateInformation();
00152
00153 mitk::BoundingBox::Pointer bb = const_cast<mitk::BoundingBox*>( timeGeometry->GetBoundingBox() );
00154 itkDebugMacro( << "boundingbox min: "<< bb->GetMinimum());
00155 itkDebugMacro( << "boundingbox max: "<< bb->GetMaximum());
00156 m_CalculateBoundingBox = false;
00157 }
00158
00159
00160 void mitk::UnstructuredGrid::SetRequestedRegionToLargestPossibleRegion()
00161 {
00162 m_RequestedRegion = GetLargestPossibleRegion();
00163 }
00164
00165 bool mitk::UnstructuredGrid::RequestedRegionIsOutsideOfTheBufferedRegion()
00166 {
00167 RegionType::IndexValueType end = m_RequestedRegion.GetIndex(3)+m_RequestedRegion.GetSize(3);
00168
00169 if(((RegionType::IndexValueType)m_GridSeries.size()) < end)
00170 return true;
00171
00172 for( RegionType::IndexValueType t=m_RequestedRegion.GetIndex(3); t < end; ++t )
00173 if(m_GridSeries[t] == 0)
00174 return true;
00175
00176 return false;
00177 }
00178
00179 bool mitk::UnstructuredGrid::VerifyRequestedRegion()
00180 {
00181 if( (m_RequestedRegion.GetIndex(3)>=0) &&
00182 (m_RequestedRegion.GetIndex(3)+m_RequestedRegion.GetSize(3)<=m_GridSeries.size()) )
00183 return true;
00184
00185 return false;
00186 }
00187
00188 void mitk::UnstructuredGrid::SetRequestedRegion( itk::DataObject *data )
00189 {
00190 mitk::UnstructuredGrid *gridData;
00191
00192 gridData = dynamic_cast<mitk::UnstructuredGrid*>(data);
00193
00194 if (gridData)
00195 {
00196 m_RequestedRegion = gridData->GetRequestedRegion();
00197 }
00198 else
00199 {
00200
00201 itkExceptionMacro( << "mitk::UnstructuredGrid::SetRequestedRegion(DataObject*) cannot cast " << typeid(data).name() << " to " << typeid(UnstructuredGrid*).name() );
00202 }
00203 }
00204
00205 void mitk::UnstructuredGrid::SetRequestedRegion(UnstructuredGrid::RegionType *region)
00206 {
00207 if(region != 0)
00208 {
00209 m_RequestedRegion = *region;
00210 }
00211 else
00212 {
00213
00214 itkExceptionMacro( << "mitk::UnstructuredGrid::SetRequestedRegion(UnstructuredGrid::RegionType*) cannot cast " << typeid(region).name() << " to " << typeid(UnstructuredGrid*).name() );
00215 }
00216 }
00217
00218 void mitk::UnstructuredGrid::CopyInformation( const itk::DataObject * data )
00219 {
00220 Superclass::CopyInformation(data);
00221 }
00222
00223 void mitk::UnstructuredGrid::Update()
00224 {
00225 if ( GetSource() == 0 )
00226 {
00227 for ( VTKUnstructuredGridSeries::iterator it = m_GridSeries.begin() ; it != m_GridSeries.end() ; ++it )
00228 {
00229 if ( ( *it ) != 0 )
00230 ( *it )->Update();
00231 }
00232 }
00233 Superclass::Update();
00234 }