Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] classification

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] classification


Chronological Thread 
  • From: wangtao8869 <>
  • To:
  • Subject: Re: [cgal-discuss] classification
  • Date: Mon, 26 Apr 2021 20:18:35 -0500 (CDT)
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None ; spf=Fail ; spf=Pass
  • Ironport-hdrordr: A9a23:GRCHCq+jxgZ/RL2WYLRuk+AbI+orLtY04lQ7vn1ZYxpTb8CeioSCnO4D0wX1lTYWXxgb6LO9EYOHRm7R8oMw3JkJMd6ZPDXOlWO0IOhZh7fK7CbnH0TFm9J18YdFX+xABMbrDV585Pya3CCdH8w7yNeKtICE7N2x815XQQtna75t4m5CY27xLmRNWAJECZAlfaDy2uN7oVObFUg/Ut62HT0sUeTFurTw5fDbXSI=
  • Ironport-phdr: A9a23:my7ktB9tWc1EBv9uWee8ngc9DhMPi/DPJgcQr6AfoPdwSMyLwZ3uMQTl6Ol3ixeRBMOHsqMC0bOG+Pm6CSQp2tWoiDg6aptCVhsI2409vjcLJ4q7M3D9N+PgdCcgHc5PBxdP9nC/NlVJSo6lPwWB6nK94iQPFRrhKAF7Ovr6GpLIj8Swyuu+54Dfbx9HiTagZb5+Ngu6oRjSu8UZnIduNKU8wQbVr3VVfOhb2XlmLk+JkRbm4cew8p9j8yBOtP8k6sVNT6b0cbkmQLJBFDgpPHw768PttRnYUAuA/WAcXXkMkhpJGAfK8hf3VYrsvyTgt+p93C6aPdDqTb0xRD+v4btnRAPuhSwaMTMy7WPZhdFqjK9DrhyvpwJxzY3Wb4GbKfRxcb/Sc9wBSGpdXMtdSzBNDp+gY4cRCecKIOZWr5P6p1sLtRa/CxOjBOXgyj9UnHD22q433ucgHAzCwQctGNwPv27SrNX6KKcdS+e1warLwDjCa/5bwirx5YnGfxw7vf6MWrdwfNPXxEIyGAzLkk+eppb5PzOJyOsNqW6b4vJvWO+shGAqqA5/rDiuy8osloTFmo0bx1/a+Ch6wYs7K8O0RFN5bNOgFJZdqT+XOoR1T84sQ29mtjo3x6ECtJO5eiUB1Zopxxnaa/OdcoiI5AruVOCLLjhjn31lfKywiwyu/kinz+3xUNS/3lVSriddj9XBsnQA2wbd58WEUPdw/Uas1SyO2g3S7OxPPFo6mrDBK5E7x749jpoTvlrHHi/xgEj2iqCbel8i+uey8OvoebHmqYGGO4BojQH+N7wims25AesmLggDR3WX9OC42bH580D0Q69Gg/43n6XDsZ3XJNwXpqujDA9U1oYj5Qy/DzCj0NkAk3gINlRFeB2bj4fzPFHDI/P1APa7jlm3jTtmxv7LMqf9DZXKK3jPiK3hcqpl605A1AozyshS6I5bCr4bJPL/Q1L+tN3DDhAlLgy02P3nBc5m1oIeXGKPGrWWPLnTsV+O/OIvIvODaJUbuDbneLAZ4KvlgnY93FMcZqK0xoA/aXaiH/0gLV/KT2Drh4IeGGEFogM5HLy02RXWTjdVaGq7WPJsuGATUdz9S4zEQ9b+0/S6wC6nE8gONSh9AVeWHCKwH620HswUYSfXGfdP1zkNVLyvUYgkvTn36lS8wL1ifLa80h1djorq0Z1O38OWlRw28lRcCZjb1WiHRWV52GgPQm1vtIhP5Hdlw1LG6pBWxuRCHLR7vq0SFAw9MMyEp9E=

