importMoka.hpp 4.43 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer 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
/*******************************************************************************
* 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
{

31
32
33
namespace Volume
{

Pierre Kraemer's avatar
Pierre Kraemer committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
namespace Import
{

template <typename PFP>
bool importMoka(typename PFP::MAP& gmap, const std::string& filename, std::vector<std::string>& attrNames)
{
	if(gmap.mapTypeName().compare("GMap3") != 0)
	{
		CGoGNerr << "Unable to load MOKA file " << filename << " : given map is not a 3-GMap" << CGoGNendl;
		return false ;
	}

	// open file
	igzstream fp(filename.c_str(), std::ios::in|std::ios::binary);

	if (!fp.good())
	{
		CGoGNerr << "Unable to open file " << filename << CGoGNendl;
		return false;
	}

55
	VertexAttribute<typename PFP::VEC3> position =  gmap.template getAttribute<typename PFP::VEC3, VERTEX>("position");
Pierre Kraemer's avatar
Pierre Kraemer committed
56
	if (!position.isValid())
57
		position = gmap.template addAttribute<typename PFP::VEC3, VERTEX>("position");
Pierre Kraemer's avatar
Pierre Kraemer committed
58
59
60

	attrNames.push_back(position.name());

61
	AttributeContainer& vertexContainer = gmap.template getAttributeContainer<VERTEX>() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
62
63
64
65
66
67
68
69
70
71
72
73
74
75

	std::string ligne;
	std::getline (fp, ligne);

	// check if the file format is in ascii
	if(ligne.compare("Moka file [ascii]") != 0)
	{
		CGoGNerr << "Unable to load this MOKA file " << filename << CGoGNendl;
		return false;
	}

	// ignore 2nd line
	std::getline (fp, ligne);

76
77
78
79
	DartAttribute<Dart> att_beta0 = gmap.template getAttribute<Dart, DART>("beta0");
	DartAttribute<Dart> att_beta1 = gmap.template getAttribute<Dart, DART>("beta1");
	DartAttribute<Dart> att_beta2 = gmap.template getAttribute<Dart, DART>("beta2");
	DartAttribute<Dart> att_beta3 = gmap.template getAttribute<Dart, DART>("beta3");
Pierre Kraemer's avatar
Pierre Kraemer committed
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123

	std::map<Dart, unsigned int> map_dart_emb;

	while(!std::getline(fp, ligne).eof())
	{
		std::stringstream oss(ligne);
		unsigned int beta0, beta1, beta2, beta3;

		Dart d = gmap.newDart();

		// read involutions
		oss >> beta0;
		oss >> beta1;
		oss >> beta2;
		oss >> beta3;

		att_beta0[d] = beta0;
		att_beta1[d] = beta1;
		att_beta2[d] = beta2;
		att_beta3[d] = beta3;

		// ignore markers
		unsigned int tmp;
		for(unsigned int i = 0 ; i < 4 ; ++i)
			oss >> tmp;

		// check if contains embedding
		unsigned int emb;
		oss >> emb;

		if(emb == 1)
		{
			typename PFP::VEC3 pos;
			oss >> pos[0];
			oss >> pos[1];
			oss >> pos[2];

			unsigned int id = vertexContainer.insertLine();
			position[id] = pos;
			map_dart_emb.insert(std::pair<Dart,unsigned int>(d, id));
		}
	}

	for(typename std::map<Dart, unsigned int>::iterator it = map_dart_emb.begin() ; it != map_dart_emb.end() ; ++it)
124
125
//		gmap.template setOrbitEmbedding<VERTEX>(it->first, it->second);
		Algo::Topo::setOrbitEmbedding<VERTEX>(gmap,it->first, it->second);
Pierre Kraemer's avatar
Pierre Kraemer committed
126
127
128
129
130
131
132
133
134

	gmap.closeMap();

	fp.close();
	return true;
}

} // namespace Import

135
136
}

Pierre Kraemer's avatar
Pierre Kraemer committed
137
138
139
} // namespace Algo

} // namespace CGoGN