#ifndef _FILE_IO_H_
#define _FILE_IO_H_

/********************************************************************
	created:	 2009/07/23
	created:	 23:7:2009   19:15
	file base:	 file_io.h
	author:		 Liangliang Nan
    contact:     liangliang.nan@gmail.com
    affiliation: Shenzhen Institute of Advanced Technology
	
	purpose:	 wrapper of the file io implementation
*********************************************************************/

#include "geometry_common.h"
#include <iostream>
#include <fstream>
#include <cfloat>

#include "../geometry/geometry_types.h"


class Vertex;
class VertexGroup;
class PointSet;


class GEOMETRY_API FileIO
{
public:
	// object type is identified by file extension
	static PointSet* read_point_cloud(const std::string& file_name);
	static bool save_point_cloud(PointSet* point_set, const std::string& file_name);

	static std::string title() { return "[FileIO]: "; }

public:
	static void load_bxyz(PointSet* pointSet, const std::string& file_name) ;
	static void save_bxyz(PointSet* pointSet, const std::string& file_name) ;

	static void load_xyz(PointSet* pointSet, const std::string& file_name) ;
	static void save_xyz(PointSet* pointSet, const std::string& file_name) ;

	//////////////////////////////////////////////////////////////////////////
	
	static void load_bpn(PointSet* pointSet, const std::string& file_name) ;
	static void save_bpn(PointSet* pointSet, const std::string& file_name) ;

	static void load_pn(PointSet* pointSet, const std::string& file_name) ;
	static void save_pn(PointSet* pointSet, const std::string& file_name) ;

	//////////////////////////////////////////////////////////////////////////

	// read and write MY OWN pcd format (sub-set of PCL pcd format)
	static void load_pcd(PointSet* pointSet, const std::string& file_name);
	static void save_pcd(PointSet* pointSet, const std::string& file_name);

	//////////////////////////////////////////////////////////////////////////

	// labeled vertex groups
	static void load_blab(PointSet* pointSet, const std::string& file_name);
	static void save_blab(PointSet* pointSet, const std::string& file_name);

	static void load_lab(PointSet* pointSet, const std::string& file_name);
	static void save_lab(PointSet* pointSet, const std::string& file_name);

private:
	static VertexGroup* lab_read_group(std::ifstream& input, Vertex** vts);
	static void lab_write_group(std::ofstream& output, VertexGroup* g);
	
	static VertexGroup* blab_read_group(std::ifstream& input, Vertex** vts);
	static void blab_write_group(std::ofstream& output, VertexGroup* g);
	
	// string are stored as array of chars in binary file
	static std::string read_binary_string(std::ifstream& input);
	static void write_binary_string(std::ofstream& output, const std::string& str);
};


#endif