Dear Simon Giraudot,
the full source code is as follow,
#if defined (_MSC_VER) && !defined (_WIN64)
#pragma warning(disable:4244) // boost::number_distance::distance()
// converts 64 to 32 bits integers
#endif

#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>

#include <CGAL/Simple_cartesian.h>
#include <CGAL/Classification.h>
#include <CGAL/IO/read_ply_points.h>
#include <CGAL/Point_set_3.h>
#include <CGAL/Point_set_3/IO.h>
#include <CGAL/Classification/Feature_base.h>




typedef CGAL::Simple_cartesian<double> Kernel;
typedef Kernel::FT FT;
typedef Kernel::Point_3 Point;
typedef Kernel::Vector_3 Vector;
typedef Kernel::Iso_cuboid_3 Iso_cuboid_3;
typedef std::vector<Point> Point_range;
typedef CGAL::Identity_property_map<Point> Pmap;
typedef CGAL::Point_set_3<Point> Point_set;
typedef Point_set::Property_map<int> Imap;
typedef Point_set::Property_map<FT> FT_map;
typedef Point_set::Vector_map Vmap;

namespace Classification = CGAL::Classification;

typedef Classification::Sum_of_weighted_features_classifier

Classifier;

typedef Classification::Point_set_neighborhood<Kernel, Point_range, Pmap>

Neighborhood;
typedef Neighborhood::K_neighbor_query

Neighbor_query;
typedef Classification::Local_eigen_analysis

Local_eigen_analysis;

typedef Classification::Label_handle

Label_handle;
typedef Classification::Feature_handle

Feature_handle;
typedef Classification::Label_set

Label_set;
typedef Classification::Feature_set

Feature_set;

typedef Classification::Feature::Verticality<Kernel>

Verticality;
typedef Classification::Feature::Distance_to_plane<Point_range, Pmap>

Distance_to_plane;
typedef Classification::Feature::Elevation<Kernel, Point_range, Pmap>

Elevation;
typedef Classification::Feature::Vertical_dispersion<Kernel, Point_range,
Pmap> Dispersion;
typedef
Classification::Feature::Gradient_of_feature<Point_range,Imap,Neighbor_query>

Gradient_of_feature;
typedef Classification::Feature::Simple_feature<Point_range, FT_map>

Simple_feature;

///////////////////////////////////////////////////////////////////
//! [Feature]

// User-defined feature that identifies a specific area of the 3D
// space. This feature takes value 1 for points that lie inside the
// area and 0 for the others.
class My_feature : public CGAL::Classification::Feature_base
{
const Point_range& range;
double xmin, xmax, ymin, ymax;
public:
My_feature (const Point_range& range,
double xmin, double xmax, double ymin, double ymax)
: range (range), xmin(xmin), xmax(xmax), ymin(ymin), ymax(ymax)
{
this->set_name ("my_feature");
}

float value (std::size_t pt_index)
{
if (xmin < range[pt_index].x() && range[pt_index].x() < xmax &&
ymin < range[pt_index].y() && range[pt_index].y() < ymax)
return 1.f;
else
return 0.f;
}

};



//! [Feature]
///////////////////////////////////////////////////////////////////

