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 "mitkImage.h"
00020 #include "mitkPlaneGeometry.h"
00021 #include "mitkTimeSlicedGeometry.h"
00022 #include "mitkSlicedGeometry3D.h"
00023
00024 #include <vnl/vnl_quaternion.h>
00025 #include <vnl/vnl_quaternion.txx>
00026
00027 #include <fstream>
00028
00029 int mitkTimeSlicedGeometryTest(int , char* [])
00030 {
00031 mitk::PlaneGeometry::Pointer planegeometry = mitk::PlaneGeometry::New();
00032
00033 mitk::Point3D origin;
00034 mitk::Vector3D right, bottom, normal;
00035 mitk::ScalarType width, height;
00036 mitk::ScalarType widthInMM, heightInMM, thicknessInMM;
00037
00038 width = 100; widthInMM = width*0.5;
00039 height = 200; heightInMM = height*1.2;
00040 thicknessInMM = 1.5;
00041 mitk::FillVector3D(origin, 2.5, -3.3, 17.2);
00042 mitk::FillVector3D(right, widthInMM, 0, 0);
00043 mitk::FillVector3D(bottom, 0, heightInMM, 0);
00044 mitk::FillVector3D(normal, 0, 0, thicknessInMM);
00045
00046
00047 std::cout << "Creating TimeSlicedGeometry" <<std::endl;
00048 mitk::TimeSlicedGeometry::Pointer timeSlicedGeometry = mitk::TimeSlicedGeometry::New();
00049 if(timeSlicedGeometry.IsNull())
00050 {
00051 std::cout<<"[FAILED]"<<std::endl;
00052 return EXIT_FAILURE;
00053 }
00054 std::cout<<"[PASSED]"<<std::endl;
00055
00056 unsigned int numOfTimeSteps = 5;
00057 std::cout << "Testing TimeSlicedGeometry::Initialize(timesteps = " << numOfTimeSteps << "): " <<std::endl;
00058 timeSlicedGeometry->Initialize(numOfTimeSteps);
00059 std::cout<<"[PASSED]"<<std::endl;
00060
00061 std::cout << "Testing TimeSlicedGeometry::GetTimeSteps()==" << numOfTimeSteps << ": " <<std::endl;
00062 if(timeSlicedGeometry->GetTimeSteps()!=numOfTimeSteps)
00063 {
00064 std::cout<<"[FAILED]"<<std::endl;
00065 return EXIT_FAILURE;
00066 }
00067 std::cout<<"[PASSED]"<<std::endl;
00068
00069 std::cout << "Testing TimeSlicedGeometry::GetEvenlyTimed(): " <<std::endl;
00070 if(timeSlicedGeometry->GetEvenlyTimed()!=true)
00071 {
00072 std::cout<<"[FAILED]"<<std::endl;
00073 return EXIT_FAILURE;
00074 }
00075 std::cout<<"[PASSED]"<<std::endl;
00076
00077
00078
00079 mitk::TimeBounds timeBounds1;
00080 timeBounds1[0] = 1.3;
00081 timeBounds1[1] = 2.4;
00082
00083 std::cout << "Initializing a PlaneGeometry by InitializeStandardPlane(rightVector, downVector, spacing = NULL): "<<std::endl;
00084 planegeometry->InitializeStandardPlane(right.Get_vnl_vector(), bottom.Get_vnl_vector());
00085 std::cout<<"[PASSED]"<<std::endl;
00086
00087 std::cout << "Setting TimeBounds of PlaneGeometry by SetTimeBounds(): "<<std::endl;
00088 planegeometry->SetTimeBounds(timeBounds1);
00089 std::cout<<"[PASSED]"<<std::endl;
00090
00091 std::cout << "Testing PlaneGeometry::GetTimeBounds(): "<<std::endl;
00092 if(planegeometry->GetTimeBounds() != timeBounds1)
00093 {
00094 std::cout<<"[FAILED]"<<std::endl;
00095 return EXIT_FAILURE;
00096 }
00097 std::cout<<"[PASSED]"<<std::endl;
00098
00099
00100 --numOfTimeSteps;
00101 std::cout << "Testing TimeSlicedGeometry::InitializeEvenlyTimed(planegeometry, timesteps = " << numOfTimeSteps << "): " <<std::endl;
00102 mitk::TimeSlicedGeometry::Pointer timeSlicedGeometry2 = mitk::TimeSlicedGeometry::New();
00103 timeSlicedGeometry2->InitializeEvenlyTimed(planegeometry, numOfTimeSteps);
00104 std::cout<<"[PASSED]"<<std::endl;
00105
00106 std::cout << "Testing TimeSlicedGeometry::GetTimeSteps()==" << numOfTimeSteps << ": " <<std::endl;
00107 if(timeSlicedGeometry2->GetTimeSteps() != numOfTimeSteps)
00108 {
00109 std::cout<<"[FAILED]"<<std::endl;
00110 return EXIT_FAILURE;
00111 }
00112 std::cout<<"[PASSED]"<<std::endl;
00113
00114 std::cout << "Testing TimeSlicedGeometry::GetEvenlyTimed(): " <<std::endl;
00115 if(timeSlicedGeometry2->GetEvenlyTimed()!=true)
00116 {
00117 std::cout<<"[FAILED]"<<std::endl;
00118 return EXIT_FAILURE;
00119 }
00120 std::cout<<"[PASSED]"<<std::endl;
00121
00122 std::cout << "Testing TimeSlicedGeometry::TimeStepToMS(): " << std::endl;
00123 if(fabs(timeSlicedGeometry2->TimeStepToMS( 2 ) - 3.5) > mitk::eps)
00124 {
00125 std::cout<<"[FAILED]"<<std::endl;
00126 return EXIT_FAILURE;
00127 }
00128 std::cout<<"[PASSED]"<<std::endl;
00129
00130 std::cout << "Testing TimeSlicedGeometry::MSToTimeStep(): " << std::endl;
00131 if(timeSlicedGeometry2->MSToTimeStep( 3.6 ) != 2)
00132 {
00133 std::cout<<"[FAILED]"<<std::endl;
00134 return EXIT_FAILURE;
00135 }
00136 std::cout<<"[PASSED]"<<std::endl;
00137
00138
00139 std::cout << "Testing TimeSlicedGeometry::TimeStepToTimeStep(): " << std::endl;
00140
00141
00142 mitk::TimeBounds timeBounds;
00143 timeBounds[0] = 0.0;
00144 timeBounds[1] = 1.0;
00145 mitk::Geometry3D::Pointer geometry = mitk::Geometry3D::New();
00146 geometry->Initialize();
00147 geometry->SetTimeBounds( timeBounds );
00148 timeSlicedGeometry->InitializeEvenlyTimed( geometry, numOfTimeSteps+1 );
00149
00150 if(timeSlicedGeometry2->TimeStepToTimeStep( timeSlicedGeometry, 4 ) != 2)
00151 {
00152 std::cout<<"[FAILED]"<<std::endl;
00153 return EXIT_FAILURE;
00154 }
00155 std::cout<<"[PASSED]"<<std::endl;
00156
00157 std::cout << "Testing availability and type (PlaneGeometry) of first geometry in the TimeSlicedGeometry: ";
00158 mitk::PlaneGeometry* accessedplanegeometry = dynamic_cast<mitk::PlaneGeometry*>(timeSlicedGeometry2->GetGeometry3D(0));
00159 if(accessedplanegeometry==NULL)
00160 {
00161 std::cout<<"[FAILED]"<<std::endl;
00162 return EXIT_FAILURE;
00163 }
00164 std::cout<<"[PASSED]"<<std::endl;
00165
00166 std::cout << "Testing identity of first geometry to the planegeometry in the TimeSlicedGeometry (should not be cloned): ";
00167 if(accessedplanegeometry != planegeometry.GetPointer())
00168 {
00169 std::cout<<"[FAILED]"<<std::endl;
00170 return EXIT_FAILURE;
00171 }
00172 std::cout<<"[PASSED]"<<std::endl;
00173
00174 std::cout << "Testing whether the spatial part of the first geometry in the TimeSlicedGeometry is identical to planegeometry by axis comparison and origin: "<<std::endl;
00175 if((mitk::Equal(accessedplanegeometry->GetAxisVector(0), planegeometry->GetAxisVector(0))==false) ||
00176 (mitk::Equal(accessedplanegeometry->GetAxisVector(1), planegeometry->GetAxisVector(1))==false) ||
00177 (mitk::Equal(accessedplanegeometry->GetAxisVector(2), planegeometry->GetAxisVector(2))==false) ||
00178 (mitk::Equal(accessedplanegeometry->GetOrigin(), planegeometry->GetOrigin())==false))
00179 {
00180 std::cout<<"[FAILED]"<<std::endl;
00181 return EXIT_FAILURE;
00182 }
00183 std::cout<<"[PASSED]"<<std::endl;
00184
00185 std::cout << "Testing timebounds of first geometry: "<<std::endl;
00186 if( timeBounds1 != accessedplanegeometry->GetTimeBounds() )
00187 {
00188 std::cout<<"[FAILED]"<<std::endl;
00189 return EXIT_FAILURE;
00190 }
00191 std::cout<<"[PASSED]"<<std::endl;
00192
00193
00194
00195 std::cout << "Testing availability and type (PlaneGeometry) of second geometry in the TimeSlicedGeometry: ";
00196 mitk::PlaneGeometry* secondplanegeometry = dynamic_cast<mitk::PlaneGeometry*>(timeSlicedGeometry2->GetGeometry3D(1));
00197 if(secondplanegeometry==NULL)
00198 {
00199 std::cout<<"[FAILED]"<<std::endl;
00200 return EXIT_FAILURE;
00201 }
00202 std::cout<<"[PASSED]"<<std::endl;
00203
00204 std::cout << "Testing PlaneGeometry::GetTimeBounds(): "<<std::endl;
00205 const mitk::TimeBounds & secondtimebounds = secondplanegeometry->GetTimeBounds();
00206 if( (timeBounds1[1] != secondtimebounds[0]) || (secondtimebounds[1] != secondtimebounds[0] + timeBounds1[1]-timeBounds1[0]) )
00207 {
00208 std::cout<<"[FAILED]"<<std::endl;
00209 return EXIT_FAILURE;
00210 }
00211 std::cout<<"[PASSED]"<<std::endl;
00212
00213
00214 std::cout << "Testing whether the spatial part of the second geometry in the TimeSlicedGeometry is identical to planegeometry by axis comparison and origin: "<<std::endl;
00215 if((mitk::Equal(secondplanegeometry->GetAxisVector(0), planegeometry->GetAxisVector(0))==false) ||
00216 (mitk::Equal(secondplanegeometry->GetAxisVector(1), planegeometry->GetAxisVector(1))==false) ||
00217 (mitk::Equal(secondplanegeometry->GetAxisVector(2), planegeometry->GetAxisVector(2))==false) ||
00218 (mitk::Equal(secondplanegeometry->GetOrigin(), planegeometry->GetOrigin())==false))
00219 {
00220 std::cout<<"[FAILED]"<<std::endl;
00221 return EXIT_FAILURE;
00222 }
00223 std::cout<<"[PASSED]"<<std::endl;
00224
00225
00226 std::cout << "Creating (new) TimeSlicedGeometry" <<std::endl;
00227 timeSlicedGeometry2 = mitk::TimeSlicedGeometry::New();
00228 if(timeSlicedGeometry2.IsNull())
00229 {
00230 std::cout<<"[FAILED]"<<std::endl;
00231 return EXIT_FAILURE;
00232 }
00233 std::cout<<"[PASSED]"<<std::endl;
00234
00235 numOfTimeSteps += 7;
00236 std::cout << "Testing TimeSlicedGeometry::InitializeEmpty(timesteps = " << numOfTimeSteps << "): " <<std::endl;
00237 timeSlicedGeometry2->InitializeEmpty(numOfTimeSteps);
00238
00239 std::cout << "Testing TimeSlicedGeometry::GetEvenlyTimed():" <<std::endl;
00240 if(timeSlicedGeometry2->GetEvenlyTimed()!=false)
00241 {
00242 std::cout<<"[FAILED]"<<std::endl;
00243 return EXIT_FAILURE;
00244 }
00245 std::cout<<"[PASSED]"<<std::endl;
00246
00247 std::cout << "Testing TimeSlicedGeometry::SetEvenlyTimed(false):" <<std::endl;
00248 timeSlicedGeometry2->SetEvenlyTimed(false);
00249 std::cout<<"[PASSED]"<<std::endl;
00250
00251 std::cout << "Testing TimeSlicedGeometry::GetEvenlyTimed()==false:" <<std::endl;
00252 if(timeSlicedGeometry2->GetEvenlyTimed()!=false)
00253 {
00254 std::cout<<"[FAILED]"<<std::endl;
00255 return EXIT_FAILURE;
00256 }
00257 std::cout<<"[PASSED]"<<std::endl;
00258
00259 std::cout << "Testing TimeSlicedGeometry::GetTimeSteps()==" << numOfTimeSteps << ": " <<std::endl;
00260 if(timeSlicedGeometry2->GetTimeSteps() != numOfTimeSteps)
00261 {
00262 std::cout<<"[FAILED]"<<std::endl;
00263 return EXIT_FAILURE;
00264 }
00265 std::cout<<"[PASSED]"<<std::endl;
00266
00267 std::cout << "Testing availability of first geometry in the TimeSlicedGeometry (should not exist): ";
00268 mitk::Geometry3D* accessedgeometry = timeSlicedGeometry2->GetGeometry3D(0);
00269 if(accessedgeometry!=NULL)
00270 {
00271 std::cout<<"[FAILED]"<<std::endl;
00272 return EXIT_FAILURE;
00273 }
00274 std::cout<<"[PASSED]"<<std::endl;
00275
00276 std::cout << "Testing TimeSlicedGeometry::SetGeometry3D(planegeometry, timesteps = 0): " <<std::endl;
00277 timeSlicedGeometry2->SetGeometry3D(planegeometry, 0);
00278 std::cout<<"[PASSED]"<<std::endl;
00279
00280 std::cout << "Testing availability and type (PlaneGeometry) of first geometry in the TimeSlicedGeometry: ";
00281 accessedplanegeometry = dynamic_cast<mitk::PlaneGeometry*>(timeSlicedGeometry2->GetGeometry3D(0));
00282 if(accessedplanegeometry==NULL)
00283 {
00284 std::cout<<"[FAILED]"<<std::endl;
00285 return EXIT_FAILURE;
00286 }
00287 std::cout<<"[PASSED]"<<std::endl;
00288
00289 std::cout << "Testing identity of first geometry to the planegeometry in the TimeSlicedGeometry: ";
00290 if(accessedplanegeometry != planegeometry.GetPointer())
00291 {
00292 std::cout<<"[FAILED]"<<std::endl;
00293 return EXIT_FAILURE;
00294 }
00295 std::cout<<"[PASSED]"<<std::endl;
00296
00297
00298
00299 std::cout << "Testing availability of second geometry in the TimeSlicedGeometry (should not exist): ";
00300 accessedgeometry = timeSlicedGeometry2->GetGeometry3D(1);
00301 if(accessedgeometry!=NULL)
00302 {
00303 std::cout<<"[FAILED]"<<std::endl;
00304 return EXIT_FAILURE;
00305 }
00306 std::cout<<"[PASSED]"<<std::endl;
00307
00308
00309 std::cout << "Setting planegeometry2 to a cloned version of planegeometry: "<<std::endl;
00310 mitk::PlaneGeometry::Pointer planegeometry2;
00311 planegeometry2 = dynamic_cast<mitk::PlaneGeometry*>(planegeometry->Clone().GetPointer());;
00312 std::cout<<"[PASSED]"<<std::endl;
00313
00314 std::cout << "Changing timebounds of planegeometry2: "<<std::endl;
00315 mitk::TimeBounds timeBounds3;
00316 timeBounds3[0] = timeBounds[1];
00317 timeBounds3[1] = timeBounds3[0]+13.2334;
00318 planegeometry2->SetTimeBounds(timeBounds3);
00319 std::cout<<"[PASSED]"<<std::endl;
00320
00321 std::cout << "Testing TimeSlicedGeometry::SetGeometry3D(planegeometry2, timesteps = 1): " <<std::endl;
00322 timeSlicedGeometry2->SetGeometry3D(planegeometry2, 1);
00323 std::cout<<"[PASSED]"<<std::endl;
00324
00325 std::cout << "Testing availability and type (PlaneGeometry) of second geometry in the TimeSlicedGeometry: ";
00326 accessedplanegeometry = dynamic_cast<mitk::PlaneGeometry*>(timeSlicedGeometry2->GetGeometry3D(1));
00327 if(accessedplanegeometry==NULL)
00328 {
00329 std::cout<<"[FAILED]"<<std::endl;
00330 return EXIT_FAILURE;
00331 }
00332 std::cout<<"[PASSED]"<<std::endl;
00333
00334 std::cout << "Testing identity of second geometry to the planegeometry2 in the TimeSlicedGeometry: ";
00335 if(accessedplanegeometry != planegeometry2.GetPointer())
00336 {
00337 std::cout<<"[FAILED]"<<std::endl;
00338 return EXIT_FAILURE;
00339 }
00340 std::cout<<"[PASSED]"<<std::endl;
00341
00342 std::cout << "Testing timebounds of second geometry: "<<std::endl;
00343 if( timeBounds3 != accessedplanegeometry->GetTimeBounds() )
00344 {
00345 std::cout<<"[FAILED]"<<std::endl;
00346 return EXIT_FAILURE;
00347 }
00348 std::cout<<"[PASSED]"<<std::endl;
00349
00350
00351 std::cout<<"[TEST DONE]"<<std::endl;
00352 return EXIT_SUCCESS;
00353 }