I'm new to boost and i am trying to build up a distributed random graph generated by the erdos algorithm. All goes well since i specialize the internal_vertex_name template to work with named vertices as suggested in the doc.
You can find the code here.
I get a lot of compilation errors like:
boost/graph/distributed/shuffled_distribution.hpp:62:56: error: ‘const struct boost::graph::distributed::hashed_distribution<std::basic_string<char> >’ has no member named ‘block_size’
error: ‘const struct boost::adjacency_list<boost::vecS, boost::distributedS<boost::graph::distributed::mpi_process_group, boost::vecS>, boost::directedS, TNode, boost::property<boost::edge_weight_t, int>
>::base_distribution_type’ has no member named ‘local
boost/graph/distributed/adjlist/initialize.hpp:29:5: error: invalid conversion from ‘long unsigned int’ to ‘const char*’
Any suggestion?
Related
I understand that pcl::VoxelGrid<PointT> can be used to downsample a PointCloud. In my use case, I want to get the number of points within each voxel grid. From PCL docs I found the leaf struct allows me to get the number of points in one voxel by calling getPointCount(). And pcl::VoxelGridCovariance allows me to get a leaf by calling getLeaf(). But I don't know how to apply all of these to a point cloud. I tried to initialize a pcl::VoxelGridCovariance<PointT> by pcl::VoxelGridCovariance<pcl::PCLPointCloud2> grid; but got the error as below. Could anyone know what's the problem here? Or is there any other way to get the number of points in each voxel? Any advice is appreciated!
/usr/local/include/pcl-1.11/pcl/point_struct_traits.h: In instantiation of ‘struct pcl::traits::fieldList<pcl::PCLPointCloud2>’:
/usr/local/include/pcl-1.11/pcl/filters/voxel_grid_covariance.h:79:70: required from ‘class pcl::VoxelGridCovariance<pcl::PCLPointCloud2>’
/home/linux/Documents/waymo_onTheGo/cart_boundary.cpp:549:60: required from here
/usr/local/include/pcl-1.11/pcl/point_struct_traits.h:198:8: error: invalid use of incomplete type ‘struct pcl::traits::fieldList<pcl::PCLPointCloud2>’
struct fieldList /** \cond NO_WARN_RECURSIVE */ : fieldList<typename POD<PointT>::type> /** \endcond */
^~~~~~~~~
/usr/local/include/pcl-1.11/pcl/point_struct_traits.h:198:8: note: declaration of ‘struct pcl::traits::fieldList<pcl::PCLPointCloud2>’
In file included from /usr/local/include/pcl-1.11/pcl/point_struct_traits.h:42:0,
from /usr/local/include/pcl-1.11/pcl/type_traits.h:40,
from /usr/local/include/pcl-1.11/pcl/memory.h:46,
from /usr/local/include/pcl-1.11/pcl/io/pcd_io.h:42,
from /home/linux/Documents/waymo_onTheGo/cart_boundary.cpp:8:
/usr/local/include/pcl-1.11/pcl/point_struct_traits.h:204:3: error: no matching function for call to ‘assertion_failed<false>(mpl_::failed************ (pcl::traits::fieldList<pcl::PCLPointCloud2>::POINT_TYPE_NOT_PROPERLY_REGISTERED::************)(pcl::PCLPointCloud2&))’
BOOST_MPL_ASSERT_MSG((!std::is_same<PointT, typename POD<PointT>::type>::value),
^
/usr/include/boost/mpl/assert.hpp:83:5: note: candidate: template<bool C> int mpl_::assertion_failed(typename mpl_::assert<C>::type)
int assertion_failed( typename assert<C>::type );
^~~~~~~~~~~~~~~~
/usr/include/boost/mpl/assert.hpp:83:5: note: template argument deduction/substitution failed:
/usr/local/include/pcl-1.11/pcl/point_struct_traits.h:204:3: note: cannot convert ‘pcl::traits::fieldList<pcl::PCLPointCloud2>::POINT_TYPE_NOT_PROPERLY_REGISTERED205::assert_arg()’ (type ‘mpl_::failed************ (pcl::traits::fieldList<pcl::PCLPointCloud2>::POINT_TYPE_NOT_PROPERLY_REGISTERED::************)(pcl::PCLPointCloud2&)’) to type ‘mpl_::assert<false>::type {aka mpl_::assert<false>}’
BOOST_MPL_ASSERT_MSG((!std::is_same<PointT, typename POD<PointT>::type>::value),
^
In file included from /home/linux/Documents/waymo_onTheGo/cart_boundary.cpp:40:0:
/usr/local/include/pcl-1.11/pcl/filters/voxel_grid_covariance.h: In instantiation of ‘class pcl::VoxelGridCovariance<pcl::PCLPointCloud2>’:
/home/linux/Documents/waymo_onTheGo/cart_boundary.cpp:549:60: required from here
/usr/local/include/pcl-1.11/pcl/filters/voxel_grid_covariance.h:79:70: error: no type named ‘type’ in ‘struct pcl::traits::fieldList<pcl::PCLPointCloud2>’
using FieldList = typename pcl::traits::fieldList<PointT>::type;
^
/usr/local/include/pcl-1.11/pcl/filters/voxel_grid_covariance.h:80:61: error: no type named ‘PointCloud’ in ‘class pcl::Filter<pcl::PCLPointCloud2>’
using PointCloud = typename Filter<PointT>::PointCloud;
^
/usr/local/include/pcl-1.11/pcl/filters/voxel_grid_covariance.h:56:9: error: ‘std::__cxx11::string pcl::Filter<pcl::PCLPointCloud2>::filter_name_’ is protected within this context
class VoxelGridCovariance : public VoxelGrid<PointT>
^~~~~~~~~~~~~~~~~~~
In file included from /usr/local/include/pcl-1.11/pcl/filters/filter_indices.h:42:0,
from /usr/local/include/pcl-1.11/pcl/filters/extract_indices.h:42,
from /home/linux/Documents/waymo_onTheGo/cart_boundary.cpp:13:
/usr/local/include/pcl-1.11/pcl/filters/filter.h:240:19: note: declared protected here
std::string filter_name_;
^~~~~~~~~~~~
In file included from /home/linux/Documents/waymo_onTheGo/cart_boundary.cpp:40:0:
/usr/local/include/pcl-1.11/pcl/filters/voxel_grid_covariance.h:56:9: error: ‘const string& pcl::Filter<pcl::PCLPointCloud2>::getClassName() const’ is protected within this context
class VoxelGridCovariance : public VoxelGrid<PointT>
^~~~~~~~~~~~~~~~~~~
In file included from /usr/local/include/pcl-1.11/pcl/filters/filter_indices.h:42:0,
from /usr/local/include/pcl-1.11/pcl/filters/extract_indices.h:42,
from /home/linux/Documents/waymo_onTheGo/cart_boundary.cpp:13:
/usr/local/include/pcl-1.11/pcl/filters/filter.h:253:7: note: declared protected here
getClassName () const
^~~~~~~~~~~~
In file included from /home/linux/Documents/waymo_onTheGo/cart_boundary.cpp:40:0:
/usr/local/include/pcl-1.11/pcl/filters/voxel_grid_covariance.h: In instantiation of ‘pcl::VoxelGridCovariance<PointT>::VoxelGridCovariance() [with PointT = pcl::PCLPointCloud2]’:
/home/linux/Documents/waymo_onTheGo/cart_boundary.cpp:549:60: required from here
/usr/local/include/pcl-1.11/pcl/filters/voxel_grid_covariance.h:205:18: error: using invalid field ‘pcl::VoxelGridCovariance<PointT>::voxel_centroids_’
kdtree_ ()
^
To just access the number of points, use OctreePointCloudDensity
To also access the points inside each voxel, use OctreePointCloudPointVector
I am trying to build this library for supervoxel segmenation. When I try to make it, I get this error:
supervoxel_clustering/src/testing.cpp:157:66: error: conversion from ‘boost::detail::sp_if_not_array<pcl::PointCloud<pcl::PointXYZL> >::type {aka boost::shared_ptr<pcl::PointCloud<pcl::PointXYZL> >}’ to non-scalar type ‘pcl::PointCloud<pcl::PointXYZL>::Ptr {aka std::shared_ptr<pcl::PointCloud<pcl::PointXYZL> >}’ requested
PointLCloudT::Ptr subcloud = boost::make_shared<PointLCloudT>();
Since this was in the testing.cpp, I tried ignoring this file to build the source. But it died again on:
supervoxel_clustering/src/clustering.cpp:406:63: error: conversion from ‘boost::detail::sp_if_not_array<pcl::Supervoxel<pcl::PointXYZRGBA> >::type {aka boost::shared_ptr<pcl::Supervoxel<pcl::PointXYZRGBA> >}’ to non-scalar type ‘pcl::Supervoxel<pcl::PointXYZRGBA>::Ptr {aka std::shared_ptr<pcl::Supervoxel<pcl::PointXYZRGBA> >}’ requested
SupervoxelT::Ptr sup_new = boost::make_shared<SupervoxelT>();
What could be going wrong with the boost::make_shared instantiation?
Boost Version: 1.58.0.1ubuntu1
PCL Version: 1.11
C++14 compiler
edit:
While I don't know why the error was being caused, I fixed it with:
PointLCCloudT::Ptr cloud_temp(new PointLCCloudT);
I have a tree structure that internally uses unordered map
#include <unordered_map>
struct Node {
std::unordered_map<int, Node> children;
};
int main() {
Node a;
}
It works just fine on Apple clang 11.0.3 and MSVC v19.24, but it fails to compile on clang 10.0.0 and gcc 10.1
While regular std::map works just fine on all compilers. I failed to find the reason for this discrepancy. Is there any way to use std::unordered_map as a value for itself? Or pointers is the only solution here?
Here's the compiler explorer link https://godbolt.org/z/6eYch9
Here's an error from gcc:
#3 with x86-64 gcc 10.1
In file included from /opt/compiler-explorer/gcc-10.1.0/include/c++/10.1.0/unordered_map:43,
from <source>:1:
/opt/compiler-explorer/gcc-10.1.0/include/c++/10.1.0/bits/stl_pair.h:
In instantiation of 'struct std::pair<const int, Node>':
/opt/compiler-explorer/gcc-10.1.0/include/c++/10.1.0/ext/aligned_buffer.h:91:28:
required from 'struct __gnu_cxx::__aligned_buffer<std::pair<const int,
Node> >'
/opt/compiler-explorer/gcc-10.1.0/include/c++/10.1.0/bits/hashtable_policy.h:233:43:
required from 'struct
std::__detail::_Hash_node_value_base<std::pair<const int, Node> >'
/opt/compiler-explorer/gcc-10.1.0/include/c++/10.1.0/bits/hashtable_policy.h:279:12:
required from 'struct std::__detail::_Hash_node<std::pair<const int,
Node>, false>'
/opt/compiler-explorer/gcc-10.1.0/include/c++/10.1.0/bits/hashtable_policy.h:1973:13:
required from 'struct
std::__detail::_Hashtable_alloc<std::allocator<std::__detail::_Hash_node<std::pair<const
int, Node>, false> > >'
/opt/compiler-explorer/gcc-10.1.0/include/c++/10.1.0/bits/hashtable.h:173:11:
required from 'class std::_Hashtable<int, std::pair<const int, Node>,
std::allocator<std::pair<const int, Node> >,
std::__detail::_Select1st, std::equal_to<int>, std::hash<int>,
std::__detail::_Mod_range_hashing,
std::__detail::_Default_ranged_hash,
std::__detail::_Prime_rehash_policy,
std::__detail::_Hashtable_traits<false, false, true> >'
/opt/compiler-explorer/gcc-10.1.0/include/c++/10.1.0/bits/unordered_map.h:105:18:
required from 'class std::unordered_map<int, Node>'
<source>:4:39: required from here
/opt/compiler-explorer/gcc-10.1.0/include/c++/10.1.0/bits/stl_pair.h:218:11:
error: 'std::pair<_T1, _T2>::second' has incomplete type
218 | _T2 second; ///< The second member
| ^~~~~~
<source>:3:8: note: forward declaration of 'struct Node'
3 | struct Node {
| ^~~~
Compiler returned: 1
STL containers are not required to work with incomplete types. If you don't mind extra indirection, then the workaround is std::map<int, std::unique_ptr<Node>>
It's the same problem as doing e.g.
struct Node
{
Node child; // An instance of the full structure
};
You can't use a structure (or class) before it's fully defined, which it is at the closing }.
You can however define pointers to the structure, because then the compiler don't need the full structure definition, only know the name of the structure:
struct Node
{
Node* child; // Pointer to the structure
};
So to solve your problem, you need a map of pointers:
std::unordered_map<int, Node*> children;
Running into this while coding a Trie data structure I've noticed that in the latest of clang (v14) and GCC (v12) I don't get the error and my code operates as expected but anything below those versions (on godbolt.com) I get the same error. This is all using -std=c++14 so it's should not be related to the standard.
I'm using the Eigen library in C++ to obtain the square root of a float square matrix:
MatrixXf gPrime(QUAD_EKF_NUM_STATES, QUAD_EKF_NUM_STATES);
gPrime.setIdentity();
auto sqrtG = gPrime.sqrt();
when I compile it I got the following error:
.../src/QuadEstimatorEKF.cpp:255:31: error: invalid use of incomplete type ‘const class Eigen::MatrixSquareRootReturnValue<Eigen::Matrix<float, -1, -1> >’
auto sqrtG = gPrime.sqrt()
^
In file included from /.../lib/Eigen/Core:346,
from /.../lib/Eigen/Dense:1,
from /.../src/QuadEstimatorEKF.h:11,
from /.../src/QuadEstimatorEKF.cpp:2:
/.../lib/Eigen/src/Core/util/ForwardDeclarations.h:286:34: note: declaration of ‘class Eigen::MatrixSquareRootReturnValue<Eigen::Matrix<float, -1, -1> >’
template<typename Derived> class MatrixSquareRootReturnValue;
^~~~~~~~~~~~~~~~~~~~~~~~~~~
What does 'incomplete type' mean and what should I do to fix it?
I'm using C++ 11 and g++ 8.1.1.
Searching for the documentation of that function reveals that it is part of Eigen-unsupported and (at the top)
To use this module, add
#include <unsupported/Eigen/MatrixFunctions>
at the start of your source file.
invalid use of incomplete type
means that the compiler only finds a declaration but a definition is required at the point of use.
Looks like its looking for something more than the P_old.sqrt(), you will need to have a look at what this object looks like, it might have getters/setters or atomic types you might need to use.
Read up about forward declarations to understand why you got this error, fixing it should be straightforward.
Drawing on this reply, I've tried to implement the Betweenness centrality as follows:
typedef struct vpr_
{
int id;
} VProp;
typedef boost::adjacency_list<boost::listS, boost::listS, boost::undirectedS, VProp, EProp> graph_t;
boost::shared_array_property_map<double, boost::property_map<graph_t, int>::const_type> centrality_map(num_vertices(g), get(VProp::id, g));
But the following error was returned.
In file included from /usr/local/include/boost/graph/adjacency_list.hpp:246:0,
from /usr/local/include/boost/graph/random.hpp:23,
from ../../src/graph/Graph.h:25,
from Graph.cpp:23:
/usr/local/include/boost/graph/detail/adjacency_list.hpp: In instantiation of ‘struct boost::adj_list_any_vertex_pa::bind_<int, boost::adjacency_list<boost::listS, boost::listS, boost::undirectedS, vpr_, epr_>, vpr_>’:
/usr/local/include/boost/graph/detail/adjacency_list.hpp:2568:12: required from ‘struct boost::detail::adj_list_choose_vertex_pa<int, boost::adjacency_list<boost::listS, boost::listS, boost::undirectedS, vpr_, epr_>, vpr_>’
/usr/local/include/boost/graph/detail/adjacency_list.hpp:2705:12: required from ‘struct boost::adj_list_vertex_property_selector::bind_<boost::adjacency_list<boost::listS, boost::listS, boost::undirectedS, vpr_, epr_>, vpr_, int>’
/usr/local/include/boost/graph/properties.hpp:217:12: required from ‘struct boost::detail::vertex_property_map<boost::adjacency_list<boost::listS, boost::listS, boost::undirectedS, vpr_, epr_>, int>’
/usr/local/include/boost/graph/properties.hpp:228:10: required from ‘struct boost::property_map<boost::adjacency_list<boost::listS, boost::listS, boost::undirectedS, vpr_, epr_>, int>’
Graph.cpp:374:76: required from here
/usr/local/include/boost/graph/detail/adjacency_list.hpp:2498:29: error: forming reference to void
/usr/local/include/boost/graph/detail/adjacency_list.hpp:2499:35: error: forming reference to void
/usr/local/include/boost/graph/detail/adjacency_list.hpp:2502:47: error: forming reference to void
/usr/local/include/boost/graph/detail/adjacency_list.hpp:2504:53: error: forming reference to void
Graph.cpp: In member function ‘void Graph::getBetweennes()’:
Graph.cpp:374:88: error: template argument 2 is invalid
Graph.cpp:375:17: error: invalid type in declaration before ‘(’ token
In file included from ../../src/graph/graph_t.h:33:0,
from ../../src/graph/Graph.h:26,
from Graph.cpp:23:
../../src/graph/VProp.h:38:6: error: invalid use of non-static data member ‘vpr_::id’
Graph.cpp:375:46: error: from this location
Graph.cpp:375:52: error: expression list treated as compound expression in initializer [-fpermissive]
EDIT
#include <boost/graph/iteration_macros.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/graph/random.hpp>
typedef struct vpr_
{
int id;
} VProp;
typedef struct epr_
{
int id;
} EProp;
typedef boost::adjacency_list<boost::listS, boost::listS, boost::undirectedS, VProp, EProp> graph_t;
int main(void) {
graph_t g;
boost::shared_array_property_map<double, boost::property_map<graph_t, VProp::*>::const_type> centrality_map(num_vertices(g), get(&VProp::id, g));
}
The code has been compiled with g++ -L/usr/local/lib -lboost_graph gtest.cpp, and the returned error is:
gtest.cpp: In function ‘int main()’:
gtest.cpp:18:81: error: template argument 2 is invalid
gtest.cpp:18:94: error: template argument 2 is invalid
gtest.cpp:18:110: error: invalid type in declaration before ‘(’ token
gtest.cpp:18:146: error: expression list treated as compound expression in initializer [-fpermissive]
gtest.cpp:18:146: error: cannot convert ‘boost::adj_list_any_vertex_pa::bind_<int vpr_::*, boost::adjacency_list<boost::listS, boost::listS, boost::undirectedS, vpr_, epr_>, vpr_>::type {aka boost::adj_list_vertex_property_map<boost::adjacency_list<boost::listS, boost::listS, boost::undirectedS, vpr_, epr_>, int, int&, int vpr_::*>}’ to ‘int’ in initialization
How could I fix this? Thanks in advance
Jackb, this BGL algorithm like many others in BGL requires a "vertex index property map" -- a one-to-one mapping between set of graph vertices and integer numbers within interval [0,num_vertices(g)).
Now, your structures EProp and VProp cannot be used as substitutes for vertex_index property maps, and it is what causes the compilation errors.
If you can use boost::adjacency_list<boost::vecS, ...> as your graph type, then vertex_index mapping will come for free (as internal property of the graph). Then you will be able to call centrality algorithms the way it is called in your referenced thread: centrality_map(num_vertices(g), get(boost::vertex_index, g));.
If for some reasons you cannot use boost::vecS, you have to organize the mapping yourself. For setS and listS it is discussed here How to use boost::graph algorithms with listS, setS as vertex/edge containers? and references thereof.
See related discussions on Property Map here What is a property map in BOOST? and specifically on vertex_index map here: Dijkstra Shortest Path with VertexList = ListS in boost graph