int main(int argc, char **argv) { TCLAP::ValueArg<int> rotation1("","rotation1", "The rotation of mesh 1", false, 0, "int"); TCLAP::ValueArg<int> rotation2("","rotation2", "The rotation of mesh 2", false, 0, "int"); TCLAP::SwitchArg dual1("","dual1", "The rotation of mesh 1", false); TCLAP::SwitchArg dual2("","dual2", "The rotation of mesh 2", false); TCLAP::UnlabeledValueArg<std::string> solution1_filename("solution1", "File name of first solution", true, "", "string"); TCLAP::UnlabeledValueArg<std::string> solution2_filename("solution2", "File name of first solution", true, "", "string"); try { TCLAP::CmdLine cmd("Compare solutions", ' ', "1.0"); cmd.add( rotation1 ); cmd.add( rotation2 ); cmd.add( dual1 ); cmd.add( dual2 ); cmd.add( solution1_filename ); cmd.add( solution2_filename ); cmd.parse( argc, argv ); } catch (TCLAP::ArgException &e) // catch any exceptions { std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; return false; } viennagrid_numeric rotation_angle1 = 2*M_PI / 5 * rotation1.getValue(); viennagrid_numeric rotation_angle2 = 2*M_PI / 5 * rotation2.getValue(); viennagrid_mesh cmesh1; viennagrid_quantity_field solution1; viennagrid_mesh_io reader1; viennagrid_mesh_io_create(&reader1); viennagrid_error err1 = viennagrid_mesh_io_read_pvd(reader1, solution1_filename.getValue().c_str()); viennagrid_mesh_io_mesh_get(reader1, &cmesh1); viennagrid_mesh_io_quantity_field_get_by_index(reader1, 0, &solution1); viennagrid_mesh cmesh2; viennagrid_quantity_field solution2; viennagrid_mesh_io reader2; viennagrid_mesh_io_create(&reader2); viennagrid_error err2 = viennagrid_mesh_io_read_pvd(reader2, solution2_filename.getValue().c_str()); viennagrid_mesh_io_mesh_get(reader2, &cmesh2); viennagrid_mesh_io_quantity_field_get_by_index(reader2, 0, &solution2); viennagrid::mesh mesh1(cmesh1); viennagrid::mesh mesh2(cmesh2); // viennagrid_numeric matrix[4]; Transformation transformation = Transformation::make_rotation_2(- (rotation_angle1-rotation_angle2)); // Transformation rotation = if (dual1.getValue() != dual2.getValue()) { viennagrid_numeric angle = rotation_angle2 - 2*2*M_PI/5; viennagrid_numeric back_angle = rotation_angle2 - 3*2*M_PI/5; Transformation de_mirror = composition( Transformation::make_rotation_2(2*M_PI/5), Transformation::make_reflection_x(2) ); // composition( // Transformation::make_rotation_2(-back_angle), // composition( // Transformation::make_reflection_x(2), // Transformation::make_rotation_2(angle) // ) // ); transformation = composition( transformation, composition( Transformation::make_rotation_2(M_PI), Transformation::make_reflection_2(rotation_angle2 - M_PI/5) ) ); } // // if (dual.isSet()) // { // // } // else // { // matrix[0] = std::cos(rotation_angle); // matrix[1] = - std::sin(rotation_angle); // matrix[2] = std::sin(rotation_angle); // matrix[3] = std::cos(rotation_angle); // } viennagrid_mesh_affine_transform(mesh2.internal(), 2, &transformation.matrix.values[0], 0); viennagrid_mesh_io_write(reader1, "mesh1.vtu"); viennagrid_mesh_io_write(reader2, "mesh2.vtu"); int max_element_per_node = 10; int max_depth = 1000; NTreeNode * ntree1 = new NTreeNode(viennagrid::make_point(-1.1, -1.1), viennagrid::make_point( 1.1, 1.1)); { ElementRangeType cells(mesh1, 2); for (ElementRangeIterator cit = cells.begin(); cit != cells.end(); ++cit) ntree1->add(*cit, max_element_per_node, max_depth); } NTreeNode * ntree2 = new NTreeNode(viennagrid::make_point(-1.1, -1.1), viennagrid::make_point( 1.1, 1.1)); { ElementRangeType cells(mesh2, 2); for (ElementRangeIterator cit = cells.begin(); cit != cells.end(); ++cit) ntree2->add(*cit, max_element_per_node, max_depth); } std::cout << compare(mesh1, ntree1, viennagrid::quantity_field(solution1), mesh2, ntree2, viennagrid::quantity_field(solution2), 1e-6, 1e-6) << std::endl;; viennagrid_mesh_io_release(reader1); viennagrid_mesh_io_release(reader2); return 0; }
CloudMapper::Clouds CloudMapper::AlignAll(CloudMapper::Clouds &clouds, CloudMapper::LandmarksVector &landmarksVector, TransformationsPtr transformations) { TransformationsPtr allTransformations(new Transformations); if (transformations != nullptr) { allTransformations = transformations; } if (clouds.size() != landmarksVector.size()) { throw HPEException("CloudMapper::AlignAll - clouds.size() != landmarksVector.size()"); } std::vector<Eigen::Matrix4f> stepTransformations; pcl::PointCloud<CloudMapper::PointType>::Ptr sourceCloud = clouds[0]; for (int cloudIndex = 1; cloudIndex < clouds.size() - 1; cloudIndex++) { int sourceIndex = cloudIndex; int targetIndex = sourceIndex + 1; pcl::PointCloud<CloudMapper::PointType>::Ptr targetCloud = clouds[targetIndex]; auto totalTransform = GetTransformHavingLandmarks(sourceCloud, landmarksVector[sourceIndex], targetCloud, landmarksVector[targetIndex]); Eigen::Matrix3f rotationMatrix = totalTransform.block<3, 3>(0, 0); Eigen::Vector3f translationVector = totalTransform.block<3, 1>(0, 3); Eigen::Quaternionf quaternion(rotationMatrix); Eigen::Matrix3f rotation2(quaternion); pcl::transformPointCloud(*sourceCloud, *sourceCloud, totalTransform); pcl::PointCloud<CloudMapper::PointType>::Ptr newCloud(new pcl::PointCloud<CloudMapper::PointType>); *sourceCloud += *targetCloud; sourceCloud = Voxelize<CloudMapper::PointType>(sourceCloud, 0.006f); //ShowCloud<CloudMapper::PointType>(sourceCloud); if (IsNotNAN(totalTransform) == false) { int q = 42; } std::cout << cloudIndex << std::endl; stepTransformations.push_back(totalTransform); } ShowCloud<CloudMapper::PointType>(sourceCloud); CloudMapper::Clouds result; auto targetCloud = clouds[clouds.size() - 1]; for (int cloudIndex = 0; cloudIndex < clouds.size() - 1; cloudIndex++) { Eigen::Matrix4f accumulatedMatrix = stepTransformations[cloudIndex]; for (int matrixIndex = cloudIndex + 1; matrixIndex < stepTransformations.size(); matrixIndex++) { accumulatedMatrix = accumulatedMatrix * stepTransformations[matrixIndex]; } CloudMapper::Cloud::Ptr transformed(new CloudMapper::Cloud); pcl::transformPointCloud(*clouds[cloudIndex], *transformed, accumulatedMatrix); allTransformations->push_back(accumulatedMatrix); result.push_back(transformed); } result.push_back(targetCloud); return result; }
void HomogeneousMatrixTest::testRPYConversions() { double xExpected, yExpected, zExpected, rollExpected, pitchExpected, yawExpected; double xActual, yActual, zActual, rollActual, pitchActual, yawActual; IHomogeneousMatrix44::IHomogeneousMatrix44Ptr transform1(new HomogeneousMatrix44()); xExpected = 1.0; yExpected = 2.0; zExpected = 3.0; rollExpected = 0.5*M_PI; pitchExpected = 0.0; yawExpected = 0.0; HomogeneousMatrix44::xyzRollPitchYawToMatrix(xExpected, yExpected, zExpected, rollExpected, pitchExpected, yawExpected, transform1); std::cout << "---> transform1 " << std::endl <<*transform1; HomogeneousMatrix44::matrixToXyzRollPitchYaw(transform1, xActual, yActual, zActual, rollActual, pitchActual, yawActual); CPPUNIT_ASSERT_DOUBLES_EQUAL(xExpected, xActual, maxTolerance); CPPUNIT_ASSERT_DOUBLES_EQUAL(yExpected, yActual, maxTolerance); CPPUNIT_ASSERT_DOUBLES_EQUAL(zExpected, zActual, maxTolerance); CPPUNIT_ASSERT_DOUBLES_EQUAL(rollExpected, rollActual, maxTolerance); CPPUNIT_ASSERT_DOUBLES_EQUAL(pitchExpected, pitchActual, maxTolerance); CPPUNIT_ASSERT_DOUBLES_EQUAL(yawExpected, yawActual, maxTolerance); xExpected = 1.0; yExpected = 2.0; zExpected = 3.0; rollExpected = 0.0; pitchExpected = 0.0; yawExpected = 0.5 * M_PI; Eigen::AngleAxis<double> rotation2(yawExpected, Eigen::Vector3d(0,0,1)); Transform3d transformation2; transformation2 = Eigen::Affine3d::Identity(); transformation2.translate(Eigen::Vector3d(xExpected,yExpected,zExpected)); transformation2.rotate(rotation2); IHomogeneousMatrix44::IHomogeneousMatrix44Ptr transform2(new HomogeneousMatrix44(&transformation2)); HomogeneousMatrix44::matrixToXyzRollPitchYaw(transform2, xActual, yActual, zActual, rollActual, pitchActual, yawActual); CPPUNIT_ASSERT_DOUBLES_EQUAL(xExpected, xActual, maxTolerance); CPPUNIT_ASSERT_DOUBLES_EQUAL(yExpected, yActual, maxTolerance); CPPUNIT_ASSERT_DOUBLES_EQUAL(zExpected, zActual, maxTolerance); CPPUNIT_ASSERT_DOUBLES_EQUAL(rollExpected, rollActual, maxTolerance); CPPUNIT_ASSERT_DOUBLES_EQUAL(pitchExpected, pitchActual, maxTolerance); CPPUNIT_ASSERT_DOUBLES_EQUAL(yawExpected, yawActual, maxTolerance); xExpected = 1.0; yExpected = 2.0; zExpected = 3.0; rollExpected = 0.0; pitchExpected = 0.5 * M_PI; yawExpected = 0; Eigen::AngleAxis<double> rotation3(pitchExpected, Eigen::Vector3d(0,1,0)); Transform3d transformation3; transformation3 = Eigen::Affine3d::Identity(); transformation3.translate(Eigen::Vector3d(xExpected,yExpected,zExpected)); transformation3.rotate(rotation3); IHomogeneousMatrix44::IHomogeneousMatrix44Ptr transform3(new HomogeneousMatrix44(&transformation3)); HomogeneousMatrix44::matrixToXyzRollPitchYaw(transform3, xActual, yActual, zActual, rollActual, pitchActual, yawActual); CPPUNIT_ASSERT_DOUBLES_EQUAL(xExpected, xActual, maxTolerance); CPPUNIT_ASSERT_DOUBLES_EQUAL(yExpected, yActual, maxTolerance); CPPUNIT_ASSERT_DOUBLES_EQUAL(zExpected, zActual, maxTolerance); CPPUNIT_ASSERT_DOUBLES_EQUAL(rollExpected, rollActual, maxTolerance); CPPUNIT_ASSERT_DOUBLES_EQUAL(pitchExpected, pitchActual, maxTolerance); CPPUNIT_ASSERT_DOUBLES_EQUAL(yawExpected, yawActual, maxTolerance); xExpected = 1.0; yExpected = 2.0; zExpected = 3.0; rollExpected = 0.5 * M_PI; pitchExpected = 0.0; yawExpected = 0; Eigen::AngleAxis<double> rotation4(rollExpected, Eigen::Vector3d(1,0,0)); Transform3d transformation4; transformation4 = Eigen::Affine3d::Identity(); transformation4.translate(Eigen::Vector3d(xExpected,yExpected,zExpected)); transformation4.rotate(rotation4); IHomogeneousMatrix44::IHomogeneousMatrix44Ptr transform4(new HomogeneousMatrix44(&transformation4)); HomogeneousMatrix44::matrixToXyzRollPitchYaw(transform4, xActual, yActual, zActual, rollActual, pitchActual, yawActual); std::cout << "---> transform4 " << std::endl <<*transform4; CPPUNIT_ASSERT_DOUBLES_EQUAL(xExpected, xActual, maxTolerance); CPPUNIT_ASSERT_DOUBLES_EQUAL(yExpected, yActual, maxTolerance); CPPUNIT_ASSERT_DOUBLES_EQUAL(zExpected, zActual, maxTolerance); CPPUNIT_ASSERT_DOUBLES_EQUAL(rollExpected, rollActual, maxTolerance); CPPUNIT_ASSERT_DOUBLES_EQUAL(pitchExpected, pitchActual, maxTolerance); CPPUNIT_ASSERT_DOUBLES_EQUAL(yawExpected, yawActual, maxTolerance); /* CHecke if Eigen generated and xyzRPY generated _matices_ are similar */ const double* matrixData1 = transform1->getRawData(); const double* matrixData4 = transform4->getRawData(); for (unsigned int i = 0; i < 16; ++i) { CPPUNIT_ASSERT_DOUBLES_EQUAL(matrixData1[i], matrixData4[i], maxTolerance); } }
int mitkPlaneGeometryTest(int /*argc*/, char* /*argv*/[]) { int result; /* // the following can be used to reproduce a bug in ITK matrix inversion // which was found while investigating bug #1210. result = TestCase1210(); if(result!=EXIT_SUCCESS) return result; */ mitk::PlaneGeometry::Pointer planegeometry = mitk::PlaneGeometry::New(); mitk::Point3D origin; mitk::Vector3D right, bottom, normal; mitk::ScalarType width, height; mitk::ScalarType widthInMM, heightInMM, thicknessInMM; width = 100; widthInMM = width; height = 200; heightInMM = height; thicknessInMM = 1.0; mitk::FillVector3D(origin, 4.5, 7.3, 11.2); mitk::FillVector3D(right, widthInMM, 0, 0); mitk::FillVector3D(bottom, 0, heightInMM, 0); mitk::FillVector3D(normal, 0, 0, thicknessInMM); std::cout << "Testing InitializeStandardPlane(rightVector, downVector, spacing = NULL): "<<std::endl; planegeometry->InitializeStandardPlane(right.Get_vnl_vector(), bottom.Get_vnl_vector()); std::cout << "Testing width, height and thickness (in units): "; if((mitk::Equal(planegeometry->GetExtent(0),width)==false) || (mitk::Equal(planegeometry->GetExtent(1),height)==false) || (mitk::Equal(planegeometry->GetExtent(2),1)==false) ) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing width, height and thickness (in mm): "; if((mitk::Equal(planegeometry->GetExtentInMM(0),widthInMM)==false) || (mitk::Equal(planegeometry->GetExtentInMM(1),heightInMM)==false) || (mitk::Equal(planegeometry->GetExtentInMM(2),thicknessInMM)==false) ) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing GetAxisVector(): "; if((mitk::Equal(planegeometry->GetAxisVector(0), right)==false) || (mitk::Equal(planegeometry->GetAxisVector(1), bottom)==false) || (mitk::Equal(planegeometry->GetAxisVector(2), normal)==false)) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing InitializeStandardPlane(rightVector, downVector, spacing = {1.0, 1.0, 1.5}): "<<std::endl; mitk::Vector3D spacing; thicknessInMM = 1.5; normal.Normalize(); normal *= thicknessInMM; mitk::FillVector3D(spacing, 1.0, 1.0, thicknessInMM); planegeometry->InitializeStandardPlane(right.Get_vnl_vector(), bottom.Get_vnl_vector(), &spacing); std::cout << "Testing width, height and thickness (in units): "; if((mitk::Equal(planegeometry->GetExtent(0),width)==false) || (mitk::Equal(planegeometry->GetExtent(1),height)==false) || (mitk::Equal(planegeometry->GetExtent(2),1)==false) ) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing width, height and thickness (in mm): "; if((mitk::Equal(planegeometry->GetExtentInMM(0),widthInMM)==false) || (mitk::Equal(planegeometry->GetExtentInMM(1),heightInMM)==false) || (mitk::Equal(planegeometry->GetExtentInMM(2),thicknessInMM)==false) ) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing GetAxisVector(): "; if((mitk::Equal(planegeometry->GetAxisVector(0), right)==false) || (mitk::Equal(planegeometry->GetAxisVector(1), bottom)==false) || (mitk::Equal(planegeometry->GetAxisVector(2), normal)==false)) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing SetExtentInMM(2, ...), querying by GetExtentInMM(2): "; thicknessInMM = 3.5; normal.Normalize(); normal *= thicknessInMM; planegeometry->SetExtentInMM(2, thicknessInMM); if(mitk::Equal(planegeometry->GetExtentInMM(2),thicknessInMM)==false) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing SetExtentInMM(2, ...), querying by GetAxisVector(2) and comparing to normal: "; if(mitk::Equal(planegeometry->GetAxisVector(2), normal)==false) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing SetOrigin: "; planegeometry->SetOrigin(origin); if(mitk::Equal(planegeometry->GetOrigin(), origin)==false) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing GetAxisVector() after SetOrigin: "; if((mitk::Equal(planegeometry->GetAxisVector(0), right)==false) || (mitk::Equal(planegeometry->GetAxisVector(1), bottom)==false) || (mitk::Equal(planegeometry->GetAxisVector(2), normal)==false)) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; result = mappingTests2D(planegeometry, width, height, widthInMM, heightInMM, origin, right, bottom); if(result!=EXIT_SUCCESS) return result; std::cout << "Changing the IndexToWorldTransform to a rotated version by SetIndexToWorldTransform() (keep origin): "<<std::endl; mitk::AffineTransform3D::Pointer transform = mitk::AffineTransform3D::New(); mitk::AffineTransform3D::MatrixType::InternalMatrixType vnlmatrix; vnlmatrix = planegeometry->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix(); mitk::VnlVector axis(3); mitk::FillVector3D(axis, 1.0, 1.0, 1.0); axis.normalize(); vnl_quaternion<mitk::ScalarType> rotation(axis, 0.223); vnlmatrix = rotation.rotation_matrix_transpose()*vnlmatrix; mitk::Matrix3D matrix; matrix = vnlmatrix; transform->SetMatrix(matrix); transform->SetOffset(planegeometry->GetIndexToWorldTransform()->GetOffset()); right.Set_vnl_vector( rotation.rotation_matrix_transpose()*right.Get_vnl_vector() ); bottom.Set_vnl_vector(rotation.rotation_matrix_transpose()*bottom.Get_vnl_vector()); normal.Set_vnl_vector(rotation.rotation_matrix_transpose()*normal.Get_vnl_vector()); planegeometry->SetIndexToWorldTransform(transform); //The origin changed,because m_Origin=m_IndexToWorldTransform->GetOffset()+GetAxisVector(2)*0.5 //and the AxisVector changes due to the rotation. In other words: the rotation was done around //the corner of the box, not around the planes origin. Now change it to a rotation around //the origin, simply by re-setting the origin to the original one: planegeometry->SetOrigin(origin); mitk::Point3D cornerpoint0 = planegeometry->GetCornerPoint(0); std::cout << "Testing whether SetIndexToWorldTransform kept origin: "; if(mitk::Equal(planegeometry->GetOrigin(), origin)==false) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } MITK_TEST_OUTPUT( << "Testing consistancy of index and world coordinates. "); mitk::Point2D point; point[0] = 4; point[1] = 3; mitk::Point2D dummy; planegeometry->WorldToIndex(point, dummy); planegeometry->IndexToWorld(dummy, dummy); MITK_TEST_CONDITION_REQUIRED(dummy == point, ""); std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing width, height and thickness (in mm) of rotated version: "; if((mitk::Equal(planegeometry->GetExtentInMM(0),widthInMM)==false) || (mitk::Equal(planegeometry->GetExtentInMM(1),heightInMM)==false) || (mitk::Equal(planegeometry->GetExtentInMM(2),thicknessInMM)==false) ) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing GetAxisVector() of rotated version: "; if((mitk::Equal(planegeometry->GetAxisVector(0), right)==false) || (mitk::Equal(planegeometry->GetAxisVector(1), bottom)==false) || (mitk::Equal(planegeometry->GetAxisVector(2), normal)==false)) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing GetAxisVector(direction).GetNorm() != planegeometry->GetExtentInMM(direction) of rotated version: "; if((mitk::Equal(planegeometry->GetAxisVector(0).GetNorm(),planegeometry->GetExtentInMM(0))==false) || (mitk::Equal(planegeometry->GetAxisVector(1).GetNorm(),planegeometry->GetExtentInMM(1))==false) || (mitk::Equal(planegeometry->GetAxisVector(2).GetNorm(),planegeometry->GetExtentInMM(2))==false) ) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; result = mappingTests2D(planegeometry, width, height, widthInMM, heightInMM, origin, right, bottom); if(result!=EXIT_SUCCESS) return result; std::cout << "Testing SetSizeInUnits() of rotated version: "<<std::endl; width *= 2; height *= 3; planegeometry->SetSizeInUnits(width, height); std::cout << "Testing width, height and thickness (in units): "; if((mitk::Equal(planegeometry->GetExtent(0),width)==false) || (mitk::Equal(planegeometry->GetExtent(1),height)==false) || (mitk::Equal(planegeometry->GetExtent(2),1)==false) ) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing width, height and thickness (in mm) of version with changed size in units: "; if(!mitk::Equal(planegeometry->GetExtentInMM(0), widthInMM) || !mitk::Equal(planegeometry->GetExtentInMM(1), heightInMM) || !mitk::Equal(planegeometry->GetExtentInMM(2), thicknessInMM)) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing GetAxisVector() of version with changed size in units: "; if((mitk::Equal(planegeometry->GetAxisVector(0), right)==false) || (mitk::Equal(planegeometry->GetAxisVector(1), bottom)==false) || (mitk::Equal(planegeometry->GetAxisVector(2), normal)==false)) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing GetAxisVector(direction).GetNorm() != planegeometry->GetExtentInMM(direction) of rotated version: "; if((mitk::Equal(planegeometry->GetAxisVector(0).GetNorm(),planegeometry->GetExtentInMM(0))==false) || (mitk::Equal(planegeometry->GetAxisVector(1).GetNorm(),planegeometry->GetExtentInMM(1))==false) || (mitk::Equal(planegeometry->GetAxisVector(2).GetNorm(),planegeometry->GetExtentInMM(2))==false) ) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; result = mappingTests2D(planegeometry, width, height, widthInMM, heightInMM, origin, right, bottom); if(result!=EXIT_SUCCESS) return result; std::cout << "Testing Clone(): "; mitk::PlaneGeometry::Pointer clonedplanegeometry = dynamic_cast<mitk::PlaneGeometry*>(planegeometry->Clone().GetPointer()); if((clonedplanegeometry.IsNull()) || (clonedplanegeometry->GetReferenceCount()!=1)) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing origin of cloned version: "; if(mitk::Equal(clonedplanegeometry->GetOrigin(), origin)==false) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing width, height and thickness (in units) of cloned version: "; if((mitk::Equal(clonedplanegeometry->GetExtent(0),width)==false) || (mitk::Equal(clonedplanegeometry->GetExtent(1),height)==false) || (mitk::Equal(clonedplanegeometry->GetExtent(2),1)==false) ) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing width, height and thickness (in mm) of cloned version: "; if(!mitk::Equal(clonedplanegeometry->GetExtentInMM(0), widthInMM) || !mitk::Equal(clonedplanegeometry->GetExtentInMM(1), heightInMM) || !mitk::Equal(clonedplanegeometry->GetExtentInMM(2), thicknessInMM)) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing GetAxisVector() of cloned version: "; if((mitk::Equal(clonedplanegeometry->GetAxisVector(0), right)==false) || (mitk::Equal(clonedplanegeometry->GetAxisVector(1), bottom)==false) || (mitk::Equal(clonedplanegeometry->GetAxisVector(2), normal)==false)) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; result = mappingTests2D(clonedplanegeometry, width, height, widthInMM, heightInMM, origin, right, bottom); if(result!=EXIT_SUCCESS) return result; // Clone, move, rotate and test for 'IsParallel' and 'IsOnPlane' std::cout << "Testing Clone(): "; mitk::PlaneGeometry::Pointer clonedplanegeometry2 = dynamic_cast<mitk::PlaneGeometry*>(planegeometry->Clone().GetPointer()); if((clonedplanegeometry2.IsNull()) || (clonedplanegeometry2->GetReferenceCount()!=1)) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout << "Testing if cloned and original version are at the same place: "; if(mitk::Equal(clonedplanegeometry2->IsOnPlane(planegeometry), true) ==false) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing if the origin is on the plane: "; if(mitk::Equal(clonedplanegeometry2->IsOnPlane(origin), true)==false) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; mitk::VnlVector newaxis(3); mitk::FillVector3D(newaxis, 1.0, 1.0, 1.0); newaxis.normalize(); vnl_quaternion<mitk::ScalarType> rotation2(newaxis, 0.0); mitk::Vector3D clonednormal = clonedplanegeometry2->GetNormal(); mitk::Point3D clonedorigin = clonedplanegeometry2->GetOrigin(); mitk::RotationOperation* planerot = new mitk::RotationOperation( mitk::OpROTATE, origin, clonedplanegeometry2->GetAxisVector( 0 ), 180.0 ); clonedplanegeometry2->ExecuteOperation( planerot ); std::cout << "Testing whether the flipped plane is still the original plane: "; if( mitk::Equal( clonedplanegeometry2->IsOnPlane(planegeometry), true )==false ) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; clonedorigin += clonednormal; clonedplanegeometry2->SetOrigin( clonedorigin ); std::cout << "Testing if the translated (cloned, flipped) plane is parallel to its origin plane: "; if( mitk::Equal( clonedplanegeometry2->IsParallel(planegeometry), true )==false ) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; delete planerot; planerot = new mitk::RotationOperation( mitk::OpROTATE, origin, clonedplanegeometry2->GetAxisVector( 0 ), 0.5 ); clonedplanegeometry2->ExecuteOperation( planerot ); std::cout << "Testing if a non-paralell plane gets recognized as not paralell [rotation +0.5 degree] : "; if( mitk::Equal( clonedplanegeometry2->IsParallel(planegeometry), false )==false ) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; delete planerot; planerot = new mitk::RotationOperation( mitk::OpROTATE, origin, clonedplanegeometry2->GetAxisVector( 0 ), -1.0 ); clonedplanegeometry2->ExecuteOperation( planerot ); std::cout << "Testing if a non-paralell plane gets recognized as not paralell [rotation -0.5 degree] : "; if( mitk::Equal( clonedplanegeometry2->IsParallel(planegeometry), false )==false ) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; delete planerot; planerot = new mitk::RotationOperation( mitk::OpROTATE, origin, clonedplanegeometry2->GetAxisVector( 0 ), 360.5 ); clonedplanegeometry2->ExecuteOperation( planerot ); std::cout << "Testing if a non-paralell plane gets recognized as not paralell [rotation 360 degree] : "; if( mitk::Equal( clonedplanegeometry2->IsParallel(planegeometry), true )==false ) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing InitializeStandardPlane(clonedplanegeometry, planeorientation = Transversal, zPosition = 0, frontside=true): " <<std::endl; planegeometry->InitializeStandardPlane(clonedplanegeometry); std::cout << "Testing origin of transversally initialized version: "; if(mitk::Equal(planegeometry->GetOrigin(), origin)==false) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing GetCornerPoint(0) of transversally initialized version: "; if(mitk::Equal(planegeometry->GetCornerPoint(0), cornerpoint0)==false) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing width, height and thickness (in units) of transversally initialized version (should be same as in mm due to unit spacing, except for thickness, which is always 1): "; if(!mitk::Equal(planegeometry->GetExtent(0), width) || !mitk::Equal(planegeometry->GetExtent(1), height) || !mitk::Equal(planegeometry->GetExtent(2), 1)) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing width, height and thickness (in mm) of transversally initialized version: "; if(!mitk::Equal(planegeometry->GetExtentInMM(0), widthInMM) || !mitk::Equal(planegeometry->GetExtentInMM(1), heightInMM) || !mitk::Equal(planegeometry->GetExtentInMM(2), thicknessInMM)) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing GetAxisVector() of transversally initialized version: "; if((mitk::Equal(planegeometry->GetAxisVector(0), right)==false) || (mitk::Equal(planegeometry->GetAxisVector(1), bottom)==false) || (mitk::Equal(planegeometry->GetAxisVector(2), normal)==false)) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; result = mappingTests2D(planegeometry, width, height, widthInMM, heightInMM, origin, right, bottom); if(result!=EXIT_SUCCESS) return result; mitk::Vector3D newright, newbottom, newnormal; mitk::ScalarType newthicknessInMM; std::cout << "Testing InitializeStandardPlane(clonedplanegeometry, planeorientation = Frontal, zPosition = 0, frontside=true): " <<std::endl; planegeometry->InitializeStandardPlane(clonedplanegeometry, mitk::PlaneGeometry::Frontal); newright = right; newbottom = normal; newbottom.Normalize(); newbottom *= thicknessInMM; newthicknessInMM = heightInMM/height*1.0/*extent in normal direction is 1*/; newnormal = -bottom; newnormal.Normalize(); newnormal *= newthicknessInMM; std::cout << "Testing GetCornerPoint(0) of frontally initialized version: "; if(mitk::Equal(planegeometry->GetCornerPoint(0), cornerpoint0)==false) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; //ok, corner was fine, so we can dare to believe the origin is ok. origin = planegeometry->GetOrigin(); std::cout << "Testing width, height and thickness (in units) of frontally initialized version: "; if(!mitk::Equal(planegeometry->GetExtent(0), width) || !mitk::Equal(planegeometry->GetExtent(1), 1) || !mitk::Equal(planegeometry->GetExtent(2), 1)) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing width, height and thickness (in mm) of frontally initialized version: "; if(!mitk::Equal(planegeometry->GetExtentInMM(0), widthInMM) || !mitk::Equal(planegeometry->GetExtentInMM(1), thicknessInMM) || !mitk::Equal(planegeometry->GetExtentInMM(2), newthicknessInMM)) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing GetAxisVector() of frontally initialized version: "; if((mitk::Equal(planegeometry->GetAxisVector(0), newright)==false) || (mitk::Equal(planegeometry->GetAxisVector(1), newbottom)==false) || (mitk::Equal(planegeometry->GetAxisVector(2), newnormal)==false)) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; result = mappingTests2D(planegeometry, width, 1, widthInMM, thicknessInMM, origin, newright, newbottom); if(result!=EXIT_SUCCESS) return result; std::cout << "Changing plane to in-plane unit spacing using SetSizeInUnits: " <<std::endl; planegeometry->SetSizeInUnits(planegeometry->GetExtentInMM(0), planegeometry->GetExtentInMM(1)); std::cout << "Testing origin of unit spaced, frontally initialized version: "; if(mitk::Equal(planegeometry->GetOrigin(), origin)==false) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing width, height and thickness (in units) of unit spaced, frontally initialized version: "; if(!mitk::Equal(planegeometry->GetExtent(0), widthInMM) || !mitk::Equal(planegeometry->GetExtent(1), thicknessInMM) || !mitk::Equal(planegeometry->GetExtent(2), 1)) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing width, height and thickness (in mm) of unit spaced, frontally initialized version: "; if(!mitk::Equal(planegeometry->GetExtentInMM(0), widthInMM) || !mitk::Equal(planegeometry->GetExtentInMM(1), thicknessInMM) || !mitk::Equal(planegeometry->GetExtentInMM(2), newthicknessInMM)) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing GetAxisVector() of unit spaced, frontally initialized version: "; if((mitk::Equal(planegeometry->GetAxisVector(0), newright)==false) || (mitk::Equal(planegeometry->GetAxisVector(1), newbottom)==false) || (mitk::Equal(planegeometry->GetAxisVector(2), newnormal)==false)) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; result = mappingTests2D(planegeometry, widthInMM, thicknessInMM, widthInMM, thicknessInMM, origin, newright, newbottom); if(result!=EXIT_SUCCESS) return result; std::cout << "Changing plane to unit spacing also in normal direction using SetExtentInMM(2, 1.0): " <<std::endl; planegeometry->SetExtentInMM(2, 1.0); newnormal.Normalize(); std::cout << "Testing origin of unit spaced, frontally initialized version: "; if(mitk::Equal(planegeometry->GetOrigin(), origin)==false) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing width, height and thickness (in units) of unit spaced, frontally initialized version: "; if(!mitk::Equal(planegeometry->GetExtent(0), widthInMM) || !mitk::Equal(planegeometry->GetExtent(1), thicknessInMM) || !mitk::Equal(planegeometry->GetExtent(2), 1)) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing width, height and thickness (in mm) of unit spaced, frontally initialized version: "; if(!mitk::Equal(planegeometry->GetExtentInMM(0), widthInMM) || !mitk::Equal(planegeometry->GetExtentInMM(1), thicknessInMM) || !mitk::Equal(planegeometry->GetExtentInMM(2), 1.0)) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing GetAxisVector() of unit spaced, frontally initialized version: "; if((mitk::Equal(planegeometry->GetAxisVector(0), newright)==false) || (mitk::Equal(planegeometry->GetAxisVector(1), newbottom)==false) || (mitk::Equal(planegeometry->GetAxisVector(2), newnormal)==false)) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; result = mappingTests2D(planegeometry, widthInMM, thicknessInMM, widthInMM, thicknessInMM, origin, newright, newbottom); if(result!=EXIT_SUCCESS) return result; std::cout << "Testing InitializeStandardPlane(clonedplanegeometry, planeorientation = Sagittal, zPosition = 0, frontside=true): " <<std::endl; planegeometry->InitializeStandardPlane(clonedplanegeometry, mitk::PlaneGeometry::Sagittal); newright = bottom; newthicknessInMM = widthInMM/width*1.0/*extent in normal direction is 1*/; newnormal = right; newnormal.Normalize(); newnormal *= newthicknessInMM; std::cout << "Testing GetCornerPoint(0) of sagitally initialized version: "; if(mitk::Equal(planegeometry->GetCornerPoint(0), cornerpoint0)==false) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; //ok, corner was fine, so we can dare to believe the origin is ok. origin = planegeometry->GetOrigin(); std::cout << "Testing width, height and thickness (in units) of sagitally initialized version: "; if(!mitk::Equal(planegeometry->GetExtent(0), height) || !mitk::Equal(planegeometry->GetExtent(1), 1) || !mitk::Equal(planegeometry->GetExtent(2), 1)) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing width, height and thickness (in mm) of sagitally initialized version: "; if(!mitk::Equal(planegeometry->GetExtentInMM(0), heightInMM) || !mitk::Equal(planegeometry->GetExtentInMM(1), thicknessInMM) || !mitk::Equal(planegeometry->GetExtentInMM(2), newthicknessInMM)) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing GetAxisVector() of sagitally initialized version: "; if((mitk::Equal(planegeometry->GetAxisVector(0), newright)==false) || (mitk::Equal(planegeometry->GetAxisVector(1), newbottom)==false) || (mitk::Equal(planegeometry->GetAxisVector(2), newnormal)==false)) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; result = mappingTests2D(planegeometry, height, 1, heightInMM, thicknessInMM, origin, newright, newbottom); if(result!=EXIT_SUCCESS) return result; //set origin back to the one of the transversal slice: origin = clonedplanegeometry->GetOrigin(); std::cout << "Testing backside initialization: InitializeStandardPlane(clonedplanegeometry, planeorientation = Transversal, zPosition = 0, frontside=false, rotated=true): " <<std::endl; planegeometry->InitializeStandardPlane(clonedplanegeometry, mitk::PlaneGeometry::Transversal, 0, false, true); mitk::Point3D backsideorigin; backsideorigin=origin+clonedplanegeometry->GetAxisVector(1);//+clonedplanegeometry->GetAxisVector(2); std::cout << "Testing origin of backsidedly, transversally initialized version: "; if(mitk::Equal(planegeometry->GetOrigin(), backsideorigin)==false) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing GetCornerPoint(0) of sagitally initialized version: "; mitk::Point3D backsidecornerpoint0; backsidecornerpoint0 = cornerpoint0+clonedplanegeometry->GetAxisVector(1);//+clonedplanegeometry->GetAxisVector(2); if(mitk::Equal(planegeometry->GetCornerPoint(0), backsidecornerpoint0)==false) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing width, height and thickness (in units) of backsidedly, transversally initialized version (should be same as in mm due to unit spacing, except for thickness, which is always 1): "; if(!mitk::Equal(planegeometry->GetExtent(0), width) || !mitk::Equal(planegeometry->GetExtent(1), height) || !mitk::Equal(planegeometry->GetExtent(2), 1)) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing width, height and thickness (in mm) of backsidedly, transversally initialized version: "; if(!mitk::Equal(planegeometry->GetExtentInMM(0), widthInMM) || !mitk::Equal(planegeometry->GetExtentInMM(1), heightInMM) || !mitk::Equal(planegeometry->GetExtentInMM(2), thicknessInMM)) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; std::cout << "Testing GetAxisVector() of backsidedly, transversally initialized version: "; if((mitk::Equal(planegeometry->GetAxisVector(0), right)==false) || (mitk::Equal(planegeometry->GetAxisVector(1), -bottom)==false) || (mitk::Equal(planegeometry->GetAxisVector(2), -normal)==false)) { std::cout<<"[FAILED]"<<std::endl; return EXIT_FAILURE; } std::cout<<"[PASSED]"<<std::endl; result = mappingTests2D(planegeometry, width, height, widthInMM, heightInMM, backsideorigin, right, -bottom); if(result!=EXIT_SUCCESS) return result; // test method mitk::PlaneGeometry::ProjectPointOntoPlane() // (see also bug #3409) result = TestProjectPointOntoPlane(); if(result!=EXIT_SUCCESS) return result; // testing mitk::PlaneGeometry::IntersectionPoint() std::cout << std::endl; std::cout << "Testing IntersectionPoint using given plane and given line: "; result = TestIntersectionPoint(); if (result != EXIT_SUCCESS) { std::cout << "[FAILED]" << std::endl; return result; } std::cout<<"[PASSED]"<<std::endl<<std::endl; std::cout<<"[TEST DONE]"<<std::endl; return EXIT_SUCCESS; }