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: Simon Giraudot <>
  • To:
  • Subject: Re: [cgal-discuss] classification
  • Date: Tue, 27 Apr 2021 08:28:24 +0200
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None ; spf=None ; spf=None
  • Ironport-hdrordr: A9a23:nSGNE67Spj2QJD5dvQPXwFbXdLJzesId70hD6mlaQ3VuE/CwvcaogfgdyFvIkz4XQn4tgpStP6OHTHPa+/dOgbU5F7GkQQXgpS+UPJhvhLGI/xTMEzDzn9Qy6Y5OaK57YeedMXFbioLA7BC8A5IcxrC8n5yAoevF1X9iQUVLZshbnmREIyKaFkEzewVcH5o+E/OnjPZvnDardXQJYsnTPBBsY8H5q9LGj57gaxIdbiRXijWmty+i67LxDnGjsys2bjUn+8ZGzUH11yjw5qCuqJiAu3vh61M=
  • Ironport-phdr: A9a23:QBLe8x+eKxC3Kf9uWQi6ngc9DhMPi/DPJgcQr6AfoPdwSMyLwZ3uMQTl6Ol3ixeRBMOHsqMC0bOH+Pm5AiQp2tWoiDg6aptCVhsI2409vjcLJ4q7M3D9N+PgdCcgHc5PBxdP9nC/NlVJSo6lPwWB6nK94iQPFRrhKAF7Ovr6GpLIj8Swyuu+54Dfbx9HiTagZb5+Ngu6oRjVu8UZnIduN6g8wQbVr3VVfOhb2XlmLk+JkRbm4cew8p9j8yBOtP8k6sVNT6b0cbkmQLJBFDgpPHw768PttRnYUAuA/WAcXXkMkhpJGAfK8hf3VYrsvyTgt+p93C6aPdDqTb0xRD+v4btnRAPuhSwaMTMy7WPZhdFqjK9DvRyvuRJ/zY7Xbo+bOvVxcaHScs8VS2daQsZcVDZMDp+gY4YBDecMO/tToYnnp1sJqBuzHRSiBOLqyj9PgH/9wKw00+U7EQ7cwQwvAtUOsGjJp9jyL6cSUOW1zK7OzTnZYPNW2C3955LVch88pvGMQal9ccXPxkkoEgPKkEm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5wD9MTwoARsHo2wV8qeuqj21RbembAtbjAf4bPI2y3xyiBLrbM0zn239uR/6oT8uU2ol7/uxu4UEEl9ic/u/FllkCE75CPNzI8FJL8VkFf30U8oraFJCw05oeR0mBwd66qsnnE1s57XIMN+lObZ95adZi8Okr3GsweCdKpLYQClFWuax8YJvFc/aUoONm3MfCB3fzzVNs=

Dear Wangtao,

You are mixing range types, which is why you have errors. The normal_map object is the normal map of CGAL::Point_set_3 while you use the function with a range of type std::vector<Point_3>. This are not compatible.

Please use only one range type to avoid this kind of error:

- either use Point_set_3 everywhere, which is easy as you can directly use normal_map() as you did
- if you want to use a std::vector and still have normals, you can use std::vector<std::pair<Point_3,Vector_3>> and use for point map CGAL::First_of_pair_property_map and for normal map CGAL::Second_of_pair_property_map

Best,

--
Simon Giraudot, PhD
R&D Engineer
GeometryFactory - http://geometryfactory.com/

Le 27/04/2021 à 03:18, wangtao8869 ( via cgal-discuss Mailing List) a écrit :
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