int NormalEstimation::compute() { //pointer to selected cloud ccPointCloud* cloud = getSelectedEntityAsCCPointCloud(); if (!cloud) return -1; //if we have normals delete them! if (cloud->hasNormals()) cloud->unallocateNorms(); if (cloud->hasNormals()) cloud->unallocateNorms(); //get xyz in sensor_msgs format cc2smReader converter; converter.setInputCloud(cloud); sensor_msgs::PointCloud2 sm_cloud = converter.getXYZ(); //get as pcl point cloud pcl::PointCloud<pcl::PointXYZ>::Ptr pcl_cloud (new pcl::PointCloud<pcl::PointXYZ>); pcl::fromROSMsg(sm_cloud, *pcl_cloud); //create storage for normals pcl::PointCloud<pcl::PointNormal>::Ptr normals (new pcl::PointCloud<pcl::PointNormal>); //now compute int result = compute_normals<pcl::PointXYZ, pcl::PointNormal>(pcl_cloud, m_useKnn ? m_knn_radius: m_radius, m_useKnn, normals); sensor_msgs::PointCloud2::Ptr sm_normals (new sensor_msgs::PointCloud2); pcl::toROSMsg(*normals, *sm_normals); sm2ccConverter converter2(sm_normals); converter2.addNormals(cloud); converter2.addScalarField(cloud, "curvature", m_overwrite_curvature); emit entityHasChanged(cloud); return 1; }
static jboolean NativeConverter_contains(JNIEnv* env, jclass, jstring name1, jstring name2) { ScopedUtfChars name1Chars(env, name1); if (name1Chars.c_str() == NULL) { return JNI_FALSE; } ScopedUtfChars name2Chars(env, name2); if (name2Chars.c_str() == NULL) { return JNI_FALSE; } UErrorCode errorCode = U_ZERO_ERROR; icu::LocalUConverterPointer converter1(ucnv_open(name1Chars.c_str(), &errorCode)); icu::UnicodeSet set1; ucnv_getUnicodeSet(&*converter1, set1.toUSet(), UCNV_ROUNDTRIP_SET, &errorCode); icu::LocalUConverterPointer converter2(ucnv_open(name2Chars.c_str(), &errorCode)); icu::UnicodeSet set2; ucnv_getUnicodeSet(&*converter2, set2.toUSet(), UCNV_ROUNDTRIP_SET, &errorCode); return U_SUCCESS(errorCode) && set1.containsAll(set2); }
/** * This tests the HDF5 to VTK converter using a 3D example * taken from a bidomain simulation. */ void TestBidomainVtkConversion3D() throw(Exception) { #ifdef CHASTE_VTK // Requires "sudo aptitude install libvtk5-dev" or similar std::string working_directory = "TestHdf5ToVtkConverter_bidomain"; std::string working_directory2 = "TestHdf5ToVtkConverter_bidomain2"; /* * Firstly, copy the .h5 file to CHASTE_TEST_OUTPUT/TestHdf5ToVtkConverter_bidomain, * as that is where the reader reads from. */ CopyToTestOutputDirectory("pde/test/data/cube_2mm_12_elements.h5", working_directory); TrianglesMeshReader<3,3> mesh_reader("mesh/test/data/cube_2mm_12_elements"); TetrahedralMesh<3,3> mesh; mesh.ConstructFromMeshReader(mesh_reader); // Convert Hdf5ToVtkConverter<3,3> converter(FileFinder(working_directory, RelativeTo::ChasteTestOutput), "cube_2mm_12_elements", &mesh, false, true); std::string test_output_directory = OutputFileHandler::GetChasteTestOutputDirectory(); // Now do something else before reading back... { //NOTE: Interleaved test // Show that trying to write .pvtu files from a TetrahedralMesh gives a warning (but writes anyway) CopyToTestOutputDirectory("pde/test/data/cube_2mm_12_elements.h5", working_directory2); Hdf5ToVtkConverter<3,3> converter2(FileFinder(working_directory2, RelativeTo::ChasteTestOutput), "cube_2mm_12_elements", &mesh, true, true); //The reading part of this test is below } /* * Note that VTK is not thread-safe. The master process has spawned * a child to write the mesh and may still be writing! This barrier * just slows things down a bit. */ PetscTools::Barrier(); VtkMeshReader<3,3> vtk_mesh_reader(test_output_directory + working_directory + "/vtk_output/cube_2mm_12_elements.vtu"); TS_ASSERT_EQUALS(vtk_mesh_reader.GetNumNodes(), 12u); TS_ASSERT_EQUALS(vtk_mesh_reader.GetNumElements(), 12u); std::vector<double> first_node = vtk_mesh_reader.GetNextNode(); TS_ASSERT_DELTA(first_node[0], 0.0, 1e-6); TS_ASSERT_DELTA(first_node[1], 0.0, 1e-6); TS_ASSERT_DELTA(first_node[2], 0.0, 1e-6); std::vector<double> next_node = vtk_mesh_reader.GetNextNode(); TS_ASSERT_DELTA(next_node[0], 0.2, 1e-6); TS_ASSERT_DELTA(next_node[1], 0.0, 1e-6); TS_ASSERT_DELTA(next_node[2], 0.0, 1e-6); // V_m and phi_e samples std::vector<double> v_at_last, phi_at_last; vtk_mesh_reader.GetPointData("V_000001", v_at_last); TS_ASSERT_DELTA(v_at_last[0], -46.3761, 1e-3); TS_ASSERT_DELTA(v_at_last[6], -46.3761, 1e-3); TS_ASSERT_DELTA(v_at_last[11], -46.3760, 1e-3); vtk_mesh_reader.GetPointData("Phi_e_000001", phi_at_last); TS_ASSERT_DELTA(phi_at_last[0], 0.0, 1e-3); TS_ASSERT_DELTA(phi_at_last[6], 0.0, 1e-3); TS_ASSERT_DELTA(phi_at_last[11], 0.0, 1e-3); { //NOTE: Interleaved test //The writing part of this test is above VtkMeshReader<3,3> vtk_mesh_reader2(test_output_directory + working_directory2 + "/vtk_output/cube_2mm_12_elements.vtu"); TS_ASSERT_EQUALS(vtk_mesh_reader2.GetNumNodes(), 12u); } #else std::cout << "This test was not run, as VTK is not enabled." << std::endl; std::cout << "If required please install and alter your hostconfig settings to switch on chaste VTK support." << std::endl; #endif //CHASTE_VTK }
/** * This tests the HDF5 to VTK converter in parallel using a 2D example * taken from a monodomain simulation. */ void TestMonodomainParallelVtkConversion2D() throw(Exception) { #ifdef CHASTE_VTK // Requires "sudo aptitude install libvtk5-dev" or similar std::string working_directory = "TestHdf5ToVtkConverter_monodomain2D"; /* * Firstly, copy the .h5 file to CHASTE_TEST_OUTPUT/TestHdf5ToVtkConverter_monodomain2D, * as that is where the reader reads from. */ CopyToTestOutputDirectory("pde/test/data/2D_0_to_1mm_400_elements.h5", working_directory); TrianglesMeshReader<2,2> mesh_reader("mesh/test/data/2D_0_to_1mm_400_elements"); DistributedTetrahedralMesh<2,2> mesh(DistributedTetrahedralMeshPartitionType::DUMB); mesh.ConstructFromMeshReader(mesh_reader); // Convert Hdf5ToVtkConverter<2,2> converter(FileFinder(working_directory, RelativeTo::ChasteTestOutput), "2D_0_to_1mm_400_elements", &mesh, true, false); /* * Note that VTK is not thread-safe. The master process has spawned * a child to write the mesh and may still be writing! This barrier * just slows things down a bit. */ PetscTools::Barrier(); std::string test_output_directory = OutputFileHandler::GetChasteTestOutputDirectory(); std::stringstream filepath; filepath << test_output_directory << working_directory << "/vtk_output/2D_0_to_1mm_400_elements"; if (!PetscTools::IsSequential()) { filepath << "_" << PetscTools::GetMyRank(); } filepath << ".vtu"; VtkMeshReader<2,2> vtk_mesh_reader(filepath.str()); TS_ASSERT_EQUALS(vtk_mesh_reader.GetNumNodes(), mesh.GetNumLocalNodes() + mesh.GetNumHaloNodes()); // 221 in total TS_ASSERT_EQUALS(vtk_mesh_reader.GetNumElements(), mesh.GetNumLocalElements()); // 400 in total if (PetscTools::IsSequential()) { std::vector<double> first_node = vtk_mesh_reader.GetNextNode(); TS_ASSERT_DELTA(first_node[0], 0.0 , 1e-6); TS_ASSERT_DELTA(first_node[1], 0.0, 1e-6); TS_ASSERT_DELTA(first_node[2], 0.0 , 1e-6); // 2d VTK files still carry z-coordinate std::vector<double> next_node = vtk_mesh_reader.GetNextNode(); TS_ASSERT_DELTA(next_node[0], 0.01, 1e-6); TS_ASSERT_DELTA(next_node[1], 0.0 , 1e-6); TS_ASSERT_DELTA(next_node[2], 0.0 , 1e-6); // 2d VTK files still carry z-coordinate } // V_m samples std::vector<double> v_at_last; vtk_mesh_reader.GetPointData("V_000020", v_at_last); if (PetscTools::IsSequential()) { TS_ASSERT_DELTA(v_at_last[0], -83.8534, 1e-3); TS_ASSERT_DELTA(v_at_last[110], -83.8534, 1e-3); TS_ASSERT_DELTA(v_at_last[220], -83.8530, 1e-3); } // Show that trying to write .pvtu files with original node ordering gives a warning (but writes anyway) Hdf5ToVtkConverter<2,2> converter2(FileFinder(working_directory, RelativeTo::ChasteTestOutput), "2D_0_to_1mm_400_elements", &mesh, true, true); /* * Note that VTK is not thread-safe. The master process has spawned * a child to write the mesh and may still be writing! This barrier * just slows things down a bit. */ PetscTools::Barrier(); VtkMeshReader<2,2> vtk_mesh_reader2(test_output_directory + working_directory + "/vtk_output/2D_0_to_1mm_400_elements.vtu"); TS_ASSERT_EQUALS(vtk_mesh_reader2.GetNumNodes(), 221u); #else std::cout << "This test was not run, as VTK is not enabled." << std::endl; std::cout << "If required please install and alter your hostconfig settings to switch on chaste VTK support." << std::endl; #endif //CHASTE_VTK }