exportVol.hpp 7.91 KB
Newer Older
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
32
33
34
35
36
37
38
39
40
41
42
/*******************************************************************************
* 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                                        *
*                                                                              *
*******************************************************************************/

#include "Topology/generic/attributeHandler.h"
#include "Topology/generic/autoAttributeHandler.h"
#include "Topology/generic/traversorCell.h"
#include "Topology/generic/traversor2.h"
#include "Topology/generic/cellmarker.h"

namespace CGoGN
{

namespace Algo
{

namespace Volume
{

namespace Export
{

43
44
45
46
47
48
49
50
std::string truncFloatTO8(float f)
{
	std::stringstream ss;
	ss << f;
	std::string res = ss.str();
	return res.substr(0,8);
}

51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
template <typename PFP>
bool exportNAS(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const char* filename)
{
	typedef typename PFP::MAP MAP;
	typedef typename PFP::VEC3 VEC3;

	// open file
	std::ofstream fout ;
	fout.open(filename, std::ios::out) ;

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

	VertexAutoAttribute<unsigned int> indices(map,"indices_vert");

69
70
71
72

	fout << "$$ ---------------------------------------------------------------------------- $"<< std::endl;
	fout << "$$      NASTRAN MEsh File Generated by CGoGN (ICube/IGG)                        $"<< std::endl;
	fout << "$$ ---------------------------------------------------------------------------- $"<< std::endl;
73
74
	fout << "CEND" << std::endl;;
	fout << "BEGIN BULK" << std::endl;
75
76
77
	fout << "$$ ---------------------------------------------------------------------------- $"<< std::endl;
	fout << "$$      Vertices position                                                       $"<< std::endl;
	fout << "$$ ---------------------------------------------------------------------------- $"<< std::endl;
78
79
80
81
82
83
	unsigned int count=1;
	for (unsigned int i = position.begin(); i != position.end(); position.next(i))
	{
		const VEC3& P = position[i];
		fout << "GRID    ";
		fout << std::right;
84
		fout.width(8);
85
86
87
		fout << count;
		fout << "        ";
		fout << std::left;
88
		fout << std::setw(8)<<truncFloatTO8(P[0]) << std::setw(8)<<truncFloatTO8(P[1]) << std::setw(8)<<truncFloatTO8(P[2]) << std::endl;
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
		indices[i] = count++;
	}


	std::vector<unsigned int> hexa;
	std::vector<unsigned int> tetra;
	hexa.reserve(2048);
	tetra.reserve(2048);

	TraversorW<MAP> trav(map) ;
	for(Dart d = trav.begin(); d != trav.end(); d = trav.next())
	{
		unsigned int degree = 0 ;

		Traversor3WV<typename PFP::MAP> twv(map, d) ;
		for(Dart it = twv.begin(); it != twv.end(); it = twv.next())
		{
			degree++;
		}

		if (degree == 8)
		{
			//CAS HEXAEDRIQUE (ordre 2 quad superposes, le premier en CCW)
			Dart e = d;
			Dart f = map.template phi<21121>(d);
			hexa.push_back(indices[e]);
			e = map.phi1(e);
			hexa.push_back(indices[e]);
			e = map.phi1(e);
			hexa.push_back(indices[e]);
			e = map.phi1(e);
			hexa.push_back(indices[e]);
			hexa.push_back(indices[f]);
			e = map.phi_1(f);
			hexa.push_back(indices[f]);
			e = map.phi_1(f);
			hexa.push_back(indices[f]);
			e = map.phi_1(f);
			hexa.push_back(indices[f]);
		}

		if (degree == 4)
		{
			//CAS HEXAEDRIQUE (ordre 2 quad superposes, le premier en CCW)
			Dart e = d;
			tetra.push_back(indices[e]);
			e = map.phi1(e);
			tetra.push_back(indices[e]);
			e = map.phi1(e);
			tetra.push_back(indices[e]);
			e = map.template phi<211>(e);
			tetra.push_back(indices[e]);
		}
	}

	unsigned int countCell=1;
	unsigned int nbhexa = hexa.size()/8;
146
147
	unsigned int nbtetra = tetra.size()/4;

148

149
150
151

	fout << std::right;
	if (nbhexa!=0)
152
	{
153
154
155
156
157
158
159
160
161
162
163
		fout << "$$ ---------------------------------------------------------------------------- $"<< std::endl;
		fout << "$$      Hexa indices                                                            $"<< std::endl;
		fout << "$$ ---------------------------------------------------------------------------- $"<< std::endl;
		for (unsigned int i=0; i<nbhexa; ++i)
		{
			fout << "CHEXA   ";
			fout << std::setw(8) << countCell++ << std::setw(8)<< 0;
			fout <<  std::setw(8) << hexa[8*i] <<  std::setw(8) << hexa[8*i+1] <<  std::setw(8) << hexa[8*i+2];
			fout <<  std::setw(8) << hexa[8*i+3] <<  std::setw(8) << hexa[8*i+4] <<  std::setw(8) << hexa[8*i+6] << "+"<< std::endl;
			fout << "+       " <<  std::setw(8) << hexa[8*i+6] <<  std::setw(8) << hexa[8*i+7] << std::endl;
		}
164
165
	}

166
	if (nbtetra != 0)
167
	{
168
169
170
171
172
173
174
175
176
		fout << "$$ ---------------------------------------------------------------------------- $"<< std::endl;
		fout << "$$      Tetra indices                                                           $"<< std::endl;
		fout << "$$ ---------------------------------------------------------------------------- $"<< std::endl;
		for (unsigned int i=0; i<nbtetra; ++i)
		{
			fout << "CTETRA  ";
			fout << std::setw(8) << countCell++ << std::setw(8)<< 0;
			fout << std::setw(8) << tetra[4*i] << std::setw(8) << tetra[4*i+1] << std::setw(8) << tetra[4*i+2] << std::setw(8) << tetra[4*i+3] << std::endl;
		}
177
178
179
	}

	fout << "ENDDATA" << std::endl;
180
	return true;
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
}


template <typename PFP>
bool exportMSH(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const char* filename)
{
	typedef typename PFP::MAP MAP;
	typedef typename PFP::VEC3 VEC3;

	// open file
	std::ofstream fout ;
	fout.open(filename, std::ios::out) ;

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


template <typename PFP>
bool exportTet(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const char* filename)
{
	typedef typename PFP::MAP MAP;
	typedef typename PFP::VEC3 VEC3;

	// open file
	std::ofstream fout ;
	fout.open(filename, std::ios::out) ;

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


template <typename PFP>
bool exportNodeEle(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const char* filename)
{
	typedef typename PFP::MAP MAP;
	typedef typename PFP::VEC3 VEC3;

	// open file
	std::ofstream fout ;
	fout.open(filename, std::ios::out) ;

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

	std::ofstream foutEle ;
	foutEle.open(filename, std::ios::out) ;

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


} // namespace Export

}

} // namespace Algo

} // namespace CGoGN