39 #include <curl/curl.h> 45 const std::string& server_password,
const std::string& mesh_layer)
46 : server_url_(server_url)
47 , server_username_(server_username)
48 , server_password_(server_password)
49 , mesh_layer_(mesh_layer)
66 mesh_filters_[channel] = std::make_pair(min_value, max_value);
72 attr[
"name"] = attribute_name;
81 filter[
"attribute_name"] = mesh_filter.first;
82 filter[
"min_val"] = mesh_filter.second.first;
83 filter[
"max_val"] = mesh_filter.second.second;
85 filters.append(filter);
87 attr[
"filters"] = filters;
99 request[
"boundingbox"] = json_bb;
100 request[
"attribute"] = attr;
102 Json::FastWriter fast_writer;
103 return fast_writer.write(request);
106 bool parseByteDataString(std::string
string,
char& type,
unsigned long& size,
unsigned long& width,
char*& data)
108 if (
string.length() < 10)
114 const char* body =
string.c_str();
116 size = *
reinterpret_cast<const unsigned long*
>(body + 1);
117 width = *
reinterpret_cast<const unsigned long*
>(body + 9);
118 data =
reinterpret_cast<char*
>(
const_cast<char*
>(body + 17));
132 if (str && str->size() > 17)
135 unsigned long size, width;
142 float* float_data =
reinterpret_cast<float*
>(data);
144 memcpy(channel.dataPtr().get(), float_data, size * width *
sizeof(float));
162 if (str && str->size() > 17)
165 unsigned long size, width;
172 unsigned int* index_data =
reinterpret_cast<unsigned int*
>(data);
174 memcpy(channel.dataPtr().get(), index_data, size * width *
sizeof(
lvr2::Index));
197 std::cout <<
"channel " << name << std::endl;
206 if (str && str->size() > 17)
209 unsigned long size, width;
216 float* float_data =
reinterpret_cast<float*
>(data);
218 memcpy(channel.get().dataPtr().get(), float_data, size * width *
sizeof(float));
236 if (str && str->size() > 17)
239 unsigned long size, width;
246 unsigned int* index_data =
reinterpret_cast<unsigned int*
>(data);
248 memcpy(channel.get().dataPtr().get(), index_data, size * width *
sizeof(
lvr2::Index));
266 if (str && str->size() > 17)
269 unsigned long size, width;
276 unsigned char* uchar_data =
reinterpret_cast<unsigned char*
>(data);
278 memcpy(channel.get().dataPtr().get(), uchar_data, size * width *
sizeof(
unsigned char));
308 curl_global_init(CURL_GLOBAL_ALL);
310 curl = curl_easy_init();
313 curl_global_cleanup();
317 std::string post_body =
buildJson(channel);
318 curl_easy_setopt(curl, CURLOPT_URL,
server_url_.c_str());
320 struct curl_slist* list = curl_slist_append(list,
"Content-Type: application/json");
322 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
323 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post_body.c_str());
324 curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
326 curl_easy_setopt(curl, CURLOPT_USERPWD, usr_pwd.c_str());
328 unique_ptr<std::string> result = std::make_unique<std::string>();
329 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
writeFunction);
330 curl_easy_setopt(curl, CURLOPT_WRITEDATA, result.get());
332 CURLcode res = curl_easy_perform(curl);
335 std::cout <<
"error" << std::endl;
336 curl_easy_cleanup(curl);
340 curl_easy_cleanup(curl);
std::string buildJson(const std::string &attribute_name)
Builds a JSON string containing the set bounding box and the attribute name and the attribute group...
std::string server_username_
std::array< float, 6 > bounding_box_
lvr2::FloatChannelOptional getVertices()
Persistence layer interface, Accesses the vertices of the mesh in the persistence layer...
bool addChannel(const std::string group, const std::string name, const lvr2::FloatChannel &channel)
addChannel Writes a float attribute channel from the given group with the given name ...
std::map< std::string, lvr2::FloatChannel > float_channels
UCharChannel::Optional UCharChannelOptional
bool getChannel(const std::string group, const std::string name, lvr2::FloatChannelOptional &channel)
getChannel Reads a float attribute channel in the given group with the given name ...
bool parseByteDataString(std::string string, char &type, unsigned long &size, unsigned long &width, char *&data)
std::map< std::string, std::pair< float, float > > mesh_filters_
Channel< float > FloatChannel
std::map< std::string, lvr2::IndexChannel > index_channels
size_t writeFunction(void *ptr, size_t size, size_t nmemb, std::string *data)
void addFilter(std::string channel, float min_value, float max_value)
void setBoundingBox(float min_x, float min_y, float min_z, const float max_x, const float max_y, const float max_z)
sets the Bounding box for the query which is send to the server
MeshClient(const std::string &srv_url, const std::string &server_username, const std::string &server_password, const std::string &mesh_layer)
Constructs a mesh client which receaves.
Channel< unsigned char > UCharChannel
void filter(lvr2::PointBufferPtr &cloud, lvr2::indexArray &inlier, size_t j)
#define ROS_DEBUG_STREAM(args)
FloatChannel::Optional FloatChannelOptional
IndexChannel::Optional IndexChannelOptional
bool addVertices(const lvr2::FloatChannel &channel_ptr)
Persistence layer interface, Writes the vertices of the mesh to the persistence layer.
std::string server_password_
lvr2::IndexChannelOptional getIndices()
Persistence layer interface, Accesses the face indices of the mesh in the persistence layer...
Channel< unsigned int > IndexChannel
#define ROS_ERROR_STREAM(args)
std::unique_ptr< std::string > requestChannel(std::string channel)
bool addIndices(const lvr2::IndexChannel &channel_ptr)
Persistence layer interface, Writes the face indices of the mesh to the persistence layer...
std::map< std::string, lvr2::UCharChannel > uchar_channels