int main (int argc, char** argv)
{
std::string filename (argc > 1 ? argv[1] : "houset.ply");
std::ifstream in (filename.c_str());
std::vector<Point> pts;
Point_set ptset;
// int intensity0;
Imap Intensity_map;
FT_map intensity;
bool lm_found = false;
bool success = false;
int Pnumpts = 0;

char *in_file = argv[1];
FILE *infile;



int cap = 0;
// char buf[048];
x = 0;
y = 0;
z = 0;



// cout<<"Enter root name of data file (.txt assumed) -->";
// cin>>rootname;
// strcat(rootname,".sift");
// cout<<endl;




std::cerr &lt;&lt; &quot;Reading input&quot; &lt;&lt; std::endl;
if (!in
|| !(CGAL::read_ply_points (in, std::back_inserter (pts))))
{
std::cerr &lt;&lt; &quot;Error: cannot read &quot; &lt;&lt; filename
&lt;&lt; std::endl;
return EXIT_FAILURE;
}
// if (!in
// || !(CGAL::read_ply_point_set(in, ptset)))
// {
// std::cerr &lt;&lt; &quot;Error: cannot read &quot; &lt;&lt; filename
&lt;&lt; std::endl;
// return EXIT_FAILURE;
// }

for (Point_set::const_iterator it = ptset.begin(); it != ptset.end();
++it)
{
pts.push_back(ptset.point(*it));
}

// in >> ptset;
ptset.add_normal_map();

boost::tie(intensity, success) =
ptset.add_property_map<FT>("intensity",0.);
if (!success)
{
std::cerr << "Intensity can't be added" << std::endl;
}
Point_set::iterator it = ptset.begin();
while (it!=ptset.end())
{
intensity[*it] = 10;
ptset.normal(*it) = Vector(1., 0., 0.);
++it;
}


// boost::tie(Intensity_map, lm_found) =
ptset.property_map<int>("Intensity");
// if (!lm_found)
// {
// std::cerr << "Intensity can't be found" << std::endl;
// }


const double search_sphere_radius = 1.0;

Neighborhood neighborhood (pts, Pmap());
// Neighbor_query neighbor_query1(neighborhood,6);

Local_eigen_analysis eigen
= Local_eigen_analysis::create_from_point_set (pts, Pmap(),
neighborhood.k_neighbor_query(6));

Label_set labels;
Label_handle a = labels.add ("label_A");
Label_handle b = labels.add ("label_B");

// std::vector<std::size_t> neighborhood0;
// neighborhood.k_neighbor_query(6);


///////////////////////////////////////////////////////////////////
//! [Addition]

std::cerr << "Computing features" << std::endl;
Feature_set features;

// Feature that identifies points whose x coordinate is between -20
// and 20 and whose y coordinate is between -15 and 15
Feature_handle my_feature = features.add<My_feature> (pts, -20., 20.,
-15., 15.);
float test = static_cast<float>(get(intensity,*(ptset.begin()+10)));
// (get(ptset.normal_map(), *(ptset.begin() + 11)));
Vmap normalmap = ptset.normal_map();
// const Vmap& normalm0 = normalmap;
// std::vector<std::size_t> neighbor;
// neighborhood.k_neighbor_query(6)((normalmap, *(pts.begin() + 10)),
std::back_inserter(neighbor));
// Vector normal = get(normalmap, *(ptset.begin() + 10));
// FT_map inten;
// boost::tie(inten, boost::tuples::ignore) =
ptset.property_map<FT>("intensity");

// std::string sl("intensity");
// Feature_handle sample_feature = features.add<Simple_feature>(pts,
intensity,"Intensity");
// Feature_handle grafeature = features.add<Gradient_of_feature>(pts,
Intensity_map, my_feature, neighborhood.k_neighbor_query(12));

//! [Addition]
///////////////////////////////////////////////////////////////////

// Feature_handle verticality = features.add<Verticality> (pts, eigen);
Feature_handle verticality = features.add<Verticality>(pts, normalmap);


Classifier classifier (labels, features);

std::cerr << "Setting weights" << std::endl;
classifier.set_weight(verticality, 0.5);
classifier.set_weight(my_feature, 0.25);

std::cerr << "Setting up labels" << std::endl;
classifier.set_effect (a, verticality, Classifier::FAVORING);
classifier.set_effect (a, my_feature, Classifier::FAVORING);
classifier.set_effect (b, verticality, Classifier::PENALIZING);
classifier.set_effect (b, my_feature, Classifier::PENALIZING);

std::cerr << "Classifying" << std::endl;
std::vector<std::size_t> label_indices(pts.size(), -1);
Classification::classify_with_graphcut<CGAL::Sequential_tag>
(pts, Pmap(), labels, classifier,
neighborhood.k_neighbor_query(12),
0.5, 1, label_indices);

std::cerr << "All done" << std::endl;
return EXIT_SUCCESS;
}
thank you!

wangtao



--
Sent from: http://cgal-discuss.949826.n4.nabble.com/



Archive powered by MHonArc 2.6.19+.

Top of Page