importChoupi.hpp 3.66 KB
Newer Older
Lionel Untereiner's avatar
Lionel Untereiner committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
*                                                                              *
* This library is free software; you can redistribute it and/or modify it      *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your     *
* option) any later version.                                                   *
*                                                                              *
* This library is distributed in the hope that it will be useful, but WITHOUT  *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or        *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License  *
* for more details.                                                            *
*                                                                              *
* You should have received a copy of the GNU Lesser General Public License     *
* along with this library; if not, write to the Free Software Foundation,      *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
*                                                                              *
* Web site: http://cgogn.unistra.fr/                                           *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/


namespace CGoGN
{

namespace Algo
{

32
33
34
namespace Surface
{

Lionel Untereiner's avatar
Lionel Untereiner committed
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
namespace Import
{

template <typename PFP>
bool importChoupi(const std::string& filename, std::vector<typename PFP::VEC3>& tabV, std::vector<unsigned int>& tabE)
{
	typedef typename PFP::VEC3 VEC3;

	//open file
	std::ifstream fp(filename.c_str(), std::ios::in);
	if (!fp.good())
	{
		CGoGNerr << "Unable to open file " << filename << CGoGNendl;
		return false;
	}

	std::string ligne;
	unsigned int nbv, nbe;
	std::getline(fp, ligne);

	std::stringstream oss(ligne);
	oss >> nbv;
	oss >> nbe;

59
60
61
	std::cout << "nb vertices = " << nbv << std::endl;
	std::cout << "nb edges = " << nbe << std::endl;

Lionel Untereiner's avatar
Lionel Untereiner committed
62
	std::vector<unsigned int> index;
63
	index.reserve(2*nbv);
Lionel Untereiner's avatar
Lionel Untereiner committed
64
65
66
67
68
69
70
71
72
73
74
75

	//read vertices
	unsigned int id = 0;
	for(unsigned int j=0 ; j < nbv ; ++j)
	{
		do
		{
			std::getline(fp, ligne);
		} while(ligne.size() == 0);

		std::stringstream oss(ligne);

76
77
		unsigned int i;
		float x, y, z;
Lionel Untereiner's avatar
Lionel Untereiner committed
78
79
80
81
82
83
84
		oss >> i;
		oss >> x;
		oss >> y;
		oss >> z;

		VEC3 pos(x,y,z);

85
86
		//std::cout << "vec[" << j << "] = " << pos << std::endl;

Lionel Untereiner's avatar
Lionel Untereiner committed
87
88
		index[i] = id;
		tabV.push_back(pos);
89
90
91
92
		//tabV[j] = pos;

		//std::cout << "vec[" << j << "] = " << tabV[j] << std::endl;

Lionel Untereiner's avatar
Lionel Untereiner committed
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
		++id;
	}

	for(unsigned int i=0 ; i < nbe ; ++i)
	{
		do
		{
			std::getline(fp, ligne);
		}while(ligne.size() == 0);

		std::stringstream oss(ligne);

		unsigned int x, y;
		oss >> x;
		oss >> x;
		oss >> y;

		tabE.push_back(index[x]);
		tabE.push_back(index[y]);
112
113
		//tabE[2*i] = index[x];
		//tabE[2*i+1] = index[y];
Lionel Untereiner's avatar
Lionel Untereiner committed
114
115
	}

116
117
118
119
120
//	for(typename std::vector<VEC3>::iterator it = tabV.begin() ; it < tabV.end() ; ++it)
//		std::cout << *it << std::endl;

//	for(std::vector<unsigned int>::iterator it = tabE.begin() ; it < tabE.end() ; it = it + 2)
//		std::cout << *it << " " << *(it + 1) << std::endl;
Lionel Untereiner's avatar
Lionel Untereiner committed
121

122
	fp.close();
Lionel Untereiner's avatar
Lionel Untereiner committed
123
124
125
126
127
128

	return true;
}

} // namespace Import

129
130
}

Lionel Untereiner's avatar
Lionel Untereiner committed
131
132
133
134
} // namespace Algo

} // namespace CGoGN