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 "mitkCommon.h"
00021 #include "mitkVector.h"
00022 #include "mitkTimeSlicedGeometry.h"
00023
00024 #include "vtkPolyData.h"
00025 #include "vtkSphereSource.h"
00026
00027 #include <fstream>
00028
00029 int mitkSurfaceTest(int , char* [])
00030 {
00031 mitk::Surface::Pointer surface;
00032 std::cout << "Testing mitk::Surface::New(): ";
00033 surface = mitk::Surface::New();
00034 if (surface.IsNull()) {
00035 std::cout<<"[FAILED]"<<std::endl;
00036 return EXIT_FAILURE;
00037 }
00038 else {
00039 std::cout<<"[PASSED]"<<std::endl;
00040 }
00041
00042 std::cout << "Testing mitk::Surface::PrintSelf() for empty surface: ";
00043 surface->PrintSelf(std::cout, 0);
00044 std::cout<<"[PASSED]"<<std::endl;
00045
00046 vtkSphereSource* sphereSource = vtkSphereSource::New();
00047 sphereSource->SetCenter(0,0,0);
00048 sphereSource->SetRadius(5.0);
00049 sphereSource->SetThetaResolution(10);
00050 sphereSource->SetPhiResolution(10);
00051 sphereSource->Update();
00052
00053 vtkPolyData* polys = sphereSource->GetOutput();
00054 surface->SetVtkPolyData( polys );
00055 sphereSource->Delete();
00056 std::cout << "Testing mitk::Surface::SetVtkPolyData(): ";
00057 if (surface->GetVtkPolyData() == NULL ) {
00058 std::cout<<"[FAILED]"<<std::endl;
00059 return EXIT_FAILURE;
00060 }
00061 else {
00062 std::cout<<"[PASSED]"<<std::endl;
00063 }
00064
00065 {
00066 vtkFloatingPointType bounds[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
00067
00068 polys->ComputeBounds();
00069 polys->GetBounds( bounds );
00070
00071 std::cout << "Testing GetBoundingBox() ";
00072 surface->UpdateOutputInformation();
00073 surface->SetRequestedRegionToLargestPossibleRegion();
00074
00075 mitk::BoundingBox* bb = const_cast<mitk::BoundingBox*>(surface->GetGeometry()->GetBoundingBox());
00076 mitk::BoundingBox::BoundsArrayType surfBounds = bb->GetBounds();
00077
00078 if ( bounds[0] != surfBounds[0]
00079 || bounds[1] != surfBounds[1]
00080 || bounds[2] != surfBounds[2]
00081 || bounds[3] != surfBounds[3]
00082 || bounds[4] != surfBounds[4]
00083 || bounds[5] != surfBounds[5]
00084 ) {
00085 std::cout<<"[FAILED]"<<std::endl;
00086 return EXIT_FAILURE;
00087 }
00088 else {
00089 std::cout<<"[PASSED]"<<std::endl;
00090 }
00091 }
00092
00093
00094 std::cout << "Testing mitk::Surface::Expand( timesteps ): ";
00095 surface->Expand(5);
00096 surface->Update();
00097 surface->SetRequestedRegionToLargestPossibleRegion();
00098 mitk::Surface::RegionType requestedRegion = surface->GetRequestedRegion();
00099
00100 if ( requestedRegion.GetSize(3) != 5 ) {
00101 std::cout<<"[FAILED]"<<std::endl;
00102 return EXIT_FAILURE;
00103 }
00104 else {
00105 std::cout<<"[PASSED]"<<std::endl;
00106 }
00107
00108 std::cout << "Testing mitk::Surface::Testing 4D surface data creation: ";
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 vtkFloatingPointType bounds[5][6];
00119
00120 for (int i=0;i<5;i++) {
00121 vtkSphereSource* sphereSource = vtkSphereSource::New();
00122 sphereSource->SetCenter(0,0,0);
00123 sphereSource->SetRadius(1.0 * (i+1.0));
00124 sphereSource->SetThetaResolution(10);
00125 sphereSource->SetPhiResolution(10);
00126 sphereSource->Update();
00127 sphereSource->GetOutput()->ComputeBounds();
00128 sphereSource->GetOutput()->GetBounds( bounds[i] );
00129 surface->SetVtkPolyData( sphereSource->GetOutput(),i );
00130 sphereSource->Delete();
00131 }
00132
00133 surface->UpdateOutputInformation();
00134 surface->SetRequestedRegionToLargestPossibleRegion();
00135
00136 bool passed = true;
00137 for (int i=0;i<5;i++)
00138 {
00139 mitk::BoundingBox::BoundsArrayType surfBounds = (const_cast<mitk::BoundingBox*>(surface->GetTimeSlicedGeometry()->GetGeometry3D(i)->GetBoundingBox()))->GetBounds();
00140
00141 if ( bounds[i][0] != surfBounds[0]
00142 || bounds[i][1] != surfBounds[1]
00143 || bounds[i][2] != surfBounds[2]
00144 || bounds[i][3] != surfBounds[3]
00145 || bounds[i][4] != surfBounds[4]
00146 || bounds[i][5] != surfBounds[5] )
00147 {
00148 passed = false;
00149 break;
00150 }
00151 }
00152
00153 if (!passed)
00154 {
00155 std::cout<<"[FAILED]"<<std::endl;
00156 return EXIT_FAILURE;
00157 }
00158 else
00159 {
00160 std::cout<<"[PASSED]"<<std::endl;
00161 }
00162
00163 std::cout << "Testing correctness of geometry for surface->GetUpdatedTimeSlicedGeometry(): \n";
00164 const mitk::TimeSlicedGeometry* inputTimeGeometry = surface->GetUpdatedTimeSlicedGeometry();
00165
00166 int time = 3;
00167 int timestep=0;
00168 timestep = inputTimeGeometry->MSToTimeStep( time );
00169
00170 std::cout << "time: "<< time << std::endl;
00171 std::cout << "timestep: "<<timestep << std::endl;
00172
00173 if (time != timestep)
00174 {
00175 std::cout<<"[FAILED]"<<std::endl;
00176 return EXIT_FAILURE;
00177 }
00178 else
00179 {
00180 std::cout<<"[PASSED]"<<std::endl;
00181 }
00182
00183 std::cout << "Explicitly changing the data of timestep 3 and checking for timebounds correctness of surface's geometry again:\n";
00184
00185 sphereSource = vtkSphereSource::New();
00186 sphereSource->SetCenter(0,0,0);
00187 sphereSource->SetRadius( 100.0 );
00188 sphereSource->SetThetaResolution(10);
00189 sphereSource->SetPhiResolution(10);
00190 sphereSource->Update();
00191 surface->SetVtkPolyData( sphereSource->GetOutput(), 3 );
00192 sphereSource->Delete();
00193
00194 inputTimeGeometry = surface->GetUpdatedTimeSlicedGeometry();
00195 time = 3;
00196 timestep=0;
00197 timestep = inputTimeGeometry->MSToTimeStep( time );
00198
00199 std::cout << "time: "<< time << std::endl;
00200 std::cout << "timestep: "<<timestep << std::endl;
00201
00202 if (time != timestep)
00203 {
00204 std::cout<<"[FAILED]"<<std::endl;
00205 return EXIT_FAILURE;
00206 }
00207 else
00208 {
00209 std::cout<<"[PASSED]"<<std::endl;
00210 }
00211
00212 std::cout << "Testing copying a Surface with Graft()" << std::endl;
00213
00214 unsigned int numberoftimesteps = surface->GetTimeSteps();
00215 mitk::Surface::Pointer dummy = mitk::Surface::New();
00216 dummy->Graft(surface);
00217 std::cout << "polyData != NULL ??" << std::endl;
00218 if (dummy->GetVtkPolyData() == NULL)
00219 {
00220 std::cout<<"[FAILED]"<<std::endl;
00221 return EXIT_FAILURE;
00222 }
00223
00224 std::cout << "orig-numberofTimeSteps:" << numberoftimesteps << " copy-numberofTimeSteps:" << dummy->GetTimeSteps() << std::endl;
00225 if (dummy->GetTimeSteps() != numberoftimesteps)
00226 {
00227 std::cout<<"[FAILED]"<<std::endl;
00228 return EXIT_FAILURE;
00229 }
00230
00231 std::cout<<"[TEST DONE]"<<std::endl;
00232 return EXIT_SUCCESS;
00233 }