void test(int segment_count, int test_count) { for (int i = 0; i < test_count; ++i) { MeshT mesh; SegmentationT segmentation(mesh); std::map<std::string, int> segment_names; while (static_cast<int>(segment_names.size()) != segment_count) segment_names[random_name()] = rand() % 90 + 10; for (std::map<std::string, int>::const_iterator sit = segment_names.begin(); sit != segment_names.end(); ++sit) { for (int j = 0; j < sit->second; ++j) viennagrid::make_vertex( segmentation(sit->first) ); } for (std::map<std::string, int>::const_iterator sit = segment_names.begin(); sit != segment_names.end(); ++sit) { if (static_cast<int>(viennagrid::vertices( segmentation(sit->first) ).size()) != sit->second) { std::cerr << "Numbers of vertices in a named segment is equal to created vertices" << std::endl; std::cerr << "FAILED!" << std::endl; exit(EXIT_FAILURE); } } } }
void testPadDimensions(AliMq::Station12Type station, AliMp::PlaneType plane) { AliMpDataProcessor mp; AliMpDataMap* dataMap = mp.CreateDataMap("data"); AliMpDataStreams dataStreams(dataMap); AliMpSectorReader r(dataStreams, station, plane); AliMpSector* sector = r.BuildSector(); AliMpSectorSegmentation segmentation(sector); segmentation.PrintZones(); TVector2 previousDimensions; for (Int_t i=1; i<segmentation.MaxPadIndexX()+1;i++) for (Int_t j=1;j<segmentation.MaxPadIndexY()+1;++j) { if ( segmentation.HasPadByIndices(i,j) ) { // Check pad dimensions AliMpPad pad = segmentation.PadByIndices(i,j); TVector2 dimensions = segmentation.PadDimensions(segmentation.Zone(pad)); if ( dimensions.X() != previousDimensions.X() || dimensions.Y() != previousDimensions.Y() ) { // Print dimensions cout << "Pad: " << "(" << i << "," << j << ")"; cout << " dimensions: (" << dimensions.X() << ", " << dimensions.Y() << ")" << endl; previousDimensions = dimensions; } } } }
int main(int argc, char **argv) { typedef viennagrid::tetrahedral_3d_mesh MeshType; typedef viennagrid::tetrahedral_3d_segmentation SegmentationType; typedef viennagrid::result_of::vertex<MeshType>::type VertexType; typedef viennagrid::result_of::cell<MeshType>::type CellType; if (argc < 4) { std::cout << "Usage: mosfet_3d_viennamesh <input_file> <output_file> <interpolate_names ...>" << std::endl; return -1; } std::string input_file = argv[1]; std::string output_file = argv[2]; MeshType mesh; SegmentationType segmentation(mesh); std::map< std::string, std::deque<double> > cell_values; std::map< std::string, std::deque<double> > vertex_values; try { viennagrid::io::vtk_reader<MeshType> reader; for (int i = 3; i < argc; ++i) viennagrid::io::add_scalar_data_on_cells(reader, viennagrid::make_accessor<CellType>(cell_values[argv[i]]), argv[i] ); reader(mesh, segmentation, input_file); } catch (...) { std::cerr << "File-Reader failed. Aborting program..." << std::endl; return EXIT_FAILURE; } viennagrid::io::vtk_writer<MeshType> vtk_writer; for ( std::map< std::string, std::deque<double> >::iterator it = cell_values.begin(); it != cell_values.end(); ++it ) { std::string interpolate_value_name = it->first; std::cout << "Interpolating " << interpolate_value_name << std::endl; viennagrid::result_of::accessor<std::deque<double>, CellType>::type cell_accessor( it->second ); viennagrid::result_of::accessor<std::deque<double>, VertexType>::type vertex_accessor( vertex_values[it->first] ); interpolate<viennagrid::tetrahedron_tag, viennagrid::vertex_tag>( mesh, cell_accessor, vertex_accessor ); viennagrid::io::add_scalar_data_on_cells(vtk_writer, cell_accessor, interpolate_value_name); viennagrid::io::add_scalar_data_on_vertices(vtk_writer, vertex_accessor, interpolate_value_name); } vtk_writer( mesh, segmentation, output_file); return 0; }
void main() { try { // ビューアー pcl::visualization::PCLVisualizer viewer( "Point Cloud Viewer" ); // 点群 pcl::PointCloud<PointType>::Ptr cloud( new pcl::PointCloud<PointType> ); // 点群の排他処理 boost::mutex mutex; // データの更新ごとに呼ばれる関数(オブジェクト) boost::function<void(const pcl::PointCloud<PointType>::ConstPtr&)> function = [&cloud, &mutex]( const pcl::PointCloud<PointType>::ConstPtr &new_cloud ){ boost::mutex::scoped_lock lock( mutex ); pcl::copyPointCloud( *new_cloud, *cloud ); }; // Kinect2Grabberを開始する pcl::Kinect2Grabber grabber; grabber.registerCallback( function ); grabber.start(); // ビューアーが終了されるまで動作する while ( !viewer.wasStopped() ){ // 表示を更新する viewer.spinOnce(); // 点群がある場合 boost::mutex::scoped_try_lock lock( mutex ); if ( (cloud->size() != 0) && lock.owns_lock() ){ // 点群を間引く voxelGridFilter( cloud ); // 平面を検出 auto inliers = segmentation( cloud ); // 平面を抽出 extractIndices( cloud, inliers ); // 点群を更新する auto ret = viewer.updatePointCloud( cloud, "cloud" ); if ( !ret ){ // 更新がエラーになった場合は、 // 未作成なので新しい点群として追加する viewer.addPointCloud( cloud, "cloud" ); } } // エスケープキーが押されたら終了する if ( GetKeyState( VK_ESCAPE ) < 0 ){ break; } } } catch ( std::exception& ex ){ std::cout << ex.what() << std::endl; } }
bool dump_information(std::string const & filename, std::string const & outputfile) { // defining and creating a mesh and a segmentation typedef typename viennagrid::result_of::segmentation<MeshT>::type SegmentationType; MeshT mesh; SegmentationType segmentation(mesh); // trying to read the file try { ReaderT reader; reader(mesh, segmentation, filename); } catch (std::exception & e) { std::cout << "Error reading mesh file: " << filename << std::endl; std::cout << e.what() << std::endl; return false; } viennagrid::io::vmesh_writer<MeshT> writer; writer(mesh, segmentation, filename, outputfile); return true; }
int main() { typedef viennagrid::mesh< viennagrid::config::tetrahedral_3d > Mesh; typedef viennagrid::result_of::segmentation<Mesh>::type Segmentation; std::cout << "--------------------------------------------" << std::endl; std::cout << "-- ViennaGrid tutorial: Convert to MPHTXT --" << std::endl; std::cout << "--------------------------------------------" << std::endl; std::cout << std::endl; Mesh mesh; Segmentation segmentation(mesh); viennagrid::io::vtk_reader<Mesh, Segmentation> reader; reader(mesh, segmentation, "../data/tets_with_data_main.pvd"); viennagrid::io::mphtxt_writer writer; writer(mesh, segmentation, "output.mphtxt"); std::cout << std::endl; std::cout << "-----------------------------------------------" << std::endl; std::cout << " \\o/ Tutorial finished successfully! \\o/ " << std::endl; std::cout << "-----------------------------------------------" << std::endl; return EXIT_SUCCESS; }
ICCVTutorial<FeatureType>::ICCVTutorial(boost::shared_ptr<pcl::Keypoint<pcl::PointXYZRGB, pcl::PointXYZI> >keypoint_detector, typename pcl::Feature<pcl::PointXYZRGB, FeatureType>::Ptr feature_extractor, boost::shared_ptr<pcl::PCLSurfaceBase<pcl::PointXYZRGBNormal> > surface_reconstructor, typename pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr source, typename pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr target) : source_keypoints_ (new pcl::PointCloud<pcl::PointXYZI> ()) , target_keypoints_ (new pcl::PointCloud<pcl::PointXYZI> ()) , keypoint_detector_ (keypoint_detector) , feature_extractor_ (feature_extractor) , surface_reconstructor_ (surface_reconstructor) , source_ (source) , target_ (target) , source_segmented_ (new pcl::PointCloud<pcl::PointXYZRGB>) , target_segmented_ (new pcl::PointCloud<pcl::PointXYZRGB>) , source_transformed_ (new pcl::PointCloud<pcl::PointXYZRGB>) , source_registered_ (new pcl::PointCloud<pcl::PointXYZRGB>) , source_features_ (new pcl::PointCloud<FeatureType>) , target_features_ (new pcl::PointCloud<FeatureType>) , correspondences_ (new pcl::Correspondences) , show_source2target_ (false) , show_target2source_ (false) , show_correspondences (false) { // visualizer_.registerKeyboardCallback(&ICCVTutorial::keyboard_callback, *this, 0); segmentation (source_, source_segmented_); segmentation (target_, target_segmented_); detectKeypoints (source_segmented_, source_keypoints_); detectKeypoints (target_segmented_, target_keypoints_); extractDescriptors (source_segmented_, source_keypoints_, source_features_); extractDescriptors (target_segmented_, target_keypoints_, target_features_); findCorrespondences (source_features_, target_features_, source2target_); findCorrespondences (target_features_, source_features_, target2source_); filterCorrespondences (); determineInitialTransformation (); determineFinalTransformation (); // reconstructSurface (); }
int main() { typedef viennagrid::tetrahedral_3d_mesh MeshType; typedef viennagrid::tetrahedral_3d_segmentation SegmentationType; // typedef viennagrid::triangular_2d_mesh MeshType; //use this for a 2d example // typedef viennagrid::triangular_2d_segmentation SegmentationType; //use this for a 2d example std::cout << "----------------------------------------------------------" << std::endl; std::cout << "-- ViennaGrid tutorial: Finite Volumes using ViennaGrid --" << std::endl; std::cout << "----------------------------------------------------------" << std::endl; std::cout << std::endl; MeshType mesh; SegmentationType segmentation(mesh); viennagrid::io::netgen_reader reader; #ifdef _MSC_VER //Visual Studio builds in a subfolder std::string path = "../../examples/data/"; #else std::string path = "../../examples/data/"; #endif reader(mesh, segmentation, path + "cube48.mesh"); //use this for a 3d example // reader(mesh, segmentation, path + "square32.mesh"); //use this for a 2d example sparse_matrix<double> system_matrix; std::vector<double> load_vector; assemble(mesh, system_matrix, load_vector); // // Next step: Solve here using a linear algebra library, e.g. ViennaCL. (not included in this tutorial to avoid external dependencies) // Instead, we print the matrix std::cout << std::endl << "System matrix: " << std::endl; for (std::size_t i=0; i<load_vector.size(); ++i) { std::cout << "Row " << i << ": "; for (std::size_t j=0; j<load_vector.size(); ++j) { if (system_matrix(i,j) != 0) std::cout << "(" << j << ", " << system_matrix(i,j) << "), "; } std::cout << std::endl; } std::cout << std::endl << "Load vector: " << std::endl; for (std::size_t i=0; i<load_vector.size(); ++i) std::cout << load_vector[i] << " " << std::endl; std::cout << std::endl; std::cout << "-----------------------------------------------" << std::endl; std::cout << " \\o/ Tutorial finished successfully! \\o/ " << std::endl; std::cout << "-----------------------------------------------" << std::endl; return EXIT_SUCCESS; }
int main(int argc, char **argv) { ros::init(argc, argv, "object_segmentation"); ObjectSegmentation segmentation("object_segmentation"); ros::spin(); return 0; }
int main() { //typedef viennagrid::mesh<my_mesh_config> mesh_type; typedef viennagrid::triangular_2d_mesh mesh_type; typedef viennagrid::result_of::mesh_view< mesh_type >::type view_type; typedef viennagrid::result_of::point<mesh_type>::type point_type; typedef viennagrid::result_of::cell< mesh_type >::type cell_type; typedef viennagrid::result_of::vertex< mesh_type >::type vertex_type; typedef viennagrid::result_of::vertex_handle< mesh_type >::type vertex_handle_type; typedef viennagrid::result_of::triangle_handle< mesh_type >::type triangle_handle_type; typedef viennagrid::result_of::triangle< mesh_type >::type triangle_type; typedef viennagrid::result_of::oriented_3d_hull_segmentation<mesh_type>::type segmentation_type; // typedef viennagrid::result_of::segmentation<mesh_type>::type segmentation_type; typedef segmentation_type::segment_handle_type segment_handle_type; typedef segmentation_type::segment_id_type segment_id_type; mesh_type mesh; segmentation_type segmentation(mesh); viennagrid::io::vtk_reader<mesh_type, segmentation_type> reader; std::deque<double> potential_point; std::deque<double> potential_cell; reader.register_vertex_scalar( viennagrid::make_accessor<vertex_type>(potential_point), "potential_point" ); reader.register_cell_scalar( viennagrid::make_accessor<cell_type>(potential_cell), "potential_cell" ); reader(mesh, segmentation, "test_main.pvd"); segment_handle_type seg0 = segmentation[0]; segment_handle_type seg1 = segmentation[1]; viennagrid::io::vtk_writer<mesh_type, segmentation_type> writer; writer.add_scalar_data_on_vertices( viennagrid::make_accessor<vertex_type>(potential_point), "potential_point" ); writer.add_scalar_data_on_vertices( seg0, reader.vertex_scalar_field("potential_point_segment", seg0), "potential_point_segment" ); writer.add_scalar_data_on_cells( viennagrid::make_accessor<cell_type>(potential_point), "potential_cell" ); writer.add_scalar_data_on_cells( seg1, reader.cell_scalar_field("potential_cell_segment", seg1), "potential_cell_segment" ); writer( mesh, segmentation, "vtk_reader_test" ); return 0; }
void testIndicesLimits(AliMq::Station12Type station,AliMp::PlaneType plane) { AliMpDataProcessor mp; AliMpDataMap* dataMap = mp.CreateDataMap("data"); AliMpDataStreams dataStreams(dataMap); AliMpSectorReader r(station, plane); AliMpSector *sector=r.BuildSector(dataStreams); AliMpSectorSegmentation segmentation(sector); // Loop over rows for (Int_t i=0; i<sector->GetNofRows(); i++) { AliMpRow* row = sector->GetRow(i); cout << i << "th row limits: "; AliMp::PairPut(cout, row->GetLowIndicesLimit()) << " "; AliMp::PairPut(cout, row->GetHighIndicesLimit()) << endl; // Loop over row segments for (Int_t j=0; j<row->GetNofRowSegments(); j++) { AliMpVRowSegment* rowSegment = row->GetRowSegment(j); cout << " " << j << "th row segment limits: "; AliMp::PairPut(cout, rowSegment->GetLowIndicesLimit()) << " "; AliMp::PairPut(cout, rowSegment->GetHighIndicesLimit()) << endl; // Loop over motif positions for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) { Int_t mposID = rowSegment->GetMotifPositionId(k); AliMpMotifPosition* mPos = sector->GetMotifMap()->FindMotifPosition(mposID); if (mPos) { cout << " " << mPos->GetID() << " motif position limits: "; AliMp::PairPut(cout, mPos->GetLowIndicesLimit()) << " "; AliMp::PairPut(cout, mPos->GetHighIndicesLimit()) << endl; } else { cerr << "Motif position " << mposID << " not found in the map" << endl; } } } } delete sector; }
int hsi(IplImage* img) { int *huearr; float *intarr, *satarr; int width = img->width; int height = img->height; int depth = img->depth; int nchannels = img->nChannels; //cvShowImage("RGB-Image(Original)",img); IplImage *intensity = cvCreateImage( cvSize(width,height), depth, 1); IplImage *saturation = cvCreateImage(cvSize(width,height), depth, 1); IplImage *hue = cvCreateImage(cvSize(width,height), depth, 1); IplImage *hsiimg = cvCreateImage(cvSize(width, height), depth, nchannels); huearr = (int*)malloc(width*height*sizeof(int)); satarr = (float*)malloc(width*height*sizeof(int)); intarr = (float*)malloc(width*height*sizeof(int)); toIntensity(img, intensity, intarr); toSaturation(img, saturation, satarr); toHue(img, hue, huearr); segmentation(huearr, satarr, intarr, height, width); toRGB(hsiimg, huearr, satarr, intarr); //cvShowImage("Intensity-Image", intensity); //cvShowImage("Saturation-Image", saturation); //cvShowImage("Hue-Image", hue); cvShowImage("HSI2RGB-Image", hsiimg); //cvNamedWindow("RGB-Image(Original)",CV_WINDOW_AUTOSIZE); //cvNamedWindow("HSI-Image",CV_WINDOW_AUTOSIZE); //cvMoveWindow("RGB-Image(Original)",100,100); //cvMoveWindow("HSI-Image",100,500); //cvDestroyWindow("Image"); cvReleaseImage(&intensity); cvReleaseImage(&saturation); cvReleaseImage(&hsiimg); return 0; }
int arrow_detection::featureExteraction(Mat arrow,vector<float> &features){ features.clear(); Mat binary; vector <std::vector<cv::Point2i >> blobs; vector<Rect> blobs_roi; preProcessing(arrow, binary); // viewImage(binary*255,"binary arrow"); segmentation(binary,blobs_roi, blobs); // DEBUG_LOG("Blobs attained : %ld\n",blobs_roi.size()); if(blobs_roi.size() > 1){ // ERROR_LOG("More than one blobs detected possibly an error."); return -1; } float convex_area = blobs[0].size(); features.push_back(convex_area); // DEBUG_LOG("convex_area : %f\n",convex_area); Rect arrow_rect(blobs_roi[0]); float a = 0,b = 0; if(arrow_rect.width > arrow_rect.height){ a = arrow_rect.width/2; b = arrow_rect.height/2; }else{ a = arrow_rect.height/2; b = arrow_rect.width/2; } // DEBUG_LOG("semi major axis: %f\n",a); // DEBUG_LOG("semi minor axis: %f\n",b); // DEBUG_LOG("their ratio: %f\n",b/a); // DEBUG_LOG("pow(b/a,2) : %f\n",pow(b/a,2)); float ecentricity = sqrtf(1-pow(b/a,2)); features.push_back(ecentricity); // DEBUG_LOG("ecentricity : %f\n",ecentricity); float extent = convex_area/float(arrow.total()); features.push_back(extent); // DEBUG_LOG("extent : %f\n",extent); float solidity = float(arrow.total())/convex_area; features.push_back(extent); // DEBUG_LOG("solidity : %f\n",solidity); return 0; }
void kmeans(pixel* clusterKernel,cluster* cluster,Image toSegment,unsigned K){ int i,k; for (i = 0; i < 10; i++) { for (k = 0; k < K; k++) { cluster[K].nbPixel=0; } segmentation(clusterKernel,cluster,K,toSegment->matrix,toSegment->height,toSegment->length); #pragma omp parallel for for (k = 0; k < K; k++) { updateKernel(clusterKernel,cluster,k); } } }
StatusCode FastGaussSmearDigi::initialize() { info() << "initialize" << endmsg; m_geoSvc = service("GeoSvc"); StatusCode sc = GaudiAlgorithm::initialize(); if (sc.isFailure()) return sc; auto lcdd = m_geoSvc->lcdd(); auto readout = lcdd->readout(m_readoutName); m_decoder = readout.idSpec().decoder(); auto segmentationXZ = dynamic_cast<DD4hep::DDSegmentation::CartesianGridXZ*>(readout.segmentation().segmentation()); if (nullptr == segmentationXZ) { error() << "Could not retrieve segmentation!" << endmsg; return StatusCode::FAILURE; } m_segGridSizeX = segmentationXZ->gridSizeX(); m_segGridSizeZ = segmentationXZ->gridSizeZ(); m_volman = lcdd->volumeManager(); return sc; }
int main() { typedef viennagrid::line_1d_mesh MeshType; typedef viennagrid::result_of::segmentation<MeshType>::type SegmentationType; typedef viennamath::function_symbol FunctionSymbol; typedef viennamath::equation Equation; // // Create a mesh from file // MeshType mesh; SegmentationType segmentation(mesh); try { viennagrid::io::netgen_reader my_netgen_reader; my_netgen_reader(mesh, segmentation, "../examples/data/line23.mesh"); } catch (...) { std::cerr << "File-Reader failed. Aborting program..." << std::endl; return EXIT_FAILURE; } // // Create problem description // viennafvm::problem_description<MeshType> problem_desc(mesh); // Initialize unknowns: typedef viennafvm::problem_description<MeshType>::quantity_type QuantityType; QuantityType & quan = problem_desc.add_quantity("u"); viennafvm::set_dirichlet_boundary(quan, segmentation(1), 0.0); viennafvm::set_dirichlet_boundary(quan, segmentation(5), 1.0); viennafvm::set_unknown(quan, segmentation(2)); viennafvm::set_unknown(quan, segmentation(3)); viennafvm::set_unknown(quan, segmentation(4)); QuantityType & quan_permittivity = problem_desc.add_quantity("permittivity", 3); viennafvm::set_initial_value(quan_permittivity, segmentation(3), 1.0); viennafvm::set_initial_value(quan_permittivity, segmentation(4), 1.0); viennafvm::set_initial_value(quan_permittivity, segmentation(5), 1.0); // Specify Poisson equation: FunctionSymbol u(0, viennamath::unknown_tag<>()); //an unknown function used for PDE specification FunctionSymbol permittivity(1); Equation poisson_eq = viennamath::make_equation( viennamath::div(permittivity * viennamath::grad(u)), 0); // \Delta u = 0 // // Setup Linear Solver // viennafvm::linsolv::viennacl linear_solver; // // Pass system to solver: // viennafvm::pde_solver my_solver; my_solver(problem_desc, viennafvm::make_linear_pde_system(poisson_eq, u), // PDE with associated unknown linear_solver); // // Writing solution back to mesh (discussion about proper way of returning a solution required...) // viennafvm::io::write_solution_to_VTK_file(problem_desc.quantities(), "poisson_1d", mesh, segmentation); std::cout << "*****************************************" << std::endl; std::cout << "* Poisson solver finished successfully! *" << std::endl; std::cout << "*****************************************" << std::endl; return EXIT_SUCCESS; }
bool ViBeBGModule::run() { if(firstTime) { if(imgARGB32.empty() || imgARGB32.data == NULL) { this->height = m_data->currentImage->height(); this->width = m_data->currentImage->width(); this->imgARGB32 = cv::Mat(height, width, CV_8UC4 ); } if(m_data->fgImage == NULL) { m_data->fgImage = new QImage(width,height, QImage::Format_Indexed8); m_data->fgImage->setColorTable(*(m_data->grayScaleTable)); memset(m_data->fgImage->bits(), 0, height*m_data->fgImage->bytesPerLine()); } if(m_data->reliabilityMap == NULL || m_data->reliabilityMap->isNull()) { m_data->reliabilityMap = new QImage(width,height, QImage::Format_ARGB32); } if(m_data->colouredFgImage == NULL) { m_data->colouredFgImage = new QImage(width,height, QImage::Format_ARGB32); } if(this->displayMeanSample) meanSample = cv::Mat(height, width, CV_32FC3); this->reliabilityNormalized = cv::Mat(height,width, CV_8UC1); this->featureMap = cv::Mat(height, width, CV_8UC1); this->ptr_colouredFg = m_data->colouredFgImage->bits(); this->ptr_fgDataImg = m_data->fgImage->bits(); memcpy(imgARGB32.data, m_data->currentImage->bits(), height*m_data->currentImage->bytesPerLine()); #ifdef __OPENCV3__ cv::cvtColor(imgARGB32, currImgC3, cv::COLOR_RGBA2BGR); #else cv::cvtColor(imgARGB32, currImgC3, CV_RGBA2BGR); #endif this->randGen.state = randSeed; initVibe( currImgC3); firstTime = false; } else { memcpy(imgARGB32.data, m_data->currentImage->bits(), height*m_data->currentImage->bytesPerLine()); #ifdef __OPENCV3__ cv::cvtColor(imgARGB32, currImgC3, cv::COLOR_RGBA2BGR); #else cv::cvtColor(imgARGB32, currImgC3, CV_RGBA2BGR); #endif } segmentation(); updateBackground(); if(this->usePreviusFg) { for(int y = 0; y < height; y++) { for(int x = 0; x < width; x++) { for(int x = 0; x < width; x++) { if( (this->foreground.at<uchar>(y,x) != 0) ) { if( ptr_fgDataImg[y*width + x] == 0 ) m_data->colouredFgImage->setPixel(x,y, this->methodColor.rgba()); else m_data->colouredFgImage->setPixel(x,y, qRgba(255,0,0,255)); } } } } } else { for(int y = 0; y < height; y++) { for(int x = 0; x < width; x++) { if(this->foreground.at<uchar>(y,x) != 0) m_data->colouredFgImage->setPixel(x,y, this->methodColor.rgb()); else m_data->colouredFgImage->setPixel(x,y, qRgba(255,255,255,255)); } } } if(displayFeatureMap) { featureMapThermal = ThermalColor::reliabilityToThermal(this->featureMap); // cv::applyColorMap(featureMap,featureMapThermal,cv::COLORMAP_HOT); #ifdef __OPENCV3__ cv::cvtColor(featureMapThermal, featureMapThermal, cv::COLOR_RGB2BGR); #else cv::cvtColor(featureMapThermal, featureMapThermal, CV_RGB2BGR); #endif cv::namedWindow("featureMap"); cv::imshow("featureMap",this->featureMapThermal); } if(displayMeanSample) { memset(meanSample.data, 0, sizeof(float)*3*height*width); for(int i = 0; i < numSamples; i++) { this->samples[i].convertTo(sample32F,CV_32FC3); meanSample += sample32F; } meanSample = meanSample/ numSamples; meanSample.convertTo(meanSampleU,CV_8UC3); #ifdef __OPENCV3__ cv::cvtColor(meanSampleU, meanSampleU, cv::COLOR_BGR2RGB); #else cv::cvtColor(meanSampleU, meanSampleU, CV_BGR2RGB); #endif cv::namedWindow("meanSample"); cv::imshow("meanSample",meanSampleU); cv::imwrite("viBeBg.jpg",meanSampleU); } if(saveFeatureMapImage) { this->featureMapThermal = ThermalColor::reliabilityToThermal(this->featureMap); #ifdef __OPENCV3__ cv::cvtColor(featureMapThermal, imgARGB32, cv::COLOR_RGB2RGBA); #else cv::cvtColor(featureMapThermal, imgARGB32, CV_RGB2RGBA); #endif memcpy(m_data->reliabilityMap->bits(), imgARGB32.data, height * m_data->reliabilityMap->bytesPerLine()); m_data->reliabilityMap->save("VB_feature_" + QString::number(m_data->frameNumber) + ".png"); } memcpy(m_data->fgImage->bits(), this->foreground.data, height*m_data->fgImage->bytesPerLine()); this->reliabilityNormalizedThermal = ThermalColor::reliabilityToThermal(this->reliabilityNormalized); #ifdef __OPENCV3__ cv::cvtColor(reliabilityNormalizedThermal, imgARGB32, cv::COLOR_BGR2BGRA); #else cv::cvtColor(reliabilityNormalizedThermal, imgARGB32, CV_BGR2BGRA); #endif memcpy(m_data->reliabilityMap->bits(), imgARGB32.data, height * m_data->reliabilityMap->bytesPerLine()); if(saveReliabilityMapImage) { m_data->reliabilityMap->save("VB_reliab_" + QString::number(m_data->frameNumber) + ".png"); } if(saveFgImage) { m_data->fgImage->save("VB_fg_" + QString::number(m_data->frameNumber) + ".png"); } if(saveColouredFgMethod) { m_data->colouredFgImage->save("VB_fg_coloured_method_" + QString::number(m_data->frameNumber) + ".png"); } return true; }
ToolsMenu::ToolsMenu(ImageViewer* iv, QWidget* parent) : QWidget(parent), ui(new Ui::ToolsMenu) { ui->setupUi(this); setLayout(ui->verticalLayoutWidget->layout()); m_viewer = (ImageViewer*) iv; m_tools = new Tools(m_viewer, this); // locking tools menu when performing transformation connect(m_viewer, SIGNAL(lockTools()), this, SLOT(disableAllTools())); connect(m_viewer, SIGNAL(unlockTools()), this, SLOT(enableAllTools())); /* ------------------------------------------------------- * ROTATION * ------------------------------------------------------- */ connect(ui->rotate90Button, SIGNAL(clicked()), m_tools, SLOT(rotate90())); connect(ui->rotate180Button, SIGNAL(clicked()), m_tools, SLOT(rotate180())); connect(ui->rotate270Button, SIGNAL(clicked()), m_tools, SLOT(rotate270())); /* ------------------------------------------------------- * HISTOGRAM * ------------------------------------------------------- */ QMenu* hMenu = new QMenu(ui->histogramButton); hMenu->addAction( QIcon(":/icons/icons/chart_curve_error.png"), QString("Equalize histograms"), m_tools, SLOT(histogramEqualize()) ); hMenu->addAction( QIcon(":/icons/icons/chart_curve_go.png"), QString("Stretch histograms"), m_tools, SLOT(histogramStretch()) ); ui->histogramButton->setMenu(hMenu); /* ------------------------------------------------------- * FILTERS (convolution, blur) * ------------------------------------------------------- */ QMenu* bMenu = new QMenu(ui->blurButton); bMenu->addAction( QIcon(":/icons/icons/draw_convolve.png"), QString("Gaussian blur"), m_tools, SLOT(blurGauss()) ); bMenu->addAction( QIcon(":/icons/icons/draw_convolve.png"), QString("Uniform blur"), m_tools, SLOT(blurUniform()) ); bMenu->addAction( QIcon(":/icons/icons/flag_airfield_vehicle_safety.png"), QString("Custom linear filter"), m_tools, SLOT(blurLinear()) ); ui->blurButton->setMenu(bMenu); /* ------------------------------------------------------- * BINARIZATION * ------------------------------------------------------- */ QMenu* binMenu = new QMenu(ui->binarizationButton); binMenu->addAction( QIcon(":/icons/icons/universal_binary.png"), QString("Manual"), m_tools, SLOT(binManual()) ); binMenu->addAction( QIcon(":/icons/icons/universal_binary.png"), QString("Gradient"), m_tools, SLOT(binGradient()) ); binMenu->addAction( QIcon(":/icons/icons/universal_binary.png"), QString("Iterative bimodal"), m_tools, SLOT(binIterBimodal()) ); binMenu->addAction( QIcon(":/icons/icons/universal_binary.png"), QString("Niblack"), m_tools, SLOT(binNiblack()) ); binMenu->addAction( QIcon(":/icons/icons/universal_binary.png"), QString("Otsu"), m_tools, SLOT(binOtsu()) ); ui->binarizationButton->setMenu(binMenu); /* ------------------------------------------------------- * NOISE REDUCTION * ------------------------------------------------------- */ QMenu* nMenu = new QMenu(ui->noiseButton); nMenu->addAction( QIcon(":/icons/icons/checkerboard.png"), QString("Median"), m_tools, SLOT(noiseMedian()) ); nMenu->addAction( QIcon(":/icons/icons/checkerboard.png"), QString("Bilateral"), m_tools, SLOT(noiseBilateral()) ); ui->noiseButton->setMenu(nMenu); /* ------------------------------------------------------- * MORPHOLOGICAL * ------------------------------------------------------- */ QMenu* morphMenu = new QMenu(ui->morphButton); morphMenu->addAction( QIcon(":/icons/icons/arrow_out.png"), QString("Dilate"), m_tools, SLOT(morphDilate()) ); morphMenu->addAction( QIcon(":/icons/icons/arrow_in.png"), QString("Erode"), m_tools, SLOT(morphErode()) ); morphMenu->addAction( QIcon(":/icons/icons/arrow_divide.png"), QString("Open"), m_tools, SLOT(morphOpen()) ); morphMenu->addAction( QIcon(":/icons/icons/arrow_join.png"), QString("Close"), m_tools, SLOT(morphClose()) ); ui->morphButton->setMenu(morphMenu); /* ------------------------------------------------------- * EDGE DETECTION * ------------------------------------------------------- */ QMenu* eMenu = new QMenu(ui->edgeButton); eMenu->addAction( QIcon(":/icons/icons/key_s.png"), QString("Sobel"), m_tools, SLOT(edgeSobel()) ); eMenu->addAction( QIcon(":/icons/icons/key_p.png"), QString("Prewitt"), m_tools, SLOT(edgePrewitt()) ); eMenu->addAction( QIcon(":/icons/icons/key_r.png"), QString("Roberts"), m_tools, SLOT(edgeRoberts()) ); eMenu->addAction( QIcon(":/icons/icons/edge_detection.png"), QString("Laplacian"), m_tools, SLOT(edgeLaplacian()) ); eMenu->addAction( QIcon(":/icons/icons/edge_detection.png"), QString("Zero-crossing (LoG)"), m_tools, SLOT(edgeZero()) ); eMenu->addAction( QIcon(":/icons/icons/edge_detection.png"), QString("Canny"), m_tools, SLOT(edgeCanny()) ); ui->edgeButton->setMenu(eMenu); /* ------------------------------------------------------- * TEXTURES * ------------------------------------------------------- */ QMenu* texMenu = new QMenu(ui->textureButton); texMenu->addAction( QIcon(":/icons/icons/flag_airfield_vehicle_safety.png"), QString("Height map"), m_tools, SLOT(mapHeight()) ); texMenu->addAction( QIcon(":/icons/icons/flag_airfield_vehicle_safety.png"), QString("Normal map"), m_tools, SLOT(mapNormal()) ); texMenu->addAction( QIcon(":/icons/icons/flag_airfield_vehicle_safety.png"), QString("Horizon map"), m_tools, SLOT(mapHorizon()) ); ui->textureButton->setMenu(texMenu); /* ------------------------------------------------------- * TRANSFORMATIONS * ------------------------------------------------------- */ QMenu* transMenu = new QMenu(ui->transformationsButton); transMenu->addAction( QIcon(":/icons/icons/videodisplay.png"), QString("Hough"), m_tools, SLOT(houghTransform()) ); transMenu->addAction( QIcon(":/icons/icons/videodisplay.png"), QString("Hough - lines"), m_tools, SLOT(houghLines()) ); transMenu->addAction( QIcon(":/icons/icons/videodisplay.png"), QString("Hough - rectangles"), m_tools, SLOT(houghRectangles()) ); transMenu->addAction( QIcon(":/icons/icons/videodisplay.png"), QString("Segmentation"), m_tools, SLOT(segmentation()) ); ui->transformationsButton->setMenu(transMenu); /* ------------------------------------------------------- * CORNER DETECTION * ------------------------------------------------------- */ QMenu* cornerMenu = new QMenu(ui->cornerButton); cornerMenu->addAction( QIcon(":/icons/icons/things_digital.png"), QString("Harris"), m_tools, SLOT(cornerHarris()) ); ui->cornerButton->setMenu(cornerMenu); }
void test_vtk(ReaderType & my_reader, std::string const & infile, std::string const & outfile) { typedef typename viennagrid::result_of::segmentation<MeshType>::type SegmentationType; typedef typename viennagrid::result_of::vertex<MeshType>::type VertexType; typedef typename viennagrid::result_of::cell<MeshType>::type CellType; typedef typename viennagrid::result_of::vertex_range<MeshType>::type VertexContainer; typedef typename viennagrid::result_of::iterator<VertexContainer>::type VertexIterator; typedef typename viennagrid::result_of::cell_range<MeshType>::type CellRange; typedef typename viennagrid::result_of::iterator<CellRange>::type CellIterator; MeshType mesh; SegmentationType segmentation(mesh); std::vector<double> vtk_vertex_double_data; std::vector<double> vtk_vertex_long_data; std::vector< std::vector<double> > vtk_vertex_vector_data; typename viennagrid::result_of::accessor< std::vector<double>, VertexType >::type vtk_vertex_double_accessor( vtk_vertex_double_data ); typename viennagrid::result_of::accessor< std::vector<double>, VertexType >::type vtk_vertex_long_accessor( vtk_vertex_long_data ); typename viennagrid::result_of::accessor< std::vector< std::vector<double> >, VertexType >::type vtk_vertex_vector_accessor( vtk_vertex_vector_data ); std::vector<double> vtk_cell_double_data; std::vector<double> vtk_cell_long_data; std::vector< std::vector<double> > vtk_cell_vector_data; typename viennagrid::result_of::accessor< std::vector<double>, CellType >::type vtk_cell_double_accessor( vtk_cell_double_data ); typename viennagrid::result_of::accessor< std::vector<double>, CellType >::type vtk_cell_long_accessor( vtk_cell_long_data ); typename viennagrid::result_of::accessor< std::vector< std::vector<double> >, CellType >::type vtk_cell_vector_accessor( vtk_cell_vector_data ); viennagrid::io::add_scalar_data_on_vertices(my_reader, vtk_vertex_double_accessor, "data_double" ); viennagrid::io::add_scalar_data_on_vertices(my_reader, vtk_vertex_long_accessor, "data_long" ); viennagrid::io::add_vector_data_on_vertices(my_reader, vtk_vertex_vector_accessor, "data_point" ); viennagrid::io::add_scalar_data_on_cells(my_reader, vtk_cell_double_accessor, "data_double"); viennagrid::io::add_scalar_data_on_cells(my_reader, vtk_cell_long_accessor, "data_long"); viennagrid::io::add_vector_data_on_cells(my_reader, vtk_cell_vector_accessor, "data_point"); try { my_reader(mesh, segmentation, infile); } catch (std::exception const & ex) { std::cerr << ex.what() << std::endl; std::cerr << "File-Reader failed. Aborting program..." << std::endl; exit(EXIT_FAILURE); } //write some dummy data: VertexContainer vertices(mesh); for (VertexIterator vit = vertices.begin(); vit != vertices.end(); ++vit) { double data_double = vtk_vertex_double_accessor(*vit); long data_long = static_cast<long>(vtk_vertex_long_accessor(*vit)); std::vector<double> data_point = vtk_vertex_vector_accessor(*vit); assert( fabs(data_double - viennagrid::point(*vit)[0]) < 1e-4 && "Vertex check failed: data_double!"); assert( (data_long == vit->id().get()) && "Vertex check failed: data_long!"); assert( fabs(data_point[0] - viennagrid::point(*vit)[0]) < 1e-4 && fabs(data_point[1] - viennagrid::point(*vit)[1]) < 1e-4 && "Vertex check failed: data_point!"); } CellRange cells(mesh); for (CellIterator cit = cells.begin(); cit != cells.end(); ++cit) { double data_double = vtk_cell_double_accessor(*cit); long data_long = static_cast<long>(vtk_cell_long_accessor(*cit)); std::vector<double> data_point = vtk_cell_vector_accessor(*cit); assert( fabs(data_double - viennagrid::centroid(*cit)[0]) < 1e-4 && "Cell check failed: data_double!"); assert( (data_long == cit->id().get()) && "Cell check failed: data_long!"); assert( fabs(data_point[0] - viennagrid::centroid(*cit)[0]) < 1e-4 && fabs(data_point[1] - viennagrid::centroid(*cit)[1]) < 1e-4 && "Cell check failed: data_point!"); } //test writers: viennagrid::io::vtk_writer<MeshType> my_vtk_writer; viennagrid::io::add_scalar_data_on_vertices(my_vtk_writer, vtk_vertex_double_accessor, "data_double"); viennagrid::io::add_scalar_data_on_vertices(my_vtk_writer, vtk_vertex_long_accessor, "data_long"); viennagrid::io::add_vector_data_on_vertices(my_vtk_writer, vtk_vertex_vector_accessor, "data_point"); viennagrid::io::add_scalar_data_on_cells(my_vtk_writer, vtk_cell_double_accessor, "data_double"); viennagrid::io::add_scalar_data_on_cells(my_vtk_writer, vtk_cell_long_accessor, "data_long"); viennagrid::io::add_vector_data_on_cells(my_vtk_writer, vtk_cell_vector_accessor, "data_point"); my_vtk_writer(mesh, segmentation, outfile); viennagrid::io::opendx_writer<MeshType> my_dx_writer; my_dx_writer(mesh, outfile + ".odx"); }
int main() { typedef viennagrid::tetrahedral_3d_mesh MeshType; typedef viennagrid::tetrahedral_3d_segmentation SegmentationType; std::cout << "* main(): Creating device..." << std::endl; MeshType mesh; SegmentationType segmentation(mesh); std::string path = "../examples/data/"; //create device: try { viennagrid::io::netgen_reader my_netgen_reader; my_netgen_reader(mesh, segmentation, path + "cube48.mesh"); } catch (...) { std::cerr << "File-Reader failed. Aborting program..." << std::endl; return EXIT_FAILURE; } typedef viennagrid::result_of::vertex<MeshType>::type VertexType; typedef viennagrid::result_of::line<MeshType>::type EdgeType; typedef viennagrid::result_of::cell<MeshType>::type CellType; typedef viennagrid::result_of::const_cell_handle<MeshType>::type ConstCellHandleType; std::deque<double> interface_areas; std::deque< viennagrid::result_of::voronoi_cell_contribution<ConstCellHandleType>::type > interface_contributions; std::deque<double> vertex_box_volumes; std::deque< viennagrid::result_of::voronoi_cell_contribution<ConstCellHandleType>::type > vertex_box_volume_contributions; std::deque<double> edge_box_volumes; std::deque< viennagrid::result_of::voronoi_cell_contribution<ConstCellHandleType>::type > edge_box_volume_contributions; //set up dual grid info: viennagrid::apply_voronoi<CellType>( mesh, viennagrid::make_field<EdgeType>(interface_areas), viennagrid::make_field<EdgeType>(interface_contributions), viennagrid::make_field<VertexType>(vertex_box_volumes), viennagrid::make_field<VertexType>(vertex_box_volume_contributions), viennagrid::make_field<EdgeType>(edge_box_volumes), viennagrid::make_field<EdgeType>(edge_box_volume_contributions) ); //output results: output_voronoi_info(mesh, viennagrid::make_field<VertexType>(vertex_box_volumes), viennagrid::make_field<VertexType>(vertex_box_volume_contributions), viennagrid::make_field<EdgeType>(interface_areas), viennagrid::make_field<EdgeType>(interface_contributions)); std::cout << std::endl; std::cout << viennagrid::cells(mesh)[0] << std::endl; std::cout << std::endl; std::cout << "Circumcenter of first cell: " << viennagrid::circumcenter(viennagrid::cells(mesh)[0]) << std::endl; // Check Voronoi volumes: voronoi_volume_check(mesh, viennagrid::make_field<VertexType>(vertex_box_volumes), viennagrid::make_field<VertexType>(vertex_box_volume_contributions), viennagrid::make_field<EdgeType>(edge_box_volume_contributions) ); //write to vtk: viennagrid::io::vtk_writer<MeshType> my_vtk_writer; my_vtk_writer(mesh, segmentation, "voronoi_tet"); std::cout << "*******************************" << std::endl; std::cout << "* Test finished successfully! *" << std::endl; std::cout << "*******************************" << std::endl; return EXIT_SUCCESS; }
int main() { typedef viennagrid::triangular_3d_mesh MeshType; typedef viennagrid::result_of::vertex_handle< MeshType >::type VertexHandleType; typedef viennagrid::result_of::vertex< MeshType >::type VertexType; typedef viennagrid::result_of::triangle_handle< MeshType >::type TriangleHandleType; typedef viennagrid::result_of::triangle< MeshType >::type TriangleType; // triangular hull segmentation, each triangular face has a segment for its positive orientation and its negative orientation typedef viennagrid::result_of::oriented_3d_hull_segmentation<MeshType>::type SegmentationType; // defining the segment type and segment id type typedef viennagrid::result_of::segment_handle<SegmentationType>::type SegmentHandleType; typedef viennagrid::result_of::segment_id<SegmentationType>::type SegmentIDType; MeshType mesh; SegmentationType segmentation(mesh); // create some vertices VertexHandleType vh0 = viennagrid::make_vertex( mesh ); VertexHandleType vh1 = viennagrid::make_vertex( mesh ); VertexHandleType vh2 = viennagrid::make_vertex( mesh ); VertexHandleType vh3 = viennagrid::make_vertex( mesh ); VertexHandleType vh4 = viennagrid::make_vertex( mesh ); VertexHandleType vh5 = viennagrid::make_vertex( mesh ); // create some triangles TriangleHandleType th0 = viennagrid::make_triangle( mesh, vh0, vh1, vh2 ); TriangleHandleType th1 = viennagrid::make_triangle( mesh, vh1, vh2, vh3 ); TriangleHandleType th2 = viennagrid::make_triangle( mesh, vh3, vh4, vh5 ); /*TriangleHandleType th3 =*/ viennagrid::make_triangle( mesh, vh0, vh4, vh5 ); // create a segment, segment id will be 0 because of first segment SegmentHandleType seg0 = segmentation.make_segment(); // create a segment, segment id will be 4 because explicit segment_id SegmentHandleType seg1 = segmentation[ SegmentIDType(4) ]; // create a segment, segment id will be 5 because highest segment id was 4 SegmentHandleType seg2 = segmentation.make_segment(); // create some other segments (ID would be 6, 7, 8) SegmentHandleType seg3 = segmentation.make_segment(); SegmentHandleType seg4 = segmentation.make_segment(); SegmentHandleType seg5 = segmentation.make_segment(); // print the segments std::cout << "Segments in Segmentation" << std::endl; for ( SegmentationType::iterator it = segmentation.begin(); it != segmentation.end(); ++it) std::cout << (*it).id() << std::endl; std::cout << std::endl; TriangleType & tri0 = viennagrid::dereference_handle(mesh, th0); TriangleType & tri1 = viennagrid::dereference_handle(mesh, th1); TriangleType & tri2 = viennagrid::dereference_handle(mesh, th2); VertexType & v0 = viennagrid::dereference_handle(mesh, vh0); // add triangle tr0 to seg0 std::cout << "Adding element tri0 to seg0" << std::endl; viennagrid::add( seg0, tri0 ); std::cout << "Adding element tri0 to seg1" << std::endl; viennagrid::add( seg1, tri0 ); std::cout << "Triangle 0 in Segment 0: " << viennagrid::is_in_segment( seg0, tri0 ) << std::endl; std::cout << "Vertex 0 in Segment 0: " << viennagrid::is_in_segment( seg0, v0 ) << std::endl; std::cout << "Numer of cells in segmentation: " << viennagrid::cells( segmentation ).size() << std::endl; std::cout << "Erasing element tri0 from seg0" << std::endl; // erase triangle tr0 from seg0 viennagrid::erase( seg0, tri0 ); std::cout << "Triangle 0 in Segment 0: " << viennagrid::is_in_segment( seg0, tri0 ) << std::endl; std::cout << "Vertex 0 in Segment 0: " << viennagrid::is_in_segment( seg0, v0 ) << std::endl; std::cout << "Numer of cells in segmentation: " << viennagrid::cells( segmentation ).size() << std::endl; std::cout << "Erasing element tri0 from seg1" << std::endl; // erase triangle tr0 from seg0 viennagrid::erase( seg1, tri0 ); std::cout << "Triangle 0 in Segment 0: " << viennagrid::is_in_segment( seg0, tri0 ) << std::endl; std::cout << "Vertex 0 in Segment 0: " << viennagrid::is_in_segment( seg0, v0 ) << std::endl; std::cout << "Numer of cells in segmentation: " << viennagrid::cells( segmentation ).size() << std::endl; // add triangle tr0 to seg0, tri1 to seg1, tri2 to seg2 viennagrid::add( seg0, tri0 ); viennagrid::add( seg1, tri1 ); viennagrid::add( seg2, tri2 ); viennagrid::add( seg3, tri0 ); viennagrid::add( seg4, tri0 ); viennagrid::add( seg5, tri0 ); // print all cells of the mesh (should be four) typedef viennagrid::result_of::cell_range<MeshType>::type MeshCellRange; typedef viennagrid::result_of::iterator<MeshCellRange>::type MeshCellIterator; std::cout << std::endl; std::cout << "All cells in the mesh:" << std::endl; MeshCellRange mesh_cells( mesh ); for (MeshCellIterator cit = mesh_cells.begin(); cit != mesh_cells.end(); ++cit) std::cout << *cit << std::endl; std::cout << std::endl; // print all cells of the segmentation (should be three) typedef viennagrid::result_of::cell_range<SegmentationType>::type SegmentationCellRange; typedef viennagrid::result_of::iterator<SegmentationCellRange>::type SegmentationCellIterator; std::cout << std::endl; std::cout << "All cells in the segmentation:" << std::endl; SegmentationCellRange segmentation_cells( segmentation ); for (SegmentationCellIterator cit = segmentation_cells.begin(); cit != segmentation_cells.end(); ++cit) std::cout << *cit << std::endl; std::cout << std::endl; typedef viennagrid::result_of::segment_id_range<SegmentationType, TriangleType>::type SegmentIDRange; SegmentIDRange segment_ids = viennagrid::segment_ids( segmentation, tri0 ); std::cout << "Segments for tr0:" << std::endl; for (SegmentIDRange::iterator it = segment_ids.begin(); it != segment_ids.end(); ++it) std::cout << *it << std::endl; // setting and querying additional segment information for tri0 std::cout << "Triangle 0 in Segment 0: " << *viennagrid::segment_element_info( seg0, tri0 ) << std::endl; *viennagrid::segment_element_info( seg0, tri0 ) = true; std::cout << "Triangle 0 in Segment 0: " << *viennagrid::segment_element_info( seg0, tri0 ) << std::endl; std::cout << std::endl; // printing all triangles from all segments typedef viennagrid::result_of::element_range< SegmentHandleType, viennagrid::triangle_tag >::type RangeType; std::cout << "Triangles of Segment 0" << std::endl; RangeType range( seg0 ); for (RangeType::iterator it = range.begin(); it != range.end(); ++it) std::cout << *it << std::endl; std::cout << "Triangles of Segment 1" << std::endl; range = RangeType( seg1 ); for (RangeType::iterator it = range.begin(); it != range.end(); ++it) std::cout << *it << std::endl; std::cout << "Triangles of Segment 2" << std::endl; range = RangeType( seg2 ); for (RangeType::iterator it = range.begin(); it != range.end(); ++it) std::cout << *it << std::endl; std::cout << std::endl; // Adding additional triangles to seg2 and printing them viennagrid::make_triangle( seg2, vh1, vh4, vh5 ); viennagrid::make_triangle( seg2, vh2, vh4, vh5 ); std::cout << "Triangles of Segment 2, added 2 additional" << std::endl; range = RangeType( seg2 ); for (RangeType::iterator it = range.begin(); it != range.end(); ++it) std::cout << *it << std::endl; std::cout << std::endl; // Printing vertices from seg2, each vertex should only be printed once typedef viennagrid::result_of::vertex_range<SegmentHandleType>::type vertex_range; std::cout << "Vertices of Segment 2" << std::endl; vertex_range vertices( seg2 ); for (vertex_range::iterator it = vertices.begin(); it != vertices.end(); ++it) std::cout << *it << std::endl; std::cout << "-----------------------------------------------" << std::endl; std::cout << " \\o/ Tutorial finished successfully! \\o/ " << std::endl; std::cout << "-----------------------------------------------" << std::endl; return EXIT_SUCCESS; }
int main(int, char**) { std::map < std::string, std::vector< std::vector<std::complex<double> > > > data_map = parser("database_kmeans.txt"); std::vector< cv::Mat > vect_frames; cv::Mat frame; cv::Mat frame_conv; std::vector < std::vector< cv::Point > > contours; int c_max = 10; std::vector < std::vector<std::complex<double> > > vect_coeff; /* frame = cv::imread("/home/ghezali/Documents/supelec/sir/tl_gesture_command/Base_de_donnees/Vers_la_droite/2015-10-20-094225_138.jpg"); vect_frames.push_back(frame); frame = cv::imread("/home/ghezali/Documents/supelec/sir/tl_gesture_command/Base_de_donnees/Vers_la_droite/2015-10-20-094225_58.jpg"); vect_frames.push_back(frame); */ frame = cv::imread("/home/ghezali/Documents/supelec/sir/tl_gesture_command/database/2016-01-27-150243_1.jpg"); vect_frames.push_back(frame); frame = cv::imread("/home/ghezali/Documents/supelec/sir/tl_gesture_command/database/2016-01-27-150430_8.jpg"); vect_frames.push_back(frame); frame = cv::imread("/home/ghezali/Documents/supelec/sir/tl_gesture_command/database/2016-01-27-150649_4.jpg"); vect_frames.push_back(frame); frame = cv::imread("/home/ghezali/Documents/supelec/sir/tl_gesture_command/database/2016-01-27-150833_8.jpg"); vect_frames.push_back(frame); frame = cv::imread("/home/ghezali/Documents/supelec/sir/tl_gesture_command/database/2016-01-27-150243_10.jpg"); vect_frames.push_back(frame); frame = cv::imread("/home/ghezali/Documents/supelec/sir/tl_gesture_command/database/2016-01-27-150243_12.jpg"); vect_frames.push_back(frame); frame = cv::imread("/home/ghezali/Documents/supelec/sir/tl_gesture_command/database/2016-01-27-150243_14.jpg"); vect_frames.push_back(frame); frame = cv::imread("/home/ghezali/Documents/supelec/sir/tl_gesture_command/database/2016-01-27-150243_16.jpg"); vect_frames.push_back(frame); frame = cv::imread("/home/ghezali/Documents/supelec/sir/tl_gesture_command/database/2016-01-27-150243_18.jpg"); vect_frames.push_back(frame); frame = cv::imread("/home/ghezali/Documents/supelec/sir/tl_gesture_command/database/2016-01-27-150243_20.jpg"); vect_frames.push_back(frame); for (auto& it : vect_frames){ segmentation(it); cv::cvtColor(it, frame_conv, CV_RGB2GRAY); cv::findContours(frame_conv, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); contours = find_longest_contour(contours); vect_coeff.push_back(descripteur_fourier_normal(contours, c_max)); } for (auto& it1 : data_map){ std::cout << it1.first << std::endl; for (auto& it2 : it1.second[0]){ std::cout << it2 << std::endl; } } std::vector <std::string> final_class_vect; std::string classe = "7"; double min_dist = std::numeric_limits<double>::max(); double dist = 0; int compt = 1; for (auto& it1 : vect_coeff){ std::cout << "frame " << compt << std::endl; compt++; for (auto& it : data_map){ dist = get_distance(it1, it.second[0]); std::cout << "distance = " << dist << std::endl; if( dist < min_dist){ min_dist = dist; classe = it.first; } } final_class_vect.push_back(classe); classe = "7"; min_dist = std::numeric_limits<int>::max(); dist = 0; } for (auto& it3 : final_class_vect){ std::cout << "final class : " << it3 << std::endl; } }
int main() { typedef viennagrid::triangular_2d_mesh MeshType; typedef viennagrid::result_of::segmentation<MeshType>::type SegmentationType; typedef viennamath::function_symbol FunctionSymbol; typedef viennamath::equation Equation; // // Create a mesh from file // MeshType mesh; SegmentationType segmentation(mesh); try { viennagrid::io::netgen_reader my_reader; my_reader(mesh, segmentation, "../examples/data/nin2d.mesh"); } catch (...) { std::cerr << "File-Reader failed. Aborting program..." << std::endl; return EXIT_FAILURE; } viennagrid::scale(mesh, 1e-9); // scale to nanometer // // Create PDE solver instance: // viennafvm::problem_description<MeshType> problem_desc(mesh); // // Assign doping and set initial values // init_quantities(segmentation, problem_desc); // // Setting boundary information on mesh (see mosfet.in2d for segment indices) // FunctionSymbol psi(0); // potential, using id=0 FunctionSymbol permittivity(1); // potential, using id=0 // // Specify PDEs: // // here is all the fun: specify DD system Equation laplace_eq = viennamath::make_equation( viennamath::div(permittivity * viennamath::grad(psi)), /* = */ 0); viennafvm::linear_pde_system<> pde_system; pde_system.add_pde(laplace_eq, psi); // equation and associated quantity pde_system.is_linear(true); // // Setup Linear Solver // viennafvm::linsolv::viennacl linear_solver; // // Run the solver: // viennafvm::pde_solver my_solver; my_solver(problem_desc, pde_system, linear_solver); // weird math happening in here ;-) // // Writing all solution variables back to mesh // viennafvm::io::write_solution_to_VTK_file(problem_desc.quantities(), "nin_2d_laplace", mesh, segmentation); std::cout << "*************************************" << std::endl; std::cout << "* Simulation finished successfully! *" << std::endl; std::cout << "*************************************" << std::endl; return EXIT_SUCCESS; }
int main() { typedef viennagrid::tetrahedral_3d_mesh MeshType; typedef viennagrid::result_of::segmentation<MeshType>::type SegmentationType; typedef viennagrid::result_of::point<MeshType>::type PointType; typedef viennagrid::result_of::cell<MeshType>::type CellType; typedef viennagrid::result_of::edge<MeshType>::type EdgeType; typedef viennagrid::result_of::vertex<MeshType>::type VertexType; typedef viennagrid::result_of::vertex_range<MeshType>::type VertexRange; std::cout << "------------------------------------------------------------ " << std::endl; std::cout << "-- ViennaGrid tutorial: Algorithms on points and elements -- " << std::endl; std::cout << "------------------------------------------------------------ " << std::endl; std::cout << std::endl; MeshType mesh; SegmentationType segmentation(mesh); // // Read mesh from Netgen file // try { viennagrid::io::netgen_reader reader; reader(mesh, segmentation, "../../examples/data/cube48.mesh"); } catch (std::exception & e) { std::cout << "Error reading Netgen mesh file: " << std::endl; std::cout << e.what() << std::endl; return EXIT_FAILURE; } // // Part 1: Point-based algorithms: // // Extract the first four points of the mesh: VertexRange vertices(mesh); PointType const & p0 = viennagrid::point(mesh, vertices[0]); PointType const & p1 = viennagrid::point(mesh, vertices[1]); PointType const & p2 = viennagrid::point(mesh, vertices[2]); PointType const & p3 = viennagrid::point(mesh, vertices[3]); std::cout << "Point p0: " << p0 << std::endl; std::cout << "Point p1: " << p1 << std::endl; std::cout << "Point p2: " << p2 << std::endl; std::cout << "Point p3: " << p3 << std::endl; // Run a few algorithms: std::cout << "Cross-product of p1 and p2: " << viennagrid::cross_prod(p1, p2) << std::endl; std::cout << "Inner product of p1 and p2: " << viennagrid::inner_prod(p1, p2) << std::endl; std::cout << "1-Norm of p2: " << viennagrid::norm_1(p2) << std::endl; std::cout << "2-Norm of p2: " << viennagrid::norm_2(p2) << std::endl; std::cout << "Inf-Norm of p2: " << viennagrid::norm_inf(p2) << std::endl; std::cout << "Length of line [p0, p1]: " << viennagrid::spanned_volume(p0, p1) << std::endl; std::cout << "Area of triangle [p0, p1, p2]: " << viennagrid::spanned_volume(p0, p1, p2) << std::endl; std::cout << "Volume of tetrahedron [p0, p1, p2, p3]: " << viennagrid::spanned_volume(p0, p1, p2, p3) << std::endl; std::cout << std::endl << "--------------------------------" << std::endl << std::endl; // // Part 2: Cell-based algorithms: // // Extract first cell from mesh: CellType const & cell = viennagrid::cells(mesh)[0]; std::cout << "Cell: " << std::endl; std::cout << cell << std::endl; // Run algorithms: std::cout << "Centroid of cell: " << viennagrid::centroid(cell) << std::endl; std::cout << "Circumcenter of cell: " << viennagrid::circumcenter(cell) << std::endl; std::cout << "Surface of cell: " << viennagrid::surface(cell) << std::endl; std::cout << "Volume of cell: " << viennagrid::volume(cell) << std::endl; std::cout << std::endl; std::cout << "Volume of mesh: " << viennagrid::volume(mesh) << std::endl; std::cout << "Surface of mesh: " << viennagrid::surface(mesh) << std::endl; // // Part 3: Mesh-based algorithms (except interfaces. Refer to the multi-segment tutorial multi_segment.cpp) // // Write Voronoi info to default ViennaData keys: typedef viennagrid::result_of::const_cell_handle<MeshType>::type ConstCellHandleType; // Defining container for storing voronoi information std::deque<double> interface_areas; std::deque< viennagrid::result_of::voronoi_cell_contribution<ConstCellHandleType>::type > interface_contributions; std::deque<double> vertex_box_volumes; std::deque< viennagrid::result_of::voronoi_cell_contribution<ConstCellHandleType>::type > vertex_box_volume_contributions; std::deque<double> edge_box_volumes; std::deque< viennagrid::result_of::voronoi_cell_contribution<ConstCellHandleType>::type > edge_box_volume_contributions; viennagrid::apply_voronoi<CellType>( mesh, viennagrid::make_field<EdgeType>(interface_areas), viennagrid::make_field<EdgeType>(interface_contributions), viennagrid::make_field<VertexType>(vertex_box_volumes), viennagrid::make_field<VertexType>(vertex_box_volume_contributions), viennagrid::make_field<EdgeType>(edge_box_volumes), viennagrid::make_field<EdgeType>(edge_box_volume_contributions) ); // Write Voronoi info again, this time using custom keys std::cout << "Voronoi box volume at first vertex: " << viennagrid::make_field<VertexType>(vertex_box_volumes)( vertices[0] ) << std::endl; // // Refine mesh uniformly: MeshType uniformly_refined_mesh; viennagrid::cell_refine_uniformly(mesh, uniformly_refined_mesh); { viennagrid::io::vtk_writer<MeshType> writer; writer(uniformly_refined_mesh, "uniform_refinement"); } // // Refine only specific cells: MeshType adaptively_refined_mesh; // Define a container which stores the flags, in this case we want an std::map as underlying container typedef viennagrid::result_of::accessor_container< CellType, bool, viennagrid::std_map_tag >::type CellRefinementContainerType; CellRefinementContainerType cell_refinement_flag; // define an field on this container for easy access with elements viennagrid::result_of::field< CellRefinementContainerType, CellType >::type cell_refinement_field(cell_refinement_flag); cell_refinement_field( viennagrid::cells(mesh)[0] ) = true; cell_refinement_field( viennagrid::cells(mesh)[3] ) = true; cell_refinement_field( viennagrid::cells(mesh)[8] ) = true; // refining the mesh using the field representing the marked cells viennagrid::cell_refine(mesh, adaptively_refined_mesh, cell_refinement_field); { viennagrid::io::vtk_writer<MeshType> writer; writer(adaptively_refined_mesh, "adaptively_refinement"); } // // Get boundary information of first vertex with respect to the full mesh: for (VertexRange::iterator it = vertices.begin(); it != vertices.end(); ++it) std::cout << *it << " " << viennagrid::point(mesh, *it) << " " << viennagrid::is_boundary(mesh, *it) //second argument is the enclosing complex (either a mesh or a segment) << std::endl << std::endl; std::cout << "-----------------------------------------------" << std::endl; std::cout << " \\o/ Tutorial finished successfully! \\o/ " << std::endl; std::cout << "-----------------------------------------------" << std::endl; return EXIT_SUCCESS; }
int main() { typedef double numeric_type; typedef viennagrid::tetrahedral_3d_mesh DomainType; typedef viennagrid::result_of::segmentation<DomainType>::type SegmentationType; typedef viennagrid::result_of::cell_tag<DomainType>::type CellTag; typedef viennagrid::result_of::element<DomainType, CellTag>::type CellType; typedef viennadata::storage<> StorageType; typedef viennagrid::result_of::element_range<DomainType, CellTag>::type CellContainer; typedef viennagrid::result_of::iterator<CellContainer>::type CellIterator; typedef viennagrid::result_of::vertex_range<CellType>::type VertexOnCellContainer; typedef viennagrid::result_of::iterator<VertexOnCellContainer>::type VertexOnCellIterator; typedef viennamath::function_symbol FunctionSymbol; typedef viennamath::equation Equation; typedef viennafvm::boundary_key BoundaryKey; // // Create a domain from file // DomainType domain; SegmentationType segmentation(domain); StorageType storage; try { viennagrid::io::netgen_reader my_netgen_reader; my_netgen_reader(domain, segmentation, "../examples/data/cube3072.mesh"); } catch (...) { std::cerr << "File-Reader failed. Aborting program..." << std::endl; return EXIT_FAILURE; } // Specify Poisson equation: viennafvm::ncell_quantity<CellType, viennamath::expr::interface_type> permittivity; permittivity.wrap_constant( storage, permittivity_key() ); FunctionSymbol u(0, viennamath::unknown_tag<>()); //an unknown function used for PDE specification Equation poisson_eq = viennamath::make_equation( viennamath::div(permittivity * viennamath::grad(u)), -1); // \Delta u = -1 // // Setting boundary information on domain (this should come from device specification) // //setting some boundary flags: viennagrid::result_of::default_point_accessor<DomainType>::type point_accessor = viennagrid::default_point_accessor(domain); viennadata::result_of::accessor<StorageType, permittivity_key, double, CellType>::type permittivity_accessor = viennadata::make_accessor(storage, permittivity_key()); viennadata::result_of::accessor<StorageType, BoundaryKey, bool, CellType>::type boundary_accessor = viennadata::make_accessor(storage, BoundaryKey( u.id() )); CellContainer cells(domain); for (CellIterator cit = cells.begin(); cit != cells.end(); ++cit) { bool cell_on_boundary = false; // write dummy permittivity to cells: permittivity_accessor(*cit) = 1.0; VertexOnCellContainer vertices(*cit); for (VertexOnCellIterator vit = vertices.begin(); vit != vertices.end(); ++vit) { //boundary for first equation: Homogeneous Dirichlet everywhere if (point_accessor(*vit)[0] == 0.0 || point_accessor(*vit)[0] == 1.0 || point_accessor(*vit)[2] == 0.0 || point_accessor(*vit)[2] == 1.0 ) { cell_on_boundary = true; break; } } boundary_accessor(*cit) = cell_on_boundary; } // // Setup Linear Solver // viennafvm::linsolv::viennacl linear_solver; // // Create PDE solver instance // viennafvm::pde_solver<> pde_solver; // // Pass system to solver: // pde_solver(viennafvm::make_linear_pde_system(poisson_eq, u), // PDE with associated unknown domain, storage, linear_solver); // // Writing solution back to domain (discussion about proper way of returning a solution required...) // viennafvm::io::write_solution_to_VTK_file(pde_solver.result(), "poisson_3d", domain, segmentation, storage, 0); std::cout << "*****************************************" << std::endl; std::cout << "* Poisson solver finished successfully! *" << std::endl; std::cout << "*****************************************" << std::endl; return EXIT_SUCCESS; }
void test(ReaderType & my_reader, std::string const & infile, std::string const & outfile) { typedef typename viennagrid::result_of::segmentation<MeshType>::type SegmentationType; typedef typename viennagrid::result_of::vertex<MeshType>::type VertexType; typedef typename viennagrid::result_of::cell<MeshType>::type CellType; typedef typename viennagrid::result_of::vertex_range<MeshType>::type VertexContainer; typedef typename viennagrid::result_of::iterator<VertexContainer>::type VertexIterator; typedef typename viennagrid::result_of::cell_range<MeshType>::type CellRange; typedef typename viennagrid::result_of::iterator<CellRange>::type CellIterator; MeshType mesh; SegmentationType segmentation(mesh); try { my_reader(mesh, segmentation, infile); } catch (std::exception const & ex) { std::cerr << ex.what() << std::endl; std::cerr << "File-Reader failed. Aborting program..." << std::endl; exit(EXIT_FAILURE); } std::vector<double> vtk_vertex_double_data; std::vector<double> vtk_vertex_long_data; std::vector< std::vector<double> > vtk_vertex_vector_data; typename viennagrid::result_of::accessor< std::vector<double>, VertexType >::type vtk_vertex_double_accessor( vtk_vertex_double_data ); typename viennagrid::result_of::accessor< std::vector<double>, VertexType >::type vtk_vertex_long_accessor( vtk_vertex_long_data ); typename viennagrid::result_of::accessor< std::vector< std::vector<double> >, VertexType >::type vtk_vertex_vector_accessor( vtk_vertex_vector_data ); //write some dummy data: VertexContainer vertices(mesh); for (VertexIterator vit = vertices.begin(); vit != vertices.end(); ++vit) { vtk_vertex_double_accessor(*vit) = viennagrid::point(*vit)[0]; vtk_vertex_long_accessor(*vit) = vit->id().get(); vtk_vertex_vector_accessor(*vit).resize(3); vtk_vertex_vector_accessor(*vit)[0] = viennagrid::point(*vit)[0]; vtk_vertex_vector_accessor(*vit)[1] = viennagrid::point(*vit)[1]; } std::vector<double> vtk_cell_double_data; std::vector<double> vtk_cell_long_data; std::vector< std::vector<double> > vtk_cell_vector_data; typename viennagrid::result_of::accessor< std::vector<double>, CellType >::type vtk_cell_double_accessor( vtk_cell_double_data ); typename viennagrid::result_of::accessor< std::vector<double>, CellType >::type vtk_cell_long_accessor( vtk_cell_long_data ); typename viennagrid::result_of::accessor< std::vector< std::vector<double> >, CellType >::type vtk_cell_vector_accessor( vtk_cell_vector_data ); int index = 0; CellRange cells(mesh); for (CellIterator cit = cells.begin(); cit != cells.end(); ++cit, ++index) { vtk_cell_double_accessor(*cit) = viennagrid::centroid(*cit)[0]; vtk_cell_long_accessor(*cit) = cit->id().get(); vtk_cell_vector_accessor(*cit).resize(3); vtk_cell_vector_accessor(*cit)[0] = viennagrid::centroid(*cit)[0]; vtk_cell_vector_accessor(*cit)[1] = viennagrid::centroid(*cit)[1]; } //test writers: viennagrid::io::vtk_writer<MeshType> my_vtk_writer; viennagrid::io::add_scalar_data_on_vertices(my_vtk_writer, vtk_vertex_double_accessor, "data_double"); viennagrid::io::add_scalar_data_on_vertices(my_vtk_writer, vtk_vertex_long_accessor, "data_long"); viennagrid::io::add_vector_data_on_vertices(my_vtk_writer, vtk_vertex_vector_accessor, "data_point"); viennagrid::io::add_scalar_data_on_cells(my_vtk_writer, vtk_cell_double_accessor, "data_double"); viennagrid::io::add_scalar_data_on_cells(my_vtk_writer, vtk_cell_long_accessor, "data_long"); viennagrid::io::add_vector_data_on_cells(my_vtk_writer, vtk_cell_vector_accessor, "data_point"); my_vtk_writer(mesh, segmentation, outfile); viennagrid::io::opendx_writer<MeshType> my_dx_writer; my_dx_writer(mesh, outfile + ".odx"); }
int main(int, char**) { cv::VideoCapture cap(1); // open the default camera if(!cap.isOpened()){ // check if we succeeded std::cout << "Cannot open the camera ! " << std::endl; return -1; } cv::Mat frame; // Matrice dans laquelle on va récupérer l'image while(true) { cap >> frame; segmentation(frame); cv::namedWindow("images",CV_WINDOW_AUTOSIZE); cv::imshow("images", frame); //cv::imwrite("/usr/users/promo2016/pierrard_reg/TL/test.png", frame); std::vector<std::vector<cv::Point>> contours; // variable dans laquelle on récupèrera la liste des contours cv::Mat frame_conv; // variable qui va contenir l'image en nuances de gris cv::cvtColor(frame, frame_conv, CV_RGB2GRAY); // conversion de l'image courante en couleur en niveaux de gris cv::findContours(frame_conv, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); cv::Scalar color( rand()&255, rand()&255, rand()&255 ); // définition d'une couleur tirée aléatoirement cv::Mat dst = cv::Mat::zeros(frame.rows, frame.cols, CV_8UC3); // Matrice qui va afficher le contour le plus long if (contours.size() != 0) { contours = find_longest_contour(contours); cv::drawContours(dst, contours, -1, color); std::vector<std::complex<double>> coeff = descripteur_fourier_normal(contours, 10); double scale = 0.25 * std::min(frame.cols, frame.rows); // coefficient multiplicateur permettant d'obtenir des valeurs plus espacées des coordonnées des points std::vector<std::vector<cv::Point>> contfil = reconstruction(coeff, 200, 10, z_moyen(contours), scale); // on récupère les points du contour reconstruit cv::Mat dst2 = cv::Mat::zeros(frame.rows, frame.cols, CV_8UC3); // Matrice dans laquelle on affichera le contour reconstruit cv::drawContours(dst2, contfil, -1, color); cv::namedWindow("contours",CV_WINDOW_AUTOSIZE); cv::imshow("contours", dst); cv::namedWindow("reconstruction",CV_WINDOW_AUTOSIZE); cv::imshow("reconstruction", dst2); } if(cv::waitKey(30) >= 0) break; } /* int c_max = 10; std::map< std::string, std::vector< std::vector< std::complex<double> > > > database = fourier_descriptor_extraction(c_max); for (auto& it : database) { std::cout << it.first << " : " << std::endl;; for (auto& it2 : it.second[0]) { std::cout << it2 << ", "; } std::cout << std::endl; }*/ return 0; }
int main( int argc, char **argv) { char fname[256]; char nom[256]; struct image *nf; Fort_int lfmt[9]; unsigned char *buf , *buf2; int sb = 0, i, j,z; struct pt_x* pt; struct pt_x *res; struct pt_x * tabPt_x; char reponse; float hr , hs; hr = 20; hs = 20; /* Initialisation */ inr_init( argc, argv, version, usage, detail); /* Lecture des options */ infileopt( fname); igetopt1("-hs", "%f", &hs); igetopt1("-hr", "%f", &hr); igetopt1("-max","%d", &max); igetopt1("-v","%d",&VOSIN); igetopt1("-n","%d",&noyau); igetopt1("-m","%d",&mode); igetopt1("-d","%d",&debug); outfileopt(nom); /*affichage the options */ fprintf(stderr, "=============OPTIONS===========\n"); fprintf(stderr, "hr = %f hs = %f\n",hr,hs); fprintf(stderr, "Voisnage = %d\n",VOSIN); if(noyau == 1){ fprintf(stderr, "Noyau = gaussian\n"); }else{ fprintf(stderr, "Noyau = epankovic\n"); } if(mode == 1){ fprintf(stderr, "Mode = segmentation\n"); }else{ fprintf(stderr, "Mode = debruit\n"); } printf("Image src = %s\n",fname); printf("Image target = %s\n",nom); printf("Mode debug = %d\n",debug); fprintf(stderr, "===============================\n"); fprintf(stderr, "would you like to continue the execution with current options ? (y,n)\n"); scanf("%c",&reponse); if(reponse!='y'){ return 0; } fprintf(stderr, "Start of execution\n"); /* Ouverture et lecture des images */ nf = image_(fname, "e", "", lfmt); /* verification du format */ if(TYPE == FIXE && BSIZE==1){ /* allocation memoire adequat */ buf = (unsigned char*)i_malloc( NDIMX * NDIMY* NDIMV *sizeof(unsigned char)); /* cree tableau de pt_x */ tabPt_x = malloc(NDIMX* NDIMY* NDIMV *sizeof(pt_x)); /* lecture image */ c_lect( nf, NDIMY, buf); }else{ imerror( 6, "codage non conforme\n"); } /* Remplir de Struct Special */ if(NDIMV == 1){ remplir_basic(buf,tabPt_x,NDIMX,NDIMY); } if(NDIMV == 3){ remplir_rgb(buf,tabPt_x,NDIMX,NDIMY); } /* Traitement */ /*debruit*/ buf2 = (unsigned char*)i_malloc( NDIMX * NDIMY*NDIMV*sizeof(unsigned char)); if(mode == 0){ if(NDIMV == 1){ debruit_basic(tabPt_x,buf2,hs,hr,1,NDIMX,NDIMY); }else{ debruit_rgb(tabPt_x,buf2,hs,hr,1,NDIMX,NDIMY); } }else{ segmentation(tabPt_x , buf2 , hs , hr , 0.1 , NDIMX, NDIMY); } /*sauvgarde*/ printf("sortir \n"); nf = c_image(nom,"c","",lfmt); c_ecr(nf,DIMY,buf2); /* fermeture image */ fermnf_( &nf); //free(&his); i_Free((void*)&buf); i_Free((void*)&buf2); return 0; }
bool change_detection (tms_msg_ss::ods_furniture::Request &req, tms_msg_ss::ods_furniture::Response &res) { //*************************** // local variable declaration //*************************** pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud1 (new pcl::PointCloud<pcl::PointXYZRGB>); pcl::PointCloud<pcl::PointXYZRGB>::Ptr model (new pcl::PointCloud<pcl::PointXYZRGB>); std::cout << mkdir("/tmp/tms_ss_ods", S_IRUSR | S_IWUSR | S_IXUSR) << std::endl; std::cout << mkdir("/tmp/tms_ss_ods/ods_change_detection", S_IRUSR | S_IWUSR | S_IXUSR) << std::endl; std::cout << mkdir("/tmp/tms_ss_ods/ods_change_detection/table", S_IRUSR | S_IWUSR | S_IXUSR) << std::endl; //*************************** // capture kinect data //*************************** tms_msg_ss::ods_pcd srv; srv.request.id = 3; if(commander_to_kinect_capture.call(srv)){ pcl::fromROSMsg (srv.response.cloud, *cloud1); } pcl::io::savePCDFile("/tmp/tms_ss_ods/ods_change_detection/table/input.pcd", *cloud1); //pcl::fromROSMsg (req.model, *model); pcl::io::loadPCDFile("/tmp/tms_ss_ods/ods_change_detection/table/input.pcd", *cloud1); TABLE = req.id; if(TABLE == 1) pcl::io::loadPCDFile ("/tmp/tms_ss_ods/ods_change_detection/table/model_table1.pcd", *model); else if(TABLE == 2) pcl::io::loadPCDFile ("/tmp/tms_ss_ods/ods_change_detection/table/model_table2.pcd", *model); //*************************** // Fill in the cloud data //*************************** // table.x = req.furniture.position.x/1000.0; // table.y = req.furniture.position.y/1000.0; // table.z = req.furniture.position.z/1000.0; // table.theta = req.furniture.orientation.z; // robot.x = req.robot.x/1000.0; // robot.y = req.robot.y/1000.0; // robot.theta = req.robot.theta; // sensor.x = req.sensor.position.x; // sensor.y = req.sensor.position.y; // sensor.z = req.sensor.position.z; // sensor.theta = req.sensor.orientation.y; table.x = 1.0; table.y = 1.5; table.z = 0.7; table.theta = 0.0; robot.x = 2.6; robot.y = 1.9; robot.theta = 180.0; sensor.x = 0.0; sensor.y = 0.0; sensor.z = 1.0; sensor.theta = 20.0; std::cout << robot.x << " " << robot.y << " " << robot.theta << std::endl; //*************************** // transform input cloud //*************************** pcl::PointCloud<pcl::PointXYZRGB>::Ptr tfm_cloud (new pcl::PointCloud<pcl::PointXYZRGB>); transformation(*cloud1, *model); for(int i=0;i<model->points.size();i++){ model->points[i].r = 255; model->points[i].g = 0; model->points[i].b = 0; } *tfm_cloud = *model + *cloud1; if(!(tfm_cloud->points.size())){ std::cout << "tfm_cloud has no point" << std::endl; return false; } else pcl::io::savePCDFile("/tmp/tms_ss_ods/ods_change_detection/table/tfm_cloud1.pcd", *tfm_cloud); //*************************** // filtering by using model //*************************** std::cout << "filtering" << std::endl; filtering(*cloud1, *model); if(!(cloud1->points.size())){ std::cout << "filtered cloud has no point" << std::endl; return false; } else pcl::io::savePCDFile("/tmp/tms_ss_ods/ods_change_detection/table/filter.pcd", *cloud1); pcl::PointCloud<pcl::PointXYZRGB>::Ptr dsp_cloud (new pcl::PointCloud<pcl::PointXYZRGB>); pcl::copyPointCloud(*cloud1, *dsp_cloud); downsampling(*dsp_cloud, 0.01); //*************************** // registration between two input pcd data //*************************** std::cout << "registration" << std::endl; pcl::PointCloud<pcl::PointXYZRGB>::Ptr rgs_cloud (new pcl::PointCloud<pcl::PointXYZRGB>); pcl::PointCloud<pcl::PointXYZRGB>::Ptr view_cloud (new pcl::PointCloud<pcl::PointXYZRGB>); Eigen::Matrix4f m; int n = 0; while (1){ registration(*dsp_cloud, *model, *rgs_cloud, *cloud1, m); if((double)(m(0,0)+m(1,1)+m(2,2)+m(3,3)) >= 4){ if(n > 2) break; } n++; } pcl::copyPointCloud(*cloud1, *view_cloud); if(!(rgs_cloud->points.size())){ std::cout << "registered cloud has no point" << std::endl; return false; } else pcl::io::savePCDFile("/tmp/tms_ss_ods/ods_change_detection/table/rgs_cloud.pcd", *rgs_cloud); //*************************** // init t_voxel //*************************** std::cout << "init table_voxel" << std::endl; make_tablevoxel(*model); //*************************** // remove table //*************************** std::cout << "remove table" << std::endl; pcl::PointCloud<pcl::PointXYZRGB>::Ptr rmc_cloud1 (new pcl::PointCloud<pcl::PointXYZRGB>); pcl::PointCloud<pcl::PointXYZRGB>::Ptr rmc_cloud2 (new pcl::PointCloud<pcl::PointXYZRGB>); pcl::io::loadPCDFile("/tmp/tms_ss_ods/ods_change_detection/table/memory.pcd", *rmc_cloud2); remove_table(*cloud1, *rmc_cloud1); if(!(rmc_cloud1->size() != 0)){ std::cout << "removed table cloud has no point" << std::endl; return false; } else pcl::io::savePCDFile("/tmp/tms_ss_ods/ods_change_detection/table/remove_table1.pcd", *rmc_cloud1, false); //*************************** // segmentation //*************************** segmentation(*rmc_cloud1, 0.015, 1); if(rmc_cloud2->size() != 0) segmentation(*rmc_cloud2, 0.015, 2); if(rmc_cloud1->size() != 0) pcl::io::savePCDFile("/tmp/tms_ss_ods/ods_change_detection/table/memory.pcd", *rmc_cloud1, true); if(rmc_cloud2->size() != 0) pcl::io::savePCDFile("/tmp/tms_ss_ods/ods_change_detection/table/obj_cloud2.pcd", *rmc_cloud2, true); //*************************** // compare segments with memory //*************************** segment_matching(); pcl::PointCloud<pcl::PointXYZRGB>::Ptr tmp_rgb1 (new pcl::PointCloud<pcl::PointXYZRGB>); pcl::PointCloud<pcl::PointXYZRGB>::Ptr tmp_rgb2 (new pcl::PointCloud<pcl::PointXYZRGB>); //*************************************** // rewrite Object data on TMS database //*************************************** tms_msg_db::tmsdb_ods_object_data srv3; ros::Time time = ros::Time::now() + ros::Duration(9*60*60); int c=0; float colors[6][3] ={{255, 0, 0}, {0,255,0}, {0,0,255}, {255,255,0}, {0,255,255}, {255,0,255}}; for(int i=0;i<Object_Map.size();i++){ std::cout << i << " → " << Object_Map[i].tf << std::endl; if((Object_Map[i].tf == 1)||(Object_Map[i].tf == 2)){ std::stringstream ss; ss << "/tmp/tms_ss_ods/ods_change_detection/table/result_rgb" << i << ".pcd"; if(Object_Map[i].cloud_rgb.size() != 0){ pcl::io::savePCDFile(ss.str (), Object_Map[i].cloud_rgb); for(int j=0;j<Object_Map[i].cloud_rgb.points.size();j++){ Object_Map[i].cloud_rgb.points[j].r = colors[c%6][0]; Object_Map[i].cloud_rgb.points[j].g = colors[c%6][1]; Object_Map[i].cloud_rgb.points[j].b = colors[c%6][2]; } c++; } else std::cout << "no cloud_rgb data" << std::endl; if(Object_Map[i].tf == 1){ *tmp_rgb1 += Object_Map[i].cloud_rgb; tms_msg_db::tmsdb_data data; data.tMeasuredTime = time; data.iType = 5; data.iID = 53; data.fX = 1000.0 * (Object_Map[i].g.x - 1.0); data.fY = 1000.0 * (Object_Map[i].g.y - 1.5); data.fZ = 700.0; data.fTheta = 0.0; data.iPlace = 14; data.iState = 1; srv3.request.srvTMSInfo.push_back(data); geometry_msgs::Pose pose; pose.position.x = Object_Map[i].g.x; pose.position.y = Object_Map[i].g.y; pose.position.z = Object_Map[i].g.z; pose.orientation.x = 0.0; pose.orientation.y = 0.0; pose.orientation.z = 0.0; pose.orientation.w = 0.0; res.objects.poses.push_back(pose); std::cout << Object_Map[i].g.x << " " << Object_Map[i].g.y << " " << Object_Map[i].g.z << std::endl; } else if(Object_Map[i].tf == 2) *tmp_rgb2 += Object_Map[i].cloud_rgb; } } if(srv3.request.srvTMSInfo.size() != 0){ if(commander_to_ods_object_data.call(srv3)) std::cout << "Rewrite TMS database!!" << std::endl; } if((tmp_rgb1->size() == 0) && (tmp_rgb2->size() == 0)){ std::cout << "No change on table!!" << std::endl; return true; } if(tmp_rgb1->size() != 0) pcl::io::savePCDFile("/tmp/tms_ss_ods/ods_change_detection/table/result1.pcd", *tmp_rgb1, true); if(tmp_rgb2->size() != 0) pcl::io::savePCDFile("/tmp/tms_ss_ods/ods_change_detection/table/result2.pcd", *tmp_rgb2, true); *view_cloud += *tmp_rgb1; pcl::io::savePCDFile("/tmp/tms_ss_ods/ods_change_detection/table/view_result.pcd", *view_cloud, true); //pcl::toROSMsg (*cloud1, res.cloud); Object_Map.clear(); return true; }
int main() { // // Define the necessary types: // typedef viennagrid::triangular_2d_mesh MeshType; typedef viennagrid::result_of::segmentation<MeshType>::type SegmentationType; typedef viennagrid::result_of::segment_handle<SegmentationType>::type SegmentHandleType; typedef viennagrid::result_of::point<MeshType>::type PointType; typedef viennagrid::result_of::vertex_handle<MeshType>::type VertexHandleType; typedef viennagrid::result_of::cell<MeshType>::type CellType; typedef viennagrid::result_of::cell_range<SegmentHandleType>::type CellRange; typedef viennagrid::result_of::iterator<CellRange>::type CellIterator; std::cout << "-------------------------------------------------------------- " << std::endl; std::cout << "-- ViennaGrid tutorial: Setup of a mesh with two segments -- " << std::endl; std::cout << "-------------------------------------------------------------- " << std::endl; std::cout << std::endl; // // Step 1: Instantiate the mesh and the segmentation and create 2 segments: // MeshType mesh; SegmentationType segmentation(mesh); // using names to create names SegmentHandleType seg0 = segmentation("segment0"); SegmentHandleType seg1 = segmentation("segment1"); // // Step 2: Add vertices to the mesh. // Note that vertices with IDs are enumerated in the order they are pushed to the mesh. // VertexHandleType vh0 = viennagrid::make_vertex(mesh, PointType(0,0)); // id = 0 VertexHandleType vh1 = viennagrid::make_vertex(mesh, PointType(1,0)); // id = 1 VertexHandleType vh2 = viennagrid::make_vertex(mesh, PointType(2,0)); VertexHandleType vh3 = viennagrid::make_vertex(mesh, PointType(2,1)); VertexHandleType vh4 = viennagrid::make_vertex(mesh, PointType(1,1)); VertexHandleType vh5 = viennagrid::make_vertex(mesh, PointType(0,1)); // id = 5 // // Step 3: Fill the two segments with cells. // To do so, each cell must be linked with the defining vertex handles from the mesh // // First triangle, use vertex handles viennagrid::static_array<VertexHandleType, 3> vertices; vertices[0] = vh0; vertices[1] = vh1; vertices[2] = vh5; // Note that vertices are rearranged internally if they are not supplied in mathematically positive order. viennagrid::make_element<CellType>(seg0, vertices.begin(), vertices.end()); // creates an element with vertex handles // Second triangle: viennagrid::make_triangle(seg0, vh1, vh4, vh5); //use the shortcut function // Third triangle: viennagrid::make_triangle(seg1, vh1, vh2, vh4); // Note that we create in 'seg1' now. // Fourth triangle: viennagrid::make_triangle(seg1, vh2, vh3, vh4 ); // // That's it. The mesh consisting of two segments is now set up. // If no segments are required, one can also directly write viennagrid::make_triangle(mesh, ...); // // // Step 4: Output the cells for each segment: // std::cout << "Cells in segment 0:" << std::endl; CellRange cells_seg0( segmentation("segment0") ); for (CellIterator cit0 = cells_seg0.begin(); cit0 != cells_seg0.end(); ++cit0) { std::cout << *cit0 << std::endl; } std::cout << std::endl; std::cout << "Cells in segment 1:" << std::endl; CellRange cells_seg1( segmentation("segment1") ); for (CellIterator cit1 = cells_seg1.begin(); cit1 != cells_seg1.end(); ++cit1) { std::cout << *cit1 << std::endl; } std::cout << std::endl; std::cout << "-----------------------------------------------" << std::endl; std::cout << " \\o/ Tutorial finished successfully! \\o/ " << std::endl; std::cout << "-----------------------------------------------" << std::endl; return EXIT_SUCCESS; }