Ask Your Question
0

octomap functions for reading and writing binaries

asked 2012-10-28 05:09:08 -0500

Chong gravatar image

updated 2012-11-02 05:31:13 -0500

--------------------------------------------------------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 << " Please input the filename of the map:" << endl;
    cin >> fileName;
    cout << " Please input the filename of the map that's going to be output:" << endl;
    cin >> 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 << "Phase 1" << endl;
        octomath::Pose6D origin(0,0,0,0,0,0);
        cout << "Phase 2" << endl;
        tree.write(newfileName);
        }

    return 0;
}

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::octree> 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!!

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2012-11-02 10:44:48 -0500

Chong gravatar image

Problem solved. Need to use writeBinaryConst instead of writeBinary

edit flag offensive delete link more
2

answered 2012-10-29 04:19:48 -0500

AHornung gravatar image

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!

edit flag offensive delete link more

Comments

Hi I've edited my question as above. Can you please spend a minute take a look at that? Thanks !!!!!

Chong gravatar image Chong  ( 2012-10-29 07:16:27 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2012-10-28 05:09:08 -0500

Seen: 1,754 times

Last updated: Nov 02 '12