00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "mitkGeometry2DDataToSurfaceFilter.h"
00019
00020 #include "mitkSurface.h"
00021 #include "mitkPlaneGeometry.h"
00022 #include "mitkGeometry2DData.h"
00023
00024 #include "vtkPolyData.h"
00025
00026 #include <fstream>
00027
00028 template <typename TScalarType>
00029 int testExpectedIndexBoundingBox(mitk::Geometry3D* geometry, TScalarType expectedIndexBounds[6])
00030 {
00031 mitk::BoundingBox* bb = const_cast<mitk::BoundingBox*>(geometry->GetBoundingBox());
00032 mitk::BoundingBox::BoundsArrayType bounds = bb->GetBounds();
00033
00034 int i;
00035 for(i=0;i<6;++i)
00036 {
00037 if( mitk::Equal(bounds[i], expectedIndexBounds[i]) == false)
00038 {
00039 std::cout<<"[FAILED]"<<std::endl;
00040 return EXIT_FAILURE;
00041 }
00042 }
00043 std::cout<<"[PASSED]"<<std::endl;
00044 return EXIT_SUCCESS;
00045 }
00046
00047 template <typename TScalarType>
00048 int testExpectedAxisParallelBoundingBox(mitk::Geometry3D* geometry, TScalarType expectedAxisParallelBounds[6])
00049 {
00050 mitk::BoundingBox::Pointer bb = geometry->CalculateBoundingBoxRelativeToTransform(NULL);
00051 mitk::BoundingBox::BoundsArrayType bounds = bb->GetBounds();
00052
00053 int i;
00054 for(i=0;i<6;++i)
00055 {
00056 if( mitk::Equal(bounds[i], expectedAxisParallelBounds[i]) == false)
00057 {
00058 std::cout<<"[FAILED]"<<std::endl;
00059 return EXIT_FAILURE;
00060 }
00061 }
00062 std::cout<<"[PASSED]"<<std::endl;
00063 return EXIT_SUCCESS;
00064 }
00065
00066 int testSurfaceBoundingBoxConsistency(mitk::Surface* surface, bool expectIdentityTransform)
00067 {
00068 int result;
00069 std::cout << " Testing surface contents: ";
00070 if ((surface == NULL )
00071 || (surface->GetVtkPolyData() == NULL)
00072 || (surface->GetVtkPolyData()->GetNumberOfPoints() == 0 )) {
00073 std::cout<<"[FAILED]"<<std::endl;
00074 return EXIT_FAILURE;
00075 }
00076 else {
00077 std::cout<<"[PASSED]"<<std::endl;
00078 }
00079
00080 vtkFloatingPointType bounds[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
00081
00082 vtkPolyData* polys = surface->GetVtkPolyData();
00083 polys->ComputeBounds();
00084 polys->GetBounds( bounds );
00085
00086 int i;
00087 if(expectIdentityTransform == false)
00088 {
00089 mitk::Geometry2D::Pointer geometry = mitk::Geometry2D::New();
00090 geometry->SetFloatBounds(bounds);
00091 geometry->SetIndexToWorldTransform(surface->GetGeometry()->GetIndexToWorldTransform());
00092 mitk::BoundingBox::BoundsArrayType bb = const_cast<mitk::BoundingBox*>(geometry->GetBoundingBox())->GetBounds();
00093 for(i=0;i<6;++i)
00094 bounds[i]=bb[i];
00095 }
00096
00097 std::cout << " Testing GetBoundingBox() ";
00098 if((result=testExpectedIndexBoundingBox(surface->GetGeometry(), bounds)) != EXIT_SUCCESS)
00099 {
00100 std::cout<<"[FAILED]"<<std::endl;
00101 return EXIT_FAILURE;
00102 }
00103 std::cout<<"[PASSED]"<<std::endl;
00104
00105 return EXIT_SUCCESS;
00106 }
00107
00108 int testGeometryDataToSurfaceFilter(mitk::Geometry2DDataToSurfaceFilter* geometryToSurfaceFilter, mitk::ScalarType expectedIndexBounds[6], mitk::ScalarType expectedAxisParallelBounds[6], bool expectIdentityTransform)
00109 {
00110 int result;
00111
00112 std::cout << "Testing SetRequestedRegionToLargestPossibleRegion(): ";
00113 geometryToSurfaceFilter->GetOutput()->SetRequestedRegionToLargestPossibleRegion();
00114 std::cout<<"[PASSED]"<<std::endl;
00115
00116 std::cout << "Testing UpdateOutputInformation(): ";
00117 geometryToSurfaceFilter->UpdateOutputInformation();
00118 std::cout<<"[PASSED]"<<std::endl;
00119
00120 std::cout << "Testing correctness of bounding-box after UpdateOutputInformation(): ";
00121 if((result=testExpectedIndexBoundingBox(geometryToSurfaceFilter->GetOutput()->GetGeometry(), expectedIndexBounds)) != EXIT_SUCCESS) {
00122 return result;
00123 }
00124
00125 std::cout << "Testing correctness of axis-parallel bounding-box after UpdateOutputInformation(): ";
00126 if((result=testExpectedAxisParallelBoundingBox(geometryToSurfaceFilter->GetOutput()->GetGeometry(), expectedAxisParallelBounds)) != EXIT_SUCCESS) {
00127 return result;
00128 }
00129
00130
00131 std::cout << "Testing Update(): ";
00132 geometryToSurfaceFilter->Update();
00133 std::cout<<"[PASSED]"<<std::endl;
00134
00135 std::cout << "Testing correctness of bounding-box after Update(): ";
00136 if((result=testExpectedIndexBoundingBox(geometryToSurfaceFilter->GetOutput()->GetGeometry(), expectedIndexBounds)) != EXIT_SUCCESS) {
00137 return result;
00138 }
00139
00140 std::cout << "Testing correctness of axis-parallel bounding-box after UpdateOutputInformation(): ";
00141 if((result=testExpectedAxisParallelBoundingBox(geometryToSurfaceFilter->GetOutput()->GetGeometry(), expectedAxisParallelBounds)) != EXIT_SUCCESS) {
00142 return result;
00143 }
00144
00145 std::cout << "Testing bounding-box consistency: "<<std::endl;
00146 if((result=testSurfaceBoundingBoxConsistency(geometryToSurfaceFilter->GetOutput(), expectIdentityTransform)) != EXIT_SUCCESS) {
00147 std::cout<<"[FAILED]"<<std::endl;
00148 return result;
00149 }
00150 else {
00151 std::cout<<"[PASSED]"<<std::endl;
00152 }
00153 return EXIT_SUCCESS;
00154 }
00155
00156 int mitkGeometryDataToSurfaceFilterTest(int , char* [])
00157 {
00158 int result;
00159
00160 std::cout << "Testing mitk::Geometry2DDataToSurfaceFilter: " << std::endl;
00161
00162 mitk::Geometry2DDataToSurfaceFilter::Pointer geometryToSurfaceFilter;
00163 std::cout << "Testing Geometry2DDataToSurfaceFilter::New(): ";
00164 geometryToSurfaceFilter = mitk::Geometry2DDataToSurfaceFilter::New();
00165 if (geometryToSurfaceFilter.IsNull()) {
00166 std::cout<<"[FAILED]"<<std::endl;
00167 return EXIT_FAILURE;
00168 }
00169 else {
00170 std::cout<<"[PASSED]"<<std::endl;
00171 }
00172
00173 mitk::Point3D origin;
00174 mitk::PlaneGeometry::Pointer plane = mitk::PlaneGeometry::New();
00175 plane->InitializeStandardPlane(50, 100);
00176 mitk::FillVector3D(origin, 1.0, 2.0, 3.0);
00177 plane->SetOrigin(origin);
00178
00179 mitk::Geometry2DData::Pointer geometryData = mitk::Geometry2DData::New();
00180 geometryData->SetGeometry2D(plane);
00181
00182 std::cout << "Testing SetInput(): ";
00183 geometryToSurfaceFilter->SetInput(geometryData);
00184 std::cout<<"[PASSED]"<<std::endl;
00185
00186 std::cout << "Testing GetInput(): ";
00187 if (geometryToSurfaceFilter->GetInput() != geometryData ) {
00188 std::cout<<"[FAILED]"<<std::endl;
00189 return EXIT_FAILURE;
00190 }
00191 else {
00192 std::cout<<"[PASSED]"<<std::endl;
00193 }
00194
00195
00196 std::cout << "Testing default of Geometry2DDataToSurfaceFilter::m_PlaceByGeometry (expected is false): ";
00197 if (geometryToSurfaceFilter->GetPlaceByGeometry() != false ) {
00198 std::cout<<"[FAILED]"<<std::endl;
00199 return EXIT_FAILURE;
00200 }
00201 else {
00202 std::cout<<"[PASSED]"<<std::endl;
00203 }
00204
00205
00206 mitk::ScalarType expectedBoundsFinal[6] = {1.0, 51.0, 2.0, 102.0, 3.0, 3.0};
00207 if((result=testGeometryDataToSurfaceFilter(geometryToSurfaceFilter, expectedBoundsFinal, expectedBoundsFinal, true)) != EXIT_SUCCESS) {
00208 return result;
00209 }
00210
00211 std::cout << "Testing Geometry2DDataToSurfaceFilter::SetPlaceByGeometry(true): ";
00212 geometryToSurfaceFilter->SetPlaceByGeometry(true);
00213 if (geometryToSurfaceFilter->GetPlaceByGeometry() != true ) {
00214 std::cout<<"[FAILED]"<<std::endl;
00215 return EXIT_FAILURE;
00216 }
00217 else {
00218 std::cout<<"[PASSED]"<<std::endl;
00219 }
00220
00221
00222 mitk::ScalarType expectedIndexBounds[6] = {0.0, 50.0, 0.0, 100.0, 0.0, 0.0};
00223 mitk::ScalarType expectedAxisParallelBounds[6] = {1.0, 51.0, 2.0, 102.0, 3.0, 3.0};
00224 if((result=testGeometryDataToSurfaceFilter(geometryToSurfaceFilter, expectedIndexBounds, expectedAxisParallelBounds, true)) != EXIT_SUCCESS) {
00225 return result;
00226 }
00227
00228
00229
00230
00231 mitk::BoundingBox::Pointer boundingBox = mitk::BoundingBox::New();
00232 mitk::Point3D bbMin, bbMax;
00233 mitk::FillVector3D( bbMin, 10.0, 10.0, -6.0 );
00234 mitk::FillVector3D( bbMax, 40.0, 90.0, 6.0 );
00235
00236 mitk::BoundingBox::PointsContainer::Pointer pointsContainer = mitk::BoundingBox::PointsContainer::New();
00237 pointsContainer->InsertElement( 0, bbMin );
00238 pointsContainer->InsertElement( 1, bbMax );
00239 boundingBox->SetPoints( pointsContainer );
00240 boundingBox->ComputeBoundingBox();
00241
00242
00243 geometryToSurfaceFilter->SetPlaceByGeometry( true );
00244 geometryToSurfaceFilter->SetBoundingBox( boundingBox );
00245 mitk::ScalarType expectedIndexBoundsWithBB[6] = {9.0, 39.0, 8.0, 88.0, 0.0, 0.0};
00246 mitk::ScalarType expectedAxisParallelBoundsWithBB[6] = {10.0, 40.0, 10.0, 90.0, 3.0, 3.0};
00247 if((result=testGeometryDataToSurfaceFilter(geometryToSurfaceFilter, expectedIndexBoundsWithBB, expectedAxisParallelBoundsWithBB, true)) != EXIT_SUCCESS) {
00248 return result;
00249 }
00250
00251
00252 std::cout<<"[TEST DONE]"<<std::endl;
00253 return EXIT_SUCCESS;
00254 }