ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
client.h
Go to the documentation of this file.
1 /***********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright 2008-2011 Marius Muja (mariusm@cs.ubc.ca). All rights reserved.
5  * Copyright 2008-2011 David G. Lowe (lowe@cs.ubc.ca). All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *************************************************************************/
28 
29 
30 #ifndef MPI_CLIENT_H_
31 #define MPI_CLIENT_H_
32 
33 #include <cstdlib>
34 #include <boost/asio.hpp>
35 #include <FLANN/util/matrix.h>
36 #include <FLANN/util/params.h>
37 #include "queries.h"
38 
39 namespace flann {
40 namespace mpi {
41 
42 
43 class Client
44 {
45 public:
46  Client(const std::string& host, const std::string& service)
47  {
48  tcp::resolver resolver(io_service_);
49  tcp::resolver::query query(tcp::v4(), host, service);
50  iterator_ = resolver.resolve(query);
51  }
52 
53 
54  template<typename ElementType, typename DistanceType>
56  {
57  tcp::socket sock(io_service_);
58  sock.connect(*iterator_);
59 
61  req.nn = knn;
62  req.queries = queries;
63  req.checks = params.checks;
64  // send request
65  write_object(sock,req);
66 
68  // read response
69  read_object(sock, resp);
70 
71  for (size_t i=0;i<indices.rows;++i) {
72  for (size_t j=0;j<indices.cols;++j) {
73  indices[i][j] = resp.indices[i][j];
74  dists[i][j] = resp.dists[i][j];
75  }
76  }
77  }
78 
79 
80 private:
81  boost::asio::io_service io_service_;
82  tcp::resolver::iterator iterator_;
83 };
84 
85 
86 } //namespace mpi
87 } // namespace flann
88 
89 #endif // MPI_CLIENT_H_
cmdLineReadable * params[]
size_t cols
Definition: matrix.h:73
size_t rows
Definition: matrix.h:72
Client(const std::string &host, const std::string &service)
Definition: client.h:46
void knnSearch(const flann::Matrix< ElementType > &queries, flann::Matrix< int > &indices, flann::Matrix< DistanceType > &dists, int knn, const SearchParams &params)
Definition: client.h:55
void write_object(tcp::socket &sock, const T &val)
Definition: queries.h:86
void read_object(tcp::socket &sock, T &val)
Definition: queries.h:72
flann::Matrix< T > queries
Definition: queries.h:44
flann::Matrix< int > indices
Definition: queries.h:58
flann::Matrix< T > dists
Definition: queries.h:59