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 <mitkPointSet.h>
00020 #include <vtkPolyData.h>
00021 #include <vtkPoints.h>
00022 #include <mitkPointLocator.h>
00023 #include <vtkPointLocator.h>
00024 #include <cstdlib>
00025
00026 vtkFloatingPointType GenerateRandomNumber( const vtkFloatingPointType& min = 0.0, const vtkFloatingPointType& max = 100.0 )
00027 {
00028 return ( ( ( vtkFloatingPointType ) ( std::rand( ) ) ) / ( ( vtkFloatingPointType ) ( RAND_MAX ) ) ) * ( max - min) + min;
00029 }
00030
00031 void GenerateRandomPoint( vtkFloatingPointType& x, vtkFloatingPointType& y, vtkFloatingPointType& z, const vtkFloatingPointType& min = 0.0, const vtkFloatingPointType& max = 100.0 )
00032 {
00033 x = GenerateRandomNumber(min, max);
00034 y = GenerateRandomNumber(min, max);
00035 z = GenerateRandomNumber(min, max);
00036 }
00037
00038 int mitkPointLocatorTest(int , char* [])
00039 {
00040 std::srand( 1 );
00041 unsigned int num_points = 10000;
00042
00043
00044 std::cout << "Creating random point set of 10000 points ";
00045 vtkPoints* points = vtkPoints::New();
00046 if ( points == NULL )
00047 {
00048 std::cout << "vtkPoints == NULL. [FAILED]" << std::endl;
00049 return EXIT_FAILURE;
00050 }
00051
00052 for (unsigned int i = 0; i < num_points ; ++i )
00053 {
00054 points->InsertPoint(i, GenerateRandomNumber(), GenerateRandomNumber(), GenerateRandomNumber());
00055 }
00056
00057 vtkPolyData* pointSet = vtkPolyData::New();
00058 pointSet->SetPoints( points );
00059
00060 points->Delete();
00061
00062 if ( (unsigned) pointSet->GetNumberOfPoints() != num_points )
00063 {
00064 std::cout << "Number of points in the vtkPointSet != "<< num_points <<". [FAILED]" << std::endl;
00065 return EXIT_FAILURE;
00066 }
00067 std::cout << "[PASSED]" << std::endl;
00068
00069
00070 std::cout << "Building vtkPointLocator ";
00071 vtkPointLocator* vtkPointLoc = vtkPointLocator::New();
00072 vtkPointLoc->SetDataSet( pointSet );
00073 vtkPointLoc->BuildLocator();
00074 std::cout << "[PASSED]" << std::endl;
00075
00076
00077 std::cout << "Building mitkPointLocator ";
00078 mitk::PointLocator::Pointer mitkPointLocator = mitk::PointLocator::New();
00079 mitk::PointLocator::Pointer mitkPointLocator2 = mitk::PointLocator::New();
00080 if ( mitkPointLocator.IsNull() )
00081 {
00082 std::cout << "[FAILED]" << std::endl;
00083 return EXIT_FAILURE;
00084 }
00085 else
00086 {
00087 std::cout << "[PASSED]" << std::endl;
00088 }
00089
00090 mitk::PointSet::Pointer mitkPointSet = mitk::PointSet::New();
00091 for ( int i=0; i<pointSet->GetNumberOfPoints();i++ )
00092 {
00093 mitk::Point3D pnt;
00094 pnt[0] = pointSet->GetPoint( i )[0];
00095 pnt[1] = pointSet->GetPoint( i )[1];
00096 pnt[2] = pointSet->GetPoint( i )[2];
00097 mitkPointSet->InsertPoint(i, pnt );
00098 }
00099
00100 std::cout << "Setting random point set ";
00101 mitkPointLocator->SetPoints( pointSet );
00102 mitkPointLocator2->SetPoints( mitkPointSet );
00103 std::cout << "[PASSED]" << std::endl;
00104
00105 std::cout << "Testing 1000 random points ";
00106
00107
00108
00109 vtkFloatingPointType p[3], x, y, z;
00110 mitk::PointSet::PointType pointType;
00111 for ( unsigned int i = 0 ; i < 1000 ; ++i )
00112 {
00113 GenerateRandomPoint( x, y, z );
00114 p[0] = x;
00115 p[1] = y;
00116 p[2] = z;
00117 pointType[0] = p[0];
00118 pointType[1] = p[1];
00119 pointType[2] = p[2];
00120 int closestPoint1 = vtkPointLoc->FindClosestPoint(p);
00121 int closestPoint2 = mitkPointLocator->FindClosestPoint(p);
00122 int closestPoint3 = mitkPointLocator->FindClosestPoint(x, y, z);
00123 int closestPoint4 = mitkPointLocator2->FindClosestPoint(p);
00124 int closestPoint5 = mitkPointLocator2->FindClosestPoint(pointType);
00125
00126 if ( closestPoint1 != closestPoint2 )
00127 {
00128 std::cout << "Id returned by vtkPointLocator doesn't match the one returned by mitk::PointLocator. [FAILED]" << std::endl;
00129 return EXIT_FAILURE;
00130 }
00131 if ( closestPoint2 != closestPoint3 )
00132 {
00133 std::cout << "There is a mismatch between passing coords as array and as single x/y/z coords. [FAILED]" << std::endl;
00134 return EXIT_FAILURE;
00135 }
00136 if ( closestPoint2 != closestPoint4 )
00137 {
00138 std::cout << "There is a mismatch between passing the points as mitkPointSet and vtkPointSet. [FAILED]" << std::endl;
00139 return EXIT_FAILURE;
00140 }
00141 if ( closestPoint4 != closestPoint5 )
00142 {
00143 std::cout << "There is a mismatch between passing coords as array and as single x/y/z coords when using MITK-Types. [FAILED]" << std::endl;
00144 return EXIT_FAILURE;
00145 }
00146
00147 }
00148
00149 vtkPointLoc->Delete();
00150 pointSet->Delete();
00151
00152 std::cout << "[PASSED]" << std::endl;
00153 std::cout<<"[TEST DONE]"<<std::endl;
00154 return EXIT_SUCCESS;
00155 }