0
$\begingroup$

Rosanswers logo

--------------------------------------------------------EDIT 20121031 ----------------------------------------------------------

Hi I think I found the problem: I am using the old version of Octomap which does not correspond to the code API. In the code API, there is a class called AbstractOccupancyOcTree, and in order to get a binary file i need to use the writeBinary function from this class. However, after I check out code trunk for ROS electric and compiled it, I cannot find this file included under octomap_mapping/octomap/octomap/include/octomap. Is there any way you can include this class in there? Thanks !!!!!

--------------------------------------------------------EDIT 20121029 ----------------------------------------------------------

here is my code:

int main(int argc, char **argv){
    ros::init(argc, argv, "read_write_node");
    ros::NodeHandle n;
    string fileName;
    string newfileName;
    cout > fileName;
    cout > newfileName;
    ofstream mapfile(newfileName.c_str(), ios_base::binary);
    if (!mapfile.is_open()){
        ROS_ERROR("Could not open file %s for writing", newfileName.c_str());
      } else {
        octomap::AbstractOcTree tree(fileName);
        cout 

However, the input file and output file doesn't have the same size. The input file is 214KB while the output file becomes 203KB. Would you please offer some suggestions on where this issue would come from?? Thanks !!

--------------------------------------------------------Original ----------------------------------------------------------

Hi, I am trying to write a program that takes in a binary file which is a 3D map generated by Octomap map_saver and rotate or tilt it and then write it out. So are there any functions I can look into and use ?

Right now for reading I am using the constructor of Octomap::OcTree and writing using Octomap::writeMap. My code is as follows:

octomap::OcTree *tree(fileName); octomath::Pose6D origin(0,0,0,0,0,0); octomap::MapNode octomap(tree,origin); octomap.writeMap(newfileName);

But the weird thing is the input file and output file don't have the same file so i suspect these two read and write functions are not a good match. Can someone give some advice on this ? Thanks!!


Originally posted by Chong on ROS Answers with karma: 76 on 2012-10-28

Post score: 0

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

Do not use the MapNode classes, unless you know what you want to do with them.

To read octree files, either use AbstractOcTree::read(filename) as factory or the contstructor you already use.

To write, simply call tree->write("octree.ot") or tree->writeBinary("binaryTree.bt"). Check the online documentation for further details.

As a side note, there is some unfinished code for your purpose in the file "src/edit_octree.cpp" in OctoMap that you can use as a basis. If you have patches to contribute back (see the octomap trac) then I will gladly include them!


Originally posted by AHornung with karma: 5904 on 2012-10-29

This answer was NOT ACCEPTED on the original site

Post score: 2


Original comments

Comment by Chong on 2012-10-29:
Hi I've edited my question as above. Can you please spend a minute take a look at that? Thanks !!!!!

$\endgroup$
0
$\begingroup$

Rosanswers logo

Problem solved. Need to use writeBinaryConst instead of writeBinary


Originally posted by Chong with karma: 76 on 2012-11-02

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.